Tutorial of OMNeT++
This document provides a quick introduction to OMNeT++. The aim is to get the interested user up and running with a simple game NIM. After finishing this, the user can start exploiting more of OMNeT++’s functionality based on the extensive user manual and the sample directories.
1.3 Where
to Get the Software?
2.2.1 Find
the folder of the Nim example.
2.2.3 Run
the program step by step
2.3.1 Where
can you find the parameters?
2.3.2 How
to change parameters?
2.3.3 Start
newly generated Nim
OMNeT++ is an object-oriented modular discrete event simulator. The name itself stands for Objective Modular Network Testbed in C++. OMNeT++ has its distant roots in OMNeT, a simulator written in Object Pascal by dr. György Pongor. The simulator can be used for:
ü traffic modeling of telecommunication networks
ü protocol modeling
ü modeling queueing networks
ü modeling multiprocessors and other distributed hardware systems
ü validating hardware architectures
ü evaluating performance aspects of complex software systems
ü modeling any other system where the discrete event approach is suitable.
There are numerous network simulation tools on the market today, both commercial and non-commercial. In this section I will try to give an overview by picking some of the most important or most representative ones in both categories and comparing them to OMNeT++: PARSEC, SMURPH, NS, Ptolemy, NetSim++, C++SIM, CLASS as non-commercial, and OPNET, COMNET III as commercial tools. (The OMNeT++ Home Page contains a list of Web sites with collections of references to network simulation tools where the reader can get a more complete list.) In the commercial category, OPNET is widely held to be the state of the art in network simulation. OMNeT++ is targeted at roughly the same segment of network simulation as OPNET.
Seven issues are examined to get an overview about the network simulation tools:
In conclusion, it can be said that OMNeT++ has enough features to make it a good alternative to most network simulation tools, and it has a strong potential to become one of the most widely used network simulation packages in academic and research environments. The most serious shortcoming is the lack of available protocol models, but since this is mostly due to the fact that it is a relatively new simulation tool, with the help of the OMNeT++ user community the situation is likely to become much better in the future.
You can find OMNeT++ at http://www.omnetpp.org/. If you are too lazy to type this in, a search with www.google.com on omnet++ will give an instant hit.
The following graph is the screenshot of the homepage of OMNeT++

Since most students use windows operation system, we should download the file OMNet++ 2.3 Win32(exe) (Circled in above graph)or simple click the following link http://www.omnetpp.org/filemgmt/visit.php?lid=31 and download the file.
a) Double click the downloaded file
,
you will see the following license window

b) Choose I Agree and you will see the following window

c) Choose default configuration and go to Next step

d) You can choose current configure to Install OMNeT++
You can also choose another directory. But the directory can not have space in its name. For example please don't install under C:\Program files! (Otherwise you'll probably have problems with the makefiles.) After click Install you will find the following installation window.

e) After a while you will see the successful installation window as follow

f) Then click Yes and restart your computer and the OMNeT++ will be ready for you to use
In this chapter we will show you the basic concepts of OMNeT++ via the simulation model of a simple game, NIM.
Nim is an ancient game with two players and a bunch of sticks (here also called tokens). The players take turns, removing 1, 2, 3 or 4 sticks from the heap of sticks at each turn. The one who takes the last stick is the loser. The game is modeled in OMNeT++ as a network with three modules: the 'game' (a manager module) and two players. The model of the Nim game is similar to 'Hello world!' by complexity, but it nicely demonstrates the modeling approach used by OMNeT++.
Let us first start the Nim and have a brief review of OMNeT++.
If you installed as default configuration, it should be at C:\OMNeT++\samples\nim. If you changed to other folder the position of the Nim is similar. The following figure shows the folder position in my computer.

You can double click the EXE file nim.exe with icon
to
start the program. Then a lot of windows will appear as follow.

1. Since the graphics window is clear and straightforward, we first click
run
in
this window to see what happens. Then we find the TKenv
window displays some messages.

2. We continue to run the game by clicking
in the graphics window. We can see the
following events happen. Player1 named “InteractivePlayer”
come out of player 1 box and go to game circle.

The Tkenv window shows the detailed event explanation. ** Event #1. T=0.0000000 ( 0.00s). Module #3 `nim.player1'

3. Continue to run the game
, we
will notice a “smartplayer” comes out of player2 box
and goes to game circle. The windows is showed as
follow.

Then the Tkenv
window shows the detailed event explanation. ** Event
#2. T=0.0000000 ( 0.00s). Module #4 `nim.player2'

4. Continue to run the game by clicking
, we
will see ** Event #3. T=0.0000000 ( 0.00s). Module #2 `nim.game'
appear in the Tkenv window

5. Click
again
and the game will begin. The Tkenv window shows the
following message

In the graphics window we can see a very interesting animation. The ball changes its color, and the text with the ball also changes to “26 sticks left”. Then, the ball goes to player2’ box. The following graph is the final result of this step.

6. Continue to run the game by clicking
,
the smart player begins to take some sticks from the 26 sticks. By the smart
algorithm he takes 1 out of 26 sticks. If you are the smart player, how many
sticks are you going to take? The Tkenv windows
displays the message like following

The graphics window looks like following

7. Continue to run the game by clicking
, it
is your turn to take sticks. The ball named 25 sticks goes to player1’s box.
The Tkenv window looks like following

8. Continue to run the game by clicking
. A
new dialogue window appears and asks you how many sticks you take. You can only
input 1, 2,3,4, the new window look like the following graph

