blob: 2c1be4a938d4b2bb80738ec90eaf22042662bb9e [file] [log] [blame]
Matteo Scandoloa229eca2017-08-08 13:05:28 -07001# Copyright 2017-present Open Networking Foundation
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15
macauley97557232015-07-16 17:28:07 +080016import logging
17
18from oftest import config
19import oftest.base_tests as base_tests
20import ofp
21import time
22from oftest.testutils import *
Pier1e4e98e2016-10-26 14:36:05 -070023from oftest.parse import parse_ipv6
macauley97557232015-07-16 17:28:07 +080024
macauleyfddc4662015-07-27 17:40:30 +080025from ncclient import manager
26import ncclient
27
macauley97557232015-07-16 17:28:07 +080028OFDPA_GROUP_TYPE_SHIFT=28
29OFDPA_VLAN_ID_SHIFT =16
macauleyfddc4662015-07-27 17:40:30 +080030OFDPA_TUNNEL_ID_SHIFT =12
31OFDPA_TUNNEL_SUBTYPE_SHIFT=10
macauley97557232015-07-16 17:28:07 +080032
33#VLAN_TABLE_FLAGS
34VLAN_TABLE_FLAG_ONLY_UNTAG=1
35VLAN_TABLE_FLAG_ONLY_TAG =2
36VLAN_TABLE_FLAG_ONLY_BOTH =3
Piere1308762016-09-12 15:29:56 -070037VLAN_TABLE_FLAG_ONLY_STACKED=5
38VLAN_TABLE_FLAG_PRIORITY=6
39VLAN_TABLE_FLAG_ONLY_UNTAG_PRIORITY=7
Andreas Pantelopoulosf83e0212018-03-18 20:44:05 -070040VLAN_TABLE_FLAG_ONLY_POP_VLAN=8
macauley97557232015-07-16 17:28:07 +080041
macauleye8b140e2015-08-03 13:35:45 +080042PORT_FLOW_TABLE=0
43VLAN_FLOW_TABLE=10
Piere1308762016-09-12 15:29:56 -070044VLAN_1_FLOW_TABLE=11
Piercf76e802016-09-19 20:16:35 -070045MPLS_L2_PORT_FLOW_TABLE=13
46MPLS_L2_PORT_DSCP_TRUST_FLOW_TABLE=15
47MPLS_L2_PORT_PCP_TRUST_FLOW_TABLE=16
macauleye8b140e2015-08-03 13:35:45 +080048TERMINATION_FLOW_TABLE=20
Piercf76e802016-09-19 20:16:35 -070049MPLS_TYPE_FLOW_TABLE=29
macauleye8b140e2015-08-03 13:35:45 +080050UCAST_ROUTING_FLOW_TABLE=30
51MCAST_ROUTING_FLOW_TABLE=40
52BRIDGE_FLOW_TABLE=50
53ACL_FLOW_TABLE=60
Jonghwan Hyunff0dfd52018-03-20 15:04:35 -070054EGRESS_TPID_FLOW_TABLE = 235
55
56ONF_EXPERIMENTER_ID = 0x4F4E4600
macauleye8b140e2015-08-03 13:35:45 +080057
Andreas Pantelopoulosf83e0212018-03-18 20:44:05 -070058EGRESS_VLAN_FLOW_TABLE=210
59EGRESS_VLAN_1_FLOW_TABLE=211
60EGRESS_MAINTENANCE_POINT_FLOW_TABLE=226
61EGRESS_DSCP_TABLE=230
62EGRESS_TPID_TABLE=235
63EGRESS_SOURCE_MAC_LEARNING_TABLE=254
64
macauleye8b140e2015-08-03 13:35:45 +080065def convertIP4toStr(ip_addr):
66 a=(ip_addr&0xff000000)>>24
67 b=(ip_addr&0x00ff0000)>>16
68 c=(ip_addr&0x0000ff00)>>8
69 d=(ip_addr&0x000000ff)
70 return str(a)+"."+str(b)+"."+str(c)+"."+str(d)
71
72def convertMACtoStr(mac):
73 if not isinstance(mac, list):
74 assert(0)
75
76 return ':'.join(['%02X' % x for x in mac])
77
macauley7f89d962015-08-06 18:13:48 +080078def getSwitchCpuMACFromDPID(dpid):
79 str_datapath_id_f= "{:016x}".format(dpid)
80 str_datapath_id=':'.join([str_datapath_id_f[i:i+2] for i in range(0, len(str_datapath_id_f), 2)])
81 switch_cpu_mac_str=str_datapath_id[6:]
82 switch_cpu_mac = switch_cpu_mac_str.split(":")
83 switch_cpu_mac=[int(switch_cpu_mac[i],16) for i in range(0, len(switch_cpu_mac))]
84
85 return switch_cpu_mac_str, switch_cpu_mac
Pierbbdf3782016-08-22 17:58:26 -070086
macauley_cheng67da9262015-08-31 15:18:41 +080087def DumpGroup(stats, verify_group_stats, always_show=True):
88 if(len(stats) > len(verify_group_stats)):
89 min_len = len(verify_group_stats)
90 print "Stats Len is not the same, stats>verify_group_stats"
91 if(len(stats)< len(verify_group_stats)):
Pierbbdf3782016-08-22 17:58:26 -070092 min_len = len(stats)
macauley_cheng67da9262015-08-31 15:18:41 +080093 print "Stats Len is not the same, stats<verify_group_stats"
Pierbbdf3782016-08-22 17:58:26 -070094 else:
macauley_cheng67da9262015-08-31 15:18:41 +080095 min_len = len(stats)
macauleye8b140e2015-08-03 13:35:45 +080096
macauley_cheng67da9262015-08-31 15:18:41 +080097 print "\r\n"
98 for i in range(min_len):
99 gs = stats[i]
Pierbbdf3782016-08-22 17:58:26 -0700100 gv = verify_group_stats[i]
macauley_cheng67da9262015-08-31 15:18:41 +0800101 print "FromSwtich:(GID=%lx, TYPE=%lx)\r\nVerify :(GID=%lx, TYPE=%lx)"%(gs.group_id, gs.group_type, gv.group_id, gv.group_type)
102 if(len(gs.buckets) != len(gv.buckets)):
103 print "buckets len is not the same gs %lx, gv %lx",(len(gs.buckets), len(gv.buckets))
104
105 for j in range(len(gs.buckets)):
106 b1=gs.buckets[j]
Pierbbdf3782016-08-22 17:58:26 -0700107 b2=gv.buckets[j]
macauley_cheng67da9262015-08-31 15:18:41 +0800108 if(len(b1.actions) != len(b2.actions)):
109 print "action len is not the same"
110
111 for k in range(len(b1.actions)):
112 a1=b1.actions[k]
113 a2=b2.actions[k]
114 if(always_show == True):
115 print "a1:"+a1.show()
Pierbbdf3782016-08-22 17:58:26 -0700116 print "a2:"+a2.show()
macauley_cheng67da9262015-08-31 15:18:41 +0800117
118def AssertGroup(self, stats, verify_group_stats):
119 self.assertTrue(len(stats) ==len(verify_group_stats), "stats len is not the same")
120
121 for i in range(len(stats)):
122 gs = stats[i]
Pierbbdf3782016-08-22 17:58:26 -0700123 gv = verify_group_stats[i]
macauley_cheng67da9262015-08-31 15:18:41 +0800124 self.assertTrue(len(gs.buckets) == len(gv.buckets), "buckets len is not the same")
125
126 for j in range(len(gs.buckets)):
127 b1=gs.buckets[j]
Pierbbdf3782016-08-22 17:58:26 -0700128 b2=gv.buckets[j]
macauley_cheng67da9262015-08-31 15:18:41 +0800129 self.assertTrue(len(b1.actions) == len(b2.actions), "action len is not the same")
130
131 for k in range(len(b1.actions)):
132 a1=b1.actions[k]
133 a2=b2.actions[k]
134 self.assertEquals(a1, a2, "action is not the same")
Pierbbdf3782016-08-22 17:58:26 -0700135
macauley97557232015-07-16 17:28:07 +0800136def encode_l2_interface_group_id(vlan, id):
137 return id + (vlan << OFDPA_VLAN_ID_SHIFT)
138
139def encode_l2_rewrite_group_id(id):
140 return id + (1 << OFDPA_GROUP_TYPE_SHIFT)
141
142def encode_l3_unicast_group_id(id):
143 return id + (2 << OFDPA_GROUP_TYPE_SHIFT)
144
145def encode_l2_mcast_group_id(vlan, id):
146 return id + (vlan << OFDPA_VLAN_ID_SHIFT) + (3 << OFDPA_GROUP_TYPE_SHIFT)
147
148def encode_l2_flood_group_id(vlan, id):
149 return id + (vlan << OFDPA_VLAN_ID_SHIFT) + (4 << OFDPA_GROUP_TYPE_SHIFT)
Pierbbdf3782016-08-22 17:58:26 -0700150
macauley97557232015-07-16 17:28:07 +0800151def encode_l3_interface_group_id(id):
152 return id + (5 << OFDPA_GROUP_TYPE_SHIFT)
153
154def encode_l3_mcast_group_id(vlan, id):
155 return id + (vlan << OFDPA_VLAN_ID_SHIFT)+(6 << OFDPA_GROUP_TYPE_SHIFT)
156
157def encode_l3_ecmp_group_id(id):
158 return id + (7 << OFDPA_GROUP_TYPE_SHIFT)
159
Flavio Castro91d1a552016-05-17 16:59:44 -0700160def encode_l2_unfiltered_group_id(id):
161 return id + (11 << OFDPA_GROUP_TYPE_SHIFT)
162
macauleyfddc4662015-07-27 17:40:30 +0800163def encode_l2_overlay_group_id(tunnel_id, subtype, index):
164 tunnel_id=tunnel_id&0xffff #16 bits
165 subtype = subtype&3 #2 bits
166 index = index & 0x3f #10 bits
167 return index + (tunnel_id << OFDPA_TUNNEL_ID_SHIFT)+ (subtype<<OFDPA_TUNNEL_SUBTYPE_SHIFT)+(8 << OFDPA_GROUP_TYPE_SHIFT)
macauley97557232015-07-16 17:28:07 +0800168
Flavio Castro91d1a552016-05-17 16:59:44 -0700169def add_l2_unfiltered_group(ctrl, ports, send_barrier=False):
170 # group table
171 # set up untag groups for each port
172 group_id_list=[]
173 msgs=[]
174 for of_port in ports:
175 # do stuff
176 group_id = encode_l2_unfiltered_group_id(of_port)
177 group_id_list.append(group_id)
178 actions = [ofp.action.output(of_port)]
179 actions.append(ofp.action.set_field(ofp.oxm.exp1ByteValue(exp_type=24, value=1)))
180
181 buckets = [ofp.bucket(actions=actions)]
182 request = ofp.message.group_add(group_type=ofp.OFPGT_INDIRECT,
183 group_id=group_id,
184 buckets=buckets
185 )
186 ctrl.message_send(request)
187 msgs.append(request)
188
189 if send_barrier:
190 do_barrier(ctrl)
191
192 return group_id_list, msgs
193
Pierf6f28162016-09-22 16:30:52 -0700194def add_one_l2_unfiltered_group(ctrl, of_port, send_barrier=False):
195 # group table
196 # set up untag groups for each port
197 group_id = encode_l2_unfiltered_group_id(of_port)
198 actions = [ofp.action.output(of_port)]
199 actions.append(ofp.action.set_field(ofp.oxm.exp1ByteValue(exp_type=24, value=1)))
200
201 buckets = [ofp.bucket(actions=actions)]
202 request = ofp.message.group_add(
203 group_type=ofp.OFPGT_INDIRECT,
204 group_id=group_id,
205 buckets=buckets
206 )
207 ctrl.message_send(request)
208
209 if send_barrier:
210 do_barrier(ctrl)
211
212 return group_id, request
213
Flavio Castrod4c44d12015-12-08 14:44:18 -0500214def add_l2_interface_group(ctrl, ports, vlan_id=1, is_tagged=False, send_barrier=False):
macauley97557232015-07-16 17:28:07 +0800215 # group table
216 # set up untag groups for each port
macauley41904ed2015-07-16 17:38:35 +0800217 group_id_list=[]
macauley15909e72015-07-17 15:58:57 +0800218 msgs=[]
macauley97557232015-07-16 17:28:07 +0800219 for of_port in ports:
220 # do stuff
221 group_id = encode_l2_interface_group_id(vlan_id, of_port)
macauley41904ed2015-07-16 17:38:35 +0800222 group_id_list.append(group_id)
macauley97557232015-07-16 17:28:07 +0800223 if is_tagged:
224 actions = [
225 ofp.action.output(of_port),
Pierbbdf3782016-08-22 17:58:26 -0700226 ]
macauley97557232015-07-16 17:28:07 +0800227 else:
228 actions = [
229 ofp.action.pop_vlan(),
230 ofp.action.output(of_port),
231 ]
232
233 buckets = [
234 ofp.bucket(actions=actions),
235 ]
236
237 request = ofp.message.group_add(group_type=ofp.OFPGT_INDIRECT,
238 group_id=group_id,
239 buckets=buckets
240 )
241 ctrl.message_send(request)
macauley15909e72015-07-17 15:58:57 +0800242 msgs.append(request)
macauley97557232015-07-16 17:28:07 +0800243
244 if send_barrier:
245 do_barrier(ctrl)
Pierbbdf3782016-08-22 17:58:26 -0700246
macauley15909e72015-07-17 15:58:57 +0800247 return group_id_list, msgs
macauley97557232015-07-16 17:28:07 +0800248
Flavio Castrod4c44d12015-12-08 14:44:18 -0500249def add_one_l2_interface_group(ctrl, port, vlan_id=1, is_tagged=False, send_barrier=False):
macauley0f91a3e2015-07-17 18:09:59 +0800250 # group table
251 # set up untag groups for each port
252 group_id = encode_l2_interface_group_id(vlan_id, port)
253
254 if is_tagged:
255 actions = [
256 ofp.action.output(port),
Pierbbdf3782016-08-22 17:58:26 -0700257 ]
macauley0f91a3e2015-07-17 18:09:59 +0800258 else:
259 actions = [
260 ofp.action.pop_vlan(),
261 ofp.action.output(port),
262 ]
263
264 buckets = [
265 ofp.bucket(actions=actions),
266 ]
267
268 request = ofp.message.group_add(group_type=ofp.OFPGT_INDIRECT,
269 group_id=group_id,
270 buckets=buckets
271 )
272 ctrl.message_send(request)
273
274 if send_barrier:
275 do_barrier(ctrl)
Pierbbdf3782016-08-22 17:58:26 -0700276
macauley0f91a3e2015-07-17 18:09:59 +0800277 return group_id, request
Pierbbdf3782016-08-22 17:58:26 -0700278
macauley97557232015-07-16 17:28:07 +0800279def add_l2_mcast_group(ctrl, ports, vlanid, mcast_grp_index):
280 buckets=[]
281 for of_port in ports:
282 group_id = encode_l2_interface_group_id(vlanid, of_port)
283 action=[ofp.action.group(group_id)]
284 buckets.append(ofp.bucket(actions=action))
285
286 group_id =encode_l2_mcast_group_id(vlanid, mcast_grp_index)
287 request = ofp.message.group_add(group_type=ofp.OFPGT_ALL,
288 group_id=group_id,
289 buckets=buckets
290 )
291 ctrl.message_send(request)
macauley15909e72015-07-17 15:58:57 +0800292 return request
macauley97557232015-07-16 17:28:07 +0800293
macauley15909e72015-07-17 15:58:57 +0800294def add_l2_flood_group(ctrl, ports, vlanid, id):
295 buckets=[]
296 for of_port in ports:
297 group_id = encode_l2_interface_group_id(vlanid, of_port)
298 action=[ofp.action.group(group_id)]
299 buckets.append(ofp.bucket(actions=action))
macauley97557232015-07-16 17:28:07 +0800300
macauley15909e72015-07-17 15:58:57 +0800301 group_id =encode_l2_flood_group_id(vlanid, id)
302 request = ofp.message.group_add(group_type=ofp.OFPGT_ALL,
303 group_id=group_id,
304 buckets=buckets
305 )
306 ctrl.message_send(request)
307 return request
308
Flavio Castroa7162bb2016-07-25 17:30:30 -0700309def mod_l2_flood_group(ctrl, ports, vlanid, id):
310 buckets=[]
311 for of_port in ports:
312 group_id = encode_l2_interface_group_id(vlanid, of_port)
313 action=[ofp.action.group(group_id)]
314 buckets.append(ofp.bucket(actions=action))
315
316 group_id =encode_l2_flood_group_id(vlanid, id)
317 request = ofp.message.group_modify(group_type=ofp.OFPGT_ALL,
318 group_id=group_id,
319 buckets=buckets
320 )
321 ctrl.message_send(request)
322 return request
323
324
macauley15909e72015-07-17 15:58:57 +0800325def add_l2_rewrite_group(ctrl, port, vlanid, id, src_mac, dst_mac):
326 group_id = encode_l2_interface_group_id(vlanid, port)
327
328 action=[]
329 if src_mac is not None:
330 action.append(ofp.action.set_field(ofp.oxm.eth_src(src_mac)))
331
332 if dst_mac is not None:
333 action.append(ofp.action.set_field(ofp.oxm.eth_dst(dst_mac)))
334
Flavio Castro91d1a552016-05-17 16:59:44 -0700335 action.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+vlanid)))
Pierbbdf3782016-08-22 17:58:26 -0700336
macauley15909e72015-07-17 15:58:57 +0800337 action.append(ofp.action.group(group_id))
Pierbbdf3782016-08-22 17:58:26 -0700338
macauley15909e72015-07-17 15:58:57 +0800339 buckets = [ofp.bucket(actions=action)]
340
341 group_id =encode_l2_rewrite_group_id(id)
342 request = ofp.message.group_add(group_type=ofp.OFPGT_INDIRECT,
343 group_id=group_id,
344 buckets=buckets
345 )
346 ctrl.message_send(request)
347 return request
Pierbbdf3782016-08-22 17:58:26 -0700348
Andreas Pantelopoulosf83e0212018-03-18 20:44:05 -0700349def add_l3_unicast_group(ctrl, port, vlanid, id, src_mac, dst_mac, send_barrier=False, gid=None):
350
351 if (not gid):
352 group_id = encode_l2_interface_group_id(vlanid, port)
353 else:
354 group_id = gid
macauley15909e72015-07-17 15:58:57 +0800355
356 action=[]
357 if src_mac is not None:
358 action.append(ofp.action.set_field(ofp.oxm.eth_src(src_mac)))
359
360 if dst_mac is not None:
361 action.append(ofp.action.set_field(ofp.oxm.eth_dst(dst_mac)))
362
Flavio Castroaf2b4502016-02-02 17:41:32 -0500363 action.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+vlanid)))
Pierbbdf3782016-08-22 17:58:26 -0700364
macauley15909e72015-07-17 15:58:57 +0800365 action.append(ofp.action.group(group_id))
Pierbbdf3782016-08-22 17:58:26 -0700366
macauley15909e72015-07-17 15:58:57 +0800367 buckets = [ofp.bucket(actions=action)]
368
369 group_id =encode_l3_unicast_group_id(id)
370 request = ofp.message.group_add(group_type=ofp.OFPGT_INDIRECT,
371 group_id=group_id,
372 buckets=buckets
373 )
374 ctrl.message_send(request)
Pier1e4e98e2016-10-26 14:36:05 -0700375
376 if send_barrier:
377 do_barrier(ctrl)
378
macauley15909e72015-07-17 15:58:57 +0800379 return request
Pierbbdf3782016-08-22 17:58:26 -0700380
macauley15909e72015-07-17 15:58:57 +0800381def add_l3_interface_group(ctrl, port, vlanid, id, src_mac):
382 group_id = encode_l2_interface_group_id(vlanid, port)
383
384 action=[]
385 action.append(ofp.action.set_field(ofp.oxm.eth_src(src_mac)))
Pierbbdf3782016-08-22 17:58:26 -0700386 action.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+vlanid)))
macauley15909e72015-07-17 15:58:57 +0800387 action.append(ofp.action.group(group_id))
Pierbbdf3782016-08-22 17:58:26 -0700388
macauley15909e72015-07-17 15:58:57 +0800389 buckets = [ofp.bucket(actions=action)]
390
391 group_id =encode_l3_interface_group_id(id)
392 request = ofp.message.group_add(group_type=ofp.OFPGT_INDIRECT,
393 group_id=group_id,
394 buckets=buckets
395 )
396 ctrl.message_send(request)
397 return request
398
Pier1e4e98e2016-10-26 14:36:05 -0700399def add_l3_ecmp_group(ctrl, id, l3_ucast_groups, send_barrier=False):
macauley15909e72015-07-17 15:58:57 +0800400 buckets=[]
401 for group in l3_ucast_groups:
402 buckets.append(ofp.bucket(actions=[ofp.action.group(group)]))
403
404 group_id =encode_l3_ecmp_group_id(id)
405 request = ofp.message.group_add(group_type=ofp.OFPGT_SELECT,
406 group_id=group_id,
407 buckets=buckets
408 )
409 ctrl.message_send(request)
Pier1e4e98e2016-10-26 14:36:05 -0700410
411 if send_barrier:
412 do_barrier(ctrl)
413
macauley15909e72015-07-17 15:58:57 +0800414 return request
Flavio Castroa7162bb2016-07-25 17:30:30 -0700415
416def mod_l3_ecmp_group(ctrl, id, l3_ucast_groups):
417 buckets=[]
418 for group in l3_ucast_groups:
419 buckets.append(ofp.bucket(actions=[ofp.action.group(group)]))
420
421 group_id =encode_l3_ecmp_group_id(id)
422 request = ofp.message.group_modify(group_type=ofp.OFPGT_SELECT,
423 group_id=group_id,
424 buckets=buckets
425 )
426 ctrl.message_send(request)
427 return request
428
macauley15909e72015-07-17 15:58:57 +0800429def add_l3_mcast_group(ctrl, vid, mcast_group_id, groups_on_buckets):
430 buckets=[]
431 for group in groups_on_buckets:
432 buckets.append(ofp.bucket(actions=[ofp.action.group(group)]))
Pierbbdf3782016-08-22 17:58:26 -0700433
macauley15909e72015-07-17 15:58:57 +0800434 group_id =encode_l3_mcast_group_id(vid, mcast_group_id)
435 request = ofp.message.group_add(group_type=ofp.OFPGT_ALL,
436 group_id=group_id,
437 buckets=buckets
438 )
439 ctrl.message_send(request)
440 return request
macauleyfddc4662015-07-27 17:40:30 +0800441
442def add_l2_overlay_flood_over_unicast_tunnel_group(ctrl, tunnel_id, ports, index):
443 buckets=[]
444 for port in ports:
445 buckets.append(ofp.bucket(actions=[ofp.action.output(port)]))
446
447 group_id=encode_l2_overlay_group_id(tunnel_id, 0, index)
448 request = ofp.message.group_add(group_type=ofp.OFPGT_ALL,
449 group_id=group_id,
450 buckets=buckets
451 )
452 ctrl.message_send(request)
453 return request
454
455def add_l2_overlay_flood_over_mcast_tunnel_group(ctrl, tunnel_id, ports, index):
456 buckets=[]
457 for port in ports:
458 buckets.append(ofp.bucket(actions=[ofp.action.output(port)]))
459
460 group_id=encode_l2_overlay_group_id(tunnel_id, 1, index)
461 request = ofp.message.group_add(group_type=ofp.OFPGT_ALL,
462 group_id=group_id,
463 buckets=buckets
464 )
465 ctrl.message_send(request)
466 return request
467
468def add_l2_overlay_mcast_over_unicast_tunnel_group(ctrl, tunnel_id, ports, index):
469 buckets=[]
470 for port in ports:
471 buckets.append(ofp.bucket(actions=[ofp.action.output(port)]))
472
473 group_id=encode_l2_overlay_group_id(tunnel_id, 2, index)
474 request = ofp.message.group_add(group_type=ofp.OFPGT_ALL,
475 group_id=group_id,
476 buckets=buckets
477 )
478 ctrl.message_send(request)
479 return request
480
481def add_l2_overlay_mcast_over_mcast_tunnel_group(ctrl, tunnel_id, ports, index):
482 buckets=[]
483 for port in ports:
484 buckets.append(ofp.bucket(actions=[ofp.action.output(port)]))
485
486 group_id=encode_l2_overlay_group_id(tunnel_id, 3, index)
487 request = ofp.message.group_add(group_type=ofp.OFPGT_ALL,
488 group_id=group_id,
489 buckets=buckets
490 )
491 ctrl.message_send(request)
492 return request
Pierbbdf3782016-08-22 17:58:26 -0700493
macauleyfddc4662015-07-27 17:40:30 +0800494def add_port_table_flow(ctrl, is_overlay=True):
495 match = ofp.match()
496
497 if is_overlay == True:
498 match.oxm_list.append(ofp.oxm.in_port(0x10000))
macauleydbff3272015-07-30 14:07:16 +0800499 NEXT_TABLE=50
macauleyfddc4662015-07-27 17:40:30 +0800500 else:
501 match.oxm_list.append(ofp.oxm.in_port(0))
Pierbbdf3782016-08-22 17:58:26 -0700502 NEXT_TABLE=10
macauleyfddc4662015-07-27 17:40:30 +0800503
504 request = ofp.message.flow_add(
Pier265ad5f2017-02-28 17:46:28 +0100505 table_id=0,
506 cookie=42,
507 match=match,
508 instructions=[
509 ofp.instruction.goto_table(NEXT_TABLE)
510 ],
511 priority=0)
macauleyfddc4662015-07-27 17:40:30 +0800512 logging.info("Add port table, match port %lx" % 0x10000)
513 ctrl.message_send(request)
Pierbbdf3782016-08-22 17:58:26 -0700514
Flavio Castrod8f8af22015-12-02 18:19:26 -0500515def pop_vlan_flow(ctrl, ports, vlan_id=1):
516 # table 10: vlan
517 # goto to table 20
518 msgs=[]
519 for of_port in ports:
520 match = ofp.match()
521 match.oxm_list.append(ofp.oxm.in_port(of_port))
522 match.oxm_list.append(ofp.oxm.vlan_vid(0x1000+vlan_id))
523 request = ofp.message.flow_add(
524 table_id=10,
525 cookie=42,
526 match=match,
527 instructions=[
528 ofp.instruction.apply_actions(
529 actions=[
530 ofp.action.pop_vlan()
531 ]
532 ),
533 ofp.instruction.goto_table(20)
534 ],
535 priority=0)
536 logging.info("Add vlan %d tagged packets on port %d and go to table 20" %( vlan_id, of_port))
537 ctrl.message_send(request)
538
539
540 return msgs
macauleyfddc4662015-07-27 17:40:30 +0800541
macauley97557232015-07-16 17:28:07 +0800542def add_vlan_table_flow(ctrl, ports, vlan_id=1, flag=VLAN_TABLE_FLAG_ONLY_BOTH, send_barrier=False):
543 # table 10: vlan
544 # goto to table 20
macauley15909e72015-07-17 15:58:57 +0800545 msgs=[]
macauley97557232015-07-16 17:28:07 +0800546 for of_port in ports:
Flavio Castro932014b2016-01-05 18:29:15 -0500547 if (flag == VLAN_TABLE_FLAG_ONLY_TAG) or (flag == VLAN_TABLE_FLAG_ONLY_BOTH) or (flag == 4):
macauley97557232015-07-16 17:28:07 +0800548 match = ofp.match()
549 match.oxm_list.append(ofp.oxm.in_port(of_port))
550 match.oxm_list.append(ofp.oxm.vlan_vid(0x1000+vlan_id))
551 request = ofp.message.flow_add(
552 table_id=10,
553 cookie=42,
554 match=match,
555 instructions=[
Flavio Castrod8f8af22015-12-02 18:19:26 -0500556 ofp.instruction.apply_actions(
557 actions=[
558 ofp.action.pop_vlan()
559 ]
560 ),
macauley97557232015-07-16 17:28:07 +0800561 ofp.instruction.goto_table(20)
562 ],
563 priority=0)
564 logging.info("Add vlan %d tagged packets on port %d and go to table 20" %( vlan_id, of_port))
565 ctrl.message_send(request)
Pierbbdf3782016-08-22 17:58:26 -0700566
macauley97557232015-07-16 17:28:07 +0800567 if (flag == VLAN_TABLE_FLAG_ONLY_UNTAG) or (flag == VLAN_TABLE_FLAG_ONLY_BOTH):
568 match = ofp.match()
569 match.oxm_list.append(ofp.oxm.in_port(of_port))
Flavio Castro12296312015-12-15 17:48:26 -0500570 match.oxm_list.append(ofp.oxm.vlan_vid_masked(0, 0x1fff))
macauley97557232015-07-16 17:28:07 +0800571 request = ofp.message.flow_add(
572 table_id=10,
573 cookie=42,
574 match=match,
575 instructions=[
576 ofp.instruction.apply_actions(
577 actions=[
Flavio Castroaf2b4502016-02-02 17:41:32 -0500578 ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+vlan_id))
macauley97557232015-07-16 17:28:07 +0800579 ]
580 ),
581 ofp.instruction.goto_table(20)
582 ],
583 priority=0)
584 logging.info("Add vlan %d untagged packets on port %d and go to table 20" % (vlan_id, of_port))
585 ctrl.message_send(request)
macauley15909e72015-07-17 15:58:57 +0800586 msgs.append(request)
macauley97557232015-07-16 17:28:07 +0800587
Flavio Castro932014b2016-01-05 18:29:15 -0500588 if (flag == 4) :
589 match = ofp.match()
590 match.oxm_list.append(ofp.oxm.in_port(of_port))
591 match.oxm_list.append(ofp.oxm.vlan_vid_masked(0x1000, 0x1fff))
592 request = ofp.message.flow_add(
593 table_id=10,
594 cookie=42,
595 match=match,
596 instructions=[
597 ofp.instruction.apply_actions(
598 actions=[
Flavio Castroaf2b4502016-02-02 17:41:32 -0500599 ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+vlan_id))
Flavio Castro932014b2016-01-05 18:29:15 -0500600 ]
601 ),
602 ofp.instruction.goto_table(20)
603 ],
604 priority=0)
605 logging.info("Add vlan %d untagged packets on port %d and go to table 20" % (vlan_id, of_port))
606 ctrl.message_send(request)
607 msgs.append(request)
608
macauley97557232015-07-16 17:28:07 +0800609 if send_barrier:
610 do_barrier(ctrl)
611
macauley15909e72015-07-17 15:58:57 +0800612 return msgs
Pierbbdf3782016-08-22 17:58:26 -0700613
macauley_cheng6e6a6122015-11-16 14:19:18 +0800614def del_vlan_table_flow(ctrl, ports, vlan_id=1, flag=VLAN_TABLE_FLAG_ONLY_BOTH, send_barrier=False):
615 # table 10: vlan
616 # goto to table 20
617 msgs=[]
618 for of_port in ports:
619 if (flag == VLAN_TABLE_FLAG_ONLY_TAG) or (flag == VLAN_TABLE_FLAG_ONLY_BOTH):
620 match = ofp.match()
621 match.oxm_list.append(ofp.oxm.in_port(of_port))
622 match.oxm_list.append(ofp.oxm.vlan_vid(0x1000+vlan_id))
623 request = ofp.message.flow_delete(
624 table_id=10,
625 cookie=42,
626 match=match,
627 priority=0)
628 logging.info("Del vlan %d tagged packets on port %d and go to table 20" %( vlan_id, of_port))
629 ctrl.message_send(request)
macauley0f91a3e2015-07-17 18:09:59 +0800630
macauley_cheng6e6a6122015-11-16 14:19:18 +0800631 if (flag == VLAN_TABLE_FLAG_ONLY_UNTAG) or (flag == VLAN_TABLE_FLAG_ONLY_BOTH):
632 match = ofp.match()
633 match.oxm_list.append(ofp.oxm.in_port(of_port))
634 match.oxm_list.append(ofp.oxm.vlan_vid_masked(0, 0xfff))
635 request = ofp.message.flow_delete(
636 table_id=10,
637 cookie=42,
638 match=match,
639 priority=0)
640 logging.info("Del vlan %d untagged packets on port %d and go to table 20" % (vlan_id, of_port))
641 ctrl.message_send(request)
642 msgs.append(request)
643
644 if send_barrier:
645 do_barrier(ctrl)
646
647 return msgs
Pierbbdf3782016-08-22 17:58:26 -0700648
macauley_cheng6b311612015-09-04 11:32:27 +0800649def add_vlan_table_flow_pvid(ctrl, in_port, match_vid=None, pvid=1, send_barrier=False):
650 """it will tag pack as untagged packet wether it has tagg or not"""
651 match = ofp.match()
652 match.oxm_list.append(ofp.oxm.in_port(in_port))
653 actions=[]
654 if match_vid == None:
Pierbbdf3782016-08-22 17:58:26 -0700655 match.oxm_list.append(ofp.oxm.vlan_vid(0))
macauley_cheng6b311612015-09-04 11:32:27 +0800656 actions.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+pvid)))
657 goto_table=20
658 else:
659 match.oxm_list.append(ofp.oxm.vlan_vid_masked(0x1000+match_vid, 0x1fff))
660 actions.append(ofp.action.push_vlan(0x8100))
Pierbbdf3782016-08-22 17:58:26 -0700661 actions.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+pvid)))
macauley_cheng6b311612015-09-04 11:32:27 +0800662 goto_table=20
Pierbbdf3782016-08-22 17:58:26 -0700663
macauley_cheng6b311612015-09-04 11:32:27 +0800664 request = ofp.message.flow_add(
665 table_id=10,
666 cookie=42,
667 match=match,
668 instructions=[
669 ofp.instruction.apply_actions(actions=actions)
670 ,ofp.instruction.goto_table(goto_table)
671 ],
672 priority=0)
673 logging.info("Add PVID %d on port %d and go to table %ld" %( pvid, in_port, goto_table))
Pierbbdf3782016-08-22 17:58:26 -0700674 ctrl.message_send(request)
675
macauley_cheng6b311612015-09-04 11:32:27 +0800676 if send_barrier:
677 do_barrier(ctrl)
678
679def add_vlan_table_flow_allow_all_vlan(ctrl, in_port, send_barrier=False):
680 """it st flow allow all vlan tag on this port"""
681 match = ofp.match()
682 match.oxm_list.append(ofp.oxm.in_port(in_port))
683 match.oxm_list.append(ofp.oxm.vlan_vid_masked(0x1000, 0x1000))
684 request = ofp.message.flow_add(
685 table_id=10,
686 cookie=42,
687 match=match,
688 instructions=[
Pierbbdf3782016-08-22 17:58:26 -0700689 ofp.instruction.goto_table(20)
macauley_cheng6b311612015-09-04 11:32:27 +0800690 ],
691 priority=0)
692 logging.info("Add allow all vlan on port %d " %(in_port))
Pierbbdf3782016-08-22 17:58:26 -0700693 ctrl.message_send(request)
macauley_cheng6b311612015-09-04 11:32:27 +0800694
Pier7b031af2016-08-25 15:00:22 -0700695def 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):
696 # Install a flow for VLAN translation
697 # in VLAN table.
698 # table 10: vlan
699 # goto to table 20
700 if (flag == VLAN_TABLE_FLAG_ONLY_TAG) or (flag == VLAN_TABLE_FLAG_ONLY_BOTH) or (flag == 4):
701 match = ofp.match()
702 match.oxm_list.append(ofp.oxm.in_port(of_port))
703 match.oxm_list.append(ofp.oxm.vlan_vid_masked(0x1000+vlan_id,0x1fff))
704
705 actions=[]
706 if vrf!=0:
707 actions.append(ofp.action.set_field(ofp.oxm.exp2ByteValue(exp_type=1, value=vrf)))
708 if new_vlan_id != -1:
709 actions.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+new_vlan_id)))
710
711 request = ofp.message.flow_add(
712 table_id=10,
713 cookie=42,
714 match=match,
715 instructions=[
716 ofp.instruction.apply_actions(
717 actions=actions
718 ),
719 ofp.instruction.goto_table(20)
720 ],
721 priority=0)
722 logging.info("Add vlan %d tagged packets on port %d and go to table 20" %( vlan_id, of_port))
723 ctrl.message_send(request)
724
Andreas Pantelopoulosf83e0212018-03-18 20:44:05 -0700725
726def add_one_egress_vlan_table_flow(ctrl, of_port, match_vlan, inner_vlan, outer_vlan):
727
728 # used for translating single to double tagged packets only
729
730 match = ofp.match()
731 match.oxm_list.append(ofp.oxm.exp4ByteValue(ofp.oxm.OFDPA_EXP_TYPE_ACTSET_OUTPUT, of_port))
732 match.oxm_list.append(ofp.oxm.exp1ByteValue(ofp.oxm.OFDPA_EXP_TYPE_ALLOW_VLAN_TRANSLATION, 1))
733 match.oxm_list.append(ofp.oxm.vlan_vid_masked(0x1000+match_vlan,0x1fff))
734
735 actions=[]
736 actions.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+inner_vlan)))
737 actions.append(ofp.action.push_vlan(0x8100))
738 actions.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+outer_vlan)))
739
740 request = ofp.message.flow_add(
741 table_id=EGRESS_VLAN_FLOW_TABLE,
742 cookie=42,
743 match=match,
744 instructions=[
745 ofp.instruction.apply_actions(
746 actions=actions
747 ),
748 ofp.instruction.goto_table(EGRESS_DSCP_TABLE)
749 ],
750 priority=0)
751
752 ctrl.message_send(request)
753
754 return
755
Piere1308762016-09-12 15:29:56 -0700756def 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):
Andreas Pantelopoulosf83e0212018-03-18 20:44:05 -0700757
macauley0f91a3e2015-07-17 18:09:59 +0800758 # goto to table 20
Flavio Castro932014b2016-01-05 18:29:15 -0500759 if (flag == VLAN_TABLE_FLAG_ONLY_TAG) or (flag == VLAN_TABLE_FLAG_ONLY_BOTH) or (flag == 4):
macauley0f91a3e2015-07-17 18:09:59 +0800760 match = ofp.match()
761 match.oxm_list.append(ofp.oxm.in_port(of_port))
Flavio Castro12296312015-12-15 17:48:26 -0500762 match.oxm_list.append(ofp.oxm.vlan_vid_masked(0x1000+vlan_id,0x1fff))
macauley7f89d962015-08-06 18:13:48 +0800763
764 actions=[]
Alex Yashchuk9f449462017-12-09 18:27:19 +0200765 if config["switch_type"] != 'xpliant' and vrf != 0:
766 actions.append(ofp.action.set_field(ofp.oxm.exp2ByteValue(exp_type=1, value=vrf)))
Pierbbdf3782016-08-22 17:58:26 -0700767
Flavio Castro6d498522015-12-15 14:05:04 -0500768 #actions.append(ofp.action.set_field(ofp.oxm.vlan_vid(value=vlan_id)))
macauley7f89d962015-08-06 18:13:48 +0800769
macauley0f91a3e2015-07-17 18:09:59 +0800770 request = ofp.message.flow_add(
771 table_id=10,
772 cookie=42,
773 match=match,
774 instructions=[
macauley53d90fe2015-08-04 17:34:22 +0800775 ofp.instruction.apply_actions(
macauley7f89d962015-08-06 18:13:48 +0800776 actions=actions
macauley53d90fe2015-08-04 17:34:22 +0800777 ),
778 ofp.instruction.goto_table(20)
macauley0f91a3e2015-07-17 18:09:59 +0800779 ],
780 priority=0)
781 logging.info("Add vlan %d tagged packets on port %d and go to table 20" %( vlan_id, of_port))
782 ctrl.message_send(request)
Pierbbdf3782016-08-22 17:58:26 -0700783
macauley0f91a3e2015-07-17 18:09:59 +0800784 if (flag == VLAN_TABLE_FLAG_ONLY_UNTAG) or (flag == VLAN_TABLE_FLAG_ONLY_BOTH):
Andreas Pantelopoulosf83e0212018-03-18 20:44:05 -0700785
macauley0f91a3e2015-07-17 18:09:59 +0800786 match = ofp.match()
787 match.oxm_list.append(ofp.oxm.in_port(of_port))
Flavio Castro12296312015-12-15 17:48:26 -0500788 match.oxm_list.append(ofp.oxm.vlan_vid_masked(0, 0x1fff))
Pierbbdf3782016-08-22 17:58:26 -0700789
macauley7f89d962015-08-06 18:13:48 +0800790 actions=[]
791 if vrf!=0:
792 actions.append(ofp.action.set_field(ofp.oxm.exp2ByteValue(exp_type=1, value=vrf)))
Pierbbdf3782016-08-22 17:58:26 -0700793
Andreas Pantelopoulosf83e0212018-03-18 20:44:05 -0700794 # actions.append(ofp.action.push_vlan(0x8100))
Flavio Castro91d1a552016-05-17 16:59:44 -0700795 actions.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+vlan_id)))
Pierbbdf3782016-08-22 17:58:26 -0700796
macauley0f91a3e2015-07-17 18:09:59 +0800797 request = ofp.message.flow_add(
798 table_id=10,
799 cookie=42,
800 match=match,
801 instructions=[
802 ofp.instruction.apply_actions(
macauley7f89d962015-08-06 18:13:48 +0800803 actions=actions
macauley0f91a3e2015-07-17 18:09:59 +0800804 ),
805 ofp.instruction.goto_table(20)
806 ],
807 priority=0)
808 logging.info("Add vlan %d untagged packets on port %d and go to table 20" % (vlan_id, of_port))
809 ctrl.message_send(request)
Pierbbdf3782016-08-22 17:58:26 -0700810
Flavio Castro932014b2016-01-05 18:29:15 -0500811 if (flag == 4) :
812 match = ofp.match()
813 match.oxm_list.append(ofp.oxm.in_port(of_port))
814 match.oxm_list.append(ofp.oxm.vlan_vid_masked(0x1000,0x1fff))
815
816 actions=[]
817 if vrf!=0:
818 actions.append(ofp.action.set_field(ofp.oxm.exp2ByteValue(exp_type=1, value=vrf)))
819
Flavio Castro91d1a552016-05-17 16:59:44 -0700820 actions.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+vlan_id)))
Flavio Castro932014b2016-01-05 18:29:15 -0500821
822 request = ofp.message.flow_add(
823 table_id=10,
824 cookie=42,
825 match=match,
826 instructions=[
827 ofp.instruction.apply_actions(
828 actions=actions
829 ),
830 ofp.instruction.goto_table(20)
831 ],
832 priority=0)
833 logging.info("Add vlan %d tagged packets on port %d and go to table 20" %( vlan_id, of_port))
834 ctrl.message_send(request)
macauley0f91a3e2015-07-17 18:09:59 +0800835
Piere1308762016-09-12 15:29:56 -0700836 if (flag == VLAN_TABLE_FLAG_ONLY_STACKED):
837 # This flag is meant to managed stacked vlan packtes
838 # Matches on outer VLAN_ID, set OVID with outer VLAN.
839 # Finally expose inner VLAN_ID with a pop action and
840 # goto VLAN_1_FLOW_TABLE
841 match = ofp.match()
842 match.oxm_list.append(ofp.oxm.in_port(of_port))
843 match.oxm_list.append(ofp.oxm.vlan_vid_masked(0x1000+vlan_id,0x1fff))
844
845 actions=[]
Andreas Pantelopoulosf83e0212018-03-18 20:44:05 -0700846 # actions.append(ofp.action.set_field(ofp.oxm.exp2ByteValue(exp_type=ofp.oxm.OFDPA_EXP_TYPE_OVID, value=0x1000+vlan_id)))
Piere1308762016-09-12 15:29:56 -0700847 actions.append(ofp.action.pop_vlan())
Andreas Pantelopoulosf83e0212018-03-18 20:44:05 -0700848 actions.append(ofp.action.set_field(ofp.oxm.exp2ByteValue(exp_type=ofp.oxm.OFDPA_EXP_TYPE_OVID, value=0x1000+vlan_id)))
Piere1308762016-09-12 15:29:56 -0700849
850 request = ofp.message.flow_add(
851 table_id=10,
852 cookie=42,
853 match=match,
854 instructions=[
855 ofp.instruction.apply_actions(
856 actions=actions
857 ),
858 ofp.instruction.goto_table(VLAN_1_FLOW_TABLE)
859 ],
860 priority=0)
861 logging.info("Add vlan %d tagged packets on port %d and go to table %d" %( vlan_id, of_port, VLAN_1_FLOW_TABLE))
862 ctrl.message_send(request)
863
864 if (flag == VLAN_TABLE_FLAG_PRIORITY) :
865 match = ofp.match()
866 match.oxm_list.append(ofp.oxm.in_port(of_port))
867 match.oxm_list.append(ofp.oxm.vlan_vid_masked(0x1000, 0x1fff))
868 request = ofp.message.flow_add(
869 table_id=10,
870 cookie=42,
871 match=match,
872 instructions=[
873 ofp.instruction.apply_actions(
874 actions=[
875 ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+vlan_id)),
876 ofp.action.push_vlan(0x8100),
877 ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+out_vlan_id)),
878 ]
879 ),
880 ofp.instruction.goto_table(20)
881 ],
882 priority=0)
883 logging.info("Add vlan %d untagged packets on port %d and go to table 20" % (vlan_id, of_port))
884 ctrl.message_send(request)
885
886 if send_barrier:
887 do_barrier(ctrl)
888
889 return request
890
Piercf76e802016-09-19 20:16:35 -0700891def 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):
892 # table 10: vlan
893 # goto to table 13
894 if flag == VLAN_TABLE_FLAG_ONLY_TAG:
895 match = ofp.match()
896 match.oxm_list.append(ofp.oxm.in_port(of_port))
897 match.oxm_list.append(ofp.oxm.vlan_vid_masked(0x1000+vlan_id, 0x1fff))
898
899 actions=[]
900 if vlan_id == -1:
901 actions.append(ofp.action.pop_vlan())
902 if new_vlan_id > 1:
903 actions.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+new_vlan_id)))
904 actions.append(ofp.action.set_field(ofp.oxm.exp2ByteValue(exp_type=ofp.oxm.OFDPA_EXP_TYPE_MPLS_TYPE, value=ofp.oxm.VPWS)))
905 actions.append(ofp.action.set_field(ofp.oxm.tunnel_id(tunnel_index + ofp.oxm.TUNNEL_ID_BASE)))
906 # 0x0000nnnn is for UNI interfaces
907 actions.append(ofp.action.set_field(ofp.oxm.exp4ByteValue(exp_type=ofp.oxm.OFDPA_EXP_TYPE_MPLS_L2_PORT, value=0x00000000 + of_port)))
908
909 request = ofp.message.flow_add(
910 table_id=10,
911 cookie=42,
912 match=match,
913 instructions=[
914 ofp.instruction.apply_actions(
915 actions=actions
916 ),
917 ofp.instruction.goto_table(MPLS_L2_PORT_FLOW_TABLE)
918 ],
919 priority=0)
920 logging.info("Add vlan %d tagged packets on port %d and go to table %d" % (vlan_id, of_port, MPLS_L2_PORT_FLOW_TABLE))
921 ctrl.message_send(request)
922
923 if flag == VLAN_TABLE_FLAG_ONLY_UNTAG:
924 match = ofp.match()
925 match.oxm_list.append(ofp.oxm.in_port(of_port))
926 match.oxm_list.append(ofp.oxm.vlan_vid(0))
927
928 actions=[]
929 if vlan_id > 1:
Charles Chanc85f1562018-01-18 15:44:29 -0800930 # actions.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+vlan_id)))
931 # actions.append(ofp.action.set_field(ofp.action.push_vlan(0x8100)))
Piercf76e802016-09-19 20:16:35 -0700932 actions.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+vlan_id)))
Charles Chanc85f1562018-01-18 15:44:29 -0800933
Piercf76e802016-09-19 20:16:35 -0700934 actions.append(ofp.action.set_field(ofp.oxm.exp2ByteValue(exp_type=ofp.oxm.OFDPA_EXP_TYPE_MPLS_TYPE, value=ofp.oxm.VPWS)))
935 actions.append(ofp.action.set_field(ofp.oxm.tunnel_id(tunnel_index + ofp.oxm.TUNNEL_ID_BASE)))
936 # 0x0000nnnn is for UNI interfaces
937 actions.append(ofp.action.set_field(ofp.oxm.exp4ByteValue(exp_type=ofp.oxm.OFDPA_EXP_TYPE_MPLS_L2_PORT, value=0x00000000 + of_port)))
938
939 request = ofp.message.flow_add(
940 table_id=10,
941 cookie=42,
942 match=match,
943 instructions=[
944 ofp.instruction.apply_actions(
945 actions=actions
946 ),
947 ofp.instruction.goto_table(MPLS_L2_PORT_FLOW_TABLE)
948 ],
949 priority=0)
950 logging.info("Add vlan %d untagged packets on port %d and go to table %d" % (vlan_id, of_port, MPLS_L2_PORT_FLOW_TABLE))
951 ctrl.message_send(request)
952
953 if send_barrier:
954 do_barrier(ctrl)
955
956 return request
957
Piere1308762016-09-12 15:29:56 -0700958def 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):
Andreas Pantelopoulosf83e0212018-03-18 20:44:05 -0700959
Piere1308762016-09-12 15:29:56 -0700960 # table 11: vlan 1 table
961 # goto to table 20
962 if flag == VLAN_TABLE_FLAG_ONLY_TAG:
963 match = ofp.match()
964 match.oxm_list.append(ofp.oxm.in_port(of_port))
965 match.oxm_list.append(ofp.oxm.vlan_vid_masked(0x1000+inner_vlan_id,0x1fff))
966 match.oxm_list.append(ofp.oxm.exp2ByteValue(ofp.oxm.OFDPA_EXP_TYPE_OVID, 0x1000+outer_vlan_id))
967
968 actions=[]
969 actions.append(ofp.action.push_vlan(0x8100))
970 if new_outer_vlan_id != -1:
971 actions.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+new_outer_vlan_id)))
972 else:
973 actions.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+outer_vlan_id)))
974
975 request = ofp.message.flow_add(
976 table_id=11,
977 cookie=42,
978 match=match,
979 instructions=[
980 ofp.instruction.apply_actions(
981 actions=actions
982 ),
983 ofp.instruction.goto_table(TERMINATION_FLOW_TABLE)
984 ],
985 priority=0)
986 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))
987 ctrl.message_send(request)
988
989 if flag == VLAN_TABLE_FLAG_ONLY_UNTAG:
Andreas Pantelopoulosf83e0212018-03-18 20:44:05 -0700990
Piere1308762016-09-12 15:29:56 -0700991 match = ofp.match()
992 match.oxm_list.append(ofp.oxm.in_port(of_port))
993 match.oxm_list.append(ofp.oxm.vlan_vid_masked(0x1000+inner_vlan_id,0x1fff))
994 match.oxm_list.append(ofp.oxm.exp2ByteValue(ofp.oxm.OFDPA_EXP_TYPE_OVID, 0x1000+outer_vlan_id))
995
996 actions=[]
997 request = ofp.message.flow_add(
998 table_id=11,
999 cookie=42,
1000 match=match,
1001 instructions=[
1002 ofp.instruction.apply_actions(
1003 actions=actions
1004 ),
1005 ofp.instruction.goto_table(TERMINATION_FLOW_TABLE)
1006 ],
1007 priority=0)
1008 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))
1009 ctrl.message_send(request)
1010
Andreas Pantelopoulosf83e0212018-03-18 20:44:05 -07001011 if flag == VLAN_TABLE_FLAG_ONLY_POP_VLAN:
1012
1013 print("INSTALLIN IN TABLE 11!")
1014
1015 match = ofp.match()
1016 match.oxm_list.append(ofp.oxm.in_port(of_port))
1017 match.oxm_list.append(ofp.oxm.vlan_vid_masked(0x1000+inner_vlan_id,0x1fff))
1018 match.oxm_list.append(ofp.oxm.exp2ByteValue(ofp.oxm.OFDPA_EXP_TYPE_OVID, 0x1000+outer_vlan_id))
1019
1020 actions=[]
1021 actions.append(ofp.action.pop_vlan())
1022
1023 request = ofp.message.flow_add(
1024 table_id=11,
1025 cookie=42,
1026 match=match,
1027 instructions=[
1028 ofp.instruction.apply_actions(
1029 actions=actions
1030 ),
1031 ofp.instruction.goto_table(TERMINATION_FLOW_TABLE)
1032 ],
1033 priority=0)
1034 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))
1035 ctrl.message_send(request)
1036
1037
macauley0f91a3e2015-07-17 18:09:59 +08001038 if send_barrier:
1039 do_barrier(ctrl)
1040
1041 return request
Pierbbdf3782016-08-22 17:58:26 -07001042
Piercf76e802016-09-19 20:16:35 -07001043def 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):
Charles Chanc85f1562018-01-18 15:44:29 -08001044
Piercf76e802016-09-19 20:16:35 -07001045 # table 11: vlan 1 table
1046 # goto to table 13
1047 match = ofp.match()
1048 match.oxm_list.append(ofp.oxm.in_port(of_port))
1049 match.oxm_list.append(ofp.oxm.vlan_vid_masked(0x1000+inner_vlan_id,0x1fff))
1050 match.oxm_list.append(ofp.oxm.exp2ByteValue(ofp.oxm.OFDPA_EXP_TYPE_OVID, 0x1000+outer_vlan_id))
1051
1052 actions=[]
1053 actions.append(ofp.action.push_vlan(0x8100))
1054 if new_outer_vlan_id != -1:
Charles Chanc85f1562018-01-18 15:44:29 -08001055 actions.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+new_outer_vlan_id)))
Piercf76e802016-09-19 20:16:35 -07001056 else:
Charles Chanc85f1562018-01-18 15:44:29 -08001057 actions.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+outer_vlan_id)))
Piercf76e802016-09-19 20:16:35 -07001058
1059 actions.append(ofp.action.set_field(ofp.oxm.exp2ByteValue(exp_type=ofp.oxm.OFDPA_EXP_TYPE_MPLS_TYPE, value=ofp.oxm.VPWS)))
1060 actions.append(ofp.action.set_field(ofp.oxm.tunnel_id(tunnel_index + ofp.oxm.TUNNEL_ID_BASE)))
1061 # 0x0000nnnn is for UNI interfaces
1062 actions.append(ofp.action.set_field(ofp.oxm.exp4ByteValue(exp_type=ofp.oxm.OFDPA_EXP_TYPE_MPLS_L2_PORT, value=0x00000000 + of_port)))
1063
1064 request = ofp.message.flow_add(
Charles Chanc85f1562018-01-18 15:44:29 -08001065 table_id=11,
1066 cookie=42,
1067 match=match,
1068 instructions=[
1069 ofp.instruction.apply_actions(
1070 actions=actions
1071 ),
1072 ofp.instruction.goto_table(MPLS_L2_PORT_FLOW_TABLE)
1073 ],
1074 priority=0)
Piercf76e802016-09-19 20:16:35 -07001075 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))
1076 ctrl.message_send(request)
Piercf76e802016-09-19 20:16:35 -07001077 if send_barrier:
1078 do_barrier(ctrl)
1079
1080 return request
1081
macauley97557232015-07-16 17:28:07 +08001082def add_bridge_flow(ctrl, dst_mac, vlanid, group_id, send_barrier=False):
1083 match = ofp.match()
castroflavio21894482015-12-08 15:29:55 -05001084 priority=500
macauleyfddc4662015-07-27 17:40:30 +08001085 if dst_mac!=None:
castroflavio21894482015-12-08 15:29:55 -05001086 priority=1000
macauleyfddc4662015-07-27 17:40:30 +08001087 match.oxm_list.append(ofp.oxm.eth_dst(dst_mac))
1088
macauley97557232015-07-16 17:28:07 +08001089 match.oxm_list.append(ofp.oxm.vlan_vid(0x1000+vlanid))
macauleyfddc4662015-07-27 17:40:30 +08001090
macauley97557232015-07-16 17:28:07 +08001091 request = ofp.message.flow_add(
1092 table_id=50,
1093 cookie=42,
1094 match=match,
1095 instructions=[
1096 ofp.instruction.write_actions(
1097 actions=[
1098 ofp.action.group(group_id)]),
1099 ofp.instruction.goto_table(60)
1100 ],
1101 buffer_id=ofp.OFP_NO_BUFFER,
castroflavio21894482015-12-08 15:29:55 -05001102 priority=priority)
macauley97557232015-07-16 17:28:07 +08001103
1104 logging.info("Inserting Brdige flow vlan %d, mac %s", vlanid, dst_mac)
1105 ctrl.message_send(request)
1106
1107 if send_barrier:
Pierbbdf3782016-08-22 17:58:26 -07001108 do_barrier(ctrl)
macauley15909e72015-07-17 15:58:57 +08001109
Pierbbdf3782016-08-22 17:58:26 -07001110 return request
macauleyfddc4662015-07-27 17:40:30 +08001111
1112def add_overlay_bridge_flow(ctrl, dst_mac, vnid, group_id, is_group=True, send_barrier=False):
1113 match = ofp.match()
1114 if dst_mac!=None:
1115 match.oxm_list.append(ofp.oxm.eth_dst(dst_mac))
1116
1117 match.oxm_list.append(ofp.oxm.tunnel_id(vnid))
1118 if is_group == True:
1119 actions=[ofp.action.group(group_id)]
1120 else:
1121 actions=[ofp.action.output(group_id)]
1122
1123 request = ofp.message.flow_add(
1124 table_id=50,
1125 cookie=42,
1126 match=match,
1127 instructions=[
1128 ofp.instruction.write_actions(
1129 actions=actions),
1130 ofp.instruction.goto_table(60)
1131 ],
1132 buffer_id=ofp.OFP_NO_BUFFER,
Pierbbdf3782016-08-22 17:58:26 -07001133 priority=1000)
macauleyfddc4662015-07-27 17:40:30 +08001134
1135 logging.info("Inserting Brdige flow vnid %d, mac %s", vnid, dst_mac)
1136 ctrl.message_send(request)
1137
1138 if send_barrier:
Pierbbdf3782016-08-22 17:58:26 -07001139 do_barrier(ctrl)
macauleyfddc4662015-07-27 17:40:30 +08001140
Pierbbdf3782016-08-22 17:58:26 -07001141 return request
1142
macauley_cheng6b133662015-11-09 13:52:39 +08001143def add_termination_flow(ctrl, in_port, eth_type, dst_mac, vlanid, goto_table=None, send_barrier=False):
macauley0f91a3e2015-07-17 18:09:59 +08001144 match = ofp.match()
macauley0f91a3e2015-07-17 18:09:59 +08001145 match.oxm_list.append(ofp.oxm.eth_type(eth_type))
macauleyfddc4662015-07-27 17:40:30 +08001146 if dst_mac[0]&0x01 == 0x01:
1147 match.oxm_list.append(ofp.oxm.eth_dst_masked(dst_mac, [0xff, 0xff, 0xff, 0x80, 0x00, 0x00]))
1148 goto_table=40
1149 else:
macauley53d90fe2015-08-04 17:34:22 +08001150 if in_port!=0:
1151 match.oxm_list.append(ofp.oxm.in_port(in_port))
macauleyfddc4662015-07-27 17:40:30 +08001152 match.oxm_list.append(ofp.oxm.eth_dst(dst_mac))
1153 match.oxm_list.append(ofp.oxm.vlan_vid(0x1000+vlanid))
macauley_cheng6b133662015-11-09 13:52:39 +08001154 if goto_table == None:
1155 goto_table=30
macauley0f91a3e2015-07-17 18:09:59 +08001156
1157 request = ofp.message.flow_add(
1158 table_id=20,
1159 cookie=42,
1160 match=match,
1161 instructions=[
1162 ofp.instruction.goto_table(goto_table)
1163 ],
1164 buffer_id=ofp.OFP_NO_BUFFER,
Pierbbdf3782016-08-22 17:58:26 -07001165 priority=1)
macauley0f91a3e2015-07-17 18:09:59 +08001166
1167 logging.info("Inserting termination flow inport %d, eth_type %lx, vlan %d, mac %s", in_port, eth_type, vlanid, dst_mac)
1168 ctrl.message_send(request)
macauley0f91a3e2015-07-17 18:09:59 +08001169 if send_barrier:
Pierbbdf3782016-08-22 17:58:26 -07001170 do_barrier(ctrl)
macauley0f91a3e2015-07-17 18:09:59 +08001171
Pierbbdf3782016-08-22 17:58:26 -07001172 return request
1173
Alex Yashchuk9f449462017-12-09 18:27:19 +02001174def add_unicast_routing_flow(ctrl, eth_type, dst_ip, mask, action_group_id, vrf=0, send_ctrl=False, send_barrier=False, priority = 1):
macauley0f91a3e2015-07-17 18:09:59 +08001175 match = ofp.match()
1176 match.oxm_list.append(ofp.oxm.eth_type(eth_type))
Alex Yashchuk9f449462017-12-09 18:27:19 +02001177 if config["switch_type"] != 'xpliant' and vrf != 0:
macauley53d90fe2015-08-04 17:34:22 +08001178 match.oxm_list.append(ofp.oxm.exp2ByteValue(ofp.oxm.OFDPA_EXP_TYPE_VRF, vrf))
macauley0f91a3e2015-07-17 18:09:59 +08001179
Flavio Castroaf2b4502016-02-02 17:41:32 -05001180 match.oxm_list.append(ofp.oxm.ipv4_dst_masked(dst_ip, mask))
1181
1182 instructions = []
1183 instructions.append(ofp.instruction.goto_table(60))
1184 if send_ctrl:
Pier265ad5f2017-02-28 17:46:28 +01001185 instructions.append(ofp.instruction.write_actions(
Flavio Castroaf2b4502016-02-02 17:41:32 -05001186 actions=[ofp.action.output( port=ofp.OFPP_CONTROLLER,
1187 max_len=ofp.OFPCML_NO_BUFFER)]))
Pierbbdf3782016-08-22 17:58:26 -07001188 else:
Flavio Castroaf2b4502016-02-02 17:41:32 -05001189 instructions.append(ofp.instruction.write_actions(
1190 actions=[ofp.action.group(action_group_id)]))
macauley53d90fe2015-08-04 17:34:22 +08001191
macauley0f91a3e2015-07-17 18:09:59 +08001192 request = ofp.message.flow_add(
1193 table_id=30,
1194 cookie=42,
1195 match=match,
Flavio Castroaf2b4502016-02-02 17:41:32 -05001196 instructions=instructions,
macauley0f91a3e2015-07-17 18:09:59 +08001197 buffer_id=ofp.OFP_NO_BUFFER,
Alex Yashchuk9f449462017-12-09 18:27:19 +02001198 priority=priority)
macauley0f91a3e2015-07-17 18:09:59 +08001199
1200 logging.info("Inserting unicast routing flow eth_type %lx, dip %ld",eth_type, dst_ip)
1201 ctrl.message_send(request)
1202
1203 if send_barrier:
Pierbbdf3782016-08-22 17:58:26 -07001204 do_barrier(ctrl)
macauley0f91a3e2015-07-17 18:09:59 +08001205
Flavio Castro9debaaa2016-07-26 19:37:50 -07001206 return request
Flavio Castrod8f8af22015-12-02 18:19:26 -05001207
Andrea Campanellabfb42b32018-04-26 10:57:23 +02001208def add_unicast_blackhole_flow(ctrl, eth_type, dst_ip, mask, vrf=0, send_ctrl=False, send_barrier=False, priority = 1):
1209 match = ofp.match()
1210 match.oxm_list.append(ofp.oxm.eth_type(eth_type))
1211 if config["switch_type"] != 'xpliant' and vrf != 0:
1212 match.oxm_list.append(ofp.oxm.exp2ByteValue(ofp.oxm.OFDPA_EXP_TYPE_VRF, vrf))
1213
1214 match.oxm_list.append(ofp.oxm.ipv4_dst_masked(dst_ip, mask))
1215
1216 instructions = []
1217 instructions.append(ofp.instruction.goto_table(60))
1218 instructions.append(ofp.instruction.clear_actions( ))
1219
1220 request = ofp.message.flow_add(
1221 table_id=30,
1222 cookie=42,
1223 match=match,
1224 instructions=instructions,
1225 buffer_id=ofp.OFP_NO_BUFFER,
1226 priority=priority)
1227
1228 logging.info("Inserting unicast blackhole routing flow eth_type %lx, dip %ld",eth_type, dst_ip)
1229 ctrl.message_send(request)
1230
1231 if send_barrier:
1232 do_barrier(ctrl)
1233
1234 return request
1235
Pier1e4e98e2016-10-26 14:36:05 -07001236def add_unicast_v6_routing_flow(ctrl, eth_type, dst_ip, mask, action_group_id, vrf=0, send_ctrl=False, send_barrier=False):
1237 match = ofp.match()
1238 match.oxm_list.append(ofp.oxm.eth_type(eth_type))
1239 if vrf != 0:
1240 match.oxm_list.append(ofp.oxm.exp2ByteValue(ofp.oxm.OFDPA_EXP_TYPE_VRF, vrf))
1241
1242 match.oxm_list.append(ofp.oxm.ipv6_dst_masked(parse_ipv6(dst_ip), parse_ipv6(mask)))
1243
1244 instructions = []
1245 instructions.append(ofp.instruction.goto_table(60))
1246 if send_ctrl:
Pier265ad5f2017-02-28 17:46:28 +01001247 instructions.append(ofp.instruction.write_actions(
Pier1e4e98e2016-10-26 14:36:05 -07001248 actions=[ofp.action.output( port=ofp.OFPP_CONTROLLER,
1249 max_len=ofp.OFPCML_NO_BUFFER)]))
1250 else:
1251 instructions.append(ofp.instruction.write_actions(
1252 actions=[ofp.action.group(action_group_id)]))
1253
1254 request = ofp.message.flow_add(
1255 table_id=30,
1256 cookie=42,
1257 match=match,
1258 instructions=instructions,
1259 buffer_id=ofp.OFP_NO_BUFFER,
1260 priority=1)
1261
1262 logging.info("Inserting unicast routing flow eth_type %lx, dip %s",eth_type, dst_ip)
1263 ctrl.message_send(request)
1264
1265 if send_barrier:
1266 do_barrier(ctrl)
1267
1268 return request
1269
Andreas Pantelopoulos6c76b942018-01-22 10:03:02 -08001270def add_mpls_flow(ctrl, action_group_id=0x0, label=100 ,ethertype=0x0800, bos=1, vrf=1, goto_table=27, dec_ttl=False, send_barrier=False):
Flavio Castrob702a2f2016-04-10 22:01:48 -04001271 match = ofp.match()
1272 match.oxm_list.append(ofp.oxm.eth_type(0x8847))
1273 match.oxm_list.append(ofp.oxm.mpls_label(label))
1274 match.oxm_list.append(ofp.oxm.mpls_bos(bos))
Pier265ad5f2017-02-28 17:46:28 +01001275 write_actions = []
1276 write_actions.append(ofp.action.group(action_group_id))
1277 apply_actions = []
1278 apply_actions = [ofp.action.dec_mpls_ttl(),
Flavio Castro8ca52542016-04-11 11:24:49 -04001279 ofp.action.set_field(ofp.oxm.exp2ByteValue(exp_type=1, value=vrf))]
Pier265ad5f2017-02-28 17:46:28 +01001280 if (goto_table != 29):
1281 apply_actions.append(ofp.action.set_field(
Flavio Castrod80fbc32016-07-25 15:54:26 -07001282 ofp.oxm.exp2ByteValue(exp_type=23, value=32)))
Pier265ad5f2017-02-28 17:46:28 +01001283 apply_actions.append(ofp.action.copy_ttl_in())
Flavio Castro9debaaa2016-07-26 19:37:50 -07001284
Flavio Castrob702a2f2016-04-10 22:01:48 -04001285 request = ofp.message.flow_add(
1286 table_id=24,
1287 cookie=43,
1288 match=match,
1289 instructions=[
Pier265ad5f2017-02-28 17:46:28 +01001290 ofp.instruction.apply_actions(actions=apply_actions),
1291 ofp.instruction.write_actions(actions=write_actions),
Flavio Castro8ca52542016-04-11 11:24:49 -04001292 ofp.instruction.goto_table(goto_table)
Flavio Castrob702a2f2016-04-10 22:01:48 -04001293 ],
1294 buffer_id=ofp.OFP_NO_BUFFER,
1295 priority=1)
Flavio Castrob702a2f2016-04-10 22:01:48 -04001296 ctrl.message_send(request)
1297
1298 if send_barrier:
1299 do_barrier(ctrl)
1300
1301 return request
1302
Alex Yashchuk9f449462017-12-09 18:27:19 +02001303def xpliant_add_mpls_flow(ctrl, action_group_id=0x0, label=100 ,ethertype=0x0800, bos=1, vrf=1, goto_table=27, send_barrier=False):
1304 match = ofp.match()
1305 match.oxm_list.append(ofp.oxm.eth_type(0x8847))
1306 match.oxm_list.append(ofp.oxm.mpls_label(label))
1307
1308 apply_actions = []
1309 apply_actions.append(ofp.action.group(action_group_id))
1310 apply_actions.append(ofp.action.dec_mpls_ttl())
1311 if (goto_table != 29):
1312 apply_actions.append(ofp.action.pop_mpls(ethertype))
1313
1314 request = ofp.message.flow_add(
1315 table_id=24,
1316 cookie=43,
1317 match=match,
1318 instructions=[
1319 ofp.instruction.apply_actions(actions=apply_actions),
1320 ],
1321 buffer_id=ofp.OFP_NO_BUFFER,
1322 priority=1)
1323 logging.info("Inserting MPLS flow , label %ld", label)
1324 ctrl.message_send(request)
1325
1326 if send_barrier:
1327 do_barrier(ctrl)
1328
1329 return request
1330
Andreas Pantelopoulos6c76b942018-01-22 10:03:02 -08001331def add_mpls_flow_swap(ctrl, action_group_id, label, ethertype, bos, goto_table=MPLS_TYPE_FLOW_TABLE, of_port=0, send_barrier=False):
1332 match = ofp.match()
1333 match.oxm_list.append(ofp.oxm.eth_type(0x8847))
1334 match.oxm_list.append(ofp.oxm.mpls_label(label))
1335 match.oxm_list.append(ofp.oxm.mpls_bos(1))
1336
1337 apply_actions = []
1338 write_actions = []
1339 apply_actions.append(ofp.action.dec_mpls_ttl())
1340 write_actions.append(ofp.action.group(action_group_id))
1341
1342 request = ofp.message.flow_add(
1343 table_id=24,
1344 cookie=43,
1345 match=match,
1346 instructions=[
1347 ofp.instruction.apply_actions(actions=apply_actions),
1348 ofp.instruction.write_actions(actions=write_actions),
1349 ofp.instruction.goto_table(goto_table)
1350 ],
1351 buffer_id=ofp.OFP_NO_BUFFER,
1352 priority=1)
1353
1354 logging.info("Inserting MPLS flow , label %ld", label)
1355 ctrl.message_send(request)
1356
1357 if send_barrier:
1358 do_barrier(ctrl)
1359
1360 return request
1361
1362
Pierf6f28162016-09-22 16:30:52 -07001363def add_mpls_flow_pw(ctrl, action_group_id, label, ethertype, bos, tunnel_index, goto_table=MPLS_TYPE_FLOW_TABLE, popMPLS=True, popL2=False, of_port=0, send_barrier=False):
Pierb5da4c92016-09-21 11:23:35 -07001364 match = ofp.match()
1365 match.oxm_list.append(ofp.oxm.eth_type(0x8847))
1366 match.oxm_list.append(ofp.oxm.mpls_label(label))
1367 match.oxm_list.append(ofp.oxm.mpls_bos(bos))
1368
Pier265ad5f2017-02-28 17:46:28 +01001369 apply_actions = []
1370 write_actions = []
1371 apply_actions.append(ofp.action.dec_mpls_ttl())
Pierf6f28162016-09-22 16:30:52 -07001372 if popMPLS == True:
Pier265ad5f2017-02-28 17:46:28 +01001373 apply_actions.append(ofp.action.copy_ttl_in())
1374 apply_actions.append(ofp.action.pop_mpls(ethertype))
Pierf6f28162016-09-22 16:30:52 -07001375 if bos==1 and popL2 == True:
Pier265ad5f2017-02-28 17:46:28 +01001376 apply_actions.append(ofp.action.ofdpa_pop_l2_header())
1377 apply_actions.append(ofp.action.ofdpa_pop_cw())
1378 apply_actions.append(ofp.action.set_field(ofp.oxm.tunnel_id(tunnel_index + ofp.oxm.TUNNEL_ID_BASE)))
Pierf6f28162016-09-22 16:30:52 -07001379 # 0x0002nnnn is for UNI interfaces
Pier265ad5f2017-02-28 17:46:28 +01001380 apply_actions.append(ofp.action.set_field(ofp.oxm.exp4ByteValue(exp_type=ofp.oxm.OFDPA_EXP_TYPE_MPLS_L2_PORT, value=0x00020000 + of_port)))
1381 apply_actions.append(ofp.action.set_field(ofp.oxm.exp2ByteValue(exp_type=ofp.oxm.OFDPA_EXP_TYPE_MPLS_TYPE, value=ofp.oxm.VPWS)))
Andreas Pantelopoulosaaa02622018-04-04 15:13:03 -07001382
Pier265ad5f2017-02-28 17:46:28 +01001383 write_actions.append(ofp.action.group(action_group_id))
Pierb5da4c92016-09-21 11:23:35 -07001384
1385 request = ofp.message.flow_add(
Pier265ad5f2017-02-28 17:46:28 +01001386 table_id=24,
1387 cookie=43,
1388 match=match,
1389 instructions=[
1390 ofp.instruction.apply_actions(actions=apply_actions),
1391 ofp.instruction.write_actions(actions=write_actions),
1392 ofp.instruction.goto_table(goto_table)
1393 ],
1394 buffer_id=ofp.OFP_NO_BUFFER,
1395 priority=1)
Pierb5da4c92016-09-21 11:23:35 -07001396 logging.info("Inserting MPLS flow , label %ld", label)
1397 ctrl.message_send(request)
1398
1399 if send_barrier:
1400 do_barrier(ctrl)
1401
1402 return request
1403
macauleyfddc4662015-07-27 17:40:30 +08001404def add_mcast4_routing_flow(ctrl, vlan_id, src_ip, src_ip_mask, dst_ip, action_group_id, send_barrier=False):
1405 match = ofp.match()
1406 match.oxm_list.append(ofp.oxm.eth_type(0x0800))
Alex Yashchuk9f449462017-12-09 18:27:19 +02001407 match.oxm_list.append(ofp.oxm.vlan_vid(0x1000 + vlan_id))
macauleyfddc4662015-07-27 17:40:30 +08001408 if src_ip_mask!=0:
1409 match.oxm_list.append(ofp.oxm.ipv4_src_masked(src_ip, src_ip_mask))
1410 else:
1411 match.oxm_list.append(ofp.oxm.ipv4_src(src_ip))
Pierbbdf3782016-08-22 17:58:26 -07001412
macauleyfddc4662015-07-27 17:40:30 +08001413 match.oxm_list.append(ofp.oxm.ipv4_dst(dst_ip))
Pierbbdf3782016-08-22 17:58:26 -07001414
macauleyfddc4662015-07-27 17:40:30 +08001415 request = ofp.message.flow_add(
1416 table_id=40,
1417 cookie=42,
1418 match=match,
1419 instructions=[
1420 ofp.instruction.write_actions(
1421 actions=[ofp.action.group(action_group_id)]),
1422 ofp.instruction.goto_table(60)
1423 ],
1424 buffer_id=ofp.OFP_NO_BUFFER,
Pierbbdf3782016-08-22 17:58:26 -07001425 priority=1)
macauleyfddc4662015-07-27 17:40:30 +08001426
1427 logging.info("Inserting mcast routing flow eth_type %lx, dip %lx, sip %lx, sip_mask %lx",0x0800, dst_ip, src_ip, src_ip_mask)
1428 ctrl.message_send(request)
1429
1430 if send_barrier:
Pierbbdf3782016-08-22 17:58:26 -07001431 do_barrier(ctrl)
macauleyfddc4662015-07-27 17:40:30 +08001432
Pierbbdf3782016-08-22 17:58:26 -07001433 return request
macauley_cheng6b133662015-11-09 13:52:39 +08001434
Pier1e4e98e2016-10-26 14:36:05 -07001435def add_acl_rule(ctrl, eth_type=None, ip_proto=None, send_barrier=False):
1436 match = ofp.match()
1437 if eth_type != None:
1438 match.oxm_list.append(ofp.oxm.eth_type(eth_type))
1439 if ip_proto != None:
1440 match.oxm_list.append(ofp.oxm.ip_proto(ip_proto))
1441
1442 request = ofp.message.flow_add(
1443 table_id=60,
1444 cookie=42,
1445 match=match,
1446 instructions=[
1447 ofp.instruction.apply_actions(
1448 actions=[ofp.action.output(port=ofp.OFPP_CONTROLLER, max_len=ofp.OFPCML_NO_BUFFER)]
1449 ),
1450 ],
1451 buffer_id=ofp.OFP_NO_BUFFER,
1452 priority=1
1453 )
1454
1455 logging.info("Inserting ACL flow eth_type %lx, ip_proto %ld", eth_type, ip_proto)
1456 ctrl.message_send(request)
1457
1458 if send_barrier:
1459 do_barrier(ctrl)
1460
1461 return request
1462
macauley_cheng6b133662015-11-09 13:52:39 +08001463#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 +08001464def 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 +08001465 match = ofp.match()
1466 match.oxm_list.append(ofp.oxm.eth_type(eth_type))
1467 match.oxm_list.append(ofp.oxm.ipv4_dst(ip_dst))
1468 match.oxm_list.append(ofp.oxm.ip_proto(ip_proto))
1469 match.oxm_list.append(ofp.oxm.tcp_dst(tcp_dst))
Pierbbdf3782016-08-22 17:58:26 -07001470
macauley_cheng6b133662015-11-09 13:52:39 +08001471 request = ofp.message.flow_add(
1472 table_id=28,
1473 cookie=42,
1474 match=match,
1475 instructions=[
1476 ofp.instruction.write_actions(
1477 actions=[ofp.action.set_field(ofp.oxm.ipv4_dst(set_ip_dst)),
1478 ofp.action.set_field(ofp.oxm.tcp_dst(set_tcp_dst)),
1479 ofp.action.group(action_group_id)]),
1480 ofp.instruction.goto_table(60)
1481 ],
1482 buffer_id=ofp.OFP_NO_BUFFER,
Pierbbdf3782016-08-22 17:58:26 -07001483 priority=1)
macauley_cheng6b133662015-11-09 13:52:39 +08001484 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)
1485 ctrl.message_send(request)
1486 return request
macauley_chengeffc20a2015-11-09 16:14:56 +08001487
1488#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
1489def add_snat_flow(ctrl, eth_type, ip_src, ip_proto, tcp_src, set_ip_src, set_tcp_src):
1490 match = ofp.match()
1491 match.oxm_list.append(ofp.oxm.eth_type(eth_type))
1492 match.oxm_list.append(ofp.oxm.ipv4_src(ip_src))
1493 match.oxm_list.append(ofp.oxm.ip_proto(ip_proto))
1494 match.oxm_list.append(ofp.oxm.tcp_src(tcp_src))
Pierbbdf3782016-08-22 17:58:26 -07001495
macauley_chengeffc20a2015-11-09 16:14:56 +08001496 request = ofp.message.flow_add(
1497 table_id=29,
1498 cookie=42,
1499 match=match,
1500 instructions=[
1501 ofp.instruction.write_actions(
1502 actions=[ofp.action.set_field(ofp.oxm.ipv4_src(set_ip_src)),
1503 ofp.action.set_field(ofp.oxm.tcp_src(set_tcp_src))]),
1504 ofp.instruction.goto_table(30)
1505 ],
1506 buffer_id=ofp.OFP_NO_BUFFER,
Pierbbdf3782016-08-22 17:58:26 -07001507 priority=1)
macauley_chengeffc20a2015-11-09 16:14:56 +08001508 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)
1509 ctrl.message_send(request)
1510 return request
Pierbbdf3782016-08-22 17:58:26 -07001511
1512def get_vtap_lport_config_xml(dp_id, lport, phy_port, vlan, vnid, operation='merge'):
macauleyfddc4662015-07-27 17:40:30 +08001513 """
1514 Command Example:
1515 of-agent vtap 10001 ethernet 1/1 vid 1
1516 of-agent vtp 10001 vni 10
1517 """
1518 if vlan != 0:
1519 config_vtap_xml="""
1520 <config>
1521 <capable-switch xmlns="urn:onf:of111:config:yang" xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0">
1522 <id>capable-switch-1</id>
1523 <resources>
1524 <port xc:operation="OPERATION">
Pierbbdf3782016-08-22 17:58:26 -07001525 <resource-id >LPORT</resource-id>
macauleyfddc4662015-07-27 17:40:30 +08001526 <features>
1527 <current>
1528 <rate>10Gb</rate>
1529 <medium>fiber</medium>
Pierbbdf3782016-08-22 17:58:26 -07001530 <pause>symmetric</pause>
macauleyfddc4662015-07-27 17:40:30 +08001531 </current>
1532 <advertised>
1533 <rate>10Gb</rate>
1534 <rate>100Gb</rate>
1535 <medium>fiber</medium>
1536 <pause>symmetric</pause>
Pierbbdf3782016-08-22 17:58:26 -07001537 </advertised>
macauleyfddc4662015-07-27 17:40:30 +08001538 <supported>
1539 <rate>10Gb</rate>
1540 <rate>100Gb</rate>
1541 <medium>fiber</medium>
1542 <pause>symmetric</pause>
Pierbbdf3782016-08-22 17:58:26 -07001543 </supported>
macauleyfddc4662015-07-27 17:40:30 +08001544 <advertised-peer>
1545 <rate>10Gb</rate>
1546 <rate>100Gb</rate>
1547 <medium>fiber</medium>
1548 <pause>symmetric</pause>
Pierbbdf3782016-08-22 17:58:26 -07001549 </advertised-peer>
macauleyfddc4662015-07-27 17:40:30 +08001550 </features>
1551 <ofdpa10:vtap xmlns:ofdpa10="urn:bcm:ofdpa10:accton01" xc:operation="OPERATION">
1552 <ofdpa10:phy-port>PHY_PORT</ofdpa10:phy-port>
1553 <ofdpa10:vid>VLAN_ID</ofdpa10:vid>
1554 <ofdpa10:vni>VNID</ofdpa10:vni>
1555 </ofdpa10:vtap>
Pierbbdf3782016-08-22 17:58:26 -07001556 </port>
macauleyfddc4662015-07-27 17:40:30 +08001557 </resources>
1558 <logical-switches>
1559 <switch>
1560 <id>DATAPATH_ID</id>
1561 <datapath-id>DATAPATH_ID</datapath-id>
1562 <resources>
1563 <port xc:operation="OPERATION">LPORT</port>
1564 </resources>
1565 </switch>
1566 </logical-switches>
1567 </capable-switch>
1568 </config>
Pierbbdf3782016-08-22 17:58:26 -07001569 """
macauleyfddc4662015-07-27 17:40:30 +08001570 else:
1571 config_vtap_xml="""
1572 <config>
1573 <capable-switch xmlns="urn:onf:of111:config:yang" xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0">
1574 <id>capable-switch-1</id>
1575 <resources>
1576 <port xc:operation="OPERATION">
Pierbbdf3782016-08-22 17:58:26 -07001577 <resource-id >LPORT</resource-id>
macauleyfddc4662015-07-27 17:40:30 +08001578 <features>
1579 <current>
1580 <rate>10Gb</rate>
1581 <medium>fiber</medium>
Pierbbdf3782016-08-22 17:58:26 -07001582 <pause>symmetric</pause>
macauleyfddc4662015-07-27 17:40:30 +08001583 </current>
1584 <advertised>
1585 <rate>10Gb</rate>
1586 <rate>100Gb</rate>
1587 <medium>fiber</medium>
1588 <pause>symmetric</pause>
Pierbbdf3782016-08-22 17:58:26 -07001589 </advertised>
macauleyfddc4662015-07-27 17:40:30 +08001590 <supported>
1591 <rate>10Gb</rate>
1592 <rate>100Gb</rate>
1593 <medium>fiber</medium>
1594 <pause>symmetric</pause>
Pierbbdf3782016-08-22 17:58:26 -07001595 </supported>
macauleyfddc4662015-07-27 17:40:30 +08001596 <advertised-peer>
1597 <rate>10Gb</rate>
1598 <rate>100Gb</rate>
1599 <medium>fiber</medium>
1600 <pause>symmetric</pause>
Pierbbdf3782016-08-22 17:58:26 -07001601 </advertised-peer>
macauleyfddc4662015-07-27 17:40:30 +08001602 </features>
1603 <ofdpa10:vtap xmlns:ofdpa10="urn:bcm:ofdpa10:accton01" xc:operation="OPERATION">
1604 <ofdpa10:phy-port>PHY_PORT</ofdpa10:phy-port>
1605 <ofdpa10:vni>VNID</ofdpa10:vni>
1606 </ofdpa10:vtap>
Pierbbdf3782016-08-22 17:58:26 -07001607 </port>
macauleyfddc4662015-07-27 17:40:30 +08001608 </resources>
1609 <logical-switches>
1610 <switch>
1611 <id>DATAPATH_ID</id>
1612 <datapath-id>DATAPATH_ID</datapath-id>
1613 <resources>
1614 <port xc:operation="OPERATION">LPORT</port>
1615 </resources>
1616 </switch>
1617 </logical-switches>
1618 </capable-switch>
1619 </config>
Pierbbdf3782016-08-22 17:58:26 -07001620 """
1621 str_datapath_id_f= "{:016x}".format(dp_id)
1622 str_datapath_id=':'.join([str_datapath_id_f[i:i+2] for i in range(0, len(str_datapath_id_f), 2)])
1623 config_vtap_xml=config_vtap_xml.replace("DATAPATH_ID", str_datapath_id)
1624 config_vtap_xml=config_vtap_xml.replace("LPORT", str(int(lport)))
1625 config_vtap_xml=config_vtap_xml.replace("PHY_PORT", str(phy_port))
1626 config_vtap_xml=config_vtap_xml.replace("VLAN_ID", str(vlan))
macauleyfddc4662015-07-27 17:40:30 +08001627 config_vtap_xml=config_vtap_xml.replace("VNID", str(vnid))
1628 config_vtap_xml=config_vtap_xml.replace("OPERATION", str(operation))
1629 return config_vtap_xml
Pierbbdf3782016-08-22 17:58:26 -07001630
1631def 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 +08001632 """
1633 Command Example:
1634 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 -07001635 of-agent vtp 10001 vni 10
macauleyfddc4662015-07-27 17:40:30 +08001636 """
1637
1638 config_vtep_xml="""
1639 <config>
1640 <capable-switch xmlns="urn:onf:of111:config:yang" xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0">
1641 <id>capable-switch-1</id>
1642 <resources>
1643 <port xc:operation="OPERATION">
Pierbbdf3782016-08-22 17:58:26 -07001644 <resource-id>LPORT</resource-id>
macauleyfddc4662015-07-27 17:40:30 +08001645 <features>
1646 <current>
1647 <rate>10Gb</rate>
1648 <medium>fiber</medium>
Pierbbdf3782016-08-22 17:58:26 -07001649 <pause>symmetric</pause>
macauleyfddc4662015-07-27 17:40:30 +08001650 </current>
1651 <advertised>
1652 <rate>10Gb</rate>
1653 <rate>100Gb</rate>
1654 <medium>fiber</medium>
1655 <pause>symmetric</pause>
Pierbbdf3782016-08-22 17:58:26 -07001656 </advertised>
macauleyfddc4662015-07-27 17:40:30 +08001657 <supported>
1658 <rate>10Gb</rate>
1659 <rate>100Gb</rate>
1660 <medium>fiber</medium>
1661 <pause>symmetric</pause>
Pierbbdf3782016-08-22 17:58:26 -07001662 </supported>
macauleyfddc4662015-07-27 17:40:30 +08001663 <advertised-peer>
1664 <rate>10Gb</rate>
1665 <rate>100Gb</rate>
1666 <medium>fiber</medium>
1667 <pause>symmetric</pause>
Pierbbdf3782016-08-22 17:58:26 -07001668 </advertised-peer>
macauleyfddc4662015-07-27 17:40:30 +08001669 </features>
Pier265ad5f2017-02-28 17:46:28 +01001670 <ofdpa10:vtep xmlns:ofdpa10="urn:bcm:ofdpa10:accton01">
1671 <ofdpa10:src-ip>SRC_IP</ofdpa10:src-ip>
1672 <ofdpa10:dest-ip>DST_IP</ofdpa10:dest-ip>
1673 <ofdpa10:udp-src-port>UDP_SRC_PORT</ofdpa10:udp-src-port>
1674 <ofdpa10:vni xc:operation="OPERATION">
macauley25999cf2015-08-07 17:03:24 +08001675 <ofdpa10:id>VNID</ofdpa10:id>
1676 </ofdpa10:vni>
Pier265ad5f2017-02-28 17:46:28 +01001677 <ofdpa10:nexthop-id>NEXT_HOP_ID</ofdpa10:nexthop-id>
1678 <ofdpa10:ttl>TTL</ofdpa10:ttl>
1679 </ofdpa10:vtep>
Pierbbdf3782016-08-22 17:58:26 -07001680 </port>
macauleyfddc4662015-07-27 17:40:30 +08001681 </resources>
1682 <logical-switches>
1683 <switch>
1684 <id>DATAPATH_ID</id>
1685 <datapath-id>DATAPATH_ID</datapath-id>
1686 <resources>
1687 <port xc:operation="OPERATION">LPORT</port>
1688 </resources>
1689 </switch>
1690 </logical-switches>
1691 </capable-switch>
Pierbbdf3782016-08-22 17:58:26 -07001692 </config>
macauleyfddc4662015-07-27 17:40:30 +08001693 """
Pierbbdf3782016-08-22 17:58:26 -07001694 str_datapath_id_f= "{:016x}".format(dp_id)
1695 str_datapath_id=':'.join([str_datapath_id_f[i:i+2] for i in range(0, len(str_datapath_id_f), 2)])
1696 config_vtep_xml=config_vtep_xml.replace("DATAPATH_ID", str_datapath_id)
macauley25999cf2015-08-07 17:03:24 +08001697 config_vtep_xml=config_vtep_xml.replace("LPORT", str(int(lport)))
Pierbbdf3782016-08-22 17:58:26 -07001698 config_vtep_xml=config_vtep_xml.replace("SRC_IP", str(src_ip))
1699 config_vtep_xml=config_vtep_xml.replace("DST_IP", str(dst_ip))
1700 config_vtep_xml=config_vtep_xml.replace("UDP_SRC_PORT", str(udp_src_port))
1701 config_vtep_xml=config_vtep_xml.replace("NEXT_HOP_ID", str(next_hop_id))
1702 config_vtep_xml=config_vtep_xml.replace("TTL", str(ttl))
macauleyfddc4662015-07-27 17:40:30 +08001703 config_vtep_xml=config_vtep_xml.replace("VNID", str(vnid))
Pierbbdf3782016-08-22 17:58:26 -07001704 config_vtep_xml=config_vtep_xml.replace("OPERATION", str(operation))
macauleyfddc4662015-07-27 17:40:30 +08001705
Pierbbdf3782016-08-22 17:58:26 -07001706 return config_vtep_xml
1707
1708def get_next_hop_config_xml(next_hop_id, dst_mac, phy_port, vlan, operation='merge'):
macauleyfddc4662015-07-27 17:40:30 +08001709 #of-agent nexthop 2 destination user-input-dst-mac ethernet 1/2 vid 2
1710 config_nexthop_xml="""
1711 <config>
1712 <of11-config:capable-switch xmlns:of11-config="urn:onf:of111:config:yang" xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0">
1713 <ofdpa10:next-hop xmlns:ofdpa10="urn:bcm:ofdpa10:accton01" xc:operation="OPERATION">
1714 <ofdpa10:id>NEXT_HOP_ID</ofdpa10:id>
1715 <ofdpa10:dest-mac>DST_MAC</ofdpa10:dest-mac>
1716 <ofdpa10:phy-port>PHY_PORT</ofdpa10:phy-port>
1717 <ofdpa10:vid>VLAN_ID</ofdpa10:vid>
1718 </ofdpa10:next-hop>
1719 </of11-config:capable-switch>
1720 </config>
1721 """
1722 config_nexthop_xml=config_nexthop_xml.replace("VLAN_ID", str(vlan))
Pierbbdf3782016-08-22 17:58:26 -07001723 config_nexthop_xml=config_nexthop_xml.replace("PHY_PORT", str(phy_port))
1724 config_nexthop_xml=config_nexthop_xml.replace("NEXT_HOP_ID", str(next_hop_id))
1725 config_nexthop_xml=config_nexthop_xml.replace("DST_MAC", str(dst_mac))
1726 config_nexthop_xml=config_nexthop_xml.replace("OPERATION", str(operation))
1727 return config_nexthop_xml
macauleyfddc4662015-07-27 17:40:30 +08001728
Pierbbdf3782016-08-22 17:58:26 -07001729def get_vni_config_xml(vni_id, mcast_ipv4, next_hop_id, operation='merge'):
macauleyfddc4662015-07-27 17:40:30 +08001730 #of-agent vni 10 multicast 224.1.1.1 nexthop 20
Pierbbdf3782016-08-22 17:58:26 -07001731 if mcast_ipv4!=None:
macauleyfddc4662015-07-27 17:40:30 +08001732 config_vni_xml="""
1733 <config>
1734 <of11-config:capable-switch xmlns:of11-config="urn:onf:of111:config:yang" xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0">
1735 <ofdpa10:vni xmlns:ofdpa10="urn:bcm:ofdpa10:accton01" xc:operation="OPERATION">
1736 <ofdpa10:id>VNID</ofdpa10:id>
1737 <ofdpa10:vni-multicast-group>MCAST_IP</ofdpa10:vni-multicast-group>
1738 <ofdpa10:multicast-group-nexthop-id>NEXT_HOP_ID</ofdpa10:multicast-group-nexthop-id>
1739 </ofdpa10:vni>
1740 </of11-config:capable-switch>
1741 </config>
Pierbbdf3782016-08-22 17:58:26 -07001742 """
1743 config_vni_xml=config_vni_xml.replace("NEXT_HOP_ID", str(next_hop_id))
1744 config_vni_xml=config_vni_xml.replace("MCAST_IP", str(mcast_ipv4))
macauleyfddc4662015-07-27 17:40:30 +08001745 else:
1746 config_vni_xml="""
1747 <config>
1748 <of11-config:capable-switch xmlns:of11-config="urn:onf:of111:config:yang" xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0">
1749 <ofdpa10:vni xmlns:ofdpa10="urn:bcm:ofdpa10:accton01" xc:operation="OPERATION">
1750 <ofdpa10:id>VNID</ofdpa10:id>
1751 </ofdpa10:vni>
1752 </of11-config:capable-switch>
1753 </config>
Pierbbdf3782016-08-22 17:58:26 -07001754 """
1755
1756 config_vni_xml=config_vni_xml.replace("VNID", str(vni_id))
1757 config_vni_xml=config_vni_xml.replace("OPERATION", str(operation))
macauleyfddc4662015-07-27 17:40:30 +08001758 return config_vni_xml
Pierbbdf3782016-08-22 17:58:26 -07001759
1760def get_featureReplay(self):
macauleyfddc4662015-07-27 17:40:30 +08001761 req = ofp.message.features_request()
1762 res, raw = self.controller.transact(req)
Pierbbdf3782016-08-22 17:58:26 -07001763 self.assertIsNotNone(res, "Did not receive a response from the DUT.")
macauleyfddc4662015-07-27 17:40:30 +08001764 self.assertEqual(res.type, ofp.OFPT_FEATURES_REPLY,
1765 ("Unexpected packet type %d received in response to "
1766 "OFPT_FEATURES_REQUEST") % res.type)
Pierbbdf3782016-08-22 17:58:26 -07001767 return res
1768
macauleyfddc4662015-07-27 17:40:30 +08001769def send_edit_config(switch_ip, xml, target='runing'):
1770 NETCONF_ACCOUNT="netconfuser"
1771 NETCONF_PASSWD="netconfuser"
1772 with manager.connect_ssh(host=switch_ip, port=830, username=NETCONF_ACCOUNT, password=NETCONF_PASSWD, hostkey_verify=False ) as m:
1773 try:
Pierbbdf3782016-08-22 17:58:26 -07001774 m.edit_config(target='running',
1775 config=xml,
1776 default_operation='merge',
macauleyfddc4662015-07-27 17:40:30 +08001777 error_option='stop-on-error')
1778
1779 except Exception as e:
1780 logging.info("Fail to set xml %s", xml)
1781 return False
1782
Pier265ad5f2017-02-28 17:46:28 +01001783 #return m.get_config(source='running').data_xml
macauleyfddc4662015-07-27 17:40:30 +08001784 return True
1785
1786def send_delete_config(switch_ip, xml, target='runing'):
1787 NETCONF_ACCOUNT="netconfuser"
1788 NETCONF_PASSWD="netconfuser"
1789 with manager.connect_ssh(host=switch_ip, port=830, username=NETCONF_ACCOUNT, password=NETCONF_PASSWD, hostkey_verify=False ) as m:
1790 try:
Pierbbdf3782016-08-22 17:58:26 -07001791 m.edit_config(target='running',
1792 config=xml,
1793 default_operation='delete',
macauleyfddc4662015-07-27 17:40:30 +08001794 error_option='stop-on-error')
1795
1796 except Exception as e:
1797 logging.info("Fail to set xml %s", xml)
1798 return False
1799
Pier265ad5f2017-02-28 17:46:28 +01001800 #return m.get_config(source='running').data_xml
macauleyfddc4662015-07-27 17:40:30 +08001801 return True
Pierbbdf3782016-08-22 17:58:26 -07001802
macauleyfddc4662015-07-27 17:40:30 +08001803def get_edit_config(switch_ip, target='runing'):
1804 NETCONF_ACCOUNT="netconfuser"
1805 NETCONF_PASSWD="netconfuser"
1806 with manager.connect_ssh(host=switch_ip, port=830, username=NETCONF_ACCOUNT, password=NETCONF_PASSWD, hostkey_verify=False ) as m:
Pier265ad5f2017-02-28 17:46:28 +01001807 return m.get_config(source='running').data_xml
macauleydbff3272015-07-30 14:07:16 +08001808
macauley_cheng67da9262015-08-31 15:18:41 +08001809
1810"""
1811MPLS
1812"""
1813
1814OFDPA_MPLS_SUBTYPE_SHIFT=24
Pierbbdf3782016-08-22 17:58:26 -07001815OFDPA_MPLS_GROUP_SUBTYPE_L2_VPN_LABEL=1
macauley_cheng67da9262015-08-31 15:18:41 +08001816OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL=2
1817OFDPA_MPLS_GROUP_SUBTYPE_TUNNEL_LABEL1=3
1818OFDPA_MPLS_GROUP_SUBTYPE_TUNNEL_LABEL2=4
1819OFDPA_MPLS_GROUP_SUBTYPE_SWAP_LABEL=5
1820OFDPA_MPLS_GROUP_SUBTYPE_FAST_FAILOVER_GROUP=6
1821OFDPA_MPLS_GROUP_SUBTYPE_ECMP=8
1822OFDPA_MPLS_GROUP_SUBTYPE_L2_TAG=10
1823
Piercf76e802016-09-19 20:16:35 -07001824
1825
1826
macauley_cheng67da9262015-08-31 15:18:41 +08001827def encode_mpls_interface_group_id(subtype, index):
1828 index=index&0x00ffffff
1829 assert(subtype==0)
1830 return index + (9 << OFDPA_GROUP_TYPE_SHIFT)+(subtype<<OFDPA_MPLS_SUBTYPE_SHIFT)
1831
1832def encode_mpls_label_group_id(subtype, index):
1833 index=index&0x00ffffff
1834 assert(subtype <=5 or subtype==0)
1835 #1: l2 vpn label
1836 #2: l3 vpn label
1837 #3: mpls tunnel label 1
1838 #4: mpls tunnel lable 2
1839 #5: mpls swap label
Pierbbdf3782016-08-22 17:58:26 -07001840 return index + (9 << OFDPA_GROUP_TYPE_SHIFT)+(subtype<<OFDPA_MPLS_SUBTYPE_SHIFT)
macauley_cheng67da9262015-08-31 15:18:41 +08001841
1842def encode_mpls_forwarding_group_id(subtype, index):
1843 index=index&0x00ffffff
1844 assert(subtype==6 or subtype==8 or subtype==10)
Pierbbdf3782016-08-22 17:58:26 -07001845 return index + (10 << OFDPA_GROUP_TYPE_SHIFT)+(subtype<<OFDPA_MPLS_SUBTYPE_SHIFT)
macauley_cheng67da9262015-08-31 15:18:41 +08001846
1847
Andreas Pantelopoulosaaa02622018-04-04 15:13:03 -07001848def add_mpls_intf_group(ctrl, ref_gid, dst_mac, src_mac, vid, index, subtype=0, send_barrier=False, add=True):
macauley_cheng67da9262015-08-31 15:18:41 +08001849 action=[]
1850 action.append(ofp.action.set_field(ofp.oxm.eth_src(src_mac)))
1851 action.append(ofp.action.set_field(ofp.oxm.eth_dst(dst_mac)))
Pier265ad5f2017-02-28 17:46:28 +01001852 action.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+vid)))
macauley_cheng67da9262015-08-31 15:18:41 +08001853 action.append(ofp.action.group(ref_gid))
Pierbbdf3782016-08-22 17:58:26 -07001854
macauley_cheng67da9262015-08-31 15:18:41 +08001855 buckets = [ofp.bucket(actions=action)]
1856
1857 mpls_group_id =encode_mpls_interface_group_id(subtype, index)
Andreas Pantelopoulosaaa02622018-04-04 15:13:03 -07001858 if add:
1859 request = ofp.message.group_add(group_type=ofp.OFPGT_INDIRECT,
1860 group_id=mpls_group_id,
1861 buckets=buckets
1862 )
1863 else:
1864 request = ofp.message.group_modify(group_type=ofp.OFPGT_INDIRECT,
1865 group_id=mpls_group_id,
1866 buckets=buckets
1867 )
1868
Andreas Pantelopoulos6c76b942018-01-22 10:03:02 -08001869
1870 logging.debug("Adding MPLS interface group %02x, src_mac %s , dst_mac %s , vid %d", mpls_group_id, src_mac, dst_mac, vid)
macauley_cheng67da9262015-08-31 15:18:41 +08001871 ctrl.message_send(request)
Pier1e4e98e2016-10-26 14:36:05 -07001872
1873 if send_barrier:
1874 do_barrier(ctrl)
macauley_cheng67da9262015-08-31 15:18:41 +08001875 return mpls_group_id, request
1876
Piercf76e802016-09-19 20:16:35 -07001877def add_mpls_tunnel_label_group(
1878 ctrl,
1879 ref_gid,
1880 subtype,
1881 index,
1882 label,
1883 ):
1884
1885 action=[]
1886 action.append(ofp.action.push_mpls(0x8847))
1887 action.append(ofp.action.set_field(ofp.oxm.mpls_label(label)))
1888 action.append(ofp.action.group(ref_gid))
1889 buckets = [ofp.bucket(actions=action)]
1890
1891 mpls_group_id = encode_mpls_label_group_id(subtype, index)
1892 request = ofp.message.group_add(group_type=ofp.OFPGT_INDIRECT,
1893 group_id=mpls_group_id,
1894 buckets=buckets
1895 )
1896 ctrl.message_send(request)
1897
1898 return mpls_group_id, request
1899
Pierb5da4c92016-09-21 11:23:35 -07001900def add_mpls_swap_label_group(
1901 ctrl,
1902 ref_gid,
1903 subtype,
1904 index,
1905 label,
1906 ):
1907
1908 action=[]
1909 action.append(ofp.action.set_field(ofp.oxm.mpls_label(label)))
1910 action.append(ofp.action.group(ref_gid))
1911 buckets = [ofp.bucket(actions=action)]
1912
1913 mpls_group_id = encode_mpls_label_group_id(subtype, index)
1914 request = ofp.message.group_add(group_type=ofp.OFPGT_INDIRECT,
1915 group_id=mpls_group_id,
1916 buckets=buckets
1917 )
Andreas Pantelopoulos6c76b942018-01-22 10:03:02 -08001918 logging.debug("Adding MPLS Swap group %02x, label %d", mpls_group_id, label)
Pierb5da4c92016-09-21 11:23:35 -07001919 ctrl.message_send(request)
1920
1921 return mpls_group_id, request
1922
Pierbbdf3782016-08-22 17:58:26 -07001923def add_mpls_label_group(ctrl, subtype, index, ref_gid,
macauley_cheng67da9262015-08-31 15:18:41 +08001924 lmep_id=-1,
1925 qos_index=-1,
1926 push_l2_header=False,
1927 push_vlan=False,
1928 push_mpls_header=False,
1929 push_cw=False,
1930 set_mpls_label=None,
1931 set_bos=None,
1932 set_tc=None,
1933 set_tc_from_table=False,
1934 cpy_tc_outward=False,
1935 set_ttl=None,
1936 cpy_ttl_outward=False,
1937 oam_lm_tx_count=False,
Pier1e4e98e2016-10-26 14:36:05 -07001938 set_pri_from_table=False,
1939 send_barrier=False
macauley_cheng67da9262015-08-31 15:18:41 +08001940 ):
1941 """
1942 @ref_gid: only can be mpls intf group or mpls tunnel label 1/2 group
Pierbbdf3782016-08-22 17:58:26 -07001943 """
macauley_cheng67da9262015-08-31 15:18:41 +08001944 action=[]
1945
1946 if push_vlan== True:
1947 action.append(ofp.action.push_vlan(0x8100))
1948 if push_mpls_header== True:
1949 action.append(ofp.action.push_mpls(0x8847))
1950 if set_mpls_label != None:
1951 action.append(ofp.action.set_field(ofp.oxm.mpls_label(set_mpls_label)))
1952 if set_bos != None:
1953 action.append(ofp.action.set_field(ofp.oxm.mpls_bos(set_bos)))
1954 if set_tc != None:
1955 assert(set_tc_from_table==False)
1956 action.append(ofp.action.set_field(ofp.oxm.mpls_tc(set_tc)))
1957 if set_ttl != None:
Pierbbdf3782016-08-22 17:58:26 -07001958 action.append(ofp.action.set_mpls_ttl(set_ttl))
macauley_cheng67da9262015-08-31 15:18:41 +08001959 if cpy_ttl_outward == True:
Pierbbdf3782016-08-22 17:58:26 -07001960 action.append(ofp.action.copy_ttl_out())
macauley_cheng67da9262015-08-31 15:18:41 +08001961 """
1962 ofdpa experimenter
Pierbbdf3782016-08-22 17:58:26 -07001963 """
macauley_cheng67da9262015-08-31 15:18:41 +08001964 if push_l2_header== True:
Pierbbdf3782016-08-22 17:58:26 -07001965 action.append(ofp.action.ofdpa_push_l2_header())
macauley_cheng67da9262015-08-31 15:18:41 +08001966 if set_tc_from_table== True:
1967 assert(qos_index>=0)
1968 assert(set_tc == None)
Pierbbdf3782016-08-22 17:58:26 -07001969 action.append(ofp.action.ofdpa_set_tc_from_table(qos_index))
macauley_cheng67da9262015-08-31 15:18:41 +08001970 if cpy_tc_outward == True:
Pierbbdf3782016-08-22 17:58:26 -07001971 action.append(ofp.action.ofdpa_copy_tc_out())
macauley_cheng67da9262015-08-31 15:18:41 +08001972 if oam_lm_tx_count == True:
Pierbbdf3782016-08-22 17:58:26 -07001973 assert(qos_index>=0 and lmep_id>=0)
1974 action.append(ofp.action.ofdpa_oam_lm_tx_count(lmep_id, qos_index))
macauley_cheng67da9262015-08-31 15:18:41 +08001975 if set_pri_from_table == True:
Pierbbdf3782016-08-22 17:58:26 -07001976 assert(qos_index>=0)
1977 action.append(ofp.action.ofdpa_set_qos_from_table(qos_index))
macauley_cheng67da9262015-08-31 15:18:41 +08001978 if push_cw == True:
1979 action.append(ofp.action.ofdpa_push_cw())
Pierbbdf3782016-08-22 17:58:26 -07001980
1981 action.append(ofp.action.group(ref_gid))
macauley_cheng67da9262015-08-31 15:18:41 +08001982 buckets = [ofp.bucket(actions=action)]
Pierbbdf3782016-08-22 17:58:26 -07001983
macauley_cheng67da9262015-08-31 15:18:41 +08001984 mpls_group_id = encode_mpls_label_group_id(subtype, index)
1985 request = ofp.message.group_add(group_type=ofp.OFPGT_INDIRECT,
1986 group_id=mpls_group_id,
1987 buckets=buckets
1988 )
1989 ctrl.message_send(request)
Pierbbdf3782016-08-22 17:58:26 -07001990
Pier1e4e98e2016-10-26 14:36:05 -07001991 if send_barrier:
1992 do_barrier(ctrl)
1993
Pierbbdf3782016-08-22 17:58:26 -07001994 return mpls_group_id, request
1995
Piercf76e802016-09-19 20:16:35 -07001996def add_mpls_l2_port_flow(ctrl, of_port, mpls_l2_port, tunnel_index, ref_gid, qos_index=0):
1997 """
1998 Only action is Group, which must indicate one of:
1999 MPLS L2 VPN Label or Fast Failover Protection Group.
2000 ref_gid contains this information
2001 """
2002 tunnel_id = tunnel_index + ofp.oxm.TUNNEL_ID_BASE
2003
2004 match = ofp.match()
2005 match.oxm_list.append(ofp.oxm.exp4ByteValue(exp_type=ofp.oxm.OFDPA_EXP_TYPE_MPLS_L2_PORT, value=0x00000000 + of_port))
2006 match.oxm_list.append(ofp.oxm.tunnel_id(tunnel_index + ofp.oxm.TUNNEL_ID_BASE))
2007
Pier23784aa2016-09-19 20:08:21 -07002008
Pier265ad5f2017-02-28 17:46:28 +01002009 write_actions = []
2010 write_actions.append(ofp.action.group(ref_gid))
2011 apply_actions = []
Piercf76e802016-09-19 20:16:35 -07002012 assert(qos_index>=0)
Pier265ad5f2017-02-28 17:46:28 +01002013 apply_actions.append(ofp.action.set_field(ofp.oxm.exp1ByteValue(exp_type=ofp.oxm.OFDPA_EXP_TYPE_QOS_INDEX, value=qos_index)))
Piercf76e802016-09-19 20:16:35 -07002014
2015 request = ofp.message.flow_add(
2016 table_id=MPLS_L2_PORT_FLOW_TABLE,
2017 cookie=42,
2018 match=match,
2019 instructions=[
Pier265ad5f2017-02-28 17:46:28 +01002020 ofp.instruction.apply_actions(actions=apply_actions),
2021 ofp.instruction.write_actions(actions=write_actions),
2022 ofp.instruction.goto_table(MPLS_L2_PORT_PCP_TRUST_FLOW_TABLE)
2023 ],
Piercf76e802016-09-19 20:16:35 -07002024 buffer_id=ofp.OFP_NO_BUFFER,
2025 priority=1)
2026 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)
2027 ctrl.message_send(request)
2028 return request
2029
2030 return
2031
Pierbbdf3782016-08-22 17:58:26 -07002032def add_mpls_forwarding_group(ctrl, subtype, index, ref_gids,
2033 watch_port=None,
Pier265ad5f2017-02-28 17:46:28 +01002034 watch_group=ofp.OFPP_ANY,
2035 push_vlan=None,
macauley_chengd17ce512015-08-31 17:45:51 +08002036 pop_vlan=None,
macauley_cheng67da9262015-08-31 15:18:41 +08002037 set_vid=None):
2038 assert(subtype == OFDPA_MPLS_GROUP_SUBTYPE_FAST_FAILOVER_GROUP
Pier265ad5f2017-02-28 17:46:28 +01002039 or subtype == OFDPA_MPLS_GROUP_SUBTYPE_ECMP
2040 or subtype == OFDPA_MPLS_GROUP_SUBTYPE_L2_TAG)
macauley_chengd17ce512015-08-31 17:45:51 +08002041
macauley_cheng67da9262015-08-31 15:18:41 +08002042 buckets=[]
2043 if subtype == OFDPA_MPLS_GROUP_SUBTYPE_FAST_FAILOVER_GROUP:
macauley_chengd17ce512015-08-31 17:45:51 +08002044 group_type = ofp.OFPGT_FF
macauley_cheng67da9262015-08-31 15:18:41 +08002045 for gid in ref_gids:
macauley_chengd17ce512015-08-31 17:45:51 +08002046 action=[]
Pierbbdf3782016-08-22 17:58:26 -07002047 action.append(ofp.action.group(gid))
macauley_chengd17ce512015-08-31 17:45:51 +08002048 buckets.append(ofp.bucket(watch_port=watch_port, watch_group=watch_group,actions=action))
2049
macauley_cheng67da9262015-08-31 15:18:41 +08002050 elif subtype == OFDPA_MPLS_GROUP_SUBTYPE_ECMP:
2051 group_type = ofp.OFPGT_SELECT
2052 for gid in ref_gids:
macauley_chengd17ce512015-08-31 17:45:51 +08002053 action=[]
Pierbbdf3782016-08-22 17:58:26 -07002054 action.append(ofp.action.group(gid))
macauley_cheng67da9262015-08-31 15:18:41 +08002055 buckets.append(ofp.bucket(actions=action))
macauley_chengd17ce512015-08-31 17:45:51 +08002056
macauley_cheng67da9262015-08-31 15:18:41 +08002057 elif subtype == OFDPA_MPLS_GROUP_SUBTYPE_L2_TAG:
2058 group_type = ofp.OFPGT_INDIRECT
macauley_chengd17ce512015-08-31 17:45:51 +08002059 action=[]
macauley_cheng67da9262015-08-31 15:18:41 +08002060 if set_vid!=None:
Flavio Castro91d1a552016-05-17 16:59:44 -07002061 action.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+set_vid)))
macauley_cheng67da9262015-08-31 15:18:41 +08002062 if push_vlan!=None:
Pierbbdf3782016-08-22 17:58:26 -07002063 action.append(ofp.action.push_vlan(push_vlan))
macauley_cheng67da9262015-08-31 15:18:41 +08002064 if pop_vlan!=None:
Pierbbdf3782016-08-22 17:58:26 -07002065 action.append(ofp.action.pop_vlan())
2066 action.append(ofp.action.group(ref_gids[0]))
macauley_cheng67da9262015-08-31 15:18:41 +08002067 buckets.append(ofp.bucket(actions=action))
macauley_chengd17ce512015-08-31 17:45:51 +08002068
2069 mpls_group_id = encode_mpls_forwarding_group_id(subtype, index)
macauley_cheng67da9262015-08-31 15:18:41 +08002070 request = ofp.message.group_add(group_type=group_type,
macauley_cheng67da9262015-08-31 15:18:41 +08002071 group_id=mpls_group_id,
2072 buckets=buckets
2073 )
2074 ctrl.message_send(request)
Pierbbdf3782016-08-22 17:58:26 -07002075 return mpls_group_id, request
macauley_chengd17ce512015-08-31 17:45:51 +08002076
Jonghwan Hyunff0dfd52018-03-20 15:04:35 -07002077def add_one_egress_vlan_tpid_table_flow(ctrl, of_port):
2078 # Used for changing ethertype of outer vlan header to 0x88a8
2079
2080 match = ofp.match()
2081 match.oxm_list.append(ofp.oxm.exp4ByteValue(ofp.oxm.OFDPA_EXP_TYPE_ACTSET_OUTPUT, of_port, ONF_EXPERIMENTER_ID))
2082 match.oxm_list.append(ofp.oxm.vlan_vid_masked(ofp.OFPVID_PRESENT, ofp.OFPVID_PRESENT))
2083
2084 actions = []
2085 actions.append(ofp.action.copy_field(
2086 12, 0, 0, ['\x80\x00\x0c\x02', ofp.oxm.exp4ByteReg(oxm_field = 1).pack()])) # VLAN_VID, PACKET_REG(1)
2087 actions.append(ofp.action.pop_vlan())
2088 actions.append(ofp.action.push_vlan(0x88a8))
2089 actions.append(ofp.action.copy_field(
2090 12, 0, 0, [ofp.oxm.exp4ByteReg(oxm_field = 1).pack(), '\x80\x00\x0c\x02'])) # PACKET_REG(1), VLAN_VID
2091
2092 request = ofp.message.flow_add(
2093 table_id=EGRESS_TPID_FLOW_TABLE,
2094 cookie=42,
2095 match=match,
2096 instructions=[
2097 ofp.instruction.apply_actions(
2098 actions=actions
2099 ),
2100 ],
2101 priority=0)
2102
2103 ctrl.message_send(request)
2104
2105 return
macauley_chengd17ce512015-08-31 17:45:51 +08002106
macauley_cheng67da9262015-08-31 15:18:41 +08002107"""
Piercf76e802016-09-19 20:16:35 -07002108display
Pierbbdf3782016-08-22 17:58:26 -07002109"""
macauleydbff3272015-07-30 14:07:16 +08002110def print_current_table_flow_stat(ctrl, table_id=0xff):
2111 stat_req=ofp.message.flow_stats_request()
2112 response, pkt = ctrl.transact(stat_req)
2113 if response == None:
2114 print "no response"
2115 return None
2116 print len(response.entries)
2117 for obj in response.entries:
2118 print "match ", obj.match
2119 print "cookie", obj.cookie
2120 print "priority", obj.priority
2121 print "idle_timeout", obj.idle_timeout
2122 print "hard_timeout", obj.hard_timeout
2123 #obj.actions
Flavio Castro167f5bd2015-12-02 19:33:53 -05002124 print "packet count: %lx"%obj.packet_count