Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Friends

OSPF::Interface Class Reference

#include <OSPFInterface.h>

List of all members.

Public Types

enum  InterfaceEventType {
  InterfaceUp = 0, HelloTimer = 1, WaitTimer = 2, AcknowledgementTimer = 3,
  BackupSeen = 4, NeighborChange = 5, LoopIndication = 6, UnloopIndication = 7,
  InterfaceDown = 8
}
enum  OSPFInterfaceType {
  UnknownType = 0, PointToPoint = 1, Broadcast = 2, NBMA = 3,
  PointToMultiPoint = 4, Virtual = 5
}
enum  InterfaceStateType {
  DownState = 0, LoopbackState = 1, WaitingState = 2, PointToPointState = 3,
  NotDesignatedRouterState = 4, BackupState = 5, DesignatedRouterState = 6
}

Public Member Functions

 Interface (OSPFInterfaceType ifType=UnknownType)
virtual ~Interface (void)
void ProcessEvent (InterfaceEventType event)
void Reset (void)
void SendHelloPacket (IPv4Address destination, short ttl=1)
void SendLSAcknowledgement (OSPFLSAHeader *lsaHeader, IPv4Address destination)
NeighborGetNeighborByID (RouterID neighborID)
NeighborGetNeighborByAddress (IPv4Address address)
void AddNeighbor (Neighbor *neighbor)
InterfaceStateType GetState (void) const
bool HasAnyNeighborInStates (int states) const
void RemoveFromAllRetransmissionLists (LSAKeyType lsaKey)
bool IsOnAnyRetransmissionList (LSAKeyType lsaKey) const
bool FloodLSA (OSPFLSA *lsa, Interface *intf=NULL, Neighbor *neighbor=NULL)
void AddDelayedAcknowledgement (OSPFLSAHeader &lsaHeader)
void SendDelayedAcknowledgements (void)
void AgeTransmittedLSALists (void)
OSPFLinkStateUpdatePacket * CreateUpdatePacket (OSPFLSA *lsa)
void SetType (OSPFInterfaceType ifType)
OSPFInterfaceType GetType (void) const
void SetIfIndex (unsigned char index)
unsigned char GetIfIndex (void) const
void SetMTU (unsigned short ifMTU)
unsigned short GetMTU (void) const
void SetAreaID (AreaID areaId)
AreaID GetAreaID (void) const
void SetTransitAreaID (AreaID areaId)
AreaID GetTransitAreaID (void) const
void SetOutputCost (Metric cost)
Metric GetOutputCost (void) const
void SetRetransmissionInterval (short interval)
short GetRetransmissionInterval (void) const
void SetTransmissionDelay (short delay)
short GetTransmissionDelay (void) const
void SetAcknowledgementDelay (short delay)
short GetAcknowledgementDelay (void) const
void SetRouterPriority (unsigned char priority)
unsigned char GetRouterPriority (void) const
void SetHelloInterval (short interval)
short GetHelloInterval (void) const
void SetPollInterval (short interval)
short GetPollInterval (void) const
void SetRouterDeadInterval (short interval)
short GetRouterDeadInterval (void) const
void SetAuthenticationType (AuthenticationType type)
AuthenticationType GetAuthenticationType (void) const
void SetAuthenticationKey (AuthenticationKeyType key)
AuthenticationKeyType GetAuthenticationKey (void) const
void SetAddressRange (IPv4AddressRange range)
IPv4AddressRange GetAddressRange (void) const
OSPFTimer * GetHelloTimer (void)
OSPFTimer * GetWaitTimer (void)
OSPFTimer * GetAcknowledgementTimer (void)
DesignatedRouterID GetDesignatedRouter (void) const
DesignatedRouterID GetBackupDesignatedRouter (void) const
unsigned long GetNeighborCount (void) const
NeighborGetNeighbor (unsigned long i)
const NeighborGetNeighbor (unsigned long i) const
void SetArea (Area *area)
AreaGetArea (void)
const AreaGetArea (void) const

Static Public Member Functions

static const char * GetStateString (InterfaceStateType stateType)

Private Member Functions

void ChangeState (InterfaceState *newState, InterfaceState *currentState)

Private Attributes

OSPFInterfaceType interfaceType
InterfaceStatestate
InterfaceStatepreviousState
unsigned char ifIndex
unsigned short mtu
IPv4AddressRange interfaceAddressRange
AreaID areaID
AreaID transitAreaID
short helloInterval
short pollInterval
short routerDeadInterval
short interfaceTransmissionDelay
unsigned char routerPriority
OSPFTimer * helloTimer
OSPFTimer * waitTimer
OSPFTimer * acknowledgementTimer
std::map< RouterID, Neighbor * > neighboringRoutersByID
std::map< IPv4Address,
Neighbor *, IPv4Address_Less
neighboringRoutersByAddress
std::vector< Neighbor * > neighboringRouters
std::map< IPv4Address,
std::list< OSPFLSAHeader >
, IPv4Address_Less
delayedAcknowledgements
DesignatedRouterID designatedRouter
DesignatedRouterID backupDesignatedRouter
Metric interfaceOutputCost
short retransmissionInterval
short acknowledgementDelay
AuthenticationType authenticationType
AuthenticationKeyType authenticationKey
AreaparentArea

Friends

class InterfaceState

Detailed Description

Definition at line 34 of file OSPFInterface.h.


Member Enumeration Documentation

Enumerator:
InterfaceUp 
HelloTimer 
WaitTimer 
AcknowledgementTimer 
BackupSeen 
NeighborChange 
LoopIndication 
UnloopIndication 
InterfaceDown 

Definition at line 36 of file OSPFInterface.h.

Enumerator:
DownState 
LoopbackState 
WaitingState 
PointToPointState 
NotDesignatedRouterState 
BackupState 
DesignatedRouterState 

