Connecting nodes to each other
OMNeT++ is quite strict on how to exchange messages between any nodes (or modules) - you have to explicitly connect them via gates. If you don't, you cannot send messages - full stop, no workarounds, please.
Connecting nodes or modules is a two-step process: defining a gate at the module NED file and connecting two gates in the module (or network) definition one level up. Let us explore an example and connect the two Nodes we defined earlier. In the Node.ned file:
simple Node
{
parameters:
@display("b=60,10,rect,blue,black,2");
gates:
inout my_gate;
}
This is a definition of a input-output gate or, with other words, a bidirectional gate, which can send and receive messages. It is also possible to define an uni-directional gate, but this is rarely required.
In the network.ned file (one level up) we will connect the two gates of the two nodes like this:
network SingleNodeNetwork
{
submodules:
node1: Node;
node2: Node;
connections:
node1.my_gate <--> node2.my_gate;
}
Ready, the nodes are connected and we are ready to send some messages.