INET Framework for OMNeT++/OMNEST
inet::ospfv2::Ospfv2 Class Reference

Implements the OSPFv2 routing protocol. More...

#include <Ospfv2.h>

Inheritance diagram for inet::ospfv2::Ospfv2:
inet::RoutingProtocolBase inet::OperationalBase inet::OperationalMixin< cSimpleModule > inet::ILifecycle

Public Member Functions

 Ospfv2 ()
 
virtual ~Ospfv2 ()
 
void insertExternalRoute (int ifIndex, const Ipv4AddressRange &netAddr)
 Insert a route learn by BGP in OSPF routingTable as an external route. More...
 
int checkExternalRoute (const Ipv4Address &route)
 Checks if the route is in OSPF external LSA Table. More...
 
- Public Member Functions inherited from inet::RoutingProtocolBase
 RoutingProtocolBase ()
 
- Public Member Functions inherited from inet::OperationalMixin< cSimpleModule >
virtual ~OperationalMixin ()
 }@ More...
 
- Public Member Functions inherited from inet::ILifecycle
virtual ~ILifecycle ()
 

Protected Member Functions

virtual int numInitStages () const override
 
virtual void initialize (int stage) override
 
virtual void handleMessageWhenUp (cMessage *msg) override
 
virtual void receiveSignal (cComponent *source, simsignal_t signalID, cObject *obj, cObject *details) override
 Listen on interface changes and update private data structures. More...
 
virtual void subscribe ()
 
virtual void unsubscribe ()
 
virtual void createOspfRouter ()
 
virtual void handleStartOperation (LifecycleOperation *operation) override
 
virtual void handleStopOperation (LifecycleOperation *operation) override
 
virtual void handleCrashOperation (LifecycleOperation *operation) override
 
void handleInterfaceDown (const NetworkInterface *ie)
 
- Protected Member Functions inherited from inet::RoutingProtocolBase
virtual bool isInitializeStage (int stage) const override
 
virtual bool isModuleStartStage (int stage) const override
 
virtual bool isModuleStopStage (int stage) const override
 
- Protected Member Functions inherited from inet::OperationalMixin< cSimpleModule >
virtual int numInitStages () const override
 
virtual void refreshDisplay () const override
 
virtual void handleMessage (cMessage *msg) override
 
virtual void handleMessageWhenDown (cMessage *msg)
 
virtual bool handleOperationStage (LifecycleOperation *operation, IDoneCallback *doneCallback) override
 Perform one stage of a lifecycle operation. More...
 
virtual State getInitialOperationalState () const
 Returns initial operational state: OPERATING or NOT_OPERATING. More...
 
virtual void handleActiveOperationTimeout (cMessage *message)
 
virtual bool isUp () const
 utility functions More...
 
virtual bool isDown () const
 
virtual void setOperationalState (State newState)
 
virtual void scheduleOperationTimeout (simtime_t timeout)
 
virtual void setupActiveOperation (LifecycleOperation *operation, IDoneCallback *doneCallback, State)
 
virtual void delayActiveOperationFinish (simtime_t timeout)
 
virtual void startActiveOperationExtraTime (simtime_t delay=SIMTIME_ZERO)
 
virtual void startActiveOperationExtraTimeOrFinish (simtime_t extraTime)
 
virtual void finishActiveOperation ()
 

Private Attributes

cModule * host = nullptr
 
ModuleRefByPar< IIpv4RoutingTablert
 
ModuleRefByPar< IInterfaceTableift
 
RouterospfRouter = nullptr
 
cMessage * startupTimer = nullptr
 

Additional Inherited Members

- Protected Types inherited from inet::OperationalMixin< cSimpleModule >
enum  State
 
- Protected Attributes inherited from inet::OperationalMixin< cSimpleModule >
State operationalState
 
simtime_t lastChange
 
Operation activeOperation
 
cMessage * activeOperationTimeout
 
cMessage * activeOperationExtraTimer
 

Detailed Description

Implements the OSPFv2 routing protocol.

See the NED file for more information.

Constructor & Destructor Documentation

◆ Ospfv2()

