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