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/address-utils.h"
26 #include "sixlowpan-header.h"
27 
28 
29 namespace ns3 {
30 
31 /*
32  * SixLowPanDispatch
33  */
34 
35 
37 {
38 }
39 
40 
43 {
44  if (dispatch <= LOWPAN_NALP_N)
45  {
46  return LOWPAN_NALP;
47  }
48  else if (dispatch == LOWPAN_IPv6)
49  {
50  return LOWPAN_IPv6;
51  }
52  else if (dispatch == LOWPAN_HC1)
53  {
54  return LOWPAN_HC1;
55  }
56  else if (dispatch == LOWPAN_BC0)
57  {
58  return LOWPAN_BC0;
59  }
60  else if ((dispatch >= LOWPAN_IPHC) && (dispatch <= LOWPAN_IPHC_N))
61  {
62  return LOWPAN_IPHC;
63  }
64  else if ((dispatch >= LOWPAN_MESH) && (dispatch <= LOWPAN_MESH_N))
65  {
66  return LOWPAN_MESH;
67  }
68  else if ((dispatch >= LOWPAN_FRAG1) && (dispatch <= LOWPAN_FRAG1_N))
69  {
70  return LOWPAN_FRAG1;
71  }
72  else if ((dispatch >= LOWPAN_FRAGN) && (dispatch <= LOWPAN_FRAGN_N))
73  {
74  return LOWPAN_FRAGN;
75  }
76  return LOWPAN_UNSUPPORTED;
77 }
78 
81 {
82  if ((dispatch >= LOWPAN_NHC) && (dispatch <= LOWPAN_NHC_N))
83  {
84  return LOWPAN_NHC;
85  }
86  else if ((dispatch >= LOWPAN_UDPNHC) && (dispatch <= LOWPAN_UDPNHC_N))
87  {
88  return LOWPAN_UDPNHC;
89  }
90  return LOWPAN_NHCUNSUPPORTED;
91 }
92 
93 
94 /*
95  * SixLowPanHc1
96  */
98 
100  : m_hopLimit (0)
101 {
102 }
103 
105 {
106  static TypeId tid = TypeId ("ns3::SixLowPanHc1")
107  .SetParent<Header> ()
108  .SetGroupName ("SixLowPan")
109  .AddConstructor<SixLowPanHc1> ();
110  return tid;
111 }
112 
114 {
115  return GetTypeId ();
116 }
117 
118 void SixLowPanHc1::Print (std::ostream & os) const
119 {
120  uint8_t encoding;
121  encoding = m_srcCompression;
122  encoding <<= 2;
123  encoding |= m_dstCompression;
124  encoding <<= 1;
125  encoding |= m_tcflCompression;
126  encoding <<= 2;
127  encoding |= m_nextHeaderCompression;
128  encoding <<= 1;
129  encoding |= m_hc2HeaderPresent;
130 
131  os << "encoding " << static_cast<int> (encoding) << ", hopLimit " << static_cast<int> (m_hopLimit);
132 }
133 
135 {
136  uint32_t serializedSize = 3;
137 
138  switch (m_srcCompression)
139  {
140  case HC1_PIII:
141  serializedSize += 16;
142  break;
143  case HC1_PIIC:
144  serializedSize += 8;
145  break;
146  case HC1_PCII:
147  serializedSize += 8;
148  break;
149  case HC1_PCIC:
150  break;
151  }
152  switch (m_dstCompression)
153  {
154  case HC1_PIII:
155  serializedSize += 16;
156  break;
157  case HC1_PIIC:
158  serializedSize += 8;
159  break;
160  case HC1_PCII:
161  serializedSize += 8;
162  break;
163  case HC1_PCIC:
164  break;
165  }
166 
167  if (m_tcflCompression == false )
168  {
169  serializedSize += 4;
170  }
171 
173  {
174  serializedSize++;
175  }
176 
177  return serializedSize;
178 }
179 
181 {
183  uint8_t encoding;
184  encoding = m_srcCompression;
185  encoding <<= 2;
186  encoding |= m_dstCompression;
187  encoding <<= 1;
188  encoding |= m_tcflCompression;
189  encoding <<= 2;
190  encoding |= m_nextHeaderCompression;
191  encoding <<= 1;
192  encoding |= m_hc2HeaderPresent;
193 
195  i.WriteU8 (encoding);
196  i.WriteU8 (m_hopLimit);
197  switch (m_srcCompression)
198  {
199  case HC1_PIII:
200  for ( int j = 0; j < 8; j++ )
201  {
202  i.WriteU8 (m_srcPrefix[j]);
203  }
204  for ( int j = 0; j < 8; j++ )
205  {
206  i.WriteU8 (m_srcInterface[j]);
207  }
208  break;
209  case HC1_PIIC:
210  for ( int j = 0; j < 8; j++ )
211  {
212  i.WriteU8 (m_srcPrefix[j]);
213  }
214  break;
215  case HC1_PCII:
216  for ( int j = 0; j < 8; j++ )
217  {
218  i.WriteU8 (m_srcInterface[j]);
219  }
220  break;
221  case HC1_PCIC:
222  break;
223  }
224  switch (m_dstCompression)
225  {
226  case HC1_PIII:
227  for ( int j = 0; j < 8; j++ )
228  {
229  i.WriteU8 (m_dstPrefix[j]);
230  }
231  for ( int j = 0; j < 8; j++ )
232  {
233  i.WriteU8 (m_dstInterface[j]);
234  }
235  break;
236  case HC1_PIIC:
237  for ( int j = 0; j < 8; j++ )
238  {
239  i.WriteU8 (m_dstPrefix[j]);
240  }
241  break;
242  case HC1_PCII:
243  for ( int j = 0; j < 8; j++ )
244  {
245  i.WriteU8 (m_dstInterface[j]);
246  }
247  break;
248  case HC1_PCIC:
249  break;
250  }
251 
252  if ( m_tcflCompression == false )
253  {
255  uint8_t temp[3];
256  temp[0] = uint8_t (m_flowLabel & 0xff);
257  temp[1] = uint8_t ((m_flowLabel >> 8) & 0xff);
258  temp[2] = uint8_t ((m_flowLabel >> 16) & 0xff);
259  i.Write (temp, 3);
260  }
261 
263  {
264  i.WriteU8 (m_nextHeader);
265  }
266 
267  // TODO: HC2 is not yet supported. Should be.
268  NS_ASSERT_MSG ( m_hc2HeaderPresent != true, "Can not compress HC2, exiting. Very sorry." );
269 }
270 
272 {
274  uint32_t serializedSize = 3;
275 
276  uint8_t dispatch = i.ReadU8 ();
277  if (dispatch != SixLowPanDispatch::LOWPAN_HC1)
278  {
279  return 0;
280  }
281 
282  uint8_t encoding = i.ReadU8 ();
283  m_hopLimit = i.ReadU8 ();
284 
285  m_srcCompression = LowPanHc1Addr_e (encoding >> 6);
286  m_dstCompression = LowPanHc1Addr_e ( (encoding >> 4) & 0x3);
287  m_tcflCompression = (encoding >> 3) & 0x1;
288  m_nextHeaderCompression = LowPanHc1NextHeader_e ( (encoding >> 1) & 0x3);
289  m_hc2HeaderPresent = encoding & 0x1;
290 
291  switch (m_srcCompression)
292  {
293  case HC1_PIII:
294  for ( int j = 0; j < 8; j++)
295  {
296  m_srcPrefix[j] = i.ReadU8 ();
297  }
298  for ( int j = 0; j < 8; j++)
299  {
300  m_srcInterface[j] = i.ReadU8 ();
301  }
302  serializedSize += 16;
303  break;
304  case HC1_PIIC:
305  for ( int j = 0; j < 8; j++)
306  {
307  m_srcPrefix[j] = i.ReadU8 ();
308  }
309  serializedSize += 8;
310  break;
311  case HC1_PCII:
312  for ( int j = 0; j < 8; j++)
313  {
314  m_srcInterface[j] = i.ReadU8 ();
315  }
316  serializedSize += 8;
317  break;
318  case HC1_PCIC:
319  break;
320  }
321  switch (m_dstCompression)
322  {
323  case HC1_PIII:
324  for ( int j = 0; j < 8; j++)
325  {
326  m_dstPrefix[j] = i.ReadU8 ();
327  }
328  for ( int j = 0; j < 8; j++)
329  {
330  m_dstInterface[j] = i.ReadU8 ();
331  }
332  serializedSize += 16;
333  break;
334  case HC1_PIIC:
335  for ( int j = 0; j < 8; j++)
336  {
337  m_dstPrefix[j] = i.ReadU8 ();
338  }
339  serializedSize += 8;
340  break;
341  case HC1_PCII:
342  for ( int j = 0; j < 8; j++)
343  {
344  m_dstInterface[j] = i.ReadU8 ();
345  }
346  serializedSize += 8;
347  break;
348  case HC1_PCIC:
349  break;
350  }
351 
352  if ( m_tcflCompression == false )
353  {
354  m_trafficClass = i.ReadU8 ();
355  uint8_t temp[3];
356  i.Read (temp, 3);
357  m_flowLabel = temp[2];
358  m_flowLabel = (m_flowLabel << 8) | temp[1];
359  m_flowLabel = (m_flowLabel << 8) | temp[0];
360  serializedSize += 4;
361  }
362 
363  switch ( m_nextHeaderCompression )
364  {
365  case HC1_NC:
366  m_nextHeader = i.ReadU8 ();
367  serializedSize++;
368  break;
369  case HC1_TCP:
371  break;
372  case HC1_UDP:
374  break;
375  case HC1_ICMP:
377  break;
378  }
379 
380  NS_ASSERT_MSG ( m_hc2HeaderPresent != true, "Can not compress HC2, exiting. Very sorry." );
381 
382  return GetSerializedSize ();
383 }
384 
385 void SixLowPanHc1::SetHopLimit (uint8_t limit)
386 {
387  m_hopLimit = limit;
388 }
389 
391 {
392  return m_hopLimit;
393 }
394 
396 {
397  return m_dstCompression;
398 }
399 
400 const uint8_t* SixLowPanHc1::GetDstInterface () const
401 {
402  return m_dstInterface;
403 }
404 
405 const uint8_t* SixLowPanHc1::GetDstPrefix () const
406 {
407  return m_dstPrefix;
408 }
409 
410 uint32_t SixLowPanHc1::GetFlowLabel () const
411 {
412  return m_flowLabel;
413 }
414 
416 {
417  return m_nextHeader;
418 }
419 
421 {
422  return m_srcCompression;
423 }
424 
425 const uint8_t* SixLowPanHc1::GetSrcInterface () const
426 {
427  return m_srcInterface;
428 }
429 
430 const uint8_t* SixLowPanHc1::GetSrcPrefix () const
431 {
432  return m_srcPrefix;
433 }
434 
436 {
437  return m_trafficClass;
438 }
439 
441 {
442  return m_tcflCompression;
443 }
444 
446 {
447  return m_hc2HeaderPresent;
448 }
449 
451 {
452  m_dstCompression = dstCompression;
453 }
454 
455 void SixLowPanHc1::SetDstInterface (const uint8_t* dstInterface)
456 {
457  for ( int i = 0; i < 8; i++)
458  {
459  m_dstInterface[i] = dstInterface[i];
460  }
461 }
462 
463 void SixLowPanHc1::SetDstPrefix (const uint8_t* dstPrefix)
464 {
465  for ( int i = 0; i < 8; i++)
466  {
467  m_dstPrefix[i] = dstPrefix[i];
468  }
469 }
470 
471 void SixLowPanHc1::SetFlowLabel (uint32_t flowLabel)
472 {
473  m_flowLabel = flowLabel;
474 }
475 
476 void SixLowPanHc1::SetNextHeader (uint8_t nextHeader)
477 {
478  m_nextHeader = nextHeader;
479 
480  switch (m_nextHeader)
481  {
484  break;
487  break;
490  break;
491  default:
493  break;
494  }
495 }
496 
498 {
499  m_srcCompression = srcCompression;
500 }
501 
502 void SixLowPanHc1::SetSrcInterface (const uint8_t* srcInterface)
503 {
504  for ( int i = 0; i < 8; i++)
505  {
506  m_srcInterface[i] = srcInterface[i];
507  }
508 }
509 
510 void SixLowPanHc1::SetSrcPrefix (const uint8_t* srcPrefix)
511 {
512  for ( int i = 0; i < 8; i++)
513  {
514  m_srcPrefix[i] = srcPrefix[i];
515  }
516 }
517 
518 void SixLowPanHc1::SetTcflCompression (bool tcflCompression)
519 {
520  m_tcflCompression = tcflCompression;
521 }
522 
523 void SixLowPanHc1::SetTrafficClass (uint8_t trafficClass)
524 {
525  m_trafficClass = trafficClass;
526 }
527 
528 
529 void SixLowPanHc1::SetHc2HeaderPresent (bool hc2HeaderPresent)
530 {
531  m_hc2HeaderPresent = hc2HeaderPresent;
532 }
533 
534 
535 std::ostream & operator << (std::ostream & os, const SixLowPanHc1 & h)
536 {
537  h.Print (os);
538  return os;
539 }
540 
541 /*
542  * SixLowPanFrag1
543  */
544 NS_OBJECT_ENSURE_REGISTERED (SixLowPanFrag1);
545 
547  : m_datagramSize (0),
548  m_datagramTag (0)
549 {
550 }
551 
553 {
554  static TypeId tid = TypeId ("ns3::SixLowPanFrag1")
555  .SetParent<Header> ()
556  .SetGroupName ("SixLowPan")
557  .AddConstructor<SixLowPanFrag1> ();
558  return tid;
559 }
560 
562 {
563  return GetTypeId ();
564 }
565 
566 void SixLowPanFrag1::Print (std::ostream & os) const
567 {
568  os << "datagram size " << m_datagramSize << " tag " << m_datagramTag;
569 }
570 
572 {
573  return 4;
574 }
575 
577 {
579 
580  uint16_t temp = m_datagramSize | ( uint16_t (SixLowPanDispatch::LOWPAN_FRAG1) << 8 );
581 
582  i.WriteU8 (uint8_t (temp >> 8));
583  i.WriteU8 (uint8_t (temp & 0xff));
584 
586 }
587 
589 {
591 
592  uint8_t temp = i.ReadU8 ();
593  m_datagramSize = (uint16_t (temp) << 8) | i.ReadU8 ();
594  m_datagramSize &= 0x7FF;
595 
596  m_datagramTag = i.ReadU16 ();
597  return GetSerializedSize ();
598 }
599 
600 void SixLowPanFrag1::SetDatagramSize (uint16_t datagramSize)
601 {
602  m_datagramSize = datagramSize & 0x7FF;
603 }
604 
606 {
607  return m_datagramSize & 0x7FF;
608 }
609 
610 void SixLowPanFrag1::SetDatagramTag (uint16_t datagramTag)
611 {
612  m_datagramTag = datagramTag;
613 }
614 
616 {
617  return m_datagramTag;
618 }
619 
620 std::ostream & operator << (std::ostream & os, const SixLowPanFrag1 & h)
621 {
622  h.Print (os);
623  return os;
624 }
625 
626 
627 /*
628  * SixLowPanFragN
629  */
630 
631 NS_OBJECT_ENSURE_REGISTERED (SixLowPanFragN);
632 
634  : m_datagramSize (0),
635  m_datagramTag (0),
636  m_datagramOffset (0)
637 {
638 }
639 /*
640  * SixLowPanFragmentOffset
641  */
643 {
644  static TypeId tid = TypeId ("ns3::SixLowPanFragN")
645  .SetParent<Header> ()
646  .SetGroupName ("SixLowPan")
647  .AddConstructor<SixLowPanFragN> ();
648  return tid;
649 }
650 
652 {
653  return GetTypeId ();
654 }
655 
656 void SixLowPanFragN::Print (std::ostream & os) const
657 {
658  os << "datagram size " << m_datagramSize << " tag " << m_datagramTag << " offset " << static_cast<int> (m_datagramOffset);
659 }
660 
662 {
663  return 5;
664 }
665 
667 {
669 
670  uint16_t temp = m_datagramSize | ( uint16_t (SixLowPanDispatch::LOWPAN_FRAGN) << 8 );
671 
672  i.WriteU8 (uint8_t (temp >> 8));
673  i.WriteU8 (uint8_t (temp & 0xff));
674 
677 }
678 
680 {
682 
683  uint8_t temp = i.ReadU8 ();
684  m_datagramSize = (uint16_t (temp) << 8) | i.ReadU8 ();
685  m_datagramSize &= 0x7FF;
686 
687  m_datagramTag = i.ReadU16 ();
688  m_datagramOffset = i.ReadU8 ();
689 
690  return GetSerializedSize ();
691 }
692 
693 void SixLowPanFragN::SetDatagramSize (uint16_t datagramSize)
694 {
695  m_datagramSize = datagramSize & 0x7FF;
696 }
697 
699 {
700  return m_datagramSize & 0x7FF;
701 }
702 
703 void SixLowPanFragN::SetDatagramTag (uint16_t datagramTag)
704 {
705  m_datagramTag = datagramTag;
706 }
707 
709 {
710  return m_datagramTag;
711 }
712 
713 void SixLowPanFragN::SetDatagramOffset (uint8_t datagramOffset)
714 {
715  m_datagramOffset = datagramOffset;
716 }
717 
719 {
720  return m_datagramOffset;
721 }
722 
723 std::ostream & operator << (std::ostream & os, const SixLowPanFragN & h)
724 {
725  h.Print (os);
726  return os;
727 }
728 
729 /*
730  * SixLowPanIpv6
731  */
732 
733 NS_OBJECT_ENSURE_REGISTERED (SixLowPanIpv6);
734 
736 {
737 }
738 
740 {
741  static TypeId tid = TypeId ("ns3::SixLowPanIpv6")
742  .SetParent<Header> ()
743  .SetGroupName ("SixLowPan")
744  .AddConstructor<SixLowPanIpv6> ();
745  return tid;
746 }
747 
749 {
750  return GetTypeId ();
751 }
752 
753 void SixLowPanIpv6::Print (std::ostream & os) const
754 {
755  os << "Uncompressed IPv6";
756 }
757 
759 {
760  return 1;
761 }
762 
764 {
766 
768 }
769 
771 {
773  i.ReadU8 ();
774 
775  return GetSerializedSize ();
776 }
777 
778 std::ostream & operator << (std::ostream & os, const SixLowPanIpv6 & h)
779 {
780  h.Print (os);
781  return os;
782 }
783 
784 /*
785  * SixLowPanIphcHeader
786  */
787 NS_OBJECT_ENSURE_REGISTERED (SixLowPanIphc);
788 
790 {
791  // 011x xxxx xxxx xxxx
792  m_baseFormat = 0x6000;
793 }
794 
796 {
797  // 011x xxxx xxxx xxxx
798  m_baseFormat = dispatch;
799  m_baseFormat <<= 8;
800 }
801 
803 {
804  static TypeId tid = TypeId ("ns3::SixLowPanIphc")
805  .SetParent<Header> ()
806  .SetGroupName ("SixLowPan")
807  .AddConstructor<SixLowPanIphc> ();
808  return tid;
809 }
810 
812 {
813  return GetTypeId ();
814 }
815 
816 void SixLowPanIphc::Print (std::ostream & os) const
817 {
818  os << "Compression kind: " << static_cast<int> (m_baseFormat);
819 }
820 
822 {
823  uint32_t serializedSize = 2;
824 
825  if ( GetCid () )
826  {
827  serializedSize++;
828  }
829  switch ( GetTf () )
830  {
831  case TF_FULL:
832  serializedSize += 4;
833  break;
834  case TF_DSCP_ELIDED:
835  serializedSize += 3;
836  break;
837  case TF_FL_ELIDED:
838  serializedSize++;
839  break;
840  default:
841  break;
842  }
843  if ( GetNh () == false )
844  {
845  serializedSize++;
846  }
847  if ( GetHlim () == HLIM_INLINE)
848  {
849  serializedSize++;
850  }
851  switch (GetSam () )
852  {
853  case HC_INLINE:
854  if ( GetSac () == false )
855  {
856  serializedSize += 16;
857  }
858  break;
859  case HC_COMPR_64:
860  serializedSize += 8;
861  break;
862  case HC_COMPR_16:
863  serializedSize += 2;
864  break;
865  case HC_COMPR_0:
866  default:
867  break;
868  }
869  if ( GetM () == false)
870  {
871  switch (GetDam () )
872  {
873  case HC_INLINE:
874  if ( GetDac () == false )
875  {
876  serializedSize += 16;
877  }
878  break;
879  case HC_COMPR_64:
880  serializedSize += 8;
881  break;
882  case HC_COMPR_16:
883  serializedSize += 2;
884  break;
885  case HC_COMPR_0:
886  default:
887  break;
888  }
889  }
890  else
891  {
892  switch (GetDam () )
893  {
894  case HC_INLINE:
895  if ( GetDac () == false )
896  {
897  serializedSize += 16;
898  }
899  else
900  {
901  serializedSize += 6;
902  }
903  break;
904  case HC_COMPR_64:
905  if ( GetDac () == false )
906  {
907  serializedSize += 6;
908  }
909  break;
910  case HC_COMPR_16:
911  if ( GetDac () == false )
912  {
913  serializedSize += 4;
914  }
915  break;
916  case HC_COMPR_0:
917  default:
918  if ( GetDac () == false )
919  {
920  serializedSize++;
921  }
922  break;
923  }
924  }
925 
926 
927 
928  return serializedSize;
929 }
930 
932 {
934 
936 
937  if ( GetCid () )
938  {
940  }
941  // Traffic Class and Flow Label
942  switch ( GetTf () )
943  {
944  uint8_t temp;
945  case TF_FULL:
946  temp = (m_ecn << 6) | m_dscp;
947  i.WriteU8 (temp);
948  temp = m_flowLabel >> 16;
949  i.WriteU8 (temp);
950  temp = (m_flowLabel >> 8) & 0xff;
951  i.WriteU8 (temp);
952  temp = m_flowLabel & 0xff;
953  i.WriteU8 (temp);
954  break;
955  case TF_DSCP_ELIDED:
956  temp = (m_ecn << 6) | (m_flowLabel >> 16 );
957  i.WriteU8 (temp);
958  temp = (m_flowLabel >> 8) & 0xff;
959  i.WriteU8 (temp);
960  temp = m_flowLabel & 0xff;
961  i.WriteU8 (temp);
962  break;
963  case TF_FL_ELIDED:
964  temp = (m_ecn << 6) | m_dscp;
965  i.WriteU8 (temp);
966  break;
967  default:
968  break;
969  }
970  // Next Header
971  if ( GetNh () == false )
972  {
973  i.WriteU8 (m_nextHeader);
974  }
975  // Hop Limit
976  if ( GetHlim () == HLIM_INLINE )
977  {
978  i.WriteU8 (m_hopLimit);
979  }
980  // Source Address
981  switch (GetSam () )
982  {
983  uint8_t temp[16];
984  case HC_INLINE:
985  if ( GetSac () == false )
986  {
987  uint8_t temp[16];
988  m_srcAddress.Serialize (temp);
989  i.Write (temp, 16);
990  }
991  break;
992  case HC_COMPR_64:
993  m_srcAddress.Serialize (temp);
994  i.Write (temp + 8, 8);
995  break;
996  case HC_COMPR_16:
997  m_srcAddress.Serialize (temp);
998  i.Write (temp + 14, 2);
999  break;
1000  case HC_COMPR_0:
1001  default:
1002  break;
1003  }
1004  // Destination Address
1005  if ( GetM () == false)
1006  {
1007  uint8_t temp[16];
1008  switch (GetDam () )
1009  {
1010  case HC_INLINE:
1011  if ( GetDac () == false )
1012  {
1013  m_dstAddress.Serialize (temp);
1014  i.Write (temp, 16);
1015  }
1016  break;
1017  case HC_COMPR_64:
1018  m_dstAddress.Serialize (temp);
1019  i.Write (temp + 8, 8);
1020  break;
1021  case HC_COMPR_16:
1022  m_dstAddress.Serialize (temp);
1023  i.Write (temp + 14, 2);
1024  break;
1025  case HC_COMPR_0:
1026  default:
1027  break;
1028  }
1029  }
1030  else
1031  {
1032  switch (GetDam () )
1033  {
1034  uint8_t temp[16];
1035  case HC_INLINE:
1036  if ( GetDac () == false )
1037  {
1038  m_dstAddress.Serialize (temp);
1039  i.Write (temp, 16);
1040  }
1041  else
1042  {
1043  m_dstAddress.Serialize (temp);
1044  i.Write (temp + 1, 2);
1045  i.Write (temp + 12, 4);
1046  }
1047  break;
1048  case HC_COMPR_64:
1049  if ( GetDac () == false )
1050  {
1051  m_dstAddress.Serialize (temp);
1052  i.Write (temp + 1, 1);
1053  i.Write (temp + 11, 5);
1054  }
1055  break;
1056  case HC_COMPR_16:
1057  if ( GetDac () == false )
1058  {
1059  m_dstAddress.Serialize (temp);
1060  i.Write (temp + 1, 1);
1061  i.Write (temp + 13, 3);
1062  }
1063  break;
1064  case HC_COMPR_0:
1065  default:
1066  if ( GetDac () == false )
1067  {
1068  m_dstAddress.Serialize (temp);
1069  i.WriteU8 (temp[15]);
1070  }
1071  break;
1072  }
1073  }
1074 }
1075 
1077 {
1078  Buffer::Iterator i = start;
1079 
1080  m_baseFormat = i.ReadNtohU16 ();
1081 
1082  if ( GetCid () )
1083  {
1084  m_srcdstContextId = i.ReadU8 ();
1085  }
1086  // Traffic Class and Flow Label
1087  switch ( GetTf () )
1088  {
1089  uint8_t temp;
1090  case TF_FULL:
1091  temp = i.ReadU8 ();
1092  m_ecn = temp >> 6;
1093  m_dscp = temp & 0x3F;
1094  temp = i.ReadU8 ();
1095  m_flowLabel = temp;
1096  temp = i.ReadU8 ();
1097  m_flowLabel = (m_flowLabel << 8) | temp;
1098  temp = i.ReadU8 ();
1099  m_flowLabel = (m_flowLabel << 8) | temp;
1100  break;
1101  case TF_DSCP_ELIDED:
1102  temp = i.ReadU8 ();
1103  m_ecn = temp >> 6;
1104  m_flowLabel = temp & 0x3F;
1105  temp = i.ReadU8 ();
1106  m_flowLabel = (m_flowLabel << 8) | temp;
1107  temp = i.ReadU8 ();
1108  m_flowLabel = (m_flowLabel << 8) | temp;
1109  break;
1110  case TF_FL_ELIDED:
1111  temp = i.ReadU8 ();
1112  m_ecn = temp >> 6;
1113  m_dscp = temp & 0x3F;
1114  break;
1115  default:
1116  break;
1117  }
1118  // Next Header
1119  if ( GetNh () == false )
1120  {
1121  m_nextHeader = i.ReadU8 ();
1122  }
1123  // Hop Limit
1124  switch ( GetHlim () )
1125  {
1126  case HLIM_INLINE:
1127  m_hopLimit = i.ReadU8 ();
1128  break;
1129  case HLIM_COMPR_1:
1130  m_hopLimit = 1;
1131  break;
1132  case HLIM_COMPR_64:
1133  m_hopLimit = 64;
1134  break;
1135  case HLIM_COMPR_255:
1136  default:
1137  m_hopLimit = 255;
1138  break;
1139 
1140  }
1141  // Source Address
1142  switch (GetSam () )
1143  {
1144  uint8_t temp[16];
1145  case HC_INLINE:
1146  if ( GetSac () == false )
1147  {
1148  i.Read (temp, 16);
1150  }
1151  break;
1152  case HC_COMPR_64:
1153  memset (temp, 0x00, sizeof (temp));
1154  i.Read (temp + 8, 8);
1155  temp[0] = 0xfe;
1156  temp[1] = 0x80;
1158  break;
1159  case HC_COMPR_16:
1160  memset (temp, 0x00, sizeof (temp));
1161  i.Read (temp + 14, 2);
1162  temp[0] = 0xfe;
1163  temp[1] = 0x80;
1164  temp[11] = 0xff;
1165  temp[12] = 0xfe;
1167  break;
1168  case HC_COMPR_0:
1169  default:
1170  break;
1171  }
1172  if ( GetSac () == true )
1173  {
1174  PostProcessSac ();
1175  }
1176  // Destination Address
1177  if ( GetM () == false)
1178  {
1179  uint8_t temp[16];
1180  switch (GetDam () )
1181  {
1182  case HC_INLINE:
1183  if ( GetDac () == false )
1184  {
1185  i.Read (temp, 16);
1187  }
1188  break;
1189  case HC_COMPR_64:
1190  memset (temp, 0x00, sizeof (temp));
1191  i.Read (temp + 8, 8);
1192  temp[0] = 0xfe;
1193  temp[1] = 0x80;
1195  break;
1196  case HC_COMPR_16:
1197  memset (temp, 0x00, sizeof (temp));
1198  i.Read (temp + 14, 2);
1199  temp[0] = 0xfe;
1200  temp[1] = 0x80;
1201  temp[11] = 0xff;
1202  temp[12] = 0xfe;
1204  break;
1205  case HC_COMPR_0:
1206  default:
1207  break;
1208  }
1209  }
1210  else
1211  {
1212  switch (GetDam () )
1213  {
1214  uint8_t temp[16];
1215  case HC_INLINE:
1216  if ( GetDac () == false )
1217  {
1218  i.Read (temp, 16);
1220  }
1221  else
1222  {
1223  memset (temp, 0x00, sizeof (temp));
1224  i.Read (temp + 1, 2);
1225  i.Read (temp + 12, 4);
1226  temp[0] = 0xff;
1228  }
1229  break;
1230  case HC_COMPR_64:
1231  if ( GetDac () == false )
1232  {
1233  memset (temp, 0x00, sizeof (temp));
1234  i.Read (temp + 1, 1);
1235  i.Read (temp + 11, 5);
1236  temp[0] = 0xff;
1238  }
1239  break;
1240  case HC_COMPR_16:
1241  if ( GetDac () == false )
1242  {
1243  memset (temp, 0x00, sizeof (temp));
1244  i.Read (temp + 1, 1);
1245  i.Read (temp + 13, 3);
1246  temp[0] = 0xff;
1248  }
1249  break;
1250  case HC_COMPR_0:
1251  default:
1252  if ( GetDac () == false )
1253  {
1254  memset (temp, 0x00, sizeof (temp));
1255  temp[15] = i.ReadU8 ();
1256  temp[0] = 0xff;
1257  temp[1] = 0x02;
1259  }
1260  break;
1261  }
1262  }
1263  if ( GetDac () == true )
1264  {
1265  PostProcessDac ();
1266  }
1267  return GetSerializedSize ();
1268 }
1269 
1271 {
1272  uint16_t field = tfField;
1273  m_baseFormat |= (field << 11);
1274 }
1275 
1277 {
1278  return TrafficClassFlowLabel_e ((m_baseFormat >> 11) & 0x3);
1279 }
1280 
1281 void SixLowPanIphc::SetNh (bool nhField)
1282 {
1283  uint16_t field = nhField;
1284  m_baseFormat |= (field << 10);
1285 }
1286 
1287 bool SixLowPanIphc::GetNh (void) const
1288 {
1289  return ((m_baseFormat >> 10) & 0x1);
1290 }
1291 
1293 {
1294  uint16_t field = hlimField;
1295  m_baseFormat |= (field << 8);
1296 }
1297 
1299 {
1300  return Hlim_e ((m_baseFormat >> 8) & 0x3);
1301 }
1302 
1303 void SixLowPanIphc::SetCid (bool cidField)
1304 {
1305  uint16_t field = cidField;
1306  m_baseFormat |= (field << 7);
1307 }
1308 
1309 bool SixLowPanIphc::GetCid (void) const
1310 {
1311  return ((m_baseFormat >> 7) & 0x1);
1312 }
1313 
1314 void SixLowPanIphc::SetSac (bool sacField)
1315 {
1316  uint16_t field = sacField;
1317  m_baseFormat |= (field << 6);
1318 }
1319 
1320 bool SixLowPanIphc::GetSac (void) const
1321 {
1322  return ((m_baseFormat >> 6) & 0x1);
1323 }
1324 
1326 {
1327  uint16_t field = samField;
1328  m_baseFormat |= (field << 4);
1329 }
1330 
1332 {
1333  return HeaderCompression_e ((m_baseFormat >> 4) & 0x3);
1334 }
1335 
1336 void SixLowPanIphc::SetM (bool mField)
1337 {
1338  uint16_t field = mField;
1339  m_baseFormat |= (field << 3);
1340 }
1341 
1342 bool SixLowPanIphc::GetM (void) const
1343 {
1344  return ((m_baseFormat >> 3) & 0x1);
1345 }
1346 
1347 void SixLowPanIphc::SetDac (bool dacField)
1348 {
1349  uint16_t field = dacField;
1350  m_baseFormat |= (field << 2);
1351 }
1352 
1353 bool SixLowPanIphc::GetDac (void) const
1354 {
1355  return ((m_baseFormat >> 2) & 0x1);
1356 }
1357 
1359 {
1360  uint16_t field = damField;
1361  m_baseFormat |= field;
1362 }
1363 
1365 {
1366  return HeaderCompression_e (m_baseFormat & 0x3);
1367 }
1368 
1369 void SixLowPanIphc::SetSrcContextId (uint8_t srcContextId)
1370 {
1371  NS_ASSERT_MSG (srcContextId < 16, "Src Context ID too large");
1372  m_srcdstContextId |= srcContextId << 4;
1373 }
1374 
1376 {
1377  return ( m_srcdstContextId >> 4);
1378 }
1379 
1380 void SixLowPanIphc::SetDstContextId (uint8_t dstContextId)
1381 {
1382  NS_ASSERT_MSG (dstContextId < 16, "Dst Context ID too large");
1383  m_srcdstContextId |= (dstContextId & 0xF);
1384 }
1385 
1387 {
1388  return (m_srcdstContextId & 0xF);
1389 }
1390 
1391 void SixLowPanIphc::SetEcn (uint8_t ecn)
1392 {
1393  NS_ASSERT_MSG (ecn < 4, "ECN too large");
1394  m_ecn = ecn;
1395 }
1396 
1397 uint8_t SixLowPanIphc::GetEcn (void) const
1398 {
1399  return m_ecn;
1400 }
1401 
1402 void SixLowPanIphc::SetDscp (uint8_t dscp)
1403 {
1404  NS_ASSERT_MSG (dscp < 64, "DSCP too large");
1405  m_dscp = dscp;
1406 }
1407 
1408 uint8_t SixLowPanIphc::GetDscp (void) const
1409 {
1410  return m_dscp;
1411 }
1412 
1413 void SixLowPanIphc::SetFlowLabel (uint32_t flowLabel)
1414 {
1415  NS_ASSERT_MSG (flowLabel < 0x100000, "Flow Label too large");
1416  m_flowLabel = flowLabel;
1417 }
1418 
1419 uint32_t SixLowPanIphc::GetFlowLabel (void) const
1420 {
1421  return m_flowLabel;
1422 }
1423 
1424 void SixLowPanIphc::SetNextHeader (uint8_t nextHeader)
1425 {
1426  m_nextHeader = nextHeader;
1427 }
1428 
1429 uint8_t SixLowPanIphc::GetNextHeader (void) const
1430 {
1431  return m_nextHeader;
1432 }
1433 
1434 void SixLowPanIphc::SetHopLimit (uint8_t hopLimit)
1435 {
1436  m_hopLimit = hopLimit;
1437 }
1438 
1439 uint8_t SixLowPanIphc::GetHopLimit (void) const
1440 {
1441  return m_hopLimit;
1442 }
1443 
1445 {
1446  m_srcAddress = srcAddress;
1447 }
1448 
1450 {
1451  return m_srcAddress;
1452 }
1453 
1455 {
1456  m_dstAddress = dstAddress;
1457 }
1458 
1460 {
1461  return m_dstAddress;
1462 }
1463 
1465 {
1466  NS_ABORT_MSG ("Unsupported; Context destination is not implemented");
1467  return;
1468 }
1469 
1471 {
1472  NS_ABORT_MSG ("Unsupported; Context destination is not implemented");
1473  return;
1474 }
1475 
1476 std::ostream & operator << (std::ostream & os, const SixLowPanIphc & h)
1477 {
1478  h.Print (os);
1479  return os;
1480 }
1481 
1482 /*
1483  * SixLowPanNhcExtensionHeader
1484  */
1485 NS_OBJECT_ENSURE_REGISTERED (SixLowPanNhcExtension);
1486 
1488 {
1489  // 1110 xxxx
1490  m_nhcExtensionHeader = 0xE0;
1491  m_nhcNextHeader = 0;
1492  m_nhcBlobLength = 0;
1493 }
1494 
1496 {
1497  static TypeId tid = TypeId ("ns3::SixLowPanNhcExtension")
1498  .SetParent<Header> ()
1499  .SetGroupName ("SixLowPan")
1500  .AddConstructor<SixLowPanNhcExtension> ();
1501  return tid;
1502 }
1503 
1505 {
1506  return GetTypeId ();
1507 }
1508 
1509 void SixLowPanNhcExtension::Print (std::ostream & os) const
1510 {
1511  os << "Compression kind: " << static_cast<int> (m_nhcExtensionHeader) << " Size: " << GetSerializedSize ();
1512 }
1513 
1515 {
1516  uint32_t serializedSize = 2;
1517  if ( GetNh () == false )
1518  {
1519  serializedSize++;
1520  }
1521  return serializedSize + m_nhcBlobLength;
1522 }
1523 
1525 {
1526  Buffer::Iterator i = start;
1528  if ( GetNh () == false )
1529  {
1531  }
1534 }
1535 
1537 {
1538  Buffer::Iterator i = start;
1540  if ( GetNh () == false )
1541  {
1542  m_nhcNextHeader = i.ReadU8 ();
1543  }
1544  m_nhcBlobLength = i.ReadU8 ();
1546 
1547  return GetSerializedSize ();
1548 }
1549 
1552 {
1554 }
1555 
1556 void SixLowPanNhcExtension::SetEid (Eid_e extensionHeaderType)
1557 {
1558  uint8_t field = extensionHeaderType;
1559  m_nhcExtensionHeader |= (field << 1);
1560 }
1561 
1563 {
1564  return Eid_e ((m_nhcExtensionHeader >> 1) & 0x7);
1565 }
1566 
1567 void SixLowPanNhcExtension::SetNextHeader (uint8_t nextHeader)
1568 {
1569  m_nhcNextHeader = nextHeader;
1570 }
1571 
1573 {
1574  return m_nhcNextHeader;
1575 }
1576 
1577 void SixLowPanNhcExtension::SetNh (bool nhField)
1578 {
1579  uint8_t field = nhField;
1580  m_nhcExtensionHeader |= field;
1581 }
1582 
1584 {
1585  return m_nhcExtensionHeader & 0x01;
1586 }
1587 
1588 void SixLowPanNhcExtension::SetBlob (const uint8_t* blob, uint32_t size)
1589 {
1590  NS_ASSERT_MSG ( size < 255, "Buffer too long" );
1591 
1592  m_nhcBlobLength = size;
1593  std::memcpy (m_nhcBlob, blob, size);
1594 }
1595 
1596 uint32_t SixLowPanNhcExtension::CopyBlob (uint8_t* blob, uint32_t size) const
1597 {
1598  NS_ASSERT_MSG ( size > m_nhcBlobLength, "Buffer too short" );
1599 
1600  std::memcpy (blob, m_nhcBlob, m_nhcBlobLength);
1601  return m_nhcBlobLength;
1602 }
1603 
1604 std::ostream & operator << (std::ostream & os, const SixLowPanNhcExtension & h)
1605 {
1606  h.Print (os);
1607  return os;
1608 }
1609 
1610 /*
1611  * SixLowPanUdpNhcExtension
1612  */
1613 NS_OBJECT_ENSURE_REGISTERED (SixLowPanUdpNhcExtension);
1614 
1616 {
1617  // 1111 0xxx
1618  m_baseFormat = 0xF0;
1619  m_checksum = 0;
1620  m_srcPort = 0;
1621  m_dstPort = 0;
1622 }
1623 
1625 {
1626  static TypeId tid = TypeId ("ns3::SixLowPanUdpNhcExtension")
1627  .SetParent<Header> ()
1628  .SetGroupName ("SixLowPan")
1629  .AddConstructor<SixLowPanUdpNhcExtension> ();
1630  return tid;
1631 }
1632 
1634 {
1635  return GetTypeId ();
1636 }
1637 
1638 void SixLowPanUdpNhcExtension::Print (std::ostream & os) const
1639 {
1640  os << "Compression kind: " << static_cast<int> (m_baseFormat);
1641 }
1642 
1644 {
1645  uint32_t serializedSize = 1;
1646  if ( !GetC () )
1647  {
1648  serializedSize += 2;
1649  }
1650  switch (GetPorts ())
1651  {
1652  case PORTS_INLINE:
1653  serializedSize += 4;
1654  break;
1657  serializedSize += 3;
1658  break;
1660  serializedSize += 1;
1661  break;
1662  default:
1663  break;
1664  }
1665  return serializedSize;
1666 }
1667 
1669 {
1670  Buffer::Iterator i = start;
1671  i.WriteU8 (m_baseFormat);
1672  uint8_t temp;
1673 
1674  // Ports
1675  switch ( GetPorts () )
1676  {
1677  case PORTS_INLINE:
1678  i.WriteHtonU16 (m_srcPort);
1679  i.WriteHtonU16 (m_dstPort);
1680  break;
1682  i.WriteHtonU16 (m_srcPort);
1683  i.WriteU8 (m_dstPort & 0xff);
1684  break;
1686  i.WriteU8 (m_srcPort & 0xff);
1687  i.WriteHtonU16 (m_dstPort);
1688  break;
1690  temp = ((m_srcPort & 0xf) << 4) | (m_dstPort & 0xf);
1691  i.WriteU8 (temp);
1692  break;
1693  default:
1694  break;
1695  }
1696 
1697  // Checksum
1698  if ( !GetC () )
1699  {
1700  i.WriteU16 (m_checksum);
1701  }
1702 
1703 }
1704 
1706 {
1707  Buffer::Iterator i = start;
1708  m_baseFormat = i.ReadU8 ();
1709  uint8_t temp;
1710 
1711  // Ports
1712  switch ( GetPorts () )
1713  {
1714  case PORTS_INLINE:
1715  m_srcPort = i.ReadNtohU16 ();
1716  m_dstPort = i.ReadNtohU16 ();
1717  break;
1719  m_srcPort = i.ReadNtohU16 ();
1720  m_dstPort = i.ReadU8 ();
1721  break;
1723  m_srcPort = i.ReadU8 ();
1724  m_dstPort = i.ReadNtohU16 ();
1725  break;
1727  temp = i.ReadU8 ();
1728  m_srcPort = temp >> 4;
1729  m_dstPort = temp & 0xf;
1730  break;
1731  default:
1732  break;
1733  }
1734 
1735  // Checksum
1736  if ( !GetC () )
1737  {
1738  m_checksum = i.ReadU16 ();
1739  }
1740 
1741  return GetSerializedSize ();
1742 }
1743 
1746 {
1748 }
1749 
1751 {
1752  uint16_t field = ports;
1753  m_baseFormat |= field;
1754 }
1755 
1757 {
1758  return Ports_e (m_baseFormat & 0x3);
1759 }
1760 
1762 {
1763  m_srcPort = srcport;
1764 }
1765 
1767 {
1768  return m_srcPort;
1769 }
1770 
1772 {
1773  m_dstPort = dstport;
1774 }
1775 
1777 {
1778  return m_dstPort;
1779 }
1780 
1782 {
1783  uint16_t field = cField;
1784  m_baseFormat |= (field << 2);
1785 }
1786 
1788 {
1789  return ((m_baseFormat >> 2) & 0x1);
1790 }
1791 
1793 {
1794  m_checksum = checksum;
1795 }
1796 
1798 {
1799  return m_checksum;
1800 }
1801 
1802 std::ostream & operator << (std::ostream & os, const SixLowPanUdpNhcExtension & h)
1803 {
1804  h.Print (os);
1805  return os;
1806 }
1807 
1808 
1809 }
1810 
uint16_t ReadU16(void)
Definition: buffer.h:1029
Protocol header serialization and deserialization.
Definition: header.h:42
static TypeId GetTypeId(void)
Get the type ID.
void SetCid(bool cidField)
Set the CID (Context Identifier Extension) compression.
uint8_t GetNextHeader(void) const
Get the Next Header field.
Ports_e GetPorts(void) const
Get the compressed Src and Dst Ports.
void SetTcflCompression(bool tcflCompression)
Set the Traffic Class and Flow Labels as compressed.
uint8_t m_ecn
ECN bits.
virtual uint32_t GetSerializedSize(void) const
Get the serialized size of the packet.
uint8_t GetNextHeader() const
Get the Next Header value.
Ipv6Address m_dstAddress
Dst address.
uint16_t m_dstPort
Destination port.
static TypeId GetTypeId(void)
Get the type ID.
void SetHopLimit(uint8_t hopLimit)
Set the Hop Limit field.
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Definition: abort.h:50
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
void SetDstCompression(LowPanHc1Addr_e dstCompression)
Set Destination Compression type.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
6LoWPAN IPv6 uncompressed header - see RFC 4944.
virtual void Print(std::ostream &os) const
virtual SixLowPanDispatch::NhcDispatch_e GetNhcDispatchType(void) const
Get the NhcDispatch type.
void SetNextHeader(uint8_t nextHeader)
Set the Next Header field values.
uint8_t m_nhcBlob[256]
NHC compressed header.
static Ipv6Address Deserialize(const uint8_t buf[16])
Deserialize this address.
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
static Dispatch_e GetDispatchType(uint8_t dispatch)
Get the Dispatch type.
LOWPAN_IPHC base Encoding - see RFC 6282.
def start()
Definition: core.py:1790
void PostProcessDac()
Post-process the Destination address stateful compression.
void SetPorts(Ports_e port)
Set the compressed Src and Dst Ports.
void SetSrcCompression(LowPanHc1Addr_e srcCompression)
Set Source Compression type.
void SetSrcContextId(uint8_t srcContextId)
Set the SrcContextId.
uint16_t GetDatagramSize(void) const
Get the datagram size.
LowPanHc1Addr_e m_srcCompression
Source compression type.
uint16_t GetDatagramSize(void) const
Get the datagram size.
virtual void Print(std::ostream &os) const
LOWPAN_NHC Extension Header Encoding - see RFC 6282.
LowPanHc1NextHeader_e
Next header information.
void SetDatagramOffset(uint8_t datagramOffset)
Set the datagram offset.
virtual TypeId GetInstanceTypeId(void) const
Return the instance type identifier.
void SetSam(HeaderCompression_e samField)
Set the SAM (Source Address Mode) compression.
virtual void Print(std::ostream &os) const
6LoWPAN FRAGN header - see RFC 4944.
TrafficClassFlowLabel_e GetTf(void) const
Get the TF (Traffic Class, Flow Label) compression.
void SetDatagramSize(uint16_t datagramSize)
Set the datagram size.
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
static TypeId GetTypeId(void)
Get the type ID.
bool IsTcflCompression() const
Check if the Traffic Class and Flow Labels are compressed.
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
bool GetM(void) const
Get the M (Multicast) compression.
void SetTrafficClass(uint8_t trafficClass)
Set the Traffic Class value.
virtual SixLowPanDispatch::NhcDispatch_e GetNhcDispatchType(void) const
Get the NhcDispatch type.
iterator in a Buffer instance
Definition: buffer.h:98
uint8_t m_srcPrefix[8]
Source prefix.
uint16_t GetDstPort() const
Get the Destination Port.
bool GetNh(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.
uint8_t GetDscp(void) const
Get the DSCP.
void SetHlim(Hlim_e hlimField)
Set the HLIM (Hop Limit) compression.
virtual TypeId GetInstanceTypeId(void) const
Return the instance type identifier.
virtual uint32_t GetSerializedSize(void) const
Get the serialized size of the packet.
virtual TypeId GetInstanceTypeId(void) const
Return the instance type identifier.
uint16_t m_srcPort
Source port.
uint16_t GetDatagramTag(void) const
Get the datagram tag.
Ipv6Address GetSrcAddress() const
Get the Source Address.
LowPanHc1Addr_e
Kind of address compression.
uint16_t GetSrcPort() const
Get the Source Port.
void SetBlob(const uint8_t *blob, uint32_t size)
Set the option header data blob.
const uint8_t * GetSrcInterface() const
Get the source interface.
Hlim_e
HLIM: Hop Limit.
void SetHc2HeaderPresent(bool hc2HeaderPresent)
Set the next header a HC2 compressed header.
virtual uint32_t GetSerializedSize(void) const
Get the serialized size of the packet.
bool GetCid(void) const
Get the CID (Context Identifier Extension) compression.
void SetDscp(uint8_t dscp)
Set the DSCP (6bits).
uint8_t GetTrafficClass() const
Get the Traffic Class value.
uint16_t m_datagramTag
Datagram tag.
uint8_t m_hopLimit
Hop Limit.
void SetDstInterface(const uint8_t *dstInterface)
Set the destination interface.
LowPanHc1Addr_e m_dstCompression
Destination compression type.
void SetSac(bool sacField)
Set the SAC (Source Address Compression) compression.
void WriteU16(uint16_t data)
Definition: buffer.cc:873
bool IsHc2HeaderPresent() const
Check if there is a HC2 compressed header.
void WriteHtonU16(uint16_t data)
Definition: buffer.h:905
uint16_t m_datagramSize
Datagram size.
void SetNh(bool nhField)
Set the NH (Next Header) compression.
Ipv6Address GetDstAddress() const
Get the Destination Address.
void SetChecksum(uint16_t checksum)
Set the Checksum field values.
uint16_t GetDatagramTag(void) const
Get the datagram tag.
uint8_t GetHopLimit(void) const
Get the Hop Limit field.
LowPanHc1Addr_e GetDstCompression() const
Get Destination Compression type.
uint8_t GetEcn(void) const
Get the ECN.
void SetDstPort(uint16_t port)
Set the Destination Port.
uint32_t m_flowLabel
Flow Label.
void SetDatagramSize(uint16_t datagramSize)
Set the datagram size.
static TypeId GetTypeId(void)
Get the type ID.
uint8_t GetHopLimit(void) const
Get the "Hop limit" field (TTL).
bool GetNh(void) const
Get the NH (Next Header) compression.
HeaderCompression_e GetDam(void) const
Get the DAM (Destination Address Mode) compression.
virtual void Print(std::ostream &os) const
Hlim_e GetHlim(void) const
Get the HLIM (Hop Limit) compression.
uint8_t GetSrcContextId(void) const
Get the SrcContextId.
void SetSrcPort(uint16_t port)
Set the Source Port.
HeaderCompression_e GetSam(void) const
Get the SAM (Source Address Mode) compression.
virtual uint32_t GetSerializedSize(void) const
Get the serialized size of the packet.
virtual void Print(std::ostream &os) const
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
Definition: angles.cc:42
uint16_t m_datagramTag
Datagram tag.
uint8_t m_dscp
DSCP bits.
static TypeId GetTypeId(void)
Get the type ID.
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void SetNextHeader(uint8_t nextHeader)
Set the Next Header field.
TrafficClassFlowLabel_e
TF: Traffic Class, Flow Label.
uint32_t GetFlowLabel() const
Get the Flow Label value.
virtual void Print(std::ostream &os) const
uint8_t m_trafficClass
Traffic Class.
bool GetC(void) const
Get the C (Checksum).
bool GetSac(void) const
Get the SAC (Source Address Compression) compression.
void SetDstContextId(uint8_t dstContextId)
Set the DstContextId.
virtual TypeId GetInstanceTypeId(void) const
Return the instance type identifier.
void SetSrcAddress(Ipv6Address srcAddress)
Set the Source Address.
bool GetDac(void) const
Get the DAC (Destination Address Compression) compression.
LowPanHc1NextHeader_e m_nextHeaderCompression
Next header compression.
void Read(uint8_t *buffer, uint32_t size)
Definition: buffer.cc:1126
const uint8_t * GetDstPrefix() const
Get the destination prefix.
virtual TypeId GetInstanceTypeId(void) const
Return the instance type identifier.
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
uint8_t GetNextHeader(void) const
Get the Next Header field value.
6LoWPAN HC1 header - see RFC 4944.
Dispatch_e
Dispatch values, as defined in RFC 4944 and RFC 6282
void SetHopLimit(uint8_t limit)
Set the "Hop limit" field (TTL).
void SetDac(bool dacField)
Set the DAC (Destination Address Compression) compression.
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
uint8_t m_hopLimit
Hop Limit.
virtual uint32_t GetSerializedSize(void) const
Get the serialized size of the packet.
#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:90
uint8_t m_nhcExtensionHeader
NHC extension header type.
void SetSrcInterface(const uint8_t *srcInterface)
Set the source interface.
virtual TypeId GetInstanceTypeId(void) const
Return the instance type identifier.
void SetDstPrefix(const uint8_t *dstPrefix)
Set the destination prefix.
Describes an IPv6 address.
Definition: ipv6-address.h:48
Ipv6Address m_srcAddress
Src address.
Eid_e
EID: IPv6 Extension Header ID.
void SetFlowLabel(uint32_t flowLabel)
Set the Flow Label (20bits).
void WriteU8(uint8_t data)
Definition: buffer.h:869
Eid_e GetEid(void) const
Get the Extension Header Type.
uint8_t m_datagramOffset
Datagram offset.
bool m_tcflCompression
Is TC and FL compressed.
uint32_t m_flowLabel
Flow Label bits.
uint8_t m_dstPrefix[8]
Destination prefix.
const uint8_t * GetSrcPrefix() const
Get the source prefix.
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
uint16_t m_datagramSize
Datagram size.
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
uint8_t m_baseFormat
Dispatch + encoding fields.
uint8_t m_srcInterface[8]
Source interface.
uint8_t m_nhcBlobLength
Length of the NHC compressed header.
uint32_t GetFlowLabel(void) const
Get the Flow Label.
uint8_t GetDstContextId(void) const
Get the DstContextId.
static NhcDispatch_e GetNhcDispatchType(uint8_t dispatch)
Get the NhcDispatch type.
uint16_t m_baseFormat
Dispatch + encoding fields.
virtual uint32_t GetSerializedSize(void) const
Get the serialized size of the packet.
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
void SetEid(Eid_e extensionHeaderType)
Set the Extension Header Type.
uint8_t ReadU8(void)
Definition: buffer.h:1021
void Write(uint8_t const *buffer, uint32_t size)
Definition: buffer.cc:956
bool m_hc2HeaderPresent
Is next header HC2 compressed.
void SetNh(bool nhField)
Set the NH field values.
uint8_t m_nhcNextHeader
Next header.
void SetTf(TrafficClassFlowLabel_e tfField)
Set the TF (Traffic Class, Flow Label) compression.
uint32_t CopyBlob(uint8_t *blob, uint32_t size) const
Get the option header data blob.
const uint8_t * GetDstInterface() const
Get the destination interface.
void SetDstAddress(Ipv6Address dstAddress)
Set the Destination Address.
uint8_t m_nextHeader
Next header.
static TypeId GetTypeId(void)
Get the type ID.
void SetM(bool mField)
Set the M (Multicast) compression.
NhcDispatch_e
Dispatch values for Next Header compression.
void SetSrcPrefix(const uint8_t *srcPrefix)
Set the source prefix.
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
uint16_t ReadNtohU16(void)
Definition: buffer.h:946
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
void SetDatagramTag(uint16_t datagramTag)
Set the datagram tag.
void SetEcn(uint8_t ecn)
Set the ECN (2bits).
6LoWPAN FRAG1 header - see RFC 4944.
uint8_t GetDatagramOffset(void) const
Get the datagram offset.
LowPanHc1Addr_e GetSrcCompression() const
Get Source Compression type.
a unique identifier for an interface.
Definition: type-id.h:58
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:914
uint8_t m_dstInterface[8]
Destination interface.
UDP LOWPAN_NHC Extension Header Encoding - see RFC 6282.
uint8_t m_nextHeader
Next header.
void SetC(bool cField)
Set the C (Checksum).
HeaderCompression_e
Source or Destination Address Mode.
uint8_t m_srcdstContextId
Src and Dst Context ID.
void SetNextHeader(uint8_t nextHeader)
Set the Next Header value.
virtual uint32_t GetSerializedSize(void) const
Get the serialized size of the packet.
void SetDam(HeaderCompression_e damField)
Set the DAM (Destination Address Mode) compression.
void SetFlowLabel(uint32_t flowLabel)
Set the Flow Label value.
void SetDatagramTag(uint16_t datagramTag)
Set the datagram tag.
uint16_t GetChecksum(void) const
Get the Checksum field value.
void PostProcessSac()
Post-process the Source address stateful compression.
virtual void Print(std::ostream &os) const
void Serialize(uint8_t buf[16]) const
Serialize this address to a 16-byte buffer.