IPv6NeighbourDiscovery.h

Go to the documentation of this file.
00001 
00019 #ifndef IPV6NEIGHBOURDISCOVERY_H
00020 #define IPV6NEIGHBOURDISCOVERY_H
00021 
00022 #include <stdio.h>
00023 #include <string.h>
00024 #include <vector>
00025 #include <set>
00026 #include <omnetpp.h>
00027 #include "IPv6Address.h"
00028 #include "IPv6Datagram.h"
00029 #include "IPv6NDMessage_m.h"
00030 #include "IPv6ControlInfo.h"
00031 #include "IPv6InterfaceData.h"
00032 #include "InterfaceEntry.h"
00033 #include "IInterfaceTable.h"
00034 #include "InterfaceTableAccess.h"
00035 #include "RoutingTable6.h"
00036 #include "RoutingTable6Access.h"
00037 #include "IPv6NeighbourCache.h"
00038 #include "ICMPv6.h"
00039 #include "ICMPv6Access.h"
00040 
00044 class INET_API IPv6NeighbourDiscovery : public cSimpleModule
00045 {
00046     public:
00047         typedef std::vector<cMessage*> MsgPtrVector;
00048         typedef IPv6NeighbourCache::Key Key;//for convenience
00049         typedef IPv6NeighbourCache::Neighbour Neighbour;  // for convenience
00050 
00051     public:
00052         IPv6NeighbourDiscovery();
00053         virtual ~IPv6NeighbourDiscovery();
00054 
00055     public:
00072         const MACAddress& resolveNeighbour(const IPv6Address& nextHop, int interfaceId);
00073 
00083         virtual void reachabilityConfirmed(const IPv6Address& neighbour, int interfaceId);
00084 
00085     protected:
00086 
00087         //Packets awaiting Address Resolution or Next-Hop Determination.
00088         cQueue pendingQueue;
00089 
00090         IInterfaceTable *ift;
00091         RoutingTable6 *rt6;
00092         ICMPv6 *icmpv6;
00093         IPv6NeighbourCache neighbourCache;
00094         typedef std::set<cMessage*> RATimerList;
00095 
00096         // stores information about a pending Duplicate Address Detection for
00097         // an interface
00098         struct DADEntry {
00099             int interfaceId;// interface on which DAD is performed
00100             IPv6Address address;// link-local address subject to DAD
00101             int numNSSent;// number of DAD solicitations sent since start of sim
00102             cMessage *timeoutMsg;// the message to cancel when NA is received
00103         };
00104         typedef std::set<DADEntry*> DADList; //FIXME why ptrs are stored?
00105 
00106         //stores information about Router Discovery for an interface
00107         struct RDEntry {
00108             int interfaceId; //interface on which Router Discovery is performed
00109             int numRSSent; //number of Router Solicitations sent since start of sim
00110             cMessage *timeoutMsg; //the message to cancel when RA is received
00111         };
00112         typedef std::set<RDEntry*> RDList; //FIXME why ptrs are stored?
00113 
00114         //An entry that stores information for an Advertising Interface
00115         struct AdvIfEntry {
00116             int interfaceId;
00117             int numRASent;//number of Router Advertisements sent since start of sim
00118             simtime_t nextScheduledRATime;//stores time when next RA will be sent.
00119             cMessage *raTimeoutMsg;//the message to cancel when resetting RA timer
00120         };
00121         typedef std::set<AdvIfEntry*> AdvIfList; //FIXME why ptrs are stored?
00122 
00123         //List of periodic RA msgs(used only for router interfaces)
00124         RATimerList raTimerList;
00125         //List of pending Duplicate Address Detections
00126         DADList dadList;
00127         //List of pending Router & Prefix Discoveries
00128         RDList rdList;
00129         //List of Advertising Interfaces
00130         AdvIfList advIfList;
00131 
00132     protected:
00133         /************************Miscellaneous Stuff***************************/
00134         virtual int numInitStages() const {return 4;}
00135         virtual void initialize(int stage);
00136         virtual void handleMessage(cMessage *msg);
00137         virtual void processNDMessage(ICMPv6Message *msg, IPv6ControlInfo *ctrlInfo);
00138         virtual void finish();
00139 
00140         virtual void processIPv6Datagram(IPv6Datagram *datagram);
00141         virtual IPv6NeighbourDiscovery::AdvIfEntry *fetchAdvIfEntry(InterfaceEntry *ie);
00142         virtual IPv6NeighbourDiscovery::RDEntry *fetchRDEntry(InterfaceEntry *ie);
00143         /************************End of Miscellaneous Stuff********************/
00144 
00154         virtual IPv6Address determineNextHop(const IPv6Address& destAddr, int& outIfID);
00155         virtual void initiateNeighbourUnreachabilityDetection(Neighbour *neighbour);
00156         virtual void processNUDTimeout(cMessage *timeoutMsg);
00157         virtual IPv6Address selectDefaultRouter(int& outIfID);
00166         virtual void timeoutPrefixEntry(const IPv6Address& destPrefix, int prefixLength);
00175         virtual void timeoutDefaultRouter(const IPv6Address& addr, int interfaceID);
00184         virtual void initiateAddressResolution(const IPv6Address& dgSrcAddr,
00185             Neighbour *nce);
00190         virtual void processARTimeout(cMessage *arTimeoutMsg);
00195         virtual void dropQueuedPacketsAwaitingAR(Neighbour *nce);
00200         virtual void sendPacketToIPv6Module(cMessage *msg, const IPv6Address& destAddr,
00201             const IPv6Address& srcAddr, int interfaceId);
00202 
00207         virtual void sendQueuedPacketsToIPv6Module(Neighbour *nce);
00208 
00213         virtual void initiateDAD(const IPv6Address& tentativeAddr, InterfaceEntry *ie);
00214 
00220         virtual void processDADTimeout(cMessage *msg);
00221 
00222         /************Address Autoconfiguration Stuff***************************/
00237         virtual void assignLinkLocalAddress(cMessage *timerMsg);
00238 
00239         /************End Of Address Autoconfiguration Stuff********************/
00240 
00241         /************Router Solicitation Stuff*********************************/
00242         virtual IPv6RouterSolicitation *createAndSendRSPacket(InterfaceEntry *ie);
00243         virtual void initiateRouterDiscovery(cMessage *msg);
00253         virtual void cancelRouterDiscovery(InterfaceEntry *ie);
00254         virtual void processRDTimeout(cMessage *msg);
00255         virtual void processRSPacket(IPv6RouterSolicitation *rs, IPv6ControlInfo *rsCtrlInfo);
00256         virtual bool validateRSPacket(IPv6RouterSolicitation *rs, IPv6ControlInfo *rsCtrlInfo);
00257         /************End of Router Solicitation Stuff**************************/
00258 
00259         /************Router Advertisment Stuff*********************************/
00260         virtual IPv6RouterAdvertisement *createAndSendRAPacket(const IPv6Address& destAddr,
00261             InterfaceEntry *ie);
00262         virtual void processRAPacket(IPv6RouterAdvertisement *ra, IPv6ControlInfo *raCtrlInfo);
00263         virtual void processRAForRouterUpdates(IPv6RouterAdvertisement *ra,
00264             IPv6ControlInfo *raCtrlInfo);
00265         //RFC 2461: Section 6.3.4
00266         /*Note: Implementations can choose to process the on-link aspects of the
00267         prefixes separately from the address autoconfiguration aspects of the
00268         prefixes by, e.g., passing a copy of each valid Router Advertisement message
00269         to both an "on-link" and an "addrconf" function. Each function can then
00270         operate independently on the prefixes that have the appropriate flag set.*/
00271         virtual void processRAPrefixInfo(IPv6RouterAdvertisement *ra, InterfaceEntry *ie);
00272         virtual void processRAPrefixInfoForAddrAutoConf(IPv6NDPrefixInformation& prefixInfo,
00273             InterfaceEntry *ie);
00278         virtual void createRATimer(InterfaceEntry *ie);
00285         virtual void resetRATimer(InterfaceEntry *ie);
00286         virtual void sendPeriodicRA(cMessage *msg);
00287         virtual void sendSolicitedRA(cMessage *msg);
00288         virtual bool validateRAPacket(IPv6RouterAdvertisement *ra, IPv6ControlInfo *raCtrlInfo);
00289         /************End of Router Advertisement Stuff*************************/
00290 
00291         /************Neighbour Solicitaton Stuff*******************************/
00292         virtual IPv6NeighbourSolicitation *createAndSendNSPacket(
00293             const IPv6Address& nsTargetAddr, const IPv6Address& dgDestAddr,
00294             const IPv6Address& dgSrcAddr, InterfaceEntry *ie);
00295         virtual void processNSPacket(IPv6NeighbourSolicitation *ns, IPv6ControlInfo *naCtrlInfo);
00296         virtual bool validateNSPacket(IPv6NeighbourSolicitation *ns, IPv6ControlInfo *nsCtrlInfo);
00297         virtual void processNSForTentativeAddress(IPv6NeighbourSolicitation *ns,
00298             IPv6ControlInfo *ctrlInfo);
00299         virtual void processNSForNonTentativeAddress(IPv6NeighbourSolicitation *ns,
00300             IPv6ControlInfo *ctrlInfo, InterfaceEntry *ie);
00301         virtual void processNSWithSpecifiedSrcAddr(IPv6NeighbourSolicitation *ns,
00302             IPv6ControlInfo *ctrlInfo, InterfaceEntry *ie);
00303         /************End Of Neighbour Solicitation Stuff***********************/
00304 
00305         /************Neighbour Advertisment Stuff)*****************************/
00306         virtual void sendSolicitedNA(IPv6NeighbourSolicitation *ns,
00307             IPv6ControlInfo *nsCtrlInfo, InterfaceEntry *ie);
00308         virtual void sendUnsolicitedNA(InterfaceEntry *ie);
00309         virtual void processNAPacket(IPv6NeighbourAdvertisement *na, IPv6ControlInfo *naCtrlInfo);
00310         virtual bool validateNAPacket(IPv6NeighbourAdvertisement *na, IPv6ControlInfo *naCtrlInfo);
00311         virtual void processNAForIncompleteNCEState(IPv6NeighbourAdvertisement *na,
00312             IPv6NeighbourCache::Neighbour *nce);
00313         virtual void processNAForOtherNCEStates(IPv6NeighbourAdvertisement *na,
00314             IPv6NeighbourCache::Neighbour *nce);
00315         /************End Of Neighbour Advertisement Stuff**********************/
00316 
00317         /************Redirect Message Stuff************************************/
00318         virtual IPv6Redirect *createAndSendRedirectPacket(InterfaceEntry *ie);
00319         virtual void processRedirectPacket(IPv6Redirect *redirect, IPv6ControlInfo *ctrlInfo);
00320         /************End Of Redirect Message Stuff*****************************/
00321 
00327         /*ICMPv6DestUnreachableMsg *createAndSendUnreachableMessage(
00328             const IPv6Address& destAddress, InterfaceEntry *ie);*/
00329 };
00330 #endif //IPV6NEIGHBOURDISCOVERY_H