INET Framework for OMNeT++/OMNEST
OSPF::Neighbor Class Reference

#include <OSPFNeighbor.h>

List of all members.

Classes

struct  DDPacketID
struct  TransmittedLSA

Public Types

enum  NeighborEventType {
  HelloReceived = 0, Start = 1, TwoWayReceived = 2, NegotiationDone = 3,
  ExchangeDone = 4, BadLinkStateRequest = 5, LoadingDone = 6, IsAdjacencyOK = 7,
  SequenceNumberMismatch = 8, OneWayReceived = 9, KillNeighbor = 10, InactivityTimer = 11,
  PollTimer = 12, LinkDown = 13, DDRetransmissionTimer = 14, UpdateRetransmissionTimer = 15,
  RequestRetransmissionTimer = 16
}
enum  NeighborStateType {
  DownState = 0, AttemptState = 1, InitState = 2, TwoWayState = 4,
  ExchangeStartState = 8, ExchangeState = 16, LoadingState = 32, FullState = 64
}
enum  DatabaseExchangeRelationshipType { Master = 0, Slave = 1 }

Public Member Functions

 Neighbor (RouterID neighbor=NullRouterID)
virtual ~Neighbor (void)
void ProcessEvent (NeighborEventType event)
void Reset (void)
void InitFirstAdjacency (void)
NeighborStateType GetState (void) const
void SendDatabaseDescriptionPacket (bool init=false)
bool RetransmitDatabaseDescriptionPacket (void)
void CreateDatabaseSummary (void)
void SendLinkStateRequestPacket (void)
void RetransmitUpdatePacket (void)
bool NeedAdjacency (void)
void AddToRetransmissionList (OSPFLSA *lsa)
void RemoveFromRetransmissionList (LSAKeyType lsaKey)
bool IsLSAOnRetransmissionList (LSAKeyType lsaKey) const
OSPFLSA * FindOnRetransmissionList (LSAKeyType lsaKey)
void StartUpdateRetransmissionTimer (void)
void ClearUpdateRetransmissionTimer (void)
void AddToRequestList (OSPFLSAHeader *lsaHeader)
void RemoveFromRequestList (LSAKeyType lsaKey)
bool IsLSAOnRequestList (LSAKeyType lsaKey) const
OSPFLSAHeader * FindOnRequestList (LSAKeyType lsaKey)
void StartRequestRetransmissionTimer (void)
void ClearRequestRetransmissionTimer (void)
void AddToTransmittedLSAList (LSAKeyType lsaKey)
bool IsOnTransmittedLSAList (LSAKeyType lsaKey) const
void AgeTransmittedLSAList (void)
unsigned long GetUniqueULong (void)
void DeleteLastSentDDPacket (void)
void SetNeighborID (RouterID id)
RouterID GetNeighborID (void) const
void SetPriority (unsigned char priority)
unsigned char GetPriority (void) const
void SetAddress (IPv4Address address)
IPv4Address GetAddress (void) const
void SetDesignatedRouter (DesignatedRouterID routerID)
DesignatedRouterID GetDesignatedRouter (void) const
void SetBackupDesignatedRouter (DesignatedRouterID routerID)
DesignatedRouterID GetBackupDesignatedRouter (void) const
void SetRouterDeadInterval (short interval)
short GetRouterDeadInterval (void) const
void SetDDSequenceNumber (unsigned long sequenceNumber)
unsigned long GetDDSequenceNumber (void) const
void SetOptions (OSPFOptions options)
OSPFOptions GetOptions (void) const
void SetLastReceivedDDPacket (DDPacketID packetID)
DDPacketID GetLastReceivedDDPacket (void) const
void SetDatabaseExchangeRelationship (DatabaseExchangeRelationshipType relation)
DatabaseExchangeRelationshipType GetDatabaseExchangeRelationship (void) const
void SetInterface (Interface *intf)
InterfaceGetInterface (void)
const InterfaceGetInterface (void) const
OSPFTimer * GetInactivityTimer (void)
OSPFTimer * GetPollTimer (void)
OSPFTimer * GetDDRetransmissionTimer (void)
OSPFTimer * GetUpdateRetransmissionTimer (void)
bool IsUpdateRetransmissionTimerActive (void) const
bool IsRequestRetransmissionTimerActive (void) const
bool IsFirstAdjacencyInited (void) const
bool DesignatedRoutersAreSetUp (void) const
void SetUpDesignatedRouters (bool setUp)
unsigned long GetDatabaseSummaryListCount (void) const
void IncrementDDSequenceNumber (void)
bool IsLinkStateRequestListEmpty (void) const
bool IsLinkStateRetransmissionListEmpty (void) const
void PopFirstLinkStateRequest (void)

Static Public Member Functions

static const char * GetStateString (NeighborStateType stateType)

Private Member Functions

void ChangeState (NeighborState *newState, NeighborState *currentState)

Private Attributes

NeighborStatestate
NeighborStatepreviousState
OSPFTimer * inactivityTimer
OSPFTimer * pollTimer
OSPFTimer * ddRetransmissionTimer
OSPFTimer * updateRetransmissionTimer
bool updateRetransmissionTimerActive
OSPFTimer * requestRetransmissionTimer
bool requestRetransmissionTimerActive
DatabaseExchangeRelationshipType databaseExchangeRelationship
bool firstAdjacencyInited
unsigned long ddSequenceNumber
DDPacketID lastReceivedDDPacket
RouterID neighborID
unsigned char neighborPriority
IPv4Address neighborIPAddress
OSPFOptions neighborOptions
DesignatedRouterID neighborsDesignatedRouter
DesignatedRouterID neighborsBackupDesignatedRouter
bool designatedRoutersSetUp
short neighborsRouterDeadInterval
std::list< OSPFLSA * > linkStateRetransmissionList
std::list< OSPFLSAHeader * > databaseSummaryList
std::list< OSPFLSAHeader * > linkStateRequestList
std::list< TransmittedLSAtransmittedLSAs
OSPFDatabaseDescriptionPacket * lastTransmittedDDPacket
InterfaceparentInterface

