8 from mininet.util import pexpect
9 from collections import defaultdict
11 class testMultiPing( unittest.TestCase ):
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",
20 pings = defaultdict( list )
22 index = p.expect( opts )
24 name = p.match.group(1)
26 targets = p.match.group(3).split()
27 pings[ name ] += targets
29 name = p.match.group(1)
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 )
37 self.assertEqual( received, 1, p.match.group(0) + '\n' +
38 target + ' received %d != 1 packets' % received )
40 pings[ name ].remove( target )
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 )
49 if __name__ == '__main__':