inet::ospfv2::Ospfv2::Ospfv2 ( )
29 {
30 }

◆ ~Ospfv2()

inet::ospfv2::Ospfv2::~Ospfv2 ( )
virtual
33 {
34  cancelAndDelete(startupTimer);
35  delete ospfRouter;
36 }

Member Function Documentation

◆ checkExternalRoute()

int inet::ospfv2::Ospfv2::checkExternalRoute ( const Ipv4Address route)

Checks if the route is in OSPF external LSA Table.

0: not external, 1: type 1 external, 2: type 2 external Used by the Bgp module.

177 {
178  Enter_Method("checkExternalRoute");
179  for (uint32_t i = 0; i < ospfRouter->getASExternalLSACount(); i++) {
180  AsExternalLsa *externalLSA = ospfRouter->getASExternalLSA(i);
181  Ipv4Address externalAddr = externalLSA->getHeader().getLinkStateID();
182  if (externalAddr == route) { // FIXME was this meant???
183  if (externalLSA->getContents().getExternalTOSInfo(0).E_ExternalMetricType)
184  return 2;
185  else
186  return 1;
187  }
188  }
189  return 0;
190 }

Referenced by inet::bgp::BgpRouter::checkExternalRoute().

◆ createOspfRouter()

void inet::ospfv2::Ospfv2::createOspfRouter ( )
protectedvirtual
65 {
66  ospfRouter = new Router(this, ift, rt);
67 
68  // read the OSPF AS configuration
69  cXMLElement *ospfConfig = par("ospfConfig");
70  Ospfv2ConfigReader configReader(this, ift);
71  if (!configReader.loadConfigFromXML(ospfConfig, ospfRouter))
72  throw cRuntimeError("Error reading AS configuration from %s", ospfConfig->getSourceLocation());
73 
75 }

Referenced by handleMessageWhenUp(), and handleStartOperation().

◆ handleCrashOperation()

void inet::ospfv2::Ospfv2::handleCrashOperation ( LifecycleOperation operation)
overrideprotectedvirtual

Implements inet::OperationalMixin< cSimpleModule >.

151 {
152  ASSERT(ospfRouter);
153  delete ospfRouter;
154  cancelEvent(startupTimer);
155  ospfRouter = nullptr;
156  unsubscribe();
157 }

◆ handleInterfaceDown()

void inet::ospfv2::Ospfv2::handleInterfaceDown ( const NetworkInterface ie)
protected
193 {
194  EV_DEBUG << "interface " << ie->getInterfaceId() << " went down. \n";
195 
196  // Step 1: delete all direct-routes connected to this interface
197 
198  // ... from OSPF table
199  for (uint32_t i = 0; i < ospfRouter->getRoutingTableEntryCount(); i++) {
200  Ospfv2RoutingTableEntry *ospfRoute = ospfRouter->getRoutingTableEntry(i);
201  if (ospfRoute && ospfRoute->getInterface() == ie && ospfRoute->getNextHopAsGeneric().isUnspecified()) {
202  EV_DEBUG << "removing route from OSPF routing table: " << ospfRoute << "\n";
203  ospfRouter->deleteRoute(ospfRoute);
204  i--;
205  }
206  }
207  // ... from Ipv4 table
208  for (int32_t i = 0; i < rt->getNumRoutes(); i++) {
209  Ipv4Route *route = rt->getRoute(i);
210  if (route && route->getInterface() == ie && route->getNextHopAsGeneric().isUnspecified()) {
211  EV_DEBUG << "removing route from Ipv4 routing table: " << route << "\n";
212  rt->deleteRoute(route);
213  i--;
214  }
215  }
216 
217  // Step 2: find the Ospfv2Interface associated with the ie and take it down
218  Ospfv2Interface *foundIntf = nullptr;
219  for (auto& areaId : ospfRouter->getAreaIds()) {
220  Ospfv2Area *area = ospfRouter->getAreaByID(areaId);
221  if (area) {
222  for (auto& ifIndex : area->getInterfaceIndices()) {
223  Ospfv2Interface *intf = area->getInterface(ifIndex);
224  if (intf && intf->getIfIndex() == ie->getInterfaceId()) {
225  foundIntf = intf;
226  break;
227  }
228  }
229  if (foundIntf) {
231  break;
232  }
233  }
234  }
235 }

