コード例 #1
0
def bench():

    # Inputs
    clk = Signal(bool(0))
    rst = Signal(bool(0))
    current_test = Signal(intbv(0)[8:])

    input_eth_hdr_valid = Signal(bool(0))
    input_eth_dest_mac = Signal(intbv(0)[48:])
    input_eth_src_mac = Signal(intbv(0)[48:])
    input_eth_type = Signal(intbv(0)[16:])
    input_eth_payload_tdata = Signal(intbv(0)[64:])
    input_eth_payload_tkeep = Signal(intbv(0)[8:])
    input_eth_payload_tvalid = Signal(bool(0))
    input_eth_payload_tlast = Signal(bool(0))
    input_eth_payload_tuser = Signal(bool(0))
    input_ip_hdr_valid = Signal(bool(0))
    input_ip_dscp = Signal(intbv(0)[6:])
    input_ip_ecn = Signal(intbv(0)[2:])
    input_ip_length = Signal(intbv(0)[16:])
    input_ip_ttl = Signal(intbv(0)[8:])
    input_ip_protocol = Signal(intbv(0)[8:])
    input_ip_source_ip = Signal(intbv(0)[32:])
    input_ip_dest_ip = Signal(intbv(0)[32:])
    input_ip_payload_tdata = Signal(intbv(0)[64:])
    input_ip_payload_tkeep = Signal(intbv(0)[8:])
    input_ip_payload_tvalid = Signal(bool(0))
    input_ip_payload_tlast = Signal(bool(0))
    input_ip_payload_tuser = Signal(bool(0))
    input_udp_hdr_valid = Signal(bool(0))
    input_udp_ip_dscp = Signal(intbv(0)[6:])
    input_udp_ip_ecn = Signal(intbv(0)[2:])
    input_udp_ip_ttl = Signal(intbv(0)[8:])
    input_udp_ip_source_ip = Signal(intbv(0)[32:])
    input_udp_ip_dest_ip = Signal(intbv(0)[32:])
    input_udp_source_port = Signal(intbv(0)[16:])
    input_udp_dest_port = Signal(intbv(0)[16:])
    input_udp_length = Signal(intbv(0)[16:])
    input_udp_checksum = Signal(intbv(0)[16:])
    input_udp_payload_tdata = Signal(intbv(0)[64:])
    input_udp_payload_tkeep = Signal(intbv(0)[8:])
    input_udp_payload_tvalid = Signal(bool(0))
    input_udp_payload_tlast = Signal(bool(0))
    input_udp_payload_tuser = Signal(bool(0))
    output_eth_payload_tready = Signal(bool(0))
    output_eth_hdr_ready = Signal(bool(0))
    output_ip_hdr_ready = Signal(bool(0))
    output_ip_payload_tready = Signal(bool(0))
    output_udp_hdr_ready = Signal(bool(0))
    output_udp_payload_tready = Signal(bool(0))

    # Outputs
    input_eth_hdr_ready = Signal(bool(0))
    input_eth_payload_tready = Signal(bool(0))
    input_ip_hdr_ready = Signal(bool(0))
    input_ip_payload_tready = Signal(bool(0))
    input_udp_hdr_ready = Signal(bool(0))
    input_udp_payload_tready = Signal(bool(0))
    output_eth_hdr_valid = Signal(bool(0))
    output_eth_dest_mac = Signal(intbv(0)[48:])
    output_eth_src_mac = Signal(intbv(0)[48:])
    output_eth_type = Signal(intbv(0)[16:])
    output_eth_payload_tdata = Signal(intbv(0)[64:])
    output_eth_payload_tkeep = Signal(intbv(0)[8:])
    output_eth_payload_tvalid = Signal(bool(0))
    output_eth_payload_tlast = Signal(bool(0))
    output_eth_payload_tuser = Signal(bool(0))
    output_ip_hdr_valid = Signal(bool(0))
    output_ip_eth_dest_mac = Signal(intbv(0)[48:])
    output_ip_eth_src_mac = Signal(intbv(0)[48:])
    output_ip_eth_type = Signal(intbv(0)[16:])
    output_ip_version = Signal(intbv(0)[4:])
    output_ip_ihl = Signal(intbv(0)[4:])
    output_ip_dscp = Signal(intbv(0)[6:])
    output_ip_ecn = Signal(intbv(0)[2:])
    output_ip_length = Signal(intbv(0)[16:])
    output_ip_identification = Signal(intbv(0)[16:])
    output_ip_flags = Signal(intbv(0)[3:])
    output_ip_fragment_offset = Signal(intbv(0)[13:])
    output_ip_ttl = Signal(intbv(0)[8:])
    output_ip_protocol = Signal(intbv(0)[8:])
    output_ip_header_checksum = Signal(intbv(0)[16:])
    output_ip_source_ip = Signal(intbv(0)[32:])
    output_ip_dest_ip = Signal(intbv(0)[32:])
    output_ip_payload_tdata = Signal(intbv(0)[64:])
    output_ip_payload_tkeep = Signal(intbv(0)[8:])
    output_ip_payload_tvalid = Signal(bool(0))
    output_ip_payload_tlast = Signal(bool(0))
    output_ip_payload_tuser = Signal(bool(0))
    output_udp_hdr_valid = Signal(bool(0))
    output_udp_eth_dest_mac = Signal(intbv(0)[48:])
    output_udp_eth_src_mac = Signal(intbv(0)[48:])
    output_udp_eth_type = Signal(intbv(0)[16:])
    output_udp_ip_version = Signal(intbv(0)[4:])
    output_udp_ip_ihl = Signal(intbv(0)[4:])
    output_udp_ip_dscp = Signal(intbv(0)[6:])
    output_udp_ip_ecn = Signal(intbv(0)[2:])
    output_udp_ip_length = Signal(intbv(0)[16:])
    output_udp_ip_identification = Signal(intbv(0)[16:])
    output_udp_ip_flags = Signal(intbv(0)[3:])
    output_udp_ip_fragment_offset = Signal(intbv(0)[13:])
    output_udp_ip_ttl = Signal(intbv(0)[8:])
    output_udp_ip_protocol = Signal(intbv(0)[8:])
    output_udp_ip_header_checksum = Signal(intbv(0)[16:])
    output_udp_ip_source_ip = Signal(intbv(0)[32:])
    output_udp_ip_dest_ip = Signal(intbv(0)[32:])
    output_udp_source_port = Signal(intbv(0)[16:])
    output_udp_dest_port = Signal(intbv(0)[16:])
    output_udp_length = Signal(intbv(0)[16:])
    output_udp_checksum = Signal(intbv(0)[16:])
    output_udp_payload_tdata = Signal(intbv(0)[64:])
    output_udp_payload_tkeep = Signal(intbv(0)[8:])
    output_udp_payload_tvalid = Signal(bool(0))
    output_udp_payload_tlast = Signal(bool(0))
    output_udp_payload_tuser = Signal(bool(0))
    ip_rx_busy = Signal(bool(0))
    ip_tx_busy = Signal(bool(0))
    udp_rx_busy = Signal(bool(0))
    udp_tx_busy = Signal(bool(0))
    ip_rx_error_header_early_termination = Signal(bool(0))
    ip_rx_error_payload_early_termination = Signal(bool(0))
    ip_rx_error_invalid_header = Signal(bool(0))
    ip_rx_error_invalid_checksum = Signal(bool(0))
    ip_tx_error_payload_early_termination = Signal(bool(0))
    ip_tx_error_arp_failed = Signal(bool(0))
    udp_rx_error_header_early_termination = Signal(bool(0))
    udp_rx_error_payload_early_termination = Signal(bool(0))
    udp_tx_error_payload_early_termination = Signal(bool(0))
    local_mac = Signal(intbv(0)[48:])
    local_ip = Signal(intbv(0)[32:])
    gateway_ip = Signal(intbv(0)[32:])
    subnet_mask = Signal(intbv(0)[32:])
    clear_arp_cache = Signal(bool(0))

    # sources and sinks
    eth_source_queue = Queue()
    eth_source_pause = Signal(bool(0))
    eth_sink_queue = Queue()
    eth_sink_pause = Signal(bool(0))
    ip_source_queue = Queue()
    ip_source_pause = Signal(bool(0))
    ip_sink_queue = Queue()
    ip_sink_pause = Signal(bool(0))
    udp_source_queue = Queue()
    udp_source_pause = Signal(bool(0))
    udp_sink_queue = Queue()
    udp_sink_pause = Signal(bool(0))

    eth_source = eth_ep.EthFrameSource(
        clk,
        rst,
        eth_hdr_ready=input_eth_hdr_ready,
        eth_hdr_valid=input_eth_hdr_valid,
        eth_dest_mac=input_eth_dest_mac,
        eth_src_mac=input_eth_src_mac,
        eth_type=input_eth_type,
        eth_payload_tdata=input_eth_payload_tdata,
        eth_payload_tkeep=input_eth_payload_tkeep,
        eth_payload_tvalid=input_eth_payload_tvalid,
        eth_payload_tready=input_eth_payload_tready,
        eth_payload_tlast=input_eth_payload_tlast,
        eth_payload_tuser=input_eth_payload_tuser,
        fifo=eth_source_queue,
        pause=eth_source_pause,
        name='eth_source')

    eth_sink = eth_ep.EthFrameSink(
        clk,
        rst,
        eth_hdr_ready=output_eth_hdr_ready,
        eth_hdr_valid=output_eth_hdr_valid,
        eth_dest_mac=output_eth_dest_mac,
        eth_src_mac=output_eth_src_mac,
        eth_type=output_eth_type,
        eth_payload_tdata=output_eth_payload_tdata,
        eth_payload_tkeep=output_eth_payload_tkeep,
        eth_payload_tvalid=output_eth_payload_tvalid,
        eth_payload_tready=output_eth_payload_tready,
        eth_payload_tlast=output_eth_payload_tlast,
        eth_payload_tuser=output_eth_payload_tuser,
        fifo=eth_sink_queue,
        pause=eth_sink_pause,
        name='eth_sink')

    ip_source = ip_ep.IPFrameSource(clk,
                                    rst,
                                    ip_hdr_valid=input_ip_hdr_valid,
                                    ip_hdr_ready=input_ip_hdr_ready,
                                    ip_dscp=input_ip_dscp,
                                    ip_ecn=input_ip_ecn,
                                    ip_length=input_ip_length,
                                    ip_ttl=input_ip_ttl,
                                    ip_protocol=input_ip_protocol,
                                    ip_source_ip=input_ip_source_ip,
                                    ip_dest_ip=input_ip_dest_ip,
                                    ip_payload_tdata=input_ip_payload_tdata,
                                    ip_payload_tkeep=input_ip_payload_tkeep,
                                    ip_payload_tvalid=input_ip_payload_tvalid,
                                    ip_payload_tready=input_ip_payload_tready,
                                    ip_payload_tlast=input_ip_payload_tlast,
                                    ip_payload_tuser=input_ip_payload_tuser,
                                    fifo=ip_source_queue,
                                    pause=ip_source_pause,
                                    name='ip_source')

    ip_sink = ip_ep.IPFrameSink(clk,
                                rst,
                                ip_hdr_ready=output_ip_hdr_ready,
                                ip_hdr_valid=output_ip_hdr_valid,
                                eth_dest_mac=output_ip_eth_dest_mac,
                                eth_src_mac=output_ip_eth_src_mac,
                                eth_type=output_ip_eth_type,
                                ip_version=output_ip_version,
                                ip_ihl=output_ip_ihl,
                                ip_dscp=output_ip_dscp,
                                ip_ecn=output_ip_ecn,
                                ip_length=output_ip_length,
                                ip_identification=output_ip_identification,
                                ip_flags=output_ip_flags,
                                ip_fragment_offset=output_ip_fragment_offset,
                                ip_ttl=output_ip_ttl,
                                ip_protocol=output_ip_protocol,
                                ip_header_checksum=output_ip_header_checksum,
                                ip_source_ip=output_ip_source_ip,
                                ip_dest_ip=output_ip_dest_ip,
                                ip_payload_tdata=output_ip_payload_tdata,
                                ip_payload_tkeep=output_ip_payload_tkeep,
                                ip_payload_tvalid=output_ip_payload_tvalid,
                                ip_payload_tready=output_ip_payload_tready,
                                ip_payload_tlast=output_ip_payload_tlast,
                                ip_payload_tuser=output_ip_payload_tuser,
                                fifo=ip_sink_queue,
                                pause=ip_sink_pause,
                                name='ip_sink')

    udp_source = udp_ep.UDPFrameSource(
        clk,
        rst,
        udp_hdr_valid=input_udp_hdr_valid,
        udp_hdr_ready=input_udp_hdr_ready,
        ip_dscp=input_udp_ip_dscp,
        ip_ecn=input_udp_ip_ecn,
        ip_ttl=input_udp_ip_ttl,
        ip_source_ip=input_udp_ip_source_ip,
        ip_dest_ip=input_udp_ip_dest_ip,
        udp_source_port=input_udp_source_port,
        udp_dest_port=input_udp_dest_port,
        udp_length=input_udp_length,
        udp_checksum=input_udp_checksum,
        udp_payload_tdata=input_udp_payload_tdata,
        udp_payload_tkeep=input_udp_payload_tkeep,
        udp_payload_tvalid=input_udp_payload_tvalid,
        udp_payload_tready=input_udp_payload_tready,
        udp_payload_tlast=input_udp_payload_tlast,
        udp_payload_tuser=input_udp_payload_tuser,
        fifo=udp_source_queue,
        pause=udp_source_pause,
        name='udp_source')

    udp_sink = udp_ep.UDPFrameSink(
        clk,
        rst,
        udp_hdr_ready=output_udp_hdr_ready,
        udp_hdr_valid=output_udp_hdr_valid,
        eth_dest_mac=output_udp_eth_dest_mac,
        eth_src_mac=output_udp_eth_src_mac,
        eth_type=output_udp_eth_type,
        ip_version=output_udp_ip_version,
        ip_ihl=output_udp_ip_ihl,
        ip_dscp=output_udp_ip_dscp,
        ip_ecn=output_udp_ip_ecn,
        ip_length=output_udp_ip_length,
        ip_identification=output_udp_ip_identification,
        ip_flags=output_udp_ip_flags,
        ip_fragment_offset=output_udp_ip_fragment_offset,
        ip_ttl=output_udp_ip_ttl,
        ip_protocol=output_udp_ip_protocol,
        ip_header_checksum=output_udp_ip_header_checksum,
        ip_source_ip=output_udp_ip_source_ip,
        ip_dest_ip=output_udp_ip_dest_ip,
        udp_source_port=output_udp_source_port,
        udp_dest_port=output_udp_dest_port,
        udp_length=output_udp_length,
        udp_checksum=output_udp_checksum,
        udp_payload_tdata=output_udp_payload_tdata,
        udp_payload_tkeep=output_udp_payload_tkeep,
        udp_payload_tvalid=output_udp_payload_tvalid,
        udp_payload_tready=output_udp_payload_tready,
        udp_payload_tlast=output_udp_payload_tlast,
        udp_payload_tuser=output_udp_payload_tuser,
        fifo=udp_sink_queue,
        pause=udp_sink_pause,
        name='udp_sink')

    # DUT
    dut = dut_udp_complete(
        clk, rst, current_test, input_eth_hdr_valid, input_eth_hdr_ready,
        input_eth_dest_mac, input_eth_src_mac, input_eth_type,
        input_eth_payload_tdata, input_eth_payload_tkeep,
        input_eth_payload_tvalid, input_eth_payload_tready,
        input_eth_payload_tlast, input_eth_payload_tuser, output_eth_hdr_valid,
        output_eth_hdr_ready, output_eth_dest_mac, output_eth_src_mac,
        output_eth_type, output_eth_payload_tdata, output_eth_payload_tkeep,
        output_eth_payload_tvalid, output_eth_payload_tready,
        output_eth_payload_tlast, output_eth_payload_tuser, input_ip_hdr_valid,
        input_ip_hdr_ready, input_ip_dscp, input_ip_ecn, input_ip_length,
        input_ip_ttl, input_ip_protocol, input_ip_source_ip, input_ip_dest_ip,
        input_ip_payload_tdata, input_ip_payload_tkeep,
        input_ip_payload_tvalid, input_ip_payload_tready,
        input_ip_payload_tlast, input_ip_payload_tuser, output_ip_hdr_valid,
        output_ip_hdr_ready, output_ip_eth_dest_mac, output_ip_eth_src_mac,
        output_ip_eth_type, output_ip_version, output_ip_ihl, output_ip_dscp,
        output_ip_ecn, output_ip_length, output_ip_identification,
        output_ip_flags, output_ip_fragment_offset, output_ip_ttl,
        output_ip_protocol, output_ip_header_checksum, output_ip_source_ip,
        output_ip_dest_ip, output_ip_payload_tdata, output_ip_payload_tkeep,
        output_ip_payload_tvalid, output_ip_payload_tready,
        output_ip_payload_tlast, output_ip_payload_tuser, input_udp_hdr_valid,
        input_udp_hdr_ready, input_udp_ip_dscp, input_udp_ip_ecn,
        input_udp_ip_ttl, input_udp_ip_source_ip, input_udp_ip_dest_ip,
        input_udp_source_port, input_udp_dest_port, input_udp_length,
        input_udp_checksum, input_udp_payload_tdata, input_udp_payload_tkeep,
        input_udp_payload_tvalid, input_udp_payload_tready,
        input_udp_payload_tlast, input_udp_payload_tuser, output_udp_hdr_valid,
        output_udp_hdr_ready, output_udp_eth_dest_mac, output_udp_eth_src_mac,
        output_udp_eth_type, output_udp_ip_version, output_udp_ip_ihl,
        output_udp_ip_dscp, output_udp_ip_ecn, output_udp_ip_length,
        output_udp_ip_identification, output_udp_ip_flags,
        output_udp_ip_fragment_offset, output_udp_ip_ttl,
        output_udp_ip_protocol, output_udp_ip_header_checksum,
        output_udp_ip_source_ip, output_udp_ip_dest_ip, output_udp_source_port,
        output_udp_dest_port, output_udp_length, output_udp_checksum,
        output_udp_payload_tdata, output_udp_payload_tkeep,
        output_udp_payload_tvalid, output_udp_payload_tready,
        output_udp_payload_tlast, output_udp_payload_tuser, ip_rx_busy,
        ip_tx_busy, udp_rx_busy, udp_tx_busy,
        ip_rx_error_header_early_termination,
        ip_rx_error_payload_early_termination, ip_rx_error_invalid_header,
        ip_rx_error_invalid_checksum, ip_tx_error_payload_early_termination,
        ip_tx_error_arp_failed, udp_rx_error_header_early_termination,
        udp_rx_error_payload_early_termination,
        udp_tx_error_payload_early_termination, local_mac, local_ip,
        gateway_ip, subnet_mask, clear_arp_cache)

    @always(delay(4))
    def clkgen():
        clk.next = not clk

    ip_rx_error_header_early_termination_asserted = Signal(bool(0))
    ip_rx_error_payload_early_termination_asserted = Signal(bool(0))
    ip_rx_error_invalid_header_asserted = Signal(bool(0))
    ip_rx_error_invalid_checksum_asserted = Signal(bool(0))
    ip_tx_error_payload_early_termination_asserted = Signal(bool(0))
    ip_tx_error_arp_failed_asserted = Signal(bool(0))
    udp_rx_error_header_early_termination_asserted = Signal(bool(0))
    udp_rx_error_payload_early_termination_asserted = Signal(bool(0))
    udp_tx_error_payload_early_termination_asserted = Signal(bool(0))

    @always(clk.posedge)
    def monitor():
        if (ip_rx_error_header_early_termination):
            ip_rx_error_header_early_termination_asserted.next = 1
        if (ip_rx_error_payload_early_termination):
            ip_rx_error_payload_early_termination_asserted.next = 1
        if (ip_rx_error_invalid_header):
            ip_rx_error_invalid_header_asserted.next = 1
        if (ip_rx_error_invalid_checksum):
            ip_rx_error_invalid_checksum_asserted.next = 1
        if (ip_tx_error_payload_early_termination):
            ip_tx_error_payload_early_termination_asserted.next = 1
        if (ip_tx_error_arp_failed):
            ip_tx_error_arp_failed_asserted.next = 1
        if (udp_rx_error_header_early_termination):
            udp_rx_error_header_early_termination_asserted.next = 1
        if (udp_rx_error_payload_early_termination):
            udp_rx_error_payload_early_termination_asserted.next = 1
        if (udp_tx_error_payload_early_termination):
            udp_tx_error_payload_early_termination_asserted.next = 1

    def wait_normal():
        while (input_eth_payload_tvalid or input_ip_payload_tvalid
               or input_udp_payload_tvalid or output_eth_payload_tvalid
               or output_ip_payload_tvalid or output_udp_payload_tvalid
               or input_eth_hdr_valid or input_ip_hdr_valid
               or input_udp_hdr_valid):
            yield clk.posedge

    @instance
    def check():
        yield delay(100)
        yield clk.posedge
        rst.next = 1
        yield clk.posedge
        rst.next = 0
        yield clk.posedge
        yield delay(100)
        yield clk.posedge

        # set MAC and IP address
        local_mac.next = 0x5A5152535455
        local_ip.next = 0xc0a80164
        gateway_ip.next = 0xc0a80101
        subnet_mask.next = 0xffffff00

        yield clk.posedge
        print("test 1: test IP RX packet")
        current_test.next = 1

        test_frame = ip_ep.IPFrame()
        test_frame.eth_dest_mac = 0x5A5152535455
        test_frame.eth_src_mac = 0xDAD1D2D3D4D5
        test_frame.eth_type = 0x0800
        test_frame.ip_version = 4
        test_frame.ip_ihl = 5
        test_frame.ip_dscp = 0
        test_frame.ip_ecn = 0
        test_frame.ip_length = None
        test_frame.ip_identification = 0
        test_frame.ip_flags = 2
        test_frame.ip_fragment_offset = 0
        test_frame.ip_ttl = 64
        test_frame.ip_protocol = 0x10
        test_frame.ip_header_checksum = None
        test_frame.ip_source_ip = 0xc0a80165
        test_frame.ip_dest_ip = 0xc0a80164
        test_frame.payload = bytearray(range(32))
        test_frame.build()
        eth_frame = test_frame.build_eth()

        eth_source_queue.put(eth_frame)

        yield clk.posedge
        yield clk.posedge

        yield wait_normal()

        yield clk.posedge
        yield clk.posedge

        rx_frame = ip_sink_queue.get(False)

        assert rx_frame == test_frame

        assert eth_source_queue.empty()
        assert eth_sink_queue.empty()
        assert ip_source_queue.empty()
        assert ip_sink_queue.empty()

        yield delay(100)

        yield clk.posedge
        print("test 2: test IP TX packet")
        current_test.next = 2

        # send IP packet
        test_frame = ip_ep.IPFrame()
        test_frame.eth_dest_mac = 0xDAD1D2D3D4D5
        test_frame.eth_src_mac = 0x5A5152535455
        test_frame.eth_type = 0x0800
        test_frame.ip_version = 4
        test_frame.ip_ihl = 5
        test_frame.ip_dscp = 0
        test_frame.ip_ecn = 0
        test_frame.ip_length = None
        test_frame.ip_identification = 0
        test_frame.ip_flags = 2
        test_frame.ip_fragment_offset = 0
        test_frame.ip_ttl = 64
        test_frame.ip_protocol = 0x10
        test_frame.ip_header_checksum = None
        test_frame.ip_source_ip = 0xc0a80164
        test_frame.ip_dest_ip = 0xc0a80166
        test_frame.payload = bytearray(range(32))
        test_frame.build()

        ip_source_queue.put(test_frame)

        # wait for ARP request packet
        while eth_sink_queue.empty():
            yield clk.posedge

        rx_frame = eth_sink_queue.get(False)
        check_frame = arp_ep.ARPFrame()
        check_frame.parse_eth(rx_frame)

        assert check_frame.eth_dest_mac == 0xFFFFFFFFFFFF
        assert check_frame.eth_src_mac == 0x5A5152535455
        assert check_frame.eth_type == 0x0806
        assert check_frame.arp_htype == 0x0001
        assert check_frame.arp_ptype == 0x0800
        assert check_frame.arp_hlen == 6
        assert check_frame.arp_plen == 4
        assert check_frame.arp_oper == 1
        assert check_frame.arp_sha == 0x5A5152535455
        assert check_frame.arp_spa == 0xc0a80164
        assert check_frame.arp_tha == 0x000000000000
        assert check_frame.arp_tpa == 0xc0a80166

        # generate response
        arp_frame = arp_ep.ARPFrame()
        arp_frame.eth_dest_mac = 0x5A5152535455
        arp_frame.eth_src_mac = 0xDAD1D2D3D4D5
        arp_frame.eth_type = 0x0806
        arp_frame.arp_htype = 0x0001
        arp_frame.arp_ptype = 0x0800
        arp_frame.arp_hlen = 6
        arp_frame.arp_plen = 4
        arp_frame.arp_oper = 2
        arp_frame.arp_sha = 0xDAD1D2D3D4D5
        arp_frame.arp_spa = 0xc0a80166
        arp_frame.arp_tha = 0x5A5152535455
        arp_frame.arp_tpa = 0xc0a80164
        eth_source_queue.put(arp_frame.build_eth())

        yield clk.posedge
        yield clk.posedge

        yield wait_normal()

        yield clk.posedge
        yield clk.posedge

        rx_frame = eth_sink_queue.get(False)

        check_frame = ip_ep.IPFrame()
        check_frame.parse_eth(rx_frame)

        print(test_frame)
        print(check_frame)

        assert check_frame == test_frame

        assert eth_source_queue.empty()
        assert eth_sink_queue.empty()
        assert ip_source_queue.empty()
        assert ip_sink_queue.empty()

        yield delay(100)

        yield clk.posedge
        print("test 3: test IP TX arp fail packet")
        current_test.next = 2

        ip_tx_error_arp_failed_asserted.next = 0

        test_frame = ip_ep.IPFrame()
        test_frame.eth_dest_mac = 0xDAD1D2D3D4D5
        test_frame.eth_src_mac = 0x5A5152535455
        test_frame.eth_type = 0x0800
        test_frame.ip_version = 4
        test_frame.ip_ihl = 5
        test_frame.ip_dscp = 0
        test_frame.ip_ecn = 0
        test_frame.ip_length = None
        test_frame.ip_identification = 0
        test_frame.ip_flags = 2
        test_frame.ip_fragment_offset = 0
        test_frame.ip_ttl = 64
        test_frame.ip_protocol = 0x10
        test_frame.ip_header_checksum = None
        test_frame.ip_source_ip = 0xc0a80164
        test_frame.ip_dest_ip = 0xc0a80167
        test_frame.payload = bytearray(range(32))
        test_frame.build()

        ip_source_queue.put(test_frame)

        yield clk.posedge
        yield clk.posedge

        yield wait_normal()

        yield clk.posedge
        yield clk.posedge

        assert ip_tx_error_arp_failed_asserted

        # check for 4 ARP requests
        assert eth_sink_queue.qsize() == 4

        while not eth_sink_queue.empty():
            rx_frame = eth_sink_queue.get(False)

            check_frame = arp_ep.ARPFrame()
            check_frame.parse_eth(rx_frame)

            assert check_frame.eth_dest_mac == 0xFFFFFFFFFFFF
            assert check_frame.eth_src_mac == 0x5A5152535455
            assert check_frame.eth_type == 0x0806
            assert check_frame.arp_htype == 0x0001
            assert check_frame.arp_ptype == 0x0800
            assert check_frame.arp_hlen == 6
            assert check_frame.arp_plen == 4
            assert check_frame.arp_oper == 1
            assert check_frame.arp_sha == 0x5A5152535455
            assert check_frame.arp_spa == 0xc0a80164
            assert check_frame.arp_tha == 0x000000000000
            assert check_frame.arp_tpa == 0xc0a80167

        assert eth_source_queue.empty()
        assert eth_sink_queue.empty()
        assert ip_source_queue.empty()
        assert ip_sink_queue.empty()

        yield delay(100)

        yield clk.posedge
        print("test 4: test UDP RX packet")
        current_test.next = 4

        test_frame = udp_ep.UDPFrame()
        test_frame.eth_dest_mac = 0x5A5152535455
        test_frame.eth_src_mac = 0xDAD1D2D3D4D5
        test_frame.eth_type = 0x0800
        test_frame.ip_version = 4
        test_frame.ip_ihl = 5
        test_frame.ip_dscp = 0
        test_frame.ip_ecn = 0
        test_frame.ip_length = None
        test_frame.ip_identification = 0
        test_frame.ip_flags = 2
        test_frame.ip_fragment_offset = 0
        test_frame.ip_ttl = 64
        test_frame.ip_protocol = 0x11
        test_frame.ip_header_checksum = None
        test_frame.ip_source_ip = 0xc0a80165
        test_frame.ip_dest_ip = 0xc0a80164
        test_frame.udp_source_port = 1234
        test_frame.udp_dest_port = 5678
        test_frame.payload = bytearray(range(32))
        test_frame.build()
        eth_frame = test_frame.build_eth()

        eth_source_queue.put(eth_frame)

        yield clk.posedge
        yield clk.posedge

        yield wait_normal()

        yield clk.posedge
        yield clk.posedge

        rx_frame = None
        if not udp_sink_queue.empty():
            rx_frame = udp_sink_queue.get()

        assert rx_frame == test_frame

        assert eth_source_queue.empty()
        assert eth_sink_queue.empty()
        assert udp_source_queue.empty()
        assert udp_sink_queue.empty()

        yield delay(100)

        yield clk.posedge
        print("test 5: test UDP TX packet")
        current_test.next = 5

        test_frame = udp_ep.UDPFrame()
        test_frame.eth_dest_mac = 0xDAD1D2D3D4D5
        test_frame.eth_src_mac = 0x5A5152535455
        test_frame.eth_type = 0x0800
        test_frame.ip_version = 4
        test_frame.ip_ihl = 5
        test_frame.ip_dscp = 0
        test_frame.ip_ecn = 0
        test_frame.ip_length = None
        test_frame.ip_identification = 0
        test_frame.ip_flags = 2
        test_frame.ip_fragment_offset = 0
        test_frame.ip_ttl = 64
        test_frame.ip_protocol = 0x11
        test_frame.ip_header_checksum = None
        test_frame.ip_source_ip = 0xc0a80164
        test_frame.ip_dest_ip = 0xc0a80166
        test_frame.udp_source_port = 1234
        test_frame.udp_dest_port = 5678
        test_frame.payload = bytearray(range(32))
        test_frame.build()

        udp_source_queue.put(test_frame)

        yield clk.posedge
        yield clk.posedge

        yield wait_normal()

        yield clk.posedge
        yield clk.posedge

        rx_frame = None
        if not eth_sink_queue.empty():
            rx_frame = eth_sink_queue.get()

        check_frame = udp_ep.UDPFrame()
        check_frame.parse_eth(rx_frame)

        assert check_frame == test_frame

        assert eth_source_queue.empty()
        assert eth_sink_queue.empty()
        assert udp_source_queue.empty()
        assert udp_sink_queue.empty()

        yield delay(100)

        raise StopSimulation

    return dut, eth_source, eth_sink, ip_source, ip_sink, udp_source, udp_sink, clkgen, monitor, check
