INET Framework for OMNeT++/OMNEST
stpXMLparser.cc
Go to the documentation of this file.
00001 /*
00002  * stpXMLparser.cpp
00003  *
00004  *  Created on: 17.5.2011
00005  *      Author: aranel
00006  */
00007 
00008 #include "stpXMLparser.h"
00009 
00010 stpXMLparser::stpXMLparser(Stp * _stp) {
00011         stp = _stp;
00012 }
00013 
00014 stpXMLparser::~stpXMLparser() {
00015 
00016 }
00017 
00018 
00019 bool stpXMLparser::parse(const char * filename, const char * switchID) {
00020 
00021         cXMLElement* switchConfig = ev.getXMLDocument(filename);
00022         if (switchConfig == NULL) {
00023                 return false;
00024         }
00025 
00026         std::string switchXPath("Switch[@id='");
00027         switchXPath += switchID;
00028         switchXPath += "']";
00029 
00030         /* FIND root of current switch's configuration subtree */
00031         cXMLElement* switchNode = switchConfig->getElementByPath(switchXPath.c_str());
00032         if (switchNode == NULL) {
00033                 return false;
00034                 //opp_error("No configuration for Switch ID: %s", switchID);
00035         }
00036 
00037 
00038         /* FIND section Interfaces */
00039         cXMLElement* stpNode = switchNode->getFirstChildWithTag("STP");
00040         if (stpNode != NULL) {
00041                 parseSTP(stpNode);
00042         }
00043 
00044         return true;
00045 
00046 }
00047 
00048 void stpXMLparser::parseSTP(cXMLElement * node) {
00049         std::string tmp, instance, bridgePriority, fwDelay, helloTime,
00050                                 maxAge, portPriority, linkCost,subNodeName;
00051 
00052         std::vector<unsigned int> portPriList, priPortList; // list of port priorities, list of ports for adressing
00053         std::vector<unsigned int> portCostList, costPortList;// list of link costs, list of links for adressing
00054 
00055         unsigned int inst=0;
00056 
00057         cXMLElementList instConfig = node->getChildren();
00058         cXMLElementList::iterator it;
00059 
00060         for(it = instConfig.begin(); it != instConfig.end(); it++) {
00061                 subNodeName  = (*it)->getTagName();
00062 
00063                 tmp.clear();
00064                 instance.clear();
00065                 bridgePriority.clear();
00066                 fwDelay.clear();
00067                 helloTime.clear();
00068                 maxAge.clear();
00069                 portPriority.clear();
00070                 linkCost.clear();
00071 
00072                 portPriList.clear();
00073                 priPortList.clear();
00074                 portCostList.clear();
00075                 costPortList.clear();
00076 
00077                 if (subNodeName == "Instance" && (*it)->getAttribute("id")) {
00078                         instance = (*it)->getAttribute("id");
00079 
00080                         cXMLElementList instDetails = (*it)->getChildren();
00081                         cXMLElementList::iterator instElemIt;
00082                         for (instElemIt = instDetails.begin(); instElemIt != instDetails.end(); instElemIt++) {
00083                           std::string nodeName = (*instElemIt)->getTagName();
00084 
00085                           if (nodeName=="BridgePriority") {
00086                                 bridgePriority = (*instElemIt)->getNodeValue();
00087                           }
00088 
00089                           if (nodeName=="PortPriority") {
00090                                 priPortList.push_back(atoi((*instElemIt)->getAttribute("id")));
00091                                 portPriList.push_back(atoi((*instElemIt)->getNodeValue()));
00092                           }
00093                           if (nodeName=="LinkCost") {
00094                                 costPortList.push_back(atoi((*instElemIt)->getAttribute("id")));
00095                                 portCostList.push_back(atoi((*instElemIt)->getNodeValue()));
00096                           }
00097                           if (nodeName=="ForwardDelay") {
00098                                   fwDelay = (*instElemIt)->getNodeValue();
00099                           }
00100                           if (nodeName=="HelloTimer") {
00101                                   helloTime = (*instElemIt)->getNodeValue();
00102                           }
00103                           if (nodeName=="MaxAge") {
00104                                   maxAge = (*instElemIt)->getNodeValue();
00105                           }
00106 
00107 
00108                         } // instDetail for
00109 
00110                 } // instConfig for
00111 
00112                 if (instance.empty() == true) {
00113                         continue;
00114                 }
00115 
00116                 inst = atoi(instance.c_str());
00117 
00118                 if (bridgePriority.empty() == false) {
00119                         stp->setBridgePriority(inst, atoi(bridgePriority.c_str()));
00120                 }
00121                 if (fwDelay.empty() == false) {
00122                         stp->setForwardDelay(inst, atoi(fwDelay.c_str()));
00123                 }
00124                 if (maxAge.empty() == false) {
00125                         stp->setMaxAge(inst, atoi(maxAge.c_str()));
00126                 }
00127                 if (helloTime.empty() == false) {
00128                         stp->setHelloTime(inst, atoi(helloTime.c_str()));
00129                 }
00130 
00131                 if (portPriList.empty() == false) {
00132                         stp->setPortPriority(inst, priPortList, portPriList);
00133                 }
00134 
00135                 if (portPriList.empty() == false) {
00136                         stp->setPortPriority(inst, costPortList, portCostList);
00137                 }
00138 
00139 
00140         }
00141 
00142 
00143 
00144 }
00145