Statistics
| Branch: | Tag: | Revision:

mininet / examples / test / test_hwintf.py @ c5da46f1

History | View | Annotate | Download (1.86 KB)

1 a46fae06 Brian O'Connor
#!/usr/bin/env python
2
3 91a06063 Brian O'Connor
"""
4
Test for hwintf.py
5
"""
6 a46fae06 Brian O'Connor
7
import unittest
8
import pexpect
9
import re
10
from mininet.log import setLogLevel
11
from mininet.net import Mininet
12
from mininet.node import Node
13
from mininet.link import Link, Intf
14
15
class testHwintf( unittest.TestCase ):
16
17
    prompt = 'mininet>'
18
19
    def setUp( self ):
20
        self.h3 = Node( 't0', ip='10.0.0.3/8' )
21 91a06063 Brian O'Connor
        self.n0 = Node( 't1', inNamespace=False )
22 a46fae06 Brian O'Connor
        Link( self.h3, self.n0 )
23
        self.h3.configDefault()
24
25
    def testLocalPing( self ):
26 91a06063 Brian O'Connor
        "Verify connectivity between virtual hosts using pingall"
27 a46fae06 Brian O'Connor
        p = pexpect.spawn( 'python -m mininet.examples.hwintf %s' % self.n0.intf() )
28
        p.expect( self.prompt )
29
        p.sendline( 'pingall' )
30
        p.expect ( '(\d+)% dropped' )
31
        percent = int( p.match.group( 1 ) ) if p.match else -1
32
        self.assertEqual( percent, 0 )
33
        p.expect( self.prompt )
34
        p.sendline( 'exit' )
35
        p.wait()
36
37
    def testExternalPing( self ):
38 91a06063 Brian O'Connor
        "Verify connnectivity between virtual host and virtual-physical 'external' host "
39 a46fae06 Brian O'Connor
        p = pexpect.spawn( 'python -m mininet.examples.hwintf %s' % self.n0.intf() )
40
        p.expect( self.prompt )
41 91a06063 Brian O'Connor
        # test ping external to internal
42
        expectStr = '(\d+) packets transmitted, (\d+) received'
43 a46fae06 Brian O'Connor
        m = re.search( expectStr, self.h3.cmd( 'ping -v -c 1 10.0.0.1' ) )
44
        tx = m.group( 1 )
45
        rx = m.group( 2 )
46
        self.assertEqual( tx, rx )
47 91a06063 Brian O'Connor
        # test ping internal to external
48 a46fae06 Brian O'Connor
        p.sendline( 'h1 ping -c 1 10.0.0.3')
49
        p.expect( expectStr )
50
        tx = p.match.group( 1 )
51
        rx = p.match.group( 2 )
52
        self.assertEqual( tx, rx )
53
        p.expect( self.prompt )
54
        p.sendline( 'exit' )
55
        p.wait()
56
57
    def tearDown( self ):
58
        self.h3.terminate()
59
        self.n0.terminate()
60
61
if __name__ == '__main__':
62
    setLogLevel( 'warning' )
63
    unittest.main()