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

Configuration reader for the OSPF module. More...

#include <OSPFConfigReader.h>

Public Member Functions

 OSPFConfigReader (cModule *ospfModule, IInterfaceTable *ift)
 
virtual ~OSPFConfigReader ()
 
bool loadConfigFromXML (cXMLElement *asConfig, Router *ospfRouter)
 Loads the configuration of the OSPF data structure from the config XML. More...
 

Private Member Functions

cPar & par (const char *name) const
 
int getIntAttrOrPar (const cXMLElement &ifConfig, const char *name) const
 
bool getBoolAttrOrPar (const cXMLElement &ifConfig, const char *name) const
 
const char * getStrAttrOrPar (const cXMLElement &ifConfig, const char *name) const
 
int resolveInterfaceName (const std::string &name) const
 Looks up the interface name in IInterfaceTable, and returns interfaceId a.k.a ifIndex. More...
 
InterfaceEntrygetInterfaceByXMLAttributesOf (const cXMLElement &ifConfig)
 Search an InterfaceEntry in IInterfaceTable by interface name or toward module name an returns the InterfaceEntry pointer or throws an error. More...
 
void getAreaListFromXML (const cXMLElement &routerNode, std::set< AreaID > &areaList) const
 Loads a list of OSPF Areas connected to this router from the config XML. More...
 
void loadAreaFromXML (const cXMLElement &asConfig, AreaID areaID)
 Loads basic configuration information for a given area from the config XML. More...
 
void loadAuthenticationConfig (Interface *intf, const cXMLElement &ifConfig)
 Loads authenticationType and authenticationKey attributes for a router interface. More...
 
void loadInterfaceParameters (const cXMLElement &ifConfig)
 Loads OSPF configuration information for a router interface. More...
 
void loadExternalRoute (const cXMLElement &externalRouteConfig)
 Loads the configuration information of a route outside of the Autonomous System (external route). More...
 
void loadHostRoute (const cXMLElement &hostRouteConfig)
 Loads the configuration of a host route (a host directly connected to the router). More...
 
void loadVirtualLink (const cXMLElement &virtualLinkConfig)
 Loads the configuration of an OSPf virtual link (virtual connection between two backbone routers). More...
 
void joinMulticastGroups (int interfaceId)
 

Private Attributes

cModule * ospfModule = nullptr
 
IInterfaceTableift = nullptr
 
RouterospfRouter = nullptr
 

Detailed Description

Configuration reader for the OSPF module.

Constructor & Destructor Documentation

inet::ospf::OSPFConfigReader::OSPFConfigReader ( cModule *  ospfModule,
IInterfaceTable ift 
)
44  :
46 {
47 }
cModule * ospfModule
Definition: OSPFConfigReader.h:40
IInterfaceTable * ift
Definition: OSPFConfigReader.h:41
inet::ospf::OSPFConfigReader::~OSPFConfigReader ( )
virtual
50 {
51 }

Member Function Documentation

void inet::ospf::OSPFConfigReader::getAreaListFromXML ( const cXMLElement &  routerNode,
std::set< AreaID > &  areaList 
) const
private

Loads a list of OSPF Areas connected to this router from the config XML.

Parameters
routerNode[in] XML node describing this router.
areaList[out] A set of OSPF Areas connected to this router.

Referenced by loadConfigFromXML().

90 {
91  cXMLElementList routerConfig = routerNode.getChildren();
92  for (auto & elem : routerConfig) {
93  std::string nodeName = (elem)->getTagName();
94  if ((nodeName == "PointToPointInterface") ||
95  (nodeName == "BroadcastInterface") ||
96  (nodeName == "NBMAInterface") ||
97  (nodeName == "PointToMultiPointInterface"))
98  {
99  AreaID areaID = IPv4Address(getStrAttrOrPar(*elem, "areaID"));
100  if (areaList.find(areaID) == areaList.end())
101  areaList.insert(areaID);
102  }
103  }
104 }
IPv4Address AreaID
Definition: OSPFcommon.h:138
const char * getStrAttrOrPar(const cXMLElement &ifConfig, const char *name) const
Definition: OSPFConfigReader.cc:166
bool inet::ospf::OSPFConfigReader::getBoolAttrOrPar ( const cXMLElement &  ifConfig,
const char *  name 
) const
private

Referenced by loadConfigFromXML().

154 {
155  const char *attrStr = ifConfig.getAttribute(name);
156  if (attrStr && *attrStr) {
157  if (strcmp(attrStr, "true") == 0 || strcmp(attrStr, "1") == 0)
158  return true;
159  if (strcmp(attrStr, "false") == 0 || strcmp(attrStr, "0") == 0)
160  return false;
161  throw cRuntimeError("Invalid boolean attribute %s = '%s' at %s", name, attrStr, ifConfig.getSourceLocation());
162  }
163  return par(name).boolValue();
164 }
cPar & par(const char *name) const
Definition: OSPFConfigReader.h:45
int inet::ospf::OSPFConfigReader::getIntAttrOrPar ( const cXMLElement &  ifConfig,
const char *  name 
) const
private

