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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
7 * Mehdi Benamor <benamor.mehdi@ensi.rnu.tn>
8 * David Gross <gdavid.devel@gmail.com>
9 */
10
11#include "icmpv6-header.h"
12
13#include "ns3/address-utils.h"
14#include "ns3/assert.h"
15#include "ns3/iana-internet-protocol-numbers.h"
16#include "ns3/log.h"
17
18namespace ns3
19{
20
21NS_LOG_COMPONENT_DEFINE("Icmpv6Header");
22
24
27{
28 static TypeId tid = TypeId("ns3::Icmpv6Header")
30 .SetGroupName("Internet")
31 .AddConstructor<Icmpv6Header>();
32 return tid;
33}
34
37{
38 NS_LOG_FUNCTION(this);
39 return GetTypeId();
40}
41
43 : m_calcChecksum(true),
44 m_checksum(0),
45 m_type(0),
46 m_code(0),
47 m_verifyChecksum(false),
48 m_goodChecksum(true)
49{
50 NS_LOG_FUNCTION(this);
51}
52
57
58uint8_t
60{
61 NS_LOG_FUNCTION(this);
62 return m_type;
63}
64
65void
67{
68 NS_LOG_FUNCTION(this << static_cast<uint32_t>(type));
69 m_type = type;
70}
71
72uint8_t
74{
75 NS_LOG_FUNCTION(this);
76 return m_code;
77}
78
79void
81{
82 NS_LOG_FUNCTION(this << static_cast<uint32_t>(code));
83 m_code = code;
84}
85
86uint16_t
88{
89 NS_LOG_FUNCTION(this);
90 return m_checksum;
91}
92
93void
94Icmpv6Header::SetChecksum(uint16_t checksum)
95{
96 NS_LOG_FUNCTION(this << checksum);
97 m_checksum = checksum;
98}
99
100void
101Icmpv6Header::Print(std::ostream& os) const
102{
103 NS_LOG_FUNCTION(this << &os);
104 os << "( type = " << (uint32_t)m_type << " code = " << (uint32_t)m_code
105 << " checksum = " << (uint32_t)m_checksum << ")";
106}
107
110{
111 NS_LOG_FUNCTION(this);
112 return 4;
113}
114
117{
118 NS_LOG_FUNCTION(this << &start);
119 Buffer::Iterator i = start;
120
121 m_type = i.ReadU8();
122 m_code = i.ReadU8();
124#if 0
125 i.ReadU32 (); /* padding */
126#endif
127
129 {
130 uint16_t headerChecksum = CalculateHeaderChecksum(start.GetRemainingSize());
131 i = start;
132 uint16_t checksum = i.CalculateIpChecksum(start.GetRemainingSize(), headerChecksum);
133 m_goodChecksum = (checksum == 0);
134 }
135
136 return GetSerializedSize();
137}
138
139void
141{
142 NS_LOG_FUNCTION(this << &start);
143 Buffer::Iterator i = start;
144
145 i.WriteU8(m_type);
146 i.WriteU8(m_code);
147 i.WriteU16(0);
148#if 0
149 i.WriteU32 (0); /* padding */
150#endif
151
152 if (m_calcChecksum)
153 {
154 i = start;
155 uint16_t checksum = i.CalculateIpChecksum(i.GetSize(), m_checksum);
156 i = start;
157 i.Next(2);
158 i.WriteU16(checksum);
159 }
160}
161
162void
164{
165 NS_LOG_FUNCTION(this << src << dst << length);
166
167 m_source = src;
168 m_destination = dst;
170}
171
172void
174{
175 NS_LOG_FUNCTION(this << source << destination);
176
177 m_source = source;
178 m_destination = destination;
179 m_verifyChecksum = true;
180}
181
182uint16_t
184{
185 NS_LOG_FUNCTION(this << size);
186
187 Buffer buf = Buffer(40);
188 uint8_t tmp[16];
190
191 buf.AddAtStart(40);
192 it = buf.Begin();
193
194 m_source.Serialize(tmp);
195 it.Write(tmp, 16); /* source IPv6 address */
196 m_destination.Serialize(tmp);
197 it.Write(tmp, 16); /* destination IPv6 address */
198 it.WriteU16(0); /* length */
199 it.WriteU8(size >> 8); /* length */
200 it.WriteU8(size & 0xff); /* length */
201 it.WriteU16(0); /* zero */
202 it.WriteU8(0); /* zero */
204
205 it = buf.Begin();
206 return ~(it.CalculateIpChecksum(40));
207}
208
209bool
211{
212 NS_LOG_FUNCTION(this);
213 return m_goodChecksum;
214}
215
217
226
227TypeId
229{
230 static TypeId tid = TypeId("ns3::Icmpv6NS")
232 .SetGroupName("Internet")
233 .AddConstructor<Icmpv6NS>();
234 return tid;
235}
236
237TypeId
239{
240 NS_LOG_FUNCTION(this);
241 return GetTypeId();
242}
243
245{
246 NS_LOG_FUNCTION(this << target);
248 SetCode(0);
249 SetReserved(0);
250 SetIpv6Target(target);
251 m_checksum = 0;
252
253 /* test */
254 /*
255 m_reserved = 0xdeadbeef;
256 */
257}
258
263
266{
267 NS_LOG_FUNCTION(this);
268 return m_reserved;
269}
270
271void
273{
274 NS_LOG_FUNCTION(this << reserved);
275 m_reserved = reserved;
276}
277
280{
281 NS_LOG_FUNCTION(this);
282 return m_target;
283}
284
285void
287{
288 NS_LOG_FUNCTION(this << target);
289 m_target = target;
290}
291
292void
293Icmpv6NS::Print(std::ostream& os) const
294{
295 NS_LOG_FUNCTION(this << &os);
296 os << "( type = " << (uint32_t)GetType() << " (NS) code = " << (uint32_t)GetCode()
297 << " target = " << m_target << " checksum = " << (uint32_t)GetChecksum() << ")";
298}
299
302{
303 NS_LOG_FUNCTION(this);
304 return 24;
305}
306
307void
309{
310 NS_LOG_FUNCTION(this << &start);
311 uint8_t buff_target[16];
312 uint16_t checksum = 0;
313 Buffer::Iterator i = start;
314
315 i.WriteU8(GetType());
316 i.WriteU8(GetCode());
317 i.WriteU16(0);
319 m_target.Serialize(buff_target);
320 i.Write(buff_target, 16);
321
322 if (m_calcChecksum)
323 {
324 i = start;
325 checksum = i.CalculateIpChecksum(i.GetSize(), m_checksum);
326 i = start;
327 i.Next(2);
328 i.WriteU16(checksum);
329 }
330}
331
334{
335 NS_LOG_FUNCTION(this << &start);
336 uint8_t buf[16];
337 Buffer::Iterator i = start;
338
339 SetType(i.ReadU8());
340 SetCode(i.ReadU8());
341 m_checksum = i.ReadU16();
343 i.Read(buf, 16);
344 m_target.Set(buf);
345
346 return GetSerializedSize();
347}
348
350
351TypeId
353{
354 static TypeId tid = TypeId("ns3::Icmpv6NA")
356 .SetGroupName("Internet")
357 .AddConstructor<Icmpv6NA>();
358 return tid;
359}
360
361TypeId
363{
364 NS_LOG_FUNCTION(this);
365 return GetTypeId();
366}
367
369{
370 NS_LOG_FUNCTION(this);
372 SetCode(0);
373 SetReserved(0);
374 SetFlagR(false);
375 SetFlagS(false);
376 SetFlagO(false);
377 m_checksum = 0;
378}
379
384
387{
388 NS_LOG_FUNCTION(this);
389 return m_reserved;
390}
391
392void
394{
395 NS_LOG_FUNCTION(this << reserved);
396 m_reserved = reserved;
397}
398
401{
402 NS_LOG_FUNCTION(this);
403 return m_target;
404}
405
406bool
408{
409 NS_LOG_FUNCTION(this);
410 return m_flagR;
411}
412
413void
415{
416 NS_LOG_FUNCTION(this << r);
417 m_flagR = r;
418}
419
420bool
422{
423 NS_LOG_FUNCTION(this);
424 return m_flagS;
425}
426
427void
429{
430 NS_LOG_FUNCTION(this << s);
431 m_flagS = s;
432}
433
434bool
436{
437 NS_LOG_FUNCTION(this);
438 return m_flagO;
439}
440
441void
443{
444 NS_LOG_FUNCTION(this << o);
445 m_flagO = o;
446}
447
448void
450{
451 NS_LOG_FUNCTION(this << target);
452 m_target = target;
453}
454
455void
456Icmpv6NA::Print(std::ostream& os) const
457{
458 NS_LOG_FUNCTION(this << &os);
459 os << "( type = " << (uint32_t)GetType() << " (NA) code = " << (uint32_t)GetCode()
460 << " checksum = " << (uint32_t)GetChecksum() << ")";
461}
462
465{
466 NS_LOG_FUNCTION(this);
467 return 24;
468}
469
470void
472{
473 NS_LOG_FUNCTION(this << &start);
474 uint8_t buff_target[16];
475 uint16_t checksum = 0;
476 Buffer::Iterator i = start;
477 uint32_t reserved = m_reserved;
478
479 i.WriteU8(GetType());
480 i.WriteU8(GetCode());
481 i.WriteU16(0);
482
483 if (m_flagR)
484 {
485 reserved |= (uint32_t)(1 << 31);
486 }
487
488 if (m_flagS)
489 {
490 reserved |= (uint32_t)(1 << 30);
491 }
492
493 if (m_flagO)
494 {
495 reserved |= (uint32_t)(1 << 29);
496 }
497
498 i.WriteHtonU32(reserved);
499 m_target.Serialize(buff_target);
500 i.Write(buff_target, 16);
501
502 if (m_calcChecksum)
503 {
504 i = start;
505 checksum = i.CalculateIpChecksum(i.GetSize(), GetChecksum());
506 i = start;
507 i.Next(2);
508 i.WriteU16(checksum);
509 }
510}
511
514{
515 NS_LOG_FUNCTION(this << &start);
516 uint8_t buf[16];
517 Buffer::Iterator i = start;
518
519 SetType(i.ReadU8());
520 SetCode(i.ReadU8());
521 m_checksum = i.ReadU16();
523
524 m_flagR = false;
525 m_flagS = false;
526 m_flagO = false;
527
528 if (m_reserved & (1 << 31))
529 {
530 m_flagR = true;
531 }
532
533 if (m_reserved & (1 << 30))
534 {
535 m_flagS = true;
536 }
537
538 if (m_reserved & (1 << 29))
539 {
540 m_flagO = true;
541 }
542
543 i.Read(buf, 16);
544 m_target.Set(buf);
545
546 return GetSerializedSize();
547}
548
550
551TypeId
553{
554 static TypeId tid = TypeId("ns3::Icmpv6RA")
556 .SetGroupName("Internet")
557 .AddConstructor<Icmpv6RA>();
558 return tid;
559}
560
561TypeId
563{
564 NS_LOG_FUNCTION(this);
565 return GetTypeId();
566}
567
569{
570 NS_LOG_FUNCTION(this);
572 SetCode(0);
573 SetFlagM(false);
574 SetFlagO(false);
575 SetFlagH(false);
577 SetLifeTime(0);
580}
581
586
587void
589{
590 NS_LOG_FUNCTION(this << static_cast<uint32_t>(m));
591 m_curHopLimit = m;
592}
593
594uint8_t
596{
597 NS_LOG_FUNCTION(this);
598 return m_curHopLimit;
599}
600
601uint16_t
603{
604 NS_LOG_FUNCTION(this);
605 return m_LifeTime;
606}
607
610{
611 NS_LOG_FUNCTION(this);
612 return m_ReachableTime;
613}
614
621
622void
624{
625 NS_LOG_FUNCTION(this << l);
626 m_LifeTime = l;
627}
628
629void
635
636void
642
643bool
645{
646 NS_LOG_FUNCTION(this);
647 return m_flagM;
648}
649
650void
652{
653 NS_LOG_FUNCTION(this << m);
654 m_flagM = m;
655}
656
657bool
659{
660 NS_LOG_FUNCTION(this);
661 return m_flagO;
662}
663
664void
666{
667 NS_LOG_FUNCTION(this << o);
668 m_flagO = o;
669}
670
671bool
673{
674 NS_LOG_FUNCTION(this);
675 return m_flagH;
676}
677
678void
680{
681 NS_LOG_FUNCTION(this << h);
682 m_flagH = h;
683}
684
685void
686Icmpv6RA::Print(std::ostream& os) const
687{
688 NS_LOG_FUNCTION(this << &os);
689 os << "( type = " << (uint32_t)GetType() << " (RA) code = " << (uint32_t)GetCode()
690 << " checksum = " << (uint32_t)GetChecksum() << ")";
691}
692
695{
696 NS_LOG_FUNCTION(this);
697 return 16;
698}
699
700void
702{
703 NS_LOG_FUNCTION(this << &start);
704 uint16_t checksum = 0;
705 Buffer::Iterator i = start;
706 uint8_t flags = 0;
707
708 i.WriteU8(GetType());
709 i.WriteU8(GetCode());
710 i.WriteHtonU16(0);
712
713 if (m_flagM)
714 {
715 flags |= (uint8_t)(1 << 7);
716 }
717
718 if (m_flagO)
719 {
720 flags |= (uint8_t)(1 << 6);
721 }
722
723 if (m_flagH)
724 {
725 flags |= (uint8_t)(1 << 5);
726 }
727 i.WriteU8(flags);
731
732 i = start;
733 checksum = i.CalculateIpChecksum(i.GetSize(), GetChecksum());
734
735 i = start;
736 i.Next(2);
737 i.WriteU16(checksum);
738}
739
742{
743 NS_LOG_FUNCTION(this << &start);
744 Buffer::Iterator i = start;
745
746 SetType(i.ReadU8());
747 SetCode(i.ReadU8());
748 m_checksum = i.ReadU16();
750 uint8_t flags = i.ReadU8();
751 m_flagM = false;
752 m_flagO = false;
753 m_flagH = false;
754
755 if (flags & (1 << 7))
756 {
757 m_flagM = true;
758 }
759
760 if (flags & (1 << 6))
761 {
762 m_flagO = true;
763 }
764
765 if (flags & (1 << 5))
766 {
767 m_flagH = true;
768 }
772
773 return GetSerializedSize();
774}
775
777
778TypeId
780{
781 static TypeId tid = TypeId("ns3::Icmpv6RS")
783 .SetGroupName("Internet")
784 .AddConstructor<Icmpv6RS>();
785 return tid;
786}
787
788TypeId
790{
791 NS_LOG_FUNCTION(this);
792 return GetTypeId();
793}
794
802
807
810{
811 NS_LOG_FUNCTION(this);
812 return m_reserved;
813}
814
815void
817{
818 NS_LOG_FUNCTION(this << reserved);
819 m_reserved = reserved;
820}
821
822void
823Icmpv6RS::Print(std::ostream& os) const
824{
825 NS_LOG_FUNCTION(this << &os);
826 os << "( type = " << (uint32_t)GetType() << " (RS) code = " << (uint32_t)GetCode()
827 << " checksum = " << (uint32_t)GetChecksum() << ")";
828}
829
832{
833 NS_LOG_FUNCTION(this);
834 return 8;
835}
836
837void
839{
840 NS_LOG_FUNCTION(this << &start);
841
842 uint16_t checksum = 0;
843 Buffer::Iterator i = start;
844
845 i.WriteU8(GetType());
846 i.WriteU8(GetCode());
847 i.WriteU16(0);
849
850 if (m_calcChecksum)
851 {
852 i = start;
853 checksum = i.CalculateIpChecksum(i.GetSize(), GetChecksum());
854
855 i = start;
856 i.Next(2);
857 i.WriteU16(checksum);
858 }
859}
860
863{
864 NS_LOG_FUNCTION(this << &start);
865 Buffer::Iterator i = start;
866
867 SetType(i.ReadU8());
868 SetCode(i.ReadU8());
869 m_checksum = i.ReadU16();
871
872 return GetSerializedSize();
873}
874
876
877TypeId
879{
880 static TypeId tid = TypeId("ns3::Icmpv6Redirection")
882 .SetGroupName("Internet")
883 .AddConstructor<Icmpv6Redirection>();
884 return tid;
885}
886
887TypeId
889{
890 NS_LOG_FUNCTION(this);
891 return GetTypeId();
892}
893
904
909
910void
912{
913 NS_LOG_FUNCTION(this << reserved);
914 m_reserved = reserved;
915}
916
919{
920 NS_LOG_FUNCTION(this);
921 return m_reserved;
922}
923
926{
927 NS_LOG_FUNCTION(this);
928 return m_target;
929}
930
931void
933{
934 NS_LOG_FUNCTION(this << target);
935 m_target = target;
936}
937
940{
941 NS_LOG_FUNCTION(this);
942 return m_destination;
943}
944
945void
947{
948 NS_LOG_FUNCTION(this << destination);
949 m_destination = destination;
950}
951
952void
953Icmpv6Redirection::Print(std::ostream& os) const
954{
955 NS_LOG_FUNCTION(this << &os);
956 os << "( type = " << (uint32_t)GetType() << " (Redirection) code = " << (uint32_t)GetCode()
957 << " checksum = " << (uint32_t)GetChecksum() << " target = " << m_target
958 << " destination = " << m_destination << ")";
959}
960
963{
964 NS_LOG_FUNCTION(this);
965 return 40;
966}
967
968void
970{
971 NS_LOG_FUNCTION(this << &start);
972 uint8_t buff[16];
973 uint16_t checksum = 0;
974 Buffer::Iterator i = start;
975
976 i.WriteU8(GetType());
977 i.WriteU8(GetCode());
978 i.WriteU16(checksum);
980
981 m_target.Serialize(buff);
982 i.Write(buff, 16);
983
984 m_destination.Serialize(buff);
985 i.Write(buff, 16);
986
987 if (m_calcChecksum)
988 {
989 i = start;
990 checksum = i.CalculateIpChecksum(i.GetSize(), GetChecksum());
991
992 i = start;
993 i.Next(2);
994 i.WriteU16(checksum);
995 }
996}
997
1000{
1001 NS_LOG_FUNCTION(this << &start);
1002 uint8_t buff[16];
1003 Buffer::Iterator i = start;
1004
1005 SetType(i.ReadU8());
1006 SetCode(i.ReadU8());
1007 m_checksum = i.ReadU16();
1008 SetReserved(i.ReadU32());
1009
1010 i.Read(buff, 16);
1011 m_target.Set(buff);
1012
1013 i.Read(buff, 16);
1014 m_destination.Set(buff);
1015
1016 return GetSerializedSize();
1017}
1018
1020
1021TypeId
1023{
1024 static TypeId tid = TypeId("ns3::Icmpv6Echo")
1026 .SetGroupName("Internet")
1027 .AddConstructor<Icmpv6Echo>();
1028 return tid;
1029}
1030
1031TypeId
1033{
1034 NS_LOG_FUNCTION(this);
1035 return GetTypeId();
1036}
1037
1039{
1040 NS_LOG_FUNCTION(this);
1042 SetCode(0);
1043 m_checksum = 0;
1044 SetId(0);
1045 SetSeq(0);
1046}
1047
1049{
1050 NS_LOG_FUNCTION(this << request);
1052 SetCode(0);
1053 m_checksum = 0;
1054 SetId(0);
1055 SetSeq(0);
1056}
1057
1062
1063uint16_t
1065{
1066 NS_LOG_FUNCTION(this);
1067 return m_id;
1068}
1069
1070void
1072{
1073 NS_LOG_FUNCTION(this << id);
1074 m_id = id;
1075}
1076
1077uint16_t
1079{
1080 NS_LOG_FUNCTION(this);
1081 return m_seq;
1082}
1083
1084void
1086{
1087 NS_LOG_FUNCTION(this << seq);
1088 m_seq = seq;
1089}
1090
1091void
1092Icmpv6Echo::Print(std::ostream& os) const
1093{
1094 NS_LOG_FUNCTION(this << &os);
1095 os << "( type = " << (GetType() == 128 ? "128 (Request)" : "129 (Reply)")
1096 << " Id = " << (uint32_t)GetId() << " SeqNo = " << (uint32_t)GetSeq()
1097 << " checksum = " << (uint32_t)GetChecksum() << ")";
1098}
1099
1102{
1103 NS_LOG_FUNCTION(this);
1104 return 8;
1105}
1106
1107void
1109{
1110 NS_LOG_FUNCTION(this << &start);
1111 uint16_t checksum = 0;
1112 Buffer::Iterator i = start;
1113
1114 i.WriteU8(GetType());
1115 i.WriteU8(GetCode());
1116 i.WriteHtonU16(0);
1117
1118 i.WriteHtonU16(m_id);
1120
1121 if (m_calcChecksum)
1122 {
1123 i = start;
1124 checksum = i.CalculateIpChecksum(i.GetSize(), GetChecksum());
1125 i = start;
1126 i.Next(2);
1127 i.WriteU16(checksum);
1128 }
1129}
1130
1133{
1134 NS_LOG_FUNCTION(this << &start);
1135 Buffer::Iterator i = start;
1136
1137 SetType(i.ReadU8());
1138 SetCode(i.ReadU8());
1139 m_checksum = i.ReadU16();
1140
1141 m_id = i.ReadNtohU16();
1142 m_seq = i.ReadNtohU16();
1143 return GetSerializedSize();
1144}
1145
1147
1148TypeId
1150{
1151 static TypeId tid = TypeId("ns3::Icmpv6DestinationUnreachable")
1153 .SetGroupName("Internet")
1154 .AddConstructor<Icmpv6DestinationUnreachable>();
1155 return tid;
1156}
1157
1158TypeId
1164
1171
1176
1177void
1179{
1180 NS_LOG_FUNCTION(this << *p);
1181 NS_ASSERT(p->GetSize() <= 1280);
1182 m_packet = p->Copy();
1183}
1184
1185void
1187{
1188 NS_LOG_FUNCTION(this << &os);
1189 os << "( type = " << (uint32_t)GetType()
1190 << " (Destination Unreachable) code = " << (uint32_t)GetCode()
1191 << " checksum = " << (uint32_t)GetChecksum() << ")";
1192}
1193
1196{
1197 NS_LOG_FUNCTION(this);
1198 // The real size of the header is 8 + m_packet->GetSize ()
1199 // HOWEVER we just serialize the first 8 bytes, as the rest is serialized separately.
1200 return 8;
1201}
1202
1203void
1205{
1206 NS_LOG_FUNCTION(this << &start);
1207 uint16_t checksum = 0;
1208 Buffer::Iterator i = start;
1209
1210 Buffer secondaryBuffer;
1211 secondaryBuffer.AddAtStart(8 + m_packet->GetSize());
1212 Buffer::Iterator iter = secondaryBuffer.Begin();
1213
1214 iter.WriteU8(GetType());
1215 iter.WriteU8(GetCode());
1216 iter.WriteU16(0);
1217 iter.WriteU32(0);
1218
1219 uint32_t size = m_packet->GetSize();
1220 auto buf = new uint8_t[size];
1221 m_packet->CopyData(buf, size);
1222 iter.Write(buf, size);
1223 delete[] buf;
1224
1225 iter = secondaryBuffer.Begin();
1226 checksum = iter.CalculateIpChecksum(iter.GetSize(), GetChecksum());
1227
1228 i.WriteU8(GetType());
1229 i.WriteU8(GetCode());
1230 i.WriteU16(checksum);
1231 i.WriteU32(0);
1232}
1233
1236{
1237 NS_LOG_FUNCTION(this << &start);
1238 Buffer::Iterator i = start;
1239
1240 SetType(i.ReadU8());
1241 SetCode(i.ReadU8());
1242 m_checksum = i.ReadU16();
1243 i.ReadU32();
1244
1245 return GetSerializedSize();
1246}
1247
1249
1250TypeId
1252{
1253 static TypeId tid = TypeId("ns3::Icmpv6TooBig")
1255 .SetGroupName("Internet")
1256 .AddConstructor<Icmpv6TooBig>();
1257 return tid;
1258}
1259
1260TypeId
1262{
1263 NS_LOG_FUNCTION(this);
1264 return GetTypeId();
1265}
1266
1268 : m_packet(nullptr),
1269 m_mtu(0)
1270{
1271 NS_LOG_FUNCTION(this);
1273}
1274
1279
1280void
1282{
1283 NS_LOG_FUNCTION(this << *p);
1284 NS_ASSERT(p->GetSize() <= 1280);
1285 m_packet = p->Copy();
1286}
1287
1290{
1291 NS_LOG_FUNCTION(this);
1292 return m_mtu;
1293}
1294
1295void
1297{
1298 NS_LOG_FUNCTION(this << mtu);
1299 m_mtu = mtu;
1300}
1301
1302void
1303Icmpv6TooBig::Print(std::ostream& os) const
1304{
1305 NS_LOG_FUNCTION(this << &os);
1306 os << "( type = " << (uint32_t)GetType() << " (Too Big) code = " << (uint32_t)GetCode()
1307 << " checksum = " << (uint32_t)GetChecksum() << " mtu = " << (uint32_t)GetMtu() << ")";
1308}
1309
1312{
1313 NS_LOG_FUNCTION(this);
1314 // The real size of the header is 8 + m_packet->GetSize ()
1315 // HOWEVER we just serialize the first 8 bytes, as the rest is serialized separately.
1316 return 8;
1317}
1318
1319void
1321{
1322 NS_LOG_FUNCTION(this << &start);
1323 uint16_t checksum = 0;
1324 Buffer::Iterator i = start;
1325
1326 Buffer secondaryBuffer;
1327 secondaryBuffer.AddAtStart(8 + m_packet->GetSize());
1328 Buffer::Iterator iter = secondaryBuffer.Begin();
1329
1330 iter.WriteU8(GetType());
1331 iter.WriteU8(GetCode());
1332 iter.WriteU16(0);
1333 iter.WriteHtonU32(GetMtu());
1334
1335 uint32_t size = m_packet->GetSize();
1336 auto buf = new uint8_t[size];
1337 m_packet->CopyData(buf, size);
1338 iter.Write(buf, size);
1339 delete[] buf;
1340
1341 iter = secondaryBuffer.Begin();
1342 checksum = iter.CalculateIpChecksum(iter.GetSize(), GetChecksum());
1343
1344 i.WriteU8(GetType());
1345 i.WriteU8(GetCode());
1346 i.WriteU16(checksum);
1347 i.WriteHtonU32(GetMtu());
1348}
1349
1352{
1353 NS_LOG_FUNCTION(this << &start);
1354 Buffer::Iterator i = start;
1355
1356 SetType(i.ReadU8());
1357 SetCode(i.ReadU8());
1358 m_checksum = i.ReadU16();
1359 SetMtu(i.ReadNtohU32());
1360
1361 return GetSerializedSize();
1362}
1363
1365
1366TypeId
1368{
1369 static TypeId tid = TypeId("ns3::Icmpv6TimeExceeded")
1371 .SetGroupName("Internet")
1372 .AddConstructor<Icmpv6TimeExceeded>();
1373 return tid;
1374}
1375
1376TypeId
1378{
1379 NS_LOG_FUNCTION(this);
1380 return GetTypeId();
1381}
1382
1389
1394
1395void
1397{
1398 NS_LOG_FUNCTION(this << *p);
1399 NS_ASSERT(p->GetSize() <= 1280);
1400 m_packet = p->Copy();
1401}
1402
1403void
1404Icmpv6TimeExceeded::Print(std::ostream& os) const
1405{
1406 NS_LOG_FUNCTION(this << &os);
1407 os << "( type = " << (uint32_t)GetType()
1408 << " (Destination Unreachable) code = " << (uint32_t)GetCode()
1409 << " checksum = " << (uint32_t)GetChecksum() << ")";
1410}
1411
1414{
1415 NS_LOG_FUNCTION(this);
1416 // The real size of the header is 8 + m_packet->GetSize ()
1417 // HOWEVER we just serialize the first 8 bytes, as the rest is serialized separately.
1418 return 8;
1419}
1420
1421void
1423{
1424 NS_LOG_FUNCTION(this << &start);
1425 uint16_t checksum = 0;
1426 Buffer::Iterator i = start;
1427
1428 Buffer secondaryBuffer;
1429 secondaryBuffer.AddAtStart(8 + m_packet->GetSize());
1430 Buffer::Iterator iter = secondaryBuffer.Begin();
1431
1432 iter.WriteU8(GetType());
1433 iter.WriteU8(GetCode());
1434 iter.WriteU16(0);
1435 iter.WriteU32(0);
1436
1437 uint32_t size = m_packet->GetSize();
1438 auto buf = new uint8_t[size];
1439 m_packet->CopyData(buf, size);
1440 iter.Write(buf, size);
1441 delete[] buf;
1442
1443 iter = secondaryBuffer.Begin();
1444 checksum = iter.CalculateIpChecksum(iter.GetSize(), GetChecksum());
1445
1446 i.WriteU8(GetType());
1447 i.WriteU8(GetCode());
1448 i.WriteU16(checksum);
1449 i.WriteU32(0);
1450}
1451
1454{
1455 NS_LOG_FUNCTION(this << &start);
1456 Buffer::Iterator i = start;
1457
1458 SetType(i.ReadU8());
1459 SetCode(i.ReadU8());
1460 m_checksum = i.ReadU16();
1461 i.ReadU32();
1462
1463 return GetSerializedSize();
1464}
1465
1467
1468TypeId
1470{
1471 static TypeId tid = TypeId("ns3::Icmpv6ParameterError")
1473 .SetGroupName("Internet")
1474 .AddConstructor<Icmpv6ParameterError>();
1475 return tid;
1476}
1477
1478TypeId
1480{
1481 NS_LOG_FUNCTION(this);
1482 return GetTypeId();
1483}
1484
1492
1497
1498void
1500{
1501 NS_LOG_FUNCTION(this << *p);
1502 NS_ASSERT(p->GetSize() <= 1280);
1503 m_packet = p->Copy();
1504}
1505
1508{
1509 NS_LOG_FUNCTION(this);
1510 return m_ptr;
1511}
1512
1513void
1515{
1516 NS_LOG_FUNCTION(this << ptr);
1517 m_ptr = ptr;
1518}
1519
1520void
1521Icmpv6ParameterError::Print(std::ostream& os) const
1522{
1523 NS_LOG_FUNCTION(this << &os);
1524 os << "( type = " << (uint32_t)GetType()
1525 << " (Destination Unreachable) code = " << (uint32_t)GetCode()
1526 << " checksum = " << (uint32_t)GetChecksum() << " ptr = " << (uint32_t)GetPtr() << ")";
1527}
1528
1531{
1532 NS_LOG_FUNCTION(this);
1533 // The real size of the header is 8 + m_packet->GetSize ()
1534 // HOWEVER we just serialize the first 8 bytes, as the rest is serialized separately.
1535 return 8;
1536}
1537
1538void
1540{
1541 NS_LOG_FUNCTION(this << &start);
1542 uint16_t checksum = 0;
1543 Buffer::Iterator i = start;
1544
1545 Buffer secondaryBuffer;
1546 secondaryBuffer.AddAtStart(8 + m_packet->GetSize());
1547 Buffer::Iterator iter = secondaryBuffer.Begin();
1548
1549 iter.WriteU8(GetType());
1550 iter.WriteU8(GetCode());
1551 iter.WriteU16(0);
1552 iter.WriteHtonU32(GetPtr());
1553
1554 uint32_t size = m_packet->GetSize();
1555 auto buf = new uint8_t[size];
1556 m_packet->CopyData(buf, size);
1557 iter.Write(buf, size);
1558 delete[] buf;
1559
1560 iter = secondaryBuffer.Begin();
1561 checksum = iter.CalculateIpChecksum(iter.GetSize(), GetChecksum());
1562
1563 i.WriteU8(GetType());
1564 i.WriteU8(GetCode());
1565 i.WriteU16(checksum);
1566 i.WriteHtonU32(GetPtr());
1567}
1568
1571{
1572 NS_LOG_FUNCTION(this << &start);
1573 Buffer::Iterator i = start;
1574
1575 SetType(i.ReadU8());
1576 SetCode(i.ReadU8());
1577 m_checksum = i.ReadU16();
1578 SetPtr(i.ReadNtohU32());
1579
1580 return GetSerializedSize();
1581}
1582
1584
1585TypeId
1587{
1588 static TypeId tid = TypeId("ns3::Icmpv6OptionHeader")
1589 .SetParent<Header>()
1590 .SetGroupName("Internet")
1591 .AddConstructor<Icmpv6OptionHeader>();
1592 return tid;
1593}
1594
1595TypeId
1597{
1598 NS_LOG_FUNCTION(this);
1599 return GetTypeId();
1600}
1601
1603{
1604 NS_LOG_FUNCTION(this);
1605 /** @todo */
1606 m_type = 0;
1607 m_len = 0;
1608}
1609
1614
1615uint8_t
1617{
1618 NS_LOG_FUNCTION(this);
1619 return m_type;
1620}
1621
1622void
1624{
1625 NS_LOG_FUNCTION(this << static_cast<uint32_t>(type));
1626 m_type = type;
1627}
1628
1629uint8_t
1631{
1632 NS_LOG_FUNCTION(this);
1633 return m_len;
1634}
1635
1636void
1638{
1639 NS_LOG_FUNCTION(this << static_cast<uint32_t>(len));
1640 m_len = len;
1641}
1642
1643void
1644Icmpv6OptionHeader::Print(std::ostream& os) const
1645{
1646 NS_LOG_FUNCTION(this << &os);
1647 os << "( type = " << (uint32_t)GetType() << " length = " << (uint32_t)GetLength() << ")";
1648}
1649
1652{
1653 NS_LOG_FUNCTION(this);
1654 return m_len * 8;
1655}
1656
1659{
1660 NS_LOG_FUNCTION(this << &start);
1661 return GetSerializedSize();
1662}
1663
1664void
1666{
1667 NS_LOG_FUNCTION(this << &start);
1668}
1669
1671
1672TypeId
1674{
1675 static TypeId tid = TypeId("ns3::Icmpv6OptionMtu")
1677 .SetGroupName("Internet")
1678 .AddConstructor<Icmpv6OptionMtu>();
1679 return tid;
1680}
1681
1682TypeId
1684{
1685 NS_LOG_FUNCTION(this);
1686 return GetTypeId();
1687}
1688
1696
1698 : m_mtu(mtu)
1699{
1700 NS_LOG_FUNCTION(this << mtu);
1702 SetLength(1);
1703 SetReserved(0);
1704}
1705
1710
1711uint16_t
1713{
1714 NS_LOG_FUNCTION(this);
1715 return m_reserved;
1716}
1717
1718void
1720{
1721 NS_LOG_FUNCTION(this << reserved);
1722 m_reserved = reserved;
1723}
1724
1727{
1728 NS_LOG_FUNCTION(this);
1729 return m_mtu;
1730}
1731
1732void
1734{
1735 NS_LOG_FUNCTION(this << mtu);
1736 m_mtu = mtu;
1737}
1738
1739void
1740Icmpv6OptionMtu::Print(std::ostream& os) const
1741{
1742 NS_LOG_FUNCTION(this << &os);
1743 os << "( type = " << (uint32_t)GetType() << " length = " << (uint32_t)GetLength()
1744 << " MTU = " << m_mtu << ")";
1745}
1746
1749{
1750 NS_LOG_FUNCTION(this);
1751 return 8; /* m_len = 1 so the real size is multiple by 8 */
1752}
1753
1754void
1756{
1757 NS_LOG_FUNCTION(this << &start);
1758 Buffer::Iterator i = start;
1759 i.WriteU8(GetType());
1760 i.WriteU8(GetLength());
1762 i.WriteHtonU32(GetMtu());
1763}
1764
1767{
1768 NS_LOG_FUNCTION(this << &start);
1769 Buffer::Iterator i = start;
1770 SetType(i.ReadU8());
1771 SetLength(i.ReadU8());
1773 SetMtu(i.ReadNtohU32());
1774 return GetSerializedSize();
1775}
1776
1778
1779TypeId
1781{
1782 static TypeId tid = TypeId("ns3::Icmpv6OptionPrefixInformation")
1784 .SetGroupName("Internet")
1785 .AddConstructor<Icmpv6OptionPrefixInformation>();
1786 return tid;
1787}
1788
1789TypeId
1795
1808
1810{
1811 NS_LOG_FUNCTION(this << prefix << static_cast<uint32_t>(prefixlen));
1813 SetLength(4);
1814 SetPrefix(prefix);
1815 SetPrefixLength(prefixlen);
1816 SetValidTime(0);
1818 SetFlags(0);
1819 SetReserved(0);
1820}
1821
1826
1827uint8_t
1833
1834void
1836{
1837 NS_LOG_FUNCTION(this << static_cast<uint32_t>(prefixLength));
1838 NS_ASSERT(prefixLength <= 128);
1839 m_prefixLength = prefixLength;
1840}
1841
1842uint8_t
1844{
1845 NS_LOG_FUNCTION(this);
1846 return m_flags;
1847}
1848
1849void
1851{
1852 NS_LOG_FUNCTION(this);
1853 m_flags = flags;
1854}
1855
1862
1863void
1865{
1866 NS_LOG_FUNCTION(this << validTime);
1867 m_validTime = validTime;
1868}
1869
1876
1877void
1879{
1880 NS_LOG_FUNCTION(this << preferredTime);
1881 m_preferredTime = preferredTime;
1882}
1883
1890
1891void
1893{
1894 NS_LOG_FUNCTION(this << reserved);
1895 m_reserved = reserved;
1896}
1897
1900{
1901 NS_LOG_FUNCTION(this);
1902 return m_prefix;
1903}
1904
1905void
1907{
1908 NS_LOG_FUNCTION(this << prefix);
1909 m_prefix = prefix;
1910}
1911
1912void
1914{
1915 NS_LOG_FUNCTION(this << &os);
1916 os << "( type = " << (uint32_t)GetType() << " length = " << (uint32_t)GetLength() << " prefix "
1917 << m_prefix << ")";
1918}
1919
1922{
1923 NS_LOG_FUNCTION(this);
1924 return 32;
1925}
1926
1927void
1929{
1930 NS_LOG_FUNCTION(this << &start);
1931 Buffer::Iterator i = start;
1932 uint8_t buf[16];
1933
1934 memset(buf, 0x00, sizeof(buf));
1935
1936 i.WriteU8(GetType());
1937 i.WriteU8(GetLength());
1939 i.WriteU8(m_flags);
1943 m_prefix.GetBytes(buf);
1944 i.Write(buf, 16);
1945}
1946
1949{
1950 NS_LOG_FUNCTION(this << &start);
1951 Buffer::Iterator i = start;
1952 uint8_t buf[16];
1953
1954 SetType(i.ReadU8());
1955 SetLength(i.ReadU8());
1957 SetFlags(i.ReadU8());
1961 i.Read(buf, 16);
1962
1963 Ipv6Address prefix(buf);
1964 SetPrefix(prefix);
1965
1966 return GetSerializedSize();
1967}
1968
1970
1971TypeId
1973{
1974 static TypeId tid = TypeId("ns3::Icmpv6OptionLinkLayerAddress")
1976 .SetGroupName("Internet")
1977 .AddConstructor<Icmpv6OptionLinkLayerAddress>();
1978 return tid;
1979}
1980
1981TypeId
1987
1994
2000
2002{
2003 NS_LOG_FUNCTION(this << source << addr);
2006 SetAddress(addr);
2007
2008 uint8_t len = (2 + m_addr.GetLength()) / 8;
2009 if ((2 + m_addr.GetLength()) % 8)
2010 {
2011 len++;
2012 }
2013 SetLength(len);
2014}
2015
2020
2021Address
2023{
2024 NS_LOG_FUNCTION(this);
2025 return m_addr;
2026}
2027
2028void
2030{
2031 NS_LOG_FUNCTION(this << addr);
2032 m_addr = addr;
2033}
2034
2035void
2037{
2038 NS_LOG_FUNCTION(this << &os);
2039 os << "( type = " << (uint32_t)GetType() << " length = " << (uint32_t)GetLength()
2040 << " L2 Address = " << m_addr << ")";
2041}
2042
2045{
2046 NS_LOG_FUNCTION(this);
2047 uint8_t nb = GetLength() * 8;
2048 return nb;
2049}
2050
2051void
2053{
2054 NS_LOG_FUNCTION(this << &start);
2055 Buffer::Iterator i = start;
2056 uint8_t mac[32];
2057
2058 i.WriteU8(GetType());
2059 i.WriteU8(GetLength());
2060 m_addr.CopyTo(mac);
2061 i.Write(mac, m_addr.GetLength());
2062
2063 uint8_t len = GetLength() * 8 - (2 + m_addr.GetLength());
2064 for (uint8_t nb = 0; nb < len; nb++)
2065 {
2066 i.WriteU8(0);
2067 }
2068}
2069
2072{
2073 NS_LOG_FUNCTION(this << &start);
2074 Buffer::Iterator i = start;
2075 uint8_t mac[32];
2076
2077 SetType(i.ReadU8());
2078 SetLength(i.ReadU8());
2079 // -fstrict-overflow sensitive, see bug 1868
2080 NS_ASSERT(GetLength() * 8 <= 32 + 2);
2081 i.Read(mac, (GetLength() * 8) - 2);
2082
2083 m_addr.SetType("MacAddress", (GetLength() * 8) - 2);
2084 m_addr.CopyFrom(mac, (GetLength() * 8) - 2);
2085
2086 return GetSerializedSize();
2087}
2088
2090
2091TypeId
2093{
2094 static TypeId tid = TypeId("ns3::Icmpv6OptionRedirected")
2096 .SetGroupName("Internet")
2097 .AddConstructor<Icmpv6OptionRedirected>();
2098 return tid;
2099}
2100
2101TypeId
2103{
2104 NS_LOG_FUNCTION(this);
2105 return GetTypeId();
2106}
2107
2114
2120
2121void
2123{
2124 NS_LOG_FUNCTION(this << *packet);
2125 NS_ASSERT(packet->GetSize() <= 1280);
2126 m_packet = packet->Copy();
2127 SetLength(1 + (m_packet->GetSize() / 8));
2128}
2129
2130void
2131Icmpv6OptionRedirected::Print(std::ostream& os) const
2132{
2133 NS_LOG_FUNCTION(this << &os);
2134 os << "( type = " << (uint32_t)GetType() << " length = " << (uint32_t)GetLength() << ")";
2135}
2136
2139{
2140 NS_LOG_FUNCTION(this);
2141 return 8 + m_packet->GetSize();
2142}
2143
2144void
2146{
2147 NS_LOG_FUNCTION(this << &start);
2148 Buffer::Iterator i = start;
2149
2150 i.WriteU8(GetType());
2151 i.WriteU8(GetLength());
2152 // Reserved
2153 i.WriteU16(0);
2154 i.WriteU32(0);
2155
2156 uint32_t size = m_packet->GetSize();
2157 auto buf = new uint8_t[size];
2158 m_packet->CopyData(buf, size);
2159 i.Write(buf, size);
2160 delete[] buf;
2161}
2162
2165{
2166 NS_LOG_FUNCTION(this << &start);
2167 Buffer::Iterator i = start;
2168
2169 SetType(i.ReadU8());
2170 uint8_t length = i.ReadU8();
2171 SetLength(length);
2172 i.ReadU16();
2173 i.ReadU32();
2174
2175 uint32_t len2 = (GetLength() - 1) * 8;
2176 auto buff = new uint8_t[len2];
2177 i.Read(buff, len2);
2178 m_packet = Create<Packet>(buff, len2);
2179 delete[] buff;
2180
2181 return GetSerializedSize();
2182}
2183
2184} /* namespace ns3 */
uint32_t r
a polymophic address class
Definition address.h:114
iterator in a Buffer instance
Definition buffer.h:109
void WriteU32(uint32_t data)
Definition buffer.cc:855
uint16_t CalculateIpChecksum(uint16_t size)
Calculate the checksum.
Definition buffer.cc:1122
void WriteU8(uint8_t data)
Definition buffer.h:944
void Write(const uint8_t *buffer, uint32_t size)
Definition buffer.cc:935
void WriteU16(uint16_t data)
Definition buffer.cc:846
void Read(uint8_t *buffer, uint32_t size)
Definition buffer.cc:1112
void WriteHtonU16(uint16_t data)
Definition buffer.h:978
uint32_t ReadNtohU32()
Definition buffer.h:1041
uint32_t ReadU32()
Definition buffer.cc:953
void WriteHtonU32(uint32_t data)
Definition buffer.h:996
uint16_t ReadNtohU16()
Definition buffer.h:1017
uint32_t GetSize() const
Definition buffer.cc:1153
uint16_t ReadU16()
Definition buffer.h:1098
void Next()
go forward by one byte
Definition buffer.h:916
automatically resized byte buffer
Definition buffer.h:103
void AddAtStart(uint32_t start)
Definition buffer.cc:303
Buffer::Iterator Begin() const
Definition buffer.h:1137
Protocol header serialization and deserialization.
Definition header.h:36
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.
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.
bool m_verifyChecksum
true if the checksum must be verified during Deserialize
TypeId GetInstanceTypeId() const override
Get the instance type ID.
uint16_t CalculateHeaderChecksum(uint16_t size) const
Calculate the partial checksum of the IPv6 pseudo header.
static TypeId GetTypeId()
Get the UID of this class.
uint16_t m_checksum
The checksum.
Ipv6Address m_destination
Destination address of the IPv6 pseudo header.
void InitializeChecksum(Ipv6Address source, Ipv6Address destination)
Initialize the IPv6 pseudo header used for checksum verification.
void Serialize(Buffer::Iterator start) const override
Serialize the packet.
void SetCode(uint8_t code)
Set the code field.
Ipv6Address m_source
Source address of the IPv6 pseudo header.
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.
bool m_goodChecksum
true if the checksum is correct
@ ICMPV6_ERROR_DESTINATION_UNREACHABLE
~Icmpv6Header() override
Destructor.
void SetChecksum(uint16_t checksum)
Set the checksum.
void CalculatePseudoHeaderChecksum(Ipv6Address src, Ipv6Address dst, uint16_t length)
Calculate pseudo header checksum for IPv6.
void Print(std::ostream &os) const override
Print information.
bool IsChecksumOk() const
Checks if the message checksum is correct.
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(Ipv6Address target)
Constructor.
~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.
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.
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.
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
a unique identifier for an interface.
Definition type-id.h:50
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1003
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:201
#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:35
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:492
constexpr uint8_t ICMPV6
ICMP for IPv6 [RFC8200].
Every class exported by the ns3 library is enclosed in the ns3 namespace.