Introduction to OMNeT++

26
Introduction to OMNet++ Prepared by Md. Mahedee Hasan M.Sc Engg. IICT, BUET Web: http://mahedee.net Reviewed by Amit Karmaker Md. Abir Hossain M.Sc Engg. IICT, BUET Supervised by Dr. Mohammad Shah Alam Assistant Professor IICT, BUET Contents What is OMNeT++? ....................................................................................................................................... 2 Modeling concepts........................................................................................................................................ 2 Module .......................................................................................................................................................... 3 Message, gets and links ................................................................................................................................ 3 Parameters .................................................................................................................................................... 3 Classes that are part of simulation class library ........................................................................................... 4 OMNeT++ Consists of.................................................................................................................................... 4 How OMNeT++ Works? ................................................................................................................................ 4 NED Features ................................................................................................................................................ 5 The Network ................................................................................................................................................. 5 .ini (Initialization) Files .................................................................................................................................. 6 .cc (C++) Files................................................................................................................................................. 7 Channel ......................................................................................................................................................... 7 Simple and Compound Module .................................................................................................................... 8

Transcript of Introduction to OMNeT++

Introduction to OMNet++ Prepared by

Md. Mahedee Hasan M.Sc Engg. IICT, BUET

Web: http://mahedee.net

Reviewed by Amit Karmaker

Md. Abir Hossain M.Sc Engg. IICT, BUET

Supervised by

Dr. Mohammad Shah Alam Assistant Professor

IICT, BUET

Contents What is OMNeT++? ....................................................................................................................................... 2

Modeling concepts ........................................................................................................................................ 2

Module .......................................................................................................................................................... 3

Message, gets and links ................................................................................................................................ 3

Parameters .................................................................................................................................................... 3

Classes that are part of simulation class library ........................................................................................... 4

OMNeT++ Consists of .................................................................................................................................... 4

How OMNeT++ Works? ................................................................................................................................ 4

NED Features ................................................................................................................................................ 5

The Network ................................................................................................................................................. 5

.ini (Initialization) Files .................................................................................................................................. 6

.cc (C++) Files................................................................................................................................................. 7

Channel ......................................................................................................................................................... 7

Simple and Compound Module .................................................................................................................... 8

Simple Module ............................................................................................................................................ 10

Compound Modules ................................................................................................................................... 11

Channels ...................................................................................................................................................... 12

Parameter ................................................................................................................................................... 12

Gates ........................................................................................................................................................... 14

Sub Modules ............................................................................................................................................... 15

Connections ................................................................................................................................................ 16

Inheritance .................................................................................................................................................. 16

Packages ...................................................................................................................................................... 16

Create First Simulation Project using OMNeT++ ........................................................................................ 17

References .................................................................................................................................................. 26

History Card ................................................................................................................................................ 26

What is OMNeT++? OMNeT++ is a Simulator

For discrete event network

It is object oriented and modular

Used to simulate o Modeling of wired and wireless communication networks o Protocol modeling o Modeling of queuing networks etc.

Modules are connected using gates to form compound module o In other system sometimes gates are called port

Modeling concepts Modules are communicate with message passing

Active modules are called simple modules

Message are sent through output gates and receive through input gates

Input and output gates are linked through connection

Parameters such as propagation delay, data rate and bit error rate, can be assigned to connections

Fig – simple and compound module

Module In hierarchical module, the top level module is system module

System module contains sub modules

Sub modules contains sub modules themselves

Both simple and compound modules are instance of module type

Message, gets and links Module communicate by exchanging message

Message can represent frames or packets

Gates are the input and output interface of modules

Two sub modules can be connected by links with gates

Links = connections

Connections support the following parameter o Data rate, propagation delay, bit error rate, packet error rate

Parameters Modules parameters can be assigned

o in either the NED files or o the configuration file omnetpp.ini.

Parameter can take string, numeric or Boolean data values or can contains XML data trees

Classes that are part of simulation class library The following classes are the part of simulation class library

Module, gates, parameter, channel

Message, packet

Container class (e.g. queue and array)

Data collection classes

Statistics and distribution estimated classes

Transition and result accuracy detection classes.

OMNeT++ Consists of NED language topology description(s)(.ned files)

Message definitions (.msg files)

Simple module sources. They are C++ files, with .h/.cc suffix.

How OMNeT++ Works? When Program started

o Read all NED files containing model topology o Then it reads a configuration file(usually called omnetpp.ini)

Output is written in result file

Graph is generated from result file using Matlab, Phython etc

NED Features NED has several features which makes it scale well to large project

