0% found this document useful (0 votes)
91 views52 pages

Tutorial Ii: Omnet++ (Part-2)

1) The document discusses steps for building a simulation of a simple network in OMNeT++, including adding more nodes, defining channels, using two-way connections between nodes, defining a message class, and collecting statistics on message hops. 2) It describes collecting statistics on the number of hops messages take to reach their destination, both by modifying the node class and by using signals, without modifying the node code. 3) The OMNeT++ IDE can visualize results, such as plotting hop counts over time for each node, calculating averages, and displaying histograms of the hop count distribution.

Uploaded by

Wissem Hammouda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
91 views52 pages

Tutorial Ii: Omnet++ (Part-2)

1) The document discusses steps for building a simulation of a simple network in OMNeT++, including adding more nodes, defining channels, using two-way connections between nodes, defining a message class, and collecting statistics on message hops. 2) It describes collecting statistics on the number of hops messages take to reach their destination, both by modifying the node class and by using signals, without modifying the node code. 3) The OMNeT++ IDE can visualize results, such as plotting hop counts over time for each node, calculating averages, and displaying histograms of the hop count distribution.

Uploaded by

Wissem Hammouda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 52

Tutorial II OMNeT++ (Part-2)

Dr. Abhishek Roy


Network System Design Lab,
Senior Manager
Samsung Electronics, South Korea
[email protected]

1
Turning it into a real network

• Step 10: More than two nodes


• Step 11: Channels and inner type definitions
• Step 12: Using two-way connections
• Step 13: Defining our message class

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

void Txc10::forwardMessage(cMessage *msg) {


// In this example, we just pick a random gate to send it on.
// We draw a random number between 0 and the size of gate `out[]'.
int n = gateSize("out”);
int k = intuniform(0,n-1);

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

• Note: built-in DelayChannel (import ned.DelayChannel)

5
Step 12: Using Two-Way Connections
• Each node pair is connected with two connections => OMNeT++ 4
supports 2-way connections

• The new connections section would look like this:

6
Step 12: Using Two-Way Connections (cont’d)

• We have modified the gate names => some modifications to


the C++ code.

• 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"

TicTocMsg13 *msg = new TicTocMsg13(msgname);


msg->setSource(src);
msg->setDestination(dest);
return msg;

8
Step 13: Defining our Message Class (cont’d)
• Use dynamic cast instead of plain C-style cast ((TicTocMsg13 *)msg) which is not safe

void Txc13::handleMessage(cMessage *msg) {


TicTocMsg13 *ttmsg = check_and_cast<TicTocMsg13 *>(msg);

if (ttmsg->getDestination()==getIndex()) {
// Message arrived.
EV << "Message " << ttmsg << " arrived after " << ttmsg->getHopCount() << " hops.\n";
bubble("ARRIVED, starting new one!");
delete ttmsg;

// Generate another one.


EV << "Generating another message: ";
TicTocMsg13 *newmsg = generateMessage();
EV << newmsg << endl;
forwardMessage(newmsg);
} else {
// We need to forward the message.
forwardMessage(ttmsg);
}
}

9
Step 13: Defining our Message Class (cont’d)

10
Adding statistics collection

• Step 14: Displaying the number of packets sent/received

• Step 15: Adding statistics collection

11
Step 14: Displaying the Number of Packets Sent/Received

• Add two counters to the module class: numSent and numReceived


• Set to zero and WATCH'ed in the initialize() method
• Use the Find/inspect objects dialog (Inspect menu; it is also on the toolbar)

12
Step 14: Displaying the Number of Packets Sent/Received (cont’d)

• This info appears above the module icons using the


t= display string tag

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

• Example: average hopCount a message has to travel before


reaching its destination
– Record in the hop count of every message upon arrival into an output
vector (a sequence of (time,value) pairs, sort of a time series)
– Calculate mean, standard deviation, minimum, maximum values per
node, and write them into a file at the end of the simulation
– Use off-line tools to analyse the output files

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)

• Scalar data (histogram object) have to be recorded manually, in the finish()


function

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

• OMNeT++ 4.1 provides an additional mechanism to record values


and events
– Any model can emit 'signals' that can carry a value or an object
– The model writer just have to decide what signals to emit, what data
to attach to them and when to emit them
• The end user can attach 'listeners' to these signals that can process
or record these data items
– This way the model code does not have to contain any code that is
specific to the statistics collection
– The end user can freely add additional statistics without even looking
into the C++ code
• We can safely remove all statistic related variables from our module
– No need for the cOutVector and cLongHistogram classes either
– Need only a single signal that carries the hopCount of the message at
the time of message arrival at the destination

18
Step 16: Statistic collection without modifying your model (cont’d)

• Define our signal: arrivalSignal as identifier

• We must register all signals before using them

• Emit our signal, when the message has arrived to the


destination node. finish() method can be deleted!

19
Step 16: Statistic collection without modifying your model (cont’d)

• Declare signals in the NED file

• Configuration via ini file

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)

• If we apply a mean operation we can see how the


hopCount in the different nodes converge to an average:

22
Visualizing the results with the OMNeT++ IDE (cont’d)

• Mean and the maximum of the hopCount of the messages


for each destination node
– based on the scalar data recorded at the end of the simulation.

23
Visualizing the results with the OMNeT++ IDE (cont’d)

• Histogram of hopCount's distribution.

24
Visualizing the results with the OMNeT++ IDE (cont’d)

• OMNeT++ simulation kernel can record the message


exchanges during the simulation => event log file =>
analyzed with Sequence Chart tool
• E.g., message is routed between the different nodes in
the network

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

You might also like