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

Configuration reader for the OSPF module. More...

#include <Ospfv2ConfigReader.h>

Public Member Functions

 Ospfv2ConfigReader (cModule *ospfModule, IInterfaceTable *ift)
 
virtual ~Ospfv2ConfigReader ()
 
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
 
std::vector< NetworkInterface * > getInterfaceByXMLAttributesOf (const cXMLElement &ifConfig)
 Search an NetworkInterface in IInterfaceTable by interface name or toward module name an returns the NetworkInterface pointer or throws an error. More...
 
cXMLElement * findMatchingConfig (const cXMLElementList &routerConfig, const NetworkInterface &intf)
 
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 (Ospfv2Interface *intf, const cXMLElement &ifConfig)
 Loads authenticationType and authenticationKey attributes for a router interface. More...
 
void loadInterfaceParameters (const cXMLElement &ifConfig, NetworkInterface &intf)
 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 loadLoopbackParameters (const cXMLElement &loConfig, NetworkInterface &intf)
 Loads the configuration of a loopback interface. More...
 
void loadVirtualLink (const cXMLElement &virtualLinkConfig, cXMLElement &asConfig)
 Loads the configuration of an OSPf virtual link (virtual connection between two backbone routers). More...
 
void initiateDefaultRouteDistribution ()
 Distributes the configure default route on this router with AS-External LSAs to other OSPF 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

◆ Ospfv2ConfigReader()

inet::ospfv2::Ospfv2ConfigReader::Ospfv2ConfigReader ( cModule *  ospfModule,
IInterfaceTable ift 
)
35  :
37 {
38 }

◆ ~Ospfv2ConfigReader()

inet::ospfv2::Ospfv2ConfigReader::~Ospfv2ConfigReader ( )
virtual
41 {
42 }

Member Function Documentation

◆ findMatchingConfig()

cXMLElement * inet::ospfv2::Ospfv2ConfigReader::findMatchingConfig ( const cXMLElementList &  routerConfig,
const NetworkInterface intf 
)
private
509 {
510  for (auto& ifConfig : routerConfig) {
511  std::string nodeName = ifConfig->getTagName();
512  if ((nodeName == "PointToPointInterface") ||
513  (nodeName == "BroadcastInterface") ||
514  (nodeName == "NBMAInterface") ||
515  (nodeName == "PointToMultiPointInterface") ||
516  (nodeName == "LoopbackInterface"))
517  {
518  const char *ifName = (*ifConfig).getAttribute("ifName");
519  if (ifName && *ifName) {
520  inet::PatternMatcher pattern(ifName, true, true, true);
521  if (pattern.matches(intf.getFullName()) ||
522  pattern.matches(intf.getInterfaceFullPath().c_str()) ||
523  pattern.matches(intf.getInterfaceName()))
524  {
525  return ifConfig;
526  }
527 
528  continue;
529  }
530 
531  const char *toward = getMandatoryFilledAttribute(*ifConfig, "toward");
532  cModule *destnode = getSimulation()->getSystemModule()->getModuleByPath(toward);
533  if (!destnode)
534  throw cRuntimeError("toward module `%s' not found at %s", toward, (*ifConfig).getSourceLocation());
535 
536  int gateId = intf.getNodeOutputGateId();
537  if ((gateId != -1) && ift->getHostModule()->gate(gateId)->pathContains(destnode))
538  return ifConfig;
539  }
540  }
541 
542  return nullptr;
543 }

Referenced by loadConfigFromXML().

◆ getAreaListFromXML()

void inet::ospfv2::Ospfv2ConfigReader::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.
132 {
133  cXMLElementList routerConfig = routerNode.getChildren();
134  for (auto& elem : routerConfig) {
135  std::string nodeName = (elem)->getTagName();
136  if ((nodeName == "PointToPointInterface") ||
137  (nodeName == "BroadcastInterface") ||
138  (nodeName == "NBMAInterface") ||
139  (nodeName == "LoopbackInterface") ||
140  (nodeName == "PointToMultiPointInterface"))
141  {
142  AreaId areaID = Ipv4Address(getStrAttrOrPar(*elem, "areaID"));
143  if (!contains(areaList, areaID))
144  areaList.insert(areaID);
145  }
146  }
147 }

Referenced by loadConfigFromXML().

◆ getBoolAttrOrPar()

bool inet::ospfv2::Ospfv2ConfigReader::getBoolAttrOrPar ( const cXMLElement &  ifConfig,
const char *  name 
) const
private
591 {
592  const char *attrStr = ifConfig.getAttribute(name);
593  if (attrStr && *attrStr) {
594  if (strcmp(attrStr, "true") == 0 || strcmp(attrStr, "1") == 0)
595  return true;
596  if (strcmp(attrStr, "false") == 0 || strcmp(attrStr, "0") == 0)
597  return false;
598  throw cRuntimeError("Invalid boolean attribute %s = '%s' at %s", name, attrStr, ifConfig.getSourceLocation());
599  }
600  return par(name);
601 }

Referenced by loadConfigFromXML().

◆ getIntAttrOrPar()

int inet::ospfv2::Ospfv2ConfigReader::getIntAttrOrPar ( const cXMLElement &  ifConfig,
const char *  name 
) const
private
583 {
584  const char *attrStr = ifConfig.getAttribute(name);
585  if (attrStr && *attrStr)
586  return atoi(attrStr);
587  return par(name);
588 }

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

