-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Common functions for Multi ASIC CLIs #4973
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
0c7d22f
0620982
00e34d0
b133dc1
3c671c1
51adf86
4985d2d
525b6b4
2af6005
3028347
c249599
c69a6c3
ea16670
2e5bc12
413b06d
6a3009c
7628bbd
b4837ff
cabc2f3
789a548
b65012e
f1814c5
f1a4f07
0b0cfd5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
| from natsort import natsorted | ||
| import glob | ||
| from swsssdk import ConfigDBConnector, SonicDBConfig | ||
| from portconfig import get_port_config | ||
|
|
||
| DOCUMENTATION = ''' | ||
| --- | ||
|
|
@@ -26,6 +27,13 @@ | |
| ASIC_CONF_FILENAME = 'asic.conf' | ||
| FRONTEND_ASIC_SUB_ROLE = 'FrontEnd' | ||
| BACKEND_ASIC_SUB_ROLE = 'BackEnd' | ||
| EXTERNAL_PORT = 'E' | ||
| INTERNAL_PORT = 'I' | ||
| PORT_CHANNEL_CFG_DB_TABLE = 'PORTCHANNEL' | ||
| PORT_CFG_DB_TABLE = 'PORT' | ||
| BGP_NEIGH_CFG_DB_TABLE = 'BGP_NEIGHBOR' | ||
| NEIGH_DEVICE_METADATA_CFG_DB_TABLE = "DEVICE_NEIGHBOR_METADATA" | ||
|
|
||
| def get_machine_info(): | ||
| if not os.path.isfile('/host/machine.conf'): | ||
| return None | ||
|
|
@@ -125,6 +133,79 @@ def get_all_namespaces(): | |
|
|
||
| return {'front_ns':front_ns, 'back_ns':back_ns} | ||
|
|
||
| def get_port_config_from_all_asics(): | ||
| if not is_multi_npu(): | ||
| return get_port_config() | ||
|
|
||
| platform = get_platform() | ||
| hwsku = get_hwsku() | ||
| all_ports = {} | ||
| ns_list = get_namespaces() | ||
|
|
||
| for ns in ns_list: | ||
| asic_id = get_npu_id_from_name(ns) | ||
| (ports, _, _) = get_port_config(hwsku=hwsku, platform=platform, asic=asic_id) | ||
| all_ports.update(ports) | ||
|
|
||
| return all_ports | ||
|
|
||
| def get_port_role(port_name): | ||
| ports_config = get_port_config_from_all_asics() | ||
| if not ports_config[port_name].has_key('role'): | ||
| return EXTERNAL_PORT | ||
|
|
||
| role = ports_config[port_name]['role'] | ||
| return role | ||
|
|
||
| def is_port_internal(port_name): | ||
| role = get_port_role(port_name) | ||
| if role is INTERNAL_PORT: | ||
| return True | ||
| return False | ||
|
|
||
| def is_port_channel_internal(port_channel, namespace=None): | ||
| if not is_multi_npu(): | ||
| return False | ||
| if namespace is None: | ||
| ns_list = get_namespaces() | ||
| else: | ||
| ns_list = [namespace] | ||
|
|
||
| for ns in ns_list: | ||
| config_db = ConfigDBConnector(use_unix_socket_path=True, namespace=ns) | ||
| config_db.connect() | ||
| #import pdb; pdb.set_trace() | ||
| port_channels = config_db.get_table(PORT_CHANNEL_CFG_DB_TABLE) | ||
| if not port_channels.has_key(port_channel): | ||
| continue | ||
| members = port_channels[port_channel]['members'] | ||
| if is_port_internal(members[0]): | ||
| return True | ||
|
||
| return False | ||
|
|
||
| def is_bgp_session_internal(bgp_neigh_ip, namespace=None): | ||
| if not is_multi_npu(): | ||
| return False | ||
|
|
||
| if namespace is None: | ||
| ns_list = get_namespaces() | ||
| else: | ||
| ns_list = [namespace] | ||
|
||
|
|
||
| for ns in ns_list: | ||
| config_db = ConfigDBConnector(use_unix_socket_path=True, namespace=ns) | ||
| config_db.connect() | ||
| bgp_sessions = config_db.get_table(BGP_NEIGH_CFG_DB_TABLE) | ||
| if not bgp_sessions.has_key(bgp_neigh_ip): | ||
| continue | ||
| bgp_neigh_name = bgp_sessions[bgp_neigh_ip]['name'] | ||
| neighbor_metadata = config_db.get_table(NEIGH_DEVICE_METADATA_CFG_DB_TABLE) | ||
| if neighbor_metadata[bgp_neigh_name]['type'].lower() == 'asic': | ||
| return True | ||
|
||
| else: | ||
| return False | ||
| return False | ||
|
|
||
| def get_platform_info(machine_info): | ||
| if machine_info != None: | ||
| if machine_info.has_key('onie_platform'): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,9 @@ | ||
| # name lanes alias asic_port_name | ||
| Ethernet0 33,34,35,36 Ethernet1/1 Eth0-ASIC0 | ||
| Ethernet4 29,30,31,32 Ethernet1/2 Eth1-ASIC0 | ||
| Ethernet8 41,42,43,44 Ethernet1/3 Eth2-ASIC0 | ||
| Ethernet12 37,38,39,40 Ethernet1/4 Eth3-ASIC0 | ||
| Ethernet-BP0 13,14,15,16 Ethernet-BP0 Eth4-ASIC0 | ||
| Ethernet-BP4 17,18,19,20 Ethernet-BP4 Eth5-ASIC0 | ||
| Ethernet-BP8 21,22,23,24 Ethernet-BP8 Eth6-ASIC0 | ||
| Ethernet-BP12 25,26,27,28 Ethernet-BP12 Eth7-ASIC0 | ||
| # name lanes alias asic_port_name role | ||
| Ethernet0 33,34,35,36 Ethernet1/1 Eth0-ASIC0 E | ||
|
||
| Ethernet4 29,30,31,32 Ethernet1/2 Eth1-ASIC0 E | ||
| Ethernet8 41,42,43,44 Ethernet1/3 Eth2-ASIC0 E | ||
| Ethernet12 37,38,39,40 Ethernet1/4 Eth3-ASIC0 E | ||
| Ethernet-BP0 13,14,15,16 Ethernet-BP0 Eth4-ASIC0 I | ||
| Ethernet-BP4 17,18,19,20 Ethernet-BP4 Eth5-ASIC0 I | ||
| Ethernet-BP8 21,22,23,24 Ethernet-BP8 Eth6-ASIC0 I | ||
| Ethernet-BP12 25,26,27,28 Ethernet-BP12 Eth7-ASIC0 I | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,9 @@ | ||
| # name lanes alias asic_port_name | ||
| Ethernet16 33,34,35,36 Ethernet1/5 Eth0-ASIC1 | ||
| Ethernet20 29,30,31,32 Ethernet1/6 Eth1-ASIC1 | ||
| Ethernet24 41,42,43,44 Ethernet1/7 Eth2-ASIC1 | ||
| Ethernet28 37,38,39,40 Ethernet1/8 Eth3-ASIC1 | ||
| Ethernet-BP16 13,14,15,16 Ethernet-BP16 Eth4-ASIC1 | ||
| Ethernet-BP20 17,18,19,20 Ethernet-BP20 Eth5-ASIC1 | ||
| Ethernet-BP24 21,22,23,24 Ethernet-BP24 Eth6-ASIC1 | ||
| Ethernet-BP28 25,26,27,28 Ethernet-BP28 Eth7-ASIC1 | ||
| # name lanes alias asic_port_name role | ||
| Ethernet16 33,34,35,36 Ethernet1/5 Eth0-ASIC1 E | ||
| Ethernet20 29,30,31,32 Ethernet1/6 Eth1-ASIC1 E | ||
| Ethernet24 41,42,43,44 Ethernet1/7 Eth2-ASIC1 E | ||
| Ethernet28 37,38,39,40 Ethernet1/8 Eth3-ASIC1 E | ||
| Ethernet-BP16 13,14,15,16 Ethernet-BP16 Eth4-ASIC1 I | ||
| Ethernet-BP20 17,18,19,20 Ethernet-BP20 Eth5-ASIC1 I | ||
| Ethernet-BP24 21,22,23,24 Ethernet-BP24 Eth6-ASIC1 I | ||
| Ethernet-BP28 25,26,27,28 Ethernet-BP28 Eth7-ASIC1 I |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,9 @@ | ||
| # name lanes alias asic_port_name | ||
| Ethernet-BP256 61,62,63,64 Ethernet-BP256 Eth0-ASIC2 | ||
| Ethernet-BP260 57,58,59,60 Ethernet-BP260 Eth1-ASIC2 | ||
| Ethernet-BP264 53,54,55,56 Ethernet-BP264 Eth2-ASIC2 | ||
| Ethernet-BP268 49,50,51,52 Ethernet-BP268 Eth3-ASIC2 | ||
| Ethernet-BP272 45,46,47,48 Ethernet-BP272 Eth4-ASIC2 | ||
| Ethernet-BP276 41,42,43,44 Ethernet-BP276 Eth5-ASIC2 | ||
| Ethernet-BP280 37,38,39,40 Ethernet-BP280 Eth6-ASIC2 | ||
| Ethernet-BP284 33,34,35,36 Ethernet-BP284 Eth7-ASIC2 | ||
| # name lanes alias asic_port_name role | ||
| Ethernet-BP256 61,62,63,64 Ethernet-BP256 Eth0-ASIC2 I | ||
| Ethernet-BP260 57,58,59,60 Ethernet-BP260 Eth1-ASIC2 I | ||
| Ethernet-BP264 53,54,55,56 Ethernet-BP264 Eth2-ASIC2 I | ||
| Ethernet-BP268 49,50,51,52 Ethernet-BP268 Eth3-ASIC2 I | ||
| Ethernet-BP272 45,46,47,48 Ethernet-BP272 Eth4-ASIC2 I | ||
| Ethernet-BP276 41,42,43,44 Ethernet-BP276 Eth5-ASIC2 I | ||
| Ethernet-BP280 37,38,39,40 Ethernet-BP280 Eth6-ASIC2 I | ||
| Ethernet-BP284 33,34,35,36 Ethernet-BP284 Eth7-ASIC2 I |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,9 @@ | ||
| # name lanes alias asic_port_name | ||
| Ethernet-BP384 29,30,31,32 Ethernet-BP384 Eth0-ASIC3 | ||
| Ethernet-BP388 25,26,27,28 Ethernet-BP388 Eth1-ASIC3 | ||
| Ethernet-BP392 21,22,23,24 Ethernet-BP392 Eth2-ASIC3 | ||
| Ethernet-BP396 17,18,19,20 Ethernet-BP396 Eth3-ASIC3 | ||
| Ethernet-BP400 13,14,15,16 Ethernet-BP400 Eth4-ASIC3 | ||
| Ethernet-BP404 9,10,11,12 Ethernet-BP404 Eth5-ASIC3 | ||
| Ethernet-BP408 5,6,7,8 Ethernet-BP408 Eth6-ASIC3 | ||
| Ethernet-BP412 1,2,3,4 Ethernet-BP412 Eth7-ASIC3 | ||
| # name lanes alias asic_port_name role | ||
| Ethernet-BP384 29,30,31,32 Ethernet-BP384 Eth0-ASIC3 I | ||
| Ethernet-BP388 25,26,27,28 Ethernet-BP388 Eth1-ASIC3 I | ||
| Ethernet-BP392 21,22,23,24 Ethernet-BP392 Eth2-ASIC3 I | ||
| Ethernet-BP396 17,18,19,20 Ethernet-BP396 Eth3-ASIC3 I | ||
| Ethernet-BP400 13,14,15,16 Ethernet-BP400 Eth4-ASIC3 I | ||
| Ethernet-BP404 9,10,11,12 Ethernet-BP404 Eth5-ASIC3 I | ||
| Ethernet-BP408 5,6,7,8 Ethernet-BP408 Eth6-ASIC3 I | ||
| Ethernet-BP412 1,2,3,4 Ethernet-BP412 Eth7-ASIC3 I |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check of valid namepsace it not already checked. Raise exception if invalid namespace.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, the namespace validation should be done by the caller ( CLI handler)