SyntaxHighlighter

2010-07-06

NS-2 (Network Simulator Ver.2) install log

以下の内容はKの日記~with ubuntu~より。忘れてしまうや元サイトが接続不能を避けて、ここに転載したもの。内容に出入があれば、全ては元サイトの方を正しいとします。




NS-2 (Network Simulator Ver.2)とは、計算機上でネットワークをエミュレートしてデータの転送実験等ができるソフトです。

新たなプロトコルを開発し、仮想ネットワークに実装して実験する事も出来ます。

OTclを習得しないと実験自体ができず、C++を習得しないとモジュールの開発は出来ず、マニュアルには間違いも多く、日本語の書籍は殆ど無く・・・と、大変無愛想なシミュレータです。

しかしながら多くの機能を実装している上、無料で利用できるので、研究予算の無い学生にはありがたいです。


最近Ubuntu利用者が増えているのに伴い、このソフトをUbuntuにインストールして利用する人も増えているようです。

筆者自身もインストールして使っているので、インストール方法を書いておきます。


Ubuntu9.10およびUbuntu10.04へのインストールも可能です。

もし挫折している方がみえましたら、参考になれば幸いです。




【1】必要なパッケージのインストール

NS-2に必要なパッケージをインストールします。

sudo apt-get update
sudo apt-get install build-essential xorg-dev libpcap-dev libtool gcc g++ xgraph





【2】ソースをダウンロード

