Skip to content

Commit d40c76b

Browse files
author
Arjun Guha
committed
Updated to use latest async
1 parent a0233f5 commit d40c76b

File tree

7 files changed

+20
-128
lines changed

7 files changed

+20
-128
lines changed

.travis.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ env:
66
- CONFIG_FLAGS="--enable-tests --enable-quickcheck --enable-async"
77
- FRENETIC_DEPENDS="ocaml-packet"
88
matrix:
9-
- OCAML_VERSION=4.01.0 OPAM_VERSION=1.1.0
10-
- OCAML_VERSION=4.01.0 OPAM_VERSION=1.2.0
11-
- OCAML_VERSION=4.02.0 OPAM_VERSION=1.1.0
129
- OCAML_VERSION=4.02.0 OPAM_VERSION=1.2.0
1310
notifications:
1411
irc:

async/Async_OpenFlow.mli

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,8 @@ open Async.Std
33

44

55
(** By default, displays untagged info messages on stderr. *)
6-
module Log : sig
6+
module Log : Log.Global_intf
77

8-
include Log.Global_intf
9-
10-
val of_lazy
11-
: ?level:[ `Debug | `Info | `Error ]
12-
-> ?time:Time.t
13-
-> ?tags:(string * string) list
14-
-> string Lazy.t
15-
-> unit
16-
17-
val make_filtered_output : (string * string) list ->
18-
Log.Output.t
19-
20-
val add_output : Log.Output.t list -> unit
21-
22-
end
238

249
module type Message = sig
2510
type t with sexp

async/Async_OpenFlow0x01.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,9 @@ module Controller = struct
175175
Hash_set.remove t.shakes c_id;
176176
return [`Connect(switch_id, fs)]
177177
| _ ->
178-
Log.of_lazy ~tags ~level:`Debug (lazy
179-
(Printf.sprintf "Dropped message during handshake: %s"
180-
(Message.to_string (xid, msg))));
178+
Log.printf ~tags ~level:`Debug
179+
"Dropped message during handshake: %s"
180+
(Message.to_string (xid, msg));
181181
return []
182182
end
183183
| `Message (c_id, msg) ->

async/Async_OpenFlow0x04.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,9 @@ module Controller = struct
205205
return [`Connect(sw_id, (fs, ps'))]
206206
end
207207
| _, _ ->
208-
Log.of_lazy ~tags ~level:`Debug (lazy
209-
(Printf.sprintf "Dropped message during handshake: %s"
210-
(Message.to_string (xid, msg))));
208+
Log.printf ~tags ~level:`Debug
209+
"Dropped message during handshake: %s"
210+
(Message.to_string (xid, msg));
211211
return []
212212
end
213213
| `Message (c_id, msg) ->

async/Async_OpenFlow_Log.ml

Lines changed: 2 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,5 @@
11
open Core.Std
22
open Async.Std
33

4-
module TagSet = Set.Make(struct
5-
type t = string * string with sexp
6-
let compare = Pervasives.compare
7-
end)
8-
9-
let filter_by_tags (enabled_tags : (string * string) list) =
10-
let enabled_tags = TagSet.of_list enabled_tags in
11-
(fun msgs ->
12-
Queue.filter_map msgs (fun msg ->
13-
match Log.Message.tags msg with
14-
| [] -> Some msg (* untagged messages are printed indiscriminately *)
15-
| msg_tags ->
16-
if List.exists ~f:(TagSet.mem enabled_tags) msg_tags then
17-
Some msg
18-
else
19-
None))
20-
21-
let label_severity msg =
22-
let debug, info, error = [`Dim], [`Blue], [`Red] in
23-
let style, prefix = match Log.Message.level msg with
24-
| None -> info, ""
25-
| Some `Debug -> debug, "[DEBUG]"
26-
| Some `Info -> info, " [INFO]"
27-
| Some `Error -> error, "[ERROR]" in
28-
String.concat ~sep:" "
29-
[ prefix
30-
; Log.Message.message msg ]
31-
32-
let make_filtered_output (tags : (string * string) list)
33-
: Log.Output.t =
34-
let filter = filter_by_tags tags in
35-
Log.Output.create
36-
(fun msgs ->
37-
let writer = Lazy.force (Writer.stderr) in
38-
return (Queue.iter (filter msgs) ~f:(fun msg ->
39-
Writer.write writer (label_severity msg);
40-
Writer.newline writer)))
41-
42-
let current_outputs = ref []
43-
44-
let stderr : Log.Output.t =
45-
make_filtered_output [("openflow", "")]
46-
47-
let log = lazy (Log.create ~level:`Info ~output:[stderr])
48-
49-
let level () = Log.level (Lazy.force log)
50-
let set_level = Log.set_level (Lazy.force log)
51-
52-
let set_output outputs = current_outputs := outputs;
53-
Log.set_output (Lazy.force log) outputs
54-
55-
let add_output outputs =
56-
let outputs = outputs @ !current_outputs in
57-
current_outputs := outputs;
58-
set_output outputs
59-
60-
let raw ?time ?(tags=[]) fmt = Log.raw (Lazy.force log) ?time ~tags fmt
61-
62-
let info ?time ?(tags=[]) fmt = Log.info (Lazy.force log) ?time ~tags fmt
63-
64-
let error ?time ?(tags=[]) fmt = Log.error (Lazy.force log) ?time ~tags fmt
65-
66-
let debug ?time ?(tags=[]) fmt = Log.debug (Lazy.force log) ?time ~tags fmt
67-
68-
let flushed () =
69-
Log.flushed (Lazy.force log)
70-
71-
let printf ?(level=`Debug) ?time ?(tags=[]) fmt =
72-
Log.printf (Lazy.force log) ~tags ~level fmt
73-
74-
let of_lazy ?(level=`Debug) ?time ?(tags=[]) lazy_str =
75-
(* As of core/async.111.25.00, `Log.of_lazy` is no longer part of that
76-
* package's public API. In 111.28.00, the `Log.level` call was added,
77-
* allowing users of the package to implement `of_lazy` without having to
78-
* manage the log level manually.
79-
* *)
80-
if level = Log.level (Lazy.force log) then
81-
Log.printf (Lazy.force log) ~tags ~level "%s" (Lazy.force lazy_str)
82-
83-
let sexp ?(level=`Debug) ?time ?(tags=[]) msg =
84-
Log.sexp (Lazy.force log) ~tags ~level msg
85-
86-
let string ?(level=`Debug) ?time ?(tags=[]) str =
87-
Log.string (Lazy.force log) ~tags ~level str
88-
89-
let message = Log.message (Lazy.force log)
4+
module Log = Log.Make_global ()
5+
include Log

