Friday, March 22, 2013

The NS-3 simulator

While the NS-2 is the most widely used simulator for research works in the literature, a newer simulator is now under rapid development. That is NS-3 simulator. Initially I thought NS-3 is a newer version of NS-2 but it is a misunderstanding. NS-3 is a complete new implementation from scratch to suit the requirements of modern network simulations.  It is said that NS-3 is more maintainable and easily extendable comparing to old NS-2 because of it's sophisticated design. Anyway in the future most probably NS-2 will go deprecated and NS-3 simulator will take the lead. Therefore it is better to have some hands on experiences in NS-3 simulator.

To try NS-3 simulator, I installed it on Ubuntu 12.04 LTS and tried some example applications. Since NS-3 is written completely on C++, it seems it is convenient to read though the source code and explore it's implementation comparing to NS-2 which is implemented using C++ and OTcl. In the following paragraphs I'm writing down the steps I followed to install and try NS-3 simulator.
Figure - 1











Download the latest release of NS-3 as a tarball file from the link - http://www.nsnam.org/releases/. Uncompress it to a new directory in your home directory and go in to it from a terminal. In the content of the uncompressed file you should see the file named as build.py which is going to be used for building our NS-3 source code.

Issue the following command to install some necessary packages before we build NS-3.

    sudo apt-get install build-essential

Then issue the following command to build NS-3.

    ./build.py --enable-examples --enable-tests

Now some processing will take place and finally it should say that 'build' finished successfully. Now move it to the ns-3.1x directory inside the uncompressed directory where you would find the file test.py. This script will be used to run some tests on NS-3 to make sure all the modules are working as expected. So, issued the following command to run those tests.

     ./test.py -c core

 After completing those tests successfully, we can try some example scripts in NS-3 to learn how to build and run scripts in NS-3. So, while staying in the  ns-3.1x directory, issue the following command to copy the hello-simulator script to a new place where we will try those examples.

    cp examples/tutorial/hello-simulator.cc scratch/myhello.cc

Now issue the following commands to build and run this script.

    ./waf

    ./waf --run myhello

So, in the terminal you should see the output of this myhello script as Hello Simulator. That is the very first example we ran on NS-3. Now issue the following command to copy another example scripts to our working place.

    cp examples/tutorial/first.cc scratch/my-point-to-point.cc

This example script creates a sever and a client in the simulation and send a packet from the client to the server. Server replies with the echo of the same packet it received from the client. If you open the file my-point-to-point.cc and it won't be hard to understand how it works.

1:  #include "ns3/core-module.h"  
2:  #include "ns3/network-module.h"  
3:  #include "ns3/internet-module.h"  
4:  #include "ns3/point-to-point-module.h"  
5:  #include "ns3/applications-module.h"  
6:  using namespace ns3;  
7:  NS_LOG_COMPONENT_DEFINE ("FirstScriptExample");  
8:  int  
9:  main (int argc, char *argv[])  
10:  {  
11:   LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);  
12:   LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);  
13:   NodeContainer nodes;  
14:   nodes.Create (2);  
15:   PointToPointHelper pointToPoint;  
16:   pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));  
17:   pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));  
18:   NetDeviceContainer devices;  
19:   devices = pointToPoint.Install (nodes);  
20:   InternetStackHelper stack;  
21:   stack.Install (nodes);  
22:   Ipv4AddressHelper address;  
23:   address.SetBase ("10.1.1.0", "255.255.255.0");  
24:   Ipv4InterfaceContainer interfaces = address.Assign (devices);  
25:   UdpEchoServerHelper echoServer (9);  
26:   ApplicationContainer serverApps = echoServer.Install (nodes.Get (1));  
27:   serverApps.Start (Seconds (1.0));  
28:   serverApps.Stop (Seconds (10.0));  
29:   UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9);  
30:   echoClient.SetAttribute ("MaxPackets", UintegerValue (1));  
31:   echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0)));  
32:   echoClient.SetAttribute ("PacketSize", UintegerValue (1024));  
33:   ApplicationContainer clientApps = echoClient.Install (nodes.Get (0));  
34:   clientApps.Start (Seconds (2.0));  
35:   clientApps.Stop (Seconds (10.0));  
36:   Simulator::Run ();  
37:   Simulator::Destroy ();  
38:   return 0;  
39:  }  

This simulation creates a topology as shown in the Figure-1. You can run this application similarly to the previous example by running the following commands.

    ./waf
    ./waf --run scratch/my-point-to-point

That's it. This is the beginning and I need to learn more things in NS-3 simulator in the near future. Most importantly I need to explore how we use it to simulate wireless networks.

Wednesday, March 20, 2013

System Programming: From Exciting World of Linux to (exciting ??) World of Windows

I was a Linux lover for a long time and used to do everything on Linux in my university academic works and research works back in Sri Lanka. However after moving to my new university, things changed so rapidly. Our research group is working mostly on Windows platform and therefore it is better for me to work on Windows just like others. In this way it's easier to work together.


So, now I'm running on Windows 7. Initially it wasn't easy for me to adapt but now I'm feeling comfortable on Windows. In this very first semester there is a course on System Programming on Windows. Well, I have done so much system programming on Linux but Windows is new to me. So, I decided to take the course and see.

In this course we are using the same C compiler which comes bundled with MS Visual Studio but without using the high-level application frameworks we are writing codes directly using Windows API. This way we get the understanding about the internal architecture and functionality of Windows OS.

Here's how we create a new copy of a file using Windows API. Of course I have used some standard C library functions (i.e- printf() ) inside the code but if we want we can write those functionality also using much lower Windows API.

