A Discrete-Event Network Simulator
API
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);
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);
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;
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];
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(0);
350 SetFlagS(0);
351 SetFlagO(0);
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;
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];
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(0);
549 SetFlagO(0);
550 SetFlagH(0);
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
660uint8_t
662{
663 NS_LOG_FUNCTION(this);
664 return 0;
665}
666
667void
669{
670 NS_LOG_FUNCTION(this << static_cast<uint32_t>(f));
671}
672
673void
674Icmpv6RA::Print(std::ostream& os) const
675{
676 NS_LOG_FUNCTION(this << &os);
677 os << "( type = " << (uint32_t)GetType() << " (RA) code = " << (uint32_t)GetCode()
678 << " checksum = " << (uint32_t)GetChecksum() << ")";
679}
680
683{
684 NS_LOG_FUNCTION(this);
685 return 16;
686}
687
688void
690{
691 NS_LOG_FUNCTION(this << &start);
692 uint16_t checksum = 0;
694 uint8_t flags = 0;
695
696 i.WriteU8(GetType());
697 i.WriteU8(GetCode());
698 i.WriteHtonU16(0);
700
701 if (m_flagM)
702 {
703 flags |= (uint8_t)(1 << 7);
704 }
705
706 if (m_flagO)
707 {
708 flags |= (uint8_t)(1 << 6);
709 }
710
711 if (m_flagH)
712 {
713 flags |= (uint8_t)(1 << 5);
714 }
715 i.WriteU8(flags);
719
720 i = start;
721 checksum = i.CalculateIpChecksum(i.GetSize(), GetChecksum());
722
723 i = start;
724 i.Next(2);
725 i.WriteU16(checksum);
726}
727
730{
731 NS_LOG_FUNCTION(this << &start);
733
734 SetType(i.ReadU8());
735 SetCode(i.ReadU8());
736 m_checksum = i.ReadU16();
738 uint8_t flags = i.ReadU8();
739 m_flagM = false;
740 m_flagO = false;
741 m_flagH = false;
742
743 if (flags & (1 << 7))
744 {
745 m_flagM = true;
746 }
747
748 if (flags & (1 << 6))
749 {
750 m_flagO = true;
751 }
752
753 if (flags & (1 << 5))
754 {
755 m_flagH = true;
756 }
760
761 return GetSerializedSize();
762}
763
765
766TypeId
768{
769 static TypeId tid = TypeId("ns3::Icmpv6RS")
771 .SetGroupName("Internet")
772 .AddConstructor<Icmpv6RS>();
773 return tid;
774}
775
776TypeId
778{
779 NS_LOG_FUNCTION(this);
780 return GetTypeId();
781}
782
784{
785 NS_LOG_FUNCTION(this);
787 SetCode(0);
788 SetReserved(0);
789}
790
792{
793 NS_LOG_FUNCTION(this);
794}
795
798{
799 NS_LOG_FUNCTION(this);
800 return m_reserved;
801}
802
803void
805{
806 NS_LOG_FUNCTION(this << reserved);
807 m_reserved = reserved;
808}
809
810void
811Icmpv6RS::Print(std::ostream& os) const
812{
813 NS_LOG_FUNCTION(this << &os);
814 os << "( type = " << (uint32_t)GetType() << " (RS) code = " << (uint32_t)GetCode()
815 << " checksum = " << (uint32_t)GetChecksum() << ")";
816}
817
820{
821 NS_LOG_FUNCTION(this);
822 return 8;
823}
824
825void
827{
828 NS_LOG_FUNCTION(this << &start);
829
830 uint16_t checksum = 0;
832
833 i.WriteU8(GetType());
834 i.WriteU8(GetCode());
835 i.WriteU16(0);
837
838 if (m_calcChecksum)
839 {
840 i = start;
841 checksum = i.CalculateIpChecksum(i.GetSize(), GetChecksum());
842
843 i = start;
844 i.Next(2);
845 i.WriteU16(checksum);
846 }
847}
848
851{
852 NS_LOG_FUNCTION(this << &start);
854
855 SetType(i.ReadU8());
856 SetCode(i.ReadU8());
857 m_checksum = i.ReadU16();
859
860 return GetSerializedSize();
861}
862
864
865TypeId
867{
868 static TypeId tid = TypeId("ns3::Icmpv6Redirection")
870 .SetGroupName("Internet")
871 .AddConstructor<Icmpv6Redirection>();
872 return tid;
873}
874
875TypeId
877{
878 NS_LOG_FUNCTION(this);
879 return GetTypeId();
880}
881
883 : m_target(Ipv6Address("")),
884 m_destination(Ipv6Address("")),
885 m_reserved(0)
886{
887 NS_LOG_FUNCTION(this);
889 SetCode(0);
890 m_checksum = 0;
891}
892
894{
895 NS_LOG_FUNCTION(this);
896}
897
898void
900{
901 NS_LOG_FUNCTION(this << reserved);
902 m_reserved = reserved;
903}
904
907{
908 NS_LOG_FUNCTION(this);
909 return m_reserved;
910}
911
914{
915 NS_LOG_FUNCTION(this);
916 return m_target;
917}
918
919void
921{
922 NS_LOG_FUNCTION(this << target);
923 m_target = target;
924}
925
928{
929 NS_LOG_FUNCTION(this);
930 return m_destination;
931}
932
933void
935{
936 NS_LOG_FUNCTION(this << destination);
937 m_destination = destination;
938}
939
940void
941Icmpv6Redirection::Print(std::ostream& os) const
942{
943 NS_LOG_FUNCTION(this << &os);
944 os << "( type = " << (uint32_t)GetType() << " (Redirection) code = " << (uint32_t)GetCode()
945 << " checksum = " << (uint32_t)GetChecksum() << " target = " << m_target
946 << " destination = " << m_destination << ")";
947}
948
951{
952 NS_LOG_FUNCTION(this);
953 return 40;
954}
955
956void
958{
959 NS_LOG_FUNCTION(this << &start);
960 uint8_t buff[16];
961 uint16_t checksum = 0;
963
964 i.WriteU8(GetType());
965 i.WriteU8(GetCode());
966 i.WriteU16(checksum);
968
969 m_target.Serialize(buff);
970 i.Write(buff, 16);
971
973 i.Write(buff, 16);
974
975 if (m_calcChecksum)
976 {
977 i = start;
978 checksum = i.CalculateIpChecksum(i.GetSize(), GetChecksum());
979
980 i = start;
981 i.Next(2);
982 i.WriteU16(checksum);
983 }
984}
985
988{
989 NS_LOG_FUNCTION(this << &start);
990 uint8_t buff[16];
992
993 SetType(i.ReadU8());
994 SetCode(i.ReadU8());
995 m_checksum = i.ReadU16();
996 SetReserved(i.ReadU32());
997
998 i.Read(buff, 16);
999 m_target.Set(buff);
1000
1001 i.Read(buff, 16);
1002 m_destination.Set(buff);
1003
1004 return GetSerializedSize();
1005}
1006
1008
1009TypeId
1011{
1012 static TypeId tid = TypeId("ns3::Icmpv6Echo")
1014 .SetGroupName("Internet")
1015 .AddConstructor<Icmpv6Echo>();
1016 return tid;
1017}
1018
1019TypeId
1021{
1022 NS_LOG_FUNCTION(this);
1023 return GetTypeId();
1024}
1025
1027{
1028 NS_LOG_FUNCTION(this);
1030 SetCode(0);
1031 m_checksum = 0;
1032 SetId(0);
1033 SetSeq(0);
1034}
1035
1037{
1038 NS_LOG_FUNCTION(this << request);
1040 SetCode(0);
1041 m_checksum = 0;
1042 SetId(0);
1043 SetSeq(0);
1044}
1045
1047{
1048 NS_LOG_FUNCTION(this);
1049}
1050
1051uint16_t
1053{
1054 NS_LOG_FUNCTION(this);
1055 return m_id;
1056}
1057
1058void
1060{
1061 NS_LOG_FUNCTION(this << id);
1062 m_id = id;
1063}
1064
1065uint16_t
1067{
1068 NS_LOG_FUNCTION(this);
1069 return m_seq;
1070}
1071
1072void
1074{
1075 NS_LOG_FUNCTION(this << seq);
1076 m_seq = seq;
1077}
1078
1079void
1080Icmpv6Echo::Print(std::ostream& os) const
1081{
1082 NS_LOG_FUNCTION(this << &os);
1083 os << "( type = " << (GetType() == 128 ? "128 (Request)" : "129 (Reply)")
1084 << " Id = " << (uint32_t)GetId() << " SeqNo = " << (uint32_t)GetSeq()
1085 << " checksum = " << (uint32_t)GetChecksum() << ")";
1086}
1087
1090{
1091 NS_LOG_FUNCTION(this);
1092 return 8;
1093}
1094
1095void
1097{
1098 NS_LOG_FUNCTION(this << &start);
1099 uint16_t checksum = 0;
1101
1102 i.WriteU8(GetType());
1103 i.WriteU8(GetCode());
1104 i.WriteHtonU16(0);
1105
1106 i.WriteHtonU16(m_id);
1108
1109 if (m_calcChecksum)
1110 {
1111 i = start;
1112 checksum = i.CalculateIpChecksum(i.GetSize(), GetChecksum());
1113 i = start;
1114 i.Next(2);
1115 i.WriteU16(checksum);
1116 }
1117}
1118
1121{
1122 NS_LOG_FUNCTION(this << &start);
1124
1125 SetType(i.ReadU8());
1126 SetCode(i.ReadU8());
1127 m_checksum = i.ReadU16();
1128
1129 m_id = i.ReadNtohU16();
1130 m_seq = i.ReadNtohU16();
1131 return GetSerializedSize();
1132}
1133
1135
1136TypeId
1138{
1139 static TypeId tid = TypeId("ns3::Icmpv6DestinationUnreachable")
1141 .SetGroupName("Internet")
1142 .AddConstructor<Icmpv6DestinationUnreachable>();
1143 return tid;
1144}
1145
1146TypeId
1148{
1149 NS_LOG_FUNCTION(this);
1150 return GetTypeId();
1151}
1152
1154 : m_packet(nullptr)
1155{
1156 NS_LOG_FUNCTION(this);
1158}
1159
1161{
1162 NS_LOG_FUNCTION(this);
1163}
1164
1165void
1167{
1168 NS_LOG_FUNCTION(this << *p);
1169 NS_ASSERT(p->GetSize() <= 1280);
1170 m_packet = p->Copy();
1171}
1172
1173void
1175{
1176 NS_LOG_FUNCTION(this << &os);
1177 os << "( type = " << (uint32_t)GetType()
1178 << " (Destination Unreachable) code = " << (uint32_t)GetCode()
1179 << " checksum = " << (uint32_t)GetChecksum() << ")";
1180}
1181
1184{
1185 NS_LOG_FUNCTION(this);
1186 // The real size of the header is 8 + m_packet->GetSize ()
1187 // HOWEVER we just serialize the first 8 bytes, as the rest is serialized separately.
1188 return 8;
1189}
1190
1191void
1193{
1194 NS_LOG_FUNCTION(this << &start);
1195 uint16_t checksum = 0;
1197
1198 Buffer secondaryBuffer;
1199 secondaryBuffer.AddAtStart(8 + m_packet->GetSize());
1200 Buffer::Iterator iter = secondaryBuffer.Begin();
1201
1202 iter.WriteU8(GetType());
1203 iter.WriteU8(GetCode());
1204 iter.WriteU16(0);
1205 iter.WriteU32(0);
1206
1207 uint32_t size = m_packet->GetSize();
1208 uint8_t* buf = new uint8_t[size];
1209 m_packet->CopyData(buf, size);
1210 iter.Write(buf, size);
1211 delete[] buf;
1212
1213 iter = secondaryBuffer.Begin();
1214 checksum = iter.CalculateIpChecksum(iter.GetSize(), GetChecksum());
1215
1216 i.WriteU8(GetType());
1217 i.WriteU8(GetCode());
1218 i.WriteU16(checksum);
1219 i.WriteU32(0);
1220}
1221
1224{
1225 NS_LOG_FUNCTION(this << &start);
1227
1228 SetType(i.ReadU8());
1229 SetCode(i.ReadU8());
1230 m_checksum = i.ReadU16();
1231 i.ReadU32();
1232
1233 return GetSerializedSize();
1234}
1235
1237
1238TypeId
1240{
1241 static TypeId tid = TypeId("ns3::Icmpv6TooBig")
1243 .SetGroupName("Internet")
1244 .AddConstructor<Icmpv6TooBig>();
1245 return tid;
1246}
1247
1248TypeId
1250{
1251 NS_LOG_FUNCTION(this);
1252 return GetTypeId();
1253}
1254
1256 : m_packet(nullptr),
1257 m_mtu(0)
1258{
1259 NS_LOG_FUNCTION(this);
1261}
1262
1264{
1265 NS_LOG_FUNCTION(this);
1266}
1267
1268void
1270{
1271 NS_LOG_FUNCTION(this << *p);
1272 NS_ASSERT(p->GetSize() <= 1280);
1273 m_packet = p->Copy();
1274}
1275
1278{
1279 NS_LOG_FUNCTION(this);
1280 return m_mtu;
1281}
1282
1283void
1285{
1286 NS_LOG_FUNCTION(this << mtu);
1287 m_mtu = mtu;
1288}
1289
1290void
1291Icmpv6TooBig::Print(std::ostream& os) const
1292{
1293 NS_LOG_FUNCTION(this << &os);
1294 os << "( type = " << (uint32_t)GetType() << " (Too Big) code = " << (uint32_t)GetCode()
1295 << " checksum = " << (uint32_t)GetChecksum() << " mtu = " << (uint32_t)GetMtu() << ")";
1296}
1297
1300{
1301 NS_LOG_FUNCTION(this);
1302 // The real size of the header is 8 + m_packet->GetSize ()
1303 // HOWEVER we just serialize the first 8 bytes, as the rest is serialized separately.
1304 return 8;
1305}
1306
1307void
1309{
1310 NS_LOG_FUNCTION(this << &start);
1311 uint16_t checksum = 0;
1313
1314 Buffer secondaryBuffer;
1315 secondaryBuffer.AddAtStart(8 + m_packet->GetSize());
1316 Buffer::Iterator iter = secondaryBuffer.Begin();
1317
1318 iter.WriteU8(GetType());
1319 iter.WriteU8(GetCode());
1320 iter.WriteU16(0);
1321 iter.WriteHtonU32(GetMtu());
1322
1323 uint32_t size = m_packet->GetSize();
1324 uint8_t* buf = new uint8_t[size];
1325 m_packet->CopyData(buf, size);
1326 iter.Write(buf, size);
1327 delete[] buf;
1328
1329 iter = secondaryBuffer.Begin();
1330 checksum = iter.CalculateIpChecksum(iter.GetSize(), GetChecksum());
1331
1332 i.WriteU8(GetType());
1333 i.WriteU8(GetCode());
1334 i.WriteU16(checksum);
1335 i.WriteHtonU32(GetMtu());
1336}
1337
1340{
1341 NS_LOG_FUNCTION(this << &start);
1343
1344 SetType(i.ReadU8());
1345 SetCode(i.ReadU8());
1346 m_checksum = i.ReadU16();
1347 SetMtu(i.ReadNtohU32());
1348
1349 return GetSerializedSize();
1350}
1351
1353
1354TypeId
1356{
1357 static TypeId tid = TypeId("ns3::Icmpv6TimeExceeded")
1359 .SetGroupName("Internet")
1360 .AddConstructor<Icmpv6TimeExceeded>();
1361 return tid;
1362}
1363
1364TypeId
1366{
1367 NS_LOG_FUNCTION(this);
1368 return GetTypeId();
1369}
1370
1372 : m_packet(nullptr)
1373{
1374 NS_LOG_FUNCTION(this);
1376}
1377
1379{
1380 NS_LOG_FUNCTION(this);
1381}
1382
1383void
1385{
1386 NS_LOG_FUNCTION(this << *p);
1387 NS_ASSERT(p->GetSize() <= 1280);
1388 m_packet = p->Copy();
1389}
1390
1391void
1392Icmpv6TimeExceeded::Print(std::ostream& os) const
1393{
1394 NS_LOG_FUNCTION(this << &os);
1395 os << "( type = " << (uint32_t)GetType()
1396 << " (Destination Unreachable) code = " << (uint32_t)GetCode()
1397 << " checksum = " << (uint32_t)GetChecksum() << ")";
1398}
1399
1402{
1403 NS_LOG_FUNCTION(this);
1404 // The real size of the header is 8 + m_packet->GetSize ()
1405 // HOWEVER we just serialize the first 8 bytes, as the rest is serialized separately.
1406 return 8;
1407}
1408
1409void
1411{
1412 NS_LOG_FUNCTION(this << &start);
1413 uint16_t checksum = 0;
1415
1416 Buffer secondaryBuffer;
1417 secondaryBuffer.AddAtStart(8 + m_packet->GetSize());
1418 Buffer::Iterator iter = secondaryBuffer.Begin();
1419
1420 iter.WriteU8(GetType());
1421 iter.WriteU8(GetCode());
1422 iter.WriteU16(0);
1423 iter.WriteU32(0);
1424
1425 uint32_t size = m_packet->GetSize();
1426 uint8_t* buf = new uint8_t[size];
1427 m_packet->CopyData(buf, size);
1428 iter.Write(buf, size);
1429 delete[] buf;
1430
1431 iter = secondaryBuffer.Begin();
1432 checksum = iter.CalculateIpChecksum(iter.GetSize(), GetChecksum());
1433
1434 i.WriteU8(GetType());
1435 i.WriteU8(GetCode());
1436 i.WriteU16(checksum);
1437 i.WriteU32(0);
1438}
1439
1442{
1443 NS_LOG_FUNCTION(this << &start);
1445
1446 SetType(i.ReadU8());
1447 SetCode(i.ReadU8());
1448 m_checksum = i.ReadU16();
1449 i.ReadU32();
1450
1451 return GetSerializedSize();
1452}
1453
1455
1456TypeId
1458{
1459 static TypeId tid = TypeId("ns3::Icmpv6ParameterError")
1461 .SetGroupName("Internet")
1462 .AddConstructor<Icmpv6ParameterError>();
1463 return tid;
1464}
1465
1466TypeId
1468{
1469 NS_LOG_FUNCTION(this);
1470 return GetTypeId();
1471}
1472
1474 : m_packet(nullptr),
1475 m_ptr(0)
1476{
1477 NS_LOG_FUNCTION(this);
1479}
1480
1482{
1483 NS_LOG_FUNCTION(this);
1484}
1485
1486void
1488{
1489 NS_LOG_FUNCTION(this << *p);
1490 NS_ASSERT(p->GetSize() <= 1280);
1491 m_packet = p->Copy();
1492}
1493
1496{
1497 NS_LOG_FUNCTION(this);
1498 return m_ptr;
1499}
1500
1501void
1503{
1504 NS_LOG_FUNCTION(this << ptr);
1505 m_ptr = ptr;
1506}
1507
1508void
1509Icmpv6ParameterError::Print(std::ostream& os) const
1510{
1511 NS_LOG_FUNCTION(this << &os);
1512 os << "( type = " << (uint32_t)GetType()
1513 << " (Destination Unreachable) code = " << (uint32_t)GetCode()
1514 << " checksum = " << (uint32_t)GetChecksum() << " ptr = " << (uint32_t)GetPtr() << ")";
1515}
1516
1519{
1520 NS_LOG_FUNCTION(this);
1521 // The real size of the header is 8 + m_packet->GetSize ()
1522 // HOWEVER we just serialize the first 8 bytes, as the rest is serialized separately.
1523 return 8;
1524}
1525
1526void
1528{
1529 NS_LOG_FUNCTION(this << &start);
1530 uint16_t checksum = 0;
1532
1533 Buffer secondaryBuffer;
1534 secondaryBuffer.AddAtStart(8 + m_packet->GetSize());
1535 Buffer::Iterator iter = secondaryBuffer.Begin();
1536
1537 iter.WriteU8(GetType());
1538 iter.WriteU8(GetCode());
1539 iter.WriteU16(0);
1540 iter.WriteHtonU32(GetPtr());
1541
1542 uint32_t size = m_packet->GetSize();
1543 uint8_t* buf = new uint8_t[size];
1544 m_packet->CopyData(buf, size);
1545 iter.Write(buf, size);
1546 delete[] buf;
1547
1548 iter = secondaryBuffer.Begin();
1549 checksum = iter.CalculateIpChecksum(iter.GetSize(), GetChecksum());
1550
1551 i.WriteU8(GetType());
1552 i.WriteU8(GetCode());
1553 i.WriteU16(checksum);
1554 i.WriteHtonU32(GetPtr());
1555}
1556
1559{
1560 NS_LOG_FUNCTION(this << &start);
1562
1563 SetType(i.ReadU8());
1564 SetCode(i.ReadU8());
1565 m_checksum = i.ReadU16();
1566 SetPtr(i.ReadNtohU32());
1567
1568 return GetSerializedSize();
1569}
1570
1572
1573TypeId
1575{
1576 static TypeId tid = TypeId("ns3::Icmpv6OptionHeader")
1577 .SetParent<Header>()
1578 .SetGroupName("Internet")
1579 .AddConstructor<Icmpv6OptionHeader>();
1580 return tid;
1581}
1582
1583TypeId
1585{
1586 NS_LOG_FUNCTION(this);
1587 return GetTypeId();
1588}
1589
1591{
1592 NS_LOG_FUNCTION(this);
1594 m_type = 0;
1595 m_len = 0;
1596}
1597
1599{
1600 NS_LOG_FUNCTION(this);
1601}
1602
1603uint8_t
1605{
1606 NS_LOG_FUNCTION(this);
1607 return m_type;
1608}
1609
1610void
1612{
1613 NS_LOG_FUNCTION(this << static_cast<uint32_t>(type));
1614 m_type = type;
1615}
1616
1617uint8_t
1619{
1620 NS_LOG_FUNCTION(this);
1621 return m_len;
1622}
1623
1624void
1626{
1627 NS_LOG_FUNCTION(this << static_cast<uint32_t>(len));
1628 m_len = len;
1629}
1630
1631void
1632Icmpv6OptionHeader::Print(std::ostream& os) const
1633{
1634 NS_LOG_FUNCTION(this << &os);
1635 os << "( type = " << (uint32_t)GetType() << " length = " << (uint32_t)GetLength() << ")";
1636}
1637
1640{
1641 NS_LOG_FUNCTION(this);
1642 return m_len * 8;
1643}
1644
1647{
1648 NS_LOG_FUNCTION(this << &start);
1649 return GetSerializedSize();
1650}
1651
1652void
1654{
1655 NS_LOG_FUNCTION(this << &start);
1656}
1657
1659
1660TypeId
1662{
1663 static TypeId tid = TypeId("ns3::Icmpv6OptionMtu")
1665 .SetGroupName("Internet")
1666 .AddConstructor<Icmpv6OptionMtu>();
1667 return tid;
1668}
1669
1670TypeId
1672{
1673 NS_LOG_FUNCTION(this);
1674 return GetTypeId();
1675}
1676
1678{
1679 NS_LOG_FUNCTION(this);
1681 SetLength(1);
1682 SetReserved(0);
1683}
1684
1686 : m_mtu(mtu)
1687{
1688 NS_LOG_FUNCTION(this << mtu);
1690 SetLength(1);
1691 SetReserved(0);
1692}
1693
1695{
1696 NS_LOG_FUNCTION(this);
1697}
1698
1699uint16_t
1701{
1702 NS_LOG_FUNCTION(this);
1703 return m_reserved;
1704}
1705
1706void
1708{
1709 NS_LOG_FUNCTION(this << reserved);
1710 m_reserved = reserved;
1711}
1712
1715{
1716 NS_LOG_FUNCTION(this);
1717 return m_mtu;
1718}
1719
1720void
1722{
1723 NS_LOG_FUNCTION(this << mtu);
1724 m_mtu = mtu;
1725}
1726
1727void
1728Icmpv6OptionMtu::Print(std::ostream& os) const
1729{
1730 NS_LOG_FUNCTION(this << &os);
1731 os << "( type = " << (uint32_t)GetType() << " length = " << (uint32_t)GetLength()
1732 << " MTU = " << m_mtu << ")";
1733}
1734
1737{
1738 NS_LOG_FUNCTION(this);
1739 return 8; /* m_len = 1 so the real size is multiple by 8 */
1740}
1741
1742void
1744{
1745 NS_LOG_FUNCTION(this << &start);
1747 i.WriteU8(GetType());
1748 i.WriteU8(GetLength());
1750 i.WriteHtonU32(GetMtu());
1751}
1752
1755{
1756 NS_LOG_FUNCTION(this << &start);
1758 SetType(i.ReadU8());
1759 SetLength(i.ReadU8());
1761 SetMtu(i.ReadNtohU32());
1762 return GetSerializedSize();
1763}
1764
1766
1767TypeId
1769{
1770 static TypeId tid = TypeId("ns3::Icmpv6OptionPrefixInformation")
1772 .SetGroupName("Internet")
1773 .AddConstructor<Icmpv6OptionPrefixInformation>();
1774 return tid;
1775}
1776
1777TypeId
1779{
1780 NS_LOG_FUNCTION(this);
1781 return GetTypeId();
1782}
1783
1785{
1786 NS_LOG_FUNCTION(this);
1788 SetLength(4);
1789 SetPrefix(Ipv6Address("::"));
1790 SetPrefixLength(0);
1791 SetValidTime(0);
1793 SetFlags(0);
1794 SetReserved(0);
1795}
1796
1798{
1799 NS_LOG_FUNCTION(this << prefix << static_cast<uint32_t>(prefixlen));
1801 SetLength(4);
1802 SetPrefix(prefix);
1803 SetPrefixLength(prefixlen);
1804 SetValidTime(0);
1806 SetFlags(0);
1807 SetReserved(0);
1808}
1809
1811{
1812 NS_LOG_FUNCTION(this);
1813}
1814
1815uint8_t
1817{
1818 NS_LOG_FUNCTION(this);
1819 return m_prefixLength;
1820}
1821
1822void
1824{
1825 NS_LOG_FUNCTION(this << static_cast<uint32_t>(prefixLength));
1826 NS_ASSERT(prefixLength <= 128);
1827 m_prefixLength = prefixLength;
1828}
1829
1830uint8_t
1832{
1833 NS_LOG_FUNCTION(this);
1834 return m_flags;
1835}
1836
1837void
1839{
1840 NS_LOG_FUNCTION(this);
1841 m_flags = flags;
1842}
1843
1846{
1847 NS_LOG_FUNCTION(this);
1848 return m_validTime;
1849}
1850
1851void
1853{
1854 NS_LOG_FUNCTION(this << validTime);
1855 m_validTime = validTime;
1856}
1857
1860{
1861 NS_LOG_FUNCTION(this);
1862 return m_preferredTime;
1863}
1864
1865void
1867{
1868 NS_LOG_FUNCTION(this << preferredTime);
1869 m_preferredTime = preferredTime;
1870}
1871
1874{
1875 NS_LOG_FUNCTION(this);
1876 return m_preferredTime;
1877}
1878
1879void
1881{
1882 NS_LOG_FUNCTION(this << reserved);
1883 m_reserved = reserved;
1884}
1885
1888{
1889 NS_LOG_FUNCTION(this);
1890 return m_prefix;
1891}
1892
1893void
1895{
1896 NS_LOG_FUNCTION(this << prefix);
1897 m_prefix = prefix;
1898}
1899
1900void
1902{
1903 NS_LOG_FUNCTION(this << &os);
1904 os << "( type = " << (uint32_t)GetType() << " length = " << (uint32_t)GetLength() << " prefix "
1905 << m_prefix << ")";
1906}
1907
1910{
1911 NS_LOG_FUNCTION(this);
1912 return 32;
1913}
1914
1915void
1917{
1918 NS_LOG_FUNCTION(this << &start);
1920 uint8_t buf[16];
1921
1922 memset(buf, 0x00, sizeof(buf));
1923
1924 i.WriteU8(GetType());
1925 i.WriteU8(GetLength());
1927 i.WriteU8(m_flags);
1931 m_prefix.GetBytes(buf);
1932 i.Write(buf, 16);
1933}
1934
1937{
1938 NS_LOG_FUNCTION(this << &start);
1940 uint8_t buf[16];
1941
1942 SetType(i.ReadU8());
1943 SetLength(i.ReadU8());
1945 SetFlags(i.ReadU8());
1949 i.Read(buf, 16);
1950
1951 Ipv6Address prefix(buf);
1952 SetPrefix(prefix);
1953
1954 return GetSerializedSize();
1955}
1956
1958
1959TypeId
1961{
1962 static TypeId tid = TypeId("ns3::Icmpv6OptionLinkLayerAddress")
1964 .SetGroupName("Internet")
1965 .AddConstructor<Icmpv6OptionLinkLayerAddress>();
1966 return tid;
1967}
1968
1969TypeId
1971{
1972 NS_LOG_FUNCTION(this);
1973 return GetTypeId();
1974}
1975
1977{
1978 NS_LOG_FUNCTION(this << source);
1981}
1982
1984{
1985 NS_LOG_FUNCTION(this);
1987}
1988
1990{
1991 NS_LOG_FUNCTION(this << source << addr);
1994 SetAddress(addr);
1995
1996 uint8_t len = (2 + m_addr.GetLength()) / 8;
1997 if ((2 + m_addr.GetLength()) % 8)
1998 {
1999 len++;
2000 }
2001 SetLength(len);
2002}
2003
2005{
2006 NS_LOG_FUNCTION(this);
2007}
2008
2009Address
2011{
2012 NS_LOG_FUNCTION(this);
2013 return m_addr;
2014}
2015
2016void
2018{
2019 NS_LOG_FUNCTION(this << addr);
2020 m_addr = addr;
2021}
2022
2023void
2025{
2026 NS_LOG_FUNCTION(this << &os);
2027 os << "( type = " << (uint32_t)GetType() << " length = " << (uint32_t)GetLength()
2028 << " L2 Address = " << m_addr << ")";
2029}
2030
2033{
2034 NS_LOG_FUNCTION(this);
2035 uint8_t nb = GetLength() * 8;
2036 return nb;
2037}
2038
2039void
2041{
2042 NS_LOG_FUNCTION(this << &start);
2044 uint8_t mac[32];
2045
2046 i.WriteU8(GetType());
2047 i.WriteU8(GetLength());
2048 m_addr.CopyTo(mac);
2049 i.Write(mac, m_addr.GetLength());
2050
2051 uint8_t len = GetLength() * 8 - (2 + m_addr.GetLength());
2052 for (uint8_t nb = 0; nb < len; nb++)
2053 {
2054 i.WriteU8(0);
2055 }
2056}
2057
2060{
2061 NS_LOG_FUNCTION(this << &start);
2063 uint8_t mac[32];
2064
2065 SetType(i.ReadU8());
2066 SetLength(i.ReadU8());
2067 // -fstrict-overflow sensitive, see bug 1868
2068 NS_ASSERT(GetLength() * 8 <= 32 + 2);
2069 i.Read(mac, (GetLength() * 8) - 2);
2070
2071 m_addr.CopyFrom(mac, (GetLength() * 8) - 2);
2072
2073 return GetSerializedSize();
2074}
2075
2077
2078TypeId
2080{
2081 static TypeId tid = TypeId("ns3::Icmpv6OptionRedirected")
2083 .SetGroupName("Internet")
2084 .AddConstructor<Icmpv6OptionRedirected>();
2085 return tid;
2086}
2087
2088TypeId
2090{
2091 NS_LOG_FUNCTION(this);
2092 return GetTypeId();
2093}
2094
2096 : m_packet(nullptr)
2097{
2098 NS_LOG_FUNCTION(this);
2100}
2101
2103{
2104 NS_LOG_FUNCTION(this);
2105 m_packet = nullptr;
2106}
2107
2108void
2110{
2111 NS_LOG_FUNCTION(this << *packet);
2112 NS_ASSERT(packet->GetSize() <= 1280);
2113 m_packet = packet->Copy();
2114 SetLength(1 + (m_packet->GetSize() / 8));
2115}
2116
2117void
2118Icmpv6OptionRedirected::Print(std::ostream& os) const
2119{
2120 NS_LOG_FUNCTION(this << &os);
2121 os << "( type = " << (uint32_t)GetType() << " length = " << (uint32_t)GetLength() << ")";
2122}
2123
2126{
2127 NS_LOG_FUNCTION(this);
2128 return 8 + m_packet->GetSize();
2129}
2130
2131void
2133{
2134 NS_LOG_FUNCTION(this << &start);
2136
2137 i.WriteU8(GetType());
2138 i.WriteU8(GetLength());
2139 // Reserved
2140 i.WriteU16(0);
2141 i.WriteU32(0);
2142
2143 uint32_t size = m_packet->GetSize();
2144 uint8_t* buf = new uint8_t[size];
2145 m_packet->CopyData(buf, size);
2146 i.Write(buf, size);
2147 delete[] buf;
2148}
2149
2152{
2153 NS_LOG_FUNCTION(this << &start);
2155
2156 SetType(i.ReadU8());
2157 uint8_t length = i.ReadU8();
2158 SetLength(length);
2159 i.ReadU16();
2160 i.ReadU32();
2161
2162 uint32_t len2 = (GetLength() - 1) * 8;
2163 uint8_t* buff = new uint8_t[len2];
2164 i.Read(buff, len2);
2165 m_packet = Create<Packet>(buff, len2);
2166 delete[] buff;
2167
2168 return GetSerializedSize();
2169}
2170
2171} /* namespace ns3 */
double f(double x, void *params)
Definition: 80211b.c:71
a polymophic address class
Definition: address.h:92
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:871
uint8_t ReadU8()
Definition: buffer.h:1027
uint16_t CalculateIpChecksum(uint16_t size)
Calculate the checksum.
Definition: buffer.cc:1138
void WriteU8(uint8_t data)
Definition: buffer.h:881
void Write(const uint8_t *buffer, uint32_t size)
Definition: buffer.cc:951
void WriteU16(uint16_t data)
Definition: buffer.cc:862
void Read(uint8_t *buffer, uint32_t size)
Definition: buffer.cc:1128
void WriteHtonU16(uint16_t data)
Definition: buffer.h:915
uint32_t ReadNtohU32()
Definition: buffer.h:978
uint32_t ReadU32()
Definition: buffer.cc:969
void WriteHtonU32(uint32_t data)
Definition: buffer.h:933
uint16_t ReadNtohU16()
Definition: buffer.h:954
uint32_t GetSize() const
Definition: buffer.cc:1169
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:311
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).
NS_DEPRECATED_3_34 void SetFlags(uint8_t f)
Setflags.
bool m_flagM
The M flag.
uint32_t GetRetransmissionTime() const
Get the node Retransmission time (Neighbor Discovery).
NS_DEPRECATED_3_34 uint8_t GetFlags() const
Getflags.
bool m_flagO
The O flag.
void SetFlagH(bool h)
Set the H flag.
void SetRetransmissionTime(uint32_t r)
Set the node Retransmission time (Neighbor Discovery).
void SetCurHopLimit(uint8_t m)
Set the IPv6 maximum number of jumps.
void SetFlagO(bool o)
Set the O flag.
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:50
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:863
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
Copy the packet contents to a byte buffer.
Definition: packet.cc:400
Ptr< Packet > Copy() const
performs a COW copy of the packet.
Definition: packet.cc:131
a unique identifier for an interface.
Definition: type-id.h:60
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:935
#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:45
Every class exported by the ns3 library is enclosed in the ns3 namespace.
mac
Definition: third.py:85
def start()
Definition: core.py:1861