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

#include <AnsaOSPFNeighbor.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 15 of file AnsaOSPFNeighbor.h.


Member Enumeration Documentation

Enumerator:
Master 
Slave 

Definition at line 51 of file AnsaOSPFNeighbor.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 20 of file AnsaOSPFNeighbor.h.

Enumerator:
DownState 
AttemptState 
InitState 
TwoWayState 
ExchangeStartState 
ExchangeState 
LoadingState 
FullState 

Definition at line 40 of file AnsaOSPFNeighbor.h.


Constructor & Destructor Documentation

Definition at line 12 of file AnsaOSPFNeighbor.cc.

                                            :
    updateRetransmissionTimerActive(false),
    requestRetransmissionTimerActive(false),
    firstAdjacencyInited(false),
    ddSequenceNumber(0),
    neighborID(neighbor),
    neighborPriority(0),
    neighborIPAddress(AnsaOSPF::NullIPv4Address),
    neighborsDesignatedRouter(AnsaOSPF::NullDesignatedRouterID),
    neighborsBackupDesignatedRouter(AnsaOSPF::NullDesignatedRouterID),
    designatedRoutersSetUp(false),
    neighborsRouterDeadInterval(40),
    lastTransmittedDDPacket(NULL)
{
    memset(&lastReceivedDDPacket, 0, sizeof(AnsaOSPF::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("AnsaOSPF::Neighbor::NeighborInactivityTimer");
    pollTimer = new OSPFTimer;
    pollTimer->setTimerKind(NeighborPollTimer);
    pollTimer->setContextPointer(this);
    pollTimer->setName("AnsaOSPF::Neighbor::NeighborPollTimer");
    ddRetransmissionTimer = new OSPFTimer;
    ddRetransmissionTimer->setTimerKind(NeighborDDRetransmissionTimer);
    ddRetransmissionTimer->setContextPointer(this);
    ddRetransmissionTimer->setName("AnsaOSPF::Neighbor::NeighborDDRetransmissionTimer");
    updateRetransmissionTimer = new OSPFTimer;
    updateRetransmissionTimer->setTimerKind(NeighborUpdateRetransmissionTimer);
    updateRetransmissionTimer->setContextPointer(this);
    updateRetransmissionTimer->setName("AnsaOSPF::Neighbor::Neighbor::NeighborUpdateRetransmissionTimer");
    requestRetransmissionTimer = new OSPFTimer;
    requestRetransmissionTimer->setTimerKind(NeighborRequestRetransmissionTimer);
    requestRetransmissionTimer->setContextPointer(this);
    requestRetransmissionTimer->setName("AnsaOSPF::Neighbor::NeighborRequestRetransmissionTimer");
    state = new AnsaOSPF::NeighborStateDown;
    previousState = NULL;
}
AnsaOSPF::Neighbor::~Neighbor ( void  ) [virtual]

Definition at line 54 of file AnsaOSPFNeighbor.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

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 376 of file AnsaOSPFNeighbor.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 533 of file AnsaOSPFNeighbor.cc.

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

{
    TransmittedLSA transmit;

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

    transmittedLSAs.push_back(transmit);
}

Definition at line 555 of file AnsaOSPFNeighbor.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 AnsaOSPF::Neighbor::ChangeState ( NeighborState newState,
NeighborState currentState 
) [private]

Definition at line 71 of file AnsaOSPFNeighbor.cc.

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

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

Definition at line 245 of file AnsaOSPFNeighbor.cc.

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

{
    AnsaOSPF::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() != AnsaOSPF::Interface::Virtual) &&
        (area->GetExternalRoutingCapability()))
    {
        AnsaOSPF::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 AnsaOSPF::Neighbor::DesignatedRoutersAreSetUp ( void  ) const [inline]

Definition at line 170 of file AnsaOSPFNeighbor.h.

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

Definition at line 507 of file AnsaOSPFNeighbor.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 443 of file AnsaOSPFNeighbor.cc.

Referenced by AnsaOSPF::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 AnsaOSPF::Neighbor::GetDatabaseSummaryListCount ( void  ) const [inline]

Definition at line 172 of file AnsaOSPFNeighbor.h.

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

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

Definition at line 150 of file AnsaOSPFNeighbor.h.

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

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

Definition at line 161 of file AnsaOSPFNeighbor.h.

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

Definition at line 152 of file AnsaOSPFNeighbor.h.

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

Definition at line 133 of file AnsaOSPFNeighbor.cc.

Referenced by AnsaOSPF::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 AnsaOSPF::Neighbor::GetUniqueULong ( void  )

Definition at line 122 of file AnsaOSPFNeighbor.cc.

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

Definition at line 494 of file AnsaOSPFNeighbor.cc.

Referenced by AnsaOSPF::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 430 of file AnsaOSPFNeighbor.cc.

Referenced by AnsaOSPF::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 543 of file AnsaOSPFNeighbor.cc.

Referenced by AnsaOSPF::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;
}

Definition at line 167 of file AnsaOSPFNeighbor.h.

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

Definition at line 177 of file AnsaOSPFNeighbor.h.

{ linkStateRequestList.pop_front(); }

Definition at line 474 of file AnsaOSPFNeighbor.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() == AnsaOSPF::Neighbor::LoadingState) && (linkStateRequestList.empty())) {
        ClearRequestRetransmissionTimer();
        ProcessEvent(AnsaOSPF::Neighbor::LoadingDone);
    }
}

