转自http://nslab.ee.ntu.edu.tw/courses/ns-tutorial/labs/lab1.html
Lab 1: Installing ns-2
1.a. Getting the pieces
- To have ns-2 running, you need these 3 pieces at minimum:
- otcl
- tclcl (a.k.a. Tcl)
- ns-2
To visualize simulations, you need: - nam-1
If your NFS doesn't support tcl/tk8.4.14 (or there're multiple tcl/tk installations that confuse configuration scripts), you need: - tcl8.4.14
- tk8.4.14
1.b. Using existing tcl/tk distribution
If tcl/tk 8.4.14 are already installed in your system, you can re-use them to install otcl, tclcl, ns-2, and nam by taking the following sub-steps.
1. Make sure you know where these tcl/tk header and library files are. Usually,
- tclsh8.14 in /usr/local/bin (or /usr/bin)
- libtcl8.4.a in /usr/local/lib (or /usr/lib)
- init.tcl in /usr/local/lib/tcl8.4 (or /usr/lib/tcl8.4)
- tcl*.h in /usr/local/include (or /usr/include) [Similarly, for tk stuff]
If you cannot locate a coherent copy for tcl/tk 8.4.14, skip 2 and 3 and go directly to I.b.alt. It is probably easier to install tcl/tk in your home directory.
2. Set environment Variables
- setenv TCL_LIBRARY /usr/local/lib/tcl8.4 (or /usr/lib/tcl8.4)
- setenv TK_LIBRARY /usr/local/lib/tk8.4 (or /usr/lib/tk8.4)
3. Set options when 'configuring' otcl, tclcl, and ns-2 in step I.c. below
- --with-tcl=/usr/local --with-tcl-ver=8.4 --with-tk=/usr/local --with-tk-ver=8.4
- (or --with-tcl=/usr --with-tcl-ver=8.4 --with-tk=/usr --with-tk-ver=8.4)
4. Skip I.b.alt. But if you have trouble completing 'configure' in step I.c., follow the instruction in I.b.alt. to install tcl/tk 8.4.14.
1.b.alt. Installing tcl and tk
1. Configure and install tcl/tk
-
tcl8.4.14
-
cd tcl8.4.14/unix
./configure --disable-load
make
-
cd tk8.4.14/unix
./configure --disable-load --with-tcl=../../tcl8.4.14/unix
make
-
cd tcl8.4.14/unix
2. Important files
- tclsh in {your tcl8.4.14 path}/unix
- libtcl8.4.a in {your tcl8.4.14 path}/unix
- init.tcl in {your tcl8.4.14 path}/library
- tcl*.h in in {your tcl8.4.14 path}/generic [Similarly, for tk stuff]
3. Environment Variables
- setenv TCL_LIBRARY {your tcl8.4.14 path}/library
- setenv TK_LIBRARY {your tk8.4.14 path}/library
4. Options to set when 'configuring' otcl, tclcl, and ns-2
- --with-tcl={your tcl8.4.14 path} --with-tcl-ver=8.4.14 \ --with-tk={your tk8.4.14 path} --with-tk-ver=8.4.14
1.c. Installing/Re-installing the otcl, tclcl, ns-2, and nam
For each of these packages, you need to run the 'configure' script which in turn creates a 'Makefile' with (supposedly) correct BIN, INCLUDE, and LIB paths and filenames.
Occasionally, your configure script may pass, but it locates incoherent combination of BIN, INCLUDE, and LIB paths and files. In this case, 'make' will fail and you will need to manually edit the Makefile so when compiling the compiler will find the right path/file to look/link.
-
otcl
-
./configure --with-tcl={your tcl8.4.14 path} --with-tcl-ver=8.4.14 --with-tk={your tk8.4.14 path} --with-tk-ver=8.4.14
make
-
./configure --with-tcl={your tcl8.4.14 path} --with-tcl-ver=8.4.14 --with-tk={your tk8.4.14 path} --with-tk-ver=8.4.14 --with-otcl={your otcl path}
make
-
./configure --with-tcl={your tcl8.4.14 path} --with-tcl-ver=8.4.14 --with-tk={your tk8.4.14 path} --with-tk-ver=8.4.14 --with-otcl={your otcl path} --with-tclcl={your tclcl or Tcl path}
make
-
./configure --with-tcl={your tcl8.4.14 path} --with-tcl-ver=8.4.14 --with-tk={your tk8.4.14 path} --with-tk-ver=8.4.14 --with-otcl={your otcl path} --with-tclcl={your tclcl or Tcl path}
make
-
./configure --with-tcl={your tcl8.4.14 path} --with-tcl-ver=8.4.14 --with-tk={your tk8.4.14 path} --with-tk-ver=8.4.14
1.d. Quickly checking whether successfully installed ns-2 and nam
-
ns-2
-
cd {your ns-2 path}/tcl/ex/
../../ns simple.tcl
-
cd {your nam path}/ex
gunzip test.nam.gz
../nam lan.nam
-
cd {your ns-2 path}/tcl/ex/
References:
- The main VINT/ns page
- The ns download page
- The ns installation problems page