Gk's Blog
Friday, November 13, 2009
  Cài đặt NS2 trên Ubuntu 9.10 - Karmic Koala
Hướng dẫn này sử dụng Ubuntu Desktop 9.10. NS2 dùng bộ cài đặt ns2 allinone phiên bản 2.34. Hầu hết hướng dẫn có thể dùng với phiên bản khác.

Cài đặt Ubuntu trên VMWare với easy installation của VMWare cho Ubuntu (gần tương đương với cài đặt mặc định của bản Desktop)

+Cài đặt NS2

-Download NS2: mở Terminal gõ lệnh:
cd ~
wget http://nchc.dl.sourceforge.net/project/nsnam/allinone/ns-allinone-2.34/ns-allinone-2.34.tar.gz
* Bản mới hơn có thể tìm trên sf: http://sourceforge.net/projects/nsnam/files/allinone/
-Cài đặt thư viện, trình biên dịch

sudo apt-get install -f build-essential libxt-dev libxt6 libsm-dev libsm6 libice-dev libice6 libxmu-dev
-Giải nén và cài đặt ns-allinone:
tar -xzf ns-allinone-2.34.tar.gz
cd ns-allinone-2.34
./install
* Chú ý: với bản Ubuntu 9.10 có thể gặp lỗi sau
otcl.o: In function `OTclDispatch': /home/ns/ns-allinone-2.34/otcl/otcl.c:495: undefined reference to `__stack_chk_fail_local' otcl.o: In function `Otcl_Init': /home/ns/ns-allinone-2.34/otcl/otcl.c:2284: undefined reference to `__stack_chk_fail_local' ld: libotcl.so: hidden symbol `__stack_chk_fail_local' isn't defined ld: final link failed: Nonrepresentable section on output make: *** [libotcl.so] Error 1
Lỗi này là do file config của otcl sử dụng nhầm linker (ld thay vì gcc).
Sửa bằng cách edit file otcl-1.13/configure trong thư mục ns-allinone-2.34
gedit otcl-1.13/configure
sửa dòng 6304 từ

SHLIB_LD="ld -shared"
thành
SHLIB_LD="gcc -shared"
-Thiết lập biến môi trường:
Sửa file ~/.bashrc:
Cách1:

gedit ~/.bashrc

thêm vào cuối file đoạn (*chú ý đổi đường dẫn chính xác: username thành tên user bạn đang dùng, có thể dùng lệnh whoami để lấy, đổi tên thư mục cho chính xác với phiên bản đang dùng)
#LD_LIBRARY_PATH
OTCL_LIB=/home/username/ns-allinone-2.34/otcl-1.13
NS2_LIB=/home/username/ns-allinone-2.34/lib
X11_LIB=/usr/X11R6/lib
USR_LOCAL_LIB=/usr/local/lib
# TCL_LIBRARY
TCL_LIB=/home/username/ns-allinone-2.34/tcl8.4.18/library
USR_LIB=/usr/lib
# PATH
XGRAPH=/home/username/ns-allinone-2.34/bin:/home/username/ns-allinone-2.34/tcl8.4.18/unix:/home/username/ns-allinone-2.34/tk8.4.18/unix
NS=/home/username/ns-allinone-2.34/ns-2.34/
NAM=/home/username/ns-allinone-2.34/nam-1.14/
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$OTCL_LIB:$NS2_LIB:$X11_LIB:$USR_LOCAL_LIB
export TCL_LIBRARY=$TCL_LIB:$USR_LIB
PATH=$PATH:$XGRAPH:$NS:$NAM
Sau đó chạy lệnh:

source ~/.bashrc

Cách 2:
Download file script genPATH (nội dung file xem ở cuối bài)
http://210.245.86.152/tantt/msk15/genPATH
(mirror http://www.mediafire.com/file/kjgg5njmz2q/genPATH )

đặt vào thư mục ns-allinone-2.34/

Chạy lệnh
bash genPATH
Sau đó chạy lệnh:

source ~/.bashrc
-Kiểm tra:
Chạy thử bằng cách gõ lệnh
ns
Nếu thấy xuất hiện dấu nhắc:
%
là đã thành công. Nếu chưa được kiểm tra lại bước Thiết lập biến môi trường.

+Cài đặt gnuplot và xgraph:


sudo apt-get install gnuplot xgraph

------------------------------------------------------
Nội dung file genPATH:

#!/bin/bash
PWD=`pwd`
ns2PATH="#LD_LIBRARY_PATH\n
OTCL_LIB=$PWD/`ls $PWD | grep tcl-`\n
NS2_LIB=`pwd`/lib\n
X11_LIB=/usr/X11R6/lib\n
USR_LOCAL_LIB=/usr/local/lib\n

# TCL_LIBRARY\n
TCL_LIB=$PWD/`ls $PWD | grep -e tcl[0-9].*`/library\n
USR_LIB=/usr/lib\n

# PATH\n
XGRAPH=`pwd`/bin:$PWD/`ls $PWD | grep -e 'tcl[0-9].*'`/unix:$PWD/`ls $PWD | grep -e 'tk[0-9].*'`/unix\n
NS=$PWD/`ls $PWD | grep -e 'ns-[0-9].*'`/\n
NAM=$PWD/`ls $PWD | grep -e 'nam-[0-9].*'`/"
echo -e $ns2PATH >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$OTCL_LIB:$NS2_LIB:$X11_LIB:$USR_LOCAL_LIB'>>~/.bashrc
echo 'export TCL_LIBRARY=$TCL_LIB:$USR_LIB'>>~/.bashrc
echo 'PATH=$PATH:$XGRAPH:$NS:$NAM'>>~/.bashrc

Labels: ,

 
Comments:
thanks for tutorial.If you get a problem,you can see a different ưay here: http://ns2onubuntu.blogspot.com/2009/11/easiest-way-to-install-ns2-on-ubuntu.html
 
Post a Comment

Subscribe to Post Comments [Atom]





<< Home

My Photo
Name:
Location: Hanoi, Vietnam
Archives
July 2009 / November 2009 / January 2010 / August 2010 / September 2010 / June 2011 / September 2013 /


Powered by Blogger

Subscribe to
Posts [Atom]