Referenced by loadExternalRoute(), loadHostRoute(), loadInterfaceParameters(), and loadVirtualLink().

146 {
147  const char *attrStr = ifConfig.getAttribute(name);
148  if (attrStr && *attrStr)
149  return atoi(attrStr);
150  return par(name).longValue();
151 }
cPar & par(const char *name) const
Definition: OSPFConfigReader.h:45
InterfaceEntry * inet::ospf::OSPFConfigReader::getInterfaceByXMLAttributesOf ( const cXMLElement &  ifConfig)
private

Search an InterfaceEntry in IInterfaceTable by interface name or toward module name an returns the InterfaceEntry pointer or throws an error.

Referenced by loadExternalRoute(), loadHostRoute(), and loadInterfaceParameters().

54 {
55  const char *ifName = ifConfig.getAttribute("ifName");
56  if (ifName && *ifName) {
57  InterfaceEntry *ie = ift->getInterfaceByName(ifName);
58  if (!ie)
59  throw cRuntimeError("Error reading XML config: IInterfaceTable contains no interface named '%s' at %s", ifName, ifConfig.getSourceLocation());
60  return ie;
61  }
62 
63  const char *toward = getRequiredAttribute(ifConfig, "toward");
64  cModule *destnode = getSimulation()->getSystemModule()->getModuleByPath(toward);
65  if (!destnode)
66  throw cRuntimeError("toward module `%s' not found at %s", toward, ifConfig.getSourceLocation());
67 
68  cModule *host = ift->getHostModule();
69  for (int i = 0; i < ift->getNumInterfaces(); i++) {
70  InterfaceEntry *ie = ift->getInterface(i);
71  if (ie) {
72  int gateId = ie->getNodeOutputGateId();
73  if ((gateId != -1) && (host->gate(gateId)->pathContains(destnode)))
74  return ie;
75  }
76  }
77  throw cRuntimeError("Error reading XML config: IInterfaceTable contains no interface toward '%s' at %s", toward, ifConfig.getSourceLocation());
78 }
virtual cModule * getHostModule() const =0
Returns the host or router this interface table lives in.
virtual InterfaceEntry * getInterfaceByName(const char *name) const =0
Returns an interface given by its name.
const char * getRequiredAttribute(const cXMLElement &node, const char *attr)
Definition: XMLUtils.cc:150
int getNodeOutputGateId() const
Definition: InterfaceEntry.h:188
IInterfaceTable * ift
Definition: OSPFConfigReader.h:41
virtual int getNumInterfaces() const =0
Returns the number of interfaces.
virtual InterfaceEntry * getInterface(int pos) const =0
Returns the InterfaceEntry specified by an index 0..numInterfaces-1.
const char * inet::ospf::OSPFConfigReader::getStrAttrOrPar ( const cXMLElement &  ifConfig,
const char *  name 
) const
private

Referenced by getAreaListFromXML(), loadAuthenticationConfig(), loadExternalRoute(), loadHostRoute(), and loadInterfaceParameters().

167 {
168  const char *attrStr = ifConfig.getAttribute(name);
169  if (attrStr && *attrStr)
170  return attrStr;
171  return par(name).stringValue();
172 }
cPar & par(const char *name) const
Definition: OSPFConfigReader.h:45
void inet::ospf::OSPFConfigReader::joinMulticastGroups ( int  interfaceId)
private

Referenced by loadExternalRoute(), loadHostRoute(), and loadInterfaceParameters().

175 {
176  InterfaceEntry *ie = ift->getInterfaceById(interfaceId);
177  if (!ie)
178  throw cRuntimeError("Interface id=%d does not exist", interfaceId);
179  if (!ie->isMulticast())
180  return;
181  IPv4InterfaceData *ipv4Data = ie->ipv4Data();
182  if (!ipv4Data)
183  throw cRuntimeError("Interface %s (id=%d) does not have IPv4 data", ie->getName(), interfaceId);
184  ipv4Data->joinMulticastGroup(IPv4Address::ALL_OSPF_ROUTERS_MCAST);
185  ipv4Data->joinMulticastGroup(IPv4Address::ALL_OSPF_DESIGNATED_ROUTERS_MCAST);
186 }
virtual InterfaceEntry * getInterfaceById(int id) const =0
Returns an interface by its Id.
IInterfaceTable * ift
Definition: OSPFConfigReader.h:41
static const IPv4Address ALL_OSPF_DESIGNATED_ROUTERS_MCAST
224.0.0.6 All OSPF Designated Routers
Definition: IPv4Address.h:111
static const IPv4Address ALL_OSPF_ROUTERS_MCAST
224.0.0.5 All OSPF routers (DR Others)
Definition: IPv4Address.h:110
void inet::ospf::OSPFConfigReader::loadAreaFromXML ( const cXMLElement &  asConfig,
AreaID  areaID 
)
private