Referenced by receiveSignal().

◆ handleMessageWhenUp()

void inet::ospfv2::Ospfv2::handleMessageWhenUp ( cMessage *  msg)
overrideprotectedvirtual

Implements inet::OperationalMixin< cSimpleModule >.

54 {
55  if (msg == startupTimer) {
57  subscribe();
58  }
59  else
61 
62 }

◆ handleStartOperation()

void inet::ospfv2::Ospfv2::handleStartOperation ( LifecycleOperation operation)
overrideprotectedvirtual

Implements inet::OperationalMixin< cSimpleModule >.

130 {
131  ASSERT(ospfRouter == nullptr);
132  simtime_t startupTime = par("startupTime");
133  if (startupTime <= simTime()) {
135  subscribe();
136  }
137  else
138  scheduleAfter(startupTime, startupTimer);
139 }

◆ handleStopOperation()

void inet::ospfv2::Ospfv2::handleStopOperation ( LifecycleOperation operation)
overrideprotectedvirtual

Implements inet::OperationalMixin< cSimpleModule >.

142 {
143  ASSERT(ospfRouter);
144  delete ospfRouter;
145  cancelEvent(startupTimer);
146  ospfRouter = nullptr;
147  unsubscribe();
148 }

◆ initialize()

void inet::ospfv2::Ospfv2::initialize ( int  stage)
overrideprotectedvirtual

Reimplemented from inet::OperationalMixin< cSimpleModule >.

39 {
41 
42  if (stage == INITSTAGE_LOCAL) {
43  host = getContainingNode(this);
44  ift.reference(this, "interfaceTableModule", true);
45  rt.reference(this, "routingTableModule", true);
46  startupTimer = new cMessage("OSPF-startup");
47  }
48  else if (stage == INITSTAGE_ROUTING_PROTOCOLS) { // interfaces and static routes are already initialized
49  registerProtocol(Protocol::ospf, gate("ipOut"), gate("ipIn"));
50  }
51 }

◆ insertExternalRoute()

void inet::ospfv2::Ospfv2::insertExternalRoute ( int  ifIndex,
const Ipv4AddressRange netAddr 
)

Insert a route learn by BGP in OSPF routingTable as an external route.

Used by the Bgp module. @ifIndex: interface ID

160 {
161  Enter_Method("insertExternalRoute");
162  Ospfv2AsExternalLsaContents newExternalContents;
163  newExternalContents.setExternalTOSInfoArraySize(1);
164  const Ipv4Address netmask = netAddr.mask;
165  newExternalContents.setNetworkMask(netmask);
166  auto& tosInfo = newExternalContents.getExternalTOSInfoForUpdate(0);
167  tosInfo.E_ExternalMetricType = false;
168  tosInfo.tos = 0;
169  tosInfo.externalRouteTag = OSPFv2_EXTERNAL_ROUTES_LEARNED_BY_BGP;
170 // tosInfo.forwardingAddress = ;
171  tosInfo.routeCost = OSPFv2_BGP_DEFAULT_COST;
172 
173  ospfRouter->updateExternalRoute(netAddr.address, newExternalContents, ifIndex);
174 }

Referenced by inet::bgp::BgpRouter::decisionProcess().

◆ numInitStages()

virtual int inet::ospfv2::Ospfv2::numInitStages ( ) const
inlineoverrideprotectedvirtual
54 { return NUM_INIT_STAGES; }

◆ receiveSignal()

void inet::ospfv2::Ospfv2::receiveSignal ( cComponent *  source,
simsignal_t  signalID,
cObject *  obj,
cObject *  details 
)
overrideprotectedvirtual

Listen on interface changes and update private data structures.

