Reads interface elements from the configuration file and stores result.
118 std::set<InterfaceEntry *> matchedBefore;
119 cXMLElementList interfaceElements =
configuration->getChildrenByTagName(
"interface");
121 for (
auto & interfaceElements_i : interfaceElements) {
122 std::set<InterfaceEntry *> interfacesSeen;
123 cXMLElement *interfaceElement = interfaceElements_i;
125 const char *hostAttr = interfaceElement->getAttribute(
"hosts");
126 const char *interfaceAttr = interfaceElement->getAttribute(
"names");
127 const char *towardsAttr = interfaceElement->getAttribute(
"towards");
128 const char *amongAttr = interfaceElement->getAttribute(
"among");
129 const char *portsAttr = interfaceElement->getAttribute(
"ports");
132 const char *cost = interfaceElement->getAttribute(
"cost");
133 const char *priority = interfaceElement->getAttribute(
"priority");
134 const char *edge = interfaceElement->getAttribute(
"edge");
137 if (amongAttr && *amongAttr) {
138 if ((hostAttr && *hostAttr) || (towardsAttr && *towardsAttr))
139 throw cRuntimeError(
"The 'hosts'/'towards' and 'among' attributes are mutually exclusive, at %s",
140 interfaceElement->getSourceLocation());
141 towardsAttr = hostAttr = amongAttr;
146 Matcher hostMatcher(hostAttr);
147 Matcher interfaceMatcher(interfaceAttr);
148 Matcher towardsMatcher(towardsAttr);
149 Matcher portsMatcher(portsAttr);
151 std::queue<Node *> Q;
156 Node *currentNode = Q.front();
159 for (
unsigned int i = 0; i < currentNode->interfaceInfos.size(); i++) {
160 InterfaceEntry *ifEntry = currentNode->interfaceInfos[i]->interfaceEntry;
161 if (interfacesSeen.count(ifEntry) == 0 && matchedBefore.count(ifEntry) == 0) {
162 cModule *hostModule = currentNode->module;
163 std::string hostFullPath = hostModule->getFullPath();
164 std::string hostShortenedFullPath = hostFullPath.substr(hostFullPath.find(
'.') + 1);
167 if (ifEntry->getNodeInputGateId() == -1) {
168 interfacesSeen.insert(ifEntry);
172 cGate *gate = hostModule->gate(ifEntry->getNodeInputGateId());
173 std::stringstream ss;
174 ss << gate->getIndex();
175 std::string port = ss.str();
178 if ((hostMatcher.matchesAny() || hostMatcher.matches(hostShortenedFullPath.c_str()) || hostMatcher.matches(hostFullPath.c_str()))
179 && (interfaceMatcher.matchesAny() || interfaceMatcher.matches(ifEntry->getFullName()))
181 && (portsMatcher.matchesAny() || portsMatcher.matches(port.c_str())))
185 currentNode->interfaceInfos[i]->portData.linkCost = atoi(cost);
189 currentNode->interfaceInfos[i]->portData.priority = atoi(priority);
193 currentNode->interfaceInfos[i]->portData.edge = strcmp(edge,
"true") ?
false :
true;
194 EV_DEBUG << hostModule->getFullPath() <<
":" << ifEntry->getFullName() << endl;
196 matchedBefore.insert(ifEntry);
199 interfacesSeen.insert(ifEntry);
200 if (currentNode->interfaceInfos[i]->childNode)
201 Q.push(currentNode->interfaceInfos[i]->childNode);
206 catch (std::exception&
e) {
207 throw cRuntimeError(
"Error in XML <interface> element at %s: %s", interfaceElement->getSourceLocation(),
Node * rootNode
Definition: L2NetworkConfigurator.h:110
bool isNotEmpty(const char *s)
Definition: L2NetworkConfigurator.cc:40
const value< double, units::C > e(1.602176487e-19)
virtual bool linkContainsMatchingHostExcept(InterfaceInfo *currentInfo, Matcher &hostMatcher, cModule *exceptModule)
Definition: L2NetworkConfigurator.cc:239
cXMLElement * configuration
Definition: L2NetworkConfigurator.h:108