|
INET Framework for OMNeT++/OMNEST
|
ICMPv6 implementation.
More...
#include <Icmpv6.h>
|
| virtual void | sendErrorMessage (Packet *datagram, Icmpv6Type type, int code) |
| | This method can be called from other modules to send an ICMPv6 error packet. More...
|
| |
| void | insertCrc (const Ptr< Icmpv6Header > &icmpHeader, Packet *packet) |
| |
| virtual bool | handleOperationStage (LifecycleOperation *operation, IDoneCallback *doneCallback) override |
| | Perform one stage of a lifecycle operation. More...
|
| |
| virtual | ~ILifecycle () |
| |
| virtual void | handleRegisterServiceGroup (const ProtocolGroup &protocolGroup, cGate *gate, ServicePrimitive servicePrimitive) override |
| |
| virtual void | handleRegisterProtocolGroup (const ProtocolGroup &protocolGroup, cGate *gate, ServicePrimitive servicePrimitive) override |
| |
| virtual void | handleRegisterAnyService (cGate *gate, ServicePrimitive servicePrimitive) override |
| |
| virtual void | handleRegisterAnyProtocol (cGate *gate, ServicePrimitive servicePrimitive) override |
| |
|
| typedef std::map< long, int > | PingMap |
| |
◆ PingMap
◆ createDestUnreachableMsg()
254 auto errorMsg = makeShared<Icmpv6DestUnreachableMsg>();
256 errorMsg->setCode(code);
257 auto packet =
new Packet(
"Dest Unreachable");
258 packet->insertAtBack(errorMsg);
Referenced by sendErrorMessage().
◆ createPacketTooBigMsg()
| Packet * inet::Icmpv6::createPacketTooBigMsg |
( |
int |
mtu | ) |
|
|
protectedvirtual |
264 auto errorMsg = makeShared<Icmpv6PacketTooBigMsg>();
266 errorMsg->setCode(0);
267 errorMsg->setMTU(mtu);
268 auto packet =
new Packet(
"Packet Too Big");
269 packet->insertAtBack(errorMsg);
Referenced by sendErrorMessage().
◆ createParamProblemMsg()
285 auto errorMsg = makeShared<Icmpv6ParamProblemMsg>();
287 errorMsg->setCode(code);
289 auto packet =
new Packet(
"Parameter Problem");
290 packet->insertAtBack(errorMsg);
Referenced by sendErrorMessage().
◆ createTimeExceededMsg()
275 auto errorMsg = makeShared<Icmpv6TimeExceededMsg>();
277 errorMsg->setCode(code);
278 auto packet =
new Packet(
"Time Exceeded");
279 packet->insertAtBack(errorMsg);
Referenced by sendErrorMessage().
◆ errorOut()
| void inet::Icmpv6::errorOut |
( |
const Ptr< const Icmpv6Header > & |
header | ) |
|
|
protectedvirtual |
◆ handleMessage()
| void inet::Icmpv6::handleMessage |
( |
cMessage * |
msg | ) |
|
|
overrideprotectedvirtual |
Processing of messages that arrive in this module.
Messages arrived here could be for ICMP ping requests or ICMPv6 messages that require processing.
48 ASSERT(!msg->isSelfMessage());
51 if (msg->getArrivalGate()->isName(
"ipv6In")) {
52 EV_INFO <<
"Processing ICMPv6 message.\n";
57 throw cRuntimeError(
"Message %s(%s) arrived in unknown '%s' gate", msg->getName(), msg->getClassName(), msg->getArrivalGate()->getName());
◆ handleRegisterProtocol()
| void inet::Icmpv6::handleRegisterProtocol |
( |
const Protocol & |
protocol, |
|
|
cGate * |
gate, |
|
|
ServicePrimitive |
servicePrimitive |
|
) |
| |
|
overrideprotectedvirtual |
◆ handleRegisterService()
◆ initialize()
| void inet::Icmpv6::initialize |
( |
int |
stage | ) |
|
|
overrideprotectedvirtual |
Initialization.
29 cSimpleModule::initialize(stage);
32 const char *crcModeString = par(
"crcMode");
37 NodeStatus *nodeStatus =
dynamic_cast<NodeStatus *
>(
getContainingNode(
this)->getSubmodule(
"status"));
38 isOperational = (!nodeStatus) || nodeStatus->getState() ==
NodeStatus::UP;
40 throw cRuntimeError(
"This module doesn't support starting in node DOWN state");
◆ insertCrc() [1/2]
◆ insertCrc() [2/2]
◆ numInitStages()
| virtual int inet::Icmpv6::numInitStages |
( |
| ) |
const |
|
inlineoverrideprotectedvirtual |
◆ processEchoReply()
◆ processEchoRequest()
Respond to the machine that tried to ping us.
150 auto replyPacket =
new Packet();
151 replyPacket->setName((std::string(requestPacket->getName()) +
"-reply").c_str());
152 auto replyHeader = makeShared<Icmpv6EchoReplyMsg>();
153 replyHeader->setIdentifier(requestHeader->getIdentifier());
154 replyHeader->setSeqNumber(requestHeader->getSeqNumber());
155 replyPacket->insertAtBack(requestPacket->peekData());
157 replyPacket->insertAtFront(replyHeader);
159 auto addressInd = requestPacket->getTag<
L3AddressInd>();
161 auto addressReq = replyPacket->addTag<L3AddressReq>();
162 addressReq->setDestAddress(addressInd->getSrcAddress());
164 if (addressInd->getDestAddress().isMulticast() ) {
165 IInterfaceTable *it = getModuleFromPar<IInterfaceTable>(par(
"interfaceTableModule"),
this);
166 auto ipv6Data = it->getInterfaceById(requestPacket->getTag<InterfaceInd>()->getInterfaceId())->getProtocolDataForUpdate<Ipv6InterfaceData>();
167 addressReq->setSrcAddress(ipv6Data->getPreferredAddress());
173 addressReq->setSrcAddress(addressInd->getDestAddress());
175 delete requestPacket;
Referenced by processICMPv6Message().
◆ processICMPv6Message()
| void inet::Icmpv6::processICMPv6Message |
( |
Packet * |
packet | ) |
|
|
protectedvirtual |
64 EV_WARN <<
"incoming ICMP packet has wrong CRC, dropped\n";
65 PacketDropDetails details;
72 auto icmpv6msg = packet->peekAtFront<Icmpv6Header>();
73 int type = icmpv6msg->getType();
76 EV_INFO <<
"ICMPv6 packet: passing it to higher layer\n";
77 const auto& bogusIpv6Header = packet->peekDataAt<Ipv6Header>(icmpv6msg->getChunkLength());
78 int transportProtocol = bogusIpv6Header->getProtocolId();
88 send(packet,
"transportOut");
92 auto icmpv6msg = packet->popAtFront<Icmpv6Header>();
93 if (dynamicPtrCast<const Icmpv6DestUnreachableMsg>(icmpv6msg)) {
94 EV_INFO <<
"ICMPv6 Destination Unreachable Message Received." << endl;
98 else if (dynamicPtrCast<const Icmpv6PacketTooBigMsg>(icmpv6msg)) {
99 EV_INFO <<
"ICMPv6 Packet Too Big Message Received." << endl;
103 else if (dynamicPtrCast<const Icmpv6TimeExceededMsg>(icmpv6msg)) {
104 EV_INFO <<
"ICMPv6 Time Exceeded Message Received." << endl;
108 else if (dynamicPtrCast<const Icmpv6ParamProblemMsg>(icmpv6msg)) {
109 EV_INFO <<
"ICMPv6 Parameter Problem Message Received." << endl;
113 else if (
auto echoRequest = dynamicPtrCast<const Icmpv6EchoRequestMsg>(icmpv6msg)) {
114 EV_INFO <<
"ICMPv6 Echo Request Message Received." << endl;
117 else if (
auto echoReply = dynamicPtrCast<const Icmpv6EchoReplyMsg>(icmpv6msg)) {
118 EV_INFO <<
"ICMPv6 Echo Reply Message Received." << endl;
122 throw cRuntimeError(
"Unknown message type received: (%s)%s.\n", icmpv6msg->getClassName(), icmpv6msg->getName());
Referenced by handleMessage(), and sendErrorMessage().
◆ sendErrorMessage()
| void inet::Icmpv6::sendErrorMessage |
( |
Packet * |
datagram, |
|
|
Icmpv6Type |
type, |
|
|
int |
code |
|
) |
| |
|
virtual |
This method can be called from other modules to send an ICMPv6 error packet.
RFC 2463, Section 3: ICMPv6 Error Messages There are a total of 4 ICMPv6 error messages as described in the RFC. This method will construct and send error messages corresponding to the given type. Error Types:
- Destination Unreachable Message - 1
- Packet Too Big Message - 2
- Time Exceeded Message - 3
- Parameter Problem Message - 4 Code Types have different semantics for each error type. See RFC 2463.
203 throw cRuntimeError(
"Unknown ICMPv6 error type: %d\n",
type);
213 errorMsg->insertAtBack(origDatagram->peekDataAt(
b(0),
std::min(copyLength, origDatagram->getDataLength())));
215 auto icmpHeader = errorMsg->removeAtFront<Icmpv6Header>();
217 errorMsg->insertAtFront(icmpHeader);
220 EV_DEBUG <<
"sending ICMP error: (" << errorMsg->getClassName() <<
")" << errorMsg->getName()
221 <<
" type=" <<
type <<
" code=" << code << endl;
225 const auto& ipv6Header = origDatagram->peekAtFront<Ipv6Header>();
226 if (ipv6Header->getSrcAddress().isUnspecified()) {
235 sendToIP(errorMsg, ipv6Header->getSrcAddress());
Referenced by inet::Ipv6FragBuf::addFragment(), and inet::Ipv6FragBuf::purgeStaleFragments().
◆ sendToIP() [1/2]
| void inet::Icmpv6::sendToIP |
( |
Packet * |
msg | ) |
|
|
protectedvirtual |
249 send(msg,
"ipv6Out");
◆ sendToIP() [2/2]
◆ validateDatagramPromptingError()
| bool inet::Icmpv6::validateDatagramPromptingError |
( |
Packet * |
packet | ) |
|
|
protectedvirtual |
Validate the received Ipv6 datagram before responding with error message.
296 auto ipv6Header = packet->peekAtFront<Ipv6Header>();
298 if (ipv6Header->getDestAddress().isMulticast()) {
299 EV_INFO <<
"won't send ICMP error messages for multicast message " << ipv6Header << endl;
305 auto recICMPMsg = packet->peekDataAt<Icmpv6Header>(ipv6Header->getChunkLength());
306 if (recICMPMsg->getType() < 128) {
307 EV_INFO <<
"ICMP error received -- do not reply to it" << endl;
Referenced by sendErrorMessage().
◆ verifyCrc()
| bool inet::Icmpv6::verifyCrc |
( |
const Packet * |
packet | ) |
|
|
static |
◆ crcMode
◆ pingMap
◆ transportProtocols
| std::set<int> inet::Icmpv6::transportProtocols |
|
protected |
The documentation for this class was generated from the following files:
virtual Packet * createDestUnreachableMsg(Icmpv6DestUnav code)
Definition: Icmpv6.cc:252
CrcMode crcMode
Definition: Icmpv6.h:96
static void insertCrc(CrcMode crcMode, const Ptr< Icmpv6Header > &icmpHeader, Packet *packet)
Definition: Icmpv6.cc:333
Icmpv6ParameterProblem
Enum generated from inet/networklayer/icmpv6/Icmpv6Header.msg:73 by opp_msgtool.
Definition: Icmpv6Header_m.h:167
std::set< int > transportProtocols
Definition: Icmpv6.h:99
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd DispatchProtocolReq L4PortInd Ipv4ControlInfo Ipv6ControlInfo down protocol
Definition: IUdp-gates.txt:25
Icmpv6DestUnav
Enum generated from inet/networklayer/icmpv6/Icmpv6Header.msg:50 by opp_msgtool.
Definition: Icmpv6Header_m.h:122
virtual void errorOut(const Ptr< const Icmpv6Header > &header)
Definition: Icmpv6.cc:314
virtual void processEchoReply(Packet *packet, const Ptr< const Icmpv6EchoReplyMsg > &header)
Forward the ping reply to the "pingOut" of this module.
Definition: Icmpv6.cc:179
@ INCORRECTLY_RECEIVED
Definition: Simsignals_m.h:71
static const Protocol ipv6
Definition: Protocol.h:94
double min(const double a, const double b)
Returns the minimum of a and b.
Definition: SctpAssociation.h:261
cModule * getContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:40
@ IP_PROT_IPv6_ICMP
Definition: IpProtocolId_m.h:101
@ CRC_COMPUTED
Definition: CrcMode_m.h:59
static void serialize(MemoryOutputStream &stream, const Ptr< const Chunk > &chunk, b offset=b(0), b length=b(-1))
Serializes a chunk into the given stream.
Definition: Chunk.cc:175
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd DispatchProtocolReq L4PortInd Ipv4ControlInfo Ipv6ControlInfo down DispatchProtocolReq
Definition: IUdp-gates.txt:25
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd L3AddressInd
Definition: IUdp-gates.txt:20
virtual bool validateDatagramPromptingError(Packet *packet)
Validate the received Ipv6 datagram before responding with error message.
Definition: Icmpv6.cc:294
CrcMode parseCrcMode(const char *crcModeString, bool allowDisable)
Definition: CrcMode.cc:14
void registerService(const Protocol &protocol, cGate *gate, ServicePrimitive servicePrimitive)
Registers a service primitive (SDU processing) at the given gate.
Definition: IProtocolRegistrationListener.cc:14
simsignal_t packetDroppedSignal
Definition: Simsignals.cc:85
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd DispatchProtocolReq L4PortInd Ipv4ControlInfo Ipv6ControlInfo down PacketProtocolTag
Definition: IUdp-gates.txt:25
intscale< b, 1, 8 > B
Definition: Units.h:1168
@ ICMPv6_PARAMETER_PROBLEM
Definition: Icmpv6Header_m.h:88
virtual void sendToIP(Packet *msg, const Ipv6Address &dest)
Definition: Icmpv6.cc:239
virtual void processICMPv6Message(Packet *packet)
Definition: Icmpv6.cc:60
@ ICMPv6_TIME_EXCEEDED
Definition: Icmpv6Header_m.h:87
removed type
Definition: IUdp-gates.txt:7
INET_API InitStage INITSTAGE_LOCAL
Initialization of local state that don't use or affect other modules includes:
int findProtocolNumber(const Protocol *protocol) const
Definition: ProtocolGroup.cc:40
value< int64_t, units::b > b
Definition: Units.h:1241
#define NUM_INIT_STAGES
Definition: InitStageRegistry.h:73
@ PF_ALLOW_INCORRECT
Definition: Chunk.h:281
@ SP_INDICATION
Definition: ProtocolTag_m.h:175
static const Ipv6Address LOOPBACK_ADDRESS
The loopback address.
Definition: Ipv6Address.h:57
Icmpv6TimeEx
Enum generated from inet/networklayer/icmpv6/Icmpv6Header.msg:63 by opp_msgtool.
Definition: Icmpv6Header_m.h:145
static uint16_t checksum(const void *addr, unsigned int count)
Definition: TcpIpChecksum.h:33
@ CRC_DECLARED_CORRECT
Definition: CrcMode_m.h:57
static const Protocol icmpv6
Definition: Protocol.h:72
virtual Packet * createParamProblemMsg(Icmpv6ParameterProblem code)
Definition: Icmpv6.cc:283
@ CRC_DECLARED_INCORRECT
Definition: CrcMode_m.h:58
@ UP
Definition: NodeStatus.h:28
#define Enter_Method(...)
Definition: SelfDoc.h:71
#define IPv6_MIN_MTU
Definition: Ipv6InterfaceData.h:31
static ProtocolGroup ipprotocol
Definition: ProtocolGroup.h:42
@ ICMPv6_PACKET_TOO_BIG
Definition: Icmpv6Header_m.h:86
virtual Packet * createPacketTooBigMsg(int mtu)
Definition: Icmpv6.cc:262
void registerProtocol(const Protocol &protocol, cGate *gate, ServicePrimitive servicePrimitive)
Registers a protocol primitive (PDU processing) at the given gate.
Definition: IProtocolRegistrationListener.cc:83
virtual void processEchoRequest(Packet *packet, const Ptr< const Icmpv6EchoRequestMsg > &header)
Respond to the machine that tried to ping us.
Definition: Icmpv6.cc:147
@ ICMPv6_DESTINATION_UNREACHABLE
Definition: Icmpv6Header_m.h:85
virtual Packet * createTimeExceededMsg(Icmpv6TimeEx code)
Definition: Icmpv6.cc:273
INET_API InitStage INITSTAGE_NETWORK_LAYER_PROTOCOLS
Initialization of network layer protocols over IP.
static bool verifyCrc(const Packet *packet)
Definition: Icmpv6.cc:361