Hello,
I am trying to use cTopology::calculateUnweightedSingleShortestPathTo(Node *node) to find the shortest path between two nodes. I have previously worked on code which utilized the function and there were no issues. Now I am writing all new code and there are issues. The network I am simulating is more complex than the example I am about to present but when I thought it would be a good idea to get things working with a simple case first.
The problem is that the shortest path algorithm doesn't seem to find any paths. I have each Device send a self message at the beginning of the simulation. Then in handleMessage I have cTopology extract the topology by module type "Device". Then for each remote Device I have cTopology calculate shortest path but when I check the number of paths it is always 0.
Just to make sure that everything is connected I tried to have the nodes duplicate received messages and then send them out on all outgoing gates. Messages make it from each node to each other node without problems.
My NED files:
simple Device
{
gates:
inout port[];
}
network OnlyDevices
{
@display("bgb=327,187");
submodules:
device0: Device {
@display("p=51,82");
gates:
port[1];
}
device1: Device {
@display("p=151,82");
gates:
port[2];
}
device2: Device {
@display("p=251,82");
gates:
port[1];
}
connections:
device0.port[0] <--> device1.port[0];
device1.port[1] <--> device2.port[0];
}
Here is Device.cc:
#include "Device.h"
Define_Module(Device);
void Device::initialize()
{
scheduleAt(simTime(), new cMessage("start"));
}
void Device::handleMessage(cMessage *msg)
{
std::vector<std::string> nedTypes;
cTopology *topology = new cTopology("topo");
nedTypes.push_back("Device");
topology->extractByNedTypeName(nedTypes);
int numNodes = topology->getNumNodes();
EV << this->getParentModule()->getName() << "." << this->getName() << "\n";
for (int i = 0; i < numNodes; i++) {
cTopology::Node *node = topology->getNode(i);
if (node->getModule() != this) {
topology->calculateUnweightedSingleShortestPathsTo(node);
EV << " number of paths to "
<< node->getModule()->getParentModule()->getName()
<< "." << node->getModule()->getName() << ": "
<< node->getNumPaths() << "\n";
}
}
delete topology;
}
Here is the simulation output:
Initializing module OnlyDevices, stage 0
Initializing module OnlyDevices.device0, stage 0
Initializing module OnlyDevices.device1, stage 0
Initializing module OnlyDevices.device2, stage 0
** Event #1 T=0 OnlyDevices.device0 (Device, id=2), on selfmsg `start' (cMessage, id=0)
OnlyDevices.device0
number of paths to OnlyDevices.device1: 0
number of paths to OnlyDevices.device2: 0
** Event #2 T=0 OnlyDevices.device1 (Device, id=3), on selfmsg `start' (cMessage, id=1)
OnlyDevices.device1
number of paths to OnlyDevices.device0: 0
number of paths to OnlyDevices.device2: 0
** Event #3 T=0 OnlyDevices.device2 (Device, id=4), on selfmsg `start' (cMessage, id=2)
OnlyDevices.device2
number of paths to OnlyDevices.device0: 0
number of paths to OnlyDevices.device1: 0
<!> No more events -- simulation ended at event #4, t=0.
** Calling finish() methods of modules
I don't know what I"m missing here. Thanks.