コード例 #2
0
def bench():

    # Inputs
    clk = Signal(bool(0))
    rst = Signal(bool(0))
    current_test = Signal(intbv(0)[8:])

    input_0_udp_hdr_valid = Signal(bool(0))
    input_0_eth_dest_mac = Signal(intbv(0)[48:])
    input_0_eth_src_mac = Signal(intbv(0)[48:])
    input_0_eth_type = Signal(intbv(0)[16:])
    input_0_ip_version = Signal(intbv(0)[4:])
    input_0_ip_ihl = Signal(intbv(0)[4:])
    input_0_ip_dscp = Signal(intbv(0)[6:])
    input_0_ip_ecn = Signal(intbv(0)[2:])
    input_0_ip_length = Signal(intbv(0)[16:])
    input_0_ip_identification = Signal(intbv(0)[16:])
    input_0_ip_flags = Signal(intbv(0)[3:])
    input_0_ip_fragment_offset = Signal(intbv(0)[13:])
    input_0_ip_ttl = Signal(intbv(0)[8:])
    input_0_ip_protocol = Signal(intbv(0)[8:])
    input_0_ip_header_checksum = Signal(intbv(0)[16:])
    input_0_ip_source_ip = Signal(intbv(0)[32:])
    input_0_ip_dest_ip = Signal(intbv(0)[32:])
    input_0_udp_source_port = Signal(intbv(0)[16:])
    input_0_udp_dest_port = Signal(intbv(0)[16:])
    input_0_udp_length = Signal(intbv(0)[16:])
    input_0_udp_checksum = Signal(intbv(0)[16:])
    input_0_udp_payload_tdata = Signal(intbv(0)[64:])
    input_0_udp_payload_tkeep = Signal(intbv(0)[8:])
    input_0_udp_payload_tvalid = Signal(bool(0))
    input_0_udp_payload_tlast = Signal(bool(0))
    input_0_udp_payload_tuser = Signal(bool(0))
    input_1_udp_hdr_valid = Signal(bool(0))
    input_1_eth_dest_mac = Signal(intbv(0)[48:])
    input_1_eth_src_mac = Signal(intbv(0)[48:])
    input_1_eth_type = Signal(intbv(0)[16:])
    input_1_ip_version = Signal(intbv(0)[4:])
    input_1_ip_ihl = Signal(intbv(0)[4:])
    input_1_ip_dscp = Signal(intbv(0)[6:])
    input_1_ip_ecn = Signal(intbv(0)[2:])
    input_1_ip_length = Signal(intbv(0)[16:])
    input_1_ip_identification = Signal(intbv(0)[16:])
    input_1_ip_flags = Signal(intbv(0)[3:])
    input_1_ip_fragment_offset = Signal(intbv(0)[13:])
    input_1_ip_ttl = Signal(intbv(0)[8:])
    input_1_ip_protocol = Signal(intbv(0)[8:])
    input_1_ip_header_checksum = Signal(intbv(0)[16:])
    input_1_ip_source_ip = Signal(intbv(0)[32:])
    input_1_ip_dest_ip = Signal(intbv(0)[32:])
    input_1_udp_source_port = Signal(intbv(0)[16:])
    input_1_udp_dest_port = Signal(intbv(0)[16:])
    input_1_udp_length = Signal(intbv(0)[16:])
    input_1_udp_checksum = Signal(intbv(0)[16:])
    input_1_udp_payload_tdata = Signal(intbv(0)[64:])
    input_1_udp_payload_tkeep = Signal(intbv(0)[8:])
    input_1_udp_payload_tvalid = Signal(bool(0))
    input_1_udp_payload_tlast = Signal(bool(0))
    input_1_udp_payload_tuser = Signal(bool(0))
    input_2_udp_hdr_valid = Signal(bool(0))
    input_2_eth_dest_mac = Signal(intbv(0)[48:])
    input_2_eth_src_mac = Signal(intbv(0)[48:])
    input_2_eth_type = Signal(intbv(0)[16:])
    input_2_ip_version = Signal(intbv(0)[4:])
    input_2_ip_ihl = Signal(intbv(0)[4:])
    input_2_ip_dscp = Signal(intbv(0)[6:])
    input_2_ip_ecn = Signal(intbv(0)[2:])
    input_2_ip_length = Signal(intbv(0)[16:])
    input_2_ip_identification = Signal(intbv(0)[16:])
    input_2_ip_flags = Signal(intbv(0)[3:])
    input_2_ip_fragment_offset = Signal(intbv(0)[13:])
    input_2_ip_ttl = Signal(intbv(0)[8:])
    input_2_ip_protocol = Signal(intbv(0)[8:])
    input_2_ip_header_checksum = Signal(intbv(0)[16:])
    input_2_ip_source_ip = Signal(intbv(0)[32:])
    input_2_ip_dest_ip = Signal(intbv(0)[32:])
    input_2_udp_source_port = Signal(intbv(0)[16:])
    input_2_udp_dest_port = Signal(intbv(0)[16:])
    input_2_udp_length = Signal(intbv(0)[16:])
    input_2_udp_checksum = Signal(intbv(0)[16:])
    input_2_udp_payload_tdata = Signal(intbv(0)[64:])
    input_2_udp_payload_tkeep = Signal(intbv(0)[8:])
    input_2_udp_payload_tvalid = Signal(bool(0))
    input_2_udp_payload_tlast = Signal(bool(0))
    input_2_udp_payload_tuser = Signal(bool(0))
    input_3_udp_hdr_valid = Signal(bool(0))
    input_3_eth_dest_mac = Signal(intbv(0)[48:])
    input_3_eth_src_mac = Signal(intbv(0)[48:])
    input_3_eth_type = Signal(intbv(0)[16:])
    input_3_ip_version = Signal(intbv(0)[4:])
    input_3_ip_ihl = Signal(intbv(0)[4:])
    input_3_ip_dscp = Signal(intbv(0)[6:])
    input_3_ip_ecn = Signal(intbv(0)[2:])
    input_3_ip_length = Signal(intbv(0)[16:])
    input_3_ip_identification = Signal(intbv(0)[16:])
    input_3_ip_flags = Signal(intbv(0)[3:])
    input_3_ip_fragment_offset = Signal(intbv(0)[13:])
    input_3_ip_ttl = Signal(intbv(0)[8:])
    input_3_ip_protocol = Signal(intbv(0)[8:])
    input_3_ip_header_checksum = Signal(intbv(0)[16:])
    input_3_ip_source_ip = Signal(intbv(0)[32:])
    input_3_ip_dest_ip = Signal(intbv(0)[32:])
    input_3_udp_source_port = Signal(intbv(0)[16:])
    input_3_udp_dest_port = Signal(intbv(0)[16:])
    input_3_udp_length = Signal(intbv(0)[16:])
    input_3_udp_checksum = Signal(intbv(0)[16:])
    input_3_udp_payload_tdata = Signal(intbv(0)[64:])
    input_3_udp_payload_tkeep = Signal(intbv(0)[8:])
    input_3_udp_payload_tvalid = Signal(bool(0))
    input_3_udp_payload_tlast = Signal(bool(0))
    input_3_udp_payload_tuser = Signal(bool(0))

    output_udp_payload_tready = Signal(bool(0))
    output_udp_hdr_ready = Signal(bool(0))

    enable = Signal(bool(0))
    select = Signal(intbv(0)[2:])

    # Outputs
    input_0_udp_hdr_ready = Signal(bool(0))
    input_0_udp_payload_tready = Signal(bool(0))
    input_1_udp_hdr_ready = Signal(bool(0))
    input_1_udp_payload_tready = Signal(bool(0))
    input_2_udp_hdr_ready = Signal(bool(0))
    input_2_udp_payload_tready = Signal(bool(0))
    input_3_udp_hdr_ready = Signal(bool(0))
    input_3_udp_payload_tready = Signal(bool(0))

    output_udp_hdr_valid = Signal(bool(0))
    output_eth_dest_mac = Signal(intbv(0)[48:])
    output_eth_src_mac = Signal(intbv(0)[48:])
    output_eth_type = Signal(intbv(0)[16:])
    output_ip_version = Signal(intbv(0)[4:])
    output_ip_ihl = Signal(intbv(0)[4:])
    output_ip_dscp = Signal(intbv(0)[6:])
    output_ip_ecn = Signal(intbv(0)[2:])
    output_ip_length = Signal(intbv(0)[16:])
    output_ip_identification = Signal(intbv(0)[16:])
    output_ip_flags = Signal(intbv(0)[3:])
    output_ip_fragment_offset = Signal(intbv(0)[13:])
    output_ip_ttl = Signal(intbv(0)[8:])
    output_ip_protocol = Signal(intbv(0)[8:])
    output_ip_header_checksum = Signal(intbv(0)[16:])
    output_ip_source_ip = Signal(intbv(0)[32:])
    output_ip_dest_ip = Signal(intbv(0)[32:])
    output_udp_source_port = Signal(intbv(0)[16:])
    output_udp_dest_port = Signal(intbv(0)[16:])
    output_udp_length = Signal(intbv(0)[16:])
    output_udp_checksum = Signal(intbv(0)[16:])
    output_udp_payload_tdata = Signal(intbv(0)[64:])
    output_udp_payload_tkeep = Signal(intbv(0)[8:])
    output_udp_payload_tvalid = Signal(bool(0))
    output_udp_payload_tlast = Signal(bool(0))
    output_udp_payload_tuser = Signal(bool(0))

    # sources and sinks
    source_0_pause = Signal(bool(0))
    source_1_pause = Signal(bool(0))
    source_2_pause = Signal(bool(0))
    source_3_pause = Signal(bool(0))
    sink_pause = Signal(bool(0))

    source_0 = udp_ep.UDPFrameSource()

    source_0_logic = source_0.create_logic(
        clk,
        rst,
        udp_hdr_ready=input_0_udp_hdr_ready,
        udp_hdr_valid=input_0_udp_hdr_valid,
        eth_dest_mac=input_0_eth_dest_mac,
        eth_src_mac=input_0_eth_src_mac,
        eth_type=input_0_eth_type,
        ip_version=input_0_ip_version,
        ip_ihl=input_0_ip_ihl,
        ip_dscp=input_0_ip_dscp,
        ip_ecn=input_0_ip_ecn,
        ip_length=input_0_ip_length,
        ip_identification=input_0_ip_identification,
        ip_flags=input_0_ip_flags,
        ip_fragment_offset=input_0_ip_fragment_offset,
        ip_ttl=input_0_ip_ttl,
        ip_protocol=input_0_ip_protocol,
        ip_header_checksum=input_0_ip_header_checksum,
        ip_source_ip=input_0_ip_source_ip,
        ip_dest_ip=input_0_ip_dest_ip,
        udp_source_port=input_0_udp_source_port,
        udp_dest_port=input_0_udp_dest_port,
        udp_length=input_0_udp_length,
        udp_checksum=input_0_udp_checksum,
        udp_payload_tdata=input_0_udp_payload_tdata,
        udp_payload_tkeep=input_0_udp_payload_tkeep,
        udp_payload_tvalid=input_0_udp_payload_tvalid,
        udp_payload_tready=input_0_udp_payload_tready,
        udp_payload_tlast=input_0_udp_payload_tlast,
        udp_payload_tuser=input_0_udp_payload_tuser,
        pause=source_0_pause,
        name='source_0')

    source_1 = udp_ep.UDPFrameSource()

    source_1_logic = source_1.create_logic(
        clk,
        rst,
        udp_hdr_ready=input_1_udp_hdr_ready,
        udp_hdr_valid=input_1_udp_hdr_valid,
        eth_dest_mac=input_1_eth_dest_mac,
        eth_src_mac=input_1_eth_src_mac,
        eth_type=input_1_eth_type,
        ip_version=input_1_ip_version,
        ip_ihl=input_1_ip_ihl,
        ip_dscp=input_1_ip_dscp,
        ip_ecn=input_1_ip_ecn,
        ip_length=input_1_ip_length,
        ip_identification=input_1_ip_identification,
        ip_flags=input_1_ip_flags,
        ip_fragment_offset=input_1_ip_fragment_offset,
        ip_ttl=input_1_ip_ttl,
        ip_protocol=input_1_ip_protocol,
        ip_header_checksum=input_1_ip_header_checksum,
        ip_source_ip=input_1_ip_source_ip,
        ip_dest_ip=input_1_ip_dest_ip,
        udp_source_port=input_1_udp_source_port,
        udp_dest_port=input_1_udp_dest_port,
        udp_length=input_1_udp_length,
        udp_checksum=input_1_udp_checksum,
        udp_payload_tdata=input_1_udp_payload_tdata,
        udp_payload_tkeep=input_1_udp_payload_tkeep,
        udp_payload_tvalid=input_1_udp_payload_tvalid,
        udp_payload_tready=input_1_udp_payload_tready,
        udp_payload_tlast=input_1_udp_payload_tlast,
        udp_payload_tuser=input_1_udp_payload_tuser,
        pause=source_1_pause,
        name='source_1')

    source_2 = udp_ep.UDPFrameSource()

    source_2_logic = source_2.create_logic(
        clk,
        rst,
        udp_hdr_ready=input_2_udp_hdr_ready,
        udp_hdr_valid=input_2_udp_hdr_valid,
        eth_dest_mac=input_2_eth_dest_mac,
        eth_src_mac=input_2_eth_src_mac,
        eth_type=input_2_eth_type,
        ip_version=input_2_ip_version,
        ip_ihl=input_2_ip_ihl,
        ip_dscp=input_2_ip_dscp,
        ip_ecn=input_2_ip_ecn,
        ip_length=input_2_ip_length,
        ip_identification=input_2_ip_identification,
        ip_flags=input_2_ip_flags,
        ip_fragment_offset=input_2_ip_fragment_offset,
        ip_ttl=input_2_ip_ttl,
        ip_protocol=input_2_ip_protocol,
        ip_header_checksum=input_2_ip_header_checksum,
        ip_source_ip=input_2_ip_source_ip,
        ip_dest_ip=input_2_ip_dest_ip,
        udp_source_port=input_2_udp_source_port,
        udp_dest_port=input_2_udp_dest_port,
        udp_length=input_2_udp_length,
        udp_checksum=input_2_udp_checksum,
        udp_payload_tdata=input_2_udp_payload_tdata,
        udp_payload_tkeep=input_2_udp_payload_tkeep,
        udp_payload_tvalid=input_2_udp_payload_tvalid,
        udp_payload_tready=input_2_udp_payload_tready,
        udp_payload_tlast=input_2_udp_payload_tlast,
        udp_payload_tuser=input_2_udp_payload_tuser,
        pause=source_2_pause,
        name='source_2')

    source_3 = udp_ep.UDPFrameSource()

    source_3_logic = source_3.create_logic(
        clk,
        rst,
        udp_hdr_ready=input_3_udp_hdr_ready,
        udp_hdr_valid=input_3_udp_hdr_valid,
        eth_dest_mac=input_3_eth_dest_mac,
        eth_src_mac=input_3_eth_src_mac,
        eth_type=input_3_eth_type,
        ip_version=input_3_ip_version,
        ip_ihl=input_3_ip_ihl,
        ip_dscp=input_3_ip_dscp,
        ip_ecn=input_3_ip_ecn,
        ip_length=input_3_ip_length,
        ip_identification=input_3_ip_identification,
        ip_flags=input_3_ip_flags,
        ip_fragment_offset=input_3_ip_fragment_offset,
        ip_ttl=input_3_ip_ttl,
        ip_protocol=input_3_ip_protocol,
        ip_header_checksum=input_3_ip_header_checksum,
        ip_source_ip=input_3_ip_source_ip,
        ip_dest_ip=input_3_ip_dest_ip,
        udp_source_port=input_3_udp_source_port,
        udp_dest_port=input_3_udp_dest_port,
        udp_length=input_3_udp_length,
        udp_checksum=input_3_udp_checksum,
        udp_payload_tdata=input_3_udp_payload_tdata,
        udp_payload_tkeep=input_3_udp_payload_tkeep,
        udp_payload_tvalid=input_3_udp_payload_tvalid,
        udp_payload_tready=input_3_udp_payload_tready,
        udp_payload_tlast=input_3_udp_payload_tlast,
        udp_payload_tuser=input_3_udp_payload_tuser,
        pause=source_3_pause,
        name='source_3')

    sink = udp_ep.UDPFrameSink()

    sink_logic = sink.create_logic(
        clk,
        rst,
        udp_hdr_ready=output_udp_hdr_ready,
        udp_hdr_valid=output_udp_hdr_valid,
        eth_dest_mac=output_eth_dest_mac,
        eth_src_mac=output_eth_src_mac,
        eth_type=output_eth_type,
        ip_version=output_ip_version,
        ip_ihl=output_ip_ihl,
        ip_dscp=output_ip_dscp,
        ip_ecn=output_ip_ecn,
        ip_length=output_ip_length,
        ip_identification=output_ip_identification,
        ip_flags=output_ip_flags,
        ip_fragment_offset=output_ip_fragment_offset,
        ip_ttl=output_ip_ttl,
        ip_protocol=output_ip_protocol,
        ip_header_checksum=output_ip_header_checksum,
        ip_source_ip=output_ip_source_ip,
        ip_dest_ip=output_ip_dest_ip,
        udp_source_port=output_udp_source_port,
        udp_dest_port=output_udp_dest_port,
        udp_length=output_udp_length,
        udp_checksum=output_udp_checksum,
        udp_payload_tdata=output_udp_payload_tdata,
        udp_payload_tkeep=output_udp_payload_tkeep,
        udp_payload_tvalid=output_udp_payload_tvalid,
        udp_payload_tready=output_udp_payload_tready,
        udp_payload_tlast=output_udp_payload_tlast,
        udp_payload_tuser=output_udp_payload_tuser,
        pause=sink_pause,
        name='sink')

    # DUT
    if os.system(build_cmd):
        raise Exception("Error running build command")

    dut = Cosimulation("vvp -m myhdl %s.vvp -lxt2" % testbench,
                       clk=clk,
                       rst=rst,
                       current_test=current_test,
                       input_0_udp_hdr_valid=input_0_udp_hdr_valid,
                       input_0_udp_hdr_ready=input_0_udp_hdr_ready,
                       input_0_eth_dest_mac=input_0_eth_dest_mac,
                       input_0_eth_src_mac=input_0_eth_src_mac,
                       input_0_eth_type=input_0_eth_type,
                       input_0_ip_version=input_0_ip_version,
                       input_0_ip_ihl=input_0_ip_ihl,
                       input_0_ip_dscp=input_0_ip_dscp,
                       input_0_ip_ecn=input_0_ip_ecn,
                       input_0_ip_length=input_0_ip_length,
                       input_0_ip_identification=input_0_ip_identification,
                       input_0_ip_flags=input_0_ip_flags,
                       input_0_ip_fragment_offset=input_0_ip_fragment_offset,
                       input_0_ip_ttl=input_0_ip_ttl,
                       input_0_ip_protocol=input_0_ip_protocol,
                       input_0_ip_header_checksum=input_0_ip_header_checksum,
                       input_0_ip_source_ip=input_0_ip_source_ip,
                       input_0_ip_dest_ip=input_0_ip_dest_ip,
                       input_0_udp_source_port=input_0_udp_source_port,
                       input_0_udp_dest_port=input_0_udp_dest_port,
                       input_0_udp_length=input_0_udp_length,
                       input_0_udp_checksum=input_0_udp_checksum,
                       input_0_udp_payload_tdata=input_0_udp_payload_tdata,
                       input_0_udp_payload_tkeep=input_0_udp_payload_tkeep,
                       input_0_udp_payload_tvalid=input_0_udp_payload_tvalid,
                       input_0_udp_payload_tready=input_0_udp_payload_tready,
                       input_0_udp_payload_tlast=input_0_udp_payload_tlast,
                       input_0_udp_payload_tuser=input_0_udp_payload_tuser,
                       input_1_udp_hdr_valid=input_1_udp_hdr_valid,
                       input_1_udp_hdr_ready=input_1_udp_hdr_ready,
                       input_1_eth_dest_mac=input_1_eth_dest_mac,
                       input_1_eth_src_mac=input_1_eth_src_mac,
                       input_1_eth_type=input_1_eth_type,
                       input_1_ip_version=input_1_ip_version,
                       input_1_ip_ihl=input_1_ip_ihl,
                       input_1_ip_dscp=input_1_ip_dscp,
                       input_1_ip_ecn=input_1_ip_ecn,
                       input_1_ip_length=input_1_ip_length,
                       input_1_ip_identification=input_1_ip_identification,
                       input_1_ip_flags=input_1_ip_flags,
                       input_1_ip_fragment_offset=input_1_ip_fragment_offset,
                       input_1_ip_ttl=input_1_ip_ttl,
                       input_1_ip_protocol=input_1_ip_protocol,
                       input_1_ip_header_checksum=input_1_ip_header_checksum,
                       input_1_ip_source_ip=input_1_ip_source_ip,
                       input_1_ip_dest_ip=input_1_ip_dest_ip,
                       input_1_udp_source_port=input_1_udp_source_port,
                       input_1_udp_dest_port=input_1_udp_dest_port,
                       input_1_udp_length=input_1_udp_length,
                       input_1_udp_checksum=input_1_udp_checksum,
                       input_1_udp_payload_tdata=input_1_udp_payload_tdata,
                       input_1_udp_payload_tkeep=input_1_udp_payload_tkeep,
                       input_1_udp_payload_tvalid=input_1_udp_payload_tvalid,
                       input_1_udp_payload_tready=input_1_udp_payload_tready,
                       input_1_udp_payload_tlast=input_1_udp_payload_tlast,
                       input_1_udp_payload_tuser=input_1_udp_payload_tuser,
                       input_2_udp_hdr_valid=input_2_udp_hdr_valid,
                       input_2_udp_hdr_ready=input_2_udp_hdr_ready,
                       input_2_eth_dest_mac=input_2_eth_dest_mac,
                       input_2_eth_src_mac=input_2_eth_src_mac,
                       input_2_eth_type=input_2_eth_type,
                       input_2_ip_version=input_2_ip_version,
                       input_2_ip_ihl=input_2_ip_ihl,
                       input_2_ip_dscp=input_2_ip_dscp,
                       input_2_ip_ecn=input_2_ip_ecn,
                       input_2_ip_length=input_2_ip_length,
                       input_2_ip_identification=input_2_ip_identification,
                       input_2_ip_flags=input_2_ip_flags,
                       input_2_ip_fragment_offset=input_2_ip_fragment_offset,
                       input_2_ip_ttl=input_2_ip_ttl,
                       input_2_ip_protocol=input_2_ip_protocol,
                       input_2_ip_header_checksum=input_2_ip_header_checksum,
                       input_2_ip_source_ip=input_2_ip_source_ip,
                       input_2_ip_dest_ip=input_2_ip_dest_ip,
                       input_2_udp_source_port=input_2_udp_source_port,
                       input_2_udp_dest_port=input_2_udp_dest_port,
                       input_2_udp_length=input_2_udp_length,
                       input_2_udp_checksum=input_2_udp_checksum,
                       input_2_udp_payload_tdata=input_2_udp_payload_tdata,
                       input_2_udp_payload_tkeep=input_2_udp_payload_tkeep,
                       input_2_udp_payload_tvalid=input_2_udp_payload_tvalid,
                       input_2_udp_payload_tready=input_2_udp_payload_tready,
                       input_2_udp_payload_tlast=input_2_udp_payload_tlast,
                       input_2_udp_payload_tuser=input_2_udp_payload_tuser,
                       input_3_udp_hdr_valid=input_3_udp_hdr_valid,
                       input_3_udp_hdr_ready=input_3_udp_hdr_ready,
                       input_3_eth_dest_mac=input_3_eth_dest_mac,
                       input_3_eth_src_mac=input_3_eth_src_mac,
                       input_3_eth_type=input_3_eth_type,
                       input_3_ip_version=input_3_ip_version,
                       input_3_ip_ihl=input_3_ip_ihl,
                       input_3_ip_dscp=input_3_ip_dscp,
                       input_3_ip_ecn=input_3_ip_ecn,
                       input_3_ip_length=input_3_ip_length,
                       input_3_ip_identification=input_3_ip_identification,
                       input_3_ip_flags=input_3_ip_flags,
                       input_3_ip_fragment_offset=input_3_ip_fragment_offset,
                       input_3_ip_ttl=input_3_ip_ttl,
                       input_3_ip_protocol=input_3_ip_protocol,
                       input_3_ip_header_checksum=input_3_ip_header_checksum,
                       input_3_ip_source_ip=input_3_ip_source_ip,
                       input_3_ip_dest_ip=input_3_ip_dest_ip,
                       input_3_udp_source_port=input_3_udp_source_port,
                       input_3_udp_dest_port=input_3_udp_dest_port,
                       input_3_udp_length=input_3_udp_length,
                       input_3_udp_checksum=input_3_udp_checksum,
                       input_3_udp_payload_tdata=input_3_udp_payload_tdata,
                       input_3_udp_payload_tkeep=input_3_udp_payload_tkeep,
                       input_3_udp_payload_tvalid=input_3_udp_payload_tvalid,
                       input_3_udp_payload_tready=input_3_udp_payload_tready,
                       input_3_udp_payload_tlast=input_3_udp_payload_tlast,
                       input_3_udp_payload_tuser=input_3_udp_payload_tuser,
                       output_udp_hdr_valid=output_udp_hdr_valid,
                       output_udp_hdr_ready=output_udp_hdr_ready,
                       output_eth_dest_mac=output_eth_dest_mac,
                       output_eth_src_mac=output_eth_src_mac,
                       output_eth_type=output_eth_type,
                       output_ip_version=output_ip_version,
                       output_ip_ihl=output_ip_ihl,
                       output_ip_dscp=output_ip_dscp,
                       output_ip_ecn=output_ip_ecn,
                       output_ip_length=output_ip_length,
                       output_ip_identification=output_ip_identification,
                       output_ip_flags=output_ip_flags,
                       output_ip_fragment_offset=output_ip_fragment_offset,
                       output_ip_ttl=output_ip_ttl,
                       output_ip_protocol=output_ip_protocol,
                       output_ip_header_checksum=output_ip_header_checksum,
                       output_ip_source_ip=output_ip_source_ip,
                       output_ip_dest_ip=output_ip_dest_ip,
                       output_udp_source_port=output_udp_source_port,
                       output_udp_dest_port=output_udp_dest_port,
                       output_udp_length=output_udp_length,
                       output_udp_checksum=output_udp_checksum,
                       output_udp_payload_tdata=output_udp_payload_tdata,
                       output_udp_payload_tkeep=output_udp_payload_tkeep,
                       output_udp_payload_tvalid=output_udp_payload_tvalid,
                       output_udp_payload_tready=output_udp_payload_tready,
                       output_udp_payload_tlast=output_udp_payload_tlast,
                       output_udp_payload_tuser=output_udp_payload_tuser,
                       enable=enable,
                       select=select)

    @always(delay(4))
    def clkgen():
        clk.next = not clk

    @instance
    def check():
        yield delay(100)
        yield clk.posedge
        rst.next = 1
        yield clk.posedge
        rst.next = 0
        yield clk.posedge
        yield delay(100)
        yield clk.posedge

        yield clk.posedge
        enable.next = True

        yield clk.posedge
        print("test 1: select port 0")
        current_test.next = 1

        select.next = 0

        test_frame = udp_ep.UDPFrame()
        test_frame.eth_dest_mac = 0xDAD1D2D3D4D5
        test_frame.eth_src_mac = 0x5A5152535455
        test_frame.eth_type = 0x8000
        test_frame.ip_version = 4
        test_frame.ip_ihl = 5
        test_frame.ip_dscp = 0
        test_frame.ip_ecn = 0
        test_frame.ip_length = None
        test_frame.ip_identification = 0
        test_frame.ip_flags = 2
        test_frame.ip_fragment_offset = 0
        test_frame.ip_ttl = 64
        test_frame.ip_protocol = 0x11
        test_frame.ip_header_checksum = None
        test_frame.ip_source_ip = 0xc0a80165
        test_frame.ip_dest_ip = 0xc0a80164
        test_frame.udp_source_port = 1
        test_frame.udp_dest_port = 2
        test_frame.udp_length = None
        test_frame.udp_checksum = None
        test_frame.payload = bytearray(range(32))
        test_frame.build()

        source_0.send(test_frame)
        yield clk.posedge
        yield clk.posedge

        while input_0_udp_payload_tvalid or input_1_udp_payload_tvalid or input_2_udp_payload_tvalid or input_3_udp_payload_tvalid:
            yield clk.posedge
        yield clk.posedge
        yield clk.posedge

        rx_frame = sink.recv()

        assert rx_frame == test_frame

        yield delay(100)

        yield clk.posedge
        print("test 2: select port 1")
        current_test.next = 2

        select.next = 1

        test_frame = udp_ep.UDPFrame()
        test_frame.eth_dest_mac = 0xDAD1D2D3D4D5
        test_frame.eth_src_mac = 0x5A5152535455
        test_frame.eth_type = 0x8000
        test_frame.ip_version = 4
        test_frame.ip_ihl = 5
        test_frame.ip_dscp = 0
        test_frame.ip_ecn = 0
        test_frame.ip_length = None
        test_frame.ip_identification = 0
        test_frame.ip_flags = 2
        test_frame.ip_fragment_offset = 0
        test_frame.ip_ttl = 64
        test_frame.ip_protocol = 0x11
        test_frame.ip_header_checksum = None
        test_frame.ip_source_ip = 0xc0a80165
        test_frame.ip_dest_ip = 0xc0a80164
        test_frame.udp_source_port = 1
        test_frame.udp_dest_port = 2
        test_frame.udp_length = None
        test_frame.udp_checksum = None
        test_frame.payload = bytearray(range(32))
        test_frame.build()

        source_1.send(test_frame)
        yield clk.posedge
        yield clk.posedge

        while input_0_udp_payload_tvalid or input_1_udp_payload_tvalid or input_2_udp_payload_tvalid or input_3_udp_payload_tvalid:
            yield clk.posedge
        yield clk.posedge
        yield clk.posedge

        rx_frame = sink.recv()

        assert rx_frame == test_frame

        yield delay(100)

        yield clk.posedge
        print("test 3: back-to-back packets, same port")
        current_test.next = 3

        select.next = 0

        test_frame1 = udp_ep.UDPFrame()
        test_frame1.eth_dest_mac = 0xDAD1D2D3D4D5
        test_frame1.eth_src_mac = 0x5A5152535455
        test_frame1.eth_type = 0x8000
        test_frame1.ip_version = 4
        test_frame1.ip_ihl = 5
        test_frame1.ip_dscp = 0
        test_frame1.ip_ecn = 0
        test_frame1.ip_length = None
        test_frame1.ip_identification = 0
        test_frame1.ip_flags = 2
        test_frame1.ip_fragment_offset = 0
        test_frame1.ip_ttl = 64
        test_frame1.ip_protocol = 0x11
        test_frame1.ip_header_checksum = None
        test_frame1.ip_source_ip = 0xc0a80165
        test_frame1.ip_dest_ip = 0xc0a80164
        test_frame1.udp_source_port = 1
        test_frame1.udp_dest_port = 2
        test_frame1.udp_length = None
        test_frame1.udp_checksum = None
        test_frame1.payload = bytearray(range(32))
        test_frame1.build()
        test_frame2 = udp_ep.UDPFrame()
        test_frame2.eth_dest_mac = 0xDAD1D2D3D4D5
        test_frame2.eth_src_mac = 0x5A5152535455
        test_frame2.eth_type = 0x8000
        test_frame2.ip_version = 4
        test_frame2.ip_ihl = 5
        test_frame2.ip_dscp = 0
        test_frame2.ip_ecn = 0
        test_frame2.ip_length = None
        test_frame2.ip_identification = 0
        test_frame2.ip_flags = 2
        test_frame2.ip_fragment_offset = 0
        test_frame2.ip_ttl = 64
        test_frame2.ip_protocol = 0x11
        test_frame2.ip_header_checksum = None
        test_frame2.ip_source_ip = 0xc0a80165
        test_frame2.ip_dest_ip = 0xc0a80164
        test_frame2.udp_source_port = 1
        test_frame2.udp_dest_port = 2
        test_frame2.udp_length = None
        test_frame2.udp_checksum = None
        test_frame2.payload = bytearray(range(32))
        test_frame2.build()

        source_0.send(test_frame1)
        source_0.send(test_frame2)
        yield clk.posedge
        yield clk.posedge

        while input_0_udp_payload_tvalid or input_1_udp_payload_tvalid or input_2_udp_payload_tvalid or input_3_udp_payload_tvalid:
            yield clk.posedge
        yield clk.posedge
        yield clk.posedge

        rx_frame = sink.recv()

        assert rx_frame == test_frame1

        rx_frame = sink.recv()

        assert rx_frame == test_frame2

        yield delay(100)

        yield clk.posedge
        print("test 4: back-to-back packets, different ports")
        current_test.next = 4

        select.next = 1

        test_frame1 = udp_ep.UDPFrame()
        test_frame1.eth_dest_mac = 0xDAD1D2D3D4D5
        test_frame1.eth_src_mac = 0x5A5152535455
        test_frame1.eth_type = 0x8000
        test_frame1.ip_version = 4
        test_frame1.ip_ihl = 5
        test_frame1.ip_dscp = 0
        test_frame1.ip_ecn = 0
        test_frame1.ip_length = None
        test_frame1.ip_identification = 0
        test_frame1.ip_flags = 2
        test_frame1.ip_fragment_offset = 0
        test_frame1.ip_ttl = 64
        test_frame1.ip_protocol = 0x11
        test_frame1.ip_header_checksum = None
        test_frame1.ip_source_ip = 0xc0a80165
        test_frame1.ip_dest_ip = 0xc0a80164
        test_frame1.udp_source_port = 1
        test_frame1.udp_dest_port = 2
        test_frame1.udp_length = None
        test_frame1.udp_checksum = None
        test_frame1.payload = bytearray(range(32))
        test_frame1.build()
        test_frame2 = udp_ep.UDPFrame()
        test_frame2.eth_dest_mac = 0xDAD1D2D3D4D5
        test_frame2.eth_src_mac = 0x5A5152535455
        test_frame2.eth_type = 0x8000
        test_frame2.ip_version = 4
        test_frame2.ip_ihl = 5
        test_frame2.ip_dscp = 0
        test_frame2.ip_ecn = 0
        test_frame2.ip_length = None
        test_frame2.ip_identification = 0
        test_frame2.ip_flags = 2
        test_frame2.ip_fragment_offset = 0
        test_frame2.ip_ttl = 64
        test_frame2.ip_protocol = 0x11
        test_frame2.ip_header_checksum = None
        test_frame2.ip_source_ip = 0xc0a80165
        test_frame2.ip_dest_ip = 0xc0a80164
        test_frame2.udp_source_port = 1
        test_frame2.udp_dest_port = 2
        test_frame2.udp_length = None
        test_frame2.udp_checksum = None
        test_frame2.payload = bytearray(range(32))
        test_frame2.build()

        source_1.send(test_frame1)
        source_2.send(test_frame2)
        yield clk.posedge
        yield clk.posedge

        while input_0_udp_payload_tvalid or input_1_udp_payload_tvalid or input_2_udp_payload_tvalid or input_3_udp_payload_tvalid:
            yield clk.posedge
            select.next = 2
        yield clk.posedge
        yield clk.posedge

        rx_frame = sink.recv()

        assert rx_frame == test_frame1

        rx_frame = sink.recv()

        assert rx_frame == test_frame2

        yield delay(100)

        yield clk.posedge
        print("test 5: alterate pause source")
        current_test.next = 5

        select.next = 1

        test_frame1 = udp_ep.UDPFrame()
        test_frame1.eth_dest_mac = 0xDAD1D2D3D4D5
        test_frame1.eth_src_mac = 0x5A5152535455
        test_frame1.eth_type = 0x8000
        test_frame1.ip_version = 4
        test_frame1.ip_ihl = 5
        test_frame1.ip_dscp = 0
        test_frame1.ip_ecn = 0
        test_frame1.ip_length = None
        test_frame1.ip_identification = 0
        test_frame1.ip_flags = 2
        test_frame1.ip_fragment_offset = 0
        test_frame1.ip_ttl = 64
        test_frame1.ip_protocol = 0x11
        test_frame1.ip_header_checksum = None
        test_frame1.ip_source_ip = 0xc0a80165
        test_frame1.ip_dest_ip = 0xc0a80164
        test_frame1.udp_source_port = 1
        test_frame1.udp_dest_port = 2
        test_frame1.udp_length = None
        test_frame1.udp_checksum = None
        test_frame1.payload = bytearray(range(32))
        test_frame1.build()
        test_frame2 = udp_ep.UDPFrame()
        test_frame2.eth_dest_mac = 0xDAD1D2D3D4D5
        test_frame2.eth_src_mac = 0x5A5152535455
        test_frame2.eth_type = 0x8000
        test_frame2.ip_version = 4
        test_frame2.ip_ihl = 5
        test_frame2.ip_dscp = 0
        test_frame2.ip_ecn = 0
        test_frame2.ip_length = None
        test_frame2.ip_identification = 0
        test_frame2.ip_flags = 2
        test_frame2.ip_fragment_offset = 0
        test_frame2.ip_ttl = 64
        test_frame2.ip_protocol = 0x11
        test_frame2.ip_header_checksum = None
        test_frame2.ip_source_ip = 0xc0a80165
        test_frame2.ip_dest_ip = 0xc0a80164
        test_frame2.udp_source_port = 1
        test_frame2.udp_dest_port = 2
        test_frame2.udp_length = None
        test_frame2.udp_checksum = None
        test_frame2.payload = bytearray(range(32))
        test_frame2.build()

        source_1.send(test_frame1)
        source_2.send(test_frame2)
        yield clk.posedge
        yield clk.posedge

        while input_0_udp_payload_tvalid or input_1_udp_payload_tvalid or input_2_udp_payload_tvalid or input_3_udp_payload_tvalid:
            source_0_pause.next = True
            source_1_pause.next = True
            source_2_pause.next = True
            source_3_pause.next = True
            yield clk.posedge
            yield clk.posedge
            yield clk.posedge
            source_0_pause.next = False
            source_1_pause.next = False
            source_2_pause.next = False
            source_3_pause.next = False
            yield clk.posedge
            select.next = 2
        yield clk.posedge
        yield clk.posedge

        rx_frame = sink.recv()

        assert rx_frame == test_frame1

        rx_frame = sink.recv()

        assert rx_frame == test_frame2

        yield delay(100)

        yield clk.posedge
        print("test 6: alterate pause sink")
        current_test.next = 6

        select.next = 1

        test_frame1 = udp_ep.UDPFrame()
        test_frame1.eth_dest_mac = 0xDAD1D2D3D4D5
        test_frame1.eth_src_mac = 0x5A5152535455
        test_frame1.eth_type = 0x8000
        test_frame1.ip_version = 4
        test_frame1.ip_ihl = 5
        test_frame1.ip_dscp = 0
        test_frame1.ip_ecn = 0
        test_frame1.ip_length = None
        test_frame1.ip_identification = 0
        test_frame1.ip_flags = 2
        test_frame1.ip_fragment_offset = 0
        test_frame1.ip_ttl = 64
        test_frame1.ip_protocol = 0x11
        test_frame1.ip_header_checksum = None
        test_frame1.ip_source_ip = 0xc0a80165
        test_frame1.ip_dest_ip = 0xc0a80164
        test_frame1.udp_source_port = 1
        test_frame1.udp_dest_port = 2
        test_frame1.udp_length = None
        test_frame1.udp_checksum = None
        test_frame1.payload = bytearray(range(32))
        test_frame1.build()
        test_frame2 = udp_ep.UDPFrame()
        test_frame2.eth_dest_mac = 0xDAD1D2D3D4D5
        test_frame2.eth_src_mac = 0x5A5152535455
        test_frame2.eth_type = 0x8000
        test_frame2.ip_version = 4
        test_frame2.ip_ihl = 5
        test_frame2.ip_dscp = 0
        test_frame2.ip_ecn = 0
        test_frame2.ip_length = None
        test_frame2.ip_identification = 0
        test_frame2.ip_flags = 2
        test_frame2.ip_fragment_offset = 0
        test_frame2.ip_ttl = 64
        test_frame2.ip_protocol = 0x11
        test_frame2.ip_header_checksum = None
        test_frame2.ip_source_ip = 0xc0a80165
        test_frame2.ip_dest_ip = 0xc0a80164
        test_frame2.udp_source_port = 1
        test_frame2.udp_dest_port = 2
        test_frame2.udp_length = None
        test_frame2.udp_checksum = None
        test_frame2.payload = bytearray(range(32))
        test_frame2.build()

        source_1.send(test_frame1)
        source_2.send(test_frame2)
        yield clk.posedge
        yield clk.posedge

        while input_0_udp_payload_tvalid or input_1_udp_payload_tvalid or input_2_udp_payload_tvalid or input_3_udp_payload_tvalid:
            sink_pause.next = True
            yield clk.posedge
            yield clk.posedge
            yield clk.posedge
            sink_pause.next = False
            yield clk.posedge
            select.next = 2
        yield clk.posedge
        yield clk.posedge
        yield clk.posedge

        rx_frame = sink.recv()

        assert rx_frame == test_frame1

        rx_frame = sink.recv()

        assert rx_frame == test_frame2

        yield delay(100)

        raise StopSimulation

    return dut, source_0_logic, source_1_logic, source_2_logic, source_3_logic, sink_logic, clkgen, check
