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
OSPFLSAFindOnRetransmissionList (LSAKeyType lsaKey)
void StartUpdateRetransmissionTimer (void)
void ClearUpdateRetransmissionTimer (void)
void AddToRequestList (OSPFLSAHeader *lsaHeader)
void RemoveFromRequestList (LSAKeyType lsaKey)
bool IsLSAOnRequestList (LSAKeyType lsaKey) const
OSPFLSAHeaderFindOnRequestList (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
OSPFTimerGetInactivityTimer (void)
OSPFTimerGetPollTimer (void)
OSPFTimerGetDDRetransmissionTimer (void)
OSPFTimerGetUpdateRetransmissionTimer (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
OSPFTimerinactivityTimer
OSPFTimerpollTimer
OSPFTimerddRetransmissionTimer
OSPFTimerupdateRetransmissionTimer
bool updateRetransmissionTimerActive
OSPFTimerrequestRetransmissionTimer
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
OSPFDatabaseDescriptionPacketlastTransmittedDDPacket
InterfaceparentInterface

Static Private Attributes

static unsigned long ddSequenceNumberInitSeed = 0

Friends

class NeighborState

Detailed Description

Definition at line 32 of file OSPFNeighbor.h.


Member Enumeration Documentation

Enumerator:
Master 
Slave 

Definition at line 68 of file OSPFNeighbor.h.

                                          {
        Master = 0,
        Slave = 1
    };
Enumerator:
HelloReceived 
Start 
TwoWayReceived 
NegotiationDone 
ExchangeDone 
BadLinkStateRequest 
LoadingDone 
IsAdjacencyOK 
SequenceNumberMismatch 
OneWayReceived 
KillNeighbor 
InactivityTimer 
PollTimer 
LinkDown 
DDRetransmissionTimer 
UpdateRetransmissionTimer 
RequestRetransmissionTimer 

Definition at line 37 of file OSPFNeighbor.h.

Enumerator:
DownState 
AttemptState 
InitState 
TwoWayState 
ExchangeStartState 
ExchangeState 
LoadingState 
FullState 

Definition at line 57 of file OSPFNeighbor.h.


Constructor & Destructor Documentation

Definition at line 29 of file OSPFNeighbor.cc.

                                        :
    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]

Definition at line 71 of file OSPFNeighbor.cc.

{
    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

Definition at line 486 of file OSPFNeighbor.cc.

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

{
    linkStateRequestList.push_back(new OSPFLSAHeader(*lsaHeader));
}

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.

Definition at line 393 of file OSPFNeighbor.cc.

{
    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));
    }
}

Definition at line 550 of file OSPFNeighbor.cc.

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

{
    TransmittedLSA transmit;

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

    transmittedLSAs.push_back(transmit);
}

Definition at line 572 of file OSPFNeighbor.cc.

{
    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]

Definition at line 88 of file OSPFNeighbor.cc.

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

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

Definition at line 262 of file OSPFNeighbor.cc.

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);
            }
        }
    }
}
bool OSPF::Neighbor::DesignatedRoutersAreSetUp ( void  ) const [inline]

Definition at line 187 of file OSPFNeighbor.h.

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

Definition at line 524 of file OSPFNeighbor.cc.

{
    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;
}

Definition at line 460 of file OSPFNeighbor.cc.

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;
}
unsigned long OSPF::Neighbor::GetDatabaseSummaryListCount ( void  ) const [inline]

Definition at line 189 of file OSPFNeighbor.h.

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

{ return databaseSummaryList.size(); }
unsigned long OSPF::Neighbor::GetDDSequenceNumber ( void  ) const [inline]

Definition at line 167 of file OSPFNeighbor.h.

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

{ return ddSequenceNumber; }
const Interface* OSPF::Neighbor::GetInterface ( void  ) const [inline]

Definition at line 178 of file OSPFNeighbor.h.

{ return parentInterface; }
OSPFOptions OSPF::Neighbor::GetOptions ( void  ) const [inline]

Definition at line 169 of file OSPFNeighbor.h.

{ return neighborOptions; }
const char * OSPF::Neighbor::GetStateString ( NeighborStateType  stateType) [static]

Definition at line 150 of file OSPFNeighbor.cc.

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  )

Definition at line 139 of file OSPFNeighbor.cc.

{
    // FIXME!!! Should come from a global unique number generator module.
    return (ddSequenceNumberInitSeed++);
}

Definition at line 183 of file OSPFNeighbor.h.

Definition at line 193 of file OSPFNeighbor.h.

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

{ return linkStateRetransmissionList.empty(); }

Definition at line 511 of file OSPFNeighbor.cc.

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;
}

Definition at line 447 of file OSPFNeighbor.cc.

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;
}

