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_remove_header_generator(self): ret = benchmark_modification(10, 4, 'rm') 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_modification(self.nb_header, self.nb_field, 'rm') 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()
def test_benchmark_add_header(self): ret = benchmark_modification(10, 4, 'add') self.assertTrue(ret)
def test_benchmark_remove_many_header(self): ret = benchmark_modification(32, 4, 'rm') self.assertTrue(ret)
# Create the directory we will run in exp_dir_path = os.path.dirname(args.json_file) exp_out_path = os.path.join(exp_dir_path, 'out') if os.path.exists(exp_out_path): assert os.path.isdir(exp_out_path) else: os.mkdir(exp_out_path) os.chdir(exp_out_path) assert 'type' in conf # Generate the P4 program, test pcap, etc. 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':