コード例 #3
0
def bench():

    # Inputs
    clk = Signal(bool(0))
    rst = Signal(bool(0))
    current_test = Signal(intbv(0)[8:])

    input_ip_hdr_valid = Signal(bool(0))
    input_ip_eth_dest_mac = Signal(intbv(0)[48:])
    input_ip_eth_src_mac = Signal(intbv(0)[48:])
    input_ip_eth_type = Signal(intbv(0)[16:])
    input_ip_version = Signal(intbv(0)[4:])
    input_ip_ihl = Signal(intbv(0)[4:])
    input_ip_dscp = Signal(intbv(0)[6:])
    input_ip_ecn = Signal(intbv(0)[2:])
    input_ip_length = Signal(intbv(0)[16:])
    input_ip_identification = Signal(intbv(0)[16:])
    input_ip_flags = Signal(intbv(0)[3:])
    input_ip_fragment_offset = Signal(intbv(0)[13:])
    input_ip_ttl = Signal(intbv(0)[8:])
    input_ip_protocol = Signal(intbv(0)[8:])
    input_ip_header_checksum = Signal(intbv(0)[16:])
    input_ip_source_ip = Signal(intbv(0)[32:])
    input_ip_dest_ip = Signal(intbv(0)[32:])
    input_ip_payload_tdata = Signal(intbv(0)[8:])
    input_ip_payload_tvalid = Signal(bool(0))
    input_ip_payload_tlast = Signal(bool(0))
    input_ip_payload_tuser = Signal(bool(0))
    input_udp_hdr_valid = Signal(bool(0))
    input_udp_eth_dest_mac = Signal(intbv(0)[48:])
    input_udp_eth_src_mac = Signal(intbv(0)[48:])
    input_udp_eth_type = Signal(intbv(0)[16:])
    input_udp_ip_version = Signal(intbv(0)[4:])
    input_udp_ip_ihl = Signal(intbv(0)[4:])
    input_udp_ip_dscp = Signal(intbv(0)[6:])
    input_udp_ip_ecn = Signal(intbv(0)[2:])
    input_udp_ip_identification = Signal(intbv(0)[16:])
    input_udp_ip_flags = Signal(intbv(0)[3:])
    input_udp_ip_fragment_offset = Signal(intbv(0)[13:])
    input_udp_ip_ttl = Signal(intbv(0)[8:])
    input_udp_ip_header_checksum = Signal(intbv(0)[16:])
    input_udp_ip_source_ip = Signal(intbv(0)[32:])
    input_udp_ip_dest_ip = Signal(intbv(0)[32:])
    input_udp_source_port = Signal(intbv(0)[16:])
    input_udp_dest_port = Signal(intbv(0)[16:])
    input_udp_length = Signal(intbv(0)[16:])
    input_udp_checksum = Signal(intbv(0)[16:])
    input_udp_payload_tdata = Signal(intbv(0)[8:])
    input_udp_payload_tvalid = Signal(bool(0))
    input_udp_payload_tlast = Signal(bool(0))
    input_udp_payload_tuser = Signal(bool(0))
    output_ip_payload_tready = Signal(bool(0))
    output_ip_hdr_ready = Signal(bool(0))
    output_udp_hdr_ready = Signal(bool(0))
    output_udp_payload_tready = Signal(bool(0))

    # Outputs
    input_ip_hdr_ready = Signal(bool(0))
    input_ip_payload_tready = Signal(bool(0))
    input_udp_hdr_ready = Signal(bool(0))
    input_udp_payload_tready = Signal(bool(0))
    output_ip_hdr_valid = Signal(bool(0))
    output_ip_eth_dest_mac = Signal(intbv(0)[48:])
    output_ip_eth_src_mac = Signal(intbv(0)[48:])
    output_ip_eth_type = Signal(intbv(0)[16:])
    output_ip_version = Signal(intbv(0)[4:])
    output_ip_ihl = Signal(intbv(0)[4:])
    output_ip_dscp = Signal(intbv(0)[6:])
    output_ip_ecn = Signal(intbv(0)[2:])
    output_ip_length = Signal(intbv(0)[16:])
    output_ip_identification = Signal(intbv(0)[16:])
    output_ip_flags = Signal(intbv(0)[3:])
    output_ip_fragment_offset = Signal(intbv(0)[13:])
    output_ip_ttl = Signal(intbv(0)[8:])
    output_ip_protocol = Signal(intbv(0)[8:])
    output_ip_header_checksum = Signal(intbv(0)[16:])
    output_ip_source_ip = Signal(intbv(0)[32:])
    output_ip_dest_ip = Signal(intbv(0)[32:])
    output_ip_payload_tdata = Signal(intbv(0)[8:])
    output_ip_payload_tvalid = Signal(bool(0))
    output_ip_payload_tlast = Signal(bool(0))
    output_ip_payload_tuser = Signal(bool(0))
    output_udp_hdr_valid = Signal(bool(0))
    output_udp_eth_dest_mac = Signal(intbv(0)[48:])
    output_udp_eth_src_mac = Signal(intbv(0)[48:])
    output_udp_eth_type = Signal(intbv(0)[16:])
    output_udp_ip_version = Signal(intbv(0)[4:])
    output_udp_ip_ihl = Signal(intbv(0)[4:])
    output_udp_ip_dscp = Signal(intbv(0)[6:])
    output_udp_ip_ecn = Signal(intbv(0)[2:])
    output_udp_ip_length = Signal(intbv(0)[16:])
    output_udp_ip_identification = Signal(intbv(0)[16:])
    output_udp_ip_flags = Signal(intbv(0)[3:])
    output_udp_ip_fragment_offset = Signal(intbv(0)[13:])
    output_udp_ip_ttl = Signal(intbv(0)[8:])
    output_udp_ip_protocol = Signal(intbv(0)[8:])
    output_udp_ip_header_checksum = Signal(intbv(0)[16:])
    output_udp_ip_source_ip = Signal(intbv(0)[32:])
    output_udp_ip_dest_ip = Signal(intbv(0)[32:])
    output_udp_source_port = Signal(intbv(0)[16:])
    output_udp_dest_port = Signal(intbv(0)[16:])
    output_udp_length = Signal(intbv(0)[16:])
    output_udp_checksum = Signal(intbv(0)[16:])
    output_udp_payload_tdata = Signal(intbv(0)[8:])
    output_udp_payload_tvalid = Signal(bool(0))
    output_udp_payload_tlast = Signal(bool(0))
    output_udp_payload_tuser = Signal(bool(0))
    rx_busy = Signal(bool(0))
    tx_busy = Signal(bool(0))
    rx_error_header_early_termination = Signal(bool(0))
    rx_error_payload_early_termination = Signal(bool(0))
    tx_error_payload_early_termination = Signal(bool(0))

    # sources and sinks
    ip_source_pause = Signal(bool(0))
    ip_sink_pause = Signal(bool(0))
    udp_source_pause = Signal(bool(0))
    udp_sink_pause = Signal(bool(0))

    ip_source = ip_ep.IPFrameSource()

    ip_source_logic = ip_source.create_logic(
        clk,
        rst,
        ip_hdr_ready=input_ip_hdr_ready,
        ip_hdr_valid=input_ip_hdr_valid,
        eth_dest_mac=input_ip_eth_dest_mac,
        eth_src_mac=input_ip_eth_src_mac,
        eth_type=input_ip_eth_type,
        ip_version=input_ip_version,
        ip_ihl=input_ip_ihl,
        ip_dscp=input_ip_dscp,
        ip_ecn=input_ip_ecn,
        ip_length=input_ip_length,
        ip_identification=input_ip_identification,
        ip_flags=input_ip_flags,
        ip_fragment_offset=input_ip_fragment_offset,
        ip_ttl=input_ip_ttl,
        ip_protocol=input_ip_protocol,
        ip_header_checksum=input_ip_header_checksum,
        ip_source_ip=input_ip_source_ip,
        ip_dest_ip=input_ip_dest_ip,
        ip_payload_tdata=input_ip_payload_tdata,
        ip_payload_tvalid=input_ip_payload_tvalid,
        ip_payload_tready=input_ip_payload_tready,
        ip_payload_tlast=input_ip_payload_tlast,
        ip_payload_tuser=input_ip_payload_tuser,
        pause=ip_source_pause,
        name='ip_source')

    ip_sink = ip_ep.IPFrameSink()

    ip_sink_logic = ip_sink.create_logic(
        clk,
        rst,
        ip_hdr_ready=output_ip_hdr_ready,
        ip_hdr_valid=output_ip_hdr_valid,
        eth_dest_mac=output_ip_eth_dest_mac,
        eth_src_mac=output_ip_eth_src_mac,
        eth_type=output_ip_eth_type,
        ip_version=output_ip_version,
        ip_ihl=output_ip_ihl,
        ip_dscp=output_ip_dscp,
        ip_ecn=output_ip_ecn,
        ip_length=output_ip_length,
        ip_identification=output_ip_identification,
        ip_flags=output_ip_flags,
        ip_fragment_offset=output_ip_fragment_offset,
        ip_ttl=output_ip_ttl,
        ip_protocol=output_ip_protocol,
        ip_header_checksum=output_ip_header_checksum,
        ip_source_ip=output_ip_source_ip,
        ip_dest_ip=output_ip_dest_ip,
        ip_payload_tdata=output_ip_payload_tdata,
        ip_payload_tvalid=output_ip_payload_tvalid,
        ip_payload_tready=output_ip_payload_tready,
        ip_payload_tlast=output_ip_payload_tlast,
        ip_payload_tuser=output_ip_payload_tuser,
        pause=ip_sink_pause,
        name='ip_sink')

    udp_source = udp_ep.UDPFrameSource()

    udp_source_logic = udp_source.create_logic(
        clk,
        rst,
        udp_hdr_ready=input_udp_hdr_ready,
        udp_hdr_valid=input_udp_hdr_valid,
        eth_dest_mac=input_udp_eth_dest_mac,
        eth_src_mac=input_udp_eth_src_mac,
        eth_type=input_udp_eth_type,
        ip_version=input_udp_ip_version,
        ip_ihl=input_udp_ip_ihl,
        ip_dscp=input_udp_ip_dscp,
        ip_ecn=input_udp_ip_ecn,
        ip_identification=input_udp_ip_identification,
        ip_flags=input_udp_ip_flags,
        ip_fragment_offset=input_udp_ip_fragment_offset,
        ip_ttl=input_udp_ip_ttl,
        ip_header_checksum=input_udp_ip_header_checksum,
        ip_source_ip=input_udp_ip_source_ip,
        ip_dest_ip=input_udp_ip_dest_ip,
        udp_source_port=input_udp_source_port,
        udp_dest_port=input_udp_dest_port,
        udp_length=input_udp_length,
        udp_checksum=input_udp_checksum,
        udp_payload_tdata=input_udp_payload_tdata,
        udp_payload_tvalid=input_udp_payload_tvalid,
        udp_payload_tready=input_udp_payload_tready,
        udp_payload_tlast=input_udp_payload_tlast,
        udp_payload_tuser=input_udp_payload_tuser,
        pause=udp_source_pause,
        name='udp_source')

    udp_sink = udp_ep.UDPFrameSink()

    udp_sink_logic = udp_sink.create_logic(
        clk,
        rst,
        udp_hdr_ready=output_udp_hdr_ready,
        udp_hdr_valid=output_udp_hdr_valid,
        eth_dest_mac=output_udp_eth_dest_mac,
        eth_src_mac=output_udp_eth_src_mac,
        eth_type=output_udp_eth_type,
        ip_version=output_udp_ip_version,
        ip_ihl=output_udp_ip_ihl,
        ip_dscp=output_udp_ip_dscp,
        ip_ecn=output_udp_ip_ecn,
        ip_length=output_udp_ip_length,
        ip_identification=output_udp_ip_identification,
        ip_flags=output_udp_ip_flags,
        ip_fragment_offset=output_udp_ip_fragment_offset,
        ip_ttl=output_udp_ip_ttl,
        ip_protocol=output_udp_ip_protocol,
        ip_header_checksum=output_udp_ip_header_checksum,
        ip_source_ip=output_udp_ip_source_ip,
        ip_dest_ip=output_udp_ip_dest_ip,
        udp_source_port=output_udp_source_port,
        udp_dest_port=output_udp_dest_port,
        udp_length=output_udp_length,
        udp_checksum=output_udp_checksum,
        udp_payload_tdata=output_udp_payload_tdata,
        udp_payload_tvalid=output_udp_payload_tvalid,
        udp_payload_tready=output_udp_payload_tready,
        udp_payload_tlast=output_udp_payload_tlast,
        udp_payload_tuser=output_udp_payload_tuser,
        pause=udp_sink_pause,
        name='udp_sink')

    # DUT
    if os.system(build_cmd):
        raise Exception("Error running build command")

    dut = Cosimulation(
        "vvp -m myhdl %s.vvp -lxt2" % testbench,
        clk=clk,
        rst=rst,
        current_test=current_test,
        input_ip_hdr_valid=input_ip_hdr_valid,
        input_ip_hdr_ready=input_ip_hdr_ready,
        input_ip_eth_dest_mac=input_ip_eth_dest_mac,
        input_ip_eth_src_mac=input_ip_eth_src_mac,
        input_ip_eth_type=input_ip_eth_type,
        input_ip_version=input_ip_version,
        input_ip_ihl=input_ip_ihl,
        input_ip_dscp=input_ip_dscp,
        input_ip_ecn=input_ip_ecn,
        input_ip_length=input_ip_length,
        input_ip_identification=input_ip_identification,
        input_ip_flags=input_ip_flags,
        input_ip_fragment_offset=input_ip_fragment_offset,
        input_ip_ttl=input_ip_ttl,
        input_ip_protocol=input_ip_protocol,
        input_ip_header_checksum=input_ip_header_checksum,
        input_ip_source_ip=input_ip_source_ip,
        input_ip_dest_ip=input_ip_dest_ip,
        input_ip_payload_tdata=input_ip_payload_tdata,
        input_ip_payload_tvalid=input_ip_payload_tvalid,
        input_ip_payload_tready=input_ip_payload_tready,
        input_ip_payload_tlast=input_ip_payload_tlast,
        input_ip_payload_tuser=input_ip_payload_tuser,
        output_ip_hdr_valid=output_ip_hdr_valid,
        output_ip_hdr_ready=output_ip_hdr_ready,
        output_ip_eth_dest_mac=output_ip_eth_dest_mac,
        output_ip_eth_src_mac=output_ip_eth_src_mac,
        output_ip_eth_type=output_ip_eth_type,
        output_ip_version=output_ip_version,
        output_ip_ihl=output_ip_ihl,
        output_ip_dscp=output_ip_dscp,
        output_ip_ecn=output_ip_ecn,
        output_ip_length=output_ip_length,
        output_ip_identification=output_ip_identification,
        output_ip_flags=output_ip_flags,
        output_ip_fragment_offset=output_ip_fragment_offset,
        output_ip_ttl=output_ip_ttl,
        output_ip_protocol=output_ip_protocol,
        output_ip_header_checksum=output_ip_header_checksum,
        output_ip_source_ip=output_ip_source_ip,
        output_ip_dest_ip=output_ip_dest_ip,
        output_ip_payload_tdata=output_ip_payload_tdata,
        output_ip_payload_tvalid=output_ip_payload_tvalid,
        output_ip_payload_tready=output_ip_payload_tready,
        output_ip_payload_tlast=output_ip_payload_tlast,
        output_ip_payload_tuser=output_ip_payload_tuser,
        input_udp_hdr_valid=input_udp_hdr_valid,
        input_udp_hdr_ready=input_udp_hdr_ready,
        input_udp_eth_dest_mac=input_udp_eth_dest_mac,
        input_udp_eth_src_mac=input_udp_eth_src_mac,
        input_udp_eth_type=input_udp_eth_type,
        input_udp_ip_version=input_udp_ip_version,
        input_udp_ip_ihl=input_udp_ip_ihl,
        input_udp_ip_dscp=input_udp_ip_dscp,
        input_udp_ip_ecn=input_udp_ip_ecn,
        input_udp_ip_identification=input_udp_ip_identification,
        input_udp_ip_flags=input_udp_ip_flags,
        input_udp_ip_fragment_offset=input_udp_ip_fragment_offset,
        input_udp_ip_ttl=input_udp_ip_ttl,
        input_udp_ip_header_checksum=input_udp_ip_header_checksum,
        input_udp_ip_source_ip=input_udp_ip_source_ip,
        input_udp_ip_dest_ip=input_udp_ip_dest_ip,
        input_udp_source_port=input_udp_source_port,
        input_udp_dest_port=input_udp_dest_port,
        input_udp_length=input_udp_length,
        input_udp_checksum=input_udp_checksum,
        input_udp_payload_tdata=input_udp_payload_tdata,
        input_udp_payload_tvalid=input_udp_payload_tvalid,
        input_udp_payload_tready=input_udp_payload_tready,
        input_udp_payload_tlast=input_udp_payload_tlast,
        input_udp_payload_tuser=input_udp_payload_tuser,
        output_udp_hdr_valid=output_udp_hdr_valid,
        output_udp_hdr_ready=output_udp_hdr_ready,
        output_udp_eth_dest_mac=output_udp_eth_dest_mac,
        output_udp_eth_src_mac=output_udp_eth_src_mac,
        output_udp_eth_type=output_udp_eth_type,
        output_udp_ip_version=output_udp_ip_version,
        output_udp_ip_ihl=output_udp_ip_ihl,
        output_udp_ip_dscp=output_udp_ip_dscp,
        output_udp_ip_ecn=output_udp_ip_ecn,
        output_udp_ip_length=output_udp_ip_length,
        output_udp_ip_identification=output_udp_ip_identification,
        output_udp_ip_flags=output_udp_ip_flags,
        output_udp_ip_fragment_offset=output_udp_ip_fragment_offset,
        output_udp_ip_ttl=output_udp_ip_ttl,
        output_udp_ip_protocol=output_udp_ip_protocol,
        output_udp_ip_header_checksum=output_udp_ip_header_checksum,
        output_udp_ip_source_ip=output_udp_ip_source_ip,
        output_udp_ip_dest_ip=output_udp_ip_dest_ip,
        output_udp_source_port=output_udp_source_port,
        output_udp_dest_port=output_udp_dest_port,
        output_udp_length=output_udp_length,
        output_udp_checksum=output_udp_checksum,
        output_udp_payload_tdata=output_udp_payload_tdata,
        output_udp_payload_tvalid=output_udp_payload_tvalid,
        output_udp_payload_tready=output_udp_payload_tready,
        output_udp_payload_tlast=output_udp_payload_tlast,
        output_udp_payload_tuser=output_udp_payload_tuser,
        rx_busy=rx_busy,
        tx_busy=tx_busy,
        rx_error_header_early_termination=rx_error_header_early_termination,
        rx_error_payload_early_termination=rx_error_payload_early_termination,
        tx_error_payload_early_termination=tx_error_payload_early_termination)

    @always(delay(4))
    def clkgen():
        clk.next = not clk

    rx_error_header_early_termination_asserted = Signal(bool(0))
    rx_error_payload_early_termination_asserted = Signal(bool(0))
    tx_error_payload_early_termination_asserted = Signal(bool(0))

    @always(clk.posedge)
    def monitor():
        if (rx_error_header_early_termination):
            rx_error_header_early_termination_asserted.next = 1
        if (rx_error_payload_early_termination):
            rx_error_payload_early_termination_asserted.next = 1
        if (tx_error_payload_early_termination):
            tx_error_payload_early_termination_asserted.next = 1

    @instance
    def check():
        yield delay(100)
        yield clk.posedge
        rst.next = 1
        yield clk.posedge
        rst.next = 0
        yield clk.posedge
        yield delay(100)
        yield clk.posedge

        yield clk.posedge
        print("test 1: test UDP RX packet")
        current_test.next = 1

        test_frame = udp_ep.UDPFrame()
        test_frame.eth_dest_mac = 0x5A5152535455
        test_frame.eth_src_mac = 0xDAD1D2D3D4D5
        test_frame.eth_type = 0x0800
        test_frame.ip_version = 4
        test_frame.ip_ihl = 5
        test_frame.ip_dscp = 0
        test_frame.ip_ecn = 0
        test_frame.ip_length = None
        test_frame.ip_identification = 0
        test_frame.ip_flags = 2
        test_frame.ip_fragment_offset = 0
        test_frame.ip_ttl = 64
        test_frame.ip_protocol = 0x11
        test_frame.ip_header_checksum = None
        test_frame.ip_source_ip = 0xc0a80165
        test_frame.ip_dest_ip = 0xc0a80164
        test_frame.udp_source_port = 1234
        test_frame.udp_dest_port = 5678
        test_frame.payload = bytearray(range(32))
        test_frame.build()
        ip_frame = test_frame.build_ip()

        ip_source.send(ip_frame)

        yield udp_sink.wait()
        rx_frame = udp_sink.recv()

        assert rx_frame == test_frame

        assert ip_source.empty()
        assert ip_sink.empty()
        assert udp_source.empty()
        assert udp_sink.empty()

        yield delay(100)

        yield clk.posedge
        print("test 2: test UDP TX packet")
        current_test.next = 2

        test_frame = udp_ep.UDPFrame()
        test_frame.eth_dest_mac = 0x5A5152535455
        test_frame.eth_src_mac = 0xDAD1D2D3D4D5
        test_frame.eth_type = 0x0800
        test_frame.ip_version = 4
        test_frame.ip_ihl = 5
        test_frame.ip_dscp = 0
        test_frame.ip_ecn = 0
        test_frame.ip_length = None
        test_frame.ip_identification = 0
        test_frame.ip_flags = 2
        test_frame.ip_fragment_offset = 0
        test_frame.ip_ttl = 64
        test_frame.ip_protocol = 0x11
        test_frame.ip_header_checksum = None
        test_frame.ip_source_ip = 0xc0a80165
        test_frame.ip_dest_ip = 0xc0a80164
        test_frame.udp_source_port = 1234
        test_frame.udp_dest_port = 5678
        test_frame.payload = bytearray(range(32))
        test_frame.build()

        udp_source.send(test_frame)

        yield ip_sink.wait()
        rx_frame = ip_sink.recv()

        check_frame = udp_ep.UDPFrame()
        check_frame.parse_ip(rx_frame)

        assert check_frame == test_frame

        assert ip_source.empty()
        assert ip_sink.empty()
        assert udp_source.empty()
        assert udp_sink.empty()

        yield delay(100)

        raise StopSimulation

    return instances()
