cn ยป

Assignment 4 - Learning Switch


In this assignment, you will use Mininet to implement a learning switch. The goal is to actually implement the correct forwarding behavior of a Layer 2 Ethernet switch.

Switches learn paths such that they don't flood (broadcast) excessively. They do this by learning the paths to the foreign MACs, and, upon receiving a packet destined for the foreign switch, they will only send out the correct path. We will go over how learning switches again in the overview section.

We will gloss over the Spanning Tree Protocol, by using a much simpler topology. Additionally, there are modules that implement learning switches already, but we are not using these. Remember, do not use these, the use of pre-implemented modules will be considered plagiarism.


Learning Switch Review


Consider the above topology. When the topology has just come up, the switch tables are empty. When a packet goes from Host 1 (with MAC address 1, for simplicity's sake), and is destined for Host 2, it first goes to Switch A. Switch A will record which port Host 1 came in on. Since Switch A does not know where the MAC address for 2 is, will flood and send a copy of the packet to both remaining ports. It will reach Host 2, but it will also reach Switch 2. Switch 2 will save off how to get to Host 1 (via Switch 1), and flood to hosts 3 and 4.

If, afterward, Host 3 is trying to send a packet to Host 1, Switch 2 learn how to get to Host 3, will not flood and send it directly to Switch 1. Switch 1 will also learn how to get to Host 3 (via Switch 2), and forward directly to Host 1.

Mininet Setup


Above is the topology provided for the assignment. There are significantly more switches than in the review, however this allows for more test cases possible.


  1. We need to edit the function learn_route() within This is marked with TODO as in previous assignments. This function fills in the switch tables as described above. Details are within the TODO block.

  2. Next, you must test that the learning switches are working by loading the topology in For this, you'll need two terminals: one for mininet, and one for the controller running Run the topology by using sudo python from within the directory ~/gt-cs6250/assignment-4/. To run the controller, first you need to copy the file to the directory ~/pyretic/pyretic/modules/. Second, you need to be in the directory ~/pyretic/ - this is very important - and run python -m p0 pyretic.modules.learning-switch

  3. To test, issuing ping commands is the easiest way. The ARPs will flow out, and the ARP response will go back on a more direct reverse path, as all switches will know how to reach the original issuer. Ping is just a mechanism for getting ARP to populate the switch tables. The controller program will print out the table whenever there is an update decision made, which is how you can check the correct functionality.

  4. Turn in the file along with a text file named hw4.txt with the answers for the quiz questions below via T-Square for grading. These should be two files, not in a zip or tarball.


  1. Which address are packets in a Layer-2 network forwarded based upon?

    • A - Source MAC address
    • B - Destination MAC address
    • C - Source IP address
    • D - Destination IP Address
  2. Which address are packets in a Layer-2 network learned based upon?

    • A - Source MAC address
    • B - Destination MAC address
    • C - Source IP address
    • D - Destination IP Address