NETWORK ATTACKS FRAMEWORK
1.0.0
A NETwork Attacks framework. Making network attacks impact evaluation easier!
|
00001 // 00002 // Copyright (C) 2013, NESG (Network Engineering and Security Group), http://nesg.ugr.es, 00003 // - Gabriel Maciá Fernández (gmacia@ugr.es) 00004 // - Leovigildo Sánchez Casado (sancale@ugr.es) 00005 // - Rafael A. Rodríguez Gómez (rodgom@ugr.es) 00006 // - Roberto Magán Carrión (rmagan@ugr.es) 00007 // - Pedro García Teodoro (pgteodor@ugr.es) 00008 // - José Camacho Páez (josecamacho@ugr.es) 00009 // - Jesús E. Díaz Verdejo (jedv@ugr.es) 00010 // 00011 // This file is part of NETA. 00012 // 00013 // NETA is free software: you can redistribute it and/or modify 00014 // it under the terms of the GNU General Public License as published by 00015 // the Free Software Foundation, either version 3 of the License, or 00016 // (at your option) any later version. 00017 // 00018 // NETA is distributed in the hope that it will be useful, 00019 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00020 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00021 // GNU General Public License for more details. 00022 // 00023 // You should have received a copy of the GNU General Public License 00024 // along with NETA. If not, see <http://www.gnu.org/licenses/>. 00025 // 00026 00027 00028 #include "NA_UDPBasicBurst.h" 00029 00030 #include "UDPControlInfo_m.h" 00031 #include "IPvXAddressResolver.h" 00032 00033 using std::cout; 00034 00035 Define_Module(NA_UDPBasicBurst); 00036 00037 simsignal_t NA_UDPBasicBurst::hopCountSignal = SIMSIGNAL_NULL; 00038 00039 void NA_UDPBasicBurst::initialize(int stage) 00040 { 00041 // because of IPvXAddressResolver, we need to wait until interfaces are registered, 00042 // address auto-assignment takes place etc. 00043 if (stage != 3) 00044 return; 00045 00046 // Initialization 00047 numHopsTotal = 0; 00048 avHopCount = 0; 00049 hopCountSignal = registerSignal("hopCount"); 00050 00051 UDPBasicBurst::initialize(stage); 00052 } 00053 00054 00055 void NA_UDPBasicBurst::processPacket(cPacket *pk) 00056 { 00057 00058 if (pk->getKind() == UDP_I_ERROR) 00059 { 00060 EV << "UDP error received\n"; 00061 delete pk; 00062 return; 00063 } 00064 00065 if (pk->hasPar("sourceId") && pk->hasPar("msgId")) 00066 { 00067 // duplicate control 00068 int moduleId = (int)pk->par("sourceId"); 00069 int msgId = (int)pk->par("msgId"); 00070 SourceSequence::iterator it = sourceSequence.find(moduleId); 00071 if (it != sourceSequence.end()) 00072 { 00073 if (it->second >= msgId) 00074 { 00075 EV << "Out of order packet: " << UDPSocket::getReceivedPacketInfo(pk) << endl; 00076 emit(outOfOrderPkSignal, pk); 00077 delete pk; 00078 numDuplicated++; 00079 return; 00080 } 00081 else 00082 it->second = msgId; 00083 } 00084 else 00085 sourceSequence[moduleId] = msgId; 00086 } 00087 00088 if (delayLimit > 0) 00089 { 00090 if (simTime() - pk->getTimestamp() > delayLimit) 00091 { 00092 EV << "Old packet: " << UDPSocket::getReceivedPacketInfo(pk) << endl; 00093 emit(dropPkSignal, pk); 00094 delete pk; 00095 numDeleted++; 00096 return; 00097 } 00098 } 00099 00100 EV << "Received packet: " << UDPSocket::getReceivedPacketInfo(pk) << endl; 00101 emit(rcvdPkSignal, pk); 00102 numReceived++; 00103 00104 cObject *ctrl = pk->getControlInfo(); 00105 if (dynamic_cast<UDPDataIndication *>(ctrl)!=NULL) { 00106 UDPDataIndication *udpCtrl = (UDPDataIndication *)ctrl; 00107 short hopCnt = 32 - udpCtrl->getTtl(); // travelled hops of IP packet 00108 00109 numHopsTotal = numHopsTotal + hopCnt; 00110 if ( numReceived > 0 ) 00111 avHopCount = (double)numHopsTotal/(double)numReceived; 00112 else 00113 avHopCount = 0; 00114 00115 //cout << "Hop Count = " << hopCnt << endl; 00116 //cout << "Num Hop total = " << numHopsTotal << endl; 00117 //cout << "Average Hop Count = " << numHopsTotal << " / " << numReceived << " = "<< avHopCount << endl << endl; 00118 00119 emit(hopCountSignal, avHopCount); 00120 00121 } 00122 00123 delete pk; 00124 00125 }