コード例 #4
0
def bench():

    # Parameters
    PAYLOAD_FIFO_DEPTH = 2048
    HEADER_FIFO_DEPTH = 8

    # Inputs
    clk = Signal(bool(0))
    rst = Signal(bool(0))
    current_test = Signal(intbv(0)[8:])

    s_udp_hdr_valid = Signal(bool(0))
    s_eth_dest_mac = Signal(intbv(0)[48:])
    s_eth_src_mac = Signal(intbv(0)[48:])
    s_eth_type = Signal(intbv(0)[16:])
    s_ip_version = Signal(intbv(0)[4:])
    s_ip_ihl = Signal(intbv(0)[4:])
    s_ip_dscp = Signal(intbv(0)[6:])
    s_ip_ecn = Signal(intbv(0)[2:])
    s_ip_identification = Signal(intbv(0)[16:])
    s_ip_flags = Signal(intbv(0)[3:])
    s_ip_fragment_offset = Signal(intbv(0)[13:])
    s_ip_ttl = Signal(intbv(0)[8:])
    s_ip_header_checksum = Signal(intbv(0)[16:])
    s_ip_source_ip = Signal(intbv(0)[32:])
    s_ip_dest_ip = Signal(intbv(0)[32:])
    s_udp_source_port = Signal(intbv(0)[16:])
    s_udp_dest_port = Signal(intbv(0)[16:])
    s_udp_payload_axis_tdata = Signal(intbv(0)[64:])
    s_udp_payload_axis_tkeep = Signal(intbv(0)[8:])
    s_udp_payload_axis_tvalid = Signal(bool(0))
    s_udp_payload_axis_tlast = Signal(bool(0))
    s_udp_payload_axis_tuser = Signal(bool(0))

    m_udp_hdr_ready = Signal(bool(0))
    m_udp_payload_axis_tready = Signal(bool(0))

    # Outputs
    s_udp_hdr_ready = Signal(bool(0))
    s_udp_payload_axis_tready = Signal(bool(0))

    m_udp_hdr_valid = Signal(bool(0))
    m_eth_dest_mac = Signal(intbv(0)[48:])
    m_eth_src_mac = Signal(intbv(0)[48:])
    m_eth_type = Signal(intbv(0)[16:])
    m_ip_version = Signal(intbv(0)[4:])
    m_ip_ihl = Signal(intbv(0)[4:])
    m_ip_dscp = Signal(intbv(0)[6:])
    m_ip_ecn = Signal(intbv(0)[2:])
    m_ip_length = Signal(intbv(0)[16:])
    m_ip_identification = Signal(intbv(0)[16:])
    m_ip_flags = Signal(intbv(0)[3:])
    m_ip_fragment_offset = Signal(intbv(0)[13:])
    m_ip_ttl = Signal(intbv(0)[8:])
    m_ip_protocol = Signal(intbv(0x11)[8:])
    m_ip_header_checksum = Signal(intbv(0)[16:])
    m_ip_source_ip = Signal(intbv(0)[32:])
    m_ip_dest_ip = Signal(intbv(0)[32:])
    m_udp_source_port = Signal(intbv(0)[16:])
    m_udp_dest_port = Signal(intbv(0)[16:])
    m_udp_length = Signal(intbv(0)[16:])
    m_udp_checksum = Signal(intbv(0)[16:])
    m_udp_payload_axis_tdata = Signal(intbv(0)[64:])
    m_udp_payload_axis_tkeep = Signal(intbv(0)[8:])
    m_udp_payload_axis_tvalid = Signal(bool(0))
    m_udp_payload_axis_tlast = Signal(bool(0))
    m_udp_payload_axis_tuser = Signal(bool(0))

    busy = Signal(bool(0))

    # sources and sinks
    source_pause = Signal(bool(0))
    sink_pause = Signal(bool(0))

    source = udp_ep.UDPFrameSource()

    source_logic = source.create_logic(
        clk,
        rst,
        udp_hdr_ready=s_udp_hdr_ready,
        udp_hdr_valid=s_udp_hdr_valid,
        eth_dest_mac=s_eth_dest_mac,
        eth_src_mac=s_eth_src_mac,
        eth_type=s_eth_type,
        ip_version=s_ip_version,
        ip_ihl=s_ip_ihl,
        ip_dscp=s_ip_dscp,
        ip_ecn=s_ip_ecn,
        ip_identification=s_ip_identification,
        ip_flags=s_ip_flags,
        ip_fragment_offset=s_ip_fragment_offset,
        ip_ttl=s_ip_ttl,
        ip_header_checksum=s_ip_header_checksum,
        ip_source_ip=s_ip_source_ip,
        ip_dest_ip=s_ip_dest_ip,
        udp_source_port=s_udp_source_port,
        udp_dest_port=s_udp_dest_port,
        udp_payload_tdata=s_udp_payload_axis_tdata,
        udp_payload_tkeep=s_udp_payload_axis_tkeep,
        udp_payload_tvalid=s_udp_payload_axis_tvalid,
        udp_payload_tready=s_udp_payload_axis_tready,
        udp_payload_tlast=s_udp_payload_axis_tlast,
        udp_payload_tuser=s_udp_payload_axis_tuser,
        pause=source_pause,
        name='source')

    sink = udp_ep.UDPFrameSink()

    sink_logic = sink.create_logic(
        clk,
        rst,
        udp_hdr_ready=m_udp_hdr_ready,
        udp_hdr_valid=m_udp_hdr_valid,
        eth_dest_mac=m_eth_dest_mac,
        eth_src_mac=m_eth_src_mac,
        eth_type=m_eth_type,
        ip_version=m_ip_version,
        ip_ihl=m_ip_ihl,
        ip_dscp=m_ip_dscp,
        ip_ecn=m_ip_ecn,
        ip_length=m_ip_length,
        ip_identification=m_ip_identification,
        ip_flags=m_ip_flags,
        ip_fragment_offset=m_ip_fragment_offset,
        ip_ttl=m_ip_ttl,
        ip_protocol=m_ip_protocol,
        ip_header_checksum=m_ip_header_checksum,
        ip_source_ip=m_ip_source_ip,
        ip_dest_ip=m_ip_dest_ip,
        udp_source_port=m_udp_source_port,
        udp_dest_port=m_udp_dest_port,
        udp_length=m_udp_length,
        udp_checksum=m_udp_checksum,
        udp_payload_tdata=m_udp_payload_axis_tdata,
        udp_payload_tkeep=m_udp_payload_axis_tkeep,
        udp_payload_tvalid=m_udp_payload_axis_tvalid,
        udp_payload_tready=m_udp_payload_axis_tready,
        udp_payload_tlast=m_udp_payload_axis_tlast,
        udp_payload_tuser=m_udp_payload_axis_tuser,
        pause=sink_pause,
        name='sink')

    # DUT
    if os.system(build_cmd):
        raise Exception("Error running build command")

    dut = Cosimulation("vvp -m myhdl %s.vvp -lxt2" % testbench,
                       clk=clk,
                       rst=rst,
                       current_test=current_test,
                       s_udp_hdr_valid=s_udp_hdr_valid,
                       s_udp_hdr_ready=s_udp_hdr_ready,
                       s_eth_dest_mac=s_eth_dest_mac,
                       s_eth_src_mac=s_eth_src_mac,
                       s_eth_type=s_eth_type,
                       s_ip_version=s_ip_version,
                       s_ip_ihl=s_ip_ihl,
                       s_ip_dscp=s_ip_dscp,
                       s_ip_ecn=s_ip_ecn,
                       s_ip_identification=s_ip_identification,
                       s_ip_flags=s_ip_flags,
                       s_ip_fragment_offset=s_ip_fragment_offset,
                       s_ip_ttl=s_ip_ttl,
                       s_ip_header_checksum=s_ip_header_checksum,
                       s_ip_source_ip=s_ip_source_ip,
                       s_ip_dest_ip=s_ip_dest_ip,
                       s_udp_source_port=s_udp_source_port,
                       s_udp_dest_port=s_udp_dest_port,
                       s_udp_payload_axis_tdata=s_udp_payload_axis_tdata,
                       s_udp_payload_axis_tkeep=s_udp_payload_axis_tkeep,
                       s_udp_payload_axis_tvalid=s_udp_payload_axis_tvalid,
                       s_udp_payload_axis_tready=s_udp_payload_axis_tready,
                       s_udp_payload_axis_tlast=s_udp_payload_axis_tlast,
                       s_udp_payload_axis_tuser=s_udp_payload_axis_tuser,
                       m_udp_hdr_valid=m_udp_hdr_valid,
                       m_udp_hdr_ready=m_udp_hdr_ready,
                       m_eth_dest_mac=m_eth_dest_mac,
                       m_eth_src_mac=m_eth_src_mac,
                       m_eth_type=m_eth_type,
                       m_ip_version=m_ip_version,
                       m_ip_ihl=m_ip_ihl,
                       m_ip_dscp=m_ip_dscp,
                       m_ip_ecn=m_ip_ecn,
                       m_ip_length=m_ip_length,
                       m_ip_identification=m_ip_identification,
                       m_ip_flags=m_ip_flags,
                       m_ip_fragment_offset=m_ip_fragment_offset,
                       m_ip_ttl=m_ip_ttl,
                       m_ip_protocol=m_ip_protocol,
                       m_ip_header_checksum=m_ip_header_checksum,
                       m_ip_source_ip=m_ip_source_ip,
                       m_ip_dest_ip=m_ip_dest_ip,
                       m_udp_source_port=m_udp_source_port,
                       m_udp_dest_port=m_udp_dest_port,
                       m_udp_length=m_udp_length,
                       m_udp_checksum=m_udp_checksum,
                       m_udp_payload_axis_tdata=m_udp_payload_axis_tdata,
                       m_udp_payload_axis_tkeep=m_udp_payload_axis_tkeep,
                       m_udp_payload_axis_tvalid=m_udp_payload_axis_tvalid,
                       m_udp_payload_axis_tready=m_udp_payload_axis_tready,
                       m_udp_payload_axis_tlast=m_udp_payload_axis_tlast,
                       m_udp_payload_axis_tuser=m_udp_payload_axis_tuser,
                       busy=busy)

    @always(delay(4))
    def clkgen():
        clk.next = not clk

    def wait_normal():
        i = 4
        while i > 0:
            i = max(0, i - 1)
            if s_udp_payload_axis_tvalid or m_udp_payload_axis_tvalid or s_udp_hdr_valid or not source.empty(
            ):
                i = 4
            yield clk.posedge

    def wait_pause_source():
        i = 2
        while i > 0:
            i = max(0, i - 1)
            if s_udp_payload_axis_tvalid or m_udp_payload_axis_tvalid or s_udp_hdr_valid or not source.empty(
            ):
                i = 2
            source_pause.next = True
            yield clk.posedge
            yield clk.posedge
            yield clk.posedge
            source_pause.next = False
            yield clk.posedge

    def wait_pause_sink():
        i = 2
        while i > 0:
            i = max(0, i - 1)
            if s_udp_payload_axis_tvalid or m_udp_payload_axis_tvalid or s_udp_hdr_valid or not source.empty(
            ):
                i = 2
            sink_pause.next = True
            yield clk.posedge
            yield clk.posedge
            yield clk.posedge
            sink_pause.next = False
            yield clk.posedge

    @instance
    def check():
        yield delay(100)
        yield clk.posedge
        rst.next = 1
        yield clk.posedge
        rst.next = 0
        yield clk.posedge
        yield delay(100)
        yield clk.posedge

        # testbench stimulus

        for payload_len in range(1, 18):
            yield clk.posedge
            print("test 1: test packet, length %d" % payload_len)
            current_test.next = 1

            test_frame = udp_ep.UDPFrame()
            test_frame.eth_dest_mac = 0xDAD1D2D3D4D5
            test_frame.eth_src_mac = 0x5A5152535455
            test_frame.eth_type = 0x0800
            test_frame.ip_version = 4
            test_frame.ip_ihl = 5
            test_frame.ip_length = None
            test_frame.ip_identification = 0
            test_frame.ip_flags = 2
            test_frame.ip_fragment_offset = 0
            test_frame.ip_ttl = 64
            test_frame.ip_protocol = 0x11
            test_frame.ip_header_checksum = None
            test_frame.ip_source_ip = 0xc0a80164
            test_frame.ip_dest_ip = 0xc0a80165
            test_frame.udp_source_port = 1
            test_frame.udp_dest_port = 2
            test_frame.udp_length = None
            test_frame.udp_checksum = None
            test_frame.payload = bytearray(range(payload_len))
            test_frame.build()

            for wait in wait_normal, wait_pause_source, wait_pause_sink:
                source.send(test_frame)
                yield clk.posedge
                yield clk.posedge

                yield wait()

                yield sink.wait()
                rx_frame = sink.recv()

                assert rx_frame == test_frame

                assert sink.empty()

                yield delay(100)

            yield clk.posedge
            print("test 2: back-to-back packets, length %d" % payload_len)
            current_test.next = 2

            test_frame1 = udp_ep.UDPFrame()
            test_frame1.eth_dest_mac = 0xDAD1D2D3D4D5
            test_frame1.eth_src_mac = 0x5A5152535455
            test_frame1.eth_type = 0x0800
            test_frame1.ip_version = 4
            test_frame1.ip_ihl = 5
            test_frame1.ip_length = None
            test_frame1.ip_identification = 0
            test_frame1.ip_flags = 2
            test_frame1.ip_fragment_offset = 0
            test_frame1.ip_ttl = 64
            test_frame1.ip_protocol = 0x11
            test_frame1.ip_header_checksum = None
            test_frame1.ip_source_ip = 0xc0a80164
            test_frame1.ip_dest_ip = 0xc0a80165
            test_frame1.udp_source_port = 1
            test_frame1.udp_dest_port = 2
            test_frame1.udp_length = None
            test_frame1.udp_checksum = None
            test_frame1.payload = bytearray(range(payload_len))
            test_frame1.build()
            test_frame2 = udp_ep.UDPFrame()
            test_frame2.eth_dest_mac = 0xDAD1D2D3D4D5
            test_frame2.eth_src_mac = 0x5A5152535455
            test_frame2.eth_type = 0x0800
            test_frame2.ip_version = 4
            test_frame2.ip_ihl = 5
            test_frame2.ip_length = None
            test_frame2.ip_identification = 0
            test_frame2.ip_flags = 2
            test_frame2.ip_fragment_offset = 0
            test_frame2.ip_ttl = 64
            test_frame2.ip_protocol = 0x11
            test_frame2.ip_header_checksum = None
            test_frame2.ip_source_ip = 0xc0a80164
            test_frame2.ip_dest_ip = 0xc0a80166
            test_frame2.udp_source_port = 1
            test_frame2.udp_dest_port = 2
            test_frame2.udp_length = None
            test_frame2.udp_checksum = None
            test_frame2.payload = bytearray(range(payload_len))
            test_frame2.build()

            for wait in wait_normal, wait_pause_source, wait_pause_sink:
                source.send(test_frame1)
                source.send(test_frame2)
                yield clk.posedge
                yield clk.posedge

                yield wait()

                yield sink.wait()
                rx_frame = sink.recv()

                assert rx_frame == test_frame1

                yield sink.wait()
                rx_frame = sink.recv()

                assert rx_frame == test_frame2

                assert sink.empty()

                yield delay(100)

            yield clk.posedge
            print("test 3: tuser assert, length %d" % payload_len)
            current_test.next = 3

            test_frame1 = udp_ep.UDPFrame()
            test_frame1.eth_dest_mac = 0xDAD1D2D3D4D5
            test_frame1.eth_src_mac = 0x5A5152535455
            test_frame1.eth_type = 0x0800
            test_frame1.ip_version = 4
            test_frame1.ip_ihl = 5
            test_frame1.ip_length = None
            test_frame1.ip_identification = 0
            test_frame1.ip_flags = 2
            test_frame1.ip_fragment_offset = 0
            test_frame1.ip_ttl = 64
            test_frame1.ip_protocol = 0x11
            test_frame1.ip_header_checksum = None
            test_frame1.ip_source_ip = 0xc0a80164
            test_frame1.ip_dest_ip = 0xc0a80165
            test_frame1.udp_source_port = 1
            test_frame1.udp_dest_port = 2
            test_frame1.udp_length = None
            test_frame1.udp_checksum = None
            test_frame1.payload = bytearray(range(payload_len))
            test_frame1.build()
            test_frame2 = udp_ep.UDPFrame()
            test_frame2.eth_dest_mac = 0xDAD1D2D3D4D5
            test_frame2.eth_src_mac = 0x5A5152535455
            test_frame2.eth_type = 0x0800
            test_frame2.ip_version = 4
            test_frame2.ip_ihl = 5
            test_frame2.ip_length = None
            test_frame2.ip_identification = 0
            test_frame2.ip_flags = 2
            test_frame2.ip_fragment_offset = 0
            test_frame2.ip_ttl = 64
            test_frame2.ip_protocol = 0x11
            test_frame2.ip_header_checksum = None
            test_frame2.ip_source_ip = 0xc0a80164
            test_frame2.ip_dest_ip = 0xc0a80166
            test_frame2.udp_source_port = 1
            test_frame2.udp_dest_port = 2
            test_frame2.udp_length = None
            test_frame2.udp_checksum = None
            test_frame2.payload = bytearray(range(payload_len))
            test_frame2.build()

            test_frame1.payload.user = 1

            for wait in wait_normal, wait_pause_source, wait_pause_sink:
                source.send(test_frame1)
                source.send(test_frame2)
                yield clk.posedge
                yield clk.posedge

                yield wait()

                yield sink.wait()
                rx_frame = sink.recv()

                assert rx_frame == test_frame1
                assert rx_frame.payload.user[-1]

                yield sink.wait()
                rx_frame = sink.recv()

                assert rx_frame == test_frame2

                assert sink.empty()

                yield delay(100)

        raise StopSimulation

    return instances()
コード例 #5
0
def bench():

    # Inputs
    clk = Signal(bool(0))
    rst = Signal(bool(0))
    current_test = Signal(intbv(0)[8:])

    input_ip_hdr_valid = Signal(bool(0))
    input_eth_dest_mac = Signal(intbv(0)[48:])
    input_eth_src_mac = Signal(intbv(0)[48:])
    input_eth_type = Signal(intbv(0)[16:])
    input_ip_version = Signal(intbv(0)[4:])
    input_ip_ihl = Signal(intbv(0)[4:])
    input_ip_dscp = Signal(intbv(0)[6:])
    input_ip_ecn = Signal(intbv(0)[2:])
    input_ip_length = Signal(intbv(0)[16:])
    input_ip_identification = Signal(intbv(0)[16:])
    input_ip_flags = Signal(intbv(0)[3:])
    input_ip_fragment_offset = Signal(intbv(0)[13:])
    input_ip_ttl = Signal(intbv(0)[8:])
    input_ip_protocol = Signal(intbv(0)[8:])
    input_ip_header_checksum = Signal(intbv(0)[16:])
    input_ip_source_ip = Signal(intbv(0)[32:])
    input_ip_dest_ip = Signal(intbv(0)[32:])
    input_ip_payload_tdata = Signal(intbv(0)[64:])
    input_ip_payload_tkeep = Signal(intbv(0)[8:])
    input_ip_payload_tvalid = Signal(bool(0))
    input_ip_payload_tlast = Signal(bool(0))
    input_ip_payload_tuser = Signal(bool(0))
    output_udp_hdr_ready = Signal(bool(0))
    output_udp_payload_tready = Signal(bool(0))

    # Outputs
    input_ip_hdr_ready = Signal(bool(0))
    input_ip_payload_tready = Signal(bool(0))
    output_udp_hdr_valid = Signal(bool(0))
    output_eth_dest_mac = Signal(intbv(0)[48:])
    output_eth_src_mac = Signal(intbv(0)[48:])
    output_eth_type = Signal(intbv(0)[16:])
    output_ip_version = Signal(intbv(0)[4:])
    output_ip_ihl = Signal(intbv(0)[4:])
    output_ip_dscp = Signal(intbv(0)[6:])
    output_ip_ecn = Signal(intbv(0)[2:])
    output_ip_length = Signal(intbv(0)[16:])
    output_ip_identification = Signal(intbv(0)[16:])
    output_ip_flags = Signal(intbv(0)[3:])
    output_ip_fragment_offset = Signal(intbv(0)[13:])
    output_ip_ttl = Signal(intbv(0)[8:])
    output_ip_protocol = Signal(intbv(0)[8:])
    output_ip_header_checksum = Signal(intbv(0)[16:])
    output_ip_source_ip = Signal(intbv(0)[32:])
    output_ip_dest_ip = Signal(intbv(0)[32:])
    output_udp_source_port = Signal(intbv(0)[16:])
    output_udp_dest_port = Signal(intbv(0)[16:])
    output_udp_length = Signal(intbv(0)[16:])
    output_udp_checksum = Signal(intbv(0)[16:])
    output_udp_payload_tdata = Signal(intbv(0)[64:])
    output_udp_payload_tkeep = Signal(intbv(0)[8:])
    output_udp_payload_tvalid = Signal(bool(0))
    output_udp_payload_tlast = Signal(bool(0))
    output_udp_payload_tuser = Signal(bool(0))
    busy = Signal(bool(0))
    error_header_early_termination = Signal(bool(0))
    error_payload_early_termination = Signal(bool(0))

    # sources and sinks
    source_pause = Signal(bool(0))
    sink_pause = Signal(bool(0))

    source = ip_ep.IPFrameSource()

    source_logic = source.create_logic(
        clk,
        rst,
        ip_hdr_ready=input_ip_hdr_ready,
        ip_hdr_valid=input_ip_hdr_valid,
        eth_dest_mac=input_eth_dest_mac,
        eth_src_mac=input_eth_src_mac,
        eth_type=input_eth_type,
        ip_version=input_ip_version,
        ip_ihl=input_ip_ihl,
        ip_dscp=input_ip_dscp,
        ip_ecn=input_ip_ecn,
        ip_length=input_ip_length,
        ip_identification=input_ip_identification,
        ip_flags=input_ip_flags,
        ip_fragment_offset=input_ip_fragment_offset,
        ip_ttl=input_ip_ttl,
        ip_protocol=input_ip_protocol,
        ip_header_checksum=input_ip_header_checksum,
        ip_source_ip=input_ip_source_ip,
        ip_dest_ip=input_ip_dest_ip,
        ip_payload_tdata=input_ip_payload_tdata,
        ip_payload_tkeep=input_ip_payload_tkeep,
        ip_payload_tvalid=input_ip_payload_tvalid,
        ip_payload_tready=input_ip_payload_tready,
        ip_payload_tlast=input_ip_payload_tlast,
        ip_payload_tuser=input_ip_payload_tuser,
        pause=source_pause,
        name='source')

    sink = udp_ep.UDPFrameSink()

    sink_logic = sink.create_logic(
        clk,
        rst,
        udp_hdr_ready=output_udp_hdr_ready,
        udp_hdr_valid=output_udp_hdr_valid,
        eth_dest_mac=output_eth_dest_mac,
        eth_src_mac=output_eth_src_mac,
        eth_type=output_eth_type,
        ip_version=output_ip_version,
        ip_ihl=output_ip_ihl,
        ip_dscp=output_ip_dscp,
        ip_ecn=output_ip_ecn,
        ip_length=output_ip_length,
        ip_identification=output_ip_identification,
        ip_flags=output_ip_flags,
        ip_fragment_offset=output_ip_fragment_offset,
        ip_ttl=output_ip_ttl,
        ip_protocol=output_ip_protocol,
        ip_header_checksum=output_ip_header_checksum,
        ip_source_ip=output_ip_source_ip,
        ip_dest_ip=output_ip_dest_ip,
        udp_source_port=output_udp_source_port,
        udp_dest_port=output_udp_dest_port,
        udp_length=output_udp_length,
        udp_checksum=output_udp_checksum,
        udp_payload_tdata=output_udp_payload_tdata,
        udp_payload_tkeep=output_udp_payload_tkeep,
        udp_payload_tvalid=output_udp_payload_tvalid,
        udp_payload_tready=output_udp_payload_tready,
        udp_payload_tlast=output_udp_payload_tlast,
        udp_payload_tuser=output_udp_payload_tuser,
        pause=sink_pause,
        name='sink')

    # DUT
    if os.system(build_cmd):
        raise Exception("Error running build command")

    dut = Cosimulation(
        "vvp -m myhdl %s.vvp -lxt2" % testbench,
        clk=clk,
        rst=rst,
        current_test=current_test,
        input_ip_hdr_valid=input_ip_hdr_valid,
        input_ip_hdr_ready=input_ip_hdr_ready,
        input_eth_dest_mac=input_eth_dest_mac,
        input_eth_src_mac=input_eth_src_mac,
        input_eth_type=input_eth_type,
        input_ip_version=input_ip_version,
        input_ip_ihl=input_ip_ihl,
        input_ip_dscp=input_ip_dscp,
        input_ip_ecn=input_ip_ecn,
        input_ip_length=input_ip_length,
        input_ip_identification=input_ip_identification,
        input_ip_flags=input_ip_flags,
        input_ip_fragment_offset=input_ip_fragment_offset,
        input_ip_ttl=input_ip_ttl,
        input_ip_protocol=input_ip_protocol,
        input_ip_header_checksum=input_ip_header_checksum,
        input_ip_source_ip=input_ip_source_ip,
        input_ip_dest_ip=input_ip_dest_ip,
        input_ip_payload_tdata=input_ip_payload_tdata,
        input_ip_payload_tkeep=input_ip_payload_tkeep,
        input_ip_payload_tvalid=input_ip_payload_tvalid,
        input_ip_payload_tready=input_ip_payload_tready,
        input_ip_payload_tlast=input_ip_payload_tlast,
        input_ip_payload_tuser=input_ip_payload_tuser,
        output_udp_hdr_valid=output_udp_hdr_valid,
        output_udp_hdr_ready=output_udp_hdr_ready,
        output_eth_dest_mac=output_eth_dest_mac,
        output_eth_src_mac=output_eth_src_mac,
        output_eth_type=output_eth_type,
        output_ip_version=output_ip_version,
        output_ip_ihl=output_ip_ihl,
        output_ip_dscp=output_ip_dscp,
        output_ip_ecn=output_ip_ecn,
        output_ip_length=output_ip_length,
        output_ip_identification=output_ip_identification,
        output_ip_flags=output_ip_flags,
        output_ip_fragment_offset=output_ip_fragment_offset,
        output_ip_ttl=output_ip_ttl,
        output_ip_protocol=output_ip_protocol,
        output_ip_header_checksum=output_ip_header_checksum,
        output_ip_source_ip=output_ip_source_ip,
        output_ip_dest_ip=output_ip_dest_ip,
        output_udp_source_port=output_udp_source_port,
        output_udp_dest_port=output_udp_dest_port,
        output_udp_length=output_udp_length,
        output_udp_checksum=output_udp_checksum,
        output_udp_payload_tdata=output_udp_payload_tdata,
        output_udp_payload_tkeep=output_udp_payload_tkeep,
        output_udp_payload_tvalid=output_udp_payload_tvalid,
        output_udp_payload_tready=output_udp_payload_tready,
        output_udp_payload_tlast=output_udp_payload_tlast,
        output_udp_payload_tuser=output_udp_payload_tuser,
        busy=busy,
        error_header_early_termination=error_header_early_termination,
        error_payload_early_termination=error_payload_early_termination)

    @always(delay(4))
    def clkgen():
        clk.next = not clk

    error_header_early_termination_asserted = Signal(bool(0))
    error_payload_early_termination_asserted = Signal(bool(0))

    @always(clk.posedge)
    def monitor():
        if (error_header_early_termination):
            error_header_early_termination_asserted.next = 1
        if (error_payload_early_termination):
            error_payload_early_termination_asserted.next = 1

    def wait_normal():
        while input_ip_payload_tvalid or output_udp_payload_tvalid or input_ip_hdr_valid:
            yield clk.posedge

    def wait_pause_source():
        while input_ip_payload_tvalid or output_udp_payload_tvalid or input_ip_hdr_valid:
            source_pause.next = True
            yield clk.posedge
            yield clk.posedge
            yield clk.posedge
            source_pause.next = False
            yield clk.posedge

    def wait_pause_sink():
        while input_ip_payload_tvalid or output_udp_payload_tvalid or input_ip_hdr_valid:
            sink_pause.next = True
            yield clk.posedge
            yield clk.posedge
            yield clk.posedge
            sink_pause.next = False
            yield clk.posedge

    @instance
    def check():
        yield delay(100)
        yield clk.posedge
        rst.next = 1
        yield clk.posedge
        rst.next = 0
        yield clk.posedge
        yield delay(100)
        yield clk.posedge

        for payload_len in range(1, 18):
            yield clk.posedge
            print("test 1: test packet, length %d" % payload_len)
            current_test.next = 1

            test_frame = udp_ep.UDPFrame()
            test_frame.eth_dest_mac = 0xDAD1D2D3D4D5
            test_frame.eth_src_mac = 0x5A5152535455
            test_frame.eth_type = 0x0800
            test_frame.ip_version = 4
            test_frame.ip_ihl = 5
            test_frame.ip_length = None
            test_frame.ip_identification = 0
            test_frame.ip_flags = 2
            test_frame.ip_fragment_offset = 0
            test_frame.ip_ttl = 64
            test_frame.ip_protocol = 0x11
            test_frame.ip_header_checksum = None
            test_frame.ip_source_ip = 0xc0a80164
            test_frame.ip_dest_ip = 0xc0a80165
            test_frame.udp_source_port = 1
            test_frame.udp_dest_port = 2
            test_frame.udp_length = None
            test_frame.udp_checksum = None
            test_frame.payload = bytearray(range(payload_len))
            test_frame.build()
            ip_frame = test_frame.build_ip()

            for wait in wait_normal, wait_pause_source, wait_pause_sink:
                source.send(ip_frame)
                yield clk.posedge
                yield clk.posedge

                yield wait()

                yield clk.posedge
                yield clk.posedge
                yield clk.posedge

                rx_frame = sink.recv()

                assert rx_frame == test_frame

                assert sink.empty()

                yield delay(100)

            yield clk.posedge
            print("test 2: back-to-back packets, length %d" % payload_len)
            current_test.next = 2

            test_frame1 = udp_ep.UDPFrame()
            test_frame1.eth_dest_mac = 0xDAD1D2D3D4D5
            test_frame1.eth_src_mac = 0x5A5152535455
            test_frame1.eth_type = 0x0800
            test_frame1.ip_version = 4
            test_frame1.ip_ihl = 5
            test_frame1.ip_length = None
            test_frame1.ip_identification = 0
            test_frame1.ip_flags = 2
            test_frame1.ip_fragment_offset = 0
            test_frame1.ip_ttl = 64
            test_frame1.ip_protocol = 0x11
            test_frame1.ip_header_checksum = None
            test_frame1.ip_source_ip = 0xc0a80164
            test_frame1.ip_dest_ip = 0xc0a80165
            test_frame1.udp_source_port = 1
            test_frame1.udp_dest_port = 2
            test_frame1.udp_length = None
            test_frame1.udp_checksum = None
            test_frame1.payload = bytearray(range(payload_len))
            test_frame1.build()
            test_frame2 = udp_ep.UDPFrame()
            test_frame2.eth_dest_mac = 0xDAD1D2D3D4D5
            test_frame2.eth_src_mac = 0x5A5152535455
            test_frame2.eth_type = 0x0800
            test_frame2.ip_version = 4
            test_frame2.ip_ihl = 5
            test_frame2.ip_length = None
            test_frame2.ip_identification = 0
            test_frame2.ip_flags = 2
            test_frame2.ip_fragment_offset = 0
            test_frame2.ip_ttl = 64
            test_frame2.ip_protocol = 0x11
            test_frame2.ip_header_checksum = None
            test_frame2.ip_source_ip = 0xc0a80164
            test_frame2.ip_dest_ip = 0xc0a80166
            test_frame2.udp_source_port = 1
            test_frame2.udp_dest_port = 2
            test_frame2.udp_length = None
            test_frame2.udp_checksum = None
            test_frame2.payload = bytearray(range(payload_len))
            test_frame2.build()

            ip_frame1 = test_frame1.build_ip()
            ip_frame2 = test_frame2.build_ip()

            for wait in wait_normal, wait_pause_source, wait_pause_sink:
                source.send(ip_frame1)
                source.send(ip_frame2)
                yield clk.posedge
                yield clk.posedge

                yield wait()

                yield clk.posedge
                yield clk.posedge
                yield clk.posedge

                rx_frame = sink.recv()

                assert rx_frame == test_frame1

                rx_frame = sink.recv()

                assert rx_frame == test_frame2

                assert sink.empty()

                yield delay(100)

            yield clk.posedge
            print("test 3: tuser assert, length %d" % payload_len)
            current_test.next = 3

            test_frame1 = udp_ep.UDPFrame()
            test_frame1.eth_dest_mac = 0xDAD1D2D3D4D5
            test_frame1.eth_src_mac = 0x5A5152535455
            test_frame1.eth_type = 0x0800
            test_frame1.ip_version = 4
            test_frame1.ip_ihl = 5
            test_frame1.ip_length = None
            test_frame1.ip_identification = 0
            test_frame1.ip_flags = 2
            test_frame1.ip_fragment_offset = 0
            test_frame1.ip_ttl = 64
            test_frame1.ip_protocol = 0x11
            test_frame1.ip_header_checksum = None
            test_frame1.ip_source_ip = 0xc0a80164
            test_frame1.ip_dest_ip = 0xc0a80165
            test_frame1.udp_source_port = 1
            test_frame1.udp_dest_port = 2
            test_frame1.udp_length = None
            test_frame1.udp_checksum = None
            test_frame1.payload = bytearray(range(payload_len))
            test_frame1.build()
            test_frame2 = udp_ep.UDPFrame()
            test_frame2.eth_dest_mac = 0xDAD1D2D3D4D5
            test_frame2.eth_src_mac = 0x5A5152535455
            test_frame2.eth_type = 0x0800
            test_frame2.ip_version = 4
            test_frame2.ip_ihl = 5
            test_frame2.ip_length = None
            test_frame2.ip_identification = 0
            test_frame2.ip_flags = 2
            test_frame2.ip_fragment_offset = 0
            test_frame2.ip_ttl = 64
            test_frame2.ip_protocol = 0x11
            test_frame2.ip_header_checksum = None
            test_frame2.ip_source_ip = 0xc0a80164
            test_frame2.ip_dest_ip = 0xc0a80166
            test_frame2.udp_source_port = 1
            test_frame2.udp_dest_port = 2
            test_frame2.udp_length = None
            test_frame2.udp_checksum = None
            test_frame2.payload = bytearray(range(payload_len))
            test_frame2.build()

            ip_frame1 = test_frame1.build_ip()
            ip_frame2 = test_frame2.build_ip()

            ip_frame1.payload.user = 1

            for wait in wait_normal, wait_pause_source, wait_pause_sink:
                source.send(ip_frame1)
                source.send(ip_frame2)
                yield clk.posedge
                yield clk.posedge

                yield wait()

                yield clk.posedge
                yield clk.posedge
                yield clk.posedge

                rx_frame = sink.recv()

                assert rx_frame == test_frame1
                assert rx_frame.payload.user[-1]

                rx_frame = sink.recv()

                assert rx_frame == test_frame2

                assert sink.empty()

                yield delay(100)

            yield clk.posedge
            print("test 4: trailing bytes (1), length %d" % payload_len)
            current_test.next = 4

            test_frame1 = udp_ep.UDPFrame()
            test_frame1.eth_dest_mac = 0xDAD1D2D3D4D5
            test_frame1.eth_src_mac = 0x5A5152535455
            test_frame1.eth_type = 0x0800
            test_frame1.ip_version = 4
            test_frame1.ip_ihl = 5
            test_frame1.ip_length = None
            test_frame1.ip_identification = 0
            test_frame1.ip_flags = 2
            test_frame1.ip_fragment_offset = 0
            test_frame1.ip_ttl = 64
            test_frame1.ip_protocol = 0x11
            test_frame1.ip_header_checksum = None
            test_frame1.ip_source_ip = 0xc0a80164
            test_frame1.ip_dest_ip = 0xc0a80165
            test_frame1.udp_source_port = 1
            test_frame1.udp_dest_port = 2
            test_frame1.udp_length = None
            test_frame1.udp_checksum = None
            test_frame1.payload = bytearray(range(payload_len))
            test_frame1.build()
            test_frame2 = udp_ep.UDPFrame()
            test_frame2.eth_dest_mac = 0xDAD1D2D3D4D5
            test_frame2.eth_src_mac = 0x5A5152535455
            test_frame2.eth_type = 0x0800
            test_frame2.ip_version = 4
            test_frame2.ip_ihl = 5
            test_frame2.ip_length = None
            test_frame2.ip_identification = 0
            test_frame2.ip_flags = 2
            test_frame2.ip_fragment_offset = 0
            test_frame2.ip_ttl = 64
            test_frame2.ip_protocol = 0x11
            test_frame2.ip_header_checksum = None
            test_frame2.ip_source_ip = 0xc0a80164
            test_frame2.ip_dest_ip = 0xc0a80166
            test_frame2.udp_source_port = 1
            test_frame2.udp_dest_port = 2
            test_frame2.udp_length = None
            test_frame2.udp_checksum = None
            test_frame2.payload = bytearray(range(payload_len))
            test_frame2.build()

            ip_frame1 = test_frame1.build_ip()
            ip_frame2 = test_frame2.build_ip()

            ip_frame1.payload.data += bytearray(b'\x00')

            for wait in wait_normal, wait_pause_source, wait_pause_sink:
                source.send(ip_frame1)
                source.send(ip_frame2)
                yield clk.posedge
                yield clk.posedge

                yield wait()

                yield clk.posedge
                yield clk.posedge
                yield clk.posedge

                rx_frame = sink.recv()

                assert rx_frame == test_frame1

                rx_frame = sink.recv()

                assert rx_frame == test_frame2

                assert sink.empty()

                yield delay(100)

            yield clk.posedge
            print("test 5: trailing bytes (10), length %d" % payload_len)
            current_test.next = 5

            test_frame1 = udp_ep.UDPFrame()
            test_frame1.eth_dest_mac = 0xDAD1D2D3D4D5
            test_frame1.eth_src_mac = 0x5A5152535455
            test_frame1.eth_type = 0x0800
            test_frame1.ip_version = 4
            test_frame1.ip_ihl = 5
            test_frame1.ip_length = None
            test_frame1.ip_identification = 0
            test_frame1.ip_flags = 2
            test_frame1.ip_fragment_offset = 0
            test_frame1.ip_ttl = 64
            test_frame1.ip_protocol = 0x11
            test_frame1.ip_header_checksum = None
            test_frame1.ip_source_ip = 0xc0a80164
            test_frame1.ip_dest_ip = 0xc0a80165
            test_frame1.udp_source_port = 1
            test_frame1.udp_dest_port = 2
            test_frame1.udp_length = None
            test_frame1.udp_checksum = None
            test_frame1.payload = bytearray(range(payload_len))
            test_frame1.build()
            test_frame2 = udp_ep.UDPFrame()
            test_frame2.eth_dest_mac = 0xDAD1D2D3D4D5
            test_frame2.eth_src_mac = 0x5A5152535455
            test_frame2.eth_type = 0x0800
            test_frame2.ip_version = 4
            test_frame2.ip_ihl = 5
            test_frame2.ip_length = None
            test_frame2.ip_identification = 0
            test_frame2.ip_flags = 2
            test_frame2.ip_fragment_offset = 0
            test_frame2.ip_ttl = 64
            test_frame2.ip_protocol = 0x11
            test_frame2.ip_header_checksum = None
            test_frame2.ip_source_ip = 0xc0a80164
            test_frame2.ip_dest_ip = 0xc0a80166
            test_frame2.udp_source_port = 1
            test_frame2.udp_dest_port = 2
            test_frame2.udp_length = None
            test_frame2.udp_checksum = None
            test_frame2.payload = bytearray(range(payload_len))
            test_frame2.build()

            ip_frame1 = test_frame1.build_ip()
            ip_frame2 = test_frame2.build_ip()

            ip_frame1.payload.data += bytearray(b'\x00' * 10)

            for wait in wait_normal, wait_pause_source, wait_pause_sink:
                source.send(ip_frame1)
                source.send(ip_frame2)
                yield clk.posedge
                yield clk.posedge

                yield wait()

                yield clk.posedge
                yield clk.posedge
                yield clk.posedge

                rx_frame = sink.recv()

                assert rx_frame == test_frame1

                rx_frame = sink.recv()

                assert rx_frame == test_frame2

                assert sink.empty()

                yield delay(100)

            yield clk.posedge
            print("test 6: trailing bytes with tuser assert (1), length %d" %
                  payload_len)
            current_test.next = 6

            test_frame1 = udp_ep.UDPFrame()
            test_frame1.eth_dest_mac = 0xDAD1D2D3D4D5
            test_frame1.eth_src_mac = 0x5A5152535455
            test_frame1.eth_type = 0x0800
            test_frame1.ip_version = 4
            test_frame1.ip_ihl = 5
            test_frame1.ip_length = None
            test_frame1.ip_identification = 0
            test_frame1.ip_flags = 2
            test_frame1.ip_fragment_offset = 0
            test_frame1.ip_ttl = 64
            test_frame1.ip_protocol = 0x11
            test_frame1.ip_header_checksum = None
            test_frame1.ip_source_ip = 0xc0a80164
            test_frame1.ip_dest_ip = 0xc0a80165
            test_frame1.udp_source_port = 1
            test_frame1.udp_dest_port = 2
            test_frame1.udp_length = None
            test_frame1.udp_checksum = None
            test_frame1.payload = bytearray(range(payload_len))
            test_frame1.build()
            test_frame2 = udp_ep.UDPFrame()
            test_frame2.eth_dest_mac = 0xDAD1D2D3D4D5
            test_frame2.eth_src_mac = 0x5A5152535455
            test_frame2.eth_type = 0x0800
            test_frame2.ip_version = 4
            test_frame2.ip_ihl = 5
            test_frame2.ip_length = None
            test_frame2.ip_identification = 0
            test_frame2.ip_flags = 2
            test_frame2.ip_fragment_offset = 0
            test_frame2.ip_ttl = 64
            test_frame2.ip_protocol = 0x11
            test_frame2.ip_header_checksum = None
            test_frame2.ip_source_ip = 0xc0a80164
            test_frame2.ip_dest_ip = 0xc0a80166
            test_frame2.udp_source_port = 1
            test_frame2.udp_dest_port = 2
            test_frame2.udp_length = None
            test_frame2.udp_checksum = None
            test_frame2.payload = bytearray(range(payload_len))
            test_frame2.build()

            ip_frame1 = test_frame1.build_ip()
            ip_frame2 = test_frame2.build_ip()

            ip_frame1.payload.data += bytearray(b'\x00')
            ip_frame1.payload.user = 1

            for wait in wait_normal, wait_pause_source, wait_pause_sink:
                source.send(ip_frame1)
                source.send(ip_frame2)
                yield clk.posedge
                yield clk.posedge

                yield wait()

                yield clk.posedge
                yield clk.posedge
                yield clk.posedge

                rx_frame = sink.recv()

                assert rx_frame == test_frame1
                assert rx_frame.payload.user[-1]

                rx_frame = sink.recv()

                assert rx_frame == test_frame2

                assert sink.empty()

                yield delay(100)

            yield clk.posedge
            print("test 7: trailing bytes with tuser assert (10), length %d" %
                  payload_len)
            current_test.next = 7

            test_frame1 = udp_ep.UDPFrame()
            test_frame1.eth_dest_mac = 0xDAD1D2D3D4D5
            test_frame1.eth_src_mac = 0x5A5152535455
            test_frame1.eth_type = 0x0800
            test_frame1.ip_version = 4
            test_frame1.ip_ihl = 5
            test_frame1.ip_length = None
            test_frame1.ip_identification = 0
            test_frame1.ip_flags = 2
            test_frame1.ip_fragment_offset = 0
            test_frame1.ip_ttl = 64
            test_frame1.ip_protocol = 0x11
            test_frame1.ip_header_checksum = None
            test_frame1.ip_source_ip = 0xc0a80164
            test_frame1.ip_dest_ip = 0xc0a80165
            test_frame1.udp_source_port = 1
            test_frame1.udp_dest_port = 2
            test_frame1.udp_length = None
            test_frame1.udp_checksum = None
            test_frame1.payload = bytearray(range(payload_len))
            test_frame1.build()
            test_frame2 = udp_ep.UDPFrame()
            test_frame2.eth_dest_mac = 0xDAD1D2D3D4D5
            test_frame2.eth_src_mac = 0x5A5152535455
            test_frame2.eth_type = 0x0800
            test_frame2.ip_version = 4
            test_frame2.ip_ihl = 5
            test_frame2.ip_length = None
            test_frame2.ip_identification = 0
            test_frame2.ip_flags = 2
            test_frame2.ip_fragment_offset = 0
            test_frame2.ip_ttl = 64
            test_frame2.ip_protocol = 0x11
            test_frame2.ip_header_checksum = None
            test_frame2.ip_source_ip = 0xc0a80164
            test_frame2.ip_dest_ip = 0xc0a80166
            test_frame2.udp_source_port = 1
            test_frame2.udp_dest_port = 2
            test_frame2.udp_length = None
            test_frame2.udp_checksum = None
            test_frame2.payload = bytearray(range(payload_len))
            test_frame2.build()

            ip_frame1 = test_frame1.build_ip()
            ip_frame2 = test_frame2.build_ip()

            ip_frame1.payload.data += bytearray(b'\x00' * 10)
            ip_frame1.payload.user = 1

            for wait in wait_normal, wait_pause_source, wait_pause_sink:
                source.send(ip_frame1)
                source.send(ip_frame2)
                yield clk.posedge
                yield clk.posedge

                yield wait()

                yield clk.posedge
                yield clk.posedge
                yield clk.posedge

                rx_frame = sink.recv()

                assert rx_frame == test_frame1
                assert rx_frame.payload.user[-1]

                rx_frame = sink.recv()

                assert rx_frame == test_frame2

                assert sink.empty()

                yield delay(100)

            yield clk.posedge
            print("test 8: truncated payload (1), length %d" % payload_len)
            current_test.next = 8

            test_frame1 = udp_ep.UDPFrame()
            test_frame1.eth_dest_mac = 0xDAD1D2D3D4D5
            test_frame1.eth_src_mac = 0x5A5152535455
            test_frame1.eth_type = 0x0800
            test_frame1.ip_version = 4
            test_frame1.ip_ihl = 5
            test_frame1.ip_length = None
            test_frame1.ip_identification = 0
            test_frame1.ip_flags = 2
            test_frame1.ip_fragment_offset = 0
            test_frame1.ip_ttl = 64
            test_frame1.ip_protocol = 0x11
            test_frame1.ip_header_checksum = None
            test_frame1.ip_source_ip = 0xc0a80164
            test_frame1.ip_dest_ip = 0xc0a80165
            test_frame1.udp_source_port = 1
            test_frame1.udp_dest_port = 2
            test_frame1.udp_length = None
            test_frame1.udp_checksum = None
            test_frame1.payload = bytearray(range(payload_len + 1))
            test_frame1.build()
            test_frame2 = udp_ep.UDPFrame()
            test_frame2.eth_dest_mac = 0xDAD1D2D3D4D5
            test_frame2.eth_src_mac = 0x5A5152535455
            test_frame2.eth_type = 0x0800
            test_frame2.ip_version = 4
            test_frame2.ip_ihl = 5
            test_frame2.ip_length = None
            test_frame2.ip_identification = 0
            test_frame2.ip_flags = 2
            test_frame2.ip_fragment_offset = 0
            test_frame2.ip_ttl = 64
            test_frame2.ip_protocol = 0x11
            test_frame2.ip_header_checksum = None
            test_frame2.ip_source_ip = 0xc0a80164
            test_frame2.ip_dest_ip = 0xc0a80166
            test_frame2.udp_source_port = 1
            test_frame2.udp_dest_port = 2
            test_frame2.udp_length = None
            test_frame2.udp_checksum = None
            test_frame2.payload = bytearray(range(payload_len))
            test_frame2.build()

            ip_frame1 = test_frame1.build_ip()
            ip_frame2 = test_frame2.build_ip()

            ip_frame1.payload.data = ip_frame1.payload.data[:-1]

            for wait in wait_normal, wait_pause_source, wait_pause_sink:
                error_payload_early_termination_asserted.next = 0

                source.send(ip_frame1)
                source.send(ip_frame2)
                yield clk.posedge
                yield clk.posedge

                yield wait()

                yield clk.posedge
                yield clk.posedge
                yield clk.posedge

                rx_frame = sink.recv()

                assert rx_frame.payload.user[-1]
                assert error_payload_early_termination_asserted

                rx_frame = sink.recv()

                assert rx_frame == test_frame2

                assert sink.empty()

                yield delay(100)

            yield clk.posedge
            print("test 9: truncated payload (10), length %d" % payload_len)
            current_test.next = 9

            test_frame1 = udp_ep.UDPFrame()
            test_frame1.eth_dest_mac = 0xDAD1D2D3D4D5
            test_frame1.eth_src_mac = 0x5A5152535455
            test_frame1.eth_type = 0x0800
            test_frame1.ip_version = 4
            test_frame1.ip_ihl = 5
            test_frame1.ip_length = None
            test_frame1.ip_identification = 0
            test_frame1.ip_flags = 2
            test_frame1.ip_fragment_offset = 0
            test_frame1.ip_ttl = 64
            test_frame1.ip_protocol = 0x11
            test_frame1.ip_header_checksum = None
            test_frame1.ip_source_ip = 0xc0a80164
            test_frame1.ip_dest_ip = 0xc0a80165
            test_frame1.udp_source_port = 1
            test_frame1.udp_dest_port = 2
            test_frame1.udp_length = None
            test_frame1.udp_checksum = None
            test_frame1.payload = bytearray(range(payload_len + 10))
            test_frame1.build()
            test_frame2 = udp_ep.UDPFrame()
            test_frame2.eth_dest_mac = 0xDAD1D2D3D4D5
            test_frame2.eth_src_mac = 0x5A5152535455
            test_frame2.eth_type = 0x0800
            test_frame2.ip_version = 4
            test_frame2.ip_ihl = 5
            test_frame2.ip_length = None
            test_frame2.ip_identification = 0
            test_frame2.ip_flags = 2
            test_frame2.ip_fragment_offset = 0
            test_frame2.ip_ttl = 64
            test_frame2.ip_protocol = 0x11
            test_frame2.ip_header_checksum = None
            test_frame2.ip_source_ip = 0xc0a80164
            test_frame2.ip_dest_ip = 0xc0a80166
            test_frame2.udp_source_port = 1
            test_frame2.udp_dest_port = 2
            test_frame2.udp_length = None
            test_frame2.udp_checksum = None
            test_frame2.payload = bytearray(range(payload_len))
            test_frame2.build()

            ip_frame1 = test_frame1.build_ip()
            ip_frame2 = test_frame2.build_ip()

            ip_frame1.payload.data = ip_frame1.payload.data[:-10]

            for wait in wait_normal, wait_pause_source, wait_pause_sink:
                error_payload_early_termination_asserted.next = 0

                source.send(ip_frame1)
                source.send(ip_frame2)
                yield clk.posedge
                yield clk.posedge

                yield wait()

                yield clk.posedge
                yield clk.posedge
                yield clk.posedge

                rx_frame = sink.recv()

                assert rx_frame.payload.user[-1]
                assert error_payload_early_termination_asserted

                rx_frame = sink.recv()

                assert rx_frame == test_frame2

                assert sink.empty()

                yield delay(100)

        for length in range(1, 9):
            yield clk.posedge
            print("test 10: truncated header, length %d" % length)
            current_test.next = 10

            test_frame1 = udp_ep.UDPFrame()
            test_frame1.eth_dest_mac = 0xDAD1D2D3D4D5
            test_frame1.eth_src_mac = 0x5A5152535455
            test_frame1.eth_type = 0x0800
            test_frame1.ip_version = 4
            test_frame1.ip_ihl = 5
            test_frame1.ip_length = None
            test_frame1.ip_identification = 0
            test_frame1.ip_flags = 2
            test_frame1.ip_fragment_offset = 0
            test_frame1.ip_ttl = 64
            test_frame1.ip_protocol = 0x11
            test_frame1.ip_header_checksum = None
            test_frame1.ip_source_ip = 0xc0a80164
            test_frame1.ip_dest_ip = 0xc0a80165
            test_frame1.udp_source_port = 1
            test_frame1.udp_dest_port = 2
            test_frame1.udp_length = None
            test_frame1.udp_checksum = None
            test_frame1.payload = bytearray(range(16))
            test_frame1.build()
            test_frame2 = udp_ep.UDPFrame()
            test_frame2.eth_dest_mac = 0xDAD1D2D3D4D5
            test_frame2.eth_src_mac = 0x5A5152535455
            test_frame2.eth_type = 0x0800
            test_frame2.ip_version = 4
            test_frame2.ip_ihl = 5
            test_frame2.ip_length = None
            test_frame2.ip_identification = 0
            test_frame2.ip_flags = 2
            test_frame2.ip_fragment_offset = 0
            test_frame2.ip_ttl = 64
            test_frame2.ip_protocol = 0x11
            test_frame2.ip_header_checksum = None
            test_frame2.ip_source_ip = 0xc0a80164
            test_frame2.ip_dest_ip = 0xc0a80166
            test_frame2.udp_source_port = 1
            test_frame2.udp_dest_port = 2
            test_frame2.udp_length = None
            test_frame2.udp_checksum = None
            test_frame2.payload = bytearray(range(16))
            test_frame2.build()

            ip_frame1 = test_frame1.build_ip()
            ip_frame2 = test_frame2.build_ip()

            ip_frame1.payload.data = ip_frame1.payload.data[:length]

            for wait in wait_normal, wait_pause_source, wait_pause_sink:
                error_header_early_termination_asserted.next = 0

                source.send(ip_frame1)
                source.send(ip_frame2)
                yield clk.posedge
                yield clk.posedge

                yield wait()

                yield clk.posedge
                yield clk.posedge
                yield clk.posedge

                assert error_header_early_termination_asserted

                rx_frame = sink.recv()

                assert rx_frame == test_frame2

                assert sink.empty()

                yield delay(100)

        raise StopSimulation

    return dut, source_logic, sink_logic, clkgen, monitor, check
