A Discrete-Event Network Simulator
API
icmpv6-header.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2007-2009 Strasbourg University
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: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
19  * Mehdi Benamor <benamor.mehdi@ensi.rnu.tn>
20  * David Gross <gdavid.devel@gmail.com>
21  */
22 
23 #include "ns3/assert.h"
24 #include "ns3/address-utils.h"
25 #include "ns3/log.h"
26 
27 #include "icmpv6-header.h"
28 
29 namespace ns3
30 {
31 
32 NS_LOG_COMPONENT_DEFINE ("Icmpv6Header");
33 
34 NS_OBJECT_ENSURE_REGISTERED (Icmpv6Header);
35 
37 {
38  static TypeId tid = TypeId ("ns3::Icmpv6Header")
39  .SetParent<Header> ()
40  .SetGroupName ("Internet")
41  .AddConstructor<Icmpv6Header> ()
42  ;
43  return tid;
44 }
45 
47 {
48  NS_LOG_FUNCTION (this);
49  return GetTypeId ();
50 }
51 
53  : m_calcChecksum (true),
54  m_checksum (0),
55  m_type (0),
56  m_code (0)
57 {
58  NS_LOG_FUNCTION (this);
59 }
60 
62 {
63  NS_LOG_FUNCTION (this);
64 }
65 
66 uint8_t Icmpv6Header::GetType () const
67 {
68  NS_LOG_FUNCTION (this);
69  return m_type;
70 }
71 
72 void Icmpv6Header::SetType (uint8_t type)
73 {
74  NS_LOG_FUNCTION (this << static_cast<uint32_t> (type));
75  m_type = type;
76 }
77 
78 uint8_t Icmpv6Header::GetCode () const
79 {
80  NS_LOG_FUNCTION (this);
81  return m_code;
82 }
83 
84 void Icmpv6Header::SetCode (uint8_t code)
85 {
86  NS_LOG_FUNCTION (this << static_cast<uint32_t> (code));
87  m_code = code;
88 }
89 
90 uint16_t Icmpv6Header::GetChecksum () const
91 {
92  NS_LOG_FUNCTION (this);
93  return m_checksum;
94 }
95 
96 void Icmpv6Header::SetChecksum (uint16_t checksum)
97 {
98  NS_LOG_FUNCTION (this << checksum);
99  m_checksum = checksum;
100 }
101 
102 void Icmpv6Header::Print (std::ostream& os) const
103 {
104  NS_LOG_FUNCTION (this << &os);
105  os << "( type = " << (uint32_t)m_type << " code = " << (uint32_t)m_code << " checksum = " << (uint32_t)m_checksum << ")";
106 }
107 
109 {
110  NS_LOG_FUNCTION (this);
111  return 4;
112 }
113 
115 {
116  NS_LOG_FUNCTION (this << &start);
118 
119  m_type = i.ReadU8 ();
120  m_code = i.ReadU8 ();
121  m_checksum = i.ReadNtohU16 ();
122 #if 0
123  i.ReadU32 (); /* padding */
124 #endif
125  return GetSerializedSize ();
126 }
127 
129 {
130  NS_LOG_FUNCTION (this << &start);
132 
133  i.WriteU8 (m_type);
134  i.WriteU8 (m_code);
135  i.WriteU16 (0);
136 #if 0
137  i.WriteU32 (0); /* padding */
138 #endif
139 
140  if (m_calcChecksum)
141  {
142  i = start;
143  uint16_t checksum = i.CalculateIpChecksum (i.GetSize (), m_checksum);
144  i = start;
145  i.Next (2);
146  i.WriteU16 (checksum);
147  }
148 }
149 
150 void Icmpv6Header::CalculatePseudoHeaderChecksum (Ipv6Address src, Ipv6Address dst, uint16_t length, uint8_t protocol)
151 {
152  NS_LOG_FUNCTION (this << src << dst << length << static_cast<uint32_t> (protocol));
153 
154  Buffer buf = Buffer (40);
155  uint8_t tmp[16];
156  Buffer::Iterator it;
157 
158  buf.AddAtStart (40);
159  it = buf.Begin ();
160 
161  src.Serialize (tmp);
162  it.Write (tmp, 16); /* source IPv6 address */
163  dst.Serialize (tmp);
164  it.Write (tmp, 16); /* destination IPv6 address */
165  it.WriteU16 (0); /* length */
166  it.WriteU8 (length >> 8); /* length */
167  it.WriteU8 (length & 0xff); /* length */
168  it.WriteU16 (0); /* zero */
169  it.WriteU8 (0); /* zero */
170  it.WriteU8 (protocol); /* next header */
171 
172  it = buf.Begin ();
173  m_checksum = ~(it.CalculateIpChecksum (40));
174 }
175 
177 
179 {
180  NS_LOG_FUNCTION (this);
182  SetCode (0);
183  SetReserved (0);
184  m_checksum = 0;
185 }
186 
188 {
189  static TypeId tid = TypeId ("ns3::Icmpv6NS")
191  .SetGroupName ("Internet")
192  .AddConstructor<Icmpv6NS> ()
193  ;
194  return tid;
195 }
196 
198 {
199  NS_LOG_FUNCTION (this);
200  return GetTypeId ();
201 }
202 
204 {
205  NS_LOG_FUNCTION (this << target);
207  SetCode (0);
208  SetReserved (0);
209  SetIpv6Target (target);
210  m_checksum = 0;
211 
212  /* test */
213  /*
214  m_reserved = 0xdeadbeef;
215  */
216 }
217 
219 {
220  NS_LOG_FUNCTION (this);
221 }
222 
223 uint32_t Icmpv6NS::GetReserved () const
224 {
225  NS_LOG_FUNCTION (this);
226  return m_reserved;
227 }
228 
229 void Icmpv6NS::SetReserved (uint32_t reserved)
230 {
231  NS_LOG_FUNCTION (this << reserved);
232  m_reserved = reserved;
233 }
234 
236 {
237  NS_LOG_FUNCTION (this);
238  return m_target;
239 }
240 
242 {
243  NS_LOG_FUNCTION (this << target);
244  m_target = target;
245 }
246 
247 void Icmpv6NS::Print (std::ostream& os) const
248 {
249  NS_LOG_FUNCTION (this << &os);
250  os << "( type = " << (uint32_t)GetType () << " (NS) code = " << (uint32_t)GetCode () << " target = " << m_target << " checksum = " << (uint32_t)GetChecksum () << ")";
251 }
252 
254 {
255  NS_LOG_FUNCTION (this);
256  return 24;
257 }
258 
260 {
261  NS_LOG_FUNCTION (this << &start);
262  uint8_t buff_target[16];
263  uint16_t checksum = 0;
265 
266  i.WriteU8 (GetType ());
267  i.WriteU8 (GetCode ());
268  i.WriteU16 (0);
270  m_target.Serialize (buff_target);
271  i.Write (buff_target, 16);
272 
273  if (m_calcChecksum)
274  {
275  i = start;
276  checksum = i.CalculateIpChecksum (i.GetSize (), m_checksum);
277  i = start;
278  i.Next (2);
279  i.WriteU16 (checksum);
280  }
281 }
282 
284 {
285  NS_LOG_FUNCTION (this << &start);
286  uint8_t buf[16];
288 
289  SetType (i.ReadU8 ());
290  SetCode (i.ReadU8 ());
291  m_checksum = i.ReadU16 ();
292  m_reserved = i.ReadNtohU32 ();
293  i.Read (buf, 16);
294  m_target.Set (buf);
295 
296  return GetSerializedSize ();
297 }
298 
300 
302 {
303  static TypeId tid = TypeId ("ns3::Icmpv6NA")
305  .SetGroupName ("Internet")
306  .AddConstructor<Icmpv6NA> ()
307  ;
308  return tid;
309 }
310 
312 {
313  NS_LOG_FUNCTION (this);
314  return GetTypeId ();
315 }
316 
318 {
319  NS_LOG_FUNCTION (this);
321  SetCode (0);
322  SetReserved (0);
323  SetFlagR (0);
324  SetFlagS (0);
325  SetFlagO (0);
326  m_checksum = 0;
327 }
328 
330 {
331  NS_LOG_FUNCTION (this);
332 }
333 
334 uint32_t Icmpv6NA::GetReserved () const
335 {
336  NS_LOG_FUNCTION (this);
337  return m_reserved;
338 }
339 
340 void Icmpv6NA::SetReserved (uint32_t reserved)
341 {
342  NS_LOG_FUNCTION (this << reserved);
343  m_reserved = reserved;
344 }
345 
347 {
348  NS_LOG_FUNCTION (this);
349  return m_target;
350 }
351 
352 bool Icmpv6NA::GetFlagR () const
353 {
354  NS_LOG_FUNCTION (this);
355  return m_flagR;
356 }
357 
358 void Icmpv6NA::SetFlagR (bool r)
359 {
360  NS_LOG_FUNCTION (this << r);
361  m_flagR = r;
362 }
363 
364 bool Icmpv6NA::GetFlagS () const
365 {
366  NS_LOG_FUNCTION (this);
367  return m_flagS;
368 }
369 
370 void Icmpv6NA::SetFlagS (bool s)
371 {
372  NS_LOG_FUNCTION (this << s);
373  m_flagS = s;
374 }
375 
376 bool Icmpv6NA::GetFlagO () const
377 {
378  NS_LOG_FUNCTION (this);
379  return m_flagO;
380 }
381 
382 void Icmpv6NA::SetFlagO (bool o)
383 {
384  NS_LOG_FUNCTION (this << o);
385  m_flagO = o;
386 }
387 
389 {
390  NS_LOG_FUNCTION (this << target);
391  m_target = target;
392 }
393 
394 void Icmpv6NA::Print (std::ostream& os) const
395 {
396  NS_LOG_FUNCTION (this << &os);
397  os << "( type = " << (uint32_t)GetType () << " (NA) code = " << (uint32_t)GetCode () << " checksum = " << (uint32_t)GetChecksum () << ")";
398 }
399 
401 {
402  NS_LOG_FUNCTION (this);
403  return 24;
404 }
405 
407 {
408  NS_LOG_FUNCTION (this << &start);
409  uint8_t buff_target[16];
410  uint16_t checksum = 0;
412  uint32_t reserved = m_reserved;
413 
414  i.WriteU8 (GetType ());
415  i.WriteU8 (GetCode ());
416  i.WriteU16 (0);
417 
418  if (m_flagR)
419  {
420  reserved |= (uint32_t)(1 << 31);
421  }
422 
423  if (m_flagS)
424  {
425  reserved |= (uint32_t)(1<< 30);
426  }
427 
428  if (m_flagO)
429  {
430  reserved |= (uint32_t)(1<< 29);
431  }
432 
433  i.WriteHtonU32 (reserved);
434  m_target.Serialize (buff_target);
435  i.Write (buff_target, 16);
436 
437  if (m_calcChecksum)
438  {
439  i = start;
440  checksum = i.CalculateIpChecksum (i.GetSize (), GetChecksum ());
441  i = start;
442  i.Next (2);
443  i.WriteU16 (checksum);
444  }
445 }
446 
448 {
449  NS_LOG_FUNCTION (this << &start);
450  uint8_t buf[16];
452 
453  SetType (i.ReadU8 ());
454  SetCode (i.ReadU8 ());
455  m_checksum = i.ReadU16 ();
456  m_reserved = i.ReadNtohU32 ();
457 
458  m_flagR = false;
459  m_flagS = false;
460  m_flagO = false;
461 
462  if (m_reserved & (1 << 31))
463  {
464  m_flagR = true;
465  }
466 
467  if (m_reserved & (1 << 30))
468  {
469  m_flagS = true;
470  }
471 
472  if (m_reserved & (1 << 29))
473  {
474  m_flagO = true;
475  }
476 
477  i.Read (buf, 16);
478  m_target.Set (buf);
479 
480  return GetSerializedSize ();
481 }
482 
484 
486 {
487  static TypeId tid = TypeId ("ns3::Icmpv6RA")
489  .SetGroupName ("Internet")
490  .AddConstructor<Icmpv6RA> ()
491  ;
492  return tid;
493 }
494 
496 {
497  NS_LOG_FUNCTION (this);
498  return GetTypeId ();
499 }
500 
502 {
503  NS_LOG_FUNCTION (this);
505  SetCode (0);
506  SetFlagM (0);
507  SetFlagO (0);
508  SetFlagH (0);
509  SetCurHopLimit (0);
510  SetLifeTime (0);
512  SetReachableTime (0);
513 }
514 
516 {
517  NS_LOG_FUNCTION (this);
518 }
519 
520 void Icmpv6RA::SetCurHopLimit (uint8_t m)
521 {
522  NS_LOG_FUNCTION (this << static_cast<uint32_t> (m));
523  m_curHopLimit = m;
524 }
525 
526 uint8_t Icmpv6RA::GetCurHopLimit () const
527 {
528  NS_LOG_FUNCTION (this);
529  return m_curHopLimit;
530 }
531 
532 uint16_t Icmpv6RA::GetLifeTime () const
533 {
534  NS_LOG_FUNCTION (this);
535  return m_LifeTime;
536 }
537 
538 uint32_t Icmpv6RA::GetReachableTime () const
539 {
540  NS_LOG_FUNCTION (this);
541  return m_ReachableTime;
542 }
543 
545 {
546  NS_LOG_FUNCTION (this);
547  return m_RetransmissionTimer;
548 }
549 
550 void Icmpv6RA::SetLifeTime (uint16_t l)
551 {
552  NS_LOG_FUNCTION (this << l);
553  m_LifeTime = l;
554 }
555 
556 void Icmpv6RA::SetReachableTime (uint32_t r)
557 {
558  NS_LOG_FUNCTION (this << r);
559  m_ReachableTime = r;
560 }
561 
563 {
564  NS_LOG_FUNCTION (this << r);
566 }
567 
568 bool Icmpv6RA::GetFlagM () const
569 {
570  NS_LOG_FUNCTION (this);
571  return m_flagM;
572 }
573 
574 void Icmpv6RA::SetFlagM (bool m)
575 {
576  NS_LOG_FUNCTION (this << m);
577  m_flagM = m;
578 }
579 
580 bool Icmpv6RA::GetFlagO () const
581 {
582  NS_LOG_FUNCTION (this);
583  return m_flagO;
584 }
585 
586 void Icmpv6RA::SetFlagO (bool o)
587 {
588  NS_LOG_FUNCTION (this << o);
589  m_flagO = o;
590 }
591 
592 bool Icmpv6RA::GetFlagH () const
593 {
594  NS_LOG_FUNCTION (this);
595  return m_flagH;
596 }
597 
598 void Icmpv6RA::SetFlagH (bool h)
599 {
600  NS_LOG_FUNCTION (this << h);
601  m_flagH = h;
602 }
603 
604 uint8_t Icmpv6RA::GetFlags () const
605 {
606  NS_LOG_FUNCTION (this);
607  return 0;
608 }
609 
610 void Icmpv6RA::SetFlags (uint8_t f)
611 {
612  NS_LOG_FUNCTION (this << static_cast<uint32_t> (f));
613 }
614 
615 void Icmpv6RA::Print (std::ostream& os) const
616 {
617  NS_LOG_FUNCTION (this << &os);
618  os << "( type = " << (uint32_t)GetType () << " (RA) code = " << (uint32_t)GetCode () << " checksum = " << (uint32_t)GetChecksum () << ")";
619 }
620 
622 {
623  NS_LOG_FUNCTION (this);
624  return 16;
625 }
626 
628 {
629  NS_LOG_FUNCTION (this << &start);
630  uint16_t checksum = 0;
632  uint8_t flags = 0;
633 
634  i.WriteU8 (GetType ());
635  i.WriteU8 (GetCode ());
636  i.WriteHtonU16 (0);
638 
639  if (m_flagM)
640  {
641  flags |= (uint8_t)(1<< 7);
642  }
643 
644  if (m_flagO)
645  {
646  flags |= (uint8_t)(1<< 6);
647  }
648 
649  if (m_flagH)
650  {
651  flags |= (uint8_t)(1<< 5);
652  }
653  i.WriteU8 (flags);
654  i.WriteHtonU16 (GetLifeTime ());
657 
658  i = start;
659  checksum = i.CalculateIpChecksum (i.GetSize (), GetChecksum ());
660 
661  i = start;
662  i.Next (2);
663  i.WriteU16 (checksum);
664 }
665 
667 {
668  NS_LOG_FUNCTION (this << &start);
670 
671  SetType (i.ReadU8 ());
672  SetCode (i.ReadU8 ());
673  m_checksum = i.ReadU16 ();
674  SetCurHopLimit (i.ReadU8 ());
675  uint8_t flags = i.ReadU8 ();
676  m_flagM = false;
677  m_flagO = false;
678  m_flagH = false;
679 
680  if (flags & (1 << 7))
681  {
682  m_flagM = true;
683  }
684 
685  if (flags & (1 << 6))
686  {
687  m_flagO = true;
688  }
689 
690  if (flags & (1 << 5))
691  {
692  m_flagH = true;
693  }
694  SetLifeTime (i.ReadNtohU16 ());
697 
698  return GetSerializedSize ();
699 }
700 
702 
704 {
705  static TypeId tid = TypeId ("ns3::Icmpv6RS")
707  .SetGroupName ("Internet")
708  .AddConstructor<Icmpv6RS> ()
709  ;
710  return tid;
711 }
712 
714 {
715  NS_LOG_FUNCTION (this);
716  return GetTypeId ();
717 }
718 
720 {
721  NS_LOG_FUNCTION (this);
723  SetCode (0);
724  SetReserved (0);
725 }
726 
728 {
729  NS_LOG_FUNCTION (this);
730 }
731 
732 uint32_t Icmpv6RS::GetReserved () const
733 {
734  NS_LOG_FUNCTION (this);
735  return m_reserved;
736 }
737 
738 void Icmpv6RS::SetReserved (uint32_t reserved)
739 {
740  NS_LOG_FUNCTION (this << reserved);
741  m_reserved = reserved;
742 }
743 
744 void Icmpv6RS::Print (std::ostream& os) const
745 {
746  NS_LOG_FUNCTION (this << &os);
747  os << "( type = " << (uint32_t)GetType () << " (RS) code = " << (uint32_t)GetCode () << " checksum = " << (uint32_t)GetChecksum () << ")";
748 }
749 
751 {
752  NS_LOG_FUNCTION (this);
753  return 8;
754 }
755 
757 {
758  NS_LOG_FUNCTION (this << &start);
759 
760  uint16_t checksum = 0;
762 
763  i.WriteU8 (GetType ());
764  i.WriteU8 (GetCode ());
765  i.WriteU16 (0);
767 
768  if (m_calcChecksum)
769  {
770  i = start;
771  checksum = i.CalculateIpChecksum (i.GetSize (), GetChecksum ());
772 
773  i = start;
774  i.Next (2);
775  i.WriteU16 (checksum);
776  }
777 }
778 
780 {
781  NS_LOG_FUNCTION (this << &start);
783 
784  SetType (i.ReadU8 ());
785  SetCode (i.ReadU8 ());
786  m_checksum = i.ReadU16 ();
787  m_reserved = i.ReadNtohU32 ();
788 
789  return GetSerializedSize ();
790 }
791 
793 
795 {
796  static TypeId tid = TypeId ("ns3::Icmpv6Redirection")
798  .SetGroupName ("Internet")
799  .AddConstructor<Icmpv6Redirection> ()
800  ;
801  return tid;
802 }
803 
805 {
806  NS_LOG_FUNCTION (this);
807  return GetTypeId ();
808 }
809 
811  : m_target (Ipv6Address ("")),
812  m_destination (Ipv6Address ("")),
813  m_reserved (0)
814 {
815  NS_LOG_FUNCTION (this);
817  SetCode (0);
818  m_checksum = 0;
819 }
820 
822 {
823  NS_LOG_FUNCTION (this);
824 }
825 
826 void Icmpv6Redirection::SetReserved (uint32_t reserved)
827 {
828  NS_LOG_FUNCTION (this << reserved);
829  m_reserved = reserved;
830 }
831 
833 {
834  NS_LOG_FUNCTION (this);
835  return m_reserved;
836 }
837 
839 {
840  NS_LOG_FUNCTION (this);
841  return m_target;
842 }
843 
845 {
846  NS_LOG_FUNCTION (this << target);
847  m_target = target;
848 }
849 
851 {
852  NS_LOG_FUNCTION (this);
853  return m_destination;
854 }
855 
857 {
858  NS_LOG_FUNCTION (this << destination);
859  m_destination = destination;
860 }
861 
862 void Icmpv6Redirection::Print (std::ostream& os) const
863 {
864  NS_LOG_FUNCTION (this << &os);
865  os << "( type = " << (uint32_t)GetType () << " (Redirection) code = " << (uint32_t)GetCode () << " checksum = " << (uint32_t)GetChecksum () << " target = " << m_target << " destination = " << m_destination << ")";
866 }
867 
869 {
870  NS_LOG_FUNCTION (this);
871  return 40;
872 }
873 
875 {
876  NS_LOG_FUNCTION (this << &start);
877  uint8_t buff[16];
878  uint16_t checksum = 0;
880 
881  i.WriteU8 (GetType ());
882  i.WriteU8 (GetCode ());
883  i.WriteU16 (checksum);
884  i.WriteU32 (m_reserved);
885 
886  m_target.Serialize (buff);
887  i.Write (buff, 16);
888 
889  m_destination.Serialize (buff);
890  i.Write (buff, 16);
891 
892  if (m_calcChecksum)
893  {
894  i = start;
895  checksum = i.CalculateIpChecksum (i.GetSize (), GetChecksum ());
896 
897  i = start;
898  i.Next (2);
899  i.WriteU16 (checksum);
900  }
901 }
902 
904 {
905  NS_LOG_FUNCTION (this << &start);
906  uint8_t buff[16];
908 
909  SetType (i.ReadU8 ());
910  SetCode (i.ReadU8 ());
911  m_checksum = i.ReadU16 ();
912  SetReserved (i.ReadU32 ());
913 
914  i.Read (buff, 16);
915  m_target.Set (buff);
916 
917  i.Read (buff, 16);
918  m_destination.Set (buff);
919 
920  return GetSerializedSize ();
921 }
922 
924 
926 {
927  static TypeId tid = TypeId ("ns3::Icmpv6Echo")
929  .SetGroupName ("Internet")
930  .AddConstructor<Icmpv6Echo> ()
931  ;
932  return tid;
933 }
934 
936 {
937  NS_LOG_FUNCTION (this);
938  return GetTypeId ();
939 }
940 
942 {
943  NS_LOG_FUNCTION (this);
945  SetCode (0);
946  m_checksum = 0;
947  SetId (0);
948  SetSeq (0);
949 }
950 
952 {
953  NS_LOG_FUNCTION (this << request);
955  SetCode (0);
956  m_checksum = 0;
957  SetId (0);
958  SetSeq (0);
959 }
960 
962 {
963  NS_LOG_FUNCTION (this);
964 }
965 
966 uint16_t Icmpv6Echo::GetId () const
967 {
968  NS_LOG_FUNCTION (this);
969  return m_id;
970 }
971 
972 void Icmpv6Echo::SetId (uint16_t id)
973 {
974  NS_LOG_FUNCTION (this << id);
975  m_id = id;
976 }
977 
978 uint16_t Icmpv6Echo::GetSeq () const
979 {
980  NS_LOG_FUNCTION (this);
981  return m_seq;
982 }
983 
984 void Icmpv6Echo::SetSeq (uint16_t seq)
985 {
986  NS_LOG_FUNCTION (this << seq);
987  m_seq = seq;
988 }
989 
990 void Icmpv6Echo::Print (std::ostream& os) const
991 {
992  NS_LOG_FUNCTION (this << &os);
993  os << "( type = " << (GetType () == 128 ? "128 (Request)" : "129 (Reply)") <<
994  " code = " << (uint32_t)GetCode () <<
995  " checksum = " << (uint32_t)GetChecksum () << ")";
996 }
997 
999 {
1000  NS_LOG_FUNCTION (this);
1001  return 8;
1002 }
1003 
1005 {
1006  NS_LOG_FUNCTION (this << &start);
1007  uint16_t checksum = 0;
1008  Buffer::Iterator i = start;
1009 
1010  i.WriteU8 (GetType ());
1011  i.WriteU8 (GetCode ());
1012  i.WriteHtonU16 (0);
1013 
1014  i.WriteHtonU16 (m_id);
1015  i.WriteHtonU16 (m_seq);
1016 
1017  if (m_calcChecksum)
1018  {
1019  i = start;
1020  checksum = i.CalculateIpChecksum (i.GetSize (), GetChecksum ());
1021  i = start;
1022  i.Next (2);
1023  i.WriteU16 (checksum);
1024  }
1025 }
1026 
1028 {
1029  NS_LOG_FUNCTION (this << &start);
1030  Buffer::Iterator i = start;
1031 
1032  SetType (i.ReadU8 ());
1033  SetCode (i.ReadU8 ());
1034  m_checksum = i.ReadU16 ();
1035 
1036  m_id = i.ReadNtohU16 ();
1037  m_seq = i.ReadNtohU16 ();
1038  return GetSerializedSize ();
1039 }
1040 
1042 
1044 {
1045  static TypeId tid = TypeId ("ns3::Icmpv6DestinationUnreachable")
1046  .SetParent<Icmpv6Header> ()
1047  .SetGroupName ("Internet")
1048  .AddConstructor<Icmpv6DestinationUnreachable> ()
1049  ;
1050  return tid;
1051 }
1052 
1054 {
1055  NS_LOG_FUNCTION (this);
1056  return GetTypeId ();
1057 }
1058 
1060  : m_packet (0)
1061 {
1062  NS_LOG_FUNCTION (this);
1064 }
1065 
1067 {
1068  NS_LOG_FUNCTION (this);
1069 }
1070 
1072 {
1073  NS_LOG_FUNCTION (this);
1074  return m_packet;
1075 }
1076 
1078 {
1079  NS_LOG_FUNCTION (this << *p);
1080  NS_ASSERT (p->GetSize () <= 1280);
1081  m_packet = p;
1082 }
1083 
1084 void Icmpv6DestinationUnreachable::Print (std::ostream& os) const
1085 {
1086  NS_LOG_FUNCTION (this << &os);
1087  os << "( type = " << (uint32_t)GetType () << " (Destination Unreachable) code = " << (uint32_t)GetCode () << " checksum = " << (uint32_t)GetChecksum () << ")";
1088 }
1089 
1091 {
1092  NS_LOG_FUNCTION (this);
1093  return 8 + m_packet->GetSize ();
1094 }
1095 
1097 {
1098  NS_LOG_FUNCTION (this << &start);
1099  uint16_t checksum = 0;
1100  Buffer::Iterator i = start;
1101 
1102  i.WriteU8 (GetType ());
1103  i.WriteU8 (GetCode ());
1104  i.WriteHtonU16 (0);
1105  i.WriteHtonU32 (0);
1106 
1107  uint32_t size = m_packet->GetSize ();
1108  uint8_t *buf = new uint8_t[size];
1109  m_packet->CopyData (buf, size);
1110  i.Write (buf, size);
1111  delete[] buf;
1112 
1113  i = start;
1114  checksum = i.CalculateIpChecksum (i.GetSize (), GetChecksum ());
1115 
1116  i = start;
1117  i.Next (2);
1118  i.WriteU16 (checksum);
1119 }
1120 
1122 {
1123  NS_LOG_FUNCTION (this << &start);
1124  uint16_t length = start.GetRemainingSize () - 8;
1125  uint8_t* data = new uint8_t[length];
1126  Buffer::Iterator i = start;
1127 
1128  SetType (i.ReadU8 ());
1129  SetCode (i.ReadU8 ());
1130  m_checksum = i.ReadU16 ();
1131  i.ReadNtohU32 ();
1132  i.Read (data, length);
1133  m_packet = Create<Packet> (data, length);
1134 
1135  delete[] data;
1136  return GetSerializedSize ();
1137 }
1138 
1140 
1142 {
1143  static TypeId tid = TypeId ("ns3::Icmpv6TooBig")
1144  .SetParent<Icmpv6Header> ()
1145  .SetGroupName ("Internet")
1146  .AddConstructor<Icmpv6TooBig> ()
1147  ;
1148  return tid;
1149 }
1150 
1152 {
1153  NS_LOG_FUNCTION (this);
1154  return GetTypeId ();
1155 }
1156 
1158  : m_packet (0),
1159  m_mtu (0)
1160 {
1161  NS_LOG_FUNCTION (this);
1163 }
1164 
1166 {
1167  NS_LOG_FUNCTION (this);
1168 }
1169 
1171 {
1172  NS_LOG_FUNCTION (this);
1173  return m_packet;
1174 }
1175 
1177 {
1178  NS_LOG_FUNCTION (this << *p);
1179  NS_ASSERT (p->GetSize () <= 1280);
1180  m_packet = p;
1181 }
1182 
1183 uint32_t Icmpv6TooBig::GetMtu () const
1184 {
1185  NS_LOG_FUNCTION (this);
1186  return m_mtu;
1187 }
1188 
1189 void Icmpv6TooBig::SetMtu (uint32_t mtu)
1190 {
1191  NS_LOG_FUNCTION (this << mtu);
1192  m_mtu = mtu;
1193 }
1194 
1195 void Icmpv6TooBig::Print (std::ostream& os) const
1196 {
1197  NS_LOG_FUNCTION (this << &os);
1198  os << "( type = " << (uint32_t)GetType () << " (Too Big) code = " << (uint32_t)GetCode () << " checksum = " << (uint32_t)GetChecksum () << " mtu = " << (uint32_t)GetMtu () << ")";
1199 }
1200 
1202 {
1203  NS_LOG_FUNCTION (this);
1204  return 8 + m_packet->GetSize ();
1205 }
1206 
1208 {
1209  NS_LOG_FUNCTION (this << &start);
1210  uint16_t checksum = 0;
1211  Buffer::Iterator i = start;
1212 
1213  i.WriteU8 (GetType ());
1214  i.WriteU8 (GetCode ());
1215  i.WriteHtonU16 (0);
1216  i.WriteHtonU32 (GetMtu ());
1217 
1218  uint32_t size = m_packet->GetSize ();
1219  uint8_t *buf = new uint8_t[size];
1220  m_packet->CopyData (buf, size);
1221  i.Write (buf, size);
1222  delete[] buf;
1223 
1224  i = start;
1225  checksum = i.CalculateIpChecksum (i.GetSize (), GetChecksum ());
1226 
1227  i = start;
1228  i.Next (2);
1229  i.WriteU16 (checksum);
1230 }
1231 
1233 {
1234  NS_LOG_FUNCTION (this << &start);
1235  uint16_t length = start.GetRemainingSize () - 8;
1236  uint8_t* data = new uint8_t[length];
1237  Buffer::Iterator i = start;
1238 
1239  SetType (i.ReadU8 ());
1240  SetCode (i.ReadU8 ());
1241  m_checksum = i.ReadU16 ();
1242  SetMtu (i.ReadNtohU32 ());
1243  i.Read (data, length);
1244  m_packet = Create<Packet> (data, length);
1245 
1246  delete[] data;
1247  return GetSerializedSize ();
1248 }
1249 
1251 
1253 {
1254  static TypeId tid = TypeId ("ns3::Icmpv6TimeExceeded")
1255  .SetParent<Icmpv6Header> ()
1256  .SetGroupName ("Internet")
1257  .AddConstructor<Icmpv6TimeExceeded> ()
1258  ;
1259  return tid;
1260 }
1261 
1263 {
1264  NS_LOG_FUNCTION (this);
1265  return GetTypeId ();
1266 }
1267 
1269  : m_packet (0)
1270 {
1271  NS_LOG_FUNCTION (this);
1273 }
1274 
1276 {
1277  NS_LOG_FUNCTION (this);
1278 }
1279 
1281 {
1282  NS_LOG_FUNCTION (this);
1283  return m_packet;
1284 }
1285 
1287 {
1288  NS_LOG_FUNCTION (this << *p);
1289  NS_ASSERT (p->GetSize () <= 1280);
1290  m_packet = p;
1291 }
1292 
1293 void Icmpv6TimeExceeded::Print (std::ostream& os) const
1294 {
1295  NS_LOG_FUNCTION (this << &os);
1296  os << "( type = " << (uint32_t)GetType () << " (Destination Unreachable) code = " << (uint32_t)GetCode () << " checksum = " << (uint32_t)GetChecksum () << ")";
1297 }
1298 
1300 {
1301  NS_LOG_FUNCTION (this);
1302  return 8 + m_packet->GetSize ();
1303 }
1304 
1306 {
1307  NS_LOG_FUNCTION (this << &start);
1308 
1309  uint16_t checksum = 0;
1310  Buffer::Iterator i = start;
1311 
1312  i.WriteU8 (GetType ());
1313  i.WriteU8 (GetCode ());
1314  i.WriteHtonU16 (0);
1315  i.WriteHtonU32 (0);
1316 
1317  uint32_t size = m_packet->GetSize ();
1318  uint8_t *buf = new uint8_t[size];
1319  m_packet->CopyData (buf, size);
1320  i.Write (buf, size);
1321  delete[] buf;
1322 
1323  i = start;
1324  checksum = i.CalculateIpChecksum (i.GetSize (), GetChecksum ());
1325 
1326  i = start;
1327  i.Next (2);
1328  i.WriteU16 (checksum);
1329 }
1330 
1332 {
1333  NS_LOG_FUNCTION (this << &start);
1334 
1335  uint16_t length = start.GetRemainingSize () - 8;
1336  uint8_t* data = new uint8_t[length];
1337  Buffer::Iterator i = start;
1338 
1339  SetType (i.ReadU8 ());
1340  SetCode (i.ReadU8 ());
1341  m_checksum = i.ReadU16 ();
1342  i.ReadNtohU32 ();
1343  i.Read (data, length);
1344  m_packet = Create<Packet> (data, length);
1345 
1346  delete[] data;
1347  return GetSerializedSize ();
1348 }
1349 
1351 
1353 {
1354  static TypeId tid = TypeId ("ns3::Icmpv6ParameterError")
1355  .SetParent<Icmpv6Header> ()
1356  .SetGroupName ("Internet")
1357  .AddConstructor<Icmpv6ParameterError> ()
1358  ;
1359  return tid;
1360 }
1361 
1363 {
1364  NS_LOG_FUNCTION (this);
1365  return GetTypeId ();
1366 }
1367 
1369  : m_packet (0),
1370  m_ptr (0)
1371 {
1372  NS_LOG_FUNCTION (this);
1374 }
1375 
1377 {
1378  NS_LOG_FUNCTION (this);
1379 }
1380 
1382 {
1383  NS_LOG_FUNCTION (this);
1384  return m_packet;
1385 }
1386 
1388 {
1389  NS_LOG_FUNCTION (this << *p);
1390  NS_ASSERT (p->GetSize () <= 1280);
1391  m_packet = p;
1392 }
1393 
1395 {
1396  NS_LOG_FUNCTION (this);
1397  return m_ptr;
1398 }
1399 
1400 void Icmpv6ParameterError::SetPtr (uint32_t ptr)
1401 {
1402  NS_LOG_FUNCTION (this << ptr);
1403  m_ptr = ptr;
1404 }
1405 
1406 void Icmpv6ParameterError::Print (std::ostream& os) const
1407 {
1408  NS_LOG_FUNCTION (this << &os);
1409  os << "( type = " << (uint32_t)GetType () << " (Destination Unreachable) code = " << (uint32_t)GetCode () << " checksum = " << (uint32_t)GetChecksum () << " ptr = " << (uint32_t)GetPtr () << ")";
1410 }
1411 
1413 {
1414  NS_LOG_FUNCTION (this);
1415  return 8 + m_packet->GetSize ();
1416 }
1417 
1419 {
1420  NS_LOG_FUNCTION (this << &start);
1421  uint16_t checksum = 0;
1422  Buffer::Iterator i = start;
1423 
1424  i.WriteU8 (GetType ());
1425  i.WriteU8 (GetCode ());
1426  i.WriteHtonU16 (0);
1427  i.WriteHtonU32 (GetPtr ());
1428 
1429  uint32_t size = m_packet->GetSize ();
1430  uint8_t *buf = new uint8_t[size];
1431  m_packet->CopyData (buf, size);
1432  i.Write (buf, size);
1433  delete[] buf;
1434 
1435  i = start;
1436  checksum = i.CalculateIpChecksum (i.GetSize (), GetChecksum ());
1437 
1438  i = start;
1439  i.Next (2);
1440  i.WriteU16 (checksum);
1441 }
1442 
1444 {
1445  NS_LOG_FUNCTION (this << &start);
1446  uint16_t length = start.GetRemainingSize () - 8;
1447  uint8_t* data = new uint8_t[length];
1448  Buffer::Iterator i = start;
1449 
1450  SetType (i.ReadU8 ());
1451  SetCode (i.ReadU8 ());
1452  m_checksum = i.ReadU16 ();
1453  SetPtr (i.ReadNtohU32 ());
1454  i.Read (data, length);
1455  m_packet = Create<Packet> (data, length);
1456  delete[] data;
1457 
1458  return GetSerializedSize ();
1459 }
1460 
1462 
1464 {
1465  static TypeId tid = TypeId ("ns3::Icmpv6OptionHeader")
1466  .SetParent<Header> ()
1467  .SetGroupName ("Internet")
1468  .AddConstructor<Icmpv6OptionHeader> ()
1469  ;
1470  return tid;
1471 }
1472 
1474 {
1475  NS_LOG_FUNCTION (this);
1476  return GetTypeId ();
1477 }
1478 
1479 
1481 {
1482  NS_LOG_FUNCTION (this);
1484  m_type = 0;
1485  m_len = 0;
1486 }
1487 
1489 {
1490  NS_LOG_FUNCTION (this);
1491 }
1492 
1494 {
1495  NS_LOG_FUNCTION (this);
1496  return m_type;
1497 }
1498 
1499 void Icmpv6OptionHeader::SetType (uint8_t type)
1500 {
1501  NS_LOG_FUNCTION (this << static_cast<uint32_t> (type));
1502  m_type = type;
1503 }
1504 
1506 {
1507  NS_LOG_FUNCTION (this);
1508  return m_len;
1509 }
1510 
1512 {
1513  NS_LOG_FUNCTION (this << static_cast<uint32_t> (len));
1514  m_len = len;
1515 }
1516 
1517 void Icmpv6OptionHeader::Print (std::ostream& os) const
1518 {
1519  NS_LOG_FUNCTION (this << &os);
1520  os << "( type = " << (uint32_t)GetType () << " length = " << (uint32_t)GetLength () << ")";
1521 }
1522 
1524 {
1525  NS_LOG_FUNCTION (this);
1526  return m_len*8;
1527 }
1528 
1530 {
1531  NS_LOG_FUNCTION (this << &start);
1532  return GetSerializedSize ();
1533 }
1534 
1536 {
1537  NS_LOG_FUNCTION (this << &start);
1538 }
1539 
1541 
1543 {
1544  static TypeId tid = TypeId ("ns3::Icmpv6OptionMtu")
1546  .SetGroupName ("Internet")
1547  .AddConstructor<Icmpv6OptionMtu> ()
1548  ;
1549  return tid;
1550 }
1551 
1553 {
1554  NS_LOG_FUNCTION (this);
1555  return GetTypeId ();
1556 }
1557 
1559 {
1560  NS_LOG_FUNCTION (this);
1562  SetLength (1);
1563  SetReserved (0);
1564 }
1565 
1567  : m_mtu (mtu)
1568 {
1569  NS_LOG_FUNCTION (this << mtu);
1571  SetLength (1);
1572  SetReserved (0);
1573 }
1574 
1576 {
1577  NS_LOG_FUNCTION (this);
1578 }
1579 
1581 {
1582  NS_LOG_FUNCTION (this);
1583  return m_reserved;
1584 }
1585 
1586 void Icmpv6OptionMtu::SetReserved (uint16_t reserved)
1587 {
1588  NS_LOG_FUNCTION (this << reserved);
1589  m_reserved = reserved;
1590 }
1591 
1592 uint32_t Icmpv6OptionMtu::GetMtu () const
1593 {
1594  NS_LOG_FUNCTION (this);
1595  return m_mtu;
1596 }
1597 
1598 void Icmpv6OptionMtu::SetMtu (uint32_t mtu)
1599 {
1600  NS_LOG_FUNCTION (this << mtu);
1601  m_mtu = mtu;
1602 }
1603 
1604 void Icmpv6OptionMtu::Print (std::ostream& os) const
1605 {
1606  NS_LOG_FUNCTION (this << &os);
1607  os << "( type = " << (uint32_t)GetType () << " length = " << (uint32_t)GetLength () << " MTU = " << m_mtu << ")";
1608 }
1609 
1611 {
1612  NS_LOG_FUNCTION (this);
1613  return 8; /* m_len = 1 so the real size is multiple by 8 */
1614 }
1615 
1617 {
1618  NS_LOG_FUNCTION (this << &start);
1619  Buffer::Iterator i = start;
1620  i.WriteU8 (GetType ());
1621  i.WriteU8 (GetLength ());
1622  i.WriteHtonU16 (GetReserved ());
1623  i.WriteHtonU32 (GetMtu ());
1624 }
1625 
1627 {
1628  NS_LOG_FUNCTION (this << &start);
1629  Buffer::Iterator i = start;
1630  SetType (i.ReadU8 ());
1631  SetLength (i.ReadU8 ());
1632  SetReserved (i.ReadNtohU16 ());
1633  SetMtu (i.ReadNtohU32 ());
1634  return GetSerializedSize ();
1635 }
1636 
1638 
1640 {
1641  static TypeId tid = TypeId ("ns3::Icmpv6OptionPrefixInformation")
1643  .SetGroupName ("Internet")
1644  .AddConstructor<Icmpv6OptionPrefixInformation> ()
1645  ;
1646  return tid;
1647 }
1648 
1650 {
1651  NS_LOG_FUNCTION (this);
1652  return GetTypeId ();
1653 }
1654 
1656 {
1657  NS_LOG_FUNCTION (this);
1659  SetLength (4);
1660  SetPrefix (Ipv6Address ("::"));
1661  SetPrefixLength (0);
1662  SetValidTime (0);
1663  SetPreferredTime (0);
1664  SetFlags (0);
1665  SetReserved (0);
1666 }
1667 
1669 {
1670  NS_LOG_FUNCTION (this << prefix << static_cast<uint32_t> (prefixlen));
1672  SetLength (4);
1673  SetPrefix (prefix);
1674  SetPrefixLength (prefixlen);
1675  SetValidTime (0);
1676  SetPreferredTime (0);
1677  SetFlags (0);
1678  SetReserved (0);
1679 }
1680 
1682 {
1683  NS_LOG_FUNCTION (this);
1684 }
1685 
1687 {
1688  NS_LOG_FUNCTION (this);
1689  return m_prefixLength;
1690 }
1691 
1693 {
1694  NS_LOG_FUNCTION (this << static_cast<uint32_t> (prefixLength));
1695  NS_ASSERT (prefixLength <= 128);
1696  m_prefixLength = prefixLength;
1697 }
1698 
1700 {
1701  NS_LOG_FUNCTION (this);
1702  return m_flags;
1703 }
1704 
1706 {
1707  NS_LOG_FUNCTION (this);
1708  m_flags = flags;
1709 }
1710 
1712 {
1713  NS_LOG_FUNCTION (this);
1714  return m_validTime;
1715 }
1716 
1718 {
1719  NS_LOG_FUNCTION (this << validTime);
1720  m_validTime = validTime;
1721 }
1722 
1724 {
1725  NS_LOG_FUNCTION (this);
1726  return m_preferredTime;
1727 }
1728 
1730 {
1731  NS_LOG_FUNCTION (this << preferredTime);
1732  m_preferredTime = preferredTime;
1733 }
1734 
1736 {
1737  NS_LOG_FUNCTION (this);
1738  return m_preferredTime;
1739 }
1740 
1742 {
1743  NS_LOG_FUNCTION (this << reserved);
1744  m_reserved = reserved;
1745 }
1746 
1748 {
1749  NS_LOG_FUNCTION (this);
1750  return m_prefix;
1751 }
1752 
1754 {
1755  NS_LOG_FUNCTION (this << prefix);
1756  m_prefix = prefix;
1757 }
1758 
1759 void Icmpv6OptionPrefixInformation::Print (std::ostream& os) const
1760 {
1761  NS_LOG_FUNCTION (this << &os);
1762  os << "( type = " << (uint32_t)GetType () << " length = " << (uint32_t)GetLength () << " prefix " << m_prefix << ")";
1763 }
1764 
1766 {
1767  NS_LOG_FUNCTION (this);
1768  return 32;
1769 }
1770 
1772 {
1773  NS_LOG_FUNCTION (this << &start);
1774  Buffer::Iterator i = start;
1775  uint8_t buf[16];
1776 
1777  memset (buf, 0x00, sizeof (buf));
1778 
1779  i.WriteU8 (GetType ());
1780  i.WriteU8 (GetLength ());
1781  i.WriteU8 (m_prefixLength);
1782  i.WriteU8 (m_flags);
1786  m_prefix.GetBytes (buf);
1787  i.Write (buf, 16);
1788 }
1789 
1791 {
1792  NS_LOG_FUNCTION (this << &start);
1793  Buffer::Iterator i = start;
1794  uint8_t buf[16];
1795 
1796  SetType (i.ReadU8 ());
1797  SetLength (i.ReadU8 ());
1798  SetPrefixLength (i.ReadU8 ());
1799  SetFlags (i.ReadU8 ());
1800  SetValidTime (i.ReadNtohU32 ());
1802  SetReserved (i.ReadNtohU32 ());
1803  i.Read (buf, 16);
1804 
1805  Ipv6Address prefix (buf);
1806  SetPrefix (prefix);
1807 
1808  return GetSerializedSize ();
1809 }
1810 
1812 
1814 {
1815  static TypeId tid = TypeId ("ns3::Icmpv6OptionLinkLayerAddress")
1817  .SetGroupName ("Internet")
1818  .AddConstructor<Icmpv6OptionLinkLayerAddress> ()
1819  ;
1820  return tid;
1821 }
1822 
1824 {
1825  NS_LOG_FUNCTION (this);
1826  return GetTypeId ();
1827 }
1828 
1830 {
1831  NS_LOG_FUNCTION (this << source);
1833 }
1834 
1836 {
1837  NS_LOG_FUNCTION (this);
1839 }
1840 
1842 {
1843  NS_LOG_FUNCTION (this << source << addr);
1845  SetAddress (addr);
1846 
1847  uint8_t len = (2 + m_addr.GetLength ()) / 8;
1848  if ( (2 + m_addr.GetLength ()) % 8 )
1849  {
1850  len ++;
1851  }
1852  SetLength (len);
1853 }
1854 
1856 {
1857  NS_LOG_FUNCTION (this);
1858 }
1859 
1861 {
1862  NS_LOG_FUNCTION (this);
1863  return m_addr;
1864 }
1865 
1867 {
1868  NS_LOG_FUNCTION (this << addr);
1869  m_addr = addr;
1870 }
1871 
1872 void Icmpv6OptionLinkLayerAddress::Print (std::ostream& os) const
1873 {
1874  NS_LOG_FUNCTION (this << &os);
1875  os << "( type = " << (uint32_t)GetType () << " length = " << (uint32_t)GetLength () << " L2 Address = " << m_addr << ")";
1876 }
1877 
1879 {
1880  NS_LOG_FUNCTION (this);
1881  uint8_t nb = GetLength() * 8;
1882  return nb;
1883 }
1884 
1886 {
1887  NS_LOG_FUNCTION (this << &start);
1888  Buffer::Iterator i = start;
1889  uint8_t mac[32];
1890 
1891  i.WriteU8 (GetType ());
1892  i.WriteU8 (GetLength ());
1893  m_addr.CopyTo (mac);
1894  i.Write (mac, m_addr.GetLength ());
1895 
1896  uint8_t len = GetLength ()*8 - (2 + m_addr.GetLength ());
1897  for (uint8_t nb = 0; nb<len; nb++)
1898  {
1899  i.WriteU8 (0);
1900  }
1901 }
1902 
1904 {
1905  NS_LOG_FUNCTION (this << &start);
1906  Buffer::Iterator i = start;
1907  uint8_t mac[32];
1908 
1909  SetType (i.ReadU8 ());
1910  SetLength (i.ReadU8 ());
1911  // -fstrict-overflow sensitive, see bug 1868
1912  NS_ASSERT (GetLength () * 8 <= 32 + 2);
1913  i.Read (mac, (GetLength () * 8) - 2);
1914 
1915  m_addr.CopyFrom (mac, (GetLength () * 8) - 2);
1916 
1917  return GetSerializedSize ();
1918 }
1919 
1921 
1923 {
1924  static TypeId tid = TypeId ("ns3::Icmpv6OptionRedirected")
1926  .SetGroupName ("Internet")
1927  .AddConstructor<Icmpv6OptionRedirected> ()
1928  ;
1929  return tid;
1930 }
1931 
1933 {
1934  NS_LOG_FUNCTION (this);
1935  return GetTypeId ();
1936 }
1937 
1939  : m_packet (0)
1940 {
1941  NS_LOG_FUNCTION (this);
1943 }
1944 
1946 {
1947  NS_LOG_FUNCTION (this);
1948  m_packet = 0;
1949 }
1950 
1952 {
1953  NS_LOG_FUNCTION (this);
1954  return m_packet;
1955 }
1956 
1958 {
1959  NS_LOG_FUNCTION (this << *packet);
1960  NS_ASSERT (packet->GetSize () <= 1280);
1961  m_packet = packet;
1962  SetLength (1 + (m_packet->GetSize () / 8));
1963 }
1964 
1965 void Icmpv6OptionRedirected::Print (std::ostream& os) const
1966 {
1967  NS_LOG_FUNCTION (this << &os);
1968  os << "( type = " << (uint32_t)GetType () << " length = " << (uint32_t)GetLength () << ")";
1969 }
1970 
1972 {
1973  NS_LOG_FUNCTION (this);
1974  return 8 + m_packet->GetSize ();
1975 }
1976 
1978 {
1979  NS_LOG_FUNCTION (this << &start);
1980  Buffer::Iterator i = start;
1981 
1982  i.WriteU8 (GetType ());
1983  i.WriteU8 (GetLength ());
1984  // Reserved
1985  i.WriteU16 (0);
1986  i.WriteU32 (0);
1987 
1988  uint32_t size = m_packet->GetSize ();
1989  uint8_t *buf = new uint8_t[size];
1990  m_packet->CopyData (buf, size);
1991  i.Write (buf, size);
1992  delete[] buf;
1993 }
1994 
1996 {
1997  NS_LOG_FUNCTION (this << &start);
1998  Buffer::Iterator i = start;
1999 
2000  SetType (i.ReadU8 ());
2001  uint8_t length = i.ReadU8 ();
2002  SetLength (length);
2003  i.ReadU16 ();
2004  i.ReadU32 ();
2005 
2006  uint32_t len2 = (GetLength () - 1) * 8;
2007  uint8_t* buff = new uint8_t[len2];
2008  i.Read (buff, len2);
2009  m_packet = Create<Packet> (buff, len2);
2010  delete[] buff;
2011 
2012  return GetSerializedSize ();
2013 }
2014 
2015 } /* namespace ns3 */
2016 
uint16_t ReadU16(void)
Definition: buffer.h:1029
Protocol header serialization and deserialization.
Definition: header.h:42
uint16_t CalculateIpChecksum(uint16_t size)
Calculate the checksum.
Definition: buffer.cc:1133
uint16_t GetSeq() const
Get the sequence number.
Icmpv6OptionHeader()
Constructor.
Ipv6Address m_destination
IPv6 destination address.
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
virtual void Print(std::ostream &os) const
Print information.
void SetLength(uint8_t len)
Set the length of the option.
uint32_t m_reserved
Reserved value.
void SetPacket(Ptr< Packet > packet)
Set the redirected packet.
void CalculatePseudoHeaderChecksum(Ipv6Address src, Ipv6Address dst, uint16_t length, uint8_t protocol)
Calculate pseudo header checksum for IPv6.
ICMPv6 redirected option.
void AddAtStart(uint32_t start)
Definition: buffer.cc:309
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
bool GetFlagS() const
Get the S flag.
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
uint32_t m_RetransmissionTimer
The retransmission timer.
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
Ipv6Address GetIpv6Target() const
Get the IPv6 target field.
uint32_t ReadU32(void)
Definition: buffer.cc:972
static TypeId GetTypeId()
Get the UID of this class.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
ICMPv6 Error Parameter Error header.
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
virtual uint32_t GetSerializedSize() const
Get the serialized size.
ICMPv6 Router Advertisement header.
virtual uint32_t GetSerializedSize() const
Get the serialized size.
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
ICMPv6 Neighbor Advertisement header.
static TypeId GetTypeId()
Get the UID of this class.
uint8_t m_type
The type.
bool m_flagR
The R flag.
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
Ptr< Packet > m_packet
The incorrect packet.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:852
Ptr< Packet > m_packet
The incorrect Packet.
Icmpv6OptionMtu()
Constructor.
void SetReserved(uint32_t reserved)
Set the reserved field (normally it will be 0x00000000).
uint8_t GetLength(void) const
Get the length of the underlying address.
Definition: address.cc:75
uint32_t m_validTime
The valid time.
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
void SetReserved(uint32_t reserved)
Set the reserved field.
Icmpv6NS()
Constructor.
virtual ~Icmpv6TimeExceeded()
Destructor.
virtual uint32_t GetSerializedSize() const
Get the serialized size.
ICMPv6 Error Time Exceeded header.
Icmpv6TimeExceeded()
Constructor.
Ptr< Packet > GetPacket() const
Get the incorrect packet.
automatically resized byte buffer
Definition: buffer.h:92
def start()
Definition: core.py:1855
ICMPv6 Router Solicitation header.
ICMPv6 Neighbor Solicitation header.
void SetType(uint8_t type)
Set the type of the option.
uint32_t m_preferredTime
The preferred time.
uint16_t m_reserved
The reserved value.
static TypeId GetTypeId()
Get the UID of this class.
uint32_t m_reserved
The reserved value.
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
void GetBytes(uint8_t buf[16]) const
Get the bytes corresponding to the address.
virtual void Print(std::ostream &os) const
Print information.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
virtual uint32_t GetSerializedSize() const
Get the serialized size.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
void SetPtr(uint32_t ptr)
Set the pointer field.
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
Ptr< Packet > m_packet
The redirected packet.
uint32_t GetReserved() const
Get the reserved field.
uint8_t m_len
The length.
void SetRetransmissionTime(uint32_t r)
Set the node Retransmission time (Neighbor Discovery).
static TypeId GetTypeId()
Get the UID of this class.
Ipv6Address m_target
IPv6 target address.
bool m_flagS
The O flag.
static TypeId GetTypeId()
Get the UID of this class.
Ipv6Address m_target
The IPv6 target address.
virtual ~Icmpv6OptionHeader()
Destructor.
NS_DEPRECATED_3_34 uint8_t GetFlags() const
Getflags.
uint16_t m_id
ID of the packet (to distinguish response between many ping program).
static TypeId GetTypeId()
Get the UID of this class.
void SetMtu(uint32_t mtu)
Set the MTU.
uint8_t GetType() const
Get the type of the option.
void SetPacket(Ptr< Packet > p)
Set the incorrect packet.
uint8_t m_code
The code.
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
void SetTarget(Ipv6Address target)
Set the IPv6 target address.
static TypeId GetTypeId()
Get the UID of this class.
Icmpv6NA()
Constructor.
uint32_t ReadNtohU32(void)
Definition: buffer.h:970
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
Icmpv6Echo()
Default constructor.
Ptr< Packet > GetPacket() const
Get the incorrect packet.
Icmpv6ParameterError()
Constructor.
static TypeId GetTypeId()
Get the UID of this class.
static TypeId GetTypeId()
Get the UID of this class.
iterator in a Buffer instance
Definition: buffer.h:98
a polymophic address class
Definition: address.h:90
virtual void Print(std::ostream &os) const
Print information.
void SetPacket(Ptr< Packet > p)
Set the incorrect packet.
uint32_t GetPreferredTime() const
Get the preferred time of the information.
virtual ~Icmpv6OptionPrefixInformation()
Destructor.
void SetLifeTime(uint16_t l)
Set the node Life time (Neighbor Discovery).
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
void SetValidTime(uint32_t validTime)
Set the valid time of the information.
uint8_t m_type
The type.
virtual void Print(std::ostream &os) const
Print information.
void SetIpv6Target(Ipv6Address target)
Set the IPv6 target field.
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
ICMPv6 Error Destination Unreachable header.
uint32_t GetMtu() const
Get the MTU field.
virtual ~Icmpv6ParameterError()
Destructor.
void SetType(uint8_t type)
Set the type.
void SetCurHopLimit(uint8_t m)
Set the IPv6 maximum number of jumps.
uint32_t GetValidTime() const
Get the valid time of the information.
virtual ~Icmpv6NA()
Destructor.
void SetPreferredTime(uint32_t preferredTime)
Set the preferred time of the information.
ICMPv6 header.
Definition: icmpv6-header.h:38
virtual uint32_t GetSerializedSize() const
Get the serialized size.
uint32_t m_reserved
The reserved value.
uint16_t m_checksum
The checksum.
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
void SetIpv6Target(Ipv6Address target)
Set the IPv6 target field.
uint8_t GetPrefixLength() const
Get the prefix length.
virtual void Print(std::ostream &os) const
Print information.
void SetPrefixLength(uint8_t prefixLength)
Set the prefix length.
ICMPv6 Option Prefix Information.
uint8_t data[writeSize]
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
void WriteU16(uint16_t data)
Definition: buffer.cc:870
Ipv6Address m_target
The IPv6 target address.
Ptr< Packet > m_packet
the incorrect packet.
uint32_t m_reserved
The reserved value.
bool m_flagH
The H flag.
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
uint32_t GetMtu() const
Get the MTU.
uint16_t GetLifeTime() const
Get the node Life time (Neighbor Discovery).
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
mac
Definition: third.py:99
void WriteHtonU16(uint16_t data)
Definition: buffer.h:905
uint32_t m_reserved
The reserved field.
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
Icmpv6RS()
Constructor.
virtual void Print(std::ostream &os) const
Print information.
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
virtual void Print(std::ostream &os) const
Print information.
uint8_t m_curHopLimit
The max jumps.
Ptr< Packet > GetPacket() const
Get the redirected packet.
bool GetFlagO() const
Get the O flag.
void Next(void)
go forward by one byte
Definition: buffer.h:845
ICMPv6 Redirection header.
uint32_t GetSize(void) const
Definition: buffer.cc:1158
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
Ipv6Address GetTarget() const
Get the IPv6 target address.
static TypeId GetTypeId()
Get the UID of this class.
uint32_t m_mtu
The MTU value.
void SetPacket(Ptr< Packet > p)
Set the incorrect packet.
bool m_calcChecksum
Checksum enable or not.
bool m_flagO
The O flag.
uint8_t GetLength() const
Get the length of the option in 8 bytes unit.
uint32_t GetReserved() const
Get the reserved field.
void SetReserved(uint16_t reserved)
Set the reserved field.
virtual void Print(std::ostream &os) const
Print information.
static TypeId GetTypeId()
Get the UID of this class.
void SetReserved(uint32_t reserved)
Set the reserved field.
void Set(char const *address)
Sets an Ipv6Address by parsing the input C-string.
void SetReserved(uint32_t reserved)
Set the reserved field.
uint8_t GetCode() const
Get the code field.
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
virtual void Print(std::ostream &os) const
Print information.
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
Ptr< Packet > GetPacket() const
Get the incorrect packet.
virtual void Print(std::ostream &os) const
Print information.
double f(double x, void *params)
Definition: 80211b.c:70
uint8_t m_prefixLength
The length of the prefix.
virtual uint32_t GetSerializedSize() const
Get the serialized size.
virtual ~Icmpv6OptionMtu()
Destructor.
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
virtual ~Icmpv6RS()
Destructor.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint32_t CopyFrom(const uint8_t *buffer, uint8_t len)
Definition: address.cc:101
virtual uint32_t GetSerializedSize() const
Get the serialized size.
void SetChecksum(uint16_t checksum)
Set the checksum.
uint32_t GetReserved() const
Get the reserved field.
bool GetFlagM() const
Get the M flag.
uint8_t GetCurHopLimit() const
Get the IPv6 maximum number of jumps.
void SetCode(uint8_t code)
Set the code field.
uint32_t GetReserved() const
Get the reserved field.
ICMPv6 MTU option.
virtual ~Icmpv6OptionRedirected()
Destructor.
virtual ~Icmpv6Redirection()
Destructor.
uint32_t m_ReachableTime
The reachable time value.
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
void Read(uint8_t *buffer, uint32_t size)
Definition: buffer.cc:1123
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
Ipv6Address GetIpv6Target() const
Get the IPv6 target field.
void SetFlagO(bool o)
Set the O flag.
void SetFlagH(bool h)
Set the H flag.
Icmpv6RA()
Constructor.
virtual void Print(std::ostream &os) const
Print information.
virtual ~Icmpv6RA()
Destructor.
void WriteHtonU32(uint32_t data)
Definition: buffer.h:924
void SetReserved(uint32_t reserved)
Set the reserved field.
void SetFlagR(bool r)
Set the R flag.
ICMPv6 Echo message.
bool m_flagO
The M flag.
void SetFlagS(bool s)
Set the S flag.
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
void SetFlagM(bool m)
Set the M flag.
void SetFlags(uint8_t flags)
Set the flags.
void SetReachableTime(uint32_t r)
Set the node Reachable time (Neighbor Discovery).
virtual uint32_t GetSerializedSize() const
Get the serialized size.
uint32_t m_ptr
The pointer field.
Describes an IPv6 address.
Definition: ipv6-address.h:49
virtual ~Icmpv6Header()
Destructor.
void WriteU8(uint8_t data)
Definition: buffer.h:869
Icmpv6TooBig()
Constructor.
virtual void Print(std::ostream &os) const
Print information.
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
Copy the packet contents to a byte buffer.
Definition: packet.cc:378
uint16_t GetReserved() const
Get the reserved field.
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
virtual ~Icmpv6Echo()
Destructor.
void SetDestination(Ipv6Address destination)
Set the IPv6 destination address.
virtual uint32_t GetSerializedSize() const
Get the serialized size.
virtual ~Icmpv6TooBig()
Destructor.
virtual uint32_t GetSerializedSize() const
Get the serialized size.
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
virtual uint32_t GetSerializedSize() const
Get the serialized size.
uint16_t GetChecksum() const
Get the checksum.
virtual void Print(std::ostream &os) const
Print information.
Ipv6Address GetDestination() const
Get the IPv6 destination address.
uint16_t m_LifeTime
The lifetime value.
uint8_t ReadU8(void)
Definition: buffer.h:1021
virtual ~Icmpv6NS()
Destructor.
Ipv6Address GetPrefix() const
Get the IPv6 prefix.
void Write(uint8_t const *buffer, uint32_t size)
Definition: buffer.cc:953
bool GetFlagR() const
Get the R flag.
Ptr< Packet > m_packet
The incorrect packet.
Icmpv6OptionRedirected()
Constructor.
virtual void Print(std::ostream &os) const
Print information.
uint32_t GetPtr() const
Get the pointer field.
Icmpv6Header()
Constructor.
virtual ~Icmpv6DestinationUnreachable()
Destructor.
virtual uint32_t GetSerializedSize() const
Get the serialized size.
Ptr< Packet > GetPacket() const
Get the incorrect packet.
static TypeId GetTypeId()
Get the UID of this class.
uint8_t GetType() const
Get the type field.
virtual uint32_t GetSerializedSize() const
Get the serialized size.
uint32_t GetReachableTime() const
Get the node Reachable time (Neighbor Discovery).
uint32_t GetReserved() const
Get the reserved field.
NS_DEPRECATED_3_34 void SetFlags(uint8_t f)
Setflags.
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
void SetSeq(uint16_t seq)
Set the sequence number.
bool GetFlagO() const
Get the O flag.
uint32_t m_mtu
The MTU value.
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
uint16_t ReadNtohU16(void)
Definition: buffer.h:946
void WriteU32(uint32_t data)
Definition: buffer.cc:878
Icmpv6Redirection()
Constructor.
void SetPacket(Ptr< Packet > p)
Set the incorrect packet.
uint16_t m_seq
Sequence number (to distinguish response).
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
ICMPv6 Error Too Big header.
a unique identifier for an interface.
Definition: type-id.h:58
void SetFlagO(bool o)
Set the O flag.
static TypeId GetTypeId()
Get the UID of this class.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
static TypeId GetTypeId()
Get the UID of this class.
void SetPrefix(Ipv6Address prefix)
Set the IPv6 prefix.
Buffer::Iterator Begin(void) const
Definition: buffer.h:1069
bool GetFlagH() const
Get the H flag.
static TypeId GetTypeId()
Get the UID of this class.
uint8_t GetFlags() const
Get the flags.
Ipv6Address m_prefix
The prefix value.
ICMPv6 option header.
virtual uint32_t GetSerializedSize() const
Get the serialized size.
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
void SetId(uint16_t id)
Set the ID of the packet.
bool m_flagM
The M flag.
void Serialize(uint8_t buf[16]) const
Serialize this address to a 16-byte buffer.
uint32_t GetRetransmissionTime() const
Get the node Retransmission time (Neighbor Discovery).
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
uint32_t CopyTo(uint8_t buffer[MAX_SIZE]) const
Copy the address bytes into a buffer.
Definition: address.cc:82
virtual uint32_t GetSerializedSize() const
Get the serialized size.
void SetMtu(uint32_t mtu)
Set the MTU.
uint16_t GetId() const
Get the ID of the packet.
virtual void Print(std::ostream &os) const
Print information.
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.