src/node/packetbb.h
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Thu Nov 12 13:01:01 2009 +0100 (2009-11-12)
changeset 5505 c0ac392289c3
parent 5263 a0283279fddd
child 5943 afda15a818fa
permissions -rw-r--r--
replace RefCountBase with SimpleRefCount<> to avoid duplicate refcounting implementations.
     1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
     2 /* vim: set ts=2 sw=2 sta expandtab ai si cin: */
     3 /* 
     4  * Copyright (c) 2009 Drexel University
     5  * 
     6  * This program is free software; you can redistribute it and/or modify
     7  * it under the terms of the GNU General Public License version 2 as
     8  * published by the Free Software Foundation;
     9  *
    10  * This program is distributed in the hope that it will be useful,
    11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13  * GNU General Public License for more details.
    14  *
    15  * You should have received a copy of the GNU General Public License
    16  * along with this program; if not, write to the Free Software
    17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    18  * 
    19  * Author: Tom Wambold <tom5760@gmail.com>
    20  */
    21 /* These classes implement RFC 5444 - The Generalized Mobile Ad Hoc Network
    22  * (MANET) Packet/PbbMessage Format
    23  * See: http://tools.ietf.org/html/rfc5444 for details */
    24 
    25 #ifndef PACKETBB_H
    26 #define PACKETBB_H
    27 
    28 #include <list>
    29 
    30 #include "ns3/ptr.h"
    31 #include "ns3/address.h"
    32 #include "ns3/header.h"
    33 #include "ns3/buffer.h"
    34 #include "ns3/simple-ref-count.h"
    35 
    36 namespace ns3 {
    37 
    38 /* Forward declare objects */
    39 class PbbMessage;
    40 class PbbAddressBlock;
    41 class PbbTlv;
    42 class PbbAddressTlv;
    43 
    44 /** Used in Messages to determine whether it contains IPv4 or IPv6 addresses */
    45 enum PbbAddressLength {
    46   IPV4 = 3,
    47   IPV6 = 15,
    48 };
    49 
    50 /**
    51  * \brief A block of packet or message TLVs (PbbTlv).
    52  *
    53  * Acts similar to a C++ STL container.  Should not be used for Address TLVs.
    54  */
    55 class PbbTlvBlock
    56 {
    57 public:
    58   typedef std::list< Ptr<PbbTlv> >::iterator Iterator;
    59   typedef std::list< Ptr<PbbTlv> >::const_iterator ConstIterator;
    60 
    61   PbbTlvBlock (void);
    62   ~PbbTlvBlock (void);
    63 
    64   /**
    65    * \return an iterator to the first TLV in this block.
    66    */
    67   Iterator Begin (void);
    68 
    69   /**
    70    * \return a const iterator to the first TLV in this block.
    71    */
    72   ConstIterator Begin (void) const;
    73 
    74   /**
    75    * \return an iterator to the past-the-end element in this block.
    76    */
    77   Iterator End (void);
    78 
    79   /**
    80    * \return a const iterator to the past-the-end element in this block.
    81    */
    82   ConstIterator End (void) const;
    83 
    84   /**
    85    * \return the number of TLVs in this block.
    86    */
    87   int Size (void) const;
    88 
    89   /**
    90    * \return true if there are no TLVs in this block, false otherwise.
    91    */
    92   bool Empty (void) const;
    93 
    94   /**
    95    * \return a smart pointer to the first TLV in this block.
    96    */
    97   Ptr<PbbTlv> Front (void) const;
    98 
    99   /**
   100    * \return a smart pointer to the last TLV in this block.
   101    */
   102   Ptr<PbbTlv> Back (void) const;
   103 
   104   /**
   105    * \brief Prepends a TLV to the front of this block.
   106    * \param tlv a smart pointer to the TLV to prepend.
   107    */
   108   void PushFront (Ptr<PbbTlv> tlv);
   109 
   110   /**
   111    * \brief Removes a TLV from the front of this block.
   112    */
   113   void PopFront (void);
   114 
   115   /**
   116    * \brief Appends a TLV to the back of this block.
   117    * \param tlv a smart pointer to the TLV to append.
   118    */
   119   void PushBack (Ptr<PbbTlv> tlv);
   120 
   121   /**
   122    * \brief Removes a TLV from the back of this block.
   123    */
   124   void PopBack (void);
   125 
   126   /**
   127    * \brief Inserts a TLV at the specified position in this block.
   128    * \param position an Iterator pointing to the position in this block to
   129    *        insert the TLV.
   130    * \param tlv a smart pointer to the TLV to insert.
   131    * \return An iterator pointing to the newly inserted TLV.
   132    */
   133   Iterator Insert (Iterator position, const Ptr<PbbTlv> tlv);
   134 
   135   /**
   136    * \brief Removes the TLV at the specified position.
   137    * \param position an Iterator pointing to the TLV to erase.
   138    * \return an iterator pointing to the next TLV in the block.
   139    */
   140   Iterator Erase (Iterator position);
   141 
   142   /**
   143    * \brief Removes all TLVs from [first, last) (includes first, not includes
   144    *        last).
   145    * \param first an Iterator pointing to the first TLV to erase (inclusive).
   146    * \param last an Iterator pointing to the element past the last TLV to erase.
   147    * \return an iterator pointing to the next TLV in the block.
   148    */
   149   Iterator Erase (Iterator first, Iterator last);
   150 
   151   /**
   152    * \brief Removes all TLVs from this block.
   153    */
   154   void Clear (void);
   155 
   156   /**
   157    * \return The size (in bytes) needed to serialize this block.
   158    */
   159   uint32_t GetSerializedSize (void) const;
   160 
   161   /**
   162    * \brief Serializes this block into the specified buffer.
   163    * \param start a reference to the point in a buffer to begin serializing.
   164    *
   165    * Users should not need to call this.  Blocks will be serialized by their
   166    * containing packet.
   167    */
   168   void Serialize (Buffer::Iterator &start) const;
   169 
   170   /**
   171    * \brief Deserializes a block from the specified buffer.
   172    * \param start a reference to the point in a buffer to begin deserializing.
   173    *
   174    * Users should not need to call this.  Blocks will be deserialized by their
   175    * containing packet.
   176    */
   177   void Deserialize (Buffer::Iterator &start);
   178 
   179   /**
   180    * \brief Pretty-prints the contents of this block.
   181    * \param os a stream object to print to.
   182    */
   183   void Print (std::ostream &os) const;
   184 
   185   /**
   186    * \brief Pretty-prints the contents of this block, with specified indentation.
   187    * \param os a stream object to print to.
   188    * \param level level of indentation.
   189    *
   190    * This probably never needs to be called by users.  This is used when
   191    * recursively printing sub-objects.
   192    */
   193   void Print (std::ostream &os, int level) const;
   194 
   195   bool operator== (const PbbTlvBlock &other) const;
   196   bool operator!= (const PbbTlvBlock &other) const;
   197 
   198 private:
   199   std::list< Ptr<PbbTlv> > m_tlvList;
   200 };
   201 
   202 /**
   203  * \brief A block of Address TLVs (PbbAddressTlv).
   204  *
   205  * Acts similar to a C++ STL container.
   206  */
   207 class PbbAddressTlvBlock
   208 {
   209 public:
   210   typedef std::list< Ptr<PbbAddressTlv> >::iterator Iterator;
   211   typedef std::list< Ptr<PbbAddressTlv> >::const_iterator ConstIterator;
   212 
   213   PbbAddressTlvBlock (void);
   214   ~PbbAddressTlvBlock (void);
   215 
   216   /**
   217    * \return an iterator to the first Address TLV in this block.
   218    */
   219   Iterator Begin (void);
   220 
   221   /**
   222    * \return a const iterator to the first Address TLV in this block.
   223    */
   224   ConstIterator Begin (void) const;
   225 
   226   /**
   227    * \return an iterator to the past-the-end element in this block.
   228    */
   229   Iterator End (void);
   230 
   231   /**
   232    * \return a const iterator to the past-the-end element in this block.
   233    */
   234   ConstIterator End (void) const;
   235 
   236   /**
   237    * \return the number of Address TLVs in this block.
   238    */
   239   int Size (void) const;
   240 
   241   /**
   242    * \return true if there are no Address TLVs in this block, false otherwise.
   243    */
   244   bool Empty (void) const;
   245 
   246   /**
   247    * \return the first Address TLV in this block.
   248    */
   249   Ptr<PbbAddressTlv> Front (void) const;
   250 
   251   /**
   252    * \return the last AddressTLV in this block.
   253    */
   254   Ptr<PbbAddressTlv> Back (void) const;
   255 
   256   /**
   257    * \brief Prepends an Address TLV to the front of this block.
   258    * \param tlv a smart pointer to the Address TLV to prepend.
   259    */
   260   void PushFront (Ptr<PbbAddressTlv> tlv);
   261 
   262   /**
   263    * \brief Removes an AddressTLV from the front of this block.
   264    */
   265   void PopFront (void);
   266 
   267   /**
   268    * \brief Appends an Address TLV to the back of this block.
   269    * \param tlv a smart pointer to the Address TLV to append.
   270    */
   271   void PushBack (Ptr<PbbAddressTlv> tlv);
   272 
   273   /**
   274    * \brief Removes an Address TLV from the back of this block.
   275    */
   276   void PopBack (void);
   277 
   278   /**
   279    * \brief Inserts an Address TLV at the specified position in this block.
   280    * \param position an Iterator pointing to the position in this block to
   281    *        insert the Address TLV.
   282    * \param tlv a smart pointer to the Address TLV to insert.
   283    * \return An iterator pointing to the newly inserted Address TLV.
   284    */
   285   Iterator Insert (Iterator position, const Ptr<PbbAddressTlv> tlv);
   286 
   287   /**
   288    * \brief Removes the Address TLV at the specified position.
   289    * \param position an Iterator pointing to the Address TLV to erase.
   290    * \return an iterator pointing to the next Address TLV in the block.
   291    */
   292   Iterator Erase (Iterator position);
   293 
   294   /**
   295    * \brief Removes all Address TLVs from [first, last) (includes first, not
   296    *        includes last).
   297    * \param first an Iterator pointing to the first Address TLV to erase
   298    *        (inclusive).
   299    * \param last an Iterator pointing to the element past the last Address TLV
   300    *        to erase.
   301    * \return an iterator pointing to the next Address TLV in the block.
   302    */
   303   Iterator Erase (Iterator first, Iterator last);
   304 
   305   /**
   306    * \brief Removes all Address TLVs from this block.
   307    */
   308   void Clear (void);
   309 
   310   /**
   311    * \return The size (in bytes) needed to serialize this block.
   312    */
   313   uint32_t GetSerializedSize (void) const;
   314 
   315   /**
   316    * \brief Serializes this block into the specified buffer.
   317    * \param start a reference to the point in a buffer to begin serializing.
   318    *
   319    * Users should not need to call this.  Blocks will be serialized by their
   320    * containing packet.
   321    */
   322   void Serialize (Buffer::Iterator &start) const;
   323 
   324   /**
   325    * \brief Deserializes a block from the specified buffer.
   326    * \param start a reference to the point in a buffer to begin deserializing.
   327    *
   328    * Users should not need to call this.  Blocks will be deserialized by their
   329    * containing packet.
   330    */
   331   void Deserialize (Buffer::Iterator &start);
   332 
   333   /**
   334    * \brief Pretty-prints the contents of this block.
   335    * \param os a stream object to print to.
   336    */
   337   void Print (std::ostream &os) const;
   338 
   339   /**
   340    * \brief Pretty-prints the contents of this block, with specified indentation.
   341    * \param os a stream object to print to.
   342    * \param level level of indentation.
   343    *
   344    * This probably never needs to be called by users.  This is used when
   345    * recursively printing sub-objects.
   346    */
   347   void Print (std::ostream &os, int level) const;
   348 
   349   bool operator== (const PbbAddressTlvBlock &other) const;
   350   bool operator!= (const PbbAddressTlvBlock &other) const;
   351 
   352 private:
   353   std::list< Ptr<PbbAddressTlv> > m_tlvList;
   354 };
   355 
   356 /**
   357  * \brief Main PacketBB Packet object.
   358  *
   359  * A PacketBB packet is made up of zero or more packet TLVs (PbbTlv), and zero
   360  * or more messages (PbbMessage).
   361  *
   362  * See: http://tools.ietf.org/html/rfc5444 for details.
   363  */
   364 class PbbPacket : public SimpleRefCount<PbbPacket,Header>
   365 {
   366 public:
   367   typedef std::list< Ptr<PbbTlv> >::iterator TlvIterator;
   368   typedef std::list< Ptr<PbbTlv> >::const_iterator ConstTlvIterator;
   369   typedef std::list< Ptr<PbbMessage> >::iterator MessageIterator;
   370   typedef std::list< Ptr<PbbMessage> >::const_iterator ConstMessageIterator;
   371 
   372   PbbPacket (void);
   373   ~PbbPacket (void);
   374 
   375   /**
   376    * \return the version of PacketBB that constructed this packet.
   377    *
   378    * This will always return 0 for packets constructed using this API.
   379    */
   380   uint8_t GetVersion (void) const;
   381 
   382   /**
   383    * \brief Sets the sequence number of this packet.
   384    * \param number the sequence number.
   385    */
   386   void SetSequenceNumber (uint16_t number);
   387 
   388   /**
   389    * \return the sequence number of this packet.
   390    *
   391    * Calling this while HasSequenceNumber is False is undefined.  Make sure you
   392    * check it first.  This will be checked by an assert in debug builds.
   393    */
   394   uint16_t GetSequenceNumber (void) const;
   395 
   396   /**
   397    * \brief Tests whether or not this packet has a sequence number.
   398    * \return true if this packet has a sequence number, false otherwise.
   399    *
   400    * This should be called before calling GetSequenceNumber to make sure there
   401    * actually is one.
   402    */
   403   bool HasSequenceNumber (void) const;
   404 
   405   /* Manipulating Packet TLVs */
   406 
   407   /**
   408    * \return an iterator to the first Packet TLV in this packet.
   409    */
   410   TlvIterator TlvBegin (void);
   411 
   412   /**
   413    * \return a const iterator to the first Packet TLV in this packet.
   414    */
   415   ConstTlvIterator TlvBegin (void) const;
   416 
   417   /**
   418    * \return an iterator to the past-the-end element in this packet TLV block.
   419    */
   420   TlvIterator TlvEnd (void);
   421 
   422   /**
   423    * \return a const iterator to the past-the-end element in this packet TLV
   424    *         block.
   425    */
   426   ConstTlvIterator TlvEnd (void) const;
   427 
   428   /**
   429    * \return the number of packet TLVs in this packet.
   430    */
   431   int TlvSize (void) const;
   432 
   433   /**
   434    * \return true if there are no packet TLVs in this packet, false otherwise.
   435    */
   436   bool TlvEmpty (void) const;
   437 
   438   /**
   439    * \return a smart pointer to the first packet TLV in this packet.
   440    */
   441   Ptr<PbbTlv> TlvFront (void);
   442 
   443   /**
   444    * \return a const smart pointer to the first packet TLV in this packet.
   445    */
   446   const Ptr<PbbTlv> TlvFront (void) const;
   447 
   448   /**
   449    * \return a smart pointer to the last packet TLV in this packet.
   450    */
   451   Ptr<PbbTlv> TlvBack (void);
   452 
   453   /**
   454    * \return a const smart pointer to the last packet TLV in this packet.
   455    */
   456   const Ptr<PbbTlv> TlvBack (void) const;
   457 
   458   /**
   459    * \brief Prepends a packet TLV to the front of this packet.
   460    * \param tlv a smart pointer to the packet TLV to prepend.
   461    */
   462   void TlvPushFront (Ptr<PbbTlv> tlv);
   463 
   464   /**
   465    * \brief Removes a packet TLV from the front of this packet.
   466    */
   467   void TlvPopFront (void);
   468 
   469   /**
   470    * \brief Appends a packet TLV to the back of this packet.
   471    * \param tlv a smart pointer to the packet TLV to append.
   472    */
   473   void TlvPushBack (Ptr<PbbTlv> tlv);
   474 
   475   /**
   476    * \brief Removes a packet TLV from the back of this block.
   477    */
   478   void TlvPopBack (void);
   479 
   480   /**
   481    * \brief Removes the packet TLV at the specified position.
   482    * \param position an Iterator pointing to the packet TLV to erase.
   483    * \return an iterator pointing to the next packet TLV in the block.
   484    */
   485   TlvIterator Erase (TlvIterator position);
   486 
   487   /**
   488    * \brief Removes all packet TLVs from [first, last) (includes first, not
   489    *        includes last).
   490    * \param first an Iterator pointing to the first packet TLV to erase
   491    *        (inclusive).
   492    * \param last an Iterator pointing to the element past the last packet TLV
   493    *        to erase.
   494    * \return an iterator pointing to the next packet TLV in the block.
   495    */
   496   TlvIterator Erase (TlvIterator first, TlvIterator last);
   497 
   498   /**
   499    * \brief Removes all packet TLVs from this packet.
   500    */
   501   void TlvClear (void);
   502 
   503   /* Manipulating Packet Messages */
   504 
   505   /**
   506    * \return an iterator to the first message in this packet.
   507    */
   508   MessageIterator MessageBegin (void);
   509 
   510   /**
   511    * \return a const iterator to the first message in this packet.
   512    */
   513   ConstMessageIterator MessageBegin (void) const;
   514 
   515   /**
   516    * \return an iterator to the past-the-end element in this message block.
   517    */
   518   MessageIterator MessageEnd (void);
   519 
   520   /**
   521    * \return a const iterator to the past-the-end element in this message
   522    *         block.
   523    */
   524   ConstMessageIterator MessageEnd (void) const;
   525 
   526   /**
   527    * \return the number of messages in this packet.
   528    */
   529   int MessageSize (void) const;
   530 
   531   /**
   532    * \return true if there are no messages in this packet, false otherwise.
   533    */
   534   bool MessageEmpty (void) const;
   535 
   536   /**
   537    * \return a smart pointer to the first message in this packet.
   538    */
   539   Ptr<PbbMessage> MessageFront (void);
   540 
   541   /**
   542    * \return a cosnt smart pointer to the first message in this packet.
   543    */
   544   const Ptr<PbbMessage> MessageFront (void) const;
   545 
   546   /**
   547    * \return a smart pointer to the last message in this packet.
   548    */
   549   Ptr<PbbMessage> MessageBack (void);
   550 
   551   /**
   552    * \return a cosnt smart pointer to the last message in this packet.
   553    */
   554   const Ptr<PbbMessage> MessageBack (void) const;
   555 
   556   /**
   557    * \brief Prepends a message to the front of this packet.
   558    * \param message a smart pointer to the message to prepend.
   559    */
   560   void MessagePushFront (Ptr<PbbMessage> message);
   561 
   562   /**
   563    * \brief Removes a message from the front of this packet.
   564    */
   565   void MessagePopFront (void);
   566 
   567   /**
   568    * \brief Appends a message to the back of this packet.
   569    * \param message a smart pointer to the message to append.
   570    */
   571   void MessagePushBack (Ptr<PbbMessage> message);
   572 
   573   /**
   574    * \brief Removes a message from the back of this packet.
   575    */
   576   void MessagePopBack (void);
   577 
   578   /**
   579    * \brief Removes the message at the specified position.
   580    * \param position an Iterator pointing to the message to erase.
   581    * \return an iterator pointing to the next message in the packet.
   582    */
   583   MessageIterator Erase (MessageIterator position);
   584 
   585   /**
   586    * \brief Removes all messages from [first, last) (includes first, not
   587    *        includes last).
   588    * \param first an Iterator pointing to the first message to erase (inclusive).
   589    * \param last an Iterator pointing to the element past the last message to erase.
   590    * \return an iterator pointing to the next message in the block.
   591    */
   592   MessageIterator Erase (MessageIterator first, MessageIterator last);
   593 
   594   /**
   595    * \brief Removes all messages from this packet.
   596    */
   597   void MessageClear (void);
   598 
   599   /* Methods implemented by all headers */
   600   static TypeId GetTypeId (void);
   601   virtual TypeId GetInstanceTypeId (void) const;
   602 
   603   /**
   604    * \return The size (in bytes) needed to serialize this packet.
   605    */
   606   virtual uint32_t GetSerializedSize (void) const;
   607 
   608   /**
   609    * \brief Serializes this packet into the specified buffer.
   610    * \param start a reference to the point in a buffer to begin serializing.
   611    */
   612   virtual void Serialize (Buffer::Iterator start) const;
   613 
   614   /**
   615    * \brief Deserializes a packet from the specified buffer.
   616    * \param start start offset
   617    * \return the number of bytes deserialized
   618    *
   619    * If this returns a number smaller than the total number of bytes in the
   620    * buffer, there was an error.
   621    */
   622   virtual uint32_t Deserialize (Buffer::Iterator start);
   623 
   624   /**
   625    * \brief Pretty-prints the contents of this block.
   626    * \param os a stream object to print to.
   627    */
   628   virtual void Print (std::ostream &os) const;
   629 
   630   bool operator== (const PbbPacket &other) const;
   631   bool operator!= (const PbbPacket &other) const;
   632 
   633 protected:
   634   void SerializePacketTlv (Buffer::Iterator &start) const;
   635 
   636 private:
   637   PbbTlvBlock m_tlvList;
   638   std::list< Ptr<PbbMessage> > m_messageList;
   639 
   640   uint8_t m_version;
   641 
   642   bool m_hasseqnum;
   643   uint16_t m_seqnum;
   644 };
   645 
   646 /**
   647  * \brief A message within a PbbPacket packet.
   648  *
   649  * There may be any number of messages in one packet packet.  This is a pure
   650  * virtual base class, when creating a message, you should instantiate either
   651  * PbbMessageIpv4 or PbbMessageIpv6.
   652  */
   653 class PbbMessage : public SimpleRefCount<PbbMessage>
   654 {
   655 public:
   656   typedef std::list< Ptr<PbbTlv> >::iterator TlvIterator;
   657   typedef std::list< Ptr<PbbTlv> >::const_iterator ConstTlvIterator;
   658   typedef std::list< Ptr<PbbAddressBlock> >::iterator AddressBlockIterator;
   659   typedef std::list< Ptr<PbbAddressBlock> >::const_iterator ConstAddressBlockIterator;
   660 
   661   PbbMessage ();
   662   virtual ~PbbMessage ();
   663 
   664   /**
   665    * \brief Sets the type for this message.
   666    * \param type the type to set.
   667    */
   668   void SetType (uint8_t type);
   669 
   670   /**
   671    * \return the type assigned to this packet
   672    */
   673   uint8_t GetType (void) const;
   674 
   675   /**
   676    * \brief Sets the address for the node that created this packet.
   677    * \param address the originator address.
   678    */
   679   void SetOriginatorAddress (Address address);
   680 
   681   /**
   682    * \return the address of the node that created this packet.
   683    *
   684    * Calling this while HasOriginatorAddress is False is undefined.  Make sure
   685    * you check it first.  This will be checked by an assert in debug builds.
   686    */
   687   Address GetOriginatorAddress (void) const;
   688 
   689   /**
   690    * \brief Tests whether or not this message has an originator address.
   691    * \return true if this message has an originator address, false otherwise.
   692    */
   693   bool HasOriginatorAddress (void) const;
   694 
   695   /**
   696    * \brief Sets the maximum number of hops this message should travel
   697    * \param hoplimit the limit to set
   698    */
   699   void SetHopLimit (uint8_t hoplimit);
   700 
   701   /**
   702    * \return the maximum number of hops this message should travel.
   703    *
   704    * Calling this while HasHopLimit is False is undefined.  Make sure you check
   705    * it first.  This will be checked by an assert in debug builds.
   706    */
   707   uint8_t GetHopLimit (void) const;
   708 
   709   /**
   710    * \brief Tests whether or not this message has a hop limit.
   711    * \return true if this message has a hop limit, false otherwise.
   712    *
   713    * If this is set, messages should not hop further than this limit.
   714    */
   715   bool HasHopLimit (void) const;
   716 
   717   /**
   718    * \brief Sets the current number of hops this message has traveled.
   719    * \param hopcount the current number of hops
   720    */
   721   void SetHopCount (uint8_t hopcount);
   722 
   723   /**
   724    * \return the current number of hops this message has traveled.
   725    *
   726    * Calling this while HasHopCount is False is undefined.  Make sure you check
   727    * it first.  This will be checked by an assert in debug builds.
   728    */
   729   uint8_t GetHopCount (void) const;
   730 
   731   /**
   732    * \brief Tests whether or not this message has a hop count.
   733    * \return true if this message has a hop limit, false otherwise.
   734    */
   735   bool HasHopCount (void) const;
   736 
   737   /**
   738    * \brief Sets the sequence number of this message.
   739    * \param seqnum the sequence number to set.
   740    */
   741   void SetSequenceNumber (uint16_t seqnum);
   742 
   743   /**
   744    * \return the sequence number of this message.
   745    *
   746    * Calling this while HasSequenceNumber is False is undefined.  Make sure you
   747    * check it first.  This will be checked by an assert in debug builds.
   748    */
   749   uint16_t GetSequenceNumber (void) const;
   750 
   751   /**
   752    * \brief Tests whether or not this message has a sequence number.
   753    * \return true if this message has a sequence number, false otherwise.
   754    */
   755   bool HasSequenceNumber (void) const;
   756 
   757   /* Manipulating PbbMessage TLVs */
   758 
   759   /**
   760    * \return an iterator to the first message TLV in this message.
   761    */
   762   TlvIterator TlvBegin ();
   763 
   764   /**
   765    * \return a const iterator to the first message TLV in this message.
   766    */
   767   ConstTlvIterator TlvBegin () const;
   768 
   769   /**
   770    * \return an iterator to the past-the-end message TLV element in this
   771    *         message.
   772    */
   773   TlvIterator TlvEnd ();
   774 
   775   /**
   776    * \return a const iterator to the past-the-end message TLV element in this
   777    *         message.
   778    */
   779   ConstTlvIterator TlvEnd () const;
   780 
   781   /**
   782    * \return the number of message TLVs in this message.
   783    */
   784   int TlvSize (void) const;
   785 
   786   /**
   787    * \return true if there are no message TLVs in this message, false otherwise.
   788    */
   789   bool TlvEmpty (void) const;
   790 
   791   /**
   792    * \return a smart pointer to the first message TLV in this message.
   793    */
   794   Ptr<PbbTlv> TlvFront (void);
   795 
   796   /**
   797    * \return a const smart pointer to the first message TLV in this message.
   798    */
   799   const Ptr<PbbTlv> TlvFront (void) const;
   800 
   801   /**
   802    * \return a smart pointer to the last message TLV in this message.
   803    */
   804   Ptr<PbbTlv> TlvBack (void);
   805 
   806   /**
   807    * \return a const smart pointer to the last message TLV in this message.
   808    */
   809   const Ptr<PbbTlv> TlvBack (void) const;
   810 
   811   /**
   812    * \brief Prepends a message TLV to the front of this message.
   813    * \param tlv a smart pointer to the message TLV to prepend.
   814    */
   815   void TlvPushFront (Ptr<PbbTlv> tlv);
   816 
   817   /**
   818    * \brief Removes a message TLV from the front of this message.
   819    */
   820   void TlvPopFront (void);
   821 
   822   /**
   823    * \brief Appends a message TLV to the back of this message.
   824    * \param tlv a smart pointer to the message TLV to append.
   825    */
   826   void TlvPushBack (Ptr<PbbTlv> tlv);
   827 
   828   /**
   829    * \brief Removes a message TLV from the back of this message.
   830    */
   831   void TlvPopBack (void);
   832 
   833   /**
   834    * \brief Removes the message TLV at the specified position.
   835    * \param position an Iterator pointing to the message TLV to erase.
   836    * \return an iterator pointing to the next TLV in the block.
   837    */
   838   TlvIterator TlvErase (TlvIterator position);
   839 
   840   /**
   841    * \brief Removes all message TLVs from [first, last) (includes first, not
   842    *        includes last).
   843    * \param first an Iterator pointing to the first message TLV to erase
   844    *        (inclusive).
   845    * \param last an Iterator pointing to the element past the last message TLV
   846    *        to erase.
   847    * \return an iterator pointing to the next message TLV in the message.
   848    */
   849   TlvIterator TlvErase (TlvIterator first, TlvIterator last);
   850 
   851   /**
   852    * \brief Removes all message TLVs from this block.
   853    */
   854   void TlvClear (void);
   855 
   856   /* Manipulating Address Block and Address TLV pairs */
   857 
   858   /**
   859    * \return an iterator to the first address block in this message.
   860    */
   861   AddressBlockIterator AddressBlockBegin ();
   862 
   863   /**
   864    * \return a const iterator to the first address block in this message.
   865    */
   866   ConstAddressBlockIterator AddressBlockBegin () const;
   867 
   868   /**
   869    * \return an iterator to the past-the-end address block element in this
   870    *         message.
   871    */
   872   AddressBlockIterator AddressBlockEnd ();
   873 
   874   /**
   875    * \return a const iterator to the past-the-end address block element in this
   876    *         message.
   877    */
   878   ConstAddressBlockIterator AddressBlockEnd () const;
   879 
   880   /**
   881    * \return the number of address blocks in this message.
   882    */
   883   int AddressBlockSize (void) const;
   884 
   885   /**
   886    * \return true if there are no address blocks in this message, false
   887    *         otherwise.
   888    */
   889   bool AddressBlockEmpty (void) const;
   890 
   891   /**
   892    * \return a smart pointer to the first address block in this message.
   893    */
   894   Ptr<PbbAddressBlock> AddressBlockFront (void);
   895 
   896   /**
   897    * \return a const smart pointer to the first address block in this message.
   898    */
   899   const Ptr<PbbAddressBlock> AddressBlockFront (void) const;
   900 
   901   /**
   902    * \return a smart pointer to the last address block in this message.
   903    */
   904   Ptr<PbbAddressBlock> AddressBlockBack (void);
   905 
   906   /**
   907    * \return a const smart pointer to the last address block in this message.
   908    */
   909   const Ptr<PbbAddressBlock> AddressBlockBack (void) const;
   910 
   911   /**
   912    * \brief Prepends an address block to the front of this message.
   913    * \param block a smart pointer to the address block to prepend.
   914    */
   915   void AddressBlockPushFront (Ptr<PbbAddressBlock> block);
   916 
   917   /**
   918    * \brief Removes an address block from the front of this message.
   919    */
   920   void AddressBlockPopFront (void);
   921 
   922   /**
   923    * \brief Appends an address block to the front of this message.
   924    * \param block a smart pointer to the address block to append.
   925    */
   926   void AddressBlockPushBack (Ptr<PbbAddressBlock> block);
   927 
   928   /**
   929    * \brief Removes an address block from the back of this message.
   930    */
   931   void AddressBlockPopBack (void);
   932 
   933   /**
   934    * \brief Removes the address block at the specified position.
   935    * \param position an Iterator pointing to the address block to erase.
   936    * \return an iterator pointing to the next address block in the message.
   937    */
   938   AddressBlockIterator AddressBlockErase (AddressBlockIterator position);
   939 
   940   /**
   941    * \brief Removes all address blocks from [first, last) (includes first, not
   942    *        includes last).
   943    * \param first an Iterator pointing to the first address block to erase
   944    *        (inclusive).
   945    * \param last an Iterator pointing to the element past the last address
   946    *        block to erase.
   947    * \return an iterator pointing to the next address block in the message.
   948    */
   949   AddressBlockIterator AddressBlockErase (AddressBlockIterator first,
   950       AddressBlockIterator last);
   951 
   952   /**
   953    * \brief Removes all address blocks from this message.
   954    */
   955   void AddressBlockClear (void);
   956 
   957   /**
   958    * \brief Deserializes a message, returning the correct object depending on
   959    *        whether it is an IPv4 message or an IPv6 message.
   960    * \param start a reference to the point in a buffer to begin deserializing.
   961    * \return A pointer to the deserialized message, or 0 on error.
   962    *
   963    * Users should not need to call this.  Blocks will be deserialized by their
   964    * containing packet.
   965    */
   966   static Ptr<PbbMessage> DeserializeMessage (Buffer::Iterator &start);
   967 
   968   /**
   969    * \return The size (in bytes) needed to serialize this message.
   970    */
   971   uint32_t GetSerializedSize (void) const;
   972 
   973   /**
   974    * \brief Serializes this message into the specified buffer.
   975    * \param start a reference to the point in a buffer to begin serializing.
   976    *
   977    * Users should not need to call this.  Blocks will be deserialized by their
   978    * containing packet.
   979    */
   980   void Serialize (Buffer::Iterator &start) const;
   981 
   982   /**
   983    * \brief Deserializes a message from the specified buffer.
   984    * \param start a reference to the point in a buffer to begin deserializing.
   985    *
   986    * Users should not need to call this.  Blocks will be deserialized by their
   987    * containing packet.
   988    */
   989   void Deserialize (Buffer::Iterator &start);
   990 
   991   /**
   992    * \brief Pretty-prints the contents of this message.
   993    * \param os a stream object to print to.
   994    */
   995   void Print (std::ostream &os) const;
   996 
   997   /**
   998    * \brief Pretty-prints the contents of this message, with specified
   999    *        indentation.
  1000    * \param os a stream object to print to.
  1001    * \param level level of indentation.
  1002    *
  1003    * This probably never needs to be called by users.  This is used when
  1004    * recursively printing sub-objects.
  1005    */
  1006   void Print (std::ostream &os, int level) const;
  1007 
  1008   bool operator== (const PbbMessage &other) const;
  1009   bool operator!= (const PbbMessage &other) const;
  1010 
  1011 protected:
  1012   /* PbbMessage size in bytes - 1.
  1013    *
  1014    * IPv4 = 4 - 1 = 3, IPv6 = 16 - 1 = 15
  1015    */
  1016   virtual PbbAddressLength GetAddressLength (void) const = 0;
  1017 
  1018   virtual void SerializeOriginatorAddress (Buffer::Iterator &start) const = 0;
  1019   virtual Address DeserializeOriginatorAddress (Buffer::Iterator &start) const = 0;
  1020   virtual void PrintOriginatorAddress (std::ostream &os) const = 0;
  1021 
  1022   virtual Ptr<PbbAddressBlock> AddressBlockDeserialize (Buffer::Iterator &start) const = 0;
  1023 
  1024 private:
  1025   PbbTlvBlock m_tlvList;
  1026   std::list< Ptr<PbbAddressBlock> > m_addressBlockList;
  1027 
  1028   uint8_t m_type;
  1029   PbbAddressLength m_addrSize;
  1030 
  1031   bool m_hasOriginatorAddress;
  1032   Address m_originatorAddress;
  1033 
  1034   bool m_hasHopLimit;
  1035   uint8_t m_hopLimit;
  1036 
  1037   bool m_hasHopCount;
  1038   uint8_t m_hopCount;
  1039 
  1040   bool m_hasSequenceNumber;
  1041   uint16_t m_sequenceNumber;
  1042 };
  1043 
  1044 /**
  1045  * \brief Concrete IPv4 specific PbbMessage.
  1046  *
  1047  * This message will only contain IPv4 addresses.
  1048  */
  1049 class PbbMessageIpv4 : public PbbMessage {
  1050 public:
  1051   PbbMessageIpv4 ();
  1052   virtual ~PbbMessageIpv4 ();
  1053 
  1054 protected:
  1055   virtual PbbAddressLength GetAddressLength (void) const;
  1056 
  1057   virtual void SerializeOriginatorAddress (Buffer::Iterator &start) const;
  1058   virtual Address DeserializeOriginatorAddress (Buffer::Iterator &start) const;
  1059   virtual void PrintOriginatorAddress (std::ostream &os) const;
  1060 
  1061   virtual Ptr<PbbAddressBlock> AddressBlockDeserialize (Buffer::Iterator &start) const;
  1062 };
  1063 
  1064 /**
  1065  * \brief Concrete IPv6 specific PbbMessage class.
  1066  *
  1067  * This message will only contain IPv6 addresses.
  1068  */
  1069 class PbbMessageIpv6 : public PbbMessage {
  1070 public:
  1071   PbbMessageIpv6 ();
  1072   virtual ~PbbMessageIpv6 ();
  1073 
  1074 protected:
  1075   virtual PbbAddressLength GetAddressLength (void) const;
  1076 
  1077   virtual void SerializeOriginatorAddress (Buffer::Iterator &start) const;
  1078   virtual Address DeserializeOriginatorAddress (Buffer::Iterator &start) const;
  1079   virtual void PrintOriginatorAddress (std::ostream &os) const;
  1080 
  1081   virtual Ptr<PbbAddressBlock> AddressBlockDeserialize (Buffer::Iterator &start) const;
  1082 };
  1083 
  1084 /**
  1085  * \brief An Address Block and its associated Address TLV Blocks.
  1086  *
  1087  * This is a pure virtual base class, when creating address blocks, you should
  1088  * instantiate either PbbAddressBlockIpv4 or PbbAddressBlockIpv6.
  1089  */
  1090 class PbbAddressBlock : public SimpleRefCount<PbbAddressBlock>
  1091 {
  1092 public:
  1093   typedef std::list< Address >::iterator AddressIterator;
  1094   typedef std::list< Address >::const_iterator ConstAddressIterator;
  1095 
  1096   typedef std::list<uint8_t>::iterator PrefixIterator;
  1097   typedef std::list<uint8_t>::const_iterator ConstPrefixIterator;
  1098 
  1099   typedef PbbAddressTlvBlock::Iterator TlvIterator;
  1100   typedef PbbAddressTlvBlock::ConstIterator ConstTlvIterator;
  1101 
  1102   PbbAddressBlock ();
  1103   virtual ~PbbAddressBlock ();
  1104 
  1105   /* Manipulating the address block */
  1106 
  1107   /**
  1108    * \return an iterator to the first address in this block.
  1109    */
  1110   AddressIterator AddressBegin (void);
  1111 
  1112   /**
  1113    * \return a const iterator to the first address in this block.
  1114    */
  1115   ConstAddressIterator AddressBegin (void) const;
  1116 
  1117   /**
  1118    * \return an iterator to the last address in this block.
  1119    */
  1120   AddressIterator AddressEnd (void);
  1121 
  1122   /**
  1123    * \return a const iterator to the last address in this block.
  1124    */
  1125   ConstAddressIterator AddressEnd (void) const;
  1126 
  1127   /**
  1128    * \return the number of addresses in this block.
  1129    */
  1130   int AddressSize (void) const;
  1131 
  1132   /**
  1133    * \return true if there are no addresses in this block, false otherwise.
  1134    */
  1135   bool AddressEmpty (void) const;
  1136 
  1137   /**
  1138    * \return the first address in this block.
  1139    */
  1140   Address AddressFront (void) const;
  1141 
  1142   /**
  1143    * \return the last address in this block.
  1144    */
  1145   Address AddressBack (void) const;
  1146 
  1147   /**
  1148    * \brief Prepends an address to the front of this block.
  1149    * \param address the address to prepend.
  1150    */
  1151   void AddressPushFront (Address address);
  1152 
  1153   /**
  1154    * \brief Removes an address from the front of this block.
  1155    */
  1156   void AddressPopFront (void);
  1157 
  1158   /**
  1159    * \brief Appends an address to the back of this block.
  1160    * \param address the address to append.
  1161    */
  1162   void AddressPushBack (Address address);
  1163 
  1164   /**
  1165    * \brief Removes an address from the back of this block.
  1166    */
  1167   void AddressPopBack (void);
  1168 
  1169   /**
  1170    * \brief Inserts an address at the specified position in this block.
  1171    * \param position an Iterator pointing to the position in this block to
  1172    *        insert the address.
  1173    * \param value the address to insert.
  1174    * \return An iterator pointing to the newly inserted address.
  1175    */
  1176   AddressIterator AddressInsert (AddressIterator position,
  1177       const Address value);
  1178 
  1179   /**
  1180    * \brief Removes the address at the specified position.
  1181    * \param position an Iterator pointing to the address to erase.
  1182    * \return an iterator pointing to the next address in the block.
  1183    */
  1184   AddressIterator AddressErase (AddressIterator position);
  1185 
  1186   /**
  1187    * \brief Removes all addresses from [first, last) (includes first, not
  1188    *        includes last).
  1189    * \param first an Iterator pointing to the first address to erase
  1190    *        (inclusive).
  1191    * \param last an Iterator pointing to the element past the last address to
  1192    *        erase.
  1193    * \return an iterator pointing to the next address in the block.
  1194    */
  1195   AddressIterator AddressErase (AddressIterator first, AddressIterator last);
  1196 
  1197   /**
  1198    * \brief Removes all addresses from this block.
  1199    */
  1200   void AddressClear (void);
  1201 
  1202   /* Prefix methods */
  1203 
  1204   /**
  1205    * \return an iterator to the first prefix in this block.
  1206    */
  1207   PrefixIterator PrefixBegin (void);
  1208 
  1209   /**
  1210    * \return a const iterator to the first prefix in this block.
  1211    */
  1212   ConstPrefixIterator PrefixBegin (void) const;
  1213 
  1214   /**
  1215    * \return an iterator to the last prefix in this block.
  1216    */
  1217   PrefixIterator PrefixEnd (void);
  1218 
  1219   /**
  1220    * \return a const iterator to the last prefix in this block.
  1221    */
  1222   ConstPrefixIterator PrefixEnd (void) const;
  1223 
  1224   /**
  1225    * \return the number of prefixes in this block.
  1226    */
  1227   int PrefixSize (void) const;
  1228 
  1229   /**
  1230    * \return true if there are no prefixes in this block, false otherwise.
  1231    */
  1232   bool PrefixEmpty (void) const;
  1233 
  1234   /**
  1235    * \return the first prefix in this block.
  1236    */
  1237   uint8_t PrefixFront (void) const;
  1238 
  1239   /**
  1240    * \return the last prefix in this block.
  1241    */
  1242   uint8_t PrefixBack (void) const;
  1243 
  1244   /**
  1245    * \brief Prepends a prefix to the front of this block.
  1246    * \param prefix the prefix to prepend.
  1247    */
  1248   void PrefixPushFront (uint8_t prefix);
  1249 
  1250   /**
  1251    * \brief Removes a prefix from the front of this block.
  1252    */
  1253   void PrefixPopFront (void);
  1254 
  1255   /**
  1256    * \brief Appends a prefix to the back of this block.
  1257    * \param prefix the prefix to append.
  1258    */
  1259   void PrefixPushBack (uint8_t prefix);
  1260 
  1261   /**
  1262    * \brief Removes a prefix from the back of this block.
  1263    */
  1264   void PrefixPopBack (void);
  1265 
  1266   /**
  1267    * \brief Inserts a prefix at the specified position in this block.
  1268    * \param position an Iterator pointing to the position in this block to
  1269    *        insert the prefix.
  1270    * \param value the prefix to insert.
  1271    * \return An iterator pointing to the newly inserted prefix.
  1272    */
  1273   PrefixIterator PrefixInsert (PrefixIterator position, const uint8_t value);
  1274 
  1275   /**
  1276    * \brief Removes the prefix at the specified position.
  1277    * \param position an Iterator pointing to the prefix to erase.
  1278    * \return an iterator pointing to the next prefix in the block.
  1279    */
  1280   PrefixIterator PrefixErase (PrefixIterator position);
  1281 
  1282   /**
  1283    * \brief Removes all prefixes from [first, last) (includes first, not
  1284    *        includes last).
  1285    * \param first an Iterator pointing to the first prefix to erase
  1286    *        (inclusive).
  1287    * \param last an Iterator pointing to the element past the last prefix to
  1288    *        erase.
  1289    * \return an iterator pointing to the next prefix in the block.
  1290    */
  1291   PrefixIterator PrefixErase (PrefixIterator first, PrefixIterator last);
  1292 
  1293   /**
  1294    * \brief Removes all prefixes from this block.
  1295    */
  1296   void PrefixClear (void);
  1297 
  1298   /* Manipulating the TLV block */
  1299 
  1300   /**
  1301    * \return an iterator to the first address TLV in this block.
  1302    */
  1303   TlvIterator TlvBegin (void);
  1304 
  1305   /**
  1306    * \return a const iterator to the first address TLV in this block.
  1307    */
  1308   ConstTlvIterator TlvBegin (void) const;
  1309 
  1310   /**
  1311    * \return an iterator to the last address TLV in this block.
  1312    */
  1313   TlvIterator TlvEnd (void);
  1314 
  1315   /**
  1316    * \return a const iterator to the last address TLV in this block.
  1317    */
  1318   ConstTlvIterator TlvEnd (void) const;
  1319 
  1320   /**
  1321    * \return the number of address TLVs in this block.
  1322    */
  1323   int TlvSize (void) const;
  1324 
  1325   /**
  1326    * \return true if there are no address TLVs in this block, false otherwise.
  1327    */
  1328   bool TlvEmpty (void) const;
  1329 
  1330   /**
  1331    * \return a smart pointer to the first address TLV in this block.
  1332    */
  1333   Ptr<PbbAddressTlv> TlvFront (void);
  1334 
  1335   /**
  1336    * \return a const smart pointer to the first address TLV in this message.
  1337    */
  1338   const Ptr<PbbAddressTlv> TlvFront (void) const;
  1339 
  1340   /**
  1341    * \return a smart pointer to the last address TLV in this message.
  1342    */
  1343   Ptr<PbbAddressTlv> TlvBack (void);
  1344 
  1345   /**
  1346    * \return a const smart pointer to the last address TLV in this message.
  1347    */
  1348   const Ptr<PbbAddressTlv> TlvBack (void) const;
  1349 
  1350   /**
  1351    * \brief Prepends an address TLV to the front of this message.
  1352    * \param address a smart pointer to the address TLV to prepend.
  1353    */
  1354   void TlvPushFront (Ptr<PbbAddressTlv> address);
  1355 
  1356   /**
  1357    * \brief Removes an address TLV from the front of this message.
  1358    */
  1359   void TlvPopFront (void);
  1360 
  1361   /**
  1362    * \brief Appends an address TLV to the back of this message.
  1363    * \param address a smart pointer to the address TLV to append.
  1364    */
  1365   void TlvPushBack (Ptr<PbbAddressTlv> address);
  1366 
  1367   /**
  1368    * \brief Removes an address TLV from the back of this message.
  1369    */
  1370   void TlvPopBack (void);
  1371 
  1372   /**
  1373    * \brief Inserts an address TLV at the specified position in this block.
  1374    * \param position an Iterator pointing to the position in this block to
  1375    *        insert the address TLV.
  1376    * \param value the prefix to insert.
  1377    * \return An iterator pointing to the newly inserted address TLV.
  1378    */
  1379   TlvIterator TlvInsert (TlvIterator position, const Ptr<PbbTlv> value);
  1380 
  1381   /**
  1382    * \brief Removes the address TLV at the specified position.
  1383    * \param position an Iterator pointing to the address TLV to erase.
  1384    * \return an iterator pointing to the next address TLV in the block.
  1385    */
  1386   TlvIterator TlvErase (TlvIterator position);
  1387 
  1388   /**
  1389    * \brief Removes all address TLVs from [first, last) (includes first, not
  1390    *        includes last).
  1391    * \param first an Iterator pointing to the first address TLV to erase
  1392    *        (inclusive).
  1393    * \param last an Iterator pointing to the element past the last address TLV
  1394    *        to erase.
  1395    * \return an iterator pointing to the next address TLV in the message.
  1396    */
  1397   TlvIterator TlvErase (TlvIterator first, TlvIterator last);
  1398 
  1399   /**
  1400    * \brief Removes all address TLVs from this block.
  1401    */
  1402   void TlvClear (void);
  1403 
  1404   /**
  1405    * \return The size (in bytes) needed to serialize this address block.
  1406    */
  1407   uint32_t GetSerializedSize (void) const;
  1408 
  1409   /**
  1410    * \brief Serializes this address block into the specified buffer.
  1411    * \param start a reference to the point in a buffer to begin serializing.
  1412    *
  1413    * Users should not need to call this.  Blocks will be deserialized by their
  1414    * containing packet.
  1415    */
  1416   void Serialize (Buffer::Iterator &start) const;
  1417 
  1418   /**
  1419    * \brief Deserializes an address block from the specified buffer.
  1420    * \param start a reference to the point in a buffer to begin deserializing.
  1421    *
  1422    * Users should not need to call this.  Blocks will be deserialized by their
  1423    * containing packet.
  1424    */
  1425   void Deserialize (Buffer::Iterator &start);
  1426 
  1427   /**
  1428    * \brief Pretty-prints the contents of this address block.
  1429    * \param os a stream object to print to.
  1430    */
  1431   void Print (std::ostream &os) const;
  1432 
  1433   /**
  1434    * \brief Pretty-prints the contents of this address block, with specified
  1435    *        indentation.
  1436    * \param os a stream object to print to.
  1437    * \param level level of indentation.
  1438    *
  1439    * This probably never needs to be called by users.  This is used when
  1440    * recursively printing sub-objects.
  1441    */
  1442   void Print (std::ostream &os, int level) const;
  1443 
  1444   bool operator== (const PbbAddressBlock &other) const;
  1445   bool operator!= (const PbbAddressBlock &other) const;
  1446 
  1447 protected:
  1448   virtual uint8_t GetAddressLength (void) const = 0;
  1449 
  1450   virtual void SerializeAddress (uint8_t *buffer, ConstAddressIterator iter) const = 0;
  1451   virtual Address DeserializeAddress (uint8_t *buffer) const = 0;
  1452   virtual void PrintAddress (std::ostream &os, ConstAddressIterator iter) const = 0;
  1453 
  1454 private:
  1455   uint8_t GetPrefixFlags (void) const;
  1456   void GetHeadTail (uint8_t *head, uint8_t &headlen,
  1457       uint8_t *tail, uint8_t &taillen) const;
  1458   bool HasZeroTail (const uint8_t *tail, uint8_t taillen) const;
  1459 
  1460   std::list<Address> m_addressList;
  1461   std::list<uint8_t> m_prefixList;
  1462   PbbAddressTlvBlock m_addressTlvList;
  1463 };
  1464 
  1465 /**
  1466  * \brief Concrete IPv4 specific PbbAddressBlock.
  1467  *
  1468  * This address block will only contain IPv4 addresses.
  1469  */
  1470 class PbbAddressBlockIpv4 : public PbbAddressBlock
  1471 {
  1472 public:
  1473   PbbAddressBlockIpv4 ();
  1474   virtual ~PbbAddressBlockIpv4 ();
  1475 
  1476 protected:
  1477   virtual uint8_t GetAddressLength (void) const;
  1478 
  1479   virtual void SerializeAddress (uint8_t *buffer, ConstAddressIterator iter) const;
  1480   virtual Address DeserializeAddress (uint8_t *buffer) const;
  1481   virtual void PrintAddress (std::ostream &os, ConstAddressIterator iter) const;
  1482 };
  1483 
  1484 /**
  1485  * \brief Concrete IPv6 specific PbbAddressBlock.
  1486  *
  1487  * This address block will only contain IPv6 addresses.
  1488  */
  1489 class PbbAddressBlockIpv6 : public PbbAddressBlock
  1490 {
  1491 public:
  1492   PbbAddressBlockIpv6 ();
  1493   virtual ~PbbAddressBlockIpv6 ();
  1494 
  1495 protected:
  1496   virtual uint8_t GetAddressLength (void) const;
  1497 
  1498   virtual void SerializeAddress (uint8_t *buffer, ConstAddressIterator iter) const;
  1499   virtual Address DeserializeAddress (uint8_t *buffer) const;
  1500   virtual void PrintAddress (std::ostream &os, ConstAddressIterator iter) const;
  1501 };
  1502 
  1503 /**
  1504  * \brief A packet or message TLV
  1505  */
  1506 class PbbTlv : public SimpleRefCount<PbbTlv>
  1507 {
  1508 public:
  1509   PbbTlv (void);
  1510   virtual ~PbbTlv (void);
  1511 
  1512   /**
  1513    * \brief Sets the type of this TLV.
  1514    * \param type the type value to set.
  1515    */
  1516   void SetType (uint8_t type);
  1517 
  1518   /**
  1519    * \return the type of this TLV.
  1520    */
  1521   uint8_t GetType (void) const;
  1522 
  1523   /**
  1524    * \brief Sets the type extension of this TLV.
  1525    * \param type the type extension value to set.
  1526    *
  1527    * The type extension is like a sub-type used to further distinguish between
  1528    * TLVs of the same type.
  1529    */
  1530   void SetTypeExt (uint8_t type);
  1531 
  1532   /**
  1533    * \return the type extension for this TLV.
  1534    *
  1535    * Calling this while HasTypeExt is False is undefined.  Make sure you check
  1536    * it first.  This will be checked by an assert in debug builds.
  1537    */
  1538   uint8_t GetTypeExt (void) const;
  1539 
  1540   /**
  1541    * \brief Tests whether or not this TLV has a type extension.
  1542    * \return true if this TLV has a type extension, false otherwise.
  1543    *
  1544    * This should be called before calling GetTypeExt to make sure there
  1545    * actually is one.
  1546    */
  1547   bool HasTypeExt (void) const;
  1548 
  1549   /**
  1550    * \brief Sets the value of this message to the specified buffer.
  1551    * \param start a buffer instance.
  1552    *
  1553    * The buffer is _not_ copied until this TLV is serialized.  You should not
  1554    * change the contents of the buffer you pass in to this function.
  1555    */
  1556   void SetValue (Buffer start);
  1557 
  1558   /**
  1559    * \brief Sets the value of this message to a buffer with the specified data.
  1560    * \param buffer a pointer to data to put in the TLVs buffer.
  1561    * \param size the size of the buffer.
  1562    *
  1563    * The buffer *is copied* into a *new buffer instance*.  You can free the
  1564    * data in the buffer provided anytime you wish.
  1565    */
  1566   void SetValue (const uint8_t * buffer, uint32_t size);
  1567 
  1568   /**
  1569    * \return a Buffer pointing to the value of this TLV.
  1570    *
  1571    * Calling this while HasValue is False is undefined.  Make sure you check it
  1572    * first.  This will be checked by an assert in debug builds.
  1573    */
  1574   Buffer GetValue (void) const;
  1575 
  1576   /**
  1577    * \brief Tests whether or not this TLV has a value.
  1578    * \return true if this tlv has a TLV, false otherwise.
  1579    *
  1580    * This should be called before calling GetTypeExt to make sure there
  1581    * actually is one.
  1582    */
  1583   bool HasValue (void) const;
  1584 
  1585   /**
  1586    * \return The size (in bytes) needed to serialize this TLV.
  1587    */
  1588   uint32_t GetSerializedSize (void) const;
  1589 
  1590   /**
  1591    * \brief Serializes this TLV into the specified buffer.
  1592    * \param start a reference to the point in a buffer to begin serializing.
  1593    *
  1594    * Users should not need to call this.  TLVs will be serialized by their
  1595    * containing blocks.
  1596    */
  1597   void Serialize (Buffer::Iterator &start) const;
  1598 
  1599   /**
  1600    * \brief Deserializes a TLV from the specified buffer.
  1601    * \param start a reference to the point in a buffer to begin deserializing.
  1602    *
  1603    * Users should not need to call this.  TLVs will be deserialized by their
  1604    * containing blocks.
  1605    */
  1606   void Deserialize (Buffer::Iterator &start);
  1607 
  1608   /**
  1609    * \brief Pretty-prints the contents of this TLV.
  1610    * \param os a stream object to print to.
  1611    */
  1612   void Print (std::ostream &os) const;
  1613 
  1614   /**
  1615    * \brief Pretty-prints the contents of this TLV, with specified indentation.
  1616    * \param os a stream object to print to.
  1617    * \param level level of indentation.
  1618    *
  1619    * This probably never needs to be called by users.  This is used when
  1620    * recursively printing sub-objects.
  1621    */
  1622   void Print (std::ostream &os, int level) const;
  1623 
  1624   bool operator== (const PbbTlv &other) const;
  1625   bool operator!= (const PbbTlv &other) const;
  1626 
  1627 protected:
  1628   void SetIndexStart (uint8_t index);
  1629   uint8_t GetIndexStart (void) const;
  1630   bool HasIndexStart (void) const;
  1631 
  1632   void SetIndexStop (uint8_t index);
  1633   uint8_t GetIndexStop (void) const;
  1634   bool HasIndexStop (void) const;
  1635 
  1636   void SetMultivalue (bool isMultivalue);
  1637   bool IsMultivalue (void) const;
  1638 
  1639 private:
  1640   uint8_t m_type;
  1641 
  1642   bool m_hasTypeExt;
  1643   uint8_t m_typeExt;
  1644 
  1645   bool m_hasIndexStart;
  1646   uint8_t m_indexStart;
  1647 
  1648   bool m_hasIndexStop;
  1649   uint8_t m_indexStop;
  1650 
  1651   bool m_isMultivalue;
  1652   bool m_hasValue;
  1653   Buffer m_value;
  1654 };
  1655 
  1656 /**
  1657  * \brief An Address TLV
  1658  */
  1659 class PbbAddressTlv : public PbbTlv
  1660 {
  1661 public:
  1662   /**
  1663    * \brief Sets the index of the first address in the associated address block
  1664    * that this address TLV applies to.
  1665    * \param index the index of the first address.
  1666    */
  1667   void SetIndexStart (uint8_t index);
  1668 
  1669   /**
  1670    * \return the first (inclusive) index of the address in the corresponding
  1671    * address block that this TLV applies to.
  1672    *
  1673    * Calling this while HasIndexStart is False is undefined.  Make sure you
  1674    * check it first.  This will be checked by an assert in debug builds.
  1675    */
  1676   uint8_t GetIndexStart (void) const;
  1677 
  1678   /**
  1679    * \brief Tests whether or not this address TLV has a start index.
  1680    * \return true if this address TLV has a start index, false otherwise.
  1681    *
  1682    * This should be called before calling GetIndexStart to make sure there
  1683    * actually is one.
  1684    */
  1685   bool HasIndexStart (void) const;
  1686 
  1687   /**
  1688    * \brief Sets the index of the last address in the associated address block
  1689    * that this address TLV applies to.
  1690    * \param index the index of the last address.
  1691    */
  1692   void SetIndexStop (uint8_t index);
  1693 
  1694   /**
  1695    * \return the last (inclusive) index of the address in the corresponding
  1696    * PbbAddressBlock that this TLV applies to.
  1697    *
  1698    * Calling this while HasIndexStop is False is undefined.  Make sure you
  1699    * check it first.  This will be checked by an assert in debug builds.
  1700    */
  1701   uint8_t GetIndexStop (void) const;
  1702 
  1703   /**
  1704    * \brief Tests whether or not this address TLV has a stop index.
  1705    * \return true if this address TLV has a stop index, false otherwise.
  1706    *
  1707    * This should be called before calling GetIndexStop to make sure there
  1708    * actually is one.
  1709    */
  1710   bool HasIndexStop (void) const;
  1711 
  1712   /**
  1713    * \brief Sets whether or not this address TLV is "multivalue"
  1714    * \param isMultivalue whether or not this address TLV should be multivalue.
  1715    *
  1716    * If true, this means the value associated with this TLV should be divided
  1717    * evenly into (GetIndexStop() - GetIndexStart() + 1) values.  Otherwise, the
  1718    * value is one single value that applies to each address in the range.
  1719    */
  1720   void SetMultivalue (bool isMultivalue);
  1721 
  1722   /**
  1723    * \brief Tests whether or not this address TLV is "multivalue"
  1724    * \return whether this address TLV is multivalue or not.
  1725    */
  1726   bool IsMultivalue (void) const;
  1727 };
  1728 
  1729 } /* namespace ns3 */
  1730 
  1731 #endif /* PACKETBB_H */