forked from netgroup/Dreamer-Mininet-Extensions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
coexistence_mechanisms.py
245 lines (160 loc) · 7.65 KB
/
coexistence_mechanisms.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
#!/usr/bin/python
import sys
from mininet.log import error
class CoexistenceMechanism (object):
prio_std_rules = 300
prio_special_rules = 301
prio_max = 32768
def __init__(self, eths, vis, name):
self.eths = eths
self.vis = vis
self.name = name
class CoexA(CoexistenceMechanism):
tableIP = 1
tableSBP = 0
def __init__(self, vlan_id, eths, vis, name):
if vlan_id > 4095:
error("ERROR VLAN ID Not Valid\n")
sys.exit(-2)
self.vlanIP = vlan_id
CoexistenceMechanism.__init__(self, eths, vis, name)
def getOVSRules(self):
rules = []
rules.append('ovs-ofctl add-flow %s "table=0,hard_timeout=0,priority=%s,dl_vlan=%s,actions=resubmit(,%s)"' %(self.name, self.prio_std_rules,
self.vlanIP, self.tableIP))
for eth, vi in zip(self.eths, self.vis):
rules.append('ovs-ofctl add-flow %s "table=%s,hard_timeout=0,priority=%s,in_port=%s,action=output:%s"' %(self.name, self.tableIP,
self.prio_std_rules, eth, vi))
rules.append('ovs-ofctl add-flow %s "table=%s,hard_timeout=0,priority=%s,in_port=%s,action=output:%s"' %(self.name, self.tableIP,
self.prio_std_rules, vi, eth))
rules.append('ovs-ofctl add-flow %s "table=%s,hard_timeout=0,priority=%s,dl_type=0x88cc,action=controller"' %(self.name, self.tableIP,
self.prio_special_rules))
rules.append('ovs-ofctl add-flow %s "table=%s,hard_timeout=0,priority=%s,dl_type=0x8942,action=controller"' %(self.name, self.tableIP,
self.prio_special_rules))
return rules
def getIPCommands(self):
commands = []
for eth, vi in zip(self.eths, self.vis):
commands.append('ifconfig %s 0' % eth)
commands.append('ip link set %s up' % vi)
commands.append('vconfig add %s %s' % (vi, self.vlanIP))
return commands
def getQuaggaInterfaces(self):
interfaces = []
for vi in self.vis:
interfaces.append("%s.%s" %(vi, self.vlanIP))
return interfaces
class CoexA_13(CoexA):
def __init__(self, vlan_id, eths, vis, name):
CoexA.__init__(self, vlan_id, eths, vis, name)
def getOVSRules(self):
rules = []
rules.append('ovs-ofctl -O OpenFlow13 add-flow %s "table=0,hard_timeout=0,priority=%s,dl_vlan=%s,actions=goto_table:%s"' %(self.name,
self.prio_std_rules, self.vlanIP, self.tableIP))
for eth, vi in zip(self.eths, self.vis):
rules.append('ovs-ofctl -O OpenFlow13 add-flow %s "table=%s,hard_timeout=0,priority=%s,in_port=%s,action=output:%s"' %(self.name,
self.tableIP, self.prio_std_rules, eth, vi))
rules.append('ovs-ofctl -O OpenFlow13 add-flow %s "table=%s,hard_timeout=0,priority=%s,in_port=%s,action=output:%s"' %(self.name,
self.tableIP, self.prio_std_rules, vi, eth))
rules.append('ovs-ofctl -O OpenFlow13 add-flow %s "table=%s,hard_timeout=0,priority=%s,dl_type=0x88cc,action=controller"' %(self.name,
self.tableIP, self.prio_special_rules))
rules.append('ovs-ofctl -O OpenFlow13 add-flow %s "table=%s,hard_timeout=0,priority=%s,dl_type=0x8942,action=controller"' %(self.name,
self.tableIP, self.prio_special_rules))
return rules
class CoexB(CoexistenceMechanism):
tableIP = 1
tableSBP = 0
def __init__(self, eths, vis, name):
CoexistenceMechanism.__init__(self, eths, vis, name)
def getOVSRules(self):
rules = []
rules.append('ovs-ofctl add-flow %s "table=0,hard_timeout=0,priority=%s,dl_vlan=%s,actions=resubmit(,%s)"' %(self.name, self.prio_std_rules,
"0xffff", self.tableIP))
for eth, vi in zip(self.eths, self.vis):
rules.append('ovs-ofctl add-flow %s "table=%s,hard_timeout=0,priority=%s,in_port=%s,action=output:%s"' %(self.name, self.tableIP,
self.prio_std_rules, eth, vi))
rules.append('ovs-ofctl add-flow %s "table=%s,hard_timeout=0,priority=%s,in_port=%s,action=output:%s"' %(self.name, self.tableIP,
self.prio_std_rules, vi, eth))
rules.append('ovs-ofctl add-flow %s "table=%s,hard_timeout=0,priority=%s,dl_type=0x88cc,action=controller"' %(self.name, self.tableIP,
self.prio_special_rules))
rules.append('ovs-ofctl add-flow %s "table=%s,hard_timeout=0,priority=%s,dl_type=0x8942,action=controller"' %(self.name, self.tableIP,
self.prio_special_rules))
return rules
def getIPCommands(self):
commands = []
for eth, vi in zip(self.eths, self.vis):
commands.append('ifconfig %s 0' % eth)
return commands
def getQuaggaInterfaces(self):
interfaces = self.vis
return interfaces
class CoexB_13(CoexB):
def __init__(self, eths, vis, name):
CoexB.__init__(self, eths, vis, name)
def getOVSRules(self):
rules = []
rules.append('ovs-ofctl -O OpenFlow13 add-flow %s "table=0,hard_timeout=0,priority=%s,dl_vlan=%s,actions=goto_table:%s"' %(self.name,
self.prio_std_rules, "0xffff", self.tableIP))
for eth, vi in zip(self.eths, self.vis):
rules.append('ovs-ofctl -O OpenFlow13 add-flow %s "table=%s,hard_timeout=0,priority=%s,in_port=%s,action=output:%s"' %(self.name,
self.tableIP, self.prio_std_rules, eth, vi))
rules.append('ovs-ofctl -O OpenFlow13 add-flow %s "table=%s,hard_timeout=0,priority=%s,in_port=%s,action=output:%s"' %(self.name,
self.tableIP, self.prio_std_rules, vi, eth))
rules.append('ovs-ofctl -O OpenFlow13 add-flow %s "table=%s,hard_timeout=0,priority=%s,dl_type=0x88cc,action=controller"' %(self.name,
self.tableIP, self.prio_special_rules))
rules.append('ovs-ofctl -O OpenFlow13 add-flow %s "table=%s,hard_timeout=0,priority=%s,dl_type=0x8942,action=controller"' %(self.name,
self.tableIP, self.prio_special_rules))
return rules
class CoexH(CoexistenceMechanism):
tableIP=0
tableSBP = 1
MPLS_UNICAST = "0x8847"
MPLS_MULTICAST = "0x8848"
def __init__(self, eths, vis, name):
CoexistenceMechanism.__init__(self, eths, vis, name)
def getOVSRules(self):
rules = []
rules.append('ovs-ofctl -O OpenFlow13 add-flow %s "table=0,hard_timeout=0,priority=%s,dl_type=%s,actions=goto_table:%s"' %(self.name,
self.prio_max, self.MPLS_UNICAST, self.tableSBP))
rules.append('ovs-ofctl -O OpenFlow13 add-flow %s "table=0,hard_timeout=0,priority=%s,dl_type=%s,actions=goto_table:%s"' %(self.name,
self.prio_max, self.MPLS_MULTICAST, self.tableSBP))
for eth, vi in zip(self.eths, self.vis):
rules.append('ovs-ofctl -O OpenFlow13 add-flow %s "table=0,hard_timeout=0,priority=%s,in_port=%s,action=output:%s"' %(self.name,
self.prio_std_rules, eth, vi))
rules.append('ovs-ofctl -O OpenFlow13 add-flow %s "table=0,hard_timeout=0,priority=%s,in_port=%s,action=output:%s"' %(self.name,
self.prio_std_rules, vi, eth))
rules.append('ovs-ofctl -O OpenFlow13 add-flow %s "table=0,hard_timeout=0,priority=%s,dl_type=0x88cc,action=controller"' %(self.name,
self.prio_special_rules))
rules.append('ovs-ofctl -O OpenFlow13 add-flow %s "table=0,hard_timeout=0,priority=%s,dl_type=0x8942,action=controller"' %(self.name,
self.prio_special_rules))
return rules
def getIPCommands(self):
commands = []
for eth, vi in zip(self.eths, self.vis):
commands.append('ifconfig %s 0' % eth)
return commands
def getQuaggaInterfaces(self):
interfaces = self.vis
return interfaces
class CoexFactory(object):
coex_types=["COEXA", "COEXB", "COEXH"]
def getCoex(self, coex_type, coex_data, eths, vis, name, OF_V):
if coex_type not in self.coex_types:
error("ERROR %s not supported" % coex_type)
sys.exit(-2)
if coex_type == "COEXA":
if OF_V == None:
return CoexA(coex_data, eths, vis, name)
elif OF_V == "OpenFlow13":
return CoexA_13(coex_data, eths, vis, name)
if coex_type == "COEXB":
if OF_V == None:
return CoexB(eths, vis, name)
elif OF_V == "OpenFlow13":
return CoexB_13(eths, vis, name)
if coex_type == "COEXH":
if OF_V == None:
error("ERROR %s is not supported by OpenFlow 1.0" % coex_type)
sys.exit(-2)
elif OF_V == "OpenFlow13":
return CoexH(eths, vis, name)