Wednesday, 7 August 2013

NS2 : Simulating Link Failure in Wired Networks


   In this post I have included the NS2 Script (TCL Script) for simulating link failure in wired networks. 

$ns rtmodel-at 1.0 down $n1 $n2
The code given above will fail the link between Node n1 and Node n2 at time 1.0.

$ns rtmodel-at 2.0 up $n1 $n2
The code given above will reconnect the link between Node n1 and Node n2 at time 2.0.

Executing the TCL Script

Simulated Network in NAM

Initial Traffic Flow Simulation in NAM

Link Between Node1 and Node2 Failed

 Traffic Flow through a Different Path

Link Between Node1 and Node2 is Up Again


NS2 : Simulating a Simple Wired Network Using TCP


   In this post I have added the NS2 Script (TCL Script) to simulate a Simple Wired Network using TCP (Transmission Control Protocol). 

Executing the TCL Script


NAM Window Showing the Network


NAM Window Showing the Traffic


  Click here to download the NS2 Script.

NS2 : Simulating a Simple Wired Network Using UDP

  
  This post gives the NS2 Script (TCL Script) to simulate a simple network using UDP (User Datagram Protocol ). The Shell command to execute the script is shown below.

Executing the script udp.tcl

NAM Window Showing the Simulation


Tuesday, 6 August 2013

Installing NAM on Fedora 17


  After installing NS-2.35 on Fedora 17 by calling the script ./install on the shell the following message is printed on the screen many often. "Please compile your nam separately". The message tells us that the NAM utility has not been installed properly. In order to install the NAM utility change the file xwd.c

The location of the file xwd.c is ns-allinone-2.35/nam-1.15/xwd.c. In the file xwd.c comment the following line of code as shown below.

// #include <X11/Xmu/WinUtil.h>

Save the file xwd.c.

Run the ./install script on the Shell again. NAM utility will be installed properly.

       

Installing NS-2.35 on Fedora 17


  Installing NS-2 on Fedora 17 only requires executing the ./install command on the Shell. But many often the Make process will fail. If the Make process fails then change the file ls.h.

The location of ls.h is the location of ls.h is  ~/ns-allinone-2.35/ns-2.35/linkstate/ls.h.

Open the file ls.h and change the code in line number 137.

The code in line line number 137 is  void eraseAll( ) { erase(baseMap::begin( ), baseMap::end( )); }  

Change it into the code given below,
void eraseAll( ) { this->erase(baseMap::begin( ), baseMap::end( )); } 

After making the change save the file ls.h.

Now again run the script ./install in the Shell. The installation will be complete.

Friday, 5 July 2013

Nesting of Functions in C

  In many C text books you might see the following piece of information "C language does not allow nesting of functions". But this information is not entirely true. At least for GCC you can have nesting of functions in C. The following program compiles fine with GCC.

#include<stdio.h>
int main()
{
 void first()
 {
     printf("\nFirst Level of Nesting\n");
     void second()
     {
         printf("\nSecond Level of Nesting\n");
         void third()
         {
             printf("\nThird Level of Nesting\n");
         }
         third();
     }
     second();
 }
 first();
}

 

The Figure Below Shows the Output

  Click here to download the C Program.

Tuesday, 11 June 2013

C/C++ Puzzles: PART - 34

  Consider the two C code fragments given below.

Code 1:

int i;
i=0;
while(i < 10)
{
     // Single Line of Code Here
     printf("\n%d",i);
     i++;
}

Code 2:

int i;
for(i=0; i < 10; i++)
{
     // Single Line of Code Here
     printf("\n%d",i);
}

The Output will be same for both the codes. The Output is shown below.



The Challenge is to obtain different outputs for the two codes by adding the same single line of code in place of the comment. You should not make any changes in the code other than replacing the comment with the same single line of code. There might be different ways to solve the puzzle.