Browse Source

return double for IP entropies

fix operator== for entry_intervalStat
Jens Keim 5 years ago
parent
commit
7330a44df7
2 changed files with 19 additions and 12 deletions
  1. 3 4
      code_boost/src/cxx/statistics.cpp
  2. 16 8
      code_boost/src/cxx/statistics.h

+ 3 - 4
code_boost/src/cxx/statistics.cpp

@@ -45,7 +45,7 @@ void statistics::checkTCPChecksum(const std::string &ipAddressSender, const std:
  * @param intervalStartTimestamp The timstamp where the interval starts.
  * @return a vector: contains source IP entropy and destination IP entropy.
  */
-std::vector<float> statistics::calculateLastIntervalIPsEntropy(std::chrono::microseconds intervalStartTimestamp){
+std::vector<double> statistics::calculateLastIntervalIPsEntropy(std::chrono::microseconds intervalStartTimestamp){
     if(this->getDoExtraTests()) {
         // TODO: change datastructures
         std::vector<long> IPsSrcPktsCounts;
@@ -133,8 +133,7 @@ std::vector<float> statistics::calculateLastIntervalIPsEntropy(std::chrono::micr
         this->ip_src_novel_count = IPsSrcNovelPktsCounts.size();
         this->ip_dst_novel_count = IPsDstNovelPktsCounts.size();
 
-        // FIXME: return doubles not floats
-        std::vector<float> entropies = {static_cast<float>(IPsSrcEntropy), static_cast<float>(IPsDstEntropy), static_cast<float>(IPsSrcNovelEntropy), static_cast<float>(IPsDstNovelEntropy)};
+        std::vector<double> entropies = {IPsSrcEntropy, IPsDstEntropy, IPsSrcNovelEntropy, IPsDstNovelEntropy};
         return entropies;
     }
     else {
@@ -262,7 +261,7 @@ void statistics::addIntervalStat(std::chrono::duration<int, std::micro> interval
     // Add packet rate for each IP to ip_statistics map
     calculateIPIntervalPacketRate(interval, intervalStartTimestamp);
     
-    std::vector<float> ipEntopies = calculateLastIntervalIPsEntropy(intervalStartTimestamp);
+    std::vector<double> ipEntopies = calculateLastIntervalIPsEntropy(intervalStartTimestamp);
     std::vector<float> ipCumEntopies = calculateIPsCumEntropy();
     std::string lastPktTimestamp_s = std::to_string(intervalEndTimestamp.count());
     std::string  intervalStartTimestamp_s = std::to_string(intervalStartTimestamp.count());

+ 16 - 8
code_boost/src/cxx/statistics.h

@@ -242,12 +242,12 @@ struct entry_intervalStat {
     float pkt_rate;
     float kbytes;
     float kbyte_rate;
-    float ip_src_entropy;
-    float ip_dst_entropy;
-    float ip_src_novel_entropy;
-    float ip_dst_novel_entropy;
-    float ip_src_cum_entropy;
-    float ip_dst_cum_entropy;
+    double ip_src_entropy;
+    double ip_dst_entropy;
+    double ip_src_novel_entropy;
+    double ip_dst_novel_entropy;
+    double ip_src_cum_entropy;
+    double ip_dst_cum_entropy;
     std::vector<double> ttl_entropies;
     std::vector<double> win_size_entropies;
     std::vector<double> tos_entropies;
@@ -274,17 +274,25 @@ struct entry_intervalStat {
                && kbyte_rate == other.kbyte_rate
                && ip_src_entropy == other.ip_src_entropy
                && ip_dst_entropy == other.ip_dst_entropy
+               && ip_src_novel_entropy == other.ip_src_novel_entropy
+               && ip_dst_novel_entropy == other.ip_dst_novel_entropy
                && ip_src_cum_entropy == other.ip_src_cum_entropy
                && ip_dst_cum_entropy == other.ip_dst_cum_entropy
                && payload_count == other.payload_count
                && incorrect_tcp_checksum_count == other.incorrect_tcp_checksum_count
+               && correct_tcp_checksum_count == other.correct_tcp_checksum_count
                && novel_ip_src_count == other.novel_ip_src_count
                && novel_ip_dst_count == other.novel_ip_dst_count
                && novel_ttl_count == other.novel_ttl_count
                && novel_win_size_count == other.novel_win_size_count
                && novel_tos_count == other.novel_tos_count
                && novel_mss_count == other.novel_mss_count
-               && novel_port_count == other.novel_port_count;
+               && novel_port_count == other.novel_port_count
+               && ttl_entropies == other.ttl_entropies
+               && win_size_entropies == other.win_size_entropies
+               && tos_entropies == other.tos_entropies
+               && mss_entropies == other.mss_entropies
+               && port_entropies == other.port_entropies;
     }
 };
 
@@ -560,7 +568,7 @@ public:
 
     std::vector<float> calculateIPsCumEntropy();
 
-    std::vector<float> calculateLastIntervalIPsEntropy(std::chrono::microseconds intervalStartTimestamp);
+    std::vector<double> calculateLastIntervalIPsEntropy(std::chrono::microseconds intervalStartTimestamp);
 
     std::vector<double> calculateEntropies(std::unordered_map<int, int> &map, std::unordered_map<int, int> &old);