From f44cb5525247d350ffe3633b8d226aaf6631aa63 Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Fri, 7 Apr 2023 10:00:07 +0200 Subject: [PATCH] jf_packet.h: renamed, moved to jungfrau/, and slightly refactored --- jungfrau/ProcessJFPacket.cpp | 4 +-- jungfrau/ProcessJFPacket.h | 4 +-- .../RawJFUDPPacket.h => jungfrau/jf_packet.h | 12 ++++----- receiver/host/CMakeLists.txt | 2 +- receiver/host/HLSSimulatedDevice.cpp | 2 +- receiver/host/HLSSimulatedDevice.h | 2 +- receiver/host/IBReceiver.cpp | 6 ++--- receiver/host/UdpReceiver.cpp | 4 +-- tests/FPGANetworkTest.cpp | 14 +++++------ tests/ProcessRawPacketTest.cpp | 4 +-- tools/UDPSimulator.cpp | 5 ++-- tools/UDPSimulator.h | 25 ------------------- 12 files changed, 30 insertions(+), 54 deletions(-) rename receiver/host/RawJFUDPPacket.h => jungfrau/jf_packet.h (78%) diff --git a/jungfrau/ProcessJFPacket.cpp b/jungfrau/ProcessJFPacket.cpp index bb1f8d81..c8658707 100644 --- a/jungfrau/ProcessJFPacket.cpp +++ b/jungfrau/ProcessJFPacket.cpp @@ -4,7 +4,7 @@ #include #include "ProcessJFPacket.h" -#include "../receiver/host/RawJFUDPPacket.h" +#include "jf_packet.h" #include "../common/JFJochException.h" ProcessJFPacket::ProcessJFPacket(ThreadSafeFIFO &in_c, ThreadSafeFIFO &in_wr, @@ -29,7 +29,7 @@ void ProcessJFPacket::RegisterConversion(uint32_t module_number, JFConversion *c conversion.at(module_number) = conv; } -void ProcessJFPacket::ProcessPacket(jf_payload *datagram, uint32_t src_ip) { +void ProcessJFPacket::ProcessPacket(jf_udp_payload *datagram, uint32_t src_ip) { if (datagram->framenum == 0) throw JFJochException(JFJochExceptionCategory::ArrayOutOfBounds, "Frame number cannot be zero"); diff --git a/jungfrau/ProcessJFPacket.h b/jungfrau/ProcessJFPacket.h index 8491b7b0..7b8df550 100644 --- a/jungfrau/ProcessJFPacket.h +++ b/jungfrau/ProcessJFPacket.h @@ -7,7 +7,7 @@ #include "../common/ThreadSafeFIFO.h" #include "../receiver/host/Completion.h" #include "JFConversion.h" -#include "../receiver/host/RawJFUDPPacket.h" +#include "jf_packet.h" #include @@ -33,7 +33,7 @@ public: ProcessJFPacket(ThreadSafeFIFO &c, ThreadSafeFIFO &wr, uint32_t nmodules); ~ProcessJFPacket(); void RegisterConversion(uint32_t module_number, JFConversion* conv); - void ProcessPacket(jf_payload *datagram, uint32_t src_ip); + void ProcessPacket(jf_udp_payload *datagram, uint32_t src_ip); uint64_t GetCounter(); }; diff --git a/receiver/host/RawJFUDPPacket.h b/jungfrau/jf_packet.h similarity index 78% rename from receiver/host/RawJFUDPPacket.h rename to jungfrau/jf_packet.h index a37461dc..4a8e0e58 100644 --- a/receiver/host/RawJFUDPPacket.h +++ b/jungfrau/jf_packet.h @@ -1,12 +1,12 @@ // Copyright (2019-2022) Paul Scherrer Institute // SPDX-License-Identifier: GPL-3.0-or-later -#ifndef JUNGFRAUJOCH_RAWJFUDPPACKET_H -#define JUNGFRAUJOCH_RAWJFUDPPACKET_H +#ifndef JUNGFRAUJOCH_JF_PACKET_H +#define JUNGFRAUJOCH_JF_PACKET_H #include -struct __attribute__((packed, aligned(2))) jf_payload { +struct __attribute__((packed, aligned(2))) jf_udp_payload { uint64_t framenum; uint32_t exptime; // x 1e-7 sec uint32_t packetnum; @@ -23,7 +23,7 @@ struct __attribute__((packed, aligned(2))) jf_payload { uint16_t data[4096]; }; -struct __attribute__((packed, aligned(2))) RawJFUDPacket { +struct __attribute__((packed, aligned(2))) jf_raw_packet { char dest_mac[6]; char sour_mac[6]; uint16_t ether_type; @@ -39,7 +39,7 @@ struct __attribute__((packed, aligned(2))) RawJFUDPacket { uint16_t udp_dest_port; uint16_t udp_length; uint16_t udp_checksum; - jf_payload jf; + jf_udp_payload jf; }; -#endif //JUNGFRAUJOCH_RAWJFUDPPACKET_H +#endif //JUNGFRAUJOCH_JF_PACKET_H diff --git a/receiver/host/CMakeLists.txt b/receiver/host/CMakeLists.txt index bbeb4f9b..4fe0f250 100644 --- a/receiver/host/CMakeLists.txt +++ b/receiver/host/CMakeLists.txt @@ -11,7 +11,7 @@ ADD_LIBRARY(JungfraujochHost STATIC AcquisitionOfflineCounters.cpp AcquisitionOfflineCounters.h IBWrappers.cpp IBWrappers.h RawEthDevice.cpp RawEthDevice.h - RawJFUDPPacket.h UdpReceiver.cpp UdpReceiver.h IBReceiver.cpp IBReceiver.h) + ../../jungfrau/jf_packet.h UdpReceiver.cpp UdpReceiver.h IBReceiver.cpp IBReceiver.h) TARGET_LINK_LIBRARIES(JungfraujochHost CommonFunctions HLSSimulation ${IBVERBS} JFCalibration) diff --git a/receiver/host/HLSSimulatedDevice.cpp b/receiver/host/HLSSimulatedDevice.cpp index 65d89d35..06b43459 100644 --- a/receiver/host/HLSSimulatedDevice.cpp +++ b/receiver/host/HLSSimulatedDevice.cpp @@ -74,7 +74,7 @@ void HLSSimulatedDevice::CreatePacketJF(const DiffractionExperiment& experiment, char buff[256*64]; memset(buff, 0, 256*64); - auto packet = (RawJFUDPacket *)buff; + auto packet = (jf_raw_packet *)buff; packet->ether_type = htons(0x0800); packet->sour_mac[0] = 0x00; // module 0 diff --git a/receiver/host/HLSSimulatedDevice.h b/receiver/host/HLSSimulatedDevice.h index 233b32df..80eb45f6 100644 --- a/receiver/host/HLSSimulatedDevice.h +++ b/receiver/host/HLSSimulatedDevice.h @@ -9,7 +9,7 @@ #include "datamover_model.h" #include "../../common/DiffractionExperiment.h" #include "AcquisitionDevice.h" -#include "RawJFUDPPacket.h" +#include "../../jungfrau/jf_packet.h" void hls_action(hls::stream &in_datamover_cmd_stream, hls::stream > &in_datamover_stream, diff --git a/receiver/host/IBReceiver.cpp b/receiver/host/IBReceiver.cpp index d83d2a3b..c1822818 100644 --- a/receiver/host/IBReceiver.cpp +++ b/receiver/host/IBReceiver.cpp @@ -16,7 +16,7 @@ #endif #include "../common/JFJochException.h" -#include "RawJFUDPPacket.h" +#include "../../jungfrau/jf_packet.h" #define BUFFER_SIZE (4096*3) #define BUFFER_COUNT 4096 @@ -95,8 +95,8 @@ void IBReceiver::Run(ProcessJFPacket *process, uint8_t numa_node) { int64_t i; size_t size; if (cq.Poll(i, size) > 0) { - if (size == sizeof(RawJFUDPacket)) { - auto ptr = (RawJFUDPacket *) buffer.GetLocation(i); + if (size == sizeof(jf_raw_packet)) { + auto ptr = (jf_raw_packet *) buffer.GetLocation(i); process->ProcessPacket(&ptr->jf, ptr->ipv4_header_sour_ip); qp.PostReceiveWR(*buffer.GetMemoryRegion(), i, buffer.GetLocation(i), BUFFER_SIZE); } diff --git a/receiver/host/UdpReceiver.cpp b/receiver/host/UdpReceiver.cpp index 108e2bcc..c971a6e0 100644 --- a/receiver/host/UdpReceiver.cpp +++ b/receiver/host/UdpReceiver.cpp @@ -49,8 +49,8 @@ void UdpReceiver::Run(uint16_t udp_port_number, ProcessJFPacket *process) { while (!cancel) { auto count = recvfrom(fd, buffer, sizeof(buffer), 0, (struct sockaddr *) &client_addr, &src_addr_len); - if (count == sizeof(jf_payload)) - process->ProcessPacket((jf_payload *) buffer, client_addr.sin_addr.s_addr); + if (count == sizeof(jf_udp_payload)) + process->ProcessPacket((jf_udp_payload *) buffer, client_addr.sin_addr.s_addr); else if ((errno != EAGAIN) && (errno != EWOULDBLOCK) && (count == -1)) throw JFJochException(JFJochExceptionCategory::UDPError, "Cannot bind to UDP port"); } diff --git a/tests/FPGANetworkTest.cpp b/tests/FPGANetworkTest.cpp index 1e839644..cfd6ab90 100644 --- a/tests/FPGANetworkTest.cpp +++ b/tests/FPGANetworkTest.cpp @@ -63,7 +63,7 @@ TEST_CASE("HLS_Network_ARP_Gratuitous") { TEST_CASE("HLS_Network_UDP") { char packet[130*64]; - auto jf_packet = (RawJFUDPacket *) packet; + auto jf_packet = (jf_raw_packet *) packet; jf_packet->ipv4_header_sour_ip = htonl(0x12345640); jf_packet->udp_length = htons(8248); @@ -106,7 +106,7 @@ TEST_CASE("HLS_Network_UDP") { TEST_CASE("HLS_Network_UDP_EthErr") { char packet[130*64]; - auto jf_packet = (RawJFUDPacket *) packet; + auto jf_packet = (jf_raw_packet *) packet; jf_packet->udp_length = htons(8248); jf_packet->udp_dest_port = htons(129); @@ -147,7 +147,7 @@ TEST_CASE("HLS_Network_UDP_EthErr") { TEST_CASE("HLS_Network_UDP_LenErr") { char packet[130*64]; - auto jf_packet = (RawJFUDPacket *) packet; + auto jf_packet = (jf_raw_packet *) packet; jf_packet->udp_length = htons(8248); jf_packet->udp_dest_port = htons(129); @@ -189,7 +189,7 @@ TEST_CASE("HLS_Network_UDP_LenErr") { TEST_CASE("HLS_Network_UDP_SLS_detector_1") { char packet[130*64]; - auto jf_packet = (RawJFUDPacket *) packet; + auto jf_packet = (jf_raw_packet *) packet; jf_packet->ipv4_header_sour_ip = htonl(32+5); jf_packet->udp_length = htons(8248); jf_packet->udp_dest_port = htons(128 + 5); @@ -246,7 +246,7 @@ TEST_CASE("HLS_Network_UDP_SLS_detector_1") { TEST_CASE("HLS_Network_UDP_SLS_detector_2") { char packet[130*64]; - auto jf_packet = (RawJFUDPacket *) packet; + auto jf_packet = (jf_raw_packet *) packet; jf_packet->udp_length = htons(8248); @@ -304,7 +304,7 @@ TEST_CASE("HLS_Network_UDP_SLS_detector_2") { TEST_CASE("HLS_Network_UDP_SLS_detector_2_packets") { char packet[130*64]; - auto jf_packet = (RawJFUDPacket *) packet; + auto jf_packet = (jf_raw_packet *) packet; jf_packet->ipv4_header_sour_ip = htonl(192+2); jf_packet->udp_length = htons(8248); @@ -374,7 +374,7 @@ TEST_CASE("HLS_Network_UDP_SLS_detector_2_packets") { TEST_CASE("HLS_Network_UDP_SLS_detector_packets_err") { char packet[130*64]; - auto jf_packet = (RawJFUDPacket *) packet; + auto jf_packet = (jf_raw_packet *) packet; jf_packet->ipv4_header_sour_ip = htonl(32+4); jf_packet->udp_length = htons(8248); diff --git a/tests/ProcessRawPacketTest.cpp b/tests/ProcessRawPacketTest.cpp index d852b58f..373a8466 100644 --- a/tests/ProcessRawPacketTest.cpp +++ b/tests/ProcessRawPacketTest.cpp @@ -4,7 +4,7 @@ #include #include "../jungfrau/ProcessJFPacket.h" -#include "../receiver/host/RawJFUDPPacket.h" +#include "../jungfrau/jf_packet.h" #include "../common/DiffractionExperiment.h" TEST_CASE("ProcessRawPacketTest_Empty") { @@ -31,7 +31,7 @@ TEST_CASE("ProcessRawPacketTest") { { ProcessJFPacket process(c_fifo, wr_fifo, 4); - jf_payload datagram; + jf_udp_payload datagram; datagram.packetnum = 36; datagram.framenum = 1; diff --git a/tools/UDPSimulator.cpp b/tools/UDPSimulator.cpp index 4f1dc292..a5ab5fa1 100644 --- a/tools/UDPSimulator.cpp +++ b/tools/UDPSimulator.cpp @@ -11,6 +11,7 @@ #include "../common/JFJochException.h" #include "../common/Definitions.h" +#include "../jungfrau/jf_packet.h" UDPSimulator::UDPSimulator(const std::vector &in_image) : image(in_image) { if (image.size() != RAW_MODULE_SIZE) @@ -43,14 +44,14 @@ void UDPSimulator::SendImage(const std::string &ipv4_dest_addr, if (inet_pton(AF_INET, ipv4_dest_addr.c_str(), &addr.sin_addr.s_addr) <= 0) throw JFJochException(JFJochExceptionCategory::UDPError, "Cannot parse address " + ipv4_dest_addr); - RAW_JF_Packet packet{ + jf_udp_payload packet{ .framenum = frame_number }; for (int i = 0; i < 128; i++) { packet.packetnum = i; memcpy(packet.data, image.data() + 4096 * i, 4096 * sizeof(uint16_t)); - sendto(fd, &packet, sizeof(RAW_JF_Packet), 0, (struct sockaddr *) &addr, sizeof(addr)); + sendto(fd, &packet, sizeof(jf_udp_payload), 0, (struct sockaddr *) &addr, sizeof(addr)); } } diff --git a/tools/UDPSimulator.h b/tools/UDPSimulator.h index d5b3c796..676c32e3 100644 --- a/tools/UDPSimulator.h +++ b/tools/UDPSimulator.h @@ -8,31 +8,6 @@ #include #include -// full JF packet - for simulation -#pragma pack(push) -#pragma pack(2) -struct RAW_JF_Packet -{ - // 42 bytes - uint64_t framenum; - uint32_t exptime; // x 1e-7 sec - uint32_t packetnum; - uint64_t bunchid; - uint64_t timestamp; - uint16_t moduleID; - uint16_t xCoord; - uint16_t yCoord; - uint16_t zCoord; - uint32_t debug; - uint16_t roundRobin; - uint8_t detectortype; - uint8_t headerVersion; - // 48 + 42 = 90 bytes - uint16_t data[4096]; - // 96 + 8192 = 8282 bytes -}; -#pragma pack(pop) - class UDPSimulator { std::mutex m; int fd;