A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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").SetParent<Header> ().AddConstructor<SixLowPanHc1> ();
107  return tid;
108 }
109 
111 {
112  return GetTypeId ();
113 }
114 
115 void SixLowPanHc1::Print (std::ostream & os) const
116 {
117  uint8_t encoding;
118  encoding = m_srcCompression;
119  encoding <<= 2;
120  encoding |= m_dstCompression;
121  encoding <<= 1;
122  encoding |= m_tcflCompression;
123  encoding <<= 2;
124  encoding |= m_nextHeaderCompression;
125  encoding <<= 1;
126  encoding |= m_hc2HeaderPresent;
127 
128  os << "encoding " << int(encoding) << ", hopLimit " << int(m_hopLimit);
129 }
130 
132 {
133  uint32_t serializedSize = 3;
134 
135  switch (m_srcCompression)
136  {
137  case HC1_PIII:
138  serializedSize += 16;
139  break;
140  case HC1_PIIC:
141  serializedSize += 8;
142  break;
143  case HC1_PCII:
144  serializedSize += 8;
145  break;
146  case HC1_PCIC:
147  break;
148  }
149  switch (m_dstCompression)
150  {
151  case HC1_PIII:
152  serializedSize += 16;
153  break;
154  case HC1_PIIC:
155  serializedSize += 8;
156  break;
157  case HC1_PCII:
158  serializedSize += 8;
159  break;
160  case HC1_PCIC:
161  break;
162  }
163 
164  if (m_tcflCompression == false )
165  {
166  serializedSize += 4;
167  }
168 
170  {
171  serializedSize++;
172  }
173 
174  return serializedSize;
175 }
176 
178 {
180  uint8_t encoding;
181  encoding = m_srcCompression;
182  encoding <<= 2;
183  encoding |= m_dstCompression;
184  encoding <<= 1;
185  encoding |= m_tcflCompression;
186  encoding <<= 2;
187  encoding |= m_nextHeaderCompression;
188  encoding <<= 1;
189  encoding |= m_hc2HeaderPresent;
190 
192  i.WriteU8 (encoding);
193  i.WriteU8 (m_hopLimit);
194  switch (m_srcCompression)
195  {
196  case HC1_PIII:
197  for ( int j = 0; j < 8; j++ )
198  {
199  i.WriteU8 (m_srcPrefix[j]);
200  }
201  for ( int j = 0; j < 8; j++ )
202  {
203  i.WriteU8 (m_srcInterface[j]);
204  }
205  break;
206  case HC1_PIIC:
207  for ( int j = 0; j < 8; j++ )
208  {
209  i.WriteU8 (m_srcPrefix[j]);
210  }
211  break;
212  case HC1_PCII:
213  for ( int j = 0; j < 8; j++ )
214  {
215  i.WriteU8 (m_srcInterface[j]);
216  }
217  break;
218  case HC1_PCIC:
219  break;
220  }
221  switch (m_dstCompression)
222  {
223  case HC1_PIII:
224  for ( int j = 0; j < 8; j++ )
225  {
226  i.WriteU8 (m_dstPrefix[j]);
227  }
228  for ( int j = 0; j < 8; j++ )
229  {
230  i.WriteU8 (m_dstInterface[j]);
231  }
232  break;
233  case HC1_PIIC:
234  for ( int j = 0; j < 8; j++ )
235  {
236  i.WriteU8 (m_dstPrefix[j]);
237  }
238  break;
239  case HC1_PCII:
240  for ( int j = 0; j < 8; j++ )
241  {
242  i.WriteU8 (m_dstInterface[j]);
243  }
244  break;
245  case HC1_PCIC:
246  break;
247  }
248 
249  if ( m_tcflCompression == false )
250  {
252  uint8_t temp[3];
253  temp[0] = uint8_t (m_flowLabel & 0xff);
254  temp[1] = uint8_t ((m_flowLabel >> 8) & 0xff);
255  temp[2] = uint8_t ((m_flowLabel >> 16) & 0xff);
256  i.Write (temp, 3);
257  }
258 
260  {
261  i.WriteU8 (m_nextHeader);
262  }
263 
264  // TODO: HC2 is not yet supported. Should be.
265  NS_ASSERT_MSG ( m_hc2HeaderPresent != true, "Can not compress HC2, exiting. Very sorry." );
266 }
267 
269 {
271  uint32_t serializedSize = 3;
272 
273  uint8_t dispatch = i.ReadU8 ();
274  if (dispatch != SixLowPanDispatch::LOWPAN_HC1)
275  {
276  return 0;
277  }
278 
279  uint8_t encoding = i.ReadU8 ();
280  m_hopLimit = i.ReadU8 ();
281 
282  m_srcCompression = LowPanHc1Addr_e (encoding >> 6);
283  m_dstCompression = LowPanHc1Addr_e ( (encoding >> 4) & 0x3);
284  m_tcflCompression = (encoding >> 3) & 0x1;
285  m_nextHeaderCompression = LowPanHc1NextHeader_e ( (encoding >> 1) & 0x3);
286  m_hc2HeaderPresent = encoding & 0x1;
287 
288  switch (m_srcCompression)
289  {
290  case HC1_PIII:
291  for ( int j = 0; j < 8; j++)
292  {
293  m_srcPrefix[j] = i.ReadU8 ();
294  }
295  for ( int j = 0; j < 8; j++)
296  {
297  m_srcInterface[j] = i.ReadU8 ();
298  }
299  serializedSize += 16;
300  break;
301  case HC1_PIIC:
302  for ( int j = 0; j < 8; j++)
303  {
304  m_srcPrefix[j] = i.ReadU8 ();
305  }
306  serializedSize += 8;
307  break;
308  case HC1_PCII:
309  for ( int j = 0; j < 8; j++)
310  {
311  m_srcInterface[j] = i.ReadU8 ();
312  }
313  serializedSize += 8;
314  break;
315  case HC1_PCIC:
316  break;
317  }
318  switch (m_dstCompression)
319  {
320  case HC1_PIII:
321  for ( int j = 0; j < 8; j++)
322  {
323  m_dstPrefix[j] = i.ReadU8 ();
324  }
325  for ( int j = 0; j < 8; j++)
326  {
327  m_dstInterface[j] = i.ReadU8 ();
328  }
329  serializedSize += 16;
330  break;
331  case HC1_PIIC:
332  for ( int j = 0; j < 8; j++)
333  {
334  m_dstPrefix[j] = i.ReadU8 ();
335  }
336  serializedSize += 8;
337  break;
338  case HC1_PCII:
339  for ( int j = 0; j < 8; j++)
340  {
341  m_dstInterface[j] = i.ReadU8 ();
342  }
343  serializedSize += 8;
344  break;
345  case HC1_PCIC:
346  break;
347  }
348 
349  if ( m_tcflCompression == false )
350  {
351  m_trafficClass = i.ReadU8 ();
352  uint8_t temp[3];
353  i.Read (temp, 3);
354  m_flowLabel = temp[2];
355  m_flowLabel = (m_flowLabel << 8) | temp[1];
356  m_flowLabel = (m_flowLabel << 8) | temp[0];
357  serializedSize += 4;
358  }
359 
360  switch ( m_nextHeaderCompression )
361  {
362  case HC1_NC:
363  m_nextHeader = i.ReadU8 ();
364  serializedSize++;
365  break;
366  case HC1_TCP:
368  break;
369  case HC1_UDP:
371  break;
372  case HC1_ICMP:
374  break;
375  }
376 
377  NS_ASSERT_MSG ( m_hc2HeaderPresent != true, "Can not compress HC2, exiting. Very sorry." );
378 
379  return GetSerializedSize ();
380 }
381 
382 void SixLowPanHc1::SetHopLimit (uint8_t limit)
383 {
384  m_hopLimit = limit;
385 }
386 
388 {
389  return m_hopLimit;
390 }
391 
393 {
394  return m_dstCompression;
395 }
396 
397 const uint8_t* SixLowPanHc1::GetDstInterface () const
398 {
399  return m_dstInterface;
400 }
401 
402 const uint8_t* SixLowPanHc1::GetDstPrefix () const
403 {
404  return m_dstPrefix;
405 }
406 
407 uint32_t SixLowPanHc1::GetFlowLabel () const
408 {
409  return m_flowLabel;
410 }
411 
413 {
414  return m_nextHeader;
415 }
416 
418 {
419  return m_srcCompression;
420 }
421 
422 const uint8_t* SixLowPanHc1::GetSrcInterface () const
423 {
424  return m_srcInterface;
425 }
426 
427 const uint8_t* SixLowPanHc1::GetSrcPrefix () const
428 {
429  return m_srcPrefix;
430 }
431 
433 {
434  return m_trafficClass;
435 }
436 
438 {
439  return m_tcflCompression;
440 }
441 
443 {
444  return m_hc2HeaderPresent;
445 }
446 
448 {
449  m_dstCompression = dstCompression;
450 }
451 
452 void SixLowPanHc1::SetDstInterface (const uint8_t* dstInterface)
453 {
454  for ( int i = 0; i < 8; i++)
455  {
456  m_dstInterface[i] = dstInterface[i];
457  }
458 }
459 
460 void SixLowPanHc1::SetDstPrefix (const uint8_t* dstPrefix)
461 {
462  for ( int i = 0; i < 8; i++)
463  {
464  m_dstPrefix[i] = dstPrefix[i];
465  }
466 }
467 
468 void SixLowPanHc1::SetFlowLabel (uint32_t flowLabel)
469 {
470  m_flowLabel = flowLabel;
471 }
472 
473 void SixLowPanHc1::SetNextHeader (uint8_t nextHeader)
474 {
475  m_nextHeader = nextHeader;
476 
477  switch (m_nextHeader)
478  {
481  break;
484  break;
487  break;
488  default:
490  break;
491  }
492 }
493 
495 {
496  m_srcCompression = srcCompression;
497 }
498 
499 void SixLowPanHc1::SetSrcInterface (const uint8_t* srcInterface)
500 {
501  for ( int i = 0; i < 8; i++)
502  {
503  m_srcInterface[i] = srcInterface[i];
504  }
505 }
506 
507 void SixLowPanHc1::SetSrcPrefix (const uint8_t* srcPrefix)
508 {
509  for ( int i = 0; i < 8; i++)
510  {
511  m_srcPrefix[i] = srcPrefix[i];
512  }
513 }
514 
515 void SixLowPanHc1::SetTcflCompression (bool tcflCompression)
516 {
517  m_tcflCompression = tcflCompression;
518 }
519 
520 void SixLowPanHc1::SetTrafficClass (uint8_t trafficClass)
521 {
522  m_trafficClass = trafficClass;
523 }
524 
525 
526 void SixLowPanHc1::SetHc2HeaderPresent (bool hc2HeaderPresent)
527 {
528  m_hc2HeaderPresent = hc2HeaderPresent;
529 }
530 
531 
532 std::ostream & operator << (std::ostream & os, const SixLowPanHc1 & h)
533 {
534  h.Print (os);
535  return os;
536 }
537 
538 /*
539  * SixLowPanFrag1
540  */
541 NS_OBJECT_ENSURE_REGISTERED (SixLowPanFrag1);
542 
544  : m_datagramSize (0),
545  m_datagramTag (0)
546 {
547 }
548 
550 {
551  static TypeId tid = TypeId ("ns3::SixLowPanFrag1").SetParent<Header> ().AddConstructor<SixLowPanFrag1> ();
552  return tid;
553 }
554 
556 {
557  return GetTypeId ();
558 }
559 
560 void SixLowPanFrag1::Print (std::ostream & os) const
561 {
562  os << "datagram size " << m_datagramSize << " tag " << m_datagramTag;
563 }
564 
566 {
567  return 4;
568 }
569 
571 {
573 
574  uint16_t temp = m_datagramSize | ( uint16_t (SixLowPanDispatch::LOWPAN_FRAG1) << 8 );
575 
576  i.WriteU8 (uint8_t (temp >> 8));
577  i.WriteU8 (uint8_t (temp & 0xff));
578 
580 }
581 
583 {
585 
586  uint8_t temp = i.ReadU8 ();
587  m_datagramSize = (uint16_t (temp) << 8) | i.ReadU8 ();
588  m_datagramSize &= 0x7FF;
589 
590  m_datagramTag = i.ReadU16 ();
591  return GetSerializedSize ();
592 }
593 
594 void SixLowPanFrag1::SetDatagramSize (uint16_t datagramSize)
595 {
596  m_datagramSize = datagramSize & 0x7FF;
597 }
598 
600 {
601  return m_datagramSize & 0x7FF;
602 }
603 
604 void SixLowPanFrag1::SetDatagramTag (uint16_t datagramTag)
605 {
606  m_datagramTag = datagramTag;
607 }
608 
610 {
611  return m_datagramTag;
612 }
613 
614 std::ostream & operator << (std::ostream & os, const SixLowPanFrag1 & h)
615 {
616  h.Print (os);
617  return os;
618 }
619 
620 
621 /*
622  * SixLowPanFragN
623  */
624 
625 NS_OBJECT_ENSURE_REGISTERED (SixLowPanFragN);
626 
628  : m_datagramSize (0),
629  m_datagramTag (0),
630  m_datagramOffset (0)
631 {
632 }
633 /*
634  * SixLowPanFragmentOffset
635  */
637 {
638  static TypeId tid = TypeId ("ns3::SixLowPanFragN").SetParent<Header> ().AddConstructor<SixLowPanFragN> ();
639  return tid;
640 }
641 
643 {
644  return GetTypeId ();
645 }
646 
647 void SixLowPanFragN::Print (std::ostream & os) const
648 {
649  os << "datagram size " << m_datagramSize << " tag " << m_datagramTag << " offset " << int(m_datagramOffset);
650 }
651 
653 {
654  return 5;
655 }
656 
658 {
660 
661  uint16_t temp = m_datagramSize | ( uint16_t (SixLowPanDispatch::LOWPAN_FRAGN) << 8 );
662 
663  i.WriteU8 (uint8_t (temp >> 8));
664  i.WriteU8 (uint8_t (temp & 0xff));
665 
668 }
669 
671 {
673 
674  uint8_t temp = i.ReadU8 ();
675  m_datagramSize = (uint16_t (temp) << 8) | i.ReadU8 ();
676  m_datagramSize &= 0x7FF;
677 
678  m_datagramTag = i.ReadU16 ();
679  m_datagramOffset = i.ReadU8 ();
680 
681  return GetSerializedSize ();
682 }
683 
684 void SixLowPanFragN::SetDatagramSize (uint16_t datagramSize)
685 {
686  m_datagramSize = datagramSize & 0x7FF;
687 }
688 
690 {
691  return m_datagramSize & 0x7FF;
692 }
693 
694 void SixLowPanFragN::SetDatagramTag (uint16_t datagramTag)
695 {
696  m_datagramTag = datagramTag;
697 }
698 
700 {
701  return m_datagramTag;
702 }
703 
704 void SixLowPanFragN::SetDatagramOffset (uint8_t datagramOffset)
705 {
706  m_datagramOffset = datagramOffset;
707 }
708 
710 {
711  return m_datagramOffset;
712 }
713 
714 std::ostream & operator << (std::ostream & os, const SixLowPanFragN & h)
715 {
716  h.Print (os);
717  return os;
718 }
719 
720 /*
721  * SixLowPanIpv6
722  */
723 
724 NS_OBJECT_ENSURE_REGISTERED (SixLowPanIpv6);
725 
727 {
728 }
729 
731 {
732  static TypeId tid = TypeId ("ns3::SixLowPanIpv6").SetParent<Header> ().AddConstructor<SixLowPanIpv6> ();
733  return tid;
734 }
735 
737 {
738  return GetTypeId ();
739 }
740 
741 void SixLowPanIpv6::Print (std::ostream & os) const
742 {
743  os << "Uncompressed IPv6";
744 }
745 
747 {
748  return 1;
749 }
750 
752 {
754 
756 }
757 
759 {
761  i.ReadU8 ();
762 
763  return GetSerializedSize ();
764 }
765 
766 std::ostream & operator << (std::ostream & os, const SixLowPanIpv6 & h)
767 {
768  h.Print (os);
769  return os;
770 }
771 
772 /*
773  * SixLowPanIphcHeader
774  */
775 NS_OBJECT_ENSURE_REGISTERED (SixLowPanIphc);
776 
778 {
779  // 011x xxxx xxxx xxxx
780  m_baseFormat = 0x6000;
781 }
782 
784 {
785  // 011x xxxx xxxx xxxx
786  m_baseFormat = dispatch;
787  m_baseFormat <<= 8;
788 }
789 
791 {
792  static TypeId tid = TypeId ("ns3::SixLowPanIphc").SetParent<Header> ().AddConstructor<SixLowPanIphc> ();
793  return tid;
794 }
795 
797 {
798  return GetTypeId ();
799 }
800 
801 void SixLowPanIphc::Print (std::ostream & os) const
802 {
803  os << "Compression kind: " << m_baseFormat;
804 }
805 
807 {
808  uint32_t serializedSize = 2;
809 
810  if ( GetCid () )
811  {
812  serializedSize++;
813  }
814  switch ( GetTf () )
815  {
816  case TF_FULL:
817  serializedSize += 4;
818  break;
819  case TF_DSCP_ELIDED:
820  serializedSize += 3;
821  break;
822  case TF_FL_ELIDED:
823  serializedSize++;
824  break;
825  default:
826  break;
827  }
828  if ( GetNh () == false )
829  {
830  serializedSize++;
831  }
832  if ( GetHlim () == HLIM_INLINE)
833  {
834  serializedSize++;
835  }
836  switch (GetSam () )
837  {
838  case HC_INLINE:
839  if ( GetSac () == false )
840  {
841  serializedSize += 16;
842  }
843  break;
844  case HC_COMPR_64:
845  serializedSize += 8;
846  break;
847  case HC_COMPR_16:
848  serializedSize += 2;
849  break;
850  case HC_COMPR_0:
851  default:
852  break;
853  }
854  if ( GetM () == false)
855  {
856  switch (GetDam () )
857  {
858  case HC_INLINE:
859  if ( GetDac () == false )
860  {
861  serializedSize += 16;
862  }
863  break;
864  case HC_COMPR_64:
865  serializedSize += 8;
866  break;
867  case HC_COMPR_16:
868  serializedSize += 2;
869  break;
870  case HC_COMPR_0:
871  default:
872  break;
873  }
874  }
875  else
876  {
877  switch (GetDam () )
878  {
879  case HC_INLINE:
880  if ( GetDac () == false )
881  {
882  serializedSize += 16;
883  }
884  else
885  {
886  serializedSize += 6;
887  }
888  break;
889  case HC_COMPR_64:
890  if ( GetDac () == false )
891  {
892  serializedSize += 6;
893  }
894  break;
895  case HC_COMPR_16:
896  if ( GetDac () == false )
897  {
898  serializedSize += 4;
899  }
900  break;
901  case HC_COMPR_0:
902  default:
903  if ( GetDac () == false )
904  {
905  serializedSize++;
906  }
907  break;
908  }
909  }
910 
911 
912 
913  return serializedSize;
914 }
915 
917 {
919 
921 
922  if ( GetCid () )
923  {
925  }
926  // Traffic Class and Flow Label
927  switch ( GetTf () )
928  {
929  uint8_t temp;
930  case TF_FULL:
931  temp = (m_ecn << 6) | m_dscp;
932  i.WriteU8 (temp);
933  temp = m_flowLabel >> 16;
934  i.WriteU8 (temp);
935  temp = (m_flowLabel >> 8) & 0xff;
936  i.WriteU8 (temp);
937  temp = m_flowLabel & 0xff;
938  i.WriteU8 (temp);
939  break;
940  case TF_DSCP_ELIDED:
941  temp = (m_ecn << 6) | (m_flowLabel >> 16 );
942  i.WriteU8 (temp);
943  temp = (m_flowLabel >> 8) & 0xff;
944  i.WriteU8 (temp);
945  temp = m_flowLabel & 0xff;
946  i.WriteU8 (temp);
947  break;
948  case TF_FL_ELIDED:
949  temp = (m_ecn << 6) | m_dscp;
950  i.WriteU8 (temp);
951  break;
952  default:
953  break;
954  }
955  // Next Header
956  if ( GetNh () == false )
957  {
958  i.WriteU8 (m_nextHeader);
959  }
960  // Hop Limit
961  if ( GetHlim () == HLIM_INLINE )
962  {
963  i.WriteU8 (m_hopLimit);
964  }
965  // Source Address
966  switch (GetSam () )
967  {
968  uint8_t temp[16];
969  case HC_INLINE:
970  if ( GetSac () == false )
971  {
972  uint8_t temp[16];
973  m_srcAddress.Serialize (temp);
974  i.Write (temp, 16);
975  }
976  break;
977  case HC_COMPR_64:
978  m_srcAddress.Serialize (temp);
979  i.Write (temp + 8, 8);
980  break;
981  case HC_COMPR_16:
982  m_srcAddress.Serialize (temp);
983  i.Write (temp + 14, 2);
984  break;
985  case HC_COMPR_0:
986  default:
987  break;
988  }
989  // Destination Address
990  if ( GetM () == false)
991  {
992  uint8_t temp[16];
993  switch (GetDam () )
994  {
995  case HC_INLINE:
996  if ( GetDac () == false )
997  {
998  m_dstAddress.Serialize (temp);
999  i.Write (temp, 16);
1000  }
1001  break;
1002  case HC_COMPR_64:
1003  m_dstAddress.Serialize (temp);
1004  i.Write (temp + 8, 8);
1005  break;
1006  case HC_COMPR_16:
1007  m_dstAddress.Serialize (temp);
1008  i.Write (temp + 14, 2);
1009  break;
1010  case HC_COMPR_0:
1011  default:
1012  break;
1013  }
1014  }
1015  else
1016  {
1017  switch (GetDam () )
1018  {
1019  uint8_t temp[16];
1020  case HC_INLINE:
1021  if ( GetDac () == false )
1022  {
1023  m_dstAddress.Serialize (temp);
1024  i.Write (temp, 16);
1025  }
1026  else
1027  {
1028  m_dstAddress.Serialize (temp);
1029  i.Write (temp + 1, 2);
1030  i.Write (temp + 12, 4);
1031  }
1032  break;
1033  case HC_COMPR_64:
1034  if ( GetDac () == false )
1035  {
1036  m_dstAddress.Serialize (temp);
1037  i.Write (temp + 1, 1);
1038  i.Write (temp + 11, 5);
1039  }
1040  break;
1041  case HC_COMPR_16:
1042  if ( GetDac () == false )
1043  {
1044  m_dstAddress.Serialize (temp);
1045  i.Write (temp + 1, 1);
1046  i.Write (temp + 13, 3);
1047  }
1048  break;
1049  case HC_COMPR_0:
1050  default:
1051  if ( GetDac () == false )
1052  {
1053  m_dstAddress.Serialize (temp);
1054  i.WriteU8 (temp[15]);
1055  }
1056  break;
1057  }
1058  }
1059 }
1060 
1062 {
1063  Buffer::Iterator i = start;
1064 
1065  m_baseFormat = i.ReadNtohU16 ();
1066 
1067  if ( GetCid () )
1068  {
1069  m_srcdstContextId = i.ReadU8 ();
1070  }
1071  // Traffic Class and Flow Label
1072  switch ( GetTf () )
1073  {
1074  uint8_t temp;
1075  case TF_FULL:
1076  temp = i.ReadU8 ();
1077  m_ecn = temp >> 6;
1078  m_dscp = temp & 0x3F;
1079  temp = i.ReadU8 ();
1080  m_flowLabel = temp;
1081  temp = i.ReadU8 ();
1082  m_flowLabel = (m_flowLabel << 8) | temp;
1083  temp = i.ReadU8 ();
1084  m_flowLabel = (m_flowLabel << 8) | temp;
1085  break;
1086  case TF_DSCP_ELIDED:
1087  temp = i.ReadU8 ();
1088  m_ecn = temp >> 6;
1089  m_flowLabel = temp & 0x3F;
1090  temp = i.ReadU8 ();
1091  m_flowLabel = (m_flowLabel << 8) | temp;
1092  temp = i.ReadU8 ();
1093  m_flowLabel = (m_flowLabel << 8) | temp;
1094  break;
1095  case TF_FL_ELIDED:
1096  temp = i.ReadU8 ();
1097  m_ecn = temp >> 6;
1098  m_dscp = temp & 0x3F;
1099  break;
1100  default:
1101  break;
1102  }
1103  // Next Header
1104  if ( GetNh () == false )
1105  {
1106  m_nextHeader = i.ReadU8 ();
1107  }
1108  // Hop Limit
1109  switch ( GetHlim () )
1110  {
1111  case HLIM_INLINE:
1112  m_hopLimit = i.ReadU8 ();
1113  break;
1114  case HLIM_COMPR_1:
1115  m_hopLimit = 1;
1116  break;
1117  case HLIM_COMPR_64:
1118  m_hopLimit = 64;
1119  break;
1120  case HLIM_COMPR_255:
1121  default:
1122  m_hopLimit = 255;
1123  break;
1124 
1125  }
1126  // Source Address
1127  switch (GetSam () )
1128  {
1129  uint8_t temp[16];
1130  case HC_INLINE:
1131  if ( GetSac () == false )
1132  {
1133  i.Read (temp, 16);
1135  }
1136  break;
1137  case HC_COMPR_64:
1138  memset (temp, 0x00, sizeof (temp));
1139  i.Read (temp + 8, 8);
1140  temp[0] = 0xfe;
1141  temp[1] = 0x80;
1143  break;
1144  case HC_COMPR_16:
1145  memset (temp, 0x00, sizeof (temp));
1146  i.Read (temp + 14, 2);
1147  temp[0] = 0xfe;
1148  temp[1] = 0x80;
1149  temp[11] = 0xff;
1150  temp[12] = 0xfe;
1152  break;
1153  case HC_COMPR_0:
1154  default:
1155  break;
1156  }
1157  if ( GetSac () == true )
1158  {
1159  PostProcessSac ();
1160  }
1161  // Destination Address
1162  if ( GetM () == false)
1163  {
1164  uint8_t temp[16];
1165  switch (GetDam () )
1166  {
1167  case HC_INLINE:
1168  if ( GetDac () == false )
1169  {
1170  i.Read (temp, 16);
1172  }
1173  break;
1174  case HC_COMPR_64:
1175  memset (temp, 0x00, sizeof (temp));
1176  i.Read (temp + 8, 8);
1177  temp[0] = 0xfe;
1178  temp[1] = 0x80;
1180  break;
1181  case HC_COMPR_16:
1182  memset (temp, 0x00, sizeof (temp));
1183  i.Read (temp + 14, 2);
1184  temp[0] = 0xfe;
1185  temp[1] = 0x80;
1186  temp[11] = 0xff;
1187  temp[12] = 0xfe;
1189  break;
1190  case HC_COMPR_0:
1191  default:
1192  break;
1193  }
1194  }
1195  else
1196  {
1197  switch (GetDam () )
1198  {
1199  uint8_t temp[16];
1200  case HC_INLINE:
1201  if ( GetDac () == false )
1202  {
1203  i.Read (temp, 16);
1205  }
1206  else
1207  {
1208  memset (temp, 0x00, sizeof (temp));
1209  i.Read (temp + 1, 2);
1210  i.Read (temp + 12, 4);
1211  temp[0] = 0xff;
1213  }
1214  break;
1215  case HC_COMPR_64:
1216  if ( GetDac () == false )
1217  {
1218  memset (temp, 0x00, sizeof (temp));
1219  i.Read (temp + 1, 1);
1220  i.Read (temp + 11, 5);
1221  temp[0] = 0xff;
1223  }
1224  break;
1225  case HC_COMPR_16:
1226  if ( GetDac () == false )
1227  {
1228  memset (temp, 0x00, sizeof (temp));
1229  i.Read (temp + 1, 1);
1230  i.Read (temp + 13, 3);
1231  temp[0] = 0xff;
1233  }
1234  break;
1235  case HC_COMPR_0:
1236  default:
1237  if ( GetDac () == false )
1238  {
1239  memset (temp, 0x00, sizeof (temp));
1240  temp[15] = i.ReadU8 ();
1241  temp[0] = 0xff;
1242  temp[1] = 0x02;
1244  }
1245  break;
1246  }
1247  }
1248  if ( GetDac () == true )
1249  {
1250  PostProcessDac ();
1251  }
1252  return GetSerializedSize ();
1253 }
1254 
1256 {
1257  uint16_t field = tfField;
1258  m_baseFormat |= (field << 11);
1259 }
1260 
1262 {
1263  return TrafficClassFlowLabel_e ((m_baseFormat >> 11) & 0x3);
1264 }
1265 
1266 void SixLowPanIphc::SetNh (bool nhField)
1267 {
1268  uint16_t field = nhField;
1269  m_baseFormat |= (field << 10);
1270 }
1271 
1272 bool SixLowPanIphc::GetNh (void) const
1273 {
1274  return ((m_baseFormat >> 10) & 0x1);
1275 }
1276 
1278 {
1279  uint16_t field = hlimField;
1280  m_baseFormat |= (field << 8);
1281 }
1282 
1284 {
1285  return Hlim_e ((m_baseFormat >> 8) & 0x3);
1286 }
1287 
1288 void SixLowPanIphc::SetCid (bool cidField)
1289 {
1290  uint16_t field = cidField;
1291  m_baseFormat |= (field << 7);
1292 }
1293 
1294 bool SixLowPanIphc::GetCid (void) const
1295 {
1296  return ((m_baseFormat >> 7) & 0x1);
1297 }
1298 
1299 void SixLowPanIphc::SetSac (bool sacField)
1300 {
1301  uint16_t field = sacField;
1302  m_baseFormat |= (field << 6);
1303 }
1304 
1305 bool SixLowPanIphc::GetSac (void) const
1306 {
1307  return ((m_baseFormat >> 6) & 0x1);
1308 }
1309 
1311 {
1312  uint16_t field = samField;
1313  m_baseFormat |= (field << 4);
1314 }
1315 
1317 {
1318  return HeaderCompression_e ((m_baseFormat >> 4) & 0x3);
1319 }
1320 
1321 void SixLowPanIphc::SetM (bool mField)
1322 {
1323  uint16_t field = mField;
1324  m_baseFormat |= (field << 3);
1325 }
1326 
1327 bool SixLowPanIphc::GetM (void) const
1328 {
1329  return ((m_baseFormat >> 3) & 0x1);
1330 }
1331 
1332 void SixLowPanIphc::SetDac (bool dacField)
1333 {
1334  uint16_t field = dacField;
1335  m_baseFormat |= (field << 2);
1336 }
1337 
1338 bool SixLowPanIphc::GetDac (void) const
1339 {
1340  return ((m_baseFormat >> 2) & 0x1);
1341 }
1342 
1344 {
1345  uint16_t field = damField;
1346  m_baseFormat |= field;
1347 }
1348 
1350 {
1351  return HeaderCompression_e (m_baseFormat & 0x3);
1352 }
1353 
1354 void SixLowPanIphc::SetSrcContextId (uint8_t srcContextId)
1355 {
1356  NS_ASSERT_MSG (srcContextId < 16, "Src Context ID too large");
1357  m_srcdstContextId |= srcContextId << 4;
1358 }
1359 
1361 {
1362  return ( m_srcdstContextId >> 4);
1363 }
1364 
1365 void SixLowPanIphc::SetDstContextId (uint8_t dstContextId)
1366 {
1367  NS_ASSERT_MSG (dstContextId < 16, "Dst Context ID too large");
1368  m_srcdstContextId |= (dstContextId & 0xF);
1369 }
1370 
1372 {
1373  return (m_srcdstContextId & 0xF);
1374 }
1375 
1376 void SixLowPanIphc::SetEcn (uint8_t ecn)
1377 {
1378  NS_ASSERT_MSG (ecn < 4, "ECN too large");
1379  m_ecn = ecn;
1380 }
1381 
1382 uint8_t SixLowPanIphc::GetEcn (void) const
1383 {
1384  return m_ecn;
1385 }
1386 
1387 void SixLowPanIphc::SetDscp (uint8_t dscp)
1388 {
1389  NS_ASSERT_MSG (dscp < 64, "DSCP too large");
1390  m_dscp = dscp;
1391 }
1392 
1393 uint8_t SixLowPanIphc::GetDscp (void) const
1394 {
1395  return m_dscp;
1396 }
1397 
1398 void SixLowPanIphc::SetFlowLabel (uint32_t flowLabel)
1399 {
1400  NS_ASSERT_MSG (flowLabel < 0x100000, "Flow Label too large");
1401  m_flowLabel = flowLabel;
1402 }
1403 
1404 uint32_t SixLowPanIphc::GetFlowLabel (void) const
1405 {
1406  return m_flowLabel;
1407 }
1408 
1409 void SixLowPanIphc::SetNextHeader (uint8_t nextHeader)
1410 {
1411  m_nextHeader = nextHeader;
1412 }
1413 
1414 uint8_t SixLowPanIphc::GetNextHeader (void) const
1415 {
1416  return m_nextHeader;
1417 }
1418 
1419 void SixLowPanIphc::SetHopLimit (uint8_t hopLimit)
1420 {
1421  m_hopLimit = hopLimit;
1422 }
1423 
1424 uint8_t SixLowPanIphc::GetHopLimit (void) const
1425 {
1426  return m_hopLimit;
1427 }
1428 
1430 {
1431  m_srcAddress = srcAddress;
1432 }
1433 
1435 {
1436  return m_srcAddress;
1437 }
1438 
1440 {
1441  m_dstAddress = dstAddress;
1442 }
1443 
1445 {
1446  return m_dstAddress;
1447 }
1448 
1450 {
1451  NS_ABORT_MSG ("Unsupported; Context destination is not implemented");
1452  return;
1453 }
1454 
1456 {
1457  NS_ABORT_MSG ("Unsupported; Context destination is not implemented");
1458  return;
1459 }
1460 
1461 std::ostream & operator << (std::ostream & os, const SixLowPanIphc & h)
1462 {
1463  h.Print (os);
1464  return os;
1465 }
1466 
1467 /*
1468  * SixLowPanNhcExtensionHeader
1469  */
1470 NS_OBJECT_ENSURE_REGISTERED (SixLowPanNhcExtension);
1471 
1473 {
1474  // 1110 xxxx
1475  m_nhcExtensionHeader = 0xE0;
1476  m_nhcNextHeader = 0;
1477  m_nhcBlobLength = 0;
1478 }
1479 
1481 {
1482  static TypeId tid = TypeId ("ns3::SixLowPanNhcExtension")
1483  .SetParent<Header> ()
1484  .AddConstructor<SixLowPanNhcExtension> ();
1485  return tid;
1486 }
1487 
1489 {
1490  return GetTypeId ();
1491 }
1492 
1493 void SixLowPanNhcExtension::Print (std::ostream & os) const
1494 {
1495  os << "Compression kind: " << int (m_nhcExtensionHeader) << " Size: " << int(GetSerializedSize ());
1496 }
1497 
1499 {
1500  uint32_t serializedSize = 2;
1501  if ( GetNh () == false )
1502  {
1503  serializedSize++;
1504  }
1505  return serializedSize + m_nhcBlobLength;
1506 }
1507 
1509 {
1510  Buffer::Iterator i = start;
1512  if ( GetNh () == false )
1513  {
1515  }
1518 }
1519 
1521 {
1522  Buffer::Iterator i = start;
1524  if ( GetNh () == false )
1525  {
1526  m_nhcNextHeader = i.ReadU8 ();
1527  }
1528  m_nhcBlobLength = i.ReadU8 ();
1530 
1531  return GetSerializedSize ();
1532 }
1533 
1536 {
1538 }
1539 
1540 void SixLowPanNhcExtension::SetEid (Eid_e extensionHeaderType)
1541 {
1542  uint8_t field = extensionHeaderType;
1543  m_nhcExtensionHeader |= (field << 1);
1544 }
1545 
1547 {
1548  return Eid_e ((m_nhcExtensionHeader >> 1) & 0x7);
1549 }
1550 
1551 void SixLowPanNhcExtension::SetNextHeader (uint8_t nextHeader)
1552 {
1553  m_nhcNextHeader = nextHeader;
1554 }
1555 
1557 {
1558  return m_nhcNextHeader;
1559 }
1560 
1561 void SixLowPanNhcExtension::SetNh (bool nhField)
1562 {
1563  uint8_t field = nhField;
1564  m_nhcExtensionHeader |= field;
1565 }
1566 
1568 {
1569  return m_nhcExtensionHeader & 0x01;
1570 }
1571 
1572 void SixLowPanNhcExtension::SetBlob (const uint8_t* blob, uint32_t size)
1573 {
1574  NS_ASSERT_MSG ( size < 255, "Buffer too long" );
1575 
1576  m_nhcBlobLength = size;
1577  std::memcpy (m_nhcBlob, blob, size);
1578 }
1579 
1580 uint32_t SixLowPanNhcExtension::CopyBlob (uint8_t* blob, uint32_t size) const
1581 {
1582  NS_ASSERT_MSG ( size > m_nhcBlobLength, "Buffer too short" );
1583 
1584  std::memcpy (blob, m_nhcBlob, m_nhcBlobLength);
1585  return m_nhcBlobLength;
1586 }
1587 
1588 std::ostream & operator << (std::ostream & os, const SixLowPanNhcExtension & h)
1589 {
1590  h.Print (os);
1591  return os;
1592 }
1593 
1594 /*
1595  * SixLowPanUdpNhcExtension
1596  */
1597 NS_OBJECT_ENSURE_REGISTERED (SixLowPanUdpNhcExtension);
1598 
1600 {
1601  // 1111 0xxx
1602  m_baseFormat = 0xF0;
1603  m_checksum = 0;
1604  m_srcPort = 0;
1605  m_dstPort = 0;
1606 }
1607 
1609 {
1610  static TypeId tid = TypeId ("ns3::SixLowPanUdpNhcExtension")
1611  .SetParent<Header> ()
1612  .AddConstructor<SixLowPanUdpNhcExtension> ();
1613  return tid;
1614 }
1615 
1617 {
1618  return GetTypeId ();
1619 }
1620 
1621 void SixLowPanUdpNhcExtension::Print (std::ostream & os) const
1622 {
1623  os << "Compression kind: " << uint8_t (m_baseFormat);
1624 }
1625 
1627 {
1628  uint32_t serializedSize = 1;
1629  if ( !GetC () )
1630  {
1631  serializedSize += 2;
1632  }
1633  switch (GetPorts ())
1634  {
1635  case PORTS_INLINE:
1636  serializedSize += 4;
1637  break;
1640  serializedSize += 3;
1641  break;
1643  serializedSize += 1;
1644  break;
1645  default:
1646  break;
1647  }
1648  return serializedSize;
1649 }
1650 
1652 {
1653  Buffer::Iterator i = start;
1654  i.WriteU8 (m_baseFormat);
1655  uint8_t temp;
1656 
1657  // Ports
1658  switch ( GetPorts () )
1659  {
1660  case PORTS_INLINE:
1661  i.WriteHtonU16 (m_srcPort);
1662  i.WriteHtonU16 (m_dstPort);
1663  break;
1665  i.WriteHtonU16 (m_srcPort);
1666  i.WriteU8 (m_dstPort & 0xff);
1667  break;
1669  i.WriteU8 (m_srcPort & 0xff);
1670  i.WriteHtonU16 (m_dstPort);
1671  break;
1673  temp = ((m_srcPort & 0xf) << 4) | (m_dstPort & 0xf);
1674  i.WriteU8 (temp);
1675  break;
1676  default:
1677  break;
1678  }
1679 
1680  // Checksum
1681  if ( !GetC () )
1682  {
1683  i.WriteU16 (m_checksum);
1684  }
1685 
1686 }
1687 
1689 {
1690  Buffer::Iterator i = start;
1691  m_baseFormat = i.ReadU8 ();
1692  uint8_t temp;
1693 
1694  // Ports
1695  switch ( GetPorts () )
1696  {
1697  case PORTS_INLINE:
1698  m_srcPort = i.ReadNtohU16 ();
1699  m_dstPort = i.ReadNtohU16 ();
1700  break;
1702  m_srcPort = i.ReadNtohU16 ();
1703  m_dstPort = i.ReadU8 ();
1704  break;
1706  m_srcPort = i.ReadU8 ();
1707  m_dstPort = i.ReadNtohU16 ();
1708  break;
1710  temp = i.ReadU8 ();
1711  m_srcPort = temp >> 4;
1712  m_dstPort = temp & 0xf;
1713  break;
1714  default:
1715  break;
1716  }
1717 
1718  // Checksum
1719  if ( !GetC () )
1720  {
1721  m_checksum = i.ReadU16 ();
1722  }
1723 
1724  return GetSerializedSize ();
1725 }
1726 
1729 {
1731 }
1732 
1734 {
1735  uint16_t field = ports;
1736  m_baseFormat |= field;
1737 }
1738 
1740 {
1741  return Ports_e (m_baseFormat & 0x3);
1742 }
1743 
1745 {
1746  m_srcPort = srcport;
1747 }
1748 
1750 {
1751  return m_srcPort;
1752 }
1753 
1755 {
1756  m_dstPort = dstport;
1757 }
1758 
1760 {
1761  return m_dstPort;
1762 }
1763 
1765 {
1766  uint16_t field = cField;
1767  m_baseFormat |= (field << 2);
1768 }
1769 
1771 {
1772  return ((m_baseFormat >> 2) & 0x1);
1773 }
1774 
1776 {
1777  m_checksum = checksum;
1778 }
1779 
1781 {
1782  return m_checksum;
1783 }
1784 
1785 std::ostream & operator << (std::ostream & os, const SixLowPanUdpNhcExtension & h)
1786 {
1787  h.Print (os);
1788  return os;
1789 }
1790 
1791 
1792 }
1793 
uint16_t ReadU16(void)
Definition: buffer.h:1036
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.
NhcDispatch_e
Dispatch values for Next Header compression.
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.
TrafficClassFlowLabel_e
TF: Traffic Class, Flow Label.
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)
Abnormal program termination.
Definition: abort.h:44
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 the class in the ns-3 factory.
Definition: object-base.h:38
6LoWPAN IPv6 uncomprssed 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.
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 compresison 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.
Hlim_e
HLIM: Hop Limit.
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)
Return the instance type identifier.
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.
uint16_t GetSrcPort() const
Get the Destination 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.
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 compresison type.
void SetSac(bool sacField)
Set the SAC (Source Address Compression) compression.
void WriteU16(uint16_t data)
Definition: buffer.cc:899
bool IsHc2HeaderPresent() const
Check if there is a HC2 compressed header.
void WriteHtonU16(uint16_t data)
Definition: buffer.h:912
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 Destination 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:43
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.
void SetNextHeader(uint8_t nextHeader)
Set the Next Header field.
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:1152
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
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:84
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:46
Ipv6Address m_srcAddress
Src address.
void SetFlowLabel(uint32_t flowLabel)
Set the Flow Label (20bits).
void WriteU8(uint8_t data)
Definition: buffer.h:876
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]
Destinaiton 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.
Eid_e
EID: IPv6 Extension Header ID.
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:1028
void Write(uint8_t const *buffer, uint32_t size)
Definition: buffer.cc:982
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.
Dispatch_e
Dispatch values, as defined in RFC4944 and RFC6282.
LowPanHc1NextHeader_e
Next header information.
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.
HeaderCompression_e
Source or Destination Address Mode.
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.
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:953
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:49
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
TypeId SetParent(TypeId tid)
Definition: type-id.cc:610
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).
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.
LowPanHc1Addr_e
Kind of address 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.