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

[xcvrd] Introduce regex style keys in media_settings for setting up port configuration in xcvrd #417

Closed
wants to merge 4 commits into from
Closed
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
33 changes: 33 additions & 0 deletions sonic-xcvrd/tests/media_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,39 @@
"lane3":"0x144808"
}
}
},
"33": {
"Default": {
"preemphasis": {
"lane0":"0x144808",
"lane1":"0x144808",
"lane2":"0x144808",
"lane3":"0x144808"
}
}
}
},
"GLOBAL_MEDIA_PATTERN_SETTINGS": {
"1-33": {
"^QSFP\\+.*10G.*SR.*": {
"interface_type": "sr4"

},
"^QSFP\\+.*40G.*": {
"interface_type": "sr4"

},
"QSFP\\+.*100GBASE-LR4.*": {
"interface_type": "sr4"

}

},
"34,35,36": {
"^QSFP\\+.*10G.*SR.*": {
"interface_type": "sr4"

}
}
}
}
Expand Down
23 changes: 23 additions & 0 deletions sonic-xcvrd/tests/test_xcvrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
media_settings_with_comma_dict = copy.deepcopy(media_settings_dict)
global_media_settings = media_settings_with_comma_dict['GLOBAL_MEDIA_SETTINGS'].pop('1-32')
media_settings_with_comma_dict['GLOBAL_MEDIA_SETTINGS']['1-5,6,7-20,21-32'] = global_media_settings
regex_media_settings = copy.deepcopy(media_settings_dict)

with open(os.path.join(test_path, 'optics_si_settings.json'), 'r') as fn:
optics_si_settings_dict = json.load(fn)
Expand Down Expand Up @@ -479,6 +480,28 @@ def _check_notify_media_setting(self, index):
port_mapping.handle_port_change_event(port_change_event)
notify_media_setting(logical_port_name, xcvr_info_dict, app_port_tbl, port_mapping)


@patch('xcvrd.xcvrd.g_dict', regex_media_settings)
@patch('xcvrd.xcvrd._wrapper_get_presence', MagicMock(return_value=True))
def test_check_notify_media_settings_value(self):
logical_port_name = 'Ethernet0'
index = 33
xcvr_info_dict = {
index: {
'manufacturer': 'Molex',
'model': '1064141421',
'cable_type': 'Length Cable Assembly(m)',
'cable_length': '255',
'specification_compliance': "{'10/40G Ethernet Compliance Code': '10GBase-SR'}",
'type_abbrv_name': 'QSFP+'
}
}
physical_port = 33
key = get_media_settings_key(physical_port, xcvr_info_dict)
media_dict = get_media_settings_value(physical_port, key)
res_dict = {'interface_type': 'sr4'}
assert media_dict == res_dict

@patch('xcvrd.xcvrd_utilities.optics_si_parser.g_optics_si_dict', optics_si_settings_dict)
@patch('xcvrd.xcvrd._wrapper_get_presence', MagicMock(return_value=True))
def test_fetch_optics_si_setting(self):
Expand Down
75 changes: 48 additions & 27 deletions sonic-xcvrd/xcvrd/xcvrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@
POWER_UNIT = 'dBm'
BIAS_UNIT = 'mA'


RANGE_SEPARATOR = '-'
COMMA_SEPARATOR = ','
GLOBAL_MEDIA_SETTINGS_KEY = 'GLOBAL_MEDIA_SETTINGS'
PORT_MEDIA_SETTINGS_KEY = 'PORT_MEDIA_SETTINGS'
GLOBAL_MEDIA_PATTERN_SETTINGS_KEY = 'GLOBAL_MEDIA_PATTERN_SETTINGS'
DEFAULT_KEY = 'Default'

g_dict = {}
# Global platform specific sfputil class instance
platform_sfputil = None
Expand Down Expand Up @@ -576,12 +584,28 @@ def check_port_in_range(range_str, physical_port):
return False


def parse_delimitors_in_port_ranges(keys, physical_port, global_key):

media_dict = {}

if COMMA_SEPARATOR in keys:
port_list = keys.split(COMMA_SEPARATOR)
for port in port_list:
if RANGE_SEPARATOR in port:
if check_port_in_range(port, physical_port):
media_dict = g_dict[global_key][keys]
break
elif str(physical_port) == port:
media_dict = g_dict[global_key][keys]
break

elif RANGE_SEPARATOR in keys:
if check_port_in_range(keys, physical_port):
media_dict = g_dict[global_key][keys]

return media_dict

