Statistics
| Branch: | Tag: | Revision:

mininet / examples / test / test_multiping.py @ e6e1260b

History | View | Annotate | Download (1.56 KB)

1
#!/usr/bin/env python
2

    
3
"""
4
Test for multiping.py
5
"""
6

    
7
import unittest
8
import pexpect
9
from collections import defaultdict
10

    
11
class 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 )
35
                else:
36
                    self.assertEqual( received, 1 )
37
                try:
38
                    pings[ name ].remove( target )
39
                except:
40
                    pass
41
            else:
42
                break
43
        self.assertTrue( len( pings ) > 0 )
44
        for t in pings.values():
45
            self.assertEqual( len( t ), 0 )
46

    
47
if __name__ == '__main__':
48
    unittest.main()