| import Queue |
| import itertools |
| |
| from oftest.testutils import * |
| from accton_util import * |
| |
| """ |
| MISC |
| """ |
| |
| def print_port_stats(test, port): |
| entries = get_port_stats(test, port) |
| for item in entries: |
| packet_rcv = item.rx_packets |
| packet_rcv_dropped = item.rx_dropped |
| packet_rcv_errors = item.rx_errors |
| |
| packet_sent = item.tx_packets |
| packet_sent_dropped = item.tx_dropped |
| packet_sent_errors = item.tx_errors |
| |
| print "\nPort %d stats count: tx %d rx %d - tx_dropped %d rx_dropped %d - tx_errors %d rx_errors %d" % ( |
| port, packet_sent, packet_rcv, packet_sent_dropped, packet_rcv_dropped, packet_sent_errors, packet_rcv_errors |
| ) |
| |
| def filter_dhcp(controller): |
| match = ofp.match( ) |
| match.oxm_list.append( ofp.oxm.eth_type( 0x0800 ) ) |
| match.oxm_list.append( ofp.oxm.ip_proto( 17 ) ) |
| match.oxm_list.append( ofp.oxm.udp_src( 68 ) ) |
| match.oxm_list.append( ofp.oxm.udp_dst( 67 )) |
| request = ofp.message.flow_add( |
| table_id=60, |
| cookie=42, |
| match=match, |
| instructions=[ofp.instruction.clear_actions( )], |
| buffer_id=ofp.OFP_NO_BUFFER, |
| priority=1 |
| ) |
| controller.message_send( request ) |
| do_barrier( controller ) |
| |
| def filter_ipv6(controller): |
| match = ofp.match( ) |
| match.oxm_list.append( ofp.oxm.eth_type( 0x86dd ) ) |
| request = ofp.message.flow_add( |
| table_id=60, |
| cookie=42, |
| match=match, |
| instructions=[ofp.instruction.clear_actions( )], |
| buffer_id=ofp.OFP_NO_BUFFER, |
| priority=1 |
| ) |
| controller.message_send( request ) |
| do_barrier( controller ) |
| |
| def filter_igmp(controller): |
| match = ofp.match( ) |
| match.oxm_list.append( ofp.oxm.eth_type( 0x0800 ) ) |
| match.oxm_list.append( ofp.oxm.ip_proto( 2 ) ) |
| request = ofp.message.flow_add( |
| table_id=60, |
| cookie=42, |
| match=match, |
| instructions=[ofp.instruction.clear_actions( )], |
| buffer_id=ofp.OFP_NO_BUFFER, |
| priority=1 |
| ) |
| controller.message_send( request ) |
| do_barrier( controller ) |
| |
| """ |
| MULTICAST Pipelines |
| """ |
| |
| def fill_mcast_pipeline_L3toL2( |
| controller, |
| logging, |
| ports, |
| is_ingress_tagged, |
| is_egress_tagged, |
| is_vlan_translated, |
| is_max_vlan |
| ): |
| """ |
| This method, according to the scenario, fills properly |
| the pipeline. The method generates using ports data the |
| necessary information to fill the multicast pipeline and |
| fills properly the pipeline which consists in this scenario: |
| |
| i) to create l2 interface groups; |
| ii) to create l3 multicast groups; |
| iii) to add multicast flows; |
| iv) to add termination; flows; |
| v) to add vlan flows |
| |
| Scenarios: |
| 1) ingress untagged, egress untagged |
| 2) ingress untagged, egress tagged |
| 3) ingress tagged, egress untagged |
| 4) ingress tagged, egress tagged, no translation |
| 5) ingress tagged, egress tagged, translation |
| """ |
| |
| MAX_INTERNAL_VLAN = 4094 |
| # Used for no translation |
| FIXED_VLAN = 300 |
| Groups = Queue.LifoQueue( ) |
| L2_Groups = [] |
| port_to_in_vlan = {} |
| port_to_out_vlan = {} |
| port_to_src_mac = {} |
| port_to_src_mac_str = {} |
| port_to_dst_mac = {} |
| port_to_dst_mac_str = {} |
| port_to_src_ip = {} |
| port_to_src_ip_str = {} |
| src_ip_0 = 0xc0a80100 |
| src_ip_0_str = "192.168.1.%s" |
| dst_ip = 0xe0000001 |
| switch_mac = [ 0x01, 0x00, 0x5e, 0x00, 0x00, 0x00 ] |
| |
| for port in ports: |
| in_vlan_id = port + 1 |
| out_vlan_id = MAX_INTERNAL_VLAN - port |
| if is_max_vlan and not is_vlan_translated: |
| in_vlan_id = MAX_INTERNAL_VLAN |
| out_vlan_id = MAX_INTERNAL_VLAN |
| elif not is_max_vlan and not is_vlan_translated: |
| in_vlan_id = FIXED_VLAN |
| out_vlan_id = FIXED_VLAN |
| src_mac = [ 0x00, 0x11, 0x11, 0x11, 0x11, port ] |
| src_mac_str = ':'.join( [ '%02X' % x for x in src_mac ] ) |
| dst_mac = [ 0x01, 0x00, 0x5e, 0x01, 0x01, port ] |
| dst_mac_str = ':'.join( [ '%02X' % x for x in dst_mac ] ) |
| src_ip = src_ip_0 + port |
| src_ip_str = src_ip_0_str % port |
| port_to_in_vlan[port] = in_vlan_id |
| port_to_out_vlan[port] = out_vlan_id |
| port_to_src_mac[port] = src_mac |
| port_to_src_mac_str[port] = src_mac_str |
| port_to_dst_mac[port] = dst_mac |
| port_to_dst_mac_str[port] = dst_mac_str |
| port_to_src_ip[port] = src_ip |
| port_to_src_ip_str[port] = src_ip_str |
| |
| for in_port in ports: |
| |
| L2_Groups = [] |
| # add vlan flows table |
| add_one_vlan_table_flow( controller, in_port, 1, port_to_in_vlan[in_port], flag=VLAN_TABLE_FLAG_ONLY_TAG ) |
| if not is_ingress_tagged: |
| add_one_vlan_table_flow( controller, in_port, 1, port_to_in_vlan[in_port], flag=VLAN_TABLE_FLAG_ONLY_UNTAG ) |
| elif is_vlan_translated: |
| 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) |
| # add termination flow |
| if not is_vlan_translated: |
| add_termination_flow( controller, in_port, 0x0800, switch_mac, port_to_in_vlan[in_port] ) |
| else: |
| add_termination_flow( controller, in_port, 0x0800, switch_mac, port_to_out_vlan[in_port] ) |
| |
| for out_port in ports: |
| if out_port == in_port: |
| continue |
| # add l2 interface group, vlan_id equals for each port and must coincide with mcast_group vlan_id |
| if not is_vlan_translated: |
| l2gid, msg = add_one_l2_interface_group( controller, out_port, vlan_id=port_to_in_vlan[in_port], |
| is_tagged=is_egress_tagged, send_barrier=True ) |
| else: |
| l2gid, msg = add_one_l2_interface_group( controller, out_port, vlan_id=port_to_out_vlan[in_port], |
| is_tagged=is_egress_tagged, send_barrier=True ) |
| Groups._put( l2gid ) |
| L2_Groups.append( l2gid ) |
| |
| # add l3 mcast group |
| if not is_vlan_translated: |
| mcat_group_msg = add_l3_mcast_group( controller, port_to_in_vlan[in_port], in_port, L2_Groups ) |
| else: |
| mcat_group_msg = add_l3_mcast_group( controller, port_to_out_vlan[in_port], in_port, L2_Groups ) |
| Groups._put( mcat_group_msg.group_id ) |
| # add mcast routing flow |
| if not is_vlan_translated: |
| 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 ) |
| else: |
| 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 ) |
| |
| return ( |
| port_to_in_vlan, |
| port_to_out_vlan, |
| port_to_src_mac_str, |
| port_to_dst_mac_str, |
| port_to_src_ip_str, |
| Groups |
| ) |
| |
| def fill_mcast_pipeline_L3toL3( |
| controller, |
| logging, |
| ports, |
| is_ingress_tagged, |
| is_egress_tagged, |
| is_vlan_translated, |
| is_max_vlan |
| ): |
| """ |
| This method, according to the scenario, fills properly |
| the pipeline. The method generates using ports data the |
| necessary information to fill the multicast pipeline and |
| fills properly the pipeline which consists in this scenario: |
| |
| i) to create l2 interface groups; |
| ii)to create l3 interface groups; |
| iii) to create l3 multicast groups; |
| iv) to add multicast flows; |
| v) to add termination; flows; |
| vi) to add vlan flows |
| |
| Scenarios: |
| 1) ingress tagged, egress tagged, translation |
| """ |
| |
| Groups = Queue.LifoQueue( ) |
| MAX_INTERNAL_VLAN = 4094 |
| port_to_in_vlan = {} |
| port_to_out_vlan = {} |
| port_to_src_mac = {} |
| port_to_src_mac_str = {} |
| port_to_dst_mac = {} |
| port_to_dst_mac_str = {} |
| port_to_src_ip = {} |
| port_to_src_ip_str = {} |
| port_to_intf_src_mac = {} |
| port_to_intf_src_mac_str = {} |
| src_ip_0 = 0xc0a80100 |
| src_ip_0_str = "192.168.1.%s" |
| dst_ip = 0xe0000001 |
| switch_mac = [ 0x01, 0x00, 0x5e, 0x00, 0x00, 0x00 ] |
| |
| for port in ports: |
| in_vlan_id = port + 1 |
| out_vlan_id = MAX_INTERNAL_VLAN - port |
| src_mac = [ 0x00, 0x11, 0x11, 0x11, 0x11, port ] |
| src_mac_str = ':'.join( [ '%02X' % x for x in src_mac ] ) |
| dst_mac = [ 0x01, 0x00, 0x5e, 0x01, 0x01, port ] |
| dst_mac_str = ':'.join( [ '%02X' % x for x in dst_mac ] ) |
| src_ip = src_ip_0 + port |
| src_ip_str = src_ip_0_str % port |
| intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, port ] |
| intf_src_mac_str = ':'.join( [ '%02X' % x for x in intf_src_mac ] ) |
| port_to_in_vlan[port] = in_vlan_id |
| port_to_out_vlan[port] = out_vlan_id |
| port_to_src_mac[port] = src_mac |
| port_to_src_mac_str[port] = src_mac_str |
| port_to_dst_mac[port] = dst_mac |
| port_to_dst_mac_str[port] = dst_mac_str |
| port_to_src_ip[port] = src_ip |
| port_to_src_ip_str[port] = src_ip_str |
| port_to_intf_src_mac[port] = intf_src_mac |
| port_to_intf_src_mac_str[port] = intf_src_mac_str |
| |
| for port in ports: |
| L3_Groups = [] |
| for other_port in ports: |
| # add l2 interface group |
| l2gid, msg = add_one_l2_interface_group( controller, other_port, vlan_id=port_to_out_vlan[other_port], |
| is_tagged=True, send_barrier=False ) |
| Groups._put( l2gid ) |
| # add l3 interface group |
| l3group_ucast_msg = add_l3_interface_group( controller, other_port, port_to_out_vlan[other_port], port_to_in_vlan[other_port], |
| port_to_intf_src_mac[other_port] ) |
| L3_Groups.append(l3group_ucast_msg.group_id) |
| Groups._put( l3group_ucast_msg.group_id ) |
| |
| # add mcast group |
| mcat_group_msg = add_l3_mcast_group( controller, port_to_in_vlan[port], port_to_in_vlan[port], L3_Groups ) |
| Groups._put( mcat_group_msg.group_id ) |
| # add mcast flow |
| add_mcast4_routing_flow( controller, port_to_in_vlan[port], port_to_src_ip[port], 0, dst_ip, mcat_group_msg.group_id ) |
| # add termination flow |
| add_termination_flow( controller, port, 0x0800, switch_mac, port_to_in_vlan[port] ) |
| # add vlan flow table |
| add_one_vlan_table_flow( controller, port, 1, port_to_in_vlan[port], flag=VLAN_TABLE_FLAG_ONLY_TAG ) |
| |
| return ( |
| port_to_in_vlan, |
| port_to_out_vlan, |
| port_to_src_mac_str, |
| port_to_dst_mac_str, |
| port_to_src_ip_str, |
| port_to_intf_src_mac_str, |
| Groups |
| ) |
| |
| """ |
| VPWS Pipeline |
| """ |
| |
| OF_DPA_MPLS_L2_VPN_Label = 1 |
| OF_DPA_MPLS_Tunnel_Label_1 = 3 |
| OF_DPA_MPLS_Tunnel_Label_2 = 4 |
| |
| EGRESS_UNTAGGED = 1 |
| EGRESS_TAGGED = 2 |
| EGRESS_TAGGED_TRANS = 3 |
| |
| |
| def fill_pw_initiation_pipeline( |
| controller, |
| logging, |
| in_port, |
| out_port, |
| ingress_tags, |
| egress_tag, |
| mpls_labels |
| ): |
| """ |
| This method, according to the scenario, fills properly |
| the pw pipeline. The method generates using ports data the |
| necessary information to fill the pw pipeline and |
| fills properly the pipeline which consists into: |
| |
| """ |
| |
| Groups = Queue.LifoQueue( ) |
| out_vlan = 4094 |
| port_to_in_vlan_1 = {} |
| port_to_in_vlan_2 = {} |
| port_to_in_vlan_3 = {} |
| port_to_src_mac = {} |
| port_to_src_mac_str = {} |
| port_to_dst_mac = {} |
| port_to_dst_mac_str = {} |
| port_to_mpls_label_1 = {} |
| port_to_mpls_label_2 = {} |
| port_to_mpls_label_pw = {} |
| ports = [in_port, out_port] |
| |
| for port in ports: |
| in_vlan_id_1 = port + 1 |
| in_vlan_id_2 = port + 100 |
| in_vlan_id_3 = port + 300 |
| mpls_label_1 = port + 100 |
| mpls_label_2 = port + 200 |
| mpls_label_pw = port + 300 |
| port_to_in_vlan_1[port] = in_vlan_id_1 |
| port_to_in_vlan_2[port] = in_vlan_id_2 |
| port_to_in_vlan_3[port] = in_vlan_id_3 |
| src_mac = [ 0x00, 0x00, 0x00, 0x00, 0x11, port ] |
| src_mac_str = ':'.join( [ '%02X' % x for x in src_mac ] ) |
| dst_mac = [ 0x00, 0x00, 0x00, 0x11, 0x11, port ] |
| dst_mac_str = ':'.join( [ '%02X' % x for x in dst_mac ] ) |
| port_to_src_mac[port] = src_mac |
| port_to_src_mac_str[port] = src_mac_str |
| port_to_dst_mac[port] = dst_mac |
| port_to_dst_mac_str[port] = dst_mac_str |
| port_to_mpls_label_1[port] = mpls_label_1 |
| port_to_mpls_label_2[port] = mpls_label_2 |
| port_to_mpls_label_pw[port] = mpls_label_pw |
| |
| # add l2 interface group, we have to pop the VLAN; |
| l2_intf_gid, l2_intf_msg = add_one_l2_interface_group( |
| ctrl=controller, |
| port=out_port, |
| vlan_id=out_vlan, |
| is_tagged=False, |
| send_barrier=False |
| ) |
| Groups._put( l2_intf_gid ) |
| # add MPLS interface group |
| mpls_intf_gid, mpls_intf_msg = add_mpls_intf_group( |
| ctrl=controller, |
| ref_gid=l2_intf_gid, |
| dst_mac=port_to_dst_mac[in_port], |
| src_mac=port_to_src_mac[out_port], |
| vid=out_vlan, |
| index=in_port |
| ) |
| Groups._put( mpls_intf_gid ) |
| mpls_gid = mpls_intf_gid |
| # add MPLS tunnel label groups, the number depends on the labels |
| if mpls_labels == 2: |
| mpls_tunnel_gid, mpls_tunnel_msg = add_mpls_tunnel_label_group( |
| ctrl=controller, |
| ref_gid=mpls_intf_gid, |
| subtype=OF_DPA_MPLS_Tunnel_Label_2, |
| index=in_port, |
| label=port_to_mpls_label_2[in_port] |
| ) |
| Groups._put( mpls_tunnel_gid ) |
| mpls_tunnel_gid, mpls_tunnel_msg = add_mpls_tunnel_label_group( |
| ctrl=controller, |
| ref_gid=mpls_tunnel_gid, |
| subtype=OF_DPA_MPLS_Tunnel_Label_1, |
| index=in_port, |
| label=port_to_mpls_label_1[in_port] |
| ) |
| Groups._put( mpls_tunnel_gid ) |
| mpls_gid = mpls_tunnel_gid |
| elif mpls_labels == 1: |
| mpls_tunnel_gid, mpls_tunnel_msg = add_mpls_tunnel_label_group( |
| ctrl=controller, |
| ref_gid=mpls_intf_gid, |
| subtype=OF_DPA_MPLS_Tunnel_Label_1, |
| index=in_port, |
| label=port_to_mpls_label_1[in_port] |
| ) |
| Groups._put( mpls_tunnel_gid ) |
| mpls_gid = mpls_tunnel_gid |
| # add MPLS L2 VPN group |
| mpls_l2_vpn_gid, mpls_l2_vpn_msg = add_mpls_label_group( |
| ctrl=controller, |
| subtype=OF_DPA_MPLS_L2_VPN_Label, |
| index=in_port, |
| ref_gid=mpls_gid, |
| push_l2_header=True, |
| push_vlan=True, |
| push_mpls_header=True, |
| push_cw=True, |
| set_mpls_label=port_to_mpls_label_pw[in_port], |
| set_bos=1, |
| cpy_ttl_outward=True |
| ) |
| Groups._put( mpls_l2_vpn_gid ) |
| # add MPLS L2 port flow |
| add_mpls_l2_port_flow( |
| ctrl=controller, |
| of_port=in_port, |
| mpls_l2_port=in_port, |
| tunnel_index=1, |
| ref_gid=mpls_l2_vpn_gid |
| ) |
| # add VLAN flows table |
| if ingress_tags == 2: |
| if egress_tag == EGRESS_TAGGED: |
| add_one_vlan_1_table_flow_pw( |
| ctrl=controller, |
| of_port=in_port, |
| tunnel_index=1, |
| new_outer_vlan_id=-1, |
| outer_vlan_id=port_to_in_vlan_2[in_port], |
| inner_vlan_id=port_to_in_vlan_1[in_port], |
| ) |
| elif egress_tag == EGRESS_TAGGED_TRANS: |
| add_one_vlan_1_table_flow_pw( |
| ctrl=controller, |
| of_port=in_port, |
| tunnel_index=1, |
| new_outer_vlan_id=port_to_in_vlan_3[in_port], |
| outer_vlan_id=port_to_in_vlan_2[in_port], |
| inner_vlan_id=port_to_in_vlan_1[in_port], |
| ) |
| add_one_vlan_table_flow( |
| ctrl=controller, |
| of_port=in_port, |
| vlan_id=port_to_in_vlan_2[in_port], |
| flag=VLAN_TABLE_FLAG_ONLY_STACKED, |
| ) |
| elif ingress_tags == 1: |
| if egress_tag == EGRESS_TAGGED: |
| add_one_vlan_table_flow_pw( |
| ctrl=controller, |
| of_port=in_port, |
| tunnel_index=1, |
| vlan_id=port_to_in_vlan_1[in_port], |
| flag=VLAN_TABLE_FLAG_ONLY_TAG, |
| ) |
| elif egress_tag == EGRESS_TAGGED_TRANS: |
| add_one_vlan_table_flow_pw( |
| ctrl=controller, |
| of_port=in_port, |
| tunnel_index=1, |
| vlan_id=port_to_in_vlan_1[in_port], |
| new_vlan_id=port_to_in_vlan_3[in_port], |
| flag=VLAN_TABLE_FLAG_ONLY_TAG, |
| ) |
| elif ingress_tags == 0: |
| filter_dhcp(controller) |
| filter_ipv6(controller) |
| filter_igmp(controller) |
| if egress_tag == EGRESS_UNTAGGED: |
| add_one_vlan_table_flow_pw( |
| ctrl=controller, |
| of_port=in_port, |
| tunnel_index=1, |
| flag=VLAN_TABLE_FLAG_ONLY_UNTAG, |
| ) |
| elif egress_tag == EGRESS_TAGGED: |
| add_one_vlan_table_flow_pw( |
| ctrl=controller, |
| of_port=in_port, |
| tunnel_index=1, |
| vlan_id=port_to_in_vlan_1[in_port], |
| flag=VLAN_TABLE_FLAG_ONLY_UNTAG, |
| ) |
| |
| return ( |
| port_to_mpls_label_2, |
| port_to_mpls_label_1, |
| port_to_mpls_label_pw, |
| port_to_in_vlan_3, |
| port_to_in_vlan_2, |
| port_to_in_vlan_1, |
| port_to_src_mac_str, |
| port_to_dst_mac_str, |
| Groups |
| ) |
| |
| MPLS_FLOW_TABLE_0 = 23 |
| OF_DPA_MPLS_SWAP_Label = 5 |
| |
| def fill_pw_intermediate_transport_pipeline( |
| controller, |
| logging, |
| ports, |
| mpls_labels |
| ): |
| """ |
| This method, according to the scenario, fills properly |
| the pw pipeline. The method generates using ports data the |
| necessary information to fill the pw pipeline and |
| fills properly the pipeline which consists into: |
| |
| """ |
| |
| Groups = Queue.LifoQueue( ) |
| out_vlan = 4094 |
| port_to_src_mac = {} |
| port_to_src_mac_str = {} |
| port_to_dst_mac = {} |
| port_to_dst_mac_str = {} |
| port_to_mpls_label_2 = {} |
| port_to_mpls_label_1 = {} |
| port_to_mpls_label_pw = {} |
| port_to_switch_mac = {} |
| port_to_switch_mac_str = {} |
| |
| for port in ports: |
| mpls_label_1 = port + 10 |
| mpls_label_2 = port + 100 |
| mpls_label_pw = port + 300 |
| src_mac = [ 0x00, 0x00, 0x00, 0x00, 0x11, port ] |
| src_mac_str = ':'.join( [ '%02X' % x for x in src_mac ] ) |
| dst_mac = [ 0x00, 0x00, 0x00, 0x11, 0x11, port ] |
| dst_mac_str = ':'.join( [ '%02X' % x for x in dst_mac ] ) |
| switch_mac = [ 0x00, 0x00, 0x00, 0x00, 0x00, port ] |
| switch_mac_str = ':'.join( [ '%02X' % x for x in switch_mac ] ) |
| port_to_src_mac[port] = src_mac |
| port_to_src_mac_str[port] = src_mac_str |
| port_to_dst_mac[port] = dst_mac |
| port_to_dst_mac_str[port] = dst_mac_str |
| port_to_mpls_label_1[port] = mpls_label_1 |
| port_to_mpls_label_2[port] = mpls_label_2 |
| port_to_mpls_label_pw[port] = mpls_label_pw |
| port_to_switch_mac[port] = switch_mac |
| port_to_switch_mac_str[port] = switch_mac_str |
| |
| for pair in itertools.product(ports, ports): |
| in_port = pair[0] |
| out_port = pair[1] |
| if out_port == in_port: |
| continue |
| # add l2 interface group, we have to pop the VLAN; |
| l2_intf_gid, l2_intf_msg = add_one_l2_interface_group( |
| ctrl=controller, |
| port=out_port, |
| vlan_id=out_vlan, |
| is_tagged=False, |
| send_barrier=False |
| ) |
| Groups._put( l2_intf_gid ) |
| # add MPLS interface group |
| mpls_intf_gid, mpls_intf_msg = add_mpls_intf_group( |
| ctrl=controller, |
| ref_gid=l2_intf_gid, |
| dst_mac=port_to_dst_mac[in_port], |
| src_mac=port_to_src_mac[out_port], |
| vid=out_vlan, |
| index=in_port |
| ) |
| Groups._put( mpls_intf_gid ) |
| # add MPLS flows |
| if mpls_labels >=2: |
| add_mpls_flow_pw( |
| ctrl=controller, |
| action_group_id=mpls_intf_gid, |
| label=port_to_mpls_label_2[in_port], |
| ethertype=0x8847, |
| tunnel_index=1, |
| bos=0 |
| ) |
| else: |
| mpls_tunnel_gid, mpls_tunnel_msg = add_mpls_tunnel_label_group( |
| ctrl=controller, |
| ref_gid=mpls_intf_gid, |
| subtype=OF_DPA_MPLS_Tunnel_Label_2, |
| index=in_port, |
| label=port_to_mpls_label_2[in_port] |
| ) |
| Groups._put( mpls_tunnel_gid ) |
| mpls_tunnel_gid, mpls_tunnel_msg = add_mpls_tunnel_label_group( |
| ctrl=controller, |
| ref_gid=mpls_tunnel_gid, |
| subtype=OF_DPA_MPLS_Tunnel_Label_1, |
| index=in_port, |
| label=port_to_mpls_label_1[in_port] |
| ) |
| Groups._put( mpls_tunnel_gid ) |
| mpls_swap_gid, mpls_tunnel_msg = add_mpls_swap_label_group( |
| ctrl=controller, |
| ref_gid=mpls_tunnel_gid, |
| subtype=OF_DPA_MPLS_SWAP_Label, |
| index=in_port, |
| label=port_to_mpls_label_pw[in_port] |
| ) |
| Groups._put( mpls_swap_gid ) |
| add_mpls_flow_pw( |
| ctrl=controller, |
| action_group_id=mpls_swap_gid, |
| label=port_to_mpls_label_pw[in_port], |
| ethertype=0x8847, |
| tunnel_index=1, |
| bos=1, |
| popMPLS=False, |
| popL2=False |
| ) |
| # add Termination flow |
| add_termination_flow( |
| ctrl=controller, |
| in_port=in_port, |
| eth_type=0x8847, |
| dst_mac=port_to_switch_mac[in_port], |
| vlanid=out_vlan, |
| goto_table=MPLS_FLOW_TABLE_0) |
| # add VLAN flows |
| add_one_vlan_table_flow( |
| ctrl=controller, |
| of_port=in_port, |
| vlan_id=out_vlan, |
| flag=VLAN_TABLE_FLAG_ONLY_TAG, |
| ) |
| add_one_vlan_table_flow( |
| ctrl=controller, |
| of_port=in_port, |
| vlan_id=out_vlan, |
| flag=VLAN_TABLE_FLAG_ONLY_UNTAG |
| ) |
| |
| return ( |
| port_to_mpls_label_2, |
| port_to_mpls_label_1, |
| port_to_mpls_label_pw, |
| port_to_switch_mac_str, |
| port_to_src_mac_str, |
| port_to_dst_mac_str, |
| Groups |
| ) |
| |
| def fill_pw_termination_pipeline( |
| controller, |
| logging, |
| in_port, |
| out_port, |
| egress_tags |
| ): |
| """ |
| This method, according to the scenario, fills properly |
| the pw pipeline. The method generates using ports data the |
| necessary information to fill the pw pipeline and |
| fills properly the pipeline which consists into: |
| |
| """ |
| |
| Groups = Queue.LifoQueue( ) |
| out_vlan = 4094 |
| port_to_mpls_label_pw = {} |
| port_to_vlan_2 = {} |
| port_to_vlan_1 = {} |
| port_to_switch_mac = {} |
| port_to_switch_mac_str = {} |
| ports = [in_port, out_port] |
| |
| for port in ports: |
| mpls_label_pw = port + 300 |
| in_vlan_id_1 = port + 1 |
| in_vlan_id_2 = port + 100 |
| switch_mac = [ 0x00, 0x00, 0x00, 0x00, 0x11, port ] |
| switch_mac_str = ':'.join( [ '%02X' % x for x in switch_mac ] ) |
| port_to_mpls_label_pw[port] = mpls_label_pw |
| port_to_vlan_2[port] = in_vlan_id_2 |
| port_to_vlan_1[port] = in_vlan_id_1 |
| port_to_switch_mac[port] = switch_mac |
| port_to_switch_mac_str[port] = switch_mac_str |
| |
| # add l2 interface group; |
| if egress_tags == 2: |
| l2_intf_gid, l2_intf_msg = add_one_l2_interface_group( |
| ctrl=controller, |
| port=out_port, |
| vlan_id=port_to_vlan_2[out_port], |
| is_tagged=True, |
| send_barrier=False |
| ) |
| elif egress_tags == 1: |
| l2_intf_gid, l2_intf_msg = add_one_l2_interface_group( |
| ctrl=controller, |
| port=out_port, |
| vlan_id=port_to_vlan_1[out_port], |
| is_tagged=True, |
| send_barrier=False |
| ) |
| elif egress_tags == 0: |
| l2_intf_gid, l2_intf_msg = add_one_l2_interface_group( |
| ctrl=controller, |
| port=out_port, |
| vlan_id=port_to_vlan_1[out_port], |
| is_tagged=False, |
| send_barrier=False |
| ) |
| Groups._put( l2_intf_gid ) |
| add_mpls_flow_pw( |
| ctrl=controller, |
| action_group_id=l2_intf_gid, |
| label=port_to_mpls_label_pw[out_port], |
| ethertype=0x6558, |
| bos=1, |
| tunnel_index=1, |
| popMPLS=True, |
| popL2=True, |
| of_port=in_port |
| ) |
| # add Termination flow |
| add_termination_flow( |
| ctrl=controller, |
| in_port=in_port, |
| eth_type=0x8847, |
| dst_mac=port_to_switch_mac[in_port], |
| vlanid=out_vlan, |
| goto_table=MPLS_FLOW_TABLE_0) |
| # add VLAN flows |
| add_one_vlan_table_flow( |
| ctrl=controller, |
| of_port=in_port, |
| vlan_id=out_vlan, |
| flag=VLAN_TABLE_FLAG_ONLY_TAG, |
| ) |
| add_one_vlan_table_flow( |
| ctrl=controller, |
| of_port=in_port, |
| vlan_id=out_vlan, |
| flag=VLAN_TABLE_FLAG_ONLY_UNTAG |
| ) |
| |
| return ( |
| port_to_mpls_label_pw, |
| port_to_vlan_2, |
| port_to_vlan_1, |
| port_to_switch_mac_str, |
| Groups |
| ) |