Loads basic configuration information for a given area from the config XML.

Reads the configured address ranges, and whether this Area should be handled as a stub Area.

Referenced by loadConfigFromXML().

107 {
108  std::string areaXPath("Area[@id='");
109  areaXPath += areaID.str(false);
110  areaXPath += "']";
111 
112  cXMLElement *areaConfig = asConfig.getElementByPath(areaXPath.c_str());
113  if (areaConfig == nullptr) {
114  throw cRuntimeError("No configuration for Area ID: %s at %s", areaID.str(false).c_str(), asConfig.getSourceLocation());
115  }
116  else {
117  EV_DEBUG << " loading info for Area id = " << areaID.str(false) << "\n";
118  }
119 
120  Area *area = new Area(ift, areaID);
121  cXMLElementList areaDetails = areaConfig->getChildren();
122  for (auto & areaDetail : areaDetails) {
123  std::string nodeName = (areaDetail)->getTagName();
124  if (nodeName == "AddressRange") {
125  IPv4AddressRange addressRange;
126  addressRange.address = ipv4AddressFromAddressString(getRequiredAttribute(*areaDetail, "address"));
127  addressRange.mask = ipv4NetmaskFromAddressString(getRequiredAttribute(*areaDetail, "mask"));
128  addressRange.address = addressRange.address & addressRange.mask;
129  std::string status = getRequiredAttribute(*areaDetail, "status");
130  area->addAddressRange(addressRange, status == "Advertise");
131  }
132  else if (nodeName == "Stub") {
133  if (areaID == BACKBONE_AREAID)
134  throw cRuntimeError("The backbone cannot be configured as a stub at %s", (areaDetail)->getSourceLocation());
135  area->setExternalRoutingCapability(false);
136  area->setStubDefaultCost(atoi(getRequiredAttribute(*areaDetail, "defaultCost")));
137  }
138  else
139  throw cRuntimeError("Invalid node '%s' at %s", nodeName.c_str(), (areaDetail)->getSourceLocation());
140  }
141  // Add the Area to the router
142  ospfRouter->addArea(area);
143 }
void addArea(Area *area)
Adds a new Area to the Area list.
Definition: OSPFRouter.cc:65
const char * getRequiredAttribute(const cXMLElement &node, const char *attr)
Definition: XMLUtils.cc:150
const AreaID BACKBONE_AREAID(0, 0, 0, 0)
IInterfaceTable * ift
Definition: OSPFConfigReader.h:41
IPv4Address ipv4NetmaskFromAddressString(const char *charForm)
Definition: OSPFcommon.h:210
IPv4Address ipv4AddressFromAddressString(const char *charForm)
Definition: OSPFcommon.h:205
Router * ospfRouter
Definition: OSPFConfigReader.h:42
void inet::ospf::OSPFConfigReader::loadAuthenticationConfig ( Interface intf,
const cXMLElement &  ifConfig 
)
private

Loads authenticationType and authenticationKey attributes for a router interface.

Referenced by loadInterfaceParameters(), and loadVirtualLink().

189 {
190  std::string authenticationType = getStrAttrOrPar(ifConfig, "authenticationType");
191  if (authenticationType == "SimplePasswordType") {
192  intf->setAuthenticationType(SIMPLE_PASSWORD_TYPE);
193  }
194  else if (authenticationType == "CrytographicType") {
195  intf->setAuthenticationType(CRYTOGRAPHIC_TYPE);
196  }
197  else if (authenticationType == "NullType") {
198  intf->setAuthenticationType(NULL_TYPE);
199  }
200  else {
201  throw cRuntimeError("Invalid AuthenticationType '%s' at %s", authenticationType.c_str(), ifConfig.getSourceLocation());
202  }
203 
204  std::string key = getStrAttrOrPar(ifConfig, "authenticationKey");
205  AuthenticationKeyType keyValue;
206  memset(keyValue.bytes, 0, sizeof(keyValue.bytes));
207  int keyLength = key.length();
208  if ((keyLength > 4) && (keyLength <= 18) && (keyLength % 2 == 0) && (key[0] == '0') && (key[1] == 'x')) {
209  for (int i = keyLength; (i > 2); i -= 2) {
210  keyValue.bytes[(i - 2) / 2 - 1] = hexPairToByte(key[i - 1], key[i]);
211  }
212  }
213  intf->setAuthenticationKey(keyValue);
214 }
Definition: OSPFcommon.h:68
Definition: OSPFcommon.h:69
Definition: OSPFcommon.h:67
const char * getStrAttrOrPar(const cXMLElement &ifConfig, const char *name) const
Definition: OSPFConfigReader.cc:166
char hexPairToByte(char upperHex, char lowerHex)
Definition: OSPFcommon.h:291
bool inet::ospf::OSPFConfigReader::loadConfigFromXML ( cXMLElement *  asConfig,
Router ospfRouter 
)

