调试运行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.ccmtcpsink.hmudp.ccmudp.hmudpsink.ccmudpsink.h
  2. 修改/home/onwaier/ns-allinone-2.35_gcc482/ns-allinone-2.35/ns-2.35/common/packet.h,在struct hdr_cmn{}中添加以下代码
int frametype_; //added by smallko
double  sendtime_;  // added by smallko
unsigned int pkt_id_; // added by smallko
unsigned int frame_pkt_id_; //added by smallko
  1. 修改/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对于语法要求很高,不能有空行或多余的空格。
  2. 修改/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
  3. 执行命令./configure --with-tcl-ver=8.5;make clean;make
    出现新的错误。

错误4 报错"cannot call constructor mUdpAgent::UdpAgent’ directly [-fpermissive]"

  1. 在makefile中加入以下CCOPT = -Wall -Wno-write-strings -fpermissive
  2. 修改measure/mudp.cc
    将代码
mUdpAgent::mUdpAgent() : id_(0), openfile(0)  
{  
        bind("packetSize_", &size_);  
       UdpAgent::UdpAgent();  
}  

改为

mUdpAgent::mUdpAgent() :UdpAgent(), id_(0), openfile(0)  
{  
        bind("packetSize_", &size_);  
}  

重新编译,运行通过。
但仍有上述问题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,运行结果为:
执行结果
如果运行过程出现环境变量错误,可以参考博客卸载ns, 然后再次尝试上述步骤。

发布了152 篇原创文章 · 获赞 29 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/happyeveryday62/article/details/103335567