We will show how to use the POX SDN controller to update flow tables on the SDN switches in a simulated network so every host on the network can forward packets to another host. We will use the Mininet network simulator to create the network of emulated SDN switches and hosts that are controlled by the POX SDN controller.
Mininet is an open-source network simulator designed to support research and education in the topic of software defined networks. If you are not already familiar with Mininet, you should review the following posts before starting this tutorial:
- Set up the Mininet network simulator VM
- Using the Mininet network simulator
- Using MiniEdit, the Mininet GUI
More information about Mininet is available at the Mininet web site.
POX provides a framework for communicating with SDN switches using either the OpenFlow or OVSDB protocol. Developers can use POX to create an SDN controller using the Python programming language. It is a popular tool for teaching about and researching software defined networks and network applications programming.1
POX can be immediately used as a basic SDN controller by using the stock components that come bundled with it. This is the scenario we will cover in this tutorial.
Developers may create a more complex SDN controller by creating new POX components. Or, developers may write network applications that address POX’s API. In this tutorial, we only briefly discuss programming for POX.
See the POX documentation to learn more about POX.
POX components are additional Python programs that can be invoked when POX is started from the command line. These components implement the network functionality in the software defined network. POX comes with some stock components already available.
The POX stock components are documented in the POX Wiki and the code for each component can be found in the ~/pox/pox directory on the Mininet 2.2 VM image.
For example, the forwarding.l2_learning component is in the ~/pox/pox/forwarding directory, as seen below:
$ cd pox/pox $ ls boot.py datapaths info log proto tk.py boot.pyc forwarding __init__.py messenger py.py topology core.py help.py __init__.pyc misc py.pyc web core.pyc host_tracker lib openflow samples $ cd forwarding $ ls hub.py l2_flowvisor.py l2_nx.py l3_learning.py __init__.py l2_learning.py l2_nx_self_learning.py l3_learning.pyc __init__.pyc l2_multi.py l2_pairs.py topo_proactive.py $
Programming for POX
The general purpose of all SDN controllers, including POX, is to allow users to write their own applications that use the controller as an intermediary — or abstraction layer — between network applications and the network equipment.
To learn how to write applications for POX, developers may study the stock POX components as examples that show how to write their own components or they may review the POX API documentation to learn how to write networking applications that use the POX Python API.
POX comes already installed on the Mininet 2.2 VM image. In this tutorial, we will use the VM image. See my previous post about setting up the Mininet 2.2 VM.
If you wish to install Mininet and POX on your own Linux system — either hardware or a virtual machine — you may use the Mininet install script, which also installs the POX controller when it installs Mininet.
If you wish to install POX by itself, follow the POX installation instructions from the POX documentation.
Start POX by running the pox.py program, and specifying the POX components to use. For example, to run POX so it makes the switches it controls emulate the behavior of Ethernet learning switches, run the command:
mininet@mininet-vm:~$ sudo ~/pox/pox.py forwarding.l2_learning
The POX Console
The POX console is the terminal session from which we run the POX controller. After POX starts, it will display log information and may optionally display an interactive Python command line, if POX is started with the py component.
To quit POX, use the control-C key combination in the POX console.
Create a network of switches and hosts
In this tutorial we assume you have already set up a Mininet VM in VirtualBox. Start VirtualBox and then start the VM.
Log into the VM using SSH with X forwarding enabled. From a terminal window on your computer, enter the following command (use PuTTY if you use Microsoft Windows):
brian@t400:~$ ssh -X firstname.lastname@example.org
Where 192.168.56.102 is the IP address of the VM’s connection to the host-only network. (The address may be different in your case)
We will use MiniEdit, the Mininet graphical user interface, to set up an emulated network made up of OpenFlow switches and Linux hosts.
To start Mininet, run the following command on a terminal window connected to the Mininet VM:
mininet@mininet-vm:~$ sudo ~/mininet/examples/miniedit.py
Now the Mininet window will appear on your computer’s desktop. (If you see display errors, first check that you have X forwarding enabled on the SSH connection to the Mininet VM)
Build the network and use a remote controller
Build the network consisting of a tree to switches with a central core switch connected to two other switches that are connected to two hosts, each. Connect a controller to all the switches.
Ensure that the MiniEdit preferences are set so that we can use the MiniEdit command line after starting the simulation. Click on the Start CLI box in the MiniEdit preferences window.
Set up the controller as a remote controller. Right click on the controller and select Properties from the menu that appears. Then select Remote Controller in the controller properties window.
In this tutorial, the POX controller is running on the same virtual machine that all the emulated switches and hosts created by Mininet are running on.
When default settings are used, MiniEdit configures OpenFlow switches to try to communicate with a remote POX controller using the host system’s loopback IP address and the default OpenFlow port number. So, in this tutorial, all switches created by MiniEdit or Mininet are looking for a remote controller with IP address and port number 127.0.0.0:6633.
Start the MiniEdit simulation
First, save the MiniEdit topology for future use.
Then start the simulation by clicking on the Run icon in the MiniEdit tool bar.
The MiniEdit console window will show information about the simulation starting and then will display the Mininet CLI prompt.
At this point, there is no controller connected to the OpenFlow switches so they will no be able to pass any traffic.
Alternative method: Mininet command line
As an alternative to using MiniEdit, the same network can be set up using the Mininet topology commands. I suggest using MiniEdit to create the network topology because MiniEdit provides a visual representation of the network. While MiniEdit is a great tool for creating topologies for the Mininet network simulator, in this tutorial we created a topology that can also be created using standard Mininet commands.
mininet@mininet-vm:~$ sudo mn --topo tree,2,2 --controller remote
Start the POX controller
Before we start the POX SDN controller, we need to determine which components we want to run when we start the controller.
Select the POX components to run
To select the correct stock components, determine what behavior we want the network of switches to exhibit. Then we will select the stock POX component that provides that functionality.
In this tutorial, we will use components that make POX work like a Layer 2 learning switch, and that dump copies of packets received by the controller to the controller’s log file (so we can see what packets the controller sees), and that list controller events to the console log screen in an easy-to-read format. According to the POX documentation, the stock components that do these tasks are: forwarding.l2_pairs, info.packet_dump, samples.pretty_log, and log.level.
See the POX documentation for information about other POX components.
To start the POX controller with the selected stock components, enter the following command on a terminal session connected to the Mininet VM.
mininet-vm:~$ sudo ~/pox/pox.py forwarding.l2_pairs \ info.packet_dump samples.pretty_log log.level --DEBUG
In the POX console, see that the log shows the controller starts and connects to the switches previously set up by the Mininet network simulator:
POX 0.2.0 (carp) / Copyright 2011-2013 James McCauley, et al. INFO:forwarding.l2_pairs:Pair-Learning switch running. INFO:info.packet_dump:Packet dumper running [core ] POX 0.2.0 (carp) is up. [openflow.of_01 ] [00-00-00-00-00-03 1] connected [openflow.of_01 ] [00-00-00-00-00-02 2] connected [openflow.of_01 ] [00-00-00-00-00-01 3] connected
Test the controller
The forwarding.l2_pairs component is a very simple application that just matches MAC addresses so it creates a simple scenario to study.
Generate some test traffic between hosts to see how POX builds flows in the network. Run the Mininet
pingall command, which runs ping tests between each host in the emulated network. This generates traffic to the controller every time a a switch receives a packet that has a destination MAC address that is not already in its flow table.
You can see in the POX console window the log messages showing what is happening. When the POX controller running the forwarding.l2_pairs component receives a packet from a switch, it tells the switch to flood the ARP packet out its other ports to other switches or hosts. One host eventually responds to the ARP request and then the forwarding.l2_pairs component sends OpenFlow messages to each switch to load the required flows into the switch flow tables.
Checking flow tables
To see the contents of the flow tables on all switches, execute the Mininet command:
mininet> dpctl dump-flows
To check ARP tables on each host, execute the Mininet arp command. For example, to show the ARP table for host h1, enter the following command:
mininet> h1 arp
To clear all flow tables on all switches, enter the Mininet command:
mininet> dpctl del-flows
As a next step, we can explore OpenFlow control messages and how flow tables are updated on the switches. In future posts, I will explore more about OpenFlow and Open vSwitch and the tools used to modify flow tables and view OpenFlow messages.
We will also explore how the other stock POX components work individually and in combination with other components or applications. For example, I’d like to see if we can get the Gephi graphing tool working with the misc.gephi_topo component.
We showed how to set up and run the POX SDN controller, how to choose and run stock POX components, and how to test the operation of the controller by using the Mininet SDN network simulator.