Loads the configuration of the OSPF data structure from the config XML.

Returns true if the configuration was successfully loaded.

Referenced by inet::ospf::OSPFRouting::createOspfRouter().

426 {
427  this->ospfRouter = ospfRouter;
428 
429  if (strcmp(asConfig->getTagName(), "OSPFASConfig"))
430  throw cRuntimeError("Cannot read OSPF configuration, unexpected element '%s' at %s", asConfig->getTagName(), asConfig->getSourceLocation());
431 
432  cModule *myNode = findContainingNode(ospfModule);
433 
434  ASSERT(myNode);
435  std::string nodeFullPath = myNode->getFullPath();
436  std::string nodeShortenedFullPath = nodeFullPath.substr(nodeFullPath.find('.') + 1);
437 
438  // load information on this router
439  cXMLElementList routers = asConfig->getElementsByTagName("Router");
440  cXMLElement *routerNode = nullptr;
441  for (auto & router : routers) {
442  const char *nodeName = getRequiredAttribute(*(router), "name");
443  inet::PatternMatcher pattern(nodeName, true, true, true);
444  if (pattern.matches(nodeFullPath.c_str()) || pattern.matches(nodeShortenedFullPath.c_str())) { // match Router@name and fullpath of my node
445  routerNode = router;
446  break;
447  }
448  }
449  if (routerNode == nullptr) {
450  throw cRuntimeError("No configuration for Router '%s' at '%s'", nodeFullPath.c_str(), asConfig->getSourceLocation());
451  }
452 
453  EV_DEBUG << "OSPFConfigReader: Loading info for Router " << nodeFullPath << "\n";
454 
455  bool rfc1583Compatible = getBoolAttrOrPar(*routerNode, "RFC1583Compatible");
456  ospfRouter->setRFC1583Compatibility(rfc1583Compatible);
457 
458  std::set<AreaID> areaList;
459  getAreaListFromXML(*routerNode, areaList);
460 
461  // if the router is an area border router then it MUST be part of the backbone(area 0)
462  if ((areaList.size() > 1) && (areaList.find(BACKBONE_AREAID) == areaList.end())) {
463  areaList.insert(BACKBONE_AREAID);
464  }
465  // load area information
466  for (const auto & elem : areaList) {
467  loadAreaFromXML(*asConfig, elem);
468  }
469 
470  // load interface information
471  cXMLElementList routerConfig = routerNode->getChildren();
472  for (auto & elem : routerConfig) {
473  std::string nodeName = (elem)->getTagName();
474  if ((nodeName == "PointToPointInterface") ||
475  (nodeName == "BroadcastInterface") ||
476  (nodeName == "NBMAInterface") ||
477  (nodeName == "PointToMultiPointInterface"))
478  {
479  loadInterfaceParameters(*(elem));
480  }
481  else if (nodeName == "ExternalInterface") {
482  loadExternalRoute(*(elem));
483  }
484  else if (nodeName == "HostInterface") {
485  loadHostRoute(*(elem));
486  }
487  else if (nodeName == "VirtualLink") {
488  loadVirtualLink(*(elem));
489  }
490  else {
491  throw cRuntimeError("Invalid '%s' node in Router '%s' at %s",
492  nodeName.c_str(), nodeFullPath.c_str(), (elem)->getSourceLocation());
493  }
494  }
495  return true;
496 }
cModule * ospfModule
Definition: OSPFConfigReader.h:40
void setRFC1583Compatibility(bool compatibility)
Definition: OSPFRouter.h:73
void loadHostRoute(const cXMLElement &hostRouteConfig)
Loads the configuration of a host route (a host directly connected to the router).
Definition: OSPFConfigReader.cc:360
void loadAreaFromXML(const cXMLElement &asConfig, AreaID areaID)
Loads basic configuration information for a given area from the config XML.
Definition: OSPFConfigReader.cc:106
const char * getRequiredAttribute(const cXMLElement &node, const char *attr)
Definition: XMLUtils.cc:150
void loadVirtualLink(const cXMLElement &virtualLinkConfig)
Loads the configuration of an OSPf virtual link (virtual connection between two backbone routers)...
Definition: OSPFConfigReader.cc:388
const AreaID BACKBONE_AREAID(0, 0, 0, 0)
void loadExternalRoute(const cXMLElement &externalRouteConfig)
Loads the configuration information of a route outside of the Autonomous System (external route)...
Definition: OSPFConfigReader.cc:308
void loadInterfaceParameters(const cXMLElement &ifConfig)
Loads OSPF configuration information for a router interface.
Definition: OSPFConfigReader.cc:216
cModule * findContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:56
bool getBoolAttrOrPar(const cXMLElement &ifConfig, const char *name) const
Definition: OSPFConfigReader.cc:153
Router * ospfRouter
Definition: OSPFConfigReader.h:42
Glob-style pattern matching class, adopted to special OMNeT++ requirements.
Definition: PatternMatcher.h:78
void getAreaListFromXML(const cXMLElement &routerNode, std::set< AreaID > &areaList) const
Loads a list of OSPF Areas connected to this router from the config XML.
Definition: OSPFConfigReader.cc:89
void inet::ospf::OSPFConfigReader::loadExternalRoute ( const cXMLElement &  externalRouteConfig)
private

