Mininet Assignment 3: switchring

Due: Friday, July 28 or whenever

Updated August 4

In class we looked at the Mininet program rectangle.py, and the Pox module rectanglepox.py that enabled full connectivity without Ethernet loops. Unicast packets circulated clockwise until they found their destination, and broadcast (ARP) traffic circulated within a manually constructed spanning tree. Specifically, such traffic would never pass s1 -- in either direction -- to continue around the loop.

In this assignment you are to implement switchringpox.py that does the same for the switchring.py Mininet program. In addition, you are to arrange so that packets take the shortest path between hosts, instead of, as in rectanglepox.py, always flowing clockwise. Let si be the current switch, and hj the destination of interest. In config_routes(), i will be the parameter dpid.  There are two cases. In the formulas below, we are now counting additional switches, aside from si, so the +1 that had appeared in the original version no longer applies. (Since the +1 is removed from both formulas, this does not change which path is shorter. The variable N is the size of the ring.
For each destination, choose the direction that minimizes the number of intervening switches.

I've provided the file switchringpox.py as a starting point; it handles the LinkEvent and ConnectionUp events. When every switch is heard from, it calls the following two functions, which you will have to implement:
These are the functions you will have to implement. You may use rectanglepox.py for ideas, though note that N there is fixed at 4 and so routes could be set up by listing each host. If necessary, you may assume that N=5 for switchringpox.py, though it's better to implement the general case. It is config_routes() that has to figure out the shorter direction (cw or ccw) to the destination. The second function, config_broadcast(), will be more similar to the rectanglepox.py version, though the relevant port numbers should be taken from cc and ccw.

The dpid is the number of the switch, eg 4 for s4. The conn parameter is the OpenFlow connection you use to send messages to the switch (eg conn.send(msg)).
 
To start the pox module, navigate to the directory containing pox.py and then run

./pox.py openflow.discovery log.level --WARNING forwarding.switchringpox --N=5

The --N=5 is the default. You can test the code by pinging in the Mininet environment (eg with pingall or h1 ping h4); if that works, then all should be well.

If you copy config_broadcast() from rectanglepox.py, it works fairly well, though bonus points for anyone who can figure out how to prevent duplicate delivery to h1 of flooded packets, or duplicate delivery to other hi's of packets flooded from h1.

A few changes, though, are essential for config_routes(), even to get it to work with purely clockwise routing. First, the Python list [1,2,3,4] is the list of switch numbers; it must at a minimum be replaced by [1,2,3,4,5]. However, a better approach is to notice that [1,2,3,4] is the list returned by range(1,5) (the list of integers starting at 1 and up to but not including 5). Consider using range(1,N+1) in your program. You will also have to change cwport[] to cw[].

Those changes should get the program to support pings. To get the shortest-path behavior, you will for each host hj have to choose the correct port on si (i=dpid) to take the shortest path. Implement the checks above in Python to determine this port. It might be helpful to define a function bestport(dpid,j) to handle all this.