From afe998d27d2386c657298fb7560b2421c7682664 Mon Sep 17 00:00:00 2001 From: Tom Wambold Date: Thu, 13 Aug 2009 23:30:03 -0400 Subject: [PATCH 01/12] Adding PacketBB (RFC 5444) library, along with test. --- src/contrib/packetbb.cc | 2676 +++++++++++++++++++++++ src/contrib/packetbb.h | 617 ++++++ src/contrib/test-packetbb.cc | 3861 ++++++++++++++++++++++++++++++++++ src/contrib/wscript | 2 + 4 files changed, 7156 insertions(+) create mode 100644 src/contrib/packetbb.cc create mode 100644 src/contrib/packetbb.h create mode 100644 src/contrib/test-packetbb.cc diff --git a/src/contrib/packetbb.cc b/src/contrib/packetbb.cc new file mode 100644 index 000000000..12bb426fe --- /dev/null +++ b/src/contrib/packetbb.cc @@ -0,0 +1,2676 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* vim: set noai ts=2 sw=2 expandtab: */ +/* + * Copyright (c) 2009 Drexel University + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Tom Wambold + */ +/* TODO: + * - Check style + * - Check copy constructors + */ + +#include "ns3/ipv4-address.h" +#include "ns3/ipv6-address.h" + +#include "packetbb.h" + +static const uint8_t VERSION = 0; +/* Packet flags */ +static const uint8_t PHAS_SEQ_NUM = 0x8; +static const uint8_t PHAS_TLV = 0x4; + +/* Message flags */ +static const uint8_t MHAS_ORIG = 0x80; +static const uint8_t MHAS_HOP_LIMIT = 0x40; +static const uint8_t MHAS_HOP_COUNT = 0x20; +static const uint8_t MHAS_SEQ_NUM = 0x10; + +/* Address block flags */ +static const uint8_t AHAS_HEAD = 0x80; +static const uint8_t AHAS_FULL_TAIL = 0x40; +static const uint8_t AHAS_ZERO_TAIL = 0x20; +static const uint8_t AHAS_SINGLE_PRE_LEN = 0x10; +static const uint8_t AHAS_MULTI_PRE_LEN = 0x08; + +/* TLV Flags */ +static const uint8_t THAS_TYPE_EXT = 0x80; +static const uint8_t THAS_SINGLE_INDEX = 0x40; +static const uint8_t THAS_MULTI_INDEX = 0x20; +static const uint8_t THAS_VALUE = 0x10; +static const uint8_t THAS_EXT_LEN = 0x08; +static const uint8_t TIS_MULTIVALUE = 0x04; + +namespace ns3 { + +namespace pbb { + +NS_OBJECT_ENSURE_REGISTERED (PacketBB); + +TlvBlock::Iterator +TlvBlock::Begin (void) +{ + return m_tlvList.begin (); +} + +TlvBlock::ConstIterator +TlvBlock::Begin (void) const +{ + return m_tlvList.begin (); +} + +TlvBlock::Iterator +TlvBlock::End (void) +{ + return m_tlvList.end (); +} + +TlvBlock::ConstIterator +TlvBlock::End (void) const +{ + return m_tlvList.end (); +} + +int +TlvBlock::Size (void) const +{ + return m_tlvList.size (); +} + +bool +TlvBlock::Empty (void) const +{ + return m_tlvList.empty (); +} + +Ptr +TlvBlock::Front (void) const +{ + return m_tlvList.front (); +} + +Ptr +TlvBlock::Back (void) const +{ + return m_tlvList.back (); +} + +void +TlvBlock::PushFront (Ptr tlv) +{ + //Ptr * newptr = new Ptr (GetPointer (tlv)); + m_tlvList.push_front (tlv); +} + +void +TlvBlock::PopFront (void) +{ + m_tlvList.pop_front (); +} + +void +TlvBlock::PushBack (Ptr tlv) +{ + //Ptr * newptr = new Ptr (GetPointer (tlv)); + m_tlvList.push_back (tlv); +} + +void +TlvBlock::PopBack (void) +{ + m_tlvList.pop_back (); +} + +TlvBlock::Iterator +TlvBlock::Insert (TlvBlock::Iterator position, const Ptr tlv) +{ + return m_tlvList.insert (position, tlv); +} + +TlvBlock::Iterator +TlvBlock::Erase (TlvBlock::Iterator position) +{ + return m_tlvList.erase (position); +} + +TlvBlock::Iterator +TlvBlock::Erase (TlvBlock::Iterator first, TlvBlock::Iterator last) +{ + return m_tlvList.erase (first, last); +} + +void +TlvBlock::Clear (void) +{ + m_tlvList.clear (); +} + +uint32_t +TlvBlock::GetSerializedSize (void) const +{ + /* tlv size */ + uint32_t size = 2; + for (ConstIterator iter = Begin (); iter != End (); iter++) + { + size += (*iter)->GetSerializedSize (); + } + return size; +} + +void +TlvBlock::Serialize (Buffer::Iterator &start) const +{ + if (Empty ()) + { + start.WriteHtonU16 (0); + return; + } + + /* We need to write the size of the TLV block in front, so save its + * position. */ + Buffer::Iterator tlvsize = start; + start.Next (2); + for (ConstIterator iter = Begin (); iter != End (); iter++) + { + (*iter)->Serialize (start); + } + /* - 2 to not include the size field */ + uint16_t size = start.GetDistanceFrom (tlvsize) - 2; + tlvsize.WriteHtonU16 (size); +} + +void +TlvBlock::Deserialize (Buffer::Iterator &start) +{ + uint16_t size = start.ReadNtohU16 (); + + Buffer::Iterator tlvstart = start; + if (size > 0) + { + while (start.GetDistanceFrom (tlvstart) < size) + { + Ptr newtlv = Create (); + //Tlv * newtlv = new Tlv (); + newtlv->Deserialize (start); + + //Ptr * newptr = new Ptr (newtlv); + PushBack (newtlv); + } + } +} + +void +TlvBlock::Print (std::ostream &os) const +{ + Print (os, 0); +} + +void +TlvBlock::Print (std::ostream &os, int level) const +{ + std::string prefix = ""; + for (int i = 0; i < level; i++) + prefix.append("\t"); + + os << prefix << "TLV Block {" << std::endl; + os << prefix << "\tsize = " << Size () << std::endl; + os << prefix << "\tmembers [" << std::endl; + for (ConstIterator iter = Begin (); iter != End (); iter++) + { + (*iter)->Print (os, level+2); + } + os << prefix << "\t]" << std::endl; + os << prefix << "}" << std::endl; +} + +bool +TlvBlock::operator== (const TlvBlock &other) const +{ + if (Size () != other.Size ()) + return false; + + ConstIterator ti, oi; + for (ti = Begin (), oi = other.Begin (); + ti != End () && oi != other.End (); + ti++, oi++) + { + if (**ti != **oi) + return false; + } + return true; +} + +bool +TlvBlock::operator!= (const TlvBlock &other) const +{ + return !(*this == other); +} + +/* End TlvBlock class */ + +AddressTlvBlock::Iterator +AddressTlvBlock::Begin (void) +{ + return m_tlvList.begin (); +} + +AddressTlvBlock::ConstIterator +AddressTlvBlock::Begin (void) const +{ + return m_tlvList.begin (); +} + +AddressTlvBlock::Iterator +AddressTlvBlock::End (void) +{ + return m_tlvList.end (); +} + +AddressTlvBlock::ConstIterator +AddressTlvBlock::End (void) const +{ + return m_tlvList.end (); +} + +int +AddressTlvBlock::Size (void) const +{ + return m_tlvList.size (); +} + +bool +AddressTlvBlock::Empty (void) const +{ + return m_tlvList.empty (); +} + +Ptr +AddressTlvBlock::Front (void) const +{ + return m_tlvList.front (); +} + +Ptr +AddressTlvBlock::Back (void) const +{ + return m_tlvList.back (); +} + +void +AddressTlvBlock::PushFront (Ptr tlv) +{ + m_tlvList.push_front (tlv); +} + +void +AddressTlvBlock::PopFront (void) +{ + m_tlvList.pop_front (); +} + +void +AddressTlvBlock::PushBack (Ptr tlv) +{ + m_tlvList.push_back (tlv); +} + +void +AddressTlvBlock::PopBack (void) +{ + m_tlvList.pop_back (); +} + +AddressTlvBlock::Iterator +AddressTlvBlock::Insert (AddressTlvBlock::Iterator position, const Ptr tlv) +{ + return m_tlvList.insert (position, tlv); +} + +AddressTlvBlock::Iterator +AddressTlvBlock::Erase (AddressTlvBlock::Iterator position) +{ + return m_tlvList.erase (position); +} + +AddressTlvBlock::Iterator +AddressTlvBlock::Erase (AddressTlvBlock::Iterator first, AddressTlvBlock::Iterator last) +{ + return m_tlvList.erase (first, last); +} + +void +AddressTlvBlock::Clear (void) +{ + m_tlvList.clear (); +} + +uint32_t +AddressTlvBlock::GetSerializedSize (void) const +{ + /* tlv size */ + uint32_t size = 2; + for (ConstIterator iter = Begin (); iter != End (); iter++) + { + size += (*iter)->GetSerializedSize (); + } + return size; +} + +void +AddressTlvBlock::Serialize (Buffer::Iterator &start) const +{ + if (Empty ()) + { + start.WriteHtonU16 (0); + return; + } + + /* We need to write the size of the TLV block in front, so save its + * position. */ + Buffer::Iterator tlvsize = start; + start.Next (2); + for (ConstIterator iter = Begin (); iter != End (); iter++) + { + (*iter)->Serialize (start); + } + /* - 2 to not include the size field */ + uint16_t size = start.GetDistanceFrom (tlvsize) - 2; + tlvsize.WriteHtonU16 (size); +} + +void +AddressTlvBlock::Deserialize (Buffer::Iterator &start) +{ + uint16_t size = start.ReadNtohU16 (); + + Buffer::Iterator tlvstart = start; + if (size > 0) + { + while (start.GetDistanceFrom (tlvstart) < size) + { + Ptr newtlv = Create (); + //AddressTlv * newtlv = new AddressTlv (); + newtlv->Deserialize (start); + + //Ptr * newptr = new Ptr (newtlv); + PushBack (newtlv); + } + } +} + +void +AddressTlvBlock::Print (std::ostream &os) const +{ + Print (os, 0); +} + +void +AddressTlvBlock::Print (std::ostream &os, int level) const +{ + std::string prefix = ""; + for (int i = 0; i < level; i++) + prefix.append("\t"); + + os << prefix << "TLV Block {" << std::endl; + os << prefix << "\tsize = " << Size () << std::endl; + os << prefix << "\tmembers [" << std::endl; + for (ConstIterator iter = Begin (); iter != End (); iter++) + { + (*iter)->Print (os, level+2); + } + os << prefix << "\t]" << std::endl; + os << prefix << "}" << std::endl; +} + +bool +AddressTlvBlock::operator== (const AddressTlvBlock &other) const +{ + if (Size () != other.Size ()) + return false; + + ConstIterator it, ot; + for (it = Begin (), ot = other.Begin (); + it != End () && ot != other.End (); + it++, ot++) + { + if (**it != **ot) + return false; + } + return true; +} + +bool +AddressTlvBlock::operator!= (const AddressTlvBlock &other) const +{ + return !(*this == other); +} + + +/* End AddressTlvBlock Class */ + +PacketBB::PacketBB (void) +{ + m_refCount = 1; + m_version = VERSION; + m_hasseqnum = false; +} + +uint8_t +PacketBB::GetVersion (void) const +{ + return m_version; +} + +void +PacketBB::SetSequenceNumber (uint16_t number) +{ + m_seqnum = number; + m_hasseqnum = true; +} + +uint16_t +PacketBB::GetSequenceNumber (void) const throw (PacketBBError) +{ + if (!HasSequenceNumber ()) + { + throw PacketBBError ("Packet has no sequence number."); + } + return m_seqnum; +} + +bool +PacketBB::HasSequenceNumber (void) const +{ + return m_hasseqnum; +} + +/* Manipulating Packet TLVs */ + +PacketBB::TlvIterator +PacketBB::TlvBegin (void) +{ + return m_tlvList.Begin (); +} + +PacketBB::ConstTlvIterator +PacketBB::TlvBegin (void) const +{ + return m_tlvList.Begin (); +} + +PacketBB::TlvIterator +PacketBB::TlvEnd (void) +{ + return m_tlvList.End (); +} + +PacketBB::ConstTlvIterator +PacketBB::TlvEnd (void) const +{ + return m_tlvList.End (); +} + +int +PacketBB::TlvSize (void) const +{ + return m_tlvList.Size (); +} + +bool +PacketBB::TlvEmpty (void) const +{ + return m_tlvList.Empty (); +} + +Ptr +PacketBB::TlvFront (void) +{ + return m_tlvList.Front (); +} + +const Ptr +PacketBB::TlvFront (void) const +{ + return m_tlvList.Front (); +} + +Ptr +PacketBB::TlvBack (void) +{ + return m_tlvList.Back (); +} + +const Ptr +PacketBB::TlvBack (void) const +{ + return m_tlvList.Back (); +} + +void +PacketBB::TlvPushFront (Ptr tlv) +{ + m_tlvList.PushFront (tlv); +} + +void +PacketBB::TlvPopFront (void) +{ + m_tlvList.PopFront (); +} + +void +PacketBB::TlvPushBack (Ptr tlv) +{ + m_tlvList.PushBack (tlv); +} + +void +PacketBB::TlvPopBack (void) +{ + m_tlvList.PopBack (); +} + +PacketBB::TlvIterator +PacketBB::Erase (PacketBB::TlvIterator position) +{ + return m_tlvList.Erase (position); +} + +PacketBB::TlvIterator +PacketBB::Erase (PacketBB::TlvIterator first, PacketBB::TlvIterator last) +{ + return m_tlvList.Erase (first, last); +} + +void +PacketBB::TlvClear (void) +{ + m_tlvList.Clear (); +} + +/* Manipulating Packet Messages */ + +PacketBB::MessageIterator +PacketBB::MessageBegin (void) +{ + return m_messageList.begin (); +} + +PacketBB::ConstMessageIterator +PacketBB::MessageBegin (void) const +{ + return m_messageList.begin (); +} + +PacketBB::MessageIterator +PacketBB::MessageEnd (void) +{ + return m_messageList.end (); +} + +PacketBB::ConstMessageIterator +PacketBB::MessageEnd (void) const +{ + return m_messageList.end (); +} + +int +PacketBB::MessageSize (void) const +{ + return m_messageList.size (); +} + +bool +PacketBB::MessageEmpty (void) const +{ + return m_messageList.empty (); +} + +Ptr +PacketBB::MessageFront (void) +{ + return m_messageList.front (); +} + +const Ptr +PacketBB::MessageFront (void) const +{ + return m_messageList.front (); +} + +Ptr +PacketBB::MessageBack (void) +{ + return m_messageList.back (); +} + +const Ptr +PacketBB::MessageBack (void) const +{ + return m_messageList.back (); +} + +void +PacketBB::MessagePushFront (Ptr tlv) +{ + m_messageList.push_front (tlv); +} + +void +PacketBB::MessagePopFront (void) +{ + m_messageList.pop_front (); +} + +void +PacketBB::MessagePushBack (Ptr tlv) +{ + m_messageList.push_back (tlv); +} + +void +PacketBB::MessagePopBack (void) +{ + m_messageList.pop_back (); +} + +PacketBB::MessageIterator +PacketBB::Erase (PacketBB::MessageIterator position) +{ + return m_messageList.erase (position); +} + +PacketBB::MessageIterator +PacketBB::Erase (PacketBB::MessageIterator first, + PacketBB::MessageIterator last) +{ + return m_messageList.erase (first, last); +} + +void +PacketBB::MessageClear (void) +{ + m_messageList.clear (); +} + +void +PacketBB::Ref (void) const +{ + m_refCount++; +} + +void +PacketBB::Unref (void) const +{ + m_refCount--; + if (m_refCount == 0) + { + delete this; + } +} + +TypeId +PacketBB::GetTypeId (void) +{ + static TypeId tid = TypeId ("PacketBB") + .SetParent
() + .AddConstructor () + ; + return tid; +} + +TypeId +PacketBB::GetInstanceTypeId (void) const +{ + return GetTypeId (); +} + +uint32_t +PacketBB::GetSerializedSize (void) const +{ + /* Version number + flags */ + uint32_t size = 1; + + if (HasSequenceNumber()) + { + size += 2; + } + + if (!TlvEmpty ()) + size += m_tlvList.GetSerializedSize (); + + for (ConstMessageIterator iter = MessageBegin (); iter != MessageEnd (); + iter++) + { + size += (*iter)->GetSerializedSize (); + } + + return size; +} + +void +PacketBB::Serialize (Buffer::Iterator start) const +{ + /* We remember the start, so we can write the flags after we check for a + * sequence number and TLV. */ + Buffer::Iterator bufref = start; + start.Next (); + + uint8_t flags = VERSION; + /* Make room for 4 bit flags */ + flags <<= 4; + + if (HasSequenceNumber ()) + { + flags |= PHAS_SEQ_NUM; + start.WriteHtonU16 (GetSequenceNumber ()); + } + + if (!TlvEmpty ()) + { + flags |= PHAS_TLV; + m_tlvList.Serialize (start); + } + + bufref.WriteU8(flags); + + for (ConstMessageIterator iter = MessageBegin (); + iter != MessageEnd (); + iter++) + { + (*iter)->Serialize (start); + } +} + +uint32_t +PacketBB::Deserialize (Buffer::Iterator start) +{ + Buffer::Iterator begin = start; + + uint8_t flags = start.ReadU8 (); + + if (flags & PHAS_SEQ_NUM) + SetSequenceNumber (start.ReadNtohU16 ()); + + if (flags & PHAS_TLV) + m_tlvList.Deserialize (start); + + while (!start.IsEnd()) + { + Ptr newmsg = Message::DeserializeMessage (start); + //Message * newmsg = Message::DeserializeMessage (start); + //Ptr * newptr = new Ptr (newmsg); + MessagePushBack (newmsg); + } + + flags >>= 4; + m_version = flags; + + return start.GetDistanceFrom (begin); +} + +void +PacketBB::Print (std::ostream &os) const +{ + os << "PacketBB {" << std::endl; + + if (HasSequenceNumber ()) + os << "\tsequence number = " << GetSequenceNumber (); + + os << std::endl; + + m_tlvList.Print (os, 1); + + for (ConstMessageIterator iter = MessageBegin (); + iter != MessageEnd (); + iter++) + { + (*iter)->Print (os, 1); + } + + os << "}" << std::endl; +} + +bool +PacketBB::operator== (const PacketBB &other) const +{ + if (GetVersion () != other.GetVersion ()) + return false; + + if (HasSequenceNumber () != other.HasSequenceNumber ()) + return false; + + if (HasSequenceNumber ()) + { + if (GetSequenceNumber () != other.GetSequenceNumber ()) + return false; + } + + if (m_tlvList != other.m_tlvList) + return false; + + if (MessageSize () != other.MessageSize ()) + return false; + + ConstMessageIterator tmi, omi; + for (tmi = MessageBegin (), omi = other.MessageBegin (); + tmi != MessageEnd () && omi != other.MessageEnd (); + tmi++, omi++) + { + if (**tmi != **omi) + return false; + } + return true; +} + +bool +PacketBB::operator!= (const PacketBB &other) const +{ + return !(*this == other); +} + +/* End PacketBB class */ + +Message::Message (void) +{ + m_refCount = 1; + /* Default to IPv4 */ + m_addrSize = IPV4; + m_hasOriginatorAddress = false; + m_hasHopLimit = false; + m_hasHopCount = false; + m_hasSequenceNumber = false; +} + +void +Message::SetType (uint8_t type) +{ + m_type = type; +} + +uint8_t +Message::GetType (void) const +{ + return m_type; +} + +AddressLength +Message::GetAddressLength (void) const +{ + return m_addrSize; +} + +void +Message::SetOriginatorAddress (Address address) +{ + m_originatorAddress = address; + m_hasOriginatorAddress = true; +} + +Address +Message::GetOriginatorAddress (void) const throw (PacketBBError) +{ + if (!HasOriginatorAddress()) + { + throw PacketBBError ("Message has no originator address."); + } + return m_originatorAddress; +} + +bool +Message::HasOriginatorAddress (void) const +{ + return m_hasOriginatorAddress; +} + +void +Message::SetHopLimit (uint8_t hopLimit) +{ + m_hopLimit = hopLimit; + m_hasHopLimit = true; +} + +uint8_t +Message::GetHopLimit (void) const throw (PacketBBError) +{ + if (!HasHopLimit()) + { + throw PacketBBError ("Message has no hop limit."); + } + return m_hopLimit; +} + +bool +Message::HasHopLimit (void) const +{ + return m_hasHopLimit; +} + +void +Message::SetHopCount (uint8_t hopCount) +{ + m_hopCount = hopCount; + m_hasHopCount = true; +} + +uint8_t +Message::GetHopCount (void) const throw (PacketBBError) +{ + if (!HasHopCount()) + { + throw PacketBBError ("Message has no hop count."); + } + return m_hopCount; +} + +bool +Message::HasHopCount (void) const +{ + return m_hasHopCount; +} + +void +Message::SetSequenceNumber (uint16_t sequenceNumber) +{ + m_sequenceNumber = sequenceNumber; + m_hasSequenceNumber = true; +} + +uint16_t +Message::GetSequenceNumber (void) const throw (PacketBBError) +{ + if (!HasSequenceNumber()) + { + throw PacketBBError ("Message has no sequence number."); + } + return m_sequenceNumber; +} + +bool +Message::HasSequenceNumber (void) const +{ + return m_hasSequenceNumber; +} + +/* Manipulating Message TLVs */ + +Message::TlvIterator +Message::TlvBegin (void) +{ + return m_tlvList.Begin(); +} + +Message::ConstTlvIterator +Message::TlvBegin (void) const +{ + return m_tlvList.Begin(); +} + +Message::TlvIterator +Message::TlvEnd (void) +{ + return m_tlvList.End(); +} + +Message::ConstTlvIterator +Message::TlvEnd (void) const +{ + return m_tlvList.End(); +} + +int +Message::TlvSize (void) const +{ + return m_tlvList.Size(); +} + +bool +Message::TlvEmpty (void) const +{ + return m_tlvList.Empty(); +} + +Ptr +Message::TlvFront (void) +{ + return m_tlvList.Front(); +} + +const Ptr +Message::TlvFront (void) const +{ + return m_tlvList.Front(); +} + +Ptr +Message::TlvBack (void) +{ + return m_tlvList.Back(); +} + +const Ptr +Message::TlvBack (void) const +{ + return m_tlvList.Back(); +} + +void +Message::TlvPushFront (Ptr tlv) +{ + m_tlvList.PushFront(tlv); +} + +void +Message::TlvPopFront (void) +{ + m_tlvList.PopFront(); +} + +void +Message::TlvPushBack (Ptr tlv) +{ + m_tlvList.PushBack(tlv); +} + +void +Message::TlvPopBack (void) +{ + m_tlvList.PopBack(); +} + +Message::TlvIterator +Message::TlvErase (Message::TlvIterator position) +{ + return m_tlvList.Erase(position); +} + +Message::TlvIterator +Message::TlvErase (Message::TlvIterator first, Message::TlvIterator last) +{ + return m_tlvList.Erase(first, last); +} + +void +Message::TlvClear (void) +{ + return m_tlvList.Clear(); +} + +/* Manipulating Address Block and Address TLV pairs */ + +Message::AddressBlockIterator +Message::AddressBlockBegin (void) +{ + return m_addressBlockList.begin(); +} + +Message::ConstAddressBlockIterator +Message::AddressBlockBegin (void) const +{ + return m_addressBlockList.begin(); +} + +Message::AddressBlockIterator +Message::AddressBlockEnd (void) +{ + return m_addressBlockList.end(); +} + +Message::ConstAddressBlockIterator +Message::AddressBlockEnd (void) const +{ + return m_addressBlockList.end(); +} + +int +Message::AddressBlockSize (void) const +{ + return m_addressBlockList.size(); +} + +bool +Message::AddressBlockEmpty (void) const +{ + return m_addressBlockList.empty(); +} + +Ptr +Message::AddressBlockFront (void) +{ + return m_addressBlockList.front(); +} + +const Ptr +Message::AddressBlockFront (void) const +{ + return m_addressBlockList.front(); +} + +Ptr +Message::AddressBlockBack (void) +{ + return m_addressBlockList.back(); +} + +const Ptr +Message::AddressBlockBack (void) const +{ + return m_addressBlockList.back(); +} + +void +Message::AddressBlockPushFront (Ptr tlv) +{ + m_addressBlockList.push_front(tlv); +} + +void +Message::AddressBlockPopFront (void) +{ + m_addressBlockList.pop_front(); +} + +void +Message::AddressBlockPushBack (Ptr tlv) +{ + m_addressBlockList.push_back(tlv); +} + +void +Message::AddressBlockPopBack (void) +{ + m_addressBlockList.pop_back(); +} + +Message::AddressBlockIterator +Message::AddressBlockErase (Message::AddressBlockIterator position) +{ + return m_addressBlockList.erase(position); +} + +Message::AddressBlockIterator +Message::AddressBlockErase (Message::AddressBlockIterator first, + Message::AddressBlockIterator last) +{ + return m_addressBlockList.erase(first, last); +} + +void +Message::AddressBlockClear (void) +{ + return m_addressBlockList.clear(); +} + +void +Message::Ref (void) const +{ + m_refCount++; +} + +void +Message::Unref (void) const +{ + m_refCount--; + if (m_refCount == 0) + { + delete this; + } +} + +uint32_t +Message::GetSerializedSize (void) const +{ + /* msg-type + (msg-flags + msg-addr-length) + 2msg-size */ + uint32_t size = 4; + + if (HasOriginatorAddress()) + size += GetAddressLength() + 1; + + if (HasHopLimit()) + size++; + + if (HasHopCount()) + size++; + + if (HasSequenceNumber()) + size += 2; + + size += m_tlvList.GetSerializedSize (); + + for (ConstAddressBlockIterator iter = AddressBlockBegin (); + iter != AddressBlockEnd (); + iter++) + { + size += (*iter)->GetSerializedSize (); + } + + return size; +} + +void +Message::Serialize (Buffer::Iterator &start) const +{ + Buffer::Iterator front = start; + + start.WriteU8 (GetType()); + + /* Save a reference to the spot where we will later write the flags */ + Buffer::Iterator bufref = start; + start.Next (1); + + uint8_t flags = 0; + + flags = GetAddressLength (); + + Buffer::Iterator sizeref = start; + start.Next (2); + + if (HasOriginatorAddress ()) + { + flags |= MHAS_ORIG; + SerializeOriginatorAddress (start); + } + + if (HasHopLimit ()) + { + flags |= MHAS_HOP_LIMIT; + start.WriteU8 (GetHopLimit ()); + } + + if (HasHopCount ()) + { + flags |= MHAS_HOP_COUNT; + start.WriteU8 (GetHopCount ()); + } + + if (HasSequenceNumber ()) + { + flags |= MHAS_SEQ_NUM; + start.WriteHtonU16 (GetSequenceNumber ()); + } + + bufref.WriteU8(flags); + + m_tlvList.Serialize (start); + + for (ConstAddressBlockIterator iter = AddressBlockBegin (); + iter != AddressBlockEnd (); + iter++) + { + (*iter)->Serialize (start); + } + + sizeref.WriteHtonU16 (front.GetDistanceFrom (start)); +} + +Ptr +Message::DeserializeMessage (Buffer::Iterator &start) throw (PacketBBError) +{ + /* We need to read the msg-addr-len field to determine what kind of object to + * construct. */ + start.Next (); + uint8_t addrlen = start.ReadU8 (); + start.Prev (2); /* Go back to the start */ + + /* The first four bytes of the flag is the address length. Set the last four + * bytes to 0 to read it. */ + addrlen = (addrlen & 0xf); + + Ptr newmsg; + + switch (addrlen) + { + case 0: + case IPV4: + newmsg = Create (); + break; + case IPV6: + newmsg = Create (); + break; + default: + throw PacketBBError ("Message deserialization has invalid address size."); + break; + } + newmsg->Deserialize (start); + return newmsg; +} + +void +Message::Deserialize (Buffer::Iterator &start) +{ + Buffer::Iterator front = start; + SetType (start.ReadU8 ()); + uint8_t flags = start.ReadU8 (); + + uint16_t size = start.ReadNtohU16 (); + + if (flags & MHAS_ORIG) + SetOriginatorAddress (DeserializeOriginatorAddress (start)); + + if (flags & MHAS_HOP_LIMIT) + SetHopLimit (start.ReadU8 ()); + + if (flags & MHAS_HOP_COUNT) + SetHopCount (start.ReadU8 ()); + + if (flags & MHAS_SEQ_NUM) + SetSequenceNumber (start.ReadNtohU16 ()); + + m_tlvList.Deserialize (start); + + if (size > 0) + { + while (start.GetDistanceFrom(front) < size) + { + Ptr newab = AddressBlockDeserialize (start); + //AddressBlock * newab = AddressBlockDeserialize (start); + //Ptr * newptr = new Ptr (newab); + AddressBlockPushBack (newab); + } + } +} + +void +Message::Print (std::ostream &os) const +{ + Print (os, 0); +} + +void +Message::Print (std::ostream &os, int level) const +{ + std::string prefix = ""; + for (int i = 0; i < level; i++) + prefix.append ("\t"); + + os << prefix << "Message {" << std::endl; + + os << prefix << "\tmessage type = " << (int)GetType () << std::endl; + os << prefix << "\taddress size = " << GetAddressLength () << std::endl; + + if (HasOriginatorAddress ()) + { + os << prefix << "\toriginator address = "; + PrintOriginatorAddress (os); + os << std::endl; + } + + if (HasHopLimit ()) + os << prefix << "\thop limit = " << (int)GetHopLimit () << std::endl; + + if (HasHopCount ()) + os << prefix << "\thop count = " << (int)GetHopCount () << std::endl; + + if (HasSequenceNumber ()) + os << prefix << "\tseqnum = " << GetSequenceNumber () << std::endl; + + m_tlvList.Print (os, level+1); + + for (ConstAddressBlockIterator iter = AddressBlockBegin (); + iter != AddressBlockEnd (); + iter++) + { + (*iter)->Print (os, level+1); + } + os << prefix << "}" << std::endl; +} + +bool +Message::operator== (const Message &other) const +{ + if (GetAddressLength () != other.GetAddressLength ()) + return false; + + if (GetType () != other.GetType ()) + return false; + + if (HasOriginatorAddress () != other.HasOriginatorAddress ()) + return false; + + if (HasOriginatorAddress ()) + { + if (GetOriginatorAddress () != other.GetOriginatorAddress ()) + return false; + } + + if (HasHopLimit () != other.HasHopLimit ()) + return false; + + if (HasHopLimit ()) + { + if (GetHopLimit () != other.GetHopLimit ()) + return false; + } + + if (HasHopCount () != other.HasHopCount ()) + return false; + + if (HasHopCount ()) + { + if (GetHopCount () != other.GetHopCount ()) + return false; + } + + if (HasSequenceNumber () != other.HasSequenceNumber ()) + return false; + + if (HasSequenceNumber ()) + { + if (GetSequenceNumber () != other.GetSequenceNumber ()) + return false; + } + + if (m_tlvList != other.m_tlvList) + return false; + + if (AddressBlockSize () != other.AddressBlockSize ()) + return false; + + ConstAddressBlockIterator tai, oai; + for (tai = AddressBlockBegin (), oai = other.AddressBlockBegin (); + tai != AddressBlockEnd () && oai != other.AddressBlockEnd (); + tai++, oai++) + { + if (**tai != **oai) + return false; + } + return true; +} + +bool +Message::operator!= (const Message &other) const +{ + return !(*this == other); +} + +/* End Message Class */ + +AddressLength +MessageIpv4::GetAddressLength (void) const +{ + return IPV4; +} + +void +MessageIpv4::SerializeOriginatorAddress (Buffer::Iterator &start) const +{ + uint8_t buffer[GetAddressLength () + 1]; + Ipv4Address::ConvertFrom (GetOriginatorAddress ()).Serialize(buffer); + start.Write (buffer, GetAddressLength () + 1); +} + +Address +MessageIpv4::DeserializeOriginatorAddress (Buffer::Iterator &start) const +{ + uint8_t buffer[GetAddressLength () + 1]; + start.Read(buffer, GetAddressLength () + 1); + return Ipv4Address::Deserialize (buffer); +} + +void +MessageIpv4::PrintOriginatorAddress (std::ostream &os) const +{ + Ipv4Address::ConvertFrom (GetOriginatorAddress ()).Print (os); +} + +Ptr +MessageIpv4::AddressBlockDeserialize (Buffer::Iterator &start) const +{ + Ptr newab = Create (); + newab->Deserialize (start); + return newab; +} + +/* End MessageIpv4 Class */ + +AddressLength +MessageIpv6::GetAddressLength (void) const +{ + return IPV6; +} + +void +MessageIpv6::SerializeOriginatorAddress (Buffer::Iterator &start) const +{ + uint8_t buffer[GetAddressLength () + 1]; + Ipv6Address::ConvertFrom (GetOriginatorAddress ()).Serialize(buffer); + start.Write (buffer, GetAddressLength () + 1); +} + +Address +MessageIpv6::DeserializeOriginatorAddress (Buffer::Iterator &start) const +{ + uint8_t buffer[GetAddressLength () + 1]; + start.Read(buffer, GetAddressLength () + 1); + return Ipv6Address::Deserialize (buffer); +} + +void +MessageIpv6::PrintOriginatorAddress (std::ostream &os) const +{ + Ipv6Address::ConvertFrom (GetOriginatorAddress ()).Print (os); +} + +Ptr +MessageIpv6::AddressBlockDeserialize (Buffer::Iterator &start) const +{ + Ptr newab = Create (); + newab->Deserialize (start); + return newab; +} + +/* End MessageIpv6 Class */ + +AddressBlock::AddressBlock () +{ + m_refCount = 1; +} + +/* Manipulating the address block */ + +AddressBlock::AddressIterator +AddressBlock::AddressBegin (void) +{ + return m_addressList.begin(); +} + +AddressBlock::ConstAddressIterator +AddressBlock::AddressBegin (void) const +{ + return m_addressList.begin(); +} + +AddressBlock::AddressIterator +AddressBlock::AddressEnd (void) +{ + return m_addressList.end(); +} + +AddressBlock::ConstAddressIterator +AddressBlock::AddressEnd (void) const +{ + return m_addressList.end(); +} + +int +AddressBlock::AddressSize (void) const +{ + return m_addressList.size(); +} + +bool +AddressBlock::AddressEmpty (void) const +{ + return m_addressList.empty(); +} + +Address +AddressBlock::AddressFront (void) const +{ + return m_addressList.front(); +} + +Address +AddressBlock::AddressBack (void) const +{ + return m_addressList.back(); +} + +void +AddressBlock::AddressPushFront (Address tlv) +{ + m_addressList.push_front(tlv); +} + +void +AddressBlock::AddressPopFront (void) +{ + m_addressList.pop_front(); +} + +void +AddressBlock::AddressPushBack (Address tlv) +{ + m_addressList.push_back(tlv); +} + +void +AddressBlock::AddressPopBack (void) +{ + m_addressList.pop_back(); +} + +AddressBlock::AddressIterator +AddressBlock::AddressErase (AddressBlock::AddressIterator position) +{ + return m_addressList.erase(position); +} + +AddressBlock::AddressIterator +AddressBlock::AddressErase (AddressBlock::AddressIterator first, + AddressBlock::AddressIterator last) +{ + return m_addressList.erase(first, last); +} + + void +AddressBlock::AddressClear (void) +{ + return m_addressList.clear(); +} + +/* Manipulating the prefix list */ + +AddressBlock::PrefixIterator +AddressBlock::PrefixBegin (void) +{ + return m_prefixList.begin (); +} + +AddressBlock::ConstPrefixIterator +AddressBlock::PrefixBegin (void) const +{ + return m_prefixList.begin (); +} + +AddressBlock::PrefixIterator +AddressBlock::PrefixEnd (void) +{ + return m_prefixList.end (); +} + +AddressBlock::ConstPrefixIterator +AddressBlock::PrefixEnd (void) const +{ + return m_prefixList.end (); +} + +int +AddressBlock::PrefixSize (void) const +{ + return m_prefixList.size (); +} + +bool +AddressBlock::PrefixEmpty (void) const +{ + return m_prefixList.empty (); +} + +uint8_t +AddressBlock::PrefixFront (void) const +{ + return m_prefixList.front (); +} + +uint8_t +AddressBlock::PrefixBack (void) const +{ + return m_prefixList.back (); +} + +void +AddressBlock::PrefixPushFront (uint8_t prefix) +{ + m_prefixList.push_front (prefix); +} + +void +AddressBlock::PrefixPopFront (void) +{ + m_prefixList.pop_front (); +} + +void +AddressBlock::PrefixPushBack (uint8_t prefix) +{ + m_prefixList.push_back (prefix); +} + +void +AddressBlock::PrefixPopBack (void) +{ + m_prefixList.pop_back (); +} + +AddressBlock::PrefixIterator +AddressBlock::PrefixInsert (AddressBlock::PrefixIterator position, const uint8_t value) +{ + return m_prefixList.insert (position, value); +} + +AddressBlock::PrefixIterator +AddressBlock::PrefixErase (AddressBlock::PrefixIterator position) +{ + return m_prefixList.erase (position); +} + +AddressBlock::PrefixIterator +AddressBlock::PrefixErase (AddressBlock::PrefixIterator first, AddressBlock::PrefixIterator last) +{ + return m_prefixList.erase (first, last); +} + +void +AddressBlock::PrefixClear (void) +{ + m_prefixList.clear (); +} + +/* Manipulating the TLV block */ + +AddressBlock::TlvIterator +AddressBlock::TlvBegin (void) +{ + return m_addressTlvList.Begin(); +} + +AddressBlock::ConstTlvIterator +AddressBlock::TlvBegin (void) const +{ + return m_addressTlvList.Begin(); +} + +AddressBlock::TlvIterator +AddressBlock::TlvEnd (void) +{ + return m_addressTlvList.End(); +} + +AddressBlock::ConstTlvIterator +AddressBlock::TlvEnd (void) const +{ + return m_addressTlvList.End(); +} + +int +AddressBlock::TlvSize (void) const +{ + return m_addressTlvList.Size(); +} + +bool +AddressBlock::TlvEmpty (void) const +{ + return m_addressTlvList.Empty(); +} + +Ptr +AddressBlock::TlvFront (void) +{ + return m_addressTlvList.Front(); +} + +const Ptr +AddressBlock::TlvFront (void) const +{ + return m_addressTlvList.Front(); +} + +Ptr +AddressBlock::TlvBack (void) +{ + return m_addressTlvList.Back(); +} + +const Ptr +AddressBlock::TlvBack (void) const +{ + return m_addressTlvList.Back(); +} + +void +AddressBlock::TlvPushFront (Ptr tlv) +{ + m_addressTlvList.PushFront(tlv); +} + +void +AddressBlock::TlvPopFront (void) +{ + m_addressTlvList.PopFront(); +} + +void +AddressBlock::TlvPushBack (Ptr tlv) +{ + m_addressTlvList.PushBack(tlv); +} + +void +AddressBlock::TlvPopBack (void) +{ + m_addressTlvList.PopBack(); +} + +AddressBlock::TlvIterator +AddressBlock::TlvErase (AddressBlock::TlvIterator position) +{ + return m_addressTlvList.Erase(position); +} + +AddressBlock::TlvIterator +AddressBlock::TlvErase (AddressBlock::TlvIterator first, + AddressBlock::TlvIterator last) +{ + return m_addressTlvList.Erase(first, last); +} + +void +AddressBlock::TlvClear (void) +{ + return m_addressTlvList.Clear(); +} + +void +AddressBlock::Ref (void) const +{ + m_refCount++; +} + +void +AddressBlock::Unref (void) const +{ + m_refCount--; + if (m_refCount == 0) + { + delete this; + } +} + +uint32_t +AddressBlock::GetSerializedSize (void) const +{ + /* num-addr + flags */ + uint32_t size = 2; + + if (AddressSize () == 1) + { + size += GetAddressLength () + PrefixSize(); + } + else if (AddressSize () > 0) + { + uint8_t head[GetAddressLength ()]; + uint8_t headlen = 0; + uint8_t tail[GetAddressLength ()]; + uint8_t taillen = 0; + + GetHeadTail (head, headlen, tail, taillen); + + if (headlen > 0) + size += 1 + headlen; + + if (taillen > 0) + { + size++; + if (!HasZeroTail (tail, taillen)) + size += taillen; + } + + /* mid size */ + size += (GetAddressLength () - headlen - taillen) * AddressSize (); + + size += PrefixSize (); + } + + size += m_addressTlvList.GetSerializedSize (); + + return size; +} + +void +AddressBlock::Serialize (Buffer::Iterator &start) const +{ + start.WriteU8 (AddressSize ()); + + if (AddressSize () == 1) { + start.WriteU8 (0); + + uint8_t buf[GetAddressLength ()]; + SerializeAddress (buf, AddressBegin ()); + start.Write (buf, GetAddressLength ()); + + if (PrefixSize () == 1) + start.WriteU8 (PrefixFront ()); + } + else if (AddressSize () > 0) + { + Buffer::Iterator bufref = start; + uint8_t flags = 0; + start.Next (); + + uint8_t head[GetAddressLength ()]; + uint8_t tail[GetAddressLength ()]; + uint8_t headlen = 0; + uint8_t taillen = 0; + + GetHeadTail (head, headlen, tail, taillen); + + if (headlen > 0) + { + flags |= AHAS_HEAD; + start.WriteU8 (headlen); + start.Write (head, headlen); + } + + if (taillen > 0) + { + start.WriteU8 (taillen); + + if (HasZeroTail (tail, taillen)) + { + flags |= AHAS_ZERO_TAIL; + } + else + { + flags |= AHAS_FULL_TAIL; + start.Write (tail, taillen); + } + } + + if (headlen + taillen < GetAddressLength ()) + { + uint8_t mid[GetAddressLength ()]; + for (AddressBlock::ConstAddressIterator iter = AddressBegin (); + iter != AddressEnd (); + iter++) + { + SerializeAddress (mid, iter); + start.Write (mid + headlen, GetAddressLength () - headlen - taillen); + } + } + + flags |= GetPrefixFlags (); + bufref.WriteU8 (flags); + + for (ConstPrefixIterator iter = PrefixBegin (); + iter != PrefixEnd (); + iter++) + { + start.WriteU8 (*iter); + } + } + + m_addressTlvList.Serialize (start); +} + +void +AddressBlock::Deserialize (Buffer::Iterator &start) +{ + uint8_t numaddr = start.ReadU8 (); + uint8_t flags = start.ReadU8 (); + + if (numaddr > 0) + { + uint8_t headlen = 0; + uint8_t taillen = 0; + uint8_t addrtmp[GetAddressLength ()]; + memset(addrtmp, 0, GetAddressLength ()); + + if (flags & AHAS_HEAD) + { + headlen = start.ReadU8 (); + start.Read (addrtmp, headlen); + } + + if ((flags & AHAS_FULL_TAIL) ^ (flags & AHAS_ZERO_TAIL)) + { + taillen = start.ReadU8 (); + + if (flags & AHAS_FULL_TAIL) + { + start.Read (addrtmp + GetAddressLength () - taillen, taillen); + } + } + + for (int i = 0; i < numaddr; i++) + { + start.Read (addrtmp + headlen, GetAddressLength () - headlen - taillen); + AddressPushBack (DeserializeAddress (addrtmp)); + } + + if (flags & AHAS_SINGLE_PRE_LEN) + { + PrefixPushBack (start.ReadU8 ()); + } + else if (flags & AHAS_MULTI_PRE_LEN) + { + for (int i = 0; i < numaddr; i++) + { + PrefixPushBack (start.ReadU8 ()); + } + } + } + + m_addressTlvList.Deserialize (start); +} + +void +AddressBlock::Print (std::ostream &os) const +{ + Print (os, 0); +} + +void +AddressBlock::Print (std::ostream &os, int level) const +{ + std::string prefix = ""; + for (int i = 0; i < level; i++) + prefix.append ("\t"); + + os << prefix << "AddressBlock {" << std::endl; + os << prefix << "\taddresses = " << std::endl; + for (ConstAddressIterator iter = AddressBegin (); + iter != AddressEnd (); + iter++) + { + os << prefix << "\t\t"; + PrintAddress(os, iter); + os << std::endl; + } + + os << prefix << "\tprefixes = " << std::endl; + for (ConstPrefixIterator iter = PrefixBegin (); + iter != PrefixEnd (); + iter++) + { + os << prefix << "\t\t" << (int)(*iter) << std::endl; + } + + m_addressTlvList.Print (os, level+1); +} + +bool +AddressBlock::operator== (const AddressBlock &other) const +{ + if (AddressSize () != other.AddressSize ()) + return false; + + ConstAddressIterator tai, oai; + for (tai = AddressBegin (), oai = other.AddressBegin (); + tai != AddressEnd () && oai != other.AddressEnd (); + tai++, oai++) + { + if (*tai != *oai) + return false; + } + + if (PrefixSize () != other.PrefixSize ()) + return false; + + ConstPrefixIterator tpi, opi; + for (tpi = PrefixBegin (), opi = other.PrefixBegin (); + tpi != PrefixEnd () && opi != other.PrefixEnd (); + tpi++, opi++) + { + if (*tpi != *opi) + return false; + } + + if (m_addressTlvList != other.m_addressTlvList) + return false; + + return true; +} + +bool +AddressBlock::operator!= (const AddressBlock &other) const +{ + return !(*this == other); +} + +uint8_t +AddressBlock::GetPrefixFlags (void) const +{ + switch (PrefixSize ()) + { + case 0: + return 0; + break; + case 1: + return AHAS_SINGLE_PRE_LEN; + break; + default: + return AHAS_MULTI_PRE_LEN; + break; + } +} + +void +AddressBlock::GetHeadTail (uint8_t *head, uint8_t &headlen, + uint8_t *tail, uint8_t &taillen) const +{ + headlen = GetAddressLength (); + taillen = headlen; + + /* Temporary automatic buffers to store serialized addresses */ + uint8_t * buflast = new uint8_t[GetAddressLength ()]; + uint8_t * bufcur = new uint8_t[GetAddressLength ()]; + uint8_t * tmp; + + SerializeAddress (buflast, AddressBegin ()); + + /* Skip the first item */ + for (AddressBlock::ConstAddressIterator iter = AddressBegin ()++; + iter != AddressEnd (); + iter++) + { + SerializeAddress (bufcur, iter); + + int i; + for (i = 0; i < headlen; i++) + { + if (buflast[i] != bufcur[i]) + { + headlen = i; + break; + } + } + + /* If headlen == fulllen - 1, then tail is 0 */ + if (headlen <= GetAddressLength () - 1) + { + for (i = GetAddressLength () - 1; + GetAddressLength () - 1 - i <= taillen && i > headlen; + i--) + { + if (buflast[i] != bufcur[i]) + break; + } + taillen = GetAddressLength () - 1 - i; + } + else if (headlen == 0) + { + taillen = 0; + break; + } + + tmp = buflast; + buflast = bufcur; + bufcur = tmp; + } + + memcpy(head, bufcur, headlen); + memcpy(tail, bufcur + (GetAddressLength () - taillen), taillen); + + delete[] buflast; + delete[] bufcur; +} + +bool +AddressBlock::HasZeroTail (const uint8_t *tail, uint8_t taillen) const +{ + int i; + for (i = 0; i < taillen; i++) + { + if (tail[i] != 0) + break; + } + return i == taillen; +} + +/* End AddressBlock Class */ + +uint8_t +AddressBlockIpv4::GetAddressLength (void) const +{ + return 4; +} + +void +AddressBlockIpv4::SerializeAddress (uint8_t *buffer, ConstAddressIterator iter) const +{ + Ipv4Address::ConvertFrom (*iter).Serialize (buffer); +} + +Address +AddressBlockIpv4::DeserializeAddress (uint8_t *buffer) const +{ + return Ipv4Address::Deserialize (buffer); +} + +void +AddressBlockIpv4::PrintAddress (std::ostream &os, ConstAddressIterator iter) const +{ + Ipv4Address::ConvertFrom (*iter).Print (os); +} + +/* End AddressBlockIpv4 Class */ + +uint8_t +AddressBlockIpv6::GetAddressLength (void) const +{ + return 16; +} + +void +AddressBlockIpv6::SerializeAddress (uint8_t *buffer, ConstAddressIterator iter) const +{ + Ipv6Address::ConvertFrom (*iter).Serialize (buffer); +} + +Address +AddressBlockIpv6::DeserializeAddress (uint8_t *buffer) const +{ + return Ipv6Address::Deserialize (buffer); +} + +void +AddressBlockIpv6::PrintAddress (std::ostream &os, ConstAddressIterator iter) const +{ + Ipv6Address::ConvertFrom (*iter).Print (os); +} + +/* End AddressBlockIpv6 Class */ + +Tlv::Tlv (void) +{ + m_refCount = 1; + m_hasTypeExt = false; + m_hasIndexStart = false; + m_hasIndexStop = false; + m_isMultivalue = false; + m_hasValue = false; +} + +void +Tlv::SetType (uint8_t type) +{ + m_type = type; +} + +uint8_t +Tlv::GetType (void) const +{ + return m_type; +} + +void +Tlv::SetTypeExt (uint8_t typeExt) +{ + m_typeExt = typeExt; + m_hasTypeExt = true; +} + +uint8_t +Tlv::GetTypeExt (void) const throw (PacketBBError) +{ + if (!HasTypeExt()) + { + throw PacketBBError ("TLV has no type extension."); + } + return m_typeExt; +} + +bool +Tlv::HasTypeExt (void) const +{ + return m_hasTypeExt; +} + +void +Tlv::SetIndexStart (uint8_t index) +{ + m_indexStart = index; + m_hasIndexStart = true; +} + +uint8_t +Tlv::GetIndexStart (void) const throw (PacketBBError) +{ + if (!HasIndexStart()) + { + throw PacketBBError ("TLV has no start index."); + } + return m_indexStart; +} + +bool +Tlv::HasIndexStart (void) const +{ + return m_hasIndexStart; +} + +void +Tlv::SetIndexStop (uint8_t index) +{ + m_indexStop = index; + m_hasIndexStop = true; +} + +uint8_t +Tlv::GetIndexStop (void) const throw (PacketBBError) +{ + if (!HasIndexStop()) + { + throw PacketBBError ("TLV has no stop index."); + } + return m_indexStop; +} + +bool +Tlv::HasIndexStop (void) const +{ + return m_hasIndexStop; +} + +void +Tlv::SetMultivalue (bool isMultivalue) +{ + m_isMultivalue = isMultivalue; +} + +bool +Tlv::IsMultivalue (void) const +{ + return m_isMultivalue; +} + +void +Tlv::SetValue (Buffer start) +{ + m_hasValue = true; + m_value = start; +} + +void +Tlv::SetValue (const uint8_t * buffer, uint32_t size) +{ + Buffer value; + value.AddAtStart (size); + value.Begin ().Write (buffer, size); + SetValue (value); +} + +Buffer +Tlv::GetValue (void) const throw (PacketBBError) +{ + if (!HasValue ()) + { + throw PacketBBError ("TLV has no value."); + } + return m_value; +} + +bool +Tlv::HasValue (void) const +{ + return m_hasValue; +} + +void +Tlv::Ref (void) const +{ + m_refCount++; +} + +void +Tlv::Unref (void) const +{ + m_refCount--; + if (m_refCount == 0) + { + delete this; + } +} + +uint32_t +Tlv::GetSerializedSize (void) const +{ + /* type + flags */ + uint32_t size = 2; + + if (HasTypeExt ()) { + size++; + } + + if (HasIndexStart ()) { + size++; + } + + if (HasIndexStop ()) { + size++; + } + + if (HasValue ()) + { + if (GetValue ().GetSize () > 255) { + size += 2; + } else { + size++; + } + size += GetValue ().GetSize (); + } + + return size; +} + +void +Tlv::Serialize (Buffer::Iterator &start) const +{ + start.WriteU8 (GetType ()); + + Buffer::Iterator bufref = start; + uint8_t flags = 0; + start.Next(); + + if (HasTypeExt()) + { + flags |= THAS_TYPE_EXT; + start.WriteU8 (GetTypeExt ()); + } + + if (HasIndexStart ()) + { + start.WriteU8 (GetIndexStart ()); + + if (HasIndexStop ()) + { + flags |= THAS_MULTI_INDEX; + start.WriteU8 (GetIndexStop ()); + } + else + { + flags |= THAS_SINGLE_INDEX; + } + } + + if (HasValue ()) { + flags |= THAS_VALUE; + + uint32_t size = GetValue ().GetSize (); + if (size > 255) + { + flags |= THAS_EXT_LEN; + start.WriteHtonU16 (size); + } + else + { + start.WriteU8 (size); + } + + if (IsMultivalue ()) + flags |= TIS_MULTIVALUE; + + start.Write(GetValue ().Begin (), GetValue ().End ()); + } + + bufref.WriteU8 (flags); +} + +void +Tlv::Deserialize (Buffer::Iterator &start) +{ + SetType (start.ReadU8 ()); + + uint8_t flags = start.ReadU8 (); + + if (flags & THAS_TYPE_EXT) + SetTypeExt (start.ReadU8 ()); + + if (flags & THAS_MULTI_INDEX) + { + SetIndexStart (start.ReadU8 ()); + SetIndexStop (start.ReadU8 ()); + } + else if (flags & THAS_SINGLE_INDEX) + { + SetIndexStart (start.ReadU8 ()); + } + + if (flags & THAS_VALUE) + { + uint16_t len = 0; + + if (flags & THAS_EXT_LEN) + len = start.ReadNtohU16 (); + else + len = start.ReadU8 (); + + m_value.AddAtStart (len); + + Buffer::Iterator valueStart = start; + start.Next (len); + m_value.Begin ().Write (valueStart, start); + m_hasValue = true; + } +} + +void +Tlv::Print (std::ostream &os) const +{ + Print (os, 0); +} + +void +Tlv::Print (std::ostream &os, int level) const +{ + std::string prefix = ""; + for (int i = 0; i < level; i++) + prefix.append ("\t"); + + os << prefix << "Tlv {" << std::endl; + os << prefix << "\ttype = " << (int)GetType () << std::endl; + + if (HasTypeExt ()) + os << prefix << "\ttypeext = " << (int)GetTypeExt () << std::endl; + + if (HasIndexStart ()) + os << prefix << "\tindexStart = " << (int)GetIndexStart () << std::endl; + + if (HasIndexStop ()) + os << prefix << "\tindexStop = " << (int)GetIndexStop () << std::endl; + + os << prefix << "\tisMultivalue = " << IsMultivalue () << std::endl; + + if (HasValue ()) + os << prefix << "\thas value; size = " << GetValue (). GetSize () << std::endl; + + os << prefix << "}" << std::endl; +} + +bool +Tlv::operator== (const Tlv &other) const +{ + if (GetType () != other.GetType ()) + return false; + + if (HasTypeExt () != other.HasTypeExt ()) + return false; + + if (HasTypeExt ()) + { + if (GetTypeExt () != other.GetTypeExt ()) + return false; + } + + if (HasValue () != other.HasValue ()) + return false; + + if (HasValue ()) + { + Buffer tv = GetValue (); + Buffer ov = other.GetValue (); + if (tv.GetSize () != ov.GetSize ()) + return false; + + /* The docs say I probably shouldn't use Buffer::PeekData, but I think it + * is justified in this case. */ + if (memcmp (tv.PeekData (), ov.PeekData (), tv.GetSize ()) != 0) + return false; + } + return true; +} + +bool +Tlv::operator!= (const Tlv &other) const +{ + return !(*this == other); +} + +/* End Tlv Class */ + +void +AddressTlv::SetIndexStart (uint8_t index) +{ + Tlv::SetIndexStart (index); +} + +uint8_t +AddressTlv::GetIndexStart (void) const throw (PacketBBError) +{ + return Tlv::GetIndexStart (); +} + +bool +AddressTlv::HasIndexStart (void) const +{ + return Tlv::HasIndexStart (); +} + +void +AddressTlv::SetIndexStop (uint8_t index) +{ + Tlv::SetIndexStop (index); +} + +uint8_t +AddressTlv::GetIndexStop (void) const throw (PacketBBError) +{ + return Tlv::GetIndexStop (); +} + +bool +AddressTlv::HasIndexStop (void) const +{ + return Tlv::HasIndexStop (); +} + +void +AddressTlv::SetMultivalue (bool isMultivalue) +{ + Tlv::SetMultivalue (isMultivalue); +} + +bool +AddressTlv::IsMultivalue (void) const +{ + return Tlv::IsMultivalue (); +} + +} /* namespace pbb */ + +} /* namespace ns3 */ diff --git a/src/contrib/packetbb.h b/src/contrib/packetbb.h new file mode 100644 index 000000000..e86f71862 --- /dev/null +++ b/src/contrib/packetbb.h @@ -0,0 +1,617 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* vim: set ts=2 sw=2 expandtab: */ +/* + * Copyright (c) 2009 Drexel University + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Tom Wambold + */ +/* These classes implement RFC 5444 - The Generalized Mobile Ad Hoc Network + * (MANET) Packet/Message Format + * See: http://tools.ietf.org/html/rfc5444 for details */ + +#ifndef PACKETBB_H +#define PACKETBB_H + +#include +#include + +#include "ns3/ptr.h" +#include "ns3/address.h" +#include "ns3/header.h" +#include "ns3/buffer.h" + +namespace ns3 { + +namespace pbb { + +/* Forward declare objects */ +class PacketBB; +class Message; +class AddressBlock; +class TlvBlock; +class AddressTlvBlock; +class Tlv; +class AddressTlv; + +enum AddressLength { + IPV4 = 3, + IPV6 = 15, +}; + +class PacketBBError : public std::runtime_error { +public: + PacketBBError(const std::string &arg) : std::runtime_error(arg) {} +}; + +class TlvBlock +{ +public: + typedef std::list< Ptr >::iterator Iterator; + typedef std::list< Ptr >::const_iterator ConstIterator; + + Iterator Begin (void); + ConstIterator Begin (void) const; + Iterator End (void); + ConstIterator End (void) const; + + int Size (void) const; + bool Empty (void) const; + + Ptr Front (void) const; + Ptr Back (void) const; + + void PushFront (Ptr tlv); + void PopFront (void); + + void PushBack (Ptr tlv); + void PopBack (void); + + Iterator Insert (Iterator position, const Ptr tlv); + + Iterator Erase (Iterator position); + Iterator Erase (Iterator first, Iterator last); + + void Clear (void); + + uint32_t GetSerializedSize (void) const; + void Serialize (Buffer::Iterator &start) const; + void Deserialize (Buffer::Iterator &start); + void Print (std::ostream &os) const; + void Print (std::ostream &os, int level) const; + + bool operator== (const TlvBlock &other) const; + bool operator!= (const TlvBlock &other) const; + +private: + std::list< Ptr > m_tlvList; +}; + +class AddressTlvBlock +{ +public: + typedef std::list< Ptr >::iterator Iterator; + typedef std::list< Ptr >::const_iterator ConstIterator; + + Iterator Begin (void); + ConstIterator Begin (void) const; + Iterator End (void); + ConstIterator End (void) const; + + int Size (void) const; + bool Empty (void) const; + + Ptr Front (void) const; + Ptr Back (void) const; + + void PushFront (Ptr tlv); + void PopFront (void); + + void PushBack (Ptr tlv); + void PopBack (void); + + Iterator Insert (Iterator position, const Ptr tlv); + + Iterator Erase (Iterator position); + Iterator Erase (Iterator first, Iterator last); + + void Clear (void); + + uint32_t GetSerializedSize (void) const; + void Serialize (Buffer::Iterator &start) const; + void Deserialize (Buffer::Iterator &start); + void Print (std::ostream &os) const; + void Print (std::ostream &os, int level) const; + + bool operator== (const AddressTlvBlock &other) const; + bool operator!= (const AddressTlvBlock &other) const; + +private: + std::list< Ptr > m_tlvList; +}; + +/** Top level PacketBB packet object */ +class PacketBB : public Header +{ +public: + typedef std::list< Ptr >::iterator TlvIterator; + typedef std::list< Ptr >::const_iterator ConstTlvIterator; + typedef std::list< Ptr >::iterator MessageIterator; + typedef std::list< Ptr >::const_iterator ConstMessageIterator; + + PacketBB (void); + + uint8_t GetVersion (void) const; + + void SetSequenceNumber (uint16_t number); + uint16_t GetSequenceNumber (void) const throw (PacketBBError); + bool HasSequenceNumber (void) const; + + /* Manipulating Packet TLVs */ + + TlvIterator TlvBegin (void); + ConstTlvIterator TlvBegin (void) const; + TlvIterator TlvEnd (void); + ConstTlvIterator TlvEnd (void) const; + + int TlvSize (void) const; + bool TlvEmpty (void) const; + + Ptr TlvFront (void); + const Ptr TlvFront (void) const; + Ptr TlvBack (void); + const Ptr TlvBack (void) const; + + void TlvPushFront (Ptr); + void TlvPopFront (void); + void TlvPushBack (Ptr); + void TlvPopBack (void); + + TlvIterator Erase (TlvIterator position); + TlvIterator Erase (TlvIterator first, TlvIterator last); + void TlvClear (void); + + /* Manipulating Packet Messages */ + + MessageIterator MessageBegin (void); + ConstMessageIterator MessageBegin (void) const; + MessageIterator MessageEnd (void); + ConstMessageIterator MessageEnd (void) const; + + int MessageSize (void) const; + bool MessageEmpty (void) const; + + Ptr MessageFront (void); + const Ptr MessageFront (void) const; + Ptr MessageBack (void); + const Ptr MessageBack (void) const; + + void MessagePushFront (Ptr message); + void MessagePopFront (void); + void MessagePushBack (Ptr message); + void MessagePopBack (void); + + MessageIterator Erase (MessageIterator position); + MessageIterator Erase (MessageIterator first, MessageIterator last); + void MessageClear (void); + + /* Smart pointer methods */ + void Ref (void) const; + void Unref (void) const; + + /* Methods implemented by all headers */ + static TypeId GetTypeId (void); + virtual TypeId GetInstanceTypeId (void) const; + virtual uint32_t GetSerializedSize (void) const; + virtual void Serialize (Buffer::Iterator start) const; + virtual uint32_t Deserialize (Buffer::Iterator start); + virtual void Print (std::ostream &os) const; + + bool operator== (const PacketBB &other) const; + bool operator!= (const PacketBB &other) const; + +protected: + void SerializePacketTlv (Buffer::Iterator &start) const; + +private: + TlvBlock m_tlvList; + std::list< Ptr > m_messageList; + + uint8_t m_version; + + bool m_hasseqnum; + uint16_t m_seqnum; + + mutable uint32_t m_refCount; +}; + +class Message +{ +public: + typedef std::list< Ptr >::iterator TlvIterator; + typedef std::list< Ptr >::const_iterator ConstTlvIterator; + typedef std::list< Ptr >::iterator AddressBlockIterator; + typedef std::list< Ptr >::const_iterator ConstAddressBlockIterator; + + Message (void); + + void SetType (uint8_t type); + uint8_t GetType (void) const; + + void SetOriginatorAddress (Address address); + Address GetOriginatorAddress (void) const throw (PacketBBError); + bool HasOriginatorAddress (void) const; + + void SetHopLimit (uint8_t hoplimit); + uint8_t GetHopLimit (void) const throw (PacketBBError); + bool HasHopLimit (void) const; + + void SetHopCount (uint8_t hopcount); + uint8_t GetHopCount (void) const throw (PacketBBError); + bool HasHopCount (void) const; + + void SetSequenceNumber (uint16_t seqnum); + uint16_t GetSequenceNumber (void) const throw (PacketBBError); + bool HasSequenceNumber (void) const; + + /* Manipulating Message TLVs */ + + TlvIterator TlvBegin (); + ConstTlvIterator TlvBegin () const; + TlvIterator TlvEnd (); + ConstTlvIterator TlvEnd () const; + + int TlvSize (void) const; + bool TlvEmpty (void) const; + + Ptr TlvFront (void); + const Ptr TlvFront (void) const; + Ptr TlvBack (void); + const Ptr TlvBack (void) const; + + void TlvPushFront (Ptr tlv); + void TlvPopFront (void); + void TlvPushBack (Ptr tlv); + void TlvPopBack (void); + + TlvIterator TlvErase (TlvIterator position); + TlvIterator TlvErase (TlvIterator first, TlvIterator last); + void TlvClear (void); + + /* Manipulating Address Block and Address TLV pairs */ + + AddressBlockIterator AddressBlockBegin (); + ConstAddressBlockIterator AddressBlockBegin () const; + AddressBlockIterator AddressBlockEnd (); + ConstAddressBlockIterator AddressBlockEnd () const; + + int AddressBlockSize (void) const; + bool AddressBlockEmpty (void) const; + + Ptr AddressBlockFront (void); + const Ptr AddressBlockFront (void) const; + Ptr AddressBlockBack (void); + const Ptr AddressBlockBack (void) const; + + void AddressBlockPushFront (Ptr block); + void AddressBlockPopFront (void); + void AddressBlockPushBack (Ptr block); + void AddressBlockPopBack (void); + + AddressBlockIterator AddressBlockErase (AddressBlockIterator position); + AddressBlockIterator AddressBlockErase (AddressBlockIterator first, + AddressBlockIterator last); + void AddressBlockClear (void); + + /* Smart pointer methods */ + void Ref (void) const; + void Unref (void) const; + + static Ptr DeserializeMessage (Buffer::Iterator &start) throw (PacketBBError); + uint32_t GetSerializedSize (void) const; + void Serialize (Buffer::Iterator &start) const; + void Deserialize (Buffer::Iterator &start); + void Print (std::ostream &os) const; + void Print (std::ostream &os, int level) const; + + bool operator== (const Message &other) const; + bool operator!= (const Message &other) const; + +protected: + /* Message size in bytes - 1. + * + * IPv4 = 4 - 1 = 3, IPv6 = 16 - 1 = 15 + */ + virtual AddressLength GetAddressLength (void) const = 0; + + virtual void SerializeOriginatorAddress (Buffer::Iterator &start) const = 0; + virtual Address DeserializeOriginatorAddress (Buffer::Iterator &start) const = 0; + virtual void PrintOriginatorAddress (std::ostream &os) const = 0; + + virtual Ptr AddressBlockDeserialize (Buffer::Iterator &start) const = 0; + +private: + TlvBlock m_tlvList; + std::list< Ptr > m_addressBlockList; + + uint8_t m_type; + AddressLength m_addrSize; + + bool m_hasOriginatorAddress; + Address m_originatorAddress; + + bool m_hasHopLimit; + uint8_t m_hopLimit; + + bool m_hasHopCount; + uint8_t m_hopCount; + + bool m_hasSequenceNumber; + uint16_t m_sequenceNumber; + + mutable uint32_t m_refCount; +}; + +class MessageIpv4 : public Message { +protected: + virtual AddressLength GetAddressLength (void) const; + + virtual void SerializeOriginatorAddress (Buffer::Iterator &start) const; + virtual Address DeserializeOriginatorAddress (Buffer::Iterator &start) const; + virtual void PrintOriginatorAddress (std::ostream &os) const; + + virtual Ptr AddressBlockDeserialize (Buffer::Iterator &start) const; +}; + +class MessageIpv6 : public Message { +protected: + virtual AddressLength GetAddressLength (void) const; + + virtual void SerializeOriginatorAddress (Buffer::Iterator &start) const; + virtual Address DeserializeOriginatorAddress (Buffer::Iterator &start) const; + virtual void PrintOriginatorAddress (std::ostream &os) const; + + virtual Ptr AddressBlockDeserialize (Buffer::Iterator &start) const; +}; + +/** This combines address blocks with their associated TLVs */ +class AddressBlock +{ +public: + typedef std::list< Address >::iterator AddressIterator; + typedef std::list< Address >::const_iterator ConstAddressIterator; + + typedef std::list::iterator PrefixIterator; + typedef std::list::const_iterator ConstPrefixIterator; + + typedef AddressTlvBlock::Iterator TlvIterator; + typedef AddressTlvBlock::ConstIterator ConstTlvIterator; + + AddressBlock (); + + /* Manipulating the address block */ + + AddressIterator AddressBegin (void); + ConstAddressIterator AddressBegin (void) const; + AddressIterator AddressEnd (void); + ConstAddressIterator AddressEnd (void) const; + + int AddressSize (void) const; + bool AddressEmpty (void) const; + + Address AddressFront (void) const; + Address AddressBack (void) const; + + void AddressPushFront (Address address); + void AddressPopFront (void); + + void AddressPushBack (Address address); + void AddressPopBack (void); + + AddressIterator AddressInsert (AddressIterator position, + const Address value); + + AddressIterator AddressErase (AddressIterator position); + AddressIterator AddressErase (AddressIterator first, AddressIterator last); + + void AddressClear (void); + + /* Prefix methods */ + PrefixIterator PrefixBegin (void); + ConstPrefixIterator PrefixBegin (void) const; + PrefixIterator PrefixEnd (void); + ConstPrefixIterator PrefixEnd (void) const; + + int PrefixSize (void) const; + bool PrefixEmpty (void) const; + + uint8_t PrefixFront (void) const; + uint8_t PrefixBack (void) const; + + void PrefixPushFront (uint8_t prefix); + void PrefixPopFront (void); + + void PrefixPushBack (uint8_t prefix); + void PrefixPopBack (void); + + PrefixIterator PrefixInsert (PrefixIterator position, const uint8_t value); + + PrefixIterator PrefixErase (PrefixIterator position); + PrefixIterator PrefixErase (PrefixIterator first, PrefixIterator last); + + void PrefixClear (void); + + /* Manipulating the TLV block */ + TlvIterator TlvBegin (void); + ConstTlvIterator TlvBegin (void) const; + TlvIterator TlvEnd (void); + ConstTlvIterator TlvEnd (void) const; + + int TlvSize (void) const; + bool TlvEmpty (void) const; + + Ptr TlvFront (void); + const Ptr TlvFront (void) const; + Ptr TlvBack (void); + const Ptr TlvBack (void) const; + + void TlvPushFront (Ptr address); + void TlvPopFront (void); + + void TlvPushBack (Ptr address); + void TlvPopBack (void); + + TlvIterator TlvInsert (TlvIterator position, const Ptr value); + + TlvIterator TlvErase (TlvIterator position); + TlvIterator TlvErase (TlvIterator first, TlvIterator last); + + void TlvClear (void); + + /* Smart pointer methods */ + void Ref (void) const; + void Unref (void) const; + + uint32_t GetSerializedSize (void) const; + void Serialize (Buffer::Iterator &start) const; + void Deserialize (Buffer::Iterator &start); + void Print (std::ostream &os) const; + void Print (std::ostream &os, int level) const; + + bool operator== (const AddressBlock &other) const; + bool operator!= (const AddressBlock &other) const; + +protected: + virtual uint8_t GetAddressLength (void) const = 0; + + virtual void SerializeAddress (uint8_t *buffer, ConstAddressIterator iter) const = 0; + virtual Address DeserializeAddress (uint8_t *buffer) const = 0; + virtual void PrintAddress (std::ostream &os, ConstAddressIterator iter) const = 0; + +private: + uint8_t GetPrefixFlags (void) const; + void GetHeadTail (uint8_t *head, uint8_t &headlen, + uint8_t *tail, uint8_t &taillen) const; + bool HasZeroTail (const uint8_t *tail, uint8_t taillen) const; + + std::list
m_addressList; + std::list m_prefixList; + AddressTlvBlock m_addressTlvList; + + mutable uint32_t m_refCount; +}; + +class AddressBlockIpv4 : public AddressBlock +{ +protected: + virtual uint8_t GetAddressLength (void) const; + + virtual void SerializeAddress (uint8_t *buffer, ConstAddressIterator iter) const; + virtual Address DeserializeAddress (uint8_t *buffer) const; + virtual void PrintAddress (std::ostream &os, ConstAddressIterator iter) const; +}; + +class AddressBlockIpv6 : public AddressBlock +{ +protected: + virtual uint8_t GetAddressLength (void) const; + + virtual void SerializeAddress (uint8_t *buffer, ConstAddressIterator iter) const; + virtual Address DeserializeAddress (uint8_t *buffer) const; + virtual void PrintAddress (std::ostream &os, ConstAddressIterator iter) const; +}; + +/** A packet or message TLV */ +class Tlv +{ +public: + Tlv (void); + + void SetType (uint8_t type); + uint8_t GetType (void) const; + + void SetTypeExt (uint8_t type); + uint8_t GetTypeExt (void) const throw (PacketBBError); + bool HasTypeExt (void) const; + + void SetValue (Buffer start); + void SetValue (const uint8_t * buffer, uint32_t size); + Buffer GetValue (void) const throw (PacketBBError); + bool HasValue (void) const; + + /* Smart pointer methods */ + void Ref (void) const; + void Unref (void) const; + + uint32_t GetSerializedSize (void) const; + void Serialize (Buffer::Iterator &start) const; + void Deserialize (Buffer::Iterator &start); + void Print (std::ostream &os) const; + void Print (std::ostream &os, int level) const; + + bool operator== (const Tlv &other) const; + bool operator!= (const Tlv &other) const; + +protected: + void SetIndexStart (uint8_t index); + uint8_t GetIndexStart (void) const throw (PacketBBError); + bool HasIndexStart (void) const; + + void SetIndexStop (uint8_t index); + uint8_t GetIndexStop (void) const throw (PacketBBError); + bool HasIndexStop (void) const; + + void SetMultivalue (bool isMultivalue); + bool IsMultivalue (void) const; + +private: + uint8_t m_type; + + bool m_hasTypeExt; + uint8_t m_typeExt; + + bool m_hasIndexStart; + uint8_t m_indexStart; + + bool m_hasIndexStop; + uint8_t m_indexStop; + + bool m_isMultivalue; + bool m_hasValue; + Buffer m_value; + + mutable uint32_t m_refCount; +}; + +class AddressTlv : public Tlv +{ +public: + void SetIndexStart (uint8_t index); + uint8_t GetIndexStart (void) const throw (PacketBBError); + bool HasIndexStart (void) const; + + void SetIndexStop (uint8_t index); + uint8_t GetIndexStop (void) const throw (PacketBBError); + bool HasIndexStop (void) const; + + void SetMultivalue (bool isMultivalue); + bool IsMultivalue (void) const; +}; + +} /* namespace pbb */ + +} /* namespace ns3 */ + +#endif /* PACKETBB_H */ diff --git a/src/contrib/test-packetbb.cc b/src/contrib/test-packetbb.cc new file mode 100644 index 000000000..35ac51339 --- /dev/null +++ b/src/contrib/test-packetbb.cc @@ -0,0 +1,3861 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* vim: set ts=2 sw=2 expandtab: */ +/* + * Copyright (c) 2009 Drexel University + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Tom Wambold + */ +/** TODO: Find out why msg-addr-length is set to 0 in tests */ + +#include + +#include "ns3/ptr.h" +#include "ns3/ipv4-address.h" +#include "ns3/ipv6-address.h" +#include "ns3/packetbb.h" + +using namespace std; +using namespace ns3; +using namespace ns3::pbb; + +class PacketBBTester +{ +public: + PacketBBTester (int testnum, PacketBB &reference, const uint8_t * buffer, uint32_t size) : + m_refPacket(reference) + { + m_refBuffer.AddAtStart (size); + m_refBuffer.Begin ().Write (buffer, size); + + cout << "Test " << testnum << " - "; + Test (); + } + + void Test (void) + { + if (TestSerialize ()) + cout << "Serialize Pass, "; + else + cout << "Serialize Fail, "; + + if (TestDeserialize ()) + cout << "Deserialize Pass, "; + else + cout << "Deserialize Fail, "; + + if (TestConsistency ()) + cout << "Consistency Pass" << endl; + else + cout << "Consistency Fail" << endl; + } + + bool TestSerialize (void) + { + Buffer newBuffer; + try + { + newBuffer.AddAtStart (m_refPacket.GetSerializedSize ()); + m_refPacket.Serialize (newBuffer.Begin ()); + } + catch (PacketBBError &e) + { + cout << endl << "Exception: " << e.what () << endl; + return false; + } + return CompareBuffers (m_refBuffer, newBuffer); + } + + bool TestDeserialize (void) + { + PacketBB newPacket; + try + { + newPacket.Deserialize (m_refBuffer.Begin ()); + } + catch (PacketBBError &e) + { + cout << endl << "Exception: " << e.what () << endl; + return false; + } + return m_refPacket == newPacket; + } + + bool TestConsistency (void) + { + Buffer newBuffer; + PacketBB newPacket; + try + { + newBuffer.AddAtStart (m_refPacket.GetSerializedSize ()); + m_refPacket.Serialize (newBuffer.Begin ()); + newPacket.Deserialize (newBuffer.Begin ()); + } + catch (PacketBBError &e) + { + cout << endl << "Exception: " << e.what () << endl; + return false; + } + return m_refPacket == newPacket; + } + + +private: + static bool CompareBuffers (Buffer a, Buffer b) + { + const uint8_t * abuf = a.PeekData (); + const uint8_t * bbuf = b.PeekData (); + + for (unsigned int i = 0; i < a.GetSize (); i++) + { + if (abuf[i] != bbuf[i]) + cout << "Difference - [" << i << "] - " << (int)abuf[i] << " - " << (int)bbuf[i] << endl; + } + + if (a.GetSize () != b.GetSize ()) + { + cout << "Buffers differ in size: " << a.GetSize () << ", " << b.GetSize() << endl; + return false; + } + + if (memcmp (a.PeekData (), b.PeekData (), a.GetSize ()) != 0) + { + return false; + } + + return true; + } + + Buffer m_refBuffer; + PacketBB &m_refPacket; +}; + +int main (void) +{ + /* These tests are from: + * http://interop08.thomasclausen.org/packets-and-dumps.txt + */ + int testnum = 1; + + /* Test 1 + * ,------------------ + * | PACKET + * |------------------ + * | * Packet version: 0 + * | * Packet flags: 0 + * `------------------ + */ + { + PacketBB packet; + uint8_t buffer[] = {0x00}; + PacketBBTester test(testnum++, packet, buffer, sizeof(buffer)); + } + + /* Test 2 + * ,------------------ + * | PACKET + * |------------------ + * | * Packet version: 0 + * | * Packet flags: 8 + * | * Packet seq number: 2 + * `------------------ + */ + { + PacketBB packet; + packet.SetSequenceNumber (2); + uint8_t buffer[] = {0x08, 0x00, 0x02}; + PacketBBTester test(testnum++, packet, buffer, sizeof(buffer)); + } + + /* Test 3 + * ,------------------ + * | PACKET + * |------------------ + * | * Packet version: 0 + * | * Packet flags: 12 + * | * Packet seq number: 3 + * `------------------ + * This test has the phastlv flag set to 1 with no tlvs. + * I'll come back to this one later. + { + PacketBB packet; + packet.SetSequenceNumber (3); + uint8_t buffer[] = {0x0c, 0x00, 0x03, 0x00, 0x00}; + PacketBBTester test(testnum++, packet, buffer, sizeof(buffer)); + } + */ + std::cout << "Skipping test " << testnum++ << std::endl; + + /* Test 4 + * ,------------------ + * | PACKET + * |------------------ + * | * Packet version: 0 + * | * Packet flags: 12 + * | * Packet seq number: 4 + * | | * Packet TLV Block + * | | - TLV + * | | Flags = 0 + * | | Type = 1; Value = (warning: parameter is NULL) + * `------------------ + */ + { + PacketBB packet; + packet.SetSequenceNumber (4); + + Ptr tlv = Create(); + tlv->SetType (1); + + packet.TlvPushBack (tlv); + uint8_t buffer[] = { + 0x0c, 0x00, 0x04, 0x00, + 0x02, 0x01, 0x00 + }; + PacketBBTester test(testnum++, packet, buffer, sizeof(buffer)); + } + + /* Test 5 + * ,------------------ + * | PACKET + * |------------------ + * | * Packet version: 0 + * | * Packet flags: 12 + * | * Packet seq number: 5 + * | | * Packet TLV Block + * | | - TLV + * | | Flags = 0 + * | | Type = 1; Value = (warning: parameter is NULL) + * | | - TLV + * | | Flags = 128 + * | | Type = 2; Type ext. = 100; Value = (warning: parameter is NULL) + * `------------------ + */ + { + PacketBB packet; + packet.SetSequenceNumber (5); + + Ptr tlv1 = Create(); + tlv1->SetType (1); + packet.TlvPushBack (tlv1); + + Ptr tlv2 = Create(); + tlv2->SetType (2); + tlv2->SetTypeExt (100); + packet.TlvPushBack (tlv2); + + uint8_t buffer[] = { + 0x0c, 0x00, 0x05, 0x00, + 0x05, 0x01, 0x00, 0x02, + 0x80, 0x64 + }; + PacketBBTester test(testnum++, packet, buffer, sizeof(buffer)); + } + + /* Test 6 + * ,------------------ + * | PACKET + * |------------------ + * | * Packet version: 0 + * | * Packet flags: 12 + * | * Packet seq number: 6 + * | | * Packet TLV Block + * | | - TLV + * | | Flags = 0 + * | | Type = 1; Value = (warning: parameter is NULL) + * | | - TLV + * | | Flags = 144 + * | | Type = 2; Type ext. = 100; Value = 01 02 03 04 + * | | + * `------------------ + */ + { + PacketBB packet; + packet.SetSequenceNumber (6); + + Ptr tlv1 = Create(); + tlv1->SetType (1); + packet.TlvPushBack (tlv1); + + Ptr tlv2 = Create(); + tlv2->SetType (2); + tlv2->SetTypeExt (100); + + uint8_t tlv2val[] = {1, 2, 3, 4}; + tlv2->SetValue(tlv2val, sizeof(tlv2val)); + + packet.TlvPushBack (tlv2); + + uint8_t buffer[] = { + 0x0c, 0x00, 0x06, 0x00, + 0x0a, 0x01, 0x00, 0x02, + 0x90, 0x64, 0x04, 0x01, + 0x02, 0x03, 0x04 + }; + PacketBBTester test(testnum++, packet, buffer, sizeof(buffer)); + } + + /* Test 7 + * ,------------------ + * | PACKET + * |------------------ + * | * Packet version: 0 + * | * Packet flags: 12 + * | * Packet seq number: 7 + * | | * Packet TLV Block + * | | - TLV + * | | Flags = 0 + * | | Type = 1; Value = (warning: parameter is NULL) + * | | - TLV + * | | Flags = 152 + * | | Type = 2; Type ext. = 100; Value = 00 01 02 03 + * | | 04 05 06 07 + * | | 08 09 0a 0b + * | | 0c 0d 0e 0f + * | | 10 11 12 13 + * | | 14 15 16 17 + * | | 18 19 1a 1b + * | | 1c 1d 1e 1f + * | | 20 21 22 23 + * | | 24 25 26 27 + * | | 28 29 2a 2b + * | | 2c 2d 2e 2f + * | | 30 31 32 33 + * | | 34 35 36 37 + * | | 38 39 3a 3b + * | | 3c 3d 3e 3f + * | | 40 41 42 43 + * | | 44 45 46 47 + * | | 48 49 4a 4b + * | | 4c 4d 4e 4f + * | | 50 51 52 53 + * | | 54 55 56 57 + * | | 58 59 5a 5b + * | | 5c 5d 5e 5f + * | | 60 61 62 63 + * | | 64 65 66 67 + * | | 68 69 6a 6b + * | | 6c 6d 6e 6f + * | | 70 71 72 73 + * | | 74 75 76 77 + * | | 78 79 7a 7b + * | | 7c 7d 7e 7f + * | | 80 81 82 83 + * | | 84 85 86 87 + * | | 88 89 8a 8b + * | | 8c 8d 8e 8f + * | | 90 91 92 93 + * | | 94 95 96 97 + * | | 98 99 9a 9b + * | | 9c 9d 9e 9f + * | | a0 a1 a2 a3 + * | | a4 a5 a6 a7 + * | | a8 a9 aa ab + * | | ac ad ae af + * | | b0 b1 b2 b3 + * | | b4 b5 b6 b7 + * | | b8 b9 ba bb + * | | bc bd be bf + * | | c0 c1 c2 c3 + * | | c4 c5 c6 c7 + * | | c8 c9 ca cb + * | | cc cd ce cf + * | | d0 d1 d2 d3 + * | | d4 d5 d6 d7 + * | | d8 d9 da db + * | | dc dd de df + * | | e0 e1 e2 e3 + * | | e4 e5 e6 e7 + * | | e8 e9 ea eb + * | | ec ed ee ef + * | | f0 f1 f2 f3 + * | | f4 f5 f6 f7 + * | | f8 f9 fa fb + * | | fc fd fe 00 + * | | 01 02 03 04 + * | | 05 06 07 08 + * | | 09 0a 0b 0c + * | | 0d 0e 0f 10 + * | | 11 12 13 14 + * | | 15 16 17 18 + * | | 19 1a 1b 1c + * | | 1d 1e 1f 20 + * | | 21 22 23 24 + * | | 25 26 27 28 + * | | 29 2a 2b 2c + * | | + * `------------------ + */ + { + PacketBB packet; + packet.SetSequenceNumber (7); + + Ptr tlv1 = Create(); + tlv1->SetType (1); + packet.TlvPushBack (tlv1); + + Ptr tlv2 = Create(); + tlv2->SetType (2); + tlv2->SetTypeExt (100); + + uint8_t tlv2val[] = { + 0x00, 0x01, 0x02, 0x03, + 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, + 0x0c, 0x0d, 0x0e, 0x0f, + 0x10, 0x11, 0x12, 0x13, + 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1a, 0x1b, + 0x1c, 0x1d, 0x1e, 0x1f, + 0x20, 0x21, 0x22, 0x23, + 0x24, 0x25, 0x26, 0x27, + 0x28, 0x29, 0x2a, 0x2b, + 0x2c, 0x2d, 0x2e, 0x2f, + 0x30, 0x31, 0x32, 0x33, + 0x34, 0x35, 0x36, 0x37, + 0x38, 0x39, 0x3a, 0x3b, + 0x3c, 0x3d, 0x3e, 0x3f, + 0x40, 0x41, 0x42, 0x43, + 0x44, 0x45, 0x46, 0x47, + 0x48, 0x49, 0x4a, 0x4b, + 0x4c, 0x4d, 0x4e, 0x4f, + 0x50, 0x51, 0x52, 0x53, + 0x54, 0x55, 0x56, 0x57, + 0x58, 0x59, 0x5a, 0x5b, + 0x5c, 0x5d, 0x5e, 0x5f, + 0x60, 0x61, 0x62, 0x63, + 0x64, 0x65, 0x66, 0x67, + 0x68, 0x69, 0x6a, 0x6b, + 0x6c, 0x6d, 0x6e, 0x6f, + 0x70, 0x71, 0x72, 0x73, + 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7a, 0x7b, + 0x7c, 0x7d, 0x7e, 0x7f, + 0x80, 0x81, 0x82, 0x83, + 0x84, 0x85, 0x86, 0x87, + 0x88, 0x89, 0x8a, 0x8b, + 0x8c, 0x8d, 0x8e, 0x8f, + 0x90, 0x91, 0x92, 0x93, + 0x94, 0x95, 0x96, 0x97, + 0x98, 0x99, 0x9a, 0x9b, + 0x9c, 0x9d, 0x9e, 0x9f, + 0xa0, 0xa1, 0xa2, 0xa3, + 0xa4, 0xa5, 0xa6, 0xa7, + 0xa8, 0xa9, 0xaa, 0xab, + 0xac, 0xad, 0xae, 0xaf, + 0xb0, 0xb1, 0xb2, 0xb3, + 0xb4, 0xb5, 0xb6, 0xb7, + 0xb8, 0xb9, 0xba, 0xbb, + 0xbc, 0xbd, 0xbe, 0xbf, + 0xc0, 0xc1, 0xc2, 0xc3, + 0xc4, 0xc5, 0xc6, 0xc7, + 0xc8, 0xc9, 0xca, 0xcb, + 0xcc, 0xcd, 0xce, 0xcf, + 0xd0, 0xd1, 0xd2, 0xd3, + 0xd4, 0xd5, 0xd6, 0xd7, + 0xd8, 0xd9, 0xda, 0xdb, + 0xdc, 0xdd, 0xde, 0xdf, + 0xe0, 0xe1, 0xe2, 0xe3, + 0xe4, 0xe5, 0xe6, 0xe7, + 0xe8, 0xe9, 0xea, 0xeb, + 0xec, 0xed, 0xee, 0xef, + 0xf0, 0xf1, 0xf2, 0xf3, + 0xf4, 0xf5, 0xf6, 0xf7, + 0xf8, 0xf9, 0xfa, 0xfb, + 0xfc, 0xfd, 0xfe, 0x00, + 0x01, 0x02, 0x03, 0x04, + 0x05, 0x06, 0x07, 0x08, + 0x09, 0x0a, 0x0b, 0x0c, + 0x0d, 0x0e, 0x0f, 0x10, + 0x11, 0x12, 0x13, 0x14, + 0x15, 0x16, 0x17, 0x18, + 0x19, 0x1a, 0x1b, 0x1c, + 0x1d, 0x1e, 0x1f, 0x20, + 0x21, 0x22, 0x23, 0x24, + 0x25, 0x26, 0x27, 0x28, + 0x29, 0x2a, 0x2b, 0x2c + }; + tlv2->SetValue(tlv2val, sizeof(tlv2val)); + + packet.TlvPushBack (tlv2); + + uint8_t buffer[] = { + 0x0c, 0x00, 0x07, 0x01, + 0x33, 0x01, 0x00, 0x02, + 0x98, 0x64, 0x01, 0x2c, + 0x00, 0x01, 0x02, 0x03, + 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, + 0x0c, 0x0d, 0x0e, 0x0f, + 0x10, 0x11, 0x12, 0x13, + 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1a, 0x1b, + 0x1c, 0x1d, 0x1e, 0x1f, + 0x20, 0x21, 0x22, 0x23, + 0x24, 0x25, 0x26, 0x27, + 0x28, 0x29, 0x2a, 0x2b, + 0x2c, 0x2d, 0x2e, 0x2f, + 0x30, 0x31, 0x32, 0x33, + 0x34, 0x35, 0x36, 0x37, + 0x38, 0x39, 0x3a, 0x3b, + 0x3c, 0x3d, 0x3e, 0x3f, + 0x40, 0x41, 0x42, 0x43, + 0x44, 0x45, 0x46, 0x47, + 0x48, 0x49, 0x4a, 0x4b, + 0x4c, 0x4d, 0x4e, 0x4f, + 0x50, 0x51, 0x52, 0x53, + 0x54, 0x55, 0x56, 0x57, + 0x58, 0x59, 0x5a, 0x5b, + 0x5c, 0x5d, 0x5e, 0x5f, + 0x60, 0x61, 0x62, 0x63, + 0x64, 0x65, 0x66, 0x67, + 0x68, 0x69, 0x6a, 0x6b, + 0x6c, 0x6d, 0x6e, 0x6f, + 0x70, 0x71, 0x72, 0x73, + 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7a, 0x7b, + 0x7c, 0x7d, 0x7e, 0x7f, + 0x80, 0x81, 0x82, 0x83, + 0x84, 0x85, 0x86, 0x87, + 0x88, 0x89, 0x8a, 0x8b, + 0x8c, 0x8d, 0x8e, 0x8f, + 0x90, 0x91, 0x92, 0x93, + 0x94, 0x95, 0x96, 0x97, + 0x98, 0x99, 0x9a, 0x9b, + 0x9c, 0x9d, 0x9e, 0x9f, + 0xa0, 0xa1, 0xa2, 0xa3, + 0xa4, 0xa5, 0xa6, 0xa7, + 0xa8, 0xa9, 0xaa, 0xab, + 0xac, 0xad, 0xae, 0xaf, + 0xb0, 0xb1, 0xb2, 0xb3, + 0xb4, 0xb5, 0xb6, 0xb7, + 0xb8, 0xb9, 0xba, 0xbb, + 0xbc, 0xbd, 0xbe, 0xbf, + 0xc0, 0xc1, 0xc2, 0xc3, + 0xc4, 0xc5, 0xc6, 0xc7, + 0xc8, 0xc9, 0xca, 0xcb, + 0xcc, 0xcd, 0xce, 0xcf, + 0xd0, 0xd1, 0xd2, 0xd3, + 0xd4, 0xd5, 0xd6, 0xd7, + 0xd8, 0xd9, 0xda, 0xdb, + 0xdc, 0xdd, 0xde, 0xdf, + 0xe0, 0xe1, 0xe2, 0xe3, + 0xe4, 0xe5, 0xe6, 0xe7, + 0xe8, 0xe9, 0xea, 0xeb, + 0xec, 0xed, 0xee, 0xef, + 0xf0, 0xf1, 0xf2, 0xf3, + 0xf4, 0xf5, 0xf6, 0xf7, + 0xf8, 0xf9, 0xfa, 0xfb, + 0xfc, 0xfd, 0xfe, 0x00, + 0x01, 0x02, 0x03, 0x04, + 0x05, 0x06, 0x07, 0x08, + 0x09, 0x0a, 0x0b, 0x0c, + 0x0d, 0x0e, 0x0f, 0x10, + 0x11, 0x12, 0x13, 0x14, + 0x15, 0x16, 0x17, 0x18, + 0x19, 0x1a, 0x1b, 0x1c, + 0x1d, 0x1e, 0x1f, 0x20, + 0x21, 0x22, 0x23, 0x24, + 0x25, 0x26, 0x27, 0x28, + 0x29, 0x2a, 0x2b, 0x2c + }; + PacketBBTester test(testnum++, packet, buffer, sizeof(buffer)); + } + + /* Test 8 + * ,------------------ + * | PACKET + * |------------------ + * | * Packet version: 0 + * | * Packet flags: 12 + * | * Packet seq number: 8 + * | | * Packet TLV Block + * | | - TLV + * | | Flags = 0 + * | | Type = 1; Value = (warning: parameter is NULL) + * | ,------------------- + * | | MESSAGE + * | |------------------- + * | | * Message type: 1 + * | | * Message flags: 0 + * | `------------------- + * | + * `------------------ + */ + { + PacketBB packet; + packet.SetSequenceNumber (8); + + Ptr tlv1 = Create (); + tlv1->SetType (1); + packet.TlvPushBack (tlv1); + + Ptr msg1 = Create (); + msg1->SetType (1); + packet.MessagePushBack (msg1); + + uint8_t buffer[] = { + 0x0c, 0x00, 0x08, 0x00, + 0x02, 0x01, 0x00, 0x01, + 0x03, 0x00, 0x06, 0x00, + 0x00 + }; + PacketBBTester test(testnum++, packet, buffer, sizeof(buffer)); + } + + /* Test 9 + * ,------------------ + * | PACKET + * |------------------ + * | * Packet version: 0 + * | * Packet flags: 12 + * | * Packet seq number: 9 + * | | * Packet TLV Block + * | | - TLV + * | | Flags = 0 + * | | Type = 1; Value = (warning: parameter is NULL) + * | ,------------------- + * | | MESSAGE + * | |------------------- + * | | * Message type: 1 + * | | * Message flags: 0 + * | `------------------- + * | + * | ,------------------- + * | | MESSAGE + * | |------------------- + * | | * Message type: 2 + * | | * Message flags: 128 + * | | * Originator address: 10.0.0.1 + * | `------------------- + * | + * `------------------ + */ + { + PacketBB packet; + packet.SetSequenceNumber (9); + + Ptr tlv1 = Create (); + tlv1->SetType (1); + packet.TlvPushBack (tlv1); + + Ptr msg1 = Create (); + msg1->SetType (1); + packet.MessagePushBack (msg1); + + Ptr msg2 = Create (); + msg2->SetType (2); + msg2->SetOriginatorAddress(Ipv4Address("10.0.0.1")); + packet.MessagePushBack (msg2); + + uint8_t buffer[] = { + 0x0c, 0x00, 0x09, 0x00, + 0x02, 0x01, 0x00, 0x01, + 0x03, 0x00, 0x06, 0x00, + 0x00, 0x02, 0x83, 0x00, /* [14] used to be 0x80 */ + 0x0a, 0x0a, 0x00, 0x00, + 0x01, 0x00, 0x00 + }; + PacketBBTester test(testnum++, packet, buffer, sizeof(buffer)); + } + + /* Test 10 + * ,------------------ + * | PACKET + * |------------------ + * | * Packet version: 0 + * | * Packet flags: 12 + * | * Packet seq number: 10 + * | | * Packet TLV Block + * | | - TLV + * | | Flags = 0 + * | | Type = 1; Value = (warning: parameter is NULL) + * | ,------------------- + * | | MESSAGE + * | |------------------- + * | | * Message type: 1 + * | | * Message flags: 0 + * | `------------------- + * | + * | ,------------------- + * | | MESSAGE + * | |------------------- + * | | * Message type: 2 + * | | * Message flags: 160 + * | | * Originator address: 10.0.0.1 + * | | * Hop count: 1 + * | `------------------- + * | + * `------------------ + */ + { + PacketBB packet; + packet.SetSequenceNumber (10); + + Ptr tlv1 = Create (); + tlv1->SetType (1); + packet.TlvPushBack (tlv1); + + Ptr msg1 = Create (); + msg1->SetType (1); + packet.MessagePushBack (msg1); + + Ptr msg2 = Create (); + msg2->SetType (2); + msg2->SetOriginatorAddress(Ipv4Address("10.0.0.1")); + msg2->SetHopCount (1); + packet.MessagePushBack (msg2); + + uint8_t buffer[] = { + 0x0c, 0x00, 0x0a, 0x00, + 0x02, 0x01, 0x00, 0x01, + 0x03, 0x00, 0x06, 0x00, + 0x00, 0x02, 0xa3, 0x00, /* [14] used to be 0xa0 */ + 0x0b, 0x0a, 0x00, 0x00, + 0x01, 0x01, 0x00, 0x00, + }; + PacketBBTester test(testnum++, packet, buffer, sizeof(buffer)); + } + + /* Test 11 + * ,------------------ + * | PACKET + * |------------------ + * | * Packet version: 0 + * | * Packet flags: 12 + * | * Packet seq number: 11 + * | | * Packet TLV Block + * | | - TLV + * | | Flags = 0 + * | | Type = 1; Value = (warning: parameter is NULL) + * | ,------------------- + * | | MESSAGE + * | |------------------- + * | | * Message type: 1 + * | | * Message flags: 0 + * | `------------------- + * | + * | ,------------------- + * | | MESSAGE + * | |------------------- + * | | * Message type: 2 + * | | * Message flags: 224 + * | | * Originator address: 10.0.0.1 + * | | * Hop limit: 255 + * | | * Hop count: 1 + * | `------------------- + * | + * `------------------ + */ + { + PacketBB packet; + packet.SetSequenceNumber (11); + + Ptr tlv1 = Create (); + tlv1->SetType (1); + packet.TlvPushBack (tlv1); + + Ptr msg1 = Create (); + msg1->SetType (1); + packet.MessagePushBack (msg1); + + Ptr msg2 = Create (); + msg2->SetType (2); + msg2->SetOriginatorAddress(Ipv4Address("10.0.0.1")); + msg2->SetHopLimit (255); + msg2->SetHopCount (1); + packet.MessagePushBack (msg2); + + uint8_t buffer[] = { + 0x0c, 0x00, 0x0b, 0x00, + 0x02, 0x01, 0x00, 0x01, + 0x03, 0x00, 0x06, 0x00, + 0x00, 0x02, 0xe3, 0x00, /* [14] used to be 0xe0 */ + 0x0c, 0x0a, 0x00, 0x00, + 0x01, 0xff, 0x01, 0x00, + 0x00 + }; + PacketBBTester test(testnum++, packet, buffer, sizeof(buffer)); + } + + /* Test 12 + * ,------------------ + * | PACKET + * |------------------ + * | * Packet version: 0 + * | * Packet flags: 12 + * | * Packet seq number: 12 + * | | * Packet TLV Block + * | | - TLV + * | | Flags = 0 + * | | Type = 1; Value = (warning: parameter is NULL) + * | ,------------------- + * | | MESSAGE + * | |------------------- + * | | * Message type: 1 + * | | * Message flags: 0 + * | `------------------- + * | + * | ,------------------- + * | | MESSAGE + * | |------------------- + * | | * Message type: 2 + * | | * Message flags: 240 + * | | * Originator address: 10.0.0.1 + * | | * Hop limit: 255 + * | | * Hop count: 1 + * | | * Message seq number: 12345 + * | `------------------- + * | + * `------------------ + */ + { + PacketBB packet; + packet.SetSequenceNumber (12); + + Ptr tlv1 = Create (); + tlv1->SetType (1); + packet.TlvPushBack (tlv1); + + Ptr msg1 = Create (); + msg1->SetType (1); + packet.MessagePushBack (msg1); + + Ptr msg2 = Create (); + msg2->SetType (2); + msg2->SetOriginatorAddress(Ipv4Address("10.0.0.1")); + msg2->SetHopLimit (255); + msg2->SetHopCount (1); + msg2->SetSequenceNumber (12345); + packet.MessagePushBack (msg2); + + uint8_t buffer[] = { + 0x0c, 0x00, 0x0c, 0x00, + 0x02, 0x01, 0x00, 0x01, + 0x03, 0x00, 0x06, 0x00, + 0x00, 0x02, 0xf3, 0x00, /* [14] - 0xf0 */ + 0x0e, 0x0a, 0x00, 0x00, + 0x01, 0xff, 0x01, 0x30, + 0x39, 0x00, 0x00 + }; + PacketBBTester test(testnum++, packet, buffer, sizeof(buffer)); + } + + /* Test 13 + * ,------------------ + * | PACKET + * |------------------ + * | * Packet version: 0 + * | * Packet flags: 12 + * | * Packet seq number: 13 + * | | * Packet TLV Block + * | | - TLV + * | | Flags = 0 + * | | Type = 1; Value = (warning: parameter is NULL) + * | ,------------------- + * | | MESSAGE + * | |------------------- + * | | * Message type: 1 + * | | * Message flags: 0 + * | `------------------- + * | + * | ,------------------- + * | | MESSAGE + * | |------------------- + * | | * Message type: 2 + * | | * Message flags: 240 + * | | * Originator address: 10.0.0.1 + * | | * Hop limit: 255 + * | | * Hop count: 1 + * | | * Message seq number: 12345 + * | `------------------- + * | + * `------------------ + */ + { + PacketBB packet; + packet.SetSequenceNumber (13); + + Ptr tlv1 = Create (); + tlv1->SetType (1); + packet.TlvPushBack (tlv1); + + Ptr msg1 = Create (); + msg1->SetType (1); + packet.MessagePushBack (msg1); + + Ptr msg2 = Create (); + msg2->SetType (2); + msg2->SetOriginatorAddress(Ipv4Address("10.0.0.1")); + msg2->SetHopLimit (255); + msg2->SetHopCount (1); + msg2->SetSequenceNumber (12345); + packet.MessagePushBack (msg2); + + uint8_t buffer[] = { + 0x0c, 0x00, 0x0d, 0x00, + 0x02, 0x01, 0x00, 0x01, + 0x03, 0x00, 0x06, 0x00, + 0x00, 0x02, 0xf3, 0x00, /* [14] - 0xf0 */ + 0x0e, 0x0a, 0x00, 0x00, + 0x01, 0xff, 0x01, 0x30, + 0x39, 0x00, 0x00 + }; + PacketBBTester test(testnum++, packet, buffer, sizeof(buffer)); + } + + /* Test 14 + * ,------------------ + * | PACKET + * |------------------ + * | * Packet version: 0 + * | * Packet flags: 12 + * | * Packet seq number: 14 + * | | * Packet TLV Block + * | | - TLV + * | | Flags = 0 + * | | Type = 1; Value = (warning: parameter is NULL) + * | ,------------------- + * | | MESSAGE + * | |------------------- + * | | * Message type: 1 + * | | * Message flags: 0 + * | | * Message TLV Block + * | | - TLV + * | | Flags = 0 + * | | Type = 1; Value = (warning: parameter is NULL) + * | `------------------- + * | + * | ,------------------- + * | | MESSAGE + * | |------------------- + * | | * Message type: 2 + * | | * Message flags: 240 + * | | * Originator address: 10.0.0.1 + * | | * Hop limit: 255 + * | | * Hop count: 1 + * | | * Message seq number: 12345 + * | `------------------- + * | + * `------------------ + */ + { + PacketBB packet; + packet.SetSequenceNumber (14); + + Ptr tlv1 = Create (); + tlv1->SetType (1); + packet.TlvPushBack (tlv1); + + Ptr msg1 = Create (); + msg1->SetType (1); + + Ptr msg1tlv1 = Create (); + msg1tlv1->SetType (1); + msg1->TlvPushBack (msg1tlv1); + + packet.MessagePushBack (msg1); + + Ptr msg2 = Create (); + msg2->SetType (2); + msg2->SetOriginatorAddress(Ipv4Address("10.0.0.1")); + msg2->SetHopLimit (255); + msg2->SetHopCount (1); + msg2->SetSequenceNumber (12345); + packet.MessagePushBack (msg2); + + uint8_t buffer[] = { + 0x0c, 0x00, 0x0e, 0x00, + 0x02, 0x01, 0x00, 0x01, + 0x03, 0x00, 0x08, 0x00, + 0x02, 0x01, 0x00, 0x02, + 0xf3, 0x00, 0x0e, 0x0a, /* [16] - 0xf0 */ + 0x00, 0x00, 0x01, 0xff, + 0x01, 0x30, 0x39, 0x00, + 0x00 + }; + PacketBBTester test(testnum++, packet, buffer, sizeof(buffer)); + } + + /* Test 15 + * ,------------------ + * | PACKET + * |------------------ + * | * Packet version: 0 + * | * Packet flags: 12 + * | * Packet seq number: 15 + * | | * Packet TLV Block + * | | - TLV + * | | Flags = 0 + * | | Type = 1; Value = (warning: parameter is NULL) + * | ,------------------- + * | | MESSAGE + * | |------------------- + * | | * Message type: 1 + * | | * Message flags: 0 + * | | * Message TLV Block + * | | - TLV + * | | Flags = 0 + * | | Type = 1; Value = (warning: parameter is NULL) + * | `------------------- + * | + * | ,------------------- + * | | MESSAGE + * | |------------------- + * | | * Message type: 2 + * | | * Message flags: 240 + * | | * Originator address: 10.0.0.1 + * | | * Hop limit: 255 + * | | * Hop count: 1 + * | | * Message seq number: 12345 + * | | - Address block (1 addresses) + * | | - 0.0.0.0/32 + * | | - Flags = 0 + * | | - ADDRESS TLV block (0 TLVs) + * | `------------------- + * | + * `------------------ + */ + { + PacketBB packet; + packet.SetSequenceNumber (15); + + Ptr tlv1 = Create (); + tlv1->SetType (1); + packet.TlvPushBack (tlv1); + + Ptr msg1 = Create (); + msg1->SetType (1); + + Ptr msg1tlv1 = Create (); + msg1tlv1->SetType (1); + msg1->TlvPushBack (msg1tlv1); + + packet.MessagePushBack (msg1); + + Ptr msg2 = Create (); + msg2->SetType (2); + msg2->SetOriginatorAddress (Ipv4Address ("10.0.0.1")); + msg2->SetHopLimit (255); + msg2->SetHopCount (1); + msg2->SetSequenceNumber (12345); + + Ptr msg2a1 = Create (); + msg2a1->AddressPushBack (Ipv4Address ("0.0.0.0")); + msg2->AddressBlockPushBack (msg2a1); + + packet.MessagePushBack (msg2); + + uint8_t buffer[] = { + 0x0c, 0x00, 0x0f, 0x00, + 0x02, 0x01, 0x00, 0x01, + 0x03, 0x00, 0x08, 0x00, + 0x02, 0x01, 0x00, 0x02, + 0xf3, 0x00, 0x16, 0x0a, /* [16] - 0xf0 */ + 0x00, 0x00, 0x01, 0xff, + 0x01, 0x30, 0x39, 0x00, + 0x00, 0x01, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00 + }; + PacketBBTester test(testnum++, packet, buffer, sizeof(buffer)); + } + + /* Test 16 + * ,------------------ + * | PACKET + * |------------------ + * | * Packet version: 0 + * | * Packet flags: 12 + * | * Packet seq number: 16 + * | | * Packet TLV Block + * | | - TLV + * | | Flags = 0 + * | | Type = 1; Value = (warning: parameter is NULL) + * | ,------------------- + * | | MESSAGE + * | |------------------- + * | | * Message type: 1 + * | | * Message flags: 0 + * | | * Message TLV Block + * | | - TLV + * | | Flags = 0 + * | | Type = 1; Value = (warning: parameter is NULL) + * | `------------------- + * | + * | ,------------------- + * | | MESSAGE + * | |------------------- + * | | * Message type: 2 + * | | * Message flags: 240 + * | | * Originator address: 10.0.0.1 + * | | * Hop limit: 255 + * | | * Hop count: 1 + * | | * Message seq number: 12345 + * | | - Address block (1 addresses) + * | | - 255.255.255.255/32 + * | | - Flags = 0 + * | | - ADDRESS TLV block (0 TLVs) + * | `------------------- + * | + * `------------------ + */ + { + PacketBB packet; + packet.SetSequenceNumber (16); + + Ptr tlv1 = Create (); + tlv1->SetType (1); + packet.TlvPushBack (tlv1); + + Ptr msg1 = Create (); + msg1->SetType (1); + + Ptr msg1tlv1 = Create (); + msg1tlv1->SetType (1); + msg1->TlvPushBack (msg1tlv1); + + packet.MessagePushBack (msg1); + + Ptr msg2 = Create (); + msg2->SetType (2); + msg2->SetOriginatorAddress (Ipv4Address ("10.0.0.1")); + msg2->SetHopLimit (255); + msg2->SetHopCount (1); + msg2->SetSequenceNumber (12345); + + Ptr msg2a1 = Create (); + msg2a1->AddressPushBack (Ipv4Address ("255.255.255.255")); + msg2->AddressBlockPushBack (msg2a1); + + packet.MessagePushBack (msg2); + + uint8_t buffer[] = { + 0x0c, 0x00, 0x10, 0x00, + 0x02, 0x01, 0x00, 0x01, + 0x03, 0x00, 0x08, 0x00, + 0x02, 0x01, 0x00, 0x02, + 0xf3, 0x00, 0x16, 0x0a, /* [16] - 0xf0 */ + 0x00, 0x00, 0x01, 0xff, + 0x01, 0x30, 0x39, 0x00, + 0x00, 0x01, 0x00, 0xff, + 0xff, 0xff, 0xff, 0x00, + 0x00, + }; + PacketBBTester test(testnum++, packet, buffer, sizeof(buffer)); + } + + /* Test 17 + * ,------------------ + * | PACKET + * |------------------ + * | * Packet version: 0 + * | * Packet flags: 12 + * | * Packet seq number: 17 + * | | * Packet TLV Block + * | | - TLV + * | | Flags = 0 + * | | Type = 1; Value = (warning: parameter is NULL) + * | ,------------------- + * | | MESSAGE + * | |------------------- + * | | * Message type: 1 + * | | * Message flags: 0 + * | | * Message TLV Block + * | | - TLV + * | | Flags = 0 + * | | Type = 1; Value = (warning: parameter is NULL) + * | `------------------- + * | + * | ,------------------- + * | | MESSAGE + * | |------------------- + * | | * Message type: 2 + * | | * Message flags: 240 + * | | * Originator address: 10.0.0.1 + * | | * Hop limit: 255 + * | | * Hop count: 1 + * | | * Message seq number: 12345 + * | | - Address block (1 addresses) + * | | - 0.0.0.1/32 + * | | - Flags = 0 + * | | - ADDRESS TLV block (0 TLVs) + * | `------------------- + * | + * `------------------ + */ + { + PacketBB packet; + packet.SetSequenceNumber (17); + + Ptr tlv1 = Create (); + tlv1->SetType (1); + packet.TlvPushBack (tlv1); + + Ptr msg1 = Create (); + msg1->SetType (1); + + Ptr msg1tlv1 = Create (); + msg1tlv1->SetType (1); + msg1->TlvPushBack (msg1tlv1); + + packet.MessagePushBack (msg1); + + Ptr msg2 = Create (); + msg2->SetType (2); + msg2->SetOriginatorAddress (Ipv4Address ("10.0.0.1")); + msg2->SetHopLimit (255); + msg2->SetHopCount (1); + msg2->SetSequenceNumber (12345); + + Ptr msg2a1 = Create (); + msg2a1->AddressPushBack (Ipv4Address ("0.0.0.1")); + msg2->AddressBlockPushBack (msg2a1); + + packet.MessagePushBack (msg2); + + uint8_t buffer[] = { + 0x0c, 0x00, 0x11, 0x00, + 0x02, 0x01, 0x00, 0x01, + 0x03, 0x00, 0x08, 0x00, + 0x02, 0x01, 0x00, 0x02, + 0xf3, 0x00, 0x16, 0x0a, /* [16] - 0xf0 */ + 0x00, 0x00, 0x01, 0xff, + 0x01, 0x30, 0x39, 0x00, + 0x00, 0x01, 0x00, 0x00, + 0x00, 0x00, 0x01, 0x00, + 0x00, + }; + PacketBBTester test(testnum++, packet, buffer, sizeof(buffer)); + } + + /* Test 18 + * ,------------------ + * | PACKET + * |------------------ + * | * Packet version: 0 + * | * Packet flags: 12 + * | * Packet seq number: 18 + * | | * Packet TLV Block + * | | - TLV + * | | Flags = 0 + * | | Type = 1; Value = (warning: parameter is NULL) + * | ,------------------- + * | | MESSAGE + * | |------------------- + * | | * Message type: 1 + * | | * Message flags: 0 + * | | * Message TLV Block + * | | - TLV + * | | Flags = 0 + * | | Type = 1; Value = (warning: parameter is NULL) + * | `------------------- + * | + * | ,------------------- + * | | MESSAGE + * | |------------------- + * | | * Message type: 2 + * | | * Message flags: 240 + * | | * Originator address: 10.0.0.1 + * | | * Hop limit: 255 + * | | * Hop count: 1 + * | | * Message seq number: 12345 + * | | - Address block (1 addresses) + * | | - 10.0.0.0/32 + * | | - Flags = 0 + * | | - ADDRESS TLV block (0 TLVs) + * | `------------------- + * | + * `------------------ + */ + { + PacketBB packet; + packet.SetSequenceNumber (18); + + Ptr tlv1 = Create (); + tlv1->SetType (1); + packet.TlvPushBack (tlv1); + + Ptr msg1 = Create (); + msg1->SetType (1); + + Ptr msg1tlv1 = Create (); + msg1tlv1->SetType (1); + msg1->TlvPushBack (msg1tlv1); + + packet.MessagePushBack (msg1); + + Ptr msg2 = Create (); + msg2->SetType (2); + msg2->SetOriginatorAddress (Ipv4Address ("10.0.0.1")); + msg2->SetHopLimit (255); + msg2->SetHopCount (1); + msg2->SetSequenceNumber (12345); + + Ptr msg2a1 = Create (); + msg2a1->AddressPushBack (Ipv4Address ("10.0.0.0")); + msg2->AddressBlockPushBack (msg2a1); + + packet.MessagePushBack (msg2); + + uint8_t buffer[] = { + 0x0c, 0x00, 0x12, 0x00, + 0x02, 0x01, 0x00, 0x01, + 0x03, 0x00, 0x08, 0x00, + 0x02, 0x01, 0x00, 0x02, + 0xf3, 0x00, 0x16, 0x0a, /* [16] - 0xf0 */ + 0x00, 0x00, 0x01, 0xff, + 0x01, 0x30, 0x39, 0x00, + 0x00, 0x01, 0x00, 0x0a, + 0x00, 0x00, 0x00, 0x00, + 0x00, + }; + PacketBBTester test(testnum++, packet, buffer, sizeof(buffer)); + } + + /* Test 19 + * ,------------------ + * | PACKET + * |------------------ + * | * Packet version: 0 + * | * Packet flags: 12 + * | * Packet seq number: 19 + * | | * Packet TLV Block + * | | - TLV + * | | Flags = 0 + * | | Type = 1; Value = (warning: parameter is NULL) + * | ,------------------- + * | | MESSAGE + * | |------------------- + * | | * Message type: 1 + * | | * Message flags: 0 + * | | * Message TLV Block + * | | - TLV + * | | Flags = 0 + * | | Type = 1; Value = (warning: parameter is NULL) + * | `------------------- + * | + * | ,------------------- + * | | MESSAGE + * | |------------------- + * | | * Message type: 2 + * | | * Message flags: 240 + * | | * Originator address: 10.0.0.1 + * | | * Hop limit: 255 + * | | * Hop count: 1 + * | | * Message seq number: 12345 + * | | - Address block (1 addresses) + * | | - 10.0.0.1/32 + * | | - Flags = 0 + * | | - ADDRESS TLV block (0 TLVs) + * | `------------------- + * | + * `------------------ + */ + { + PacketBB packet; + packet.SetSequenceNumber (19); + + Ptr tlv1 = Create (); + tlv1->SetType (1); + packet.TlvPushBack (tlv1); + + Ptr msg1 = Create (); + msg1->SetType (1); + + Ptr msg1tlv1 = Create (); + msg1tlv1->SetType (1); + msg1->TlvPushBack (msg1tlv1); + + packet.MessagePushBack (msg1); + + Ptr msg2 = Create (); + msg2->SetType (2); + msg2->SetOriginatorAddress (Ipv4Address ("10.0.0.1")); + msg2->SetHopLimit (255); + msg2->SetHopCount (1); + msg2->SetSequenceNumber (12345); + + Ptr msg2a1 = Create (); + msg2a1->AddressPushBack (Ipv4Address ("10.0.0.1")); + msg2->AddressBlockPushBack (msg2a1); + + packet.MessagePushBack (msg2); + + uint8_t buffer[] = { + 0x0c, 0x00, 0x13, 0x00, + 0x02, 0x01, 0x00, 0x01, + 0x03, 0x00, 0x08, 0x00, + 0x02, 0x01, 0x00, 0x02, + 0xf3, 0x00, 0x16, 0x0a, /* [16] - 0xf0 */ + 0x00, 0x00, 0x01, 0xff, + 0x01, 0x30, 0x39, 0x00, + 0x00, 0x01, 0x00, 0x0a, + 0x00, 0x00, 0x01, 0x00, + 0x00, + }; + PacketBBTester test(testnum++, packet, buffer, sizeof(buffer)); + } + + /* Test 20 + * ,------------------ + * | PACKET + * |------------------ + * | * Packet version: 0 + * | * Packet flags: 12 + * | * Packet seq number: 20 + * | | * Packet TLV Block + * | | - TLV + * | | Flags = 0 + * | | Type = 1; Value = (warning: parameter is NULL) + * | ,------------------- + * | | MESSAGE + * | |------------------- + * | | * Message type: 1 + * | | * Message flags: 0 + * | | * Message TLV Block + * | | - TLV + * | | Flags = 0 + * | | Type = 1; Value = (warning: parameter is NULL) + * | `------------------- + * | + * | ,------------------- + * | | MESSAGE + * | |------------------- + * | | * Message type: 2 + * | | * Message flags: 240 + * | | * Originator address: 10.0.0.1 + * | | * Hop limit: 255 + * | | * Hop count: 1 + * | | * Message seq number: 12345 + * | | - Address block (2 addresses) + * | | - 10.0.0.1/32 + * | | - 10.0.0.2/32 + * | | - Flags = 128 + * | | - ADDRESS TLV block (0 TLVs) + * | `------------------- + * | + * `------------------ + */ + { + PacketBB packet; + packet.SetSequenceNumber (20); + + Ptr tlv1 = Create (); + tlv1->SetType (1); + packet.TlvPushBack (tlv1); + + Ptr msg1 = Create (); + msg1->SetType (1); + + Ptr msg1tlv1 = Create (); + msg1tlv1->SetType (1); + msg1->TlvPushBack (msg1tlv1); + + packet.MessagePushBack (msg1); + + Ptr msg2 = Create (); + msg2->SetType (2); + msg2->SetOriginatorAddress (Ipv4Address ("10.0.0.1")); + msg2->SetHopLimit (255); + msg2->SetHopCount (1); + msg2->SetSequenceNumber (12345); + + Ptr msg2a1 = Create (); + msg2a1->AddressPushBack (Ipv4Address ("10.0.0.1")); + msg2a1->AddressPushBack (Ipv4Address ("10.0.0.2")); + msg2->AddressBlockPushBack (msg2a1); + + packet.MessagePushBack (msg2); + + uint8_t buffer[] = { + 0x0c, 0x00, 0x14, 0x00, + 0x02, 0x01, 0x00, 0x01, + 0x03, 0x00, 0x08, 0x00, + 0x02, 0x01, 0x00, 0x02, + 0xf3, 0x00, 0x18, 0x0a, /* [16] - 0xf0 */ + 0x00, 0x00, 0x01, 0xff, + 0x01, 0x30, 0x39, 0x00, + 0x00, 0x02, 0x80, 0x03, + 0x0a, 0x00, 0x00, 0x01, + 0x02, 0x00, 0x00, + }; + PacketBBTester test(testnum++, packet, buffer, sizeof(buffer)); + } + + /* Test 21 + * ,------------------ + * | PACKET + * |------------------ + * | * Packet version: 0 + * | * Packet flags: 12 + * | * Packet seq number: 21 + * | | * Packet TLV Block + * | | - TLV + * | | Flags = 0 + * | | Type = 1; Value = (warning: parameter is NULL) + * | ,------------------- + * | | MESSAGE + * | |------------------- + * | | * Message type: 1 + * | | * Message flags: 0 + * | | * Message TLV Block + * | | - TLV + * | | Flags = 0 + * | | Type = 1; Value = (warning: parameter is NULL) + * | `------------------- + * | + * | ,------------------- + * | | MESSAGE + * | |------------------- + * | | * Message type: 2 + * | | * Message flags: 240 + * | | * Originator address: 10.0.0.1 + * | | * Hop limit: 255 + * | | * Hop count: 1 + * | | * Message seq number: 12345 + * | | - Address block (2 addresses) + * | | - 10.0.0.2/32 + * | | - 10.1.1.2/32 + * | | - Flags = 192 + * | | - ADDRESS TLV block (0 TLVs) + * | `------------------- + * | + * `------------------ + */ + { + PacketBB packet; + packet.SetSequenceNumber (21); + + Ptr tlv1 = Create (); + tlv1->SetType (1); + packet.TlvPushBack (tlv1); + + Ptr msg1 = Create (); + msg1->SetType (1); + + Ptr msg1tlv1 = Create (); + msg1tlv1->SetType (1); + msg1->TlvPushBack (msg1tlv1); + + packet.MessagePushBack (msg1); + + Ptr msg2 = Create (); + msg2->SetType (2); + msg2->SetOriginatorAddress (Ipv4Address ("10.0.0.1")); + msg2->SetHopLimit (255); + msg2->SetHopCount (1); + msg2->SetSequenceNumber (12345); + + Ptr msg2a1 = Create (); + msg2a1->AddressPushBack (Ipv4Address ("10.0.0.2")); + msg2a1->AddressPushBack (Ipv4Address ("10.1.1.2")); + msg2->AddressBlockPushBack (msg2a1); + + packet.MessagePushBack (msg2); + + uint8_t buffer[] = { + 0x0c, 0x00, 0x15, 0x00, + 0x02, 0x01, 0x00, 0x01, + 0x03, 0x00, 0x08, 0x00, + 0x02, 0x01, 0x00, 0x02, + 0xf3, 0x00, 0x1a, 0x0a, /* [16] - 0xf0 */ + 0x00, 0x00, 0x01, 0xff, + 0x01, 0x30, 0x39, 0x00, + 0x00, 0x02, 0xc0, 0x01, + 0x0a, 0x01, 0x02, 0x00, + 0x00, 0x01, 0x01, 0x00, + 0x00, + }; + PacketBBTester test(testnum++, packet, buffer, sizeof(buffer)); + } + + /* Test 22 + * ,------------------ + * | PACKET + * |------------------ + * | * Packet version: 0 + * | * Packet flags: 12 + * | * Packet seq number: 22 + * | | * Packet TLV Block + * | | - TLV + * | | Flags = 0 + * | | Type = 1; Value = (warning: parameter is NULL) + * | ,------------------- + * | | MESSAGE + * | |------------------- + * | | * Message type: 1 + * | | * Message flags: 0 + * | | * Message TLV Block + * | | - TLV + * | | Flags = 0 + * | | Type = 1; Value = (warning: parameter is NULL) + * | `------------------- + * | + * | ,------------------- + * | | MESSAGE + * | |------------------- + * | | * Message type: 2 + * | | * Message flags: 240 + * | | * Originator address: 10.0.0.1 + * | | * Hop limit: 255 + * | | * Hop count: 1 + * | | * Message seq number: 12345 + * | | - Address block (2 addresses) + * | | - 10.0.0.2/32 + * | | - 10.1.1.2/32 + * | | - Flags = 192 + * | | - ADDRESS TLV block (0 TLVs) + * | | - Address block (2 addresses) + * | | - 10.0.0.0/32 + * | | - 11.0.0.0/32 + * | | - Flags = 32 + * | | - ADDRESS TLV block (0 TLVs) + * | `------------------- + * | + * `------------------ + */ + { + PacketBB packet; + packet.SetSequenceNumber (22); + + Ptr tlv1 = Create (); + tlv1->SetType (1); + packet.TlvPushBack (tlv1); + + Ptr msg1 = Create (); + msg1->SetType (1); + + Ptr msg1tlv1 = Create (); + msg1tlv1->SetType (1); + msg1->TlvPushBack (msg1tlv1); + + packet.MessagePushBack (msg1); + + Ptr msg2 = Create (); + msg2->SetType (2); + msg2->SetOriginatorAddress (Ipv4Address ("10.0.0.1")); + msg2->SetHopLimit (255); + msg2->SetHopCount (1); + msg2->SetSequenceNumber (12345); + + Ptr msg2a1 = Create (); + msg2a1->AddressPushBack (Ipv4Address ("10.0.0.2")); + msg2a1->AddressPushBack (Ipv4Address ("10.1.1.2")); + msg2->AddressBlockPushBack (msg2a1); + + Ptr msg2a2 = Create (); + msg2a2->AddressPushBack (Ipv4Address ("10.0.0.0")); + msg2a2->AddressPushBack (Ipv4Address ("11.0.0.0")); + msg2->AddressBlockPushBack (msg2a2); + + packet.MessagePushBack (msg2); + + uint8_t buffer[] = { + 0x0c, 0x00, 0x16, 0x00, + 0x02, 0x01, 0x00, 0x01, + 0x03, 0x00, 0x08, 0x00, + 0x02, 0x01, 0x00, 0x02, + 0xf3, 0x00, 0x21, 0x0a, /* [16] - 0xf0 */ + 0x00, 0x00, 0x01, 0xff, + 0x01, 0x30, 0x39, 0x00, + 0x00, 0x02, 0xc0, 0x01, + 0x0a, 0x01, 0x02, 0x00, + 0x00, 0x01, 0x01, 0x00, + 0x00, 0x02, 0x20, 0x03, + 0x0a, 0x0b, 0x00, 0x00, + }; + PacketBBTester test(testnum++, packet, buffer, sizeof(buffer)); + } + + /* Test 23 + * ,------------------ + * | PACKET + * |------------------ + * | * Packet version: 0 + * | * Packet flags: 12 + * | * Packet seq number: 23 + * | | * Packet TLV Block + * | | - TLV + * | | Flags = 0 + * | | Type = 1; Value = (warning: parameter is NULL) + * | ,------------------- + * | | MESSAGE + * | |------------------- + * | | * Message type: 1 + * | | * Message flags: 0 + * | | * Message TLV Block + * | | - TLV + * | | Flags = 0 + * | | Type = 1; Value = (warning: parameter is NULL) + * | `------------------- + * | + * | ,------------------- + * | | MESSAGE + * | |------------------- + * | | * Message type: 2 + * | | * Message flags: 240 + * | | * Originator address: 10.0.0.1 + * | | * Hop limit: 255 + * | | * Hop count: 1 + * | | * Message seq number: 12345 + * | | - Address block (2 addresses) + * | | - 10.0.0.2/32 + * | | - 10.1.1.2/32 + * | | - Flags = 192 + * | | - ADDRESS TLV block (0 TLVs) + * | | - Address block (4 addresses) + * | | - 10.0.0.0/32 + * | | - 11.0.0.0/32 + * | | - 10.0.0.5/16 + * | | - 10.0.0.6/24 + * | | - Flags = 8 + * | | - ADDRESS TLV block (0 TLVs) + * | `------------------- + * | + * `------------------ + */ + { + PacketBB packet; + packet.SetSequenceNumber (23); + + Ptr tlv1 = Create (); + tlv1->SetType (1); + packet.TlvPushBack (tlv1); + + Ptr msg1 = Create (); + msg1->SetType (1); + + Ptr msg1tlv1 = Create (); + msg1tlv1->SetType (1); + msg1->TlvPushBack (msg1tlv1); + + packet.MessagePushBack (msg1); + + Ptr msg2 = Create (); + msg2->SetType (2); + msg2->SetOriginatorAddress (Ipv4Address ("10.0.0.1")); + msg2->SetHopLimit (255); + msg2->SetHopCount (1); + msg2->SetSequenceNumber (12345); + + Ptr msg2a1 = Create (); + msg2a1->AddressPushBack (Ipv4Address ("10.0.0.2")); + msg2a1->AddressPushBack (Ipv4Address ("10.1.1.2")); + msg2->AddressBlockPushBack (msg2a1); + + Ptr msg2a2 = Create (); + msg2a2->AddressPushBack (Ipv4Address ("10.0.0.0")); + msg2a2->AddressPushBack (Ipv4Address ("11.0.0.0")); + msg2a2->AddressPushBack (Ipv4Address ("10.0.0.5")); + msg2a2->AddressPushBack (Ipv4Address ("10.0.0.6")); + + msg2a2->PrefixPushBack (32); + msg2a2->PrefixPushBack (32); + msg2a2->PrefixPushBack (16); + msg2a2->PrefixPushBack (24); + + msg2->AddressBlockPushBack (msg2a2); + + packet.MessagePushBack (msg2); + + uint8_t buffer[] = { + 0x0c, 0x00, 0x17, 0x00, + 0x02, 0x01, 0x00, 0x01, + 0x03, 0x00, 0x08, 0x00, + 0x02, 0x01, 0x00, 0x02, + 0xf3, 0x00, 0x32, 0x0a, /* [16] - 0xf0 */ + 0x00, 0x00, 0x01, 0xff, + 0x01, 0x30, 0x39, 0x00, + 0x00, 0x02, 0xc0, 0x01, + 0x0a, 0x01, 0x02, 0x00, + 0x00, 0x01, 0x01, 0x00, + 0x00, 0x04, 0x08, 0x0a, + 0x00, 0x00, 0x00, 0x0b, + 0x00, 0x00, 0x00, 0x0a, + 0x00, 0x00, 0x05, 0x0a, + 0x00, 0x00, 0x06, 0x20, + 0x20, 0x10, 0x18, 0x00, + 0x00, + }; + PacketBBTester test(testnum++, packet, buffer, sizeof(buffer)); + } + + /* Test 24 + * ,------------------ + * | PACKET + * |------------------ + * | * Packet version: 0 + * | * Packet flags: 12 + * | * Packet seq number: 24 + * | | * Packet TLV Block + * | | - TLV + * | | Flags = 0 + * | | Type = 1; Value = (warning: parameter is NULL) + * | ,------------------- + * | | MESSAGE + * | |------------------- + * | | * Message type: 1 + * | | * Message flags: 0 + * | | * Message TLV Block + * | | - TLV + * | | Flags = 0 + * | | Type = 1; Value = (warning: parameter is NULL) + * | `------------------- + * | + * | ,------------------- + * | | MESSAGE + * | |------------------- + * | | * Message type: 2 + * | | * Message flags: 240 + * | | * Originator address: 10.0.0.1 + * | | * Hop limit: 255 + * | | * Hop count: 1 + * | | * Message seq number: 12345 + * | | - Address block (2 addresses) + * | | - 10.0.0.2/32 + * | | - 10.1.1.2/32 + * | | - Flags = 192 + * | | - ADDRESS TLV block (0 TLVs) + * | | - Address block (4 addresses) + * | | - 10.0.0.0/32 + * | | - 11.0.0.0/32 + * | | - 10.0.0.5/16 + * | | - 10.0.0.6/24 + * | | - Flags = 8 + * | | - ADDRESS TLV block (1 TLVs) + * | | - TLV + * | | Flags = 0 + * | | Type = 1; Value = (warning: parameter is NULL) + * | `------------------- + * | + * `------------------ + */ + { + PacketBB packet; + packet.SetSequenceNumber (24); + + Ptr tlv1 = Create (); + tlv1->SetType (1); + packet.TlvPushBack (tlv1); + + Ptr msg1 = Create (); + msg1->SetType (1); + + Ptr msg1tlv1 = Create (); + msg1tlv1->SetType (1); + msg1->TlvPushBack (msg1tlv1); + + packet.MessagePushBack (msg1); + + Ptr msg2 = Create (); + msg2->SetType (2); + msg2->SetOriginatorAddress (Ipv4Address ("10.0.0.1")); + msg2->SetHopLimit (255); + msg2->SetHopCount (1); + msg2->SetSequenceNumber (12345); + + Ptr msg2a1 = Create (); + msg2a1->AddressPushBack (Ipv4Address ("10.0.0.2")); + msg2a1->AddressPushBack (Ipv4Address ("10.1.1.2")); + msg2->AddressBlockPushBack (msg2a1); + + Ptr msg2a2 = Create (); + msg2a2->AddressPushBack (Ipv4Address ("10.0.0.0")); + msg2a2->AddressPushBack (Ipv4Address ("11.0.0.0")); + msg2a2->AddressPushBack (Ipv4Address ("10.0.0.5")); + msg2a2->AddressPushBack (Ipv4Address ("10.0.0.6")); + + msg2a2->PrefixPushBack (32); + msg2a2->PrefixPushBack (32); + msg2a2->PrefixPushBack (16); + msg2a2->PrefixPushBack (24); + + Ptr msg2a2tlv1 = Create (); + msg2a2tlv1->SetType (1); + msg2a2->TlvPushBack (msg2a2tlv1); + + msg2->AddressBlockPushBack (msg2a2); + + packet.MessagePushBack (msg2); + + uint8_t buffer[] = { + 0x0c, 0x00, 0x18, 0x00, + 0x02, 0x01, 0x00, 0x01, + 0x03, 0x00, 0x08, 0x00, + 0x02, 0x01, 0x00, 0x02, + 0xf3, 0x00, 0x34, 0x0a, /* [16] - 0xf0 */ + 0x00, 0x00, 0x01, 0xff, + 0x01, 0x30, 0x39, 0x00, + 0x00, 0x02, 0xc0, 0x01, + 0x0a, 0x01, 0x02, 0x00, + 0x00, 0x01, 0x01, 0x00, + 0x00, 0x04, 0x08, 0x0a, + 0x00, 0x00, 0x00, 0x0b, + 0x00, 0x00, 0x00, 0x0a, + 0x00, 0x00, 0x05, 0x0a, + 0x00, 0x00, 0x06, 0x20, + 0x20, 0x10, 0x18, 0x00, + 0x02, 0x01, 0x00, + }; + PacketBBTester test(testnum++, packet, buffer, sizeof(buffer)); + } + + /* Test 25 + * ,------------------ + * | PACKET + * |------------------ + * | * Packet version: 0 + * | * Packet flags: 12 + * | * Packet seq number: 25 + * | | * Packet TLV Block + * | | - TLV + * | | Flags = 0 + * | | Type = 1; Value = (warning: parameter is NULL) + * | ,------------------- + * | | MESSAGE + * | |------------------- + * | | * Message type: 1 + * | | * Message flags: 0 + * | | * Message TLV Block + * | | - TLV + * | | Flags = 0 + * | | Type = 1; Value = (warning: parameter is NULL) + * | `------------------- + * | + * | ,------------------- + * | | MESSAGE + * | |------------------- + * | | * Message type: 2 + * | | * Message flags: 240 + * | | * Originator address: 10.0.0.1 + * | | * Hop limit: 255 + * | | * Hop count: 1 + * | | * Message seq number: 12345 + * | | - Address block (2 addresses) + * | | - 10.0.0.2/32 + * | | - 10.1.1.2/32 + * | | - Flags = 192 + * | | - ADDRESS TLV block (0 TLVs) + * | | - Address block (4 addresses) + * | | - 10.0.0.0/32 + * | | - 11.0.0.0/32 + * | | - 10.0.0.5/16 + * | | - 10.0.0.6/24 + * | | - Flags = 8 + * | | - ADDRESS TLV block (1 TLVs) + * | | - TLV + * | | Flags = 64 + * | | Index-start = 1 + * | | Type = 1; Value = (warning: parameter is NULL) + * | `------------------- + * | + * `------------------ + */ + { + PacketBB packet; + packet.SetSequenceNumber (25); + + Ptr tlv1 = Create (); + tlv1->SetType (1); + packet.TlvPushBack (tlv1); + + Ptr msg1 = Create (); + msg1->SetType (1); + + Ptr msg1tlv1 = Create (); + msg1tlv1->SetType (1); + msg1->TlvPushBack (msg1tlv1); + + packet.MessagePushBack (msg1); + + Ptr msg2 = Create (); + msg2->SetType (2); + msg2->SetOriginatorAddress (Ipv4Address ("10.0.0.1")); + msg2->SetHopLimit (255); + msg2->SetHopCount (1); + msg2->SetSequenceNumber (12345); + + Ptr msg2a1 = Create (); + msg2a1->AddressPushBack (Ipv4Address ("10.0.0.2")); + msg2a1->AddressPushBack (Ipv4Address ("10.1.1.2")); + msg2->AddressBlockPushBack (msg2a1); + + Ptr msg2a2 = Create (); + msg2a2->AddressPushBack (Ipv4Address ("10.0.0.0")); + msg2a2->AddressPushBack (Ipv4Address ("11.0.0.0")); + msg2a2->AddressPushBack (Ipv4Address ("10.0.0.5")); + msg2a2->AddressPushBack (Ipv4Address ("10.0.0.6")); + + msg2a2->PrefixPushBack (32); + msg2a2->PrefixPushBack (32); + msg2a2->PrefixPushBack (16); + msg2a2->PrefixPushBack (24); + + Ptr msg2a2tlv1 = Create (); + msg2a2tlv1->SetType (1); + msg2a2tlv1->SetIndexStart (1); + msg2a2->TlvPushBack (msg2a2tlv1); + + msg2->AddressBlockPushBack (msg2a2); + + packet.MessagePushBack (msg2); + + uint8_t buffer[] = { + 0x0c, 0x00, 0x19, 0x00, + 0x02, 0x01, 0x00, 0x01, + 0x03, 0x00, 0x08, 0x00, + 0x02, 0x01, 0x00, 0x02, + 0xf3, 0x00, 0x35, 0x0a, /* [16] - 0xf0 */ + 0x00, 0x00, 0x01, 0xff, + 0x01, 0x30, 0x39, 0x00, + 0x00, 0x02, 0xc0, 0x01, + 0x0a, 0x01, 0x02, 0x00, + 0x00, 0x01, 0x01, 0x00, + 0x00, 0x04, 0x08, 0x0a, + 0x00, 0x00, 0x00, 0x0b, + 0x00, 0x00, 0x00, 0x0a, + 0x00, 0x00, 0x05, 0x0a, + 0x00, 0x00, 0x06, 0x20, + 0x20, 0x10, 0x18, 0x00, + 0x03, 0x01, 0x40, 0x01, + }; + PacketBBTester test(testnum++, packet, buffer, sizeof(buffer)); + } + + /* Test 26 + * ,------------------ + * | PACKET + * |------------------ + * | * Packet version: 0 + * | * Packet flags: 12 + * | * Packet seq number: 26 + * | | * Packet TLV Block + * | | - TLV + * | | Flags = 0 + * | | Type = 1; Value = (warning: parameter is NULL) + * | ,------------------- + * | | MESSAGE + * | |------------------- + * | | * Message type: 1 + * | | * Message flags: 0 + * | | * Message TLV Block + * | | - TLV + * | | Flags = 0 + * | | Type = 1; Value = (warning: parameter is NULL) + * | `------------------- + * | + * | ,------------------- + * | | MESSAGE + * | |------------------- + * | | * Message type: 2 + * | | * Message flags: 240 + * | | * Originator address: 10.0.0.1 + * | | * Hop limit: 255 + * | | * Hop count: 1 + * | | * Message seq number: 12345 + * | | - Address block (2 addresses) + * | | - 10.0.0.2/32 + * | | - 10.1.1.2/32 + * | | - Flags = 192 + * | | - ADDRESS TLV block (0 TLVs) + * | | - Address block (4 addresses) + * | | - 10.0.0.0/32 + * | | - 11.0.0.0/32 + * | | - 10.0.0.5/16 + * | | - 10.0.0.6/24 + * | | - Flags = 8 + * | | - ADDRESS TLV block (1 TLVs) + * | | - TLV + * | | Flags = 32 + * | | Index-start = 1 + * | | Index-stop = 3 + * | | Type = 1; Value = (warning: parameter is NULL) + * | `------------------- + * | + * `------------------ + */ + { + PacketBB packet; + packet.SetSequenceNumber (26); + + Ptr tlv1 = Create (); + tlv1->SetType (1); + packet.TlvPushBack (tlv1); + + Ptr msg1 = Create (); + msg1->SetType (1); + + Ptr msg1tlv1 = Create (); + msg1tlv1->SetType (1); + msg1->TlvPushBack (msg1tlv1); + + packet.MessagePushBack (msg1); + + Ptr msg2 = Create (); + msg2->SetType (2); + msg2->SetOriginatorAddress (Ipv4Address ("10.0.0.1")); + msg2->SetHopLimit (255); + msg2->SetHopCount (1); + msg2->SetSequenceNumber (12345); + + Ptr msg2a1 = Create (); + msg2a1->AddressPushBack (Ipv4Address ("10.0.0.2")); + msg2a1->AddressPushBack (Ipv4Address ("10.1.1.2")); + msg2->AddressBlockPushBack (msg2a1); + + Ptr msg2a2 = Create (); + msg2a2->AddressPushBack (Ipv4Address ("10.0.0.0")); + msg2a2->AddressPushBack (Ipv4Address ("11.0.0.0")); + msg2a2->AddressPushBack (Ipv4Address ("10.0.0.5")); + msg2a2->AddressPushBack (Ipv4Address ("10.0.0.6")); + + msg2a2->PrefixPushBack (32); + msg2a2->PrefixPushBack (32); + msg2a2->PrefixPushBack (16); + msg2a2->PrefixPushBack (24); + + Ptr msg2a2tlv1 = Create (); + msg2a2tlv1->SetType (1); + msg2a2tlv1->SetIndexStart (1); + msg2a2tlv1->SetIndexStop (3); + msg2a2->TlvPushBack (msg2a2tlv1); + + msg2->AddressBlockPushBack (msg2a2); + + packet.MessagePushBack (msg2); + + uint8_t buffer[] = { + 0x0c, 0x00, 0x1a, 0x00, + 0x02, 0x01, 0x00, 0x01, + 0x03, 0x00, 0x08, 0x00, + 0x02, 0x01, 0x00, 0x02, + 0xf3, 0x00, 0x36, 0x0a, /* [16] - 0xf0 */ + 0x00, 0x00, 0x01, 0xff, + 0x01, 0x30, 0x39, 0x00, + 0x00, 0x02, 0xc0, 0x01, + 0x0a, 0x01, 0x02, 0x00, + 0x00, 0x01, 0x01, 0x00, + 0x00, 0x04, 0x08, 0x0a, + 0x00, 0x00, 0x00, 0x0b, + 0x00, 0x00, 0x00, 0x0a, + 0x00, 0x00, 0x05, 0x0a, + 0x00, 0x00, 0x06, 0x20, + 0x20, 0x10, 0x18, 0x00, + 0x04, 0x01, 0x20, 0x01, + 0x03, + }; + PacketBBTester test(testnum++, packet, buffer, sizeof(buffer)); + } + + /* Test 27 + * ,------------------ + * | PACKET + * |------------------ + * | * Packet version: 0 + * | * Packet flags: 12 + * | * Packet seq number: 27 + * | | * Packet TLV Block + * | | - TLV + * | | Flags = 0 + * | | Type = 1; Value = (warning: parameter is NULL) + * | ,------------------- + * | | MESSAGE + * | |------------------- + * | | * Message type: 1 + * | | * Message flags: 0 + * | | * Message TLV Block + * | | - TLV + * | | Flags = 0 + * | | Type = 1; Value = (warning: parameter is NULL) + * | `------------------- + * | + * | ,------------------- + * | | MESSAGE + * | |------------------- + * | | * Message type: 2 + * | | * Message flags: 240 + * | | * Originator address: 10.0.0.1 + * | | * Hop limit: 255 + * | | * Hop count: 1 + * | | * Message seq number: 12345 + * | | - Address block (2 addresses) + * | | - 10.0.0.2/32 + * | | - 10.1.1.2/32 + * | | - Flags = 192 + * | | - ADDRESS TLV block (0 TLVs) + * | | - Address block (4 addresses) + * | | - 10.0.0.0/32 + * | | - 11.0.0.0/32 + * | | - 10.0.0.5/16 + * | | - 10.0.0.6/24 + * | | - Flags = 8 + * | | - ADDRESS TLV block (1 TLVs) + * | | - TLV + * | | Flags = 52 + * | | Index-start = 1 + * | | Index-stop = 3 + * | | Type = 1; Value = 01 02 03 + * | `------------------- + * | + * `------------------ + */ + { + PacketBB packet; + packet.SetSequenceNumber (27); + + Ptr tlv1 = Create (); + tlv1->SetType (1); + packet.TlvPushBack (tlv1); + + Ptr msg1 = Create (); + msg1->SetType (1); + + Ptr msg1tlv1 = Create (); + msg1tlv1->SetType (1); + msg1->TlvPushBack (msg1tlv1); + + packet.MessagePushBack (msg1); + + Ptr msg2 = Create (); + msg2->SetType (2); + msg2->SetOriginatorAddress (Ipv4Address ("10.0.0.1")); + msg2->SetHopLimit (255); + msg2->SetHopCount (1); + msg2->SetSequenceNumber (12345); + + Ptr msg2a1 = Create (); + msg2a1->AddressPushBack (Ipv4Address ("10.0.0.2")); + msg2a1->AddressPushBack (Ipv4Address ("10.1.1.2")); + msg2->AddressBlockPushBack (msg2a1); + + Ptr msg2a2 = Create (); + msg2a2->AddressPushBack (Ipv4Address ("10.0.0.0")); + msg2a2->AddressPushBack (Ipv4Address ("11.0.0.0")); + msg2a2->AddressPushBack (Ipv4Address ("10.0.0.5")); + msg2a2->AddressPushBack (Ipv4Address ("10.0.0.6")); + + msg2a2->PrefixPushBack (32); + msg2a2->PrefixPushBack (32); + msg2a2->PrefixPushBack (16); + msg2a2->PrefixPushBack (24); + + Ptr msg2a2tlv1 = Create (); + msg2a2tlv1->SetType (1); + msg2a2tlv1->SetIndexStart (1); + msg2a2tlv1->SetIndexStop (3); + + uint8_t value[] = {1, 2, 3}; + msg2a2tlv1->SetValue(value, sizeof (value)); + msg2a2tlv1->SetMultivalue (true); + + msg2a2->TlvPushBack (msg2a2tlv1); + + msg2->AddressBlockPushBack (msg2a2); + + packet.MessagePushBack (msg2); + + uint8_t buffer[] = { + 0x0c, 0x00, 0x1b, 0x00, + 0x02, 0x01, 0x00, 0x01, + 0x03, 0x00, 0x08, 0x00, + 0x02, 0x01, 0x00, 0x02, + 0xf3, 0x00, 0x3a, 0x0a, /* [16] - 0xf0 */ + 0x00, 0x00, 0x01, 0xff, + 0x01, 0x30, 0x39, 0x00, + 0x00, 0x02, 0xc0, 0x01, + 0x0a, 0x01, 0x02, 0x00, + 0x00, 0x01, 0x01, 0x00, + 0x00, 0x04, 0x08, 0x0a, + 0x00, 0x00, 0x00, 0x0b, + 0x00, 0x00, 0x00, 0x0a, + 0x00, 0x00, 0x05, 0x0a, + 0x00, 0x00, 0x06, 0x20, + 0x20, 0x10, 0x18, 0x00, + 0x08, 0x01, 0x34, 0x01, + 0x03, 0x03, 0x01, 0x02, + 0x03, + }; + PacketBBTester test(testnum++, packet, buffer, sizeof(buffer)); + } + + /* Test 28 + * ,------------------ + * | PACKET + * |------------------ + * | * Packet version: 0 + * | * Packet flags: 12 + * | * Packet seq number: 28 + * | | * Packet TLV Block + * | | - TLV + * | | Flags = 0 + * | | Type = 1; Value = (warning: parameter is NULL) + * | ,------------------- + * | | MESSAGE + * | |------------------- + * | | * Message type: 1 + * | | * Message flags: 0 + * | | * Message TLV Block + * | | - TLV + * | | Flags = 0 + * | | Type = 1; Value = (warning: parameter is NULL) + * | `------------------- + * | + * | ,------------------- + * | | MESSAGE + * | |------------------- + * | | * Message type: 2 + * | | * Message flags: 240 + * | | * Originator address: 10.0.0.1 + * | | * Hop limit: 255 + * | | * Hop count: 1 + * | | * Message seq number: 12345 + * | | - Address block (2 addresses) + * | | - 10.0.0.2/32 + * | | - 10.1.1.2/32 + * | | - Flags = 192 + * | | - ADDRESS TLV block (0 TLVs) + * | | - Address block (4 addresses) + * | | - 10.0.0.0/32 + * | | - 11.0.0.0/32 + * | | - 10.0.0.5/16 + * | | - 10.0.0.6/24 + * | | - Flags = 8 + * | | - ADDRESS TLV block (1 TLVs) + * | | - TLV + * | | Flags = 56 + * | | Index-start = 1 + * | | Index-stop = 3 + * | | Type = 1; Value = 00 01 02 03 + * | | 04 05 06 07 + * | | 08 09 0a 0b + * | | 0c 0d 0e 0f + * | | 10 11 12 13 + * | | 14 15 16 17 + * | | 18 19 1a 1b + * | | 1c 1d 1e 1f + * | | 20 21 22 23 + * | | 24 25 26 27 + * | | 28 29 2a 2b + * | | 2c 2d 2e 2f + * | | 30 31 32 33 + * | | 34 35 36 37 + * | | 38 39 3a 3b + * | | 3c 3d 3e 3f + * | | 40 41 42 43 + * | | 44 45 46 47 + * | | 48 49 4a 4b + * | | 4c 4d 4e 4f + * | | 50 51 52 53 + * | | 54 55 56 57 + * | | 58 59 5a 5b + * | | 5c 5d 5e 5f + * | | 60 61 62 63 + * | | 64 65 66 67 + * | | 68 69 6a 6b + * | | 6c 6d 6e 6f + * | | 70 71 72 73 + * | | 74 75 76 77 + * | | 78 79 7a 7b + * | | 7c 7d 7e 7f + * | | 80 81 82 83 + * | | 84 85 86 87 + * | | 88 89 8a 8b + * | | 8c 8d 8e 8f + * | | 90 91 92 93 + * | | 94 95 96 97 + * | | 98 99 9a 9b + * | | 9c 9d 9e 9f + * | | a0 a1 a2 a3 + * | | a4 a5 a6 a7 + * | | a8 a9 aa ab + * | | ac ad ae af + * | | b0 b1 b2 b3 + * | | b4 b5 b6 b7 + * | | b8 b9 ba bb + * | | bc bd be bf + * | | c0 c1 c2 c3 + * | | c4 c5 c6 c7 + * | | c8 c9 ca cb + * | | cc cd ce cf + * | | d0 d1 d2 d3 + * | | d4 d5 d6 d7 + * | | d8 d9 da db + * | | dc dd de df + * | | e0 e1 e2 e3 + * | | e4 e5 e6 e7 + * | | e8 e9 ea eb + * | | ec ed ee ef + * | | f0 f1 f2 f3 + * | | f4 f5 f6 f7 + * | | f8 f9 fa fb + * | | fc fd fe 00 + * | | 01 02 03 04 + * | | 05 06 07 08 + * | | 09 0a 0b 0c + * | | 0d 0e 0f 10 + * | | 11 12 13 14 + * | | 15 16 17 18 + * | | 19 1a 1b 1c + * | | 1d 1e 1f 20 + * | | 21 22 23 24 + * | | 25 26 27 28 + * | | 29 2a 2b 2c + * | | + * | `------------------- + * | + * `------------------ + */ + { + PacketBB packet; + packet.SetSequenceNumber (28); + + Ptr tlv1 = Create (); + tlv1->SetType (1); + packet.TlvPushBack (tlv1); + + Ptr msg1 = Create (); + msg1->SetType (1); + + Ptr msg1tlv1 = Create (); + msg1tlv1->SetType (1); + msg1->TlvPushBack (msg1tlv1); + + packet.MessagePushBack (msg1); + + Ptr msg2 = Create (); + msg2->SetType (2); + msg2->SetOriginatorAddress (Ipv4Address ("10.0.0.1")); + msg2->SetHopLimit (255); + msg2->SetHopCount (1); + msg2->SetSequenceNumber (12345); + + Ptr msg2a1 = Create (); + msg2a1->AddressPushBack (Ipv4Address ("10.0.0.2")); + msg2a1->AddressPushBack (Ipv4Address ("10.1.1.2")); + msg2->AddressBlockPushBack (msg2a1); + + Ptr msg2a2 = Create (); + msg2a2->AddressPushBack (Ipv4Address ("10.0.0.0")); + msg2a2->AddressPushBack (Ipv4Address ("11.0.0.0")); + msg2a2->AddressPushBack (Ipv4Address ("10.0.0.5")); + msg2a2->AddressPushBack (Ipv4Address ("10.0.0.6")); + + msg2a2->PrefixPushBack (32); + msg2a2->PrefixPushBack (32); + msg2a2->PrefixPushBack (16); + msg2a2->PrefixPushBack (24); + + Ptr msg2a2tlv1 = Create (); + msg2a2tlv1->SetType (1); + msg2a2tlv1->SetIndexStart (1); + msg2a2tlv1->SetIndexStop (3); + + uint8_t value[] = { + 0x00, 0x01, 0x02, 0x03, + 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, + 0x0c, 0x0d, 0x0e, 0x0f, + 0x10, 0x11, 0x12, 0x13, + 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1a, 0x1b, + 0x1c, 0x1d, 0x1e, 0x1f, + 0x20, 0x21, 0x22, 0x23, + 0x24, 0x25, 0x26, 0x27, + 0x28, 0x29, 0x2a, 0x2b, + 0x2c, 0x2d, 0x2e, 0x2f, + 0x30, 0x31, 0x32, 0x33, + 0x34, 0x35, 0x36, 0x37, + 0x38, 0x39, 0x3a, 0x3b, + 0x3c, 0x3d, 0x3e, 0x3f, + 0x40, 0x41, 0x42, 0x43, + 0x44, 0x45, 0x46, 0x47, + 0x48, 0x49, 0x4a, 0x4b, + 0x4c, 0x4d, 0x4e, 0x4f, + 0x50, 0x51, 0x52, 0x53, + 0x54, 0x55, 0x56, 0x57, + 0x58, 0x59, 0x5a, 0x5b, + 0x5c, 0x5d, 0x5e, 0x5f, + 0x60, 0x61, 0x62, 0x63, + 0x64, 0x65, 0x66, 0x67, + 0x68, 0x69, 0x6a, 0x6b, + 0x6c, 0x6d, 0x6e, 0x6f, + 0x70, 0x71, 0x72, 0x73, + 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7a, 0x7b, + 0x7c, 0x7d, 0x7e, 0x7f, + 0x80, 0x81, 0x82, 0x83, + 0x84, 0x85, 0x86, 0x87, + 0x88, 0x89, 0x8a, 0x8b, + 0x8c, 0x8d, 0x8e, 0x8f, + 0x90, 0x91, 0x92, 0x93, + 0x94, 0x95, 0x96, 0x97, + 0x98, 0x99, 0x9a, 0x9b, + 0x9c, 0x9d, 0x9e, 0x9f, + 0xa0, 0xa1, 0xa2, 0xa3, + 0xa4, 0xa5, 0xa6, 0xa7, + 0xa8, 0xa9, 0xaa, 0xab, + 0xac, 0xad, 0xae, 0xaf, + 0xb0, 0xb1, 0xb2, 0xb3, + 0xb4, 0xb5, 0xb6, 0xb7, + 0xb8, 0xb9, 0xba, 0xbb, + 0xbc, 0xbd, 0xbe, 0xbf, + 0xc0, 0xc1, 0xc2, 0xc3, + 0xc4, 0xc5, 0xc6, 0xc7, + 0xc8, 0xc9, 0xca, 0xcb, + 0xcc, 0xcd, 0xce, 0xcf, + 0xd0, 0xd1, 0xd2, 0xd3, + 0xd4, 0xd5, 0xd6, 0xd7, + 0xd8, 0xd9, 0xda, 0xdb, + 0xdc, 0xdd, 0xde, 0xdf, + 0xe0, 0xe1, 0xe2, 0xe3, + 0xe4, 0xe5, 0xe6, 0xe7, + 0xe8, 0xe9, 0xea, 0xeb, + 0xec, 0xed, 0xee, 0xef, + 0xf0, 0xf1, 0xf2, 0xf3, + 0xf4, 0xf5, 0xf6, 0xf7, + 0xf8, 0xf9, 0xfa, 0xfb, + 0xfc, 0xfd, 0xfe, 0x00, + 0x01, 0x02, 0x03, 0x04, + 0x05, 0x06, 0x07, 0x08, + 0x09, 0x0a, 0x0b, 0x0c, + 0x0d, 0x0e, 0x0f, 0x10, + 0x11, 0x12, 0x13, 0x14, + 0x15, 0x16, 0x17, 0x18, + 0x19, 0x1a, 0x1b, 0x1c, + 0x1d, 0x1e, 0x1f, 0x20, + 0x21, 0x22, 0x23, 0x24, + 0x25, 0x26, 0x27, 0x28, + 0x29, 0x2a, 0x2b, 0x2c, + }; + msg2a2tlv1->SetValue(value, sizeof (value)); + + msg2a2->TlvPushBack (msg2a2tlv1); + + msg2->AddressBlockPushBack (msg2a2); + + packet.MessagePushBack (msg2); + + uint8_t buffer[] = { + 0x0c, 0x00, 0x1c, 0x00, + 0x02, 0x01, 0x00, 0x01, + 0x03, 0x00, 0x08, 0x00, + 0x02, 0x01, 0x00, 0x02, + 0xf3, 0x01, 0x64, 0x0a, /* [16] - 0xf0 */ + 0x00, 0x00, 0x01, 0xff, + 0x01, 0x30, 0x39, 0x00, + 0x00, 0x02, 0xc0, 0x01, + 0x0a, 0x01, 0x02, 0x00, + 0x00, 0x01, 0x01, 0x00, + 0x00, 0x04, 0x08, 0x0a, + 0x00, 0x00, 0x00, 0x0b, + 0x00, 0x00, 0x00, 0x0a, + 0x00, 0x00, 0x05, 0x0a, + 0x00, 0x00, 0x06, 0x20, + 0x20, 0x10, 0x18, 0x01, + 0x32, 0x01, 0x38, 0x01, + 0x03, 0x01, 0x2c, 0x00, + 0x01, 0x02, 0x03, 0x04, + 0x05, 0x06, 0x07, 0x08, + 0x09, 0x0a, 0x0b, 0x0c, + 0x0d, 0x0e, 0x0f, 0x10, + 0x11, 0x12, 0x13, 0x14, + 0x15, 0x16, 0x17, 0x18, + 0x19, 0x1a, 0x1b, 0x1c, + 0x1d, 0x1e, 0x1f, 0x20, + 0x21, 0x22, 0x23, 0x24, + 0x25, 0x26, 0x27, 0x28, + 0x29, 0x2a, 0x2b, 0x2c, + 0x2d, 0x2e, 0x2f, 0x30, + 0x31, 0x32, 0x33, 0x34, + 0x35, 0x36, 0x37, 0x38, + 0x39, 0x3a, 0x3b, 0x3c, + 0x3d, 0x3e, 0x3f, 0x40, + 0x41, 0x42, 0x43, 0x44, + 0x45, 0x46, 0x47, 0x48, + 0x49, 0x4a, 0x4b, 0x4c, + 0x4d, 0x4e, 0x4f, 0x50, + 0x51, 0x52, 0x53, 0x54, + 0x55, 0x56, 0x57, 0x58, + 0x59, 0x5a, 0x5b, 0x5c, + 0x5d, 0x5e, 0x5f, 0x60, + 0x61, 0x62, 0x63, 0x64, + 0x65, 0x66, 0x67, 0x68, + 0x69, 0x6a, 0x6b, 0x6c, + 0x6d, 0x6e, 0x6f, 0x70, + 0x71, 0x72, 0x73, 0x74, + 0x75, 0x76, 0x77, 0x78, + 0x79, 0x7a, 0x7b, 0x7c, + 0x7d, 0x7e, 0x7f, 0x80, + 0x81, 0x82, 0x83, 0x84, + 0x85, 0x86, 0x87, 0x88, + 0x89, 0x8a, 0x8b, 0x8c, + 0x8d, 0x8e, 0x8f, 0x90, + 0x91, 0x92, 0x93, 0x94, + 0x95, 0x96, 0x97, 0x98, + 0x99, 0x9a, 0x9b, 0x9c, + 0x9d, 0x9e, 0x9f, 0xa0, + 0xa1, 0xa2, 0xa3, 0xa4, + 0xa5, 0xa6, 0xa7, 0xa8, + 0xa9, 0xaa, 0xab, 0xac, + 0xad, 0xae, 0xaf, 0xb0, + 0xb1, 0xb2, 0xb3, 0xb4, + 0xb5, 0xb6, 0xb7, 0xb8, + 0xb9, 0xba, 0xbb, 0xbc, + 0xbd, 0xbe, 0xbf, 0xc0, + 0xc1, 0xc2, 0xc3, 0xc4, + 0xc5, 0xc6, 0xc7, 0xc8, + 0xc9, 0xca, 0xcb, 0xcc, + 0xcd, 0xce, 0xcf, 0xd0, + 0xd1, 0xd2, 0xd3, 0xd4, + 0xd5, 0xd6, 0xd7, 0xd8, + 0xd9, 0xda, 0xdb, 0xdc, + 0xdd, 0xde, 0xdf, 0xe0, + 0xe1, 0xe2, 0xe3, 0xe4, + 0xe5, 0xe6, 0xe7, 0xe8, + 0xe9, 0xea, 0xeb, 0xec, + 0xed, 0xee, 0xef, 0xf0, + 0xf1, 0xf2, 0xf3, 0xf4, + 0xf5, 0xf6, 0xf7, 0xf8, + 0xf9, 0xfa, 0xfb, 0xfc, + 0xfd, 0xfe, 0x00, 0x01, + 0x02, 0x03, 0x04, 0x05, + 0x06, 0x07, 0x08, 0x09, + 0x0a, 0x0b, 0x0c, 0x0d, + 0x0e, 0x0f, 0x10, 0x11, + 0x12, 0x13, 0x14, 0x15, + 0x16, 0x17, 0x18, 0x19, + 0x1a, 0x1b, 0x1c, 0x1d, + 0x1e, 0x1f, 0x20, 0x21, + 0x22, 0x23, 0x24, 0x25, + 0x26, 0x27, 0x28, 0x29, + 0x2a, 0x2b, 0x2c + }; + PacketBBTester test(testnum++, packet, buffer, sizeof(buffer)); + } + + /* Test 29 + * ,------------------ + * | PACKET + * |------------------ + * | * Packet version: 0 + * | * Packet flags: 0 + * | ,------------------- + * | | MESSAGE + * | |------------------- + * | | * Message type: 1 + * | | * Message flags: 1 + * | `------------------- + * | + * `------------------ + */ + { + PacketBB packet; + + Ptr m1 = Create (); + m1->SetType(1); + + packet.MessagePushBack (m1); + + uint8_t buffer[] = { + 0x00, 0x01, 0x0f, 0x00, + 0x06, 0x00, 0x00, + }; + PacketBBTester test(testnum++, packet, buffer, sizeof(buffer)); + } + + /* Test 30 + * ,------------------ + * | PACKET + * |------------------ + * | * Packet version: 0 + * | * Packet flags: 0 + * | ,------------------- + * | | MESSAGE + * | |------------------- + * | | * Message type: 1 + * | | * Message flags: 129 + * | | * Originator address: abcd::1 + * | `------------------- + * | + * `------------------ + */ + { + PacketBB packet; + + Ptr m1 = Create (); + m1->SetType(1); + m1->SetOriginatorAddress (Ipv6Address("abcd::1")); + + packet.MessagePushBack (m1); + + uint8_t buffer[] = { + 0x00, 0x01, 0x8f, 0x00, + 0x16, 0xab, 0xcd, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00 + }; + PacketBBTester test(testnum++, packet, buffer, sizeof(buffer)); + } + + /* Test 31 + * ,------------------ + * | PACKET + * |------------------ + * | * Packet version: 0 + * | * Packet flags: 0 + * | ,------------------- + * | | MESSAGE + * | |------------------- + * | | * Message type: 1 + * | | * Message flags: 129 + * | | * Originator address: abcd::1 + * | | - Address block (1 addresses) + * | | - 10::1/128 + * | | - Flags = 0 + * | | - ADDRESS TLV block (0 TLVs) + * | `------------------- + * | + * `------------------ + */ + { + PacketBB packet; + + Ptr m1 = Create (); + m1->SetType(1); + m1->SetOriginatorAddress (Ipv6Address("abcd::1")); + + Ptr m1a1 = Create (); + m1a1->AddressPushBack (Ipv6Address ("10::1")); + m1->AddressBlockPushBack (m1a1); + + packet.MessagePushBack (m1); + + uint8_t buffer[] = { + 0x00, 0x01, 0x8f, 0x00, + 0x2a, 0xab, 0xcd, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x01, + 0x00, 0x00, 0x10, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, + }; + PacketBBTester test(testnum++, packet, buffer, sizeof(buffer)); + } + + /* Test 32 + * ,------------------ + * | PACKET + * |------------------ + * | * Packet version: 0 + * | * Packet flags: 0 + * | ,------------------- + * | | MESSAGE + * | |------------------- + * | | * Message type: 1 + * | | * Message flags: 129 + * | | * Originator address: abcd::1 + * | | - Address block (2 addresses) + * | | - 10::1/128 + * | | - 10::2/128 + * | | - Flags = 128 + * | | - ADDRESS TLV block (0 TLVs) + * | `------------------- + * | + * `------------------ + */ + { + PacketBB packet; + + Ptr m1 = Create (); + m1->SetType(1); + m1->SetOriginatorAddress (Ipv6Address("abcd::1")); + + Ptr m1a1 = Create (); + m1a1->AddressPushBack (Ipv6Address ("10::1")); + m1a1->AddressPushBack (Ipv6Address ("10::2")); + m1->AddressBlockPushBack (m1a1); + + packet.MessagePushBack (m1); + + uint8_t buffer[] = { + 0x00, 0x01, 0x8f, 0x00, + 0x2c, 0xab, 0xcd, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x02, + 0x80, 0x0f, 0x00, 0x10, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x01, 0x02, 0x00, + 0x00, + }; + PacketBBTester test(testnum++, packet, buffer, sizeof(buffer)); + } + + /* Test 33 + * ,------------------ + * | PACKET + * |------------------ + * | * Packet version: 0 + * | * Packet flags: 0 + * | ,------------------- + * | | MESSAGE + * | |------------------- + * | | * Message type: 1 + * | | * Message flags: 129 + * | | * Originator address: abcd::1 + * | | - Address block (2 addresses) + * | | - 10::2/128 + * | | - 10::11:2/128 + * | | - Flags = 192 + * | | - ADDRESS TLV block (0 TLVs) + * | `------------------- + * | + * `------------------ + */ + { + PacketBB packet; + + Ptr m1 = Create (); + m1->SetType(1); + m1->SetOriginatorAddress (Ipv6Address("abcd::1")); + + Ptr m1a1 = Create (); + m1a1->AddressPushBack (Ipv6Address ("10::2")); + m1a1->AddressPushBack (Ipv6Address ("10::11:2")); + m1->AddressBlockPushBack (m1a1); + + packet.MessagePushBack (m1); + + uint8_t buffer[] = { + 0x00, 0x01, 0x8f, 0x00, + 0x2d, 0xab, 0xcd, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x02, + 0xc0, 0x0d, 0x00, 0x10, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x02, + 0x00, 0x02, 0x00, 0x11, + 0x00, 0x00, + }; + PacketBBTester test(testnum++, packet, buffer, sizeof(buffer)); + } + + /* Test 34 + * ,------------------ + * | PACKET + * |------------------ + * | * Packet version: 0 + * | * Packet flags: 0 + * | ,------------------- + * | | MESSAGE + * | |------------------- + * | | * Message type: 1 + * | | * Message flags: 129 + * | | * Originator address: abcd::1 + * | | - Address block (2 addresses) + * | | - 10::2/128 + * | | - 10::11:2/128 + * | | - Flags = 192 + * | | - ADDRESS TLV block (0 TLVs) + * | | - Address block (2 addresses) + * | | - 10::/128 + * | | - 11::/128 + * | | - Flags = 160 + * | | - ADDRESS TLV block (0 TLVs) + * | `------------------- + * | + * `------------------ + */ + { + PacketBB packet; + + Ptr m1 = Create (); + m1->SetType(1); + m1->SetOriginatorAddress (Ipv6Address("abcd::1")); + + Ptr m1a1 = Create (); + m1a1->AddressPushBack (Ipv6Address ("10::2")); + m1a1->AddressPushBack (Ipv6Address ("10::11:2")); + m1->AddressBlockPushBack (m1a1); + + Ptr m1a2 = Create (); + m1a2->AddressPushBack (Ipv6Address ("10::")); + m1a2->AddressPushBack (Ipv6Address ("11::")); + m1->AddressBlockPushBack (m1a2); + + packet.MessagePushBack (m1); + + uint8_t buffer[] = { + 0x00, 0x01, 0x8f, 0x00, + 0x36, 0xab, 0xcd, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x02, + 0xc0, 0x0d, 0x00, 0x10, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x02, + 0x00, 0x02, 0x00, 0x11, + 0x00, 0x00, 0x02, 0xa0, + 0x01, 0x00, 0x0e, 0x10, + 0x11, 0x00, 0x00, + }; + PacketBBTester test(testnum++, packet, buffer, sizeof(buffer)); + } + + /* Test 35 + * ,------------------ + * | PACKET + * |------------------ + * | * Packet version: 0 + * | * Packet flags: 0 + * | ,------------------- + * | | MESSAGE + * | |------------------- + * | | * Message type: 1 + * | | * Message flags: 129 + * | | * Originator address: abcd::1 + * | | - Address block (2 addresses) + * | | - 10::2/128 + * | | - 10::11:2/128 + * | | - Flags = 192 + * | | - ADDRESS TLV block (0 TLVs) + * | | - Address block (4 addresses) + * | | - 10::/128 + * | | - 11::/128 + * | | - 10::5/64 + * | | - 10::6/48 + * | | - Flags = 136 + * | | - ADDRESS TLV block (0 TLVs) + * | `------------------- + * | + * `------------------ + */ + { + PacketBB packet; + + Ptr m1 = Create (); + m1->SetType(1); + m1->SetOriginatorAddress (Ipv6Address("abcd::1")); + + Ptr m1a1 = Create (); + m1a1->AddressPushBack (Ipv6Address ("10::2")); + m1a1->AddressPushBack (Ipv6Address ("10::11:2")); + m1->AddressBlockPushBack (m1a1); + + Ptr m1a2 = Create (); + m1a2->AddressPushBack (Ipv6Address ("10::")); + m1a2->AddressPushBack (Ipv6Address ("11::")); + m1a2->AddressPushBack (Ipv6Address ("10::5")); + m1a2->AddressPushBack (Ipv6Address ("10::6")); + m1a2->PrefixPushBack (128); + m1a2->PrefixPushBack (128); + m1a2->PrefixPushBack (64); + m1a2->PrefixPushBack (48); + m1->AddressBlockPushBack (m1a2); + + packet.MessagePushBack (m1); + + uint8_t buffer[] = { + 0x00, 0x01, 0x8f, 0x00, + 0x73, 0xab, 0xcd, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x02, + 0xc0, 0x0d, 0x00, 0x10, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x02, + 0x00, 0x02, 0x00, 0x11, + 0x00, 0x00, 0x04, 0x88, + 0x01, 0x00, 0x10, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x11, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x05, 0x10, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x06, 0x80, 0x80, + 0x40, 0x30, 0x00, 0x00, + }; + PacketBBTester test(testnum++, packet, buffer, sizeof(buffer)); + } + + /* Test 36 + * ,------------------ + * | PACKET + * |------------------ + * | * Packet version: 0 + * | * Packet flags: 12 + * | * Packet seq number: 29 + * | | * Packet TLV Block + * | | - TLV + * | | Flags = 0 + * | | Type = 1; Value = (warning: parameter is NULL) + * | ,------------------- + * | | MESSAGE + * | |------------------- + * | | * Message type: 1 + * | | * Message flags: 0 + * | | * Message TLV Block + * | | - TLV + * | | Flags = 0 + * | | Type = 1; Value = (warning: parameter is NULL) + * | `------------------- + * | + * | ,------------------- + * | | MESSAGE + * | |------------------- + * | | * Message type: 2 + * | | * Message flags: 240 + * | | * Originator address: 10.0.0.1 + * | | * Hop limit: 255 + * | | * Hop count: 1 + * | | * Message seq number: 12345 + * | | - Address block (2 addresses) + * | | - 10.0.0.2/32 + * | | - 10.1.1.2/32 + * | | - Flags = 192 + * | | - ADDRESS TLV block (0 TLVs) + * | | - Address block (4 addresses) + * | | - 10.0.0.0/32 + * | | - 11.0.0.0/32 + * | | - 10.0.0.5/16 + * | | - 10.0.0.6/24 + * | | - Flags = 8 + * | | - ADDRESS TLV block (1 TLVs) + * | | - TLV + * | | Flags = 56 + * | | Index-start = 1 + * | | Index-stop = 3 + * | | Type = 1; Value = 00 01 02 03 + * | | 04 05 06 07 + * | | 08 09 0a 0b + * | | 0c 0d 0e 0f + * | | 10 11 12 13 + * | | 14 15 16 17 + * | | 18 19 1a 1b + * | | 1c 1d 1e 1f + * | | 20 21 22 23 + * | | 24 25 26 27 + * | | 28 29 2a 2b + * | | 2c 2d 2e 2f + * | | 30 31 32 33 + * | | 34 35 36 37 + * | | 38 39 3a 3b + * | | 3c 3d 3e 3f + * | | 40 41 42 43 + * | | 44 45 46 47 + * | | 48 49 4a 4b + * | | 4c 4d 4e 4f + * | | 50 51 52 53 + * | | 54 55 56 57 + * | | 58 59 5a 5b + * | | 5c 5d 5e 5f + * | | 60 61 62 63 + * | | 64 65 66 67 + * | | 68 69 6a 6b + * | | 6c 6d 6e 6f + * | | 70 71 72 73 + * | | 74 75 76 77 + * | | 78 79 7a 7b + * | | 7c 7d 7e 7f + * | | 80 81 82 83 + * | | 84 85 86 87 + * | | 88 89 8a 8b + * | | 8c 8d 8e 8f + * | | 90 91 92 93 + * | | 94 95 96 97 + * | | 98 99 9a 9b + * | | 9c 9d 9e 9f + * | | a0 a1 a2 a3 + * | | a4 a5 a6 a7 + * | | a8 a9 aa ab + * | | ac ad ae af + * | | b0 b1 b2 b3 + * | | b4 b5 b6 b7 + * | | b8 b9 ba bb + * | | bc bd be bf + * | | c0 c1 c2 c3 + * | | c4 c5 c6 c7 + * | | c8 c9 ca cb + * | | cc cd ce cf + * | | d0 d1 d2 d3 + * | | d4 d5 d6 d7 + * | | d8 d9 da db + * | | dc dd de df + * | | e0 e1 e2 e3 + * | | e4 e5 e6 e7 + * | | e8 e9 ea eb + * | | ec ed ee ef + * | | f0 f1 f2 f3 + * | | f4 f5 f6 f7 + * | | f8 f9 fa fb + * | | fc fd fe 00 + * | | 01 02 03 04 + * | | 05 06 07 08 + * | | 09 0a 0b 0c + * | | 0d 0e 0f 10 + * | | 11 12 13 14 + * | | 15 16 17 18 + * | | 19 1a 1b 1c + * | | 1d 1e 1f 20 + * | | 21 22 23 24 + * | | 25 26 27 28 + * | | 29 2a 2b 2c + * | | + * | `------------------- + * | + * | ,------------------- + * | | MESSAGE + * | |------------------- + * | | * Message type: 1 + * | | * Message flags: 129 + * | | * Originator address: abcd::1 + * | | - Address block (2 addresses) + * | | - 10::2/128 + * | | - 10::11:2/128 + * | | - Flags = 192 + * | | - ADDRESS TLV block (0 TLVs) + * | | - Address block (4 addresses) + * | | - 10::/128 + * | | - 11::/128 + * | | - 10::5/64 + * | | - 10::6/48 + * | | - Flags = 136 + * | | - ADDRESS TLV block (0 TLVs) + * | `------------------- + * | + * `------------------ + */ + { + PacketBB packet; + packet.SetSequenceNumber (29); + + Ptr ptlv1 = Create (); + ptlv1->SetType (1); + packet.TlvPushBack (ptlv1); + + Ptr m1 = Create (); + m1->SetType (1); + + Ptr m1tlv1 = Create (); + m1tlv1->SetType (1); + m1->TlvPushBack (m1tlv1); + packet.MessagePushBack (m1); + + Ptr m2 = Create (); + m2->SetType (2); + m2->SetOriginatorAddress (Ipv4Address ("10.0.0.1")); + m2->SetHopLimit (255); + m2->SetHopCount (1); + m2->SetSequenceNumber (12345); + + Ptr m2a1 = Create (); + m2a1->AddressPushBack (Ipv4Address ("10.0.0.2")); + m2a1->AddressPushBack (Ipv4Address ("10.1.1.2")); + m2->AddressBlockPushBack (m2a1); + + Ptr m2a2 = Create (); + m2a2->AddressPushBack (Ipv4Address ("10.0.0.0")); + m2a2->AddressPushBack (Ipv4Address ("11.0.0.0")); + m2a2->AddressPushBack (Ipv4Address ("10.0.0.5")); + m2a2->AddressPushBack (Ipv4Address ("10.0.0.6")); + m2a2->PrefixPushBack (32); + m2a2->PrefixPushBack (32); + m2a2->PrefixPushBack (16); + m2a2->PrefixPushBack (24); + + Ptr m2a2tlv1 = Create (); + m2a2tlv1->SetType (1); + m2a2tlv1->SetIndexStart (1); + m2a2tlv1->SetIndexStop (3); + + uint8_t value[] = { + 0x00, 0x01, 0x02, 0x03, + 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, + 0x0c, 0x0d, 0x0e, 0x0f, + 0x10, 0x11, 0x12, 0x13, + 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1a, 0x1b, + 0x1c, 0x1d, 0x1e, 0x1f, + 0x20, 0x21, 0x22, 0x23, + 0x24, 0x25, 0x26, 0x27, + 0x28, 0x29, 0x2a, 0x2b, + 0x2c, 0x2d, 0x2e, 0x2f, + 0x30, 0x31, 0x32, 0x33, + 0x34, 0x35, 0x36, 0x37, + 0x38, 0x39, 0x3a, 0x3b, + 0x3c, 0x3d, 0x3e, 0x3f, + 0x40, 0x41, 0x42, 0x43, + 0x44, 0x45, 0x46, 0x47, + 0x48, 0x49, 0x4a, 0x4b, + 0x4c, 0x4d, 0x4e, 0x4f, + 0x50, 0x51, 0x52, 0x53, + 0x54, 0x55, 0x56, 0x57, + 0x58, 0x59, 0x5a, 0x5b, + 0x5c, 0x5d, 0x5e, 0x5f, + 0x60, 0x61, 0x62, 0x63, + 0x64, 0x65, 0x66, 0x67, + 0x68, 0x69, 0x6a, 0x6b, + 0x6c, 0x6d, 0x6e, 0x6f, + 0x70, 0x71, 0x72, 0x73, + 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7a, 0x7b, + 0x7c, 0x7d, 0x7e, 0x7f, + 0x80, 0x81, 0x82, 0x83, + 0x84, 0x85, 0x86, 0x87, + 0x88, 0x89, 0x8a, 0x8b, + 0x8c, 0x8d, 0x8e, 0x8f, + 0x90, 0x91, 0x92, 0x93, + 0x94, 0x95, 0x96, 0x97, + 0x98, 0x99, 0x9a, 0x9b, + 0x9c, 0x9d, 0x9e, 0x9f, + 0xa0, 0xa1, 0xa2, 0xa3, + 0xa4, 0xa5, 0xa6, 0xa7, + 0xa8, 0xa9, 0xaa, 0xab, + 0xac, 0xad, 0xae, 0xaf, + 0xb0, 0xb1, 0xb2, 0xb3, + 0xb4, 0xb5, 0xb6, 0xb7, + 0xb8, 0xb9, 0xba, 0xbb, + 0xbc, 0xbd, 0xbe, 0xbf, + 0xc0, 0xc1, 0xc2, 0xc3, + 0xc4, 0xc5, 0xc6, 0xc7, + 0xc8, 0xc9, 0xca, 0xcb, + 0xcc, 0xcd, 0xce, 0xcf, + 0xd0, 0xd1, 0xd2, 0xd3, + 0xd4, 0xd5, 0xd6, 0xd7, + 0xd8, 0xd9, 0xda, 0xdb, + 0xdc, 0xdd, 0xde, 0xdf, + 0xe0, 0xe1, 0xe2, 0xe3, + 0xe4, 0xe5, 0xe6, 0xe7, + 0xe8, 0xe9, 0xea, 0xeb, + 0xec, 0xed, 0xee, 0xef, + 0xf0, 0xf1, 0xf2, 0xf3, + 0xf4, 0xf5, 0xf6, 0xf7, + 0xf8, 0xf9, 0xfa, 0xfb, + 0xfc, 0xfd, 0xfe, 0x00, + 0x01, 0x02, 0x03, 0x04, + 0x05, 0x06, 0x07, 0x08, + 0x09, 0x0a, 0x0b, 0x0c, + 0x0d, 0x0e, 0x0f, 0x10, + 0x11, 0x12, 0x13, 0x14, + 0x15, 0x16, 0x17, 0x18, + 0x19, 0x1a, 0x1b, 0x1c, + 0x1d, 0x1e, 0x1f, 0x20, + 0x21, 0x22, 0x23, 0x24, + 0x25, 0x26, 0x27, 0x28, + 0x29, 0x2a, 0x2b, 0x2c, + }; + m2a2tlv1->SetValue (value, sizeof(value)); + m2a2->TlvPushBack (m2a2tlv1); + + m2->AddressBlockPushBack (m2a2); + packet.MessagePushBack (m2); + + Ptr m3 = Create (); + m3->SetType (1); + m3->SetOriginatorAddress (Ipv6Address ("abcd::1")); + + Ptr m3a1 = Create (); + m3a1->AddressPushBack (Ipv6Address ("10::2")); + m3a1->AddressPushBack (Ipv6Address ("10::11:2")); + m3->AddressBlockPushBack (m3a1); + + Ptr m3a2 = Create (); + m3a2->AddressPushBack (Ipv6Address ("10::")); + m3a2->AddressPushBack (Ipv6Address ("11::")); + m3a2->AddressPushBack (Ipv6Address ("10::5")); + m3a2->AddressPushBack (Ipv6Address ("10::6")); + m3a2->PrefixPushBack (128); + m3a2->PrefixPushBack (128); + m3a2->PrefixPushBack (64); + m3a2->PrefixPushBack (48); + + m3->AddressBlockPushBack (m3a2); + packet.MessagePushBack (m3); + + uint8_t buffer[] = { + 0x0c, 0x00, 0x1d, 0x00, + 0x02, 0x01, 0x00, 0x01, + 0x0f, 0x00, 0x08, 0x00, + 0x02, 0x01, 0x00, 0x02, + 0xf3, 0x01, 0x64, 0x0a, + 0x00, 0x00, 0x01, 0xff, + 0x01, 0x30, 0x39, 0x00, + 0x00, 0x02, 0xc0, 0x01, + 0x0a, 0x01, 0x02, 0x00, + 0x00, 0x01, 0x01, 0x00, + 0x00, 0x04, 0x08, 0x0a, + 0x00, 0x00, 0x00, 0x0b, + 0x00, 0x00, 0x00, 0x0a, + 0x00, 0x00, 0x05, 0x0a, + 0x00, 0x00, 0x06, 0x20, + 0x20, 0x10, 0x18, 0x01, + 0x32, 0x01, 0x38, 0x01, + 0x03, 0x01, 0x2c, 0x00, + 0x01, 0x02, 0x03, 0x04, + 0x05, 0x06, 0x07, 0x08, + 0x09, 0x0a, 0x0b, 0x0c, + 0x0d, 0x0e, 0x0f, 0x10, + 0x11, 0x12, 0x13, 0x14, + 0x15, 0x16, 0x17, 0x18, + 0x19, 0x1a, 0x1b, 0x1c, + 0x1d, 0x1e, 0x1f, 0x20, + 0x21, 0x22, 0x23, 0x24, + 0x25, 0x26, 0x27, 0x28, + 0x29, 0x2a, 0x2b, 0x2c, + 0x2d, 0x2e, 0x2f, 0x30, + 0x31, 0x32, 0x33, 0x34, + 0x35, 0x36, 0x37, 0x38, + 0x39, 0x3a, 0x3b, 0x3c, + 0x3d, 0x3e, 0x3f, 0x40, + 0x41, 0x42, 0x43, 0x44, + 0x45, 0x46, 0x47, 0x48, + 0x49, 0x4a, 0x4b, 0x4c, + 0x4d, 0x4e, 0x4f, 0x50, + 0x51, 0x52, 0x53, 0x54, + 0x55, 0x56, 0x57, 0x58, + 0x59, 0x5a, 0x5b, 0x5c, + 0x5d, 0x5e, 0x5f, 0x60, + 0x61, 0x62, 0x63, 0x64, + 0x65, 0x66, 0x67, 0x68, + 0x69, 0x6a, 0x6b, 0x6c, + 0x6d, 0x6e, 0x6f, 0x70, + 0x71, 0x72, 0x73, 0x74, + 0x75, 0x76, 0x77, 0x78, + 0x79, 0x7a, 0x7b, 0x7c, + 0x7d, 0x7e, 0x7f, 0x80, + 0x81, 0x82, 0x83, 0x84, + 0x85, 0x86, 0x87, 0x88, + 0x89, 0x8a, 0x8b, 0x8c, + 0x8d, 0x8e, 0x8f, 0x90, + 0x91, 0x92, 0x93, 0x94, + 0x95, 0x96, 0x97, 0x98, + 0x99, 0x9a, 0x9b, 0x9c, + 0x9d, 0x9e, 0x9f, 0xa0, + 0xa1, 0xa2, 0xa3, 0xa4, + 0xa5, 0xa6, 0xa7, 0xa8, + 0xa9, 0xaa, 0xab, 0xac, + 0xad, 0xae, 0xaf, 0xb0, + 0xb1, 0xb2, 0xb3, 0xb4, + 0xb5, 0xb6, 0xb7, 0xb8, + 0xb9, 0xba, 0xbb, 0xbc, + 0xbd, 0xbe, 0xbf, 0xc0, + 0xc1, 0xc2, 0xc3, 0xc4, + 0xc5, 0xc6, 0xc7, 0xc8, + 0xc9, 0xca, 0xcb, 0xcc, + 0xcd, 0xce, 0xcf, 0xd0, + 0xd1, 0xd2, 0xd3, 0xd4, + 0xd5, 0xd6, 0xd7, 0xd8, + 0xd9, 0xda, 0xdb, 0xdc, + 0xdd, 0xde, 0xdf, 0xe0, + 0xe1, 0xe2, 0xe3, 0xe4, + 0xe5, 0xe6, 0xe7, 0xe8, + 0xe9, 0xea, 0xeb, 0xec, + 0xed, 0xee, 0xef, 0xf0, + 0xf1, 0xf2, 0xf3, 0xf4, + 0xf5, 0xf6, 0xf7, 0xf8, + 0xf9, 0xfa, 0xfb, 0xfc, + 0xfd, 0xfe, 0x00, 0x01, + 0x02, 0x03, 0x04, 0x05, + 0x06, 0x07, 0x08, 0x09, + 0x0a, 0x0b, 0x0c, 0x0d, + 0x0e, 0x0f, 0x10, 0x11, + 0x12, 0x13, 0x14, 0x15, + 0x16, 0x17, 0x18, 0x19, + 0x1a, 0x1b, 0x1c, 0x1d, + 0x1e, 0x1f, 0x20, 0x21, + 0x22, 0x23, 0x24, 0x25, + 0x26, 0x27, 0x28, 0x29, + 0x2a, 0x2b, 0x2c, 0x01, + 0x8f, 0x00, 0x73, 0xab, + 0xcd, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x01, 0x00, + 0x00, 0x02, 0xc0, 0x0d, + 0x00, 0x10, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x02, 0x00, 0x02, + 0x00, 0x11, 0x00, 0x00, + 0x04, 0x88, 0x01, 0x00, + 0x10, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x11, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x10, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x05, 0x10, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x06, + 0x80, 0x80, 0x40, 0x30, + 0x00, 0x00, + }; + PacketBBTester test(testnum++, packet, buffer, sizeof(buffer)); + } + + /* Test 37 + * ,------------------ + * | PACKET + * |------------------ + * | * Packet version: 0 + * | * Packet flags: 12 + * | * Packet seq number: 30 + * | | * Packet TLV Block + * | | - TLV + * | | Flags = 0 + * | | Type = 1; Value = (warning: parameter is NULL) + * | ,------------------- + * | | MESSAGE + * | |------------------- + * | | * Message type: 1 + * | | * Message flags: 0 + * | | * Message TLV Block + * | | - TLV + * | | Flags = 0 + * | | Type = 1; Value = (warning: parameter is NULL) + * | `------------------- + * | + * | ,------------------- + * | | MESSAGE + * | |------------------- + * | | * Message type: 2 + * | | * Message flags: 240 + * | | * Originator address: 10.0.0.1 + * | | * Hop limit: 255 + * | | * Hop count: 1 + * | | * Message seq number: 12345 + * | | - Address block (2 addresses) + * | | - 10.0.0.2/32 + * | | - 10.1.1.2/32 + * | | - Flags = 192 + * | | - ADDRESS TLV block (0 TLVs) + * | | - Address block (4 addresses) + * | | - 10.0.0.0/32 + * | | - 11.0.0.0/32 + * | | - 10.0.0.5/16 + * | | - 10.0.0.6/24 + * | | - Flags = 8 + * | | - ADDRESS TLV block (1 TLVs) + * | | - TLV + * | | Flags = 56 + * | | Index-start = 1 + * | | Index-stop = 3 + * | | Type = 1; Value = 00 01 02 03 + * | | 04 05 06 07 + * | | 08 09 0a 0b + * | | 0c 0d 0e 0f + * | | 10 11 12 13 + * | | 14 15 16 17 + * | | 18 19 1a 1b + * | | 1c 1d 1e 1f + * | | 20 21 22 23 + * | | 24 25 26 27 + * | | 28 29 2a 2b + * | | 2c 2d 2e 2f + * | | 30 31 32 33 + * | | 34 35 36 37 + * | | 38 39 3a 3b + * | | 3c 3d 3e 3f + * | | 40 41 42 43 + * | | 44 45 46 47 + * | | 48 49 4a 4b + * | | 4c 4d 4e 4f + * | | 50 51 52 53 + * | | 54 55 56 57 + * | | 58 59 5a 5b + * | | 5c 5d 5e 5f + * | | 60 61 62 63 + * | | 64 65 66 67 + * | | 68 69 6a 6b + * | | 6c 6d 6e 6f + * | | 70 71 72 73 + * | | 74 75 76 77 + * | | 78 79 7a 7b + * | | 7c 7d 7e 7f + * | | 80 81 82 83 + * | | 84 85 86 87 + * | | 88 89 8a 8b + * | | 8c 8d 8e 8f + * | | 90 91 92 93 + * | | 94 95 96 97 + * | | 98 99 9a 9b + * | | 9c 9d 9e 9f + * | | a0 a1 a2 a3 + * | | a4 a5 a6 a7 + * | | a8 a9 aa ab + * | | ac ad ae af + * | | b0 b1 b2 b3 + * | | b4 b5 b6 b7 + * | | b8 b9 ba bb + * | | bc bd be bf + * | | c0 c1 c2 c3 + * | | c4 c5 c6 c7 + * | | c8 c9 ca cb + * | | cc cd ce cf + * | | d0 d1 d2 d3 + * | | d4 d5 d6 d7 + * | | d8 d9 da db + * | | dc dd de df + * | | e0 e1 e2 e3 + * | | e4 e5 e6 e7 + * | | e8 e9 ea eb + * | | ec ed ee ef + * | | f0 f1 f2 f3 + * | | f4 f5 f6 f7 + * | | f8 f9 fa fb + * | | fc fd fe 00 + * | | 01 02 03 04 + * | | 05 06 07 08 + * | | 09 0a 0b 0c + * | | 0d 0e 0f 10 + * | | 11 12 13 14 + * | | 15 16 17 18 + * | | 19 1a 1b 1c + * | | 1d 1e 1f 20 + * | | 21 22 23 24 + * | | 25 26 27 28 + * | | 29 2a 2b 2c + * | | + * | `------------------- + * | + * | ,------------------- + * | | MESSAGE + * | |------------------- + * | | * Message type: 1 + * | | * Message flags: 129 + * | | * Originator address: abcd::1 + * | | - Address block (2 addresses) + * | | - 10::2/128 + * | | - 10::11:2/128 + * | | - Flags = 192 + * | | - ADDRESS TLV block (0 TLVs) + * | | - Address block (4 addresses) + * | | - 10::/128 + * | | - 11::/128 + * | | - 10::5/64 + * | | - 10::6/48 + * | | - Flags = 136 + * | | - ADDRESS TLV block (0 TLVs) + * | `------------------- + * | + * `------------------ + */ + { + PacketBB packet; + packet.SetSequenceNumber (30); + + Ptr ptlv1 = Create (); + ptlv1->SetType (1); + packet.TlvPushBack (ptlv1); + + Ptr m1 = Create (); + m1->SetType (1); + + Ptr m1tlv1 = Create (); + m1tlv1->SetType (1); + m1->TlvPushBack (m1tlv1); + packet.MessagePushBack (m1); + + Ptr m2 = Create (); + m2->SetType (2); + m2->SetOriginatorAddress (Ipv4Address ("10.0.0.1")); + m2->SetHopLimit (255); + m2->SetHopCount (1); + m2->SetSequenceNumber (12345); + + Ptr m2a1 = Create (); + m2a1->AddressPushBack (Ipv4Address ("10.0.0.2")); + m2a1->AddressPushBack (Ipv4Address ("10.1.1.2")); + m2->AddressBlockPushBack (m2a1); + + Ptr m2a2 = Create (); + m2a2->AddressPushBack (Ipv4Address ("10.0.0.0")); + m2a2->AddressPushBack (Ipv4Address ("11.0.0.0")); + m2a2->AddressPushBack (Ipv4Address ("10.0.0.5")); + m2a2->AddressPushBack (Ipv4Address ("10.0.0.6")); + m2a2->PrefixPushBack (32); + m2a2->PrefixPushBack (32); + m2a2->PrefixPushBack (16); + m2a2->PrefixPushBack (24); + + Ptr m2a2tlv1 = Create (); + m2a2tlv1->SetType (1); + m2a2tlv1->SetIndexStart (1); + m2a2tlv1->SetIndexStop (3); + + uint8_t value[] = { + 0x00, 0x01, 0x02, 0x03, + 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, + 0x0c, 0x0d, 0x0e, 0x0f, + 0x10, 0x11, 0x12, 0x13, + 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1a, 0x1b, + 0x1c, 0x1d, 0x1e, 0x1f, + 0x20, 0x21, 0x22, 0x23, + 0x24, 0x25, 0x26, 0x27, + 0x28, 0x29, 0x2a, 0x2b, + 0x2c, 0x2d, 0x2e, 0x2f, + 0x30, 0x31, 0x32, 0x33, + 0x34, 0x35, 0x36, 0x37, + 0x38, 0x39, 0x3a, 0x3b, + 0x3c, 0x3d, 0x3e, 0x3f, + 0x40, 0x41, 0x42, 0x43, + 0x44, 0x45, 0x46, 0x47, + 0x48, 0x49, 0x4a, 0x4b, + 0x4c, 0x4d, 0x4e, 0x4f, + 0x50, 0x51, 0x52, 0x53, + 0x54, 0x55, 0x56, 0x57, + 0x58, 0x59, 0x5a, 0x5b, + 0x5c, 0x5d, 0x5e, 0x5f, + 0x60, 0x61, 0x62, 0x63, + 0x64, 0x65, 0x66, 0x67, + 0x68, 0x69, 0x6a, 0x6b, + 0x6c, 0x6d, 0x6e, 0x6f, + 0x70, 0x71, 0x72, 0x73, + 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7a, 0x7b, + 0x7c, 0x7d, 0x7e, 0x7f, + 0x80, 0x81, 0x82, 0x83, + 0x84, 0x85, 0x86, 0x87, + 0x88, 0x89, 0x8a, 0x8b, + 0x8c, 0x8d, 0x8e, 0x8f, + 0x90, 0x91, 0x92, 0x93, + 0x94, 0x95, 0x96, 0x97, + 0x98, 0x99, 0x9a, 0x9b, + 0x9c, 0x9d, 0x9e, 0x9f, + 0xa0, 0xa1, 0xa2, 0xa3, + 0xa4, 0xa5, 0xa6, 0xa7, + 0xa8, 0xa9, 0xaa, 0xab, + 0xac, 0xad, 0xae, 0xaf, + 0xb0, 0xb1, 0xb2, 0xb3, + 0xb4, 0xb5, 0xb6, 0xb7, + 0xb8, 0xb9, 0xba, 0xbb, + 0xbc, 0xbd, 0xbe, 0xbf, + 0xc0, 0xc1, 0xc2, 0xc3, + 0xc4, 0xc5, 0xc6, 0xc7, + 0xc8, 0xc9, 0xca, 0xcb, + 0xcc, 0xcd, 0xce, 0xcf, + 0xd0, 0xd1, 0xd2, 0xd3, + 0xd4, 0xd5, 0xd6, 0xd7, + 0xd8, 0xd9, 0xda, 0xdb, + 0xdc, 0xdd, 0xde, 0xdf, + 0xe0, 0xe1, 0xe2, 0xe3, + 0xe4, 0xe5, 0xe6, 0xe7, + 0xe8, 0xe9, 0xea, 0xeb, + 0xec, 0xed, 0xee, 0xef, + 0xf0, 0xf1, 0xf2, 0xf3, + 0xf4, 0xf5, 0xf6, 0xf7, + 0xf8, 0xf9, 0xfa, 0xfb, + 0xfc, 0xfd, 0xfe, 0x00, + 0x01, 0x02, 0x03, 0x04, + 0x05, 0x06, 0x07, 0x08, + 0x09, 0x0a, 0x0b, 0x0c, + 0x0d, 0x0e, 0x0f, 0x10, + 0x11, 0x12, 0x13, 0x14, + 0x15, 0x16, 0x17, 0x18, + 0x19, 0x1a, 0x1b, 0x1c, + 0x1d, 0x1e, 0x1f, 0x20, + 0x21, 0x22, 0x23, 0x24, + 0x25, 0x26, 0x27, 0x28, + 0x29, 0x2a, 0x2b, 0x2c, + }; + m2a2tlv1->SetValue (value, sizeof(value)); + m2a2->TlvPushBack (m2a2tlv1); + + m2->AddressBlockPushBack (m2a2); + packet.MessagePushBack (m2); + + Ptr m3 = Create (); + m3->SetType (1); + m3->SetOriginatorAddress (Ipv6Address ("abcd::1")); + + Ptr m3a1 = Create (); + m3a1->AddressPushBack (Ipv6Address ("10::2")); + m3a1->AddressPushBack (Ipv6Address ("10::11:2")); + m3->AddressBlockPushBack (m3a1); + + Ptr m3a2 = Create (); + m3a2->AddressPushBack (Ipv6Address ("10::")); + m3a2->AddressPushBack (Ipv6Address ("11::")); + m3a2->AddressPushBack (Ipv6Address ("10::5")); + m3a2->AddressPushBack (Ipv6Address ("10::6")); + m3a2->PrefixPushBack (128); + m3a2->PrefixPushBack (128); + m3a2->PrefixPushBack (64); + m3a2->PrefixPushBack (48); + + m3->AddressBlockPushBack (m3a2); + packet.MessagePushBack (m3); + + uint8_t buffer[] = { + 0x0c, 0x00, 0x1e, 0x00, + 0x02, 0x01, 0x00, 0x01, + 0x0f, 0x00, 0x08, 0x00, + 0x02, 0x01, 0x00, 0x02, + 0xf3, 0x01, 0x64, 0x0a, + 0x00, 0x00, 0x01, 0xff, + 0x01, 0x30, 0x39, 0x00, + 0x00, 0x02, 0xc0, 0x01, + 0x0a, 0x01, 0x02, 0x00, + 0x00, 0x01, 0x01, 0x00, + 0x00, 0x04, 0x08, 0x0a, + 0x00, 0x00, 0x00, 0x0b, + 0x00, 0x00, 0x00, 0x0a, + 0x00, 0x00, 0x05, 0x0a, + 0x00, 0x00, 0x06, 0x20, + 0x20, 0x10, 0x18, 0x01, + 0x32, 0x01, 0x38, 0x01, + 0x03, 0x01, 0x2c, 0x00, + 0x01, 0x02, 0x03, 0x04, + 0x05, 0x06, 0x07, 0x08, + 0x09, 0x0a, 0x0b, 0x0c, + 0x0d, 0x0e, 0x0f, 0x10, + 0x11, 0x12, 0x13, 0x14, + 0x15, 0x16, 0x17, 0x18, + 0x19, 0x1a, 0x1b, 0x1c, + 0x1d, 0x1e, 0x1f, 0x20, + 0x21, 0x22, 0x23, 0x24, + 0x25, 0x26, 0x27, 0x28, + 0x29, 0x2a, 0x2b, 0x2c, + 0x2d, 0x2e, 0x2f, 0x30, + 0x31, 0x32, 0x33, 0x34, + 0x35, 0x36, 0x37, 0x38, + 0x39, 0x3a, 0x3b, 0x3c, + 0x3d, 0x3e, 0x3f, 0x40, + 0x41, 0x42, 0x43, 0x44, + 0x45, 0x46, 0x47, 0x48, + 0x49, 0x4a, 0x4b, 0x4c, + 0x4d, 0x4e, 0x4f, 0x50, + 0x51, 0x52, 0x53, 0x54, + 0x55, 0x56, 0x57, 0x58, + 0x59, 0x5a, 0x5b, 0x5c, + 0x5d, 0x5e, 0x5f, 0x60, + 0x61, 0x62, 0x63, 0x64, + 0x65, 0x66, 0x67, 0x68, + 0x69, 0x6a, 0x6b, 0x6c, + 0x6d, 0x6e, 0x6f, 0x70, + 0x71, 0x72, 0x73, 0x74, + 0x75, 0x76, 0x77, 0x78, + 0x79, 0x7a, 0x7b, 0x7c, + 0x7d, 0x7e, 0x7f, 0x80, + 0x81, 0x82, 0x83, 0x84, + 0x85, 0x86, 0x87, 0x88, + 0x89, 0x8a, 0x8b, 0x8c, + 0x8d, 0x8e, 0x8f, 0x90, + 0x91, 0x92, 0x93, 0x94, + 0x95, 0x96, 0x97, 0x98, + 0x99, 0x9a, 0x9b, 0x9c, + 0x9d, 0x9e, 0x9f, 0xa0, + 0xa1, 0xa2, 0xa3, 0xa4, + 0xa5, 0xa6, 0xa7, 0xa8, + 0xa9, 0xaa, 0xab, 0xac, + 0xad, 0xae, 0xaf, 0xb0, + 0xb1, 0xb2, 0xb3, 0xb4, + 0xb5, 0xb6, 0xb7, 0xb8, + 0xb9, 0xba, 0xbb, 0xbc, + 0xbd, 0xbe, 0xbf, 0xc0, + 0xc1, 0xc2, 0xc3, 0xc4, + 0xc5, 0xc6, 0xc7, 0xc8, + 0xc9, 0xca, 0xcb, 0xcc, + 0xcd, 0xce, 0xcf, 0xd0, + 0xd1, 0xd2, 0xd3, 0xd4, + 0xd5, 0xd6, 0xd7, 0xd8, + 0xd9, 0xda, 0xdb, 0xdc, + 0xdd, 0xde, 0xdf, 0xe0, + 0xe1, 0xe2, 0xe3, 0xe4, + 0xe5, 0xe6, 0xe7, 0xe8, + 0xe9, 0xea, 0xeb, 0xec, + 0xed, 0xee, 0xef, 0xf0, + 0xf1, 0xf2, 0xf3, 0xf4, + 0xf5, 0xf6, 0xf7, 0xf8, + 0xf9, 0xfa, 0xfb, 0xfc, + 0xfd, 0xfe, 0x00, 0x01, + 0x02, 0x03, 0x04, 0x05, + 0x06, 0x07, 0x08, 0x09, + 0x0a, 0x0b, 0x0c, 0x0d, + 0x0e, 0x0f, 0x10, 0x11, + 0x12, 0x13, 0x14, 0x15, + 0x16, 0x17, 0x18, 0x19, + 0x1a, 0x1b, 0x1c, 0x1d, + 0x1e, 0x1f, 0x20, 0x21, + 0x22, 0x23, 0x24, 0x25, + 0x26, 0x27, 0x28, 0x29, + 0x2a, 0x2b, 0x2c, 0x01, + 0x8f, 0x00, 0x73, 0xab, + 0xcd, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x01, 0x00, + 0x00, 0x02, 0xc0, 0x0d, + 0x00, 0x10, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x02, 0x00, 0x02, + 0x00, 0x11, 0x00, 0x00, + 0x04, 0x88, 0x01, 0x00, + 0x10, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x11, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x10, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x05, 0x10, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x06, + 0x80, 0x80, 0x40, 0x30, + 0x00, 0x00, + }; + PacketBBTester test(testnum++, packet, buffer, sizeof(buffer)); + } +} diff --git a/src/contrib/wscript b/src/contrib/wscript index 046958dda..f63225935 100644 --- a/src/contrib/wscript +++ b/src/contrib/wscript @@ -30,6 +30,7 @@ def build(bld): 'attribute-default-iterator.cc', 'file-config.cc', 'raw-text-config.cc', + 'packetbb.cc', ] headers = bld.new_task_gen('ns3header') @@ -41,6 +42,7 @@ def build(bld): 'file-config.h', 'config-store.h', 'flow-id-tag.h', + 'packetbb.h', ] if bld.env['ENABLE_GTK_CONFIG_STORE']: From 5ee5fd9c8c2662adabeaa0dd6044befd9f57fcf1 Mon Sep 17 00:00:00 2001 From: Tom Wambold Date: Fri, 21 Aug 2009 16:23:41 -0400 Subject: [PATCH 02/12] Minor style fixes. --- src/contrib/packetbb.cc | 1155 ++++++++++++++++++---------------- src/contrib/packetbb.h | 47 +- src/contrib/test-packetbb.cc | 91 +-- 3 files changed, 694 insertions(+), 599 deletions(-) diff --git a/src/contrib/packetbb.cc b/src/contrib/packetbb.cc index 12bb426fe..9293e44bf 100644 --- a/src/contrib/packetbb.cc +++ b/src/contrib/packetbb.cc @@ -1,5 +1,5 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/* vim: set noai ts=2 sw=2 expandtab: */ +/* vim: set ts=2 sw=2 sta expandtab ai si cin: */ /* * Copyright (c) 2009 Drexel University * @@ -111,7 +111,6 @@ TlvBlock::Back (void) const void TlvBlock::PushFront (Ptr tlv) { - //Ptr * newptr = new Ptr (GetPointer (tlv)); m_tlvList.push_front (tlv); } @@ -124,7 +123,6 @@ TlvBlock::PopFront (void) void TlvBlock::PushBack (Ptr tlv) { - //Ptr * newptr = new Ptr (GetPointer (tlv)); m_tlvList.push_back (tlv); } @@ -164,9 +162,9 @@ TlvBlock::GetSerializedSize (void) const /* tlv size */ uint32_t size = 2; for (ConstIterator iter = Begin (); iter != End (); iter++) - { - size += (*iter)->GetSerializedSize (); - } + { + size += (*iter)->GetSerializedSize (); + } return size; } @@ -174,19 +172,19 @@ void TlvBlock::Serialize (Buffer::Iterator &start) const { if (Empty ()) - { - start.WriteHtonU16 (0); - return; - } + { + start.WriteHtonU16 (0); + return; + } /* We need to write the size of the TLV block in front, so save its * position. */ Buffer::Iterator tlvsize = start; start.Next (2); for (ConstIterator iter = Begin (); iter != End (); iter++) - { - (*iter)->Serialize (start); - } + { + (*iter)->Serialize (start); + } /* - 2 to not include the size field */ uint16_t size = start.GetDistanceFrom (tlvsize) - 2; tlvsize.WriteHtonU16 (size); @@ -199,17 +197,14 @@ TlvBlock::Deserialize (Buffer::Iterator &start) Buffer::Iterator tlvstart = start; if (size > 0) - { - while (start.GetDistanceFrom (tlvstart) < size) { - Ptr newtlv = Create (); - //Tlv * newtlv = new Tlv (); - newtlv->Deserialize (start); - - //Ptr * newptr = new Ptr (newtlv); - PushBack (newtlv); + while (start.GetDistanceFrom (tlvstart) < size) + { + Ptr newtlv = Create (); + newtlv->Deserialize (start); + PushBack (newtlv); + } } - } } void @@ -223,15 +218,19 @@ TlvBlock::Print (std::ostream &os, int level) const { std::string prefix = ""; for (int i = 0; i < level; i++) - prefix.append("\t"); + { + prefix.append("\t"); + } os << prefix << "TLV Block {" << std::endl; os << prefix << "\tsize = " << Size () << std::endl; os << prefix << "\tmembers [" << std::endl; + for (ConstIterator iter = Begin (); iter != End (); iter++) - { - (*iter)->Print (os, level+2); - } + { + (*iter)->Print (os, level+2); + } + os << prefix << "\t]" << std::endl; os << prefix << "}" << std::endl; } @@ -240,16 +239,20 @@ bool TlvBlock::operator== (const TlvBlock &other) const { if (Size () != other.Size ()) - return false; + { + return false; + } ConstIterator ti, oi; for (ti = Begin (), oi = other.Begin (); ti != End () && oi != other.End (); ti++, oi++) - { - if (**ti != **oi) - return false; - } + { + if (**ti != **oi) + { + return false; + } + } return true; } @@ -363,9 +366,9 @@ AddressTlvBlock::GetSerializedSize (void) const /* tlv size */ uint32_t size = 2; for (ConstIterator iter = Begin (); iter != End (); iter++) - { - size += (*iter)->GetSerializedSize (); - } + { + size += (*iter)->GetSerializedSize (); + } return size; } @@ -373,19 +376,19 @@ void AddressTlvBlock::Serialize (Buffer::Iterator &start) const { if (Empty ()) - { - start.WriteHtonU16 (0); - return; - } + { + start.WriteHtonU16 (0); + return; + } /* We need to write the size of the TLV block in front, so save its * position. */ Buffer::Iterator tlvsize = start; start.Next (2); for (ConstIterator iter = Begin (); iter != End (); iter++) - { - (*iter)->Serialize (start); - } + { + (*iter)->Serialize (start); + } /* - 2 to not include the size field */ uint16_t size = start.GetDistanceFrom (tlvsize) - 2; tlvsize.WriteHtonU16 (size); @@ -398,17 +401,14 @@ AddressTlvBlock::Deserialize (Buffer::Iterator &start) Buffer::Iterator tlvstart = start; if (size > 0) - { - while (start.GetDistanceFrom (tlvstart) < size) { - Ptr newtlv = Create (); - //AddressTlv * newtlv = new AddressTlv (); - newtlv->Deserialize (start); - - //Ptr * newptr = new Ptr (newtlv); - PushBack (newtlv); + while (start.GetDistanceFrom (tlvstart) < size) + { + Ptr newtlv = Create (); + newtlv->Deserialize (start); + PushBack (newtlv); + } } - } } void @@ -422,15 +422,19 @@ AddressTlvBlock::Print (std::ostream &os, int level) const { std::string prefix = ""; for (int i = 0; i < level; i++) - prefix.append("\t"); + { + prefix.append("\t"); + } os << prefix << "TLV Block {" << std::endl; os << prefix << "\tsize = " << Size () << std::endl; os << prefix << "\tmembers [" << std::endl; + for (ConstIterator iter = Begin (); iter != End (); iter++) - { - (*iter)->Print (os, level+2); - } + { + (*iter)->Print (os, level+2); + } + os << prefix << "\t]" << std::endl; os << prefix << "}" << std::endl; } @@ -439,16 +443,20 @@ bool AddressTlvBlock::operator== (const AddressTlvBlock &other) const { if (Size () != other.Size ()) - return false; + { + return false; + } ConstIterator it, ot; for (it = Begin (), ot = other.Begin (); it != End () && ot != other.End (); it++, ot++) - { - if (**it != **ot) - return false; - } + { + if (**it != **ot) + { + return false; + } + } return true; } @@ -482,12 +490,8 @@ PacketBB::SetSequenceNumber (uint16_t number) } uint16_t -PacketBB::GetSequenceNumber (void) const throw (PacketBBError) +PacketBB::GetSequenceNumber (void) const { - if (!HasSequenceNumber ()) - { - throw PacketBBError ("Packet has no sequence number."); - } return m_seqnum; } @@ -717,9 +721,9 @@ PacketBB::Unref (void) const { m_refCount--; if (m_refCount == 0) - { - delete this; - } + { + delete this; + } } TypeId @@ -745,18 +749,21 @@ PacketBB::GetSerializedSize (void) const uint32_t size = 1; if (HasSequenceNumber()) - { - size += 2; - } + { + size += 2; + } if (!TlvEmpty ()) - size += m_tlvList.GetSerializedSize (); + { + size += m_tlvList.GetSerializedSize (); + } - for (ConstMessageIterator iter = MessageBegin (); iter != MessageEnd (); + for (ConstMessageIterator iter = MessageBegin (); + iter != MessageEnd (); iter++) - { - size += (*iter)->GetSerializedSize (); - } + { + size += (*iter)->GetSerializedSize (); + } return size; } @@ -774,25 +781,25 @@ PacketBB::Serialize (Buffer::Iterator start) const flags <<= 4; if (HasSequenceNumber ()) - { - flags |= PHAS_SEQ_NUM; - start.WriteHtonU16 (GetSequenceNumber ()); - } + { + flags |= PHAS_SEQ_NUM; + start.WriteHtonU16 (GetSequenceNumber ()); + } if (!TlvEmpty ()) - { - flags |= PHAS_TLV; - m_tlvList.Serialize (start); - } + { + flags |= PHAS_TLV; + m_tlvList.Serialize (start); + } bufref.WriteU8(flags); for (ConstMessageIterator iter = MessageBegin (); iter != MessageEnd (); iter++) - { - (*iter)->Serialize (start); - } + { + (*iter)->Serialize (start); + } } uint32_t @@ -803,18 +810,24 @@ PacketBB::Deserialize (Buffer::Iterator start) uint8_t flags = start.ReadU8 (); if (flags & PHAS_SEQ_NUM) - SetSequenceNumber (start.ReadNtohU16 ()); + { + SetSequenceNumber (start.ReadNtohU16 ()); + } if (flags & PHAS_TLV) - m_tlvList.Deserialize (start); + { + m_tlvList.Deserialize (start); + } while (!start.IsEnd()) - { - Ptr newmsg = Message::DeserializeMessage (start); - //Message * newmsg = Message::DeserializeMessage (start); - //Ptr * newptr = new Ptr (newmsg); - MessagePushBack (newmsg); - } + { + Ptr newmsg = Message::DeserializeMessage (start); + if (newmsg == 0) + { + return start.GetDistanceFrom (begin); + } + MessagePushBack (newmsg); + } flags >>= 4; m_version = flags; @@ -828,7 +841,9 @@ PacketBB::Print (std::ostream &os) const os << "PacketBB {" << std::endl; if (HasSequenceNumber ()) - os << "\tsequence number = " << GetSequenceNumber (); + { + os << "\tsequence number = " << GetSequenceNumber (); + } os << std::endl; @@ -837,9 +852,9 @@ PacketBB::Print (std::ostream &os) const for (ConstMessageIterator iter = MessageBegin (); iter != MessageEnd (); iter++) - { - (*iter)->Print (os, 1); - } + { + (*iter)->Print (os, 1); + } os << "}" << std::endl; } @@ -848,31 +863,41 @@ bool PacketBB::operator== (const PacketBB &other) const { if (GetVersion () != other.GetVersion ()) - return false; + { + return false; + } if (HasSequenceNumber () != other.HasSequenceNumber ()) - return false; + { + return false; + } if (HasSequenceNumber ()) - { - if (GetSequenceNumber () != other.GetSequenceNumber ()) - return false; - } + { + if (GetSequenceNumber () != other.GetSequenceNumber ()) + return false; + } if (m_tlvList != other.m_tlvList) - return false; + { + return false; + } if (MessageSize () != other.MessageSize ()) - return false; + { + return false; + } ConstMessageIterator tmi, omi; for (tmi = MessageBegin (), omi = other.MessageBegin (); tmi != MessageEnd () && omi != other.MessageEnd (); tmi++, omi++) - { - if (**tmi != **omi) - return false; - } + { + if (**tmi != **omi) + { + return false; + } + } return true; } @@ -921,12 +946,8 @@ Message::SetOriginatorAddress (Address address) } Address -Message::GetOriginatorAddress (void) const throw (PacketBBError) +Message::GetOriginatorAddress (void) const { - if (!HasOriginatorAddress()) - { - throw PacketBBError ("Message has no originator address."); - } return m_originatorAddress; } @@ -944,12 +965,8 @@ Message::SetHopLimit (uint8_t hopLimit) } uint8_t -Message::GetHopLimit (void) const throw (PacketBBError) +Message::GetHopLimit (void) const { - if (!HasHopLimit()) - { - throw PacketBBError ("Message has no hop limit."); - } return m_hopLimit; } @@ -967,12 +984,8 @@ Message::SetHopCount (uint8_t hopCount) } uint8_t -Message::GetHopCount (void) const throw (PacketBBError) +Message::GetHopCount (void) const { - if (!HasHopCount()) - { - throw PacketBBError ("Message has no hop count."); - } return m_hopCount; } @@ -990,12 +1003,8 @@ Message::SetSequenceNumber (uint16_t sequenceNumber) } uint16_t -Message::GetSequenceNumber (void) const throw (PacketBBError) +Message::GetSequenceNumber (void) const { - if (!HasSequenceNumber()) - { - throw PacketBBError ("Message has no sequence number."); - } return m_sequenceNumber; } @@ -1225,9 +1234,9 @@ Message::Unref (void) const { m_refCount--; if (m_refCount == 0) - { - delete this; - } + { + delete this; + } } uint32_t @@ -1237,25 +1246,33 @@ Message::GetSerializedSize (void) const uint32_t size = 4; if (HasOriginatorAddress()) - size += GetAddressLength() + 1; + { + size += GetAddressLength() + 1; + } if (HasHopLimit()) - size++; + { + size++; + } if (HasHopCount()) - size++; + { + size++; + } if (HasSequenceNumber()) - size += 2; + { + size += 2; + } size += m_tlvList.GetSerializedSize (); for (ConstAddressBlockIterator iter = AddressBlockBegin (); iter != AddressBlockEnd (); iter++) - { - size += (*iter)->GetSerializedSize (); - } + { + size += (*iter)->GetSerializedSize (); + } return size; } @@ -1279,28 +1296,28 @@ Message::Serialize (Buffer::Iterator &start) const start.Next (2); if (HasOriginatorAddress ()) - { - flags |= MHAS_ORIG; - SerializeOriginatorAddress (start); - } + { + flags |= MHAS_ORIG; + SerializeOriginatorAddress (start); + } if (HasHopLimit ()) - { - flags |= MHAS_HOP_LIMIT; - start.WriteU8 (GetHopLimit ()); - } + { + flags |= MHAS_HOP_LIMIT; + start.WriteU8 (GetHopLimit ()); + } if (HasHopCount ()) - { - flags |= MHAS_HOP_COUNT; - start.WriteU8 (GetHopCount ()); - } + { + flags |= MHAS_HOP_COUNT; + start.WriteU8 (GetHopCount ()); + } if (HasSequenceNumber ()) - { - flags |= MHAS_SEQ_NUM; - start.WriteHtonU16 (GetSequenceNumber ()); - } + { + flags |= MHAS_SEQ_NUM; + start.WriteHtonU16 (GetSequenceNumber ()); + } bufref.WriteU8(flags); @@ -1309,15 +1326,15 @@ Message::Serialize (Buffer::Iterator &start) const for (ConstAddressBlockIterator iter = AddressBlockBegin (); iter != AddressBlockEnd (); iter++) - { - (*iter)->Serialize (start); - } + { + (*iter)->Serialize (start); + } sizeref.WriteHtonU16 (front.GetDistanceFrom (start)); } Ptr -Message::DeserializeMessage (Buffer::Iterator &start) throw (PacketBBError) +Message::DeserializeMessage (Buffer::Iterator &start) { /* We need to read the msg-addr-len field to determine what kind of object to * construct. */ @@ -1332,18 +1349,18 @@ Message::DeserializeMessage (Buffer::Iterator &start) throw (PacketBBError) Ptr newmsg; switch (addrlen) - { - case 0: - case IPV4: - newmsg = Create (); - break; - case IPV6: - newmsg = Create (); - break; - default: - throw PacketBBError ("Message deserialization has invalid address size."); - break; - } + { + case 0: + case IPV4: + newmsg = Create (); + break; + case IPV6: + newmsg = Create (); + break; + default: + return 0; + break; + } newmsg->Deserialize (start); return newmsg; } @@ -1358,29 +1375,35 @@ Message::Deserialize (Buffer::Iterator &start) uint16_t size = start.ReadNtohU16 (); if (flags & MHAS_ORIG) - SetOriginatorAddress (DeserializeOriginatorAddress (start)); + { + SetOriginatorAddress (DeserializeOriginatorAddress (start)); + } if (flags & MHAS_HOP_LIMIT) - SetHopLimit (start.ReadU8 ()); + { + SetHopLimit (start.ReadU8 ()); + } if (flags & MHAS_HOP_COUNT) - SetHopCount (start.ReadU8 ()); + { + SetHopCount (start.ReadU8 ()); + } if (flags & MHAS_SEQ_NUM) - SetSequenceNumber (start.ReadNtohU16 ()); + { + SetSequenceNumber (start.ReadNtohU16 ()); + } m_tlvList.Deserialize (start); if (size > 0) - { - while (start.GetDistanceFrom(front) < size) { - Ptr newab = AddressBlockDeserialize (start); - //AddressBlock * newab = AddressBlockDeserialize (start); - //Ptr * newptr = new Ptr (newab); - AddressBlockPushBack (newab); + while (start.GetDistanceFrom(front) < size) + { + Ptr newab = AddressBlockDeserialize (start); + AddressBlockPushBack (newab); + } } - } } void @@ -1394,7 +1417,9 @@ Message::Print (std::ostream &os, int level) const { std::string prefix = ""; for (int i = 0; i < level; i++) - prefix.append ("\t"); + { + prefix.append ("\t"); + } os << prefix << "Message {" << std::endl; @@ -1402,29 +1427,35 @@ Message::Print (std::ostream &os, int level) const os << prefix << "\taddress size = " << GetAddressLength () << std::endl; if (HasOriginatorAddress ()) - { - os << prefix << "\toriginator address = "; - PrintOriginatorAddress (os); - os << std::endl; - } + { + os << prefix << "\toriginator address = "; + PrintOriginatorAddress (os); + os << std::endl; + } if (HasHopLimit ()) - os << prefix << "\thop limit = " << (int)GetHopLimit () << std::endl; + { + os << prefix << "\thop limit = " << (int)GetHopLimit () << std::endl; + } if (HasHopCount ()) - os << prefix << "\thop count = " << (int)GetHopCount () << std::endl; + { + os << prefix << "\thop count = " << (int)GetHopCount () << std::endl; + } if (HasSequenceNumber ()) - os << prefix << "\tseqnum = " << GetSequenceNumber () << std::endl; + { + os << prefix << "\tseqnum = " << GetSequenceNumber () << std::endl; + } m_tlvList.Print (os, level+1); for (ConstAddressBlockIterator iter = AddressBlockBegin (); iter != AddressBlockEnd (); iter++) - { - (*iter)->Print (os, level+1); - } + { + (*iter)->Print (os, level+1); + } os << prefix << "}" << std::endl; } @@ -1432,61 +1463,87 @@ bool Message::operator== (const Message &other) const { if (GetAddressLength () != other.GetAddressLength ()) - return false; + { + return false; + } if (GetType () != other.GetType ()) - return false; + { + return false; + } if (HasOriginatorAddress () != other.HasOriginatorAddress ()) - return false; + { + return false; + } if (HasOriginatorAddress ()) - { - if (GetOriginatorAddress () != other.GetOriginatorAddress ()) - return false; - } + { + if (GetOriginatorAddress () != other.GetOriginatorAddress ()) + { + return false; + } + } if (HasHopLimit () != other.HasHopLimit ()) - return false; + { + return false; + } if (HasHopLimit ()) - { - if (GetHopLimit () != other.GetHopLimit ()) - return false; - } + { + if (GetHopLimit () != other.GetHopLimit ()) + { + return false; + } + } if (HasHopCount () != other.HasHopCount ()) - return false; + { + return false; + } if (HasHopCount ()) - { - if (GetHopCount () != other.GetHopCount ()) - return false; - } + { + if (GetHopCount () != other.GetHopCount ()) + { + return false; + } + } if (HasSequenceNumber () != other.HasSequenceNumber ()) - return false; + { + return false; + } if (HasSequenceNumber ()) - { - if (GetSequenceNumber () != other.GetSequenceNumber ()) - return false; - } + { + if (GetSequenceNumber () != other.GetSequenceNumber ()) + { + return false; + } + } if (m_tlvList != other.m_tlvList) - return false; + { + return false; + } if (AddressBlockSize () != other.AddressBlockSize ()) - return false; + { + return false; + } ConstAddressBlockIterator tai, oai; for (tai = AddressBlockBegin (), oai = other.AddressBlockBegin (); tai != AddressBlockEnd () && oai != other.AddressBlockEnd (); tai++, oai++) - { - if (**tai != **oai) - return false; - } + { + if (**tai != **oai) + { + return false; + } + } return true; } @@ -1886,9 +1943,9 @@ AddressBlock::Unref (void) const { m_refCount--; if (m_refCount == 0) - { - delete this; - } + { + delete this; + } } uint32_t @@ -1898,33 +1955,37 @@ AddressBlock::GetSerializedSize (void) const uint32_t size = 2; if (AddressSize () == 1) - { - size += GetAddressLength () + PrefixSize(); - } - else if (AddressSize () > 0) - { - uint8_t head[GetAddressLength ()]; - uint8_t headlen = 0; - uint8_t tail[GetAddressLength ()]; - uint8_t taillen = 0; - - GetHeadTail (head, headlen, tail, taillen); - - if (headlen > 0) - size += 1 + headlen; - - if (taillen > 0) { - size++; - if (!HasZeroTail (tail, taillen)) - size += taillen; + size += GetAddressLength () + PrefixSize(); } + else if (AddressSize () > 0) + { + uint8_t head[GetAddressLength ()]; + uint8_t headlen = 0; + uint8_t tail[GetAddressLength ()]; + uint8_t taillen = 0; - /* mid size */ - size += (GetAddressLength () - headlen - taillen) * AddressSize (); + GetHeadTail (head, headlen, tail, taillen); - size += PrefixSize (); - } + if (headlen > 0) + { + size += 1 + headlen; + } + + if (taillen > 0) + { + size++; + if (!HasZeroTail (tail, taillen)) + { + size += taillen; + } + } + + /* mid size */ + size += (GetAddressLength () - headlen - taillen) * AddressSize (); + + size += PrefixSize (); + } size += m_addressTlvList.GetSerializedSize (); @@ -1936,73 +1997,76 @@ AddressBlock::Serialize (Buffer::Iterator &start) const { start.WriteU8 (AddressSize ()); - if (AddressSize () == 1) { - start.WriteU8 (0); + if (AddressSize () == 1) + { + start.WriteU8 (0); - uint8_t buf[GetAddressLength ()]; - SerializeAddress (buf, AddressBegin ()); - start.Write (buf, GetAddressLength ()); + uint8_t buf[GetAddressLength ()]; + SerializeAddress (buf, AddressBegin ()); + start.Write (buf, GetAddressLength ()); - if (PrefixSize () == 1) - start.WriteU8 (PrefixFront ()); - } + if (PrefixSize () == 1) + { + start.WriteU8 (PrefixFront ()); + } + } else if (AddressSize () > 0) - { - Buffer::Iterator bufref = start; - uint8_t flags = 0; - start.Next (); - - uint8_t head[GetAddressLength ()]; - uint8_t tail[GetAddressLength ()]; - uint8_t headlen = 0; - uint8_t taillen = 0; - - GetHeadTail (head, headlen, tail, taillen); - - if (headlen > 0) { - flags |= AHAS_HEAD; - start.WriteU8 (headlen); - start.Write (head, headlen); - } + Buffer::Iterator bufref = start; + uint8_t flags = 0; + start.Next (); - if (taillen > 0) - { - start.WriteU8 (taillen); + uint8_t head[GetAddressLength ()]; + uint8_t tail[GetAddressLength ()]; + uint8_t headlen = 0; + uint8_t taillen = 0; - if (HasZeroTail (tail, taillen)) - { - flags |= AHAS_ZERO_TAIL; - } - else - { - flags |= AHAS_FULL_TAIL; - start.Write (tail, taillen); - } - } + GetHeadTail (head, headlen, tail, taillen); - if (headlen + taillen < GetAddressLength ()) - { - uint8_t mid[GetAddressLength ()]; - for (AddressBlock::ConstAddressIterator iter = AddressBegin (); - iter != AddressEnd (); + if (headlen > 0) + { + flags |= AHAS_HEAD; + start.WriteU8 (headlen); + start.Write (head, headlen); + } + + if (taillen > 0) + { + start.WriteU8 (taillen); + + if (HasZeroTail (tail, taillen)) + { + flags |= AHAS_ZERO_TAIL; + } + else + { + flags |= AHAS_FULL_TAIL; + start.Write (tail, taillen); + } + } + + if (headlen + taillen < GetAddressLength ()) + { + uint8_t mid[GetAddressLength ()]; + for (AddressBlock::ConstAddressIterator iter = AddressBegin (); + iter != AddressEnd (); + iter++) + { + SerializeAddress (mid, iter); + start.Write (mid + headlen, GetAddressLength () - headlen - taillen); + } + } + + flags |= GetPrefixFlags (); + bufref.WriteU8 (flags); + + for (ConstPrefixIterator iter = PrefixBegin (); + iter != PrefixEnd (); iter++) - { - SerializeAddress (mid, iter); - start.Write (mid + headlen, GetAddressLength () - headlen - taillen); - } + { + start.WriteU8 (*iter); + } } - - flags |= GetPrefixFlags (); - bufref.WriteU8 (flags); - - for (ConstPrefixIterator iter = PrefixBegin (); - iter != PrefixEnd (); - iter++) - { - start.WriteU8 (*iter); - } - } m_addressTlvList.Serialize (start); } @@ -2014,46 +2078,46 @@ AddressBlock::Deserialize (Buffer::Iterator &start) uint8_t flags = start.ReadU8 (); if (numaddr > 0) - { - uint8_t headlen = 0; - uint8_t taillen = 0; - uint8_t addrtmp[GetAddressLength ()]; - memset(addrtmp, 0, GetAddressLength ()); + { + uint8_t headlen = 0; + uint8_t taillen = 0; + uint8_t addrtmp[GetAddressLength ()]; + memset(addrtmp, 0, GetAddressLength ()); - if (flags & AHAS_HEAD) - { - headlen = start.ReadU8 (); - start.Read (addrtmp, headlen); - } + if (flags & AHAS_HEAD) + { + headlen = start.ReadU8 (); + start.Read (addrtmp, headlen); + } - if ((flags & AHAS_FULL_TAIL) ^ (flags & AHAS_ZERO_TAIL)) - { - taillen = start.ReadU8 (); - - if (flags & AHAS_FULL_TAIL) - { - start.Read (addrtmp + GetAddressLength () - taillen, taillen); - } - } + if ((flags & AHAS_FULL_TAIL) ^ (flags & AHAS_ZERO_TAIL)) + { + taillen = start.ReadU8 (); + + if (flags & AHAS_FULL_TAIL) + { + start.Read (addrtmp + GetAddressLength () - taillen, taillen); + } + } - for (int i = 0; i < numaddr; i++) - { - start.Read (addrtmp + headlen, GetAddressLength () - headlen - taillen); - AddressPushBack (DeserializeAddress (addrtmp)); - } - - if (flags & AHAS_SINGLE_PRE_LEN) - { - PrefixPushBack (start.ReadU8 ()); - } - else if (flags & AHAS_MULTI_PRE_LEN) - { for (int i = 0; i < numaddr; i++) - { - PrefixPushBack (start.ReadU8 ()); - } + { + start.Read (addrtmp + headlen, GetAddressLength () - headlen - taillen); + AddressPushBack (DeserializeAddress (addrtmp)); + } + + if (flags & AHAS_SINGLE_PRE_LEN) + { + PrefixPushBack (start.ReadU8 ()); + } + else if (flags & AHAS_MULTI_PRE_LEN) + { + for (int i = 0; i < numaddr; i++) + { + PrefixPushBack (start.ReadU8 ()); + } + } } - } m_addressTlvList.Deserialize (start); } @@ -2069,26 +2133,28 @@ AddressBlock::Print (std::ostream &os, int level) const { std::string prefix = ""; for (int i = 0; i < level; i++) - prefix.append ("\t"); + { + prefix.append ("\t"); + } os << prefix << "AddressBlock {" << std::endl; os << prefix << "\taddresses = " << std::endl; for (ConstAddressIterator iter = AddressBegin (); iter != AddressEnd (); iter++) - { - os << prefix << "\t\t"; - PrintAddress(os, iter); - os << std::endl; - } + { + os << prefix << "\t\t"; + PrintAddress(os, iter); + os << std::endl; + } os << prefix << "\tprefixes = " << std::endl; for (ConstPrefixIterator iter = PrefixBegin (); iter != PrefixEnd (); iter++) - { - os << prefix << "\t\t" << (int)(*iter) << std::endl; - } + { + os << prefix << "\t\t" << (int)(*iter) << std::endl; + } m_addressTlvList.Print (os, level+1); } @@ -2097,31 +2163,41 @@ bool AddressBlock::operator== (const AddressBlock &other) const { if (AddressSize () != other.AddressSize ()) - return false; + { + return false; + } ConstAddressIterator tai, oai; for (tai = AddressBegin (), oai = other.AddressBegin (); tai != AddressEnd () && oai != other.AddressEnd (); tai++, oai++) - { - if (*tai != *oai) - return false; - } + { + if (*tai != *oai) + { + return false; + } + } if (PrefixSize () != other.PrefixSize ()) - return false; + { + return false; + } ConstPrefixIterator tpi, opi; for (tpi = PrefixBegin (), opi = other.PrefixBegin (); tpi != PrefixEnd () && opi != other.PrefixEnd (); tpi++, opi++) - { - if (*tpi != *opi) - return false; - } + { + if (*tpi != *opi) + { + return false; + } + } if (m_addressTlvList != other.m_addressTlvList) - return false; + { + return false; + } return true; } @@ -2136,17 +2212,17 @@ uint8_t AddressBlock::GetPrefixFlags (void) const { switch (PrefixSize ()) - { - case 0: - return 0; - break; - case 1: - return AHAS_SINGLE_PRE_LEN; - break; - default: - return AHAS_MULTI_PRE_LEN; - break; - } + { + case 0: + return 0; + break; + case 1: + return AHAS_SINGLE_PRE_LEN; + break; + default: + return AHAS_MULTI_PRE_LEN; + break; + } } void @@ -2167,41 +2243,43 @@ AddressBlock::GetHeadTail (uint8_t *head, uint8_t &headlen, for (AddressBlock::ConstAddressIterator iter = AddressBegin ()++; iter != AddressEnd (); iter++) - { - SerializeAddress (bufcur, iter); - - int i; - for (i = 0; i < headlen; i++) { - if (buflast[i] != bufcur[i]) - { - headlen = i; - break; - } - } + SerializeAddress (bufcur, iter); - /* If headlen == fulllen - 1, then tail is 0 */ - if (headlen <= GetAddressLength () - 1) - { - for (i = GetAddressLength () - 1; - GetAddressLength () - 1 - i <= taillen && i > headlen; - i--) - { - if (buflast[i] != bufcur[i]) + int i; + for (i = 0; i < headlen; i++) + { + if (buflast[i] != bufcur[i]) + { + headlen = i; + break; + } + } + + /* If headlen == fulllen - 1, then tail is 0 */ + if (headlen <= GetAddressLength () - 1) + { + for (i = GetAddressLength () - 1; + GetAddressLength () - 1 - i <= taillen && i > headlen; + i--) + { + if (buflast[i] != bufcur[i]) + { + break; + } + } + taillen = GetAddressLength () - 1 - i; + } + else if (headlen == 0) + { + taillen = 0; break; - } - taillen = GetAddressLength () - 1 - i; - } - else if (headlen == 0) - { - taillen = 0; - break; - } + } - tmp = buflast; - buflast = bufcur; - bufcur = tmp; - } + tmp = buflast; + buflast = bufcur; + bufcur = tmp; + } memcpy(head, bufcur, headlen); memcpy(tail, bufcur + (GetAddressLength () - taillen), taillen); @@ -2215,10 +2293,12 @@ AddressBlock::HasZeroTail (const uint8_t *tail, uint8_t taillen) const { int i; for (i = 0; i < taillen; i++) - { - if (tail[i] != 0) - break; - } + { + if (tail[i] != 0) + { + break; + } + } return i == taillen; } @@ -2306,12 +2386,8 @@ Tlv::SetTypeExt (uint8_t typeExt) } uint8_t -Tlv::GetTypeExt (void) const throw (PacketBBError) +Tlv::GetTypeExt (void) const { - if (!HasTypeExt()) - { - throw PacketBBError ("TLV has no type extension."); - } return m_typeExt; } @@ -2329,12 +2405,8 @@ Tlv::SetIndexStart (uint8_t index) } uint8_t -Tlv::GetIndexStart (void) const throw (PacketBBError) +Tlv::GetIndexStart (void) const { - if (!HasIndexStart()) - { - throw PacketBBError ("TLV has no start index."); - } return m_indexStart; } @@ -2352,12 +2424,8 @@ Tlv::SetIndexStop (uint8_t index) } uint8_t -Tlv::GetIndexStop (void) const throw (PacketBBError) +Tlv::GetIndexStop (void) const { - if (!HasIndexStop()) - { - throw PacketBBError ("TLV has no stop index."); - } return m_indexStop; } @@ -2396,12 +2464,8 @@ Tlv::SetValue (const uint8_t * buffer, uint32_t size) } Buffer -Tlv::GetValue (void) const throw (PacketBBError) +Tlv::GetValue (void) const { - if (!HasValue ()) - { - throw PacketBBError ("TLV has no value."); - } return m_value; } @@ -2422,9 +2486,9 @@ Tlv::Unref (void) const { m_refCount--; if (m_refCount == 0) - { - delete this; - } + { + delete this; + } } uint32_t @@ -2433,27 +2497,33 @@ Tlv::GetSerializedSize (void) const /* type + flags */ uint32_t size = 2; - if (HasTypeExt ()) { - size++; - } - - if (HasIndexStart ()) { - size++; - } - - if (HasIndexStop ()) { - size++; - } - - if (HasValue ()) - { - if (GetValue ().GetSize () > 255) { - size += 2; - } else { + if (HasTypeExt ()) + { size++; } - size += GetValue ().GetSize (); - } + + if (HasIndexStart ()) + { + size++; + } + + if (HasIndexStop ()) + { + size++; + } + + if (HasValue ()) + { + if (GetValue ().GetSize () > 255) + { + size += 2; + } + else + { + size++; + } + size += GetValue ().GetSize (); + } return size; } @@ -2468,45 +2538,48 @@ Tlv::Serialize (Buffer::Iterator &start) const start.Next(); if (HasTypeExt()) - { - flags |= THAS_TYPE_EXT; - start.WriteU8 (GetTypeExt ()); - } + { + flags |= THAS_TYPE_EXT; + start.WriteU8 (GetTypeExt ()); + } if (HasIndexStart ()) - { - start.WriteU8 (GetIndexStart ()); + { + start.WriteU8 (GetIndexStart ()); - if (HasIndexStop ()) - { - flags |= THAS_MULTI_INDEX; - start.WriteU8 (GetIndexStop ()); - } - else - { - flags |= THAS_SINGLE_INDEX; - } - } - - if (HasValue ()) { - flags |= THAS_VALUE; - - uint32_t size = GetValue ().GetSize (); - if (size > 255) - { - flags |= THAS_EXT_LEN; - start.WriteHtonU16 (size); - } - else - { - start.WriteU8 (size); + if (HasIndexStop ()) + { + flags |= THAS_MULTI_INDEX; + start.WriteU8 (GetIndexStop ()); + } + else + { + flags |= THAS_SINGLE_INDEX; + } } - if (IsMultivalue ()) - flags |= TIS_MULTIVALUE; + if (HasValue ()) + { + flags |= THAS_VALUE; - start.Write(GetValue ().Begin (), GetValue ().End ()); - } + uint32_t size = GetValue ().GetSize (); + if (size > 255) + { + flags |= THAS_EXT_LEN; + start.WriteHtonU16 (size); + } + else + { + start.WriteU8 (size); + } + + if (IsMultivalue ()) + { + flags |= TIS_MULTIVALUE; + } + + start.Write(GetValue ().Begin (), GetValue ().End ()); + } bufref.WriteU8 (flags); } @@ -2519,34 +2592,40 @@ Tlv::Deserialize (Buffer::Iterator &start) uint8_t flags = start.ReadU8 (); if (flags & THAS_TYPE_EXT) - SetTypeExt (start.ReadU8 ()); + { + SetTypeExt (start.ReadU8 ()); + } if (flags & THAS_MULTI_INDEX) - { - SetIndexStart (start.ReadU8 ()); - SetIndexStop (start.ReadU8 ()); - } + { + SetIndexStart (start.ReadU8 ()); + SetIndexStop (start.ReadU8 ()); + } else if (flags & THAS_SINGLE_INDEX) - { - SetIndexStart (start.ReadU8 ()); - } + { + SetIndexStart (start.ReadU8 ()); + } if (flags & THAS_VALUE) - { - uint16_t len = 0; + { + uint16_t len = 0; - if (flags & THAS_EXT_LEN) - len = start.ReadNtohU16 (); - else - len = start.ReadU8 (); + if (flags & THAS_EXT_LEN) + { + len = start.ReadNtohU16 (); + } + else + { + len = start.ReadU8 (); + } - m_value.AddAtStart (len); + m_value.AddAtStart (len); - Buffer::Iterator valueStart = start; - start.Next (len); - m_value.Begin ().Write (valueStart, start); - m_hasValue = true; - } + Buffer::Iterator valueStart = start; + start.Next (len); + m_value.Begin ().Write (valueStart, start); + m_hasValue = true; + } } void @@ -2560,24 +2639,34 @@ Tlv::Print (std::ostream &os, int level) const { std::string prefix = ""; for (int i = 0; i < level; i++) - prefix.append ("\t"); + { + prefix.append ("\t"); + } os << prefix << "Tlv {" << std::endl; os << prefix << "\ttype = " << (int)GetType () << std::endl; if (HasTypeExt ()) - os << prefix << "\ttypeext = " << (int)GetTypeExt () << std::endl; + { + os << prefix << "\ttypeext = " << (int)GetTypeExt () << std::endl; + } if (HasIndexStart ()) - os << prefix << "\tindexStart = " << (int)GetIndexStart () << std::endl; + { + os << prefix << "\tindexStart = " << (int)GetIndexStart () << std::endl; + } if (HasIndexStop ()) - os << prefix << "\tindexStop = " << (int)GetIndexStop () << std::endl; + { + os << prefix << "\tindexStop = " << (int)GetIndexStop () << std::endl; + } os << prefix << "\tisMultivalue = " << IsMultivalue () << std::endl; if (HasValue ()) - os << prefix << "\thas value; size = " << GetValue (). GetSize () << std::endl; + { + os << prefix << "\thas value; size = " << GetValue (). GetSize () << std::endl; + } os << prefix << "}" << std::endl; } @@ -2586,32 +2675,44 @@ bool Tlv::operator== (const Tlv &other) const { if (GetType () != other.GetType ()) - return false; + { + return false; + } if (HasTypeExt () != other.HasTypeExt ()) - return false; + { + return false; + } if (HasTypeExt ()) - { - if (GetTypeExt () != other.GetTypeExt ()) - return false; - } + { + if (GetTypeExt () != other.GetTypeExt ()) + { + return false; + } + } if (HasValue () != other.HasValue ()) - return false; + { + return false; + } if (HasValue ()) - { - Buffer tv = GetValue (); - Buffer ov = other.GetValue (); - if (tv.GetSize () != ov.GetSize ()) - return false; + { + Buffer tv = GetValue (); + Buffer ov = other.GetValue (); + if (tv.GetSize () != ov.GetSize ()) + { + return false; + } - /* The docs say I probably shouldn't use Buffer::PeekData, but I think it - * is justified in this case. */ - if (memcmp (tv.PeekData (), ov.PeekData (), tv.GetSize ()) != 0) - return false; - } + /* The docs say I probably shouldn't use Buffer::PeekData, but I think it + * is justified in this case. */ + if (memcmp (tv.PeekData (), ov.PeekData (), tv.GetSize ()) != 0) + { + return false; + } + } return true; } @@ -2630,7 +2731,7 @@ AddressTlv::SetIndexStart (uint8_t index) } uint8_t -AddressTlv::GetIndexStart (void) const throw (PacketBBError) +AddressTlv::GetIndexStart (void) const { return Tlv::GetIndexStart (); } @@ -2648,7 +2749,7 @@ AddressTlv::SetIndexStop (uint8_t index) } uint8_t -AddressTlv::GetIndexStop (void) const throw (PacketBBError) +AddressTlv::GetIndexStop (void) const { return Tlv::GetIndexStop (); } diff --git a/src/contrib/packetbb.h b/src/contrib/packetbb.h index e86f71862..95e92237c 100644 --- a/src/contrib/packetbb.h +++ b/src/contrib/packetbb.h @@ -1,5 +1,5 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/* vim: set ts=2 sw=2 expandtab: */ +/* vim: set ts=2 sw=2 sta expandtab ai si cin: */ /* * Copyright (c) 2009 Drexel University * @@ -156,7 +156,9 @@ public: uint8_t GetVersion (void) const; void SetSequenceNumber (uint16_t number); - uint16_t GetSequenceNumber (void) const throw (PacketBBError); + /* Calling this while HasSequenceNumber is False is undefined, make sure you + * check first! */ + uint16_t GetSequenceNumber (void) const; bool HasSequenceNumber (void) const; /* Manipulating Packet TLVs */ @@ -216,6 +218,8 @@ public: virtual TypeId GetInstanceTypeId (void) const; virtual uint32_t GetSerializedSize (void) const; virtual void Serialize (Buffer::Iterator start) const; + /* If this returns a number smaller than the total number of bytes in the + * buffer, there was an error. */ virtual uint32_t Deserialize (Buffer::Iterator start); virtual void Print (std::ostream &os) const; @@ -251,19 +255,27 @@ public: uint8_t GetType (void) const; void SetOriginatorAddress (Address address); - Address GetOriginatorAddress (void) const throw (PacketBBError); + /* Calling this while HasOriginatorAddress is False is undefined, make sure + * you check first! */ + Address GetOriginatorAddress (void) const; bool HasOriginatorAddress (void) const; void SetHopLimit (uint8_t hoplimit); - uint8_t GetHopLimit (void) const throw (PacketBBError); + /* Calling this while HasHopLimit is False is undefined, make sure + * you check first! */ + uint8_t GetHopLimit (void) const; bool HasHopLimit (void) const; void SetHopCount (uint8_t hopcount); - uint8_t GetHopCount (void) const throw (PacketBBError); + /* Calling this while HasHopCount is False is undefined, make sure + * you check first! */ + uint8_t GetHopCount (void) const; bool HasHopCount (void) const; void SetSequenceNumber (uint16_t seqnum); - uint16_t GetSequenceNumber (void) const throw (PacketBBError); + /* Calling this while HasSequenceNumber is False is undefined, make sure + * you check first! */ + uint16_t GetSequenceNumber (void) const; bool HasSequenceNumber (void) const; /* Manipulating Message TLVs */ @@ -319,7 +331,8 @@ public: void Ref (void) const; void Unref (void) const; - static Ptr DeserializeMessage (Buffer::Iterator &start) throw (PacketBBError); + /* Returns 0 on error */ + static Ptr DeserializeMessage (Buffer::Iterator &start); uint32_t GetSerializedSize (void) const; void Serialize (Buffer::Iterator &start) const; void Deserialize (Buffer::Iterator &start); @@ -543,12 +556,16 @@ public: uint8_t GetType (void) const; void SetTypeExt (uint8_t type); - uint8_t GetTypeExt (void) const throw (PacketBBError); + /* Calling this while HasTypeExt is False is undefined, make sure + * you check first! */ + uint8_t GetTypeExt (void) const; bool HasTypeExt (void) const; void SetValue (Buffer start); void SetValue (const uint8_t * buffer, uint32_t size); - Buffer GetValue (void) const throw (PacketBBError); + /* Calling this while HasValue is False is undefined, make sure + * you check first! */ + Buffer GetValue (void) const; bool HasValue (void) const; /* Smart pointer methods */ @@ -566,11 +583,11 @@ public: protected: void SetIndexStart (uint8_t index); - uint8_t GetIndexStart (void) const throw (PacketBBError); + uint8_t GetIndexStart (void) const; bool HasIndexStart (void) const; void SetIndexStop (uint8_t index); - uint8_t GetIndexStop (void) const throw (PacketBBError); + uint8_t GetIndexStop (void) const; bool HasIndexStop (void) const; void SetMultivalue (bool isMultivalue); @@ -599,11 +616,15 @@ class AddressTlv : public Tlv { public: void SetIndexStart (uint8_t index); - uint8_t GetIndexStart (void) const throw (PacketBBError); + /* Calling this while HasIndexStart is False is undefined, make sure + * you check first! */ + uint8_t GetIndexStart (void) const; bool HasIndexStart (void) const; void SetIndexStop (uint8_t index); - uint8_t GetIndexStop (void) const throw (PacketBBError); + /* Calling this while HasIndexStop is False is undefined, make sure + * you check first! */ + uint8_t GetIndexStop (void) const; bool HasIndexStop (void) const; void SetMultivalue (bool isMultivalue); diff --git a/src/contrib/test-packetbb.cc b/src/contrib/test-packetbb.cc index 35ac51339..f11f1d335 100644 --- a/src/contrib/test-packetbb.cc +++ b/src/contrib/test-packetbb.cc @@ -1,5 +1,5 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/* vim: set ts=2 sw=2 expandtab: */ +/* vim: set ts=2 sw=2 sta expandtab ai si cin: */ /* * Copyright (c) 2009 Drexel University * @@ -47,71 +47,42 @@ public: void Test (void) { if (TestSerialize ()) - cout << "Serialize Pass, "; + { + cout << "Serialize Pass, "; + } else - cout << "Serialize Fail, "; + { + cout << "Serialize Fail, "; + } if (TestDeserialize ()) - cout << "Deserialize Pass, "; + { + cout << "Deserialize Pass, "; + } else - cout << "Deserialize Fail, "; - - if (TestConsistency ()) - cout << "Consistency Pass" << endl; - else - cout << "Consistency Fail" << endl; + { + cout << "Deserialize Fail, "; + } } bool TestSerialize (void) { Buffer newBuffer; - try - { - newBuffer.AddAtStart (m_refPacket.GetSerializedSize ()); - m_refPacket.Serialize (newBuffer.Begin ()); - } - catch (PacketBBError &e) - { - cout << endl << "Exception: " << e.what () << endl; - return false; - } + newBuffer.AddAtStart (m_refPacket.GetSerializedSize ()); + m_refPacket.Serialize (newBuffer.Begin ()); return CompareBuffers (m_refBuffer, newBuffer); } bool TestDeserialize (void) { PacketBB newPacket; - try - { - newPacket.Deserialize (m_refBuffer.Begin ()); - } - catch (PacketBBError &e) - { - cout << endl << "Exception: " << e.what () << endl; - return false; - } + if (newPacket.Deserialize (m_refBuffer.Begin ()) != m_refBuffer.GetSize ()) + { + return false; + } return m_refPacket == newPacket; } - bool TestConsistency (void) - { - Buffer newBuffer; - PacketBB newPacket; - try - { - newBuffer.AddAtStart (m_refPacket.GetSerializedSize ()); - m_refPacket.Serialize (newBuffer.Begin ()); - newPacket.Deserialize (newBuffer.Begin ()); - } - catch (PacketBBError &e) - { - cout << endl << "Exception: " << e.what () << endl; - return false; - } - return m_refPacket == newPacket; - } - - private: static bool CompareBuffers (Buffer a, Buffer b) { @@ -119,21 +90,23 @@ private: const uint8_t * bbuf = b.PeekData (); for (unsigned int i = 0; i < a.GetSize (); i++) - { - if (abuf[i] != bbuf[i]) - cout << "Difference - [" << i << "] - " << (int)abuf[i] << " - " << (int)bbuf[i] << endl; - } + { + if (abuf[i] != bbuf[i]) + { + cout << "Difference - [" << i << "] - " << (int)abuf[i] << " - " << (int)bbuf[i] << endl; + } + } if (a.GetSize () != b.GetSize ()) - { - cout << "Buffers differ in size: " << a.GetSize () << ", " << b.GetSize() << endl; - return false; - } + { + cout << "Buffers differ in size: " << a.GetSize () << ", " << b.GetSize() << endl; + return false; + } if (memcmp (a.PeekData (), b.PeekData (), a.GetSize ()) != 0) - { - return false; - } + { + return false; + } return true; } From 2f45cf66bb4cbc731a900a43a7d82ddd37cc4427 Mon Sep 17 00:00:00 2001 From: Tom Wambold Date: Fri, 21 Aug 2009 16:31:55 -0400 Subject: [PATCH 03/12] Typo in PacketBB test. --- src/contrib/test-packetbb.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/contrib/test-packetbb.cc b/src/contrib/test-packetbb.cc index f11f1d335..5c3f79539 100644 --- a/src/contrib/test-packetbb.cc +++ b/src/contrib/test-packetbb.cc @@ -57,12 +57,14 @@ public: if (TestDeserialize ()) { - cout << "Deserialize Pass, "; + cout << "Deserialize Pass"; } else { - cout << "Deserialize Fail, "; + cout << "Deserialize Fail"; } + + cout << endl; } bool TestSerialize (void) From ff9f6045be1e332b209022449e6eeabe2caf9e03 Mon Sep 17 00:00:00 2001 From: Tom Wambold Date: Fri, 21 Aug 2009 18:47:36 -0400 Subject: [PATCH 04/12] Added Doxygen comments to PacketBB. --- src/contrib/packetbb.h | 143 ++++++++++++++++++++++++++++++++--------- 1 file changed, 114 insertions(+), 29 deletions(-) diff --git a/src/contrib/packetbb.h b/src/contrib/packetbb.h index 95e92237c..8b95a6bc2 100644 --- a/src/contrib/packetbb.h +++ b/src/contrib/packetbb.h @@ -25,7 +25,6 @@ #ifndef PACKETBB_H #define PACKETBB_H -#include #include #include "ns3/ptr.h" @@ -51,11 +50,11 @@ enum AddressLength { IPV6 = 15, }; -class PacketBBError : public std::runtime_error { -public: - PacketBBError(const std::string &arg) : std::runtime_error(arg) {} -}; - +/** + * \brief A block of Packet or Message TLVs. + * + * Acts similar to a C++ STL container. Should not be used for Address TLVs. + */ class TlvBlock { public: @@ -99,6 +98,11 @@ private: std::list< Ptr > m_tlvList; }; +/** + * \brief A block of Address TLVs. + * + * Acts similar to a C++ STL container. + */ class AddressTlvBlock { public: @@ -142,7 +146,9 @@ private: std::list< Ptr > m_tlvList; }; -/** Top level PacketBB packet object */ +/** + * \brief Main PacketBB Packet object. + */ class PacketBB : public Header { public: @@ -156,8 +162,12 @@ public: uint8_t GetVersion (void) const; void SetSequenceNumber (uint16_t number); - /* Calling this while HasSequenceNumber is False is undefined, make sure you - * check first! */ + /** + * \returns the sequence number of this packet. + * + * Calling this while HasSequenceNumber is False is undefined. Make sure you + * check it first. + */ uint16_t GetSequenceNumber (void) const; bool HasSequenceNumber (void) const; @@ -218,8 +228,12 @@ public: virtual TypeId GetInstanceTypeId (void) const; virtual uint32_t GetSerializedSize (void) const; virtual void Serialize (Buffer::Iterator start) const; - /* If this returns a number smaller than the total number of bytes in the - * buffer, there was an error. */ + /** + * \returns the number of bytes deserialized + * + * If this returns a number smaller than the total number of bytes in the + * buffer, there was an error. + */ virtual uint32_t Deserialize (Buffer::Iterator start); virtual void Print (std::ostream &os) const; @@ -241,6 +255,13 @@ private: mutable uint32_t m_refCount; }; +/** + * \brief A message within a PacketBB packet. + * + * There may be any number of messages in one PacketBB packet. + * This is a pure virutal base class, you should instantiate either MessageIpv4 + * or MessageIpv6. + */ class Message { public: @@ -255,26 +276,42 @@ public: uint8_t GetType (void) const; void SetOriginatorAddress (Address address); - /* Calling this while HasOriginatorAddress is False is undefined, make sure - * you check first! */ + /** + * \returns the address of the node that created this packet. + * + * Calling this while HasOriginatorAddress is False is undefined. Make sure + * you check it first. + */ Address GetOriginatorAddress (void) const; bool HasOriginatorAddress (void) const; void SetHopLimit (uint8_t hoplimit); - /* Calling this while HasHopLimit is False is undefined, make sure - * you check first! */ + /** + * \returns the maximum number of hops this message should travel. + * + * Calling this while HasHopLimit is False is undefined. Make sure you check + * it first. + */ uint8_t GetHopLimit (void) const; bool HasHopLimit (void) const; void SetHopCount (uint8_t hopcount); - /* Calling this while HasHopCount is False is undefined, make sure - * you check first! */ + /** + * \returns the current number of hops this message has traveled. + * + * Calling this while HasHopCount is False is undefined. Make sure you check + * it first. + */ uint8_t GetHopCount (void) const; bool HasHopCount (void) const; void SetSequenceNumber (uint16_t seqnum); - /* Calling this while HasSequenceNumber is False is undefined, make sure - * you check first! */ + /** + * \returns the sequence number of this message. + * + * Calling this while HasSequenceNumber is False is undefined. Make sure you + * check it first. + */ uint16_t GetSequenceNumber (void) const; bool HasSequenceNumber (void) const; @@ -377,6 +414,11 @@ private: mutable uint32_t m_refCount; }; +/** + * \brief Concrete IPv4 specific Message. + * + * This message will only contain IPv4 addresses. + */ class MessageIpv4 : public Message { protected: virtual AddressLength GetAddressLength (void) const; @@ -388,6 +430,11 @@ protected: virtual Ptr AddressBlockDeserialize (Buffer::Iterator &start) const; }; +/** + * \brief Concrete IPv6 specific Message class. + * + * This message will only contain IPv6 addresses. + */ class MessageIpv6 : public Message { protected: virtual AddressLength GetAddressLength (void) const; @@ -399,7 +446,12 @@ protected: virtual Ptr AddressBlockDeserialize (Buffer::Iterator &start) const; }; -/** This combines address blocks with their associated TLVs */ +/** + * \brief An Address Block and its associated Address TLV Blocks. + * + * This is a pure virtual base class, you should instantiate either + * AddressBlockIpv4 or AddressBlockIpv6. + */ class AddressBlock { public: @@ -526,6 +578,11 @@ private: mutable uint32_t m_refCount; }; +/** + * \brief Concrete IPv4 specific AddressBlock. + * + * This address block will only contain IPv4 addresses. + */ class AddressBlockIpv4 : public AddressBlock { protected: @@ -536,6 +593,11 @@ protected: virtual void PrintAddress (std::ostream &os, ConstAddressIterator iter) const; }; +/** + * \brief Concrete IPv6 specific AddressBlock. + * + * This address block will only contain IPv6 addresses. + */ class AddressBlockIpv6 : public AddressBlock { protected: @@ -546,7 +608,9 @@ protected: virtual void PrintAddress (std::ostream &os, ConstAddressIterator iter) const; }; -/** A packet or message TLV */ +/** + * \brief A packet or message TLV + */ class Tlv { public: @@ -556,15 +620,23 @@ public: uint8_t GetType (void) const; void SetTypeExt (uint8_t type); - /* Calling this while HasTypeExt is False is undefined, make sure - * you check first! */ + /** + * \returns the type extension for this TLV. + * + * Calling this while HasTypeExt is False is undefined. Make sure you check + * it first. + */ uint8_t GetTypeExt (void) const; bool HasTypeExt (void) const; void SetValue (Buffer start); void SetValue (const uint8_t * buffer, uint32_t size); - /* Calling this while HasValue is False is undefined, make sure - * you check first! */ + /** + * \returns a Buffer pointing to the value of this TLV. + * + * Calling this while HasValue is False is undefined. Make sure you check it + * first. + */ Buffer GetValue (void) const; bool HasValue (void) const; @@ -612,18 +684,31 @@ private: mutable uint32_t m_refCount; }; +/** + * \brief An Address TLV + */ class AddressTlv : public Tlv { public: void SetIndexStart (uint8_t index); - /* Calling this while HasIndexStart is False is undefined, make sure - * you check first! */ + /** + * \returns the first (inclusive) index of the address in the corresponding + * AddressBlock that this TLV applies to. + * + * Calling this while HasIndexStart is False is undefined. Make sure you + * check it first. + */ uint8_t GetIndexStart (void) const; bool HasIndexStart (void) const; void SetIndexStop (uint8_t index); - /* Calling this while HasIndexStop is False is undefined, make sure - * you check first! */ + /** + * \returns the last (inclusive) index of the address in the corresponding + * AddressBlock that this TLV applies to. + * + * Calling this while HasIndexStop is False is undefined. Make sure you + * check it first. + */ uint8_t GetIndexStop (void) const; bool HasIndexStop (void) const; From 6cc6c5303199325b6ded126166d2393042e65777 Mon Sep 17 00:00:00 2001 From: Tom Wambold Date: Fri, 28 Aug 2009 10:56:37 -0400 Subject: [PATCH 05/12] PacketBB: Added assert checks to the Get*() methods, along with comments. --- src/contrib/packetbb.cc | 10 ++++++++++ src/contrib/packetbb.h | 18 +++++++++--------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/contrib/packetbb.cc b/src/contrib/packetbb.cc index 9293e44bf..4eee57048 100644 --- a/src/contrib/packetbb.cc +++ b/src/contrib/packetbb.cc @@ -25,6 +25,7 @@ #include "ns3/ipv4-address.h" #include "ns3/ipv6-address.h" +#include "ns3/assert.h" #include "packetbb.h" @@ -492,6 +493,7 @@ PacketBB::SetSequenceNumber (uint16_t number) uint16_t PacketBB::GetSequenceNumber (void) const { + NS_ASSERT (HasSequenceNumber ()); return m_seqnum; } @@ -948,6 +950,7 @@ Message::SetOriginatorAddress (Address address) Address Message::GetOriginatorAddress (void) const { + NS_ASSERT (HasOriginatorAddress ()); return m_originatorAddress; } @@ -967,6 +970,7 @@ Message::SetHopLimit (uint8_t hopLimit) uint8_t Message::GetHopLimit (void) const { + NS_ASSERT (HasHopLimit ()); return m_hopLimit; } @@ -986,6 +990,7 @@ Message::SetHopCount (uint8_t hopCount) uint8_t Message::GetHopCount (void) const { + NS_ASSERT (HasHopCount ()); return m_hopCount; } @@ -1005,6 +1010,7 @@ Message::SetSequenceNumber (uint16_t sequenceNumber) uint16_t Message::GetSequenceNumber (void) const { + NS_ASSERT (HasSequenceNumber ()); return m_sequenceNumber; } @@ -2388,6 +2394,7 @@ Tlv::SetTypeExt (uint8_t typeExt) uint8_t Tlv::GetTypeExt (void) const { + NS_ASSERT (HasTypeExt ()); return m_typeExt; } @@ -2407,6 +2414,7 @@ Tlv::SetIndexStart (uint8_t index) uint8_t Tlv::GetIndexStart (void) const { + NS_ASSERT (HasIndexStart ()); return m_indexStart; } @@ -2426,6 +2434,7 @@ Tlv::SetIndexStop (uint8_t index) uint8_t Tlv::GetIndexStop (void) const { + NS_ASSERT (HasIndexStop ()); return m_indexStop; } @@ -2466,6 +2475,7 @@ Tlv::SetValue (const uint8_t * buffer, uint32_t size) Buffer Tlv::GetValue (void) const { + NS_ASSERT (HasValue ()); return m_value; } diff --git a/src/contrib/packetbb.h b/src/contrib/packetbb.h index 8b95a6bc2..00e660387 100644 --- a/src/contrib/packetbb.h +++ b/src/contrib/packetbb.h @@ -166,7 +166,7 @@ public: * \returns the sequence number of this packet. * * Calling this while HasSequenceNumber is False is undefined. Make sure you - * check it first. + * check it first. This will be checked by an assert in debug builds. */ uint16_t GetSequenceNumber (void) const; bool HasSequenceNumber (void) const; @@ -280,7 +280,7 @@ public: * \returns the address of the node that created this packet. * * Calling this while HasOriginatorAddress is False is undefined. Make sure - * you check it first. + * you check it first. This will be checked by an assert in debug builds. */ Address GetOriginatorAddress (void) const; bool HasOriginatorAddress (void) const; @@ -290,7 +290,7 @@ public: * \returns the maximum number of hops this message should travel. * * Calling this while HasHopLimit is False is undefined. Make sure you check - * it first. + * it first. This will be checked by an assert in debug builds. */ uint8_t GetHopLimit (void) const; bool HasHopLimit (void) const; @@ -300,7 +300,7 @@ public: * \returns the current number of hops this message has traveled. * * Calling this while HasHopCount is False is undefined. Make sure you check - * it first. + * it first. This will be checked by an assert in debug builds. */ uint8_t GetHopCount (void) const; bool HasHopCount (void) const; @@ -310,7 +310,7 @@ public: * \returns the sequence number of this message. * * Calling this while HasSequenceNumber is False is undefined. Make sure you - * check it first. + * check it first. This will be checked by an assert in debug builds. */ uint16_t GetSequenceNumber (void) const; bool HasSequenceNumber (void) const; @@ -624,7 +624,7 @@ public: * \returns the type extension for this TLV. * * Calling this while HasTypeExt is False is undefined. Make sure you check - * it first. + * it first. This will be checked by an assert in debug builds. */ uint8_t GetTypeExt (void) const; bool HasTypeExt (void) const; @@ -635,7 +635,7 @@ public: * \returns a Buffer pointing to the value of this TLV. * * Calling this while HasValue is False is undefined. Make sure you check it - * first. + * first. This will be checked by an assert in debug builds. */ Buffer GetValue (void) const; bool HasValue (void) const; @@ -696,7 +696,7 @@ public: * AddressBlock that this TLV applies to. * * Calling this while HasIndexStart is False is undefined. Make sure you - * check it first. + * check it first. This will be checked by an assert in debug builds. */ uint8_t GetIndexStart (void) const; bool HasIndexStart (void) const; @@ -707,7 +707,7 @@ public: * AddressBlock that this TLV applies to. * * Calling this while HasIndexStop is False is undefined. Make sure you - * check it first. + * check it first. This will be checked by an assert in debug builds. */ uint8_t GetIndexStop (void) const; bool HasIndexStop (void) const; From 0745740c077b6171f25120825fa7249e6adf5fdf Mon Sep 17 00:00:00 2001 From: Tom Wambold Date: Thu, 10 Sep 2009 15:33:23 -0400 Subject: [PATCH 06/12] PacketBB:: Removed pbb namespace, instead prefix class names with Pbb. --- src/contrib/packetbb.cc | 794 ++++++++++++++--------------- src/contrib/packetbb.h | 236 +++++---- src/contrib/test-packetbb.cc | 963 +++++++++++++++++------------------ 3 files changed, 992 insertions(+), 1001 deletions(-) diff --git a/src/contrib/packetbb.cc b/src/contrib/packetbb.cc index 4eee57048..806db5877 100644 --- a/src/contrib/packetbb.cc +++ b/src/contrib/packetbb.cc @@ -34,7 +34,7 @@ static const uint8_t VERSION = 0; static const uint8_t PHAS_SEQ_NUM = 0x8; static const uint8_t PHAS_TLV = 0x4; -/* Message flags */ +/* PbbMessage flags */ static const uint8_t MHAS_ORIG = 0x80; static const uint8_t MHAS_HOP_LIMIT = 0x40; static const uint8_t MHAS_HOP_COUNT = 0x20; @@ -57,108 +57,106 @@ static const uint8_t TIS_MULTIVALUE = 0x04; namespace ns3 { -namespace pbb { +NS_OBJECT_ENSURE_REGISTERED (PbbPacket); -NS_OBJECT_ENSURE_REGISTERED (PacketBB); - -TlvBlock::Iterator -TlvBlock::Begin (void) +PbbTlvBlock::Iterator +PbbTlvBlock::Begin (void) { return m_tlvList.begin (); } -TlvBlock::ConstIterator -TlvBlock::Begin (void) const +PbbTlvBlock::ConstIterator +PbbTlvBlock::Begin (void) const { return m_tlvList.begin (); } -TlvBlock::Iterator -TlvBlock::End (void) +PbbTlvBlock::Iterator +PbbTlvBlock::End (void) { return m_tlvList.end (); } -TlvBlock::ConstIterator -TlvBlock::End (void) const +PbbTlvBlock::ConstIterator +PbbTlvBlock::End (void) const { return m_tlvList.end (); } int -TlvBlock::Size (void) const +PbbTlvBlock::Size (void) const { return m_tlvList.size (); } bool -TlvBlock::Empty (void) const +PbbTlvBlock::Empty (void) const { return m_tlvList.empty (); } -Ptr -TlvBlock::Front (void) const +Ptr +PbbTlvBlock::Front (void) const { return m_tlvList.front (); } -Ptr -TlvBlock::Back (void) const +Ptr +PbbTlvBlock::Back (void) const { return m_tlvList.back (); } void -TlvBlock::PushFront (Ptr tlv) +PbbTlvBlock::PushFront (Ptr tlv) { m_tlvList.push_front (tlv); } void -TlvBlock::PopFront (void) +PbbTlvBlock::PopFront (void) { m_tlvList.pop_front (); } void -TlvBlock::PushBack (Ptr tlv) +PbbTlvBlock::PushBack (Ptr tlv) { m_tlvList.push_back (tlv); } void -TlvBlock::PopBack (void) +PbbTlvBlock::PopBack (void) { m_tlvList.pop_back (); } -TlvBlock::Iterator -TlvBlock::Insert (TlvBlock::Iterator position, const Ptr tlv) +PbbTlvBlock::Iterator +PbbTlvBlock::Insert (PbbTlvBlock::Iterator position, const Ptr tlv) { return m_tlvList.insert (position, tlv); } -TlvBlock::Iterator -TlvBlock::Erase (TlvBlock::Iterator position) +PbbTlvBlock::Iterator +PbbTlvBlock::Erase (PbbTlvBlock::Iterator position) { return m_tlvList.erase (position); } -TlvBlock::Iterator -TlvBlock::Erase (TlvBlock::Iterator first, TlvBlock::Iterator last) +PbbTlvBlock::Iterator +PbbTlvBlock::Erase (PbbTlvBlock::Iterator first, PbbTlvBlock::Iterator last) { return m_tlvList.erase (first, last); } void -TlvBlock::Clear (void) +PbbTlvBlock::Clear (void) { m_tlvList.clear (); } uint32_t -TlvBlock::GetSerializedSize (void) const +PbbTlvBlock::GetSerializedSize (void) const { /* tlv size */ uint32_t size = 2; @@ -170,7 +168,7 @@ TlvBlock::GetSerializedSize (void) const } void -TlvBlock::Serialize (Buffer::Iterator &start) const +PbbTlvBlock::Serialize (Buffer::Iterator &start) const { if (Empty ()) { @@ -192,7 +190,7 @@ TlvBlock::Serialize (Buffer::Iterator &start) const } void -TlvBlock::Deserialize (Buffer::Iterator &start) +PbbTlvBlock::Deserialize (Buffer::Iterator &start) { uint16_t size = start.ReadNtohU16 (); @@ -201,7 +199,7 @@ TlvBlock::Deserialize (Buffer::Iterator &start) { while (start.GetDistanceFrom (tlvstart) < size) { - Ptr newtlv = Create (); + Ptr newtlv = Create (); newtlv->Deserialize (start); PushBack (newtlv); } @@ -209,13 +207,13 @@ TlvBlock::Deserialize (Buffer::Iterator &start) } void -TlvBlock::Print (std::ostream &os) const +PbbTlvBlock::Print (std::ostream &os) const { Print (os, 0); } void -TlvBlock::Print (std::ostream &os, int level) const +PbbTlvBlock::Print (std::ostream &os, int level) const { std::string prefix = ""; for (int i = 0; i < level; i++) @@ -237,7 +235,7 @@ TlvBlock::Print (std::ostream &os, int level) const } bool -TlvBlock::operator== (const TlvBlock &other) const +PbbTlvBlock::operator== (const PbbTlvBlock &other) const { if (Size () != other.Size ()) { @@ -258,111 +256,111 @@ TlvBlock::operator== (const TlvBlock &other) const } bool -TlvBlock::operator!= (const TlvBlock &other) const +PbbTlvBlock::operator!= (const PbbTlvBlock &other) const { return !(*this == other); } -/* End TlvBlock class */ +/* End PbbTlvBlock class */ -AddressTlvBlock::Iterator -AddressTlvBlock::Begin (void) +PbbAddressTlvBlock::Iterator +PbbAddressTlvBlock::Begin (void) { return m_tlvList.begin (); } -AddressTlvBlock::ConstIterator -AddressTlvBlock::Begin (void) const +PbbAddressTlvBlock::ConstIterator +PbbAddressTlvBlock::Begin (void) const { return m_tlvList.begin (); } -AddressTlvBlock::Iterator -AddressTlvBlock::End (void) +PbbAddressTlvBlock::Iterator +PbbAddressTlvBlock::End (void) { return m_tlvList.end (); } -AddressTlvBlock::ConstIterator -AddressTlvBlock::End (void) const +PbbAddressTlvBlock::ConstIterator +PbbAddressTlvBlock::End (void) const { return m_tlvList.end (); } int -AddressTlvBlock::Size (void) const +PbbAddressTlvBlock::Size (void) const { return m_tlvList.size (); } bool -AddressTlvBlock::Empty (void) const +PbbAddressTlvBlock::Empty (void) const { return m_tlvList.empty (); } -Ptr -AddressTlvBlock::Front (void) const +Ptr +PbbAddressTlvBlock::Front (void) const { return m_tlvList.front (); } -Ptr -AddressTlvBlock::Back (void) const +Ptr +PbbAddressTlvBlock::Back (void) const { return m_tlvList.back (); } void -AddressTlvBlock::PushFront (Ptr tlv) +PbbAddressTlvBlock::PushFront (Ptr tlv) { m_tlvList.push_front (tlv); } void -AddressTlvBlock::PopFront (void) +PbbAddressTlvBlock::PopFront (void) { m_tlvList.pop_front (); } void -AddressTlvBlock::PushBack (Ptr tlv) +PbbAddressTlvBlock::PushBack (Ptr tlv) { m_tlvList.push_back (tlv); } void -AddressTlvBlock::PopBack (void) +PbbAddressTlvBlock::PopBack (void) { m_tlvList.pop_back (); } -AddressTlvBlock::Iterator -AddressTlvBlock::Insert (AddressTlvBlock::Iterator position, const Ptr tlv) +PbbAddressTlvBlock::Iterator +PbbAddressTlvBlock::Insert (PbbAddressTlvBlock::Iterator position, const Ptr tlv) { return m_tlvList.insert (position, tlv); } -AddressTlvBlock::Iterator -AddressTlvBlock::Erase (AddressTlvBlock::Iterator position) +PbbAddressTlvBlock::Iterator +PbbAddressTlvBlock::Erase (PbbAddressTlvBlock::Iterator position) { return m_tlvList.erase (position); } -AddressTlvBlock::Iterator -AddressTlvBlock::Erase (AddressTlvBlock::Iterator first, AddressTlvBlock::Iterator last) +PbbAddressTlvBlock::Iterator +PbbAddressTlvBlock::Erase (PbbAddressTlvBlock::Iterator first, PbbAddressTlvBlock::Iterator last) { return m_tlvList.erase (first, last); } void -AddressTlvBlock::Clear (void) +PbbAddressTlvBlock::Clear (void) { m_tlvList.clear (); } uint32_t -AddressTlvBlock::GetSerializedSize (void) const +PbbAddressTlvBlock::GetSerializedSize (void) const { /* tlv size */ uint32_t size = 2; @@ -374,7 +372,7 @@ AddressTlvBlock::GetSerializedSize (void) const } void -AddressTlvBlock::Serialize (Buffer::Iterator &start) const +PbbAddressTlvBlock::Serialize (Buffer::Iterator &start) const { if (Empty ()) { @@ -396,7 +394,7 @@ AddressTlvBlock::Serialize (Buffer::Iterator &start) const } void -AddressTlvBlock::Deserialize (Buffer::Iterator &start) +PbbAddressTlvBlock::Deserialize (Buffer::Iterator &start) { uint16_t size = start.ReadNtohU16 (); @@ -405,7 +403,7 @@ AddressTlvBlock::Deserialize (Buffer::Iterator &start) { while (start.GetDistanceFrom (tlvstart) < size) { - Ptr newtlv = Create (); + Ptr newtlv = Create (); newtlv->Deserialize (start); PushBack (newtlv); } @@ -413,13 +411,13 @@ AddressTlvBlock::Deserialize (Buffer::Iterator &start) } void -AddressTlvBlock::Print (std::ostream &os) const +PbbAddressTlvBlock::Print (std::ostream &os) const { Print (os, 0); } void -AddressTlvBlock::Print (std::ostream &os, int level) const +PbbAddressTlvBlock::Print (std::ostream &os, int level) const { std::string prefix = ""; for (int i = 0; i < level; i++) @@ -441,7 +439,7 @@ AddressTlvBlock::Print (std::ostream &os, int level) const } bool -AddressTlvBlock::operator== (const AddressTlvBlock &other) const +PbbAddressTlvBlock::operator== (const PbbAddressTlvBlock &other) const { if (Size () != other.Size ()) { @@ -462,15 +460,15 @@ AddressTlvBlock::operator== (const AddressTlvBlock &other) const } bool -AddressTlvBlock::operator!= (const AddressTlvBlock &other) const +PbbAddressTlvBlock::operator!= (const PbbAddressTlvBlock &other) const { return !(*this == other); } -/* End AddressTlvBlock Class */ +/* End PbbAddressTlvBlock Class */ -PacketBB::PacketBB (void) +PbbPacket::PbbPacket (void) { m_refCount = 1; m_version = VERSION; @@ -478,248 +476,248 @@ PacketBB::PacketBB (void) } uint8_t -PacketBB::GetVersion (void) const +PbbPacket::GetVersion (void) const { return m_version; } void -PacketBB::SetSequenceNumber (uint16_t number) +PbbPacket::SetSequenceNumber (uint16_t number) { m_seqnum = number; m_hasseqnum = true; } uint16_t -PacketBB::GetSequenceNumber (void) const +PbbPacket::GetSequenceNumber (void) const { NS_ASSERT (HasSequenceNumber ()); return m_seqnum; } bool -PacketBB::HasSequenceNumber (void) const +PbbPacket::HasSequenceNumber (void) const { return m_hasseqnum; } /* Manipulating Packet TLVs */ -PacketBB::TlvIterator -PacketBB::TlvBegin (void) +PbbPacket::TlvIterator +PbbPacket::TlvBegin (void) { return m_tlvList.Begin (); } -PacketBB::ConstTlvIterator -PacketBB::TlvBegin (void) const +PbbPacket::ConstTlvIterator +PbbPacket::TlvBegin (void) const { return m_tlvList.Begin (); } -PacketBB::TlvIterator -PacketBB::TlvEnd (void) +PbbPacket::TlvIterator +PbbPacket::TlvEnd (void) { return m_tlvList.End (); } -PacketBB::ConstTlvIterator -PacketBB::TlvEnd (void) const +PbbPacket::ConstTlvIterator +PbbPacket::TlvEnd (void) const { return m_tlvList.End (); } int -PacketBB::TlvSize (void) const +PbbPacket::TlvSize (void) const { return m_tlvList.Size (); } bool -PacketBB::TlvEmpty (void) const +PbbPacket::TlvEmpty (void) const { return m_tlvList.Empty (); } -Ptr -PacketBB::TlvFront (void) +Ptr +PbbPacket::TlvFront (void) { return m_tlvList.Front (); } -const Ptr -PacketBB::TlvFront (void) const +const Ptr +PbbPacket::TlvFront (void) const { return m_tlvList.Front (); } -Ptr -PacketBB::TlvBack (void) +Ptr +PbbPacket::TlvBack (void) { return m_tlvList.Back (); } -const Ptr -PacketBB::TlvBack (void) const +const Ptr +PbbPacket::TlvBack (void) const { return m_tlvList.Back (); } void -PacketBB::TlvPushFront (Ptr tlv) +PbbPacket::TlvPushFront (Ptr tlv) { m_tlvList.PushFront (tlv); } void -PacketBB::TlvPopFront (void) +PbbPacket::TlvPopFront (void) { m_tlvList.PopFront (); } void -PacketBB::TlvPushBack (Ptr tlv) +PbbPacket::TlvPushBack (Ptr tlv) { m_tlvList.PushBack (tlv); } void -PacketBB::TlvPopBack (void) +PbbPacket::TlvPopBack (void) { m_tlvList.PopBack (); } -PacketBB::TlvIterator -PacketBB::Erase (PacketBB::TlvIterator position) +PbbPacket::TlvIterator +PbbPacket::Erase (PbbPacket::TlvIterator position) { return m_tlvList.Erase (position); } -PacketBB::TlvIterator -PacketBB::Erase (PacketBB::TlvIterator first, PacketBB::TlvIterator last) +PbbPacket::TlvIterator +PbbPacket::Erase (PbbPacket::TlvIterator first, PbbPacket::TlvIterator last) { return m_tlvList.Erase (first, last); } void -PacketBB::TlvClear (void) +PbbPacket::TlvClear (void) { m_tlvList.Clear (); } /* Manipulating Packet Messages */ -PacketBB::MessageIterator -PacketBB::MessageBegin (void) +PbbPacket::MessageIterator +PbbPacket::MessageBegin (void) { return m_messageList.begin (); } -PacketBB::ConstMessageIterator -PacketBB::MessageBegin (void) const +PbbPacket::ConstMessageIterator +PbbPacket::MessageBegin (void) const { return m_messageList.begin (); } -PacketBB::MessageIterator -PacketBB::MessageEnd (void) +PbbPacket::MessageIterator +PbbPacket::MessageEnd (void) { return m_messageList.end (); } -PacketBB::ConstMessageIterator -PacketBB::MessageEnd (void) const +PbbPacket::ConstMessageIterator +PbbPacket::MessageEnd (void) const { return m_messageList.end (); } int -PacketBB::MessageSize (void) const +PbbPacket::MessageSize (void) const { return m_messageList.size (); } bool -PacketBB::MessageEmpty (void) const +PbbPacket::MessageEmpty (void) const { return m_messageList.empty (); } -Ptr -PacketBB::MessageFront (void) +Ptr +PbbPacket::MessageFront (void) { return m_messageList.front (); } -const Ptr -PacketBB::MessageFront (void) const +const Ptr +PbbPacket::MessageFront (void) const { return m_messageList.front (); } -Ptr -PacketBB::MessageBack (void) +Ptr +PbbPacket::MessageBack (void) { return m_messageList.back (); } -const Ptr -PacketBB::MessageBack (void) const +const Ptr +PbbPacket::MessageBack (void) const { return m_messageList.back (); } void -PacketBB::MessagePushFront (Ptr tlv) +PbbPacket::MessagePushFront (Ptr tlv) { m_messageList.push_front (tlv); } void -PacketBB::MessagePopFront (void) +PbbPacket::MessagePopFront (void) { m_messageList.pop_front (); } void -PacketBB::MessagePushBack (Ptr tlv) +PbbPacket::MessagePushBack (Ptr tlv) { m_messageList.push_back (tlv); } void -PacketBB::MessagePopBack (void) +PbbPacket::MessagePopBack (void) { m_messageList.pop_back (); } -PacketBB::MessageIterator -PacketBB::Erase (PacketBB::MessageIterator position) +PbbPacket::MessageIterator +PbbPacket::Erase (PbbPacket::MessageIterator position) { return m_messageList.erase (position); } -PacketBB::MessageIterator -PacketBB::Erase (PacketBB::MessageIterator first, - PacketBB::MessageIterator last) +PbbPacket::MessageIterator +PbbPacket::Erase (PbbPacket::MessageIterator first, + PbbPacket::MessageIterator last) { return m_messageList.erase (first, last); } void -PacketBB::MessageClear (void) +PbbPacket::MessageClear (void) { m_messageList.clear (); } void -PacketBB::Ref (void) const +PbbPacket::Ref (void) const { m_refCount++; } void -PacketBB::Unref (void) const +PbbPacket::Unref (void) const { m_refCount--; if (m_refCount == 0) @@ -729,23 +727,23 @@ PacketBB::Unref (void) const } TypeId -PacketBB::GetTypeId (void) +PbbPacket::GetTypeId (void) { - static TypeId tid = TypeId ("PacketBB") + static TypeId tid = TypeId ("PbbPacket") .SetParent
() - .AddConstructor () + .AddConstructor () ; return tid; } TypeId -PacketBB::GetInstanceTypeId (void) const +PbbPacket::GetInstanceTypeId (void) const { return GetTypeId (); } uint32_t -PacketBB::GetSerializedSize (void) const +PbbPacket::GetSerializedSize (void) const { /* Version number + flags */ uint32_t size = 1; @@ -771,7 +769,7 @@ PacketBB::GetSerializedSize (void) const } void -PacketBB::Serialize (Buffer::Iterator start) const +PbbPacket::Serialize (Buffer::Iterator start) const { /* We remember the start, so we can write the flags after we check for a * sequence number and TLV. */ @@ -805,7 +803,7 @@ PacketBB::Serialize (Buffer::Iterator start) const } uint32_t -PacketBB::Deserialize (Buffer::Iterator start) +PbbPacket::Deserialize (Buffer::Iterator start) { Buffer::Iterator begin = start; @@ -823,7 +821,7 @@ PacketBB::Deserialize (Buffer::Iterator start) while (!start.IsEnd()) { - Ptr newmsg = Message::DeserializeMessage (start); + Ptr newmsg = PbbMessage::DeserializeMessage (start); if (newmsg == 0) { return start.GetDistanceFrom (begin); @@ -838,9 +836,9 @@ PacketBB::Deserialize (Buffer::Iterator start) } void -PacketBB::Print (std::ostream &os) const +PbbPacket::Print (std::ostream &os) const { - os << "PacketBB {" << std::endl; + os << "PbbPacket {" << std::endl; if (HasSequenceNumber ()) { @@ -862,7 +860,7 @@ PacketBB::Print (std::ostream &os) const } bool -PacketBB::operator== (const PacketBB &other) const +PbbPacket::operator== (const PbbPacket &other) const { if (GetVersion () != other.GetVersion ()) { @@ -904,14 +902,14 @@ PacketBB::operator== (const PacketBB &other) const } bool -PacketBB::operator!= (const PacketBB &other) const +PbbPacket::operator!= (const PbbPacket &other) const { return !(*this == other); } -/* End PacketBB class */ +/* End PbbPacket class */ -Message::Message (void) +PbbMessage::PbbMessage (void) { m_refCount = 1; /* Default to IPv4 */ @@ -923,320 +921,320 @@ Message::Message (void) } void -Message::SetType (uint8_t type) +PbbMessage::SetType (uint8_t type) { m_type = type; } uint8_t -Message::GetType (void) const +PbbMessage::GetType (void) const { return m_type; } AddressLength -Message::GetAddressLength (void) const +PbbMessage::GetAddressLength (void) const { return m_addrSize; } void -Message::SetOriginatorAddress (Address address) +PbbMessage::SetOriginatorAddress (Address address) { m_originatorAddress = address; m_hasOriginatorAddress = true; } Address -Message::GetOriginatorAddress (void) const +PbbMessage::GetOriginatorAddress (void) const { NS_ASSERT (HasOriginatorAddress ()); return m_originatorAddress; } bool -Message::HasOriginatorAddress (void) const +PbbMessage::HasOriginatorAddress (void) const { return m_hasOriginatorAddress; } void -Message::SetHopLimit (uint8_t hopLimit) +PbbMessage::SetHopLimit (uint8_t hopLimit) { m_hopLimit = hopLimit; m_hasHopLimit = true; } uint8_t -Message::GetHopLimit (void) const +PbbMessage::GetHopLimit (void) const { NS_ASSERT (HasHopLimit ()); return m_hopLimit; } bool -Message::HasHopLimit (void) const +PbbMessage::HasHopLimit (void) const { return m_hasHopLimit; } void -Message::SetHopCount (uint8_t hopCount) +PbbMessage::SetHopCount (uint8_t hopCount) { m_hopCount = hopCount; m_hasHopCount = true; } uint8_t -Message::GetHopCount (void) const +PbbMessage::GetHopCount (void) const { NS_ASSERT (HasHopCount ()); return m_hopCount; } bool -Message::HasHopCount (void) const +PbbMessage::HasHopCount (void) const { return m_hasHopCount; } void -Message::SetSequenceNumber (uint16_t sequenceNumber) +PbbMessage::SetSequenceNumber (uint16_t sequenceNumber) { m_sequenceNumber = sequenceNumber; m_hasSequenceNumber = true; } uint16_t -Message::GetSequenceNumber (void) const +PbbMessage::GetSequenceNumber (void) const { NS_ASSERT (HasSequenceNumber ()); return m_sequenceNumber; } bool -Message::HasSequenceNumber (void) const +PbbMessage::HasSequenceNumber (void) const { return m_hasSequenceNumber; } -/* Manipulating Message TLVs */ +/* Manipulating PbbMessage TLVs */ -Message::TlvIterator -Message::TlvBegin (void) +PbbMessage::TlvIterator +PbbMessage::TlvBegin (void) { return m_tlvList.Begin(); } -Message::ConstTlvIterator -Message::TlvBegin (void) const +PbbMessage::ConstTlvIterator +PbbMessage::TlvBegin (void) const { return m_tlvList.Begin(); } -Message::TlvIterator -Message::TlvEnd (void) +PbbMessage::TlvIterator +PbbMessage::TlvEnd (void) { return m_tlvList.End(); } -Message::ConstTlvIterator -Message::TlvEnd (void) const +PbbMessage::ConstTlvIterator +PbbMessage::TlvEnd (void) const { return m_tlvList.End(); } int -Message::TlvSize (void) const +PbbMessage::TlvSize (void) const { return m_tlvList.Size(); } bool -Message::TlvEmpty (void) const +PbbMessage::TlvEmpty (void) const { return m_tlvList.Empty(); } -Ptr -Message::TlvFront (void) +Ptr +PbbMessage::TlvFront (void) { return m_tlvList.Front(); } -const Ptr -Message::TlvFront (void) const +const Ptr +PbbMessage::TlvFront (void) const { return m_tlvList.Front(); } -Ptr -Message::TlvBack (void) +Ptr +PbbMessage::TlvBack (void) { return m_tlvList.Back(); } -const Ptr -Message::TlvBack (void) const +const Ptr +PbbMessage::TlvBack (void) const { return m_tlvList.Back(); } void -Message::TlvPushFront (Ptr tlv) +PbbMessage::TlvPushFront (Ptr tlv) { m_tlvList.PushFront(tlv); } void -Message::TlvPopFront (void) +PbbMessage::TlvPopFront (void) { m_tlvList.PopFront(); } void -Message::TlvPushBack (Ptr tlv) +PbbMessage::TlvPushBack (Ptr tlv) { m_tlvList.PushBack(tlv); } void -Message::TlvPopBack (void) +PbbMessage::TlvPopBack (void) { m_tlvList.PopBack(); } -Message::TlvIterator -Message::TlvErase (Message::TlvIterator position) +PbbMessage::TlvIterator +PbbMessage::TlvErase (PbbMessage::TlvIterator position) { return m_tlvList.Erase(position); } -Message::TlvIterator -Message::TlvErase (Message::TlvIterator first, Message::TlvIterator last) +PbbMessage::TlvIterator +PbbMessage::TlvErase (PbbMessage::TlvIterator first, PbbMessage::TlvIterator last) { return m_tlvList.Erase(first, last); } void -Message::TlvClear (void) +PbbMessage::TlvClear (void) { return m_tlvList.Clear(); } /* Manipulating Address Block and Address TLV pairs */ -Message::AddressBlockIterator -Message::AddressBlockBegin (void) +PbbMessage::AddressBlockIterator +PbbMessage::AddressBlockBegin (void) { return m_addressBlockList.begin(); } -Message::ConstAddressBlockIterator -Message::AddressBlockBegin (void) const +PbbMessage::ConstAddressBlockIterator +PbbMessage::AddressBlockBegin (void) const { return m_addressBlockList.begin(); } -Message::AddressBlockIterator -Message::AddressBlockEnd (void) +PbbMessage::AddressBlockIterator +PbbMessage::AddressBlockEnd (void) { return m_addressBlockList.end(); } -Message::ConstAddressBlockIterator -Message::AddressBlockEnd (void) const +PbbMessage::ConstAddressBlockIterator +PbbMessage::AddressBlockEnd (void) const { return m_addressBlockList.end(); } int -Message::AddressBlockSize (void) const +PbbMessage::AddressBlockSize (void) const { return m_addressBlockList.size(); } bool -Message::AddressBlockEmpty (void) const +PbbMessage::AddressBlockEmpty (void) const { return m_addressBlockList.empty(); } -Ptr -Message::AddressBlockFront (void) +Ptr +PbbMessage::AddressBlockFront (void) { return m_addressBlockList.front(); } -const Ptr -Message::AddressBlockFront (void) const +const Ptr +PbbMessage::AddressBlockFront (void) const { return m_addressBlockList.front(); } -Ptr -Message::AddressBlockBack (void) +Ptr +PbbMessage::AddressBlockBack (void) { return m_addressBlockList.back(); } -const Ptr -Message::AddressBlockBack (void) const +const Ptr +PbbMessage::AddressBlockBack (void) const { return m_addressBlockList.back(); } void -Message::AddressBlockPushFront (Ptr tlv) +PbbMessage::AddressBlockPushFront (Ptr tlv) { m_addressBlockList.push_front(tlv); } void -Message::AddressBlockPopFront (void) +PbbMessage::AddressBlockPopFront (void) { m_addressBlockList.pop_front(); } void -Message::AddressBlockPushBack (Ptr tlv) +PbbMessage::AddressBlockPushBack (Ptr tlv) { m_addressBlockList.push_back(tlv); } void -Message::AddressBlockPopBack (void) +PbbMessage::AddressBlockPopBack (void) { m_addressBlockList.pop_back(); } -Message::AddressBlockIterator -Message::AddressBlockErase (Message::AddressBlockIterator position) +PbbMessage::AddressBlockIterator +PbbMessage::AddressBlockErase (PbbMessage::AddressBlockIterator position) { return m_addressBlockList.erase(position); } -Message::AddressBlockIterator -Message::AddressBlockErase (Message::AddressBlockIterator first, - Message::AddressBlockIterator last) +PbbMessage::AddressBlockIterator +PbbMessage::AddressBlockErase (PbbMessage::AddressBlockIterator first, + PbbMessage::AddressBlockIterator last) { return m_addressBlockList.erase(first, last); } void -Message::AddressBlockClear (void) +PbbMessage::AddressBlockClear (void) { return m_addressBlockList.clear(); } void -Message::Ref (void) const +PbbMessage::Ref (void) const { m_refCount++; } void -Message::Unref (void) const +PbbMessage::Unref (void) const { m_refCount--; if (m_refCount == 0) @@ -1246,7 +1244,7 @@ Message::Unref (void) const } uint32_t -Message::GetSerializedSize (void) const +PbbMessage::GetSerializedSize (void) const { /* msg-type + (msg-flags + msg-addr-length) + 2msg-size */ uint32_t size = 4; @@ -1284,7 +1282,7 @@ Message::GetSerializedSize (void) const } void -Message::Serialize (Buffer::Iterator &start) const +PbbMessage::Serialize (Buffer::Iterator &start) const { Buffer::Iterator front = start; @@ -1339,8 +1337,8 @@ Message::Serialize (Buffer::Iterator &start) const sizeref.WriteHtonU16 (front.GetDistanceFrom (start)); } -Ptr -Message::DeserializeMessage (Buffer::Iterator &start) +Ptr +PbbMessage::DeserializeMessage (Buffer::Iterator &start) { /* We need to read the msg-addr-len field to determine what kind of object to * construct. */ @@ -1352,16 +1350,16 @@ Message::DeserializeMessage (Buffer::Iterator &start) * bytes to 0 to read it. */ addrlen = (addrlen & 0xf); - Ptr newmsg; + Ptr newmsg; switch (addrlen) { case 0: case IPV4: - newmsg = Create (); + newmsg = Create (); break; case IPV6: - newmsg = Create (); + newmsg = Create (); break; default: return 0; @@ -1372,7 +1370,7 @@ Message::DeserializeMessage (Buffer::Iterator &start) } void -Message::Deserialize (Buffer::Iterator &start) +PbbMessage::Deserialize (Buffer::Iterator &start) { Buffer::Iterator front = start; SetType (start.ReadU8 ()); @@ -1406,20 +1404,20 @@ Message::Deserialize (Buffer::Iterator &start) { while (start.GetDistanceFrom(front) < size) { - Ptr newab = AddressBlockDeserialize (start); + Ptr newab = AddressBlockDeserialize (start); AddressBlockPushBack (newab); } } } void -Message::Print (std::ostream &os) const +PbbMessage::Print (std::ostream &os) const { Print (os, 0); } void -Message::Print (std::ostream &os, int level) const +PbbMessage::Print (std::ostream &os, int level) const { std::string prefix = ""; for (int i = 0; i < level; i++) @@ -1427,7 +1425,7 @@ Message::Print (std::ostream &os, int level) const prefix.append ("\t"); } - os << prefix << "Message {" << std::endl; + os << prefix << "PbbMessage {" << std::endl; os << prefix << "\tmessage type = " << (int)GetType () << std::endl; os << prefix << "\taddress size = " << GetAddressLength () << std::endl; @@ -1466,7 +1464,7 @@ Message::Print (std::ostream &os, int level) const } bool -Message::operator== (const Message &other) const +PbbMessage::operator== (const PbbMessage &other) const { if (GetAddressLength () != other.GetAddressLength ()) { @@ -1554,21 +1552,21 @@ Message::operator== (const Message &other) const } bool -Message::operator!= (const Message &other) const +PbbMessage::operator!= (const PbbMessage &other) const { return !(*this == other); } -/* End Message Class */ +/* End PbbMessage Class */ AddressLength -MessageIpv4::GetAddressLength (void) const +PbbMessageIpv4::GetAddressLength (void) const { return IPV4; } void -MessageIpv4::SerializeOriginatorAddress (Buffer::Iterator &start) const +PbbMessageIpv4::SerializeOriginatorAddress (Buffer::Iterator &start) const { uint8_t buffer[GetAddressLength () + 1]; Ipv4Address::ConvertFrom (GetOriginatorAddress ()).Serialize(buffer); @@ -1576,7 +1574,7 @@ MessageIpv4::SerializeOriginatorAddress (Buffer::Iterator &start) const } Address -MessageIpv4::DeserializeOriginatorAddress (Buffer::Iterator &start) const +PbbMessageIpv4::DeserializeOriginatorAddress (Buffer::Iterator &start) const { uint8_t buffer[GetAddressLength () + 1]; start.Read(buffer, GetAddressLength () + 1); @@ -1584,29 +1582,29 @@ MessageIpv4::DeserializeOriginatorAddress (Buffer::Iterator &start) const } void -MessageIpv4::PrintOriginatorAddress (std::ostream &os) const +PbbMessageIpv4::PrintOriginatorAddress (std::ostream &os) const { Ipv4Address::ConvertFrom (GetOriginatorAddress ()).Print (os); } -Ptr -MessageIpv4::AddressBlockDeserialize (Buffer::Iterator &start) const +Ptr +PbbMessageIpv4::AddressBlockDeserialize (Buffer::Iterator &start) const { - Ptr newab = Create (); + Ptr newab = Create (); newab->Deserialize (start); return newab; } -/* End MessageIpv4 Class */ +/* End PbbMessageIpv4 Class */ AddressLength -MessageIpv6::GetAddressLength (void) const +PbbMessageIpv6::GetAddressLength (void) const { return IPV6; } void -MessageIpv6::SerializeOriginatorAddress (Buffer::Iterator &start) const +PbbMessageIpv6::SerializeOriginatorAddress (Buffer::Iterator &start) const { uint8_t buffer[GetAddressLength () + 1]; Ipv6Address::ConvertFrom (GetOriginatorAddress ()).Serialize(buffer); @@ -1614,7 +1612,7 @@ MessageIpv6::SerializeOriginatorAddress (Buffer::Iterator &start) const } Address -MessageIpv6::DeserializeOriginatorAddress (Buffer::Iterator &start) const +PbbMessageIpv6::DeserializeOriginatorAddress (Buffer::Iterator &start) const { uint8_t buffer[GetAddressLength () + 1]; start.Read(buffer, GetAddressLength () + 1); @@ -1622,330 +1620,330 @@ MessageIpv6::DeserializeOriginatorAddress (Buffer::Iterator &start) const } void -MessageIpv6::PrintOriginatorAddress (std::ostream &os) const +PbbMessageIpv6::PrintOriginatorAddress (std::ostream &os) const { Ipv6Address::ConvertFrom (GetOriginatorAddress ()).Print (os); } -Ptr -MessageIpv6::AddressBlockDeserialize (Buffer::Iterator &start) const +Ptr +PbbMessageIpv6::AddressBlockDeserialize (Buffer::Iterator &start) const { - Ptr newab = Create (); + Ptr newab = Create (); newab->Deserialize (start); return newab; } -/* End MessageIpv6 Class */ +/* End PbbMessageIpv6 Class */ -AddressBlock::AddressBlock () +PbbAddressBlock::PbbAddressBlock () { m_refCount = 1; } /* Manipulating the address block */ -AddressBlock::AddressIterator -AddressBlock::AddressBegin (void) +PbbAddressBlock::AddressIterator +PbbAddressBlock::AddressBegin (void) { return m_addressList.begin(); } -AddressBlock::ConstAddressIterator -AddressBlock::AddressBegin (void) const +PbbAddressBlock::ConstAddressIterator +PbbAddressBlock::AddressBegin (void) const { return m_addressList.begin(); } -AddressBlock::AddressIterator -AddressBlock::AddressEnd (void) +PbbAddressBlock::AddressIterator +PbbAddressBlock::AddressEnd (void) { return m_addressList.end(); } -AddressBlock::ConstAddressIterator -AddressBlock::AddressEnd (void) const +PbbAddressBlock::ConstAddressIterator +PbbAddressBlock::AddressEnd (void) const { return m_addressList.end(); } int -AddressBlock::AddressSize (void) const +PbbAddressBlock::AddressSize (void) const { return m_addressList.size(); } bool -AddressBlock::AddressEmpty (void) const +PbbAddressBlock::AddressEmpty (void) const { return m_addressList.empty(); } Address -AddressBlock::AddressFront (void) const +PbbAddressBlock::AddressFront (void) const { return m_addressList.front(); } Address -AddressBlock::AddressBack (void) const +PbbAddressBlock::AddressBack (void) const { return m_addressList.back(); } void -AddressBlock::AddressPushFront (Address tlv) +PbbAddressBlock::AddressPushFront (Address tlv) { m_addressList.push_front(tlv); } void -AddressBlock::AddressPopFront (void) +PbbAddressBlock::AddressPopFront (void) { m_addressList.pop_front(); } void -AddressBlock::AddressPushBack (Address tlv) +PbbAddressBlock::AddressPushBack (Address tlv) { m_addressList.push_back(tlv); } void -AddressBlock::AddressPopBack (void) +PbbAddressBlock::AddressPopBack (void) { m_addressList.pop_back(); } -AddressBlock::AddressIterator -AddressBlock::AddressErase (AddressBlock::AddressIterator position) +PbbAddressBlock::AddressIterator +PbbAddressBlock::AddressErase (PbbAddressBlock::AddressIterator position) { return m_addressList.erase(position); } -AddressBlock::AddressIterator -AddressBlock::AddressErase (AddressBlock::AddressIterator first, - AddressBlock::AddressIterator last) +PbbAddressBlock::AddressIterator +PbbAddressBlock::AddressErase (PbbAddressBlock::AddressIterator first, + PbbAddressBlock::AddressIterator last) { return m_addressList.erase(first, last); } void -AddressBlock::AddressClear (void) +PbbAddressBlock::AddressClear (void) { return m_addressList.clear(); } /* Manipulating the prefix list */ -AddressBlock::PrefixIterator -AddressBlock::PrefixBegin (void) +PbbAddressBlock::PrefixIterator +PbbAddressBlock::PrefixBegin (void) { return m_prefixList.begin (); } -AddressBlock::ConstPrefixIterator -AddressBlock::PrefixBegin (void) const +PbbAddressBlock::ConstPrefixIterator +PbbAddressBlock::PrefixBegin (void) const { return m_prefixList.begin (); } -AddressBlock::PrefixIterator -AddressBlock::PrefixEnd (void) +PbbAddressBlock::PrefixIterator +PbbAddressBlock::PrefixEnd (void) { return m_prefixList.end (); } -AddressBlock::ConstPrefixIterator -AddressBlock::PrefixEnd (void) const +PbbAddressBlock::ConstPrefixIterator +PbbAddressBlock::PrefixEnd (void) const { return m_prefixList.end (); } int -AddressBlock::PrefixSize (void) const +PbbAddressBlock::PrefixSize (void) const { return m_prefixList.size (); } bool -AddressBlock::PrefixEmpty (void) const +PbbAddressBlock::PrefixEmpty (void) const { return m_prefixList.empty (); } uint8_t -AddressBlock::PrefixFront (void) const +PbbAddressBlock::PrefixFront (void) const { return m_prefixList.front (); } uint8_t -AddressBlock::PrefixBack (void) const +PbbAddressBlock::PrefixBack (void) const { return m_prefixList.back (); } void -AddressBlock::PrefixPushFront (uint8_t prefix) +PbbAddressBlock::PrefixPushFront (uint8_t prefix) { m_prefixList.push_front (prefix); } void -AddressBlock::PrefixPopFront (void) +PbbAddressBlock::PrefixPopFront (void) { m_prefixList.pop_front (); } void -AddressBlock::PrefixPushBack (uint8_t prefix) +PbbAddressBlock::PrefixPushBack (uint8_t prefix) { m_prefixList.push_back (prefix); } void -AddressBlock::PrefixPopBack (void) +PbbAddressBlock::PrefixPopBack (void) { m_prefixList.pop_back (); } -AddressBlock::PrefixIterator -AddressBlock::PrefixInsert (AddressBlock::PrefixIterator position, const uint8_t value) +PbbAddressBlock::PrefixIterator +PbbAddressBlock::PrefixInsert (PbbAddressBlock::PrefixIterator position, const uint8_t value) { return m_prefixList.insert (position, value); } -AddressBlock::PrefixIterator -AddressBlock::PrefixErase (AddressBlock::PrefixIterator position) +PbbAddressBlock::PrefixIterator +PbbAddressBlock::PrefixErase (PbbAddressBlock::PrefixIterator position) { return m_prefixList.erase (position); } -AddressBlock::PrefixIterator -AddressBlock::PrefixErase (AddressBlock::PrefixIterator first, AddressBlock::PrefixIterator last) +PbbAddressBlock::PrefixIterator +PbbAddressBlock::PrefixErase (PbbAddressBlock::PrefixIterator first, PbbAddressBlock::PrefixIterator last) { return m_prefixList.erase (first, last); } void -AddressBlock::PrefixClear (void) +PbbAddressBlock::PrefixClear (void) { m_prefixList.clear (); } /* Manipulating the TLV block */ -AddressBlock::TlvIterator -AddressBlock::TlvBegin (void) +PbbAddressBlock::TlvIterator +PbbAddressBlock::TlvBegin (void) { return m_addressTlvList.Begin(); } -AddressBlock::ConstTlvIterator -AddressBlock::TlvBegin (void) const +PbbAddressBlock::ConstTlvIterator +PbbAddressBlock::TlvBegin (void) const { return m_addressTlvList.Begin(); } -AddressBlock::TlvIterator -AddressBlock::TlvEnd (void) +PbbAddressBlock::TlvIterator +PbbAddressBlock::TlvEnd (void) { return m_addressTlvList.End(); } -AddressBlock::ConstTlvIterator -AddressBlock::TlvEnd (void) const +PbbAddressBlock::ConstTlvIterator +PbbAddressBlock::TlvEnd (void) const { return m_addressTlvList.End(); } int -AddressBlock::TlvSize (void) const +PbbAddressBlock::TlvSize (void) const { return m_addressTlvList.Size(); } bool -AddressBlock::TlvEmpty (void) const +PbbAddressBlock::TlvEmpty (void) const { return m_addressTlvList.Empty(); } -Ptr -AddressBlock::TlvFront (void) +Ptr +PbbAddressBlock::TlvFront (void) { return m_addressTlvList.Front(); } -const Ptr -AddressBlock::TlvFront (void) const +const Ptr +PbbAddressBlock::TlvFront (void) const { return m_addressTlvList.Front(); } -Ptr -AddressBlock::TlvBack (void) +Ptr +PbbAddressBlock::TlvBack (void) { return m_addressTlvList.Back(); } -const Ptr -AddressBlock::TlvBack (void) const +const Ptr +PbbAddressBlock::TlvBack (void) const { return m_addressTlvList.Back(); } void -AddressBlock::TlvPushFront (Ptr tlv) +PbbAddressBlock::TlvPushFront (Ptr tlv) { m_addressTlvList.PushFront(tlv); } void -AddressBlock::TlvPopFront (void) +PbbAddressBlock::TlvPopFront (void) { m_addressTlvList.PopFront(); } void -AddressBlock::TlvPushBack (Ptr tlv) +PbbAddressBlock::TlvPushBack (Ptr tlv) { m_addressTlvList.PushBack(tlv); } void -AddressBlock::TlvPopBack (void) +PbbAddressBlock::TlvPopBack (void) { m_addressTlvList.PopBack(); } -AddressBlock::TlvIterator -AddressBlock::TlvErase (AddressBlock::TlvIterator position) +PbbAddressBlock::TlvIterator +PbbAddressBlock::TlvErase (PbbAddressBlock::TlvIterator position) { return m_addressTlvList.Erase(position); } -AddressBlock::TlvIterator -AddressBlock::TlvErase (AddressBlock::TlvIterator first, - AddressBlock::TlvIterator last) +PbbAddressBlock::TlvIterator +PbbAddressBlock::TlvErase (PbbAddressBlock::TlvIterator first, + PbbAddressBlock::TlvIterator last) { return m_addressTlvList.Erase(first, last); } void -AddressBlock::TlvClear (void) +PbbAddressBlock::TlvClear (void) { return m_addressTlvList.Clear(); } void -AddressBlock::Ref (void) const +PbbAddressBlock::Ref (void) const { m_refCount++; } void -AddressBlock::Unref (void) const +PbbAddressBlock::Unref (void) const { m_refCount--; if (m_refCount == 0) @@ -1955,7 +1953,7 @@ AddressBlock::Unref (void) const } uint32_t -AddressBlock::GetSerializedSize (void) const +PbbAddressBlock::GetSerializedSize (void) const { /* num-addr + flags */ uint32_t size = 2; @@ -1999,7 +1997,7 @@ AddressBlock::GetSerializedSize (void) const } void -AddressBlock::Serialize (Buffer::Iterator &start) const +PbbAddressBlock::Serialize (Buffer::Iterator &start) const { start.WriteU8 (AddressSize ()); @@ -2054,7 +2052,7 @@ AddressBlock::Serialize (Buffer::Iterator &start) const if (headlen + taillen < GetAddressLength ()) { uint8_t mid[GetAddressLength ()]; - for (AddressBlock::ConstAddressIterator iter = AddressBegin (); + for (PbbAddressBlock::ConstAddressIterator iter = AddressBegin (); iter != AddressEnd (); iter++) { @@ -2078,7 +2076,7 @@ AddressBlock::Serialize (Buffer::Iterator &start) const } void -AddressBlock::Deserialize (Buffer::Iterator &start) +PbbAddressBlock::Deserialize (Buffer::Iterator &start) { uint8_t numaddr = start.ReadU8 (); uint8_t flags = start.ReadU8 (); @@ -2129,13 +2127,13 @@ AddressBlock::Deserialize (Buffer::Iterator &start) } void -AddressBlock::Print (std::ostream &os) const +PbbAddressBlock::Print (std::ostream &os) const { Print (os, 0); } void -AddressBlock::Print (std::ostream &os, int level) const +PbbAddressBlock::Print (std::ostream &os, int level) const { std::string prefix = ""; for (int i = 0; i < level; i++) @@ -2143,7 +2141,7 @@ AddressBlock::Print (std::ostream &os, int level) const prefix.append ("\t"); } - os << prefix << "AddressBlock {" << std::endl; + os << prefix << "PbbAddressBlock {" << std::endl; os << prefix << "\taddresses = " << std::endl; for (ConstAddressIterator iter = AddressBegin (); iter != AddressEnd (); @@ -2166,7 +2164,7 @@ AddressBlock::Print (std::ostream &os, int level) const } bool -AddressBlock::operator== (const AddressBlock &other) const +PbbAddressBlock::operator== (const PbbAddressBlock &other) const { if (AddressSize () != other.AddressSize ()) { @@ -2209,13 +2207,13 @@ AddressBlock::operator== (const AddressBlock &other) const } bool -AddressBlock::operator!= (const AddressBlock &other) const +PbbAddressBlock::operator!= (const PbbAddressBlock &other) const { return !(*this == other); } uint8_t -AddressBlock::GetPrefixFlags (void) const +PbbAddressBlock::GetPrefixFlags (void) const { switch (PrefixSize ()) { @@ -2232,7 +2230,7 @@ AddressBlock::GetPrefixFlags (void) const } void -AddressBlock::GetHeadTail (uint8_t *head, uint8_t &headlen, +PbbAddressBlock::GetHeadTail (uint8_t *head, uint8_t &headlen, uint8_t *tail, uint8_t &taillen) const { headlen = GetAddressLength (); @@ -2246,7 +2244,7 @@ AddressBlock::GetHeadTail (uint8_t *head, uint8_t &headlen, SerializeAddress (buflast, AddressBegin ()); /* Skip the first item */ - for (AddressBlock::ConstAddressIterator iter = AddressBegin ()++; + for (PbbAddressBlock::ConstAddressIterator iter = AddressBegin ()++; iter != AddressEnd (); iter++) { @@ -2295,7 +2293,7 @@ AddressBlock::GetHeadTail (uint8_t *head, uint8_t &headlen, } bool -AddressBlock::HasZeroTail (const uint8_t *tail, uint8_t taillen) const +PbbAddressBlock::HasZeroTail (const uint8_t *tail, uint8_t taillen) const { int i; for (i = 0; i < taillen; i++) @@ -2308,61 +2306,61 @@ AddressBlock::HasZeroTail (const uint8_t *tail, uint8_t taillen) const return i == taillen; } -/* End AddressBlock Class */ +/* End PbbAddressBlock Class */ uint8_t -AddressBlockIpv4::GetAddressLength (void) const +PbbAddressBlockIpv4::GetAddressLength (void) const { return 4; } void -AddressBlockIpv4::SerializeAddress (uint8_t *buffer, ConstAddressIterator iter) const +PbbAddressBlockIpv4::SerializeAddress (uint8_t *buffer, ConstAddressIterator iter) const { Ipv4Address::ConvertFrom (*iter).Serialize (buffer); } Address -AddressBlockIpv4::DeserializeAddress (uint8_t *buffer) const +PbbAddressBlockIpv4::DeserializeAddress (uint8_t *buffer) const { return Ipv4Address::Deserialize (buffer); } void -AddressBlockIpv4::PrintAddress (std::ostream &os, ConstAddressIterator iter) const +PbbAddressBlockIpv4::PrintAddress (std::ostream &os, ConstAddressIterator iter) const { Ipv4Address::ConvertFrom (*iter).Print (os); } -/* End AddressBlockIpv4 Class */ +/* End PbbAddressBlockIpv4 Class */ uint8_t -AddressBlockIpv6::GetAddressLength (void) const +PbbAddressBlockIpv6::GetAddressLength (void) const { return 16; } void -AddressBlockIpv6::SerializeAddress (uint8_t *buffer, ConstAddressIterator iter) const +PbbAddressBlockIpv6::SerializeAddress (uint8_t *buffer, ConstAddressIterator iter) const { Ipv6Address::ConvertFrom (*iter).Serialize (buffer); } Address -AddressBlockIpv6::DeserializeAddress (uint8_t *buffer) const +PbbAddressBlockIpv6::DeserializeAddress (uint8_t *buffer) const { return Ipv6Address::Deserialize (buffer); } void -AddressBlockIpv6::PrintAddress (std::ostream &os, ConstAddressIterator iter) const +PbbAddressBlockIpv6::PrintAddress (std::ostream &os, ConstAddressIterator iter) const { Ipv6Address::ConvertFrom (*iter).Print (os); } -/* End AddressBlockIpv6 Class */ +/* End PbbAddressBlockIpv6 Class */ -Tlv::Tlv (void) +PbbTlv::PbbTlv (void) { m_refCount = 1; m_hasTypeExt = false; @@ -2373,98 +2371,98 @@ Tlv::Tlv (void) } void -Tlv::SetType (uint8_t type) +PbbTlv::SetType (uint8_t type) { m_type = type; } uint8_t -Tlv::GetType (void) const +PbbTlv::GetType (void) const { return m_type; } void -Tlv::SetTypeExt (uint8_t typeExt) +PbbTlv::SetTypeExt (uint8_t typeExt) { m_typeExt = typeExt; m_hasTypeExt = true; } uint8_t -Tlv::GetTypeExt (void) const +PbbTlv::GetTypeExt (void) const { NS_ASSERT (HasTypeExt ()); return m_typeExt; } bool -Tlv::HasTypeExt (void) const +PbbTlv::HasTypeExt (void) const { return m_hasTypeExt; } void -Tlv::SetIndexStart (uint8_t index) +PbbTlv::SetIndexStart (uint8_t index) { m_indexStart = index; m_hasIndexStart = true; } uint8_t -Tlv::GetIndexStart (void) const +PbbTlv::GetIndexStart (void) const { NS_ASSERT (HasIndexStart ()); return m_indexStart; } bool -Tlv::HasIndexStart (void) const +PbbTlv::HasIndexStart (void) const { return m_hasIndexStart; } void -Tlv::SetIndexStop (uint8_t index) +PbbTlv::SetIndexStop (uint8_t index) { m_indexStop = index; m_hasIndexStop = true; } uint8_t -Tlv::GetIndexStop (void) const +PbbTlv::GetIndexStop (void) const { NS_ASSERT (HasIndexStop ()); return m_indexStop; } bool -Tlv::HasIndexStop (void) const +PbbTlv::HasIndexStop (void) const { return m_hasIndexStop; } void -Tlv::SetMultivalue (bool isMultivalue) +PbbTlv::SetMultivalue (bool isMultivalue) { m_isMultivalue = isMultivalue; } bool -Tlv::IsMultivalue (void) const +PbbTlv::IsMultivalue (void) const { return m_isMultivalue; } void -Tlv::SetValue (Buffer start) +PbbTlv::SetValue (Buffer start) { m_hasValue = true; m_value = start; } void -Tlv::SetValue (const uint8_t * buffer, uint32_t size) +PbbTlv::SetValue (const uint8_t * buffer, uint32_t size) { Buffer value; value.AddAtStart (size); @@ -2473,26 +2471,26 @@ Tlv::SetValue (const uint8_t * buffer, uint32_t size) } Buffer -Tlv::GetValue (void) const +PbbTlv::GetValue (void) const { NS_ASSERT (HasValue ()); return m_value; } bool -Tlv::HasValue (void) const +PbbTlv::HasValue (void) const { return m_hasValue; } void -Tlv::Ref (void) const +PbbTlv::Ref (void) const { m_refCount++; } void -Tlv::Unref (void) const +PbbTlv::Unref (void) const { m_refCount--; if (m_refCount == 0) @@ -2502,7 +2500,7 @@ Tlv::Unref (void) const } uint32_t -Tlv::GetSerializedSize (void) const +PbbTlv::GetSerializedSize (void) const { /* type + flags */ uint32_t size = 2; @@ -2539,7 +2537,7 @@ Tlv::GetSerializedSize (void) const } void -Tlv::Serialize (Buffer::Iterator &start) const +PbbTlv::Serialize (Buffer::Iterator &start) const { start.WriteU8 (GetType ()); @@ -2595,7 +2593,7 @@ Tlv::Serialize (Buffer::Iterator &start) const } void -Tlv::Deserialize (Buffer::Iterator &start) +PbbTlv::Deserialize (Buffer::Iterator &start) { SetType (start.ReadU8 ()); @@ -2639,13 +2637,13 @@ Tlv::Deserialize (Buffer::Iterator &start) } void -Tlv::Print (std::ostream &os) const +PbbTlv::Print (std::ostream &os) const { Print (os, 0); } void -Tlv::Print (std::ostream &os, int level) const +PbbTlv::Print (std::ostream &os, int level) const { std::string prefix = ""; for (int i = 0; i < level; i++) @@ -2653,7 +2651,7 @@ Tlv::Print (std::ostream &os, int level) const prefix.append ("\t"); } - os << prefix << "Tlv {" << std::endl; + os << prefix << "PbbTlv {" << std::endl; os << prefix << "\ttype = " << (int)GetType () << std::endl; if (HasTypeExt ()) @@ -2682,7 +2680,7 @@ Tlv::Print (std::ostream &os, int level) const } bool -Tlv::operator== (const Tlv &other) const +PbbTlv::operator== (const PbbTlv &other) const { if (GetType () != other.GetType ()) { @@ -2727,61 +2725,59 @@ Tlv::operator== (const Tlv &other) const } bool -Tlv::operator!= (const Tlv &other) const +PbbTlv::operator!= (const PbbTlv &other) const { return !(*this == other); } -/* End Tlv Class */ +/* End PbbTlv Class */ void -AddressTlv::SetIndexStart (uint8_t index) +PbbAddressTlv::SetIndexStart (uint8_t index) { - Tlv::SetIndexStart (index); + PbbTlv::SetIndexStart (index); } uint8_t -AddressTlv::GetIndexStart (void) const +PbbAddressTlv::GetIndexStart (void) const { - return Tlv::GetIndexStart (); + return PbbTlv::GetIndexStart (); } bool -AddressTlv::HasIndexStart (void) const +PbbAddressTlv::HasIndexStart (void) const { - return Tlv::HasIndexStart (); + return PbbTlv::HasIndexStart (); } void -AddressTlv::SetIndexStop (uint8_t index) +PbbAddressTlv::SetIndexStop (uint8_t index) { - Tlv::SetIndexStop (index); + PbbTlv::SetIndexStop (index); } uint8_t -AddressTlv::GetIndexStop (void) const +PbbAddressTlv::GetIndexStop (void) const { - return Tlv::GetIndexStop (); + return PbbTlv::GetIndexStop (); } bool -AddressTlv::HasIndexStop (void) const +PbbAddressTlv::HasIndexStop (void) const { - return Tlv::HasIndexStop (); + return PbbTlv::HasIndexStop (); } void -AddressTlv::SetMultivalue (bool isMultivalue) +PbbAddressTlv::SetMultivalue (bool isMultivalue) { - Tlv::SetMultivalue (isMultivalue); + PbbTlv::SetMultivalue (isMultivalue); } bool -AddressTlv::IsMultivalue (void) const +PbbAddressTlv::IsMultivalue (void) const { - return Tlv::IsMultivalue (); + return PbbTlv::IsMultivalue (); } -} /* namespace pbb */ - } /* namespace ns3 */ diff --git a/src/contrib/packetbb.h b/src/contrib/packetbb.h index 00e660387..7d6b5b1ae 100644 --- a/src/contrib/packetbb.h +++ b/src/contrib/packetbb.h @@ -19,7 +19,7 @@ * Author: Tom Wambold */ /* These classes implement RFC 5444 - The Generalized Mobile Ad Hoc Network - * (MANET) Packet/Message Format + * (MANET) Packet/PbbMessage Format * See: http://tools.ietf.org/html/rfc5444 for details */ #ifndef PACKETBB_H @@ -34,16 +34,14 @@ namespace ns3 { -namespace pbb { - /* Forward declare objects */ -class PacketBB; -class Message; -class AddressBlock; -class TlvBlock; -class AddressTlvBlock; -class Tlv; -class AddressTlv; +class PbbPacket; +class PbbMessage; +class PbbAddressBlock; +class PbbTlvBlock; +class PbbAddressTlvBlock; +class PbbTlv; +class PbbAddressTlv; enum AddressLength { IPV4 = 3, @@ -51,15 +49,15 @@ enum AddressLength { }; /** - * \brief A block of Packet or Message TLVs. + * \brief A block of Packet or PbbMessage TLVs. * * Acts similar to a C++ STL container. Should not be used for Address TLVs. */ -class TlvBlock +class PbbTlvBlock { public: - typedef std::list< Ptr >::iterator Iterator; - typedef std::list< Ptr >::const_iterator ConstIterator; + typedef std::list< Ptr >::iterator Iterator; + typedef std::list< Ptr >::const_iterator ConstIterator; Iterator Begin (void); ConstIterator Begin (void) const; @@ -69,16 +67,16 @@ public: int Size (void) const; bool Empty (void) const; - Ptr Front (void) const; - Ptr Back (void) const; + Ptr Front (void) const; + Ptr Back (void) const; - void PushFront (Ptr tlv); + void PushFront (Ptr tlv); void PopFront (void); - void PushBack (Ptr tlv); + void PushBack (Ptr tlv); void PopBack (void); - Iterator Insert (Iterator position, const Ptr tlv); + Iterator Insert (Iterator position, const Ptr tlv); Iterator Erase (Iterator position); Iterator Erase (Iterator first, Iterator last); @@ -91,11 +89,11 @@ public: void Print (std::ostream &os) const; void Print (std::ostream &os, int level) const; - bool operator== (const TlvBlock &other) const; - bool operator!= (const TlvBlock &other) const; + bool operator== (const PbbTlvBlock &other) const; + bool operator!= (const PbbTlvBlock &other) const; private: - std::list< Ptr > m_tlvList; + std::list< Ptr > m_tlvList; }; /** @@ -103,11 +101,11 @@ private: * * Acts similar to a C++ STL container. */ -class AddressTlvBlock +class PbbAddressTlvBlock { public: - typedef std::list< Ptr >::iterator Iterator; - typedef std::list< Ptr >::const_iterator ConstIterator; + typedef std::list< Ptr >::iterator Iterator; + typedef std::list< Ptr >::const_iterator ConstIterator; Iterator Begin (void); ConstIterator Begin (void) const; @@ -117,16 +115,16 @@ public: int Size (void) const; bool Empty (void) const; - Ptr Front (void) const; - Ptr Back (void) const; + Ptr Front (void) const; + Ptr Back (void) const; - void PushFront (Ptr tlv); + void PushFront (Ptr tlv); void PopFront (void); - void PushBack (Ptr tlv); + void PushBack (Ptr tlv); void PopBack (void); - Iterator Insert (Iterator position, const Ptr tlv); + Iterator Insert (Iterator position, const Ptr tlv); Iterator Erase (Iterator position); Iterator Erase (Iterator first, Iterator last); @@ -139,25 +137,25 @@ public: void Print (std::ostream &os) const; void Print (std::ostream &os, int level) const; - bool operator== (const AddressTlvBlock &other) const; - bool operator!= (const AddressTlvBlock &other) const; + bool operator== (const PbbAddressTlvBlock &other) const; + bool operator!= (const PbbAddressTlvBlock &other) const; private: - std::list< Ptr > m_tlvList; + std::list< Ptr > m_tlvList; }; /** - * \brief Main PacketBB Packet object. + * \brief Main PbbPacket Packet object. */ -class PacketBB : public Header +class PbbPacket : public Header { public: - typedef std::list< Ptr >::iterator TlvIterator; - typedef std::list< Ptr >::const_iterator ConstTlvIterator; - typedef std::list< Ptr >::iterator MessageIterator; - typedef std::list< Ptr >::const_iterator ConstMessageIterator; + typedef std::list< Ptr >::iterator TlvIterator; + typedef std::list< Ptr >::const_iterator ConstTlvIterator; + typedef std::list< Ptr >::iterator MessageIterator; + typedef std::list< Ptr >::const_iterator ConstMessageIterator; - PacketBB (void); + PbbPacket (void); uint8_t GetVersion (void) const; @@ -181,14 +179,14 @@ public: int TlvSize (void) const; bool TlvEmpty (void) const; - Ptr TlvFront (void); - const Ptr TlvFront (void) const; - Ptr TlvBack (void); - const Ptr TlvBack (void) const; + Ptr TlvFront (void); + const Ptr TlvFront (void) const; + Ptr TlvBack (void); + const Ptr TlvBack (void) const; - void TlvPushFront (Ptr); + void TlvPushFront (Ptr); void TlvPopFront (void); - void TlvPushBack (Ptr); + void TlvPushBack (Ptr); void TlvPopBack (void); TlvIterator Erase (TlvIterator position); @@ -205,14 +203,14 @@ public: int MessageSize (void) const; bool MessageEmpty (void) const; - Ptr MessageFront (void); - const Ptr MessageFront (void) const; - Ptr MessageBack (void); - const Ptr MessageBack (void) const; + Ptr MessageFront (void); + const Ptr MessageFront (void) const; + Ptr MessageBack (void); + const Ptr MessageBack (void) const; - void MessagePushFront (Ptr message); + void MessagePushFront (Ptr message); void MessagePopFront (void); - void MessagePushBack (Ptr message); + void MessagePushBack (Ptr message); void MessagePopBack (void); MessageIterator Erase (MessageIterator position); @@ -237,15 +235,15 @@ public: virtual uint32_t Deserialize (Buffer::Iterator start); virtual void Print (std::ostream &os) const; - bool operator== (const PacketBB &other) const; - bool operator!= (const PacketBB &other) const; + bool operator== (const PbbPacket &other) const; + bool operator!= (const PbbPacket &other) const; protected: void SerializePacketTlv (Buffer::Iterator &start) const; private: - TlvBlock m_tlvList; - std::list< Ptr > m_messageList; + PbbTlvBlock m_tlvList; + std::list< Ptr > m_messageList; uint8_t m_version; @@ -256,21 +254,21 @@ private: }; /** - * \brief A message within a PacketBB packet. + * \brief A message within a PbbPacket packet. * - * There may be any number of messages in one PacketBB packet. - * This is a pure virutal base class, you should instantiate either MessageIpv4 - * or MessageIpv6. + * There may be any number of messages in one PbbPacket packet. + * This is a pure virutal base class, you should instantiate either PbbMessageIpv4 + * or PbbMessageIpv6. */ -class Message +class PbbMessage { public: - typedef std::list< Ptr >::iterator TlvIterator; - typedef std::list< Ptr >::const_iterator ConstTlvIterator; - typedef std::list< Ptr >::iterator AddressBlockIterator; - typedef std::list< Ptr >::const_iterator ConstAddressBlockIterator; + typedef std::list< Ptr >::iterator TlvIterator; + typedef std::list< Ptr >::const_iterator ConstTlvIterator; + typedef std::list< Ptr >::iterator AddressBlockIterator; + typedef std::list< Ptr >::const_iterator ConstAddressBlockIterator; - Message (void); + PbbMessage (void); void SetType (uint8_t type); uint8_t GetType (void) const; @@ -315,7 +313,7 @@ public: uint16_t GetSequenceNumber (void) const; bool HasSequenceNumber (void) const; - /* Manipulating Message TLVs */ + /* Manipulating PbbMessage TLVs */ TlvIterator TlvBegin (); ConstTlvIterator TlvBegin () const; @@ -325,14 +323,14 @@ public: int TlvSize (void) const; bool TlvEmpty (void) const; - Ptr TlvFront (void); - const Ptr TlvFront (void) const; - Ptr TlvBack (void); - const Ptr TlvBack (void) const; + Ptr TlvFront (void); + const Ptr TlvFront (void) const; + Ptr TlvBack (void); + const Ptr TlvBack (void) const; - void TlvPushFront (Ptr tlv); + void TlvPushFront (Ptr tlv); void TlvPopFront (void); - void TlvPushBack (Ptr tlv); + void TlvPushBack (Ptr tlv); void TlvPopBack (void); TlvIterator TlvErase (TlvIterator position); @@ -349,14 +347,14 @@ public: int AddressBlockSize (void) const; bool AddressBlockEmpty (void) const; - Ptr AddressBlockFront (void); - const Ptr AddressBlockFront (void) const; - Ptr AddressBlockBack (void); - const Ptr AddressBlockBack (void) const; + Ptr AddressBlockFront (void); + const Ptr AddressBlockFront (void) const; + Ptr AddressBlockBack (void); + const Ptr AddressBlockBack (void) const; - void AddressBlockPushFront (Ptr block); + void AddressBlockPushFront (Ptr block); void AddressBlockPopFront (void); - void AddressBlockPushBack (Ptr block); + void AddressBlockPushBack (Ptr block); void AddressBlockPopBack (void); AddressBlockIterator AddressBlockErase (AddressBlockIterator position); @@ -369,18 +367,18 @@ public: void Unref (void) const; /* Returns 0 on error */ - static Ptr DeserializeMessage (Buffer::Iterator &start); + static Ptr DeserializeMessage (Buffer::Iterator &start); uint32_t GetSerializedSize (void) const; void Serialize (Buffer::Iterator &start) const; void Deserialize (Buffer::Iterator &start); void Print (std::ostream &os) const; void Print (std::ostream &os, int level) const; - bool operator== (const Message &other) const; - bool operator!= (const Message &other) const; + bool operator== (const PbbMessage &other) const; + bool operator!= (const PbbMessage &other) const; protected: - /* Message size in bytes - 1. + /* PbbMessage size in bytes - 1. * * IPv4 = 4 - 1 = 3, IPv6 = 16 - 1 = 15 */ @@ -390,11 +388,11 @@ protected: virtual Address DeserializeOriginatorAddress (Buffer::Iterator &start) const = 0; virtual void PrintOriginatorAddress (std::ostream &os) const = 0; - virtual Ptr AddressBlockDeserialize (Buffer::Iterator &start) const = 0; + virtual Ptr AddressBlockDeserialize (Buffer::Iterator &start) const = 0; private: - TlvBlock m_tlvList; - std::list< Ptr > m_addressBlockList; + PbbTlvBlock m_tlvList; + std::list< Ptr > m_addressBlockList; uint8_t m_type; AddressLength m_addrSize; @@ -415,11 +413,11 @@ private: }; /** - * \brief Concrete IPv4 specific Message. + * \brief Concrete IPv4 specific PbbMessage. * * This message will only contain IPv4 addresses. */ -class MessageIpv4 : public Message { +class PbbMessageIpv4 : public PbbMessage { protected: virtual AddressLength GetAddressLength (void) const; @@ -427,15 +425,15 @@ protected: virtual Address DeserializeOriginatorAddress (Buffer::Iterator &start) const; virtual void PrintOriginatorAddress (std::ostream &os) const; - virtual Ptr AddressBlockDeserialize (Buffer::Iterator &start) const; + virtual Ptr AddressBlockDeserialize (Buffer::Iterator &start) const; }; /** - * \brief Concrete IPv6 specific Message class. + * \brief Concrete IPv6 specific PbbMessage class. * * This message will only contain IPv6 addresses. */ -class MessageIpv6 : public Message { +class PbbMessageIpv6 : public PbbMessage { protected: virtual AddressLength GetAddressLength (void) const; @@ -443,16 +441,16 @@ protected: virtual Address DeserializeOriginatorAddress (Buffer::Iterator &start) const; virtual void PrintOriginatorAddress (std::ostream &os) const; - virtual Ptr AddressBlockDeserialize (Buffer::Iterator &start) const; + virtual Ptr AddressBlockDeserialize (Buffer::Iterator &start) const; }; /** * \brief An Address Block and its associated Address TLV Blocks. * * This is a pure virtual base class, you should instantiate either - * AddressBlockIpv4 or AddressBlockIpv6. + * PbbAddressBlockIpv4 or PbbAddressBlockIpv6. */ -class AddressBlock +class PbbAddressBlock { public: typedef std::list< Address >::iterator AddressIterator; @@ -461,10 +459,10 @@ public: typedef std::list::iterator PrefixIterator; typedef std::list::const_iterator ConstPrefixIterator; - typedef AddressTlvBlock::Iterator TlvIterator; - typedef AddressTlvBlock::ConstIterator ConstTlvIterator; + typedef PbbAddressTlvBlock::Iterator TlvIterator; + typedef PbbAddressTlvBlock::ConstIterator ConstTlvIterator; - AddressBlock (); + PbbAddressBlock (); /* Manipulating the address block */ @@ -527,18 +525,18 @@ public: int TlvSize (void) const; bool TlvEmpty (void) const; - Ptr TlvFront (void); - const Ptr TlvFront (void) const; - Ptr TlvBack (void); - const Ptr TlvBack (void) const; + Ptr TlvFront (void); + const Ptr TlvFront (void) const; + Ptr TlvBack (void); + const Ptr TlvBack (void) const; - void TlvPushFront (Ptr address); + void TlvPushFront (Ptr address); void TlvPopFront (void); - void TlvPushBack (Ptr address); + void TlvPushBack (Ptr address); void TlvPopBack (void); - TlvIterator TlvInsert (TlvIterator position, const Ptr value); + TlvIterator TlvInsert (TlvIterator position, const Ptr value); TlvIterator TlvErase (TlvIterator position); TlvIterator TlvErase (TlvIterator first, TlvIterator last); @@ -555,8 +553,8 @@ public: void Print (std::ostream &os) const; void Print (std::ostream &os, int level) const; - bool operator== (const AddressBlock &other) const; - bool operator!= (const AddressBlock &other) const; + bool operator== (const PbbAddressBlock &other) const; + bool operator!= (const PbbAddressBlock &other) const; protected: virtual uint8_t GetAddressLength (void) const = 0; @@ -573,17 +571,17 @@ private: std::list
m_addressList; std::list m_prefixList; - AddressTlvBlock m_addressTlvList; + PbbAddressTlvBlock m_addressTlvList; mutable uint32_t m_refCount; }; /** - * \brief Concrete IPv4 specific AddressBlock. + * \brief Concrete IPv4 specific PbbAddressBlock. * * This address block will only contain IPv4 addresses. */ -class AddressBlockIpv4 : public AddressBlock +class PbbAddressBlockIpv4 : public PbbAddressBlock { protected: virtual uint8_t GetAddressLength (void) const; @@ -594,11 +592,11 @@ protected: }; /** - * \brief Concrete IPv6 specific AddressBlock. + * \brief Concrete IPv6 specific PbbAddressBlock. * * This address block will only contain IPv6 addresses. */ -class AddressBlockIpv6 : public AddressBlock +class PbbAddressBlockIpv6 : public PbbAddressBlock { protected: virtual uint8_t GetAddressLength (void) const; @@ -611,10 +609,10 @@ protected: /** * \brief A packet or message TLV */ -class Tlv +class PbbTlv { public: - Tlv (void); + PbbTlv (void); void SetType (uint8_t type); uint8_t GetType (void) const; @@ -650,8 +648,8 @@ public: void Print (std::ostream &os) const; void Print (std::ostream &os, int level) const; - bool operator== (const Tlv &other) const; - bool operator!= (const Tlv &other) const; + bool operator== (const PbbTlv &other) const; + bool operator!= (const PbbTlv &other) const; protected: void SetIndexStart (uint8_t index); @@ -687,13 +685,13 @@ private: /** * \brief An Address TLV */ -class AddressTlv : public Tlv +class PbbAddressTlv : public PbbTlv { public: void SetIndexStart (uint8_t index); /** * \returns the first (inclusive) index of the address in the corresponding - * AddressBlock that this TLV applies to. + * PbbAddressBlock that this TLV applies to. * * Calling this while HasIndexStart is False is undefined. Make sure you * check it first. This will be checked by an assert in debug builds. @@ -704,7 +702,7 @@ public: void SetIndexStop (uint8_t index); /** * \returns the last (inclusive) index of the address in the corresponding - * AddressBlock that this TLV applies to. + * PbbAddressBlock that this TLV applies to. * * Calling this while HasIndexStop is False is undefined. Make sure you * check it first. This will be checked by an assert in debug builds. @@ -716,8 +714,6 @@ public: bool IsMultivalue (void) const; }; -} /* namespace pbb */ - } /* namespace ns3 */ #endif /* PACKETBB_H */ diff --git a/src/contrib/test-packetbb.cc b/src/contrib/test-packetbb.cc index 5c3f79539..28f9fa1d5 100644 --- a/src/contrib/test-packetbb.cc +++ b/src/contrib/test-packetbb.cc @@ -18,7 +18,6 @@ * * Author: Tom Wambold */ -/** TODO: Find out why msg-addr-length is set to 0 in tests */ #include @@ -29,12 +28,12 @@ using namespace std; using namespace ns3; -using namespace ns3::pbb; class PacketBBTester { public: - PacketBBTester (int testnum, PacketBB &reference, const uint8_t * buffer, uint32_t size) : + PacketBBTester (int testnum, PbbPacket &reference, const uint8_t * buffer, + uint32_t size) : m_refPacket(reference) { m_refBuffer.AddAtStart (size); @@ -77,7 +76,7 @@ public: bool TestDeserialize (void) { - PacketBB newPacket; + PbbPacket newPacket; if (newPacket.Deserialize (m_refBuffer.Begin ()) != m_refBuffer.GetSize ()) { return false; @@ -114,7 +113,7 @@ private: } Buffer m_refBuffer; - PacketBB &m_refPacket; + PbbPacket &m_refPacket; }; int main (void) @@ -133,7 +132,7 @@ int main (void) * `------------------ */ { - PacketBB packet; + PbbPacket packet; uint8_t buffer[] = {0x00}; PacketBBTester test(testnum++, packet, buffer, sizeof(buffer)); } @@ -148,7 +147,7 @@ int main (void) * `------------------ */ { - PacketBB packet; + PbbPacket packet; packet.SetSequenceNumber (2); uint8_t buffer[] = {0x08, 0x00, 0x02}; PacketBBTester test(testnum++, packet, buffer, sizeof(buffer)); @@ -165,7 +164,7 @@ int main (void) * This test has the phastlv flag set to 1 with no tlvs. * I'll come back to this one later. { - PacketBB packet; + PbbPacket packet; packet.SetSequenceNumber (3); uint8_t buffer[] = {0x0c, 0x00, 0x03, 0x00, 0x00}; PacketBBTester test(testnum++, packet, buffer, sizeof(buffer)); @@ -187,10 +186,10 @@ int main (void) * `------------------ */ { - PacketBB packet; + PbbPacket packet; packet.SetSequenceNumber (4); - Ptr tlv = Create(); + Ptr tlv = Create(); tlv->SetType (1); packet.TlvPushBack (tlv); @@ -218,14 +217,14 @@ int main (void) * `------------------ */ { - PacketBB packet; + PbbPacket packet; packet.SetSequenceNumber (5); - Ptr tlv1 = Create(); + Ptr tlv1 = Create(); tlv1->SetType (1); packet.TlvPushBack (tlv1); - Ptr tlv2 = Create(); + Ptr tlv2 = Create(); tlv2->SetType (2); tlv2->SetTypeExt (100); packet.TlvPushBack (tlv2); @@ -256,14 +255,14 @@ int main (void) * `------------------ */ { - PacketBB packet; + PbbPacket packet; packet.SetSequenceNumber (6); - Ptr tlv1 = Create(); + Ptr tlv1 = Create(); tlv1->SetType (1); packet.TlvPushBack (tlv1); - Ptr tlv2 = Create(); + Ptr tlv2 = Create(); tlv2->SetType (2); tlv2->SetTypeExt (100); @@ -295,92 +294,92 @@ int main (void) * | | - TLV * | | Flags = 152 * | | Type = 2; Type ext. = 100; Value = 00 01 02 03 - * | | 04 05 06 07 - * | | 08 09 0a 0b - * | | 0c 0d 0e 0f - * | | 10 11 12 13 - * | | 14 15 16 17 - * | | 18 19 1a 1b - * | | 1c 1d 1e 1f - * | | 20 21 22 23 - * | | 24 25 26 27 - * | | 28 29 2a 2b - * | | 2c 2d 2e 2f - * | | 30 31 32 33 - * | | 34 35 36 37 - * | | 38 39 3a 3b - * | | 3c 3d 3e 3f - * | | 40 41 42 43 - * | | 44 45 46 47 - * | | 48 49 4a 4b - * | | 4c 4d 4e 4f - * | | 50 51 52 53 - * | | 54 55 56 57 - * | | 58 59 5a 5b - * | | 5c 5d 5e 5f - * | | 60 61 62 63 - * | | 64 65 66 67 - * | | 68 69 6a 6b - * | | 6c 6d 6e 6f - * | | 70 71 72 73 - * | | 74 75 76 77 - * | | 78 79 7a 7b - * | | 7c 7d 7e 7f - * | | 80 81 82 83 - * | | 84 85 86 87 - * | | 88 89 8a 8b - * | | 8c 8d 8e 8f - * | | 90 91 92 93 - * | | 94 95 96 97 - * | | 98 99 9a 9b - * | | 9c 9d 9e 9f - * | | a0 a1 a2 a3 - * | | a4 a5 a6 a7 - * | | a8 a9 aa ab - * | | ac ad ae af - * | | b0 b1 b2 b3 - * | | b4 b5 b6 b7 - * | | b8 b9 ba bb - * | | bc bd be bf - * | | c0 c1 c2 c3 - * | | c4 c5 c6 c7 - * | | c8 c9 ca cb - * | | cc cd ce cf - * | | d0 d1 d2 d3 - * | | d4 d5 d6 d7 - * | | d8 d9 da db - * | | dc dd de df - * | | e0 e1 e2 e3 - * | | e4 e5 e6 e7 - * | | e8 e9 ea eb - * | | ec ed ee ef - * | | f0 f1 f2 f3 - * | | f4 f5 f6 f7 - * | | f8 f9 fa fb - * | | fc fd fe 00 - * | | 01 02 03 04 - * | | 05 06 07 08 - * | | 09 0a 0b 0c - * | | 0d 0e 0f 10 - * | | 11 12 13 14 - * | | 15 16 17 18 - * | | 19 1a 1b 1c - * | | 1d 1e 1f 20 - * | | 21 22 23 24 - * | | 25 26 27 28 - * | | 29 2a 2b 2c + * | | 04 05 06 07 + * | | 08 09 0a 0b + * | | 0c 0d 0e 0f + * | | 10 11 12 13 + * | | 14 15 16 17 + * | | 18 19 1a 1b + * | | 1c 1d 1e 1f + * | | 20 21 22 23 + * | | 24 25 26 27 + * | | 28 29 2a 2b + * | | 2c 2d 2e 2f + * | | 30 31 32 33 + * | | 34 35 36 37 + * | | 38 39 3a 3b + * | | 3c 3d 3e 3f + * | | 40 41 42 43 + * | | 44 45 46 47 + * | | 48 49 4a 4b + * | | 4c 4d 4e 4f + * | | 50 51 52 53 + * | | 54 55 56 57 + * | | 58 59 5a 5b + * | | 5c 5d 5e 5f + * | | 60 61 62 63 + * | | 64 65 66 67 + * | | 68 69 6a 6b + * | | 6c 6d 6e 6f + * | | 70 71 72 73 + * | | 74 75 76 77 + * | | 78 79 7a 7b + * | | 7c 7d 7e 7f + * | | 80 81 82 83 + * | | 84 85 86 87 + * | | 88 89 8a 8b + * | | 8c 8d 8e 8f + * | | 90 91 92 93 + * | | 94 95 96 97 + * | | 98 99 9a 9b + * | | 9c 9d 9e 9f + * | | a0 a1 a2 a3 + * | | a4 a5 a6 a7 + * | | a8 a9 aa ab + * | | ac ad ae af + * | | b0 b1 b2 b3 + * | | b4 b5 b6 b7 + * | | b8 b9 ba bb + * | | bc bd be bf + * | | c0 c1 c2 c3 + * | | c4 c5 c6 c7 + * | | c8 c9 ca cb + * | | cc cd ce cf + * | | d0 d1 d2 d3 + * | | d4 d5 d6 d7 + * | | d8 d9 da db + * | | dc dd de df + * | | e0 e1 e2 e3 + * | | e4 e5 e6 e7 + * | | e8 e9 ea eb + * | | ec ed ee ef + * | | f0 f1 f2 f3 + * | | f4 f5 f6 f7 + * | | f8 f9 fa fb + * | | fc fd fe 00 + * | | 01 02 03 04 + * | | 05 06 07 08 + * | | 09 0a 0b 0c + * | | 0d 0e 0f 10 + * | | 11 12 13 14 + * | | 15 16 17 18 + * | | 19 1a 1b 1c + * | | 1d 1e 1f 20 + * | | 21 22 23 24 + * | | 25 26 27 28 + * | | 29 2a 2b 2c * | | * `------------------ */ { - PacketBB packet; + PbbPacket packet; packet.SetSequenceNumber (7); - Ptr tlv1 = Create(); + Ptr tlv1 = Create(); tlv1->SetType (1); packet.TlvPushBack (tlv1); - Ptr tlv2 = Create(); + Ptr tlv2 = Create(); tlv2->SetType (2); tlv2->SetTypeExt (100); @@ -569,14 +568,14 @@ int main (void) * `------------------ */ { - PacketBB packet; + PbbPacket packet; packet.SetSequenceNumber (8); - Ptr tlv1 = Create (); + Ptr tlv1 = Create (); tlv1->SetType (1); packet.TlvPushBack (tlv1); - Ptr msg1 = Create (); + Ptr msg1 = Create (); msg1->SetType (1); packet.MessagePushBack (msg1); @@ -618,18 +617,18 @@ int main (void) * `------------------ */ { - PacketBB packet; + PbbPacket packet; packet.SetSequenceNumber (9); - Ptr tlv1 = Create (); + Ptr tlv1 = Create (); tlv1->SetType (1); packet.TlvPushBack (tlv1); - Ptr msg1 = Create (); + Ptr msg1 = Create (); msg1->SetType (1); packet.MessagePushBack (msg1); - Ptr msg2 = Create (); + Ptr msg2 = Create (); msg2->SetType (2); msg2->SetOriginatorAddress(Ipv4Address("10.0.0.1")); packet.MessagePushBack (msg2); @@ -675,18 +674,18 @@ int main (void) * `------------------ */ { - PacketBB packet; + PbbPacket packet; packet.SetSequenceNumber (10); - Ptr tlv1 = Create (); + Ptr tlv1 = Create (); tlv1->SetType (1); packet.TlvPushBack (tlv1); - Ptr msg1 = Create (); + Ptr msg1 = Create (); msg1->SetType (1); packet.MessagePushBack (msg1); - Ptr msg2 = Create (); + Ptr msg2 = Create (); msg2->SetType (2); msg2->SetOriginatorAddress(Ipv4Address("10.0.0.1")); msg2->SetHopCount (1); @@ -734,18 +733,18 @@ int main (void) * `------------------ */ { - PacketBB packet; + PbbPacket packet; packet.SetSequenceNumber (11); - Ptr tlv1 = Create (); + Ptr tlv1 = Create (); tlv1->SetType (1); packet.TlvPushBack (tlv1); - Ptr msg1 = Create (); + Ptr msg1 = Create (); msg1->SetType (1); packet.MessagePushBack (msg1); - Ptr msg2 = Create (); + Ptr msg2 = Create (); msg2->SetType (2); msg2->SetOriginatorAddress(Ipv4Address("10.0.0.1")); msg2->SetHopLimit (255); @@ -796,18 +795,18 @@ int main (void) * `------------------ */ { - PacketBB packet; + PbbPacket packet; packet.SetSequenceNumber (12); - Ptr tlv1 = Create (); + Ptr tlv1 = Create (); tlv1->SetType (1); packet.TlvPushBack (tlv1); - Ptr msg1 = Create (); + Ptr msg1 = Create (); msg1->SetType (1); packet.MessagePushBack (msg1); - Ptr msg2 = Create (); + Ptr msg2 = Create (); msg2->SetType (2); msg2->SetOriginatorAddress(Ipv4Address("10.0.0.1")); msg2->SetHopLimit (255); @@ -859,18 +858,18 @@ int main (void) * `------------------ */ { - PacketBB packet; + PbbPacket packet; packet.SetSequenceNumber (13); - Ptr tlv1 = Create (); + Ptr tlv1 = Create (); tlv1->SetType (1); packet.TlvPushBack (tlv1); - Ptr msg1 = Create (); + Ptr msg1 = Create (); msg1->SetType (1); packet.MessagePushBack (msg1); - Ptr msg2 = Create (); + Ptr msg2 = Create (); msg2->SetType (2); msg2->SetOriginatorAddress(Ipv4Address("10.0.0.1")); msg2->SetHopLimit (255); @@ -926,23 +925,23 @@ int main (void) * `------------------ */ { - PacketBB packet; + PbbPacket packet; packet.SetSequenceNumber (14); - Ptr tlv1 = Create (); + Ptr tlv1 = Create (); tlv1->SetType (1); packet.TlvPushBack (tlv1); - Ptr msg1 = Create (); + Ptr msg1 = Create (); msg1->SetType (1); - Ptr msg1tlv1 = Create (); + Ptr msg1tlv1 = Create (); msg1tlv1->SetType (1); msg1->TlvPushBack (msg1tlv1); packet.MessagePushBack (msg1); - Ptr msg2 = Create (); + Ptr msg2 = Create (); msg2->SetType (2); msg2->SetOriginatorAddress(Ipv4Address("10.0.0.1")); msg2->SetHopLimit (255); @@ -1003,30 +1002,30 @@ int main (void) * `------------------ */ { - PacketBB packet; + PbbPacket packet; packet.SetSequenceNumber (15); - Ptr tlv1 = Create (); + Ptr tlv1 = Create (); tlv1->SetType (1); packet.TlvPushBack (tlv1); - Ptr msg1 = Create (); + Ptr msg1 = Create (); msg1->SetType (1); - Ptr msg1tlv1 = Create (); + Ptr msg1tlv1 = Create (); msg1tlv1->SetType (1); msg1->TlvPushBack (msg1tlv1); packet.MessagePushBack (msg1); - Ptr msg2 = Create (); + Ptr msg2 = Create (); msg2->SetType (2); msg2->SetOriginatorAddress (Ipv4Address ("10.0.0.1")); msg2->SetHopLimit (255); msg2->SetHopCount (1); msg2->SetSequenceNumber (12345); - Ptr msg2a1 = Create (); + Ptr msg2a1 = Create (); msg2a1->AddressPushBack (Ipv4Address ("0.0.0.0")); msg2->AddressBlockPushBack (msg2a1); @@ -1087,30 +1086,30 @@ int main (void) * `------------------ */ { - PacketBB packet; + PbbPacket packet; packet.SetSequenceNumber (16); - Ptr tlv1 = Create (); + Ptr tlv1 = Create (); tlv1->SetType (1); packet.TlvPushBack (tlv1); - Ptr msg1 = Create (); + Ptr msg1 = Create (); msg1->SetType (1); - Ptr msg1tlv1 = Create (); + Ptr msg1tlv1 = Create (); msg1tlv1->SetType (1); msg1->TlvPushBack (msg1tlv1); packet.MessagePushBack (msg1); - Ptr msg2 = Create (); + Ptr msg2 = Create (); msg2->SetType (2); msg2->SetOriginatorAddress (Ipv4Address ("10.0.0.1")); msg2->SetHopLimit (255); msg2->SetHopCount (1); msg2->SetSequenceNumber (12345); - Ptr msg2a1 = Create (); + Ptr msg2a1 = Create (); msg2a1->AddressPushBack (Ipv4Address ("255.255.255.255")); msg2->AddressBlockPushBack (msg2a1); @@ -1171,30 +1170,30 @@ int main (void) * `------------------ */ { - PacketBB packet; + PbbPacket packet; packet.SetSequenceNumber (17); - Ptr tlv1 = Create (); + Ptr tlv1 = Create (); tlv1->SetType (1); packet.TlvPushBack (tlv1); - Ptr msg1 = Create (); + Ptr msg1 = Create (); msg1->SetType (1); - Ptr msg1tlv1 = Create (); + Ptr msg1tlv1 = Create (); msg1tlv1->SetType (1); msg1->TlvPushBack (msg1tlv1); packet.MessagePushBack (msg1); - Ptr msg2 = Create (); + Ptr msg2 = Create (); msg2->SetType (2); msg2->SetOriginatorAddress (Ipv4Address ("10.0.0.1")); msg2->SetHopLimit (255); msg2->SetHopCount (1); msg2->SetSequenceNumber (12345); - Ptr msg2a1 = Create (); + Ptr msg2a1 = Create (); msg2a1->AddressPushBack (Ipv4Address ("0.0.0.1")); msg2->AddressBlockPushBack (msg2a1); @@ -1255,30 +1254,30 @@ int main (void) * `------------------ */ { - PacketBB packet; + PbbPacket packet; packet.SetSequenceNumber (18); - Ptr tlv1 = Create (); + Ptr tlv1 = Create (); tlv1->SetType (1); packet.TlvPushBack (tlv1); - Ptr msg1 = Create (); + Ptr msg1 = Create (); msg1->SetType (1); - Ptr msg1tlv1 = Create (); + Ptr msg1tlv1 = Create (); msg1tlv1->SetType (1); msg1->TlvPushBack (msg1tlv1); packet.MessagePushBack (msg1); - Ptr msg2 = Create (); + Ptr msg2 = Create (); msg2->SetType (2); msg2->SetOriginatorAddress (Ipv4Address ("10.0.0.1")); msg2->SetHopLimit (255); msg2->SetHopCount (1); msg2->SetSequenceNumber (12345); - Ptr msg2a1 = Create (); + Ptr msg2a1 = Create (); msg2a1->AddressPushBack (Ipv4Address ("10.0.0.0")); msg2->AddressBlockPushBack (msg2a1); @@ -1339,30 +1338,30 @@ int main (void) * `------------------ */ { - PacketBB packet; + PbbPacket packet; packet.SetSequenceNumber (19); - Ptr tlv1 = Create (); + Ptr tlv1 = Create (); tlv1->SetType (1); packet.TlvPushBack (tlv1); - Ptr msg1 = Create (); + Ptr msg1 = Create (); msg1->SetType (1); - Ptr msg1tlv1 = Create (); + Ptr msg1tlv1 = Create (); msg1tlv1->SetType (1); msg1->TlvPushBack (msg1tlv1); packet.MessagePushBack (msg1); - Ptr msg2 = Create (); + Ptr msg2 = Create (); msg2->SetType (2); msg2->SetOriginatorAddress (Ipv4Address ("10.0.0.1")); msg2->SetHopLimit (255); msg2->SetHopCount (1); msg2->SetSequenceNumber (12345); - Ptr msg2a1 = Create (); + Ptr msg2a1 = Create (); msg2a1->AddressPushBack (Ipv4Address ("10.0.0.1")); msg2->AddressBlockPushBack (msg2a1); @@ -1424,30 +1423,30 @@ int main (void) * `------------------ */ { - PacketBB packet; + PbbPacket packet; packet.SetSequenceNumber (20); - Ptr tlv1 = Create (); + Ptr tlv1 = Create (); tlv1->SetType (1); packet.TlvPushBack (tlv1); - Ptr msg1 = Create (); + Ptr msg1 = Create (); msg1->SetType (1); - Ptr msg1tlv1 = Create (); + Ptr msg1tlv1 = Create (); msg1tlv1->SetType (1); msg1->TlvPushBack (msg1tlv1); packet.MessagePushBack (msg1); - Ptr msg2 = Create (); + Ptr msg2 = Create (); msg2->SetType (2); msg2->SetOriginatorAddress (Ipv4Address ("10.0.0.1")); msg2->SetHopLimit (255); msg2->SetHopCount (1); msg2->SetSequenceNumber (12345); - Ptr msg2a1 = Create (); + Ptr msg2a1 = Create (); msg2a1->AddressPushBack (Ipv4Address ("10.0.0.1")); msg2a1->AddressPushBack (Ipv4Address ("10.0.0.2")); msg2->AddressBlockPushBack (msg2a1); @@ -1510,30 +1509,30 @@ int main (void) * `------------------ */ { - PacketBB packet; + PbbPacket packet; packet.SetSequenceNumber (21); - Ptr tlv1 = Create (); + Ptr tlv1 = Create (); tlv1->SetType (1); packet.TlvPushBack (tlv1); - Ptr msg1 = Create (); + Ptr msg1 = Create (); msg1->SetType (1); - Ptr msg1tlv1 = Create (); + Ptr msg1tlv1 = Create (); msg1tlv1->SetType (1); msg1->TlvPushBack (msg1tlv1); packet.MessagePushBack (msg1); - Ptr msg2 = Create (); + Ptr msg2 = Create (); msg2->SetType (2); msg2->SetOriginatorAddress (Ipv4Address ("10.0.0.1")); msg2->SetHopLimit (255); msg2->SetHopCount (1); msg2->SetSequenceNumber (12345); - Ptr msg2a1 = Create (); + Ptr msg2a1 = Create (); msg2a1->AddressPushBack (Ipv4Address ("10.0.0.2")); msg2a1->AddressPushBack (Ipv4Address ("10.1.1.2")); msg2->AddressBlockPushBack (msg2a1); @@ -1602,35 +1601,35 @@ int main (void) * `------------------ */ { - PacketBB packet; + PbbPacket packet; packet.SetSequenceNumber (22); - Ptr tlv1 = Create (); + Ptr tlv1 = Create (); tlv1->SetType (1); packet.TlvPushBack (tlv1); - Ptr msg1 = Create (); + Ptr msg1 = Create (); msg1->SetType (1); - Ptr msg1tlv1 = Create (); + Ptr msg1tlv1 = Create (); msg1tlv1->SetType (1); msg1->TlvPushBack (msg1tlv1); packet.MessagePushBack (msg1); - Ptr msg2 = Create (); + Ptr msg2 = Create (); msg2->SetType (2); msg2->SetOriginatorAddress (Ipv4Address ("10.0.0.1")); msg2->SetHopLimit (255); msg2->SetHopCount (1); msg2->SetSequenceNumber (12345); - Ptr msg2a1 = Create (); + Ptr msg2a1 = Create (); msg2a1->AddressPushBack (Ipv4Address ("10.0.0.2")); msg2a1->AddressPushBack (Ipv4Address ("10.1.1.2")); msg2->AddressBlockPushBack (msg2a1); - Ptr msg2a2 = Create (); + Ptr msg2a2 = Create (); msg2a2->AddressPushBack (Ipv4Address ("10.0.0.0")); msg2a2->AddressPushBack (Ipv4Address ("11.0.0.0")); msg2->AddressBlockPushBack (msg2a2); @@ -1702,35 +1701,35 @@ int main (void) * `------------------ */ { - PacketBB packet; + PbbPacket packet; packet.SetSequenceNumber (23); - Ptr tlv1 = Create (); + Ptr tlv1 = Create (); tlv1->SetType (1); packet.TlvPushBack (tlv1); - Ptr msg1 = Create (); + Ptr msg1 = Create (); msg1->SetType (1); - Ptr msg1tlv1 = Create (); + Ptr msg1tlv1 = Create (); msg1tlv1->SetType (1); msg1->TlvPushBack (msg1tlv1); packet.MessagePushBack (msg1); - Ptr msg2 = Create (); + Ptr msg2 = Create (); msg2->SetType (2); msg2->SetOriginatorAddress (Ipv4Address ("10.0.0.1")); msg2->SetHopLimit (255); msg2->SetHopCount (1); msg2->SetSequenceNumber (12345); - Ptr msg2a1 = Create (); + Ptr msg2a1 = Create (); msg2a1->AddressPushBack (Ipv4Address ("10.0.0.2")); msg2a1->AddressPushBack (Ipv4Address ("10.1.1.2")); msg2->AddressBlockPushBack (msg2a1); - Ptr msg2a2 = Create (); + Ptr msg2a2 = Create (); msg2a2->AddressPushBack (Ipv4Address ("10.0.0.0")); msg2a2->AddressPushBack (Ipv4Address ("11.0.0.0")); msg2a2->AddressPushBack (Ipv4Address ("10.0.0.5")); @@ -1818,35 +1817,35 @@ int main (void) * `------------------ */ { - PacketBB packet; + PbbPacket packet; packet.SetSequenceNumber (24); - Ptr tlv1 = Create (); + Ptr tlv1 = Create (); tlv1->SetType (1); packet.TlvPushBack (tlv1); - Ptr msg1 = Create (); + Ptr msg1 = Create (); msg1->SetType (1); - Ptr msg1tlv1 = Create (); + Ptr msg1tlv1 = Create (); msg1tlv1->SetType (1); msg1->TlvPushBack (msg1tlv1); packet.MessagePushBack (msg1); - Ptr msg2 = Create (); + Ptr msg2 = Create (); msg2->SetType (2); msg2->SetOriginatorAddress (Ipv4Address ("10.0.0.1")); msg2->SetHopLimit (255); msg2->SetHopCount (1); msg2->SetSequenceNumber (12345); - Ptr msg2a1 = Create (); + Ptr msg2a1 = Create (); msg2a1->AddressPushBack (Ipv4Address ("10.0.0.2")); msg2a1->AddressPushBack (Ipv4Address ("10.1.1.2")); msg2->AddressBlockPushBack (msg2a1); - Ptr msg2a2 = Create (); + Ptr msg2a2 = Create (); msg2a2->AddressPushBack (Ipv4Address ("10.0.0.0")); msg2a2->AddressPushBack (Ipv4Address ("11.0.0.0")); msg2a2->AddressPushBack (Ipv4Address ("10.0.0.5")); @@ -1857,7 +1856,7 @@ int main (void) msg2a2->PrefixPushBack (16); msg2a2->PrefixPushBack (24); - Ptr msg2a2tlv1 = Create (); + Ptr msg2a2tlv1 = Create (); msg2a2tlv1->SetType (1); msg2a2->TlvPushBack (msg2a2tlv1); @@ -1939,35 +1938,35 @@ int main (void) * `------------------ */ { - PacketBB packet; + PbbPacket packet; packet.SetSequenceNumber (25); - Ptr tlv1 = Create (); + Ptr tlv1 = Create (); tlv1->SetType (1); packet.TlvPushBack (tlv1); - Ptr msg1 = Create (); + Ptr msg1 = Create (); msg1->SetType (1); - Ptr msg1tlv1 = Create (); + Ptr msg1tlv1 = Create (); msg1tlv1->SetType (1); msg1->TlvPushBack (msg1tlv1); packet.MessagePushBack (msg1); - Ptr msg2 = Create (); + Ptr msg2 = Create (); msg2->SetType (2); msg2->SetOriginatorAddress (Ipv4Address ("10.0.0.1")); msg2->SetHopLimit (255); msg2->SetHopCount (1); msg2->SetSequenceNumber (12345); - Ptr msg2a1 = Create (); + Ptr msg2a1 = Create (); msg2a1->AddressPushBack (Ipv4Address ("10.0.0.2")); msg2a1->AddressPushBack (Ipv4Address ("10.1.1.2")); msg2->AddressBlockPushBack (msg2a1); - Ptr msg2a2 = Create (); + Ptr msg2a2 = Create (); msg2a2->AddressPushBack (Ipv4Address ("10.0.0.0")); msg2a2->AddressPushBack (Ipv4Address ("11.0.0.0")); msg2a2->AddressPushBack (Ipv4Address ("10.0.0.5")); @@ -1978,7 +1977,7 @@ int main (void) msg2a2->PrefixPushBack (16); msg2a2->PrefixPushBack (24); - Ptr msg2a2tlv1 = Create (); + Ptr msg2a2tlv1 = Create (); msg2a2tlv1->SetType (1); msg2a2tlv1->SetIndexStart (1); msg2a2->TlvPushBack (msg2a2tlv1); @@ -2062,35 +2061,35 @@ int main (void) * `------------------ */ { - PacketBB packet; + PbbPacket packet; packet.SetSequenceNumber (26); - Ptr tlv1 = Create (); + Ptr tlv1 = Create (); tlv1->SetType (1); packet.TlvPushBack (tlv1); - Ptr msg1 = Create (); + Ptr msg1 = Create (); msg1->SetType (1); - Ptr msg1tlv1 = Create (); + Ptr msg1tlv1 = Create (); msg1tlv1->SetType (1); msg1->TlvPushBack (msg1tlv1); packet.MessagePushBack (msg1); - Ptr msg2 = Create (); + Ptr msg2 = Create (); msg2->SetType (2); msg2->SetOriginatorAddress (Ipv4Address ("10.0.0.1")); msg2->SetHopLimit (255); msg2->SetHopCount (1); msg2->SetSequenceNumber (12345); - Ptr msg2a1 = Create (); + Ptr msg2a1 = Create (); msg2a1->AddressPushBack (Ipv4Address ("10.0.0.2")); msg2a1->AddressPushBack (Ipv4Address ("10.1.1.2")); msg2->AddressBlockPushBack (msg2a1); - Ptr msg2a2 = Create (); + Ptr msg2a2 = Create (); msg2a2->AddressPushBack (Ipv4Address ("10.0.0.0")); msg2a2->AddressPushBack (Ipv4Address ("11.0.0.0")); msg2a2->AddressPushBack (Ipv4Address ("10.0.0.5")); @@ -2101,7 +2100,7 @@ int main (void) msg2a2->PrefixPushBack (16); msg2a2->PrefixPushBack (24); - Ptr msg2a2tlv1 = Create (); + Ptr msg2a2tlv1 = Create (); msg2a2tlv1->SetType (1); msg2a2tlv1->SetIndexStart (1); msg2a2tlv1->SetIndexStop (3); @@ -2187,35 +2186,35 @@ int main (void) * `------------------ */ { - PacketBB packet; + PbbPacket packet; packet.SetSequenceNumber (27); - Ptr tlv1 = Create (); + Ptr tlv1 = Create (); tlv1->SetType (1); packet.TlvPushBack (tlv1); - Ptr msg1 = Create (); + Ptr msg1 = Create (); msg1->SetType (1); - Ptr msg1tlv1 = Create (); + Ptr msg1tlv1 = Create (); msg1tlv1->SetType (1); msg1->TlvPushBack (msg1tlv1); packet.MessagePushBack (msg1); - Ptr msg2 = Create (); + Ptr msg2 = Create (); msg2->SetType (2); msg2->SetOriginatorAddress (Ipv4Address ("10.0.0.1")); msg2->SetHopLimit (255); msg2->SetHopCount (1); msg2->SetSequenceNumber (12345); - Ptr msg2a1 = Create (); + Ptr msg2a1 = Create (); msg2a1->AddressPushBack (Ipv4Address ("10.0.0.2")); msg2a1->AddressPushBack (Ipv4Address ("10.1.1.2")); msg2->AddressBlockPushBack (msg2a1); - Ptr msg2a2 = Create (); + Ptr msg2a2 = Create (); msg2a2->AddressPushBack (Ipv4Address ("10.0.0.0")); msg2a2->AddressPushBack (Ipv4Address ("11.0.0.0")); msg2a2->AddressPushBack (Ipv4Address ("10.0.0.5")); @@ -2226,7 +2225,7 @@ int main (void) msg2a2->PrefixPushBack (16); msg2a2->PrefixPushBack (24); - Ptr msg2a2tlv1 = Create (); + Ptr msg2a2tlv1 = Create (); msg2a2tlv1->SetType (1); msg2a2tlv1->SetIndexStart (1); msg2a2tlv1->SetIndexStop (3); @@ -2313,115 +2312,115 @@ int main (void) * | | Index-start = 1 * | | Index-stop = 3 * | | Type = 1; Value = 00 01 02 03 - * | | 04 05 06 07 - * | | 08 09 0a 0b - * | | 0c 0d 0e 0f - * | | 10 11 12 13 - * | | 14 15 16 17 - * | | 18 19 1a 1b - * | | 1c 1d 1e 1f - * | | 20 21 22 23 - * | | 24 25 26 27 - * | | 28 29 2a 2b - * | | 2c 2d 2e 2f - * | | 30 31 32 33 - * | | 34 35 36 37 - * | | 38 39 3a 3b - * | | 3c 3d 3e 3f - * | | 40 41 42 43 - * | | 44 45 46 47 - * | | 48 49 4a 4b - * | | 4c 4d 4e 4f - * | | 50 51 52 53 - * | | 54 55 56 57 - * | | 58 59 5a 5b - * | | 5c 5d 5e 5f - * | | 60 61 62 63 - * | | 64 65 66 67 - * | | 68 69 6a 6b - * | | 6c 6d 6e 6f - * | | 70 71 72 73 - * | | 74 75 76 77 - * | | 78 79 7a 7b - * | | 7c 7d 7e 7f - * | | 80 81 82 83 - * | | 84 85 86 87 - * | | 88 89 8a 8b - * | | 8c 8d 8e 8f - * | | 90 91 92 93 - * | | 94 95 96 97 - * | | 98 99 9a 9b - * | | 9c 9d 9e 9f - * | | a0 a1 a2 a3 - * | | a4 a5 a6 a7 - * | | a8 a9 aa ab - * | | ac ad ae af - * | | b0 b1 b2 b3 - * | | b4 b5 b6 b7 - * | | b8 b9 ba bb - * | | bc bd be bf - * | | c0 c1 c2 c3 - * | | c4 c5 c6 c7 - * | | c8 c9 ca cb - * | | cc cd ce cf - * | | d0 d1 d2 d3 - * | | d4 d5 d6 d7 - * | | d8 d9 da db - * | | dc dd de df - * | | e0 e1 e2 e3 - * | | e4 e5 e6 e7 - * | | e8 e9 ea eb - * | | ec ed ee ef - * | | f0 f1 f2 f3 - * | | f4 f5 f6 f7 - * | | f8 f9 fa fb - * | | fc fd fe 00 - * | | 01 02 03 04 - * | | 05 06 07 08 - * | | 09 0a 0b 0c - * | | 0d 0e 0f 10 - * | | 11 12 13 14 - * | | 15 16 17 18 - * | | 19 1a 1b 1c - * | | 1d 1e 1f 20 - * | | 21 22 23 24 - * | | 25 26 27 28 - * | | 29 2a 2b 2c + * | | 04 05 06 07 + * | | 08 09 0a 0b + * | | 0c 0d 0e 0f + * | | 10 11 12 13 + * | | 14 15 16 17 + * | | 18 19 1a 1b + * | | 1c 1d 1e 1f + * | | 20 21 22 23 + * | | 24 25 26 27 + * | | 28 29 2a 2b + * | | 2c 2d 2e 2f + * | | 30 31 32 33 + * | | 34 35 36 37 + * | | 38 39 3a 3b + * | | 3c 3d 3e 3f + * | | 40 41 42 43 + * | | 44 45 46 47 + * | | 48 49 4a 4b + * | | 4c 4d 4e 4f + * | | 50 51 52 53 + * | | 54 55 56 57 + * | | 58 59 5a 5b + * | | 5c 5d 5e 5f + * | | 60 61 62 63 + * | | 64 65 66 67 + * | | 68 69 6a 6b + * | | 6c 6d 6e 6f + * | | 70 71 72 73 + * | | 74 75 76 77 + * | | 78 79 7a 7b + * | | 7c 7d 7e 7f + * | | 80 81 82 83 + * | | 84 85 86 87 + * | | 88 89 8a 8b + * | | 8c 8d 8e 8f + * | | 90 91 92 93 + * | | 94 95 96 97 + * | | 98 99 9a 9b + * | | 9c 9d 9e 9f + * | | a0 a1 a2 a3 + * | | a4 a5 a6 a7 + * | | a8 a9 aa ab + * | | ac ad ae af + * | | b0 b1 b2 b3 + * | | b4 b5 b6 b7 + * | | b8 b9 ba bb + * | | bc bd be bf + * | | c0 c1 c2 c3 + * | | c4 c5 c6 c7 + * | | c8 c9 ca cb + * | | cc cd ce cf + * | | d0 d1 d2 d3 + * | | d4 d5 d6 d7 + * | | d8 d9 da db + * | | dc dd de df + * | | e0 e1 e2 e3 + * | | e4 e5 e6 e7 + * | | e8 e9 ea eb + * | | ec ed ee ef + * | | f0 f1 f2 f3 + * | | f4 f5 f6 f7 + * | | f8 f9 fa fb + * | | fc fd fe 00 + * | | 01 02 03 04 + * | | 05 06 07 08 + * | | 09 0a 0b 0c + * | | 0d 0e 0f 10 + * | | 11 12 13 14 + * | | 15 16 17 18 + * | | 19 1a 1b 1c + * | | 1d 1e 1f 20 + * | | 21 22 23 24 + * | | 25 26 27 28 + * | | 29 2a 2b 2c * | | * | `------------------- * | * `------------------ */ { - PacketBB packet; + PbbPacket packet; packet.SetSequenceNumber (28); - Ptr tlv1 = Create (); + Ptr tlv1 = Create (); tlv1->SetType (1); packet.TlvPushBack (tlv1); - Ptr msg1 = Create (); + Ptr msg1 = Create (); msg1->SetType (1); - Ptr msg1tlv1 = Create (); + Ptr msg1tlv1 = Create (); msg1tlv1->SetType (1); msg1->TlvPushBack (msg1tlv1); packet.MessagePushBack (msg1); - Ptr msg2 = Create (); + Ptr msg2 = Create (); msg2->SetType (2); msg2->SetOriginatorAddress (Ipv4Address ("10.0.0.1")); msg2->SetHopLimit (255); msg2->SetHopCount (1); msg2->SetSequenceNumber (12345); - Ptr msg2a1 = Create (); + Ptr msg2a1 = Create (); msg2a1->AddressPushBack (Ipv4Address ("10.0.0.2")); msg2a1->AddressPushBack (Ipv4Address ("10.1.1.2")); msg2->AddressBlockPushBack (msg2a1); - Ptr msg2a2 = Create (); + Ptr msg2a2 = Create (); msg2a2->AddressPushBack (Ipv4Address ("10.0.0.0")); msg2a2->AddressPushBack (Ipv4Address ("11.0.0.0")); msg2a2->AddressPushBack (Ipv4Address ("10.0.0.5")); @@ -2432,7 +2431,7 @@ int main (void) msg2a2->PrefixPushBack (16); msg2a2->PrefixPushBack (24); - Ptr msg2a2tlv1 = Create (); + Ptr msg2a2tlv1 = Create (); msg2a2tlv1->SetType (1); msg2a2tlv1->SetIndexStart (1); msg2a2tlv1->SetIndexStop (3); @@ -2636,9 +2635,9 @@ int main (void) * `------------------ */ { - PacketBB packet; + PbbPacket packet; - Ptr m1 = Create (); + Ptr m1 = Create (); m1->SetType(1); packet.MessagePushBack (m1); @@ -2667,9 +2666,9 @@ int main (void) * `------------------ */ { - PacketBB packet; + PbbPacket packet; - Ptr m1 = Create (); + Ptr m1 = Create (); m1->SetType(1); m1->SetOriginatorAddress (Ipv6Address("abcd::1")); @@ -2707,13 +2706,13 @@ int main (void) * `------------------ */ { - PacketBB packet; + PbbPacket packet; - Ptr m1 = Create (); + Ptr m1 = Create (); m1->SetType(1); m1->SetOriginatorAddress (Ipv6Address("abcd::1")); - Ptr m1a1 = Create (); + Ptr m1a1 = Create (); m1a1->AddressPushBack (Ipv6Address ("10::1")); m1->AddressBlockPushBack (m1a1); @@ -2757,13 +2756,13 @@ int main (void) * `------------------ */ { - PacketBB packet; + PbbPacket packet; - Ptr m1 = Create (); + Ptr m1 = Create (); m1->SetType(1); m1->SetOriginatorAddress (Ipv6Address("abcd::1")); - Ptr m1a1 = Create (); + Ptr m1a1 = Create (); m1a1->AddressPushBack (Ipv6Address ("10::1")); m1a1->AddressPushBack (Ipv6Address ("10::2")); m1->AddressBlockPushBack (m1a1); @@ -2809,13 +2808,13 @@ int main (void) * `------------------ */ { - PacketBB packet; + PbbPacket packet; - Ptr m1 = Create (); + Ptr m1 = Create (); m1->SetType(1); m1->SetOriginatorAddress (Ipv6Address("abcd::1")); - Ptr m1a1 = Create (); + Ptr m1a1 = Create (); m1a1->AddressPushBack (Ipv6Address ("10::2")); m1a1->AddressPushBack (Ipv6Address ("10::11:2")); m1->AddressBlockPushBack (m1a1); @@ -2866,18 +2865,18 @@ int main (void) * `------------------ */ { - PacketBB packet; + PbbPacket packet; - Ptr m1 = Create (); + Ptr m1 = Create (); m1->SetType(1); m1->SetOriginatorAddress (Ipv6Address("abcd::1")); - Ptr m1a1 = Create (); + Ptr m1a1 = Create (); m1a1->AddressPushBack (Ipv6Address ("10::2")); m1a1->AddressPushBack (Ipv6Address ("10::11:2")); m1->AddressBlockPushBack (m1a1); - Ptr m1a2 = Create (); + Ptr m1a2 = Create (); m1a2->AddressPushBack (Ipv6Address ("10::")); m1a2->AddressPushBack (Ipv6Address ("11::")); m1->AddressBlockPushBack (m1a2); @@ -2932,18 +2931,18 @@ int main (void) * `------------------ */ { - PacketBB packet; + PbbPacket packet; - Ptr m1 = Create (); + Ptr m1 = Create (); m1->SetType(1); m1->SetOriginatorAddress (Ipv6Address("abcd::1")); - Ptr m1a1 = Create (); + Ptr m1a1 = Create (); m1a1->AddressPushBack (Ipv6Address ("10::2")); m1a1->AddressPushBack (Ipv6Address ("10::11:2")); m1->AddressBlockPushBack (m1a1); - Ptr m1a2 = Create (); + Ptr m1a2 = Create (); m1a2->AddressPushBack (Ipv6Address ("10::")); m1a2->AddressPushBack (Ipv6Address ("11::")); m1a2->AddressPushBack (Ipv6Address ("10::5")); @@ -3038,80 +3037,80 @@ int main (void) * | | Index-start = 1 * | | Index-stop = 3 * | | Type = 1; Value = 00 01 02 03 - * | | 04 05 06 07 - * | | 08 09 0a 0b - * | | 0c 0d 0e 0f - * | | 10 11 12 13 - * | | 14 15 16 17 - * | | 18 19 1a 1b - * | | 1c 1d 1e 1f - * | | 20 21 22 23 - * | | 24 25 26 27 - * | | 28 29 2a 2b - * | | 2c 2d 2e 2f - * | | 30 31 32 33 - * | | 34 35 36 37 - * | | 38 39 3a 3b - * | | 3c 3d 3e 3f - * | | 40 41 42 43 - * | | 44 45 46 47 - * | | 48 49 4a 4b - * | | 4c 4d 4e 4f - * | | 50 51 52 53 - * | | 54 55 56 57 - * | | 58 59 5a 5b - * | | 5c 5d 5e 5f - * | | 60 61 62 63 - * | | 64 65 66 67 - * | | 68 69 6a 6b - * | | 6c 6d 6e 6f - * | | 70 71 72 73 - * | | 74 75 76 77 - * | | 78 79 7a 7b - * | | 7c 7d 7e 7f - * | | 80 81 82 83 - * | | 84 85 86 87 - * | | 88 89 8a 8b - * | | 8c 8d 8e 8f - * | | 90 91 92 93 - * | | 94 95 96 97 - * | | 98 99 9a 9b - * | | 9c 9d 9e 9f - * | | a0 a1 a2 a3 - * | | a4 a5 a6 a7 - * | | a8 a9 aa ab - * | | ac ad ae af - * | | b0 b1 b2 b3 - * | | b4 b5 b6 b7 - * | | b8 b9 ba bb - * | | bc bd be bf - * | | c0 c1 c2 c3 - * | | c4 c5 c6 c7 - * | | c8 c9 ca cb - * | | cc cd ce cf - * | | d0 d1 d2 d3 - * | | d4 d5 d6 d7 - * | | d8 d9 da db - * | | dc dd de df - * | | e0 e1 e2 e3 - * | | e4 e5 e6 e7 - * | | e8 e9 ea eb - * | | ec ed ee ef - * | | f0 f1 f2 f3 - * | | f4 f5 f6 f7 - * | | f8 f9 fa fb - * | | fc fd fe 00 - * | | 01 02 03 04 - * | | 05 06 07 08 - * | | 09 0a 0b 0c - * | | 0d 0e 0f 10 - * | | 11 12 13 14 - * | | 15 16 17 18 - * | | 19 1a 1b 1c - * | | 1d 1e 1f 20 - * | | 21 22 23 24 - * | | 25 26 27 28 - * | | 29 2a 2b 2c + * | | 04 05 06 07 + * | | 08 09 0a 0b + * | | 0c 0d 0e 0f + * | | 10 11 12 13 + * | | 14 15 16 17 + * | | 18 19 1a 1b + * | | 1c 1d 1e 1f + * | | 20 21 22 23 + * | | 24 25 26 27 + * | | 28 29 2a 2b + * | | 2c 2d 2e 2f + * | | 30 31 32 33 + * | | 34 35 36 37 + * | | 38 39 3a 3b + * | | 3c 3d 3e 3f + * | | 40 41 42 43 + * | | 44 45 46 47 + * | | 48 49 4a 4b + * | | 4c 4d 4e 4f + * | | 50 51 52 53 + * | | 54 55 56 57 + * | | 58 59 5a 5b + * | | 5c 5d 5e 5f + * | | 60 61 62 63 + * | | 64 65 66 67 + * | | 68 69 6a 6b + * | | 6c 6d 6e 6f + * | | 70 71 72 73 + * | | 74 75 76 77 + * | | 78 79 7a 7b + * | | 7c 7d 7e 7f + * | | 80 81 82 83 + * | | 84 85 86 87 + * | | 88 89 8a 8b + * | | 8c 8d 8e 8f + * | | 90 91 92 93 + * | | 94 95 96 97 + * | | 98 99 9a 9b + * | | 9c 9d 9e 9f + * | | a0 a1 a2 a3 + * | | a4 a5 a6 a7 + * | | a8 a9 aa ab + * | | ac ad ae af + * | | b0 b1 b2 b3 + * | | b4 b5 b6 b7 + * | | b8 b9 ba bb + * | | bc bd be bf + * | | c0 c1 c2 c3 + * | | c4 c5 c6 c7 + * | | c8 c9 ca cb + * | | cc cd ce cf + * | | d0 d1 d2 d3 + * | | d4 d5 d6 d7 + * | | d8 d9 da db + * | | dc dd de df + * | | e0 e1 e2 e3 + * | | e4 e5 e6 e7 + * | | e8 e9 ea eb + * | | ec ed ee ef + * | | f0 f1 f2 f3 + * | | f4 f5 f6 f7 + * | | f8 f9 fa fb + * | | fc fd fe 00 + * | | 01 02 03 04 + * | | 05 06 07 08 + * | | 09 0a 0b 0c + * | | 0d 0e 0f 10 + * | | 11 12 13 14 + * | | 15 16 17 18 + * | | 19 1a 1b 1c + * | | 1d 1e 1f 20 + * | | 21 22 23 24 + * | | 25 26 27 28 + * | | 29 2a 2b 2c * | | * | `------------------- * | @@ -3138,34 +3137,34 @@ int main (void) * `------------------ */ { - PacketBB packet; + PbbPacket packet; packet.SetSequenceNumber (29); - Ptr ptlv1 = Create (); + Ptr ptlv1 = Create (); ptlv1->SetType (1); packet.TlvPushBack (ptlv1); - Ptr m1 = Create (); + Ptr m1 = Create (); m1->SetType (1); - Ptr m1tlv1 = Create (); + Ptr m1tlv1 = Create (); m1tlv1->SetType (1); m1->TlvPushBack (m1tlv1); packet.MessagePushBack (m1); - Ptr m2 = Create (); + Ptr m2 = Create (); m2->SetType (2); m2->SetOriginatorAddress (Ipv4Address ("10.0.0.1")); m2->SetHopLimit (255); m2->SetHopCount (1); m2->SetSequenceNumber (12345); - Ptr m2a1 = Create (); + Ptr m2a1 = Create (); m2a1->AddressPushBack (Ipv4Address ("10.0.0.2")); m2a1->AddressPushBack (Ipv4Address ("10.1.1.2")); m2->AddressBlockPushBack (m2a1); - Ptr m2a2 = Create (); + Ptr m2a2 = Create (); m2a2->AddressPushBack (Ipv4Address ("10.0.0.0")); m2a2->AddressPushBack (Ipv4Address ("11.0.0.0")); m2a2->AddressPushBack (Ipv4Address ("10.0.0.5")); @@ -3175,7 +3174,7 @@ int main (void) m2a2->PrefixPushBack (16); m2a2->PrefixPushBack (24); - Ptr m2a2tlv1 = Create (); + Ptr m2a2tlv1 = Create (); m2a2tlv1->SetType (1); m2a2tlv1->SetIndexStart (1); m2a2tlv1->SetIndexStop (3); @@ -3263,16 +3262,16 @@ int main (void) m2->AddressBlockPushBack (m2a2); packet.MessagePushBack (m2); - Ptr m3 = Create (); + Ptr m3 = Create (); m3->SetType (1); m3->SetOriginatorAddress (Ipv6Address ("abcd::1")); - Ptr m3a1 = Create (); + Ptr m3a1 = Create (); m3a1->AddressPushBack (Ipv6Address ("10::2")); m3a1->AddressPushBack (Ipv6Address ("10::11:2")); m3->AddressBlockPushBack (m3a1); - Ptr m3a2 = Create (); + Ptr m3a2 = Create (); m3a2->AddressPushBack (Ipv6Address ("10::")); m3a2->AddressPushBack (Ipv6Address ("11::")); m3a2->AddressPushBack (Ipv6Address ("10::5")); @@ -3460,80 +3459,80 @@ int main (void) * | | Index-start = 1 * | | Index-stop = 3 * | | Type = 1; Value = 00 01 02 03 - * | | 04 05 06 07 - * | | 08 09 0a 0b - * | | 0c 0d 0e 0f - * | | 10 11 12 13 - * | | 14 15 16 17 - * | | 18 19 1a 1b - * | | 1c 1d 1e 1f - * | | 20 21 22 23 - * | | 24 25 26 27 - * | | 28 29 2a 2b - * | | 2c 2d 2e 2f - * | | 30 31 32 33 - * | | 34 35 36 37 - * | | 38 39 3a 3b - * | | 3c 3d 3e 3f - * | | 40 41 42 43 - * | | 44 45 46 47 - * | | 48 49 4a 4b - * | | 4c 4d 4e 4f - * | | 50 51 52 53 - * | | 54 55 56 57 - * | | 58 59 5a 5b - * | | 5c 5d 5e 5f - * | | 60 61 62 63 - * | | 64 65 66 67 - * | | 68 69 6a 6b - * | | 6c 6d 6e 6f - * | | 70 71 72 73 - * | | 74 75 76 77 - * | | 78 79 7a 7b - * | | 7c 7d 7e 7f - * | | 80 81 82 83 - * | | 84 85 86 87 - * | | 88 89 8a 8b - * | | 8c 8d 8e 8f - * | | 90 91 92 93 - * | | 94 95 96 97 - * | | 98 99 9a 9b - * | | 9c 9d 9e 9f - * | | a0 a1 a2 a3 - * | | a4 a5 a6 a7 - * | | a8 a9 aa ab - * | | ac ad ae af - * | | b0 b1 b2 b3 - * | | b4 b5 b6 b7 - * | | b8 b9 ba bb - * | | bc bd be bf - * | | c0 c1 c2 c3 - * | | c4 c5 c6 c7 - * | | c8 c9 ca cb - * | | cc cd ce cf - * | | d0 d1 d2 d3 - * | | d4 d5 d6 d7 - * | | d8 d9 da db - * | | dc dd de df - * | | e0 e1 e2 e3 - * | | e4 e5 e6 e7 - * | | e8 e9 ea eb - * | | ec ed ee ef - * | | f0 f1 f2 f3 - * | | f4 f5 f6 f7 - * | | f8 f9 fa fb - * | | fc fd fe 00 - * | | 01 02 03 04 - * | | 05 06 07 08 - * | | 09 0a 0b 0c - * | | 0d 0e 0f 10 - * | | 11 12 13 14 - * | | 15 16 17 18 - * | | 19 1a 1b 1c - * | | 1d 1e 1f 20 - * | | 21 22 23 24 - * | | 25 26 27 28 - * | | 29 2a 2b 2c + * | | 04 05 06 07 + * | | 08 09 0a 0b + * | | 0c 0d 0e 0f + * | | 10 11 12 13 + * | | 14 15 16 17 + * | | 18 19 1a 1b + * | | 1c 1d 1e 1f + * | | 20 21 22 23 + * | | 24 25 26 27 + * | | 28 29 2a 2b + * | | 2c 2d 2e 2f + * | | 30 31 32 33 + * | | 34 35 36 37 + * | | 38 39 3a 3b + * | | 3c 3d 3e 3f + * | | 40 41 42 43 + * | | 44 45 46 47 + * | | 48 49 4a 4b + * | | 4c 4d 4e 4f + * | | 50 51 52 53 + * | | 54 55 56 57 + * | | 58 59 5a 5b + * | | 5c 5d 5e 5f + * | | 60 61 62 63 + * | | 64 65 66 67 + * | | 68 69 6a 6b + * | | 6c 6d 6e 6f + * | | 70 71 72 73 + * | | 74 75 76 77 + * | | 78 79 7a 7b + * | | 7c 7d 7e 7f + * | | 80 81 82 83 + * | | 84 85 86 87 + * | | 88 89 8a 8b + * | | 8c 8d 8e 8f + * | | 90 91 92 93 + * | | 94 95 96 97 + * | | 98 99 9a 9b + * | | 9c 9d 9e 9f + * | | a0 a1 a2 a3 + * | | a4 a5 a6 a7 + * | | a8 a9 aa ab + * | | ac ad ae af + * | | b0 b1 b2 b3 + * | | b4 b5 b6 b7 + * | | b8 b9 ba bb + * | | bc bd be bf + * | | c0 c1 c2 c3 + * | | c4 c5 c6 c7 + * | | c8 c9 ca cb + * | | cc cd ce cf + * | | d0 d1 d2 d3 + * | | d4 d5 d6 d7 + * | | d8 d9 da db + * | | dc dd de df + * | | e0 e1 e2 e3 + * | | e4 e5 e6 e7 + * | | e8 e9 ea eb + * | | ec ed ee ef + * | | f0 f1 f2 f3 + * | | f4 f5 f6 f7 + * | | f8 f9 fa fb + * | | fc fd fe 00 + * | | 01 02 03 04 + * | | 05 06 07 08 + * | | 09 0a 0b 0c + * | | 0d 0e 0f 10 + * | | 11 12 13 14 + * | | 15 16 17 18 + * | | 19 1a 1b 1c + * | | 1d 1e 1f 20 + * | | 21 22 23 24 + * | | 25 26 27 28 + * | | 29 2a 2b 2c * | | * | `------------------- * | @@ -3560,34 +3559,34 @@ int main (void) * `------------------ */ { - PacketBB packet; + PbbPacket packet; packet.SetSequenceNumber (30); - Ptr ptlv1 = Create (); + Ptr ptlv1 = Create (); ptlv1->SetType (1); packet.TlvPushBack (ptlv1); - Ptr m1 = Create (); + Ptr m1 = Create (); m1->SetType (1); - Ptr m1tlv1 = Create (); + Ptr m1tlv1 = Create (); m1tlv1->SetType (1); m1->TlvPushBack (m1tlv1); packet.MessagePushBack (m1); - Ptr m2 = Create (); + Ptr m2 = Create (); m2->SetType (2); m2->SetOriginatorAddress (Ipv4Address ("10.0.0.1")); m2->SetHopLimit (255); m2->SetHopCount (1); m2->SetSequenceNumber (12345); - Ptr m2a1 = Create (); + Ptr m2a1 = Create (); m2a1->AddressPushBack (Ipv4Address ("10.0.0.2")); m2a1->AddressPushBack (Ipv4Address ("10.1.1.2")); m2->AddressBlockPushBack (m2a1); - Ptr m2a2 = Create (); + Ptr m2a2 = Create (); m2a2->AddressPushBack (Ipv4Address ("10.0.0.0")); m2a2->AddressPushBack (Ipv4Address ("11.0.0.0")); m2a2->AddressPushBack (Ipv4Address ("10.0.0.5")); @@ -3597,7 +3596,7 @@ int main (void) m2a2->PrefixPushBack (16); m2a2->PrefixPushBack (24); - Ptr m2a2tlv1 = Create (); + Ptr m2a2tlv1 = Create (); m2a2tlv1->SetType (1); m2a2tlv1->SetIndexStart (1); m2a2tlv1->SetIndexStop (3); @@ -3685,16 +3684,16 @@ int main (void) m2->AddressBlockPushBack (m2a2); packet.MessagePushBack (m2); - Ptr m3 = Create (); + Ptr m3 = Create (); m3->SetType (1); m3->SetOriginatorAddress (Ipv6Address ("abcd::1")); - Ptr m3a1 = Create (); + Ptr m3a1 = Create (); m3a1->AddressPushBack (Ipv6Address ("10::2")); m3a1->AddressPushBack (Ipv6Address ("10::11:2")); m3->AddressBlockPushBack (m3a1); - Ptr m3a2 = Create (); + Ptr m3a2 = Create (); m3a2->AddressPushBack (Ipv6Address ("10::")); m3a2->AddressPushBack (Ipv6Address ("11::")); m3a2->AddressPushBack (Ipv6Address ("10::5")); From 94bf0517f7a9fbb54267d2ab346430569c274584 Mon Sep 17 00:00:00 2001 From: Tom Wambold Date: Thu, 10 Sep 2009 15:35:16 -0400 Subject: [PATCH 07/12] PacketBB: Forgot to add Pbb prefix to enum. --- src/contrib/packetbb.cc | 6 +++--- src/contrib/packetbb.h | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/contrib/packetbb.cc b/src/contrib/packetbb.cc index 806db5877..0b5a92a36 100644 --- a/src/contrib/packetbb.cc +++ b/src/contrib/packetbb.cc @@ -932,7 +932,7 @@ PbbMessage::GetType (void) const return m_type; } -AddressLength +PbbAddressLength PbbMessage::GetAddressLength (void) const { return m_addrSize; @@ -1559,7 +1559,7 @@ PbbMessage::operator!= (const PbbMessage &other) const /* End PbbMessage Class */ -AddressLength +PbbAddressLength PbbMessageIpv4::GetAddressLength (void) const { return IPV4; @@ -1597,7 +1597,7 @@ PbbMessageIpv4::AddressBlockDeserialize (Buffer::Iterator &start) const /* End PbbMessageIpv4 Class */ -AddressLength +PbbAddressLength PbbMessageIpv6::GetAddressLength (void) const { return IPV6; diff --git a/src/contrib/packetbb.h b/src/contrib/packetbb.h index 7d6b5b1ae..01fb685d7 100644 --- a/src/contrib/packetbb.h +++ b/src/contrib/packetbb.h @@ -43,7 +43,7 @@ class PbbAddressTlvBlock; class PbbTlv; class PbbAddressTlv; -enum AddressLength { +enum PbbAddressLength { IPV4 = 3, IPV6 = 15, }; @@ -382,7 +382,7 @@ protected: * * IPv4 = 4 - 1 = 3, IPv6 = 16 - 1 = 15 */ - virtual AddressLength GetAddressLength (void) const = 0; + virtual PbbAddressLength GetAddressLength (void) const = 0; virtual void SerializeOriginatorAddress (Buffer::Iterator &start) const = 0; virtual Address DeserializeOriginatorAddress (Buffer::Iterator &start) const = 0; @@ -395,7 +395,7 @@ private: std::list< Ptr > m_addressBlockList; uint8_t m_type; - AddressLength m_addrSize; + PbbAddressLength m_addrSize; bool m_hasOriginatorAddress; Address m_originatorAddress; @@ -419,7 +419,7 @@ private: */ class PbbMessageIpv4 : public PbbMessage { protected: - virtual AddressLength GetAddressLength (void) const; + virtual PbbAddressLength GetAddressLength (void) const; virtual void SerializeOriginatorAddress (Buffer::Iterator &start) const; virtual Address DeserializeOriginatorAddress (Buffer::Iterator &start) const; @@ -435,7 +435,7 @@ protected: */ class PbbMessageIpv6 : public PbbMessage { protected: - virtual AddressLength GetAddressLength (void) const; + virtual PbbAddressLength GetAddressLength (void) const; virtual void SerializeOriginatorAddress (Buffer::Iterator &start) const; virtual Address DeserializeOriginatorAddress (Buffer::Iterator &start) const; From ea886c586f8a8b1630b5a14ab0158c3613c78c32 Mon Sep 17 00:00:00 2001 From: Tom Wambold Date: Fri, 11 Sep 2009 00:52:23 -0400 Subject: [PATCH 08/12] PacketBB: Doxygen documentation. Still have some more I want to write. --- src/contrib/packetbb.h | 1064 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 1036 insertions(+), 28 deletions(-) diff --git a/src/contrib/packetbb.h b/src/contrib/packetbb.h index 01fb685d7..aaffcb018 100644 --- a/src/contrib/packetbb.h +++ b/src/contrib/packetbb.h @@ -43,6 +43,7 @@ class PbbAddressTlvBlock; class PbbTlv; class PbbAddressTlv; +/** Used in Messages to determine whether it contains IPv4 or IPv6 addresses */ enum PbbAddressLength { IPV4 = 3, IPV6 = 15, @@ -59,34 +60,135 @@ public: typedef std::list< Ptr >::iterator Iterator; typedef std::list< Ptr >::const_iterator ConstIterator; + /** + * \return an iterator to the first TLV in this block. + */ Iterator Begin (void); + + /** + * \return a const iterator to the first TLV in this block. + */ ConstIterator Begin (void) const; + + /** + * \return an iterator to the past-the-end element in this block. + */ Iterator End (void); + + /** + * \return a const iterator to the past-the-end element in this block. + */ ConstIterator End (void) const; + /** + * \return the number of TLVs in this block. + */ int Size (void) const; + + /** + * \return true if there are no TLVs in this block, false otherwise. + */ bool Empty (void) const; + /** + * \return a smart pointer to the first TLV in this block. + */ Ptr Front (void) const; + + /** + * \return a smart pointer to the last TLV in this block. + */ Ptr Back (void) const; + /** + * \brief Prepends a TLV to the front of this block. + * \param tlv a smart pointer to the TLV to prepend. + */ void PushFront (Ptr tlv); + + /** + * \brief Removes a TLV from the front of this block. + */ void PopFront (void); + /** + * \brief Appends a TLV to the back of this block. + * \param tlv a smart pointer to the TLV to append. + */ void PushBack (Ptr tlv); + + /** + * \brief Removes a TLV from the back of this block. + */ void PopBack (void); + /** + * \brief Inserts a TLV at the specified position in this block. + * \param position an Iterator pointing to the position in this block to + * insert the TLV. + * \param tlv a smart pointer to the TLV to insert. + * \return An iterator pointing to the newly inserted TLV. + */ Iterator Insert (Iterator position, const Ptr tlv); + /** + * \brief Removes the TLV at the specified position. + * \param position an Iterator pointing to the TLV to erase. + * \return an iterator pointing to the next TLV in the block. + */ Iterator Erase (Iterator position); + + /** + * \brief Removes all TLVs from [first, last) (includes first, not includes + * last). + * \param first an Iterator pointing to the first TLV to erase (inclusive). + * \param last an Iterator pointing to the element past the last TLV to erase. + * \return an iterator pointing to the next TLV in the block. + */ Iterator Erase (Iterator first, Iterator last); + /** + * \brief Removes all TLVs from this block. + */ void Clear (void); + /** + * \return The size (in bytes) needed to serialize this block. + */ uint32_t GetSerializedSize (void) const; + + /** + * \brief Serializes this block into the specified buffer. + * \param start a reference to the point in a buffer to begin serializing. + * + * Users should not need to call this. Blocks will be serialized by their + * containing packet. + */ void Serialize (Buffer::Iterator &start) const; + + /** + * \brief Deserializes a block from the specified buffer. + * \param start a reference to the point in a buffer to begin deserializing. + * + * Users should not need to call this. Blocks will be deserialized by their + * containing packet. + */ void Deserialize (Buffer::Iterator &start); + + /** + * \brief Pretty-prints the contents of this block. + * \param os a stream object to print to. + */ void Print (std::ostream &os) const; + + /** + * \brief Pretty-prints the contents of this block, with specified indentation. + * \param os a stream object to print to. + * \param level level of indentation. + * + * This probably never needs to be called by users. This is used when + * recursively printing sub-objects. + */ void Print (std::ostream &os, int level) const; bool operator== (const PbbTlvBlock &other) const; @@ -107,34 +209,137 @@ public: typedef std::list< Ptr >::iterator Iterator; typedef std::list< Ptr >::const_iterator ConstIterator; + /** + * \return an iterator to the first Address TLV in this block. + */ Iterator Begin (void); + + /** + * \return a const iterator to the first Address TLV in this block. + */ ConstIterator Begin (void) const; + + /** + * \return an iterator to the past-the-end element in this block. + */ Iterator End (void); + + /** + * \return a const iterator to the past-the-end element in this block. + */ ConstIterator End (void) const; + /** + * \return the number of Address TLVs in this block. + */ int Size (void) const; + + /** + * \return true if there are no Address TLVs in this block, false otherwise. + */ bool Empty (void) const; + /** + * \return the first Address TLV in this block. + */ Ptr Front (void) const; + + /** + * \return the last AddressTLV in this block. + */ Ptr Back (void) const; + /** + * \brief Prepends an Address TLV to the front of this block. + * \param tlv a smart pointer to the Address TLV to prepend. + */ void PushFront (Ptr tlv); + + /** + * \brief Removes an AddressTLV from the front of this block. + */ void PopFront (void); + /** + * \brief Appends an Address TLV to the back of this block. + * \param tlv a smart pointer to the Address TLV to append. + */ void PushBack (Ptr tlv); + + /** + * \brief Removes an Address TLV from the back of this block. + */ void PopBack (void); + /** + * \brief Inserts an Address TLV at the specified position in this block. + * \param position an Iterator pointing to the position in this block to + * insert the Address TLV. + * \param tlv a smart pointer to the Address TLV to insert. + * \return An iterator pointing to the newly inserted Address TLV. + */ Iterator Insert (Iterator position, const Ptr tlv); + /** + * \brief Removes the Address TLV at the specified position. + * \param position an Iterator pointing to the Address TLV to erase. + * \return an iterator pointing to the next Address TLV in the block. + */ Iterator Erase (Iterator position); + + /** + * \brief Removes all Address TLVs from [first, last) (includes first, not + * includes last). + * \param first an Iterator pointing to the first Address TLV to erase + * (inclusive). + * \param last an Iterator pointing to the element past the last Address TLV + * to erase. + * \return an iterator pointing to the next Address TLV in the block. + */ Iterator Erase (Iterator first, Iterator last); + /** + * \brief Removes all Address TLVs from this block. + */ void Clear (void); + /** + * \return The size (in bytes) needed to serialize this block. + */ uint32_t GetSerializedSize (void) const; + + /** + * \brief Serializes this block into the specified buffer. + * \param start a reference to the point in a buffer to begin serializing. + * + * Users should not need to call this. Blocks will be serialized by their + * containing packet. + */ void Serialize (Buffer::Iterator &start) const; + + /** + * \brief Deserializes a block from the specified buffer. + * \param start a reference to the point in a buffer to begin deserializing. + * + * Users should not need to call this. Blocks will be deserialized by their + * containing packet. + */ void Deserialize (Buffer::Iterator &start); + + /** + * \brief Pretty-prints the contents of this block. + * \param os a stream object to print to. + */ void Print (std::ostream &os) const; + + /** + * \brief Pretty-prints the contents of this block, with specified indentation. + * \param os a stream object to print to. + * \param level level of indentation. + * + * This probably never needs to be called by users. This is used when + * recursively printing sub-objects. + */ void Print (std::ostream &os, int level) const; bool operator== (const PbbAddressTlvBlock &other) const; @@ -145,7 +350,9 @@ private: }; /** - * \brief Main PbbPacket Packet object. + * \brief Main PacketBB Packet object. + * + * See: http://tools.ietf.org/html/rfc5444 for details. */ class PbbPacket : public Header { @@ -157,64 +364,228 @@ public: PbbPacket (void); + /** + * \return the version of PacketBB that constructed this packet. + * + * This will always return 0 for packets constructed using this API. + */ uint8_t GetVersion (void) const; - void SetSequenceNumber (uint16_t number); /** - * \returns the sequence number of this packet. + * \brief Sets the sequence number of this packet. + * \param number the sequence number. + */ + void SetSequenceNumber (uint16_t number); + + /** + * \return the sequence number of this packet. * * Calling this while HasSequenceNumber is False is undefined. Make sure you * check it first. This will be checked by an assert in debug builds. */ uint16_t GetSequenceNumber (void) const; + + /** + * \brief Tests whether or not this packet has a sequence number. + * \return true if this packet has a sequence number, false otherwise. + * + * This should be called before calling GetSequenceNumber to make sure there + * actually is one. + */ bool HasSequenceNumber (void) const; /* Manipulating Packet TLVs */ + /** + * \return an iterator to the first Packet TLV in this packet. + */ TlvIterator TlvBegin (void); + + /** + * \return a const iterator to the first Packet TLV in this packet. + */ ConstTlvIterator TlvBegin (void) const; + + /** + * \return an iterator to the past-the-end element in this packet TLV block. + */ TlvIterator TlvEnd (void); + + /** + * \return a const iterator to the past-the-end element in this packet TLV + * block. + */ ConstTlvIterator TlvEnd (void) const; + /** + * \return the number of packet TLVs in this packet. + */ int TlvSize (void) const; + + /** + * \return true if there are no packet TLVs in this packet, false otherwise. + */ bool TlvEmpty (void) const; + /** + * \return a smart pointer to the first packet TLV in this packet. + */ Ptr TlvFront (void); + + /** + * \return a const smart pointer to the first packet TLV in this packet. + */ const Ptr TlvFront (void) const; + + /** + * \return a smart pointer to the last packet TLV in this packet. + */ Ptr TlvBack (void); + + /** + * \return a const smart pointer to the last packet TLV in this packet. + */ const Ptr TlvBack (void) const; - void TlvPushFront (Ptr); + /** + * \brief Prepends a packet TLV to the front of this packet. + * \param tlv a smart pointer to the packet TLV to prepend. + */ + void TlvPushFront (Ptr tlv); + + /** + * \brief Removes a packet TLV from the front of this packet. + */ void TlvPopFront (void); - void TlvPushBack (Ptr); + + /** + * \brief Appends a packet TLV to the back of this packet. + * \param tlv a smart pointer to the packet TLV to append. + */ + void TlvPushBack (Ptr tlv); + + /** + * \brief Removes a packet TLV from the back of this block. + */ void TlvPopBack (void); + /** + * \brief Removes the packet TLV at the specified position. + * \param position an Iterator pointing to the packet TLV to erase. + * \return an iterator pointing to the next packet TLV in the block. + */ TlvIterator Erase (TlvIterator position); + + /** + * \brief Removes all packet TLVs from [first, last) (includes first, not + * includes last). + * \param first an Iterator pointing to the first packet TLV to erase + * (inclusive). + * \param last an Iterator pointing to the element past the last packet TLV + * to erase. + * \return an iterator pointing to the next packet TLV in the block. + */ TlvIterator Erase (TlvIterator first, TlvIterator last); + + /** + * \brief Removes all packet TLVs from this packet. + */ void TlvClear (void); /* Manipulating Packet Messages */ + /** + * \return an iterator to the first message in this packet. + */ MessageIterator MessageBegin (void); + + /** + * \return a const iterator to the first message in this packet. + */ ConstMessageIterator MessageBegin (void) const; + + /** + * \return an iterator to the past-the-end element in this message block. + */ MessageIterator MessageEnd (void); + + /** + * \return a const iterator to the past-the-end element in this message + * block. + */ ConstMessageIterator MessageEnd (void) const; + /** + * \return the number of messages in this packet. + */ int MessageSize (void) const; + + /** + * \return true if there are no messages in this packet, false otherwise. + */ bool MessageEmpty (void) const; + /** + * \return a smart pointer to the first message in this packet. + */ Ptr MessageFront (void); + + /** + * \return a cosnt smart pointer to the first message in this packet. + */ const Ptr MessageFront (void) const; + + /** + * \return a smart pointer to the last message in this packet. + */ Ptr MessageBack (void); + + /** + * \return a cosnt smart pointer to the last message in this packet. + */ const Ptr MessageBack (void) const; + /** + * \brief Prepends a message to the front of this packet. + * \param message a smart pointer to the message to prepend. + */ void MessagePushFront (Ptr message); + + /** + * \brief Removes a message from the front of this packet. + */ void MessagePopFront (void); + + /** + * \brief Appends a message to the back of this packet. + * \param message a smart pointer to the message to append. + */ void MessagePushBack (Ptr message); + + /** + * \brief Removes a message from the back of this packet. + */ void MessagePopBack (void); + /** + * \brief Removes the message at the specified position. + * \param position an Iterator pointing to the message to erase. + * \return an iterator pointing to the next message in the packet. + */ MessageIterator Erase (MessageIterator position); + + /** + * \brief Removes all messages from [first, last) (includes first, not + * includes last). + * \param first an Iterator pointing to the first message to erase (inclusive). + * \param last an Iterator pointing to the element past the last message to erase. + * \return an iterator pointing to the next message in the block. + */ MessageIterator Erase (MessageIterator first, MessageIterator last); + + /** + * \brief Removes all messages from this packet. + */ void MessageClear (void); /* Smart pointer methods */ @@ -224,15 +595,31 @@ public: /* Methods implemented by all headers */ static TypeId GetTypeId (void); virtual TypeId GetInstanceTypeId (void) const; - virtual uint32_t GetSerializedSize (void) const; - virtual void Serialize (Buffer::Iterator start) const; + /** - * \returns the number of bytes deserialized + * \return The size (in bytes) needed to serialize this packet. + */ + virtual uint32_t GetSerializedSize (void) const; + + /** + * \brief Serializes this packet into the specified buffer. + * \param start a reference to the point in a buffer to begin serializing. + */ + virtual void Serialize (Buffer::Iterator start) const; + + /** + * \brief Deserializes a packet from the specified buffer. + * \return the number of bytes deserialized * * If this returns a number smaller than the total number of bytes in the * buffer, there was an error. */ virtual uint32_t Deserialize (Buffer::Iterator start); + + /** + * \brief Pretty-prints the contents of this block. + * \param os a stream object to print to. + */ virtual void Print (std::ostream &os) const; bool operator== (const PbbPacket &other) const; @@ -270,108 +657,352 @@ public: PbbMessage (void); + /** + * \brief Sets the type for this message. + * \param type the type to set. + */ void SetType (uint8_t type); + + /** + * \return the type assigned to this packet + */ uint8_t GetType (void) const; - void SetOriginatorAddress (Address address); /** - * \returns the address of the node that created this packet. + * \brief Sets the address for the node that created this packet. + * \param address the originator address. + */ + void SetOriginatorAddress (Address address); + + /** + * \return the address of the node that created this packet. * * Calling this while HasOriginatorAddress is False is undefined. Make sure * you check it first. This will be checked by an assert in debug builds. */ Address GetOriginatorAddress (void) const; + + /** + * \brief Tests whether or not this message has an originator address. + * \return true if this message has an originator address, false otherwise. + */ bool HasOriginatorAddress (void) const; - void SetHopLimit (uint8_t hoplimit); /** - * \returns the maximum number of hops this message should travel. + * \brief Sets the maximum number of hops this message should travel + * \param hoplimit the limit to set + */ + void SetHopLimit (uint8_t hoplimit); + + /** + * \return the maximum number of hops this message should travel. * * Calling this while HasHopLimit is False is undefined. Make sure you check * it first. This will be checked by an assert in debug builds. */ uint8_t GetHopLimit (void) const; + + /** + * \brief Tests whether or not this message has a hop limit. + * \return true if this message has a hop limit, false otherwise. + * + * If this is set, messages should not hop further than this limit. + */ bool HasHopLimit (void) const; - void SetHopCount (uint8_t hopcount); /** - * \returns the current number of hops this message has traveled. + * \brief Sets the current number of hops this message has traveled. + * \param hopcount the current number of hops + */ + void SetHopCount (uint8_t hopcount); + + /** + * \return the current number of hops this message has traveled. * * Calling this while HasHopCount is False is undefined. Make sure you check * it first. This will be checked by an assert in debug builds. */ uint8_t GetHopCount (void) const; + + /** + * \brief Tests whether or not this message has a hop count. + * \return true if this message has a hop limit, false otherwise. + */ bool HasHopCount (void) const; - void SetSequenceNumber (uint16_t seqnum); /** - * \returns the sequence number of this message. + * \brief Sets the sequence number of this message. + * \param seqnum the sequence number to set. + */ + void SetSequenceNumber (uint16_t seqnum); + + /** + * \return the sequence number of this message. * * Calling this while HasSequenceNumber is False is undefined. Make sure you * check it first. This will be checked by an assert in debug builds. */ uint16_t GetSequenceNumber (void) const; + + /** + * \brief Tests whether or not this message has a sequence number. + * \return true if this message has a sequence number, false otherwise. + */ bool HasSequenceNumber (void) const; /* Manipulating PbbMessage TLVs */ + /** + * \return an iterator to the first message TLV in this message. + */ TlvIterator TlvBegin (); + + /** + * \return a const iterator to the first message TLV in this message. + */ ConstTlvIterator TlvBegin () const; + + /** + * \return an iterator to the past-the-end message TLV element in this + * message. + */ TlvIterator TlvEnd (); + + /** + * \return a const iterator to the past-the-end message TLV element in this + * message. + */ ConstTlvIterator TlvEnd () const; + /** + * \return the number of message TLVs in this message. + */ int TlvSize (void) const; + + /** + * \return true if there are no message TLVs in this message, false otherwise. + */ bool TlvEmpty (void) const; + /** + * \return a smart pointer to the first message TLV in this message. + */ Ptr TlvFront (void); + + /** + * \return a const smart pointer to the first message TLV in this message. + */ const Ptr TlvFront (void) const; + + /** + * \return a smart pointer to the last message TLV in this message. + */ Ptr TlvBack (void); + + /** + * \return a const smart pointer to the last message TLV in this message. + */ const Ptr TlvBack (void) const; + /** + * \brief Prepends a message TLV to the front of this message. + * \param tlv a smart pointer to the message TLV to prepend. + */ void TlvPushFront (Ptr tlv); + + /** + * \brief Removes a message TLV from the front of this message. + */ void TlvPopFront (void); + + /** + * \brief Appends a message TLV to the back of this message. + * \param tlv a smart pointer to the message TLV to append. + */ void TlvPushBack (Ptr tlv); + + /** + * \brief Removes a message TLV from the back of this message. + */ void TlvPopBack (void); + /** + * \brief Removes the message TLV at the specified position. + * \param position an Iterator pointing to the message TLV to erase. + * \return an iterator pointing to the next TLV in the block. + */ TlvIterator TlvErase (TlvIterator position); + + /** + * \brief Removes all message TLVs from [first, last) (includes first, not + * includes last). + * \param first an Iterator pointing to the first message TLV to erase + * (inclusive). + * \param last an Iterator pointing to the element past the last message TLV + * to erase. + * \return an iterator pointing to the next message TLV in the message. + */ TlvIterator TlvErase (TlvIterator first, TlvIterator last); + + /** + * \brief Removes all message TLVs from this block. + */ void TlvClear (void); /* Manipulating Address Block and Address TLV pairs */ + /** + * \return an iterator to the first address block in this message. + */ AddressBlockIterator AddressBlockBegin (); + + /** + * \return a const iterator to the first address block in this message. + */ ConstAddressBlockIterator AddressBlockBegin () const; + + /** + * \return an iterator to the past-the-end address block element in this + * message. + */ AddressBlockIterator AddressBlockEnd (); + + /** + * \return a const iterator to the past-the-end address block element in this + * message. + */ ConstAddressBlockIterator AddressBlockEnd () const; + /** + * \return the number of address blocks in this message. + */ int AddressBlockSize (void) const; + + /** + * \return true if there are no address blocks in this message, false + * otherwise. + */ bool AddressBlockEmpty (void) const; + /** + * \return a smart pointer to the first address block in this message. + */ Ptr AddressBlockFront (void); + + /** + * \return a const smart pointer to the first address block in this message. + */ const Ptr AddressBlockFront (void) const; + + /** + * \return a smart pointer to the last address block in this message. + */ Ptr AddressBlockBack (void); + + /** + * \return a const smart pointer to the last address block in this message. + */ const Ptr AddressBlockBack (void) const; + /** + * \brief Prepends an address block to the front of this message. + * \param block a smart pointer to the address block to prepend. + */ void AddressBlockPushFront (Ptr block); + + /** + * \brief Removes an address block from the front of this message. + */ void AddressBlockPopFront (void); + + /** + * \brief Appends an address block to the front of this message. + * \param block a smart pointer to the address block to append. + */ void AddressBlockPushBack (Ptr block); + + /** + * \brief Removes an address block from the back of this message. + */ void AddressBlockPopBack (void); + /** + * \brief Removes the address block at the specified position. + * \param position an Iterator pointing to the address block to erase. + * \return an iterator pointing to the next address block in the message. + */ AddressBlockIterator AddressBlockErase (AddressBlockIterator position); + + /** + * \brief Removes all address blocks from [first, last) (includes first, not + * includes last). + * \param first an Iterator pointing to the first address block to erase + * (inclusive). + * \param last an Iterator pointing to the element past the last address + * block to erase. + * \return an iterator pointing to the next address block in the message. + */ AddressBlockIterator AddressBlockErase (AddressBlockIterator first, AddressBlockIterator last); + + /** + * \brief Removes all address blocks from this message. + */ void AddressBlockClear (void); /* Smart pointer methods */ void Ref (void) const; void Unref (void) const; - /* Returns 0 on error */ + /** + * \brief Deserializes a message, returning the correct object depending on + * whether it is an IPv4 message or an IPv6 message. + * \param start a reference to the point in a buffer to begin deserializing. + * \return A pointer to the deserialized message, or 0 on error. + * + * Users should not need to call this. Blocks will be deserialized by their + * containing packet. + */ static Ptr DeserializeMessage (Buffer::Iterator &start); + + /** + * \return The size (in bytes) needed to serialize this message. + */ uint32_t GetSerializedSize (void) const; + + /** + * \brief Serializes this message into the specified buffer. + * \param start a reference to the point in a buffer to begin serializing. + * + * Users should not need to call this. Blocks will be deserialized by their + * containing packet. + */ void Serialize (Buffer::Iterator &start) const; + + /** + * \brief Deserializes a message from the specified buffer. + * \param start a reference to the point in a buffer to begin deserializing. + * + * Users should not need to call this. Blocks will be deserialized by their + * containing packet. + */ void Deserialize (Buffer::Iterator &start); + + /** + * \brief Pretty-prints the contents of this message. + * \param os a stream object to print to. + */ void Print (std::ostream &os) const; + + /** + * \brief Pretty-prints the contents of this message, with specified + * indentation. + * \param os a stream object to print to. + * \param level level of indentation. + * + * This probably never needs to be called by users. This is used when + * recursively printing sub-objects. + */ void Print (std::ostream &os, int level) const; bool operator== (const PbbMessage &other) const; @@ -462,95 +1093,349 @@ public: typedef PbbAddressTlvBlock::Iterator TlvIterator; typedef PbbAddressTlvBlock::ConstIterator ConstTlvIterator; - PbbAddressBlock (); + PbbAddressBlock (void); /* Manipulating the address block */ + /** + * \return an iterator to the first address in this block. + */ AddressIterator AddressBegin (void); + + /** + * \return a const iterator to the first address in this block. + */ ConstAddressIterator AddressBegin (void) const; + + /** + * \return an iterator to the last address in this block. + */ AddressIterator AddressEnd (void); + + /** + * \return a const iterator to the last address in this block. + */ ConstAddressIterator AddressEnd (void) const; + /** + * \return the number of addresses in this block. + */ int AddressSize (void) const; + + /** + * \return true if there are no addresses in this block, false otherwise. + */ bool AddressEmpty (void) const; + /** + * \return the first address in this block. + */ Address AddressFront (void) const; + + /** + * \return the last address in this block. + */ Address AddressBack (void) const; + /** + * \brief Prepends an address to the front of this block. + * \param address the address to prepend. + */ void AddressPushFront (Address address); + + /** + * \brief Removes an address from the front of this block. + */ void AddressPopFront (void); + /** + * \brief Appends an address to the back of this block. + * \param address the address to append. + */ void AddressPushBack (Address address); + + /** + * \brief Removes an address from the back of this block. + */ void AddressPopBack (void); + /** + * \brief Inserts an address at the specified position in this block. + * \param position an Iterator pointing to the position in this block to + * insert the address. + * \param value the address to insert. + * \return An iterator pointing to the newly inserted address. + */ AddressIterator AddressInsert (AddressIterator position, const Address value); + /** + * \brief Removes the address at the specified position. + * \param position an Iterator pointing to the address to erase. + * \return an iterator pointing to the next address in the block. + */ AddressIterator AddressErase (AddressIterator position); + + /** + * \brief Removes all addresses from [first, last) (includes first, not + * includes last). + * \param first an Iterator pointing to the first address to erase + * (inclusive). + * \param last an Iterator pointing to the element past the last address to + * erase. + * \return an iterator pointing to the next address in the block. + */ AddressIterator AddressErase (AddressIterator first, AddressIterator last); + /** + * \brief Removes all addresses from this block. + */ void AddressClear (void); /* Prefix methods */ + + /** + * \return an iterator to the first prefix in this block. + */ PrefixIterator PrefixBegin (void); + + /** + * \return a const iterator to the first prefix in this block. + */ ConstPrefixIterator PrefixBegin (void) const; + + /** + * \return an iterator to the last prefix in this block. + */ PrefixIterator PrefixEnd (void); + + /** + * \return a const iterator to the last prefix in this block. + */ ConstPrefixIterator PrefixEnd (void) const; + /** + * \return the number of prefixes in this block. + */ int PrefixSize (void) const; + + /** + * \return true if there are no prefixes in this block, false otherwise. + */ bool PrefixEmpty (void) const; + /** + * \return the first prefix in this block. + */ uint8_t PrefixFront (void) const; + + /** + * \return the last prefix in this block. + */ uint8_t PrefixBack (void) const; + /** + * \brief Prepends a prefix to the front of this block. + * \param prefix the prefix to prepend. + */ void PrefixPushFront (uint8_t prefix); + + /** + * \brief Removes a prefix from the front of this block. + */ void PrefixPopFront (void); + /** + * \brief Appends a prefix to the back of this block. + * \param prefix the prefix to append. + */ void PrefixPushBack (uint8_t prefix); + + /** + * \brief Removes a prefix from the back of this block. + */ void PrefixPopBack (void); + /** + * \brief Inserts a prefix at the specified position in this block. + * \param position an Iterator pointing to the position in this block to + * insert the prefix. + * \param value the prefix to insert. + * \return An iterator pointing to the newly inserted prefix. + */ PrefixIterator PrefixInsert (PrefixIterator position, const uint8_t value); + /** + * \brief Removes the prefix at the specified position. + * \param position an Iterator pointing to the prefix to erase. + * \return an iterator pointing to the next prefix in the block. + */ PrefixIterator PrefixErase (PrefixIterator position); + + /** + * \brief Removes all prefixes from [first, last) (includes first, not + * includes last). + * \param first an Iterator pointing to the first prefix to erase + * (inclusive). + * \param last an Iterator pointing to the element past the last prefix to + * erase. + * \return an iterator pointing to the next prefix in the block. + */ PrefixIterator PrefixErase (PrefixIterator first, PrefixIterator last); + /** + * \brief Removes all prefixes from this block. + */ void PrefixClear (void); /* Manipulating the TLV block */ + + /** + * \return an iterator to the first address TLV in this block. + */ TlvIterator TlvBegin (void); + + /** + * \return a const iterator to the first address TLV in this block. + */ ConstTlvIterator TlvBegin (void) const; + + /** + * \return an iterator to the last address TLV in this block. + */ TlvIterator TlvEnd (void); + + /** + * \return a const iterator to the last address TLV in this block. + */ ConstTlvIterator TlvEnd (void) const; + /** + * \return the number of address TLVs in this block. + */ int TlvSize (void) const; + + /** + * \return true if there are no address TLVs in this block, false otherwise. + */ bool TlvEmpty (void) const; + /** + * \return a smart pointer to the first address TLV in this block. + */ Ptr TlvFront (void); + + /** + * \return a const smart pointer to the first address TLV in this message. + */ const Ptr TlvFront (void) const; + + /** + * \return a smart pointer to the last address TLV in this message. + */ Ptr TlvBack (void); + + /** + * \return a const smart pointer to the last address TLV in this message. + */ const Ptr TlvBack (void) const; + /** + * \brief Prepends an address TLV to the front of this message. + * \param address a smart pointer to the address TLV to prepend. + */ void TlvPushFront (Ptr address); + + /** + * \brief Removes an address TLV from the front of this message. + */ void TlvPopFront (void); + /** + * \brief Appends an address TLV to the back of this message. + * \param address a smart pointer to the address TLV to append. + */ void TlvPushBack (Ptr address); + + /** + * \brief Removes an address TLV from the back of this message. + */ void TlvPopBack (void); + /** + * \brief Inserts an address TLV at the specified position in this block. + * \param position an Iterator pointing to the position in this block to + * insert the address TLV. + * \param value the prefix to insert. + * \return An iterator pointing to the newly inserted address TLV. + */ TlvIterator TlvInsert (TlvIterator position, const Ptr value); + /** + * \brief Removes the address TLV at the specified position. + * \param position an Iterator pointing to the address TLV to erase. + * \return an iterator pointing to the next address TLV in the block. + */ TlvIterator TlvErase (TlvIterator position); + + /** + * \brief Removes all address TLVs from [first, last) (includes first, not + * includes last). + * \param first an Iterator pointing to the first address TLV to erase + * (inclusive). + * \param last an Iterator pointing to the element past the last address TLV + * to erase. + * \return an iterator pointing to the next address TLV in the message. + */ TlvIterator TlvErase (TlvIterator first, TlvIterator last); + /** + * \brief Removes all address TLVs from this block. + */ void TlvClear (void); /* Smart pointer methods */ void Ref (void) const; void Unref (void) const; + /** + * \return The size (in bytes) needed to serialize this address block. + */ uint32_t GetSerializedSize (void) const; + + /** + * \brief Serializes this address block into the specified buffer. + * \param start a reference to the point in a buffer to begin serializing. + * + * Users should not need to call this. Blocks will be deserialized by their + * containing packet. + */ void Serialize (Buffer::Iterator &start) const; + + /** + * \brief Deserializes an address block from the specified buffer. + * \param start a reference to the point in a buffer to begin deserializing. + * + * Users should not need to call this. Blocks will be deserialized by their + * containing packet. + */ void Deserialize (Buffer::Iterator &start); + + /** + * \brief Pretty-prints the contents of this address block. + * \param os a stream object to print to. + */ void Print (std::ostream &os) const; + + /** + * \brief Pretty-prints the contents of this address block, with specified + * indentation. + * \param os a stream object to print to. + * \param level level of indentation. + * + * This probably never needs to be called by users. This is used when + * recursively printing sub-objects. + */ void Print (std::ostream &os, int level) const; bool operator== (const PbbAddressBlock &other) const; @@ -614,38 +1499,120 @@ class PbbTlv public: PbbTlv (void); + /** + * \brief Sets the type of this TLV. + * \param type the type value to set. + */ void SetType (uint8_t type); + + /** + * \return the type of this TLV. + */ uint8_t GetType (void) const; - void SetTypeExt (uint8_t type); /** - * \returns the type extension for this TLV. + * \brief Sets the type extension of this TLV. + * \param type the type extension value to set. + * + * The type extension is like a sub-type used to further distinguish between + * TLVs of the same type. + */ + void SetTypeExt (uint8_t type); + + /** + * \return the type extension for this TLV. * * Calling this while HasTypeExt is False is undefined. Make sure you check * it first. This will be checked by an assert in debug builds. */ uint8_t GetTypeExt (void) const; + + /** + * \brief Tests whether or not this TLV has a type extension. + * \return true if this TLV has a type extension, false otherwise. + * + * This should be called before calling GetTypeExt to make sure there + * actually is one. + */ bool HasTypeExt (void) const; - void SetValue (Buffer start); - void SetValue (const uint8_t * buffer, uint32_t size); /** - * \returns a Buffer pointing to the value of this TLV. + * \brief Sets the value of this message to the specified buffer. + * \param start a buffer instance. + * + * The buffer is _not_ copied until this TLV is serialized. You should not + * change the contents of the buffer you pass in to this function. + */ + void SetValue (Buffer start); + + /** + * \brief Sets the value of this message to a buffer with the specified data. + * \param buffer a pointer to data to put in the TLVs buffer. + * \param size the size of the buffer. + * + * The buffer *is copied* into a *new buffer instance*. You can free the + * data in the buffer provided anytime you wish. + */ + void SetValue (const uint8_t * buffer, uint32_t size); + + /** + * \return a Buffer pointing to the value of this TLV. * * Calling this while HasValue is False is undefined. Make sure you check it * first. This will be checked by an assert in debug builds. */ Buffer GetValue (void) const; + + /** + * \brief Tests whether or not this TLV has a value. + * \return true if this tlv has a TLV, false otherwise. + * + * This should be called before calling GetTypeExt to make sure there + * actually is one. + */ bool HasValue (void) const; /* Smart pointer methods */ void Ref (void) const; void Unref (void) const; + /** + * \return The size (in bytes) needed to serialize this TLV. + */ uint32_t GetSerializedSize (void) const; + + /** + * \brief Serializes this TLV into the specified buffer. + * \param start a reference to the point in a buffer to begin serializing. + * + * Users should not need to call this. TLVs will be serialized by their + * containing blocks. + */ void Serialize (Buffer::Iterator &start) const; + + /** + * \brief Deserializes a TLV from the specified buffer. + * \param start a reference to the point in a buffer to begin deserializing. + * + * Users should not need to call this. TLVs will be deserialized by their + * containing blocks. + */ void Deserialize (Buffer::Iterator &start); + + /** + * \brief Pretty-prints the contents of this TLV. + * \param os a stream object to print to. + */ void Print (std::ostream &os) const; + + /** + * \brief Pretty-prints the contents of this TLV, with specified indentation. + * \param os a stream object to print to. + * \param level level of indentation. + * + * This probably never needs to be called by users. This is used when + * recursively printing sub-objects. + */ void Print (std::ostream &os, int level) const; bool operator== (const PbbTlv &other) const; @@ -688,29 +1655,70 @@ private: class PbbAddressTlv : public PbbTlv { public: - void SetIndexStart (uint8_t index); /** - * \returns the first (inclusive) index of the address in the corresponding - * PbbAddressBlock that this TLV applies to. + * \brief Sets the index of the first address in the associated address block + * that this address TLV applies to. + * \param index the index of the first address. + */ + void SetIndexStart (uint8_t index); + + /** + * \return the first (inclusive) index of the address in the corresponding + * address block that this TLV applies to. * * Calling this while HasIndexStart is False is undefined. Make sure you * check it first. This will be checked by an assert in debug builds. */ uint8_t GetIndexStart (void) const; + + /** + * \brief Tests whether or not this address TLV has a start index. + * \return true if this address TLV has a start index, false otherwise. + * + * This should be called before calling GetIndexStart to make sure there + * actually is one. + */ bool HasIndexStart (void) const; - void SetIndexStop (uint8_t index); /** - * \returns the last (inclusive) index of the address in the corresponding + * \brief Sets the index of the last address in the associated address block + * that this address TLV applies to. + * \param index the index of the last address. + */ + void SetIndexStop (uint8_t index); + + /** + * \return the last (inclusive) index of the address in the corresponding * PbbAddressBlock that this TLV applies to. * * Calling this while HasIndexStop is False is undefined. Make sure you * check it first. This will be checked by an assert in debug builds. */ uint8_t GetIndexStop (void) const; + + /** + * \brief Tests whether or not this address TLV has a stop index. + * \return true if this address TLV has a stop index, false otherwise. + * + * This should be called before calling GetIndexStop to make sure there + * actually is one. + */ bool HasIndexStop (void) const; + /** + * \brief Sets whether or not this address TLV is "multivalue" + * \param isMultivalue whether or not this address TLV should be multivalue. + * + * If true, this means the value associated with this TLV should be divided + * evenly into (GetIndexStop() - GetIndexStart() + 1) values. Otherwise, the + * value is one single value that applies to each address in the range. + */ void SetMultivalue (bool isMultivalue); + + /** + * \brief Tests whether or not this address TLV is "multivalue" + * \return whether this address TLV is multivalue or not. + */ bool IsMultivalue (void) const; }; From 7d7681d6bcc0dae315b6d1d0af482d1381d975df Mon Sep 17 00:00:00 2001 From: Tom Wambold Date: Fri, 11 Sep 2009 11:52:47 -0400 Subject: [PATCH 09/12] PacketBB: Moved from src/contrib to src/node. --- src/{contrib => node}/packetbb.cc | 0 src/{contrib => node}/packetbb.h | 0 src/{contrib => node}/test-packetbb.cc | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename src/{contrib => node}/packetbb.cc (100%) rename src/{contrib => node}/packetbb.h (100%) rename src/{contrib => node}/test-packetbb.cc (100%) diff --git a/src/contrib/packetbb.cc b/src/node/packetbb.cc similarity index 100% rename from src/contrib/packetbb.cc rename to src/node/packetbb.cc diff --git a/src/contrib/packetbb.h b/src/node/packetbb.h similarity index 100% rename from src/contrib/packetbb.h rename to src/node/packetbb.h diff --git a/src/contrib/test-packetbb.cc b/src/node/test-packetbb.cc similarity index 100% rename from src/contrib/test-packetbb.cc rename to src/node/test-packetbb.cc From bf9984d28ac8a0dce8dee417165b0a205699e368 Mon Sep 17 00:00:00 2001 From: Tom Wambold Date: Fri, 11 Sep 2009 12:00:38 -0400 Subject: [PATCH 10/12] PacketBB: Removed unnecessary forward declarations. --- src/contrib/wscript | 2 -- src/node/packetbb.h | 3 --- src/node/wscript | 2 ++ 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/contrib/wscript b/src/contrib/wscript index f63225935..046958dda 100644 --- a/src/contrib/wscript +++ b/src/contrib/wscript @@ -30,7 +30,6 @@ def build(bld): 'attribute-default-iterator.cc', 'file-config.cc', 'raw-text-config.cc', - 'packetbb.cc', ] headers = bld.new_task_gen('ns3header') @@ -42,7 +41,6 @@ def build(bld): 'file-config.h', 'config-store.h', 'flow-id-tag.h', - 'packetbb.h', ] if bld.env['ENABLE_GTK_CONFIG_STORE']: diff --git a/src/node/packetbb.h b/src/node/packetbb.h index aaffcb018..fd5ee6570 100644 --- a/src/node/packetbb.h +++ b/src/node/packetbb.h @@ -35,11 +35,8 @@ namespace ns3 { /* Forward declare objects */ -class PbbPacket; class PbbMessage; class PbbAddressBlock; -class PbbTlvBlock; -class PbbAddressTlvBlock; class PbbTlv; class PbbAddressTlv; diff --git a/src/node/wscript b/src/node/wscript index 1430e63ef..416db3879 100644 --- a/src/node/wscript +++ b/src/node/wscript @@ -45,6 +45,7 @@ def build(bld): 'ipv6.cc', 'ipv6-raw-socket-factory.cc', 'ipv6-routing-protocol.cc', + 'packetbb.cc', ] headers = bld.new_task_gen('ns3header') @@ -91,4 +92,5 @@ def build(bld): 'ipv6.h', 'ipv6-raw-socket-factory.h', 'ipv6-routing-protocol.h', + 'packetbb.h', ] From 0785e918e2d932889edb25d50c79821cd2fdecf7 Mon Sep 17 00:00:00 2001 From: Tom Wambold Date: Fri, 11 Sep 2009 12:11:23 -0400 Subject: [PATCH 11/12] PacketBB: A bit more documentation. --- src/node/packetbb.cc | 7 +++---- src/node/packetbb.h | 17 ++++++++++------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/node/packetbb.cc b/src/node/packetbb.cc index 0b5a92a36..4eeb13356 100644 --- a/src/node/packetbb.cc +++ b/src/node/packetbb.cc @@ -18,10 +18,9 @@ * * Author: Tom Wambold */ -/* TODO: - * - Check style - * - Check copy constructors - */ +/* These classes implement RFC 5444 - The Generalized Mobile Ad Hoc Network + * (MANET) Packet/PbbMessage Format + * See: http://tools.ietf.org/html/rfc5444 for details */ #include "ns3/ipv4-address.h" #include "ns3/ipv6-address.h" diff --git a/src/node/packetbb.h b/src/node/packetbb.h index fd5ee6570..45e720ece 100644 --- a/src/node/packetbb.h +++ b/src/node/packetbb.h @@ -47,7 +47,7 @@ enum PbbAddressLength { }; /** - * \brief A block of Packet or PbbMessage TLVs. + * \brief A block of packet or message TLVs (PbbTlv). * * Acts similar to a C++ STL container. Should not be used for Address TLVs. */ @@ -196,7 +196,7 @@ private: }; /** - * \brief A block of Address TLVs. + * \brief A block of Address TLVs (PbbAddressTlv). * * Acts similar to a C++ STL container. */ @@ -349,6 +349,9 @@ private: /** * \brief Main PacketBB Packet object. * + * A PacketBB packet is made up of zero or more packet TLVs (PbbTlv), and zero + * or more messages (PbbMessage). + * * See: http://tools.ietf.org/html/rfc5444 for details. */ class PbbPacket : public Header @@ -640,9 +643,9 @@ private: /** * \brief A message within a PbbPacket packet. * - * There may be any number of messages in one PbbPacket packet. - * This is a pure virutal base class, you should instantiate either PbbMessageIpv4 - * or PbbMessageIpv6. + * There may be any number of messages in one packet packet. This is a pure + * virutal base class, when creating a message, you should instantiate either + * PbbMessageIpv4 or PbbMessageIpv6. */ class PbbMessage { @@ -1075,8 +1078,8 @@ protected: /** * \brief An Address Block and its associated Address TLV Blocks. * - * This is a pure virtual base class, you should instantiate either - * PbbAddressBlockIpv4 or PbbAddressBlockIpv6. + * This is a pure virtual base class, when creating address blocks, you should + * instantiate either PbbAddressBlockIpv4 or PbbAddressBlockIpv6. */ class PbbAddressBlock { From 124ed7e91b7f960fd04899387290d946026eab40 Mon Sep 17 00:00:00 2001 From: Tom Wambold Date: Fri, 11 Sep 2009 12:16:21 -0400 Subject: [PATCH 12/12] PacketBB: Typo in comment. --- src/node/packetbb.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/node/packetbb.h b/src/node/packetbb.h index 45e720ece..5802f43af 100644 --- a/src/node/packetbb.h +++ b/src/node/packetbb.h @@ -644,7 +644,7 @@ private: * \brief A message within a PbbPacket packet. * * There may be any number of messages in one packet packet. This is a pure - * virutal base class, when creating a message, you should instantiate either + * virtual base class, when creating a message, you should instantiate either * PbbMessageIpv4 or PbbMessageIpv6. */ class PbbMessage