Loads the configuration information of a route outside of the Autonomous System (external route).

Referenced by loadConfigFromXML().

309 {
310  InterfaceEntry *ie = getInterfaceByXMLAttributesOf(externalRouteConfig);
311  int ifIndex = ie->getInterfaceId();
312 
313  OSPFASExternalLSAContents asExternalRoute;
314  //RoutingTableEntry externalRoutingEntry; // only used here to keep the path cost calculation in one place
315  IPv4AddressRange networkAddress;
316 
317  EV_DEBUG << " loading ExternalInterface " << ie->getName() << " ifIndex[" << ifIndex << "]\n";
318 
319  joinMulticastGroups(ifIndex);
320 
321  networkAddress.address = ipv4AddressFromAddressString(getRequiredAttribute(externalRouteConfig, "advertisedExternalNetworkAddress"));
322  networkAddress.mask = ipv4NetmaskFromAddressString(getRequiredAttribute(externalRouteConfig, "advertisedExternalNetworkMask"));
323  networkAddress.address = networkAddress.address & networkAddress.mask;
324  asExternalRoute.setNetworkMask(networkAddress.mask);
325 
326  int routeCost = getIntAttrOrPar(externalRouteConfig, "externalInterfaceOutputCost");
327  asExternalRoute.setRouteCost(routeCost);
328 
329  std::string metricType = getStrAttrOrPar(externalRouteConfig, "externalInterfaceOutputType");
330  if (metricType == "Type2") {
331  asExternalRoute.setE_ExternalMetricType(true);
332  //externalRoutingEntry.setType2Cost(routeCost);
333  //externalRoutingEntry.setPathType(RoutingTableEntry::TYPE2_EXTERNAL);
334  }
335  else if (metricType == "Type1") {
336  asExternalRoute.setE_ExternalMetricType(false);
337  //externalRoutingEntry.setCost(routeCost);
338  //externalRoutingEntry.setPathType(RoutingTableEntry::TYPE1_EXTERNAL);
339  }
340  else {
341  throw cRuntimeError("Invalid 'externalInterfaceOutputType' at interface '%s' at ", ie->getName(), externalRouteConfig.getSourceLocation());
342  }
343 
344  asExternalRoute.setForwardingAddress(ipv4AddressFromAddressString(getRequiredAttribute(externalRouteConfig, "forwardingAddress")));
345 
346  long externalRouteTagVal = 0; // default value
347  const char *externalRouteTag = externalRouteConfig.getAttribute("externalRouteTag");
348  if (externalRouteTag && *externalRouteTag) {
349  char *endp = nullptr;
350  externalRouteTagVal = strtol(externalRouteTag, &endp, 0);
351  if (*endp)
352  throw cRuntimeError("Invalid externalRouteTag='%s' at %s", externalRouteTag, externalRouteConfig.getSourceLocation());
353  }
354  asExternalRoute.setExternalRouteTag(externalRouteTagVal);
355 
356  // add the external route to the OSPF data structure
357  ospfRouter->updateExternalRoute(networkAddress.address, asExternalRoute, ifIndex);
358 }
const char * getRequiredAttribute(const cXMLElement &node, const char *attr)
Definition: XMLUtils.cc:150
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
IPv4Address ipv4NetmaskFromAddressString(const char *charForm)
Definition: OSPFcommon.h:210
IPv4Address ipv4AddressFromAddressString(const char *charForm)
Definition: OSPFcommon.h:205
void joinMulticastGroups(int interfaceId)
Definition: OSPFConfigReader.cc:174
Router * ospfRouter
Definition: OSPFConfigReader.h:42
const char * getStrAttrOrPar(const cXMLElement &ifConfig, const char *name) const
Definition: OSPFConfigReader.cc:166
int getIntAttrOrPar(const cXMLElement &ifConfig, const char *name) const
Definition: OSPFConfigReader.cc:145
InterfaceEntry * getInterfaceByXMLAttributesOf(const cXMLElement &ifConfig)
Search an InterfaceEntry in IInterfaceTable by interface name or toward module name an returns the In...
Definition: OSPFConfigReader.cc:53
void inet::ospf::OSPFConfigReader::loadHostRoute ( const cXMLElement &  hostRouteConfig)
private

