Statistics
| Branch: | Tag: | Revision:

mininet / mininet / nodelib.py @ 3878c000

History | View | Annotate | Download (1.33 KB)

1
"""
2
Package: nodelib
3

4
Node Library for Mininet
5

6
This contains additional node types which you may find to be useful
7
"""
8

    
9
from mininet.net import Mininet
10
from mininet.topo import Topo
11
from mininet.node import Switch
12
from mininet.log import setLogLevel, info
13

    
14
class LinuxBridge( Switch ):
15
    "Linux Bridge (with optional spanning tree)"
16

    
17
    nextPrio = 100  # next bridge priority for spanning tree
18

    
19
    def __init__( self, name, stp=False, prio=None, **kwargs ):
20
        """stp: use spanning tree protocol? (default False)
21
           prio: optional explicit bridge priority for STP"""
22
        self.stp = stp
23
        if prio:
24
            self.prio = prio
25
        else:
26
            self.prio = LinuxBridge.nextPrio
27
            LinuxBridge.nextPrio += 1
28
        Switch.__init__( self, name, **kwargs )
29

    
30
    def start( self, controllers ):
31
        self.cmd( 'ifconfig', self, 'down' )
32
        self.cmd( 'brctl delbr', self )
33
        self.cmd( 'brctl addbr', self )
34
        if self.stp:
35
            self.cmd( 'brctl setbridgeprio', self.prio )
36
            self.cmd( 'brctl stp', self, 'on' )
37
        for i in self.intfList():
38
            if self.name in i.name:
39
                self.cmd( 'brctl addif', self, i )
40
        self.cmd( 'ifconfig', self, 'up' )
41

    
42
    def stop( self ):
43
        self.cmd( 'ifconfig', self, 'down' )
44
        self.cmd( 'brctl delbr', self )
45