コード例 #6
0
def bench():

    # Parameters
    S_COUNT = 4
    DATA_WIDTH = 8
    KEEP_ENABLE = (DATA_WIDTH > 8)
    KEEP_WIDTH = (DATA_WIDTH / 8)
    ID_ENABLE = 1
    ID_WIDTH = 8
    DEST_ENABLE = 1
    DEST_WIDTH = 8
    USER_ENABLE = 1
    USER_WIDTH = 1
    ARB_TYPE = "PRIORITY"
    LSB_PRIORITY = "HIGH"

    # Inputs
    clk = Signal(bool(0))
    rst = Signal(bool(0))
    current_test = Signal(intbv(0)[8:])

    s_udp_hdr_valid_list = [Signal(bool(0)) for i in range(S_COUNT)]
    s_eth_dest_mac_list = [Signal(intbv(0)[48:]) for i in range(S_COUNT)]
    s_eth_src_mac_list = [Signal(intbv(0)[48:]) for i in range(S_COUNT)]
    s_eth_type_list = [Signal(intbv(0)[16:]) for i in range(S_COUNT)]
    s_ip_version_list = [Signal(intbv(0)[4:]) for i in range(S_COUNT)]
    s_ip_ihl_list = [Signal(intbv(0)[4:]) for i in range(S_COUNT)]
    s_ip_dscp_list = [Signal(intbv(0)[6:]) for i in range(S_COUNT)]
    s_ip_ecn_list = [Signal(intbv(0)[2:]) for i in range(S_COUNT)]
    s_ip_length_list = [Signal(intbv(0)[16:]) for i in range(S_COUNT)]
    s_ip_identification_list = [Signal(intbv(0)[16:]) for i in range(S_COUNT)]
    s_ip_flags_list = [Signal(intbv(0)[3:]) for i in range(S_COUNT)]
    s_ip_fragment_offset_list = [Signal(intbv(0)[13:]) for i in range(S_COUNT)]
    s_ip_ttl_list = [Signal(intbv(0)[8:]) for i in range(S_COUNT)]
    s_ip_protocol_list = [Signal(intbv(0)[8:]) for i in range(S_COUNT)]
    s_ip_header_checksum_list = [Signal(intbv(0)[16:]) for i in range(S_COUNT)]
    s_ip_source_ip_list = [Signal(intbv(0)[32:]) for i in range(S_COUNT)]
    s_ip_dest_ip_list = [Signal(intbv(0)[32:]) for i in range(S_COUNT)]
    s_udp_source_port_list = [Signal(intbv(0)[16:]) for i in range(S_COUNT)]
    s_udp_dest_port_list = [Signal(intbv(0)[16:]) for i in range(S_COUNT)]
    s_udp_length_list = [Signal(intbv(0)[16:]) for i in range(S_COUNT)]
    s_udp_checksum_list = [Signal(intbv(0)[16:]) for i in range(S_COUNT)]
    s_udp_payload_axis_tdata_list = [
        Signal(intbv(0)[DATA_WIDTH:]) for i in range(S_COUNT)
    ]
    s_udp_payload_axis_tkeep_list = [
        Signal(intbv(1)[KEEP_WIDTH:]) for i in range(S_COUNT)
    ]
    s_udp_payload_axis_tvalid_list = [Signal(bool(0)) for i in range(S_COUNT)]
    s_udp_payload_axis_tlast_list = [Signal(bool(0)) for i in range(S_COUNT)]
    s_udp_payload_axis_tid_list = [
        Signal(intbv(0)[ID_WIDTH:]) for i in range(S_COUNT)
    ]
    s_udp_payload_axis_tdest_list = [
        Signal(intbv(0)[DEST_WIDTH:]) for i in range(S_COUNT)
    ]
    s_udp_payload_axis_tuser_list = [
        Signal(intbv(0)[USER_WIDTH:]) for i in range(S_COUNT)
    ]

    s_udp_hdr_valid = ConcatSignal(*reversed(s_udp_hdr_valid_list))
    s_eth_dest_mac = ConcatSignal(*reversed(s_eth_dest_mac_list))
    s_eth_src_mac = ConcatSignal(*reversed(s_eth_src_mac_list))
    s_eth_type = ConcatSignal(*reversed(s_eth_type_list))
    s_ip_version = ConcatSignal(*reversed(s_ip_version_list))
    s_ip_ihl = ConcatSignal(*reversed(s_ip_ihl_list))
    s_ip_dscp = ConcatSignal(*reversed(s_ip_dscp_list))
    s_ip_ecn = ConcatSignal(*reversed(s_ip_ecn_list))
    s_ip_length = ConcatSignal(*reversed(s_ip_length_list))
    s_ip_identification = ConcatSignal(*reversed(s_ip_identification_list))
    s_ip_flags = ConcatSignal(*reversed(s_ip_flags_list))
    s_ip_fragment_offset = ConcatSignal(*reversed(s_ip_fragment_offset_list))
    s_ip_ttl = ConcatSignal(*reversed(s_ip_ttl_list))
    s_ip_protocol = ConcatSignal(*reversed(s_ip_protocol_list))
    s_ip_header_checksum = ConcatSignal(*reversed(s_ip_header_checksum_list))
    s_ip_source_ip = ConcatSignal(*reversed(s_ip_source_ip_list))
    s_ip_dest_ip = ConcatSignal(*reversed(s_ip_dest_ip_list))
    s_udp_source_port = ConcatSignal(*reversed(s_udp_source_port_list))
    s_udp_dest_port = ConcatSignal(*reversed(s_udp_dest_port_list))
    s_udp_length = ConcatSignal(*reversed(s_udp_length_list))
    s_udp_checksum = ConcatSignal(*reversed(s_udp_checksum_list))
    s_udp_payload_axis_tdata = ConcatSignal(
        *reversed(s_udp_payload_axis_tdata_list))
    s_udp_payload_axis_tkeep = ConcatSignal(
        *reversed(s_udp_payload_axis_tkeep_list))
    s_udp_payload_axis_tvalid = ConcatSignal(
        *reversed(s_udp_payload_axis_tvalid_list))
    s_udp_payload_axis_tlast = ConcatSignal(
        *reversed(s_udp_payload_axis_tlast_list))
    s_udp_payload_axis_tid = ConcatSignal(
        *reversed(s_udp_payload_axis_tid_list))
    s_udp_payload_axis_tdest = ConcatSignal(
        *reversed(s_udp_payload_axis_tdest_list))
    s_udp_payload_axis_tuser = ConcatSignal(
        *reversed(s_udp_payload_axis_tuser_list))

    m_udp_hdr_ready = Signal(bool(0))
    m_udp_payload_axis_tready = Signal(bool(0))

    # Outputs
    s_udp_hdr_ready = Signal(intbv(0)[S_COUNT:])
    s_udp_payload_axis_tready = Signal(intbv(0)[S_COUNT:])

    s_udp_hdr_ready_list = [s_udp_hdr_ready(i) for i in range(S_COUNT)]
    s_udp_payload_axis_tready_list = [
        s_udp_payload_axis_tready(i) for i in range(S_COUNT)
    ]

    m_udp_hdr_valid = Signal(bool(0))
    m_eth_dest_mac = Signal(intbv(0)[48:])
    m_eth_src_mac = Signal(intbv(0)[48:])
    m_eth_type = Signal(intbv(0)[16:])
    m_ip_version = Signal(intbv(0)[4:])
    m_ip_ihl = Signal(intbv(0)[4:])
    m_ip_dscp = Signal(intbv(0)[6:])
    m_ip_ecn = Signal(intbv(0)[2:])
    m_ip_length = Signal(intbv(0)[16:])
    m_ip_identification = Signal(intbv(0)[16:])
    m_ip_flags = Signal(intbv(0)[3:])
    m_ip_fragment_offset = Signal(intbv(0)[13:])
    m_ip_ttl = Signal(intbv(0)[8:])
    m_ip_protocol = Signal(intbv(0)[8:])
    m_ip_header_checksum = Signal(intbv(0)[16:])
    m_ip_source_ip = Signal(intbv(0)[32:])
    m_ip_dest_ip = Signal(intbv(0)[32:])
    m_udp_source_port = Signal(intbv(0)[16:])
    m_udp_dest_port = Signal(intbv(0)[16:])
    m_udp_length = Signal(intbv(0)[16:])
    m_udp_checksum = Signal(intbv(0)[16:])
    m_udp_payload_axis_tdata = Signal(intbv(0)[DATA_WIDTH:])
    m_udp_payload_axis_tkeep = Signal(intbv(1)[KEEP_WIDTH:])
    m_udp_payload_axis_tvalid = Signal(bool(0))
    m_udp_payload_axis_tlast = Signal(bool(0))
    m_udp_payload_axis_tid = Signal(intbv(0)[ID_WIDTH:])
    m_udp_payload_axis_tdest = Signal(intbv(0)[DEST_WIDTH:])
    m_udp_payload_axis_tuser = Signal(intbv(0)[USER_WIDTH:])

    # sources and sinks
    source_pause_list = []
    source_list = []
    source_logic_list = []
    sink_pause = Signal(bool(0))

    for k in range(S_COUNT):
        s = udp_ep.UDPFrameSource()
        p = Signal(bool(0))

        source_list.append(s)
        source_pause_list.append(p)

        source_logic_list.append(
            s.create_logic(
                clk,
                rst,
                udp_hdr_ready=s_udp_hdr_ready_list[k],
                udp_hdr_valid=s_udp_hdr_valid_list[k],
                eth_dest_mac=s_eth_dest_mac_list[k],
                eth_src_mac=s_eth_src_mac_list[k],
                eth_type=s_eth_type_list[k],
                ip_version=s_ip_version_list[k],
                ip_ihl=s_ip_ihl_list[k],
                ip_dscp=s_ip_dscp_list[k],
                ip_ecn=s_ip_ecn_list[k],
                ip_length=s_ip_length_list[k],
                ip_identification=s_ip_identification_list[k],
                ip_flags=s_ip_flags_list[k],
                ip_fragment_offset=s_ip_fragment_offset_list[k],
                ip_ttl=s_ip_ttl_list[k],
                ip_protocol=s_ip_protocol_list[k],
                ip_header_checksum=s_ip_header_checksum_list[k],
                ip_source_ip=s_ip_source_ip_list[k],
                ip_dest_ip=s_ip_dest_ip_list[k],
                udp_source_port=s_udp_source_port_list[k],
                udp_dest_port=s_udp_dest_port_list[k],
                udp_length=s_udp_length_list[k],
                udp_checksum=s_udp_checksum_list[k],
                udp_payload_tdata=s_udp_payload_axis_tdata_list[k],
                udp_payload_tkeep=s_udp_payload_axis_tkeep_list[k],
                udp_payload_tvalid=s_udp_payload_axis_tvalid_list[k],
                udp_payload_tready=s_udp_payload_axis_tready_list[k],
                udp_payload_tlast=s_udp_payload_axis_tlast_list[k],
                udp_payload_tuser=s_udp_payload_axis_tuser_list[k],
                pause=p,
                name='source_%d' % k))

    sink = udp_ep.UDPFrameSink()

    sink_logic = sink.create_logic(
        clk,
        rst,
        udp_hdr_ready=m_udp_hdr_ready,
        udp_hdr_valid=m_udp_hdr_valid,
        eth_dest_mac=m_eth_dest_mac,
        eth_src_mac=m_eth_src_mac,
        eth_type=m_eth_type,
        ip_version=m_ip_version,
        ip_ihl=m_ip_ihl,
        ip_dscp=m_ip_dscp,
        ip_ecn=m_ip_ecn,
        ip_length=m_ip_length,
        ip_identification=m_ip_identification,
        ip_flags=m_ip_flags,
        ip_fragment_offset=m_ip_fragment_offset,
        ip_ttl=m_ip_ttl,
        ip_protocol=m_ip_protocol,
        ip_header_checksum=m_ip_header_checksum,
        ip_source_ip=m_ip_source_ip,
        ip_dest_ip=m_ip_dest_ip,
        udp_source_port=m_udp_source_port,
        udp_dest_port=m_udp_dest_port,
        udp_length=m_udp_length,
        udp_checksum=m_udp_checksum,
        udp_payload_tdata=m_udp_payload_axis_tdata,
        udp_payload_tkeep=m_udp_payload_axis_tkeep,
        udp_payload_tvalid=m_udp_payload_axis_tvalid,
        udp_payload_tready=m_udp_payload_axis_tready,
        udp_payload_tlast=m_udp_payload_axis_tlast,
        udp_payload_tuser=m_udp_payload_axis_tuser,
        pause=sink_pause,
        name='sink')

    # DUT
    if os.system(build_cmd):
        raise Exception("Error running build command")

    dut = Cosimulation("vvp -m myhdl %s.vvp -lxt2" % testbench,
                       clk=clk,
                       rst=rst,
                       current_test=current_test,
                       s_udp_hdr_valid=s_udp_hdr_valid,
                       s_udp_hdr_ready=s_udp_hdr_ready,
                       s_eth_dest_mac=s_eth_dest_mac,
                       s_eth_src_mac=s_eth_src_mac,
                       s_eth_type=s_eth_type,
                       s_ip_version=s_ip_version,
                       s_ip_ihl=s_ip_ihl,
                       s_ip_dscp=s_ip_dscp,
                       s_ip_ecn=s_ip_ecn,
                       s_ip_length=s_ip_length,
                       s_ip_identification=s_ip_identification,
                       s_ip_flags=s_ip_flags,
                       s_ip_fragment_offset=s_ip_fragment_offset,
                       s_ip_ttl=s_ip_ttl,
                       s_ip_protocol=s_ip_protocol,
                       s_ip_header_checksum=s_ip_header_checksum,
                       s_ip_source_ip=s_ip_source_ip,
                       s_ip_dest_ip=s_ip_dest_ip,
                       s_udp_source_port=s_udp_source_port,
                       s_udp_dest_port=s_udp_dest_port,
                       s_udp_length=s_udp_length,
                       s_udp_checksum=s_udp_checksum,
                       s_udp_payload_axis_tdata=s_udp_payload_axis_tdata,
                       s_udp_payload_axis_tkeep=s_udp_payload_axis_tkeep,
                       s_udp_payload_axis_tvalid=s_udp_payload_axis_tvalid,
                       s_udp_payload_axis_tready=s_udp_payload_axis_tready,
                       s_udp_payload_axis_tlast=s_udp_payload_axis_tlast,
                       s_udp_payload_axis_tid=s_udp_payload_axis_tid,
                       s_udp_payload_axis_tdest=s_udp_payload_axis_tdest,
                       s_udp_payload_axis_tuser=s_udp_payload_axis_tuser,
                       m_udp_hdr_valid=m_udp_hdr_valid,
                       m_udp_hdr_ready=m_udp_hdr_ready,
                       m_eth_dest_mac=m_eth_dest_mac,
                       m_eth_src_mac=m_eth_src_mac,
                       m_eth_type=m_eth_type,
                       m_ip_version=m_ip_version,
                       m_ip_ihl=m_ip_ihl,
                       m_ip_dscp=m_ip_dscp,
                       m_ip_ecn=m_ip_ecn,
                       m_ip_length=m_ip_length,
                       m_ip_identification=m_ip_identification,
                       m_ip_flags=m_ip_flags,
                       m_ip_fragment_offset=m_ip_fragment_offset,
                       m_ip_ttl=m_ip_ttl,
                       m_ip_protocol=m_ip_protocol,
                       m_ip_header_checksum=m_ip_header_checksum,
                       m_ip_source_ip=m_ip_source_ip,
                       m_ip_dest_ip=m_ip_dest_ip,
                       m_udp_source_port=m_udp_source_port,
                       m_udp_dest_port=m_udp_dest_port,
                       m_udp_length=m_udp_length,
                       m_udp_checksum=m_udp_checksum,
                       m_udp_payload_axis_tdata=m_udp_payload_axis_tdata,
                       m_udp_payload_axis_tkeep=m_udp_payload_axis_tkeep,
                       m_udp_payload_axis_tvalid=m_udp_payload_axis_tvalid,
                       m_udp_payload_axis_tready=m_udp_payload_axis_tready,
                       m_udp_payload_axis_tlast=m_udp_payload_axis_tlast,
                       m_udp_payload_axis_tid=m_udp_payload_axis_tid,
                       m_udp_payload_axis_tdest=m_udp_payload_axis_tdest,
                       m_udp_payload_axis_tuser=m_udp_payload_axis_tuser)

    @always(delay(4))
    def clkgen():
        clk.next = not clk

    @instance
    def check():
        yield delay(100)
        yield clk.posedge
        rst.next = 1
        yield clk.posedge
        rst.next = 0
        yield clk.posedge
        yield delay(100)
        yield clk.posedge

        yield clk.posedge

        yield clk.posedge
        print("test 1: port 0")
        current_test.next = 1

        test_frame = udp_ep.UDPFrame()
        test_frame.eth_dest_mac = 0xDAD1D2D3D4D5
        test_frame.eth_src_mac = 0x5A5152535455
        test_frame.eth_type = 0x8000
        test_frame.ip_version = 4
        test_frame.ip_ihl = 5
        test_frame.ip_dscp = 0
        test_frame.ip_ecn = 0
        test_frame.ip_length = None
        test_frame.ip_identification = 0
        test_frame.ip_flags = 2
        test_frame.ip_fragment_offset = 0
        test_frame.ip_ttl = 64
        test_frame.ip_protocol = 0x11
        test_frame.ip_header_checksum = None
        test_frame.ip_source_ip = 0xc0a80165
        test_frame.ip_dest_ip = 0xc0a80164
        test_frame.udp_source_port = 1
        test_frame.udp_dest_port = 2
        test_frame.udp_length = None
        test_frame.udp_checksum = None
        test_frame.payload = bytearray(range(32))
        test_frame.build()

        source_list[0].send(test_frame)

        yield sink.wait()
        rx_frame = sink.recv()

        assert rx_frame == test_frame

        yield delay(100)

        yield clk.posedge
        print("test 2: port 1")
        current_test.next = 2

        test_frame = udp_ep.UDPFrame()
        test_frame.eth_dest_mac = 0xDAD1D2D3D4D5
        test_frame.eth_src_mac = 0x5A5152535455
        test_frame.eth_type = 0x8000
        test_frame.ip_version = 4
        test_frame.ip_ihl = 5
        test_frame.ip_dscp = 0
        test_frame.ip_ecn = 0
        test_frame.ip_length = None
        test_frame.ip_identification = 0
        test_frame.ip_flags = 2
        test_frame.ip_fragment_offset = 0
        test_frame.ip_ttl = 64
        test_frame.ip_protocol = 0x11
        test_frame.ip_header_checksum = None
        test_frame.ip_source_ip = 0xc0a80165
        test_frame.ip_dest_ip = 0xc0a80164
        test_frame.udp_source_port = 1
        test_frame.udp_dest_port = 2
        test_frame.udp_length = None
        test_frame.udp_checksum = None
        test_frame.payload = bytearray(range(32))
        test_frame.build()

        source_list[1].send(test_frame)

        yield sink.wait()
        rx_frame = sink.recv()

        assert rx_frame == test_frame

        yield delay(100)

        yield clk.posedge
        print("test 3: back-to-back packets, same port")
        current_test.next = 3

        test_frame1 = udp_ep.UDPFrame()
        test_frame1.eth_dest_mac = 0xDAD1D2D3D4D5
        test_frame1.eth_src_mac = 0x5A5152535455
        test_frame1.eth_type = 0x8000
        test_frame1.ip_version = 4
        test_frame1.ip_ihl = 5
        test_frame1.ip_dscp = 0
        test_frame1.ip_ecn = 0
        test_frame1.ip_length = None
        test_frame1.ip_identification = 0
        test_frame1.ip_flags = 2
        test_frame1.ip_fragment_offset = 0
        test_frame1.ip_ttl = 64
        test_frame1.ip_protocol = 0x11
        test_frame1.ip_header_checksum = None
        test_frame1.ip_source_ip = 0xc0a80165
        test_frame1.ip_dest_ip = 0xc0a80164
        test_frame1.udp_source_port = 1
        test_frame1.udp_dest_port = 2
        test_frame1.udp_length = None
        test_frame1.udp_checksum = None
        test_frame1.payload = bytearray(range(32))
        test_frame1.build()
        test_frame2 = udp_ep.UDPFrame()
        test_frame2.eth_dest_mac = 0xDAD1D2D3D4D5
        test_frame2.eth_src_mac = 0x5A5152535455
        test_frame2.eth_type = 0x8000
        test_frame2.ip_version = 4
        test_frame2.ip_ihl = 5
        test_frame2.ip_dscp = 0
        test_frame2.ip_ecn = 0
        test_frame2.ip_length = None
        test_frame2.ip_identification = 0
        test_frame2.ip_flags = 2
        test_frame2.ip_fragment_offset = 0
        test_frame2.ip_ttl = 64
        test_frame2.ip_protocol = 0x11
        test_frame2.ip_header_checksum = None
        test_frame2.ip_source_ip = 0xc0a80165
        test_frame2.ip_dest_ip = 0xc0a80164
        test_frame2.udp_source_port = 1
        test_frame2.udp_dest_port = 2
        test_frame2.udp_length = None
        test_frame2.udp_checksum = None
        test_frame2.payload = bytearray(range(32))
        test_frame2.build()

        source_list[0].send(test_frame1)
        source_list[0].send(test_frame2)

        yield sink.wait()
        rx_frame = sink.recv()

        assert rx_frame == test_frame1

        yield sink.wait()
        rx_frame = sink.recv()

        assert rx_frame == test_frame2

        yield delay(100)

        yield clk.posedge
        print("test 4: back-to-back packets, different ports")
        current_test.next = 4

        test_frame1 = udp_ep.UDPFrame()
        test_frame1.eth_dest_mac = 0xDAD1D2D3D4D5
        test_frame1.eth_src_mac = 0x5A0152535455
        test_frame1.eth_type = 0x8000
        test_frame1.ip_version = 4
        test_frame1.ip_ihl = 5
        test_frame1.ip_dscp = 0
        test_frame1.ip_ecn = 0
        test_frame1.ip_length = None
        test_frame1.ip_identification = 0
        test_frame1.ip_flags = 2
        test_frame1.ip_fragment_offset = 0
        test_frame1.ip_ttl = 64
        test_frame1.ip_protocol = 0x11
        test_frame1.ip_header_checksum = None
        test_frame1.ip_source_ip = 0xc0a80165
        test_frame1.ip_dest_ip = 0xc0a80164
        test_frame1.udp_source_port = 1
        test_frame1.udp_dest_port = 2
        test_frame1.udp_length = None
        test_frame1.udp_checksum = None
        test_frame1.payload = bytearray(range(32))
        test_frame1.build()
        test_frame2 = udp_ep.UDPFrame()
        test_frame2.eth_dest_mac = 0xDAD1D2D3D4D5
        test_frame2.eth_src_mac = 0x5A0252535455
        test_frame2.eth_type = 0x8000
        test_frame2.ip_version = 4
        test_frame2.ip_ihl = 5
        test_frame2.ip_dscp = 0
        test_frame2.ip_ecn = 0
        test_frame2.ip_length = None
        test_frame2.ip_identification = 0
        test_frame2.ip_flags = 2
        test_frame2.ip_fragment_offset = 0
        test_frame2.ip_ttl = 64
        test_frame2.ip_protocol = 0x11
        test_frame2.ip_header_checksum = None
        test_frame2.ip_source_ip = 0xc0a80165
        test_frame2.ip_dest_ip = 0xc0a80164
        test_frame2.udp_source_port = 1
        test_frame2.udp_dest_port = 2
        test_frame2.udp_length = None
        test_frame2.udp_checksum = None
        test_frame2.payload = bytearray(range(32))
        test_frame2.build()

        source_list[1].send(test_frame1)
        source_list[2].send(test_frame2)

        yield sink.wait()
        rx_frame = sink.recv()

        assert rx_frame == test_frame1

        yield sink.wait()
        rx_frame = sink.recv()

        assert rx_frame == test_frame2

        yield delay(100)

        yield clk.posedge
        print("test 5: alterate pause source")
        current_test.next = 5

        test_frame1 = udp_ep.UDPFrame()
        test_frame1.eth_dest_mac = 0xDAD1D2D3D4D5
        test_frame1.eth_src_mac = 0x5A0152535455
        test_frame1.eth_type = 0x8000
        test_frame1.ip_version = 4
        test_frame1.ip_ihl = 5
        test_frame1.ip_dscp = 0
        test_frame1.ip_ecn = 0
        test_frame1.ip_length = None
        test_frame1.ip_identification = 0
        test_frame1.ip_flags = 2
        test_frame1.ip_fragment_offset = 0
        test_frame1.ip_ttl = 64
        test_frame1.ip_protocol = 0x11
        test_frame1.ip_header_checksum = None
        test_frame1.ip_source_ip = 0xc0a80165
        test_frame1.ip_dest_ip = 0xc0a80164
        test_frame1.udp_source_port = 1
        test_frame1.udp_dest_port = 2
        test_frame1.udp_length = None
        test_frame1.udp_checksum = None
        test_frame1.payload = bytearray(range(32))
        test_frame1.build()
        test_frame2 = udp_ep.UDPFrame()
        test_frame2.eth_dest_mac = 0xDAD1D2D3D4D5
        test_frame2.eth_src_mac = 0x5A0252535455
        test_frame2.eth_type = 0x8000
        test_frame2.ip_version = 4
        test_frame2.ip_ihl = 5
        test_frame2.ip_dscp = 0
        test_frame2.ip_ecn = 0
        test_frame2.ip_length = None
        test_frame2.ip_identification = 0
        test_frame2.ip_flags = 2
        test_frame2.ip_fragment_offset = 0
        test_frame2.ip_ttl = 64
        test_frame2.ip_protocol = 0x11
        test_frame2.ip_header_checksum = None
        test_frame2.ip_source_ip = 0xc0a80165
        test_frame2.ip_dest_ip = 0xc0a80164
        test_frame2.udp_source_port = 1
        test_frame2.udp_dest_port = 2
        test_frame2.udp_length = None
        test_frame2.udp_checksum = None
        test_frame2.payload = bytearray(range(32))
        test_frame2.build()

        source_list[1].send(test_frame1)
        source_list[2].send(test_frame2)
        yield clk.posedge
        yield clk.posedge

        while s_udp_payload_axis_tvalid:
            yield clk.posedge
            yield clk.posedge
            for k in range(S_COUNT):
                source_pause_list[k].next = False
            yield clk.posedge
            for k in range(S_COUNT):
                source_pause_list[k].next = True
            yield clk.posedge

        for k in range(S_COUNT):
            source_pause_list[k].next = False

        yield sink.wait()
        rx_frame = sink.recv()

        assert rx_frame == test_frame1

        yield sink.wait()
        rx_frame = sink.recv()

        assert rx_frame == test_frame2

        yield delay(100)

        yield clk.posedge
        print("test 6: alterate pause sink")
        current_test.next = 6

        test_frame1 = udp_ep.UDPFrame()
        test_frame1.eth_dest_mac = 0xDAD1D2D3D4D5
        test_frame1.eth_src_mac = 0x5A0152535455
        test_frame1.eth_type = 0x8000
        test_frame1.ip_version = 4
        test_frame1.ip_ihl = 5
        test_frame1.ip_dscp = 0
        test_frame1.ip_ecn = 0
        test_frame1.ip_length = None
        test_frame1.ip_identification = 0
        test_frame1.ip_flags = 2
        test_frame1.ip_fragment_offset = 0
        test_frame1.ip_ttl = 64
        test_frame1.ip_protocol = 0x11
        test_frame1.ip_header_checksum = None
        test_frame1.ip_source_ip = 0xc0a80165
        test_frame1.ip_dest_ip = 0xc0a80164
        test_frame1.udp_source_port = 1
        test_frame1.udp_dest_port = 2
        test_frame1.udp_length = None
        test_frame1.udp_checksum = None
        test_frame1.payload = bytearray(range(32))
        test_frame1.build()
        test_frame2 = udp_ep.UDPFrame()
        test_frame2.eth_dest_mac = 0xDAD1D2D3D4D5
        test_frame2.eth_src_mac = 0x5A0252535455
        test_frame2.eth_type = 0x8000
        test_frame2.ip_version = 4
        test_frame2.ip_ihl = 5
        test_frame2.ip_dscp = 0
        test_frame2.ip_ecn = 0
        test_frame2.ip_length = None
        test_frame2.ip_identification = 0
        test_frame2.ip_flags = 2
        test_frame2.ip_fragment_offset = 0
        test_frame2.ip_ttl = 64
        test_frame2.ip_protocol = 0x11
        test_frame2.ip_header_checksum = None
        test_frame2.ip_source_ip = 0xc0a80165
        test_frame2.ip_dest_ip = 0xc0a80164
        test_frame2.udp_source_port = 1
        test_frame2.udp_dest_port = 2
        test_frame2.udp_length = None
        test_frame2.udp_checksum = None
        test_frame2.payload = bytearray(range(32))
        test_frame2.build()

        source_list[1].send(test_frame1)
        source_list[2].send(test_frame2)
        yield clk.posedge
        yield clk.posedge

        while s_udp_payload_axis_tvalid:
            sink_pause.next = True
            yield clk.posedge
            yield clk.posedge
            yield clk.posedge
            sink_pause.next = False
            yield clk.posedge

        yield sink.wait()
        rx_frame = sink.recv()

        assert rx_frame == test_frame1

        yield sink.wait()
        rx_frame = sink.recv()

        assert rx_frame == test_frame2

        yield delay(100)

        yield clk.posedge
        print(
            "test 7: back-to-back packets, different ports, arbitration test")
        current_test.next = 7

        test_frame1 = udp_ep.UDPFrame()
        test_frame1.eth_dest_mac = 0xDAD1D2D3D4D5
        test_frame1.eth_src_mac = 0x5A0152535455
        test_frame1.eth_type = 0x8000
        test_frame1.ip_version = 4
        test_frame1.ip_ihl = 5
        test_frame1.ip_dscp = 0
        test_frame1.ip_ecn = 0
        test_frame1.ip_length = None
        test_frame1.ip_identification = 0
        test_frame1.ip_flags = 2
        test_frame1.ip_fragment_offset = 0
        test_frame1.ip_ttl = 64
        test_frame1.ip_protocol = 0x11
        test_frame1.ip_header_checksum = None
        test_frame1.ip_source_ip = 0xc0a80165
        test_frame1.ip_dest_ip = 0xc0a80164
        test_frame1.udp_source_port = 1
        test_frame1.udp_dest_port = 2
        test_frame1.udp_length = None
        test_frame1.udp_checksum = None
        test_frame1.payload = bytearray(range(32))
        test_frame1.build()
        test_frame2 = udp_ep.UDPFrame()
        test_frame2.eth_dest_mac = 0xDAD1D2D3D4D5
        test_frame2.eth_src_mac = 0x5A0252535455
        test_frame2.eth_type = 0x8000
        test_frame2.ip_version = 4
        test_frame2.ip_ihl = 5
        test_frame2.ip_dscp = 0
        test_frame2.ip_ecn = 0
        test_frame2.ip_length = None
        test_frame2.ip_identification = 0
        test_frame2.ip_flags = 2
        test_frame2.ip_fragment_offset = 0
        test_frame2.ip_ttl = 64
        test_frame2.ip_protocol = 0x11
        test_frame2.ip_header_checksum = None
        test_frame2.ip_source_ip = 0xc0a80165
        test_frame2.ip_dest_ip = 0xc0a80164
        test_frame2.udp_source_port = 1
        test_frame2.udp_dest_port = 2
        test_frame2.udp_length = None
        test_frame2.udp_checksum = None
        test_frame2.payload = bytearray(range(32))
        test_frame2.build()

        source_list[1].send(test_frame1)
        source_list[2].send(test_frame2)
        source_list[2].send(test_frame2)
        source_list[2].send(test_frame2)
        source_list[2].send(test_frame2)
        source_list[2].send(test_frame2)
        yield clk.posedge

        yield delay(800)
        yield clk.posedge
        source_list[1].send(test_frame1)

        yield sink.wait()
        rx_frame = sink.recv()

        assert rx_frame == test_frame1

        yield sink.wait()
        rx_frame = sink.recv()

        assert rx_frame == test_frame2

        yield sink.wait()
        rx_frame = sink.recv()

        assert rx_frame == test_frame2

        yield sink.wait()
        rx_frame = sink.recv()

        assert rx_frame == test_frame2

        yield sink.wait()
        rx_frame = sink.recv()

        assert rx_frame == test_frame1

        yield sink.wait()
        rx_frame = sink.recv()

        assert rx_frame == test_frame2

        yield delay(100)

        raise StopSimulation

    return instances()
