A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
sixlowpan-header.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2013 Universita' di Firenze, Italy
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Tommaso Pecorella <tommaso.pecorella@unifi.it>
7 * Michele Muccio <michelemuccio@virgilio.it>
8 */
9
10#include "sixlowpan-header.h"
11
12#include "ns3/abort.h"
13#include "ns3/assert.h"
14#include "ns3/ipv6-header.h"
15#include "ns3/log.h"
16#include "ns3/mac16-address.h"
17#include "ns3/mac64-address.h"
18
19namespace ns3
20{
21
22/*
23 * SixLowPanDispatch
24 */
25
29
32{
33 if (dispatch <= LOWPAN_NALP_N)
34 {
35 return LOWPAN_NALP;
36 }
37 else if (dispatch == LOWPAN_IPv6)
38 {
39 return LOWPAN_IPv6;
40 }
41 else if (dispatch == LOWPAN_HC1)
42 {
43 return LOWPAN_HC1;
44 }
45 else if (dispatch == LOWPAN_BC0)
46 {
47 return LOWPAN_BC0;
48 }
49 else if ((dispatch >= LOWPAN_IPHC) && (dispatch <= LOWPAN_IPHC_N))
50 {
51 return LOWPAN_IPHC;
52 }
53 else if ((dispatch >= LOWPAN_MESH) && (dispatch <= LOWPAN_MESH_N))
54 {
55 return LOWPAN_MESH;
56 }
57 else if ((dispatch >= LOWPAN_FRAG1) && (dispatch <= LOWPAN_FRAG1_N))
58 {
59 return LOWPAN_FRAG1;
60 }
61 else if ((dispatch >= LOWPAN_FRAGN) && (dispatch <= LOWPAN_FRAGN_N))
62 {
63 return LOWPAN_FRAGN;
64 }
65 return LOWPAN_UNSUPPORTED;
66}
67
70{
71 if ((dispatch >= LOWPAN_GHC_EXT) && (dispatch <= LOWPAN_GHC_EXT_N))
72 {
73 return LOWPAN_GHC_EXT;
74 }
75 else if (dispatch == LOWPAN_GHC_ICMPV6)
76 {
77 return LOWPAN_GHC_ICMPV6;
78 }
79 else if ((dispatch >= LOWPAN_GHC_UDP) && (dispatch <= LOWPAN_GHC_UDP_N))
80 {
81 return LOWPAN_GHC_UDP;
82 }
83 else if ((dispatch >= LOWPAN_NHC) && (dispatch <= LOWPAN_NHC_N))
84 {
85 return LOWPAN_NHC;
86 }
87 else if ((dispatch >= LOWPAN_UDPNHC) && (dispatch <= LOWPAN_UDPNHC_N))
88 {
89 return LOWPAN_UDPNHC;
90 }
92}
93
94/*
95 * SixLowPanHc1
96 */
98
103
104TypeId
106{
107 static TypeId tid = TypeId("ns3::SixLowPanHc1")
108 .SetParent<Header>()
109 .SetGroupName("SixLowPan")
110 .AddConstructor<SixLowPanHc1>();
111 return tid;
112}
113
114TypeId
116{
117 return GetTypeId();
118}
119
120void
121SixLowPanHc1::Print(std::ostream& os) const
122{
123 uint8_t encoding;
124 encoding = m_srcCompression;
125 encoding <<= 2;
126 encoding |= m_dstCompression;
127 encoding <<= 1;
128 encoding |= m_tcflCompression;
129 encoding <<= 2;
130 encoding |= m_nextHeaderCompression;
131 encoding <<= 1;
132 encoding |= m_hc2HeaderPresent;
133
134 os << "encoding " << +encoding << ", hopLimit " << +m_hopLimit;
135}
136
139{
140 uint32_t serializedSize = 3;
141
142 switch (m_srcCompression)
143 {
144 case HC1_PIII:
145 serializedSize += 16;
146 break;
147 case HC1_PIIC:
148 case HC1_PCII:
149 serializedSize += 8;
150 break;
151 case HC1_PCIC:
152 break;
153 }
154 switch (m_dstCompression)
155 {
156 case HC1_PIII:
157 serializedSize += 16;
158 break;
159 case HC1_PIIC:
160 case HC1_PCII:
161 serializedSize += 8;
162 break;
163 case HC1_PCIC:
164 break;
165 }
166
168 {
169 serializedSize += 4;
170 }
171
173 {
174 serializedSize++;
175 }
176
177 return serializedSize;
178}
179
180void
182{
183 Buffer::Iterator i = start;
184 uint8_t encoding;
185 encoding = m_srcCompression;
186 encoding <<= 2;
187 encoding |= m_dstCompression;
188 encoding <<= 1;
189 encoding |= m_tcflCompression;
190 encoding <<= 2;
191 encoding |= m_nextHeaderCompression;
192 encoding <<= 1;
193 encoding |= m_hc2HeaderPresent;
194
196 i.WriteU8(encoding);
198 switch (m_srcCompression)
199 {
200 case HC1_PIII:
201 for (int j = 0; j < 8; j++)
202 {
203 i.WriteU8(m_srcPrefix[j]);
204 }
205 for (int j = 0; j < 8; j++)
206 {
208 }
209 break;
210 case HC1_PIIC:
211 for (int j = 0; j < 8; j++)
212 {
213 i.WriteU8(m_srcPrefix[j]);
214 }
215 break;
216 case HC1_PCII:
217 for (int j = 0; j < 8; j++)
218 {
220 }
221 break;
222 case HC1_PCIC:
223 break;
224 }
225 switch (m_dstCompression)
226 {
227 case HC1_PIII:
228 for (int j = 0; j < 8; j++)
229 {
230 i.WriteU8(m_dstPrefix[j]);
231 }
232 for (int j = 0; j < 8; j++)
233 {
235 }
236 break;
237 case HC1_PIIC:
238 for (int j = 0; j < 8; j++)
239 {
240 i.WriteU8(m_dstPrefix[j]);
241 }
242 break;
243 case HC1_PCII:
244 for (int j = 0; j < 8; j++)
245 {
247 }
248 break;
249 case HC1_PCIC:
250 break;
251 }
252
254 {
256 uint8_t temp[3];
257 temp[0] = uint8_t(m_flowLabel & 0xff);
258 temp[1] = uint8_t((m_flowLabel >> 8) & 0xff);
259 temp[2] = uint8_t((m_flowLabel >> 16) & 0xff);
260 i.Write(temp, 3);
261 }
262
264 {
266 }
267
268 // TODO: HC2 is not yet supported. Should be.
269 NS_ASSERT_MSG(m_hc2HeaderPresent != true, "Can not compress HC2, exiting. Very sorry.");
270}
271
274{
275 Buffer::Iterator i = start;
276
277 uint8_t dispatch = i.ReadU8();
278 if (dispatch != SixLowPanDispatch::LOWPAN_HC1)
279 {
280 return 0;
281 }
282
283 uint8_t encoding = i.ReadU8();
284 m_hopLimit = i.ReadU8();
285
286 m_srcCompression = LowPanHc1Addr_e(encoding >> 6);
287 m_dstCompression = LowPanHc1Addr_e((encoding >> 4) & 0x3);
288 m_tcflCompression = (encoding >> 3) & 0x1;
289 m_nextHeaderCompression = LowPanHc1NextHeader_e((encoding >> 1) & 0x3);
290 m_hc2HeaderPresent = encoding & 0x1;
291
292 switch (m_srcCompression)
293 {
294 case HC1_PIII:
295 for (int j = 0; j < 8; j++)
296 {
297 m_srcPrefix[j] = i.ReadU8();
298 }
299 for (int j = 0; j < 8; j++)
300 {
301 m_srcInterface[j] = i.ReadU8();
302 }
303 break;
304 case HC1_PIIC:
305 for (int j = 0; j < 8; j++)
306 {
307 m_srcPrefix[j] = i.ReadU8();
308 }
309 break;
310 case HC1_PCII:
311 for (int j = 0; j < 8; j++)
312 {
313 m_srcInterface[j] = i.ReadU8();
314 }
315 break;
316 case HC1_PCIC:
317 break;
318 }
319 switch (m_dstCompression)
320 {
321 case HC1_PIII:
322 for (int j = 0; j < 8; j++)
323 {
324 m_dstPrefix[j] = i.ReadU8();
325 }
326 for (int j = 0; j < 8; j++)
327 {
328 m_dstInterface[j] = i.ReadU8();
329 }
330 break;
331 case HC1_PIIC:
332 for (int j = 0; j < 8; j++)
333 {
334 m_dstPrefix[j] = i.ReadU8();
335 }
336 break;
337 case HC1_PCII:
338 for (int j = 0; j < 8; j++)
339 {
340 m_dstInterface[j] = i.ReadU8();
341 }
342 break;
343 case HC1_PCIC:
344 break;
345 }
346
348 {
350 uint8_t temp[3];
351 i.Read(temp, 3);
352 m_flowLabel = temp[2];
353 m_flowLabel = (m_flowLabel << 8) | temp[1];
354 m_flowLabel = (m_flowLabel << 8) | temp[0];
355 }
356
358 {
359 case HC1_NC:
360 m_nextHeader = i.ReadU8();
361 break;
362 case HC1_TCP:
364 break;
365 case HC1_UDP:
367 break;
368 case HC1_ICMP:
370 break;
371 }
372
373 NS_ASSERT_MSG(m_hc2HeaderPresent != true, "Can not compress HC2, exiting. Very sorry.");
374
375 return GetSerializedSize();
376}
377
378void
380{
381 m_hopLimit = limit;
382}
383
384uint8_t
386{
387 return m_hopLimit;
388}
389
395
396const uint8_t*
398{
399 return m_dstInterface;
400}
401
402const uint8_t*
404{
405 return m_dstPrefix;
406}
407
410{
411 return m_flowLabel;
412}
413
414uint8_t
416{
417 return m_nextHeader;
418}
419
425
426const uint8_t*
428{
429 return m_srcInterface;
430}
431
432const uint8_t*
434{
435 return m_srcPrefix;
436}
437
438uint8_t
440{
441 return m_trafficClass;
442}
443
444bool
449
450bool
455
456void
458{
459 m_dstCompression = dstCompression;
460}
461
462void
463SixLowPanHc1::SetDstInterface(const uint8_t* dstInterface)
464{
465 for (int i = 0; i < 8; i++)
466 {
467 m_dstInterface[i] = dstInterface[i];
468 }
469}
470
471void
472SixLowPanHc1::SetDstPrefix(const uint8_t* dstPrefix)
473{
474 for (int i = 0; i < 8; i++)
475 {
476 m_dstPrefix[i] = dstPrefix[i];
477 }
478}
479
480void
482{
483 m_flowLabel = flowLabel;
484}
485
486void
488{
489 m_nextHeader = nextHeader;
490
491 switch (m_nextHeader)
492 {
495 break;
498 break;
501 break;
502 default:
504 break;
505 }
506}
507
508void
510{
511 m_srcCompression = srcCompression;
512}
513
514void
515SixLowPanHc1::SetSrcInterface(const uint8_t* srcInterface)
516{
517 for (int i = 0; i < 8; i++)
518 {
519 m_srcInterface[i] = srcInterface[i];
520 }
521}
522
523void
524SixLowPanHc1::SetSrcPrefix(const uint8_t* srcPrefix)
525{
526 for (int i = 0; i < 8; i++)
527 {
528 m_srcPrefix[i] = srcPrefix[i];
529 }
530}
531
532void
534{
535 m_tcflCompression = tcflCompression;
536}
537
538void
539SixLowPanHc1::SetTrafficClass(uint8_t trafficClass)
540{
541 m_trafficClass = trafficClass;
542}
543
544void
546{
547 m_hc2HeaderPresent = hc2HeaderPresent;
548}
549
550std::ostream&
551operator<<(std::ostream& os, const SixLowPanHc1& h)
552{
553 h.Print(os);
554 return os;
555}
556
557/*
558 * SixLowPanFrag1
559 */
560NS_OBJECT_ENSURE_REGISTERED(SixLowPanFrag1);
561
567
568TypeId
570{
571 static TypeId tid = TypeId("ns3::SixLowPanFrag1")
572 .SetParent<Header>()
573 .SetGroupName("SixLowPan")
574 .AddConstructor<SixLowPanFrag1>();
575 return tid;
576}
577
578TypeId
580{
581 return GetTypeId();
582}
583
584void
585SixLowPanFrag1::Print(std::ostream& os) const
586{
587 os << "datagram size " << m_datagramSize << " tag " << m_datagramTag;
588}
589
592{
593 return 4;
594}
595
596void
598{
599 Buffer::Iterator i = start;
600
601 uint16_t temp = m_datagramSize | (uint16_t(SixLowPanDispatch::LOWPAN_FRAG1) << 8);
602
603 i.WriteU8(uint8_t(temp >> 8));
604 i.WriteU8(uint8_t(temp & 0xff));
605
607}
608
611{
612 Buffer::Iterator i = start;
613
614 uint8_t temp = i.ReadU8();
615 m_datagramSize = (uint16_t(temp) << 8) | i.ReadU8();
616 m_datagramSize &= 0x7FF;
617
619 return GetSerializedSize();
620}
621
622void
624{
625 m_datagramSize = datagramSize & 0x7FF;
626}
627
628uint16_t
630{
631 return m_datagramSize & 0x7FF;
632}
633
634void
636{
637 m_datagramTag = datagramTag;
638}
639
640uint16_t
642{
643 return m_datagramTag;
644}
645
646std::ostream&
647operator<<(std::ostream& os, const SixLowPanFrag1& h)
648{
649 h.Print(os);
650 return os;
651}
652
653/*
654 * SixLowPanFragN
655 */
656
657NS_OBJECT_ENSURE_REGISTERED(SixLowPanFragN);
658
665
666/*
667 * SixLowPanFragmentOffset
668 */
669TypeId
671{
672 static TypeId tid = TypeId("ns3::SixLowPanFragN")
673 .SetParent<Header>()
674 .SetGroupName("SixLowPan")
675 .AddConstructor<SixLowPanFragN>();
676 return tid;
677}
678
679TypeId
681{
682 return GetTypeId();
683}
684
685void
686SixLowPanFragN::Print(std::ostream& os) const
687{
688 os << "datagram size " << m_datagramSize << " tag " << m_datagramTag << " offset "
690}
691
694{
695 return 5;
696}
697
698void
700{
701 Buffer::Iterator i = start;
702
703 uint16_t temp = m_datagramSize | (uint16_t(SixLowPanDispatch::LOWPAN_FRAGN) << 8);
704
705 i.WriteU8(uint8_t(temp >> 8));
706 i.WriteU8(uint8_t(temp & 0xff));
707
710}
711
714{
715 Buffer::Iterator i = start;
716
717 uint8_t temp = i.ReadU8();
718 m_datagramSize = (uint16_t(temp) << 8) | i.ReadU8();
719 m_datagramSize &= 0x7FF;
720
723
724 return GetSerializedSize();
725}
726
727void
729{
730 m_datagramSize = datagramSize & 0x7FF;
731}
732
733uint16_t
735{
736 return m_datagramSize & 0x7FF;
737}
738
739void
741{
742 m_datagramTag = datagramTag;
743}
744
745uint16_t
747{
748 return m_datagramTag;
749}
750
751void
753{
754 m_datagramOffset = datagramOffset;
755}
756
757uint8_t
762
763std::ostream&
764operator<<(std::ostream& os, const SixLowPanFragN& h)
765{
766 h.Print(os);
767 return os;
768}
769
770/*
771 * SixLowPanIpv6
772 */
773
774NS_OBJECT_ENSURE_REGISTERED(SixLowPanIpv6);
775
779
780TypeId
782{
783 static TypeId tid = TypeId("ns3::SixLowPanIpv6")
784 .SetParent<Header>()
785 .SetGroupName("SixLowPan")
786 .AddConstructor<SixLowPanIpv6>();
787 return tid;
788}
789
790TypeId
792{
793 return GetTypeId();
794}
795
796void
797SixLowPanIpv6::Print(std::ostream& os) const
798{
799 os << "Uncompressed IPv6";
800}
801
804{
805 return 1;
806}
807
808void
815
818{
819 Buffer::Iterator i = start;
820 i.ReadU8();
821
822 return GetSerializedSize();
823}
824
825std::ostream&
826operator<<(std::ostream& os, const SixLowPanIpv6& h)
827{
828 h.Print(os);
829 return os;
830}
831
832/*
833 * SixLowPanIphcHeader
834 */
835NS_OBJECT_ENSURE_REGISTERED(SixLowPanIphc);
836
838{
839 // 011x xxxx xxxx xxxx
840 m_baseFormat = 0x6000;
842}
843
845{
846 // 011x xxxx xxxx xxxx
847 m_baseFormat = dispatch;
848 m_baseFormat <<= 8;
850}
851
852TypeId
854{
855 static TypeId tid = TypeId("ns3::SixLowPanIphc")
856 .SetParent<Header>()
857 .SetGroupName("SixLowPan")
858 .AddConstructor<SixLowPanIphc>();
859 return tid;
860}
861
862TypeId
864{
865 return GetTypeId();
866}
867
868void
869SixLowPanIphc::Print(std::ostream& os) const
870{
871 switch (GetTf())
872 {
873 case TF_FULL:
874 os << "TF_FULL(" << +m_ecn << ", " << +m_dscp << ", " << m_flowLabel << ")";
875 break;
876 case TF_DSCP_ELIDED:
877 os << "TF_DSCP_ELIDED(" << +m_ecn << ", " << m_flowLabel << ")";
878 break;
879 case TF_FL_ELIDED:
880 os << "TF_FL_ELIDED(" << +m_ecn << ", " << +m_dscp << ")";
881 break;
882 default:
883 os << "TF_ELIDED";
884 break;
885 }
886
887 GetNh() ? os << " NH(1)" : os << " NH(0)";
888
889 switch (GetHlim())
890 {
891 case HLIM_INLINE:
892 os << " HLIM_INLINE(" << +m_hopLimit << ")";
893 break;
894 case HLIM_COMPR_1:
895 os << " HLIM_COMPR_1(1)";
896 break;
897 case HLIM_COMPR_64:
898 os << " HLIM_COMPR_64(64)";
899 break;
900 default:
901 os << " HLIM_COMPR_255(255)";
902 break;
903 }
904
905 GetCid() ? os << " CID(" << +m_srcdstContextId << ")" : os << " CID(0)";
906
907 GetSac() ? os << " SAC(1)" : os << " SAC(0)";
908 os << " SAM (" << GetSam() << ")";
909
910 GetM() ? os << " M(1)" : os << " M(0)";
911 GetDac() ? os << " DAC(1)" : os << " DAC(0)";
912 os << " DAM (" << GetDam() << ")";
913}
914
917{
918 uint32_t serializedSize = 2;
919
920 if (GetCid())
921 {
922 serializedSize++;
923 }
924 switch (GetTf())
925 {
926 case TF_FULL:
927 serializedSize += 4;
928 break;
929 case TF_DSCP_ELIDED:
930 serializedSize += 3;
931 break;
932 case TF_FL_ELIDED:
933 serializedSize++;
934 break;
935 default:
936 break;
937 }
938 if (!GetNh())
939 {
940 serializedSize++;
941 }
942 if (GetHlim() == HLIM_INLINE)
943 {
944 serializedSize++;
945 }
946 switch (GetSam())
947 {
948 case HC_INLINE:
949 if (!GetSac())
950 {
951 serializedSize += 16;
952 }
953 break;
954 case HC_COMPR_64:
955 serializedSize += 8;
956 break;
957 case HC_COMPR_16:
958 serializedSize += 2;
959 break;
960 case HC_COMPR_0:
961 default:
962 break;
963 }
964 if (!GetM())
965 {
966 switch (GetDam())
967 {
968 case HC_INLINE:
969 if (!GetDac())
970 {
971 serializedSize += 16;
972 }
973 break;
974 case HC_COMPR_64:
975 serializedSize += 8;
976 break;
977 case HC_COMPR_16:
978 serializedSize += 2;
979 break;
980 case HC_COMPR_0:
981 default:
982 break;
983 }
984 }
985 else
986 {
987 switch (GetDam())
988 {
989 case HC_INLINE:
990 if (!GetDac())
991 {
992 serializedSize += 16;
993 }
994 else
995 {
996 serializedSize += 6;
997 }
998 break;
999 case HC_COMPR_64:
1000 if (!GetDac())
1001 {
1002 serializedSize += 6;
1003 }
1004 break;
1005 case HC_COMPR_16:
1006 if (!GetDac())
1007 {
1008 serializedSize += 4;
1009 }
1010 break;
1011 case HC_COMPR_0:
1012 default:
1013 if (!GetDac())
1014 {
1015 serializedSize++;
1016 }
1017 break;
1018 }
1019 }
1020
1021 return serializedSize;
1022}
1023
1024void
1026{
1027 Buffer::Iterator i = start;
1028
1030
1031 if (GetCid())
1032 {
1034 }
1035 // Traffic Class and Flow Label
1036 switch (GetTf())
1037 {
1038 uint8_t temp;
1039 case TF_FULL:
1040 temp = (m_ecn << 6) | m_dscp;
1041 i.WriteU8(temp);
1042 temp = m_flowLabel >> 16;
1043 i.WriteU8(temp);
1044 temp = (m_flowLabel >> 8) & 0xff;
1045 i.WriteU8(temp);
1046 temp = m_flowLabel & 0xff;
1047 i.WriteU8(temp);
1048 break;
1049 case TF_DSCP_ELIDED:
1050 temp = (m_ecn << 6) | (m_flowLabel >> 16);
1051 i.WriteU8(temp);
1052 temp = (m_flowLabel >> 8) & 0xff;
1053 i.WriteU8(temp);
1054 temp = m_flowLabel & 0xff;
1055 i.WriteU8(temp);
1056 break;
1057 case TF_FL_ELIDED:
1058 temp = (m_ecn << 6) | m_dscp;
1059 i.WriteU8(temp);
1060 break;
1061 default:
1062 break;
1063 }
1064 // Next Header
1065 if (!GetNh())
1066 {
1068 }
1069 // Hop Limit
1070 if (GetHlim() == HLIM_INLINE)
1071 {
1073 }
1074 // Source Address
1075 switch (GetSam())
1076 {
1077 case HC_INLINE:
1078 if (!GetSac())
1079 {
1080 i.Write(m_srcInlinePart, 16);
1081 }
1082 break;
1083 case HC_COMPR_64:
1084 i.Write(m_srcInlinePart, 8);
1085 break;
1086 case HC_COMPR_16:
1087 i.Write(m_srcInlinePart, 2);
1088 break;
1089 case HC_COMPR_0:
1090 default:
1091 break;
1092 }
1093 // Destination Address
1094 if (!GetM())
1095 {
1096 // unicast
1097 switch (GetDam())
1098 {
1099 case HC_INLINE:
1100 i.Write(m_dstInlinePart, 16);
1101 break;
1102 case HC_COMPR_64:
1103 i.Write(m_dstInlinePart, 8);
1104 break;
1105 case HC_COMPR_16:
1106 i.Write(m_dstInlinePart, 2);
1107 break;
1108 case HC_COMPR_0:
1109 default:
1110 break;
1111 }
1112 }
1113 else
1114 {
1115 // multicast
1116 switch (GetDam())
1117 {
1118 case HC_INLINE:
1119 // Stateful (DAC=1) multicast is the 48-bit form (RFC 6282, Section 3.1.1).
1120 if (!GetDac())
1121 {
1122 i.Write(m_dstInlinePart, 16);
1123 }
1124 else
1125 {
1126 i.Write(m_dstInlinePart, 6);
1127 }
1128 break;
1129 case HC_COMPR_64:
1130 i.Write(m_dstInlinePart, 6);
1131 break;
1132 case HC_COMPR_16:
1133 i.Write(m_dstInlinePart, 4);
1134 break;
1135 case HC_COMPR_0:
1136 i.Write(m_dstInlinePart, 1);
1137 break;
1138 default:
1139 break;
1140 }
1141 }
1142}
1143
1146{
1147 Buffer::Iterator i = start;
1148
1150
1151 if (GetCid())
1152 {
1154 }
1155 else
1156 {
1158 }
1159 // Traffic Class and Flow Label
1160 switch (GetTf())
1161 {
1162 uint8_t temp;
1163 case TF_FULL:
1164 temp = i.ReadU8();
1165 m_ecn = temp >> 6;
1166 m_dscp = temp & 0x3F;
1167 temp = i.ReadU8();
1168 m_flowLabel = temp;
1169 temp = i.ReadU8();
1170 m_flowLabel = (m_flowLabel << 8) | temp;
1171 temp = i.ReadU8();
1172 m_flowLabel = (m_flowLabel << 8) | temp;
1173 break;
1174 case TF_DSCP_ELIDED:
1175 temp = i.ReadU8();
1176 m_ecn = temp >> 6;
1177 m_flowLabel = temp & 0x3F;
1178 temp = i.ReadU8();
1179 m_flowLabel = (m_flowLabel << 8) | temp;
1180 temp = i.ReadU8();
1181 m_flowLabel = (m_flowLabel << 8) | temp;
1182 break;
1183 case TF_FL_ELIDED:
1184 temp = i.ReadU8();
1185 m_ecn = temp >> 6;
1186 m_dscp = temp & 0x3F;
1187 break;
1188 default:
1189 break;
1190 }
1191 // Next Header
1192 if (!GetNh())
1193 {
1194 m_nextHeader = i.ReadU8();
1195 }
1196 // Hop Limit
1197 switch (GetHlim())
1198 {
1199 case HLIM_INLINE:
1200 m_hopLimit = i.ReadU8();
1201 break;
1202 case HLIM_COMPR_1:
1203 m_hopLimit = 1;
1204 break;
1205 case HLIM_COMPR_64:
1206 m_hopLimit = 64;
1207 break;
1208 case HLIM_COMPR_255:
1209 default:
1210 m_hopLimit = 255;
1211 break;
1212 }
1213 // Source Address
1214 memset(m_srcInlinePart, 0x00, sizeof(m_srcInlinePart));
1215 switch (GetSam())
1216 {
1217 case HC_INLINE:
1218 if (!GetSac())
1219 {
1220 i.Read(m_srcInlinePart, 16);
1221 }
1222 break;
1223 case HC_COMPR_64:
1224 i.Read(m_srcInlinePart, 8);
1225 break;
1226 case HC_COMPR_16:
1227 i.Read(m_srcInlinePart, 2);
1228 break;
1229 case HC_COMPR_0:
1230 default:
1231 break;
1232 }
1233
1234 // Destination Address
1235 memset(m_dstInlinePart, 0x00, sizeof(m_dstInlinePart));
1236 if (!GetM())
1237 {
1238 // unicast
1239 switch (GetDam())
1240 {
1241 case HC_INLINE:
1242 i.Read(m_dstInlinePart, 16);
1243 break;
1244 case HC_COMPR_64:
1245 i.Read(m_dstInlinePart, 8);
1246 break;
1247 case HC_COMPR_16:
1248 i.Read(m_dstInlinePart, 2);
1249 break;
1250 case HC_COMPR_0:
1251 default:
1252 break;
1253 }
1254 }
1255 else
1256 {
1257 // multicast
1258 switch (GetDam())
1259 {
1260 case HC_INLINE:
1261 // Stateful (DAC=1) multicast is the 48-bit form (RFC 6282, Section 3.1.1).
1262 if (!GetDac())
1263 {
1264 i.Read(m_dstInlinePart, 16);
1265 }
1266 else
1267 {
1268 i.Read(m_dstInlinePart, 6);
1269 }
1270 break;
1271 case HC_COMPR_64:
1272 i.Read(m_dstInlinePart, 6);
1273 break;
1274 case HC_COMPR_16:
1275 i.Read(m_dstInlinePart, 4);
1276 break;
1277 case HC_COMPR_0:
1278 i.Read(m_dstInlinePart, 1);
1279 break;
1280 default:
1281 break;
1282 }
1283 }
1284
1285 return GetSerializedSize();
1286}
1287
1288void
1290{
1291 uint16_t field = tfField;
1292 m_baseFormat |= (field << 11);
1293}
1294
1297{
1298 return TrafficClassFlowLabel_e((m_baseFormat >> 11) & 0x3);
1299}
1300
1301void
1303{
1304 uint16_t field = nhField;
1305 m_baseFormat |= (field << 10);
1306}
1307
1308bool
1310{
1311 return ((m_baseFormat >> 10) & 0x1);
1312}
1313
1314void
1316{
1317 uint16_t field = hlimField;
1318 m_baseFormat |= (field << 8);
1319}
1320
1323{
1324 return Hlim_e((m_baseFormat >> 8) & 0x3);
1325}
1326
1327void
1329{
1330 uint16_t field = cidField;
1331 m_baseFormat |= (field << 7);
1332}
1333
1334bool
1336{
1337 return ((m_baseFormat >> 7) & 0x1);
1338}
1339
1340void
1342{
1343 uint16_t field = sacField;
1344 m_baseFormat |= (field << 6);
1345}
1346
1347bool
1349{
1350 return ((m_baseFormat >> 6) & 0x1);
1351}
1352
1353void
1355{
1356 uint16_t field = samField;
1357 m_baseFormat |= (field << 4);
1358}
1359
1362{
1363 return HeaderCompression_e((m_baseFormat >> 4) & 0x3);
1364}
1365
1366const uint8_t*
1368{
1369 return m_srcInlinePart;
1370}
1371
1372void
1373SixLowPanIphc::SetSrcInlinePart(uint8_t srcInlinePart[16], uint8_t size)
1374{
1375 NS_ASSERT_MSG(size <= 16, "Src inline part too large");
1376
1377 memcpy(m_srcInlinePart, srcInlinePart, size);
1378}
1379
1380void
1382{
1383 uint16_t field = mField;
1384 m_baseFormat |= (field << 3);
1385}
1386
1387bool
1389{
1390 return ((m_baseFormat >> 3) & 0x1);
1391}
1392
1393void
1395{
1396 uint16_t field = dacField;
1397 m_baseFormat |= (field << 2);
1398}
1399
1400bool
1402{
1403 return ((m_baseFormat >> 2) & 0x1);
1404}
1405
1406void
1408{
1409 uint16_t field = damField;
1410 m_baseFormat |= field;
1411}
1412
1415{
1416 return HeaderCompression_e(m_baseFormat & 0x3);
1417}
1418
1419const uint8_t*
1421{
1422 return m_dstInlinePart;
1423}
1424
1425void
1426SixLowPanIphc::SetDstInlinePart(uint8_t dstInlinePart[16], uint8_t size)
1427{
1428 NS_ASSERT_MSG(size <= 16, "Dst inline part too large");
1429
1430 memcpy(m_dstInlinePart, dstInlinePart, size);
1431}
1432
1433void
1435{
1436 NS_ASSERT_MSG(srcContextId < 16, "Src Context ID too large");
1437 m_srcdstContextId |= srcContextId << 4;
1438}
1439
1440uint8_t
1442{
1443 return (m_srcdstContextId >> 4);
1444}
1445
1446void
1448{
1449 NS_ASSERT_MSG(dstContextId < 16, "Dst Context ID too large");
1450 m_srcdstContextId |= (dstContextId & 0xF);
1451}
1452
1453uint8_t
1455{
1456 return (m_srcdstContextId & 0xF);
1457}
1458
1459void
1461{
1462 NS_ASSERT_MSG(ecn < 4, "ECN too large");
1463 m_ecn = ecn;
1464}
1465
1466uint8_t
1468{
1469 return m_ecn;
1470}
1471
1472void
1474{
1475 NS_ASSERT_MSG(dscp < 64, "DSCP too large");
1476 m_dscp = dscp;
1477}
1478
1479uint8_t
1481{
1482 return m_dscp;
1483}
1484
1485void
1487{
1488 NS_ASSERT_MSG(flowLabel < 0x100000, "Flow Label too large");
1489 m_flowLabel = flowLabel;
1490}
1491
1494{
1495 return m_flowLabel;
1496}
1497
1498void
1500{
1501 m_nextHeader = nextHeader;
1502}
1503
1504uint8_t
1506{
1507 return m_nextHeader;
1508}
1509
1510void
1512{
1513 m_hopLimit = hopLimit;
1514}
1515
1516uint8_t
1518{
1519 return m_hopLimit;
1520}
1521
1522std::ostream&
1523operator<<(std::ostream& os, const SixLowPanIphc& h)
1524{
1525 h.Print(os);
1526 return os;
1527}
1528
1529/*
1530 * SixLowPanNhcExtensionHeader
1531 */
1532NS_OBJECT_ENSURE_REGISTERED(SixLowPanNhcExtension);
1533
1535{
1536 // 1110 xxxx
1537 m_nhcExtensionHeader = 0xE0;
1538 m_nhcNextHeader = 0;
1539 m_nhcBlobLength = 0;
1540}
1541
1542TypeId
1544{
1545 static TypeId tid = TypeId("ns3::SixLowPanNhcExtension")
1546 .SetParent<Header>()
1547 .SetGroupName("SixLowPan")
1548 .AddConstructor<SixLowPanNhcExtension>();
1549 return tid;
1550}
1551
1552TypeId
1554{
1555 return GetTypeId();
1556}
1557
1558void
1559SixLowPanNhcExtension::Print(std::ostream& os) const
1560{
1561 os << "Compression kind: " << +m_nhcExtensionHeader << " Size: " << GetSerializedSize();
1562}
1563
1566{
1567 uint32_t serializedSize = 2;
1568 if (!GetNh())
1569 {
1570 serializedSize++;
1571 }
1572 return serializedSize + m_nhcBlobLength;
1573}
1574
1575void
1577{
1578 Buffer::Iterator i = start;
1580 if (!GetNh())
1581 {
1583 }
1586}
1587
1590{
1591 Buffer::Iterator i = start;
1593 if (!GetNh())
1594 {
1595 m_nhcNextHeader = i.ReadU8();
1596 }
1597 m_nhcBlobLength = i.ReadU8();
1599
1600 return GetSerializedSize();
1601}
1602
1608
1609void
1611{
1612 uint8_t field = extensionHeaderType;
1613 m_nhcExtensionHeader |= (field << 1);
1614}
1615
1618{
1619 return Eid_e((m_nhcExtensionHeader >> 1) & 0x7);
1620}
1621
1622void
1624{
1625 m_nhcNextHeader = nextHeader;
1626}
1627
1628uint8_t
1633
1634void
1636{
1637 uint8_t field = nhField;
1638 m_nhcExtensionHeader |= field;
1639}
1640
1641bool
1643{
1644 return m_nhcExtensionHeader & 0x01;
1645}
1646
1647void
1649{
1650 NS_ASSERT_MSG(size < 255, "Buffer too long");
1651
1652 m_nhcBlobLength = size;
1653 std::memcpy(m_nhcBlob, blob, size);
1654}
1655
1658{
1659 NS_ASSERT_MSG(size > m_nhcBlobLength, "Buffer too short");
1660
1661 std::memcpy(blob, m_nhcBlob, m_nhcBlobLength);
1662 return m_nhcBlobLength;
1663}
1664
1665std::ostream&
1666operator<<(std::ostream& os, const SixLowPanNhcExtension& h)
1667{
1668 h.Print(os);
1669 return os;
1670}
1671
1672/*
1673 * SixLowPanUdpNhcExtension
1674 */
1675NS_OBJECT_ENSURE_REGISTERED(SixLowPanUdpNhcExtension);
1676
1678{
1679 // 1111 0xxx
1680 m_baseFormat = 0xF0;
1681 m_checksum = 0;
1682 m_srcPort = 0;
1683 m_dstPort = 0;
1684}
1685
1686TypeId
1688{
1689 static TypeId tid = TypeId("ns3::SixLowPanUdpNhcExtension")
1690 .SetParent<Header>()
1691 .SetGroupName("SixLowPan")
1692 .AddConstructor<SixLowPanUdpNhcExtension>();
1693 return tid;
1694}
1695
1696TypeId
1701
1702void
1703SixLowPanUdpNhcExtension::Print(std::ostream& os) const
1704{
1705 os << "Compression kind: " << +m_baseFormat;
1706}
1707
1710{
1711 uint32_t serializedSize = 1;
1712 if (!GetC())
1713 {
1714 serializedSize += 2;
1715 }
1716 switch (GetPorts())
1717 {
1718 case PORTS_INLINE:
1719 serializedSize += 4;
1720 break;
1723 serializedSize += 3;
1724 break;
1726 serializedSize += 1;
1727 break;
1728 default:
1729 break;
1730 }
1731 return serializedSize;
1732}
1733
1734void
1736{
1737 Buffer::Iterator i = start;
1739 uint8_t temp;
1740
1741 // Ports
1742 switch (GetPorts())
1743 {
1744 case PORTS_INLINE:
1747 break;
1750 i.WriteU8(m_dstPort & 0xff);
1751 break;
1753 i.WriteU8(m_srcPort & 0xff);
1755 break;
1757 temp = ((m_srcPort & 0xf) << 4) | (m_dstPort & 0xf);
1758 i.WriteU8(temp);
1759 break;
1760 default:
1761 break;
1762 }
1763
1764 // Checksum
1765 if (!GetC())
1766 {
1768 }
1769}
1770
1773{
1774 Buffer::Iterator i = start;
1775 m_baseFormat = i.ReadU8();
1776 uint8_t temp;
1777
1778 // Ports
1779 switch (GetPorts())
1780 {
1781 case PORTS_INLINE:
1782 m_srcPort = i.ReadNtohU16();
1783 m_dstPort = i.ReadNtohU16();
1784 break;
1786 m_srcPort = i.ReadNtohU16();
1787 m_dstPort = i.ReadU8();
1788 break;
1790 m_srcPort = i.ReadU8();
1791 m_dstPort = i.ReadNtohU16();
1792 break;
1794 temp = i.ReadU8();
1795 m_srcPort = temp >> 4;
1796 m_dstPort = temp & 0xf;
1797 break;
1798 default:
1799 break;
1800 }
1801
1802 // Checksum
1803 if (!GetC())
1804 {
1805 m_checksum = i.ReadU16();
1806 }
1807
1808 return GetSerializedSize();
1809}
1810
1816
1817void
1819{
1820 uint16_t field = ports;
1821 m_baseFormat |= field;
1822}
1823
1826{
1827 return Ports_e(m_baseFormat & 0x3);
1828}
1829
1830void
1832{
1833 m_srcPort = srcport;
1834}
1835
1836uint16_t
1838{
1839 return m_srcPort;
1840}
1841
1842void
1844{
1845 m_dstPort = dstport;
1846}
1847
1848uint16_t
1850{
1851 return m_dstPort;
1852}
1853
1854void
1856{
1857 uint16_t field = cField;
1858 m_baseFormat |= (field << 2);
1859}
1860
1861bool
1863{
1864 return ((m_baseFormat >> 2) & 0x1);
1865}
1866
1867void
1869{
1870 m_checksum = checksum;
1871}
1872
1873uint16_t
1875{
1876 return m_checksum;
1877}
1878
1879std::ostream&
1880operator<<(std::ostream& os, const SixLowPanUdpNhcExtension& h)
1881{
1882 h.Print(os);
1883 return os;
1884}
1885
1886/*
1887 * SixLowPanBc0
1888 */
1889NS_OBJECT_ENSURE_REGISTERED(SixLowPanBc0);
1890
1895
1896TypeId
1898{
1899 static TypeId tid = TypeId("ns3::SixLowPanBc0")
1900 .SetParent<Header>()
1901 .SetGroupName("SixLowPan")
1902 .AddConstructor<SixLowPanBc0>();
1903 return tid;
1904}
1905
1906TypeId
1908{
1909 return GetTypeId();
1910}
1911
1912void
1913SixLowPanBc0::Print(std::ostream& os) const
1914{
1915 os << "Sequence number: " << +m_seqNumber;
1916}
1917
1920{
1921 return 2;
1922}
1923
1924void
1926{
1927 Buffer::Iterator i = start;
1928 i.WriteU8(0x50);
1930}
1931
1934{
1935 Buffer::Iterator i = start;
1936 uint8_t dispatch = i.ReadU8();
1937
1938 if (dispatch != 0x50)
1939 {
1940 return 0;
1941 }
1942
1943 m_seqNumber = i.ReadU8();
1944
1945 return GetSerializedSize();
1946}
1947
1948void
1950{
1951 m_seqNumber = seqNumber;
1952}
1953
1954uint8_t
1956{
1957 return m_seqNumber;
1958}
1959
1960std::ostream&
1961operator<<(std::ostream& os, const SixLowPanBc0& h)
1962{
1963 h.Print(os);
1964 return os;
1965}
1966
1967/*
1968 * SixLowPanMesh
1969 */
1970NS_OBJECT_ENSURE_REGISTERED(SixLowPanMesh);
1971
1973{
1974 m_hopsLeft = 0;
1975 m_src = Address();
1976 m_dst = Address();
1977 m_v = false;
1978 m_f = false;
1979}
1980
1981TypeId
1983{
1984 static TypeId tid = TypeId("ns3::SixLowPanMesh")
1985 .SetParent<Header>()
1986 .SetGroupName("SixLowPan")
1987 .AddConstructor<SixLowPanMesh>();
1988 return tid;
1989}
1990
1991TypeId
1993{
1994 return GetTypeId();
1995}
1996
1997void
1998SixLowPanMesh::Print(std::ostream& os) const
1999{
2000 os << "Hops left: " << +m_hopsLeft << ", src: ";
2002 {
2004 }
2005 else
2006 {
2008 }
2009 os << ", dst: ";
2011 {
2013 }
2014 else
2015 {
2017 }
2018}
2019
2022{
2023 uint32_t serializedSize = 1;
2024
2025 if (m_hopsLeft >= 0xF)
2026 {
2027 serializedSize++;
2028 }
2029
2030 if (m_v)
2031 {
2032 serializedSize += 2;
2033 }
2034 else
2035 {
2036 serializedSize += 8;
2037 }
2038
2039 if (m_f)
2040 {
2041 serializedSize += 2;
2042 }
2043 else
2044 {
2045 serializedSize += 8;
2046 }
2047
2048 return serializedSize;
2049}
2050
2051void
2053{
2054 Buffer::Iterator i = start;
2055
2056 uint8_t dispatch = 0x80;
2057
2058 if (m_v)
2059 {
2060 dispatch |= 0x20;
2061 }
2062 if (m_f)
2063 {
2064 dispatch |= 0x10;
2065 }
2066
2067 if (m_hopsLeft < 0xF)
2068 {
2069 dispatch |= m_hopsLeft;
2070 i.WriteU8(dispatch);
2071 }
2072 else
2073 {
2074 dispatch |= 0xF;
2075 i.WriteU8(dispatch);
2077 }
2078
2079 uint8_t buffer[8];
2080
2081 m_src.CopyTo(buffer);
2082 if (m_v)
2083 {
2084 i.Write(buffer, 2);
2085 }
2086 else
2087 {
2088 i.Write(buffer, 8);
2089 }
2090
2091 m_dst.CopyTo(buffer);
2092 if (m_f)
2093 {
2094 i.Write(buffer, 2);
2095 }
2096 else
2097 {
2098 i.Write(buffer, 8);
2099 }
2100}
2101
2104{
2105 Buffer::Iterator i = start;
2106 uint8_t temp = i.ReadU8();
2107
2108 if ((temp & 0xC0) != 0x80)
2109 {
2110 return 0;
2111 }
2112
2113 m_v = temp & 0x20;
2114 m_f = temp & 0x10;
2115 m_hopsLeft = temp & 0xF;
2116
2117 if (m_hopsLeft == 0xF)
2118 {
2119 m_hopsLeft = i.ReadU8();
2120 }
2121
2122 uint8_t buffer[8];
2123 uint8_t addrSize;
2124
2125 if (m_v)
2126 {
2127 addrSize = 2;
2128 }
2129 else
2130 {
2131 addrSize = 8;
2132 }
2133 i.Read(buffer, addrSize);
2134 m_src.SetType("MacAddress", addrSize);
2135 m_src.CopyFrom(buffer, addrSize);
2136
2137 if (m_f)
2138 {
2139 addrSize = 2;
2140 }
2141 else
2142 {
2143 addrSize = 8;
2144 }
2145 i.Read(buffer, addrSize);
2146 m_dst.SetType("MacAddress", addrSize);
2147 m_dst.CopyFrom(buffer, addrSize);
2148
2149 return GetSerializedSize();
2150}
2151
2152void
2154{
2155 if (Mac64Address::IsMatchingType(originator))
2156 {
2157 m_v = false;
2158 }
2159 else if (Mac16Address::IsMatchingType(originator))
2160 {
2161 m_v = true;
2162 }
2163 else
2164 {
2165 NS_ABORT_MSG("SixLowPanMesh::SetOriginator - incompatible address");
2166 }
2167
2168 m_src = originator;
2169}
2170
2171Address
2173{
2174 return m_src;
2175}
2176
2177void
2179{
2180 if (Mac64Address::IsMatchingType(finalDst))
2181 {
2182 m_f = false;
2183 }
2184 else if (Mac16Address::IsMatchingType(finalDst))
2185 {
2186 m_f = true;
2187 }
2188 else
2189 {
2190 NS_ABORT_MSG("SixLowPanMesh::SetFinalDst - incompatible address");
2191 }
2192
2193 m_dst = finalDst;
2194}
2195
2196Address
2198{
2199 return m_dst;
2200}
2201
2202void
2204{
2205 m_hopsLeft = hopsLeft;
2206}
2207
2208uint8_t
2210{
2211 return m_hopsLeft;
2212}
2213
2214std::ostream&
2215operator<<(std::ostream& os, const SixLowPanMesh& h)
2216{
2217 h.Print(os);
2218 return os;
2219}
2220
2221/*
2222 * SixLowPanCio
2223 */
2224NS_OBJECT_ENSURE_REGISTERED(Icmpv6OptionSixLowPanCapabilityIndication);
2225
2232
2233TypeId
2235{
2236 static TypeId tid = TypeId("ns3::Icmpv6OptionSixLowPanCapabilityIndication")
2238 .SetGroupName("SixLowPan")
2240 return tid;
2241}
2242
2243TypeId
2248
2249void
2251{
2252 os << "( type = " << (uint32_t)GetType() << " Option field: ";
2253
2255 {
2256 os << "D";
2257 }
2258 else
2259 {
2260 os << " ";
2261 }
2262
2264 {
2265 os << "L";
2266 }
2267 else
2268 {
2269 os << " ";
2270 }
2271
2273 {
2274 os << "B";
2275 }
2276 else
2277 {
2278 os << " ";
2279 }
2280
2282 {
2283 os << "P";
2284 }
2285 else
2286 {
2287 os << " ";
2288 }
2289
2291 {
2292 os << "E";
2293 }
2294 else
2295 {
2296 os << " ";
2297 }
2298
2300 {
2301 os << "G";
2302 }
2303 else
2304 {
2305 os << " ";
2306 }
2307 os << " )";
2308}
2309
2315
2316void
2318{
2319 Buffer::Iterator i = start;
2320
2321 i.WriteU8(GetType());
2322 i.WriteU8(GetLength());
2323
2324 i.WriteU8(0);
2326 i.WriteU32(0);
2327}
2328
2331{
2332 Buffer::Iterator i = start;
2333
2334 SetType(i.ReadU8());
2335 SetLength(i.ReadU8());
2336
2337 i.Next();
2339 i.Next(4);
2340
2341 return GetSerializedSize();
2342}
2343
2344void
2349
2350bool
2355
2356std::ostream&
2357operator<<(std::ostream& os, const Icmpv6OptionSixLowPanCapabilityIndication& h)
2358{
2359 h.Print(os);
2360 return os;
2361}
2362
2363} // namespace ns3
a polymophic address class
Definition address.h:114
iterator in a Buffer instance
Definition buffer.h:109
void WriteU32(uint32_t data)
Definition buffer.cc:855
void WriteU8(uint8_t data)
Definition buffer.h:944
void Write(const uint8_t *buffer, uint32_t size)
Definition buffer.cc:935
void WriteU16(uint16_t data)
Definition buffer.cc:846
void Read(uint8_t *buffer, uint32_t size)
Definition buffer.cc:1112
void WriteHtonU16(uint16_t data)
Definition buffer.h:978
uint16_t ReadNtohU16()
Definition buffer.h:1017
uint16_t ReadU16()
Definition buffer.h:1098
void Next()
go forward by one byte
Definition buffer.h:916
Protocol header serialization and deserialization.
Definition header.h:36
ICMPv6 header.
void SetType(uint8_t type)
Set the type of the option.
uint8_t GetType() const
Get the type of the option.
void SetLength(uint8_t len)
Set the length of the option.
uint8_t GetLength() const
Get the length of the option in 8 bytes unit.
6LoWPAN Capability Indication Option - see RFC 7400.
void SetOption(SixLowPanCapability_e option)
Set an option.
bool CheckOption(SixLowPanCapability_e option) const
Checks an option.
uint32_t GetSerializedSize() const override
Get the serialized size of the packet.
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the packet.
@ P
The node is a Routing Registrar (see RFC 8505).
@ G
Generic Header Compression (GHC) capable (see RFC 7400).
@ B
The node is a 6LBR (see RFC 8505).
@ E
The node is an IPv6 ND Registrar (see RFC 8505).
@ D
The 6LBR supports EDAR and EDAC messages (see RFC 8505).
uint8_t m_capabilityOptionField
Capability options bitfield.
void Print(std::ostream &os) const override
Print information.
TypeId GetInstanceTypeId() const override
Return the instance type identifier.
void Serialize(Buffer::Iterator start) const override
Serialize the packet.
static bool IsMatchingType(const Address &address)
static Mac16Address ConvertFrom(const Address &address)
static bool IsMatchingType(const Address &address)
static Mac64Address ConvertFrom(const Address &address)
6LoWPAN BC0 header - see RFC 4944.
void Print(std::ostream &os) const override
void Serialize(Buffer::Iterator start) const override
Serialize the packet.
TypeId GetInstanceTypeId() const override
Return the instance type identifier.
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the packet.
uint32_t GetSerializedSize() const override
Get the serialized size of the packet.
void SetSequenceNumber(uint8_t seqNumber)
Set the "Sequence Number" field.
static TypeId GetTypeId()
Get the type ID.
uint8_t m_seqNumber
Sequence number.
uint8_t GetSequenceNumber() const
Get the "Sequence Number" field.
static Dispatch_e GetDispatchType(uint8_t dispatch)
Get the Dispatch type.
Dispatch_e
Dispatch values, as defined in RFC 4944 and RFC 6282.
static NhcDispatch_e GetNhcDispatchType(uint8_t dispatch)
Get the NhcDispatch type.
NhcDispatch_e
Dispatch values for Next Header compression.
6LoWPAN FRAG1 header - see RFC 4944.
TypeId GetInstanceTypeId() const override
Return the instance type identifier.
static TypeId GetTypeId()
Get the type ID.
void SetDatagramSize(uint16_t datagramSize)
Set the datagram size.
void Print(std::ostream &os) const override
void SetDatagramTag(uint16_t datagramTag)
Set the datagram tag.
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the packet.
uint16_t GetDatagramSize() const
Get the datagram size.
void Serialize(Buffer::Iterator start) const override
Serialize the packet.
uint16_t m_datagramTag
Datagram tag.
uint16_t GetDatagramTag() const
Get the datagram tag.
uint32_t GetSerializedSize() const override
Get the serialized size of the packet.
uint16_t m_datagramSize
Datagram size.
6LoWPAN FRAGN header - see RFC 4944.
TypeId GetInstanceTypeId() const override
Return the instance type identifier.
void Serialize(Buffer::Iterator start) const override
Serialize the packet.
uint16_t m_datagramTag
Datagram tag.
void SetDatagramSize(uint16_t datagramSize)
Set the datagram size.
uint32_t GetSerializedSize() const override
Get the serialized size of the packet.
static TypeId GetTypeId()
Get the type ID.
uint16_t GetDatagramTag() const
Get the datagram tag.
void SetDatagramTag(uint16_t datagramTag)
Set the datagram tag.
void SetDatagramOffset(uint8_t datagramOffset)
Set the datagram offset.
uint8_t GetDatagramOffset() const
Get the datagram offset.
uint8_t m_datagramOffset
Datagram offset.
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the packet.
uint16_t GetDatagramSize() const
Get the datagram size.
uint16_t m_datagramSize
Datagram size.
void Print(std::ostream &os) const override
6LoWPAN HC1 header - see RFC 4944.
static TypeId GetTypeId()
Get the type ID.
void SetTcflCompression(bool tcflCompression)
Set the Traffic Class and Flow Labels as compressed.
uint8_t m_dstInterface[8]
Destination interface.
uint8_t GetHopLimit() const
Get the "Hop limit" field (TTL).
const uint8_t * GetSrcPrefix() const
Get the source prefix.
void SetFlowLabel(uint32_t flowLabel)
Set the Flow Label value.
uint8_t GetTrafficClass() const
Get the Traffic Class value.
void SetDstCompression(LowPanHc1Addr_e dstCompression)
Set Destination Compression type.
void SetTrafficClass(uint8_t trafficClass)
Set the Traffic Class value.
TypeId GetInstanceTypeId() const override
Return the instance type identifier.
void SetHopLimit(uint8_t limit)
Set the "Hop limit" field (TTL).
LowPanHc1Addr_e
Kind of address compression.
uint8_t m_srcInterface[8]
Source interface.
uint8_t m_dstPrefix[8]
Destination prefix.
uint32_t GetFlowLabel() const
Get the Flow Label value.
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the packet.
bool m_hc2HeaderPresent
Is next header HC2 compressed.
const uint8_t * GetSrcInterface() const
Get the source interface.
const uint8_t * GetDstPrefix() const
Get the destination prefix.
void SetHc2HeaderPresent(bool hc2HeaderPresent)
Set the next header a HC2 compressed header.
LowPanHc1NextHeader_e m_nextHeaderCompression
Next header compression.
uint32_t GetSerializedSize() const override
Get the serialized size of the packet.
bool m_tcflCompression
Is TC and FL compressed.
uint32_t m_flowLabel
Flow Label.
void SetNextHeader(uint8_t nextHeader)
Set the Next Header value.
LowPanHc1Addr_e m_dstCompression
Destination compression type.
LowPanHc1NextHeader_e
Next header information.
void Serialize(Buffer::Iterator start) const override
Serialize the packet.
uint8_t m_hopLimit
Hop Limit.
void SetSrcCompression(LowPanHc1Addr_e srcCompression)
Set Source Compression type.
uint8_t m_srcPrefix[8]
Source prefix.
void SetDstInterface(const uint8_t *dstInterface)
Set the destination interface.
void SetDstPrefix(const uint8_t *dstPrefix)
Set the destination prefix.
const uint8_t * GetDstInterface() const
Get the destination interface.
LowPanHc1Addr_e m_srcCompression
Source compression type.
uint8_t m_nextHeader
Next header.
void Print(std::ostream &os) const override
void SetSrcPrefix(const uint8_t *srcPrefix)
Set the source prefix.
uint8_t GetNextHeader() const
Get the Next Header value.
void SetSrcInterface(const uint8_t *srcInterface)
Set the source interface.
uint8_t m_trafficClass
Traffic Class.
LowPanHc1Addr_e GetDstCompression() const
Get Destination Compression type.
bool IsHc2HeaderPresent() const
Check if there is a HC2 compressed header.
LowPanHc1Addr_e GetSrcCompression() const
Get Source Compression type.
bool IsTcflCompression() const
Check if the Traffic Class and Flow Labels are compressed.
LOWPAN_IPHC base Encoding - see RFC 6282.
bool GetSac() const
Get the SAC (Source Address Compression) compression.
void SetNextHeader(uint8_t nextHeader)
Set the Next Header field.
uint8_t GetNextHeader() const
Get the Next Header field.
void SetHlim(Hlim_e hlimField)
Set the HLIM (Hop Limit) compression.
void SetDstContextId(uint8_t dstContextId)
Set the DstContextId.
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the packet.
Hlim_e
HLIM: Hop Limit.
const uint8_t * GetSrcInlinePart() const
brief Get the source address inline part
uint8_t m_srcdstContextId
Src and Dst Context ID.
void SetSam(HeaderCompression_e samField)
Set the SAM (Source Address Mode) compression.
void SetNh(bool nhField)
Set the NH (Next Header) compression.
uint8_t GetDscp() const
Get the DSCP.
HeaderCompression_e
Source or Destination Address Mode.
HeaderCompression_e GetDam() const
Get the DAM (Destination Address Mode) compression.
uint8_t GetHopLimit() const
Get the Hop Limit field.
bool GetDac() const
Get the DAC (Destination Address Compression) compression.
uint8_t m_srcInlinePart[16]
source address inline part.
void SetEcn(uint8_t ecn)
Set the ECN (2bits).
uint8_t m_hopLimit
Hop Limit.
void SetFlowLabel(uint32_t flowLabel)
Set the Flow Label (20bits).
void Serialize(Buffer::Iterator start) const override
Serialize the packet.
void SetDscp(uint8_t dscp)
Set the DSCP (6bits).
uint32_t GetFlowLabel() const
Get the Flow Label.
void SetTf(TrafficClassFlowLabel_e tfField)
Set the TF (Traffic Class, Flow Label) compression.
uint8_t GetEcn() const
Get the ECN.
static TypeId GetTypeId()
Get the type ID.
void SetDam(HeaderCompression_e damField)
Set the DAM (Destination Address Mode) compression.
void SetCid(bool cidField)
Set the CID (Context Identifier Extension) compression.
uint32_t GetSerializedSize() const override
Get the serialized size of the packet.
Hlim_e GetHlim() const
Get the HLIM (Hop Limit) compression.
uint8_t m_dscp
DSCP bits.
void SetSac(bool sacField)
Set the SAC (Source Address Compression) compression.
bool GetNh() const
Get the NH (Next Header) compression.
void Print(std::ostream &os) const override
TrafficClassFlowLabel_e GetTf() const
Get the TF (Traffic Class, Flow Label) compression.
bool GetM() const
Get the M (Multicast) compression.
HeaderCompression_e GetSam() const
Get the SAM (Source Address Mode) compression.
uint8_t m_dstInlinePart[16]
destination address inline part.
TypeId GetInstanceTypeId() const override
Return the instance type identifier.
void SetDstInlinePart(uint8_t dstInlinePart[16], uint8_t size)
brief Set the destination address inline part
void SetSrcContextId(uint8_t srcContextId)
Set the SrcContextId.
void SetSrcInlinePart(uint8_t srcInlinePart[16], uint8_t size)
brief Set the source address inline part
TrafficClassFlowLabel_e
TF: Traffic Class, Flow Label.
void SetM(bool mField)
Set the M (Multicast) compression.
uint16_t m_baseFormat
Dispatch + encoding fields.
uint8_t m_nextHeader
Next header.
const uint8_t * GetDstInlinePart() const
brief Get the destination address inline part
bool GetCid() const
Get the CID (Context Identifier Extension) compression.
uint8_t GetSrcContextId() const
Get the SrcContextId.
uint32_t m_flowLabel
Flow Label bits.
void SetHopLimit(uint8_t hopLimit)
Set the Hop Limit field.
uint8_t m_ecn
ECN bits.
uint8_t GetDstContextId() const
Get the DstContextId.
void SetDac(bool dacField)
Set the DAC (Destination Address Compression) compression.
6LoWPAN IPv6 uncompressed header - see RFC 4944.
uint32_t GetSerializedSize() const override
Get the serialized size of the packet.
static TypeId GetTypeId()
Get the type ID.
TypeId GetInstanceTypeId() const override
Return the instance type identifier.
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the packet.
void Serialize(Buffer::Iterator start) const override
Serialize the packet.
void Print(std::ostream &os) const override
6LoWPAN Mesh header - see RFC 4944.
bool m_f
True if Destination address is 16 bit.
void Serialize(Buffer::Iterator start) const override
Serialize the packet.
Address GetOriginator() const
Get the "Originator" address.
bool m_v
True if Originator address is 16 bit.
void SetHopsLeft(uint8_t hopsLeft)
Set the "Hops Left" field.
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the packet.
void SetFinalDst(Address finalDst)
Set the "Final Destination" address.
uint8_t m_hopsLeft
Hops left.
Address m_src
Originator (source) address.
TypeId GetInstanceTypeId() const override
Return the instance type identifier.
uint32_t GetSerializedSize() const override
Get the serialized size of the packet.
uint8_t GetHopsLeft() const
Get the "Hops Left" field.
static TypeId GetTypeId()
Get the type ID.
void Print(std::ostream &os) const override
Address GetFinalDst() const
Get the "Final Destination" address.
void SetOriginator(Address originator)
Set the "Originator" address.
Address m_dst
Destination (final) address.
LOWPAN_NHC Extension Header Encoding - see RFC 6282.
uint8_t m_nhcNextHeader
Next header.
uint8_t m_nhcBlob[256]
NHC compressed header.
SixLowPanDispatch::NhcDispatch_e GetNhcDispatchType() const
Get the NhcDispatch type.
TypeId GetInstanceTypeId() const override
Return the instance type identifier.
bool GetNh() const
Get the Next Header field value.
uint8_t m_nhcExtensionHeader
NHC extension header type.
Eid_e GetEid() const
Get the Extension Header Type.
void SetNh(bool nhField)
Set the NH field values.
void SetEid(Eid_e extensionHeaderType)
Set the Extension Header Type.
uint8_t m_nhcBlobLength
Length of the NHC compressed header.
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the packet.
void SetBlob(const uint8_t *blob, uint32_t size)
Set the option header data blob.
void Print(std::ostream &os) const override
void Serialize(Buffer::Iterator start) const override
Serialize the packet.
Eid_e
EID: IPv6 Extension Header ID.
uint32_t CopyBlob(uint8_t *blob, uint32_t size) const
Get the option header data blob.
uint8_t GetNextHeader() const
Get the Next Header field value.
void SetNextHeader(uint8_t nextHeader)
Set the Next Header field values.
uint32_t GetSerializedSize() const override
Get the serialized size of the packet.
static TypeId GetTypeId()
Get the type ID.
UDP LOWPAN_NHC Extension Header Encoding - see RFC 6282.
void Serialize(Buffer::Iterator start) const override
Serialize the packet.
TypeId GetInstanceTypeId() const override
Return the instance type identifier.
uint8_t m_baseFormat
Dispatch + encoding fields.
Ports_e GetPorts() const
Get the compressed Src and Dst Ports.
uint16_t GetChecksum() const
Get the Checksum field value.
uint16_t GetDstPort() const
Get the Destination Port.
void SetPorts(Ports_e port)
Set the compressed Src and Dst Ports.
bool GetC() const
Get the C (Checksum).
static TypeId GetTypeId()
Get the type ID.
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the packet.
void Print(std::ostream &os) const override
void SetChecksum(uint16_t checksum)
Set the Checksum field values.
void SetDstPort(uint16_t port)
Set the Destination Port.
uint32_t GetSerializedSize() const override
Get the serialized size of the packet.
void SetSrcPort(uint16_t port)
Set the Source Port.
void SetC(bool cField)
Set the C (Checksum).
uint16_t m_dstPort
Destination port.
SixLowPanDispatch::NhcDispatch_e GetNhcDispatchType() const
Get the NhcDispatch type.
uint16_t GetSrcPort() const
Get the Source Port.
a unique identifier for an interface.
Definition type-id.h:50
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1003
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition assert.h:76
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Definition abort.h:38
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition angles.cc:148