File: test_natnet.py

package info (click to toggle)
mininet 2.3.0-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,588 kB
  • sloc: python: 11,181; ansic: 1,332; sh: 967; makefile: 87
file content (57 lines) | stat: -rwxr-xr-x 1,845 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python

"""
Test for natnet.py
"""

import unittest
from mininet.util import pexpect
from mininet.util import quietRun

class testNATNet( unittest.TestCase ):

    prompt = 'mininet>'

    def setUp( self ):
        self.net = pexpect.spawn( 'python -m mininet.examples.natnet' )
        self.net.expect( self.prompt )

    def testPublicPing( self ):
        "Attempt to ping the public server (h0) from h1 and h2"
        self.net.sendline( 'h1 ping -c 1 h0' )
        self.net.expect ( '(\d+)% packet loss' )
        percent = int( self.net.match.group( 1 ) ) if self.net.match else -1
        self.assertEqual( percent, 0 )
        self.net.expect( self.prompt )

        self.net.sendline( 'h2 ping -c 1 h0' )
        self.net.expect ( '(\d+)% packet loss' )
        percent = int( self.net.match.group( 1 ) ) if self.net.match else -1
        self.assertEqual( percent, 0 )
        self.net.expect( self.prompt )

    def testPrivatePing( self ):
        "Attempt to ping h1 and h2 from public server"
        self.net.sendline( 'h0 ping -c 1 -t 1 h1' )
        result = self.net.expect ( [ 'unreachable', 'loss' ] )
        self.assertEqual( result, 0 )
        self.net.expect( self.prompt )

        self.net.sendline( 'h0 ping -c 1 -t 1 h2' )
        result = self.net.expect ( [ 'unreachable', 'loss' ] )
        self.assertEqual( result, 0 )
        self.net.expect( self.prompt )

    def testPrivateToPrivatePing( self ):
        "Attempt to ping from NAT'ed host h1 to NAT'ed host h2"
        self.net.sendline( 'h1 ping -c 1 -t 1 h2' )
        result = self.net.expect ( [ '[Uu]nreachable', 'loss' ] )
        self.assertEqual( result, 0 )
        self.net.expect( self.prompt )

    def tearDown( self ):
        self.net.sendline( 'exit' )
        self.net.wait()

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