Definition at line 560 of file OSPFNeighbor.cc.

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::IsUpdateRetransmissionTimerActive ( void  ) const [inline]

Definition at line 184 of file OSPFNeighbor.h.

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

void OSPF::Neighbor::PopFirstLinkStateRequest ( void  ) [inline]

Definition at line 194 of file OSPFNeighbor.h.

{ linkStateRequestList.pop_front(); }

Definition at line 491 of file OSPFNeighbor.cc.

{
    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);
    }
}

Definition at line 432 of file OSPFNeighbor.cc.

Referenced by OSPF::LinkStateAcknowledgementHandler::ProcessPacket(), and OSPF::LinkStateUpdateHandler::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++;
        }
    }
}

Definition at line 584 of file OSPFNeighbor.cc.

Referenced by OSPF::NeighborStateExchange::ProcessEvent(), OSPF::NeighborStateLoading::ProcessEvent(), and OSPF::NeighborStateFull::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)

Definition at line 166 of file OSPFNeighbor.cc.

Referenced by OSPF::DatabaseDescriptionHandler::ProcessDDPacket(), OSPF::NeighborStateExchangeStart::ProcessEvent(), OSPF::NeighborStateLoading::ProcessEvent(), OSPF::NeighborStateInit::ProcessEvent(), OSPF::NeighborStateFull::ProcessEvent(), OSPF::NeighborStateTwoWay::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);
}

Definition at line 311 of file OSPFNeighbor.cc.

Referenced by OSPF::NeighborStateExchange::ProcessEvent(), OSPF::NeighborStateLoading::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::SetDDSequenceNumber ( unsigned long  sequenceNumber) [inline]

Definition at line 160 of file OSPFNeighbor.h.

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

{ neighborsDesignatedRouter = routerID; }
void OSPF::Neighbor::SetInterface ( Interface intf) [inline]

Definition at line 176 of file OSPFNeighbor.h.

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

{ parentInterface = intf; }

Definition at line 170 of file OSPFNeighbor.h.

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

{ lastReceivedDDPacket = packetID; }
void OSPF::Neighbor::SetNeighborID ( RouterID  id) [inline]

Definition at line 154 of file OSPFNeighbor.h.

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

{ neighborID = id; }
void OSPF::Neighbor::SetOptions ( OSPFOptions  options) [inline]

Definition at line 168 of file OSPFNeighbor.h.

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

{ neighborOptions = options; }
void OSPF::Neighbor::SetPriority ( unsigned char  priority) [inline]
void OSPF::Neighbor::SetRouterDeadInterval ( short  interval) [inline]

Definition at line 164 of file OSPFNeighbor.h.

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

void OSPF::Neighbor::SetUpDesignatedRouters ( bool  setUp) [inline]

Definition at line 188 of file OSPFNeighbor.h.

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


Friends And Related Function Documentation

friend class NeighborState [friend]

Definition at line 34 of file OSPFNeighbor.h.


Member Data Documentation

Definition at line 108 of file OSPFNeighbor.h.

Referenced by GetDatabaseSummaryListCount().

Definition at line 90 of file OSPFNeighbor.h.

Referenced by GetDDRetransmissionTimer(), and Neighbor().

unsigned long OSPF::Neighbor::ddSequenceNumber [private]
unsigned long OSPF::Neighbor::ddSequenceNumberInitSeed = 0 [static, private]

Definition at line 116 of file OSPFNeighbor.h.

Definition at line 96 of file OSPFNeighbor.h.

Referenced by IsFirstAdjacencyInited().

Definition at line 88 of file OSPFNeighbor.h.

Referenced by GetInactivityTimer(), and Neighbor().

Definition at line 107 of file OSPFNeighbor.h.

Referenced by IsLinkStateRetransmissionListEmpty().

Definition at line 99 of file OSPFNeighbor.h.

Referenced by GetNeighborID(), and SetNeighborID().

Definition at line 101 of file OSPFNeighbor.h.

Referenced by GetAddress(), and SetAddress().

Definition at line 102 of file OSPFNeighbor.h.

Referenced by GetOptions(), and SetOptions().

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

Definition at line 100 of file OSPFNeighbor.h.

Referenced by GetPriority(), and SetPriority().

Definition at line 113 of file OSPFNeighbor.h.

Referenced by GetInterface(), and SetInterface().

Definition at line 89 of file OSPFNeighbor.h.

Referenced by GetPollTimer(), and Neighbor().

Definition at line 87 of file OSPFNeighbor.h.

Referenced by Neighbor().

Definition at line 93 of file OSPFNeighbor.h.

Referenced by Neighbor().

Definition at line 86 of file OSPFNeighbor.h.

Referenced by Neighbor().

Definition at line 110 of file OSPFNeighbor.h.


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