NETWORK ATTACKS FRAMEWORK  1.0.0
A NETwork Attacks framework. Making network attacks impact evaluation easier!
NA_aodv_msg_struct.cc
Go to the documentation of this file.
00001 
00002 
00003 #include  <string.h>
00004 
00005 #include "NA_aodv_msg_struct.h"
00006 #include "InterfaceTable.h"
00007 #include "UDPPacket.h"
00008 #include "IPv4ControlInfo.h"
00009 #include "IPv6ControlInfo.h"
00010 #include "ICMPMessage_m.h"
00011 #include "IPv4Datagram.h"
00012 #include "RoutingTable.h"
00013 #include "ICMPAccess.h"
00014 #include "IPv4ControlInfo.h"
00015 #include "IPv4Datagram.h"
00016 #include "ProtocolMap.h"
00017 
00018 
00019 
00020 Register_Class(AODV_msg);
00021 
00022 
00023 AODV_msg::AODV_msg(const AODV_msg& m) : cPacket(m)
00024 {
00025     copy(m);
00026 }
00027 
00028 
00029 AODV_msg& AODV_msg::operator=(const AODV_msg& m)
00030 {
00031     if (this==&m) return *this;
00032 
00033     clearExtension();
00034     cPacket::operator=(m);
00035     copy(m);
00036     return *this;
00037 }
00038 
00039 
00040 void AODV_msg::copy(const AODV_msg& m)
00041 {
00042     type = m.type;
00043     ttl = m.ttl;
00044     prevFix = m.prevFix;
00045     extensionsize = m.extensionsize;
00046     if (extensionsize==0)
00047     {
00048         extension = NULL;
00049         return;
00050     }
00051     extension = new AODV_ext [extensionsize];
00052     for (int i=0; i < extensionsize; i++)
00053     {
00054         extension[i].type = m.extension[i].type;
00055         extension[i].length = m.extension[i].length;
00056         extension[i].pointer = new char[extension[i].length];
00057         memcpy(extension[i].pointer, m.extension[i].pointer, extension[i].length);
00058     }
00059 }
00060 
00061 void AODV_msg:: clearExtension()
00062 {
00063     if (extensionsize==0)
00064     {
00065         return;
00066     }
00067     for (int i=0; i < extensionsize; i++)
00068     {
00069         delete extension[i].pointer;
00070     }
00071     delete [] extension;
00072     extensionsize = 0;
00073     extension = NULL;
00074 }
00075 
00076 AODV_msg::~AODV_msg()
00077 {
00078     clearExtension();
00079 }
00080 
00081 AODV_ext * AODV_msg::addExtension(int type, int len, char *data)
00082 {
00083     AODV_ext* extension_aux;
00084     if (len<0)
00085     {
00086         return NULL;
00087     }
00088     extension_aux =   new AODV_ext [extensionsize+1];
00089     for (int i=0; i < extensionsize; i++)
00090     {
00091         extension_aux[i].type = extension[i].type;
00092         extension_aux[i].length = extension[i].length;
00093         extension_aux[i].pointer = extension[i].pointer;
00094     }
00095     if (extensionsize>0)
00096         delete [] extension;
00097     extension =  extension_aux;
00098     extensionsize++;
00099     extension[extensionsize-1].type = type;
00100     extension[extensionsize-1].length = len;
00101     extension[extensionsize-1].pointer  =  new char[len];
00102     memcpy(extension_aux[extensionsize-1].pointer, data, len);
00103     setBitLength(getBitLength()+((AODV_EXT_HDR_SIZE+len) *8));
00104     return & extension[extensionsize-1];
00105 }
00106 
00107 
00108 AODV_ext * AODV_msg::getNexExtension(AODV_ext* aodv_ext)
00109 {
00110     if ((&extension[extensionsize-1]>aodv_ext+1) && (aodv_ext >= extension))
00111         return aodv_ext+1;
00112     else
00113         return NULL;
00114 }
00115 
00116 //=== registration
00117 Register_Class(RERR);
00118 
00119 //=========================================================================
00120 
00121 RERR::RERR(const RERR& m) : AODV_msg(m)
00122 {
00123     copy(m);
00124 }
00125 
00126 RERR& RERR::operator=(const RERR& m)
00127 {
00128     if (this==&m) return *this;
00129     clearUdest();
00130     AODV_msg::operator=(m);
00131     copy(m);
00132     return *this;
00133 }
00134 
00135 void RERR::copy(const RERR& m)
00136 {
00137     n = m.n;
00138     res1 = m.res1;
00139     res2 = m.res2;
00140     dest_count = m.dest_count;
00141     _udest = new RERR_udest [dest_count];
00142     for (int i=0; i < dest_count; i++)
00143     {
00144         _udest[i].dest_addr = m._udest[i].dest_addr;
00145         _udest[i].dest_seqno = m._udest[i].dest_seqno;
00146     }
00147 }
00148 
00149 RERR::~RERR()
00150 {
00151     clearUdest();
00152 }
00153 
00154 void RERR::addUdest(const ManetAddress & src_addr, unsigned int udest_seqno)
00155 {
00156 
00157     RERR_udest *temp_udest;
00158     temp_udest = new RERR_udest [dest_count+1];
00159     for (int i=0; i < dest_count; i++)
00160     {
00161         temp_udest[i].dest_addr = _udest[i].dest_addr;
00162         temp_udest[i].dest_seqno = _udest[i].dest_seqno;
00163     }
00164     delete []  _udest;
00165     temp_udest[dest_count].dest_addr = src_addr;
00166     temp_udest[dest_count].dest_seqno = udest_seqno;
00167     _udest = temp_udest;
00168     dest_count++;
00169     setBitLength(getBitLength()+(RERR_UDEST_SIZE));
00170 }
00171 
00172 RERR_udest * RERR::getUdest(int i)
00173 {
00174     if (i < dest_count)
00175     {
00176         return  &(_udest[i]);
00177     }
00178     else
00179     {
00180         return NULL;
00181     }
00182 }
00183 
00184 void RERR::clearUdest()
00185 {
00186     if (_udest!=NULL)
00187     {
00188         delete []  _udest;
00189     }
00190     _udest = NULL;
00191 }
00192 
00193 
00194 Register_Class(RREP);
00195 RREP::RREP(const RREP& m) : AODV_msg(m)
00196 {
00197     copy(m);
00198 }
00199 
00200 RREP& RREP::operator=(const RREP& m)
00201 {
00202     if (this==&m) return *this;
00203     AODV_msg::operator=(m);
00204     copy(m);
00205     return *this;
00206 }
00207 
00208 void RREP::copy(const RREP& m)
00209 {
00210     res1 = m.res1;
00211     a = m.a;
00212     r = m.r;
00213     prefix = m.prefix;
00214     res2 = m.res2;
00215     hcnt = m.hcnt;
00216     dest_addr = m.dest_addr;
00217     dest_seqno = m.dest_seqno;
00218     orig_addr = m.orig_addr;
00219     lifetime = m.lifetime;
00220     cost = m.cost;
00221     hopfix = m.hopfix;
00222 }
00223 
00224 std::string RREP::detailedInfo() const
00225 {
00226     std::stringstream out;
00227     int timeToLive = ttl;
00228     int hops = hcnt;
00229     out << " RREP "  << "\n"; // Khmm...
00230     out <<" Source :"<< orig_addr << "\n";
00231     out <<" Destination :"<< dest_addr << "\n";
00232     out <<" Destination seq num:"<< dest_seqno << "\n";
00233     out <<" TTL :"<< timeToLive << "\n";
00234     out <<" hops :"<< hops << "\n";
00235     return out.str();
00236 }
00237 
00238 
00239 
00240 Register_Class(RREP_ack);
00241 RREP_ack::RREP_ack(const RREP_ack& m) : AODV_msg(m)
00242 {
00243     copy(m);
00244 }
00245 
00246 RREP_ack& RREP_ack::operator=(const RREP_ack& m)
00247 {
00248     if (this==&m) return *this;
00249     AODV_msg::operator=(m);
00250     copy(m);
00251     return *this;
00252 }
00253 
00254 
00255 
00256 Register_Class(RREQ);
00257 RREQ::RREQ(const RREQ& m) : AODV_msg(m)
00258 {
00259     copy(m);
00260 }
00261 
00262 RREQ& RREQ::operator=(const RREQ& m)
00263 {
00264     if (this==&m) return *this;
00265     AODV_msg::operator=(m);
00266     copy(m);
00267     return *this;
00268 }
00269 
00270 void RREQ::copy(const RREQ& m)
00271 {
00272     j = m.j;      /* Join flag (multicast) */
00273     r = m.r;      /* Repair flag */
00274     g = m.g;      /* Gratuitous RREP flag */
00275     d = m.d;      /* Destination only respond */
00276     res1 = m.res1;
00277     res2 = m.res2;
00278     hcnt = m.hcnt;
00279     rreq_id = m.rreq_id;
00280     dest_addr = m.dest_addr;
00281     dest_seqno = m.dest_seqno;
00282     orig_addr = m.orig_addr;
00283     orig_seqno = m.orig_seqno;
00284     cost = m.cost;
00285     hopfix = m.hopfix;
00286 }
00287 
00288 std::string RREQ::detailedInfo() const
00289 {
00290     std::stringstream out;
00291     int timeToLive = ttl;
00292     int hops = hcnt;
00293     out << " RREQ "  << "\n"; // Khmm...
00294     out <<" Source :"<< orig_addr << "\n";
00295     out <<" Source seq num:"<< orig_seqno << "\n";
00296     out <<" Destination :"<< dest_addr << "\n";
00297     out <<" Destination seq num:"<< dest_seqno << "\n";
00298     out <<" TTL :"<< timeToLive << "\n";
00299     out <<" hops :"<< hops << "\n";
00300     return out.str();
00301 }
00302 
00303 
 All Classes Files Functions Variables Typedefs Enumerator Defines