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
284/* End PbbTlvBlock class */
285
290
296
299{
300 NS_LOG_FUNCTION(this);
301 return m_tlvList.begin();
302}
303
306{
307 NS_LOG_FUNCTION(this);
308 return m_tlvList.begin();
309}
310
313{
314 NS_LOG_FUNCTION(this);
315 return m_tlvList.end();
316}
317
320{
321 NS_LOG_FUNCTION(this);
322 return m_tlvList.end();
323}
324
325int
327{
328 NS_LOG_FUNCTION(this);
329 return m_tlvList.size();
330}
331
332bool
334{
335 NS_LOG_FUNCTION(this);
336 return m_tlvList.empty();
337}
338
341{
342 NS_LOG_FUNCTION(this);
343 return m_tlvList.front();
344}
345
348{
349 NS_LOG_FUNCTION(this);
350 return m_tlvList.back();
351}
352
353void
355{
356 NS_LOG_FUNCTION(this << tlv);
357 m_tlvList.push_front(tlv);
358}
359
360void
362{
363 NS_LOG_FUNCTION(this);
364 m_tlvList.pop_front();
365}
366
367void
369{
370 NS_LOG_FUNCTION(this << tlv);
371 m_tlvList.push_back(tlv);
372}
373
374void
376{
377 NS_LOG_FUNCTION(this);
378 m_tlvList.pop_back();
379}
380
383{
384 NS_LOG_FUNCTION(this << &position << tlv);
385 return m_tlvList.insert(position, tlv);
386}
387
390{
391 NS_LOG_FUNCTION(this << &position);
392 return m_tlvList.erase(position);
393}
394
401
402void
404{
405 NS_LOG_FUNCTION(this);
406 for (auto iter = Begin(); iter != End(); iter++)
407 {
408 *iter = nullptr;
409 }
410 m_tlvList.clear();
411}
412
415{
416 NS_LOG_FUNCTION(this);
417 /* tlv size */
418 uint32_t size = 2;
419 for (auto iter = Begin(); iter != End(); iter++)
420 {
421 size += (*iter)->GetSerializedSize();
422 }
423 return size;
424}
425
426void
428{
429 NS_LOG_FUNCTION(this << &start);
430 if (Empty())
431 {
432 start.WriteHtonU16(0);
433 return;
434 }
435
436 /* We need to write the size of the TLV block in front, so save its
437 * position. */
438 Buffer::Iterator tlvsize = start;
439 start.Next(2);
440 for (auto iter = Begin(); iter != End(); iter++)
441 {
442 (*iter)->Serialize(start);
443 }
444 /* - 2 to not include the size field */
445 uint16_t size = start.GetDistanceFrom(tlvsize) - 2;
446 tlvsize.WriteHtonU16(size);
447}
448
449void
451{
452 NS_LOG_FUNCTION(this << &start);
453 uint16_t size = start.ReadNtohU16();
454
455 Buffer::Iterator tlvstart = start;
456 if (size > 0)
457 {
458 while (start.GetDistanceFrom(tlvstart) < size)
459 {
461 newtlv->Deserialize(start);
462 PushBack(newtlv);
463 }
464 }
465}
466
467void
468PbbAddressTlvBlock::Print(std::ostream& os) const
469{
470 NS_LOG_FUNCTION(this << &os);
471 Print(os, 0);
472}
473
474void
475PbbAddressTlvBlock::Print(std::ostream& os, int level) const
476{
477 NS_LOG_FUNCTION(this << &os << level);
478 std::string prefix = "";
479 for (int i = 0; i < level; i++)
480 {
481 prefix.append("\t");
482 }
483
484 os << prefix << "TLV Block {" << std::endl;
485 os << prefix << "\tsize = " << Size() << std::endl;
486 os << prefix << "\tmembers [" << std::endl;
487
488 for (auto iter = Begin(); iter != End(); iter++)
489 {
490 (*iter)->Print(os, level + 2);
491 }
492
493 os << prefix << "\t]" << std::endl;
494 os << prefix << "}" << std::endl;
495}
496
497bool
499{
500 if (Size() != other.Size())
501 {
502 return false;
503 }
504
505 ConstIterator it;
506 ConstIterator ot;
507 for (it = Begin(), ot = other.Begin(); it != End() && ot != other.End(); it++, ot++)
508 {
509 if (**it != **ot)
510 {
511 return false;
512 }
513 }
514 return true;
515}
516
517/* End PbbAddressTlvBlock Class */
518
520{
521 NS_LOG_FUNCTION(this);
523 m_hasseqnum = false;
524 m_forceTlv = false;
525}
526
532
533uint8_t
535{
536 NS_LOG_FUNCTION(this);
537 return m_version;
538}
539
540void
542{
543 NS_LOG_FUNCTION(this << number);
544 m_seqnum = number;
545 m_hasseqnum = true;
546}
547
548uint16_t
550{
551 NS_LOG_FUNCTION(this);
553 return m_seqnum;
554}
555
556bool
558{
559 NS_LOG_FUNCTION(this);
560 return m_hasseqnum;
561}
562
563void
565{
566 NS_LOG_FUNCTION(this);
567 m_forceTlv = forceTlv;
568}
569
570/* Manipulating Packet TLVs */
571
574{
575 NS_LOG_FUNCTION(this);
576 return m_tlvList.Begin();
577}
578
581{
582 NS_LOG_FUNCTION(this);
583 return m_tlvList.Begin();
584}
585
588{
589 NS_LOG_FUNCTION(this);
590 return m_tlvList.End();
591}
592
595{
596 NS_LOG_FUNCTION(this);
597 return m_tlvList.End();
598}
599
600int
602{
603 NS_LOG_FUNCTION(this);
604 return m_tlvList.Size();
605}
606
607bool
609{
610 NS_LOG_FUNCTION(this);
611 return m_tlvList.Empty();
612}
613
616{
617 NS_LOG_FUNCTION(this);
618 return m_tlvList.Front();
619}
620
621const Ptr<PbbTlv>
623{
624 NS_LOG_FUNCTION(this);
625 return m_tlvList.Front();
626}
627
630{
631 NS_LOG_FUNCTION(this);
632 return m_tlvList.Back();
633}
634
635const Ptr<PbbTlv>
637{
638 NS_LOG_FUNCTION(this);
639 return m_tlvList.Back();
640}
641
642void
644{
645 NS_LOG_FUNCTION(this << tlv);
646 m_tlvList.PushFront(tlv);
647}
648
649void
651{
652 NS_LOG_FUNCTION(this);
653 m_tlvList.PopFront();
654}
655
656void
658{
659 NS_LOG_FUNCTION(this << tlv);
660 m_tlvList.PushBack(tlv);
661}
662
663void
665{
666 NS_LOG_FUNCTION(this);
667 m_tlvList.PopBack();
668}
669
672{
673 NS_LOG_FUNCTION(this << &position);
674 return m_tlvList.Erase(position);
675}
676
679{
680 NS_LOG_FUNCTION(this << &first << &last);
681 return m_tlvList.Erase(first, last);
682}
683
684void
686{
687 NS_LOG_FUNCTION(this);
688 m_tlvList.Clear();
689}
690
691/* Manipulating Packet Messages */
692
695{
696 NS_LOG_FUNCTION(this);
697 return m_messageList.begin();
698}
699
702{
703 NS_LOG_FUNCTION(this);
704 return m_messageList.begin();
705}
706
709{
710 NS_LOG_FUNCTION(this);
711 return m_messageList.end();
712}
713
716{
717 NS_LOG_FUNCTION(this);
718 return m_messageList.end();
719}
720
721int
723{
724 NS_LOG_FUNCTION(this);
725 return m_messageList.size();
726}
727
728bool
730{
731 NS_LOG_FUNCTION(this);
732 return m_messageList.empty();
733}
734
737{
738 NS_LOG_FUNCTION(this);
739 return m_messageList.front();
740}
741
742const Ptr<PbbMessage>
744{
745 NS_LOG_FUNCTION(this);
746 return m_messageList.front();
747}
748
751{
752 NS_LOG_FUNCTION(this);
753 return m_messageList.back();
754}
755
756const Ptr<PbbMessage>
758{
759 NS_LOG_FUNCTION(this);
760 return m_messageList.back();
761}
762
763void
765{
766 NS_LOG_FUNCTION(this << tlv);
767 m_messageList.push_front(tlv);
768}
769
770void
772{
773 NS_LOG_FUNCTION(this);
774 m_messageList.pop_front();
775}
776
777void
779{
780 NS_LOG_FUNCTION(this << tlv);
781 m_messageList.push_back(tlv);
782}
783
784void
786{
787 NS_LOG_FUNCTION(this);
788 m_messageList.pop_back();
789}
790
793{
794 NS_LOG_FUNCTION(this << &position);
795 return m_messageList.erase(position);
796}
797
800{
801 NS_LOG_FUNCTION(this << &first << &last);
802 return m_messageList.erase(first, last);
803}
804
805void
807{
808 NS_LOG_FUNCTION(this);
809 for (auto iter = MessageBegin(); iter != MessageEnd(); iter++)
810 {
811 *iter = nullptr;
812 }
813 m_messageList.clear();
814}
815
816TypeId
818{
819 static TypeId tid = TypeId("ns3::PbbPacket")
820 .SetParent<Header>()
821 .SetGroupName("Network")
822 .AddConstructor<PbbPacket>();
823 return tid;
824}
825
826TypeId
828{
829 return GetTypeId();
830}
831
834{
835 NS_LOG_FUNCTION(this);
836 /* Version number + flags */
837 uint32_t size = 1;
838
839 if (HasSequenceNumber())
840 {
841 size += 2;
842 }
843
844 if (!TlvEmpty() || m_forceTlv)
845 {
846 size += m_tlvList.GetSerializedSize();
847 }
848
849 for (auto iter = MessageBegin(); iter != MessageEnd(); iter++)
850 {
851 size += (*iter)->GetSerializedSize();
852 }
853
854 return size;
855}
856
857void
859{
860 NS_LOG_FUNCTION(this << &start);
861 /* We remember the start, so we can write the flags after we check for a
862 * sequence number and TLV. */
863 Buffer::Iterator bufref = start;
864 start.Next();
865
866 uint8_t flags = VERSION;
867 /* Make room for 4 bit flags */
868 flags <<= 4;
869
870 if (HasSequenceNumber())
871 {
872 flags |= PHAS_SEQ_NUM;
873 start.WriteHtonU16(GetSequenceNumber());
874 }
875
876 if (!TlvEmpty() || m_forceTlv)
877 {
878 flags |= PHAS_TLV;
879 m_tlvList.Serialize(start);
880 }
881
882 bufref.WriteU8(flags);
883
884 for (auto iter = MessageBegin(); iter != MessageEnd(); iter++)
885 {
886 (*iter)->Serialize(start);
887 }
888}
889
892{
893 NS_LOG_FUNCTION(this << &start);
894 Buffer::Iterator begin = start;
895
896 uint8_t flags = start.ReadU8();
897
898 if (flags & PHAS_SEQ_NUM)
899 {
900 SetSequenceNumber(start.ReadNtohU16());
901 }
902
903 if (flags & PHAS_TLV)
904 {
905 m_tlvList.Deserialize(start);
906 }
907
908 while (!start.IsEnd())
909 {
911 if (!newmsg)
912 {
913 return start.GetDistanceFrom(begin);
914 }
915 MessagePushBack(newmsg);
916 }
917
918 flags >>= 4;
919 m_version = flags;
920
921 return start.GetDistanceFrom(begin);
922}
923
924void
925PbbPacket::Print(std::ostream& os) const
926{
927 NS_LOG_FUNCTION(this << &os);
928 os << "PbbPacket {" << std::endl;
929
930 if (HasSequenceNumber())
931 {
932 os << "\tsequence number = " << GetSequenceNumber();
933 }
934
935 os << std::endl;
936
937 m_tlvList.Print(os, 1);
938
939 for (auto iter = MessageBegin(); iter != MessageEnd(); iter++)
940 {
941 (*iter)->Print(os, 1);
942 }
943
944 os << "}" << std::endl;
945}
946
947bool
949{
950 if (GetVersion() != other.GetVersion())
951 {
952 return false;
953 }
954
955 if (HasSequenceNumber() != other.HasSequenceNumber())
956 {
957 return false;
958 }
959
960 if (HasSequenceNumber())
961 {
962 if (GetSequenceNumber() != other.GetSequenceNumber())
963 {
964 return false;
965 }
966 }
967
968 if (m_tlvList != other.m_tlvList)
969 {
970 return false;
971 }
972
973 if (MessageSize() != other.MessageSize())
974 {
975 return false;
976 }
977
980 for (tmi = MessageBegin(), omi = other.MessageBegin();
981 tmi != MessageEnd() && omi != other.MessageEnd();
982 tmi++, omi++)
983 {
984 if (**tmi != **omi)
985 {
986 return false;
987 }
988 }
989 return true;
990}
991
992/* End PbbPacket class */
993
995{
996 NS_LOG_FUNCTION(this);
997 /* Default to IPv4 */
1000 m_hasHopLimit = false;
1001 m_hasHopCount = false;
1002 m_hasSequenceNumber = false;
1003}
1004
1010
1011void
1013{
1014 NS_LOG_FUNCTION(this << static_cast<uint32_t>(type));
1015 m_type = type;
1016}
1017
1018uint8_t
1020{
1021 NS_LOG_FUNCTION(this);
1022 return m_type;
1023}
1024
1027{
1028 NS_LOG_FUNCTION(this);
1029 return m_addrSize;
1030}
1031
1032void
1034{
1035 NS_LOG_FUNCTION(this << address);
1036 m_originatorAddress = address;
1038}
1039
1040Address
1047
1048bool
1054
1055void
1057{
1058 NS_LOG_FUNCTION(this << static_cast<uint32_t>(hopLimit));
1059 m_hopLimit = hopLimit;
1060 m_hasHopLimit = true;
1061}
1062
1063uint8_t
1065{
1066 NS_LOG_FUNCTION(this);
1068 return m_hopLimit;
1069}
1070
1071bool
1073{
1074 NS_LOG_FUNCTION(this);
1075 return m_hasHopLimit;
1076}
1077
1078void
1080{
1081 NS_LOG_FUNCTION(this << static_cast<uint32_t>(hopCount));
1082 m_hopCount = hopCount;
1083 m_hasHopCount = true;
1084}
1085
1086uint8_t
1088{
1089 NS_LOG_FUNCTION(this);
1091 return m_hopCount;
1092}
1093
1094bool
1096{
1097 NS_LOG_FUNCTION(this);
1098 return m_hasHopCount;
1099}
1100
1101void
1102PbbMessage::SetSequenceNumber(uint16_t sequenceNumber)
1103{
1104 NS_LOG_FUNCTION(this << sequenceNumber);
1105 m_sequenceNumber = sequenceNumber;
1106 m_hasSequenceNumber = true;
1107}
1108
1109uint16_t
1116
1117bool
1119{
1120 NS_LOG_FUNCTION(this);
1121 return m_hasSequenceNumber;
1122}
1123
1124/* Manipulating PbbMessage TLVs */
1125
1128{
1129 NS_LOG_FUNCTION(this);
1130 return m_tlvList.Begin();
1131}
1132
1135{
1136 NS_LOG_FUNCTION(this);
1137 return m_tlvList.Begin();
1138}
1139
1142{
1143 NS_LOG_FUNCTION(this);
1144 return m_tlvList.End();
1145}
1146
1149{
1150 NS_LOG_FUNCTION(this);
1151 return m_tlvList.End();
1152}
1153
1154int
1156{
1157 NS_LOG_FUNCTION(this);
1158 return m_tlvList.Size();
1159}
1160
1161bool
1163{
1164 NS_LOG_FUNCTION(this);
1165 return m_tlvList.Empty();
1166}
1167
1170{
1171 NS_LOG_FUNCTION(this);
1172 return m_tlvList.Front();
1173}
1174
1175const Ptr<PbbTlv>
1177{
1178 NS_LOG_FUNCTION(this);
1179 return m_tlvList.Front();
1180}
1181
1184{
1185 NS_LOG_FUNCTION(this);
1186 return m_tlvList.Back();
1187}
1188
1189const Ptr<PbbTlv>
1191{
1192 NS_LOG_FUNCTION(this);
1193 return m_tlvList.Back();
1194}
1195
1196void
1198{
1199 NS_LOG_FUNCTION(this << tlv);
1200 m_tlvList.PushFront(tlv);
1201}
1202
1203void
1205{
1206 NS_LOG_FUNCTION(this);
1207 m_tlvList.PopFront();
1208}
1209
1210void
1212{
1213 NS_LOG_FUNCTION(this << tlv);
1214 m_tlvList.PushBack(tlv);
1215}
1216
1217void
1219{
1220 NS_LOG_FUNCTION(this);
1221 m_tlvList.PopBack();
1222}
1223
1226{
1227 NS_LOG_FUNCTION(this << &position);
1228 return m_tlvList.Erase(position);
1229}
1230
1233{
1234 NS_LOG_FUNCTION(this << &first << &last);
1235 return m_tlvList.Erase(first, last);
1236}
1237
1238void
1240{
1241 NS_LOG_FUNCTION(this);
1242 m_tlvList.Clear();
1243}
1244
1245/* Manipulating Address Block and Address TLV pairs */
1246
1249{
1250 NS_LOG_FUNCTION(this);
1251 return m_addressBlockList.begin();
1252}
1253
1256{
1257 NS_LOG_FUNCTION(this);
1258 return m_addressBlockList.begin();
1259}
1260
1263{
1264 NS_LOG_FUNCTION(this);
1265 return m_addressBlockList.end();
1266}
1267
1270{
1271 NS_LOG_FUNCTION(this);
1272 return m_addressBlockList.end();
1273}
1274
1275int
1277{
1278 NS_LOG_FUNCTION(this);
1279 return m_addressBlockList.size();
1280}
1281
1282bool
1284{
1285 NS_LOG_FUNCTION(this);
1286 return m_addressBlockList.empty();
1287}
1288
1291{
1292 NS_LOG_FUNCTION(this);
1293 return m_addressBlockList.front();
1294}
1295
1298{
1299 NS_LOG_FUNCTION(this);
1300 return m_addressBlockList.front();
1301}
1302
1305{
1306 NS_LOG_FUNCTION(this);
1307 return m_addressBlockList.back();
1308}
1309
1312{
1313 NS_LOG_FUNCTION(this);
1314 return m_addressBlockList.back();
1315}
1316
1317void
1319{
1320 NS_LOG_FUNCTION(this << tlv);
1321 m_addressBlockList.push_front(tlv);
1322}
1323
1324void
1326{
1327 NS_LOG_FUNCTION(this);
1328 m_addressBlockList.pop_front();
1329}
1330
1331void
1333{
1334 NS_LOG_FUNCTION(this << tlv);
1335 m_addressBlockList.push_back(tlv);
1336}
1337
1338void
1340{
1341 NS_LOG_FUNCTION(this);
1342 m_addressBlockList.pop_back();
1343}
1344
1347{
1348 NS_LOG_FUNCTION(this << &position);
1349 return m_addressBlockList.erase(position);
1350}
1351
1359
1360void
1362{
1363 NS_LOG_FUNCTION(this);
1364 for (auto iter = AddressBlockBegin(); iter != AddressBlockEnd(); iter++)
1365 {
1366 *iter = nullptr;
1367 }
1368 return m_addressBlockList.clear();
1369}
1370
1373{
1374 NS_LOG_FUNCTION(this);
1375 /* msg-type + (msg-flags + msg-addr-length) + 2msg-size */
1376 uint32_t size = 4;
1377
1379 {
1380 size += GetAddressLength() + 1;
1381 }
1382
1383 if (HasHopLimit())
1384 {
1385 size++;
1386 }
1387
1388 if (HasHopCount())
1389 {
1390 size++;
1391 }
1392
1393 if (HasSequenceNumber())
1394 {
1395 size += 2;
1396 }
1397
1398 size += m_tlvList.GetSerializedSize();
1399
1400 for (auto iter = AddressBlockBegin(); iter != AddressBlockEnd(); iter++)
1401 {
1402 size += (*iter)->GetSerializedSize();
1403 }
1404
1405 return size;
1406}
1407
1408void
1410{
1411 NS_LOG_FUNCTION(this << &start);
1412 Buffer::Iterator front = start;
1413
1414 start.WriteU8(GetType());
1415
1416 /* Save a reference to the spot where we will later write the flags */
1417 Buffer::Iterator bufref = start;
1418 start.Next(1);
1419
1420 uint8_t flags = 0;
1421
1422 flags = GetAddressLength();
1423
1424 Buffer::Iterator sizeref = start;
1425 start.Next(2);
1426
1428 {
1429 flags |= MHAS_ORIG;
1431 }
1432
1433 if (HasHopLimit())
1434 {
1435 flags |= MHAS_HOP_LIMIT;
1436 start.WriteU8(GetHopLimit());
1437 }
1438
1439 if (HasHopCount())
1440 {
1441 flags |= MHAS_HOP_COUNT;
1442 start.WriteU8(GetHopCount());
1443 }
1444
1445 if (HasSequenceNumber())
1446 {
1447 flags |= MHAS_SEQ_NUM;
1448 start.WriteHtonU16(GetSequenceNumber());
1449 }
1450
1451 bufref.WriteU8(flags);
1452
1453 m_tlvList.Serialize(start);
1454
1455 for (auto iter = AddressBlockBegin(); iter != AddressBlockEnd(); iter++)
1456 {
1457 (*iter)->Serialize(start);
1458 }
1459
1460 sizeref.WriteHtonU16(front.GetDistanceFrom(start));
1461}
1462
1465{
1466 NS_LOG_FUNCTION(&start);
1467 /* We need to read the msg-addr-len field to determine what kind of object to
1468 * construct. */
1469 start.Next();
1470 uint8_t addrlen = start.ReadU8();
1471 start.Prev(2); /* Go back to the start */
1472
1473 /* The first four bytes of the flag is the address length. Set the last four
1474 * bytes to 0 to read it. */
1475 addrlen = (addrlen & 0xf);
1476
1477 Ptr<PbbMessage> newmsg;
1478
1479 switch (addrlen)
1480 {
1481 case 0:
1482 case IPV4:
1483 newmsg = Create<PbbMessageIpv4>();
1484 break;
1485 case IPV6:
1486 newmsg = Create<PbbMessageIpv6>();
1487 break;
1488 default:
1489 return nullptr;
1490 }
1491 newmsg->Deserialize(start);
1492 return newmsg;
1493}
1494
1495void
1497{
1498 NS_LOG_FUNCTION(this << &start);
1499 Buffer::Iterator front = start;
1500 SetType(start.ReadU8());
1501 uint8_t flags = start.ReadU8();
1502
1503 uint16_t size = start.ReadNtohU16();
1504
1505 if (flags & MHAS_ORIG)
1506 {
1508 }
1509
1510 if (flags & MHAS_HOP_LIMIT)
1511 {
1512 SetHopLimit(start.ReadU8());
1513 }
1514
1515 if (flags & MHAS_HOP_COUNT)
1516 {
1517 SetHopCount(start.ReadU8());
1518 }
1519
1520 if (flags & MHAS_SEQ_NUM)
1521 {
1522 SetSequenceNumber(start.ReadNtohU16());
1523 }
1524
1525 m_tlvList.Deserialize(start);
1526
1527 if (size > 0)
1528 {
1529 while (start.GetDistanceFrom(front) < size)
1530 {
1532 AddressBlockPushBack(newab);
1533 }
1534 }
1535}
1536
1537void
1538PbbMessage::Print(std::ostream& os) const
1539{
1540 NS_LOG_FUNCTION(this << &os);
1541 Print(os, 0);
1542}
1543
1544void
1545PbbMessage::Print(std::ostream& os, int level) const
1546{
1547 NS_LOG_FUNCTION(this << &os << level);
1548 std::string prefix = "";
1549 for (int i = 0; i < level; i++)
1550 {
1551 prefix.append("\t");
1552 }
1553
1554 os << prefix << "PbbMessage {" << std::endl;
1555
1556 os << prefix << "\tmessage type = " << (int)GetType() << std::endl;
1557 os << prefix << "\taddress size = " << GetAddressLength() << std::endl;
1558
1560 {
1561 os << prefix << "\toriginator address = ";
1563 os << std::endl;
1564 }
1565
1566 if (HasHopLimit())
1567 {
1568 os << prefix << "\thop limit = " << (int)GetHopLimit() << std::endl;
1569 }
1570
1571 if (HasHopCount())
1572 {
1573 os << prefix << "\thop count = " << (int)GetHopCount() << std::endl;
1574 }
1575
1576 if (HasSequenceNumber())
1577 {
1578 os << prefix << "\tseqnum = " << GetSequenceNumber() << std::endl;
1579 }
1580
1581 m_tlvList.Print(os, level + 1);
1582
1583 for (auto iter = AddressBlockBegin(); iter != AddressBlockEnd(); iter++)
1584 {
1585 (*iter)->Print(os, level + 1);
1586 }
1587 os << prefix << "}" << std::endl;
1588}
1589
1590bool
1592{
1593 if (GetAddressLength() != other.GetAddressLength())
1594 {
1595 return false;
1596 }
1597
1598 if (GetType() != other.GetType())
1599 {
1600 return false;
1601 }
1602
1604 {
1605 return false;
1606 }
1607
1609 {
1611 {
1612 return false;
1613 }
1614 }
1615
1616 if (HasHopLimit() != other.HasHopLimit())
1617 {
1618 return false;
1619 }
1620
1621 if (HasHopLimit())
1622 {
1623 if (GetHopLimit() != other.GetHopLimit())
1624 {
1625 return false;
1626 }
1627 }
1628
1629 if (HasHopCount() != other.HasHopCount())
1630 {
1631 return false;
1632 }
1633
1634 if (HasHopCount())
1635 {
1636 if (GetHopCount() != other.GetHopCount())
1637 {
1638 return false;
1639 }
1640 }
1641
1642 if (HasSequenceNumber() != other.HasSequenceNumber())
1643 {
1644 return false;
1645 }
1646
1647 if (HasSequenceNumber())
1648 {
1649 if (GetSequenceNumber() != other.GetSequenceNumber())
1650 {
1651 return false;
1652 }
1653 }
1654
1655 if (m_tlvList != other.m_tlvList)
1656 {
1657 return false;
1658 }
1659
1660 if (AddressBlockSize() != other.AddressBlockSize())
1661 {
1662 return false;
1663 }
1664
1667 for (tai = AddressBlockBegin(), oai = other.AddressBlockBegin();
1668 tai != AddressBlockEnd() && oai != other.AddressBlockEnd();
1669 tai++, oai++)
1670 {
1671 if (**tai != **oai)
1672 {
1673 return false;
1674 }
1675 }
1676 return true;
1677}
1678
1679/* End PbbMessage Class */
1680
1685
1688{
1689 NS_LOG_FUNCTION(this);
1690 return IPV4;
1691}
1692
1693void
1695{
1696 NS_LOG_FUNCTION(this << &start);
1697 auto buffer = new uint8_t[GetAddressLength() + 1];
1699 start.Write(buffer, GetAddressLength() + 1);
1700 delete[] buffer;
1701}
1702
1703Address
1705{
1706 NS_LOG_FUNCTION(this << &start);
1707 auto buffer = new uint8_t[GetAddressLength() + 1];
1708 start.Read(buffer, GetAddressLength() + 1);
1710 delete[] buffer;
1711 return result;
1712}
1713
1714void
1716{
1717 NS_LOG_FUNCTION(this << &os);
1719}
1720
1723{
1724 NS_LOG_FUNCTION(this << &start);
1726 newab->Deserialize(start);
1727 return newab;
1728}
1729
1730/* End PbbMessageIpv4 Class */
1731
1736
1739{
1740 NS_LOG_FUNCTION(this);
1741 return IPV6;
1742}
1743
1744void
1746{
1747 NS_LOG_FUNCTION(this << &start);
1748 auto buffer = new uint8_t[GetAddressLength() + 1];
1750 start.Write(buffer, GetAddressLength() + 1);
1751 delete[] buffer;
1752}
1753
1754Address
1756{
1757 NS_LOG_FUNCTION(this << &start);
1758 auto buffer = new uint8_t[GetAddressLength() + 1];
1759 start.Read(buffer, GetAddressLength() + 1);
1760 Address res = Ipv6Address::Deserialize(buffer);
1761 delete[] buffer;
1762 return res;
1763}
1764
1765void
1767{
1768 NS_LOG_FUNCTION(this << &os);
1770}
1771
1774{
1775 NS_LOG_FUNCTION(this << &start);
1777 newab->Deserialize(start);
1778 return newab;
1779}
1780
1781/* End PbbMessageIpv6 Class */
1782
1787
1792
1793/* Manipulating the address block */
1794
1797{
1798 NS_LOG_FUNCTION(this);
1799 return m_addressList.begin();
1800}
1801
1804{
1805 NS_LOG_FUNCTION(this);
1806 return m_addressList.begin();
1807}
1808
1811{
1812 NS_LOG_FUNCTION(this);
1813 return m_addressList.end();
1814}
1815
1818{
1819 NS_LOG_FUNCTION(this);
1820 return m_addressList.end();
1821}
1822
1823int
1825{
1826 NS_LOG_FUNCTION(this);
1827 return m_addressList.size();
1828}
1829
1830bool
1832{
1833 NS_LOG_FUNCTION(this);
1834 return m_addressList.empty();
1835}
1836
1837Address
1839{
1840 NS_LOG_FUNCTION(this);
1841 return m_addressList.front();
1842}
1843
1844Address
1846{
1847 NS_LOG_FUNCTION(this);
1848 return m_addressList.back();
1849}
1850
1851void
1853{
1854 NS_LOG_FUNCTION(this << tlv);
1855 m_addressList.push_front(tlv);
1856}
1857
1858void
1860{
1861 NS_LOG_FUNCTION(this);
1862 m_addressList.pop_front();
1863}
1864
1865void
1867{
1868 NS_LOG_FUNCTION(this << tlv);
1869 m_addressList.push_back(tlv);
1870}
1871
1872void
1874{
1875 NS_LOG_FUNCTION(this);
1876 m_addressList.pop_back();
1877}
1878
1881{
1882 NS_LOG_FUNCTION(this << &position);
1883 return m_addressList.erase(position);
1884}
1885
1893
1894void
1896{
1897 NS_LOG_FUNCTION(this);
1898 return m_addressList.clear();
1899}
1900
1901/* Manipulating the prefix list */
1902
1905{
1906 NS_LOG_FUNCTION(this);
1907 return m_prefixList.begin();
1908}
1909
1912{
1913 NS_LOG_FUNCTION(this);
1914 return m_prefixList.begin();
1915}
1916
1919{
1920 NS_LOG_FUNCTION(this);
1921 return m_prefixList.end();
1922}
1923
1926{
1927 NS_LOG_FUNCTION(this);
1928 return m_prefixList.end();
1929}
1930
1931int
1933{
1934 NS_LOG_FUNCTION(this);
1935 return m_prefixList.size();
1936}
1937
1938bool
1940{
1941 NS_LOG_FUNCTION(this);
1942 return m_prefixList.empty();
1943}
1944
1945uint8_t
1947{
1948 NS_LOG_FUNCTION(this);
1949 return m_prefixList.front();
1950}
1951
1952uint8_t
1954{
1955 NS_LOG_FUNCTION(this);
1956 return m_prefixList.back();
1957}
1958
1959void
1961{
1962 NS_LOG_FUNCTION(this << static_cast<uint32_t>(prefix));
1963 m_prefixList.push_front(prefix);
1964}
1965
1966void
1968{
1969 NS_LOG_FUNCTION(this);
1970 m_prefixList.pop_front();
1971}
1972
1973void
1975{
1976 NS_LOG_FUNCTION(this << static_cast<uint32_t>(prefix));
1977 m_prefixList.push_back(prefix);
1978}
1979
1980void
1982{
1983 NS_LOG_FUNCTION(this);
1984 m_prefixList.pop_back();
1985}
1986
1989{
1990 NS_LOG_FUNCTION(this << &position << static_cast<uint32_t>(value));
1991 return m_prefixList.insert(position, value);
1992}
1993
1996{
1997 NS_LOG_FUNCTION(this << &position);
1998 return m_prefixList.erase(position);
1999}
2000
2008
2009void
2011{
2012 NS_LOG_FUNCTION(this);
2013 m_prefixList.clear();
2014}
2015
2016/* Manipulating the TLV block */
2017
2020{
2021 NS_LOG_FUNCTION(this);
2022 return m_addressTlvList.Begin();
2023}
2024
2027{
2028 NS_LOG_FUNCTION(this);
2029 return m_addressTlvList.Begin();
2030}
2031
2034{
2035 NS_LOG_FUNCTION(this);
2036 return m_addressTlvList.End();
2037}
2038
2041{
2042 NS_LOG_FUNCTION(this);
2043 return m_addressTlvList.End();
2044}
2045
2046int
2048{
2049 NS_LOG_FUNCTION(this);
2050 return m_addressTlvList.Size();
2051}
2052
2053bool
2055{
2056 NS_LOG_FUNCTION(this);
2057 return m_addressTlvList.Empty();
2058}
2059
2062{
2063 NS_LOG_FUNCTION(this);
2064 return m_addressTlvList.Front();
2065}
2066
2069{
2070 NS_LOG_FUNCTION(this);
2071 return m_addressTlvList.Front();
2072}
2073
2076{
2077 NS_LOG_FUNCTION(this);
2078 return m_addressTlvList.Back();
2079}
2080
2083{
2084 NS_LOG_FUNCTION(this);
2085 return m_addressTlvList.Back();
2086}
2087
2088void
2090{
2091 NS_LOG_FUNCTION(this << tlv);
2092 m_addressTlvList.PushFront(tlv);
2093}
2094
2095void
2097{
2098 NS_LOG_FUNCTION(this);
2099 m_addressTlvList.PopFront();
2100}
2101
2102void
2104{
2105 NS_LOG_FUNCTION(this << tlv);
2106 m_addressTlvList.PushBack(tlv);
2107}
2108
2109void
2111{
2112 NS_LOG_FUNCTION(this);
2113 m_addressTlvList.PopBack();
2114}
2115
2118{
2119 NS_LOG_FUNCTION(this << &position);
2120 return m_addressTlvList.Erase(position);
2121}
2122
2129
2130void
2132{
2133 NS_LOG_FUNCTION(this);
2134 m_addressTlvList.Clear();
2135}
2136
2139{
2140 NS_LOG_FUNCTION(this);
2141 /* num-addr + flags */
2142 uint32_t size = 2;
2143
2144 if (AddressSize() == 1)
2145 {
2146 size += GetAddressLength() + PrefixSize();
2147 }
2148 else if (AddressSize() > 0)
2149 {
2150 auto head = new uint8_t[GetAddressLength()];
2151 uint8_t headlen = 0;
2152 auto tail = new uint8_t[GetAddressLength()];
2153 uint8_t taillen = 0;
2154
2155 GetHeadTail(head, headlen, tail, taillen);
2156
2157 if (headlen > 0)
2158 {
2159 size += 1 + headlen;
2160 }
2161
2162 if (taillen > 0)
2163 {
2164 size++;
2165 if (!HasZeroTail(tail, taillen))
2166 {
2167 size += taillen;
2168 }
2169 }
2170
2171 /* mid size */
2172 size += (GetAddressLength() - headlen - taillen) * AddressSize();
2173
2174 size += PrefixSize();
2175
2176 delete[] head;
2177 delete[] tail;
2178 }
2179
2180 size += m_addressTlvList.GetSerializedSize();
2181
2182 return size;
2183}
2184
2185void
2187{
2188 NS_LOG_FUNCTION(this << &start);
2189 start.WriteU8(AddressSize());
2190 Buffer::Iterator bufref = start;
2191 uint8_t flags = 0;
2192 start.Next();
2193
2194 if (AddressSize() == 1)
2195 {
2196 auto buf = new uint8_t[GetAddressLength()];
2198 start.Write(buf, GetAddressLength());
2199
2200 if (PrefixSize() == 1)
2201 {
2202 start.WriteU8(PrefixFront());
2203 flags |= AHAS_SINGLE_PRE_LEN;
2204 }
2205 bufref.WriteU8(flags);
2206 delete[] buf;
2207 }
2208 else if (AddressSize() > 0)
2209 {
2210 auto head = new uint8_t[GetAddressLength()];
2211 auto tail = new uint8_t[GetAddressLength()];
2212 uint8_t headlen = 0;
2213 uint8_t taillen = 0;
2214
2215 GetHeadTail(head, headlen, tail, taillen);
2216
2217 if (headlen > 0)
2218 {
2219 flags |= AHAS_HEAD;
2220 start.WriteU8(headlen);
2221 start.Write(head, headlen);
2222 }
2223
2224 if (taillen > 0)
2225 {
2226 start.WriteU8(taillen);
2227
2228 if (HasZeroTail(tail, taillen))
2229 {
2230 flags |= AHAS_ZERO_TAIL;
2231 }
2232 else
2233 {
2234 flags |= AHAS_FULL_TAIL;
2235 start.Write(tail, taillen);
2236 }
2237 }
2238
2239 if (headlen + taillen < GetAddressLength())
2240 {
2241 auto mid = new uint8_t[GetAddressLength()];
2242 for (auto iter = AddressBegin(); iter != AddressEnd(); iter++)
2243 {
2244 SerializeAddress(mid, iter);
2245 start.Write(mid + headlen, GetAddressLength() - headlen - taillen);
2246 }
2247 delete[] mid;
2248 }
2249
2250 flags |= GetPrefixFlags();
2251 bufref.WriteU8(flags);
2252
2253 for (auto iter = PrefixBegin(); iter != PrefixEnd(); iter++)
2254 {
2255 start.WriteU8(*iter);
2256 }
2257
2258 delete[] head;
2259 delete[] tail;
2260 }
2261
2262 m_addressTlvList.Serialize(start);
2263}
2264
2265void
2267{
2268 NS_LOG_FUNCTION(this << &start);
2269 uint8_t numaddr = start.ReadU8();
2270 uint8_t flags = start.ReadU8();
2271
2272 if (numaddr > 0)
2273 {
2274 uint8_t headlen = 0;
2275 uint8_t taillen = 0;
2276 auto addrtmp = new uint8_t[GetAddressLength()];
2277 memset(addrtmp, 0, GetAddressLength());
2278
2279 if (flags & AHAS_HEAD)
2280 {
2281 headlen = start.ReadU8();
2282 start.Read(addrtmp, headlen);
2283 }
2284
2285 if ((flags & AHAS_FULL_TAIL) ^ (flags & AHAS_ZERO_TAIL))
2286 {
2287 taillen = start.ReadU8();
2288
2289 if (flags & AHAS_FULL_TAIL)
2290 {
2291 start.Read(addrtmp + GetAddressLength() - taillen, taillen);
2292 }
2293 }
2294
2295 for (int i = 0; i < numaddr; i++)
2296 {
2297 start.Read(addrtmp + headlen, GetAddressLength() - headlen - taillen);
2299 }
2300
2301 if (flags & AHAS_SINGLE_PRE_LEN)
2302 {
2303 PrefixPushBack(start.ReadU8());
2304 }
2305 else if (flags & AHAS_MULTI_PRE_LEN)
2306 {
2307 for (int i = 0; i < numaddr; i++)
2308 {
2309 PrefixPushBack(start.ReadU8());
2310 }
2311 }
2312
2313 delete[] addrtmp;
2314 }
2315
2316 m_addressTlvList.Deserialize(start);
2317}
2318
2319void
2320PbbAddressBlock::Print(std::ostream& os) const
2321{
2322 NS_LOG_FUNCTION(this << &os);
2323 Print(os, 0);
2324}
2325
2326void
2327PbbAddressBlock::Print(std::ostream& os, int level) const
2328{
2329 NS_LOG_FUNCTION(this << &os << level);
2330 std::string prefix = "";
2331 for (int i = 0; i < level; i++)
2332 {
2333 prefix.append("\t");
2334 }
2335
2336 os << prefix << "PbbAddressBlock {" << std::endl;
2337 os << prefix << "\taddresses = " << std::endl;
2338 for (auto iter = AddressBegin(); iter != AddressEnd(); iter++)
2339 {
2340 os << prefix << "\t\t";
2341 PrintAddress(os, iter);
2342 os << std::endl;
2343 }
2344
2345 os << prefix << "\tprefixes = " << std::endl;
2346 for (auto iter = PrefixBegin(); iter != PrefixEnd(); iter++)
2347 {
2348 os << prefix << "\t\t" << (int)(*iter) << std::endl;
2349 }
2350
2351 m_addressTlvList.Print(os, level + 1);
2352}
2353
2354bool
2356{
2357 if (AddressSize() != other.AddressSize())
2358 {
2359 return false;
2360 }
2361
2364 for (tai = AddressBegin(), oai = other.AddressBegin();
2365 tai != AddressEnd() && oai != other.AddressEnd();
2366 tai++, oai++)
2367 {
2368 if (*tai != *oai)
2369 {
2370 return false;
2371 }
2372 }
2373
2374 if (PrefixSize() != other.PrefixSize())
2375 {
2376 return false;
2377 }
2378
2381 for (tpi = PrefixBegin(), opi = other.PrefixBegin();
2382 tpi != PrefixEnd() && opi != other.PrefixEnd();
2383 tpi++, opi++)
2384 {
2385 if (*tpi != *opi)
2386 {
2387 return false;
2388 }
2389 }
2390
2391 return m_addressTlvList == other.m_addressTlvList;
2392}
2393
2394uint8_t
2396{
2397 NS_LOG_FUNCTION(this);
2398 switch (PrefixSize())
2399 {
2400 case 0:
2401 return 0;
2402 case 1:
2403 return AHAS_SINGLE_PRE_LEN;
2404 default:
2405 return AHAS_MULTI_PRE_LEN;
2406 }
2407
2408 /* Quiet compiler */
2409 return 0;
2410}
2411
2412void
2413PbbAddressBlock::GetHeadTail(uint8_t* head, uint8_t& headlen, uint8_t* tail, uint8_t& taillen) const
2414{
2415 NS_LOG_FUNCTION(this << &head << static_cast<uint32_t>(headlen) << &tail
2416 << static_cast<uint32_t>(taillen));
2417 headlen = GetAddressLength();
2418 taillen = headlen;
2419
2420 /* Temporary automatic buffers to store serialized addresses */
2421 auto buflast = new uint8_t[GetAddressLength()];
2422 auto bufcur = new uint8_t[GetAddressLength()];
2423 uint8_t* tmp;
2424
2425 SerializeAddress(buflast, AddressBegin());
2426
2427 /* Skip the first item */
2428 for (auto iter = AddressBegin()++; iter != AddressEnd(); iter++)
2429 {
2430 SerializeAddress(bufcur, iter);
2431
2432 int i;
2433 for (i = 0; i < headlen; i++)
2434 {
2435 if (buflast[i] != bufcur[i])
2436 {
2437 headlen = i;
2438 break;
2439 }
2440 }
2441
2442 /* If headlen == fulllen - 1, then tail is 0 */
2443 if (GetAddressLength() - headlen > 0)
2444 {
2445 for (i = GetAddressLength() - 1; GetAddressLength() - 1 - i <= taillen && i > headlen;
2446 i--)
2447 {
2448 if (buflast[i] != bufcur[i])
2449 {
2450 break;
2451 }
2452 }
2453 taillen = GetAddressLength() - 1 - i;
2454 }
2455 else if (headlen == 0)
2456 {
2457 taillen = 0;
2458 break;
2459 }
2460
2461 tmp = buflast;
2462 buflast = bufcur;
2463 bufcur = tmp;
2464 }
2465
2466 memcpy(head, bufcur, headlen);
2467 memcpy(tail, bufcur + (GetAddressLength() - taillen), taillen);
2468
2469 delete[] buflast;
2470 delete[] bufcur;
2471}
2472
2473bool
2474PbbAddressBlock::HasZeroTail(const uint8_t* tail, uint8_t taillen) const
2475{
2476 NS_LOG_FUNCTION(this << &tail << static_cast<uint32_t>(taillen));
2477 int i;
2478 for (i = 0; i < taillen; i++)
2479 {
2480 if (tail[i] != 0)
2481 {
2482 break;
2483 }
2484 }
2485 return i == taillen;
2486}
2487
2488/* End PbbAddressBlock Class */
2489
2494
2499
2500uint8_t
2502{
2503 NS_LOG_FUNCTION(this);
2504 return 4;
2505}
2506
2507void
2509{
2510 NS_LOG_FUNCTION(this << &buffer << &iter);
2511 Ipv4Address::ConvertFrom(*iter).Serialize(buffer);
2512}
2513
2514Address
2516{
2517 NS_LOG_FUNCTION(this << &buffer);
2518 return Ipv4Address::Deserialize(buffer);
2519}
2520
2521void
2523{
2524 NS_LOG_FUNCTION(this << &os << &iter);
2526}
2527
2528/* End PbbAddressBlockIpv4 Class */
2529
2534
2539
2540uint8_t
2542{
2543 NS_LOG_FUNCTION(this);
2544 return 16;
2545}
2546
2547void
2549{
2550 NS_LOG_FUNCTION(this << &buffer << &iter);
2551 Ipv6Address::ConvertFrom(*iter).Serialize(buffer);
2552}
2553
2554Address
2556{
2557 NS_LOG_FUNCTION(this << &buffer);
2558 return Ipv6Address::Deserialize(buffer);
2559}
2560
2561void
2563{
2564 NS_LOG_FUNCTION(this << &os << &iter);
2566}
2567
2568/* End PbbAddressBlockIpv6 Class */
2569
2571{
2572 NS_LOG_FUNCTION(this);
2573 m_hasTypeExt = false;
2574 m_hasIndexStart = false;
2575 m_hasIndexStop = false;
2576 m_isMultivalue = false;
2577 m_hasValue = false;
2578}
2579
2581{
2582 NS_LOG_FUNCTION(this);
2583 m_value.RemoveAtEnd(m_value.GetSize());
2584}
2585
2586void
2587PbbTlv::SetType(uint8_t type)
2588{
2589 NS_LOG_FUNCTION(this << static_cast<uint32_t>(type));
2590 m_type = type;
2591}
2592
2593uint8_t
2595{
2596 NS_LOG_FUNCTION(this);
2597 return m_type;
2598}
2599
2600void
2601PbbTlv::SetTypeExt(uint8_t typeExt)
2602{
2603 NS_LOG_FUNCTION(this << static_cast<uint32_t>(typeExt));
2604 m_typeExt = typeExt;
2605 m_hasTypeExt = true;
2606}
2607
2608uint8_t
2610{
2611 NS_LOG_FUNCTION(this);
2613 return m_typeExt;
2614}
2615
2616bool
2618{
2619 NS_LOG_FUNCTION(this);
2620 return m_hasTypeExt;
2621}
2622
2623void
2625{
2626 NS_LOG_FUNCTION(this << static_cast<uint32_t>(index));
2627 m_indexStart = index;
2628 m_hasIndexStart = true;
2629}
2630
2631uint8_t
2633{
2634 NS_LOG_FUNCTION(this);
2636 return m_indexStart;
2637}
2638
2639bool
2641{
2642 NS_LOG_FUNCTION(this);
2643 return m_hasIndexStart;
2644}
2645
2646void
2648{
2649 NS_LOG_FUNCTION(this << static_cast<uint32_t>(index));
2650 m_indexStop = index;
2651 m_hasIndexStop = true;
2652}
2653
2654uint8_t
2656{
2657 NS_LOG_FUNCTION(this);
2659 return m_indexStop;
2660}
2661
2662bool
2664{
2665 NS_LOG_FUNCTION(this);
2666 return m_hasIndexStop;
2667}
2668
2669void
2670PbbTlv::SetMultivalue(bool isMultivalue)
2671{
2672 NS_LOG_FUNCTION(this << isMultivalue);
2673 m_isMultivalue = isMultivalue;
2674}
2675
2676bool
2678{
2679 NS_LOG_FUNCTION(this);
2680 return m_isMultivalue;
2681}
2682
2683void
2685{
2686 NS_LOG_FUNCTION(this << &start);
2687 m_hasValue = true;
2688 m_value = start;
2689}
2690
2691void
2692PbbTlv::SetValue(const uint8_t* buffer, uint32_t size)
2693{
2694 NS_LOG_FUNCTION(this << &buffer << size);
2695 m_hasValue = true;
2696 m_value.AddAtStart(size);
2697 m_value.Begin().Write(buffer, size);
2698}
2699
2700Buffer
2702{
2703 NS_LOG_FUNCTION(this);
2705 return m_value;
2706}
2707
2708bool
2710{
2711 NS_LOG_FUNCTION(this);
2712 return m_hasValue;
2713}
2714
2717{
2718 NS_LOG_FUNCTION(this);
2719 /* type + flags */
2720 uint32_t size = 2;
2721
2722 if (HasTypeExt())
2723 {
2724 size++;
2725 }
2726
2727 if (HasIndexStart())
2728 {
2729 size++;
2730 }
2731
2732 if (HasIndexStop())
2733 {
2734 size++;
2735 }
2736
2737 if (HasValue())
2738 {
2739 if (GetValue().GetSize() > 255)
2740 {
2741 size += 2;
2742 }
2743 else
2744 {
2745 size++;
2746 }
2747 size += GetValue().GetSize();
2748 }
2749
2750 return size;
2751}
2752
2753void
2755{
2756 NS_LOG_FUNCTION(this << &start);
2757 start.WriteU8(GetType());
2758
2759 Buffer::Iterator bufref = start;
2760 uint8_t flags = 0;
2761 start.Next();
2762
2763 if (HasTypeExt())
2764 {
2765 flags |= THAS_TYPE_EXT;
2766 start.WriteU8(GetTypeExt());
2767 }
2768
2769 if (HasIndexStart())
2770 {
2771 start.WriteU8(GetIndexStart());
2772
2773 if (HasIndexStop())
2774 {
2775 flags |= THAS_MULTI_INDEX;
2776 start.WriteU8(GetIndexStop());
2777 }
2778 else
2779 {
2780 flags |= THAS_SINGLE_INDEX;
2781 }
2782 }
2783
2784 if (HasValue())
2785 {
2786 flags |= THAS_VALUE;
2787
2788 uint32_t size = GetValue().GetSize();
2789 if (size > 255)
2790 {
2791 flags |= THAS_EXT_LEN;
2792 start.WriteHtonU16(size);
2793 }
2794 else
2795 {
2796 start.WriteU8(size);
2797 }
2798
2799 if (IsMultivalue())
2800 {
2801 flags |= TIS_MULTIVALUE;
2802 }
2803
2804 start.Write(GetValue().Begin(), GetValue().End());
2805 }
2806
2807 bufref.WriteU8(flags);
2808}
2809
2810void
2812{
2813 NS_LOG_FUNCTION(this << &start);
2814 SetType(start.ReadU8());
2815
2816 uint8_t flags = start.ReadU8();
2817
2818 if (flags & THAS_TYPE_EXT)
2819 {
2820 SetTypeExt(start.ReadU8());
2821 }
2822
2823 if (flags & THAS_MULTI_INDEX)
2824 {
2825 SetIndexStart(start.ReadU8());
2826 SetIndexStop(start.ReadU8());
2827 }
2828 else if (flags & THAS_SINGLE_INDEX)
2829 {
2830 SetIndexStart(start.ReadU8());
2831 }
2832
2833 if (flags & THAS_VALUE)
2834 {
2835 uint16_t len = 0;
2836
2837 if (flags & THAS_EXT_LEN)
2838 {
2839 len = start.ReadNtohU16();
2840 }
2841 else
2842 {
2843 len = start.ReadU8();
2844 }
2845
2846 m_value.AddAtStart(len);
2847
2848 Buffer::Iterator valueStart = start;
2849 start.Next(len);
2850 m_value.Begin().Write(valueStart, start);
2851 m_hasValue = true;
2852 }
2853}
2854
2855void
2856PbbTlv::Print(std::ostream& os) const
2857{
2858 NS_LOG_FUNCTION(this << &os);
2859 Print(os, 0);
2860}
2861
2862void
2863PbbTlv::Print(std::ostream& os, int level) const
2864{
2865 NS_LOG_FUNCTION(this << &os << level);
2866 std::string prefix = "";
2867 for (int i = 0; i < level; i++)
2868 {
2869 prefix.append("\t");
2870 }
2871
2872 os << prefix << "PbbTlv {" << std::endl;
2873 os << prefix << "\ttype = " << (int)GetType() << std::endl;
2874
2875 if (HasTypeExt())
2876 {
2877 os << prefix << "\ttypeext = " << (int)GetTypeExt() << std::endl;
2878 }
2879
2880 if (HasIndexStart())
2881 {
2882 os << prefix << "\tindexStart = " << (int)GetIndexStart() << std::endl;
2883 }
2884
2885 if (HasIndexStop())
2886 {
2887 os << prefix << "\tindexStop = " << (int)GetIndexStop() << std::endl;
2888 }
2889
2890 os << prefix << "\tisMultivalue = " << IsMultivalue() << std::endl;
2891
2892 if (HasValue())
2893 {
2894 os << prefix << "\thas value; size = " << GetValue().GetSize() << std::endl;
2895 }
2896
2897 os << prefix << "}" << std::endl;
2898}
2899
2900bool
2901PbbTlv::operator==(const PbbTlv& other) const
2902{
2903 if (GetType() != other.GetType())
2904 {
2905 return false;
2906 }
2907
2908 if (HasTypeExt() != other.HasTypeExt())
2909 {
2910 return false;
2911 }
2912
2913 if (HasTypeExt())
2914 {
2915 if (GetTypeExt() != other.GetTypeExt())
2916 {
2917 return false;
2918 }
2919 }
2920
2921 if (HasValue() != other.HasValue())
2922 {
2923 return false;
2924 }
2925
2926 if (HasValue())
2927 {
2928 Buffer tv = GetValue();
2929 Buffer ov = other.GetValue();
2930 if (tv.GetSize() != ov.GetSize())
2931 {
2932 return false;
2933 }
2934
2935 /* The docs say I probably shouldn't use Buffer::PeekData, but I think it
2936 * is justified in this case. */
2937 if (memcmp(tv.PeekData(), ov.PeekData(), tv.GetSize()) != 0)
2938 {
2939 return false;
2940 }
2941 }
2942 return true;
2943}
2944
2945/* End PbbTlv Class */
2946
2947void
2949{
2950 NS_LOG_FUNCTION(this << static_cast<uint32_t>(index));
2951 PbbTlv::SetIndexStart(index);
2952}
2953
2954uint8_t
2956{
2957 NS_LOG_FUNCTION(this);
2958 return PbbTlv::GetIndexStart();
2959}
2960
2961bool
2963{
2964 NS_LOG_FUNCTION(this);
2965 return PbbTlv::HasIndexStart();
2966}
2967
2968void
2970{
2971 NS_LOG_FUNCTION(this << static_cast<uint32_t>(index));
2972 PbbTlv::SetIndexStop(index);
2973}
2974
2975uint8_t
2977{
2978 NS_LOG_FUNCTION(this);
2979 return PbbTlv::GetIndexStop();
2980}
2981
2982bool
2984{
2985 NS_LOG_FUNCTION(this);
2986 return PbbTlv::HasIndexStop();
2987}
2988
2989void
2991{
2992 NS_LOG_FUNCTION(this << isMultivalue);
2993 PbbTlv::SetMultivalue(isMultivalue);
2994}
2995
2996bool
2998{
2999 NS_LOG_FUNCTION(this);
3000 return PbbTlv::IsMultivalue();
3001}
3002
3003} /* namespace ns3 */
return result
a polymophic address class
Definition address.h:114
iterator in a Buffer instance
Definition buffer.h:89
void WriteU8(uint8_t data)
Definition buffer.h:882
void WriteHtonU16(uint16_t data)
Definition buffer.h:916
uint32_t GetDistanceFrom(const Iterator &o) const
Definition buffer.cc:769
automatically resized byte buffer
Definition buffer.h:83
uint32_t GetSize() const
Definition buffer.h:1069
const uint8_t * PeekData() const
Definition buffer.cc:692
Protocol header serialization and deserialization.
Definition header.h:36
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.
void PrefixPopFront()
Removes a prefix from the front of this block.
Definition packetbb.cc:1967
Address AddressFront() const
Definition packetbb.cc:1838
std::list< uint8_t >::iterator PrefixIterator
Prefix iterator.
Definition packetbb.h:1166
int TlvSize() const
Definition packetbb.cc:2047
void AddressPopFront()
Removes an address from the front of this block.
Definition packetbb.cc:1859
uint8_t GetPrefixFlags() const
Get the prefix flags.
Definition packetbb.cc:2395
void PrefixPushFront(uint8_t prefix)
Prepends a prefix to the front of this block.
Definition packetbb.cc:1960
void Print(std::ostream &os) const
Pretty-prints the contents of this address block.
Definition packetbb.cc:2320
PrefixIterator PrefixEnd()
Definition packetbb.cc:1918
std::list< Address > m_addressList
Addresses container.
Definition packetbb.h:1571
void PrefixClear()
Removes all prefixes from this block.
Definition packetbb.cc:2010
uint32_t GetSerializedSize() const
Definition packetbb.cc:2138
void Serialize(Buffer::Iterator &start) const
Serializes this address block into the specified buffer.
Definition packetbb.cc:2186
PbbAddressTlvBlock::Iterator TlvIterator
tlvblock iterator
Definition packetbb.h:1171
bool PrefixEmpty() const
Definition packetbb.cc:1939
Ptr< PbbAddressTlv > TlvBack()
Definition packetbb.cc:2075
virtual void PrintAddress(std::ostream &os, ConstAddressIterator iter) const =0
Print one or more addresses.
Ptr< PbbAddressTlv > TlvFront()
Definition packetbb.cc:2061
void GetHeadTail(uint8_t *head, uint8_t &headlen, uint8_t *tail, uint8_t &taillen) const
Get head and tail.
Definition packetbb.cc:2413
void TlvPopBack()
Removes an address TLV from the back of this message.
Definition packetbb.cc:2110
TlvIterator TlvBegin()
Definition packetbb.cc:2019
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:1163
bool TlvEmpty() const
Definition packetbb.cc:2054
int PrefixSize() const
Definition packetbb.cc:1932
void TlvPushBack(Ptr< PbbAddressTlv > address)
Appends an address TLV to the back of this message.
Definition packetbb.cc:2103
Address AddressBack() const
Definition packetbb.cc:1845
void AddressClear()
Removes all addresses from this block.
Definition packetbb.cc:1895
void AddressPushBack(Address address)
Appends an address to the back of this block.
Definition packetbb.cc:1866
AddressIterator AddressErase(AddressIterator position)
Removes the address at the specified position.
Definition packetbb.cc:1880
bool HasZeroTail(const uint8_t *tail, uint8_t taillen) const
Check if the tail is empty.
Definition packetbb.cc:2474
std::list< uint8_t > m_prefixList
Prefixes container.
Definition packetbb.h:1572
void PrefixPushBack(uint8_t prefix)
Appends a prefix to the back of this block.
Definition packetbb.cc:1974
void PrefixPopBack()
Removes a prefix from the back of this block.
Definition packetbb.cc:1981
uint8_t PrefixFront() const
Definition packetbb.cc:1946
PrefixIterator PrefixBegin()
Definition packetbb.cc:1904
void AddressPopBack()
Removes an address from the back of this block.
Definition packetbb.cc:1873
PrefixIterator PrefixErase(PrefixIterator position)
Removes the prefix at the specified position.
Definition packetbb.cc:1995
virtual Address DeserializeAddress(uint8_t *buffer) const =0
Deserialize one address.
uint8_t PrefixBack() const
Definition packetbb.cc:1953
void TlvClear()
Removes all address TLVs from this block.
Definition packetbb.cc:2131
PbbAddressTlvBlock::ConstIterator ConstTlvIterator
tlvblock const iterator
Definition packetbb.h:1173
PrefixIterator PrefixInsert(PrefixIterator position, const uint8_t value)
Inserts a prefix at the specified position in this block.
Definition packetbb.cc:1988
void TlvPushFront(Ptr< PbbAddressTlv > address)
Prepends an address TLV to the front of this message.
Definition packetbb.cc:2089
void TlvPopFront()
Removes an address TLV from the front of this message.
Definition packetbb.cc:2096
virtual ~PbbAddressBlock()
Definition packetbb.cc:1788
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:2266
AddressIterator AddressBegin()
Definition packetbb.cc:1796
TlvIterator TlvErase(TlvIterator position)
Removes the address TLV at the specified position.
Definition packetbb.cc:2117
std::list< uint8_t >::const_iterator ConstPrefixIterator
Prefix const iterator.
Definition packetbb.h:1168
void AddressPushFront(Address address)
Prepends an address to the front of this block.
Definition packetbb.cc:1852
std::list< Address >::iterator AddressIterator
Address iterator.
Definition packetbb.h:1161
AddressIterator AddressEnd()
Definition packetbb.cc:1810
bool AddressEmpty() const
Definition packetbb.cc:1831
bool operator==(const PbbAddressBlock &other) const
Equality operator for PbbAddressBlock.
Definition packetbb.cc:2355
TlvIterator TlvEnd()
Definition packetbb.cc:2033
PbbAddressTlvBlock m_addressTlvList
PbbAddressTlv container.
Definition packetbb.h:1573
int AddressSize() const
Definition packetbb.cc:1824
uint8_t GetAddressLength() const override
Returns address length.
Definition packetbb.cc:2501
void PrintAddress(std::ostream &os, ConstAddressIterator iter) const override
Print one or more addresses.
Definition packetbb.cc:2522
void SerializeAddress(uint8_t *buffer, ConstAddressIterator iter) const override
Serialize one or more addresses.
Definition packetbb.cc:2508
~PbbAddressBlockIpv4() override
Definition packetbb.cc:2495
Address DeserializeAddress(uint8_t *buffer) const override
Deserialize one address.
Definition packetbb.cc:2515
~PbbAddressBlockIpv6() override
Definition packetbb.cc:2535
void SerializeAddress(uint8_t *buffer, ConstAddressIterator iter) const override
Serialize one or more addresses.
Definition packetbb.cc:2548
uint8_t GetAddressLength() const override
Returns address length.
Definition packetbb.cc:2541
void PrintAddress(std::ostream &os, ConstAddressIterator iter) const override
Print one or more addresses.
Definition packetbb.cc:2562
Address DeserializeAddress(uint8_t *buffer) const override
Deserialize one address.
Definition packetbb.cc:2555
void Serialize(Buffer::Iterator &start) const
Serializes this block into the specified buffer.
Definition packetbb.cc:427
void PushBack(Ptr< PbbAddressTlv > tlv)
Appends an Address TLV to the back of this block.
Definition packetbb.cc:368
void Print(std::ostream &os) const
Pretty-prints the contents of this block.
Definition packetbb.cc:468
Iterator Erase(Iterator position)
Removes the Address TLV at the specified position.
Definition packetbb.cc:389
std::list< Ptr< PbbAddressTlv > > m_tlvList
PbbAddressTlv container.
Definition packetbb.h:354
void PopFront()
Removes an AddressTLV from the front of this block.
Definition packetbb.cc:361
std::list< Ptr< PbbAddressTlv > >::const_iterator ConstIterator
PbbAddressTlv const iterator for PbbAddressTlvBlock.
Definition packetbb.h:208
void Clear()
Removes all Address TLVs from this block.
Definition packetbb.cc:403
std::list< Ptr< PbbAddressTlv > >::iterator Iterator
PbbAddressTlv iterator for PbbAddressTlvBlock.
Definition packetbb.h:206
void Deserialize(Buffer::Iterator &start)
Deserializes a block from the specified buffer.
Definition packetbb.cc:450
uint32_t GetSerializedSize() const
Definition packetbb.cc:414
Ptr< PbbAddressTlv > Front() const
Definition packetbb.cc:340
Ptr< PbbAddressTlv > Back() const
Definition packetbb.cc:347
Iterator Insert(Iterator position, const Ptr< PbbAddressTlv > tlv)
Inserts an Address TLV at the specified position in this block.
Definition packetbb.cc:382
void PushFront(Ptr< PbbAddressTlv > tlv)
Prepends an Address TLV to the front of this block.
Definition packetbb.cc:354
void PopBack()
Removes an Address TLV from the back of this block.
Definition packetbb.cc:375
bool operator==(const PbbAddressTlvBlock &other) const
Equality operator for PbbAddressTlvBlock.
Definition packetbb.cc:498
bool HasIndexStart() const
Tests whether or not this address TLV has a start index.
Definition packetbb.cc:2962
bool IsMultivalue() const
Tests whether or not this address TLV is "multivalue".
Definition packetbb.cc:2997
void SetMultivalue(bool isMultivalue)
Sets whether or not this address TLV is "multivalue".
Definition packetbb.cc:2990
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:2948
bool HasIndexStop() const
Tests whether or not this address TLV has a stop index.
Definition packetbb.cc:2983
uint8_t GetIndexStop() const
Definition packetbb.cc:2976
uint8_t GetIndexStart() const
Definition packetbb.cc:2955
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:2969
void AddressBlockPushFront(Ptr< PbbAddressBlock > block)
Prepends an address block to the front of this message.
Definition packetbb.cc:1318
uint16_t m_sequenceNumber
Sequence number.
Definition packetbb.h:1092
virtual PbbAddressLength GetAddressLength() const =0
Returns address length (IPV4 3 or IPV6 15).
Definition packetbb.cc:1026
std::list< Ptr< PbbAddressBlock > >::iterator AddressBlockIterator
PbbAddressBlock iterator.
Definition packetbb.h:683
bool HasOriginatorAddress() const
Tests whether or not this message has an originator address.
Definition packetbb.cc:1049
bool m_hasHopLimit
Hop limit present.
Definition packetbb.h:1085
void TlvPopFront()
Removes a message TLV from the front of this message.
Definition packetbb.cc:1204
void TlvPushFront(Ptr< PbbTlv > tlv)
Prepends a message TLV to the front of this message.
Definition packetbb.cc:1197
Address m_originatorAddress
originator address
Definition packetbb.h:1083
uint8_t GetType() const
Definition packetbb.cc:1019
bool HasHopLimit() const
Tests whether or not this message has a hop limit.
Definition packetbb.cc:1072
int AddressBlockSize() const
Definition packetbb.cc:1276
AddressBlockIterator AddressBlockBegin()
Definition packetbb.cc:1248
void Deserialize(Buffer::Iterator &start)
Deserializes a message from the specified buffer.
Definition packetbb.cc:1496
std::list< Ptr< PbbTlv > >::const_iterator ConstTlvIterator
PbbTlv const iterator.
Definition packetbb.h:681
AddressBlockIterator AddressBlockEnd()
Definition packetbb.cc:1262
void SetType(uint8_t type)
Sets the type for this message.
Definition packetbb.cc:1012
std::list< Ptr< PbbAddressBlock > >::const_iterator ConstAddressBlockIterator
PbbAddressBlock const iterator.
Definition packetbb.h:685
void Serialize(Buffer::Iterator &start) const
Serializes this message into the specified buffer.
Definition packetbb.cc:1409
Ptr< PbbTlv > TlvFront()
Definition packetbb.cc:1169
TlvIterator TlvErase(TlvIterator position)
Removes the message TLV at the specified position.
Definition packetbb.cc:1225
std::list< Ptr< PbbAddressBlock > > m_addressBlockList
PbbAddressBlock container.
Definition packetbb.h:1077
void SetOriginatorAddress(Address address)
Sets the address for the node that created this packet.
Definition packetbb.cc:1033
void SetHopLimit(uint8_t hoplimit)
Sets the maximum number of hops this message should travel.
Definition packetbb.cc:1056
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:1464
Address GetOriginatorAddress() const
Definition packetbb.cc:1041
void TlvClear()
Removes all message TLVs from this block.
Definition packetbb.cc:1239
uint8_t m_hopLimit
Hop limit.
Definition packetbb.h:1086
void AddressBlockPushBack(Ptr< PbbAddressBlock > block)
Appends an address block to the front of this message.
Definition packetbb.cc:1332
TlvIterator TlvBegin()
Definition packetbb.cc:1127
void TlvPopBack()
Removes a message TLV from the back of this message.
Definition packetbb.cc:1218
uint16_t GetSequenceNumber() const
Definition packetbb.cc:1110
bool m_hasOriginatorAddress
Originator address present.
Definition packetbb.h:1082
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:1118
uint8_t GetHopLimit() const
Definition packetbb.cc:1064
std::list< Ptr< PbbTlv > >::iterator TlvIterator
PbbTlv iterator.
Definition packetbb.h:679
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:1079
void Print(std::ostream &os) const
Pretty-prints the contents of this message.
Definition packetbb.cc:1538
void SetSequenceNumber(uint16_t seqnum)
Sets the sequence number of this message.
Definition packetbb.cc:1102
int TlvSize() const
Definition packetbb.cc:1155
bool m_hasHopCount
Hop count present.
Definition packetbb.h:1088
void AddressBlockClear()
Removes all address blocks from this message.
Definition packetbb.cc:1361
virtual ~PbbMessage()
Definition packetbb.cc:1005
virtual Ptr< PbbAddressBlock > AddressBlockDeserialize(Buffer::Iterator &start) const =0
Deserialize an address block.
PbbTlvBlock m_tlvList
PbbTlvBlock.
Definition packetbb.h:1076
void TlvPushBack(Ptr< PbbTlv > tlv)
Appends a message TLV to the back of this message.
Definition packetbb.cc:1211
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:1346
Ptr< PbbAddressBlock > AddressBlockBack()
Definition packetbb.cc:1304
uint8_t GetHopCount() const
Definition packetbb.cc:1087
void AddressBlockPopFront()
Removes an address block from the front of this message.
Definition packetbb.cc:1325
bool operator==(const PbbMessage &other) const
Equality operator for PbbMessage.
Definition packetbb.cc:1591
PbbAddressLength m_addrSize
the address size
Definition packetbb.h:1080
uint8_t m_hopCount
Hop count.
Definition packetbb.h:1089
bool m_hasSequenceNumber
Sequence number present.
Definition packetbb.h:1091
uint32_t GetSerializedSize() const
Definition packetbb.cc:1372
TlvIterator TlvEnd()
Definition packetbb.cc:1141
Ptr< PbbAddressBlock > AddressBlockFront()
Definition packetbb.cc:1290
bool AddressBlockEmpty() const
Definition packetbb.cc:1283
bool TlvEmpty() const
Definition packetbb.cc:1162
bool HasHopCount() const
Tests whether or not this message has a hop count.
Definition packetbb.cc:1095
Ptr< PbbTlv > TlvBack()
Definition packetbb.cc:1183
uint8_t m_type
the type for this message
Definition packetbb.h:1079
void AddressBlockPopBack()
Removes an address block from the back of this message.
Definition packetbb.cc:1339
void PrintOriginatorAddress(std::ostream &os) const override
Print the originator address.
Definition packetbb.cc:1715
void SerializeOriginatorAddress(Buffer::Iterator &start) const override
Serialize the originator address.
Definition packetbb.cc:1694
PbbAddressLength GetAddressLength() const override
Returns address length (IPV4 3 or IPV6 15).
Definition packetbb.cc:1687
Address DeserializeOriginatorAddress(Buffer::Iterator &start) const override
Deserialize the originator address.
Definition packetbb.cc:1704
Ptr< PbbAddressBlock > AddressBlockDeserialize(Buffer::Iterator &start) const override
Deserialize an address block.
Definition packetbb.cc:1722
Ptr< PbbAddressBlock > AddressBlockDeserialize(Buffer::Iterator &start) const override
Deserialize an address block.
Definition packetbb.cc:1773
void PrintOriginatorAddress(std::ostream &os) const override
Print the originator address.
Definition packetbb.cc:1766
void SerializeOriginatorAddress(Buffer::Iterator &start) const override
Serialize the originator address.
Definition packetbb.cc:1745
PbbAddressLength GetAddressLength() const override
Returns address length (IPV4 3 or IPV6 15).
Definition packetbb.cc:1738
Address DeserializeOriginatorAddress(Buffer::Iterator &start) const override
Deserialize the originator address.
Definition packetbb.cc:1755
std::list< Ptr< PbbMessage > >::iterator MessageIterator
PbbMessage Iterator for PbbPacket.
Definition packetbb.h:373
~PbbPacket() override
Definition packetbb.cc:527
uint8_t m_version
version
Definition packetbb.h:661
TlvIterator TlvBegin()
Definition packetbb.cc:573
std::list< Ptr< PbbMessage > >::const_iterator ConstMessageIterator
PbbMessage Const Iterator for PbbPacket.
Definition packetbb.h:375
MessageIterator MessageEnd()
Definition packetbb.cc:708
std::list< Ptr< PbbMessage > > m_messageList
PbbTlvBlock container.
Definition packetbb.h:659
bool m_hasseqnum
Sequence number present.
Definition packetbb.h:663
void TlvPushBack(Ptr< PbbTlv > tlv)
Appends a packet TLV to the back of this packet.
Definition packetbb.cc:657
bool TlvEmpty() const
Definition packetbb.cc:608
void TlvClear()
Removes all packet TLVs from this packet.
Definition packetbb.cc:685
static TypeId GetTypeId()
Get the type ID.
Definition packetbb.cc:817
void TlvPopBack()
Removes a packet TLV from the back of this block.
Definition packetbb.cc:664
void TlvPopFront()
Removes a packet TLV from the front of this packet.
Definition packetbb.cc:650
void MessagePushBack(Ptr< PbbMessage > message)
Appends a message to the back of this packet.
Definition packetbb.cc:778
std::list< Ptr< PbbTlv > >::iterator TlvIterator
PbbTlv iterator for PbbPacket.
Definition packetbb.h:369
Ptr< PbbTlv > TlvFront()
Definition packetbb.cc:615
TlvIterator TlvEnd()
Definition packetbb.cc:587
void MessageClear()
Removes all messages from this packet.
Definition packetbb.cc:806
Ptr< PbbMessage > MessageFront()
Definition packetbb.cc:736
void SetSequenceNumber(uint16_t number)
Sets the sequence number of this packet.
Definition packetbb.cc:541
void MessagePopFront()
Removes a message from the front of this packet.
Definition packetbb.cc:771
void ForceTlv(bool forceTlv)
Forces a packet to write a TLV list even if it's empty, ignoring the phastlv bit.
Definition packetbb.cc:564
uint32_t GetSerializedSize() const override
Definition packetbb.cc:833
void TlvPushFront(Ptr< PbbTlv > tlv)
Prepends a packet TLV to the front of this packet.
Definition packetbb.cc:643
bool MessageEmpty() const
Definition packetbb.cc:729
uint16_t GetSequenceNumber() const
Definition packetbb.cc:549
void MessagePopBack()
Removes a message from the back of this packet.
Definition packetbb.cc:785
bool HasSequenceNumber() const
Tests whether or not this packet has a sequence number.
Definition packetbb.cc:557
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition packetbb.cc:827
Ptr< PbbTlv > TlvBack()
Definition packetbb.cc:629
MessageIterator MessageBegin()
Definition packetbb.cc:694
TlvIterator Erase(TlvIterator position)
Removes the packet TLV at the specified position.
Definition packetbb.cc:671
void MessagePushFront(Ptr< PbbMessage > message)
Prepends a message to the front of this packet.
Definition packetbb.cc:764
int TlvSize() const
Definition packetbb.cc:601
void Serialize(Buffer::Iterator start) const override
Serializes this packet into the specified buffer.
Definition packetbb.cc:858
Ptr< PbbMessage > MessageBack()
Definition packetbb.cc:750
void Print(std::ostream &os) const override
Pretty-prints the contents of this block.
Definition packetbb.cc:925
uint16_t m_seqnum
Sequence number.
Definition packetbb.h:664
uint8_t GetVersion() const
Definition packetbb.cc:534
uint32_t Deserialize(Buffer::Iterator start) override
Deserializes a packet from the specified buffer.
Definition packetbb.cc:891
bool m_forceTlv
Force writing a TLV list (even if it's empty).
Definition packetbb.h:665
std::list< Ptr< PbbTlv > >::const_iterator ConstTlvIterator
PbbTlv const iterator for PbbPacket.
Definition packetbb.h:371
int MessageSize() const
Definition packetbb.cc:722
PbbTlvBlock m_tlvList
PbbTlv container.
Definition packetbb.h:658
bool operator==(const PbbPacket &other) const
Equality operator for PbbPacket.
Definition packetbb.cc:948
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:194
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 m_isMultivalue
Is multivalue.
Definition packetbb.h:1804
uint8_t m_indexStop
Stop index.
Definition packetbb.h:1802
void SetValue(Buffer start)
Sets the value of this message to the specified buffer.
Definition packetbb.cc:2684
uint8_t GetIndexStop() const
Get the stop point index.
Definition packetbb.cc:2655
bool HasTypeExt() const
Tests whether or not this TLV has a type extension.
Definition packetbb.cc:2617
uint8_t GetIndexStart() const
Get the starting point index.
Definition packetbb.cc:2632
bool HasValue() const
Tests whether or not this TLV has a value.
Definition packetbb.cc:2709
bool HasIndexStart() const
Checks if there is a starting index.
Definition packetbb.cc:2640
uint8_t m_indexStart
Start index.
Definition packetbb.h:1799
uint8_t m_type
Type of this TLV.
Definition packetbb.h:1793
Buffer m_value
Value.
Definition packetbb.h:1806
bool m_hasIndexStart
Start index present.
Definition packetbb.h:1798
bool operator==(const PbbTlv &other) const
Equality operator for PbbTlv.
Definition packetbb.cc:2901
void Serialize(Buffer::Iterator &start) const
Serializes this TLV into the specified buffer.
Definition packetbb.cc:2754
bool IsMultivalue() const
Check the multivalue parameter.
Definition packetbb.cc:2677
void SetType(uint8_t type)
Sets the type of this TLV.
Definition packetbb.cc:2587
bool m_hasIndexStop
Stop index present.
Definition packetbb.h:1801
uint8_t GetTypeExt() const
Definition packetbb.cc:2609
void SetIndexStop(uint8_t index)
Set an index as stop point.
Definition packetbb.cc:2647
bool HasIndexStop() const
Checks if there is a stop index.
Definition packetbb.cc:2663
void SetMultivalue(bool isMultivalue)
Set the multivalue parameter.
Definition packetbb.cc:2670
void Print(std::ostream &os) const
Pretty-prints the contents of this TLV.
Definition packetbb.cc:2856
virtual ~PbbTlv()
Definition packetbb.cc:2580
void SetIndexStart(uint8_t index)
Set an index as starting point.
Definition packetbb.cc:2624
Buffer GetValue() const
Definition packetbb.cc:2701
uint8_t m_typeExt
Extended type.
Definition packetbb.h:1796
bool m_hasTypeExt
Extended type present.
Definition packetbb.h:1795
uint8_t GetType() const
Definition packetbb.cc:2594
uint32_t GetSerializedSize() const
Definition packetbb.cc:2716
void SetTypeExt(uint8_t type)
Sets the type extension of this TLV.
Definition packetbb.cc:2601
void Deserialize(Buffer::Iterator &start)
Deserializes a TLV from the specified buffer.
Definition packetbb.cc:2811
bool m_hasValue
Has value.
Definition packetbb.h:1805
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
a unique identifier for an interface.
Definition type-id.h:50
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:999
#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:194
#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:454
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