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