Reputation: 544
Good Morning!
I'm implementing a simulation for a dynamic distributed storage network, which requires at certain points, that the connections between the modules vary. (e.g. client connects to a node (establishes a new connection) and wants to work with his data, stored on different nodes).
Is there is possibility to establish connections between unconnected but existing gates of two nodes at runtime?
For example:
simple node1 {
parameters:
@display(...);
gates:
input in @loose;
output out @loose;
}
simple node2 {
parameters:
@display(...);
gates:
input in @loose;
output out @loose;
}
Afterwards there would be a boring network definition with no connections. (Don't know if it is possible to have a completely blank definition, but for the minimal example we assume it)
In the C++ file for the modules I wish to create a connection between these nodes depending on a certain condition like (pseudo code):
if(condition){
node1->setConnection(ownGate("out"),node2->getGates("in"),true);
}else{
node1->setConnection(ownGate("out"),node2->getGates("in"),false);
}
I've read the simulation manual of Omnet++ but really can't figure out what to do here ...
Is it possible at all to do this? And how?
Thanks for any help here!
Upvotes: 2
Views: 879
Reputation: 7002
Yes, it is possible to dynamically create a connection between two modules. One may use connectTo() method to do it.
Assuming that the network contains two nodes of both types from your question:
network Test1 {
submodules:
n1 : node1;
n2 : node2;
}
the following code may be used to connect n1
to n2
using bidirectional connection:
// code of n1
if(condition) {
cModule * dest = getModuleByPath("n2");
cGate * destGateIn = dest->gate("in");
cGate * thisGateOut = gate("out");
thisGateOut->connectTo(destGateIn); // forward direction
cGate * destGateOut = dest->gate("out");
cGate * thisGateIn = gate("in");
destGateOut->connectTo(thisGateIn); // reverse direction
}
Upvotes: 0