async/Async_OpenFlow_Message.ml

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,12 @@ module MakeSerializers (M : Message) = struct
2424
Digest.to_hex (Digest.string buf)
2525

2626
let deserialize ?(tags : (string * string) list = []) ?(label : string = "")
27-
(raw_reader : Reader.t) : [ `Eof | `Ok of M.t] Deferred.t =
28-
let log msg = Log.of_lazy ~level:`Debug ~tags:tags msg in
27+
(raw_reader : Reader.t) : [ `Eof | `Ok of M.t] Deferred.t =
2928
let ofhdr_str = String.create Header.size in
3029
Reader.really_read raw_reader ofhdr_str
3130
>>= function
32-
| `Eof _ ->
33-
log (lazy (sprintf "[%s] EOF reading header" label));
31+
| `Eof _ ->
32+
Log.printf "[%s] EOF reading header" label;
3433
return `Eof
3534
| `Ok ->
3635
let hdr = Header.parse (Cstruct.of_string ofhdr_str) in
@@ -39,16 +38,13 @@ module MakeSerializers (M : Message) = struct
3938
Reader.really_read raw_reader body_buf
4039
>>= function
4140
| `Eof _ ->
42-
log (lazy (sprintf "[%s] EOF reading body (expected %d bytes)"
43-
label body_len));
41+
Log.printf "[%s] EOF reading body (expected %d bytes)" label body_len;
4442
return `Eof
4543
| `Ok ->
4644
let m = M.parse hdr (Cstruct.of_string body_buf) in
4745
(* extra space left so read and write align in the log *)
48-
log (lazy (sprintf "[%s] read %s hash=%s"
49-
label
50-
(Header.to_string hdr)
51-
(readable_md5 (ofhdr_str ^ body_buf))));
46+
Log.printf "[%s] read %s hash=%s" label (Header.to_string hdr)
47+
(readable_md5 (ofhdr_str ^ body_buf));
5248
return (`Ok m)
5349

5450
let serialize ?(tags : (string * string) list = []) ?(label : string = "")
@@ -58,8 +54,6 @@ module MakeSerializers (M : Message) = struct
5854
Header.marshal buf hdr;
5955
let _ = M.marshal m (Cstruct.shift buf Header.size) in
6056
Async_cstruct.schedule_write raw_writer buf;
61-
Log.of_lazy ~level:`Debug ~tags:tags
62-
(lazy (sprintf "[%s] wrote %s hash=%s"
63-
label (Header.to_string hdr)
64-
(readable_md5 (Cstruct.to_string buf))))
57+
Log.printf ~level:`Debug ~tags "[%s] wrote %s hash=%s"
58+
label (Header.to_string hdr) (readable_md5 (Cstruct.to_string buf))
6559
end

opam

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ depends: [
1818
"packet" {>= "0.3.0" }
1919
"sexplib"
2020
]
21-
depopts: [ "async" "quickcheck" ]
22-
conflicts: [
23-
"async_extra" { != "111.28.00" }
21+
depopts: [
22+
"async" {>= "112.06.00" }
23+
"quickcheck"
2424
]

0 commit comments

Comments
 (0)