INET Framework for OMNeT++/OMNEST
ansaOspfInterface6.h
Go to the documentation of this file.
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 ANSAOSPFINTERFACE6_H_
00017 #define ANSAOSPFINTERFACE6_H_
00018 
00019 #include "IPv6Address.h"
00020 
00021 #include "ansaOspfCommon6.h"
00022 #include "ansaOspfNeighbor6.h"
00023 #include "ansaOspfTimer6_m.h"
00024 #include "ansaOspfPacket6_m.h"
00025 
00026 
00027 namespace AnsaOspf6 {
00028 
00029 class InterfaceState;
00030 class Area;
00031 
00032 class Interface {
00033 public:
00034    enum InterfaceEventType {
00035       InterfaceUp          = 0,
00036       HelloTimer           = 1,
00037       WaitTimer            = 2,
00038       AcknowledgementTimer = 3,
00039       BackupSeen           = 4,
00040       NeighborChange       = 5,
00041       LoopIndication       = 6,
00042       UnloopIndication     = 7,
00043       InterfaceDown        = 8
00044    };
00045 
00046    enum OspfInterfaceType {
00047       UnknownType       = 0,
00048       PointToPoint      = 1,
00049       Broadcast         = 2,
00050       NBMA              = 3,
00051       PointToMultiPoint = 4,
00052       Virtual           = 5
00053    };
00054 
00055    enum InterfaceStateType {
00056       DownState                = 0,
00057       LoopbackState            = 1,
00058       WaitingState             = 2,
00059       PointToPointState        = 3,
00060       NotDesignatedRouterState = 4,
00061       BackupState              = 5,
00062       DesignatedRouterState    = 6
00063    };
00064 
00065 private:
00066    OspfInterfaceType                                                   interfaceType;
00067    InterfaceState*                                                     state;
00068    InterfaceState*                                                     previousState;
00069    IfaceID                                                             ifIndex;
00070    std::string                                                         ifName;
00071    InstanceID                                                          instanceID;
00072    unsigned short                                                      mtu;
00073    IPv6Address                                                         interfaceAddress;
00074    std::map<IPv6AddressPrefix, bool, IPv6AddressPrefix_Less>           advertiseAddressPrefixes;
00075    std::vector<IPv6AddressPrefix>                                      interfaceAddressPrefixes;
00076    std::map<LinkStateID, LinkLsa*>                                     linkLSAsByID;
00077    std::vector<LinkLsa*>                                               linkLSAs;
00078    AreaID                                                              areaID;
00079    AreaID                                                              transitAreaID;
00080    short                                                               helloInterval;
00081    short                                                               pollInterval;
00082    short                                                               routerDeadInterval;
00083    short                                                               interfaceTransmissionDelay;
00084    unsigned char                                                       routerPriority;
00085    OspfTimer6*                                                         helloTimer;
00086    OspfTimer6*                                                         waitTimer;
00087    OspfTimer6*                                                         acknowledgementTimer;
00088    std::map<RouterID, Neighbor*>                                       neighboringRoutersByID;
00089    std::map<IPv6Address, Neighbor*, IPv6Address_Less>                  neighboringRoutersByAddress;
00090    std::vector<Neighbor*>                                              neighboringRouters;
00091    std::map<IPv6Address, std::list<OspfLsaHeader6>, IPv6Address_Less>  delayedAcknowledgements;
00092    DesignatedRouterID                                                  designatedRouter;
00093    DesignatedRouterID                                                  backupDesignatedRouter;
00094    Metric                                                              interfaceOutputCost;
00095    short                                                               retransmissionInterval;
00096    short                                                               acknowledgementDelay;
00097 
00098    Area*                                                               parentArea;
00099 
00100    bool                                                                isGoingDown;
00101 
00102 private:
00103    friend class InterfaceState;
00104    void ChangeState(InterfaceState* newState, InterfaceState* currentState);
00105 
00106 public:
00107    Interface(OspfInterfaceType ifType = UnknownType);
00108    virtual ~Interface(void);
00109 
00110    void                ProcessEvent                        (InterfaceEventType event);
00111    void                Reset                               (void);
00112    void                SendHelloPacket                     (IPv6Address destination, short ttl = 1);
00113    void                SendLSAcknowledgement               (OspfLsaHeader6* lsaHeader, IPv6Address destination);
00114    Neighbor*           GetNeighborByID                     (RouterID neighborID);
00115    Neighbor*           GetNeighborByAddress                (IPv6Address address);
00116    void                AddNeighbor                         (Neighbor* neighbor);
00117    InterfaceStateType  GetState                            (void) const;
00118    static const char*  GetStateString                      (InterfaceStateType stateType);
00119    static const char*  GetTypeString                       (OspfInterfaceType type);
00120    bool                HasAnyNeighborInStates              (int states) const;
00121    void                RemoveFromAllRetransmissionLists    (LsaKeyType6 lsaKey);
00122    bool                IsOnAnyRetransmissionList           (LsaKeyType6 lsaKey) const;
00123    bool                FloodLSA                            (OspfLsa6* lsa, Interface* intf = NULL, Neighbor* neighbor = NULL);
00124    void                AddDelayedAcknowledgement           (OspfLsaHeader6& lsaHeader);
00125    void                SendDelayedAcknowledgements         (void);
00126    void                AgeTransmittedLSALists              (void);
00127 
00128    OspfLinkStateUpdatePacket6*  CreateUpdatePacket          (OspfLsa6* lsa);
00129 
00130    void                    SetType                         (OspfInterfaceType ifType)  { interfaceType = ifType; }
00131    OspfInterfaceType       GetType                         (void) const                { return interfaceType; }
00132    void                    SetIfIndex                      (IfaceID id);
00133    unsigned char           GetIfIndex                      (void) const                { return ifIndex; }
00134    void                    SetIfName                       (const char *name)          { ifName = name; };
00135    const char *            GetIfName                       (void) const                { return ifName.c_str(); }
00136    void                    SetInstanceID                   (InstanceID id)             { instanceID = id; }
00137    InstanceID              GetInstanceID                   (void) const                { return instanceID; }
00138    void                    SetMtu                          (unsigned short ifMTU)      { mtu = ifMTU; }
00139    unsigned short          GetMtu                          (void) const                { return mtu; }
00140    void                    SetAreaID                       (AreaID id)                 { areaID = id; }
00141    AreaID                  GetAreaID                       (void) const                { return areaID; }
00142    void                    SetTransitAreaID                (AreaID id)                 { transitAreaID = id; }
00143    AreaID                  GetTransitAreaID                (void) const                { return transitAreaID; }
00144    void                    SetOutputCost                   (Metric cost)               { interfaceOutputCost = cost; }
00145    Metric                  GetOutputCost                   (void) const                { return interfaceOutputCost; }
00146    void                    SetRetransmissionInterval       (short interval)            { retransmissionInterval = interval; }
00147    short                   GetRetransmissionInterval       (void) const                { return retransmissionInterval; }
00148    void                    SetTransmissionDelay            (short delay)               { interfaceTransmissionDelay = delay; }
00149    short                   GetTransmissionDelay            (void) const                { return interfaceTransmissionDelay; }
00150    void                    SetAcknowledgementDelay         (short delay)               { acknowledgementDelay = delay; }
00151    short                   GetAcknowledgementDelay         (void) const                { return acknowledgementDelay; }
00152    void                    SetRouterPriority               (unsigned char priority)    { routerPriority = priority; }
00153    unsigned char           GetRouterPriority               (void) const                { return routerPriority; }
00154    void                    SetHelloInterval                (short interval)            { helloInterval = interval; }
00155    short                   GetHelloInterval                (void) const                { return helloInterval; }
00156    void                    SetPollInterval                 (short interval)            { pollInterval = interval; }
00157    short                   GetPollInterval                 (void) const                { return pollInterval; }
00158    void                    SetRouterDeadInterval           (short interval)            { routerDeadInterval = interval; }
00159    short                   GetRouterDeadInterval           (void) const                { return routerDeadInterval; }
00160 
00161    void                    SetInterfaceAddress             (IPv6Address addr)          { interfaceAddress = addr; }
00162    IPv6Address             GetInterfaceAddress             (void) const                { return interfaceAddress; }
00163    void                    AddAddressPrefix                (IPv6AddressPrefix prefix, bool advertise)      { interfaceAddressPrefixes.push_back(prefix); advertiseAddressPrefixes[prefix] = advertise; }
00164    unsigned int            GetAddressPrefixCount           (void) const                                    { return interfaceAddressPrefixes.size(); }
00165    IPv6AddressPrefix       GetAddressPrefix                (unsigned int index) const                      { return interfaceAddressPrefixes[index]; }
00166    unsigned long           GetLinkLSACount                 (void) const               { return linkLSAs.size(); }
00167    LinkLsa*                GetLinkLSA                      (unsigned long i)          { return linkLSAs[i]; }
00168    const LinkLsa*          GetLinkLSA                      (unsigned long i) const    { return linkLSAs[i]; }
00169 
00170    OspfTimer6*             GetHelloTimer                   (void)                      { return helloTimer; }
00171    OspfTimer6*             GetWaitTimer                    (void)                      { return waitTimer; }
00172    OspfTimer6*             GetAcknowledgementTimer         (void)                      { return acknowledgementTimer; }
00173    DesignatedRouterID      GetDesignatedRouter             (void) const                { return designatedRouter; }
00174    DesignatedRouterID      GetBackupDesignatedRouter       (void) const                { return backupDesignatedRouter; }
00175    unsigned long           GetNeighborCount                (void) const                { return neighboringRouters.size(); }
00176    Neighbor*               GetNeighbor                     (unsigned long i)           { return neighboringRouters[i]; }
00177    const Neighbor*         GetNeighbor                     (unsigned long i) const     { return neighboringRouters[i]; }
00178 
00179    void                    SetArea                         (Area* area)                { parentArea = area; }
00180    Area*                   GetArea                         (void)                      { return parentArea; }
00181    const Area*             GetArea                         (void) const                { return parentArea; }
00182 
00183    bool                    IsGoingDown                     (void)                      { return isGoingDown; }
00184    void                    SetIsGoingDown                  (bool b)                    { isGoingDown = b; }
00185 };
00186 
00187 }
00188 
00189 #endif /* ANSAOSPFINTERFACE6_H_ */