blob: 2a8eba3362a3006620afb3db3c413d1110ae1534 [file] [log] [blame]
macauley97557232015-07-16 17:28:07 +08001import logging
2
3from oftest import config
4import oftest.base_tests as base_tests
5import ofp
6import time
7from oftest.testutils import *
8
macauleyfddc4662015-07-27 17:40:30 +08009from ncclient import manager
10import ncclient
11
macauley97557232015-07-16 17:28:07 +080012OFDPA_GROUP_TYPE_SHIFT=28
13OFDPA_VLAN_ID_SHIFT =16
macauleyfddc4662015-07-27 17:40:30 +080014OFDPA_TUNNEL_ID_SHIFT =12
15OFDPA_TUNNEL_SUBTYPE_SHIFT=10
macauley97557232015-07-16 17:28:07 +080016
17#VLAN_TABLE_FLAGS
18VLAN_TABLE_FLAG_ONLY_UNTAG=1
19VLAN_TABLE_FLAG_ONLY_TAG =2
20VLAN_TABLE_FLAG_ONLY_BOTH =3
Piere1308762016-09-12 15:29:56 -070021VLAN_TABLE_FLAG_ONLY_STACKED=5
22VLAN_TABLE_FLAG_PRIORITY=6
23VLAN_TABLE_FLAG_ONLY_UNTAG_PRIORITY=7
macauley97557232015-07-16 17:28:07 +080024
macauleye8b140e2015-08-03 13:35:45 +080025PORT_FLOW_TABLE=0
26VLAN_FLOW_TABLE=10
Piere1308762016-09-12 15:29:56 -070027VLAN_1_FLOW_TABLE=11
Piercf76e802016-09-19 20:16:35 -070028MPLS_L2_PORT_FLOW_TABLE=13
29MPLS_L2_PORT_DSCP_TRUST_FLOW_TABLE=15
30MPLS_L2_PORT_PCP_TRUST_FLOW_TABLE=16
macauleye8b140e2015-08-03 13:35:45 +080031TERMINATION_FLOW_TABLE=20
Piercf76e802016-09-19 20:16:35 -070032MPLS_TYPE_FLOW_TABLE=29
macauleye8b140e2015-08-03 13:35:45 +080033UCAST_ROUTING_FLOW_TABLE=30
34MCAST_ROUTING_FLOW_TABLE=40
35BRIDGE_FLOW_TABLE=50
36ACL_FLOW_TABLE=60
37
38def convertIP4toStr(ip_addr):
39 a=(ip_addr&0xff000000)>>24
40 b=(ip_addr&0x00ff0000)>>16
41 c=(ip_addr&0x0000ff00)>>8
42 d=(ip_addr&0x000000ff)
43 return str(a)+"."+str(b)+"."+str(c)+"."+str(d)
44
45def convertMACtoStr(mac):
46 if not isinstance(mac, list):
47 assert(0)
48
49 return ':'.join(['%02X' % x for x in mac])
50
macauley7f89d962015-08-06 18:13:48 +080051def getSwitchCpuMACFromDPID(dpid):
52 str_datapath_id_f= "{:016x}".format(dpid)
53 str_datapath_id=':'.join([str_datapath_id_f[i:i+2] for i in range(0, len(str_datapath_id_f), 2)])
54 switch_cpu_mac_str=str_datapath_id[6:]
55 switch_cpu_mac = switch_cpu_mac_str.split(":")
56 switch_cpu_mac=[int(switch_cpu_mac[i],16) for i in range(0, len(switch_cpu_mac))]
57
58 return switch_cpu_mac_str, switch_cpu_mac
Pierbbdf3782016-08-22 17:58:26 -070059
macauley_cheng67da9262015-08-31 15:18:41 +080060def DumpGroup(stats, verify_group_stats, always_show=True):
61 if(len(stats) > len(verify_group_stats)):
62 min_len = len(verify_group_stats)
63 print "Stats Len is not the same, stats>verify_group_stats"
64 if(len(stats)< len(verify_group_stats)):
Pierbbdf3782016-08-22 17:58:26 -070065 min_len = len(stats)
macauley_cheng67da9262015-08-31 15:18:41 +080066 print "Stats Len is not the same, stats<verify_group_stats"
Pierbbdf3782016-08-22 17:58:26 -070067 else:
macauley_cheng67da9262015-08-31 15:18:41 +080068 min_len = len(stats)
macauleye8b140e2015-08-03 13:35:45 +080069
macauley_cheng67da9262015-08-31 15:18:41 +080070 print "\r\n"
71 for i in range(min_len):
72 gs = stats[i]
Pierbbdf3782016-08-22 17:58:26 -070073 gv = verify_group_stats[i]
macauley_cheng67da9262015-08-31 15:18:41 +080074 print "FromSwtich:(GID=%lx, TYPE=%lx)\r\nVerify :(GID=%lx, TYPE=%lx)"%(gs.group_id, gs.group_type, gv.group_id, gv.group_type)
75 if(len(gs.buckets) != len(gv.buckets)):
76 print "buckets len is not the same gs %lx, gv %lx",(len(gs.buckets), len(gv.buckets))
77
78 for j in range(len(gs.buckets)):
79 b1=gs.buckets[j]
Pierbbdf3782016-08-22 17:58:26 -070080 b2=gv.buckets[j]
macauley_cheng67da9262015-08-31 15:18:41 +080081 if(len(b1.actions) != len(b2.actions)):
82 print "action len is not the same"
83
84 for k in range(len(b1.actions)):
85 a1=b1.actions[k]
86 a2=b2.actions[k]
87 if(always_show == True):
88 print "a1:"+a1.show()
Pierbbdf3782016-08-22 17:58:26 -070089 print "a2:"+a2.show()
macauley_cheng67da9262015-08-31 15:18:41 +080090
91def AssertGroup(self, stats, verify_group_stats):
92 self.assertTrue(len(stats) ==len(verify_group_stats), "stats len is not the same")
93
94 for i in range(len(stats)):
95 gs = stats[i]
Pierbbdf3782016-08-22 17:58:26 -070096 gv = verify_group_stats[i]
macauley_cheng67da9262015-08-31 15:18:41 +080097 self.assertTrue(len(gs.buckets) == len(gv.buckets), "buckets len is not the same")
98
99 for j in range(len(gs.buckets)):
100 b1=gs.buckets[j]
Pierbbdf3782016-08-22 17:58:26 -0700101 b2=gv.buckets[j]
macauley_cheng67da9262015-08-31 15:18:41 +0800102 self.assertTrue(len(b1.actions) == len(b2.actions), "action len is not the same")
103
104 for k in range(len(b1.actions)):
105 a1=b1.actions[k]
106 a2=b2.actions[k]
107 self.assertEquals(a1, a2, "action is not the same")
Pierbbdf3782016-08-22 17:58:26 -0700108
macauley97557232015-07-16 17:28:07 +0800109def encode_l2_interface_group_id(vlan, id):
110 return id + (vlan << OFDPA_VLAN_ID_SHIFT)
111
112def encode_l2_rewrite_group_id(id):
113 return id + (1 << OFDPA_GROUP_TYPE_SHIFT)
114
115def encode_l3_unicast_group_id(id):
116 return id + (2 << OFDPA_GROUP_TYPE_SHIFT)
117
118def encode_l2_mcast_group_id(vlan, id):
119 return id + (vlan << OFDPA_VLAN_ID_SHIFT) + (3 << OFDPA_GROUP_TYPE_SHIFT)
120
121def encode_l2_flood_group_id(vlan, id):
122 return id + (vlan << OFDPA_VLAN_ID_SHIFT) + (4 << OFDPA_GROUP_TYPE_SHIFT)
Pierbbdf3782016-08-22 17:58:26 -0700123
macauley97557232015-07-16 17:28:07 +0800124def encode_l3_interface_group_id(id):
125 return id + (5 << OFDPA_GROUP_TYPE_SHIFT)
126
127def encode_l3_mcast_group_id(vlan, id):
128 return id + (vlan << OFDPA_VLAN_ID_SHIFT)+(6 << OFDPA_GROUP_TYPE_SHIFT)
129
130def encode_l3_ecmp_group_id(id):
131 return id + (7 << OFDPA_GROUP_TYPE_SHIFT)
132
Flavio Castro91d1a552016-05-17 16:59:44 -0700133def encode_l2_unfiltered_group_id(id):
134 return id + (11 << OFDPA_GROUP_TYPE_SHIFT)
135
macauleyfddc4662015-07-27 17:40:30 +0800136def encode_l2_overlay_group_id(tunnel_id, subtype, index):
137 tunnel_id=tunnel_id&0xffff #16 bits
138 subtype = subtype&3 #2 bits
139 index = index & 0x3f #10 bits
140 return index + (tunnel_id << OFDPA_TUNNEL_ID_SHIFT)+ (subtype<<OFDPA_TUNNEL_SUBTYPE_SHIFT)+(8 << OFDPA_GROUP_TYPE_SHIFT)
macauley97557232015-07-16 17:28:07 +0800141
Flavio Castro91d1a552016-05-17 16:59:44 -0700142def add_l2_unfiltered_group(ctrl, ports, send_barrier=False):
143 # group table
144 # set up untag groups for each port
145 group_id_list=[]
146 msgs=[]
147 for of_port in ports:
148 # do stuff
149 group_id = encode_l2_unfiltered_group_id(of_port)
150 group_id_list.append(group_id)
151 actions = [ofp.action.output(of_port)]
152 actions.append(ofp.action.set_field(ofp.oxm.exp1ByteValue(exp_type=24, value=1)))
153
154 buckets = [ofp.bucket(actions=actions)]
155 request = ofp.message.group_add(group_type=ofp.OFPGT_INDIRECT,
156 group_id=group_id,
157 buckets=buckets
158 )
159 ctrl.message_send(request)
160 msgs.append(request)
161
162 if send_barrier:
163 do_barrier(ctrl)
164
165 return group_id_list, msgs
166
Flavio Castrod4c44d12015-12-08 14:44:18 -0500167def add_l2_interface_group(ctrl, ports, vlan_id=1, is_tagged=False, send_barrier=False):
macauley97557232015-07-16 17:28:07 +0800168 # group table
169 # set up untag groups for each port
macauley41904ed2015-07-16 17:38:35 +0800170 group_id_list=[]
macauley15909e72015-07-17 15:58:57 +0800171 msgs=[]
macauley97557232015-07-16 17:28:07 +0800172 for of_port in ports:
173 # do stuff
174 group_id = encode_l2_interface_group_id(vlan_id, of_port)
macauley41904ed2015-07-16 17:38:35 +0800175 group_id_list.append(group_id)
macauley97557232015-07-16 17:28:07 +0800176 if is_tagged:
177 actions = [
178 ofp.action.output(of_port),
Pierbbdf3782016-08-22 17:58:26 -0700179 ]
macauley97557232015-07-16 17:28:07 +0800180 else:
181 actions = [
182 ofp.action.pop_vlan(),
183 ofp.action.output(of_port),
184 ]
185
186 buckets = [
187 ofp.bucket(actions=actions),
188 ]
189
190 request = ofp.message.group_add(group_type=ofp.OFPGT_INDIRECT,
191 group_id=group_id,
192 buckets=buckets
193 )
194 ctrl.message_send(request)
macauley15909e72015-07-17 15:58:57 +0800195 msgs.append(request)
macauley97557232015-07-16 17:28:07 +0800196
197 if send_barrier:
198 do_barrier(ctrl)
Pierbbdf3782016-08-22 17:58:26 -0700199
macauley15909e72015-07-17 15:58:57 +0800200 return group_id_list, msgs
macauley97557232015-07-16 17:28:07 +0800201
Flavio Castrod4c44d12015-12-08 14:44:18 -0500202def add_one_l2_interface_group(ctrl, port, vlan_id=1, is_tagged=False, send_barrier=False):
macauley0f91a3e2015-07-17 18:09:59 +0800203 # group table
204 # set up untag groups for each port
205 group_id = encode_l2_interface_group_id(vlan_id, port)
206
207 if is_tagged:
208 actions = [
209 ofp.action.output(port),
Pierbbdf3782016-08-22 17:58:26 -0700210 ]
macauley0f91a3e2015-07-17 18:09:59 +0800211 else:
212 actions = [
213 ofp.action.pop_vlan(),
214 ofp.action.output(port),
215 ]
216
217 buckets = [
218 ofp.bucket(actions=actions),
219 ]
220
221 request = ofp.message.group_add(group_type=ofp.OFPGT_INDIRECT,
222 group_id=group_id,
223 buckets=buckets
224 )
225 ctrl.message_send(request)
226
227 if send_barrier:
228 do_barrier(ctrl)
Pierbbdf3782016-08-22 17:58:26 -0700229
macauley0f91a3e2015-07-17 18:09:59 +0800230 return group_id, request
Pierbbdf3782016-08-22 17:58:26 -0700231
macauley97557232015-07-16 17:28:07 +0800232def add_l2_mcast_group(ctrl, ports, vlanid, mcast_grp_index):
233 buckets=[]
234 for of_port in ports:
235 group_id = encode_l2_interface_group_id(vlanid, of_port)
236 action=[ofp.action.group(group_id)]
237 buckets.append(ofp.bucket(actions=action))
238
239 group_id =encode_l2_mcast_group_id(vlanid, mcast_grp_index)
240 request = ofp.message.group_add(group_type=ofp.OFPGT_ALL,
241 group_id=group_id,
242 buckets=buckets
243 )
244 ctrl.message_send(request)
macauley15909e72015-07-17 15:58:57 +0800245 return request
macauley97557232015-07-16 17:28:07 +0800246
macauley15909e72015-07-17 15:58:57 +0800247def add_l2_flood_group(ctrl, ports, vlanid, id):
248 buckets=[]
249 for of_port in ports:
250 group_id = encode_l2_interface_group_id(vlanid, of_port)
251 action=[ofp.action.group(group_id)]
252 buckets.append(ofp.bucket(actions=action))
macauley97557232015-07-16 17:28:07 +0800253
macauley15909e72015-07-17 15:58:57 +0800254 group_id =encode_l2_flood_group_id(vlanid, id)
255 request = ofp.message.group_add(group_type=ofp.OFPGT_ALL,
256 group_id=group_id,
257 buckets=buckets
258 )
259 ctrl.message_send(request)
260 return request
261
Flavio Castroa7162bb2016-07-25 17:30:30 -0700262def mod_l2_flood_group(ctrl, ports, vlanid, id):
263 buckets=[]
264 for of_port in ports:
265 group_id = encode_l2_interface_group_id(vlanid, of_port)
266 action=[ofp.action.group(group_id)]
267 buckets.append(ofp.bucket(actions=action))
268
269 group_id =encode_l2_flood_group_id(vlanid, id)
270 request = ofp.message.group_modify(group_type=ofp.OFPGT_ALL,
271 group_id=group_id,
272 buckets=buckets
273 )
274 ctrl.message_send(request)
275 return request
276
277
macauley15909e72015-07-17 15:58:57 +0800278def add_l2_rewrite_group(ctrl, port, vlanid, id, src_mac, dst_mac):
279 group_id = encode_l2_interface_group_id(vlanid, port)
280
281 action=[]
282 if src_mac is not None:
283 action.append(ofp.action.set_field(ofp.oxm.eth_src(src_mac)))
284
285 if dst_mac is not None:
286 action.append(ofp.action.set_field(ofp.oxm.eth_dst(dst_mac)))
287
Flavio Castro91d1a552016-05-17 16:59:44 -0700288 action.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+vlanid)))
Pierbbdf3782016-08-22 17:58:26 -0700289
macauley15909e72015-07-17 15:58:57 +0800290 action.append(ofp.action.group(group_id))
Pierbbdf3782016-08-22 17:58:26 -0700291
macauley15909e72015-07-17 15:58:57 +0800292 buckets = [ofp.bucket(actions=action)]
293
294 group_id =encode_l2_rewrite_group_id(id)
295 request = ofp.message.group_add(group_type=ofp.OFPGT_INDIRECT,
296 group_id=group_id,
297 buckets=buckets
298 )
299 ctrl.message_send(request)
300 return request
Pierbbdf3782016-08-22 17:58:26 -0700301
macauley15909e72015-07-17 15:58:57 +0800302def add_l3_unicast_group(ctrl, port, vlanid, id, src_mac, dst_mac):
303 group_id = encode_l2_interface_group_id(vlanid, port)
304
305 action=[]
306 if src_mac is not None:
307 action.append(ofp.action.set_field(ofp.oxm.eth_src(src_mac)))
308
309 if dst_mac is not None:
310 action.append(ofp.action.set_field(ofp.oxm.eth_dst(dst_mac)))
311
Flavio Castroaf2b4502016-02-02 17:41:32 -0500312 action.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+vlanid)))
Pierbbdf3782016-08-22 17:58:26 -0700313
macauley15909e72015-07-17 15:58:57 +0800314 action.append(ofp.action.group(group_id))
Pierbbdf3782016-08-22 17:58:26 -0700315
macauley15909e72015-07-17 15:58:57 +0800316 buckets = [ofp.bucket(actions=action)]
317
318 group_id =encode_l3_unicast_group_id(id)
319 request = ofp.message.group_add(group_type=ofp.OFPGT_INDIRECT,
320 group_id=group_id,
321 buckets=buckets
322 )
323 ctrl.message_send(request)
324 return request
Pierbbdf3782016-08-22 17:58:26 -0700325
macauley15909e72015-07-17 15:58:57 +0800326def add_l3_interface_group(ctrl, port, vlanid, id, src_mac):
327 group_id = encode_l2_interface_group_id(vlanid, port)
328
329 action=[]
330 action.append(ofp.action.set_field(ofp.oxm.eth_src(src_mac)))
Pierbbdf3782016-08-22 17:58:26 -0700331 action.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+vlanid)))
macauley15909e72015-07-17 15:58:57 +0800332 action.append(ofp.action.group(group_id))
Pierbbdf3782016-08-22 17:58:26 -0700333
macauley15909e72015-07-17 15:58:57 +0800334 buckets = [ofp.bucket(actions=action)]
335
336 group_id =encode_l3_interface_group_id(id)
337 request = ofp.message.group_add(group_type=ofp.OFPGT_INDIRECT,
338 group_id=group_id,
339 buckets=buckets
340 )
341 ctrl.message_send(request)
342 return request
343
344def add_l3_ecmp_group(ctrl, id, l3_ucast_groups):
345 buckets=[]
346 for group in l3_ucast_groups:
347 buckets.append(ofp.bucket(actions=[ofp.action.group(group)]))
348
349 group_id =encode_l3_ecmp_group_id(id)
350 request = ofp.message.group_add(group_type=ofp.OFPGT_SELECT,
351 group_id=group_id,
352 buckets=buckets
353 )
354 ctrl.message_send(request)
355 return request
Flavio Castroa7162bb2016-07-25 17:30:30 -0700356
357def mod_l3_ecmp_group(ctrl, id, l3_ucast_groups):
358 buckets=[]
359 for group in l3_ucast_groups:
360 buckets.append(ofp.bucket(actions=[ofp.action.group(group)]))
361
362 group_id =encode_l3_ecmp_group_id(id)
363 request = ofp.message.group_modify(group_type=ofp.OFPGT_SELECT,
364 group_id=group_id,
365 buckets=buckets
366 )
367 ctrl.message_send(request)
368 return request
369
macauley15909e72015-07-17 15:58:57 +0800370def add_l3_mcast_group(ctrl, vid, mcast_group_id, groups_on_buckets):
371 buckets=[]
372 for group in groups_on_buckets:
373 buckets.append(ofp.bucket(actions=[ofp.action.group(group)]))
Pierbbdf3782016-08-22 17:58:26 -0700374
macauley15909e72015-07-17 15:58:57 +0800375 group_id =encode_l3_mcast_group_id(vid, mcast_group_id)
376 request = ofp.message.group_add(group_type=ofp.OFPGT_ALL,
377 group_id=group_id,
378 buckets=buckets
379 )
380 ctrl.message_send(request)
381 return request
macauleyfddc4662015-07-27 17:40:30 +0800382
383def add_l2_overlay_flood_over_unicast_tunnel_group(ctrl, tunnel_id, ports, index):
384 buckets=[]
385 for port in ports:
386 buckets.append(ofp.bucket(actions=[ofp.action.output(port)]))
387
388 group_id=encode_l2_overlay_group_id(tunnel_id, 0, index)
389 request = ofp.message.group_add(group_type=ofp.OFPGT_ALL,
390 group_id=group_id,
391 buckets=buckets
392 )
393 ctrl.message_send(request)
394 return request
395
396def add_l2_overlay_flood_over_mcast_tunnel_group(ctrl, tunnel_id, ports, index):
397 buckets=[]
398 for port in ports:
399 buckets.append(ofp.bucket(actions=[ofp.action.output(port)]))
400
401 group_id=encode_l2_overlay_group_id(tunnel_id, 1, index)
402 request = ofp.message.group_add(group_type=ofp.OFPGT_ALL,
403 group_id=group_id,
404 buckets=buckets
405 )
406 ctrl.message_send(request)
407 return request
408
409def add_l2_overlay_mcast_over_unicast_tunnel_group(ctrl, tunnel_id, ports, index):
410 buckets=[]
411 for port in ports:
412 buckets.append(ofp.bucket(actions=[ofp.action.output(port)]))
413
414 group_id=encode_l2_overlay_group_id(tunnel_id, 2, index)
415 request = ofp.message.group_add(group_type=ofp.OFPGT_ALL,
416 group_id=group_id,
417 buckets=buckets
418 )
419 ctrl.message_send(request)
420 return request
421
422def add_l2_overlay_mcast_over_mcast_tunnel_group(ctrl, tunnel_id, ports, index):
423 buckets=[]
424 for port in ports:
425 buckets.append(ofp.bucket(actions=[ofp.action.output(port)]))
426
427 group_id=encode_l2_overlay_group_id(tunnel_id, 3, index)
428 request = ofp.message.group_add(group_type=ofp.OFPGT_ALL,
429 group_id=group_id,
430 buckets=buckets
431 )
432 ctrl.message_send(request)
433 return request
Pierbbdf3782016-08-22 17:58:26 -0700434
macauleyfddc4662015-07-27 17:40:30 +0800435def add_port_table_flow(ctrl, is_overlay=True):
436 match = ofp.match()
437
438 if is_overlay == True:
439 match.oxm_list.append(ofp.oxm.in_port(0x10000))
macauleydbff3272015-07-30 14:07:16 +0800440 NEXT_TABLE=50
macauleyfddc4662015-07-27 17:40:30 +0800441 else:
442 match.oxm_list.append(ofp.oxm.in_port(0))
Pierbbdf3782016-08-22 17:58:26 -0700443 NEXT_TABLE=10
macauleyfddc4662015-07-27 17:40:30 +0800444
445 request = ofp.message.flow_add(
446 table_id=0,
447 cookie=42,
448 match=match,
449 instructions=[
macauleydbff3272015-07-30 14:07:16 +0800450 ofp.instruction.goto_table(NEXT_TABLE)
macauleyfddc4662015-07-27 17:40:30 +0800451 ],
452 priority=0)
453 logging.info("Add port table, match port %lx" % 0x10000)
454 ctrl.message_send(request)
Pierbbdf3782016-08-22 17:58:26 -0700455
Flavio Castrod8f8af22015-12-02 18:19:26 -0500456def pop_vlan_flow(ctrl, ports, vlan_id=1):
457 # table 10: vlan
458 # goto to table 20
459 msgs=[]
460 for of_port in ports:
461 match = ofp.match()
462 match.oxm_list.append(ofp.oxm.in_port(of_port))
463 match.oxm_list.append(ofp.oxm.vlan_vid(0x1000+vlan_id))
464 request = ofp.message.flow_add(
465 table_id=10,
466 cookie=42,
467 match=match,
468 instructions=[
469 ofp.instruction.apply_actions(
470 actions=[
471 ofp.action.pop_vlan()
472 ]
473 ),
474 ofp.instruction.goto_table(20)
475 ],
476 priority=0)
477 logging.info("Add vlan %d tagged packets on port %d and go to table 20" %( vlan_id, of_port))
478 ctrl.message_send(request)
479
480
481 return msgs
macauleyfddc4662015-07-27 17:40:30 +0800482
macauley97557232015-07-16 17:28:07 +0800483def add_vlan_table_flow(ctrl, ports, vlan_id=1, flag=VLAN_TABLE_FLAG_ONLY_BOTH, send_barrier=False):
484 # table 10: vlan
485 # goto to table 20
macauley15909e72015-07-17 15:58:57 +0800486 msgs=[]
macauley97557232015-07-16 17:28:07 +0800487 for of_port in ports:
Flavio Castro932014b2016-01-05 18:29:15 -0500488 if (flag == VLAN_TABLE_FLAG_ONLY_TAG) or (flag == VLAN_TABLE_FLAG_ONLY_BOTH) or (flag == 4):
macauley97557232015-07-16 17:28:07 +0800489 match = ofp.match()
490 match.oxm_list.append(ofp.oxm.in_port(of_port))
491 match.oxm_list.append(ofp.oxm.vlan_vid(0x1000+vlan_id))
492 request = ofp.message.flow_add(
493 table_id=10,
494 cookie=42,
495 match=match,
496 instructions=[
Flavio Castrod8f8af22015-12-02 18:19:26 -0500497 ofp.instruction.apply_actions(
498 actions=[
499 ofp.action.pop_vlan()
500 ]
501 ),
macauley97557232015-07-16 17:28:07 +0800502 ofp.instruction.goto_table(20)
503 ],
504 priority=0)
505 logging.info("Add vlan %d tagged packets on port %d and go to table 20" %( vlan_id, of_port))
506 ctrl.message_send(request)
Pierbbdf3782016-08-22 17:58:26 -0700507
macauley97557232015-07-16 17:28:07 +0800508 if (flag == VLAN_TABLE_FLAG_ONLY_UNTAG) or (flag == VLAN_TABLE_FLAG_ONLY_BOTH):
509 match = ofp.match()
510 match.oxm_list.append(ofp.oxm.in_port(of_port))
Flavio Castro12296312015-12-15 17:48:26 -0500511 match.oxm_list.append(ofp.oxm.vlan_vid_masked(0, 0x1fff))
macauley97557232015-07-16 17:28:07 +0800512 request = ofp.message.flow_add(
513 table_id=10,
514 cookie=42,
515 match=match,
516 instructions=[
517 ofp.instruction.apply_actions(
518 actions=[
Flavio Castroaf2b4502016-02-02 17:41:32 -0500519 ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+vlan_id))
macauley97557232015-07-16 17:28:07 +0800520 ]
521 ),
522 ofp.instruction.goto_table(20)
523 ],
524 priority=0)
525 logging.info("Add vlan %d untagged packets on port %d and go to table 20" % (vlan_id, of_port))
526 ctrl.message_send(request)
macauley15909e72015-07-17 15:58:57 +0800527 msgs.append(request)
macauley97557232015-07-16 17:28:07 +0800528
Flavio Castro932014b2016-01-05 18:29:15 -0500529 if (flag == 4) :
530 match = ofp.match()
531 match.oxm_list.append(ofp.oxm.in_port(of_port))
532 match.oxm_list.append(ofp.oxm.vlan_vid_masked(0x1000, 0x1fff))
533 request = ofp.message.flow_add(
534 table_id=10,
535 cookie=42,
536 match=match,
537 instructions=[
538 ofp.instruction.apply_actions(
539 actions=[
Flavio Castroaf2b4502016-02-02 17:41:32 -0500540 ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+vlan_id))
Flavio Castro932014b2016-01-05 18:29:15 -0500541 ]
542 ),
543 ofp.instruction.goto_table(20)
544 ],
545 priority=0)
546 logging.info("Add vlan %d untagged packets on port %d and go to table 20" % (vlan_id, of_port))
547 ctrl.message_send(request)
548 msgs.append(request)
549
macauley97557232015-07-16 17:28:07 +0800550 if send_barrier:
551 do_barrier(ctrl)
552
macauley15909e72015-07-17 15:58:57 +0800553 return msgs
Pierbbdf3782016-08-22 17:58:26 -0700554
macauley_cheng6e6a6122015-11-16 14:19:18 +0800555def del_vlan_table_flow(ctrl, ports, vlan_id=1, flag=VLAN_TABLE_FLAG_ONLY_BOTH, send_barrier=False):
556 # table 10: vlan
557 # goto to table 20
558 msgs=[]
559 for of_port in ports:
560 if (flag == VLAN_TABLE_FLAG_ONLY_TAG) or (flag == VLAN_TABLE_FLAG_ONLY_BOTH):
561 match = ofp.match()
562 match.oxm_list.append(ofp.oxm.in_port(of_port))
563 match.oxm_list.append(ofp.oxm.vlan_vid(0x1000+vlan_id))
564 request = ofp.message.flow_delete(
565 table_id=10,
566 cookie=42,
567 match=match,
568 priority=0)
569 logging.info("Del vlan %d tagged packets on port %d and go to table 20" %( vlan_id, of_port))
570 ctrl.message_send(request)
macauley0f91a3e2015-07-17 18:09:59 +0800571
macauley_cheng6e6a6122015-11-16 14:19:18 +0800572 if (flag == VLAN_TABLE_FLAG_ONLY_UNTAG) or (flag == VLAN_TABLE_FLAG_ONLY_BOTH):
573 match = ofp.match()
574 match.oxm_list.append(ofp.oxm.in_port(of_port))
575 match.oxm_list.append(ofp.oxm.vlan_vid_masked(0, 0xfff))
576 request = ofp.message.flow_delete(
577 table_id=10,
578 cookie=42,
579 match=match,
580 priority=0)
581 logging.info("Del vlan %d untagged packets on port %d and go to table 20" % (vlan_id, of_port))
582 ctrl.message_send(request)
583 msgs.append(request)
584
585 if send_barrier:
586 do_barrier(ctrl)
587
588 return msgs
Pierbbdf3782016-08-22 17:58:26 -0700589
macauley_cheng6b311612015-09-04 11:32:27 +0800590def add_vlan_table_flow_pvid(ctrl, in_port, match_vid=None, pvid=1, send_barrier=False):
591 """it will tag pack as untagged packet wether it has tagg or not"""
592 match = ofp.match()
593 match.oxm_list.append(ofp.oxm.in_port(in_port))
594 actions=[]
595 if match_vid == None:
Pierbbdf3782016-08-22 17:58:26 -0700596 match.oxm_list.append(ofp.oxm.vlan_vid(0))
macauley_cheng6b311612015-09-04 11:32:27 +0800597 actions.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+pvid)))
598 goto_table=20
599 else:
600 match.oxm_list.append(ofp.oxm.vlan_vid_masked(0x1000+match_vid, 0x1fff))
601 actions.append(ofp.action.push_vlan(0x8100))
Pierbbdf3782016-08-22 17:58:26 -0700602 actions.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+pvid)))
macauley_cheng6b311612015-09-04 11:32:27 +0800603 goto_table=20
Pierbbdf3782016-08-22 17:58:26 -0700604
macauley_cheng6b311612015-09-04 11:32:27 +0800605 request = ofp.message.flow_add(
606 table_id=10,
607 cookie=42,
608 match=match,
609 instructions=[
610 ofp.instruction.apply_actions(actions=actions)
611 ,ofp.instruction.goto_table(goto_table)
612 ],
613 priority=0)
614 logging.info("Add PVID %d on port %d and go to table %ld" %( pvid, in_port, goto_table))
Pierbbdf3782016-08-22 17:58:26 -0700615 ctrl.message_send(request)
616
macauley_cheng6b311612015-09-04 11:32:27 +0800617 if send_barrier:
618 do_barrier(ctrl)
619
620def add_vlan_table_flow_allow_all_vlan(ctrl, in_port, send_barrier=False):
621 """it st flow allow all vlan tag on this port"""
622 match = ofp.match()
623 match.oxm_list.append(ofp.oxm.in_port(in_port))
624 match.oxm_list.append(ofp.oxm.vlan_vid_masked(0x1000, 0x1000))
625 request = ofp.message.flow_add(
626 table_id=10,
627 cookie=42,
628 match=match,
629 instructions=[
Pierbbdf3782016-08-22 17:58:26 -0700630 ofp.instruction.goto_table(20)
macauley_cheng6b311612015-09-04 11:32:27 +0800631 ],
632 priority=0)
633 logging.info("Add allow all vlan on port %d " %(in_port))
Pierbbdf3782016-08-22 17:58:26 -0700634 ctrl.message_send(request)
macauley_cheng6b311612015-09-04 11:32:27 +0800635
Pier7b031af2016-08-25 15:00:22 -0700636def add_one_vlan_table_flow_translation(ctrl, of_port, vlan_id=1, new_vlan_id=-1, vrf=0, flag=VLAN_TABLE_FLAG_ONLY_BOTH, send_barrier=False):
637 # Install a flow for VLAN translation
638 # in VLAN table.
639 # table 10: vlan
640 # goto to table 20
641 if (flag == VLAN_TABLE_FLAG_ONLY_TAG) or (flag == VLAN_TABLE_FLAG_ONLY_BOTH) or (flag == 4):
642 match = ofp.match()
643 match.oxm_list.append(ofp.oxm.in_port(of_port))
644 match.oxm_list.append(ofp.oxm.vlan_vid_masked(0x1000+vlan_id,0x1fff))
645
646 actions=[]
647 if vrf!=0:
648 actions.append(ofp.action.set_field(ofp.oxm.exp2ByteValue(exp_type=1, value=vrf)))
649 if new_vlan_id != -1:
650 actions.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+new_vlan_id)))
651
652 request = ofp.message.flow_add(
653 table_id=10,
654 cookie=42,
655 match=match,
656 instructions=[
657 ofp.instruction.apply_actions(
658 actions=actions
659 ),
660 ofp.instruction.goto_table(20)
661 ],
662 priority=0)
663 logging.info("Add vlan %d tagged packets on port %d and go to table 20" %( vlan_id, of_port))
664 ctrl.message_send(request)
665
Piere1308762016-09-12 15:29:56 -0700666def add_one_vlan_table_flow(ctrl, of_port, out_vlan_id=1, vlan_id=1, vrf=0, flag=VLAN_TABLE_FLAG_ONLY_BOTH, send_barrier=False):
macauley0f91a3e2015-07-17 18:09:59 +0800667 # table 10: vlan
668 # goto to table 20
Flavio Castro932014b2016-01-05 18:29:15 -0500669 if (flag == VLAN_TABLE_FLAG_ONLY_TAG) or (flag == VLAN_TABLE_FLAG_ONLY_BOTH) or (flag == 4):
macauley0f91a3e2015-07-17 18:09:59 +0800670 match = ofp.match()
671 match.oxm_list.append(ofp.oxm.in_port(of_port))
Flavio Castro12296312015-12-15 17:48:26 -0500672 match.oxm_list.append(ofp.oxm.vlan_vid_masked(0x1000+vlan_id,0x1fff))
macauley7f89d962015-08-06 18:13:48 +0800673
674 actions=[]
675 if vrf!=0:
676 actions.append(ofp.action.set_field(ofp.oxm.exp2ByteValue(exp_type=1, value=vrf)))
Pierbbdf3782016-08-22 17:58:26 -0700677
Flavio Castro6d498522015-12-15 14:05:04 -0500678 #actions.append(ofp.action.set_field(ofp.oxm.vlan_vid(value=vlan_id)))
macauley7f89d962015-08-06 18:13:48 +0800679
macauley0f91a3e2015-07-17 18:09:59 +0800680 request = ofp.message.flow_add(
681 table_id=10,
682 cookie=42,
683 match=match,
684 instructions=[
macauley53d90fe2015-08-04 17:34:22 +0800685 ofp.instruction.apply_actions(
macauley7f89d962015-08-06 18:13:48 +0800686 actions=actions
macauley53d90fe2015-08-04 17:34:22 +0800687 ),
688 ofp.instruction.goto_table(20)
macauley0f91a3e2015-07-17 18:09:59 +0800689 ],
690 priority=0)
691 logging.info("Add vlan %d tagged packets on port %d and go to table 20" %( vlan_id, of_port))
692 ctrl.message_send(request)
Pierbbdf3782016-08-22 17:58:26 -0700693
macauley0f91a3e2015-07-17 18:09:59 +0800694 if (flag == VLAN_TABLE_FLAG_ONLY_UNTAG) or (flag == VLAN_TABLE_FLAG_ONLY_BOTH):
695 match = ofp.match()
696 match.oxm_list.append(ofp.oxm.in_port(of_port))
Flavio Castro12296312015-12-15 17:48:26 -0500697 match.oxm_list.append(ofp.oxm.vlan_vid_masked(0, 0x1fff))
Pierbbdf3782016-08-22 17:58:26 -0700698
macauley7f89d962015-08-06 18:13:48 +0800699 actions=[]
700 if vrf!=0:
701 actions.append(ofp.action.set_field(ofp.oxm.exp2ByteValue(exp_type=1, value=vrf)))
Pierbbdf3782016-08-22 17:58:26 -0700702
Flavio Castro91d1a552016-05-17 16:59:44 -0700703 actions.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+vlan_id)))
Pierbbdf3782016-08-22 17:58:26 -0700704
macauley0f91a3e2015-07-17 18:09:59 +0800705 request = ofp.message.flow_add(
706 table_id=10,
707 cookie=42,
708 match=match,
709 instructions=[
710 ofp.instruction.apply_actions(
macauley7f89d962015-08-06 18:13:48 +0800711 actions=actions
macauley0f91a3e2015-07-17 18:09:59 +0800712 ),
713 ofp.instruction.goto_table(20)
714 ],
715 priority=0)
716 logging.info("Add vlan %d untagged packets on port %d and go to table 20" % (vlan_id, of_port))
717 ctrl.message_send(request)
Pierbbdf3782016-08-22 17:58:26 -0700718
Flavio Castro932014b2016-01-05 18:29:15 -0500719 if (flag == 4) :
720 match = ofp.match()
721 match.oxm_list.append(ofp.oxm.in_port(of_port))
722 match.oxm_list.append(ofp.oxm.vlan_vid_masked(0x1000,0x1fff))
723
724 actions=[]
725 if vrf!=0:
726 actions.append(ofp.action.set_field(ofp.oxm.exp2ByteValue(exp_type=1, value=vrf)))
727
Flavio Castro91d1a552016-05-17 16:59:44 -0700728 actions.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+vlan_id)))
Flavio Castro932014b2016-01-05 18:29:15 -0500729
730 request = ofp.message.flow_add(
731 table_id=10,
732 cookie=42,
733 match=match,
734 instructions=[
735 ofp.instruction.apply_actions(
736 actions=actions
737 ),
738 ofp.instruction.goto_table(20)
739 ],
740 priority=0)
741 logging.info("Add vlan %d tagged packets on port %d and go to table 20" %( vlan_id, of_port))
742 ctrl.message_send(request)
macauley0f91a3e2015-07-17 18:09:59 +0800743
Piere1308762016-09-12 15:29:56 -0700744 if (flag == VLAN_TABLE_FLAG_ONLY_STACKED):
745 # This flag is meant to managed stacked vlan packtes
746 # Matches on outer VLAN_ID, set OVID with outer VLAN.
747 # Finally expose inner VLAN_ID with a pop action and
748 # goto VLAN_1_FLOW_TABLE
749 match = ofp.match()
750 match.oxm_list.append(ofp.oxm.in_port(of_port))
751 match.oxm_list.append(ofp.oxm.vlan_vid_masked(0x1000+vlan_id,0x1fff))
752
753 actions=[]
754 actions.append(ofp.action.set_field(ofp.oxm.exp2ByteValue(exp_type=ofp.oxm.OFDPA_EXP_TYPE_OVID, value=0x1000+vlan_id)))
755 actions.append(ofp.action.pop_vlan())
756
757 request = ofp.message.flow_add(
758 table_id=10,
759 cookie=42,
760 match=match,
761 instructions=[
762 ofp.instruction.apply_actions(
763 actions=actions
764 ),
765 ofp.instruction.goto_table(VLAN_1_FLOW_TABLE)
766 ],
767 priority=0)
768 logging.info("Add vlan %d tagged packets on port %d and go to table %d" %( vlan_id, of_port, VLAN_1_FLOW_TABLE))
769 ctrl.message_send(request)
770
771 if (flag == VLAN_TABLE_FLAG_PRIORITY) :
772 match = ofp.match()
773 match.oxm_list.append(ofp.oxm.in_port(of_port))
774 match.oxm_list.append(ofp.oxm.vlan_vid_masked(0x1000, 0x1fff))
775 request = ofp.message.flow_add(
776 table_id=10,
777 cookie=42,
778 match=match,
779 instructions=[
780 ofp.instruction.apply_actions(
781 actions=[
782 ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+vlan_id)),
783 ofp.action.push_vlan(0x8100),
784 ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+out_vlan_id)),
785 ]
786 ),
787 ofp.instruction.goto_table(20)
788 ],
789 priority=0)
790 logging.info("Add vlan %d untagged packets on port %d and go to table 20" % (vlan_id, of_port))
791 ctrl.message_send(request)
792
793 if send_barrier:
794 do_barrier(ctrl)
795
796 return request
797
Piercf76e802016-09-19 20:16:35 -0700798def add_one_vlan_table_flow_pw(ctrl, of_port, tunnel_index, new_vlan_id=1, vlan_id=1, vrf=0, flag=VLAN_TABLE_FLAG_ONLY_TAG, send_barrier=False):
799 # table 10: vlan
800 # goto to table 13
801 if flag == VLAN_TABLE_FLAG_ONLY_TAG:
802 match = ofp.match()
803 match.oxm_list.append(ofp.oxm.in_port(of_port))
804 match.oxm_list.append(ofp.oxm.vlan_vid_masked(0x1000+vlan_id, 0x1fff))
805
806 actions=[]
807 if vlan_id == -1:
808 actions.append(ofp.action.pop_vlan())
809 if new_vlan_id > 1:
810 actions.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+new_vlan_id)))
811 actions.append(ofp.action.set_field(ofp.oxm.exp2ByteValue(exp_type=ofp.oxm.OFDPA_EXP_TYPE_MPLS_TYPE, value=ofp.oxm.VPWS)))
812 actions.append(ofp.action.set_field(ofp.oxm.tunnel_id(tunnel_index + ofp.oxm.TUNNEL_ID_BASE)))
813 # 0x0000nnnn is for UNI interfaces
814 actions.append(ofp.action.set_field(ofp.oxm.exp4ByteValue(exp_type=ofp.oxm.OFDPA_EXP_TYPE_MPLS_L2_PORT, value=0x00000000 + of_port)))
815
816 request = ofp.message.flow_add(
817 table_id=10,
818 cookie=42,
819 match=match,
820 instructions=[
821 ofp.instruction.apply_actions(
822 actions=actions
823 ),
824 ofp.instruction.goto_table(MPLS_L2_PORT_FLOW_TABLE)
825 ],
826 priority=0)
827 logging.info("Add vlan %d tagged packets on port %d and go to table %d" % (vlan_id, of_port, MPLS_L2_PORT_FLOW_TABLE))
828 ctrl.message_send(request)
829
830 if flag == VLAN_TABLE_FLAG_ONLY_UNTAG:
831 match = ofp.match()
832 match.oxm_list.append(ofp.oxm.in_port(of_port))
833 match.oxm_list.append(ofp.oxm.vlan_vid(0))
834
835 actions=[]
836 if vlan_id > 1:
837 actions.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+vlan_id)))
838 actions.append(ofp.action.set_field(ofp.oxm.exp2ByteValue(exp_type=ofp.oxm.OFDPA_EXP_TYPE_MPLS_TYPE, value=ofp.oxm.VPWS)))
839 actions.append(ofp.action.set_field(ofp.oxm.tunnel_id(tunnel_index + ofp.oxm.TUNNEL_ID_BASE)))
840 # 0x0000nnnn is for UNI interfaces
841 actions.append(ofp.action.set_field(ofp.oxm.exp4ByteValue(exp_type=ofp.oxm.OFDPA_EXP_TYPE_MPLS_L2_PORT, value=0x00000000 + of_port)))
842
843 request = ofp.message.flow_add(
844 table_id=10,
845 cookie=42,
846 match=match,
847 instructions=[
848 ofp.instruction.apply_actions(
849 actions=actions
850 ),
851 ofp.instruction.goto_table(MPLS_L2_PORT_FLOW_TABLE)
852 ],
853 priority=0)
854 logging.info("Add vlan %d untagged packets on port %d and go to table %d" % (vlan_id, of_port, MPLS_L2_PORT_FLOW_TABLE))
855 ctrl.message_send(request)
856
857 if send_barrier:
858 do_barrier(ctrl)
859
860 return request
861
Piere1308762016-09-12 15:29:56 -0700862def add_one_vlan_1_table_flow(ctrl, of_port, new_outer_vlan_id=-1, outer_vlan_id=1, inner_vlan_id=1, flag=VLAN_TABLE_FLAG_ONLY_TAG, send_barrier=False):
863 # table 11: vlan 1 table
864 # goto to table 20
865 if flag == VLAN_TABLE_FLAG_ONLY_TAG:
866 match = ofp.match()
867 match.oxm_list.append(ofp.oxm.in_port(of_port))
868 match.oxm_list.append(ofp.oxm.vlan_vid_masked(0x1000+inner_vlan_id,0x1fff))
869 match.oxm_list.append(ofp.oxm.exp2ByteValue(ofp.oxm.OFDPA_EXP_TYPE_OVID, 0x1000+outer_vlan_id))
870
871 actions=[]
872 actions.append(ofp.action.push_vlan(0x8100))
873 if new_outer_vlan_id != -1:
874 actions.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+new_outer_vlan_id)))
875 else:
876 actions.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+outer_vlan_id)))
877
878 request = ofp.message.flow_add(
879 table_id=11,
880 cookie=42,
881 match=match,
882 instructions=[
883 ofp.instruction.apply_actions(
884 actions=actions
885 ),
886 ofp.instruction.goto_table(TERMINATION_FLOW_TABLE)
887 ],
888 priority=0)
889 logging.info("Add vlan 1 double tagged %d-%d packets on port %d and go to table %d" %( outer_vlan_id, inner_vlan_id, of_port, TERMINATION_FLOW_TABLE))
890 ctrl.message_send(request)
891
892 if flag == VLAN_TABLE_FLAG_ONLY_UNTAG:
893 match = ofp.match()
894 match.oxm_list.append(ofp.oxm.in_port(of_port))
895 match.oxm_list.append(ofp.oxm.vlan_vid_masked(0x1000+inner_vlan_id,0x1fff))
896 match.oxm_list.append(ofp.oxm.exp2ByteValue(ofp.oxm.OFDPA_EXP_TYPE_OVID, 0x1000+outer_vlan_id))
897
898 actions=[]
899 request = ofp.message.flow_add(
900 table_id=11,
901 cookie=42,
902 match=match,
903 instructions=[
904 ofp.instruction.apply_actions(
905 actions=actions
906 ),
907 ofp.instruction.goto_table(TERMINATION_FLOW_TABLE)
908 ],
909 priority=0)
910 logging.info("Add vlan 1 double tagged %d-%d packets on port %d and go to table %d" %( outer_vlan_id, inner_vlan_id, of_port, TERMINATION_FLOW_TABLE))
911 ctrl.message_send(request)
912
macauley0f91a3e2015-07-17 18:09:59 +0800913 if send_barrier:
914 do_barrier(ctrl)
915
916 return request
Pierbbdf3782016-08-22 17:58:26 -0700917
Piercf76e802016-09-19 20:16:35 -0700918def add_one_vlan_1_table_flow_pw(ctrl, of_port, tunnel_index, new_outer_vlan_id=-1, outer_vlan_id=1, inner_vlan_id=1, flag=VLAN_TABLE_FLAG_ONLY_TAG, send_barrier=False):
919 # table 11: vlan 1 table
920 # goto to table 13
921 match = ofp.match()
922 match.oxm_list.append(ofp.oxm.in_port(of_port))
923 match.oxm_list.append(ofp.oxm.vlan_vid_masked(0x1000+inner_vlan_id,0x1fff))
924 match.oxm_list.append(ofp.oxm.exp2ByteValue(ofp.oxm.OFDPA_EXP_TYPE_OVID, 0x1000+outer_vlan_id))
925
926 actions=[]
927 actions.append(ofp.action.push_vlan(0x8100))
928 if new_outer_vlan_id != -1:
929 actions.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+new_outer_vlan_id)))
930 else:
931 actions.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+outer_vlan_id)))
932
933 actions.append(ofp.action.set_field(ofp.oxm.exp2ByteValue(exp_type=ofp.oxm.OFDPA_EXP_TYPE_MPLS_TYPE, value=ofp.oxm.VPWS)))
934 actions.append(ofp.action.set_field(ofp.oxm.tunnel_id(tunnel_index + ofp.oxm.TUNNEL_ID_BASE)))
935 # 0x0000nnnn is for UNI interfaces
936 actions.append(ofp.action.set_field(ofp.oxm.exp4ByteValue(exp_type=ofp.oxm.OFDPA_EXP_TYPE_MPLS_L2_PORT, value=0x00000000 + of_port)))
937
938 request = ofp.message.flow_add(
939 table_id=11,
940 cookie=42,
941 match=match,
942 instructions=[
943 ofp.instruction.apply_actions(
944 actions=actions
945 ),
946 ofp.instruction.goto_table(MPLS_L2_PORT_FLOW_TABLE)
947 ],
948 priority=0)
949 logging.info("Add vlan 1 double tagged %d-%d packets on port %d and go to table %d" %( outer_vlan_id, inner_vlan_id, of_port, MPLS_L2_PORT_FLOW_TABLE))
950 ctrl.message_send(request)
951
952 if send_barrier:
953 do_barrier(ctrl)
954
955 return request
956
macauley97557232015-07-16 17:28:07 +0800957def add_bridge_flow(ctrl, dst_mac, vlanid, group_id, send_barrier=False):
958 match = ofp.match()
castroflavio21894482015-12-08 15:29:55 -0500959 priority=500
macauleyfddc4662015-07-27 17:40:30 +0800960 if dst_mac!=None:
castroflavio21894482015-12-08 15:29:55 -0500961 priority=1000
macauleyfddc4662015-07-27 17:40:30 +0800962 match.oxm_list.append(ofp.oxm.eth_dst(dst_mac))
963
macauley97557232015-07-16 17:28:07 +0800964 match.oxm_list.append(ofp.oxm.vlan_vid(0x1000+vlanid))
macauleyfddc4662015-07-27 17:40:30 +0800965
macauley97557232015-07-16 17:28:07 +0800966 request = ofp.message.flow_add(
967 table_id=50,
968 cookie=42,
969 match=match,
970 instructions=[
971 ofp.instruction.write_actions(
972 actions=[
973 ofp.action.group(group_id)]),
974 ofp.instruction.goto_table(60)
975 ],
976 buffer_id=ofp.OFP_NO_BUFFER,
castroflavio21894482015-12-08 15:29:55 -0500977 priority=priority)
macauley97557232015-07-16 17:28:07 +0800978
979 logging.info("Inserting Brdige flow vlan %d, mac %s", vlanid, dst_mac)
980 ctrl.message_send(request)
981
982 if send_barrier:
Pierbbdf3782016-08-22 17:58:26 -0700983 do_barrier(ctrl)
macauley15909e72015-07-17 15:58:57 +0800984
Pierbbdf3782016-08-22 17:58:26 -0700985 return request
macauleyfddc4662015-07-27 17:40:30 +0800986
987def add_overlay_bridge_flow(ctrl, dst_mac, vnid, group_id, is_group=True, send_barrier=False):
988 match = ofp.match()
989 if dst_mac!=None:
990 match.oxm_list.append(ofp.oxm.eth_dst(dst_mac))
991
992 match.oxm_list.append(ofp.oxm.tunnel_id(vnid))
993 if is_group == True:
994 actions=[ofp.action.group(group_id)]
995 else:
996 actions=[ofp.action.output(group_id)]
997
998 request = ofp.message.flow_add(
999 table_id=50,
1000 cookie=42,
1001 match=match,
1002 instructions=[
1003 ofp.instruction.write_actions(
1004 actions=actions),
1005 ofp.instruction.goto_table(60)
1006 ],
1007 buffer_id=ofp.OFP_NO_BUFFER,
Pierbbdf3782016-08-22 17:58:26 -07001008 priority=1000)
macauleyfddc4662015-07-27 17:40:30 +08001009
1010 logging.info("Inserting Brdige flow vnid %d, mac %s", vnid, dst_mac)
1011 ctrl.message_send(request)
1012
1013 if send_barrier:
Pierbbdf3782016-08-22 17:58:26 -07001014 do_barrier(ctrl)
macauleyfddc4662015-07-27 17:40:30 +08001015
Pierbbdf3782016-08-22 17:58:26 -07001016 return request
1017
macauley_cheng6b133662015-11-09 13:52:39 +08001018def add_termination_flow(ctrl, in_port, eth_type, dst_mac, vlanid, goto_table=None, send_barrier=False):
macauley0f91a3e2015-07-17 18:09:59 +08001019 match = ofp.match()
macauley0f91a3e2015-07-17 18:09:59 +08001020 match.oxm_list.append(ofp.oxm.eth_type(eth_type))
macauleyfddc4662015-07-27 17:40:30 +08001021 if dst_mac[0]&0x01 == 0x01:
1022 match.oxm_list.append(ofp.oxm.eth_dst_masked(dst_mac, [0xff, 0xff, 0xff, 0x80, 0x00, 0x00]))
1023 goto_table=40
1024 else:
macauley53d90fe2015-08-04 17:34:22 +08001025 if in_port!=0:
1026 match.oxm_list.append(ofp.oxm.in_port(in_port))
macauleyfddc4662015-07-27 17:40:30 +08001027 match.oxm_list.append(ofp.oxm.eth_dst(dst_mac))
1028 match.oxm_list.append(ofp.oxm.vlan_vid(0x1000+vlanid))
macauley_cheng6b133662015-11-09 13:52:39 +08001029 if goto_table == None:
1030 goto_table=30
macauley0f91a3e2015-07-17 18:09:59 +08001031
1032 request = ofp.message.flow_add(
1033 table_id=20,
1034 cookie=42,
1035 match=match,
1036 instructions=[
1037 ofp.instruction.goto_table(goto_table)
1038 ],
1039 buffer_id=ofp.OFP_NO_BUFFER,
Pierbbdf3782016-08-22 17:58:26 -07001040 priority=1)
macauley0f91a3e2015-07-17 18:09:59 +08001041
1042 logging.info("Inserting termination flow inport %d, eth_type %lx, vlan %d, mac %s", in_port, eth_type, vlanid, dst_mac)
1043 ctrl.message_send(request)
1044
1045 if send_barrier:
Pierbbdf3782016-08-22 17:58:26 -07001046 do_barrier(ctrl)
macauley0f91a3e2015-07-17 18:09:59 +08001047
Pierbbdf3782016-08-22 17:58:26 -07001048 return request
1049
Flavio Castroaf2b4502016-02-02 17:41:32 -05001050def add_unicast_routing_flow(ctrl, eth_type, dst_ip, mask, action_group_id, vrf=0, send_ctrl=False, send_barrier=False):
macauley0f91a3e2015-07-17 18:09:59 +08001051 match = ofp.match()
1052 match.oxm_list.append(ofp.oxm.eth_type(eth_type))
macauley53d90fe2015-08-04 17:34:22 +08001053 if vrf != 0:
1054 match.oxm_list.append(ofp.oxm.exp2ByteValue(ofp.oxm.OFDPA_EXP_TYPE_VRF, vrf))
macauley0f91a3e2015-07-17 18:09:59 +08001055
Flavio Castroaf2b4502016-02-02 17:41:32 -05001056 match.oxm_list.append(ofp.oxm.ipv4_dst_masked(dst_ip, mask))
1057
1058 instructions = []
1059 instructions.append(ofp.instruction.goto_table(60))
1060 if send_ctrl:
Piere0918ec2016-09-09 20:06:05 -07001061 instructions.append(ofp.instruction.apply_actions(
Flavio Castroaf2b4502016-02-02 17:41:32 -05001062 actions=[ofp.action.output( port=ofp.OFPP_CONTROLLER,
1063 max_len=ofp.OFPCML_NO_BUFFER)]))
Pierbbdf3782016-08-22 17:58:26 -07001064 else:
Flavio Castroaf2b4502016-02-02 17:41:32 -05001065 instructions.append(ofp.instruction.write_actions(
1066 actions=[ofp.action.group(action_group_id)]))
macauley53d90fe2015-08-04 17:34:22 +08001067
macauley0f91a3e2015-07-17 18:09:59 +08001068 request = ofp.message.flow_add(
1069 table_id=30,
1070 cookie=42,
1071 match=match,
Flavio Castroaf2b4502016-02-02 17:41:32 -05001072 instructions=instructions,
macauley0f91a3e2015-07-17 18:09:59 +08001073 buffer_id=ofp.OFP_NO_BUFFER,
Pierbbdf3782016-08-22 17:58:26 -07001074 priority=1)
macauley0f91a3e2015-07-17 18:09:59 +08001075
1076 logging.info("Inserting unicast routing flow eth_type %lx, dip %ld",eth_type, dst_ip)
1077 ctrl.message_send(request)
1078
1079 if send_barrier:
Pierbbdf3782016-08-22 17:58:26 -07001080 do_barrier(ctrl)
macauley0f91a3e2015-07-17 18:09:59 +08001081
Flavio Castro9debaaa2016-07-26 19:37:50 -07001082 return request
Flavio Castrod8f8af22015-12-02 18:19:26 -05001083
Flavio Castro8ca52542016-04-11 11:24:49 -04001084def add_mpls_flow(ctrl, action_group_id=0x0, label=100 ,ethertype=0x0800, bos=1, vrf=1, goto_table=27, send_barrier=False):
Flavio Castrob702a2f2016-04-10 22:01:48 -04001085 match = ofp.match()
1086 match.oxm_list.append(ofp.oxm.eth_type(0x8847))
1087 match.oxm_list.append(ofp.oxm.mpls_label(label))
1088 match.oxm_list.append(ofp.oxm.mpls_bos(bos))
1089 actions = [ofp.action.dec_mpls_ttl(),
Flavio Castro8ca52542016-04-11 11:24:49 -04001090 ofp.action.set_field(ofp.oxm.exp2ByteValue(exp_type=1, value=vrf))]
1091 if (goto_table == 29):
Flavio Castro8ca52542016-04-11 11:24:49 -04001092 actions.append(ofp.action.group(action_group_id))
1093 else:
Flavio Castrod80fbc32016-07-25 15:54:26 -07001094 actions.append(ofp.action.set_field(
1095 ofp.oxm.exp2ByteValue(exp_type=23, value=32)))
1096 actions.append(ofp.action.group(action_group_id))
Flavio Castro8ca52542016-04-11 11:24:49 -04001097 actions.append(ofp.action.copy_ttl_in())
Flavio Castro9debaaa2016-07-26 19:37:50 -07001098
Flavio Castrob702a2f2016-04-10 22:01:48 -04001099 request = ofp.message.flow_add(
1100 table_id=24,
1101 cookie=43,
1102 match=match,
1103 instructions=[
Flavio Castro8ca52542016-04-11 11:24:49 -04001104 ofp.instruction.apply_actions(actions=actions),
1105 ofp.instruction.goto_table(goto_table)
Flavio Castrob702a2f2016-04-10 22:01:48 -04001106 ],
1107 buffer_id=ofp.OFP_NO_BUFFER,
1108 priority=1)
Flavio Castrob702a2f2016-04-10 22:01:48 -04001109 logging.info("Inserting MPLS flow , label %ld", label)
1110 ctrl.message_send(request)
1111
1112 if send_barrier:
1113 do_barrier(ctrl)
1114
1115 return request
1116
macauleyfddc4662015-07-27 17:40:30 +08001117def add_mcast4_routing_flow(ctrl, vlan_id, src_ip, src_ip_mask, dst_ip, action_group_id, send_barrier=False):
1118 match = ofp.match()
1119 match.oxm_list.append(ofp.oxm.eth_type(0x0800))
Pierbbdf3782016-08-22 17:58:26 -07001120 match.oxm_list.append(ofp.oxm.vlan_vid(vlan_id))
macauleyfddc4662015-07-27 17:40:30 +08001121 if src_ip_mask!=0:
1122 match.oxm_list.append(ofp.oxm.ipv4_src_masked(src_ip, src_ip_mask))
1123 else:
1124 match.oxm_list.append(ofp.oxm.ipv4_src(src_ip))
Pierbbdf3782016-08-22 17:58:26 -07001125
macauleyfddc4662015-07-27 17:40:30 +08001126 match.oxm_list.append(ofp.oxm.ipv4_dst(dst_ip))
Pierbbdf3782016-08-22 17:58:26 -07001127
macauleyfddc4662015-07-27 17:40:30 +08001128 request = ofp.message.flow_add(
1129 table_id=40,
1130 cookie=42,
1131 match=match,
1132 instructions=[
1133 ofp.instruction.write_actions(
1134 actions=[ofp.action.group(action_group_id)]),
1135 ofp.instruction.goto_table(60)
1136 ],
1137 buffer_id=ofp.OFP_NO_BUFFER,
Pierbbdf3782016-08-22 17:58:26 -07001138 priority=1)
macauleyfddc4662015-07-27 17:40:30 +08001139
1140 logging.info("Inserting mcast routing flow eth_type %lx, dip %lx, sip %lx, sip_mask %lx",0x0800, dst_ip, src_ip, src_ip_mask)
1141 ctrl.message_send(request)
1142
1143 if send_barrier:
Pierbbdf3782016-08-22 17:58:26 -07001144 do_barrier(ctrl)
macauleyfddc4662015-07-27 17:40:30 +08001145
Pierbbdf3782016-08-22 17:58:26 -07001146 return request
macauley_cheng6b133662015-11-09 13:52:39 +08001147
1148#dpctl tcp:192.168.1.1:6633 flow-mod table=28,cmd=add,prio=281 eth_type=0x800,ip_dst=100.0.0.1,ip_proto=6,tcp_dst=5000 write:set_field=ip_dst:10.0.0.1,set_field=tcp_dst:2000,group=0x71000001 goto:60
macauley_chengeffc20a2015-11-09 16:14:56 +08001149def add_dnat_flow(ctrl, eth_type, ip_dst, ip_proto, tcp_dst, set_ip_dst, set_tcp_dst, action_group_id):
macauley_cheng6b133662015-11-09 13:52:39 +08001150 match = ofp.match()
1151 match.oxm_list.append(ofp.oxm.eth_type(eth_type))
1152 match.oxm_list.append(ofp.oxm.ipv4_dst(ip_dst))
1153 match.oxm_list.append(ofp.oxm.ip_proto(ip_proto))
1154 match.oxm_list.append(ofp.oxm.tcp_dst(tcp_dst))
Pierbbdf3782016-08-22 17:58:26 -07001155
macauley_cheng6b133662015-11-09 13:52:39 +08001156 request = ofp.message.flow_add(
1157 table_id=28,
1158 cookie=42,
1159 match=match,
1160 instructions=[
1161 ofp.instruction.write_actions(
1162 actions=[ofp.action.set_field(ofp.oxm.ipv4_dst(set_ip_dst)),
1163 ofp.action.set_field(ofp.oxm.tcp_dst(set_tcp_dst)),
1164 ofp.action.group(action_group_id)]),
1165 ofp.instruction.goto_table(60)
1166 ],
1167 buffer_id=ofp.OFP_NO_BUFFER,
Pierbbdf3782016-08-22 17:58:26 -07001168 priority=1)
macauley_cheng6b133662015-11-09 13:52:39 +08001169 logging.info("Inserting DNAT flow eth_type %lx, dip %lx, ip_proto %ld, tcp_dst %ld, SetFeild: Dip %lx, tcp_dst %ld, action_gorup=%lx",eth_type, ip_dst, ip_proto, tcp_dst, set_ip_dst, set_tcp_dst, action_group_id)
1170 ctrl.message_send(request)
1171 return request
macauley_chengeffc20a2015-11-09 16:14:56 +08001172
1173#dpctl tcp:192.168.1.1:6633 flow-mod table=29,cmd=add,prio=291 eth_type=0x800,ip_src=10.0.0.1,ip_proto=6,tcp_src=2000 write:set_field=ip_src:100.0.0.1,set_field=tcp_src:5000 goto:30
1174def add_snat_flow(ctrl, eth_type, ip_src, ip_proto, tcp_src, set_ip_src, set_tcp_src):
1175 match = ofp.match()
1176 match.oxm_list.append(ofp.oxm.eth_type(eth_type))
1177 match.oxm_list.append(ofp.oxm.ipv4_src(ip_src))
1178 match.oxm_list.append(ofp.oxm.ip_proto(ip_proto))
1179 match.oxm_list.append(ofp.oxm.tcp_src(tcp_src))
Pierbbdf3782016-08-22 17:58:26 -07001180
macauley_chengeffc20a2015-11-09 16:14:56 +08001181 request = ofp.message.flow_add(
1182 table_id=29,
1183 cookie=42,
1184 match=match,
1185 instructions=[
1186 ofp.instruction.write_actions(
1187 actions=[ofp.action.set_field(ofp.oxm.ipv4_src(set_ip_src)),
1188 ofp.action.set_field(ofp.oxm.tcp_src(set_tcp_src))]),
1189 ofp.instruction.goto_table(30)
1190 ],
1191 buffer_id=ofp.OFP_NO_BUFFER,
Pierbbdf3782016-08-22 17:58:26 -07001192 priority=1)
macauley_chengeffc20a2015-11-09 16:14:56 +08001193 logging.info("Inserting DNAT flow eth_type %lx, sip %lx, ip_proto %ld, tcp_src %ld, SetFeild: sip %lx, tcp_src %ld",eth_type, ip_src, ip_proto, tcp_src, set_ip_src, set_tcp_src)
1194 ctrl.message_send(request)
1195 return request
Pierbbdf3782016-08-22 17:58:26 -07001196
1197def get_vtap_lport_config_xml(dp_id, lport, phy_port, vlan, vnid, operation='merge'):
macauleyfddc4662015-07-27 17:40:30 +08001198 """
1199 Command Example:
1200 of-agent vtap 10001 ethernet 1/1 vid 1
1201 of-agent vtp 10001 vni 10
1202 """
1203 if vlan != 0:
1204 config_vtap_xml="""
1205 <config>
1206 <capable-switch xmlns="urn:onf:of111:config:yang" xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0">
1207 <id>capable-switch-1</id>
1208 <resources>
1209 <port xc:operation="OPERATION">
Pierbbdf3782016-08-22 17:58:26 -07001210 <resource-id >LPORT</resource-id>
macauleyfddc4662015-07-27 17:40:30 +08001211 <features>
1212 <current>
1213 <rate>10Gb</rate>
1214 <medium>fiber</medium>
Pierbbdf3782016-08-22 17:58:26 -07001215 <pause>symmetric</pause>
macauleyfddc4662015-07-27 17:40:30 +08001216 </current>
1217 <advertised>
1218 <rate>10Gb</rate>
1219 <rate>100Gb</rate>
1220 <medium>fiber</medium>
1221 <pause>symmetric</pause>
Pierbbdf3782016-08-22 17:58:26 -07001222 </advertised>
macauleyfddc4662015-07-27 17:40:30 +08001223 <supported>
1224 <rate>10Gb</rate>
1225 <rate>100Gb</rate>
1226 <medium>fiber</medium>
1227 <pause>symmetric</pause>
Pierbbdf3782016-08-22 17:58:26 -07001228 </supported>
macauleyfddc4662015-07-27 17:40:30 +08001229 <advertised-peer>
1230 <rate>10Gb</rate>
1231 <rate>100Gb</rate>
1232 <medium>fiber</medium>
1233 <pause>symmetric</pause>
Pierbbdf3782016-08-22 17:58:26 -07001234 </advertised-peer>
macauleyfddc4662015-07-27 17:40:30 +08001235 </features>
1236 <ofdpa10:vtap xmlns:ofdpa10="urn:bcm:ofdpa10:accton01" xc:operation="OPERATION">
1237 <ofdpa10:phy-port>PHY_PORT</ofdpa10:phy-port>
1238 <ofdpa10:vid>VLAN_ID</ofdpa10:vid>
1239 <ofdpa10:vni>VNID</ofdpa10:vni>
1240 </ofdpa10:vtap>
Pierbbdf3782016-08-22 17:58:26 -07001241 </port>
macauleyfddc4662015-07-27 17:40:30 +08001242 </resources>
1243 <logical-switches>
1244 <switch>
1245 <id>DATAPATH_ID</id>
1246 <datapath-id>DATAPATH_ID</datapath-id>
1247 <resources>
1248 <port xc:operation="OPERATION">LPORT</port>
1249 </resources>
1250 </switch>
1251 </logical-switches>
1252 </capable-switch>
1253 </config>
Pierbbdf3782016-08-22 17:58:26 -07001254 """
macauleyfddc4662015-07-27 17:40:30 +08001255 else:
1256 config_vtap_xml="""
1257 <config>
1258 <capable-switch xmlns="urn:onf:of111:config:yang" xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0">
1259 <id>capable-switch-1</id>
1260 <resources>
1261 <port xc:operation="OPERATION">
Pierbbdf3782016-08-22 17:58:26 -07001262 <resource-id >LPORT</resource-id>
macauleyfddc4662015-07-27 17:40:30 +08001263 <features>
1264 <current>
1265 <rate>10Gb</rate>
1266 <medium>fiber</medium>
Pierbbdf3782016-08-22 17:58:26 -07001267 <pause>symmetric</pause>
macauleyfddc4662015-07-27 17:40:30 +08001268 </current>
1269 <advertised>
1270 <rate>10Gb</rate>
1271 <rate>100Gb</rate>
1272 <medium>fiber</medium>
1273 <pause>symmetric</pause>
Pierbbdf3782016-08-22 17:58:26 -07001274 </advertised>
macauleyfddc4662015-07-27 17:40:30 +08001275 <supported>
1276 <rate>10Gb</rate>
1277 <rate>100Gb</rate>
1278 <medium>fiber</medium>
1279 <pause>symmetric</pause>
Pierbbdf3782016-08-22 17:58:26 -07001280 </supported>
macauleyfddc4662015-07-27 17:40:30 +08001281 <advertised-peer>
1282 <rate>10Gb</rate>
1283 <rate>100Gb</rate>
1284 <medium>fiber</medium>
1285 <pause>symmetric</pause>
Pierbbdf3782016-08-22 17:58:26 -07001286 </advertised-peer>
macauleyfddc4662015-07-27 17:40:30 +08001287 </features>
1288 <ofdpa10:vtap xmlns:ofdpa10="urn:bcm:ofdpa10:accton01" xc:operation="OPERATION">
1289 <ofdpa10:phy-port>PHY_PORT</ofdpa10:phy-port>
1290 <ofdpa10:vni>VNID</ofdpa10:vni>
1291 </ofdpa10:vtap>
Pierbbdf3782016-08-22 17:58:26 -07001292 </port>
macauleyfddc4662015-07-27 17:40:30 +08001293 </resources>
1294 <logical-switches>
1295 <switch>
1296 <id>DATAPATH_ID</id>
1297 <datapath-id>DATAPATH_ID</datapath-id>
1298 <resources>
1299 <port xc:operation="OPERATION">LPORT</port>
1300 </resources>
1301 </switch>
1302 </logical-switches>
1303 </capable-switch>
1304 </config>
Pierbbdf3782016-08-22 17:58:26 -07001305 """
1306 str_datapath_id_f= "{:016x}".format(dp_id)
1307 str_datapath_id=':'.join([str_datapath_id_f[i:i+2] for i in range(0, len(str_datapath_id_f), 2)])
1308 config_vtap_xml=config_vtap_xml.replace("DATAPATH_ID", str_datapath_id)
1309 config_vtap_xml=config_vtap_xml.replace("LPORT", str(int(lport)))
1310 config_vtap_xml=config_vtap_xml.replace("PHY_PORT", str(phy_port))
1311 config_vtap_xml=config_vtap_xml.replace("VLAN_ID", str(vlan))
macauleyfddc4662015-07-27 17:40:30 +08001312 config_vtap_xml=config_vtap_xml.replace("VNID", str(vnid))
1313 config_vtap_xml=config_vtap_xml.replace("OPERATION", str(operation))
1314 return config_vtap_xml
Pierbbdf3782016-08-22 17:58:26 -07001315
1316def get_vtep_lport_config_xml(dp_id, lport, src_ip, dst_ip, next_hop_id, vnid, udp_src_port=6633, ttl=25, operation='merge'):
macauleyfddc4662015-07-27 17:40:30 +08001317 """
1318 Command Example:
1319 of-agent vtep 10002 source user-input-src-ip destination user-input-dst-ip udp-source-port 6633 nexthop 2 ttl 25
Pierbbdf3782016-08-22 17:58:26 -07001320 of-agent vtp 10001 vni 10
macauleyfddc4662015-07-27 17:40:30 +08001321 """
1322
1323 config_vtep_xml="""
1324 <config>
1325 <capable-switch xmlns="urn:onf:of111:config:yang" xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0">
1326 <id>capable-switch-1</id>
1327 <resources>
1328 <port xc:operation="OPERATION">
Pierbbdf3782016-08-22 17:58:26 -07001329 <resource-id>LPORT</resource-id>
macauleyfddc4662015-07-27 17:40:30 +08001330 <features>
1331 <current>
1332 <rate>10Gb</rate>
1333 <medium>fiber</medium>
Pierbbdf3782016-08-22 17:58:26 -07001334 <pause>symmetric</pause>
macauleyfddc4662015-07-27 17:40:30 +08001335 </current>
1336 <advertised>
1337 <rate>10Gb</rate>
1338 <rate>100Gb</rate>
1339 <medium>fiber</medium>
1340 <pause>symmetric</pause>
Pierbbdf3782016-08-22 17:58:26 -07001341 </advertised>
macauleyfddc4662015-07-27 17:40:30 +08001342 <supported>
1343 <rate>10Gb</rate>
1344 <rate>100Gb</rate>
1345 <medium>fiber</medium>
1346 <pause>symmetric</pause>
Pierbbdf3782016-08-22 17:58:26 -07001347 </supported>
macauleyfddc4662015-07-27 17:40:30 +08001348 <advertised-peer>
1349 <rate>10Gb</rate>
1350 <rate>100Gb</rate>
1351 <medium>fiber</medium>
1352 <pause>symmetric</pause>
Pierbbdf3782016-08-22 17:58:26 -07001353 </advertised-peer>
macauleyfddc4662015-07-27 17:40:30 +08001354 </features>
1355 <ofdpa10:vtep xmlns:ofdpa10="urn:bcm:ofdpa10:accton01">
1356 <ofdpa10:src-ip>SRC_IP</ofdpa10:src-ip>
1357 <ofdpa10:dest-ip>DST_IP</ofdpa10:dest-ip>
1358 <ofdpa10:udp-src-port>UDP_SRC_PORT</ofdpa10:udp-src-port>
macauley25999cf2015-08-07 17:03:24 +08001359 <ofdpa10:vni xc:operation="OPERATION">
1360 <ofdpa10:id>VNID</ofdpa10:id>
1361 </ofdpa10:vni>
macauleyfddc4662015-07-27 17:40:30 +08001362 <ofdpa10:nexthop-id>NEXT_HOP_ID</ofdpa10:nexthop-id>
1363 <ofdpa10:ttl>TTL</ofdpa10:ttl>
1364 </ofdpa10:vtep>
Pierbbdf3782016-08-22 17:58:26 -07001365 </port>
macauleyfddc4662015-07-27 17:40:30 +08001366 </resources>
1367 <logical-switches>
1368 <switch>
1369 <id>DATAPATH_ID</id>
1370 <datapath-id>DATAPATH_ID</datapath-id>
1371 <resources>
1372 <port xc:operation="OPERATION">LPORT</port>
1373 </resources>
1374 </switch>
1375 </logical-switches>
1376 </capable-switch>
Pierbbdf3782016-08-22 17:58:26 -07001377 </config>
macauleyfddc4662015-07-27 17:40:30 +08001378 """
Pierbbdf3782016-08-22 17:58:26 -07001379 str_datapath_id_f= "{:016x}".format(dp_id)
1380 str_datapath_id=':'.join([str_datapath_id_f[i:i+2] for i in range(0, len(str_datapath_id_f), 2)])
1381 config_vtep_xml=config_vtep_xml.replace("DATAPATH_ID", str_datapath_id)
macauley25999cf2015-08-07 17:03:24 +08001382 config_vtep_xml=config_vtep_xml.replace("LPORT", str(int(lport)))
Pierbbdf3782016-08-22 17:58:26 -07001383 config_vtep_xml=config_vtep_xml.replace("SRC_IP", str(src_ip))
1384 config_vtep_xml=config_vtep_xml.replace("DST_IP", str(dst_ip))
1385 config_vtep_xml=config_vtep_xml.replace("UDP_SRC_PORT", str(udp_src_port))
1386 config_vtep_xml=config_vtep_xml.replace("NEXT_HOP_ID", str(next_hop_id))
1387 config_vtep_xml=config_vtep_xml.replace("TTL", str(ttl))
macauleyfddc4662015-07-27 17:40:30 +08001388 config_vtep_xml=config_vtep_xml.replace("VNID", str(vnid))
Pierbbdf3782016-08-22 17:58:26 -07001389 config_vtep_xml=config_vtep_xml.replace("OPERATION", str(operation))
macauleyfddc4662015-07-27 17:40:30 +08001390
Pierbbdf3782016-08-22 17:58:26 -07001391 return config_vtep_xml
1392
1393def get_next_hop_config_xml(next_hop_id, dst_mac, phy_port, vlan, operation='merge'):
macauleyfddc4662015-07-27 17:40:30 +08001394 #of-agent nexthop 2 destination user-input-dst-mac ethernet 1/2 vid 2
1395 config_nexthop_xml="""
1396 <config>
1397 <of11-config:capable-switch xmlns:of11-config="urn:onf:of111:config:yang" xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0">
1398 <ofdpa10:next-hop xmlns:ofdpa10="urn:bcm:ofdpa10:accton01" xc:operation="OPERATION">
1399 <ofdpa10:id>NEXT_HOP_ID</ofdpa10:id>
1400 <ofdpa10:dest-mac>DST_MAC</ofdpa10:dest-mac>
1401 <ofdpa10:phy-port>PHY_PORT</ofdpa10:phy-port>
1402 <ofdpa10:vid>VLAN_ID</ofdpa10:vid>
1403 </ofdpa10:next-hop>
1404 </of11-config:capable-switch>
1405 </config>
1406 """
1407 config_nexthop_xml=config_nexthop_xml.replace("VLAN_ID", str(vlan))
Pierbbdf3782016-08-22 17:58:26 -07001408 config_nexthop_xml=config_nexthop_xml.replace("PHY_PORT", str(phy_port))
1409 config_nexthop_xml=config_nexthop_xml.replace("NEXT_HOP_ID", str(next_hop_id))
1410 config_nexthop_xml=config_nexthop_xml.replace("DST_MAC", str(dst_mac))
1411 config_nexthop_xml=config_nexthop_xml.replace("OPERATION", str(operation))
1412 return config_nexthop_xml
macauleyfddc4662015-07-27 17:40:30 +08001413
Pierbbdf3782016-08-22 17:58:26 -07001414def get_vni_config_xml(vni_id, mcast_ipv4, next_hop_id, operation='merge'):
macauleyfddc4662015-07-27 17:40:30 +08001415 #of-agent vni 10 multicast 224.1.1.1 nexthop 20
Pierbbdf3782016-08-22 17:58:26 -07001416 if mcast_ipv4!=None:
macauleyfddc4662015-07-27 17:40:30 +08001417 config_vni_xml="""
1418 <config>
1419 <of11-config:capable-switch xmlns:of11-config="urn:onf:of111:config:yang" xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0">
1420 <ofdpa10:vni xmlns:ofdpa10="urn:bcm:ofdpa10:accton01" xc:operation="OPERATION">
1421 <ofdpa10:id>VNID</ofdpa10:id>
1422 <ofdpa10:vni-multicast-group>MCAST_IP</ofdpa10:vni-multicast-group>
1423 <ofdpa10:multicast-group-nexthop-id>NEXT_HOP_ID</ofdpa10:multicast-group-nexthop-id>
1424 </ofdpa10:vni>
1425 </of11-config:capable-switch>
1426 </config>
Pierbbdf3782016-08-22 17:58:26 -07001427 """
1428 config_vni_xml=config_vni_xml.replace("NEXT_HOP_ID", str(next_hop_id))
1429 config_vni_xml=config_vni_xml.replace("MCAST_IP", str(mcast_ipv4))
macauleyfddc4662015-07-27 17:40:30 +08001430 else:
1431 config_vni_xml="""
1432 <config>
1433 <of11-config:capable-switch xmlns:of11-config="urn:onf:of111:config:yang" xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0">
1434 <ofdpa10:vni xmlns:ofdpa10="urn:bcm:ofdpa10:accton01" xc:operation="OPERATION">
1435 <ofdpa10:id>VNID</ofdpa10:id>
1436 </ofdpa10:vni>
1437 </of11-config:capable-switch>
1438 </config>
Pierbbdf3782016-08-22 17:58:26 -07001439 """
1440
1441 config_vni_xml=config_vni_xml.replace("VNID", str(vni_id))
1442 config_vni_xml=config_vni_xml.replace("OPERATION", str(operation))
macauleyfddc4662015-07-27 17:40:30 +08001443 return config_vni_xml
Pierbbdf3782016-08-22 17:58:26 -07001444
1445def get_featureReplay(self):
macauleyfddc4662015-07-27 17:40:30 +08001446 req = ofp.message.features_request()
1447 res, raw = self.controller.transact(req)
Pierbbdf3782016-08-22 17:58:26 -07001448 self.assertIsNotNone(res, "Did not receive a response from the DUT.")
macauleyfddc4662015-07-27 17:40:30 +08001449 self.assertEqual(res.type, ofp.OFPT_FEATURES_REPLY,
1450 ("Unexpected packet type %d received in response to "
1451 "OFPT_FEATURES_REQUEST") % res.type)
Pierbbdf3782016-08-22 17:58:26 -07001452 return res
1453
macauleyfddc4662015-07-27 17:40:30 +08001454def send_edit_config(switch_ip, xml, target='runing'):
1455 NETCONF_ACCOUNT="netconfuser"
1456 NETCONF_PASSWD="netconfuser"
1457 with manager.connect_ssh(host=switch_ip, port=830, username=NETCONF_ACCOUNT, password=NETCONF_PASSWD, hostkey_verify=False ) as m:
1458 try:
Pierbbdf3782016-08-22 17:58:26 -07001459 m.edit_config(target='running',
1460 config=xml,
1461 default_operation='merge',
macauleyfddc4662015-07-27 17:40:30 +08001462 error_option='stop-on-error')
1463
1464 except Exception as e:
1465 logging.info("Fail to set xml %s", xml)
1466 return False
1467
1468 #return m.get_config(source='running').data_xml
1469 return True
1470
1471def send_delete_config(switch_ip, xml, target='runing'):
1472 NETCONF_ACCOUNT="netconfuser"
1473 NETCONF_PASSWD="netconfuser"
1474 with manager.connect_ssh(host=switch_ip, port=830, username=NETCONF_ACCOUNT, password=NETCONF_PASSWD, hostkey_verify=False ) as m:
1475 try:
Pierbbdf3782016-08-22 17:58:26 -07001476 m.edit_config(target='running',
1477 config=xml,
1478 default_operation='delete',
macauleyfddc4662015-07-27 17:40:30 +08001479 error_option='stop-on-error')
1480
1481 except Exception as e:
1482 logging.info("Fail to set xml %s", xml)
1483 return False
1484
1485 #return m.get_config(source='running').data_xml
1486 return True
Pierbbdf3782016-08-22 17:58:26 -07001487
macauleyfddc4662015-07-27 17:40:30 +08001488def get_edit_config(switch_ip, target='runing'):
1489 NETCONF_ACCOUNT="netconfuser"
1490 NETCONF_PASSWD="netconfuser"
1491 with manager.connect_ssh(host=switch_ip, port=830, username=NETCONF_ACCOUNT, password=NETCONF_PASSWD, hostkey_verify=False ) as m:
macauley6f6ceb22015-08-07 09:37:12 +08001492 return m.get_config(source='running').data_xml
macauleydbff3272015-07-30 14:07:16 +08001493
macauley_cheng67da9262015-08-31 15:18:41 +08001494
1495"""
1496MPLS
1497"""
1498
1499OFDPA_MPLS_SUBTYPE_SHIFT=24
Pierbbdf3782016-08-22 17:58:26 -07001500OFDPA_MPLS_GROUP_SUBTYPE_L2_VPN_LABEL=1
macauley_cheng67da9262015-08-31 15:18:41 +08001501OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL=2
1502OFDPA_MPLS_GROUP_SUBTYPE_TUNNEL_LABEL1=3
1503OFDPA_MPLS_GROUP_SUBTYPE_TUNNEL_LABEL2=4
1504OFDPA_MPLS_GROUP_SUBTYPE_SWAP_LABEL=5
1505OFDPA_MPLS_GROUP_SUBTYPE_FAST_FAILOVER_GROUP=6
1506OFDPA_MPLS_GROUP_SUBTYPE_ECMP=8
1507OFDPA_MPLS_GROUP_SUBTYPE_L2_TAG=10
1508
Piercf76e802016-09-19 20:16:35 -07001509
1510
1511
macauley_cheng67da9262015-08-31 15:18:41 +08001512def encode_mpls_interface_group_id(subtype, index):
1513 index=index&0x00ffffff
1514 assert(subtype==0)
1515 return index + (9 << OFDPA_GROUP_TYPE_SHIFT)+(subtype<<OFDPA_MPLS_SUBTYPE_SHIFT)
1516
1517def encode_mpls_label_group_id(subtype, index):
1518 index=index&0x00ffffff
1519 assert(subtype <=5 or subtype==0)
1520 #1: l2 vpn label
1521 #2: l3 vpn label
1522 #3: mpls tunnel label 1
1523 #4: mpls tunnel lable 2
1524 #5: mpls swap label
Pierbbdf3782016-08-22 17:58:26 -07001525 return index + (9 << OFDPA_GROUP_TYPE_SHIFT)+(subtype<<OFDPA_MPLS_SUBTYPE_SHIFT)
macauley_cheng67da9262015-08-31 15:18:41 +08001526
1527def encode_mpls_forwarding_group_id(subtype, index):
1528 index=index&0x00ffffff
1529 assert(subtype==6 or subtype==8 or subtype==10)
Pierbbdf3782016-08-22 17:58:26 -07001530 return index + (10 << OFDPA_GROUP_TYPE_SHIFT)+(subtype<<OFDPA_MPLS_SUBTYPE_SHIFT)
macauley_cheng67da9262015-08-31 15:18:41 +08001531
1532
1533def add_mpls_intf_group(ctrl, ref_gid, dst_mac, src_mac, vid, index, subtype=0):
1534 action=[]
1535 action.append(ofp.action.set_field(ofp.oxm.eth_src(src_mac)))
1536 action.append(ofp.action.set_field(ofp.oxm.eth_dst(dst_mac)))
Piercf76e802016-09-19 20:16:35 -07001537 if vid != 1:
1538 action.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+vid)))
macauley_cheng67da9262015-08-31 15:18:41 +08001539 action.append(ofp.action.group(ref_gid))
Pierbbdf3782016-08-22 17:58:26 -07001540
macauley_cheng67da9262015-08-31 15:18:41 +08001541 buckets = [ofp.bucket(actions=action)]
1542
1543 mpls_group_id =encode_mpls_interface_group_id(subtype, index)
1544 request = ofp.message.group_add(group_type=ofp.OFPGT_INDIRECT,
1545 group_id=mpls_group_id,
1546 buckets=buckets
1547 )
1548 ctrl.message_send(request)
1549 return mpls_group_id, request
1550
Piercf76e802016-09-19 20:16:35 -07001551def add_mpls_tunnel_label_group(
1552 ctrl,
1553 ref_gid,
1554 subtype,
1555 index,
1556 label,
1557 ):
1558
1559 action=[]
1560 action.append(ofp.action.push_mpls(0x8847))
1561 action.append(ofp.action.set_field(ofp.oxm.mpls_label(label)))
1562 action.append(ofp.action.group(ref_gid))
1563 buckets = [ofp.bucket(actions=action)]
1564
1565 mpls_group_id = encode_mpls_label_group_id(subtype, index)
1566 request = ofp.message.group_add(group_type=ofp.OFPGT_INDIRECT,
1567 group_id=mpls_group_id,
1568 buckets=buckets
1569 )
1570 ctrl.message_send(request)
1571
1572 return mpls_group_id, request
1573
Pierbbdf3782016-08-22 17:58:26 -07001574def add_mpls_label_group(ctrl, subtype, index, ref_gid,
macauley_cheng67da9262015-08-31 15:18:41 +08001575 lmep_id=-1,
1576 qos_index=-1,
1577 push_l2_header=False,
1578 push_vlan=False,
1579 push_mpls_header=False,
1580 push_cw=False,
1581 set_mpls_label=None,
1582 set_bos=None,
1583 set_tc=None,
1584 set_tc_from_table=False,
1585 cpy_tc_outward=False,
1586 set_ttl=None,
1587 cpy_ttl_outward=False,
1588 oam_lm_tx_count=False,
1589 set_pri_from_table=False
1590 ):
1591 """
1592 @ref_gid: only can be mpls intf group or mpls tunnel label 1/2 group
Pierbbdf3782016-08-22 17:58:26 -07001593 """
macauley_cheng67da9262015-08-31 15:18:41 +08001594 action=[]
1595
1596 if push_vlan== True:
1597 action.append(ofp.action.push_vlan(0x8100))
1598 if push_mpls_header== True:
1599 action.append(ofp.action.push_mpls(0x8847))
1600 if set_mpls_label != None:
1601 action.append(ofp.action.set_field(ofp.oxm.mpls_label(set_mpls_label)))
1602 if set_bos != None:
1603 action.append(ofp.action.set_field(ofp.oxm.mpls_bos(set_bos)))
1604 if set_tc != None:
1605 assert(set_tc_from_table==False)
1606 action.append(ofp.action.set_field(ofp.oxm.mpls_tc(set_tc)))
1607 if set_ttl != None:
Pierbbdf3782016-08-22 17:58:26 -07001608 action.append(ofp.action.set_mpls_ttl(set_ttl))
macauley_cheng67da9262015-08-31 15:18:41 +08001609 if cpy_ttl_outward == True:
Pierbbdf3782016-08-22 17:58:26 -07001610 action.append(ofp.action.copy_ttl_out())
macauley_cheng67da9262015-08-31 15:18:41 +08001611 """
1612 ofdpa experimenter
Pierbbdf3782016-08-22 17:58:26 -07001613 """
macauley_cheng67da9262015-08-31 15:18:41 +08001614 if push_l2_header== True:
Pierbbdf3782016-08-22 17:58:26 -07001615 action.append(ofp.action.ofdpa_push_l2_header())
macauley_cheng67da9262015-08-31 15:18:41 +08001616 if set_tc_from_table== True:
1617 assert(qos_index>=0)
1618 assert(set_tc == None)
Pierbbdf3782016-08-22 17:58:26 -07001619 action.append(ofp.action.ofdpa_set_tc_from_table(qos_index))
macauley_cheng67da9262015-08-31 15:18:41 +08001620 if cpy_tc_outward == True:
Pierbbdf3782016-08-22 17:58:26 -07001621 action.append(ofp.action.ofdpa_copy_tc_out())
macauley_cheng67da9262015-08-31 15:18:41 +08001622 if oam_lm_tx_count == True:
Pierbbdf3782016-08-22 17:58:26 -07001623 assert(qos_index>=0 and lmep_id>=0)
1624 action.append(ofp.action.ofdpa_oam_lm_tx_count(lmep_id, qos_index))
macauley_cheng67da9262015-08-31 15:18:41 +08001625 if set_pri_from_table == True:
Pierbbdf3782016-08-22 17:58:26 -07001626 assert(qos_index>=0)
1627 action.append(ofp.action.ofdpa_set_qos_from_table(qos_index))
macauley_cheng67da9262015-08-31 15:18:41 +08001628 if push_cw == True:
1629 action.append(ofp.action.ofdpa_push_cw())
Pierbbdf3782016-08-22 17:58:26 -07001630
1631 action.append(ofp.action.group(ref_gid))
macauley_cheng67da9262015-08-31 15:18:41 +08001632 buckets = [ofp.bucket(actions=action)]
Pierbbdf3782016-08-22 17:58:26 -07001633
macauley_cheng67da9262015-08-31 15:18:41 +08001634 mpls_group_id = encode_mpls_label_group_id(subtype, index)
1635 request = ofp.message.group_add(group_type=ofp.OFPGT_INDIRECT,
1636 group_id=mpls_group_id,
1637 buckets=buckets
1638 )
1639 ctrl.message_send(request)
Pierbbdf3782016-08-22 17:58:26 -07001640
1641 return mpls_group_id, request
1642
Piercf76e802016-09-19 20:16:35 -07001643def add_mpls_l2_port_flow(ctrl, of_port, mpls_l2_port, tunnel_index, ref_gid, qos_index=0):
1644 """
1645 Only action is Group, which must indicate one of:
1646 MPLS L2 VPN Label or Fast Failover Protection Group.
1647 ref_gid contains this information
1648 """
1649 tunnel_id = tunnel_index + ofp.oxm.TUNNEL_ID_BASE
1650
1651 match = ofp.match()
1652 match.oxm_list.append(ofp.oxm.exp4ByteValue(exp_type=ofp.oxm.OFDPA_EXP_TYPE_MPLS_L2_PORT, value=0x00000000 + of_port))
1653 match.oxm_list.append(ofp.oxm.tunnel_id(tunnel_index + ofp.oxm.TUNNEL_ID_BASE))
1654
1655 action = []
1656 action.append(ofp.action.group(ref_gid))
1657 assert(qos_index>=0)
1658 action.append(ofp.action.set_field(ofp.oxm.exp1ByteValue(exp_type=ofp.oxm.OFDPA_EXP_TYPE_QOS_INDEX, value=qos_index)))
1659
1660 request = ofp.message.flow_add(
1661 table_id=MPLS_L2_PORT_FLOW_TABLE,
1662 cookie=42,
1663 match=match,
1664 instructions=[
1665 ofp.instruction.write_actions(
1666 actions=action
1667 ),
1668 ofp.instruction.goto_table(MPLS_L2_PORT_PCP_TRUST_FLOW_TABLE) ],
1669 buffer_id=ofp.OFP_NO_BUFFER,
1670 priority=1)
1671 logging.info("Inserting flow %d mpls_l2_port, %d tunnel_id, action %x group and go to table %d", mpls_l2_port, tunnel_id, ref_gid, MPLS_L2_PORT_DSCP_TRUST_FLOW_TABLE)
1672 ctrl.message_send(request)
1673 return request
1674
1675 return
1676
Pierbbdf3782016-08-22 17:58:26 -07001677def add_mpls_forwarding_group(ctrl, subtype, index, ref_gids,
1678 watch_port=None,
1679 watch_group=ofp.OFPP_ANY,
macauley_cheng67da9262015-08-31 15:18:41 +08001680 push_vlan=None,
macauley_chengd17ce512015-08-31 17:45:51 +08001681 pop_vlan=None,
macauley_cheng67da9262015-08-31 15:18:41 +08001682 set_vid=None):
1683 assert(subtype == OFDPA_MPLS_GROUP_SUBTYPE_FAST_FAILOVER_GROUP
1684 or subtype == OFDPA_MPLS_GROUP_SUBTYPE_ECMP
1685 or subtype == OFDPA_MPLS_GROUP_SUBTYPE_L2_TAG)
macauley_chengd17ce512015-08-31 17:45:51 +08001686
macauley_cheng67da9262015-08-31 15:18:41 +08001687 buckets=[]
1688 if subtype == OFDPA_MPLS_GROUP_SUBTYPE_FAST_FAILOVER_GROUP:
macauley_chengd17ce512015-08-31 17:45:51 +08001689 group_type = ofp.OFPGT_FF
macauley_cheng67da9262015-08-31 15:18:41 +08001690 for gid in ref_gids:
macauley_chengd17ce512015-08-31 17:45:51 +08001691 action=[]
Pierbbdf3782016-08-22 17:58:26 -07001692 action.append(ofp.action.group(gid))
macauley_chengd17ce512015-08-31 17:45:51 +08001693 buckets.append(ofp.bucket(watch_port=watch_port, watch_group=watch_group,actions=action))
1694
macauley_cheng67da9262015-08-31 15:18:41 +08001695 elif subtype == OFDPA_MPLS_GROUP_SUBTYPE_ECMP:
1696 group_type = ofp.OFPGT_SELECT
1697 for gid in ref_gids:
macauley_chengd17ce512015-08-31 17:45:51 +08001698 action=[]
Pierbbdf3782016-08-22 17:58:26 -07001699 action.append(ofp.action.group(gid))
macauley_cheng67da9262015-08-31 15:18:41 +08001700 buckets.append(ofp.bucket(actions=action))
macauley_chengd17ce512015-08-31 17:45:51 +08001701
macauley_cheng67da9262015-08-31 15:18:41 +08001702 elif subtype == OFDPA_MPLS_GROUP_SUBTYPE_L2_TAG:
1703 group_type = ofp.OFPGT_INDIRECT
macauley_chengd17ce512015-08-31 17:45:51 +08001704 action=[]
macauley_cheng67da9262015-08-31 15:18:41 +08001705 if set_vid!=None:
Flavio Castro91d1a552016-05-17 16:59:44 -07001706 action.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+set_vid)))
macauley_cheng67da9262015-08-31 15:18:41 +08001707 if push_vlan!=None:
Pierbbdf3782016-08-22 17:58:26 -07001708 action.append(ofp.action.push_vlan(push_vlan))
macauley_cheng67da9262015-08-31 15:18:41 +08001709 if pop_vlan!=None:
Pierbbdf3782016-08-22 17:58:26 -07001710 action.append(ofp.action.pop_vlan())
1711 action.append(ofp.action.group(ref_gids[0]))
macauley_cheng67da9262015-08-31 15:18:41 +08001712 buckets.append(ofp.bucket(actions=action))
macauley_chengd17ce512015-08-31 17:45:51 +08001713
1714 mpls_group_id = encode_mpls_forwarding_group_id(subtype, index)
macauley_cheng67da9262015-08-31 15:18:41 +08001715 request = ofp.message.group_add(group_type=group_type,
macauley_cheng67da9262015-08-31 15:18:41 +08001716 group_id=mpls_group_id,
1717 buckets=buckets
1718 )
1719 ctrl.message_send(request)
Pierbbdf3782016-08-22 17:58:26 -07001720 return mpls_group_id, request
macauley_chengd17ce512015-08-31 17:45:51 +08001721
1722
macauley_cheng67da9262015-08-31 15:18:41 +08001723"""
Piercf76e802016-09-19 20:16:35 -07001724display
Pierbbdf3782016-08-22 17:58:26 -07001725"""
macauleydbff3272015-07-30 14:07:16 +08001726def print_current_table_flow_stat(ctrl, table_id=0xff):
1727 stat_req=ofp.message.flow_stats_request()
1728 response, pkt = ctrl.transact(stat_req)
1729 if response == None:
1730 print "no response"
1731 return None
1732 print len(response.entries)
1733 for obj in response.entries:
1734 print "match ", obj.match
1735 print "cookie", obj.cookie
1736 print "priority", obj.priority
1737 print "idle_timeout", obj.idle_timeout
1738 print "hard_timeout", obj.hard_timeout
1739 #obj.actions
Flavio Castro167f5bd2015-12-02 19:33:53 -05001740 print "packet count: %lx"%obj.packet_count