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
GetTypeId()36 TypeId Icmpv6Header::GetTypeId ()
37 {
38 static TypeId tid = TypeId ("ns3::Icmpv6Header")
39 .SetParent<Header> ()
40 .SetGroupName ("Internet")
41 .AddConstructor<Icmpv6Header> ()
42 ;
43 return tid;
44 }
45
GetInstanceTypeId() const46 TypeId Icmpv6Header::GetInstanceTypeId () const
47 {
48 NS_LOG_FUNCTION (this);
49 return GetTypeId ();
50 }
51
Icmpv6Header()52 Icmpv6Header::Icmpv6Header ()
53 : m_calcChecksum (true),
54 m_checksum (0),
55 m_type (0),
56 m_code (0)
57 {
58 NS_LOG_FUNCTION (this);
59 }
60
~Icmpv6Header()61 Icmpv6Header::~Icmpv6Header ()
62 {
63 NS_LOG_FUNCTION (this);
64 }
65
GetType() const66 uint8_t Icmpv6Header::GetType () const
67 {
68 NS_LOG_FUNCTION (this);
69 return m_type;
70 }
71
SetType(uint8_t type)72 void Icmpv6Header::SetType (uint8_t type)
73 {
74 NS_LOG_FUNCTION (this << static_cast<uint32_t> (type));
75 m_type = type;
76 }
77
GetCode() const78 uint8_t Icmpv6Header::GetCode () const
79 {
80 NS_LOG_FUNCTION (this);
81 return m_code;
82 }
83
SetCode(uint8_t code)84 void Icmpv6Header::SetCode (uint8_t code)
85 {
86 NS_LOG_FUNCTION (this << static_cast<uint32_t> (code));
87 m_code = code;
88 }
89
GetChecksum() const90 uint16_t Icmpv6Header::GetChecksum () const
91 {
92 NS_LOG_FUNCTION (this);
93 return m_checksum;
94 }
95
SetChecksum(uint16_t checksum)96 void Icmpv6Header::SetChecksum (uint16_t checksum)
97 {
98 NS_LOG_FUNCTION (this << checksum);
99 m_checksum = checksum;
100 }
101
Print(std::ostream & os) const102 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
GetSerializedSize() const108 uint32_t Icmpv6Header::GetSerializedSize () const
109 {
110 NS_LOG_FUNCTION (this);
111 return 4;
112 }
113
Deserialize(Buffer::Iterator start)114 uint32_t Icmpv6Header::Deserialize (Buffer::Iterator start)
115 {
116 NS_LOG_FUNCTION (this << &start);
117 Buffer::Iterator i = 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
Serialize(Buffer::Iterator start) const128 void Icmpv6Header::Serialize (Buffer::Iterator start) const
129 {
130 NS_LOG_FUNCTION (this << &start);
131 Buffer::Iterator i = 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
CalculatePseudoHeaderChecksum(Ipv6Address src,Ipv6Address dst,uint16_t length,uint8_t protocol)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
176 NS_OBJECT_ENSURE_REGISTERED (Icmpv6NS);
177
Icmpv6NS()178 Icmpv6NS::Icmpv6NS ()
179 {
180 NS_LOG_FUNCTION (this);
181 SetType (ICMPV6_ND_NEIGHBOR_SOLICITATION);
182 SetCode (0);
183 SetReserved (0);
184 m_checksum = 0;
185 }
186
GetTypeId()187 TypeId Icmpv6NS::GetTypeId ()
188 {
189 static TypeId tid = TypeId ("ns3::Icmpv6NS")
190 .SetParent<Icmpv6Header> ()
191 .SetGroupName ("Internet")
192 .AddConstructor<Icmpv6NS> ()
193 ;
194 return tid;
195 }
196
GetInstanceTypeId() const197 TypeId Icmpv6NS::GetInstanceTypeId () const
198 {
199 NS_LOG_FUNCTION (this);
200 return GetTypeId ();
201 }
202
Icmpv6NS(Ipv6Address target)203 Icmpv6NS::Icmpv6NS (Ipv6Address target)
204 {
205 NS_LOG_FUNCTION (this << target);
206 SetType (ICMPV6_ND_NEIGHBOR_SOLICITATION);
207 SetCode (0);
208 SetReserved (0);
209 SetIpv6Target (target);
210 m_checksum = 0;
211
212 /* test */
213 /*
214 m_reserved = 0xdeadbeef;
215 */
216 }
217
~Icmpv6NS()218 Icmpv6NS::~Icmpv6NS ()
219 {
220 NS_LOG_FUNCTION (this);
221 }
222
GetReserved() const223 uint32_t Icmpv6NS::GetReserved () const
224 {
225 NS_LOG_FUNCTION (this);
226 return m_reserved;
227 }
228
SetReserved(uint32_t reserved)229 void Icmpv6NS::SetReserved (uint32_t reserved)
230 {
231 NS_LOG_FUNCTION (this << reserved);
232 m_reserved = reserved;
233 }
234
GetIpv6Target() const235 Ipv6Address Icmpv6NS::GetIpv6Target () const
236 {
237 NS_LOG_FUNCTION (this);
238 return m_target;
239 }
240
SetIpv6Target(Ipv6Address target)241 void Icmpv6NS::SetIpv6Target (Ipv6Address target)
242 {
243 NS_LOG_FUNCTION (this << target);
244 m_target = target;
245 }
246
Print(std::ostream & os) const247 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
GetSerializedSize() const253 uint32_t Icmpv6NS::GetSerializedSize () const
254 {
255 NS_LOG_FUNCTION (this);
256 return 24;
257 }
258
Serialize(Buffer::Iterator start) const259 void Icmpv6NS::Serialize (Buffer::Iterator start) const
260 {
261 NS_LOG_FUNCTION (this << &start);
262 uint8_t buff_target[16];
263 uint16_t checksum = 0;
264 Buffer::Iterator i = start;
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
Deserialize(Buffer::Iterator start)283 uint32_t Icmpv6NS::Deserialize (Buffer::Iterator start)
284 {
285 NS_LOG_FUNCTION (this << &start);
286 uint8_t buf[16];
287 Buffer::Iterator i = start;
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
299 NS_OBJECT_ENSURE_REGISTERED (Icmpv6NA);
300
GetTypeId()301 TypeId Icmpv6NA::GetTypeId ()
302 {
303 static TypeId tid = TypeId ("ns3::Icmpv6NA")
304 .SetParent<Icmpv6Header> ()
305 .SetGroupName ("Internet")
306 .AddConstructor<Icmpv6NA> ()
307 ;
308 return tid;
309 }
310
GetInstanceTypeId() const311 TypeId Icmpv6NA::GetInstanceTypeId () const
312 {
313 NS_LOG_FUNCTION (this);
314 return GetTypeId ();
315 }
316
Icmpv6NA()317 Icmpv6NA::Icmpv6NA ()
318 {
319 NS_LOG_FUNCTION (this);
320 SetType (ICMPV6_ND_NEIGHBOR_ADVERTISEMENT);
321 SetCode (0);
322 SetReserved (0);
323 SetFlagR (0);
324 SetFlagS (0);
325 SetFlagO (0);
326 m_checksum = 0;
327 }
328
~Icmpv6NA()329 Icmpv6NA::~Icmpv6NA ()
330 {
331 NS_LOG_FUNCTION (this);
332 }
333
GetReserved() const334 uint32_t Icmpv6NA::GetReserved () const
335 {
336 NS_LOG_FUNCTION (this);
337 return m_reserved;
338 }
339
SetReserved(uint32_t reserved)340 void Icmpv6NA::SetReserved (uint32_t reserved)
341 {
342 NS_LOG_FUNCTION (this << reserved);
343 m_reserved = reserved;
344 }
345
GetIpv6Target() const346 Ipv6Address Icmpv6NA::GetIpv6Target () const
347 {
348 NS_LOG_FUNCTION (this);
349 return m_target;
350 }
351
GetFlagR() const352 bool Icmpv6NA::GetFlagR () const
353 {
354 NS_LOG_FUNCTION (this);
355 return m_flagR;
356 }
357
SetFlagR(bool r)358 void Icmpv6NA::SetFlagR (bool r)
359 {
360 NS_LOG_FUNCTION (this << r);
361 m_flagR = r;
362 }
363
GetFlagS() const364 bool Icmpv6NA::GetFlagS () const
365 {
366 NS_LOG_FUNCTION (this);
367 return m_flagS;
368 }
369
SetFlagS(bool s)370 void Icmpv6NA::SetFlagS (bool s)
371 {
372 NS_LOG_FUNCTION (this << s);
373 m_flagS = s;
374 }
375
GetFlagO() const376 bool Icmpv6NA::GetFlagO () const
377 {
378 NS_LOG_FUNCTION (this);
379 return m_flagO;
380 }
381
SetFlagO(bool o)382 void Icmpv6NA::SetFlagO (bool o)
383 {
384 NS_LOG_FUNCTION (this << o);
385 m_flagO = o;
386 }
387
SetIpv6Target(Ipv6Address target)388 void Icmpv6NA::SetIpv6Target (Ipv6Address target)
389 {
390 NS_LOG_FUNCTION (this << target);
391 m_target = target;
392 }
393
Print(std::ostream & os) const394 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
GetSerializedSize() const400 uint32_t Icmpv6NA::GetSerializedSize () const
401 {
402 NS_LOG_FUNCTION (this);
403 return 24;
404 }
405
Serialize(Buffer::Iterator start) const406 void Icmpv6NA::Serialize (Buffer::Iterator start) const
407 {
408 NS_LOG_FUNCTION (this << &start);
409 uint8_t buff_target[16];
410 uint16_t checksum = 0;
411 Buffer::Iterator i = start;
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
Deserialize(Buffer::Iterator start)447 uint32_t Icmpv6NA::Deserialize (Buffer::Iterator start)
448 {
449 NS_LOG_FUNCTION (this << &start);
450 uint8_t buf[16];
451 Buffer::Iterator i = start;
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
483 NS_OBJECT_ENSURE_REGISTERED (Icmpv6RA);
484
GetTypeId()485 TypeId Icmpv6RA::GetTypeId ()
486 {
487 static TypeId tid = TypeId ("ns3::Icmpv6RA")
488 .SetParent<Icmpv6Header> ()
489 .SetGroupName ("Internet")
490 .AddConstructor<Icmpv6RA> ()
491 ;
492 return tid;
493 }
494
GetInstanceTypeId() const495 TypeId Icmpv6RA::GetInstanceTypeId () const
496 {
497 NS_LOG_FUNCTION (this);
498 return GetTypeId ();
499 }
500
Icmpv6RA()501 Icmpv6RA::Icmpv6RA ()
502 {
503 NS_LOG_FUNCTION (this);
504 SetType (ICMPV6_ND_ROUTER_ADVERTISEMENT);
505 SetCode (0);
506 SetFlagM (0);
507 SetFlagO (0);
508 SetFlagH (0);
509 SetCurHopLimit (0);
510 SetLifeTime (0);
511 SetRetransmissionTime (0);
512 SetReachableTime (0);
513 }
514
~Icmpv6RA()515 Icmpv6RA::~Icmpv6RA ()
516 {
517 NS_LOG_FUNCTION (this);
518 }
519
SetCurHopLimit(uint8_t m)520 void Icmpv6RA::SetCurHopLimit (uint8_t m)
521 {
522 NS_LOG_FUNCTION (this << static_cast<uint32_t> (m));
523 m_curHopLimit = m;
524 }
525
GetCurHopLimit() const526 uint8_t Icmpv6RA::GetCurHopLimit () const
527 {
528 NS_LOG_FUNCTION (this);
529 return m_curHopLimit;
530 }
531
GetLifeTime() const532 uint16_t Icmpv6RA::GetLifeTime () const
533 {
534 NS_LOG_FUNCTION (this);
535 return m_LifeTime;
536 }
537
GetReachableTime() const538 uint32_t Icmpv6RA::GetReachableTime () const
539 {
540 NS_LOG_FUNCTION (this);
541 return m_ReachableTime;
542 }
543
GetRetransmissionTime() const544 uint32_t Icmpv6RA::GetRetransmissionTime () const
545 {
546 NS_LOG_FUNCTION (this);
547 return m_RetransmissionTimer;
548 }
549
SetLifeTime(uint16_t l)550 void Icmpv6RA::SetLifeTime (uint16_t l)
551 {
552 NS_LOG_FUNCTION (this << l);
553 m_LifeTime = l;
554 }
555
SetReachableTime(uint32_t r)556 void Icmpv6RA::SetReachableTime (uint32_t r)
557 {
558 NS_LOG_FUNCTION (this << r);
559 m_ReachableTime = r;
560 }
561
SetRetransmissionTime(uint32_t r)562 void Icmpv6RA::SetRetransmissionTime (uint32_t r)
563 {
564 NS_LOG_FUNCTION (this << r);
565 m_RetransmissionTimer = r;
566 }
567
GetFlagM() const568 bool Icmpv6RA::GetFlagM () const
569 {
570 NS_LOG_FUNCTION (this);
571 return m_flagM;
572 }
573
SetFlagM(bool m)574 void Icmpv6RA::SetFlagM (bool m)
575 {
576 NS_LOG_FUNCTION (this << m);
577 m_flagM = m;
578 }
579
GetFlagO() const580 bool Icmpv6RA::GetFlagO () const
581 {
582 NS_LOG_FUNCTION (this);
583 return m_flagO;
584 }
585
SetFlagO(bool o)586 void Icmpv6RA::SetFlagO (bool o)
587 {
588 NS_LOG_FUNCTION (this << o);
589 m_flagO = o;
590 }
591
GetFlagH() const592 bool Icmpv6RA::GetFlagH () const
593 {
594 NS_LOG_FUNCTION (this);
595 return m_flagH;
596 }
597
SetFlagH(bool h)598 void Icmpv6RA::SetFlagH (bool h)
599 {
600 NS_LOG_FUNCTION (this << h);
601 m_flagH = h;
602 }
603
GetFlags() const604 uint8_t Icmpv6RA::GetFlags () const
605 {
606 NS_LOG_FUNCTION (this);
607 return 0;
608 }
609
SetFlags(uint8_t f)610 void Icmpv6RA::SetFlags (uint8_t f)
611 {
612 NS_LOG_FUNCTION (this << static_cast<uint32_t> (f));
613 }
614
Print(std::ostream & os) const615 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
GetSerializedSize() const621 uint32_t Icmpv6RA::GetSerializedSize () const
622 {
623 NS_LOG_FUNCTION (this);
624 return 16;
625 }
626
Serialize(Buffer::Iterator start) const627 void Icmpv6RA::Serialize (Buffer::Iterator start) const
628 {
629 NS_LOG_FUNCTION (this << &start);
630 uint16_t checksum = 0;
631 Buffer::Iterator i = start;
632 uint8_t flags = 0;
633
634 i.WriteU8 (GetType ());
635 i.WriteU8 (GetCode ());
636 i.WriteHtonU16 (0);
637 i.WriteU8 (m_curHopLimit);
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 ());
655 i.WriteHtonU32 (GetReachableTime ());
656 i.WriteHtonU32 (GetRetransmissionTime ());
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
Deserialize(Buffer::Iterator start)666 uint32_t Icmpv6RA::Deserialize (Buffer::Iterator start)
667 {
668 NS_LOG_FUNCTION (this << &start);
669 Buffer::Iterator i = 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 ());
695 SetReachableTime (i.ReadNtohU32 ());
696 SetRetransmissionTime (i.ReadNtohU32 ());
697
698 return GetSerializedSize ();
699 }
700
701 NS_OBJECT_ENSURE_REGISTERED (Icmpv6RS);
702
GetTypeId()703 TypeId Icmpv6RS::GetTypeId ()
704 {
705 static TypeId tid = TypeId ("ns3::Icmpv6RS")
706 .SetParent<Icmpv6Header> ()
707 .SetGroupName ("Internet")
708 .AddConstructor<Icmpv6RS> ()
709 ;
710 return tid;
711 }
712
GetInstanceTypeId() const713 TypeId Icmpv6RS::GetInstanceTypeId () const
714 {
715 NS_LOG_FUNCTION (this);
716 return GetTypeId ();
717 }
718
Icmpv6RS()719 Icmpv6RS::Icmpv6RS ()
720 {
721 NS_LOG_FUNCTION (this);
722 SetType (ICMPV6_ND_ROUTER_SOLICITATION);
723 SetCode (0);
724 SetReserved (0);
725 }
726
~Icmpv6RS()727 Icmpv6RS::~Icmpv6RS ()
728 {
729 NS_LOG_FUNCTION (this);
730 }
731
GetReserved() const732 uint32_t Icmpv6RS::GetReserved () const
733 {
734 NS_LOG_FUNCTION (this);
735 return m_reserved;
736 }
737
SetReserved(uint32_t reserved)738 void Icmpv6RS::SetReserved (uint32_t reserved)
739 {
740 NS_LOG_FUNCTION (this << reserved);
741 m_reserved = reserved;
742 }
743
Print(std::ostream & os) const744 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
GetSerializedSize() const750 uint32_t Icmpv6RS::GetSerializedSize () const
751 {
752 NS_LOG_FUNCTION (this);
753 return 8;
754 }
755
Serialize(Buffer::Iterator start) const756 void Icmpv6RS::Serialize (Buffer::Iterator start) const
757 {
758 NS_LOG_FUNCTION (this << &start);
759
760 uint16_t checksum = 0;
761 Buffer::Iterator i = start;
762
763 i.WriteU8 (GetType ());
764 i.WriteU8 (GetCode ());
765 i.WriteU16 (0);
766 i.WriteHtonU32 (m_reserved);
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
Deserialize(Buffer::Iterator start)779 uint32_t Icmpv6RS::Deserialize (Buffer::Iterator start)
780 {
781 NS_LOG_FUNCTION (this << &start);
782 Buffer::Iterator i = 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
792 NS_OBJECT_ENSURE_REGISTERED (Icmpv6Redirection);
793
GetTypeId()794 TypeId Icmpv6Redirection::GetTypeId ()
795 {
796 static TypeId tid = TypeId ("ns3::Icmpv6Redirection")
797 .SetParent<Icmpv6Header> ()
798 .SetGroupName ("Internet")
799 .AddConstructor<Icmpv6Redirection> ()
800 ;
801 return tid;
802 }
803
GetInstanceTypeId() const804 TypeId Icmpv6Redirection::GetInstanceTypeId () const
805 {
806 NS_LOG_FUNCTION (this);
807 return GetTypeId ();
808 }
809
Icmpv6Redirection()810 Icmpv6Redirection::Icmpv6Redirection ()
811 : m_target (Ipv6Address ("")),
812 m_destination (Ipv6Address ("")),
813 m_reserved (0)
814 {
815 NS_LOG_FUNCTION (this);
816 SetType (ICMPV6_ND_REDIRECTION);
817 SetCode (0);
818 m_checksum = 0;
819 }
820
~Icmpv6Redirection()821 Icmpv6Redirection::~Icmpv6Redirection ()
822 {
823 NS_LOG_FUNCTION (this);
824 }
825
SetReserved(uint32_t reserved)826 void Icmpv6Redirection::SetReserved (uint32_t reserved)
827 {
828 NS_LOG_FUNCTION (this << reserved);
829 m_reserved = reserved;
830 }
831
GetReserved() const832 uint32_t Icmpv6Redirection::GetReserved () const
833 {
834 NS_LOG_FUNCTION (this);
835 return m_reserved;
836 }
837
GetTarget() const838 Ipv6Address Icmpv6Redirection::GetTarget () const
839 {
840 NS_LOG_FUNCTION (this);
841 return m_target;
842 }
843
SetTarget(Ipv6Address target)844 void Icmpv6Redirection::SetTarget (Ipv6Address target)
845 {
846 NS_LOG_FUNCTION (this << target);
847 m_target = target;
848 }
849
GetDestination() const850 Ipv6Address Icmpv6Redirection::GetDestination () const
851 {
852 NS_LOG_FUNCTION (this);
853 return m_destination;
854 }
855
SetDestination(Ipv6Address destination)856 void Icmpv6Redirection::SetDestination (Ipv6Address destination)
857 {
858 NS_LOG_FUNCTION (this << destination);
859 m_destination = destination;
860 }
861
Print(std::ostream & os) const862 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
GetSerializedSize() const868 uint32_t Icmpv6Redirection::GetSerializedSize () const
869 {
870 NS_LOG_FUNCTION (this);
871 return 40;
872 }
873
Serialize(Buffer::Iterator start) const874 void Icmpv6Redirection::Serialize (Buffer::Iterator start) const
875 {
876 NS_LOG_FUNCTION (this << &start);
877 uint8_t buff[16];
878 uint16_t checksum = 0;
879 Buffer::Iterator i = start;
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
Deserialize(Buffer::Iterator start)903 uint32_t Icmpv6Redirection::Deserialize (Buffer::Iterator start)
904 {
905 NS_LOG_FUNCTION (this << &start);
906 uint8_t buff[16];
907 Buffer::Iterator i = start;
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
923 NS_OBJECT_ENSURE_REGISTERED (Icmpv6Echo);
924
GetTypeId()925 TypeId Icmpv6Echo::GetTypeId ()
926 {
927 static TypeId tid = TypeId ("ns3::Icmpv6Echo")
928 .SetParent<Icmpv6Header> ()
929 .SetGroupName ("Internet")
930 .AddConstructor<Icmpv6Echo> ()
931 ;
932 return tid;
933 }
934
GetInstanceTypeId() const935 TypeId Icmpv6Echo::GetInstanceTypeId () const
936 {
937 NS_LOG_FUNCTION (this);
938 return GetTypeId ();
939 }
940
Icmpv6Echo()941 Icmpv6Echo::Icmpv6Echo ()
942 {
943 NS_LOG_FUNCTION (this);
944 SetType (Icmpv6Header::ICMPV6_ECHO_REQUEST);
945 SetCode (0);
946 m_checksum = 0;
947 SetId (0);
948 SetSeq (0);
949 }
950
Icmpv6Echo(bool request)951 Icmpv6Echo::Icmpv6Echo (bool request)
952 {
953 NS_LOG_FUNCTION (this << request);
954 SetType (request ? Icmpv6Header::ICMPV6_ECHO_REQUEST : Icmpv6Header::ICMPV6_ECHO_REPLY);
955 SetCode (0);
956 m_checksum = 0;
957 SetId (0);
958 SetSeq (0);
959 }
960
~Icmpv6Echo()961 Icmpv6Echo::~Icmpv6Echo ()
962 {
963 NS_LOG_FUNCTION (this);
964 }
965
GetId() const966 uint16_t Icmpv6Echo::GetId () const
967 {
968 NS_LOG_FUNCTION (this);
969 return m_id;
970 }
971
SetId(uint16_t id)972 void Icmpv6Echo::SetId (uint16_t id)
973 {
974 NS_LOG_FUNCTION (this << id);
975 m_id = id;
976 }
977
GetSeq() const978 uint16_t Icmpv6Echo::GetSeq () const
979 {
980 NS_LOG_FUNCTION (this);
981 return m_seq;
982 }
983
SetSeq(uint16_t seq)984 void Icmpv6Echo::SetSeq (uint16_t seq)
985 {
986 NS_LOG_FUNCTION (this << seq);
987 m_seq = seq;
988 }
989
Print(std::ostream & os) const990 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
GetSerializedSize() const999 uint32_t Icmpv6Echo::GetSerializedSize () const
1000 {
1001 NS_LOG_FUNCTION (this);
1002 return 8;
1003 }
1004
Serialize(Buffer::Iterator start) const1005 void Icmpv6Echo::Serialize (Buffer::Iterator start) const
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
Deserialize(Buffer::Iterator start)1028 uint32_t Icmpv6Echo::Deserialize (Buffer::Iterator start)
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
1042 NS_OBJECT_ENSURE_REGISTERED (Icmpv6DestinationUnreachable);
1043
GetTypeId()1044 TypeId Icmpv6DestinationUnreachable::GetTypeId ()
1045 {
1046 static TypeId tid = TypeId ("ns3::Icmpv6DestinationUnreachable")
1047 .SetParent<Icmpv6Header> ()
1048 .SetGroupName ("Internet")
1049 .AddConstructor<Icmpv6DestinationUnreachable> ()
1050 ;
1051 return tid;
1052 }
1053
GetInstanceTypeId() const1054 TypeId Icmpv6DestinationUnreachable::GetInstanceTypeId () const
1055 {
1056 NS_LOG_FUNCTION (this);
1057 return GetTypeId ();
1058 }
1059
Icmpv6DestinationUnreachable()1060 Icmpv6DestinationUnreachable::Icmpv6DestinationUnreachable ()
1061 : m_packet (0)
1062 {
1063 NS_LOG_FUNCTION (this);
1064 SetType (ICMPV6_ERROR_DESTINATION_UNREACHABLE);
1065 }
1066
~Icmpv6DestinationUnreachable()1067 Icmpv6DestinationUnreachable::~Icmpv6DestinationUnreachable ()
1068 {
1069 NS_LOG_FUNCTION (this);
1070 }
1071
GetPacket() const1072 Ptr<Packet> Icmpv6DestinationUnreachable::GetPacket () const
1073 {
1074 NS_LOG_FUNCTION (this);
1075 return m_packet;
1076 }
1077
SetPacket(Ptr<Packet> p)1078 void Icmpv6DestinationUnreachable::SetPacket (Ptr<Packet> p)
1079 {
1080 NS_LOG_FUNCTION (this << *p);
1081 NS_ASSERT (p->GetSize () <= 1280);
1082 m_packet = p;
1083 }
1084
Print(std::ostream & os) const1085 void Icmpv6DestinationUnreachable::Print (std::ostream& os) const
1086 {
1087 NS_LOG_FUNCTION (this << &os);
1088 os << "( type = " << (uint32_t)GetType () << " (Destination Unreachable) code = " << (uint32_t)GetCode () << " checksum = " << (uint32_t)GetChecksum () << ")";
1089 }
1090
GetSerializedSize() const1091 uint32_t Icmpv6DestinationUnreachable::GetSerializedSize () const
1092 {
1093 NS_LOG_FUNCTION (this);
1094 return 8 + m_packet->GetSize ();
1095 }
1096
Serialize(Buffer::Iterator start) const1097 void Icmpv6DestinationUnreachable::Serialize (Buffer::Iterator start) const
1098 {
1099 NS_LOG_FUNCTION (this << &start);
1100 uint16_t checksum = 0;
1101 Buffer::Iterator i = start;
1102
1103 i.WriteU8 (GetType ());
1104 i.WriteU8 (GetCode ());
1105 i.WriteHtonU16 (0);
1106 i.WriteHtonU32 (0);
1107
1108 uint32_t size = m_packet->GetSize ();
1109 uint8_t *buf = new uint8_t[size];
1110 m_packet->CopyData (buf, size);
1111 i.Write (buf, size);
1112 delete[] buf;
1113
1114 i = start;
1115 checksum = i.CalculateIpChecksum (i.GetSize (), GetChecksum ());
1116
1117 i = start;
1118 i.Next (2);
1119 i.WriteU16 (checksum);
1120 }
1121
Deserialize(Buffer::Iterator start)1122 uint32_t Icmpv6DestinationUnreachable::Deserialize (Buffer::Iterator start)
1123 {
1124 NS_LOG_FUNCTION (this << &start);
1125 uint16_t length = start.GetRemainingSize () - 8;
1126 uint8_t* data = new uint8_t[length];
1127 Buffer::Iterator i = start;
1128
1129 SetType (i.ReadU8 ());
1130 SetCode (i.ReadU8 ());
1131 m_checksum = i.ReadU16 ();
1132 i.ReadNtohU32 ();
1133 i.Read (data, length);
1134 m_packet = Create<Packet> (data, length);
1135
1136 delete[] data;
1137 return GetSerializedSize ();
1138 }
1139
1140 NS_OBJECT_ENSURE_REGISTERED (Icmpv6TooBig);
1141
GetTypeId()1142 TypeId Icmpv6TooBig::GetTypeId ()
1143 {
1144 static TypeId tid = TypeId ("ns3::Icmpv6TooBig")
1145 .SetParent<Icmpv6Header> ()
1146 .SetGroupName ("Internet")
1147 .AddConstructor<Icmpv6TooBig> ()
1148 ;
1149 return tid;
1150 }
1151
GetInstanceTypeId() const1152 TypeId Icmpv6TooBig::GetInstanceTypeId () const
1153 {
1154 NS_LOG_FUNCTION (this);
1155 return GetTypeId ();
1156 }
1157
Icmpv6TooBig()1158 Icmpv6TooBig::Icmpv6TooBig ()
1159 : m_packet (0),
1160 m_mtu (0)
1161 {
1162 NS_LOG_FUNCTION (this);
1163 SetType (ICMPV6_ERROR_PACKET_TOO_BIG);
1164 }
1165
~Icmpv6TooBig()1166 Icmpv6TooBig::~Icmpv6TooBig ()
1167 {
1168 NS_LOG_FUNCTION (this);
1169 }
1170
GetPacket() const1171 Ptr<Packet> Icmpv6TooBig::GetPacket () const
1172 {
1173 NS_LOG_FUNCTION (this);
1174 return m_packet;
1175 }
1176
SetPacket(Ptr<Packet> p)1177 void Icmpv6TooBig::SetPacket (Ptr<Packet> p)
1178 {
1179 NS_LOG_FUNCTION (this << *p);
1180 NS_ASSERT (p->GetSize () <= 1280);
1181 m_packet = p;
1182 }
1183
GetMtu() const1184 uint32_t Icmpv6TooBig::GetMtu () const
1185 {
1186 NS_LOG_FUNCTION (this);
1187 return m_mtu;
1188 }
1189
SetMtu(uint32_t mtu)1190 void Icmpv6TooBig::SetMtu (uint32_t mtu)
1191 {
1192 NS_LOG_FUNCTION (this << mtu);
1193 m_mtu = mtu;
1194 }
1195
Print(std::ostream & os) const1196 void Icmpv6TooBig::Print (std::ostream& os) const
1197 {
1198 NS_LOG_FUNCTION (this << &os);
1199 os << "( type = " << (uint32_t)GetType () << " (Too Big) code = " << (uint32_t)GetCode () << " checksum = " << (uint32_t)GetChecksum () << " mtu = " << (uint32_t)GetMtu () << ")";
1200 }
1201
GetSerializedSize() const1202 uint32_t Icmpv6TooBig::GetSerializedSize () const
1203 {
1204 NS_LOG_FUNCTION (this);
1205 return 8 + m_packet->GetSize ();
1206 }
1207
Serialize(Buffer::Iterator start) const1208 void Icmpv6TooBig::Serialize (Buffer::Iterator start) const
1209 {
1210 NS_LOG_FUNCTION (this << &start);
1211 uint16_t checksum = 0;
1212 Buffer::Iterator i = start;
1213
1214 i.WriteU8 (GetType ());
1215 i.WriteU8 (GetCode ());
1216 i.WriteHtonU16 (0);
1217 i.WriteHtonU32 (GetMtu ());
1218
1219 uint32_t size = m_packet->GetSize ();
1220 uint8_t *buf = new uint8_t[size];
1221 m_packet->CopyData (buf, size);
1222 i.Write (buf, size);
1223 delete[] buf;
1224
1225 i = start;
1226 checksum = i.CalculateIpChecksum (i.GetSize (), GetChecksum ());
1227
1228 i = start;
1229 i.Next (2);
1230 i.WriteU16 (checksum);
1231 }
1232
Deserialize(Buffer::Iterator start)1233 uint32_t Icmpv6TooBig::Deserialize (Buffer::Iterator start)
1234 {
1235 NS_LOG_FUNCTION (this << &start);
1236 uint16_t length = start.GetRemainingSize () - 8;
1237 uint8_t* data = new uint8_t[length];
1238 Buffer::Iterator i = start;
1239
1240 SetType (i.ReadU8 ());
1241 SetCode (i.ReadU8 ());
1242 m_checksum = i.ReadU16 ();
1243 SetMtu (i.ReadNtohU32 ());
1244 i.Read (data, length);
1245 m_packet = Create<Packet> (data, length);
1246
1247 delete[] data;
1248 return GetSerializedSize ();
1249 }
1250
1251 NS_OBJECT_ENSURE_REGISTERED (Icmpv6TimeExceeded);
1252
GetTypeId()1253 TypeId Icmpv6TimeExceeded::GetTypeId ()
1254 {
1255 static TypeId tid = TypeId ("ns3::Icmpv6TimeExceeded")
1256 .SetParent<Icmpv6Header> ()
1257 .SetGroupName ("Internet")
1258 .AddConstructor<Icmpv6TimeExceeded> ()
1259 ;
1260 return tid;
1261 }
1262
GetInstanceTypeId() const1263 TypeId Icmpv6TimeExceeded::GetInstanceTypeId () const
1264 {
1265 NS_LOG_FUNCTION (this);
1266 return GetTypeId ();
1267 }
1268
Icmpv6TimeExceeded()1269 Icmpv6TimeExceeded::Icmpv6TimeExceeded ()
1270 : m_packet (0)
1271 {
1272 NS_LOG_FUNCTION (this);
1273 SetType (ICMPV6_ERROR_TIME_EXCEEDED);
1274 }
1275
~Icmpv6TimeExceeded()1276 Icmpv6TimeExceeded::~Icmpv6TimeExceeded ()
1277 {
1278 NS_LOG_FUNCTION (this);
1279 }
1280
GetPacket() const1281 Ptr<Packet> Icmpv6TimeExceeded::GetPacket () const
1282 {
1283 NS_LOG_FUNCTION (this);
1284 return m_packet;
1285 }
1286
SetPacket(Ptr<Packet> p)1287 void Icmpv6TimeExceeded::SetPacket (Ptr<Packet> p)
1288 {
1289 NS_LOG_FUNCTION (this << *p);
1290 NS_ASSERT (p->GetSize () <= 1280);
1291 m_packet = p;
1292 }
1293
Print(std::ostream & os) const1294 void Icmpv6TimeExceeded::Print (std::ostream& os) const
1295 {
1296 NS_LOG_FUNCTION (this << &os);
1297 os << "( type = " << (uint32_t)GetType () << " (Destination Unreachable) code = " << (uint32_t)GetCode () << " checksum = " << (uint32_t)GetChecksum () << ")";
1298 }
1299
GetSerializedSize() const1300 uint32_t Icmpv6TimeExceeded::GetSerializedSize () const
1301 {
1302 NS_LOG_FUNCTION (this);
1303 return 8 + m_packet->GetSize ();
1304 }
1305
Serialize(Buffer::Iterator start) const1306 void Icmpv6TimeExceeded::Serialize (Buffer::Iterator start) const
1307 {
1308 NS_LOG_FUNCTION (this << &start);
1309
1310 uint16_t checksum = 0;
1311 Buffer::Iterator i = start;
1312
1313 i.WriteU8 (GetType ());
1314 i.WriteU8 (GetCode ());
1315 i.WriteHtonU16 (0);
1316 i.WriteHtonU32 (0);
1317
1318 uint32_t size = m_packet->GetSize ();
1319 uint8_t *buf = new uint8_t[size];
1320 m_packet->CopyData (buf, size);
1321 i.Write (buf, size);
1322 delete[] buf;
1323
1324 i = start;
1325 checksum = i.CalculateIpChecksum (i.GetSize (), GetChecksum ());
1326
1327 i = start;
1328 i.Next (2);
1329 i.WriteU16 (checksum);
1330 }
1331
Deserialize(Buffer::Iterator start)1332 uint32_t Icmpv6TimeExceeded::Deserialize (Buffer::Iterator start)
1333 {
1334 NS_LOG_FUNCTION (this << &start);
1335
1336 uint16_t length = start.GetRemainingSize () - 8;
1337 uint8_t* data = new uint8_t[length];
1338 Buffer::Iterator i = start;
1339
1340 SetType (i.ReadU8 ());
1341 SetCode (i.ReadU8 ());
1342 m_checksum = i.ReadU16 ();
1343 i.ReadNtohU32 ();
1344 i.Read (data, length);
1345 m_packet = Create<Packet> (data, length);
1346
1347 delete[] data;
1348 return GetSerializedSize ();
1349 }
1350
1351 NS_OBJECT_ENSURE_REGISTERED (Icmpv6ParameterError);
1352
GetTypeId()1353 TypeId Icmpv6ParameterError::GetTypeId ()
1354 {
1355 static TypeId tid = TypeId ("ns3::Icmpv6ParameterError")
1356 .SetParent<Icmpv6Header> ()
1357 .SetGroupName ("Internet")
1358 .AddConstructor<Icmpv6ParameterError> ()
1359 ;
1360 return tid;
1361 }
1362
GetInstanceTypeId() const1363 TypeId Icmpv6ParameterError::GetInstanceTypeId () const
1364 {
1365 NS_LOG_FUNCTION (this);
1366 return GetTypeId ();
1367 }
1368
Icmpv6ParameterError()1369 Icmpv6ParameterError::Icmpv6ParameterError ()
1370 : m_packet (0),
1371 m_ptr (0)
1372 {
1373 NS_LOG_FUNCTION (this);
1374 SetType (ICMPV6_ERROR_PARAMETER_ERROR);
1375 }
1376
~Icmpv6ParameterError()1377 Icmpv6ParameterError::~Icmpv6ParameterError ()
1378 {
1379 NS_LOG_FUNCTION (this);
1380 }
1381
GetPacket() const1382 Ptr<Packet> Icmpv6ParameterError::GetPacket () const
1383 {
1384 NS_LOG_FUNCTION (this);
1385 return m_packet;
1386 }
1387
SetPacket(Ptr<Packet> p)1388 void Icmpv6ParameterError::SetPacket (Ptr<Packet> p)
1389 {
1390 NS_LOG_FUNCTION (this << *p);
1391 NS_ASSERT (p->GetSize () <= 1280);
1392 m_packet = p;
1393 }
1394
GetPtr() const1395 uint32_t Icmpv6ParameterError::GetPtr () const
1396 {
1397 NS_LOG_FUNCTION (this);
1398 return m_ptr;
1399 }
1400
SetPtr(uint32_t ptr)1401 void Icmpv6ParameterError::SetPtr (uint32_t ptr)
1402 {
1403 NS_LOG_FUNCTION (this << ptr);
1404 m_ptr = ptr;
1405 }
1406
Print(std::ostream & os) const1407 void Icmpv6ParameterError::Print (std::ostream& os) const
1408 {
1409 NS_LOG_FUNCTION (this << &os);
1410 os << "( type = " << (uint32_t)GetType () << " (Destination Unreachable) code = " << (uint32_t)GetCode () << " checksum = " << (uint32_t)GetChecksum () << " ptr = " << (uint32_t)GetPtr () << ")";
1411 }
1412
GetSerializedSize() const1413 uint32_t Icmpv6ParameterError::GetSerializedSize () const
1414 {
1415 NS_LOG_FUNCTION (this);
1416 return 8 + m_packet->GetSize ();
1417 }
1418
Serialize(Buffer::Iterator start) const1419 void Icmpv6ParameterError::Serialize (Buffer::Iterator start) const
1420 {
1421 NS_LOG_FUNCTION (this << &start);
1422 uint16_t checksum = 0;
1423 Buffer::Iterator i = start;
1424
1425 i.WriteU8 (GetType ());
1426 i.WriteU8 (GetCode ());
1427 i.WriteHtonU16 (0);
1428 i.WriteHtonU32 (GetPtr ());
1429
1430 uint32_t size = m_packet->GetSize ();
1431 uint8_t *buf = new uint8_t[size];
1432 m_packet->CopyData (buf, size);
1433 i.Write (buf, size);
1434 delete[] buf;
1435
1436 i = start;
1437 checksum = i.CalculateIpChecksum (i.GetSize (), GetChecksum ());
1438
1439 i = start;
1440 i.Next (2);
1441 i.WriteU16 (checksum);
1442 }
1443
Deserialize(Buffer::Iterator start)1444 uint32_t Icmpv6ParameterError::Deserialize (Buffer::Iterator start)
1445 {
1446 NS_LOG_FUNCTION (this << &start);
1447 uint16_t length = start.GetRemainingSize () - 8;
1448 uint8_t* data = new uint8_t[length];
1449 Buffer::Iterator i = start;
1450
1451 SetType (i.ReadU8 ());
1452 SetCode (i.ReadU8 ());
1453 m_checksum = i.ReadU16 ();
1454 SetPtr (i.ReadNtohU32 ());
1455 i.Read (data, length);
1456 m_packet = Create<Packet> (data, length);
1457 delete[] data;
1458
1459 return GetSerializedSize ();
1460 }
1461
1462 NS_OBJECT_ENSURE_REGISTERED (Icmpv6OptionHeader);
1463
GetTypeId()1464 TypeId Icmpv6OptionHeader::GetTypeId ()
1465 {
1466 static TypeId tid = TypeId ("ns3::Icmpv6OptionHeader")
1467 .SetParent<Header> ()
1468 .SetGroupName ("Internet")
1469 .AddConstructor<Icmpv6OptionHeader> ()
1470 ;
1471 return tid;
1472 }
1473
GetInstanceTypeId() const1474 TypeId Icmpv6OptionHeader::GetInstanceTypeId () const
1475 {
1476 NS_LOG_FUNCTION (this);
1477 return GetTypeId ();
1478 }
1479
1480
Icmpv6OptionHeader()1481 Icmpv6OptionHeader::Icmpv6OptionHeader ()
1482 {
1483 NS_LOG_FUNCTION (this);
1484 /** \todo */
1485 m_type = 0;
1486 m_len = 0;
1487 }
1488
~Icmpv6OptionHeader()1489 Icmpv6OptionHeader::~Icmpv6OptionHeader ()
1490 {
1491 NS_LOG_FUNCTION (this);
1492 }
1493
GetType() const1494 uint8_t Icmpv6OptionHeader::GetType () const
1495 {
1496 NS_LOG_FUNCTION (this);
1497 return m_type;
1498 }
1499
SetType(uint8_t type)1500 void Icmpv6OptionHeader::SetType (uint8_t type)
1501 {
1502 NS_LOG_FUNCTION (this << static_cast<uint32_t> (type));
1503 m_type = type;
1504 }
1505
GetLength() const1506 uint8_t Icmpv6OptionHeader::GetLength () const
1507 {
1508 NS_LOG_FUNCTION (this);
1509 return m_len;
1510 }
1511
SetLength(uint8_t len)1512 void Icmpv6OptionHeader::SetLength (uint8_t len)
1513 {
1514 NS_LOG_FUNCTION (this << static_cast<uint32_t> (len));
1515 m_len = len;
1516 }
1517
Print(std::ostream & os) const1518 void Icmpv6OptionHeader::Print (std::ostream& os) const
1519 {
1520 NS_LOG_FUNCTION (this << &os);
1521 os << "( type = " << (uint32_t)GetType () << " length = " << (uint32_t)GetLength () << ")";
1522 }
1523
GetSerializedSize() const1524 uint32_t Icmpv6OptionHeader::GetSerializedSize () const
1525 {
1526 NS_LOG_FUNCTION (this);
1527 return m_len*8;
1528 }
1529
Deserialize(Buffer::Iterator start)1530 uint32_t Icmpv6OptionHeader::Deserialize (Buffer::Iterator start)
1531 {
1532 NS_LOG_FUNCTION (this << &start);
1533 return GetSerializedSize ();
1534 }
1535
Serialize(Buffer::Iterator start) const1536 void Icmpv6OptionHeader::Serialize (Buffer::Iterator start) const
1537 {
1538 NS_LOG_FUNCTION (this << &start);
1539 }
1540
1541 NS_OBJECT_ENSURE_REGISTERED (Icmpv6OptionMtu);
1542
GetTypeId()1543 TypeId Icmpv6OptionMtu::GetTypeId ()
1544 {
1545 static TypeId tid = TypeId ("ns3::Icmpv6OptionMtu")
1546 .SetParent<Icmpv6OptionHeader> ()
1547 .SetGroupName ("Internet")
1548 .AddConstructor<Icmpv6OptionMtu> ()
1549 ;
1550 return tid;
1551 }
1552
GetInstanceTypeId() const1553 TypeId Icmpv6OptionMtu::GetInstanceTypeId () const
1554 {
1555 NS_LOG_FUNCTION (this);
1556 return GetTypeId ();
1557 }
1558
Icmpv6OptionMtu()1559 Icmpv6OptionMtu::Icmpv6OptionMtu ()
1560 {
1561 NS_LOG_FUNCTION (this);
1562 SetType (Icmpv6Header::ICMPV6_OPT_MTU);
1563 SetLength (1);
1564 SetReserved (0);
1565 }
1566
Icmpv6OptionMtu(uint32_t mtu)1567 Icmpv6OptionMtu::Icmpv6OptionMtu (uint32_t mtu)
1568 : m_mtu (mtu)
1569 {
1570 NS_LOG_FUNCTION (this << mtu);
1571 SetType (Icmpv6Header::ICMPV6_OPT_MTU);
1572 SetLength (1);
1573 SetReserved (0);
1574 }
1575
~Icmpv6OptionMtu()1576 Icmpv6OptionMtu::~Icmpv6OptionMtu ()
1577 {
1578 NS_LOG_FUNCTION (this);
1579 }
1580
GetReserved() const1581 uint16_t Icmpv6OptionMtu::GetReserved () const
1582 {
1583 NS_LOG_FUNCTION (this);
1584 return m_reserved;
1585 }
1586
SetReserved(uint16_t reserved)1587 void Icmpv6OptionMtu::SetReserved (uint16_t reserved)
1588 {
1589 NS_LOG_FUNCTION (this << reserved);
1590 m_reserved = reserved;
1591 }
1592
GetMtu() const1593 uint32_t Icmpv6OptionMtu::GetMtu () const
1594 {
1595 NS_LOG_FUNCTION (this);
1596 return m_mtu;
1597 }
1598
SetMtu(uint32_t mtu)1599 void Icmpv6OptionMtu::SetMtu (uint32_t mtu)
1600 {
1601 NS_LOG_FUNCTION (this << mtu);
1602 m_mtu = mtu;
1603 }
1604
Print(std::ostream & os) const1605 void Icmpv6OptionMtu::Print (std::ostream& os) const
1606 {
1607 NS_LOG_FUNCTION (this << &os);
1608 os << "( type = " << (uint32_t)GetType () << " length = " << (uint32_t)GetLength () << " MTU = " << m_mtu << ")";
1609 }
1610
GetSerializedSize() const1611 uint32_t Icmpv6OptionMtu::GetSerializedSize () const
1612 {
1613 NS_LOG_FUNCTION (this);
1614 return 8; /* m_len = 1 so the real size is multiple by 8 */
1615 }
1616
Serialize(Buffer::Iterator start) const1617 void Icmpv6OptionMtu::Serialize (Buffer::Iterator start) const
1618 {
1619 NS_LOG_FUNCTION (this << &start);
1620 Buffer::Iterator i = start;
1621 i.WriteU8 (GetType ());
1622 i.WriteU8 (GetLength ());
1623 i.WriteHtonU16 (GetReserved ());
1624 i.WriteHtonU32 (GetMtu ());
1625 }
1626
Deserialize(Buffer::Iterator start)1627 uint32_t Icmpv6OptionMtu::Deserialize (Buffer::Iterator start)
1628 {
1629 NS_LOG_FUNCTION (this << &start);
1630 Buffer::Iterator i = start;
1631 SetType (i.ReadU8 ());
1632 SetLength (i.ReadU8 ());
1633 SetReserved (i.ReadNtohU16 ());
1634 SetMtu (i.ReadNtohU32 ());
1635 return GetSerializedSize ();
1636 }
1637
1638 NS_OBJECT_ENSURE_REGISTERED (Icmpv6OptionPrefixInformation);
1639
GetTypeId()1640 TypeId Icmpv6OptionPrefixInformation::GetTypeId ()
1641 {
1642 static TypeId tid = TypeId ("ns3::Icmpv6OptionPrefixInformation")
1643 .SetParent<Icmpv6OptionHeader> ()
1644 .SetGroupName ("Internet")
1645 .AddConstructor<Icmpv6OptionPrefixInformation> ()
1646 ;
1647 return tid;
1648 }
1649
GetInstanceTypeId() const1650 TypeId Icmpv6OptionPrefixInformation::GetInstanceTypeId () const
1651 {
1652 NS_LOG_FUNCTION (this);
1653 return GetTypeId ();
1654 }
1655
Icmpv6OptionPrefixInformation()1656 Icmpv6OptionPrefixInformation::Icmpv6OptionPrefixInformation ()
1657 {
1658 NS_LOG_FUNCTION (this);
1659 SetType (Icmpv6Header::ICMPV6_OPT_PREFIX);
1660 SetLength (4);
1661 SetPrefix (Ipv6Address ("::"));
1662 SetPrefixLength (0);
1663 SetValidTime (0);
1664 SetPreferredTime (0);
1665 SetFlags (0);
1666 SetReserved (0);
1667 }
1668
Icmpv6OptionPrefixInformation(Ipv6Address prefix,uint8_t prefixlen)1669 Icmpv6OptionPrefixInformation::Icmpv6OptionPrefixInformation (Ipv6Address prefix, uint8_t prefixlen)
1670 {
1671 NS_LOG_FUNCTION (this << prefix << static_cast<uint32_t> (prefixlen));
1672 SetType (Icmpv6Header::ICMPV6_OPT_PREFIX);
1673 SetLength (4);
1674 SetPrefix (prefix);
1675 SetPrefixLength (prefixlen);
1676 SetValidTime (0);
1677 SetPreferredTime (0);
1678 SetFlags (0);
1679 SetReserved (0);
1680 }
1681
~Icmpv6OptionPrefixInformation()1682 Icmpv6OptionPrefixInformation::~Icmpv6OptionPrefixInformation ()
1683 {
1684 NS_LOG_FUNCTION (this);
1685 }
1686
GetPrefixLength() const1687 uint8_t Icmpv6OptionPrefixInformation::GetPrefixLength () const
1688 {
1689 NS_LOG_FUNCTION (this);
1690 return m_prefixLength;
1691 }
1692
SetPrefixLength(uint8_t prefixLength)1693 void Icmpv6OptionPrefixInformation::SetPrefixLength (uint8_t prefixLength)
1694 {
1695 NS_LOG_FUNCTION (this << static_cast<uint32_t> (prefixLength));
1696 NS_ASSERT (prefixLength <= 128);
1697 m_prefixLength = prefixLength;
1698 }
1699
GetFlags() const1700 uint8_t Icmpv6OptionPrefixInformation::GetFlags () const
1701 {
1702 NS_LOG_FUNCTION (this);
1703 return m_flags;
1704 }
1705
SetFlags(uint8_t flags)1706 void Icmpv6OptionPrefixInformation::SetFlags (uint8_t flags)
1707 {
1708 NS_LOG_FUNCTION (this);
1709 m_flags = flags;
1710 }
1711
GetValidTime() const1712 uint32_t Icmpv6OptionPrefixInformation::GetValidTime () const
1713 {
1714 NS_LOG_FUNCTION (this);
1715 return m_validTime;
1716 }
1717
SetValidTime(uint32_t validTime)1718 void Icmpv6OptionPrefixInformation::SetValidTime (uint32_t validTime)
1719 {
1720 NS_LOG_FUNCTION (this << validTime);
1721 m_validTime = validTime;
1722 }
1723
GetPreferredTime() const1724 uint32_t Icmpv6OptionPrefixInformation::GetPreferredTime () const
1725 {
1726 NS_LOG_FUNCTION (this);
1727 return m_preferredTime;
1728 }
1729
SetPreferredTime(uint32_t preferredTime)1730 void Icmpv6OptionPrefixInformation::SetPreferredTime (uint32_t preferredTime)
1731 {
1732 NS_LOG_FUNCTION (this << preferredTime);
1733 m_preferredTime = preferredTime;
1734 }
1735
GetReserved() const1736 uint32_t Icmpv6OptionPrefixInformation::GetReserved () const
1737 {
1738 NS_LOG_FUNCTION (this);
1739 return m_preferredTime;
1740 }
1741
SetReserved(uint32_t reserved)1742 void Icmpv6OptionPrefixInformation::SetReserved (uint32_t reserved)
1743 {
1744 NS_LOG_FUNCTION (this << reserved);
1745 m_reserved = reserved;
1746 }
1747
GetPrefix() const1748 Ipv6Address Icmpv6OptionPrefixInformation::GetPrefix () const
1749 {
1750 NS_LOG_FUNCTION (this);
1751 return m_prefix;
1752 }
1753
SetPrefix(Ipv6Address prefix)1754 void Icmpv6OptionPrefixInformation::SetPrefix (Ipv6Address prefix)
1755 {
1756 NS_LOG_FUNCTION (this << prefix);
1757 m_prefix = prefix;
1758 }
1759
Print(std::ostream & os) const1760 void Icmpv6OptionPrefixInformation::Print (std::ostream& os) const
1761 {
1762 NS_LOG_FUNCTION (this << &os);
1763 os << "( type = " << (uint32_t)GetType () << " length = " << (uint32_t)GetLength () << " prefix " << m_prefix << ")";
1764 }
1765
GetSerializedSize() const1766 uint32_t Icmpv6OptionPrefixInformation::GetSerializedSize () const
1767 {
1768 NS_LOG_FUNCTION (this);
1769 return 32;
1770 }
1771
Serialize(Buffer::Iterator start) const1772 void Icmpv6OptionPrefixInformation::Serialize (Buffer::Iterator start) const
1773 {
1774 NS_LOG_FUNCTION (this << &start);
1775 Buffer::Iterator i = start;
1776 uint8_t buf[16];
1777
1778 memset (buf, 0x00, sizeof (buf));
1779
1780 i.WriteU8 (GetType ());
1781 i.WriteU8 (GetLength ());
1782 i.WriteU8 (m_prefixLength);
1783 i.WriteU8 (m_flags);
1784 i.WriteHtonU32 (m_validTime);
1785 i.WriteHtonU32 (m_preferredTime);
1786 i.WriteHtonU32 (m_reserved);
1787 m_prefix.GetBytes (buf);
1788 i.Write (buf, 16);
1789 }
1790
Deserialize(Buffer::Iterator start)1791 uint32_t Icmpv6OptionPrefixInformation::Deserialize (Buffer::Iterator start)
1792 {
1793 NS_LOG_FUNCTION (this << &start);
1794 Buffer::Iterator i = start;
1795 uint8_t buf[16];
1796
1797 SetType (i.ReadU8 ());
1798 SetLength (i.ReadU8 ());
1799 SetPrefixLength (i.ReadU8 ());
1800 SetFlags (i.ReadU8 ());
1801 SetValidTime (i.ReadNtohU32 ());
1802 SetPreferredTime (i.ReadNtohU32 ());
1803 SetReserved (i.ReadNtohU32 ());
1804 i.Read (buf, 16);
1805
1806 Ipv6Address prefix (buf);
1807 SetPrefix (prefix);
1808
1809 return GetSerializedSize ();
1810 }
1811
1812 NS_OBJECT_ENSURE_REGISTERED (Icmpv6OptionLinkLayerAddress);
1813
GetTypeId()1814 TypeId Icmpv6OptionLinkLayerAddress::GetTypeId ()
1815 {
1816 static TypeId tid = TypeId ("ns3::Icmpv6OptionLinkLayerAddress")
1817 .SetParent<Icmpv6OptionHeader> ()
1818 .SetGroupName ("Internet")
1819 .AddConstructor<Icmpv6OptionLinkLayerAddress> ()
1820 ;
1821 return tid;
1822 }
1823
GetInstanceTypeId() const1824 TypeId Icmpv6OptionLinkLayerAddress::GetInstanceTypeId () const
1825 {
1826 NS_LOG_FUNCTION (this);
1827 return GetTypeId ();
1828 }
1829
Icmpv6OptionLinkLayerAddress(bool source)1830 Icmpv6OptionLinkLayerAddress::Icmpv6OptionLinkLayerAddress (bool source)
1831 {
1832 NS_LOG_FUNCTION (this << source);
1833 SetType (source ? Icmpv6Header::ICMPV6_OPT_LINK_LAYER_SOURCE : Icmpv6Header::ICMPV6_OPT_LINK_LAYER_TARGET);
1834 }
1835
Icmpv6OptionLinkLayerAddress()1836 Icmpv6OptionLinkLayerAddress::Icmpv6OptionLinkLayerAddress ()
1837 {
1838 NS_LOG_FUNCTION (this);
1839 SetType (Icmpv6Header::ICMPV6_OPT_LINK_LAYER_SOURCE);
1840 }
1841
Icmpv6OptionLinkLayerAddress(bool source,Address addr)1842 Icmpv6OptionLinkLayerAddress::Icmpv6OptionLinkLayerAddress (bool source, Address addr)
1843 {
1844 NS_LOG_FUNCTION (this << source << addr);
1845 SetType (source ? Icmpv6Header::ICMPV6_OPT_LINK_LAYER_SOURCE : Icmpv6Header::ICMPV6_OPT_LINK_LAYER_TARGET);
1846 SetAddress (addr);
1847
1848 uint8_t len = (2 + m_addr.GetLength ()) / 8;
1849 if ( (2 + m_addr.GetLength ()) % 8 )
1850 {
1851 len ++;
1852 }
1853 SetLength (len);
1854 }
1855
~Icmpv6OptionLinkLayerAddress()1856 Icmpv6OptionLinkLayerAddress::~Icmpv6OptionLinkLayerAddress ()
1857 {
1858 NS_LOG_FUNCTION (this);
1859 }
1860
GetAddress() const1861 Address Icmpv6OptionLinkLayerAddress::GetAddress () const
1862 {
1863 NS_LOG_FUNCTION (this);
1864 return m_addr;
1865 }
1866
SetAddress(Address addr)1867 void Icmpv6OptionLinkLayerAddress::SetAddress (Address addr)
1868 {
1869 NS_LOG_FUNCTION (this << addr);
1870 m_addr = addr;
1871 }
1872
Print(std::ostream & os) const1873 void Icmpv6OptionLinkLayerAddress::Print (std::ostream& os) const
1874 {
1875 NS_LOG_FUNCTION (this << &os);
1876 os << "( type = " << (uint32_t)GetType () << " length = " << (uint32_t)GetLength () << " L2 Address = " << m_addr << ")";
1877 }
1878
GetSerializedSize() const1879 uint32_t Icmpv6OptionLinkLayerAddress::GetSerializedSize () const
1880 {
1881 NS_LOG_FUNCTION (this);
1882 uint8_t nb = GetLength() * 8;
1883 return nb;
1884 }
1885
Serialize(Buffer::Iterator start) const1886 void Icmpv6OptionLinkLayerAddress::Serialize (Buffer::Iterator start) const
1887 {
1888 NS_LOG_FUNCTION (this << &start);
1889 Buffer::Iterator i = start;
1890 uint8_t mac[32];
1891
1892 i.WriteU8 (GetType ());
1893 i.WriteU8 (GetLength ());
1894 m_addr.CopyTo (mac);
1895 i.Write (mac, m_addr.GetLength ());
1896
1897 uint8_t len = GetLength ()*8 - (2 + m_addr.GetLength ());
1898 for (uint8_t nb = 0; nb<len; nb++)
1899 {
1900 i.WriteU8 (0);
1901 }
1902 }
1903
Deserialize(Buffer::Iterator start)1904 uint32_t Icmpv6OptionLinkLayerAddress::Deserialize (Buffer::Iterator start)
1905 {
1906 NS_LOG_FUNCTION (this << &start);
1907 Buffer::Iterator i = start;
1908 uint8_t mac[32];
1909
1910 SetType (i.ReadU8 ());
1911 SetLength (i.ReadU8 ());
1912 // -fstrict-overflow sensitive, see bug 1868
1913 NS_ASSERT (GetLength () * 8 <= 32 + 2);
1914 i.Read (mac, (GetLength () * 8) - 2);
1915
1916 m_addr.CopyFrom (mac, (GetLength () * 8) - 2);
1917
1918 return GetSerializedSize ();
1919 }
1920
1921 NS_OBJECT_ENSURE_REGISTERED (Icmpv6OptionRedirected);
1922
GetTypeId()1923 TypeId Icmpv6OptionRedirected::GetTypeId ()
1924 {
1925 static TypeId tid = TypeId ("ns3::Icmpv6OptionRedirected")
1926 .SetParent<Icmpv6OptionHeader> ()
1927 .SetGroupName ("Internet")
1928 .AddConstructor<Icmpv6OptionRedirected> ()
1929 ;
1930 return tid;
1931 }
1932
GetInstanceTypeId() const1933 TypeId Icmpv6OptionRedirected::GetInstanceTypeId () const
1934 {
1935 NS_LOG_FUNCTION (this);
1936 return GetTypeId ();
1937 }
1938
Icmpv6OptionRedirected()1939 Icmpv6OptionRedirected::Icmpv6OptionRedirected ()
1940 : m_packet (0)
1941 {
1942 NS_LOG_FUNCTION (this);
1943 SetType (Icmpv6Header::ICMPV6_OPT_REDIRECTED);
1944 }
1945
~Icmpv6OptionRedirected()1946 Icmpv6OptionRedirected::~Icmpv6OptionRedirected ()
1947 {
1948 NS_LOG_FUNCTION (this);
1949 m_packet = 0;
1950 }
1951
GetPacket() const1952 Ptr<Packet> Icmpv6OptionRedirected::GetPacket () const
1953 {
1954 NS_LOG_FUNCTION (this);
1955 return m_packet;
1956 }
1957
SetPacket(Ptr<Packet> packet)1958 void Icmpv6OptionRedirected::SetPacket (Ptr<Packet> packet)
1959 {
1960 NS_LOG_FUNCTION (this << *packet);
1961 NS_ASSERT (packet->GetSize () <= 1280);
1962 m_packet = packet;
1963 SetLength (1 + (m_packet->GetSize () / 8));
1964 }
1965
Print(std::ostream & os) const1966 void Icmpv6OptionRedirected::Print (std::ostream& os) const
1967 {
1968 NS_LOG_FUNCTION (this << &os);
1969 os << "( type = " << (uint32_t)GetType () << " length = " << (uint32_t)GetLength () << ")";
1970 }
1971
GetSerializedSize() const1972 uint32_t Icmpv6OptionRedirected::GetSerializedSize () const
1973 {
1974 NS_LOG_FUNCTION (this);
1975 return 8 + m_packet->GetSize ();
1976 }
1977
Serialize(Buffer::Iterator start) const1978 void Icmpv6OptionRedirected::Serialize (Buffer::Iterator start) const
1979 {
1980 NS_LOG_FUNCTION (this << &start);
1981 Buffer::Iterator i = start;
1982
1983 i.WriteU8 (GetType ());
1984 i.WriteU8 (GetLength ());
1985 // Reserved
1986 i.WriteU16 (0);
1987 i.WriteU32 (0);
1988
1989 uint32_t size = m_packet->GetSize ();
1990 uint8_t *buf = new uint8_t[size];
1991 m_packet->CopyData (buf, size);
1992 i.Write (buf, size);
1993 delete[] buf;
1994 }
1995
Deserialize(Buffer::Iterator start)1996 uint32_t Icmpv6OptionRedirected::Deserialize (Buffer::Iterator start)
1997 {
1998 NS_LOG_FUNCTION (this << &start);
1999 Buffer::Iterator i = start;
2000
2001 SetType (i.ReadU8 ());
2002 uint8_t length = i.ReadU8 ();
2003 SetLength (length);
2004 i.ReadU16 ();
2005 i.ReadU32 ();
2006
2007 uint32_t len2 = (GetLength () - 1) * 8;
2008 uint8_t* buff = new uint8_t[len2];
2009 i.Read (buff, len2);
2010 m_packet = Create<Packet> (buff, len2);
2011 delete[] buff;
2012
2013 return GetSerializedSize ();
2014 }
2015
2016 } /* namespace ns3 */
2017
2018