95 {
96  Enter_Method("%s", cComponent::getSignalName(signalID));
97 
98  const NetworkInterface *ie;
99  const NetworkInterfaceChangeDetails *change;
100 
101  if (signalID == interfaceCreatedSignal) {
102  // configure interface for RIP
103  ie = check_and_cast<const NetworkInterface *>(obj);
104  if (ie->isMulticast() && !ie->isLoopback()) {
105  // TODO
106  }
107  }
108  else if (signalID == interfaceDeletedSignal) {
109  ie = check_and_cast<const NetworkInterface *>(obj);
110  // TODO
111  }
112  else if (signalID == interfaceStateChangedSignal) {
113  change = check_and_cast<const NetworkInterfaceChangeDetails *>(obj);
114  auto fieldId = change->getFieldId();
115  if (fieldId == NetworkInterface::F_STATE || fieldId == NetworkInterface::F_CARRIER) {
116  ie = change->getNetworkInterface();
117  if (!ie->isUp())
119  else {
120  // interface went back online. Do nothing!
121  // Wait for Hello messages to establish adjacency.
122  }
123  }
124  }
125  else
126  throw cRuntimeError("Unexpected signal: %s", getSignalName(signalID));
127 }

◆ subscribe()

void inet::ospfv2::Ospfv2::subscribe ( )
protectedvirtual
78 {
79  host->subscribe(interfaceCreatedSignal, this);
80  host->subscribe(interfaceDeletedSignal, this);
81  host->subscribe(interfaceStateChangedSignal, this);
82 }

Referenced by handleMessageWhenUp(), and handleStartOperation().

◆ unsubscribe()

void inet::ospfv2::Ospfv2::unsubscribe ( )
protectedvirtual
85 {
86  host->unsubscribe(interfaceCreatedSignal, this);
87  host->unsubscribe(interfaceDeletedSignal, this);
88  host->unsubscribe(interfaceStateChangedSignal, this);
89 }

Referenced by handleCrashOperation(), and handleStopOperation().

Member Data Documentation

◆ host

cModule* inet::ospfv2::Ospfv2::host = nullptr
private

Referenced by initialize(), subscribe(), and unsubscribe().

◆ ift

ModuleRefByPar<IInterfaceTable> inet::ospfv2::Ospfv2::ift
private

Referenced by createOspfRouter(), and initialize().

◆ ospfRouter

◆ rt

ModuleRefByPar<IIpv4RoutingTable> inet::ospfv2::Ospfv2::rt
private

◆ startupTimer

cMessage* inet::ospfv2::Ospfv2::startupTimer = nullptr
private

