Matteo Scandolo | a229eca | 2017-08-08 13:05:28 -0700 | [diff] [blame] | 1 | |
| 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 | |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 17 | import Queue |
Pier | cf76e80 | 2016-09-19 20:16:35 -0700 | [diff] [blame] | 18 | import itertools |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 19 | |
| 20 | from oftest.testutils import * |
| 21 | from accton_util import * |
| 22 | |
Pier | cf76e80 | 2016-09-19 20:16:35 -0700 | [diff] [blame] | 23 | """ |
| 24 | MISC |
| 25 | """ |
| 26 | |
| 27 | def 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 | |
Pier | 1e4e98e | 2016-10-26 14:36:05 -0700 | [diff] [blame] | 38 | print "\nPort %d stats count: tx %d rx %d - tx_dropped %d rx_dropped %d - tx_errors %d rx_errors %d" % ( |
Pier | cf76e80 | 2016-09-19 20:16:35 -0700 | [diff] [blame] | 39 | port, packet_sent, packet_rcv, packet_sent_dropped, packet_rcv_dropped, packet_sent_errors, packet_rcv_errors |
| 40 | ) |
| 41 | |
| 42 | def 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 | |
| 59 | def 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 | |
| 73 | def 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 | |
Pier | cf76e80 | 2016-09-19 20:16:35 -0700 | [diff] [blame] | 88 | """ |
| 89 | MULTICAST Pipelines |
| 90 | """ |
| 91 | |
Pier | 7b031af | 2016-08-25 15:00:22 -0700 | [diff] [blame] | 92 | def 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 |
Pier | 265ad5f | 2017-02-28 17:46:28 +0100 | [diff] [blame] | 167 | add_one_vlan_table_flow( controller, in_port, 1, port_to_in_vlan[in_port], flag=VLAN_TABLE_FLAG_ONLY_TAG ) |
Pier | 7b031af | 2016-08-25 15:00:22 -0700 | [diff] [blame] | 168 | if not is_ingress_tagged: |
Pier | 265ad5f | 2017-02-28 17:46:28 +0100 | [diff] [blame] | 169 | add_one_vlan_table_flow( controller, in_port, 1, port_to_in_vlan[in_port], flag=VLAN_TABLE_FLAG_ONLY_UNTAG ) |
Pier | 7b031af | 2016-08-25 15:00:22 -0700 | [diff] [blame] | 170 | 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 Campanella | 0ea9632 | 2018-04-19 19:11:49 +0200 | [diff] [blame] | 208 | port_to_src_ip, |
Pier | 7b031af | 2016-08-25 15:00:22 -0700 | [diff] [blame] | 209 | port_to_src_ip_str, |
| 210 | Groups |
| 211 | ) |
| 212 | |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 213 | def 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 Chou | d619580 | 2018-06-01 11:52:26 +0800 | [diff] [blame^] | 283 | is_tagged=True, send_barrier=True ) |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 284 | 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 ) |
| 293 | Groups._put( mcat_group_msg.group_id ) |
| 294 | # add mcast flow |
| 295 | add_mcast4_routing_flow( controller, port_to_in_vlan[port], port_to_src_ip[port], 0, dst_ip, mcat_group_msg.group_id ) |
| 296 | # add termination flow |
| 297 | add_termination_flow( controller, port, 0x0800, switch_mac, port_to_in_vlan[port] ) |
| 298 | # add vlan flow table |
Pier | 265ad5f | 2017-02-28 17:46:28 +0100 | [diff] [blame] | 299 | add_one_vlan_table_flow( controller, port, 1, port_to_in_vlan[port], flag=VLAN_TABLE_FLAG_ONLY_TAG ) |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 300 | |
| 301 | return ( |
| 302 | port_to_in_vlan, |
| 303 | port_to_out_vlan, |
| 304 | port_to_src_mac_str, |
| 305 | port_to_dst_mac_str, |
Andrea Campanella | 0ea9632 | 2018-04-19 19:11:49 +0200 | [diff] [blame] | 306 | port_to_src_ip, |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 307 | port_to_src_ip_str, |
| 308 | port_to_intf_src_mac_str, |
| 309 | Groups |
Pier | cf76e80 | 2016-09-19 20:16:35 -0700 | [diff] [blame] | 310 | ) |
| 311 | |
| 312 | """ |
| 313 | VPWS Pipeline |
| 314 | """ |
| 315 | |
| 316 | OF_DPA_MPLS_L2_VPN_Label = 1 |
| 317 | OF_DPA_MPLS_Tunnel_Label_1 = 3 |
| 318 | OF_DPA_MPLS_Tunnel_Label_2 = 4 |
| 319 | |
| 320 | EGRESS_UNTAGGED = 1 |
| 321 | EGRESS_TAGGED = 2 |
| 322 | EGRESS_TAGGED_TRANS = 3 |
| 323 | |
| 324 | |
| 325 | def fill_pw_initiation_pipeline( |
| 326 | controller, |
| 327 | logging, |
| 328 | in_port, |
| 329 | out_port, |
| 330 | ingress_tags, |
| 331 | egress_tag, |
| 332 | mpls_labels |
| 333 | ): |
| 334 | """ |
| 335 | This method, according to the scenario, fills properly |
| 336 | the pw pipeline. The method generates using ports data the |
| 337 | necessary information to fill the pw pipeline and |
| 338 | fills properly the pipeline which consists into: |
| 339 | |
| 340 | """ |
| 341 | |
| 342 | Groups = Queue.LifoQueue( ) |
| 343 | out_vlan = 4094 |
| 344 | port_to_in_vlan_1 = {} |
| 345 | port_to_in_vlan_2 = {} |
| 346 | port_to_in_vlan_3 = {} |
| 347 | port_to_src_mac = {} |
| 348 | port_to_src_mac_str = {} |
| 349 | port_to_dst_mac = {} |
| 350 | port_to_dst_mac_str = {} |
Pier | cf76e80 | 2016-09-19 20:16:35 -0700 | [diff] [blame] | 351 | port_to_mpls_label_1 = {} |
| 352 | port_to_mpls_label_2 = {} |
| 353 | port_to_mpls_label_pw = {} |
| 354 | ports = [in_port, out_port] |
| 355 | |
| 356 | for port in ports: |
| 357 | in_vlan_id_1 = port + 1 |
| 358 | in_vlan_id_2 = port + 100 |
| 359 | in_vlan_id_3 = port + 300 |
| 360 | mpls_label_1 = port + 100 |
| 361 | mpls_label_2 = port + 200 |
| 362 | mpls_label_pw = port + 300 |
| 363 | port_to_in_vlan_1[port] = in_vlan_id_1 |
| 364 | port_to_in_vlan_2[port] = in_vlan_id_2 |
| 365 | port_to_in_vlan_3[port] = in_vlan_id_3 |
| 366 | src_mac = [ 0x00, 0x00, 0x00, 0x00, 0x11, port ] |
| 367 | src_mac_str = ':'.join( [ '%02X' % x for x in src_mac ] ) |
| 368 | dst_mac = [ 0x00, 0x00, 0x00, 0x11, 0x11, port ] |
| 369 | dst_mac_str = ':'.join( [ '%02X' % x for x in dst_mac ] ) |
| 370 | port_to_src_mac[port] = src_mac |
| 371 | port_to_src_mac_str[port] = src_mac_str |
| 372 | port_to_dst_mac[port] = dst_mac |
| 373 | port_to_dst_mac_str[port] = dst_mac_str |
| 374 | port_to_mpls_label_1[port] = mpls_label_1 |
| 375 | port_to_mpls_label_2[port] = mpls_label_2 |
| 376 | port_to_mpls_label_pw[port] = mpls_label_pw |
| 377 | |
| 378 | # add l2 interface group, we have to pop the VLAN; |
| 379 | l2_intf_gid, l2_intf_msg = add_one_l2_interface_group( |
| 380 | ctrl=controller, |
| 381 | port=out_port, |
| 382 | vlan_id=out_vlan, |
| 383 | is_tagged=False, |
| 384 | send_barrier=False |
| 385 | ) |
| 386 | Groups._put( l2_intf_gid ) |
| 387 | # add MPLS interface group |
| 388 | mpls_intf_gid, mpls_intf_msg = add_mpls_intf_group( |
| 389 | ctrl=controller, |
| 390 | ref_gid=l2_intf_gid, |
| 391 | dst_mac=port_to_dst_mac[in_port], |
| 392 | src_mac=port_to_src_mac[out_port], |
| 393 | vid=out_vlan, |
| 394 | index=in_port |
| 395 | ) |
| 396 | Groups._put( mpls_intf_gid ) |
| 397 | mpls_gid = mpls_intf_gid |
| 398 | # add MPLS tunnel label groups, the number depends on the labels |
| 399 | if mpls_labels == 2: |
| 400 | mpls_tunnel_gid, mpls_tunnel_msg = add_mpls_tunnel_label_group( |
| 401 | ctrl=controller, |
| 402 | ref_gid=mpls_intf_gid, |
| 403 | subtype=OF_DPA_MPLS_Tunnel_Label_2, |
| 404 | index=in_port, |
| 405 | label=port_to_mpls_label_2[in_port] |
| 406 | ) |
| 407 | Groups._put( mpls_tunnel_gid ) |
| 408 | mpls_tunnel_gid, mpls_tunnel_msg = add_mpls_tunnel_label_group( |
| 409 | ctrl=controller, |
| 410 | ref_gid=mpls_tunnel_gid, |
| 411 | subtype=OF_DPA_MPLS_Tunnel_Label_1, |
| 412 | index=in_port, |
| 413 | label=port_to_mpls_label_1[in_port] |
| 414 | ) |
| 415 | Groups._put( mpls_tunnel_gid ) |
| 416 | mpls_gid = mpls_tunnel_gid |
| 417 | elif mpls_labels == 1: |
| 418 | mpls_tunnel_gid, mpls_tunnel_msg = add_mpls_tunnel_label_group( |
| 419 | ctrl=controller, |
| 420 | ref_gid=mpls_intf_gid, |
| 421 | subtype=OF_DPA_MPLS_Tunnel_Label_1, |
| 422 | index=in_port, |
| 423 | label=port_to_mpls_label_1[in_port] |
| 424 | ) |
| 425 | Groups._put( mpls_tunnel_gid ) |
| 426 | mpls_gid = mpls_tunnel_gid |
Pier | cf76e80 | 2016-09-19 20:16:35 -0700 | [diff] [blame] | 427 | # add MPLS L2 VPN group |
| 428 | mpls_l2_vpn_gid, mpls_l2_vpn_msg = add_mpls_label_group( |
| 429 | ctrl=controller, |
| 430 | subtype=OF_DPA_MPLS_L2_VPN_Label, |
| 431 | index=in_port, |
| 432 | ref_gid=mpls_gid, |
| 433 | push_l2_header=True, |
| 434 | push_vlan=True, |
| 435 | push_mpls_header=True, |
| 436 | push_cw=True, |
| 437 | set_mpls_label=port_to_mpls_label_pw[in_port], |
| 438 | set_bos=1, |
| 439 | cpy_ttl_outward=True |
| 440 | ) |
Pier | cf76e80 | 2016-09-19 20:16:35 -0700 | [diff] [blame] | 441 | Groups._put( mpls_l2_vpn_gid ) |
| 442 | # add MPLS L2 port flow |
| 443 | add_mpls_l2_port_flow( |
| 444 | ctrl=controller, |
| 445 | of_port=in_port, |
| 446 | mpls_l2_port=in_port, |
| 447 | tunnel_index=1, |
| 448 | ref_gid=mpls_l2_vpn_gid |
| 449 | ) |
| 450 | # add VLAN flows table |
| 451 | if ingress_tags == 2: |
| 452 | if egress_tag == EGRESS_TAGGED: |
| 453 | add_one_vlan_1_table_flow_pw( |
| 454 | ctrl=controller, |
| 455 | of_port=in_port, |
| 456 | tunnel_index=1, |
| 457 | new_outer_vlan_id=-1, |
| 458 | outer_vlan_id=port_to_in_vlan_2[in_port], |
| 459 | inner_vlan_id=port_to_in_vlan_1[in_port], |
| 460 | ) |
| 461 | elif egress_tag == EGRESS_TAGGED_TRANS: |
| 462 | add_one_vlan_1_table_flow_pw( |
| 463 | ctrl=controller, |
| 464 | of_port=in_port, |
| 465 | tunnel_index=1, |
| 466 | new_outer_vlan_id=port_to_in_vlan_3[in_port], |
| 467 | outer_vlan_id=port_to_in_vlan_2[in_port], |
| 468 | inner_vlan_id=port_to_in_vlan_1[in_port], |
| 469 | ) |
| 470 | add_one_vlan_table_flow( |
| 471 | ctrl=controller, |
| 472 | of_port=in_port, |
| 473 | vlan_id=port_to_in_vlan_2[in_port], |
| 474 | flag=VLAN_TABLE_FLAG_ONLY_STACKED, |
| 475 | ) |
| 476 | elif ingress_tags == 1: |
| 477 | if egress_tag == EGRESS_TAGGED: |
| 478 | add_one_vlan_table_flow_pw( |
| 479 | ctrl=controller, |
| 480 | of_port=in_port, |
| 481 | tunnel_index=1, |
| 482 | vlan_id=port_to_in_vlan_1[in_port], |
| 483 | flag=VLAN_TABLE_FLAG_ONLY_TAG, |
| 484 | ) |
| 485 | elif egress_tag == EGRESS_TAGGED_TRANS: |
| 486 | add_one_vlan_table_flow_pw( |
| 487 | ctrl=controller, |
| 488 | of_port=in_port, |
| 489 | tunnel_index=1, |
| 490 | vlan_id=port_to_in_vlan_1[in_port], |
| 491 | new_vlan_id=port_to_in_vlan_3[in_port], |
| 492 | flag=VLAN_TABLE_FLAG_ONLY_TAG, |
| 493 | ) |
| 494 | elif ingress_tags == 0: |
| 495 | filter_dhcp(controller) |
| 496 | filter_ipv6(controller) |
| 497 | filter_igmp(controller) |
| 498 | if egress_tag == EGRESS_UNTAGGED: |
| 499 | add_one_vlan_table_flow_pw( |
| 500 | ctrl=controller, |
| 501 | of_port=in_port, |
| 502 | tunnel_index=1, |
| 503 | flag=VLAN_TABLE_FLAG_ONLY_UNTAG, |
| 504 | ) |
| 505 | elif egress_tag == EGRESS_TAGGED: |
| 506 | add_one_vlan_table_flow_pw( |
| 507 | ctrl=controller, |
| 508 | of_port=in_port, |
| 509 | tunnel_index=1, |
| 510 | vlan_id=port_to_in_vlan_1[in_port], |
| 511 | flag=VLAN_TABLE_FLAG_ONLY_UNTAG, |
| 512 | ) |
| 513 | |
| 514 | return ( |
| 515 | port_to_mpls_label_2, |
| 516 | port_to_mpls_label_1, |
| 517 | port_to_mpls_label_pw, |
| 518 | port_to_in_vlan_3, |
| 519 | port_to_in_vlan_2, |
| 520 | port_to_in_vlan_1, |
| 521 | port_to_src_mac_str, |
| 522 | port_to_dst_mac_str, |
| 523 | Groups |
| 524 | ) |
Pier | b5da4c9 | 2016-09-21 11:23:35 -0700 | [diff] [blame] | 525 | |
| 526 | MPLS_FLOW_TABLE_0 = 23 |
| 527 | OF_DPA_MPLS_SWAP_Label = 5 |
| 528 | |
| 529 | def fill_pw_intermediate_transport_pipeline( |
| 530 | controller, |
| 531 | logging, |
| 532 | ports, |
| 533 | mpls_labels |
| 534 | ): |
| 535 | """ |
| 536 | This method, according to the scenario, fills properly |
| 537 | the pw pipeline. The method generates using ports data the |
| 538 | necessary information to fill the pw pipeline and |
| 539 | fills properly the pipeline which consists into: |
| 540 | |
| 541 | """ |
| 542 | |
| 543 | Groups = Queue.LifoQueue( ) |
| 544 | out_vlan = 4094 |
| 545 | port_to_src_mac = {} |
| 546 | port_to_src_mac_str = {} |
| 547 | port_to_dst_mac = {} |
| 548 | port_to_dst_mac_str = {} |
| 549 | port_to_mpls_label_2 = {} |
| 550 | port_to_mpls_label_1 = {} |
| 551 | port_to_mpls_label_pw = {} |
| 552 | port_to_switch_mac = {} |
| 553 | port_to_switch_mac_str = {} |
| 554 | |
| 555 | for port in ports: |
| 556 | mpls_label_1 = port + 10 |
| 557 | mpls_label_2 = port + 100 |
| 558 | mpls_label_pw = port + 300 |
| 559 | src_mac = [ 0x00, 0x00, 0x00, 0x00, 0x11, port ] |
| 560 | src_mac_str = ':'.join( [ '%02X' % x for x in src_mac ] ) |
| 561 | dst_mac = [ 0x00, 0x00, 0x00, 0x11, 0x11, port ] |
| 562 | dst_mac_str = ':'.join( [ '%02X' % x for x in dst_mac ] ) |
| 563 | switch_mac = [ 0x00, 0x00, 0x00, 0x00, 0x00, port ] |
| 564 | switch_mac_str = ':'.join( [ '%02X' % x for x in switch_mac ] ) |
| 565 | port_to_src_mac[port] = src_mac |
| 566 | port_to_src_mac_str[port] = src_mac_str |
| 567 | port_to_dst_mac[port] = dst_mac |
| 568 | port_to_dst_mac_str[port] = dst_mac_str |
| 569 | port_to_mpls_label_1[port] = mpls_label_1 |
| 570 | port_to_mpls_label_2[port] = mpls_label_2 |
| 571 | port_to_mpls_label_pw[port] = mpls_label_pw |
| 572 | port_to_switch_mac[port] = switch_mac |
| 573 | port_to_switch_mac_str[port] = switch_mac_str |
| 574 | |
| 575 | for pair in itertools.product(ports, ports): |
| 576 | in_port = pair[0] |
| 577 | out_port = pair[1] |
| 578 | if out_port == in_port: |
| 579 | continue |
| 580 | # add l2 interface group, we have to pop the VLAN; |
| 581 | l2_intf_gid, l2_intf_msg = add_one_l2_interface_group( |
| 582 | ctrl=controller, |
| 583 | port=out_port, |
| 584 | vlan_id=out_vlan, |
| 585 | is_tagged=False, |
| 586 | send_barrier=False |
| 587 | ) |
| 588 | Groups._put( l2_intf_gid ) |
| 589 | # add MPLS interface group |
| 590 | mpls_intf_gid, mpls_intf_msg = add_mpls_intf_group( |
| 591 | ctrl=controller, |
| 592 | ref_gid=l2_intf_gid, |
| 593 | dst_mac=port_to_dst_mac[in_port], |
| 594 | src_mac=port_to_src_mac[out_port], |
| 595 | vid=out_vlan, |
| 596 | index=in_port |
| 597 | ) |
| 598 | Groups._put( mpls_intf_gid ) |
| 599 | # add MPLS flows |
| 600 | if mpls_labels >=2: |
| 601 | add_mpls_flow_pw( |
| 602 | ctrl=controller, |
| 603 | action_group_id=mpls_intf_gid, |
| 604 | label=port_to_mpls_label_2[in_port], |
| 605 | ethertype=0x8847, |
| 606 | tunnel_index=1, |
| 607 | bos=0 |
| 608 | ) |
| 609 | else: |
| 610 | mpls_tunnel_gid, mpls_tunnel_msg = add_mpls_tunnel_label_group( |
| 611 | ctrl=controller, |
| 612 | ref_gid=mpls_intf_gid, |
| 613 | subtype=OF_DPA_MPLS_Tunnel_Label_2, |
| 614 | index=in_port, |
| 615 | label=port_to_mpls_label_2[in_port] |
| 616 | ) |
| 617 | Groups._put( mpls_tunnel_gid ) |
| 618 | mpls_tunnel_gid, mpls_tunnel_msg = add_mpls_tunnel_label_group( |
| 619 | ctrl=controller, |
| 620 | ref_gid=mpls_tunnel_gid, |
| 621 | subtype=OF_DPA_MPLS_Tunnel_Label_1, |
| 622 | index=in_port, |
| 623 | label=port_to_mpls_label_1[in_port] |
| 624 | ) |
| 625 | Groups._put( mpls_tunnel_gid ) |
| 626 | mpls_swap_gid, mpls_tunnel_msg = add_mpls_swap_label_group( |
| 627 | ctrl=controller, |
| 628 | ref_gid=mpls_tunnel_gid, |
| 629 | subtype=OF_DPA_MPLS_SWAP_Label, |
| 630 | index=in_port, |
| 631 | label=port_to_mpls_label_pw[in_port] |
| 632 | ) |
| 633 | Groups._put( mpls_swap_gid ) |
| 634 | add_mpls_flow_pw( |
| 635 | ctrl=controller, |
| 636 | action_group_id=mpls_swap_gid, |
| 637 | label=port_to_mpls_label_pw[in_port], |
| 638 | ethertype=0x8847, |
| 639 | tunnel_index=1, |
| 640 | bos=1, |
| 641 | popMPLS=False, |
| 642 | popL2=False |
| 643 | ) |
| 644 | # add Termination flow |
| 645 | add_termination_flow( |
| 646 | ctrl=controller, |
| 647 | in_port=in_port, |
| 648 | eth_type=0x8847, |
| 649 | dst_mac=port_to_switch_mac[in_port], |
| 650 | vlanid=out_vlan, |
| 651 | goto_table=MPLS_FLOW_TABLE_0) |
| 652 | # add VLAN flows |
| 653 | add_one_vlan_table_flow( |
| 654 | ctrl=controller, |
| 655 | of_port=in_port, |
| 656 | vlan_id=out_vlan, |
| 657 | flag=VLAN_TABLE_FLAG_ONLY_TAG, |
Pier | b5da4c9 | 2016-09-21 11:23:35 -0700 | [diff] [blame] | 658 | ) |
| 659 | add_one_vlan_table_flow( |
| 660 | ctrl=controller, |
| 661 | of_port=in_port, |
| 662 | vlan_id=out_vlan, |
| 663 | flag=VLAN_TABLE_FLAG_ONLY_UNTAG |
| 664 | ) |
| 665 | |
| 666 | return ( |
| 667 | port_to_mpls_label_2, |
| 668 | port_to_mpls_label_1, |
| 669 | port_to_mpls_label_pw, |
| 670 | port_to_switch_mac_str, |
| 671 | port_to_src_mac_str, |
| 672 | port_to_dst_mac_str, |
| 673 | Groups |
| 674 | ) |
Pier | f6f2816 | 2016-09-22 16:30:52 -0700 | [diff] [blame] | 675 | |
| 676 | def fill_pw_termination_pipeline( |
| 677 | controller, |
| 678 | logging, |
| 679 | in_port, |
| 680 | out_port, |
Pier | 23784aa | 2016-09-19 20:08:21 -0700 | [diff] [blame] | 681 | egress_tags |
Pier | f6f2816 | 2016-09-22 16:30:52 -0700 | [diff] [blame] | 682 | ): |
| 683 | """ |
| 684 | This method, according to the scenario, fills properly |
| 685 | the pw pipeline. The method generates using ports data the |
| 686 | necessary information to fill the pw pipeline and |
| 687 | fills properly the pipeline which consists into: |
| 688 | |
| 689 | """ |
| 690 | |
| 691 | Groups = Queue.LifoQueue( ) |
| 692 | out_vlan = 4094 |
| 693 | port_to_mpls_label_pw = {} |
| 694 | port_to_vlan_2 = {} |
| 695 | port_to_vlan_1 = {} |
| 696 | port_to_switch_mac = {} |
| 697 | port_to_switch_mac_str = {} |
| 698 | ports = [in_port, out_port] |
| 699 | |
| 700 | for port in ports: |
| 701 | mpls_label_pw = port + 300 |
| 702 | in_vlan_id_1 = port + 1 |
| 703 | in_vlan_id_2 = port + 100 |
| 704 | switch_mac = [ 0x00, 0x00, 0x00, 0x00, 0x11, port ] |
| 705 | switch_mac_str = ':'.join( [ '%02X' % x for x in switch_mac ] ) |
| 706 | port_to_mpls_label_pw[port] = mpls_label_pw |
| 707 | port_to_vlan_2[port] = in_vlan_id_2 |
| 708 | port_to_vlan_1[port] = in_vlan_id_1 |
| 709 | port_to_switch_mac[port] = switch_mac |
| 710 | port_to_switch_mac_str[port] = switch_mac_str |
| 711 | |
| 712 | # add l2 interface group; |
| 713 | if egress_tags == 2: |
| 714 | l2_intf_gid, l2_intf_msg = add_one_l2_interface_group( |
| 715 | ctrl=controller, |
| 716 | port=out_port, |
| 717 | vlan_id=port_to_vlan_2[out_port], |
| 718 | is_tagged=True, |
| 719 | send_barrier=False |
| 720 | ) |
| 721 | elif egress_tags == 1: |
| 722 | l2_intf_gid, l2_intf_msg = add_one_l2_interface_group( |
| 723 | ctrl=controller, |
| 724 | port=out_port, |
| 725 | vlan_id=port_to_vlan_1[out_port], |
| 726 | is_tagged=True, |
| 727 | send_barrier=False |
| 728 | ) |
| 729 | elif egress_tags == 0: |
| 730 | l2_intf_gid, l2_intf_msg = add_one_l2_interface_group( |
| 731 | ctrl=controller, |
| 732 | port=out_port, |
| 733 | vlan_id=port_to_vlan_1[out_port], |
| 734 | is_tagged=False, |
| 735 | send_barrier=False |
| 736 | ) |
Charles Chan | c85f156 | 2018-01-18 15:44:29 -0800 | [diff] [blame] | 737 | |
Pier | f6f2816 | 2016-09-22 16:30:52 -0700 | [diff] [blame] | 738 | Groups._put( l2_intf_gid ) |
| 739 | add_mpls_flow_pw( |
| 740 | ctrl=controller, |
| 741 | action_group_id=l2_intf_gid, |
| 742 | label=port_to_mpls_label_pw[out_port], |
| 743 | ethertype=0x6558, |
| 744 | bos=1, |
| 745 | tunnel_index=1, |
| 746 | popMPLS=True, |
| 747 | popL2=True, |
| 748 | of_port=in_port |
| 749 | ) |
| 750 | # add Termination flow |
| 751 | add_termination_flow( |
| 752 | ctrl=controller, |
| 753 | in_port=in_port, |
| 754 | eth_type=0x8847, |
| 755 | dst_mac=port_to_switch_mac[in_port], |
| 756 | vlanid=out_vlan, |
| 757 | goto_table=MPLS_FLOW_TABLE_0) |
| 758 | # add VLAN flows |
| 759 | add_one_vlan_table_flow( |
| 760 | ctrl=controller, |
| 761 | of_port=in_port, |
| 762 | vlan_id=out_vlan, |
| 763 | flag=VLAN_TABLE_FLAG_ONLY_TAG, |
Pier | f6f2816 | 2016-09-22 16:30:52 -0700 | [diff] [blame] | 764 | ) |
| 765 | add_one_vlan_table_flow( |
| 766 | ctrl=controller, |
| 767 | of_port=in_port, |
| 768 | vlan_id=out_vlan, |
| 769 | flag=VLAN_TABLE_FLAG_ONLY_UNTAG |
| 770 | ) |
| 771 | |
| 772 | return ( |
| 773 | port_to_mpls_label_pw, |
| 774 | port_to_vlan_2, |
Pier | 23784aa | 2016-09-19 20:08:21 -0700 | [diff] [blame] | 775 | port_to_vlan_1, |
Pier | f6f2816 | 2016-09-22 16:30:52 -0700 | [diff] [blame] | 776 | port_to_switch_mac_str, |
| 777 | Groups |
| 778 | ) |