Software-defined network experiment 2: Mininet experiment - command script generation of topology
1. The purpose of the experiment
Master Mininet's custom topology generation method: command line creation, Python scripting
2. Experimental tasks
Familiarize yourself with the basic functionality of Mininet by using command line creation, Python scripting to generate topology.
3. Experimental steps
1. Experimental environment
- Virtual machine with Ubuntu 16.04.6 Desktop amd64 installed
2. Experimental procedure
-
(1) Quick command line creation for a specific topology
- //Minimum topology, 2 hosts are attached to 1 switch
$ sudo mn --topo minimal - // Simple topology, n hosts are attached to one switch, where n=3, n=2 is the minimum topology
$ sudo mn --topo single,3 - // Linear topology, switches are connected in a line, each switch is connected to 1 host, there are 3 switches and 3 hosts here
$ sudo mn --topo linear,3 - // tree topology, based on depth depth and fanout fanout, both here are 2
$ sudo mn --topo tree, fanout=2,depth=2
- //Minimum topology, 2 hosts are attached to 1 switch
-
(2) Custom creation of Python scripts for general situations
- This method requires programming skills in Python.
- The linear topology constructed in this question is shown in the figure below
The python code is as follows:
# coding=UTF-8 from mininet.net import Mininet from mininet.node import CPULimitedHost from mininet.link import TCLink net = Mininet(host=CPULimitedHost,link=TCLink) # If the performance is not limited, the parameter is empty # Create a network node c0 = net.addController() h1 = net.addHost('h1',cpu=0.5) h2 = net.addHost('h2',cpu=0.5) h3 = net.addHost('h3',cpu=0.5) s1 = net.addSwitch('s1') s2 = net.addSwitch('s2') s3 = net.addSwitch('s3') # Create links between nodes net.addLink(h1,s1,bw=10,delay='5ms',max_queue_size=1000,loss=0,use_htb=True) net.addLink(s1,s2) net.addLink(h2,s2,bw=10,delay='5ms',max_queue_size=1000,loss=0,use_htb=True) net.addLink(s2,s3) net.addLink(h3,s3,bw=10,delay='5ms',max_queue_size=1000,loss=0,use_htb=True) # configure host ip h1.setIP('10.0.0.1',24) h2.setIP('10.0.0.2',24) h3.setIP('10.0.0.3',24) net.start() net.pingAll() net.stop()
-
Excuting an order:
- $ nano mytopo.py // Copy the Python code into the py file
- $ sudo python mytopo.py // execute py file
-
The result is as follows:
-
Then modify the previous Python program to use iPerf to test the bandwidth between the specified hosts in the network topology.
The python code is as follows:
# coding=UTF-8 #!/usr/bin/python from mininet.net import Mininet from mininet.node import CPULimitedHost from mininet.link import TCLink from mininet.util import dumpNodeConnections from mininet.log import setLogLevel def IperfTest(): net = Mininet(host=CPULimitedHost, link=TCLink) c0 = net.addController() h1 = net.addHost('h1',cpu=0.5) h2 = net.addHost('h2',cpu=0.5) h3 = net.addHost('h3',cpu=0.5) s1 = net.addSwitch('s1') s2 = net.addSwitch('s2') s3 = net.addSwitch('s3') net.addLink(h1,s1, bw=10,delay='5ms',max_queue_size=1000,loss=0,use_htb=True) net.addLink(s1,s2) net.addLink(h2,s2, bw=10,delay='5ms',max_queue_size=1000,loss=0,use_htb=True) net.addLink(s2,s3) net.addLink(h3,s3, bw=10,delay='5ms',max_queue_size=1000,loss=0,use_htb=True) h1.setIP('10.0.0.1',24) h2.setIP('10.0.0.2',24) h3.setIP('10.0.0.3',24) net.start() print "Dumping host connections" dumpNodeConnections(net.hosts) print "Testing network connectivity" net.pingAll() print "Testing bandwidth" h1,h2,h3 = net.get('h1','h2','h3') net.iperf((h1,h2)) net.iperf((h2,h3)) net.iperf((h1,h3)) net.stop() if __name__=='__main__': setLogLevel('info') #print the log when Configuring hosts,starting switches and controller IperfTest()
- Excuting an order:
- $ nano IperfTest.py // Copy the Python code into the py file
- $ sudo python IperfTest.py // execute py file
- The result is as follows:
Fourth, the experimental experience
- Pay attention to the space indentation of the code, otherwise an error will be reported.