tutorial 4 adding some details

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

Upload: mohd-batati

Post on 13-Jan-2017

15.277 views

Category:

Technology


0 download

TRANSCRIPT

ByMohammed Amer Al-

Batati

2012

OMNet++

Step by Step

Part - 4

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.

Let’s Add some Actions!

The class has to be registered with OMNeT++ via the Define_Module() macro. The Define_Module() line should always be put into .cc or .cpp files and not header file (.h).

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.

Main Member Functions

The message can arrive:1. From another module or2. From the same module (self-

messages are used to implement timers).

Messages Sources

Add the following code in Node.cc

C++ Simple Code

Why??

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

1. Modifying NED file:

Adding Some Details – cont.

2. Modifying .h file

Adding Some Details – cont.

Is it important??

3. Modifying .cc file

Adding Some Details – cont.

3. Modifying .cc file

Adding Some Details – cont.Sir, Can I use CTRL+SHIFT+F and CTRL+SPACE here?

3. Modifying .cc file

Adding Some Details – cont.Sir, Can I use CTRL+SHIFT+F and CTRL+SPACE here?

Thanks!!

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

Running The Experiment

OMNeT++ provides WATCH() and a set of other macros to allow variables to be inspectable in Tkenv.

Always put watches in initialize()Syntax: WATCH(var)

WATCH Macro

Save and Rebuild

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 modes, open the Source mode.

Choosing Different Values

Wow, CTRL+SPACE would help much here. Ya…

I know!

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.

Using Wildcard Patterns

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’ .

More Configuration Sections