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