Definition at line 57 of file OSPFInterface.h.

Enumerator:
UnknownType 
PointToPoint 
Broadcast 
NBMA 
PointToMultiPoint 
Virtual 

Definition at line 48 of file OSPFInterface.h.

                           {
        UnknownType       = 0,
        PointToPoint      = 1,
        Broadcast         = 2,
        NBMA              = 3,
        PointToMultiPoint = 4,
        Virtual           = 5
    };


Constructor & Destructor Documentation

OSPF::Interface::Interface ( OSPFInterfaceType  ifType = UnknownType  ) 

Definition at line 28 of file OSPFInterface.cc.

                                                              :
    interfaceType(ifType),
    ifIndex(0),
    mtu(0),
    interfaceAddressRange(OSPF::NullIPv4AddressRange),
    areaID(OSPF::BackboneAreaID),
    transitAreaID(OSPF::BackboneAreaID),
    helloInterval(10),
    pollInterval(120),
    routerDeadInterval(40),
    interfaceTransmissionDelay(1),
    routerPriority(0),
    designatedRouter(OSPF::NullDesignatedRouterID),
    backupDesignatedRouter(OSPF::NullDesignatedRouterID),
    interfaceOutputCost(1),
    retransmissionInterval(5),
    acknowledgementDelay(1),
    authenticationType(OSPF::NullType),
    parentArea(NULL)
{
    state = new OSPF::InterfaceStateDown;
    previousState = NULL;
    helloTimer = new OSPFTimer;
    helloTimer->setTimerKind(InterfaceHelloTimer);
    helloTimer->setContextPointer(this);
    helloTimer->setName("OSPF::Interface::InterfaceHelloTimer");
    waitTimer = new OSPFTimer;
    waitTimer->setTimerKind(InterfaceWaitTimer);
    waitTimer->setContextPointer(this);
    waitTimer->setName("OSPF::Interface::InterfaceWaitTimer");
    acknowledgementTimer = new OSPFTimer;
    acknowledgementTimer->setTimerKind(InterfaceAcknowledgementTimer);
    acknowledgementTimer->setContextPointer(this);
    acknowledgementTimer->setName("OSPF::Interface::InterfaceAcknowledgementTimer");
    memset(authenticationKey.bytes, 0, 8 * sizeof(char));
}

OSPF::Interface::~Interface ( void   )  [virtual]

Definition at line 65 of file OSPFInterface.cc.

{
    MessageHandler* messageHandler = parentArea->GetRouter()->GetMessageHandler();
    messageHandler->ClearTimer(helloTimer);
    delete helloTimer;
    messageHandler->ClearTimer(waitTimer);
    delete waitTimer;
    messageHandler->ClearTimer(acknowledgementTimer);
    delete acknowledgementTimer;
    if (previousState != NULL) {
        delete previousState;
    }
    delete state;
    long neighborCount = neighboringRouters.size();
    for (long i = 0; i < neighborCount; i++) {
        delete neighboringRouters[i];
    }
}


Member Function Documentation

void OSPF::Interface::AddDelayedAcknowledgement ( OSPFLSAHeader &  lsaHeader  ) 

Definition at line 495 of file OSPFInterface.cc.

Referenced by OSPF::LinkStateUpdateHandler::AcknowledgeLSA().

{
    if (interfaceType == OSPF::Interface::Broadcast) {
        if ((GetState() == OSPF::Interface::DesignatedRouterState) ||
            (GetState() == OSPF::Interface::BackupState) ||
            (designatedRouter == OSPF::NullDesignatedRouterID))
        {
            delayedAcknowledgements[OSPF::AllSPFRouters].push_back(lsaHeader);
        } else {
            delayedAcknowledgements[OSPF::AllDRouters].push_back(lsaHeader);
        }
    } else {
        long neighborCount = neighboringRouters.size();
        for (long i = 0; i < neighborCount; i++) {
            if (neighboringRouters[i]->GetState() >= OSPF::Neighbor::ExchangeState) {
                delayedAcknowledgements[neighboringRouters[i]->GetAddress()].push_back(lsaHeader);
            }
        }
    }
}

void OSPF::Interface::AddNeighbor ( OSPF::Neighbor neighbor  ) 

Definition at line 216 of file OSPFInterface.cc.

Referenced by OSPFRouting::LoadInterfaceParameters(), OSPFRouting::LoadVirtualLink(), and OSPF::HelloHandler::ProcessPacket().

{
    neighboringRoutersByID[neighbor->GetNeighborID()] = neighbor;
    neighboringRoutersByAddress[neighbor->GetAddress()] = neighbor;
    neighbor->SetInterface(this);
    neighboringRouters.push_back(neighbor);
}

void OSPF::Interface::AgeTransmittedLSALists ( void   ) 

Definition at line 574 of file OSPFInterface.cc.

{
    long neighborCount = neighboringRouters.size();
    for (long i = 0; i < neighborCount; i++) {
        neighboringRouters[i]->AgeTransmittedLSAList();
    }
}

void OSPF::Interface::ChangeState ( OSPF::InterfaceState newState,
OSPF::InterfaceState currentState 
) [private]

Definition at line 95 of file OSPFInterface.cc.

Referenced by OSPF::InterfaceState::ChangeState().

{
    if (previousState != NULL) {
        delete previousState;
    }
    state = newState;
    previousState = currentState;
}

OSPFLinkStateUpdatePacket * OSPF::Interface::CreateUpdatePacket ( OSPFLSA *  lsa  ) 

Definition at line 408 of file OSPFInterface.cc.

Referenced by FloodLSA(), OSPF::LinkStateUpdateHandler::ProcessPacket(), and OSPF::LinkStateRequestHandler::ProcessPacket().

