Skip to content

Commit fed19e3

Browse files
authored
Added get_system_mac support for cisco-8000 device (sonic-net#9104)
Added get_system_mac support for cisco-8000 device Why I did it This is required to assign unique MACs to namespaces on Backend and Frontend asics for cisco-8000 platforms How I did it Add vendor specific hook in get_system_mac. The MAC address are read from /profile.ini file How to verify it config load_minigraph on a multi-asic system config save check mac addresses in DEVICE_METADATA section in each config_db json file
1 parent 5604983 commit fed19e3

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

src/sonic-config-engine/minigraph.py

+9
Original file line numberDiff line numberDiff line change
@@ -1753,6 +1753,15 @@ def parse_asic_sub_role(filename, asic_name):
17531753
sub_role, _, _, _ = parse_asic_meta(child, asic_name)
17541754
return sub_role
17551755

1756+
def parse_asic_switch_type(filename, asic_name):
1757+
if os.path.isfile(filename):
1758+
root = ET.parse(filename).getroot()
1759+
for child in root:
1760+
if child.tag == str(QName(ns, "MetadataDeclaration")):
1761+
_, _, switch_type, _ = parse_asic_meta(child, asic_name)
1762+
return switch_type
1763+
return None
1764+
17561765
def parse_asic_meta_get_devices(root):
17571766
local_devices = []
17581767

src/sonic-config-engine/sonic-cfggen

+6-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import yaml
2929
from collections import OrderedDict
3030
from config_samples import generate_sample_config, get_available_config
3131
from functools import partial
32-
from minigraph import minigraph_encoder, parse_xml, parse_device_desc_xml, parse_asic_sub_role
32+
from minigraph import minigraph_encoder, parse_xml, parse_device_desc_xml, parse_asic_sub_role, parse_asic_switch_type
3333
from portconfig import get_port_config, get_breakout_mode
3434
from redis_bcc import RedisBytecodeCache
3535
from sonic_py_common.multi_asic import get_asic_id_from_name, get_asic_device_id
@@ -363,13 +363,17 @@ def main():
363363

364364

365365
# the minigraph file must be provided to get the mac address for backend asics
366+
# or switch_type chassis_packet
366367
if args.platform_info:
367368
asic_role = None
369+
switch_type = None
368370
if asic_name is not None:
369371
if args.minigraph is not None:
370372
asic_role = parse_asic_sub_role(args.minigraph, asic_name)
373+
switch_type = parse_asic_switch_type(args.minigraph, asic_name)
371374

372-
if asic_role is not None and asic_role.lower() == "backend":
375+
if ((switch_type is not None and switch_type.lower() == "chassis-packet") or
376+
(asic_role is not None and asic_role.lower() == "backend")):
373377
mac = device_info.get_system_mac(namespace=asic_name)
374378
else:
375379
mac = device_info.get_system_mac()

src/sonic-py-common/sonic_py_common/device_info.py

+8
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,14 @@ def get_system_mac(namespace=None):
492492
else:
493493
profile_cmd = "false"
494494
hw_mac_entry_cmds = ["sudo decode-syseeprom -m", profile_cmd, "ip link show eth0 | grep ether | awk '{print $2}'"]
495+
elif (version_info['asic_type'] == 'cisco-8000'):
496+
# Try to get valid MAC from profile.ini first, else fetch it from syseeprom or eth0
497+
platform = get_platform()
498+
if namespace is not None:
499+
profile_cmd = 'cat ' + HOST_DEVICE_PATH + '/' + platform + '/profile.ini | grep ' + namespace + 'switchMacAddress | cut -f2 -d='
500+
else:
501+
profile_cmd = "false"
502+
hw_mac_entry_cmds = [profile_cmd, "sudo decode-syseeprom -m", "ip link show eth0 | grep ether | awk '{print $2}'"]
495503
else:
496504
mac_address_cmd = "cat /sys/class/net/eth0/address"
497505
if namespace is not None:

0 commit comments

Comments
 (0)