|
INET Framework for OMNeT++/OMNEST
|
00001 // 00002 // This program is free software: you can redistribute it and/or modify 00003 // it under the terms of the GNU Lesser General Public License as published by 00004 // the Free Software Foundation, either version 3 of the License, or 00005 // (at your option) any later version. 00006 // 00007 // This program is distributed in the hope that it will be useful, 00008 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00009 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00010 // GNU Lesser General Public License for more details. 00011 // 00012 // You should have received a copy of the GNU Lesser General Public License 00013 // along with this program. If not, see http://www.gnu.org/licenses/. 00014 // 00015 00016 #ifndef ANSAOSPFNEIGHBOR6_H_ 00017 #define ANSAOSPFNEIGHBOR6_H_ 00018 00019 #include "ansaLsa6.h" 00020 #include "ansaOspfCommon6.h" 00021 #include "ansaOspfPacket6_m.h" 00022 #include "ansaOspfTimer6_m.h" 00023 00024 namespace AnsaOspf6 { 00025 00026 class NeighborState; 00027 class Interface; 00028 00029 class Neighbor { 00030 00031 friend class NeighborState; 00032 00033 public: 00034 enum NeighborEventType { 00035 HelloReceived = 0, 00036 Start = 1, 00037 TwoWayReceived = 2, 00038 NegotiationDone = 3, 00039 ExchangeDone = 4, 00040 BadLinkStateRequest = 5, 00041 LoadingDone = 6, 00042 IsAdjacencyOK = 7, 00043 SequenceNumberMismatch = 8, 00044 OneWayReceived = 9, 00045 KillNeighbor = 10, 00046 InactivityTimer = 11, 00047 PollTimer = 12, 00048 LinkDown = 13, 00049 DDRetransmissionTimer = 14, 00050 UpdateRetransmissionTimer = 15, 00051 RequestRetransmissionTimer = 16 00052 }; 00053 00054 enum NeighborStateType { 00055 DownState = 0, 00056 AttemptState = 1, 00057 InitState = 2, 00058 TwoWayState = 4, 00059 ExchangeStartState = 8, 00060 ExchangeState = 16, 00061 LoadingState = 32, 00062 FullState = 64 00063 }; 00064 00065 enum DatabaseExchangeRelationshipType { 00066 Master = 0, 00067 Slave = 1 00068 }; 00069 00070 struct DDPacketID { 00071 OspfDdOptions6 ddOptions; 00072 OspfOptions6 options; 00073 unsigned long sequenceNumber; 00074 }; 00075 00076 private: 00077 struct TransmittedLSA { 00078 LsaKeyType6 lsaKey; 00079 unsigned short age; 00080 }; 00081 private: 00082 NeighborState* state; 00083 NeighborState* previousState; 00084 OspfTimer6* inactivityTimer; 00085 OspfTimer6* pollTimer; 00086 OspfTimer6* ddRetransmissionTimer; 00087 OspfTimer6* updateRetransmissionTimer; 00088 bool updateRetransmissionTimerActive; 00089 OspfTimer6* requestRetransmissionTimer; 00090 bool requestRetransmissionTimerActive; 00091 DatabaseExchangeRelationshipType databaseExchangeRelationship; 00092 bool firstAdjacencyInited; 00093 unsigned long ddSequenceNumber; 00094 DDPacketID lastReceivedDDPacket; 00095 RouterID neighborID; 00096 unsigned char neighborPriority; 00097 IPv6Address neighborIPAddress; 00098 OspfOptions6 neighborOptions; 00099 DesignatedRouterID neighborsDesignatedRouter; 00100 DesignatedRouterID neighborsBackupDesignatedRouter; 00101 bool designatedRoutersSetUp; 00102 short neighborsRouterDeadInterval; 00103 std::list<OspfLsa6*> linkStateRetransmissionList; 00104 std::list<OspfLsaHeader6*> databaseSummaryList; 00105 std::list<OspfLsaHeader6*> linkStateRequestList; 00106 std::list<TransmittedLSA> transmittedLSAs; 00107 OspfDatabaseDescriptionPacket6* lastTransmittedDDPacket; 00108 00109 Interface* parentInterface; 00110 00111 // FIXME!!! Should come from a global unique number generator module. 00112 static unsigned long ddSequenceNumberInitSeed; 00113 00114 private: 00115 void ChangeState(NeighborState* newState, NeighborState* currentState); 00116 00117 public: 00118 Neighbor(RouterID neighbor = NullRouterID); 00119 virtual ~Neighbor(void); 00120 00121 void ProcessEvent (NeighborEventType event); 00122 void Reset (void); 00123 void InitFirstAdjacency (void); 00124 NeighborStateType GetState (void) const; 00125 static const char* GetStateString (NeighborStateType stateType); 00126 void SendDatabaseDescriptionPacket (bool init = false); 00127 bool RetransmitDatabaseDescriptionPacket (void); 00128 void CreateDatabaseSummary (void); 00129 void SendLinkStateRequestPacket (void); 00130 void RetransmitUpdatePacket (void); 00131 bool NeedAdjacency (void); 00132 void AddToRetransmissionList (OspfLsa6* lsa); 00133 void RemoveFromRetransmissionList (LsaKeyType6 lsaKey); 00134 bool IsLSAOnRetransmissionList (LsaKeyType6 lsaKey) const; 00135 OspfLsa6* FindOnRetransmissionList (LsaKeyType6 lsaKey); 00136 void StartUpdateRetransmissionTimer (void); 00137 void ClearUpdateRetransmissionTimer (void); 00138 void AddToRequestList (OspfLsaHeader6* lsaHeader); 00139 void RemoveFromRequestList (LsaKeyType6 lsaKey); 00140 bool IsLSAOnRequestList (LsaKeyType6 lsaKey) const; 00141 OspfLsaHeader6* FindOnRequestList (LsaKeyType6 lsaKey); 00142 void StartRequestRetransmissionTimer (void); 00143 void ClearRequestRetransmissionTimer (void); 00144 void AddToTransmittedLSAList (LsaKeyType6 lsaKey); 00145 bool IsOnTransmittedLSAList (LsaKeyType6 lsaKey) const; 00146 void AgeTransmittedLSAList (void); 00147 unsigned long GetUniqueULong (void); 00148 void DeleteLastSentDDPacket (void); 00149 00150 void SetNeighborID (RouterID id) { neighborID = id; } 00151 RouterID GetNeighborID (void) const { return neighborID; } 00152 void SetPriority (unsigned char priority) { neighborPriority = priority; } 00153 unsigned char GetPriority (void) const { return neighborPriority; } 00154 void SetAddress (IPv6Address address) { neighborIPAddress = address; } 00155 IPv6Address GetAddress (void) const { return neighborIPAddress; } 00156 void SetDesignatedRouter (DesignatedRouterID routerID) { neighborsDesignatedRouter = routerID; } 00157 DesignatedRouterID GetDesignatedRouter (void) const { return neighborsDesignatedRouter; } 00158 void SetBackupDesignatedRouter (DesignatedRouterID routerID) { neighborsBackupDesignatedRouter = routerID; } 00159 DesignatedRouterID GetBackupDesignatedRouter (void) const { return neighborsBackupDesignatedRouter; } 00160 void SetRouterDeadInterval (short interval) { neighborsRouterDeadInterval = interval; } 00161 short GetRouterDeadInterval (void) const { return neighborsRouterDeadInterval; } 00162 void SetDDSequenceNumber (unsigned long sequenceNumber) { ddSequenceNumber = sequenceNumber; } 00163 unsigned long GetDDSequenceNumber (void) const { return ddSequenceNumber; } 00164 void SetOptions (OspfOptions6 options) { neighborOptions = options; } 00165 OspfOptions6 GetOptions (void) const { return neighborOptions; } 00166 void SetLastReceivedDDPacket (DDPacketID packetID) { lastReceivedDDPacket = packetID; } 00167 DDPacketID GetLastReceivedDDPacket (void) const { return lastReceivedDDPacket; } 00168 00169 void SetDatabaseExchangeRelationship(DatabaseExchangeRelationshipType relation) { databaseExchangeRelationship = relation; } 00170 DatabaseExchangeRelationshipType GetDatabaseExchangeRelationship(void) const { return databaseExchangeRelationship; } 00171 00172 void SetInterface (Interface* intf) { parentInterface = intf; } 00173 Interface* GetInterface (void) { return parentInterface; } 00174 const Interface* GetInterface (void) const { return parentInterface; } 00175 00176 OspfTimer6* GetInactivityTimer (void) { return inactivityTimer; } 00177 OspfTimer6* GetPollTimer (void) { return pollTimer; } 00178 OspfTimer6* GetDDRetransmissionTimer (void) { return ddRetransmissionTimer; } 00179 OspfTimer6* GetUpdateRetransmissionTimer (void) { return updateRetransmissionTimer; } 00180 bool IsUpdateRetransmissionTimerActive (void) const { return updateRetransmissionTimerActive; } 00181 bool IsRequestRetransmissionTimerActive (void) const { return requestRetransmissionTimerActive; } 00182 bool IsFirstAdjacencyInited (void) const { return firstAdjacencyInited; } 00183 bool DesignatedRoutersAreSetUp (void) const { return designatedRoutersSetUp; } 00184 void SetUpDesignatedRouters (bool setUp) { designatedRoutersSetUp = setUp; } 00185 unsigned long GetDatabaseSummaryListCount (void) const { return databaseSummaryList.size(); } 00186 00187 void IncrementDDSequenceNumber (void) { ddSequenceNumber++; } 00188 bool IsLinkStateRequestListEmpty (void) const { return linkStateRequestList.empty(); } 00189 bool IsLinkStateRetransmissionListEmpty (void) const { return linkStateRetransmissionList.empty(); } 00190 void PopFirstLinkStateRequest (void) { linkStateRequestList.pop_front(); } 00191 }; 00192 00193 } 00194 00195 inline bool operator== (AnsaOspf6::Neighbor::DDPacketID leftID, AnsaOspf6::Neighbor::DDPacketID rightID) 00196 { 00197 return ((leftID.ddOptions.I_Init == rightID.ddOptions.I_Init) && 00198 (leftID.ddOptions.M_More == rightID.ddOptions.M_More) && 00199 (leftID.ddOptions.MS_MasterSlave == rightID.ddOptions.MS_MasterSlave) && 00200 (leftID.options == rightID.options) && 00201 (leftID.sequenceNumber == rightID.sequenceNumber)); 00202 } 00203 00204 inline bool operator!= (AnsaOspf6::Neighbor::DDPacketID leftID, AnsaOspf6::Neighbor::DDPacketID rightID) 00205 { 00206 return (!(leftID == rightID)); 00207 } 00208 00209 #endif /* ANSAOSPFNEIGHBOR_H6_ */