{
    LSAType lsaType                  = static_cast<LSAType> (lsa->getHeader().getLsType());
    OSPFRouterLSA* routerLSA         = (lsaType == RouterLSAType) ? dynamic_cast<OSPFRouterLSA*> (lsa) : NULL;
    OSPFNetworkLSA* networkLSA       = (lsaType == NetworkLSAType) ? dynamic_cast<OSPFNetworkLSA*> (lsa) : NULL;
    OSPFSummaryLSA* summaryLSA       = ((lsaType == SummaryLSA_NetworksType) ||
                                        (lsaType == SummaryLSA_ASBoundaryRoutersType)) ? dynamic_cast<OSPFSummaryLSA*> (lsa) : NULL;
    OSPFASExternalLSA* asExternalLSA = (lsaType == ASExternalLSAType) ? dynamic_cast<OSPFASExternalLSA*> (lsa) : NULL;

    if (((lsaType == RouterLSAType) && (routerLSA != NULL)) ||
        ((lsaType == NetworkLSAType) && (networkLSA != NULL)) ||
        (((lsaType == SummaryLSA_NetworksType) || (lsaType == SummaryLSA_ASBoundaryRoutersType)) && (summaryLSA != NULL)) ||
        ((lsaType == ASExternalLSAType) && (asExternalLSA != NULL)))
    {
        OSPFLinkStateUpdatePacket* updatePacket = new OSPFLinkStateUpdatePacket;

        updatePacket->setType(LinkStateUpdatePacket);
        updatePacket->setRouterID(parentArea->GetRouter()->GetRouterID());
        updatePacket->setAreaID(areaID);
        updatePacket->setAuthenticationType(authenticationType);
        for (int j = 0; j < 8; j++) {
            updatePacket->setAuthentication(j, authenticationKey.bytes[j]);
        }

        updatePacket->setNumberOfLSAs(1);

        switch (lsaType) {
            case RouterLSAType:
                {
                    updatePacket->setRouterLSAsArraySize(1);
                    updatePacket->setRouterLSAs(0, *routerLSA);
                    unsigned short lsAge = updatePacket->getRouterLSAs(0).getHeader().getLsAge();
                    if (lsAge < MAX_AGE - interfaceTransmissionDelay) {
                        updatePacket->getRouterLSAs(0).getHeader().setLsAge(lsAge + interfaceTransmissionDelay);
                    } else {
                        updatePacket->getRouterLSAs(0).getHeader().setLsAge(MAX_AGE);
                    }
                }
                break;
            case NetworkLSAType:
                {
                    updatePacket->setNetworkLSAsArraySize(1);
                    updatePacket->setNetworkLSAs(0, *networkLSA);
                    unsigned short lsAge = updatePacket->getNetworkLSAs(0).getHeader().getLsAge();
                    if (lsAge < MAX_AGE - interfaceTransmissionDelay) {
                        updatePacket->getNetworkLSAs(0).getHeader().setLsAge(lsAge + interfaceTransmissionDelay);
                    } else {
                        updatePacket->getNetworkLSAs(0).getHeader().setLsAge(MAX_AGE);
                    }
                }
                break;
            case SummaryLSA_NetworksType:
            case SummaryLSA_ASBoundaryRoutersType:
                {
                    updatePacket->setSummaryLSAsArraySize(1);
                    updatePacket->setSummaryLSAs(0, *summaryLSA);
                    unsigned short lsAge = updatePacket->getSummaryLSAs(0).getHeader().getLsAge();
                    if (lsAge < MAX_AGE - interfaceTransmissionDelay) {
                        updatePacket->getSummaryLSAs(0).getHeader().setLsAge(lsAge + interfaceTransmissionDelay);
                    } else {
                        updatePacket->getSummaryLSAs(0).getHeader().setLsAge(MAX_AGE);
                    }
                }
                break;
            case ASExternalLSAType:
                {
                    updatePacket->setAsExternalLSAsArraySize(1);
                    updatePacket->setAsExternalLSAs(0, *asExternalLSA);
                    unsigned short lsAge = updatePacket->getAsExternalLSAs(0).getHeader().getLsAge();
                    if (lsAge < MAX_AGE - interfaceTransmissionDelay) {
                        updatePacket->getAsExternalLSAs(0).getHeader().setLsAge(lsAge + interfaceTransmissionDelay);
                    } else {
                        updatePacket->getAsExternalLSAs(0).getHeader().setLsAge(MAX_AGE);
                    }
                }
                break;
            default: break;
        }

        updatePacket->setPacketLength(0); // TODO: Calculate correct length
        updatePacket->setChecksum(0); // TODO: Calculate correct cheksum(16-bit one's complement of the entire packet)

        return updatePacket;
    }
    return NULL;
}

bool OSPF::Interface::FloodLSA ( OSPFLSA *  lsa,
OSPF::Interface intf = NULL,
OSPF::Neighbor neighbor = NULL 
)
See also:
RFC2328 Section 13.3.

Definition at line 278 of file OSPFInterface.cc.

