diff options
author | Tobias Frust <tobiasfrust@gmail.com> | 2016-07-21 09:33:42 +0200 |
---|---|---|
committer | Tobias Frust <tobiasfrust@gmail.com> | 2016-07-21 09:33:42 +0200 |
commit | cdf8aac7e3a88df0fb93586bbf47b17c192ae2fc (patch) | |
tree | ad9cc18aeefd5f7923ab0106bc2e580490ba087f /src/ReceiverThreads | |
parent | 409e2fd20af5620066796e43410a92521376b2c1 (diff) | |
download | ods-cdf8aac7e3a88df0fb93586bbf47b17c192ae2fc.tar.gz ods-cdf8aac7e3a88df0fb93586bbf47b17c192ae2fc.tar.bz2 ods-cdf8aac7e3a88df0fb93586bbf47b17c192ae2fc.tar.xz ods-cdf8aac7e3a88df0fb93586bbf47b17c192ae2fc.zip |
added ReceiverThreads for tests with 40GBE
Diffstat (limited to 'src/ReceiverThreads')
-rw-r--r-- | src/ReceiverThreads/ReceiverThreads.cpp | 48 | ||||
-rw-r--r-- | src/ReceiverThreads/ReceiverThreads.h | 35 |
2 files changed, 83 insertions, 0 deletions
diff --git a/src/ReceiverThreads/ReceiverThreads.cpp b/src/ReceiverThreads/ReceiverThreads.cpp new file mode 100644 index 0000000..6f389f2 --- /dev/null +++ b/src/ReceiverThreads/ReceiverThreads.cpp @@ -0,0 +1,48 @@ +/* + * Copyright 2016 + * + * ReceiverThreads.cpp + * + * Created on: 21.07.2016 + * Author: Tobias Frust + */ + +#include "ReceiverThreads.h" +#include "../UDPServer/UDPServer.h" + +#include <boost/log/trivial.hpp> + +ReceiverThreads::ReceiverThreads(const std::string& address, const int timeIntervall, const int numberOfDetectorModules) + : timeIntervall_{timeIntervall}, numberOfDetectorModules_{numberOfDetectorModules}, address_{address}, loss_{0} { + + for(auto i = 0; i < numberOfDetectorModules; i++){ + receiverModules_.emplace_back(&ReceiverThreads::receiverThread, this, 4000+i); + } + + for(auto i = 0; i < numberOfDetectorModules; i++){ + receiverModules_[i].join(); + } + +} + +auto ReceiverThreads::receiverThread(const int port) -> void { + UDPServer server = UDPServer(address_, port); + std::vector<unsigned short> buf(16000); + std::size_t lastIndex{0}; + BOOST_LOG_TRIVIAL(info) << "Address: " << address_ << " port: " << port << " timeout: " << timeIntervall_; + while(true){ + int bytes = server.timed_recv((char*)buf.data(), buf.size()*sizeof(unsigned short), timeIntervall_); + if(bytes < 0){ + break; + } + std::size_t index = *((std::size_t *)buf.data()); + int diff = index - lastIndex - 1; + if(diff > 0){ + BOOST_LOG_TRIVIAL(warning) << "Packet loss or wrong order! new: " << index << " old: " << lastIndex; + } + loss_ += diff; + lastIndex = index; + } + BOOST_LOG_TRIVIAL(info) << "Lost " << loss_ << " from " << lastIndex << " packets; (" << loss_/(double)lastIndex << "%)"; +} + diff --git a/src/ReceiverThreads/ReceiverThreads.h b/src/ReceiverThreads/ReceiverThreads.h new file mode 100644 index 0000000..7cb04c0 --- /dev/null +++ b/src/ReceiverThreads/ReceiverThreads.h @@ -0,0 +1,35 @@ +/* + * Copyright 2016 + * + * ReceiverThreads.h + * + * Created on: 21.07.2016 + * Author: Tobias Frust + */ + +#ifndef RECEIVERTHREADS_H_ +#define RECEIVERTHREADS_H_ + +#include <vector> +#include <thread> + +class ReceiverThreads { +public: + ReceiverThreads(const std::string& address, const int timeIntervall, const int numberOfDetectorModules); + + auto run() -> void; +private: + auto receiverThread(const int port) -> void; + + std::vector<std::thread> receiverModules_; + + std::size_t loss_; + + int timeIntervall_; + int numberOfDetectorModules_; + + std::string address_; + +}; + +#endif /* RECEIVERTHREADS_H_ */ |