The goal of this post is to clarify the structure of an OMNET++ simulation, explaining how the file structure works and where you should include each part of your simulation.
As described in the post about the Network Simulators, OMNET++ has an IDE based on Eclipse that makes it easier to create a project and run simulations. The structure of an OMNET++ simulation can be explained by three file levels:
The source code (C++)
This is the bottom level. Here, you should include the algorithms that will be used, which is the intelligence of your simulation. You can imagine that if you are simulating a system which is going to be sold, the C++ code is the part that you would sell to your clients. Therefore, it should be as generic as possible and have no dependency with specific use cases. Usually, you have one source code that works for every simulation and you do not have to recompile to observe how your system would behave in a different scenario.
OMNET++ has a component-based structure. Each component has a different description and its behavior, which is defined by the algorithm implemented at this level.
Examples at this level: Protocols to manage queues, access control and messages that are used by the network components.
The Network Description (NED files)
In these files, you should set up the structures that you are planning to simulate, link the components and establish a relationship between them.
The most relevant observation is that each NED file may describe only one topology level. For example, if you are describing the network, your components will be computers, switches, routers and so on. To describe the protocol stack of a computer you must create another NED file, which components will be the different layers: physical, MAC, link, presentation, application, etc.
In the end, you may have a tree like this:
In summary, if you want to connect your Computer with your Router, you should:
- In the Computer description, define a link between its physical layer and the external input/output connection;
- In the Router description, define a link between its physical layer and the external input/output connection;
- In the Network description, define the Channel and connect the external interface of the Computer and the external interface of the Router to the Channel.
Link between the Network Description and the Source code:
The link between a component and its algorithm is done by the command “Define_Module(ned_filename)” in the source code. By doing this connection, you will be able to set, in the upper layers, the parameters that will be used by the algorithm.
The Configuration File (omnet.ini)
In this text file, you can describe simulation-specific parameters that you may want to compare. For example, you can change the size of the packets that you are transmitting in order to see how good your computer will handle the network traffic. The recommendation is that you create one ini file with multiple configurations of different simulations, but you can reuse the lower levels to make multiple simulations and compare different parameters on each one.
Each configuration is defined by a section “Config”, for example:
*.packetSize = 20b
*.packetSize = 100b
In the case above, you have two different simulations (A and B) and you may choose one to run.
Link between the Configuration File and the Network Description:
At this level, it is also possible to set which modules you want to use, according to your requirements. For example, if your tests want to compare the performance of different MAC protocols in the Computer, it is possible to define:
Computer.MACprotocol = CSMA
Computer.MACprotocol = TDMA
Important: The content of this file depends on what you need to compare with the simulations. For example, if you want to compare different MAC protocols, you should consider setting the network interface at the Network description.
By default, each run will generate output files with vectors and scalar values and those files are saved in a folder called “results” and have extensions .vec and .sca, respectively. Using the tools available in the IDE, it is possible to generate different types of charts (bars, lines, etc) using as well as create macros to plot charts later.
If you are creating your first simulation, you may follow these steps:
- Translate your system into a hierarchy of communicating modules (the tree described above)
- Define the model structure in the NED files
- Develop the source code (C++)
- Create the omnetpp.ini
- Run it