A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
packetbb.cc
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /* vim: set ts=2 sw=2 sta expandtab ai si cin: */
3 /*
4  * Copyright (c) 2009 Drexel University
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation;
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Author: Tom Wambold <tom5760@gmail.com>
20  */
21 /* These classes implement RFC 5444 - The Generalized Mobile Ad Hoc Network
22  * (MANET) Packet/PbbMessage Format
23  * See: http://tools.ietf.org/html/rfc5444 for details */
24 
25 #include "ns3/ipv4-address.h"
26 #include "ns3/ipv6-address.h"
27 #include "ns3/assert.h"
28 #include "ns3/log.h"
29 #include "packetbb.h"
30 
31 NS_LOG_COMPONENT_DEFINE ("PacketBB");
32 
33 static const uint8_t VERSION = 0;
34 /* Packet flags */
35 static const uint8_t PHAS_SEQ_NUM = 0x8;
36 static const uint8_t PHAS_TLV = 0x4;
37 
38 /* PbbMessage flags */
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;
43 
44 /* Address block flags */
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;
50 
51 /* TLV Flags */
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;
58 
59 namespace ns3 {
60 
61 NS_OBJECT_ENSURE_REGISTERED (PbbPacket);
62 
63 PbbTlvBlock::PbbTlvBlock (void)
64 {
65  NS_LOG_FUNCTION (this);
66  return;
67 }
68 
69 PbbTlvBlock::~PbbTlvBlock (void)
70 {
71  NS_LOG_FUNCTION (this);
72  Clear ();
73 }
74 
75 PbbTlvBlock::Iterator
77 {
78  NS_LOG_FUNCTION (this);
79  return m_tlvList.begin ();
80 }
81 
82 PbbTlvBlock::ConstIterator
83 PbbTlvBlock::Begin (void) const
84 {
85  NS_LOG_FUNCTION (this);
86  return m_tlvList.begin ();
87 }
88 
89 PbbTlvBlock::Iterator
91 {
92  NS_LOG_FUNCTION (this);
93  return m_tlvList.end ();
94 }
95 
96 PbbTlvBlock::ConstIterator
97 PbbTlvBlock::End (void) const
98 {
99  NS_LOG_FUNCTION (this);
100  return m_tlvList.end ();
101 }
102 
103 int
104 PbbTlvBlock::Size (void) const
105 {
106  NS_LOG_FUNCTION (this);
107  return m_tlvList.size ();
108 }
109 
110 bool
111 PbbTlvBlock::Empty (void) const
112 {
113  NS_LOG_FUNCTION (this);
114  return m_tlvList.empty ();
115 }
116 
118 PbbTlvBlock::Front (void) const
119 {
120  NS_LOG_FUNCTION (this);
121  return m_tlvList.front ();
122 }
123 
125 PbbTlvBlock::Back (void) const
126 {
127  NS_LOG_FUNCTION (this);
128  return m_tlvList.back ();
129 }
130 
131 void
133 {
134  NS_LOG_FUNCTION (this << tlv);
135  m_tlvList.push_front (tlv);
136 }
137 
138 void
140 {
141  NS_LOG_FUNCTION (this);
142  m_tlvList.pop_front ();
143 }
144 
145 void
147 {
148  NS_LOG_FUNCTION (this << tlv);
149  m_tlvList.push_back (tlv);
150 }
151 
152 void
154 {
155  NS_LOG_FUNCTION (this);
156  m_tlvList.pop_back ();
157 }
158 
159 PbbTlvBlock::Iterator
160 PbbTlvBlock::Insert (PbbTlvBlock::Iterator position, const Ptr<PbbTlv> tlv)
161 {
162  NS_LOG_FUNCTION (this << &position << tlv);
163  return m_tlvList.insert (position, tlv);
164 }
165 
166 PbbTlvBlock::Iterator
167 PbbTlvBlock::Erase (PbbTlvBlock::Iterator position)
168 {
169  NS_LOG_FUNCTION (this << &position);
170  return m_tlvList.erase (position);
171 }
172 
173 PbbTlvBlock::Iterator
174 PbbTlvBlock::Erase (PbbTlvBlock::Iterator first, PbbTlvBlock::Iterator last)
175 {
176  NS_LOG_FUNCTION (this << &first << &last);
177  return m_tlvList.erase (first, last);
178 }
179 
180 void
182 {
183  NS_LOG_FUNCTION (this);
184  for (Iterator iter = Begin (); iter != End (); iter++)
185  {
186  *iter = 0;
187  }
188  m_tlvList.clear ();
189 }
190 
191 uint32_t
193 {
194  NS_LOG_FUNCTION (this);
195  /* tlv size */
196  uint32_t size = 2;
197  for (ConstIterator iter = Begin (); iter != End (); iter++)
198  {
199  size += (*iter)->GetSerializedSize ();
200  }
201  return size;
202 }
203 
204 void
206 {
207  NS_LOG_FUNCTION (this << &start);
208  if (Empty ())
209  {
210  start.WriteHtonU16 (0);
211  return;
212  }
213 
214  /* We need to write the size of the TLV block in front, so save its
215  * position. */
216  Buffer::Iterator tlvsize = start;
217  start.Next (2);
218  for (ConstIterator iter = Begin (); iter != End (); iter++)
219  {
220  (*iter)->Serialize (start);
221  }
222  /* - 2 to not include the size field */
223  uint16_t size = start.GetDistanceFrom (tlvsize) - 2;
224  tlvsize.WriteHtonU16 (size);
225 }
226 
227 void
229 {
230  NS_LOG_FUNCTION (this << &start);
231  uint16_t size = start.ReadNtohU16 ();
232 
233  Buffer::Iterator tlvstart = start;
234  if (size > 0)
235  {
236  while (start.GetDistanceFrom (tlvstart) < size)
237  {
238  Ptr<PbbTlv> newtlv = Create<PbbTlv> ();
239  newtlv->Deserialize (start);
240  PushBack (newtlv);
241  }
242  }
243 }
244 
245 void
246 PbbTlvBlock::Print (std::ostream &os) const
247 {
248  NS_LOG_FUNCTION (this << &os);
249  Print (os, 0);
250 }
251 
252 void
253 PbbTlvBlock::Print (std::ostream &os, int level) const
254 {
255  NS_LOG_FUNCTION (this << &os << level);
256  std::string prefix = "";
257  for (int i = 0; i < level; i++)
258  {
259  prefix.append ("\t");
260  }
261 
262  os << prefix << "TLV Block {" << std::endl;
263  os << prefix << "\tsize = " << Size () << std::endl;
264  os << prefix << "\tmembers [" << std::endl;
265 
266  for (ConstIterator iter = Begin (); iter != End (); iter++)
267  {
268  (*iter)->Print (os, level+2);
269  }
270 
271  os << prefix << "\t]" << std::endl;
272  os << prefix << "}" << std::endl;
273 }
274 
275 bool
276 PbbTlvBlock::operator== (const PbbTlvBlock &other) const
277 {
278  if (Size () != other.Size ())
279  {
280  return false;
281  }
282 
283  ConstIterator ti, oi;
284  for (ti = Begin (), oi = other.Begin ();
285  ti != End () && oi != other.End ();
286  ti++, oi++)
287  {
288  if (**ti != **oi)
289  {
290  return false;
291  }
292  }
293  return true;
294 }
295 
296 bool
297 PbbTlvBlock::operator!= (const PbbTlvBlock &other) const
298 {
299  return !(*this == other);
300 }
301 
302 /* End PbbTlvBlock class */
303 
304 PbbAddressTlvBlock::PbbAddressTlvBlock (void)
305 {
306  NS_LOG_FUNCTION (this);
307  return;
308 }
309 
310 PbbAddressTlvBlock::~PbbAddressTlvBlock (void)
311 {
312  NS_LOG_FUNCTION (this);
313  Clear ();
314 }
315 
316 PbbAddressTlvBlock::Iterator
318 {
319  NS_LOG_FUNCTION (this);
320  return m_tlvList.begin ();
321 }
322 
323 PbbAddressTlvBlock::ConstIterator
325 {
326  NS_LOG_FUNCTION (this);
327  return m_tlvList.begin ();
328 }
329 
330 PbbAddressTlvBlock::Iterator
332 {
333  NS_LOG_FUNCTION (this);
334  return m_tlvList.end ();
335 }
336 
337 PbbAddressTlvBlock::ConstIterator
339 {
340  NS_LOG_FUNCTION (this);
341  return m_tlvList.end ();
342 }
343 
344 int
346 {
347  NS_LOG_FUNCTION (this);
348  return m_tlvList.size ();
349 }
350 
351 bool
353 {
354  NS_LOG_FUNCTION (this);
355  return m_tlvList.empty ();
356 }
357 
360 {
361  NS_LOG_FUNCTION (this);
362  return m_tlvList.front ();
363 }
364 
367 {
368  NS_LOG_FUNCTION (this);
369  return m_tlvList.back ();
370 }
371 
372 void
374 {
375  NS_LOG_FUNCTION (this << tlv);
376  m_tlvList.push_front (tlv);
377 }
378 
379 void
381 {
382  NS_LOG_FUNCTION (this);
383  m_tlvList.pop_front ();
384 }
385 
386 void
388 {
389  NS_LOG_FUNCTION (this << tlv);
390  m_tlvList.push_back (tlv);
391 }
392 
393 void
395 {
396  NS_LOG_FUNCTION (this);
397  m_tlvList.pop_back ();
398 }
399 
400 PbbAddressTlvBlock::Iterator
401 PbbAddressTlvBlock::Insert (PbbAddressTlvBlock::Iterator position, const Ptr<PbbAddressTlv> tlv)
402 {
403  NS_LOG_FUNCTION (this << &position << tlv);
404  return m_tlvList.insert (position, tlv);
405 }
406 
407 PbbAddressTlvBlock::Iterator
408 PbbAddressTlvBlock::Erase (PbbAddressTlvBlock::Iterator position)
409 {
410  NS_LOG_FUNCTION (this << &position);
411  return m_tlvList.erase (position);
412 }
413 
414 PbbAddressTlvBlock::Iterator
415 PbbAddressTlvBlock::Erase (PbbAddressTlvBlock::Iterator first, PbbAddressTlvBlock::Iterator last)
416 {
417  NS_LOG_FUNCTION (this << &first << &last);
418  return m_tlvList.erase (first, last);
419 }
420 
421 void
423 {
424  NS_LOG_FUNCTION (this);
425  for (Iterator iter = Begin (); iter != End (); iter++)
426  {
427  *iter = 0;
428  }
429  m_tlvList.clear ();
430 }
431 
432 uint32_t
434 {
435  NS_LOG_FUNCTION (this);
436  /* tlv size */
437  uint32_t size = 2;
438  for (ConstIterator iter = Begin (); iter != End (); iter++)
439  {
440  size += (*iter)->GetSerializedSize ();
441  }
442  return size;
443 }
444 
445 void
447 {
448  NS_LOG_FUNCTION (this << &start);
449  if (Empty ())
450  {
451  start.WriteHtonU16 (0);
452  return;
453  }
454 
455  /* We need to write the size of the TLV block in front, so save its
456  * position. */
457  Buffer::Iterator tlvsize = start;
458  start.Next (2);
459  for (ConstIterator iter = Begin (); iter != End (); iter++)
460  {
461  (*iter)->Serialize (start);
462  }
463  /* - 2 to not include the size field */
464  uint16_t size = start.GetDistanceFrom (tlvsize) - 2;
465  tlvsize.WriteHtonU16 (size);
466 }
467 
468 void
470 {
471  NS_LOG_FUNCTION (this << &start);
472  uint16_t size = start.ReadNtohU16 ();
473 
474  Buffer::Iterator tlvstart = start;
475  if (size > 0)
476  {
477  while (start.GetDistanceFrom (tlvstart) < size)
478  {
479  Ptr<PbbAddressTlv> newtlv = Create<PbbAddressTlv> ();
480  newtlv->Deserialize (start);
481  PushBack (newtlv);
482  }
483  }
484 }
485 
486 void
487 PbbAddressTlvBlock::Print (std::ostream &os) const
488 {
489  NS_LOG_FUNCTION (this << &os);
490  Print (os, 0);
491 }
492 
493 void
494 PbbAddressTlvBlock::Print (std::ostream &os, int level) const
495 {
496  NS_LOG_FUNCTION (this << &os << level);
497  std::string prefix = "";
498  for (int i = 0; i < level; i++)
499  {
500  prefix.append ("\t");
501  }
502 
503  os << prefix << "TLV Block {" << std::endl;
504  os << prefix << "\tsize = " << Size () << std::endl;
505  os << prefix << "\tmembers [" << std::endl;
506 
507  for (ConstIterator iter = Begin (); iter != End (); iter++)
508  {
509  (*iter)->Print (os, level+2);
510  }
511 
512  os << prefix << "\t]" << std::endl;
513  os << prefix << "}" << std::endl;
514 }
515 
516 bool
517 PbbAddressTlvBlock::operator== (const PbbAddressTlvBlock &other) const
518 {
519  if (Size () != other.Size ())
520  {
521  return false;
522  }
523 
524  ConstIterator it, ot;
525  for (it = Begin (), ot = other.Begin ();
526  it != End () && ot != other.End ();
527  it++, ot++)
528  {
529  if (**it != **ot)
530  {
531  return false;
532  }
533  }
534  return true;
535 }
536 
537 bool
538 PbbAddressTlvBlock::operator!= (const PbbAddressTlvBlock &other) const
539 {
540  return !(*this == other);
541 }
542 
543 
544 /* End PbbAddressTlvBlock Class */
545 
546 PbbPacket::PbbPacket (void)
547 {
548  NS_LOG_FUNCTION (this);
549  m_version = VERSION;
550  m_hasseqnum = false;
551 }
552 
553 PbbPacket::~PbbPacket (void)
554 {
555  NS_LOG_FUNCTION (this);
556  MessageClear ();
557 }
558 
559 uint8_t
561 {
562  NS_LOG_FUNCTION (this);
563  return m_version;
564 }
565 
566 void
568 {
569  NS_LOG_FUNCTION (this << number);
570  m_seqnum = number;
571  m_hasseqnum = true;
572 }
573 
574 uint16_t
576 {
577  NS_LOG_FUNCTION (this);
579  return m_seqnum;
580 }
581 
582 bool
584 {
585  NS_LOG_FUNCTION (this);
586  return m_hasseqnum;
587 }
588 
589 /* Manipulating Packet TLVs */
590 
591 PbbPacket::TlvIterator
593 {
594  NS_LOG_FUNCTION (this);
595  return m_tlvList.Begin ();
596 }
597 
598 PbbPacket::ConstTlvIterator
600 {
601  NS_LOG_FUNCTION (this);
602  return m_tlvList.Begin ();
603 }
604 
605 PbbPacket::TlvIterator
607 {
608  NS_LOG_FUNCTION (this);
609  return m_tlvList.End ();
610 }
611 
612 PbbPacket::ConstTlvIterator
613 PbbPacket::TlvEnd (void) const
614 {
615  NS_LOG_FUNCTION (this);
616  return m_tlvList.End ();
617 }
618 
619 int
620 PbbPacket::TlvSize (void) const
621 {
622  NS_LOG_FUNCTION (this);
623  return m_tlvList.Size ();
624 }
625 
626 bool
628 {
629  NS_LOG_FUNCTION (this);
630  return m_tlvList.Empty ();
631 }
632 
635 {
636  NS_LOG_FUNCTION (this);
637  return m_tlvList.Front ();
638 }
639 
640 const Ptr<PbbTlv>
642 {
643  NS_LOG_FUNCTION (this);
644  return m_tlvList.Front ();
645 }
646 
649 {
650  NS_LOG_FUNCTION (this);
651  return m_tlvList.Back ();
652 }
653 
654 const Ptr<PbbTlv>
655 PbbPacket::TlvBack (void) const
656 {
657  NS_LOG_FUNCTION (this);
658  return m_tlvList.Back ();
659 }
660 
661 void
663 {
664  NS_LOG_FUNCTION (this << tlv);
665  m_tlvList.PushFront (tlv);
666 }
667 
668 void
670 {
671  NS_LOG_FUNCTION (this);
672  m_tlvList.PopFront ();
673 }
674 
675 void
677 {
678  NS_LOG_FUNCTION (this << tlv);
679  m_tlvList.PushBack (tlv);
680 }
681 
682 void
684 {
685  NS_LOG_FUNCTION (this);
686  m_tlvList.PopBack ();
687 }
688 
689 PbbPacket::TlvIterator
690 PbbPacket::Erase (PbbPacket::TlvIterator position)
691 {
692  NS_LOG_FUNCTION (this << &position);
693  return m_tlvList.Erase (position);
694 }
695 
696 PbbPacket::TlvIterator
697 PbbPacket::Erase (PbbPacket::TlvIterator first, PbbPacket::TlvIterator last)
698 {
699  NS_LOG_FUNCTION (this << &first << &last);
700  return m_tlvList.Erase (first, last);
701 }
702 
703 void
705 {
706  NS_LOG_FUNCTION (this);
707  m_tlvList.Clear ();
708 }
709 
710 /* Manipulating Packet Messages */
711 
712 PbbPacket::MessageIterator
714 {
715  NS_LOG_FUNCTION (this);
716  return m_messageList.begin ();
717 }
718 
719 PbbPacket::ConstMessageIterator
721 {
722  NS_LOG_FUNCTION (this);
723  return m_messageList.begin ();
724 }
725 
726 PbbPacket::MessageIterator
728 {
729  NS_LOG_FUNCTION (this);
730  return m_messageList.end ();
731 }
732 
733 PbbPacket::ConstMessageIterator
735 {
736  NS_LOG_FUNCTION (this);
737  return m_messageList.end ();
738 }
739 
740 int
742 {
743  NS_LOG_FUNCTION (this);
744  return m_messageList.size ();
745 }
746 
747 bool
749 {
750  NS_LOG_FUNCTION (this);
751  return m_messageList.empty ();
752 }
753 
756 {
757  NS_LOG_FUNCTION (this);
758  return m_messageList.front ();
759 }
760 
761 const Ptr<PbbMessage>
763 {
764  NS_LOG_FUNCTION (this);
765  return m_messageList.front ();
766 }
767 
770 {
771  NS_LOG_FUNCTION (this);
772  return m_messageList.back ();
773 }
774 
775 const Ptr<PbbMessage>
777 {
778  NS_LOG_FUNCTION (this);
779  return m_messageList.back ();
780 }
781 
782 void
784 {
785  NS_LOG_FUNCTION (this << tlv);
786  m_messageList.push_front (tlv);
787 }
788 
789 void
791 {
792  NS_LOG_FUNCTION (this);
793  m_messageList.pop_front ();
794 }
795 
796 void
798 {
799  NS_LOG_FUNCTION (this << tlv);
800  m_messageList.push_back (tlv);
801 }
802 
803 void
805 {
806  NS_LOG_FUNCTION (this);
807  m_messageList.pop_back ();
808 }
809 
810 PbbPacket::MessageIterator
811 PbbPacket::Erase (PbbPacket::MessageIterator position)
812 {
813  NS_LOG_FUNCTION (this << &position);
814  return m_messageList.erase (position);
815 }
816 
817 PbbPacket::MessageIterator
818 PbbPacket::Erase (PbbPacket::MessageIterator first,
819  PbbPacket::MessageIterator last)
820 {
821  NS_LOG_FUNCTION (this << &first << &last);
822  return m_messageList.erase (first, last);
823 }
824 
825 void
827 {
828  NS_LOG_FUNCTION (this);
829  for (MessageIterator iter = MessageBegin (); iter != MessageEnd (); iter++)
830  {
831  *iter = 0;
832  }
833  m_messageList.clear ();
834 }
835 
836 
837 TypeId
838 PbbPacket::GetTypeId (void)
839 {
840  static TypeId tid = TypeId ("ns3::PbbPacket")
841  .SetParent<Header> ()
842  .AddConstructor<PbbPacket> ()
843  ;
844  return tid;
845 }
846 
847 TypeId
849 {
850  return GetTypeId ();
851 }
852 
853 uint32_t
855 {
856  NS_LOG_FUNCTION (this);
857  /* Version number + flags */
858  uint32_t size = 1;
859 
860  if (HasSequenceNumber ())
861  {
862  size += 2;
863  }
864 
865  if (!TlvEmpty ())
866  {
867  size += m_tlvList.GetSerializedSize ();
868  }
869 
870  for (ConstMessageIterator iter = MessageBegin ();
871  iter != MessageEnd ();
872  iter++)
873  {
874  size += (*iter)->GetSerializedSize ();
875  }
876 
877  return size;
878 }
879 
880 void
882 {
883  NS_LOG_FUNCTION (this << &start);
884  /* We remember the start, so we can write the flags after we check for a
885  * sequence number and TLV. */
886  Buffer::Iterator bufref = start;
887  start.Next ();
888 
889  uint8_t flags = VERSION;
890  /* Make room for 4 bit flags */
891  flags <<= 4;
892 
893  if (HasSequenceNumber ())
894  {
895  flags |= PHAS_SEQ_NUM;
896  start.WriteHtonU16 (GetSequenceNumber ());
897  }
898 
899  if (!TlvEmpty ())
900  {
901  flags |= PHAS_TLV;
902  m_tlvList.Serialize (start);
903  }
904 
905  bufref.WriteU8 (flags);
906 
907  for (ConstMessageIterator iter = MessageBegin ();
908  iter != MessageEnd ();
909  iter++)
910  {
911  (*iter)->Serialize (start);
912  }
913 }
914 
915 uint32_t
917 {
918  NS_LOG_FUNCTION (this << &start);
919  Buffer::Iterator begin = start;
920 
921  uint8_t flags = start.ReadU8 ();
922 
923  if (flags & PHAS_SEQ_NUM)
924  {
925  SetSequenceNumber (start.ReadNtohU16 ());
926  }
927 
928  if (flags & PHAS_TLV)
929  {
930  m_tlvList.Deserialize (start);
931  }
932 
933  while (!start.IsEnd ())
934  {
936  if (newmsg == 0)
937  {
938  return start.GetDistanceFrom (begin);
939  }
940  MessagePushBack (newmsg);
941  }
942 
943  flags >>= 4;
944  m_version = flags;
945 
946  return start.GetDistanceFrom (begin);
947 }
948 
949 void
950 PbbPacket::Print (std::ostream &os) const
951 {
952  NS_LOG_FUNCTION (this << &os);
953  os << "PbbPacket {" << std::endl;
954 
955  if (HasSequenceNumber ())
956  {
957  os << "\tsequence number = " << GetSequenceNumber ();
958  }
959 
960  os << std::endl;
961 
962  m_tlvList.Print (os, 1);
963 
964  for (ConstMessageIterator iter = MessageBegin ();
965  iter != MessageEnd ();
966  iter++)
967  {
968  (*iter)->Print (os, 1);
969  }
970 
971  os << "}" << std::endl;
972 }
973 
974 bool
975 PbbPacket::operator== (const PbbPacket &other) const
976 {
977  if (GetVersion () != other.GetVersion ())
978  {
979  return false;
980  }
981 
982  if (HasSequenceNumber () != other.HasSequenceNumber ())
983  {
984  return false;
985  }
986 
987  if (HasSequenceNumber ())
988  {
989  if (GetSequenceNumber () != other.GetSequenceNumber ())
990  return false;
991  }
992 
993  if (m_tlvList != other.m_tlvList)
994  {
995  return false;
996  }
997 
998  if (MessageSize () != other.MessageSize ())
999  {
1000  return false;
1001  }
1002 
1003  ConstMessageIterator tmi, omi;
1004  for (tmi = MessageBegin (), omi = other.MessageBegin ();
1005  tmi != MessageEnd () && omi != other.MessageEnd ();
1006  tmi++, omi++)
1007  {
1008  if (**tmi != **omi)
1009  {
1010  return false;
1011  }
1012  }
1013  return true;
1014 }
1015 
1016 bool
1017 PbbPacket::operator!= (const PbbPacket &other) const
1018 {
1019  return !(*this == other);
1020 }
1021 
1022 /* End PbbPacket class */
1023 
1024 PbbMessage::PbbMessage ()
1025 {
1026  NS_LOG_FUNCTION (this);
1027  /* Default to IPv4 */
1028  m_addrSize = IPV4;
1029  m_hasOriginatorAddress = false;
1030  m_hasHopLimit = false;
1031  m_hasHopCount = false;
1032  m_hasSequenceNumber = false;
1033 }
1034 
1035 PbbMessage::~PbbMessage ()
1036 {
1037  NS_LOG_FUNCTION (this);
1038  AddressBlockClear ();
1039 }
1040 
1041 void
1042 PbbMessage::SetType (uint8_t type)
1043 {
1044  NS_LOG_FUNCTION (this << static_cast<uint32_t> (type));
1045  m_type = type;
1046 }
1047 
1048 uint8_t
1050 {
1051  NS_LOG_FUNCTION (this);
1052  return m_type;
1053 }
1054 
1056 PbbMessage::GetAddressLength (void) const
1057 {
1058  NS_LOG_FUNCTION (this);
1059  return m_addrSize;
1060 }
1061 
1062 void
1064 {
1065  NS_LOG_FUNCTION (this << address);
1066  m_originatorAddress = address;
1067  m_hasOriginatorAddress = true;
1068 }
1069 
1070 Address
1072 {
1073  NS_LOG_FUNCTION (this);
1075  return m_originatorAddress;
1076 }
1077 
1078 bool
1080 {
1081  NS_LOG_FUNCTION (this);
1082  return m_hasOriginatorAddress;
1083 }
1084 
1085 void
1086 PbbMessage::SetHopLimit (uint8_t hopLimit)
1087 {
1088  NS_LOG_FUNCTION (this << static_cast<uint32_t> (hopLimit));
1089  m_hopLimit = hopLimit;
1090  m_hasHopLimit = true;
1091 }
1092 
1093 uint8_t
1095 {
1096  NS_LOG_FUNCTION (this);
1097  NS_ASSERT (HasHopLimit ());
1098  return m_hopLimit;
1099 }
1100 
1101 bool
1103 {
1104  NS_LOG_FUNCTION (this);
1105  return m_hasHopLimit;
1106 }
1107 
1108 void
1109 PbbMessage::SetHopCount (uint8_t hopCount)
1110 {
1111  NS_LOG_FUNCTION (this << static_cast<uint32_t> (hopCount));
1112  m_hopCount = hopCount;
1113  m_hasHopCount = true;
1114 }
1115 
1116 uint8_t
1118 {
1119  NS_LOG_FUNCTION (this);
1120  NS_ASSERT (HasHopCount ());
1121  return m_hopCount;
1122 }
1123 
1124 bool
1126 {
1127  NS_LOG_FUNCTION (this);
1128  return m_hasHopCount;
1129 }
1130 
1131 void
1132 PbbMessage::SetSequenceNumber (uint16_t sequenceNumber)
1133 {
1134  NS_LOG_FUNCTION (this << sequenceNumber);
1135  m_sequenceNumber = sequenceNumber;
1136  m_hasSequenceNumber = true;
1137 }
1138 
1139 uint16_t
1141 {
1142  NS_LOG_FUNCTION (this);
1144  return m_sequenceNumber;
1145 }
1146 
1147 bool
1149 {
1150  NS_LOG_FUNCTION (this);
1151  return m_hasSequenceNumber;
1152 }
1153 
1154 /* Manipulating PbbMessage TLVs */
1155 
1156 PbbMessage::TlvIterator
1158 {
1159  NS_LOG_FUNCTION (this);
1160  return m_tlvList.Begin ();
1161 }
1162 
1163 PbbMessage::ConstTlvIterator
1165 {
1166  NS_LOG_FUNCTION (this);
1167  return m_tlvList.Begin ();
1168 }
1169 
1170 PbbMessage::TlvIterator
1172 {
1173  NS_LOG_FUNCTION (this);
1174  return m_tlvList.End ();
1175 }
1176 
1177 PbbMessage::ConstTlvIterator
1179 {
1180  NS_LOG_FUNCTION (this);
1181  return m_tlvList.End ();
1182 }
1183 
1184 int
1186 {
1187  NS_LOG_FUNCTION (this);
1188  return m_tlvList.Size ();
1189 }
1190 
1191 bool
1193 {
1194  NS_LOG_FUNCTION (this);
1195  return m_tlvList.Empty ();
1196 }
1197 
1200 {
1201  NS_LOG_FUNCTION (this);
1202  return m_tlvList.Front ();
1203 }
1204 
1205 const Ptr<PbbTlv>
1207 {
1208  NS_LOG_FUNCTION (this);
1209  return m_tlvList.Front ();
1210 }
1211 
1214 {
1215  NS_LOG_FUNCTION (this);
1216  return m_tlvList.Back ();
1217 }
1218 
1219 const Ptr<PbbTlv>
1221 {
1222  NS_LOG_FUNCTION (this);
1223  return m_tlvList.Back ();
1224 }
1225 
1226 void
1228 {
1229  NS_LOG_FUNCTION (this << tlv);
1230  m_tlvList.PushFront (tlv);
1231 }
1232 
1233 void
1235 {
1236  NS_LOG_FUNCTION (this);
1237  m_tlvList.PopFront ();
1238 }
1239 
1240 void
1242 {
1243  NS_LOG_FUNCTION (this << tlv);
1244  m_tlvList.PushBack (tlv);
1245 }
1246 
1247 void
1249 {
1250  NS_LOG_FUNCTION (this);
1251  m_tlvList.PopBack ();
1252 }
1253 
1254 PbbMessage::TlvIterator
1255 PbbMessage::TlvErase (PbbMessage::TlvIterator position)
1256 {
1257  NS_LOG_FUNCTION (this << &position);
1258  return m_tlvList.Erase (position);
1259 }
1260 
1261 PbbMessage::TlvIterator
1262 PbbMessage::TlvErase (PbbMessage::TlvIterator first, PbbMessage::TlvIterator last)
1263 {
1264  NS_LOG_FUNCTION (this << &first << &last);
1265  return m_tlvList.Erase (first, last);
1266 }
1267 
1268 void
1270 {
1271  NS_LOG_FUNCTION (this);
1272  m_tlvList.Clear ();
1273 }
1274 
1275 /* Manipulating Address Block and Address TLV pairs */
1276 
1277 PbbMessage::AddressBlockIterator
1279 {
1280  NS_LOG_FUNCTION (this);
1281  return m_addressBlockList.begin ();
1282 }
1283 
1284 PbbMessage::ConstAddressBlockIterator
1286 {
1287  NS_LOG_FUNCTION (this);
1288  return m_addressBlockList.begin ();
1289 }
1290 
1291 PbbMessage::AddressBlockIterator
1293 {
1294  NS_LOG_FUNCTION (this);
1295  return m_addressBlockList.end ();
1296 }
1297 
1298 PbbMessage::ConstAddressBlockIterator
1300 {
1301  NS_LOG_FUNCTION (this);
1302  return m_addressBlockList.end ();
1303 }
1304 
1305 int
1307 {
1308  NS_LOG_FUNCTION (this);
1309  return m_addressBlockList.size ();
1310 }
1311 
1312 bool
1314 {
1315  NS_LOG_FUNCTION (this);
1316  return m_addressBlockList.empty ();
1317 }
1318 
1321 {
1322  NS_LOG_FUNCTION (this);
1323  return m_addressBlockList.front ();
1324 }
1325 
1328 {
1329  NS_LOG_FUNCTION (this);
1330  return m_addressBlockList.front ();
1331 }
1332 
1335 {
1336  NS_LOG_FUNCTION (this);
1337  return m_addressBlockList.back ();
1338 }
1339 
1342 {
1343  NS_LOG_FUNCTION (this);
1344  return m_addressBlockList.back ();
1345 }
1346 
1347 void
1349 {
1350  NS_LOG_FUNCTION (this << tlv);
1351  m_addressBlockList.push_front (tlv);
1352 }
1353 
1354 void
1356 {
1357  NS_LOG_FUNCTION (this);
1358  m_addressBlockList.pop_front ();
1359 }
1360 
1361 void
1363 {
1364  NS_LOG_FUNCTION (this << tlv);
1365  m_addressBlockList.push_back (tlv);
1366 }
1367 
1368 void
1370 {
1371  NS_LOG_FUNCTION (this);
1372  m_addressBlockList.pop_back ();
1373 }
1374 
1375 PbbMessage::AddressBlockIterator
1376 PbbMessage::AddressBlockErase (PbbMessage::AddressBlockIterator position)
1377 {
1378  NS_LOG_FUNCTION (this << &position);
1379  return m_addressBlockList.erase (position);
1380 }
1381 
1382 PbbMessage::AddressBlockIterator
1383 PbbMessage::AddressBlockErase (PbbMessage::AddressBlockIterator first,
1384  PbbMessage::AddressBlockIterator last)
1385 {
1386  NS_LOG_FUNCTION (this << &first << &last);
1387  return m_addressBlockList.erase (first, last);
1388 }
1389 
1390 void
1392 {
1393  NS_LOG_FUNCTION (this);
1394  for (AddressBlockIterator iter = AddressBlockBegin ();
1395  iter != AddressBlockEnd ();
1396  iter++)
1397  {
1398  *iter = 0;
1399  }
1400  return m_addressBlockList.clear ();
1401 }
1402 
1403 uint32_t
1405 {
1406  NS_LOG_FUNCTION (this);
1407  /* msg-type + (msg-flags + msg-addr-length) + 2msg-size */
1408  uint32_t size = 4;
1409 
1410  if (HasOriginatorAddress ())
1411  {
1412  size += GetAddressLength () + 1;
1413  }
1414 
1415  if (HasHopLimit ())
1416  {
1417  size++;
1418  }
1419 
1420  if (HasHopCount ())
1421  {
1422  size++;
1423  }
1424 
1425  if (HasSequenceNumber ())
1426  {
1427  size += 2;
1428  }
1429 
1430  size += m_tlvList.GetSerializedSize ();
1431 
1432  for (ConstAddressBlockIterator iter = AddressBlockBegin ();
1433  iter != AddressBlockEnd ();
1434  iter++)
1435  {
1436  size += (*iter)->GetSerializedSize ();
1437  }
1438 
1439  return size;
1440 }
1441 
1442 void
1444 {
1445  NS_LOG_FUNCTION (this << &start);
1446  Buffer::Iterator front = start;
1447 
1448  start.WriteU8 (GetType ());
1449 
1450  /* Save a reference to the spot where we will later write the flags */
1451  Buffer::Iterator bufref = start;
1452  start.Next (1);
1453 
1454  uint8_t flags = 0;
1455 
1456  flags = GetAddressLength ();
1457 
1458  Buffer::Iterator sizeref = start;
1459  start.Next (2);
1460 
1461  if (HasOriginatorAddress ())
1462  {
1463  flags |= MHAS_ORIG;
1464  SerializeOriginatorAddress (start);
1465  }
1466 
1467  if (HasHopLimit ())
1468  {
1469  flags |= MHAS_HOP_LIMIT;
1470  start.WriteU8 (GetHopLimit ());
1471  }
1472 
1473  if (HasHopCount ())
1474  {
1475  flags |= MHAS_HOP_COUNT;
1476  start.WriteU8 (GetHopCount ());
1477  }
1478 
1479  if (HasSequenceNumber ())
1480  {
1481  flags |= MHAS_SEQ_NUM;
1482  start.WriteHtonU16 (GetSequenceNumber ());
1483  }
1484 
1485  bufref.WriteU8 (flags);
1486 
1487  m_tlvList.Serialize (start);
1488 
1489  for (ConstAddressBlockIterator iter = AddressBlockBegin ();
1490  iter != AddressBlockEnd ();
1491  iter++)
1492  {
1493  (*iter)->Serialize (start);
1494  }
1495 
1496  sizeref.WriteHtonU16 (front.GetDistanceFrom (start));
1497 }
1498 
1501 {
1502  NS_LOG_FUNCTION (&start);
1503  /* We need to read the msg-addr-len field to determine what kind of object to
1504  * construct. */
1505  start.Next ();
1506  uint8_t addrlen = start.ReadU8 ();
1507  start.Prev (2); /* Go back to the start */
1508 
1509  /* The first four bytes of the flag is the address length. Set the last four
1510  * bytes to 0 to read it. */
1511  addrlen = (addrlen & 0xf);
1512 
1513  Ptr<PbbMessage> newmsg;
1514 
1515  switch (addrlen)
1516  {
1517  case 0:
1518  case IPV4:
1519  newmsg = Create<PbbMessageIpv4> ();
1520  break;
1521  case IPV6:
1522  newmsg = Create<PbbMessageIpv6> ();
1523  break;
1524  default:
1525  return 0;
1526  break;
1527  }
1528  newmsg->Deserialize (start);
1529  return newmsg;
1530 }
1531 
1532 void
1534 {
1535  NS_LOG_FUNCTION (this << &start);
1536  Buffer::Iterator front = start;
1537  SetType (start.ReadU8 ());
1538  uint8_t flags = start.ReadU8 ();
1539 
1540  uint16_t size = start.ReadNtohU16 ();
1541 
1542  if (flags & MHAS_ORIG)
1543  {
1544  SetOriginatorAddress (DeserializeOriginatorAddress (start));
1545  }
1546 
1547  if (flags & MHAS_HOP_LIMIT)
1548  {
1549  SetHopLimit (start.ReadU8 ());
1550  }
1551 
1552  if (flags & MHAS_HOP_COUNT)
1553  {
1554  SetHopCount (start.ReadU8 ());
1555  }
1556 
1557  if (flags & MHAS_SEQ_NUM)
1558  {
1559  SetSequenceNumber (start.ReadNtohU16 ());
1560  }
1561 
1562  m_tlvList.Deserialize (start);
1563 
1564  if (size > 0)
1565  {
1566  while (start.GetDistanceFrom (front) < size)
1567  {
1568  Ptr<PbbAddressBlock> newab = AddressBlockDeserialize (start);
1569  AddressBlockPushBack (newab);
1570  }
1571  }
1572 }
1573 
1574 void
1575 PbbMessage::Print (std::ostream &os) const
1576 {
1577  NS_LOG_FUNCTION (this << &os);
1578  Print (os, 0);
1579 }
1580 
1581 void
1582 PbbMessage::Print (std::ostream &os, int level) const
1583 {
1584  NS_LOG_FUNCTION (this << &os << level);
1585  std::string prefix = "";
1586  for (int i = 0; i < level; i++)
1587  {
1588  prefix.append ("\t");
1589  }
1590 
1591  os << prefix << "PbbMessage {" << std::endl;
1592 
1593  os << prefix << "\tmessage type = " << (int)GetType () << std::endl;
1594  os << prefix << "\taddress size = " << GetAddressLength () << std::endl;
1595 
1596  if (HasOriginatorAddress ())
1597  {
1598  os << prefix << "\toriginator address = ";
1599  PrintOriginatorAddress (os);
1600  os << std::endl;
1601  }
1602 
1603  if (HasHopLimit ())
1604  {
1605  os << prefix << "\thop limit = " << (int)GetHopLimit () << std::endl;
1606  }
1607 
1608  if (HasHopCount ())
1609  {
1610  os << prefix << "\thop count = " << (int)GetHopCount () << std::endl;
1611  }
1612 
1613  if (HasSequenceNumber ())
1614  {
1615  os << prefix << "\tseqnum = " << GetSequenceNumber () << std::endl;
1616  }
1617 
1618  m_tlvList.Print (os, level+1);
1619 
1620  for (ConstAddressBlockIterator iter = AddressBlockBegin ();
1621  iter != AddressBlockEnd ();
1622  iter++)
1623  {
1624  (*iter)->Print (os, level+1);
1625  }
1626  os << prefix << "}" << std::endl;
1627 }
1628 
1629 bool
1630 PbbMessage::operator== (const PbbMessage &other) const
1631 {
1632  if (GetAddressLength () != other.GetAddressLength ())
1633  {
1634  return false;
1635  }
1636 
1637  if (GetType () != other.GetType ())
1638  {
1639  return false;
1640  }
1641 
1642  if (HasOriginatorAddress () != other.HasOriginatorAddress ())
1643  {
1644  return false;
1645  }
1646 
1647  if (HasOriginatorAddress ())
1648  {
1649  if (GetOriginatorAddress () != other.GetOriginatorAddress ())
1650  {
1651  return false;
1652  }
1653  }
1654 
1655  if (HasHopLimit () != other.HasHopLimit ())
1656  {
1657  return false;
1658  }
1659 
1660  if (HasHopLimit ())
1661  {
1662  if (GetHopLimit () != other.GetHopLimit ())
1663  {
1664  return false;
1665  }
1666  }
1667 
1668  if (HasHopCount () != other.HasHopCount ())
1669  {
1670  return false;
1671  }
1672 
1673  if (HasHopCount ())
1674  {
1675  if (GetHopCount () != other.GetHopCount ())
1676  {
1677  return false;
1678  }
1679  }
1680 
1681  if (HasSequenceNumber () != other.HasSequenceNumber ())
1682  {
1683  return false;
1684  }
1685 
1686  if (HasSequenceNumber ())
1687  {
1688  if (GetSequenceNumber () != other.GetSequenceNumber ())
1689  {
1690  return false;
1691  }
1692  }
1693 
1694  if (m_tlvList != other.m_tlvList)
1695  {
1696  return false;
1697  }
1698 
1699  if (AddressBlockSize () != other.AddressBlockSize ())
1700  {
1701  return false;
1702  }
1703 
1704  ConstAddressBlockIterator tai, oai;
1705  for (tai = AddressBlockBegin (), oai = other.AddressBlockBegin ();
1706  tai != AddressBlockEnd () && oai != other.AddressBlockEnd ();
1707  tai++, oai++)
1708  {
1709  if (**tai != **oai)
1710  {
1711  return false;
1712  }
1713  }
1714  return true;
1715 }
1716 
1717 bool
1718 PbbMessage::operator!= (const PbbMessage &other) const
1719 {
1720  return !(*this == other);
1721 }
1722 
1723 /* End PbbMessage Class */
1724 
1725 PbbMessageIpv4::PbbMessageIpv4 ()
1726 {
1727  NS_LOG_FUNCTION (this);
1728 }
1729 
1730 PbbMessageIpv4::~PbbMessageIpv4 ()
1731 {
1732  NS_LOG_FUNCTION (this);
1733 }
1734 
1736 PbbMessageIpv4::GetAddressLength (void) const
1737 {
1738  NS_LOG_FUNCTION (this);
1739  return IPV4;
1740 }
1741 
1742 void
1743 PbbMessageIpv4::SerializeOriginatorAddress (Buffer::Iterator &start) const
1744 {
1745  NS_LOG_FUNCTION (this << &start);
1746  uint8_t* buffer = new uint8_t[GetAddressLength () + 1];
1748  start.Write (buffer, GetAddressLength () + 1);
1749  delete[] buffer;
1750 }
1751 
1752 Address
1753 PbbMessageIpv4::DeserializeOriginatorAddress (Buffer::Iterator &start) const
1754 {
1755  NS_LOG_FUNCTION (this << &start);
1756  uint8_t* buffer = new uint8_t[GetAddressLength () + 1];
1757  start.Read (buffer, GetAddressLength () + 1);
1758  Address result = Ipv4Address::Deserialize (buffer);
1759  delete[] buffer;
1760  return result;
1761 }
1762 
1763 void
1764 PbbMessageIpv4::PrintOriginatorAddress (std::ostream &os) const
1765 {
1766  NS_LOG_FUNCTION (this << &os);
1768 }
1769 
1770 Ptr<PbbAddressBlock>
1771 PbbMessageIpv4::AddressBlockDeserialize (Buffer::Iterator &start) const
1772 {
1773  NS_LOG_FUNCTION (this << &start);
1774  Ptr<PbbAddressBlock> newab = Create<PbbAddressBlockIpv4> ();
1775  newab->Deserialize (start);
1776  return newab;
1777 }
1778 
1779 /* End PbbMessageIpv4 Class */
1780 
1781 PbbMessageIpv6::PbbMessageIpv6 ()
1782 {
1783  NS_LOG_FUNCTION (this);
1784 }
1785 
1786 PbbMessageIpv6::~PbbMessageIpv6 ()
1787 {
1788  NS_LOG_FUNCTION (this);
1789 }
1790 
1792 PbbMessageIpv6::GetAddressLength (void) const
1793 {
1794  NS_LOG_FUNCTION (this);
1795  return IPV6;
1796 }
1797 
1798 void
1799 PbbMessageIpv6::SerializeOriginatorAddress (Buffer::Iterator &start) const
1800 {
1801  NS_LOG_FUNCTION (this << &start);
1802  uint8_t* buffer = new uint8_t[GetAddressLength () + 1];
1804  start.Write (buffer, GetAddressLength () + 1);
1805  delete[] buffer;
1806 }
1807 
1808 Address
1809 PbbMessageIpv6::DeserializeOriginatorAddress (Buffer::Iterator &start) const
1810 {
1811  NS_LOG_FUNCTION (this << &start);
1812  uint8_t* buffer = new uint8_t[GetAddressLength () + 1];
1813  start.Read (buffer, GetAddressLength () + 1);
1814  Address res = Ipv6Address::Deserialize (buffer);
1815  delete[] buffer;
1816  return res;
1817 }
1818 
1819 void
1820 PbbMessageIpv6::PrintOriginatorAddress (std::ostream &os) const
1821 {
1822  NS_LOG_FUNCTION (this << &os);
1824 }
1825 
1826 Ptr<PbbAddressBlock>
1827 PbbMessageIpv6::AddressBlockDeserialize (Buffer::Iterator &start) const
1828 {
1829  NS_LOG_FUNCTION (this << &start);
1830  Ptr<PbbAddressBlock> newab = Create<PbbAddressBlockIpv6> ();
1831  newab->Deserialize (start);
1832  return newab;
1833 }
1834 
1835 /* End PbbMessageIpv6 Class */
1836 
1837 PbbAddressBlock::PbbAddressBlock ()
1838 {
1839  NS_LOG_FUNCTION (this);
1840 }
1841 
1842 PbbAddressBlock::~PbbAddressBlock ()
1843 {
1844  NS_LOG_FUNCTION (this);
1845 }
1846 
1847 /* Manipulating the address block */
1848 
1849 PbbAddressBlock::AddressIterator
1851 {
1852  NS_LOG_FUNCTION (this);
1853  return m_addressList.begin ();
1854 }
1855 
1856 PbbAddressBlock::ConstAddressIterator
1858 {
1859  NS_LOG_FUNCTION (this);
1860  return m_addressList.begin ();
1861 }
1862 
1863 PbbAddressBlock::AddressIterator
1865 {
1866  NS_LOG_FUNCTION (this);
1867  return m_addressList.end ();
1868 }
1869 
1870 PbbAddressBlock::ConstAddressIterator
1872 {
1873  NS_LOG_FUNCTION (this);
1874  return m_addressList.end ();
1875 }
1876 
1877 int
1879 {
1880  NS_LOG_FUNCTION (this);
1881  return m_addressList.size ();
1882 }
1883 
1884 bool
1886 {
1887  NS_LOG_FUNCTION (this);
1888  return m_addressList.empty ();
1889 }
1890 
1891 Address
1893 {
1894  NS_LOG_FUNCTION (this);
1895  return m_addressList.front ();
1896 }
1897 
1898 Address
1900 {
1901  NS_LOG_FUNCTION (this);
1902  return m_addressList.back ();
1903 }
1904 
1905 void
1907 {
1908  NS_LOG_FUNCTION (this << tlv);
1909  m_addressList.push_front (tlv);
1910 }
1911 
1912 void
1914 {
1915  NS_LOG_FUNCTION (this);
1916  m_addressList.pop_front ();
1917 }
1918 
1919 void
1921 {
1922  NS_LOG_FUNCTION (this << tlv);
1923  m_addressList.push_back (tlv);
1924 }
1925 
1926 void
1928 {
1929  NS_LOG_FUNCTION (this);
1930  m_addressList.pop_back ();
1931 }
1932 
1933 PbbAddressBlock::AddressIterator
1934 PbbAddressBlock::AddressErase (PbbAddressBlock::AddressIterator position)
1935 {
1936  NS_LOG_FUNCTION (this << &position);
1937  return m_addressList.erase (position);
1938 }
1939 
1940 PbbAddressBlock::AddressIterator
1941 PbbAddressBlock::AddressErase (PbbAddressBlock::AddressIterator first,
1942  PbbAddressBlock::AddressIterator last)
1943 {
1944  NS_LOG_FUNCTION (this << &first << &last);
1945  return m_addressList.erase (first, last);
1946 }
1947 
1948 void
1950 {
1951  NS_LOG_FUNCTION (this);
1952  return m_addressList.clear ();
1953 }
1954 
1955 /* Manipulating the prefix list */
1956 
1957 PbbAddressBlock::PrefixIterator
1959 {
1960  NS_LOG_FUNCTION (this);
1961  return m_prefixList.begin ();
1962 }
1963 
1964 PbbAddressBlock::ConstPrefixIterator
1966 {
1967  NS_LOG_FUNCTION (this);
1968  return m_prefixList.begin ();
1969 }
1970 
1971 PbbAddressBlock::PrefixIterator
1973 {
1974  NS_LOG_FUNCTION (this);
1975  return m_prefixList.end ();
1976 }
1977 
1978 PbbAddressBlock::ConstPrefixIterator
1980 {
1981  NS_LOG_FUNCTION (this);
1982  return m_prefixList.end ();
1983 }
1984 
1985 int
1987 {
1988  NS_LOG_FUNCTION (this);
1989  return m_prefixList.size ();
1990 }
1991 
1992 bool
1994 {
1995  NS_LOG_FUNCTION (this);
1996  return m_prefixList.empty ();
1997 }
1998 
1999 uint8_t
2001 {
2002  NS_LOG_FUNCTION (this);
2003  return m_prefixList.front ();
2004 }
2005 
2006 uint8_t
2008 {
2009  NS_LOG_FUNCTION (this);
2010  return m_prefixList.back ();
2011 }
2012 
2013 void
2015 {
2016  NS_LOG_FUNCTION (this << static_cast<uint32_t> (prefix));
2017  m_prefixList.push_front (prefix);
2018 }
2019 
2020 void
2022 {
2023  NS_LOG_FUNCTION (this);
2024  m_prefixList.pop_front ();
2025 }
2026 
2027 void
2029 {
2030  NS_LOG_FUNCTION (this << static_cast<uint32_t> (prefix));
2031  m_prefixList.push_back (prefix);
2032 }
2033 
2034 void
2036 {
2037  NS_LOG_FUNCTION (this);
2038  m_prefixList.pop_back ();
2039 }
2040 
2041 PbbAddressBlock::PrefixIterator
2042 PbbAddressBlock::PrefixInsert (PbbAddressBlock::PrefixIterator position, const uint8_t value)
2043 {
2044  NS_LOG_FUNCTION (this << &position << static_cast<uint32_t> (value));
2045  return m_prefixList.insert (position, value);
2046 }
2047 
2048 PbbAddressBlock::PrefixIterator
2049 PbbAddressBlock::PrefixErase (PbbAddressBlock::PrefixIterator position)
2050 {
2051  NS_LOG_FUNCTION (this << &position);
2052  return m_prefixList.erase (position);
2053 }
2054 
2055 PbbAddressBlock::PrefixIterator
2056 PbbAddressBlock::PrefixErase (PbbAddressBlock::PrefixIterator first, PbbAddressBlock::PrefixIterator last)
2057 {
2058  NS_LOG_FUNCTION (this << &first << &last);
2059  return m_prefixList.erase (first, last);
2060 }
2061 
2062 void
2064 {
2065  NS_LOG_FUNCTION (this);
2066  m_prefixList.clear ();
2067 }
2068 
2069 /* Manipulating the TLV block */
2070 
2071 PbbAddressBlock::TlvIterator
2073 {
2074  NS_LOG_FUNCTION (this);
2075  return m_addressTlvList.Begin ();
2076 }
2077 
2078 PbbAddressBlock::ConstTlvIterator
2080 {
2081  NS_LOG_FUNCTION (this);
2082  return m_addressTlvList.Begin ();
2083 }
2084 
2085 PbbAddressBlock::TlvIterator
2087 {
2088  NS_LOG_FUNCTION (this);
2089  return m_addressTlvList.End ();
2090 }
2091 
2092 PbbAddressBlock::ConstTlvIterator
2094 {
2095  NS_LOG_FUNCTION (this);
2096  return m_addressTlvList.End ();
2097 }
2098 
2099 int
2101 {
2102  NS_LOG_FUNCTION (this);
2103  return m_addressTlvList.Size ();
2104 }
2105 
2106 bool
2108 {
2109  NS_LOG_FUNCTION (this);
2110  return m_addressTlvList.Empty ();
2111 }
2112 
2115 {
2116  NS_LOG_FUNCTION (this);
2117  return m_addressTlvList.Front ();
2118 }
2119 
2120 const Ptr<PbbAddressTlv>
2122 {
2123  NS_LOG_FUNCTION (this);
2124  return m_addressTlvList.Front ();
2125 }
2126 
2129 {
2130  NS_LOG_FUNCTION (this);
2131  return m_addressTlvList.Back ();
2132 }
2133 
2134 const Ptr<PbbAddressTlv>
2136 {
2137  NS_LOG_FUNCTION (this);
2138  return m_addressTlvList.Back ();
2139 }
2140 
2141 void
2143 {
2144  NS_LOG_FUNCTION (this << tlv);
2145  m_addressTlvList.PushFront (tlv);
2146 }
2147 
2148 void
2150 {
2151  NS_LOG_FUNCTION (this);
2152  m_addressTlvList.PopFront ();
2153 }
2154 
2155 void
2157 {
2158  NS_LOG_FUNCTION (this << tlv);
2159  m_addressTlvList.PushBack (tlv);
2160 }
2161 
2162 void
2164 {
2165  NS_LOG_FUNCTION (this);
2166  m_addressTlvList.PopBack ();
2167 }
2168 
2169 PbbAddressBlock::TlvIterator
2170 PbbAddressBlock::TlvErase (PbbAddressBlock::TlvIterator position)
2171 {
2172  NS_LOG_FUNCTION (this << &position);
2173  return m_addressTlvList.Erase (position);
2174 }
2175 
2176 PbbAddressBlock::TlvIterator
2177 PbbAddressBlock::TlvErase (PbbAddressBlock::TlvIterator first,
2178  PbbAddressBlock::TlvIterator last)
2179 {
2180  NS_LOG_FUNCTION (this << &first << &last);
2181  return m_addressTlvList.Erase (first, last);
2182 }
2183 
2184 void
2186 {
2187  NS_LOG_FUNCTION (this);
2188  m_addressTlvList.Clear ();
2189 }
2190 uint32_t
2192 {
2193  NS_LOG_FUNCTION (this);
2194  /* num-addr + flags */
2195  uint32_t size = 2;
2196 
2197  if (AddressSize () == 1)
2198  {
2199  size += GetAddressLength () + PrefixSize ();
2200  }
2201  else if (AddressSize () > 0)
2202  {
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;
2207 
2208  GetHeadTail (head, headlen, tail, taillen);
2209 
2210  if (headlen > 0)
2211  {
2212  size += 1 + headlen;
2213  }
2214 
2215  if (taillen > 0)
2216  {
2217  size++;
2218  if (!HasZeroTail (tail, taillen))
2219  {
2220  size += taillen;
2221  }
2222  }
2223 
2224  /* mid size */
2225  size += (GetAddressLength () - headlen - taillen) * AddressSize ();
2226 
2227  size += PrefixSize ();
2228 
2229  delete[] head;
2230  delete[] tail;
2231  }
2232 
2233  size += m_addressTlvList.GetSerializedSize ();
2234 
2235  return size;
2236 }
2237 
2238 void
2240 {
2241  NS_LOG_FUNCTION (this << &start);
2242  start.WriteU8 (AddressSize ());
2243  Buffer::Iterator bufref = start;
2244  uint8_t flags = 0;
2245  start.Next ();
2246 
2247  if (AddressSize () == 1)
2248  {
2249  uint8_t* buf = new uint8_t[GetAddressLength ()];
2250  SerializeAddress (buf, AddressBegin ());
2251  start.Write (buf, GetAddressLength ());
2252 
2253  if (PrefixSize () == 1)
2254  {
2255  start.WriteU8 (PrefixFront ());
2256  flags |= AHAS_SINGLE_PRE_LEN;
2257  }
2258  bufref.WriteU8 (flags);
2259  delete[] buf;
2260  }
2261  else if (AddressSize () > 0)
2262  {
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;
2267 
2268  GetHeadTail (head, headlen, tail, taillen);
2269 
2270  if (headlen > 0)
2271  {
2272  flags |= AHAS_HEAD;
2273  start.WriteU8 (headlen);
2274  start.Write (head, headlen);
2275  }
2276 
2277  if (taillen > 0)
2278  {
2279  start.WriteU8 (taillen);
2280 
2281  if (HasZeroTail (tail, taillen))
2282  {
2283  flags |= AHAS_ZERO_TAIL;
2284  }
2285  else
2286  {
2287  flags |= AHAS_FULL_TAIL;
2288  start.Write (tail, taillen);
2289  }
2290  }
2291 
2292  if (headlen + taillen < GetAddressLength ())
2293  {
2294  uint8_t* mid = new uint8_t[GetAddressLength ()];
2295  for (PbbAddressBlock::ConstAddressIterator iter = AddressBegin ();
2296  iter != AddressEnd ();
2297  iter++)
2298  {
2299  SerializeAddress (mid, iter);
2300  start.Write (mid + headlen, GetAddressLength () - headlen - taillen);
2301  }
2302  delete[] mid;
2303  }
2304 
2305  flags |= GetPrefixFlags ();
2306  bufref.WriteU8 (flags);
2307 
2308  for (ConstPrefixIterator iter = PrefixBegin ();
2309  iter != PrefixEnd ();
2310  iter++)
2311  {
2312  start.WriteU8 (*iter);
2313  }
2314 
2315  delete[] head;
2316  delete[] tail;
2317  }
2318 
2319  m_addressTlvList.Serialize (start);
2320 }
2321 
2322 void
2324 {
2325  NS_LOG_FUNCTION (this << &start);
2326  uint8_t numaddr = start.ReadU8 ();
2327  uint8_t flags = start.ReadU8 ();
2328 
2329  if (numaddr > 0)
2330  {
2331  uint8_t headlen = 0;
2332  uint8_t taillen = 0;
2333  uint8_t* addrtmp = new uint8_t[GetAddressLength ()];
2334  memset (addrtmp, 0, GetAddressLength ());
2335 
2336  if (flags & AHAS_HEAD)
2337  {
2338  headlen = start.ReadU8 ();
2339  start.Read (addrtmp, headlen);
2340  }
2341 
2342  if ((flags & AHAS_FULL_TAIL) ^ (flags & AHAS_ZERO_TAIL))
2343  {
2344  taillen = start.ReadU8 ();
2345 
2346  if (flags & AHAS_FULL_TAIL)
2347  {
2348  start.Read (addrtmp + GetAddressLength () - taillen, taillen);
2349  }
2350  }
2351 
2352  for (int i = 0; i < numaddr; i++)
2353  {
2354  start.Read (addrtmp + headlen, GetAddressLength () - headlen - taillen);
2355  AddressPushBack (DeserializeAddress (addrtmp));
2356  }
2357 
2358  if (flags & AHAS_SINGLE_PRE_LEN)
2359  {
2360  PrefixPushBack (start.ReadU8 ());
2361  }
2362  else if (flags & AHAS_MULTI_PRE_LEN)
2363  {
2364  for (int i = 0; i < numaddr; i++)
2365  {
2366  PrefixPushBack (start.ReadU8 ());
2367  }
2368  }
2369 
2370  delete[] addrtmp;
2371  }
2372 
2373  m_addressTlvList.Deserialize (start);
2374 }
2375 
2376 void
2377 PbbAddressBlock::Print (std::ostream &os) const
2378 {
2379  NS_LOG_FUNCTION (this << &os);
2380  Print (os, 0);
2381 }
2382 
2383 void
2384 PbbAddressBlock::Print (std::ostream &os, int level) const
2385 {
2386  NS_LOG_FUNCTION (this << &os << level);
2387  std::string prefix = "";
2388  for (int i = 0; i < level; i++)
2389  {
2390  prefix.append ("\t");
2391  }
2392 
2393  os << prefix << "PbbAddressBlock {" << std::endl;
2394  os << prefix << "\taddresses = " << std::endl;
2395  for (ConstAddressIterator iter = AddressBegin ();
2396  iter != AddressEnd ();
2397  iter++)
2398  {
2399  os << prefix << "\t\t";
2400  PrintAddress (os, iter);
2401  os << std::endl;
2402  }
2403 
2404  os << prefix << "\tprefixes = " << std::endl;
2405  for (ConstPrefixIterator iter = PrefixBegin ();
2406  iter != PrefixEnd ();
2407  iter++)
2408  {
2409  os << prefix << "\t\t" << (int)(*iter) << std::endl;
2410  }
2411 
2412  m_addressTlvList.Print (os, level+1);
2413 }
2414 
2415 bool
2416 PbbAddressBlock::operator== (const PbbAddressBlock &other) const
2417 {
2418  if (AddressSize () != other.AddressSize ())
2419  {
2420  return false;
2421  }
2422 
2423  ConstAddressIterator tai, oai;
2424  for (tai = AddressBegin (), oai = other.AddressBegin ();
2425  tai != AddressEnd () && oai != other.AddressEnd ();
2426  tai++, oai++)
2427  {
2428  if (*tai != *oai)
2429  {
2430  return false;
2431  }
2432  }
2433 
2434  if (PrefixSize () != other.PrefixSize ())
2435  {
2436  return false;
2437  }
2438 
2439  ConstPrefixIterator tpi, opi;
2440  for (tpi = PrefixBegin (), opi = other.PrefixBegin ();
2441  tpi != PrefixEnd () && opi != other.PrefixEnd ();
2442  tpi++, opi++)
2443  {
2444  if (*tpi != *opi)
2445  {
2446  return false;
2447  }
2448  }
2449 
2450  if (m_addressTlvList != other.m_addressTlvList)
2451  {
2452  return false;
2453  }
2454 
2455  return true;
2456 }
2457 
2458 bool
2459 PbbAddressBlock::operator!= (const PbbAddressBlock &other) const
2460 {
2461  return !(*this == other);
2462 }
2463 
2464 uint8_t
2465 PbbAddressBlock::GetPrefixFlags (void) const
2466 {
2467  NS_LOG_FUNCTION (this);
2468  switch (PrefixSize ())
2469  {
2470  case 0:
2471  return 0;
2472  break;
2473  case 1:
2474  return AHAS_SINGLE_PRE_LEN;
2475  break;
2476  default:
2477  return AHAS_MULTI_PRE_LEN;
2478  break;
2479  }
2480 
2481  /* Quiet compiler */
2482  return 0;
2483 }
2484 
2485 void
2486 PbbAddressBlock::GetHeadTail (uint8_t *head, uint8_t &headlen,
2487  uint8_t *tail, uint8_t &taillen) const
2488 {
2489  NS_LOG_FUNCTION (this << &head << static_cast<uint32_t> (headlen)
2490  << &tail << static_cast<uint32_t> (taillen));
2491  headlen = GetAddressLength ();
2492  taillen = headlen;
2493 
2494  /* Temporary automatic buffers to store serialized addresses */
2495  uint8_t * buflast = new uint8_t[GetAddressLength ()];
2496  uint8_t * bufcur = new uint8_t[GetAddressLength ()];
2497  uint8_t * tmp;
2498 
2499  SerializeAddress (buflast, AddressBegin ());
2500 
2501  /* Skip the first item */
2502  for (PbbAddressBlock::ConstAddressIterator iter = AddressBegin ()++;
2503  iter != AddressEnd ();
2504  iter++)
2505  {
2506  SerializeAddress (bufcur, iter);
2507 
2508  int i;
2509  for (i = 0; i < headlen; i++)
2510  {
2511  if (buflast[i] != bufcur[i])
2512  {
2513  headlen = i;
2514  break;
2515  }
2516  }
2517 
2518  /* If headlen == fulllen - 1, then tail is 0 */
2519  if (headlen <= GetAddressLength () - 1)
2520  {
2521  for (i = GetAddressLength () - 1;
2522  GetAddressLength () - 1 - i <= taillen && i > headlen;
2523  i--)
2524  {
2525  if (buflast[i] != bufcur[i])
2526  {
2527  break;
2528  }
2529  }
2530  taillen = GetAddressLength () - 1 - i;
2531  }
2532  else if (headlen == 0)
2533  {
2534  taillen = 0;
2535  break;
2536  }
2537 
2538  tmp = buflast;
2539  buflast = bufcur;
2540  bufcur = tmp;
2541  }
2542 
2543  memcpy (head, bufcur, headlen);
2544  memcpy (tail, bufcur + (GetAddressLength () - taillen), taillen);
2545 
2546  delete[] buflast;
2547  delete[] bufcur;
2548 }
2549 
2550 bool
2551 PbbAddressBlock::HasZeroTail (const uint8_t *tail, uint8_t taillen) const
2552 {
2553  NS_LOG_FUNCTION (this << &tail << static_cast<uint32_t> (taillen));
2554  int i;
2555  for (i = 0; i < taillen; i++)
2556  {
2557  if (tail[i] != 0)
2558  {
2559  break;
2560  }
2561  }
2562  return i == taillen;
2563 }
2564 
2565 /* End PbbAddressBlock Class */
2566 
2567 PbbAddressBlockIpv4::PbbAddressBlockIpv4 ()
2568 {
2569  NS_LOG_FUNCTION (this);
2570 }
2571 
2572 PbbAddressBlockIpv4::~PbbAddressBlockIpv4 ()
2573 {
2574  NS_LOG_FUNCTION (this);
2575 }
2576 
2577 uint8_t
2578 PbbAddressBlockIpv4::GetAddressLength (void) const
2579 {
2580  NS_LOG_FUNCTION (this);
2581  return 4;
2582 }
2583 
2584 void
2585 PbbAddressBlockIpv4::SerializeAddress (uint8_t *buffer, ConstAddressIterator iter) const
2586 {
2587  NS_LOG_FUNCTION (this << &buffer << &iter);
2588  Ipv4Address::ConvertFrom (*iter).Serialize (buffer);
2589 }
2590 
2591 Address
2592 PbbAddressBlockIpv4::DeserializeAddress (uint8_t *buffer) const
2593 {
2594  NS_LOG_FUNCTION (this << &buffer);
2595  return Ipv4Address::Deserialize (buffer);
2596 }
2597 
2598 void
2599 PbbAddressBlockIpv4::PrintAddress (std::ostream &os, ConstAddressIterator iter) const
2600 {
2601  NS_LOG_FUNCTION (this << &os << &iter);
2602  Ipv4Address::ConvertFrom (*iter).Print (os);
2603 }
2604 
2605 /* End PbbAddressBlockIpv4 Class */
2606 
2607 PbbAddressBlockIpv6::PbbAddressBlockIpv6 ()
2608 {
2609  NS_LOG_FUNCTION (this);
2610 }
2611 
2612 PbbAddressBlockIpv6::~PbbAddressBlockIpv6 ()
2613 {
2614  NS_LOG_FUNCTION (this);
2615 }
2616 
2617 uint8_t
2618 PbbAddressBlockIpv6::GetAddressLength (void) const
2619 {
2620  NS_LOG_FUNCTION (this);
2621  return 16;
2622 }
2623 
2624 void
2625 PbbAddressBlockIpv6::SerializeAddress (uint8_t *buffer, ConstAddressIterator iter) const
2626 {
2627  NS_LOG_FUNCTION (this << &buffer << &iter);
2628  Ipv6Address::ConvertFrom (*iter).Serialize (buffer);
2629 }
2630 
2631 Address
2632 PbbAddressBlockIpv6::DeserializeAddress (uint8_t *buffer) const
2633 {
2634  NS_LOG_FUNCTION (this << &buffer);
2635  return Ipv6Address::Deserialize (buffer);
2636 }
2637 
2638 void
2639 PbbAddressBlockIpv6::PrintAddress (std::ostream &os, ConstAddressIterator iter) const
2640 {
2641  NS_LOG_FUNCTION (this << &os << &iter);
2642  Ipv6Address::ConvertFrom (*iter).Print (os);
2643 }
2644 
2645 /* End PbbAddressBlockIpv6 Class */
2646 
2647 PbbTlv::PbbTlv (void)
2648 {
2649  NS_LOG_FUNCTION (this);
2650  m_hasTypeExt = false;
2651  m_hasIndexStart = false;
2652  m_hasIndexStop = false;
2653  m_isMultivalue = false;
2654  m_hasValue = false;
2655 }
2656 
2657 PbbTlv::~PbbTlv (void)
2658 {
2659  NS_LOG_FUNCTION (this);
2660  m_value.RemoveAtEnd (m_value.GetSize ());
2661 }
2662 
2663 void
2664 PbbTlv::SetType (uint8_t type)
2665 {
2666  NS_LOG_FUNCTION (this << static_cast<uint32_t> (type));
2667  m_type = type;
2668 }
2669 
2670 uint8_t
2671 PbbTlv::GetType (void) const
2672 {
2673  NS_LOG_FUNCTION (this);
2674  return m_type;
2675 }
2676 
2677 void
2678 PbbTlv::SetTypeExt (uint8_t typeExt)
2679 {
2680  NS_LOG_FUNCTION (this << static_cast<uint32_t> (typeExt));
2681  m_typeExt = typeExt;
2682  m_hasTypeExt = true;
2683 }
2684 
2685 uint8_t
2687 {
2688  NS_LOG_FUNCTION (this);
2689  NS_ASSERT (HasTypeExt ());
2690  return m_typeExt;
2691 }
2692 
2693 bool
2695 {
2696  NS_LOG_FUNCTION (this);
2697  return m_hasTypeExt;
2698 }
2699 
2700 void
2701 PbbTlv::SetIndexStart (uint8_t index)
2702 {
2703  NS_LOG_FUNCTION (this << static_cast<uint32_t> (index));
2704  m_indexStart = index;
2705  m_hasIndexStart = true;
2706 }
2707 
2708 uint8_t
2709 PbbTlv::GetIndexStart (void) const
2710 {
2711  NS_LOG_FUNCTION (this);
2712  NS_ASSERT (HasIndexStart ());
2713  return m_indexStart;
2714 }
2715 
2716 bool
2717 PbbTlv::HasIndexStart (void) const
2718 {
2719  NS_LOG_FUNCTION (this);
2720  return m_hasIndexStart;
2721 }
2722 
2723 void
2724 PbbTlv::SetIndexStop (uint8_t index)
2725 {
2726  NS_LOG_FUNCTION (this << static_cast<uint32_t> (index));
2727  m_indexStop = index;
2728  m_hasIndexStop = true;
2729 }
2730 
2731 uint8_t
2732 PbbTlv::GetIndexStop (void) const
2733 {
2734  NS_LOG_FUNCTION (this);
2735  NS_ASSERT (HasIndexStop ());
2736  return m_indexStop;
2737 }
2738 
2739 bool
2740 PbbTlv::HasIndexStop (void) const
2741 {
2742  NS_LOG_FUNCTION (this);
2743  return m_hasIndexStop;
2744 }
2745 
2746 void
2747 PbbTlv::SetMultivalue (bool isMultivalue)
2748 {
2749  NS_LOG_FUNCTION (this << isMultivalue);
2750  m_isMultivalue = isMultivalue;
2751 }
2752 
2753 bool
2754 PbbTlv::IsMultivalue (void) const
2755 {
2756  NS_LOG_FUNCTION (this);
2757  return m_isMultivalue;
2758 }
2759 
2760 void
2762 {
2763  NS_LOG_FUNCTION (this << &start);
2764  m_hasValue = true;
2765  m_value = start;
2766 }
2767 
2768 void
2769 PbbTlv::SetValue (const uint8_t * buffer, uint32_t size)
2770 {
2771  NS_LOG_FUNCTION (this << &buffer << size);
2772  m_hasValue = true;
2773  m_value.AddAtStart (size);
2774  m_value.Begin ().Write (buffer, size);
2775 }
2776 
2777 Buffer
2778 PbbTlv::GetValue (void) const
2779 {
2780  NS_LOG_FUNCTION (this);
2781  NS_ASSERT (HasValue ());
2782  return m_value;
2783 }
2784 
2785 bool
2786 PbbTlv::HasValue (void) const
2787 {
2788  NS_LOG_FUNCTION (this);
2789  return m_hasValue;
2790 }
2791 
2792 uint32_t
2794 {
2795  NS_LOG_FUNCTION (this);
2796  /* type + flags */
2797  uint32_t size = 2;
2798 
2799  if (HasTypeExt ())
2800  {
2801  size++;
2802  }
2803 
2804  if (HasIndexStart ())
2805  {
2806  size++;
2807  }
2808 
2809  if (HasIndexStop ())
2810  {
2811  size++;
2812  }
2813 
2814  if (HasValue ())
2815  {
2816  if (GetValue ().GetSize () > 255)
2817  {
2818  size += 2;
2819  }
2820  else
2821  {
2822  size++;
2823  }
2824  size += GetValue ().GetSize ();
2825  }
2826 
2827  return size;
2828 }
2829 
2830 void
2832 {
2833  NS_LOG_FUNCTION (this << &start);
2834  start.WriteU8 (GetType ());
2835 
2836  Buffer::Iterator bufref = start;
2837  uint8_t flags = 0;
2838  start.Next ();
2839 
2840  if (HasTypeExt ())
2841  {
2842  flags |= THAS_TYPE_EXT;
2843  start.WriteU8 (GetTypeExt ());
2844  }
2845 
2846  if (HasIndexStart ())
2847  {
2848  start.WriteU8 (GetIndexStart ());
2849 
2850  if (HasIndexStop ())
2851  {
2852  flags |= THAS_MULTI_INDEX;
2853  start.WriteU8 (GetIndexStop ());
2854  }
2855  else
2856  {
2857  flags |= THAS_SINGLE_INDEX;
2858  }
2859  }
2860 
2861  if (HasValue ())
2862  {
2863  flags |= THAS_VALUE;
2864 
2865  uint32_t size = GetValue ().GetSize ();
2866  if (size > 255)
2867  {
2868  flags |= THAS_EXT_LEN;
2869  start.WriteHtonU16 (size);
2870  }
2871  else
2872  {
2873  start.WriteU8 (size);
2874  }
2875 
2876  if (IsMultivalue ())
2877  {
2878  flags |= TIS_MULTIVALUE;
2879  }
2880 
2881  start.Write (GetValue ().Begin (), GetValue ().End ());
2882  }
2883 
2884  bufref.WriteU8 (flags);
2885 }
2886 
2887 void
2889 {
2890  NS_LOG_FUNCTION (this << &start);
2891  SetType (start.ReadU8 ());
2892 
2893  uint8_t flags = start.ReadU8 ();
2894 
2895  if (flags & THAS_TYPE_EXT)
2896  {
2897  SetTypeExt (start.ReadU8 ());
2898  }
2899 
2900  if (flags & THAS_MULTI_INDEX)
2901  {
2902  SetIndexStart (start.ReadU8 ());
2903  SetIndexStop (start.ReadU8 ());
2904  }
2905  else if (flags & THAS_SINGLE_INDEX)
2906  {
2907  SetIndexStart (start.ReadU8 ());
2908  }
2909 
2910  if (flags & THAS_VALUE)
2911  {
2912  uint16_t len = 0;
2913 
2914  if (flags & THAS_EXT_LEN)
2915  {
2916  len = start.ReadNtohU16 ();
2917  }
2918  else
2919  {
2920  len = start.ReadU8 ();
2921  }
2922 
2923  m_value.AddAtStart (len);
2924 
2925  Buffer::Iterator valueStart = start;
2926  start.Next (len);
2927  m_value.Begin ().Write (valueStart, start);
2928  m_hasValue = true;
2929  }
2930 }
2931 
2932 void
2933 PbbTlv::Print (std::ostream &os) const
2934 {
2935  NS_LOG_FUNCTION (this << &os);
2936  Print (os, 0);
2937 }
2938 
2939 void
2940 PbbTlv::Print (std::ostream &os, int level) const
2941 {
2942  NS_LOG_FUNCTION (this << &os << level);
2943  std::string prefix = "";
2944  for (int i = 0; i < level; i++)
2945  {
2946  prefix.append ("\t");
2947  }
2948 
2949  os << prefix << "PbbTlv {" << std::endl;
2950  os << prefix << "\ttype = " << (int)GetType () << std::endl;
2951 
2952  if (HasTypeExt ())
2953  {
2954  os << prefix << "\ttypeext = " << (int)GetTypeExt () << std::endl;
2955  }
2956 
2957  if (HasIndexStart ())
2958  {
2959  os << prefix << "\tindexStart = " << (int)GetIndexStart () << std::endl;
2960  }
2961 
2962  if (HasIndexStop ())
2963  {
2964  os << prefix << "\tindexStop = " << (int)GetIndexStop () << std::endl;
2965  }
2966 
2967  os << prefix << "\tisMultivalue = " << IsMultivalue () << std::endl;
2968 
2969  if (HasValue ())
2970  {
2971  os << prefix << "\thas value; size = " << GetValue ().GetSize () << std::endl;
2972  }
2973 
2974  os << prefix << "}" << std::endl;
2975 }
2976 
2977 bool
2978 PbbTlv::operator== (const PbbTlv &other) const
2979 {
2980  if (GetType () != other.GetType ())
2981  {
2982  return false;
2983  }
2984 
2985  if (HasTypeExt () != other.HasTypeExt ())
2986  {
2987  return false;
2988  }
2989 
2990  if (HasTypeExt ())
2991  {
2992  if (GetTypeExt () != other.GetTypeExt ())
2993  {
2994  return false;
2995  }
2996  }
2997 
2998  if (HasValue () != other.HasValue ())
2999  {
3000  return false;
3001  }
3002 
3003  if (HasValue ())
3004  {
3005  Buffer tv = GetValue ();
3006  Buffer ov = other.GetValue ();
3007  if (tv.GetSize () != ov.GetSize ())
3008  {
3009  return false;
3010  }
3011 
3012  /* The docs say I probably shouldn't use Buffer::PeekData, but I think it
3013  * is justified in this case. */
3014  if (memcmp (tv.PeekData (), ov.PeekData (), tv.GetSize ()) != 0)
3015  {
3016  return false;
3017  }
3018  }
3019  return true;
3020 }
3021 
3022 bool
3023 PbbTlv::operator!= (const PbbTlv &other) const
3024 {
3025  return !(*this == other);
3026 }
3027 
3028 /* End PbbTlv Class */
3029 
3030 void
3032 {
3033  NS_LOG_FUNCTION (this << static_cast<uint32_t> (index));
3034  PbbTlv::SetIndexStart (index);
3035 }
3036 
3037 uint8_t
3039 {
3040  NS_LOG_FUNCTION (this);
3041  return PbbTlv::GetIndexStart ();
3042 }
3043 
3044 bool
3046 {
3047  NS_LOG_FUNCTION (this);
3048  return PbbTlv::HasIndexStart ();
3049 }
3050 
3051 void
3053 {
3054  NS_LOG_FUNCTION (this << static_cast<uint32_t> (index));
3055  PbbTlv::SetIndexStop (index);
3056 }
3057 
3058 uint8_t
3060 {
3061  NS_LOG_FUNCTION (this);
3062  return PbbTlv::GetIndexStop ();
3063 }
3064 
3065 bool
3067 {
3068  NS_LOG_FUNCTION (this);
3069  return PbbTlv::HasIndexStop ();
3070 }
3071 
3072 void
3073 PbbAddressTlv::SetMultivalue (bool isMultivalue)
3074 {
3075  NS_LOG_FUNCTION (this << isMultivalue);
3076  PbbTlv::SetMultivalue (isMultivalue);
3077 }
3078 
3079 bool
3081 {
3082  NS_LOG_FUNCTION (this);
3083  return PbbTlv::IsMultivalue ();
3084 }
3085 
3086 } /* namespace ns3 */
Protocol header serialization and deserialization.
Definition: header.h:42
PrefixIterator PrefixEnd(void)
Definition: packetbb.cc:1972
AddressBlockIterator AddressBlockEnd()
Definition: packetbb.cc:1292
static Ipv4Address Deserialize(const uint8_t buf[4])
void Print(std::ostream &os) const
Pretty-prints the contents of this message.
Definition: packetbb.cc:1575
void TlvPushBack(Ptr< PbbTlv > tlv)
Appends a packet TLV to the back of this packet.
Definition: packetbb.cc:676
void AddressBlockPushBack(Ptr< PbbAddressBlock > block)
Appends an address block to the front of this message.
Definition: packetbb.cc:1362
TlvIterator TlvBegin(void)
Definition: packetbb.cc:592
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:311
void MessagePushFront(Ptr< PbbMessage > message)
Prepends a message to the front of this packet.
Definition: packetbb.cc:783
Ptr< PbbMessage > MessageBack(void)
Definition: packetbb.cc:769
A packet or message TLV.
Definition: packetbb.h:1505
void PushFront(Ptr< PbbTlv > tlv)
Prepends a TLV to the front of this block.
Definition: packetbb.cc:132
uint16_t GetSequenceNumber(void) const
Definition: packetbb.cc:1140
void RemoveAtEnd(uint32_t end)
Definition: buffer.cc:497
int Size(void) const
Definition: packetbb.cc:104
Main PacketBB Packet object.
Definition: packetbb.h:364
void MessagePushBack(Ptr< PbbMessage > message)
Appends a message to the back of this packet.
Definition: packetbb.cc:797
void PopFront(void)
Removes an AddressTLV from the front of this block.
Definition: packetbb.cc:380
uint32_t GetSerializedSize(void) const
Definition: packetbb.cc:2793
void PushFront(Ptr< PbbAddressTlv > tlv)
Prepends an Address TLV to the front of this block.
Definition: packetbb.cc:373
void SetSequenceNumber(uint16_t number)
Sets the sequence number of this packet.
Definition: packetbb.cc:567
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.
Definition: packetbb.cc:1148
int TlvSize(void) const
Definition: packetbb.cc:2100
automatically resized byte buffer
Definition: buffer.h:92
int PrefixSize(void) const
Definition: packetbb.cc:1986
void AddressBlockPopBack(void)
Removes an address block from the back of this message.
Definition: packetbb.cc:1369
void SetIndexStop(uint8_t index)
Sets the index of the last address in the associated address block that this address TLV applies to...
Definition: packetbb.cc:3052
TlvIterator TlvEnd()
Definition: packetbb.cc:1171
bool TlvEmpty(void) const
Definition: packetbb.cc:627
#define NS_ASSERT(condition)
Definition: assert.h:64
void TlvPushFront(Ptr< PbbTlv > tlv)
Prepends a packet TLV to the front of this packet.
Definition: packetbb.cc:662
#define NS_LOG_COMPONENT_DEFINE(name)
Definition: log.h:122
PbbAddressLength
Definition: packetbb.h:45
Ptr< PbbAddressBlock > AddressBlockBack(void)
Definition: packetbb.cc:1334
void PrefixPopBack(void)
Removes a prefix from the back of this block.
Definition: packetbb.cc:2035
bool HasTypeExt(void) const
Tests whether or not this TLV has a type extension.
Definition: packetbb.cc:2694
AddressIterator AddressEnd(void)
Definition: packetbb.cc:1864
void SetMultivalue(bool isMultivalue)
Sets whether or not this address TLV is "multivalue".
Definition: packetbb.cc:3073
A message within a PbbPacket packet.
Definition: packetbb.h:652
void MessageClear(void)
Removes all messages from this packet.
Definition: packetbb.cc:826
void PushBack(Ptr< PbbTlv > tlv)
Appends a TLV to the back of this block.
Definition: packetbb.cc:146
TlvIterator TlvBegin()
Definition: packetbb.cc:1157
Ptr< PbbAddressTlv > Back(void) const
Definition: packetbb.cc:366
void Print(std::ostream &os) const
Pretty-prints the contents of this block.
Definition: packetbb.cc:487
bool HasIndexStart(void) const
Tests whether or not this address TLV has a start index.
Definition: packetbb.cc:3045
bool HasIndexStop(void) const
Tests whether or not this address TLV has a stop index.
Definition: packetbb.cc:3066
void MessagePopFront(void)
Removes a message from the front of this packet.
Definition: packetbb.cc:790
void SetSequenceNumber(uint16_t seqnum)
Sets the sequence number of this message.
Definition: packetbb.cc:1132
void TlvPopBack(void)
Removes a message TLV from the back of this message.
Definition: packetbb.cc:1248
uint8_t GetIndexStart(void) const
Definition: packetbb.cc:3038
Ptr< PbbAddressTlv > TlvFront(void)
Definition: packetbb.cc:2114
bool IsMultivalue(void) const
Tests whether or not this address TLV is "multivalue".
Definition: packetbb.cc:3080
uint32_t GetDistanceFrom(Iterator const &o) const
Definition: buffer.cc:807
Ptr< PbbTlv > TlvBack(void)
Definition: packetbb.cc:648
iterator in a Buffer instance
Definition: buffer.h:98
a polymophic address class
Definition: address.h:86
MessageIterator MessageEnd(void)
Definition: packetbb.cc:727
AddressBlockIterator AddressBlockBegin()
Definition: packetbb.cc:1278
void SetType(uint8_t type)
Sets the type of this TLV.
Definition: packetbb.cc:2664
void PopBack(void)
Removes an Address TLV from the back of this block.
Definition: packetbb.cc:394
bool TlvEmpty(void) const
Definition: packetbb.cc:2107
bool AddressEmpty(void) const
Definition: packetbb.cc:1885
void AddressBlockClear(void)
Removes all address blocks from this message.
Definition: packetbb.cc:1391
bool IsEnd(void) const
Definition: buffer.cc:823
Address GetOriginatorAddress(void) const
Definition: packetbb.cc:1071
uint8_t GetTypeExt(void) const
Definition: packetbb.cc:2686
void TlvPushFront(Ptr< PbbAddressTlv > address)
Prepends an address TLV to the front of this message.
Definition: packetbb.cc:2142
Iterator Erase(Iterator position)
Removes the Address TLV at the specified position.
Definition: packetbb.cc:408
void AddressPopFront(void)
Removes an address from the front of this block.
Definition: packetbb.cc:1913
TlvIterator TlvBegin(void)
Definition: packetbb.cc:2072
TlvIterator Erase(TlvIterator position)
Removes the packet TLV at the specified position.
Definition: packetbb.cc:690
void SetIndexStart(uint8_t index)
Sets the index of the first address in the associated address block that this address TLV applies to...
Definition: packetbb.cc:3031
void Prev(void)
Definition: buffer.h:672
Ptr< PbbAddressTlv > TlvBack(void)
Definition: packetbb.cc:2128
uint8_t GetVersion(void) const
Definition: packetbb.cc:560
void PushBack(Ptr< PbbAddressTlv > tlv)
Appends an Address TLV to the back of this block.
Definition: packetbb.cc:387
void SetType(uint8_t type)
Sets the type for this message.
Definition: packetbb.cc:1042
void Serialize(Buffer::Iterator &start) const
Serializes this message into the specified buffer.
Definition: packetbb.cc:1443
void TlvPopBack(void)
Removes an address TLV from the back of this message.
Definition: packetbb.cc:2163
uint16_t GetSequenceNumber(void) const
Definition: packetbb.cc:575
int MessageSize(void) const
Definition: packetbb.cc:741
void AddressPushBack(Address address)
Appends an address to the back of this block.
Definition: packetbb.cc:1920
void WriteHtonU16(uint16_t data)
Definition: buffer.h:726
Address AddressFront(void) const
Definition: packetbb.cc:1892
void TlvClear(void)
Removes all message TLVs from this block.
Definition: packetbb.cc:1269
Ptr< PbbAddressBlock > AddressBlockFront(void)
Definition: packetbb.cc:1320
bool TlvEmpty(void) const
Definition: packetbb.cc:1192
TlvIterator TlvEnd(void)
Definition: packetbb.cc:2086
uint8_t PrefixBack(void) const
Definition: packetbb.cc:2007
Ptr< PbbTlv > Front(void) const
Definition: packetbb.cc:118
bool HasHopCount(void) const
Tests whether or not this message has a hop count.
Definition: packetbb.cc:1125
void Next(void)
Definition: buffer.h:666
uint8_t GetType(void) const
Definition: packetbb.cc:2671
void Print(std::ostream &os) const
Print this address to the given output stream.
bool Empty(void) const
Definition: packetbb.cc:352
Ptr< PbbTlv > Back(void) const
Definition: packetbb.cc:125
void Serialize(uint8_t buf[4]) const
void Deserialize(Buffer::Iterator &start)
Deserializes a block from the specified buffer.
Definition: packetbb.cc:469
uint32_t GetSerializedSize(void) const
Definition: packetbb.cc:192
void Print(std::ostream &os) const
Print this address to the given output stream.
int AddressBlockSize(void) const
Definition: packetbb.cc:1306
void Deserialize(Buffer::Iterator &start)
Deserializes a block from the specified buffer.
Definition: packetbb.cc:228
virtual uint32_t GetSerializedSize(void) const
Definition: packetbb.cc:854
Buffer::Iterator Begin(void) const
Definition: buffer.h:875
void Deserialize(Buffer::Iterator &start)
Deserializes a message from the specified buffer.
Definition: packetbb.cc:1533
void TlvPopFront(void)
Removes a message TLV from the front of this message.
Definition: packetbb.cc:1234
bool HasValue(void) const
Tests whether or not this TLV has a value.
Definition: packetbb.cc:2786
void Deserialize(Buffer::Iterator &start)
Deserializes a TLV from the specified buffer.
Definition: packetbb.cc:2888
void TlvPopBack(void)
Removes a packet TLV from the back of this block.
Definition: packetbb.cc:683
void SetHopLimit(uint8_t hoplimit)
Sets the maximum number of hops this message should travel.
Definition: packetbb.cc:1086
bool HasOriginatorAddress(void) const
Tests whether or not this message has an originator address.
Definition: packetbb.cc:1079
uint8_t PrefixFront(void) const
Definition: packetbb.cc:2000
void PrefixPushFront(uint8_t prefix)
Prepends a prefix to the front of this block.
Definition: packetbb.cc:2014
bool HasHopLimit(void) const
Tests whether or not this message has a hop limit.
Definition: packetbb.cc:1102
AddressBlockIterator AddressBlockErase(AddressBlockIterator position)
Removes the address block at the specified position.
Definition: packetbb.cc:1376
void Serialize(Buffer::Iterator &start) const
Serializes this address block into the specified buffer.
Definition: packetbb.cc:2239
void Print(std::ostream &os) const
Pretty-prints the contents of this TLV.
Definition: packetbb.cc:2933
int Size(void) const
Definition: packetbb.cc:345
void Print(std::ostream &os) const
Pretty-prints the contents of this address block.
Definition: packetbb.cc:2377
int TlvSize(void) const
Definition: packetbb.cc:620
void TlvClear(void)
Removes all address TLVs from this block.
Definition: packetbb.cc:2185
uint32_t GetSerializedSize(void) const
Definition: packetbb.cc:433
void PrefixPushBack(uint8_t prefix)
Appends a prefix to the back of this block.
Definition: packetbb.cc:2028
void Read(uint8_t *buffer, uint32_t size)
Definition: buffer.cc:1148
void AddressBlockPopFront(void)
Removes an address block from the front of this message.
Definition: packetbb.cc:1355
A block of packet or message TLVs (PbbTlv).
Definition: packetbb.h:55
uint8_t GetType(void) const
Definition: packetbb.cc:1049
bool MessageEmpty(void) const
Definition: packetbb.cc:748
uint32_t GetSize(void) const
Definition: buffer.h:869
uint8_t GetIndexStop(void) const
Definition: packetbb.cc:3059
void Print(std::ostream &os) const
Pretty-prints the contents of this block.
Definition: packetbb.cc:246
void TlvPushBack(Ptr< PbbAddressTlv > address)
Appends an address TLV to the back of this message.
Definition: packetbb.cc:2156
int AddressSize(void) const
Definition: packetbb.cc:1878
bool Empty(void) const
Definition: packetbb.cc:111
Iterator End(void)
Definition: packetbb.cc:90
A block of Address TLVs (PbbAddressTlv).
Definition: packetbb.h:207
uint8_t GetHopCount(void) const
Definition: packetbb.cc:1117
bool HasSequenceNumber(void) const
Tests whether or not this packet has a sequence number.
Definition: packetbb.cc:583
void PopBack(void)
Removes a TLV from the back of this block.
Definition: packetbb.cc:153
void TlvPopFront(void)
Removes a packet TLV from the front of this packet.
Definition: packetbb.cc:669
uint8_t GetHopLimit(void) const
Definition: packetbb.cc:1094
void WriteU8(uint8_t data)
Definition: buffer.h:690
PrefixIterator PrefixInsert(PrefixIterator position, const uint8_t value)
Inserts a prefix at the specified position in this block.
Definition: packetbb.cc:2042
Ptr< PbbTlv > TlvBack(void)
Definition: packetbb.cc:1213
TlvIterator TlvErase(TlvIterator position)
Removes the message TLV at the specified position.
Definition: packetbb.cc:1255
uint32_t GetSerializedSize(void) const
Definition: packetbb.cc:1404
void AddressBlockPushFront(Ptr< PbbAddressBlock > block)
Prepends an address block to the front of this message.
Definition: packetbb.cc:1348
void MessagePopBack(void)
Removes a message from the back of this packet.
Definition: packetbb.cc:804
Ptr< PbbTlv > TlvFront(void)
Definition: packetbb.cc:1199
Iterator Insert(Iterator position, const Ptr< PbbAddressTlv > tlv)
Inserts an Address TLV at the specified position in this block.
Definition: packetbb.cc:401
TlvIterator TlvEnd(void)
Definition: packetbb.cc:606
void SetTypeExt(uint8_t type)
Sets the type extension of this TLV.
Definition: packetbb.cc:2678
AddressIterator AddressBegin(void)
Definition: packetbb.cc:1850
int TlvSize(void) const
Definition: packetbb.cc:1185
void AddressClear(void)
Removes all addresses from this block.
Definition: packetbb.cc:1949
void SetHopCount(uint8_t hopcount)
Sets the current number of hops this message has traveled.
Definition: packetbb.cc:1109
Ptr< PbbTlv > TlvFront(void)
Definition: packetbb.cc:634
void PrefixPopFront(void)
Removes a prefix from the front of this block.
Definition: packetbb.cc:2021
uint8_t ReadU8(void)
Definition: buffer.h:819
Address AddressBack(void) const
Definition: packetbb.cc:1899
void Write(uint8_t const *buffer, uint32_t size)
Definition: buffer.cc:978
PrefixIterator PrefixErase(PrefixIterator position)
Removes the prefix at the specified position.
Definition: packetbb.cc:2049
void Serialize(Buffer::Iterator &start) const
Serializes this block into the specified buffer.
Definition: packetbb.cc:205
Iterator Begin(void)
Definition: packetbb.cc:76
void SetOriginatorAddress(Address address)
Sets the address for the node that created this packet.
Definition: packetbb.cc:1063
uint32_t GetSerializedSize(void) const
Definition: packetbb.cc:2191
void Deserialize(Buffer::Iterator &start)
Deserializes an address block from the specified buffer.
Definition: packetbb.cc:2323
Iterator Insert(Iterator position, const Ptr< PbbTlv > tlv)
Inserts a TLV at the specified position in this block.
Definition: packetbb.cc:160
void TlvPopFront(void)
Removes an address TLV from the front of this message.
Definition: packetbb.cc:2149
static Ipv4Address ConvertFrom(const Address &address)
bool AddAtStart(uint32_t start)
Definition: buffer.cc:305
Buffer GetValue(void) const
Definition: packetbb.cc:2778
void Clear(void)
Removes all Address TLVs from this block.
Definition: packetbb.cc:422
void SetValue(Buffer start)
Sets the value of this message to the specified buffer.
Definition: packetbb.cc:2761
Iterator Begin(void)
Definition: packetbb.cc:317
PrefixIterator PrefixBegin(void)
Definition: packetbb.cc:1958
virtual void Print(std::ostream &os) const
Pretty-prints the contents of this block.
Definition: packetbb.cc:950
Ptr< PbbMessage > MessageFront(void)
Definition: packetbb.cc:755
void TlvPushFront(Ptr< PbbTlv > tlv)
Prepends a message TLV to the front of this message.
Definition: packetbb.cc:1227
MessageIterator MessageBegin(void)
Definition: packetbb.cc:713
uint16_t ReadNtohU16(void)
Definition: buffer.h:767
void Clear(void)
Removes all TLVs from this block.
Definition: packetbb.cc:181
Iterator End(void)
Definition: packetbb.cc:331
AddressIterator AddressErase(AddressIterator position)
Removes the address at the specified position.
Definition: packetbb.cc:1934
void AddressPopBack(void)
Removes an address from the back of this block.
Definition: packetbb.cc:1927
void Serialize(Buffer::Iterator &start) const
Serializes this block into the specified buffer.
Definition: packetbb.cc:446
a unique identifier for an interface.
Definition: type-id.h:44
virtual void Serialize(Buffer::Iterator start) const
Serializes this packet into the specified buffer.
Definition: packetbb.cc:881
TypeId SetParent(TypeId tid)
Definition: type-id.cc:471
static Ptr< PbbMessage > DeserializeMessage(Buffer::Iterator &start)
Deserializes a message, returning the correct object depending on whether it is an IPv4 message or an...
Definition: packetbb.cc:1500
bool AddressBlockEmpty(void) const
Definition: packetbb.cc:1313
An Address Block and its associated Address TLV Blocks.
Definition: packetbb.h:1089
void Serialize(Buffer::Iterator &start) const
Serializes this TLV into the specified buffer.
Definition: packetbb.cc:2831
void TlvPushBack(Ptr< PbbTlv > tlv)
Appends a message TLV to the back of this message.
Definition: packetbb.cc:1241
virtual TypeId GetInstanceTypeId(void) const
Definition: packetbb.cc:848
void AddressPushFront(Address address)
Prepends an address to the front of this block.
Definition: packetbb.cc:1906
void PrefixClear(void)
Removes all prefixes from this block.
Definition: packetbb.cc:2063
bool PrefixEmpty(void) const
Definition: packetbb.cc:1993
Ptr< PbbAddressTlv > Front(void) const
Definition: packetbb.cc:359
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserializes a packet from the specified buffer.
Definition: packetbb.cc:916
static Ipv6Address ConvertFrom(const Address &address)
Convert the Address object into an Ipv6Address ones.
void TlvClear(void)
Removes all packet TLVs from this packet.
Definition: packetbb.cc:704
TlvIterator TlvErase(TlvIterator position)
Removes the address TLV at the specified position.
Definition: packetbb.cc:2170
Iterator Erase(Iterator position)
Removes the TLV at the specified position.
Definition: packetbb.cc:167
void PopFront(void)
Removes a TLV from the front of this block.
Definition: packetbb.cc:139
void Serialize(uint8_t buf[16]) const
Serialize this address to a 16-byte buffer.