OSPFInterface.h

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