Static Private Attributes

static unsigned long ddSequenceNumberInitSeed = 0

Friends

class NeighborState

Member Enumeration Documentation

Enumerator:
Master 
Slave 
                                          {
        Master = 0,
        Slave = 1
    };
Enumerator:
HelloReceived 
Start 
TwoWayReceived 
NegotiationDone 
ExchangeDone 
BadLinkStateRequest 
LoadingDone 
IsAdjacencyOK 
SequenceNumberMismatch 
OneWayReceived 
KillNeighbor 
InactivityTimer 
PollTimer 
LinkDown 
DDRetransmissionTimer 
UpdateRetransmissionTimer 
RequestRetransmissionTimer 
Enumerator:
DownState 
AttemptState 
InitState 
TwoWayState 
ExchangeStartState 
ExchangeState 
LoadingState 
FullState 

Constructor & Destructor Documentation

OSPF::Neighbor::Neighbor ( RouterID  neighbor = NullRouterID)
                                        :
    updateRetransmissionTimerActive(false),
    requestRetransmissionTimerActive(false),
    firstAdjacencyInited(false),
    ddSequenceNumber(0),
    neighborID(neighbor),
    neighborPriority(0),
    neighborIPAddress(OSPF::NullIPv4Address),
    neighborsDesignatedRouter(OSPF::NullDesignatedRouterID),
    neighborsBackupDesignatedRouter(OSPF::NullDesignatedRouterID),
    designatedRoutersSetUp(false),
    neighborsRouterDeadInterval(40),
    lastTransmittedDDPacket(NULL)
{
    memset(&lastReceivedDDPacket, 0, sizeof(OSPF::Neighbor::DDPacketID));
    // setting only I and M bits is invalid -> good initializer
    lastReceivedDDPacket.ddOptions.I_Init = true;
    lastReceivedDDPacket.ddOptions.M_More = true;
    inactivityTimer = new OSPFTimer;
    inactivityTimer->setTimerKind(NeighborInactivityTimer);
    inactivityTimer->setContextPointer(this);
    inactivityTimer->setName("OSPF::Neighbor::NeighborInactivityTimer");
    pollTimer = new OSPFTimer;
    pollTimer->setTimerKind(NeighborPollTimer);
    pollTimer->setContextPointer(this);
    pollTimer->setName("OSPF::Neighbor::NeighborPollTimer");
    ddRetransmissionTimer = new OSPFTimer;
    ddRetransmissionTimer->setTimerKind(NeighborDDRetransmissionTimer);
    ddRetransmissionTimer->setContextPointer(this);
    ddRetransmissionTimer->setName("OSPF::Neighbor::NeighborDDRetransmissionTimer");
    updateRetransmissionTimer = new OSPFTimer;
    updateRetransmissionTimer->setTimerKind(NeighborUpdateRetransmissionTimer);
    updateRetransmissionTimer->setContextPointer(this);
    updateRetransmissionTimer->setName("OSPF::Neighbor::Neighbor::NeighborUpdateRetransmissionTimer");
    requestRetransmissionTimer = new OSPFTimer;
    requestRetransmissionTimer->setTimerKind(NeighborRequestRetransmissionTimer);
    requestRetransmissionTimer->setContextPointer(this);
    requestRetransmissionTimer->setName("OSPF::Neighbor::NeighborRequestRetransmissionTimer");
    state = new OSPF::NeighborStateDown;
    previousState = NULL;
}
OSPF::Neighbor::~Neighbor ( void  ) [virtual]
{
    Reset();
    MessageHandler* messageHandler = parentInterface->GetArea()->GetRouter()->GetMessageHandler();
    messageHandler->ClearTimer(inactivityTimer);
    messageHandler->ClearTimer(pollTimer);
    delete inactivityTimer;
    delete pollTimer;
    delete ddRetransmissionTimer;
    delete updateRetransmissionTimer;
    delete requestRetransmissionTimer;
    if (previousState != NULL) {
        delete previousState;
    }
    delete state;
}

Member Function Documentation

void OSPF::Neighbor::AddToRequestList ( OSPFLSAHeader *  lsaHeader)

Referenced by OSPF::DatabaseDescriptionHandler::ProcessDDPacket().

{
    linkStateRequestList.push_back(new OSPFLSAHeader(*lsaHeader));
}
void OSPF::Neighbor::AddToRetransmissionList ( OSPFLSA *  lsa)

If the LSA is already on the retransmission list then it is replaced, else a copy of the LSA is added to the end of the retransmission list.