1:  /* Basic cp file copy program                */  
2:  /* cpW file1 file2: Copy file1 to file2           */  
3:  #include <windows.h> /* Always required for Windows */  
4:  #include <stdio.h>  
5:  #define BUF_SIZE 256 /* Increase for faster copy */  
6:  int main(int argc, LPTSTR argv [])  
7:  {  
8:       HANDLE hIn, hOut; /* Input and output handles */  
9:       DWORD nIn, nOut; /* Number bytes transferred */  
10:       CHAR Buffer[BUF_SIZE];  
11:       if (argc != 3) {  
12:            printf ("Usage: cp file1 file2\n");  
13:            return 1;  
14:  }  
15:  /* Create handles for reading and writing. Many     */  
16:  /*     default values are used                */  
17:  hIn = CreateFile (argv[1], GENERIC_READ, 0, NULL,  
18:       OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);  
19:  if (hIn == INVALID_HANDLE_VALUE) {  
20:       printf ("Cannot open input file\n");  
21:       return 2;  
22:  }  
23:  hOut = CreateFile (argv[2], GENERIC_WRITE, 0, NULL,  
24:       CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);  
25:  if (hOut == INVALID_HANDLE_VALUE) {  
26:       printf ("Cannot open output file\n");  
27:       return 3;  
28:  }  
29:  /*     Input and output file handles are open.     */  
30:  /*     Copy file. Note end-of-file detection      */  
31:  while (ReadFile (hIn, Buffer, BUF_SIZE,     &nIn, NULL) && nIn > 0)  
32:       WriteFile (hOut, Buffer, nIn, &nOut, NULL);  
33:  /*     Deallocate resources, such as open handles */  
34:       CloseHandle (hIn); CloseHandle (hOut);  
35:       return 0;  
36:  }  

Save this file as cpW.c in somewhere in your home directory. Additionally create a text file (eg- file1.txt) in the same place with some content. Open the Visual Studio command prompt and go to the place where these files are saved. Issue the following command to compile the program.

               cl cpW.c

Now there should be a file as cpW.exe in that directory. You can use that executable to create a new copy of our text file. Let's do that by using following way.

               cpW file1.txt file2.txt

Now you will find the new text file file2.txt in the same directory with the same content of the first file. This is the very first program I had to write using Windows API. More interesting things will come ahead of time.

I will write those new things I learn on Windows API in the future.



Tuesday, March 5, 2013

Towards Intelligent Transportation Systems (ITS)

Day by day, the amount of vehicles in the roads is increasing. Proportionally to it, the amount of road side accidents and the traffic jams are increasing. Those traditional traffic controlling mechanisms, rules and regulations are unable to control this increasing issue anymore. This is where the need for intelligent transportation systems arise. We need smarter ways to coordinate vehicles on the road so that our transportation system becomes more efficient, safe and human friendly.

Vehicles mounted with sensors and wireless communication units are such a way towards implementing intelligent transportation systems. While moving on the road these vehicles can exchange valuable information to supplement safe and efficient driving. In addition to the vehicles, some base station units mounted in road sides can provide and gather information. These kinds of networks builds the new research field called Vehicular Ad-hoc Networks (VANET) which is a special case of the Mobile Ad-hoc Networks (MANET). VANETs differ from MANETs in various ways. One important aspect is the high mobility of nodes in vehicular networks since motor vehicles are moving so fast from each other on the road. VANETs differ from Wireless Sensor Networks (WSN) since VANET nodes virtually does not suffer from any resource constraint since power and hardware resources are easily available to nodes mounted in automobiles.

A key challenge faced by VANET researchers is how to provide communication links between vehicles as they are travelling very fast from each other on the road. As an example when two vehicles move to opposite directions passing each other at a high speed, the amount of time they are in each others wireless transmission range can be few seconds or less. Therefore if messages has to be passed from one to another, it should be done so quickly. But in traditional wireless networks, the connection establishment take some considerable time which is not acceptable in VANET scenarios. For example if the network uses IEEE 802.11 for communication, the two vehicles might not be able set up the connection before they go far away from the transmission ranges of each other.

On addressing these issues, researchers have made some improvements to the above standard which is considered as IEEE 802.11p and it is specifically designed to cope with high node mobility condition in VANETs. Another standard called IEEE 1609 is also have introduced which runs on top of IEEE 802.11p layer to provide further necessary functionality for IEEE 802.11p protocol. Altogether we call this WAVE (Wireless Access in Vehicular Environments) protocol. There are lot of active research going on in this area, so we can hope we will have VANET equipped automobiles in our roads in the near future.

Saturday, March 2, 2013

Entered to Kyungpook National University (KNU)

About a week ago I left my country and my work place and moved to a new place to start another chapter of my life. Now I'm a graduate student at Kyungpook National University (KNU) in Daegu city, South Korea. I will be staying here several years until I complete my masters and doctoral studies.

I arrived in the beginning of the Spring season and therefore it's still cold everywhere. There are some Sri Lankan students who are studying here including a past student of University of Colombo School of Computing (UCSC). Their existence made my life easier since they knew all the necessary things  to survive here before I arrive.

I'm staying in a dormitory of KNU and therefore it's much easier to carry on my work. Dormitory has all the facilities and it's very comfortable. The three meals for a day is provided by the dormitory cafeteria. I'm working with Professor Dongkyun Kim and he is my academic adviser. He is leading the Wireless & Mobile Internet Laboratory (MoNet) in the department of computer science and engineering where I'm involved with his research work. The other members of the MoNet lab includes some graduate students from Korea and also Pakistan. All of them are so friendly to me.

By any mean KNU is a beautiful university. It is so huge and has almost all the components of a university such as medical, engineering, humanities, etc. Still I got only few chances to go around the university. There are so many things to explore. Until this article all the previous articles I've written are don while staying in Sri Lanka. But from now on I will be writing about various things from here in my new place.