Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into improve_ctnr_hard…
Browse files Browse the repository at this point in the history
…ening
  • Loading branch information
maipbui committed Oct 3, 2023
2 parents 5e84564 + f978fca commit 39a5d74
Show file tree
Hide file tree
Showing 102 changed files with 4,179 additions and 1,334 deletions.
6 changes: 6 additions & 0 deletions .azure-pipelines/pr_test_scripts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,16 @@ wan-pub:
- tacacs/test_authorization.py
- tacacs/test_accounting.py

dpu:
- dash/test_dash_vnet.py

specific_param:
t0-sonic:
- name: bgp/test_bgp_fact.py
param: "--neighbor_type=sonic --enable_macsec --macsec_profile=128_SCI,256_XPN_SCI"
# all the test modules under macsec directory
- name: macsec
param: "--neighbor_type=sonic --enable_macsec --macsec_profile=128_SCI,256_XPN_SCI"
dpu:
- name: dash/test_dash_vnet.py
param: " --skip_dataplane_checking "
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ tests/metadata
.vscode/
.idea/

.python-version
42 changes: 28 additions & 14 deletions ansible/TestbedProcessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def makeTestbed(data, outfile):


def makeSonicLabLinks(data, outfile):
csv_columns = "StartDevice,StartPort,EndDevice,EndPort,BandWidth,VlanID,VlanMode"
csv_columns = "StartDevice,StartPort,EndDevice,EndPort,BandWidth,VlanID,VlanMode,SlotId"
topology = data
csv_file = outfile

Expand All @@ -331,6 +331,7 @@ def makeSonicLabLinks(data, outfile):
bandWidth = element.get("Bandwidth")
vlanID = element.get("VlanID")
vlanMode = element.get("VlanMode")
slotId = element.get("SlotId")

# catch empty values
if not endDevice:
Expand All @@ -343,10 +344,13 @@ def makeSonicLabLinks(data, outfile):
vlanID = ""
if not vlanMode:
vlanMode = ""
if not slotId:
slotId = ""

row = startDevice + "," + startPort + "," + endDevice + "," + \
endPort + "," + str(bandWidth) + \
"," + str(vlanID) + "," + vlanMode
"," + str(vlanID) + "," + vlanMode + \
"," + str(slotId)
f.write(row + "\n")
except IOError:
print("I/O error: issue creating sonic_lab_links.csv")
Expand Down Expand Up @@ -560,7 +564,7 @@ def makeLab(data, devices, testbed, outfile):
try: # get frontend_asics
frontend_asics = dev.get("frontend_asics")
if frontend_asics is not None:
entry += "\tfrontend_asics=" + frontend_asics.__str__()
entry += "\tfrontend_asics=\"" + frontend_asics.__str__() + "\""
except AttributeError:
print("\t\t" + host + ": frontend_asics not found")

Expand All @@ -584,6 +588,13 @@ def makeLab(data, devices, testbed, outfile):
switch_type = dev.get("switch_type")
if switch_type is not None:
entry += "\tswitch_type=" + str(switch_type)
if switch_type == 'fabric' and card_type == 'supervisor':
# Add switchids for fabric asics
# switchids, single asic example "[4]", 3 asic example "[4,6,8]"
switchids = dev.get("switchids")
if switchids:
entry += "\tswitchids=\"" + str(switchids) + "\""

if switch_type == 'voq' and card_type != 'supervisor':
if num_asics is None:
num_asics = 1
Expand Down Expand Up @@ -615,28 +626,28 @@ def makeLab(data, devices, testbed, outfile):
switchids = [
start_switchid +
(asic_id * num_cores_per_asic) for asic_id in range(num_asics)]
entry += "\tswitchids=" + str(switchids)
entry += "\tswitchids=\"" + str(switchids) + "\""

if voq_inband_ip is None:
voq_inband_ip = [
"1.1.1.{}/32"
.format(start_switchid + asic_id) for asic_id in range(num_asics)]
entry += "\tvoq_inband_ip=" + \
str(voq_inband_ip)
entry += "\tvoq_inband_ip=\"" + \
str(voq_inband_ip) + "\""

