A Discrete-Event Network Simulator
API
sixlowpan-header.cc
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2013 Universita' di Firenze, Italy
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Tommaso Pecorella <tommaso.pecorella@unifi.it>
19 * Michele Muccio <michelemuccio@virgilio.it>
20 */
21
22#include "ns3/assert.h"
23#include "ns3/log.h"
24#include "ns3/abort.h"
25#include "ns3/ipv6-header.h"
26#include "ns3/mac64-address.h"
27#include "ns3/mac16-address.h"
28#include "ns3/ipv6-header.h"
29#include "sixlowpan-header.h"
30
31
32namespace ns3 {
33
34/*
35 * SixLowPanDispatch
36 */
37
38
40{
41}
42
43
46{
47 if (dispatch <= LOWPAN_NALP_N)
48 {
49 return LOWPAN_NALP;
50 }
51 else if (dispatch == LOWPAN_IPv6)
52 {
53 return LOWPAN_IPv6;
54 }
55 else if (dispatch == LOWPAN_HC1)
56 {
57 return LOWPAN_HC1;
58 }
59 else if (dispatch == LOWPAN_BC0)
60 {
61 return LOWPAN_BC0;
62 }
63 else if ((dispatch >= LOWPAN_IPHC) && (dispatch <= LOWPAN_IPHC_N))
64 {
65 return LOWPAN_IPHC;
66 }
67 else if ((dispatch >= LOWPAN_MESH) && (dispatch <= LOWPAN_MESH_N))
68 {
69 return LOWPAN_MESH;
70 }
71 else if ((dispatch >= LOWPAN_FRAG1) && (dispatch <= LOWPAN_FRAG1_N))
72 {
73 return LOWPAN_FRAG1;
74 }
75 else if ((dispatch >= LOWPAN_FRAGN) && (dispatch <= LOWPAN_FRAGN_N))
76 {
77 return LOWPAN_FRAGN;
78 }
79 return LOWPAN_UNSUPPORTED;
80}
81
84{
85 if ((dispatch >= LOWPAN_NHC) && (dispatch <= LOWPAN_NHC_N))
86 {
87 return LOWPAN_NHC;
88 }
89 else if ((dispatch >= LOWPAN_UDPNHC) && (dispatch <= LOWPAN_UDPNHC_N))
90 {
91 return LOWPAN_UDPNHC;
92 }
94}
95
96
97/*
98 * SixLowPanHc1
99 */
101
103 : m_hopLimit (0)
104{
105}
106
108{
109 static TypeId tid = TypeId ("ns3::SixLowPanHc1")
110 .SetParent<Header> ()
111 .SetGroupName ("SixLowPan")
112 .AddConstructor<SixLowPanHc1> ();
113 return tid;
114}
115
117{
118 return GetTypeId ();
119}
120
121void SixLowPanHc1::Print (std::ostream & os) const
122{
123 uint8_t encoding;
124 encoding = m_srcCompression;
125 encoding <<= 2;
126 encoding |= m_dstCompression;
127 encoding <<= 1;
128 encoding |= m_tcflCompression;
129 encoding <<= 2;
130 encoding |= m_nextHeaderCompression;
131 encoding <<= 1;
132 encoding |= m_hc2HeaderPresent;
133
134 os << "encoding " << +encoding << ", hopLimit " << +m_hopLimit;
135}
136
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 serializedSize += 8;
148 break;
149 case HC1_PCII:
150 serializedSize += 8;
151 break;
152 case HC1_PCIC:
153 break;
154 }
155 switch (m_dstCompression)
156 {
157 case HC1_PIII:
158 serializedSize += 16;
159 break;
160 case HC1_PIIC:
161 serializedSize += 8;
162 break;
163 case HC1_PCII:
164 serializedSize += 8;
165 break;
166 case HC1_PCIC:
167 break;
168 }
169
170 if (m_tcflCompression == false )
171 {
172 serializedSize += 4;
173 }
174
176 {
177 serializedSize++;
178 }
179
180 return serializedSize;
181}
182
184{
186 uint8_t encoding;
187 encoding = m_srcCompression;
188 encoding <<= 2;
189 encoding |= m_dstCompression;
190 encoding <<= 1;
191 encoding |= m_tcflCompression;
192 encoding <<= 2;
193 encoding |= m_nextHeaderCompression;
194 encoding <<= 1;
195 encoding |= m_hc2HeaderPresent;
196
198 i.WriteU8 (encoding);
200 switch (m_srcCompression)
201 {
202 case HC1_PIII:
203 for ( int j = 0; j < 8; j++ )
204 {
205 i.WriteU8 (m_srcPrefix[j]);
206 }
207 for ( int j = 0; j < 8; j++ )
208 {
209 i.WriteU8 (m_srcInterface[j]);
210 }
211 break;
212 case HC1_PIIC:
213 for ( int j = 0; j < 8; j++ )
214 {
215 i.WriteU8 (m_srcPrefix[j]);
216 }
217 break;
218 case HC1_PCII:
219 for ( int j = 0; j < 8; j++ )
220 {
221 i.WriteU8 (m_srcInterface[j]);
222 }
223 break;
224 case HC1_PCIC:
225 break;
226 }
227 switch (m_dstCompression)
228 {
229 case HC1_PIII:
230 for ( int j = 0; j < 8; j++ )
231 {
232 i.WriteU8 (m_dstPrefix[j]);
233 }
234 for ( int j = 0; j < 8; j++ )
235 {
236 i.WriteU8 (m_dstInterface[j]);
237 }
238 break;
239 case HC1_PIIC:
240 for ( int j = 0; j < 8; j++ )
241 {
242 i.WriteU8 (m_dstPrefix[j]);
243 }
244 break;
245 case HC1_PCII:
246 for ( int j = 0; j < 8; j++ )
247 {
248 i.WriteU8 (m_dstInterface[j]);
249 }
250 break;
251 case HC1_PCIC:
252 break;
253 }
254
255 if ( m_tcflCompression == false )
256 {
258 uint8_t temp[3];
259 temp[0] = uint8_t (m_flowLabel & 0xff);
260 temp[1] = uint8_t ((m_flowLabel >> 8) & 0xff);
261 temp[2] = uint8_t ((m_flowLabel >> 16) & 0xff);
262 i.Write (temp, 3);
263 }
264
266 {
268 }
269
270 // TODO: HC2 is not yet supported. Should be.
271 NS_ASSERT_MSG ( m_hc2HeaderPresent != true, "Can not compress HC2, exiting. Very sorry." );
272}
273
275{
277 uint32_t serializedSize = 3;
278
279 uint8_t dispatch = i.ReadU8 ();
280 if (dispatch != SixLowPanDispatch::LOWPAN_HC1)
281 {
282 return 0;
283 }
284
285 uint8_t encoding = i.ReadU8 ();
286 m_hopLimit = i.ReadU8 ();
287
288 m_srcCompression = LowPanHc1Addr_e (encoding >> 6);
289 m_dstCompression = LowPanHc1Addr_e ( (encoding >> 4) & 0x3);
290 m_tcflCompression = (encoding >> 3) & 0x1;
291 m_nextHeaderCompression = LowPanHc1NextHeader_e ( (encoding >> 1) & 0x3);
292 m_hc2HeaderPresent = encoding & 0x1;
293
294 switch (m_srcCompression)
295 {
296 case HC1_PIII:
297 for ( int j = 0; j < 8; j++)
298 {
299 m_srcPrefix[j] = i.ReadU8 ();
300 }
301 for ( int j = 0; j < 8; j++)
302 {
303 m_srcInterface[j] = i.ReadU8 ();
304 }
305 serializedSize += 16;
306 break;
307 case HC1_PIIC:
308 for ( int j = 0; j < 8; j++)
309 {
310 m_srcPrefix[j] = i.ReadU8 ();
311 }
312 serializedSize += 8;
313 break;
314 case HC1_PCII:
315 for ( int j = 0; j < 8; j++)
316 {
317 m_srcInterface[j] = i.ReadU8 ();
318 }
319 serializedSize += 8;
320 break;
321 case HC1_PCIC:
322 break;
323 }
324 switch (m_dstCompression)
325 {
326 case HC1_PIII:
327 for ( int j = 0; j < 8; j++)
328 {
329 m_dstPrefix[j] = i.ReadU8 ();
330 }
331 for ( int j = 0; j < 8; j++)
332 {
333 m_dstInterface[j] = i.ReadU8 ();
334 }
335 serializedSize += 16;
336 break;
337 case HC1_PIIC:
338 for ( int j = 0; j < 8; j++)
339 {
340 m_dstPrefix[j] = i.ReadU8 ();
341 }
342 serializedSize += 8;
343 break;
344 case HC1_PCII:
345 for ( int j = 0; j < 8; j++)
346 {
347 m_dstInterface[j] = i.ReadU8 ();
348 }
349 serializedSize += 8;
350 break;
351 case HC1_PCIC:
352 break;
353 }
354
355 if ( m_tcflCompression == false )
356 {
357 m_trafficClass = i.ReadU8 ();
358 uint8_t temp[3];
359 i.Read (temp, 3);
360 m_flowLabel = temp[2];
361 m_flowLabel = (m_flowLabel << 8) | temp[1];
362 m_flowLabel = (m_flowLabel << 8) | temp[0];
363 serializedSize += 4;
364 }
365
366 switch ( m_nextHeaderCompression )
367 {
368 case HC1_NC:
369 m_nextHeader = i.ReadU8 ();
370 serializedSize++;
371 break;
372 case HC1_TCP:
374 break;
375 case HC1_UDP:
377 break;
378 case HC1_ICMP:
380 break;
381 }
382
383 NS_ASSERT_MSG ( m_hc2HeaderPresent != true, "Can not compress HC2, exiting. Very sorry." );
384
385 return GetSerializedSize ();
386}
387
388void SixLowPanHc1::SetHopLimit (uint8_t limit)
389{
390 m_hopLimit = limit;
391}
392
394{
395 return m_hopLimit;
396}
397
399{
400 return m_dstCompression;
401}
402
403const uint8_t* SixLowPanHc1::GetDstInterface () const
404{
405 return m_dstInterface;
406}
407
408const uint8_t* SixLowPanHc1::GetDstPrefix () const
409{
410 return m_dstPrefix;
411}
412
414{
415 return m_flowLabel;
416}
417
419{
420 return m_nextHeader;
421}
422
424{
425 return m_srcCompression;
426}
427
428const uint8_t* SixLowPanHc1::GetSrcInterface () const
429{
430 return m_srcInterface;
431}
432
433const uint8_t* SixLowPanHc1::GetSrcPrefix () const
434{
435 return m_srcPrefix;
436}
437
439{
440 return m_trafficClass;
441}
442
444{
445 return m_tcflCompression;
446}
447
449{
450 return m_hc2HeaderPresent;
451}
452
454{
455 m_dstCompression = dstCompression;
456}
457
458void SixLowPanHc1::SetDstInterface (const uint8_t* dstInterface)
459{
460 for ( int i = 0; i < 8; i++)
461 {
462 m_dstInterface[i] = dstInterface[i];
463 }
464}
465
466void SixLowPanHc1::SetDstPrefix (const uint8_t* dstPrefix)
467{
468 for ( int i = 0; i < 8; i++)
469 {
470 m_dstPrefix[i] = dstPrefix[i];
471 }
472}
473
475{
476 m_flowLabel = flowLabel;
477}
478
479void SixLowPanHc1::SetNextHeader (uint8_t nextHeader)
480{
481 m_nextHeader = nextHeader;
482
483 switch (m_nextHeader)
484 {
487 break;
490 break;
493 break;
494 default:
496 break;
497 }
498}
499
501{
502 m_srcCompression = srcCompression;
503}
504
505void SixLowPanHc1::SetSrcInterface (const uint8_t* srcInterface)
506{
507 for ( int i = 0; i < 8; i++)
508 {
509 m_srcInterface[i] = srcInterface[i];
510 }
511}
512
513void SixLowPanHc1::SetSrcPrefix (const uint8_t* srcPrefix)
514{
515 for ( int i = 0; i < 8; i++)
516 {
517 m_srcPrefix[i] = srcPrefix[i];
518 }
519}
520
521void SixLowPanHc1::SetTcflCompression (bool tcflCompression)
522{
523 m_tcflCompression = tcflCompression;
524}
525
526void SixLowPanHc1::SetTrafficClass (uint8_t trafficClass)
527{
528 m_trafficClass = trafficClass;
529}
530
531
532void SixLowPanHc1::SetHc2HeaderPresent (bool hc2HeaderPresent)
533{
534 m_hc2HeaderPresent = hc2HeaderPresent;
535}
536
537
538std::ostream & operator << (std::ostream & os, const SixLowPanHc1 & h)
539{
540 h.Print (os);
541 return os;
542}
543
544/*
545 * SixLowPanFrag1
546 */
547NS_OBJECT_ENSURE_REGISTERED (SixLowPanFrag1);
548
550 : m_datagramSize (0),
551 m_datagramTag (0)
552{
553}
554
556{
557 static TypeId tid = TypeId ("ns3::SixLowPanFrag1")
558 .SetParent<Header> ()
559 .SetGroupName ("SixLowPan")
560 .AddConstructor<SixLowPanFrag1> ();
561 return tid;
562}
563
565{
566 return GetTypeId ();
567}
568
569void SixLowPanFrag1::Print (std::ostream & os) const
570{
571 os << "datagram size " << m_datagramSize << " tag " << m_datagramTag;
572}
573
575{
576 return 4;
577}
578
580{
582
583 uint16_t temp = m_datagramSize | ( uint16_t (SixLowPanDispatch::LOWPAN_FRAG1) << 8 );
584
585 i.WriteU8 (uint8_t (temp >> 8));
586 i.WriteU8 (uint8_t (temp & 0xff));
587
589}
590
592{
594
595 uint8_t temp = i.ReadU8 ();
596 m_datagramSize = (uint16_t (temp) << 8) | i.ReadU8 ();
597 m_datagramSize &= 0x7FF;
598
599 m_datagramTag = i.ReadU16 ();
600 return GetSerializedSize ();
601}
602
603void SixLowPanFrag1::SetDatagramSize (uint16_t datagramSize)
604{
605 m_datagramSize = datagramSize & 0x7FF;
606}
607
609{
610 return m_datagramSize & 0x7FF;
611}
612
613void SixLowPanFrag1::SetDatagramTag (uint16_t datagramTag)
614{
615 m_datagramTag = datagramTag;
616}
617
619{
620 return m_datagramTag;
621}
622
623std::ostream & operator << (std::ostream & os, const SixLowPanFrag1 & h)
624{
625 h.Print (os);
626 return os;
627}
628
629
630/*
631 * SixLowPanFragN
632 */
633
634NS_OBJECT_ENSURE_REGISTERED (SixLowPanFragN);
635
637 : m_datagramSize (0),
638 m_datagramTag (0),
639 m_datagramOffset (0)
640{
641}
642/*
643 * SixLowPanFragmentOffset
644 */
646{
647 static TypeId tid = TypeId ("ns3::SixLowPanFragN")
648 .SetParent<Header> ()
649 .SetGroupName ("SixLowPan")
650 .AddConstructor<SixLowPanFragN> ();
651 return tid;
652}
653
655{
656 return GetTypeId ();
657}
658
659void SixLowPanFragN::Print (std::ostream & os) const
660{
661 os << "datagram size " << m_datagramSize << " tag " << m_datagramTag << " offset " << +m_datagramOffset;
662}
663
665{
666 return 5;
667}
668
670{
672
673 uint16_t temp = m_datagramSize | ( uint16_t (SixLowPanDispatch::LOWPAN_FRAGN) << 8 );
674
675 i.WriteU8 (uint8_t (temp >> 8));
676 i.WriteU8 (uint8_t (temp & 0xff));
677
680}
681
683{
685
686 uint8_t temp = i.ReadU8 ();
687 m_datagramSize = (uint16_t (temp) << 8) | i.ReadU8 ();
688 m_datagramSize &= 0x7FF;
689
690 m_datagramTag = i.ReadU16 ();
692
693 return GetSerializedSize ();
694}
695
696void SixLowPanFragN::SetDatagramSize (uint16_t datagramSize)
697{
698 m_datagramSize = datagramSize & 0x7FF;
699}
700
702{
703 return m_datagramSize & 0x7FF;
704}
705
706void SixLowPanFragN::SetDatagramTag (uint16_t datagramTag)
707{
708 m_datagramTag = datagramTag;
709}
710
712{
713 return m_datagramTag;
714}
715
716void SixLowPanFragN::SetDatagramOffset (uint8_t datagramOffset)
717{
718 m_datagramOffset = datagramOffset;
719}
720
722{
723 return m_datagramOffset;
724}
725
726std::ostream & operator << (std::ostream & os, const SixLowPanFragN & h)
727{
728 h.Print (os);
729 return os;
730}
731
732/*
733 * SixLowPanIpv6
734 */
735
736NS_OBJECT_ENSURE_REGISTERED (SixLowPanIpv6);
737
739{
740}
741
743{
744 static TypeId tid = TypeId ("ns3::SixLowPanIpv6")
745 .SetParent<Header> ()
746 .SetGroupName ("SixLowPan")
747 .AddConstructor<SixLowPanIpv6> ();
748 return tid;
749}
750
752{
753 return GetTypeId ();
754}
755
756void SixLowPanIpv6::Print (std::ostream & os) const
757{
758 os << "Uncompressed IPv6";
759}
760
762{
763 return 1;
764}
765
767{
769
771}
772
774{
776 i.ReadU8 ();
777
778 return GetSerializedSize ();
779}
780
781std::ostream & operator << (std::ostream & os, const SixLowPanIpv6 & h)
782{
783 h.Print (os);
784 return os;
785}
786
787/*
788 * SixLowPanIphcHeader
789 */
790NS_OBJECT_ENSURE_REGISTERED (SixLowPanIphc);
791
793{
794 // 011x xxxx xxxx xxxx
795 m_baseFormat = 0x6000;
797}
798
800{
801 // 011x xxxx xxxx xxxx
802 m_baseFormat = dispatch;
803 m_baseFormat <<= 8;
805}
806
808{
809 static TypeId tid = TypeId ("ns3::SixLowPanIphc")
810 .SetParent<Header> ()
811 .SetGroupName ("SixLowPan")
812 .AddConstructor<SixLowPanIphc> ();
813 return tid;
814}
815
817{
818 return GetTypeId ();
819}
820
821void SixLowPanIphc::Print (std::ostream & os) const
822{
823 switch ( GetTf () )
824 {
825 case TF_FULL:
826 os << "TF_FULL(" << +m_ecn << ", " << +m_dscp << ", " << m_flowLabel << ")";
827 break;
828 case TF_DSCP_ELIDED:
829 os << "TF_DSCP_ELIDED(" << +m_ecn << ", " << m_flowLabel << ")";
830 break;
831 case TF_FL_ELIDED:
832 os << "TF_FL_ELIDED(" << +m_ecn << ", " << +m_dscp << ")";
833 break;
834 default:
835 os << "TF_ELIDED";
836 break;
837 }
838
839 GetNh () ? os << " NH(1)" : os << " NH(0)";
840
841 switch ( GetHlim () )
842 {
843 case HLIM_INLINE:
844 os << " HLIM_INLINE(" << +m_hopLimit << ")";
845 break;
846 case HLIM_COMPR_1:
847 os << " HLIM_COMPR_1(1)";
848 break;
849 case HLIM_COMPR_64:
850 os << " HLIM_COMPR_64(64)";
851 break;
852 default:
853 os << " HLIM_COMPR_255(255)";
854 break;
855 }
856
857 GetCid () ? os << " CID(" << +m_srcdstContextId << ")" : os << " CID(0)";
858
859 GetSac () ? os << " SAC(1)" : os << " SAC(0)";
860 os << " SAM (" << GetSam () << ")";
861
862 GetM () ? os << " M(1)" : os << " M(0)";
863 GetDac () ? os << " DAC(1)" : os << " DAC(0)";
864 os << " DAM (" << GetDam () << ")";
865}
866
868{
869 uint32_t serializedSize = 2;
870
871 if ( GetCid () )
872 {
873 serializedSize++;
874 }
875 switch ( GetTf () )
876 {
877 case TF_FULL:
878 serializedSize += 4;
879 break;
880 case TF_DSCP_ELIDED:
881 serializedSize += 3;
882 break;
883 case TF_FL_ELIDED:
884 serializedSize++;
885 break;
886 default:
887 break;
888 }
889 if ( GetNh () == false )
890 {
891 serializedSize++;
892 }
893 if ( GetHlim () == HLIM_INLINE)
894 {
895 serializedSize++;
896 }
897 switch (GetSam () )
898 {
899 case HC_INLINE:
900 if ( GetSac () == false )
901 {
902 serializedSize += 16;
903 }
904 break;
905 case HC_COMPR_64:
906 serializedSize += 8;
907 break;
908 case HC_COMPR_16:
909 serializedSize += 2;
910 break;
911 case HC_COMPR_0:
912 default:
913 break;
914 }
915 if ( GetM () == false)
916 {
917 switch (GetDam () )
918 {
919 case HC_INLINE:
920 if ( GetDac () == false )
921 {
922 serializedSize += 16;
923 }
924 break;
925 case HC_COMPR_64:
926 serializedSize += 8;
927 break;
928 case HC_COMPR_16:
929 serializedSize += 2;
930 break;
931 case HC_COMPR_0:
932 default:
933 break;
934 }
935 }
936 else
937 {
938 switch (GetDam () )
939 {
940 case HC_INLINE:
941 if ( GetDac () == false )
942 {
943 serializedSize += 16;
944 }
945 else
946 {
947 serializedSize += 6;
948 }
949 break;
950 case HC_COMPR_64:
951 if ( GetDac () == false )
952 {
953 serializedSize += 6;
954 }
955 break;
956 case HC_COMPR_16:
957 if ( GetDac () == false )
958 {
959 serializedSize += 4;
960 }
961 break;
962 case HC_COMPR_0:
963 default:
964 if ( GetDac () == false )
965 {
966 serializedSize++;
967 }
968 break;
969 }
970 }
971
972
973
974 return serializedSize;
975}
976
978{
980
982
983 if ( GetCid () )
984 {
986 }
987 // Traffic Class and Flow Label
988 switch ( GetTf () )
989 {
990 uint8_t temp;
991 case TF_FULL:
992 temp = (m_ecn << 6) | m_dscp;
993 i.WriteU8 (temp);
994 temp = m_flowLabel >> 16;
995 i.WriteU8 (temp);
996 temp = (m_flowLabel >> 8) & 0xff;
997 i.WriteU8 (temp);
998 temp = m_flowLabel & 0xff;
999 i.WriteU8 (temp);
1000 break;
1001 case TF_DSCP_ELIDED:
1002 temp = (m_ecn << 6) | (m_flowLabel >> 16 );
1003 i.WriteU8 (temp);
1004 temp = (m_flowLabel >> 8) & 0xff;
1005 i.WriteU8 (temp);
1006 temp = m_flowLabel & 0xff;
1007 i.WriteU8 (temp);
1008 break;
1009 case TF_FL_ELIDED:
1010 temp = (m_ecn << 6) | m_dscp;
1011 i.WriteU8 (temp);
1012 break;
1013 default:
1014 break;
1015 }
1016 // Next Header
1017 if ( GetNh () == false )
1018 {
1020 }
1021 // Hop Limit
1022 if ( GetHlim () == HLIM_INLINE )
1023 {
1024 i.WriteU8 (m_hopLimit);
1025 }
1026 // Source Address
1027 switch (GetSam () )
1028 {
1029 case HC_INLINE:
1030 if ( GetSac () == false )
1031 {
1032 i.Write (m_srcInlinePart, 16);
1033 }
1034 break;
1035 case HC_COMPR_64:
1036 i.Write (m_srcInlinePart, 8);
1037 break;
1038 case HC_COMPR_16:
1039 i.Write (m_srcInlinePart, 2);
1040 break;
1041 case HC_COMPR_0:
1042 default:
1043 break;
1044 }
1045 // Destination Address
1046 if ( GetM () == false)
1047 {
1048 // unicast
1049 switch (GetDam () )
1050 {
1051 case HC_INLINE:
1052 i.Write (m_dstInlinePart, 16);
1053 break;
1054 case HC_COMPR_64:
1055 i.Write (m_dstInlinePart, 8);
1056 break;
1057 case HC_COMPR_16:
1058 i.Write (m_dstInlinePart, 2);
1059 break;
1060 case HC_COMPR_0:
1061 default:
1062 break;
1063 }
1064 }
1065 else
1066 {
1067 // multicast
1068 switch (GetDam () )
1069 {
1070 case HC_INLINE:
1071 i.Write (m_dstInlinePart, 16);
1072 break;
1073 case HC_COMPR_64:
1074 i.Write (m_dstInlinePart, 6);
1075 break;
1076 case HC_COMPR_16:
1077 i.Write (m_dstInlinePart, 4);
1078 break;
1079 case HC_COMPR_0:
1080 i.Write (m_dstInlinePart, 1);
1081 break;
1082 default:
1083 break;
1084 }
1085 }
1086}
1087
1089{
1091
1093
1094 if ( GetCid () )
1095 {
1097 }
1098 else
1099 {
1101 }
1102 // Traffic Class and Flow Label
1103 switch ( GetTf () )
1104 {
1105 uint8_t temp;
1106 case TF_FULL:
1107 temp = i.ReadU8 ();
1108 m_ecn = temp >> 6;
1109 m_dscp = temp & 0x3F;
1110 temp = i.ReadU8 ();
1111 m_flowLabel = temp;
1112 temp = i.ReadU8 ();
1113 m_flowLabel = (m_flowLabel << 8) | temp;
1114 temp = i.ReadU8 ();
1115 m_flowLabel = (m_flowLabel << 8) | temp;
1116 break;
1117 case TF_DSCP_ELIDED:
1118 temp = i.ReadU8 ();
1119 m_ecn = temp >> 6;
1120 m_flowLabel = temp & 0x3F;
1121 temp = i.ReadU8 ();
1122 m_flowLabel = (m_flowLabel << 8) | temp;
1123 temp = i.ReadU8 ();
1124 m_flowLabel = (m_flowLabel << 8) | temp;
1125 break;
1126 case TF_FL_ELIDED:
1127 temp = i.ReadU8 ();
1128 m_ecn = temp >> 6;
1129 m_dscp = temp & 0x3F;
1130 break;
1131 default:
1132 break;
1133 }
1134 // Next Header
1135 if ( GetNh () == false )
1136 {
1137 m_nextHeader = i.ReadU8 ();
1138 }
1139 // Hop Limit
1140 switch ( GetHlim () )
1141 {
1142 case HLIM_INLINE:
1143 m_hopLimit = i.ReadU8 ();
1144 break;
1145 case HLIM_COMPR_1:
1146 m_hopLimit = 1;
1147 break;
1148 case HLIM_COMPR_64:
1149 m_hopLimit = 64;
1150 break;
1151 case HLIM_COMPR_255:
1152 default:
1153 m_hopLimit = 255;
1154 break;
1155
1156 }
1157 // Source Address
1158 memset (m_srcInlinePart, 0x00, sizeof (m_srcInlinePart));
1159 switch (GetSam () )
1160 {
1161 case HC_INLINE:
1162 if ( GetSac () == false )
1163 {
1164 i.Read (m_srcInlinePart, 16);
1165 }
1166 break;
1167 case HC_COMPR_64:
1168 i.Read (m_srcInlinePart, 8);
1169 break;
1170 case HC_COMPR_16:
1171 i.Read (m_srcInlinePart, 2);
1172 break;
1173 case HC_COMPR_0:
1174 default:
1175 break;
1176 }
1177
1178 // Destination Address
1179 memset (m_dstInlinePart, 0x00, sizeof (m_dstInlinePart));
1180 if ( GetM () == false)
1181 {
1182 // unicast
1183 switch (GetDam () )
1184 {
1185 case HC_INLINE:
1186 i.Read (m_dstInlinePart, 16);
1187 break;
1188 case HC_COMPR_64:
1189 i.Read (m_dstInlinePart, 8);
1190 break;
1191 case HC_COMPR_16:
1192 i.Read (m_dstInlinePart, 2);
1193 break;
1194 case HC_COMPR_0:
1195 default:
1196 break;
1197 }
1198 }
1199 else
1200 {
1201 // multicast
1202 switch (GetDam () )
1203 {
1204 case HC_INLINE:
1205 i.Read (m_dstInlinePart, 16);
1206 break;
1207 case HC_COMPR_64:
1208 i.Read (m_dstInlinePart, 6);
1209 break;
1210 case HC_COMPR_16:
1211 i.Read (m_dstInlinePart, 4);
1212 break;
1213 case HC_COMPR_0:
1214 i.Read (m_dstInlinePart, 1);
1215 break;
1216 default:
1217 break;
1218 }
1219 }
1220
1221 return GetSerializedSize ();
1222}
1223
1225{
1226 uint16_t field = tfField;
1227 m_baseFormat |= (field << 11);
1228}
1229
1231{
1232 return TrafficClassFlowLabel_e ((m_baseFormat >> 11) & 0x3);
1233}
1234
1235void SixLowPanIphc::SetNh (bool nhField)
1236{
1237 uint16_t field = nhField;
1238 m_baseFormat |= (field << 10);
1239}
1240
1241bool SixLowPanIphc::GetNh (void) const
1242{
1243 return ((m_baseFormat >> 10) & 0x1);
1244}
1245
1247{
1248 uint16_t field = hlimField;
1249 m_baseFormat |= (field << 8);
1250}
1251
1253{
1254 return Hlim_e ((m_baseFormat >> 8) & 0x3);
1255}
1256
1257void SixLowPanIphc::SetCid (bool cidField)
1258{
1259 uint16_t field = cidField;
1260 m_baseFormat |= (field << 7);
1261}
1262
1263bool SixLowPanIphc::GetCid (void) const
1264{
1265 return ((m_baseFormat >> 7) & 0x1);
1266}
1267
1268void SixLowPanIphc::SetSac (bool sacField)
1269{
1270 uint16_t field = sacField;
1271 m_baseFormat |= (field << 6);
1272}
1273
1274bool SixLowPanIphc::GetSac (void) const
1275{
1276 return ((m_baseFormat >> 6) & 0x1);
1277}
1278
1280{
1281 uint16_t field = samField;
1282 m_baseFormat |= (field << 4);
1283}
1284
1286{
1287 return HeaderCompression_e ((m_baseFormat >> 4) & 0x3);
1288}
1289
1290const uint8_t* SixLowPanIphc::GetSrcInlinePart (void) const
1291{
1292 return m_srcInlinePart;
1293}
1294
1295void SixLowPanIphc::SetSrcInlinePart (uint8_t srcInlinePart[16], uint8_t size)
1296{
1297 NS_ASSERT_MSG (size <= 16, "Src inline part too large");
1298
1299 memcpy (m_srcInlinePart, srcInlinePart, size);
1300 return;
1301}
1302
1303void SixLowPanIphc::SetM (bool mField)
1304{
1305 uint16_t field = mField;
1306 m_baseFormat |= (field << 3);
1307}
1308
1309bool SixLowPanIphc::GetM (void) const
1310{
1311 return ((m_baseFormat >> 3) & 0x1);
1312}
1313
1314void SixLowPanIphc::SetDac (bool dacField)
1315{
1316 uint16_t field = dacField;
1317 m_baseFormat |= (field << 2);
1318}
1319
1320bool SixLowPanIphc::GetDac (void) const
1321{
1322 return ((m_baseFormat >> 2) & 0x1);
1323}
1324
1326{
1327 uint16_t field = damField;
1328 m_baseFormat |= field;
1329}
1330
1332{
1333 return HeaderCompression_e (m_baseFormat & 0x3);
1334}
1335
1336const uint8_t* SixLowPanIphc::GetDstInlinePart (void) const
1337{
1338 return m_dstInlinePart;
1339}
1340
1341void SixLowPanIphc::SetDstInlinePart (uint8_t dstInlinePart[16], uint8_t size)
1342{
1343 NS_ASSERT_MSG (size <= 16, "Dst inline part too large");
1344
1345 memcpy (m_dstInlinePart, dstInlinePart, size);
1346 return;
1347}
1348
1349void SixLowPanIphc::SetSrcContextId (uint8_t srcContextId)
1350{
1351 NS_ASSERT_MSG (srcContextId < 16, "Src Context ID too large");
1352 m_srcdstContextId |= srcContextId << 4;
1353}
1354
1356{
1357 return ( m_srcdstContextId >> 4);
1358}
1359
1360void SixLowPanIphc::SetDstContextId (uint8_t dstContextId)
1361{
1362 NS_ASSERT_MSG (dstContextId < 16, "Dst Context ID too large");
1363 m_srcdstContextId |= (dstContextId & 0xF);
1364}
1365
1367{
1368 return (m_srcdstContextId & 0xF);
1369}
1370
1371void SixLowPanIphc::SetEcn (uint8_t ecn)
1372{
1373 NS_ASSERT_MSG (ecn < 4, "ECN too large");
1374 m_ecn = ecn;
1375}
1376
1377uint8_t SixLowPanIphc::GetEcn (void) const
1378{
1379 return m_ecn;
1380}
1381
1382void SixLowPanIphc::SetDscp (uint8_t dscp)
1383{
1384 NS_ASSERT_MSG (dscp < 64, "DSCP too large");
1385 m_dscp = dscp;
1386}
1387
1388uint8_t SixLowPanIphc::GetDscp (void) const
1389{
1390 return m_dscp;
1391}
1392
1394{
1395 NS_ASSERT_MSG (flowLabel < 0x100000, "Flow Label too large");
1396 m_flowLabel = flowLabel;
1397}
1398
1400{
1401 return m_flowLabel;
1402}
1403
1404void SixLowPanIphc::SetNextHeader (uint8_t nextHeader)
1405{
1406 m_nextHeader = nextHeader;
1407}
1408
1410{
1411 return m_nextHeader;
1412}
1413
1414void SixLowPanIphc::SetHopLimit (uint8_t hopLimit)
1415{
1416 m_hopLimit = hopLimit;
1417}
1418
1419uint8_t SixLowPanIphc::GetHopLimit (void) const
1420{
1421 return m_hopLimit;
1422}
1423
1424std::ostream & operator << (std::ostream & os, const SixLowPanIphc & h)
1425{
1426 h.Print (os);
1427 return os;
1428}
1429
1430/*
1431 * SixLowPanNhcExtensionHeader
1432 */
1433NS_OBJECT_ENSURE_REGISTERED (SixLowPanNhcExtension);
1434
1436{
1437 // 1110 xxxx
1438 m_nhcExtensionHeader = 0xE0;
1439 m_nhcNextHeader = 0;
1440 m_nhcBlobLength = 0;
1441}
1442
1444{
1445 static TypeId tid = TypeId ("ns3::SixLowPanNhcExtension")
1446 .SetParent<Header> ()
1447 .SetGroupName ("SixLowPan")
1448 .AddConstructor<SixLowPanNhcExtension> ();
1449 return tid;
1450}
1451
1453{
1454 return GetTypeId ();
1455}
1456
1457void SixLowPanNhcExtension::Print (std::ostream & os) const
1458{
1459 os << "Compression kind: " << +m_nhcExtensionHeader << " Size: " << GetSerializedSize ();
1460}
1461
1463{
1464 uint32_t serializedSize = 2;
1465 if ( GetNh () == false )
1466 {
1467 serializedSize++;
1468 }
1469 return serializedSize + m_nhcBlobLength;
1470}
1471
1473{
1476 if ( GetNh () == false )
1477 {
1479 }
1482}
1483
1485{
1488 if ( GetNh () == false )
1489 {
1490 m_nhcNextHeader = i.ReadU8 ();
1491 }
1492 m_nhcBlobLength = i.ReadU8 ();
1494
1495 return GetSerializedSize ();
1496}
1497
1500{
1502}
1503
1504void SixLowPanNhcExtension::SetEid (Eid_e extensionHeaderType)
1505{
1506 uint8_t field = extensionHeaderType;
1507 m_nhcExtensionHeader |= (field << 1);
1508}
1509
1511{
1512 return Eid_e ((m_nhcExtensionHeader >> 1) & 0x7);
1513}
1514
1516{
1517 m_nhcNextHeader = nextHeader;
1518}
1519
1521{
1522 return m_nhcNextHeader;
1523}
1524
1526{
1527 uint8_t field = nhField;
1528 m_nhcExtensionHeader |= field;
1529}
1530
1532{
1533 return m_nhcExtensionHeader & 0x01;
1534}
1535
1536void SixLowPanNhcExtension::SetBlob (const uint8_t* blob, uint32_t size)
1537{
1538 NS_ASSERT_MSG ( size < 255, "Buffer too long" );
1539
1540 m_nhcBlobLength = size;
1541 std::memcpy (m_nhcBlob, blob, size);
1542}
1543
1545{
1546 NS_ASSERT_MSG ( size > m_nhcBlobLength, "Buffer too short" );
1547
1548 std::memcpy (blob, m_nhcBlob, m_nhcBlobLength);
1549 return m_nhcBlobLength;
1550}
1551
1552std::ostream & operator << (std::ostream & os, const SixLowPanNhcExtension & h)
1553{
1554 h.Print (os);
1555 return os;
1556}
1557
1558/*
1559 * SixLowPanUdpNhcExtension
1560 */
1561NS_OBJECT_ENSURE_REGISTERED (SixLowPanUdpNhcExtension);
1562
1564{
1565 // 1111 0xxx
1566 m_baseFormat = 0xF0;
1567 m_checksum = 0;
1568 m_srcPort = 0;
1569 m_dstPort = 0;
1570}
1571
1573{
1574 static TypeId tid = TypeId ("ns3::SixLowPanUdpNhcExtension")
1575 .SetParent<Header> ()
1576 .SetGroupName ("SixLowPan")
1577 .AddConstructor<SixLowPanUdpNhcExtension> ();
1578 return tid;
1579}
1580
1582{
1583 return GetTypeId ();
1584}
1585
1586void SixLowPanUdpNhcExtension::Print (std::ostream & os) const
1587{
1588 os << "Compression kind: " << +m_baseFormat;
1589}
1590
1592{
1593 uint32_t serializedSize = 1;
1594 if ( !GetC () )
1595 {
1596 serializedSize += 2;
1597 }
1598 switch (GetPorts ())
1599 {
1600 case PORTS_INLINE:
1601 serializedSize += 4;
1602 break;
1605 serializedSize += 3;
1606 break;
1608 serializedSize += 1;
1609 break;
1610 default:
1611 break;
1612 }
1613 return serializedSize;
1614}
1615
1617{
1620 uint8_t temp;
1621
1622 // Ports
1623 switch ( GetPorts () )
1624 {
1625 case PORTS_INLINE:
1628 break;
1631 i.WriteU8 (m_dstPort & 0xff);
1632 break;
1634 i.WriteU8 (m_srcPort & 0xff);
1636 break;
1638 temp = ((m_srcPort & 0xf) << 4) | (m_dstPort & 0xf);
1639 i.WriteU8 (temp);
1640 break;
1641 default:
1642 break;
1643 }
1644
1645 // Checksum
1646 if ( !GetC () )
1647 {
1648 i.WriteU16 (m_checksum);
1649 }
1650
1651}
1652
1654{
1656 m_baseFormat = i.ReadU8 ();
1657 uint8_t temp;
1658
1659 // Ports
1660 switch ( GetPorts () )
1661 {
1662 case PORTS_INLINE:
1663 m_srcPort = i.ReadNtohU16 ();
1664 m_dstPort = i.ReadNtohU16 ();
1665 break;
1667 m_srcPort = i.ReadNtohU16 ();
1668 m_dstPort = i.ReadU8 ();
1669 break;
1671 m_srcPort = i.ReadU8 ();
1672 m_dstPort = i.ReadNtohU16 ();
1673 break;
1675 temp = i.ReadU8 ();
1676 m_srcPort = temp >> 4;
1677 m_dstPort = temp & 0xf;
1678 break;
1679 default:
1680 break;
1681 }
1682
1683 // Checksum
1684 if ( !GetC () )
1685 {
1686 m_checksum = i.ReadU16 ();
1687 }
1688
1689 return GetSerializedSize ();
1690}
1691
1694{
1696}
1697
1699{
1700 uint16_t field = ports;
1701 m_baseFormat |= field;
1702}
1703
1705{
1706 return Ports_e (m_baseFormat & 0x3);
1707}
1708
1710{
1711 m_srcPort = srcport;
1712}
1713
1715{
1716 return m_srcPort;
1717}
1718
1720{
1721 m_dstPort = dstport;
1722}
1723
1725{
1726 return m_dstPort;
1727}
1728
1730{
1731 uint16_t field = cField;
1732 m_baseFormat |= (field << 2);
1733}
1734
1736{
1737 return ((m_baseFormat >> 2) & 0x1);
1738}
1739
1741{
1742 m_checksum = checksum;
1743}
1744
1746{
1747 return m_checksum;
1748}
1749
1750std::ostream & operator << (std::ostream & os, const SixLowPanUdpNhcExtension & h)
1751{
1752 h.Print (os);
1753 return os;
1754}
1755
1756/*
1757 * SixLowPanBc0
1758 */
1759NS_OBJECT_ENSURE_REGISTERED (SixLowPanBc0);
1760
1762{
1763 m_seqNumber = 66;
1764}
1765
1767{
1768 static TypeId tid = TypeId ("ns3::SixLowPanBc0")
1769 .SetParent<Header> ()
1770 .SetGroupName ("SixLowPan")
1771 .AddConstructor<SixLowPanBc0> ();
1772 return tid;
1773}
1774
1776{
1777 return GetTypeId ();
1778}
1779
1780void SixLowPanBc0::Print (std::ostream & os) const
1781{
1782 os << "Sequence number: " << +m_seqNumber;
1783}
1784
1786{
1787 return 2;
1788}
1789
1791{
1793 i.WriteU8 (0x50);
1794 i.WriteU8 (m_seqNumber);
1795
1796}
1797
1799{
1801 uint8_t dispatch = i.ReadU8 ();
1802
1803 if (dispatch != 0x50)
1804 {
1805 return 0;
1806 }
1807
1808 m_seqNumber = i.ReadU8 ();
1809
1810 return GetSerializedSize ();
1811}
1812
1813void SixLowPanBc0::SetSequenceNumber (uint8_t seqNumber)
1814{
1815 m_seqNumber = seqNumber;
1816}
1817
1819{
1820 return m_seqNumber;
1821}
1822
1823std::ostream & operator << (std::ostream & os, const SixLowPanBc0 & h)
1824{
1825 h.Print (os);
1826 return os;
1827}
1828
1829/*
1830 * SixLowPanMesh
1831 */
1832NS_OBJECT_ENSURE_REGISTERED (SixLowPanMesh);
1833
1835{
1836 m_hopsLeft = 0;
1837 m_src = Address ();
1838 m_dst = Address ();
1839 m_v = false;
1840 m_f = false;
1841}
1842
1844{
1845 static TypeId tid = TypeId ("ns3::SixLowPanMesh")
1846 .SetParent<Header> ()
1847 .SetGroupName ("SixLowPan")
1848 .AddConstructor<SixLowPanMesh> ();
1849 return tid;
1850}
1851
1853{
1854 return GetTypeId ();
1855}
1856
1857void SixLowPanMesh::Print (std::ostream & os) const
1858{
1859 os << "Hops left: " << +m_hopsLeft << ", src: ";
1861 {
1863 }
1864 else
1865 {
1867 }
1868 os << ", dst: ";
1870 {
1872 }
1873 else
1874 {
1876 }
1877}
1878
1880{
1881 uint32_t serializedSize = 1;
1882
1883 if (m_hopsLeft >= 0xF)
1884 {
1885 serializedSize++;
1886 }
1887
1888 if (m_v)
1889 {
1890 serializedSize += 2;
1891 }
1892 else
1893 {
1894 serializedSize += 8;
1895 }
1896
1897 if (m_f)
1898 {
1899 serializedSize += 2;
1900 }
1901 else
1902 {
1903 serializedSize += 8;
1904 }
1905
1906 return serializedSize;
1907}
1908
1910{
1912
1913 uint8_t dispatch = 0x80;
1914
1915 if (m_v)
1916 {
1917 dispatch |= 0x20;
1918 }
1919 if (m_f)
1920 {
1921 dispatch |= 0x10;
1922 }
1923
1924 if (m_hopsLeft < 0xF)
1925 {
1926 dispatch |= m_hopsLeft;
1927 i.WriteU8 (dispatch);
1928 }
1929 else
1930 {
1931 dispatch |= 0xF;
1932 i.WriteU8 (dispatch);
1933 i.WriteU8 (m_hopsLeft);
1934 }
1935
1936 uint8_t buffer[8];
1937
1938 m_src.CopyTo (buffer);
1939 if (m_v)
1940 {
1941 i.Write (buffer, 2);
1942 }
1943 else
1944 {
1945 i.Write (buffer, 8);
1946 }
1947
1948 m_dst.CopyTo (buffer);
1949 if (m_f)
1950 {
1951 i.Write (buffer, 2);
1952 }
1953 else
1954 {
1955 i.Write (buffer, 8);
1956 }
1957}
1958
1960{
1962 uint8_t temp = i.ReadU8 ();
1963
1964 if ((temp & 0xC0) != 0x80)
1965 {
1966 return 0;
1967 }
1968
1969 m_v = temp & 0x20;
1970 m_f = temp & 0x10;
1971 m_hopsLeft = temp & 0xF;
1972
1973 if (m_hopsLeft == 0xF)
1974 {
1975 m_hopsLeft = i.ReadU8 ();
1976 }
1977
1978 uint8_t buffer[8];
1979 uint8_t addrSize;
1980
1981 if (m_v)
1982 {
1983 addrSize = 2;
1984 }
1985 else
1986 {
1987 addrSize = 8;
1988 }
1989 i.Read (buffer, addrSize);
1990 m_src.CopyFrom (buffer, addrSize);
1991
1992 if (m_f)
1993 {
1994 addrSize = 2;
1995 }
1996 else
1997 {
1998 addrSize = 8;
1999 }
2000 i.Read (buffer, addrSize);
2001 m_dst.CopyFrom (buffer, addrSize);
2002
2003 return GetSerializedSize ();
2004}
2005
2007{
2008 if (Mac64Address::IsMatchingType (originator))
2009 {
2010 m_v = false;
2011 }
2012 else if (Mac16Address::IsMatchingType (originator))
2013 {
2014 m_v = true;
2015 }
2016 else
2017 {
2018 NS_ABORT_MSG ("SixLowPanMesh::SetOriginator - incompatible address");
2019 }
2020
2021 m_src = originator;
2022}
2023
2025{
2026 return m_src;
2027}
2028
2030{
2031 if (Mac64Address::IsMatchingType (finalDst))
2032 {
2033 m_f = false;
2034 }
2035 else if (Mac16Address::IsMatchingType (finalDst))
2036 {
2037 m_f = true;
2038 }
2039 else
2040 {
2041 NS_ABORT_MSG ("SixLowPanMesh::SetFinalDst - incompatible address");
2042 }
2043
2044 m_dst = finalDst;
2045}
2046
2048{
2049 return m_dst;
2050}
2051
2052void SixLowPanMesh::SetHopsLeft (uint8_t hopsLeft)
2053{
2054 m_hopsLeft = hopsLeft;
2055}
2056
2057uint8_t SixLowPanMesh::GetHopsLeft (void) const
2058{
2059 return m_hopsLeft;
2060}
2061
2062std::ostream & operator << (std::ostream & os, const SixLowPanMesh & h)
2063{
2064 h.Print (os);
2065 return os;
2066}
2067
2068}
2069
a polymophic address class
Definition: address.h:91
uint32_t CopyFrom(const uint8_t *buffer, uint8_t len)
Definition: address.cc:101
uint32_t CopyTo(uint8_t buffer[MAX_SIZE]) const
Copy the address bytes into a buffer.
Definition: address.cc:82
iterator in a Buffer instance
Definition: buffer.h:99
void Write(uint8_t const *buffer, uint32_t size)
Definition: buffer.cc:954
uint16_t ReadNtohU16(void)
Definition: buffer.h:946
void WriteU8(uint8_t data)
Definition: buffer.h:869
void WriteU16(uint16_t data)
Definition: buffer.cc:871
uint16_t ReadU16(void)
Definition: buffer.h:1029
uint8_t ReadU8(void)
Definition: buffer.h:1021
void Read(uint8_t *buffer, uint32_t size)
Definition: buffer.cc:1124
void WriteHtonU16(uint16_t data)
Definition: buffer.h:905
Protocol header serialization and deserialization.
Definition: header.h:43
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.
virtual void Print(std::ostream &os) const
virtual uint32_t GetSerializedSize(void) const
Get the serialized size of the packet.
static TypeId GetTypeId(void)
Get the type ID.
uint8_t GetSequenceNumber(void) const
Get the "Sequence Number" field.
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
void SetSequenceNumber(uint8_t seqNumber)
Set the "Sequence Number" field.
virtual TypeId GetInstanceTypeId(void) const
Return the instance type identifier.
uint8_t m_seqNumber
Sequence number.
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
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.
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
void SetDatagramSize(uint16_t datagramSize)
Set the datagram size.
void SetDatagramTag(uint16_t datagramTag)
Set the datagram tag.
virtual uint32_t GetSerializedSize(void) const
Get the serialized size of the packet.
virtual void Print(std::ostream &os) const
virtual TypeId GetInstanceTypeId(void) const
Return the instance type identifier.
uint16_t GetDatagramSize(void) const
Get the datagram size.
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
uint16_t GetDatagramTag(void) const
Get the datagram tag.
static TypeId GetTypeId(void)
Get the type ID.
uint16_t m_datagramTag
Datagram tag.
uint16_t m_datagramSize
Datagram size.
6LoWPAN FRAGN header - see RFC 4944.
static TypeId GetTypeId(void)
Get the type ID.
uint16_t GetDatagramTag(void) const
Get the datagram tag.
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
uint8_t GetDatagramOffset(void) const
Get the datagram offset.
uint16_t m_datagramTag
Datagram tag.
void SetDatagramSize(uint16_t datagramSize)
Set the datagram size.
uint16_t GetDatagramSize(void) const
Get the datagram size.
void SetDatagramTag(uint16_t datagramTag)
Set the datagram tag.
virtual void Print(std::ostream &os) const
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
void SetDatagramOffset(uint8_t datagramOffset)
Set the datagram offset.
uint8_t m_datagramOffset
Datagram offset.
uint16_t m_datagramSize
Datagram size.
virtual uint32_t GetSerializedSize(void) const
Get the serialized size of the packet.
virtual TypeId GetInstanceTypeId(void) const
Return the instance type identifier.
6LoWPAN HC1 header - see RFC 4944.
void SetTcflCompression(bool tcflCompression)
Set the Traffic Class and Flow Labels as compressed.
uint8_t m_dstInterface[8]
Destination interface.
const uint8_t * GetSrcPrefix() const
Get the source prefix.
void SetFlowLabel(uint32_t flowLabel)
Set the Flow Label value.
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
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.
virtual uint32_t GetSerializedSize(void) const
Get the serialized size of the packet.
void SetHopLimit(uint8_t limit)
Set the "Hop limit" field (TTL).
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
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.
bool m_hc2HeaderPresent
Is next header HC2 compressed.
uint8_t GetHopLimit(void) const
Get the "Hop limit" field (TTL).
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.
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.
uint8_t m_hopLimit
Hop Limit.
void SetSrcCompression(LowPanHc1Addr_e srcCompression)
Set Source Compression type.
uint8_t m_srcPrefix[8]
Source prefix.
virtual void Print(std::ostream &os) const
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.
virtual TypeId GetInstanceTypeId(void) const
Return the instance type identifier.
LowPanHc1Addr_e m_srcCompression
Source compression type.
uint8_t m_nextHeader
Next header.
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.
static TypeId GetTypeId(void)
Get the type ID.
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.
void SetNextHeader(uint8_t nextHeader)
Set the Next Header field.
bool GetM(void) const
Get the M (Multicast) compression.
void SetHlim(Hlim_e hlimField)
Set the HLIM (Hop Limit) compression.
bool GetSac(void) const
Get the SAC (Source Address Compression) compression.
void SetDstContextId(uint8_t dstContextId)
Set the DstContextId.
Hlim_e
HLIM: Hop Limit.
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.
HeaderCompression_e
Source or Destination Address Mode.
virtual uint32_t GetSerializedSize(void) const
Get the serialized size of the packet.
uint8_t m_srcInlinePart[16]
source address inline part.
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
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).
TrafficClassFlowLabel_e GetTf(void) const
Get the TF (Traffic Class, Flow Label) compression.
bool GetDac(void) const
Get the DAC (Destination Address Compression) compression.
void SetDscp(uint8_t dscp)
Set the DSCP (6bits).
uint8_t GetDstContextId(void) const
Get the DstContextId.
void SetTf(TrafficClassFlowLabel_e tfField)
Set the TF (Traffic Class, Flow Label) compression.
const uint8_t * GetDstInlinePart(void) const
brief Get the destination address inline part
bool GetCid(void) const
Get the CID (Context Identifier Extension) compression.
void SetDam(HeaderCompression_e damField)
Set the DAM (Destination Address Mode) compression.
void SetCid(bool cidField)
Set the CID (Context Identifier Extension) compression.
uint8_t GetEcn(void) const
Get the ECN.
HeaderCompression_e GetSam(void) const
Get the SAM (Source Address Mode) compression.
uint8_t m_dscp
DSCP bits.
uint8_t GetHopLimit(void) const
Get the Hop Limit field.
bool GetNh(void) const
Get the NH (Next Header) compression.
void SetSac(bool sacField)
Set the SAC (Source Address Compression) compression.
HeaderCompression_e GetDam(void) const
Get the DAM (Destination Address Mode) compression.
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
uint8_t m_dstInlinePart[16]
destination address inline part.
const uint8_t * GetSrcInlinePart(void) const
brief Get the source address inline part
void SetDstInlinePart(uint8_t dstInlinePart[16], uint8_t size)
brief Set the destination address inline part
uint8_t GetSrcContextId(void) const
Get the SrcContextId.
void SetSrcContextId(uint8_t srcContextId)
Set the SrcContextId.
void SetSrcInlinePart(uint8_t srcInlinePart[16], uint8_t size)
brief Set the source address inline part
uint8_t GetDscp(void) const
Get the DSCP.
TrafficClassFlowLabel_e
TF: Traffic Class, Flow Label.
Hlim_e GetHlim(void) const
Get the HLIM (Hop Limit) compression.
static TypeId GetTypeId(void)
Get the type ID.
void SetM(bool mField)
Set the M (Multicast) compression.
uint16_t m_baseFormat
Dispatch + encoding fields.
uint8_t m_nextHeader
Next header.
uint32_t GetFlowLabel(void) const
Get the Flow Label.
uint8_t GetNextHeader(void) const
Get the Next Header field.
uint32_t m_flowLabel
Flow Label bits.
virtual TypeId GetInstanceTypeId(void) const
Return the instance type identifier.
virtual void Print(std::ostream &os) const
void SetHopLimit(uint8_t hopLimit)
Set the Hop Limit field.
uint8_t m_ecn
ECN bits.
void SetDac(bool dacField)
Set the DAC (Destination Address Compression) compression.
6LoWPAN IPv6 uncompressed header - see RFC 4944.
virtual TypeId GetInstanceTypeId(void) const
Return the instance type identifier.
virtual void Print(std::ostream &os) const
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
static TypeId GetTypeId(void)
Get the type ID.
virtual uint32_t GetSerializedSize(void) const
Get the serialized size of the packet.
6LoWPAN Mesh header - see RFC 4944.
static TypeId GetTypeId(void)
Get the type ID.
bool m_f
True if Destination address is 16 bit.
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
bool m_v
True if Originator address is 16 bit.
virtual TypeId GetInstanceTypeId(void) const
Return the instance type identifier.
void SetHopsLeft(uint8_t hopsLeft)
Set the "Hops Left" field.
Address GetFinalDst(void) const
Get the "Final Destination" address.
virtual void Print(std::ostream &os) const
void SetFinalDst(Address finalDst)
Set the "Final Destination" address.
uint8_t m_hopsLeft
Hops left.
Address m_src
Originator (source) address.
Address GetOriginator(void) const
Get the "Originator" address.
uint8_t GetHopsLeft(void) const
Get the "Hops Left" field.
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
virtual uint32_t GetSerializedSize(void) const
Get the serialized size of the packet.
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.
uint8_t m_nhcExtensionHeader
NHC extension header type.
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
uint8_t GetNextHeader(void) const
Get the Next Header field value.
virtual TypeId GetInstanceTypeId(void) const
Return the instance type identifier.
static TypeId GetTypeId(void)
Get the type ID.
void SetNh(bool nhField)
Set the NH field values.
Eid_e GetEid(void) const
Get the Extension Header Type.
void SetEid(Eid_e extensionHeaderType)
Set the Extension Header Type.
uint8_t m_nhcBlobLength
Length of the NHC compressed header.
void SetBlob(const uint8_t *blob, uint32_t size)
Set the option header data blob.
virtual SixLowPanDispatch::NhcDispatch_e GetNhcDispatchType(void) const
Get the NhcDispatch type.
Eid_e
EID: IPv6 Extension Header ID.
virtual uint32_t GetSerializedSize(void) const
Get the serialized size of the packet.
uint32_t CopyBlob(uint8_t *blob, uint32_t size) const
Get the option header data blob.
virtual void Print(std::ostream &os) const
bool GetNh(void) const
Get the Next Header field value.
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
void SetNextHeader(uint8_t nextHeader)
Set the Next Header field values.
UDP LOWPAN_NHC Extension Header Encoding - see RFC 6282.
virtual void Print(std::ostream &os) const
uint8_t m_baseFormat
Dispatch + encoding fields.
uint16_t GetDstPort() const
Get the Destination Port.
void SetPorts(Ports_e port)
Set the compressed Src and Dst Ports.
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
uint16_t GetChecksum(void) const
Get the Checksum field value.
virtual TypeId GetInstanceTypeId(void) const
Return the instance type identifier.
virtual uint32_t GetSerializedSize(void) const
Get the serialized size of the packet.
bool GetC(void) const
Get the C (Checksum).
void SetChecksum(uint16_t checksum)
Set the Checksum field values.
void SetDstPort(uint16_t port)
Set the Destination Port.
static TypeId GetTypeId(void)
Get the type ID.
virtual SixLowPanDispatch::NhcDispatch_e GetNhcDispatchType(void) const
Get the NhcDispatch type.
void SetSrcPort(uint16_t port)
Set the Source Port.
void SetC(bool cField)
Set the C (Checksum).
uint16_t m_dstPort
Destination port.
Ports_e GetPorts(void) const
Get the compressed Src and Dst Ports.
uint16_t m_srcPort
Source port.
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:922
#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:88
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Definition: abort.h:50
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
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:139
def start()
Definition: core.py:1853