◆ getInterfaceByXMLAttributesOf()

std::vector< NetworkInterface * > inet::ospfv2::Ospfv2ConfigReader::getInterfaceByXMLAttributesOf ( const cXMLElement &  ifConfig)
private

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

546 {
547  std::vector<NetworkInterface *> results;
548  const char *ifName = ifConfig.getAttribute("ifName");
549  if (ifName && *ifName) {
550  inet::PatternMatcher pattern(ifName, true, true, true);
551  for (int n = 0; n < ift->getNumInterfaces(); n++) {
552  NetworkInterface *intf = ift->getInterface(n);
553  if (pattern.matches(intf->getFullName()) ||
554  pattern.matches(intf->getInterfaceFullPath().c_str()) ||
555  pattern.matches(intf->getInterfaceName()))
556  {
557  results.push_back(intf);
558  }
559  }
560  return results;
561  }
562 
563  const char *toward = getMandatoryFilledAttribute(ifConfig, "toward");
564  cModule *destnode = getSimulation()->getSystemModule()->getModuleByPath(toward);
565  if (!destnode)
566  throw cRuntimeError("'ifName' or 'toward' module `%s' not found at %s", toward, ifConfig.getSourceLocation());
567 
568  cModule *host = ift->getHostModule();
569  for (int i = 0; i < ift->getNumInterfaces(); i++) {
570  NetworkInterface *ie = ift->getInterface(i);
571  if (ie) {
572  int gateId = ie->getNodeOutputGateId();
573  if ((gateId != -1) && (host->gate(gateId)->pathContains(destnode))) {
574  results.push_back(ie);
575  return results;
576  }
577  }
578  }
579  throw cRuntimeError("Error reading XML config: IInterfaceTable contains no interface toward '%s' at %s", toward, ifConfig.getSourceLocation());
580 }

Referenced by loadExternalRoute(), and loadHostRoute().

◆ getStrAttrOrPar()

const char * inet::ospfv2::Ospfv2ConfigReader::getStrAttrOrPar ( const cXMLElement &  ifConfig,
const char *  name 
) const
private
604 {
605  const char *attrStr = ifConfig.getAttribute(name);
606  if (attrStr && *attrStr)
607  return attrStr;
608  return par(name);
609 }

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

◆ initiateDefaultRouteDistribution()

void inet::ospfv2::Ospfv2ConfigReader::initiateDefaultRouteDistribution ( )
private

Distributes the configure default route on this router with AS-External LSAs to other OSPF routers.

481 {
482  Ipv4Route *entry = ospfRouter->getDefaultRoute();
483  // if a default route exist on this router
484  if (entry) {
485  EV_DEBUG << " distributing the default route. \n";
486 
487  Ipv4AddressRange networkAddress;
488  networkAddress.address = ipv4AddressFromAddressString("0.0.0.0");
489  networkAddress.mask = ipv4NetmaskFromAddressString("0.0.0.0");
490  networkAddress.address = networkAddress.address & networkAddress.mask;
491 
492  Ospfv2AsExternalLsaContents asExternalRoute;
493  asExternalRoute.setNetworkMask(networkAddress.mask);
494  // default route is advertised with cost of 1 of 'type 2' external metric
495  asExternalRoute.setExternalTOSInfoArraySize(1);
496  auto& tosInfo = asExternalRoute.getExternalTOSInfoForUpdate(0);
497  tosInfo.E_ExternalMetricType = true;
498  tosInfo.tos = 0;
499  tosInfo.externalRouteTag = 0;
500  tosInfo.forwardingAddress = ipv4AddressFromAddressString("0.0.0.0");
501  tosInfo.routeCost = 1;
502 
503  // add the external route to the OSPF data structure
504  ospfRouter->updateExternalRoute(networkAddress.address, asExternalRoute);
505  }
506 }

Referenced by loadConfigFromXML().

◆ joinMulticastGroups()

void inet::ospfv2::Ospfv2ConfigReader::joinMulticastGroups ( int  interfaceId)
private
612 {
613  NetworkInterface *ie = ift->getInterfaceById(interfaceId);
614  if (!ie)
615  throw cRuntimeError("Interface id=%d does not exist", interfaceId);
616  if (!ie->isMulticast())
617  return;
618  auto ipv4Data = ie->getProtocolDataForUpdate<Ipv4InterfaceData>();
619  ipv4Data->joinMulticastGroup(Ipv4Address::ALL_OSPF_ROUTERS_MCAST);
620  ipv4Data->joinMulticastGroup(Ipv4Address::ALL_OSPF_DESIGNATED_ROUTERS_MCAST);
621 }

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

◆ loadAreaFromXML()

void inet::ospfv2::Ospfv2ConfigReader::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.

