cygwin+ns2.33安装过程遇到的问题及解决方法

1. cygwin安装组件的选择
为了简单,我直接选择的是完全安装,但实际上在之后ns2的安装上还是会存在找不到某些必须组件的问题。问题在于选择package的时候,点选了"Hide obsolete packages"的选项,而这些obsolete packages中的一些默认选项是not install,所以即使使用完全安装,也要show obsolete packages,从而确保"完全安装"。当然,也可以按照网上的方法只安装ns2必要的组件,但其中的一些也是位于obsolete packages中的。

2. bash.bashrc文件
按照网络上的说法,安装ns2之后需要把环境变量写入bash文件,而且据说在第一次运行cygwin后会自动在/home/usrname文件夹中生成针对此用户的bash文件。但是在我尝试了两次,并没有在/home/usrname中找到bash,原因未知。
解决方法1:copy系统默认的global bash文件到/home/usrname, 并命名为.bashrc, global bash在/etc/defaults/etc/bash.bashrc。这是网络上提供的方法,我没尝试过。
解决方法2:由于cygwin实际上是单用户的unix模拟环境,所以可以直接修改系统默认的global bash, 即位于/etc文件夹中的bash.bashrc,添加ns2相关路径到此bash文件即可。Attention:为了是修改后的bash文件有效,需要执行source bash.bashrc命令。

3. bash & bash script


Bourne Again shell

The UNIX shell program interprets user commands, which are either directly entered by the user, or which can be read from a file called the shell script or shell program. Shell scripts are interpreted, not compiled.

Apart from passing commands to the kernel, the main task of a shell is providing a user environment, which can be configured individually using shell resource configuration files.

bash or Bourne Again shell: the standard GNU shell, intuitive and flexible. On Linux, bash is the standard shell for common users. Bash offers functions including command line editing, unlimited size command history, job control, shell functions and aliases, indexed arrays of unlimited size, and integer arithmetic in any base from two to sixty-four.

Executing commands

Bash determines the type of program that is to be executed. Normal programs are system commands that exist in compiled form on your system. When such a program is executed, a new process is created because Bash makes an exact copy of itself. This child process has the same environment as its parent, only the process ID number is different. This procedure is called forking.

After the forking process, the address space of the child process is overwritten with the new process data. This is done through an exec call to the system.


The fork-and-exec mechanism thus switches an old command with a new, while the environment in which the new program is executed remains the same, including configuration of input and output devices, environment variables and priority. This mechanism is used to create all UNIX processes, so it also applies to the Linux operating system. Even the first process, init, with process ID 1, is forked during the boot procedure in the so-called bootstrapping procedure.

Shell script

Shell scripts consist of three kinds of commands - the shell functions, shell built-ins and existing commands in a directory on your system, which are arranged as shell syntax dictates. Scripts are read and executed line per line and should have a logical structure.

4. 针对ns2.33中nam的问题
安装ns2完成后,运行simple.tcl,nam执行时候会报错:
[code omitted because of length]
: no event type or button # or keysym
while executing
"bind Listbox {
%W yview scroll [expr {- (%D / 120) * 4}] units
}"
invoked from within
"if {[tk windowingsystem] eq "classic" [tk windowingsystem] eq "aqua"} {
bind Listbox {
%W yview scroll [expr {- (%D)}] units
}
bind Li..."


这个是ns2.33特有的一个问题,原因据说是tcl/tk和x11-proto/xproto-7.0.13不兼容,网络上给出两种解决方法:
1. 给tk-8.4.18-tkBind打上补丁,具体来说,到http://bugs.gentoo.org/show_bug.cgi?id=225999 下载 tk-8.4.18-tkBind.patch,放在ns-allinone-2.33目录下,之后运行命令

patch -p0 < tk-8.4.18-tkBind.patch

然后重新编译安装ns2.

2. 直接修改 ns-allinone-2.33/tk8.4.18/generic/tkBind.c 文件如下:

...

static int flagArray [TK_LASTEVENT] = {

...

/*MappingNotify*/ 0,

+#ifdef GenericEvent
+/*GenericEvent*/ 0,
+#endif

/*VirtualEvent*/ VIRTUAL,
...

之后重新编译安装ns2.

我使用了第二种方法,可以解决执行nam时报错的问题。