コード例 #7
0
def bench():

    # Inputs
    clk = Signal(bool(0))
    rst = Signal(bool(0))
    current_test = Signal(intbv(0)[8:])

    s_eth_hdr_valid = Signal(bool(0))
    s_eth_dest_mac = Signal(intbv(0)[48:])
    s_eth_src_mac = Signal(intbv(0)[48:])
    s_eth_type = Signal(intbv(0)[16:])
    s_eth_payload_axis_tdata = Signal(intbv(0)[8:])
    s_eth_payload_axis_tvalid = Signal(bool(0))
    s_eth_payload_axis_tlast = Signal(bool(0))
    s_eth_payload_axis_tuser = Signal(bool(0))
    s_ip_hdr_valid = Signal(bool(0))
    s_ip_dscp = Signal(intbv(0)[6:])
    s_ip_ecn = Signal(intbv(0)[2:])
    s_ip_length = Signal(intbv(0)[16:])
    s_ip_ttl = Signal(intbv(0)[8:])
    s_ip_protocol = Signal(intbv(0)[8:])
    s_ip_source_ip = Signal(intbv(0)[32:])
    s_ip_dest_ip = Signal(intbv(0)[32:])
    s_ip_payload_axis_tdata = Signal(intbv(0)[8:])
    s_ip_payload_axis_tvalid = Signal(bool(0))
    s_ip_payload_axis_tlast = Signal(bool(0))
    s_ip_payload_axis_tuser = Signal(bool(0))
    s_udp_hdr_valid = Signal(bool(0))
    s_udp_ip_dscp = Signal(intbv(0)[6:])
    s_udp_ip_ecn = Signal(intbv(0)[2:])
    s_udp_ip_ttl = Signal(intbv(0)[8:])
    s_udp_ip_source_ip = Signal(intbv(0)[32:])
    s_udp_ip_dest_ip = Signal(intbv(0)[32:])
    s_udp_source_port = Signal(intbv(0)[16:])
    s_udp_dest_port = Signal(intbv(0)[16:])
    s_udp_length = Signal(intbv(0)[16:])
    s_udp_checksum = Signal(intbv(0)[16:])
    s_udp_payload_axis_tdata = Signal(intbv(0)[8:])
    s_udp_payload_axis_tvalid = Signal(bool(0))
    s_udp_payload_axis_tlast = Signal(bool(0))
    s_udp_payload_axis_tuser = Signal(bool(0))
    m_eth_payload_axis_tready = Signal(bool(0))
    m_eth_hdr_ready = Signal(bool(0))
    m_ip_hdr_ready = Signal(bool(0))
    m_ip_payload_axis_tready = Signal(bool(0))
    m_udp_hdr_ready = Signal(bool(0))
    m_udp_payload_axis_tready = Signal(bool(0))

    # Outputs
    s_eth_hdr_ready = Signal(bool(0))
    s_eth_payload_axis_tready = Signal(bool(0))
    s_ip_hdr_ready = Signal(bool(0))
    s_ip_payload_axis_tready = Signal(bool(0))
    s_udp_hdr_ready = Signal(bool(0))
    s_udp_payload_axis_tready = Signal(bool(0))
    m_eth_hdr_valid = Signal(bool(0))
    m_eth_dest_mac = Signal(intbv(0)[48:])
    m_eth_src_mac = Signal(intbv(0)[48:])
    m_eth_type = Signal(intbv(0)[16:])
    m_eth_payload_axis_tdata = Signal(intbv(0)[8:])
    m_eth_payload_axis_tvalid = Signal(bool(0))
    m_eth_payload_axis_tlast = Signal(bool(0))
    m_eth_payload_axis_tuser = Signal(bool(0))
    m_ip_hdr_valid = Signal(bool(0))
    m_ip_eth_dest_mac = Signal(intbv(0)[48:])
    m_ip_eth_src_mac = Signal(intbv(0)[48:])
    m_ip_eth_type = Signal(intbv(0)[16:])
    m_ip_version = Signal(intbv(0)[4:])
    m_ip_ihl = Signal(intbv(0)[4:])
    m_ip_dscp = Signal(intbv(0)[6:])
    m_ip_ecn = Signal(intbv(0)[2:])
    m_ip_length = Signal(intbv(0)[16:])
    m_ip_identification = Signal(intbv(0)[16:])
    m_ip_flags = Signal(intbv(0)[3:])
    m_ip_fragment_offset = Signal(intbv(0)[13:])
    m_ip_ttl = Signal(intbv(0)[8:])
    m_ip_protocol = Signal(intbv(0)[8:])
    m_ip_header_checksum = Signal(intbv(0)[16:])
    m_ip_source_ip = Signal(intbv(0)[32:])
    m_ip_dest_ip = Signal(intbv(0)[32:])
    m_ip_payload_axis_tdata = Signal(intbv(0)[8:])
    m_ip_payload_axis_tvalid = Signal(bool(0))
    m_ip_payload_axis_tlast = Signal(bool(0))
    m_ip_payload_axis_tuser = Signal(bool(0))
    m_udp_hdr_valid = Signal(bool(0))
    m_udp_eth_dest_mac = Signal(intbv(0)[48:])
    m_udp_eth_src_mac = Signal(intbv(0)[48:])
    m_udp_eth_type = Signal(intbv(0)[16:])
    m_udp_ip_version = Signal(intbv(0)[4:])
    m_udp_ip_ihl = Signal(intbv(0)[4:])
    m_udp_ip_dscp = Signal(intbv(0)[6:])
    m_udp_ip_ecn = Signal(intbv(0)[2:])
    m_udp_ip_length = Signal(intbv(0)[16:])
    m_udp_ip_identification = Signal(intbv(0)[16:])
    m_udp_ip_flags = Signal(intbv(0)[3:])
    m_udp_ip_fragment_offset = Signal(intbv(0)[13:])
    m_udp_ip_ttl = Signal(intbv(0)[8:])
    m_udp_ip_protocol = Signal(intbv(0)[8:])
    m_udp_ip_header_checksum = Signal(intbv(0)[16:])
    m_udp_ip_source_ip = Signal(intbv(0)[32:])
    m_udp_ip_dest_ip = Signal(intbv(0)[32:])
    m_udp_source_port = Signal(intbv(0)[16:])
    m_udp_dest_port = Signal(intbv(0)[16:])
    m_udp_length = Signal(intbv(0)[16:])
    m_udp_checksum = Signal(intbv(0)[16:])
    m_udp_payload_axis_tdata = Signal(intbv(0)[8:])
    m_udp_payload_axis_tvalid = Signal(bool(0))
    m_udp_payload_axis_tlast = Signal(bool(0))
    m_udp_payload_axis_tuser = Signal(bool(0))
    ip_rx_busy = Signal(bool(0))
    ip_tx_busy = Signal(bool(0))
    udp_rx_busy = Signal(bool(0))
    udp_tx_busy = Signal(bool(0))
    ip_rx_error_header_early_termination = Signal(bool(0))
    ip_rx_error_payload_early_termination = Signal(bool(0))
    ip_rx_error_invalid_header = Signal(bool(0))
    ip_rx_error_invalid_checksum = Signal(bool(0))
    ip_tx_error_payload_early_termination = Signal(bool(0))
    ip_tx_error_arp_failed = Signal(bool(0))
    udp_rx_error_header_early_termination = Signal(bool(0))
    udp_rx_error_payload_early_termination = Signal(bool(0))
    udp_tx_error_payload_early_termination = Signal(bool(0))
    local_mac = Signal(intbv(0)[48:])
    local_ip = Signal(intbv(0)[32:])
    gateway_ip = Signal(intbv(0)[32:])
    subnet_mask = Signal(intbv(0)[32:])
    clear_arp_cache = Signal(bool(0))

    # sources and sinks
    eth_source_pause = Signal(bool(0))
    eth_sink_pause = Signal(bool(0))
    ip_source_pause = Signal(bool(0))
    ip_sink_pause = Signal(bool(0))
    udp_source_pause = Signal(bool(0))
    udp_sink_pause = Signal(bool(0))

    eth_source = eth_ep.EthFrameSource()

    eth_source_logic = eth_source.create_logic(
        clk,
        rst,
        eth_hdr_ready=s_eth_hdr_ready,
        eth_hdr_valid=s_eth_hdr_valid,
        eth_dest_mac=s_eth_dest_mac,
        eth_src_mac=s_eth_src_mac,
        eth_type=s_eth_type,
        eth_payload_tdata=s_eth_payload_axis_tdata,
        eth_payload_tvalid=s_eth_payload_axis_tvalid,
        eth_payload_tready=s_eth_payload_axis_tready,
        eth_payload_tlast=s_eth_payload_axis_tlast,
        eth_payload_tuser=s_eth_payload_axis_tuser,
        pause=eth_source_pause,
        name='eth_source')

    eth_sink = eth_ep.EthFrameSink()

    eth_sink_logic = eth_sink.create_logic(
        clk,
        rst,
        eth_hdr_ready=m_eth_hdr_ready,
        eth_hdr_valid=m_eth_hdr_valid,
        eth_dest_mac=m_eth_dest_mac,
        eth_src_mac=m_eth_src_mac,
        eth_type=m_eth_type,
        eth_payload_tdata=m_eth_payload_axis_tdata,
        eth_payload_tvalid=m_eth_payload_axis_tvalid,
        eth_payload_tready=m_eth_payload_axis_tready,
        eth_payload_tlast=m_eth_payload_axis_tlast,
        eth_payload_tuser=m_eth_payload_axis_tuser,
        pause=eth_sink_pause,
        name='eth_sink')

    ip_source = ip_ep.IPFrameSource()

    ip_source_logic = ip_source.create_logic(
        clk,
        rst,
        ip_hdr_valid=s_ip_hdr_valid,
        ip_hdr_ready=s_ip_hdr_ready,
        ip_dscp=s_ip_dscp,
        ip_ecn=s_ip_ecn,
        ip_length=s_ip_length,
        ip_ttl=s_ip_ttl,
        ip_protocol=s_ip_protocol,
        ip_source_ip=s_ip_source_ip,
        ip_dest_ip=s_ip_dest_ip,
        ip_payload_tdata=s_ip_payload_axis_tdata,
        ip_payload_tvalid=s_ip_payload_axis_tvalid,
        ip_payload_tready=s_ip_payload_axis_tready,
        ip_payload_tlast=s_ip_payload_axis_tlast,
        ip_payload_tuser=s_ip_payload_axis_tuser,
        pause=ip_source_pause,
        name='ip_source')

    ip_sink = ip_ep.IPFrameSink()

    ip_sink_logic = ip_sink.create_logic(
        clk,
        rst,
        ip_hdr_ready=m_ip_hdr_ready,
        ip_hdr_valid=m_ip_hdr_valid,
        eth_dest_mac=m_ip_eth_dest_mac,
        eth_src_mac=m_ip_eth_src_mac,
        eth_type=m_ip_eth_type,
        ip_version=m_ip_version,
        ip_ihl=m_ip_ihl,
        ip_dscp=m_ip_dscp,
        ip_ecn=m_ip_ecn,
        ip_length=m_ip_length,
        ip_identification=m_ip_identification,
        ip_flags=m_ip_flags,
        ip_fragment_offset=m_ip_fragment_offset,
        ip_ttl=m_ip_ttl,
        ip_protocol=m_ip_protocol,
        ip_header_checksum=m_ip_header_checksum,
        ip_source_ip=m_ip_source_ip,
        ip_dest_ip=m_ip_dest_ip,
        ip_payload_tdata=m_ip_payload_axis_tdata,
        ip_payload_tvalid=m_ip_payload_axis_tvalid,
        ip_payload_tready=m_ip_payload_axis_tready,
        ip_payload_tlast=m_ip_payload_axis_tlast,
        ip_payload_tuser=m_ip_payload_axis_tuser,
        pause=ip_sink_pause,
        name='ip_sink')

    udp_source = udp_ep.UDPFrameSource()

    udp_source_logic = udp_source.create_logic(
        clk,
        rst,
        udp_hdr_ready=s_udp_hdr_ready,
        udp_hdr_valid=s_udp_hdr_valid,
        ip_dscp=s_udp_ip_dscp,
        ip_ecn=s_udp_ip_ecn,
        ip_ttl=s_udp_ip_ttl,
        ip_source_ip=s_udp_ip_source_ip,
        ip_dest_ip=s_udp_ip_dest_ip,
        udp_source_port=s_udp_source_port,
        udp_dest_port=s_udp_dest_port,
        udp_length=s_udp_length,
        udp_checksum=s_udp_checksum,
        udp_payload_tdata=s_udp_payload_axis_tdata,
        udp_payload_tvalid=s_udp_payload_axis_tvalid,
        udp_payload_tready=s_udp_payload_axis_tready,
        udp_payload_tlast=s_udp_payload_axis_tlast,
        udp_payload_tuser=s_udp_payload_axis_tuser,
        pause=udp_source_pause,
        name='udp_source')

    udp_sink = udp_ep.UDPFrameSink()

    udp_sink_logic = udp_sink.create_logic(
        clk,
        rst,
        udp_hdr_ready=m_udp_hdr_ready,
        udp_hdr_valid=m_udp_hdr_valid,
        eth_dest_mac=m_udp_eth_dest_mac,
        eth_src_mac=m_udp_eth_src_mac,
        eth_type=m_udp_eth_type,
        ip_version=m_udp_ip_version,
        ip_ihl=m_udp_ip_ihl,
        ip_dscp=m_udp_ip_dscp,
        ip_ecn=m_udp_ip_ecn,
        ip_length=m_udp_ip_length,
        ip_identification=m_udp_ip_identification,
        ip_flags=m_udp_ip_flags,
        ip_fragment_offset=m_udp_ip_fragment_offset,
        ip_ttl=m_udp_ip_ttl,
        ip_protocol=m_udp_ip_protocol,
        ip_header_checksum=m_udp_ip_header_checksum,
        ip_source_ip=m_udp_ip_source_ip,
        ip_dest_ip=m_udp_ip_dest_ip,
        udp_source_port=m_udp_source_port,
        udp_dest_port=m_udp_dest_port,
        udp_length=m_udp_length,
        udp_checksum=m_udp_checksum,
        udp_payload_tdata=m_udp_payload_axis_tdata,
        udp_payload_tvalid=m_udp_payload_axis_tvalid,
        udp_payload_tready=m_udp_payload_axis_tready,
        udp_payload_tlast=m_udp_payload_axis_tlast,
        udp_payload_tuser=m_udp_payload_axis_tuser,
        pause=udp_sink_pause,
        name='udp_sink')

    # DUT
    if os.system(build_cmd):
        raise Exception("Error running build command")

    dut = Cosimulation(
        "vvp -m myhdl %s.vvp -lxt2" % testbench,
        clk=clk,
        rst=rst,
        current_test=current_test,
        s_eth_hdr_valid=s_eth_hdr_valid,
        s_eth_hdr_ready=s_eth_hdr_ready,
        s_eth_dest_mac=s_eth_dest_mac,
        s_eth_src_mac=s_eth_src_mac,
        s_eth_type=s_eth_type,
        s_eth_payload_axis_tdata=s_eth_payload_axis_tdata,
        s_eth_payload_axis_tvalid=s_eth_payload_axis_tvalid,
        s_eth_payload_axis_tready=s_eth_payload_axis_tready,
        s_eth_payload_axis_tlast=s_eth_payload_axis_tlast,
        s_eth_payload_axis_tuser=s_eth_payload_axis_tuser,
        m_eth_hdr_valid=m_eth_hdr_valid,
        m_eth_hdr_ready=m_eth_hdr_ready,
        m_eth_dest_mac=m_eth_dest_mac,
        m_eth_src_mac=m_eth_src_mac,
        m_eth_type=m_eth_type,
        m_eth_payload_axis_tdata=m_eth_payload_axis_tdata,
        m_eth_payload_axis_tvalid=m_eth_payload_axis_tvalid,
        m_eth_payload_axis_tready=m_eth_payload_axis_tready,
        m_eth_payload_axis_tlast=m_eth_payload_axis_tlast,
        m_eth_payload_axis_tuser=m_eth_payload_axis_tuser,
        s_ip_hdr_valid=s_ip_hdr_valid,
        s_ip_hdr_ready=s_ip_hdr_ready,
        s_ip_dscp=s_ip_dscp,
        s_ip_ecn=s_ip_ecn,
        s_ip_length=s_ip_length,
        s_ip_ttl=s_ip_ttl,
        s_ip_protocol=s_ip_protocol,
        s_ip_source_ip=s_ip_source_ip,
        s_ip_dest_ip=s_ip_dest_ip,
        s_ip_payload_axis_tdata=s_ip_payload_axis_tdata,
        s_ip_payload_axis_tvalid=s_ip_payload_axis_tvalid,
        s_ip_payload_axis_tready=s_ip_payload_axis_tready,
        s_ip_payload_axis_tlast=s_ip_payload_axis_tlast,
        s_ip_payload_axis_tuser=s_ip_payload_axis_tuser,
        m_ip_hdr_valid=m_ip_hdr_valid,
        m_ip_hdr_ready=m_ip_hdr_ready,
        m_ip_eth_dest_mac=m_ip_eth_dest_mac,
        m_ip_eth_src_mac=m_ip_eth_src_mac,
        m_ip_eth_type=m_ip_eth_type,
        m_ip_version=m_ip_version,
        m_ip_ihl=m_ip_ihl,
        m_ip_dscp=m_ip_dscp,
        m_ip_ecn=m_ip_ecn,
        m_ip_length=m_ip_length,
        m_ip_identification=m_ip_identification,
        m_ip_flags=m_ip_flags,
        m_ip_fragment_offset=m_ip_fragment_offset,
        m_ip_ttl=m_ip_ttl,
        m_ip_protocol=m_ip_protocol,
        m_ip_header_checksum=m_ip_header_checksum,
        m_ip_source_ip=m_ip_source_ip,
        m_ip_dest_ip=m_ip_dest_ip,
        m_ip_payload_axis_tdata=m_ip_payload_axis_tdata,
        m_ip_payload_axis_tvalid=m_ip_payload_axis_tvalid,
        m_ip_payload_axis_tready=m_ip_payload_axis_tready,
        m_ip_payload_axis_tlast=m_ip_payload_axis_tlast,
        m_ip_payload_axis_tuser=m_ip_payload_axis_tuser,
        s_udp_hdr_valid=s_udp_hdr_valid,
        s_udp_hdr_ready=s_udp_hdr_ready,
        s_udp_ip_dscp=s_udp_ip_dscp,
        s_udp_ip_ecn=s_udp_ip_ecn,
        s_udp_ip_ttl=s_udp_ip_ttl,
        s_udp_ip_source_ip=s_udp_ip_source_ip,
        s_udp_ip_dest_ip=s_udp_ip_dest_ip,
        s_udp_source_port=s_udp_source_port,
        s_udp_dest_port=s_udp_dest_port,
        s_udp_length=s_udp_length,
        s_udp_checksum=s_udp_checksum,
        s_udp_payload_axis_tdata=s_udp_payload_axis_tdata,
        s_udp_payload_axis_tvalid=s_udp_payload_axis_tvalid,
        s_udp_payload_axis_tready=s_udp_payload_axis_tready,
        s_udp_payload_axis_tlast=s_udp_payload_axis_tlast,
        s_udp_payload_axis_tuser=s_udp_payload_axis_tuser,
        m_udp_hdr_valid=m_udp_hdr_valid,
        m_udp_hdr_ready=m_udp_hdr_ready,
        m_udp_eth_dest_mac=m_udp_eth_dest_mac,
        m_udp_eth_src_mac=m_udp_eth_src_mac,
        m_udp_eth_type=m_udp_eth_type,
        m_udp_ip_version=m_udp_ip_version,
        m_udp_ip_ihl=m_udp_ip_ihl,
        m_udp_ip_dscp=m_udp_ip_dscp,
        m_udp_ip_ecn=m_udp_ip_ecn,
        m_udp_ip_length=m_udp_ip_length,
        m_udp_ip_identification=m_udp_ip_identification,
        m_udp_ip_flags=m_udp_ip_flags,
        m_udp_ip_fragment_offset=m_udp_ip_fragment_offset,
        m_udp_ip_ttl=m_udp_ip_ttl,
        m_udp_ip_protocol=m_udp_ip_protocol,
        m_udp_ip_header_checksum=m_udp_ip_header_checksum,
        m_udp_ip_source_ip=m_udp_ip_source_ip,
        m_udp_ip_dest_ip=m_udp_ip_dest_ip,
        m_udp_source_port=m_udp_source_port,
        m_udp_dest_port=m_udp_dest_port,
        m_udp_length=m_udp_length,
        m_udp_checksum=m_udp_checksum,
        m_udp_payload_axis_tdata=m_udp_payload_axis_tdata,
        m_udp_payload_axis_tvalid=m_udp_payload_axis_tvalid,
        m_udp_payload_axis_tready=m_udp_payload_axis_tready,
        m_udp_payload_axis_tlast=m_udp_payload_axis_tlast,
        m_udp_payload_axis_tuser=m_udp_payload_axis_tuser,
        ip_rx_busy=ip_rx_busy,
        ip_tx_busy=ip_tx_busy,
        udp_rx_busy=udp_rx_busy,
        udp_tx_busy=udp_tx_busy,
        ip_rx_error_header_early_termination=
        ip_rx_error_header_early_termination,
        ip_rx_error_payload_early_termination=
        ip_rx_error_payload_early_termination,
        ip_rx_error_invalid_header=ip_rx_error_invalid_header,
        ip_rx_error_invalid_checksum=ip_rx_error_invalid_checksum,
        ip_tx_error_payload_early_termination=
        ip_tx_error_payload_early_termination,
        ip_tx_error_arp_failed=ip_tx_error_arp_failed,
        udp_rx_error_header_early_termination=
        udp_rx_error_header_early_termination,
        udp_rx_error_payload_early_termination=
        udp_rx_error_payload_early_termination,
        udp_tx_error_payload_early_termination=
        udp_tx_error_payload_early_termination,
        local_mac=local_mac,
        local_ip=local_ip,
        gateway_ip=gateway_ip,
        subnet_mask=subnet_mask,
        clear_arp_cache=clear_arp_cache)

    @always(delay(4))
    def clkgen():
        clk.next = not clk

    ip_rx_error_header_early_termination_asserted = Signal(bool(0))
    ip_rx_error_payload_early_termination_asserted = Signal(bool(0))
    ip_rx_error_invalid_header_asserted = Signal(bool(0))
    ip_rx_error_invalid_checksum_asserted = Signal(bool(0))
    ip_tx_error_payload_early_termination_asserted = Signal(bool(0))
    ip_tx_error_arp_failed_asserted = Signal(bool(0))
    udp_rx_error_header_early_termination_asserted = Signal(bool(0))
    udp_rx_error_payload_early_termination_asserted = Signal(bool(0))
    udp_tx_error_payload_early_termination_asserted = Signal(bool(0))

    @always(clk.posedge)
    def monitor():
        if (ip_rx_error_header_early_termination):
            ip_rx_error_header_early_termination_asserted.next = 1
        if (ip_rx_error_payload_early_termination):
            ip_rx_error_payload_early_termination_asserted.next = 1
        if (ip_rx_error_invalid_header):
            ip_rx_error_invalid_header_asserted.next = 1
        if (ip_rx_error_invalid_checksum):
            ip_rx_error_invalid_checksum_asserted.next = 1
        if (ip_tx_error_payload_early_termination):
            ip_tx_error_payload_early_termination_asserted.next = 1
        if (ip_tx_error_arp_failed):
            ip_tx_error_arp_failed_asserted.next = 1
        if (udp_rx_error_header_early_termination):
            udp_rx_error_header_early_termination_asserted.next = 1
        if (udp_rx_error_payload_early_termination):
            udp_rx_error_payload_early_termination_asserted.next = 1
        if (udp_tx_error_payload_early_termination):
            udp_tx_error_payload_early_termination_asserted.next = 1

    def wait_normal():
        i = 20
        while i > 0:
            i = max(0, i - 1)
            if (s_eth_payload_axis_tvalid or s_ip_payload_axis_tvalid
                    or s_udp_payload_axis_tvalid or m_eth_payload_axis_tvalid
                    or m_ip_payload_axis_tvalid or m_udp_payload_axis_tvalid
                    or s_eth_hdr_valid or s_ip_hdr_valid or s_udp_hdr_valid):
                i = 20
            yield clk.posedge

    @instance
    def check():
        yield delay(100)
        yield clk.posedge
        rst.next = 1
        yield clk.posedge
        rst.next = 0
        yield clk.posedge
        yield delay(100)
        yield clk.posedge

        # set MAC and IP address
        local_mac.next = 0x5A5152535455
        local_ip.next = 0xc0a80164
        gateway_ip.next = 0xc0a80101
        subnet_mask.next = 0xffffff00

        yield clk.posedge
        print("test 1: test IP RX packet")
        current_test.next = 1

        test_frame = ip_ep.IPFrame()
        test_frame.eth_dest_mac = 0x5A5152535455
        test_frame.eth_src_mac = 0xDAD1D2D3D4D5
        test_frame.eth_type = 0x0800
        test_frame.ip_version = 4
        test_frame.ip_ihl = 5
        test_frame.ip_dscp = 0
        test_frame.ip_ecn = 0
        test_frame.ip_length = None
        test_frame.ip_identification = 0
        test_frame.ip_flags = 2
        test_frame.ip_fragment_offset = 0
        test_frame.ip_ttl = 64
        test_frame.ip_protocol = 0x10
        test_frame.ip_header_checksum = None
        test_frame.ip_source_ip = 0xc0a80165
        test_frame.ip_dest_ip = 0xc0a80164
        test_frame.payload = bytearray(range(32))
        test_frame.build()
        eth_frame = test_frame.build_eth()

        eth_source.send(eth_frame)

        yield ip_sink.wait()
        rx_frame = ip_sink.recv()

        assert rx_frame == test_frame

        assert eth_source.empty()
        assert eth_sink.empty()
        assert ip_source.empty()
        assert ip_sink.empty()

        yield delay(100)

        yield clk.posedge
        print("test 2: test IP TX packet")
        current_test.next = 2

        # send IP packet
        test_frame = ip_ep.IPFrame()
        test_frame.eth_dest_mac = 0xDAD1D2D3D4D5
        test_frame.eth_src_mac = 0x5A5152535455
        test_frame.eth_type = 0x0800
        test_frame.ip_version = 4
        test_frame.ip_ihl = 5
        test_frame.ip_dscp = 0
        test_frame.ip_ecn = 0
        test_frame.ip_length = None
        test_frame.ip_identification = 0
        test_frame.ip_flags = 2
        test_frame.ip_fragment_offset = 0
        test_frame.ip_ttl = 64
        test_frame.ip_protocol = 0x10
        test_frame.ip_header_checksum = None
        test_frame.ip_source_ip = 0xc0a80164
        test_frame.ip_dest_ip = 0xc0a80166
        test_frame.payload = bytearray(range(32))
        test_frame.build()

        ip_source.send(test_frame)

        # wait for ARP request packet
        yield eth_sink.wait()
        rx_frame = eth_sink.recv()
        check_frame = arp_ep.ARPFrame()
        check_frame.parse_eth(rx_frame)

        assert check_frame.eth_dest_mac == 0xFFFFFFFFFFFF
        assert check_frame.eth_src_mac == 0x5A5152535455
        assert check_frame.eth_type == 0x0806
        assert check_frame.arp_htype == 0x0001
        assert check_frame.arp_ptype == 0x0800
        assert check_frame.arp_hlen == 6
        assert check_frame.arp_plen == 4
        assert check_frame.arp_oper == 1
        assert check_frame.arp_sha == 0x5A5152535455
        assert check_frame.arp_spa == 0xc0a80164
        assert check_frame.arp_tha == 0x000000000000
        assert check_frame.arp_tpa == 0xc0a80166

        # generate response
        arp_frame = arp_ep.ARPFrame()
        arp_frame.eth_dest_mac = 0x5A5152535455
        arp_frame.eth_src_mac = 0xDAD1D2D3D4D5
        arp_frame.eth_type = 0x0806
        arp_frame.arp_htype = 0x0001
        arp_frame.arp_ptype = 0x0800
        arp_frame.arp_hlen = 6
        arp_frame.arp_plen = 4
        arp_frame.arp_oper = 2
        arp_frame.arp_sha = 0xDAD1D2D3D4D5
        arp_frame.arp_spa = 0xc0a80166
        arp_frame.arp_tha = 0x5A5152535455
        arp_frame.arp_tpa = 0xc0a80164
        eth_source.send(arp_frame.build_eth())

        yield eth_sink.wait()
        rx_frame = eth_sink.recv()

        check_frame = ip_ep.IPFrame()
        check_frame.parse_eth(rx_frame)

        print(test_frame)
        print(check_frame)

        assert check_frame == test_frame

        assert eth_source.empty()
        assert eth_sink.empty()
        assert ip_source.empty()
        assert ip_sink.empty()

        yield delay(100)

        yield clk.posedge
        print("test 3: test IP TX arp fail packet")
        current_test.next = 2

        ip_tx_error_arp_failed_asserted.next = 0

        test_frame = ip_ep.IPFrame()
        test_frame.eth_dest_mac = 0xDAD1D2D3D4D5
        test_frame.eth_src_mac = 0x5A5152535455
        test_frame.eth_type = 0x0800
        test_frame.ip_version = 4
        test_frame.ip_ihl = 5
        test_frame.ip_dscp = 0
        test_frame.ip_ecn = 0
        test_frame.ip_length = None
        test_frame.ip_identification = 0
        test_frame.ip_flags = 2
        test_frame.ip_fragment_offset = 0
        test_frame.ip_ttl = 64
        test_frame.ip_protocol = 0x10
        test_frame.ip_header_checksum = None
        test_frame.ip_source_ip = 0xc0a80164
        test_frame.ip_dest_ip = 0xc0a80167
        test_frame.payload = bytearray(range(32))
        test_frame.build()

        ip_source.send(test_frame)

        yield clk.posedge
        yield clk.posedge

        yield wait_normal()

        yield clk.posedge
        yield clk.posedge

        assert ip_tx_error_arp_failed_asserted

        # check for 4 ARP requests
        assert eth_sink.count() == 4

        while not eth_sink.empty():
            rx_frame = eth_sink.recv()

            check_frame = arp_ep.ARPFrame()
            check_frame.parse_eth(rx_frame)

            assert check_frame.eth_dest_mac == 0xFFFFFFFFFFFF
            assert check_frame.eth_src_mac == 0x5A5152535455
            assert check_frame.eth_type == 0x0806
            assert check_frame.arp_htype == 0x0001
            assert check_frame.arp_ptype == 0x0800
            assert check_frame.arp_hlen == 6
            assert check_frame.arp_plen == 4
            assert check_frame.arp_oper == 1
            assert check_frame.arp_sha == 0x5A5152535455
            assert check_frame.arp_spa == 0xc0a80164
            assert check_frame.arp_tha == 0x000000000000
            assert check_frame.arp_tpa == 0xc0a80167

        assert eth_source.empty()
        assert eth_sink.empty()
        assert ip_source.empty()
        assert ip_sink.empty()

        yield delay(100)

        yield clk.posedge
        print("test 4: test UDP RX packet")
        current_test.next = 4

        test_frame = udp_ep.UDPFrame()
        test_frame.eth_dest_mac = 0x5A5152535455
        test_frame.eth_src_mac = 0xDAD1D2D3D4D5
        test_frame.eth_type = 0x0800
        test_frame.ip_version = 4
        test_frame.ip_ihl = 5
        test_frame.ip_dscp = 0
        test_frame.ip_ecn = 0
        test_frame.ip_length = None
        test_frame.ip_identification = 0
        test_frame.ip_flags = 2
        test_frame.ip_fragment_offset = 0
        test_frame.ip_ttl = 64
        test_frame.ip_protocol = 0x11
        test_frame.ip_header_checksum = None
        test_frame.ip_source_ip = 0xc0a80165
        test_frame.ip_dest_ip = 0xc0a80164
        test_frame.udp_source_port = 1234
        test_frame.udp_dest_port = 5678
        test_frame.payload = bytearray(range(32))
        test_frame.build()
        eth_frame = test_frame.build_eth()

        eth_source.send(eth_frame)

        yield udp_sink.wait()
        rx_frame = udp_sink.recv()

        assert rx_frame == test_frame

        assert eth_source.empty()
        assert eth_sink.empty()
        assert udp_source.empty()
        assert udp_sink.empty()

        yield delay(100)

        yield clk.posedge
        print("test 5: test UDP TX packet")
        current_test.next = 5

        test_frame = udp_ep.UDPFrame()
        test_frame.eth_dest_mac = 0xDAD1D2D3D4D5
        test_frame.eth_src_mac = 0x5A5152535455
        test_frame.eth_type = 0x0800
        test_frame.ip_version = 4
        test_frame.ip_ihl = 5
        test_frame.ip_dscp = 0
        test_frame.ip_ecn = 0
        test_frame.ip_length = None
        test_frame.ip_identification = 0
        test_frame.ip_flags = 2
        test_frame.ip_fragment_offset = 0
        test_frame.ip_ttl = 64
        test_frame.ip_protocol = 0x11
        test_frame.ip_header_checksum = None
        test_frame.ip_source_ip = 0xc0a80164
        test_frame.ip_dest_ip = 0xc0a80166
        test_frame.udp_source_port = 1234
        test_frame.udp_dest_port = 5678
        test_frame.payload = bytearray(range(32))
        test_frame.build()

        udp_source.send(test_frame)

        yield eth_sink.wait()
        rx_frame = eth_sink.recv()

        check_frame = udp_ep.UDPFrame()
        check_frame.parse_eth(rx_frame)

        assert check_frame == test_frame

        assert eth_source.empty()
        assert eth_sink.empty()
        assert udp_source.empty()
        assert udp_sink.empty()

        yield delay(100)

        raise StopSimulation

    return instances()
