调试运行ns2 lab22.tcl中遇到的问题
需要用到threshold来计算不同的无线传输模型的传输矩离,但使用gcc编译过程中出错。 首先进入ns文件夹下的indep-utils/propagation,我的路径是/home/onwaier/ns-allinone-2.35_gcc482/ns-allinone-2.35/ns-2.35/indep-utils/propagation 编辑命令为g++ -lm threshold.cc -o threshold
错误1 报错”threshold.cc:56:22: fatal error: iostream.h: 没有那个文件或目录”
找到#include<iostream.h>这一行,把#include<iostream.h>修改为#include<iostream>,并添加命令空间std,代码为using namespace std; 编译再次出现新的错误
错误2 报错”threshold.cc:211:30: error: ‘strcmp’ was not declared in this scope”
strcmp函数是关于字符串的操作,头文件为#include<string.h>,而文件中并未包含,加入#include<string.h>一行。 再次编译,没有报错,编译成功。 以Two Ray Ground,希望有效的传输距离为250m为例。 输入命令./threshold -m TwoRayGround 250 运行结果如图所示。
执行命令ns test_2nodes.tcl出错,
错误3 报错”invalid command name “Agent/mUDP””
查询发现mUDP,mUdpSink,mTcpsink是NS2中没有的,是后来人写的。所以要使用此功能必须自行加入。下载mUDP, mUdpSink的文件,要下载的有下列几个文件 mudp.cc、mudp.h、mudpsink.cc、mudpsink.h。下载地址为:百度网盘,提取码为65j6。个人网盘。 具体如何添加参照博客1和博客2 下面以我的路径(ns在/home/onwaier)来说明配置过程 1. 在/home/onwaier/ns-allinone-2.35_gcc482/ns-allinone-2.35/ns-2.35目录下新建文件夹,添加刚才下载的文件mtcpsink.cc、mtcpsink.h、mudp.cc、mudp.h、mudpsink.cc、mudpsink.h。 2. 修改/home/onwaier/ns-allinone-2.35_gcc482/ns-allinone-2.35/ns-2.35/common/packet.h,在struct hdr_cmn{}中添加以下代码
1 | int frametype_; //added by smallko |
- 修改
/home/onwaier/ns-allinone-2.35_gcc482/ns-allinone-2.35/ns-2.35/Makefile,找到OBJ_CC这一行, 在其下行添加代码measure/mtcpsink.o measure/mudp.o measure/mudpsink.o \。注意Makefile对于语法要求很高,不能有空行或多余的空格。 - 修改
/home/onwaier/ns-allinone-2.35_gcc482/ns-allinone-2.35/ns-2.35/tcl/lib/ns-default.tcl,找到Delayer set debug_ false这一行,在其下一行添加Agent/mUDP set packetSize_ 1000。 - 执行命令
./configure --with-tcl-ver=8.5;make clean;make出现新的错误。
错误4 报错”cannot call constructor mUdpAgent::UdpAgent’ directly [-fpermissive]“
- 在makefile中加入以下
CCOPT = -Wall -Wno-write-strings -fpermissive - 修改
measure/mudp.cc将代码
1 | mUdpAgent::mUdpAgent() : id_(0), openfile(0) |
改为
1 | mUdpAgent::mUdpAgent() :UdpAgent(), id_(0), openfile(0) |
重新编译,运行通过。 但仍有上述问题invalid command name "Agent/mUDP" 尝试进入目录/home/onwaier/ns-allinone-2.35_gcc482/ns-allinone-2.35,执行./install,然后进入目录/home/onwaier/ns-allinone-2.35_gcc482/ns-allinone-2.35/ns-2.35执行sudo make install。 再次执行命令ns test_2nodes.tcl,运行结果为: 