Parameters:
lsa[in] The LSA to be added.
{
    std::list<OSPFLSA*>::iterator it;
    for (it = linkStateRetransmissionList.begin(); it != linkStateRetransmissionList.end(); it++) {
        if (((*it)->getHeader().getLinkStateID() == lsa->getHeader().getLinkStateID()) &&
            ((*it)->getHeader().getAdvertisingRouter().getInt() == lsa->getHeader().getAdvertisingRouter().getInt()))
        {
            break;
        }
    }

    OSPFLSA* lsaCopy = NULL;
    switch (lsa->getHeader().getLsType()) {
        case RouterLSAType:
            lsaCopy = new OSPFRouterLSA(*(check_and_cast<OSPFRouterLSA*> (lsa)));
            break;
        case NetworkLSAType:
            lsaCopy = new OSPFNetworkLSA(*(check_and_cast<OSPFNetworkLSA*> (lsa)));
            break;
        case SummaryLSA_NetworksType:
        case SummaryLSA_ASBoundaryRoutersType:
            lsaCopy = new OSPFSummaryLSA(*(check_and_cast<OSPFSummaryLSA*> (lsa)));
            break;
        case ASExternalLSAType:
            lsaCopy = new OSPFASExternalLSA(*(check_and_cast<OSPFASExternalLSA*> (lsa)));
            break;
        default:
            ASSERT(false); // error
            break;
    }

    if (it != linkStateRetransmissionList.end()) {
        delete(*it);
        *it = static_cast<OSPFLSA*> (lsaCopy);
    } else {
        linkStateRetransmissionList.push_back(static_cast<OSPFLSA*> (lsaCopy));
    }
}
void OSPF::Neighbor::AddToTransmittedLSAList ( OSPF::LSAKeyType  lsaKey)

Referenced by OSPF::Interface::FloodLSA().

{
    TransmittedLSA transmit;

    transmit.lsaKey = lsaKey;
    transmit.age = 0;

    transmittedLSAs.push_back(transmit);
}
void OSPF::Neighbor::AgeTransmittedLSAList ( void  )
{
    std::list<TransmittedLSA>::iterator it = transmittedLSAs.begin();
    while ((it != transmittedLSAs.end()) && (it->age == MIN_LS_ARRIVAL)) {
        transmittedLSAs.pop_front();
        it = transmittedLSAs.begin();
    }
    for (it = transmittedLSAs.begin(); it != transmittedLSAs.end(); it++) {
        it->age++;
    }
}
void OSPF::Neighbor::ChangeState ( NeighborState newState,
NeighborState currentState 
) [private]

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

{
    if (previousState != NULL) {
        delete previousState;
    }
    state = newState;
    previousState = currentState;
}
void OSPF::Neighbor::ClearRequestRetransmissionTimer ( void  )

Referenced by OSPF::NeighborStateLoading::ProcessEvent(), OSPF::NeighborStateExchange::ProcessEvent(), and OSPF::DatabaseDescriptionHandler::ProcessPacket().

{
    MessageHandler* messageHandler = parentInterface->GetArea()->GetRouter()->GetMessageHandler();
    messageHandler->ClearTimer(requestRetransmissionTimer);
    requestRetransmissionTimerActive = false;
}
void OSPF::Neighbor::ClearUpdateRetransmissionTimer ( void  )

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

{
    MessageHandler* messageHandler = parentInterface->GetArea()->GetRouter()->GetMessageHandler();
    messageHandler->ClearTimer(updateRetransmissionTimer);
    updateRetransmissionTimerActive = false;
}
void OSPF::Neighbor::CreateDatabaseSummary ( void  )

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

{
    OSPF::Area*   area           = parentInterface->GetArea();
    unsigned long routerLSACount = area->GetRouterLSACount();

    /* Note: OSPF specification says:
     * "LSAs whose age is equal to MaxAge are instead added to the neighbor's
     *  Link state retransmission list."
     * But this task has been already done during the aging of the database. (???)
     * So we'll skip this.
     */
    for (unsigned long i = 0; i < routerLSACount; i++) {
        if (area->GetRouterLSA(i)->getHeader().getLsAge() < MAX_AGE) {
            OSPFLSAHeader* routerLSA = new OSPFLSAHeader(area->GetRouterLSA(i)->getHeader());
            databaseSummaryList.push_back(routerLSA);
        }
    }

    unsigned long networkLSACount = area->GetNetworkLSACount();
    for (unsigned long j = 0; j < networkLSACount; j++) {
        if (area->GetNetworkLSA(j)->getHeader().getLsAge() < MAX_AGE) {
            OSPFLSAHeader* networkLSA = new OSPFLSAHeader(area->GetNetworkLSA(j)->getHeader());
            databaseSummaryList.push_back(networkLSA);
        }
    }

    unsigned long summaryLSACount = area->GetSummaryLSACount();
    for (unsigned long k = 0; k < summaryLSACount; k++) {
        if (area->GetSummaryLSA(k)->getHeader().getLsAge() < MAX_AGE) {
            OSPFLSAHeader* summaryLSA = new OSPFLSAHeader(area->GetSummaryLSA(k)->getHeader());
            databaseSummaryList.push_back(summaryLSA);
        }
    }

    if ((parentInterface->GetType() != OSPF::Interface::Virtual) &&
        (area->GetExternalRoutingCapability()))
    {
        OSPF::Router* router             = area->GetRouter();
        unsigned long asExternalLSACount = router->GetASExternalLSACount();

        for (unsigned long m = 0; m < asExternalLSACount; m++) {
            if (router->GetASExternalLSA(m)->getHeader().getLsAge() < MAX_AGE) {
                OSPFLSAHeader* asExternalLSA = new OSPFLSAHeader(router->GetASExternalLSA(m)->getHeader());
                databaseSummaryList.push_back(asExternalLSA);
            }
        }
    }
}
void OSPF::Neighbor::DeleteLastSentDDPacket ( void  )
bool OSPF::Neighbor::DesignatedRoutersAreSetUp ( void  ) const [inline]
OSPFLSAHeader * OSPF::Neighbor::FindOnRequestList ( OSPF::LSAKeyType  lsaKey)
{
    for (std::list<OSPFLSAHeader*>::iterator it = linkStateRequestList.begin(); it != linkStateRequestList.end(); it++) {
        if (((*it)->getLinkStateID() == lsaKey.linkStateID) &&
            ((*it)->getAdvertisingRouter().getInt() == lsaKey.advertisingRouter))
        {
            return (*it);
        }
    }
    return NULL;
}
OSPFLSA * OSPF::Neighbor::FindOnRetransmissionList ( OSPF::LSAKeyType  lsaKey)

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