150 {
151  std::string areaXPath("Area[@id='");
152  areaXPath += areaID.str(false);
153  areaXPath += "']";
154 
155  auto crcMode = parseCrcMode(par("crcMode"), false);
156 
157  cXMLElement *areaConfig = asConfig.getElementByPath(areaXPath.c_str());
158  if (areaConfig == nullptr) {
159  if (areaID != Ipv4Address("0.0.0.0"))
160  throw cRuntimeError("No configuration for Area ID: %s at %s", areaID.str(false).c_str(), asConfig.getSourceLocation());
161  Ospfv2Area *area = new Ospfv2Area(crcMode, ift, areaID);
162  area->addWatches();
163  ospfRouter->addArea(area);
164  return;
165  }
166 
167  EV_DEBUG << " loading info for Area id = " << areaID.str(false) << "\n";
168 
169  Ospfv2Area *area = new Ospfv2Area(crcMode, ift, areaID);
170  area->addWatches();
171  cXMLElementList areaDetails = areaConfig->getChildren();
172  for (auto& areaDetail : areaDetails) {
173  std::string nodeName = (areaDetail)->getTagName();
174  if (nodeName == "AddressRange") {
175  Ipv4AddressRange addressRange;
176  addressRange.address = ipv4AddressFromAddressString(getMandatoryFilledAttribute(*areaDetail, "address"));
177  addressRange.mask = ipv4NetmaskFromAddressString(getMandatoryFilledAttribute(*areaDetail, "mask"));
178  addressRange.address = addressRange.address & addressRange.mask;
179  const char *adv = areaDetail->getAttribute("advertise");
180  if (!adv)
181  area->addAddressRange(addressRange, true);
182  else
183  area->addAddressRange(addressRange, std::string(adv) == "true");
184  }
185  else if (nodeName == "Stub") {
186  if (areaID == BACKBONE_AREAID)
187  throw cRuntimeError("The backbone cannot be configured as a stub at %s", (areaDetail)->getSourceLocation());
188  area->setExternalRoutingCapability(false);
189  area->setStubDefaultCost(atoi(getMandatoryFilledAttribute(*areaDetail, "defaultCost")));
190  }
191  else
192  throw cRuntimeError("Invalid node '%s' at %s", nodeName.c_str(), (areaDetail)->getSourceLocation());
193  }
194  // Add the Area to the router
195  ospfRouter->addArea(area);
196 }

Referenced by loadConfigFromXML(), and loadVirtualLink().

◆ loadAuthenticationConfig()

void inet::ospfv2::Ospfv2ConfigReader::loadAuthenticationConfig ( Ospfv2Interface intf,
const cXMLElement &  ifConfig 
)
private

Loads authenticationType and authenticationKey attributes for a router interface.

457 {
458  std::string authenticationType = getStrAttrOrPar(ifConfig, "authenticationType");
459  if (authenticationType == "SimplePasswordType")
460  intf->setAuthenticationType(SIMPLE_PASSWORD_TYPE);
461  else if (authenticationType == "CrytographicType")
462  intf->setAuthenticationType(CRYTOGRAPHIC_TYPE);
463  else if (authenticationType == "NullType")
464  intf->setAuthenticationType(NULL_TYPE);
465  else
466  throw cRuntimeError("Invalid AuthenticationType '%s' at %s", authenticationType.c_str(), ifConfig.getSourceLocation());
467 
468  std::string key = getStrAttrOrPar(ifConfig, "authenticationKey");
469  AuthenticationKeyType keyValue;
470  memset(keyValue.bytes, 0, sizeof(keyValue.bytes));
471  int keyLength = key.length();
472  if ((keyLength > 4) && (keyLength <= 18) && (keyLength % 2 == 0) && (key[0] == '0') && (key[1] == 'x')) {
473  for (int i = keyLength; (i > 2); i -= 2) {
474  keyValue.bytes[(i - 2) / 2 - 1] = hexPairToByte(key[i - 1], key[i]);
475  }
476  }
477  intf->setAuthenticationKey(keyValue);
478 }

Referenced by loadInterfaceParameters(), and loadVirtualLink().

◆ loadConfigFromXML()

bool inet::ospfv2::Ospfv2ConfigReader::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.

