Skip to content

Commit

Permalink
Bootstrapification
Browse files Browse the repository at this point in the history
  • Loading branch information
Arjun Guha committed Jul 23, 2014
1 parent 8dfff01 commit ad7e938
Show file tree
Hide file tree
Showing 29 changed files with 9,230 additions and 78 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_site
37 changes: 21 additions & 16 deletions 02-OxRepeater.md → 02-OxRepeater/index.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
layout: main
title: Frenetic Tutorial
---

Chapter 2: Repeater
====================

Expand Down Expand Up @@ -117,7 +122,7 @@ end
module Controller = OxStart.Make (MyApplication)
```

Within the body of `packet_in`, you need to use `send_packet_out`,
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
Expand All @@ -135,7 +140,7 @@ every port (excluding the input port). This is easier than it
sounds, because you can do it with just one OpenFlow action.

Find the right action in the Ox manual (it is in the [OpenFlow_Core]
module) and fill it in.
module) and fill it in.

<h4 id="compiling">Compiling your Controller</h4>

Expand Down Expand Up @@ -176,7 +181,7 @@ hosts and have them ping each other:

* `--mac` sets the hosts' mac addresses to 1, 2, 3, and 4 (instead
of random numbers). This makes debugging a lot easier.

* `--arp` statically configures the ARP tables on all hosts, so you don't have to
deal with ARP broadcast traffic.

Expand All @@ -197,7 +202,7 @@ hosts and have them ping each other:
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:

```
Expand All @@ -224,7 +229,7 @@ hosts and have them ping each other:
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
see the controller receiving all pings.
Expand Down Expand Up @@ -254,15 +259,15 @@ h2 h2-eth0:s1-eth2

<p>
Line 1 tells you there is a controller (<code>c0</code>) running. Line 2
describes the ports on switch <code>s1</code>. In particular,
describes the ports on switch <code>s1</code>. In particular,
switch 1 port 1 (<code>s1-eth1</code>) is connected to host <code>h1</code>.
Likewise, switch 1 port 2 (<code>s1-eth2</code>) is connected to
Likewise, switch 1 port 2 (<code>s1-eth2</code>) is connected to
host <code>h2</code>. If there was more than one switch in the network, we would
see additional lines prefixed by the switch identifier, one line
per switch. Lines 3 and 4 describe the hosts <code>h1</code>
per switch. Lines 3 and 4 describe the hosts <code>h1</code>
and <code>h2</code>.
</blockquote>

### Exercise 2: An Efficient Repeater

Processing all packets at the controller is very inefficient.
Expand Down Expand Up @@ -366,13 +371,13 @@ implement a policy change, you may see packets at the controller.
## Next chapter: [Ox Firewall][Ch3]


[Ch2]: 02-OxRepeater
[Ch3]: 03-OxFirewall
[Ch4]: 04-OxMonitor
[Ch5]: 05-OxLearning
[Ch6]: 06-NetCoreIntroduction
[Ch7]: 07-NetCoreComposition
[Ch8]: 08-DynamicNetCore
[Ch2]: /02-OxRepeater
[Ch3]: /03-OxFirewall
[Ch4]: /04-OxMonitor
[Ch5]: /05-OxLearning
[Ch6]: /06-NetCoreIntroduction
[Ch7]: /07-NetCoreComposition
[Ch8]: /08-DynamicNetCore

[OpenFlow_Core]: https://github.com/frenetic-lang/ocaml-openflow/blob/master/lib/OpenFlow0x04_Core.mli

Expand Down
21 changes: 13 additions & 8 deletions 03-OxFirewall.md → 03-OxFirewall/index.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
layout: main
title: Frenetic Tutorial
---

Chapter 3: Firewall
===================

Expand Down Expand Up @@ -88,7 +93,7 @@ module Controller = OxStart.Make (MyApplication)

- On the controller terminal, you should see the controller receiving
several ICMP echo requests, but no ICMP echo replies:

