Skip to content

Commit df447b4

Browse files
authored
[ycabled] Fix the init values for active-active ports (#266)
* [ycabled] Fix the init values for active-active ports Signed-off-by: vaibhav-dahiya [email protected] Since linkmgr/orchagent relies on ycabled to populate the mux_cable entries in the HW_MUX_CABLE_TABLE, for the cable active-active type this is accomplished by putting an unknown value if gRPC is unavailable, otherwise a normal RPC is used to query this and the response active or standby is written is HW_MUX_CABLE_TABLE table with a timeout. This Fix accomplishes putting an unknown/active/standby to state key when ycabled starts Description Motivation and Context How Has This Been Tested? Unit-Tests and deploying the changes on testbed Signed-off-by: vaibhav-dahiya <[email protected]>
1 parent ec84af4 commit df447b4

File tree

2 files changed

+71
-12
lines changed

2 files changed

+71
-12
lines changed

sonic-ycabled/tests/test_y_cable_helper.py

+25
Original file line numberDiff line numberDiff line change
@@ -5271,6 +5271,31 @@ def test_parse_grpc_response_forwarding_state_standby_standby_with_true_read_sid
52715271

52725272
rc = handle_fwd_state_command_grpc_notification(fvs_m, hw_mux_cable_tbl, fwd_state_response_tbl, asic_index, port, "TestDB")
52735273
assert(rc == True)
5274+
5275+
@patch('ycable.ycable_utilities.y_cable_helper.grpc_port_stubs', MagicMock(return_value={}))
5276+
@patch('ycable.ycable_utilities.y_cable_helper.grpc_port_channels', MagicMock(return_value={}))
5277+
def test_parse_grpc_response_forwarding_state_standby_standby_with_true_read_side(self):
5278+
5279+
status = True
5280+
asic_index = 0
5281+
test_db = "TEST_DB"
5282+
port = "Ethernet0"
5283+
fvs_m = [('command', "probe"), ('read_side', 1), ('cable_type','active-standby'), ('soc_ipv4','192.168.0.1')]
5284+
hw_mux_cable_tbl = {}
5285+
hw_mux_cable_tbl_peer = {}
5286+
fwd_state_response_tbl = {}
5287+
hw_mux_cable_tbl[asic_index] = swsscommon.Table(
5288+
test_db[asic_index], "PORT_INFO_TABLE")
5289+
hw_mux_cable_tbl_peer[asic_index] = swsscommon.Table(
5290+
test_db[asic_index], "PORT_INFO_TABLE")
5291+
fwd_state_response_tbl[asic_index] = swsscommon.Table(
5292+
test_db[asic_index], "PORT_INFO_TABLE")
5293+
hw_mux_cable_tbl[asic_index].get.return_value = (status, fvs_m)
5294+
5295+
rc = put_init_values_for_grpc_states(port, '0', hw_mux_cable_tbl, hw_mux_cable_tbl_peer, 0)
5296+
assert(rc == None)
5297+
5298+
52745299
def test_get_mux_cable_static_info_without_presence(self):
52755300

52765301
rc = get_muxcable_static_info_without_presence()

sonic-ycabled/ycable/ycable_utilities/y_cable_helper.py

+46-12
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,41 @@ def setup_grpc_channel_for_port(port, soc_ip):
398398

399399
return channel, stub
400400

401+
def put_init_values_for_grpc_states(port, read_side, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, asic_index):
402+
403+
404+
stub = grpc_port_stubs.get(port, None)
405+
request = linkmgr_grpc_driver_pb2.AdminRequest(portid=[int(read_side), 1 - int(read_side)], state=[0, 0])
406+
if stub is None:
407+
helper_logger.log_notice("stub is None for getting admin port forwarding state RPC port {}".format(port))
408+
fvs_updated = swsscommon.FieldValuePairs([('state', 'unknown'),
409+
('read_side', str(read_side)),
410+
('active_side', 'unknown')])
411+
hw_mux_cable_tbl[asic_index].set(port, fvs_updated)
412+
hw_mux_cable_tbl_peer[asic_index].set(port, fvs_updated)
413+
return
414+
415+
ret, response = try_grpc(stub.QueryAdminForwardingPortState, QUERY_ADMIN_FORWARDING_TIMEOUT, request)
416+
(self_state, peer_state) = parse_grpc_response_forwarding_state(ret, response, read_side)
417+
if response is not None:
418+
# Debug only, remove this section once Server side is Finalized
419+
fwd_response_port_ids = response.portid
420+
fwd_response_port_ids_state = response.state
421+
helper_logger.log_notice(
422+
"forwarding state RPC received response port ids = {} port {}".format(fwd_response_port_ids, port))
423+
helper_logger.log_notice(
424+
"forwarding state RPC received response state values = {} port {}".format(fwd_response_port_ids_state, port))
425+
else:
426+
helper_logger.log_warning("response was none while doing init config state for gRPC HW_MUX_CABLE_TABLE {} ".format(port))
427+
428+
fvs_updated = swsscommon.FieldValuePairs([('state', self_state),
429+
('read_side', str(read_side)),
430+
('active_side', self_state)])
431+
hw_mux_cable_tbl[asic_index].set(port, fvs_updated)
432+
fvs_updated = swsscommon.FieldValuePairs([('state', peer_state),
433+
('read_side', str(read_side)),
434+
('active_side', peer_state)])
435+
hw_mux_cable_tbl_peer[asic_index].set(port, fvs_updated)
401436

402437
def process_loopback_interface_and_get_read_side(loopback_keys):
403438

@@ -473,13 +508,12 @@ def check_identifier_presence_and_setup_channel(logical_port_name, port_tbl, hw_
473508
helper_logger.log_notice(
474509
"stub is not None, Cable-Insert or daemon init, daemon able to set up channel for gRPC SOC IP {}, port {}".format(soc_ipv4, logical_port_name))
475510

476-
fvs_updated = swsscommon.FieldValuePairs([('read_side', str(read_side))])
477-
hw_mux_cable_tbl[asic_index].set(logical_port_name, fvs_updated)
478-
hw_mux_cable_tbl_peer[asic_index].set(logical_port_name, fvs_updated)
479511
else:
480512
helper_logger.log_warning(
481513
"DAC cable not present while Channel setup Port {} for gRPC channel initiation".format(logical_port_name))
482514

515+
put_init_values_for_grpc_states(logical_port_name, read_side, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, asic_index)
516+
483517
else:
484518
helper_logger.log_warning(
485519
"DAC cable logical to physical port mapping returned more than one physical ports while Channel setup Port {}".format(logical_port_name))
@@ -3049,8 +3083,8 @@ def handle_fwd_state_command_grpc_notification(fvp_m, hw_mux_cable_tbl, fwd_stat
30493083
helper_logger.log_debug("Y_CABLE_DEBUG:before invoking RPC fwd_state read_side = {}".format(read_side))
30503084
# TODO state only for dummy value in this request MSG remove this
30513085
request = linkmgr_grpc_driver_pb2.AdminRequest(portid=[int(read_side), 1 - int(read_side)], state=[0, 0])
3052-
helper_logger.log_warning(
3053-
"calling RPC for getting forwarding state read_side portid = {} Ethernet port {}".format(read_side, port))
3086+
helper_logger.log_notice(
3087+
"calling RPC for getting forwarding state port = {} portid {} peer portid {} read_side {}".format(port, read_side, 1 - int(read_side), read_side))
30543088

30553089
self_state = "unknown"
30563090
peer_state = "unknown"
@@ -3075,9 +3109,9 @@ def handle_fwd_state_command_grpc_notification(fvp_m, hw_mux_cable_tbl, fwd_stat
30753109
fwd_response_port_ids = response.portid
30763110
fwd_response_port_ids_state = response.state
30773111
helper_logger.log_notice(
3078-
"forwarding state RPC received response port ids = {} port {}".format(fwd_response_port_ids, port))
3112+
"forwarding state RPC received response port = {} portids {} read_side {}".format(port, fwd_response_port_ids,read_side))
30793113
helper_logger.log_notice(
3080-
"forwarding state RPC received response state values = {} port {}".format(fwd_response_port_ids_state, port))
3114+
"forwarding state RPC received response port = {} state values = {} read_side {}".format(port, fwd_response_port_ids_state, read_side))
30813115
else:
30823116
helper_logger.log_notice("response was none handle_fwd_state_command_grpc_notification {} ".format(port))
30833117

@@ -3132,7 +3166,7 @@ def handle_hw_mux_cable_table_grpc_notification(fvp, hw_mux_cable_tbl, asic_inde
31323166
state_req = 0
31333167

31343168
helper_logger.log_notice(
3135-
"calling RPC for hw mux_cable set state state peer = {} portid Ethernet port {}".format(peer, port))
3169+
"calling RPC for hw mux_cable set state ispeer = {} port {} portid {} read_side {} state requested {}".format(peer, port, curr_read_side, read_side, new_state))
31363170

31373171
request = linkmgr_grpc_driver_pb2.AdminRequest(portid=[curr_read_side], state=[state_req])
31383172

@@ -3152,9 +3186,9 @@ def handle_hw_mux_cable_table_grpc_notification(fvp, hw_mux_cable_tbl, asic_inde
31523186
hw_response_port_ids = response.portid
31533187
hw_response_port_ids_state = response.state
31543188
helper_logger.log_notice(
3155-
"Set admin state RPC received response port ids = {}".format(hw_response_port_ids))
3189+
"Set admin state RPC received response port {} port ids = {} curr_read_side {} read_side {}".format(port, hw_response_port_ids, curr_read_side, read_side))
31563190
helper_logger.log_notice(
3157-
"Set admin state RPC received response state values = {}".format(hw_response_port_ids_state))
3191+
"Set admin state RPC received response port {} state values = {} curr_read_side {} read_side {}".format(port, hw_response_port_ids_state, curr_read_side, read_side))
31583192
else:
31593193
helper_logger.log_notice("response was none hw_mux_cable_table_grpc_notification {} ".format(port))
31603194

@@ -3166,8 +3200,8 @@ def handle_hw_mux_cable_table_grpc_notification(fvp, hw_mux_cable_tbl, asic_inde
31663200
new_state = 'unknown'
31673201

31683202
time_end = datetime.datetime.utcnow().strftime("%Y-%b-%d %H:%M:%S.%f")
3169-
fvs_metrics = swsscommon.FieldValuePairs([('grpc_switch_{}_{}_start'.format(toggle_side, new_state), str(time_start)),
3170-
('grpc_switch_{}_{}_end'.format(toggle_side, new_state), str(time_end))])
3203+
fvs_metrics = swsscommon.FieldValuePairs([('xcvrd_switch_{}_{}_start'.format(toggle_side, new_state), str(time_start)),
3204+
('xcvrd_switch_{}_{}_end'.format(toggle_side, new_state), str(time_end))])
31713205
grpc_metrics_tbl[asic_index].set(port, fvs_metrics)
31723206

31733207
fvs_updated = swsscommon.FieldValuePairs([('state', new_state),

0 commit comments

Comments
 (0)