Вы находитесь на странице: 1из 7

Installing NS2 followed by getting Evalvid to work with NS2

(In Ubuntu).

By: Shesha Vishnu Prasad, under the guidance of Mr.Gururaj H.L.

Ill try to keep this documentation as simple as possible to be understood easily by novice.
I hope you understand the commands that are about to be used. If you dont understand,
dont worry; it doesnt matter. At any point of time if you get stuck, just Google it!

LETS BEGIN BY INSTALLING NS2


Login to the system as root user (or use sudo).
Download the NS2 all-in-one compressed file in this link.
Type in the following commands in terminal (optional but recommended).

apt-get update

apt-get dist-upgrade

apt-get update

Now type in following commands to install necessary libraries for NS2.

apt-get install build-essential autoconf automake

apt-get install tcl8.5-dev tk8.5-dev

apt-get install perl xgraph libxt-dev libx11-dev libxmu-dev

apt-get install gcc-4.4


(If youre getting couldnt locate package error, use the command
apt-cache search [keyword]
to find which version is available to install. Eg: apt-cache search gcc)

Move the ns-allinone-2.35.tar.gz package to root directory(/root or /) for this


tutorials convenience and extract it using the following command:

tar -xvzf ns-allinone-2.35.tar.gz

After extracting the file, open the file /ns-allinone-2.35/ns-2.35/linkstate/ls.h


using gedit (Command: gedit /ns-allinone-2.35/ns-2.35/linkstate/ls.h). Now goto
line 137 and replace the word erase with this->erase.
Now goto /ns-allinone-2.35 and install NS2 by typing ./install in terminal.
Sit back and relax (for around 15 minutes) until NS2 is installed.

Now that if your NS2 installation didnt get any error, lets move ahead to set up
the environment variables. Enter gedit ~/.bashrc and edit the file by adding the
following lines at the end of file.

# LD_LIBRARY_PATH
OTCL_LIB=/ns-allinone-2.35/otcl-1.14/
NS2_LIB=/ns-allinone-2.35/lib/
USR_Local_LIB=/usr/local/lib/
export
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$OTCL_LIB:$NS2_LIB:$USR_Local
_LIB
# TCL_LIBRARY
TCL_LIB=/ns-allinone-2.35/tcl8.5.10/library/
USR_LIB=/usr/lib/
export TCL_LIBRARY=$TCL_LIBRARY:$TCL_LIB:$USR_LIB
# PATH
XGRAPH /ns-allinone-2.35/xgraph-12.2/:/ns-allinone-2.35/bin/:/ns-allinone2.35/tcl8.5.10/unix/:/ns-allinone-2.35/tk8.5.10/unix/
NS=/ns-allinone-2.35/ns-2.35/
NAM=/ns-allinone-2.35/nam-1.15/
export PATH=$PATH:$XGRAPH:$NS:$NAM

Now reload the bashrc file by typing source ~/.bashrc .


Run ns command in terminal. If you receive % sign, then NS2 has been installed
successfully! If not, check the path correctly in .bashrc and try restarting the
system.
Optionally, you can run ./validate in ns-2.35 folder to check if everything is okay.
This would take a lot of time(around 1:30hrs).

NOW LETS INSTALL EVALVID


Evalvid is a video transmission evaluation tool which consists of several pre-compiled
binaries. Pre-compiled binaries are files that are just ready to run, provided it has
necessary libraries. So, lets install necessary libraries to get it running!
Just type in following commands in terminal:

add-apt-repository ppa:kirillshkrogalev/ffmpeg-next
apt-get update
apt-get install ffmpeg
apt-get install libssl0.9.8
(This would be installed automatically or would be available in different version).

apt-get install subversion


svn co https://svn.code.sf.net/p/gpac/code/trunk/gpac gpac
cd gpac chmod +x configure
./configure disable-opengl use-js=no use-ft=no usejpeg=no use-png=no use-faad=no use-mad=no usexvid=no use-ffmpeg=no use-ogg=no use-vorbis=no usetheora=no use-openjpeg=no
make
make install
cp bin/gcc/libgpac.so /usr/lib
which MP4Box
(If you find the file /usr/local/bin/MP4Box, then support libraries are successfully
installed.)

apt-get install reinstall libgpac-dev


Download Evalvid pre-compiled binaries here.

Extract the file at /ns-allinone-2.35 directory into folder named


evalvid.
Now run ./psnr in evalvid folder. If your system is 32-bit, then it
would show the command format. If youre on 64 bit system,
then youve to install 32-bit support libraries to execute 32-bit
Evalvid binaries. So, if your system is 64-bit, then execute
following commands:
dpkg --add-architecture i386 (or echo "foreign-architecture i386"
> /etc/dpkg/dpkg.cfg.d/multiarch if youre running Ubuntu 12.04 or below.)

apt-get update
apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386
Now you can run ./psnr in evalvid folder which will show
command format if support libraries are successfully
installed. If youre getting No such file or directory error,
then your system is 64-bit and you need to verify that
youve followed above steps properly.
Congrats on getting Evalvid and NS2 to work successfully! Lets now
integrate them to work together!

