Skip to content

Commit b1866a1

Browse files
authored
[nic_simulator] Add timeout and common options (#6005)
Approach What is the motivation for this PR? mgmt client could not talks to the gRPC server. Signed-off-by: Longxiang Lyu <[email protected]> How did you do it? Bring up loopback device to enable mgmt service talks to each gRPC server interacting with SONiC. Add common gRPC options to the nic_simulator. Add timeout for the gRPC calls from mgmt service. How did you verify/test it? Verify mgmt client could talks to the mgmt service of `nic_simulator. Any platform specific information?
1 parent 9acb531 commit b1866a1

2 files changed

Lines changed: 33 additions & 9 deletions

File tree

ansible/dualtor/nic_simulator/nic_simulator.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@
4444
ACTIVE_ACTIVE_INTERFACE_PATTERN = "iaa-[\w-]+-\d+"
4545
SERVER_NIC_INTERFACE_TEMPLATE = "nic-%s-%d"
4646
SERVER_NIC_INTERFACE_PATTERN = "nic-[\w-]+-\d+"
47+
GRPC_TIMEOUT = 0.5
48+
GRPC_SERVER_OPTIONS = [
49+
('grpc.http2.min_ping_interval_without_data_ms', 1000),
50+
('grpc.http2.max_ping_strikes', 0)
51+
]
52+
GRPC_CLIENT_OPTIONS = [
53+
('grpc.keepalive_timeout_ms', 8000),
54+
('grpc.keepalive_time_ms', 4000),
55+
('grpc.keepalive_permit_without_calls', True),
56+
('grpc.http2.max_pings_without_data', 0)
57+
]
4758

4859

4960
def get_ip_address(ifname):
@@ -530,9 +541,10 @@ def QueryServerVersion(self, request, context):
530541

531542
def _run_server(self, binding_port):
532543
"""Run the gRPC server."""
533-
self.server = grpc.server(futures.ThreadPoolExecutor(max_workers=THREAD_CONCURRENCY_PER_SERVER),
534-
options=[('grpc.http2.min_ping_interval_without_data_ms', 1000),
535-
('grpc.http2.max_ping_strikes', 0)])
544+
self.server = grpc.server(
545+
futures.ThreadPoolExecutor(max_workers=THREAD_CONCURRENCY_PER_SERVER),
546+
options=GRPC_SERVER_OPTIONS
547+
)
536548
nic_simulator_grpc_service_pb2_grpc.add_DualToRActiveServicer_to_server(
537549
self,
538550
self.server
@@ -569,7 +581,10 @@ def _get_client_stub(self, nic_address):
569581
client_stub = self.client_stubs[nic_address]
570582
else:
571583
client_stub = nic_simulator_grpc_service_pb2_grpc.DualToRActiveStub(
572-
grpc.insecure_channel("%s:%s" % (nic_address, self.binding_port))
584+
grpc.insecure_channel(
585+
"%s:%s" % (nic_address, self.binding_port),
586+
options=GRPC_CLIENT_OPTIONS
587+
)
573588
)
574589
self.client_stubs[nic_address] = client_stub
575590
return client_stub
@@ -585,7 +600,8 @@ def QueryAdminForwardingPortState(self, request, context):
585600
nic_simulator_grpc_service_pb2.AdminRequest(
586601
portid=[0, 1],
587602
state=[True, True]
588-
)
603+
),
604+
timeout=GRPC_TIMEOUT
589605
)
590606
query_responses.append(state)
591607
except Exception as e:
@@ -608,7 +624,8 @@ def SetAdminForwardingPortState(self, request, context):
608624
client_stub = self._get_client_stub(nic_address)
609625
try:
610626
state = client_stub.SetAdminForwardingPortState(
611-
admin_request
627+
admin_request,
628+
timeout=GRPC_TIMEOUT
612629
)
613630
set_responses.append(state)
614631
except Exception as e:
@@ -626,9 +643,10 @@ def QueryOperationPortState(self, request, context):
626643
return nic_simulator_grpc_mgmt_service_pb2.ListOfOperationReply()
627644

628645
def start(self):
629-
self.server = grpc.server(futures.ThreadPoolExecutor(max_workers=THREAD_CONCURRENCY_PER_SERVER),
630-
options=[('grpc.http2.min_ping_interval_without_data_ms', 1000),
631-
('grpc.http2.max_ping_strikes', 0)])
646+
self.server = grpc.server(
647+
futures.ThreadPoolExecutor(max_workers=THREAD_CONCURRENCY_PER_SERVER),
648+
options=GRPC_SERVER_OPTIONS
649+
)
632650
nic_simulator_grpc_mgmt_service_pb2_grpc.add_DualTorMgmtServiceServicer_to_server(self, self.server)
633651
self.server.add_insecure_port("%s:%s" % (self.binding_address, self.binding_port))
634652
self.server.start()

ansible/roles/vm_set/library/vm_topology.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,10 @@ def add_host_ports(self):
10331033
vlan_id = self.vlan_ids[str(intf)]
10341034
self.add_dut_vlan_subif_to_docker(ptf_if, vlan_separator, vlan_id)
10351035

1036+
def enable_netns_loopback(self):
1037+
"""Enable loopback device in the netns."""
1038+
VMTopology.cmd("ip netns exec %s ifconfig lo up" % self.netns)
1039+
10361040
def setup_netns_source_routing(self):
10371041
"""Setup policy-based routing to forward packet to its igress ports."""
10381042

@@ -1593,6 +1597,7 @@ def main():
15931597
if net.netns:
15941598
net.add_network_namespace()
15951599
net.add_mgmt_port_to_netns(mgmt_bridge, netns_mgmt_ip_addr, ptf_mgmt_ip_gw)
1600+
net.enable_netns_loopback()
15961601

15971602
if hostif_exists:
15981603
net.add_host_ports()
@@ -1722,6 +1727,7 @@ def main():
17221727
if net.netns:
17231728
net.add_network_namespace()
17241729
net.add_mgmt_port_to_netns(mgmt_bridge, netns_mgmt_ip_addr, ptf_mgmt_ip_gw)
1730+
net.enable_netns_loopback()
17251731

17261732
if hostif_exists:
17271733
net.add_host_ports()

0 commit comments

Comments
 (0)