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