INET Framework for OMNeT++/OMNEST
inet::ospf::OSPFRouting Class Reference

Implements the OSPFv2 routing protocol. More...

#include <OSPFRouting.h>

Inheritance diagram for inet::ospf::OSPFRouting:
inet::ILifecycle

Public Member Functions

 OSPFRouting ()
 
virtual ~OSPFRouting ()
 
void insertExternalRoute (int ifIndex, const IPv4AddressRange &netAddr)
 Insert a route learn by BGP in OSPF routingTable as an external route. More...
 
bool checkExternalRoute (const IPv4Address &route)
 Return true if the route is in OSPF external LSA Table, false else. 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 handleMessage (cMessage *msg) override
 
virtual void handleMessageWhenDown (cMessage *msg)
 
virtual bool handleOperationStage (LifecycleOperation *operation, int stage, IDoneCallback *doneCallback) override
 Perform one stage of a lifecycle operation. More...
 
virtual void createOspfRouter ()
 
virtual bool isNodeUp ()
 

Private Attributes

IIPv4RoutingTablert = nullptr
 
IInterfaceTableift = nullptr
 
bool isUp = false
 
RouterospfRouter = nullptr
 

Detailed Description

Implements the OSPFv2 routing protocol.

See the NED file for more information.

Constructor & Destructor Documentation

inet::ospf::OSPFRouting::OSPFRouting ( )
40 {
41 }
inet::ospf::OSPFRouting::~OSPFRouting ( )
virtual
44 {
45  delete ospfRouter;
46 }
Router * ospfRouter
Definition: OSPFRouting.h:44

Member Function Documentation

bool inet::ospf::OSPFRouting::checkExternalRoute ( const IPv4Address route)

Return true if the route is in OSPF external LSA Table, false else.

Used by the BGPRouting module.

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

144 {
145  Enter_Method_Silent();
146  for (unsigned long i = 1; i < ospfRouter->getASExternalLSACount(); i++) {
147  ASExternalLSA *externalLSA = ospfRouter->getASExternalLSA(i);
148  IPv4Address externalAddr = externalLSA->getHeader().getLinkStateID();
149  if (externalAddr == route) //FIXME was this meant???
150  return true;
151  }
152  return false;
153 }
unsigned long getASExternalLSACount() const
Definition: OSPFRouter.h:79
ASExternalLSA * getASExternalLSA(unsigned long i)
Definition: OSPFRouter.h:80
Router * ospfRouter
Definition: OSPFRouting.h:44
virtual IPv4Address & getLinkStateID()
virtual OSPFLSAHeader & getHeader()
void inet::ospf::OSPFRouting::createOspfRouter ( )
protectedvirtual

Referenced by handleOperationStage(), initialize(), and numInitStages().

65 {
66  ospfRouter = new Router(rt->getRouterId(), this, ift, rt);
67 
68  // read the OSPF AS configuration
69  cXMLElement *ospfConfig = par("ospfConfig").xmlValue();
70  OSPFConfigReader configReader(this, ift);
71  if (!configReader.loadConfigFromXML(ospfConfig, ospfRouter))
72  throw cRuntimeError("Error reading AS configuration from %s", ospfConfig->getSourceLocation());
73 
75 }
IInterfaceTable * ift
Definition: OSPFRouting.h:42
void addWatches()
Adds OMNeT++ watches for the routerID, the list of Areas and the list of AS External LSAs...
Definition: OSPFRouter.cc:57
IIPv4RoutingTable * rt
Definition: OSPFRouting.h:41
virtual IPv4Address getRouterId() const =0
Returns routerId.
Router * ospfRouter
Definition: OSPFRouting.h:44
void inet::ospf::OSPFRouting::handleMessage ( cMessage *  msg)
overrideprotectedvirtual

Referenced by numInitStages().

78 {
79  if (!isUp)
81  else
83 }
void messageReceived(cMessage *message)
Definition: MessageHandler.cc:38
virtual void handleMessageWhenDown(cMessage *msg)
Definition: OSPFRouting.cc:85
Router * ospfRouter
Definition: OSPFRouting.h:44
MessageHandler * getMessageHandler()
Definition: OSPFRouter.h:77
bool isUp
Definition: OSPFRouting.h:43
void inet::ospf::OSPFRouting::handleMessageWhenDown ( cMessage *  msg)
protectedvirtual

Referenced by handleMessage(), and numInitStages().

86 {
87  if (msg->isSelfMessage())
88  throw cRuntimeError("Model error: self msg '%s' received when protocol is down", msg->getName());
89  EV_ERROR << "Protocol is turned off, dropping '" << msg->getName() << "' message\n";
90  delete msg;
91 }
bool inet::ospf::OSPFRouting::handleOperationStage ( LifecycleOperation operation,
int  stage,
IDoneCallback doneCallback 
)
overrideprotectedvirtual

Perform one stage of a lifecycle operation.

