This homework will cover the some of the networking in cloud computing. In particular it will introduce you to software defined networking (SDN). Scott Shenker, professor at the UC Berkeley are giving a lot of good talks on SDN and why we need it, one of which you can find here. The homework is based on this Github turorial so if you find the instructions here confusing, I recommend that you look around in that one:)
The goal of this homework is to develop a network control application using OpenFlow. OpenFlow is an open interface for remotely controlling the forwarding tables in network switches, routers and access points. The network we will control will be built on Mininet, which creates a realistic virtual network on a single machine (VM).
There are a bunch of available controller platforms to build this application on. However, we recommend using POX (which is written in python). The rest of this homework will be based on it, but as usual, feel free to use whatever platform you wish!
The structure of the homework is as follows:
Some platforms:
Java: Beacon, Floodlight
Ruby: Trema
Deadline for this homework is March 31. You will hand in the source code (usually just two files) and a short text (1/4 - 1/2 page) that answers the following questions:
As with the privious homeworks this one does also reqwuire you to install some software. First off you will need to install a Virtual Machine (like VirualBox which is free, or VMware).
ssh
into your virtual machine!ssh
into your virtual machine (VM)$ git clone http://github.com/noxrepo/pox
There are many different ways of creating a network topology in mininet. Most of them are explained here
To prepare for the next homework assignment, we will learn how to create and define a topology using the mininet API, and Pyhton. Make sure to download and look through our file hw3_start.py
(can be found here). In this file we have already created a topology corresponding to the figure below. It also contains some useful comments on how you can change the file so that the switches can use a remote controller - which is exactly what you want when you will create your learning switch!
Follow these steps to familiarize yourself with the topology, and the mininet API:
ssh
into your VMhw3_start.py
into your VM - can be found here$ sudo ./hw3_start.py
mininet> pingall
mininet> h1 ping h2
mininet> h1 ifconfig
mininet> s1 ifconfig
mininet> exit
hw3_start.py
in a text editor:
$ sudo ./hw3_start.py
When running a remote controller it is up to you to make sure that you actually connect a controller. The controller you specified in your mininet topology (in hw3_start.py
) will only ensure that your switch(es) listen for a connection from a remote controller.
These steps will guide you on how to connect a remote controller to your network switch. The remote controller that we will connect is the one that currently acts as a hub. You will later edit this controller so that it instead acts as a learning switch.
ssh
into your VM on both of them
hw3_start.py
-file$ sudo ./hw3_start.py
mininet> pingall
pox
-folder: $ cd pox/
pox/misc/of_tutorial.py
$ ./pox.py log.level --DEBUG misc.of_tutorial
/misc/of_tutorial.py
POX 0.1.0 (betta) / Copyright 2011-2013 James McCauley, et al.
DEBUG:core:POX 0.1.0 (betta) going up...
DEBUG:core:Running on CPython (2.7.6/Mar 22 2014 22:59:56)
DEBUG:core:Platform is Linux-3.13.0-24-generic-x86_64-with-Ubuntu-14.04-trusty
INFO:core:POX 0.1.0 (betta) is up.
DEBUG:openflow.of_01:Listening on 0.0.0.0:6633
INFO:openflow.of_01:[00-00-00-00-00-02 1] connected
DEBUG:misc.of_tutorial:Controlling [00-00-00-00-00-02 1]
INFO:openflow.of_01:[00-00-00-00-00-01 2] connected
DEBUG:misc.of_tutorial:Controlling [00-00-00-00-00-01 2]
mininet> pingall
mininet> h1 ping h5
mininet> iperf
This is the main part of the homework assignment. Here you will take the provided controller (of_tutorial.py
) which acts as a hub and turn it into a learning switch. You should have done the above steps before doing this one!
ssh
into your VM$ cd pox/
pox/misc/of_tutorial.py
in your favorite text editorself.act_like_hub(packet, packet_in)
from _handle_PacketIN()
self.resend_packet(packet_in, of.OFPP_ALL)
self.act_like_switch(packet, packet_in)
$ ./pox.py log.level --DEBUG misc.of_tutorial
of_tutorial.py
to build your learning switch.If you are unfamiliar with Python, you can check out some good commands below, or this turorial.
mactable = {}
- Initialize a dictionarymactable[0x123] = 2
- Add an element to itCheck for a member in the dictionary:
if 0x123 in mactable:
print 'element 2 is in mactable'
if 0x123 not in mactable:
print 'element 2 is not in mactable'
log.debug('saw a new MAC!')
- Print a debug message in POX
log.error('unexpected packet causing system meltdown!')
- Print an error message in POXprint dir(object)
- Print all member variables and functions of an objectprepend code with a #
- Comment a line of codeI highly recommend the OpenFlow POX wiki for any question on OpenFlow and POX. However, I will list some useful commands below:
packet.src
- Get the source of a packet (the parsed packet data)packet.dst
- Get the destination of a packet (the parsed packet data)packet_in.in_port
- Get the inport of a packet_in
(the actual ofp_packet_in
message)self.resend_packet(packet_in, out_port)
- Send a packet to a certain portlog.debug("Sent packet: %s.%i -> %s.%i" %(mac_src, inport, mac_dst, outport))
- Example of a log.debug
messageTo install a flow table entry into a switch you will have to send an ofp_flow_mod
message to it. The message contains some fields that need to be set.
ofp_flow_mod
message fields:
idle_timeout
- Number of idle seconds before the flow entry is removed. Defaults to no idle timeout.hard_timeout
- Number of seconds before the flow entry is removed. Defaults to no timeout.actions
- A list of actions to perform on matching packets (e.g., ofp_action_output
)buffer_id
- The buffer_id of a buffer to apply the actions to immediately.in_port
- If using a buffer_id
, this is the associated input port.match
- An ofp_match
object. By default, this matches everything, so you should probably set some of its fields!ofp_match
fields:
dl_src
- The data link layer (MAC) source address.dl_dst
- The data link layer (MAC) destination address.in_port
- The packet input switch port.Some examples of how to use these fields:
msg = of.opf_flow_mod()
msg.match.dl_src = ...
msg.match.dl_dst = ...
msg.idle_timeout = ...
msg.hard_timeout = ...
msg.actions.append(of.ofp_action_output(port = outport))
msg.buffer_id = packet_in.buffer_id
self.connection.send(msg)