src/dsr/model/dsr-option-header.cc
changeset 8751 efad81f3cb47
child 8752 2da1fab73114
equal deleted inserted replaced
8750:b3db7d51f260 8751:efad81f3cb47
       
     1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
       
     2 /*
       
     3  * Copyright (c) 2011 Yufei Cheng
       
     4  *
       
     5  * This program is free software; you can redistribute it and/or modify
       
     6  * it under the terms of the GNU General Public License version 2 as
       
     7  * published by the Free Software Foundation;
       
     8  *
       
     9  * This program is distributed in the hope that it will be useful,
       
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    12  * GNU General Public License for more details.
       
    13  *
       
    14  * You should have received a copy of the GNU General Public License
       
    15  * along with this program; if not, write to the Free Software
       
    16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
       
    17  *
       
    18  * Author: Yufei Cheng   <yfcheng@ittc.ku.edu>
       
    19  *
       
    20  * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director
       
    21  * ResiliNets Research Group  http://wiki.ittc.ku.edu/resilinets
       
    22  * Information and Telecommunication Technology Center (ITTC)
       
    23  * and Department of Electrical Engineering and Computer Science
       
    24  * The University of Kansas Lawrence, KS USA.
       
    25  *
       
    26  * Work supported in part by NSF FIND (Future Internet Design) Program
       
    27  * under grant CNS-0626918 (Postmodern Internet Architecture),
       
    28  * NSF grant CNS-1050226 (Multilayer Network Resilience Analysis and Experimentation on GENI),
       
    29  * US Department of Defense (DoD), and ITTC at The University of Kansas.
       
    30  */
       
    31 
       
    32 #include "ns3/assert.h"
       
    33 #include "ns3/log.h"
       
    34 #include "ns3/header.h"
       
    35 #include "dsr-option-header.h"
       
    36 #include "ns3/ipv4-address.h"
       
    37 #include "ns3/address-utils.h"
       
    38 #include "ns3/packet.h"
       
    39 #include "ns3/enum.h"
       
    40 
       
    41 
       
    42 namespace ns3 {
       
    43 namespace dsr {
       
    44 NS_LOG_COMPONENT_DEFINE ("DsrOptionHeader");
       
    45 
       
    46 NS_OBJECT_ENSURE_REGISTERED (DsrOptionHeader);
       
    47 
       
    48 TypeId DsrOptionHeader::GetTypeId ()
       
    49 {
       
    50   static TypeId tid = TypeId ("ns3::dsr::DsrOptionHeader")
       
    51     .AddConstructor<DsrOptionHeader> ()
       
    52     .SetParent<Header> ()
       
    53   ;
       
    54   return tid;
       
    55 }
       
    56 
       
    57 TypeId DsrOptionHeader::GetInstanceTypeId () const
       
    58 {
       
    59   return GetTypeId ();
       
    60 }
       
    61 
       
    62 DsrOptionHeader::DsrOptionHeader ()
       
    63   : m_type (0),
       
    64     m_length (0)
       
    65 {
       
    66 }
       
    67 
       
    68 DsrOptionHeader::~DsrOptionHeader ()
       
    69 {
       
    70 }
       
    71 
       
    72 void DsrOptionHeader::SetType (uint8_t type)
       
    73 {
       
    74   m_type = type;
       
    75 }
       
    76 
       
    77 uint8_t DsrOptionHeader::GetType () const
       
    78 {
       
    79   return m_type;
       
    80 }
       
    81 
       
    82 void DsrOptionHeader::SetLength (uint8_t length)
       
    83 {
       
    84   m_length = length;
       
    85 }
       
    86 
       
    87 uint8_t DsrOptionHeader::GetLength () const
       
    88 {
       
    89   return m_length;
       
    90 }
       
    91 
       
    92 void DsrOptionHeader::Print (std::ostream &os) const
       
    93 {
       
    94   os << "( type = " << (uint32_t)m_type << " length = " << (uint32_t)m_length << " )";
       
    95 }
       
    96 
       
    97 uint32_t DsrOptionHeader::GetSerializedSize () const
       
    98 {
       
    99   return m_length + 2;
       
   100 }
       
   101 
       
   102 void DsrOptionHeader::Serialize (Buffer::Iterator start) const
       
   103 {
       
   104   Buffer::Iterator i = start;
       
   105 
       
   106   i.WriteU8 (m_type);
       
   107   i.WriteU8 (m_length);
       
   108   i.Write (m_data.Begin (), m_data.End ());
       
   109 }
       
   110 
       
   111 uint32_t DsrOptionHeader::Deserialize (Buffer::Iterator start)
       
   112 {
       
   113   Buffer::Iterator i = start;
       
   114 
       
   115   m_type = i.ReadU8 ();
       
   116   m_length = i.ReadU8 ();
       
   117 
       
   118   m_data = Buffer ();
       
   119   m_data.AddAtEnd (m_length);
       
   120   Buffer::Iterator dataStart = i;
       
   121   i.Next (m_length);
       
   122   Buffer::Iterator dataEnd = i;
       
   123   m_data.Begin ().Write (dataStart, dataEnd);
       
   124 
       
   125   return GetSerializedSize ();
       
   126 }
       
   127 
       
   128 DsrOptionHeader::Alignment DsrOptionHeader::GetAlignment () const
       
   129 {
       
   130   Alignment retVal = { 1, 0 };
       
   131   return retVal;
       
   132 }
       
   133 
       
   134 NS_OBJECT_ENSURE_REGISTERED (DsrOptionPad1Header);
       
   135 
       
   136 TypeId DsrOptionPad1Header::GetTypeId ()
       
   137 {
       
   138   static TypeId tid = TypeId ("ns3::dsr::DsrOptionPad1Header")
       
   139     .AddConstructor<DsrOptionPad1Header> ()
       
   140     .SetParent<DsrOptionHeader> ()
       
   141   ;
       
   142   return tid;
       
   143 }
       
   144 
       
   145 TypeId DsrOptionPad1Header::GetInstanceTypeId () const
       
   146 {
       
   147   return GetTypeId ();
       
   148 }
       
   149 
       
   150 DsrOptionPad1Header::DsrOptionPad1Header ()
       
   151 {
       
   152   SetType (224);
       
   153 }
       
   154 
       
   155 DsrOptionPad1Header::~DsrOptionPad1Header ()
       
   156 {
       
   157 }
       
   158 
       
   159 void DsrOptionPad1Header::Print (std::ostream &os) const
       
   160 {
       
   161   os << "( type = " << (uint32_t)GetType () << " )";
       
   162 }
       
   163 
       
   164 uint32_t DsrOptionPad1Header::GetSerializedSize () const
       
   165 {
       
   166   return 1;
       
   167 }
       
   168 
       
   169 void DsrOptionPad1Header::Serialize (Buffer::Iterator start) const
       
   170 {
       
   171   Buffer::Iterator i = start;
       
   172 
       
   173   i.WriteU8 (GetType ());
       
   174 }
       
   175 
       
   176 uint32_t DsrOptionPad1Header::Deserialize (Buffer::Iterator start)
       
   177 {
       
   178   Buffer::Iterator i = start;
       
   179 
       
   180   SetType (i.ReadU8 ());
       
   181 
       
   182   return GetSerializedSize ();
       
   183 }
       
   184 
       
   185 NS_OBJECT_ENSURE_REGISTERED (DsrOptionPadnHeader);
       
   186 
       
   187 TypeId DsrOptionPadnHeader::GetTypeId ()
       
   188 {
       
   189   static TypeId tid = TypeId ("ns3::dsr::DsrOptionPadnHeader")
       
   190     .AddConstructor<DsrOptionPadnHeader> ()
       
   191     .SetParent<DsrOptionHeader> ()
       
   192   ;
       
   193   return tid;
       
   194 }
       
   195 
       
   196 TypeId DsrOptionPadnHeader::GetInstanceTypeId () const
       
   197 {
       
   198   return GetTypeId ();
       
   199 }
       
   200 
       
   201 DsrOptionPadnHeader::DsrOptionPadnHeader (uint32_t pad)
       
   202 {
       
   203   SetType (0);
       
   204   NS_ASSERT_MSG (pad >= 2, "PadN must be at least 2 bytes long");
       
   205   SetLength (pad - 2);
       
   206 }
       
   207 
       
   208 DsrOptionPadnHeader::~DsrOptionPadnHeader ()
       
   209 {
       
   210 }
       
   211 
       
   212 void DsrOptionPadnHeader::Print (std::ostream &os) const
       
   213 {
       
   214   os << "( type = " << (uint32_t)GetType () << " length = " << (uint32_t)GetLength () << " )";
       
   215 }
       
   216 
       
   217 uint32_t DsrOptionPadnHeader::GetSerializedSize () const
       
   218 {
       
   219   return GetLength () + 2;
       
   220 }
       
   221 
       
   222 void DsrOptionPadnHeader::Serialize (Buffer::Iterator start) const
       
   223 {
       
   224   Buffer::Iterator i = start;
       
   225 
       
   226   i.WriteU8 (GetType ());
       
   227   i.WriteU8 (GetLength ());
       
   228 
       
   229   for (int padding = 0; padding < GetLength (); padding++)
       
   230     {
       
   231       i.WriteU8 (0);
       
   232     }
       
   233 }
       
   234 
       
   235 uint32_t DsrOptionPadnHeader::Deserialize (Buffer::Iterator start)
       
   236 {
       
   237   Buffer::Iterator i = start;
       
   238 
       
   239   SetType (i.ReadU8 ());
       
   240   SetLength (i.ReadU8 ());
       
   241 
       
   242   return GetSerializedSize ();
       
   243 }
       
   244 
       
   245 NS_OBJECT_ENSURE_REGISTERED (DsrOptionRreqHeader);
       
   246 
       
   247 TypeId DsrOptionRreqHeader::GetTypeId ()
       
   248 {
       
   249   static TypeId tid = TypeId ("ns3::dsr::DsrOptionRreqHeader")
       
   250     .AddConstructor<DsrOptionRreqHeader> ()
       
   251     .SetParent<DsrOptionHeader> ()
       
   252   ;
       
   253   return tid;
       
   254 }
       
   255 
       
   256 TypeId DsrOptionRreqHeader::GetInstanceTypeId () const
       
   257 {
       
   258   return GetTypeId ();
       
   259 }
       
   260 
       
   261 DsrOptionRreqHeader::DsrOptionRreqHeader ()
       
   262   : m_ipv4Address (0)
       
   263 {
       
   264   SetType (1);
       
   265   SetLength (6 + m_ipv4Address.size () * 4);
       
   266 }
       
   267 
       
   268 DsrOptionRreqHeader::~DsrOptionRreqHeader ()
       
   269 {
       
   270 }
       
   271 
       
   272 void DsrOptionRreqHeader::SetNumberAddress (uint8_t n)
       
   273 {
       
   274   m_ipv4Address.clear ();
       
   275   m_ipv4Address.assign (n, Ipv4Address (""));
       
   276 }
       
   277 
       
   278 Ipv4Address DsrOptionRreqHeader::GetTarget ()
       
   279 {
       
   280   return m_target;
       
   281 }
       
   282 
       
   283 void DsrOptionRreqHeader::SetTarget (Ipv4Address target)
       
   284 {
       
   285   m_target = target;
       
   286 }
       
   287 
       
   288 void DsrOptionRreqHeader::AddNodeAddress (Ipv4Address ipv4)
       
   289 {
       
   290   m_ipv4Address.push_back (ipv4);
       
   291   SetLength (6 + m_ipv4Address.size () * 4);
       
   292 }
       
   293 
       
   294 void DsrOptionRreqHeader::SetNodesAddress (std::vector<Ipv4Address> ipv4Address)
       
   295 {
       
   296   m_ipv4Address = ipv4Address;
       
   297   SetLength (6 + m_ipv4Address.size () * 4);
       
   298 }
       
   299 
       
   300 std::vector<Ipv4Address> DsrOptionRreqHeader::GetNodesAddresses () const
       
   301 {
       
   302   return m_ipv4Address;
       
   303 }
       
   304 
       
   305 uint32_t DsrOptionRreqHeader::GetNodesNumber () const
       
   306 {
       
   307   return m_ipv4Address.size ();
       
   308 }
       
   309 
       
   310 void DsrOptionRreqHeader::SetNodeAddress (uint8_t index, Ipv4Address addr)
       
   311 {
       
   312   m_ipv4Address.at (index) = addr;
       
   313 }
       
   314 
       
   315 Ipv4Address DsrOptionRreqHeader::GetNodeAddress (uint8_t index) const
       
   316 {
       
   317   return m_ipv4Address.at (index);
       
   318 }
       
   319 
       
   320 void DsrOptionRreqHeader::SetId (uint16_t identification)
       
   321 {
       
   322   m_identification = identification;
       
   323 }
       
   324 
       
   325 uint16_t DsrOptionRreqHeader::GetId () const
       
   326 {
       
   327   return m_identification;
       
   328 }
       
   329 
       
   330 void DsrOptionRreqHeader::Print (std::ostream &os) const
       
   331 {
       
   332   os << "( type = " << (uint32_t)GetType () << " length = " << (uint32_t)GetLength () << "";
       
   333 
       
   334   for (std::vector<Ipv4Address>::const_iterator it = m_ipv4Address.begin (); it != m_ipv4Address.end (); it++)
       
   335     {
       
   336       os << *it << " ";
       
   337     }
       
   338 
       
   339   os << ")";
       
   340 }
       
   341 
       
   342 uint32_t DsrOptionRreqHeader::GetSerializedSize () const
       
   343 {
       
   344   return 8 + m_ipv4Address.size () * 4;
       
   345 }
       
   346 
       
   347 void DsrOptionRreqHeader::Serialize (Buffer::Iterator start) const
       
   348 {
       
   349   Buffer::Iterator i = start;
       
   350   uint8_t buff[4];
       
   351 
       
   352   i.WriteU8 (GetType ());
       
   353   i.WriteU8 (GetLength ());
       
   354   i.WriteHtonU16 (m_identification);
       
   355   WriteTo (i, m_target);
       
   356 
       
   357   for (VectorIpv4Address_t::const_iterator it = m_ipv4Address.begin (); it != m_ipv4Address.end (); it++)
       
   358     {
       
   359       it->Serialize (buff);
       
   360       i.Write (buff, 4);
       
   361     }
       
   362 }
       
   363 
       
   364 uint32_t DsrOptionRreqHeader::Deserialize (Buffer::Iterator start)
       
   365 {
       
   366   Buffer::Iterator i = start;
       
   367   uint8_t buff[4];
       
   368 
       
   369   SetType (i.ReadU8 ());
       
   370   SetLength (i.ReadU8 ());
       
   371   m_identification = i.ReadNtohU16 ();
       
   372   ReadFrom (i, m_target);
       
   373 
       
   374   uint8_t index = 0;
       
   375   for (std::vector<Ipv4Address>::iterator it = m_ipv4Address.begin (); it != m_ipv4Address.end (); it++)
       
   376     {
       
   377       i.Read (buff, 4);
       
   378       m_address = it->Deserialize (buff);
       
   379       SetNodeAddress (index, m_address);
       
   380       ++index;
       
   381     }
       
   382 
       
   383   return GetSerializedSize ();
       
   384 }
       
   385 
       
   386 DsrOptionHeader::Alignment DsrOptionRreqHeader::GetAlignment () const
       
   387 {
       
   388   Alignment retVal = { 4, 0 };
       
   389   return retVal;
       
   390 }
       
   391 
       
   392 NS_OBJECT_ENSURE_REGISTERED (DsrOptionRrepHeader);
       
   393 
       
   394 TypeId DsrOptionRrepHeader::GetTypeId ()
       
   395 {
       
   396   static TypeId tid = TypeId ("ns3::dsr::DsrOptionRrepHeader")
       
   397     .AddConstructor<DsrOptionRrepHeader> ()
       
   398     .SetParent<DsrOptionHeader> ()
       
   399   ;
       
   400   return tid;
       
   401 }
       
   402 
       
   403 TypeId DsrOptionRrepHeader::GetInstanceTypeId () const
       
   404 {
       
   405   return GetTypeId ();
       
   406 }
       
   407 
       
   408 DsrOptionRrepHeader::DsrOptionRrepHeader ()
       
   409   : m_ipv4Address (0)
       
   410 {
       
   411   SetType (2);
       
   412   SetLength (2 + m_ipv4Address.size () * 4);
       
   413 }
       
   414 
       
   415 DsrOptionRrepHeader::~DsrOptionRrepHeader ()
       
   416 {
       
   417 }
       
   418 
       
   419 void DsrOptionRrepHeader::SetNumberAddress (uint8_t n)
       
   420 {
       
   421   m_ipv4Address.clear ();
       
   422   m_ipv4Address.assign (n, Ipv4Address (""));
       
   423 }
       
   424 
       
   425 void DsrOptionRrepHeader::SetNodesAddress (std::vector<Ipv4Address> ipv4Address)
       
   426 {
       
   427   m_ipv4Address = ipv4Address;
       
   428   SetLength (2 + m_ipv4Address.size () * 4);
       
   429 }
       
   430 
       
   431 std::vector<Ipv4Address> DsrOptionRrepHeader::GetNodesAddress () const
       
   432 {
       
   433   return m_ipv4Address;
       
   434 }
       
   435 
       
   436 void DsrOptionRrepHeader::SetNodeAddress (uint8_t index, Ipv4Address addr)
       
   437 {
       
   438   m_ipv4Address.at (index) = addr;
       
   439 }
       
   440 
       
   441 Ipv4Address DsrOptionRrepHeader::GetNodeAddress (uint8_t index) const
       
   442 {
       
   443   return m_ipv4Address.at (index);
       
   444 }
       
   445 
       
   446 Ipv4Address DsrOptionRrepHeader::GetTargetAddress (std::vector<Ipv4Address> ipv4Address) const
       
   447 {
       
   448   return m_ipv4Address.at (ipv4Address.size () - 1);
       
   449 }
       
   450 
       
   451 void DsrOptionRrepHeader::Print (std::ostream &os) const
       
   452 {
       
   453   os << "( type = " << (uint32_t)GetType () << " length = " << (uint32_t)GetLength () << "";
       
   454 
       
   455   for (std::vector<Ipv4Address>::const_iterator it = m_ipv4Address.begin (); it != m_ipv4Address.end (); it++)
       
   456     {
       
   457       os << *it << " ";
       
   458     }
       
   459 
       
   460   os << ")";
       
   461 }
       
   462 
       
   463 uint32_t DsrOptionRrepHeader::GetSerializedSize () const
       
   464 {
       
   465   return 4 + m_ipv4Address.size () * 4;
       
   466 }
       
   467 
       
   468 void DsrOptionRrepHeader::Serialize (Buffer::Iterator start) const
       
   469 {
       
   470   Buffer::Iterator i = start;
       
   471   uint8_t buff[4];
       
   472 
       
   473   i.WriteU8 (GetType ());
       
   474   i.WriteU8 (GetLength ());
       
   475   i.WriteU8 (0);
       
   476   i.WriteU8 (0);
       
   477 
       
   478   for (VectorIpv4Address_t::const_iterator it = m_ipv4Address.begin (); it != m_ipv4Address.end (); it++)
       
   479     {
       
   480       it->Serialize (buff);
       
   481       i.Write (buff, 4);
       
   482     }
       
   483 }
       
   484 
       
   485 uint32_t DsrOptionRrepHeader::Deserialize (Buffer::Iterator start)
       
   486 {
       
   487   Buffer::Iterator i = start;
       
   488   uint8_t buff[4];
       
   489 
       
   490   SetType (i.ReadU8 ());
       
   491   SetLength (i.ReadU8 ());
       
   492   i.ReadU8 ();
       
   493   i.ReadU8 ();
       
   494 
       
   495   uint8_t index = 0;
       
   496   for (std::vector<Ipv4Address>::iterator it = m_ipv4Address.begin (); it != m_ipv4Address.end (); it++)
       
   497     {
       
   498       i.Read (buff, 4);
       
   499       m_address = it->Deserialize (buff);
       
   500       SetNodeAddress (index, m_address);
       
   501       ++index;
       
   502     }
       
   503 
       
   504   return GetSerializedSize ();
       
   505 }
       
   506 
       
   507 DsrOptionHeader::Alignment DsrOptionRrepHeader::GetAlignment () const
       
   508 {
       
   509   Alignment retVal = { 4, 0 };
       
   510   return retVal;
       
   511 }
       
   512 
       
   513 NS_OBJECT_ENSURE_REGISTERED (DsrOptionSRHeader);
       
   514 
       
   515 TypeId DsrOptionSRHeader::GetTypeId ()
       
   516 {
       
   517   static TypeId tid = TypeId ("ns3::dsr::DsrOptionSRHeader")
       
   518     .AddConstructor<DsrOptionSRHeader> ()
       
   519     .SetParent<DsrOptionHeader> ()
       
   520   ;
       
   521   return tid;
       
   522 }
       
   523 
       
   524 TypeId DsrOptionSRHeader::GetInstanceTypeId () const
       
   525 {
       
   526   return GetTypeId ();
       
   527 }
       
   528 
       
   529 DsrOptionSRHeader::DsrOptionSRHeader ()
       
   530   : m_segmentsLeft (0),
       
   531     m_ipv4Address (0)
       
   532 {
       
   533   SetType (96);
       
   534   SetLength (2 + m_ipv4Address.size () * 4);
       
   535 }
       
   536 
       
   537 DsrOptionSRHeader::~DsrOptionSRHeader ()
       
   538 {
       
   539 }
       
   540 
       
   541 void DsrOptionSRHeader::SetSegmentsLeft (uint8_t segmentsLeft)
       
   542 {
       
   543   m_segmentsLeft = segmentsLeft;
       
   544 }
       
   545 
       
   546 uint8_t DsrOptionSRHeader::GetSegmentsLeft () const
       
   547 {
       
   548   return m_segmentsLeft;
       
   549 }
       
   550 
       
   551 void DsrOptionSRHeader::SetSalvage (uint8_t salvage)
       
   552 {
       
   553   m_salvage = salvage;
       
   554 }
       
   555 
       
   556 uint8_t DsrOptionSRHeader::GetSalvage () const
       
   557 {
       
   558   return m_salvage;
       
   559 }
       
   560 
       
   561 void DsrOptionSRHeader::SetNumberAddress (uint8_t n)
       
   562 {
       
   563   m_ipv4Address.clear ();
       
   564   m_ipv4Address.assign (n, Ipv4Address (""));
       
   565 }
       
   566 
       
   567 void DsrOptionSRHeader::SetNodesAddress (std::vector<Ipv4Address> ipv4Address)
       
   568 {
       
   569   m_ipv4Address = ipv4Address;
       
   570   SetLength (2 + m_ipv4Address.size () * 4);
       
   571 }
       
   572 
       
   573 std::vector<Ipv4Address> DsrOptionSRHeader::GetNodesAddress () const
       
   574 {
       
   575   return m_ipv4Address;
       
   576 }
       
   577 
       
   578 void DsrOptionSRHeader::SetNodeAddress (uint8_t index, Ipv4Address addr)
       
   579 {
       
   580   m_ipv4Address.at (index) = addr;
       
   581 }
       
   582 
       
   583 Ipv4Address DsrOptionSRHeader::GetNodeAddress (uint8_t index) const
       
   584 {
       
   585   return m_ipv4Address.at (index);
       
   586 }
       
   587 
       
   588 uint8_t DsrOptionSRHeader::GetNodeListSize () const
       
   589 {
       
   590   return m_ipv4Address.size ();
       
   591 }
       
   592 
       
   593 void DsrOptionSRHeader::Print (std::ostream &os) const
       
   594 {
       
   595   os << "( type = " << (uint32_t)GetType () << " length = " << (uint32_t)GetLength () << "";
       
   596 
       
   597   for (std::vector<Ipv4Address>::const_iterator it = m_ipv4Address.begin (); it != m_ipv4Address.end (); it++)
       
   598     {
       
   599       os << *it << " ";
       
   600     }
       
   601 
       
   602   os << ")";
       
   603 }
       
   604 
       
   605 uint32_t DsrOptionSRHeader::GetSerializedSize () const
       
   606 {
       
   607   return 4 + m_ipv4Address.size () * 4;
       
   608 }
       
   609 
       
   610 void DsrOptionSRHeader::Serialize (Buffer::Iterator start) const
       
   611 {
       
   612   Buffer::Iterator i = start;
       
   613   uint8_t buff[4];
       
   614 
       
   615   i.WriteU8 (GetType ());
       
   616   i.WriteU8 (GetLength ());
       
   617   i.WriteU8 (m_salvage);
       
   618   i.WriteU8 (m_segmentsLeft);
       
   619 
       
   620   for (VectorIpv4Address_t::const_iterator it = m_ipv4Address.begin (); it != m_ipv4Address.end (); it++)
       
   621     {
       
   622       it->Serialize (buff);
       
   623       i.Write (buff, 4);
       
   624     }
       
   625 }
       
   626 
       
   627 uint32_t DsrOptionSRHeader::Deserialize (Buffer::Iterator start)
       
   628 {
       
   629   Buffer::Iterator i = start;
       
   630   uint8_t buff[4];
       
   631 
       
   632   SetType (i.ReadU8 ());
       
   633   SetLength (i.ReadU8 ());
       
   634   m_salvage = i.ReadU8 ();
       
   635   m_segmentsLeft = i.ReadU8 ();
       
   636 
       
   637   uint8_t index = 0;
       
   638   for (std::vector<Ipv4Address>::iterator it = m_ipv4Address.begin (); it != m_ipv4Address.end (); it++)
       
   639     {
       
   640       i.Read (buff, 4);
       
   641       m_address = it->Deserialize (buff);
       
   642       SetNodeAddress (index, m_address);
       
   643       ++index;
       
   644     }
       
   645 
       
   646   return GetSerializedSize ();
       
   647 }
       
   648 
       
   649 DsrOptionHeader::Alignment DsrOptionSRHeader::GetAlignment () const
       
   650 {
       
   651   Alignment retVal = { 4, 0 };
       
   652   return retVal;
       
   653 }
       
   654 
       
   655 NS_OBJECT_ENSURE_REGISTERED (DsrOptionRerrHeader);
       
   656 
       
   657 TypeId DsrOptionRerrHeader::GetTypeId ()
       
   658 {
       
   659   static TypeId tid = TypeId ("ns3::dsr::DsrOptionRerrHeader")
       
   660     .AddConstructor<DsrOptionRerrHeader> ()
       
   661     .SetParent<DsrOptionHeader> ()
       
   662     .AddAttribute ("ErrorType","Type of route errors",
       
   663                    EnumValue (NODE_UNREACHABLE),
       
   664                    MakeEnumAccessor (&DsrOptionRerrHeader::m_errorType),
       
   665                    MakeEnumChecker (NODE_UNREACHABLE, "Node unreachable",
       
   666                                     FLOW_STATE_NOT_SUPPORTED, "Flow state not supported",
       
   667                                     OPTION_NOT_SUPPORTED, "Option not supported"))
       
   668   ;
       
   669   return tid;
       
   670 }
       
   671 
       
   672 TypeId DsrOptionRerrHeader::GetInstanceTypeId () const
       
   673 {
       
   674   return GetTypeId ();
       
   675 }
       
   676 
       
   677 DsrOptionRerrHeader::DsrOptionRerrHeader ()
       
   678   : m_errorType (0),
       
   679     m_reserved (0),
       
   680     m_salvage (0),
       
   681     m_errorLength (4)
       
   682 {
       
   683   SetType (3);
       
   684   SetLength (14);
       
   685 }
       
   686 
       
   687 DsrOptionRerrHeader::~DsrOptionRerrHeader ()
       
   688 {
       
   689 }
       
   690 
       
   691 void DsrOptionRerrHeader::SetErrorType (uint8_t errorType)
       
   692 {
       
   693   m_errorType = errorType;
       
   694 }
       
   695 
       
   696 uint8_t DsrOptionRerrHeader::GetErrorType () const
       
   697 {
       
   698   return m_errorType;
       
   699 }
       
   700 
       
   701 void DsrOptionRerrHeader::SetSalvage (uint8_t salvage)
       
   702 {
       
   703   m_salvage = salvage;
       
   704 }
       
   705 
       
   706 uint8_t DsrOptionRerrHeader::GetSalvage () const
       
   707 {
       
   708   return m_salvage;
       
   709 }
       
   710 
       
   711 void DsrOptionRerrHeader::SetErrorSrc (Ipv4Address errorSrcAddress)
       
   712 {
       
   713   m_errorSrcAddress = errorSrcAddress;
       
   714 }
       
   715 
       
   716 Ipv4Address DsrOptionRerrHeader::GetErrorSrc () const
       
   717 {
       
   718   return m_errorSrcAddress;
       
   719 }
       
   720 
       
   721 void DsrOptionRerrHeader::SetErrorDst (Ipv4Address errorDstAddress)
       
   722 {
       
   723   m_errorDstAddress = errorDstAddress;
       
   724 }
       
   725 
       
   726 Ipv4Address DsrOptionRerrHeader::GetErrorDst () const
       
   727 {
       
   728   return m_errorDstAddress;
       
   729 }
       
   730 
       
   731 void DsrOptionRerrHeader::Print (std::ostream &os) const
       
   732 {
       
   733   os << "( type = " << (uint32_t)GetType () << " length = " << (uint32_t)GetLength ()
       
   734      << " errorType = " << (uint32_t)m_errorType << " salvage = " << (uint32_t)m_salvage
       
   735      << " error source = " << m_errorSrcAddress << " error dst = " << m_errorDstAddress << " )";
       
   736 
       
   737 }
       
   738 
       
   739 uint32_t DsrOptionRerrHeader::GetSerializedSize () const
       
   740 {
       
   741   return 16;
       
   742 }
       
   743 
       
   744 void DsrOptionRerrHeader::Serialize (Buffer::Iterator start) const
       
   745 {
       
   746   Buffer::Iterator i = start;
       
   747 
       
   748   i.WriteU8 (GetType ());
       
   749   i.WriteU8 (GetLength ());
       
   750   i.WriteU8 (m_errorType);
       
   751   i.WriteU8 (m_salvage);
       
   752   WriteTo (i, m_errorSrcAddress);
       
   753   WriteTo (i, m_errorDstAddress);
       
   754   i.Write (m_errorData.Begin (), m_errorData.End ());
       
   755 }
       
   756 
       
   757 uint32_t DsrOptionRerrHeader::Deserialize (Buffer::Iterator start)
       
   758 {
       
   759   Buffer::Iterator i = start;
       
   760 
       
   761   SetType (i.ReadU8 ());
       
   762   SetLength (i.ReadU8 ());
       
   763   m_errorType = i.ReadU8 ();
       
   764   m_salvage = i.ReadU8 ();
       
   765   ReadFrom (i, m_errorSrcAddress);
       
   766   ReadFrom (i, m_errorDstAddress);
       
   767 
       
   768   m_errorData = Buffer ();
       
   769   m_errorData.AddAtEnd (m_errorLength);
       
   770   Buffer::Iterator dataStart = i;
       
   771   i.Next (m_errorLength);
       
   772   Buffer::Iterator dataEnd = i;
       
   773   m_errorData.Begin ().Write (dataStart, dataEnd);
       
   774 
       
   775   return GetSerializedSize ();
       
   776 }
       
   777 
       
   778 DsrOptionHeader::Alignment DsrOptionRerrHeader::GetAlignment () const
       
   779 {
       
   780   Alignment retVal = { 4, 0 };
       
   781   return retVal;
       
   782 }
       
   783 
       
   784 NS_OBJECT_ENSURE_REGISTERED (DsrOptionRerrUnreachHeader);
       
   785 
       
   786 TypeId DsrOptionRerrUnreachHeader::GetTypeId ()
       
   787 {
       
   788   static TypeId tid = TypeId ("ns3::dsr::DsrOptionRerrUnreachHeader")
       
   789     .AddConstructor<DsrOptionRerrUnreachHeader> ()
       
   790     .SetParent<DsrOptionRerrHeader> ()
       
   791   ;
       
   792   return tid;
       
   793 }
       
   794 
       
   795 TypeId DsrOptionRerrUnreachHeader::GetInstanceTypeId () const
       
   796 {
       
   797   return GetTypeId ();
       
   798 }
       
   799 
       
   800 DsrOptionRerrUnreachHeader::DsrOptionRerrUnreachHeader ()
       
   801   :    m_reserved (0),
       
   802     m_salvage (0)
       
   803 {
       
   804   SetType (3);
       
   805   SetLength (14);
       
   806   SetErrorType (1);
       
   807 }
       
   808 
       
   809 DsrOptionRerrUnreachHeader::~DsrOptionRerrUnreachHeader ()
       
   810 {
       
   811 }
       
   812 
       
   813 void DsrOptionRerrUnreachHeader::SetSalvage (uint8_t salvage)
       
   814 {
       
   815   m_salvage = salvage;
       
   816 }
       
   817 
       
   818 uint8_t DsrOptionRerrUnreachHeader::GetSalvage () const
       
   819 {
       
   820   return m_salvage;
       
   821 }
       
   822 
       
   823 void DsrOptionRerrUnreachHeader::SetErrorSrc (Ipv4Address errorSrcAddress)
       
   824 {
       
   825   m_errorSrcAddress = errorSrcAddress;
       
   826 }
       
   827 
       
   828 Ipv4Address DsrOptionRerrUnreachHeader::GetErrorSrc () const
       
   829 {
       
   830   return m_errorSrcAddress;
       
   831 }
       
   832 
       
   833 void DsrOptionRerrUnreachHeader::SetErrorDst (Ipv4Address errorDstAddress)
       
   834 {
       
   835   m_errorDstAddress = errorDstAddress;
       
   836 }
       
   837 
       
   838 Ipv4Address DsrOptionRerrUnreachHeader::GetErrorDst () const
       
   839 {
       
   840   return m_errorDstAddress;
       
   841 }
       
   842 
       
   843 void DsrOptionRerrUnreachHeader::SetUnreachNode (Ipv4Address unreachNode)
       
   844 {
       
   845   m_unreachNode = unreachNode;
       
   846 }
       
   847 
       
   848 Ipv4Address DsrOptionRerrUnreachHeader::GetUnreachNode () const
       
   849 {
       
   850   return m_unreachNode;
       
   851 }
       
   852 
       
   853 void DsrOptionRerrUnreachHeader::Print (std::ostream &os) const
       
   854 {
       
   855   os << "( type = " << (uint32_t)GetType () << " length = " << (uint32_t)GetLength ()
       
   856      << " errorType = " << (uint32_t)m_errorType << " salvage = " << (uint32_t)m_salvage
       
   857      << " error source = " << m_errorSrcAddress << " error dst = " << m_errorDstAddress
       
   858      << " unreach node = " <<  m_unreachNode << " )";
       
   859 }
       
   860 
       
   861 uint32_t DsrOptionRerrUnreachHeader::GetSerializedSize () const
       
   862 {
       
   863   return 16;
       
   864 }
       
   865 
       
   866 void DsrOptionRerrUnreachHeader::Serialize (Buffer::Iterator start) const
       
   867 {
       
   868   Buffer::Iterator i = start;
       
   869 
       
   870   i.WriteU8 (GetType ());
       
   871   i.WriteU8 (GetLength ());
       
   872   i.WriteU8 (GetErrorType ());
       
   873   i.WriteU8 (m_salvage);
       
   874   WriteTo (i, m_errorSrcAddress);
       
   875   WriteTo (i, m_errorDstAddress);
       
   876   WriteTo (i, m_unreachNode);
       
   877 
       
   878 }
       
   879 
       
   880 uint32_t DsrOptionRerrUnreachHeader::Deserialize (Buffer::Iterator start)
       
   881 {
       
   882   Buffer::Iterator i = start;
       
   883 
       
   884   SetType (i.ReadU8 ());
       
   885   SetLength (i.ReadU8 ());
       
   886   SetErrorType (i.ReadU8 ());
       
   887   m_salvage = i.ReadU8 ();
       
   888   ReadFrom (i, m_errorSrcAddress);
       
   889   ReadFrom (i, m_errorDstAddress);
       
   890   ReadFrom (i, m_unreachNode);
       
   891 
       
   892   return GetSerializedSize ();
       
   893 }
       
   894 
       
   895 DsrOptionHeader::Alignment DsrOptionRerrUnreachHeader::GetAlignment () const
       
   896 {
       
   897   Alignment retVal = { 4, 0 };
       
   898   return retVal;
       
   899 }
       
   900 
       
   901 NS_OBJECT_ENSURE_REGISTERED (DsrOptionRerrUnsupportHeader);
       
   902 
       
   903 TypeId DsrOptionRerrUnsupportHeader::GetTypeId ()
       
   904 {
       
   905   static TypeId tid = TypeId ("ns3::dsr::DsrOptionRerrUnsupportHeader")
       
   906     .AddConstructor<DsrOptionRerrUnsupportHeader> ()
       
   907     .SetParent<DsrOptionRerrHeader> ()
       
   908   ;
       
   909   return tid;
       
   910 }
       
   911 
       
   912 TypeId DsrOptionRerrUnsupportHeader::GetInstanceTypeId () const
       
   913 {
       
   914   return GetTypeId ();
       
   915 }
       
   916 
       
   917 DsrOptionRerrUnsupportHeader::DsrOptionRerrUnsupportHeader ()
       
   918   :    m_reserved (0),
       
   919     m_salvage (0)
       
   920 {
       
   921   SetType (3);
       
   922   SetLength (14);
       
   923   SetErrorType (3);
       
   924 }
       
   925 
       
   926 DsrOptionRerrUnsupportHeader::~DsrOptionRerrUnsupportHeader ()
       
   927 {
       
   928 }
       
   929 
       
   930 void DsrOptionRerrUnsupportHeader::SetSalvage (uint8_t salvage)
       
   931 {
       
   932   m_salvage = salvage;
       
   933 }
       
   934 
       
   935 uint8_t DsrOptionRerrUnsupportHeader::GetSalvage () const
       
   936 {
       
   937   return m_salvage;
       
   938 }
       
   939 
       
   940 void DsrOptionRerrUnsupportHeader::SetErrorSrc (Ipv4Address errorSrcAddress)
       
   941 {
       
   942   m_errorSrcAddress = errorSrcAddress;
       
   943 }
       
   944 
       
   945 Ipv4Address DsrOptionRerrUnsupportHeader::GetErrorSrc () const
       
   946 {
       
   947   return m_errorSrcAddress;
       
   948 }
       
   949 
       
   950 void DsrOptionRerrUnsupportHeader::SetErrorDst (Ipv4Address errorDstAddress)
       
   951 {
       
   952   m_errorDstAddress = errorDstAddress;
       
   953 }
       
   954 
       
   955 Ipv4Address DsrOptionRerrUnsupportHeader::GetErrorDst () const
       
   956 {
       
   957   return m_errorDstAddress;
       
   958 }
       
   959 
       
   960 void DsrOptionRerrUnsupportHeader::SetUnsupported (uint16_t unsupport)
       
   961 {
       
   962   m_unsupport = unsupport;
       
   963 }
       
   964 
       
   965 uint16_t DsrOptionRerrUnsupportHeader::GetUnsupported () const
       
   966 {
       
   967   return m_unsupport;
       
   968 }
       
   969 
       
   970 void DsrOptionRerrUnsupportHeader::Print (std::ostream &os) const
       
   971 {
       
   972   os << "( type = " << (uint32_t)GetType () << " length = " << (uint32_t)GetLength ()
       
   973      << " errorType = " << (uint32_t)m_errorType << " salvage = " << (uint32_t)m_salvage
       
   974      << " error source = " << m_errorSrcAddress << " error dst = " << m_errorDstAddress
       
   975      << " unsupported option = " <<  m_unsupport << " )";
       
   976 
       
   977 }
       
   978 
       
   979 uint32_t DsrOptionRerrUnsupportHeader::GetSerializedSize () const
       
   980 {
       
   981   return 16;
       
   982 }
       
   983 
       
   984 void DsrOptionRerrUnsupportHeader::Serialize (Buffer::Iterator start) const
       
   985 {
       
   986   Buffer::Iterator i = start;
       
   987 
       
   988   i.WriteU8 (GetType ());
       
   989   i.WriteU8 (GetLength ());
       
   990   i.WriteU8 (GetErrorType ());
       
   991   i.WriteU8 (m_salvage);
       
   992   WriteTo (i, m_errorSrcAddress);
       
   993   WriteTo (i, m_errorDstAddress);
       
   994   i.WriteU16 (m_unsupport);
       
   995 
       
   996 }
       
   997 
       
   998 uint32_t DsrOptionRerrUnsupportHeader::Deserialize (Buffer::Iterator start)
       
   999 {
       
  1000   Buffer::Iterator i = start;
       
  1001 
       
  1002   SetType (i.ReadU8 ());
       
  1003   SetLength (i.ReadU8 ());
       
  1004   SetErrorType (i.ReadU8 ());
       
  1005   m_salvage = i.ReadU8 ();
       
  1006   ReadFrom (i, m_errorSrcAddress);
       
  1007   ReadFrom (i, m_errorDstAddress);
       
  1008   m_unsupport = i.ReadU16 ();
       
  1009 
       
  1010   return GetSerializedSize ();
       
  1011 }
       
  1012 
       
  1013 DsrOptionHeader::Alignment DsrOptionRerrUnsupportHeader::GetAlignment () const
       
  1014 {
       
  1015   Alignment retVal = { 4, 0 };
       
  1016   return retVal;
       
  1017 }
       
  1018 
       
  1019 NS_OBJECT_ENSURE_REGISTERED (DsrOptionAckReqHeader);
       
  1020 
       
  1021 TypeId DsrOptionAckReqHeader::GetTypeId ()
       
  1022 {
       
  1023   static TypeId tid = TypeId ("ns3::dsr::DsrOptionAckReqHeader")
       
  1024     .AddConstructor<DsrOptionAckReqHeader> ()
       
  1025     .SetParent<DsrOptionHeader> ()
       
  1026   ;
       
  1027   return tid;
       
  1028 }
       
  1029 
       
  1030 TypeId DsrOptionAckReqHeader::GetInstanceTypeId () const
       
  1031 {
       
  1032   return GetTypeId ();
       
  1033 }
       
  1034 
       
  1035 DsrOptionAckReqHeader::DsrOptionAckReqHeader ()
       
  1036   : m_identification (0)
       
  1037 
       
  1038 {
       
  1039   SetType (160);
       
  1040   SetLength (2);
       
  1041 }
       
  1042 
       
  1043 DsrOptionAckReqHeader::~DsrOptionAckReqHeader ()
       
  1044 {
       
  1045 }
       
  1046 
       
  1047 void DsrOptionAckReqHeader::SetAckId (uint16_t identification)
       
  1048 {
       
  1049   m_identification = identification;
       
  1050 }
       
  1051 
       
  1052 uint16_t DsrOptionAckReqHeader::GetAckId () const
       
  1053 {
       
  1054   return m_identification;
       
  1055 }
       
  1056 
       
  1057 void DsrOptionAckReqHeader::Print (std::ostream &os) const
       
  1058 {
       
  1059   os << "( type = " << (uint32_t)GetType () << " length = " << (uint32_t)GetLength ()
       
  1060      << " id = " << m_identification << " )";
       
  1061 }
       
  1062 
       
  1063 uint32_t DsrOptionAckReqHeader::GetSerializedSize () const
       
  1064 {
       
  1065   return 4;
       
  1066 }
       
  1067 
       
  1068 void DsrOptionAckReqHeader::Serialize (Buffer::Iterator start) const
       
  1069 {
       
  1070   Buffer::Iterator i = start;
       
  1071 
       
  1072   i.WriteU8 (GetType ());
       
  1073   i.WriteU8 (GetLength ());
       
  1074   i.WriteU16 (m_identification);
       
  1075 }
       
  1076 
       
  1077 uint32_t DsrOptionAckReqHeader::Deserialize (Buffer::Iterator start)
       
  1078 {
       
  1079   Buffer::Iterator i = start;
       
  1080 
       
  1081   SetType (i.ReadU8 ());
       
  1082   SetLength (i.ReadU8 ());
       
  1083   m_identification = i.ReadU16 ();
       
  1084 
       
  1085   return GetSerializedSize ();
       
  1086 }
       
  1087 
       
  1088 DsrOptionHeader::Alignment DsrOptionAckReqHeader::GetAlignment () const
       
  1089 {
       
  1090   Alignment retVal = { 4, 0 };
       
  1091   return retVal;
       
  1092 }
       
  1093 
       
  1094 NS_OBJECT_ENSURE_REGISTERED (DsrOptionAckHeader);
       
  1095 
       
  1096 TypeId DsrOptionAckHeader::GetTypeId ()
       
  1097 {
       
  1098   static TypeId tid = TypeId ("ns3::dsr::DsrOptionAckHeader")
       
  1099     .AddConstructor<DsrOptionAckHeader> ()
       
  1100     .SetParent<DsrOptionHeader> ()
       
  1101   ;
       
  1102   return tid;
       
  1103 }
       
  1104 
       
  1105 TypeId DsrOptionAckHeader::GetInstanceTypeId () const
       
  1106 {
       
  1107   return GetTypeId ();
       
  1108 }
       
  1109 
       
  1110 DsrOptionAckHeader::DsrOptionAckHeader ()
       
  1111   :    m_identification (0)
       
  1112 {
       
  1113   SetType (32);
       
  1114   SetLength (10);
       
  1115 }
       
  1116 
       
  1117 DsrOptionAckHeader::~DsrOptionAckHeader ()
       
  1118 {
       
  1119 }
       
  1120 
       
  1121 void DsrOptionAckHeader::SetAckId (uint16_t identification)
       
  1122 {
       
  1123   m_identification = identification;
       
  1124 }
       
  1125 
       
  1126 uint16_t DsrOptionAckHeader::GetAckId () const
       
  1127 {
       
  1128   return m_identification;
       
  1129 }
       
  1130 
       
  1131 void DsrOptionAckHeader::SetRealSrc (Ipv4Address realSrcAddress)
       
  1132 {
       
  1133   m_realSrcAddress = realSrcAddress;
       
  1134 }
       
  1135 
       
  1136 Ipv4Address DsrOptionAckHeader::GetRealSrc () const
       
  1137 {
       
  1138   return m_realSrcAddress;
       
  1139 }
       
  1140 
       
  1141 void DsrOptionAckHeader::SetRealDst (Ipv4Address realDstAddress)
       
  1142 {
       
  1143   m_realDstAddress = realDstAddress;
       
  1144 }
       
  1145 
       
  1146 Ipv4Address DsrOptionAckHeader::GetRealDst () const
       
  1147 {
       
  1148   return m_realDstAddress;
       
  1149 }
       
  1150 
       
  1151 void DsrOptionAckHeader::Print (std::ostream &os) const
       
  1152 {
       
  1153   os << "( type = " << (uint32_t)GetType () << " length = " << (uint32_t)GetLength ()
       
  1154      << " id = " << m_identification << " real src = " << m_realSrcAddress
       
  1155      << " real dst = " << m_realDstAddress << " )";
       
  1156 
       
  1157 }
       
  1158 
       
  1159 uint32_t DsrOptionAckHeader::GetSerializedSize () const
       
  1160 {
       
  1161   return 12;
       
  1162 }
       
  1163 
       
  1164 void DsrOptionAckHeader::Serialize (Buffer::Iterator start) const
       
  1165 {
       
  1166   Buffer::Iterator i = start;
       
  1167 
       
  1168   i.WriteU8 (GetType ());
       
  1169   i.WriteU8 (GetLength ());
       
  1170   i.WriteU16 (m_identification);
       
  1171   WriteTo (i, m_realSrcAddress);
       
  1172   WriteTo (i, m_realDstAddress);
       
  1173 }
       
  1174 
       
  1175 uint32_t DsrOptionAckHeader::Deserialize (Buffer::Iterator start)
       
  1176 {
       
  1177   Buffer::Iterator i = start;
       
  1178 
       
  1179   SetType (i.ReadU8 ());
       
  1180   SetLength (i.ReadU8 ());
       
  1181   m_identification = i.ReadU16 ();
       
  1182   ReadFrom (i, m_realSrcAddress);
       
  1183   ReadFrom (i, m_realDstAddress);
       
  1184 
       
  1185   return GetSerializedSize ();
       
  1186 }
       
  1187 
       
  1188 DsrOptionHeader::Alignment DsrOptionAckHeader::GetAlignment () const
       
  1189 {
       
  1190   Alignment retVal = { 4, 0 };
       
  1191   return retVal;
       
  1192 }
       
  1193 } /* namespace dsr */
       
  1194 } /* namespace ns3 */