From ae2128299d54bf7fa5c5a1fb44e468b85ca1bea0 Mon Sep 17 00:00:00 2001 From: "Richard.Yu" Date: Sun, 15 May 2022 22:35:17 -0700 Subject: [PATCH] Add t0 configs: metadata, port (without serdes) (#10) Add two T0 configurations, metadata and port (without serdes) base on the config_db.json configuration file. Define the new setup method in T0 broadcom. Add a config file for the s6000_s1220_r0 Refactor the method for abstract the info from config.ini, make the key from the name to the index, which can map the the port index directly. Todo: Add the serdes config, which needs to read the config file and parse the info. Test done: Tested on the dut. --- ptf/platform_helper/brcm_t0_sai_helper.py | 234 +++++++++++++++++- .../broadcom/s6000_s1220-r0_port_config.ini | 33 +++ ptf/sai_base_test.py | 10 +- 3 files changed, 266 insertions(+), 11 deletions(-) create mode 100644 ptf/platform_helper/broadcom/s6000_s1220-r0_port_config.ini diff --git a/ptf/platform_helper/brcm_t0_sai_helper.py b/ptf/platform_helper/brcm_t0_sai_helper.py index 844ca4f1c..9ff1932c7 100644 --- a/ptf/platform_helper/brcm_t0_sai_helper.py +++ b/ptf/platform_helper/brcm_t0_sai_helper.py @@ -19,10 +19,16 @@ """ This file contains class for brcm specified functions. """ - +import pdb +from socket import AddressFamily from platform_helper.common_sai_helper import * # pylint: disable=wildcard-import; lgtm[py/polluting-import] -import pdb +DEFAULT_IP_V4_PREFIX = '0.0.0.0/0' +DEFAULT_IP_V6_PREFIX = '0000:0000:0000:0000:0000:0000:0000:0000' +#Todo make those two parameters from input +LOCAL_IP_128V6_PREFIX = 'fe80::f68e:38ff:fe16:bc75/128' +LOCAL_IP_10V6_PREFIX = 'fe80::/10' +PORT_MTU=9122 class BrcmT0SaiHelper(CommonSaiHelper): """ This class contains broadcom(brcm) specified functions for the platform setup and test context configuration. @@ -33,7 +39,7 @@ class BrcmT0SaiHelper(CommonSaiHelper): def normal_setup(self): """ - Setup method + Normal setup """ print("BrcmT0SaiHelper::normal_setup") self.start_switch() @@ -42,12 +48,19 @@ def normal_setup(self): def config_meta_port(self): """ - Entry point for configuring the meta and port configs. + Default configuation, with metadata and ports configurations. """ - attr = sai_thrift_get_switch_attribute(self.client, default_virtual_router_id=True) - self.default_vrf = attr['default_virtual_router_id'] - self.assertNotEqual(self.default_vrf, 0) - pdb.set_trace() + self.get_port_list() + self.create_default_route_intf() + self.get_default_1q_bridge() + self.get_default_vlan() + self.remove_vlan_member() + self.remove_bridge_port() + self.create_default_v4_v6_route_entry() + self.create_local_v6_route() + self.create_host_intf() + self.turn_on_port_admin_state() + #self.set_port_serdes() def start_switch(self): @@ -62,3 +75,208 @@ def start_switch(self): print("Waiting for switch to get ready, {} seconds ...".format(switch_init_wait)) time.sleep(switch_init_wait) + + + def get_port_list(self): + """ + Set the class variable port_list. + + Output variable: + self.port_list + """ + port_list = sai_thrift_object_list_t(count=100) + p_list = sai_thrift_get_switch_attribute( + self.client, port_list=port_list) + self.port_list = p_list['port_list'].idlist + + + def create_default_route_intf(self): + """ + Create default route interface on loop back interface. + + Output variables: + self.default_vrf + self.lpbk_intf + """ + print("Create loop back interface...") + attr = sai_thrift_get_switch_attribute(self.client, default_virtual_router_id=True) + self.default_vrf = attr['default_virtual_router_id'] + self.assertNotEqual(self.default_vrf, 0) + self.lpbk_intf = sai_thrift_create_router_interface( + self.client, type=SAI_ROUTER_INTERFACE_TYPE_LOOPBACK, + virtual_router_id=self.default_vrf) + self.assertEqual(self.status(), SAI_STATUS_SUCCESS) + + + def get_default_1q_bridge(self): + """ + Get defaule 1Q bridge. + + Output variables: + self.default_1q_bridge_id + """ + print("Get default 1Q bridge...") + def_attr = sai_thrift_get_switch_attribute( + self.client, default_1q_bridge_id=True) + self.default_1q_bridge_id = def_attr['default_1q_bridge_id'] + + + def get_default_vlan(self): + """ + Get defaule vlan. + + Output variables: + self.default_vlan_id + """ + print("Get default vlan...") + def_attr = sai_thrift_get_switch_attribute( + self.client, default_vlan_id=True) + self.default_vlan_id = def_attr['default_vlan_id'] + + + def remove_vlan_member(self): + """ + Remove vlan member when init the environment. + """ + print("Remove vlan and members...") + vlan_member_list = sai_thrift_object_list_t(count=100) + mbr_list = sai_thrift_get_vlan_attribute( + self.client, self.default_vlan_id, member_list=vlan_member_list) + vlan_members = mbr_list['SAI_VLAN_ATTR_MEMBER_LIST'].idlist + + for member in vlan_members: + sai_thrift_remove_vlan_member(self.client, vlan_member_oid=member) + self.assertEqual(self.status(), SAI_STATUS_SUCCESS) + + + def remove_bridge_port(): + """ + Remove bridge ports. + """ + print("Remove bridge ports...") + bridge_port_list = sai_thrift_object_list_t(count=100) + bp_list = sai_thrift_get_bridge_attribute( + self.client, self.default_1q_bridge_id, port_list=bridge_port_list) + bp_ports = bp_list['port_list'].idlist + for port in bp_ports: + sai_thrift_remove_bridge_port(self.client, port) + self.assertEqual(self.status(), SAI_STATUS_SUCCESS) + + + def create_default_v4_v6_route_entry(self): + """ + Create default v4 and v6 route entry. + + Output variable: + self.default_ipv6_route_entry + self.default_ipv4_route_entry + """ + print("Create default v4 & v6 route entry...") + v6_default = sai_thrift_ip_prefix_t( + addr_family=1, addr=sai_thrift_ip_addr_t(ip6=DEFAULT_IP_V6_PREFIX), + mask=sai_thrift_ip_addr_t(ip6=DEFAULT_IP_V6_PREFIX)) + entry = sai_thrift_route_entry_t( + vr_id=self.default_vrf, + destination=v6_default, + switch_id=self.switch_id) + self.default_ipv6_route_entry = sai_thrift_create_route_entry( + self.client, route_entry=entry, packet_action=SAI_PACKET_ACTION_DROP) + self.assertEqual(self.status(), SAI_STATUS_SUCCESS) + entry = sai_thrift_route_entry_t( + vr_id=self.default_vrf, + destination=sai_ipprefix(DEFAULT_IP_V4_PREFIX), + switch_id=self.switch_id) + self.default_ipv4_route_entry = sai_thrift_create_route_entry( + self.client, route_entry=entry, packet_action=SAI_PACKET_ACTION_DROP) + self.assertEqual(self.status(), SAI_STATUS_SUCCESS) + + + def create_local_v6_route(self): + """ + Create local v6 route base on the configuration of the actual switch. + + Output variable: + self.local_10v6_route_entry + self.local_128v6_route_entry + """ + #Todo make the v6 prefix from actual device config. + + print("Create Local V6 route...") + entry = sai_thrift_route_entry_t( + vr_id=self.default_vrf, + destination=sai_ipprefix(LOCAL_IP_10V6_PREFIX), + switch_id=self.switch_id) + self.local_10v6_route_entry = sai_thrift_create_route_entry( + self.client, route_entry=entry, packet_action=SAI_PACKET_ACTION_FORWARD) + self.assertEqual(self.status(), SAI_STATUS_SUCCESS) + entry = sai_thrift_route_entry_t( + vr_id=self.default_vrf, + destination=sai_ipprefix(LOCAL_IP_128V6_PREFIX), + switch_id=self.switch_id) + self.local_128v6_route_entry = sai_thrift_create_route_entry( + self.client, route_entry=entry, packet_action=SAI_PACKET_ACTION_FORWARD) + self.assertEqual(self.status(), SAI_STATUS_SUCCESS) + + + def create_host_intf(self): + """ + Craete host interface. + Steps: + 1. create host table entry + 2. create host interface trap + 3. set host interface base on the port_config.int (this file contains the lanes, name and index information.) + + Output variables: + self.host_intf_table_id + self.ports_config + self.port_to_hostif_map + self.hostifs + """ + print("Create Host intfs...") + self.host_intf_table_id = sai_thrift_create_hostif_table_entry( + self.client, type=SAI_HOSTIF_TABLE_ENTRY_TYPE_WILDCARD, + channel_type=SAI_HOSTIF_TABLE_ENTRY_CHANNEL_TYPE_NETDEV_PHYSICAL_PORT) + attr = sai_thrift_get_switch_attribute(self.client, default_trap_group=True) + self.default_trap_group = attr['default_trap_group'] + sai_thrift_create_hostif_trap( + self.client, trap_type=SAI_HOSTIF_TRAP_TYPE_TTL_ERROR, packet_action=SAI_PACKET_ACTION_TRAP, + trap_group=self.default_trap_group, trap_priority=0) + + self.ports_config = self.parsePortConfig( + self.test_params['port_config_ini']) + self.port_to_hostif_map = {} + self.hostifs = [] + for i, _ in enumerate(self.port_list): + try: + setattr(self, 'port%s' % i, self.port_list[i]) + hostif = sai_thrift_create_hostif( + self.client, + type=SAI_HOSTIF_TYPE_NETDEV, + obj_id=self.port_list[i], + name=self.ports_config[i]['name']) + setattr(self, 'host_if%s' % i, hostif) + self.port_to_hostif_map[i]=hostif + sai_thrift_set_hostif_attribute(self.client, hostif_oid=hostif, oper_status=False) + self.hostifs.append(hostif) + except BaseException as e: + print("Cannot create hostif, error : {}".format(e)) + + + def turn_on_port_admin_state(self): + """ + Turn on port admin state + """ + print("Set port...") + for i, port in enumerate(self.port_list): + sai_thrift_set_port_attribute( + self.client, port_oid=port, mtu=PORT_MTU, admin_state=True) + + + def set_port_serdes(self): + """ + Set prot Serdes. + """ + print("Recreate Port serdes...") + for i, port in enumerate(self.port_list): + sai_thrift_set_port_attribute( + self.client, port_oid=port, mtu=PORT_MTU, admin_state=True) diff --git a/ptf/platform_helper/broadcom/s6000_s1220-r0_port_config.ini b/ptf/platform_helper/broadcom/s6000_s1220-r0_port_config.ini new file mode 100644 index 000000000..48a98898a --- /dev/null +++ b/ptf/platform_helper/broadcom/s6000_s1220-r0_port_config.ini @@ -0,0 +1,33 @@ +# name lanes alias index speed +Ethernet0 29,30,31,32 fortyGigE0/0 0 40000 +Ethernet4 25,26,27,28 fortyGigE0/4 1 40000 +Ethernet8 37,38,39,40 fortyGigE0/8 2 40000 +Ethernet12 33,34,35,36 fortyGigE0/12 3 40000 +Ethernet16 41,42,43,44 fortyGigE0/16 4 40000 +Ethernet20 45,46,47,48 fortyGigE0/20 5 40000 +Ethernet24 5,6,7,8 fortyGigE0/24 6 40000 +Ethernet28 1,2,3,4 fortyGigE0/28 7 40000 +Ethernet32 9,10,11,12 fortyGigE0/32 8 40000 +Ethernet36 13,14,15,16 fortyGigE0/36 9 40000 +Ethernet40 21,22,23,24 fortyGigE0/40 10 40000 +Ethernet44 17,18,19,20 fortyGigE0/44 11 40000 +Ethernet48 49,50,51,52 fortyGigE0/48 12 40000 +Ethernet52 53,54,55,56 fortyGigE0/52 13 40000 +Ethernet56 61,62,63,64 fortyGigE0/56 14 40000 +Ethernet60 57,58,59,60 fortyGigE0/60 15 40000 +Ethernet64 65,66,67,68 fortyGigE0/64 16 40000 +Ethernet68 69,70,71,72 fortyGigE0/68 17 40000 +Ethernet72 77,78,79,80 fortyGigE0/72 18 40000 +Ethernet76 73,74,75,76 fortyGigE0/76 19 40000 +Ethernet80 105,106,107,108 fortyGigE0/80 20 40000 +Ethernet84 109,110,111,112 fortyGigE0/84 21 40000 +Ethernet88 117,118,119,120 fortyGigE0/88 22 40000 +Ethernet92 113,114,115,116 fortyGigE0/92 23 40000 +Ethernet96 121,122,123,124 fortyGigE0/96 24 40000 +Ethernet100 125,126,127,128 fortyGigE0/100 25 40000 +Ethernet104 85,86,87,88 fortyGigE0/104 26 40000 +Ethernet108 81,82,83,84 fortyGigE0/108 27 40000 +Ethernet112 89,90,91,92 fortyGigE0/112 28 40000 +Ethernet116 93,94,95,96 fortyGigE0/116 29 40000 +Ethernet120 97,98,99,100 fortyGigE0/120 30 40000 +Ethernet124 101,102,103,104 fortyGigE0/124 31 40000 diff --git a/ptf/sai_base_test.py b/ptf/sai_base_test.py index 5d94e27a4..5e705f922 100644 --- a/ptf/sai_base_test.py +++ b/ptf/sai_base_test.py @@ -519,8 +519,8 @@ def fec_str_to_int(fec): # add new ports from port config file self.ports_config = self.parsePortConfig( self.test_params['port_config_ini']) - for name, port in self.ports_config.items(): - print("Creating port: %s" % name) + for index, port in self.ports_config.items(): + print("Creating port: %s" % self.ports_config[index]) fec_mode = fec_str_to_int(port.get('fec', None)) auto_neg_mode = True if port.get( 'autoneg', "").lower() == "on" else False @@ -564,6 +564,7 @@ def parsePortConfig(self, port_config_file): """ ports = OrderedDict() try: + index = 0 with open(port_config_file) as conf: for line in conf: if line.startswith('#'): @@ -573,6 +574,7 @@ def parsePortConfig(self, port_config_file): tokens = line.split() if len(tokens) < 2: continue + name_index = titles.index('name') name = tokens[name_index] data = {} @@ -583,7 +585,9 @@ def parsePortConfig(self, port_config_file): data['lanes'] = [int(lane) for lane in data['lanes'].split(',')] data['speed'] = int(data['speed']) - ports[name] = data + data['name'] = name + ports[index] = data + index = index + 1 return ports except Exception as e: raise e