45 {
46  this->ospfRouter = ospfRouter;
47 
48  if (strcmp(asConfig->getTagName(), "OSPFASConfig"))
49  throw cRuntimeError("Cannot read OSPF configuration, unexpected element '%s' at %s", asConfig->getTagName(), asConfig->getSourceLocation());
50 
51  cModule *myNode = findContainingNode(ospfModule);
52  ASSERT(myNode);
53  std::string nodeFullPath = myNode->getFullPath();
54  std::string nodeShortenedFullPath = nodeFullPath.substr(nodeFullPath.find('.') + 1);
55 
56  // load information on this router
57  cXMLElementList routers = asConfig->getElementsByTagName("Router");
58  cXMLElement *routerNode = nullptr;
59  for (auto& router : routers) {
60  const char *nodeName = getMandatoryFilledAttribute(*(router), "name");
61  inet::PatternMatcher pattern(nodeName, true, true, true);
62  if (pattern.matches(nodeFullPath.c_str()) || pattern.matches(nodeShortenedFullPath.c_str())) { // match Router@name and fullpath of my node
63  routerNode = router;
64  break;
65  }
66  }
67  if (routerNode == nullptr) {
68  throw cRuntimeError("No configuration for Router '%s' at '%s'", nodeFullPath.c_str(), asConfig->getSourceLocation());
69  }
70 
71  EV_DEBUG << "Ospfv2ConfigReader: Loading info for Router " << nodeFullPath << "\n";
72 
73  bool rfc1583Compatible = getBoolAttrOrPar(*routerNode, "RFC1583Compatible");
74  ospfRouter->setRFC1583Compatibility(rfc1583Compatible);
75 
76  std::set<AreaId> areaList;
77  getAreaListFromXML(*routerNode, areaList);
78 
79  // load area information
80  for (const auto& elem : areaList) {
81  loadAreaFromXML(*asConfig, elem);
82  }
83 
84  cXMLElementList routerConfig = routerNode->getChildren();
85 
86  // load interface information
87  for (int n = 0; n < ift->getNumInterfaces(); n++) {
88  NetworkInterface *intf = ift->getInterface(n);
89  cXMLElement *ifConfig = findMatchingConfig(routerConfig, *intf);
90  if (ifConfig) {
91  if (intf->isLoopback())
92  loadLoopbackParameters(*ifConfig, *intf);
93  else
94  loadInterfaceParameters(*ifConfig, *intf);
95  }
96  }
97 
98  // load remaining information
99  for (auto& elem : routerConfig) {
100  std::string nodeName = elem->getTagName();
101  if ((nodeName == "PointToPointInterface") ||
102  (nodeName == "BroadcastInterface") ||
103  (nodeName == "NBMAInterface") ||
104  (nodeName == "PointToMultiPointInterface") ||
105  (nodeName == "LoopbackInterface"))
106  {
107  continue;
108  }
109  else if (nodeName == "ExternalInterface") {
110  loadExternalRoute(*elem);
111  }
112  else if (nodeName == "HostInterface") {
113  loadHostRoute(*elem);
114  }
115  else if (nodeName == "VirtualLink") {
116  loadVirtualLink(*elem, *asConfig);
117  }
118  else {
119  throw cRuntimeError("Invalid '%s' node in Router '%s' at %s",
120  nodeName.c_str(), nodeFullPath.c_str(), elem->getSourceLocation());
121  }
122  }
123 
124  bool DistributeDefaultRoute = getBoolAttrOrPar(*routerNode, "DistributeDefaultRoute");
125  if (DistributeDefaultRoute)
127 
128  return true;
129 }

Referenced by inet::ospfv2::Ospfv2::createOspfRouter().

◆ loadExternalRoute()

void inet::ospfv2::Ospfv2ConfigReader::loadExternalRoute ( const cXMLElement &  externalRouteConfig)
private

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

309 {
310  for (auto& ie : getInterfaceByXMLAttributesOf(externalRouteConfig)) {
311  Ospfv2AsExternalLsaContents asExternalRoute;
312  Ipv4AddressRange networkAddress;
313  int ifIndex = ie->getInterfaceId();
314 
315  EV_DEBUG << " loading ExternalInterface " << ie->getInterfaceName() << " ifIndex[" << ifIndex << "]\n";
316 
317  joinMulticastGroups(ifIndex);
318 
319  networkAddress.address = ipv4AddressFromAddressString(getMandatoryFilledAttribute(externalRouteConfig, "advertisedExternalNetworkAddress"));
320  networkAddress.mask = ipv4NetmaskFromAddressString(getMandatoryFilledAttribute(externalRouteConfig, "advertisedExternalNetworkMask"));
321  networkAddress.address = networkAddress.address & networkAddress.mask;
322  asExternalRoute.setNetworkMask(networkAddress.mask);
323  asExternalRoute.setExternalTOSInfoArraySize(1);
324  auto& tosInfo = asExternalRoute.getExternalTOSInfoForUpdate(0);
325 
326  int routeCost = getIntAttrOrPar(externalRouteConfig, "externalInterfaceOutputCost");
327  tosInfo.tos = 0;
328  tosInfo.routeCost = routeCost;
329 
330  std::string metricType = getStrAttrOrPar(externalRouteConfig, "externalInterfaceOutputType");
331  if (metricType == "Type1")
332  tosInfo.E_ExternalMetricType = false;
333  else if (metricType == "Type2")
334  tosInfo.E_ExternalMetricType = true;
335  else
336  throw cRuntimeError("Invalid 'externalInterfaceOutputType' at interface '%s' at '%s'", ie->getInterfaceName(), externalRouteConfig.getSourceLocation());
337 
338  tosInfo.forwardingAddress = ipv4AddressFromAddressString(getStrAttrOrPar(externalRouteConfig, "forwardingAddress"));
339 
340  long externalRouteTagVal = 0; // default value
341  const char *externalRouteTag = externalRouteConfig.getAttribute("externalRouteTag");
342  if (externalRouteTag && *externalRouteTag) {
343  char *endp = nullptr;
344  externalRouteTagVal = strtol(externalRouteTag, &endp, 0);
345  if (*endp)
346  throw cRuntimeError("Invalid externalRouteTag='%s' at %s", externalRouteTag, externalRouteConfig.getSourceLocation());
347  }
348  tosInfo.externalRouteTag = externalRouteTagVal;
349 
350  // add the external route to the OSPF data structure
351  ospfRouter->updateExternalRoute(networkAddress.address, asExternalRoute, ifIndex);
352  }
353 }

Referenced by loadConfigFromXML().

◆ loadHostRoute()

void inet::ospfv2::Ospfv2ConfigReader::loadHostRoute ( const cXMLElement &  hostRouteConfig)
private

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