{
    bool floodedBackOut = false;

    if (
        (
         (lsa->getHeader().getLsType() == ASExternalLSAType) &&
         (interfaceType != OSPF::Interface::Virtual) &&
         (parentArea->GetExternalRoutingCapability())
        ) ||
        (
         (lsa->getHeader().getLsType() != ASExternalLSAType) &&
         (
          (
           (areaID != OSPF::BackboneAreaID) &&
           (interfaceType != OSPF::Interface::Virtual)
          ) ||
          (areaID == OSPF::BackboneAreaID)
         )
        )
       )
    {
        long              neighborCount                = neighboringRouters.size();
        bool              lsaAddedToRetransmissionList = false;
        OSPF::LinkStateID linkStateID                  = lsa->getHeader().getLinkStateID();
        OSPF::LSAKeyType  lsaKey;

        lsaKey.linkStateID = linkStateID;
        lsaKey.advertisingRouter = lsa->getHeader().getAdvertisingRouter().getInt();

        for (long i = 0; i < neighborCount; i++) {  // (1)
            if (neighboringRouters[i]->GetState() < OSPF::Neighbor::ExchangeState) {   // (1) (a)
                continue;
            }
            if (neighboringRouters[i]->GetState() < OSPF::Neighbor::FullState) {   // (1) (b)
                OSPFLSAHeader* requestLSAHeader = neighboringRouters[i]->FindOnRequestList(lsaKey);
                if (requestLSAHeader != NULL) {
                    // operator< and operator== on OSPFLSAHeaders determines which one is newer(less means older)
                    if (lsa->getHeader() < (*requestLSAHeader)) {
                        continue;
                    }
                    if (operator== (lsa->getHeader(), (*requestLSAHeader))) {
                        neighboringRouters[i]->RemoveFromRequestList(lsaKey);
                        continue;
                    }
                    neighboringRouters[i]->RemoveFromRequestList(lsaKey);
                }
            }
            if (neighbor == neighboringRouters[i]) {     // (1) (c)
                continue;
            }
            neighboringRouters[i]->AddToRetransmissionList(lsa);   // (1) (d)
            lsaAddedToRetransmissionList = true;
        }
        if (lsaAddedToRetransmissionList) {     // (2)
            if ((intf != this) ||
                ((neighbor != NULL) &&
                 (neighbor->GetNeighborID() != designatedRouter.routerID) &&
                 (neighbor->GetNeighborID() != backupDesignatedRouter.routerID)))  // (3)
            {
                if ((intf != this) || (GetState() != OSPF::Interface::BackupState)) {  // (4)
                    OSPFLinkStateUpdatePacket* updatePacket = CreateUpdatePacket(lsa);    // (5)

                    if (updatePacket != NULL) {
                        int                   ttl            = (interfaceType == OSPF::Interface::Virtual) ? VIRTUAL_LINK_TTL : 1;
                        OSPF::MessageHandler* messageHandler = parentArea->GetRouter()->GetMessageHandler();

                        if (interfaceType == OSPF::Interface::Broadcast) {
                            if ((GetState() == OSPF::Interface::DesignatedRouterState) ||
                                (GetState() == OSPF::Interface::BackupState) ||
                                (designatedRouter == OSPF::NullDesignatedRouterID))
                            {
                                messageHandler->SendPacket(updatePacket, OSPF::AllSPFRouters, ifIndex, ttl);
                                for (long k = 0; k < neighborCount; k++) {
                                    neighboringRouters[k]->AddToTransmittedLSAList(lsaKey);
                                    if (!neighboringRouters[k]->IsUpdateRetransmissionTimerActive()) {
                                        neighboringRouters[k]->StartUpdateRetransmissionTimer();
                                    }
                                }
                            } else {
                                messageHandler->SendPacket(updatePacket, OSPF::AllDRouters, ifIndex, ttl);
                                OSPF::Neighbor* dRouter = GetNeighborByID(designatedRouter.routerID);
                                OSPF::Neighbor* backupDRouter = GetNeighborByID(backupDesignatedRouter.routerID);
                                if (dRouter != NULL) {
                                    dRouter->AddToTransmittedLSAList(lsaKey);
                                    if (!dRouter->IsUpdateRetransmissionTimerActive()) {
                                        dRouter->StartUpdateRetransmissionTimer();
                                    }
                                }
                                if (backupDRouter != NULL) {
                                    backupDRouter->AddToTransmittedLSAList(lsaKey);
                                    if (!backupDRouter->IsUpdateRetransmissionTimerActive()) {
                                        backupDRouter->StartUpdateRetransmissionTimer();
                                    }
                                }
                            }
                        } else {
                            if (interfaceType == OSPF::Interface::PointToPoint) {
                                messageHandler->SendPacket(updatePacket, OSPF::AllSPFRouters, ifIndex, ttl);
                                if (neighborCount > 0) {
                                    neighboringRouters[0]->AddToTransmittedLSAList(lsaKey);
                                    if (!neighboringRouters[0]->IsUpdateRetransmissionTimerActive()) {
                                        neighboringRouters[0]->StartUpdateRetransmissionTimer();
                                    }
                                }
                            } else {
                                for (long m = 0; m < neighborCount; m++) {
                                    if (neighboringRouters[m]->GetState() >= OSPF::Neighbor::ExchangeState) {
                                        messageHandler->SendPacket(updatePacket, neighboringRouters[m]->GetAddress(), ifIndex, ttl);
                                        neighboringRouters[m]->AddToTransmittedLSAList(lsaKey);
                                        if (!neighboringRouters[m]->IsUpdateRetransmissionTimerActive()) {
                                            neighboringRouters[m]->StartUpdateRetransmissionTimer();
                                        }
                                    }
                                }
                            }
                        }

                        if (intf == this) {
                            floodedBackOut = true;
                        }
                    }
                }
            }
        }
    }

    return floodedBackOut;
}

short OSPF::Interface::GetAcknowledgementDelay ( void   )  const [inline]

Definition at line 141 of file OSPFInterface.h.

Referenced by OSPF::InterfaceStateDown::ProcessEvent().

OSPFTimer* OSPF::Interface::GetAcknowledgementTimer ( void   )  [inline]

Definition at line 159 of file OSPFInterface.h.

Referenced by OSPF::InterfaceStateDown::ProcessEvent().

IPv4AddressRange OSPF::Interface::GetAddressRange ( void   )  const [inline]
Area* OSPF::Interface::GetArea ( void   )  [inline]

Definition at line 167 of file OSPFInterface.h.