{
    for (std::list<OSPFLSA*>::iterator it = linkStateRetransmissionList.begin(); it != linkStateRetransmissionList.end(); it++) {
        if (((*it)->getHeader().getLinkStateID() == lsaKey.linkStateID) &&
            ((*it)->getHeader().getAdvertisingRouter().getInt() == lsaKey.advertisingRouter))
        {
            return (*it);
        }
    }
    return NULL;
}
DesignatedRouterID OSPF::Neighbor::GetBackupDesignatedRouter ( void  ) const [inline]
DatabaseExchangeRelationshipType OSPF::Neighbor::GetDatabaseExchangeRelationship ( void  ) const [inline]
unsigned long OSPF::Neighbor::GetDatabaseSummaryListCount ( void  ) const [inline]
unsigned long OSPF::Neighbor::GetDDSequenceNumber ( void  ) const [inline]
DesignatedRouterID OSPF::Neighbor::GetDesignatedRouter ( void  ) const [inline]
const Interface* OSPF::Neighbor::GetInterface ( void  ) const [inline]
{ return parentInterface; }
DDPacketID OSPF::Neighbor::GetLastReceivedDDPacket ( void  ) const [inline]
OSPFOptions OSPF::Neighbor::GetOptions ( void  ) const [inline]
{ return neighborOptions; }
const char * OSPF::Neighbor::GetStateString ( NeighborStateType  stateType) [static]

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

{
    switch (stateType) {
        case DownState:             return "Down";
        case AttemptState:          return "Attempt";
        case InitState:             return "Init";
        case TwoWayState:           return "TwoWay";
        case ExchangeStartState:    return "ExchangeStart";
        case ExchangeState:         return "Exchange";
        case LoadingState:          return "Loading";
        case FullState:             return "Full";
        default:                    ASSERT(false);
    }
    return "";
}
unsigned long OSPF::Neighbor::GetUniqueULong ( void  )
{
    // FIXME!!! Should come from a global unique number generator module.
    return (ddSequenceNumberInitSeed++);
}
OSPFTimer* OSPF::Neighbor::GetUpdateRetransmissionTimer ( void  ) [inline]
void OSPF::Neighbor::InitFirstAdjacency ( void  )
bool OSPF::Neighbor::IsFirstAdjacencyInited ( void  ) const [inline]
bool OSPF::Neighbor::IsLinkStateRequestListEmpty ( void  ) const [inline]
bool OSPF::Neighbor::IsLinkStateRetransmissionListEmpty ( void  ) const [inline]
bool OSPF::Neighbor::IsLSAOnRequestList ( OSPF::LSAKeyType  lsaKey) const

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

{
    for (std::list<OSPFLSAHeader*>::const_iterator it = linkStateRequestList.begin(); it != linkStateRequestList.end(); it++) {
        const OSPFLSAHeader* lsaHeader = *it;
        if ((lsaHeader->getLinkStateID() == lsaKey.linkStateID) &&
            (lsaHeader->getAdvertisingRouter().getInt() == lsaKey.advertisingRouter))
        {
            return true;
        }
    }
    return false;
}
bool OSPF::Neighbor::IsLSAOnRetransmissionList ( OSPF::LSAKeyType  lsaKey) const

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

{
    for (std::list<OSPFLSA*>::const_iterator it = linkStateRetransmissionList.begin(); it != linkStateRetransmissionList.end(); it++) {
        const OSPFLSA* lsa = *it;
        if ((lsa->getHeader().getLinkStateID() == lsaKey.linkStateID) &&
            (lsa->getHeader().getAdvertisingRouter().getInt() == lsaKey.advertisingRouter))
        {
            return true;
        }
    }
    return false;
}
bool OSPF::Neighbor::IsOnTransmittedLSAList ( OSPF::LSAKeyType  lsaKey) const

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

{
    for (std::list<TransmittedLSA>::const_iterator it = transmittedLSAs.begin(); it != transmittedLSAs.end(); it++) {
        if ((it->lsaKey.linkStateID == lsaKey.linkStateID) &&
            (it->lsaKey.advertisingRouter == lsaKey.advertisingRouter))
        {
            return true;
        }
    }
    return false;
}
bool OSPF::Neighbor::IsRequestRetransmissionTimerActive ( void  ) const [inline]
bool OSPF::Neighbor::IsUpdateRetransmissionTimerActive ( void  ) const [inline]
bool OSPF::Neighbor::NeedAdjacency ( void  )

Referenced by OSPF::NeighborStateTwoWay::ProcessEvent(), OSPF::NeighborStateLoading::ProcessEvent(), OSPF::NeighborStateInit::ProcessEvent(), OSPF::NeighborStateFull::ProcessEvent(), OSPF::NeighborStateExchangeStart::ProcessEvent(), and OSPF::NeighborStateExchange::ProcessEvent().