356 {
357  std::string intfModeStr = getStrAttrOrPar(hostRouteConfig, "interfaceMode");
358  if (intfModeStr == "NoOSPF")
359  return;
360 
361  HostRouteParameters hostParameters;
362  AreaId hostArea;
363 
364  for (auto& ie : getInterfaceByXMLAttributesOf(hostRouteConfig)) {
365  int ifIndex = ie->getInterfaceId();
366 
367  hostParameters.ifIndex = ifIndex;
368 
369  EV_DEBUG << " loading HostInterface " << ie->getInterfaceName() << " ifIndex[" << ifIndex << "]\n";
370 
371  joinMulticastGroups(hostParameters.ifIndex);
372 
373  hostArea = ipv4AddressFromAddressString(getStrAttrOrPar(hostRouteConfig, "areaID"));
374  hostParameters.address = ipv4AddressFromAddressString(getMandatoryFilledAttribute(hostRouteConfig, "attachedHost"));
375  hostParameters.linkCost = getIntAttrOrPar(hostRouteConfig, "linkCost");
376 
377  // add the host route to the OSPF data structure.
378  Ospfv2Area *area = ospfRouter->getAreaByID(hostArea);
379  if (area != nullptr) {
380  area->addHostRoute(hostParameters);
381  }
382  else {
383  throw cRuntimeError("Loading HostInterface '%s' aborted, unknown area %s at %s", ie->getInterfaceName(), hostArea.str(false).c_str(), hostRouteConfig.getSourceLocation());
384  }
385  }
386 }

Referenced by loadConfigFromXML().

◆ loadInterfaceParameters()

void inet::ospfv2::Ospfv2ConfigReader::loadInterfaceParameters ( const cXMLElement &  ifConfig,
NetworkInterface intf 
)
private

Loads OSPF configuration information for a router interface.

Handles POINTTOPOINT, BROADCAST, NBMA and POINTTOMULTIPOINT interfaces.