if voq_inband_ipv6 is None:
voq_inband_ip = [
voq_inband_ipv6 = [
"1111::1:{}/128"
.format(start_switchid + asic_id) for asic_id in range(num_asics)]
entry += "\tvoq_inband_ipv6=" + \
str(voq_inband_ip)
entry += "\tvoq_inband_ipv6=\"" + \
str(voq_inband_ipv6) + "\""

if voq_inband_intf is None:
voq_inband_intf = [
"Ethernet-IB{}"
.format(asic_id) for asic_id in range(num_asics)]
entry += "\tvoq_inband_intf=" + \
str(voq_inband_intf)
entry += "\tvoq_inband_intf=\"" + \
str(voq_inband_intf) + "\""

if voq_inband_type is None:
voq_inband_type = "port"
Expand All @@ -650,13 +661,13 @@ def makeLab(data, devices, testbed, outfile):
lo4096_ip = [
"8.0.0.{}/32"
.format(start_switchid + asic_id) for asic_id in range(num_asics)]
entry += "\tloopback4096_ip=" + lo4096_ip
entry += "\tloopback4096_ip=\"" + str(lo4096_ip) + "\""

if lo4096_ipv6 is None:
lo4096_ipv6 = [
"2603:10e2:400::{}/128"
.format(start_switchid + asic_id) for asic_id in range(num_asics)]
entry += "\tloopback4096_ipv6=" + lo4096_ipv6
entry += "\tloopback4096_ipv6=\"" + str(lo4096_ipv6) + "\""

start_switchid += (num_asics *
num_cores_per_asic)
Expand Down Expand Up @@ -851,6 +862,9 @@ def makeVeos(data, veos, devices, outfile):
entry += "\ttype=" + dev.get("type")
entry += "\thwsku=" + dev.get("hwsku")
entry += "\tcard_type=" + dev.get("card_type")
entry += "\tmodel=" + dev.get("model")
entry += "\tserial=" + dev.get("serial")
entry += "\tbase_mac=" + dev.get("base_mac")
except Exception:
try:
ansible_host = veos.get(key).get(
Expand Down Expand Up @@ -939,7 +953,7 @@ def makeHostVar(data):
host_vars = data
for key, value in host_vars.items(): # iterate through all devices in host_vars dictionary
# create (or overwrite) a file named <device>.yml
with open(args.basedir + "host_vars/" + key.upper() + ".yml", "w") as toWrite:
with open(args.basedir + "host_vars/" + key + ".yml", "w") as toWrite:
for attribute, attribute_data in value.items(): # for each element in device's dictionary
# write the attribute and the attribute value to <device>.yml
toWrite.write(str(attribute) + ": " +
Expand Down
128 changes: 119 additions & 9 deletions ansible/dualtor/nic_simulator/nic_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ def __init__(
self.group_str_cache = {}

def set_upper_tor_forwarding_state(self, state):
if state == self.upper_tor_forwarding_state:
return False
if state == ForwardingState.ACTIVE:
if self.upper_tor_forwarding_state == ForwardingState.STANDBY:
self.output_ports.add(self.upper_tor_port)
Expand All @@ -309,8 +311,11 @@ def set_upper_tor_forwarding_state(self, state):
self.output_ports.remove(self.upper_tor_port)
self.upper_tor_forwarding_state = ForwardingState.STANDBY
self.reset()
return True

def set_lower_tor_forwarding_state(self, state):
if state == self.lower_tor_forwarding_state:
return False
if state == ForwardingState.ACTIVE:
if self.lower_tor_forwarding_state == ForwardingState.STANDBY:
self.output_ports.add(self.lower_tor_port)
Expand All @@ -321,6 +326,7 @@ def set_lower_tor_forwarding_state(self, state):
self.output_ports.remove(self.lower_tor_port)
self.lower_tor_forwarding_state = ForwardingState.STANDBY
self.reset()
return True

def __str__(self):
return self.group_str_cache.setdefault(
Expand All @@ -339,10 +345,10 @@ def __init__(self, in_port, group, priority=None):
in_port, group=group, priority=priority)

def set_upper_tor_forwarding_state(self, state):
self.group.set_upper_tor_forwarding_state(state)
return self.group.set_upper_tor_forwarding_state(state)

def set_lower_tor_forwarding_state(self, state):
self.group.set_lower_tor_forwarding_state(state)
return self.group.set_lower_tor_forwarding_state(state)

def get_upper_tor_forwarding_state(self):
return self.group.upper_tor_forwarding_state
Expand Down Expand Up @@ -387,7 +393,8 @@ class OVSBridge(object):
"upstream_upper_tor_loopback3_flow",
"upstream_lower_tor_loopback3_flow",
"upstream_arp_flow",
"upstream_icmpv6_flow"
"upstream_icmpv6_flow",
"flap_counter"
)

def __init__(self, bridge_name, loopback_ips):
Expand Down Expand Up @@ -419,6 +426,10 @@ def __init__(self, bridge_name, loopback_ips):
1: self.downstream_upper_tor_flow,
0: self.downstream_lower_tor_flow
}
self.flap_counter = {
1: 0,
0: 0
}

def _init_ports(self):
"""Initialize ports."""
Expand Down Expand Up @@ -566,7 +577,7 @@ def set_forwarding_state(self, portids, states):
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)
self.flap_counter[portid] += self.states_setter[portid](state)
OVSCommand.ovs_ofctl_mod_groups(
self.bridge_name, self.upstream_ecmp_group)
return self.query_forwarding_state(portids)
Expand Down Expand Up @@ -692,6 +703,25 @@ def set_drop(self, portids, directions, recover):
result.append(True)
return result

def query_flap_counter(self, portids):
"""Query flap counter."""
with self.lock:
flap_counter = [self.flap_counter[portid] for portid in portids]
logging.info("Query bridge %s flap counter for ports %s: %s",
self.bridge_name, portids, flap_counter)
return flap_counter

def reset_flap_counter(self, portids):
"""Reset flap counter."""
with self.lock:
flap_counter = []
for portid in portids:
self.flap_counter[portid] = 0
flap_counter.append(0)
logging.info("Reset bridge %s flap counter for ports %s: %s",
self.bridge_name, portids, flap_counter)
return flap_counter


class InterruptableThread(threading.Thread):
"""Thread class that can be interrupted by Exception raised."""
Expand Down Expand Up @@ -791,6 +821,30 @@ def SetDrop(self, request, context):
context.peer(), self.nic_addr, response)
return response

