|
@@ -248,101 +248,78 @@ void statistics::addConvStat(std::string ipAddressSender,int sport,std::string i
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Registers statistical data for a sent packet in a given stateless conversation (two IPs, two ports).
|
|
|
+ * Registers statistical data for a sent packet in a given extended conversation (two IPs, two ports, protocol).
|
|
|
* Increments the counter packets_A_B or packets_B_A.
|
|
|
* Adds the timestamp of the packet in pkts_A_B_timestamp or pkts_B_A_timestamp.
|
|
|
+ * Updates all other statistics of conv_statistics_extended
|
|
|
* @param ipAddressSender The sender IP address.
|
|
|
* @param sport The source port.
|
|
|
* @param ipAddressReceiver The receiver IP address.
|
|
|
* @param dport The destination port.
|
|
|
+ * @param protocol The used protocol.
|
|
|
* @param timestamp The timestamp of the packet.
|
|
|
*/
|
|
|
-void statistics::addConvStatStateless(std::string ipAddressSender,int sport,std::string ipAddressReceiver,int dport, std::chrono::microseconds timestamp){
|
|
|
+void statistics::addConvStatExt(std::string ipAddressSender,int sport,std::string ipAddressReceiver,int dport,std::string protocol, std::chrono::microseconds timestamp){
|
|
|
+ convWithProt f1 = {ipAddressReceiver, dport, ipAddressSender, sport, protocol};
|
|
|
+ convWithProt f2 = {ipAddressSender, sport, ipAddressReceiver, dport, protocol};
|
|
|
+ convWithProt f;
|
|
|
|
|
|
- conv f1 = {ipAddressReceiver, dport, ipAddressSender, sport};
|
|
|
- conv f2 = {ipAddressSender, sport, ipAddressReceiver, dport};
|
|
|
-
|
|
|
- // if already exist A(ipAddressReceiver, dport), B(ipAddressSender, sport) conversation
|
|
|
- if (conv_statistics_stateless.count(f1)>0){
|
|
|
- conv_statistics_stateless[f1].pkts_count++;
|
|
|
- if(conv_statistics_stateless[f1].pkts_count<=3)
|
|
|
- conv_statistics_stateless[f1].interarrival_time.push_back(std::chrono::duration_cast<std::chrono::microseconds> (timestamp - conv_statistics_stateless[f1].pkts_timestamp.back()));
|
|
|
- conv_statistics_stateless[f1].pkts_timestamp.push_back(timestamp);
|
|
|
- }
|
|
|
- // Add new conversation A(ipAddressSender, sport), B(ipAddressReceiver, dport)
|
|
|
- else{
|
|
|
- conv_statistics_stateless[f2].pkts_count++;
|
|
|
- if(conv_statistics_stateless[f2].pkts_timestamp.size()>0 && conv_statistics_stateless[f2].pkts_count<=3 )
|
|
|
- conv_statistics_stateless[f2].interarrival_time.push_back(std::chrono::duration_cast<std::chrono::microseconds> (timestamp - conv_statistics_stateless[f2].pkts_timestamp.back()));
|
|
|
- conv_statistics_stateless[f2].pkts_timestamp.push_back(timestamp);
|
|
|
- }
|
|
|
-}
|
|
|
+ // if there already exists a communication interval for the specified conversation
|
|
|
+ if (conv_statistics_extended.count(f1) > 0 || conv_statistics_extended.count(f2) > 0){
|
|
|
|
|
|
-/**
|
|
|
- * Adds the passed information to the relevant communication intervals of the respective conversation.
|
|
|
- * If the time between the last message of the latest interval and the timestamp of the current message exceeds
|
|
|
- * the threshold, a new interval is created.
|
|
|
- * Note: here and within the function, conversation refers to a stateless conversation.
|
|
|
- * @param ipAddressSender The sender IP address.
|
|
|
- * @param sport The source port.
|
|
|
- * @param ipAddressReceiver The receiver IP address.
|
|
|
- * @param dport The destination port.
|
|
|
- * @param timestamp The timestamp of the packet.
|
|
|
- */
|
|
|
-
|
|
|
-void statistics::addCommInterval(std::string ipAddressSender,int sport,std::string ipAddressReceiver,int dport, std::chrono::microseconds timestamp){
|
|
|
- conv f1 = {ipAddressReceiver, dport, ipAddressSender, sport};
|
|
|
- conv f2 = {ipAddressSender, sport, ipAddressReceiver, dport};
|
|
|
- conv f;
|
|
|
-
|
|
|
- // if there already exists a communication interval for the specified conversation ...
|
|
|
- if (comm_intervals.count(f1) > 0 || comm_intervals.count(f2) > 0){
|
|
|
-
|
|
|
- // find out which direction of conversation is contained in comm_intervals
|
|
|
- if (comm_intervals.count(f1) > 0)
|
|
|
+ // find out which direction of conversation is contained in conv_statistics_extended
|
|
|
+ if (conv_statistics_extended.count(f1) > 0)
|
|
|
f = f1;
|
|
|
else
|
|
|
f = f2;
|
|
|
|
|
|
- // if the time difference is exceeded, create a new interval with this message
|
|
|
- if (timestamp - comm_intervals[f].back().end > (std::chrono::microseconds) ((unsigned long) COMM_INTERVAL_THRESHOLD)) { // > or >= ?
|
|
|
+ // increase pkts count and check on delay
|
|
|
+ conv_statistics_extended[f].pkts_count++;
|
|
|
+ if (conv_statistics_extended[f].pkts_timestamp.size()>0 && conv_statistics_extended[f].pkts_count<=3)
|
|
|
+ conv_statistics_extended[f].interarrival_time.push_back(std::chrono::duration_cast<std::chrono::microseconds> (timestamp - conv_statistics_extended[f].pkts_timestamp.back()));
|
|
|
+ conv_statistics_extended[f].pkts_timestamp.push_back(timestamp);
|
|
|
+
|
|
|
+ // if the time difference has exceeded the threshold, create a new interval with this message
|
|
|
+ if (timestamp - conv_statistics_extended[f].comm_intervals.back().end > (std::chrono::microseconds) ((unsigned long) COMM_INTERVAL_THRESHOLD)) { // > or >= ?
|
|
|
commInterval new_interval = {timestamp, timestamp, 1};
|
|
|
- comm_intervals[f].push_back(new_interval);
|
|
|
+ conv_statistics_extended[f].comm_intervals.push_back(new_interval);
|
|
|
}
|
|
|
// otherwise, set the time of the last interval message to the current timestamp and increase interval packet count by 1
|
|
|
else{
|
|
|
- comm_intervals[f].back().end = timestamp;
|
|
|
- comm_intervals[f].back().pkts_count++;
|
|
|
+ conv_statistics_extended[f].comm_intervals.back().end = timestamp;
|
|
|
+ conv_statistics_extended[f].comm_intervals.back().pkts_count++;
|
|
|
}
|
|
|
}
|
|
|
- // if there does not exist a communication interval for the specified conversation ...
|
|
|
+ // if there does not exist a communication interval for the specified conversation
|
|
|
else{
|
|
|
- // add initial interval for this conversation
|
|
|
+ // add initial interval entry for this conversation
|
|
|
commInterval initial_interval = {timestamp, timestamp, 1};
|
|
|
|
|
|
- std::vector<commInterval> intervals;
|
|
|
- intervals.push_back(initial_interval);
|
|
|
- comm_intervals[f1] = intervals;
|
|
|
+ entry_convStatExt entry;
|
|
|
+ entry.comm_intervals.push_back(initial_interval);
|
|
|
+ entry.pkts_count = 1;
|
|
|
+ entry.pkts_timestamp.push_back(timestamp);
|
|
|
+ conv_statistics_extended[f2] = entry;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Aggregate the collected information about all communication intervals of every conversation.
|
|
|
+ * Aggregate the collected information about all communication intervals within conv_statistics_extended of every conversation.
|
|
|
* Do this by computing the average packet rate per interval and the average time between intervals.
|
|
|
* Also compute average interval duration and total communication duration (i.e. last_msg.time - first_msg.time)
|
|
|
- * Note: here and within the function, conversation refers to a stateless conversation.
|
|
|
*/
|
|
|
void statistics::createCommIntervalStats(){
|
|
|
- // iterate over all <conv, conv_intervals> pairs
|
|
|
- for (auto &cur_elem : comm_intervals) {
|
|
|
- conv cur_conv = cur_elem.first;
|
|
|
- std::vector<commInterval> intervals = cur_elem.second;
|
|
|
+ // iterate over all <convWithProt, entry_convStatExt> pairs
|
|
|
+ for (auto &cur_elem : conv_statistics_extended) {
|
|
|
+ entry_convStatExt &entry = cur_elem.second;
|
|
|
+ std::vector<commInterval> &intervals = entry.comm_intervals;
|
|
|
|
|
|
// if there is only one interval, the time between intervals cannot be computed and is therefore set to 0
|
|
|
if (intervals.size() == 1){
|
|
|
double interval_duration = (double) (intervals[0].end - intervals[0].start).count() / (double) 1e6;
|
|
|
- entry_commIntervalStat e = {(double) intervals[0].pkts_count, (double) 0, interval_duration, interval_duration};
|
|
|
- comm_interval_statistics[cur_conv] = e;
|
|
|
+ entry.avg_int_pkts_count = (double) intervals[0].pkts_count;
|
|
|
+ entry.avg_time_between_ints = (double) 0;
|
|
|
+ entry.avg_interval_time = interval_duration;
|
|
|
}
|
|
|
// If there is more than one interval, compute the specified averages
|
|
|
else if (intervals.size() > 1){
|
|
@@ -356,13 +333,12 @@ void statistics::createCommIntervalStats(){
|
|
|
time_between_ints_sum += intervals[i].start - intervals[i - 1].end;
|
|
|
}
|
|
|
|
|
|
- double avg_pkts_count = summed_pkts_count / ((double) intervals.size());
|
|
|
- double avg_time_betw_ints = (time_between_ints_sum.count() / (double) (intervals.size() - 1)) / (double) 1e6;
|
|
|
- double avg_interval_time = (summed_int_duration.count() / (double) intervals.size()) / (double) 1e6;
|
|
|
- double total_comm_duration = (double) (intervals.back().end - intervals.front().start).count() / (double) 1e6;
|
|
|
- entry_commIntervalStat e = {avg_pkts_count, avg_time_betw_ints, avg_interval_time, total_comm_duration};
|
|
|
- comm_interval_statistics[cur_conv] = e;
|
|
|
+ entry.avg_int_pkts_count = summed_pkts_count / ((double) intervals.size());
|
|
|
+ entry.avg_time_between_ints = (time_between_ints_sum.count() / (double) (intervals.size() - 1)) / (double) 1e6;
|
|
|
+ entry.avg_interval_time = (summed_int_duration.count() / (double) intervals.size()) / (double) 1e6;
|
|
|
+
|
|
|
}
|
|
|
+ entry.total_comm_duration = (double) (entry.pkts_timestamp.back() - entry.pkts_timestamp.front()).count() / (double) 1e6;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -720,9 +696,8 @@ void statistics::writeToDatabase(std::string database_path) {
|
|
|
db.writeStatisticsToS(tos_distribution);
|
|
|
db.writeStatisticsWin(win_distribution);
|
|
|
db.writeStatisticsConv(conv_statistics);
|
|
|
- db.writeStatisticsConvStateless(conv_statistics_stateless);
|
|
|
+ db.writeStatisticsConvExt(conv_statistics_extended);
|
|
|
db.writeStatisticsInterval(interval_statistics);
|
|
|
- db.writeCommIntervalStats(comm_interval_statistics);
|
|
|
}
|
|
|
else {
|
|
|
// Tinslib failed to recognize the types of the packets in the input PCAP
|