199 {
200  std::string intfModeStr = getStrAttrOrPar(ifConfig, "interfaceMode");
201  if (intfModeStr == "NoOSPF")
202  return;
203 
204  std::string interfaceType = ifConfig.getTagName();
205  int ifIndex = ie.getInterfaceId();
206  std::string ifName = ie.getInterfaceName();
207 
208  EV_DEBUG << " loading " << interfaceType << " " << ifName << " (ifIndex=" << ifIndex << ")\n";
209 
210  Ospfv2Interface *intf = new Ospfv2Interface;
211 
212  intf->setInterfaceName(ifName);
213  AreaId areaID = Ipv4Address(getStrAttrOrPar(ifConfig, "areaID"));
214  intf->setAreaId(areaID);
215  intf->setIfIndex(ift, ifIndex); // should be called before calling setType()
216 
217  if (interfaceType == "PointToPointInterface")
218  intf->setType(Ospfv2Interface::POINTTOPOINT);
219  else if (interfaceType == "BroadcastInterface")
220  intf->setType(Ospfv2Interface::BROADCAST);
221  else if (interfaceType == "NBMAInterface")
222  intf->setType(Ospfv2Interface::NBMA);
223  else if (interfaceType == "PointToMultiPointInterface")
224  intf->setType(Ospfv2Interface::POINTTOMULTIPOINT);
225  else {
226  delete intf;
227  throw cRuntimeError("Unknown interface type '%s' for interface %s (ifIndex=%d) at %s",
228  interfaceType.c_str(), ifName.c_str(), ifIndex, ifConfig.getSourceLocation());
229  }
230 
231  if (intfModeStr == "Active")
232  intf->setMode(Ospfv2Interface::ACTIVE);
233  else if (intfModeStr == "Passive")
234  intf->setMode(Ospfv2Interface::PASSIVE);
235  else {
236  delete intf;
237  throw cRuntimeError("Unknown interface mode '%s' for interface %s (ifIndex=%d) at %s",
238  interfaceType.c_str(), ifName.c_str(), ifIndex, ifConfig.getSourceLocation());
239  }
240 
241  intf->setCrcMode(parseCrcMode(par("crcMode"), false));
242 
243  Metric cost = getIntAttrOrPar(ifConfig, "interfaceOutputCost");
244  if (cost == 0)
245  intf->setOutputCost(round(par("referenceBandwidth").intValue() / ie.getDatarate()));
246  else
247  intf->setOutputCost(cost);
248 
249  intf->setRetransmissionInterval(getIntAttrOrPar(ifConfig, "retransmissionInterval"));
250 
251  intf->setTransmissionDelay(getIntAttrOrPar(ifConfig, "interfaceTransmissionDelay"));
252 
253  if (interfaceType == "BroadcastInterface" || interfaceType == "NBMAInterface")
254  intf->setRouterPriority(getIntAttrOrPar(ifConfig, "routerPriority"));
255 
256  intf->setHelloInterval(getIntAttrOrPar(ifConfig, "helloInterval"));
257 
258  intf->setRouterDeadInterval(getIntAttrOrPar(ifConfig, "routerDeadInterval"));
259 
260  loadAuthenticationConfig(intf, ifConfig);
261 
262  if (interfaceType == "NBMAInterface")
263  intf->setPollInterval(getIntAttrOrPar(ifConfig, "pollInterval"));
264 
265  cXMLElementList ifDetails = ifConfig.getChildren();
266 
267  for (auto& ifDetail : ifDetails) {
268  std::string nodeName = (ifDetail)->getTagName();
269  if ((interfaceType == "NBMAInterface") && (nodeName == "NBMANeighborList")) {
270  cXMLElementList neighborList = (ifDetail)->getChildren();
271  for (auto& elem : neighborList) {
272  std::string neighborNodeName = (elem)->getTagName();
273  if (neighborNodeName == "NBMANeighbor") {
274  Neighbor *neighbor = new Neighbor;
275  neighbor->setAddress(ipv4AddressFromAddressString(getMandatoryFilledAttribute(*elem, "networkInterfaceAddress")));
276  neighbor->setPriority(atoi(getMandatoryFilledAttribute(*elem, "neighborPriority")));
277  intf->addNeighbor(neighbor);
278  }
279  }
280  }
281  if ((interfaceType == "PointToMultiPointInterface") && (nodeName == "PointToMultiPointNeighborList")) {
282  cXMLElementList neighborList = (ifDetail)->getChildren();
283  for (auto& elem : neighborList) {
284  std::string neighborNodeName = (elem)->getTagName();
285  if (neighborNodeName == "PointToMultiPointNeighbor") {
286  Neighbor *neighbor = new Neighbor;
287  neighbor->setAddress(ipv4AddressFromAddressString((elem)->getNodeValue()));
288  intf->addNeighbor(neighbor);
289  }
290  }
291  }
292  }
293 
294  joinMulticastGroups(ifIndex);
295 
296  // add the interface to it's Area
297  Ospfv2Area *area = ospfRouter->getAreaByID(areaID);
298  if (area != nullptr) {
299  area->addInterface(intf);
300  intf->processEvent(Ospfv2Interface::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 }

Referenced by loadConfigFromXML().

◆ loadLoopbackParameters()

void inet::ospfv2::Ospfv2ConfigReader::loadLoopbackParameters ( const cXMLElement &  loConfig,
NetworkInterface intf 
)
private

Loads the configuration of a loopback interface.

389 {
390  int ifIndex = ie.getInterfaceId();
391  EV_DEBUG << " loading LoopbackInterface " << ie.getInterfaceName() << " ifIndex[" << ifIndex << "]\n";
392 
393  joinMulticastGroups(ifIndex);
394 
395  // Loopbacks are considered host routes in OSPF, and they are advertised as /32
396  HostRouteParameters hostParameters;
397  hostParameters.ifIndex = ifIndex;
398  AreaId hostArea = ipv4AddressFromAddressString(getStrAttrOrPar(loConfig, "areaID"));
399  hostParameters.address = ie.getIpv4Address();
400  hostParameters.linkCost = getIntAttrOrPar(loConfig, "linkCost");
401 
402  // add the host route to the OSPF data structure.
403  Ospfv2Area *area = ospfRouter->getAreaByID(hostArea);
404  if (area != nullptr)
405  area->addHostRoute(hostParameters);
406  else
407  throw cRuntimeError("Loading LoopbackInterface '%s' aborted, unknown area %s at %s", ie.getInterfaceName(), hostArea.str(false).c_str(), loConfig.getSourceLocation());
408 }

Referenced by loadConfigFromXML().

◆ loadVirtualLink()

void inet::ospfv2::Ospfv2ConfigReader::loadVirtualLink ( const cXMLElement &  virtualLinkConfig,
cXMLElement &  asConfig 
)
private

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

411 {
412  std::string endPoint = getMandatoryFilledAttribute(virtualLinkConfig, "endPointRouterID");
413  Ipv4Address routerId = ipv4AddressFromAddressString(endPoint.c_str());
414 
415  EV_DEBUG << " loading VirtualLink to OSPF router " << routerId.str(false) << "\n";
416 
417  Neighbor *neighbor = new Neighbor;
418  neighbor->setNeighborID(routerId);
419 
420  Ospfv2Interface *intf = new Ospfv2Interface;
421 
422  intf->setType(Ospfv2Interface::VIRTUAL);
423  intf->setInterfaceName("virtual");
424  intf->addNeighbor(neighbor);
425  intf->setTransitAreaId(ipv4AddressFromAddressString(getMandatoryFilledAttribute(virtualLinkConfig, "transitAreaID")));
426  intf->setRetransmissionInterval(getIntAttrOrPar(virtualLinkConfig, "retransmissionInterval"));
427  intf->setTransmissionDelay(getIntAttrOrPar(virtualLinkConfig, "interfaceTransmissionDelay"));
428  intf->setHelloInterval(getIntAttrOrPar(virtualLinkConfig, "helloInterval"));
429  intf->setRouterDeadInterval(getIntAttrOrPar(virtualLinkConfig, "routerDeadInterval"));
430 
431  const char *ospfCrcMode = par("crcMode");
432  intf->setCrcMode(parseCrcMode(ospfCrcMode, false));
433 
434  loadAuthenticationConfig(intf, virtualLinkConfig);
435 
436  AreaId transitAreaId = intf->getTransitAreaId();
437  Ospfv2Area *transitArea = ospfRouter->getAreaByID(transitAreaId);
438  if (!transitArea) {
439  delete intf;
440  throw cRuntimeError("Virtual link to router %s cannot be configured through a non-existence transit area '%s' at %s", routerId.str(false).c_str(), transitAreaId.str(false).c_str(), virtualLinkConfig.getSourceLocation());
441  }
442  else if (!transitArea->getExternalRoutingCapability()) {
443  delete intf;
444  throw cRuntimeError("Virtual link to router %s cannot be configured through a stub area '%s' at %s", routerId.str(false).c_str(), transitAreaId.str(false).c_str(), virtualLinkConfig.getSourceLocation());
445  }
446 
447  // add the virtual link to the OSPF data structure
448  Ospfv2Area *backbone = ospfRouter->getAreaByID(BACKBONE_AREAID);
449  if (!backbone) {
450  loadAreaFromXML(asConfig, BACKBONE_AREAID);
452  }
453  backbone->addInterface(intf);
454 }

Referenced by loadConfigFromXML().

◆ par()

cPar& inet::ospfv2::Ospfv2ConfigReader::par ( const char *  name) const
inlineprivate

Member Data Documentation

◆ ift

◆ ospfModule

cModule* inet::ospfv2::Ospfv2ConfigReader::ospfModule = nullptr
private

Referenced by loadConfigFromXML().

◆ ospfRouter


The documentation for this class was generated from the following files:
inet::findContainingNode
cModule * findContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:31
inet::ospfv2::Ospfv2Area::addHostRoute
void addHostRoute(HostRouteParameters &hostRouteParameters)
Definition: Ospfv2Area.h:57
inet::ospfv2::Ospfv2Interface::POINTTOPOINT
@ POINTTOPOINT
Definition: Ospfv2Interface.h:32
inet::ospfv2::Ospfv2ConfigReader::getAreaListFromXML
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: Ospfv2ConfigReader.cc:131
inet::ospfv2::Router::setRFC1583Compatibility
void setRFC1583Compatibility(bool compatibility)
Definition: Ospfv2Router.h:61
inet::ospfv2::Metric
unsigned long Metric
Definition: Ospfv2Common.h:56
inet::ospfv2::Ospfv2ConfigReader::findMatchingConfig
cXMLElement * findMatchingConfig(const cXMLElementList &routerConfig, const NetworkInterface &intf)
Definition: Ospfv2ConfigReader.cc:508
inet::ospfv2::Ospfv2Interface::INTERFACE_UP
@ INTERFACE_UP
Definition: Ospfv2Interface.h:40
inet::ospfv2::Ospfv2ConfigReader::par
cPar & par(const char *name) const
Definition: Ospfv2ConfigReader.h:32
inet::ospfv2::Ospfv2ConfigReader::getStrAttrOrPar
const char * getStrAttrOrPar(const cXMLElement &ifConfig, const char *name) const
Definition: Ospfv2ConfigReader.cc:603
inet::ospfv2::Router::getDefaultRoute
Ipv4Route * getDefaultRoute()
get the default route in the routing table.
Definition: Ospfv2Router.cc:1346
inet::ospfv2::ipv4AddressFromAddressString
Ipv4Address ipv4AddressFromAddressString(const char *charForm)
Definition: Ospfv2Common.h:197
inet::ospfv2::Ospfv2ConfigReader::ospfModule
cModule * ospfModule
Definition: Ospfv2ConfigReader.h:27
inet::parseCrcMode
CrcMode parseCrcMode(const char *crcModeString, bool allowDisable)
Definition: CrcMode.cc:14
inet::ospfv2::Ospfv2ConfigReader::loadHostRoute
void loadHostRoute(const cXMLElement &hostRouteConfig)
Loads the configuration of a host route (a host directly connected to the router).
Definition: Ospfv2ConfigReader.cc:355
inet::ospfv2::Ospfv2Interface::ACTIVE
@ ACTIVE
Definition: Ospfv2Interface.h:62
inet::IInterfaceTable::getInterfaceById
virtual NetworkInterface * getInterfaceById(int id) const =0
Returns an interface by its Id.
inet::ospfv2::Ospfv2ConfigReader::getIntAttrOrPar
int getIntAttrOrPar(const cXMLElement &ifConfig, const char *name) const
Definition: Ospfv2ConfigReader.cc:582
inet::ospfv2::NULL_TYPE
@ NULL_TYPE
Definition: Ospfv2Common.h:59
inet::ospfv2::hexPairToByte
char hexPairToByte(char upperHex, char lowerHex)
Definition: Ospfv2Common.h:282
inet::ospfv2::Ospfv2ConfigReader::loadLoopbackParameters
void loadLoopbackParameters(const cXMLElement &loConfig, NetworkInterface &intf)
Loads the configuration of a loopback interface.
Definition: Ospfv2ConfigReader.cc:388
inet::ospfv2::SIMPLE_PASSWORD_TYPE
@ SIMPLE_PASSWORD_TYPE
Definition: Ospfv2Common.h:60
inet::ospfv2::BACKBONE_AREAID
const AreaId BACKBONE_AREAID(0, 0, 0, 0)
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::Ospfv2ConfigReader::getBoolAttrOrPar
bool getBoolAttrOrPar(const cXMLElement &ifConfig, const char *name) const
Definition: Ospfv2ConfigReader.cc:590
inet::ospfv2::Router::addArea
void addArea(Ospfv2Area *area)
Adds a new Area to the Area list.
Definition: Ospfv2Router.cc:56
inet::ospfv2::Ospfv2Interface::VIRTUAL
@ VIRTUAL
Definition: Ospfv2Interface.h:36
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::IInterfaceTable::getHostModule
virtual cModule * getHostModule() const =0
Returns the host or router this interface table lives in.
inet::Ipv4Address::ALL_OSPF_DESIGNATED_ROUTERS_MCAST
static const Ipv4Address ALL_OSPF_DESIGNATED_ROUTERS_MCAST
224.0.0.6 All OSPF Designated Routers
Definition: Ipv4Address.h:100
inet::contains
bool contains(const std::vector< T > &v, const Tk &a)
Definition: stlutils.h:65
inet::ospfv2::Ospfv2ConfigReader::loadAreaFromXML
void loadAreaFromXML(const cXMLElement &asConfig, AreaId areaID)
Loads basic configuration information for a given area from the config XML.
Definition: Ospfv2ConfigReader.cc:149
inet::ospfv2::Ospfv2ConfigReader::ift
IInterfaceTable * ift
Definition: Ospfv2ConfigReader.h:28
inet::ospfv2::Ospfv2Interface::NBMA
@ NBMA
Definition: Ospfv2Interface.h:34
inet::ospfv2::Ospfv2Interface::PASSIVE
@ PASSIVE
Definition: Ospfv2Interface.h:63
inet::math::round
int round(double d)
Returns an integer that corresponds to rounded double parameter.
Definition: INETMath.h:143
inet::ospfv2::Ospfv2Interface::POINTTOMULTIPOINT
@ POINTTOMULTIPOINT
Definition: Ospfv2Interface.h:35
inet::ospfv2::Ospfv2ConfigReader::initiateDefaultRouteDistribution
void initiateDefaultRouteDistribution()
Distributes the configure default route on this router with AS-External LSAs to other OSPF routers.
Definition: Ospfv2ConfigReader.cc:480
inet::NetworkInterface::getNodeOutputGateId
int getNodeOutputGateId() const
Definition: NetworkInterface.h:234
inet::ospfv2::CRYTOGRAPHIC_TYPE
@ CRYTOGRAPHIC_TYPE
Definition: Ospfv2Common.h:61
inet::IInterfaceTable::getNumInterfaces
virtual int getNumInterfaces() const =0
Returns the number of interfaces.
inet::ospfv2::Ospfv2ConfigReader::ospfRouter
Router * ospfRouter
Definition: Ospfv2ConfigReader.h:29
inet::ospfv2::Ospfv2ConfigReader::joinMulticastGroups
void joinMulticastGroups(int interfaceId)
Definition: Ospfv2ConfigReader.cc:611
inet::ospfv2::Ospfv2Area::addInterface
void addInterface(Ospfv2Interface *intf)
Definition: Ospfv2Area.cc:58
inet::ospfv2::ipv4NetmaskFromAddressString
Ipv4Address ipv4NetmaskFromAddressString(const char *charForm)
Definition: Ospfv2Common.h:202
inet::IInterfaceTable::getInterface
virtual NetworkInterface * getInterface(int pos) const =0
Returns the NetworkInterface specified by an index 0..numInterfaces-1.
inet::ospfv2::Ospfv2Interface::BROADCAST
@ BROADCAST
Definition: Ospfv2Interface.h:33
inet::PatternMatcher
Glob-style pattern matching class, adopted to special OMNeT++ requirements.
Definition: PatternMatcher.h:69
inet::ospfv2::AreaId
Ipv4Address AreaId
Definition: Ospfv2Common.h:130
inet::ospfv2::Ospfv2ConfigReader::loadVirtualLink
void loadVirtualLink(const cXMLElement &virtualLinkConfig, cXMLElement &asConfig)
Loads the configuration of an OSPf virtual link (virtual connection between two backbone routers).
Definition: Ospfv2ConfigReader.cc:410
inet::ospfv2::Ospfv2ConfigReader::getInterfaceByXMLAttributesOf
std::vector< NetworkInterface * > getInterfaceByXMLAttributesOf(const cXMLElement &ifConfig)
Search an NetworkInterface in IInterfaceTable by interface name or toward module name an returns the ...
Definition: Ospfv2ConfigReader.cc:545
inet::ospfv2::Ospfv2ConfigReader::loadExternalRoute
void loadExternalRoute(const cXMLElement &externalRouteConfig)
Loads the configuration information of a route outside of the Autonomous System (external route).
Definition: Ospfv2ConfigReader.cc:308
inet::ospfv2::Ospfv2ConfigReader::loadAuthenticationConfig
void loadAuthenticationConfig(Ospfv2Interface *intf, const cXMLElement &ifConfig)
Loads authenticationType and authenticationKey attributes for a router interface.
Definition: Ospfv2ConfigReader.cc:456
inet::ospfv2::Ospfv2ConfigReader::loadInterfaceParameters
void loadInterfaceParameters(const cXMLElement &ifConfig, NetworkInterface &intf)
Loads OSPF configuration information for a router interface.
Definition: Ospfv2ConfigReader.cc:198
inet::xmlutils::getMandatoryFilledAttribute
const char * getMandatoryFilledAttribute(const cXMLElement &node, const char *attr)
Definition: XMLUtils.cc:160
inet::Ipv4Address::ALL_OSPF_ROUTERS_MCAST
static const Ipv4Address ALL_OSPF_ROUTERS_MCAST
224.0.0.5 All OSPF routers (DR Others)
Definition: Ipv4Address.h:99