How to Compile Ns2 on Windows Platform

The following is an installation guide for Ns2 from its source code on Windows platform (95/98/2000) for ns versions up to 2.1b9. Later versions of ns work under Windows using Cygwin. If you would like to provide updated information for ns after 2.1b9, please send it to the ns mailing list.

Before installing Ns2 it is important to note that pre-compiled versions already exists. A precompiled version of the latest release (ns-2.1b8a-win32.exe) exists for win2000. This serves as an excellent trial tool for anyone getting started with Ns2. For those who plan on implementing an extension for Ns2 you will have to compile it from its source distribution. You can use WinZip to untar the files. This guide is designed to clarify this.

What is required

Setting the environment variables

Before compiling Ns2 the proper functionality of certain VC++ command-line tools such as CL.EXE and LINK.EXE must be assured. These tools require that the environment variables be set properly. The batch file VCVARS32.BAT is used to set these variables.

Source Code Organization

Organize the source code for Ns2 in the following directories:

Modifying Makefiles

Makefiles contain the instructions necessary to build a project with Nmake. The instructions include paths indicating the location of source code and VC++ libraries. To install Ns2 successfully you will need to modify the makefiles for Ns2 and its components. To assist you in this task I have added functional makefiles which represent a typical system configuration. You can modify these makefiles and copy them into the proper directories or use them as examples for changing existing makefiles. If you choose to modify these makefiles simply modify the lines specified in each makefile.

Note: for tclcl and ns2 is found in the respective directories for each ..\conf, while resides in their base directory. otcl only has but not Here are some sample makefiles.

Using Nmake to compile Ns2

Nmake is the command line C++ compiler that is provided with Visual C++. The argument that Nmake receives is a makefile. Nmake is run from an MS-DOS Prompt. Cd into the directory containing the source code. Type the following: <nmake_dir>\nmake /f . Since this command will have to be used for every component of Ns2 create a few batch files. The following would be the contents of a typical batch file for running nmake:
cd D:\NetSim\ns-2.1b6-current

c:\progra~1\micros~3\vc98\bin\nmake /f

Batch files are saved with the extension .bat.

Notes on installation

Compile each component of Ns in the order given at the top of the page.

Compiling TCL is done in two steps. For the first step use nmake /f After this use nmake /f install. The install option will create directories for binary, include and library files.

The file mkd.bat in TCl8.3.2\win and TK8.3.2\win needs to be modified. Every instance of "md" should be changed to "mkdir". This is because the DOS command to make a directory is "mkdir" and not "md"


Now that ns2 and its components have been installed they must be validated to ensure their proper functionality. Two tools are needed to run the validation under Windows 95/98/2000/NT. The first tool is named Cygwin and the second is named Perl.

What is Cygwin?

The Cygwin tools are ports of the popular GNU development tools for Windows NT, 95, 98 & 2000. They run thanks to the Cygwin library which provides the UNIX system calls and environment these programs expect.

Dowloading Cygwin

Go to Cygwin web page for downloading Cygwin. This page gives the most recent version of Cygwin.
Note: With Cygwin-1.3.2 we have been unable to make awk work. And since ns' validation scripts makes use of awk, the ns-2.1b8a-win version has not been validated under windows.

What is Perl?

Short for Practical Extraction and Report Language, Perl is a programming language developed by Larry Wall, especially for processing text. Because of its strong text processing abilities, Perl has become one of the most popular languages for writing CGI scripts and other Internet applications. Perl is an interpretive language which makes it easy to build and test simple programs. However, Perl is also robust enough to allow for the creation of complex programs. Because Perl is extremely useful in "gluing" together smaller programs into larger applications, it has often been referred to as "the duct tape of the Internet."

Dowloading Perl

Running the validation

Important Note: The paragraph below describes validation that was run on win95 for ns-2.1b6 version using cygwin-1.1.2. However the cygwin release 1.3.2 currently available (as of 07/2001), which we installed in win2000, doesn't seem to have a functional awk utility. A significant portion of the ns validation script uses awk, so we tried to replace awk with perl; but now the bash shell (another cygwin utility) didnot handle stdin/stdout correctly. So we were unable to validate the windows version (ns2.1b8a) in this platform. We welcome any suggestion from windows users to help solve this problem.

To run the validation on win95 a patch must be applied to test-all-template1 which resides in ~ns/tcl/test/. Download and run the patch.exe program included in Cygwin. A description of the syntax for "patch" is available by typing patch --help. If you prefer having it in a text file, --> --type

	patch --help > out.txt

The following patch to ~ns/tcl/test/test-all-template1 is required to get around the \r\n problem:
+++      Fri Jul  2 14:33:25 1999
@@ -116,14 +116,16 @@
            cp $datafile.bk $datafile
            mv $datafile.Z $directory/$t.Z
-           uncompress -c $directory/$t.Z | cmp -s - $datafile
+#          uncompress -c $directory/$t.Z | cmp -s - $datafile
+           gzip -dc $directory/$t.Z | perl -ne 'print $_;' | cmp -s - $datafile 
            if [ $? = 0 ]; then
                echo Test output agrees with reference output
                echo Test output differs from reference output
                cp $datafile $directory/$t.test
-               uncompress -c $directory/$t.Z > $directory/$t
+#              uncompress -c $directory/$t.Z > $directory/$t
+               gzip -dc $directory/$t.Z > $directory/$t
                echo "Diagnose with: diff $directory/$t.test $directory/$t"
                echo "Differences due to floating-point formatting are not significant."
Some of the test suites will fail on win32 platform. As of Feburary 26, 1999 snapshot of ns, the following test suites fail:
 ./test-all-simple ./test-all-tcp ./test-all-red ./test-all-sack
 ./test-all-schedule ./test-all-red-v1 ./test-all-sack-v1 ./test-all-v1
 ./test-all-vegas-v1 ./test-all-ecn ./test-all-manual-routing
 ./test-all-intserv ./test-all-webcache ./test-all-srm
However, the above test suites failed because of floating point rounding differences on win32 and on unix, or because of incompatibilities of the unix awk program and its cygwin variation. We will test current ns snapshots and update the results here. Thanks to Christian Joensson for providing these information.
You are now ready to run the validation. Cd to <ns_dir> and type ./validate. Once again you can redirect the output to a text file by using ./validate > out.txt.