Sunteți pe pagina 1din 20

OMNET++

Outline
Introduction
Overview
The NED Language
Simple Modules

What Is OMNeT++?
Object-oriented modular discrete event network

simulation framework
modeling of wired and wireless communication networks
protocol modeling
modeling of queueing networks
modeling of multiprocessors and other distributed hardware

systems
validating of hardware architectures
evaluating performance aspects of complex software systems

What Is OMNeT++?
Object-oriented modular discrete event network

simulation framework
Components (modules) are programmed in C++
Assembled into larger components and models using a

high-level language (NED)

Modeling Concepts

Gates
Input and output interfaces
Connection
Spanning hierarchy levels are not permitted
Propagation delay, data rate and bit error rate, can be assigned

Main features
Hierarchical Modules
Top level module is the system module
Depth of module nesting is unlimited
Model structure is described in OMNeT++'s NED language
User implements the simple modules in C++, using the OMNeT++
simulation class library
Module Types
Both simple and compound modules are instances of module types

Main features
Messages
Modules communicate by exchanging messages
Frames or packets in a computer network
Jobs or customers in a queuing network

Gates
Input and output interfaces of modules
messages are sent out through output gates and arrive through
input gates
Links (connection)
Created within a single level of the module hierarchy

Main features
Modeling of Packet Transmissions
Data rate, propagation delay, bit error rate and packet error rate
Parameters
Can be assigned in either the NED files or the configuration file
omnetpp.ini
Used to customize simple module behavior, and to parameterize
the model topology
Topology Description Method
User defines the structure of the model in NED language
descriptions

The NED Language


A communication network

Defines a network
//Net6.ned
network Network
{
submodules:
node1: Node;
node2: Node;
node3: Node;
new gate
...
connections:
node1.port++ <--> {datarate=100Mbps;} <--> node2.port++;
node2.port++ <--> {datarate=100Mbps;} <--> node4.port++;
node4.port++ <--> {datarate=100Mbps;} <--> node6.port++;
...
}
//omnetpp.ini
[General]
network = Network

Introducing a Channel
network Network
{
types:
channel C extends ned.DatarateChannel {
datarate = 100Mbps;
}
submodules:
node1: Node;
node2: Node;
node3: Node;
...
connections:
node1.port++ <--> C <--> node2.port++;
node2.port++ <--> C <--> node4.port++;
node4.port++ <--> C <--> node6.port++;
...
}

The App, Routing, and Queue Simple


Modules
simple App
{
parameters:
int destAddress;
...
@display("i=block/browser");
gates:
sending
input in;
output out;
}
simple Routing
{
...
}
simple Queue
{
...
}

App.ned, Routing.ned and Queue.ned

and receiving application packets

The Node Compound Module


module Node
{
parameters:
int address;
@display("i=misc/node_vs,gold");
gates:
size will be determined implicitly
inout port[];
bidirectional connections
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];
}
}

by the number of neighbours

Simple Modules
Simple modules are programmed in C++, using the

OMNeT++ class library


Discrete Event Simulation
start of a packet transmission
end of a packet transmission
expiry of a retransmission timeout
initialize -- this includes building the model and
inserting initial events to FES(Future Event Set)
while (FES not empty and simulation not yet complete)
{
retrieve first event from FES
t:= timestamp of this event
process event
(processing may insert new events in FES or delete existing ones)
}
finish simulation (write statistical results, etc.)

Components, Simple Modules,


Channels

Defining Simple Module Types


// file: HelloModule.cc
#include <omnetpp.h>

// file: HelloModule.ned
simple HelloModule
{
gates:
input in;
}

class HelloModule : public cSimpleModule


{
protected:
virtual void initialize();
virtual void handleMessage(cMessage *msg);
};
// register module class with `\opp`
Define_Module(HelloModule);
void HelloModule::initialize()
{
ev << "Hello World!\n";
}

called for every message that arrives at the module

void HelloModule::handleMessage(cMessage *msg)


{
delete msg; // just discard everything we receive
}

handleMessage()
send() family of functions
to send messages to other modules
scheduleAt()
to schedule an event (the module sends a message to itself)
cancelEvent()
to delete an event scheduled with scheduleAt()
Cannot use the receive() and wait() functions

Protocol Models
class FooProtocol : public cSimpleModule
{
protected:
// state variables
// ...
virtual void processMsgFromHigherLayer(cMessage *packet);
virtual void processMsgFromLowerLayer(FooPacket *packet);
virtual void processTimer(cMessage *timer);
virtual void initialize();
virtual void handleMessage(cMessage *msg);
};
// ...
void FooProtocol::handleMessage(cMessage *msg)
{
if (msg->isSelfMessage())
processTimer(msg);
else if (msg->arrivedOn("fromNetw"))
processMsgFromLowerLayer(check_and_cast<FooPacket *>(msg));
else
processMsgFromHigherLayer(msg);
}

activity()
receive()
to receive messages (events)
wait()
to suspend execution for some time (model time)
send() family of functions
to send messages to other modules
scheduleAt()
to schedule an event (the module sends a message to itself)
cancelEvent()
to delete an event scheduled with scheduleAt()
end()
to finish execution of this module (same as exiting the activity()
function)

activity()
void Sink::activity()
{
while(true)
{
msg = receive();
delete msg;
}
}

S-ar putea să vă placă și