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: */
4 * Copyright (c) 2009 Drexel University
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;
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.
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
19 * Author: Tom Wambold <tom5760@gmail.com>
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 */
31 #include "ns3/address.h"
32 #include "ns3/header.h"
33 #include "ns3/buffer.h"
34 #include "ns3/simple-ref-count.h"
38 /* Forward declare objects */
40 class PbbAddressBlock;
44 /** Used in Messages to determine whether it contains IPv4 or IPv6 addresses */
45 enum PbbAddressLength {
51 * \brief A block of packet or message TLVs (PbbTlv).
53 * Acts similar to a C++ STL container. Should not be used for Address TLVs.
58 typedef std::list< Ptr<PbbTlv> >::iterator Iterator;
59 typedef std::list< Ptr<PbbTlv> >::const_iterator ConstIterator;
65 * \return an iterator to the first TLV in this block.
67 Iterator Begin (void);
70 * \return a const iterator to the first TLV in this block.
72 ConstIterator Begin (void) const;
75 * \return an iterator to the past-the-end element in this block.
80 * \return a const iterator to the past-the-end element in this block.
82 ConstIterator End (void) const;
85 * \return the number of TLVs in this block.
87 int Size (void) const;
90 * \return true if there are no TLVs in this block, false otherwise.
92 bool Empty (void) const;
95 * \return a smart pointer to the first TLV in this block.
97 Ptr<PbbTlv> Front (void) const;
100 * \return a smart pointer to the last TLV in this block.
102 Ptr<PbbTlv> Back (void) const;
105 * \brief Prepends a TLV to the front of this block.
106 * \param tlv a smart pointer to the TLV to prepend.
108 void PushFront (Ptr<PbbTlv> tlv);
111 * \brief Removes a TLV from the front of this block.
113 void PopFront (void);
116 * \brief Appends a TLV to the back of this block.
117 * \param tlv a smart pointer to the TLV to append.
119 void PushBack (Ptr<PbbTlv> tlv);
122 * \brief Removes a TLV from the back of this block.
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
130 * \param tlv a smart pointer to the TLV to insert.
131 * \return An iterator pointing to the newly inserted TLV.
133 Iterator Insert (Iterator position, const Ptr<PbbTlv> tlv);
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.
140 Iterator Erase (Iterator position);
143 * \brief Removes all TLVs from [first, last) (includes first, not includes
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.
149 Iterator Erase (Iterator first, Iterator last);
152 * \brief Removes all TLVs from this block.
157 * \return The size (in bytes) needed to serialize this block.
159 uint32_t GetSerializedSize (void) const;
162 * \brief Serializes this block into the specified buffer.
163 * \param start a reference to the point in a buffer to begin serializing.
165 * Users should not need to call this. Blocks will be serialized by their
168 void Serialize (Buffer::Iterator &start) const;
171 * \brief Deserializes a block from the specified buffer.
172 * \param start a reference to the point in a buffer to begin deserializing.
174 * Users should not need to call this. Blocks will be deserialized by their
177 void Deserialize (Buffer::Iterator &start);
180 * \brief Pretty-prints the contents of this block.
181 * \param os a stream object to print to.
183 void Print (std::ostream &os) const;
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.
190 * This probably never needs to be called by users. This is used when
191 * recursively printing sub-objects.
193 void Print (std::ostream &os, int level) const;
195 bool operator== (const PbbTlvBlock &other) const;
196 bool operator!= (const PbbTlvBlock &other) const;
199 std::list< Ptr<PbbTlv> > m_tlvList;
203 * \brief A block of Address TLVs (PbbAddressTlv).
205 * Acts similar to a C++ STL container.
207 class PbbAddressTlvBlock
210 typedef std::list< Ptr<PbbAddressTlv> >::iterator Iterator;
211 typedef std::list< Ptr<PbbAddressTlv> >::const_iterator ConstIterator;
213 PbbAddressTlvBlock (void);
214 ~PbbAddressTlvBlock (void);
217 * \return an iterator to the first Address TLV in this block.
219 Iterator Begin (void);
222 * \return a const iterator to the first Address TLV in this block.
224 ConstIterator Begin (void) const;
227 * \return an iterator to the past-the-end element in this block.
232 * \return a const iterator to the past-the-end element in this block.
234 ConstIterator End (void) const;
237 * \return the number of Address TLVs in this block.
239 int Size (void) const;
242 * \return true if there are no Address TLVs in this block, false otherwise.
244 bool Empty (void) const;
247 * \return the first Address TLV in this block.
249 Ptr<PbbAddressTlv> Front (void) const;
252 * \return the last AddressTLV in this block.
254 Ptr<PbbAddressTlv> Back (void) const;
257 * \brief Prepends an Address TLV to the front of this block.
258 * \param tlv a smart pointer to the Address TLV to prepend.
260 void PushFront (Ptr<PbbAddressTlv> tlv);
263 * \brief Removes an AddressTLV from the front of this block.
265 void PopFront (void);
268 * \brief Appends an Address TLV to the back of this block.
269 * \param tlv a smart pointer to the Address TLV to append.
271 void PushBack (Ptr<PbbAddressTlv> tlv);
274 * \brief Removes an Address TLV from the back of this block.
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.
285 Iterator Insert (Iterator position, const Ptr<PbbAddressTlv> tlv);
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.
292 Iterator Erase (Iterator position);
295 * \brief Removes all Address TLVs from [first, last) (includes first, not
297 * \param first an Iterator pointing to the first Address TLV to erase
299 * \param last an Iterator pointing to the element past the last Address TLV
301 * \return an iterator pointing to the next Address TLV in the block.
303 Iterator Erase (Iterator first, Iterator last);
306 * \brief Removes all Address TLVs from this block.
311 * \return The size (in bytes) needed to serialize this block.
313 uint32_t GetSerializedSize (void) const;
316 * \brief Serializes this block into the specified buffer.
317 * \param start a reference to the point in a buffer to begin serializing.
319 * Users should not need to call this. Blocks will be serialized by their
322 void Serialize (Buffer::Iterator &start) const;
325 * \brief Deserializes a block from the specified buffer.
326 * \param start a reference to the point in a buffer to begin deserializing.
328 * Users should not need to call this. Blocks will be deserialized by their
331 void Deserialize (Buffer::Iterator &start);
334 * \brief Pretty-prints the contents of this block.
335 * \param os a stream object to print to.
337 void Print (std::ostream &os) const;
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.
344 * This probably never needs to be called by users. This is used when
345 * recursively printing sub-objects.
347 void Print (std::ostream &os, int level) const;
349 bool operator== (const PbbAddressTlvBlock &other) const;
350 bool operator!= (const PbbAddressTlvBlock &other) const;
353 std::list< Ptr<PbbAddressTlv> > m_tlvList;
357 * \brief Main PacketBB Packet object.
359 * A PacketBB packet is made up of zero or more packet TLVs (PbbTlv), and zero
360 * or more messages (PbbMessage).
362 * See: http://tools.ietf.org/html/rfc5444 for details.
364 class PbbPacket : public SimpleRefCount<PbbPacket,Header>
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;
376 * \return the version of PacketBB that constructed this packet.
378 * This will always return 0 for packets constructed using this API.
380 uint8_t GetVersion (void) const;
383 * \brief Sets the sequence number of this packet.
384 * \param number the sequence number.
386 void SetSequenceNumber (uint16_t number);
389 * \return the sequence number of this packet.
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.
394 uint16_t GetSequenceNumber (void) const;
397 * \brief Tests whether or not this packet has a sequence number.
398 * \return true if this packet has a sequence number, false otherwise.
400 * This should be called before calling GetSequenceNumber to make sure there
403 bool HasSequenceNumber (void) const;
405 /* Manipulating Packet TLVs */
408 * \return an iterator to the first Packet TLV in this packet.
410 TlvIterator TlvBegin (void);
413 * \return a const iterator to the first Packet TLV in this packet.
415 ConstTlvIterator TlvBegin (void) const;
418 * \return an iterator to the past-the-end element in this packet TLV block.
420 TlvIterator TlvEnd (void);
423 * \return a const iterator to the past-the-end element in this packet TLV
426 ConstTlvIterator TlvEnd (void) const;
429 * \return the number of packet TLVs in this packet.
431 int TlvSize (void) const;
434 * \return true if there are no packet TLVs in this packet, false otherwise.
436 bool TlvEmpty (void) const;
439 * \return a smart pointer to the first packet TLV in this packet.
441 Ptr<PbbTlv> TlvFront (void);
444 * \return a const smart pointer to the first packet TLV in this packet.
446 const Ptr<PbbTlv> TlvFront (void) const;
449 * \return a smart pointer to the last packet TLV in this packet.
451 Ptr<PbbTlv> TlvBack (void);
454 * \return a const smart pointer to the last packet TLV in this packet.
456 const Ptr<PbbTlv> TlvBack (void) const;
459 * \brief Prepends a packet TLV to the front of this packet.
460 * \param tlv a smart pointer to the packet TLV to prepend.
462 void TlvPushFront (Ptr<PbbTlv> tlv);
465 * \brief Removes a packet TLV from the front of this packet.
467 void TlvPopFront (void);
470 * \brief Appends a packet TLV to the back of this packet.
471 * \param tlv a smart pointer to the packet TLV to append.
473 void TlvPushBack (Ptr<PbbTlv> tlv);
476 * \brief Removes a packet TLV from the back of this block.
478 void TlvPopBack (void);
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.
485 TlvIterator Erase (TlvIterator position);
488 * \brief Removes all packet TLVs from [first, last) (includes first, not
490 * \param first an Iterator pointing to the first packet TLV to erase
492 * \param last an Iterator pointing to the element past the last packet TLV
494 * \return an iterator pointing to the next packet TLV in the block.
496 TlvIterator Erase (TlvIterator first, TlvIterator last);
499 * \brief Removes all packet TLVs from this packet.
501 void TlvClear (void);
503 /* Manipulating Packet Messages */
506 * \return an iterator to the first message in this packet.
508 MessageIterator MessageBegin (void);
511 * \return a const iterator to the first message in this packet.
513 ConstMessageIterator MessageBegin (void) const;
516 * \return an iterator to the past-the-end element in this message block.
518 MessageIterator MessageEnd (void);
521 * \return a const iterator to the past-the-end element in this message
524 ConstMessageIterator MessageEnd (void) const;
527 * \return the number of messages in this packet.
529 int MessageSize (void) const;
532 * \return true if there are no messages in this packet, false otherwise.
534 bool MessageEmpty (void) const;
537 * \return a smart pointer to the first message in this packet.
539 Ptr<PbbMessage> MessageFront (void);
542 * \return a cosnt smart pointer to the first message in this packet.
544 const Ptr<PbbMessage> MessageFront (void) const;
547 * \return a smart pointer to the last message in this packet.
549 Ptr<PbbMessage> MessageBack (void);
552 * \return a cosnt smart pointer to the last message in this packet.
554 const Ptr<PbbMessage> MessageBack (void) const;
557 * \brief Prepends a message to the front of this packet.
558 * \param message a smart pointer to the message to prepend.
560 void MessagePushFront (Ptr<PbbMessage> message);
563 * \brief Removes a message from the front of this packet.
565 void MessagePopFront (void);
568 * \brief Appends a message to the back of this packet.
569 * \param message a smart pointer to the message to append.
571 void MessagePushBack (Ptr<PbbMessage> message);
574 * \brief Removes a message from the back of this packet.
576 void MessagePopBack (void);
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.
583 MessageIterator Erase (MessageIterator position);
586 * \brief Removes all messages from [first, last) (includes first, not
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.
592 MessageIterator Erase (MessageIterator first, MessageIterator last);
595 * \brief Removes all messages from this packet.
597 void MessageClear (void);
599 /* Methods implemented by all headers */
600 static TypeId GetTypeId (void);
601 virtual TypeId GetInstanceTypeId (void) const;
604 * \return The size (in bytes) needed to serialize this packet.
606 virtual uint32_t GetSerializedSize (void) const;
609 * \brief Serializes this packet into the specified buffer.
610 * \param start a reference to the point in a buffer to begin serializing.
612 virtual void Serialize (Buffer::Iterator start) const;
615 * \brief Deserializes a packet from the specified buffer.
616 * \param start start offset
617 * \return the number of bytes deserialized
619 * If this returns a number smaller than the total number of bytes in the
620 * buffer, there was an error.
622 virtual uint32_t Deserialize (Buffer::Iterator start);
625 * \brief Pretty-prints the contents of this block.
626 * \param os a stream object to print to.
628 virtual void Print (std::ostream &os) const;
630 bool operator== (const PbbPacket &other) const;
631 bool operator!= (const PbbPacket &other) const;
634 void SerializePacketTlv (Buffer::Iterator &start) const;
637 PbbTlvBlock m_tlvList;
638 std::list< Ptr<PbbMessage> > m_messageList;
647 * \brief A message within a PbbPacket packet.
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.
653 class PbbMessage : public SimpleRefCount<PbbMessage>
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;
662 virtual ~PbbMessage ();
665 * \brief Sets the type for this message.
666 * \param type the type to set.
668 void SetType (uint8_t type);
671 * \return the type assigned to this packet
673 uint8_t GetType (void) const;
676 * \brief Sets the address for the node that created this packet.
677 * \param address the originator address.
679 void SetOriginatorAddress (Address address);
682 * \return the address of the node that created this packet.
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.
687 Address GetOriginatorAddress (void) const;
690 * \brief Tests whether or not this message has an originator address.
691 * \return true if this message has an originator address, false otherwise.
693 bool HasOriginatorAddress (void) const;
696 * \brief Sets the maximum number of hops this message should travel
697 * \param hoplimit the limit to set
699 void SetHopLimit (uint8_t hoplimit);
702 * \return the maximum number of hops this message should travel.
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.
707 uint8_t GetHopLimit (void) const;
710 * \brief Tests whether or not this message has a hop limit.
711 * \return true if this message has a hop limit, false otherwise.
713 * If this is set, messages should not hop further than this limit.
715 bool HasHopLimit (void) const;
718 * \brief Sets the current number of hops this message has traveled.
719 * \param hopcount the current number of hops
721 void SetHopCount (uint8_t hopcount);
724 * \return the current number of hops this message has traveled.
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.
729 uint8_t GetHopCount (void) const;
732 * \brief Tests whether or not this message has a hop count.
733 * \return true if this message has a hop limit, false otherwise.
735 bool HasHopCount (void) const;
738 * \brief Sets the sequence number of this message.
739 * \param seqnum the sequence number to set.
741 void SetSequenceNumber (uint16_t seqnum);
744 * \return the sequence number of this message.
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.
749 uint16_t GetSequenceNumber (void) const;
752 * \brief Tests whether or not this message has a sequence number.
753 * \return true if this message has a sequence number, false otherwise.
755 bool HasSequenceNumber (void) const;
757 /* Manipulating PbbMessage TLVs */
760 * \return an iterator to the first message TLV in this message.
762 TlvIterator TlvBegin ();
765 * \return a const iterator to the first message TLV in this message.
767 ConstTlvIterator TlvBegin () const;
770 * \return an iterator to the past-the-end message TLV element in this
773 TlvIterator TlvEnd ();
776 * \return a const iterator to the past-the-end message TLV element in this
779 ConstTlvIterator TlvEnd () const;
782 * \return the number of message TLVs in this message.
784 int TlvSize (void) const;
787 * \return true if there are no message TLVs in this message, false otherwise.
789 bool TlvEmpty (void) const;
792 * \return a smart pointer to the first message TLV in this message.
794 Ptr<PbbTlv> TlvFront (void);
797 * \return a const smart pointer to the first message TLV in this message.
799 const Ptr<PbbTlv> TlvFront (void) const;
802 * \return a smart pointer to the last message TLV in this message.
804 Ptr<PbbTlv> TlvBack (void);
807 * \return a const smart pointer to the last message TLV in this message.
809 const Ptr<PbbTlv> TlvBack (void) const;
812 * \brief Prepends a message TLV to the front of this message.
813 * \param tlv a smart pointer to the message TLV to prepend.
815 void TlvPushFront (Ptr<PbbTlv> tlv);
818 * \brief Removes a message TLV from the front of this message.
820 void TlvPopFront (void);
823 * \brief Appends a message TLV to the back of this message.
824 * \param tlv a smart pointer to the message TLV to append.
826 void TlvPushBack (Ptr<PbbTlv> tlv);
829 * \brief Removes a message TLV from the back of this message.
831 void TlvPopBack (void);
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.
838 TlvIterator TlvErase (TlvIterator position);
841 * \brief Removes all message TLVs from [first, last) (includes first, not
843 * \param first an Iterator pointing to the first message TLV to erase
845 * \param last an Iterator pointing to the element past the last message TLV
847 * \return an iterator pointing to the next message TLV in the message.
849 TlvIterator TlvErase (TlvIterator first, TlvIterator last);
852 * \brief Removes all message TLVs from this block.
854 void TlvClear (void);
856 /* Manipulating Address Block and Address TLV pairs */
859 * \return an iterator to the first address block in this message.
861 AddressBlockIterator AddressBlockBegin ();
864 * \return a const iterator to the first address block in this message.
866 ConstAddressBlockIterator AddressBlockBegin () const;
869 * \return an iterator to the past-the-end address block element in this
872 AddressBlockIterator AddressBlockEnd ();
875 * \return a const iterator to the past-the-end address block element in this
878 ConstAddressBlockIterator AddressBlockEnd () const;
881 * \return the number of address blocks in this message.
883 int AddressBlockSize (void) const;
886 * \return true if there are no address blocks in this message, false
889 bool AddressBlockEmpty (void) const;
892 * \return a smart pointer to the first address block in this message.
894 Ptr<PbbAddressBlock> AddressBlockFront (void);
897 * \return a const smart pointer to the first address block in this message.
899 const Ptr<PbbAddressBlock> AddressBlockFront (void) const;
902 * \return a smart pointer to the last address block in this message.
904 Ptr<PbbAddressBlock> AddressBlockBack (void);
907 * \return a const smart pointer to the last address block in this message.
909 const Ptr<PbbAddressBlock> AddressBlockBack (void) const;
912 * \brief Prepends an address block to the front of this message.
913 * \param block a smart pointer to the address block to prepend.
915 void AddressBlockPushFront (Ptr<PbbAddressBlock> block);
918 * \brief Removes an address block from the front of this message.
920 void AddressBlockPopFront (void);
923 * \brief Appends an address block to the front of this message.
924 * \param block a smart pointer to the address block to append.
926 void AddressBlockPushBack (Ptr<PbbAddressBlock> block);
929 * \brief Removes an address block from the back of this message.
931 void AddressBlockPopBack (void);
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.
938 AddressBlockIterator AddressBlockErase (AddressBlockIterator position);
941 * \brief Removes all address blocks from [first, last) (includes first, not
943 * \param first an Iterator pointing to the first address block to erase
945 * \param last an Iterator pointing to the element past the last address
947 * \return an iterator pointing to the next address block in the message.
949 AddressBlockIterator AddressBlockErase (AddressBlockIterator first,
950 AddressBlockIterator last);
953 * \brief Removes all address blocks from this message.
955 void AddressBlockClear (void);
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.
963 * Users should not need to call this. Blocks will be deserialized by their
966 static Ptr<PbbMessage> DeserializeMessage (Buffer::Iterator &start);
969 * \return The size (in bytes) needed to serialize this message.
971 uint32_t GetSerializedSize (void) const;
974 * \brief Serializes this message into the specified buffer.
975 * \param start a reference to the point in a buffer to begin serializing.
977 * Users should not need to call this. Blocks will be deserialized by their
980 void Serialize (Buffer::Iterator &start) const;
983 * \brief Deserializes a message from the specified buffer.
984 * \param start a reference to the point in a buffer to begin deserializing.
986 * Users should not need to call this. Blocks will be deserialized by their
989 void Deserialize (Buffer::Iterator &start);
992 * \brief Pretty-prints the contents of this message.
993 * \param os a stream object to print to.
995 void Print (std::ostream &os) const;
998 * \brief Pretty-prints the contents of this message, with specified
1000 * \param os a stream object to print to.
1001 * \param level level of indentation.
1003 * This probably never needs to be called by users. This is used when
1004 * recursively printing sub-objects.
1006 void Print (std::ostream &os, int level) const;
1008 bool operator== (const PbbMessage &other) const;
1009 bool operator!= (const PbbMessage &other) const;
1012 /* PbbMessage size in bytes - 1.
1014 * IPv4 = 4 - 1 = 3, IPv6 = 16 - 1 = 15
1016 virtual PbbAddressLength GetAddressLength (void) const = 0;
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;
1022 virtual Ptr<PbbAddressBlock> AddressBlockDeserialize (Buffer::Iterator &start) const = 0;
1025 PbbTlvBlock m_tlvList;
1026 std::list< Ptr<PbbAddressBlock> > m_addressBlockList;
1029 PbbAddressLength m_addrSize;
1031 bool m_hasOriginatorAddress;
1032 Address m_originatorAddress;
1040 bool m_hasSequenceNumber;
1041 uint16_t m_sequenceNumber;
1045 * \brief Concrete IPv4 specific PbbMessage.
1047 * This message will only contain IPv4 addresses.
1049 class PbbMessageIpv4 : public PbbMessage {
1052 virtual ~PbbMessageIpv4 ();
1055 virtual PbbAddressLength GetAddressLength (void) const;
1057 virtual void SerializeOriginatorAddress (Buffer::Iterator &start) const;
1058 virtual Address DeserializeOriginatorAddress (Buffer::Iterator &start) const;
1059 virtual void PrintOriginatorAddress (std::ostream &os) const;
1061 virtual Ptr<PbbAddressBlock> AddressBlockDeserialize (Buffer::Iterator &start) const;
1065 * \brief Concrete IPv6 specific PbbMessage class.
1067 * This message will only contain IPv6 addresses.
1069 class PbbMessageIpv6 : public PbbMessage {
1072 virtual ~PbbMessageIpv6 ();
1075 virtual PbbAddressLength GetAddressLength (void) const;
1077 virtual void SerializeOriginatorAddress (Buffer::Iterator &start) const;
1078 virtual Address DeserializeOriginatorAddress (Buffer::Iterator &start) const;
1079 virtual void PrintOriginatorAddress (std::ostream &os) const;
1081 virtual Ptr<PbbAddressBlock> AddressBlockDeserialize (Buffer::Iterator &start) const;
1085 * \brief An Address Block and its associated Address TLV Blocks.
1087 * This is a pure virtual base class, when creating address blocks, you should
1088 * instantiate either PbbAddressBlockIpv4 or PbbAddressBlockIpv6.
1090 class PbbAddressBlock : public SimpleRefCount<PbbAddressBlock>
1093 typedef std::list< Address >::iterator AddressIterator;
1094 typedef std::list< Address >::const_iterator ConstAddressIterator;
1096 typedef std::list<uint8_t>::iterator PrefixIterator;
1097 typedef std::list<uint8_t>::const_iterator ConstPrefixIterator;
1099 typedef PbbAddressTlvBlock::Iterator TlvIterator;
1100 typedef PbbAddressTlvBlock::ConstIterator ConstTlvIterator;
1103 virtual ~PbbAddressBlock ();
1105 /* Manipulating the address block */
1108 * \return an iterator to the first address in this block.
1110 AddressIterator AddressBegin (void);
1113 * \return a const iterator to the first address in this block.
1115 ConstAddressIterator AddressBegin (void) const;
1118 * \return an iterator to the last address in this block.
1120 AddressIterator AddressEnd (void);
1123 * \return a const iterator to the last address in this block.
1125 ConstAddressIterator AddressEnd (void) const;
1128 * \return the number of addresses in this block.
1130 int AddressSize (void) const;
1133 * \return true if there are no addresses in this block, false otherwise.
1135 bool AddressEmpty (void) const;
1138 * \return the first address in this block.
1140 Address AddressFront (void) const;
1143 * \return the last address in this block.
1145 Address AddressBack (void) const;
1148 * \brief Prepends an address to the front of this block.
1149 * \param address the address to prepend.
1151 void AddressPushFront (Address address);
1154 * \brief Removes an address from the front of this block.
1156 void AddressPopFront (void);
1159 * \brief Appends an address to the back of this block.
1160 * \param address the address to append.
1162 void AddressPushBack (Address address);
1165 * \brief Removes an address from the back of this block.
1167 void AddressPopBack (void);
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.
1176 AddressIterator AddressInsert (AddressIterator position,
1177 const Address value);
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.
1184 AddressIterator AddressErase (AddressIterator position);
1187 * \brief Removes all addresses from [first, last) (includes first, not
1189 * \param first an Iterator pointing to the first address to erase
1191 * \param last an Iterator pointing to the element past the last address to
1193 * \return an iterator pointing to the next address in the block.
1195 AddressIterator AddressErase (AddressIterator first, AddressIterator last);
1198 * \brief Removes all addresses from this block.
1200 void AddressClear (void);
1202 /* Prefix methods */
1205 * \return an iterator to the first prefix in this block.
1207 PrefixIterator PrefixBegin (void);
1210 * \return a const iterator to the first prefix in this block.
1212 ConstPrefixIterator PrefixBegin (void) const;
1215 * \return an iterator to the last prefix in this block.
1217 PrefixIterator PrefixEnd (void);
1220 * \return a const iterator to the last prefix in this block.
1222 ConstPrefixIterator PrefixEnd (void) const;
1225 * \return the number of prefixes in this block.
1227 int PrefixSize (void) const;
1230 * \return true if there are no prefixes in this block, false otherwise.
1232 bool PrefixEmpty (void) const;
1235 * \return the first prefix in this block.
1237 uint8_t PrefixFront (void) const;
1240 * \return the last prefix in this block.
1242 uint8_t PrefixBack (void) const;
1245 * \brief Prepends a prefix to the front of this block.
1246 * \param prefix the prefix to prepend.
1248 void PrefixPushFront (uint8_t prefix);
1251 * \brief Removes a prefix from the front of this block.
1253 void PrefixPopFront (void);
1256 * \brief Appends a prefix to the back of this block.
1257 * \param prefix the prefix to append.
1259 void PrefixPushBack (uint8_t prefix);
1262 * \brief Removes a prefix from the back of this block.
1264 void PrefixPopBack (void);
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.
1273 PrefixIterator PrefixInsert (PrefixIterator position, const uint8_t value);
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.
1280 PrefixIterator PrefixErase (PrefixIterator position);
1283 * \brief Removes all prefixes from [first, last) (includes first, not
1285 * \param first an Iterator pointing to the first prefix to erase
1287 * \param last an Iterator pointing to the element past the last prefix to
1289 * \return an iterator pointing to the next prefix in the block.
1291 PrefixIterator PrefixErase (PrefixIterator first, PrefixIterator last);
1294 * \brief Removes all prefixes from this block.
1296 void PrefixClear (void);
1298 /* Manipulating the TLV block */
1301 * \return an iterator to the first address TLV in this block.
1303 TlvIterator TlvBegin (void);
1306 * \return a const iterator to the first address TLV in this block.
1308 ConstTlvIterator TlvBegin (void) const;
1311 * \return an iterator to the last address TLV in this block.
1313 TlvIterator TlvEnd (void);
1316 * \return a const iterator to the last address TLV in this block.
1318 ConstTlvIterator TlvEnd (void) const;
1321 * \return the number of address TLVs in this block.
1323 int TlvSize (void) const;
1326 * \return true if there are no address TLVs in this block, false otherwise.
1328 bool TlvEmpty (void) const;
1331 * \return a smart pointer to the first address TLV in this block.
1333 Ptr<PbbAddressTlv> TlvFront (void);
1336 * \return a const smart pointer to the first address TLV in this message.
1338 const Ptr<PbbAddressTlv> TlvFront (void) const;
1341 * \return a smart pointer to the last address TLV in this message.
1343 Ptr<PbbAddressTlv> TlvBack (void);
1346 * \return a const smart pointer to the last address TLV in this message.
1348 const Ptr<PbbAddressTlv> TlvBack (void) const;
1351 * \brief Prepends an address TLV to the front of this message.
1352 * \param address a smart pointer to the address TLV to prepend.
1354 void TlvPushFront (Ptr<PbbAddressTlv> address);
1357 * \brief Removes an address TLV from the front of this message.
1359 void TlvPopFront (void);
1362 * \brief Appends an address TLV to the back of this message.
1363 * \param address a smart pointer to the address TLV to append.
1365 void TlvPushBack (Ptr<PbbAddressTlv> address);
1368 * \brief Removes an address TLV from the back of this message.
1370 void TlvPopBack (void);
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.
1379 TlvIterator TlvInsert (TlvIterator position, const Ptr<PbbTlv> value);
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.
1386 TlvIterator TlvErase (TlvIterator position);
1389 * \brief Removes all address TLVs from [first, last) (includes first, not
1391 * \param first an Iterator pointing to the first address TLV to erase
1393 * \param last an Iterator pointing to the element past the last address TLV
1395 * \return an iterator pointing to the next address TLV in the message.
1397 TlvIterator TlvErase (TlvIterator first, TlvIterator last);
1400 * \brief Removes all address TLVs from this block.
1402 void TlvClear (void);
1405 * \return The size (in bytes) needed to serialize this address block.
1407 uint32_t GetSerializedSize (void) const;
1410 * \brief Serializes this address block into the specified buffer.
1411 * \param start a reference to the point in a buffer to begin serializing.
1413 * Users should not need to call this. Blocks will be deserialized by their
1414 * containing packet.
1416 void Serialize (Buffer::Iterator &start) const;
1419 * \brief Deserializes an address block from the specified buffer.
1420 * \param start a reference to the point in a buffer to begin deserializing.
1422 * Users should not need to call this. Blocks will be deserialized by their
1423 * containing packet.
1425 void Deserialize (Buffer::Iterator &start);
1428 * \brief Pretty-prints the contents of this address block.
1429 * \param os a stream object to print to.
1431 void Print (std::ostream &os) const;
1434 * \brief Pretty-prints the contents of this address block, with specified
1436 * \param os a stream object to print to.
1437 * \param level level of indentation.
1439 * This probably never needs to be called by users. This is used when
1440 * recursively printing sub-objects.
1442 void Print (std::ostream &os, int level) const;
1444 bool operator== (const PbbAddressBlock &other) const;
1445 bool operator!= (const PbbAddressBlock &other) const;
1448 virtual uint8_t GetAddressLength (void) const = 0;
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;
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;
1460 std::list<Address> m_addressList;
1461 std::list<uint8_t> m_prefixList;
1462 PbbAddressTlvBlock m_addressTlvList;
1466 * \brief Concrete IPv4 specific PbbAddressBlock.
1468 * This address block will only contain IPv4 addresses.
1470 class PbbAddressBlockIpv4 : public PbbAddressBlock
1473 PbbAddressBlockIpv4 ();
1474 virtual ~PbbAddressBlockIpv4 ();
1477 virtual uint8_t GetAddressLength (void) const;
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;
1485 * \brief Concrete IPv6 specific PbbAddressBlock.
1487 * This address block will only contain IPv6 addresses.
1489 class PbbAddressBlockIpv6 : public PbbAddressBlock
1492 PbbAddressBlockIpv6 ();
1493 virtual ~PbbAddressBlockIpv6 ();
1496 virtual uint8_t GetAddressLength (void) const;
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;
1504 * \brief A packet or message TLV
1506 class PbbTlv : public SimpleRefCount<PbbTlv>
1510 virtual ~PbbTlv (void);
1513 * \brief Sets the type of this TLV.
1514 * \param type the type value to set.
1516 void SetType (uint8_t type);
1519 * \return the type of this TLV.
1521 uint8_t GetType (void) const;
1524 * \brief Sets the type extension of this TLV.
1525 * \param type the type extension value to set.
1527 * The type extension is like a sub-type used to further distinguish between
1528 * TLVs of the same type.
1530 void SetTypeExt (uint8_t type);
1533 * \return the type extension for this TLV.
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.
1538 uint8_t GetTypeExt (void) const;
1541 * \brief Tests whether or not this TLV has a type extension.
1542 * \return true if this TLV has a type extension, false otherwise.
1544 * This should be called before calling GetTypeExt to make sure there
1547 bool HasTypeExt (void) const;
1550 * \brief Sets the value of this message to the specified buffer.
1551 * \param start a buffer instance.
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.
1556 void SetValue (Buffer start);
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.
1563 * The buffer *is copied* into a *new buffer instance*. You can free the
1564 * data in the buffer provided anytime you wish.
1566 void SetValue (const uint8_t * buffer, uint32_t size);
1569 * \return a Buffer pointing to the value of this TLV.
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.
1574 Buffer GetValue (void) const;
1577 * \brief Tests whether or not this TLV has a value.
1578 * \return true if this tlv has a TLV, false otherwise.
1580 * This should be called before calling GetTypeExt to make sure there
1583 bool HasValue (void) const;
1586 * \return The size (in bytes) needed to serialize this TLV.
1588 uint32_t GetSerializedSize (void) const;
1591 * \brief Serializes this TLV into the specified buffer.
1592 * \param start a reference to the point in a buffer to begin serializing.
1594 * Users should not need to call this. TLVs will be serialized by their
1595 * containing blocks.
1597 void Serialize (Buffer::Iterator &start) const;
1600 * \brief Deserializes a TLV from the specified buffer.
1601 * \param start a reference to the point in a buffer to begin deserializing.
1603 * Users should not need to call this. TLVs will be deserialized by their
1604 * containing blocks.
1606 void Deserialize (Buffer::Iterator &start);
1609 * \brief Pretty-prints the contents of this TLV.
1610 * \param os a stream object to print to.
1612 void Print (std::ostream &os) const;
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.
1619 * This probably never needs to be called by users. This is used when
1620 * recursively printing sub-objects.
1622 void Print (std::ostream &os, int level) const;
1624 bool operator== (const PbbTlv &other) const;
1625 bool operator!= (const PbbTlv &other) const;
1628 void SetIndexStart (uint8_t index);
1629 uint8_t GetIndexStart (void) const;
1630 bool HasIndexStart (void) const;
1632 void SetIndexStop (uint8_t index);
1633 uint8_t GetIndexStop (void) const;
1634 bool HasIndexStop (void) const;
1636 void SetMultivalue (bool isMultivalue);
1637 bool IsMultivalue (void) const;
1645 bool m_hasIndexStart;
1646 uint8_t m_indexStart;
1648 bool m_hasIndexStop;
1649 uint8_t m_indexStop;
1651 bool m_isMultivalue;
1657 * \brief An Address TLV
1659 class PbbAddressTlv : public PbbTlv
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.
1667 void SetIndexStart (uint8_t index);
1670 * \return the first (inclusive) index of the address in the corresponding
1671 * address block that this TLV applies to.
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.
1676 uint8_t GetIndexStart (void) const;
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.
1682 * This should be called before calling GetIndexStart to make sure there
1685 bool HasIndexStart (void) const;
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.
1692 void SetIndexStop (uint8_t index);
1695 * \return the last (inclusive) index of the address in the corresponding
1696 * PbbAddressBlock that this TLV applies to.
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.
1701 uint8_t GetIndexStop (void) const;
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.
1707 * This should be called before calling GetIndexStop to make sure there
1710 bool HasIndexStop (void) const;
1713 * \brief Sets whether or not this address TLV is "multivalue"
1714 * \param isMultivalue whether or not this address TLV should be multivalue.
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.
1720 void SetMultivalue (bool isMultivalue);
1723 * \brief Tests whether or not this address TLV is "multivalue"
1724 * \return whether this address TLV is multivalue or not.
1726 bool IsMultivalue (void) const;
1729 } /* namespace ns3 */
1731 #endif /* PACKETBB_H */