Simple modules

Download Report

Transcript Simple modules

Network Simulation with
OMNet++
Ing. Giuliana Alderisi
Introduction
OMNeT++ is an open-source modular discrete event network
simulator
The simulator is used for:
• Modeling telecommunication networks
• Modeling protocols for networks
• Modeling queuing networks
• Modeling multiprocessor and other distributed systems
• Measuring performance of complex software systems
• Other discrete event systems...
The OMNeT++ approach
OMNeT++ is a simulation framework
Provides an infrastructure for writing such simulations,
made up of:
A library of C++ classes
From which the user derives its own classes
A discrete event simulation kernel
Not to be changed by the user
A user who wants to develop a simulator must
Describe the simulation model
Describe the parameterized simulation scenarios
Simulation Model
A simulation model is described through the Network Description
Language, in terms of:
Modules
Gates
Connections
Messages
Hierarchically nested modules exchanging messages with each another
The depth of modules nesting is not limited. This allows the user to
reflect the logical structure of the actual system in the model structure.
Omnet++ Modules
Modules can be simple or composed
Compound modules: Modules that contain submodules
Simple modules: contain the algorithms in the model,
implemented in C++, using the OMNeT++ simulation class
library
Example Module Hierarchy
Network interface
card: a compound
module consisting of a
simple module MAC
and a compound
module Phy
Messages
Modules communicate by exchanging messages
Messages can represent frames or packets in a computer network, or
other logical elements (e.g. timers)
Messages can contain arbitrarily complex data structures
Messages can arrive from another module or from the same module
(self-messages are used to implement timers)
Simple modules can send messages either directly to their
destination or along a predefined path, through gates and
connections.
Gates
Gates are the input and output interfaces of modules:
Messages are sent out through output gates and arrive through input gates
Each connection (also called link) is created within a single level of the
module hierarchy:
Within a compound module, one can connect the corresponding gates of two
submodules, or a gate of one submodule and a gate of the compound
module.
Submodules connected to each other
Submodules connected to the parent module
Connections
Connections can be assigned some parameters, which
facilitate the modeling of communication networks:
propagation delay
bit error rate
data rate
One can specify link parameters individually for each
connection, or define link types and use them throughout the
whole model.
Implementation
To implement a simulation model the user
must provide:
The .ned files which describe the
modules
The .msg files which describe the
messages
The .h and .cc files which implements the
simple modules behaviour
The .ini file which contains the
simulation parameters
The NEtwork Description language (NED)
Components of a NED description:
Import directives
Channel definitions
Simple and compound module definitions
Network definitions
Import directives
import "ethernet"; // imports ethernet.ned
import
"Router",
"StandardHost",
"FlatNetworkConfigurator";
import inet.protocols.networklayer.ip.RoutingTable; // packages
import inet.protocols.networklayer.ip.*; // wildcards
import inet.protocols.networklayer.ip.Ro*Ta*;
import inet.protocols.*.ip.*;
import inet.**.RoutingTable;
Channel definitions
Channels encapsulate parameters and behavior associated with
connections.
The predefined types are:
ned.IdealChannel
No parameters
ned.DelayChannel
Two parameters: delay. Disabled
ned.DatarateChannel.
Three more parameters: datarate, per, ber
New channel types can be defined by specializing the predefined
ones
Channel definitions
Examples:
channel C extends ned.DatarateChannel
{
datarate = 100Mbps;
delay = 100us;
ber = 1e-10;
}
channel DatarateChannel2 extends ned.DatarateChannel
{
double distance @unit(m);
delay = this.distance / 200000km * 1s;
}
Simple module definitions
simple TrafficGen
{
parameters:
interarrivalTime: double;
numOfMessages : int;
address : string;
gates:
in: fromPort, fromHigherLayer;
out: toPort, toHigherLayer;
}
Compound module definitions
module CompoundModule
{
types: //...
parameters: //...
gates: //...
submodules: //...
connections: //...
}
Compound module definitions: submodules
module CompoundModule {
//...
submodules:
submodule1: ModuleType1 {
parameters:
//...
}
submodule2: ModuleType2 {
parameters:
//...
}
}
Compound module definitions: submodules
module CompoundModule {
parameters:
param1: numeric,
param2: numeric,
useParam1: bool;
submodules:
submodule1: Node {
parameters: p1 = 10,
p2 = param1+param2,
p3 = useParam1==true ? param1 : param2;
//...
}
}
Compound module definitions: connections
module CompoundModule {
parameters: //...
gates: //...
submodules: //...
connections:
node1.output --> node2.input
node1.input <-- node2.output;
node1.inout <--> node2.inout;
//...
}
Message definition
Messages are a central concept in OMNeT++. In the model,
message objects represent events, packets, commands, jobs,
customers or other kinds of entities, depending on the model
domain.
Message definitions provide a very compact syntax to
describe message contents.
C++ code is automatically generated from message
definitions, thus saving a lot of typing.
Message definition
Message definition provided
in mypacket.msg:
The generated mypacket_m.h
declares the following class:
In your C++ file, you could use the MyPacket class like this:
Message definition
Data types for message fields can be:
Primitive data types (bool, char, int, long, double, string,
etc.)
Enumerations
Classes
Structures
Arrays
It is also possible to use existing C++ types
cMessage class
All the messages are derived from cMessage class
Some useful methods:
msg->setKind( kind );
msg->setBitLength( length );
msg->setByteLength( lengthInBytes );
msg->setBitError( err );
msg->setTimestamp();
msg->setTimestamp( simtime );
msg->dup(); //duplicates the message
bool isSelfMessage();
bool isScheduled();
int k = msg->getKind();
int l = msg->getBitLength();
int lb = msg>getByteLength();
bool b = msg->hasBitError();
simtime_t t = msg>getTimestamp();
simtime_t
getCreationTime();
simtime_t getSendingTime();
simtime_t getArrivalTime();
Recording simuation results
The simulation may write output vector and output scalar files
scenarioname.vec and scenarioname.sca
The capability to record simulation results has to be explicitly programmed into
the simple modules
An output vector file contains several output vectors
Series of pairs (timestamp, value)
They can store things like:
Queue length over time, end-to-end delay of received packets, packet drops
or channel throughput
You can configure output vectors from omnetpp.ini
You can enable or disable recording individual output vectors, or limit
recording to a certain simulation time interval
Output vectors capture behaviour over time
Output scalar files contain summary statistics
Number of packets sent, number of packet drops, average end-to-end delay of
received packets, peak throughput
Recording simulation results
Output vectors
Output scalars
Domande?
Per inziare…
• Scaricare OMNet++ dal sito
• Installare OMNet++ (come da manuale)
Prima di chiedere la tesina:
• Seguire il tutorial (almeno il TIC TOC!!)