A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 NS_LOG_COMPONENT_DEFINE ("Icmpv6Header");
30 
31 namespace ns3
32 {
33 
34 NS_OBJECT_ENSURE_REGISTERED (Icmpv6Header);
35 
37 {
38  static TypeId tid = TypeId ("ns3::Icmpv6Header")
39  .SetParent<Header> ()
40  .AddConstructor<Icmpv6Header> ()
41  ;
42  return tid;
43 }
44 
46 {
47  NS_LOG_FUNCTION (this);
48  return GetTypeId ();
49 }
50 
52  : m_calcChecksum (true),
53  m_checksum (0),
54  m_type (0),
55  m_code (0)
56 {
57  NS_LOG_FUNCTION (this);
58 }
59 
61 {
62  NS_LOG_FUNCTION (this);
63 }
64 
65 uint8_t Icmpv6Header::GetType () const
66 {
67  NS_LOG_FUNCTION (this);
68  return m_type;
69 }
70 
71 void Icmpv6Header::SetType (uint8_t type)
72 {
73  NS_LOG_FUNCTION (this << static_cast<uint32_t> (type));
74  m_type = type;
75 }
76 
77 uint8_t Icmpv6Header::GetCode () const
78 {
79  NS_LOG_FUNCTION (this);
80  return m_code;
81 }
82 
83 void Icmpv6Header::SetCode (uint8_t code)
84 {
85  NS_LOG_FUNCTION (this << static_cast<uint32_t> (code));
86  m_code = code;
87 }
88 
89 uint16_t Icmpv6Header::GetChecksum () const
90 {
91  NS_LOG_FUNCTION (this);
92  return m_checksum;
93 }
94 
95 void Icmpv6Header::SetChecksum (uint16_t checksum)
96 {
97  NS_LOG_FUNCTION (this << checksum);
98  m_checksum = checksum;
99 }
100 
101 void Icmpv6Header::Print (std::ostream& os) const
102 {
103  NS_LOG_FUNCTION (this << &os);
104  os << "( type = " << (uint32_t)m_type << " code = " << (uint32_t)m_code << " checksum = " << (uint32_t)m_checksum << ")";
105 }
106 
108 {
109  NS_LOG_FUNCTION (this);
110  return 4;
111 }
112 
114 {
115  NS_LOG_FUNCTION (this << &start);
117 
118  m_type = i.ReadU8 ();
119  m_code = i.ReadU8 ();
120  m_checksum = i.ReadNtohU16 ();
121 #if 0
122  i.ReadU32 (); /* padding */
123 #endif
124  return GetSerializedSize ();
125 }
126 
128 {
129  NS_LOG_FUNCTION (this << &start);
131 
132  i.WriteU8 (m_type);
133  i.WriteU8 (m_code);
134  i.WriteU16 (0);
135 #if 0
136  i.WriteU32 (0); /* padding */
137 #endif
138 
139  if (m_calcChecksum)
140  {
141  i = start;
142  uint16_t checksum = i.CalculateIpChecksum (i.GetSize (), m_checksum);
143  i = start;
144  i.Next (2);
145  i.WriteU16 (checksum);
146  }
147 }
148 
149 void Icmpv6Header::CalculatePseudoHeaderChecksum (Ipv6Address src, Ipv6Address dst, uint16_t length, uint8_t protocol)
150 {
151  NS_LOG_FUNCTION (this << src << dst << length << static_cast<uint32_t> (protocol));
152 
153  Buffer buf = Buffer (40);
154  uint8_t tmp[16];
155  Buffer::Iterator it;
156 
157  buf.AddAtStart (40);
158  it = buf.Begin ();
159 
160  src.Serialize (tmp);
161  it.Write (tmp, 16); /* source IPv6 address */
162  dst.Serialize (tmp);
163  it.Write (tmp, 16); /* destination IPv6 address */
164  it.WriteU16 (0); /* length */
165  it.WriteU8 (length >> 8); /* length */
166  it.WriteU8 (length & 0xff); /* length */
167  it.WriteU16 (0); /* zero */
168  it.WriteU8 (0); /* zero */
169  it.WriteU8 (protocol); /* next header */
170 
171  it = buf.Begin ();
172  m_checksum = ~(it.CalculateIpChecksum (40));
173 }
174 
176 
178 {
179  NS_LOG_FUNCTION (this);
181  SetCode (0);
182  SetReserved (0);
183  m_checksum = 0;
184 }
185 
187 {
188  static TypeId tid = TypeId ("ns3::Icmpv6NS")
190  .AddConstructor<Icmpv6NS> ()
191  ;
192  return tid;
193 }
194 
196 {
197  NS_LOG_FUNCTION (this);
198  return GetTypeId ();
199 }
200 
202 {
203  NS_LOG_FUNCTION (this << target);
205  SetCode (0);
206  SetReserved (0);
207  SetIpv6Target (target);
208  m_checksum = 0;
209 
210  /* test */
211  /*
212  m_reserved = 0xdeadbeef;
213  */
214 }
215 
217 {
218  NS_LOG_FUNCTION (this);
219 }
220 
221 uint32_t Icmpv6NS::GetReserved () const
222 {
223  NS_LOG_FUNCTION (this);
224  return m_reserved;
225 }
226 
227 void Icmpv6NS::SetReserved (uint32_t reserved)
228 {
229  NS_LOG_FUNCTION (this << reserved);
230  m_reserved = reserved;
231 }
232 
234 {
235  NS_LOG_FUNCTION (this);
236  return m_target;
237 }
238 
240 {
241  NS_LOG_FUNCTION (this << target);
242  m_target = target;
243 }
244 
245 void Icmpv6NS::Print (std::ostream& os) const
246 {
247  NS_LOG_FUNCTION (this << &os);
248  os << "( type = " << (uint32_t)GetType () << " (NS) code = " << (uint32_t)GetCode () << " checksum = " << (uint32_t)GetChecksum () << ")";
249 }
250 
252 {
253  NS_LOG_FUNCTION (this);
254  return 24;
255 }
256 
258 {
259  NS_LOG_FUNCTION (this << &start);
260  uint8_t buff_target[16];
261  uint16_t checksum = 0;
263 
264  i.WriteU8 (GetType ());
265  i.WriteU8 (GetCode ());
266  i.WriteU16 (0);
268  m_target.Serialize (buff_target);
269  i.Write (buff_target, 16);
270 
271  if (m_calcChecksum)
272  {
273  i = start;
274  checksum = i.CalculateIpChecksum (i.GetSize (), m_checksum);
275  i = start;
276  i.Next (2);
277  i.WriteU16 (checksum);
278  }
279 }
280 
282 {
283  NS_LOG_FUNCTION (this << &start);
284  uint8_t buf[16];
286 
287  SetType (i.ReadU8 ());
288  SetCode (i.ReadU8 ());
289  m_checksum = i.ReadU16 ();
290  m_reserved = i.ReadNtohU32 ();
291  i.Read (buf, 16);
292  m_target.Set (buf);
293 
294  return GetSerializedSize ();
295 }
296 
298 
300 {
301  static TypeId tid = TypeId ("ns3::Icmpv6NA")
303  .AddConstructor<Icmpv6NA> ()
304  ;
305  return tid;
306 }
307 
309 {
310  NS_LOG_FUNCTION (this);
311  return GetTypeId ();
312 }
313 
315 {
316  NS_LOG_FUNCTION (this);
318  SetCode (0);
319  SetReserved (0);
320  SetFlagR (0);
321  SetFlagS (0);
322  SetFlagO (0);
323  m_checksum = 0;
324 }
325 
327 {
328  NS_LOG_FUNCTION (this);
329 }
330 
331 uint32_t Icmpv6NA::GetReserved () const
332 {
333  NS_LOG_FUNCTION (this);
334  return m_reserved;
335 }
336 
337 void Icmpv6NA::SetReserved (uint32_t reserved)
338 {
339  NS_LOG_FUNCTION (this << reserved);
340  m_reserved = reserved;
341 }
342 
344 {
345  NS_LOG_FUNCTION (this);
346  return m_target;
347 }
348 
349 bool Icmpv6NA::GetFlagR () const
350 {
351  NS_LOG_FUNCTION (this);
352  return m_flagR;
353 }
354 
355 void Icmpv6NA::SetFlagR (bool r)
356 {
357  NS_LOG_FUNCTION (this << r);
358  m_flagR = r;
359 }
360 
361 bool Icmpv6NA::GetFlagS () const
362 {
363  NS_LOG_FUNCTION (this);
364  return m_flagS;
365 }
366 
368 {
369  NS_LOG_FUNCTION (this << s);
370  m_flagS = s;
371 }
372 
373 bool Icmpv6NA::GetFlagO () const
374 {
375  NS_LOG_FUNCTION (this);
376  return m_flagO;
377 }
378 
379 void Icmpv6NA::SetFlagO (bool o)
380 {
381  NS_LOG_FUNCTION (this << o);
382  m_flagO = o;
383 }
384 
386 {
387  NS_LOG_FUNCTION (this << target);
388  m_target = target;
389 }
390 
391 void Icmpv6NA::Print (std::ostream& os) const
392 {
393  NS_LOG_FUNCTION (this << &os);
394  os << "( type = " << (uint32_t)GetType () << " (NA) code = " << (uint32_t)GetCode () << " checksum = " << (uint32_t)GetChecksum () << ")";
395 }
396 
398 {
399  NS_LOG_FUNCTION (this);
400  return 24;
401 }
402 
404 {
405  NS_LOG_FUNCTION (this << &start);
406  uint8_t buff_target[16];
407  uint16_t checksum = 0;
409  uint32_t reserved = m_reserved;
410 
411  i.WriteU8 (GetType ());
412  i.WriteU8 (GetCode ());
413  i.WriteU16 (0);
414 
415  if (m_flagR)
416  {
417  reserved |= (uint32_t)(1 << 31);
418  }
419 
420  if (m_flagS)
421  {
422  reserved |= (uint32_t)(1<< 30);
423  }
424 
425  if (m_flagO)
426  {
427  reserved |= (uint32_t)(1<< 29);
428  }
429 
430  i.WriteHtonU32 (reserved);
431  m_target.Serialize (buff_target);
432  i.Write (buff_target, 16);
433 
434  if (m_calcChecksum)
435  {
436  i = start;
437  checksum = i.CalculateIpChecksum (i.GetSize (), GetChecksum ());
438  i = start;
439  i.Next (2);
440  i.WriteU16 (checksum);
441  }
442 }
443 
445 {
446  NS_LOG_FUNCTION (this << &start);
447  uint8_t buf[16];
449 
450  SetType (i.ReadU8 ());
451  SetCode (i.ReadU8 ());
452  m_checksum = i.ReadU16 ();
453  m_reserved = i.ReadNtohU32 ();
454 
455  m_flagR = false;
456  m_flagS = false;
457  m_flagO = false;
458 
459  if (m_reserved & (1 << 31))
460  {
461  m_flagR = true;
462  }
463 
464  if (m_reserved & (1 << 30))
465  {
466  m_flagS = true;
467  }
468 
469  if (m_reserved & (1 << 29))
470  {
471  m_flagO = true;
472  }
473 
474  i.Read (buf, 16);
475  m_target.Set (buf);
476 
477  return GetSerializedSize ();
478 }
479 
481 
483 {
484  static TypeId tid = TypeId ("ns3::Icmpv6RA")
486  .AddConstructor<Icmpv6RA> ()
487  ;
488  return tid;
489 }
490 
492 {
493  NS_LOG_FUNCTION (this);
494  return GetTypeId ();
495 }
496 
498 {
499  NS_LOG_FUNCTION (this);
501  SetCode (0);
502  SetFlags (0);
503  SetFlagM (0);
504  SetFlagO (0);
505  SetFlagH (0);
506  SetCurHopLimit (0);
507  SetLifeTime (0);
509  SetReachableTime (0);
510 }
511 
513 {
514  NS_LOG_FUNCTION (this);
515 }
516 
517 void Icmpv6RA::SetCurHopLimit (uint8_t m)
518 {
519  NS_LOG_FUNCTION (this << static_cast<uint32_t> (m));
520  m_curHopLimit = m;
521 }
522 
523 uint8_t Icmpv6RA::GetCurHopLimit () const
524 {
525  NS_LOG_FUNCTION (this);
526  return m_curHopLimit;
527 }
528 
529 uint16_t Icmpv6RA::GetLifeTime () const
530 {
531  NS_LOG_FUNCTION (this);
532  return m_LifeTime;
533 }
534 
535 uint32_t Icmpv6RA::GetReachableTime () const
536 {
537  NS_LOG_FUNCTION (this);
538  return m_ReachableTime;
539 }
540 
542 {
543  NS_LOG_FUNCTION (this);
544  return m_RetransmissionTimer;
545 }
546 
547 void Icmpv6RA::SetLifeTime (uint16_t l)
548 {
549  NS_LOG_FUNCTION (this << l);
550  m_LifeTime = l;
551 }
552 
553 void Icmpv6RA::SetReachableTime (uint32_t r)
554 {
555  NS_LOG_FUNCTION (this << r);
556  m_ReachableTime = r;
557 }
558 
560 {
561  NS_LOG_FUNCTION (this << r);
563 }
564 
565 bool Icmpv6RA::GetFlagM () const
566 {
567  NS_LOG_FUNCTION (this);
568  return m_flagM;
569 }
570 
571 void Icmpv6RA::SetFlagM (bool m)
572 {
573  NS_LOG_FUNCTION (this << m);
574  m_flagM = m;
575 }
576 
577 bool Icmpv6RA::GetFlagO () const
578 {
579  NS_LOG_FUNCTION (this);
580  return m_flagO;
581 }
582 
583 void Icmpv6RA::SetFlagO (bool o)
584 {
585  NS_LOG_FUNCTION (this << o);
586  m_flagO = o;
587 }
588 
589 bool Icmpv6RA::GetFlagH () const
590 {
591  NS_LOG_FUNCTION (this);
592  return m_flagH;
593 }
594 
595 void Icmpv6RA::SetFlagH (bool h)
596 {
597  NS_LOG_FUNCTION (this << h);
598  m_flagH = h;
599 }
600 
601 uint8_t Icmpv6RA::GetFlags () const
602 {
603  NS_LOG_FUNCTION (this);
604  return m_flags;
605 }
606 
607 void Icmpv6RA::SetFlags (uint8_t f)
608 {
609  NS_LOG_FUNCTION (this << static_cast<uint32_t> (f));
610  m_flags = f;
611 }
612 
613 void Icmpv6RA::Print (std::ostream& os) const
614 {
615  NS_LOG_FUNCTION (this << &os);
616  os << "( type = " << (uint32_t)GetType () << " (RA) code = " << (uint32_t)GetCode () << " checksum = " << (uint32_t)GetChecksum () << ")";
617 }
618 
620 {
621  NS_LOG_FUNCTION (this);
622  return 16;
623 }
624 
626 {
627  NS_LOG_FUNCTION (this << &start);
628  uint16_t checksum = 0;
630  uint8_t flags = 0;
631 
632  i.WriteU8 (GetType ());
633  i.WriteU8 (GetCode ());
634  i.WriteHtonU16 (0);
636 
637  if (m_flagM)
638  {
639  flags |= (uint8_t)(1<< 7);
640  }
641 
642  if (m_flagO)
643  {
644  flags |= (uint8_t)(1<< 6);
645  }
646 
647  if (m_flagH)
648  {
649  flags |= (uint8_t)(1<< 5);
650  }
651  i.WriteU8 (flags);
652  i.WriteHtonU16 (GetLifeTime ());
655 
656  i = start;
657  checksum = i.CalculateIpChecksum (i.GetSize (), GetChecksum ());
658 
659  i = start;
660  i.Next (2);
661  i.WriteU16 (checksum);
662 }
663 
665 {
666  NS_LOG_FUNCTION (this << &start);
668 
669  SetType (i.ReadU8 ());
670  SetCode (i.ReadU8 ());
671  m_checksum = i.ReadU16 ();
672  SetCurHopLimit (i.ReadU8 ());
673  m_flags = i.ReadU8 ();
674  m_flagM = false;
675  m_flagO = false;
676  m_flagH = false;
677 
678  if (m_flags & (1 << 7))
679  {
680  m_flagM = true;
681  }
682 
683  if (m_flags & (1 << 6))
684  {
685  m_flagO = true;
686  }
687 
688  if (m_flags & (1 << 5))
689  {
690  m_flagH = true;
691  }
692  SetLifeTime (i.ReadNtohU16 ());
695 
696  return GetSerializedSize ();
697 }
698 
700 
702 {
703  static TypeId tid = TypeId ("ns3::Icmpv6RS")
705  .AddConstructor<Icmpv6RS> ()
706  ;
707  return tid;
708 }
709 
711 {
712  NS_LOG_FUNCTION (this);
713  return GetTypeId ();
714 }
715 
717 {
718  NS_LOG_FUNCTION (this);
720  SetCode (0);
721  SetReserved (0);
722 }
723 
725 {
726  NS_LOG_FUNCTION (this);
727 }
728 
729 uint32_t Icmpv6RS::GetReserved () const
730 {
731  NS_LOG_FUNCTION (this);
732  return m_reserved;
733 }
734 
735 void Icmpv6RS::SetReserved (uint32_t reserved)
736 {
737  NS_LOG_FUNCTION (this << reserved);
738  m_reserved = reserved;
739 }
740 
741 void Icmpv6RS::Print (std::ostream& os) const
742 {
743  NS_LOG_FUNCTION (this << &os);
744  os << "( type = " << (uint32_t)GetType () << " (RS) code = " << (uint32_t)GetCode () << " checksum = " << (uint32_t)GetChecksum () << ")";
745 }
746 
748 {
749  NS_LOG_FUNCTION (this);
750  return 8;
751 }
752 
754 {
755  NS_LOG_FUNCTION (this << &start);
757  uint16_t checksum = 0;
759 
760  i.WriteU8 (GetType ());
761  i.WriteU8 (GetCode ());
762  i.WriteU16 (0);
764 
765  if (m_calcChecksum)
766  {
767  i = start;
768  checksum = i.CalculateIpChecksum (i.GetSize (), GetChecksum ());
769 
770  i = start;
771  i.Next (2);
772  i.WriteU16 (checksum);
773  }
774 }
775 
777 {
778  NS_LOG_FUNCTION (this << &start);
780 
781  SetType (i.ReadU8 ());
782  SetCode (i.ReadU8 ());
783  m_checksum = i.ReadU16 ();
784  m_reserved = i.ReadNtohU32 ();
785 
786  return GetSerializedSize ();
787 }
788 
790 
792 {
793  static TypeId tid = TypeId ("ns3::Icmpv6Redirection")
795  .AddConstructor<Icmpv6Redirection> ()
796  ;
797  return tid;
798 }
799 
801 {
802  NS_LOG_FUNCTION (this);
803  return GetTypeId ();
804 }
805 
807  : m_target (Ipv6Address ("")),
808  m_destination (Ipv6Address ("")),
809  m_reserved (0)
810 {
811  NS_LOG_FUNCTION (this);
813  SetCode (0);
814  m_checksum = 0;
815 }
816 
818 {
819  NS_LOG_FUNCTION (this);
820 }
821 
822 void Icmpv6Redirection::SetReserved (uint32_t reserved)
823 {
824  NS_LOG_FUNCTION (this << reserved);
825  m_reserved = reserved;
826 }
827 
829 {
830  NS_LOG_FUNCTION (this);
831  return m_reserved;
832 }
833 
835 {
836  NS_LOG_FUNCTION (this);
837  return m_target;
838 }
839 
841 {
842  NS_LOG_FUNCTION (this << target);
843  m_target = target;
844 }
845 
847 {
848  NS_LOG_FUNCTION (this);
849  return m_destination;
850 }
851 
853 {
854  NS_LOG_FUNCTION (this << destination);
855  m_destination = destination;
856 }
857 
858 void Icmpv6Redirection::Print (std::ostream& os) const
859 {
860  NS_LOG_FUNCTION (this << &os);
861  os << "( type = " << (uint32_t)GetType () << " (Redirection) code = " << (uint32_t)GetCode () << " checksum = " << (uint32_t)GetChecksum () << " target = " << m_target << " destination = " << m_destination << ")";
862 }
863 
865 {
866  NS_LOG_FUNCTION (this);
867  return 40;
868 }
869 
871 {
872  NS_LOG_FUNCTION (this << &start);
873  uint8_t buff[16];
874  uint16_t checksum = 0;
876 
877  i.WriteU8 (GetType ());
878  i.WriteU8 (GetCode ());
879  i.WriteU16 (checksum);
880  i.WriteU32 (m_reserved);
881 
882  m_target.Serialize (buff);
883  i.Write (buff, 16);
884 
885  m_destination.Serialize (buff);
886  i.Write (buff, 16);
887 
888  if (m_calcChecksum)
889  {
890  i = start;
891  checksum = i.CalculateIpChecksum (i.GetSize (), GetChecksum ());
892 
893  i = start;
894  i.Next (2);
895  i.WriteU16 (checksum);
896  }
897 }
898 
900 {
901  NS_LOG_FUNCTION (this << &start);
902  uint8_t buff[16];
904 
905  SetType (i.ReadU8 ());
906  SetCode (i.ReadU8 ());
907  m_checksum = i.ReadU16 ();
908  SetReserved (i.ReadU32 ());
909 
910  i.Read (buff, 16);
911  m_target.Set (buff);
912 
913  i.Read (buff, 16);
914  m_destination.Set (buff);
915 
916  return GetSerializedSize ();
917 }
918 
920 
922 {
923  static TypeId tid = TypeId ("ns3::Icmpv6Echo")
925  .AddConstructor<Icmpv6Echo> ()
926  ;
927  return tid;
928 }
929 
931 {
932  NS_LOG_FUNCTION (this);
933  return GetTypeId ();
934 }
935 
937 {
938  NS_LOG_FUNCTION (this);
940  SetCode (0);
941  m_checksum = 0;
942  SetId (0);
943  SetSeq (0);
944 }
945 
947 {
948  NS_LOG_FUNCTION (this << request);
950  SetCode (0);
951  m_checksum = 0;
952  SetId (0);
953  SetSeq (0);
954 }
955 
957 {
958  NS_LOG_FUNCTION (this);
959 }
960 
961 uint16_t Icmpv6Echo::GetId () const
962 {
963  NS_LOG_FUNCTION (this);
964  return m_id;
965 }
966 
967 void Icmpv6Echo::SetId (uint16_t id)
968 {
969  NS_LOG_FUNCTION (this << id);
970  m_id = id;
971 }
972 
973 uint16_t Icmpv6Echo::GetSeq () const
974 {
975  NS_LOG_FUNCTION (this);
976  return m_seq;
977 }
978 
979 void Icmpv6Echo::SetSeq (uint16_t seq)
980 {
981  NS_LOG_FUNCTION (this << seq);
982  m_seq = seq;
983 }
984 
985 void Icmpv6Echo::Print (std::ostream& os) const
986 {
987  NS_LOG_FUNCTION (this << &os);
988  os << "( type = " << (GetType () == 128 ? "128 (Request)" : "129 (Reply)") <<
989  " code = " << (uint32_t)GetCode () <<
990  " checksum = " << (uint32_t)GetChecksum () << ")";
991 }
992 
994 {
995  NS_LOG_FUNCTION (this);
996  return 8;
997 }
998 
1000 {
1001  NS_LOG_FUNCTION (this << &start);
1002  uint16_t checksum = 0;
1003  Buffer::Iterator i = start;
1004 
1005  i.WriteU8 (GetType ());
1006  i.WriteU8 (GetCode ());
1007  i.WriteHtonU16 (0);
1008 
1009  i.WriteHtonU16 (m_id);
1010  i.WriteHtonU16 (m_seq);
1011 
1012  if (m_calcChecksum)
1013  {
1014  i = start;
1015  checksum = i.CalculateIpChecksum (i.GetSize (), GetChecksum ());
1016  i = start;
1017  i.Next (2);
1018  i.WriteU16 (checksum);
1019  }
1020 }
1021 
1023 {
1024  NS_LOG_FUNCTION (this << &start);
1025  Buffer::Iterator i = start;
1026 
1027  SetType (i.ReadU8 ());
1028  SetCode (i.ReadU8 ());
1029  m_checksum = i.ReadU16 ();
1030 
1031  m_id = i.ReadNtohU16 ();
1032  m_seq = i.ReadNtohU16 ();
1033  return GetSerializedSize ();
1034 }
1035 
1037 
1039 {
1040  static TypeId tid = TypeId ("ns3::Icmpv6DestinationUnreachable")
1041  .SetParent<Icmpv6Header> ()
1042  .AddConstructor<Icmpv6DestinationUnreachable> ()
1043  ;
1044  return tid;
1045 }
1046 
1048 {
1049  NS_LOG_FUNCTION (this);
1050  return GetTypeId ();
1051 }
1052 
1054  : m_packet (0)
1055 {
1056  NS_LOG_FUNCTION (this);
1058 }
1059 
1061 {
1062  NS_LOG_FUNCTION (this);
1063 }
1064 
1066 {
1067  NS_LOG_FUNCTION (this);
1068  return m_packet;
1069 }
1070 
1072 {
1073  NS_LOG_FUNCTION (this << *p);
1074  NS_ASSERT (p->GetSize () <= 1280);
1075  m_packet = p;
1076 }
1077 
1078 void Icmpv6DestinationUnreachable::Print (std::ostream& os) const
1079 {
1080  NS_LOG_FUNCTION (this << &os);
1081  os << "( type = " << (uint32_t)GetType () << " (Destination Unreachable) code = " << (uint32_t)GetCode () << " checksum = " << (uint32_t)GetChecksum () << ")";
1082 }
1083 
1085 {
1086  NS_LOG_FUNCTION (this);
1087  return 8 + m_packet->GetSize ();
1088 }
1089 
1091 {
1092  NS_LOG_FUNCTION (this << &start);
1093  uint16_t checksum = 0;
1094  Buffer::Iterator i = start;
1095 
1096  i.WriteU8 (GetType ());
1097  i.WriteU8 (GetCode ());
1098  i.WriteHtonU16 (0);
1099  i.WriteHtonU32 (0);
1100 
1101  uint32_t size = m_packet->GetSize ();
1102  uint8_t *buf = new uint8_t[size];
1103  m_packet->CopyData (buf, size);
1104  i.Write (buf, size);
1105  delete[] buf;
1106 
1107  i = start;
1108  checksum = i.CalculateIpChecksum (i.GetSize (), GetChecksum ());
1109 
1110  i = start;
1111  i.Next (2);
1112  i.WriteU16 (checksum);
1113 }
1114 
1116 {
1117  NS_LOG_FUNCTION (this << &start);
1118  uint16_t length = start.GetSize () - 8;
1119  uint8_t* data = new uint8_t[length];
1120  Buffer::Iterator i = start;
1121 
1122  SetType (i.ReadU8 ());
1123  SetCode (i.ReadU8 ());
1124  m_checksum = i.ReadU16 ();
1125  i.ReadNtohU32 ();
1126  i.Read (data, length);
1127  m_packet = Create<Packet> (data, length);
1128 
1129  delete[] data;
1130  return GetSerializedSize ();
1131 }
1132 
1134 
1136 {
1137  static TypeId tid = TypeId ("ns3::Icmpv6TooBig")
1138  .SetParent<Icmpv6Header> ()
1139  .AddConstructor<Icmpv6TooBig> ()
1140  ;
1141  return tid;
1142 }
1143 
1145 {
1146  NS_LOG_FUNCTION (this);
1147  return GetTypeId ();
1148 }
1149 
1151  : m_packet (0),
1152  m_mtu (0)
1153 {
1154  NS_LOG_FUNCTION (this);
1156 }
1157 
1159 {
1160  NS_LOG_FUNCTION (this);
1161 }
1162 
1164 {
1165  NS_LOG_FUNCTION (this);
1166  return m_packet;
1167 }
1168 
1170 {
1171  NS_LOG_FUNCTION (this << *p);
1172  NS_ASSERT (p->GetSize () <= 1280);
1173  m_packet = p;
1174 }
1175 
1176 uint32_t Icmpv6TooBig::GetMtu () const
1177 {
1178  NS_LOG_FUNCTION (this);
1179  return m_mtu;
1180 }
1181 
1182 void Icmpv6TooBig::SetMtu (uint32_t mtu)
1183 {
1184  NS_LOG_FUNCTION (this << mtu);
1185  m_mtu = mtu;
1186 }
1187 
1188 void Icmpv6TooBig::Print (std::ostream& os) const
1189 {
1190  NS_LOG_FUNCTION (this << &os);
1191  os << "( type = " << (uint32_t)GetType () << " (Too Big) code = " << (uint32_t)GetCode () << " checksum = " << (uint32_t)GetChecksum () << " mtu = " << (uint32_t)GetMtu () << ")";
1192 }
1193 
1195 {
1196  NS_LOG_FUNCTION (this);
1197  return 8 + m_packet->GetSize ();
1198 }
1199 
1201 {
1202  NS_LOG_FUNCTION (this << &start);
1203  uint16_t checksum = 0;
1204  Buffer::Iterator i = start;
1205 
1206  i.WriteU8 (GetType ());
1207  i.WriteU8 (GetCode ());
1208  i.WriteHtonU16 (0);
1209  i.WriteHtonU32 (GetMtu ());
1210 
1211  uint32_t size = m_packet->GetSize ();
1212  uint8_t *buf = new uint8_t[size];
1213  m_packet->CopyData (buf, size);
1214  i.Write (buf, size);
1215  delete[] buf;
1216 
1217  i = start;
1218  checksum = i.CalculateIpChecksum (i.GetSize (), GetChecksum ());
1219 
1220  i = start;
1221  i.Next (2);
1222  i.WriteU16 (checksum);
1223 }
1224 
1226 {
1227  NS_LOG_FUNCTION (this << &start);
1228  uint16_t length = start.GetSize () - 8;
1229  uint8_t* data = new uint8_t[length];
1230  Buffer::Iterator i = start;
1231 
1232  SetType (i.ReadU8 ());
1233  SetCode (i.ReadU8 ());
1234  m_checksum = i.ReadU16 ();
1235  SetMtu (i.ReadNtohU32 ());
1236  i.Read (data, length);
1237  m_packet = Create<Packet> (data, length);
1238 
1239  delete[] data;
1240  return GetSerializedSize ();
1241 }
1242 
1244 
1246 {
1247  static TypeId tid = TypeId ("ns3::Icmpv6TimeExceeded")
1248  .SetParent<Icmpv6Header> ()
1249  .AddConstructor<Icmpv6TimeExceeded> ()
1250  ;
1251  return tid;
1252 }
1253 
1255 {
1256  NS_LOG_FUNCTION (this);
1257  return GetTypeId ();
1258 }
1259 
1261  : m_packet (0)
1262 {
1263  NS_LOG_FUNCTION (this);
1265 }
1266 
1268 {
1269  NS_LOG_FUNCTION (this);
1270 }
1271 
1273 {
1274  NS_LOG_FUNCTION (this);
1275  return m_packet;
1276 }
1277 
1279 {
1280  NS_LOG_FUNCTION (this << *p);
1281  NS_ASSERT (p->GetSize () <= 1280);
1282  m_packet = p;
1283 }
1284 
1285 void Icmpv6TimeExceeded::Print (std::ostream& os) const
1286 {
1287  NS_LOG_FUNCTION (this << &os);
1288  os << "( type = " << (uint32_t)GetType () << " (Destination Unreachable) code = " << (uint32_t)GetCode () << " checksum = " << (uint32_t)GetChecksum () << ")";
1289 }
1290 
1292 {
1293  NS_LOG_FUNCTION (this);
1294  return 8 + m_packet->GetSize ();
1295 }
1296 
1298 {
1299  NS_LOG_FUNCTION (this << &start);
1300 
1301  uint16_t checksum = 0;
1302  Buffer::Iterator i = start;
1303 
1304  i.WriteU8 (GetType ());
1305  i.WriteU8 (GetCode ());
1306  i.WriteHtonU16 (0);
1307  i.WriteHtonU32 (0);
1308 
1309  uint32_t size = m_packet->GetSize ();
1310  uint8_t *buf = new uint8_t[size];
1311  m_packet->CopyData (buf, size);
1312  i.Write (buf, size);
1313  delete[] buf;
1314 
1315  i = start;
1316  checksum = i.CalculateIpChecksum (i.GetSize (), GetChecksum ());
1317 
1318  i = start;
1319  i.Next (2);
1320  i.WriteU16 (checksum);
1321 }
1322 
1324 {
1325  NS_LOG_FUNCTION (this << &start);
1326 
1327  uint16_t length = start.GetSize () - 8;
1328  uint8_t* data = new uint8_t[length];
1329  Buffer::Iterator i = start;
1330 
1331  SetType (i.ReadU8 ());
1332  SetCode (i.ReadU8 ());
1333  m_checksum = i.ReadU16 ();
1334  i.ReadNtohU32 ();
1335  i.Read (data, length);
1336  m_packet = Create<Packet> (data, length);
1337 
1338  delete[] data;
1339  return GetSerializedSize ();
1340 }
1341 
1343 
1345 {
1346  static TypeId tid = TypeId ("ns3::Icmpv6ParameterError")
1347  .SetParent<Icmpv6Header> ()
1348  .AddConstructor<Icmpv6ParameterError> ()
1349  ;
1350  return tid;
1351 }
1352 
1354 {
1355  NS_LOG_FUNCTION (this);
1356  return GetTypeId ();
1357 }
1358 
1360  : m_packet (0),
1361  m_ptr (0)
1362 {
1363  NS_LOG_FUNCTION (this);
1365 }
1366 
1368 {
1369  NS_LOG_FUNCTION (this);
1370 }
1371 
1373 {
1374  NS_LOG_FUNCTION (this);
1375  return m_packet;
1376 }
1377 
1379 {
1380  NS_LOG_FUNCTION (this << *p);
1381  NS_ASSERT (p->GetSize () <= 1280);
1382  m_packet = p;
1383 }
1384 
1386 {
1387  NS_LOG_FUNCTION (this);
1388  return m_ptr;
1389 }
1390 
1391 void Icmpv6ParameterError::SetPtr (uint32_t ptr)
1392 {
1393  NS_LOG_FUNCTION (this << ptr);
1394  m_ptr = ptr;
1395 }
1396 
1397 void Icmpv6ParameterError::Print (std::ostream& os) const
1398 {
1399  NS_LOG_FUNCTION (this << &os);
1400  os << "( type = " << (uint32_t)GetType () << " (Destination Unreachable) code = " << (uint32_t)GetCode () << " checksum = " << (uint32_t)GetChecksum () << " ptr = " << (uint32_t)GetPtr () << ")";
1401 }
1402 
1404 {
1405  NS_LOG_FUNCTION (this);
1406  return 8 + m_packet->GetSize ();
1407 }
1408 
1410 {
1411  NS_LOG_FUNCTION (this << &start);
1412  uint16_t checksum = 0;
1413  Buffer::Iterator i = start;
1414 
1415  i.WriteU8 (GetType ());
1416  i.WriteU8 (GetCode ());
1417  i.WriteHtonU16 (0);
1418  i.WriteHtonU32 (GetPtr ());
1419 
1420  uint32_t size = m_packet->GetSize ();
1421  uint8_t *buf = new uint8_t[size];
1422  m_packet->CopyData (buf, size);
1423  i.Write (buf, size);
1424  delete[] buf;
1425 
1426  i = start;
1427  checksum = i.CalculateIpChecksum (i.GetSize (), GetChecksum ());
1428 
1429  i = start;
1430  i.Next (2);
1431  i.WriteU16 (checksum);
1432 }
1433 
1435 {
1436  NS_LOG_FUNCTION (this << &start);
1437  uint16_t length = start.GetSize () - 8;
1438  uint8_t* data = new uint8_t[length];
1439  Buffer::Iterator i = start;
1440 
1441  SetType (i.ReadU8 ());
1442  SetCode (i.ReadU8 ());
1443  m_checksum = i.ReadU16 ();
1444  SetPtr (i.ReadNtohU32 ());
1445  i.Read (data, length);
1446  m_packet = Create<Packet> (data, length);
1447  delete[] data;
1448 
1449  return GetSerializedSize ();
1450 }
1451 
1453 
1455 {
1456  static TypeId tid = TypeId ("ns3::Icmpv6OptionHeader")
1457  .SetParent<Header> ()
1458  .AddConstructor<Icmpv6OptionHeader> ()
1459  ;
1460  return tid;
1461 }
1462 
1464 {
1465  NS_LOG_FUNCTION (this);
1466  return GetTypeId ();
1467 }
1468 
1469 
1471 {
1472  NS_LOG_FUNCTION (this);
1474  m_type = 0;
1475  m_len = 0;
1476 }
1477 
1479 {
1480  NS_LOG_FUNCTION (this);
1481 }
1482 
1484 {
1486  return m_type;
1487 }
1488 
1489 void Icmpv6OptionHeader::SetType (uint8_t type)
1490 {
1491  NS_LOG_FUNCTION (this << static_cast<uint32_t> (type));
1492  m_type = type;
1493 }
1494 
1496 {
1497  NS_LOG_FUNCTION (this);
1498  return m_len;
1499 }
1500 
1502 {
1503  NS_LOG_FUNCTION (this << static_cast<uint32_t> (len));
1504  m_len = len;
1505 }
1506 
1507 void Icmpv6OptionHeader::Print (std::ostream& os) const
1508 {
1509  NS_LOG_FUNCTION (this << &os);
1510  os << "( type = " << (uint32_t)GetType () << " length = " << (uint32_t)GetLength () << ")";
1511 }
1512 
1514 {
1515  NS_LOG_FUNCTION (this);
1516  return m_len*8;
1517 }
1518 
1520 {
1521  NS_LOG_FUNCTION (this << &start);
1522  return GetSerializedSize ();
1523 }
1524 
1526 {
1527  NS_LOG_FUNCTION (this << &start);
1528 }
1529 
1531 
1533 {
1534  static TypeId tid = TypeId ("ns3::Icmpv6OptionMtu")
1536  .AddConstructor<Icmpv6OptionMtu> ()
1537  ;
1538  return tid;
1539 }
1540 
1542 {
1543  NS_LOG_FUNCTION (this);
1544  return GetTypeId ();
1545 }
1546 
1548 {
1549  NS_LOG_FUNCTION (this);
1551  SetLength (1);
1552  SetReserved (0);
1553 }
1554 
1556  : m_mtu (mtu)
1557 {
1558  NS_LOG_FUNCTION (this << mtu);
1560  SetLength (1);
1561  SetReserved (0);
1562 }
1563 
1565 {
1566  NS_LOG_FUNCTION (this);
1567 }
1568 
1570 {
1571  NS_LOG_FUNCTION (this);
1572  return m_reserved;
1573 }
1574 
1575 void Icmpv6OptionMtu::SetReserved (uint16_t reserved)
1576 {
1577  NS_LOG_FUNCTION (this << reserved);
1578  m_reserved = reserved;
1579 }
1580 
1581 uint32_t Icmpv6OptionMtu::GetMtu () const
1582 {
1583  NS_LOG_FUNCTION (this);
1584  return m_mtu;
1585 }
1586 
1587 void Icmpv6OptionMtu::SetMtu (uint32_t mtu)
1588 {
1589  NS_LOG_FUNCTION (this << mtu);
1590  m_mtu = mtu;
1591 }
1592 
1593 void Icmpv6OptionMtu::Print (std::ostream& os) const
1594 {
1595  NS_LOG_FUNCTION (this << &os);
1596  os << "( type = " << (uint32_t)GetType () << " length = " << (uint32_t)GetLength () << " MTU = " << m_mtu << ")";
1597 }
1598 
1600 {
1601  NS_LOG_FUNCTION (this);
1602  return 8; /* m_len = 1 so the real size is multiple by 8 */
1603 }
1604 
1606 {
1607  NS_LOG_FUNCTION (this << &start);
1608  Buffer::Iterator i = start;
1609  i.WriteU8 (GetType ());
1610  i.WriteU8 (GetLength ());
1611  i.WriteHtonU16 (GetReserved ());
1612  i.WriteHtonU32 (GetMtu ());
1613 }
1614 
1616 {
1617  NS_LOG_FUNCTION (this << &start);
1618  Buffer::Iterator i = start;
1619  SetType (i.ReadU8 ());
1620  SetLength (i.ReadU8 ());
1621  SetReserved (i.ReadNtohU16 ());
1622  SetMtu (i.ReadNtohU32 ());
1623  return GetSerializedSize ();
1624 }
1625 
1627 
1629 {
1630  static TypeId tid = TypeId ("ns3::Icmpv6OptionPrefixInformation")
1632  .AddConstructor<Icmpv6OptionPrefixInformation> ()
1633  ;
1634  return tid;
1635 }
1636 
1638 {
1639  NS_LOG_FUNCTION (this);
1640  return GetTypeId ();
1641 }
1642 
1644 {
1645  NS_LOG_FUNCTION (this);
1647  SetLength (4);
1648  SetPrefix (Ipv6Address ("::"));
1649  SetPrefixLength (0);
1650  SetValidTime (0);
1651  SetPreferredTime (0);
1652  SetFlags (0);
1653  SetReserved (0);
1654 }
1655 
1657 {
1658  NS_LOG_FUNCTION (this << prefix << static_cast<uint32_t> (prefixlen));
1660  SetLength (4);
1661  SetPrefix (prefix);
1662  SetPrefixLength (prefixlen);
1663  SetValidTime (0);
1664  SetPreferredTime (0);
1665  SetFlags (0);
1666  SetReserved (0);
1667 }
1668 
1670 {
1671  NS_LOG_FUNCTION (this);
1672 }
1673 
1675 {
1676  NS_LOG_FUNCTION (this);
1677  return m_prefixLength;
1678 }
1679 
1681 {
1682  NS_LOG_FUNCTION (this << static_cast<uint32_t> (prefixLength));
1683  NS_ASSERT (prefixLength <= 128);
1684  m_prefixLength = prefixLength;
1685 }
1686 
1688 {
1689  NS_LOG_FUNCTION (this);
1690  return m_flags;
1691 }
1692 
1694 {
1695  NS_LOG_FUNCTION (this);
1696  m_flags = flags;
1697 }
1698 
1700 {
1701  NS_LOG_FUNCTION (this);
1702  return m_validTime;
1703 }
1704 
1706 {
1707  NS_LOG_FUNCTION (this << validTime);
1708  m_validTime = validTime;
1709 }
1710 
1712 {
1713  NS_LOG_FUNCTION (this);
1714  return m_preferredTime;
1715 }
1716 
1718 {
1719  NS_LOG_FUNCTION (this << preferredTime);
1720  m_preferredTime = preferredTime;
1721 }
1722 
1724 {
1725  NS_LOG_FUNCTION (this);
1726  return m_preferredTime;
1727 }
1728 
1730 {
1731  NS_LOG_FUNCTION (this << reserved);
1732  m_reserved = reserved;
1733 }
1734 
1736 {
1737  NS_LOG_FUNCTION (this);
1738  return m_prefix;
1739 }
1740 
1742 {
1743  NS_LOG_FUNCTION (this << prefix);
1744  m_prefix = prefix;
1745 }
1746 
1747 void Icmpv6OptionPrefixInformation::Print (std::ostream& os) const
1748 {
1749  NS_LOG_FUNCTION (this << &os);
1750  os << "( type = " << (uint32_t)GetType () << " length = " << (uint32_t)GetLength () << " prefix " << m_prefix << ")";
1751 }
1752 
1754 {
1755  NS_LOG_FUNCTION (this);
1756  return 32;
1757 }
1758 
1760 {
1761  NS_LOG_FUNCTION (this << &start);
1762  Buffer::Iterator i = start;
1763  uint8_t buf[16];
1764 
1765  memset (buf, 0x00, sizeof (buf));
1766 
1767  i.WriteU8 (GetType ());
1768  i.WriteU8 (GetLength ());
1769  i.WriteU8 (m_prefixLength);
1770  i.WriteU8 (m_flags);
1774  m_prefix.GetBytes (buf);
1775  i.Write (buf, 16);
1776 }
1777 
1779 {
1780  NS_LOG_FUNCTION (this << &start);
1781  Buffer::Iterator i = start;
1782  uint8_t buf[16];
1783 
1784  SetType (i.ReadU8 ());
1785  SetLength (i.ReadU8 ());
1786  SetPrefixLength (i.ReadU8 ());
1787  SetFlags (i.ReadU8 ());
1788  SetValidTime (i.ReadNtohU32 ());
1790  SetReserved (i.ReadNtohU32 ());
1791  i.Read (buf, 16);
1792 
1793  Ipv6Address prefix (buf);
1794  SetPrefix (prefix);
1795 
1796  return GetSerializedSize ();
1797 }
1798 
1800 
1802 {
1803  static TypeId tid = TypeId ("ns3::Icmpv6OptionLinkLayerAddress")
1805  .AddConstructor<Icmpv6OptionLinkLayerAddress> ()
1806  ;
1807  return tid;
1808 }
1809 
1811 {
1812  NS_LOG_FUNCTION (this);
1813  return GetTypeId ();
1814 }
1815 
1817 {
1818  NS_LOG_FUNCTION (this << source);
1820 }
1821 
1823 {
1824  NS_LOG_FUNCTION (this);
1826 }
1827 
1829 {
1830  NS_LOG_FUNCTION (this << source << addr);
1832  SetAddress (addr);
1833 
1834  uint8_t len = (2 + m_addr.GetLength ()) / 8;
1835  if ( (2 + m_addr.GetLength ()) % 8 )
1836  {
1837  len ++;
1838  }
1839  SetLength (len);
1840 }
1841 
1843 {
1844  NS_LOG_FUNCTION (this);
1845 }
1846 
1848 {
1849  NS_LOG_FUNCTION (this);
1850  return m_addr;
1851 }
1852 
1854 {
1855  NS_LOG_FUNCTION (this << addr);
1856  m_addr = addr;
1857 }
1858 
1859 void Icmpv6OptionLinkLayerAddress::Print (std::ostream& os) const
1860 {
1861  NS_LOG_FUNCTION (this << &os);
1862  os << "( type = " << (uint32_t)GetType () << " length = " << (uint32_t)GetLength () << " L2 Address = " << m_addr << ")";
1863 }
1864 
1866 {
1867  NS_LOG_FUNCTION (this);
1868  uint8_t nb = GetLength() * 8;
1869  return nb;
1870 }
1871 
1873 {
1874  NS_LOG_FUNCTION (this << &start);
1875  Buffer::Iterator i = start;
1876  uint8_t mac[32];
1877 
1878  i.WriteU8 (GetType ());
1879  i.WriteU8 (GetLength ());
1880  m_addr.CopyTo (mac);
1881  i.Write (mac, m_addr.GetLength ());
1882 
1883  uint8_t len = GetLength ()*8 - (2 + m_addr.GetLength ());
1884  for (uint8_t nb = 0; nb<len; nb++)
1885  {
1886  i.WriteU8 (0);
1887  }
1888 }
1889 
1891 {
1892  NS_LOG_FUNCTION (this << &start);
1893  Buffer::Iterator i = start;
1894  uint8_t mac[32];
1895 
1896  SetType (i.ReadU8 ());
1897  SetLength (i.ReadU8 ());
1898  // -fstrict-overflow sensitive, see bug 1868
1899  NS_ASSERT (GetLength () * 8 <= 32 + 2);
1900  i.Read (mac, (GetLength () * 8) - 2);
1901 
1902  m_addr.CopyFrom (mac, (GetLength () * 8) - 2);
1903 
1904  return GetSerializedSize ();
1905 }
1906 
1908 
1910 {
1911  static TypeId tid = TypeId ("ns3::Icmpv6OptionRedirected")
1913  .AddConstructor<Icmpv6OptionRedirected> ()
1914  ;
1915  return tid;
1916 }
1917 
1919 {
1920  NS_LOG_FUNCTION (this);
1921  return GetTypeId ();
1922 }
1923 
1925  : m_packet (0)
1926 {
1927  NS_LOG_FUNCTION (this);
1929 }
1930 
1932 {
1933  NS_LOG_FUNCTION (this);
1934  m_packet = 0;
1935 }
1936 
1938 {
1939  NS_LOG_FUNCTION (this);
1940  return m_packet;
1941 }
1942 
1944 {
1945  NS_LOG_FUNCTION (this << *packet);
1946  NS_ASSERT (packet->GetSize () <= 1280);
1947  m_packet = packet;
1948  SetLength (1 + (m_packet->GetSize () / 8));
1949 }
1950 
1951 void Icmpv6OptionRedirected::Print (std::ostream& os) const
1952 {
1953  NS_LOG_FUNCTION (this << &os);
1954  os << "( type = " << (uint32_t)GetType () << " length = " << (uint32_t)GetLength () << ")";
1955 }
1956 
1958 {
1959  NS_LOG_FUNCTION (this);
1960  return 8 + m_packet->GetSize ();
1961 }
1962 
1964 {
1965  NS_LOG_FUNCTION (this << &start);
1966  Buffer::Iterator i = start;
1967 
1968  i.WriteU8 (GetType ());
1969  i.WriteU8 (GetLength ());
1970  // Reserved
1971  i.WriteU16 (0);
1972  i.WriteU32 (0);
1973 
1974  uint32_t size = m_packet->GetSize ();
1975  uint8_t *buf = new uint8_t[size];
1976  m_packet->CopyData (buf, size);
1977  i.Write (buf, size);
1978  delete[] buf;
1979 }
1980 
1982 {
1983  NS_LOG_FUNCTION (this << &start);
1984  Buffer::Iterator i = start;
1985 
1986  SetType (i.ReadU8 ());
1987  uint8_t length = i.ReadU8 ();
1988  SetLength (length);
1989  i.ReadU16 ();
1990  i.ReadU32 ();
1991 
1992  uint32_t len2 = (GetLength () - 1) * 8;
1993  uint8_t* buff = new uint8_t[len2];
1994  i.Read (buff, len2);
1995  m_packet = Create<Packet> (buff, len2);
1996  delete[] buff;
1997 
1998  return GetSerializedSize ();
1999 }
2000 
2001 } /* namespace ns3 */
2002 
uint16_t ReadU16(void)
Definition: buffer.h:1036
Protocol header serialization and deserialization.
Definition: header.h:42
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
uint16_t CalculateIpChecksum(uint16_t size)
Calculate the checksum.
Definition: buffer.cc:1162
virtual void Print(std::ostream &os) const
Print informations.
uint32_t GetReserved() const
Get the reserved field.
Icmpv6OptionHeader()
Constructor.
Ipv6Address m_destination
IPv6 destination address.
void SetLength(uint8_t len)
Set the length of the option.
uint8_t GetLength() const
Get the length of the option in 8 bytes unit.
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.
uint16_t GetReserved() const
Get the reserved field.
Doxygen introspection did not find any typical Config paths.
uint16_t GetId() const
Get the ID of the packet.
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.
uint32_t GetPtr() const
Get the pointer field.
uint32_t ReadU32(void)
Definition: buffer.cc:1001
static TypeId GetTypeId()
Get the UID of this class.
virtual void Print(std::ostream &os) const
Print informations.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
Doxygen introspection did not find any typical Config paths.
uint32_t GetReserved() const
Get the reserved field.
Doxygen introspection did not find any typical Config paths.
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
Doxygen introspection did not find any typical Config paths.
static TypeId GetTypeId()
Get the UID of this class.
Ipv6Address GetPrefix() const
Get the IPv6 prefix.
uint8_t m_type
The type.
bool m_flagR
The R flag.
virtual uint32_t GetSerializedSize() const
Get the serialized size.
virtual void Print(std::ostream &os) const
Print informations.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register the class in the ns-3 factory.
Definition: object-base.h:38
virtual uint32_t GetSerializedSize() const
Get the serialized size.
Ptr< Packet > GetPacket() const
Get the incorrect packet.
Ptr< Packet > m_packet
The incorrect packet.
Ptr< Packet > m_packet
The incorrect Packet.
Icmpv6OptionMtu()
Constructor.
void SetReserved(uint32_t reserved)
Set the reserved field (normally it will be 0x00000000).
Ipv6Address GetTarget() const
Get the IPv6 target address.
uint32_t m_validTime
The valid time.
virtual uint32_t GetSerializedSize() const
Get the serialized size.
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
void SetReserved(uint32_t reserved)
Set the reserved field.
Icmpv6NS()
Constructor.
virtual ~Icmpv6TimeExceeded()
Destructor.
Doxygen introspection did not find any typical Config paths.
Icmpv6TimeExceeded()
Constructor.
automatically resized byte buffer
Definition: buffer.h:92
Doxygen introspection did not find any typical Config paths.
virtual void Print(std::ostream &os) const
Print informations.
Doxygen introspection did not find any typical Config paths.
uint8_t GetType() const
Get the type field.
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.
uint8_t GetType() const
Get the type of the option.
static TypeId GetTypeId()
Get the UID of this class.
uint32_t m_reserved
The reserved value.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:61
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:170
bool GetFlagH() const
Get the H flag.
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.
bool GetFlagS() const
Get the S flag.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:744
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 TypeId GetInstanceTypeId() const
Get the instance type ID.
virtual ~Icmpv6OptionHeader()
Destructor.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
uint16_t m_id
ID of the packet (to distinguish response between many ping program).
uint8_t GetCurHopLimit() const
Get the IPv6 maximum number of jumps.
static TypeId GetTypeId()
Get the UID of this class.
void SetMtu(uint32_t mtu)
Set the MTU.
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.
virtual uint32_t GetSerializedSize() const
Get the serialized size.
Icmpv6NA()
Constructor.
uint32_t ReadNtohU32(void)
Definition: buffer.h:977
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
virtual uint32_t GetSerializedSize() const
Get the serialized size.
Icmpv6Echo()
Default constructor.
uint16_t GetLifeTime() const
Get the node Life time (Neighbor Discovery).
Icmpv6ParameterError()
Constructor.
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
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:86
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
void SetPacket(Ptr< Packet > p)
Set the incorrect packet.
virtual uint32_t GetSerializedSize() const
Get the serialized size.
virtual ~Icmpv6OptionPrefixInformation()
Destructor.
void SetLifeTime(uint16_t l)
Set the node Life time (Neighbor Discovery).
virtual void Print(std::ostream &os) const
Print informations.
void SetValidTime(uint32_t validTime)
Set the valid time of the information.
uint8_t m_type
The type.
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
bool GetFlagR() const
Get the R flag.
void SetIpv6Target(Ipv6Address target)
Set the IPv6 target field.
Doxygen introspection did not find any typical Config paths.
virtual ~Icmpv6ParameterError()
Destructor.
void SetType(uint8_t type)
Set the type.
void SetCurHopLimit(uint8_t m)
Set the IPv6 maximum number of jumps.
virtual ~Icmpv6NA()
Destructor.
void SetPreferredTime(uint32_t preferredTime)
Set the preferred time of the information.
Ipv6Address GetIpv6Target() const
Get the IPv6 target field.
Doxygen introspection did not find any typical Config paths.
Definition: icmpv6-header.h:37
uint32_t m_reserved
The reserved value.
uint16_t m_checksum
The checksum.
Ptr< Packet > GetPacket() const
Get the incorrect packet.
uint32_t GetReserved() const
Get the reserved field.
void SetIpv6Target(Ipv6Address target)
Set the IPv6 target field.
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
virtual uint32_t GetSerializedSize() const
Get the serialized size.
void SetPrefixLength(uint8_t prefixLength)
Set the prefix length.
Doxygen introspection did not find any typical Config paths.
uint8_t data[writeSize]
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
uint32_t GetMtu() const
Get the MTU.
Ptr< SampleEmitter > s
virtual uint32_t GetSerializedSize() const
Get the serialized size.
void WriteU16(uint16_t data)
Definition: buffer.cc:899
Ipv6Address m_target
The IPv6 target address.
Ptr< Packet > m_packet
the incorrect packet.
virtual void Print(std::ostream &os) const
Print informations.
uint32_t m_reserved
The reserved value.
bool m_flagH
The H flag.
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
void WriteHtonU16(uint16_t data)
Definition: buffer.h:912
uint32_t m_reserved
The reserved field.
virtual void Print(std::ostream &os) const
Print informations.
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
uint32_t GetPreferredTime() const
Get the preferred time of the information.
Icmpv6RS()
Constructor.
uint8_t GetLength(void) const
Get the length of the underlying address.
Definition: address.cc:75
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
virtual void Print(std::ostream &os) const
Print informations.
uint8_t m_curHopLimit
The max jumps.
virtual void Print(std::ostream &os) const
Print informations.
void Next(void)
go forward by one byte
Definition: buffer.h:852
Doxygen introspection did not find any typical Config paths.
Ptr< Packet > GetPacket() const
Get the incorrect packet.
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
bool GetFlagO() const
Get the O flag.
void GetBytes(uint8_t buf[16]) const
Get the bytes corresponding to the address.
uint32_t GetReserved() const
Get the reserved field.
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.
bool GetFlagO() const
Get the O flag.
virtual void Print(std::ostream &os) const
Print informations.
void SetReserved(uint16_t reserved)
Set the reserved field.
static TypeId GetTypeId()
Get the UID of this class.
Buffer::Iterator Begin(void) const
Definition: buffer.h:1076
void SetReserved(uint32_t reserved)
Set the reserved field.
uint16_t GetSeq() const
Get the sequence number.
void Set(char const *address)
Sets an Ipv6Address by parsing the input C-string.
void SetReserved(uint32_t reserved)
Set the reserved field.
virtual uint32_t GetSerializedSize() const
Get the serialized size.
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
virtual void Print(std::ostream &os) const
Print informations.
uint8_t m_prefixLength
The length of the prefix.
uint8_t m_flags
The flags field value.
virtual ~Icmpv6OptionMtu()
Destructor.
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
uint8_t GetFlags() const
Get the flags.
virtual ~Icmpv6RS()
Destructor.
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
uint32_t CopyFrom(const uint8_t *buffer, uint8_t len)
Definition: address.cc:101
void SetChecksum(uint16_t checksum)
Set the checksum.
void SetCode(uint8_t code)
Set the code field.
Doxygen introspection did not find any typical Config paths.
uint8_t GetCode() const
Get the code field.
virtual ~Icmpv6OptionRedirected()
Destructor.
virtual void Print(std::ostream &os) const
Print informations.
uint32_t GetRetransmissionTime() const
Get the node Retransmission time (Neighbor Discovery).
virtual uint32_t GetSerializedSize() const
Get the serialized size.
virtual ~Icmpv6Redirection()
Destructor.
uint32_t GetReserved() const
Get the reserved field.
uint32_t m_ReachableTime
The reachable time value.
virtual void Print(std::ostream &os) const
Print informations.
void Read(uint8_t *buffer, uint32_t size)
Definition: buffer.cc:1152
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
void SetFlagO(bool o)
Set the O flag.
uint16_t GetChecksum() const
Get the checksum.
uint32_t GetValidTime() const
Get the valid time of the information.
void SetFlagH(bool h)
Set the H flag.
Icmpv6RA()
Constructor.
virtual ~Icmpv6RA()
Destructor.
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
void WriteHtonU32(uint32_t data)
Definition: buffer.h:931
void SetReserved(uint32_t reserved)
Set the reserved field.
void SetFlagR(bool r)
Set the R flag.
virtual uint32_t GetSerializedSize() const
Get the serialized size.
virtual void Print(std::ostream &os) const
Print informations.
Doxygen introspection did not find any typical Config paths.
bool m_flagO
The M flag.
void SetFlagS(bool s)
Set the S flag.
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
void SetFlagM(bool m)
Set the M flag.
void SetFlags(uint8_t flags)
Set the flags.
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
void SetReachableTime(uint32_t r)
Set the node Reachable time (Neighbor Discovery).
uint32_t m_ptr
The pointer field.
Describes an IPv6 address.
Definition: ipv6-address.h:46
virtual ~Icmpv6Header()
Destructor.
uint32_t CopyTo(uint8_t buffer[MAX_SIZE]) const
Copy the address bytes into a buffer.
Definition: address.cc:82
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
void WriteU8(uint8_t data)
Definition: buffer.h:876
Icmpv6TooBig()
Constructor.
virtual void Print(std::ostream &os) const
Print informations.
virtual ~Icmpv6Echo()
Destructor.
void SetDestination(Ipv6Address destination)
Set the IPv6 destination address.
uint8_t GetFlags() const
Getflags.
Ptr< Packet > GetPacket() const
Get the redirected packet.
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
virtual ~Icmpv6TooBig()
Destructor.
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
virtual uint32_t GetSerializedSize() const
Get the serialized size.
uint16_t m_LifeTime
The lifetime value.
uint8_t ReadU8(void)
Definition: buffer.h:1028
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
virtual ~Icmpv6NS()
Destructor.
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
void Write(uint8_t const *buffer, uint32_t size)
Definition: buffer.cc:982
Ptr< Packet > m_packet
The incorrect packet.
Ipv6Address GetDestination() const
Get the IPv6 destination address.
Ipv6Address GetIpv6Target() const
Get the IPv6 target field.
Icmpv6OptionRedirected()
Constructor.
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
Copy the packet contents to a byte buffer.
Definition: packet.cc:381
Icmpv6Header()
Constructor.
virtual ~Icmpv6DestinationUnreachable()
Destructor.
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
static TypeId GetTypeId()
Get the UID of this class.
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
bool AddAtStart(uint32_t start)
Definition: buffer.cc:309
void SetFlags(uint8_t f)
Setflags.
virtual uint32_t GetSerializedSize() const
Get the serialized size.
void SetSeq(uint16_t seq)
Set the sequence number.
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.
uint16_t ReadNtohU16(void)
Definition: buffer.h:953
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
void WriteU32(uint32_t data)
Definition: buffer.cc:907
Icmpv6Redirection()
Constructor.
void SetPacket(Ptr< Packet > p)
Set the incorrect packet.
uint32_t GetMtu() const
Get the MTU field.
bool GetFlagM() const
Get the M flag.
uint16_t m_seq
Sequence number (to distinguish response).
virtual uint32_t GetSerializedSize() const
Get the serialized size.
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
uint32_t GetSize(void) const
Definition: buffer.cc:1187
Doxygen introspection did not find any typical Config paths.
a unique identifier for an interface.
Definition: type-id.h:49
Ptr< Packet > GetPacket() const
Get the incorrect packet.
virtual uint32_t GetSerializedSize() const
Get the serialized size.
void SetFlagO(bool o)
Set the O flag.
static TypeId GetTypeId()
Get the UID of this class.
TypeId SetParent(TypeId tid)
Definition: type-id.cc:610
static TypeId GetTypeId()
Get the UID of this class.
void SetPrefix(Ipv6Address prefix)
Set the IPv6 prefix.
static TypeId GetTypeId()
Get the UID of this class.
uint32_t GetReachableTime() const
Get the node Reachable time (Neighbor Discovery).
Ipv6Address m_prefix
The prefix value.
Doxygen introspection did not find any typical Config paths.
void SetId(uint16_t id)
Set the ID of the packet.
bool m_flagM
The M flag.
uint8_t GetPrefixLength() const
Get the prefix length.
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
void SetMtu(uint32_t mtu)
Set the MTU.
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
void Serialize(uint8_t buf[16]) const
Serialize this address to a 16-byte buffer.