def QueryFlapCounter(self, request, context):
logging.debug("QueryFlapCounter: request to server %s from client %s\n",
self.nic_addr, context.peer())
portids = request.portid
response = nic_simulator_grpc_service_pb2.FlapCounterReply(
portid=portids,
flaps=self.ovs_bridge.query_flap_counter(portids)
)
logging.debug("QueryFlapCounter: response to client %s from server %s:\n%s",
context.peer(), self.nic_addr, response)
return response

def ResetFlapCounter(self, request, context):
logging.debug("ResetFlapCounter: request to server %s from client %s\n",
self.nic_addr, context.peer())
portids = request.portid
response = nic_simulator_grpc_service_pb2.FlapCounterReply(
portid=portids,
flaps=self.ovs_bridge.reset_flap_counter(portids)
)
logging.debug("ResetFlapCounter: response to client %s from server %s:\n%s",
context.peer(), self.nic_addr, response)
return response

def _run_server(self, binding_port):
"""Run the gRPC server."""
self.server = grpc.server(
Expand Down Expand Up @@ -849,17 +903,15 @@ def _get_client_stub(self, nic_address):

def QueryAdminForwardingPortState(self, request, context):
nic_addresses = request.nic_addresses
admin_requests = request.admin_requests
logging.debug(
"QueryAdminForwardingPortState[mgmt]: request query admin port state for %s\n", nic_addresses)
query_responses = []
for nic_address in nic_addresses:
for nic_address, admin_request in zip(nic_addresses, admin_requests):
client_stub = self._get_client_stub(nic_address)
try:
state = client_stub.QueryAdminForwardingPortState(
nic_simulator_grpc_service_pb2.AdminRequest(
portid=[0, 1],
state=[True, True]
),
admin_request,
timeout=GRPC_TIMEOUT
)
query_responses.append(state)
Expand Down Expand Up @@ -972,6 +1024,64 @@ def SetNicServerAdminState(self, request, context):
"SetNicServerAdminState[mgmt]: response of set nic server admin state:%s\n", response)
return response