Hierarchical

Component-based

Interfaces

Inheritance

Packages

Metadata annotation

The Network Network consists of

o Nodes o Gates and o Connections

Fig: The network

network Network { submodules: node1 : Node; node2 : Node; node3 : Node;

……………………… connections: node1.port++<-->{datarate=100Mbps;}<-->node2.port++; node2.port++<-->{datarate=100Mbps;}<-->node3.port++; node3.port++<-->{datarate=100Mbps;}<-->node1.port++;

……………………… }

The double arrow means bi-directional connection

The connection points of the modules are called gates

The port++ notation adds a new gate to the port[] gate vector

Nodes are connected with a channel

Specify the network option in to the configuration like below [General] network = Network

.ini (Initialization) Files Defines the network initialization point with/without some parameters

[General] network = TicToc1

.cc (C++) Files Contains class definition and function for modules.

#include <string.h> #include <omnetpp.h> class Txc1 : public cSimpleModule { protected:

virtual void initialize(); virtual void handleMessage(cMessage *msg);

};

Define_Module(Txc1); void Txc1::initialize() { // Am I Tic or Toc? if (strcmp("tic", getName()) == 0) { cMessage *msg = new cMessage("tictocMsg"); send(msg, "out"); } } void Txc1::handleMessage(cMessage *msg) { send(msg, "out"); }

Channel Predefined Channel type

o IdealChannel o DelayChannel

delay (double with s, ms, us) diabled (boolean)

o DatarateChannel delay (double with s, ms, us) disabled (boolean) datarate (double with unit as bps, kbps, Mbps, Gbps) ber (double bit error rate [0,1]) per (double packet error rate [0,1])

One can create new channel type

network net { @display("bgb=340,233"); types: channel customChannel extends ned.DatarateChannel{ datarate=100Mbps; } submodules: computer1: computer { @display("p=63,55"); } computer2: computer { @display("p=260,55"); } connections: computer1.out -->customChannel--> computer2.in; computer2.out -->customChannel--> computer1.in; }

Simple and Compound Module Simple module is a basic building block

Denoted by simple keyword simple App {

parameters: int destAddress; ... @display("i=block/browser");

gates: input in; output out;

} simple Routing {

... } simple Queue {

... }

Convention : Module name should be Pascal case

Simple module combines into compound module

simple App { parameters: int destAddress; @display("i=block/browser"); gates: input in; output out; } simple Routing { gates: input localIn; output localOut; } simple Queue { gates: input in; output out; } module Node { parameters: int address; @display("i=misc/node_vs,gold"); gates: inout port[]; submodules: app: App; routing: Routing; queue[sizeof(port)]: Queue; connections: routing.localOut --> app.in; routing.localIn <-- app.out; for i=0..sizeof(port)-1 { routing.out[i] --> queue[i].in; routing.in[i] <-- queue[i].out; queue[i].line <--> port[i]; } }

Fig – The node compound module

When simulation program started its load NED file first.

Then it load corresponding simple module written in C++ such as App, Queue

Simple Module Simple module is the active component defined by simple keyword

simple Queue { parameters: int capacity; @display("i=block/queue"); gates: input in; output out; }

Parameters and gates sections are optional here

Parameters keywords is optional too, parameters can be defined without parameters keyword

One can explicitly specify the C++ class with the @class property simple Queue { parameters: int capacity; @class(mylib::Queue); @display("i=block/queue"); gates: input in; output out; }

The C++ classes will be mylib::App, mylib::Router and mylib::Queue

@namespace(mylib); simple App{ ... } simple Router{ ... } simple Queue{ ... }

Compound Modules Groups other modules into a larger unit

A compound modules may have gates and parameters like simple module but not active

A compound modules may have several sections all of them optional module Host { types: ... parameters: ... gates: ... submodules: ... connections: ... }

Modules contains in compound module are called sub module – are in sub module section

Compound module may be inherited via sub classing module WirelessHost extends WirelessHostBase { submodules: webAgent:WebAgent; connections: webAgent.tcpOut-->tcp.appIn++; webAgent.tcpIn<--tcp.appOut++; } module DesktopHost extends WirelessHost { gates: inout ethg; submodules:

eth:EthernetNic; connections: ip.nicOut++-->eth.ipIn; ip.nicIn++<--eth.ipOut; eth.phy<-->ethg; }

Channels Channels are connections between nodes

Predefined channel types are: ned.IdealChannel, ned.DelayChannel and ned.DatarateChannel

Can use import ned.*

channel Ethernet100 extends ned.DatarateChannel { datarate = 100Mbps; delay = 100us; ber = 1e-10; }

Or

channel DatarateChannel2 extends ned.DatarateChannel { double distance @unit(m); // @unit is a property delay = this.distance/200000km * 1s; }

Parameter Parameters are variables that belong to a module.

Parameters can be used in building the topology (number of nodes, etc)

To supply input to C++ code that implements simple modules and channels

For the numeric types, a unit of measurement can also be specified (@unit property), to increase type safety.

Parameters can get their values from NED files or from the configuration(Omnetpp.ini)

simple App { parameters:

string protocol; //protocoltouse:"UDP"/"IP"/"ICMP"/... int destAddress; //destinationaddress volatile double sendInterval@unit(s)= default(exponential(1s)); //timebetweengeneratingpackets volatile int packetLength@unit(byte)= default(100B); //lengthofonepacket volatile int timeToLive= default(32); //maximumnumberofnetworkhopstosurvive

gates:

input in; output out;

}

Assigning a Value

Another example

* matches any index

.. matches ranges

If number of individual hosts instead of a sub module vector, network definition can be like this:

Example:

Gates Connection points of Module

OMNeT++ has three types of gates o Input, output and inout

Example 1:

Example 2:

Example 3:

Gates around the edges of the grid are expected to remain unconnected, hence the @loose

annotation used.

Sub Modules Modules that a compound module is composed of are called its sub modules.

A sub module has a name, and it is an instance of a compound or simple module type.

Example:

Connections Connections are defined in connections section in compound module

Inheritance In NED, a type may only extend an element of the same component type

A simple module may only extend a simple module, compound module may only extend a compound module, and so on.

Single inheritance is supported for modules and channels

Multiple inheritance is supported for module interfaces and channel interfaces

Inheritance may: o Add new properties, parameters, gates, inner types, sub modules, connections, as long

as names do not conflict with inherited names o Modify inherited properties, and properties of inherited parameters and gates

Packages Group together similar modules

Reduces name conflicts

Before use the class, must reference the package

Create First Simulation Project using OMNeT++ Step 1: Create a OMNeT++ Project Go to File -> New -> OMNeT++ Project

Step 2: Type project Name Type project Name (ex. FirstSim) in Project Name text box

Step 3: Add Initial Contents Here I add Empty project

Step 4: Choose C++ Project Type Here we choose OMNeT++ simulation

Step 5: Select Configuration

Step 6: Create NED File File -> New -> Network Description file (NED)

Step 7: Select Project for the NED file

Step 8: Choose initial content for NED file

Step 9: Click finish Step 10: Modify and add the code below to source of ned file // // TODO documentation // simple computer { gates: input in; output out; } // // TODO documentation // network net { @display("bgb=340,233"); submodules: computer1: computer { @display("p=63,55"); } computer2: computer { @display("p=260,55"); } connections: computer1.out --> computer2.in; computer2.out --> computer1.in; }

Step 11: Modify the source of Package.ned //package firstsim; // //@license(LGPL); @license(omnetpp);

Step 12: Create Initialization File (ini)

Step 13: Choose project for ini file

Step 14: Choose initial content for ini file

Step 15: Choose ned file for ini file

Step 16: Click finish Step 17: Create a C++ source file File->New->Source File

Step 18: Type name of the C++ File (example: computer.cc)

Step 19: Modify the computer.cc /* * computer.cc * * Created on: Aug 25, 2015 * Author: mahedee */ #include<string.h> #include<omnetpp.h> /*computer is a simple module. A simple module is nothing more than a C++ class which has to be sub classed from cSimpleModule,with one or more virtual member functions redefined to define its behavior.*/ class computer : public cSimpleModule { protected: virtual void initialize(); virtual void handleMessage(cMessage *msg); }; /* The class has to be registered with OMNeT++ via the Define_Module() macro.The Define_Module() line should always be put into .cc or .cpp file and not header file (.h), because the compiler generates code from it. */ Define_Module(computer); void computer :: initialize() { if(strcmp("computer1",getName())==0) { cMessage *msg = new cMessage("checkMsg"); send(msg,"out"); } } void computer::handleMessage(cMessage *msg) { send(msg,"out"); }

Now build the project, if it succeed then run the project. Mission complete..

References 1. OMNeT++ User Manual – Version 4.4

2. OMNeT++ User Guide – Version 4.4

3. OMNeT++ Video Tutorial

4. Stack Overflow

5. A Quick Overview of OMNeT++ IDE

History Card Version Description Update Date Published Date

1 Draft Preparation 14 Aug 2015

2