Loads the configuration of a host route (a host directly connected to the router).

Referenced by loadConfigFromXML().

361 {
362  HostRouteParameters hostParameters;
363  AreaID hostArea;
364 
365  InterfaceEntry *ie = getInterfaceByXMLAttributesOf(hostRouteConfig);
366  int ifIndex = ie->getInterfaceId();
367 
368  hostParameters.ifIndex = ifIndex;
369 
370  EV_DEBUG << " loading HostInterface " << ie->getName() << " ifIndex[" << ifIndex << "]\n";
371 
372  joinMulticastGroups(hostParameters.ifIndex);
373 
374  hostArea = ipv4AddressFromAddressString(getStrAttrOrPar(hostRouteConfig, "areaID"));
375  hostParameters.address = ipv4AddressFromAddressString(getRequiredAttribute(hostRouteConfig, "attachedHost"));
376  hostParameters.linkCost = getIntAttrOrPar(hostRouteConfig, "linkCost");
377 
378  // add the host route to the OSPF data structure.
379  Area *area = ospfRouter->getAreaByID(hostArea);
380  if (area != nullptr) {
381  area->addHostRoute(hostParameters);
382  }
383  else {
384  throw cRuntimeError("Loading HostInterface '%s' aborted, unknown area %s at %s", ie->getName(), hostArea.str(false).c_str(), hostRouteConfig.getSourceLocation());
385  }
386 }
void addHostRoute(HostRouteParameters &hostRouteParameters)
Definition: OSPFArea.h:68
IPv4Address AreaID
Definition: OSPFcommon.h:138
const char * getRequiredAttribute(const cXMLElement &node, const char *attr)
Definition: XMLUtils.cc:150
IPv4Address ipv4AddressFromAddressString(const char *charForm)
Definition: OSPFcommon.h:205
void joinMulticastGroups(int interfaceId)
Definition: OSPFConfigReader.cc:174
Area * getAreaByID(AreaID areaID)
Returns the pointer to the Area identified by the input areaID, if it&#39;s on the Area list...
Definition: OSPFRouter.cc:72
Router * ospfRouter
Definition: OSPFConfigReader.h:42
const char * getStrAttrOrPar(const cXMLElement &ifConfig, const char *name) const
Definition: OSPFConfigReader.cc:166
int getIntAttrOrPar(const cXMLElement &ifConfig, const char *name) const
Definition: OSPFConfigReader.cc:145
InterfaceEntry * getInterfaceByXMLAttributesOf(const cXMLElement &ifConfig)
Search an InterfaceEntry in IInterfaceTable by interface name or toward module name an returns the In...
Definition: OSPFConfigReader.cc:53
void inet::ospf::OSPFConfigReader::loadInterfaceParameters ( const cXMLElement &  ifConfig)
private

Loads OSPF configuration information for a router interface.

Handles POINTTOPOINT, BROADCAST, NBMA and POINTTOMULTIPOINT interfaces.

Referenced by loadConfigFromXML().

