ByMohammed Amer Al-
Batati
2012
OMNet++
Step by Step
Part - 6
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
cQueue Example:
Iterators
Queues – cont.
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?{
}}
Expandable Array
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.
Let’s record the node power after every transmission operation. To do that add the following:1. cOutVector TxEnergy;// in Node.h2. TxEnergy.setName("NodePower");// in Node.cc (initialize())3. TxEnergy.record(energy);// after updating node energy
Save, build, and run.
Result Recording and Analysis
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
Click Wildcard to add all other VEC files in single ANF file.
Browse data to get the following results
Output Vectors – cont.
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().
Histograms
Let’s 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
Save, Build and run
Play with the properties to get:
Output Scalars – cont.
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.
Eventlog and Sequence Chart
ELOG files will be generated.
Double-Click one of them to watch the sequence chart.
Sequence Chart
Top Related