def testRegressionRun( self ): "Test pingpair (0% drop) and iperf (bw > 0) regression test" # test pingpair p = pexpect.spawn( 'mn --test pingpair' ) p.expect( '0% dropped' ) p.expect( pexpect.EOF ) # test iperf p = pexpect.spawn( 'mn --test iperf' ) p.expect( r"Results: \['([\d\.]+) .bits/sec'," ) bw = float( p.match.group( 1 ) ) self.assertTrue( bw > 0 ) p.expect( pexpect.EOF )
def testRegressionRun( self ): "Test pingpair (0% drop) and iperf (bw > 0) regression tests" # test pingpair p = pexpect.spawn( 'mn --test pingpair' ) p.expect( '0% dropped' ) p.expect( pexpect.EOF ) # test iperf p = pexpect.spawn( 'mn --test iperf' ) p.expect( r"Results: \['([\d\.]+) .bits/sec'," ) bw = float( p.match.group( 1 ) ) self.assertTrue( bw > 0 ) p.expect( pexpect.EOF )
def testVerbosity( self ): "Test debug and output verbosity" # test output p = pexpect.spawn( 'mn -v output' ) p.expect( self.prompt ) self.assertEqual( len( p.before ), 0, 'Too much output for "output"' ) p.sendline( 'exit' ) p.wait() # test debug p = pexpect.spawn( 'mn -v debug --test none' ) p.expect( pexpect.EOF ) lines = p.before.split( '\n' ) self.assertTrue( len( lines ) > 70, "Debug output is too short" )
def testRemoteController( self ): "Test Mininet using Pox controller" # Satisfy pylint assert self if not os.path.exists( '/tmp/pox' ): p = pexpect.spawn( 'git clone https://github.com/noxrepo/pox.git /tmp/pox' ) p.expect( pexpect.EOF ) pox = pexpect.spawn( '/tmp/pox/pox.py forwarding.l2_learning' ) net = pexpect.spawn( 'mn --controller=remote,ip=127.0.0.1,port=6633 --test pingall' ) net.expect( '0% dropped' ) net.expect( pexpect.EOF ) pox.sendintr() pox.wait()
def testWireshark( self ): "Use tshark to test the of dissector" # Satisfy pylint assert self if StrictVersion( tsharkVersion() ) < StrictVersion( '1.12.0' ): tshark = pexpect.spawn( 'tshark -i lo -R of' ) else: tshark = pexpect.spawn( 'tshark -i lo -Y openflow_v1' ) tshark.expect( [ 'Capturing on lo', "Capturing on 'Loopback'" ] ) mn = pexpect.spawn( 'mn --test pingall' ) mn.expect( '0% dropped' ) tshark.expect( [ '74 Hello', '74 of_hello', '74 Type: OFPT_HELLO' ] ) tshark.sendintr() mn.expect( pexpect.EOF ) tshark.expect( pexpect.EOF )
def testLinearBandwidth( self ): "Verify that bandwidth is monotonically decreasing as # of hops increases" p = pexpect.spawn( 'python -m mininet.examples.linearbandwidth' ) count = 0 opts = [ '\*\*\* Linear network results', '(\d+)\s+([\d\.]+) (.bits)', pexpect.EOF ] while True: index = p.expect( opts, timeout=600 ) if index == 0: count += 1 elif index == 1: n = int( p.match.group( 1 ) ) bw = float( p.match.group( 2 ) ) unit = p.match.group( 3 ) if unit[ 0 ] == 'K': bw *= 10 ** 3 elif unit[ 0 ] == 'M': bw *= 10 ** 6 elif unit[ 0 ] == 'G': bw *= 10 ** 9 # check that we have a previous result to compare to if n != 1: info = ( 'bw: %.2e bits/s across %d switches, ' 'previous: %.2e bits/s across %d switches' % ( bw, n, previous_bw, previous_n ) ) self.assertTrue( bw < previous_bw, info ) previous_bw, previous_n = bw, n else: break # verify that we received results from at least one switch self.assertTrue( count > 0 )
def testMultiPoll( self ): "Verify that we receive one ping per second per host" p = pexpect.spawn( 'python -m mininet.examples.multipoll' ) opts = [ "\*\*\* (h\d) :" , "(h\d+): \d+ bytes from", "Monitoring output for (\d+) seconds", pexpect.EOF ] pings, seconds = {}, -1 while True: index = p.expect( opts ) if index == 0: name = p.match.group( 1 ) pings[ name ] = 0 elif index == 1: name = p.match.group( 1 ) pings[ name ] += 1 elif index == 2: seconds = int( p.match.group( 1 ) ) else: break self.assertTrue( len( pings ) > 0 ) # make sure we have received at least one ping per second for count in pings.values(): self.assertTrue( count >= seconds, '%d pings < %d seconds' % ( count, seconds ) )
def testOwnNamespace( self ): "Test running user switch in its own namespace" p = pexpect.spawn( 'mn --innamespace --switch user' ) p.expect( self.prompt ) interfaces = [ r'h1-eth0[:\s]', r's1-eth1[:\s]', r'[^-](eth|en)\w*\d[:\s]', r'lo[:\s]', self.prompt ] p.sendline( 's1 ifconfig -a' ) ifcount = 0 while True: index = p.expect( interfaces ) if index == 1 or index == 3: ifcount += 1 elif index == 0: self.fail( 'h1 interface displayed in "s1 ifconfig"' ) elif index == 2: self.fail( 'eth0 displayed in "s1 ifconfig"' ) else: break self.assertEqual( ifcount, 2, 'Missing interfaces on s1' ) # verify that all hosts a reachable p.sendline( 'pingall' ) p.expect( r'(\d+)% dropped' ) dropped = int( p.match.group( 1 ) ) self.assertEqual( dropped, 0, 'pingall failed') p.expect( self.prompt ) p.sendline( 'exit' ) p.wait()
def setUp(self): # verify that sshd is not running self.assertFalse(self.connected()) # create public key pair for testing sh('rm -rf /tmp/ssh') sh('mkdir /tmp/ssh') sh("ssh-keygen -t rsa -P '' -f /tmp/ssh/test_rsa") sh('cat /tmp/ssh/test_rsa.pub >> /tmp/ssh/authorized_keys') # run example with custom sshd args cmd = ('python -m mininet.examples.baresshd ' '-o AuthorizedKeysFile=/tmp/ssh/authorized_keys ' '-o StrictModes=no') p = pexpect.spawn(cmd) runOpts = [ 'You may now ssh into h1 at 10.0.0.1', 'after 5 seconds, h1 is not listening on port 22', pexpect.EOF, pexpect.TIMEOUT ] while True: index = p.expect(runOpts) if index == 0: break else: self.tearDown() self.fail('sshd failed to start in host h1')
def pingTest(self, name): "Verify that there are no dropped packets for each host" p = pexpect.spawn('python -m %s' % name) opts = [ "<(h\d+)>: PING ", "<(h\d+)>: (\d+) packets transmitted, (\d+) received", pexpect.EOF ] pings = {} while True: index = p.expect(opts) if index == 0: name = p.match.group(1) pings[name] = 0 elif index == 1: name = p.match.group(1) transmitted = p.match.group(2) received = p.match.group(3) # verify no dropped packets self.assertEqual(received, transmitted) pings[name] += 1 else: break self.assertTrue(len(pings) > 0) # verify that each host has gotten results for count in pings.values(): self.assertEqual(count, 1)
def testIntfOptions( self ): "verify that intf.config is correctly limiting traffic" p = pexpect.spawn( 'python -m mininet.examples.intfoptions ' ) tolerance = .2 # plus or minus 20% 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 = 5 bw = float( p.match.group( 1 ) ) self.assertGreaterEqual( bw, BW * ( 1 - tolerance ) ) self.assertLessEqual( bw, BW * ( 1 + tolerance ) ) elif index == 1: BW = 10 measuredBw = float( p.match.group( 1 ) ) loss = ( measuredBw / BW ) * 100 self.assertGreaterEqual( loss, 50 * ( 1 - tolerance ) ) self.assertLessEqual( loss, 50 * ( 1 + tolerance ) ) elif index == 2: delay = float( p.match.group( 6 ) ) self.assertGreaterEqual( delay, 15 * ( 1 - tolerance ) ) self.assertLessEqual( delay, 15 * ( 1 + tolerance ) ) else: break
def testLimit(self): "Verify that CPU limits are within a 2% tolerance of limit for each scheduler" p = pexpect.spawn('python -m mininet.examples.limit') opts = [ '\*\*\* Testing network ([\d\.]+) Mbps', '\*\*\* Results: \[([\d\., ]+)\]', pexpect.EOF ] count = 0 bw = 0 tolerance = 2 while True: index = p.expect(opts) if index == 0: bw = float(p.match.group(1)) count += 1 elif index == 1: results = p.match.group(1) for x in results.split(','): result = float(x) self.assertTrue(result < bw + tolerance) self.assertTrue(result > bw - tolerance) else: break self.assertTrue(count > 0)
def testMultiPing( self ): """Verify that each target is pinged at least once, and that pings to 'real' targets are successful and unknown targets fail""" p = pexpect.spawn( 'python -m mininet.examples.multiping' ) opts = [ "Host (h\d+) \(([\d.]+)\) will be pinging ips: ([\d\. ]+)", "(h\d+): ([\d.]+) -> ([\d.]+) \d packets transmitted, (\d) received", pexpect.EOF ] pings = defaultdict( list ) while True: index = p.expect( opts ) if index == 0: name = p.match.group(1) ip = p.match.group(2) targets = p.match.group(3).split() pings[ name ] += targets elif index == 1: name = p.match.group(1) ip = p.match.group(2) target = p.match.group(3) received = int( p.match.group(4) ) if target == '10.0.0.200': self.assertEqual( received, 0, p.match.group(0) + '\n' + target + ' received %d != 0 packets' % received ) else: self.assertEqual( received, 1, p.match.group(0) + '\n' + target + ' received %d != 1 packets' % received ) try: pings[ name ].remove( target ) except: pass else: break self.assertTrue( len( pings ) > 0, 'too few pings' ) for t in pings.values(): self.assertEqual( len( t ), 0, 'missed ping target(s): %s' % t )
def testIntfOptions(self): "verify that intf.config is correctly limiting traffic" p = pexpect.spawn('python -m mininet.examples.intfoptions ') tolerance = .25 # plus or minus 25% for cloud CI tests 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 = 10 bw = float(p.match.group(1)) self.assertGreaterEqual(bw, BW * (1 - tolerance)) self.assertLessEqual(bw, BW * (1 + tolerance)) elif index == 1: BW = 10 measuredBw = float(p.match.group(1)) loss = (measuredBw / BW) * 100 self.assertGreaterEqual(loss, 50 * (1 - tolerance), 'loss of %d%% << 50%%' % loss) self.assertLessEqual(loss, 50 * (1 + tolerance), 'loss of %d%% >> 50%%' % loss) elif index == 2: delay = float(p.match.group(6)) self.assertGreaterEqual(delay, 15 * (1 - tolerance)) self.assertLessEqual(delay, 15 * (1 + tolerance)) else: break
def testLinearBandwidth(self): "Verify that bandwidth is monotonically decreasing as # of hops increases" p = pexpect.spawn('python -m mininet.examples.linearbandwidth') count = 0 opts = [ '\*\*\* Linear network results', '(\d+)\s+([\d\.]+) (.bits)', pexpect.EOF ] while True: index = p.expect(opts, timeout=600) if index == 0: count += 1 elif index == 1: n = int(p.match.group(1)) bw = float(p.match.group(2)) unit = p.match.group(3) if unit[0] == 'K': bw *= 10**3 elif unit[0] == 'M': bw *= 10**6 elif unit[0] == 'G': bw *= 10**9 # check that we have a previous result to compare to if n != 1: info = ('bw: %.2e bits/s across %d switches, ' 'previous: %.2e bits/s across %d switches' % (bw, n, previous_bw, previous_n)) self.assertTrue(bw < previous_bw, info) previous_bw, previous_n = bw, n else: break # verify that we received results from at least one switch self.assertTrue(count > 0)
def testTopoChange( self ): "Test pingall on single,3 and linear,4 topos" # testing single,3 p = pexpect.spawn( 'mn --test pingall --topo single,3' ) p.expect( r'(\d+)/(\d+) received') received = int( p.match.group( 1 ) ) sent = int( p.match.group( 2 ) ) self.assertEqual( sent, 6, 'Wrong number of pings sent in single,3' ) self.assertEqual( sent, received, 'Dropped packets in single,3') p.expect( pexpect.EOF ) # testing linear,4 p = pexpect.spawn( 'mn --test pingall --topo linear,4' ) p.expect( r'(\d+)/(\d+) received') received = int( p.match.group( 1 ) ) sent = int( p.match.group( 2 ) ) self.assertEqual( sent, 12, 'Wrong number of pings sent in linear,4' ) self.assertEqual( sent, received, 'Dropped packets in linear,4') p.expect( pexpect.EOF )
def setUp( self ): self.net = pexpect.spawn( 'python -m mininet.examples.bind' ) self.net.expect( "Private Directories: \[([\w\s,'/]+)\]" ) self.directories = [] # parse directories from mn output for d in self.net.match.group(1).split(', '): self.directories.append( d.strip("'") ) self.net.expect( self.prompt ) self.assertTrue( len( self.directories ) > 0 )
def setUp(self): self.net = pexpect.spawn('python -m mininet.examples.bind') self.net.expect("Private Directories: \[([\w\s,'/]+)\]") self.directories = [] # parse directories from mn output for d in self.net.match.group(1).split(', '): self.directories.append(d.strip("'")) self.net.expect(self.prompt) self.assertTrue(len(self.directories) > 0)
def testSwitches( self ): "Run iperf test using user and ovsk switches" switches = [ 'user', 'ovsk' ] for sw in switches: p = pexpect.spawn( 'mn --switch %s --test iperf' % sw ) p.expect( r"Results: \['([\d\.]+) .bits/sec'," ) bw = float( p.match.group( 1 ) ) self.assertTrue( bw > 0 ) p.expect( pexpect.EOF )
def testStaticMAC( self ): "Verify that MACs are set to easy to read numbers" p = pexpect.spawn( 'mn --mac' ) p.expect( self.prompt ) for i in range( 1, 3 ): p.sendline( 'h%d ifconfig' % i ) p.expect( r'\s00:00:00:00:00:0%d\s' % i ) p.expect( self.prompt ) p.sendline( 'exit' ) p.expect( pexpect.EOF )
def testClusterPingAll( self ): p = pexpect.spawn( 'python -m mininet.examples.clusterSanity' ) p.expect( self.prompt ) p.sendline( 'pingall' ) p.expect ( '(\d+)% dropped' ) percent = int( p.match.group( 1 ) ) if p.match else -1 self.assertEqual( percent, 0 ) p.expect( self.prompt ) p.sendline( 'exit' ) p.wait()
def testClusterPingAll(self): p = pexpect.spawn('python -m mininet.examples.clusterSanity') p.expect(self.prompt) p.sendline('pingall') p.expect('(\d+)% dropped') percent = int(p.match.group(1)) if p.match else -1 self.assertEqual(percent, 0) p.expect(self.prompt) p.sendline('exit') p.wait()
def testFailover(self): "Kill controllers and verify that switch, s1, fails over properly" count = 1 p = pexpect.spawn('python -m mininet.examples.controlnet') p.expect(self.prompt) lp = pexpect.spawn('tail -f /tmp/s1-ofp.log') lp.expect('tcp:\d+\.\d+\.\d+\.(\d+):\d+: connected') ip = int(lp.match.group(1)) self.assertEqual(count, ip) count += 1 for c in ['c0', 'c1']: p.sendline('%s ifconfig %s-eth0 down' % (c, c)) p.expect(self.prompt) lp.expect('tcp:\d+\.\d+\.\d+\.(\d+):\d+: connected') ip = int(lp.match.group(1)) self.assertEqual(count, ip) count += 1 p.sendline('exit') p.wait()
def testNAT( self ): "Attempt to ping an IP on the Internet and verify 0% packet loss" p = pexpect.spawn( 'python -m mininet.examples.nat' ) p.expect( self.prompt ) p.sendline( 'h1 ping -c 1 %s' % destIP ) p.expect ( '(\d+)% packet loss' ) percent = int( p.match.group( 1 ) ) if p.match else -1 p.expect( self.prompt ) p.sendline( 'exit' ) p.wait() self.assertEqual( percent, 0 )
def testCustomTopo( self ): "Start Mininet using a custom topo, then run pingall" # Satisfy pylint assert self custom = os.path.dirname( os.path.realpath( __file__ ) ) custom = os.path.join( custom, '../../custom/topo-2sw-2host.py' ) custom = os.path.normpath( custom ) p = pexpect.spawn( 'mn --custom %s --topo mytopo --test pingall' % custom ) p.expect( '0% dropped' ) p.expect( pexpect.EOF )
def testPingall( self ): "Test connectivity between hosts" p = pexpect.spawn( 'python -m mininet.examples.linuxrouter' ) p.expect( self.prompt ) p.sendline( 'pingall' ) p.expect ( '(\d+)% dropped' ) percent = int( p.match.group( 1 ) ) if p.match else -1 p.expect( self.prompt ) p.sendline( 'exit' ) p.wait() self.assertEqual( percent, 0 )
def testNAT(self): "Attempt to ping an IP on the Internet and verify 0% packet loss" p = pexpect.spawn('python -m mininet.examples.nat') p.expect(self.prompt) p.sendline('h1 ping -c 1 %s' % destIP) p.expect('(\d+)% packet loss') percent = int(p.match.group(1)) if p.match else -1 p.expect(self.prompt) p.sendline('exit') p.wait() self.assertEqual(percent, 0)
def testRouterPing( self ): "Test connectivity from h1 to router" p = pexpect.spawn( 'python -m mininet.examples.linuxrouter' ) p.expect( self.prompt ) p.sendline( 'h1 ping -c 1 r0' ) p.expect ( '(\d+)% packet loss' ) percent = int( p.match.group( 1 ) ) if p.match else -1 p.expect( self.prompt ) p.sendline( 'exit' ) p.wait() self.assertEqual( percent, 0 )
def testTTL( self ): "Verify that the TTL is decremented" p = pexpect.spawn( 'python -m mininet.examples.linuxrouter' ) p.expect( self.prompt ) p.sendline( 'h1 ping -c 1 h2' ) p.expect ( 'ttl=(\d+)' ) ttl = int( p.match.group( 1 ) ) if p.match else -1 p.expect( self.prompt ) p.sendline( 'exit' ) p.wait() self.assertEqual( ttl, 63 ) # 64 - 1
def testLocalPing( self ): "Verify connectivity between virtual hosts using pingall" p = pexpect.spawn( 'python -m mininet.examples.hwintf %s' % self.n0.intf() ) p.expect( self.prompt ) p.sendline( 'pingall' ) p.expect ( '(\d+)% dropped' ) percent = int( p.match.group( 1 ) ) if p.match else -1 self.assertEqual( percent, 0 ) p.expect( self.prompt ) p.sendline( 'exit' ) p.wait()
def testRouterPing(self): "Test connectivity from h1 to router" p = pexpect.spawn('python -m mininet.examples.linuxrouter') p.expect(self.prompt) p.sendline('h1 ping -c 1 r0') p.expect('(\d+)% packet loss') percent = int(p.match.group(1)) if p.match else -1 p.expect(self.prompt) p.sendline('exit') p.wait() self.assertEqual(percent, 0)
def testTTL(self): "Verify that the TTL is decremented" p = pexpect.spawn('python -m mininet.examples.linuxrouter') p.expect(self.prompt) p.sendline('h1 ping -c 1 h2') p.expect('ttl=(\d+)') ttl = int(p.match.group(1)) if p.match else -1 p.expect(self.prompt) p.sendline('exit') p.wait() self.assertEqual(ttl, 63) # 64 - 1
def testPingall(self): "Simple pingall test that verifies 0% packet drop in data network" p = pexpect.spawn('python -m mininet.examples.controlnet') p.expect(self.prompt) p.sendline('pingall') p.expect('(\d+)% dropped') percent = int(p.match.group(1)) if p.match else -1 self.assertEqual(percent, 0) p.expect(self.prompt) p.sendline('exit') p.wait()
def testPingall(self): "Test connectivity between hosts" p = pexpect.spawn('python -m mininet.examples.linuxrouter') p.expect(self.prompt) p.sendline('pingall') p.expect('(\d+)% dropped') percent = int(p.match.group(1)) if p.match else -1 p.expect(self.prompt) p.sendline('exit') p.wait() self.assertEqual(percent, 0)
def connected( self ): "Log into ssh server, check banner, then exit" p = pexpect.spawn( 'ssh 10.0.0.1 -o ConnectTimeout=1 ' '-o StrictHostKeyChecking=no ' '-i /tmp/ssh/test_rsa exit' ) while True: index = p.expect( self.opts ) if index == 0: return True else: return False
def testVLANTopo( self ): "Test connectivity (or lack thereof) between hosts in VLANTopo" p = pexpect.spawn( 'python -m mininet.examples.vlanhost' ) p.expect( self.prompt ) p.sendline( 'pingall 1' ) #ping timeout=1 p.expect( '(\d+)% dropped', timeout=30 ) # there should be 24 failed pings percent = int( p.match.group( 1 ) ) if p.match else -1 p.expect( self.prompt ) p.sendline( 'exit' ) p.wait() self.assertEqual( percent, 80 )
def connected(self): "Log into ssh server, check banner, then exit" p = pexpect.spawn('ssh 10.0.0.1 -o ConnectTimeout=1 ' '-o StrictHostKeyChecking=no ' '-i /tmp/ssh/test_rsa exit') while True: index = p.expect(self.opts) if index == 0: return True else: return False
def testVLANTopo(self): "Test connectivity (or lack thereof) between hosts in VLANTopo" p = pexpect.spawn('python -m mininet.examples.vlanhost') p.expect(self.prompt) p.sendline('pingall 1') #ping timeout=1 p.expect('(\d+)% dropped', timeout=30) # there should be 24 failed pings percent = int(p.match.group(1)) if p.match else -1 p.expect(self.prompt) p.sendline('exit') p.wait() self.assertEqual(percent, 80)
def setUp( self ): # create public key pair for testing sh( 'rm -rf /tmp/ssh' ) sh( 'mkdir /tmp/ssh' ) sh( "ssh-keygen -t rsa -P '' -f /tmp/ssh/test_rsa" ) sh( 'cat /tmp/ssh/test_rsa.pub >> /tmp/ssh/authorized_keys' ) cmd = ( 'python -m mininet.examples.sshd -D ' '-o AuthorizedKeysFile=/tmp/ssh/authorized_keys ' '-o StrictModes=no -o UseDNS=no -u0' ) # run example with custom sshd args self.net = pexpect.spawn( cmd ) self.net.expect( 'mininet>' )
def testConnectivity( self ): "Test ping and pingall" p = pexpect.spawn( 'mn' ) p.expect( self.prompt ) p.sendline( 'h1 ping -c 1 h2' ) p.expect( '1 packets transmitted, 1 received' ) p.expect( self.prompt ) p.sendline( 'pingall' ) p.expect( '0% dropped' ) p.expect( self.prompt ) p.sendline( 'exit' ) p.wait()
def testLocalPing(self): "Verify connectivity between virtual hosts using pingall" p = pexpect.spawn('python -m mininet.examples.hwintf %s' % self.n0.intf()) p.expect(self.prompt) p.sendline('pingall') p.expect('(\d+)% dropped') percent = int(p.match.group(1)) if p.match else -1 self.assertEqual(percent, 0) p.expect(self.prompt) p.sendline('exit') p.wait()
def testHostCommands(self): "Test ifconfig and ps on h1 and s1" p = pexpect.spawn('mn -w') p.expect(self.prompt) # Third pattern is a local interface beginning with 'eth' or 'en' interfaces = [ r'h1-eth0[:\s]', r's1-eth1[:\s]', r'[^-](eth|en)\w*\d[:\s]', r'lo[:\s]', self.prompt ] # h1 ifconfig p.sendline('h1 ifconfig -a') ifcount = 0 while True: index = p.expect(interfaces) if index in (0, 3): ifcount += 1 elif index == 1: self.fail('s1 interface displayed in "h1 ifconfig"') elif index == 2: self.fail('eth0 displayed in "h1 ifconfig"') else: break self.assertEqual(ifcount, 2, 'Missing interfaces on h1') # s1 ifconfig p.sendline('s1 ifconfig -a') ifcount = 0 while True: index = p.expect(interfaces) if index == 0: self.fail('h1 interface displayed in "s1 ifconfig"') elif index in (1, 2, 3): ifcount += 1 else: break self.assertTrue(ifcount <= 3, 'Missing interfaces on s1') # h1 ps p.sendline("h1 ps -a | egrep -v 'ps|grep'") p.expect(self.prompt) h1Output = p.before # s1 ps p.sendline("s1 ps -a | egrep -v 'ps|grep'") p.expect(self.prompt) s1Output = p.before # strip command from ps output and compute diffs h1Output = h1Output.split('\n')[1:] s1Output = s1Output.split('\n')[1:] diffs = set(h1Output).difference(set(s1Output)) # allow up to two diffs to account for daemons, etc. self.assertTrue( len(diffs) <= 2, 'h1 and s1 "ps" output differ too much: %s' % diffs) p.sendline('exit') p.wait()
def setUp(self): # create public key pair for testing sh('rm -rf /tmp/ssh') sh('mkdir /tmp/ssh') sh("ssh-keygen -t rsa -P '' -f /tmp/ssh/test_rsa") sh('cat /tmp/ssh/test_rsa.pub >> /tmp/ssh/authorized_keys') cmd = ('python -m mininet.examples.sshd -D ' '-o AuthorizedKeysFile=/tmp/ssh/authorized_keys ' '-o StrictModes=no -o UseDNS=no -u0') # run example with custom sshd args self.net = pexpect.spawn(cmd) self.net.expect('mininet>')
def testTree1024(self): "Run the example and do a simple ping test from h1 to h1024" p = pexpect.spawn('python -m mininet.examples.tree1024') p.expect(self.prompt, timeout=6000) # it takes awhile to set up p.sendline('h1 ping -c 20 h1024') p.expect('(\d+)% packet loss') packetLossPercent = int(p.match.group(1)) if p.match else -1 p.expect(self.prompt) p.sendline('exit') p.wait() # Tolerate slow startup on some systems - we should revisit this # and determine the root cause. self.assertLess(packetLossPercent, 60)
def testTree1024( self ): "Run the example and do a simple ping test from h1 to h1024" p = pexpect.spawn( 'python -m mininet.examples.tree1024' ) p.expect( self.prompt, timeout=6000 ) # it takes awhile to set up p.sendline( 'h1 ping -c 20 h1024' ) p.expect ( '(\d+)% packet loss' ) packetLossPercent = int( p.match.group( 1 ) ) if p.match else -1 p.expect( self.prompt ) p.sendline( 'exit' ) p.wait() # Tolerate slow startup on some systems - we should revisit this # and determine the root cause. self.assertLess( packetLossPercent, 60 )
def testHostCommands( self ): "Test ifconfig and ps on h1 and s1" p = pexpect.spawn( 'mn' ) p.expect( self.prompt ) # Third pattern is a local interface beginning with 'eth' or 'en' interfaces = [ r'h1-eth0[:\s]', r's1-eth1[:\s]', r'[^-](eth|en)\w*\d[:\s]', r'lo[:\s]', self.prompt ] # h1 ifconfig p.sendline( 'h1 ifconfig -a' ) ifcount = 0 while True: index = p.expect( interfaces ) if index == 0 or index == 3: ifcount += 1 elif index == 1: self.fail( 's1 interface displayed in "h1 ifconfig"' ) elif index == 2: self.fail( 'eth0 displayed in "h1 ifconfig"' ) else: break self.assertEqual( ifcount, 2, 'Missing interfaces on h1') # s1 ifconfig p.sendline( 's1 ifconfig -a' ) ifcount = 0 while True: index = p.expect( interfaces ) if index == 0: self.fail( 'h1 interface displayed in "s1 ifconfig"' ) elif index == 1 or index == 2 or index == 3: ifcount += 1 else: break self.assertTrue( ifcount <= 3, 'Missing interfaces on s1') # h1 ps p.sendline( "h1 ps -a | egrep -v 'ps|grep'" ) p.expect( self.prompt ) h1Output = p.before # s1 ps p.sendline( "s1 ps -a | egrep -v 'ps|grep'" ) p.expect( self.prompt ) s1Output = p.before # strip command from ps output and compute diffs h1Output = h1Output.split( '\n' )[ 1: ] s1Output = s1Output.split( '\n' )[ 1: ] diffs = set( h1Output ).difference( set( s1Output ) ) # allow up to two diffs to account for daemons, etc. self.assertTrue( len( diffs ) <= 2, 'h1 and s1 "ps" output differ too much: %s' % diffs ) p.sendline( 'exit' ) p.wait()
def testE2E( self ): "Run the example and verify iperf results" # 10 Mb/s, plus or minus 20% tolerance BW = 10 TOLERANCE = .2 p = pexpect.spawn( 'python -m mininet.examples.simpleperf testmode' ) # check iperf results p.expect( "Results: \['10M', '([\d\.]+) .bits/sec", timeout=480 ) measuredBw = float( p.match.group( 1 ) ) lowerBound = BW * ( 1 - TOLERANCE ) upperBound = BW + ( 1 + TOLERANCE ) self.assertGreaterEqual( measuredBw, lowerBound ) self.assertLessEqual( measuredBw, upperBound ) p.wait()
def testTreePing64( self ): "Run the example and verify ping results" p = pexpect.spawn( 'python -m mininet.examples.treeping64' ) p.expect( 'Tree network ping results:', timeout=6000 ) count = 0 while True: index = p.expect( [ '(\d+)% packet loss', pexpect.EOF ] ) if index == 0: percent = int( p.match.group( 1 ) ) if p.match else -1 self.assertEqual( percent, 0 ) count += 1 else: break self.assertTrue( count > 0 )
def testEmptyNet( self ): "Run simple CLI tests: pingall (verify 0% drop) and iperf (sanity)" p = pexpect.spawn( 'python -m mininet.examples.emptynet' ) p.expect( self.prompt ) # pingall test p.sendline( 'pingall' ) p.expect ( '(\d+)% dropped' ) percent = int( p.match.group( 1 ) ) if p.match else -1 self.assertEqual( percent, 0 ) p.expect( self.prompt ) # iperf test p.sendline( 'iperf' ) p.expect( "Results: \['[\d.]+ .bits/sec', '[\d.]+ .bits/sec'\]" ) p.expect( self.prompt ) p.sendline( 'exit' ) p.wait()
def testLink( self ): "Test link CLI command using ping" p = pexpect.spawn( 'mn' ) p.expect( self.prompt ) p.sendline( 'link s1 h1 down' ) p.expect( self.prompt ) p.sendline( 'h1 ping -c 1 h2' ) p.expect( 'unreachable' ) p.expect( self.prompt ) p.sendline( 'link s1 h1 up' ) p.expect( self.prompt ) p.sendline( 'h1 ping -c 1 h2' ) p.expect( '0% packet loss' ) p.expect( self.prompt ) p.sendline( 'exit' ) p.wait()
def testMultiTest( self ): "Verify pingall (0% dropped) and hX-eth0 interface for each host (ifconfig)" p = pexpect.spawn( 'python -m mininet.examples.multitest' ) p.expect( '(\d+)% dropped' ) dropped = int( p.match.group( 1 ) ) self.assertEqual( dropped, 0 ) ifCount = 0 while True: index = p.expect( [ 'h\d-eth0', self.prompt ] ) if index == 0: ifCount += 1 elif index == 1: p.sendline( 'exit' ) break p.wait() self.assertEqual( ifCount, 4 )