217 {
218  Interface *intf = new Interface;
219  InterfaceEntry *ie = getInterfaceByXMLAttributesOf(ifConfig);
220  int ifIndex = ie->getInterfaceId();
221 
222  std::string interfaceType = ifConfig.getTagName();
223 
224  EV_DEBUG << " loading " << interfaceType << " " << ie->getName() << " (ifIndex=" << ifIndex << ")\n";
225 
226  intf->setIfIndex(ift, ifIndex);
227  if (interfaceType == "PointToPointInterface") {
228  intf->setType(Interface::POINTTOPOINT);
229  }
230  else if (interfaceType == "BroadcastInterface") {
231  intf->setType(Interface::BROADCAST);
232  }
233  else if (interfaceType == "NBMAInterface") {
234  intf->setType(Interface::NBMA);
235  }
236  else if (interfaceType == "PointToMultiPointInterface") {
237  intf->setType(Interface::POINTTOMULTIPOINT);
238  }
239  else {
240  delete intf;
241  throw cRuntimeError("Unknown interface type '%s' for interface %s (ifIndex=%d) at %s",
242  interfaceType.c_str(), ie->getName(), ifIndex, ifConfig.getSourceLocation());
243  }
244 
245  joinMulticastGroups(ifIndex);
246 
247  AreaID areaID = IPv4Address(getStrAttrOrPar(ifConfig, "areaID"));
248  intf->setAreaID(areaID);
249 
250  intf->setOutputCost(getIntAttrOrPar(ifConfig, "interfaceOutputCost"));
251 
252  intf->setRetransmissionInterval(getIntAttrOrPar(ifConfig, "retransmissionInterval"));
253 
254  intf->setTransmissionDelay(getIntAttrOrPar(ifConfig, "interfaceTransmissionDelay"));
255 
256  if (interfaceType == "BroadcastInterface" || interfaceType == "NBMAInterface")
257  intf->setRouterPriority(getIntAttrOrPar(ifConfig, "routerPriority"));
258 
259  intf->setHelloInterval(getIntAttrOrPar(ifConfig, "helloInterval"));
260 
261  intf->setRouterDeadInterval(getIntAttrOrPar(ifConfig, "routerDeadInterval"));
262 
263  loadAuthenticationConfig(intf, ifConfig);
264 
265  if (interfaceType == "NBMAInterface")
266  intf->setPollInterval(getIntAttrOrPar(ifConfig, "pollInterval"));
267 
268  cXMLElementList ifDetails = ifConfig.getChildren();
269 
270  for (auto & ifDetail : ifDetails) {
271  std::string nodeName = (ifDetail)->getTagName();
272  if ((interfaceType == "NBMAInterface") && (nodeName == "NBMANeighborList")) {
273  cXMLElementList neighborList = (ifDetail)->getChildren();
274  for (auto & elem : neighborList) {
275  std::string neighborNodeName = (elem)->getTagName();
276  if (neighborNodeName == "NBMANeighbor") {
277  Neighbor *neighbor = new Neighbor;
278  neighbor->setAddress(ipv4AddressFromAddressString(getRequiredAttribute(*elem, "networkInterfaceAddress")));
279  neighbor->setPriority(atoi(getRequiredAttribute(*elem, "neighborPriority")));
280  intf->addNeighbor(neighbor);
281  }
282  }
283  }
284  if ((interfaceType == "PointToMultiPointInterface") && (nodeName == "PointToMultiPointNeighborList")) {
285  cXMLElementList neighborList = (ifDetail)->getChildren();
286  for (auto & elem : neighborList) {
287  std::string neighborNodeName = (elem)->getTagName();
288  if (neighborNodeName == "PointToMultiPointNeighbor") {
289  Neighbor *neighbor = new Neighbor;
290  neighbor->setAddress(ipv4AddressFromAddressString((elem)->getNodeValue()));
291  intf->addNeighbor(neighbor);
292  }
293  }
294  }
295  }
296  // add the interface to it's Area
297  Area *area = ospfRouter->getAreaByID(areaID);
298  if (area != nullptr) {
299  area->addInterface(intf);
300  intf->processEvent(Interface::INTERFACE_UP); // notification should come from the blackboard...
301  }
302  else {
303  delete intf;
304  throw cRuntimeError("Loading %s ifIndex[%d] in Area %s aborted at %s", interfaceType.c_str(), ifIndex, areaID.str(false).c_str(), ifConfig.getSourceLocation());
305  }
306 }
void addInterface(Interface *intf)
Definition: OSPFArea.cc:61
IPv4Address AreaID
Definition: OSPFcommon.h:138
const char * getRequiredAttribute(const cXMLElement &node, const char *attr)
Definition: XMLUtils.cc:150
void loadAuthenticationConfig(Interface *intf, const cXMLElement &ifConfig)
Loads authenticationType and authenticationKey attributes for a router interface. ...
Definition: OSPFConfigReader.cc:188
Definition: OSPFInterface.h:56
IInterfaceTable * ift
Definition: OSPFConfigReader.h:41
Definition: OSPFInterface.h:58
IPv4Address ipv4AddressFromAddressString(const char *charForm)
Definition: OSPFcommon.h:205
Definition: OSPFInterface.h:57
Definition: OSPFInterface.h:59
void joinMulticastGroups(int interfaceId)
Definition: OSPFConfigReader.cc:174
Area * getAreaByID(AreaID areaID)
Returns the pointer to the Area identified by the input areaID, if it&#39;s on the Area list...
Definition: OSPFRouter.cc:72
Definition: OSPFInterface.h:43
Router * ospfRouter
Definition: OSPFConfigReader.h:42
const char * getStrAttrOrPar(const cXMLElement &ifConfig, const char *name) const
Definition: OSPFConfigReader.cc:166
int getIntAttrOrPar(const cXMLElement &ifConfig, const char *name) const
Definition: OSPFConfigReader.cc:145
InterfaceEntry * getInterfaceByXMLAttributesOf(const cXMLElement &ifConfig)
Search an InterfaceEntry in IInterfaceTable by interface name or toward module name an returns the In...
Definition: OSPFConfigReader.cc:53
void inet::ospf::OSPFConfigReader::loadVirtualLink ( const cXMLElement &  virtualLinkConfig)
private

