Sfoglia il codice sorgente

refactored untracked to unrecognized

Stefano Acquaviti 6 anni fa
parent
commit
56030e0baf

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

@@ -8,7 +8,7 @@ using namespace Tins;
  */
 pcap_processor::pcap_processor(std::string path, std::string extraTests) {
     filePath = path;
-    hasUntracked = false;
+    hasUnrecognized = false;
     if(extraTests == "True")
         stats.setDoExtraTests(true);
     else stats.setDoExtraTests(false);;
@@ -253,24 +253,24 @@ void pcap_processor::process_packets(const Packet &pkt) {
 
         EthernetII eth = (const EthernetII &) *pdu_l2;
 
-        stats.incrementUntrackedPDUCount(macAddressSender, macAddressReceiver, eth.payload_type());
+        stats.incrementUnrecognizedPDUCount(macAddressSender, macAddressReceiver, eth.payload_type());
 
-        if(!hasUntracked) {
-            std::cerr << "Unrecognized PDUs detected: Check 'untracked_pdus' table!" << std::endl;
-            hasUntracked = true;
+        if(!hasUnrecognized) {
+            std::cerr << "Unrecognized PDUs detected: Check 'unrecognized_pdus' table!" << std::endl;
+            hasUnrecognized = true;
         }
 
     }
 
     else {
-        if(!hasUntracked) {
-            std::cerr << "Unrecognized PDUs detected: Check 'untracked_pdus' table!" << std::endl;
-            hasUntracked = true;
+        if(!hasUnrecognized) {
+            std::cerr << "Unrecognized PDUs detected: Check 'unrecognized_pdus' table!" << std::endl;
+            hasUnrecognized = true;
         }
 
         EthernetII eth = (const EthernetII &) *pdu_l2;
 
-        stats.incrementUntrackedPDUCount(macAddressSender, macAddressReceiver, eth.payload_type());
+        stats.incrementUnrecognizedPDUCount(macAddressSender, macAddressReceiver, eth.payload_type());
     }
 
     // Layer 4 - Transport -------------------------------

+ 1 - 1
code_boost/src/cxx/pcap_processor.h

@@ -30,7 +30,7 @@ public:
      */
     statistics stats;
     std::string filePath;
-    bool hasUntracked;
+    bool hasUnrecognized;
 
     /*
      * Methods

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

@@ -367,8 +367,8 @@ void statistics::increasePortByteCount(std::string ipAddressSender, int outgoing
  * @param dstMac The MAC address of the packet receiver.
  * @param typeNumber The payload type number of the packet.
  */
-void statistics::incrementUntrackedPDUCount(std::string srcMac, std::string dstMac, uint32_t typeNumber) {
-    untracked_PDUs[{srcMac, dstMac, typeNumber}]++;
+void statistics::incrementUnrecognizedPDUCount(std::string srcMac, std::string dstMac, uint32_t typeNumber) {
+    unrecognized_PDUs[{srcMac, dstMac, typeNumber}]++;
 }
 
 /**
@@ -650,7 +650,7 @@ void statistics::writeToDatabase(std::string database_path) {
         db.writeStatisticsConv(conv_statistics);
         db.writeStatisticsInterval(interval_statistics);
         db.writeDbVersion();
-        db.writeStatisticsUntrackedPDUs(untracked_PDUs);
+        db.writeStatisticsUnrecognizedPDUs(unrecognized_PDUs);
     }
     else {
         // Tinslib failed to recognize the types of the packets in the input PCAP

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

@@ -289,12 +289,12 @@ struct ipAddress_inOut_port {
  * - Destination MAC address
  * - Payload type number
  */
-struct untracked_PDU {
+struct unrecognized_PDU {
     std::string srcMacAddress;
     std::string dstMacAddress;
     uint32_t typeNumber;
 
-    bool operator==(const untracked_PDU &other) const {
+    bool operator==(const unrecognized_PDU &other) const {
         return srcMacAddress == other.srcMacAddress
                && dstMacAddress == other.dstMacAddress
                && typeNumber == other.typeNumber;
@@ -386,8 +386,8 @@ namespace std {
     };
 
     template<>
-    struct hash<untracked_PDU> {
-        std::size_t operator()(const untracked_PDU &k) const {
+    struct hash<unrecognized_PDU> {
+        std::size_t operator()(const unrecognized_PDU &k) const {
             using std::size_t;
             using std::hash;
             using std::string;
@@ -443,7 +443,7 @@ public:
 
     void increaseProtocolByteCount(std::string ipAddress, std::string protocol, long bytesSent);
 
-    void incrementUntrackedPDUCount(std::string srcMac, std::string dstMac, uint32_t typeNumber);
+    void incrementUnrecognizedPDUCount(std::string srcMac, std::string dstMac, uint32_t typeNumber);
 
     void incrementPortCount(std::string ipAddressSender, int outgoingPort, std::string ipAddressReceiver,
                             int incomingPort);
@@ -579,7 +579,7 @@ private:
     std::unordered_map<std::string, std::string> ip_mac_mapping;
 
     // {Source MAC, Destination MAC, typeNumber, #count}
-    std::unordered_map<untracked_PDU, int> untracked_PDUs;
+    std::unordered_map<unrecognized_PDU, int> unrecognized_PDUs;
 };
 
 

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

@@ -455,23 +455,23 @@ void statistics_db::writeDbVersion(){
 }
 
 /**
- * Writes the untracked PDUs into the database.
- * @param untracked_PDUs The untracked PDUs from class statistics.
+ * Writes the unrecognized PDUs into the database.
+ * @param unrecognized_PDUs The unrecognized PDUs from class statistics.
  */
-void statistics_db::writeStatisticsUntrackedPDUs(std::unordered_map<untracked_PDU, int> untracked_PDUs) {
+void statistics_db::writeStatisticsUnrecognizedPDUs(std::unordered_map<unrecognized_PDU, int> unrecognized_PDUs) {
     try {
-        db->exec("DROP TABLE IF EXISTS untracked_pdus");
+        db->exec("DROP TABLE IF EXISTS unrecognized_pdus");
         SQLite::Transaction transaction(*db);
-        const char *createTable = "CREATE TABLE untracked_pdus ("
+        const char *createTable = "CREATE TABLE unrecognized_pdus ("
                 "srcMac TEXT COLLATE NOCASE,"
                 "dstMac TEXT COLLATE NOCASE,"
-                "typeNumber INTEGER,"
+                "etherType INTEGER,"
                 "pktCount INTEGER,"
-                "PRIMARY KEY(srcMac,dstMac,typeNumber));";
+                "PRIMARY KEY(srcMac,dstMac,etherType));";
         db->exec(createTable);
-        SQLite::Statement query(*db, "INSERT INTO untracked_pdus VALUES (?, ?, ?, ?)");
-        for (auto it = untracked_PDUs.begin(); it != untracked_PDUs.end(); ++it) {
-            untracked_PDU e = it->first;
+        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);
             query.bind(3, e.typeNumber);

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

@@ -52,7 +52,7 @@ public:
 
     void writeDbVersion();
 
-    void writeStatisticsUntrackedPDUs(std::unordered_map<untracked_PDU, int> untracked_PDUs);
+    void writeStatisticsUnrecognizedPDUs(std::unordered_map<unrecognized_PDU, int> unrecognized_PDUs);
 
 private:
     // Pointer to the SQLite database