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 test_benchmark_memory_consumption_generator(self): ret = benchmark_memory(10, 32, 1024, 1) self.assertTrue(ret) prog = 'main' ret = call([ self.p4c, 'output/%s.p4' % prog, '--json', 'output/%s.json' % prog ]) self.assertEqual(ret, 0)
def compile_p4_program(self): ret = benchmark_memory(1, 32, 1024, self.operation, False) 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 compile_p4_program(self): ret = benchmark_memory(self.nb_registers, self.element_size, self.nb_elements, 1) 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 compile_p4_program(self): # each operation write to a distinguished register registers = self.operation ret = benchmark_memory(registers, 32, 1024, 1, True) 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)
print("cazz") 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': print("caz") #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") #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) if __name__=='__main__': main()
if conf['type'] == 'mod': assert 'operations' in conf assert 'fields' in conf ret = benchmark_modification(int(conf['operations']), int(conf['fields']), 'mod') assert ret == True build_p4_prog() elif conf['type'] == 'field': assert 'operations' in conf ret = benchmark_field_write(int(conf['operations'])) assert ret == True build_p4_prog() elif conf['type'] == 'mem': assert 'registers' in conf and 'size' in conf and 'elements' in conf and 'operations' in conf write_op = True if 'write' in conf: write_op = conf['write'].lower() in ['1', 'true', 't', 'yes', 'y'] ret = benchmark_memory(int(conf['registers']), int(conf['size']), int(conf['elements']), int(conf['operations']), write_op) assert ret == True build_p4_prog() elif conf['type'] == 'pipeline': assert 'tables' in conf and 'tbl_size' in conf ret = benchmark_pipeline(int(conf['tables']), int(conf['tbl_size'])) assert ret == True build_p4_prog() elif conf['type'] == 'parser': assert 'headers' in conf and 'fields' in conf ret = benchmark_parser_header(int(conf['headers']), int(conf['fields'])) assert ret == True build_p4_prog() else: assert False, "unknown experiment type: " + conf['type']
def test_generate_multiple_registers(self): ret = benchmark_memory(10, 32, 1024, 1) self.assertTrue(ret)
def test_generate_single_register(self): ret = benchmark_memory(3, 32, 1024, 10) self.assertTrue(ret)