void NetBuilder::buildNetwork(cModule *parent)
{
<code>const char* xmlPath = par("xmlConfig");
cXMLElement* xmlRoot = getEnvir()->getXMLDocument(xmlPath);
if (xmlRoot == nullptr) {
EV << "XML file not found or invalid format." << endl;
return;
}
for (cXMLElement* node : xmlRoot->getChildrenByTagName("node")) {
const char* id = node->getAttribute("id");
const char* type = node->getAttribute("type");
cModuleType* moduleType = cModuleType::get(type);
cModule* nodeModule = moduleType->create(id, parent);
nodeModule->finalizeParameters();
}
for (cXMLElement* link : xmlRoot->getChildrenByTagName("link")) {
const char* from = link->getAttribute("from");
const char* to = link->getAttribute("to");
const char* bandwidth = link->getAttribute("bandwidth");
const char* delay = link->getAttribute("delay");
cModule *fromModule = getParentModule()->getSubmodule(from);
cModule *toModule = getParentModule()->getSubmodule(to);
cGate *srcIn, *srcOut, *dstIn, *dstOut;
fromModule->getOrCreateFirstUnconnectedGatePair("ethg", false, true, srcIn, srcOut);
toModule->getOrCreateFirstUnconnectedGatePair("ethg", false, true, dstIn, dstOut);
cDatarateChannel *channel1 = cDatarateChannel::create("channel1");
channel1->setDatarate(atof(bandwidth));
channel1->setDelay(atof(delay));
srcOut->connectTo(dstIn, channel1);
cDatarateChannel *channel2 = cDatarateChannel::create("channel2");
channel2->setDatarate(atof(bandwidth));
channel2->setDelay(atof(delay));
dstOut->connectTo(srcIn, channel2);
}
cModuleType* configuratorType = cModuleType::get("inet.networklayer.configurator.ipv4.Ipv4NetworkConfigurator");
cModule* configuratorModule = configuratorType->create("configurator", parent);
configuratorModule->finalizeParameters();
cModuleType* canvasType = cModuleType::get("inet.visualizer.canvas.integrated.IntegratedCanvasVisualizer");
cModule* canvasModule = canvasType->create("visualizer", parent);
canvasModule->finalizeParameters();
parent->callInitialize();
</code>
<code>const char* xmlPath = par("xmlConfig");
cXMLElement* xmlRoot = getEnvir()->getXMLDocument(xmlPath);
if (xmlRoot == nullptr) {
EV << "XML file not found or invalid format." << endl;
return;
}
for (cXMLElement* node : xmlRoot->getChildrenByTagName("node")) {
const char* id = node->getAttribute("id");
const char* type = node->getAttribute("type");
cModuleType* moduleType = cModuleType::get(type);
cModule* nodeModule = moduleType->create(id, parent);
nodeModule->finalizeParameters();
}
for (cXMLElement* link : xmlRoot->getChildrenByTagName("link")) {
const char* from = link->getAttribute("from");
const char* to = link->getAttribute("to");
const char* bandwidth = link->getAttribute("bandwidth");
const char* delay = link->getAttribute("delay");
cModule *fromModule = getParentModule()->getSubmodule(from);
cModule *toModule = getParentModule()->getSubmodule(to);
cGate *srcIn, *srcOut, *dstIn, *dstOut;
fromModule->getOrCreateFirstUnconnectedGatePair("ethg", false, true, srcIn, srcOut);
toModule->getOrCreateFirstUnconnectedGatePair("ethg", false, true, dstIn, dstOut);
cDatarateChannel *channel1 = cDatarateChannel::create("channel1");
channel1->setDatarate(atof(bandwidth));
channel1->setDelay(atof(delay));
srcOut->connectTo(dstIn, channel1);
cDatarateChannel *channel2 = cDatarateChannel::create("channel2");
channel2->setDatarate(atof(bandwidth));
channel2->setDelay(atof(delay));
dstOut->connectTo(srcIn, channel2);
}
cModuleType* configuratorType = cModuleType::get("inet.networklayer.configurator.ipv4.Ipv4NetworkConfigurator");
cModule* configuratorModule = configuratorType->create("configurator", parent);
configuratorModule->finalizeParameters();
cModuleType* canvasType = cModuleType::get("inet.visualizer.canvas.integrated.IntegratedCanvasVisualizer");
cModule* canvasModule = canvasType->create("visualizer", parent);
canvasModule->finalizeParameters();
parent->callInitialize();
</code>
const char* xmlPath = par("xmlConfig");
cXMLElement* xmlRoot = getEnvir()->getXMLDocument(xmlPath);
if (xmlRoot == nullptr) {
EV << "XML file not found or invalid format." << endl;
return;
}
for (cXMLElement* node : xmlRoot->getChildrenByTagName("node")) {
const char* id = node->getAttribute("id");
const char* type = node->getAttribute("type");
cModuleType* moduleType = cModuleType::get(type);
cModule* nodeModule = moduleType->create(id, parent);
nodeModule->finalizeParameters();
}
for (cXMLElement* link : xmlRoot->getChildrenByTagName("link")) {
const char* from = link->getAttribute("from");
const char* to = link->getAttribute("to");
const char* bandwidth = link->getAttribute("bandwidth");
const char* delay = link->getAttribute("delay");
cModule *fromModule = getParentModule()->getSubmodule(from);
cModule *toModule = getParentModule()->getSubmodule(to);
cGate *srcIn, *srcOut, *dstIn, *dstOut;
fromModule->getOrCreateFirstUnconnectedGatePair("ethg", false, true, srcIn, srcOut);
toModule->getOrCreateFirstUnconnectedGatePair("ethg", false, true, dstIn, dstOut);
cDatarateChannel *channel1 = cDatarateChannel::create("channel1");
channel1->setDatarate(atof(bandwidth));
channel1->setDelay(atof(delay));
srcOut->connectTo(dstIn, channel1);
cDatarateChannel *channel2 = cDatarateChannel::create("channel2");
channel2->setDatarate(atof(bandwidth));
channel2->setDelay(atof(delay));
dstOut->connectTo(srcIn, channel2);
}
cModuleType* configuratorType = cModuleType::get("inet.networklayer.configurator.ipv4.Ipv4NetworkConfigurator");
cModule* configuratorModule = configuratorType->create("configurator", parent);
configuratorModule->finalizeParameters();
cModuleType* canvasType = cModuleType::get("inet.visualizer.canvas.integrated.IntegratedCanvasVisualizer");
cModule* canvasModule = canvasType->create("visualizer", parent);
canvasModule->finalizeParameters();
parent->callInitialize();
}
The routes are correct generated, but when transmitting,the error is posted:<!> (omnetpp::cIdealChannel)StaticNet.n1.ipv4.transportIn.channel: Channel not initialized (did you forget to invoke callInitialize() for a dynamically created channel or a dynamically created compound module that contains it?) — in module (inet::MessageDispatcher) StaticNet.n1.tn (id=25), at t=0.5s, event #4