DiffractionExperiment: Refactor IPv4 handling (now it is just base addr for detector IP)

This commit is contained in:
2023-04-15 12:29:14 +02:00
parent 32baaef1e4
commit feb5fcacf3
8 changed files with 104 additions and 193 deletions
+1 -1
View File
@@ -227,7 +227,7 @@ void ParseFacilityConfiguration(const nlohmann::json &input, const std::string&
experiment.SpotFindingPeriod(GET_TIME(j, "spot_finding_period_us"));
experiment.PreviewPeriod(GET_TIME(j, "preview_period_us"));
experiment.IPv4Subnet(GET_STR(j, "ipv4_subnet"));
experiment.IPv4BaseAddr(GET_STR(j, "detector_ipv4"));
} else
throw JFJochException(JFJochExceptionCategory::JSON, "Default configuration not found");
}
+6 -46
View File
@@ -67,8 +67,7 @@ DiffractionExperiment::DiffractionExperiment(const DetectorSetup& det_setup) {
internal.set_high_q(5.0);
internal.set_q_spacing(0.02);
internal.set_ipv4_subnet(0x0032010a);
internal.set_base_udp_port(8192);
internal.set_ipv4_base_addr(0x0132010a);
internal.set_git_sha1(jfjoch_git_sha1());
internal.set_git_date(jfjoch_git_date());
@@ -253,27 +252,8 @@ DiffractionExperiment &DiffractionExperiment::UseInternalPacketGenerator(bool in
return *this;
}
DiffractionExperiment &DiffractionExperiment::IPv4Subnet(std::string input) {
IPv4Subnet(IPv4AddressFromStr(input)); // IPv4 address is passed as low endian to FPGA
return *this;
}
DiffractionExperiment &DiffractionExperiment::IPv4Subnet(int64_t input) {
check_min("IPv4 address", input, 1);
check_max("IPv4 address", input, (1L<<33) - 1);
if ((input >> 24) % 256 != 0)
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid,"Requires 255.255.255.0 masked subnet");
internal.set_ipv4_subnet(input);
return *this;
}
DiffractionExperiment &DiffractionExperiment::BaseUDPPort(int64_t input) {
check_min("UDP port", input, 1024);
check_max("UDP port", input, 65535);
if (input % 64 != 0)
throw JFJochException(JFJochExceptionCategory::WrongNumber, "Base UDP port must be multiple of 64");
internal.set_base_udp_port(input);
DiffractionExperiment &DiffractionExperiment::IPv4BaseAddr(std::string input) {
internal.set_ipv4_base_addr(IPv4AddressFromStr(input));
return *this;
}
@@ -734,32 +714,12 @@ bool DiffractionExperiment::IsUsingInternalPacketGen() const {
uint32_t DiffractionExperiment::GetSrcIPv4Address(uint32_t data_stream, uint32_t half_module) const {
if (data_stream >= GetDataStreamsNum())
throw JFJochException(JFJochExceptionCategory::ArrayOutOfBounds, "Non existing data stream");
if (half_module >= 2 * GetModulesNum())
if (half_module >= 2 * GetModulesNum(data_stream))
throw JFJochException(JFJochExceptionCategory::ArrayOutOfBounds, "Non existing module");
if ((data_stream+1) >= 256/32)
throw JFJochException(JFJochExceptionCategory::ArrayOutOfBounds,
"Cannot handle more than 7 data stream in the current model");
if (half_module >= 32)
throw JFJochException(JFJochExceptionCategory::ArrayOutOfBounds,
"Cannot handle more than 16 modules / data stream in the current model");
uint32_t host = (((data_stream+1) * 32) | half_module) << 24;
return internal.ipv4_subnet() | host;
}
uint32_t DiffractionExperiment::GetDestIPv4Address(uint32_t data_stream) const {
if (data_stream >= GetDataStreamsNum())
throw JFJochException(JFJochExceptionCategory::ArrayOutOfBounds, "Non existing data stream");
uint32_t host = half_module + 2 * GetFirstModuleOfDataStream(data_stream);
uint32_t host = (data_stream + 1) << 24;
return internal.ipv4_subnet() | host;
}
uint16_t DiffractionExperiment::GetDestUDPPort(uint16_t data_stream, uint16_t half_module) const {
if (data_stream >= GetDataStreamsNum())
throw JFJochException(JFJochExceptionCategory::ArrayOutOfBounds, "Non existing data stream");
if (half_module >= GetModulesNum(data_stream) * 2)
throw JFJochException(JFJochExceptionCategory::ArrayOutOfBounds, "Non existing module");
return internal.base_udp_port() + data_stream;
return internal.ipv4_base_addr() + (host << 24);
}
bool DiffractionExperiment::CheckGitSha1Consistent() const {
+1 -5
View File
@@ -69,9 +69,7 @@ public:
DiffractionExperiment& SpotFindingPeriod(std::chrono::microseconds input);
DiffractionExperiment& UseInternalPacketGenerator(bool input);
DiffractionExperiment& IPv4Subnet(std::string input); // requires 255.255.255.0 subnet
DiffractionExperiment& IPv4Subnet(int64_t input); // requires 255.255.255.0 subnet
DiffractionExperiment& BaseUDPPort(int64_t input);
DiffractionExperiment& IPv4BaseAddr(std::string input);
DiffractionExperiment& MaskModuleEdges(bool input);
DiffractionExperiment& MaskChipEdges(bool input);
DiffractionExperiment& SetUnitCell(const UnitCell &cell);
@@ -177,8 +175,6 @@ public:
bool IsUsingInternalPacketGen() const;
uint32_t GetSrcIPv4Address(uint32_t data_stream, uint32_t half_module) const;
uint32_t GetDestIPv4Address(uint32_t data_stream) const;
uint16_t GetDestUDPPort(uint16_t data_stream, uint16_t half_module) const;
bool CheckGitSha1Consistent() const;
std::string CheckGitSha1Msg() const;
+1 -2
View File
@@ -163,8 +163,7 @@ message InternalSettings {
bool mask_module_edges = 20;
bool mask_chip_edges = 21;
int64 ipv4_subnet = 22;
int64 base_udp_port = 23;
int64 ipv4_base_addr = 22;
float low_q = 26;
float high_q = 27;
+86 -86
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -93,7 +93,7 @@ void HLSSimulatedDevice::CreatePacketJF(const DiffractionExperiment& experiment,
packet->ipv4_header_ttl_protocol = htons(0x0011);
packet->ipv4_header_checksum = checksum( (uint16_t *) &packet->ipv4_header_h, 20); // checksum is already in network order
packet->udp_dest_port = htons(experiment.GetDestUDPPort(data_stream, half_module)); // module number
packet->udp_dest_port = htons(GetUDPPort()); // module number
packet->udp_sour_port = htons(0xDFAC);
packet->udp_length = htons(8248);
+7 -51
View File
@@ -178,28 +178,10 @@ TEST_CASE("DiffractionExperiment_IPv4Address","[DiffractionExperiment]") {
uint32_t ndatastreams = 3;
x.DataStreams(ndatastreams);
REQUIRE(x.GetDestIPv4Address(0) == 0x0132010a);
REQUIRE(x.GetDestIPv4Address(1) == 0x0232010a);
REQUIRE(x.GetDestIPv4Address(2) == 0x0332010a);
REQUIRE(x.GetSrcIPv4Address(0, 4) == (0x0032010a | ((1 * 32 + 4) << 24)));
REQUIRE(x.GetSrcIPv4Address(2, 23) == (0x0032010a | ((3 * 32 + 23) << 24)));
REQUIRE_THROWS(x.GetDestIPv4Address(3));
REQUIRE_THROWS(x.GetSrcIPv4Address(0, 24));
REQUIRE_THROWS(x.GetSrcIPv4Address(3, 5));
REQUIRE_THROWS(x.IPv4Subnet("456"));
REQUIRE_THROWS(x.IPv4Subnet("257.1.1.1"));
REQUIRE_THROWS(x.IPv4Subnet("257.1.1.1111"));
REQUIRE_THROWS(x.IPv4Subnet("64.1.124.34"));
REQUIRE_THROWS(x.IPv4Subnet("64.1.124.129"));
REQUIRE_NOTHROW(x.IPv4Subnet("64.1.124.0"));
REQUIRE(x.GetDestIPv4Address(0) == 0x017c0140u);
REQUIRE(x.GetDestIPv4Address(1) == 0x027c0140u);
REQUIRE(x.GetDestIPv4Address(2) == 0x037c0140u);
REQUIRE(x.GetSrcIPv4Address(2, 12) == 0x007c0140u + ((3 * 32 + 12) << 24));
REQUIRE(IPv4AddressToStr(x.GetDestIPv4Address(2)) == "64.1.124.3");
REQUIRE_NOTHROW(x.IPv4BaseAddr("64.1.124.1"));
REQUIRE(x.GetSrcIPv4Address(0, 0) == IPv4AddressFromStr("64.1.124.1"));
REQUIRE(x.GetSrcIPv4Address(0, 6) == IPv4AddressFromStr("64.1.124.7"));
REQUIRE(x.GetSrcIPv4Address(2, 6) == IPv4AddressFromStr("64.1.124.23"));
}
TEST_CASE("IPv4AddressToStr","") {
@@ -226,32 +208,6 @@ TEST_CASE("MacAddressFromStr","") {
REQUIRE_THROWS(MacAddressFromStr("xy:22:33:44:55"));
}
TEST_CASE("DiffractionExperiment_UDPAddress","[DiffractionExperiment]") {
DiffractionExperiment x(DetectorGeometry(12));
x.Mode(DetectorMode::Conversion).DataStreams(3);
REQUIRE(x.GetDestUDPPort(0, 0) % 64 == 0);
REQUIRE(x.GetDestUDPPort(0, 2) % 64 == 0);
REQUIRE(x.GetDestUDPPort(0, 4) % 64 == 0);
REQUIRE_THROWS(x.GetDestUDPPort(0, 8));
REQUIRE(x.GetDestUDPPort(2, 0) % 64 == 2);
REQUIRE(x.GetDestUDPPort(2, 2) % 64 == 2);
REQUIRE(x.GetDestUDPPort(2, 4) % 64 == 2);
REQUIRE_THROWS(x.GetDestUDPPort(3, 0));
REQUIRE_THROWS(x.BaseUDPPort(-1));
REQUIRE_THROWS(x.BaseUDPPort(65536));
REQUIRE_THROWS(x.BaseUDPPort(64*93+1));
REQUIRE_NOTHROW(x.BaseUDPPort(64*93));
REQUIRE(x.GetDestUDPPort(0, 0) == 64*93);
REQUIRE(x.GetDestUDPPort(2, 1) == 64*93 + 2);
}
TEST_CASE("DiffractionExperiment_DataStreams","[DiffractionExperiment]") {
DiffractionExperiment x(DetectorGeometry(18)); // 9M
@@ -552,7 +508,7 @@ TEST_CASE("DiffractionExperiment_ExportProtobuf","[DiffractionExperiment]") {
.PhotonEnergy_keV(16.0).BeamX_pxl(566).BeamY_pxl(1234).DetectorDistance_mm(145)
.FrameTime(std::chrono::microseconds(765), std::chrono::microseconds(10))
.PedestalG1G2FrameTime(std::chrono::milliseconds(10))
.IPv4Subnet("2.2.2.0").BaseUDPPort(64 * 76).MaskModuleEdges(true);
.IPv4BaseAddr("2.2.2.2").MaskModuleEdges(true);
JFJochProtoBuf::JungfraujochSettings settings_in_protobuf = x;
REQUIRE_NOTHROW(y.Import(settings_in_protobuf));
@@ -573,8 +529,8 @@ TEST_CASE("DiffractionExperiment_ExportProtobuf","[DiffractionExperiment]") {
REQUIRE(x.GetFrameNum() == y.GetFrameNum());
REQUIRE(x.GetImageTime() == y.GetImageTime());
REQUIRE(y.GetFrameCountTime().count() == x.GetFrameCountTime().count());
REQUIRE(y.GetDestUDPPort(0,0) == 64*76);
REQUIRE(y.GetDestIPv4Address(0) == 0x01020202);
REQUIRE(y.GetSrcIPv4Address(0, 0) == 0x02020202);
REQUIRE(y.GetPedestalG0Frames() == x.GetPedestalG0Frames());
REQUIRE(y.GetMaskModuleEdges() == x.GetMaskModuleEdges());
REQUIRE(y.GetMaskChipEdges() == x.GetMaskChipEdges());
+1 -1
View File
@@ -112,7 +112,7 @@ TEST_CASE("JFJochBrokerParser_ParseFacilityConfiguration") {
"count_time_us": "950 us",
"spot_finding_period_us": " 2 ms",
"preview_period_us": "1 s",
"ipv4_subnet": "10.10.25.0"
"detector_ipv4": "10.10.25.0"
}
}
)"_json;