How to do it...

In this recipe, we will rewrite the same recipe of 9.2 for MaxiNet. As you can notice, with minor changes, the code and the API remains compatible with that of Mininet's.

Listing 9.2 adopts the listing 9.1 for MaxiNet, as follows:

#!/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. 
 
import sys 
import maxinet 
from mininet.topolib import TreeTopo 
 
# Emulate a network with depth of depth_ and fanout of fanout_ 
def emulate(depth_, fanout_): 
    # Start the MaxiNet as a Mininet cluster. 
    cluster = maxinet.MininetCluster("pc1","pc2","pc3") 
    cluster.start() 
 
    # Emulate the network topology. 
    emu = maxinet.Emulation(cluster, TreeTopo(depth_,fanout_)) 
 
    # Start Execution of the Emulated System. 
    emu.setup() 
 
    # Name two of the instances as h1 and h2. 
    h1, h2  = net.hosts[0], net.hosts[depth_] 
 
    # Ping from an instance to another, and print the output. 
    print (h1.cmd('ping -c1 %s' % h2.IP())) 
 
    # Stop the MaxiNet Emulation. 
    emu.stop() 
    cluster.stop() 
 
if __name__ == '__main__': 
    parser = argparse.ArgumentParser(description='Maxinet
Simple Emulation') parser.add_argument('--depth', action="store",
dest="depth", type=int, required=True) parser.add_argument('--fanout', action="store",
dest="fanout", type=int, required=True) given_args = parser.parse_args() emulate(given_args.depth, given_args.fanout)

Now you may run this from the master instance, as you would have run this on a Mininet emulation. The master instance communicates with the other worker instance to distribute the workload:

$ sudo python 9_3_maxinet_emulation.py --depth=2 --fanout=3
PING 10.0.0.3 (10.0.0.3) 56(84) bytes of data.
64 bytes from 10.0.0.3: icmp_seq=1 ttl=64 time=1.82 ms
    
--- 10.0.0.3 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 1.827/1.827/1.827/0.000 ms
..................Content has been hidden....................

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