add example and test for multiple links
This commit is contained in:
Executable
+35
@@ -0,0 +1,35 @@
|
|||||||
|
#!/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()
|
||||||
Executable
+55
@@ -0,0 +1,55 @@
|
|||||||
|
#!/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()
|
||||||
Reference in New Issue
Block a user