示例#1
0
def benchmark_parser_header_16(nb_headers, nb_fields, do_checksum=False):
    """
    This method generate the P4 program to benchmark the P4 parser

    :param nb_headers: the number of generic headers included in the program
    :type nb_headers: int
    :param nb_fields: the number of fields (16 bits) in each header
    :type tbl_size: int
    :returns: bool -- True if there is no error

    """
    output_dir = 'output'
    if not os.path.exists(output_dir):
       os.makedirs(output_dir)
    program  = add_headers_and_parsers_16(nb_headers, nb_fields, do_checksum)
    program += add_ingress_block_16()

    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()

    fwd_tbl = 'forward_table'
    commands = cli_commands(fwd_tbl)
    with open ('%s/commands.txt' % output_dir, 'w') as out:
        out.write(commands)
    write_output(output_dir, program)
    get_parser_header_pcap(nb_fields, nb_headers, output_dir)
    generate_pisces_command(output_dir, nb_headers, nb_fields, do_checksum)

    return True
示例#2
0
def benchmark_parser_header16(nb_headers, nb_fields, do_checksum=False):
    """
    This method generate the P4-16 program to benchmark the P4 parser

    :param nb_headers: the number of generic headers included in the program
    :type nb_headers: int
    :param nb_fields: the number of fields (16 bits) in each header
    :type tbl_size: int
    :returns: bool -- True if there is no error

    """
    output_dir = 'output_16'
    if not os.path.exists(output_dir):
        os.makedirs(output_dir)
    program = add_headers_and_parsers16(nb_headers, nb_fields, do_checksum)
    program += add_ingress_block16(nb_headers, output_dir)
    write_output(output_dir, program)
    get_parser_header_pcap(nb_fields, nb_headers, output_dir)
    generate_pisces_command(output_dir, nb_headers, nb_fields, do_checksum)
    return True
示例#3
0
def parser_complexity(depth, fanout):
    """
    This method adds Ethernet, IPv4, TCP, UDP, and a number of generic headers
    which follow the UDP header. The UDP destination port 0x9091 is used to
    identify the generic header

    :param depth: the depth of the parsing graph
    :type depth: int
    :param fanout: the number branches for each node
    :type fanout: int
    :returns: str -- the header and parser definition

    """
    program = p4_define() + ethernet_header() + ptp_header() + parser_start()

    next_headers = select_case('ETHERTYPE_PTP', 'parse_ptp')
    next_headers += select_case('default', 'ingress')
    program += add_parser('ethernet_t', 'ethernet', 'parse_ethernet',
                          'etherType', next_headers)

    ptp_next_states = ''
    for i in range(fanout):
        ptp_next_states += select_case(i + 1, 'parse_header_%d' % i)
    ptp_next_states += select_case('default', 'ingress')
    program += add_parser('ptp_t', 'ptp', 'parse_ptp', 'reserved2',
                          ptp_next_states)

    root = ParseNode()
    loop_rec(root, depth, fanout)
    program += preorder(root)

    output_dir = 'output'
    if not os.path.exists(output_dir):
        os.makedirs(output_dir)
    program = add_forwarding_table(output_dir, program)
    write_output(output_dir, program)
    get_parser_header_pcap(depth + 1, 1, output_dir)

    return True
示例#4
0
def parser_complexity16(depth, fanout):
    """
    This method adds Ethernet, IPv4, TCP, UDP, and a number of generic headers
    which follow the UDP header. The UDP destination port 0x9091 is used to
    identify the generic header

    :param depth: the depth of the parsing graph
    :type depth: int
    :param fanout: the number branches for each node
    :type fanout: int
    :returns: str -- the header and parser definition

    """
    program = p4_define16() + ethernet_header16()

    root = ParseNode()
    loop_rec16(root, depth, fanout)
    program += header_dec16(root)

    program += ptp_header16()
    program += 'struct metadata{\n}\n\n'
    program += 'struct headers{\n'
    program += add_struct_header16('ethernet_t', 'ethernet')
    program += struct_header16(root)
    program += add_struct_header16('ptp_t', 'ptp')

    program += '}\n\n'
    program += add_parser_complex16(root, depth, fanout)
    output_dir = 'output_16'
    if not os.path.exists(output_dir):
        os.makedirs(output_dir)
    program += add_ingress_block_complex16(root, output_dir)
    write_output(output_dir, program)
    get_parser_header_pcap(depth + 1, 1, output_dir)

    return True
示例#5
0
def parser_complexity_16(depth, fanout):
    """
    This method adds Ethernet, IPv4, TCP, UDP, and a number of generic headers
    which follow the UDP header. The UDP destination port 0x9091 is used to
    identify the generic header

    :param depth: the depth of the parsing graph
    :type depth: int
    :param fanout: the number branches for each node
    :type fanout: int
    :returns: str -- the header and parser definition

    """
    output_dir = 'output'
    if not os.path.exists(output_dir):
       os.makedirs(output_dir)

    fwd_tbl = 'forward_table'

    program = p4_define(16) + ethernet_header(16) + ptp_header(16)

    root = ParseNode()
    loop_rec_16(root, depth, fanout)

    program += preorder_header(root)

    program += add_metadata()

    header_dec = ''
    header_dec += add_struct_item('ethernet_t', 'ethernet')
    header_dec += add_struct_item('ptp_t', 'ptp')

    header_dec += preorder_header_dec(root)

    program += add_headers(header_dec)

    states_dec = ''
    states_dec += add_state_without_select('start','parse_ethernet')

    next_states = select_case('16w0x88f7', 'parse_ptp')
    next_states += select_case('default', 'accept')
    states_dec += add_state('parse_ethernet', 'ethernet', 'etherType', next_states)

    next_states = select_case('8w1', 'parse_header_0')
    next_states += select_case('default', 'accept')
    states_dec += add_state('parse_ptp', 'ptp', 'reserved2', next_states)

    states_dec += preorder_parser(root)

    program += parser_16(states_dec, 'ParserImpl')

    program += add_ingress_block_16()

    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'

    applies += preorder_headers(root)

    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()


    commands = cli_commands(fwd_tbl)
    with open ('%s/commands.txt' % output_dir, 'w') as out:
        out.write(commands)
    write_output(output_dir, program)
    get_parser_header_pcap(depth+1, 1, output_dir)

    return True