瀏覽代碼

WIP: Use IP addresses instead of std::string

Stefan Schmidt 6 年之前
父節點
當前提交
b3be72382a

+ 4 - 4
code_boost/src/cxx/pcap_processor.cpp

@@ -248,14 +248,14 @@ void pcap_processor::process_packets(const Packet &pkt) {
     // Layer 3 - Network -------------------------------
     const PDU *pdu_l3 = pkt.pdu()->inner_pdu();
     const PDU::PDUType pdu_l3_type = pdu_l3->pdu_type();
-    std::string ipAddressSender;
-    std::string ipAddressReceiver;
+    IPv4Address ipAddressSender;
+    IPv4Address ipAddressReceiver;
 
     // PDU is IPv4
     if (pdu_l3_type == PDU::PDUType::IP) {
         const IP &ipLayer = (const IP &) *pdu_l3;
-        ipAddressSender = ipLayer.src_addr().to_string();
-        ipAddressReceiver = ipLayer.dst_addr().to_string();
+        ipAddressSender = ipLayer.src_addr();
+        ipAddressReceiver = ipLayer.dst_addr();
 
         // IP distribution
         stats.addIpStat_packetSent(ipAddressSender, ipAddressReceiver, sizeCurrentPacket, pkt.timestamp());

+ 19 - 19
code_boost/src/cxx/statistics.cpp

@@ -32,7 +32,7 @@ void statistics::checkPayload(const PDU *pdu_l4) {
  * @param ipAddressReceiver The destination IP.
  * @param tcpPkt The packet to get checked.
  */
-void statistics::checkTCPChecksum(const std::string &ipAddressSender, const std::string &ipAddressReceiver, TCP tcpPkt) {
+void statistics::checkTCPChecksum(const IPv4Address ipAddressSender, const IPv4Address ipAddressReceiver, TCP tcpPkt) {
     if(this->getDoExtraTests()) {
         if(check_tcpChecksum(ipAddressSender, ipAddressReceiver, tcpPkt))
             correctTCPChecksumCount++;
@@ -112,7 +112,7 @@ std::vector<float> statistics::calculateLastIntervalIPsEntropy(std::chrono::micr
  */
 std::vector<float> statistics::calculateIPsCumEntropy(){
     if(this->getDoExtraTests()) {
-        std::vector <std::string> IPs;
+        std::vector <IPv4Address> IPs;
         std::vector <float> IPsSrcProb;
         std::vector <float> IPsDstProb;
 
@@ -226,7 +226,7 @@ void statistics::addIntervalStat(std::chrono::duration<int, std::micro> interval
  * @param dport The destination port.
  * @param timestamp The timestamp of the packet.
  */
-void statistics::addConvStat(const std::string &ipAddressSender,int sport,const std::string &ipAddressReceiver,int dport, std::chrono::microseconds timestamp){
+void statistics::addConvStat(const IPv4Address ipAddressSender,int sport,const IPv4Address ipAddressReceiver,int dport, std::chrono::microseconds timestamp){
 
     conv f1 = {ipAddressReceiver, dport, ipAddressSender, sport};
     conv f2 = {ipAddressSender, sport, ipAddressReceiver, dport};
@@ -259,7 +259,7 @@ void statistics::addConvStat(const std::string &ipAddressSender,int sport,const
  * @param protocol The used protocol.
  * @param timestamp The timestamp of the packet.
  */
-void statistics::addConvStatExt(const std::string &ipAddressSender,int sport,const std::string &ipAddressReceiver,int dport,const std::string &protocol, std::chrono::microseconds timestamp){
+void statistics::addConvStatExt(const IPv4Address ipAddressSender,int sport, const IPv4Address ipAddressReceiver,int dport,const std::string &protocol, std::chrono::microseconds timestamp){
     if(this->getDoExtraTests()) {
         convWithProt f1 = {ipAddressReceiver, dport, ipAddressSender, sport, protocol};
         convWithProt f2 = {ipAddressSender, sport, ipAddressReceiver, dport, protocol};
@@ -349,7 +349,7 @@ void statistics::createCommIntervalStats(){
  * @param ipAddress The IP address whose MSS packet counter should be incremented.
  * @param mssValue The MSS value of the packet.
  */
-void statistics::incrementMSScount(const std::string &ipAddress, int mssValue) {
+void statistics::incrementMSScount(const IPv4Address ipAddress, int mssValue) {
     mss_values[mssValue]++;
     mss_distribution[{ipAddress, mssValue}]++;
 }
@@ -359,7 +359,7 @@ void statistics::incrementMSScount(const std::string &ipAddress, int mssValue) {
  * @param ipAddress The IP address whose window size packet counter should be incremented.
  * @param winSize The window size of the packet.
  */
-void statistics::incrementWinCount(const std::string &ipAddress, int winSize) {
+void statistics::incrementWinCount(const IPv4Address ipAddress, int winSize) {
     win_values[winSize]++;
     win_distribution[{ipAddress, winSize}]++;
 }
@@ -369,7 +369,7 @@ void statistics::incrementWinCount(const std::string &ipAddress, int winSize) {
  * @param ipAddress The IP address whose TTL packet counter should be incremented.
  * @param ttlValue The TTL value of the packet.
  */
-void statistics::incrementTTLcount(const std::string &ipAddress, int ttlValue) {
+void statistics::incrementTTLcount(const IPv4Address ipAddress, int ttlValue) {
     ttl_values[ttlValue]++;
     ttl_distribution[{ipAddress, ttlValue}]++;
 }
@@ -379,7 +379,7 @@ void statistics::incrementTTLcount(const std::string &ipAddress, int ttlValue) {
  * @param ipAddress The IP address whose ToS packet counter should be incremented.
  * @param tosValue The ToS value of the packet.
  */
-void statistics::incrementToScount(const std::string &ipAddress, int tosValue) {
+void statistics::incrementToScount(const IPv4Address ipAddress, int tosValue) {
     tos_values[tosValue]++;
     tos_distribution[{ipAddress, tosValue}]++;
 }
@@ -389,7 +389,7 @@ void statistics::incrementToScount(const std::string &ipAddress, int tosValue) {
  * @param ipAddress The IP address whose protocol packet counter should be incremented.
  * @param protocol The protocol of the packet.
  */
-void statistics::incrementProtocolCount(const std::string &ipAddress, const std::string &protocol) {
+void statistics::incrementProtocolCount(const IPv4Address ipAddress, const std::string &protocol) {
     protocol_distribution[{ipAddress, protocol}].count++;
 }
 
@@ -398,7 +398,7 @@ void statistics::incrementProtocolCount(const std::string &ipAddress, const std:
  * @param ipAddress The IP address whose packet count is wanted.
  * @param protocol The protocol whose packet count is wanted.
  */
-int statistics::getProtocolCount(const std::string &ipAddress, const std::string &protocol) {
+int statistics::getProtocolCount(const IPv4Address ipAddress, const std::string &protocol) {
     return protocol_distribution[{ipAddress, protocol}].count;
 }
 
@@ -408,7 +408,7 @@ int statistics::getProtocolCount(const std::string &ipAddress, const std::string
  * @param protocol The protocol of the packet.
  * @param byteSent The packet's size.
  */
-void statistics::increaseProtocolByteCount(const std::string &ipAddress, const std::string &protocol, long bytesSent) {
+void statistics::increaseProtocolByteCount(const IPv4Address ipAddress, const std::string &protocol, long bytesSent) {
     protocol_distribution[{ipAddress, protocol}].byteCount += bytesSent;
 }
 
@@ -418,7 +418,7 @@ void statistics::increaseProtocolByteCount(const std::string &ipAddress, const s
  * @param protocol The protocol whose byte count is wanted.
  * @return a float: The number of bytes
  */
-float statistics::getProtocolByteCount(const std::string &ipAddress, const std::string &protocol) {
+float statistics::getProtocolByteCount(const IPv4Address ipAddress, const std::string &protocol) {
     return protocol_distribution[{ipAddress, protocol}].byteCount;
 }
 
@@ -431,7 +431,7 @@ float statistics::getProtocolByteCount(const std::string &ipAddress, const std::
  * @param ipAddressReceiver The IP address of the packet receiver.
  * @param incomingPort The port used by the receiver.
  */
-void statistics::incrementPortCount(const std::string &ipAddressSender, int outgoingPort, const std::string &ipAddressReceiver,
+void statistics::incrementPortCount(const IPv4Address ipAddressSender, int outgoingPort, const IPv4Address ipAddressReceiver,
                                     int incomingPort, const std::string &protocol) {
     port_values[outgoingPort]++;
     port_values[incomingPort]++;
@@ -449,7 +449,7 @@ void statistics::incrementPortCount(const std::string &ipAddressSender, int outg
  * @param incomingPort The port used by the receiver.
  * @param byteSent The packet's size.
  */
-void statistics::increasePortByteCount(const std::string &ipAddressSender, int outgoingPort, const std::string &ipAddressReceiver,
+void statistics::increasePortByteCount(const IPv4Address ipAddressSender, int outgoingPort, const IPv4Address ipAddressReceiver,
                                        int incomingPort, long bytesSent, const std::string &protocol) {
     ip_ports[{ipAddressSender, "out", outgoingPort, protocol}].byteCount += bytesSent;
     ip_ports[{ipAddressReceiver, "in", incomingPort, protocol}].byteCount += bytesSent;
@@ -480,7 +480,7 @@ statistics::statistics(void) {
  * @param ipAddress The IP address belonging to the given MAC address.
  * @param macAddress The MAC address belonging to the given IP address.
  */
-void statistics::assignMacAddress(const std::string &ipAddress, const std::string &macAddress) {
+void statistics::assignMacAddress(const IPv4Address ipAddress, const std::string &macAddress) {
     ip_mac_mapping[ipAddress] = macAddress;
 }
 
@@ -491,7 +491,7 @@ void statistics::assignMacAddress(const std::string &ipAddress, const std::strin
  * @param ipAddressReceiver The IP address of the packet receiver.
  * @param bytesSent The packet's size.
  */
-void statistics::addIpStat_packetSent(const std::string &ipAddressSender, const std::string &ipAddressReceiver, long bytesSent, std::chrono::microseconds timestamp) {
+void statistics::addIpStat_packetSent(const IPv4Address ipAddressSender, const IPv4Address ipAddressReceiver, long bytesSent, std::chrono::microseconds timestamp) {
 
     // Adding IP as a sender for first time
     if(ip_statistics[ipAddressSender].pkts_sent==0){  
@@ -517,7 +517,7 @@ void statistics::addIpStat_packetSent(const std::string &ipAddressSender, const
 
     if(this->getDoExtraTests()) {
         // Increment Degrees for sender and receiver, if Sender sends its first packet to this receiver
-        std::unordered_set<std::string>::const_iterator found_receiver = contacted_ips[ipAddressSender].find(ipAddressReceiver);
+        std::unordered_set<IPv4Address>::const_iterator found_receiver = contacted_ips[ipAddressSender].find(ipAddressReceiver);
         if(found_receiver == contacted_ips[ipAddressSender].end()){
             // Receiver is NOT contained in the List of IPs, that the Sender has contacted, therefore this is the first packet in this direction
             ip_statistics[ipAddressSender].out_degree++;
@@ -525,7 +525,7 @@ void statistics::addIpStat_packetSent(const std::string &ipAddressSender, const
 
             // Increment overall_degree only if this is the first packet for the connection (both directions)
             // Therefore check, whether Receiver has contacted Sender before
-            std::unordered_set<std::string>::const_iterator sender_contacted = contacted_ips[ipAddressReceiver].find(ipAddressSender);
+            std::unordered_set<IPv4Address>::const_iterator sender_contacted = contacted_ips[ipAddressReceiver].find(ipAddressSender);
             if(sender_contacted == contacted_ips[ipAddressReceiver].end()){
                 ip_statistics[ipAddressSender].overall_degree++;
                 ip_statistics[ipAddressReceiver].overall_degree++;
@@ -677,7 +677,7 @@ std::string statistics::getFormattedTimestamp(time_t seconds, suseconds_t micros
  * @param ipAddress The IP address whose statistics should be calculated.
  * @return a ip_stats struct containing statistical data derived by the statistical data collected.
  */
-ip_stats statistics::getStatsForIP(const std::string &ipAddress) {
+ip_stats statistics::getStatsForIP(const IPv4Address ipAddress) {
     float duration = getCaptureDurationSeconds();
     entry_ipStat ipStatEntry = ip_statistics[ipAddress];
 

+ 40 - 40
code_boost/src/cxx/statistics.h

@@ -50,9 +50,9 @@ struct ip_stats {
  * - Port B
  */
 struct conv{
-    std::string ipAddressA;
+    IPv4Address ipAddressA;
     int portA;
-    std::string ipAddressB;
+    IPv4Address ipAddressB;
     int portB;
 
     bool operator==(const conv &other) const {
@@ -72,9 +72,9 @@ struct conv{
  * - Protocol
  */
 struct convWithProt{
-    std::string ipAddressA;
+    IPv4Address ipAddressA;
     int portA;
-    std::string ipAddressB;
+    IPv4Address ipAddressB;
     int portB;
     std::string protocol;
 
@@ -93,7 +93,7 @@ struct convWithProt{
  * - MSS value
  */
 struct ipAddress_mss {
-    std::string ipAddress;
+    IPv4Address ipAddress;
     int mssValue;
 
     bool operator==(const ipAddress_mss &other) const {
@@ -108,7 +108,7 @@ struct ipAddress_mss {
  * - ToS value
  */
 struct ipAddress_tos {
-    std::string ipAddress;
+    IPv4Address ipAddress;
     int tosValue;
 
     bool operator==(const ipAddress_tos &other) const {
@@ -123,7 +123,7 @@ struct ipAddress_tos {
  * - Window size
  */
 struct ipAddress_win {
-    std::string ipAddress;
+    IPv4Address ipAddress;
     int winSize;
 
     bool operator==(const ipAddress_win &other) const {
@@ -138,7 +138,7 @@ struct ipAddress_win {
  * - TTL value
  */
 struct ipAddress_ttl {
-    std::string ipAddress;
+    IPv4Address ipAddress;
     int ttlValue;
 
     bool operator==(const ipAddress_ttl &other) const {
@@ -153,7 +153,7 @@ struct ipAddress_ttl {
  * - Protocol (e.g. TCP, UDP, IPv4, IPv6)
  */
 struct ipAddress_protocol {
-    std::string ipAddress;
+    IPv4Address ipAddress;
     std::string protocol;
 
     bool operator==(const ipAddress_protocol &other) const {
@@ -301,7 +301,7 @@ struct entry_convStat {
  * - Port number
  */
 struct ipAddress_inOut_port {
-    std::string ipAddress;
+    IPv4Address ipAddress;
     std::string trafficDirection;
     int portNumber;
     std::string protocol;
@@ -409,7 +409,7 @@ namespace std {
             using std::size_t;
             using std::hash;
             using std::string;
-            return ((hash<string>()(k.ipAddress)
+            return ((hash<uint32_t>()(k.ipAddress)
                      ^ (hash<int>()(k.ttlValue) << 1)) >> 1);
         }
     };
@@ -420,7 +420,7 @@ namespace std {
             using std::size_t;
             using std::hash;
             using std::string;
-            return ((hash<string>()(k.ipAddress)
+            return ((hash<uint32_t>()(k.ipAddress)
                      ^ (hash<int>()(k.mssValue) << 1)) >> 1);
         }
     };
@@ -431,7 +431,7 @@ namespace std {
             using std::size_t;
             using std::hash;
             using std::string;
-            return ((hash<string>()(k.ipAddress)
+            return ((hash<uint32_t>()(k.ipAddress)
                      ^ (hash<int>()(k.tosValue) << 1)) >> 1);
         }
     };
@@ -442,7 +442,7 @@ namespace std {
             using std::size_t;
             using std::hash;
             using std::string;
-            return ((hash<string>()(k.ipAddress)
+            return ((hash<uint32_t>()(k.ipAddress)
                      ^ (hash<int>()(k.winSize) << 1)) >> 1);
         }
     };
@@ -453,9 +453,9 @@ namespace std {
             using std::size_t;
             using std::hash;
             using std::string;
-            return ((hash<string>()(k.ipAddressA)
+            return ((hash<uint32_t>()(k.ipAddressA)
                      ^ (hash<int>()(k.portA) << 1)) >> 1)
-                     ^ ((hash<string>()(k.ipAddressB)
+                     ^ ((hash<uint32_t>()(k.ipAddressB)
                      ^ (hash<int>()(k.portB) << 1)) >> 1);
         }
     };
@@ -466,9 +466,9 @@ namespace std {
             using std::size_t;
             using std::hash;
             using std::string;
-            return ((hash<string>()(c.ipAddressA)
+            return ((hash<uint32_t>()(c.ipAddressA)
                      ^ (hash<int>()(c.portA) << 1)) >> 1)
-                     ^ ((hash<string>()(c.ipAddressB)
+                     ^ ((hash<uint32_t>()(c.ipAddressB)
                      ^ (hash<int>()(c.portB) << 1)) >> 1)
                      ^ (hash<string>()(c.protocol));
         }
@@ -480,7 +480,7 @@ namespace std {
             using std::size_t;
             using std::hash;
             using std::string;
-            return ((hash<string>()(k.ipAddress)
+            return ((hash<uint32_t>()(k.ipAddress)
                      ^ (hash<string>()(k.protocol) << 1)) >> 1);
         }
     };
@@ -491,7 +491,7 @@ namespace std {
             using std::size_t;
             using std::hash;
             using std::string;
-            return ((hash<string>()(k.ipAddress)
+            return ((hash<uint32_t>()(k.ipAddress)
                      ^ (hash<string>()(k.trafficDirection) << 1)) >> 1)
                    ^ (hash<int>()(k.portNumber) << 1);
         }
@@ -529,13 +529,13 @@ public:
 
     void calculateIPIntervalPacketRate(std::chrono::duration<int, std::micro> interval, std::chrono::microseconds intervalStartTimestamp);
 
-    void incrementMSScount(const std::string &ipAddress, int mssValue);
+    void incrementMSScount(const IPv4Address ipAddress, int mssValue);
 
-    void incrementWinCount(const std::string &ipAddress, int winSize);
+    void incrementWinCount(const IPv4Address ipAddress, int winSize);
 
-    void addConvStat(const std::string &ipAddressSender,int sport, const std::string &ipAddressReceiver,int dport, std::chrono::microseconds timestamp);
+    void addConvStat(const IPv4Address ipAddressSender,int sport, const IPv4Address ipAddressReceiver,int dport, std::chrono::microseconds timestamp);
 
-    void addConvStatExt(const std::string &ipAddressSender,int sport, const std::string &ipAddressReceiver,int dport, const std::string &protocol, std::chrono::microseconds timestamp);
+    void addConvStatExt(const IPv4Address ipAddressSender,int sport, const IPv4Address ipAddressReceiver,int dport, const std::string &protocol, std::chrono::microseconds timestamp);
 
     void createCommIntervalStats();
 
@@ -547,30 +547,30 @@ public:
 
     void checkPayload(const PDU *pdu_l4);
 
-    void checkTCPChecksum(const std::string &ipAddressSender, const std::string &ipAddressReceiver, TCP tcpPkt);
+    void checkTCPChecksum(const IPv4Address ipAddressSender, const IPv4Address ipAddressReceiver, TCP tcpPkt);
 
     void checkToS(uint8_t ToS);
 
-    void incrementToScount(const std::string &ipAddress, int tosValue);
+    void incrementToScount(const IPv4Address ipAddress, int tosValue);
 
-    void incrementTTLcount(const std::string &ipAddress, int ttlValue);
+    void incrementTTLcount(const IPv4Address ipAddress, int ttlValue);
 
-    void incrementProtocolCount(const std::string &ipAddress, const std::string &protocol);
+    void incrementProtocolCount(const IPv4Address ipAddress, const std::string &protocol);
 
-    void increaseProtocolByteCount(const std::string &ipAddress, const std::string &protocol, long bytesSent);
+    void increaseProtocolByteCount(const IPv4Address ipAddress, const std::string &protocol, long bytesSent);
 
     void incrementUnrecognizedPDUCount(const std::string &srcMac, const std::string &dstMac, uint32_t typeNumber,
                                        const std::string &timestamp);
 
-    void incrementPortCount(const std::string &ipAddressSender, int outgoingPort, const std::string &ipAddressReceiver,
+    void incrementPortCount(const IPv4Address ipAddressSender, int outgoingPort, const IPv4Address ipAddressReceiver,
                             int incomingPort, const std::string &protocol);
 
-    void increasePortByteCount(const std::string &ipAddressSender, int outgoingPort, const std::string &ipAddressReceiver,
+    void increasePortByteCount(const IPv4Address ipAddressSender, int outgoingPort, const IPv4Address ipAddressReceiver,
                                int incomingPort, long bytesSent, const std::string &protocol);
 
-    int getProtocolCount(const std::string &ipAddress, const std::string &protocol);
+    int getProtocolCount(const IPv4Address ipAddress, const std::string &protocol);
 
-    float getProtocolByteCount(const std::string &ipAddress, const std::string &protocol);
+    float getProtocolByteCount(const IPv4Address ipAddress, const std::string &protocol);
 
     void setTimestampFirstPacket(Tins::Timestamp ts);
 
@@ -579,15 +579,15 @@ public:
     Tins::Timestamp getTimestampFirstPacket();
     Tins::Timestamp getTimestampLastPacket();
 
-    void assignMacAddress(const std::string &ipAddress, const std::string &macAddress);
+    void assignMacAddress(const IPv4Address ipAddress, const std::string &macAddress);
     
-    void addIpStat_packetSent(const std::string &ipAddressSender, const std::string &ipAddressReceiver, long bytesSent, std::chrono::microseconds timestamp);
+    void addIpStat_packetSent(const IPv4Address ipAddressSender, const IPv4Address ipAddressReceiver, long bytesSent, std::chrono::microseconds timestamp);
 
     int getPacketCount();
 
     int getSumPacketSize();
 
-    void addMSS(const std::string &ipAddress, int MSSvalue);
+    void addMSS(const IPv4Address ipAddress, int MSSvalue);
 
     void writeToDatabase(std::string database_path);
 
@@ -608,7 +608,7 @@ public:
     /*
      * IP Address-specific statistics
      */
-    ip_stats getStatsForIP(const std::string &ipAddress);
+    ip_stats getStatsForIP(const IPv4Address ipAddress);
 
 private:
     /*
@@ -691,19 +691,19 @@ private:
 
 
     //{IP Address, contacted IP Addresses}
-    std::unordered_map<std::string, std::unordered_set<std::string>> contacted_ips;
+    std::unordered_map<IPv4Address, std::unordered_set<IPv4Address>> contacted_ips;
 
     // {IP Address, Protocol,  #count, #Data transmitted in bytes}
     std::unordered_map<ipAddress_protocol, entry_protocolStat> protocol_distribution;
 
     // {IP Address,  #received packets, #sent packets, Data received in kbytes, Data sent in kbytes}
-    std::unordered_map<std::string, entry_ipStat> ip_statistics;
+    std::unordered_map<IPv4Address, entry_ipStat> ip_statistics;
 
     // {IP Address, in_out, Port Number,  #count, #Data transmitted in bytes}
     std::unordered_map<ipAddress_inOut_port, entry_portStat> ip_ports;
 
     // {IP Address, MAC Address}
-    std::unordered_map<std::string, std::string> ip_mac_mapping;
+    std::unordered_map<IPv4Address, std::string> ip_mac_mapping;
 
     // {Source MAC, Destination MAC, typeNumber, #count, #timestamp of last occurrence}
     std::unordered_map<unrecognized_PDU, unrecognized_PDU_stat> unrecognized_PDUs;

+ 16 - 16
code_boost/src/cxx/statistics_db.cpp

@@ -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(const std::unordered_map<std::string, entry_ipStat> &ipStatistics) {
+void statistics_db::writeStatisticsIP(const std::unordered_map<IPv4Address, entry_ipStat> &ipStatistics) {
     try {
         db->exec("DROP TABLE IF EXISTS ip_statistics");
         SQLite::Transaction transaction(*db);
@@ -45,7 +45,7 @@ void statistics_db::writeStatisticsIP(const std::unordered_map<std::string, entr
         SQLite::Statement query(*db, "INSERT INTO ip_statistics VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
         for (auto it = ipStatistics.begin(); it != ipStatistics.end(); ++it) {
             const entry_ipStat &e = it->second;
-            query.bindNoCopy(1, it->first);
+            query.bindNoCopy(1, it->first.to_string());
             query.bind(2, (int) e.pkts_received);
             query.bind(3, (int) e.pkts_sent);
             query.bind(4, e.kbytes_received);
@@ -68,7 +68,7 @@ void statistics_db::writeStatisticsIP(const std::unordered_map<std::string, entr
  * @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(const std::unordered_map<std::string, entry_ipStat> &ipStatistics){
+void statistics_db::writeStatisticsDegree(const std::unordered_map<IPv4Address, entry_ipStat> &ipStatistics){
     try {
         db->exec("DROP TABLE IF EXISTS ip_degrees");
         SQLite::Transaction transaction(*db);
@@ -82,7 +82,7 @@ void statistics_db::writeStatisticsDegree(const std::unordered_map<std::string,
         SQLite::Statement query(*db, "INSERT INTO ip_degrees VALUES (?, ?, ?, ?)");
         for (auto it = ipStatistics.begin(); it != ipStatistics.end(); ++it) {
             const entry_ipStat &e = it->second;
-            query.bindNoCopy(1, it->first);
+            query.bindNoCopy(1, it->first.to_string());
             query.bind(2, e.in_degree);
             query.bind(3, e.out_degree);
             query.bind(4, e.overall_degree);
@@ -114,7 +114,7 @@ void statistics_db::writeStatisticsTTL(const std::unordered_map<ipAddress_ttl, i
         SQLite::Statement query(*db, "INSERT INTO ip_ttl VALUES (?, ?, ?)");
         for (auto it = ttlDistribution.begin(); it != ttlDistribution.end(); ++it) {
             const ipAddress_ttl &e = it->first;
-            query.bindNoCopy(1, e.ipAddress);
+            query.bindNoCopy(1, e.ipAddress.to_string());
             query.bind(2, e.ttlValue);
             query.bind(3, it->second);
             query.exec();
@@ -145,7 +145,7 @@ void statistics_db::writeStatisticsMSS(const std::unordered_map<ipAddress_mss, i
         SQLite::Statement query(*db, "INSERT INTO tcp_mss VALUES (?, ?, ?)");
         for (auto it = mssDistribution.begin(); it != mssDistribution.end(); ++it) {
             const ipAddress_mss &e = it->first;
-            query.bindNoCopy(1, e.ipAddress);
+            query.bindNoCopy(1, e.ipAddress.to_string());
             query.bind(2, e.mssValue);
             query.bind(3, it->second);
             query.exec();
@@ -175,7 +175,7 @@ void statistics_db::writeStatisticsToS(const std::unordered_map<ipAddress_tos, i
         SQLite::Statement query(*db, "INSERT INTO ip_tos VALUES (?, ?, ?)");
         for (auto it = tosDistribution.begin(); it != tosDistribution.end(); ++it) {
             const ipAddress_tos &e = it->first;
-            query.bindNoCopy(1, e.ipAddress);
+            query.bindNoCopy(1, e.ipAddress.to_string());
             query.bind(2, e.tosValue);
             query.bind(3, it->second);
             query.exec();
@@ -206,7 +206,7 @@ void statistics_db::writeStatisticsWin(const std::unordered_map<ipAddress_win, i
         SQLite::Statement query(*db, "INSERT INTO tcp_win VALUES (?, ?, ?)");
         for (auto it = winDistribution.begin(); it != winDistribution.end(); ++it) {
             const ipAddress_win &e = it->first;
-            query.bindNoCopy(1, e.ipAddress);
+            query.bindNoCopy(1, e.ipAddress.to_string());
             query.bind(2, e.winSize);
             query.bind(3, it->second);
             query.exec();
@@ -237,7 +237,7 @@ void statistics_db::writeStatisticsProtocols(const std::unordered_map<ipAddress_
         SQLite::Statement query(*db, "INSERT INTO ip_protocols VALUES (?, ?, ?, ?)");
         for (auto it = protocolDistribution.begin(); it != protocolDistribution.end(); ++it) {
             const ipAddress_protocol &e = it->first;
-            query.bindNoCopy(1, e.ipAddress);
+            query.bindNoCopy(1, e.ipAddress.to_string());
             query.bindNoCopy(2, e.protocol);
             query.bind(3, it->second.count);
             query.bind(4, it->second.byteCount);
@@ -279,7 +279,7 @@ void statistics_db::writeStatisticsPorts(const std::unordered_map<ipAddress_inOu
                 else {portService = "unknown";}
             }
 
-            query.bindNoCopy(1, e.ipAddress);
+            query.bindNoCopy(1, e.ipAddress.to_string());
             query.bindNoCopy(2, e.trafficDirection);
             query.bind(3, e.portNumber);
             query.bind(4, it->second.count);
@@ -300,7 +300,7 @@ void statistics_db::writeStatisticsPorts(const std::unordered_map<ipAddress_inOu
  *  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(const std::unordered_map<std::string, std::string> &IpMacStatistics) {
+void statistics_db::writeStatisticsIpMac(const std::unordered_map<IPv4Address, std::string> &IpMacStatistics) {
     try {
         db->exec("DROP TABLE IF EXISTS ip_mac");
         SQLite::Transaction transaction(*db);
@@ -311,7 +311,7 @@ void statistics_db::writeStatisticsIpMac(const std::unordered_map<std::string, s
         db->exec(createTable);
         SQLite::Statement query(*db, "INSERT INTO ip_mac VALUES (?, ?)");
         for (auto it = IpMacStatistics.begin(); it != IpMacStatistics.end(); ++it) {
-            query.bindNoCopy(1, it->first);
+            query.bindNoCopy(1, it->first.to_string());
             query.bindNoCopy(2, it->second);
             query.exec();
             query.reset();
@@ -420,9 +420,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.bindNoCopy(1, f.ipAddressA);
+                query.bindNoCopy(1, f.ipAddressA.to_string());
                 query.bind(2, f.portA);
-                query.bindNoCopy(3, f.ipAddressB);
+                query.bindNoCopy(3, f.ipAddressB.to_string());
                 query.bind(4, f.portB);
                 query.bind(5, (int) e.pkts_count);
                 query.bind(6, (float) e.avg_pkt_rate);
@@ -495,9 +495,9 @@ 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.bindNoCopy(1, f.ipAddressA);
+                query.bindNoCopy(1, f.ipAddressA.to_string());
                 query.bind(2, f.portA);
-                query.bindNoCopy(3, f.ipAddressB);
+                query.bindNoCopy(3, f.ipAddressB.to_string());
                 query.bind(4, f.portB);
                 query.bindNoCopy(5, f.protocol);
                 query.bind(6, (int) e.pkts_count);

+ 3 - 3
code_boost/src/cxx/statistics_db.h

@@ -27,9 +27,9 @@ public:
     /*
      * Methods for writing values into database
      */
-    void writeStatisticsIP(const std::unordered_map<std::string, entry_ipStat> &ipStatistics);
+    void writeStatisticsIP(const std::unordered_map<IPv4Address, entry_ipStat> &ipStatistics);
 
-    void writeStatisticsDegree(const std::unordered_map<std::string, entry_ipStat> &ipStatistics);
+    void writeStatisticsDegree(const std::unordered_map<IPv4Address, entry_ipStat> &ipStatistics);
 
     void writeStatisticsTTL(const std::unordered_map<ipAddress_ttl, int> &ttlDistribution);
 
@@ -43,7 +43,7 @@ public:
 
     void writeStatisticsPorts(const std::unordered_map<ipAddress_inOut_port, entry_portStat> &portsStatistics);
 
-    void writeStatisticsIpMac(const std::unordered_map<std::string, std::string> &IpMacStatistics);
+    void writeStatisticsIpMac(const std::unordered_map<IPv4Address, std::string> &IpMacStatistics);
 
     void writeStatisticsFile(int packetCount, float captureDuration, std::string timestampFirstPkt,
                              std::string timestampLastPkt, float avgPacketRate, float avgPacketSize,

+ 5 - 5
code_boost/src/cxx/utilities.cpp

@@ -33,11 +33,11 @@ void split_str(const std::string& s, char delim,std::vector<std::string>& v) {
  * Get the class (A,B,C,D,E) of IP address.
  * @param ipAddress IP that we get its class.
  */
-std::string getIPv4Class(const std::string &ipAddress){
+std::string getIPv4Class(const IPv4Address ipAddress){
     std::string ipClass="Unknown";
     
     std::vector<std::string> ipBytes;
-    split_str(ipAddress, '.',ipBytes);
+    split_str(ipAddress.to_string(), '.',ipBytes);
     
     //std::cout<< ipAddress << "\n";
     
@@ -150,7 +150,7 @@ u16 tcp_sum_calc(u16 len_tcp, u16 src_addr[],u16 dest_addr[], bool padding, u16
  * @param ipAddressReceiver The destination IP.
  * @param tcpPkt The packet to get checked.
  */
-bool check_tcpChecksum(const std::string &ipAddressSender, const std::string &ipAddressReceiver, TCP tcpPkt){
+bool check_tcpChecksum(const IPv4Address ipAddressSender, const IPv4Address ipAddressReceiver, TCP tcpPkt){
     uint16_t checksum = tcpPkt.checksum();
 
     unsigned short calculatedChecsum = 0;
@@ -174,8 +174,8 @@ bool check_tcpChecksum(const std::string &ipAddressSender, const std::string &ip
     unsigned short* buff_16 = &bufferArray_16[0];
     unsigned short ipAddressSender_bytes[4];
     unsigned short ipAddressReceiver_bytes[4];
-    convertIPv4toArray(ipAddressSender, ipAddressSender_bytes);
-    convertIPv4toArray(ipAddressReceiver, ipAddressReceiver_bytes);
+    convertIPv4toArray(ipAddressSender.to_string(), ipAddressSender_bytes);
+    convertIPv4toArray(ipAddressReceiver.to_string(), ipAddressReceiver_bytes);
 
     bool padding = false;
     int dataSize = bufferArray_8.size() - headerSize;

+ 2 - 2
code_boost/src/cxx/utilities.h

@@ -21,7 +21,7 @@ typedef unsigned long u32;
 using namespace Tins;
 
 
-std::string getIPv4Class(const std::string &ipAddress);
+std::string getIPv4Class(const IPv4Address ipAddress);
 
 void convertIPv4toArray(const std::string &IP, unsigned short IP_bytes[]);
 
@@ -29,7 +29,7 @@ void split_str(const std::string& s, char delim,std::vector<std::string>& v);
 
 u16 tcp_sum_calc(u16 len_tcp, u16 src_addr[],u16 dest_addr[], bool padding, u16 buff[]);
 
-bool check_tcpChecksum(const std::string &ipAddressSender, const std::string &ipAddressReceiver, TCP tcpPkt);
+bool check_tcpChecksum(const IPv4Address ipAddressSender, const IPv4Address ipAddressReceiver, TCP tcpPkt);
 
 template<class T>
 std::string integral_to_binary_string(T byte);