def QueryFlapCounter(self, request, context):
nic_addresses = request.nic_addresses
flap_counter_requests = request.flap_counter_requests
logging.debug(
"QueryFlapCounter[mgmt]: request query port flap counter for %s\n", nic_addresses)

query_responses = []
for nic_address, flap_counter_request in zip(nic_addresses, flap_counter_requests):
client_stub = self._get_client_stub(nic_address)
try:
flap_counter_reply = client_stub.QueryFlapCounter(
flap_counter_request,
timeout=GRPC_TIMEOUT
)
query_responses.append(flap_counter_reply)
except Exception as e:
context.set_code(grpc.StatusCode.ABORTED)
context.set_details(
"Error in QueryFlapCounter to %s: %s" % (nic_address, repr(e)))
return nic_simulator_grpc_mgmt_service_pb2.ListOfFlapCounterReply()

response = nic_simulator_grpc_mgmt_service_pb2.ListOfFlapCounterReply(
nic_addresses=nic_addresses,
flap_counter_replies=query_responses
)
logging.debug(
"QueryFlapCounter[mgmt]: response of query: %s", response)
return response

def ResetFlapCounter(self, request, context):
nic_addresses = request.nic_addresses
flap_counter_requests = request.flap_counter_requests
logging.debug(
"ResetFlapCounter[mgmt]: request reset port flap counter for %s\n", nic_addresses)

reset_responses = []
for nic_address, flap_counter_request in zip(nic_addresses, flap_counter_requests):
client_stub = self._get_client_stub(nic_address)
try:
flap_counter_reply = client_stub.ResetFlapCounter(
flap_counter_request,
timeout=GRPC_TIMEOUT
)
reset_responses.append(flap_counter_reply)
except Exception as e:
context.set_code(grpc.StatusCode.ABORTED)
context.set_details(
"Error in ResetFlapCounter to %s: %s" % (nic_address, repr(e)))
return nic_simulator_grpc_mgmt_service_pb2.ListOfFlapCounterReply()

response = nic_simulator_grpc_mgmt_service_pb2.ListOfFlapCounterReply(
nic_addresses=nic_addresses,
flap_counter_replies=reset_responses
)
logging.debug(
"ResetFlapCounter[mgmt]: response of reset: %s", response)
return response

def start(self):
self.server = grpc.server(
futures.ThreadPoolExecutor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ service DualTorMgmtService {
rpc SetDrop(ListOfDropRequest) returns(ListOfDropReply) {}

rpc SetNicServerAdminState(ListOfNiCServerAdminStateRequest) returns(ListOfNiCServerAdminStateReply) {}

rpc QueryFlapCounter(ListOfFlapCounterRequest) returns(ListOfFlapCounterReply) {}

rpc ResetFlapCounter(ListOfFlapCounterRequest) returns(ListOfFlapCounterReply) {}
}

message ListOfAdminRequest {
Expand Down Expand Up @@ -54,3 +58,13 @@ message ListOfNiCServerAdminStateReply {
repeated bool admin_states = 2;
repeated bool successes = 3;
}

message ListOfFlapCounterRequest {
repeated string nic_addresses = 1;
repeated FlapCounterRequest flap_counter_requests = 2;
};

message ListOfFlapCounterReply {
repeated string nic_addresses = 1;
repeated FlapCounterReply flap_counter_replies = 2;
};
Loading

0 comments on commit 39a5d74

Please sign in to comment.