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_NHC) && (dispatch <= LOWPAN_NHC_N))
72 {
73 return LOWPAN_NHC;
74 }
75 else if ((dispatch >= LOWPAN_UDPNHC) && (dispatch <= LOWPAN_UDPNHC_N))
76 {
77 return LOWPAN_UDPNHC;
78 }
80}
81
82/*
83 * SixLowPanHc1
84 */
86
88 : m_hopLimit(0)
89{
90}
91
94{
95 static TypeId tid = TypeId("ns3::SixLowPanHc1")
97 .SetGroupName("SixLowPan")
98 .AddConstructor<SixLowPanHc1>();
99 return tid;
100}
101
102TypeId
104{
105 return GetTypeId();
106}
107
108void
109SixLowPanHc1::Print(std::ostream& os) const
110{
111 uint8_t encoding;
112 encoding = m_srcCompression;
113 encoding <<= 2;
114 encoding |= m_dstCompression;
115 encoding <<= 1;
116 encoding |= m_tcflCompression;
117 encoding <<= 2;
118 encoding |= m_nextHeaderCompression;
119 encoding <<= 1;
120 encoding |= m_hc2HeaderPresent;
121
122 os << "encoding " << +encoding << ", hopLimit " << +m_hopLimit;
123}
124
127{
128 uint32_t serializedSize = 3;
129
130 switch (m_srcCompression)
131 {
132 case HC1_PIII:
133 serializedSize += 16;
134 break;
135 case HC1_PIIC:
136 case HC1_PCII:
137 serializedSize += 8;
138 break;
139 case HC1_PCIC:
140 break;
141 }
142 switch (m_dstCompression)
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
156 {
157 serializedSize += 4;
158 }
159
161 {
162 serializedSize++;
163 }
164
165 return serializedSize;
166}
167
168void
170{
171 Buffer::Iterator i = start;
172 uint8_t encoding;
173 encoding = m_srcCompression;
174 encoding <<= 2;
175 encoding |= m_dstCompression;
176 encoding <<= 1;
177 encoding |= m_tcflCompression;
178 encoding <<= 2;
179 encoding |= m_nextHeaderCompression;
180 encoding <<= 1;
181 encoding |= m_hc2HeaderPresent;
182
184 i.WriteU8(encoding);
186 switch (m_srcCompression)
187 {
188 case HC1_PIII:
189 for (int j = 0; j < 8; j++)
190 {
191 i.WriteU8(m_srcPrefix[j]);
192 }
193 for (int j = 0; j < 8; j++)
194 {
196 }
197 break;
198 case HC1_PIIC:
199 for (int j = 0; j < 8; j++)
200 {
201 i.WriteU8(m_srcPrefix[j]);
202 }
203 break;
204 case HC1_PCII:
205 for (int j = 0; j < 8; j++)
206 {
208 }
209 break;
210 case HC1_PCIC:
211 break;
212 }
213 switch (m_dstCompression)
214 {
215 case HC1_PIII:
216 for (int j = 0; j < 8; j++)
217 {
218 i.WriteU8(m_dstPrefix[j]);
219 }
220 for (int j = 0; j < 8; j++)
221 {
223 }
224 break;
225 case HC1_PIIC:
226 for (int j = 0; j < 8; j++)
227 {
228 i.WriteU8(m_dstPrefix[j]);
229 }
230 break;
231 case HC1_PCII:
232 for (int j = 0; j < 8; j++)
233 {
235 }
236 break;
237 case HC1_PCIC:
238 break;
239 }
240
242 {
244 uint8_t temp[3];
245 temp[0] = uint8_t(m_flowLabel & 0xff);
246 temp[1] = uint8_t((m_flowLabel >> 8) & 0xff);
247 temp[2] = uint8_t((m_flowLabel >> 16) & 0xff);
248 i.Write(temp, 3);
249 }
250
252 {
254 }
255
256 // TODO: HC2 is not yet supported. Should be.
257 NS_ASSERT_MSG(m_hc2HeaderPresent != true, "Can not compress HC2, exiting. Very sorry.");
258}
259
262{
263 Buffer::Iterator i = start;
264
265 uint8_t dispatch = i.ReadU8();
266 if (dispatch != SixLowPanDispatch::LOWPAN_HC1)
267 {
268 return 0;
269 }
270
271 uint8_t encoding = i.ReadU8();
272 m_hopLimit = i.ReadU8();
273
274 m_srcCompression = LowPanHc1Addr_e(encoding >> 6);
275 m_dstCompression = LowPanHc1Addr_e((encoding >> 4) & 0x3);
276 m_tcflCompression = (encoding >> 3) & 0x1;
277 m_nextHeaderCompression = LowPanHc1NextHeader_e((encoding >> 1) & 0x3);
278 m_hc2HeaderPresent = encoding & 0x1;
279
280 switch (m_srcCompression)
281 {
282 case HC1_PIII:
283 for (int j = 0; j < 8; j++)
284 {
285 m_srcPrefix[j] = i.ReadU8();
286 }
287 for (int j = 0; j < 8; j++)
288 {
289 m_srcInterface[j] = i.ReadU8();
290 }
291 break;
292 case HC1_PIIC:
293 for (int j = 0; j < 8; j++)
294 {
295 m_srcPrefix[j] = i.ReadU8();
296 }
297 break;
298 case HC1_PCII:
299 for (int j = 0; j < 8; j++)
300 {
301 m_srcInterface[j] = i.ReadU8();
302 }
303 break;
304 case HC1_PCIC:
305 break;
306 }
307 switch (m_dstCompression)
308 {
309 case HC1_PIII:
310 for (int j = 0; j < 8; j++)
311 {
312 m_dstPrefix[j] = i.ReadU8();
313 }
314 for (int j = 0; j < 8; j++)
315 {
316 m_dstInterface[j] = i.ReadU8();
317 }
318 break;
319 case HC1_PIIC:
320 for (int j = 0; j < 8; j++)
321 {
322 m_dstPrefix[j] = i.ReadU8();
323 }
324 break;
325 case HC1_PCII:
326 for (int j = 0; j < 8; j++)
327 {
328 m_dstInterface[j] = i.ReadU8();
329 }
330 break;
331 case HC1_PCIC:
332 break;
333 }
334
336 {
338 uint8_t temp[3];
339 i.Read(temp, 3);
340 m_flowLabel = temp[2];
341 m_flowLabel = (m_flowLabel << 8) | temp[1];
342 m_flowLabel = (m_flowLabel << 8) | temp[0];
343 }
344
346 {
347 case HC1_NC:
348 m_nextHeader = i.ReadU8();
349 break;
350 case HC1_TCP:
352 break;
353 case HC1_UDP:
355 break;
356 case HC1_ICMP:
358 break;
359 }
360
361 NS_ASSERT_MSG(m_hc2HeaderPresent != true, "Can not compress HC2, exiting. Very sorry.");
362
363 return GetSerializedSize();
364}
365
366void
368{
369 m_hopLimit = limit;
370}
371
372uint8_t
374{
375 return m_hopLimit;
376}
377
383
384const uint8_t*
386{
387 return m_dstInterface;
388}
389
390const uint8_t*
392{
393 return m_dstPrefix;
394}
395
398{
399 return m_flowLabel;
400}
401
402uint8_t
404{
405 return m_nextHeader;
406}
407
413
414const uint8_t*
416{
417 return m_srcInterface;
418}
419
420const uint8_t*
422{
423 return m_srcPrefix;
424}
425
426uint8_t
428{
429 return m_trafficClass;
430}
431
432bool
437
438bool
443
444void
446{
447 m_dstCompression = dstCompression;
448}
449
450void
451SixLowPanHc1::SetDstInterface(const uint8_t* dstInterface)
452{
453 for (int i = 0; i < 8; i++)
454 {
455 m_dstInterface[i] = dstInterface[i];
456 }
457}
458
459void
460SixLowPanHc1::SetDstPrefix(const uint8_t* dstPrefix)
461{
462 for (int i = 0; i < 8; i++)
463 {
464 m_dstPrefix[i] = dstPrefix[i];
465 }
466}
467
468void
470{
471 m_flowLabel = flowLabel;
472}
473
474void
476{
477 m_nextHeader = nextHeader;
478
479 switch (m_nextHeader)
480 {
483 break;
486 break;
489 break;
490 default:
492 break;
493 }
494}
495
496void
498{
499 m_srcCompression = srcCompression;
500}
501
502void
503SixLowPanHc1::SetSrcInterface(const uint8_t* srcInterface)
504{
505 for (int i = 0; i < 8; i++)
506 {
507 m_srcInterface[i] = srcInterface[i];
508 }
509}
510
511void
512SixLowPanHc1::SetSrcPrefix(const uint8_t* srcPrefix)
513{
514 for (int i = 0; i < 8; i++)
515 {
516 m_srcPrefix[i] = srcPrefix[i];
517 }
518}
519
520void
522{
523 m_tcflCompression = tcflCompression;
524}
525
526void
527SixLowPanHc1::SetTrafficClass(uint8_t trafficClass)
528{
529 m_trafficClass = trafficClass;
530}
531
532void
534{
535 m_hc2HeaderPresent = hc2HeaderPresent;
536}
537
538std::ostream&
539operator<<(std::ostream& os, const SixLowPanHc1& h)
540{
541 h.Print(os);
542 return os;
543}
544
545/*
546 * SixLowPanFrag1
547 */
548NS_OBJECT_ENSURE_REGISTERED(SixLowPanFrag1);
549
551 : m_datagramSize(0),
552 m_datagramTag(0)
553{
554}
555
556TypeId
558{
559 static TypeId tid = TypeId("ns3::SixLowPanFrag1")
560 .SetParent<Header>()
561 .SetGroupName("SixLowPan")
562 .AddConstructor<SixLowPanFrag1>();
563 return tid;
564}
565
566TypeId
568{
569 return GetTypeId();
570}
571
572void
573SixLowPanFrag1::Print(std::ostream& os) const
574{
575 os << "datagram size " << m_datagramSize << " tag " << m_datagramTag;
576}
577
580{
581 return 4;
582}
583
584void
586{
587 Buffer::Iterator i = start;
588
589 uint16_t temp = m_datagramSize | (uint16_t(SixLowPanDispatch::LOWPAN_FRAG1) << 8);
590
591 i.WriteU8(uint8_t(temp >> 8));
592 i.WriteU8(uint8_t(temp & 0xff));
593
595}
596
599{
600 Buffer::Iterator i = start;
601
602 uint8_t temp = i.ReadU8();
603 m_datagramSize = (uint16_t(temp) << 8) | i.ReadU8();
604 m_datagramSize &= 0x7FF;
605
607 return GetSerializedSize();
608}
609
610void
612{
613 m_datagramSize = datagramSize & 0x7FF;
614}
615
616uint16_t
618{
619 return m_datagramSize & 0x7FF;
620}
621
622void
624{
625 m_datagramTag = datagramTag;
626}
627
628uint16_t
630{
631 return m_datagramTag;
632}
633
634std::ostream&
635operator<<(std::ostream& os, const SixLowPanFrag1& h)
636{
637 h.Print(os);
638 return os;
639}
640
641/*
642 * SixLowPanFragN
643 */
644
645NS_OBJECT_ENSURE_REGISTERED(SixLowPanFragN);
646
648 : m_datagramSize(0),
649 m_datagramTag(0),
650 m_datagramOffset(0)
651{
652}
653
654/*
655 * SixLowPanFragmentOffset
656 */
657TypeId
659{
660 static TypeId tid = TypeId("ns3::SixLowPanFragN")
661 .SetParent<Header>()
662 .SetGroupName("SixLowPan")
663 .AddConstructor<SixLowPanFragN>();
664 return tid;
665}
666
667TypeId
669{
670 return GetTypeId();
671}
672
673void
674SixLowPanFragN::Print(std::ostream& os) const
675{
676 os << "datagram size " << m_datagramSize << " tag " << m_datagramTag << " offset "
678}
679
682{
683 return 5;
684}
685
686void
688{
689 Buffer::Iterator i = start;
690
691 uint16_t temp = m_datagramSize | (uint16_t(SixLowPanDispatch::LOWPAN_FRAGN) << 8);
692
693 i.WriteU8(uint8_t(temp >> 8));
694 i.WriteU8(uint8_t(temp & 0xff));
695
698}
699
702{
703 Buffer::Iterator i = start;
704
705 uint8_t temp = i.ReadU8();
706 m_datagramSize = (uint16_t(temp) << 8) | i.ReadU8();
707 m_datagramSize &= 0x7FF;
708
711
712 return GetSerializedSize();
713}
714
715void
717{
718 m_datagramSize = datagramSize & 0x7FF;
719}
720
721uint16_t
723{
724 return m_datagramSize & 0x7FF;
725}
726
727void
729{
730 m_datagramTag = datagramTag;
731}
732
733uint16_t
735{
736 return m_datagramTag;
737}
738
739void
741{
742 m_datagramOffset = datagramOffset;
743}
744
745uint8_t
750
751std::ostream&
752operator<<(std::ostream& os, const SixLowPanFragN& h)
753{
754 h.Print(os);
755 return os;
756}
757
758/*
759 * SixLowPanIpv6
760 */
761
762NS_OBJECT_ENSURE_REGISTERED(SixLowPanIpv6);
763
767
768TypeId
770{
771 static TypeId tid = TypeId("ns3::SixLowPanIpv6")
772 .SetParent<Header>()
773 .SetGroupName("SixLowPan")
774 .AddConstructor<SixLowPanIpv6>();
775 return tid;
776}
777
778TypeId
780{
781 return GetTypeId();
782}
783
784void
785SixLowPanIpv6::Print(std::ostream& os) const
786{
787 os << "Uncompressed IPv6";
788}
789
792{
793 return 1;
794}
795
796void
803
806{
807 Buffer::Iterator i = start;
808 i.ReadU8();
809
810 return GetSerializedSize();
811}
812
813std::ostream&
814operator<<(std::ostream& os, const SixLowPanIpv6& h)
815{
816 h.Print(os);
817 return os;
818}
819
820/*
821 * SixLowPanIphcHeader
822 */
823NS_OBJECT_ENSURE_REGISTERED(SixLowPanIphc);
824
826{
827 // 011x xxxx xxxx xxxx
828 m_baseFormat = 0x6000;
830}
831
833{
834 // 011x xxxx xxxx xxxx
835 m_baseFormat = dispatch;
836 m_baseFormat <<= 8;
838}
839
840TypeId
842{
843 static TypeId tid = TypeId("ns3::SixLowPanIphc")
844 .SetParent<Header>()
845 .SetGroupName("SixLowPan")
846 .AddConstructor<SixLowPanIphc>();
847 return tid;
848}
849
850TypeId
852{
853 return GetTypeId();
854}
855
856void
857SixLowPanIphc::Print(std::ostream& os) const
858{
859 switch (GetTf())
860 {
861 case TF_FULL:
862 os << "TF_FULL(" << +m_ecn << ", " << +m_dscp << ", " << m_flowLabel << ")";
863 break;
864 case TF_DSCP_ELIDED:
865 os << "TF_DSCP_ELIDED(" << +m_ecn << ", " << m_flowLabel << ")";
866 break;
867 case TF_FL_ELIDED:
868 os << "TF_FL_ELIDED(" << +m_ecn << ", " << +m_dscp << ")";
869 break;
870 default:
871 os << "TF_ELIDED";
872 break;
873 }
874
875 GetNh() ? os << " NH(1)" : os << " NH(0)";
876
877 switch (GetHlim())
878 {
879 case HLIM_INLINE:
880 os << " HLIM_INLINE(" << +m_hopLimit << ")";
881 break;
882 case HLIM_COMPR_1:
883 os << " HLIM_COMPR_1(1)";
884 break;
885 case HLIM_COMPR_64:
886 os << " HLIM_COMPR_64(64)";
887 break;
888 default:
889 os << " HLIM_COMPR_255(255)";
890 break;
891 }
892
893 GetCid() ? os << " CID(" << +m_srcdstContextId << ")" : os << " CID(0)";
894
895 GetSac() ? os << " SAC(1)" : os << " SAC(0)";
896 os << " SAM (" << GetSam() << ")";
897
898 GetM() ? os << " M(1)" : os << " M(0)";
899 GetDac() ? os << " DAC(1)" : os << " DAC(0)";
900 os << " DAM (" << GetDam() << ")";
901}
902
905{
906 uint32_t serializedSize = 2;
907
908 if (GetCid())
909 {
910 serializedSize++;
911 }
912 switch (GetTf())
913 {
914 case TF_FULL:
915 serializedSize += 4;
916 break;
917 case TF_DSCP_ELIDED:
918 serializedSize += 3;
919 break;
920 case TF_FL_ELIDED:
921 serializedSize++;
922 break;
923 default:
924 break;
925 }
926 if (!GetNh())
927 {
928 serializedSize++;
929 }
930 if (GetHlim() == HLIM_INLINE)
931 {
932 serializedSize++;
933 }
934 switch (GetSam())
935 {
936 case HC_INLINE:
937 if (!GetSac())
938 {
939 serializedSize += 16;
940 }
941 break;
942 case HC_COMPR_64:
943 serializedSize += 8;
944 break;
945 case HC_COMPR_16:
946 serializedSize += 2;
947 break;
948 case HC_COMPR_0:
949 default:
950 break;
951 }
952 if (!GetM())
953 {
954 switch (GetDam())
955 {
956 case HC_INLINE:
957 if (!GetDac())
958 {
959 serializedSize += 16;
960 }
961 break;
962 case HC_COMPR_64:
963 serializedSize += 8;
964 break;
965 case HC_COMPR_16:
966 serializedSize += 2;
967 break;
968 case HC_COMPR_0:
969 default:
970 break;
971 }
972 }
973 else
974 {
975 switch (GetDam())
976 {
977 case HC_INLINE:
978 if (!GetDac())
979 {
980 serializedSize += 16;
981 }
982 else
983 {
984 serializedSize += 6;
985 }
986 break;
987 case HC_COMPR_64:
988 if (!GetDac())
989 {
990 serializedSize += 6;
991 }
992 break;
993 case HC_COMPR_16:
994 if (!GetDac())
995 {
996 serializedSize += 4;
997 }
998 break;
999 case HC_COMPR_0:
1000 default:
1001 if (!GetDac())
1002 {
1003 serializedSize++;
1004 }
1005 break;
1006 }
1007 }
1008
1009 return serializedSize;
1010}
1011
1012void
1014{
1015 Buffer::Iterator i = start;
1016
1018
1019 if (GetCid())
1020 {
1022 }
1023 // Traffic Class and Flow Label
1024 switch (GetTf())
1025 {
1026 uint8_t temp;
1027 case TF_FULL:
1028 temp = (m_ecn << 6) | m_dscp;
1029 i.WriteU8(temp);
1030 temp = m_flowLabel >> 16;
1031 i.WriteU8(temp);
1032 temp = (m_flowLabel >> 8) & 0xff;
1033 i.WriteU8(temp);
1034 temp = m_flowLabel & 0xff;
1035 i.WriteU8(temp);
1036 break;
1037 case TF_DSCP_ELIDED:
1038 temp = (m_ecn << 6) | (m_flowLabel >> 16);
1039 i.WriteU8(temp);
1040 temp = (m_flowLabel >> 8) & 0xff;
1041 i.WriteU8(temp);
1042 temp = m_flowLabel & 0xff;
1043 i.WriteU8(temp);
1044 break;
1045 case TF_FL_ELIDED:
1046 temp = (m_ecn << 6) | m_dscp;
1047 i.WriteU8(temp);
1048 break;
1049 default:
1050 break;
1051 }
1052 // Next Header
1053 if (!GetNh())
1054 {
1056 }
1057 // Hop Limit
1058 if (GetHlim() == HLIM_INLINE)
1059 {
1061 }
1062 // Source Address
1063 switch (GetSam())
1064 {
1065 case HC_INLINE:
1066 if (!GetSac())
1067 {
1068 i.Write(m_srcInlinePart, 16);
1069 }
1070 break;
1071 case HC_COMPR_64:
1072 i.Write(m_srcInlinePart, 8);
1073 break;
1074 case HC_COMPR_16:
1075 i.Write(m_srcInlinePart, 2);
1076 break;
1077 case HC_COMPR_0:
1078 default:
1079 break;
1080 }
1081 // Destination Address
1082 if (!GetM())
1083 {
1084 // unicast
1085 switch (GetDam())
1086 {
1087 case HC_INLINE:
1088 i.Write(m_dstInlinePart, 16);
1089 break;
1090 case HC_COMPR_64:
1091 i.Write(m_dstInlinePart, 8);
1092 break;
1093 case HC_COMPR_16:
1094 i.Write(m_dstInlinePart, 2);
1095 break;
1096 case HC_COMPR_0:
1097 default:
1098 break;
1099 }
1100 }
1101 else
1102 {
1103 // multicast
1104 switch (GetDam())
1105 {
1106 case HC_INLINE:
1107 i.Write(m_dstInlinePart, 16);
1108 break;
1109 case HC_COMPR_64:
1110 i.Write(m_dstInlinePart, 6);
1111 break;
1112 case HC_COMPR_16:
1113 i.Write(m_dstInlinePart, 4);
1114 break;
1115 case HC_COMPR_0:
1116 i.Write(m_dstInlinePart, 1);
1117 break;
1118 default:
1119 break;
1120 }
1121 }
1122}
1123
1126{
1127 Buffer::Iterator i = start;
1128
1130
1131 if (GetCid())
1132 {
1134 }
1135 else
1136 {
1138 }
1139 // Traffic Class and Flow Label
1140 switch (GetTf())
1141 {
1142 uint8_t temp;
1143 case TF_FULL:
1144 temp = i.ReadU8();
1145 m_ecn = temp >> 6;
1146 m_dscp = temp & 0x3F;
1147 temp = i.ReadU8();
1148 m_flowLabel = temp;
1149 temp = i.ReadU8();
1150 m_flowLabel = (m_flowLabel << 8) | temp;
1151 temp = i.ReadU8();
1152 m_flowLabel = (m_flowLabel << 8) | temp;
1153 break;
1154 case TF_DSCP_ELIDED:
1155 temp = i.ReadU8();
1156 m_ecn = temp >> 6;
1157 m_flowLabel = temp & 0x3F;
1158 temp = i.ReadU8();
1159 m_flowLabel = (m_flowLabel << 8) | temp;
1160 temp = i.ReadU8();
1161 m_flowLabel = (m_flowLabel << 8) | temp;
1162 break;
1163 case TF_FL_ELIDED:
1164 temp = i.ReadU8();
1165 m_ecn = temp >> 6;
1166 m_dscp = temp & 0x3F;
1167 break;
1168 default:
1169 break;
1170 }
1171 // Next Header
1172 if (!GetNh())
1173 {
1174 m_nextHeader = i.ReadU8();
1175 }
1176 // Hop Limit
1177 switch (GetHlim())
1178 {
1179 case HLIM_INLINE:
1180 m_hopLimit = i.ReadU8();
1181 break;
1182 case HLIM_COMPR_1:
1183 m_hopLimit = 1;
1184 break;
1185 case HLIM_COMPR_64:
1186 m_hopLimit = 64;
1187 break;
1188 case HLIM_COMPR_255:
1189 default:
1190 m_hopLimit = 255;
1191 break;
1192 }
1193 // Source Address
1194 memset(m_srcInlinePart, 0x00, sizeof(m_srcInlinePart));
1195 switch (GetSam())
1196 {
1197 case HC_INLINE:
1198 if (!GetSac())
1199 {
1200 i.Read(m_srcInlinePart, 16);
1201 }
1202 break;
1203 case HC_COMPR_64:
1204 i.Read(m_srcInlinePart, 8);
1205 break;
1206 case HC_COMPR_16:
1207 i.Read(m_srcInlinePart, 2);
1208 break;
1209 case HC_COMPR_0:
1210 default:
1211 break;
1212 }
1213
1214 // Destination Address
1215 memset(m_dstInlinePart, 0x00, sizeof(m_dstInlinePart));
1216 if (!GetM())
1217 {
1218 // unicast
1219 switch (GetDam())
1220 {
1221 case HC_INLINE:
1222 i.Read(m_dstInlinePart, 16);
1223 break;
1224 case HC_COMPR_64:
1225 i.Read(m_dstInlinePart, 8);
1226 break;
1227 case HC_COMPR_16:
1228 i.Read(m_dstInlinePart, 2);
1229 break;
1230 case HC_COMPR_0:
1231 default:
1232 break;
1233 }
1234 }
1235 else
1236 {
1237 // multicast
1238 switch (GetDam())
1239 {
1240 case HC_INLINE:
1241 i.Read(m_dstInlinePart, 16);
1242 break;
1243 case HC_COMPR_64:
1244 i.Read(m_dstInlinePart, 6);
1245 break;
1246 case HC_COMPR_16:
1247 i.Read(m_dstInlinePart, 4);
1248 break;
1249 case HC_COMPR_0:
1250 i.Read(m_dstInlinePart, 1);
1251 break;
1252 default:
1253 break;
1254 }
1255 }
1256
1257 return GetSerializedSize();
1258}
1259
1260void
1262{
1263 uint16_t field = tfField;
1264 m_baseFormat |= (field << 11);
1265}
1266
1269{
1270 return TrafficClassFlowLabel_e((m_baseFormat >> 11) & 0x3);
1271}
1272
1273void
1275{
1276 uint16_t field = nhField;
1277 m_baseFormat |= (field << 10);
1278}
1279
1280bool
1282{
1283 return ((m_baseFormat >> 10) & 0x1);
1284}
1285
1286void
1288{
1289 uint16_t field = hlimField;
1290 m_baseFormat |= (field << 8);
1291}
1292
1295{
1296 return Hlim_e((m_baseFormat >> 8) & 0x3);
1297}
1298
1299void
1301{
1302 uint16_t field = cidField;
1303 m_baseFormat |= (field << 7);
1304}
1305
1306bool
1308{
1309 return ((m_baseFormat >> 7) & 0x1);
1310}
1311
1312void
1314{
1315 uint16_t field = sacField;
1316 m_baseFormat |= (field << 6);
1317}
1318
1319bool
1321{
1322 return ((m_baseFormat >> 6) & 0x1);
1323}
1324
1325void
1327{
1328 uint16_t field = samField;
1329 m_baseFormat |= (field << 4);
1330}
1331
1334{
1335 return HeaderCompression_e((m_baseFormat >> 4) & 0x3);
1336}
1337
1338const uint8_t*
1340{
1341 return m_srcInlinePart;
1342}
1343
1344void
1345SixLowPanIphc::SetSrcInlinePart(uint8_t srcInlinePart[16], uint8_t size)
1346{
1347 NS_ASSERT_MSG(size <= 16, "Src inline part too large");
1348
1349 memcpy(m_srcInlinePart, srcInlinePart, size);
1350}
1351
1352void
1354{
1355 uint16_t field = mField;
1356 m_baseFormat |= (field << 3);
1357}
1358
1359bool
1361{
1362 return ((m_baseFormat >> 3) & 0x1);
1363}
1364
1365void
1367{
1368 uint16_t field = dacField;
1369 m_baseFormat |= (field << 2);
1370}
1371
1372bool
1374{
1375 return ((m_baseFormat >> 2) & 0x1);
1376}
1377
1378void
1380{
1381 uint16_t field = damField;
1382 m_baseFormat |= field;
1383}
1384
1387{
1388 return HeaderCompression_e(m_baseFormat & 0x3);
1389}
1390
1391const uint8_t*
1393{
1394 return m_dstInlinePart;
1395}
1396
1397void
1398SixLowPanIphc::SetDstInlinePart(uint8_t dstInlinePart[16], uint8_t size)
1399{
1400 NS_ASSERT_MSG(size <= 16, "Dst inline part too large");
1401
1402 memcpy(m_dstInlinePart, dstInlinePart, size);
1403}
1404
1405void
1407{
1408 NS_ASSERT_MSG(srcContextId < 16, "Src Context ID too large");
1409 m_srcdstContextId |= srcContextId << 4;
1410}
1411
1412uint8_t
1414{
1415 return (m_srcdstContextId >> 4);
1416}
1417
1418void
1420{
1421 NS_ASSERT_MSG(dstContextId < 16, "Dst Context ID too large");
1422 m_srcdstContextId |= (dstContextId & 0xF);
1423}
1424
1425uint8_t
1427{
1428 return (m_srcdstContextId & 0xF);
1429}
1430
1431void
1433{
1434 NS_ASSERT_MSG(ecn < 4, "ECN too large");
1435 m_ecn = ecn;
1436}
1437
1438uint8_t
1440{
1441 return m_ecn;
1442}
1443
1444void
1446{
1447 NS_ASSERT_MSG(dscp < 64, "DSCP too large");
1448 m_dscp = dscp;
1449}
1450
1451uint8_t
1453{
1454 return m_dscp;
1455}
1456
1457void
1459{
1460 NS_ASSERT_MSG(flowLabel < 0x100000, "Flow Label too large");
1461 m_flowLabel = flowLabel;
1462}
1463
1466{
1467 return m_flowLabel;
1468}
1469
1470void
1472{
1473 m_nextHeader = nextHeader;
1474}
1475
1476uint8_t
1478{
1479 return m_nextHeader;
1480}
1481
1482void
1484{
1485 m_hopLimit = hopLimit;
1486}
1487
1488uint8_t
1490{
1491 return m_hopLimit;
1492}
1493
1494std::ostream&
1495operator<<(std::ostream& os, const SixLowPanIphc& h)
1496{
1497 h.Print(os);
1498 return os;
1499}
1500
1501/*
1502 * SixLowPanNhcExtensionHeader
1503 */
1504NS_OBJECT_ENSURE_REGISTERED(SixLowPanNhcExtension);
1505
1507{
1508 // 1110 xxxx
1509 m_nhcExtensionHeader = 0xE0;
1510 m_nhcNextHeader = 0;
1511 m_nhcBlobLength = 0;
1512}
1513
1514TypeId
1516{
1517 static TypeId tid = TypeId("ns3::SixLowPanNhcExtension")
1518 .SetParent<Header>()
1519 .SetGroupName("SixLowPan")
1520 .AddConstructor<SixLowPanNhcExtension>();
1521 return tid;
1522}
1523
1524TypeId
1526{
1527 return GetTypeId();
1528}
1529
1530void
1531SixLowPanNhcExtension::Print(std::ostream& os) const
1532{
1533 os << "Compression kind: " << +m_nhcExtensionHeader << " Size: " << GetSerializedSize();
1534}
1535
1538{
1539 uint32_t serializedSize = 2;
1540 if (!GetNh())
1541 {
1542 serializedSize++;
1543 }
1544 return serializedSize + m_nhcBlobLength;
1545}
1546
1547void
1549{
1550 Buffer::Iterator i = start;
1552 if (!GetNh())
1553 {
1555 }
1558}
1559
1562{
1563 Buffer::Iterator i = start;
1565 if (!GetNh())
1566 {
1567 m_nhcNextHeader = i.ReadU8();
1568 }
1569 m_nhcBlobLength = i.ReadU8();
1571
1572 return GetSerializedSize();
1573}
1574
1580
1581void
1583{
1584 uint8_t field = extensionHeaderType;
1585 m_nhcExtensionHeader |= (field << 1);
1586}
1587
1590{
1591 return Eid_e((m_nhcExtensionHeader >> 1) & 0x7);
1592}
1593
1594void
1596{
1597 m_nhcNextHeader = nextHeader;
1598}
1599
1600uint8_t
1605
1606void
1608{
1609 uint8_t field = nhField;
1610 m_nhcExtensionHeader |= field;
1611}
1612
1613bool
1615{
1616 return m_nhcExtensionHeader & 0x01;
1617}
1618
1619void
1621{
1622 NS_ASSERT_MSG(size < 255, "Buffer too long");
1623
1624 m_nhcBlobLength = size;
1625 std::memcpy(m_nhcBlob, blob, size);
1626}
1627
1630{
1631 NS_ASSERT_MSG(size > m_nhcBlobLength, "Buffer too short");
1632
1633 std::memcpy(blob, m_nhcBlob, m_nhcBlobLength);
1634 return m_nhcBlobLength;
1635}
1636
1637std::ostream&
1638operator<<(std::ostream& os, const SixLowPanNhcExtension& h)
1639{
1640 h.Print(os);
1641 return os;
1642}
1643
1644/*
1645 * SixLowPanUdpNhcExtension
1646 */
1647NS_OBJECT_ENSURE_REGISTERED(SixLowPanUdpNhcExtension);
1648
1650{
1651 // 1111 0xxx
1652 m_baseFormat = 0xF0;
1653 m_checksum = 0;
1654 m_srcPort = 0;
1655 m_dstPort = 0;
1656}
1657
1658TypeId
1660{
1661 static TypeId tid = TypeId("ns3::SixLowPanUdpNhcExtension")
1662 .SetParent<Header>()
1663 .SetGroupName("SixLowPan")
1664 .AddConstructor<SixLowPanUdpNhcExtension>();
1665 return tid;
1666}
1667
1668TypeId
1673
1674void
1675SixLowPanUdpNhcExtension::Print(std::ostream& os) const
1676{
1677 os << "Compression kind: " << +m_baseFormat;
1678}
1679
1682{
1683 uint32_t serializedSize = 1;
1684 if (!GetC())
1685 {
1686 serializedSize += 2;
1687 }
1688 switch (GetPorts())
1689 {
1690 case PORTS_INLINE:
1691 serializedSize += 4;
1692 break;
1695 serializedSize += 3;
1696 break;
1698 serializedSize += 1;
1699 break;
1700 default:
1701 break;
1702 }
1703 return serializedSize;
1704}
1705
1706void
1708{
1709 Buffer::Iterator i = start;
1711 uint8_t temp;
1712
1713 // Ports
1714 switch (GetPorts())
1715 {
1716 case PORTS_INLINE:
1719 break;
1722 i.WriteU8(m_dstPort & 0xff);
1723 break;
1725 i.WriteU8(m_srcPort & 0xff);
1727 break;
1729 temp = ((m_srcPort & 0xf) << 4) | (m_dstPort & 0xf);
1730 i.WriteU8(temp);
1731 break;
1732 default:
1733 break;
1734 }
1735
1736 // Checksum
1737 if (!GetC())
1738 {
1740 }
1741}
1742
1745{
1746 Buffer::Iterator i = start;
1747 m_baseFormat = i.ReadU8();
1748 uint8_t temp;
1749
1750 // Ports
1751 switch (GetPorts())
1752 {
1753 case PORTS_INLINE:
1754 m_srcPort = i.ReadNtohU16();
1755 m_dstPort = i.ReadNtohU16();
1756 break;
1758 m_srcPort = i.ReadNtohU16();
1759 m_dstPort = i.ReadU8();
1760 break;
1762 m_srcPort = i.ReadU8();
1763 m_dstPort = i.ReadNtohU16();
1764 break;
1766 temp = i.ReadU8();
1767 m_srcPort = temp >> 4;
1768 m_dstPort = temp & 0xf;
1769 break;
1770 default:
1771 break;
1772 }
1773
1774 // Checksum
1775 if (!GetC())
1776 {
1777 m_checksum = i.ReadU16();
1778 }
1779
1780 return GetSerializedSize();
1781}
1782
1788
1789void
1791{
1792 uint16_t field = ports;
1793 m_baseFormat |= field;
1794}
1795
1798{
1799 return Ports_e(m_baseFormat & 0x3);
1800}
1801
1802void
1804{
1805 m_srcPort = srcport;
1806}
1807
1808uint16_t
1810{
1811 return m_srcPort;
1812}
1813
1814void
1816{
1817 m_dstPort = dstport;
1818}
1819
1820uint16_t
1822{
1823 return m_dstPort;
1824}
1825
1826void
1828{
1829 uint16_t field = cField;
1830 m_baseFormat |= (field << 2);
1831}
1832
1833bool
1835{
1836 return ((m_baseFormat >> 2) & 0x1);
1837}
1838
1839void
1841{
1842 m_checksum = checksum;
1843}
1844
1845uint16_t
1847{
1848 return m_checksum;
1849}
1850
1851std::ostream&
1852operator<<(std::ostream& os, const SixLowPanUdpNhcExtension& h)
1853{
1854 h.Print(os);
1855 return os;
1856}
1857
1858/*
1859 * SixLowPanBc0
1860 */
1861NS_OBJECT_ENSURE_REGISTERED(SixLowPanBc0);
1862
1867
1868TypeId
1870{
1871 static TypeId tid = TypeId("ns3::SixLowPanBc0")
1872 .SetParent<Header>()
1873 .SetGroupName("SixLowPan")
1874 .AddConstructor<SixLowPanBc0>();
1875 return tid;
1876}
1877
1878TypeId
1880{
1881 return GetTypeId();
1882}
1883
1884void
1885SixLowPanBc0::Print(std::ostream& os) const
1886{
1887 os << "Sequence number: " << +m_seqNumber;
1888}
1889
1892{
1893 return 2;
1894}
1895
1896void
1898{
1899 Buffer::Iterator i = start;
1900 i.WriteU8(0x50);
1902}
1903
1906{
1907 Buffer::Iterator i = start;
1908 uint8_t dispatch = i.ReadU8();
1909
1910 if (dispatch != 0x50)
1911 {
1912 return 0;
1913 }
1914
1915 m_seqNumber = i.ReadU8();
1916
1917 return GetSerializedSize();
1918}
1919
1920void
1922{
1923 m_seqNumber = seqNumber;
1924}
1925
1926uint8_t
1928{
1929 return m_seqNumber;
1930}
1931
1932std::ostream&
1933operator<<(std::ostream& os, const SixLowPanBc0& h)
1934{
1935 h.Print(os);
1936 return os;
1937}
1938
1939/*
1940 * SixLowPanMesh
1941 */
1942NS_OBJECT_ENSURE_REGISTERED(SixLowPanMesh);
1943
1945{
1946 m_hopsLeft = 0;
1947 m_src = Address();
1948 m_dst = Address();
1949 m_v = false;
1950 m_f = false;
1951}
1952
1953TypeId
1955{
1956 static TypeId tid = TypeId("ns3::SixLowPanMesh")
1957 .SetParent<Header>()
1958 .SetGroupName("SixLowPan")
1959 .AddConstructor<SixLowPanMesh>();
1960 return tid;
1961}
1962
1963TypeId
1965{
1966 return GetTypeId();
1967}
1968
1969void
1970SixLowPanMesh::Print(std::ostream& os) const
1971{
1972 os << "Hops left: " << +m_hopsLeft << ", src: ";
1974 {
1976 }
1977 else
1978 {
1980 }
1981 os << ", dst: ";
1983 {
1985 }
1986 else
1987 {
1989 }
1990}
1991
1994{
1995 uint32_t serializedSize = 1;
1996
1997 if (m_hopsLeft >= 0xF)
1998 {
1999 serializedSize++;
2000 }
2001
2002 if (m_v)
2003 {
2004 serializedSize += 2;
2005 }
2006 else
2007 {
2008 serializedSize += 8;
2009 }
2010
2011 if (m_f)
2012 {
2013 serializedSize += 2;
2014 }
2015 else
2016 {
2017 serializedSize += 8;
2018 }
2019
2020 return serializedSize;
2021}
2022
2023void
2025{
2026 Buffer::Iterator i = start;
2027
2028 uint8_t dispatch = 0x80;
2029
2030 if (m_v)
2031 {
2032 dispatch |= 0x20;
2033 }
2034 if (m_f)
2035 {
2036 dispatch |= 0x10;
2037 }
2038
2039 if (m_hopsLeft < 0xF)
2040 {
2041 dispatch |= m_hopsLeft;
2042 i.WriteU8(dispatch);
2043 }
2044 else
2045 {
2046 dispatch |= 0xF;
2047 i.WriteU8(dispatch);
2049 }
2050
2051 uint8_t buffer[8];
2052
2053 m_src.CopyTo(buffer);
2054 if (m_v)
2055 {
2056 i.Write(buffer, 2);
2057 }
2058 else
2059 {
2060 i.Write(buffer, 8);
2061 }
2062
2063 m_dst.CopyTo(buffer);
2064 if (m_f)
2065 {
2066 i.Write(buffer, 2);
2067 }
2068 else
2069 {
2070 i.Write(buffer, 8);
2071 }
2072}
2073
2076{
2077 Buffer::Iterator i = start;
2078 uint8_t temp = i.ReadU8();
2079
2080 if ((temp & 0xC0) != 0x80)
2081 {
2082 return 0;
2083 }
2084
2085 m_v = temp & 0x20;
2086 m_f = temp & 0x10;
2087 m_hopsLeft = temp & 0xF;
2088
2089 if (m_hopsLeft == 0xF)
2090 {
2091 m_hopsLeft = i.ReadU8();
2092 }
2093
2094 uint8_t buffer[8];
2095 uint8_t addrSize;
2096
2097 if (m_v)
2098 {
2099 addrSize = 2;
2100 }
2101 else
2102 {
2103 addrSize = 8;
2104 }
2105 i.Read(buffer, addrSize);
2106 m_src.CopyFrom(buffer, addrSize);
2107
2108 if (m_f)
2109 {
2110 addrSize = 2;
2111 }
2112 else
2113 {
2114 addrSize = 8;
2115 }
2116 i.Read(buffer, addrSize);
2117 m_dst.CopyFrom(buffer, addrSize);
2118
2119 return GetSerializedSize();
2120}
2121
2122void
2124{
2125 if (Mac64Address::IsMatchingType(originator))
2126 {
2127 m_v = false;
2128 }
2129 else if (Mac16Address::IsMatchingType(originator))
2130 {
2131 m_v = true;
2132 }
2133 else
2134 {
2135 NS_ABORT_MSG("SixLowPanMesh::SetOriginator - incompatible address");
2136 }
2137
2138 m_src = originator;
2139}
2140
2141Address
2143{
2144 return m_src;
2145}
2146
2147void
2149{
2150 if (Mac64Address::IsMatchingType(finalDst))
2151 {
2152 m_f = false;
2153 }
2154 else if (Mac16Address::IsMatchingType(finalDst))
2155 {
2156 m_f = true;
2157 }
2158 else
2159 {
2160 NS_ABORT_MSG("SixLowPanMesh::SetFinalDst - incompatible address");
2161 }
2162
2163 m_dst = finalDst;
2164}
2165
2166Address
2168{
2169 return m_dst;
2170}
2171
2172void
2174{
2175 m_hopsLeft = hopsLeft;
2176}
2177
2178uint8_t
2180{
2181 return m_hopsLeft;
2182}
2183
2184std::ostream&
2185operator<<(std::ostream& os, const SixLowPanMesh& h)
2186{
2187 h.Print(os);
2188 return os;
2189}
2190
2191} // namespace ns3
a polymophic address class
Definition address.h:90
uint32_t CopyFrom(const uint8_t *buffer, uint8_t len)
Definition address.cc:95
uint32_t CopyTo(uint8_t buffer[MAX_SIZE]) const
Copy the address bytes into a buffer.
Definition address.cc:75
iterator in a Buffer instance
Definition buffer.h:89
void WriteU8(uint8_t data)
Definition buffer.h:870
void Write(const uint8_t *buffer, uint32_t size)
Definition buffer.cc:937
void WriteU16(uint16_t data)
Definition buffer.cc:848
void Read(uint8_t *buffer, uint32_t size)
Definition buffer.cc:1114
void WriteHtonU16(uint16_t data)
Definition buffer.h:904
uint16_t ReadNtohU16()
Definition buffer.h:943
uint16_t ReadU16()
Definition buffer.h:1024
Protocol header serialization and deserialization.
Definition header.h:33
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.
virtual 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.
virtual 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:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
#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:75
#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