Upload
karanpreet-singh
View
223
Download
0
Embed Size (px)
Citation preview
7/30/2019 omnetpp.pdf
1/33
[Car2X] Summer 2012 OMNeT++ 1
Computer and Communication Systems
(Lehrstuhl fr Technische Informatik)
OMNeT++
7/30/2019 omnetpp.pdf
2/33
[Car2X] Summer 2012 OMNeT++ 2
Overview
OMNeT++
Discrete-Event Simulation (DES) kernelMulti-platform, Open Source
Modular concept
Pure C++
IDE (source code, configuration, , evaluation) optional
GUI (simulation execution) optional
Model repositories
OverSim
Upper layers (Overlay networks)
The INET Framework
Middlelayers (HTTP, TCP, IP, )
MiXiM
Lowerlayers (, MAC, PHY) MiXiM
7/30/2019 omnetpp.pdf
3/33
[Car2X] Summer 2012 OMNeT++ 3
Simple Module
Gate
Simple Module
Hierarchical, modular, object oriented,
Compound Module
Modeling Approach
Simple Module
7/30/2019 omnetpp.pdf
4/33
[Car2X] Summer 2012 OMNeT++ 4
Compare to layered architecture
Modeling Approach
Network
Transport
Application
Link
Physical
Network
Transport
Application
Link
Physical
7/30/2019 omnetpp.pdf
5/33
[Car2X] Summer 2012 OMNeT++ 5
Example
7/30/2019 omnetpp.pdf
6/33
[Car2X] Summer 2012 OMNeT++ 6
The DES Modeling Paradigm
Simulations are based on event queue
1. Select next event from queue2. Deliver event to destination module
Destination module reacts to event
Potentially places new event(s) into queue
3. Repeat
Scheduling events
send/sendDelayed: Send message via output gate
Event scheduled for delivery via connected modules input gate
sendDirect: Send message to other modules input gate
Disrupts hierarchical modeling pattern
scheduleAt: Send message to oneself
Common way of modeling timer expiry,
7/30/2019 omnetpp.pdf
7/33
[Car2X] Summer 2012 OMNeT++ 7
The DES Modeling Paradigm
Need to map real-world processes discrete events
ex.: transmission of a packet
Alice
Bob
7/30/2019 omnetpp.pdf
8/33
[Car2X] Summer 2012 OMNeT++ 8
Simulation GUI
Event
queue
Event
delivery
Child
Module
ParentModule
7/30/2019 omnetpp.pdf
9/33
[Car2X] Summer 2012 OMNeT++ 9
Separation of Concerns
Simulation components
Runtime parameters
omnetpp.ini
Structure
network description (NED)
(plain text file)
message format (MSG)
(plain text file)
Behavior
C++ code
7/30/2019 omnetpp.pdf
10/33
[Car2X] Summer 2012 OMNeT++ 10
Structure: NED files
Simple Module Compound Modulesimple TicModule
{
gates:
input in;
output out;
}
import TicModule;
import TocModule;
module Watch
{
gates:
input lightSwitch;
output lcd;
submodules:
tic: TicModule;
toc: TocModule;
connections:
tic.out --> toc.in;
tic.in
7/30/2019 omnetpp.pdf
11/33
[Car2X] Summer 2012 OMNeT++ 11
Structure: NED files
Properties Network definition@namespace(MySimulation);
@display("i=block/queue");
@display("p=100,100;i=
@display(t=Now Running;p=
@node;
@foo[1](s=apples; i=42);
@foo[2](s=pears!; n=42);
network sim extends Watch
{
}
7/30/2019 omnetpp.pdf
12/33
[Car2X] Summer 2012 OMNeT++ 12
Structure: MSG files
Messages and Gates
message MyMessage{
int sourceId;
int destinationId;
string information;
}
simple MyModule{
gates:
input gate1;
output gate2;
inout gate3;
}
7/30/2019 omnetpp.pdf
13/33
[Car2X] Summer 2012 OMNeT++ 13
Messages and Packets
Messages vs. Packets
Packet encapsulation
#include MyMessage_m.h
cMessage* msg = ;
msg->setName(Bob);
msg->setControlInfo();
#include MyPacket_m.h
cPacket* pkt = ;
pkt->setName(Bob);
pkt->setControlInfo();
pkt->encapsulate(innerPkt);
pkt->setByteLength(42);
IP Packet
TCP Segment
IP Control Info
TCP Segmenten/decapsulation
7/30/2019 omnetpp.pdf
14/33
[Car2X] Summer 2012 OMNeT++ 14
Runtime Parameters
Defining parametersNodes NED file
Setting parameters
omnetpp.ini file
Reading parametersC++ source code
simple Node
{
parameters:
int foo;double bar;
}
[General]
network = sim
sim.node.foo = 42
void Node::initialize() {
int i = par(foo);
double bar = par(bar);
}
7/30/2019 omnetpp.pdf
15/33
[Car2X] Summer 2012 OMNeT++ 15
Parameter Studies and Sensitivity Analyses
[General]
sim.tic.tickRate = 42
sim.toc.tickRate = 42
# wildcards (first-match policy)
sim.t[io]c.tickRate = 42
sim.*.tickRate = 42
*.*.tickRate = 42
**.tickRate = 42
**.tic.tickRate = intuniform(1, 12)
**.tic.tickRate = ${FOO = 1, 5, 10}
**.toc.tickRate = ${ 10, 5, 1 ! FOO}
7/30/2019 omnetpp.pdf
16/33
[Car2X] Summer 2012 OMNeT++ 16
Experiment Measurement Replication
Simulation: Use DYMO protocol to find route
Experiment 1: impact of network load?Measurement 1.1: load of 5 packets/s?
Replication 1.1.1: random seed 7 (= run 0)
Replication 1.1.2: random seed 42 (= run 1)
Measurement 1.2: load of 15 packets/s?
Replication 1.2.1: random seed 7 (= run 2) Replication 1.2.2: random seed 42 (= run 3)
Experiment 2: impact of node density?
Measurement 2.1: density of 25 nodes/m2?
Replication 2.1.1: random seed 7 (= run 0)
Replication 2.1.2: random seed 42 (= run 1)Measurement 2.2: density of 50 nodes/m2?
Replication 2.2.1: random seed 7 (= run 2)
Replication 2.2.2: random seed 42 (= run 3)
7/30/2019 omnetpp.pdf
17/33
[Car2X] Summer 2012 OMNeT++ 17
Behavior: C++ Code
#include
Define_Module(TicModule);
class TicModule : public cSimpleModule {
void initialize() {
cMessage *msg = new cMessage(sendTock");send(msg, "out");
recordScalar(start time, simTime());
}
void handleMessage(cMessage *msg) {
send(msg, "out");cOutVector v; v.setName(ticks); v.record(1);
}
};
7/30/2019 omnetpp.pdf
18/33
[Car2X] Summer 2012 OMNeT++ 18
Use of initialize/finish
constructor
set pointers to 0
initialize(int stage)
initialize pointers
read parameters
schedule messages
finish()
record statistics
destructor
cancel and delete messages
free (owned) memory
7/30/2019 omnetpp.pdf
19/33
[Car2X] Summer 2012 OMNeT++ 19
Finite State Machines
Declare FSM
Enter of
steady state:
FSM_Switch
returns
Exit branchtaken on next call
determines
next state
cFSM fsm;
enum {
INIT = 0,
ONE = FSM_Steady(1),
TWO = FSM_Steady(2),
};
ONE
TWO
FSM_Switch(fsm) {case FSM_Exit(INIT):
FSM_Goto(fsm, ONE);
break;
case FSM_Enter(ONE):
break;
case FSM_Exit(ONE):
FSM_Goto(fsm, TWO);
break;
7/30/2019 omnetpp.pdf
20/33
[Car2X] Summer 2012 OMNeT++ 20
Building the Simulation
OMNeT++
kernel
Model
Library
Own
Models
GUI
Executable
Simulation
Results
.ini file
.ned files
static/dynamic linker
simk
ernel
7/30/2019 omnetpp.pdf
21/33
[Car2X] Summer 2012 OMNeT++ 21
Running Simulations
With GUI
Command line only
Parameters
-u: user interface to load
-l: model library to load
-c: configuration section (= experiment) to read
-r: run (= measurement and replication) to execute
$ opp_run u Tkenv l /model-lib c Config1 r 0
$ opp_run u Cmdenv l /model-lib c Config1 r 0..8,10
7/30/2019 omnetpp.pdf
22/33
[Car2X] Summer 2012 OMNeT++ 22
Generating Random Numbers
Properties of the stdlib pRNG
#include {
srand(42);
while (1) {
int dice = rand() % 6;
std::cout
7/30/2019 omnetpp.pdf
23/33
[Car2X] Summer 2012 OMNeT++ 23
Generating Random Numbers
Properties of the stdlib pRNG
#include {
srand(42);
while (1) {
int dice = rand() % 6;
std::cout
7/30/2019 omnetpp.pdf
24/33
[Car2X] Summer 2012 OMNeT++ 24
#include {
while (1) {
int dice = intrand(6);
std::cout
7/30/2019 omnetpp.pdf
25/33
[Car2X] Summer 2012 OMNeT++ 25
Collecting Results (1)
Either (1) do statistics in simulation
Can track mean, histogram bin population, estimate quantiles,
Transient phase detection
Accuracy judging
cStdDev stat;
stat.collect(0.012);
stat.collect(0.013);
stat.collect(0.014);
ASSERT(stat.getMean() == 0.013);
cTDExpandingWindows::setParameters(
int reps=3, int minw=4, double wind=1.3, double acc=0.3)
cADByStddev::setParameters(
double acc=0.1, int reps=3)
7/30/2019 omnetpp.pdf
26/33
[Car2X] Summer 2012 OMNeT++ 26
Collecting Results (2)
Or (2) write raw observations to a file
Can use C++ standard file I/O
Problem: when and how to open, close file?
Problem: how to manage files?
Better: Use OMNeT++ data logging
Data associated with whole simulation: Scalar Value
e.g.: numPacketsReceived = 42
Data associated with event / time: Vector Valuee.g. packetDelays = {0.013s, 0.014s, 0.012s, }
Next Step: read file, derive statistics
7/30/2019 omnetpp.pdf
27/33
[Car2X] Summer 2012 OMNeT++ 27
Statistics and Plotting
Convert vector output file to .csv
Read and use in GNU R
./opp_vec2csv.pl -F packetDelay
results/run1.vec > packetDelays.csv
% R
> d
7/30/2019 omnetpp.pdf
28/33
[Car2X] Summer 2012 OMNeT++ 28
Logging and Debugging
Logging
Watches (and interaction with watched variables)
EV
7/30/2019 omnetpp.pdf
29/33
[Car2X] Summer 2012 OMNeT++ 29
Error Handling
Kernel will catch and display errors
or allow debugger to trap errors
ASSERT(7 < 42);
if (7 >= 42) {
this->error(this shouldnt have happened);opp_error(same);
throw cRuntimeError(same);
}
Error in module (Txc2) Tictoc2.tic (id=2)
during network initialization: Model error:
ASSERT: condition 7 < 42 false in function
initialize, txc2.cc line 41.
[General]
debug-on-errors = true
7/30/2019 omnetpp.pdf
30/33
[Car2X] Summer 2012 OMNeT++ 30
Error Handling
Run simulation in gdb
% gdb --args opp_run u Cmdenv l /model-lib r 0
(gdb) run
Error in module: ASSERT: condition i > 42 false
TRAPPING on the exception above, due to a debug-on-
errors=true configuration option. Is your debugger ready?
(gdb) up 4
tx2.cc:33 ASSERT(i > 42);(gdb) print i
$1 = 7
(gdb) _
[General]
debug-on-errors = true
7/30/2019 omnetpp.pdf
31/33
[Car2X] Summer 2012 OMNeT++ 31
Documentation
NED and MSG files C++ code
//
// Documentation
//
simple MyModule
{
parameters:int foo; // The Foo
int bar; // The Bar
gates:
// Leave unconnected
input in;
}
/**
* Documentation
*/
class TicModule {
public:int foo; /**< The Foo */
int bar; /**< The Bar */
/** Dont call before 7 */
void main();
};
7/30/2019 omnetpp.pdf
32/33
[Car2X] Summer 2012 OMNeT++ 32
Work Smart not Hard
Make (ample) use of scripting
Less error-prone than dozens of manual steps (and less work)Ideal documentation
% ./runall.sh
Building simulation...
Copying binary/data to target machines... [100%]
Starting simulations... [100%]Waiting for runs to finish...
Error check of log files... [93%]
Collecting results... [0%]
Transforming to csv... [0%]
Plotting results... [0%]
ERROR: Sanity check failed. Run 927 incomplete.
% _
7/30/2019 omnetpp.pdf
33/33
[Car2X] Summer 2012 OMNeT++ 33
Pitfalls
Common and very common pitfalls
Use of pointer after send()Pointer now owned by kernel; might have moved/destroyed data
Use of constructor for initializing members
Multiple simulation runs per binary execution
Use of finish() method for cleanup
Other modules (or kernel) might still need data or messages
Use of global variables / static members
Who initializes those? When?
Using std::map::const_iterator
Nondeterminism: order of iteration dependent on raw pointer value