Referenced by OSPF::LinkStateUpdateHandler::AcknowledgeLSA(), OSPF::NeighborState::ChangeState(), OSPF::InterfaceState::ChangeState(), OSPF::Neighbor::ClearRequestRetransmissionTimer(), OSPF::Neighbor::ClearUpdateRetransmissionTimer(), OSPF::Neighbor::CreateDatabaseSummary(), OSPF::Neighbor::NeedAdjacency(), OSPF::DatabaseDescriptionHandler::ProcessDDPacket(), OSPF::NeighborStateTwoWay::ProcessEvent(), OSPF::NeighborStateLoading::ProcessEvent(), OSPF::NeighborStateInit::ProcessEvent(), OSPF::NeighborStateFull::ProcessEvent(), OSPF::NeighborStateExchangeStart::ProcessEvent(), OSPF::NeighborStateExchange::ProcessEvent(), OSPF::NeighborStateDown::ProcessEvent(), OSPF::NeighborStateAttempt::ProcessEvent(), OSPF::InterfaceStateWaiting::ProcessEvent(), OSPF::InterfaceStatePointToPoint::ProcessEvent(), OSPF::InterfaceStateNotDesignatedRouter::ProcessEvent(), OSPF::InterfaceStateDown::ProcessEvent(), OSPF::InterfaceStateDesignatedRouter::ProcessEvent(), OSPF::InterfaceStateBackup::ProcessEvent(), OSPF::LinkStateRequestHandler::ProcessPacket(), OSPF::HelloHandler::ProcessPacket(), OSPF::Neighbor::Reset(), OSPF::Neighbor::RetransmitDatabaseDescriptionPacket(), OSPF::Neighbor::RetransmitUpdatePacket(), OSPF::Neighbor::SendDatabaseDescriptionPacket(), OSPF::Neighbor::SendLinkStateRequestPacket(), OSPF::Neighbor::StartRequestRetransmissionTimer(), OSPF::Neighbor::StartUpdateRetransmissionTimer(), and OSPF::Neighbor::~Neighbor().

{ return parentArea; }

const Area* OSPF::Interface::GetArea ( void   )  const [inline]

Definition at line 168 of file OSPFInterface.h.

{ return parentArea; }

AreaID OSPF::Interface::GetAreaID ( void   )  const [inline]

Definition at line 131 of file OSPFInterface.h.

Referenced by OSPFRouting::LoadVirtualLink().

{ return areaID; }

AuthenticationKeyType OSPF::Interface::GetAuthenticationKey ( void   )  const [inline]
AuthenticationType OSPF::Interface::GetAuthenticationType ( void   )  const [inline]
DesignatedRouterID OSPF::Interface::GetBackupDesignatedRouter ( void   )  const [inline]
DesignatedRouterID OSPF::Interface::GetDesignatedRouter ( void   )  const [inline]
short OSPF::Interface::GetHelloInterval ( void   )  const [inline]
OSPFTimer* OSPF::Interface::GetHelloTimer ( void   )  [inline]
unsigned char OSPF::Interface::GetIfIndex ( void   )  const [inline]
unsigned short OSPF::Interface::GetMTU ( void   )  const [inline]
Neighbor* OSPF::Interface::GetNeighbor ( unsigned long  i  )  [inline]
const Neighbor* OSPF::Interface::GetNeighbor ( unsigned long  i  )  const [inline]

Definition at line 164 of file OSPFInterface.h.

{ return neighboringRouters[i]; }

OSPF::Neighbor * OSPF::Interface::GetNeighborByAddress ( OSPF::IPv4Address  address  ) 

Definition at line 205 of file OSPFInterface.cc.

Referenced by OSPF::Area::OriginateRouterLSA(), OSPF::MessageHandler::ProcessPacket(), and OSPF::HelloHandler::ProcessPacket().

{
    std::map<OSPF::IPv4Address, OSPF::Neighbor*, OSPF::IPv4Address_Less>::iterator neighborIt = neighboringRoutersByAddress.find(address);
    if (neighborIt != neighboringRoutersByAddress.end()) {
        return (neighborIt->second);
    }
    else {
        return NULL;
    }
}

OSPF::Neighbor * OSPF::Interface::GetNeighborByID ( OSPF::RouterID  neighborID  ) 

Definition at line 194 of file OSPFInterface.cc.

Referenced by OSPF::LinkStateUpdateHandler::AcknowledgeLSA(), FloodLSA(), OSPF::MessageHandler::ProcessPacket(), and OSPF::HelloHandler::ProcessPacket().

{
    std::map<OSPF::RouterID, OSPF::Neighbor*>::iterator neighborIt = neighboringRoutersByID.find(neighborID);
    if (neighborIt != neighboringRoutersByID.end()) {
        return (neighborIt->second);
    }
    else {
        return NULL;
    }
}

unsigned long OSPF::Interface::GetNeighborCount ( void   )  const [inline]
Metric OSPF::Interface::GetOutputCost ( void   )  const [inline]

Definition at line 135 of file OSPFInterface.h.

Referenced by OSPF::Area::OriginateRouterLSA().

{ return interfaceOutputCost; }

short OSPF::Interface::GetPollInterval ( void   )  const [inline]
short OSPF::Interface::GetRetransmissionInterval ( void   )  const [inline]
short OSPF::Interface::GetRouterDeadInterval ( void   )  const [inline]
unsigned char OSPF::Interface::GetRouterPriority ( void   )  const [inline]
OSPF::Interface::InterfaceStateType OSPF::Interface::GetState ( void   )  const
const char * OSPF::Interface::GetStateString ( InterfaceStateType  stateType  )  [static]

Definition at line 229 of file OSPFInterface.cc.

Referenced by OSPF::MessageHandler::PrintEvent().

{
    switch (stateType) {
        case DownState:                 return "Down";
        case LoopbackState:             return "Loopback";
        case WaitingState:              return "Waiting";
        case PointToPointState:         return "PointToPoint";
        case NotDesignatedRouterState:  return "NotDesignatedRouter";
        case BackupState:               return "Backup";
        case DesignatedRouterState:     return "DesignatedRouter";
        default:                        ASSERT(false);
    }
    return "";
}

