CS456 Assignment 3 F211
CS456 Assignment 3 F211
2) Background
You will find necessary background material in the following textbook chapter sections and articles:
a. Chapter 4 Section 4.4 Generalized Forwarding and SDN
b. Chapter 4 Section 4.5 Middleboxes
c. Chapter 5 Section 5.5 The SDN Control Plane
d. Mininet Documentation at http://mininet.org/overview/
For this assignment, you will have to download a virtual box and virtual machine to run on the virtual box.
1. To download a virtual box, please download and install VirtualBox. (If you own a MacBook with
an M1 processor, please follow the instructions at Section 8.)
2. We have created a virtual machine for CS456 Computer Networking course, which includes the
software needed to complete the assignment. Please download it from here, it will download as
an .ova file.
To run the virtual machine, double-click on the downloaded .ova file, which will open in VirtualBox.
Complete importing the appliance, our virtual machine, without changing the default settings.
Getting Started
Quick setup guide assuming you have VirtualBox installed:
1. Start the provided VM in Virtualbox.
2. After the VM boots, you will see a screen with a password prompt for the user mininet. Enter
mininet as the password.
3. In the CS456 VM provided for this course, you will find all CS456 related files in the directory
/home/mininet/cs456-a3
4. Open a terminal by selecting Menu->System Tools -> MATE Terminal.
5. Enter sudo mn in the terminal, you should see the following output:
The above output shows that Mininet has created a simple network topology with one switch
and two hosts connected to it. Type exit, to exit the Mininet shell, then type sudo mn -c to
clear the created topology.
Note that the creation of your next topology may fail if you do not clear the previous one.
Also, note that you will face problems if you have two instances of Mininet running at the
same time (e.g., in two different terminals).
6. The VM comes with Open vSwitch and a controller pre-installed. Open vSwitch (OVS) is used for
creating a programmable switch, i.e., a switch that works with flow table rules. The controller
installs the rules in the network switches based on the network topology to ensure connectivity
between hosts. Mininet uses OVS and a controller in its default network. To test whether the
controller works, type sudo mn --test pingall in the vm terminal. You should see an
output similar to the illustration below.
Note the logs that state that Mininet is starting the controller. Also note that both hosts are
reachable from one another according to the logs. Again, type in sudo mn -c to clear the
created topology.
7. To see the effect of the controller, we will repeat the above command but ask Mininet to ignore
the controller. Type in the command:
sudo mn --test pingall --controller=none
You should see an output like the one illustrated in the figure below.
We see that Mininet gets stuck, while waiting for the switches to connect. This is because in the absence
of a controller, the switches do not have forwarding rules and do not know how to forward any of the
packets.
For the first two parts of this assignment, Part A and Part B, we will be working without a controller,
meaning that we will be adding static flow table entries to the switches manually, rather than having a
controller do it. The objective is to learn about flow tables and forwarding rules.
The Mininet shell also allows running commands from each node. Try the following commands for
example:
mininet> h1 ifconfig
mininet> s1 ping s2
When running the above commands, the Mininet shell will infer that the first item (h1 in the first
command, s1 in the second) is the name of the node on which to run the rest of the command (ifconfig,
ping s2); it will, behind-the-scenes, enter that node’s bash in your stead.
Furthermore, to access a specific node, you can use:
xterm node_name
In which node_name is the name of the node whose you are trying to access, e.g., h1, s1, etc. This will
open a new terminal window inside the VM. Now, you can run any command, such as, ifconfig inside
that window to see the interfaces of the corresponding node.
Refer to the Mininet walk through for more Mininet commands.
Figure 1. Topology for Part B: Custom Topologies. The squares are hosts for Alice, Bob and Carol. R1 and
R2 are layer-3 switches. S1, S2, and S3 are layer-2 switches. Note that R1, R2, S1 and S3 each have 2
ports, whereas S2 has three ports.
5) Part C: Introducing the Controller
In this part, we explore the SDN controller and its value for configuring networks from a centralized
component. In parts A and B, you have seen how configuring networks at a low level, even for achieving
very simple requirements, can become complex and exhaustive.
However, in the real world, it is often not a human operator that comes up with those OpenFlow rules!
The controller is a centralized software that acts as the brains of the SDN network. Using the SDN
controller, you can instruct high-level policies, such as “host A should be able to ping host B”, and let
the controller figure out how that translates to low-level OpenFlow commands and deploy it on the
network switching devices. The controller is a server that will run in a separate terminal than the one
you will use for Mininet commands. The CS456 VM you are provided with comes with a preinstalled
POX controller.
Follow the instructions below to run a topology connected to the POX controller:
1. Clear any topology you may have running using the sudo mn –c command.
2. Open a terminal, cd to ~/pox
3. Type and run the command below to start the POX controller and open its shell
./pox.py --verbose py openflow.of_01 --port=6633
openflow.discovery forwarding.l2_learning host_tracker
Note, that you will see the controller’s logs in this window after you run the mininet topology.
4. Open a different terminal window, and run the following command
sudo mn --controller=remote,ip=127.0.0.1,port=6633
--topo=tree,depth=3 --mac --switch ovs
This will create a tree topology as illustrated below and connect it to the POX controller on port
6633 that was started in Step 3.
1 2
3 3
1 2 1 2
3 3 3 3
1 2 1 2 1 2 1 2
The objective of this part of the assignment, is to explore the effect of the POX controller on the
network by answering the following questions.
1) Try pinging h5 from h1 (Type h1 ping h5 in mininet). The ping should succeed, even
though you have not installed any OVS rules on the switches yourself. Study the output in
the POX controller terminal. What has the controller done? Include a screenshot of the
output as well as your interpretation of it. Make sure that the screenshot is readable. Hint:
To interpret the effect of the controller, consider the path ping packets must take from h1
to h5. Now consider the number of logs generated by the controller and explain how they
relate to the topology.
2) Take a screenshot of the ping RTT times for the first 5 ping messages. Compare the RTT of
the first ping message with the subsequent ones. Is there a difference? Why or why not?
3) Open a new terminal in the CS456 VM and dump the flow rules installed on switch s1 using
the command, sudo ovs-ofctl dump-flows s1. Dump the flow rules on all the
switches both before and after the ping, make sure you change s1 in the command above to
the appropriate switch name. Compare the initial flows rules with the ones installed in the
switches after initiating ping between hosts. What do you think the initial rules are for? Do
all switches have newly installed flow rules after the ping? Explain why.
Include a screenshot of the terminal showing all the dump commands and their outputs in
your answer, use multiple screenshots, if necessary. The screenshots should be readable
and clearly show which output pertains to which switch. Observe how the OVS rules are
different from the rules you defined in part A. Explain what that indicates about the type of
packet-forwarding that this controller implements?
In this part of the assignment, you will write a program to install the necessary OpenFlow rules to deploy
a simple middlebox. Rather than deploying a complicated middlebox like a firewall or a load-balancer that
requires lots of configuration by systems administrators, we will deploy a very simple middlebox that will
append the utf-8 encoded string “ from the middlebox” to the payload of all the packets it receives.
In the CS456 VM provided for this course, you will find some of the CS456 related files for Part D in the
directory /home/mininet/cs456-a3/partD. We will provide you with a program to send UDP
packets in udp_client.py, the middlebox program cs456_middlebox.py, the custom topology
cs456_tree_topology.py, and a UDP server program in udp_server.py so that you can test
your code. The objective of this part of the assignment will be to use the POX SDN controller to install the
OpenFlow rules necessary for your middlebox to work.
Your program should be able to work in any loop-free network topology. That is, in any loop free network
topology, you should be able to deploy the middlebox program, and use the UDP client program to send
a message to the UDP server program and the message should have “ from the middlebox” appended to
it by the time it reaches the UDP server.
Because your program needs to run within the POX controller framework, the steps for running your
program will be different than that of a traditional python program. To run your program, you will first
start POX and load the required modules.
1. Clear any topology you may have running using the sudo mn –c command.
2. Open a terminal, cd to ~/pox
3. Run the following command:
This will start the POX command line where you can issue commands that run within the POX
controller framework. Notice that we have loaded both the forwarding.l2_learning, the
openflow.discovery and the host_tracker modules. The first,
forwarding.l2_learning module turns every OpenFlow switch that connects to the controller
into a MAC learning switch. This ensures that our ARP requests are switched through the network
correctly. The openflow.discovery module enables the topology discovery features of the POX
controller. In this way, an application can retrieve a graph of the network topology. A network graph
reveals vital information about connectivity and reachability. We use it to compute the shortest path
between the client node and the middlebox node and the middlebox node and the server node. The
third module, the host_tracker, will keep track of the hosts in the network so that we can ask
POX where the hosts are located and retrieve information about their MAC and IP addresses. For host
tracking to work you always need to run pingall from the Mininet console, after you run the POX
controller but before you test your code.
Now that you are running the POX command line you can load all the symbols from the python module
that you are working on by typing:
from cs456.a3 import *
To make the assignment simpler, your application will not need to set up the flow rules to implement
the middlebox functionality in real time, instead you will use the command line interface to provide
your program with the following parameters:
● DPID of the switch that the client host is attached to.
● DPID of the switch that the server host is attached to.
● DPID of the switch that the middlebox host is attached to.
● Source UDP port of the traffic
● Destination UDP port of the traffic
4. Your program will use this information, along with the POX APIs, to install the necessary flow rules
to steer only the UDP traffic from the client host to the middlebox host and finally on to the server
host. The middlebox host, should only receive the UDP traffic that matches the 4-tuple that
defines the packet from the client host to the server host, with source UDP port and destination
UDP port. The middlebox program should append the message “ from the middlebox” onto the
payload of each of the UDP packets it receives and then transmit the augmented packet back out
of its network interface.
5. The POX controller must be programmed for the middlebox functionality we require. The file
/home/mininet/pox/pox/cs456/a3.py provides the code necessary to program the
POX controller. The install_udp_middlebox_flows function, which we have provided for
you in the a3.py file, will print a message encouraging you to complete the assignment by adding
code to this function. The skeleton file also contains some helper functions that should be useful
in completing the assignment. The parameters and return values of each of the helper functions
are documented within the source code. The install_udp_middlebox_flows function
also contains some comments that will guide you in your completion of this part of the
assignment.
To run the program in your controller, type and execute the command below in the POX command
line:
install_udp_middlebox_flows(<client_dpid>,<server_dpid>,<middlebox_dpid>,
source_port,destination_port)
6. Testing Your Program. You are expected to test your implementation of
install_udp_middlebox_flows using Mininet. As was mentioned earlier, your program is expected
to work for in various loop-free network topologies so you should test with two or three different
topologies. The mininet command line program can be used to automatically create a few
different network topologies of various sizes. For example, to create a linear topology with 5
nodes and one host attached to each node run:
We will only use the bult in linear topology, with differing number of hosts, to evaluate your
submission. However, for testing we have provided an additional custom topology. The topology is a
tree topology where the branching factor of the tree is always two and there is a host connected to
every node in the tree. You can instantiate this custom topology using the command:
sudo mn --mac \
--custom /home/mininet/cs456-utils/cs456_tree_topology.py \
--topo=SimpleTreeTopo,3 \
--controller=remote,ip=127.0.0.1,port=6633
Once you have started Mininet you need to start the middlebox program on the middlebox host
that you have chosen and the server program on the server host that you have chosen.
Finally, you need to follow the steps described in step 5 to run install_udp_middlebox_flows with
the DPID’s that correspond to your client, server and middlebox hosts. All the programs that are
to be run on the hosts in the network are in /home/mininet/cs456-a3/part-D directory and will
tell you the parameters they need if you invoke them with the --help flag.
You can start an xterm session on the client, middlebox and server hosts from the Mininet
terminal and run the appropriate programs from the /home/mininet/cs456-a3/part-D directory
with the correct parameters to transmit a message from client host to server host. The controller
program you wrote should install the appropriate flow rules to enable the middlebox functionality
that is required for Part D of this assignment. The expected result is that for every UDP packet
sent from client host with source port, the server host should print a log line with the message
that was sent appended with the phrase “ from the middlebox.”
8) VM on M1 Macs
The Apple M1 is an ARM-based CPU, so you cannot install VirtualBox and use Intel-based VMs such as the
one provided for this assignment easily like the others. It is strongly suggested that you find another
machine to complete this assignment, since there will be performance degradations with the solution
below. If that is not possible for you, then follow these instructions.
1. Download and install UTM from this link, by clicking on the download button (NOT the Mac
App Store button, that one is not free). Once downloaded, run the .dmg file.
2. Download this .qcow2 file.
3. In the opened UTM window, click on the Create a New Virtual Machine button.
4. Go to the Drive tab and import the downloaded .qcow2 file.
5. Go to the System tab and disable UEFI Boot.
6. Go to the Display tab and change virtio-vga-gl to virtio-vga.
7. Save and run the machine. It is going to be really slow at first, so give it some time for the
initial background processes to settle.
8. Feel free to do your research and play with different options to find out whether you can
somehow make it faster…
9) Deliverables
1) For Part A there are two deliverables:
1. The file partA.md, which explains what each field name in the first add-flow command in
the provided file means. Each field should be explained in no more than one sentence.
2. submit a file named partA_connect.sh, which includes the OVS commands that
enable only the following pairs of hosts to ping each other and only each other:
h2 ↔︎ h4 h1 ↔︎ h6 h0 ↔︎ h3
Make sure that after you run the provided topology.py and partA_connect.sh in two
separate terminal windows, the specified host pairs can ping each other with no other steps
required. You will lose marks if any additional hosts can ping each other, or if any of the
mentioned hosts cannot ping each other. Your script MUST contain OVS routing entries and
comments similar to those provided to you in the walkthrough.
2) For Part B, there are two deliverables:
1. submit the Python code for implementing the topology for Part B, in a file named
partB_topology.py.
2. The shell script partB_connect.sh that allows for the connection of hosts as described
in part B.
3) For Part C, there is one deliverable, a file named partC.pdf that clearly answers the three
questions asked in part C, by including explanations that are justified by one or more of the
required screenshots.
4) For Part D, there is one deliverable, your completed /home/pox/pox/cs456/a3.py file.