Esempio n. 1
0
 def build_handover_cmd_pkt(self, handover_id, cmd):
     """
     Build a control message packet with a specific handover id and command code
     :param handover_id: Handover id for the packet
     :param cmd: Command code for the packet
     :return: Control message buffer
     """
     msg = HandoverMessage(cmd, handover_id, [])
     raw = Raw(msg.serialize())
     pkt = Ether(type=CONTROL_MESSAGE_ETHER_TYPE) / raw
     return pkt.build()
async def run_test(dut,
                   payload_lengths=None,
                   payload_data=None,
                   idle_inserter=None,
                   backpressure_inserter=None):

    tb = TB(dut)

    await tb.reset()

    tb.set_idle_generator(idle_inserter)
    tb.set_backpressure_generator(backpressure_inserter)

    test_pkts = []

    for payload in [payload_data(x) for x in payload_lengths()]:
        eth = Ether(src='5A:51:52:53:54:55',
                    dst='DA:D1:D2:D3:D4:D5',
                    type=0x8000)
        test_pkt = eth / payload
        test_pkts.append(test_pkt.copy())

        test_frame = test_pkt.build()

        hdr = EthHdrTransaction()
        hdr.dest_mac = int.from_bytes(test_frame[0:6], "big")
        hdr.src_mac = int.from_bytes(test_frame[6:12], "big")
        hdr.type = int.from_bytes(test_frame[12:14], "big")

        await tb.header_source.send(hdr)
        await tb.payload_source.send(AxiStreamFrame(payload))

    for test_pkt in test_pkts:
        rx_frame = await tb.sink.recv()

        rx_pkt = Ether(bytes(rx_frame))

        tb.log.info("RX packet: %s", repr(rx_pkt))

        assert rx_pkt.build() == test_pkt.build()
        assert not rx_frame.tuser

    assert tb.sink.empty()

    await RisingEdge(dut.clk)
    await RisingEdge(dut.clk)