NS2(Network Simulator)는 오픈 소스로 개발되어 소스가 공개되어 있고 무료로 사용이 가능한 네트워크 시뮬레이션 프로그램이다. 리눅스 기반의 환경에서 잘 동작한다.
이 프로그램은
홈페이지에서 다운로드가 가능하다. 홈페이지에서 다운로드를 할 때에 일반 사용자 계정에서 사용할 것을 권장하며, ns2만이 아닌 ns2-allinone 패키지의 다운로드를 권장한다.
ns2만을 다운로드할 경우 다른 tcl 패키지가 시스템에 적당하게 설치되어 있어야 한다. 하지만 ns2-allinone의 경우에는 시스템에 설치된 tcl의 버전과 상관없이 ns2-allinone에 포함된 버전으로 컴파일과 설치가 진행되기 때문에 독립적으로 컴파일하고 동작이 가능하도록 되어있다.
ns2-allinone의 설치 방법은 다음과 같다.
먼저 ns2-allinone의 압축을 푼다. 여기에서는 ns-allinone-2.2.8.tar.gz 파일의 압축을 푼다.
[yarang@wuc235 ~]$ tar zxf simul/ns-allinone-2.28.tar.gz
[yarang@wuc235 ~]$ cd ns-allinone-2.28
[yarang@wuc235 ns-allinone-2.28]$ ls
INSTALL.WIN32 cweb install ns-2.28 sgb tclcl-1.16 xgraph-12.1
README gt-itm nam-1.11 otcl-1.9 tcl8.4.5 tk8.4.5 zlib-1.1.4
설치를 진행하기 전에 페도라 코어 4의 gcc 버전에 적합한 패치를 해주어야 한다. gcc의 버전을 확인하는 명령은 다음과 같다.
[yarang@wuc235 ns-2.28]$ gcc --version
gcc (GCC) 4.0.2 20051125 (Red Hat 4.0.2-8)
Copyright (C) 2005 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
위에서와 같이 페도라 코어 4는 gcc 4.0.2를 사용하고 있다. 그래서 ns2를 컴파일해주기 위해서 gcc 버전에 맞도록 패치를 해주어야 한다. ns228-gcc40.patch 파일은 ns2-2.28 버전에 gcc 4.0에 대한 패치를 적용하는 파일이다. 패치는 다음과 같은 명령으로 가능하다.
[yarang@wuc235 ns-allinone-2.28]$ patch -p1 < ../simul/ns228-gcc40.patch
patching file nam-1.11/agent.h
patching file ns-2.28/diffusion3/lib/nr/nr.hh
patching file ns-2.28/xcp/xcpq.cc
patching file ns-2.28/xcp/xcpq.h
위의 패치를 적용한다 하더라도 컴파일을 하면 다음과 같은 에러가 발생한다. 페도라 코어 4에서 아래와 같은 에러가 발생하면 수동으로 파일을 수정해 주어야 한다. 에러가 발생한 것은 다음과 같을 것이다.
g++ -c -DTCP_DELAY_BIND_ALL -DNO_TK -DTCLCL_CLASSINSTVAR -DNDEBUG -DLINUX_TCP_HEADER -DUSE_SHM -DHAVE_LIBTCLCL -DHAVE_TCLCL_H -DHAVE_LIBOTCL1_9 -DHAVE_OTCL_H -DHAVE_LIBTK8_4 -DHAVE_TK_H -DHAVE_LIBTCL8_4 -DHAVE_TCL_H -DHAVE_CONFIG_H -DNS_DIFFUSION -DSMAC_NO_SYNC -DCPP_NAMESPACE=std -DUSE_SINGLE_ADDRESS_SPACE -Drng_test -I. -I/home/users/yarang/ns-allinone-2.28/tclcl-1.16 -I/home/users/yarang/ns-allinone-2.28/otcl-1.9 -I/home/users/yarang/ns-allinone-2.28/include -I/home/users/yarang/ns-allinone-2.28/include -I/usr/include/pcap -I./tcp -I./sctp -I./common -I./link -I./queue -I./adc -I./apps -I./mac -I./mobile -I./trace -I./routing -I./tools -I./classifier -I./mcast -I./diffusion3/lib/main -I./diffusion3/lib -I./diffusion3/lib/nr -I./diffusion3/ns -I./diffusion3/filter_core -I./asim/ -I./qs -I./diffserv -I./wpan -o queue/cbq.o queue/cbq.cc
queue/cbq.cc:112: error: ISO C++ forbids declaration of #CBQueue# with no type
queue/cbq.cc:112: error: expected #;# before #*# token
queue/cbq.cc: In member function #virtual int CBQueue::insert_class(CBQClass*)#:
queue/cbq.cc:488: error: #class CBQClass# has no member named #cbq_#
queue/cbq.cc: In constructor #CBQClass::CBQClass()#:
queue/cbq.cc:805: error: class #CBQClass# does not have any field named #cbq_#
queue/cbq.cc: In member function #virtual void CBQClass::recv(Packet*, Handler*)#:
queue/cbq.cc:850: error: #cbq_# was not declared in this scope
queue/cbq.cc:856: error: #cbq_# was not declared in this scope
queue/cbq.cc: In member function #void CBQClass::update(Packet*, double)#:
queue/cbq.cc:873: error: #cbq_# was not declared in this scope
queue/cbq.cc: In member function #int CBQClass::desc_with_demand()#:
queue/cbq.cc:928: error: #cbq_# was not declared in this scope
queue/cbq.cc: In member function #void CBQClass::newallot(double)#:
queue/cbq.cc:975: error: #cbq_# was not declared in this scope
queue/cbq.cc: In member function #virtual int CBQClass::command(int, const char* const*)#:
queue/cbq.cc:1002: error: #cbq_# was not declared in this scope
make: *** [queue/cbq.o] ## 1
Ns make failed!
See http://www.isi.edu/nsnam/ns/ns-problems.html for problems
[yarang@wuc235 ns-allinone-2.28]$
위의 에러가 발생하면 직접 소스를 고쳐야 하는데 고쳐야 하는 소스와 위치는 다음과 같다. 모든 소스는 ns2-2.28 디렉토리에 있으며 고쳐야 하는 소스의 부분은 다음과 같다.
파일 : queue/cbq.cc
88 #define POWEROFTWO 16
89
90 class CBQueue; <-- 추가된 부분
91
92 class CBQClass : public Connector
파일 : tora/tora_neighbor.h
46 LINK_DN = 0x0002, // downstream
47 LINK_UN = 0x0004, // undirected
48 };
49
50 class toraAgent; <-- 추가된 부분
51
52 class TORANeighbor {
53 friend class TORADest;
54 friend class toraAgent;
파일 : diffusion3/filter_core/filter_core.hh
103 typedef list NeighborList;
104 typedef list HashList;
105 typedef list BlackList;
106
107 class DiffRoutingAgent; <-- 추가된 부분
108
109 class DiffusionCoreAgent {
110 public:
111 #ifdef NS_DIFFUSION
112 friend class DiffRoutingAgent;
위의 파일들을 수정한 다음에 다시 설치 명령을 실행하면 컴파일이 다시 시작된다.
[yarang@wuc235 ns-allinone-2.28]$ ./install
모든 컴파일을 성공하면 다음과 같은 메시지가 나온다.
Please compile your gt-itm & sgb2ns separately.
Ns-allinone package has been installed successfully.
Here are the installation places:
tcl8.4.5: /home/users/yarang/ns-allinone-2.28/{bin,include,lib}
tk8.4.5: /home/users/yarang/ns-allinone-2.28/{bin,include,lib}
otcl: /home/users/yarang/ns-allinone-2.28/otcl-1.9
tclcl: /home/users/yarang/ns-allinone-2.28/tclcl-1.16
ns: /home/users/yarang/ns-allinone-2.28/ns-2.28/ns
nam: /home/users/yarang/ns-allinone-2.28/nam-1.11/nam
xgraph: /home/users/yarang/ns-allinone-2.28/xgraph-12.1
----------------------------------------------------------------------------------
Please put
/home/users/yarang/ns-allinone-2.28/bin:/home/users/yarang/ns-allinone-2.28/tcl8.4.5/unix:/home/users/yarang/ns-allinone-2.28/tk8.4.5/unixinto your
PATH environment; so that you'll be able to run itm/tclsh/wish/xgraph.
IMPORTANT NOTICES:
(1) You MUST put
/home/users/yarang/ns-allinone-2.28/otcl-1.9, /home/users/yarang/ns-allinone-2.28/lib,
into your
LD_LIBRARY_PATH environment variable.
If it complains about X libraries, add path to your X libraries
into LD_LIBRARY_PATH.
If you are using csh, you can set it like:
setenv LD_LIBRARY_PATH
If you are using sh, you can set it like:
export LD_LIBRARY_PATH=
(2) You MUST put /home/users/yarang/ns-allinone-2.28/tcl8.4.5/library into your TCL_LIBRARY environmental
variable. Otherwise ns/nam will complain during startup.
(3) [OPTIONAL] To save disk space, you can now delete directories tcl8.4.5
and tk8.4.5. They are now installed under /home/users/yarang/ns-allinone-2.28/{bin,include,lib}
After these steps, you can now run the ns validation suite with
cd ns-2.28; ./validate
For trouble shooting, please first read ns problems page
http://www.isi.edu/nsnam/ns/ns-problems.html. Also search the ns mailing list archive
for related posts.
그리고 PATH를 추가하기 위해서 다음과 같은 설정을 .bash_profile에 넣어준다.
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=/usr/java/j2sdk1.4.2_04/bin:~/ns-allinone-2.28/bin:~/ns-allinone-2.28/tcl8.4.5/unix:~/ns-allinone-2.28/tk8.4.5/unix:$PATH:$HOME/bin
LD_LIBRARY_PATH=~/ns-allinone-2.28/otcl-1.9:~/ns-allinone-2.28/lib
TCL_LIBRARY=~/ns-allinone-2.28/tcl8.4.5/library
export PATH LD_LIBRARY_PATH TCL_LIBRARY
unset USERNAME
잘보면 위에서는
/home/users/yarang/이라고 명시된 부분이 아래에서는
~/로 변경되어 있을 것이다. 사용자의 홈 디렉토리가
/home/users/yarang/ 이기 때문에 이와 동일한
~/로 변경하여 보여준 것이다. 그러므로 이 둘은 동일하게 작동한다. 하지만 다른 사용자가 설치한 경우에는 홈 디렉토리의 위치가 변경되기 때문에
~/를 사용한 경우에는 사용자가 변경되어도 설정을 변경없이 사용이 가능하다.

trackbacks
http://main.yarang.com/trackback/9
comments
comments rss (+댓글 쓰러가기)