INET Framework for OMNeT++/OMNEST
RoutingTableXmlParser Class Reference

#include <RoutingTableXmlParser.h>

List of all members.

Public Member Functions

 RoutingTableXmlParser (IInterfaceTable *ift, IRoutingTable *rt)
virtual bool readRoutingTableFromXml (const char *filename, const char *RouterId)
void readInterfaceFromXml (cXMLElement *Node)
void readStaticRouteFromXml (cXMLElement *Node)

Protected Attributes

IInterfaceTableift
IRoutingTablert

Detailed Description

Parses a routing table file into a routing table.

Definition at line 29 of file RoutingTableXmlParser.h.


Constructor & Destructor Documentation

Constructor

Definition at line 32 of file RoutingTableXmlParser.cc.

{
    ift = i;
    rt = r;
}

Member Function Documentation

void RoutingTableXmlParser::readInterfaceFromXml ( cXMLElement *  Node)

Definition at line 68 of file RoutingTableXmlParser.cc.

Referenced by readRoutingTableFromXml().

{
    InterfaceEntry* ie;

    cXMLElementList intConfig = Node->getChildren();
    for (cXMLElementList::iterator intConfigIt = intConfig.begin(); intConfigIt != intConfig.end(); intConfigIt++)
    {
      std::string nodeName = (*intConfigIt)->getTagName();
      if (nodeName == "Interface" && (*intConfigIt)->getAttribute("name"))
      {
        std::string intName=(*intConfigIt)->getAttribute("name");
        std::string typeName=intName.substr(0,3);
        
        ie=ift->getInterfaceByName(intName.c_str());
        
        if (!ie)
          opp_error("Error in routing file: interface name `%s' not registered by any L2 module", intName.c_str());
        
        //implicitne nastavenia
        if (typeName=="eth")
              ie->setBroadcast(true);
        if (typeName=="ppp")
              ie->setPointToPoint(true);
              
        IPv4InterfaceData::IPAddressVector mcg = ie->ipv4Data()->getMulticastGroups();
        
        //registracia do multicast groups
        mcg.push_back(IPAddress("224.0.0.1"));
        mcg.push_back(IPAddress("224.0.0.2"));
        ie->ipv4Data()->setMulticastGroups(mcg);
        
        ie->ipv4Data()->setMetric(1); 
        ie->setMtu(1500);
        
        cXMLElementList ifDetails = (*intConfigIt)->getChildren();  
        for (cXMLElementList::iterator ifElemIt = ifDetails.begin(); ifElemIt != ifDetails.end(); ifElemIt++) 
        {
          std::string nodeName = (*ifElemIt)->getTagName();
          
          if (nodeName=="IPAddress") 
          {
            ie->ipv4Data()->setIPAddress(IPAddress((*ifElemIt)->getNodeValue()));
          }
          
          if (nodeName=="Mask") 
          {
            ie->ipv4Data()->setNetmask(IPAddress((*ifElemIt)->getNodeValue()));
          }
          
          if (nodeName=="MTU") 
          {
            ie->setMtu(atoi((*ifElemIt)->getNodeValue()));
          }
            
        }
        
      }
    }    
}
bool RoutingTableXmlParser::readRoutingTableFromXml ( const char *  filename,
const char *  RouterId 
) [virtual]

Read Routing Table file; return 0 on success, -1 on error

Definition at line 39 of file RoutingTableXmlParser.cc.

Referenced by AnsaRoutingTable::initialize().

{
    cXMLElement* routerConfig = ev.getXMLDocument(filename);
    if (routerConfig == NULL) {
        return false;
    }

    // load information on this router
    std::string routerXPath("Router[@id='");
    routerXPath += RouterId;
    routerXPath += "']";

    cXMLElement* routerNode = routerConfig->getElementByPath(routerXPath.c_str());
    if (routerNode == NULL)
        opp_error("No configuration for Router ID: %s", RouterId);

    cXMLElement* IntNode = routerNode->getFirstChildWithTag("Interfaces");
    if (IntNode)
        readInterfaceFromXml(IntNode);

    cXMLElement* routingNode = routerNode->getFirstChildWithTag("Routing");
    if (routingNode){
       cXMLElement* staticNode = routingNode->getFirstChildWithTag("Static");
       if (staticNode)
          readStaticRouteFromXml(staticNode);
    }
    return true;
}
void RoutingTableXmlParser::readStaticRouteFromXml ( cXMLElement *  Node)

Definition at line 128 of file RoutingTableXmlParser.cc.

Referenced by readRoutingTableFromXml().

{
  cXMLElementList intConfig = Node->getChildren();
  for (cXMLElementList::iterator intConfigIt = intConfig.begin(); intConfigIt != intConfig.end(); intConfigIt++)
  {
    std::string nodeName = (*intConfigIt)->getTagName();
    if (nodeName == "Route")
    {
        IPRoute *e = new IPRoute();
        cXMLElementList ifDetails = (*intConfigIt)->getChildren();  
        for (cXMLElementList::iterator ifElemIt = ifDetails.begin(); ifElemIt != ifDetails.end(); ifElemIt++) 
        {
          std::string nodeName = (*ifElemIt)->getTagName();
          
          if (nodeName=="NetworkAddress") 
          {
            e->setHost(IPAddress((*ifElemIt)->getNodeValue()));
          }
          
          if (nodeName=="NetworkMask") 
          {
            e->setNetmask(IPAddress((*ifElemIt)->getNodeValue()));
          }
          
          if (nodeName=="NextHopAddress") 
          {
            e->setGateway(IPAddress((*ifElemIt)->getNodeValue()));
            InterfaceEntry *intf=NULL;
            for (int i=0; i<ift->getNumInterfaces(); i++)
            {
              intf = ift->getInterface(i);
              if (((intf->ipv4Data()->getIPAddress()).doAnd(intf->ipv4Data()->getNetmask()))==((e->getGateway()).doAnd(intf->ipv4Data()->getNetmask())))
                  break;
               
            }
            if (intf)
              e->setInterface(intf);
            else
              opp_error("Error.");
            e->setMetric(1);
          }
          if (nodeName=="ExitInterface") 
          {
            InterfaceEntry *ie=ift->getInterfaceByName((*ifElemIt)->getNodeValue());
            if (!ie)
                opp_error("Interface does not exists");
            
            e->setInterface(ie);
            e->setGateway(IPAddress::UNSPECIFIED_ADDRESS);
            e->setMetric(0);
          }
          if (nodeName=="StaticRouteMetric") 
          {
            e->setMetric(atoi((*ifElemIt)->getNodeValue()));
          }  
        }
        rt->addRoute(e);
    }
    
  }
}

Member Data Documentation


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