在Win2003下基于Cygwin环境的LEACH安装

来源:互联网 发布:linux系统ftp命令用法 编辑:程序博客网 时间:2024/05/18 01:11

此篇文章是实验室师兄杨师兄的作品,可以给初学习NS2仿真的同学学习。 他的博客是:blog.csdn.net/delphiwcdj

在Win2003下基于Cygwin环境的LEACH安装

Step 0: 准备必要的安装文件
1. Cygwin (70M)
下载地址:
http://140.116.72.80/~smallko/ns2/cygwin.rar
2. NS-2.27 package (55M): ns-allinone-2.27.tar.gz
下载地址:
http://www.internetworkflow.com/downloads/ns2leach/ns-allinone-2.27.tar.gz
3. MIT's LEACH extension: mit.tar.gz
下载地址:
http://www.internetworkflow.com/downloads/ns2leach/mit.tar.gz
4. LEACH's Makefile
下载地址:
http://www.internetworkflow.com/downloads/ns2leach/Makefile
5. vim7.3: gvim73_46.exe
下载地址:
http://www.vim.org/download.php
6. ns227-gcc34.patch (可选)
下载地址:
http://www.baisi.net/attachpage.php?tid=2470660&aid=1706851
7. NS-2.27环境下配置好的.bashrc文件 (可选)
下载地址:
http://140.116.72.80/~smallko/ns2/.bashrc
8. Index of /nsnam/dist/binary,nam-1.0a11a-win32.exe (可选)
下载地址:
http://www.isi.edu/nsnam/dist/binary/

Step 1: 安装Cygwin环境和NS-2.27包
(1) Cygwin通过本地的离线包安装,为了减少出现错误,选择全部all安装。
(2) 将ns-allinone-2.27.tar.gz复制到~目录下(即自己的家目录下),通过下面命令安装:
[1] cd ~
[2] tar zxvf ns-allinone-2.27.tar.gz
[3] patch -p0<ns227-gcc34.patch (可选)
[4] cd ns-allinone-2.27
[5] ./install
PS: 详细内容可参考关于安装问题的link[1]
Step 2: 设置环境变量使NS-2.27在终端下可用
[1] cd ~
[2] vim .bashrc
# LD_LIBRARY_PATH
OTCL_LIB=~/ns-allinone-2.27/otcl-1.8
NS2_LIB=~/ns-allinone-2.27/lib
X11_LIB=/usr/X11R6/lib
USR_LOCAL_LIB=/usr/local/lib
export
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$OTCL_LIB:$NS2_LIB:$X11_LIB:$USR_LOCAL_LIB
# TCL_LIBRARY
1/5
如有未提及的,或相关问题,欢迎一起讨论:) blog.csdn.net/delphiwcdj 2010-11-23
TCL_LIB=~/ns-allinone-2.27/tcl8.4.5/library
USR_LIB=/usr/lib
export TCL_LIBRARY=$TCL_LIB:$USR_LIB
# PATH
PATH=$PATH:~/ns-allinone-2.27/bin:~/ns-allinone-2.27/tcl8.4.5/unix:~/ns-allinone-
2.27/tk8.4.5/unix
[3] . .bashrc # or use source .bashrc
PS: 详细可参考Step 0, 6, NS-2.27环境下配置好的.bashrc文件

Step 3: 添加MIT的LEACH extension
把mit.tar.gz复制到~/ns-allinone-2.27/ns-2.27/目录下。
[1] cd ~/ns-allinone-2.27/ns-2.27/
[2] tar zxvf mit.tar.gz
[3] rm mit.tar.gz
PS: 建议先将~/ns-allinone-2.27/ns-2.27目录复制一份,目的是便于对比在添加完LEACH extension后有
哪些文件被覆盖。