{
    OSPF::Interface::OSPFInterfaceType interfaceType = parentInterface->GetType();
    OSPF::RouterID                     routerID      = parentInterface->GetArea()->GetRouter()->GetRouterID();
    OSPF::DesignatedRouterID           dRouter       = parentInterface->GetDesignatedRouter();
    OSPF::DesignatedRouterID           backupDRouter = parentInterface->GetBackupDesignatedRouter();

    if ((interfaceType == OSPF::Interface::PointToPoint) ||
        (interfaceType == OSPF::Interface::PointToMultiPoint) ||
        (interfaceType == OSPF::Interface::Virtual) ||
        (dRouter.routerID == routerID) ||
        (backupDRouter.routerID == routerID) ||
        ((neighborsDesignatedRouter.routerID == dRouter.routerID) ||
         (!designatedRoutersSetUp &&
          (neighborsDesignatedRouter.ipInterfaceAddress == dRouter.ipInterfaceAddress))) ||
        ((neighborsBackupDesignatedRouter.routerID == backupDRouter.routerID) ||
         (!designatedRoutersSetUp &&
          (neighborsBackupDesignatedRouter.ipInterfaceAddress == backupDRouter.ipInterfaceAddress))))
    {
        return true;
    } else {
        return false;
    }
}
void OSPF::Neighbor::PopFirstLinkStateRequest ( void  ) [inline]
{ linkStateRequestList.pop_front(); }
void OSPF::Neighbor::RemoveFromRequestList ( OSPF::LSAKeyType  lsaKey)
{
    std::list<OSPFLSAHeader*>::iterator it = linkStateRequestList.begin();
    while (it != linkStateRequestList.end()) {
        if (((*it)->getLinkStateID() == lsaKey.linkStateID) &&
            ((*it)->getAdvertisingRouter().getInt() == lsaKey.advertisingRouter))
        {
            delete(*it);
            it = linkStateRequestList.erase(it);
        } else {
            it++;
        }
    }

    if ((GetState() == OSPF::Neighbor::LoadingState) && (linkStateRequestList.empty())) {
        ClearRequestRetransmissionTimer();
        ProcessEvent(OSPF::Neighbor::LoadingDone);
    }
}
void OSPF::Neighbor::RemoveFromRetransmissionList ( OSPF::LSAKeyType  lsaKey)

Referenced by OSPF::LinkStateUpdateHandler::ProcessPacket(), and OSPF::LinkStateAcknowledgementHandler::ProcessPacket().

{
    std::list<OSPFLSA*>::iterator it = linkStateRetransmissionList.begin();
    while (it != linkStateRetransmissionList.end()) {
        if (((*it)->getHeader().getLinkStateID() == lsaKey.linkStateID) &&
            ((*it)->getHeader().getAdvertisingRouter().getInt() == lsaKey.advertisingRouter))
        {
            delete(*it);
            it = linkStateRetransmissionList.erase(it);
        } else {
            it++;
        }
    }
}
void OSPF::Neighbor::Reset ( void  )
bool OSPF::Neighbor::RetransmitDatabaseDescriptionPacket ( void  )

Referenced by OSPF::NeighborStateExchangeStart::ProcessEvent(), and OSPF::DatabaseDescriptionHandler::ProcessPacket().

{
    if (lastTransmittedDDPacket != NULL) {
        OSPFDatabaseDescriptionPacket* ddPacket       = new OSPFDatabaseDescriptionPacket(*lastTransmittedDDPacket);
        OSPF::MessageHandler*          messageHandler = parentInterface->GetArea()->GetRouter()->GetMessageHandler();
        int                            ttl            = (parentInterface->GetType() == OSPF::Interface::Virtual) ? VIRTUAL_LINK_TTL : 1;

        if (parentInterface->GetType() == OSPF::Interface::PointToPoint) {
            messageHandler->SendPacket(ddPacket, OSPF::AllSPFRouters, parentInterface->GetIfIndex(), ttl);
        } else {
            messageHandler->SendPacket(ddPacket, neighborIPAddress, parentInterface->GetIfIndex(), ttl);
        }

        return true;
    } else {
        return false;
    }
}
void OSPF::Neighbor::RetransmitUpdatePacket ( void  )

Referenced by OSPF::NeighborStateLoading::ProcessEvent(), OSPF::NeighborStateFull::ProcessEvent(), and OSPF::NeighborStateExchange::ProcessEvent().