The documentation for this class was generated from the following files:
OSPFv2_BGP_DEFAULT_COST
#define OSPFv2_BGP_DEFAULT_COST
Definition: Ospfv2Common.h:54
inet::ospfv2::Ospfv2Area::getInterface
Ospfv2Interface * getInterface(unsigned char ifIndex)
Definition: Ospfv2Area.cc:197
inet::NetworkInterface::F_STATE
@ F_STATE
Definition: NetworkInterface.h:146
inet::ospfv2::Ospfv2::rt
ModuleRefByPar< IIpv4RoutingTable > rt
Definition: Ospfv2.h:30
inet::ospfv2::Router::getASExternalLSA
AsExternalLsa * getASExternalLSA(unsigned long i)
Definition: Ospfv2Router.h:69
inet::ospfv2::Router::addWatches
void addWatches()
Adds OMNeT++ watches for the routerID, the list of Areas and the list of AS External LSAs.
Definition: Ospfv2Router.cc:48
inet::ospfv2::Ospfv2Interface::processEvent
void processEvent(Ospfv2InterfaceEventType event)
Definition: Ospfv2Interface.cc:153
inet::ospfv2::Ospfv2::createOspfRouter
virtual void createOspfRouter()
Definition: Ospfv2.cc:64
inet::getContainingNode
cModule * getContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:40
inet::OperationalMixin< cSimpleModule >::initialize
virtual void initialize(int stage) override
Definition: OperationalMixinImpl.h:26
inet::ospfv2::Router::getMessageHandler
MessageHandler * getMessageHandler()
Definition: Ospfv2Router.h:66
inet::ospfv2::Router::getASExternalLSACount
unsigned long getASExternalLSACount() const
Definition: Ospfv2Router.h:68
OSPFv2_EXTERNAL_ROUTES_LEARNED_BY_BGP
#define OSPFv2_EXTERNAL_ROUTES_LEARNED_BY_BGP
Definition: Ospfv2Common.h:53
inet::ospfv2::MessageHandler::messageReceived
void messageReceived(cMessage *message)
Definition: MessageHandler.cc:33
inet::ospfv2::Ospfv2::unsubscribe
virtual void unsubscribe()
Definition: Ospfv2.cc:84
inet::ospfv2::Ospfv2::ift
ModuleRefByPar< IInterfaceTable > ift
Definition: Ospfv2.h:31
inet::ospfv2::Router::deleteRoute
bool deleteRoute(Ospfv2RoutingTableEntry *entry)
Definition: Ospfv2Router.cc:776
inet::ospfv2::Ospfv2::ospfRouter
Router * ospfRouter
Definition: Ospfv2.h:32
inet::interfaceDeletedSignal
simsignal_t interfaceDeletedSignal
Definition: Simsignals.cc:31
inet::NetworkInterface::F_CARRIER
@ F_CARRIER
Definition: NetworkInterface.h:146
inet::ospfv2::Router::getAreaByID
Ospfv2Area * getAreaByID(AreaId areaID)
Returns the pointer to the Area identified by the input areaID, if it's on the Area list,...
Definition: Ospfv2Router.cc:63
inet::ospfv2::Router::updateExternalRoute
void updateExternalRoute(Ipv4Address networkAddress, const Ospfv2AsExternalLsaContents &externalRouteContents, int ifIndex=-1)
Stores information on an AS External Route in externalRoutes and intalls(or updates) a new AsExternal...
Definition: Ospfv2Router.cc:1356
inet::ospfv2::Router::getRoutingTableEntryCount
unsigned long getRoutingTableEntryCount() const
Definition: Ospfv2Router.h:73
inet::ospfv2::Ospfv2Interface::INTERFACE_DOWN
@ INTERFACE_DOWN
Definition: Ospfv2Interface.h:48
inet::interfaceStateChangedSignal
simsignal_t interfaceStateChangedSignal
Definition: Simsignals.cc:32
inet::INITSTAGE_LOCAL
INET_API InitStage INITSTAGE_LOCAL
Initialization of local state that don't use or affect other modules includes:
inet::ospfv2::Router::getAreaIds
std::vector< AreaId > getAreaIds()
Definition: Ospfv2Router.cc:81
NUM_INIT_STAGES
#define NUM_INIT_STAGES
Definition: InitStageRegistry.h:73
inet::ospfv2::Ospfv2::host
cModule * host
Definition: Ospfv2.h:29
inet::ospfv2::Router::getRoutingTableEntry
Ospfv2RoutingTableEntry * getRoutingTableEntry(unsigned long i)
Definition: Ospfv2Router.h:74
inet::ospfv2::Ospfv2::startupTimer
cMessage * startupTimer
Definition: Ospfv2.h:33
inet::Protocol::ospf
static const Protocol ospf
Definition: Protocol.h:102
Enter_Method
#define Enter_Method(...)
Definition: SelfDoc.h:71
inet::ospfv2::Ospfv2LsaHeader::getLinkStateID
virtual const ::inet::Ipv4Address & getLinkStateID() const
inet::interfaceCreatedSignal
simsignal_t interfaceCreatedSignal
Definition: Simsignals.cc:30
inet::registerProtocol
void registerProtocol(const Protocol &protocol, cGate *gate, ServicePrimitive servicePrimitive)
Registers a protocol primitive (PDU processing) at the given gate.
Definition: IProtocolRegistrationListener.cc:83
inet::ospfv2::Ospfv2Lsa::getHeader
virtual const Ospfv2LsaHeader & getHeader() const
inet::ospfv2::Ospfv2::subscribe
virtual void subscribe()
Definition: Ospfv2.cc:77
inet::ospfv2::Ospfv2::handleInterfaceDown
void handleInterfaceDown(const NetworkInterface *ie)
Definition: Ospfv2.cc:192
inet::INITSTAGE_ROUTING_PROTOCOLS
INET_API InitStage INITSTAGE_ROUTING_PROTOCOLS
Initialization of routing protocols.