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