Skip to content
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

Added get_system_mac support for cisco-8000 device #9104

Merged
merged 2 commits into from
Nov 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/sonic-config-engine/minigraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -1753,6 +1753,15 @@ def parse_asic_sub_role(filename, asic_name):
sub_role, _, _, _ = parse_asic_meta(child, asic_name)
return sub_role

def parse_asic_switch_type(filename, asic_name):
if os.path.isfile(filename):
root = ET.parse(filename).getroot()
for child in root:
if child.tag == str(QName(ns, "MetadataDeclaration")):
_, _, switch_type, _ = parse_asic_meta(child, asic_name)
return switch_type
return None

def parse_asic_meta_get_devices(root):
local_devices = []

Expand Down
8 changes: 6 additions & 2 deletions src/sonic-config-engine/sonic-cfggen
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import yaml
from collections import OrderedDict
from config_samples import generate_sample_config, get_available_config
from functools import partial
from minigraph import minigraph_encoder, parse_xml, parse_device_desc_xml, parse_asic_sub_role
from minigraph import minigraph_encoder, parse_xml, parse_device_desc_xml, parse_asic_sub_role, parse_asic_switch_type
from portconfig import get_port_config, get_breakout_mode
from redis_bcc import RedisBytecodeCache
from sonic_py_common.multi_asic import get_asic_id_from_name, get_asic_device_id
Expand Down Expand Up @@ -363,13 +363,17 @@ def main():


# the minigraph file must be provided to get the mac address for backend asics
# or switch_type chassis_packet
if args.platform_info:
asic_role = None
switch_type = None
if asic_name is not None:
if args.minigraph is not None:
asic_role = parse_asic_sub_role(args.minigraph, asic_name)
switch_type = parse_asic_switch_type(args.minigraph, asic_name)

if asic_role is not None and asic_role.lower() == "backend":
if ((switch_type is not None and switch_type.lower() == "chassis-packet") or
(asic_role is not None and asic_role.lower() == "backend")):
mac = device_info.get_system_mac(namespace=asic_name)
else:
mac = device_info.get_system_mac()
Expand Down
8 changes: 8 additions & 0 deletions src/sonic-py-common/sonic_py_common/device_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,14 @@ def get_system_mac(namespace=None):
else:
profile_cmd = "false"
hw_mac_entry_cmds = ["sudo decode-syseeprom -m", profile_cmd, "ip link show eth0 | grep ether | awk '{print $2}'"]
elif (version_info['asic_type'] == 'cisco-8000'):
# Try to get valid MAC from profile.ini first, else fetch it from syseeprom or eth0
platform = get_platform()
if namespace is not None:
profile_cmd = 'cat ' + HOST_DEVICE_PATH + '/' + platform + '/profile.ini | grep ' + namespace + 'switchMacAddress | cut -f2 -d='
else:
profile_cmd = "false"
hw_mac_entry_cmds = [profile_cmd, "sudo decode-syseeprom -m", "ip link show eth0 | grep ether | awk '{print $2}'"]
else:
mac_address_cmd = "cat /sys/class/net/eth0/address"
if namespace is not None:
Expand Down