Skip to content

Commit ad6b905

Browse files
committed
Update for Frenetic 4.0
1 parent f7daf09 commit ad6b905

File tree

12 files changed

+137
-74
lines changed

12 files changed

+137
-74
lines changed

Introduction/index.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Software Environment
4646
This is a hands-on tutorial with several programming exercises. We
4747
recommend using the virtual machine we've prepared that has all the
4848
necessary software that you need pre-installed. You can get the
49-
tutorial VM from the following link: [Frenetic Tutorial VM](http://storage.googleapis.com/arjun-umass-disks/Frenetic-Tutorial.ova).
49+
tutorial VM from the following link: [Frenetic Tutorial VM](https://cornell.box.com/frenetic-4-tutorial).
5050

5151
References
5252
----------
@@ -76,4 +76,3 @@ References
7676
[NetKAT](http://frenetic-lang.github.io/api/frenetic) libraries, as
7777
well as other supporting libraries used in this tutorial.
7878

79-
[Real World OCaml]: https://realworldocaml.org

NetKATFirewall/index.md

+29-11
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,22 @@ to configure the switch.
1414
We can implement the same policy in NetKAT as follows:
1515

1616
~~~ ocaml
17-
open NetKAT.Std
18-
open RepeaterPolicy
17+
open Frenetic_NetKAT
18+
open Core.Std
19+
open Async.Std
20+
open Repeater
1921
2022
let firewall : policy =
2123
<:netkat<
2224
if ipProto = 0x01 && ethType = 0x800 then drop else $pol
2325
>>
2426
25-
let _ = run_static firewall
27+
let _ =
28+
let module Controller = Frenetic_NetKAT_Controller.Make in
29+
Controller.start 6633;
30+
Controller.update_policy repeater;
31+
never_returns (Scheduler.go ());
32+
2633
~~~
2734

2835
There are two things to note about this program. First, rather than
@@ -44,8 +51,8 @@ To test your code, compile the firewall and start the controller in
4451
one terminal,
4552

4653
~~~
47-
$ netkat-build Firewall.native
48-
$ ./Firewall.native
54+
$ netkat-build Firewall
55+
$ ./Firewall.d.byte
4956
~~~
5057

5158
and Mininet in another:
@@ -86,7 +93,9 @@ The hosts have IP addresses 10.0.0.1 through 10.0.0.4 and are
8693
connected to ports 1 through 4 respetively.
8794

8895
~~~
89-
open NetKAT.Std
96+
open Frenetic_NetKAT
97+
open Core.Std
98+
open Async.Std
9099
91100
let forwarding : policy =
92101
<:netkat<
@@ -103,15 +112,22 @@ Type this policy into a file `Forwarding.ml` in the
103112
We want our firewall policy to wrap this forwarding policy:
104113

105114
~~~
106-
open NetKAT.Std
115+
open Frenetic_NetKAT
116+
open Core.Std
117+
open Async.Std
107118
open Forwarding
108119
109120
let firewall : policy =
110121
<:netkat<
111122
if (* FILL condition for ICMP packets *) then drop else (filter ethType = 0x800; $forwarding)
112123
>>
113124
114-
let _ = run_static firewall
125+
let _ =
126+
let module Controller = Frenetic_NetKAT_Controller.Make in
127+
Controller.start 6633;
128+
Controller.update_policy repeater;
129+
never_returns (Scheduler.go ());
130+
115131
~~~
116132

117133
Save this policy into a file `Firewall2.ml` in the
@@ -122,8 +138,8 @@ Save this policy into a file `Firewall2.ml` in the
122138
- Build and launch the controller:
123139

124140
~~~ shell
125-
$ netkat-build Firewall2.native
126-
$ ./Firewall2.native
141+
$ netkat-build Firewall2
142+
$ ./Firewall2.d.byte
127143
~~~
128144

129145
- Start Mininet using the same parameters you've used before:
@@ -188,7 +204,9 @@ policy in NetKAT, you need to allow packets from the first host to
188204
port 80 on second *and* from port 80 on the second back to the first:
189205

190206
~~~ ocaml
191-
open NetKAT.Std
207+
open Frenetic_NetKAT
208+
open Core.Std
209+
open Async.Std
192210
open Forwarding
193211
194212
let firewall : policy =

NetKATRepeater/index.md

+23-12
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ platform. Most of the controllers we built followed a two-step recipe:
99
* Write a `packet_in` handler that implements the desired
1010
packet-processing functionality.
1111

12-
* Use `flow__mod` messages to configure the switch flow tables to
12+
* Use `flow_mod` messages to configure the switch flow tables to
1313
implement the same functionality efficiently.
1414

1515
In the next few chapters, we will explore a completely different
@@ -18,12 +18,11 @@ programming language, and let a compiler and run-time system handle
1818
the details related to configuring switch flow tables (as well as
1919
sending requests for statistics, accumulating replies, etc.)
2020

21-
The templates for this part of the tutorial are in the
22-
`netkat-tutorial-workspace` directory, and the solutions are in
23-
`netkat-tutorial-solutions`.
21+
The templates for this part are in
22+
`src/netkat-tutorial-solutions`.
2423

2524
~~~
26-
$ cd tutorials/netkat-tutorial-solutions
25+
$ cd src/netkat-tutorial-solutions
2726
~~~
2827

2928
### Example 1: A Repeater (Redux)
@@ -39,7 +38,9 @@ of a single switch with four ports, numbered 1 through 4:
3938
The following program implements a repeater in NetKAT:
4039

4140
~~~ ocaml
42-
open NetKAT.Std
41+
open Frenetic_NetKAT
42+
open Core.Std
43+
open Async.Std
4344
4445
(* a simple repeater *)
4546
let repeater : policy =
@@ -51,7 +52,12 @@ let repeater : policy =
5152
else drop
5253
>>
5354
54-
let _ = run_static repeater
55+
let _ =
56+
let module Controller = Frenetic_NetKAT_Controller.Make in
57+
Controller.start 6633;
58+
Controller.update_policy repeater;
59+
never_returns (Scheduler.go ());
60+
5561
~~~
5662

5763
This main part of this code uses a Camlp4 quotation,
@@ -67,13 +73,16 @@ the switch with a static NetKAT policy.
6773

6874
To run the repeater, type the code above into a file
6975
<code>Repeater.ml</code> within the
70-
<code>netkat-tutorial-workspace</code> directory. Then compile and
76+
<code>netkat-tutorial-solutionbs</code> directory. Then compile and
7177
start the repeater controller using the following commands.
78+
7279
~~~
73-
$ netkatbuild Repeater.native
74-
$ ./Repeater.native
80+
$ netkat-build Repeater
81+
$ ./Repeater.d.byte
7582
~~~
83+
7684
Next, in a separate terminal, start up mininet.
85+
7786
~~~
7887
$ sudo mn --controller=remote --topology=single,4 --mac --arp
7988
~~~
@@ -111,7 +120,9 @@ wanted to implement repeaters on switches with different numbers of
111120
ports.
112121

113122
~~~ ocaml
114-
open NetKAT.Std
123+
open Frenetic_NetKAT
124+
open Core.Std
125+
open Async.Std
115126
116127
(* a simple repeater *)
117128
let all_ports : int list = [1; 2; 3; 4]
@@ -125,5 +136,5 @@ let repeater : policy =
125136
List.fold_right
126137
(fun m pol -> <:netkat<let p = flood m in if port = $m then $p else $pol>>)
127138
all_ports <:netkat<drop>>
128-
>>
139+
129140
~~~

NetKATRouting/index.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ last chapter to this new network. Unfortunately, you cannot simply reuse the fir
7878
Your firewall policy from the previous chapter probably has the following form:
7979

8080
~~~
81-
open NetKAT.Std
81+
open Frenetic_NetKAT
82+
open Core.Std
83+
open Async.Std
8284
open Forwarding
8385
8486
let firewall =

OxFirewall/index.md

+9-4
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,15 @@ number for ICMP is 1 (`Packet.nwProto pk = 1`).
3939
Fill in the `is_icmp_packet` function in the following template:
4040

4141
~~~ ocaml
42-
open OpenFlow0x01_Core
43-
open OxPlatform
42+
open Frenetic_Ox
43+
open Frenetic_OpenFlow0x01
44+
open Core.Std
45+
open Async.Std
4446
4547
module MyApplication = struct
4648
47-
include OxStart.DefaultTutorialHandlers
49+
include DefaultHandlers
50+
open Platform
4851
4952
let is_icmp_packet (pk : Packet.packet) = ... (* [FILL] *)
5053
@@ -59,7 +62,9 @@ module MyApplication = struct
5962
6063
end
6164
62-
module Controller = OxStart.Make (MyApplication)
65+
let _ =
66+
let module C = Make (MyApplication) in
67+
C.start ();
6368
~~~
6469

6570
### Building and Testing Your Firewall

OxLearning/index.md

+12-8
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,20 @@ learns host locations.
4040

4141
You should use the template below to get started. Save it in a file
4242
called `Learning.ml` and place it in the directory
43-
`~/src/frenetic/ox-tutorial-workspace/Learning.ml`.
43+
`~/src/frenetic-tutorial-workspace/Learning.ml`.
4444

4545
~~~ ocaml
46-
(* ~/src/frenetic/ox-tutorial-workspace/Learning.ml *)
46+
(* ~/src/frenetic-tutorial-workspace/Learning.ml *)
4747
48-
open OxPlatform
49-
open OpenFlow0x01_Core
50-
open Packet
48+
open Frenetic_Ox
49+
open Frenetic_OpenFlow0x01
50+
open Frenetic_Packet
51+
open Core.Std
52+
open Async.Std
5153
5254
module MyApplication = struct
53-
54-
include OxStart.DefaultTutorialHandlers
55+
include DefaultHandlers
56+
open Platform
5557
5658
let known_hosts : (dlAddr, portId) Hashtbl.t = Hashtbl.create 50
5759
@@ -90,7 +92,9 @@ module MyApplication = struct
9092
9193
end
9294
93-
module Controller = OxStart.Make (MyApplication)
95+
let _ =
96+
let module C = Make (MyApplication) in
97+
C.start ();
9498
~~~
9599

96100
Note that it contains a hash table to map hosts to ports:

OxMonitor/index.md

+16-12
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,20 @@ let packet_in (sw : switchId) (xid : xid) (pktIn : packetIn) : unit =
3636

3737
Use the following code as a template for this exercise. Save it in a file
3838
called `Monitor.ml` and place it in the directory
39-
`~/src/frenetic/ox-tutorial-workspace/Monitor.ml`.
39+
`~/src/frenetic-tutorial-workspace/Monitor.ml`.
4040

4141
~~~ ocaml
42-
(* ~/src/frenetic/ox-tutorial-workspace/Monitor.ml *)
42+
(* ~/src/frenetic-tutorial-workspace/Monitor.ml *)
4343
44-
open OxPlatform
45-
open OpenFlow0x01_Core
46-
module Stats = OpenFlow0x01_Stats
44+
open Frenetic_Ox
45+
open Frenetic_OpenFlow0x01
46+
open Core.Std
47+
open Async.Std
4748
4849
module MyApplication = struct
4950
50-
include OxStart.DefaultTutorialHandlers
51+
include DefaultHandlers
52+
open Platform
5153
5254
(* [FILL] copy over the packet_in function from Firewall.ml
5355
verbatim, including any helper functions. *)
@@ -71,7 +73,9 @@ module MyApplication = struct
7173
7274
end
7375
74-
module Controller = OxStart.Make (MyApplication)
76+
let _ =
77+
let module C = Make (MyApplication) in
78+
C.start ();
7579
~~~
7680

7781
Your task:
@@ -225,7 +229,7 @@ let rec periodic_stats_request sw interval xid pat =
225229
let callback () =
226230
Printf.printf "Sending stats request to %Ld\n%!" sw;
227231
send_stats_request sw xid
228-
(Stats.AggregateRequest (pat, 0xff, None));
232+
(AggregateRequest (pat, 0xff, None));
229233
periodic_stats_request sw interval xid pat in
230234
timeout interval callback
231235
~~~
@@ -259,12 +263,12 @@ let num_http_response_packets = ref 0L
259263
260264
let stats_reply (sw : switchId) (xid : xid) (stats : Stats.reply) : unit =
261265
match stats with
262-
| Stats.AggregateFlowRep rep ->
266+
| AggregateFlowRep rep ->
263267
begin
264268
if xid = 10l then
265-
num_http_request_packets := rep.Stats.total_packet_count
269+
num_http_request_packets := rep.total_packet_count
266270
else if xid = 20l then
267-
num_http_response_packets := rep.Stats.total_packet_count
271+
num_http_response_packets := rep.total_packet_count
268272
end;
269273
Printf.printf "Saw %Ld HTTP packets.\n%!"
270274
(Int64.add !num_http_request_packets !num_http_response_packets)
@@ -282,7 +286,7 @@ Consider what happens if the controller receives HTTP packets before
282286
the switch is fully initialized and extend your monitoring program to
283287
handle this situation.
284288

285-
[statistics]: https://github.com/frenetic-lang/ocaml-openflow/blob/master/lib/OpenFlow0x01_Stats.mli
289+
[statistics]: https://github.com/frenetic-lang/frenetic/blob/master/lib/OpenFlow0x01.mli
286290

287291
[Action]: http://frenetic-lang.github.io/frenetic/docs/OpenFlow0x01.Action.html
288292

OxNat/index.md

+11-8
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,19 @@ $ sudo mn --controller=remote --topo=single,3 --mac --arp
4343
#### Programming Task
4444

4545
Use the template below to get started. Save it in a file called
46-
`Nat1.ml` and place it in the directory `~/src/frenetic/ox-tutorial-workspace/Nat1.ml`.
46+
`Nat1.ml` and place it in the directory `~/src/frenetic-tutorial-workspace/Nat1.ml`.
4747

4848
~~~ ocaml
49-
(* ~/src/frenetic/ox-tutorial-workspace/Nat1.ml *)
49+
(* ~/src/frenetic-tutorial-workspace/Nat1.ml *)
5050
51-
open OxPlatform
52-
open Packet
53-
open OpenFlow0x01_Core
51+
open Frenetic_Ox
52+
open Frenetic_OpenFlow0x01
53+
open Core.Std
54+
open Async.Std
5455
5556
module MyApplication = struct
56-
57-
include OxStart.DefaultTutorialHandlers
57+
include DefaultHandlers
58+
open Platform
5859
5960
let mappings = Hashtbl.create 50
6061
@@ -88,7 +89,9 @@ module MyApplication = struct
8889
...
8990
end
9091
91-
module Controller = OxStart.Make (MyApplication)
92+
let _ =
93+
let module C = Make (MyApplication) in
94+
C.start ();
9295
9396
~~~
9497

0 commit comments

Comments
 (0)