Skip to content

Commit 5669564

Browse files
committed
Merge pull request #186 from frenetic-lang/compilekat
Compilekat
2 parents e22bccb + 1d1581a commit 5669564

16 files changed

+269
-282
lines changed

.travis-ci.sh

Lines changed: 0 additions & 42 deletions
This file was deleted.

.travis.yml

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
language: c
2-
script: bash -ex .travis-ci.sh
2+
install: wget https://raw.githubusercontent.com/ocaml/ocaml-travisci-skeleton/master/.travis-opam.sh
3+
script: bash -ex .travis-opam.sh
34
env:
4-
global:
5-
- OPAM_DEPENDS="cstruct quickcheck ounit pa_ounit core async sexplib"
6-
- CONFIG_FLAGS="--enable-tests --enable-quickcheck --enable-async"
7-
- FRENETIC_DEPENDS="ocaml-packet"
8-
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
12-
- OCAML_VERSION=4.02.0 OPAM_VERSION=1.2.0
5+
- OCAML_VERSION=latest PACKAGE=openflow
136
notifications:
147
irc:
158
channels:

Makefile

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,41 @@
1-
all: build
1+
# OASIS_START
2+
# DO NOT EDIT (digest: a3c674b4239234cbbe53afe090018954)
23

3-
ASYNC ?= $(shell if ocamlfind query async >/dev/null 2>&1; then echo --enable-async; else echo --disable-async; fi)
4-
# Implies --enable-quickcheck
5-
TESTS ?= $(shell if ocamlfind query quickcheck >/dev/null 2>&1; then echo --enable-tests; else echo --disable-tests; fi)
4+
SETUP = ocaml setup.ml
65

7-
NAME=openflow
8-
J=4
6+
build: setup.data
7+
$(SETUP) -build $(BUILDFLAGS)
98

10-
setup.ml: _oasis
11-
oasis setup
9+
doc: setup.data build
10+
$(SETUP) -doc $(DOCFLAGS)
1211

13-
setup.data: setup.ml
14-
ocaml setup.ml -configure $(ASYNC) $(TESTS)
12+
test: setup.data build
13+
$(SETUP) -test $(TESTFLAGS)
1514

16-
build: setup.data setup.ml
17-
ocaml setup.ml -build -j $(J)
15+
all:
16+
$(SETUP) -all $(ALLFLAGS)
1817

19-
install: setup.data setup.ml
20-
ocaml setup.ml -install
18+
install: setup.data
19+
$(SETUP) -install $(INSTALLFLAGS)
2120

22-
test: setup.ml build
23-
_build/test/Test.byte inline-test-runner openflow
21+
uninstall: setup.data
22+
$(SETUP) -uninstall $(UNINSTALLFLAGS)
2423

25-
reinstall: setup.ml
26-
ocamlfind remove $(NAME) || true
27-
ocaml setup.ml -reinstall
24+
reinstall: setup.data
25+
$(SETUP) -reinstall $(REINSTALLFLAGS)
2826

2927
clean:
30-
ocamlbuild -clean
31-
rm -f setup.data setup.log
28+
$(SETUP) -clean $(CLEANFLAGS)
29+
30+
distclean:
31+
$(SETUP) -distclean $(DISTCLEANFLAGS)
32+
33+
setup.data:
34+
$(SETUP) -configure $(CONFIGUREFLAGS)
35+
36+
configure:
37+
$(SETUP) -configure $(CONFIGUREFLAGS)
38+
39+
.PHONY: build doc test all install uninstall reinstall clean distclean configure
40+
41+
# OASIS_STOP

_oasis

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,14 @@
11
OASISFormat: 0.3
22
OCamlVersion: >= 4.01.0
33
Name: openflow
4-
Version: 0.7.0
4+
Version: 0.8.0
55
Synopsis: Serialization library for OpenFlow
66
Authors: https://github.com/frenetic-lang/ocaml-openflow/contributors
77
License: LGPL
8-
Plugins: META (0.3)
8+
Plugins: META (0.3), DevFiles (0.3)
99
BuildTools:
1010
ocamlbuild
1111

12-
Flag quickcheck
13-
Description: build the openflow.quickcheck library
14-
Default: false
15-
16-
Flag async
17-
Description: build the openflow.async library
18-
Default: false
19-
2012
Library openflow
2113
Path: lib
2214
BuildDepends:
@@ -50,7 +42,6 @@ Library async
5042
Findlibparent: openflow
5143
Findlibname: async
5244
Path: async
53-
Build$: flag(async)
5445
BuildDepends:
5546
async,
5647
openflow,
@@ -74,7 +65,6 @@ Library quickcheck
7465
Findlibparent: openflow
7566
Findlibname: quickcheck
7667
Path: quickcheck
77-
Build$: flag(tests) || flag(quickcheck)
7868
BuildDepends:
7969
quickcheck,
8070
openflow,
@@ -103,19 +93,19 @@ Executable testtool
10393
Executable ping_test
10494
Path: ping-test
10595
Install: false
106-
Build$: flag(tests) && flag(async)
96+
Build$: flag(tests)
10797
MainIs: PingTest.ml
10898
BuildDepends: packet,openflow,openflow.async,oUnit,pa_ounit,pa_ounit.syntax
10999

110100
Test all_tests
111101
Command: $testtool inline-test-runner openflow
112-
Run$: flag(quickcheck) && flag(tests)
102+
Run$: flag(tests)
113103
TestTools: testtool
114104

115105
Executable learning_switch
116106
Path: examples
117107
MainIs: Learning_Switch.ml
118-
Build$: flag(async)
108+
Build$: flag(tests)
119109
Install: false
120110
BuildDepends:
121111
threads,
@@ -129,7 +119,7 @@ Executable learning_switch
129119
Executable learning_switch0x04
130120
Path: examples
131121
MainIs: Learning_Switch0x04.ml
132-
Build$: flag(async)
122+
Build$: flag(tests)
133123
Install: false
134124
BuildDepends:
135125
threads,

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

0 commit comments

Comments
 (0)