A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
icmpv6-header.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007-2009 Strasbourg University
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
18 * Mehdi Benamor <benamor.mehdi@ensi.rnu.tn>
19 * David Gross <gdavid.devel@gmail.com>
20 */
21
22#include "icmpv6-header.h"
23
24#include "ns3/address-utils.h"
25#include "ns3/assert.h"
26#include "ns3/log.h"
27
28namespace ns3
29{
30
31NS_LOG_COMPONENT_DEFINE("Icmpv6Header");
32
33NS_OBJECT_ENSURE_REGISTERED(Icmpv6Header);
34
35TypeId
37{
38 static TypeId tid = TypeId("ns3::Icmpv6Header")
40 .SetGroupName("Internet")
41 .AddConstructor<Icmpv6Header>();
42 return tid;
43}
44
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
66uint8_t
68{
69 NS_LOG_FUNCTION(this);
70 return m_type;
71}
72
73void
75{
76 NS_LOG_FUNCTION(this << static_cast<uint32_t>(type));
77 m_type = type;
78}
79
80uint8_t
82{
83 NS_LOG_FUNCTION(this);
84 return m_code;
85}
86
87void
89{
90 NS_LOG_FUNCTION(this << static_cast<uint32_t>(code));
91 m_code = code;
92}
93
94uint16_t
96{
97 NS_LOG_FUNCTION(this);
98 return m_checksum;
99}
100
101void
103{
104 NS_LOG_FUNCTION(this << checksum);
105 m_checksum = checksum;
106}
107
108void
109Icmpv6Header::Print(std::ostream& os) const
110{
111 NS_LOG_FUNCTION(this << &os);
112 os << "( type = " << (uint32_t)m_type << " code = " << (uint32_t)m_code
113 << " checksum = " << (uint32_t)m_checksum << ")";
114}
115
118{
119 NS_LOG_FUNCTION(this);
120 return 4;
121}
122
125{
126 NS_LOG_FUNCTION(this << &start);
127 Buffer::Iterator i = start;
128
129 m_type = i.ReadU8();
130 m_code = i.ReadU8();
132#if 0
133 i.ReadU32 (); /* padding */
134#endif
135 return GetSerializedSize();
136}
137
138void
140{
141 NS_LOG_FUNCTION(this << &start);
142 Buffer::Iterator i = start;
143
144 i.WriteU8(m_type);
145 i.WriteU8(m_code);
146 i.WriteU16(0);
147#if 0
148 i.WriteU32 (0); /* padding */
149#endif
150
151 if (m_calcChecksum)
152 {
153 i = start;
154 uint16_t checksum = i.CalculateIpChecksum(i.GetSize(), m_checksum);
155 i = start;
156 i.Next(2);
157 i.WriteU16(checksum);
158 }
159}
160
161void
163 Ipv6Address dst,
164 uint16_t length,
165 uint8_t protocol)
166{
167 NS_LOG_FUNCTION(this << src << dst << length << static_cast<uint32_t>(protocol));
168
169 Buffer buf = Buffer(40);
170 uint8_t tmp[16];
172
173 buf.AddAtStart(40);
174 it = buf.Begin();
175
176 src.Serialize(tmp);
177 it.Write(tmp, 16); /* source IPv6 address */
178 dst.Serialize(tmp);
179 it.Write(tmp, 16); /* destination IPv6 address */
180 it.WriteU16(0); /* length */
181 it.WriteU8(length >> 8); /* length */
182 it.WriteU8(length & 0xff); /* length */
183 it.WriteU16(0); /* zero */
184 it.WriteU8(0); /* zero */
185 it.WriteU8(protocol); /* next header */
186
187 it = buf.Begin();
189}
190
192
194{
195 NS_LOG_FUNCTION(this);
197 SetCode(0);
198 SetReserved(0);
199 m_checksum = 0;
200}
201
202TypeId
204{
205 static TypeId tid = TypeId("ns3::Icmpv6NS")
207 .SetGroupName("Internet")
208 .AddConstructor<Icmpv6NS>();
209 return tid;
210}
211
212TypeId
214{
215 NS_LOG_FUNCTION(this);
216 return GetTypeId();
217}
218
220{
221 NS_LOG_FUNCTION(this << target);
223 SetCode(0);
224 SetReserved(0);
225 SetIpv6Target(target);
226 m_checksum = 0;
227
228 /* test */
229 /*
230 m_reserved = 0xdeadbeef;
231 */
232}
233
235{
236 NS_LOG_FUNCTION(this);
237}
238
241{
242 NS_LOG_FUNCTION(this);
243 return m_reserved;
244}
245
246void
248{
249 NS_LOG_FUNCTION(this << reserved);
250 m_reserved = reserved;
251}
252
255{
256 NS_LOG_FUNCTION(this);
257 return m_target;
258}
259
260void
262{
263 NS_LOG_FUNCTION(this << target);
264 m_target = target;
265}
266
267void
268Icmpv6NS::Print(std::ostream& os) const
269{
270 NS_LOG_FUNCTION(this << &os);
271 os << "( type = " << (uint32_t)GetType() << " (NS) code = " << (uint32_t)GetCode()
272 << " target = " << m_target << " checksum = " << (uint32_t)GetChecksum() << ")";
273}
274
277{
278 NS_LOG_FUNCTION(this);
279 return 24;
280}
281
282void
284{
285 NS_LOG_FUNCTION(this << &start);
286 uint8_t buff_target[16];
287 uint16_t checksum = 0;
288 Buffer::Iterator i = start;
289
290 i.WriteU8(GetType());
291 i.WriteU8(GetCode());
292 i.WriteU16(0);
294 m_target.Serialize(buff_target);
295 i.Write(buff_target, 16);
296
297 if (m_calcChecksum)
298 {
299 i = start;
300 checksum = i.CalculateIpChecksum(i.GetSize(), m_checksum);
301 i = start;
302 i.Next(2);
303 i.WriteU16(checksum);
304 }
305}
306
309{
310 NS_LOG_FUNCTION(this << &start);
311 uint8_t buf[16];
312 Buffer::Iterator i = start;
313
314 SetType(i.ReadU8());
315 SetCode(i.ReadU8());
316 m_checksum = i.ReadU16();
318 i.Read(buf, 16);
319 m_target.Set(buf);
320
321 return GetSerializedSize();
322}
323
325
326TypeId
328{
329 static TypeId tid = TypeId("ns3::Icmpv6NA")
331 .SetGroupName("Internet")
332 .AddConstructor<Icmpv6NA>();
333 return tid;
334}
335
336TypeId
338{
339 NS_LOG_FUNCTION(this);
340 return GetTypeId();
341}
342
344{
345 NS_LOG_FUNCTION(this);
347 SetCode(0);
348 SetReserved(0);
349 SetFlagR(false);
350 SetFlagS(false);
351 SetFlagO(false);
352 m_checksum = 0;
353}
354
356{
357 NS_LOG_FUNCTION(this);
358}
359
362{
363 NS_LOG_FUNCTION(this);
364 return m_reserved;
365}
366
367void
369{
370 NS_LOG_FUNCTION(this << reserved);
371 m_reserved = reserved;
372}
373
376{
377 NS_LOG_FUNCTION(this);
378 return m_target;
379}
380
381bool
383{
384 NS_LOG_FUNCTION(this);
385 return m_flagR;
386}
387
388void
390{
391 NS_LOG_FUNCTION(this << r);
392 m_flagR = r;
393}
394
395bool
397{
398 NS_LOG_FUNCTION(this);
399 return m_flagS;
400}
401
402void
404{
405 NS_LOG_FUNCTION(this << s);
406 m_flagS = s;
407}
408
409bool
411{
412 NS_LOG_FUNCTION(this);
413 return m_flagO;
414}
415
416void
418{
419 NS_LOG_FUNCTION(this << o);
420 m_flagO = o;
421}
422
423void
425{
426 NS_LOG_FUNCTION(this << target);
427 m_target = target;
428}
429
430void
431Icmpv6NA::Print(std::ostream& os) const
432{
433 NS_LOG_FUNCTION(this << &os);
434 os << "( type = " << (uint32_t)GetType() << " (NA) code = " << (uint32_t)GetCode()
435 << " checksum = " << (uint32_t)GetChecksum() << ")";
436}
437
440{
441 NS_LOG_FUNCTION(this);
442 return 24;
443}
444
445void
447{
448 NS_LOG_FUNCTION(this << &start);
449 uint8_t buff_target[16];
450 uint16_t checksum = 0;
451 Buffer::Iterator i = start;
452 uint32_t reserved = m_reserved;
453
454 i.WriteU8(GetType());
455 i.WriteU8(GetCode());
456 i.WriteU16(0);
457
458 if (m_flagR)
459 {
460 reserved |= (uint32_t)(1 << 31);
461 }
462
463 if (m_flagS)
464 {
465 reserved |= (uint32_t)(1 << 30);
466 }
467
468 if (m_flagO)
469 {
470 reserved |= (uint32_t)(1 << 29);
471 }
472
473 i.WriteHtonU32(reserved);
474 m_target.Serialize(buff_target);
475 i.Write(buff_target, 16);
476
477 if (m_calcChecksum)
478 {
479 i = start;
480 checksum = i.CalculateIpChecksum(i.GetSize(), GetChecksum());
481 i = start;
482 i.Next(2);
483 i.WriteU16(checksum);
484 }
485}
486
489{
490 NS_LOG_FUNCTION(this << &start);
491 uint8_t buf[16];
492 Buffer::Iterator i = start;
493
494 SetType(i.ReadU8());
495 SetCode(i.ReadU8());
496 m_checksum = i.ReadU16();
498
499 m_flagR = false;
500 m_flagS = false;
501 m_flagO = false;
502
503 if (m_reserved & (1 << 31))
504 {
505 m_flagR = true;
506 }
507
508 if (m_reserved & (1 << 30))
509 {
510 m_flagS = true;
511 }
512
513 if (m_reserved & (1 << 29))
514 {
515 m_flagO = true;
516 }
517
518 i.Read(buf, 16);
519 m_target.Set(buf);
520
521 return GetSerializedSize();
522}
523
525
526TypeId
528{
529 static TypeId tid = TypeId("ns3::Icmpv6RA")
531 .SetGroupName("Internet")
532 .AddConstructor<Icmpv6RA>();
533 return tid;
534}
535
536TypeId
538{
539 NS_LOG_FUNCTION(this);
540 return GetTypeId();
541}
542
544{
545 NS_LOG_FUNCTION(this);
547 SetCode(0);
548 SetFlagM(false);
549 SetFlagO(false);
550 SetFlagH(false);
552 SetLifeTime(0);
555}
556
558{
559 NS_LOG_FUNCTION(this);
560}
561
562void
564{
565 NS_LOG_FUNCTION(this << static_cast<uint32_t>(m));
566 m_curHopLimit = m;
567}
568
569uint8_t
571{
572 NS_LOG_FUNCTION(this);
573 return m_curHopLimit;
574}
575
576uint16_t
578{
579 NS_LOG_FUNCTION(this);
580 return m_LifeTime;
581}
582
585{
586 NS_LOG_FUNCTION(this);
587 return m_ReachableTime;
588}
589
592{
593 NS_LOG_FUNCTION(this);
595}
596
597void
599{
600 NS_LOG_FUNCTION(this << l);
601 m_LifeTime = l;
602}
603
604void
606{
607 NS_LOG_FUNCTION(this << r);
608 m_ReachableTime = r;
609}
610
611void
613{
614 NS_LOG_FUNCTION(this << r);
616}
617
618bool
620{
621 NS_LOG_FUNCTION(this);
622 return m_flagM;
623}
624
625void
627{
628 NS_LOG_FUNCTION(this << m);
629 m_flagM = m;
630}
631
632bool
634{
635 NS_LOG_FUNCTION(this);
636 return m_flagO;
637}
638
639void
641{
642 NS_LOG_FUNCTION(this << o);
643 m_flagO = o;
644}
645
646bool
648{
649 NS_LOG_FUNCTION(this);
650 return m_flagH;
651}
652
653void
655{
656 NS_LOG_FUNCTION(this << h);
657 m_flagH = h;
658}
659
660void
661Icmpv6RA::Print(std::ostream& os) const
662{
663 NS_LOG_FUNCTION(this << &os);
664 os << "( type = " << (uint32_t)GetType() << " (RA) code = " << (uint32_t)GetCode()
665 << " checksum = " << (uint32_t)GetChecksum() << ")";
666}
667
670{
671 NS_LOG_FUNCTION(this);
672 return 16;
673}
674
675void
677{
678 NS_LOG_FUNCTION(this << &start);
679 uint16_t checksum = 0;
680 Buffer::Iterator i = start;
681 uint8_t flags = 0;
682
683 i.WriteU8(GetType());
684 i.WriteU8(GetCode());
685 i.WriteHtonU16(0);
687
688 if (m_flagM)
689 {
690 flags |= (uint8_t)(1 << 7);
691 }
692
693 if (m_flagO)
694 {
695 flags |= (uint8_t)(1 << 6);
696 }
697
698 if (m_flagH)
699 {
700 flags |= (uint8_t)(1 << 5);
701 }
702 i.WriteU8(flags);
706
707 i = start;
708 checksum = i.CalculateIpChecksum(i.GetSize(), GetChecksum());
709
710 i = start;
711 i.Next(2);
712 i.WriteU16(checksum);
713}
714
717{
718 NS_LOG_FUNCTION(this << &start);
719 Buffer::Iterator i = start;
720
721 SetType(i.ReadU8());
722 SetCode(i.ReadU8());
723 m_checksum = i.ReadU16();
725 uint8_t flags = i.ReadU8();
726 m_flagM = false;
727 m_flagO = false;
728 m_flagH = false;
729
730 if (flags & (1 << 7))
731 {
732 m_flagM = true;
733 }
734
735 if (flags & (1 << 6))
736 {
737 m_flagO = true;
738 }
739
740 if (flags & (1 << 5))
741 {
742 m_flagH = true;
743 }
747
748 return GetSerializedSize();
749}
750
752
753TypeId
755{
756 static TypeId tid = TypeId("ns3::Icmpv6RS")
758 .SetGroupName("Internet")
759 .AddConstructor<Icmpv6RS>();
760 return tid;
761}
762
763TypeId
765{
766 NS_LOG_FUNCTION(this);
767 return GetTypeId();
768}
769
771{
772 NS_LOG_FUNCTION(this);
774 SetCode(0);
775 SetReserved(0);
776}
777
779{
780 NS_LOG_FUNCTION(this);
781}
782
785{
786 NS_LOG_FUNCTION(this);
787 return m_reserved;
788}
789
790void
792{
793 NS_LOG_FUNCTION(this << reserved);
794 m_reserved = reserved;
795}
796
797void
798Icmpv6RS::Print(std::ostream& os) const
799{
800 NS_LOG_FUNCTION(this << &os);
801 os << "( type = " << (uint32_t)GetType() << " (RS) code = " << (uint32_t)GetCode()
802 << " checksum = " << (uint32_t)GetChecksum() << ")";
803}
804
807{
808 NS_LOG_FUNCTION(this);
809 return 8;
810}
811
812void
814{
815 NS_LOG_FUNCTION(this << &start);
816
817 uint16_t checksum = 0;
818 Buffer::Iterator i = start;
819
820 i.WriteU8(GetType());
821 i.WriteU8(GetCode());
822 i.WriteU16(0);
824
825 if (m_calcChecksum)
826 {
827 i = start;
828 checksum = i.CalculateIpChecksum(i.GetSize(), GetChecksum());
829
830 i = start;
831 i.Next(2);
832 i.WriteU16(checksum);
833 }
834}
835
838{
839 NS_LOG_FUNCTION(this << &start);
840 Buffer::Iterator i = start;
841
842 SetType(i.ReadU8());
843 SetCode(i.ReadU8());
844 m_checksum = i.ReadU16();
846
847 return GetSerializedSize();
848}
849
851
852TypeId
854{
855 static TypeId tid = TypeId("ns3::Icmpv6Redirection")
857 .SetGroupName("Internet")
858 .AddConstructor<Icmpv6Redirection>();
859 return tid;
860}
861
862TypeId
864{
865 NS_LOG_FUNCTION(this);
866 return GetTypeId();
867}
868
870 : m_target(Ipv6Address("")),
871 m_destination(Ipv6Address("")),
872 m_reserved(0)
873{
874 NS_LOG_FUNCTION(this);
876 SetCode(0);
877 m_checksum = 0;
878}
879
881{
882 NS_LOG_FUNCTION(this);
883}
884
885void
887{
888 NS_LOG_FUNCTION(this << reserved);
889 m_reserved = reserved;
890}
891
894{
895 NS_LOG_FUNCTION(this);
896 return m_reserved;
897}
898
901{
902 NS_LOG_FUNCTION(this);
903 return m_target;
904}
905
906void
908{
909 NS_LOG_FUNCTION(this << target);
910 m_target = target;
911}
912
915{
916 NS_LOG_FUNCTION(this);
917 return m_destination;
918}
919
920void
922{
923 NS_LOG_FUNCTION(this << destination);
924 m_destination = destination;
925}
926
927void
928Icmpv6Redirection::Print(std::ostream& os) const
929{
930 NS_LOG_FUNCTION(this << &os);
931 os << "( type = " << (uint32_t)GetType() << " (Redirection) code = " << (uint32_t)GetCode()
932 << " checksum = " << (uint32_t)GetChecksum() << " target = " << m_target
933 << " destination = " << m_destination << ")";
934}
935
938{
939 NS_LOG_FUNCTION(this);
940 return 40;
941}
942
943void
945{
946 NS_LOG_FUNCTION(this << &start);
947 uint8_t buff[16];
948 uint16_t checksum = 0;
949 Buffer::Iterator i = start;
950
951 i.WriteU8(GetType());
952 i.WriteU8(GetCode());
953 i.WriteU16(checksum);
955
956 m_target.Serialize(buff);
957 i.Write(buff, 16);
958
960 i.Write(buff, 16);
961
962 if (m_calcChecksum)
963 {
964 i = start;
965 checksum = i.CalculateIpChecksum(i.GetSize(), GetChecksum());
966
967 i = start;
968 i.Next(2);
969 i.WriteU16(checksum);
970 }
971}
972
975{
976 NS_LOG_FUNCTION(this << &start);
977 uint8_t buff[16];
978 Buffer::Iterator i = start;
979
980 SetType(i.ReadU8());
981 SetCode(i.ReadU8());
982 m_checksum = i.ReadU16();
983 SetReserved(i.ReadU32());
984
985 i.Read(buff, 16);
986 m_target.Set(buff);
987
988 i.Read(buff, 16);
989 m_destination.Set(buff);
990
991 return GetSerializedSize();
992}
993
995
996TypeId
998{
999 static TypeId tid = TypeId("ns3::Icmpv6Echo")
1001 .SetGroupName("Internet")
1002 .AddConstructor<Icmpv6Echo>();
1003 return tid;
1004}
1005
1006TypeId
1008{
1009 NS_LOG_FUNCTION(this);
1010 return GetTypeId();
1011}
1012
1014{
1015 NS_LOG_FUNCTION(this);
1017 SetCode(0);
1018 m_checksum = 0;
1019 SetId(0);
1020 SetSeq(0);
1021}
1022
1024{
1025 NS_LOG_FUNCTION(this << request);
1027 SetCode(0);
1028 m_checksum = 0;
1029 SetId(0);
1030 SetSeq(0);
1031}
1032
1034{
1035 NS_LOG_FUNCTION(this);
1036}
1037
1038uint16_t
1040{
1041 NS_LOG_FUNCTION(this);
1042 return m_id;
1043}
1044
1045void
1047{
1048 NS_LOG_FUNCTION(this << id);
1049 m_id = id;
1050}
1051
1052uint16_t
1054{
1055 NS_LOG_FUNCTION(this);
1056 return m_seq;
1057}
1058
1059void
1061{
1062 NS_LOG_FUNCTION(this << seq);
1063 m_seq = seq;
1064}
1065
1066void
1067Icmpv6Echo::Print(std::ostream& os) const
1068{
1069 NS_LOG_FUNCTION(this << &os);
1070 os << "( type = " << (GetType() == 128 ? "128 (Request)" : "129 (Reply)")
1071 << " Id = " << (uint32_t)GetId() << " SeqNo = " << (uint32_t)GetSeq()
1072 << " checksum = " << (uint32_t)GetChecksum() << ")";
1073}
1074
1077{
1078 NS_LOG_FUNCTION(this);
1079 return 8;
1080}
1081
1082void
1084{
1085 NS_LOG_FUNCTION(this << &start);
1086 uint16_t checksum = 0;
1087 Buffer::Iterator i = start;
1088
1089 i.WriteU8(GetType());
1090 i.WriteU8(GetCode());
1091 i.WriteHtonU16(0);
1092
1093 i.WriteHtonU16(m_id);
1095
1096 if (m_calcChecksum)
1097 {
1098 i = start;
1099 checksum = i.CalculateIpChecksum(i.GetSize(), GetChecksum());
1100 i = start;
1101 i.Next(2);
1102 i.WriteU16(checksum);
1103 }
1104}
1105
1108{
1109 NS_LOG_FUNCTION(this << &start);
1110 Buffer::Iterator i = start;
1111
1112 SetType(i.ReadU8());
1113 SetCode(i.ReadU8());
1114 m_checksum = i.ReadU16();
1115
1116 m_id = i.ReadNtohU16();
1117 m_seq = i.ReadNtohU16();
1118 return GetSerializedSize();
1119}
1120
1122
1123TypeId
1125{
1126 static TypeId tid = TypeId("ns3::Icmpv6DestinationUnreachable")
1128 .SetGroupName("Internet")
1129 .AddConstructor<Icmpv6DestinationUnreachable>();
1130 return tid;
1131}
1132
1133TypeId
1135{
1136 NS_LOG_FUNCTION(this);
1137 return GetTypeId();
1138}
1139
1141 : m_packet(nullptr)
1142{
1143 NS_LOG_FUNCTION(this);
1145}
1146
1148{
1149 NS_LOG_FUNCTION(this);
1150}
1151
1152void
1154{
1155 NS_LOG_FUNCTION(this << *p);
1156 NS_ASSERT(p->GetSize() <= 1280);
1157 m_packet = p->Copy();
1158}
1159
1160void
1162{
1163 NS_LOG_FUNCTION(this << &os);
1164 os << "( type = " << (uint32_t)GetType()
1165 << " (Destination Unreachable) code = " << (uint32_t)GetCode()
1166 << " checksum = " << (uint32_t)GetChecksum() << ")";
1167}
1168
1171{
1172 NS_LOG_FUNCTION(this);
1173 // The real size of the header is 8 + m_packet->GetSize ()
1174 // HOWEVER we just serialize the first 8 bytes, as the rest is serialized separately.
1175 return 8;
1176}
1177
1178void
1180{
1181 NS_LOG_FUNCTION(this << &start);
1182 uint16_t checksum = 0;
1183 Buffer::Iterator i = start;
1184
1185 Buffer secondaryBuffer;
1186 secondaryBuffer.AddAtStart(8 + m_packet->GetSize());
1187 Buffer::Iterator iter = secondaryBuffer.Begin();
1188
1189 iter.WriteU8(GetType());
1190 iter.WriteU8(GetCode());
1191 iter.WriteU16(0);
1192 iter.WriteU32(0);
1193
1194 uint32_t size = m_packet->GetSize();
1195 auto buf = new uint8_t[size];
1196 m_packet->CopyData(buf, size);
1197 iter.Write(buf, size);
1198 delete[] buf;
1199
1200 iter = secondaryBuffer.Begin();
1201 checksum = iter.CalculateIpChecksum(iter.GetSize(), GetChecksum());
1202
1203 i.WriteU8(GetType());
1204 i.WriteU8(GetCode());
1205 i.WriteU16(checksum);
1206 i.WriteU32(0);
1207}
1208
1211{
1212 NS_LOG_FUNCTION(this << &start);
1213 Buffer::Iterator i = start;
1214
1215 SetType(i.ReadU8());
1216 SetCode(i.ReadU8());
1217 m_checksum = i.ReadU16();
1218 i.ReadU32();
1219
1220 return GetSerializedSize();
1221}
1222
1224
1225TypeId
1227{
1228 static TypeId tid = TypeId("ns3::Icmpv6TooBig")
1230 .SetGroupName("Internet")
1231 .AddConstructor<Icmpv6TooBig>();
1232 return tid;
1233}
1234
1235TypeId
1237{
1238 NS_LOG_FUNCTION(this);
1239 return GetTypeId();
1240}
1241
1243 : m_packet(nullptr),
1244 m_mtu(0)
1245{
1246 NS_LOG_FUNCTION(this);
1248}
1249
1251{
1252 NS_LOG_FUNCTION(this);
1253}
1254
1255void
1257{
1258 NS_LOG_FUNCTION(this << *p);
1259 NS_ASSERT(p->GetSize() <= 1280);
1260 m_packet = p->Copy();
1261}
1262
1265{
1266 NS_LOG_FUNCTION(this);
1267 return m_mtu;
1268}
1269
1270void
1272{
1273 NS_LOG_FUNCTION(this << mtu);
1274 m_mtu = mtu;
1275}
1276
1277void
1278Icmpv6TooBig::Print(std::ostream& os) const
1279{
1280 NS_LOG_FUNCTION(this << &os);
1281 os << "( type = " << (uint32_t)GetType() << " (Too Big) code = " << (uint32_t)GetCode()
1282 << " checksum = " << (uint32_t)GetChecksum() << " mtu = " << (uint32_t)GetMtu() << ")";
1283}
1284
1287{
1288 NS_LOG_FUNCTION(this);
1289 // The real size of the header is 8 + m_packet->GetSize ()
1290 // HOWEVER we just serialize the first 8 bytes, as the rest is serialized separately.
1291 return 8;
1292}
1293
1294void
1296{
1297 NS_LOG_FUNCTION(this << &start);
1298 uint16_t checksum = 0;
1299 Buffer::Iterator i = start;
1300
1301 Buffer secondaryBuffer;
1302 secondaryBuffer.AddAtStart(8 + m_packet->GetSize());
1303 Buffer::Iterator iter = secondaryBuffer.Begin();
1304
1305 iter.WriteU8(GetType());
1306 iter.WriteU8(GetCode());
1307 iter.WriteU16(0);
1308 iter.WriteHtonU32(GetMtu());
1309
1310 uint32_t size = m_packet->GetSize();
1311 auto buf = new uint8_t[size];
1312 m_packet->CopyData(buf, size);
1313 iter.Write(buf, size);
1314 delete[] buf;
1315
1316 iter = secondaryBuffer.Begin();
1317 checksum = iter.CalculateIpChecksum(iter.GetSize(), GetChecksum());
1318
1319 i.WriteU8(GetType());
1320 i.WriteU8(GetCode());
1321 i.WriteU16(checksum);
1322 i.WriteHtonU32(GetMtu());
1323}
1324
1327{
1328 NS_LOG_FUNCTION(this << &start);
1329 Buffer::Iterator i = start;
1330
1331 SetType(i.ReadU8());
1332 SetCode(i.ReadU8());
1333 m_checksum = i.ReadU16();
1334 SetMtu(i.ReadNtohU32());
1335
1336 return GetSerializedSize();
1337}
1338
1340
1341TypeId
1343{
1344 static TypeId tid = TypeId("ns3::Icmpv6TimeExceeded")
1346 .SetGroupName("Internet")
1347 .AddConstructor<Icmpv6TimeExceeded>();
1348 return tid;
1349}
1350
1351TypeId
1353{
1354 NS_LOG_FUNCTION(this);
1355 return GetTypeId();
1356}
1357
1359 : m_packet(nullptr)
1360{
1361 NS_LOG_FUNCTION(this);
1363}
1364
1366{
1367 NS_LOG_FUNCTION(this);
1368}
1369
1370void
1372{
1373 NS_LOG_FUNCTION(this << *p);
1374 NS_ASSERT(p->GetSize() <= 1280);
1375 m_packet = p->Copy();
1376}
1377
1378void
1379Icmpv6TimeExceeded::Print(std::ostream& os) const
1380{
1381 NS_LOG_FUNCTION(this << &os);
1382 os << "( type = " << (uint32_t)GetType()
1383 << " (Destination Unreachable) code = " << (uint32_t)GetCode()
1384 << " checksum = " << (uint32_t)GetChecksum() << ")";
1385}
1386
1389{
1390 NS_LOG_FUNCTION(this);
1391 // The real size of the header is 8 + m_packet->GetSize ()
1392 // HOWEVER we just serialize the first 8 bytes, as the rest is serialized separately.
1393 return 8;
1394}
1395
1396void
1398{
1399 NS_LOG_FUNCTION(this << &start);
1400 uint16_t checksum = 0;
1401 Buffer::Iterator i = start;
1402
1403 Buffer secondaryBuffer;
1404 secondaryBuffer.AddAtStart(8 + m_packet->GetSize());
1405 Buffer::Iterator iter = secondaryBuffer.Begin();
1406
1407 iter.WriteU8(GetType());
1408 iter.WriteU8(GetCode());
1409 iter.WriteU16(0);
1410 iter.WriteU32(0);
1411
1412 uint32_t size = m_packet->GetSize();
1413 auto buf = new uint8_t[size];
1414 m_packet->CopyData(buf, size);
1415 iter.Write(buf, size);
1416 delete[] buf;
1417
1418 iter = secondaryBuffer.Begin();
1419 checksum = iter.CalculateIpChecksum(iter.GetSize(), GetChecksum());
1420
1421 i.WriteU8(GetType());
1422 i.WriteU8(GetCode());
1423 i.WriteU16(checksum);
1424 i.WriteU32(0);
1425}
1426
1429{
1430 NS_LOG_FUNCTION(this << &start);
1431 Buffer::Iterator i = start;
1432
1433 SetType(i.ReadU8());
1434 SetCode(i.ReadU8());
1435 m_checksum = i.ReadU16();
1436 i.ReadU32();
1437
1438 return GetSerializedSize();
1439}
1440
1442
1443TypeId
1445{
1446 static TypeId tid = TypeId("ns3::Icmpv6ParameterError")
1448 .SetGroupName("Internet")
1449 .AddConstructor<Icmpv6ParameterError>();
1450 return tid;
1451}
1452
1453TypeId
1455{
1456 NS_LOG_FUNCTION(this);
1457 return GetTypeId();
1458}
1459
1461 : m_packet(nullptr),
1462 m_ptr(0)
1463{
1464 NS_LOG_FUNCTION(this);
1466}
1467
1469{
1470 NS_LOG_FUNCTION(this);
1471}
1472
1473void
1475{
1476 NS_LOG_FUNCTION(this << *p);
1477 NS_ASSERT(p->GetSize() <= 1280);
1478 m_packet = p->Copy();
1479}
1480
1483{
1484 NS_LOG_FUNCTION(this);
1485 return m_ptr;
1486}
1487
1488void
1490{
1491 NS_LOG_FUNCTION(this << ptr);
1492 m_ptr = ptr;
1493}
1494
1495void
1496Icmpv6ParameterError::Print(std::ostream& os) const
1497{
1498 NS_LOG_FUNCTION(this << &os);
1499 os << "( type = " << (uint32_t)GetType()
1500 << " (Destination Unreachable) code = " << (uint32_t)GetCode()
1501 << " checksum = " << (uint32_t)GetChecksum() << " ptr = " << (uint32_t)GetPtr() << ")";
1502}
1503
1506{
1507 NS_LOG_FUNCTION(this);
1508 // The real size of the header is 8 + m_packet->GetSize ()
1509 // HOWEVER we just serialize the first 8 bytes, as the rest is serialized separately.
1510 return 8;
1511}
1512
1513void
1515{
1516 NS_LOG_FUNCTION(this << &start);
1517 uint16_t checksum = 0;
1518 Buffer::Iterator i = start;
1519
1520 Buffer secondaryBuffer;
1521 secondaryBuffer.AddAtStart(8 + m_packet->GetSize());
1522 Buffer::Iterator iter = secondaryBuffer.Begin();
1523
1524 iter.WriteU8(GetType());
1525 iter.WriteU8(GetCode());
1526 iter.WriteU16(0);
1527 iter.WriteHtonU32(GetPtr());
1528
1529 uint32_t size = m_packet->GetSize();
1530 auto buf = new uint8_t[size];
1531 m_packet->CopyData(buf, size);
1532 iter.Write(buf, size);
1533 delete[] buf;
1534
1535 iter = secondaryBuffer.Begin();
1536 checksum = iter.CalculateIpChecksum(iter.GetSize(), GetChecksum());
1537
1538 i.WriteU8(GetType());
1539 i.WriteU8(GetCode());
1540 i.WriteU16(checksum);
1541 i.WriteHtonU32(GetPtr());
1542}
1543
1546{
1547 NS_LOG_FUNCTION(this << &start);
1548 Buffer::Iterator i = start;
1549
1550 SetType(i.ReadU8());
1551 SetCode(i.ReadU8());
1552 m_checksum = i.ReadU16();
1553 SetPtr(i.ReadNtohU32());
1554
1555 return GetSerializedSize();
1556}
1557
1559
1560TypeId
1562{
1563 static TypeId tid = TypeId("ns3::Icmpv6OptionHeader")
1564 .SetParent<Header>()
1565 .SetGroupName("Internet")
1566 .AddConstructor<Icmpv6OptionHeader>();
1567 return tid;
1568}
1569
1570TypeId
1572{
1573 NS_LOG_FUNCTION(this);
1574 return GetTypeId();
1575}
1576
1578{
1579 NS_LOG_FUNCTION(this);
1580 /** \todo */
1581 m_type = 0;
1582 m_len = 0;
1583}
1584
1586{
1587 NS_LOG_FUNCTION(this);
1588}
1589
1590uint8_t
1592{
1593 NS_LOG_FUNCTION(this);
1594 return m_type;
1595}
1596
1597void
1599{
1600 NS_LOG_FUNCTION(this << static_cast<uint32_t>(type));
1601 m_type = type;
1602}
1603
1604uint8_t
1606{
1607 NS_LOG_FUNCTION(this);
1608 return m_len;
1609}
1610
1611void
1613{
1614 NS_LOG_FUNCTION(this << static_cast<uint32_t>(len));
1615 m_len = len;
1616}
1617
1618void
1619Icmpv6OptionHeader::Print(std::ostream& os) const
1620{
1621 NS_LOG_FUNCTION(this << &os);
1622 os << "( type = " << (uint32_t)GetType() << " length = " << (uint32_t)GetLength() << ")";
1623}
1624
1627{
1628 NS_LOG_FUNCTION(this);
1629 return m_len * 8;
1630}
1631
1634{
1635 NS_LOG_FUNCTION(this << &start);
1636 return GetSerializedSize();
1637}
1638
1639void
1641{
1642 NS_LOG_FUNCTION(this << &start);
1643}
1644
1646
1647TypeId
1649{
1650 static TypeId tid = TypeId("ns3::Icmpv6OptionMtu")
1652 .SetGroupName("Internet")
1653 .AddConstructor<Icmpv6OptionMtu>();
1654 return tid;
1655}
1656
1657TypeId
1659{
1660 NS_LOG_FUNCTION(this);
1661 return GetTypeId();
1662}
1663
1665{
1666 NS_LOG_FUNCTION(this);
1668 SetLength(1);
1669 SetReserved(0);
1670}
1671
1673 : m_mtu(mtu)
1674{
1675 NS_LOG_FUNCTION(this << mtu);
1677 SetLength(1);
1678 SetReserved(0);
1679}
1680
1682{
1683 NS_LOG_FUNCTION(this);
1684}
1685
1686uint16_t
1688{
1689 NS_LOG_FUNCTION(this);
1690 return m_reserved;
1691}
1692
1693void
1695{
1696 NS_LOG_FUNCTION(this << reserved);
1697 m_reserved = reserved;
1698}
1699
1702{
1703 NS_LOG_FUNCTION(this);
1704 return m_mtu;
1705}
1706
1707void
1709{
1710 NS_LOG_FUNCTION(this << mtu);
1711 m_mtu = mtu;
1712}
1713
1714void
1715Icmpv6OptionMtu::Print(std::ostream& os) const
1716{
1717 NS_LOG_FUNCTION(this << &os);
1718 os << "( type = " << (uint32_t)GetType() << " length = " << (uint32_t)GetLength()
1719 << " MTU = " << m_mtu << ")";
1720}
1721
1724{
1725 NS_LOG_FUNCTION(this);
1726 return 8; /* m_len = 1 so the real size is multiple by 8 */
1727}
1728
1729void
1731{
1732 NS_LOG_FUNCTION(this << &start);
1733 Buffer::Iterator i = start;
1734 i.WriteU8(GetType());
1735 i.WriteU8(GetLength());
1737 i.WriteHtonU32(GetMtu());
1738}
1739
1742{
1743 NS_LOG_FUNCTION(this << &start);
1744 Buffer::Iterator i = start;
1745 SetType(i.ReadU8());
1746 SetLength(i.ReadU8());
1748 SetMtu(i.ReadNtohU32());
1749 return GetSerializedSize();
1750}
1751
1753
1754TypeId
1756{
1757 static TypeId tid = TypeId("ns3::Icmpv6OptionPrefixInformation")
1759 .SetGroupName("Internet")
1760 .AddConstructor<Icmpv6OptionPrefixInformation>();
1761 return tid;
1762}
1763
1764TypeId
1766{
1767 NS_LOG_FUNCTION(this);
1768 return GetTypeId();
1769}
1770
1772{
1773 NS_LOG_FUNCTION(this);
1775 SetLength(4);
1776 SetPrefix(Ipv6Address("::"));
1777 SetPrefixLength(0);
1778 SetValidTime(0);
1780 SetFlags(0);
1781 SetReserved(0);
1782}
1783
1785{
1786 NS_LOG_FUNCTION(this << prefix << static_cast<uint32_t>(prefixlen));
1788 SetLength(4);
1789 SetPrefix(prefix);
1790 SetPrefixLength(prefixlen);
1791 SetValidTime(0);
1793 SetFlags(0);
1794 SetReserved(0);
1795}
1796
1798{
1799 NS_LOG_FUNCTION(this);
1800}
1801
1802uint8_t
1804{
1805 NS_LOG_FUNCTION(this);
1806 return m_prefixLength;
1807}
1808
1809void
1811{
1812 NS_LOG_FUNCTION(this << static_cast<uint32_t>(prefixLength));
1813 NS_ASSERT(prefixLength <= 128);
1814 m_prefixLength = prefixLength;
1815}
1816
1817uint8_t
1819{
1820 NS_LOG_FUNCTION(this);
1821 return m_flags;
1822}
1823
1824void
1826{
1827 NS_LOG_FUNCTION(this);
1828 m_flags = flags;
1829}
1830
1833{
1834 NS_LOG_FUNCTION(this);
1835 return m_validTime;
1836}
1837
1838void
1840{
1841 NS_LOG_FUNCTION(this << validTime);
1842 m_validTime = validTime;
1843}
1844
1847{
1848 NS_LOG_FUNCTION(this);
1849 return m_preferredTime;
1850}
1851
1852void
1854{
1855 NS_LOG_FUNCTION(this << preferredTime);
1856 m_preferredTime = preferredTime;
1857}
1858
1861{
1862 NS_LOG_FUNCTION(this);
1863 return m_preferredTime;
1864}
1865
1866void
1868{
1869 NS_LOG_FUNCTION(this << reserved);
1870 m_reserved = reserved;
1871}
1872
1875{
1876 NS_LOG_FUNCTION(this);
1877 return m_prefix;
1878}
1879
1880void
1882{
1883 NS_LOG_FUNCTION(this << prefix);
1884 m_prefix = prefix;
1885}
1886
1887void
1889{
1890 NS_LOG_FUNCTION(this << &os);
1891 os << "( type = " << (uint32_t)GetType() << " length = " << (uint32_t)GetLength() << " prefix "
1892 << m_prefix << ")";
1893}
1894
1897{
1898 NS_LOG_FUNCTION(this);
1899 return 32;
1900}
1901
1902void
1904{
1905 NS_LOG_FUNCTION(this << &start);
1906 Buffer::Iterator i = start;
1907 uint8_t buf[16];
1908
1909 memset(buf, 0x00, sizeof(buf));
1910
1911 i.WriteU8(GetType());
1912 i.WriteU8(GetLength());
1914 i.WriteU8(m_flags);
1918 m_prefix.GetBytes(buf);
1919 i.Write(buf, 16);
1920}
1921
1924{
1925 NS_LOG_FUNCTION(this << &start);
1926 Buffer::Iterator i = start;
1927 uint8_t buf[16];
1928
1929 SetType(i.ReadU8());
1930 SetLength(i.ReadU8());
1932 SetFlags(i.ReadU8());
1936 i.Read(buf, 16);
1937
1938 Ipv6Address prefix(buf);
1939 SetPrefix(prefix);
1940
1941 return GetSerializedSize();
1942}
1943
1945
1946TypeId
1948{
1949 static TypeId tid = TypeId("ns3::Icmpv6OptionLinkLayerAddress")
1951 .SetGroupName("Internet")
1952 .AddConstructor<Icmpv6OptionLinkLayerAddress>();
1953 return tid;
1954}
1955
1956TypeId
1958{
1959 NS_LOG_FUNCTION(this);
1960 return GetTypeId();
1961}
1962
1964{
1965 NS_LOG_FUNCTION(this << source);
1968}
1969
1971{
1972 NS_LOG_FUNCTION(this);
1974}
1975
1977{
1978 NS_LOG_FUNCTION(this << source << addr);
1981 SetAddress(addr);
1982
1983 uint8_t len = (2 + m_addr.GetLength()) / 8;
1984 if ((2 + m_addr.GetLength()) % 8)
1985 {
1986 len++;
1987 }
1988 SetLength(len);
1989}
1990
1992{
1993 NS_LOG_FUNCTION(this);
1994}
1995
1996Address
1998{
1999 NS_LOG_FUNCTION(this);
2000 return m_addr;
2001}
2002
2003void
2005{
2006 NS_LOG_FUNCTION(this << addr);
2007 m_addr = addr;
2008}
2009
2010void
2012{
2013 NS_LOG_FUNCTION(this << &os);
2014 os << "( type = " << (uint32_t)GetType() << " length = " << (uint32_t)GetLength()
2015 << " L2 Address = " << m_addr << ")";
2016}
2017
2020{
2021 NS_LOG_FUNCTION(this);
2022 uint8_t nb = GetLength() * 8;
2023 return nb;
2024}
2025
2026void
2028{
2029 NS_LOG_FUNCTION(this << &start);
2030 Buffer::Iterator i = start;
2031 uint8_t mac[32];
2032
2033 i.WriteU8(GetType());
2034 i.WriteU8(GetLength());
2035 m_addr.CopyTo(mac);
2036 i.Write(mac, m_addr.GetLength());
2037
2038 uint8_t len = GetLength() * 8 - (2 + m_addr.GetLength());
2039 for (uint8_t nb = 0; nb < len; nb++)
2040 {
2041 i.WriteU8(0);
2042 }
2043}
2044
2047{
2048 NS_LOG_FUNCTION(this << &start);
2049 Buffer::Iterator i = start;
2050 uint8_t mac[32];
2051
2052 SetType(i.ReadU8());
2053 SetLength(i.ReadU8());
2054 // -fstrict-overflow sensitive, see bug 1868
2055 NS_ASSERT(GetLength() * 8 <= 32 + 2);
2056 i.Read(mac, (GetLength() * 8) - 2);
2057
2058 m_addr.CopyFrom(mac, (GetLength() * 8) - 2);
2059
2060 return GetSerializedSize();
2061}
2062
2064
2065TypeId
2067{
2068 static TypeId tid = TypeId("ns3::Icmpv6OptionRedirected")
2070 .SetGroupName("Internet")
2071 .AddConstructor<Icmpv6OptionRedirected>();
2072 return tid;
2073}
2074
2075TypeId
2077{
2078 NS_LOG_FUNCTION(this);
2079 return GetTypeId();
2080}
2081
2083 : m_packet(nullptr)
2084{
2085 NS_LOG_FUNCTION(this);
2087}
2088
2090{
2091 NS_LOG_FUNCTION(this);
2092 m_packet = nullptr;
2093}
2094
2095void
2097{
2098 NS_LOG_FUNCTION(this << *packet);
2099 NS_ASSERT(packet->GetSize() <= 1280);
2100 m_packet = packet->Copy();
2101 SetLength(1 + (m_packet->GetSize() / 8));
2102}
2103
2104void
2105Icmpv6OptionRedirected::Print(std::ostream& os) const
2106{
2107 NS_LOG_FUNCTION(this << &os);
2108 os << "( type = " << (uint32_t)GetType() << " length = " << (uint32_t)GetLength() << ")";
2109}
2110
2113{
2114 NS_LOG_FUNCTION(this);
2115 return 8 + m_packet->GetSize();
2116}
2117
2118void
2120{
2121 NS_LOG_FUNCTION(this << &start);
2122 Buffer::Iterator i = start;
2123
2124 i.WriteU8(GetType());
2125 i.WriteU8(GetLength());
2126 // Reserved
2127 i.WriteU16(0);
2128 i.WriteU32(0);
2129
2130 uint32_t size = m_packet->GetSize();
2131 auto buf = new uint8_t[size];
2132 m_packet->CopyData(buf, size);
2133 i.Write(buf, size);
2134 delete[] buf;
2135}
2136
2139{
2140 NS_LOG_FUNCTION(this << &start);
2141 Buffer::Iterator i = start;
2142
2143 SetType(i.ReadU8());
2144 uint8_t length = i.ReadU8();
2145 SetLength(length);
2146 i.ReadU16();
2147 i.ReadU32();
2148
2149 uint32_t len2 = (GetLength() - 1) * 8;
2150 auto buff = new uint8_t[len2];
2151 i.Read(buff, len2);
2152 m_packet = Create<Packet>(buff, len2);
2153 delete[] buff;
2154
2155 return GetSerializedSize();
2156}
2157
2158} /* namespace ns3 */
a polymophic address class
Definition: address.h:101
uint32_t CopyFrom(const uint8_t *buffer, uint8_t len)
Definition: address.cc:106
uint8_t GetLength() const
Get the length of the underlying address.
Definition: address.cc:78
uint32_t CopyTo(uint8_t buffer[MAX_SIZE]) const
Copy the address bytes into a buffer.
Definition: address.cc:86
iterator in a Buffer instance
Definition: buffer.h:100
void WriteU32(uint32_t data)
Definition: buffer.cc:868
uint8_t ReadU8()
Definition: buffer.h:1027
uint16_t CalculateIpChecksum(uint16_t size)
Calculate the checksum.
Definition: buffer.cc:1135
void WriteU8(uint8_t data)
Definition: buffer.h:881
void Write(const uint8_t *buffer, uint32_t size)
Definition: buffer.cc:948
void WriteU16(uint16_t data)
Definition: buffer.cc:859
void Read(uint8_t *buffer, uint32_t size)
Definition: buffer.cc:1125
void WriteHtonU16(uint16_t data)
Definition: buffer.h:915
uint32_t ReadNtohU32()
Definition: buffer.h:978
uint32_t ReadU32()
Definition: buffer.cc:966
void WriteHtonU32(uint32_t data)
Definition: buffer.h:933
uint16_t ReadNtohU16()
Definition: buffer.h:954
uint32_t GetSize() const
Definition: buffer.cc:1166
uint16_t ReadU16()
Definition: buffer.h:1035
void Next()
go forward by one byte
Definition: buffer.h:853
automatically resized byte buffer
Definition: buffer.h:94
void AddAtStart(uint32_t start)
Definition: buffer.cc:314
Buffer::Iterator Begin() const
Definition: buffer.h:1074
Protocol header serialization and deserialization.
Definition: header.h:44
ICMPv6 Error Destination Unreachable header.
uint32_t GetSerializedSize() const override
Get the serialized size.
void SetPacket(Ptr< Packet > p)
Set the incorrect packet.
~Icmpv6DestinationUnreachable() override
Destructor.
void Print(std::ostream &os) const override
Print information.
TypeId GetInstanceTypeId() const override
Get the instance type ID.
void Serialize(Buffer::Iterator start) const override
Serialize the packet.
Ptr< Packet > m_packet
The incorrect Packet.
static TypeId GetTypeId()
Get the UID of this class.
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the packet.
ICMPv6 Echo message.
static TypeId GetTypeId()
Get the UID of this class.
void SetId(uint16_t id)
Set the ID of the packet.
uint16_t m_seq
Sequence number (to distinguish response).
Icmpv6Echo()
Default constructor.
~Icmpv6Echo() override
Destructor.
uint16_t m_id
ID of the packet (to distinguish response between many ping program).
uint16_t GetId() const
Get the ID of the packet.
void Print(std::ostream &os) const override
Print information.
void SetSeq(uint16_t seq)
Set the sequence number.
uint32_t GetSerializedSize() const override
Get the serialized size.
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the packet.
uint16_t GetSeq() const
Get the sequence number.
TypeId GetInstanceTypeId() const override
Get the instance type ID.
void Serialize(Buffer::Iterator start) const override
Serialize the packet.
ICMPv6 header.
Definition: icmpv6-header.h:38
uint8_t GetCode() const
Get the code field.
uint8_t GetType() const
Get the type field.
Icmpv6Header()
Constructor.
uint8_t m_code
The code.
uint16_t GetChecksum() const
Get the checksum.
TypeId GetInstanceTypeId() const override
Get the instance type ID.
static TypeId GetTypeId()
Get the UID of this class.
uint16_t m_checksum
The checksum.
void Serialize(Buffer::Iterator start) const override
Serialize the packet.
void CalculatePseudoHeaderChecksum(Ipv6Address src, Ipv6Address dst, uint16_t length, uint8_t protocol)
Calculate pseudo header checksum for IPv6.
void SetCode(uint8_t code)
Set the code field.
uint8_t m_type
The type.
uint32_t GetSerializedSize() const override
Get the serialized size.
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the packet.
void SetType(uint8_t type)
Set the type.
@ ICMPV6_ND_NEIGHBOR_ADVERTISEMENT
Definition: icmpv6-header.h:57
@ ICMPV6_ERROR_DESTINATION_UNREACHABLE
Definition: icmpv6-header.h:45
~Icmpv6Header() override
Destructor.
void SetChecksum(uint16_t checksum)
Set the checksum.
void Print(std::ostream &os) const override
Print information.
bool m_calcChecksum
Checksum enable or not.
ICMPv6 Neighbor Advertisement header.
bool GetFlagS() const
Get the S flag.
void Serialize(Buffer::Iterator start) const override
Serialize the packet.
bool m_flagS
The O flag.
uint32_t m_reserved
The reserved value.
~Icmpv6NA() override
Destructor.
TypeId GetInstanceTypeId() const override
Get the instance type ID.
void SetFlagS(bool s)
Set the S flag.
void SetIpv6Target(Ipv6Address target)
Set the IPv6 target field.
void SetFlagR(bool r)
Set the R flag.
Ipv6Address GetIpv6Target() const
Get the IPv6 target field.
bool GetFlagR() const
Get the R flag.
uint32_t GetSerializedSize() const override
Get the serialized size.
bool GetFlagO() const
Get the O flag.
void SetFlagO(bool o)
Set the O flag.
Icmpv6NA()
Constructor.
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the packet.
bool m_flagR
The R flag.
void SetReserved(uint32_t reserved)
Set the reserved field.
void Print(std::ostream &os) const override
Print information.
static TypeId GetTypeId()
Get the UID of this class.
Ipv6Address m_target
The IPv6 target address.
bool m_flagO
The M flag.
uint32_t GetReserved() const
Get the reserved field.
ICMPv6 Neighbor Solicitation header.
uint32_t m_reserved
The reserved value.
uint32_t GetSerializedSize() const override
Get the serialized size.
void SetIpv6Target(Ipv6Address target)
Set the IPv6 target field.
uint32_t GetReserved() const
Get the reserved field.
void Serialize(Buffer::Iterator start) const override
Serialize the packet.
static TypeId GetTypeId()
Get the UID of this class.
void Print(std::ostream &os) const override
Print information.
Ipv6Address m_target
The IPv6 target address.
void SetReserved(uint32_t reserved)
Set the reserved field.
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the packet.
TypeId GetInstanceTypeId() const override
Get the instance type ID.
Ipv6Address GetIpv6Target() const
Get the IPv6 target field.
~Icmpv6NS() override
Destructor.
Icmpv6NS()
Constructor.
ICMPv6 option header.
void SetType(uint8_t type)
Set the type of the option.
Icmpv6OptionHeader()
Constructor.
void Print(std::ostream &os) const override
Print information.
void Serialize(Buffer::Iterator start) const override
Serialize the packet.
uint8_t m_len
The length.
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the packet.
uint8_t m_type
The type.
TypeId GetInstanceTypeId() const override
Get the instance type ID.
static TypeId GetTypeId()
Get the UID of this class.
uint8_t GetType() const
Get the type of the option.
~Icmpv6OptionHeader() override
Destructor.
void SetLength(uint8_t len)
Set the length of the option.
uint32_t GetSerializedSize() const override
Get the serialized size.
uint8_t GetLength() const
Get the length of the option in 8 bytes unit.
ICMPv6 MTU option.
~Icmpv6OptionMtu() override
Destructor.
uint32_t GetSerializedSize() const override
Get the serialized size.
uint16_t m_reserved
The reserved value.
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the packet.
void SetReserved(uint16_t reserved)
Set the reserved field.
uint32_t GetMtu() const
Get the MTU.
static TypeId GetTypeId()
Get the UID of this class.
TypeId GetInstanceTypeId() const override
Get the instance type ID.
void Serialize(Buffer::Iterator start) const override
Serialize the packet.
void Print(std::ostream &os) const override
Print information.
void SetMtu(uint32_t mtu)
Set the MTU.
uint32_t m_mtu
The MTU value.
Icmpv6OptionMtu()
Constructor.
uint16_t GetReserved() const
Get the reserved field.
ICMPv6 Option Prefix Information.
uint32_t GetValidTime() const
Get the valid time of the information.
uint8_t m_prefixLength
The length of the prefix.
void SetReserved(uint32_t reserved)
Set the reserved field (normally it will be 0x00000000).
void SetValidTime(uint32_t validTime)
Set the valid time of the information.
TypeId GetInstanceTypeId() const override
Get the instance type ID.
void SetPrefix(Ipv6Address prefix)
Set the IPv6 prefix.
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the packet.
Ipv6Address GetPrefix() const
Get the IPv6 prefix.
void SetFlags(uint8_t flags)
Set the flags.
void Print(std::ostream &os) const override
Print information.
uint32_t GetSerializedSize() const override
Get the serialized size.
~Icmpv6OptionPrefixInformation() override
Destructor.
void SetPrefixLength(uint8_t prefixLength)
Set the prefix length.
Ipv6Address m_prefix
The prefix value.
uint32_t m_reserved
The reserved field.
uint8_t GetPrefixLength() const
Get the prefix length.
void SetPreferredTime(uint32_t preferredTime)
Set the preferred time of the information.
uint32_t m_preferredTime
The preferred time.
uint8_t GetFlags() const
Get the flags.
uint32_t GetReserved() const
Get the reserved field.
uint32_t m_validTime
The valid time.
static TypeId GetTypeId()
Get the UID of this class.
void Serialize(Buffer::Iterator start) const override
Serialize the packet.
uint32_t GetPreferredTime() const
Get the preferred time of the information.
ICMPv6 redirected option.
Icmpv6OptionRedirected()
Constructor.
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the packet.
~Icmpv6OptionRedirected() override
Destructor.
Ptr< Packet > m_packet
The redirected packet.
void Print(std::ostream &os) const override
Print information.
uint32_t GetSerializedSize() const override
Get the serialized size.
static TypeId GetTypeId()
Get the UID of this class.
void SetPacket(Ptr< Packet > packet)
Set the redirected packet.
TypeId GetInstanceTypeId() const override
Get the instance type ID.
void Serialize(Buffer::Iterator start) const override
Serialize the packet.
ICMPv6 Error Parameter Error header.
uint32_t GetSerializedSize() const override
Get the serialized size.
uint32_t m_ptr
The pointer field.
void SetPacket(Ptr< Packet > p)
Set the incorrect packet.
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the packet.
static TypeId GetTypeId()
Get the UID of this class.
void SetPtr(uint32_t ptr)
Set the pointer field.
void Serialize(Buffer::Iterator start) const override
Serialize the packet.
~Icmpv6ParameterError() override
Destructor.
void Print(std::ostream &os) const override
Print information.
Ptr< Packet > m_packet
The incorrect packet.
uint32_t GetPtr() const
Get the pointer field.
TypeId GetInstanceTypeId() const override
Get the instance type ID.
Icmpv6ParameterError()
Constructor.
ICMPv6 Router Advertisement header.
void Print(std::ostream &os) const override
Print information.
Icmpv6RA()
Constructor.
void SetLifeTime(uint16_t l)
Set the node Life time (Neighbor Discovery).
bool m_flagM
The M flag.
uint32_t GetRetransmissionTime() const
Get the node Retransmission time (Neighbor Discovery).
bool m_flagO
The O flag.
void SetFlagH(bool h)
Set the H flag.
void SetRetransmissionTime(uint32_t r)
Set the node Retransmission time (Neighbor Discovery).
void SetCurHopLimit(uint8_t m)
Set the IPv6 maximum number of jumps.
void SetFlagO(bool o)
Set the O flag.
void Serialize(Buffer::Iterator start) const override
Serialize the packet.
void SetFlagM(bool m)
Set the M flag.
void SetReachableTime(uint32_t r)
Set the node Reachable time (Neighbor Discovery).
static TypeId GetTypeId()
Get the UID of this class.
TypeId GetInstanceTypeId() const override
Get the instance type ID.
uint32_t m_RetransmissionTimer
The retransmission timer.
uint32_t GetSerializedSize() const override
Get the serialized size.
uint16_t GetLifeTime() const
Get the node Life time (Neighbor Discovery).
uint32_t GetReachableTime() const
Get the node Reachable time (Neighbor Discovery).
uint8_t GetCurHopLimit() const
Get the IPv6 maximum number of jumps.
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the packet.
bool GetFlagO() const
Get the O flag.
uint16_t m_LifeTime
The lifetime value.
bool GetFlagM() const
Get the M flag.
uint8_t m_curHopLimit
The max jumps.
uint32_t m_ReachableTime
The reachable time value.
bool m_flagH
The H flag.
~Icmpv6RA() override
Destructor.
bool GetFlagH() const
Get the H flag.
ICMPv6 Router Solicitation header.
void SetReserved(uint32_t reserved)
Set the reserved field.
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the packet.
~Icmpv6RS() override
Destructor.
uint32_t GetReserved() const
Get the reserved field.
void Serialize(Buffer::Iterator start) const override
Serialize the packet.
uint32_t GetSerializedSize() const override
Get the serialized size.
uint32_t m_reserved
The reserved value.
static TypeId GetTypeId()
Get the UID of this class.
void Print(std::ostream &os) const override
Print information.
TypeId GetInstanceTypeId() const override
Get the instance type ID.
Icmpv6RS()
Constructor.
ICMPv6 Redirection header.
Ipv6Address m_target
IPv6 target address.
Ipv6Address GetTarget() const
Get the IPv6 target address.
Ipv6Address m_destination
IPv6 destination address.
uint32_t GetReserved() const
Get the reserved field.
uint32_t GetSerializedSize() const override
Get the serialized size.
~Icmpv6Redirection() override
Destructor.
void Print(std::ostream &os) const override
Print information.
Icmpv6Redirection()
Constructor.
void SetDestination(Ipv6Address destination)
Set the IPv6 destination address.
void SetReserved(uint32_t reserved)
Set the reserved field.
Ipv6Address GetDestination() const
Get the IPv6 destination address.
void SetTarget(Ipv6Address target)
Set the IPv6 target address.
TypeId GetInstanceTypeId() const override
Get the instance type ID.
static TypeId GetTypeId()
Get the UID of this class.
void Serialize(Buffer::Iterator start) const override
Serialize the packet.
uint32_t m_reserved
Reserved value.
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the packet.
ICMPv6 Error Time Exceeded header.
uint32_t GetSerializedSize() const override
Get the serialized size.
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the packet.
TypeId GetInstanceTypeId() const override
Get the instance type ID.
void SetPacket(Ptr< Packet > p)
Set the incorrect packet.
~Icmpv6TimeExceeded() override
Destructor.
Icmpv6TimeExceeded()
Constructor.
static TypeId GetTypeId()
Get the UID of this class.
void Print(std::ostream &os) const override
Print information.
Ptr< Packet > m_packet
The incorrect packet.
void Serialize(Buffer::Iterator start) const override
Serialize the packet.
ICMPv6 Error Too Big header.
static TypeId GetTypeId()
Get the UID of this class.
void SetMtu(uint32_t mtu)
Set the MTU.
void Print(std::ostream &os) const override
Print information.
Ptr< Packet > m_packet
the incorrect packet.
Icmpv6TooBig()
Constructor.
TypeId GetInstanceTypeId() const override
Get the instance type ID.
uint32_t GetSerializedSize() const override
Get the serialized size.
~Icmpv6TooBig() override
Destructor.
void SetPacket(Ptr< Packet > p)
Set the incorrect packet.
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the packet.
uint32_t m_mtu
The MTU value.
void Serialize(Buffer::Iterator start) const override
Serialize the packet.
uint32_t GetMtu() const
Get the MTU field.
Describes an IPv6 address.
Definition: ipv6-address.h:49
void GetBytes(uint8_t buf[16]) const
Get the bytes corresponding to the address.
void Set(const char *address)
Sets an Ipv6Address by parsing the input C-string.
void Serialize(uint8_t buf[16]) const
Serialize this address to a 16-byte buffer.
uint32_t GetSize() const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:861
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
Copy the packet contents to a byte buffer.
Definition: packet.cc:400
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:932
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Every class exported by the ns3 library is enclosed in the ns3 namespace.