def benchmark_field_write_16(nb_operations, do_checksum=False): """ This method generate the P4 program to benchmark packet modification :param nb_operations: the number of Set-Field actions :type nb_operations: int :returns: bool -- True if there is no error """ out_dir = 'output' if not os.path.exists(out_dir): os.makedirs(out_dir) fwd_tbl = 'forward_table' nb_headers = 1 program = add_headers_and_parsers_16(nb_headers, nb_operations) program += add_ingress_block_16(nb_operations) arguments = 'inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata' program += add_control_block_16('egress', '', '', '', arguments) applies = '\t\tpacket.emit(hdr.ethernet);\n' applies += '\t\tpacket.emit(hdr.ptp);\n' for i in range(nb_headers): applies += '\t\tpacket.emit(hdr.header_%d);\n' % i program += add_control_block_16('DeparserImpl', '', '', applies, 'packet_out packet, in headers hdr') program += add_control_block_16('verifyChecksum', '', '', '', 'inout headers hdr, inout metadata meta') program += add_control_block_16('computeChecksum', '', '', '', 'inout headers hdr, inout metadata meta') program += add_main_module() with open('%s/main.p4' % out_dir, 'w') as out: out.write(program) action_name = 'mod_headers' table_name = 'test_tbl' commands = add_default_rule(table_name, '_nop') # commands += add_rule(table_name, action_name, 319) commands += add_default_rule(table_name, action_name) commands += cli_commands(fwd_tbl) with open('%s/commands.txt' % out_dir, 'w') as out: out.write(commands) copy_scripts(out_dir) set_custom_field_pcap(nb_operations, out_dir, packet_size=256) generate_pisces_command(nb_operations, out_dir, do_checksum) return True
def benchmark_field_write(nb_operations, do_checksum=False): """ This method generate the P4 program to benchmark packet modification :param nb_operations: the number of Set-Field actions :type nb_operations: int :returns: bool -- True if there is no error """ out_dir = 'output' if not os.path.exists(out_dir): os.makedirs(out_dir) fwd_tbl = 'forward_table' nb_headers = 1 program = add_headers_and_parsers(nb_headers, nb_operations) program += nop_action_14() program += forward_table() action_name = 'mod_headers' program += write_to_custom_header(action_name, nb_operations) table_name = 'test_tbl' match = 'ptp.reserved2 : exact;' actions = '\t\t_nop;\n\t\t{0};'.format(action_name) program += add_table(table_name, match, actions, 4, 14) program += control(fwd_tbl, apply_table(table_name)) with open('%s/main.p4' % out_dir, 'w') as out: out.write(program) commands = add_default_rule(table_name, '_nop') # commands += add_rule(table_name, action_name, 319) commands += add_default_rule(table_name, action_name) commands += cli_commands(fwd_tbl) with open('%s/commands.txt' % out_dir, 'w') as out: out.write(commands) copy_scripts(out_dir) set_custom_field_pcap(nb_operations, out_dir, packet_size=256) generate_pisces_command(nb_operations, out_dir, do_checksum) return True