AreaID OSPF::Interface::GetTransitAreaID ( void   )  const [inline]

Definition at line 133 of file OSPFInterface.h.

Referenced by OSPF::MessageHandler::ProcessPacket().

{ return transitAreaID; }

short OSPF::Interface::GetTransmissionDelay ( void   )  const [inline]

Definition at line 139 of file OSPFInterface.h.

Referenced by OSPF::Neighbor::RetransmitUpdatePacket().

OSPFInterfaceType OSPF::Interface::GetType ( void   )  const [inline]
OSPFTimer* OSPF::Interface::GetWaitTimer ( void   )  [inline]

Definition at line 158 of file OSPFInterface.h.

Referenced by OSPF::InterfaceStateDown::ProcessEvent().

{ return waitTimer; }

bool OSPF::Interface::HasAnyNeighborInStates ( int  states  )  const

Definition at line 244 of file OSPFInterface.cc.

Referenced by OSPF::Area::AgeDatabase(), OSPF::Area::OriginateNetworkLSA(), and OSPF::Area::OriginateRouterLSA().

{
    long neighborCount = neighboringRouters.size();
    for (long i = 0; i < neighborCount; i++) {
        OSPF::Neighbor::NeighborStateType neighborState = neighboringRouters[i]->GetState();
        if (neighborState & states) {
            return true;
        }
    }
    return false;
}

bool OSPF::Interface::IsOnAnyRetransmissionList ( OSPF::LSAKeyType  lsaKey  )  const

Definition at line 264 of file OSPFInterface.cc.

{
    long neighborCount = neighboringRouters.size();
    for (long i = 0; i < neighborCount; i++) {
        if (neighboringRouters[i]->IsLSAOnRetransmissionList(lsaKey)) {
            return true;
        }
    }
    return false;
}

void OSPF::Interface::ProcessEvent ( InterfaceEventType  event  ) 

Definition at line 104 of file OSPFInterface.cc.

Referenced by OSPF::MessageHandler::HandleTimer(), OSPFRouting::LoadInterfaceParameters(), and OSPF::HelloHandler::ProcessPacket().

{
    state->ProcessEvent(this, event);
}

void OSPF::Interface::RemoveFromAllRetransmissionLists ( OSPF::LSAKeyType  lsaKey  ) 

Definition at line 256 of file OSPFInterface.cc.

{
    long neighborCount = neighboringRouters.size();
    for (long i = 0; i < neighborCount; i++) {
        neighboringRouters[i]->RemoveFromRetransmissionList(lsaKey);
    }
}

void OSPF::Interface::Reset ( void   ) 
void OSPF::Interface::SendDelayedAcknowledgements ( void   ) 

Definition at line 516 of file OSPFInterface.cc.

Referenced by OSPF::InterfaceStateWaiting::ProcessEvent(), OSPF::InterfaceStatePointToPoint::ProcessEvent(), OSPF::InterfaceStateNotDesignatedRouter::ProcessEvent(), OSPF::InterfaceStateDesignatedRouter::ProcessEvent(), and OSPF::InterfaceStateBackup::ProcessEvent().

{
    OSPF::MessageHandler* messageHandler = parentArea->GetRouter()->GetMessageHandler();
    long                  maxPacketSize  = ((IPV4_HEADER_LENGTH + OSPF_HEADER_LENGTH + OSPF_LSA_HEADER_LENGTH) > mtu) ? IPV4_DATAGRAM_LENGTH : mtu;

    for (std::map<IPv4Address, std::list<OSPFLSAHeader>, OSPF::IPv4Address_Less>::iterator delayIt = delayedAcknowledgements.begin();
         delayIt != delayedAcknowledgements.end();
         delayIt++)
    {
        int ackCount = delayIt->second.size();
        if (ackCount > 0) {
            while (!(delayIt->second.empty())) {
                OSPFLinkStateAcknowledgementPacket* ackPacket  = new OSPFLinkStateAcknowledgementPacket;
                long                                packetSize = IPV4_HEADER_LENGTH + OSPF_HEADER_LENGTH;

                ackPacket->setType(LinkStateAcknowledgementPacket);
                ackPacket->setRouterID(parentArea->GetRouter()->GetRouterID());
                ackPacket->setAreaID(areaID);
                ackPacket->setAuthenticationType(authenticationType);
                for (int i = 0; i < 8; i++) {
                    ackPacket->setAuthentication(i, authenticationKey.bytes[i]);
                }

                while ((!(delayIt->second.empty())) && (packetSize <= (maxPacketSize - OSPF_LSA_HEADER_LENGTH))) {
                    unsigned long   headerCount = ackPacket->getLsaHeadersArraySize();
                    ackPacket->setLsaHeadersArraySize(headerCount + 1);
                    ackPacket->setLsaHeaders(headerCount, *(delayIt->second.begin()));
                    delayIt->second.pop_front();
                    packetSize += OSPF_LSA_HEADER_LENGTH;
                }

                ackPacket->setPacketLength(0); // TODO: Calculate correct length
                ackPacket->setChecksum(0); // TODO: Calculate correct cheksum(16-bit one's complement of the entire packet)

                int ttl = (interfaceType == OSPF::Interface::Virtual) ? VIRTUAL_LINK_TTL : 1;

                if (interfaceType == OSPF::Interface::Broadcast) {
                    if ((GetState() == OSPF::Interface::DesignatedRouterState) ||
                        (GetState() == OSPF::Interface::BackupState) ||
                        (designatedRouter == OSPF::NullDesignatedRouterID))
                    {
                        messageHandler->SendPacket(ackPacket, OSPF::AllSPFRouters, ifIndex, ttl);
                    } else {
                        messageHandler->SendPacket(ackPacket, OSPF::AllDRouters, ifIndex, ttl);
                    }
                } else {
                    if (interfaceType == OSPF::Interface::PointToPoint) {
                        messageHandler->SendPacket(ackPacket, OSPF::AllSPFRouters, ifIndex, ttl);
                    } else {
                        messageHandler->SendPacket(ackPacket, delayIt->first, ifIndex, ttl);
                    }
                }
            }
        }
    }
    messageHandler->StartTimer(acknowledgementTimer, acknowledgementDelay);
}

