Reads interface elements from the configuration file and stores result.
97 std::set<NetworkInterface *> matchedBefore;
98 cXMLElementList interfaceElements =
configuration->getChildrenByTagName(
"interface");
100 for (
auto& interfaceElements_i : interfaceElements) {
101 std::set<NetworkInterface *> interfacesSeen;
102 cXMLElement *interfaceElement = interfaceElements_i;
104 const char *hostAttr = interfaceElement->getAttribute(
"hosts");
105 const char *interfaceAttr = interfaceElement->getAttribute(
"names");
106 const char *towardsAttr = interfaceElement->getAttribute(
"towards");
107 const char *amongAttr = interfaceElement->getAttribute(
"among");
108 const char *portsAttr = interfaceElement->getAttribute(
"ports");
111 const char *cost = interfaceElement->getAttribute(
"cost");
112 const char *priority = interfaceElement->getAttribute(
"priority");
113 const char *edge = interfaceElement->getAttribute(
"edge");
116 if (amongAttr && *amongAttr) {
117 if ((hostAttr && *hostAttr) || (towardsAttr && *towardsAttr))
118 throw cRuntimeError(
"The 'hosts'/'towards' and 'among' attributes are mutually exclusive, at %s",
119 interfaceElement->getSourceLocation());
120 towardsAttr = hostAttr = amongAttr;
125 Matcher hostMatcher(hostAttr);
126 Matcher interfaceMatcher(interfaceAttr);
127 Matcher towardsMatcher(towardsAttr);
128 Matcher portsMatcher(portsAttr);
130 std::queue<Node *> Q;
135 Node *currentNode = Q.front();
138 for (
unsigned int i = 0; i < currentNode->interfaceInfos.size(); i++) {
139 NetworkInterface *ifEntry = currentNode->interfaceInfos[i]->networkInterface;
140 if (interfacesSeen.count(ifEntry) == 0 && matchedBefore.count(ifEntry) == 0) {
141 cModule *hostModule = currentNode->module;
142 std::string hostFullPath = hostModule->getFullPath();
143 std::string hostShortenedFullPath = hostFullPath.substr(hostFullPath.find(
'.') + 1);
146 if (ifEntry->getNodeInputGateId() == -1) {
147 interfacesSeen.insert(ifEntry);
151 cGate *gate = hostModule->gate(ifEntry->getNodeInputGateId());
152 std::stringstream ss;
153 ss << gate->getIndex();
154 std::string port = ss.str();
157 if ((hostMatcher.matchesAny() || hostMatcher.matches(hostShortenedFullPath.c_str()) || hostMatcher.matches(hostFullPath.c_str()))
158 && (interfaceMatcher.matchesAny() || interfaceMatcher.matches(ifEntry->getInterfaceName()))
160 && (portsMatcher.matchesAny() || portsMatcher.matches(port.c_str())))
163 if (!opp_isempty(cost))
164 currentNode->interfaceInfos[i]->portData.linkCost = atoi(cost);
167 if (!opp_isempty(priority))
168 currentNode->interfaceInfos[i]->portData.priority = atoi(priority);
171 if (!opp_isempty(edge))
172 currentNode->interfaceInfos[i]->portData.edge = strcmp(edge,
"true") ? false :
true;
173 EV_DEBUG << hostModule->getFullPath() <<
":" << ifEntry->getInterfaceName() << endl;
175 matchedBefore.insert(ifEntry);
178 interfacesSeen.insert(ifEntry);
179 if (currentNode->interfaceInfos[i]->childNode)
180 Q.push(currentNode->interfaceInfos[i]->childNode);
185 catch (std::exception&
e) {
186 throw cRuntimeError(
"Error in XML <interface> element at %s: %s", interfaceElement->getSourceLocation(),