{
    OSPFLinkStateUpdatePacket* updatePacket = new OSPFLinkStateUpdatePacket;

    updatePacket->setType(LinkStateUpdatePacket);
    updatePacket->setRouterID(parentInterface->GetArea()->GetRouter()->GetRouterID());
    updatePacket->setAreaID(parentInterface->GetArea()->GetAreaID());
    updatePacket->setAuthenticationType(parentInterface->GetAuthenticationType());
    OSPF::AuthenticationKeyType authKey = parentInterface->GetAuthenticationKey();
    for (int i = 0; i < 8; i++) {
        updatePacket->setAuthentication(i, authKey.bytes[i]);
    }

    bool                          packetFull   = false;
    unsigned short                lsaCount     = 0;
    unsigned long                 packetLength = IPV4_HEADER_LENGTH + OSPF_LSA_HEADER_LENGTH;
    std::list<OSPFLSA*>::iterator it           = linkStateRetransmissionList.begin();

    while (!packetFull && (it != linkStateRetransmissionList.end())) {
        LSAType            lsaType       = static_cast<LSAType> ((*it)->getHeader().getLsType());
        OSPFRouterLSA*     routerLSA     = (lsaType == RouterLSAType) ? dynamic_cast<OSPFRouterLSA*> (*it) : NULL;
        OSPFNetworkLSA*    networkLSA    = (lsaType == NetworkLSAType) ? dynamic_cast<OSPFNetworkLSA*> (*it) : NULL;
        OSPFSummaryLSA*    summaryLSA    = ((lsaType == SummaryLSA_NetworksType) ||
                                            (lsaType == SummaryLSA_ASBoundaryRoutersType)) ? dynamic_cast<OSPFSummaryLSA*> (*it) : NULL;
        OSPFASExternalLSA* asExternalLSA = (lsaType == ASExternalLSAType) ? dynamic_cast<OSPFASExternalLSA*> (*it) : NULL;
        long               lsaSize       = 0;
        bool               includeLSA    = false;

        switch (lsaType) {
            case RouterLSAType:
                if (routerLSA != NULL) {
                    lsaSize = CalculateLSASize(routerLSA);
                }
                break;
            case NetworkLSAType:
                if (networkLSA != NULL) {
                    lsaSize = CalculateLSASize(networkLSA);
                }
                break;
            case SummaryLSA_NetworksType:
            case SummaryLSA_ASBoundaryRoutersType:
                if (summaryLSA != NULL) {
                    lsaSize = CalculateLSASize(summaryLSA);
                }
                break;
            case ASExternalLSAType:
                if (asExternalLSA != NULL) {
                    lsaSize = CalculateLSASize(asExternalLSA);
                }
                break;
            default: break;
        }

        if (packetLength + lsaSize < parentInterface->GetMTU()) {
            includeLSA = true;
            lsaCount++;
        } else {
            if ((lsaCount == 0) && (packetLength + lsaSize < IPV4_DATAGRAM_LENGTH)) {
                includeLSA = true;
                lsaCount++;
                packetFull = true;
            }
        }

        if (includeLSA) {
            switch (lsaType) {
                case RouterLSAType:
                    if (routerLSA != NULL) {
                        unsigned int routerLSACount = updatePacket->getRouterLSAsArraySize();

                        updatePacket->setRouterLSAsArraySize(routerLSACount + 1);
                        updatePacket->setRouterLSAs(routerLSACount, *routerLSA);

                        unsigned short lsAge = updatePacket->getRouterLSAs(routerLSACount).getHeader().getLsAge();
                        if (lsAge < MAX_AGE - parentInterface->GetTransmissionDelay()) {
                            updatePacket->getRouterLSAs(routerLSACount).getHeader().setLsAge(lsAge + parentInterface->GetTransmissionDelay());
                        } else {
                            updatePacket->getRouterLSAs(routerLSACount).getHeader().setLsAge(MAX_AGE);
                        }
                    }
                    break;
                case NetworkLSAType:
                    if (networkLSA != NULL) {
                        unsigned int networkLSACount = updatePacket->getNetworkLSAsArraySize();

                        updatePacket->setNetworkLSAsArraySize(networkLSACount + 1);
                        updatePacket->setNetworkLSAs(networkLSACount, *networkLSA);

                        unsigned short lsAge = updatePacket->getNetworkLSAs(networkLSACount).getHeader().getLsAge();
                        if (lsAge < MAX_AGE - parentInterface->GetTransmissionDelay()) {
                            updatePacket->getNetworkLSAs(networkLSACount).getHeader().setLsAge(lsAge + parentInterface->GetTransmissionDelay());
                        } else {
                            updatePacket->getNetworkLSAs(networkLSACount).getHeader().setLsAge(MAX_AGE);
                        }
                    }
                    break;
                case SummaryLSA_NetworksType:
                case SummaryLSA_ASBoundaryRoutersType:
                    if (summaryLSA != NULL) {
                        unsigned int summaryLSACount = updatePacket->getSummaryLSAsArraySize();

                        updatePacket->setSummaryLSAsArraySize(summaryLSACount + 1);
                        updatePacket->setSummaryLSAs(summaryLSACount, *summaryLSA);

                        unsigned short lsAge = updatePacket->getSummaryLSAs(summaryLSACount).getHeader().getLsAge();
                        if (lsAge < MAX_AGE - parentInterface->GetTransmissionDelay()) {
                            updatePacket->getSummaryLSAs(summaryLSACount).getHeader().setLsAge(lsAge + parentInterface->GetTransmissionDelay());
                        } else {
                            updatePacket->getSummaryLSAs(summaryLSACount).getHeader().setLsAge(MAX_AGE);
                        }
                    }
                    break;
                case ASExternalLSAType:
                    if (asExternalLSA != NULL) {
                        unsigned int asExternalLSACount = updatePacket->getAsExternalLSAsArraySize();

                        updatePacket->setAsExternalLSAsArraySize(asExternalLSACount + 1);
                        updatePacket->setAsExternalLSAs(asExternalLSACount, *asExternalLSA);

                        unsigned short lsAge = updatePacket->getAsExternalLSAs(asExternalLSACount).getHeader().getLsAge();
                        if (lsAge < MAX_AGE - parentInterface->GetTransmissionDelay()) {
                            updatePacket->getAsExternalLSAs(asExternalLSACount).getHeader().setLsAge(lsAge + parentInterface->GetTransmissionDelay());
                        } else {
                            updatePacket->getAsExternalLSAs(asExternalLSACount).getHeader().setLsAge(MAX_AGE);
                        }
                    }
                    break;
                default: break;
            }
        }

        it++;
    }

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

    OSPF::MessageHandler* messageHandler = parentInterface->GetArea()->GetRouter()->GetMessageHandler();
    int ttl = (parentInterface->GetType() == OSPF::Interface::Virtual) ? VIRTUAL_LINK_TTL : 1;
    messageHandler->SendPacket(updatePacket, neighborIPAddress, parentInterface->GetIfIndex(), ttl);
}
void OSPF::Neighbor::SendDatabaseDescriptionPacket ( bool  init = false)

