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);
269  i.WriteHtonU32 (m_reserved);
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  SetFlags (0);
507  SetFlagM (0);
508  SetFlagO (0);
509  SetFlagH (0);
510  SetCurHopLimit (0);
511  SetLifeTime (0);
512  SetRetransmissionTime (0);
513  SetReachableTime (0);
514 }
515 
517 {
518  NS_LOG_FUNCTION (this);
519 }
520 
521 void Icmpv6RA::SetCurHopLimit (uint8_t m)
522 {
523  NS_LOG_FUNCTION (this << static_cast<uint32_t> (m));
524  m_curHopLimit = m;
525 }
526 
527 uint8_t Icmpv6RA::GetCurHopLimit () const
528 {
529  NS_LOG_FUNCTION (this);
530  return m_curHopLimit;
531 }
532 
533 uint16_t Icmpv6RA::GetLifeTime () const
534 {
535  NS_LOG_FUNCTION (this);
536  return m_LifeTime;
537 }
538 
539 uint32_t Icmpv6RA::GetReachableTime () const
540 {
541  NS_LOG_FUNCTION (this);
542  return m_ReachableTime;
543 }
544 
546 {
547  NS_LOG_FUNCTION (this);
548  return m_RetransmissionTimer;
549 }
550 
551 void Icmpv6RA::SetLifeTime (uint16_t l)
552 {
553  NS_LOG_FUNCTION (this << l);
554  m_LifeTime = l;
555 }
556 
557 void Icmpv6RA::SetReachableTime (uint32_t r)
558 {
559  NS_LOG_FUNCTION (this << r);
560  m_ReachableTime = r;
561 }
562 
564 {
565  NS_LOG_FUNCTION (this << r);
566  m_RetransmissionTimer = r;
567 }
568 
569 bool Icmpv6RA::GetFlagM () const
570 {
571  NS_LOG_FUNCTION (this);
572  return m_flagM;
573 }
574 
575 void Icmpv6RA::SetFlagM (bool m)
576 {
577  NS_LOG_FUNCTION (this << m);
578  m_flagM = m;
579 }
580 
581 bool Icmpv6RA::GetFlagO () const
582 {
583  NS_LOG_FUNCTION (this);
584  return m_flagO;
585 }
586 
587 void Icmpv6RA::SetFlagO (bool o)
588 {
589  NS_LOG_FUNCTION (this << o);
590  m_flagO = o;
591 }
592 
593 bool Icmpv6RA::GetFlagH () const
594 {
595  NS_LOG_FUNCTION (this);
596  return m_flagH;
597 }
598 
599 void Icmpv6RA::SetFlagH (bool h)
600 {
601  NS_LOG_FUNCTION (this << h);
602  m_flagH = h;
603 }
604 
605 uint8_t Icmpv6RA::GetFlags () const
606 {
607  NS_LOG_FUNCTION (this);
608  return m_flags;
609 }
610 
611 void Icmpv6RA::SetFlags (uint8_t f)
612 {
613  NS_LOG_FUNCTION (this << static_cast<uint32_t> (f));
614  m_flags = f;
615 }
616 
617 void Icmpv6RA::Print (std::ostream& os) const
618 {
619  NS_LOG_FUNCTION (this << &os);
620  os << "( type = " << (uint32_t)GetType () << " (RA) code = " << (uint32_t)GetCode () << " checksum = " << (uint32_t)GetChecksum () << ")";
621 }
622 
624 {
625  NS_LOG_FUNCTION (this);
626  return 16;
627 }
628 
630 {
631  NS_LOG_FUNCTION (this << &start);
632  uint16_t checksum = 0;
634  uint8_t flags = 0;
635 
636  i.WriteU8 (GetType ());
637  i.WriteU8 (GetCode ());
638  i.WriteHtonU16 (0);
639  i.WriteU8 (m_curHopLimit);
640 
641  if (m_flagM)
642  {
643  flags |= (uint8_t)(1<< 7);
644  }
645 
646  if (m_flagO)
647  {
648  flags |= (uint8_t)(1<< 6);
649  }
650 
651  if (m_flagH)
652  {
653  flags |= (uint8_t)(1<< 5);
654  }
655  i.WriteU8 (flags);
656  i.WriteHtonU16 (GetLifeTime ());
657  i.WriteHtonU32 (GetReachableTime ());
658  i.WriteHtonU32 (GetRetransmissionTime ());
659 
660  i = start;
661  checksum = i.CalculateIpChecksum (i.GetSize (), GetChecksum ());
662 
663  i = start;
664  i.Next (2);
665  i.WriteU16 (checksum);
666 }
667 
669 {
670  NS_LOG_FUNCTION (this << &start);
672 
673  SetType (i.ReadU8 ());
674  SetCode (i.ReadU8 ());
675  m_checksum = i.ReadU16 ();
676  SetCurHopLimit (i.ReadU8 ());
677  m_flags = i.ReadU8 ();
678  m_flagM = false;
679  m_flagO = false;
680  m_flagH = false;
681 
682  if (m_flags & (1 << 7))
683  {
684  m_flagM = true;
685  }
686 
687  if (m_flags & (1 << 6))
688  {
689  m_flagO = true;
690  }
691 
692  if (m_flags & (1 << 5))
693  {
694  m_flagH = true;
695  }
696  SetLifeTime (i.ReadNtohU16 ());
697  SetReachableTime (i.ReadNtohU32 ());
698  SetRetransmissionTime (i.ReadNtohU32 ());
699 
700  return GetSerializedSize ();
701 }
702 
704 
706 {
707  static TypeId tid = TypeId ("ns3::Icmpv6RS")
709  .SetGroupName ("Internet")
710  .AddConstructor<Icmpv6RS> ()
711  ;
712  return tid;
713 }
714 
716 {
717  NS_LOG_FUNCTION (this);
718  return GetTypeId ();
719 }
720 
722 {
723  NS_LOG_FUNCTION (this);
725  SetCode (0);
726  SetReserved (0);
727 }
728 
730 {
731  NS_LOG_FUNCTION (this);
732 }
733 
734 uint32_t Icmpv6RS::GetReserved () const
735 {
736  NS_LOG_FUNCTION (this);
737  return m_reserved;
738 }
739 
740 void Icmpv6RS::SetReserved (uint32_t reserved)
741 {
742  NS_LOG_FUNCTION (this << reserved);
743  m_reserved = reserved;
744 }
745 
746 void Icmpv6RS::Print (std::ostream& os) const
747 {
748  NS_LOG_FUNCTION (this << &os);
749  os << "( type = " << (uint32_t)GetType () << " (RS) code = " << (uint32_t)GetCode () << " checksum = " << (uint32_t)GetChecksum () << ")";
750 }
751 
753 {
754  NS_LOG_FUNCTION (this);
755  return 8;
756 }
757 
759 {
760  NS_LOG_FUNCTION (this << &start);
762  uint16_t checksum = 0;
764 
765  i.WriteU8 (GetType ());
766  i.WriteU8 (GetCode ());
767  i.WriteU16 (0);
768  i.WriteHtonU32 (m_reserved);
769 
770  if (m_calcChecksum)
771  {
772  i = start;
773  checksum = i.CalculateIpChecksum (i.GetSize (), GetChecksum ());
774 
775  i = start;
776  i.Next (2);
777  i.WriteU16 (checksum);
778  }
779 }
780 
782 {
783  NS_LOG_FUNCTION (this << &start);
785 
786  SetType (i.ReadU8 ());
787  SetCode (i.ReadU8 ());
788  m_checksum = i.ReadU16 ();
789  m_reserved = i.ReadNtohU32 ();
790 
791  return GetSerializedSize ();
792 }
793 
795 
797 {
798  static TypeId tid = TypeId ("ns3::Icmpv6Redirection")
800  .SetGroupName ("Internet")
801  .AddConstructor<Icmpv6Redirection> ()
802  ;
803  return tid;
804 }
805 
807 {
808  NS_LOG_FUNCTION (this);
809  return GetTypeId ();
810 }
811 
813  : m_target (Ipv6Address ("")),
814  m_destination (Ipv6Address ("")),
815  m_reserved (0)
816 {
817  NS_LOG_FUNCTION (this);
819  SetCode (0);
820  m_checksum = 0;
821 }
822 
824 {
825  NS_LOG_FUNCTION (this);
826 }
827 
828 void Icmpv6Redirection::SetReserved (uint32_t reserved)
829 {
830  NS_LOG_FUNCTION (this << reserved);
831  m_reserved = reserved;
832 }
833 
835 {
836  NS_LOG_FUNCTION (this);
837  return m_reserved;
838 }
839 
841 {
842  NS_LOG_FUNCTION (this);
843  return m_target;
844 }
845 
847 {
848  NS_LOG_FUNCTION (this << target);
849  m_target = target;
850 }
851 
853 {
854  NS_LOG_FUNCTION (this);
855  return m_destination;
856 }
857 
859 {
860  NS_LOG_FUNCTION (this << destination);
861  m_destination = destination;
862 }
863 
864 void Icmpv6Redirection::Print (std::ostream& os) const
865 {
866  NS_LOG_FUNCTION (this << &os);
867  os << "( type = " << (uint32_t)GetType () << " (Redirection) code = " << (uint32_t)GetCode () << " checksum = " << (uint32_t)GetChecksum () << " target = " << m_target << " destination = " << m_destination << ")";
868 }
869 
871 {
872  NS_LOG_FUNCTION (this);
873  return 40;
874 }
875 
877 {
878  NS_LOG_FUNCTION (this << &start);
879  uint8_t buff[16];
880  uint16_t checksum = 0;
882 
883  i.WriteU8 (GetType ());
884  i.WriteU8 (GetCode ());
885  i.WriteU16 (checksum);
886  i.WriteU32 (m_reserved);
887 
888  m_target.Serialize (buff);
889  i.Write (buff, 16);
890 
891  m_destination.Serialize (buff);
892  i.Write (buff, 16);
893 
894  if (m_calcChecksum)
895  {
896  i = start;
897  checksum = i.CalculateIpChecksum (i.GetSize (), GetChecksum ());
898 
899  i = start;
900  i.Next (2);
901  i.WriteU16 (checksum);
902  }
903 }
904 
906 {
907  NS_LOG_FUNCTION (this << &start);
908  uint8_t buff[16];
910 
911  SetType (i.ReadU8 ());
912  SetCode (i.ReadU8 ());
913  m_checksum = i.ReadU16 ();
914  SetReserved (i.ReadU32 ());
915 
916  i.Read (buff, 16);
917  m_target.Set (buff);
918 
919  i.Read (buff, 16);
920  m_destination.Set (buff);
921 
922  return GetSerializedSize ();
923 }
924 
926 
928 {
929  static TypeId tid = TypeId ("ns3::Icmpv6Echo")
931  .SetGroupName ("Internet")
932  .AddConstructor<Icmpv6Echo> ()
933  ;
934  return tid;
935 }
936 
938 {
939  NS_LOG_FUNCTION (this);
940  return GetTypeId ();
941 }
942 
944 {
945  NS_LOG_FUNCTION (this);
947  SetCode (0);
948  m_checksum = 0;
949  SetId (0);
950  SetSeq (0);
951 }
952 
954 {
955  NS_LOG_FUNCTION (this << request);
957  SetCode (0);
958  m_checksum = 0;
959  SetId (0);
960  SetSeq (0);
961 }
962 
964 {
965  NS_LOG_FUNCTION (this);
966 }
967 
968 uint16_t Icmpv6Echo::GetId () const
969 {
970  NS_LOG_FUNCTION (this);
971  return m_id;
972 }
973 
974 void Icmpv6Echo::SetId (uint16_t id)
975 {
976  NS_LOG_FUNCTION (this << id);
977  m_id = id;
978 }
979 
980 uint16_t Icmpv6Echo::GetSeq () const
981 {
982  NS_LOG_FUNCTION (this);
983  return m_seq;
984 }
985 
986 void Icmpv6Echo::SetSeq (uint16_t seq)
987 {
988  NS_LOG_FUNCTION (this << seq);
989  m_seq = seq;
990 }
991 
992 void Icmpv6Echo::Print (std::ostream& os) const
993 {
994  NS_LOG_FUNCTION (this << &os);
995  os << "( type = " << (GetType () == 128 ? "128 (Request)" : "129 (Reply)") <<
996  " code = " << (uint32_t)GetCode () <<
997  " checksum = " << (uint32_t)GetChecksum () << ")";
998 }
999 
1001 {
1002  NS_LOG_FUNCTION (this);
1003  return 8;
1004 }
1005 
1007 {
1008  NS_LOG_FUNCTION (this << &start);
1009  uint16_t checksum = 0;
1010  Buffer::Iterator i = start;
1011 
1012  i.WriteU8 (GetType ());
1013  i.WriteU8 (GetCode ());
1014  i.WriteHtonU16 (0);
1015 
1016  i.WriteHtonU16 (m_id);
1017  i.WriteHtonU16 (m_seq);
1018 
1019  if (m_calcChecksum)
1020  {
1021  i = start;
1022  checksum = i.CalculateIpChecksum (i.GetSize (), GetChecksum ());
1023  i = start;
1024  i.Next (2);
1025  i.WriteU16 (checksum);
1026  }
1027 }
1028 
1030 {
1031  NS_LOG_FUNCTION (this << &start);
1032  Buffer::Iterator i = start;
1033 
1034  SetType (i.ReadU8 ());
1035  SetCode (i.ReadU8 ());
1036  m_checksum = i.ReadU16 ();
1037 
1038  m_id = i.ReadNtohU16 ();
1039  m_seq = i.ReadNtohU16 ();
1040  return GetSerializedSize ();
1041 }
1042 
1044 
1046 {
1047  static TypeId tid = TypeId ("ns3::Icmpv6DestinationUnreachable")
1048  .SetParent<Icmpv6Header> ()
1049  .SetGroupName ("Internet")
1050  .AddConstructor<Icmpv6DestinationUnreachable> ()
1051  ;
1052  return tid;
1053 }
1054 
1056 {
1057  NS_LOG_FUNCTION (this);
1058  return GetTypeId ();
1059 }
1060 
1062  : m_packet (0)
1063 {
1064  NS_LOG_FUNCTION (this);
1066 }
1067 
1069 {
1070  NS_LOG_FUNCTION (this);
1071 }
1072 
1074 {
1075  NS_LOG_FUNCTION (this);
1076  return m_packet;
1077 }
1078 
1080 {
1081  NS_LOG_FUNCTION (this << *p);
1082  NS_ASSERT (p->GetSize () <= 1280);
1083  m_packet = p;
1084 }
1085 
1086 void Icmpv6DestinationUnreachable::Print (std::ostream& os) const
1087 {
1088  NS_LOG_FUNCTION (this << &os);
1089  os << "( type = " << (uint32_t)GetType () << " (Destination Unreachable) code = " << (uint32_t)GetCode () << " checksum = " << (uint32_t)GetChecksum () << ")";
1090 }
1091 
1093 {
1094  NS_LOG_FUNCTION (this);
1095  return 8 + m_packet->GetSize ();
1096 }
1097 
1099 {
1100  NS_LOG_FUNCTION (this << &start);
1101  uint16_t checksum = 0;
1102  Buffer::Iterator i = start;
1103 
1104  i.WriteU8 (GetType ());
1105  i.WriteU8 (GetCode ());
1106  i.WriteHtonU16 (0);
1107  i.WriteHtonU32 (0);
1108 
1109  uint32_t size = m_packet->GetSize ();
1110  uint8_t *buf = new uint8_t[size];
1111  m_packet->CopyData (buf, size);
1112  i.Write (buf, size);
1113  delete[] buf;
1114 
1115  i = start;
1116  checksum = i.CalculateIpChecksum (i.GetSize (), GetChecksum ());
1117 
1118  i = start;
1119  i.Next (2);
1120  i.WriteU16 (checksum);
1121 }
1122 
1124 {
1125  NS_LOG_FUNCTION (this << &start);
1126  uint16_t length = start.GetRemainingSize () - 8;
1127  uint8_t* data = new uint8_t[length];
1128  Buffer::Iterator i = start;
1129 
1130  SetType (i.ReadU8 ());
1131  SetCode (i.ReadU8 ());
1132  m_checksum = i.ReadU16 ();
1133  i.ReadNtohU32 ();
1134  i.Read (data, length);
1135  m_packet = Create<Packet> (data, length);
1136 
1137  delete[] data;
1138  return GetSerializedSize ();
1139 }
1140 
1142 
1144 {
1145  static TypeId tid = TypeId ("ns3::Icmpv6TooBig")
1146  .SetParent<Icmpv6Header> ()
1147  .SetGroupName ("Internet")
1148  .AddConstructor<Icmpv6TooBig> ()
1149  ;
1150  return tid;
1151 }
1152 
1154 {
1155  NS_LOG_FUNCTION (this);
1156  return GetTypeId ();
1157 }
1158 
1160  : m_packet (0),
1161  m_mtu (0)
1162 {
1163  NS_LOG_FUNCTION (this);
1165 }
1166 
1168 {
1169  NS_LOG_FUNCTION (this);
1170 }
1171 
1173 {
1174  NS_LOG_FUNCTION (this);
1175  return m_packet;
1176 }
1177 
1179 {
1180  NS_LOG_FUNCTION (this << *p);
1181  NS_ASSERT (p->GetSize () <= 1280);
1182  m_packet = p;
1183 }
1184 
1185 uint32_t Icmpv6TooBig::GetMtu () const
1186 {
1187  NS_LOG_FUNCTION (this);
1188  return m_mtu;
1189 }
1190 
1191 void Icmpv6TooBig::SetMtu (uint32_t mtu)
1192 {
1193  NS_LOG_FUNCTION (this << mtu);
1194  m_mtu = mtu;
1195 }
1196 
1197 void Icmpv6TooBig::Print (std::ostream& os) const
1198 {
1199  NS_LOG_FUNCTION (this << &os);
1200  os << "( type = " << (uint32_t)GetType () << " (Too Big) code = " << (uint32_t)GetCode () << " checksum = " << (uint32_t)GetChecksum () << " mtu = " << (uint32_t)GetMtu () << ")";
1201 }
1202 
1204 {
1205  NS_LOG_FUNCTION (this);
1206  return 8 + m_packet->GetSize ();
1207 }
1208 
1210 {
1211  NS_LOG_FUNCTION (this << &start);
1212  uint16_t checksum = 0;
1213  Buffer::Iterator i = start;
1214 
1215  i.WriteU8 (GetType ());
1216  i.WriteU8 (GetCode ());
1217  i.WriteHtonU16 (0);
1218  i.WriteHtonU32 (GetMtu ());
1219 
1220  uint32_t size = m_packet->GetSize ();
1221  uint8_t *buf = new uint8_t[size];
1222  m_packet->CopyData (buf, size);
1223  i.Write (buf, size);
1224  delete[] buf;
1225 
1226  i = start;
1227  checksum = i.CalculateIpChecksum (i.GetSize (), GetChecksum ());
1228 
1229  i = start;
1230  i.Next (2);
1231  i.WriteU16 (checksum);
1232 }
1233 
1235 {
1236  NS_LOG_FUNCTION (this << &start);
1237  uint16_t length = start.GetRemainingSize () - 8;
1238  uint8_t* data = new uint8_t[length];
1239  Buffer::Iterator i = start;
1240 
1241  SetType (i.ReadU8 ());
1242  SetCode (i.ReadU8 ());
1243  m_checksum = i.ReadU16 ();
1244  SetMtu (i.ReadNtohU32 ());
1245  i.Read (data, length);
1246  m_packet = Create<Packet> (data, length);
1247 
1248  delete[] data;
1249  return GetSerializedSize ();
1250 }
1251 
1253 
1255 {
1256  static TypeId tid = TypeId ("ns3::Icmpv6TimeExceeded")
1257  .SetParent<Icmpv6Header> ()
1258  .SetGroupName ("Internet")
1259  .AddConstructor<Icmpv6TimeExceeded> ()
1260  ;
1261  return tid;
1262 }
1263 
1265 {
1266  NS_LOG_FUNCTION (this);
1267  return GetTypeId ();
1268 }
1269 
1271  : m_packet (0)
1272 {
1273  NS_LOG_FUNCTION (this);
1275 }
1276 
1278 {
1279  NS_LOG_FUNCTION (this);
1280 }
1281 
1283 {
1284  NS_LOG_FUNCTION (this);
1285  return m_packet;
1286 }
1287 
1289 {
1290  NS_LOG_FUNCTION (this << *p);
1291  NS_ASSERT (p->GetSize () <= 1280);
1292  m_packet = p;
1293 }
1294 
1295 void Icmpv6TimeExceeded::Print (std::ostream& os) const
1296 {
1297  NS_LOG_FUNCTION (this << &os);
1298  os << "( type = " << (uint32_t)GetType () << " (Destination Unreachable) code = " << (uint32_t)GetCode () << " checksum = " << (uint32_t)GetChecksum () << ")";
1299 }
1300 
1302 {
1303  NS_LOG_FUNCTION (this);
1304  return 8 + m_packet->GetSize ();
1305 }
1306 
1308 {
1309  NS_LOG_FUNCTION (this << &start);
1310 
1311  uint16_t checksum = 0;
1312  Buffer::Iterator i = start;
1313 
1314  i.WriteU8 (GetType ());
1315  i.WriteU8 (GetCode ());
1316  i.WriteHtonU16 (0);
1317  i.WriteHtonU32 (0);
1318 
1319  uint32_t size = m_packet->GetSize ();
1320  uint8_t *buf = new uint8_t[size];
1321  m_packet->CopyData (buf, size);
1322  i.Write (buf, size);
1323  delete[] buf;
1324 
1325  i = start;
1326  checksum = i.CalculateIpChecksum (i.GetSize (), GetChecksum ());
1327 
1328  i = start;
1329  i.Next (2);
1330  i.WriteU16 (checksum);
1331 }
1332 
1334 {
1335  NS_LOG_FUNCTION (this << &start);
1336 
1337  uint16_t length = start.GetRemainingSize () - 8;
1338  uint8_t* data = new uint8_t[length];
1339  Buffer::Iterator i = start;
1340 
1341  SetType (i.ReadU8 ());
1342  SetCode (i.ReadU8 ());
1343  m_checksum = i.ReadU16 ();
1344  i.ReadNtohU32 ();
1345  i.Read (data, length);
1346  m_packet = Create<Packet> (data, length);
1347 
1348  delete[] data;
1349  return GetSerializedSize ();
1350 }
1351 
1353 
1355 {
1356  static TypeId tid = TypeId ("ns3::Icmpv6ParameterError")
1357  .SetParent<Icmpv6Header> ()
1358  .SetGroupName ("Internet")
1359  .AddConstructor<Icmpv6ParameterError> ()
1360  ;
1361  return tid;
1362 }
1363 
1365 {
1366  NS_LOG_FUNCTION (this);
1367  return GetTypeId ();
1368 }
1369 
1371  : m_packet (0),
1372  m_ptr (0)
1373 {
1374  NS_LOG_FUNCTION (this);
1376 }
1377 
1379 {
1380  NS_LOG_FUNCTION (this);
1381 }
1382 
1384 {
1385  NS_LOG_FUNCTION (this);
1386  return m_packet;
1387 }
1388 
1390 {
1391  NS_LOG_FUNCTION (this << *p);
1392  NS_ASSERT (p->GetSize () <= 1280);
1393  m_packet = p;
1394 }
1395 
1397 {
1398  NS_LOG_FUNCTION (this);
1399  return m_ptr;
1400 }
1401 
1402 void Icmpv6ParameterError::SetPtr (uint32_t ptr)
1403 {
1404  NS_LOG_FUNCTION (this << ptr);
1405  m_ptr = ptr;
1406 }
1407 
1408 void Icmpv6ParameterError::Print (std::ostream& os) const
1409 {
1410  NS_LOG_FUNCTION (this << &os);
1411  os << "( type = " << (uint32_t)GetType () << " (Destination Unreachable) code = " << (uint32_t)GetCode () << " checksum = " << (uint32_t)GetChecksum () << " ptr = " << (uint32_t)GetPtr () << ")";
1412 }
1413 
1415 {
1416  NS_LOG_FUNCTION (this);
1417  return 8 + m_packet->GetSize ();
1418 }
1419 
1421 {
1422  NS_LOG_FUNCTION (this << &start);
1423  uint16_t checksum = 0;
1424  Buffer::Iterator i = start;
1425 
1426  i.WriteU8 (GetType ());
1427  i.WriteU8 (GetCode ());
1428  i.WriteHtonU16 (0);
1429  i.WriteHtonU32 (GetPtr ());
1430 
1431  uint32_t size = m_packet->GetSize ();
1432  uint8_t *buf = new uint8_t[size];
1433  m_packet->CopyData (buf, size);
1434  i.Write (buf, size);
1435  delete[] buf;
1436 
1437  i = start;
1438  checksum = i.CalculateIpChecksum (i.GetSize (), GetChecksum ());
1439 
1440  i = start;
1441  i.Next (2);
1442  i.WriteU16 (checksum);
1443 }
1444 
1446 {
1447  NS_LOG_FUNCTION (this << &start);
1448  uint16_t length = start.GetRemainingSize () - 8;
1449  uint8_t* data = new uint8_t[length];
1450  Buffer::Iterator i = start;
1451 
1452  SetType (i.ReadU8 ());
1453  SetCode (i.ReadU8 ());
1454  m_checksum = i.ReadU16 ();
1455  SetPtr (i.ReadNtohU32 ());
1456  i.Read (data, length);
1457  m_packet = Create<Packet> (data, length);
1458  delete[] data;
1459 
1460  return GetSerializedSize ();
1461 }
1462 
1464 
1466 {
1467  static TypeId tid = TypeId ("ns3::Icmpv6OptionHeader")
1468  .SetParent<Header> ()
1469  .SetGroupName ("Internet")
1470  .AddConstructor<Icmpv6OptionHeader> ()
1471  ;
1472  return tid;
1473 }
1474 
1476 {
1477  NS_LOG_FUNCTION (this);
1478  return GetTypeId ();
1479 }
1480 
1481 
1483 {
1484  NS_LOG_FUNCTION (this);
1486  m_type = 0;
1487  m_len = 0;
1488 }
1489 
1491 {
1492  NS_LOG_FUNCTION (this);
1493 }
1494 
1496 {
1498  return m_type;
1499 }
1500 
1501 void Icmpv6OptionHeader::SetType (uint8_t type)
1502 {
1503  NS_LOG_FUNCTION (this << static_cast<uint32_t> (type));
1504  m_type = type;
1505 }
1506 
1508 {
1509  NS_LOG_FUNCTION (this);
1510  return m_len;
1511 }
1512 
1514 {
1515  NS_LOG_FUNCTION (this << static_cast<uint32_t> (len));
1516  m_len = len;
1517 }
1518 
1519 void Icmpv6OptionHeader::Print (std::ostream& os) const
1520 {
1521  NS_LOG_FUNCTION (this << &os);
1522  os << "( type = " << (uint32_t)GetType () << " length = " << (uint32_t)GetLength () << ")";
1523 }
1524 
1526 {
1527  NS_LOG_FUNCTION (this);
1528  return m_len*8;
1529 }
1530 
1532 {
1533  NS_LOG_FUNCTION (this << &start);
1534  return GetSerializedSize ();
1535 }
1536 
1538 {
1539  NS_LOG_FUNCTION (this << &start);
1540 }
1541 
1543 
1545 {
1546  static TypeId tid = TypeId ("ns3::Icmpv6OptionMtu")
1548  .SetGroupName ("Internet")
1549  .AddConstructor<Icmpv6OptionMtu> ()
1550  ;
1551  return tid;
1552 }
1553 
1555 {
1556  NS_LOG_FUNCTION (this);
1557  return GetTypeId ();
1558 }
1559 
1561 {
1562  NS_LOG_FUNCTION (this);
1564  SetLength (1);
1565  SetReserved (0);
1566 }
1567 
1569  : m_mtu (mtu)
1570 {
1571  NS_LOG_FUNCTION (this << mtu);
1573  SetLength (1);
1574  SetReserved (0);
1575 }
1576 
1578 {
1579  NS_LOG_FUNCTION (this);
1580 }
1581 
1583 {
1584  NS_LOG_FUNCTION (this);
1585  return m_reserved;
1586 }
1587 
1588 void Icmpv6OptionMtu::SetReserved (uint16_t reserved)
1589 {
1590  NS_LOG_FUNCTION (this << reserved);
1591  m_reserved = reserved;
1592 }
1593 
1594 uint32_t Icmpv6OptionMtu::GetMtu () const
1595 {
1596  NS_LOG_FUNCTION (this);
1597  return m_mtu;
1598 }
1599 
1600 void Icmpv6OptionMtu::SetMtu (uint32_t mtu)
1601 {
1602  NS_LOG_FUNCTION (this << mtu);
1603  m_mtu = mtu;
1604 }
1605 
1606 void Icmpv6OptionMtu::Print (std::ostream& os) const
1607 {
1608  NS_LOG_FUNCTION (this << &os);
1609  os << "( type = " << (uint32_t)GetType () << " length = " << (uint32_t)GetLength () << " MTU = " << m_mtu << ")";
1610 }
1611 
1613 {
1614  NS_LOG_FUNCTION (this);
1615  return 8; /* m_len = 1 so the real size is multiple by 8 */
1616 }
1617 
1619 {
1620  NS_LOG_FUNCTION (this << &start);
1621  Buffer::Iterator i = start;
1622  i.WriteU8 (GetType ());
1623  i.WriteU8 (GetLength ());
1624  i.WriteHtonU16 (GetReserved ());
1625  i.WriteHtonU32 (GetMtu ());
1626 }
1627 
1629 {
1630  NS_LOG_FUNCTION (this << &start);
1631  Buffer::Iterator i = start;
1632  SetType (i.ReadU8 ());
1633  SetLength (i.ReadU8 ());
1634  SetReserved (i.ReadNtohU16 ());
1635  SetMtu (i.ReadNtohU32 ());
1636  return GetSerializedSize ();
1637 }
1638 
1640 
1642 {
1643  static TypeId tid = TypeId ("ns3::Icmpv6OptionPrefixInformation")
1645  .SetGroupName ("Internet")
1646  .AddConstructor<Icmpv6OptionPrefixInformation> ()
1647  ;
1648  return tid;
1649 }
1650 
1652 {
1653  NS_LOG_FUNCTION (this);
1654  return GetTypeId ();
1655 }
1656 
1658 {
1659  NS_LOG_FUNCTION (this);
1661  SetLength (4);
1662  SetPrefix (Ipv6Address ("::"));
1663  SetPrefixLength (0);
1664  SetValidTime (0);
1665  SetPreferredTime (0);
1666  SetFlags (0);
1667  SetReserved (0);
1668 }
1669 
1671 {
1672  NS_LOG_FUNCTION (this << prefix << static_cast<uint32_t> (prefixlen));
1674  SetLength (4);
1675  SetPrefix (prefix);
1676  SetPrefixLength (prefixlen);
1677  SetValidTime (0);
1678  SetPreferredTime (0);
1679  SetFlags (0);
1680  SetReserved (0);
1681 }
1682 
1684 {
1685  NS_LOG_FUNCTION (this);
1686 }
1687 
1689 {
1690  NS_LOG_FUNCTION (this);
1691  return m_prefixLength;
1692 }
1693 
1695 {
1696  NS_LOG_FUNCTION (this << static_cast<uint32_t> (prefixLength));
1697  NS_ASSERT (prefixLength <= 128);
1698  m_prefixLength = prefixLength;
1699 }
1700 
1702 {
1703  NS_LOG_FUNCTION (this);
1704  return m_flags;
1705 }
1706 
1708 {
1709  NS_LOG_FUNCTION (this);
1710  m_flags = flags;
1711 }
1712 
1714 {
1715  NS_LOG_FUNCTION (this);
1716  return m_validTime;
1717 }
1718 
1720 {
1721  NS_LOG_FUNCTION (this << validTime);
1722  m_validTime = validTime;
1723 }
1724 
1726 {
1727  NS_LOG_FUNCTION (this);
1728  return m_preferredTime;
1729 }
1730 
1732 {
1733  NS_LOG_FUNCTION (this << preferredTime);
1734  m_preferredTime = preferredTime;
1735 }
1736 
1738 {
1739  NS_LOG_FUNCTION (this);
1740  return m_preferredTime;
1741 }
1742 
1744 {
1745  NS_LOG_FUNCTION (this << reserved);
1746  m_reserved = reserved;
1747 }
1748 
1750 {
1751  NS_LOG_FUNCTION (this);
1752  return m_prefix;
1753 }
1754 
1756 {
1757  NS_LOG_FUNCTION (this << prefix);
1758  m_prefix = prefix;
1759 }
1760 
1761 void Icmpv6OptionPrefixInformation::Print (std::ostream& os) const
1762 {
1763  NS_LOG_FUNCTION (this << &os);
1764  os << "( type = " << (uint32_t)GetType () << " length = " << (uint32_t)GetLength () << " prefix " << m_prefix << ")";
1765 }
1766 
1768 {
1769  NS_LOG_FUNCTION (this);
1770  return 32;
1771 }
1772 
1774 {
1775  NS_LOG_FUNCTION (this << &start);
1776  Buffer::Iterator i = start;
1777  uint8_t buf[16];
1778 
1779  memset (buf, 0x00, sizeof (buf));
1780 
1781  i.WriteU8 (GetType ());
1782  i.WriteU8 (GetLength ());
1783  i.WriteU8 (m_prefixLength);
1784  i.WriteU8 (m_flags);
1785  i.WriteHtonU32 (m_validTime);
1786  i.WriteHtonU32 (m_preferredTime);
1788  m_prefix.GetBytes (buf);
1789  i.Write (buf, 16);
1790 }
1791 
1793 {
1794  NS_LOG_FUNCTION (this << &start);
1795  Buffer::Iterator i = start;
1796  uint8_t buf[16];
1797 
1798  SetType (i.ReadU8 ());
1799  SetLength (i.ReadU8 ());
1800  SetPrefixLength (i.ReadU8 ());
1801  SetFlags (i.ReadU8 ());
1802  SetValidTime (i.ReadNtohU32 ());
1803  SetPreferredTime (i.ReadNtohU32 ());
1804  SetReserved (i.ReadNtohU32 ());
1805  i.Read (buf, 16);
1806 
1807  Ipv6Address prefix (buf);
1808  SetPrefix (prefix);
1809 
1810  return GetSerializedSize ();
1811 }
1812 
1814 
1816 {
1817  static TypeId tid = TypeId ("ns3::Icmpv6OptionLinkLayerAddress")
1819  .SetGroupName ("Internet")
1820  .AddConstructor<Icmpv6OptionLinkLayerAddress> ()
1821  ;
1822  return tid;
1823 }
1824 
1826 {
1827  NS_LOG_FUNCTION (this);
1828  return GetTypeId ();
1829 }
1830 
1832 {
1833  NS_LOG_FUNCTION (this << source);
1835 }
1836 
1838 {
1839  NS_LOG_FUNCTION (this);
1841 }
1842 
1844 {
1845  NS_LOG_FUNCTION (this << source << addr);
1847  SetAddress (addr);
1848 
1849  uint8_t len = (2 + m_addr.GetLength ()) / 8;
1850  if ( (2 + m_addr.GetLength ()) % 8 )
1851  {
1852  len ++;
1853  }
1854  SetLength (len);
1855 }
1856 
1858 {
1859  NS_LOG_FUNCTION (this);
1860 }
1861 
1863 {
1864  NS_LOG_FUNCTION (this);
1865  return m_addr;
1866 }
1867 
1869 {
1870  NS_LOG_FUNCTION (this << addr);
1871  m_addr = addr;
1872 }
1873 
1874 void Icmpv6OptionLinkLayerAddress::Print (std::ostream& os) const
1875 {
1876  NS_LOG_FUNCTION (this << &os);
1877  os << "( type = " << (uint32_t)GetType () << " length = " << (uint32_t)GetLength () << " L2 Address = " << m_addr << ")";
1878 }
1879 
1881 {
1882  NS_LOG_FUNCTION (this);
1883  uint8_t nb = GetLength() * 8;
1884  return nb;
1885 }
1886 
1888 {
1889  NS_LOG_FUNCTION (this << &start);
1890  Buffer::Iterator i = start;
1891  uint8_t mac[32];
1892 
1893  i.WriteU8 (GetType ());
1894  i.WriteU8 (GetLength ());
1895  m_addr.CopyTo (mac);
1896  i.Write (mac, m_addr.GetLength ());
1897 
1898  uint8_t len = GetLength ()*8 - (2 + m_addr.GetLength ());
1899  for (uint8_t nb = 0; nb<len; nb++)
1900  {
1901  i.WriteU8 (0);
1902  }
1903 }
1904 
1906 {
1907  NS_LOG_FUNCTION (this << &start);
1908  Buffer::Iterator i = start;
1909  uint8_t mac[32];
1910 
1911  SetType (i.ReadU8 ());
1912  SetLength (i.ReadU8 ());
1913  // -fstrict-overflow sensitive, see bug 1868
1914  NS_ASSERT (GetLength () * 8 <= 32 + 2);
1915  i.Read (mac, (GetLength () * 8) - 2);
1916 
1917  m_addr.CopyFrom (mac, (GetLength () * 8) - 2);
1918 
1919  return GetSerializedSize ();
1920 }
1921 
1923 
1925 {
1926  static TypeId tid = TypeId ("ns3::Icmpv6OptionRedirected")
1928  .SetGroupName ("Internet")
1929  .AddConstructor<Icmpv6OptionRedirected> ()
1930  ;
1931  return tid;
1932 }
1933 
1935 {
1936  NS_LOG_FUNCTION (this);
1937  return GetTypeId ();
1938 }
1939 
1941  : m_packet (0)
1942 {
1943  NS_LOG_FUNCTION (this);
1945 }
1946 
1948 {
1949  NS_LOG_FUNCTION (this);
1950  m_packet = 0;
1951 }
1952 
1954 {
1955  NS_LOG_FUNCTION (this);
1956  return m_packet;
1957 }
1958 
1960 {
1961  NS_LOG_FUNCTION (this << *packet);
1962  NS_ASSERT (packet->GetSize () <= 1280);
1963  m_packet = packet;
1964  SetLength (1 + (m_packet->GetSize () / 8));
1965 }
1966 
1967 void Icmpv6OptionRedirected::Print (std::ostream& os) const
1968 {
1969  NS_LOG_FUNCTION (this << &os);
1970  os << "( type = " << (uint32_t)GetType () << " length = " << (uint32_t)GetLength () << ")";
1971 }
1972 
1974 {
1975  NS_LOG_FUNCTION (this);
1976  return 8 + m_packet->GetSize ();
1977 }
1978 
1980 {
1981  NS_LOG_FUNCTION (this << &start);
1982  Buffer::Iterator i = start;
1983 
1984  i.WriteU8 (GetType ());
1985  i.WriteU8 (GetLength ());
1986  // Reserved
1987  i.WriteU16 (0);
1988  i.WriteU32 (0);
1989 
1990  uint32_t size = m_packet->GetSize ();
1991  uint8_t *buf = new uint8_t[size];
1992  m_packet->CopyData (buf, size);
1993  i.Write (buf, size);
1994  delete[] buf;
1995 }
1996 
1998 {
1999  NS_LOG_FUNCTION (this << &start);
2000  Buffer::Iterator i = start;
2001 
2002  SetType (i.ReadU8 ());
2003  uint8_t length = i.ReadU8 ();
2004  SetLength (length);
2005  i.ReadU16 ();
2006  i.ReadU32 ();
2007 
2008  uint32_t len2 = (GetLength () - 1) * 8;
2009  uint8_t* buff = new uint8_t[len2];
2010  i.Read (buff, len2);
2011  m_packet = Create<Packet> (buff, len2);
2012  delete[] buff;
2013 
2014  return GetSerializedSize ();
2015 }
2016 
2017 } /* namespace ns3 */
2018 
uint16_t ReadU16(void)
Definition: buffer.h:1029
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:1136
virtual void Print(std::ostream &os) const
Print information.
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.
ICMPv6 redirected option.
uint16_t GetId() const
Get the ID of the packet.
void AddAtStart(uint32_t start)
Definition: buffer.cc:309
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
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:975
static TypeId GetTypeId()
Get the UID of this class.
virtual void Print(std::ostream &os) const
Print information.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
ICMPv6 Error Parameter Error header.
uint32_t GetReserved() const
Get the reserved field.
ICMPv6 Router Advertisement header.
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
ICMPv6 Neighbor Advertisement header.
static TypeId GetTypeId()
Get the UID of this class.
Ipv6Address GetPrefix() const
Get the IPv6 prefix.
virtual uint32_t GetSerializedSize() const
Get the serialized size.
virtual void Print(std::ostream &os) const
Print information.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
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.
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.
ICMPv6 Error Time Exceeded header.
Icmpv6TimeExceeded()
Constructor.
automatically resized byte buffer
Definition: buffer.h:92
def start()
Definition: core.py:1806
ICMPv6 Router Solicitation header.
virtual void Print(std::ostream &os) const
Print information.
ICMPv6 Neighbor Solicitation header.
uint8_t GetType() const
Get the type field.
void SetType(uint8_t type)
Set the type of the option.
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.
#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:202
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:831
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.
static TypeId GetTypeId()
Get the UID of this class.
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
virtual ~Icmpv6OptionHeader()
Destructor.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
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:970
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:90
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 information.
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.
ICMPv6 Error Destination Unreachable header.
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.
ICMPv6 header.
Definition: icmpv6-header.h:38
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.
ICMPv6 Option Prefix Information.
uint8_t data[writeSize]
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
uint32_t GetMtu() const
Get the MTU.
virtual uint32_t GetSerializedSize() const
Get the serialized size.
void WriteU16(uint16_t data)
Definition: buffer.cc:873
Ptr< Packet > m_packet
the incorrect packet.
virtual void Print(std::ostream &os) const
Print information.
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
mac
Definition: third.py:92
void WriteHtonU16(uint16_t data)
Definition: buffer.h:905
virtual void Print(std::ostream &os) const
Print information.
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
uint32_t GetPreferredTime() const
Get the preferred time of the information.
Icmpv6RS()
Constructor.
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
virtual void Print(std::ostream &os) const
Print information.
virtual void Print(std::ostream &os) const
Print information.
void Next(void)
go forward by one byte
Definition: buffer.h:845
ICMPv6 Redirection header.
Ptr< Packet > GetPacket() const
Get the incorrect packet.
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
uint32_t GetRemainingSize(void) const
Definition: buffer.cc:1168
bool GetFlagO() const
Get the O flag.
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 GetFlagO() const
Get the O flag.
virtual void Print(std::ostream &os) const
Print information.
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:1069
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 information.
double f(double x, void *params)
Definition: 80211b.c:70
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.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
void SetChecksum(uint16_t checksum)
Set the checksum.
void SetCode(uint8_t code)
Set the code field.
ICMPv6 MTU option.
uint8_t GetCode() const
Get the code field.
virtual ~Icmpv6OptionRedirected()
Destructor.
virtual void Print(std::ostream &os) const
Print information.
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.
virtual void Print(std::ostream &os) const
Print information.
void Read(uint8_t *buffer, uint32_t size)
Definition: buffer.cc:1126
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:924
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 information.
ICMPv6 Echo message.
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:49
virtual ~Icmpv6Header()
Destructor.
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
void WriteU8(uint8_t data)
Definition: buffer.h:869
Icmpv6TooBig()
Constructor.
virtual void Print(std::ostream &os) const
Print information.
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.
uint8_t ReadU8(void)
Definition: buffer.h:1021
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:956
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:378
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.
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:946
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
void WriteU32(uint32_t data)
Definition: buffer.cc:881
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.
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:1161
ICMPv6 Error Too Big header.
a unique identifier for an interface.
Definition: type-id.h:58
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)
Set the parent TypeId.
Definition: type-id.cc:915
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).
ICMPv6 option header.
void SetId(uint16_t id)
Set the ID of the packet.
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.