Skip to content

Instantly share code, notes, and snippets.

@teone
Created May 22, 2020 21:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save teone/fcafb16333065331f1e9d574b958d292 to your computer and use it in GitHub Desktop.
Save teone/fcafb16333065331f1e9d574b958d292 to your computer and use it in GitHub Desktop.
Find missing ports in ONOS when running at scale with BBSim
import argparse
import re
def read_ports(file):
file1 = open(file, 'r')
lines = file1.readlines()
p = re.compile('.*(BBSM.*-1)')
ports = []
for l in lines:
name = p.match(l)
if name:
ports.append(name.group(1))
return ports
def ports_by_pon(ports):
d = {}
for port in ports:
pon = port[8:10]
uni = port[10:12]
if not pon in d:
d[pon] = []
d[pon].append(uni)
return d
def check_values(pon, onu, ports):
assert len(ports.keys()) == pon, "A PON is missing"
all_missing = []
for k, v in ports.iteritems():
if len(v) != onu:
decimal_ports = [int(x, 16) for x in ports[k]]
missing = [ele for ele in range(1, max(decimal_ports)+1) if ele not in decimal_ports]
hex_missing = ["BBSM0000%s%s-1" % (k, format(x, 'x')) for x in missing]
all_missing = all_missing + hex_missing
return all_missing
def main(file):
ports = read_ports(file)
d = ports_by_pon(ports)
missing = check_values(16, 32, d)
if len(missing) > 0:
print("Missing ports: %s" % ", ".join(missing))
else:
print("All ports accounted for")
if __name__ == "__main__":
parser = argparse.ArgumentParser(prog="missing-port-finder")
parser.add_argument("-f", "--file", help="The output of ports -e | grep BBSM command in ONOS", default="onos-ports-list.txt"),
args = parser.parse_args()
main(args.file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment