소스 검색

fix normalized entropy calculation for IP cumulative

Jens Keim 6 년 전
부모
커밋
5f1fc22604
3개의 변경된 파일13개의 추가작업 그리고 16개의 파일을 삭제
  1. 7 2
      code_boost/src/cxx/statistics.cpp
  2. 4 0
      code_boost/src/cxx/statistics.h
  3. 2 14
      code_boost/src/cxx/statistics_db.cpp

+ 7 - 2
code_boost/src/cxx/statistics.cpp

@@ -176,11 +176,14 @@ std::vector<double> statistics::calculateIPsCumEntropy(){
                 IPsDstEntropy += - IPsDstProb[i]*log2(IPsDstProb[i]);
         }
 
-        std::vector<double> entropies = {IPsSrcEntropy, IPsDstEntropy};
+        double norm_src_entropy = IPsSrcEntropy / log2(IPsSrcProb.size());
+        double norm_dst_entropy = IPsDstEntropy / log2(IPsDstProb.size());
+
+        std::vector<double> entropies = {IPsSrcEntropy, IPsDstEntropy, norm_src_entropy, norm_dst_entropy};
         return entropies;
     }
     else {
-        return {-1, -1};
+        return {-1, -1, -1, -1};
     }
 }
 
@@ -328,6 +331,8 @@ void statistics::addIntervalStat(std::chrono::duration<int, std::micro> interval
     if(ipCumEntopies.size()>1){
         interval_statistics[lastPktTimestamp_s].ip_src_cum_entropy = ipCumEntopies[0];
         interval_statistics[lastPktTimestamp_s].ip_dst_cum_entropy = ipCumEntopies[1];
+        interval_statistics[lastPktTimestamp_s].ip_src_cum_entropy_norm = ipCumEntopies[2];
+        interval_statistics[lastPktTimestamp_s].ip_dst_cum_entropy_norm = ipCumEntopies[3];
     }
 }
 

+ 4 - 0
code_boost/src/cxx/statistics.h

@@ -252,6 +252,8 @@ struct entry_intervalStat {
     double ip_dst_novel_entropy_norm;
     double ip_src_cum_entropy;
     double ip_dst_cum_entropy;
+    double ip_src_cum_entropy_norm;
+    double ip_dst_cum_entropy_norm;
     std::vector<double> ttl_entropies;
     std::vector<double> win_size_entropies;
     std::vector<double> tos_entropies;
@@ -286,6 +288,8 @@ struct entry_intervalStat {
                && ip_dst_novel_entropy_norm == other.ip_dst_novel_entropy_norm
                && ip_src_cum_entropy == other.ip_src_cum_entropy
                && ip_dst_cum_entropy == other.ip_dst_cum_entropy
+               && ip_src_cum_entropy_norm == other.ip_src_cum_entropy_norm
+               && ip_dst_cum_entropy_norm == other.ip_dst_cum_entropy_norm
                && payload_count == other.payload_count
                && incorrect_tcp_checksum_count == other.incorrect_tcp_checksum_count
                && correct_tcp_checksum_count == other.correct_tcp_checksum_count

+ 2 - 14
code_boost/src/cxx/statistics_db.cpp

@@ -713,18 +713,6 @@ void statistics_db::writeStatisticsInterval(const std::unordered_map<std::string
                     "ip_dst_novel_entropy_normalized REAL,"
                     "PRIMARY KEY(last_pkt_timestamp));");
 
-            double ip_src_cum_entropy = 0.0;
-            double ip_dst_cum_entropy = 0.0;
-            for (auto it = intervalStatistics.begin(); it != intervalStatistics.end(); ++it) {
-                const entry_intervalStat &e = it->second;
-                if (ip_src_cum_entropy < e.ip_src_cum_entropy) {
-                    ip_src_cum_entropy = e.ip_src_cum_entropy;
-                }
-                if (ip_dst_cum_entropy < e.ip_dst_cum_entropy) {
-                    ip_dst_cum_entropy = e.ip_dst_cum_entropy;
-                }
-            }
-
             SQLite::Statement query(*db, "INSERT INTO " + table_name + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
             for (auto it = intervalStatistics.begin(); it != intervalStatistics.end(); ++it) {
                 const entry_intervalStat &e = it->second;
@@ -771,8 +759,8 @@ void statistics_db::writeStatisticsInterval(const std::unordered_map<std::string
                 query.bind(40, e.mss_entropies[3]);
                 query.bind(41, e.ip_src_entropy_norm);
                 query.bind(42, e.ip_dst_entropy_norm);
-                query.bind(43, e.ip_src_cum_entropy/ip_src_cum_entropy);
-                query.bind(44, e.ip_dst_cum_entropy/ip_dst_cum_entropy);
+                query.bind(43, e.ip_src_cum_entropy_norm);
+                query.bind(44, e.ip_dst_cum_entropy_norm);
                 query.bind(45, e.ip_src_novel_entropy);
                 query.bind(46, e.ip_dst_novel_entropy);
                 query.bind(47, e.ip_src_novel_entropy_norm);