blob: ebc168d0d3da18fb3462ab74718892b2d56e90ca [file] [log] [blame]
Matteo Scandoloa229eca2017-08-08 13:05:28 -07001
2# Copyright 2017-present Open Networking Foundation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16
Pierbbdf3782016-08-22 17:58:26 -070017import Queue
Piercf76e802016-09-19 20:16:35 -070018import itertools
Pierbbdf3782016-08-22 17:58:26 -070019
20from oftest.testutils import *
21from accton_util import *
22
Piercf76e802016-09-19 20:16:35 -070023"""
24MISC
25"""
26
27def print_port_stats(test, port):
28 entries = get_port_stats(test, port)
29 for item in entries:
30 packet_rcv = item.rx_packets
31 packet_rcv_dropped = item.rx_dropped
32 packet_rcv_errors = item.rx_errors
33
34 packet_sent = item.tx_packets
35 packet_sent_dropped = item.tx_dropped
36 packet_sent_errors = item.tx_errors
37
Pier1e4e98e2016-10-26 14:36:05 -070038 print "\nPort %d stats count: tx %d rx %d - tx_dropped %d rx_dropped %d - tx_errors %d rx_errors %d" % (
Piercf76e802016-09-19 20:16:35 -070039 port, packet_sent, packet_rcv, packet_sent_dropped, packet_rcv_dropped, packet_sent_errors, packet_rcv_errors
40 )
41
42def filter_dhcp(controller):
43 match = ofp.match( )
44 match.oxm_list.append( ofp.oxm.eth_type( 0x0800 ) )
45 match.oxm_list.append( ofp.oxm.ip_proto( 17 ) )
46 match.oxm_list.append( ofp.oxm.udp_src( 68 ) )
47 match.oxm_list.append( ofp.oxm.udp_dst( 67 ))
48 request = ofp.message.flow_add(
49 table_id=60,
50 cookie=42,
51 match=match,
52 instructions=[ofp.instruction.clear_actions( )],
53 buffer_id=ofp.OFP_NO_BUFFER,
54 priority=1
55 )
56 controller.message_send( request )
57 do_barrier( controller )
58
59def filter_ipv6(controller):
60 match = ofp.match( )
61 match.oxm_list.append( ofp.oxm.eth_type( 0x86dd ) )
62 request = ofp.message.flow_add(
63 table_id=60,
64 cookie=42,
65 match=match,
66 instructions=[ofp.instruction.clear_actions( )],
67 buffer_id=ofp.OFP_NO_BUFFER,
68 priority=1
69 )
70 controller.message_send( request )
71 do_barrier( controller )
72
73def filter_igmp(controller):
74 match = ofp.match( )
75 match.oxm_list.append( ofp.oxm.eth_type( 0x0800 ) )
76 match.oxm_list.append( ofp.oxm.ip_proto( 2 ) )
77 request = ofp.message.flow_add(
78 table_id=60,
79 cookie=42,
80 match=match,
81 instructions=[ofp.instruction.clear_actions( )],
82 buffer_id=ofp.OFP_NO_BUFFER,
83 priority=1
84 )
85 controller.message_send( request )
86 do_barrier( controller )
87
Piercf76e802016-09-19 20:16:35 -070088"""
89MULTICAST Pipelines
90"""
91
Pier7b031af2016-08-25 15:00:22 -070092def fill_mcast_pipeline_L3toL2(
93 controller,
94 logging,
95 ports,
96 is_ingress_tagged,
97 is_egress_tagged,
98 is_vlan_translated,
99 is_max_vlan
100 ):
101 """
102 This method, according to the scenario, fills properly
103 the pipeline. The method generates using ports data the
104 necessary information to fill the multicast pipeline and
105 fills properly the pipeline which consists in this scenario:
106
107 i) to create l2 interface groups;
108 ii) to create l3 multicast groups;
109 iii) to add multicast flows;
110 iv) to add termination; flows;
111 v) to add vlan flows
112
113 Scenarios:
114 1) ingress untagged, egress untagged
115 2) ingress untagged, egress tagged
116 3) ingress tagged, egress untagged
117 4) ingress tagged, egress tagged, no translation
118 5) ingress tagged, egress tagged, translation
119 """
120
121 MAX_INTERNAL_VLAN = 4094
122 # Used for no translation
123 FIXED_VLAN = 300
124 Groups = Queue.LifoQueue( )
125 L2_Groups = []
126 port_to_in_vlan = {}
127 port_to_out_vlan = {}
128 port_to_src_mac = {}
129 port_to_src_mac_str = {}
130 port_to_dst_mac = {}
131 port_to_dst_mac_str = {}
132 port_to_src_ip = {}
133 port_to_src_ip_str = {}
134 src_ip_0 = 0xc0a80100
135 src_ip_0_str = "192.168.1.%s"
136 dst_ip = 0xe0000001
137 switch_mac = [ 0x01, 0x00, 0x5e, 0x00, 0x00, 0x00 ]
138
139 for port in ports:
140 in_vlan_id = port + 1
141 out_vlan_id = MAX_INTERNAL_VLAN - port
142 if is_max_vlan and not is_vlan_translated:
143 in_vlan_id = MAX_INTERNAL_VLAN
144 out_vlan_id = MAX_INTERNAL_VLAN
145 elif not is_max_vlan and not is_vlan_translated:
146 in_vlan_id = FIXED_VLAN
147 out_vlan_id = FIXED_VLAN
148 src_mac = [ 0x00, 0x11, 0x11, 0x11, 0x11, port ]
149 src_mac_str = ':'.join( [ '%02X' % x for x in src_mac ] )
150 dst_mac = [ 0x01, 0x00, 0x5e, 0x01, 0x01, port ]
151 dst_mac_str = ':'.join( [ '%02X' % x for x in dst_mac ] )
152 src_ip = src_ip_0 + port
153 src_ip_str = src_ip_0_str % port
154 port_to_in_vlan[port] = in_vlan_id
155 port_to_out_vlan[port] = out_vlan_id
156 port_to_src_mac[port] = src_mac
157 port_to_src_mac_str[port] = src_mac_str
158 port_to_dst_mac[port] = dst_mac
159 port_to_dst_mac_str[port] = dst_mac_str
160 port_to_src_ip[port] = src_ip
161 port_to_src_ip_str[port] = src_ip_str
162
163 for in_port in ports:
164
165 L2_Groups = []
166 # add vlan flows table
Pier265ad5f2017-02-28 17:46:28 +0100167 add_one_vlan_table_flow( controller, in_port, 1, port_to_in_vlan[in_port], flag=VLAN_TABLE_FLAG_ONLY_TAG )
Pier7b031af2016-08-25 15:00:22 -0700168 if not is_ingress_tagged:
Pier265ad5f2017-02-28 17:46:28 +0100169 add_one_vlan_table_flow( controller, in_port, 1, port_to_in_vlan[in_port], flag=VLAN_TABLE_FLAG_ONLY_UNTAG )
Pier7b031af2016-08-25 15:00:22 -0700170 elif is_vlan_translated:
171 add_one_vlan_table_flow_translation( controller, in_port, port_to_in_vlan[in_port], port_to_out_vlan[in_port], flag=VLAN_TABLE_FLAG_ONLY_TAG)
172 # add termination flow
173 if not is_vlan_translated:
174 add_termination_flow( controller, in_port, 0x0800, switch_mac, port_to_in_vlan[in_port] )
175 else:
176 add_termination_flow( controller, in_port, 0x0800, switch_mac, port_to_out_vlan[in_port] )
177
178 for out_port in ports:
179 if out_port == in_port:
180 continue
181 # add l2 interface group, vlan_id equals for each port and must coincide with mcast_group vlan_id
182 if not is_vlan_translated:
183 l2gid, msg = add_one_l2_interface_group( controller, out_port, vlan_id=port_to_in_vlan[in_port],
184 is_tagged=is_egress_tagged, send_barrier=True )
185 else:
186 l2gid, msg = add_one_l2_interface_group( controller, out_port, vlan_id=port_to_out_vlan[in_port],
187 is_tagged=is_egress_tagged, send_barrier=True )
188 Groups._put( l2gid )
189 L2_Groups.append( l2gid )
190
191 # add l3 mcast group
192 if not is_vlan_translated:
193 mcat_group_msg = add_l3_mcast_group( controller, port_to_in_vlan[in_port], in_port, L2_Groups )
194 else:
195 mcat_group_msg = add_l3_mcast_group( controller, port_to_out_vlan[in_port], in_port, L2_Groups )
196 Groups._put( mcat_group_msg.group_id )
197 # add mcast routing flow
198 if not is_vlan_translated:
199 add_mcast4_routing_flow( controller, port_to_in_vlan[in_port], port_to_src_ip[in_port], 0, dst_ip, mcat_group_msg.group_id )
200 else:
201 add_mcast4_routing_flow( controller, port_to_out_vlan[in_port], port_to_src_ip[in_port], 0, dst_ip, mcat_group_msg.group_id )
202
203 return (
204 port_to_in_vlan,
205 port_to_out_vlan,
206 port_to_src_mac_str,
207 port_to_dst_mac_str,
Andrea Campanella0ea96322018-04-19 19:11:49 +0200208 port_to_src_ip,
Pier7b031af2016-08-25 15:00:22 -0700209 port_to_src_ip_str,
210 Groups
211 )
212
Pierbbdf3782016-08-22 17:58:26 -0700213def fill_mcast_pipeline_L3toL3(
214 controller,
215 logging,
216 ports,
217 is_ingress_tagged,
218 is_egress_tagged,
219 is_vlan_translated,
220 is_max_vlan
221 ):
222 """
223 This method, according to the scenario, fills properly
224 the pipeline. The method generates using ports data the
225 necessary information to fill the multicast pipeline and
226 fills properly the pipeline which consists in this scenario:
227
228 i) to create l2 interface groups;
229 ii)to create l3 interface groups;
230 iii) to create l3 multicast groups;
231 iv) to add multicast flows;
232 v) to add termination; flows;
233 vi) to add vlan flows
234
235 Scenarios:
236 1) ingress tagged, egress tagged, translation
237 """
238
239 Groups = Queue.LifoQueue( )
240 MAX_INTERNAL_VLAN = 4094
241 port_to_in_vlan = {}
242 port_to_out_vlan = {}
243 port_to_src_mac = {}
244 port_to_src_mac_str = {}
245 port_to_dst_mac = {}
246 port_to_dst_mac_str = {}
247 port_to_src_ip = {}
248 port_to_src_ip_str = {}
249 port_to_intf_src_mac = {}
250 port_to_intf_src_mac_str = {}
251 src_ip_0 = 0xc0a80100
252 src_ip_0_str = "192.168.1.%s"
253 dst_ip = 0xe0000001
254 switch_mac = [ 0x01, 0x00, 0x5e, 0x00, 0x00, 0x00 ]
255
256 for port in ports:
257 in_vlan_id = port + 1
258 out_vlan_id = MAX_INTERNAL_VLAN - port
259 src_mac = [ 0x00, 0x11, 0x11, 0x11, 0x11, port ]
260 src_mac_str = ':'.join( [ '%02X' % x for x in src_mac ] )
261 dst_mac = [ 0x01, 0x00, 0x5e, 0x01, 0x01, port ]
262 dst_mac_str = ':'.join( [ '%02X' % x for x in dst_mac ] )
263 src_ip = src_ip_0 + port
264 src_ip_str = src_ip_0_str % port
265 intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, port ]
266 intf_src_mac_str = ':'.join( [ '%02X' % x for x in intf_src_mac ] )
267 port_to_in_vlan[port] = in_vlan_id
268 port_to_out_vlan[port] = out_vlan_id
269 port_to_src_mac[port] = src_mac
270 port_to_src_mac_str[port] = src_mac_str
271 port_to_dst_mac[port] = dst_mac
272 port_to_dst_mac_str[port] = dst_mac_str
273 port_to_src_ip[port] = src_ip
274 port_to_src_ip_str[port] = src_ip_str
275 port_to_intf_src_mac[port] = intf_src_mac
276 port_to_intf_src_mac_str[port] = intf_src_mac_str
277
278 for port in ports:
279 L3_Groups = []
280 for other_port in ports:
281 # add l2 interface group
282 l2gid, msg = add_one_l2_interface_group( controller, other_port, vlan_id=port_to_out_vlan[other_port],
Tony Choud6195802018-06-01 11:52:26 +0800283 is_tagged=True, send_barrier=True )
Pierbbdf3782016-08-22 17:58:26 -0700284 Groups._put( l2gid )
285 # add l3 interface group
286 l3group_ucast_msg = add_l3_interface_group( controller, other_port, port_to_out_vlan[other_port], port_to_in_vlan[other_port],
287 port_to_intf_src_mac[other_port] )
288 L3_Groups.append(l3group_ucast_msg.group_id)
289 Groups._put( l3group_ucast_msg.group_id )
290
291 # add mcast group
292 mcat_group_msg = add_l3_mcast_group( controller, port_to_in_vlan[port], port_to_in_vlan[port], L3_Groups )
Andrea Campanella84ebbf22018-05-10 16:15:57 +0200293 do_barrier(controller)
Pierbbdf3782016-08-22 17:58:26 -0700294 Groups._put( mcat_group_msg.group_id )
295 # add mcast flow
Andrea Campanella84ebbf22018-05-10 16:15:57 +0200296 add_mcast4_routing_flow( controller, port_to_in_vlan[port], port_to_src_ip[port], 0, dst_ip, mcat_group_msg.group_id, True )
Pierbbdf3782016-08-22 17:58:26 -0700297 # add termination flow
298 add_termination_flow( controller, port, 0x0800, switch_mac, port_to_in_vlan[port] )
299 # add vlan flow table
Pier265ad5f2017-02-28 17:46:28 +0100300 add_one_vlan_table_flow( controller, port, 1, port_to_in_vlan[port], flag=VLAN_TABLE_FLAG_ONLY_TAG )
Pierbbdf3782016-08-22 17:58:26 -0700301
302 return (
303 port_to_in_vlan,
304 port_to_out_vlan,
305 port_to_src_mac_str,
306 port_to_dst_mac_str,
Andrea Campanella0ea96322018-04-19 19:11:49 +0200307 port_to_src_ip,
Pierbbdf3782016-08-22 17:58:26 -0700308 port_to_src_ip_str,
309 port_to_intf_src_mac_str,
310 Groups
Piercf76e802016-09-19 20:16:35 -0700311 )
312
313"""
314VPWS Pipeline
315"""
316
317OF_DPA_MPLS_L2_VPN_Label = 1
318OF_DPA_MPLS_Tunnel_Label_1 = 3
319OF_DPA_MPLS_Tunnel_Label_2 = 4
320
321EGRESS_UNTAGGED = 1
322EGRESS_TAGGED = 2
323EGRESS_TAGGED_TRANS = 3
324
325
326def fill_pw_initiation_pipeline(
327 controller,
328 logging,
329 in_port,
330 out_port,
331 ingress_tags,
332 egress_tag,
333 mpls_labels
334 ):
335 """
336 This method, according to the scenario, fills properly
337 the pw pipeline. The method generates using ports data the
338 necessary information to fill the pw pipeline and
339 fills properly the pipeline which consists into:
340
341 """
342
343 Groups = Queue.LifoQueue( )
344 out_vlan = 4094
345 port_to_in_vlan_1 = {}
346 port_to_in_vlan_2 = {}
347 port_to_in_vlan_3 = {}
348 port_to_src_mac = {}
349 port_to_src_mac_str = {}
350 port_to_dst_mac = {}
351 port_to_dst_mac_str = {}
Piercf76e802016-09-19 20:16:35 -0700352 port_to_mpls_label_1 = {}
353 port_to_mpls_label_2 = {}
354 port_to_mpls_label_pw = {}
355 ports = [in_port, out_port]
356
357 for port in ports:
358 in_vlan_id_1 = port + 1
359 in_vlan_id_2 = port + 100
360 in_vlan_id_3 = port + 300
361 mpls_label_1 = port + 100
362 mpls_label_2 = port + 200
363 mpls_label_pw = port + 300
364 port_to_in_vlan_1[port] = in_vlan_id_1
365 port_to_in_vlan_2[port] = in_vlan_id_2
366 port_to_in_vlan_3[port] = in_vlan_id_3
367 src_mac = [ 0x00, 0x00, 0x00, 0x00, 0x11, port ]
368 src_mac_str = ':'.join( [ '%02X' % x for x in src_mac ] )
369 dst_mac = [ 0x00, 0x00, 0x00, 0x11, 0x11, port ]
370 dst_mac_str = ':'.join( [ '%02X' % x for x in dst_mac ] )
371 port_to_src_mac[port] = src_mac
372 port_to_src_mac_str[port] = src_mac_str
373 port_to_dst_mac[port] = dst_mac
374 port_to_dst_mac_str[port] = dst_mac_str
375 port_to_mpls_label_1[port] = mpls_label_1
376 port_to_mpls_label_2[port] = mpls_label_2
377 port_to_mpls_label_pw[port] = mpls_label_pw
378
379 # add l2 interface group, we have to pop the VLAN;
380 l2_intf_gid, l2_intf_msg = add_one_l2_interface_group(
381 ctrl=controller,
382 port=out_port,
383 vlan_id=out_vlan,
384 is_tagged=False,
385 send_barrier=False
386 )
387 Groups._put( l2_intf_gid )
388 # add MPLS interface group
389 mpls_intf_gid, mpls_intf_msg = add_mpls_intf_group(
390 ctrl=controller,
391 ref_gid=l2_intf_gid,
392 dst_mac=port_to_dst_mac[in_port],
393 src_mac=port_to_src_mac[out_port],
394 vid=out_vlan,
395 index=in_port
396 )
397 Groups._put( mpls_intf_gid )
398 mpls_gid = mpls_intf_gid
399 # add MPLS tunnel label groups, the number depends on the labels
400 if mpls_labels == 2:
401 mpls_tunnel_gid, mpls_tunnel_msg = add_mpls_tunnel_label_group(
402 ctrl=controller,
403 ref_gid=mpls_intf_gid,
404 subtype=OF_DPA_MPLS_Tunnel_Label_2,
405 index=in_port,
406 label=port_to_mpls_label_2[in_port]
407 )
408 Groups._put( mpls_tunnel_gid )
409 mpls_tunnel_gid, mpls_tunnel_msg = add_mpls_tunnel_label_group(
410 ctrl=controller,
411 ref_gid=mpls_tunnel_gid,
412 subtype=OF_DPA_MPLS_Tunnel_Label_1,
413 index=in_port,
414 label=port_to_mpls_label_1[in_port]
415 )
416 Groups._put( mpls_tunnel_gid )
417 mpls_gid = mpls_tunnel_gid
418 elif mpls_labels == 1:
419 mpls_tunnel_gid, mpls_tunnel_msg = add_mpls_tunnel_label_group(
420 ctrl=controller,
421 ref_gid=mpls_intf_gid,
422 subtype=OF_DPA_MPLS_Tunnel_Label_1,
423 index=in_port,
424 label=port_to_mpls_label_1[in_port]
425 )
426 Groups._put( mpls_tunnel_gid )
427 mpls_gid = mpls_tunnel_gid
Piercf76e802016-09-19 20:16:35 -0700428 # add MPLS L2 VPN group
429 mpls_l2_vpn_gid, mpls_l2_vpn_msg = add_mpls_label_group(
430 ctrl=controller,
431 subtype=OF_DPA_MPLS_L2_VPN_Label,
432 index=in_port,
433 ref_gid=mpls_gid,
434 push_l2_header=True,
435 push_vlan=True,
436 push_mpls_header=True,
437 push_cw=True,
438 set_mpls_label=port_to_mpls_label_pw[in_port],
439 set_bos=1,
440 cpy_ttl_outward=True
441 )
Piercf76e802016-09-19 20:16:35 -0700442 Groups._put( mpls_l2_vpn_gid )
443 # add MPLS L2 port flow
444 add_mpls_l2_port_flow(
445 ctrl=controller,
446 of_port=in_port,
447 mpls_l2_port=in_port,
448 tunnel_index=1,
449 ref_gid=mpls_l2_vpn_gid
450 )
451 # add VLAN flows table
452 if ingress_tags == 2:
453 if egress_tag == EGRESS_TAGGED:
454 add_one_vlan_1_table_flow_pw(
455 ctrl=controller,
456 of_port=in_port,
457 tunnel_index=1,
458 new_outer_vlan_id=-1,
459 outer_vlan_id=port_to_in_vlan_2[in_port],
460 inner_vlan_id=port_to_in_vlan_1[in_port],
461 )
462 elif egress_tag == EGRESS_TAGGED_TRANS:
463 add_one_vlan_1_table_flow_pw(
464 ctrl=controller,
465 of_port=in_port,
466 tunnel_index=1,
467 new_outer_vlan_id=port_to_in_vlan_3[in_port],
468 outer_vlan_id=port_to_in_vlan_2[in_port],
469 inner_vlan_id=port_to_in_vlan_1[in_port],
470 )
471 add_one_vlan_table_flow(
472 ctrl=controller,
473 of_port=in_port,
474 vlan_id=port_to_in_vlan_2[in_port],
475 flag=VLAN_TABLE_FLAG_ONLY_STACKED,
476 )
477 elif ingress_tags == 1:
478 if egress_tag == EGRESS_TAGGED:
479 add_one_vlan_table_flow_pw(
480 ctrl=controller,
481 of_port=in_port,
482 tunnel_index=1,
483 vlan_id=port_to_in_vlan_1[in_port],
484 flag=VLAN_TABLE_FLAG_ONLY_TAG,
485 )
486 elif egress_tag == EGRESS_TAGGED_TRANS:
487 add_one_vlan_table_flow_pw(
488 ctrl=controller,
489 of_port=in_port,
490 tunnel_index=1,
491 vlan_id=port_to_in_vlan_1[in_port],
492 new_vlan_id=port_to_in_vlan_3[in_port],
493 flag=VLAN_TABLE_FLAG_ONLY_TAG,
494 )
495 elif ingress_tags == 0:
496 filter_dhcp(controller)
497 filter_ipv6(controller)
498 filter_igmp(controller)
499 if egress_tag == EGRESS_UNTAGGED:
500 add_one_vlan_table_flow_pw(
501 ctrl=controller,
502 of_port=in_port,
503 tunnel_index=1,
504 flag=VLAN_TABLE_FLAG_ONLY_UNTAG,
505 )
506 elif egress_tag == EGRESS_TAGGED:
507 add_one_vlan_table_flow_pw(
508 ctrl=controller,
509 of_port=in_port,
510 tunnel_index=1,
511 vlan_id=port_to_in_vlan_1[in_port],
512 flag=VLAN_TABLE_FLAG_ONLY_UNTAG,
513 )
514
515 return (
516 port_to_mpls_label_2,
517 port_to_mpls_label_1,
518 port_to_mpls_label_pw,
519 port_to_in_vlan_3,
520 port_to_in_vlan_2,
521 port_to_in_vlan_1,
522 port_to_src_mac_str,
523 port_to_dst_mac_str,
524 Groups
525 )
Pierb5da4c92016-09-21 11:23:35 -0700526
527MPLS_FLOW_TABLE_0 = 23
528OF_DPA_MPLS_SWAP_Label = 5
529
530def fill_pw_intermediate_transport_pipeline(
531 controller,
532 logging,
533 ports,
534 mpls_labels
535 ):
536 """
537 This method, according to the scenario, fills properly
538 the pw pipeline. The method generates using ports data the
539 necessary information to fill the pw pipeline and
540 fills properly the pipeline which consists into:
541
542 """
543
544 Groups = Queue.LifoQueue( )
545 out_vlan = 4094
546 port_to_src_mac = {}
547 port_to_src_mac_str = {}
548 port_to_dst_mac = {}
549 port_to_dst_mac_str = {}
550 port_to_mpls_label_2 = {}
551 port_to_mpls_label_1 = {}
552 port_to_mpls_label_pw = {}
553 port_to_switch_mac = {}
554 port_to_switch_mac_str = {}
555
556 for port in ports:
557 mpls_label_1 = port + 10
558 mpls_label_2 = port + 100
559 mpls_label_pw = port + 300
560 src_mac = [ 0x00, 0x00, 0x00, 0x00, 0x11, port ]
561 src_mac_str = ':'.join( [ '%02X' % x for x in src_mac ] )
562 dst_mac = [ 0x00, 0x00, 0x00, 0x11, 0x11, port ]
563 dst_mac_str = ':'.join( [ '%02X' % x for x in dst_mac ] )
564 switch_mac = [ 0x00, 0x00, 0x00, 0x00, 0x00, port ]
565 switch_mac_str = ':'.join( [ '%02X' % x for x in switch_mac ] )
566 port_to_src_mac[port] = src_mac
567 port_to_src_mac_str[port] = src_mac_str
568 port_to_dst_mac[port] = dst_mac
569 port_to_dst_mac_str[port] = dst_mac_str
570 port_to_mpls_label_1[port] = mpls_label_1
571 port_to_mpls_label_2[port] = mpls_label_2
572 port_to_mpls_label_pw[port] = mpls_label_pw
573 port_to_switch_mac[port] = switch_mac
574 port_to_switch_mac_str[port] = switch_mac_str
575
576 for pair in itertools.product(ports, ports):
577 in_port = pair[0]
578 out_port = pair[1]
579 if out_port == in_port:
580 continue
581 # add l2 interface group, we have to pop the VLAN;
582 l2_intf_gid, l2_intf_msg = add_one_l2_interface_group(
583 ctrl=controller,
584 port=out_port,
585 vlan_id=out_vlan,
586 is_tagged=False,
587 send_barrier=False
588 )
589 Groups._put( l2_intf_gid )
590 # add MPLS interface group
591 mpls_intf_gid, mpls_intf_msg = add_mpls_intf_group(
592 ctrl=controller,
593 ref_gid=l2_intf_gid,
594 dst_mac=port_to_dst_mac[in_port],
595 src_mac=port_to_src_mac[out_port],
596 vid=out_vlan,
597 index=in_port
598 )
599 Groups._put( mpls_intf_gid )
600 # add MPLS flows
601 if mpls_labels >=2:
602 add_mpls_flow_pw(
603 ctrl=controller,
604 action_group_id=mpls_intf_gid,
605 label=port_to_mpls_label_2[in_port],
606 ethertype=0x8847,
607 tunnel_index=1,
608 bos=0
609 )
610 else:
611 mpls_tunnel_gid, mpls_tunnel_msg = add_mpls_tunnel_label_group(
612 ctrl=controller,
613 ref_gid=mpls_intf_gid,
614 subtype=OF_DPA_MPLS_Tunnel_Label_2,
615 index=in_port,
616 label=port_to_mpls_label_2[in_port]
617 )
618 Groups._put( mpls_tunnel_gid )
619 mpls_tunnel_gid, mpls_tunnel_msg = add_mpls_tunnel_label_group(
620 ctrl=controller,
621 ref_gid=mpls_tunnel_gid,
622 subtype=OF_DPA_MPLS_Tunnel_Label_1,
623 index=in_port,
624 label=port_to_mpls_label_1[in_port]
625 )
626 Groups._put( mpls_tunnel_gid )
627 mpls_swap_gid, mpls_tunnel_msg = add_mpls_swap_label_group(
628 ctrl=controller,
629 ref_gid=mpls_tunnel_gid,
630 subtype=OF_DPA_MPLS_SWAP_Label,
631 index=in_port,
632 label=port_to_mpls_label_pw[in_port]
633 )
634 Groups._put( mpls_swap_gid )
635 add_mpls_flow_pw(
636 ctrl=controller,
637 action_group_id=mpls_swap_gid,
638 label=port_to_mpls_label_pw[in_port],
639 ethertype=0x8847,
640 tunnel_index=1,
641 bos=1,
642 popMPLS=False,
643 popL2=False
644 )
645 # add Termination flow
646 add_termination_flow(
647 ctrl=controller,
648 in_port=in_port,
649 eth_type=0x8847,
650 dst_mac=port_to_switch_mac[in_port],
651 vlanid=out_vlan,
652 goto_table=MPLS_FLOW_TABLE_0)
653 # add VLAN flows
654 add_one_vlan_table_flow(
655 ctrl=controller,
656 of_port=in_port,
657 vlan_id=out_vlan,
658 flag=VLAN_TABLE_FLAG_ONLY_TAG,
Pierb5da4c92016-09-21 11:23:35 -0700659 )
660 add_one_vlan_table_flow(
661 ctrl=controller,
662 of_port=in_port,
663 vlan_id=out_vlan,
664 flag=VLAN_TABLE_FLAG_ONLY_UNTAG
665 )
666
667 return (
668 port_to_mpls_label_2,
669 port_to_mpls_label_1,
670 port_to_mpls_label_pw,
671 port_to_switch_mac_str,
672 port_to_src_mac_str,
673 port_to_dst_mac_str,
674 Groups
675 )
Pierf6f28162016-09-22 16:30:52 -0700676
677def fill_pw_termination_pipeline(
678 controller,
679 logging,
680 in_port,
681 out_port,
Pier23784aa2016-09-19 20:08:21 -0700682 egress_tags
Pierf6f28162016-09-22 16:30:52 -0700683 ):
684 """
685 This method, according to the scenario, fills properly
686 the pw pipeline. The method generates using ports data the
687 necessary information to fill the pw pipeline and
688 fills properly the pipeline which consists into:
689
690 """
691
692 Groups = Queue.LifoQueue( )
693 out_vlan = 4094
694 port_to_mpls_label_pw = {}
695 port_to_vlan_2 = {}
696 port_to_vlan_1 = {}
697 port_to_switch_mac = {}
698 port_to_switch_mac_str = {}
699 ports = [in_port, out_port]
700
701 for port in ports:
702 mpls_label_pw = port + 300
703 in_vlan_id_1 = port + 1
704 in_vlan_id_2 = port + 100
705 switch_mac = [ 0x00, 0x00, 0x00, 0x00, 0x11, port ]
706 switch_mac_str = ':'.join( [ '%02X' % x for x in switch_mac ] )
707 port_to_mpls_label_pw[port] = mpls_label_pw
708 port_to_vlan_2[port] = in_vlan_id_2
709 port_to_vlan_1[port] = in_vlan_id_1
710 port_to_switch_mac[port] = switch_mac
711 port_to_switch_mac_str[port] = switch_mac_str
712
713 # add l2 interface group;
714 if egress_tags == 2:
715 l2_intf_gid, l2_intf_msg = add_one_l2_interface_group(
716 ctrl=controller,
717 port=out_port,
718 vlan_id=port_to_vlan_2[out_port],
719 is_tagged=True,
720 send_barrier=False
721 )
722 elif egress_tags == 1:
723 l2_intf_gid, l2_intf_msg = add_one_l2_interface_group(
724 ctrl=controller,
725 port=out_port,
726 vlan_id=port_to_vlan_1[out_port],
727 is_tagged=True,
728 send_barrier=False
729 )
730 elif egress_tags == 0:
731 l2_intf_gid, l2_intf_msg = add_one_l2_interface_group(
732 ctrl=controller,
733 port=out_port,
734 vlan_id=port_to_vlan_1[out_port],
735 is_tagged=False,
736 send_barrier=False
737 )
Charles Chanc85f1562018-01-18 15:44:29 -0800738
Pierf6f28162016-09-22 16:30:52 -0700739 Groups._put( l2_intf_gid )
740 add_mpls_flow_pw(
741 ctrl=controller,
742 action_group_id=l2_intf_gid,
743 label=port_to_mpls_label_pw[out_port],
744 ethertype=0x6558,
745 bos=1,
746 tunnel_index=1,
747 popMPLS=True,
748 popL2=True,
749 of_port=in_port
750 )
751 # add Termination flow
752 add_termination_flow(
753 ctrl=controller,
754 in_port=in_port,
755 eth_type=0x8847,
756 dst_mac=port_to_switch_mac[in_port],
757 vlanid=out_vlan,
758 goto_table=MPLS_FLOW_TABLE_0)
759 # add VLAN flows
760 add_one_vlan_table_flow(
761 ctrl=controller,
762 of_port=in_port,
763 vlan_id=out_vlan,
764 flag=VLAN_TABLE_FLAG_ONLY_TAG,
Pierf6f28162016-09-22 16:30:52 -0700765 )
766 add_one_vlan_table_flow(
767 ctrl=controller,
768 of_port=in_port,
769 vlan_id=out_vlan,
770 flag=VLAN_TABLE_FLAG_ONLY_UNTAG
771 )
772
773 return (
774 port_to_mpls_label_pw,
775 port_to_vlan_2,
Pier23784aa2016-09-19 20:08:21 -0700776 port_to_vlan_1,
Pierf6f28162016-09-22 16:30:52 -0700777 port_to_switch_mac_str,
778 Groups
779 )