def setUp()

in ptf/sairif.py [0:0]


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

        self.port10_rif_in = 0
        self.port10_rif_out = 0
        self.port11_rif_in = 0
        self.port11_rif_out = 0
        self.port30_bp = 0
        self.lag3_rif_in = 0
        self.lag3_rif_out = 0
        self.vlan600_rif_in = 0
        self.vlan600_rif_out = 0
        self.vlan700_rif_in = 0
        self.vlan700_rif_out = 0
        self.subport10_100_in = 0
        self.subport10_200_in = 0
        self.subport11_200_in = 0
        self.subport11_300_in = 0
        self.sublag3_400_in = 0
        self.sublag3_500_in = 0
        self.subport24_600_in = 0
        self.subport25_400_in = 0
        self.subport25_500_in = 0
        self.subport10_100_out = 0
        self.subport10_200_out = 0
        self.subport11_200_out = 0
        self.subport11_300_out = 0
        self.sublag3_400_out = 0
        self.sublag3_500_out = 0
        self.subport24_600_out = 0
        self.subport25_400_out = 0
        self.subport25_500_out = 0

        dmac0 = '00:11:22:33:44:55'
        dmac1 = '00:22:22:33:44:55'
        dmac2 = '00:33:22:33:44:55'
        dmac3 = '00:44:22:33:44:55'
        dmac4 = '00:55:22:33:44:55'
        mac_action = SAI_PACKET_ACTION_FORWARD

        # L3 RIF on port10, port11 and lag3
        self.nhop0 = sai_thrift_create_next_hop(
            self.client,
            ip=sai_ipaddress('10.10.10.1'),
            router_interface_id=self.port10_rif,
            type=SAI_NEXT_HOP_TYPE_IP)
        self.neighbor_entry0 = sai_thrift_neighbor_entry_t(
            rif_id=self.port10_rif, ip_address=sai_ipaddress('10.10.10.1'))
        sai_thrift_create_neighbor_entry(
            self.client, self.neighbor_entry0, dst_mac_address=dmac0)

        self.nhop1 = sai_thrift_create_next_hop(
            self.client,
            ip=sai_ipaddress('10.10.10.2'),
            router_interface_id=self.port11_rif,
            type=SAI_NEXT_HOP_TYPE_IP)
        self.neighbor_entry1 = sai_thrift_neighbor_entry_t(
            rif_id=self.port11_rif, ip_address=sai_ipaddress('10.10.10.2'))
        sai_thrift_create_neighbor_entry(
            self.client, self.neighbor_entry1, dst_mac_address=dmac1)

        self.nhop2 = sai_thrift_create_next_hop(
            self.client,
            ip=sai_ipaddress('10.10.10.3'),
            router_interface_id=self.lag3_rif,
            type=SAI_NEXT_HOP_TYPE_IP)
        self.neighbor_entry2 = sai_thrift_neighbor_entry_t(
            rif_id=self.lag3_rif, ip_address=sai_ipaddress('10.10.10.3'))
        sai_thrift_create_neighbor_entry(
            self.client, self.neighbor_entry2, dst_mac_address=dmac2)

        self.port24_bp = sai_thrift_create_bridge_port(
            self.client,
            bridge_id=self.default_1q_bridge,
            port_id=self.port24,
            type=SAI_BRIDGE_PORT_TYPE_PORT,
            admin_state=True)
        self.port25_bp = sai_thrift_create_bridge_port(
            self.client,
            bridge_id=self.default_1q_bridge,
            port_id=self.port25,
            type=SAI_BRIDGE_PORT_TYPE_PORT,
            admin_state=True)

        # add SVI on vlan600, port24 and vlan700, port 25
        self.vlan600 = sai_thrift_create_vlan(self.client, vlan_id=600)
        self.vlan_member601 = sai_thrift_create_vlan_member(
            self.client,
            vlan_id=self.vlan600,
            bridge_port_id=self.port24_bp,
            vlan_tagging_mode=SAI_VLAN_TAGGING_MODE_UNTAGGED)
        self.vlan600_rif = sai_thrift_create_router_interface(
            self.client,
            type=SAI_ROUTER_INTERFACE_TYPE_VLAN,
            virtual_router_id=self.default_vrf,
            vlan_id=self.vlan600)
        self.nhop3 = sai_thrift_create_next_hop(
            self.client,
            ip=sai_ipaddress('10.10.10.4'),
            router_interface_id=self.vlan600_rif,
            type=SAI_NEXT_HOP_TYPE_IP)
        self.neighbor_entry3 = sai_thrift_neighbor_entry_t(
            rif_id=self.vlan600_rif, ip_address=sai_ipaddress('10.10.10.4'))
        sai_thrift_create_neighbor_entry(
            self.client, self.neighbor_entry3, dst_mac_address=dmac3)
        self.fdb_entry3 = sai_thrift_fdb_entry_t(
            switch_id=self.switch_id, mac_address=dmac3, bv_id=self.vlan600)
        sai_thrift_create_fdb_entry(self.client,
                                    self.fdb_entry3,
                                    type=SAI_FDB_ENTRY_TYPE_STATIC,
                                    bridge_port_id=self.port24_bp,
                                    packet_action=mac_action)
        sai_thrift_set_port_attribute(
            self.client, self.port24, port_vlan_id=600)

        self.vlan700 = sai_thrift_create_vlan(self.client, vlan_id=700)
        self.vlan_member701 = sai_thrift_create_vlan_member(
            self.client,
            vlan_id=self.vlan700,
            bridge_port_id=self.port25_bp,
            vlan_tagging_mode=SAI_VLAN_TAGGING_MODE_TAGGED)
        self.vlan700_rif = sai_thrift_create_router_interface(
            self.client,
            type=SAI_ROUTER_INTERFACE_TYPE_VLAN,
            virtual_router_id=self.default_vrf,
            vlan_id=self.vlan700)
        self.nhop4 = sai_thrift_create_next_hop(
            self.client,
            ip=sai_ipaddress('10.10.10.5'),
            router_interface_id=self.vlan700_rif,
            type=SAI_NEXT_HOP_TYPE_IP)
        self.neighbor_entry4 = sai_thrift_neighbor_entry_t(
            rif_id=self.vlan700_rif, ip_address=sai_ipaddress('10.10.10.5'))
        sai_thrift_create_neighbor_entry(
            self.client, self.neighbor_entry4, dst_mac_address=dmac4)
        self.fdb_entry4 = sai_thrift_fdb_entry_t(
            switch_id=self.switch_id, mac_address=dmac4, bv_id=self.vlan700)
        sai_thrift_create_fdb_entry(self.client,
                                    self.fdb_entry4,
                                    type=SAI_FDB_ENTRY_TYPE_STATIC,
                                    bridge_port_id=self.port25_bp,
                                    packet_action=mac_action)

        # add subport 100, 200 on port10
        self.subport10_100 = sai_thrift_create_router_interface(
            self.client,
            type=SAI_ROUTER_INTERFACE_TYPE_SUB_PORT,
            virtual_router_id=self.default_vrf,
            port_id=self.port10,
            admin_v4_state=True,
            outer_vlan_id=100)
        self.nhop_sp10_100 = sai_thrift_create_next_hop(
            self.client,
            ip=sai_ipaddress('20.20.0.10'),
            router_interface_id=self.subport10_100,
            type=SAI_NEXT_HOP_TYPE_IP)
        self.neighbor_entry_sp10_100 = sai_thrift_neighbor_entry_t(
            rif_id=self.subport10_100, ip_address=sai_ipaddress('20.20.0.10'))
        sai_thrift_create_neighbor_entry(self.client,
                                         self.neighbor_entry_sp10_100,
                                         dst_mac_address="00:33:33:33:01:00")

        self.subport10_200 = sai_thrift_create_router_interface(
            self.client,
            type=SAI_ROUTER_INTERFACE_TYPE_SUB_PORT,
            virtual_router_id=self.default_vrf,
            port_id=self.port10,
            admin_v4_state=True,
            outer_vlan_id=200)
        self.nhop_sp10_200 = sai_thrift_create_next_hop(
            self.client,
            ip=sai_ipaddress('20.20.0.20'),
            router_interface_id=self.subport10_200,
            type=SAI_NEXT_HOP_TYPE_IP)
        self.neighbor_entry_sp10_200 = sai_thrift_neighbor_entry_t(
            rif_id=self.subport10_200, ip_address=sai_ipaddress('20.20.0.20'))
        sai_thrift_create_neighbor_entry(self.client,
                                         self.neighbor_entry_sp10_200,
                                         dst_mac_address="00:33:33:33:02:00")

        # add subport 200, 300 on port11
        self.subport11_200 = sai_thrift_create_router_interface(
            self.client,
            type=SAI_ROUTER_INTERFACE_TYPE_SUB_PORT,
            virtual_router_id=self.default_vrf,
            port_id=self.port11,
            admin_v4_state=True,
            outer_vlan_id=200)
        self.nhop_sp11_200 = sai_thrift_create_next_hop(
            self.client,
            ip=sai_ipaddress('20.20.1.20'),
            router_interface_id=self.subport11_200,
            type=SAI_NEXT_HOP_TYPE_IP)
        self.neighbor_entry_sp11_200 = sai_thrift_neighbor_entry_t(
            rif_id=self.subport11_200, ip_address=sai_ipaddress('20.20.1.20'))
        sai_thrift_create_neighbor_entry(self.client,
                                         self.neighbor_entry_sp11_200,
                                         dst_mac_address="00:33:33:33:12:00")

        self.subport11_300 = sai_thrift_create_router_interface(
            self.client,
            type=SAI_ROUTER_INTERFACE_TYPE_SUB_PORT,
            virtual_router_id=self.default_vrf,
            port_id=self.port11,
            admin_v4_state=True,
            outer_vlan_id=300)
        self.nhop_sp11_300 = sai_thrift_create_next_hop(
            self.client,
            ip=sai_ipaddress('20.20.1.30'),
            router_interface_id=self.subport11_300,
            type=SAI_NEXT_HOP_TYPE_IP)
        self.neighbor_entry_sp11_300 = sai_thrift_neighbor_entry_t(
            rif_id=self.subport11_300, ip_address=sai_ipaddress('20.20.1.30'))
        sai_thrift_create_neighbor_entry(self.client,
                                         self.neighbor_entry_sp11_300,
                                         dst_mac_address="00:33:33:33:13:00")

        # add subport 400, 500 on lag3
        self.sublag3_400 = sai_thrift_create_router_interface(
            self.client,
            type=SAI_ROUTER_INTERFACE_TYPE_SUB_PORT,
            virtual_router_id=self.default_vrf,
            port_id=self.lag3,
            admin_v4_state=True,
            outer_vlan_id=400)
        self.nhop_sl3_400 = sai_thrift_create_next_hop(
            self.client,
            ip=sai_ipaddress('20.20.0.40'),
            router_interface_id=self.sublag3_400,
            type=SAI_NEXT_HOP_TYPE_IP)
        self.neighbor_entry_sl3_400 = sai_thrift_neighbor_entry_t(
            rif_id=self.sublag3_400, ip_address=sai_ipaddress('20.20.0.40'))
        sai_thrift_create_neighbor_entry(self.client,
                                         self.neighbor_entry_sl3_400,
                                         dst_mac_address="00:33:33:33:04:00")

        self.sublag3_500 = sai_thrift_create_router_interface(
            self.client,
            type=SAI_ROUTER_INTERFACE_TYPE_SUB_PORT,
            virtual_router_id=self.default_vrf,
            port_id=self.lag3,
            admin_v4_state=True,
            outer_vlan_id=500)
        self.nhop_sl3_500 = sai_thrift_create_next_hop(
            self.client,
            ip=sai_ipaddress('20.20.0.50'),
            router_interface_id=self.sublag3_500,
            type=SAI_NEXT_HOP_TYPE_IP)

        self.neighbor_entry_sl3_500 = sai_thrift_neighbor_entry_t(
            rif_id=self.sublag3_500, ip_address=sai_ipaddress('20.20.0.50'))
        sai_thrift_create_neighbor_entry(self.client,
                                         self.neighbor_entry_sl3_500,
                                         dst_mac_address="00:33:33:33:05:00")

        # add subport 600 on port24, this port is untagged on vlan600
        self.subport24_600 = sai_thrift_create_router_interface(
            self.client,
            type=SAI_ROUTER_INTERFACE_TYPE_SUB_PORT,
            virtual_router_id=self.default_vrf,
            port_id=self.port24,
            admin_v4_state=True,
            outer_vlan_id=600)
        self.nhop_sp24_600 = sai_thrift_create_next_hop(
            self.client,
            ip=sai_ipaddress('20.20.3.60'),
            router_interface_id=self.subport24_600,
            type=SAI_NEXT_HOP_TYPE_IP)
        self.neighbor_entry_sp24_600 = sai_thrift_neighbor_entry_t(
            rif_id=self.subport24_600, ip_address=sai_ipaddress('20.20.3.60'))
        sai_thrift_create_neighbor_entry(self.client,
                                         self.neighbor_entry_sp24_600,
                                         dst_mac_address="00:33:33:33:36:00")

        # add subport 400, 500 on port25, this port is tagged on vlan700
        self.subport25_400 = sai_thrift_create_router_interface(
            self.client,
            type=SAI_ROUTER_INTERFACE_TYPE_SUB_PORT,
            virtual_router_id=self.default_vrf,
            port_id=self.port25,
            admin_v4_state=True,
            outer_vlan_id=400)
        self.nhop_sp25_400 = sai_thrift_create_next_hop(
            self.client,
            ip=sai_ipaddress('20.20.4.40'),
            router_interface_id=self.subport25_400,
            type=SAI_NEXT_HOP_TYPE_IP)
        self.neighbor_entry_sp25_400 = sai_thrift_neighbor_entry_t(
            rif_id=self.subport25_400, ip_address=sai_ipaddress('20.20.4.40'))
        sai_thrift_create_neighbor_entry(self.client,
                                         self.neighbor_entry_sp25_400,
                                         dst_mac_address="00:33:33:33:44:00")

        self.subport25_500 = sai_thrift_create_router_interface(
            self.client,
            type=SAI_ROUTER_INTERFACE_TYPE_SUB_PORT,
            virtual_router_id=self.default_vrf,
            port_id=self.port25,
            admin_v4_state=True,
            outer_vlan_id=500)
        self.nhop_sp25_500 = sai_thrift_create_next_hop(
            self.client,
            ip=sai_ipaddress('20.20.4.50'),
            router_interface_id=self.subport25_500,
            type=SAI_NEXT_HOP_TYPE_IP)
        self.neighbor_entry_sp25_500 = sai_thrift_neighbor_entry_t(
            rif_id=self.subport25_500, ip_address=sai_ipaddress('20.20.4.50'))
        sai_thrift_create_neighbor_entry(self.client,
                                         self.neighbor_entry_sp25_500,
                                         dst_mac_address="00:33:33:33:45:00")

        self.route_entry0 = sai_thrift_route_entry_t(
            vr_id=self.default_vrf, destination=sai_ipprefix('30.30.0.1/32'))
        sai_thrift_create_route_entry(
            self.client, self.route_entry0, next_hop_id=self.nhop0)

        self.route_entry1 = sai_thrift_route_entry_t(
            vr_id=self.default_vrf, destination=sai_ipprefix('30.30.1.1/32'))
        sai_thrift_create_route_entry(
            self.client, self.route_entry1, next_hop_id=self.nhop1)

        self.route_entry1_ipv6 = sai_thrift_route_entry_t(
            vr_id=self.default_vrf,
            destination=sai_ipprefix(
                '1234:5678:9abc:def0:4422:1133:5577:99aa/128'))
        sai_thrift_create_route_entry(
            self.client, self.route_entry1_ipv6, next_hop_id=self.nhop0)

        self.route_entry2 = sai_thrift_route_entry_t(
            vr_id=self.default_vrf, destination=sai_ipprefix('30.30.2.1/32'))
        sai_thrift_create_route_entry(
            self.client, self.route_entry2, next_hop_id=self.nhop2)

        self.route_entry3 = sai_thrift_route_entry_t(
            vr_id=self.default_vrf, destination=sai_ipprefix('30.30.3.1/32'))
        sai_thrift_create_route_entry(
            self.client, self.route_entry3, next_hop_id=self.nhop3)

        self.route_entry4 = sai_thrift_route_entry_t(
            vr_id=self.default_vrf, destination=sai_ipprefix('30.30.4.1/32'))
        sai_thrift_create_route_entry(
            self.client, self.route_entry4, next_hop_id=self.nhop4)

        self.route_entry_sp10_100 = sai_thrift_route_entry_t(
            vr_id=self.default_vrf, destination=sai_ipprefix('40.40.0.10/32'))
        sai_thrift_create_route_entry(self.client,
                                      self.route_entry_sp10_100,
                                      next_hop_id=self.nhop_sp10_100)

        self.route_entry_sp10_100_ipv6 = sai_thrift_route_entry_t(
            vr_id=self.default_vrf,
            destination=sai_ipprefix(
                '1234:5678:9abc:def0:4422:1133:5577:8899/128'))
        sai_thrift_create_route_entry(self.client,
                                      self.route_entry_sp10_100_ipv6,
                                      next_hop_id=self.nhop_sp10_100)

        self.route_entry_sp10_200 = sai_thrift_route_entry_t(
            vr_id=self.default_vrf, destination=sai_ipprefix('40.40.0.20/32'))
        sai_thrift_create_route_entry(self.client,
                                      self.route_entry_sp10_200,
                                      next_hop_id=self.nhop_sp10_200)

        self.route_entry_sp11_200 = sai_thrift_route_entry_t(
            vr_id=self.default_vrf, destination=sai_ipprefix('40.40.1.20/32'))
        sai_thrift_create_route_entry(self.client,
                                      self.route_entry_sp11_200,
                                      next_hop_id=self.nhop_sp11_200)

        self.route_entry_sp11_300 = sai_thrift_route_entry_t(
            vr_id=self.default_vrf, destination=sai_ipprefix('40.40.1.30/32'))
        sai_thrift_create_route_entry(self.client,
                                      self.route_entry_sp11_300,
                                      next_hop_id=self.nhop_sp11_300)

        self.route_entry_sl3_400 = sai_thrift_route_entry_t(
            vr_id=self.default_vrf, destination=sai_ipprefix('40.40.0.40/32'))
        sai_thrift_create_route_entry(self.client,
                                      self.route_entry_sl3_400,
                                      next_hop_id=self.nhop_sl3_400)

        self.route_entry_sl3_500 = sai_thrift_route_entry_t(
            vr_id=self.default_vrf, destination=sai_ipprefix('40.40.0.50/32'))
        sai_thrift_create_route_entry(self.client,
                                      self.route_entry_sl3_500,
                                      next_hop_id=self.nhop_sl3_500)

        self.route_entry_sp24_600 = sai_thrift_route_entry_t(
            vr_id=self.default_vrf, destination=sai_ipprefix('40.40.3.60/32'))
        sai_thrift_create_route_entry(self.client,
                                      self.route_entry_sp24_600,
                                      next_hop_id=self.nhop_sp24_600)

        self.route_entry_sp25_400 = sai_thrift_route_entry_t(
            vr_id=self.default_vrf, destination=sai_ipprefix('40.40.4.40/32'))
        sai_thrift_create_route_entry(self.client,
                                      self.route_entry_sp25_400,
                                      next_hop_id=self.nhop_sp25_400)

        self.route_entry_sp25_500 = sai_thrift_route_entry_t(
            vr_id=self.default_vrf, destination=sai_ipprefix('40.40.4.50/32'))
        sai_thrift_create_route_entry(self.client,
                                      self.route_entry_sp25_500,
                                      next_hop_id=self.nhop_sp25_500)

        # ECMP
        self.nhop_group = sai_thrift_create_next_hop_group(
            self.client, type=SAI_NEXT_HOP_GROUP_TYPE_ECMP)
        self.nhop_group_member1 = sai_thrift_create_next_hop_group_member(
            self.client, next_hop_group_id=self.nhop_group,
            next_hop_id=self.nhop_sp10_200)
        self.nhop_group_member2 = sai_thrift_create_next_hop_group_member(
            self.client, next_hop_group_id=self.nhop_group,
            next_hop_id=self.nhop_sp11_200)
        self.nhop_group_member3 = sai_thrift_create_next_hop_group_member(
            self.client, next_hop_group_id=self.nhop_group,
            next_hop_id=self.nhop_sl3_400)
        self.nhop_group_member4 = sai_thrift_create_next_hop_group_member(
            self.client, next_hop_group_id=self.nhop_group,
            next_hop_id=self.nhop_sp24_600)
        self.nhop_group_member5 = sai_thrift_create_next_hop_group_member(
            self.client, next_hop_group_id=self.nhop_group,
            next_hop_id=self.nhop_sp25_500)

        self.route_entry_ecmp = sai_thrift_route_entry_t(
            vr_id=self.default_vrf, destination=sai_ipprefix('60.60.60.0/16'))
        sai_thrift_create_route_entry(
            self.client, self.route_entry_ecmp, next_hop_id=self.nhop_group)