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  " Id = " << (uint32_t)GetId () <<
995  " SeqNo = " << (uint32_t)GetSeq () <<
996  " checksum = " << (uint32_t)GetChecksum () << ")";
997 }
998 
1000 {
1001  NS_LOG_FUNCTION (this);
1002  return 8;
1003 }
1004 
1006 {
1007  NS_LOG_FUNCTION (this << &start);
1008  uint16_t checksum = 0;
1009  Buffer::Iterator i = start;
1010 
1011  i.WriteU8 (GetType ());
1012  i.WriteU8 (GetCode ());
1013  i.WriteHtonU16 (0);
1014 
1015  i.WriteHtonU16 (m_id);
1016  i.WriteHtonU16 (m_seq);
1017 
1018  if (m_calcChecksum)
1019  {
1020  i = start;
1021  checksum = i.CalculateIpChecksum (i.GetSize (), GetChecksum ());
1022  i = start;
1023  i.Next (2);
1024  i.WriteU16 (checksum);
1025  }
1026 }
1027 
1029 {
1030  NS_LOG_FUNCTION (this << &start);
1031  Buffer::Iterator i = start;
1032 
1033  SetType (i.ReadU8 ());
1034  SetCode (i.ReadU8 ());
1035  m_checksum = i.ReadU16 ();
1036 
1037  m_id = i.ReadNtohU16 ();
1038  m_seq = i.ReadNtohU16 ();
1039  return GetSerializedSize ();
1040 }
1041 
1043 
1045 {
1046  static TypeId tid = TypeId ("ns3::Icmpv6DestinationUnreachable")
1047  .SetParent<Icmpv6Header> ()
1048  .SetGroupName ("Internet")
1049  .AddConstructor<Icmpv6DestinationUnreachable> ()
1050  ;
1051  return tid;
1052 }
1053 
1055 {
1056  NS_LOG_FUNCTION (this);
1057  return GetTypeId ();
1058 }
1059 
1061  : m_packet (0)
1062 {
1063  NS_LOG_FUNCTION (this);
1065 }
1066 
1068 {
1069  NS_LOG_FUNCTION (this);
1070 }
1071 
1073 {
1074  NS_LOG_FUNCTION (this);
1075  return m_packet;
1076 }
1077 
1079 {
1080  NS_LOG_FUNCTION (this << *p);
1081  NS_ASSERT (p->GetSize () <= 1280);
1082  m_packet = p;
1083 }
1084 
1085 void Icmpv6DestinationUnreachable::Print (std::ostream& os) const
1086 {
1087  NS_LOG_FUNCTION (this << &os);
1088  os << "( type = " << (uint32_t)GetType () << " (Destination Unreachable) code = " << (uint32_t)GetCode () << " checksum = " << (uint32_t)GetChecksum () << ")";
1089 }
1090 
1092 {
1093  NS_LOG_FUNCTION (this);
1094  return 8 + m_packet->GetSize ();
1095 }
1096 
1098 {
1099  NS_LOG_FUNCTION (this << &start);
1100  uint16_t checksum = 0;
1101  Buffer::Iterator i = start;
1102 
1103  i.WriteU8 (GetType ());
1104  i.WriteU8 (GetCode ());
1105  i.WriteHtonU16 (0);
1106  i.WriteHtonU32 (0);
1107 
1108  uint32_t size = m_packet->GetSize ();
1109  uint8_t *buf = new uint8_t[size];
1110  m_packet->CopyData (buf, size);
1111  i.Write (buf, size);
1112  delete[] buf;
1113 
1114  i = start;
1115  checksum = i.CalculateIpChecksum (i.GetSize (), GetChecksum ());
1116 
1117  i = start;
1118  i.Next (2);
1119  i.WriteU16 (checksum);
1120 }
1121 
1123 {
1124  NS_LOG_FUNCTION (this << &start);
1125  uint16_t length = start.GetRemainingSize () - 8;
1126  uint8_t* data = new uint8_t[length];
1127  Buffer::Iterator i = start;
1128 
1129  SetType (i.ReadU8 ());
1130  SetCode (i.ReadU8 ());
1131  m_checksum = i.ReadU16 ();
1132  i.ReadNtohU32 ();
1133  i.Read (data, length);
1134  m_packet = Create<Packet> (data, length);
1135 
1136  delete[] data;
1137  return GetSerializedSize ();
1138 }
1139 
1141 
1143 {
1144  static TypeId tid = TypeId ("ns3::Icmpv6TooBig")
1145  .SetParent<Icmpv6Header> ()
1146  .SetGroupName ("Internet")
1147  .AddConstructor<Icmpv6TooBig> ()
1148  ;
1149  return tid;
1150 }
1151 
1153 {
1154  NS_LOG_FUNCTION (this);
1155  return GetTypeId ();
1156 }
1157 
1159  : m_packet (0),
1160  m_mtu (0)
1161 {
1162  NS_LOG_FUNCTION (this);
1164 }
1165 
1167 {
1168  NS_LOG_FUNCTION (this);
1169 }
1170 
1172 {
1173  NS_LOG_FUNCTION (this);
1174  return m_packet;
1175 }
1176 
1178 {
1179  NS_LOG_FUNCTION (this << *p);
1180  NS_ASSERT (p->GetSize () <= 1280);
1181  m_packet = p;
1182 }
1183 
1184 uint32_t Icmpv6TooBig::GetMtu () const
1185 {
1186  NS_LOG_FUNCTION (this);
1187  return m_mtu;
1188 }
1189 
1190 void Icmpv6TooBig::SetMtu (uint32_t mtu)
1191 {
1192  NS_LOG_FUNCTION (this << mtu);
1193  m_mtu = mtu;
1194 }
1195 
1196 void Icmpv6TooBig::Print (std::ostream& os) const
1197 {
1198  NS_LOG_FUNCTION (this << &os);
1199  os << "( type = " << (uint32_t)GetType () << " (Too Big) code = " << (uint32_t)GetCode () << " checksum = " << (uint32_t)GetChecksum () << " mtu = " << (uint32_t)GetMtu () << ")";
1200 }
1201 
1203 {
1204  NS_LOG_FUNCTION (this);
1205  return 8 + m_packet->GetSize ();
1206 }
1207 
1209 {
1210  NS_LOG_FUNCTION (this << &start);
1211  uint16_t checksum = 0;
1212  Buffer::Iterator i = start;
1213 
1214  i.WriteU8 (GetType ());
1215  i.WriteU8 (GetCode ());
1216  i.WriteHtonU16 (0);
1217  i.WriteHtonU32 (GetMtu ());
1218 
1219  uint32_t size = m_packet->GetSize ();
1220  uint8_t *buf = new uint8_t[size];
1221  m_packet->CopyData (buf, size);
1222  i.Write (buf, size);
1223  delete[] buf;
1224 
1225  i = start;
1226  checksum = i.CalculateIpChecksum (i.GetSize (), GetChecksum ());
1227 
1228  i = start;
1229  i.Next (2);
1230  i.WriteU16 (checksum);
1231 }
1232 
1234 {
1235  NS_LOG_FUNCTION (this << &start);
1236  uint16_t length = start.GetRemainingSize () - 8;
1237  uint8_t* data = new uint8_t[length];
1238  Buffer::Iterator i = start;
1239 
1240  SetType (i.ReadU8 ());
1241  SetCode (i.ReadU8 ());
1242  m_checksum = i.ReadU16 ();
1243  SetMtu (i.ReadNtohU32 ());
1244  i.Read (data, length);
1245  m_packet = Create<Packet> (data, length);
1246 
1247  delete[] data;
1248  return GetSerializedSize ();
1249 }
1250 
1252 
1254 {
1255  static TypeId tid = TypeId ("ns3::Icmpv6TimeExceeded")
1256  .SetParent<Icmpv6Header> ()
1257  .SetGroupName ("Internet")
1258  .AddConstructor<Icmpv6TimeExceeded> ()
1259  ;
1260  return tid;
1261 }
1262 
1264 {
1265  NS_LOG_FUNCTION (this);
1266  return GetTypeId ();
1267 }
1268 
1270  : m_packet (0)
1271 {
1272  NS_LOG_FUNCTION (this);
1274 }
1275 
1277 {
1278  NS_LOG_FUNCTION (this);
1279 }
1280 
1282 {
1283  NS_LOG_FUNCTION (this);
1284  return m_packet;
1285 }
1286 
1288 {
1289  NS_LOG_FUNCTION (this << *p);
1290  NS_ASSERT (p->GetSize () <= 1280);
1291  m_packet = p;
1292 }
1293 
1294 void Icmpv6TimeExceeded::Print (std::ostream& os) const
1295 {
1296  NS_LOG_FUNCTION (this << &os);
1297  os << "( type = " << (uint32_t)GetType () << " (Destination Unreachable) code = " << (uint32_t)GetCode () << " checksum = " << (uint32_t)GetChecksum () << ")";
1298 }
1299 
1301 {
1302  NS_LOG_FUNCTION (this);
1303  return 8 + m_packet->GetSize ();
1304 }
1305 
1307 {
1308  NS_LOG_FUNCTION (this << &start);
1309 
1310  uint16_t checksum = 0;
1311  Buffer::Iterator i = start;
1312 
1313  i.WriteU8 (GetType ());
1314  i.WriteU8 (GetCode ());
1315  i.WriteHtonU16 (0);
1316  i.WriteHtonU32 (0);
1317 
1318  uint32_t size = m_packet->GetSize ();
1319  uint8_t *buf = new uint8_t[size];
1320  m_packet->CopyData (buf, size);
1321  i.Write (buf, size);
1322  delete[] buf;
1323 
1324  i = start;
1325  checksum = i.CalculateIpChecksum (i.GetSize (), GetChecksum ());
1326 
1327  i = start;
1328  i.Next (2);
1329  i.WriteU16 (checksum);
1330 }
1331 
1333 {
1334  NS_LOG_FUNCTION (this << &start);
1335 
1336  uint16_t length = start.GetRemainingSize () - 8;
1337  uint8_t* data = new uint8_t[length];
1338  Buffer::Iterator i = start;
1339 
1340  SetType (i.ReadU8 ());
1341  SetCode (i.ReadU8 ());
1342  m_checksum = i.ReadU16 ();
1343  i.ReadNtohU32 ();
1344  i.Read (data, length);
1345  m_packet = Create<Packet> (data, length);
1346 
1347  delete[] data;
1348  return GetSerializedSize ();
1349 }
1350 
1352 
1354 {
1355  static TypeId tid = TypeId ("ns3::Icmpv6ParameterError")
1356  .SetParent<Icmpv6Header> ()
1357  .SetGroupName ("Internet")
1358  .AddConstructor<Icmpv6ParameterError> ()
1359  ;
1360  return tid;
1361 }
1362 
1364 {
1365  NS_LOG_FUNCTION (this);
1366  return GetTypeId ();
1367 }
1368 
1370  : m_packet (0),
1371  m_ptr (0)
1372 {
1373  NS_LOG_FUNCTION (this);
1375 }
1376 
1378 {
1379  NS_LOG_FUNCTION (this);
1380 }
1381 
1383 {
1384  NS_LOG_FUNCTION (this);
1385  return m_packet;
1386 }
1387 
1389 {
1390  NS_LOG_FUNCTION (this << *p);
1391  NS_ASSERT (p->GetSize () <= 1280);
1392  m_packet = p;
1393 }
1394 
1396 {
1397  NS_LOG_FUNCTION (this);
1398  return m_ptr;
1399 }
1400 
1401 void Icmpv6ParameterError::SetPtr (uint32_t ptr)
1402 {
1403  NS_LOG_FUNCTION (this << ptr);
1404  m_ptr = ptr;
1405 }
1406 
1407 void Icmpv6ParameterError::Print (std::ostream& os) const
1408 {
1409  NS_LOG_FUNCTION (this << &os);
1410  os << "( type = " << (uint32_t)GetType () << " (Destination Unreachable) code = " << (uint32_t)GetCode () << " checksum = " << (uint32_t)GetChecksum () << " ptr = " << (uint32_t)GetPtr () << ")";
1411 }
1412 
1414 {
1415  NS_LOG_FUNCTION (this);
1416  return 8 + m_packet->GetSize ();
1417 }
1418 
1420 {
1421  NS_LOG_FUNCTION (this << &start);
1422  uint16_t checksum = 0;
1423  Buffer::Iterator i = start;
1424 
1425  i.WriteU8 (GetType ());
1426  i.WriteU8 (GetCode ());
1427  i.WriteHtonU16 (0);
1428  i.WriteHtonU32 (GetPtr ());
1429 
1430  uint32_t size = m_packet->GetSize ();
1431  uint8_t *buf = new uint8_t[size];
1432  m_packet->CopyData (buf, size);
1433  i.Write (buf, size);
1434  delete[] buf;
1435 
1436  i = start;
1437  checksum = i.CalculateIpChecksum (i.GetSize (), GetChecksum ());
1438 
1439  i = start;
1440  i.Next (2);
1441  i.WriteU16 (checksum);
1442 }
1443 
1445 {
1446  NS_LOG_FUNCTION (this << &start);
1447  uint16_t length = start.GetRemainingSize () - 8;
1448  uint8_t* data = new uint8_t[length];
1449  Buffer::Iterator i = start;
1450 
1451  SetType (i.ReadU8 ());
1452  SetCode (i.ReadU8 ());
1453  m_checksum = i.ReadU16 ();
1454  SetPtr (i.ReadNtohU32 ());
1455  i.Read (data, length);
1456  m_packet = Create<Packet> (data, length);
1457  delete[] data;
1458 
1459  return GetSerializedSize ();
1460 }
1461 
1463 
1465 {
1466  static TypeId tid = TypeId ("ns3::Icmpv6OptionHeader")
1467  .SetParent<Header> ()
1468  .SetGroupName ("Internet")
1469  .AddConstructor<Icmpv6OptionHeader> ()
1470  ;
1471  return tid;
1472 }
1473 
1475 {
1476  NS_LOG_FUNCTION (this);
1477  return GetTypeId ();
1478 }
1479 
1480 
1482 {
1483  NS_LOG_FUNCTION (this);
1485  m_type = 0;
1486  m_len = 0;
1487 }
1488 
1490 {
1491  NS_LOG_FUNCTION (this);
1492 }
1493 
1495 {
1496  NS_LOG_FUNCTION (this);
1497  return m_type;
1498 }
1499 
1500 void Icmpv6OptionHeader::SetType (uint8_t type)
1501 {
1502  NS_LOG_FUNCTION (this << static_cast<uint32_t> (type));
1503  m_type = type;
1504 }
1505 
1507 {
1508  NS_LOG_FUNCTION (this);
1509  return m_len;
1510 }
1511 
1513 {
1514  NS_LOG_FUNCTION (this << static_cast<uint32_t> (len));
1515  m_len = len;
1516 }
1517 
1518 void Icmpv6OptionHeader::Print (std::ostream& os) const
1519 {
1520  NS_LOG_FUNCTION (this << &os);
1521  os << "( type = " << (uint32_t)GetType () << " length = " << (uint32_t)GetLength () << ")";
1522 }
1523 
1525 {
1526  NS_LOG_FUNCTION (this);
1527  return m_len*8;
1528 }
1529 
1531 {
1532  NS_LOG_FUNCTION (this << &start);
1533  return GetSerializedSize ();
1534 }
1535 
1537 {
1538  NS_LOG_FUNCTION (this << &start);
1539 }
1540 
1542 
1544 {
1545  static TypeId tid = TypeId ("ns3::Icmpv6OptionMtu")
1547  .SetGroupName ("Internet")
1548  .AddConstructor<Icmpv6OptionMtu> ()
1549  ;
1550  return tid;
1551 }
1552 
1554 {
1555  NS_LOG_FUNCTION (this);
1556  return GetTypeId ();
1557 }
1558 
1560 {
1561  NS_LOG_FUNCTION (this);
1563  SetLength (1);
1564  SetReserved (0);
1565 }
1566 
1568  : m_mtu (mtu)
1569 {
1570  NS_LOG_FUNCTION (this << mtu);
1572  SetLength (1);
1573  SetReserved (0);
1574 }
1575 
1577 {
1578  NS_LOG_FUNCTION (this);
1579 }
1580 
1582 {
1583  NS_LOG_FUNCTION (this);
1584  return m_reserved;
1585 }
1586 
1587 void Icmpv6OptionMtu::SetReserved (uint16_t reserved)
1588 {
1589  NS_LOG_FUNCTION (this << reserved);
1590  m_reserved = reserved;
1591 }
1592 
1593 uint32_t Icmpv6OptionMtu::GetMtu () const
1594 {
1595  NS_LOG_FUNCTION (this);
1596  return m_mtu;
1597 }
1598 
1599 void Icmpv6OptionMtu::SetMtu (uint32_t mtu)
1600 {
1601  NS_LOG_FUNCTION (this << mtu);
1602  m_mtu = mtu;
1603 }
1604 
1605 void Icmpv6OptionMtu::Print (std::ostream& os) const
1606 {
1607  NS_LOG_FUNCTION (this << &os);
1608  os << "( type = " << (uint32_t)GetType () << " length = " << (uint32_t)GetLength () << " MTU = " << m_mtu << ")";
1609 }
1610 
1612 {
1613  NS_LOG_FUNCTION (this);
1614  return 8; /* m_len = 1 so the real size is multiple by 8 */
1615 }
1616 
1618 {
1619  NS_LOG_FUNCTION (this << &start);
1620  Buffer::Iterator i = start;
1621  i.WriteU8 (GetType ());
1622  i.WriteU8 (GetLength ());
1623  i.WriteHtonU16 (GetReserved ());
1624  i.WriteHtonU32 (GetMtu ());
1625 }
1626 
1628 {
1629  NS_LOG_FUNCTION (this << &start);
1630  Buffer::Iterator i = start;
1631  SetType (i.ReadU8 ());
1632  SetLength (i.ReadU8 ());
1633  SetReserved (i.ReadNtohU16 ());
1634  SetMtu (i.ReadNtohU32 ());
1635  return GetSerializedSize ();
1636 }
1637 
1639 
1641 {
1642  static TypeId tid = TypeId ("ns3::Icmpv6OptionPrefixInformation")
1644  .SetGroupName ("Internet")
1645  .AddConstructor<Icmpv6OptionPrefixInformation> ()
1646  ;
1647  return tid;
1648 }
1649 
1651 {
1652  NS_LOG_FUNCTION (this);
1653  return GetTypeId ();
1654 }
1655 
1657 {
1658  NS_LOG_FUNCTION (this);
1660  SetLength (4);
1661  SetPrefix (Ipv6Address ("::"));
1662  SetPrefixLength (0);
1663  SetValidTime (0);
1664  SetPreferredTime (0);
1665  SetFlags (0);
1666  SetReserved (0);
1667 }
1668 
1670 {
1671  NS_LOG_FUNCTION (this << prefix << static_cast<uint32_t> (prefixlen));
1673  SetLength (4);
1674  SetPrefix (prefix);
1675  SetPrefixLength (prefixlen);
1676  SetValidTime (0);
1677  SetPreferredTime (0);
1678  SetFlags (0);
1679  SetReserved (0);
1680 }
1681 
1683 {
1684  NS_LOG_FUNCTION (this);
1685 }
1686 
1688 {
1689  NS_LOG_FUNCTION (this);
1690  return m_prefixLength;
1691 }
1692 
1694 {
1695  NS_LOG_FUNCTION (this << static_cast<uint32_t> (prefixLength));
1696  NS_ASSERT (prefixLength <= 128);
1697  m_prefixLength = prefixLength;
1698 }
1699 
1701 {
1702  NS_LOG_FUNCTION (this);
1703  return m_flags;
1704 }
1705 
1707 {
1708  NS_LOG_FUNCTION (this);
1709  m_flags = flags;
1710 }
1711 
1713 {
1714  NS_LOG_FUNCTION (this);
1715  return m_validTime;
1716 }
1717 
1719 {
1720  NS_LOG_FUNCTION (this << validTime);
1721  m_validTime = validTime;
1722 }
1723 
1725 {
1726  NS_LOG_FUNCTION (this);
1727  return m_preferredTime;
1728 }
1729 
1731 {
1732  NS_LOG_FUNCTION (this << preferredTime);
1733  m_preferredTime = preferredTime;
1734 }
1735 
1737 {
1738  NS_LOG_FUNCTION (this);
1739  return m_preferredTime;
1740 }
1741 
1743 {
1744  NS_LOG_FUNCTION (this << reserved);
1745  m_reserved = reserved;
1746 }
1747 
1749 {
1750  NS_LOG_FUNCTION (this);
1751  return m_prefix;
1752 }
1753 
1755 {
1756  NS_LOG_FUNCTION (this << prefix);
1757  m_prefix = prefix;
1758 }
1759 
1760 void Icmpv6OptionPrefixInformation::Print (std::ostream& os) const
1761 {
1762  NS_LOG_FUNCTION (this << &os);
1763  os << "( type = " << (uint32_t)GetType () << " length = " << (uint32_t)GetLength () << " prefix " << m_prefix << ")";
1764 }
1765 
1767 {
1768  NS_LOG_FUNCTION (this);
1769  return 32;
1770 }
1771 
1773 {
1774  NS_LOG_FUNCTION (this << &start);
1775  Buffer::Iterator i = start;
1776  uint8_t buf[16];
1777 
1778  memset (buf, 0x00, sizeof (buf));
1779 
1780  i.WriteU8 (GetType ());
1781  i.WriteU8 (GetLength ());
1782  i.WriteU8 (m_prefixLength);
1783  i.WriteU8 (m_flags);
1787  m_prefix.GetBytes (buf);
1788  i.Write (buf, 16);
1789 }
1790 
1792 {
1793  NS_LOG_FUNCTION (this << &start);
1794  Buffer::Iterator i = start;
1795  uint8_t buf[16];
1796 
1797  SetType (i.ReadU8 ());
1798  SetLength (i.ReadU8 ());
1799  SetPrefixLength (i.ReadU8 ());
1800  SetFlags (i.ReadU8 ());
1801  SetValidTime (i.ReadNtohU32 ());
1803  SetReserved (i.ReadNtohU32 ());
1804  i.Read (buf, 16);
1805 
1806  Ipv6Address prefix (buf);
1807  SetPrefix (prefix);
1808 
1809  return GetSerializedSize ();
1810 }
1811 
1813 
1815 {
1816  static TypeId tid = TypeId ("ns3::Icmpv6OptionLinkLayerAddress")
1818  .SetGroupName ("Internet")
1819  .AddConstructor<Icmpv6OptionLinkLayerAddress> ()
1820  ;
1821  return tid;
1822 }
1823 
1825 {
1826  NS_LOG_FUNCTION (this);
1827  return GetTypeId ();
1828 }
1829 
1831 {
1832  NS_LOG_FUNCTION (this << source);
1834 }
1835 
1837 {
1838  NS_LOG_FUNCTION (this);
1840 }
1841 
1843 {
1844  NS_LOG_FUNCTION (this << source << addr);
1846  SetAddress (addr);
1847 
1848  uint8_t len = (2 + m_addr.GetLength ()) / 8;
1849  if ( (2 + m_addr.GetLength ()) % 8 )
1850  {
1851  len ++;
1852  }
1853  SetLength (len);
1854 }
1855 
1857 {
1858  NS_LOG_FUNCTION (this);
1859 }
1860 
1862 {
1863  NS_LOG_FUNCTION (this);
1864  return m_addr;
1865 }
1866 
1868 {
1869  NS_LOG_FUNCTION (this << addr);
1870  m_addr = addr;
1871 }
1872 
1873 void Icmpv6OptionLinkLayerAddress::Print (std::ostream& os) const
1874 {
1875  NS_LOG_FUNCTION (this << &os);
1876  os << "( type = " << (uint32_t)GetType () << " length = " << (uint32_t)GetLength () << " L2 Address = " << m_addr << ")";
1877 }
1878 
1880 {
1881  NS_LOG_FUNCTION (this);
1882  uint8_t nb = GetLength() * 8;
1883  return nb;
1884 }
1885 
1887 {
1888  NS_LOG_FUNCTION (this << &start);
1889  Buffer::Iterator i = start;
1890  uint8_t mac[32];
1891 
1892  i.WriteU8 (GetType ());
1893  i.WriteU8 (GetLength ());
1894  m_addr.CopyTo (mac);
1895  i.Write (mac, m_addr.GetLength ());
1896 
1897  uint8_t len = GetLength ()*8 - (2 + m_addr.GetLength ());
1898  for (uint8_t nb = 0; nb<len; nb++)
1899  {
1900  i.WriteU8 (0);
1901  }
1902 }
1903 
1905 {
1906  NS_LOG_FUNCTION (this << &start);
1907  Buffer::Iterator i = start;
1908  uint8_t mac[32];
1909 
1910  SetType (i.ReadU8 ());
1911  SetLength (i.ReadU8 ());
1912  // -fstrict-overflow sensitive, see bug 1868
1913  NS_ASSERT (GetLength () * 8 <= 32 + 2);
1914  i.Read (mac, (GetLength () * 8) - 2);
1915 
1916  m_addr.CopyFrom (mac, (GetLength () * 8) - 2);
1917 
1918  return GetSerializedSize ();
1919 }
1920 
1922 
1924 {
1925  static TypeId tid = TypeId ("ns3::Icmpv6OptionRedirected")
1927  .SetGroupName ("Internet")
1928  .AddConstructor<Icmpv6OptionRedirected> ()
1929  ;
1930  return tid;
1931 }
1932 
1934 {
1935  NS_LOG_FUNCTION (this);
1936  return GetTypeId ();
1937 }
1938 
1940  : m_packet (0)
1941 {
1942  NS_LOG_FUNCTION (this);
1944 }
1945 
1947 {
1948  NS_LOG_FUNCTION (this);
1949  m_packet = 0;
1950 }
1951 
1953 {
1954  NS_LOG_FUNCTION (this);
1955  return m_packet;
1956 }
1957 
1959 {
1960  NS_LOG_FUNCTION (this << *packet);
1961  NS_ASSERT (packet->GetSize () <= 1280);
1962  m_packet = packet;
1963  SetLength (1 + (m_packet->GetSize () / 8));
1964 }
1965 
1966 void Icmpv6OptionRedirected::Print (std::ostream& os) const
1967 {
1968  NS_LOG_FUNCTION (this << &os);
1969  os << "( type = " << (uint32_t)GetType () << " length = " << (uint32_t)GetLength () << ")";
1970 }
1971 
1973 {
1974  NS_LOG_FUNCTION (this);
1975  return 8 + m_packet->GetSize ();
1976 }
1977 
1979 {
1980  NS_LOG_FUNCTION (this << &start);
1981  Buffer::Iterator i = start;
1982 
1983  i.WriteU8 (GetType ());
1984  i.WriteU8 (GetLength ());
1985  // Reserved
1986  i.WriteU16 (0);
1987  i.WriteU32 (0);
1988 
1989  uint32_t size = m_packet->GetSize ();
1990  uint8_t *buf = new uint8_t[size];
1991  m_packet->CopyData (buf, size);
1992  i.Write (buf, size);
1993  delete[] buf;
1994 }
1995 
1997 {
1998  NS_LOG_FUNCTION (this << &start);
1999  Buffer::Iterator i = start;
2000 
2001  SetType (i.ReadU8 ());
2002  uint8_t length = i.ReadU8 ();
2003  SetLength (length);
2004  i.ReadU16 ();
2005  i.ReadU32 ();
2006 
2007  uint32_t len2 = (GetLength () - 1) * 8;
2008  uint8_t* buff = new uint8_t[len2];
2009  i.Read (buff, len2);
2010  m_packet = Create<Packet> (buff, len2);
2011  delete[] buff;
2012 
2013  return GetSerializedSize ();
2014 }
2015 
2016 } /* namespace ns3 */
2017 
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.