Skip to content

Commit

Permalink
Merge branch 'master' into route-flow-counter
Browse files Browse the repository at this point in the history
  • Loading branch information
Junchao-Mellanox authored May 26, 2022
2 parents e2fe2d8 + 99ef5c3 commit 8e31615
Show file tree
Hide file tree
Showing 184 changed files with 8,513 additions and 1,870 deletions.
2 changes: 2 additions & 0 deletions .azure-pipelines/run-test-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ steps:
parent_dir=$(basename $PWD)
docker exec sonic-mgmt-2 bash -c "/var/src/$parent_dir/tests/kvmtest.sh -en -T ${{ parameters.tbtype }} -d /var/src/$parent_dir ${{ parameters.tbname }} ${{ parameters.dut }} ${{ parameters.section }}"
displayName: "Run tests"
${{ if eq(parameters.tbtype, 't0-sonic') }}:
continueOnError: true

- script: |
# save dut state if test fails
Expand Down
2 changes: 2 additions & 0 deletions ansible/TestbedProcessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,7 @@ def makeLabYAML(data, devices, testbed, outfile):
if dut in devices:
dutDict.update({dut:
{'ansible_host': devices[dut].get("ansible").get("ansible_host"),
'ansible_hostv6': devices[dut].get("ansible").get("ansible_hostv6"),
'ansible_ssh_user': devices[dut].get("ansible").get("ansible_ssh_user"),
'ansible_ssh_pass': devices[dut].get("ansible").get("ansible_ssh_pass"),
'hwsku': devices[dut].get("hwsku"),
Expand Down Expand Up @@ -687,6 +688,7 @@ def makeLabYAML(data, devices, testbed, outfile):
if ptfhost in testbed:
ptfDict.update({ptfhost:
{'ansible_host': testbed[ptfhost].get("ansible").get("ansible_host"),
'ansible_hostv6': testbed[ptfhost].get("ansible").get("ansible_hostv6"),
'ansible_ssh_user': testbed[ptfhost].get("ansible").get("ansible_ssh_user"),
'ansible_ssh_pass': testbed[ptfhost].get("ansible").get("ansible_ssh_pass")
}
Expand Down
7 changes: 7 additions & 0 deletions ansible/config_sonic_basedon_testbed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
- name: set default dualtor facts
set_fact:
dual_tor_facts: {}
mux_cable_facts: {}
when: "'dualtor' not in topo"

- name: gather dual ToR information
Expand All @@ -166,6 +167,12 @@
delegate_to: localhost
when: "'dualtor' in topo or 'cable' in topo"

- name: gather mux cable information
mux_cable_facts:
topo_name: "{{ topo }}"
delegate_to: localhost
when: "'dualtor' in topo"

- name: generate y_cable simulator driver
include_tasks: dualtor/config_simulated_y_cable.yml
vars:
Expand Down
88 changes: 55 additions & 33 deletions ansible/dualtor/nic_simulator/nic_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,9 @@ class OVSBridge(object):
"flows",
"groups",
"upstream_ecmp_flow",
"upstream_ecmp_group"
"upstream_ecmp_group",
"states_getter",
"states_setter"
)

def __init__(self, bridge_name):
Expand All @@ -317,6 +319,14 @@ def __init__(self, bridge_name):
self.groups = []
self._init_ports()
self._init_flows()
self.states_getter = {
0: self.upstream_ecmp_flow.get_upper_tor_forwarding_state,
1: self.upstream_ecmp_flow.get_lower_tor_forwarding_state
}
self.states_setter = {
0: self.upstream_ecmp_flow.set_upper_tor_forwarding_state,
1: self.upstream_ecmp_flow.set_lower_tor_forwarding_state
}

def _init_ports(self):
"""Initialize ports."""
Expand Down Expand Up @@ -398,20 +408,20 @@ def _add_upstream_ecmp_flow(self, in_port, group):
self.flows.append(flow)
return flow

def set_forwarding_state(self, states):
def set_forwarding_state(self, portids, states):
"""Set forwarding state."""
with self.lock:
logging.info("Set bridge %s forwarding state: %s", self.bridge_name, tuple(ForwardingState.STATE_LABELS[_] for _ in states))
self.upstream_ecmp_flow.set_upper_tor_forwarding_state(states[0])
self.upstream_ecmp_flow.set_lower_tor_forwarding_state(states[1])
for portid, state in zip(portids, states):
logging.info("Set bridge %s port %s forwarding state: %s", self.bridge_name, portid, ForwardingState.STATE_LABELS[state])
self.states_setter[portid](state)
OVSCommand.ovs_ofctl_mod_groups(self.bridge_name, self.upstream_ecmp_group)
return self.query_forwarding_state()
return self.query_forwarding_state(portids)

def query_forwarding_state(self):
def query_forwarding_state(self, portids):
"""Query forwarding state."""
with self.lock:
states = (self.upstream_ecmp_flow.get_upper_tor_forwarding_state(), self.upstream_ecmp_flow.get_lower_tor_forwarding_state())
logging.info("Query bridge %s forwarding state: %s", self.bridge_name, tuple(ForwardingState.STATE_LABELS[_] for _ in states))
states = [self.states_getter[portid]() for portid in portids]
logging.info("Query bridge %s forwarding state for ports %s: %s", self.bridge_name, portids, tuple(ForwardingState.STATE_LABELS[_] for _ in states))
return states


Expand Down Expand Up @@ -466,7 +476,7 @@ def join(self, timeout=None, suppress_exception=False):
raise(self._e) from None


class NiCServer(nic_simulator_grpc_service_pb2_grpc.DualTorServiceServicer):
class NiCServer(nic_simulator_grpc_service_pb2_grpc.DualToRActiveServicer):
"""gRPC for a NiC."""

def __init__(self, nic_addr, ovs_bridge):
Expand All @@ -476,34 +486,46 @@ def __init__(self, nic_addr, ovs_bridge):
self.thread = None

@validate_request_certificate(nic_simulator_grpc_service_pb2.AdminReply())
def QueryAdminPortState(self, request, context):
logging.debug("QueryAdminPortState: request to server %s from client %s\n", self.nic_addr, context.peer())
def QueryAdminForwardingPortState(self, request, context):
logging.debug("QueryAdminForwardingPortState: request to server %s from client %s\n", self.nic_addr, context.peer())
portids = request.portid
response = nic_simulator_grpc_service_pb2.AdminReply(
portid=[0, 1],
state=self.ovs_bridge.query_forwarding_state()
portid=portids,
state=self.ovs_bridge.query_forwarding_state(portids)
)
logging.debug("QueryAdminPortState: response to client %s from server %s:\n%s", context.peer(), self.nic_addr, response)
logging.debug("QueryAdminForwardingPortState: response to client %s from server %s:\n%s", context.peer(), self.nic_addr, response)
return response

@validate_request_certificate(nic_simulator_grpc_service_pb2.AdminReply())
def SetAdminPortState(self, request, context):
logging.debug("SetAdminPortState: request to server %s from client %s\n", self.nic_addr, context.peer())
def SetAdminForwardingPortState(self, request, context):
logging.debug("SetAdminForwardingPortState: request to server %s from client %s\n", self.nic_addr, context.peer())
portids, states = request.portid, request.state
response = nic_simulator_grpc_service_pb2.AdminReply(
portid=[0, 1],
state=self.ovs_bridge.set_forwarding_state(request.state)
portid=portids,
state=self.ovs_bridge.set_forwarding_state(portids, states)
)
logging.debug("SetAdminPortState: response to client %s from server %s:\n%s", context.peer(), self.nic_addr, response)
logging.debug("SetAdminForwardingPortState: response to client %s from server %s:\n%s", context.peer(), self.nic_addr, response)
return response

@validate_request_certificate(nic_simulator_grpc_service_pb2.OperationReply())
def QueryOperationPortState(self, request, context):
# TODO: Add QueryOperationPortState implementation
return nic_simulator_grpc_service_pb2.OperationReply()

@validate_request_certificate(nic_simulator_grpc_service_pb2.LinkStateReply())
def QueryLinkState(self, request, context):
# TODO: add QueryLinkState implementation
return nic_simulator_grpc_service_pb2.LinkStateReply()

@validate_request_certificate(nic_simulator_grpc_service_pb2.ServerVersionReply())
def QueryServerVersion(self, request, context):
# TODO: add QueryServerVersion implementation
return nic_simulator_grpc_service_pb2.ServerVersionReply()

def _run_server(self, binding_port):
"""Run the gRPC server."""
self.server = grpc.server(futures.ThreadPoolExecutor(max_workers=THREAD_CONCURRENCY_PER_SERVER))
nic_simulator_grpc_service_pb2_grpc.add_DualTorServiceServicer_to_server(
nic_simulator_grpc_service_pb2_grpc.add_DualToRActiveServicer_to_server(
self,
self.server
)
Expand Down Expand Up @@ -538,20 +560,20 @@ def _get_client_stub(self, nic_address):
if nic_address in self.client_stubs:
client_stub = self.client_stubs[nic_address]
else:
client_stub = nic_simulator_grpc_service_pb2_grpc.DualTorServiceStub(
client_stub = nic_simulator_grpc_service_pb2_grpc.DualToRActiveStub(
grpc.insecure_channel("%s:%s" % (nic_address, self.binding_port))
)
self.client_stubs[nic_address] = client_stub
return client_stub

def QueryAdminPortState(self, request, context):
def QueryAdminForwardingPortState(self, request, context):
nic_addresses = request.nic_addresses
logging.debug("QueryAdminPortState[mgmt]: request query admin port state for %s\n", nic_addresses)
logging.debug("QueryAdminForwardingPortState[mgmt]: request query admin port state for %s\n", nic_addresses)
query_responses = []
for nic_address in nic_addresses:
client_stub = self._get_client_stub(nic_address)
try:
state = client_stub.QueryAdminPortState(
state = client_stub.QueryAdminForwardingPortState(
nic_simulator_grpc_service_pb2.AdminRequest(
portid=[0, 1],
state=[True, True]
Expand All @@ -560,36 +582,36 @@ def QueryAdminPortState(self, request, context):
query_responses.append(state)
except Exception as e:
context.set_code(grpc.StatusCode.ABORTED)
context.set_details("Error in QueryAdminPortState to %s: %s" % (nic_address, repr(e)))
context.set_details("Error in QueryAdminForwardingPortState to %s: %s" % (nic_address, repr(e)))
return nic_simulator_grpc_mgmt_service_pb2.ListOfAdminReply()
response = nic_simulator_grpc_mgmt_service_pb2.ListOfAdminReply(
nic_addresses=nic_addresses,
admin_replies=query_responses
)
logging.debug("QueryAdminPortState[mgmt]: response of query: %s", response)
logging.debug("QueryAdminForwardingPortState[mgmt]: response of query: %s", response)
return response

def SetAdminPortState(self, request, context):
def SetAdminForwardingPortState(self, request, context):
nic_addresses = request.nic_addresses
admin_requests = request.admin_requests
logging.debug("SetAdminPortState[mgmt]: request set admin port state: %s\n", request)
logging.debug("SetAdminForwardingPortState[mgmt]: request set admin port state: %s\n", request)
set_responses = []
for nic_address, admin_request in zip(nic_addresses, admin_requests):
client_stub = self._get_client_stub(nic_address)
try:
state = client_stub.SetAdminPortState(
state = client_stub.SetAdminForwardingPortState(
admin_request
)
set_responses.append(state)
except Exception as e:
context.set_code(grpc.StatusCode.ABORTED)
context.set_details("Error in QueryAdminPortState to %s: %s" % (nic_address, repr(e)))
context.set_details("Error in SetAdminForwardingPortState to %s: %s" % (nic_address, repr(e)))
return nic_simulator_grpc_mgmt_service_pb2.ListOfAdminRequest()
response = nic_simulator_grpc_mgmt_service_pb2.ListOfAdminReply(
nic_addresses=nic_addresses,
admin_replies=set_responses
)
logging.debug("QueryAdminPortState[mgmt]: response of query: %s", response)
logging.debug("SetAdminForwardingPortState[mgmt]: response of query: %s", response)
return response

def QueryOperationPortState(self, request, context):
Expand All @@ -603,7 +625,7 @@ def start(self):
self.server.wait_for_termination()


class NiCSimulator(nic_simulator_grpc_service_pb2_grpc.DualTorServiceServicer):
class NiCSimulator(nic_simulator_grpc_service_pb2_grpc.DualToRActiveServicer):
"""NiC simulator class, define all the gRPC calls."""

def __init__(self, vm_set, mgmt_port, binding_port):
Expand Down
2 changes: 1 addition & 1 deletion ansible/dualtor/nic_simulator/nic_simulator_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def main():
response = stub.QueryAdminPortState(request)
print(response)
else:
stub = nic_simulator_grpc_service_pb2_grpc.DualTorServiceStub(channel)
stub = nic_simulator_grpc_service_pb2_grpc.DualToRActiveStub(channel)
request = nic_simulator_grpc_service_pb2.AdminRequest(
portid=[0, 1],
state=[True, True]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ syntax = "proto3";
import "nic_simulator_grpc_service.proto";

service DualTorMgmtService {
rpc QueryAdminPortState(ListOfAdminRequest) returns (ListOfAdminReply) {}
rpc QueryAdminForwardingPortState(ListOfAdminRequest) returns (ListOfAdminReply) {}

rpc SetAdminPortState(ListOfAdminRequest) returns (ListOfAdminReply) {}
rpc SetAdminForwardingPortState(ListOfAdminRequest) returns (ListOfAdminReply) {}

rpc QueryOperationPortState(ListOfOperationRequest) returns (ListOfOperationReply) {}
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8e31615

Please sign in to comment.