MCPcopy Create free account
hub / github.com/mininet/mininet / testMultiPing

Method testMultiPing

examples/test/test_multiping.py:13–47  ·  view source on GitHub ↗

Verify that each target is pinged at least once, and that pings to 'real' targets are successful and unknown targets fail

( self )

Source from the content-addressed store, hash-verified

11class testMultiPing( unittest.TestCase ):
12
13 def testMultiPing( self ):
14 """Verify that each target is pinged at least once, and
15 that pings to 'real' targets are successful and unknown targets fail"""
16 p = pexpect.spawn( 'python -m mininet.examples.multiping' )
17 opts = [ "Host (h\d+) \(([\d.]+)\) will be pinging ips: ([\d\. ]+)",
18 "(h\d+): ([\d.]+) -> ([\d.]+) \d packets transmitted, (\d) received",
19 pexpect.EOF ]
20 pings = defaultdict( list )
21 while True:
22 index = p.expect( opts )
23 if index == 0:
24 name = p.match.group(1)
25 ip = p.match.group(2)
26 targets = p.match.group(3).split()
27 pings[ name ] += targets
28 elif index == 1:
29 name = p.match.group(1)
30 ip = p.match.group(2)
31 target = p.match.group(3)
32 received = int( p.match.group(4) )
33 if target == '10.0.0.200':
34 self.assertEqual( received, 0, p.match.group(0) + '\n' +
35 target + ' received %d != 0 packets' % received )
36 else:
37 self.assertEqual( received, 1, p.match.group(0) + '\n' +
38 target + ' received %d != 1 packets' % received )
39 try:
40 pings[ name ].remove( target )
41 except:
42 pass
43 else:
44 break
45 self.assertTrue( len( pings ) > 0, 'too few pings' )
46 for t in pings.values():
47 self.assertEqual( len( t ), 0, 'missed ping target(s): %s' % t )
48
49if __name__ == '__main__':
50 unittest.main()

Callers

nothing calls this directly

Calls 2

spawnMethod · 0.80
valuesMethod · 0.45

Tested by

no test coverage detected