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

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 {