INTEGRATE NS2 AND EVALVID


To integrate NS2 and Evalvid, we need to edit some files in ns-allinone-2.35
folder. Well use gedit to edit the files.
Note: To find a particular word in gedit editor, press Ctrl+F and type in the word.

Evalvid and NS2 integrated architecture is shown in below figure.

evaluate end-to-end video quality by


PSNR (PSNR program in Evalvid)

Figure: Integrated architecture of ns-2 and EvalVid (Courtesy: csie.nqu.edu.tw)

Now lets start editing the files. Please follow the below steps:

Edit /ns-allinone-2.35/ns-2.35/common/packet.h file.


o

Find double ts_arr_; and add the following lines after that line.
//add the following three lines

int frametype_; // frame type for MPEG video transmission


double sendtime_; // send time

unsigned long int frame_pkt_id_;

Edit /ns-allinone-2.35/ns-2.35/common/agent.h file.


o

Find inline packet_t function and add the following lines after that line.
// add the following two lines

inline void set_frametype(int type) { frametype_ = type; }


inline void set_prio(int prio) { prio_ = prio; }
o

Find int defttl_; and add the following line after that line.

int frametype_; // frame type for MPEG video transmission

Edit /ns-allinone-2.35/ns-2.35/common/agent.cc file.

o Find ch->error() = 0; and add the following line after that line.
// add the following line

ch->frametype_= frametype_;

Edit ns-allinone-2.35/ns-2.35/tcl/lib/nsdefault.tcl file and add the following lines


at the end of the file.
Agent/myUDP set packetSize_ 1000
Tracefile set debug_ 0

Download the support files here. Extract the myevalvid folder in the downloaded file to
/ns-allinone-2.35/ns-2.35/ directory.

Edit ns-allinone-2.35/ns-2.35/Makefile file.


o Find $(OBJ_STL) and add the following lines before that line.
myevalvid/myudp.o \

myevalvid/myevalvid_sink.o \
myevalvid/myevalvid.o \

Execute the following command in terminal.


./configure ; make clean ; make

If you get any constructor call error, then replace Line 19 in ns-allinone-2.35/ns-

2.35/myevalvid/myudp.cc file with following and re-execute the above command:


UdpAgent();
If you dont get any errors, congrats! Youve integrated Evalvid with NS2.

AN EXAMPLE OF EVALVID WITH NS2


Download a raw yuv video sequence (you can use known yuv videos from
http://trace.eas.asu.edu/yuv/). Eg: bus_cif.yuv

A yuv video sequence is a raw output of any camera or image recorder. Y stands for Luma
and UV stands for chrominance. For more info click here.
Download ffmpeg pre-compiled binary here. Place the ffmpeg file in /ns-allinone-2.35/ns2.35/evalvid directory.
Disable Malloc check to prevent any errors while execution using following command in
terminal:

export MALLOC_CHECK_=0
Goto /ns-allinone-2.35/ns-2.35/evalvid directory and execute the following commands. If
you get any error while executing any of these commands, it would be because your
system may not have support libraries. If you face any errors, then just google the required
file that Ubuntu asks you to know how to get that library installed.
o

./ffmpeg -s cif -r 30 -i bus_cif.yuv -c:v mpeg4 -b:v 64k -bt 32k -g 30 bus_cif.m4v

MP4Box -hint -mtu 1024 -fps 30 -add bus_cif.m4v bus_cif2.mp4

Create reference yuv file to evaluate with received yuv file at receiver:
./ffmpeg -i bus_cif2.mp4 bus_cif_ref.yuv

The Source_Video_Trace file is the video trace file which has the information
about each frame of the video and will be used by ns-2 as a traffic source. Create
the file by using:
./mp4trace -f -s 224.1.2.3 12346 bus_cif2.mp4 > Source_Video_Trace

o
o

Place the Evalvid.tcl file from the downloaded tar file in the myevalvid directory.
Now execute: ns Evalvid.tcl

After simulation, ns-2 will create two files, Send_time_file and Recv_time_file
(the filename as used in the tcl file), which record the sending time and received
time of each packet, respectively.

To reconstruct the transmitted video as it is seen by the receiver, the video and
trace files are processed by etmp4 (Evaluate Traces of MP4-file transmission):
./etmp4 -f -0 -c Send_time_file Recv_time_file Source_Video_Trace bus_cif2.mp4 bus_cif_recv.mp

Now, decode the received video to yuv format:


./ffmpeg -i bus_cif_recv.mp4 bus_cif_recv.yuv

Compute the PSNR:


psnr x y <YUV format> <src.yuv> <dst.yuv> [multiplex] [ssim]

./psnr 352 288 420 bus_cif2.yuv bus_cif_recv.yuv > ref_psnr.txt


o

PSNR is the Peak Signal to Noise Ratio which is calculated in dB which shows the
quality of pixel in image frame.

We can plot the graph PSNR using ref_psnr.txt

Feel free to drop an email(sheshavishnuprasad@gmail.com) if youre stuck at any step.


All the best
References: Testing Video Transmission in NS2 using the Evalvid Framework by Vijay S Ukani.

Вам также может понравиться