Skip to content

Commit

Permalink
[ycabled] enable telemetry for 'active-active'; fix gRPC portid order…
Browse files Browse the repository at this point in the history
…ing (sonic-net#284)

* [ycabled] enable telemetry for 'active-active'; fix gRPC portid ordering

This PR fixes the portID sent for gRPC probing to the SoC/NIC-Simulator, and defaults it to [0,1].
This helps improve the logic and readibility of the logs as well for easier debug and response parsing is also improved
This PR also enables sonic-telemetry logging for active-active cable type

Description
Motivation and Context
How Has This Been Tested?
running the changes on testbed and UT

Signed-off-by: vaibhav-dahiya <vdahiya@microsoft.com>
  • Loading branch information
vdahiya12 committed Aug 18, 2022
1 parent a1d7257 commit 7c0a326
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion sonic-ycabled/tests/test_y_cable_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def test_y_cable_wrapper_get_presence_with_platform_chassis_raise_exception(self
def test_post_port_mux_info_to_db(self):
logical_port_name = "Ethernet0"
mux_tbl = Table("STATE_DB", "Y_CABLE_INFO_TABLE")
rc = post_port_mux_info_to_db(logical_port_name, mux_tbl)
rc = post_port_mux_info_to_db(logical_port_name, mux_tbl,'active-standby')
assert(rc != -1)

@patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil', MagicMock(return_value=[0]))
Expand Down
2 changes: 1 addition & 1 deletion sonic-ycabled/tests/test_ycable.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def test_put_all_values_from_dict_to_db(self):
def test_post_port_mux_info_to_db(self):
logical_port_name = "Ethernet0"
mux_tbl = Table("STATE_DB", y_cable_helper.MUX_CABLE_INFO_TABLE)
rc = post_port_mux_info_to_db(logical_port_name, mux_tbl)
rc = post_port_mux_info_to_db(logical_port_name, mux_tbl, 'active-standby')
assert(rc != -1)

@patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil', MagicMock(return_value=[0]))
Expand Down
20 changes: 11 additions & 9 deletions sonic-ycabled/ycable/ycable_utilities/y_cable_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
('grpc.http2.max_pings_without_data', 0)
]

DEFAULT_PORT_IDS = [0, 1]

SYSLOG_IDENTIFIER = "y_cable_helper"

helper_logger = logger.Logger(SYSLOG_IDENTIFIER)
Expand Down Expand Up @@ -501,7 +503,7 @@ def put_init_values_for_grpc_states(port, read_side, hw_mux_cable_tbl, hw_mux_ca


stub = grpc_port_stubs.get(port, None)
request = linkmgr_grpc_driver_pb2.AdminRequest(portid=[int(read_side), 1 - int(read_side)], state=[0, 0])
request = linkmgr_grpc_driver_pb2.AdminRequest(portid=DEFAULT_PORT_IDS, state=[0, 0])
if stub is None:
helper_logger.log_notice("stub is None for getting admin port forwarding state RPC port {}".format(port))
fvs_updated = swsscommon.FieldValuePairs([('state', 'unknown'),
Expand Down Expand Up @@ -1212,7 +1214,7 @@ def check_identifier_presence_and_update_mux_table_entry(state_db, port_tbl, y_c
read_y_cable_and_update_statedb_port_tbl(
logical_port_name, y_cable_tbl[asic_index])
post_port_mux_info_to_db(
logical_port_name, mux_tbl[asic_index])
logical_port_name, mux_tbl[asic_index], 'active-standby')
post_port_mux_static_info_to_db(
logical_port_name, static_tbl[asic_index])
else:
Expand Down Expand Up @@ -1526,7 +1528,7 @@ def check_identifier_presence_and_update_mux_info_entry(state_db, mux_tbl, asic_
helper_logger.log_info("Could not retreive fieldvalue pairs for {}, inside config_db table {}".format(logical_port_name, port_tbl[asic_index].getTableName()))
return

elif cable_status and cable_type == "active-standby":
elif cable_status is True:
# Convert list of tuples to a dictionary
mux_table_dict = dict(fvs)
if "state" in mux_table_dict:
Expand All @@ -1535,7 +1537,7 @@ def check_identifier_presence_and_update_mux_info_entry(state_db, mux_tbl, asic_

if mux_tbl.get(asic_index, None) is not None:
# fill in the newly found entry
post_port_mux_info_to_db(logical_port_name, mux_tbl[asic_index])
post_port_mux_info_to_db(logical_port_name, mux_tbl[asic_index], cable_type)

else:
# first create the state db y cable table and then fill in the entry
Expand All @@ -1544,7 +1546,7 @@ def check_identifier_presence_and_update_mux_info_entry(state_db, mux_tbl, asic_
asic_id = multi_asic.get_asic_index_from_namespace(namespace)
mux_tbl[asic_id] = swsscommon.Table(state_db[asic_id], MUX_CABLE_INFO_TABLE)
# fill the newly found entry
post_port_mux_info_to_db(logical_port_name, mux_tbl[asic_index])
post_port_mux_info_to_db(logical_port_name, mux_tbl[asic_index], cable_type)
else:
helper_logger.log_warning(
"Could not retreive active or auto value for state kvp for {}, inside MUX_CABLE table".format(logical_port_name))
Expand Down Expand Up @@ -2038,7 +2040,7 @@ def get_muxcable_static_info(physical_port, logical_port_name):
return mux_static_info_dict


def post_port_mux_info_to_db(logical_port_name, table):
def post_port_mux_info_to_db(logical_port_name, table, cable_type):

physical_port_list = logical_port_name_to_physical_port_list(logical_port_name)
if physical_port_list is None:
Expand All @@ -2051,7 +2053,7 @@ def post_port_mux_info_to_db(logical_port_name, table):

for physical_port in physical_port_list:

if not y_cable_wrapper_get_presence(physical_port):
if not y_cable_wrapper_get_presence(physical_port) or cable_type == 'active-active':
helper_logger.log_warning("Error: trying to post mux info without presence of port {}".format(logical_port_name))
mux_info_dict = get_muxcable_info_without_presence()
else:
Expand Down Expand Up @@ -3082,7 +3084,7 @@ def handle_show_hwmode_state_cmd_arg_tbl_notification(fvp, port_tbl, xcvrd_show_

helper_logger.log_debug("Y_CABLE_DEBUG:before invoking RPC fwd_state read_side = {}".format(read_side))
# TODO state only for dummy value in this request MSG remove this
request = linkmgr_grpc_driver_pb2.AdminRequest(portid=[int(read_side), 1 - int(read_side)], state=[0, 0])
request = linkmgr_grpc_driver_pb2.AdminRequest(portid=DEFAULT_PORT_IDS, state=[0, 0])
helper_logger.log_debug(
"Y_CABLE_DEBUG:calling RPC for getting cli forwarding state read_side portid = {} Ethernet port {}".format(read_side, port))

Expand Down Expand Up @@ -3187,7 +3189,7 @@ def handle_fwd_state_command_grpc_notification(fvp_m, hw_mux_cable_tbl, fwd_stat
read_side = mux_port_dict.get("read_side")
helper_logger.log_debug("Y_CABLE_DEBUG:before invoking RPC fwd_state read_side = {}".format(read_side))
# TODO state only for dummy value in this request MSG remove this
request = linkmgr_grpc_driver_pb2.AdminRequest(portid=[int(read_side), 1 - int(read_side)], state=[0, 0])
request = linkmgr_grpc_driver_pb2.AdminRequest(portid=DEFAULT_PORT_IDS, state=[0, 0])
helper_logger.log_notice(
"calling RPC for getting forwarding state port = {} portid {} peer portid {} read_side {}".format(port, read_side, 1 - int(read_side), read_side))

Expand Down

0 comments on commit 7c0a326

Please sign in to comment.