ARP.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004 Andras Varga
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public License
00015  * along with this program; if not, see <http://www.gnu.org/licenses/>.
00016 */
00017 
00018 #ifndef __INET_ARP_H
00019 #define __INET_ARP_H
00020 
00021 #include <stdio.h>
00022 #include <string.h>
00023 #include <vector>
00024 #include <map>
00025 #include <omnetpp.h>
00026 #include "IPAddress.h"
00027 #include "ARPPacket_m.h"
00028 #include "IPControlInfo.h"
00029 #include "IPDatagram.h"
00030 #include "IInterfaceTable.h"
00031 #include "InterfaceTableAccess.h"
00032 #include "IRoutingTable.h"
00033 #include "RoutingTableAccess.h"
00034 
00035 
00036 
00040 class INET_API ARP : public cSimpleModule
00041 {
00042   public:
00043     struct ARPCacheEntry;
00044     typedef std::map<IPAddress, ARPCacheEntry*> ARPCache;
00045     typedef std::vector<cMessage*> MsgPtrVector;
00046 
00047     // IPAddress -> MACAddress table
00048     // TBD should we key it on (IPAddress, InterfaceEntry*)?
00049     struct ARPCacheEntry
00050     {
00051         InterfaceEntry *ie; // NIC to send the packet to
00052         bool pending; // true if resolution is pending
00053         MACAddress macAddress;  // MAC address
00054         simtime_t lastUpdate;  // entries should time out after cacheTimeout
00055         int numRetries; // if pending==true: 0 after first ARP request, 1 after second, etc.
00056         cMessage *timer;  // if pending==true: request timeout msg
00057         MsgPtrVector pendingPackets;  // if pending==true: ptrs to packets waiting for resolution
00058                                       // (packets are owned by pendingQueue)
00059         ARPCache::iterator myIter;  // iterator pointing to this entry
00060     };
00061 
00062   protected:
00063     simtime_t retryTimeout;
00064     int retryCount;
00065     simtime_t cacheTimeout;
00066     bool doProxyARP;
00067 
00068     long numResolutions;
00069     long numFailedResolutions;
00070     long numRequestsSent;
00071     long numRepliesSent;
00072 
00073     ARPCache arpCache;
00074 
00075     cQueue pendingQueue; // outbound packets waiting for ARP resolution
00076     int nicOutBaseGateId;  // id of the nicOut[0] gate
00077 
00078     IInterfaceTable *ift;
00079     IRoutingTable *rt;  // for Proxy ARP
00080 
00081   public:
00082     ARP() {}
00083     virtual ~ARP();
00084 
00085   protected:
00086     virtual void initialize();
00087     virtual void handleMessage(cMessage *msg);
00088     virtual void finish();
00089 
00090     virtual void processOutboundPacket(cMessage *msg);
00091     virtual void sendPacketToNIC(cMessage *msg, InterfaceEntry *ie, const MACAddress& macAddress);
00092 
00093     virtual void initiateARPResolution(ARPCacheEntry *entry);
00094     virtual void sendARPRequest(InterfaceEntry *ie, IPAddress ipAddress);
00095     virtual void requestTimedOut(cMessage *selfmsg);
00096     virtual bool addressRecognized(IPAddress destAddr, InterfaceEntry *ie);
00097     virtual void processARPPacket(ARPPacket *arp);
00098     virtual void updateARPCache(ARPCacheEntry *entry, const MACAddress& macAddress);
00099 
00100     virtual void dumpARPPacket(ARPPacket *arp);
00101     virtual void updateDisplayString();
00102 
00103 };
00104 
00105 #endif
00106