Referenced by OSPF::DatabaseDescriptionHandler::ProcessDDPacket(), OSPF::NeighborStateTwoWay::ProcessEvent(), OSPF::NeighborStateLoading::ProcessEvent(), OSPF::NeighborStateInit::ProcessEvent(), OSPF::NeighborStateFull::ProcessEvent(), OSPF::NeighborStateExchangeStart::ProcessEvent(), OSPF::NeighborStateExchange::ProcessEvent(), and OSPF::DatabaseDescriptionHandler::ProcessPacket().

{
    OSPFDatabaseDescriptionPacket* ddPacket = new OSPFDatabaseDescriptionPacket;

    ddPacket->setType(DatabaseDescriptionPacket);
    ddPacket->setRouterID(parentInterface->GetArea()->GetRouter()->GetRouterID());
    ddPacket->setAreaID(parentInterface->GetArea()->GetAreaID());
    ddPacket->setAuthenticationType(parentInterface->GetAuthenticationType());
    OSPF::AuthenticationKeyType authKey = parentInterface->GetAuthenticationKey();
    for (int i = 0; i < 8; i++) {
        ddPacket->setAuthentication(i, authKey.bytes[i]);
    }

    if (parentInterface->GetType() != OSPF::Interface::Virtual) {
        ddPacket->setInterfaceMTU(parentInterface->GetMTU());
    } else {
        ddPacket->setInterfaceMTU(0);
    }

    OSPFOptions options;
    memset(&options, 0, sizeof(OSPFOptions));
    options.E_ExternalRoutingCapability = parentInterface->GetArea()->GetExternalRoutingCapability();
    ddPacket->setOptions(options);

    ddPacket->setDdSequenceNumber(ddSequenceNumber);

    long maxPacketSize = ((IPV4_HEADER_LENGTH + OSPF_HEADER_LENGTH + OSPF_DD_HEADER_LENGTH + OSPF_LSA_HEADER_LENGTH) > parentInterface->GetMTU()) ?
                          IPV4_DATAGRAM_LENGTH :
                          parentInterface->GetMTU();

    if (init || databaseSummaryList.empty()) {
        ddPacket->setLsaHeadersArraySize(0);
    } else {
        // delete included LSAs from summary list
        // (they are still in lastTransmittedDDPacket)
        long packetSize = IPV4_HEADER_LENGTH + OSPF_HEADER_LENGTH + OSPF_DD_HEADER_LENGTH;
        while ((!databaseSummaryList.empty()) && (packetSize <= (maxPacketSize - OSPF_LSA_HEADER_LENGTH))) {
            unsigned long   headerCount = ddPacket->getLsaHeadersArraySize();
            OSPFLSAHeader*  lsaHeader   = *(databaseSummaryList.begin());
            ddPacket->setLsaHeadersArraySize(headerCount + 1);
            ddPacket->setLsaHeaders(headerCount, *lsaHeader);
            delete lsaHeader;
            databaseSummaryList.pop_front();
            packetSize += OSPF_LSA_HEADER_LENGTH;
        }
    }

    OSPFDDOptions ddOptions;
    memset(&ddOptions, 0, sizeof(OSPFDDOptions));
    if (init) {
        ddOptions.I_Init = true;
        ddOptions.M_More = true;
        ddOptions.MS_MasterSlave = true;
    } else {
        ddOptions.I_Init = false;
        ddOptions.M_More = (databaseSummaryList.empty()) ? false : true;
        ddOptions.MS_MasterSlave = (databaseExchangeRelationship == OSPF::Neighbor::Master) ? true : false;
    }
    ddPacket->setDdOptions(ddOptions);

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

    OSPF::MessageHandler* messageHandler = parentInterface->GetArea()->GetRouter()->GetMessageHandler();
    int ttl = (parentInterface->GetType() == OSPF::Interface::Virtual) ? VIRTUAL_LINK_TTL : 1;
    if (parentInterface->GetType() == OSPF::Interface::PointToPoint) {
        messageHandler->SendPacket(ddPacket, OSPF::AllSPFRouters, parentInterface->GetIfIndex(), ttl);
    } else {
        messageHandler->SendPacket(ddPacket, neighborIPAddress, parentInterface->GetIfIndex(), ttl);
    }

    if (lastTransmittedDDPacket != NULL) {
        delete lastTransmittedDDPacket;
    }
    lastTransmittedDDPacket = new OSPFDatabaseDescriptionPacket(*ddPacket);
}
void OSPF::Neighbor::SendLinkStateRequestPacket ( void  )

Referenced by OSPF::NeighborStateLoading::ProcessEvent(), OSPF::NeighborStateExchange::ProcessEvent(), and OSPF::DatabaseDescriptionHandler::ProcessPacket().

