17
By Mohammed Amer Al- Batati 2012 OMNet++ Step by Step Part - 5

Tutorial 5 adding more nodes

Embed Size (px)

Citation preview

Page 1: Tutorial 5   adding more nodes

ByMohammed Amer Al-

Batati

2012

OMNet++

Step by Step

Part - 5

Page 2: Tutorial 5   adding more nodes

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

Page 3: Tutorial 5   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.

Page 4: Tutorial 5   adding more nodes

Goto to “mynetwork”-> add more nodes -> connect them to each other then run the experiment. As follows:

Adding More Nodes - cont.

Page 5: Tutorial 5   adding more nodes

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.

Page 6: Tutorial 5   adding more nodes

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

Page 7: Tutorial 5   adding more nodes

Messages – Duplicating MessagescMessage *copy = msg->dup();

… one slide……one line…

Page 8: Tutorial 5   adding more nodes

Messages – EncapsulationExample

IP

MAC

MAC IP

Page 9: Tutorial 5   adding more nodes

Inspecting cMessage objects (previous code).

Messages – Encapsulation – cont.

Page 10: Tutorial 5   adding more nodes

Modify Node.cc code to include the encapsulation example.

Save, build and run.

Messages – Encapsulation – cont.

Page 11: Tutorial 5   adding more nodes

Inspecting cPacekt objects (new code).

Messages – Encapsulation – cont.

Page 12: Tutorial 5   adding more nodes

Messages – DecapsulationExampleAssume that the following cPacket was

received as “MACdata”.

After using the following decapsulation statement:

MAC IP

IP MAC

Page 13: Tutorial 5   adding more nodes

Assume that you want to add your own header between IP and MAC.

Define Your Own Message

IPMAC

MyHeader

Name ID Year

Page 14: Tutorial 5   adding more nodes

Assume that you want to add your own header between IP and MAC.

Define Your Own Message

IPMAC

MyHeader

Name ID Year

HELPWANTED

Page 15: Tutorial 5   adding more nodes

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.

Page 16: Tutorial 5   adding more nodes

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.

Page 17: Tutorial 5   adding more nodes

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