|
INET Framework for OMNeT++/OMNEST
|
ARP implementation.
More...
#include <Arp.h>
◆ ArpCache
◆ MsgPtrVector
◆ Arp()
◆ ~Arp()
◆ addressRecognized()
215 if (
rt->isLocalAddress(destAddr))
222 NetworkInterface *rtie =
rt->getInterfaceForDestAddr(destAddr);
223 return rtie !=
nullptr && rtie != ie;
Referenced by processArpPacket().
◆ dumpArpPacket()
| void inet::Arp::dumpArpPacket |
( |
const ArpPacket * |
arp | ) |
|
|
protectedvirtual |
232 EV_DETAIL << (arp->getOpcode() ==
ARP_REQUEST ?
"ARP_REQ" : arp->getOpcode() ==
ARP_REPLY ?
"ARP_REPLY" :
"unknown type")
233 <<
" src=" << arp->getSrcIpAddress() <<
" / " << arp->getSrcMacAddress()
234 <<
" dest=" << arp->getDestIpAddress() <<
" / " << arp->getDestMacAddress() <<
"\n";
Referenced by processArpPacket().
◆ finish()
| void inet::Arp::finish |
( |
| ) |
|
|
overrideprotectedvirtual |
◆ flush()
| void inet::Arp::flush |
( |
| ) |
|
|
protectedvirtual |
◆ getL3AddressFor()
Returns the Layer 3 address for the given MAC address.
If it is not available (not in the cache, pending resolution, or already expired), UNSPECIFIED_ADDRESS is returned.
Implements inet::IArp.
436 if (macAddr.isUnspecified())
439 simtime_t now = simTime();
441 if (elem.second->macAddress == macAddr && elem.second->lastUpdate +
cacheTimeout >= now)
◆ handleCrashOperation()
◆ handleMessageWhenUp()
| void inet::Arp::handleMessageWhenUp |
( |
cMessage * |
msg | ) |
|
|
overrideprotectedvirtual |
◆ handleStartOperation()
◆ handleStopOperation()
◆ initialize()
| void inet::Arp::initialize |
( |
int |
stage | ) |
|
|
overrideprotectedvirtual |
◆ initiateArpResolution()
137 entry->pending =
true;
138 entry->numRetries = 0;
139 entry->lastUpdate = SIMTIME_ZERO;
141 entry->ipv4Address = nextHopAddr;
145 cMessage *msg = entry->timer =
new cMessage(
"ARP timeout");
146 msg->setContextPointer(entry);
Referenced by resolveL3Address().
◆ isInitializeStage()
| virtual bool inet::Arp::isInitializeStage |
( |
int |
stage | ) |
const |
|
inlineoverrideprotectedvirtual |
◆ isModuleStartStage()
| virtual bool inet::Arp::isModuleStartStage |
( |
int |
stage | ) |
const |
|
inlineoverrideprotectedvirtual |
◆ isModuleStopStage()
| virtual bool inet::Arp::isModuleStopStage |
( |
int |
stage | ) |
const |
|
inlineoverrideprotectedvirtual |
◆ mapMulticastAddress()
◆ numInitStages()
| virtual int inet::Arp::numInitStages |
( |
| ) |
const |
|
inlineoverridevirtual |
◆ processArpPacket()
| void inet::Arp::processArpPacket |
( |
Packet * |
packet | ) |
|
|
protectedvirtual |
239 EV_INFO <<
"Received " << packet <<
" from network protocol.\n";
240 const auto& arp = packet->peekAtFront<ArpPacket>();
244 NetworkInterface *ie =
ift->getInterfaceById(packet->getTag<InterfaceInd>()->getInterfaceId());
274 MacAddress srcMacAddress = arp->getSrcMacAddress();
275 Ipv4Address srcIpAddress = arp->getSrcIpAddress();
277 if (srcMacAddress.isUnspecified())
278 throw cRuntimeError(
"wrong ARP packet: source MAC address is empty");
279 if (srcIpAddress.isUnspecified())
280 throw cRuntimeError(
"wrong ARP packet: source IPv4 address is empty");
282 bool mergeFlag =
false;
284 auto it =
arpCache.find(srcIpAddress);
287 ArpCacheEntry *entry = it->second;
298 ArpCacheEntry *entry;
303 entry =
new ArpCacheEntry();
305 entry->ipv4Address = srcIpAddress;
308 entry->pending =
false;
309 entry->timer =
nullptr;
310 entry->numRetries = 0;
316 switch (arp->getOpcode()) {
318 EV_DETAIL <<
"Packet was ARP REQUEST, sending REPLY\n";
320 if (myMACAddress.isUnspecified()) {
325 Ipv4Address myIPAddress = ie->getProtocolData<Ipv4InterfaceData>()->getIPAddress();
328 const auto& arpReply = makeShared<ArpPacket>();
329 Ipv4Address origDestAddress = arp->getDestIpAddress();
330 arpReply->setDestIpAddress(srcIpAddress);
331 arpReply->setDestMacAddress(srcMacAddress);
332 arpReply->setSrcIpAddress(origDestAddress);
333 arpReply->setSrcMacAddress(myMACAddress);
335 Packet *outPk =
new Packet(
"arpREPLY");
336 outPk->insertAtFront(arpReply);
337 outPk->addTag<MacAddressReq>()->setDestAddress(srcMacAddress);
338 outPk->addTag<
InterfaceReq>()->setInterfaceId(ie->getInterfaceId());
339 if (ie->getProtocol() !=
nullptr)
346 EV_INFO <<
"Sending " << outPk <<
" to network protocol.\n";
348 send(outPk,
"ifOut");
354 EV_DETAIL <<
"Discarding packet\n";
359 throw cRuntimeError(
"RARP request received: RARP is not supported");
362 throw cRuntimeError(
"RARP reply received: RARP is not supported");
365 throw cRuntimeError(
"Unsupported opcode %d in received ARP packet", arp->getOpcode());
370 EV_INFO <<
"IPv4 address " << arp->getDestIpAddress() <<
" not recognized, dropping ARP packet\n";
Referenced by handleMessageWhenUp().
◆ refreshDisplay()
| void inet::Arp::refreshDisplay |
( |
| ) |
const |
|
overrideprotectedvirtual |
127 std::stringstream os;
132 getDisplayString().setTagArg(
"t", 0, os.str().c_str());
◆ requestTimedOut()
| void inet::Arp::requestTimedOut |
( |
cMessage * |
selfmsg | ) |
|
|
protectedvirtual |
190 ArpCacheEntry *entry = (ArpCacheEntry *)selfmsg->getContextPointer();
194 Ipv4Address nextHopAddr = entry->ipv4Address;
195 EV_INFO <<
"ARP request for " << nextHopAddr <<
" timed out, resending\n";
205 EV <<
"ARP timeout, max retry count " <<
retryCount <<
" for " << entry->ipv4Address <<
" reached.\n";
Referenced by handleMessageWhenUp().
◆ resolveL3Address()
IArp implementation.
Implements inet::IArp.
399 Enter_Method(
"resolveMACAddress(%s,%s)", address.str().c_str(), ie->getInterfaceName());
401 Ipv4Address addr = address.toIpv4();
405 ArpCacheEntry *entry =
new ArpCacheEntry();
408 entry->ipv4Address = addr;
411 EV <<
"Starting ARP resolution for " << addr <<
"\n";
415 else if (it->second->pending) {
417 EV <<
"ARP resolution for " << addr <<
" is already pending\n";
420 else if (it->second->lastUpdate +
cacheTimeout >= simTime()) {
421 return it->second->macAddress;
424 EV <<
"ARP cache entry for " << addr <<
" expired, starting new ARP resolution\n";
425 ArpCacheEntry *entry = it->second;
◆ resolveMacAddressForArpReply()
◆ sendArpGratuitous()
453 ASSERT(!srcAddr.isUnspecified());
454 ASSERT(!ipAddr.isUnspecified());
457 Packet *packet =
new Packet(
"arpGrt");
458 const auto& arp = makeShared<ArpPacket>();
459 arp->setOpcode(opCode);
460 arp->setSrcMacAddress(srcAddr);
461 arp->setSrcIpAddress(ipAddr);
462 arp->setDestIpAddress(ipAddr);
464 packet->insertAtFront(arp);
466 auto macAddrReq = packet->addTag<MacAddressReq>();
467 macAddrReq->setSrcAddress(srcAddr);
469 packet->addTag<
InterfaceReq>()->setInterfaceId(ie->getInterfaceId());
470 if (ie->getProtocol() !=
nullptr)
476 ArpCacheEntry *entry =
new ArpCacheEntry();
478 entry->ipv4Address = ipAddr;
481 entry->pending =
false;
482 entry->timer =
nullptr;
483 entry->numRetries = 0;
485 entry->lastUpdate = simTime();
489 send(packet,
"ifOut");
◆ sendArpProbe()
499 ASSERT(!srcAddr.isUnspecified());
500 ASSERT(!probedAddr.isUnspecified());
502 Packet *packet =
new Packet(
"arpProbe");
503 const auto& arp = makeShared<ArpPacket>();
505 arp->setSrcMacAddress(srcAddr);
507 arp->setDestIpAddress(probedAddr);
509 packet->insertAtFront(arp);
511 auto macAddrReq = packet->addTag<MacAddressReq>();
512 macAddrReq->setSrcAddress(srcAddr);
514 packet->addTag<
InterfaceReq>()->setInterfaceId(ie->getInterfaceId());
515 if (ie->getProtocol() !=
nullptr)
522 send(packet,
"ifOut");
◆ sendArpRequest()
157 MacAddress myMACAddress = ie->getMacAddress();
158 Ipv4Address myIPAddress = ie->getProtocolData<Ipv4InterfaceData>()->getIPAddress();
161 ASSERT(!myMACAddress.isUnspecified());
162 ASSERT(!myIPAddress.isUnspecified());
165 Packet *packet =
new Packet(
"arpREQ");
166 const auto& arp = makeShared<ArpPacket>();
168 arp->setSrcMacAddress(myMACAddress);
169 arp->setSrcIpAddress(myIPAddress);
170 arp->setDestIpAddress(ipAddress);
171 packet->insertAtFront(arp);
174 packet->addTag<
InterfaceReq>()->setInterfaceId(ie->getInterfaceId());
175 if (ie->getProtocol() !=
nullptr)
182 EV_INFO <<
"Sending " << packet <<
" to network protocol.\n";
184 send(packet,
"ifOut");
Referenced by initiateArpResolution(), and requestTimedOut().
◆ updateArpCache()
382 EV_DETAIL <<
"Updating ARP cache entry: " << entry->ipv4Address <<
" <--> " << macAddress <<
"\n";
385 if (entry->pending) {
386 entry->pending =
false;
387 cancelAndDelete(entry->timer);
388 entry->timer =
nullptr;
389 entry->numRetries = 0;
391 entry->macAddress = macAddress;
392 entry->lastUpdate = simTime();
393 Notification signal(entry->ipv4Address, macAddress, entry->ie);
Referenced by processArpPacket().
◆ arpCache
◆ arpReplySentSignal
| simsignal_t inet::Arp::arpReplySentSignal = registerSignal("arpReplySent") |
|
staticprotected |
◆ arpRequestSentSignal
| simsignal_t inet::Arp::arpRequestSentSignal = registerSignal("arpRequestSent") |
|
staticprotected |
◆ cacheTimeout
| simtime_t inet::Arp::cacheTimeout |
|
protected |
◆ ift
◆ numFailedResolutions
| long inet::Arp::numFailedResolutions = 0 |
|
protected |
◆ numRepliesSent
| long inet::Arp::numRepliesSent = 0 |
|
protected |
◆ numRequestsSent
| long inet::Arp::numRequestsSent = 0 |
|
protected |
◆ numResolutions
| long inet::Arp::numResolutions = 0 |
|
protected |
◆ proxyArpInterfaces
| std::string inet::Arp::proxyArpInterfaces = "" |
|
protected |
◆ proxyArpInterfacesMatcher
| cPatternMatcher inet::Arp::proxyArpInterfacesMatcher |
|
protected |
◆ retryCount
| int inet::Arp::retryCount = 0 |
|
protected |
◆ retryTimeout
| simtime_t inet::Arp::retryTimeout |
|
protected |
◆ rt
The documentation for this class was generated from the following files:
static const Protocol arp
Definition: Protocol.h:53
@ ARP_REQUEST
Definition: ArpPacket_m.h:64
int retryCount
Definition: Arp.h:59
ModuleRefByPar< IIpv4RoutingTable > rt
Definition: Arp.h:75
@ STAGE_NETWORK_LAYER
Definition: ModuleOperations.h:53
static simsignal_t arpRequestSentSignal
Definition: Arp.h:69
virtual void initialize(int stage) override
Definition: OperationalMixinImpl.h:26
@ ARP_REPLY
Definition: ArpPacket_m.h:65
@ STAGE_NETWORK_LAYER
Definition: ModuleOperations.h:29
removed InterfaceReq
Definition: IUdp-gates.txt:11
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd DispatchProtocolReq L4PortInd Ipv4ControlInfo Ipv6ControlInfo down DispatchProtocolReq
Definition: IUdp-gates.txt:25
INET_API InitStage INITSTAGE_NETWORK_LAYER
Initialization of network layer protocols.
virtual void dumpArpPacket(const ArpPacket *arp)
Definition: Arp.cc:230
@ ARP_RARP_REPLY
Definition: ArpPacket_m.h:67
simtime_t retryTimeout
Definition: Arp.h:58
simtime_t cacheTimeout
Definition: Arp.h:60
void registerService(const Protocol &protocol, cGate *gate, ServicePrimitive servicePrimitive)
Registers a service primitive (SDU processing) at the given gate.
Definition: IProtocolRegistrationListener.cc:14
static simsignal_t arpReplySentSignal
Definition: Arp.h:70
std::string proxyArpInterfaces
Definition: Arp.h:61
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd DispatchProtocolReq L4PortInd Ipv4ControlInfo Ipv6ControlInfo down PacketProtocolTag
Definition: IUdp-gates.txt:25
ArpCache arpCache
Definition: Arp.h:72
virtual void updateArpCache(ArpCacheEntry *entry, const MacAddress &macAddress)
Definition: Arp.cc:380
virtual void processArpPacket(Packet *packet)
Definition: Arp.cc:237
virtual bool addressRecognized(Ipv4Address destAddr, NetworkInterface *ie)
Definition: Arp.cc:213
virtual MacAddress resolveMacAddressForArpReply(const NetworkInterface *ie, const ArpPacket *arp)
Definition: Arp.cc:375
virtual void flush()
Definition: Arp.cc:111
virtual void sendArpRequest(const NetworkInterface *ie, Ipv4Address ipAddress)
Definition: Arp.cc:154
INET_API InitStage INITSTAGE_LOCAL
Initialization of local state that don't use or affect other modules includes:
long numRequestsSent
Definition: Arp.h:64
static const simsignal_t arpResolutionFailedSignal
Definition: IArp.h:43
#define NUM_INIT_STAGES
Definition: InitStageRegistry.h:73
long numResolutions
Definition: Arp.h:62
ModuleRefByPar< IInterfaceTable > ift
Definition: Arp.h:74
@ ARP_RARP_REQUEST
Definition: ArpPacket_m.h:66
virtual void initiateArpResolution(Ipv4Address ipv4Address, ArpCacheEntry *entry)
Definition: Arp.cc:135
static const simsignal_t arpResolutionInitiatedSignal
Signals used to publish ARP state changes.
Definition: IArp.h:41
static const Ipv4Address UNSPECIFIED_ADDRESS
0.0.0.0
Definition: Ipv4Address.h:91
#define Enter_Method(...)
Definition: SelfDoc.h:71
static const MacAddress BROADCAST_ADDRESS
The broadcast MAC address, ff:ff:ff:ff:ff:ff.
Definition: MacAddress.h:34
static const simsignal_t arpResolutionCompletedSignal
Definition: IArp.h:42
long numFailedResolutions
Definition: Arp.h:63
virtual void requestTimedOut(cMessage *selfmsg)
Definition: Arp.cc:188
long numRepliesSent
Definition: Arp.h:65
static const MacAddress UNSPECIFIED_ADDRESS
The unspecified MAC address, 00:00:00:00:00:00.
Definition: MacAddress.h:31
virtual void refreshDisplay() const override
Definition: OperationalMixinImpl.h:200
void registerProtocol(const Protocol &protocol, cGate *gate, ServicePrimitive servicePrimitive)
Registers a protocol primitive (PDU processing) at the given gate.
Definition: IProtocolRegistrationListener.cc:83
cPatternMatcher proxyArpInterfacesMatcher
Definition: Arp.h:67