def main(): parser = argparse.ArgumentParser(description='A programs that generate a' ' P4 program for benchmarking a particular feature') parser.add_argument('--feature', choices=features, help='select a feature for benchmarking') parser.add_argument('--checksum', default=False, action='store_true', help='perform update checksum') # Processing options parser.add_argument('--tables', default=1, type=int, help='number of tables') parser.add_argument('--table-size', default=1, type=int, help='number of rules in the table') # Parser (Field|Header) and Packet Modification options parser.add_argument('--headers', default=1, type=int, help='number of headers') parser.add_argument('--fields', default=1, type=int, help='number of fields') # Parser Complexity parser.add_argument('--depth', default=1, type=int, help='the depth of the parse graph') parser.add_argument('--fanout', default=2, type=int, help='the number of branch of a node in the parse graph') # State Access option parser.add_argument('--registers', default=1, type=int, help='number of registers') parser.add_argument('--nb-element', default=1024, type=int, help='number of element in a register') parser.add_argument('--element-width', default=32, type=int, help='the bit width of a register element') # Parser Action complexity parser.add_argument('--operations', default=1, type=int, help='the number of set-field/read/write operations') args = parser.parse_args() if args.feature == 'parse-header': benchmark_parser_header(args.headers, args.fields, do_checksum=args.checksum) elif args.feature == 'parse-field': benchmark_parser_with_header_field(args.fields, do_checksum=args.checksum) elif args.feature == 'parse-complex': parser_complexity(args.depth, args.fanout) elif args.feature == 'set-field': benchmark_field_write(args.operations, do_checksum=args.checksum) elif args.feature == 'add-header': benchmark_modification(args.headers, args.fields, 'add') elif args.feature == 'rm-header': benchmark_modification(args.headers, args.fields, 'rm') elif args.feature == 'pipeline': benchmark_pipeline(args.tables, args.table_size) elif args.feature == 'read-state': benchmark_memory(args.registers, args.element_width, args.nb_element, args.operations, False) elif args.feature == 'write-state': benchmark_memory(args.registers, args.element_width, args.nb_element, args.operations, True) else: parser.print_help() sys.exit(0) print "Generate files to 'output' directory"
def main(): parser = argparse.ArgumentParser( description='A programs that generate a' ' P4 program for benchmarking a particular feature') parser.add_argument('--feature', choices=features, help='select a feature for benchmarking') parser.add_argument('--checksum', default=False, action='store_true', help='perform update checksum') # Parser (Field|Header) and Packet Modification options parser.add_argument('--headers', default=1, type=int, help='number of headers') parser.add_argument('--fields', default=1, type=int, help='number of fields') # Parser Complexity parser.add_argument('--depth', default=1, type=int, help='the depth of the parse graph') parser.add_argument( '--fanout', default=2, type=int, help='the number of branch of a node in the parse graph') args = parser.parse_args() if args.feature == 'parse-header': benchmark_parser_header(args.headers, args.fields, do_checksum=args.checksum) elif args.feature == 'parse-field': benchmark_parser_with_header_field(args.fields, do_checksum=args.checksum) elif args.feature == 'parse-complex': parser_complexity(args.depth, args.fanout) elif args.feature == 'parse-header16': benchmark_parser_header(args.headers, args.fields, do_checksum=args.checksum) elif args.feature == 'parse-field16': print("cazz") #benchmark_parser_with_header_field(args.fields, do_checksum=args.checksum) elif args.feature == 'parse-complex16': print("cazzz")
def compile_p4_program(self): ret = benchmark_parser_with_header_field(self.nb_field) assert (ret == True) prog = 'main' json_path = 'output/%s.json' % prog out_file = '{0}/p4c.log'.format(self.directory) with open(out_file, 'w+') as out: p = Popen([self.p4c, 'output/%s.p4' % prog, '--json', json_path], stdout=out, stderr=out) p.wait() assert (p.returncode == 0)
def test_benchmark_parser_field(self): ret = benchmark_parser_with_header_field(10) self.assertTrue(ret)