def setUp()

in ptf/saimpls.py [0:0]


    def setUp(self):
        super(MplsIpv4Test, self).setUp()

        ttl_value = 63
        exp_value = 5
        ipv4_1 = '10.10.10.1'
        ipv4_2 = '10.10.10.2'
        ipv4_3 = '10.10.10.3'
        ipv4_4 = '20.20.20.1'
        ipv4_5 = '30.30.30.1'
        ipv4_6 = '50.50.50.1'
        ipv4_7 = '70.70.70.1'
        ipv4_8 = '71.71.71.1'
        ipv4_9 = '72.72.72.1'
        ipv4_10 = '80.80.80.1'

        ipv4_subnet_1 = '10.10.10.1/32'
        ipv4_subnet_2 = '10.10.10.2/32'
        ipv4_subnet_3 = '10.10.10.3/32'
        ipv4_subnet_4 = '20.20.20.1/24'
        dmac = '00:11:22:33:44:55'

        # Ingress LER config
        self.ingress_rif = self.port10_rif
        self.egress_rif_1 = self.port11_rif

        label_list = [1000]
        label_list_t = sai_thrift_u32_list_t(
            count=len(label_list),
            uint32list=label_list)

        self.nhop_label_1 = sai_thrift_create_next_hop(
            self.client,
            ip=sai_ipaddress(ipv4_1),
            router_interface_id=self.egress_rif_1,
            type=SAI_NEXT_HOP_TYPE_MPLS,
            labelstack=label_list_t,
            outseg_ttl_mode=SAI_OUTSEG_TTL_MODE_PIPE,
            outseg_ttl_value=ttl_value,
            outseg_exp_value=exp_value,
            outseg_type=SAI_OUTSEG_TYPE_PUSH)

        label_list.append(2000)
        label_list_t = sai_thrift_u32_list_t(
            count=len(label_list),
            uint32list=label_list)

        self.nhop_label_2 = sai_thrift_create_next_hop(
            self.client,
            ip=sai_ipaddress(ipv4_2),
            router_interface_id=self.egress_rif_1,
            type=SAI_NEXT_HOP_TYPE_MPLS,
            labelstack=label_list_t,
            outseg_ttl_mode=SAI_OUTSEG_TTL_MODE_PIPE,
            outseg_ttl_value=ttl_value,
            outseg_exp_value=exp_value,
            outseg_type=SAI_OUTSEG_TYPE_PUSH)

        label_list.append(3000)
        label_list_t = sai_thrift_u32_list_t(
            count=len(label_list),
            uint32list=label_list)

        self.nhop_label_3 = sai_thrift_create_next_hop(
            self.client,
            ip=sai_ipaddress(ipv4_3),
            router_interface_id=self.egress_rif_1,
            type=SAI_NEXT_HOP_TYPE_MPLS,
            labelstack=label_list_t,
            outseg_ttl_mode=SAI_OUTSEG_TTL_MODE_PIPE,
            outseg_ttl_value=ttl_value,
            outseg_exp_value=exp_value,
            outseg_type=SAI_OUTSEG_TYPE_PUSH)

        # note: neighbor with the same dst_ip as MPLS nexthop has to be created
        # after MPLS nexthop is created,
        # if not it will create second nexthop of type IP with this dst_ip
        # and neither of them will be functioning correctly - packets
        # will be gleaned to CPU
        self.mpls_neighbor_entry_1 = sai_thrift_neighbor_entry_t(
            rif_id=self.egress_rif_1, ip_address=sai_ipaddress(ipv4_1))
        status = sai_thrift_create_neighbor_entry(
            self.client, self.mpls_neighbor_entry_1, dst_mac_address=dmac,
            no_host_route=True)
        self.assertEqual(status, SAI_STATUS_SUCCESS)

        self.mpls_neighbor_entry_2 = sai_thrift_neighbor_entry_t(
            rif_id=self.egress_rif_1, ip_address=sai_ipaddress(ipv4_2))
        status = sai_thrift_create_neighbor_entry(
            self.client, self.mpls_neighbor_entry_2, dst_mac_address=dmac,
            no_host_route=True)
        self.assertEqual(status, SAI_STATUS_SUCCESS)

        self.mpls_neighbor_entry_3 = sai_thrift_neighbor_entry_t(
            rif_id=self.egress_rif_1, ip_address=sai_ipaddress(ipv4_3))
        status = sai_thrift_create_neighbor_entry(
            self.client, self.mpls_neighbor_entry_3, dst_mac_address=dmac,
            no_host_route=True)
        self.assertEqual(status, SAI_STATUS_SUCCESS)

        self.mpls_encap_route_1 = sai_thrift_route_entry_t(
            vr_id=self.default_vrf, destination=sai_ipprefix(ipv4_subnet_1))
        sai_thrift_create_route_entry(
            self.client, self.mpls_encap_route_1,
            next_hop_id=self.nhop_label_1)

        self.mpls_encap_route_2 = sai_thrift_route_entry_t(
            vr_id=self.default_vrf, destination=sai_ipprefix(ipv4_subnet_2))
        sai_thrift_create_route_entry(
            self.client, self.mpls_encap_route_2,
            next_hop_id=self.nhop_label_2)

        self.mpls_encap_route_3 = sai_thrift_route_entry_t(
            vr_id=self.default_vrf, destination=sai_ipprefix(ipv4_subnet_3))
        sai_thrift_create_route_entry(
            self.client, self.mpls_encap_route_3,
            next_hop_id=self.nhop_label_3)

        # MPLS egress LER term config
        self.egress_rif_2 = self.port12_rif

        self.vrf = sai_thrift_create_virtual_router(self.client)

        self.egress_rif_vrf = sai_thrift_create_router_interface(
            self.client,
            type=SAI_ROUTER_INTERFACE_TYPE_PORT,
            port_id=self.port24,
            virtual_router_id=self.default_vrf)

        self.mpls_rif = sai_thrift_create_router_interface(
            self.client,
            type=SAI_ROUTER_INTERFACE_TYPE_MPLS_ROUTER,
            virtual_router_id=self.default_vrf)

        self.nhop_vrf = sai_thrift_create_next_hop(
            self.client,
            ip=sai_ipaddress(ipv4_4),
            router_interface_id=self.egress_rif_vrf,
            type=SAI_NEXT_HOP_TYPE_IP)
        self.neighbor_entry_vrf = sai_thrift_neighbor_entry_t(
            rif_id=self.egress_rif_vrf, ip_address=sai_ipaddress(ipv4_4))
        sai_thrift_create_neighbor_entry(
            self.client, self.neighbor_entry_vrf, dst_mac_address=dmac,
            no_host_route=True)
        self.route_entry_vrf = sai_thrift_route_entry_t(
            vr_id=self.vrf, destination=sai_ipprefix(ipv4_subnet_4))
        sai_thrift_create_route_entry(
            self.client, self.route_entry_vrf, next_hop_id=self.nhop_vrf)

        self.nhop_1 = sai_thrift_create_next_hop(
            self.client,
            ip=sai_ipaddress(ipv4_4),
            router_interface_id=self.egress_rif_2,
            type=SAI_NEXT_HOP_TYPE_IP)
        self.neighbor_entry_1 = sai_thrift_neighbor_entry_t(
            rif_id=self.egress_rif_2, ip_address=sai_ipaddress(ipv4_4))
        sai_thrift_create_neighbor_entry(
            self.client, self.neighbor_entry_1, dst_mac_address=dmac,
            no_host_route=True)
        self.route_entry_1 = sai_thrift_route_entry_t(
            vr_id=self.default_vrf, destination=sai_ipprefix(ipv4_subnet_4))
        sai_thrift_create_route_entry(
            self.client, self.route_entry_1, next_hop_id=self.nhop_1)

        self.inseg_entry_1000 = sai_thrift_inseg_entry_t(label=1000)
        status = sai_thrift_create_inseg_entry(
            self.client, self.inseg_entry_1000,
            num_of_pop=1,
            pop_ttl_mode=SAI_INSEG_ENTRY_POP_TTL_MODE_PIPE,
            next_hop_id=self.mpls_rif)
        self.assertEqual(status, SAI_STATUS_SUCCESS)

        # MPLS Egress LER Null Term configs
        self.inseg_entry_0 = sai_thrift_inseg_entry_t(label=0)
        status = sai_thrift_create_inseg_entry(
            self.client, self.inseg_entry_0,
            num_of_pop=1,
            pop_ttl_mode=SAI_INSEG_ENTRY_POP_TTL_MODE_PIPE,
            next_hop_id=self.mpls_rif)
        self.assertEqual(status, SAI_STATUS_SUCCESS)

        # MPLS Egress PHP configs
        self.egress_rif_3 = self.port13_rif

        self.nhop_2 = sai_thrift_create_next_hop(
            self.client,
            ip=sai_ipaddress(ipv4_4),
            router_interface_id=self.egress_rif_3,
            type=SAI_NEXT_HOP_TYPE_IP)

        self.neighbor_entry_2 = sai_thrift_neighbor_entry_t(
            rif_id=self.egress_rif_3, ip_address=sai_ipaddress(ipv4_4))
        status = sai_thrift_create_neighbor_entry(
            self.client, self.neighbor_entry_2, dst_mac_address=dmac,
            no_host_route=True)
        self.assertEqual(status, SAI_STATUS_SUCCESS)

        self.inseg_entry_2000 = sai_thrift_inseg_entry_t(label=2000)
        status = sai_thrift_create_inseg_entry(
            self.client, self.inseg_entry_2000,
            num_of_pop=1,
            pop_ttl_mode=SAI_INSEG_ENTRY_POP_TTL_MODE_UNIFORM,
            next_hop_id=self.nhop_2)
        self.assertEqual(status, SAI_STATUS_SUCCESS)

        self.inseg_entry_2111 = sai_thrift_inseg_entry_t(label=2111)
        status = sai_thrift_create_inseg_entry(
            self.client, self.inseg_entry_2111,
            num_of_pop=2,
            pop_ttl_mode=SAI_INSEG_ENTRY_POP_TTL_MODE_UNIFORM,
            next_hop_id=self.nhop_2)
        self.assertEqual(status, SAI_STATUS_SUCCESS)

        self.inseg_entry_2222 = sai_thrift_inseg_entry_t(label=2222)
        status = sai_thrift_create_inseg_entry(
            self.client, self.inseg_entry_2222,
            num_of_pop=3,
            pop_ttl_mode=SAI_INSEG_ENTRY_POP_TTL_MODE_UNIFORM,
            next_hop_id=self.nhop_2)
        self.assertEqual(status, SAI_STATUS_SUCCESS)

        # MPLS Egress PHP Swap Null configs
        self.egress_rif_4 = sai_thrift_create_router_interface(
            self.client,
            type=SAI_ROUTER_INTERFACE_TYPE_PORT,
            port_id=self.port25,
            virtual_router_id=self.default_vrf)

        label_list = [0]
        label_list_t = sai_thrift_u32_list_t(
            count=len(label_list),
            uint32list=label_list)

        self.nhop_label_4 = sai_thrift_create_next_hop(
            self.client,
            ip=sai_ipaddress(ipv4_5),
            router_interface_id=self.egress_rif_4,
            type=SAI_NEXT_HOP_TYPE_MPLS,
            labelstack=label_list_t,
            outseg_ttl_mode=SAI_OUTSEG_TTL_MODE_PIPE,
            outseg_ttl_value=ttl_value,
            outseg_type=SAI_OUTSEG_TYPE_SWAP)

        self.mpls_neighbor_entry_4 = sai_thrift_neighbor_entry_t(
            rif_id=self.egress_rif_4, ip_address=sai_ipaddress(ipv4_5))
        status = sai_thrift_create_neighbor_entry(
            self.client, self.mpls_neighbor_entry_4, dst_mac_address=dmac,
            no_host_route=True)
        self.assertEqual(status, SAI_STATUS_SUCCESS)

        self.inseg_entry_3000 = sai_thrift_inseg_entry_t(label=3000)
        status = sai_thrift_create_inseg_entry(
            self.client, self.inseg_entry_3000,
            next_hop_id=self.nhop_label_4)
        self.assertEqual(status, SAI_STATUS_SUCCESS)

        # MPLS Transit Swap configs
        self.egress_rif_5 = sai_thrift_create_router_interface(
            self.client,
            type=SAI_ROUTER_INTERFACE_TYPE_PORT,
            port_id=self.port26,
            virtual_router_id=self.default_vrf)

        label_list = [0]
        label_list_t = sai_thrift_u32_list_t(
            count=len(label_list),
            uint32list=label_list)

        self.nhop_label_5 = sai_thrift_create_next_hop(
            self.client,
            ip=sai_ipaddress(ipv4_6),
            router_interface_id=self.egress_rif_5,
            type=SAI_NEXT_HOP_TYPE_MPLS,
            labelstack=label_list_t,
            outseg_type=SAI_OUTSEG_TYPE_SWAP)

        self.mpls_neighbor_entry_5 = sai_thrift_neighbor_entry_t(
            rif_id=self.egress_rif_5, ip_address=sai_ipaddress(ipv4_6))
        status = sai_thrift_create_neighbor_entry(
            self.client, self.mpls_neighbor_entry_5, dst_mac_address=dmac,
            no_host_route=True)
        self.assertEqual(status, SAI_STATUS_SUCCESS)

        self.inseg_entry_5000 = sai_thrift_inseg_entry_t(label=5000)
        status = sai_thrift_create_inseg_entry(
            self.client, self.inseg_entry_5000,
            next_hop_id=self.nhop_label_5)
        self.assertEqual(status, SAI_STATUS_SUCCESS)

        # MLPS ECMP Swap configs
        self.egress_rif_6 = sai_thrift_create_router_interface(
            self.client,
            type=SAI_ROUTER_INTERFACE_TYPE_PORT,
            port_id=self.port27,
            virtual_router_id=self.default_vrf)

        self.egress_rif_7 = sai_thrift_create_router_interface(
            self.client,
            type=SAI_ROUTER_INTERFACE_TYPE_PORT,
            port_id=self.port28,
            virtual_router_id=self.default_vrf)

        self.egress_rif_8 = sai_thrift_create_router_interface(
            self.client,
            type=SAI_ROUTER_INTERFACE_TYPE_PORT,
            port_id=self.port29,
            virtual_router_id=self.default_vrf)

        label_list = [7070]
        label_list_t = sai_thrift_u32_list_t(
            count=len(label_list),
            uint32list=label_list)

        self.nhop_label_6 = sai_thrift_create_next_hop(
            self.client,
            ip=sai_ipaddress(ipv4_7),
            router_interface_id=self.egress_rif_6,
            type=SAI_NEXT_HOP_TYPE_MPLS,
            labelstack=label_list_t,
            outseg_type=SAI_OUTSEG_TYPE_SWAP)

        label_list = [7171]
        label_list_t = sai_thrift_u32_list_t(
            count=len(label_list),
            uint32list=label_list)

        self.nhop_label_7 = sai_thrift_create_next_hop(
            self.client,
            ip=sai_ipaddress(ipv4_8),
            router_interface_id=self.egress_rif_7,
            type=SAI_NEXT_HOP_TYPE_MPLS,
            labelstack=label_list_t,
            outseg_type=SAI_OUTSEG_TYPE_SWAP)

        label_list = [7272]
        label_list_t = sai_thrift_u32_list_t(
            count=len(label_list),
            uint32list=label_list)

        self.nhop_label_8 = sai_thrift_create_next_hop(
            self.client,
            ip=sai_ipaddress(ipv4_9),
            router_interface_id=self.egress_rif_8,
            type=SAI_NEXT_HOP_TYPE_MPLS,
            labelstack=label_list_t,
            outseg_type=SAI_OUTSEG_TYPE_SWAP)

        self.ecmp_group = sai_thrift_create_next_hop_group(
            self.client, type=SAI_NEXT_HOP_GROUP_TYPE_ECMP)
        self.ecmp_mbr1 = sai_thrift_create_next_hop_group_member(
            self.client, next_hop_group_id=self.ecmp_group,
            next_hop_id=self.nhop_label_6)
        self.ecmp_mbr2 = sai_thrift_create_next_hop_group_member(
            self.client, next_hop_group_id=self.ecmp_group,
            next_hop_id=self.nhop_label_7)
        self.ecmp_mbr3 = sai_thrift_create_next_hop_group_member(
            self.client, next_hop_group_id=self.ecmp_group,
            next_hop_id=self.nhop_label_8)

        self.mpls_neighbor_entry_6 = sai_thrift_neighbor_entry_t(
            rif_id=self.egress_rif_6, ip_address=sai_ipaddress(ipv4_7))
        status = sai_thrift_create_neighbor_entry(
            self.client, self.mpls_neighbor_entry_6, dst_mac_address=dmac,
            no_host_route=True)
        self.assertEqual(status, SAI_STATUS_SUCCESS)

        self.mpls_neighbor_entry_7 = sai_thrift_neighbor_entry_t(
            rif_id=self.egress_rif_7, ip_address=sai_ipaddress(ipv4_8))
        status = sai_thrift_create_neighbor_entry(
            self.client, self.mpls_neighbor_entry_7, dst_mac_address=dmac,
            no_host_route=True)
        self.assertEqual(status, SAI_STATUS_SUCCESS)

        self.mpls_neighbor_entry_8 = sai_thrift_neighbor_entry_t(
            rif_id=self.egress_rif_8, ip_address=sai_ipaddress(ipv4_9))
        status = sai_thrift_create_neighbor_entry(
            self.client, self.mpls_neighbor_entry_8, dst_mac_address=dmac,
            no_host_route=True)
        self.assertEqual(status, SAI_STATUS_SUCCESS)

        self.inseg_entry_7000 = sai_thrift_inseg_entry_t(label=7000)
        status = sai_thrift_create_inseg_entry(
            self.client, self.inseg_entry_7000,
            next_hop_id=self.ecmp_group)
        self.assertEqual(status, SAI_STATUS_SUCCESS)

        # MPLS Transit Push configs
        self.egress_rif_9 = sai_thrift_create_router_interface(
            self.client,
            type=SAI_ROUTER_INTERFACE_TYPE_PORT,
            port_id=self.port30,
            virtual_router_id=self.default_vrf)

        label_list = [9000]
        label_list_t = sai_thrift_u32_list_t(
            count=len(label_list),
            uint32list=label_list)

        self.nhop_label_9 = sai_thrift_create_next_hop(
            self.client,
            ip=sai_ipaddress(ipv4_10),
            router_interface_id=self.egress_rif_9,
            type=SAI_NEXT_HOP_TYPE_MPLS,
            labelstack=label_list_t,
            outseg_ttl_mode=SAI_OUTSEG_TTL_MODE_PIPE,
            outseg_ttl_value=ttl_value,
            outseg_exp_value=exp_value,
            outseg_type=SAI_OUTSEG_TYPE_PUSH)

        self.mpls_neighbor_entry_9 = sai_thrift_neighbor_entry_t(
            rif_id=self.egress_rif_9, ip_address=sai_ipaddress(ipv4_10))
        status = sai_thrift_create_neighbor_entry(
            self.client, self.mpls_neighbor_entry_9, dst_mac_address=dmac,
            no_host_route=True)
        self.assertEqual(status, SAI_STATUS_SUCCESS)

        self.inseg_entry_8000 = sai_thrift_inseg_entry_t(label=8000)
        status = sai_thrift_create_inseg_entry(
            self.client, self.inseg_entry_8000,
            next_hop_id=self.nhop_label_9)
        self.assertEqual(status, SAI_STATUS_SUCCESS)

        # packet counters settings
        for rif in [self.ingress_rif, self.egress_rif_1, self.egress_rif_2,
                    self.egress_rif_3, self.egress_rif_4, self.egress_rif_5,
                    self.egress_rif_9, self.egress_rif_vrf, self.mpls_rif]:
            status = clear_counter(
                    self, sai_thrift_clear_router_interface_stats, rif)
            self.assertEqual(status, SAI_STATUS_SUCCESS)

        self.ingress_rif_in_stats = 0     # port 10
        self.ingress_rif_out_stats = 0
        self.egress_rif_1_in_stats = 0    # port 11
        self.egress_rif_1_out_stats = 0
        self.egress_rif_2_in_stats = 0    # port 12
        self.egress_rif_2_out_stats = 0
        self.egress_rif_3_in_stats = 0    # port 13
        self.egress_rif_3_out_stats = 0
        self.egress_rif_4_in_stats = 0    # port 25
        self.egress_rif_4_out_stats = 0
        self.egress_rif_5_in_stats = 0    # port 26
        self.egress_rif_5_out_stats = 0
        self.egress_rif_vrf_in_stats = 0  # port 24
        self.egress_rif_vrf_out_stats = 0
        self.egress_rif_9_in_stats = 0    # port 30
        self.egress_rif_9_out_stats = 0
        self.mpls_rif_in_stats = 0
        self.mpls_rif_out_stats = 0