Download - Tutorial 5 adding more nodes
ByMohammed Amer Al-
Batati
2012
OMNet++
Step by Step
Part - 5
In our network we can’t add more than two nodes.
The reason is that, Node.ned defines only one input gate and one output gate.
The solution is to use gate vectors instead of single gates.
A more advanced solution is to use inout gate, which is basically an input and an output gate glued together.
Adding More Nodes
Let’s modify our plan. When a node decides to transmit a message, it have to select a random destination. Therefore, we need to modify Node.cc file.
Adding More Nodes - cont.
Goto to “mynetwork”-> add more nodes -> connect them to each other then run the experiment. As follows:
Adding More Nodes - cont.
MessagesDepending on the model domain, message
objects represent events, packets, commands, jobs, customers or other kinds of entities.
There are cMessage and cPacket Classes.The cPacket class extends cMessage.cPacket is used for network packets (frames,
datagrams, transport packets, etc.) in a communication network, and cMessage is used for everything else.For example, encapsulation and decapsulation
operations are only used with cPacket.
Messages – Basic UsagecMessage *msg = new cMessage();cMessage *msg = new cMessage("timer");cMessage *msg = new cMessage("timer",
kind);msg->setKind( kind );msg->setBitLength( length );msg->setTimestamp( simtime );int K = msg->getKind();int L = msg->getBitLength();simtime_t T = msg->getTimestamp();…etc
Messages – Duplicating MessagescMessage *copy = msg->dup();
… one slide……one line…
Messages – EncapsulationExample
IP
MAC
MAC IP
Inspecting cMessage objects (previous code).
Messages – Encapsulation – cont.
Modify Node.cc code to include the encapsulation example.
Save, build and run.
Messages – Encapsulation – cont.
Inspecting cPacekt objects (new code).
Messages – Encapsulation – cont.
Messages – DecapsulationExampleAssume that the following cPacket was
received as “MACdata”.
After using the following decapsulation statement:
MAC IP
IP MAC
Assume that you want to add your own header between IP and MAC.
Define Your Own Message
IPMAC
MyHeader
Name ID Year
Assume that you want to add your own header between IP and MAC.
Define Your Own Message
IPMAC
MyHeader
Name ID Year
HELPWANTED
From Project Explorer: right-click on myproject -> New -> Message Definition (.msg) -> name it (myHeader) -> Next -> Select New Message File -> Next -> Finish.
Add our fields:
Save and Build.
Define Your Own Message - cont.
OMNet++ generates .cc and .h (myHeader_m.cc and myHeader_m.h).
Your needs are generated.
How to use it.
Define Your Own Message - cont.
To use your new message:1. Include the needed header.2. Use “myHeader” as “cPacket”3. That is it!
Insert it between IP and MAC
Define Your Own Message - cont.
At Node.cc