Skip to content

Commit

Permalink
fixed codeblock formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Arjun Guha committed Jul 23, 2014
1 parent 002385e commit c556621
Show file tree
Hide file tree
Showing 11 changed files with 264 additions and 264 deletions.
56 changes: 28 additions & 28 deletions 02-OxRepeater/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ use the template below.
Save it in a file called `Repeater.ml` and place it in the directory
`~/src/frenetic/ox-tutorial-workspace/Repeater.ml`.

```ocaml
~~~ ocaml
(* ~/src/frenetic/ox-tutorial-workspace/Repeater.ml *)
open OxPlatform
open OpenFlow0x01_Core
Expand All @@ -118,20 +118,20 @@ module MyApplication = struct
end
module Controller = OxStart.Make (MyApplication)
```
~~~

Within the body of `packet_in`, you need to use `send_packet_out`,
which takes a list of actions (`apply_actions`) to apply to the packet:

```ocaml
~~~ ocaml
let packet_in (sw : switchId) (xid : xid) (pk : packetIn) : unit =
Printf.printf "%s\n%!" (packetIn_to_string pk);
send_packet_out sw 0l {
output_payload = pk.input_payload;
port_id = None;
apply_actions = ... (* [FILL] *)
}
```
~~~

You need to fill in the list of actions to send the packet out of
every port (excluding the input port). This is easier than it
Expand All @@ -144,20 +144,20 @@ module) and fill it in.

To build your controller, run the following command:

```
~~~
$ make Repeater.d.byte
```
~~~

> The file extension indicates that it is a bytecode, debug build. You
> can use `make foo.d.byte` to compile any `foo.ml` file in this
> directory.
If compilation succeeds, you should see output akin to this:

```
~~~
ocamlbuild -use-ocamlfind Repeater1.d.byte
Finished, 4 targets (4 cached) in 00:00:00.
```
~~~

#### Testing your Controller

Expand All @@ -169,9 +169,9 @@ hosts and have them ping each other:

- Start Mininet in a separate terminal window:

```
~~~
$ sudo mn --controller=remote --topo=single,4 --mac --arp
```
~~~

A brief explanation of the flags:

Expand All @@ -193,17 +193,17 @@ hosts and have them ping each other:

- Start your controller back in the original terminal:

```
~~~
$ ./Repeater.d.byte
```
~~~

It should print `[Ox] Controller launching...`
and then you should see switch 1 connecting to the controller:
`[Ox] switch 1 connected`.

- From the Mininet prompt, you can make your hosts ping each other:

```
~~~
mininet> h1 ping h2
PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data.
64 bytes from 10.0.0.2: icmp_req=1 ttl=64 time=1.97 ms
Expand All @@ -214,9 +214,9 @@ hosts and have them ping each other:
--- 10.0.0.2 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3006ms
rtt min/avg/max/mdev = 1.926/2.144/2.461/0.213 ms
```
~~~

```
~~~
mininet> h2 ping h1
PING 10.0.0.1 (10.0.0.1) 56(84) bytes of data.
64 bytes from 10.0.0.1: icmp_req=1 ttl=64 time=1.98 ms
Expand All @@ -226,7 +226,7 @@ hosts and have them ping each other:
--- 10.0.0.1 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2005ms
rtt min/avg/max/mdev = 1.983/2.280/2.453/0.214 ms
```
~~~

Pinging should always succeed ("0% packet loss"). In addition, if
your controller calls `printf` in its packet-in function, you will
Expand Down Expand Up @@ -277,11 +277,11 @@ For this part, continue building on the naive repeater you wrote above. Build on
Your task is to write a `switch_connected` handler in your program,
using the following as a template:

```ocaml
~~~ ocaml
let switch_connected (sw : switchId) feats : unit =
Printf.printf "Switch %Ld connected.\n%!" sw;
send_flow_mod sw 1l (add_flow priority pattern action_list)
```
~~~

