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