-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbridge_switch.py
70 lines (56 loc) · 2.07 KB
/
bridge_switch.py
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
58
59
60
61
62
63
64
65
66
67
68
69
from mininet.node import Switch
from mininet.util import (quietRun, errRun, errFail, moveIntf, isShellBuiltin,
numCores, retry, mountCgroups)
from mininet.moduledeps import moduleDeps, pathCheck, OVS_KMOD, OF_KMOD, TUN
from mininet.link import Link, Intf, TCIntf
from mininet.log import info, error, warn, debug
class BridgeSwitch(Switch):
"Bridge switch."
def __init__(self, name, blocking=False, **params):
Switch.__init__(self, name, **params)
self.block = blocking
@classmethod
def setup(cls):
pathCheck('brctl', moduleName='Bridge Control')
pathCheck('ebtables', moduleName='Ethernet filter')
def dpctl(self, *args):
return True
def attach(self, intf):
"Connect a data port to the bridge"
self.cmd('brctl addif', self, intf)
self.cmd('ifconfig', intf, 'up')
if self.block:
self.cmd('ebtables -A FORWARD -i', intf, '-p ARP -j DROP')
self.TCReapply(intf)
def detach(self, intf):
"Disconnect a data port"
self.cmd('brctl delif', self, intf)
def deleteIntfs(self, checkName=True):
for intf in self.intfs.values():
if self.block:
self.cmd('ebtables -D FORWARD -i', intf, '-p ARP -j DROP')
super(BridgeSwitch, self).deleteIntfs()
def controllerUUIDs(self):
"Return ovsdb UUIDs for our controllers"
uuids = []
return uuids
def connected(self):
return True
@staticmethod
def TCReapply(intf):
if type(intf) is TCIntf:
intf.config(**intf.params)
def start(self, controllers):
self.cmd('ifconfig lo up')
self.cmd('ifconfig', self, 'down')
self.cmd('brctl delbr', self)
self.cmd('brctl addbr', self)
for intf in self.intfList():
if not intf.IP():
self.attach(intf)
self.cmd('ifconfig', self, 'up')
def stop(self):
"Terminate OVS switch."
self.cmd('ifconfig', self, 'down')
self.cmd('brctl delbr', self)
self.deleteIntfs()