9. Input a number, for example, 3, and click Ok to continue the game. The Tkenv window will show the message

10. Now each of the two players has taken some sticks. You can easily continue the game until all the sticks are taken. Finally, you will pick up the last stick, then the game is over and the following window appears.

The Tkenv window shows the following message

The last screenshot of graphics window is shown by follow

You can continue to play the game
by clicking
,
you can also click
in the Tkenv
window.
The following dialogue window will appear

Click Yes and you can restart the game. You will find that the number of stick may change and sometime the player who first picks up sticks may also change. If you are selected to first pick up sticks, try to think about it and be a smart player.
This game is very simple and does not have many parameters to change. The number of sticks and the player who first pick up sticks are two parameters we can change. Let us find how we can change it.
Click
and have a look at the structure of Nim

You can expand the object tree to see every item. The two parameters we are looking for are at the following place

The variable “num_sticks” indicates the number of initial sticks and the “first_move” indicates the player who will first move the sticks
double click “num_sticks” you will see the following window

intuniform(21,31) means the number of sticks uniformly distributed between 21 and 31.
double click “num_sticks” you will see the following window

intuniform(1,2) means the number of sticks uniformly distributed between 1 and 2. ‘1’ refers to the player1 and ‘2’ refers to the player2. It means both players have equal probability to be the first player.
You may want to change these two parameters, but it is not straightforward to do so. You need to follow the following steps:
1. Find the nim.ned file in the directory C:\OMNeT++\samples\nim

2. Right click the file and open with notepad.

The following is the content of nim.ned. It defines all the modules and their input, output, and parameters.
//-------------------------------------------------------------
// file: nim.ned
//
(part of NIM - an OMNeT++ demo simulation)
//
// NIM is an ancient game with two
players and a bunch of sticks.
//
// The players take turns, removing
1..4 sticks from the heap
// at each turn.
//
// The player who must take the
*last* stick is the loser.
//
//-------------------------------------------------------------
// Game --
//
// Declaration of simple module
type Game
//
simple Game
parameters:
num_sticks :
numeric, // starting number of sticks
first_move :
numeric; // 1=Player1, 2=Player2
gates:
in: from_player1; // input and output gates
in: from_player2; // for connecting to Player1/Player2
out: to_player1;
out: to_player2;
endsimple
// Player --
//
// Interface declaration for
different modules implementing players
//
simple Player
gates:
in: in; // gates for connecting to Game
out: out;
endsimple
// Nim --
//
// The NIM game's network: Game and
two players interconnected
//
module Nim
parameters:
player1_type : string,
player2_type : string;
submodules:
//
create the Game module, with the initial number of
//
sticks and the starting player as random parameters
game: Game;
parameters:
num_sticks = intuniform
(21, 31),
first_move = intuniform
(1, 2);
//
for players, define module type as parameter to
//
the parent module, Nim
player1: player1_type like Player;
player2: player2_type like Player;
connections:
player1.out --> game.from_player1;
player1.in <-- game.to_player1;
player2.out --> game.from_player2;
player2.in <-- game.to_player2;
endmodule
// nim --
//
// an instance of the Nim module
//
network nim : Nim
parameters:
player1_type
= input("InteractivePlayer"),
player2_type = input("SmartPlayer");
endnetwork
3. The red text is the parameters. We change them to, for example,
num_sticks =27,
first_move = 1;
Save it and close the notepad.
open DOS command window by Start->Run->cmd

You will see the command window

Change directory to cd c:\omnet++\samples\nim

4. Input the command opp_nmakemake -f

5. Then you can build the program by typing:
nmake -f Makefile.vc
The most common problem is that nmake (which is is part of MSVC) cannot be found because it is not in the path. You can fix this by running vcvars32.bat, which can be found in the MSVC bin directory (usually C:\Program Files\Microsoft Visual Studio\VC98\Bin). After successfully execute the nmake command, you will see the following message in the command window

You will find a newly generated nim.exe in the directory.

1. Start the newly configured Nim game and see whether the parameters are changed or not. Double click game in the object tree as follow.

You will see the following window

2. Click Params to see the parameters of game

All the two parameters are listed and we notice their values have been changed. Double Click each of the parameters you can see its value as follow.


3. Run the game and it is your turn to first pick up sticks. Pick up 4, then the other player will pick 1, then, pick up 4 again, and you will win.

Now you have learned how change parameters and make file in OMNeT++
There are various ways to understand the implementation of a new simulation. I found the following approach the most useful. First I run it, of course, to get an understanding of where the various entities reside and how they exchange jobs. Then I work through the files belonging to each entity separately. I start with the .ned file to understand what goes in and out of a module, and the parameters it needs. Then I give the header file a brief look to become familiar with the module’s specific internal variables and functions. Finally I study the C++ code belonging to the module. Once I somewhat understand what this first module does, I take the next module in the simulation chain, that is, the module that gets its messages from the one I just studied. Working this way, I gain a quicker understanding of what is going on than by first working through all .ned files, than all the C++ files, etc.
Each entity in a simulation needs to communicate via messages with itself and other entities. Messages can be used for various purposes. One is to represent sticks that are available. Another is to convey information of the entity’s state to itself in the future, or to other entities. Specifically, the Nim example contains three entities: a game module, two player modules. Clearly, all these modules need in- and output gates to receive and send messages. The .ned file specifies these gates. In our example, the game module has two input and two output gates. Furthermore these modules may need parameters such as number of sticks, first players, etc. These pa