INET Framework for OMNeT++/OMNEST
inet::ospf::NeighborState Class Referenceabstract

#include <OSPFNeighborState.h>

Inheritance diagram for inet::ospf::NeighborState:
inet::ospf::NeighborStateAttempt inet::ospf::NeighborStateDown inet::ospf::NeighborStateExchange inet::ospf::NeighborStateExchangeStart inet::ospf::NeighborStateFull inet::ospf::NeighborStateInit inet::ospf::NeighborStateLoading inet::ospf::NeighborStateTwoWay

Public Member Functions

virtual ~NeighborState ()
 
virtual void processEvent (Neighbor *neighbor, Neighbor::NeighborEventType event)=0
 
virtual Neighbor::NeighborStateType getState () const =0
 

Protected Member Functions

void changeState (Neighbor *neighbor, NeighborState *newState, NeighborState *currentState)
 

Constructor & Destructor Documentation

virtual inet::ospf::NeighborState::~NeighborState ( )
inlinevirtual
34 {}

Member Function Documentation

void inet::ospf::NeighborState::changeState ( Neighbor neighbor,
NeighborState newState,
NeighborState currentState 
)
protected

Referenced by inet::ospf::NeighborStateAttempt::processEvent(), inet::ospf::NeighborStateTwoWay::processEvent(), inet::ospf::NeighborStateLoading::processEvent(), inet::ospf::NeighborStateInit::processEvent(), inet::ospf::NeighborStateFull::processEvent(), inet::ospf::NeighborStateExchangeStart::processEvent(), inet::ospf::NeighborStateExchange::processEvent(), and inet::ospf::NeighborStateDown::processEvent().

29 {
30  Neighbor::NeighborStateType oldState = currentState->getState();
31  Neighbor::NeighborStateType nextState = newState->getState();
32  bool shouldRebuildRoutingTable = false;
33 
34  neighbor->changeState(newState, currentState);
35 
36  if ((oldState == Neighbor::FULL_STATE) || (nextState == Neighbor::FULL_STATE)) {
37  RouterID routerID = neighbor->getInterface()->getArea()->getRouter()->getRouterID();
38  RouterLSA *routerLSA = neighbor->getInterface()->getArea()->findRouterLSA(routerID);
39 
40  if (routerLSA != nullptr) {
41  long sequenceNumber = routerLSA->getHeader().getLsSequenceNumber();
42  if (sequenceNumber == MAX_SEQUENCE_NUMBER) {
43  routerLSA->getHeader().setLsAge(MAX_AGE);
44  neighbor->getInterface()->getArea()->floodLSA(routerLSA);
45  routerLSA->incrementInstallTime();
46  }
47  else {
48  RouterLSA *newLSA = neighbor->getInterface()->getArea()->originateRouterLSA();
49 
50  newLSA->getHeader().setLsSequenceNumber(sequenceNumber + 1);
51  shouldRebuildRoutingTable |= routerLSA->update(newLSA);
52  delete newLSA;
53 
54  neighbor->getInterface()->getArea()->floodLSA(routerLSA);
55  }
56  }
57 
58  if (neighbor->getInterface()->getState() == Interface::DESIGNATED_ROUTER_STATE) {
59  NetworkLSA *networkLSA = neighbor->getInterface()->getArea()->findNetworkLSA(neighbor->getInterface()->getAddressRange().address);
60 
61  if (networkLSA != nullptr) {
62  long sequenceNumber = networkLSA->getHeader().getLsSequenceNumber();
63  if (sequenceNumber == MAX_SEQUENCE_NUMBER) {
64  networkLSA->getHeader().setLsAge(MAX_AGE);
65  neighbor->getInterface()->getArea()->floodLSA(networkLSA);
66  networkLSA->incrementInstallTime();
67  }
68  else {
69  NetworkLSA *newLSA = neighbor->getInterface()->getArea()->originateNetworkLSA(neighbor->getInterface());
70 
71  if (newLSA != nullptr) {
72  newLSA->getHeader().setLsSequenceNumber(sequenceNumber + 1);
73  shouldRebuildRoutingTable |= networkLSA->update(newLSA);
74  delete newLSA;
75  }
76  else { // no neighbors on the network -> old NetworkLSA must be flushed
77  networkLSA->getHeader().setLsAge(MAX_AGE);
78  networkLSA->incrementInstallTime();
79  }
80 
81  neighbor->getInterface()->getArea()->floodLSA(networkLSA);
82  }
83  }
84  }
85  }
86 
87  if (shouldRebuildRoutingTable) {
88  neighbor->getInterface()->getArea()->getRouter()->rebuildRoutingTable();
89  }
90 }
NeighborStateType
Definition: OSPFNeighbor.h:61
#define MAX_SEQUENCE_NUMBER
Definition: OSPFcommon.h:43
#define MAX_AGE
Definition: OSPFcommon.h:36
Definition: OSPFNeighbor.h:69
IPv4Address RouterID
Definition: OSPFcommon.h:137

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