Erwin Harahap

do Now or Never

Questioning NS2

Posted by Erwin on February 1, 2012

I use this question for my own purpose only. Anyone can use it with your own risk. There’s no guarantee the script or anything else will work here. Any comment is welcome but don’t expect any replies. Spam comment will be trashed.

  1. How is packet created ?
  2. What is DSR ?
  3. Where is location C++ file code of http/server, http/cache, and http/client ?
  4. How do I know the NS2 code reference ?
  5. How can I get queue length?
  6. How to plot data?
  7. How do I know C++?
  8. How to solve NS2.35 installation problem “tk8.5.10 make failed!” in Linux CentOS 5.7
  9. How to solve NS2.35 installation problem “can’t find X includes ” in Linux CentOS 5.7
  10. How to solve NS2.35 installation problem “tclcl-1.20 make failed! ” in Linux CentOS 5.7

1. How is packet created

SRPacket p;
p.src = net_id;
p.pkt = allocpkt();

hdr_sr *srh = hdr_sr::access(p.pkt);
hdr_ip *iph = hdr_ip::access(p.pkt);
hdr_cmn *cmnh = hdr_cmn::access(p.pkt);

2. What is DSR

DSR is stand for Dynamic Source Routing
for details see this link –> http://www.skynet.ie/~bryan/dsr_faq/

3. Where is location C++ file code of http/server, http/cache, and http/client ?

details code in http.h , http.cc
~/ns-allinone-2.35/ns-2.35/webcache

4. How do I know the NS2 code reference ?

see this link –> http://www-rp.lip6.fr/ns-doc/ns226-doc/html/hierarchy.htm

5. How can I get queue length ?

If you set up a router, you can then create a trace file for it…
$ns duplex-link $router0 $router1 10Mb .05 DropTail
set routertracefile [open routertrace.tr w]
$ns trace-queue $router0 $router1 $routertracefile

And after the simulation runs, you can use an awk script like this one:

#usage:
#awk -f makerouterstats.awk routertrace.tr .1
#or other trace file and time increment

BEGIN {
drops = 0
recv = 0
numinque = 0
time = 0
packetsent = 0
timewindow = ARGV[2]
ARGC = 2
}

$2 > (time + timewindow) {updateTime()}
$1 == “r” {rec += 1}
$1 == “+” {numinque += 1}
$1 == “-” {numinque += -1; packetsent+=1}
$1 == “d” {drops += 1; numinque+= -1}

function updateTime() {
time = time + timewindow
printf(“%s \t %s \t %s \t %s \t %s \n”, time, numinque, drops, recv,
packetsent)
rec = 0
drops = 0
packetsent = 0
}

END {
updateTime()
}

6. How to plot data?

Suppose you want to plot the file d1.dat.
Try the following.

#set terminal postfile (These commented lines would be used to )
#set output “d1_plot.ps” (generate a postscript file. )
set title “Energy vs. Time for Sample Data”
set xlabel “Time”
set ylabel “Energy”
plot “d1.dat” with lines
pause -1 “Hit any key to continue”

This example uses the default X11 window for output. It sets the name of the plot title. Then it set the names of the x-axis and y-axis to Time and Energy (default would be X and Y). The plot command is really the key line. It plots data from a file, using column 1 and 2 as the default x and y values. The limits are set automatically, and data points are connected with lines. Some variations on the plot command are:

  • Plot a function. To plot a function instead of a data file, try
    plot sin(x) with lines
  • Plot in a specified range. To plot a data set in the range 0 < x < 10 and 0.2 < y < 0.6, try
    plot [0,10] [0.2,0.6] "d1.dat" with lines
  • Plot with points. To plot with points, or to plot with lines and points, use the folloing forms
    plot "d1.dat" with points
    plot "d1.dat" with linespoints
  • Plot different columns of datafile. For example, to take x from column 4 and y from column 2,
    plot "data.dat" using 4:2 with lines
  • Plot several functions at once. To plot d1.dat against the line y(x)=exp(-x), try
    plot "d1.dat" with lines, exp(x) with lines
  • Change the Plot Title. To change the name that appears in the ‘key’ in the corner of the plot, try
    plot "d1.dat" title 'Sample Data' with lines
    or, if you don’t like the key, try
    plot "d1.dat" notitle with lines
  • Rainbow plot –> http://gnuplot.sourceforge.net/demo/rainbow.html
  • Another Example –> http://www2.yukawa.kyoto-u.ac.jp/~ohnishi/Lib/gnuplot.html
  • http://sparky.rice.edu/gnuplot.html
  • Gnuplot Demo –> http://gnuplot.sourceforge.net/demo/

7. How do I know C++ ?

8. How to solve NS2.35 installation problem “tk8.5.10 make failed!” in Linux CentOS 5.7

  • Requirements : # yum install \
    libX11-devel libXext-devel libXau-devel libXmu-devel gcc-c++

9. How to solve NS2.35 installation problem “can’t find X includes ” in Linux CentOS 5.7

  • Requirements : # yum install \
    libXt-devel

10. How to solve NS2.35 installation problem “tclcl-1.20 make failed! ” in Linux CentOS 5.7

  • Requirements : # yum install \
    gcc-c++

One Response to “Questioning NS2”

  1. Thanks for the marvelous posting! I actually enjoyed reading it, you’re a great author. I will always bookmark your blog and will often come back later in life. I want to encourage that you continue your great posts, have a nice day!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: