diff --git a/examples/multiLink.py b/examples/multiLink.py new file mode 100755 index 0000000..28a67a8 --- /dev/null +++ b/examples/multiLink.py @@ -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() diff --git a/examples/test/test_multiLink.py b/examples/test/test_multiLink.py new file mode 100755 index 0000000..6b4bca2 --- /dev/null +++ b/examples/test/test_multiLink.py @@ -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()