コード例 #8
0
ファイル: test_udp_64.py プロジェクト: riple/verilog-ethernet
def bench():

    # Inputs
    clk = Signal(bool(0))
    rst = Signal(bool(0))
    current_test = Signal(intbv(0)[8:])

    input_ip_hdr_valid = Signal(bool(0))
    input_ip_eth_dest_mac = Signal(intbv(0)[48:])
    input_ip_eth_src_mac = Signal(intbv(0)[48:])
    input_ip_eth_type = Signal(intbv(0)[16:])
    input_ip_version = Signal(intbv(0)[4:])
    input_ip_ihl = Signal(intbv(0)[4:])
    input_ip_dscp = Signal(intbv(0)[6:])
    input_ip_ecn = Signal(intbv(0)[2:])
    input_ip_length = Signal(intbv(0)[16:])
    input_ip_identification = Signal(intbv(0)[16:])
    input_ip_flags = Signal(intbv(0)[3:])
    input_ip_fragment_offset = Signal(intbv(0)[13:])
    input_ip_ttl = Signal(intbv(0)[8:])
    input_ip_protocol = Signal(intbv(0)[8:])
    input_ip_header_checksum = Signal(intbv(0)[16:])
    input_ip_source_ip = Signal(intbv(0)[32:])
    input_ip_dest_ip = Signal(intbv(0)[32:])
    input_ip_payload_tdata = Signal(intbv(0)[64:])
    input_ip_payload_tkeep = Signal(intbv(0)[8:])
    input_ip_payload_tvalid = Signal(bool(0))
    input_ip_payload_tlast = Signal(bool(0))
    input_ip_payload_tuser = Signal(bool(0))
    input_udp_hdr_valid = Signal(bool(0))
    input_udp_eth_dest_mac = Signal(intbv(0)[48:])
    input_udp_eth_src_mac = Signal(intbv(0)[48:])
    input_udp_eth_type = Signal(intbv(0)[16:])
    input_udp_ip_version = Signal(intbv(0)[4:])
    input_udp_ip_ihl = Signal(intbv(0)[4:])
    input_udp_ip_dscp = Signal(intbv(0)[6:])
    input_udp_ip_ecn = Signal(intbv(0)[2:])
    input_udp_ip_identification = Signal(intbv(0)[16:])
    input_udp_ip_flags = Signal(intbv(0)[3:])
    input_udp_ip_fragment_offset = Signal(intbv(0)[13:])
    input_udp_ip_ttl = Signal(intbv(0)[8:])
    input_udp_ip_header_checksum = Signal(intbv(0)[16:])
    input_udp_ip_source_ip = Signal(intbv(0)[32:])
    input_udp_ip_dest_ip = Signal(intbv(0)[32:])
    input_udp_source_port = Signal(intbv(0)[16:])
    input_udp_dest_port = Signal(intbv(0)[16:])
    input_udp_length = Signal(intbv(0)[16:])
    input_udp_checksum = Signal(intbv(0)[16:])
    input_udp_payload_tdata = Signal(intbv(0)[64:])
    input_udp_payload_tkeep = Signal(intbv(0)[8:])
    input_udp_payload_tvalid = Signal(bool(0))
    input_udp_payload_tlast = Signal(bool(0))
    input_udp_payload_tuser = Signal(bool(0))
    output_ip_payload_tready = Signal(bool(0))
    output_ip_hdr_ready = Signal(bool(0))
    output_udp_hdr_ready = Signal(bool(0))
    output_udp_payload_tready = Signal(bool(0))

    # Outputs
    input_ip_hdr_ready = Signal(bool(0))
    input_ip_payload_tready = Signal(bool(0))
    input_udp_hdr_ready = Signal(bool(0))
    input_udp_payload_tready = Signal(bool(0))
    output_ip_hdr_valid = Signal(bool(0))
    output_ip_eth_dest_mac = Signal(intbv(0)[48:])
    output_ip_eth_src_mac = Signal(intbv(0)[48:])
    output_ip_eth_type = Signal(intbv(0)[16:])
    output_ip_version = Signal(intbv(0)[4:])
    output_ip_ihl = Signal(intbv(0)[4:])
    output_ip_dscp = Signal(intbv(0)[6:])
    output_ip_ecn = Signal(intbv(0)[2:])
    output_ip_length = Signal(intbv(0)[16:])
    output_ip_identification = Signal(intbv(0)[16:])
    output_ip_flags = Signal(intbv(0)[3:])
    output_ip_fragment_offset = Signal(intbv(0)[13:])
    output_ip_ttl = Signal(intbv(0)[8:])
    output_ip_protocol = Signal(intbv(0)[8:])
    output_ip_header_checksum = Signal(intbv(0)[16:])
    output_ip_source_ip = Signal(intbv(0)[32:])
    output_ip_dest_ip = Signal(intbv(0)[32:])
    output_ip_payload_tdata = Signal(intbv(0)[64:])
    output_ip_payload_tkeep = Signal(intbv(0)[8:])
    output_ip_payload_tvalid = Signal(bool(0))
    output_ip_payload_tlast = Signal(bool(0))
    output_ip_payload_tuser = Signal(bool(0))
    output_udp_hdr_valid = Signal(bool(0))
    output_udp_eth_dest_mac = Signal(intbv(0)[48:])
    output_udp_eth_src_mac = Signal(intbv(0)[48:])
    output_udp_eth_type = Signal(intbv(0)[16:])
    output_udp_ip_version = Signal(intbv(0)[4:])
    output_udp_ip_ihl = Signal(intbv(0)[4:])
    output_udp_ip_dscp = Signal(intbv(0)[6:])
    output_udp_ip_ecn = Signal(intbv(0)[2:])
    output_udp_ip_length = Signal(intbv(0)[16:])
    output_udp_ip_identification = Signal(intbv(0)[16:])
    output_udp_ip_flags = Signal(intbv(0)[3:])
    output_udp_ip_fragment_offset = Signal(intbv(0)[13:])
    output_udp_ip_ttl = Signal(intbv(0)[8:])
    output_udp_ip_protocol = Signal(intbv(0)[8:])
    output_udp_ip_header_checksum = Signal(intbv(0)[16:])
    output_udp_ip_source_ip = Signal(intbv(0)[32:])
    output_udp_ip_dest_ip = Signal(intbv(0)[32:])
    output_udp_source_port = Signal(intbv(0)[16:])
    output_udp_dest_port = Signal(intbv(0)[16:])
    output_udp_length = Signal(intbv(0)[16:])
    output_udp_checksum = Signal(intbv(0)[16:])
    output_udp_payload_tdata = Signal(intbv(0)[64:])
    output_udp_payload_tkeep = Signal(intbv(0)[8:])
    output_udp_payload_tvalid = Signal(bool(0))
    output_udp_payload_tlast = Signal(bool(0))
    output_udp_payload_tuser = Signal(bool(0))
    rx_busy = Signal(bool(0))
    tx_busy = Signal(bool(0))
    rx_error_header_early_termination = Signal(bool(0))
    rx_error_payload_early_termination = Signal(bool(0))
    tx_error_payload_early_termination = Signal(bool(0))

    # sources and sinks
    ip_source_queue = Queue()
    ip_source_pause = Signal(bool(0))
    ip_sink_queue = Queue()
    ip_sink_pause = Signal(bool(0))
    udp_source_queue = Queue()
    udp_source_pause = Signal(bool(0))
    udp_sink_queue = Queue()
    udp_sink_pause = Signal(bool(0))

    ip_source = ip_ep.IPFrameSource(
        clk,
        rst,
        ip_hdr_valid=input_ip_hdr_valid,
        ip_hdr_ready=input_ip_hdr_ready,
        eth_dest_mac=input_ip_eth_dest_mac,
        eth_src_mac=input_ip_eth_src_mac,
        eth_type=input_ip_eth_type,
        ip_version=input_ip_version,
        ip_ihl=input_ip_ihl,
        ip_dscp=input_ip_dscp,
        ip_ecn=input_ip_ecn,
        ip_length=input_ip_length,
        ip_identification=input_ip_identification,
        ip_flags=input_ip_flags,
        ip_fragment_offset=input_ip_fragment_offset,
        ip_ttl=input_ip_ttl,
        ip_protocol=input_ip_protocol,
        ip_header_checksum=input_ip_header_checksum,
        ip_source_ip=input_ip_source_ip,
        ip_dest_ip=input_ip_dest_ip,
        ip_payload_tdata=input_ip_payload_tdata,
        ip_payload_tkeep=input_ip_payload_tkeep,
        ip_payload_tvalid=input_ip_payload_tvalid,
        ip_payload_tready=input_ip_payload_tready,
        ip_payload_tlast=input_ip_payload_tlast,
        ip_payload_tuser=input_ip_payload_tuser,
        fifo=ip_source_queue,
        pause=ip_source_pause,
        name='ip_source')

    ip_sink = ip_ep.IPFrameSink(clk,
                                rst,
                                ip_hdr_ready=output_ip_hdr_ready,
                                ip_hdr_valid=output_ip_hdr_valid,
                                eth_dest_mac=output_ip_eth_dest_mac,
                                eth_src_mac=output_ip_eth_src_mac,
                                eth_type=output_ip_eth_type,
                                ip_version=output_ip_version,
                                ip_ihl=output_ip_ihl,
                                ip_dscp=output_ip_dscp,
                                ip_ecn=output_ip_ecn,
                                ip_length=output_ip_length,
                                ip_identification=output_ip_identification,
                                ip_flags=output_ip_flags,
                                ip_fragment_offset=output_ip_fragment_offset,
                                ip_ttl=output_ip_ttl,
                                ip_protocol=output_ip_protocol,
                                ip_header_checksum=output_ip_header_checksum,
                                ip_source_ip=output_ip_source_ip,
                                ip_dest_ip=output_ip_dest_ip,
                                ip_payload_tdata=output_ip_payload_tdata,
                                ip_payload_tkeep=output_ip_payload_tkeep,
                                ip_payload_tvalid=output_ip_payload_tvalid,
                                ip_payload_tready=output_ip_payload_tready,
                                ip_payload_tlast=output_ip_payload_tlast,
                                ip_payload_tuser=output_ip_payload_tuser,
                                fifo=ip_sink_queue,
                                pause=ip_sink_pause,
                                name='ip_sink')

    udp_source = udp_ep.UDPFrameSource(
        clk,
        rst,
        udp_hdr_valid=input_udp_hdr_valid,
        udp_hdr_ready=input_udp_hdr_ready,
        eth_dest_mac=input_udp_eth_dest_mac,
        eth_src_mac=input_udp_eth_src_mac,
        eth_type=input_udp_eth_type,
        ip_version=input_udp_ip_version,
        ip_ihl=input_udp_ip_ihl,
        ip_dscp=input_udp_ip_dscp,
        ip_ecn=input_udp_ip_ecn,
        ip_identification=input_udp_ip_identification,
        ip_flags=input_udp_ip_flags,
        ip_fragment_offset=input_udp_ip_fragment_offset,
        ip_ttl=input_udp_ip_ttl,
        ip_header_checksum=input_udp_ip_header_checksum,
        ip_source_ip=input_udp_ip_source_ip,
        ip_dest_ip=input_udp_ip_dest_ip,
        udp_source_port=input_udp_source_port,
        udp_dest_port=input_udp_dest_port,
        udp_length=input_udp_length,
        udp_checksum=input_udp_checksum,
        udp_payload_tdata=input_udp_payload_tdata,
        udp_payload_tkeep=input_udp_payload_tkeep,
        udp_payload_tvalid=input_udp_payload_tvalid,
        udp_payload_tready=input_udp_payload_tready,
        udp_payload_tlast=input_udp_payload_tlast,
        udp_payload_tuser=input_udp_payload_tuser,
        fifo=udp_source_queue,
        pause=udp_source_pause,
        name='udp_source')

    udp_sink = udp_ep.UDPFrameSink(
        clk,
        rst,
        udp_hdr_ready=output_udp_hdr_ready,
        udp_hdr_valid=output_udp_hdr_valid,
        eth_dest_mac=output_udp_eth_dest_mac,
        eth_src_mac=output_udp_eth_src_mac,
        eth_type=output_udp_eth_type,
        ip_version=output_udp_ip_version,
        ip_ihl=output_udp_ip_ihl,
        ip_dscp=output_udp_ip_dscp,
        ip_ecn=output_udp_ip_ecn,
        ip_length=output_udp_ip_length,
        ip_identification=output_udp_ip_identification,
        ip_flags=output_udp_ip_flags,
        ip_fragment_offset=output_udp_ip_fragment_offset,
        ip_ttl=output_udp_ip_ttl,
        ip_protocol=output_udp_ip_protocol,
        ip_header_checksum=output_udp_ip_header_checksum,
        ip_source_ip=output_udp_ip_source_ip,
        ip_dest_ip=output_udp_ip_dest_ip,
        udp_source_port=output_udp_source_port,
        udp_dest_port=output_udp_dest_port,
        udp_length=output_udp_length,
        udp_checksum=output_udp_checksum,
        udp_payload_tdata=output_udp_payload_tdata,
        udp_payload_tkeep=output_udp_payload_tkeep,
        udp_payload_tvalid=output_udp_payload_tvalid,
        udp_payload_tready=output_udp_payload_tready,
        udp_payload_tlast=output_udp_payload_tlast,
        udp_payload_tuser=output_udp_payload_tuser,
        fifo=udp_sink_queue,
        pause=udp_sink_pause,
        name='udp_sink')

    # DUT
    dut = dut_udp(
        clk, rst, current_test, input_ip_hdr_valid, input_ip_hdr_ready,
        input_ip_eth_dest_mac, input_ip_eth_src_mac, input_ip_eth_type,
        input_ip_version, input_ip_ihl, input_ip_dscp, input_ip_ecn,
        input_ip_length, input_ip_identification, input_ip_flags,
        input_ip_fragment_offset, input_ip_ttl, input_ip_protocol,
        input_ip_header_checksum, input_ip_source_ip, input_ip_dest_ip,
        input_ip_payload_tdata, input_ip_payload_tkeep,
        input_ip_payload_tvalid, input_ip_payload_tready,
        input_ip_payload_tlast, input_ip_payload_tuser, output_ip_hdr_valid,
        output_ip_hdr_ready, output_ip_eth_dest_mac, output_ip_eth_src_mac,
        output_ip_eth_type, output_ip_version, output_ip_ihl, output_ip_dscp,
        output_ip_ecn, output_ip_length, output_ip_identification,
        output_ip_flags, output_ip_fragment_offset, output_ip_ttl,
        output_ip_protocol, output_ip_header_checksum, output_ip_source_ip,
        output_ip_dest_ip, output_ip_payload_tdata, output_ip_payload_tkeep,
        output_ip_payload_tvalid, output_ip_payload_tready,
        output_ip_payload_tlast, output_ip_payload_tuser, input_udp_hdr_valid,
        input_udp_hdr_ready, input_udp_eth_dest_mac, input_udp_eth_src_mac,
        input_udp_eth_type, input_udp_ip_version, input_udp_ip_ihl,
        input_udp_ip_dscp, input_udp_ip_ecn, input_udp_ip_identification,
        input_udp_ip_flags, input_udp_ip_fragment_offset, input_udp_ip_ttl,
        input_udp_ip_header_checksum, input_udp_ip_source_ip,
        input_udp_ip_dest_ip, input_udp_source_port, input_udp_dest_port,
        input_udp_length, input_udp_checksum, input_udp_payload_tdata,
        input_udp_payload_tkeep, input_udp_payload_tvalid,
        input_udp_payload_tready, input_udp_payload_tlast,
        input_udp_payload_tuser, output_udp_hdr_valid, output_udp_hdr_ready,
        output_udp_eth_dest_mac, output_udp_eth_src_mac, output_udp_eth_type,
        output_udp_ip_version, output_udp_ip_ihl, output_udp_ip_dscp,
        output_udp_ip_ecn, output_udp_ip_length, output_udp_ip_identification,
        output_udp_ip_flags, output_udp_ip_fragment_offset, output_udp_ip_ttl,
        output_udp_ip_protocol, output_udp_ip_header_checksum,
        output_udp_ip_source_ip, output_udp_ip_dest_ip, output_udp_source_port,
        output_udp_dest_port, output_udp_length, output_udp_checksum,
        output_udp_payload_tdata, output_udp_payload_tkeep,
        output_udp_payload_tvalid, output_udp_payload_tready,
        output_udp_payload_tlast, output_udp_payload_tuser, rx_busy, tx_busy,
        rx_error_header_early_termination, rx_error_payload_early_termination,
        tx_error_payload_early_termination)

    @always(delay(4))
    def clkgen():
        clk.next = not clk

    rx_error_header_early_termination_asserted = Signal(bool(0))
    rx_error_payload_early_termination_asserted = Signal(bool(0))
    tx_error_payload_early_termination_asserted = Signal(bool(0))

    @always(clk.posedge)
    def monitor():
        if (rx_error_header_early_termination):
            rx_error_header_early_termination_asserted.next = 1
        if (rx_error_payload_early_termination):
            rx_error_payload_early_termination_asserted.next = 1
        if (tx_error_payload_early_termination):
            tx_error_payload_early_termination_asserted.next = 1

    def wait_normal():
        while (input_ip_payload_tvalid or input_udp_payload_tvalid
               or output_ip_payload_tvalid or output_udp_payload_tvalid
               or input_ip_hdr_valid or input_udp_hdr_valid):
            yield clk.posedge

    @instance
    def check():
        yield delay(100)
        yield clk.posedge
        rst.next = 1
        yield clk.posedge
        rst.next = 0
        yield clk.posedge
        yield delay(100)
        yield clk.posedge

        yield clk.posedge
        print("test 1: test UDP RX packet")
        current_test.next = 1

        test_frame = udp_ep.UDPFrame()
        test_frame.eth_dest_mac = 0x5A5152535455
        test_frame.eth_src_mac = 0xDAD1D2D3D4D5
        test_frame.eth_type = 0x0800
        test_frame.ip_version = 4
        test_frame.ip_ihl = 5
        test_frame.ip_dscp = 0
        test_frame.ip_ecn = 0
        test_frame.ip_length = None
        test_frame.ip_identification = 0
        test_frame.ip_flags = 2
        test_frame.ip_fragment_offset = 0
        test_frame.ip_ttl = 64
        test_frame.ip_protocol = 0x11
        test_frame.ip_header_checksum = None
        test_frame.ip_source_ip = 0xc0a80165
        test_frame.ip_dest_ip = 0xc0a80164
        test_frame.udp_source_port = 1234
        test_frame.udp_dest_port = 5678
        test_frame.payload = bytearray(range(32))
        test_frame.build()
        ip_frame = test_frame.build_ip()

        ip_source_queue.put(ip_frame)

        yield clk.posedge
        yield clk.posedge

        yield wait_normal()

        yield clk.posedge
        yield clk.posedge

        rx_frame = None
        if not udp_sink_queue.empty():
            rx_frame = udp_sink_queue.get()

        assert rx_frame == test_frame

        assert ip_source_queue.empty()
        assert ip_sink_queue.empty()
        assert udp_source_queue.empty()
        assert udp_sink_queue.empty()

        yield delay(100)

        yield clk.posedge
        print("test 2: test UDP TX packet")
        current_test.next = 2

        test_frame = udp_ep.UDPFrame()
        test_frame.eth_dest_mac = 0x5A5152535455
        test_frame.eth_src_mac = 0xDAD1D2D3D4D5
        test_frame.eth_type = 0x0800
        test_frame.ip_version = 4
        test_frame.ip_ihl = 5
        test_frame.ip_dscp = 0
        test_frame.ip_ecn = 0
        test_frame.ip_length = None
        test_frame.ip_identification = 0
        test_frame.ip_flags = 2
        test_frame.ip_fragment_offset = 0
        test_frame.ip_ttl = 64
        test_frame.ip_protocol = 0x11
        test_frame.ip_header_checksum = None
        test_frame.ip_source_ip = 0xc0a80165
        test_frame.ip_dest_ip = 0xc0a80164
        test_frame.udp_source_port = 1234
        test_frame.udp_dest_port = 5678
        test_frame.payload = bytearray(range(32))
        test_frame.build()

        udp_source_queue.put(test_frame)

        yield clk.posedge
        yield clk.posedge

        yield wait_normal()

        yield clk.posedge
        yield clk.posedge

        rx_frame = None
        if not ip_sink_queue.empty():
            rx_frame = ip_sink_queue.get()

        check_frame = udp_ep.UDPFrame()
        check_frame.parse_ip(rx_frame)

        assert check_frame == test_frame

        assert ip_source_queue.empty()
        assert ip_sink_queue.empty()
        assert udp_source_queue.empty()
        assert udp_sink_queue.empty()

        yield delay(100)

        raise StopSimulation

    return dut, ip_source, ip_sink, udp_source, udp_sink, clkgen, monitor, check
