You are on page 1of 17

OMNet+

+
Step by Step
Part - 5
By
Mohammed Amer AlBatati

Adding More Nodes


In our network we cant 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 - cont.


Lets 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:

Messages
Depending 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 Usage


cMessage *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 Messages


cMessage *copy = msg->dup();

one slide
one line

Messages Encapsulation
Example
IP

MAC

MAC

IP

Messages Encapsulation
cont.
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 Decapsulation
Example
Assume that the following cPacket was

received as MACdata.
MAC

IP

After using the following decapsulation

statement:

IP

MAC

Define Your Own Message


Assume that you want to add your own

header between IP and MAC.


MyHeader
MAC

Name

IP

ID

Year

Define Your Own Message


Assume that you want to add your own

header between IP and MAC.


MyHeader
MAC

H
W E
A LP
Name N ID
D TE

IP

Year

Define Your Own Message cont.


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

At
Node.cc

You might also like