Minor code cleanup
This commit is contained in:
+1
-1
@@ -38,7 +38,7 @@ from mininet.net import Mininet
|
|||||||
from mininet.node import Host
|
from mininet.node import Host
|
||||||
from mininet.cli import CLI
|
from mininet.cli import CLI
|
||||||
from mininet.topo import SingleSwitchTopo
|
from mininet.topo import SingleSwitchTopo
|
||||||
from mininet.log import setLogLevel, info, debug
|
from mininet.log import setLogLevel, info
|
||||||
|
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ A sanity check for cluster edition
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
from mininet.examples.cluster import MininetCluster
|
from mininet.examples.cluster import MininetCluster
|
||||||
from mininet.log import info, setLogLevel
|
from mininet.log import setLogLevel
|
||||||
from mininet.examples.clustercli import ClusterCLI as CLI
|
from mininet.examples.clustercli import ClusterCLI as CLI
|
||||||
from mininet.topo import SingleSwitchTopo
|
from mininet.topo import SingleSwitchTopo
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ class ClusterCLI( CLI ):
|
|||||||
import networkx as nx
|
import networkx as nx
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
import pygraphviz
|
import pygraphviz
|
||||||
|
assert pygraphviz # silence pyflakes
|
||||||
except:
|
except:
|
||||||
error( 'plot requires networkx, matplotlib and pygraphviz - '
|
error( 'plot requires networkx, matplotlib and pygraphviz - '
|
||||||
'please install them and try again\n' )
|
'please install them and try again\n' )
|
||||||
@@ -40,7 +41,6 @@ class ClusterCLI( CLI ):
|
|||||||
g = nx.Graph()
|
g = nx.Graph()
|
||||||
mn = self.mn
|
mn = self.mn
|
||||||
servers, hosts, switches = mn.servers, mn.hosts, mn.switches
|
servers, hosts, switches = mn.servers, mn.hosts, mn.switches
|
||||||
hlen, slen = len( hosts ), len( switches )
|
|
||||||
nodes = hosts + switches
|
nodes = hosts + switches
|
||||||
g.add_nodes_from( nodes )
|
g.add_nodes_from( nodes )
|
||||||
links = [ ( link.intf1.node, link.intf2.node )
|
links = [ ( link.intf1.node, link.intf2.node )
|
||||||
|
|||||||
+1
-2
@@ -8,9 +8,8 @@ from mininet.net import Mininet
|
|||||||
from mininet.node import CPULimitedHost
|
from mininet.node import CPULimitedHost
|
||||||
from mininet.topolib import TreeTopo
|
from mininet.topolib import TreeTopo
|
||||||
from mininet.util import custom, waitListening
|
from mininet.util import custom, waitListening
|
||||||
from mininet.log import setLogLevel, output, info
|
from mininet.log import setLogLevel, info
|
||||||
|
|
||||||
from time import sleep
|
|
||||||
|
|
||||||
def bwtest( cpuLimits, period_us=100000, seconds=5 ):
|
def bwtest( cpuLimits, period_us=100000, seconds=5 ):
|
||||||
"""Example/test of link and CPU bandwidth limits
|
"""Example/test of link and CPU bandwidth limits
|
||||||
|
|||||||
@@ -1,48 +0,0 @@
|
|||||||
#!/usr/bin/python
|
|
||||||
|
|
||||||
'''
|
|
||||||
example of using various TCIntf options.
|
|
||||||
reconfigures a single interface using intf.config()
|
|
||||||
to use different traffic control commands to test
|
|
||||||
bandwidth, loss, and delay
|
|
||||||
'''
|
|
||||||
|
|
||||||
from mininet.net import Mininet
|
|
||||||
from mininet.log import setLogLevel, info
|
|
||||||
from mininet.link import TCLink
|
|
||||||
|
|
||||||
def intfOptions():
|
|
||||||
"run various traffic control commands on a single interface"
|
|
||||||
net = Mininet( autoStaticArp=True )
|
|
||||||
net.addController( 'c0' )
|
|
||||||
h1 = net.addHost( 'h1' )
|
|
||||||
h2 = net.addHost( 'h2' )
|
|
||||||
s1 = net.addSwitch( 's1' )
|
|
||||||
link1 = net.addLink( h1, s1, cls=TCLink )
|
|
||||||
link2 = net.addLink( h2, s1 )
|
|
||||||
net.start()
|
|
||||||
|
|
||||||
# flush out latency from reactive forwarding delay
|
|
||||||
net.pingAll()
|
|
||||||
|
|
||||||
info( '\n*** Configuring one intf with bandwidth of 5 Mb\n' )
|
|
||||||
link1.intf1.config( bw=5 )
|
|
||||||
info( '\n*** Running iperf to test\n' )
|
|
||||||
net.iperf()
|
|
||||||
|
|
||||||
info( '\n*** Configuring one intf with loss of 50%\n' )
|
|
||||||
link1.intf1.config( loss=50 )
|
|
||||||
info( '\n' )
|
|
||||||
net.iperf( ( h1, h2 ), l4Type='UDP' )
|
|
||||||
|
|
||||||
info( '\n*** Configuring one intf with delay of 15ms\n' )
|
|
||||||
link1.intf1.config( delay='15ms' )
|
|
||||||
info( '\n*** Run a ping to confirm delay\n' )
|
|
||||||
net.pingPairFull()
|
|
||||||
|
|
||||||
info( '\n*** Done testing\n' )
|
|
||||||
net.stop()
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
setLogLevel( 'info' )
|
|
||||||
intfOptions()
|
|
||||||
@@ -27,7 +27,6 @@ from mininet.net import Mininet
|
|||||||
from mininet.node import Node
|
from mininet.node import Node
|
||||||
from mininet.log import setLogLevel, info
|
from mininet.log import setLogLevel, info
|
||||||
from mininet.cli import CLI
|
from mininet.cli import CLI
|
||||||
from mininet.util import irange
|
|
||||||
|
|
||||||
class LinuxRouter( Node ):
|
class LinuxRouter( Node ):
|
||||||
"A Node with IP forwarding enabled."
|
"A Node with IP forwarding enabled."
|
||||||
|
|||||||
@@ -22,11 +22,9 @@ to-do:
|
|||||||
from mininet.net import Mininet
|
from mininet.net import Mininet
|
||||||
from mininet.node import OVSSwitch
|
from mininet.node import OVSSwitch
|
||||||
from mininet.topo import LinearTopo
|
from mininet.topo import LinearTopo
|
||||||
from mininet.util import quietRun
|
|
||||||
from mininet.log import output, warn
|
from mininet.log import output, warn
|
||||||
|
|
||||||
from random import randint
|
from random import randint
|
||||||
from re import findall
|
|
||||||
|
|
||||||
|
|
||||||
class MobilitySwitch( OVSSwitch ):
|
class MobilitySwitch( OVSSwitch ):
|
||||||
|
|||||||
@@ -1,35 +0,0 @@
|
|||||||
#!/usr/bin/python
|
|
||||||
|
|
||||||
"""
|
|
||||||
This is a simple example that demonstrates multiple links
|
|
||||||
between nodes.
|
|
||||||
"""
|
|
||||||
|
|
||||||
from mininet.cli import CLI
|
|
||||||
from mininet.log import lg, info
|
|
||||||
from mininet.net import Mininet
|
|
||||||
from mininet.topo import Topo
|
|
||||||
|
|
||||||
def runMultiLink():
|
|
||||||
|
|
||||||
topo = simpleMultiLinkTopo( n=2 )
|
|
||||||
net = Mininet( topo=topo )
|
|
||||||
net.start()
|
|
||||||
CLI( net )
|
|
||||||
net.stop()
|
|
||||||
|
|
||||||
class simpleMultiLinkTopo( Topo ):
|
|
||||||
|
|
||||||
def __init__( self, n, **kwargs ):
|
|
||||||
Topo.__init__( self, **kwargs )
|
|
||||||
|
|
||||||
h1, h2 = self.addHost( 'h1' ), self.addHost( 'h2' )
|
|
||||||
s1 = self.addSwitch( 's1' )
|
|
||||||
|
|
||||||
for _ in range( n ):
|
|
||||||
self.addLink( s1, h1 )
|
|
||||||
self.addLink( s1, h2 )
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
lg.setLogLevel( 'info' )
|
|
||||||
runMultiLink()
|
|
||||||
@@ -6,7 +6,7 @@ between nodes.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from mininet.cli import CLI
|
from mininet.cli import CLI
|
||||||
from mininet.log import lg, info
|
from mininet.log import setLogLevel
|
||||||
from mininet.net import Mininet
|
from mininet.net import Mininet
|
||||||
from mininet.topo import Topo
|
from mininet.topo import Topo
|
||||||
|
|
||||||
@@ -31,5 +31,5 @@ class simpleMultiLinkTopo( Topo ):
|
|||||||
self.addLink( s1, h2 )
|
self.addLink( s1, h2 )
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
lg.setLogLevel( 'info' )
|
setLogLevel( 'info' )
|
||||||
runMultiLink()
|
runMultiLink()
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ and that the ovs ports match the mininet ports.
|
|||||||
from mininet.net import Mininet
|
from mininet.net import Mininet
|
||||||
from mininet.node import Controller
|
from mininet.node import Controller
|
||||||
from mininet.log import setLogLevel, info, warn
|
from mininet.log import setLogLevel, info, warn
|
||||||
from mininet.node import Node
|
|
||||||
|
|
||||||
def validatePort( switch, intf ):
|
def validatePort( switch, intf ):
|
||||||
"Validate intf's OF port number"
|
"Validate intf's OF port number"
|
||||||
@@ -48,7 +47,6 @@ def net():
|
|||||||
net.addLink( h4, s1 )
|
net.addLink( h4, s1 )
|
||||||
net.addLink( h5, s1, port1 = 1, port2 = 9 ) # specify a different port to connect host 5 to on the switch.
|
net.addLink( h5, s1, port1 = 1, port2 = 9 ) # specify a different port to connect host 5 to on the switch.
|
||||||
|
|
||||||
root = Node( 'root', inNamespace=False )
|
|
||||||
info( '*** Starting network\n' )
|
info( '*** Starting network\n' )
|
||||||
net.start()
|
net.start()
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ def perfTest():
|
|||||||
dumpNodeConnections(net.hosts)
|
dumpNodeConnections(net.hosts)
|
||||||
print "Testing bandwidth between h1 and h4"
|
print "Testing bandwidth between h1 and h4"
|
||||||
h1, h4 = net.getNodeByName('h1', 'h4')
|
h1, h4 = net.getNodeByName('h1', 'h4')
|
||||||
results = net.iperf( ( h1, h4 ), l4Type='UDP' )
|
net.iperf( ( h1, h4 ), l4Type='UDP' )
|
||||||
net.stop()
|
net.stop()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
@@ -1,42 +0,0 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
|
|
||||||
"""
|
|
||||||
Test for intfOptions.py
|
|
||||||
"""
|
|
||||||
|
|
||||||
import unittest
|
|
||||||
import pexpect
|
|
||||||
import sys
|
|
||||||
|
|
||||||
class testIntfOptions( unittest.TestCase ):
|
|
||||||
|
|
||||||
def testIntfOptions( self ):
|
|
||||||
"verify that intf.config is correctly limiting traffic"
|
|
||||||
p = pexpect.spawn( 'python -m mininet.examples.intfOptions ' )
|
|
||||||
tolerance = .8
|
|
||||||
opts = [ "Results: \['([\d\.]+) .bits/sec",
|
|
||||||
"Results: \['10M', '([\d\.]+) .bits/sec",
|
|
||||||
"h(\d+)->h(\d+): (\d)/(\d), rtt min/avg/max/mdev ([\d\.]+)/([\d\.]+)/([\d\.]+)/([\d\.]+) ms",
|
|
||||||
pexpect.EOF ]
|
|
||||||
while True:
|
|
||||||
index = p.expect( opts, timeout=600 )
|
|
||||||
if index == 0:
|
|
||||||
bw = float( p.match.group( 1 ) )
|
|
||||||
self.assertGreaterEqual( bw, float( 5 * tolerance ) )
|
|
||||||
self.assertLessEqual( bw, float( 5 + 5 * ( 1 - tolerance ) ) )
|
|
||||||
elif index == 1:
|
|
||||||
BW = 10
|
|
||||||
measuredBw = float( p.match.group( 1 ) )
|
|
||||||
loss = ( measuredBw / BW ) * 100
|
|
||||||
self.assertGreaterEqual( loss, 50 * tolerance )
|
|
||||||
self.assertLessEqual( loss, 50 + 50 * ( 1 - tolerance ) )
|
|
||||||
elif index == 2:
|
|
||||||
delay = float( p.match.group( 6 ) )
|
|
||||||
self.assertGreaterEqual( delay, 15 * tolerance )
|
|
||||||
self.assertLessEqual( delay, 15 + 15 * ( 1 - tolerance ) )
|
|
||||||
else:
|
|
||||||
break
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
unittest.main()
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
|
|
||||||
'''
|
|
||||||
Test for multiple links between nodes
|
|
||||||
validates mininet interfaces against systems interfaces
|
|
||||||
'''
|
|
||||||
|
|
||||||
import unittest
|
|
||||||
import pexpect
|
|
||||||
|
|
||||||
class testMultiLink( unittest.TestCase ):
|
|
||||||
|
|
||||||
prompt = 'mininet>'
|
|
||||||
|
|
||||||
def testMultiLink(self):
|
|
||||||
p = pexpect.spawn( 'python -m mininet.examples.multiLink' )
|
|
||||||
p.expect( self.prompt )
|
|
||||||
p.sendline( 'intfs' )
|
|
||||||
p.expect( 's(\d): lo' )
|
|
||||||
intfsOutput = p.before
|
|
||||||
# parse interfaces from mininet intfs, and store them in a list
|
|
||||||
hostToIntfs = intfsOutput.split( '\r\n' )[ 1:3 ]
|
|
||||||
intfList = []
|
|
||||||
for hostToIntf in hostToIntfs:
|
|
||||||
intfList += [ intf for intf in
|
|
||||||
hostToIntf.split()[1].split(',') ]
|
|
||||||
|
|
||||||
# get interfaces from system by running ifconfig on every host
|
|
||||||
sysIntfList = []
|
|
||||||
opts = [ 'h(\d)-eth(\d)', self.prompt ]
|
|
||||||
p.expect( self.prompt )
|
|
||||||
|
|
||||||
p.sendline( 'h1 ifconfig' )
|
|
||||||
while True:
|
|
||||||
p.expect( opts )
|
|
||||||
if p.after == self.prompt:
|
|
||||||
break
|
|
||||||
sysIntfList.append( p.after )
|
|
||||||
|
|
||||||
p.sendline( 'h2 ifconfig' )
|
|
||||||
while True:
|
|
||||||
p.expect( opts )
|
|
||||||
if p.after == self.prompt:
|
|
||||||
break
|
|
||||||
sysIntfList.append( p.after )
|
|
||||||
|
|
||||||
failMsg = ( 'The systems interfaces and mininet interfaces\n'
|
|
||||||
'are not the same' )
|
|
||||||
|
|
||||||
self.assertEqual( sysIntfList, intfList, msg=failMsg )
|
|
||||||
p.sendline( 'exit' )
|
|
||||||
p.wait()
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
unittest.main()
|
|
||||||
@@ -37,7 +37,7 @@ class testSwitchDpidAssignmentCommon ( object ):
|
|||||||
name of the switch does not contin a digit. Also verify the
|
name of the switch does not contin a digit. Also verify the
|
||||||
exception message."""
|
exception message."""
|
||||||
with self.assertRaises( Exception ) as raises_cm:
|
with self.assertRaises( Exception ) as raises_cm:
|
||||||
switch = Mininet( Topo(), self.switchClass, Host, Controller ).addSwitch( 'A' )
|
Mininet( Topo(), self.switchClass, Host, Controller ).addSwitch( 'A' )
|
||||||
self.assertEqual(raises_cm.exception.message, 'Unable to derive '
|
self.assertEqual(raises_cm.exception.message, 'Unable to derive '
|
||||||
'default datapath ID - please either specify a dpid '
|
'default datapath ID - please either specify a dpid '
|
||||||
'or use a canonical switch name such as s23.')
|
'or use a canonical switch name such as s23.')
|
||||||
|
|||||||
Reference in New Issue
Block a user