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