|
INET Framework for OMNeT++/OMNEST
|
00001 #ifndef __INET_OSPFNEIGHBOR_H 00002 #define __INET_OSPFNEIGHBOR_H 00003 00004 #include "OSPFPacket_m.h" 00005 #include "OSPFTimer_m.h" 00006 #include "AnsaOSPFcommon.h" 00007 #include "AnsaLSA.h" 00008 #include <list> 00009 00010 namespace AnsaOSPF { 00011 00012 class NeighborState; 00013 class Interface; 00014 00015 class Neighbor { 00016 00017 friend class NeighborState; 00018 00019 public: 00020 enum NeighborEventType { 00021 HelloReceived = 0, 00022 Start = 1, 00023 TwoWayReceived = 2, 00024 NegotiationDone = 3, 00025 ExchangeDone = 4, 00026 BadLinkStateRequest = 5, 00027 LoadingDone = 6, 00028 IsAdjacencyOK = 7, 00029 SequenceNumberMismatch = 8, 00030 OneWayReceived = 9, 00031 KillNeighbor = 10, 00032 InactivityTimer = 11, 00033 PollTimer = 12, 00034 LinkDown = 13, 00035 DDRetransmissionTimer = 14, 00036 UpdateRetransmissionTimer = 15, 00037 RequestRetransmissionTimer = 16 00038 }; 00039 00040 enum NeighborStateType { 00041 DownState = 0, 00042 AttemptState = 1, 00043 InitState = 2, 00044 TwoWayState = 4, 00045 ExchangeStartState = 8, 00046 ExchangeState = 16, 00047 LoadingState = 32, 00048 FullState = 64 00049 }; 00050 00051 enum DatabaseExchangeRelationshipType { 00052 Master = 0, 00053 Slave = 1 00054 }; 00055 00056 struct DDPacketID { 00057 OSPFDDOptions ddOptions; 00058 OSPFOptions options; 00059 unsigned long sequenceNumber; 00060 }; 00061 00062 private: 00063 struct TransmittedLSA { 00064 LSAKeyType lsaKey; 00065 unsigned short age; 00066 }; 00067 00068 private: 00069 NeighborState* state; 00070 NeighborState* previousState; 00071 OSPFTimer* inactivityTimer; 00072 OSPFTimer* pollTimer; 00073 OSPFTimer* ddRetransmissionTimer; 00074 OSPFTimer* updateRetransmissionTimer; 00075 bool updateRetransmissionTimerActive; 00076 OSPFTimer* requestRetransmissionTimer; 00077 bool requestRetransmissionTimerActive; 00078 DatabaseExchangeRelationshipType databaseExchangeRelationship; 00079 bool firstAdjacencyInited; 00080 unsigned long ddSequenceNumber; 00081 DDPacketID lastReceivedDDPacket; 00082 RouterID neighborID; 00083 unsigned char neighborPriority; 00084 IPv4Address neighborIPAddress; 00085 OSPFOptions neighborOptions; 00086 DesignatedRouterID neighborsDesignatedRouter; 00087 DesignatedRouterID neighborsBackupDesignatedRouter; 00088 bool designatedRoutersSetUp; 00089 short neighborsRouterDeadInterval; 00090 std::list<OSPFLSA*> linkStateRetransmissionList; 00091 std::list<OSPFLSAHeader*> databaseSummaryList; 00092 std::list<OSPFLSAHeader*> linkStateRequestList; 00093 std::list<TransmittedLSA> transmittedLSAs; 00094 OSPFDatabaseDescriptionPacket* lastTransmittedDDPacket; 00095 00096 Interface* parentInterface; 00097 00098 // FIXME!!! Should come from a global unique number generator module. 00099 static unsigned long ddSequenceNumberInitSeed; 00100 00101 private: 00102 void ChangeState(NeighborState* newState, NeighborState* currentState); 00103 00104 public: 00105 Neighbor(RouterID neighbor = NullRouterID); 00106 virtual ~Neighbor(void); 00107 00108 void ProcessEvent (NeighborEventType event); 00109 void Reset (void); 00110 void InitFirstAdjacency (void); 00111 NeighborStateType GetState (void) const; 00112 static const char* GetStateString (NeighborStateType stateType); 00113 void SendDatabaseDescriptionPacket (bool init = false); 00114 bool RetransmitDatabaseDescriptionPacket(void); 00115 void CreateDatabaseSummary (void); 00116 void SendLinkStateRequestPacket (void); 00117 void RetransmitUpdatePacket (void); 00118 bool NeedAdjacency (void); 00119 void AddToRetransmissionList (OSPFLSA* lsa); 00120 void RemoveFromRetransmissionList (LSAKeyType lsaKey); 00121 bool IsLSAOnRetransmissionList (LSAKeyType lsaKey) const; 00122 OSPFLSA* FindOnRetransmissionList (LSAKeyType lsaKey); 00123 void StartUpdateRetransmissionTimer (void); 00124 void ClearUpdateRetransmissionTimer (void); 00125 void AddToRequestList (OSPFLSAHeader* lsaHeader); 00126 void RemoveFromRequestList (LSAKeyType lsaKey); 00127 bool IsLSAOnRequestList (LSAKeyType lsaKey) const; 00128 OSPFLSAHeader* FindOnRequestList (LSAKeyType lsaKey); 00129 void StartRequestRetransmissionTimer (void); 00130 void ClearRequestRetransmissionTimer (void); 00131 void AddToTransmittedLSAList (LSAKeyType lsaKey); 00132 bool IsOnTransmittedLSAList (LSAKeyType lsaKey) const; 00133 void AgeTransmittedLSAList (void); 00134 unsigned long GetUniqueULong (void); 00135 void DeleteLastSentDDPacket (void); 00136 00137 void SetNeighborID (RouterID id) { neighborID = id; } 00138 RouterID GetNeighborID (void) const { return neighborID; } 00139 void SetPriority (unsigned char priority) { neighborPriority = priority; } 00140 unsigned char GetPriority (void) const { return neighborPriority; } 00141 void SetAddress (IPv4Address address) { neighborIPAddress = address; } 00142 IPv4Address GetAddress (void) const { return neighborIPAddress; } 00143 void SetDesignatedRouter (DesignatedRouterID routerID) { neighborsDesignatedRouter = routerID; } 00144 DesignatedRouterID GetDesignatedRouter (void) const { return neighborsDesignatedRouter; } 00145 void SetBackupDesignatedRouter (DesignatedRouterID routerID) { neighborsBackupDesignatedRouter = routerID; } 00146 DesignatedRouterID GetBackupDesignatedRouter (void) const { return neighborsBackupDesignatedRouter; } 00147 void SetRouterDeadInterval (short interval) { neighborsRouterDeadInterval = interval; } 00148 short GetRouterDeadInterval (void) const { return neighborsRouterDeadInterval; } 00149 void SetDDSequenceNumber (unsigned long sequenceNumber) { ddSequenceNumber = sequenceNumber; } 00150 unsigned long GetDDSequenceNumber (void) const { return ddSequenceNumber; } 00151 void SetOptions (OSPFOptions options) { neighborOptions = options; } 00152 OSPFOptions GetOptions (void) const { return neighborOptions; } 00153 void SetLastReceivedDDPacket (DDPacketID packetID) { lastReceivedDDPacket = packetID; } 00154 DDPacketID GetLastReceivedDDPacket (void) const { return lastReceivedDDPacket; } 00155 00156 void SetDatabaseExchangeRelationship(DatabaseExchangeRelationshipType relation) { databaseExchangeRelationship = relation; } 00157 DatabaseExchangeRelationshipType GetDatabaseExchangeRelationship(void) const { return databaseExchangeRelationship; } 00158 00159 void SetInterface (Interface* intf) { parentInterface = intf; } 00160 Interface* GetInterface (void) { return parentInterface; } 00161 const Interface* GetInterface (void) const { return parentInterface; } 00162 00163 OSPFTimer* GetInactivityTimer (void) { return inactivityTimer; } 00164 OSPFTimer* GetPollTimer (void) { return pollTimer; } 00165 OSPFTimer* GetDDRetransmissionTimer (void) { return ddRetransmissionTimer; } 00166 OSPFTimer* GetUpdateRetransmissionTimer (void) { return updateRetransmissionTimer; } 00167 bool IsUpdateRetransmissionTimerActive (void) const { return updateRetransmissionTimerActive; } 00168 bool IsRequestRetransmissionTimerActive (void) const { return requestRetransmissionTimerActive; } 00169 bool IsFirstAdjacencyInited (void) const { return firstAdjacencyInited; } 00170 bool DesignatedRoutersAreSetUp (void) const { return designatedRoutersSetUp; } 00171 void SetUpDesignatedRouters (bool setUp) { designatedRoutersSetUp = setUp; } 00172 unsigned long GetDatabaseSummaryListCount (void) const { return databaseSummaryList.size(); } 00173 00174 void IncrementDDSequenceNumber (void) { ddSequenceNumber++; } 00175 bool IsLinkStateRequestListEmpty (void) const { return linkStateRequestList.empty(); } 00176 bool IsLinkStateRetransmissionListEmpty(void) const { return linkStateRetransmissionList.empty(); } 00177 void PopFirstLinkStateRequest (void) { linkStateRequestList.pop_front(); } 00178 }; 00179 00180 } // namespace AnsaOSPF 00181 00182 inline bool operator== (AnsaOSPF::Neighbor::DDPacketID leftID, AnsaOSPF::Neighbor::DDPacketID rightID) 00183 { 00184 return ((leftID.ddOptions.I_Init == rightID.ddOptions.I_Init) && 00185 (leftID.ddOptions.M_More == rightID.ddOptions.M_More) && 00186 (leftID.ddOptions.MS_MasterSlave == rightID.ddOptions.MS_MasterSlave) && 00187 (leftID.options == rightID.options) && 00188 (leftID.sequenceNumber == rightID.sequenceNumber)); 00189 } 00190 00191 inline bool operator!= (AnsaOSPF::Neighbor::DDPacketID leftID, AnsaOSPF::Neighbor::DDPacketID rightID) 00192 { 00193 return (!(leftID == rightID)); 00194 } 00195 00196 #endif // __INET_OSPFNEIGHBOR_H 00197