Statistics
| Branch: | Tag: | Revision:

mininet / mininet / test / test_nets.py @ 18aab5b7

History | View | Annotate | Download (3.65 KB)

1
#!/usr/bin/env python
2

    
3
"""Package: mininet
4
   Test creation and all-pairs ping for each included mininet topo type."""
5

    
6
import unittest
7
import sys
8
from functools import partial
9

    
10
from mininet.net import Mininet
11
from mininet.node import Host, Controller
12
from mininet.node import UserSwitch, OVSSwitch, IVSSwitch
13
from mininet.topo import SingleSwitchTopo, LinearTopo
14
from mininet.log import setLogLevel
15
from mininet.util import quietRun
16
from mininet.clean import cleanup
17

    
18
# Tell pylint not to complain about calls to other class
19
# pylint: disable=E1101
20

    
21
class testSingleSwitchCommon( object ):
22
    "Test ping with single switch topology (common code)."
23

    
24
    switchClass = None # overridden in subclasses
25

    
26
    @staticmethod
27
    def tearDown():
28
        "Clean up if necessary"
29
        if sys.exc_info != ( None, None, None ):
30
            cleanup()
31

    
32
    def testMinimal( self ):
33
        "Ping test on minimal topology"
34
        mn = Mininet( SingleSwitchTopo(), self.switchClass, Host, Controller,
35
                      waitConnected=True )
36
        dropped = mn.run( mn.ping )
37
        self.assertEqual( dropped, 0 )
38

    
39
    def testSingle5( self ):
40
        "Ping test on 5-host single-switch topology"
41
        mn = Mininet( SingleSwitchTopo( k=5 ), self.switchClass, Host,
42
                      Controller, waitConnected=True )
43
        dropped = mn.run( mn.ping )
44
        self.assertEqual( dropped, 0 )
45

    
46
# pylint: enable=E1101
47

    
48
class testSingleSwitchOVSKernel( testSingleSwitchCommon, unittest.TestCase ):
49
    "Test ping with single switch topology (OVS kernel switch)."
50
    switchClass = OVSSwitch
51

    
52
class testSingleSwitchOVSUser( testSingleSwitchCommon, unittest.TestCase ):
53
    "Test ping with single switch topology (OVS user switch)."
54
    switchClass = partial( OVSSwitch, datapath='user' )
55

    
56
@unittest.skipUnless( quietRun( 'which ivs-ctl' ), 'IVS is not installed' )
57
class testSingleSwitchIVS( testSingleSwitchCommon, unittest.TestCase ):
58
    "Test ping with single switch topology (IVS switch)."
59
    switchClass = IVSSwitch
60

    
61
@unittest.skipUnless( quietRun( 'which ofprotocol' ),
62
                     'Reference user switch is not installed' )
63
class testSingleSwitchUserspace( testSingleSwitchCommon, unittest.TestCase ):
64
    "Test ping with single switch topology (Userspace switch)."
65
    switchClass = UserSwitch
66

    
67

    
68
# Tell pylint not to complain about calls to other class
69
# pylint: disable=E1101
70

    
71
class testLinearCommon( object ):
72
    "Test all-pairs ping with LinearNet (common code)."
73

    
74
    switchClass = None # overridden in subclasses
75

    
76
    def testLinear5( self ):
77
        "Ping test on a 5-switch topology"
78
        mn = Mininet( LinearTopo( k=5 ), self.switchClass, Host,
79
                      Controller, waitConnected=True )
80
        dropped = mn.run( mn.ping )
81
        self.assertEqual( dropped, 0 )
82

    
83
# pylint: enable=E1101
84

    
85

    
86
class testLinearOVSKernel( testLinearCommon, unittest.TestCase ):
87
    "Test all-pairs ping with LinearNet (OVS kernel switch)."
88
    switchClass = OVSSwitch
89

    
90
class testLinearOVSUser( testLinearCommon, unittest.TestCase ):
91
    "Test all-pairs ping with LinearNet (OVS user switch)."
92
    switchClass = partial( OVSSwitch, datapath='user' )
93

    
94
@unittest.skipUnless( quietRun( 'which ivs-ctl' ), 'IVS is not installed' )
95
class testLinearIVS( testLinearCommon, unittest.TestCase ):
96
    "Test all-pairs ping with LinearNet (IVS switch)."
97
    switchClass = IVSSwitch
98

    
99
@unittest.skipUnless( quietRun( 'which ofprotocol' ),
100
                      'Reference user switch is not installed' )
101
class testLinearUserspace( testLinearCommon, unittest.TestCase ):
102
    "Test all-pairs ping with LinearNet (Userspace switch)."
103
    switchClass = UserSwitch
104

    
105

    
106
if __name__ == '__main__':
107
    setLogLevel( 'warning' )
108
    unittest.main()