Step 4: 修改NS-2.27的源代码
(1) 修改~/ns-allinone-2.27/ns-2.27/mac/wireless-phy.cc文件:
vim ~/ns-allinone-2.27/ns-2.27/mac/wireless-phy.cc
Goto line 59, that is after line 58:
#define max(a,b) (((a)<(b))?(b):(a))
Insert:
#define min(a,b) (((a)>(b))?(b):(a))
(2) 修改~/ns-allinone-2.27/ns-2.27/indep-utils/webtrace-conv/dec/my-endian.h文件:
#ifndef _ENDIAN_H_
#define _ENDIAN_H_
改为
#ifndef _MY_ENDIAN_H_
#define _MY_ENDIAN_H_
或者将该文件的第一行和最后一行注释掉即可。
(3) 修改~/ns-allinone-2.27/ns-2.27/indep-utils/cmu-scen-gen/setdest/Makefile文件 :
change this line:
DEFINE = -Dstand_alone
-DSTL_NAMESPACE=@STL_NAMESPACE@
to this line:
DEFINE = -Dstand_alone
-DSTL_NAMESPACE=@STL_NAMESPACE@ -DCPP_NAMESPACE=std
In the other makefiles, append -DCPP_NAMESPACE=std to CFLAGS. (可以根据error的提示的目录修
改)
(4) 修改~/ns-allinone-2.27/ns-2.27/test文件:
否者在测试运行./test时,会出现:./test: line 5: ./leach_test: No such file or directly 的错误。
#!/bin/bash
cd tcl/ex
ns wireless-demo-csci694.tcl
sleep 2
# 改变下面两行代码的顺序
2/5
如有未提及的,或相关问题,欢迎一起讨论:) blog.csdn.net/delphiwcdj 2010-11-23
cd ../../
./leach_test
(5) 修改~/ns-allinone-2.27/ns-2.27/tcl/lib/ns_default.tcl文件,否者在./test的时候后会出现一堆
warnings,在第692行加入7个初始值如下:
Phy/WirelessPhy set alive_ 1
Phy/WirelessPhy set Efriss_amp_ 100e-12 # wireless-phy.cc文件中为:100 * 1e-12,修改
为:100e-12,否者会出现浮点数例外
Phy/WirelessPhy set Etwo_ray_amp_ 0.0131e-12 # 同上
Phy/WirelessPhy set EXcvr_ 50e-9 # 同上
Phy/WirelessPhy set sleep_ 0
Phy/WirelessPhy set ss_ 1
Phy/WirelessPhy set dist_ 0
具体的初始值应该对照在:~/ns-allinone-2.27/ns-2.27/mac/wireless-phy.cc输入(第95行,第97-99
行,第104-105行,第107行)
PS: 修改相关文件的目的是,为了减少在make时出现错误的可能性。详细内容可参考关于安装问题的link[2]:
LEACH protocol installation on NS2.27

Step 5: 给LEACH extension添加环境变量
[1] vim ~/.bashrc
# LEACH
export RCA_LIBRARY=`pwd`/ns-allinone-2.27/ns-2.27/mit/rca
export uAMPS_LIBRARY=`pwd`/ns-allinone-2.27/ns-2.27/mit/uAMPS
[2] . .bashrc # or use source .bashrc

