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