This function uses `send_flow_mod` to add a new rule to
the flow table. Your task is to fill in `priority`, `pattern`, and
Expand All @@ -306,22 +306,22 @@ receive any packets itself.

- In a separate terminal, start Mininet:

```
~~~
$ sudo mn --controller=remote --topo=single,4 --mac
```
~~~

- Build and start the controller:

```shell
~~~ shell
$ make Repeater.d.byte
$ ./Repeater.d.byte
```
~~~

- From the Mininet prompt, try a ping:

```
~~~
mininet> h1 ping h2
```
~~~

The pings should succeed, but the controller won't receive any
packets (keep a `printf` in the `packet_in` function to observe
Expand All @@ -341,15 +341,15 @@ function is necessary. We'll try to create such a situation artificially:

- In mininet, send a stream of high-frequency pings:

```
~~~
mininet> h1 ping -i 0.001 h2
```
~~~

- Launch the repeater again:

```
~~~
$ ./Repeater.d.byte
```
~~~

It is very likely that a few packets will get sent to the controller,
and here's why. When you launch the controller and the switch
Expand Down
36 changes: 18 additions & 18 deletions 03-OxFirewall/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ To do so, you need to parse the packet received. Ox includes a packet
parsing library that supports some common packet formats, including ICMP.
You can use it to parse packets as follows:

```ocaml
~~~ ocaml
let packet_in (sw : switchId) (xid : xid) (pktIn : packetIn) : unit =
let pk = parse_payload pktIn.input_payload in
...
```
~~~
Applying `parse_payload` parses the packet into a series of nested
frames. The easiest way to examine packet headers is to then use the
[header accessor functions] in the packet library.
Expand All @@ -39,7 +39,7 @@ is 0x800 (`Packet.dlTyp pk = 0x800`) and the protocol number for ICMP is 1
You can use the following template, which only requires you to fill
in the `is_icmp_packet` function.

```ocaml
~~~ ocaml
open OpenFlow0x01_Core
open OxPlatform
Expand All @@ -61,30 +61,30 @@ module MyApplication = struct
end
module Controller = OxStart.Make (MyApplication)
```
~~~

### Building and Testing Your Firewall

- Build and launch the controller:

```shell
~~~ shell
$ make Firewall.d.byte
$ ./Firewall.d.byte
```
~~~

- In a separate terminal window, start Mininet using the same
parameters you've used before:

```
~~~
$ sudo mn --controller=remote --topo=single,4 --mac --arp
```
~~~

- Test to ensure that pings fail within Mininet:

```
~~~
mininet> h1 ping -c 1 h2
mininet> h2 ping -c 1 h1
```
~~~

These command should fail, printing `100.0% packet loss`.

Expand Down Expand Up @@ -118,22 +118,22 @@ packetIn{

* In Mininet, start new terminals for `h1` and `h2`:

```
~~~
mininet> xterm h1 h2
```
~~~
* In the terminal for `h1` start a local "fortune server" (a server
that returns insightful fortunes to those who query it):
```
~~~
# while true; do fortune | nc -l 80; done
```
~~~
* In the terminal for `h2` fetch a fortune from `h1`:
```
~~~
# curl 10.0.0.1:80
```
~~~
This command should succeed.
Expand All @@ -147,12 +147,12 @@ Fill in the `switch_connected` event handler. You need to install two
entries into the flow table: one for ICMP traffic and the other for
all other traffic. Use the following template:
```ocaml
~~~ ocaml
let switch_connected (sw : switchId) feats : unit =
Printf.printf "Switch %Ld connected.\n%!" sw;
send_flow_mod sw 0l (add_flow priority1 pattern1 actions1);
send_flow_mod sw 0l (add_flow priority2 pattern2 actions2)
```
~~~

You have to determine the priorities, patterns, and actions in the
handler above. You might want to revisit the description of flow
Expand Down
Loading

0 comments on commit c556621

Please sign in to comment.