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 << *p);
1075  NS_ASSERT (p->GetSize () <= 1280);
1076  m_packet = p->Copy ();
1077 }
1078 
1079 void Icmpv6DestinationUnreachable::Print (std::ostream& os) const
1080 {
1081  NS_LOG_FUNCTION (this << &os);
1082  os << "( type = " << (uint32_t)GetType () << " (Destination Unreachable) code = " << (uint32_t)GetCode () << " checksum = " << (uint32_t)GetChecksum () << ")";
1083 }
1084 
1086 {
1087  NS_LOG_FUNCTION (this);
1088  // The real size of the header is 8 + m_packet->GetSize ()
1089  // HOWEVER we just serialize the first 8 bytes, as the rest is serialized separately.
1090  return 8;
1091 }
1092 
1094 {
1095  NS_LOG_FUNCTION (this << &start);
1096  uint16_t checksum = 0;
1097  Buffer::Iterator i = start;
1098 
1099  Buffer secondaryBuffer;
1100  secondaryBuffer.AddAtStart (8 + m_packet->GetSize ());
1101  Buffer::Iterator iter = secondaryBuffer.Begin ();
1102 
1103  iter.WriteU8 (GetType ());
1104  iter.WriteU8 (GetCode ());
1105  iter.WriteU16 (0);
1106  iter.WriteU32 (0);
1107 
1108  uint32_t size = m_packet->GetSize ();
1109  uint8_t *buf = new uint8_t[size];
1110  m_packet->CopyData (buf, size);
1111  iter.Write (buf, size);
1112  delete[] buf;
1113 
1114  iter = secondaryBuffer.Begin ();
1115  checksum = iter.CalculateIpChecksum (iter.GetSize (), GetChecksum ());
1116 
1117  i.WriteU8 (GetType ());
1118  i.WriteU8 (GetCode ());
1119  i.WriteU16 (checksum);
1120  i.WriteU32 (0);
1121 }
1122 
1124 {
1125  NS_LOG_FUNCTION (this << &start);
1126  Buffer::Iterator i = start;
1127 
1128  SetType (i.ReadU8 ());
1129  SetCode (i.ReadU8 ());
1130  m_checksum = i.ReadU16 ();
1131  i.ReadU32 ();
1132 
1133  return GetSerializedSize ();
1134 }
1135 
1137 
1139 {
1140  static TypeId tid = TypeId ("ns3::Icmpv6TooBig")
1141  .SetParent<Icmpv6Header> ()
1142  .SetGroupName ("Internet")
1143  .AddConstructor<Icmpv6TooBig> ()
1144  ;
1145  return tid;
1146 }
1147 
1149 {
1150  NS_LOG_FUNCTION (this);
1151  return GetTypeId ();
1152 }
1153 
1155  : m_packet (0),
1156  m_mtu (0)
1157 {
1158  NS_LOG_FUNCTION (this);
1160 }
1161 
1163 {
1164  NS_LOG_FUNCTION (this);
1165 }
1166 
1168 {
1169  NS_LOG_FUNCTION (this << *p);
1170  NS_ASSERT (p->GetSize () <= 1280);
1171  m_packet = p->Copy ();
1172 }
1173 
1174 uint32_t Icmpv6TooBig::GetMtu () const
1175 {
1176  NS_LOG_FUNCTION (this);
1177  return m_mtu;
1178 }
1179 
1180 void Icmpv6TooBig::SetMtu (uint32_t mtu)
1181 {
1182  NS_LOG_FUNCTION (this << mtu);
1183  m_mtu = mtu;
1184 }
1185 
1186 void Icmpv6TooBig::Print (std::ostream& os) const
1187 {
1188  NS_LOG_FUNCTION (this << &os);
1189  os << "( type = " << (uint32_t)GetType () << " (Too Big) code = " << (uint32_t)GetCode () << " checksum = " << (uint32_t)GetChecksum () << " mtu = " << (uint32_t)GetMtu () << ")";
1190 }
1191 
1193 {
1194  NS_LOG_FUNCTION (this);
1195  // The real size of the header is 8 + m_packet->GetSize ()
1196  // HOWEVER we just serialize the first 8 bytes, as the rest is serialized separately.
1197  return 8;
1198 }
1199 
1201 {
1202  NS_LOG_FUNCTION (this << &start);
1203  uint16_t checksum = 0;
1204  Buffer::Iterator i = start;
1205 
1206  Buffer secondaryBuffer;
1207  secondaryBuffer.AddAtStart (8 + m_packet->GetSize ());
1208  Buffer::Iterator iter = secondaryBuffer.Begin ();
1209 
1210  iter.WriteU8 (GetType ());
1211  iter.WriteU8 (GetCode ());
1212  iter.WriteU16 (0);
1213  iter.WriteHtonU32 (GetMtu ());
1214 
1215  uint32_t size = m_packet->GetSize ();
1216  uint8_t *buf = new uint8_t[size];
1217  m_packet->CopyData (buf, size);
1218  iter.Write (buf, size);
1219  delete[] buf;
1220 
1221  iter = secondaryBuffer.Begin ();
1222  checksum = iter.CalculateIpChecksum (iter.GetSize (), GetChecksum ());
1223 
1224  i.WriteU8 (GetType ());
1225  i.WriteU8 (GetCode ());
1226  i.WriteU16 (checksum);
1227  i.WriteHtonU32 (GetMtu ());
1228 }
1229 
1231 {
1232  NS_LOG_FUNCTION (this << &start);
1233  Buffer::Iterator i = start;
1234 
1235  SetType (i.ReadU8 ());
1236  SetCode (i.ReadU8 ());
1237  m_checksum = i.ReadU16 ();
1238  SetMtu (i.ReadNtohU32 ());
1239 
1240  return GetSerializedSize ();
1241 }
1242 
1244 
1246 {
1247  static TypeId tid = TypeId ("ns3::Icmpv6TimeExceeded")
1248  .SetParent<Icmpv6Header> ()
1249  .SetGroupName ("Internet")
1250  .AddConstructor<Icmpv6TimeExceeded> ()
1251  ;
1252  return tid;
1253 }
1254 
1256 {
1257  NS_LOG_FUNCTION (this);
1258  return GetTypeId ();
1259 }
1260 
1262  : m_packet (0)
1263 {
1264  NS_LOG_FUNCTION (this);
1266 }
1267 
1269 {
1270  NS_LOG_FUNCTION (this);
1271 }
1272 
1273 
1275 {
1276  NS_LOG_FUNCTION (this << *p);
1277  NS_ASSERT (p->GetSize () <= 1280);
1278  m_packet = p->Copy ();
1279 }
1280 
1281 void Icmpv6TimeExceeded::Print (std::ostream& os) const
1282 {
1283  NS_LOG_FUNCTION (this << &os);
1284  os << "( type = " << (uint32_t)GetType () << " (Destination Unreachable) code = " << (uint32_t)GetCode () << " checksum = " << (uint32_t)GetChecksum () << ")";
1285 }
1286 
1288 {
1289  NS_LOG_FUNCTION (this);
1290  // The real size of the header is 8 + m_packet->GetSize ()
1291  // HOWEVER we just serialize the first 8 bytes, as the rest is serialized separately.
1292  return 8;
1293 }
1294 
1296 {
1297  NS_LOG_FUNCTION (this << &start);
1298  uint16_t checksum = 0;
1299  Buffer::Iterator i = start;
1300 
1301  Buffer secondaryBuffer;
1302  secondaryBuffer.AddAtStart (8 + m_packet->GetSize ());
1303  Buffer::Iterator iter = secondaryBuffer.Begin ();
1304 
1305  iter.WriteU8 (GetType ());
1306  iter.WriteU8 (GetCode ());
1307  iter.WriteU16 (0);
1308  iter.WriteU32 (0);
1309 
1310  uint32_t size = m_packet->GetSize ();
1311  uint8_t *buf = new uint8_t[size];
1312  m_packet->CopyData (buf, size);
1313  iter.Write (buf, size);
1314  delete[] buf;
1315 
1316  iter = secondaryBuffer.Begin ();
1317  checksum = iter.CalculateIpChecksum (iter.GetSize (), GetChecksum ());
1318 
1319  i.WriteU8 (GetType ());
1320  i.WriteU8 (GetCode ());
1321  i.WriteU16 (checksum);
1322  i.WriteU32 (0);
1323 }
1324 
1326 {
1327  NS_LOG_FUNCTION (this << &start);
1328  Buffer::Iterator i = start;
1329 
1330  SetType (i.ReadU8 ());
1331  SetCode (i.ReadU8 ());
1332  m_checksum = i.ReadU16 ();
1333  i.ReadU32 ();
1334 
1335  return GetSerializedSize ();
1336 }
1337 
1339 
1341 {
1342  static TypeId tid = TypeId ("ns3::Icmpv6ParameterError")
1343  .SetParent<Icmpv6Header> ()
1344  .SetGroupName ("Internet")
1345  .AddConstructor<Icmpv6ParameterError> ()
1346  ;
1347  return tid;
1348 }
1349 
1351 {
1352  NS_LOG_FUNCTION (this);
1353  return GetTypeId ();
1354 }
1355 
1357  : m_packet (0),
1358  m_ptr (0)
1359 {
1360  NS_LOG_FUNCTION (this);
1362 }
1363 
1365 {
1366  NS_LOG_FUNCTION (this);
1367 }
1368 
1370 {
1371  NS_LOG_FUNCTION (this << *p);
1372  NS_ASSERT (p->GetSize () <= 1280);
1373  m_packet = p->Copy ();
1374 }
1375 
1377 {
1378  NS_LOG_FUNCTION (this);
1379  return m_ptr;
1380 }
1381 
1382 void Icmpv6ParameterError::SetPtr (uint32_t ptr)
1383 {
1384  NS_LOG_FUNCTION (this << ptr);
1385  m_ptr = ptr;
1386 }
1387 
1388 void Icmpv6ParameterError::Print (std::ostream& os) const
1389 {
1390  NS_LOG_FUNCTION (this << &os);
1391  os << "( type = " << (uint32_t)GetType () << " (Destination Unreachable) code = " << (uint32_t)GetCode () << " checksum = " << (uint32_t)GetChecksum () << " ptr = " << (uint32_t)GetPtr () << ")";
1392 }
1393 
1395 {
1396  NS_LOG_FUNCTION (this);
1397  // The real size of the header is 8 + m_packet->GetSize ()
1398  // HOWEVER we just serialize the first 8 bytes, as the rest is serialized separately.
1399  return 8;
1400 }
1401 
1403 {
1404  NS_LOG_FUNCTION (this << &start);
1405  uint16_t checksum = 0;
1406  Buffer::Iterator i = start;
1407 
1408  Buffer secondaryBuffer;
1409  secondaryBuffer.AddAtStart (8 + m_packet->GetSize ());
1410  Buffer::Iterator iter = secondaryBuffer.Begin ();
1411 
1412  iter.WriteU8 (GetType ());
1413  iter.WriteU8 (GetCode ());
1414  iter.WriteU16 (0);
1415  iter.WriteHtonU32 (GetPtr ());
1416 
1417  uint32_t size = m_packet->GetSize ();
1418  uint8_t *buf = new uint8_t[size];
1419  m_packet->CopyData (buf, size);
1420  iter.Write (buf, size);
1421  delete[] buf;
1422 
1423  iter = secondaryBuffer.Begin ();
1424  checksum = iter.CalculateIpChecksum (iter.GetSize (), GetChecksum ());
1425 
1426  i.WriteU8 (GetType ());
1427  i.WriteU8 (GetCode ());
1428  i.WriteU16 (checksum);
1429  i.WriteHtonU32 (GetPtr ());
1430 }
1431 
1433 {
1434  NS_LOG_FUNCTION (this << &start);
1435  Buffer::Iterator i = start;
1436 
1437  SetType (i.ReadU8 ());
1438  SetCode (i.ReadU8 ());
1439  m_checksum = i.ReadU16 ();
1440  SetPtr (i.ReadNtohU32 ());
1441 
1442  return GetSerializedSize ();
1443 }
1444 
1446 
1448 {
1449  static TypeId tid = TypeId ("ns3::Icmpv6OptionHeader")
1450  .SetParent<Header> ()
1451  .SetGroupName ("Internet")
1452  .AddConstructor<Icmpv6OptionHeader> ()
1453  ;
1454  return tid;
1455 }
1456 
1458 {
1459  NS_LOG_FUNCTION (this);
1460  return GetTypeId ();
1461 }
1462 
1463 
1465 {
1466  NS_LOG_FUNCTION (this);
1468  m_type = 0;
1469  m_len = 0;
1470 }
1471 
1473 {
1474  NS_LOG_FUNCTION (this);
1475 }
1476 
1478 {
1479  NS_LOG_FUNCTION (this);
1480  return m_type;
1481 }
1482 
1483 void Icmpv6OptionHeader::SetType (uint8_t type)
1484 {
1485  NS_LOG_FUNCTION (this << static_cast<uint32_t> (type));
1486  m_type = type;
1487 }
1488 
1490 {
1491  NS_LOG_FUNCTION (this);
1492  return m_len;
1493 }
1494 
1496 {
1497  NS_LOG_FUNCTION (this << static_cast<uint32_t> (len));
1498  m_len = len;
1499 }
1500 
1501 void Icmpv6OptionHeader::Print (std::ostream& os) const
1502 {
1503  NS_LOG_FUNCTION (this << &os);
1504  os << "( type = " << (uint32_t)GetType () << " length = " << (uint32_t)GetLength () << ")";
1505 }
1506 
1508 {
1509  NS_LOG_FUNCTION (this);
1510  return m_len*8;
1511 }
1512 
1514 {
1515  NS_LOG_FUNCTION (this << &start);
1516  return GetSerializedSize ();
1517 }
1518 
1520 {
1521  NS_LOG_FUNCTION (this << &start);
1522 }
1523 
1525 
1527 {
1528  static TypeId tid = TypeId ("ns3::Icmpv6OptionMtu")
1530  .SetGroupName ("Internet")
1531  .AddConstructor<Icmpv6OptionMtu> ()
1532  ;
1533  return tid;
1534 }
1535 
1537 {
1538  NS_LOG_FUNCTION (this);
1539  return GetTypeId ();
1540 }
1541 
1543 {
1544  NS_LOG_FUNCTION (this);
1546  SetLength (1);
1547  SetReserved (0);
1548 }
1549 
1551  : m_mtu (mtu)
1552 {
1553  NS_LOG_FUNCTION (this << mtu);
1555  SetLength (1);
1556  SetReserved (0);
1557 }
1558 
1560 {
1561  NS_LOG_FUNCTION (this);
1562 }
1563 
1565 {
1566  NS_LOG_FUNCTION (this);
1567  return m_reserved;
1568 }
1569 
1570 void Icmpv6OptionMtu::SetReserved (uint16_t reserved)
1571 {
1572  NS_LOG_FUNCTION (this << reserved);
1573  m_reserved = reserved;
1574 }
1575 
1576 uint32_t Icmpv6OptionMtu::GetMtu () const
1577 {
1578  NS_LOG_FUNCTION (this);
1579  return m_mtu;
1580 }
1581 
1582 void Icmpv6OptionMtu::SetMtu (uint32_t mtu)
1583 {
1584  NS_LOG_FUNCTION (this << mtu);
1585  m_mtu = mtu;
1586 }
1587 
1588 void Icmpv6OptionMtu::Print (std::ostream& os) const
1589 {
1590  NS_LOG_FUNCTION (this << &os);
1591  os << "( type = " << (uint32_t)GetType () << " length = " << (uint32_t)GetLength () << " MTU = " << m_mtu << ")";
1592 }
1593 
1595 {
1596  NS_LOG_FUNCTION (this);
1597  return 8; /* m_len = 1 so the real size is multiple by 8 */
1598 }
1599 
1601 {
1602  NS_LOG_FUNCTION (this << &start);
1603  Buffer::Iterator i = start;
1604  i.WriteU8 (GetType ());
1605  i.WriteU8 (GetLength ());
1606  i.WriteHtonU16 (GetReserved ());
1607  i.WriteHtonU32 (GetMtu ());
1608 }
1609 
1611 {
1612  NS_LOG_FUNCTION (this << &start);
1613  Buffer::Iterator i = start;
1614  SetType (i.ReadU8 ());
1615  SetLength (i.ReadU8 ());
1616  SetReserved (i.ReadNtohU16 ());
1617  SetMtu (i.ReadNtohU32 ());
1618  return GetSerializedSize ();
1619 }
1620 
1622 
1624 {
1625  static TypeId tid = TypeId ("ns3::Icmpv6OptionPrefixInformation")
1627  .SetGroupName ("Internet")
1628  .AddConstructor<Icmpv6OptionPrefixInformation> ()
1629  ;
1630  return tid;
1631 }
1632 
1634 {
1635  NS_LOG_FUNCTION (this);
1636  return GetTypeId ();
1637 }
1638 
1640 {
1641  NS_LOG_FUNCTION (this);
1643  SetLength (4);
1644  SetPrefix (Ipv6Address ("::"));
1645  SetPrefixLength (0);
1646  SetValidTime (0);
1647  SetPreferredTime (0);
1648  SetFlags (0);
1649  SetReserved (0);
1650 }
1651 
1653 {
1654  NS_LOG_FUNCTION (this << prefix << static_cast<uint32_t> (prefixlen));
1656  SetLength (4);
1657  SetPrefix (prefix);
1658  SetPrefixLength (prefixlen);
1659  SetValidTime (0);
1660  SetPreferredTime (0);
1661  SetFlags (0);
1662  SetReserved (0);
1663 }
1664 
1666 {
1667  NS_LOG_FUNCTION (this);
1668 }
1669 
1671 {
1672  NS_LOG_FUNCTION (this);
1673  return m_prefixLength;
1674 }
1675 
1677 {
1678  NS_LOG_FUNCTION (this << static_cast<uint32_t> (prefixLength));
1679  NS_ASSERT (prefixLength <= 128);
1680  m_prefixLength = prefixLength;
1681 }
1682 
1684 {
1685  NS_LOG_FUNCTION (this);
1686  return m_flags;
1687 }
1688 
1690 {
1691  NS_LOG_FUNCTION (this);
1692  m_flags = flags;
1693 }
1694 
1696 {
1697  NS_LOG_FUNCTION (this);
1698  return m_validTime;
1699 }
1700 
1702 {
1703  NS_LOG_FUNCTION (this << validTime);
1704  m_validTime = validTime;
1705 }
1706 
1708 {
1709  NS_LOG_FUNCTION (this);
1710  return m_preferredTime;
1711 }
1712 
1714 {
1715  NS_LOG_FUNCTION (this << preferredTime);
1716  m_preferredTime = preferredTime;
1717 }
1718 
1720 {
1721  NS_LOG_FUNCTION (this);
1722  return m_preferredTime;
1723 }
1724 
1726 {
1727  NS_LOG_FUNCTION (this << reserved);
1728  m_reserved = reserved;
1729 }
1730 
1732 {
1733  NS_LOG_FUNCTION (this);
1734  return m_prefix;
1735 }
1736 
1738 {
1739  NS_LOG_FUNCTION (this << prefix);
1740  m_prefix = prefix;
1741 }
1742 
1743 void Icmpv6OptionPrefixInformation::Print (std::ostream& os) const
1744 {
1745  NS_LOG_FUNCTION (this << &os);
1746  os << "( type = " << (uint32_t)GetType () << " length = " << (uint32_t)GetLength () << " prefix " << m_prefix << ")";
1747 }
1748 
1750 {
1751  NS_LOG_FUNCTION (this);
1752  return 32;
1753 }
1754 
1756 {
1757  NS_LOG_FUNCTION (this << &start);
1758  Buffer::Iterator i = start;
1759  uint8_t buf[16];
1760 
1761  memset (buf, 0x00, sizeof (buf));
1762 
1763  i.WriteU8 (GetType ());
1764  i.WriteU8 (GetLength ());
1765  i.WriteU8 (m_prefixLength);
1766  i.WriteU8 (m_flags);
1770  m_prefix.GetBytes (buf);
1771  i.Write (buf, 16);
1772 }
1773 
1775 {
1776  NS_LOG_FUNCTION (this << &start);
1777  Buffer::Iterator i = start;
1778  uint8_t buf[16];
1779 
1780  SetType (i.ReadU8 ());
1781  SetLength (i.ReadU8 ());
1782  SetPrefixLength (i.ReadU8 ());
1783  SetFlags (i.ReadU8 ());
1784  SetValidTime (i.ReadNtohU32 ());
1786  SetReserved (i.ReadNtohU32 ());
1787  i.Read (buf, 16);
1788 
1789  Ipv6Address prefix (buf);
1790  SetPrefix (prefix);
1791 
1792  return GetSerializedSize ();
1793 }
1794 
1796 
1798 {
1799  static TypeId tid = TypeId ("ns3::Icmpv6OptionLinkLayerAddress")
1801  .SetGroupName ("Internet")
1802  .AddConstructor<Icmpv6OptionLinkLayerAddress> ()
1803  ;
1804  return tid;
1805 }
1806 
1808 {
1809  NS_LOG_FUNCTION (this);
1810  return GetTypeId ();
1811 }
1812 
1814 {
1815  NS_LOG_FUNCTION (this << source);
1817 }
1818 
1820 {
1821  NS_LOG_FUNCTION (this);
1823 }
1824 
1826 {
1827  NS_LOG_FUNCTION (this << source << addr);
1829  SetAddress (addr);
1830 
1831  uint8_t len = (2 + m_addr.GetLength ()) / 8;
1832  if ( (2 + m_addr.GetLength ()) % 8 )
1833  {
1834  len ++;
1835  }
1836  SetLength (len);
1837 }
1838 
1840 {
1841  NS_LOG_FUNCTION (this);
1842 }
1843 
1845 {
1846  NS_LOG_FUNCTION (this);
1847  return m_addr;
1848 }
1849 
1851 {
1852  NS_LOG_FUNCTION (this << addr);
1853  m_addr = addr;
1854 }
1855 
1856 void Icmpv6OptionLinkLayerAddress::Print (std::ostream& os) const
1857 {
1858  NS_LOG_FUNCTION (this << &os);
1859  os << "( type = " << (uint32_t)GetType () << " length = " << (uint32_t)GetLength () << " L2 Address = " << m_addr << ")";
1860 }
1861 
1863 {
1864  NS_LOG_FUNCTION (this);
1865  uint8_t nb = GetLength() * 8;
1866  return nb;
1867 }
1868 
1870 {
1871  NS_LOG_FUNCTION (this << &start);
1872  Buffer::Iterator i = start;
1873  uint8_t mac[32];
1874 
1875  i.WriteU8 (GetType ());
1876  i.WriteU8 (GetLength ());
1877  m_addr.CopyTo (mac);
1878  i.Write (mac, m_addr.GetLength ());
1879 
1880  uint8_t len = GetLength ()*8 - (2 + m_addr.GetLength ());
1881  for (uint8_t nb = 0; nb<len; nb++)
1882  {
1883  i.WriteU8 (0);
1884  }
1885 }
1886 
1888 {
1889  NS_LOG_FUNCTION (this << &start);
1890  Buffer::Iterator i = start;
1891  uint8_t mac[32];
1892 
1893  SetType (i.ReadU8 ());
1894  SetLength (i.ReadU8 ());
1895  // -fstrict-overflow sensitive, see bug 1868
1896  NS_ASSERT (GetLength () * 8 <= 32 + 2);
1897  i.Read (mac, (GetLength () * 8) - 2);
1898 
1899  m_addr.CopyFrom (mac, (GetLength () * 8) - 2);
1900 
1901  return GetSerializedSize ();
1902 }
1903 
1905 
1907 {
1908  static TypeId tid = TypeId ("ns3::Icmpv6OptionRedirected")
1910  .SetGroupName ("Internet")
1911  .AddConstructor<Icmpv6OptionRedirected> ()
1912  ;
1913  return tid;
1914 }
1915 
1917 {
1918  NS_LOG_FUNCTION (this);
1919  return GetTypeId ();
1920 }
1921 
1923  : m_packet (0)
1924 {
1925  NS_LOG_FUNCTION (this);
1927 }
1928 
1930 {
1931  NS_LOG_FUNCTION (this);
1932  m_packet = 0;
1933 }
1934 
1936 {
1937  NS_LOG_FUNCTION (this << *packet);
1938  NS_ASSERT (packet->GetSize () <= 1280);
1939  m_packet = packet->Copy ();
1940  SetLength (1 + (m_packet->GetSize () / 8));
1941 }
1942 
1943 void Icmpv6OptionRedirected::Print (std::ostream& os) const
1944 {
1945  NS_LOG_FUNCTION (this << &os);
1946  os << "( type = " << (uint32_t)GetType () << " length = " << (uint32_t)GetLength () << ")";
1947 }
1948 
1950 {
1951  NS_LOG_FUNCTION (this);
1952  return 8 + m_packet->GetSize ();
1953 }
1954 
1956 {
1957  NS_LOG_FUNCTION (this << &start);
1958  Buffer::Iterator i = start;
1959 
1960  i.WriteU8 (GetType ());
1961  i.WriteU8 (GetLength ());
1962  // Reserved
1963  i.WriteU16 (0);
1964  i.WriteU32 (0);
1965 
1966  uint32_t size = m_packet->GetSize ();
1967  uint8_t *buf = new uint8_t[size];
1968  m_packet->CopyData (buf, size);
1969  i.Write (buf, size);
1970  delete[] buf;
1971 }
1972 
1974 {
1975  NS_LOG_FUNCTION (this << &start);
1976  Buffer::Iterator i = start;
1977 
1978  SetType (i.ReadU8 ());
1979  uint8_t length = i.ReadU8 ();
1980  SetLength (length);
1981  i.ReadU16 ();
1982  i.ReadU32 ();
1983 
1984  uint32_t len2 = (GetLength () - 1) * 8;
1985  uint8_t* buff = new uint8_t[len2];
1986  i.Read (buff, len2);
1987  m_packet = Create<Packet> (buff, len2);
1988  delete[] buff;
1989 
1990  return GetSerializedSize ();
1991 }
1992 
1993 } /* namespace ns3 */
1994 
double f(double x, void *params)
Definition: 80211b.c:70
a polymophic address class
Definition: address.h:91
uint8_t GetLength(void) const
Get the length of the underlying address.
Definition: address.cc:75
uint32_t CopyFrom(const uint8_t *buffer, uint8_t len)
Definition: address.cc:101
uint32_t CopyTo(uint8_t buffer[MAX_SIZE]) const
Copy the address bytes into a buffer.
Definition: address.cc:82
iterator in a Buffer instance
Definition: buffer.h:99
void Write(uint8_t const *buffer, uint32_t size)
Definition: buffer.cc:954
void WriteU32(uint32_t data)
Definition: buffer.cc:879
uint16_t ReadNtohU16(void)
Definition: buffer.h:946
uint16_t CalculateIpChecksum(uint16_t size)
Calculate the checksum.
Definition: buffer.cc:1134
void WriteU8(uint8_t data)
Definition: buffer.h:869
void Next(void)
go forward by one byte
Definition: buffer.h:845
void WriteU16(uint16_t data)
Definition: buffer.cc:871
uint16_t ReadU16(void)
Definition: buffer.h:1029
uint8_t ReadU8(void)
Definition: buffer.h:1021
void Read(uint8_t *buffer, uint32_t size)
Definition: buffer.cc:1124
void WriteHtonU16(uint16_t data)
Definition: buffer.h:905
void WriteHtonU32(uint32_t data)
Definition: buffer.h:924
uint32_t GetSize(void) const
Definition: buffer.cc:1159
uint32_t ReadU32(void)
Definition: buffer.cc:973
uint32_t ReadNtohU32(void)
Definition: buffer.h:970
automatically resized byte buffer
Definition: buffer.h:93
void AddAtStart(uint32_t start)
Definition: buffer.cc:309
Buffer::Iterator Begin(void) const
Definition: buffer.h:1069
Protocol header serialization and deserialization.
Definition: header.h:43
virtual uint32_t Deserialize(Buffer::Iterator start)=0
Deserialize the object from a buffer iterator.
ICMPv6 Error Destination Unreachable header.
void SetPacket(Ptr< Packet > p)
Set the incorrect packet.
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 information.
Ptr< Packet > m_packet
The incorrect Packet.
static TypeId GetTypeId()
Get the UID of this class.
virtual ~Icmpv6DestinationUnreachable()
Destructor.
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
ICMPv6 Echo message.
static TypeId GetTypeId()
Get the UID of this class.
void SetId(uint16_t id)
Set the ID of the packet.
uint16_t m_seq
Sequence number (to distinguish response).
Icmpv6Echo()
Default constructor.
virtual void Print(std::ostream &os) const
Print information.
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
uint16_t m_id
ID of the packet (to distinguish response between many ping program).
virtual ~Icmpv6Echo()
Destructor.
uint16_t GetId() const
Get the ID of the packet.
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
void SetSeq(uint16_t seq)
Set the sequence number.
uint16_t GetSeq() const
Get the sequence number.
virtual uint32_t GetSerializedSize() const
Get the serialized size.
ICMPv6 header.
Definition: icmpv6-header.h:39
uint8_t GetCode() const
Get the code field.
virtual uint32_t GetSerializedSize() const
Get the serialized size.
uint8_t GetType() const
Get the type field.
Icmpv6Header()
Constructor.
uint8_t m_code
The code.
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
uint16_t GetChecksum() const
Get the checksum.
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
static TypeId GetTypeId()
Get the UID of this class.
uint16_t m_checksum
The checksum.
void CalculatePseudoHeaderChecksum(Ipv6Address src, Ipv6Address dst, uint16_t length, uint8_t protocol)
Calculate pseudo header checksum for IPv6.
void SetCode(uint8_t code)
Set the code field.
virtual ~Icmpv6Header()
Destructor.
uint8_t m_type
The type.
void SetType(uint8_t type)
Set the type.
@ ICMPV6_ND_NEIGHBOR_ADVERTISEMENT
Definition: icmpv6-header.h:58
@ ICMPV6_ERROR_DESTINATION_UNREACHABLE
Definition: icmpv6-header.h:46
void SetChecksum(uint16_t checksum)
Set the checksum.
bool m_calcChecksum
Checksum enable or not.
virtual void Print(std::ostream &os) const
Print information.
ICMPv6 Neighbor Advertisement header.
virtual uint32_t GetSerializedSize() const
Get the serialized size.
bool GetFlagS() const
Get the S flag.
virtual void Print(std::ostream &os) const
Print information.
bool m_flagS
The O flag.
uint32_t m_reserved
The reserved value.
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
void SetFlagS(bool s)
Set the S flag.
void SetIpv6Target(Ipv6Address target)
Set the IPv6 target field.
void SetFlagR(bool r)
Set the R flag.
Ipv6Address GetIpv6Target() const
Get the IPv6 target field.
bool GetFlagR() const
Get the R flag.
bool GetFlagO() const
Get the O flag.
void SetFlagO(bool o)
Set the O flag.
Icmpv6NA()
Constructor.
bool m_flagR
The R flag.
void SetReserved(uint32_t reserved)
Set the reserved field.
static TypeId GetTypeId()
Get the UID of this class.
Ipv6Address m_target
The IPv6 target address.
virtual ~Icmpv6NA()
Destructor.
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
bool m_flagO
The M flag.
uint32_t GetReserved() const
Get the reserved field.
ICMPv6 Neighbor Solicitation header.
uint32_t m_reserved
The reserved value.
void SetIpv6Target(Ipv6Address target)
Set the IPv6 target field.
uint32_t GetReserved() const
Get the reserved field.
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
static TypeId GetTypeId()
Get the UID of this class.
Ipv6Address m_target
The IPv6 target address.
void SetReserved(uint32_t reserved)
Set the reserved field.
virtual uint32_t GetSerializedSize() const
Get the serialized size.
virtual ~Icmpv6NS()
Destructor.
Ipv6Address GetIpv6Target() const
Get the IPv6 target field.
virtual void Print(std::ostream &os) const
Print information.
Icmpv6NS()
Constructor.
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
ICMPv6 option header.
void SetType(uint8_t type)
Set the type of the option.
Icmpv6OptionHeader()
Constructor.
virtual ~Icmpv6OptionHeader()
Destructor.
uint8_t m_len
The length.
virtual void Print(std::ostream &os) const
Print 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.
static TypeId GetTypeId()
Get the UID of this class.
uint8_t GetType() const
Get the type of the option.
void SetLength(uint8_t len)
Set the length of the option.
virtual uint32_t GetSerializedSize() const
Get the serialized size.
uint8_t GetLength() const
Get the length of the option in 8 bytes unit.
ICMPv6 MTU option.
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
uint16_t m_reserved
The reserved value.
void SetReserved(uint16_t reserved)
Set the reserved field.
uint32_t GetMtu() const
Get the MTU.
static TypeId GetTypeId()
Get the UID of this class.
void SetMtu(uint32_t mtu)
Set the MTU.
virtual void Print(std::ostream &os) const
Print information.
virtual ~Icmpv6OptionMtu()
Destructor.
uint32_t m_mtu
The MTU value.
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
Icmpv6OptionMtu()
Constructor.
uint16_t GetReserved() const
Get the reserved field.
virtual uint32_t GetSerializedSize() const
Get the serialized size.
ICMPv6 Option Prefix Information.
uint32_t GetValidTime() const
Get the valid time of the information.
uint8_t m_prefixLength
The length of the prefix.
void SetReserved(uint32_t reserved)
Set the reserved field (normally it will be 0x00000000).
virtual ~Icmpv6OptionPrefixInformation()
Destructor.
void SetValidTime(uint32_t validTime)
Set the valid time of the information.
void SetPrefix(Ipv6Address prefix)
Set the IPv6 prefix.
virtual void Print(std::ostream &os) const
Print information.
Ipv6Address GetPrefix() const
Get the IPv6 prefix.
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
void SetFlags(uint8_t flags)
Set the flags.
void SetPrefixLength(uint8_t prefixLength)
Set the prefix length.
Ipv6Address m_prefix
The prefix value.
uint32_t m_reserved
The reserved field.
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
uint8_t GetPrefixLength() const
Get the prefix length.
void SetPreferredTime(uint32_t preferredTime)
Set the preferred time of the information.
virtual uint32_t GetSerializedSize() const
Get the serialized size.
uint32_t m_preferredTime
The preferred time.
uint8_t GetFlags() const
Get the flags.
uint32_t GetReserved() const
Get the reserved field.
uint32_t m_validTime
The valid time.
static TypeId GetTypeId()
Get the UID of this class.
uint32_t GetPreferredTime() const
Get the preferred time of the information.
ICMPv6 redirected option.
Icmpv6OptionRedirected()
Constructor.
virtual uint32_t GetSerializedSize() const
Get the serialized size.
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
Ptr< Packet > m_packet
The redirected packet.
virtual ~Icmpv6OptionRedirected()
Destructor.
static TypeId GetTypeId()
Get the UID of this class.
virtual void Print(std::ostream &os) const
Print information.
void SetPacket(Ptr< Packet > packet)
Set the redirected packet.
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
ICMPv6 Error Parameter Error header.
uint32_t m_ptr
The pointer field.
virtual ~Icmpv6ParameterError()
Destructor.
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
virtual void Print(std::ostream &os) const
Print information.
void SetPacket(Ptr< Packet > p)
Set the incorrect packet.
static TypeId GetTypeId()
Get the UID of this class.
void SetPtr(uint32_t ptr)
Set the pointer field.
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
Ptr< Packet > m_packet
The incorrect packet.
virtual uint32_t GetSerializedSize() const
Get the serialized size.
uint32_t GetPtr() const
Get the pointer field.
Icmpv6ParameterError()
Constructor.
ICMPv6 Router Advertisement header.
Icmpv6RA()
Constructor.
void SetLifeTime(uint16_t l)
Set the node Life time (Neighbor Discovery).
NS_DEPRECATED_3_34 void SetFlags(uint8_t f)
Setflags.
bool m_flagM
The M flag.
uint32_t GetRetransmissionTime() const
Get the node Retransmission time (Neighbor Discovery).
NS_DEPRECATED_3_34 uint8_t GetFlags() const
Getflags.
bool m_flagO
The O flag.
void SetFlagH(bool h)
Set the H flag.
void SetRetransmissionTime(uint32_t r)
Set the node Retransmission time (Neighbor Discovery).
void SetCurHopLimit(uint8_t m)
Set the IPv6 maximum number of jumps.
void SetFlagO(bool o)
Set the O flag.
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
void SetFlagM(bool m)
Set the M flag.
void SetReachableTime(uint32_t r)
Set the node Reachable time (Neighbor Discovery).
static TypeId GetTypeId()
Get the UID of this class.
uint32_t m_RetransmissionTimer
The retransmission timer.
uint16_t GetLifeTime() const
Get the node Life time (Neighbor Discovery).
uint32_t GetReachableTime() const
Get the node Reachable time (Neighbor Discovery).
uint8_t GetCurHopLimit() const
Get the IPv6 maximum number of jumps.
bool GetFlagO() const
Get the O flag.
uint16_t m_LifeTime
The lifetime value.
virtual uint32_t GetSerializedSize() const
Get the serialized size.
bool GetFlagM() const
Get the M flag.
uint8_t m_curHopLimit
The max jumps.
virtual ~Icmpv6RA()
Destructor.
uint32_t m_ReachableTime
The reachable time value.
bool m_flagH
The H flag.
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
virtual void Print(std::ostream &os) const
Print information.
bool GetFlagH() const
Get the H flag.
ICMPv6 Router Solicitation header.
void SetReserved(uint32_t reserved)
Set the reserved field.
uint32_t GetReserved() const
Get the reserved field.
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
virtual uint32_t GetSerializedSize() const
Get the serialized size.
uint32_t m_reserved
The reserved value.
static TypeId GetTypeId()
Get the UID of this class.
virtual ~Icmpv6RS()
Destructor.
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
virtual void Print(std::ostream &os) const
Print information.
Icmpv6RS()
Constructor.
ICMPv6 Redirection header.
Ipv6Address m_target
IPv6 target address.
Ipv6Address GetTarget() const
Get the IPv6 target address.
Ipv6Address m_destination
IPv6 destination address.
uint32_t GetReserved() const
Get the reserved field.
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
Icmpv6Redirection()
Constructor.
virtual ~Icmpv6Redirection()
Destructor.
void SetDestination(Ipv6Address destination)
Set the IPv6 destination address.
void SetReserved(uint32_t reserved)
Set the reserved field.
Ipv6Address GetDestination() const
Get the IPv6 destination address.
virtual uint32_t GetSerializedSize() const
Get the serialized size.
void SetTarget(Ipv6Address target)
Set the IPv6 target address.
virtual void Print(std::ostream &os) const
Print information.
static TypeId GetTypeId()
Get the UID of this class.
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
uint32_t m_reserved
Reserved value.
ICMPv6 Error Time Exceeded header.
void SetPacket(Ptr< Packet > p)
Set the incorrect packet.
Icmpv6TimeExceeded()
Constructor.
static TypeId GetTypeId()
Get the UID of this class.
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.
virtual ~Icmpv6TimeExceeded()
Destructor.
Ptr< Packet > m_packet
The incorrect packet.
virtual uint32_t GetSerializedSize() const
Get the serialized size.
ICMPv6 Error Too Big header.
static TypeId GetTypeId()
Get the UID of this class.
void SetMtu(uint32_t mtu)
Set the MTU.
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
Ptr< Packet > m_packet
the incorrect packet.
Icmpv6TooBig()
Constructor.
virtual uint32_t GetSerializedSize() const
Get the serialized size.
virtual void Print(std::ostream &os) const
Print information.
void SetPacket(Ptr< Packet > p)
Set the incorrect packet.
virtual ~Icmpv6TooBig()
Destructor.
uint32_t m_mtu
The MTU value.
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
uint32_t GetMtu() const
Get the MTU field.
Describes an IPv6 address.
Definition: ipv6-address.h:50
void GetBytes(uint8_t buf[16]) const
Get the bytes corresponding to the address.
void Serialize(uint8_t buf[16]) const
Serialize this address to a 16-byte buffer.
void Set(char const *address)
Sets an Ipv6Address by parsing the input C-string.
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
Copy the packet contents to a byte buffer.
Definition: packet.cc:378
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Definition: packet.cc:121
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:856
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
#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
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
Every class exported by the ns3 library is enclosed in the ns3 namespace.
mac
Definition: third.py:99
def start()
Definition: core.py:1853