|
INET Framework for OMNeT++/OMNEST
|
00001 00019 #ifndef NEIGHBORCACHE_H 00020 #define NEIGHBORCACHE_H 00021 00022 #include <map> 00023 #include <vector> 00024 #include <omnetpp.h> 00025 #include "IPv6Address.h" 00026 #include "MACAddress.h" 00027 00028 00042 class INET_API IPv6NeighbourCache 00043 { 00044 public: 00045 typedef std::vector<cMessage*> MsgPtrVector; // TODO verify this is really needed --Andras 00046 00048 enum ReachabilityState {INCOMPLETE, REACHABLE, STALE, DELAY, PROBE}; 00049 00055 struct Key 00056 { 00057 IPv6Address address; 00058 int interfaceID; 00059 Key(IPv6Address addr, int ifaceID) {address=addr; interfaceID=ifaceID;} 00060 bool operator<(const Key& b) const { 00061 return interfaceID==b.interfaceID ? address<b.address : interfaceID<b.interfaceID; 00062 } 00063 }; 00064 00066 struct Neighbour 00067 { 00068 // Neighbour info 00069 const Key *nceKey;//store a pointer back to the key that links to this NCE.-WEI 00070 MACAddress macAddress; 00071 bool isRouter; 00072 bool isDefaultRouter; // is it on the Default Router List? 00073 00074 // Neighbour Unreachability Detection variables 00075 ReachabilityState reachabilityState; 00076 simtime_t reachabilityExpires; // reachabilityLastConfirmed+reachableTime 00077 short numProbesSent; 00078 cMessage *nudTimeoutEvent; // DELAY or PROBE timer 00079 00080 //WEI-We could have a seperate AREntry in the ND module. 00081 //But we should merge those information in the neighbour cache for a 00082 //cleaner solution. if reachability state is INCOMPLETE, it means that 00083 //addr resolution is being performed for this NCE. 00084 int numOfARNSSent; 00085 cMessage *arTimer;//Address Resolution self-message timer 00086 MsgPtrVector pendingPackets; //ptrs to queued packets associated with this NCE 00087 IPv6Address nsSrcAddr;//the src addr that was used to send the previous NS 00088 00089 // Router variables. 00090 // NOTE: we only store lifetime expiry. Other Router Advertisement 00091 // fields (reachableTime, retransTimer, MTU) update the interface 00092 // configuration (IPv6InterfaceData). We won't have a timer message 00093 // for router lifetime; instead, we'll check the expirytime every time 00094 // we bump into a router entry (as nexthop in dest cache, or during 00095 // default router selection 00096 simtime_t routerExpiryTime; // time when router lifetime expires 00097 }; 00098 00099 // Design note: we could have polymorphic entries in the neighbour cache 00100 // (i.e. a separate Router class subclassed from Neighbour), but then 00101 // we'd have to store in the map pointers to dynamically allocated 00102 // Neighbour structs, instead of the data directly. As long as expiryTime 00103 // is the only router-specific field, polymorphic entries don't pay off 00104 // because of the overhead caused by 'new'. 00105 00107 typedef std::map<Key,Neighbour> NeighbourMap; 00108 typedef NeighbourMap::iterator iterator; 00109 00110 protected: 00111 NeighbourMap neighbourMap; 00112 00113 public: 00114 IPv6NeighbourCache(); 00115 virtual ~IPv6NeighbourCache() {} 00116 00118 virtual Neighbour *lookup(const IPv6Address& addr, int interfaceID); 00119 00121 virtual const Key *lookupKeyAddr(Key& key); 00122 00124 iterator begin() {return neighbourMap.begin();} 00125 00127 iterator end() {return neighbourMap.end();} 00128 00130 //TODO merge into next one (using default arg) 00131 virtual Neighbour *addNeighbour(const IPv6Address& addr, int interfaceID); 00132 00134 virtual Neighbour *addNeighbour(const IPv6Address& addr, int interfaceID, 00135 MACAddress macAddress); 00136 00138 //TODO merge into next one (using default arg) 00139 virtual Neighbour *addRouter(const IPv6Address& addr, int interfaceID, 00140 simtime_t expiryTime); 00141 00143 virtual Neighbour *addRouter(const IPv6Address& addr, int interfaceID, 00144 MACAddress macAddress, simtime_t expiryTime); 00145 00147 virtual void remove(const IPv6Address& addr, int interfaceID); 00148 00150 virtual void remove(NeighbourMap::iterator it); 00151 00153 static const char *stateName(ReachabilityState state); 00154 }; 00155 00156 #endif