Tutorial Ii: Omnet++ (Part-2)
Tutorial Ii: Omnet++ (Part-2)
1
Turning it into a real network
2
Step 10: More Than Two Nodes
3
Step 10: More Than Two Nodes (cont’d)
• tic[0] will generate the message to be sent around
– done in initialize()
– getIndex() function which returns the index of the module
• forwardMessage(): invoke from handleMessage() whenever a message arrives
EV << "Forwarding message " << msg << " on port out[" << k << "]\n";
send(msg, "out", k);
}
• When the message arrives at tic[3], its handleMessage() will delete the message
4
Step 11: Channels and Inner Type Definitions
• Network definition is getting quite complex and long, e.g., connections
section
5
Step 12: Using Two-Way Connections
• Each node pair is connected with two connections => OMNeT++ 4
supports 2-way connections
6
Step 12: Using Two-Way Connections (cont’d)
• Note: The special $i and $o suffix after the gate name allows us
to use the connection's two direction separately.
7
Step 13: Defining our Message Class
• Destination address is no longer hardcoded tic[3] – add destination address to message
• Subclass cMessage: tictoc13.msg
message TicTocMsg13 {
fields:
int source;
int destination;
int hopCount = 0;
}
• opp_msgc is invoked and it generates tictoc13_m.h and tictoc13_m.cc
• Include tictoc13_m.h into our C++ code, and we can use TicTocMsg13 as any other class
#include "tictoc13_m.h"
8
Step 13: Defining our Message Class (cont’d)
• Use dynamic cast instead of plain C-style cast ((TicTocMsg13 *)msg) which is not safe
if (ttmsg->getDestination()==getIndex()) {
// Message arrived.
EV << "Message " << ttmsg << " arrived after " << ttmsg->getHopCount() << " hops.\n";
bubble("ARRIVED, starting new one!");
delete ttmsg;
9
Step 13: Defining our Message Class (cont’d)
10
Adding statistics collection
11
Step 14: Displaying the Number of Packets Sent/Received
12
Step 14: Displaying the Number of Packets Sent/Received (cont’d)
if (ev.isGUI())
updateDisplay();
void Txc11::updateDisplay(){
char buf[40];
sprintf(buf, "rcvd: %ld sent: %ld", numReceived, numSent);
getDisplayString().setTagArg("t",0,buf);
}
13
Step 15: Adding statistics collection
• OMNeT++ simulation kernel: omnetpp.ini
14
Step 15: Adding statistics collection (cont’d)
• Output vector object (which will record the data into omnetpp.vec) and a histogram object (which
also calculates mean, etc)
class Txc15 : public cSimpleModule {
private:
long numSent;
long numReceived;
cLongHistogram hopCountStats;
cOutVector hopCountVector;
protected:
• Upon message arrival, update statistics within handleMessage()
hopCountVector.record(hopcount);
hopCountStats.collect(hopcount);
• hopCountVector.record() call writes the data into Tictoc15-0.vec (will be deleted each time the
simulation is restarted)
15
Step 15: Adding statistics collection (cont’d)
void Txc15::finish() {
// This function is called by OMNeT++ at the end of the simulation.
EV << "Sent: " << numSent << endl;
EV << "Received: " << numReceived << endl;
EV << "Hop count, min: " << hopCountStats.getMin() << endl;
EV << "Hop count, max: " << hopCountStats.getMax() << endl;
EV << "Hop count, mean: " << hopCountStats.getMean() << endl;
EV << "Hop count, stddev: " << hopCountStats.getStddev() << endl;
recordScalar("#sent", numSent);
recordScalar("#received", numReceived);
hopCountStats.recordAs("hop count");
}
• recordScalar() calls in the code below write into the Tictoc15-0.sca file
• Tictoc15-0.sca not deleted between simulation runs; new data are just appended –
allows to jointly analyze data from several simulation runs
16
Step 15: Adding statistics collection (cont’d)
17
Step 16: Statistic collection without modifying your model
18
Step 16: Statistic collection without modifying your model (cont’d)
19
Step 16: Statistic collection without modifying your model (cont’d)
20
Visualizing the results with the OMNeT++ IDE
• OMNet++ IDE can be used to analyze the results.
• Our last model records the hopCount of a message each
time the message reaches its destination.
• The following plot shows these vectors for nodes 0 and 1.
21
Visualizing the results with the OMNeT++ IDE (cont’d)
22
Visualizing the results with the OMNeT++ IDE (cont’d)
23
Visualizing the results with the OMNeT++ IDE (cont’d)
24
Visualizing the results with the OMNeT++ IDE (cont’d)
25
OMNet++ 4.3 IDE
• Introduction
• The NED Editor
• The ini File Editor
• Simulation Launcher
• Sequence Chart
• Scave (Result Analysis)
26
Introduction
• OMNeT++ 4.x Integrated Development
Environment is based on the Eclipse platform
• Functionality
– Create/config NED and ini
files
– Perform batch executions
– Analyze simulation results
– Eclipse functionality: C++
editing, CVS/SVN/GIT
integration and optionally
other features via plug-ins
27
The NED Editor
• Edit NED files both graphically or in text mode
• User can switch between the two modes at any time
28
The NED Editor (cont’d)
• Properties view: edit graphical and non-
graphical properties of objects
29
The NED Editor (cont’d)
• NED Editor in source editing mode
30
The NED Editor (cont’d)
• Outline View
31
The ini File Editor
• Form-based ini file editing
32
The ini File Editor (cont’d)
• The ini file source editor
33
The ini File Editor (cont’d)
• Add Missing Keys
dialog
34
The ini File Editor (cont’d)
• Module Hierarchy View
35
The ini File Editor (cont’d)
• The NED Parameters View
36
The ini File Editor (cont’d)
• The Problems View
37
Simulation Launcher
• Run dialog showing
a simulation launch
configuration
38
Simulation Launcher (cont’d)
• Progress View
• Console View
39
Simulation Launcher (cont’d)
• Debug View showing three runs in a simulation batch
40
Sequence Chart
• Sequence Chart showing ARP on a wireless network
41
Sequence Chart (cont’d)
• Event Log View
42
Scave (Result Analysis)
• Specifying input files for data analysis
43
Scave (Result Analysis) (cont’d)
• Browsing vector and scalar data generated by the simulation
44
Scave (Result Analysis) (cont’d)
• Defining datasets to be analyzed
45
Scave (Result Analysis) (cont’d)
• A Line Chart
46
Scave (Result Analysis) (cont’d)
• A Bar Chart
47
Scave (Result Analysis) (cont’d)
• Output Vector View
48
Scave (Result Analysis) (cont’d)
• Dataset View
49
Conclusions
• OMNeT++: discrete event simulation system
• OMNeT++ is a
– public-source,
– component-based,
– modular and open-architecture simulation environment
– with strong GUI support and
– an embeddable simulation kernel
• OMNeT++ 4.3 IDE (Eclipse)
• http://www.omnetpp.org/documentation
50
References
• http://www.omnetpp.org/
51
Thank you
52