{
    OSPFLinkStateRequestPacket* requestPacket = new OSPFLinkStateRequestPacket;

    requestPacket->setType(LinkStateRequestPacket);
    requestPacket->setRouterID(parentInterface->GetArea()->GetRouter()->GetRouterID());
    requestPacket->setAreaID(parentInterface->GetArea()->GetAreaID());
    requestPacket->setAuthenticationType(parentInterface->GetAuthenticationType());
    OSPF::AuthenticationKeyType authKey = parentInterface->GetAuthenticationKey();
    for (int i = 0; i < 8; i++) {
        requestPacket->setAuthentication(i, authKey.bytes[i]);
    }

    long maxPacketSize = ((IPV4_HEADER_LENGTH + OSPF_HEADER_LENGTH + OSPF_REQUEST_LENGTH) > parentInterface->GetMTU()) ?
                          IPV4_DATAGRAM_LENGTH :
                          parentInterface->GetMTU();

    if (linkStateRequestList.empty()) {
        requestPacket->setRequestsArraySize(0);
    } else {
        long packetSize = IPV4_HEADER_LENGTH + OSPF_HEADER_LENGTH;
        std::list<OSPFLSAHeader*>::iterator it = linkStateRequestList.begin();

        while ((it != linkStateRequestList.end()) && (packetSize <= (maxPacketSize - OSPF_REQUEST_LENGTH))) {
            unsigned long  requestCount  = requestPacket->getRequestsArraySize();
            OSPFLSAHeader* requestHeader = (*it);
            LSARequest     request;

            request.lsType = requestHeader->getLsType();
            request.linkStateID = requestHeader->getLinkStateID();
            request.advertisingRouter = requestHeader->getAdvertisingRouter();

            requestPacket->setRequestsArraySize(requestCount + 1);
            requestPacket->setRequests(requestCount, request);

            packetSize += OSPF_REQUEST_LENGTH;
            it++;
        }
    }

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

    OSPF::MessageHandler* messageHandler = parentInterface->GetArea()->GetRouter()->GetMessageHandler();
    int ttl = (parentInterface->GetType() == OSPF::Interface::Virtual) ? VIRTUAL_LINK_TTL : 1;
    if (parentInterface->GetType() == OSPF::Interface::PointToPoint) {
        messageHandler->SendPacket(requestPacket, OSPF::AllSPFRouters, parentInterface->GetIfIndex(), ttl);
    } else {
        messageHandler->SendPacket(requestPacket, neighborIPAddress, parentInterface->GetIfIndex(), ttl);
    }
}
void OSPF::Neighbor::SetAddress ( IPv4Address  address) [inline]
void OSPF::Neighbor::SetBackupDesignatedRouter ( DesignatedRouterID  routerID) [inline]
void OSPF::Neighbor::SetDatabaseExchangeRelationship ( DatabaseExchangeRelationshipType  relation) [inline]
void OSPF::Neighbor::SetDDSequenceNumber ( unsigned long  sequenceNumber) [inline]
void OSPF::Neighbor::SetDesignatedRouter ( DesignatedRouterID  routerID) [inline]
void OSPF::Neighbor::SetInterface ( Interface intf) [inline]

Referenced by OSPF::Interface::AddNeighbor().

{ parentInterface = intf; }
void OSPF::Neighbor::SetLastReceivedDDPacket ( DDPacketID  packetID) [inline]
void OSPF::Neighbor::SetNeighborID ( RouterID  id) [inline]
void OSPF::Neighbor::SetOptions ( OSPFOptions  options) [inline]
void OSPF::Neighbor::SetPriority ( unsigned char  priority) [inline]
void OSPF::Neighbor::SetRouterDeadInterval ( short  interval) [inline]
void OSPF::Neighbor::SetUpDesignatedRouters ( bool  setUp) [inline]
void OSPF::Neighbor::StartRequestRetransmissionTimer ( void  )

Referenced by OSPF::NeighborStateLoading::ProcessEvent(), OSPF::NeighborStateExchange::ProcessEvent(), and OSPF::DatabaseDescriptionHandler::ProcessPacket().

{
    MessageHandler* messageHandler = parentInterface->GetArea()->GetRouter()->GetMessageHandler();
    messageHandler->StartTimer(requestRetransmissionTimer, parentInterface->GetRetransmissionInterval());
    requestRetransmissionTimerActive = true;
}
void OSPF::Neighbor::StartUpdateRetransmissionTimer ( void  )

Referenced by OSPF::Interface::FloodLSA(), OSPF::NeighborStateLoading::ProcessEvent(), OSPF::NeighborStateFull::ProcessEvent(), and OSPF::NeighborStateExchange::ProcessEvent().

{
    MessageHandler* messageHandler = parentInterface->GetArea()->GetRouter()->GetMessageHandler();
    messageHandler->StartTimer(updateRetransmissionTimer, parentInterface->GetRetransmissionInterval());
    updateRetransmissionTimerActive = true;
}

Friends And Related Function Documentation

friend class NeighborState [friend]

Member Data Documentation

std::list<OSPFLSAHeader*> OSPF::Neighbor::databaseSummaryList [private]
unsigned long OSPF::Neighbor::ddSequenceNumberInitSeed = 0 [static, private]
OSPFTimer* OSPF::Neighbor::inactivityTimer [private]

Referenced by GetInactivityTimer(), and Neighbor().

OSPFDatabaseDescriptionPacket* OSPF::Neighbor::lastTransmittedDDPacket [private]
OSPFOptions OSPF::Neighbor::neighborOptions [private]

Referenced by GetOptions(), and SetOptions().

unsigned char OSPF::Neighbor::neighborPriority [private]

Referenced by GetPriority(), and SetPriority().

OSPFTimer* OSPF::Neighbor::pollTimer [private]

Referenced by GetPollTimer(), and Neighbor().

Referenced by Neighbor().

Referenced by Neighbor().


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