Processing may be done entirely within this method, or may be a longer process that involves nonzero simulation time or several events, and is triggered by this method call.

Return value: true = "done"; false = "not yet done, will invoke doneCallback when done"

Implements inet::ILifecycle.

Referenced by numInitStages().

94 {
95  Enter_Method_Silent();
96 
97  if (dynamic_cast<NodeStartOperation *>(operation)) {
99  ASSERT(ospfRouter == nullptr);
100  isUp = true;
102  }
103  }
104  else if (dynamic_cast<NodeShutdownOperation *>(operation)) {
106  ASSERT(ospfRouter);
107  isUp = false;
108  delete ospfRouter;
109  ospfRouter = nullptr;
110  }
111  }
112  else if (dynamic_cast<NodeCrashOperation *>(operation)) {
114  ASSERT(ospfRouter);
115  isUp = false;
116  delete ospfRouter;
117  ospfRouter = nullptr;
118  }
119  }
120  else {
121  throw cRuntimeError("Unsupported operation '%s'", operation->getClassName());
122  }
123  return true;
124 }
Stage
Definition: NodeOperations.h:71
Stage
Definition: NodeOperations.h:126
virtual void createOspfRouter()
Definition: OSPFRouting.cc:64
Router * ospfRouter
Definition: OSPFRouting.h:44
Stage
Definition: NodeOperations.h:46
bool isUp
Definition: OSPFRouting.h:43
Definition: NodeOperations.h:127
void inet::ospf::OSPFRouting::initialize ( int  stage)
overrideprotectedvirtual

Referenced by numInitStages().

49 {
50  cSimpleModule::initialize(stage);
51 
52  if (stage == INITSTAGE_ROUTING_PROTOCOLS) {
53  ift = getModuleFromPar<IInterfaceTable>(par("interfaceTableModule"), this);
54  rt = getModuleFromPar<IIPv4RoutingTable>(par("routingTableModule"), this);
55  IPSocket ipSocket(gate("ipOut"));
56  ipSocket.registerProtocol(IP_PROT_OSPF);
57 
58  isUp = isNodeUp();
59  if (isUp)
61  }
62 }
IInterfaceTable * ift
Definition: OSPFRouting.h:42
IIPv4RoutingTable * rt
Definition: OSPFRouting.h:41
Initialization of routing protocols.
Definition: InitStages.h:101
virtual void createOspfRouter()
Definition: OSPFRouting.cc:64
Definition: IPProtocolId_m.h:89
virtual bool isNodeUp()
Definition: OSPFRouting.cc:126
bool isUp
Definition: OSPFRouting.h:43
void inet::ospf::OSPFRouting::insertExternalRoute ( int  ifIndex,
const IPv4AddressRange netAddr 
)

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

Used by the BGPRouting module. : interface ID

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

133 {
134  Enter_Method_Silent();
135  OSPFASExternalLSAContents newExternalContents;
136  newExternalContents.setRouteCost(OSPF_BGP_DEFAULT_COST);
137  newExternalContents.setExternalRouteTag(OSPF_EXTERNAL_ROUTES_LEARNED_BY_BGP);
138  const IPv4Address netmask = netAddr.mask;
139  newExternalContents.setNetworkMask(netmask);
140  ospfRouter->updateExternalRoute(netAddr.address, newExternalContents, ifIndex);
141 }
#define OSPF_BGP_DEFAULT_COST
Definition: OSPFcommon.h:62
#define OSPF_EXTERNAL_ROUTES_LEARNED_BY_BGP
Definition: OSPFcommon.h:61
void updateExternalRoute(IPv4Address networkAddress, const OSPFASExternalLSAContents &externalRouteContents, int ifIndex)
Stores information on an AS External Route in externalRoutes and intalls(or updates) a new ASExternal...
Definition: OSPFRouter.cc:1322
Router * ospfRouter
Definition: OSPFRouting.h:44
bool inet::ospf::OSPFRouting::isNodeUp ( )
protectedvirtual

Referenced by initialize(), and numInitStages().

127 {
128  NodeStatus *nodeStatus = dynamic_cast<NodeStatus *>(findContainingNode(this)->getSubmodule("status"));
129  return !nodeStatus || nodeStatus->getState() == NodeStatus::UP;
130 }
cModule * findContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:56
Definition: NodeStatus.h:40
virtual int inet::ospf::OSPFRouting::numInitStages ( ) const
inlineoverrideprotectedvirtual
64 { return NUM_INIT_STAGES; }
The number of initialization stages.
Definition: InitStages.h:116

Member Data Documentation

IInterfaceTable* inet::ospf::OSPFRouting::ift = nullptr
private

Referenced by createOspfRouter(), and initialize().

bool inet::ospf::OSPFRouting::isUp = false
private
Router* inet::ospf::OSPFRouting::ospfRouter = nullptr
private
IIPv4RoutingTable* inet::ospf::OSPFRouting::rt = nullptr
private

Referenced by createOspfRouter(), and initialize().


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