Chapter 4. Creating and Running a Simulation

In this chapter, you will learn how to create your own network simulation and then run it using OMNeT++. After going through the previous chapters, you should have no problems understanding this chapter! You will learn the following topics:

  • How to create the topology of your network using both the OMNeT++ IDE and the NED language
  • How to create multiple scenarios for your simulation using the same network topology
  • How to run and control the flow of your simulation

The OMNeT++ IDE

The OMNeT++ IDE provides you with the ideal environment to develop and run your OMNeT++ simulations. Based on the popular and extremely versatile Java-based Eclipse IDE platform, the OMNeT++ IDE is essentially a customized build of Eclipse. What's great about this development environment of OMNeT++ is that you're able to create network simulations without having to do any coding. However, if you need some extra functionality in your simulation, the OMNeT++ IDE lets you go as deep into the code as you want.

If we open up the OMNeT++ IDE, we should see the INET project that we previously set up. Using the Project Explorer on the left-hand side of the window, we can navigate through all the files and folders inside that project.

The OMNeT++ IDE

If you click on the triangle just on the left of the src folder, you will see a number of folders. These folders contain the source code that makes up the INET framework. This source code gives you the perfect template if you wish to write your own network protocols. The OMNeT++ IDE is also a fully-fledged development environment for C++ coding. Click on the triangle just on the left of the applications folder and then do the same for the dhcp folder. Now you'll see a listing of the source code that makes up an INET module for the Dynamic Host Configuration Protocol, as shown in the following screenshot:

The OMNeT++ IDE

To take a look at the source code for this module, just double-click on the DHCPClient.cc source file to open it. The OMNeT++ IDE provides really good code indentation and great syntax coloring which makes reading and writing code much easier.

The following is a snippet of the DHCPClient.cc file:

#include "DHCPClient.h"

#include "InterfaceTableAccess.h"
#include "IPv4InterfaceData.h"
#include "ModuleAccess.h"
#include "NotifierConsts.h"
#include "RoutingTableAccess.h"

Define_Module(DHCPClient);

DHCPClient::DHCPClient()
{
    timer_t1 = NULL;
    timer_t2 = NULL;
    timer_to = NULL;
    nb = NULL;
    ie = NULL;
    irt = NULL;
    lease = NULL;
}

DHCPClient::~DHCPClient()
{
    cancelTimer_T1();
    cancelTimer_T2();
    cancelTimer_TO();
}

The preceding code will make more sense as you continue through this chapter. Note how DHCPClient is parsed into a method called Define_Module() . It must be an OMNeT++ module!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.28.108