How to do it...

You may emulate mobile ad hoc network (MANET) and vehicular ad hoc network (VANET) using Mininet-WiFi, and visualize them in a graphical interface. VANET is a subset of MANET, which can be emulated by sub-classing the generic interfaces of Mininet-WiFi. In this recipe, we will adopt and extend an example from the Mininet-WiFi.

Listing 9.4 shows the code to emulate a mobile network:

#!/usr/bin/env python 
# Python Network Programming Cookbook, Second Edition -- Chapter - 9 
# This program is optimized for Python 2.7.12. 
# It may run on any other version with/without modifications. 
 
from mininet.net import Mininet 
from mininet.node import Controller, OVSKernelAP 
from mininet.link import TCLink 
from mininet.cli import CLI 
from mininet.log import setLogLevel 
 
def emulate(): 
    # Setting the position of nodes and providing mobility 
 
    # Create a network. 
    net = Mininet(controller=Controller, link=TCLink,
accessPoint=OVSKernelAP) print ("*** Creating nodes") # Add the host h1 = net.addHost('h1', mac='00:00:00:00:00:01', ip='10.0.0.1/8') # Add 3 mobile stations, sta1, sta2, sta3. sta1 = net.addStation('sta1', mac='00:00:00:00:00:02', ip='10.0.0.2/8') sta2 = net.addStation('sta2', mac='00:00:00:00:00:03', ip='10.0.0.3/8') sta3 = net.addStation('sta3', mac='00:00:00:00:00:04', ip='10.0.0.4/8') # Add an access point ap1 = net.addAccessPoint('ap1', ssid='new-ssid',
mode='g', channel='1', position='45,40,30') # Add a controller c1 = net.addController('c1', controller=Controller) print ("*** Configuring wifi nodes") net.configureWifiNodes() print ("*** Associating and Creating links") net.addLink(ap1, h1) net.addLink(ap1, sta1) net.addLink(ap1, sta2) net.addLink(ap1, sta3) print ("*** Starting network") net.build() c1.start() ap1.start([c1]) # Plot a 3-dimensional graph. net.plotGraph(max_x=100, max_y=100, max_z=200) # Start the mobility at the start of the emulation. net.startMobility(time=0) # Start the mobile stations from their initial positions. net.mobility(sta1, 'start', time=1, position='40.0,30.0,20.0') net.mobility(sta2, 'start', time=2, position='40.0,40.0,90.0') net.mobility(sta3, 'start', time=3, position='50.0,50.0,160.0') # Indicate the final destination of the mobile stations during
the emulation. net.mobility(sta1, 'stop', time=12, position='31.0,10.0,50.0') net.mobility(sta2, 'stop', time=22, position='55.0,31.0,30.0') net.mobility(sta3, 'stop', time=32, position='75.0,99.0,120.0') # Stop the mobility at certain time. net.stopMobility(time=33) print ("*** Running CLI") CLI(net) print ("*** Stopping network") net.stop() if __name__ == '__main__': setLogLevel('info') emulate()

In this recipe, we emulate a mobile network with a host, an access point, a controller, and three mobile stations. We start the mobile stations with their initial positions, and let them move to their final positions during the emulation. Once the emulation is done, we stop the mobility and the emulation:

$ sudo python 9_4_mininet_wifi_emulation.py
*** Creating nodes
*** Configuring wifi nodes
*** Associating and Creating links
Associating sta1-wlan0 to ap1
Associating sta2-wlan0 to ap1
Associating sta3-wlan0 to ap1
*** Starting network
*** Configuring hosts
Mobility started at 0 second(s)
*** Running CLI
*** Starting CLI:
mininet-wifi> exit
*** Stopping network
*** Stopping 1 controllers
c1 
*** Stopping 1 links
.
*** Stopping switches and/or access points
ap1 
*** Stopping hosts and/or stations
h1 sta1 sta2 sta3 
    
*** Done
  

The following screenshots indicate the graph at the start and end of the emulation. The following screenshot shows the positions of the mobile stations at the start of the emulation:

Starting State of the Emulation

The following screenshot shows the position at the end of the emulation:

Finishing State of the Emulation

During the course, you may monitor how the mobile stations move between their initial and final positions.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.187.233