25 #include "ns3/ipv4-address.h"
26 #include "ns3/ipv6-address.h"
27 #include "ns3/assert.h"
33 static const uint8_t VERSION = 0;
35 static const uint8_t PHAS_SEQ_NUM = 0x8;
36 static const uint8_t PHAS_TLV = 0x4;
39 static const uint8_t MHAS_ORIG = 0x80;
40 static const uint8_t MHAS_HOP_LIMIT = 0x40;
41 static const uint8_t MHAS_HOP_COUNT = 0x20;
42 static const uint8_t MHAS_SEQ_NUM = 0x10;
45 static const uint8_t AHAS_HEAD = 0x80;
46 static const uint8_t AHAS_FULL_TAIL = 0x40;
47 static const uint8_t AHAS_ZERO_TAIL = 0x20;
48 static const uint8_t AHAS_SINGLE_PRE_LEN = 0x10;
49 static const uint8_t AHAS_MULTI_PRE_LEN = 0x08;
52 static const uint8_t THAS_TYPE_EXT = 0x80;
53 static const uint8_t THAS_SINGLE_INDEX = 0x40;
54 static const uint8_t THAS_MULTI_INDEX = 0x20;
55 static const uint8_t THAS_VALUE = 0x10;
56 static const uint8_t THAS_EXT_LEN = 0x08;
57 static const uint8_t TIS_MULTIVALUE = 0x04;
61 NS_OBJECT_ENSURE_REGISTERED (PbbPacket);
63 PbbTlvBlock::PbbTlvBlock (
void)
69 PbbTlvBlock::~PbbTlvBlock (
void)
79 return m_tlvList.begin ();
82 PbbTlvBlock::ConstIterator
86 return m_tlvList.begin ();
93 return m_tlvList.end ();
96 PbbTlvBlock::ConstIterator
100 return m_tlvList.end ();
107 return m_tlvList.size ();
114 return m_tlvList.empty ();
121 return m_tlvList.front ();
128 return m_tlvList.back ();
135 m_tlvList.push_front (tlv);
142 m_tlvList.pop_front ();
149 m_tlvList.push_back (tlv);
156 m_tlvList.pop_back ();
159 PbbTlvBlock::Iterator
163 return m_tlvList.insert (position, tlv);
166 PbbTlvBlock::Iterator
170 return m_tlvList.erase (position);
173 PbbTlvBlock::Iterator
177 return m_tlvList.erase (first, last);
184 for (Iterator iter =
Begin (); iter !=
End (); iter++)
197 for (ConstIterator iter =
Begin (); iter !=
End (); iter++)
199 size += (*iter)->GetSerializedSize ();
218 for (ConstIterator iter =
Begin (); iter !=
End (); iter++)
220 (*iter)->Serialize (start);
239 newtlv->Deserialize (start);
256 std::string prefix =
"";
257 for (
int i = 0; i < level; i++)
259 prefix.append (
"\t");
262 os << prefix <<
"TLV Block {" << std::endl;
263 os << prefix <<
"\tsize = " <<
Size () << std::endl;
264 os << prefix <<
"\tmembers [" << std::endl;
266 for (ConstIterator iter =
Begin (); iter !=
End (); iter++)
268 (*iter)->Print (os, level+2);
271 os << prefix <<
"\t]" << std::endl;
272 os << prefix <<
"}" << std::endl;
276 PbbTlvBlock::operator== (
const PbbTlvBlock &other)
const
283 ConstIterator ti, oi;
285 ti !=
End () && oi != other.
End ();
297 PbbTlvBlock::operator!= (
const PbbTlvBlock &other)
const
299 return !(*
this == other);
304 PbbAddressTlvBlock::PbbAddressTlvBlock (
void)
310 PbbAddressTlvBlock::~PbbAddressTlvBlock (
void)
316 PbbAddressTlvBlock::Iterator
320 return m_tlvList.begin ();
323 PbbAddressTlvBlock::ConstIterator
327 return m_tlvList.begin ();
330 PbbAddressTlvBlock::Iterator
334 return m_tlvList.end ();
337 PbbAddressTlvBlock::ConstIterator
341 return m_tlvList.end ();
348 return m_tlvList.size ();
355 return m_tlvList.empty ();
362 return m_tlvList.front ();
369 return m_tlvList.back ();
376 m_tlvList.push_front (tlv);
383 m_tlvList.pop_front ();
390 m_tlvList.push_back (tlv);
397 m_tlvList.pop_back ();
400 PbbAddressTlvBlock::Iterator
404 return m_tlvList.insert (position, tlv);
407 PbbAddressTlvBlock::Iterator
411 return m_tlvList.erase (position);
414 PbbAddressTlvBlock::Iterator
418 return m_tlvList.erase (first, last);
425 for (Iterator iter =
Begin (); iter !=
End (); iter++)
438 for (ConstIterator iter =
Begin (); iter !=
End (); iter++)
440 size += (*iter)->GetSerializedSize ();
459 for (ConstIterator iter =
Begin (); iter !=
End (); iter++)
461 (*iter)->Serialize (start);
480 newtlv->Deserialize (start);
497 std::string prefix =
"";
498 for (
int i = 0; i < level; i++)
500 prefix.append (
"\t");
503 os << prefix <<
"TLV Block {" << std::endl;
504 os << prefix <<
"\tsize = " <<
Size () << std::endl;
505 os << prefix <<
"\tmembers [" << std::endl;
507 for (ConstIterator iter =
Begin (); iter !=
End (); iter++)
509 (*iter)->Print (os, level+2);
512 os << prefix <<
"\t]" << std::endl;
513 os << prefix <<
"}" << std::endl;
524 ConstIterator it, ot;
526 it !=
End () && ot != other.
End ();
538 PbbAddressTlvBlock::operator!= (
const PbbAddressTlvBlock &other)
const
540 return !(*
this == other);
546 PbbPacket::PbbPacket (
void)
553 PbbPacket::~PbbPacket (
void)
591 PbbPacket::TlvIterator
595 return m_tlvList.
Begin ();
598 PbbPacket::ConstTlvIterator
602 return m_tlvList.
Begin ();
605 PbbPacket::TlvIterator
609 return m_tlvList.
End ();
612 PbbPacket::ConstTlvIterator
616 return m_tlvList.
End ();
623 return m_tlvList.
Size ();
630 return m_tlvList.
Empty ();
637 return m_tlvList.
Front ();
644 return m_tlvList.
Front ();
651 return m_tlvList.
Back ();
658 return m_tlvList.
Back ();
689 PbbPacket::TlvIterator
693 return m_tlvList.
Erase (position);
696 PbbPacket::TlvIterator
700 return m_tlvList.
Erase (first, last);
712 PbbPacket::MessageIterator
716 return m_messageList.begin ();
719 PbbPacket::ConstMessageIterator
723 return m_messageList.begin ();
726 PbbPacket::MessageIterator
730 return m_messageList.end ();
733 PbbPacket::ConstMessageIterator
737 return m_messageList.end ();
744 return m_messageList.size ();
751 return m_messageList.empty ();
758 return m_messageList.front ();
765 return m_messageList.front ();
772 return m_messageList.back ();
779 return m_messageList.back ();
786 m_messageList.push_front (tlv);
793 m_messageList.pop_front ();
800 m_messageList.push_back (tlv);
807 m_messageList.pop_back ();
810 PbbPacket::MessageIterator
814 return m_messageList.erase (position);
817 PbbPacket::MessageIterator
819 PbbPacket::MessageIterator last)
822 return m_messageList.erase (first, last);
833 m_messageList.clear ();
838 PbbPacket::GetTypeId (
void)
842 .AddConstructor<PbbPacket> ()
874 size += (*iter)->GetSerializedSize ();
889 uint8_t flags = VERSION;
895 flags |= PHAS_SEQ_NUM;
911 (*iter)->Serialize (start);
921 uint8_t flags = start.
ReadU8 ();
923 if (flags & PHAS_SEQ_NUM)
928 if (flags & PHAS_TLV)
933 while (!start.
IsEnd ())
953 os <<
"PbbPacket {" << std::endl;
962 m_tlvList.
Print (os, 1);
968 (*iter)->Print (os, 1);
971 os <<
"}" << std::endl;
975 PbbPacket::operator== (
const PbbPacket &other)
const
993 if (m_tlvList != other.m_tlvList)
1003 ConstMessageIterator tmi, omi;
1017 PbbPacket::operator!= (
const PbbPacket &other)
const
1019 return !(*
this == other);
1024 PbbMessage::PbbMessage ()
1029 m_hasOriginatorAddress =
false;
1030 m_hasHopLimit =
false;
1031 m_hasHopCount =
false;
1032 m_hasSequenceNumber =
false;
1035 PbbMessage::~PbbMessage ()
1056 PbbMessage::GetAddressLength (
void)
const
1066 m_originatorAddress = address;
1067 m_hasOriginatorAddress =
true;
1075 return m_originatorAddress;
1082 return m_hasOriginatorAddress;
1089 m_hopLimit = hopLimit;
1090 m_hasHopLimit =
true;
1105 return m_hasHopLimit;
1112 m_hopCount = hopCount;
1113 m_hasHopCount =
true;
1128 return m_hasHopCount;
1135 m_sequenceNumber = sequenceNumber;
1136 m_hasSequenceNumber =
true;
1144 return m_sequenceNumber;
1151 return m_hasSequenceNumber;
1156 PbbMessage::TlvIterator
1160 return m_tlvList.
Begin ();
1163 PbbMessage::ConstTlvIterator
1167 return m_tlvList.
Begin ();
1170 PbbMessage::TlvIterator
1174 return m_tlvList.
End ();
1177 PbbMessage::ConstTlvIterator
1181 return m_tlvList.
End ();
1188 return m_tlvList.
Size ();
1195 return m_tlvList.
Empty ();
1202 return m_tlvList.
Front ();
1209 return m_tlvList.
Front ();
1216 return m_tlvList.
Back ();
1223 return m_tlvList.
Back ();
1254 PbbMessage::TlvIterator
1258 return m_tlvList.
Erase (position);
1261 PbbMessage::TlvIterator
1265 return m_tlvList.
Erase (first, last);
1277 PbbMessage::AddressBlockIterator
1281 return m_addressBlockList.begin ();
1284 PbbMessage::ConstAddressBlockIterator
1288 return m_addressBlockList.begin ();
1291 PbbMessage::AddressBlockIterator
1295 return m_addressBlockList.end ();
1298 PbbMessage::ConstAddressBlockIterator
1302 return m_addressBlockList.end ();
1309 return m_addressBlockList.size ();
1316 return m_addressBlockList.empty ();
1323 return m_addressBlockList.front ();
1330 return m_addressBlockList.front ();
1337 return m_addressBlockList.back ();
1344 return m_addressBlockList.back ();
1351 m_addressBlockList.push_front (tlv);
1358 m_addressBlockList.pop_front ();
1365 m_addressBlockList.push_back (tlv);
1372 m_addressBlockList.pop_back ();
1375 PbbMessage::AddressBlockIterator
1379 return m_addressBlockList.erase (position);
1382 PbbMessage::AddressBlockIterator
1384 PbbMessage::AddressBlockIterator last)
1387 return m_addressBlockList.erase (first, last);
1400 return m_addressBlockList.clear ();
1412 size += GetAddressLength () + 1;
1436 size += (*iter)->GetSerializedSize ();
1456 flags = GetAddressLength ();
1464 SerializeOriginatorAddress (start);
1469 flags |= MHAS_HOP_LIMIT;
1475 flags |= MHAS_HOP_COUNT;
1481 flags |= MHAS_SEQ_NUM;
1493 (*iter)->Serialize (start);
1506 uint8_t addrlen = start.
ReadU8 ();
1511 addrlen = (addrlen & 0xf);
1519 newmsg = Create<PbbMessageIpv4> ();
1522 newmsg = Create<PbbMessageIpv6> ();
1528 newmsg->Deserialize (start);
1538 uint8_t flags = start.
ReadU8 ();
1542 if (flags & MHAS_ORIG)
1547 if (flags & MHAS_HOP_LIMIT)
1552 if (flags & MHAS_HOP_COUNT)
1557 if (flags & MHAS_SEQ_NUM)
1585 std::string prefix =
"";
1586 for (
int i = 0; i < level; i++)
1588 prefix.append (
"\t");
1591 os << prefix <<
"PbbMessage {" << std::endl;
1593 os << prefix <<
"\tmessage type = " << (int)
GetType () << std::endl;
1594 os << prefix <<
"\taddress size = " << GetAddressLength () << std::endl;
1598 os << prefix <<
"\toriginator address = ";
1599 PrintOriginatorAddress (os);
1605 os << prefix <<
"\thop limit = " << (int)
GetHopLimit () << std::endl;
1610 os << prefix <<
"\thop count = " << (int)
GetHopCount () << std::endl;
1618 m_tlvList.
Print (os, level+1);
1624 (*iter)->Print (os, level+1);
1626 os << prefix <<
"}" << std::endl;
1630 PbbMessage::operator== (
const PbbMessage &other)
const
1632 if (GetAddressLength () != other.GetAddressLength ())
1694 if (m_tlvList != other.m_tlvList)
1704 ConstAddressBlockIterator tai, oai;
1718 PbbMessage::operator!= (
const PbbMessage &other)
const
1720 return !(*
this == other);
1725 PbbMessageIpv4::PbbMessageIpv4 ()
1730 PbbMessageIpv4::~PbbMessageIpv4 ()
1736 PbbMessageIpv4::GetAddressLength (
void)
const
1743 PbbMessageIpv4::SerializeOriginatorAddress (Buffer::Iterator &start)
const
1746 uint8_t* buffer =
new uint8_t[GetAddressLength () + 1];
1748 start.Write (buffer, GetAddressLength () + 1);
1753 PbbMessageIpv4::DeserializeOriginatorAddress (Buffer::Iterator &start)
const
1756 uint8_t* buffer =
new uint8_t[GetAddressLength () + 1];
1757 start.Read (buffer, GetAddressLength () + 1);
1764 PbbMessageIpv4::PrintOriginatorAddress (std::ostream &os)
const
1770 Ptr<PbbAddressBlock>
1771 PbbMessageIpv4::AddressBlockDeserialize (Buffer::Iterator &start)
const
1774 Ptr<PbbAddressBlock> newab = Create<PbbAddressBlockIpv4> ();
1775 newab->Deserialize (start);
1781 PbbMessageIpv6::PbbMessageIpv6 ()
1786 PbbMessageIpv6::~PbbMessageIpv6 ()
1792 PbbMessageIpv6::GetAddressLength (
void)
const
1799 PbbMessageIpv6::SerializeOriginatorAddress (Buffer::Iterator &start)
const
1802 uint8_t* buffer =
new uint8_t[GetAddressLength () + 1];
1804 start.Write (buffer, GetAddressLength () + 1);
1809 PbbMessageIpv6::DeserializeOriginatorAddress (Buffer::Iterator &start)
const
1812 uint8_t* buffer =
new uint8_t[GetAddressLength () + 1];
1813 start.Read (buffer, GetAddressLength () + 1);
1820 PbbMessageIpv6::PrintOriginatorAddress (std::ostream &os)
const
1826 Ptr<PbbAddressBlock>
1827 PbbMessageIpv6::AddressBlockDeserialize (Buffer::Iterator &start)
const
1830 Ptr<PbbAddressBlock> newab = Create<PbbAddressBlockIpv6> ();
1831 newab->Deserialize (start);
1837 PbbAddressBlock::PbbAddressBlock ()
1842 PbbAddressBlock::~PbbAddressBlock ()
1849 PbbAddressBlock::AddressIterator
1853 return m_addressList.begin ();
1856 PbbAddressBlock::ConstAddressIterator
1860 return m_addressList.begin ();
1863 PbbAddressBlock::AddressIterator
1867 return m_addressList.end ();
1870 PbbAddressBlock::ConstAddressIterator
1874 return m_addressList.end ();
1881 return m_addressList.size ();
1888 return m_addressList.empty ();
1895 return m_addressList.front ();
1902 return m_addressList.back ();
1909 m_addressList.push_front (tlv);
1916 m_addressList.pop_front ();
1923 m_addressList.push_back (tlv);
1930 m_addressList.pop_back ();
1933 PbbAddressBlock::AddressIterator
1937 return m_addressList.erase (position);
1940 PbbAddressBlock::AddressIterator
1942 PbbAddressBlock::AddressIterator last)
1945 return m_addressList.erase (first, last);
1952 return m_addressList.clear ();
1957 PbbAddressBlock::PrefixIterator
1961 return m_prefixList.begin ();
1964 PbbAddressBlock::ConstPrefixIterator
1968 return m_prefixList.begin ();
1971 PbbAddressBlock::PrefixIterator
1975 return m_prefixList.end ();
1978 PbbAddressBlock::ConstPrefixIterator
1982 return m_prefixList.end ();
1989 return m_prefixList.size ();
1996 return m_prefixList.empty ();
2003 return m_prefixList.front ();
2010 return m_prefixList.back ();
2017 m_prefixList.push_front (prefix);
2024 m_prefixList.pop_front ();
2031 m_prefixList.push_back (prefix);
2038 m_prefixList.pop_back ();
2041 PbbAddressBlock::PrefixIterator
2045 return m_prefixList.insert (position, value);
2048 PbbAddressBlock::PrefixIterator
2052 return m_prefixList.erase (position);
2055 PbbAddressBlock::PrefixIterator
2059 return m_prefixList.erase (first, last);
2066 m_prefixList.clear ();
2071 PbbAddressBlock::TlvIterator
2075 return m_addressTlvList.
Begin ();
2078 PbbAddressBlock::ConstTlvIterator
2082 return m_addressTlvList.
Begin ();
2085 PbbAddressBlock::TlvIterator
2089 return m_addressTlvList.
End ();
2092 PbbAddressBlock::ConstTlvIterator
2096 return m_addressTlvList.
End ();
2103 return m_addressTlvList.
Size ();
2110 return m_addressTlvList.
Empty ();
2117 return m_addressTlvList.
Front ();
2124 return m_addressTlvList.
Front ();
2131 return m_addressTlvList.
Back ();
2138 return m_addressTlvList.
Back ();
2169 PbbAddressBlock::TlvIterator
2173 return m_addressTlvList.
Erase (position);
2176 PbbAddressBlock::TlvIterator
2178 PbbAddressBlock::TlvIterator last)
2181 return m_addressTlvList.
Erase (first, last);
2188 m_addressTlvList.
Clear ();
2203 uint8_t* head =
new uint8_t[GetAddressLength ()];
2204 uint8_t headlen = 0;
2205 uint8_t* tail =
new uint8_t[GetAddressLength ()];
2206 uint8_t taillen = 0;
2208 GetHeadTail (head, headlen, tail, taillen);
2212 size += 1 + headlen;
2218 if (!HasZeroTail (tail, taillen))
2225 size += (GetAddressLength () - headlen - taillen) *
AddressSize ();
2249 uint8_t* buf =
new uint8_t[GetAddressLength ()];
2251 start.
Write (buf, GetAddressLength ());
2256 flags |= AHAS_SINGLE_PRE_LEN;
2263 uint8_t* head =
new uint8_t[GetAddressLength ()];
2264 uint8_t* tail =
new uint8_t[GetAddressLength ()];
2265 uint8_t headlen = 0;
2266 uint8_t taillen = 0;
2268 GetHeadTail (head, headlen, tail, taillen);
2274 start.
Write (head, headlen);
2281 if (HasZeroTail (tail, taillen))
2283 flags |= AHAS_ZERO_TAIL;
2287 flags |= AHAS_FULL_TAIL;
2288 start.
Write (tail, taillen);
2292 if (headlen + taillen < GetAddressLength ())
2294 uint8_t* mid =
new uint8_t[GetAddressLength ()];
2295 for (PbbAddressBlock::ConstAddressIterator iter =
AddressBegin ();
2299 SerializeAddress (mid, iter);
2300 start.
Write (mid + headlen, GetAddressLength () - headlen - taillen);
2305 flags |= GetPrefixFlags ();
2326 uint8_t numaddr = start.
ReadU8 ();
2327 uint8_t flags = start.
ReadU8 ();
2331 uint8_t headlen = 0;
2332 uint8_t taillen = 0;
2333 uint8_t* addrtmp =
new uint8_t[GetAddressLength ()];
2334 memset (addrtmp, 0, GetAddressLength ());
2336 if (flags & AHAS_HEAD)
2338 headlen = start.
ReadU8 ();
2339 start.
Read (addrtmp, headlen);
2342 if ((flags & AHAS_FULL_TAIL) ^ (flags & AHAS_ZERO_TAIL))
2344 taillen = start.
ReadU8 ();
2346 if (flags & AHAS_FULL_TAIL)
2348 start.
Read (addrtmp + GetAddressLength () - taillen, taillen);
2352 for (
int i = 0; i < numaddr; i++)
2354 start.
Read (addrtmp + headlen, GetAddressLength () - headlen - taillen);
2358 if (flags & AHAS_SINGLE_PRE_LEN)
2362 else if (flags & AHAS_MULTI_PRE_LEN)
2364 for (
int i = 0; i < numaddr; i++)
2387 std::string prefix =
"";
2388 for (
int i = 0; i < level; i++)
2390 prefix.append (
"\t");
2393 os << prefix <<
"PbbAddressBlock {" << std::endl;
2394 os << prefix <<
"\taddresses = " << std::endl;
2399 os << prefix <<
"\t\t";
2400 PrintAddress (os, iter);
2404 os << prefix <<
"\tprefixes = " << std::endl;
2409 os << prefix <<
"\t\t" << (int)(*iter) << std::endl;
2412 m_addressTlvList.
Print (os, level+1);
2423 ConstAddressIterator tai, oai;
2439 ConstPrefixIterator tpi, opi;
2450 if (m_addressTlvList != other.m_addressTlvList)
2459 PbbAddressBlock::operator!= (
const PbbAddressBlock &other)
const
2461 return !(*
this == other);
2465 PbbAddressBlock::GetPrefixFlags (
void)
const
2474 return AHAS_SINGLE_PRE_LEN;
2477 return AHAS_MULTI_PRE_LEN;
2486 PbbAddressBlock::GetHeadTail (uint8_t *head, uint8_t &headlen,
2487 uint8_t *tail, uint8_t &taillen)
const
2490 << &tail << static_cast<uint32_t> (taillen));
2491 headlen = GetAddressLength ();
2495 uint8_t * buflast =
new uint8_t[GetAddressLength ()];
2496 uint8_t * bufcur =
new uint8_t[GetAddressLength ()];
2502 for (PbbAddressBlock::ConstAddressIterator iter =
AddressBegin ()++;
2506 SerializeAddress (bufcur, iter);
2509 for (i = 0; i < headlen; i++)
2511 if (buflast[i] != bufcur[i])
2519 if (headlen <= GetAddressLength () - 1)
2521 for (i = GetAddressLength () - 1;
2522 GetAddressLength () - 1 - i <= taillen && i > headlen;
2525 if (buflast[i] != bufcur[i])
2530 taillen = GetAddressLength () - 1 - i;
2532 else if (headlen == 0)
2543 memcpy (head, bufcur, headlen);
2544 memcpy (tail, bufcur + (GetAddressLength () - taillen), taillen);
2551 PbbAddressBlock::HasZeroTail (
const uint8_t *tail, uint8_t taillen)
const
2555 for (i = 0; i < taillen; i++)
2562 return i == taillen;
2567 PbbAddressBlockIpv4::PbbAddressBlockIpv4 ()
2572 PbbAddressBlockIpv4::~PbbAddressBlockIpv4 ()
2578 PbbAddressBlockIpv4::GetAddressLength (
void)
const
2585 PbbAddressBlockIpv4::SerializeAddress (uint8_t *buffer, ConstAddressIterator iter)
const
2592 PbbAddressBlockIpv4::DeserializeAddress (uint8_t *buffer)
const
2599 PbbAddressBlockIpv4::PrintAddress (std::ostream &os, ConstAddressIterator iter)
const
2607 PbbAddressBlockIpv6::PbbAddressBlockIpv6 ()
2612 PbbAddressBlockIpv6::~PbbAddressBlockIpv6 ()
2618 PbbAddressBlockIpv6::GetAddressLength (
void)
const
2625 PbbAddressBlockIpv6::SerializeAddress (uint8_t *buffer, ConstAddressIterator iter)
const
2632 PbbAddressBlockIpv6::DeserializeAddress (uint8_t *buffer)
const
2639 PbbAddressBlockIpv6::PrintAddress (std::ostream &os, ConstAddressIterator iter)
const
2647 PbbTlv::PbbTlv (
void)
2650 m_hasTypeExt =
false;
2651 m_hasIndexStart =
false;
2652 m_hasIndexStop =
false;
2653 m_isMultivalue =
false;
2657 PbbTlv::~PbbTlv (
void)
2681 m_typeExt = typeExt;
2682 m_hasTypeExt =
true;
2697 return m_hasTypeExt;
2701 PbbTlv::SetIndexStart (uint8_t index)
2704 m_indexStart = index;
2705 m_hasIndexStart =
true;
2709 PbbTlv::GetIndexStart (
void)
const
2713 return m_indexStart;
2717 PbbTlv::HasIndexStart (
void)
const
2720 return m_hasIndexStart;
2724 PbbTlv::SetIndexStop (uint8_t index)
2727 m_indexStop = index;
2728 m_hasIndexStop =
true;
2732 PbbTlv::GetIndexStop (
void)
const
2740 PbbTlv::HasIndexStop (
void)
const
2743 return m_hasIndexStop;
2747 PbbTlv::SetMultivalue (
bool isMultivalue)
2750 m_isMultivalue = isMultivalue;
2754 PbbTlv::IsMultivalue (
void)
const
2757 return m_isMultivalue;
2804 if (HasIndexStart ())
2809 if (HasIndexStop ())
2842 flags |= THAS_TYPE_EXT;
2846 if (HasIndexStart ())
2848 start.
WriteU8 (GetIndexStart ());
2850 if (HasIndexStop ())
2852 flags |= THAS_MULTI_INDEX;
2853 start.
WriteU8 (GetIndexStop ());
2857 flags |= THAS_SINGLE_INDEX;
2863 flags |= THAS_VALUE;
2868 flags |= THAS_EXT_LEN;
2876 if (IsMultivalue ())
2878 flags |= TIS_MULTIVALUE;
2893 uint8_t flags = start.
ReadU8 ();
2895 if (flags & THAS_TYPE_EXT)
2900 if (flags & THAS_MULTI_INDEX)
2902 SetIndexStart (start.
ReadU8 ());
2903 SetIndexStop (start.
ReadU8 ());
2905 else if (flags & THAS_SINGLE_INDEX)
2907 SetIndexStart (start.
ReadU8 ());
2910 if (flags & THAS_VALUE)
2914 if (flags & THAS_EXT_LEN)
2943 std::string prefix =
"";
2944 for (
int i = 0; i < level; i++)
2946 prefix.append (
"\t");
2949 os << prefix <<
"PbbTlv {" << std::endl;
2950 os << prefix <<
"\ttype = " << (int)
GetType () << std::endl;
2954 os << prefix <<
"\ttypeext = " << (int)
GetTypeExt () << std::endl;
2957 if (HasIndexStart ())
2959 os << prefix <<
"\tindexStart = " << (int)GetIndexStart () << std::endl;
2962 if (HasIndexStop ())
2964 os << prefix <<
"\tindexStop = " << (int)GetIndexStop () << std::endl;
2967 os << prefix <<
"\tisMultivalue = " << IsMultivalue () << std::endl;
2971 os << prefix <<
"\thas value; size = " <<
GetValue ().
GetSize () << std::endl;
2974 os << prefix <<
"}" << std::endl;
2978 PbbTlv::operator== (
const PbbTlv &other)
const
3007 if (tv.GetSize () != ov.GetSize ())
3014 if (memcmp (tv.PeekData (), ov.PeekData (), tv.GetSize ()) != 0)
3023 PbbTlv::operator!= (
const PbbTlv &other)
const
3025 return !(*
this == other);
3034 PbbTlv::SetIndexStart (index);
3041 return PbbTlv::GetIndexStart ();
3048 return PbbTlv::HasIndexStart ();
3055 PbbTlv::SetIndexStop (index);
3062 return PbbTlv::GetIndexStop ();
3069 return PbbTlv::HasIndexStop ();
3076 PbbTlv::SetMultivalue (isMultivalue);
3083 return PbbTlv::IsMultivalue ();
PrefixIterator PrefixEnd(void)
AddressBlockIterator AddressBlockEnd()
static Ipv4Address Deserialize(const uint8_t buf[4])
void Print(std::ostream &os) const
Pretty-prints the contents of this message.
void TlvPushBack(Ptr< PbbTlv > tlv)
Appends a packet TLV to the back of this packet.
void AddressBlockPushBack(Ptr< PbbAddressBlock > block)
Appends an address block to the front of this message.
TlvIterator TlvBegin(void)
smart pointer class similar to boost::intrusive_ptr
#define NS_LOG_FUNCTION(parameters)
void MessagePushFront(Ptr< PbbMessage > message)
Prepends a message to the front of this packet.
Ptr< PbbMessage > MessageBack(void)
void PushFront(Ptr< PbbTlv > tlv)
Prepends a TLV to the front of this block.
uint16_t GetSequenceNumber(void) const
void RemoveAtEnd(uint32_t end)
Main PacketBB Packet object.
void MessagePushBack(Ptr< PbbMessage > message)
Appends a message to the back of this packet.
void PopFront(void)
Removes an AddressTLV from the front of this block.
uint32_t GetSerializedSize(void) const
void PushFront(Ptr< PbbAddressTlv > tlv)
Prepends an Address TLV to the front of this block.
void SetSequenceNumber(uint16_t number)
Sets the sequence number of this packet.
static Ipv6Address Deserialize(const uint8_t buf[16])
Deserialize this address.
bool HasSequenceNumber(void) const
Tests whether or not this message has a sequence number.
automatically resized byte buffer
int PrefixSize(void) const
void AddressBlockPopBack(void)
Removes an address block from the back of this message.
void SetIndexStop(uint8_t index)
Sets the index of the last address in the associated address block that this address TLV applies to...
bool TlvEmpty(void) const
#define NS_ASSERT(condition)
void TlvPushFront(Ptr< PbbTlv > tlv)
Prepends a packet TLV to the front of this packet.
#define NS_LOG_COMPONENT_DEFINE(name)
Ptr< PbbAddressBlock > AddressBlockBack(void)
void PrefixPopBack(void)
Removes a prefix from the back of this block.
bool HasTypeExt(void) const
Tests whether or not this TLV has a type extension.
AddressIterator AddressEnd(void)
void SetMultivalue(bool isMultivalue)
Sets whether or not this address TLV is "multivalue".
A message within a PbbPacket packet.
void MessageClear(void)
Removes all messages from this packet.
void PushBack(Ptr< PbbTlv > tlv)
Appends a TLV to the back of this block.
Ptr< PbbAddressTlv > Back(void) const
void Print(std::ostream &os) const
Pretty-prints the contents of this block.
bool HasIndexStart(void) const
Tests whether or not this address TLV has a start index.
bool HasIndexStop(void) const
Tests whether or not this address TLV has a stop index.
void MessagePopFront(void)
Removes a message from the front of this packet.
void SetSequenceNumber(uint16_t seqnum)
Sets the sequence number of this message.
void TlvPopBack(void)
Removes a message TLV from the back of this message.
uint8_t GetIndexStart(void) const
Ptr< PbbAddressTlv > TlvFront(void)
bool IsMultivalue(void) const
Tests whether or not this address TLV is "multivalue".
uint32_t GetDistanceFrom(Iterator const &o) const
Ptr< PbbTlv > TlvBack(void)
iterator in a Buffer instance
a polymophic address class
MessageIterator MessageEnd(void)
AddressBlockIterator AddressBlockBegin()
void SetType(uint8_t type)
Sets the type of this TLV.
void PopBack(void)
Removes an Address TLV from the back of this block.
bool TlvEmpty(void) const
bool AddressEmpty(void) const
void AddressBlockClear(void)
Removes all address blocks from this message.
Address GetOriginatorAddress(void) const
uint8_t GetTypeExt(void) const
void TlvPushFront(Ptr< PbbAddressTlv > address)
Prepends an address TLV to the front of this message.
Iterator Erase(Iterator position)
Removes the Address TLV at the specified position.
void AddressPopFront(void)
Removes an address from the front of this block.
TlvIterator TlvBegin(void)
TlvIterator Erase(TlvIterator position)
Removes the packet TLV at the specified position.
void SetIndexStart(uint8_t index)
Sets the index of the first address in the associated address block that this address TLV applies to...
Ptr< PbbAddressTlv > TlvBack(void)
uint8_t GetVersion(void) const
void PushBack(Ptr< PbbAddressTlv > tlv)
Appends an Address TLV to the back of this block.
void SetType(uint8_t type)
Sets the type for this message.
void Serialize(Buffer::Iterator &start) const
Serializes this message into the specified buffer.
void TlvPopBack(void)
Removes an address TLV from the back of this message.
uint16_t GetSequenceNumber(void) const
int MessageSize(void) const
void AddressPushBack(Address address)
Appends an address to the back of this block.
void WriteHtonU16(uint16_t data)
Address AddressFront(void) const
void TlvClear(void)
Removes all message TLVs from this block.
Ptr< PbbAddressBlock > AddressBlockFront(void)
bool TlvEmpty(void) const
uint8_t PrefixBack(void) const
Ptr< PbbTlv > Front(void) const
bool HasHopCount(void) const
Tests whether or not this message has a hop count.
uint8_t GetType(void) const
void Print(std::ostream &os) const
Print this address to the given output stream.
Ptr< PbbTlv > Back(void) const
void Serialize(uint8_t buf[4]) const
void Deserialize(Buffer::Iterator &start)
Deserializes a block from the specified buffer.
uint32_t GetSerializedSize(void) const
void Print(std::ostream &os) const
Print this address to the given output stream.
int AddressBlockSize(void) const
void Deserialize(Buffer::Iterator &start)
Deserializes a block from the specified buffer.
virtual uint32_t GetSerializedSize(void) const
Buffer::Iterator Begin(void) const
void Deserialize(Buffer::Iterator &start)
Deserializes a message from the specified buffer.
void TlvPopFront(void)
Removes a message TLV from the front of this message.
bool HasValue(void) const
Tests whether or not this TLV has a value.
void Deserialize(Buffer::Iterator &start)
Deserializes a TLV from the specified buffer.
void TlvPopBack(void)
Removes a packet TLV from the back of this block.
void SetHopLimit(uint8_t hoplimit)
Sets the maximum number of hops this message should travel.
bool HasOriginatorAddress(void) const
Tests whether or not this message has an originator address.
uint8_t PrefixFront(void) const
void PrefixPushFront(uint8_t prefix)
Prepends a prefix to the front of this block.
bool HasHopLimit(void) const
Tests whether or not this message has a hop limit.
AddressBlockIterator AddressBlockErase(AddressBlockIterator position)
Removes the address block at the specified position.
void Serialize(Buffer::Iterator &start) const
Serializes this address block into the specified buffer.
void Print(std::ostream &os) const
Pretty-prints the contents of this TLV.
void Print(std::ostream &os) const
Pretty-prints the contents of this address block.
void TlvClear(void)
Removes all address TLVs from this block.
uint32_t GetSerializedSize(void) const
void PrefixPushBack(uint8_t prefix)
Appends a prefix to the back of this block.
void Read(uint8_t *buffer, uint32_t size)
void AddressBlockPopFront(void)
Removes an address block from the front of this message.
A block of packet or message TLVs (PbbTlv).
uint8_t GetType(void) const
bool MessageEmpty(void) const
uint32_t GetSize(void) const
uint8_t GetIndexStop(void) const
void Print(std::ostream &os) const
Pretty-prints the contents of this block.
void TlvPushBack(Ptr< PbbAddressTlv > address)
Appends an address TLV to the back of this message.
int AddressSize(void) const
A block of Address TLVs (PbbAddressTlv).
uint8_t GetHopCount(void) const
bool HasSequenceNumber(void) const
Tests whether or not this packet has a sequence number.
void PopBack(void)
Removes a TLV from the back of this block.
void TlvPopFront(void)
Removes a packet TLV from the front of this packet.
uint8_t GetHopLimit(void) const
void WriteU8(uint8_t data)
PrefixIterator PrefixInsert(PrefixIterator position, const uint8_t value)
Inserts a prefix at the specified position in this block.
Ptr< PbbTlv > TlvBack(void)
TlvIterator TlvErase(TlvIterator position)
Removes the message TLV at the specified position.
uint32_t GetSerializedSize(void) const
void AddressBlockPushFront(Ptr< PbbAddressBlock > block)
Prepends an address block to the front of this message.
void MessagePopBack(void)
Removes a message from the back of this packet.
Ptr< PbbTlv > TlvFront(void)
Iterator Insert(Iterator position, const Ptr< PbbAddressTlv > tlv)
Inserts an Address TLV at the specified position in this block.
void SetTypeExt(uint8_t type)
Sets the type extension of this TLV.
AddressIterator AddressBegin(void)
void AddressClear(void)
Removes all addresses from this block.
void SetHopCount(uint8_t hopcount)
Sets the current number of hops this message has traveled.
Ptr< PbbTlv > TlvFront(void)
void PrefixPopFront(void)
Removes a prefix from the front of this block.
Address AddressBack(void) const
void Write(uint8_t const *buffer, uint32_t size)
PrefixIterator PrefixErase(PrefixIterator position)
Removes the prefix at the specified position.
void Serialize(Buffer::Iterator &start) const
Serializes this block into the specified buffer.
void SetOriginatorAddress(Address address)
Sets the address for the node that created this packet.
uint32_t GetSerializedSize(void) const
void Deserialize(Buffer::Iterator &start)
Deserializes an address block from the specified buffer.
Iterator Insert(Iterator position, const Ptr< PbbTlv > tlv)
Inserts a TLV at the specified position in this block.
void TlvPopFront(void)
Removes an address TLV from the front of this message.
static Ipv4Address ConvertFrom(const Address &address)
bool AddAtStart(uint32_t start)
Buffer GetValue(void) const
void Clear(void)
Removes all Address TLVs from this block.
void SetValue(Buffer start)
Sets the value of this message to the specified buffer.
PrefixIterator PrefixBegin(void)
virtual void Print(std::ostream &os) const
Pretty-prints the contents of this block.
Ptr< PbbMessage > MessageFront(void)
void TlvPushFront(Ptr< PbbTlv > tlv)
Prepends a message TLV to the front of this message.
MessageIterator MessageBegin(void)
uint16_t ReadNtohU16(void)
void Clear(void)
Removes all TLVs from this block.
AddressIterator AddressErase(AddressIterator position)
Removes the address at the specified position.
void AddressPopBack(void)
Removes an address from the back of this block.
void Serialize(Buffer::Iterator &start) const
Serializes this block into the specified buffer.
a unique identifier for an interface.
virtual void Serialize(Buffer::Iterator start) const
Serializes this packet into the specified buffer.
TypeId SetParent(TypeId tid)
static Ptr< PbbMessage > DeserializeMessage(Buffer::Iterator &start)
Deserializes a message, returning the correct object depending on whether it is an IPv4 message or an...
bool AddressBlockEmpty(void) const
An Address Block and its associated Address TLV Blocks.
void Serialize(Buffer::Iterator &start) const
Serializes this TLV into the specified buffer.
void TlvPushBack(Ptr< PbbTlv > tlv)
Appends a message TLV to the back of this message.
virtual TypeId GetInstanceTypeId(void) const
void AddressPushFront(Address address)
Prepends an address to the front of this block.
void PrefixClear(void)
Removes all prefixes from this block.
bool PrefixEmpty(void) const
Ptr< PbbAddressTlv > Front(void) const
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserializes a packet from the specified buffer.
static Ipv6Address ConvertFrom(const Address &address)
Convert the Address object into an Ipv6Address ones.
void TlvClear(void)
Removes all packet TLVs from this packet.
TlvIterator TlvErase(TlvIterator position)
Removes the address TLV at the specified position.
Iterator Erase(Iterator position)
Removes the TLV at the specified position.
void PopFront(void)
Removes a TLV from the front of this block.
void Serialize(uint8_t buf[16]) const
Serialize this address to a 16-byte buffer.