Step 6: 修改Makefile文件内容,用LEACH extention重新编译NS-2.27
修改~/ns-allinone-2.27/ns-2.27/Makefile文件,复制一个新文件,不修改原文件。
PS: 在vim中使用查找命令:/word向下查找;?word向上查找。
[1] mv ~/ns-allinone-2.27/ns-2.27/Makefile ~/ns-allinone-2.27/ns-2.27/Makefile_Modified
[2] vim ~/ns-allinone-2.27/ns-2.27/Makefile_Modified
<1> Add -DMIT_uAMPS to the DEFINE list
<2> Add -I./mit/rca -I./mit/uAMPS to the INCLUDE list
<3> Add the following just prior to the line gaf/gaf.o \
mit/rca/energy.o mit/rca/rcagent.o \
mit/rca/rca-ll.o mit/rca/resource.o \
mac/mac-sensor-timers.o mac/mac-sensor.o mit/uAMPS/bsagent.o \
<4> make clean
<5> make -f Makefile_Modified
或者使用后台编译命令:nohup make -f Makefile_Modified 2>make.error >make.log &
PS: 关于nohup、2>make.error和&命令的用法可以参考关于安装问题的link[3-4]
在make完成后,查看make.error文件,会发现出现一堆irritating warnings信息(不用管它),但是没有
errors信息说明编译通过:
common/ip.cc: In member function `virtual void IPHeaderClass::export_offsets()
':
common/ip.cc:53: warning: invalid access to non-static data member `
3/5
如有未提及的,或相关问题,欢迎一起讨论:) blog.csdn.net/delphiwcdj 2010-11-23
hdr_ip::src_' of NULL object
common/ip.cc:53: warning: (perhaps the `offsetof' macro was used incorrectily)
common/ip.cc:54: warning: invalid access to non-static data member `
hdr_ip::dst_' of NULL object
common/ip.cc:54: warning: (perhaps the `offsetof' macro was used incorrectly)
common/ip.cc:55: warning: invalid access to non-static data member `
hdr_ip::ttl_' of NULL object
common/ip.cc:55: warning: (perhaps the `offsetof' macro was used incorrectly)
common/ip.cc:56: warning: invalid access to non-static data member `
hdr_ip::fid_' of NULL object
common/ip.cc:56: warning: (perhaps the `offsetof' macro was used incorrectly)

Step 7: 测试
Test default wireless demo and LEACH:
[1] cd ~/ns-allinone-2.27/ns-2.27/
[2] ./test
结果显示如下图:


[3] Validate the full installation — this takes a while too so take a break (可选)
nohup ./validate-full 2>validate.error >validate.log &
[4] 查看一下~/ns-allinone-2.27/ns-2.27/mit/leach_sims/leach.err文件的内容,如果为下面的内容,则
安装成功。
# leach.err
INITIALIZE THE LIST xListHead
channel.cc:sendUp - Calc highestAntennaZ_ and distCST_
highestAntennaZ_ = 1.5, distCST_ = 222.8
SORTING LISTS ...DONE!


【关于安装问题的link参考】
[1] Windows + Cygwin + NS2 (好,先把这个安装成功才能进行下面的工作)
http://140.116.72.80/~smallko/ns2/setup_en.htm (英文)
http://140.116.72.80/~smallko/ns2/setup.htm (中文)
[2] LEACH protocol installation on NS2.27 (好,仔细阅读,很多问题可以在这个link中解决)
http://www.linuxquestions.org/questions/linux-general-1/leach-protocol-installation-on-ns2-27-
a-785379/
[3] nohup、&、disdown、screen的用法
4/5
如有未提及的,或相关问题,欢迎一起讨论:) blog.csdn.net/delphiwcdj 2010-11-23
http://blog.csdn.net/sayigood/archive/2010/10/03/5919483.aspx
[4] "2>&1" 是什么意思?
http://hi.baidu.com/cui1206/blog/item/85e74c084ddf473ce82488d8.html
[5] ns2 2.27 ubuntu (一个韩国人的博客)
http://cypress.tistory.com/entry/ns2-227-ubuntu
[6] Leach协议学习——NS2.27+leach协议安装 (介绍了几种错误)
http://hi.baidu.com/jerry_916/blog/item/ab630c32391f944aac4b5f3e.html
[7] Cygwin+ns2.27+leach协议 安装笔记
http://www.baisi.net/viewthread.php?tid=3009793
[8] windows下 cygwin+ns2.27+leach安装与总结
http://blog.sina.com.cn/s/blog_3c680f8101008rty.html
[9] leach在ns2.28,2.29上的安装
http://hi.baidu.com/zhubanty/blog/item/6366d6ddf3215c305982ddd4.html
[10] leach在ns2各版本下安装的问题
http://hi.baidu.com/savin2009/blog/item/9090da37ef21e8d5a2cc2b56.html
[11] Cygwin+ns2.27+leach安装问题与解决方法
http://hi.baidu.com/savin2009/blog/item/7b8f6cfbf71a38d6b48f318b.html
[12] The Network Simulator ns-2: Installation Problems, Bug Fixes, and Help
http://www.isi.edu/nsnam/ns/ns-problems.html#ns-2.27
http://nsnam.isi.edu/nsnam/index.php/Troubleshooting

【进一步阅读的link参考】
[1] NS2 Leach Implementation (PDF Only 25 KB)
http://www.internetworkflow.com/resources/index.shtml
[2] MIT uAMPS LEACH ns Extensions
http://www.ece.rochester.edu/research/wcng/code/index.htm
[3] Threads Tagged(标签) with leach
http://www.linuxquestions.org/questions/tags/leach/
[4] 一个关于WSN研究的外国教授的网站
http://www.ece.rochester.edu/~wheinzel/index.html
[5] NS-2 Trace Formats
http://nsnam.isi.edu/nsnam/index.php/NS-2_Trace_Formats
[6] 一个国内博士关于的WSN博客 (好)
http://hi.baidu.com/vvfang/blog/category/Ns2%20Related
[7] 一个上交博士关于NS2学习笔记的博客 (好)
http://hi.baidu.com/jerry_916/home
http://hi.baidu.com/jerry_916/blog/category/Ns2
[8] 一个关于NS与网络模拟的博客
http://blog.sina.com.cn/s/articlelist_1013452673_9_1.html

原创粉丝点击