Loads the configuration of an OSPf virtual link (virtual connection between two backbone routers).

Referenced by loadConfigFromXML().

389 {
390  Interface *intf = new Interface;
391  std::string endPoint = getRequiredAttribute(virtualLinkConfig, "endPointRouterID");
392  Neighbor *neighbor = new Neighbor;
393 
394  EV_DEBUG << " loading VirtualLink to " << endPoint << "\n";
395 
396  intf->setType(Interface::VIRTUAL);
397  neighbor->setNeighborID(ipv4AddressFromAddressString(endPoint.c_str()));
398  intf->addNeighbor(neighbor);
399 
400  intf->setTransitAreaID(ipv4AddressFromAddressString(getRequiredAttribute(virtualLinkConfig, "transitAreaID")));
401 
402  intf->setRetransmissionInterval(getIntAttrOrPar(virtualLinkConfig, "retransmissionInterval"));
403 
404  intf->setTransmissionDelay(getIntAttrOrPar(virtualLinkConfig, "interfaceTransmissionDelay"));
405 
406  intf->setHelloInterval(getIntAttrOrPar(virtualLinkConfig, "helloInterval"));
407 
408  intf->setRouterDeadInterval(getIntAttrOrPar(virtualLinkConfig, "routerDeadInterval"));
409 
410  loadAuthenticationConfig(intf, virtualLinkConfig);
411 
412  // add the virtual link to the OSPF data structure.
413  Area *transitArea = ospfRouter->getAreaByID(intf->getAreaID());
414  Area *backbone = ospfRouter->getAreaByID(BACKBONE_AREAID);
415 
416  if ((backbone != nullptr) && (transitArea != nullptr) && (transitArea->getExternalRoutingCapability())) {
417  backbone->addInterface(intf);
418  }
419  else {
420  throw cRuntimeError("Loading VirtualLink to %s through Area %s aborted at ", endPoint.c_str(), intf->getAreaID().str(false).c_str(), virtualLinkConfig.getSourceLocation());
421  //delete intf;
422  }
423 }
Definition: OSPFInterface.h:60
void addInterface(Interface *intf)
Definition: OSPFArea.cc:61
const char * getRequiredAttribute(const cXMLElement &node, const char *attr)
Definition: XMLUtils.cc:150
void loadAuthenticationConfig(Interface *intf, const cXMLElement &ifConfig)
Loads authenticationType and authenticationKey attributes for a router interface. ...
Definition: OSPFConfigReader.cc:188
const AreaID BACKBONE_AREAID(0, 0, 0, 0)
IPv4Address ipv4AddressFromAddressString(const char *charForm)
Definition: OSPFcommon.h:205
Area * getAreaByID(AreaID areaID)
Returns the pointer to the Area identified by the input areaID, if it&#39;s on the Area list...
Definition: OSPFRouter.cc:72
Router * ospfRouter
Definition: OSPFConfigReader.h:42
int getIntAttrOrPar(const cXMLElement &ifConfig, const char *name) const
Definition: OSPFConfigReader.cc:145
cPar& inet::ospf::OSPFConfigReader::par ( const char *  name) const
inlineprivate

Referenced by getBoolAttrOrPar(), getIntAttrOrPar(), and getStrAttrOrPar().

45 { return ospfModule->par(name); }
cModule * ospfModule
Definition: OSPFConfigReader.h:40
int inet::ospf::OSPFConfigReader::resolveInterfaceName ( const std::string &  name) const
private

Looks up the interface name in IInterfaceTable, and returns interfaceId a.k.a ifIndex.

81 {
82  InterfaceEntry *ie = ift->getInterfaceByName(name.c_str());
83  if (!ie)
84  throw cRuntimeError("Error reading XML config: IInterfaceTable contains no interface named '%s'", name.c_str());
85 
86  return ie->getInterfaceId();
87 }
int getInterfaceId() const
Definition: InterfaceEntry.h:185
virtual InterfaceEntry * getInterfaceByName(const char *name) const =0
Returns an interface given by its name.
IInterfaceTable * ift
Definition: OSPFConfigReader.h:41

Member Data Documentation

cModule* inet::ospf::OSPFConfigReader::ospfModule = nullptr
private

Referenced by loadConfigFromXML().

Router* inet::ospf::OSPFConfigReader::ospfRouter = nullptr
private

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