Anda di halaman 1dari 17

OMNet+

+
Step by Step
Part - 4
By
Mohammed Amer AlBatati

Lets Add some Actions!


Let every node send a packet periodically.
How? Time to go to C++ files.
The model behavior is defined by the user as C++

code.

The class has to be


OMNeT++ via the
macro. The Define_
Module() line should
into .cc or .cpp files
file (.h).

registered with
Define_Module()
always be put
and not header

Main Member Functions


1) initialize(). This method is invoked after
OMNeT++ has set up the network.
2) handleMessage(cMessage *msg). It is
invoked with the message as parameter
whenever
the
module
receives
a
message. handleMessage() is expected to
process the message, and then return.
3) finish(). It is called when the simulation
has terminated successfully, and its
recommended use is the recording of
summary statistics.

Messages Sources
The message can arrive:
1. From another module or
2. From the same module (self-

messages are used to implement


timers).

C++ Simple Code


Add the following code in Node.cc

Why??

Adding Some Details


Each node has a limited energy (e,g.;

100mW).
Each transmission operation consumes energy
(e.g.; 0.8mW per transmission).
Make the initial energy variable.
Make the transmission interval variable.
When a node cannot transmit a packet (the
remaining energy is less than 0.8mW), then it
stops sending data (dies).

Adding Some Details cont.


1. Modifying NED file:

Adding Some Details cont.


2. Modifying .h file

Is it
important??

Adding Some Details cont.


3. Modifying .cc file

Adding Some Details cont.


3. Modifying .cc file

Sir, Can I use


CTRL+SHIFT+F
and CTRL+SPACE
here?

Adding Some Details cont.


3. Modifying .cc file

Sir, Can I use


CTRL+SHIFT+F
Thanks!!
and CTRL+SPACE
here?

Running The Experiment


Be sure that the previous run was closed.
Run the experiment, every thing should work

fine.
The events are shown in the Tkenv view.

Inspect the network


By double-clicking on either node1 or node 2,

we can see the detailed implementation of our


Nodes.
But the variables (tx_interval and energy) are
not there.
To watch them, add WATCH(var) statement

WATCH Macro
OMNeT++ provides WATCH() and a set of

other macros to allow variables to


inspectable in Tkenv.
Always put watches in initialize()
Save and
Syntax: WATCH(var)
Rebuild

be

Choosing Different Values


In previous experiments, we were using the

default values of both Tx_interval and Energy.


Using different parameters can be achieved
using the INI file.
Open omnetpp.ini file.
There are two modes, open the Source mode.

Choosing Different Values


In previous experiments, we were using the

default values of both Tx_interval and Energy.


Using different parameters can be achieved
using the INI file.
Open omnetpp.ini file.
There are two
Wow,
modes, open the Source mode.
CTRL+SPACE
would help much
here.

Ya
I know!

Using Wildcard Patterns


Models can have a large number of

parameters to be configured, and it would be


tedious to set them one-by-one in
omnetpp.ini.
OMNeT++ supports wildcard patterns which
allow for setting several model parameters at
once.

More Configuration Sections


Assume we want to test our system (Node)

with two types of traffic: high and low. We can


create a separate section for each type as
follows:

For every run, we need to select a specific Config

name .