コード例 #9
0
def bench():

    # Parameters
    M_COUNT = 4
    DATA_WIDTH = 64
    KEEP_ENABLE = (DATA_WIDTH > 8)
    KEEP_WIDTH = (DATA_WIDTH / 8)
    ID_ENABLE = 1
    ID_WIDTH = 8
    DEST_ENABLE = 1
    DEST_WIDTH = 8
    USER_ENABLE = 1
    USER_WIDTH = 1

    # Inputs
    clk = Signal(bool(0))
    rst = Signal(bool(0))
    current_test = Signal(intbv(0)[8:])

    s_udp_hdr_valid = Signal(bool(0))
    s_eth_dest_mac = Signal(intbv(0)[48:])
    s_eth_src_mac = Signal(intbv(0)[48:])
    s_eth_type = Signal(intbv(0)[16:])
    s_ip_version = Signal(intbv(0)[4:])
    s_ip_ihl = Signal(intbv(0)[4:])
    s_ip_dscp = Signal(intbv(0)[6:])
    s_ip_ecn = Signal(intbv(0)[2:])
    s_ip_length = Signal(intbv(0)[16:])
    s_ip_identification = Signal(intbv(0)[16:])
    s_ip_flags = Signal(intbv(0)[3:])
    s_ip_fragment_offset = Signal(intbv(0)[13:])
    s_ip_ttl = Signal(intbv(0)[8:])
    s_ip_protocol = Signal(intbv(0)[8:])
    s_ip_header_checksum = Signal(intbv(0)[16:])
    s_ip_source_ip = Signal(intbv(0)[32:])
    s_ip_dest_ip = Signal(intbv(0)[32:])
    s_udp_source_port = Signal(intbv(0)[16:])
    s_udp_dest_port = Signal(intbv(0)[16:])
    s_udp_length = Signal(intbv(0)[16:])
    s_udp_checksum = Signal(intbv(0)[16:])
    s_udp_payload_axis_tdata = Signal(intbv(0)[DATA_WIDTH:])
    s_udp_payload_axis_tkeep = Signal(intbv(1)[KEEP_WIDTH:])
    s_udp_payload_axis_tvalid = Signal(bool(0))
    s_udp_payload_axis_tlast = Signal(bool(0))
    s_udp_payload_axis_tid = Signal(intbv(0)[ID_WIDTH:])
    s_udp_payload_axis_tdest = Signal(intbv(0)[DEST_WIDTH:])
    s_udp_payload_axis_tuser = Signal(intbv(0)[USER_WIDTH:])

    m_udp_hdr_ready_list = [Signal(bool(0)) for i in range(M_COUNT)]
    m_udp_payload_axis_tready_list = [Signal(bool(0)) for i in range(M_COUNT)]

    m_udp_hdr_ready = ConcatSignal(*reversed(m_udp_hdr_ready_list))
    m_udp_payload_axis_tready = ConcatSignal(
        *reversed(m_udp_payload_axis_tready_list))

    enable = Signal(bool(0))
    drop = Signal(bool(0))
    select = Signal(intbv(0)[2:])

    # Outputs
    s_udp_hdr_ready = Signal(bool(0))
    s_udp_payload_axis_tready = Signal(bool(0))

    m_udp_hdr_valid = Signal(intbv(0)[M_COUNT:])
    m_eth_dest_mac = Signal(intbv(0)[M_COUNT * 48:])
    m_eth_src_mac = Signal(intbv(0)[M_COUNT * 48:])
    m_eth_type = Signal(intbv(0)[M_COUNT * 16:])
    m_ip_version = Signal(intbv(0)[M_COUNT * 4:])
    m_ip_ihl = Signal(intbv(0)[M_COUNT * 4:])
    m_ip_dscp = Signal(intbv(0)[M_COUNT * 6:])
    m_ip_ecn = Signal(intbv(0)[M_COUNT * 2:])
    m_ip_length = Signal(intbv(0)[M_COUNT * 16:])
    m_ip_identification = Signal(intbv(0)[M_COUNT * 16:])
    m_ip_flags = Signal(intbv(0)[M_COUNT * 3:])
    m_ip_fragment_offset = Signal(intbv(0)[M_COUNT * 13:])
    m_ip_ttl = Signal(intbv(0)[M_COUNT * 8:])
    m_ip_protocol = Signal(intbv(0)[M_COUNT * 8:])
    m_ip_header_checksum = Signal(intbv(0)[M_COUNT * 16:])
    m_ip_source_ip = Signal(intbv(0)[M_COUNT * 32:])
    m_ip_dest_ip = Signal(intbv(0)[M_COUNT * 32:])
    m_udp_source_port = Signal(intbv(0)[M_COUNT * 16:])
    m_udp_dest_port = Signal(intbv(0)[M_COUNT * 16:])
    m_udp_length = Signal(intbv(0)[M_COUNT * 16:])
    m_udp_checksum = Signal(intbv(0)[M_COUNT * 16:])
    m_udp_payload_axis_tdata = Signal(intbv(0)[M_COUNT * DATA_WIDTH:])
    m_udp_payload_axis_tkeep = Signal(intbv(0xf)[M_COUNT * KEEP_WIDTH:])
    m_udp_payload_axis_tvalid = Signal(intbv(0)[M_COUNT:])
    m_udp_payload_axis_tlast = Signal(intbv(0)[M_COUNT:])
    m_udp_payload_axis_tid = Signal(intbv(0)[M_COUNT * ID_WIDTH:])
    m_udp_payload_axis_tdest = Signal(intbv(0)[M_COUNT * DEST_WIDTH:])
    m_udp_payload_axis_tuser = Signal(intbv(0)[M_COUNT * USER_WIDTH:])

    m_udp_hdr_valid_list = [m_udp_hdr_valid(i) for i in range(M_COUNT)]
    m_eth_dest_mac_list = [
        m_eth_dest_mac((i + 1) * 48, i * 48) for i in range(M_COUNT)
    ]
    m_eth_src_mac_list = [
        m_eth_src_mac((i + 1) * 48, i * 48) for i in range(M_COUNT)
    ]
    m_eth_type_list = [
        m_eth_type((i + 1) * 16, i * 16) for i in range(M_COUNT)
    ]
    m_ip_version_list = [
        m_ip_version((i + 1) * 4, i * 4) for i in range(M_COUNT)
    ]
    m_ip_ihl_list = [m_ip_ihl((i + 1) * 4, i * 4) for i in range(M_COUNT)]
    m_ip_dscp_list = [m_ip_dscp((i + 1) * 6, i * 6) for i in range(M_COUNT)]
    m_ip_ecn_list = [m_ip_ecn((i + 1) * 2, i * 2) for i in range(M_COUNT)]
    m_ip_length_list = [
        m_ip_length((i + 1) * 16, i * 16) for i in range(M_COUNT)
    ]
    m_ip_identification_list = [
        m_ip_identification((i + 1) * 16, i * 16) for i in range(M_COUNT)
    ]
    m_ip_flags_list = [m_ip_flags((i + 1) * 3, i * 3) for i in range(M_COUNT)]
    m_ip_fragment_offset_list = [
        m_ip_fragment_offset((i + 1) * 13, i * 13) for i in range(M_COUNT)
    ]
    m_ip_ttl_list = [m_ip_ttl((i + 1) * 8, i * 8) for i in range(M_COUNT)]
    m_ip_protocol_list = [
        m_ip_protocol((i + 1) * 8, i * 8) for i in range(M_COUNT)
    ]
    m_ip_header_checksum_list = [
        m_ip_header_checksum((i + 1) * 16, i * 16) for i in range(M_COUNT)
    ]
    m_ip_source_ip_list = [
        m_ip_source_ip((i + 1) * 32, i * 32) for i in range(M_COUNT)
    ]
    m_ip_dest_ip_list = [
        m_ip_dest_ip((i + 1) * 32, i * 32) for i in range(M_COUNT)
    ]
    m_udp_source_port_list = [
        m_udp_source_port((i + 1) * 16, i * 16) for i in range(M_COUNT)
    ]
    m_udp_dest_port_list = [
        m_udp_dest_port((i + 1) * 16, i * 16) for i in range(M_COUNT)
    ]
    m_udp_length_list = [
        m_udp_length((i + 1) * 16, i * 16) for i in range(M_COUNT)
    ]
    m_udp_checksum_list = [
        m_udp_checksum((i + 1) * 16, i * 16) for i in range(M_COUNT)
    ]
    m_udp_payload_axis_tdata_list = [
        m_udp_payload_axis_tdata((i + 1) * DATA_WIDTH, i * DATA_WIDTH)
        for i in range(M_COUNT)
    ]
    m_udp_payload_axis_tkeep_list = [
        m_udp_payload_axis_tkeep((i + 1) * KEEP_WIDTH, i * KEEP_WIDTH)
        for i in range(M_COUNT)
    ]
    m_udp_payload_axis_tvalid_list = [
        m_udp_payload_axis_tvalid(i) for i in range(M_COUNT)
    ]
    m_udp_payload_axis_tlast_list = [
        m_udp_payload_axis_tlast(i) for i in range(M_COUNT)
    ]
    m_udp_payload_axis_tid_list = [
        m_udp_payload_axis_tid((i + 1) * ID_WIDTH, i * ID_WIDTH)
        for i in range(M_COUNT)
    ]
    m_udp_payload_axis_tdest_list = [
        m_udp_payload_axis_tdest((i + 1) * DEST_WIDTH, i * DEST_WIDTH)
        for i in range(M_COUNT)
    ]
    m_udp_payload_axis_tuser_list = [
        m_udp_payload_axis_tuser((i + 1) * USER_WIDTH, i * USER_WIDTH)
        for i in range(M_COUNT)
    ]

    # sources and sinks
    source_pause = Signal(bool(0))
    sink_pause_list = []
    sink_list = []
    sink_logic_list = []

    source = udp_ep.UDPFrameSource()

    source_logic = source.create_logic(
        clk,
        rst,
        udp_hdr_ready=s_udp_hdr_ready,
        udp_hdr_valid=s_udp_hdr_valid,
        eth_dest_mac=s_eth_dest_mac,
        eth_src_mac=s_eth_src_mac,
        eth_type=s_eth_type,
        ip_version=s_ip_version,
        ip_ihl=s_ip_ihl,
        ip_dscp=s_ip_dscp,
        ip_ecn=s_ip_ecn,
        ip_length=s_ip_length,
        ip_identification=s_ip_identification,
        ip_flags=s_ip_flags,
        ip_fragment_offset=s_ip_fragment_offset,
        ip_ttl=s_ip_ttl,
        ip_protocol=s_ip_protocol,
        ip_header_checksum=s_ip_header_checksum,
        ip_source_ip=s_ip_source_ip,
        ip_dest_ip=s_ip_dest_ip,
        udp_source_port=s_udp_source_port,
        udp_dest_port=s_udp_dest_port,
        udp_length=s_udp_length,
        udp_checksum=s_udp_checksum,
        udp_payload_tdata=s_udp_payload_axis_tdata,
        udp_payload_tkeep=s_udp_payload_axis_tkeep,
        udp_payload_tvalid=s_udp_payload_axis_tvalid,
        udp_payload_tready=s_udp_payload_axis_tready,
        udp_payload_tlast=s_udp_payload_axis_tlast,
        udp_payload_tuser=s_udp_payload_axis_tuser,
        pause=source_pause,
        name='source')

    for k in range(M_COUNT):
        s = udp_ep.UDPFrameSink()
        p = Signal(bool(0))

        sink_list.append(s)
        sink_pause_list.append(p)

        sink_logic_list.append(
            s.create_logic(
                clk,
                rst,
                udp_hdr_ready=m_udp_hdr_ready_list[k],
                udp_hdr_valid=m_udp_hdr_valid_list[k],
                eth_dest_mac=m_eth_dest_mac_list[k],
                eth_src_mac=m_eth_src_mac_list[k],
                eth_type=m_eth_type_list[k],
                ip_version=m_ip_version_list[k],
                ip_ihl=m_ip_ihl_list[k],
                ip_dscp=m_ip_dscp_list[k],
                ip_ecn=m_ip_ecn_list[k],
                ip_length=m_ip_length_list[k],
                ip_identification=m_ip_identification_list[k],
                ip_flags=m_ip_flags_list[k],
                ip_fragment_offset=m_ip_fragment_offset_list[k],
                ip_ttl=m_ip_ttl_list[k],
                ip_protocol=m_ip_protocol_list[k],
                ip_header_checksum=m_ip_header_checksum_list[k],
                ip_source_ip=m_ip_source_ip_list[k],
                ip_dest_ip=m_ip_dest_ip_list[k],
                udp_source_port=m_udp_source_port_list[k],
                udp_dest_port=m_udp_dest_port_list[k],
                udp_length=m_udp_length_list[k],
                udp_checksum=m_udp_checksum_list[k],
                udp_payload_tdata=m_udp_payload_axis_tdata_list[k],
                udp_payload_tkeep=m_udp_payload_axis_tkeep_list[k],
                udp_payload_tvalid=m_udp_payload_axis_tvalid_list[k],
                udp_payload_tready=m_udp_payload_axis_tready_list[k],
                udp_payload_tlast=m_udp_payload_axis_tlast_list[k],
                udp_payload_tuser=m_udp_payload_axis_tuser_list[k],
                pause=p,
                name='sink_%d' % k))

    # DUT
    if os.system(build_cmd):
        raise Exception("Error running build command")

    dut = Cosimulation("vvp -m myhdl %s.vvp -lxt2" % testbench,
                       clk=clk,
                       rst=rst,
                       current_test=current_test,
                       s_udp_hdr_valid=s_udp_hdr_valid,
                       s_udp_hdr_ready=s_udp_hdr_ready,
                       s_eth_dest_mac=s_eth_dest_mac,
                       s_eth_src_mac=s_eth_src_mac,
                       s_eth_type=s_eth_type,
                       s_ip_version=s_ip_version,
                       s_ip_ihl=s_ip_ihl,
                       s_ip_dscp=s_ip_dscp,
                       s_ip_ecn=s_ip_ecn,
                       s_ip_length=s_ip_length,
                       s_ip_identification=s_ip_identification,
                       s_ip_flags=s_ip_flags,
                       s_ip_fragment_offset=s_ip_fragment_offset,
                       s_ip_ttl=s_ip_ttl,
                       s_ip_protocol=s_ip_protocol,
                       s_ip_header_checksum=s_ip_header_checksum,
                       s_ip_source_ip=s_ip_source_ip,
                       s_ip_dest_ip=s_ip_dest_ip,
                       s_udp_source_port=s_udp_source_port,
                       s_udp_dest_port=s_udp_dest_port,
                       s_udp_length=s_udp_length,
                       s_udp_checksum=s_udp_checksum,
                       s_udp_payload_axis_tdata=s_udp_payload_axis_tdata,
                       s_udp_payload_axis_tkeep=s_udp_payload_axis_tkeep,
                       s_udp_payload_axis_tvalid=s_udp_payload_axis_tvalid,
                       s_udp_payload_axis_tready=s_udp_payload_axis_tready,
                       s_udp_payload_axis_tlast=s_udp_payload_axis_tlast,
                       s_udp_payload_axis_tid=s_udp_payload_axis_tid,
                       s_udp_payload_axis_tdest=s_udp_payload_axis_tdest,
                       s_udp_payload_axis_tuser=s_udp_payload_axis_tuser,
                       m_udp_hdr_valid=m_udp_hdr_valid,
                       m_udp_hdr_ready=m_udp_hdr_ready,
                       m_eth_dest_mac=m_eth_dest_mac,
                       m_eth_src_mac=m_eth_src_mac,
                       m_eth_type=m_eth_type,
                       m_ip_version=m_ip_version,
                       m_ip_ihl=m_ip_ihl,
                       m_ip_dscp=m_ip_dscp,
                       m_ip_ecn=m_ip_ecn,
                       m_ip_length=m_ip_length,
                       m_ip_identification=m_ip_identification,
                       m_ip_flags=m_ip_flags,
                       m_ip_fragment_offset=m_ip_fragment_offset,
                       m_ip_ttl=m_ip_ttl,
                       m_ip_protocol=m_ip_protocol,
                       m_ip_header_checksum=m_ip_header_checksum,
                       m_ip_source_ip=m_ip_source_ip,
                       m_ip_dest_ip=m_ip_dest_ip,
                       m_udp_source_port=m_udp_source_port,
                       m_udp_dest_port=m_udp_dest_port,
                       m_udp_length=m_udp_length,
                       m_udp_checksum=m_udp_checksum,
                       m_udp_payload_axis_tdata=m_udp_payload_axis_tdata,
                       m_udp_payload_axis_tkeep=m_udp_payload_axis_tkeep,
                       m_udp_payload_axis_tvalid=m_udp_payload_axis_tvalid,
                       m_udp_payload_axis_tready=m_udp_payload_axis_tready,
                       m_udp_payload_axis_tlast=m_udp_payload_axis_tlast,
                       m_udp_payload_axis_tid=m_udp_payload_axis_tid,
                       m_udp_payload_axis_tdest=m_udp_payload_axis_tdest,
                       m_udp_payload_axis_tuser=m_udp_payload_axis_tuser,
                       enable=enable,
                       drop=drop,
                       select=select)

    @always(delay(4))
    def clkgen():
        clk.next = not clk

    @instance
    def check():
        yield delay(100)
        yield clk.posedge
        rst.next = 1
        yield clk.posedge
        rst.next = 0
        yield clk.posedge
        yield delay(100)
        yield clk.posedge

        yield clk.posedge
        enable.next = True

        yield clk.posedge
        print("test 1: select port 0")
        current_test.next = 1

        select.next = 0

        test_frame = udp_ep.UDPFrame()
        test_frame.eth_dest_mac = 0xDAD1D2D3D4D5
        test_frame.eth_src_mac = 0x5A5152535455
        test_frame.eth_type = 0x8000
        test_frame.ip_version = 4
        test_frame.ip_ihl = 5
        test_frame.ip_dscp = 0
        test_frame.ip_ecn = 0
        test_frame.ip_length = None
        test_frame.ip_identification = 0
        test_frame.ip_flags = 2
        test_frame.ip_fragment_offset = 0
        test_frame.ip_ttl = 64
        test_frame.ip_protocol = 0x11
        test_frame.ip_header_checksum = None
        test_frame.ip_source_ip = 0xc0a80165
        test_frame.ip_dest_ip = 0xc0a80164
        test_frame.udp_source_port = 1
        test_frame.udp_dest_port = 2
        test_frame.udp_length = None
        test_frame.udp_checksum = None
        test_frame.payload = bytearray(range(32))
        test_frame.build()

        source.send(test_frame)

        yield sink_list[0].wait()
        rx_frame = sink_list[0].recv()

        assert rx_frame == test_frame

        yield delay(100)

        yield clk.posedge
        print("test 2: select port 1")
        current_test.next = 2

        select.next = 1

        test_frame = udp_ep.UDPFrame()
        test_frame.eth_dest_mac = 0xDAD1D2D3D4D5
        test_frame.eth_src_mac = 0x5A5152535455
        test_frame.eth_type = 0x8000
        test_frame.ip_version = 4
        test_frame.ip_ihl = 5
        test_frame.ip_dscp = 0
        test_frame.ip_ecn = 0
        test_frame.ip_length = None
        test_frame.ip_identification = 0
        test_frame.ip_flags = 2
        test_frame.ip_fragment_offset = 0
        test_frame.ip_ttl = 64
        test_frame.ip_protocol = 0x11
        test_frame.ip_header_checksum = None
        test_frame.ip_source_ip = 0xc0a80165
        test_frame.ip_dest_ip = 0xc0a80164
        test_frame.udp_source_port = 1
        test_frame.udp_dest_port = 2
        test_frame.udp_length = None
        test_frame.udp_checksum = None
        test_frame.payload = bytearray(range(32))
        test_frame.build()

        source.send(test_frame)

        yield sink_list[1].wait()
        rx_frame = sink_list[1].recv()

        assert rx_frame == test_frame

        yield delay(100)

        yield clk.posedge
        print("test 3: back-to-back packets, same port")
        current_test.next = 3

        select.next = 0

        test_frame1 = udp_ep.UDPFrame()
        test_frame1.eth_dest_mac = 0xDAD1D2D3D4D5
        test_frame1.eth_src_mac = 0x5A5152535455
        test_frame1.eth_type = 0x8000
        test_frame1.ip_version = 4
        test_frame1.ip_ihl = 5
        test_frame1.ip_dscp = 0
        test_frame1.ip_ecn = 0
        test_frame1.ip_length = None
        test_frame1.ip_identification = 0
        test_frame1.ip_flags = 2
        test_frame1.ip_fragment_offset = 0
        test_frame1.ip_ttl = 64
        test_frame1.ip_protocol = 0x11
        test_frame1.ip_header_checksum = None
        test_frame1.ip_source_ip = 0xc0a80165
        test_frame1.ip_dest_ip = 0xc0a80164
        test_frame1.udp_source_port = 1
        test_frame1.udp_dest_port = 2
        test_frame1.udp_length = None
        test_frame1.udp_checksum = None
        test_frame1.payload = bytearray(range(32))
        test_frame1.build()
        test_frame2 = udp_ep.UDPFrame()
        test_frame2.eth_dest_mac = 0xDAD1D2D3D4D5
        test_frame2.eth_src_mac = 0x5A5152535455
        test_frame2.eth_type = 0x8000
        test_frame2.ip_version = 4
        test_frame2.ip_ihl = 5
        test_frame2.ip_dscp = 0
        test_frame2.ip_ecn = 0
        test_frame2.ip_length = None
        test_frame2.ip_identification = 0
        test_frame2.ip_flags = 2
        test_frame2.ip_fragment_offset = 0
        test_frame2.ip_ttl = 64
        test_frame2.ip_protocol = 0x11
        test_frame2.ip_header_checksum = None
        test_frame2.ip_source_ip = 0xc0a80165
        test_frame2.ip_dest_ip = 0xc0a80164
        test_frame2.udp_source_port = 1
        test_frame2.udp_dest_port = 2
        test_frame2.udp_length = None
        test_frame2.udp_checksum = None
        test_frame2.payload = bytearray(range(32))
        test_frame2.build()

        source.send(test_frame1)
        source.send(test_frame2)

        yield sink_list[0].wait()
        rx_frame = sink_list[0].recv()

        assert rx_frame == test_frame1

        yield sink_list[0].wait()
        rx_frame = sink_list[0].recv()

        assert rx_frame == test_frame2

        yield delay(100)

        yield clk.posedge
        print("test 4: back-to-back packets, different ports")
        current_test.next = 4

        select.next = 1

        test_frame1 = udp_ep.UDPFrame()
        test_frame1.eth_dest_mac = 0xDAD1D2D3D4D5
        test_frame1.eth_src_mac = 0x5A5152535455
        test_frame1.eth_type = 0x8000
        test_frame1.ip_version = 4
        test_frame1.ip_ihl = 5
        test_frame1.ip_dscp = 0
        test_frame1.ip_ecn = 0
        test_frame1.ip_length = None
        test_frame1.ip_identification = 0
        test_frame1.ip_flags = 2
        test_frame1.ip_fragment_offset = 0
        test_frame1.ip_ttl = 64
        test_frame1.ip_protocol = 0x11
        test_frame1.ip_header_checksum = None
        test_frame1.ip_source_ip = 0xc0a80165
        test_frame1.ip_dest_ip = 0xc0a80164
        test_frame1.udp_source_port = 1
        test_frame1.udp_dest_port = 2
        test_frame1.udp_length = None
        test_frame1.udp_checksum = None
        test_frame1.payload = bytearray(range(32))
        test_frame1.build()
        test_frame2 = udp_ep.UDPFrame()
        test_frame2.eth_dest_mac = 0xDAD1D2D3D4D5
        test_frame2.eth_src_mac = 0x5A5152535455
        test_frame2.eth_type = 0x8000
        test_frame2.ip_version = 4
        test_frame2.ip_ihl = 5
        test_frame2.ip_dscp = 0
        test_frame2.ip_ecn = 0
        test_frame2.ip_length = None
        test_frame2.ip_identification = 0
        test_frame2.ip_flags = 2
        test_frame2.ip_fragment_offset = 0
        test_frame2.ip_ttl = 64
        test_frame2.ip_protocol = 0x11
        test_frame2.ip_header_checksum = None
        test_frame2.ip_source_ip = 0xc0a80165
        test_frame2.ip_dest_ip = 0xc0a80164
        test_frame2.udp_source_port = 1
        test_frame2.udp_dest_port = 2
        test_frame2.udp_length = None
        test_frame2.udp_checksum = None
        test_frame2.payload = bytearray(range(32))
        test_frame2.build()

        source.send(test_frame1)
        source.send(test_frame2)
        yield clk.posedge

        while s_udp_payload_axis_tvalid or s_udp_hdr_valid:
            yield clk.posedge
            select.next = 2

        yield sink_list[1].wait()
        rx_frame = sink_list[1].recv()

        assert rx_frame == test_frame1

        yield sink_list[2].wait()
        rx_frame = sink_list[2].recv()

        assert rx_frame == test_frame2

        yield delay(100)

        yield clk.posedge
        print("test 5: alterate pause source")
        current_test.next = 5

        select.next = 1

        test_frame1 = udp_ep.UDPFrame()
        test_frame1.eth_dest_mac = 0xDAD1D2D3D4D5
        test_frame1.eth_src_mac = 0x5A5152535455
        test_frame1.eth_type = 0x8000
        test_frame1.ip_version = 4
        test_frame1.ip_ihl = 5
        test_frame1.ip_dscp = 0
        test_frame1.ip_ecn = 0
        test_frame1.ip_length = None
        test_frame1.ip_identification = 0
        test_frame1.ip_flags = 2
        test_frame1.ip_fragment_offset = 0
        test_frame1.ip_ttl = 64
        test_frame1.ip_protocol = 0x11
        test_frame1.ip_header_checksum = None
        test_frame1.ip_source_ip = 0xc0a80165
        test_frame1.ip_dest_ip = 0xc0a80164
        test_frame1.udp_source_port = 1
        test_frame1.udp_dest_port = 2
        test_frame1.udp_length = None
        test_frame1.udp_checksum = None
        test_frame1.payload = bytearray(range(32))
        test_frame1.build()
        test_frame2 = udp_ep.UDPFrame()
        test_frame2.eth_dest_mac = 0xDAD1D2D3D4D5
        test_frame2.eth_src_mac = 0x5A5152535455
        test_frame2.eth_type = 0x8000
        test_frame2.ip_version = 4
        test_frame2.ip_ihl = 5
        test_frame2.ip_dscp = 0
        test_frame2.ip_ecn = 0
        test_frame2.ip_length = None
        test_frame2.ip_identification = 0
        test_frame2.ip_flags = 2
        test_frame2.ip_fragment_offset = 0
        test_frame2.ip_ttl = 64
        test_frame2.ip_protocol = 0x11
        test_frame2.ip_header_checksum = None
        test_frame2.ip_source_ip = 0xc0a80165
        test_frame2.ip_dest_ip = 0xc0a80164
        test_frame2.udp_source_port = 1
        test_frame2.udp_dest_port = 2
        test_frame2.udp_length = None
        test_frame2.udp_checksum = None
        test_frame2.payload = bytearray(range(32))
        test_frame2.build()

        source.send(test_frame1)
        source.send(test_frame2)
        yield clk.posedge

        while s_udp_payload_axis_tvalid or s_udp_hdr_valid:
            source_pause.next = True
            yield clk.posedge
            yield clk.posedge
            yield clk.posedge
            source_pause.next = False
            yield clk.posedge
            select.next = 2

        yield sink_list[1].wait()
        rx_frame = sink_list[1].recv()

        assert rx_frame == test_frame1

        yield sink_list[2].wait()
        rx_frame = sink_list[2].recv()

        assert rx_frame == test_frame2

        yield delay(100)

        yield clk.posedge
        print("test 6: alterate pause sink")
        current_test.next = 6

        select.next = 1

        test_frame1 = udp_ep.UDPFrame()
        test_frame1.eth_dest_mac = 0xDAD1D2D3D4D5
        test_frame1.eth_src_mac = 0x5A5152535455
        test_frame1.eth_type = 0x8000
        test_frame1.ip_version = 4
        test_frame1.ip_ihl = 5
        test_frame1.ip_dscp = 0
        test_frame1.ip_ecn = 0
        test_frame1.ip_length = None
        test_frame1.ip_identification = 0
        test_frame1.ip_flags = 2
        test_frame1.ip_fragment_offset = 0
        test_frame1.ip_ttl = 64
        test_frame1.ip_protocol = 0x11
        test_frame1.ip_header_checksum = None
        test_frame1.ip_source_ip = 0xc0a80165
        test_frame1.ip_dest_ip = 0xc0a80164
        test_frame1.udp_source_port = 1
        test_frame1.udp_dest_port = 2
        test_frame1.udp_length = None
        test_frame1.udp_checksum = None
        test_frame1.payload = bytearray(range(32))
        test_frame1.build()
        test_frame2 = udp_ep.UDPFrame()
        test_frame2.eth_dest_mac = 0xDAD1D2D3D4D5
        test_frame2.eth_src_mac = 0x5A5152535455
        test_frame2.eth_type = 0x8000
        test_frame2.ip_version = 4
        test_frame2.ip_ihl = 5
        test_frame2.ip_dscp = 0
        test_frame2.ip_ecn = 0
        test_frame2.ip_length = None
        test_frame2.ip_identification = 0
        test_frame2.ip_flags = 2
        test_frame2.ip_fragment_offset = 0
        test_frame2.ip_ttl = 64
        test_frame2.ip_protocol = 0x11
        test_frame2.ip_header_checksum = None
        test_frame2.ip_source_ip = 0xc0a80165
        test_frame2.ip_dest_ip = 0xc0a80164
        test_frame2.udp_source_port = 1
        test_frame2.udp_dest_port = 2
        test_frame2.udp_length = None
        test_frame2.udp_checksum = None
        test_frame2.payload = bytearray(range(32))
        test_frame2.build()

        source.send(test_frame1)
        source.send(test_frame2)
        yield clk.posedge

        while s_udp_payload_axis_tvalid or s_udp_hdr_valid:
            for k in range(M_COUNT):
                sink_pause_list[k].next = False
            yield clk.posedge
            yield clk.posedge
            yield clk.posedge
            for k in range(M_COUNT):
                sink_pause_list[k].next = False
            yield clk.posedge
            select.next = 2

        yield sink_list[1].wait()
        rx_frame = sink_list[1].recv()

        assert rx_frame == test_frame1

        yield sink_list[2].wait()
        rx_frame = sink_list[2].recv()

        assert rx_frame == test_frame2

        yield delay(100)

        yield clk.posedge
        print("test 7: enable")
        current_test.next = 7

        enable.next = False
        select.next = 0

        test_frame = udp_ep.UDPFrame()
        test_frame.eth_dest_mac = 0xDAD1D2D3D4D5
        test_frame.eth_src_mac = 0x5A5152535455
        test_frame.eth_type = 0x8000
        test_frame.ip_version = 4
        test_frame.ip_ihl = 5
        test_frame.ip_dscp = 0
        test_frame.ip_ecn = 0
        test_frame.ip_length = None
        test_frame.ip_identification = 0
        test_frame.ip_flags = 2
        test_frame.ip_fragment_offset = 0
        test_frame.ip_ttl = 64
        test_frame.ip_protocol = 0x11
        test_frame.ip_header_checksum = None
        test_frame.ip_source_ip = 0xc0a80165
        test_frame.ip_dest_ip = 0xc0a80164
        test_frame.udp_source_port = 1
        test_frame.udp_dest_port = 2
        test_frame.udp_length = None
        test_frame.udp_checksum = None
        test_frame.payload = bytearray(range(32))
        test_frame.build()

        source.send(test_frame)

        yield delay(500)

        assert sink_list[0].empty()

        enable.next = True

        yield sink_list[0].wait()
        rx_frame = sink_list[0].recv()

        assert rx_frame == test_frame

        yield delay(100)

        yield clk.posedge
        print("test 8: drop")
        current_test.next = 8

        drop.next = True
        select.next = 0

        test_frame = udp_ep.UDPFrame()
        test_frame.eth_dest_mac = 0xDAD1D2D3D4D5
        test_frame.eth_src_mac = 0x5A5152535455
        test_frame.eth_type = 0x8000
        test_frame.ip_version = 4
        test_frame.ip_ihl = 5
        test_frame.ip_dscp = 0
        test_frame.ip_ecn = 0
        test_frame.ip_length = None
        test_frame.ip_identification = 0
        test_frame.ip_flags = 2
        test_frame.ip_fragment_offset = 0
        test_frame.ip_ttl = 64
        test_frame.ip_protocol = 0x11
        test_frame.ip_header_checksum = None
        test_frame.ip_source_ip = 0xc0a80165
        test_frame.ip_dest_ip = 0xc0a80164
        test_frame.udp_source_port = 1
        test_frame.udp_dest_port = 2
        test_frame.udp_length = None
        test_frame.udp_checksum = None
        test_frame.payload = bytearray(range(32))
        test_frame.build()

        source.send(test_frame)

        yield delay(500)

        assert sink_list[0].empty()

        drop.next = False

        yield delay(100)

        raise StopSimulation

    return instances()