void OSPF::Interface::SendHelloPacket ( OSPF::IPv4Address  destination,
short  ttl = 1 
)

Definition at line 123 of file OSPFInterface.cc.

Referenced by OSPF::NeighborStateDown::ProcessEvent(), OSPF::InterfaceStateWaiting::ProcessEvent(), OSPF::InterfaceStatePointToPoint::ProcessEvent(), OSPF::InterfaceStateNotDesignatedRouter::ProcessEvent(), OSPF::InterfaceStateDesignatedRouter::ProcessEvent(), OSPF::InterfaceStateBackup::ProcessEvent(), and OSPF::HelloHandler::ProcessPacket().

{
    OSPFOptions options;
    OSPFHelloPacket* helloPacket = new OSPFHelloPacket;
    std::vector<OSPF::IPv4Address> neighbors;

    helloPacket->setRouterID(parentArea->GetRouter()->GetRouterID());
    helloPacket->setAreaID(parentArea->GetAreaID());
    helloPacket->setAuthenticationType(authenticationType);
    for (int i = 0; i < 8; i++) {
        helloPacket->setAuthentication(i, authenticationKey.bytes[i]);
    }

    if (((interfaceType == PointToPoint) &&
         (interfaceAddressRange.address == OSPF::NullIPv4Address)) ||
        (interfaceType == Virtual))
    {
        helloPacket->setNetworkMask(ULongFromIPv4Address(OSPF::NullIPv4Address));
    } else {
        helloPacket->setNetworkMask(ULongFromIPv4Address(interfaceAddressRange.mask));
    }
    memset(&options, 0, sizeof(OSPFOptions));
    options.E_ExternalRoutingCapability = parentArea->GetExternalRoutingCapability();
    helloPacket->setOptions(options);
    helloPacket->setHelloInterval(helloInterval);
    helloPacket->setRouterPriority(routerPriority);
    helloPacket->setRouterDeadInterval(routerDeadInterval);
    helloPacket->setDesignatedRouter(ULongFromIPv4Address(designatedRouter.ipInterfaceAddress));
    helloPacket->setBackupDesignatedRouter(ULongFromIPv4Address(backupDesignatedRouter.ipInterfaceAddress));
    long neighborCount = neighboringRouters.size();
    for (long j = 0; j < neighborCount; j++) {
        if (neighboringRouters[j]->GetState() >= OSPF::Neighbor::InitState) {
            neighbors.push_back(neighboringRouters[j]->GetAddress());
        }
    }
    unsigned int initedNeighborCount = neighbors.size();
    helloPacket->setNeighborArraySize(initedNeighborCount);
    for (unsigned int k = 0; k < initedNeighborCount; k++) {
        helloPacket->setNeighbor(k, ULongFromIPv4Address(neighbors[k]));
    }

    helloPacket->setPacketLength(0); // TODO: Calculate correct length
    helloPacket->setChecksum(0); // TODO: Calculate correct cheksum(16-bit one's complement of the entire packet)

    parentArea->GetRouter()->GetMessageHandler()->SendPacket(helloPacket, destination, ifIndex, ttl);
}

void OSPF::Interface::SendLSAcknowledgement ( OSPFLSAHeader *  lsaHeader,
IPv4Address  destination 
)

Definition at line 170 of file OSPFInterface.cc.

Referenced by OSPF::LinkStateUpdateHandler::ProcessPacket().

{
    OSPFOptions                         options;
    OSPFLinkStateAcknowledgementPacket* lsAckPacket = new OSPFLinkStateAcknowledgementPacket;

    lsAckPacket->setType(LinkStateAcknowledgementPacket);
    lsAckPacket->setRouterID(parentArea->GetRouter()->GetRouterID());
    lsAckPacket->setAreaID(parentArea->GetAreaID());
    lsAckPacket->setAuthenticationType(authenticationType);
    for (int i = 0; i < 8; i++) {
        lsAckPacket->setAuthentication(i, authenticationKey.bytes[i]);
    }

    lsAckPacket->setLsaHeadersArraySize(1);
    lsAckPacket->setLsaHeaders(0, *lsaHeader);

    lsAckPacket->setPacketLength(0); // TODO: Calculate correct length
    lsAckPacket->setChecksum(0); // TODO: Calculate correct cheksum(16-bit one's complement of the entire packet)

    int ttl = (interfaceType == OSPF::Interface::Virtual) ? VIRTUAL_LINK_TTL : 1;
    parentArea->GetRouter()->GetMessageHandler()->SendPacket(lsAckPacket, destination, ifIndex, ttl);
}

void OSPF::Interface::SetAcknowledgementDelay ( short  delay  )  [inline]

Definition at line 140 of file OSPFInterface.h.

{ acknowledgementDelay = delay; }

void OSPF::Interface::SetAddressRange ( IPv4AddressRange  range  )  [inline]

Definition at line 154 of file OSPFInterface.h.

{ interfaceAddressRange = range; }

void OSPF::Interface::SetArea ( Area area  )  [inline]

Definition at line 166 of file OSPFInterface.h.

Referenced by OSPF::Area::AddInterface().

{ parentArea = area; }

void OSPF::Interface::SetAreaID ( AreaID  areaId  )  [inline]

Definition at line 130 of file OSPFInterface.h.

Referenced by OSPFRouting::LoadInterfaceParameters().

