--- tags: mininet-wifi-tutorials --- # Act 3 - OpenFlow Protocol You now will learn and put into practice basic concepts of the OpenFlow protocol, such as idle/hard timeouts, and apply them into a wireless scenario to understand the impact in mobile communications. ## Activity 1: Mobility Plese consider the content of handover.py below: ```python= #!/usr/bin/python 'Example for handover' from mn_wifi.net import Mininet_wifi from mn_wifi.cli import CLI from mininet.node import Controller from mininet.log import setLogLevel def topology(): "Create a network." net = Mininet_wifi() print "*** Creating nodes" sta1 = net.addStation('sta1', mac='00:00:00:00:00:01', ip='10.0.0.1/8') ap1 = net.addAccessPoint('ap1', ssid='new-ssid1', mode='g', channel='1', position='15,30,0') ap2 = net.addAccessPoint('ap2', ssid='new-ssid1', mode='g', channel='6', position='55,30,0') s3 = net.addSwitch('s3') h1 = net.addHost('h1', mac='00:00:00:00:00:02', ip='10.0.0.2/8') c1 = net.addController('c1', controller=Controller, port=6653) net.setPropagationModel(model="logDistance", exp=5) print "*** Configuring WiFi Nodes" net.configureWifiNodes() #s3.plot(position='35,90,0') #h1.plot(position='35,80,0') print "*** Creating links" net.addLink(ap1, s3) net.addLink(ap2, s3) net.addLink(h1, s3) 'plotting graph' net.plotGraph(max_x=100, max_y=100) net.startMobility(time=0, repetitions=1) net.mobility(sta1, 'start', time=1, position='10,30,0') net.mobility(sta1, 'stop', time=80, position='60,30,0') net.stopMobility(time=80) print "*** Starting network" net.build() c1.start() ap1.start([c1]) ap2.start([c1]) s3.start([c1]) print "*** Running CLI" CLI(net) print "*** Stopping network" net.stop() if __name__ == '__main__': setLogLevel('info') topology() ``` and then run it: ``` ~/mininet-wifi$ sudo python handover.py ``` Now, let h1 keep pinging sta1: ``` mininet-wifi>h1 ping sta1 ``` **Question 1.1**: As you can see, h1 cannot reach sta1 when sta1 goes to ap2. Why? Two important commands should help you to answer this question: ``` mininet-wifi>links mininet-wifi>sh ovs-ofctl dump-flows s3 ``` _Tip: Observe both idle_timeout and idle_age._ **Question 1.2**: Now you know the answer, how could sta1 be reached by h1? Suggest (and prototype) some possible solutions. ## Activity 2: Remote Controller In the activities made so far, the controller has run on your computer and in a somewhat abstract way. That is, we started Mininet-WiFi and the controller was started along with Mininet-WiFi. However, in the real world, the controller is installed and run on a known computer or server. Be it a physical computer or even a virtual machine. So, let’s run a test with a controller other than the ovs-testcontroller, the controller that starts with Mininet-WiFi. To do so, we will use the Ryu controller. The source code of Ryu can be found at https://github.com/osrg/ryu, however, we will consider for this activity a copy of the official repository available at https://github.com/ramonfontes/ryu, especially the branch book. ``` git clone https://github.com/ramonfontes/ryu -b book ``` To follow up on this tutorial, let’s then run the following command. The command sudo mn has been presented previously, however, we will use it next to the --controller parameter. ``` sudo mn --controller=remote ``` Now, let’s try a ping between h1 and h2. ``` mininet-wifi> h1 ping -c1 h2 ``` **Question 2.1**: What happened? You now must start Ryu so that the nodes can communicate with each other. To do so, try to start Ryu on a new terminal. As the Ryu source code has been previously obtained, it can be started as follows. ``` ~/mininet-wifi/ryu$ sudo PYTHONPATH=. ./bin/ryu-manager ryu/app/simple_switch_13.py ``` Now, let’s repeat the ping between h1 and h2. ``` mininet-wifi> h1 ping -c1 h2 ```