Definition at line 415 of file AnsaOSPFNeighbor.cc.

Referenced by AnsaOSPF::LinkStateAcknowledgementHandler::ProcessPacket(), and AnsaOSPF::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 567 of file AnsaOSPFNeighbor.cc.

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

{
    OSPFLinkStateUpdatePacket* updatePacket = new OSPFLinkStateUpdatePacket;

    updatePacket->setType(LinkStateUpdatePacket);
    updatePacket->setRouterID(parentInterface->GetArea()->GetRouter()->GetRouterID());
    updatePacket->setAreaID(parentInterface->GetArea()->GetAreaID());
    updatePacket->setAuthenticationType(parentInterface->GetAuthenticationType());
    AnsaOSPF::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)

    AnsaOSPF::MessageHandler* messageHandler = parentInterface->GetArea()->GetRouter()->GetMessageHandler();
    int ttl = (parentInterface->GetType() == AnsaOSPF::Interface::Virtual) ? VIRTUAL_LINK_TTL : 1;
    messageHandler->SendPacket(updatePacket, neighborIPAddress, parentInterface->GetIfIndex(), ttl);
}

Definition at line 149 of file AnsaOSPFNeighbor.cc.

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

{
    OSPFDatabaseDescriptionPacket* ddPacket = new OSPFDatabaseDescriptionPacket;

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

    if (parentInterface->GetType() != AnsaOSPF::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 == AnsaOSPF::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)

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

    if (lastTransmittedDDPacket != NULL) {
        delete lastTransmittedDDPacket;
    }
    lastTransmittedDDPacket = new OSPFDatabaseDescriptionPacket(*ddPacket);
}

Definition at line 294 of file AnsaOSPFNeighbor.cc.

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

{
    OSPFLinkStateRequestPacket* requestPacket = new OSPFLinkStateRequestPacket;

    requestPacket->setType(LinkStateRequestPacket);
    requestPacket->setRouterID(parentInterface->GetArea()->GetRouter()->GetRouterID());
    requestPacket->setAreaID(parentInterface->GetArea()->GetAreaID());
    requestPacket->setAuthenticationType(parentInterface->GetAuthenticationType());
    AnsaOSPF::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)

    AnsaOSPF::MessageHandler* messageHandler = parentInterface->GetArea()->GetRouter()->GetMessageHandler();
    int ttl = (parentInterface->GetType() == AnsaOSPF::Interface::Virtual) ? VIRTUAL_LINK_TTL : 1;
    if (parentInterface->GetType() == AnsaOSPF::Interface::PointToPoint) {
        messageHandler->SendPacket(requestPacket, AnsaOSPF::AllSPFRouters, parentInterface->GetIfIndex(), ttl);
    } else {
        messageHandler->SendPacket(requestPacket, neighborIPAddress, parentInterface->GetIfIndex(), ttl);
    }
}
void AnsaOSPF::Neighbor::SetDDSequenceNumber ( unsigned long  sequenceNumber) [inline]
void AnsaOSPF::Neighbor::SetInterface ( Interface intf) [inline]

Definition at line 159 of file AnsaOSPFNeighbor.h.

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

{ parentInterface = intf; }
void AnsaOSPF::Neighbor::SetOptions ( OSPFOptions  options) [inline]

Definition at line 151 of file AnsaOSPFNeighbor.h.

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

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

Definition at line 147 of file AnsaOSPFNeighbor.h.

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

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

Definition at line 171 of file AnsaOSPFNeighbor.h.

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


Friends And Related Function Documentation

friend class NeighborState [friend]

Definition at line 17 of file AnsaOSPFNeighbor.h.


Member Data Documentation

Definition at line 91 of file AnsaOSPFNeighbor.h.

Referenced by GetDatabaseSummaryListCount().

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

Definition at line 99 of file AnsaOSPFNeighbor.h.

Definition at line 79 of file AnsaOSPFNeighbor.h.

Referenced by IsFirstAdjacencyInited().

Definition at line 71 of file AnsaOSPFNeighbor.h.

Referenced by GetInactivityTimer(), and Neighbor().

Definition at line 82 of file AnsaOSPFNeighbor.h.

Referenced by GetNeighborID(), and SetNeighborID().

Definition at line 84 of file AnsaOSPFNeighbor.h.

Referenced by GetAddress(), and SetAddress().

Definition at line 85 of file AnsaOSPFNeighbor.h.

Referenced by GetOptions(), and SetOptions().

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

Definition at line 83 of file AnsaOSPFNeighbor.h.

Referenced by GetPriority(), and SetPriority().

Definition at line 96 of file AnsaOSPFNeighbor.h.

Referenced by GetInterface(), and SetInterface().

Definition at line 72 of file AnsaOSPFNeighbor.h.

Referenced by GetPollTimer(), and Neighbor().

Definition at line 70 of file AnsaOSPFNeighbor.h.

Referenced by Neighbor().

Definition at line 76 of file AnsaOSPFNeighbor.h.

Referenced by Neighbor().

Definition at line 69 of file AnsaOSPFNeighbor.h.

Referenced by Neighbor().

Definition at line 93 of file AnsaOSPFNeighbor.h.


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