def get_media_settings_value(physical_port, key):
GLOBAL_MEDIA_SETTINGS_KEY = 'GLOBAL_MEDIA_SETTINGS'
PORT_MEDIA_SETTINGS_KEY = 'PORT_MEDIA_SETTINGS'
DEFAULT_KEY = 'Default'
RANGE_SEPARATOR = '-'
COMMA_SEPARATOR = ','
media_dict = {}
default_dict = {}

Expand All @@ -590,23 +614,12 @@ def get_media_settings_value(physical_port, key):
# 1-32
# 1,2,3,4,5
# 1-4,9-12



if GLOBAL_MEDIA_SETTINGS_KEY in g_dict:
for keys in g_dict[GLOBAL_MEDIA_SETTINGS_KEY]:
if COMMA_SEPARATOR in keys:
port_list = keys.split(COMMA_SEPARATOR)
for port in port_list:
if RANGE_SEPARATOR in port:
if check_port_in_range(port, physical_port):
media_dict = g_dict[GLOBAL_MEDIA_SETTINGS_KEY][keys]
break
elif str(physical_port) == port:
media_dict = g_dict[GLOBAL_MEDIA_SETTINGS_KEY][keys]
break

elif RANGE_SEPARATOR in keys:
if check_port_in_range(keys, physical_port):
media_dict = g_dict[GLOBAL_MEDIA_SETTINGS_KEY][keys]

media_dict = parse_delimitors_in_port_ranges(keys, physical_port, GLOBAL_MEDIA_SETTINGS_KEY)

# If there is a match in the global profile for a media type,
# fetch those values
Expand All @@ -621,6 +634,7 @@ def get_media_settings_value(physical_port, key):

media_dict = {}


if PORT_MEDIA_SETTINGS_KEY in g_dict:
for keys in g_dict[PORT_MEDIA_SETTINGS_KEY]:
if int(keys) == physical_port:
Expand All @@ -634,20 +648,27 @@ def get_media_settings_value(physical_port, key):
helper_logger.log_error("Error: No values for physical port '{}'".format(physical_port))
return {}


if key[0] in media_dict:
return media_dict[key[0]]
elif key[0].split('-')[0] in media_dict:
return media_dict[key[0].split('-')[0]]
elif key[1] in media_dict:
return media_dict[key[1]]
elif DEFAULT_KEY in media_dict:
return media_dict[DEFAULT_KEY]
elif len(default_dict) != 0:
return default_dict
default_dict = media_dict[DEFAULT_KEY]

if GLOBAL_MEDIA_PATTERN_SETTINGS_KEY in g_dict:
for keys in g_dict[GLOBAL_MEDIA_PATTERN_SETTINGS_KEY]:
media_dict = parse_delimitors_in_port_ranges(keys, physical_port, GLOBAL_MEDIA_PATTERN_SETTINGS_KEY)

for dkey, val in media_dict.items():
if re.match(dkey, key[1]):
return media_dict[dkey]

else:
if len(default_dict) != 0:
return default_dict

return {}


Expand Down Expand Up @@ -1096,7 +1117,7 @@ def get_cmis_media_lanes_mask(self, api, appl, lport, subport):
self.log_error("Invalid input to get media lane mask - appl {} media_lane_count {} "
"lport {} subport {}!".format(appl, media_lane_count, lport, subport))
return media_lanes_mask
media_lane_start_bit = (media_lane_count * (0 if subport == 0 else subport - 1))
if media_lane_assignment_option & (1 << media_lane_start_bit):
media_lanes_mask = ((1 << media_lane_count) - 1) << media_lane_start_bit
Expand Down Expand Up @@ -1522,7 +1543,7 @@ def task_worker(self):
continue
host_lanes_mask = self.port_dict[lport]['host_lanes_mask']
self.log_notice("{}: Setting host_lanemask=0x{:x}".format(lport, host_lanes_mask))
self.port_dict[lport]['media_lane_count'] = int(api.get_media_lane_count(appl))
self.port_dict[lport]['media_lane_assignment_options'] = int(api.get_media_lane_assignment_option(appl))
media_lane_count = self.port_dict[lport]['media_lane_count']
Expand Down Expand Up @@ -2586,7 +2607,7 @@ def run(self):
class XcvrTableHelper:
def __init__(self, namespaces):
self.int_tbl, self.dom_tbl, self.dom_threshold_tbl, self.status_tbl, self.app_port_tbl, \
self.cfg_port_tbl, self.state_port_tbl, self.pm_tbl = {}, {}, {}, {}, {}, {}, {}, {}
self.cfg_port_tbl, self.state_port_tbl, self.pm_tbl = {}, {}, {}, {}, {}, {}, {}, {}
self.state_db = {}
self.cfg_db = {}
for namespace in namespaces:
Expand Down