{ areaID = areaId; }

void OSPF::Interface::SetAuthenticationKey ( AuthenticationKeyType  key  )  [inline]
void OSPF::Interface::SetAuthenticationType ( AuthenticationType  type  )  [inline]
void OSPF::Interface::SetHelloInterval ( short  interval  )  [inline]

Definition at line 144 of file OSPFInterface.h.

Referenced by OSPFRouting::LoadInterfaceParameters(), and OSPFRouting::LoadVirtualLink().

{ helloInterval = interval; }

void OSPF::Interface::SetIfIndex ( unsigned char  index  ) 

Definition at line 84 of file OSPFInterface.cc.

Referenced by OSPFRouting::LoadInterfaceParameters().

{
    ifIndex = index;
    if (interfaceType == OSPF::Interface::UnknownType) {
        InterfaceEntry* routingInterface = InterfaceTableAccess().get()->getInterfaceById(ifIndex);
        interfaceAddressRange.address = IPv4AddressFromAddressString(routingInterface->ipv4Data()->getIPAddress().str().c_str());
        interfaceAddressRange.mask = IPv4AddressFromAddressString(routingInterface->ipv4Data()->getNetmask().str().c_str());
        mtu = routingInterface->getMTU();
    }
}

void OSPF::Interface::SetMTU ( unsigned short  ifMTU  )  [inline]

Definition at line 128 of file OSPFInterface.h.

{ mtu = ifMTU; }

void OSPF::Interface::SetOutputCost ( Metric  cost  )  [inline]

Definition at line 134 of file OSPFInterface.h.

Referenced by OSPFRouting::LoadInterfaceParameters().

{ interfaceOutputCost = cost; }

void OSPF::Interface::SetPollInterval ( short  interval  )  [inline]

Definition at line 146 of file OSPFInterface.h.

Referenced by OSPFRouting::LoadInterfaceParameters().

{ pollInterval = interval; }

void OSPF::Interface::SetRetransmissionInterval ( short  interval  )  [inline]
void OSPF::Interface::SetRouterDeadInterval ( short  interval  )  [inline]

Definition at line 148 of file OSPFInterface.h.

Referenced by OSPFRouting::LoadInterfaceParameters(), and OSPFRouting::LoadVirtualLink().

{ routerDeadInterval = interval; }

void OSPF::Interface::SetRouterPriority ( unsigned char  priority  )  [inline]

Definition at line 142 of file OSPFInterface.h.

Referenced by OSPFRouting::LoadInterfaceParameters().

{ routerPriority = priority; }

void OSPF::Interface::SetTransitAreaID ( AreaID  areaId  )  [inline]

Definition at line 132 of file OSPFInterface.h.

Referenced by OSPFRouting::LoadVirtualLink().

{ transitAreaID = areaId; }

void OSPF::Interface::SetTransmissionDelay ( short  delay  )  [inline]
void OSPF::Interface::SetType ( OSPFInterfaceType  ifType  )  [inline]

Definition at line 124 of file OSPFInterface.h.

Referenced by OSPFRouting::LoadInterfaceParameters(), and OSPFRouting::LoadVirtualLink().

{ interfaceType = ifType; }


Friends And Related Function Documentation

friend class InterfaceState [friend]

Definition at line 98 of file OSPFInterface.h.


Member Data Documentation

std::map<IPv4Address, std::list<OSPFLSAHeader>, IPv4Address_Less> OSPF::Interface::delayedAcknowledgements [private]

Definition at line 87 of file OSPFInterface.h.

Referenced by AddDelayedAcknowledgement(), and SendDelayedAcknowledgements().

Definition at line 76 of file OSPFInterface.h.

Referenced by GetHelloInterval(), SendHelloPacket(), and SetHelloInterval().

OSPFTimer* OSPF::Interface::helloTimer [private]

Definition at line 81 of file OSPFInterface.h.

Referenced by GetHelloTimer(), Interface(), Reset(), and ~Interface().

unsigned char OSPF::Interface::ifIndex [private]

Definition at line 90 of file OSPFInterface.h.

Referenced by GetOutputCost(), and SetOutputCost().

Definition at line 79 of file OSPFInterface.h.

Referenced by CreateUpdatePacket(), GetTransmissionDelay(), and SetTransmissionDelay().

unsigned short OSPF::Interface::mtu [private]

Definition at line 72 of file OSPFInterface.h.

Referenced by GetMTU(), SendDelayedAcknowledgements(), SetIfIndex(), and SetMTU().

Definition at line 85 of file OSPFInterface.h.

Referenced by AddNeighbor(), and GetNeighborByAddress().

Definition at line 84 of file OSPFInterface.h.

Referenced by AddNeighbor(), and GetNeighborByID().

Definition at line 77 of file OSPFInterface.h.

Referenced by GetPollInterval(), and SetPollInterval().

Definition at line 70 of file OSPFInterface.h.

Referenced by ChangeState(), Interface(), and ~Interface().

Definition at line 91 of file OSPFInterface.h.

Referenced by GetRetransmissionInterval(), and SetRetransmissionInterval().

Definition at line 78 of file OSPFInterface.h.

Referenced by GetRouterDeadInterval(), SendHelloPacket(), and SetRouterDeadInterval().

unsigned char OSPF::Interface::routerPriority [private]

Definition at line 69 of file OSPFInterface.h.

Referenced by ChangeState(), GetState(), Interface(), ProcessEvent(), and ~Interface().

Definition at line 75 of file OSPFInterface.h.

Referenced by GetTransitAreaID(), and SetTransitAreaID().

OSPFTimer* OSPF::Interface::waitTimer [private]

Definition at line 82 of file OSPFInterface.h.

Referenced by GetWaitTimer(), Interface(), Reset(), and ~Interface().


The documentation for this class was generated from the following files: