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 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Tommaso Pecorella <tommaso.pecorella@unifi.it>
18 * Michele Muccio <michelemuccio@virgilio.it>
19 */
20
21#include "sixlowpan-header.h"
22
23#include "ns3/abort.h"
24#include "ns3/assert.h"
25#include "ns3/ipv6-header.h"
26#include "ns3/log.h"
27#include "ns3/mac16-address.h"
28#include "ns3/mac64-address.h"
29
30namespace ns3
31{
32
33/*
34 * SixLowPanDispatch
35 */
36
38{
39}
40
43{
44 if (dispatch <= LOWPAN_NALP_N)
45 {
46 return LOWPAN_NALP;
47 }
48 else if (dispatch == LOWPAN_IPv6)
49 {
50 return LOWPAN_IPv6;
51 }
52 else if (dispatch == LOWPAN_HC1)
53 {
54 return LOWPAN_HC1;
55 }
56 else if (dispatch == LOWPAN_BC0)
57 {
58 return LOWPAN_BC0;
59 }
60 else if ((dispatch >= LOWPAN_IPHC) && (dispatch <= LOWPAN_IPHC_N))
61 {
62 return LOWPAN_IPHC;
63 }
64 else if ((dispatch >= LOWPAN_MESH) && (dispatch <= LOWPAN_MESH_N))
65 {
66 return LOWPAN_MESH;
67 }
68 else if ((dispatch >= LOWPAN_FRAG1) && (dispatch <= LOWPAN_FRAG1_N))
69 {
70 return LOWPAN_FRAG1;
71 }
72 else if ((dispatch >= LOWPAN_FRAGN) && (dispatch <= LOWPAN_FRAGN_N))
73 {
74 return LOWPAN_FRAGN;
75 }
76 return LOWPAN_UNSUPPORTED;
77}
78
81{
82 if ((dispatch >= LOWPAN_NHC) && (dispatch <= LOWPAN_NHC_N))
83 {
84 return LOWPAN_NHC;
85 }
86 else if ((dispatch >= LOWPAN_UDPNHC) && (dispatch <= LOWPAN_UDPNHC_N))
87 {
88 return LOWPAN_UDPNHC;
89 }
91}
92
93/*
94 * SixLowPanHc1
95 */
97
99 : m_hopLimit(0)
100{
101}
102
103TypeId
105{
106 static TypeId tid = TypeId("ns3::SixLowPanHc1")
107 .SetParent<Header>()
108 .SetGroupName("SixLowPan")
109 .AddConstructor<SixLowPanHc1>();
110 return tid;
111}
112
113TypeId
115{
116 return GetTypeId();
117}
118
119void
120SixLowPanHc1::Print(std::ostream& os) const
121{
122 uint8_t encoding;
123 encoding = m_srcCompression;
124 encoding <<= 2;
125 encoding |= m_dstCompression;
126 encoding <<= 1;
127 encoding |= m_tcflCompression;
128 encoding <<= 2;
129 encoding |= m_nextHeaderCompression;
130 encoding <<= 1;
131 encoding |= m_hc2HeaderPresent;
132
133 os << "encoding " << +encoding << ", hopLimit " << +m_hopLimit;
134}
135
138{
139 uint32_t serializedSize = 3;
140
141 switch (m_srcCompression)
142 {
143 case HC1_PIII:
144 serializedSize += 16;
145 break;
146 case HC1_PIIC:
147 case HC1_PCII:
148 serializedSize += 8;
149 break;
150 case HC1_PCIC:
151 break;
152 }
153 switch (m_dstCompression)
154 {
155 case HC1_PIII:
156 serializedSize += 16;
157 break;
158 case HC1_PIIC:
159 case HC1_PCII:
160 serializedSize += 8;
161 break;
162 case HC1_PCIC:
163 break;
164 }
165
167 {
168 serializedSize += 4;
169 }
170
172 {
173 serializedSize++;
174 }
175
176 return serializedSize;
177}
178
179void
181{
182 Buffer::Iterator i = start;
183 uint8_t encoding;
184 encoding = m_srcCompression;
185 encoding <<= 2;
186 encoding |= m_dstCompression;
187 encoding <<= 1;
188 encoding |= m_tcflCompression;
189 encoding <<= 2;
190 encoding |= m_nextHeaderCompression;
191 encoding <<= 1;
192 encoding |= m_hc2HeaderPresent;
193
195 i.WriteU8(encoding);
197 switch (m_srcCompression)
198 {
199 case HC1_PIII:
200 for (int j = 0; j < 8; j++)
201 {
202 i.WriteU8(m_srcPrefix[j]);
203 }
204 for (int j = 0; j < 8; j++)
205 {
207 }
208 break;
209 case HC1_PIIC:
210 for (int j = 0; j < 8; j++)
211 {
212 i.WriteU8(m_srcPrefix[j]);
213 }
214 break;
215 case HC1_PCII:
216 for (int j = 0; j < 8; j++)
217 {
219 }
220 break;
221 case HC1_PCIC:
222 break;
223 }
224 switch (m_dstCompression)
225 {
226 case HC1_PIII:
227 for (int j = 0; j < 8; j++)
228 {
229 i.WriteU8(m_dstPrefix[j]);
230 }
231 for (int j = 0; j < 8; j++)
232 {
234 }
235 break;
236 case HC1_PIIC:
237 for (int j = 0; j < 8; j++)
238 {
239 i.WriteU8(m_dstPrefix[j]);
240 }
241 break;
242 case HC1_PCII:
243 for (int j = 0; j < 8; j++)
244 {
246 }
247 break;
248 case HC1_PCIC:
249 break;
250 }
251
253 {
255 uint8_t temp[3];
256 temp[0] = uint8_t(m_flowLabel & 0xff);
257 temp[1] = uint8_t((m_flowLabel >> 8) & 0xff);
258 temp[2] = uint8_t((m_flowLabel >> 16) & 0xff);
259 i.Write(temp, 3);
260 }
261
263 {
265 }
266
267 // TODO: HC2 is not yet supported. Should be.
268 NS_ASSERT_MSG(m_hc2HeaderPresent != true, "Can not compress HC2, exiting. Very sorry.");
269}
270
273{
274 Buffer::Iterator i = start;
275
276 uint8_t dispatch = i.ReadU8();
277 if (dispatch != SixLowPanDispatch::LOWPAN_HC1)
278 {
279 return 0;
280 }
281
282 uint8_t encoding = i.ReadU8();
283 m_hopLimit = i.ReadU8();
284
285 m_srcCompression = LowPanHc1Addr_e(encoding >> 6);
286 m_dstCompression = LowPanHc1Addr_e((encoding >> 4) & 0x3);
287 m_tcflCompression = (encoding >> 3) & 0x1;
288 m_nextHeaderCompression = LowPanHc1NextHeader_e((encoding >> 1) & 0x3);
289 m_hc2HeaderPresent = encoding & 0x1;
290
291 switch (m_srcCompression)
292 {
293 case HC1_PIII:
294 for (int j = 0; j < 8; j++)
295 {
296 m_srcPrefix[j] = i.ReadU8();
297 }
298 for (int j = 0; j < 8; j++)
299 {
300 m_srcInterface[j] = i.ReadU8();
301 }
302 break;
303 case HC1_PIIC:
304 for (int j = 0; j < 8; j++)
305 {
306 m_srcPrefix[j] = i.ReadU8();
307 }
308 break;
309 case HC1_PCII:
310 for (int j = 0; j < 8; j++)
311 {
312 m_srcInterface[j] = i.ReadU8();
313 }
314 break;
315 case HC1_PCIC:
316 break;
317 }
318 switch (m_dstCompression)
319 {
320 case HC1_PIII:
321 for (int j = 0; j < 8; j++)
322 {
323 m_dstPrefix[j] = i.ReadU8();
324 }
325 for (int j = 0; j < 8; j++)
326 {
327 m_dstInterface[j] = i.ReadU8();
328 }
329 break;
330 case HC1_PIIC:
331 for (int j = 0; j < 8; j++)
332 {
333 m_dstPrefix[j] = i.ReadU8();
334 }
335 break;
336 case HC1_PCII:
337 for (int j = 0; j < 8; j++)
338 {
339 m_dstInterface[j] = i.ReadU8();
340 }
341 break;
342 case HC1_PCIC:
343 break;
344 }
345
347 {
349 uint8_t temp[3];
350 i.Read(temp, 3);
351 m_flowLabel = temp[2];
352 m_flowLabel = (m_flowLabel << 8) | temp[1];
353 m_flowLabel = (m_flowLabel << 8) | temp[0];
354 }
355
357 {
358 case HC1_NC:
359 m_nextHeader = i.ReadU8();
360 break;
361 case HC1_TCP:
363 break;
364 case HC1_UDP:
366 break;
367 case HC1_ICMP:
369 break;
370 }
371
372 NS_ASSERT_MSG(m_hc2HeaderPresent != true, "Can not compress HC2, exiting. Very sorry.");
373
374 return GetSerializedSize();
375}
376
377void
379{
380 m_hopLimit = limit;
381}
382
383uint8_t
385{
386 return m_hopLimit;
387}
388
391{
392 return m_dstCompression;
393}
394
395const uint8_t*
397{
398 return m_dstInterface;
399}
400
401const uint8_t*
403{
404 return m_dstPrefix;
405}
406
409{
410 return m_flowLabel;
411}
412
413uint8_t
415{
416 return m_nextHeader;
417}
418
421{
422 return m_srcCompression;
423}
424
425const uint8_t*
427{
428 return m_srcInterface;
429}
430
431const uint8_t*
433{
434 return m_srcPrefix;
435}
436
437uint8_t
439{
440 return m_trafficClass;
441}
442
443bool
445{
446 return m_tcflCompression;
447}
448
449bool
451{
452 return m_hc2HeaderPresent;
453}
454
455void
457{
458 m_dstCompression = dstCompression;
459}
460
461void
462SixLowPanHc1::SetDstInterface(const uint8_t* dstInterface)
463{
464 for (int i = 0; i < 8; i++)
465 {
466 m_dstInterface[i] = dstInterface[i];
467 }
468}
469
470void
471SixLowPanHc1::SetDstPrefix(const uint8_t* dstPrefix)
472{
473 for (int i = 0; i < 8; i++)
474 {
475 m_dstPrefix[i] = dstPrefix[i];
476 }
477}
478
479void
481{
482 m_flowLabel = flowLabel;
483}
484
485void
487{
488 m_nextHeader = nextHeader;
489
490 switch (m_nextHeader)
491 {
494 break;
497 break;
500 break;
501 default:
503 break;
504 }
505}
506
507void
509{
510 m_srcCompression = srcCompression;
511}
512
513void
514SixLowPanHc1::SetSrcInterface(const uint8_t* srcInterface)
515{
516 for (int i = 0; i < 8; i++)
517 {
518 m_srcInterface[i] = srcInterface[i];
519 }
520}
521
522void
523SixLowPanHc1::SetSrcPrefix(const uint8_t* srcPrefix)
524{
525 for (int i = 0; i < 8; i++)
526 {
527 m_srcPrefix[i] = srcPrefix[i];
528 }
529}
530
531void
533{
534 m_tcflCompression = tcflCompression;
535}
536
537void
538SixLowPanHc1::SetTrafficClass(uint8_t trafficClass)
539{
540 m_trafficClass = trafficClass;
541}
542
543void
545{
546 m_hc2HeaderPresent = hc2HeaderPresent;
547}
548
549std::ostream&
550operator<<(std::ostream& os, const SixLowPanHc1& h)
551{
552 h.Print(os);
553 return os;
554}
555
556/*
557 * SixLowPanFrag1
558 */
559NS_OBJECT_ENSURE_REGISTERED(SixLowPanFrag1);
560
562 : m_datagramSize(0),
563 m_datagramTag(0)
564{
565}
566
567TypeId
569{
570 static TypeId tid = TypeId("ns3::SixLowPanFrag1")
571 .SetParent<Header>()
572 .SetGroupName("SixLowPan")
573 .AddConstructor<SixLowPanFrag1>();
574 return tid;
575}
576
577TypeId
579{
580 return GetTypeId();
581}
582
583void
584SixLowPanFrag1::Print(std::ostream& os) const
585{
586 os << "datagram size " << m_datagramSize << " tag " << m_datagramTag;
587}
588
591{
592 return 4;
593}
594
595void
597{
598 Buffer::Iterator i = start;
599
600 uint16_t temp = m_datagramSize | (uint16_t(SixLowPanDispatch::LOWPAN_FRAG1) << 8);
601
602 i.WriteU8(uint8_t(temp >> 8));
603 i.WriteU8(uint8_t(temp & 0xff));
604
606}
607
610{
611 Buffer::Iterator i = start;
612
613 uint8_t temp = i.ReadU8();
614 m_datagramSize = (uint16_t(temp) << 8) | i.ReadU8();
615 m_datagramSize &= 0x7FF;
616
618 return GetSerializedSize();
619}
620
621void
623{
624 m_datagramSize = datagramSize & 0x7FF;
625}
626
627uint16_t
629{
630 return m_datagramSize & 0x7FF;
631}
632
633void
635{
636 m_datagramTag = datagramTag;
637}
638
639uint16_t
641{
642 return m_datagramTag;
643}
644
645std::ostream&
646operator<<(std::ostream& os, const SixLowPanFrag1& h)
647{
648 h.Print(os);
649 return os;
650}
651
652/*
653 * SixLowPanFragN
654 */
655
656NS_OBJECT_ENSURE_REGISTERED(SixLowPanFragN);
657
659 : m_datagramSize(0),
660 m_datagramTag(0),
661 m_datagramOffset(0)
662{
663}
664
665/*
666 * SixLowPanFragmentOffset
667 */
668TypeId
670{
671 static TypeId tid = TypeId("ns3::SixLowPanFragN")
672 .SetParent<Header>()
673 .SetGroupName("SixLowPan")
674 .AddConstructor<SixLowPanFragN>();
675 return tid;
676}
677
678TypeId
680{
681 return GetTypeId();
682}
683
684void
685SixLowPanFragN::Print(std::ostream& os) const
686{
687 os << "datagram size " << m_datagramSize << " tag " << m_datagramTag << " offset "
689}
690
693{
694 return 5;
695}
696
697void
699{
700 Buffer::Iterator i = start;
701
702 uint16_t temp = m_datagramSize | (uint16_t(SixLowPanDispatch::LOWPAN_FRAGN) << 8);
703
704 i.WriteU8(uint8_t(temp >> 8));
705 i.WriteU8(uint8_t(temp & 0xff));
706
709}
710
713{
714 Buffer::Iterator i = start;
715
716 uint8_t temp = i.ReadU8();
717 m_datagramSize = (uint16_t(temp) << 8) | i.ReadU8();
718 m_datagramSize &= 0x7FF;
719
722
723 return GetSerializedSize();
724}
725
726void
728{
729 m_datagramSize = datagramSize & 0x7FF;
730}
731
732uint16_t
734{
735 return m_datagramSize & 0x7FF;
736}
737
738void
740{
741 m_datagramTag = datagramTag;
742}
743
744uint16_t
746{
747 return m_datagramTag;
748}
749
750void
752{
753 m_datagramOffset = datagramOffset;
754}
755
756uint8_t
758{
759 return m_datagramOffset;
760}
761
762std::ostream&
763operator<<(std::ostream& os, const SixLowPanFragN& h)
764{
765 h.Print(os);
766 return os;
767}
768
769/*
770 * SixLowPanIpv6
771 */
772
773NS_OBJECT_ENSURE_REGISTERED(SixLowPanIpv6);
774
776{
777}
778
779TypeId
781{
782 static TypeId tid = TypeId("ns3::SixLowPanIpv6")
783 .SetParent<Header>()
784 .SetGroupName("SixLowPan")
785 .AddConstructor<SixLowPanIpv6>();
786 return tid;
787}
788
789TypeId
791{
792 return GetTypeId();
793}
794
795void
796SixLowPanIpv6::Print(std::ostream& os) const
797{
798 os << "Uncompressed IPv6";
799}
800
803{
804 return 1;
805}
806
807void
809{
810 Buffer::Iterator i = start;
811
813}
814
817{
818 Buffer::Iterator i = start;
819 i.ReadU8();
820
821 return GetSerializedSize();
822}
823
824std::ostream&
825operator<<(std::ostream& os, const SixLowPanIpv6& h)
826{
827 h.Print(os);
828 return os;
829}
830
831/*
832 * SixLowPanIphcHeader
833 */
834NS_OBJECT_ENSURE_REGISTERED(SixLowPanIphc);
835
837{
838 // 011x xxxx xxxx xxxx
839 m_baseFormat = 0x6000;
841}
842
844{
845 // 011x xxxx xxxx xxxx
846 m_baseFormat = dispatch;
847 m_baseFormat <<= 8;
849}
850
851TypeId
853{
854 static TypeId tid = TypeId("ns3::SixLowPanIphc")
855 .SetParent<Header>()
856 .SetGroupName("SixLowPan")
857 .AddConstructor<SixLowPanIphc>();
858 return tid;
859}
860
861TypeId
863{
864 return GetTypeId();
865}
866
867void
868SixLowPanIphc::Print(std::ostream& os) const
869{
870 switch (GetTf())
871 {
872 case TF_FULL:
873 os << "TF_FULL(" << +m_ecn << ", " << +m_dscp << ", " << m_flowLabel << ")";
874 break;
875 case TF_DSCP_ELIDED:
876 os << "TF_DSCP_ELIDED(" << +m_ecn << ", " << m_flowLabel << ")";
877 break;
878 case TF_FL_ELIDED:
879 os << "TF_FL_ELIDED(" << +m_ecn << ", " << +m_dscp << ")";
880 break;
881 default:
882 os << "TF_ELIDED";
883 break;
884 }
885
886 GetNh() ? os << " NH(1)" : os << " NH(0)";
887
888 switch (GetHlim())
889 {
890 case HLIM_INLINE:
891 os << " HLIM_INLINE(" << +m_hopLimit << ")";
892 break;
893 case HLIM_COMPR_1:
894 os << " HLIM_COMPR_1(1)";
895 break;
896 case HLIM_COMPR_64:
897 os << " HLIM_COMPR_64(64)";
898 break;
899 default:
900 os << " HLIM_COMPR_255(255)";
901 break;
902 }
903
904 GetCid() ? os << " CID(" << +m_srcdstContextId << ")" : os << " CID(0)";
905
906 GetSac() ? os << " SAC(1)" : os << " SAC(0)";
907 os << " SAM (" << GetSam() << ")";
908
909 GetM() ? os << " M(1)" : os << " M(0)";
910 GetDac() ? os << " DAC(1)" : os << " DAC(0)";
911 os << " DAM (" << GetDam() << ")";
912}
913
916{
917 uint32_t serializedSize = 2;
918
919 if (GetCid())
920 {
921 serializedSize++;
922 }
923 switch (GetTf())
924 {
925 case TF_FULL:
926 serializedSize += 4;
927 break;
928 case TF_DSCP_ELIDED:
929 serializedSize += 3;
930 break;
931 case TF_FL_ELIDED:
932 serializedSize++;
933 break;
934 default:
935 break;
936 }
937 if (!GetNh())
938 {
939 serializedSize++;
940 }
941 if (GetHlim() == HLIM_INLINE)
942 {
943 serializedSize++;
944 }
945 switch (GetSam())
946 {
947 case HC_INLINE:
948 if (!GetSac())
949 {
950 serializedSize += 16;
951 }
952 break;
953 case HC_COMPR_64:
954 serializedSize += 8;
955 break;
956 case HC_COMPR_16:
957 serializedSize += 2;
958 break;
959 case HC_COMPR_0:
960 default:
961 break;
962 }
963 if (!GetM())
964 {
965 switch (GetDam())
966 {
967 case HC_INLINE:
968 if (!GetDac())
969 {
970 serializedSize += 16;
971 }
972 break;
973 case HC_COMPR_64:
974 serializedSize += 8;
975 break;
976 case HC_COMPR_16:
977 serializedSize += 2;
978 break;
979 case HC_COMPR_0:
980 default:
981 break;
982 }
983 }
984 else
985 {
986 switch (GetDam())
987 {
988 case HC_INLINE:
989 if (!GetDac())
990 {
991 serializedSize += 16;
992 }
993 else
994 {
995 serializedSize += 6;
996 }
997 break;
998 case HC_COMPR_64:
999 if (!GetDac())
1000 {
1001 serializedSize += 6;
1002 }
1003 break;
1004 case HC_COMPR_16:
1005 if (!GetDac())
1006 {
1007 serializedSize += 4;
1008 }
1009 break;
1010 case HC_COMPR_0:
1011 default:
1012 if (!GetDac())
1013 {
1014 serializedSize++;
1015 }
1016 break;
1017 }
1018 }
1019
1020 return serializedSize;
1021}
1022
1023void
1025{
1026 Buffer::Iterator i = start;
1027
1029
1030 if (GetCid())
1031 {
1033 }
1034 // Traffic Class and Flow Label
1035 switch (GetTf())
1036 {
1037 uint8_t temp;
1038 case TF_FULL:
1039 temp = (m_ecn << 6) | m_dscp;
1040 i.WriteU8(temp);
1041 temp = m_flowLabel >> 16;
1042 i.WriteU8(temp);
1043 temp = (m_flowLabel >> 8) & 0xff;
1044 i.WriteU8(temp);
1045 temp = m_flowLabel & 0xff;
1046 i.WriteU8(temp);
1047 break;
1048 case TF_DSCP_ELIDED:
1049 temp = (m_ecn << 6) | (m_flowLabel >> 16);
1050 i.WriteU8(temp);
1051 temp = (m_flowLabel >> 8) & 0xff;
1052 i.WriteU8(temp);
1053 temp = m_flowLabel & 0xff;
1054 i.WriteU8(temp);
1055 break;
1056 case TF_FL_ELIDED:
1057 temp = (m_ecn << 6) | m_dscp;
1058 i.WriteU8(temp);
1059 break;
1060 default:
1061 break;
1062 }
1063 // Next Header
1064 if (!GetNh())
1065 {
1067 }
1068 // Hop Limit
1069 if (GetHlim() == HLIM_INLINE)
1070 {
1072 }
1073 // Source Address
1074 switch (GetSam())
1075 {
1076 case HC_INLINE:
1077 if (!GetSac())
1078 {
1079 i.Write(m_srcInlinePart, 16);
1080 }
1081 break;
1082 case HC_COMPR_64:
1083 i.Write(m_srcInlinePart, 8);
1084 break;
1085 case HC_COMPR_16:
1086 i.Write(m_srcInlinePart, 2);
1087 break;
1088 case HC_COMPR_0:
1089 default:
1090 break;
1091 }
1092 // Destination Address
1093 if (!GetM())
1094 {
1095 // unicast
1096 switch (GetDam())
1097 {
1098 case HC_INLINE:
1099 i.Write(m_dstInlinePart, 16);
1100 break;
1101 case HC_COMPR_64:
1102 i.Write(m_dstInlinePart, 8);
1103 break;
1104 case HC_COMPR_16:
1105 i.Write(m_dstInlinePart, 2);
1106 break;
1107 case HC_COMPR_0:
1108 default:
1109 break;
1110 }
1111 }
1112 else
1113 {
1114 // multicast
1115 switch (GetDam())
1116 {
1117 case HC_INLINE:
1118 i.Write(m_dstInlinePart, 16);
1119 break;
1120 case HC_COMPR_64:
1121 i.Write(m_dstInlinePart, 6);
1122 break;
1123 case HC_COMPR_16:
1124 i.Write(m_dstInlinePart, 4);
1125 break;
1126 case HC_COMPR_0:
1127 i.Write(m_dstInlinePart, 1);
1128 break;
1129 default:
1130 break;
1131 }
1132 }
1133}
1134
1137{
1138 Buffer::Iterator i = start;
1139
1141
1142 if (GetCid())
1143 {
1145 }
1146 else
1147 {
1149 }
1150 // Traffic Class and Flow Label
1151 switch (GetTf())
1152 {
1153 uint8_t temp;
1154 case TF_FULL:
1155 temp = i.ReadU8();
1156 m_ecn = temp >> 6;
1157 m_dscp = temp & 0x3F;
1158 temp = i.ReadU8();
1159 m_flowLabel = temp;
1160 temp = i.ReadU8();
1161 m_flowLabel = (m_flowLabel << 8) | temp;
1162 temp = i.ReadU8();
1163 m_flowLabel = (m_flowLabel << 8) | temp;
1164 break;
1165 case TF_DSCP_ELIDED:
1166 temp = i.ReadU8();
1167 m_ecn = temp >> 6;
1168 m_flowLabel = temp & 0x3F;
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_FL_ELIDED:
1175 temp = i.ReadU8();
1176 m_ecn = temp >> 6;
1177 m_dscp = temp & 0x3F;
1178 break;
1179 default:
1180 break;
1181 }
1182 // Next Header
1183 if (!GetNh())
1184 {
1185 m_nextHeader = i.ReadU8();
1186 }
1187 // Hop Limit
1188 switch (GetHlim())
1189 {
1190 case HLIM_INLINE:
1191 m_hopLimit = i.ReadU8();
1192 break;
1193 case HLIM_COMPR_1:
1194 m_hopLimit = 1;
1195 break;
1196 case HLIM_COMPR_64:
1197 m_hopLimit = 64;
1198 break;
1199 case HLIM_COMPR_255:
1200 default:
1201 m_hopLimit = 255;
1202 break;
1203 }
1204 // Source Address
1205 memset(m_srcInlinePart, 0x00, sizeof(m_srcInlinePart));
1206 switch (GetSam())
1207 {
1208 case HC_INLINE:
1209 if (!GetSac())
1210 {
1211 i.Read(m_srcInlinePart, 16);
1212 }
1213 break;
1214 case HC_COMPR_64:
1215 i.Read(m_srcInlinePart, 8);
1216 break;
1217 case HC_COMPR_16:
1218 i.Read(m_srcInlinePart, 2);
1219 break;
1220 case HC_COMPR_0:
1221 default:
1222 break;
1223 }
1224
1225 // Destination Address
1226 memset(m_dstInlinePart, 0x00, sizeof(m_dstInlinePart));
1227 if (!GetM())
1228 {
1229 // unicast
1230 switch (GetDam())
1231 {
1232 case HC_INLINE:
1233 i.Read(m_dstInlinePart, 16);
1234 break;
1235 case HC_COMPR_64:
1236 i.Read(m_dstInlinePart, 8);
1237 break;
1238 case HC_COMPR_16:
1239 i.Read(m_dstInlinePart, 2);
1240 break;
1241 case HC_COMPR_0:
1242 default:
1243 break;
1244 }
1245 }
1246 else
1247 {
1248 // multicast
1249 switch (GetDam())
1250 {
1251 case HC_INLINE:
1252 i.Read(m_dstInlinePart, 16);
1253 break;
1254 case HC_COMPR_64:
1255 i.Read(m_dstInlinePart, 6);
1256 break;
1257 case HC_COMPR_16:
1258 i.Read(m_dstInlinePart, 4);
1259 break;
1260 case HC_COMPR_0:
1261 i.Read(m_dstInlinePart, 1);
1262 break;
1263 default:
1264 break;
1265 }
1266 }
1267
1268 return GetSerializedSize();
1269}
1270
1271void
1273{
1274 uint16_t field = tfField;
1275 m_baseFormat |= (field << 11);
1276}
1277
1280{
1281 return TrafficClassFlowLabel_e((m_baseFormat >> 11) & 0x3);
1282}
1283
1284void
1286{
1287 uint16_t field = nhField;
1288 m_baseFormat |= (field << 10);
1289}
1290
1291bool
1293{
1294 return ((m_baseFormat >> 10) & 0x1);
1295}
1296
1297void
1299{
1300 uint16_t field = hlimField;
1301 m_baseFormat |= (field << 8);
1302}
1303
1306{
1307 return Hlim_e((m_baseFormat >> 8) & 0x3);
1308}
1309
1310void
1312{
1313 uint16_t field = cidField;
1314 m_baseFormat |= (field << 7);
1315}
1316
1317bool
1319{
1320 return ((m_baseFormat >> 7) & 0x1);
1321}
1322
1323void
1325{
1326 uint16_t field = sacField;
1327 m_baseFormat |= (field << 6);
1328}
1329
1330bool
1332{
1333 return ((m_baseFormat >> 6) & 0x1);
1334}
1335
1336void
1338{
1339 uint16_t field = samField;
1340 m_baseFormat |= (field << 4);
1341}
1342
1345{
1346 return HeaderCompression_e((m_baseFormat >> 4) & 0x3);
1347}
1348
1349const uint8_t*
1351{
1352 return m_srcInlinePart;
1353}
1354
1355void
1356SixLowPanIphc::SetSrcInlinePart(uint8_t srcInlinePart[16], uint8_t size)
1357{
1358 NS_ASSERT_MSG(size <= 16, "Src inline part too large");
1359
1360 memcpy(m_srcInlinePart, srcInlinePart, size);
1361}
1362
1363void
1365{
1366 uint16_t field = mField;
1367 m_baseFormat |= (field << 3);
1368}
1369
1370bool
1372{
1373 return ((m_baseFormat >> 3) & 0x1);
1374}
1375
1376void
1378{
1379 uint16_t field = dacField;
1380 m_baseFormat |= (field << 2);
1381}
1382
1383bool
1385{
1386 return ((m_baseFormat >> 2) & 0x1);
1387}
1388
1389void
1391{
1392 uint16_t field = damField;
1393 m_baseFormat |= field;
1394}
1395
1398{
1399 return HeaderCompression_e(m_baseFormat & 0x3);
1400}
1401
1402const uint8_t*
1404{
1405 return m_dstInlinePart;
1406}
1407
1408void
1409SixLowPanIphc::SetDstInlinePart(uint8_t dstInlinePart[16], uint8_t size)
1410{
1411 NS_ASSERT_MSG(size <= 16, "Dst inline part too large");
1412
1413 memcpy(m_dstInlinePart, dstInlinePart, size);
1414}
1415
1416void
1418{
1419 NS_ASSERT_MSG(srcContextId < 16, "Src Context ID too large");
1420 m_srcdstContextId |= srcContextId << 4;
1421}
1422
1423uint8_t
1425{
1426 return (m_srcdstContextId >> 4);
1427}
1428
1429void
1431{
1432 NS_ASSERT_MSG(dstContextId < 16, "Dst Context ID too large");
1433 m_srcdstContextId |= (dstContextId & 0xF);
1434}
1435
1436uint8_t
1438{
1439 return (m_srcdstContextId & 0xF);
1440}
1441
1442void
1444{
1445 NS_ASSERT_MSG(ecn < 4, "ECN too large");
1446 m_ecn = ecn;
1447}
1448
1449uint8_t
1451{
1452 return m_ecn;
1453}
1454
1455void
1457{
1458 NS_ASSERT_MSG(dscp < 64, "DSCP too large");
1459 m_dscp = dscp;
1460}
1461
1462uint8_t
1464{
1465 return m_dscp;
1466}
1467
1468void
1470{
1471 NS_ASSERT_MSG(flowLabel < 0x100000, "Flow Label too large");
1472 m_flowLabel = flowLabel;
1473}
1474
1477{
1478 return m_flowLabel;
1479}
1480
1481void
1483{
1484 m_nextHeader = nextHeader;
1485}
1486
1487uint8_t
1489{
1490 return m_nextHeader;
1491}
1492
1493void
1495{
1496 m_hopLimit = hopLimit;
1497}
1498
1499uint8_t
1501{
1502 return m_hopLimit;
1503}
1504
1505std::ostream&
1506operator<<(std::ostream& os, const SixLowPanIphc& h)
1507{
1508 h.Print(os);
1509 return os;
1510}
1511
1512/*
1513 * SixLowPanNhcExtensionHeader
1514 */
1515NS_OBJECT_ENSURE_REGISTERED(SixLowPanNhcExtension);
1516
1518{
1519 // 1110 xxxx
1520 m_nhcExtensionHeader = 0xE0;
1521 m_nhcNextHeader = 0;
1522 m_nhcBlobLength = 0;
1523}
1524
1525TypeId
1527{
1528 static TypeId tid = TypeId("ns3::SixLowPanNhcExtension")
1529 .SetParent<Header>()
1530 .SetGroupName("SixLowPan")
1531 .AddConstructor<SixLowPanNhcExtension>();
1532 return tid;
1533}
1534
1535TypeId
1537{
1538 return GetTypeId();
1539}
1540
1541void
1542SixLowPanNhcExtension::Print(std::ostream& os) const
1543{
1544 os << "Compression kind: " << +m_nhcExtensionHeader << " Size: " << GetSerializedSize();
1545}
1546
1549{
1550 uint32_t serializedSize = 2;
1551 if (!GetNh())
1552 {
1553 serializedSize++;
1554 }
1555 return serializedSize + m_nhcBlobLength;
1556}
1557
1558void
1560{
1561 Buffer::Iterator i = start;
1563 if (!GetNh())
1564 {
1566 }
1569}
1570
1573{
1574 Buffer::Iterator i = start;
1576 if (!GetNh())
1577 {
1578 m_nhcNextHeader = i.ReadU8();
1579 }
1580 m_nhcBlobLength = i.ReadU8();
1582
1583 return GetSerializedSize();
1584}
1585
1588{
1590}
1591
1592void
1594{
1595 uint8_t field = extensionHeaderType;
1596 m_nhcExtensionHeader |= (field << 1);
1597}
1598
1601{
1602 return Eid_e((m_nhcExtensionHeader >> 1) & 0x7);
1603}
1604
1605void
1607{
1608 m_nhcNextHeader = nextHeader;
1609}
1610
1611uint8_t
1613{
1614 return m_nhcNextHeader;
1615}
1616
1617void
1619{
1620 uint8_t field = nhField;
1621 m_nhcExtensionHeader |= field;
1622}
1623
1624bool
1626{
1627 return m_nhcExtensionHeader & 0x01;
1628}
1629
1630void
1632{
1633 NS_ASSERT_MSG(size < 255, "Buffer too long");
1634
1635 m_nhcBlobLength = size;
1636 std::memcpy(m_nhcBlob, blob, size);
1637}
1638
1641{
1642 NS_ASSERT_MSG(size > m_nhcBlobLength, "Buffer too short");
1643
1644 std::memcpy(blob, m_nhcBlob, m_nhcBlobLength);
1645 return m_nhcBlobLength;
1646}
1647
1648std::ostream&
1649operator<<(std::ostream& os, const SixLowPanNhcExtension& h)
1650{
1651 h.Print(os);
1652 return os;
1653}
1654
1655/*
1656 * SixLowPanUdpNhcExtension
1657 */
1658NS_OBJECT_ENSURE_REGISTERED(SixLowPanUdpNhcExtension);
1659
1661{
1662 // 1111 0xxx
1663 m_baseFormat = 0xF0;
1664 m_checksum = 0;
1665 m_srcPort = 0;
1666 m_dstPort = 0;
1667}
1668
1669TypeId
1671{
1672 static TypeId tid = TypeId("ns3::SixLowPanUdpNhcExtension")
1673 .SetParent<Header>()
1674 .SetGroupName("SixLowPan")
1675 .AddConstructor<SixLowPanUdpNhcExtension>();
1676 return tid;
1677}
1678
1679TypeId
1681{
1682 return GetTypeId();
1683}
1684
1685void
1686SixLowPanUdpNhcExtension::Print(std::ostream& os) const
1687{
1688 os << "Compression kind: " << +m_baseFormat;
1689}
1690
1693{
1694 uint32_t serializedSize = 1;
1695 if (!GetC())
1696 {
1697 serializedSize += 2;
1698 }
1699 switch (GetPorts())
1700 {
1701 case PORTS_INLINE:
1702 serializedSize += 4;
1703 break;
1706 serializedSize += 3;
1707 break;
1709 serializedSize += 1;
1710 break;
1711 default:
1712 break;
1713 }
1714 return serializedSize;
1715}
1716
1717void
1719{
1720 Buffer::Iterator i = start;
1722 uint8_t temp;
1723
1724 // Ports
1725 switch (GetPorts())
1726 {
1727 case PORTS_INLINE:
1730 break;
1733 i.WriteU8(m_dstPort & 0xff);
1734 break;
1736 i.WriteU8(m_srcPort & 0xff);
1738 break;
1740 temp = ((m_srcPort & 0xf) << 4) | (m_dstPort & 0xf);
1741 i.WriteU8(temp);
1742 break;
1743 default:
1744 break;
1745 }
1746
1747 // Checksum
1748 if (!GetC())
1749 {
1751 }
1752}
1753
1756{
1757 Buffer::Iterator i = start;
1758 m_baseFormat = i.ReadU8();
1759 uint8_t temp;
1760
1761 // Ports
1762 switch (GetPorts())
1763 {
1764 case PORTS_INLINE:
1765 m_srcPort = i.ReadNtohU16();
1766 m_dstPort = i.ReadNtohU16();
1767 break;
1769 m_srcPort = i.ReadNtohU16();
1770 m_dstPort = i.ReadU8();
1771 break;
1773 m_srcPort = i.ReadU8();
1774 m_dstPort = i.ReadNtohU16();
1775 break;
1777 temp = i.ReadU8();
1778 m_srcPort = temp >> 4;
1779 m_dstPort = temp & 0xf;
1780 break;
1781 default:
1782 break;
1783 }
1784
1785 // Checksum
1786 if (!GetC())
1787 {
1788 m_checksum = i.ReadU16();
1789 }
1790
1791 return GetSerializedSize();
1792}
1793
1796{
1798}
1799
1800void
1802{
1803 uint16_t field = ports;
1804 m_baseFormat |= field;
1805}
1806
1809{
1810 return Ports_e(m_baseFormat & 0x3);
1811}
1812
1813void
1815{
1816 m_srcPort = srcport;
1817}
1818
1819uint16_t
1821{
1822 return m_srcPort;
1823}
1824
1825void
1827{
1828 m_dstPort = dstport;
1829}
1830
1831uint16_t
1833{
1834 return m_dstPort;
1835}
1836
1837void
1839{
1840 uint16_t field = cField;
1841 m_baseFormat |= (field << 2);
1842}
1843
1844bool
1846{
1847 return ((m_baseFormat >> 2) & 0x1);
1848}
1849
1850void
1852{
1853 m_checksum = checksum;
1854}
1855
1856uint16_t
1858{
1859 return m_checksum;
1860}
1861
1862std::ostream&
1863operator<<(std::ostream& os, const SixLowPanUdpNhcExtension& h)
1864{
1865 h.Print(os);
1866 return os;
1867}
1868
1869/*
1870 * SixLowPanBc0
1871 */
1872NS_OBJECT_ENSURE_REGISTERED(SixLowPanBc0);
1873
1875{
1876 m_seqNumber = 66;
1877}
1878
1879TypeId
1881{
1882 static TypeId tid = TypeId("ns3::SixLowPanBc0")
1883 .SetParent<Header>()
1884 .SetGroupName("SixLowPan")
1885 .AddConstructor<SixLowPanBc0>();
1886 return tid;
1887}
1888
1889TypeId
1891{
1892 return GetTypeId();
1893}
1894
1895void
1896SixLowPanBc0::Print(std::ostream& os) const
1897{
1898 os << "Sequence number: " << +m_seqNumber;
1899}
1900
1903{
1904 return 2;
1905}
1906
1907void
1909{
1910 Buffer::Iterator i = start;
1911 i.WriteU8(0x50);
1913}
1914
1917{
1918 Buffer::Iterator i = start;
1919 uint8_t dispatch = i.ReadU8();
1920
1921 if (dispatch != 0x50)
1922 {
1923 return 0;
1924 }
1925
1926 m_seqNumber = i.ReadU8();
1927
1928 return GetSerializedSize();
1929}
1930
1931void
1933{
1934 m_seqNumber = seqNumber;
1935}
1936
1937uint8_t
1939{
1940 return m_seqNumber;
1941}
1942
1943std::ostream&
1944operator<<(std::ostream& os, const SixLowPanBc0& h)
1945{
1946 h.Print(os);
1947 return os;
1948}
1949
1950/*
1951 * SixLowPanMesh
1952 */
1953NS_OBJECT_ENSURE_REGISTERED(SixLowPanMesh);
1954
1956{
1957 m_hopsLeft = 0;
1958 m_src = Address();
1959 m_dst = Address();
1960 m_v = false;
1961 m_f = false;
1962}
1963
1964TypeId
1966{
1967 static TypeId tid = TypeId("ns3::SixLowPanMesh")
1968 .SetParent<Header>()
1969 .SetGroupName("SixLowPan")
1970 .AddConstructor<SixLowPanMesh>();
1971 return tid;
1972}
1973
1974TypeId
1976{
1977 return GetTypeId();
1978}
1979
1980void
1981SixLowPanMesh::Print(std::ostream& os) const
1982{
1983 os << "Hops left: " << +m_hopsLeft << ", src: ";
1985 {
1987 }
1988 else
1989 {
1991 }
1992 os << ", dst: ";
1994 {
1996 }
1997 else
1998 {
2000 }
2001}
2002
2005{
2006 uint32_t serializedSize = 1;
2007
2008 if (m_hopsLeft >= 0xF)
2009 {
2010 serializedSize++;
2011 }
2012
2013 if (m_v)
2014 {
2015 serializedSize += 2;
2016 }
2017 else
2018 {
2019 serializedSize += 8;
2020 }
2021
2022 if (m_f)
2023 {
2024 serializedSize += 2;
2025 }
2026 else
2027 {
2028 serializedSize += 8;
2029 }
2030
2031 return serializedSize;
2032}
2033
2034void
2036{
2037 Buffer::Iterator i = start;
2038
2039 uint8_t dispatch = 0x80;
2040
2041 if (m_v)
2042 {
2043 dispatch |= 0x20;
2044 }
2045 if (m_f)
2046 {
2047 dispatch |= 0x10;
2048 }
2049
2050 if (m_hopsLeft < 0xF)
2051 {
2052 dispatch |= m_hopsLeft;
2053 i.WriteU8(dispatch);
2054 }
2055 else
2056 {
2057 dispatch |= 0xF;
2058 i.WriteU8(dispatch);
2060 }
2061
2062 uint8_t buffer[8];
2063
2064 m_src.CopyTo(buffer);
2065 if (m_v)
2066 {
2067 i.Write(buffer, 2);
2068 }
2069 else
2070 {
2071 i.Write(buffer, 8);
2072 }
2073
2074 m_dst.CopyTo(buffer);
2075 if (m_f)
2076 {
2077 i.Write(buffer, 2);
2078 }
2079 else
2080 {
2081 i.Write(buffer, 8);
2082 }
2083}
2084
2087{
2088 Buffer::Iterator i = start;
2089 uint8_t temp = i.ReadU8();
2090
2091 if ((temp & 0xC0) != 0x80)
2092 {
2093 return 0;
2094 }
2095
2096 m_v = temp & 0x20;
2097 m_f = temp & 0x10;
2098 m_hopsLeft = temp & 0xF;
2099
2100 if (m_hopsLeft == 0xF)
2101 {
2102 m_hopsLeft = i.ReadU8();
2103 }
2104
2105 uint8_t buffer[8];
2106 uint8_t addrSize;
2107
2108 if (m_v)
2109 {
2110 addrSize = 2;
2111 }
2112 else
2113 {
2114 addrSize = 8;
2115 }
2116 i.Read(buffer, addrSize);
2117 m_src.CopyFrom(buffer, addrSize);
2118
2119 if (m_f)
2120 {
2121 addrSize = 2;
2122 }
2123 else
2124 {
2125 addrSize = 8;
2126 }
2127 i.Read(buffer, addrSize);
2128 m_dst.CopyFrom(buffer, addrSize);
2129
2130 return GetSerializedSize();
2131}
2132
2133void
2135{
2136 if (Mac64Address::IsMatchingType(originator))
2137 {
2138 m_v = false;
2139 }
2140 else if (Mac16Address::IsMatchingType(originator))
2141 {
2142 m_v = true;
2143 }
2144 else
2145 {
2146 NS_ABORT_MSG("SixLowPanMesh::SetOriginator - incompatible address");
2147 }
2148
2149 m_src = originator;
2150}
2151
2152Address
2154{
2155 return m_src;
2156}
2157
2158void
2160{
2161 if (Mac64Address::IsMatchingType(finalDst))
2162 {
2163 m_f = false;
2164 }
2165 else if (Mac16Address::IsMatchingType(finalDst))
2166 {
2167 m_f = true;
2168 }
2169 else
2170 {
2171 NS_ABORT_MSG("SixLowPanMesh::SetFinalDst - incompatible address");
2172 }
2173
2174 m_dst = finalDst;
2175}
2176
2177Address
2179{
2180 return m_dst;
2181}
2182
2183void
2185{
2186 m_hopsLeft = hopsLeft;
2187}
2188
2189uint8_t
2191{
2192 return m_hopsLeft;
2193}
2194
2195std::ostream&
2196operator<<(std::ostream& os, const SixLowPanMesh& h)
2197{
2198 h.Print(os);
2199 return os;
2200}
2201
2202} // namespace ns3
a polymophic address class
Definition: address.h:101
uint32_t CopyFrom(const uint8_t *buffer, uint8_t len)
Definition: address.cc:106
uint32_t CopyTo(uint8_t buffer[MAX_SIZE]) const
Copy the address bytes into a buffer.
Definition: address.cc:86
iterator in a Buffer instance
Definition: buffer.h:100
uint8_t ReadU8()
Definition: buffer.h:1027
void WriteU8(uint8_t data)
Definition: buffer.h:881
void Write(const uint8_t *buffer, uint32_t size)
Definition: buffer.cc:948
void WriteU16(uint16_t data)
Definition: buffer.cc:859
void Read(uint8_t *buffer, uint32_t size)
Definition: buffer.cc:1125
void WriteHtonU16(uint16_t data)
Definition: buffer.h:915
uint16_t ReadNtohU16()
Definition: buffer.h:954
uint16_t ReadU16()
Definition: buffer.h:1035
Protocol header serialization and deserialization.
Definition: header.h:44
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.
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.
uint16_t m_srcPort
Source 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:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:932
#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:86
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Definition: abort.h:49
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
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:159