|
INET Framework for OMNeT++/OMNEST
|
00001 #ifndef __INET_OSPFINTERFACE_H 00002 #define __INET_OSPFINTERFACE_H 00003 00004 #include "INETDefs.h" 00005 #include "AnsaOSPFcommon.h" 00006 #include "OSPFTimer_m.h" 00007 #include "AnsaOSPFNeighbor.h" 00008 #include <map> 00009 #include <vector> 00010 #include <list> 00011 00012 namespace AnsaOSPF { 00013 00014 class InterfaceState; 00015 class Area; 00016 00017 class Interface { 00018 public: 00019 enum InterfaceEventType { 00020 InterfaceUp = 0, 00021 HelloTimer = 1, 00022 WaitTimer = 2, 00023 AcknowledgementTimer = 3, 00024 BackupSeen = 4, 00025 NeighborChange = 5, 00026 LoopIndication = 6, 00027 UnloopIndication = 7, 00028 InterfaceDown = 8 00029 }; 00030 00031 enum OSPFInterfaceType { 00032 UnknownType = 0, 00033 PointToPoint = 1, 00034 Broadcast = 2, 00035 NBMA = 3, 00036 PointToMultiPoint = 4, 00037 Virtual = 5 00038 }; 00039 00040 enum InterfaceStateType { 00041 DownState = 0, 00042 LoopbackState = 1, 00043 WaitingState = 2, 00044 PointToPointState = 3, 00045 NotDesignatedRouterState = 4, 00046 BackupState = 5, 00047 DesignatedRouterState = 6 00048 }; 00049 00050 private: 00051 OSPFInterfaceType interfaceType; 00052 InterfaceState* state; 00053 InterfaceState* previousState; 00054 unsigned char ifIndex; 00055 unsigned short mtu; 00056 IPv4AddressRange interfaceAddressRange; 00057 AreaID areaID; 00058 AreaID transitAreaID; 00059 short helloInterval; 00060 short pollInterval; 00061 short routerDeadInterval; 00062 short interfaceTransmissionDelay; 00063 unsigned char routerPriority; 00064 OSPFTimer* helloTimer; 00065 OSPFTimer* waitTimer; 00066 OSPFTimer* acknowledgementTimer; 00067 std::map<RouterID, Neighbor*> neighboringRoutersByID; 00068 std::map<IPv4Address, Neighbor*, IPv4Address_Less> neighboringRoutersByAddress; 00069 std::vector<Neighbor*> neighboringRouters; 00070 std::map<IPv4Address, std::list<OSPFLSAHeader>, IPv4Address_Less> delayedAcknowledgements; 00071 DesignatedRouterID designatedRouter; 00072 DesignatedRouterID backupDesignatedRouter; 00073 Metric interfaceOutputCost; 00074 short retransmissionInterval; 00075 short acknowledgementDelay; 00076 AuthenticationType authenticationType; 00077 AuthenticationKeyType authenticationKey; 00078 00079 Area* parentArea; 00080 00081 bool isGoingDown; 00082 private: 00083 friend class InterfaceState; 00084 void ChangeState(InterfaceState* newState, InterfaceState* currentState); 00085 00086 public: 00087 Interface(OSPFInterfaceType ifType = UnknownType); 00088 virtual ~Interface(void); 00089 00090 void ProcessEvent (InterfaceEventType event); 00091 void Reset (void); 00092 void SendHelloPacket (IPv4Address destination, short ttl = 1); 00093 void SendLSAcknowledgement (OSPFLSAHeader* lsaHeader, IPv4Address destination); 00094 Neighbor* GetNeighborByID (RouterID neighborID); 00095 Neighbor* GetNeighborByAddress (IPv4Address address); 00096 void AddNeighbor (Neighbor* neighbor); 00097 InterfaceStateType GetState (void) const; 00098 static const char* GetStateString (InterfaceStateType stateType); 00099 bool HasAnyNeighborInStates (int states) const; 00100 void RemoveFromAllRetransmissionLists (LSAKeyType lsaKey); 00101 bool IsOnAnyRetransmissionList (LSAKeyType lsaKey) const; 00102 bool FloodLSA (OSPFLSA* lsa, Interface* intf = NULL, Neighbor* neighbor = NULL); 00103 void AddDelayedAcknowledgement (OSPFLSAHeader& lsaHeader); 00104 void SendDelayedAcknowledgements (void); 00105 void AgeTransmittedLSALists (void); 00106 00107 OSPFLinkStateUpdatePacket* CreateUpdatePacket (OSPFLSA* lsa); 00108 00109 void SetType (OSPFInterfaceType ifType) { interfaceType = ifType; } 00110 OSPFInterfaceType GetType (void) const { return interfaceType; } 00111 void SetIfIndex (unsigned char index); 00112 unsigned char GetIfIndex (void) const { return ifIndex; } 00113 void SetMTU (unsigned short ifMTU) { mtu = ifMTU; } 00114 unsigned short GetMTU (void) const { return mtu; } 00115 void SetAreaID (AreaID areaId) { areaID = areaId; } 00116 AreaID GetAreaID (void) const { return areaID; } 00117 void SetTransitAreaID (AreaID areaId) { transitAreaID = areaId; } 00118 AreaID GetTransitAreaID (void) const { return transitAreaID; } 00119 void SetOutputCost (Metric cost) { interfaceOutputCost = cost; } 00120 Metric GetOutputCost (void) const { return interfaceOutputCost; } 00121 void SetRetransmissionInterval (short interval) { retransmissionInterval = interval; } 00122 short GetRetransmissionInterval (void) const { return retransmissionInterval; } 00123 void SetTransmissionDelay (short delay) { interfaceTransmissionDelay = delay; } 00124 short GetTransmissionDelay (void) const { return interfaceTransmissionDelay; } 00125 void SetAcknowledgementDelay (short delay) { acknowledgementDelay = delay; } 00126 short GetAcknowledgementDelay (void) const { return acknowledgementDelay; } 00127 void SetRouterPriority (unsigned char priority) { routerPriority = priority; } 00128 unsigned char GetRouterPriority (void) const { return routerPriority; } 00129 void SetHelloInterval (short interval) { helloInterval = interval; } 00130 short GetHelloInterval (void) const { return helloInterval; } 00131 void SetPollInterval (short interval) { pollInterval = interval; } 00132 short GetPollInterval (void) const { return pollInterval; } 00133 void SetRouterDeadInterval (short interval) { routerDeadInterval = interval; } 00134 short GetRouterDeadInterval (void) const { return routerDeadInterval; } 00135 void SetAuthenticationType (AuthenticationType type) { authenticationType = type; } 00136 AuthenticationType GetAuthenticationType (void) const { return authenticationType; } 00137 void SetAuthenticationKey (AuthenticationKeyType key) { authenticationKey = key; } 00138 AuthenticationKeyType GetAuthenticationKey (void) const { return authenticationKey; } 00139 void SetAddressRange (IPv4AddressRange range) { interfaceAddressRange = range; } 00140 IPv4AddressRange GetAddressRange (void) const { return interfaceAddressRange; } 00141 00142 OSPFTimer* GetHelloTimer (void) { return helloTimer; } 00143 OSPFTimer* GetWaitTimer (void) { return waitTimer; } 00144 OSPFTimer* GetAcknowledgementTimer (void) { return acknowledgementTimer; } 00145 DesignatedRouterID GetDesignatedRouter (void) const { return designatedRouter; } 00146 DesignatedRouterID GetBackupDesignatedRouter (void) const { return backupDesignatedRouter; } 00147 unsigned long GetNeighborCount (void) const { return neighboringRouters.size(); } 00148 Neighbor* GetNeighbor (unsigned long i) { return neighboringRouters[i]; } 00149 const Neighbor* GetNeighbor (unsigned long i) const { return neighboringRouters[i]; } 00150 00151 void SetArea (Area* area) { parentArea = area; } 00152 Area* GetArea (void) { return parentArea; } 00153 const Area* GetArea (void) const { return parentArea; } 00154 00155 bool IsGoingDown (void) { return isGoingDown; } 00156 void SetIsGoingDown (bool b) { isGoingDown = b; } 00157 }; 00158 00159 } // namespace AnsaOSPF 00160 00161 #endif // __INET_OSPFINTERFACE_H 00162