Commit 7549fa9e authored by Jonas Kaufmann's avatar Jonas Kaufmann Committed by Antoine Kaufmann
Browse files

pre-commit run -a

parent aac98df8
......@@ -21,20 +21,23 @@
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import json
import re
import os
import re
def parse_nopaxos_run(num_c, seq, path):
ret = {}
ret['throughput'] = None
ret['latency'] = None
tp_pat = re.compile(r'(.*)Completed *([0-9\.]*) requests in *([0-9\.]*) seconds')
tp_pat = re.compile(
r'(.*)Completed *([0-9\.]*) requests in *([0-9\.]*) seconds'
)
lat_pat = re.compile(r'(.*)Average latency is *([0-9\.]*) ns(.*)')
if not os.path.exists(path):
return ret
f_log = open(path, 'r')
log = json.load(f_log)
......@@ -43,27 +46,26 @@ def parse_nopaxos_run(num_c, seq, path):
for i in range(num_c):
sim_name = f'host.client.{i}'
#print(sim_name)
# in this host log stdout
for j in log["sims"][sim_name]["stdout"]:
for j in log['sims'][sim_name]['stdout']:
#print(j)
m_t = tp_pat.match(j)
m_l = lat_pat.match(j)
if m_l:
#print(j)
lat = float(m_l.group(2)) / 1000 # us latency
lat = float(m_l.group(2)) / 1000 # us latency
#print(lat)
total_avglat += lat
if m_t:
n_req = float(m_t.group(2))
n_time = float(m_t.group(3))
total_tput += n_req/n_time
total_tput += n_req / n_time
avglat = total_avglat/num_c
#print(avglat)
avglat = total_avglat / num_c
#print(avglat)
#print(total_tput)
ret['throughput'] = total_tput
ret['latency'] = avglat
......
......@@ -53,7 +53,7 @@ class l2_switch():
if table['type'] in table_types or len(table_types) == 0:
try:
if verbose:
print("Clearing table {:<40} ... ".
print('Clearing table {:<40} ... '.
format(table['full_name']),
end='', flush=True)
table['node'].clear(batch=batching)
......@@ -109,7 +109,7 @@ class l2_switch():
# no add() etc. Another reason is that the
# table is read-only.
if verbose:
print("Failed")
print('Failed')
finally:
if batching:
bfrt.batch_end()
......@@ -128,16 +128,16 @@ class l2_switch():
self.__init__()
# Enable learning on SMAC
print("Initializing learning on SMAC ... ", end='', flush=True)
print('Initializing learning on SMAC ... ', end='', flush=True)
try:
self.p4.IngressDeparser.l2_digest.callback_deregister()
except:
pass
self.p4.IngressDeparser.l2_digest.callback_register(self.learning_cb)
print("Done")
print('Done')
# Enable aging on SMAC
print("Inializing Aging on SMAC ... ", end='', flush=True)
print('Inializing Aging on SMAC ... ', end='', flush=True)
try:
self.p4.Ingress.smac.idle_table_set_notify(enable=False,
callback=None)
......@@ -149,7 +149,7 @@ class l2_switch():
# interval = 10000,
# min_ttl = 10000,
# max_ttl = 60000)
print("Done")
print('Done')
@staticmethod
def aging_cb(dev_id, pipe_id, direction, parser_id, entry):
......@@ -158,13 +158,13 @@ class l2_switch():
mac_addr = entry.key[b'hdr.ethernet.src_addr']
print("Aging out: MAC: {}".format(mac(mac_addr)))
print('Aging out: MAC: {}'.format(mac(mac_addr)))
entry.remove() # from smac
try:
dmac.delete(dst_addr=mac_addr)
except:
print("WARNING: Could not find the matching DMAC entry")
print('WARNING: Could not find the matching DMAC entry')
@staticmethod
def learning_cb(dev_id, pipe_id, direction, parser_id, session, msg):
......@@ -172,19 +172,19 @@ class l2_switch():
dmac = bfrt.nopaxos.pipe.Ingress.dmac
for digest in msg:
port = digest["ingress_port"]
mac_move = digest["mac_move"]
mac_addr = digest["src_mac"]
port = digest['ingress_port']
mac_move = digest['mac_move']
mac_addr = digest['src_mac']
old_port = port ^ mac_move # Because mac_move = ingress_port ^ port
print("MAC: {}, Port={}".format(
mac(mac_addr), port), end="")
print('MAC: {}, Port={}'.format(
mac(mac_addr), port), end='')
if mac_move != 0:
print("(Move from port={})".format(old_port))
print('(Move from port={})'.format(old_port))
else:
print("(New)")
print('(New)')
# Since we do not have access to self, we have to use
# the hardcoded value for the TTL :(
......@@ -221,7 +221,7 @@ def set_mcast(num_groups=1, num_sequencers=1):
### Setup L2 learning
sl2 = l2_switch(default_ttl=10000)
sl2.setup()
sl2.l2_add_smac_drop(1, "00:00:00:00:00:00")
sl2.l2_add_smac_drop(1, '00:00:00:00:00:00')
bfrt.complete_operations()
p4 = bfrt.nopaxos.pipe
......@@ -236,5 +236,5 @@ bfrt.complete_operations()
### Register print out
print("""******************* SETUP RESULTS *****************""")
print ("\n reg_cnt:")
print ('\n reg_cnt:')
p4.Ingress.reg_cnt.get(REGISTER_INDEX=0, from_hw=True)
......@@ -54,7 +54,7 @@ class l2_switch():
if table['type'] in table_types or len(table_types) == 0:
try:
if verbose:
print("Clearing table {:<40} ... ".
print('Clearing table {:<40} ... '.
format(table['full_name']),
end='', flush=True)
table['node'].clear(batch=batching)
......@@ -110,7 +110,7 @@ class l2_switch():
# no add() etc. Another reason is that the
# table is read-only.
if verbose:
print("Failed")
print('Failed')
finally:
if batching:
bfrt.batch_end()
......@@ -151,16 +151,16 @@ class l2_switch():
self.p4.Egress.port_vlan_tagged.symmetric_mode_set(False)
# Enable learning on SMAC
print("Initializing learning on SMAC ... ", end='', flush=True)
print('Initializing learning on SMAC ... ', end='', flush=True)
try:
self.p4.IngressDeparser.l2_digest.callback_deregister()
except:
pass
self.p4.IngressDeparser.l2_digest.callback_register(self.learning_cb)
print("Done")
print('Done')
# Enable aging on SMAC
print("Inializing Aging on SMAC ... ", end='', flush=True)
print('Inializing Aging on SMAC ... ', end='', flush=True)
self.p4.Ingress.smac.idle_table_set_notify(enable=False,
callback=None)
......@@ -169,7 +169,7 @@ class l2_switch():
interval = 10000,
min_ttl = 10000,
max_ttl = 60000)
print("Done")
print('Done')
@staticmethod
def aging_cb(dev_id, pipe_id, direction, parser_id, entry):
......@@ -179,13 +179,13 @@ class l2_switch():
vid = entry.key[b'meta.vid']
mac_addr = entry.key[b'hdr.ethernet.src_addr']
print("Aging out: VID: {}, MAC: {}".format(vid, mac(mac_addr)))
print('Aging out: VID: {}, MAC: {}'.format(vid, mac(mac_addr)))
entry.remove() # from smac
try:
dmac.delete(vid=vid, dst_addr=mac_addr)
except:
print("WARNING: Could not find the matching DMAC entry")
print('WARNING: Could not find the matching DMAC entry')
@staticmethod
def learning_cb(dev_id, pipe_id, direction, parser_id, session, msg):
......@@ -193,20 +193,20 @@ class l2_switch():
dmac = bfrt.l2_switch.pipe.Ingress.dmac
for digest in msg:
vid = digest["vid"]
port = digest["ingress_port"]
mac_move = digest["mac_move"]
mac_addr = digest["src_mac"]
vid = digest['vid']
port = digest['ingress_port']
mac_move = digest['mac_move']
mac_addr = digest['src_mac']
old_port = port ^ mac_move # Because mac_move = ingress_port ^ port
print("VID: {}, MAC: {}, Port={}".format(
vid, mac(mac_addr), port), end="")
print('VID: {}, MAC: {}, Port={}'.format(
vid, mac(mac_addr), port), end='')
if mac_move != 0:
print("(Move from port={})".format(old_port))
print('(Move from port={})'.format(old_port))
else:
print("(New)")
print('(New)')
# Since we do not have access to self, we have to use
# the hardcoded value for the TTL :(
......@@ -220,9 +220,9 @@ class l2_switch():
def vlan_create(self, vid):
if vid in self.vlan:
raise KeyError("Vlan {} already exists".format(vid))
raise KeyError('Vlan {} already exists'.format(vid))
if not 1 <= vid <= 4095:
raise ValueError("Vlan ID {} is incorrect".format(vid))
raise ValueError('Vlan ID {} is incorrect'.format(vid))
bfrt.pre.node.entry(MULTICAST_NODE_ID = vid,
MULTICAST_RID = 0xFFFF, # See P4 code
......@@ -233,7 +233,7 @@ class l2_switch():
MULTICAST_NODE_L1_XID_VALID = [0],
MULTICAST_NODE_L1_XID = [0]).push()
self.vlan[vid] = {
"ports": {}
'ports': {}
}
......@@ -284,15 +284,15 @@ class l2_switch():
for vid in sorted(vlans):
print ('| {:>4d} | '.format(vid), end='')
for p in sorted(self.vlan[vid]["ports"].keys()):
for p in sorted(self.vlan[vid]['ports'].keys()):
print(p, end='')
if self.vlan[vid]["ports"][p]:
print("(T)", end='')
if self.vlan[vid]['ports'][p]:
print('(T)', end='')
else:
print("(U)", end='')
print('(U)', end='')
print()
print( "+------+------------------------------------------")
print( '+------+------------------------------------------')
def vlan_port_add(self, vid, dp, tagged=False):
if vid not in self.vlan:
......@@ -340,7 +340,7 @@ class l2_switch():
vid << 7 | port, 0, pipe=pipe)
# Update internal state
vlan_ports = self.vlan[vid]["ports"]
vlan_ports = self.vlan[vid]['ports']
vlan_ports[dp] = tagged
def vlan_port_delete(self, vid, dp):
......@@ -397,7 +397,7 @@ class l2_switch():
try:
default_vid = self.port_vlan_default_get(dp)
if default_vid != 0 or show_all:
print("Port %3d : Default VLAN is %4d" % (dp, default_vid))
print('Port %3d : Default VLAN is %4d' % (dp, default_vid))
except:
pass
......@@ -427,54 +427,54 @@ class l2_switch():
def l2_print(self, dmac_entry, smac_entry):
vid = None
mac_addr = None
port = " "
pending = " "
valid = " "
static = " "
dst_drop = " "
src_drop = " "
static = " "
ttl = " "
dmac_eh_s= " "
smac_eh_s= " "
port = ' '
pending = ' '
valid = ' '
static = ' '
dst_drop = ' '
src_drop = ' '
static = ' '
ttl = ' '
dmac_eh_s= ' '
smac_eh_s= ' '
if dmac_entry is not None:
valid = "Y"
valid = 'Y'
vid = dmac_entry.key[b'meta.vid']
mac_addr = mac(dmac_entry.key[b'hdr.ethernet.dst_addr'])
if dmac_entry.action.endswith("dmac_drop"):
dst_drop = "Y"
if dmac_entry.action.endswith('dmac_drop'):
dst_drop = 'Y'
else:
dst_drop = " "
if dmac_entry.action.endswith("dmac_unicast"):
dst_drop = ' '
if dmac_entry.action.endswith('dmac_unicast'):
port = dmac_entry.data[b'port']
if smac_entry is not None:
valid = "Y"
valid = 'Y'
ttl = int(smac_entry.data[b'$ENTRY_TTL'])
if ttl > 1000 or ttl == 0:
ttl = "%6d" % (ttl/1000)
ttl = '%6d' % (ttl/1000)
else:
ttl = " 0.%03d" % ttl
ttl = ' 0.%03d' % ttl
if dmac_entry is None:
vid = smac_entry.key[b'meta.vid']
mac_addr = mac(smac_entry.key[b'hdr.ethernet.src_addr'])
if smac_entry.action.endswith("smac_hit"):
if smac_entry.action.endswith('smac_hit'):
if (dmac_entry is None or
dmac_entry.action.endswith("dmac_miss")):
pending = "Y"
dmac_entry.action.endswith('dmac_miss')):
pending = 'Y'
port = smac_entry.data[b'port']
if smac_entry.data[b'is_static']:
static = "Y"
elif smac_entry.action.endswith("smac_drop"):
src_drop = "Y"
static = 'Y'
elif smac_entry.action.endswith('smac_drop'):
src_drop = 'Y'
if dmac_entry or smac_entry:
print("| %4d | %s | %3d | %s %s %s | %s %s | %s |" % (
print('| %4d | %s | %3d | %s %s %s | %s %s | %s |' % (
vid, mac_addr, port,
valid, pending, static,
src_drop, dst_drop,
......@@ -537,7 +537,7 @@ sl2.port_vlan_default_set(0, 1)
sl2.port_vlan_default_set(1, 1)
sl2.port_vlan_default_set(2, 1)
sl2.port_vlan_default_set(3, 1)
sl2.l2_add_smac_drop(1, "00:00:00:00:00:00")
sl2.l2_add_smac_drop(1, '00:00:00:00:00:00')
bfrt.complete_operations()
sl2.vlan_show()
......
#!/usr/bin/env python
"""
Generates an AXI Stream arbitrated mux wrapper with the specified number of ports
"""
"""Generates an AXI Stream arbitrated mux wrapper with the specified number of
ports."""
from __future__ import print_function
......@@ -11,9 +10,9 @@ from jinja2 import Template
def main():
parser = argparse.ArgumentParser(description=__doc__.strip())
parser.add_argument('-p', '--ports', type=int, default=4, help="number of ports")
parser.add_argument('-n', '--name', type=str, help="module name")
parser.add_argument('-o', '--output', type=str, help="output file name")
parser.add_argument('-p', '--ports', type=int, default=4, help='number of ports')
parser.add_argument('-n', '--name', type=str, help='module name')
parser.add_argument('-o', '--output', type=str, help='output file name')
args = parser.parse_args()
......@@ -27,16 +26,16 @@ def generate(ports=4, name=None, output=None):
n = ports
if name is None:
name = "axis_arb_mux_wrap_{0}".format(n)
name = 'axis_arb_mux_wrap_{0}'.format(n)
if output is None:
output = name + ".v"
output = name + '.v'
print("Opening file '{0}'...".format(output))
output_file = open(output, 'w')
print("Generating {0} port AXI stream arbitrated mux wrapper {1}...".format(n, name))
print('Generating {0} port AXI stream arbitrated mux wrapper {1}...'.format(n, name))
cn = int(math.ceil(math.log(n, 2)))
......@@ -173,8 +172,7 @@ endmodule
name=name
))
print("Done")
print('Done')
if __name__ == "__main__":
if __name__ == '__main__':
main()
#!/usr/bin/env python
"""
Generates an AXI Stream crosspoint wrapper with the specified number of ports
"""
"""Generates an AXI Stream crosspoint wrapper with the specified number of
ports."""
from __future__ import print_function
......@@ -11,9 +10,9 @@ from jinja2 import Template
def main():
parser = argparse.ArgumentParser(description=__doc__.strip())
parser.add_argument('-p', '--ports', type=int, default=[4], nargs='+', help="number of ports")
parser.add_argument('-n', '--name', type=str, help="module name")
parser.add_argument('-o', '--output', type=str, help="output file name")
parser.add_argument('-p', '--ports', type=int, default=[4], nargs='+', help='number of ports')
parser.add_argument('-n', '--name', type=str, help='module name')
parser.add_argument('-o', '--output', type=str, help='output file name')
args = parser.parse_args()
......@@ -32,16 +31,16 @@ def generate(ports=4, name=None, output=None):
m, n = ports
if name is None:
name = "axis_crosspoint_wrap_{0}x{1}".format(m, n)
name = 'axis_crosspoint_wrap_{0}x{1}'.format(m, n)
if output is None:
output = name + ".v"
output = name + '.v'
print("Opening file '{0}'...".format(output))
output_file = open(output, 'w')
print("Generating {0}x{1} port AXI stream crosspoint wrapper {2}...".format(m, n, name))
print('Generating {0}x{1} port AXI stream crosspoint wrapper {2}...'.format(m, n, name))
cm = int(math.ceil(math.log(m, 2)))
cn = int(math.ceil(math.log(n, 2)))
......@@ -185,8 +184,7 @@ endmodule
name=name
))
print("Done")
print('Done')
if __name__ == "__main__":
if __name__ == '__main__':
main()
#!/usr/bin/env python
"""
Generates an AXI Stream demux wrapper with the specified number of ports
"""
"""Generates an AXI Stream demux wrapper with the specified number of ports."""
from __future__ import print_function
......@@ -11,9 +9,9 @@ from jinja2 import Template
def main():
parser = argparse.ArgumentParser(description=__doc__.strip())
parser.add_argument('-p', '--ports', type=int, default=4, help="number of ports")
parser.add_argument('-n', '--name', type=str, help="module name")
parser.add_argument('-o', '--output', type=str, help="output file name")
parser.add_argument('-p', '--ports', type=int, default=4, help='number of ports')
parser.add_argument('-n', '--name', type=str, help='module name')
parser.add_argument('-o', '--output', type=str, help='output file name')
args = parser.parse_args()
......@@ -27,16 +25,16 @@ def generate(ports=4, name=None, output=None):
n = ports
if name is None:
name = "axis_demux_wrap_{0}".format(n)
name = 'axis_demux_wrap_{0}'.format(n)
if output is None:
output = name + ".v"
output = name + '.v'
print("Opening file '{0}'...".format(output))
output_file = open(output, 'w')
print("Generating {0} port AXI stream demux wrapper {1}...".format(n, name))
print('Generating {0} port AXI stream demux wrapper {1}...'.format(n, name))
cn = int(math.ceil(math.log(n, 2)))
......@@ -179,8 +177,7 @@ endmodule
name=name
))
print("Done")
print('Done')
if __name__ == "__main__":
if __name__ == '__main__':
main()
#!/usr/bin/env python
"""
Generates an AXI Stream frame joiner wrapper with the specified number of ports
"""
"""Generates an AXI Stream frame joiner wrapper with the specified number of
ports."""
from __future__ import print_function
......@@ -11,9 +10,9 @@ from jinja2 import Template
def main():
parser = argparse.ArgumentParser(description=__doc__.strip())
parser.add_argument('-p', '--ports', type=int, default=4, help="number of ports")
parser.add_argument('-n', '--name', type=str, help="module name")
parser.add_argument('-o', '--output', type=str, help="output file name")
parser.add_argument('-p', '--ports', type=int, default=4, help='number of ports')
parser.add_argument('-n', '--name', type=str, help='module name')
parser.add_argument('-o', '--output', type=str, help='output file name')
args = parser.parse_args()
......@@ -27,16 +26,16 @@ def generate(ports=4, name=None, output=None):
n = ports
if name is None:
name = "axis_frame_join_wrap_{0}".format(n)
name = 'axis_frame_join_wrap_{0}'.format(n)
if output is None:
output = name + ".v"
output = name + '.v'
print("Opening file '{0}'...".format(output))
output_file = open(output, 'w')
print("Generating {0} port AXI stream frame joiner wrapper {1}...".format(n, name))
print('Generating {0} port AXI stream frame joiner wrapper {1}...'.format(n, name))
cn = int(math.ceil(math.log(n, 2)))
......@@ -151,8 +150,7 @@ endmodule
name=name
))
print("Done")
print('Done')
if __name__ == "__main__":
if __name__ == '__main__':
main()
#!/usr/bin/env python
"""
Generates an AXI Stream mux wrapper with the specified number of ports
"""
"""Generates an AXI Stream mux wrapper with the specified number of ports."""
from __future__ import print_function
......@@ -11,9 +9,9 @@ from jinja2 import Template
def main():
parser = argparse.ArgumentParser(description=__doc__.strip())
parser.add_argument('-p', '--ports', type=int, default=4, help="number of ports")
parser.add_argument('-n', '--name', type=str, help="module name")
parser.add_argument('-o', '--output', type=str, help="output file name")
parser.add_argument('-p', '--ports', type=int, default=4, help='number of ports')
parser.add_argument('-n', '--name', type=str, help='module name')
parser.add_argument('-o', '--output', type=str, help='output file name')
args = parser.parse_args()
......@@ -27,16 +25,16 @@ def generate(ports=4, name=None, output=None):
n = ports
if name is None:
name = "axis_mux_wrap_{0}".format(n)
name = 'axis_mux_wrap_{0}'.format(n)
if output is None:
output = name + ".v"
output = name + '.v'
print("Opening file '{0}'...".format(output))
output_file = open(output, 'w')
print("Generating {0} port AXI stream mux wrapper {1}...".format(n, name))
print('Generating {0} port AXI stream mux wrapper {1}...'.format(n, name))
cn = int(math.ceil(math.log(n, 2)))
......@@ -176,8 +174,7 @@ endmodule
name=name
))
print("Done")
print('Done')
if __name__ == "__main__":
if __name__ == '__main__':
main()
#!/usr/bin/env python
"""
Generates an AXI Stream switch wrapper with the specified number of ports
"""
"""Generates an AXI Stream switch wrapper with the specified number of ports."""
from __future__ import print_function
......@@ -11,9 +9,9 @@ from jinja2 import Template
def main():
parser = argparse.ArgumentParser(description=__doc__.strip())
parser.add_argument('-p', '--ports', type=int, default=[4], nargs='+', help="number of ports")
parser.add_argument('-n', '--name', type=str, help="module name")
parser.add_argument('-o', '--output', type=str, help="output file name")
parser.add_argument('-p', '--ports', type=int, default=[4], nargs='+', help='number of ports')
parser.add_argument('-n', '--name', type=str, help='module name')
parser.add_argument('-o', '--output', type=str, help='output file name')
args = parser.parse_args()
......@@ -32,16 +30,16 @@ def generate(ports=4, name=None, output=None):
m, n = ports
if name is None:
name = "axis_switch_wrap_{0}x{1}".format(m, n)
name = 'axis_switch_wrap_{0}x{1}'.format(m, n)
if output is None:
output = name + ".v"
output = name + '.v'
print("Opening file '{0}'...".format(output))
output_file = open(output, 'w')
print("Generating {0}x{1} port AXI stream switch wrapper {2}...".format(m, n, name))
print('Generating {0}x{1} port AXI stream switch wrapper {2}...'.format(m, n, name))
cm = int(math.ceil(math.log(m, 2)))
cn = int(math.ceil(math.log(n, 2)))
......@@ -212,8 +210,7 @@ endmodule
name=name
))
print("Done")
print('Done')
if __name__ == "__main__":
if __name__ == '__main__':
main()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment