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}
1301
1302void SixLowPanIphc::SetM (bool mField)
1303{
1304 uint16_t field = mField;
1305 m_baseFormat |= (field << 3);
1306}
1307
1308bool SixLowPanIphc::GetM (void) const
1309{
1310 return ((m_baseFormat >> 3) & 0x1);
1311}
1312
1313void SixLowPanIphc::SetDac (bool dacField)
1314{
1315 uint16_t field = dacField;
1316 m_baseFormat |= (field << 2);
1317}
1318
1319bool SixLowPanIphc::GetDac (void) const
1320{
1321 return ((m_baseFormat >> 2) & 0x1);
1322}
1323
1325{
1326 uint16_t field = damField;
1327 m_baseFormat |= field;
1328}
1329
1331{
1332 return HeaderCompression_e (m_baseFormat & 0x3);
1333}
1334
1335const uint8_t* SixLowPanIphc::GetDstInlinePart (void) const
1336{
1337 return m_dstInlinePart;
1338}
1339
1340void SixLowPanIphc::SetDstInlinePart (uint8_t dstInlinePart[16], uint8_t size)
1341{
1342 NS_ASSERT_MSG (size <= 16, "Dst inline part too large");
1343
1344 memcpy (m_dstInlinePart, dstInlinePart, size);
1345}
1346
1347void SixLowPanIphc::SetSrcContextId (uint8_t srcContextId)
1348{
1349 NS_ASSERT_MSG (srcContextId < 16, "Src Context ID too large");
1350 m_srcdstContextId |= srcContextId << 4;
1351}
1352
1354{
1355 return ( m_srcdstContextId >> 4);
1356}
1357
1358void SixLowPanIphc::SetDstContextId (uint8_t dstContextId)
1359{
1360 NS_ASSERT_MSG (dstContextId < 16, "Dst Context ID too large");
1361 m_srcdstContextId |= (dstContextId & 0xF);
1362}
1363
1365{
1366 return (m_srcdstContextId & 0xF);
1367}
1368
1369void SixLowPanIphc::SetEcn (uint8_t ecn)
1370{
1371 NS_ASSERT_MSG (ecn < 4, "ECN too large");
1372 m_ecn = ecn;
1373}
1374
1375uint8_t SixLowPanIphc::GetEcn (void) const
1376{
1377 return m_ecn;
1378}
1379
1380void SixLowPanIphc::SetDscp (uint8_t dscp)
1381{
1382 NS_ASSERT_MSG (dscp < 64, "DSCP too large");
1383 m_dscp = dscp;
1384}
1385
1386uint8_t SixLowPanIphc::GetDscp (void) const
1387{
1388 return m_dscp;
1389}
1390
1392{
1393 NS_ASSERT_MSG (flowLabel < 0x100000, "Flow Label too large");
1394 m_flowLabel = flowLabel;
1395}
1396
1398{
1399 return m_flowLabel;
1400}
1401
1402void SixLowPanIphc::SetNextHeader (uint8_t nextHeader)
1403{
1404 m_nextHeader = nextHeader;
1405}
1406
1408{
1409 return m_nextHeader;
1410}
1411
1412void SixLowPanIphc::SetHopLimit (uint8_t hopLimit)
1413{
1414 m_hopLimit = hopLimit;
1415}
1416
1417uint8_t SixLowPanIphc::GetHopLimit (void) const
1418{
1419 return m_hopLimit;
1420}
1421
1422std::ostream & operator << (std::ostream & os, const SixLowPanIphc & h)
1423{
1424 h.Print (os);
1425 return os;
1426}
1427
1428/*
1429 * SixLowPanNhcExtensionHeader
1430 */
1431NS_OBJECT_ENSURE_REGISTERED (SixLowPanNhcExtension);
1432
1434{
1435 // 1110 xxxx
1436 m_nhcExtensionHeader = 0xE0;
1437 m_nhcNextHeader = 0;
1438 m_nhcBlobLength = 0;
1439}
1440
1442{
1443 static TypeId tid = TypeId ("ns3::SixLowPanNhcExtension")
1444 .SetParent<Header> ()
1445 .SetGroupName ("SixLowPan")
1446 .AddConstructor<SixLowPanNhcExtension> ();
1447 return tid;
1448}
1449
1451{
1452 return GetTypeId ();
1453}
1454
1455void SixLowPanNhcExtension::Print (std::ostream & os) const
1456{
1457 os << "Compression kind: " << +m_nhcExtensionHeader << " Size: " << GetSerializedSize ();
1458}
1459
1461{
1462 uint32_t serializedSize = 2;
1463 if ( GetNh () == false )
1464 {
1465 serializedSize++;
1466 }
1467 return serializedSize + m_nhcBlobLength;
1468}
1469
1471{
1474 if ( GetNh () == false )
1475 {
1477 }
1480}
1481
1483{
1486 if ( GetNh () == false )
1487 {
1488 m_nhcNextHeader = i.ReadU8 ();
1489 }
1490 m_nhcBlobLength = i.ReadU8 ();
1492
1493 return GetSerializedSize ();
1494}
1495
1498{
1500}
1501
1502void SixLowPanNhcExtension::SetEid (Eid_e extensionHeaderType)
1503{
1504 uint8_t field = extensionHeaderType;
1505 m_nhcExtensionHeader |= (field << 1);
1506}
1507
1509{
1510 return Eid_e ((m_nhcExtensionHeader >> 1) & 0x7);
1511}
1512
1514{
1515 m_nhcNextHeader = nextHeader;
1516}
1517
1519{
1520 return m_nhcNextHeader;
1521}
1522
1524{
1525 uint8_t field = nhField;
1526 m_nhcExtensionHeader |= field;
1527}
1528
1530{
1531 return m_nhcExtensionHeader & 0x01;
1532}
1533
1534void SixLowPanNhcExtension::SetBlob (const uint8_t* blob, uint32_t size)
1535{
1536 NS_ASSERT_MSG ( size < 255, "Buffer too long" );
1537
1538 m_nhcBlobLength = size;
1539 std::memcpy (m_nhcBlob, blob, size);
1540}
1541
1543{
1544 NS_ASSERT_MSG ( size > m_nhcBlobLength, "Buffer too short" );
1545
1546 std::memcpy (blob, m_nhcBlob, m_nhcBlobLength);
1547 return m_nhcBlobLength;
1548}
1549
1550std::ostream & operator << (std::ostream & os, const SixLowPanNhcExtension & h)
1551{
1552 h.Print (os);
1553 return os;
1554}
1555
1556/*
1557 * SixLowPanUdpNhcExtension
1558 */
1559NS_OBJECT_ENSURE_REGISTERED (SixLowPanUdpNhcExtension);
1560
1562{
1563 // 1111 0xxx
1564 m_baseFormat = 0xF0;
1565 m_checksum = 0;
1566 m_srcPort = 0;
1567 m_dstPort = 0;
1568}
1569
1571{
1572 static TypeId tid = TypeId ("ns3::SixLowPanUdpNhcExtension")
1573 .SetParent<Header> ()
1574 .SetGroupName ("SixLowPan")
1575 .AddConstructor<SixLowPanUdpNhcExtension> ();
1576 return tid;
1577}
1578
1580{
1581 return GetTypeId ();
1582}
1583
1584void SixLowPanUdpNhcExtension::Print (std::ostream & os) const
1585{
1586 os << "Compression kind: " << +m_baseFormat;
1587}
1588
1590{
1591 uint32_t serializedSize = 1;
1592 if ( !GetC () )
1593 {
1594 serializedSize += 2;
1595 }
1596 switch (GetPorts ())
1597 {
1598 case PORTS_INLINE:
1599 serializedSize += 4;
1600 break;
1603 serializedSize += 3;
1604 break;
1606 serializedSize += 1;
1607 break;
1608 default:
1609 break;
1610 }
1611 return serializedSize;
1612}
1613
1615{
1618 uint8_t temp;
1619
1620 // Ports
1621 switch ( GetPorts () )
1622 {
1623 case PORTS_INLINE:
1626 break;
1629 i.WriteU8 (m_dstPort & 0xff);
1630 break;
1632 i.WriteU8 (m_srcPort & 0xff);
1634 break;
1636 temp = ((m_srcPort & 0xf) << 4) | (m_dstPort & 0xf);
1637 i.WriteU8 (temp);
1638 break;
1639 default:
1640 break;
1641 }
1642
1643 // Checksum
1644 if ( !GetC () )
1645 {
1646 i.WriteU16 (m_checksum);
1647 }
1648
1649}
1650
1652{
1654 m_baseFormat = i.ReadU8 ();
1655 uint8_t temp;
1656
1657 // Ports
1658 switch ( GetPorts () )
1659 {
1660 case PORTS_INLINE:
1661 m_srcPort = i.ReadNtohU16 ();
1662 m_dstPort = i.ReadNtohU16 ();
1663 break;
1665 m_srcPort = i.ReadNtohU16 ();
1666 m_dstPort = i.ReadU8 ();
1667 break;
1669 m_srcPort = i.ReadU8 ();
1670 m_dstPort = i.ReadNtohU16 ();
1671 break;
1673 temp = i.ReadU8 ();
1674 m_srcPort = temp >> 4;
1675 m_dstPort = temp & 0xf;
1676 break;
1677 default:
1678 break;
1679 }
1680
1681 // Checksum
1682 if ( !GetC () )
1683 {
1684 m_checksum = i.ReadU16 ();
1685 }
1686
1687 return GetSerializedSize ();
1688}
1689
1692{
1694}
1695
1697{
1698 uint16_t field = ports;
1699 m_baseFormat |= field;
1700}
1701
1703{
1704 return Ports_e (m_baseFormat & 0x3);
1705}
1706
1708{
1709 m_srcPort = srcport;
1710}
1711
1713{
1714 return m_srcPort;
1715}
1716
1718{
1719 m_dstPort = dstport;
1720}
1721
1723{
1724 return m_dstPort;
1725}
1726
1728{
1729 uint16_t field = cField;
1730 m_baseFormat |= (field << 2);
1731}
1732
1734{
1735 return ((m_baseFormat >> 2) & 0x1);
1736}
1737
1739{
1740 m_checksum = checksum;
1741}
1742
1744{
1745 return m_checksum;
1746}
1747
1748std::ostream & operator << (std::ostream & os, const SixLowPanUdpNhcExtension & h)
1749{
1750 h.Print (os);
1751 return os;
1752}
1753
1754/*
1755 * SixLowPanBc0
1756 */
1757NS_OBJECT_ENSURE_REGISTERED (SixLowPanBc0);
1758
1760{
1761 m_seqNumber = 66;
1762}
1763
1765{
1766 static TypeId tid = TypeId ("ns3::SixLowPanBc0")
1767 .SetParent<Header> ()
1768 .SetGroupName ("SixLowPan")
1769 .AddConstructor<SixLowPanBc0> ();
1770 return tid;
1771}
1772
1774{
1775 return GetTypeId ();
1776}
1777
1778void SixLowPanBc0::Print (std::ostream & os) const
1779{
1780 os << "Sequence number: " << +m_seqNumber;
1781}
1782
1784{
1785 return 2;
1786}
1787
1789{
1791 i.WriteU8 (0x50);
1792 i.WriteU8 (m_seqNumber);
1793
1794}
1795
1797{
1799 uint8_t dispatch = i.ReadU8 ();
1800
1801 if (dispatch != 0x50)
1802 {
1803 return 0;
1804 }
1805
1806 m_seqNumber = i.ReadU8 ();
1807
1808 return GetSerializedSize ();
1809}
1810
1811void SixLowPanBc0::SetSequenceNumber (uint8_t seqNumber)
1812{
1813 m_seqNumber = seqNumber;
1814}
1815
1817{
1818 return m_seqNumber;
1819}
1820
1821std::ostream & operator << (std::ostream & os, const SixLowPanBc0 & h)
1822{
1823 h.Print (os);
1824 return os;
1825}
1826
1827/*
1828 * SixLowPanMesh
1829 */
1830NS_OBJECT_ENSURE_REGISTERED (SixLowPanMesh);
1831
1833{
1834 m_hopsLeft = 0;
1835 m_src = Address ();
1836 m_dst = Address ();
1837 m_v = false;
1838 m_f = false;
1839}
1840
1842{
1843 static TypeId tid = TypeId ("ns3::SixLowPanMesh")
1844 .SetParent<Header> ()
1845 .SetGroupName ("SixLowPan")
1846 .AddConstructor<SixLowPanMesh> ();
1847 return tid;
1848}
1849
1851{
1852 return GetTypeId ();
1853}
1854
1855void SixLowPanMesh::Print (std::ostream & os) const
1856{
1857 os << "Hops left: " << +m_hopsLeft << ", src: ";
1859 {
1861 }
1862 else
1863 {
1865 }
1866 os << ", dst: ";
1868 {
1870 }
1871 else
1872 {
1874 }
1875}
1876
1878{
1879 uint32_t serializedSize = 1;
1880
1881 if (m_hopsLeft >= 0xF)
1882 {
1883 serializedSize++;
1884 }
1885
1886 if (m_v)
1887 {
1888 serializedSize += 2;
1889 }
1890 else
1891 {
1892 serializedSize += 8;
1893 }
1894
1895 if (m_f)
1896 {
1897 serializedSize += 2;
1898 }
1899 else
1900 {
1901 serializedSize += 8;
1902 }
1903
1904 return serializedSize;
1905}
1906
1908{
1910
1911 uint8_t dispatch = 0x80;
1912
1913 if (m_v)
1914 {
1915 dispatch |= 0x20;
1916 }
1917 if (m_f)
1918 {
1919 dispatch |= 0x10;
1920 }
1921
1922 if (m_hopsLeft < 0xF)
1923 {
1924 dispatch |= m_hopsLeft;
1925 i.WriteU8 (dispatch);
1926 }
1927 else
1928 {
1929 dispatch |= 0xF;
1930 i.WriteU8 (dispatch);
1931 i.WriteU8 (m_hopsLeft);
1932 }
1933
1934 uint8_t buffer[8];
1935
1936 m_src.CopyTo (buffer);
1937 if (m_v)
1938 {
1939 i.Write (buffer, 2);
1940 }
1941 else
1942 {
1943 i.Write (buffer, 8);
1944 }
1945
1946 m_dst.CopyTo (buffer);
1947 if (m_f)
1948 {
1949 i.Write (buffer, 2);
1950 }
1951 else
1952 {
1953 i.Write (buffer, 8);
1954 }
1955}
1956
1958{
1960 uint8_t temp = i.ReadU8 ();
1961
1962 if ((temp & 0xC0) != 0x80)
1963 {
1964 return 0;
1965 }
1966
1967 m_v = temp & 0x20;
1968 m_f = temp & 0x10;
1969 m_hopsLeft = temp & 0xF;
1970
1971 if (m_hopsLeft == 0xF)
1972 {
1973 m_hopsLeft = i.ReadU8 ();
1974 }
1975
1976 uint8_t buffer[8];
1977 uint8_t addrSize;
1978
1979 if (m_v)
1980 {
1981 addrSize = 2;
1982 }
1983 else
1984 {
1985 addrSize = 8;
1986 }
1987 i.Read (buffer, addrSize);
1988 m_src.CopyFrom (buffer, addrSize);
1989
1990 if (m_f)
1991 {
1992 addrSize = 2;
1993 }
1994 else
1995 {
1996 addrSize = 8;
1997 }
1998 i.Read (buffer, addrSize);
1999 m_dst.CopyFrom (buffer, addrSize);
2000
2001 return GetSerializedSize ();
2002}
2003
2005{
2006 if (Mac64Address::IsMatchingType (originator))
2007 {
2008 m_v = false;
2009 }
2010 else if (Mac16Address::IsMatchingType (originator))
2011 {
2012 m_v = true;
2013 }
2014 else
2015 {
2016 NS_ABORT_MSG ("SixLowPanMesh::SetOriginator - incompatible address");
2017 }
2018
2019 m_src = originator;
2020}
2021
2023{
2024 return m_src;
2025}
2026
2028{
2029 if (Mac64Address::IsMatchingType (finalDst))
2030 {
2031 m_f = false;
2032 }
2033 else if (Mac16Address::IsMatchingType (finalDst))
2034 {
2035 m_f = true;
2036 }
2037 else
2038 {
2039 NS_ABORT_MSG ("SixLowPanMesh::SetFinalDst - incompatible address");
2040 }
2041
2042 m_dst = finalDst;
2043}
2044
2046{
2047 return m_dst;
2048}
2049
2050void SixLowPanMesh::SetHopsLeft (uint8_t hopsLeft)
2051{
2052 m_hopsLeft = hopsLeft;
2053}
2054
2055uint8_t SixLowPanMesh::GetHopsLeft (void) const
2056{
2057 return m_hopsLeft;
2058}
2059
2060std::ostream & operator << (std::ostream & os, const SixLowPanMesh & h)
2061{
2062 h.Print (os);
2063 return os;
2064}
2065
2066}
2067
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:1852