You are on page 1of 12

OMNet+

+
Step by Step
Part - 6
By
Mohammed Amer AlBatati

Queues
cQueue is a container class that acts as a queue.
The basic cQueue member functions:
insert(obj), inserts an object into the queue head.
pop(), returns and removes object from the front.
remove(obj), removes that object from the queue.
length(), returns the number of items in the queue.
empty(), tells whether there is anything in the

queue.
insertBefore(obj_where, obj_what)
insertAfter(obj_where, obj_what)
front(), returns pointer to the object at the front.
back() , returns pointer to the object at the back.

Queues cont.
cQueue Example:

Iterators

Expandable Array
cArray is a container class that holds objects derived from cObject.
cArray works as an array, but it grows automatically when it

becomes full.
The basic usage:
cArray array("array"); // Creating an array
int index = array.add( obj ); // Adding an object
int index = array.find(obj);// Finding an object
array.remove (obj)// Remove an object

Iteration

for (int i=0; i<array.size(); i++)


{
if (array[i]) // is this position used?
{
}
}

Result Recording and Analysis


There are two main types of outputs: vectors

and scalars.
output vectors are to record time series data
and output scalars are supposed to record a
single value per simulation run.
Lets record the node power after every
transmission operation. To do that add the
following:
1.
2.
3.

cOutVector TxEnergy;// in Node.h


TxEnergy.setName("NodePower");// in Node.cc (initialize())
TxEnergy.record(energy);// after updating node energy

Save, build, and run.

Output Vectors
A folder called results will be generated.

Click one of VEC files to generate an analysis file

(.anf).
Select result as parent folder -> name it-> click
finish.

Output Vectors cont.


Click Wildcard to add all other VEC files in

single ANF file.

Browse data to get the following results

Histograms
You may want to record the distribution as a

histogram (not as a time series).


Syntax: cHistogram hData;
hData.collect(value);// to insert a new value.

Other functions can be used to get the statics,

for example:
hData.getCount(), hData.getMin(),
hData.getMax(), hData.getMean(),
hData.getStddev(), hData.getVariance(),
hData.getSum(), hData.getSqrSum().

Output Scalars
Lets record node life time, which is the time

that a node takes before it dies:


1. At Node.h

2. At Node.cc

Output Scalars cont.


Save, Build and run

Play with the properties to get:

Eventlog and Sequence Chart


An eventlog file contains a log of messages

sent during the simulation and the details of


events that prompted their sending or
reception.
The Sequence Chart displays eventlog files in
a graphical form.
Add: record-eventlog = true # In omnetpp.ini

Save and run.

Sequence Chart
ELOG files will be generated.

Double-Click one of them to watch the sequence

chart.

You might also like