NS-2の本家(http://www.isi.edu/nsnam/ns/)へ行って"ns-allinone-2.**"パッケージをダウンロードするか、端末からwgetで取得します

今回は、現時点での最新版である 2.34 を利用してみます。

wget http://sourceforge.net/projects/nsnam/files/allinone/ns-allinone-2.34/ns-allinone-2.34.tar.gz/download


↑の2.342.33に書き換えれば前のバージョンがDL可能です。


解凍します。

tar zxvf ns-allinone-2.34.tar.gz



以下の操作は全てns-allinone-2.34ディレクトリ内で行うものとします




【3】xgraphのソースファイル削除

xgraphは、ns-allinone-2.34のソースに含まれており、ソースを直接ビルドすることもできますが、Ubuntuのパッケージが用意されているのでapt-getでインストールしてしまいます。

なので、このソースは必要なくなったので消してしまいます。

rm -rf xgraph-12.1





【4】installスクリプトからxgraphのインストールコマンドを削除

xgraphのソースを削除しましたが、インストール用のシェルスクリプトにはxgraphのインストールコマンドもかかれているので、これも無効にします。

消してしまってもいいですが、コメントアウトでも構いません。

まずinstallを開きます。

gedit install


スクリプトの最後の方にxgraphのインストールスクリプトが書かれています。

[Ctrl] + [F]

xgraphを文字列検索すると見つけやすいです。


286行目の # Compile and install xgraph から、

304行目の cd ../

がインストールスクリプトなので、286?304行目を全てコメントアウト(行頭に#を付記)します。

続いて638?643行目でシンボリックリンクを張っているので、同様にコメントアウト。

671?674行目でインストールディレクトリを表示しているので、これも同様にコメントアウト。




【!】Ubuntu9.10 or Ubuntu10.04 の場合

Ubuntu9.10もしくはUbuntu10.04でインストールしようとすると、OTclのビルド中に、

============================================================
* Build OTcl-1.13
============================================================
No .configure file found in current directory
Continuing with default options...
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking target system type... i686-pc-linux-gnu
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for g++... g++
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for string.h... (cached) yes
checking for main in -lXbsd... no
checking for socket in -lsocket... no
checking for gethostbyname in -lnsl... yes
checking for dcgettext in -lintl... no
checking for getnodebyname in -ldnet_stub... no
checking that g++ can handle -O2... no
checking standard STL is available... no
checking for tcl.h... -I../include
checking for tclInt.h... -I../include
checking for libtcl8.4... -L../lib -ltcl8.4
checking for init.tcl... ../lib/tcl8.4
checking for http.tcl... ../lib/tcl8.4/http1.0
checking Tcl http.tcl library... yes
checking for tclsh8.4.18... no
checking for tclsh8.4... ../bin/tclsh8.4
checking for tk.h... -I../include
checking for libtk8.4... -L../lib -ltk8.4
checking for tk.tcl... ../lib/tk8.4
checking for X11 header files
checking for X11 library archive
checking for XOpenDisplay in -lX11... yes
checking for XShmAttach in -lXext... yes
checking for ranlib... ranlib
checking for a BSD-compatible install... /usr/bin/install -c
checking system version (for dynamic loading)... Linux-2.6.32-21-generic
No explicit static compilation flag; setting V_STATIC to ""
checking for dlopen in -ldl... yes
checking for a BSD-compatible install... /usr/bin/install -c
configure: creating ./config.status
config.status: creating Makefile
rm -f libotcl.so otcl.o so_locations
gcc -c -g -O2 -DNDEBUG -DUSE_SHM -fpic -I. -I/usr/local/ns-allinone-2.34/include -I/usr/local/ns-allinone-2.34/include -I/usr/local/ns-allinone-2.34/include -I/include otcl.c
ld -shared -o libotcl.so otcl.o
otcl.o: In function `OTclDispatch':
/usr/local/ns-allinone-2.34/otcl-1.13/otcl.c:495: undefined reference to `__stack_chk_fail_local'
otcl.o: In function `Otcl_Init':
/usr/local/ns-allinone-2.34/otcl-1.13/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] エラー 1
otcl-1.13 make failed! Exiting ...
See http://www.isi.edu/nsnam/ns/ns-problems.html for problems


こんなエラーが出てインストールが停止してしまいます。

これはどうもGCCのバージョンとOTclの相性が悪いのが原因のようです。

Ubuntu9.10及びUbuntu10.04に標準でインストールされるGCCのバージョンは4.4です。

Ubuntu9.04ではGCCのバージョンは4.3で、普通にインストール出来ていました。

なので、Otclのインストール時だけコンパイラをgcc-4.3に変更してビルドしてやります。

なお、OtclのソースにはC++ソースはありませんので、g++のバージョン変更は必要ありません。


まずgcc-4.3をインストールします。

sudo apt-get update
sudo apt-get install gcc-4.3


次に、

ns-allinone-2.34/otcl-1.13/Makefile.in

というファイルを開きます。

ファイルの先頭付近に、

CC= @CC@


という記述があります。これを

CC= gcc-4.3


と書き換えます。こうすることでOTclのインストールに使うコンパイラをgcc-4.3に変更出来ます。

ちなみにコンパイラのバージョンによるエラーが出るのはOTclだけのようです。

変更を保存したらインストールに進みます。




【5】インストール

インストールします。

./install


インストールログを残したい場合は、

./install &> compile.out


コンパイル中、「警告」の文字がたくさん出てきますが、エラーでは無いので無視してください。

コンパイラによっては出ないかもしれません。




【6】パスの設定

各実行ファイルへのパスを張ります。

xgraphaptでインストールしてるので、普通に使えます。

他のパスは以下を参考にしてください。

一応インストールの最後に

(1) You MUST put /home/k/ns-allinone-2.34/otcl-1.13, /home/k/ns-allinone-2.34/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/k/ns-allinone-2.34/tcl8.4.18/library into your TCL_LIBRARY environmental
variable. Otherwise ns/nam will complain during startup.


↑こんなメッセージが表示されるはずなので(これは僕の環境での出力ですが)、これを参考にして記述していけばいいです。


まず一旦ホームディレクトリに戻りましょう。

cd


PATHは.bashrcに書き込みます(cshの場合は多分.tcshrc)。

gedit .bashrc


ファイルの一番最後に追記します。


# PATH for NS-2

# VERSION
NS_VER=2.34
OTCL_VER=1.13
TCL_VER=8.4.18

# Parent directory path
NS_PAR=/usr/local
# NS home directory path
NS_HOME=$NS_PAR/ns-allinone-$NS_VER

# LD_LIBRARY_PATH
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$NS_HOME/otcl-$OTCL_VER:$NS_HOME/lib

# TCL_LIBRARY
export TCL_LIBRARY=$NS_HOME/tcl$TCL_VER/library

# PATH
PATH=$PATH:$NS_HOME/bin



バージョンはns-allinone-2.34のものなので、それ以前のバージョンを使う場合はそれぞれ書き直してください。

保存したら端末で、

source .bashrc


を実行すると変更が反映されます。


端末で

ns


と入力してプロンプト「%」が表示されることを確認します。

nam


と入力して「NAM - The Network Animator」が起動するか確認します。



0 件のコメント:

人気の投稿