From 9ca5abc9a53b0932a43a54907d8ea949ae26b2b9 Mon Sep 17 00:00:00 2001 From: Reinier van der Walle <walle@astron.nl> Date: Tue, 23 Jul 2024 10:59:11 +0200 Subject: [PATCH] WIP: added eth_200g IP --- .../cocotb/tb_rdma_packetiser.py | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/applications/rdma_demo/libraries/rdma_packetiser/cocotb/tb_rdma_packetiser.py b/applications/rdma_demo/libraries/rdma_packetiser/cocotb/tb_rdma_packetiser.py index 95cf9c4124..09b3e7a1ae 100644 --- a/applications/rdma_demo/libraries/rdma_packetiser/cocotb/tb_rdma_packetiser.py +++ b/applications/rdma_demo/libraries/rdma_packetiser/cocotb/tb_rdma_packetiser.py @@ -318,21 +318,25 @@ async def tb_rdma_packetiser(dut): dut._log.debug("src_out data = \n%s", hexdump(data)) # Verify icrc + icrc = int.from_bytes(packet[-4:], "big") + # calculation of icrc is done as in: # https://github.com/secdev/scapy/blob/master/scapy/contrib/roce.py - # ICRC could be calculated using the scapy library (if installed) with the code below. - # from scapy.layers.l2 import Ether - # from scapy.contrib.roce import BTH # for compute_icrc function - # exp_icrc = int.from_bytes(Ether(packet)['BTH'].compute_icrc(None), 'little') - icrc = int.from_bytes(packet[-4:], "big") - ones = (0xFF).to_bytes(1, 'little') - pseudo_packet = ([ones] * 8 + [packet[14:15]] + - [ones] + [packet[16:22]] + [ones] + - [packet[23:24]] + [ones] * 2 + - [packet[26:40]] + [ones] * 2 + - [packet[42:46]] + [ones] + [packet[47:-4]] - ) - pseudo_packet = b''.join(pseudo_packet) - exp_icrc = crc32(pseudo_packet) & 0xffffffff + # ICRC could be calculated using the scapy library (if installed) with the code below. + try: + from scapy.layers.l2 import Ether + from scapy.contrib.roce import BTH # for compute_icrc function + Ether(packet).show() # print packet if scapy is installed. + exp_icrc = int.from_bytes(Ether(packet)['BTH'].compute_icrc(None), 'little') + except ModuleNotFoundError: + ones = (0xFF).to_bytes(1, 'little') + pseudo_packet = ([ones] * 8 + [packet[14:15]] + + [ones] + [packet[16:22]] + [ones] + + [packet[23:24]] + [ones] * 2 + + [packet[26:40]] + [ones] * 2 + + [packet[42:46]] + [ones] + [packet[47:-4]] + ) + pseudo_packet = b''.join(pseudo_packet) + exp_icrc = crc32(pseudo_packet) & 0xffffffff assert exp_icrc == icrc, ( f'ERROR: Wrong ICRC, expected = {hex(exp_icrc)}, actual = {hex(icrc)}') -- GitLab