Statistics
| Branch: | Tag: | Revision:

mininet / mininet / test / test_nets.py @ 684092ba

History | View | Annotate | Download (3.45 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
from functools import partial
8

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

    
16
# Tell pylint not to complain about calls to other class
17
# pylint: disable=E1101
18

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

    
22
    switchClass = None # overridden in subclasses
23

    
24
    def testMinimal( self ):
25
        "Ping test on minimal topology"
26
        mn = Mininet( SingleSwitchTopo(), self.switchClass, Host, Controller,
27
                      waitConnected=True )
28
        dropped = mn.run( mn.ping )
29
        self.assertEqual( dropped, 0 )
30

    
31
    def testSingle5( self ):
32
        "Ping test on 5-host single-switch topology"
33
        mn = Mininet( SingleSwitchTopo( k=5 ), self.switchClass, Host,
34
                      Controller, waitConnected=True )
35
        dropped = mn.run( mn.ping )
36
        self.assertEqual( dropped, 0 )
37

    
38
# pylint: enable=E1101
39

    
40
class testSingleSwitchOVSKernel( testSingleSwitchCommon, unittest.TestCase ):
41
    "Test ping with single switch topology (OVS kernel switch)."
42
    switchClass = OVSSwitch
43

    
44
class testSingleSwitchOVSUser( testSingleSwitchCommon, unittest.TestCase ):
45
    "Test ping with single switch topology (OVS user switch)."
46
    switchClass = partial( OVSSwitch, datapath='user' )
47

    
48
@unittest.skipUnless( quietRun( 'which ivs-ctl' ), 'IVS is not installed' )
49
class testSingleSwitchIVS( testSingleSwitchCommon, unittest.TestCase ):
50
    "Test ping with single switch topology (IVS switch)."
51
    switchClass = IVSSwitch
52

    
53
@unittest.skipUnless( quietRun( 'which ofprotocol' ),
54
                     'Reference user switch is not installed' )
55
class testSingleSwitchUserspace( testSingleSwitchCommon, unittest.TestCase ):
56
    "Test ping with single switch topology (Userspace switch)."
57
    switchClass = UserSwitch
58

    
59

    
60
# Tell pylint not to complain about calls to other class
61
# pylint: disable=E1101
62

    
63
class testLinearCommon( object ):
64
    "Test all-pairs ping with LinearNet (common code)."
65

    
66
    switchClass = None # overridden in subclasses
67

    
68
    def testLinear5( self ):
69
        "Ping test on a 5-switch topology"
70
        mn = Mininet( LinearTopo( k=5 ), self.switchClass, Host, Controller, waitConnected=True )
71
        dropped = mn.run( mn.ping )
72
        self.assertEqual( dropped, 0 )
73

    
74
# pylint: enable=E1101
75

    
76

    
77
class testLinearOVSKernel( testLinearCommon, unittest.TestCase ):
78
    "Test all-pairs ping with LinearNet (OVS kernel switch)."
79
    switchClass = OVSSwitch
80

    
81
class testLinearOVSUser( testLinearCommon, unittest.TestCase ):
82
    "Test all-pairs ping with LinearNet (OVS user switch)."
83
    switchClass = partial( OVSSwitch, datapath='user' )
84

    
85
@unittest.skipUnless( quietRun( 'which ivs-ctl' ), 'IVS is not installed' )
86
class testLinearIVS( testLinearCommon, unittest.TestCase ):
87
    "Test all-pairs ping with LinearNet (IVS switch)."
88
    switchClass = IVSSwitch
89

    
90
@unittest.skipUnless( quietRun( 'which ofprotocol' ),
91
                      'Reference user switch is not installed' )
92
class testLinearUserspace( testLinearCommon, unittest.TestCase ):
93
    "Test all-pairs ping with LinearNet (Userspace switch)."
94
    switchClass = UserSwitch
95

    
96

    
97
if __name__ == '__main__':
98
    setLogLevel( 'warning' )
99
    unittest.main()