|
@@ -27,7 +27,7 @@ statistics_db::statistics_db(std::string database_path) {
|
|
|
* Writes the IP statistics into the database.
|
|
|
* @param ipStatistics The IP statistics from class statistics.
|
|
|
*/
|
|
|
-void statistics_db::writeStatisticsIP(std::unordered_map<std::string, entry_ipStat> ipStatistics) {
|
|
|
+void statistics_db::writeStatisticsIP(const std::unordered_map<std::string, entry_ipStat> &ipStatistics) {
|
|
|
try {
|
|
|
db->exec("DROP TABLE IF EXISTS ip_statistics");
|
|
|
SQLite::Transaction transaction(*db);
|
|
@@ -44,15 +44,15 @@ void statistics_db::writeStatisticsIP(std::unordered_map<std::string, entry_ipSt
|
|
|
db->exec(createTable);
|
|
|
SQLite::Statement query(*db, "INSERT INTO ip_statistics VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
|
|
|
for (auto it = ipStatistics.begin(); it != ipStatistics.end(); ++it) {
|
|
|
- entry_ipStat e = it->second;
|
|
|
- query.bind(1, it->first);
|
|
|
+ const entry_ipStat &e = it->second;
|
|
|
+ query.bindNoCopy(1, it->first);
|
|
|
query.bind(2, (int) e.pkts_received);
|
|
|
query.bind(3, (int) e.pkts_sent);
|
|
|
query.bind(4, e.kbytes_received);
|
|
|
query.bind(5, e.kbytes_sent);
|
|
|
query.bind(6, e.max_interval_pkt_rate);
|
|
|
query.bind(7, e.min_interval_pkt_rate);
|
|
|
- query.bind(8, e.ip_class);
|
|
|
+ query.bindNoCopy(8, e.ip_class);
|
|
|
query.exec();
|
|
|
query.reset();
|
|
|
}
|
|
@@ -68,7 +68,7 @@ void statistics_db::writeStatisticsIP(std::unordered_map<std::string, entry_ipSt
|
|
|
* @param ipStatistics The IP statistics from class statistics. Degree Statistics are supposed to be integrated into the ip_statistics table later on,
|
|
|
* therefore they use the same parameter. But for now they are inserted into their own table.
|
|
|
*/
|
|
|
-void statistics_db::writeStatisticsDegree(std::unordered_map<std::string, entry_ipStat> ipStatistics){
|
|
|
+void statistics_db::writeStatisticsDegree(const std::unordered_map<std::string, entry_ipStat> &ipStatistics){
|
|
|
try {
|
|
|
db->exec("DROP TABLE IF EXISTS ip_degrees");
|
|
|
SQLite::Transaction transaction(*db);
|
|
@@ -81,8 +81,8 @@ void statistics_db::writeStatisticsDegree(std::unordered_map<std::string, entry_
|
|
|
db->exec(createTable);
|
|
|
SQLite::Statement query(*db, "INSERT INTO ip_degrees VALUES (?, ?, ?, ?)");
|
|
|
for (auto it = ipStatistics.begin(); it != ipStatistics.end(); ++it) {
|
|
|
- entry_ipStat e = it->second;
|
|
|
- query.bind(1, it->first);
|
|
|
+ const entry_ipStat &e = it->second;
|
|
|
+ query.bindNoCopy(1, it->first);
|
|
|
query.bind(2, e.in_degree);
|
|
|
query.bind(3, e.out_degree);
|
|
|
query.bind(4, e.overall_degree);
|
|
@@ -100,7 +100,7 @@ void statistics_db::writeStatisticsDegree(std::unordered_map<std::string, entry_
|
|
|
* Writes the TTL distribution into the database.
|
|
|
* @param ttlDistribution The TTL distribution from class statistics.
|
|
|
*/
|
|
|
-void statistics_db::writeStatisticsTTL(std::unordered_map<ipAddress_ttl, int> ttlDistribution) {
|
|
|
+void statistics_db::writeStatisticsTTL(const std::unordered_map<ipAddress_ttl, int> &ttlDistribution) {
|
|
|
try {
|
|
|
db->exec("DROP TABLE IF EXISTS ip_ttl");
|
|
|
SQLite::Transaction transaction(*db);
|
|
@@ -112,8 +112,8 @@ void statistics_db::writeStatisticsTTL(std::unordered_map<ipAddress_ttl, int> tt
|
|
|
db->exec(createTable);
|
|
|
SQLite::Statement query(*db, "INSERT INTO ip_ttl VALUES (?, ?, ?)");
|
|
|
for (auto it = ttlDistribution.begin(); it != ttlDistribution.end(); ++it) {
|
|
|
- ipAddress_ttl e = it->first;
|
|
|
- query.bind(1, e.ipAddress);
|
|
|
+ const ipAddress_ttl &e = it->first;
|
|
|
+ query.bindNoCopy(1, e.ipAddress);
|
|
|
query.bind(2, e.ttlValue);
|
|
|
query.bind(3, it->second);
|
|
|
query.exec();
|
|
@@ -130,7 +130,7 @@ void statistics_db::writeStatisticsTTL(std::unordered_map<ipAddress_ttl, int> tt
|
|
|
* Writes the MSS distribution into the database.
|
|
|
* @param mssDistribution The MSS distribution from class statistics.
|
|
|
*/
|
|
|
-void statistics_db::writeStatisticsMSS(std::unordered_map<ipAddress_mss, int> mssDistribution) {
|
|
|
+void statistics_db::writeStatisticsMSS(const std::unordered_map<ipAddress_mss, int> &mssDistribution) {
|
|
|
try {
|
|
|
db->exec("DROP TABLE IF EXISTS tcp_mss");
|
|
|
SQLite::Transaction transaction(*db);
|
|
@@ -142,8 +142,8 @@ void statistics_db::writeStatisticsMSS(std::unordered_map<ipAddress_mss, int> ms
|
|
|
db->exec(createTable);
|
|
|
SQLite::Statement query(*db, "INSERT INTO tcp_mss VALUES (?, ?, ?)");
|
|
|
for (auto it = mssDistribution.begin(); it != mssDistribution.end(); ++it) {
|
|
|
- ipAddress_mss e = it->first;
|
|
|
- query.bind(1, e.ipAddress);
|
|
|
+ const ipAddress_mss &e = it->first;
|
|
|
+ query.bindNoCopy(1, e.ipAddress);
|
|
|
query.bind(2, e.mssValue);
|
|
|
query.bind(3, it->second);
|
|
|
query.exec();
|
|
@@ -160,7 +160,7 @@ void statistics_db::writeStatisticsMSS(std::unordered_map<ipAddress_mss, int> ms
|
|
|
* Writes the ToS distribution into the database.
|
|
|
* @param tosDistribution The ToS distribution from class statistics.
|
|
|
*/
|
|
|
-void statistics_db::writeStatisticsToS(std::unordered_map<ipAddress_tos, int> tosDistribution) {
|
|
|
+void statistics_db::writeStatisticsToS(const std::unordered_map<ipAddress_tos, int> &tosDistribution) {
|
|
|
try {
|
|
|
db->exec("DROP TABLE IF EXISTS ip_tos");
|
|
|
SQLite::Transaction transaction(*db);
|
|
@@ -172,8 +172,8 @@ void statistics_db::writeStatisticsToS(std::unordered_map<ipAddress_tos, int> to
|
|
|
db->exec(createTable);
|
|
|
SQLite::Statement query(*db, "INSERT INTO ip_tos VALUES (?, ?, ?)");
|
|
|
for (auto it = tosDistribution.begin(); it != tosDistribution.end(); ++it) {
|
|
|
- ipAddress_tos e = it->first;
|
|
|
- query.bind(1, e.ipAddress);
|
|
|
+ const ipAddress_tos &e = it->first;
|
|
|
+ query.bindNoCopy(1, e.ipAddress);
|
|
|
query.bind(2, e.tosValue);
|
|
|
query.bind(3, it->second);
|
|
|
query.exec();
|
|
@@ -190,7 +190,7 @@ void statistics_db::writeStatisticsToS(std::unordered_map<ipAddress_tos, int> to
|
|
|
* Writes the window size distribution into the database.
|
|
|
* @param winDistribution The window size distribution from class statistics.
|
|
|
*/
|
|
|
-void statistics_db::writeStatisticsWin(std::unordered_map<ipAddress_win, int> winDistribution) {
|
|
|
+void statistics_db::writeStatisticsWin(const std::unordered_map<ipAddress_win, int> &winDistribution) {
|
|
|
try {
|
|
|
db->exec("DROP TABLE IF EXISTS tcp_win");
|
|
|
SQLite::Transaction transaction(*db);
|
|
@@ -202,8 +202,8 @@ void statistics_db::writeStatisticsWin(std::unordered_map<ipAddress_win, int> wi
|
|
|
db->exec(createTable);
|
|
|
SQLite::Statement query(*db, "INSERT INTO tcp_win VALUES (?, ?, ?)");
|
|
|
for (auto it = winDistribution.begin(); it != winDistribution.end(); ++it) {
|
|
|
- ipAddress_win e = it->first;
|
|
|
- query.bind(1, e.ipAddress);
|
|
|
+ const ipAddress_win &e = it->first;
|
|
|
+ query.bindNoCopy(1, e.ipAddress);
|
|
|
query.bind(2, e.winSize);
|
|
|
query.bind(3, it->second);
|
|
|
query.exec();
|
|
@@ -220,7 +220,7 @@ void statistics_db::writeStatisticsWin(std::unordered_map<ipAddress_win, int> wi
|
|
|
* Writes the protocol distribution into the database.
|
|
|
* @param protocolDistribution The protocol distribution from class statistics.
|
|
|
*/
|
|
|
-void statistics_db::writeStatisticsProtocols(std::unordered_map<ipAddress_protocol, entry_protocolStat> protocolDistribution) {
|
|
|
+void statistics_db::writeStatisticsProtocols(const std::unordered_map<ipAddress_protocol, entry_protocolStat> &protocolDistribution) {
|
|
|
try {
|
|
|
db->exec("DROP TABLE IF EXISTS ip_protocols");
|
|
|
SQLite::Transaction transaction(*db);
|
|
@@ -233,9 +233,9 @@ void statistics_db::writeStatisticsProtocols(std::unordered_map<ipAddress_protoc
|
|
|
db->exec(createTable);
|
|
|
SQLite::Statement query(*db, "INSERT INTO ip_protocols VALUES (?, ?, ?, ?)");
|
|
|
for (auto it = protocolDistribution.begin(); it != protocolDistribution.end(); ++it) {
|
|
|
- ipAddress_protocol e = it->first;
|
|
|
- query.bind(1, e.ipAddress);
|
|
|
- query.bind(2, e.protocol);
|
|
|
+ const ipAddress_protocol &e = it->first;
|
|
|
+ query.bindNoCopy(1, e.ipAddress);
|
|
|
+ query.bindNoCopy(2, e.protocol);
|
|
|
query.bind(3, it->second.count);
|
|
|
query.bind(4, it->second.byteCount);
|
|
|
query.exec();
|
|
@@ -252,7 +252,7 @@ void statistics_db::writeStatisticsProtocols(std::unordered_map<ipAddress_protoc
|
|
|
* Writes the port statistics into the database.
|
|
|
* @param portsStatistics The ports statistics from class statistics.
|
|
|
*/
|
|
|
-void statistics_db::writeStatisticsPorts(std::unordered_map<ipAddress_inOut_port, entry_portStat> portsStatistics) {
|
|
|
+void statistics_db::writeStatisticsPorts(const std::unordered_map<ipAddress_inOut_port, entry_portStat> &portsStatistics) {
|
|
|
try {
|
|
|
db->exec("DROP TABLE IF EXISTS ip_ports");
|
|
|
SQLite::Transaction transaction(*db);
|
|
@@ -264,11 +264,11 @@ void statistics_db::writeStatisticsPorts(std::unordered_map<ipAddress_inOut_port
|
|
|
"byteCount REAL,"
|
|
|
"portProtocol TEXT COLLATE NOCASE,"
|
|
|
"portService TEXT COLLATE NOCASE,"
|
|
|
- "PRIMARY KEY(ipAddress,portDirection,portNumber));";
|
|
|
+ "PRIMARY KEY(ipAddress,portDirection,portNumber,portProtocol));";
|
|
|
db->exec(createTable);
|
|
|
SQLite::Statement query(*db, "INSERT INTO ip_ports VALUES (?, ?, ?, ?, ?, ?, ?)");
|
|
|
for (auto it = portsStatistics.begin(); it != portsStatistics.end(); ++it) {
|
|
|
- ipAddress_inOut_port e = it->first;
|
|
|
+ const ipAddress_inOut_port &e = it->first;
|
|
|
|
|
|
std::string portService = portServices[e.portNumber];
|
|
|
if(portService.empty()) {
|
|
@@ -276,13 +276,13 @@ void statistics_db::writeStatisticsPorts(std::unordered_map<ipAddress_inOut_port
|
|
|
else {portService = "unknown";}
|
|
|
}
|
|
|
|
|
|
- query.bind(1, e.ipAddress);
|
|
|
- query.bind(2, e.trafficDirection);
|
|
|
+ query.bindNoCopy(1, e.ipAddress);
|
|
|
+ query.bindNoCopy(2, e.trafficDirection);
|
|
|
query.bind(3, e.portNumber);
|
|
|
query.bind(4, it->second.count);
|
|
|
query.bind(5, it->second.byteCount);
|
|
|
- query.bind(6, e.protocol);
|
|
|
- query.bind(7, portService);
|
|
|
+ query.bindNoCopy(6, e.protocol);
|
|
|
+ query.bindNoCopy(7, portService);
|
|
|
query.exec();
|
|
|
query.reset();
|
|
|
}
|
|
@@ -297,7 +297,7 @@ void statistics_db::writeStatisticsPorts(std::unordered_map<ipAddress_inOut_port
|
|
|
* Writes the IP address -> MAC address mapping into the database.
|
|
|
* @param IpMacStatistics The IP address -> MAC address mapping from class statistics.
|
|
|
*/
|
|
|
-void statistics_db::writeStatisticsIpMac(std::unordered_map<std::string, std::string> IpMacStatistics) {
|
|
|
+void statistics_db::writeStatisticsIpMac(const std::unordered_map<std::string, std::string> &IpMacStatistics) {
|
|
|
try {
|
|
|
db->exec("DROP TABLE IF EXISTS ip_mac");
|
|
|
SQLite::Transaction transaction(*db);
|
|
@@ -308,8 +308,8 @@ void statistics_db::writeStatisticsIpMac(std::unordered_map<std::string, std::st
|
|
|
db->exec(createTable);
|
|
|
SQLite::Statement query(*db, "INSERT INTO ip_mac VALUES (?, ?)");
|
|
|
for (auto it = IpMacStatistics.begin(); it != IpMacStatistics.end(); ++it) {
|
|
|
- query.bind(1, it->first);
|
|
|
- query.bind(2, it->second);
|
|
|
+ query.bindNoCopy(1, it->first);
|
|
|
+ query.bindNoCopy(2, it->second);
|
|
|
query.exec();
|
|
|
query.reset();
|
|
|
}
|
|
@@ -334,7 +334,8 @@ void statistics_db::writeStatisticsIpMac(std::unordered_map<std::string, std::st
|
|
|
*/
|
|
|
void statistics_db::writeStatisticsFile(int packetCount, float captureDuration, std::string timestampFirstPkt,
|
|
|
std::string timestampLastPkt, float avgPacketRate, float avgPacketSize,
|
|
|
- float avgPacketsSentPerHost, float avgBandwidthIn, float avgBandwidthOut) {
|
|
|
+ float avgPacketsSentPerHost, float avgBandwidthIn, float avgBandwidthOut,
|
|
|
+ bool doExtraTests) {
|
|
|
try {
|
|
|
db->exec("DROP TABLE IF EXISTS file_statistics");
|
|
|
SQLite::Transaction transaction(*db);
|
|
@@ -347,9 +348,10 @@ void statistics_db::writeStatisticsFile(int packetCount, float captureDuration,
|
|
|
"avgPacketSize REAL,"
|
|
|
"avgPacketsSentPerHost REAL,"
|
|
|
"avgBandwidthIn REAL,"
|
|
|
- "avgBandwidthOut REAL);";
|
|
|
+ "avgBandwidthOut REAL,"
|
|
|
+ "doExtraTests INTEGER);";
|
|
|
db->exec(createTable);
|
|
|
- SQLite::Statement query(*db, "INSERT INTO file_statistics VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
|
|
+ SQLite::Statement query(*db, "INSERT INTO file_statistics VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
|
|
query.bind(1, packetCount);
|
|
|
query.bind(2, captureDuration);
|
|
|
query.bind(3, timestampFirstPkt);
|
|
@@ -359,6 +361,7 @@ void statistics_db::writeStatisticsFile(int packetCount, float captureDuration,
|
|
|
query.bind(7, avgPacketsSentPerHost);
|
|
|
query.bind(8, avgBandwidthIn);
|
|
|
query.bind(9, avgBandwidthOut);
|
|
|
+ query.bind(10, doExtraTests);
|
|
|
query.exec();
|
|
|
transaction.commit();
|
|
|
}
|
|
@@ -372,7 +375,7 @@ void statistics_db::writeStatisticsFile(int packetCount, float captureDuration,
|
|
|
* Writes the conversation statistics into the database.
|
|
|
* @param convStatistics The conversation from class statistics.
|
|
|
*/
|
|
|
-void statistics_db::writeStatisticsConv(std::unordered_map<conv, entry_convStat> convStatistics){
|
|
|
+void statistics_db::writeStatisticsConv(std::unordered_map<conv, entry_convStat> &convStatistics){
|
|
|
try {
|
|
|
db->exec("DROP TABLE IF EXISTS conv_statistics");
|
|
|
SQLite::Transaction transaction(*db);
|
|
@@ -392,8 +395,8 @@ void statistics_db::writeStatisticsConv(std::unordered_map<conv, entry_convStat>
|
|
|
|
|
|
// Calculate average of inter-arrival times and average packet rate
|
|
|
for (auto it = convStatistics.begin(); it != convStatistics.end(); ++it) {
|
|
|
- conv f = it->first;
|
|
|
- entry_convStat e = it->second;
|
|
|
+ const conv &f = it->first;
|
|
|
+ entry_convStat &e = it->second;
|
|
|
if (e.pkts_count > 1){
|
|
|
int sumDelay = 0;
|
|
|
int minDelay = -1;
|
|
@@ -414,9 +417,9 @@ void statistics_db::writeStatisticsConv(std::unordered_map<conv, entry_convStat>
|
|
|
std::chrono::microseconds conn_duration = end_timesttamp - start_timesttamp;
|
|
|
e.avg_pkt_rate = (float) e.pkts_count * 1000000 / conn_duration.count(); // pkt per sec
|
|
|
|
|
|
- query.bind(1, f.ipAddressA);
|
|
|
+ query.bindNoCopy(1, f.ipAddressA);
|
|
|
query.bind(2, f.portA);
|
|
|
- query.bind(3, f.ipAddressB);
|
|
|
+ query.bindNoCopy(3, f.ipAddressB);
|
|
|
query.bind(4, f.portB);
|
|
|
query.bind(5, (int) e.pkts_count);
|
|
|
query.bind(6, (float) e.avg_pkt_rate);
|
|
@@ -438,7 +441,7 @@ void statistics_db::writeStatisticsConv(std::unordered_map<conv, entry_convStat>
|
|
|
* Writes the extended statistics for every conversation into the database.
|
|
|
* @param conv_statistics_extended The extended conversation statistics from class statistics.
|
|
|
*/
|
|
|
-void statistics_db::writeStatisticsConvExt(std::unordered_map<convWithProt, entry_convStatExt> conv_statistics_extended){
|
|
|
+void statistics_db::writeStatisticsConvExt(std::unordered_map<convWithProt, entry_convStatExt> &conv_statistics_extended){
|
|
|
try {
|
|
|
db->exec("DROP TABLE IF EXISTS conv_statistics_extended");
|
|
|
SQLite::Transaction transaction(*db);
|
|
@@ -447,7 +450,7 @@ void statistics_db::writeStatisticsConvExt(std::unordered_map<convWithProt, entr
|
|
|
"portA INTEGER,"
|
|
|
"ipAddressB TEXT,"
|
|
|
"portB INTEGER,"
|
|
|
- "protocol TEXT,"
|
|
|
+ "protocol TEXT COLLATE NOCASE,"
|
|
|
"pktsCount INTEGER,"
|
|
|
"avgPktRate REAL,"
|
|
|
"avgDelay INTEGER,"
|
|
@@ -462,8 +465,8 @@ void statistics_db::writeStatisticsConvExt(std::unordered_map<convWithProt, entr
|
|
|
SQLite::Statement query(*db, "INSERT INTO conv_statistics_extended VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
|
|
// iterate over every conversation and interval aggregation pair and store the respective values in the database
|
|
|
for (auto it = conv_statistics_extended.begin(); it != conv_statistics_extended.end(); ++it) {
|
|
|
- convWithProt f = it->first;
|
|
|
- entry_convStatExt e = it->second;
|
|
|
+ const convWithProt &f = it->first;
|
|
|
+ entry_convStatExt &e = it->second;
|
|
|
|
|
|
int sumDelay = 0;
|
|
|
int minDelay = -1;
|
|
@@ -489,42 +492,34 @@ void statistics_db::writeStatisticsConvExt(std::unordered_map<convWithProt, entr
|
|
|
e.avg_pkt_rate = e.pkts_count / e.total_comm_duration;
|
|
|
|
|
|
if (e.avg_int_pkts_count > 0){
|
|
|
- query.bind(1, f.ipAddressA);
|
|
|
+ query.bindNoCopy(1, f.ipAddressA);
|
|
|
query.bind(2, f.portA);
|
|
|
- query.bind(3, f.ipAddressB);
|
|
|
+ query.bindNoCopy(3, f.ipAddressB);
|
|
|
query.bind(4, f.portB);
|
|
|
- query.bind(5, f.protocol);
|
|
|
+ query.bindNoCopy(5, f.protocol);
|
|
|
query.bind(6, (int) e.pkts_count);
|
|
|
query.bind(7, (float) e.avg_pkt_rate);
|
|
|
- query.bind(8, (int) e.avg_interarrival_time.count());
|
|
|
- query.bind(9, minDelay);
|
|
|
- query.bind(10, maxDelay);
|
|
|
+
|
|
|
+ if (f.protocol == "UDP" || (f.protocol == "TCP" && e.pkts_count < 2))
|
|
|
+ query.bind(8);
|
|
|
+ else
|
|
|
+ query.bind(8, (int) e.avg_interarrival_time.count());
|
|
|
+
|
|
|
+ if (minDelay == -1)
|
|
|
+ query.bind(9);
|
|
|
+ else
|
|
|
+ query.bind(9, minDelay);
|
|
|
+
|
|
|
+ if (maxDelay == -1)
|
|
|
+ query.bind(10);
|
|
|
+ else
|
|
|
+ query.bind(10, maxDelay);
|
|
|
+
|
|
|
query.bind(11, e.avg_int_pkts_count);
|
|
|
query.bind(12, e.avg_time_between_ints);
|
|
|
query.bind(13, e.avg_interval_time);
|
|
|
query.bind(14, e.total_comm_duration);
|
|
|
query.exec();
|
|
|
-
|
|
|
- std::string primary_where = "WHERE ipAddressA=\"" + f.ipAddressA + "\" AND portA=" + std::to_string(f.portA) + " AND ipAddressB=\"";
|
|
|
- primary_where += f.ipAddressB + "\" AND portB=" + std::to_string(f.portB) + " AND protocol=\"" + f.protocol + "\";";
|
|
|
- std::string update_stmt;
|
|
|
-
|
|
|
- // replace -1 with null
|
|
|
- if (minDelay == -1){
|
|
|
- update_stmt = "UPDATE conv_statistics_extended SET minDelay=NULL " + primary_where;
|
|
|
- db->exec(update_stmt);
|
|
|
- }
|
|
|
-
|
|
|
- if (maxDelay == -1){
|
|
|
- update_stmt = "UPDATE conv_statistics_extended SET maxDelay=NULL " + primary_where;
|
|
|
- db->exec(update_stmt);
|
|
|
- }
|
|
|
-
|
|
|
- if (f.protocol == "UDP" || (f.protocol == "TCP" && e.pkts_count < 2)){
|
|
|
- update_stmt = "UPDATE conv_statistics_extended SET avgDelay=NULL " + primary_where;
|
|
|
- db->exec(update_stmt);
|
|
|
- }
|
|
|
-
|
|
|
query.reset();
|
|
|
}
|
|
|
|
|
@@ -540,7 +535,7 @@ void statistics_db::writeStatisticsConvExt(std::unordered_map<convWithProt, entr
|
|
|
* Writes the interval statistics into the database.
|
|
|
* @param intervalStatistics The interval entries from class statistics.
|
|
|
*/
|
|
|
-void statistics_db::writeStatisticsInterval(std::unordered_map<std::string, entry_intervalStat> intervalStatistics){
|
|
|
+void statistics_db::writeStatisticsInterval(const std::unordered_map<std::string, entry_intervalStat> &intervalStatistics){
|
|
|
try {
|
|
|
db->exec("DROP TABLE IF EXISTS interval_statistics");
|
|
|
SQLite::Transaction transaction(*db);
|
|
@@ -565,10 +560,9 @@ void statistics_db::writeStatisticsInterval(std::unordered_map<std::string, entr
|
|
|
db->exec(createTable);
|
|
|
SQLite::Statement query(*db, "INSERT INTO interval_statistics VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
|
|
for (auto it = intervalStatistics.begin(); it != intervalStatistics.end(); ++it) {
|
|
|
- std::string t = it->first;
|
|
|
- entry_intervalStat e = it->second;
|
|
|
+ const entry_intervalStat &e = it->second;
|
|
|
|
|
|
- query.bind(1, t);
|
|
|
+ query.bindNoCopy(1, it->first);
|
|
|
query.bind(2, (int)e.pkts_count);
|
|
|
query.bind(3, e.kbytes);
|
|
|
query.bind(4, e.ip_src_entropy);
|
|
@@ -707,8 +701,8 @@ bool statistics_db::pathExists(std::string path)
|
|
|
* Writes the unrecognized PDUs into the database.
|
|
|
* @param unrecognized_PDUs The unrecognized PDUs from class statistics.
|
|
|
*/
|
|
|
-void statistics_db::writeStatisticsUnrecognizedPDUs(std::unordered_map<unrecognized_PDU, unrecognized_PDU_stat>
|
|
|
- unrecognized_PDUs) {
|
|
|
+void statistics_db::writeStatisticsUnrecognizedPDUs(const std::unordered_map<unrecognized_PDU, unrecognized_PDU_stat>
|
|
|
+ &unrecognized_PDUs) {
|
|
|
try {
|
|
|
db->exec("DROP TABLE IF EXISTS unrecognized_pdus");
|
|
|
SQLite::Transaction transaction(*db);
|
|
@@ -722,12 +716,12 @@ void statistics_db::writeStatisticsUnrecognizedPDUs(std::unordered_map<unrecogni
|
|
|
db->exec(createTable);
|
|
|
SQLite::Statement query(*db, "INSERT INTO unrecognized_pdus VALUES (?, ?, ?, ?, ?)");
|
|
|
for (auto it = unrecognized_PDUs.begin(); it != unrecognized_PDUs.end(); ++it) {
|
|
|
- unrecognized_PDU e = it->first;
|
|
|
- query.bind(1, e.srcMacAddress);
|
|
|
- query.bind(2, e.dstMacAddress);
|
|
|
+ const unrecognized_PDU &e = it->first;
|
|
|
+ query.bindNoCopy(1, e.srcMacAddress);
|
|
|
+ query.bindNoCopy(2, e.dstMacAddress);
|
|
|
query.bind(3, e.typeNumber);
|
|
|
query.bind(4, it->second.count);
|
|
|
- query.bind(5, it->second.timestamp_last_occurrence);
|
|
|
+ query.bindNoCopy(5, it->second.timestamp_last_occurrence);
|
|
|
query.exec();
|
|
|
query.reset();
|
|
|
}
|
|
@@ -736,4 +730,4 @@ void statistics_db::writeStatisticsUnrecognizedPDUs(std::unordered_map<unrecogni
|
|
|
catch (std::exception &e) {
|
|
|
std::cout << "Exception in statistics_db: " << e.what() << std::endl;
|
|
|
}
|
|
|
-}
|
|
|
+}
|