<pre>
Switch 1 connected.
packetIn{
Expand Down Expand Up @@ -186,13 +191,13 @@ packets at the controller.

[Packet]: http://frenetic-lang.github.io/frenetic/docs/Packet.html

[Ch2]: 02-OxRepeater
[Ch3]: 03-OxFirewall
[Ch4]: 04-OxMonitor
[Ch5]: 05-OxLearning
[Ch6]: 06-NetCoreIntroduction
[Ch7]: 07-NetCoreComposition
[Ch8]: 08-DynamicNetCore
[Ch2]: /02-OxRepeater
[Ch3]: /03-OxFirewall
[Ch4]: /04-OxMonitor
[Ch5]: /05-OxLearning
[Ch6]: /06-NetCoreIntroduction
[Ch7]: /07-NetCoreComposition
[Ch8]: /08-DynamicNetCore

[OpenFlow_Core]: http://frenetic-lang.github.io/frenetic/docs/OpenFlow0x01_Core.html

Expand Down
15 changes: 10 additions & 5 deletions 04-OxMonitor.md → 04-OxMonitor/index.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
layout: main
title: Frenetic Tutorial
---

Chapter 4: Traffic Monitoring
=============================

Expand Down Expand Up @@ -45,7 +50,7 @@ module Stats = OpenFlow0x01_Stats
module MyApplication = struct
include OxStart.DefaultTutorialHandlers
(* [FILL] copy over the packet_in function from Firewall.ml
verbatim, including any helper functions. *)
let firewall_packet_in (sw : switchId) (xid : xid) (pktIn : packetIn) : unit =
Expand All @@ -56,7 +61,7 @@ module MyApplication = struct
false
let num_http_packets = ref 0
let packet_in (sw : switchId) (xid : xid) (pktIn : packetIn) : unit =
Printf.printf "%s\n%!" (packetIn_to_string pktIn);
firewall_packet_in sw xid pktIn;
Expand Down Expand Up @@ -146,7 +151,7 @@ port 80 increments the counter (and that other traffic does not).
- Finally, you should test that other traffic is neither blocked by
the firewall nor counted by your monitor. To do so, kill the fortune
the firewall nor counted by your monitor. To do so, kill the fortune
server running on `h1` and start a new fortune server on a non-standard
port (e.g., 8080):
Expand Down Expand Up @@ -225,7 +230,7 @@ To do so, you can use the following function:
```ocaml
let rec periodic_stats_request sw interval xid pat =
let callback () =
Printf.printf "Sending stats request to %Ld\n%!" sw;
Printf.printf "Sending stats request to %Ld\n%!" sw;
send_stats_request sw xid
(Stats.AggregateRequest (pat, 0xff, None));
periodic_stats_request sw interval xid pat in
Expand Down Expand Up @@ -257,7 +262,7 @@ responses from the switch and calculate the sum of the two
counters. We've provided one below:

```ocaml
let num_http_request_packets = ref 0L
let num_http_request_packets = ref 0L
let num_http_response_packets = ref 0L
let stats_reply (sw : switchId) (xid : xid) (stats : Stats.reply) : unit =
Expand Down
19 changes: 12 additions & 7 deletions 05-OxLearning.md → 05-OxLearning/index.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
layout: main
title: Frenetic Tutorial
---

Chapter 5: Learning Switch
==========================

Expand All @@ -24,14 +29,14 @@ A learning switch has two logically distinct components:
builds this table by inspecting the source ethernet address and inport
of every packet at the switch.

- The *routing module* uses this table in order to route incoming traffic:
if the switch receives a packet for destination _X_ and the learning
module has learned that _X_ is accessible through port _N_, then the
routing module forwards the packet directly out port _N_. (If the table
- The *routing module* uses this table in order to route incoming traffic:
if the switch receives a packet for destination _X_ and the learning
module has learned that _X_ is accessible through port _N_, then the
routing module forwards the packet directly out port _N_. (If the table
does not have an entry for _X_, it simply floods the packet.)

Naturally, you will begin by writing a `packet_in` function that learns host
locations.
locations.

#### Programming Task

Expand Down Expand Up @@ -174,7 +179,7 @@ from `h2` to `h3`. No traffic should reach `h1`.
Together, these flags cause `tcpdump` to exit as soon as a packet arrives on port 80.
* In the terminal for `h2`, start a local fortune server:
```
# while true; do fortune | nc -l 80; done
```
Expand Down Expand Up @@ -226,7 +231,7 @@ arrive on the controller.
#### Compiling and Testing your Efficient Learning Switch
You should build and test your learning switch as before.
You should build and test your learning switch as before.
## Next chapter: [Network Address Translator][Ch6]
Expand Down
35 changes: 20 additions & 15 deletions 06-OxNat.md → 06-OxNat/index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
---
layout: main
title: Frenetic Tutorial
---

Chapter 6: Network Address Translator
==========================

In this exercise, you will build a Network Address Translator (NAT) by first writing and
In this exercise, you will build a Network Address Translator (NAT) by first writing and
testing a translator function that first translates IP addresses and then extending
it so that it translates port numbers as well.

Expand All @@ -12,11 +17,11 @@ Before NAT was invented, all IP addresses were globally unique. NAT allows priva
to be reused in multiple local area networks (LAN) by translating all private IP addresses in
a LAN to one globally unique public IP address. NAT essentially does the following:

* For packets received on private (internal) ports, NAT rewrites the private IP address
* For packets received on private (internal) ports, NAT rewrites the private IP address
to the public IP address and installs rules to forward the packet to the public port.
* NAT will also store relevant information for each packet in a data structure,
* NAT will also store relevant information for each packet in a data structure,
such as a hashtable.
* For packets received on the public (external) port, NAT checks to see if the TCP port
* For packets received on the public (external) port, NAT checks to see if the TCP port
destination of the packet matches the TCP port source of any of the packets stored in
the data structure.
* If so, the public IP address of the packet is rewritten to the corresponding private
Expand Down Expand Up @@ -59,25 +64,25 @@ module MyApplication = struct
let privateIP2 = 167772162l
let switch_connected (sw:switchId) feats : unit =
let switch_connected (sw:switchId) feats : unit =
Printf.printf "Switch Connected %Ld\n%!" sw
let packet_in (sw: switchId) (xid : xid) (pktIn : packetIn) : unit =
let packet_in (sw: switchId) (xid : xid) (pktIn : packetIn) : unit =
let pk = parse_payload pktIn.input_payload in
(* If the packet is of type TCP and came in through port 1 or 2 *)
if (pktIn.port = 1 || pktIn.port = 2)
&& Packet.dlTyp pk = 0x800
&& Packet.nwProto pk = 0x06
if (pktIn.port = 1 || pktIn.port = 2)
&& Packet.dlTyp pk = 0x800
&& Packet.nwProto pk = 0x06
then
(* [FILL] Add packet info into hashtable and install rules to
(* [FILL] Add packet info into hashtable and install rules to
forward packet out of correct port *)
...
else (* For packets arriving on port 3 *)
try (* If a mapping is found in the hashtable *)
Printf.printf "Non TCP or incoming flow %s \n" (packetIn_to_string pktIn);
(* [FILL] Install reverse rules to forward packet back to correct host *)
...
with Not_found ->
with Not_found ->
(* [FILL] If no mapping is found in hashtable then drop the packet *)
...
end
Expand Down Expand Up @@ -124,21 +129,21 @@ The first command adds a static entry into the arp table that binds your public
address to your public IP address.

* In the terminal for `h1`, fetch a fortune from `h3`.

```
# curl 10.0.0.3:80
```
You should’ve received a fortune. Now try to fetch a fortune on the `h2` terminal.

* In the terminal for the controller, check to see that your IP addresses are translating
correctly.

```
Outgoing flow packetIn{
total_len=74 port=1 reason=NoMatch
payload=dlSrc=00:00:00:00:00:01,dlDst=00:00:00:00:00:03,
nwSrc=10.0.0.1,nwDst=10.0.0.3,tpSrc=42635;tpDst=80 (buffered at 256)
Translating Private IP:167772161 to Public IP:167772259.
```
* Incoming packets should look similar to this:
Expand Down Expand Up @@ -192,7 +197,7 @@ Compile and test your controller the same way that you did before.
```

* Incoming packets should look similar to this:

```
Non TCP or incoming flow packetIn{
total_len=74 port=3 reason=NoMatch
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
layout: main
title: Frenetic Tutorial
---

Chapter 7: Introducing Frenetic
==============================

Expand Down Expand Up @@ -32,7 +37,7 @@ efficient repeater by adding rules to the switch flow table. Recall that a
repeater simply forwards incoming packets out all other ports.

In this example, we will begin by considering a network with just one switch
with two ports, numbered 1 and 2:
with two ports, numbered 1 and 2:

![Default Mininet topology.][topo_1]

Expand Down Expand Up @@ -61,7 +66,7 @@ OpenFlow-supported fields, such as the <code>srcIP</code>, <code>dstIP</code>
or <code>dlTyp</code>. Conditions can also be formed using conjunctions
(<code>&&</code>), disjunctions (<code>||</code>) and negation (<code>!</code>)
of other conditions. See the [manual](A-NCManual) for the complete list of
predicates.
predicates.

The last line of the program uses <code>monitorTable(1,repeater)</code>, which
will print the flow table generated for switch <code>1</code> from the
Expand Down Expand Up @@ -111,7 +116,7 @@ all ports on that switch except the port it arrived on. Try testing
that out too to see if you have done it correctly.

The opposite of the <code>all</code> policy is the <code>drop</code> policy,
which drops all packets on the floor.
which drops all packets on the floor.

## Next chapter: [Firewall Redux][Ch7]

Expand Down
Loading

0 comments on commit ad7e938

Please sign in to comment.