柯老师的mudp.cc在NS2.35上的移植问题解决方案

9 篇文章 0 订阅

最近移植柯老师的示例代码measure/mudp 相关的代码,发现了问题,但是网上也没找到解决方法,很多人有相同问题但是没有最后解决。

1、在Makefile中不加 -fpermissive, 会报错误,说mUdpAgent 不能直接调用UdpAgent(),

  在makefile中加入

  1. CCOPT    -Wall -Wno-write-strings -fpermissive  
   编译能通过,但是运行的时候会出现
  1. invalid command name "Agent/TCPSink/mTCPSink"  
  2. while executing  
  3. "Agent/TCPSink/mTCPSink   creat -o83"  

   因此也是不能通过的。



2、具体解决方案:

在源代码中

  1. mUdpAgent::mUdpAgent() id_(0), openfile(0)  
  2.  
  3.         bind("packetSize_", &size_);  
  4.        UdpAgent::UdpAgent();  
  5.  
UdpAgent::UdpAgent()调用是有问题的,改为:
  1. mUdpAgent::mUdpAgent() :UdpAgent(), id_(0), openfile(0)  
  2.  
  3.         bind("packetSize_", &size_);  
  4.  
重新编译后,运行通过,不会出现1中的问题。


添加mUDP.mUDPSink  

mUDP是UDP的延伸,除了具有UDP的功能外,还能记录所发送的包的信息。mUdpSink可以把接收到的包的信息记录到文件中。

这篇文章是基于柯老师的making NS-2 simulate an 802.11b link

希望能对大家有所帮助:

在阅读柯老师的仿真代码前,请先阅读一下

http://www.ece.rice.edu/~jpr/ns/docs/ns-802_11b.html

这篇文章是对实际效果和仿真效果进行比较,修改一些仿真参数,以达到更接近实际的效果。

http://140.116.72.80/~smallko/ns2/tool_en.htm

而这篇文章是在仿真前要着手进行的准备工作,下面我会具体介绍一下文章中的内容。(其实也就是翻译整理一下了)

准备工作的基本思想是插入两个参数“sendtime_”和“pkt_id_”到“hdr_cmn” header代码里面去。当分组被发送,分组id和发送时间被记录到发送端的trace文件中。而当分组被目的端接受,分组id和接收时间被记录到接收端的trace文件中。所以作者预备了两个agent,mudp和mudpsink去完成这项工作,mudp是udp agent的扩展,它只是越过发送消息功能,将分组id和发送时间下载到用户指定的文件中。

以下是具体的实现过程:

 

1.      Downloadmudp.cc,mudp.h,mudpsink.cc, andmudpsink.h(我这不带链接)

2.      Create a folder named measure under ns. (for example, ~/ns-allinone-2.28/ns-2.28/measure)(就放在这个路径吧,其他我没有试过)

3.      Put these four files into measure folder.

4.      add sendtime_, pkt_id_ into packet common header. (modify common/packet.h)

struct hdr_cmn {

        enum dir_t { DOWN= -1, NONE= 0, UP= 1 };

        packet_t ptype_;      // packet type (see above)

        int     size_;                // simulated packet size

        int     uid_;         // unique id

        int     error_;              // error flag

        int     errbitcnt_;     // # of corrupted bits jahn

        int     fecsize_;

        double      ts_;           // timestamp: for q-delay measurement

        int     iface_;              // receiving interface (label)

        dir_t direction_;        // direction: 0=none, 1=up, -1=down

       double  sendtime_;          ...

        unsigned long int pkt_id_;(添加得)

        ...

        inline int& addr_type() { return (addr_type_); }

        inline int& num_forwards() { return (num_forwards_); }

        inline int& opt_num_forwards() { return (opt_num_forwards_); }

        //monarch_end

       inline double& sendtime() { return (sendtime_); } // added by smallko(添加得)

   }

 

5.      Add the “measure/mudp.o measure/mudpsink.o “ in the OBJ_CC of Makefile.(路径:ns-allinone-2.2x/ns-2.2x,不是ns~/ns-allinone-2.2x/nam-1.1x/)

 

具体加入位置如下:找到OBJ_CC

OBJ_CC = \

measure/mudp.o measure/mudpsink.o  \
netview.o netmodel.o edge.o packet.o node.o main.o \
trace.o queue.o drop.o animation.o agent.o feature.o \
route.o transform.o paint.o state.o monitor.o anetmodel.o \
random.o rng.o view.o graphview.o netgraph.o tracehook.o\
lan.o psview.o group.o editview.o tag.o address.o animator.o \
wnetmodel.o nam_stream.o enetmodel.o testview.o parser.o \
trafficsource.o lossmodel.o queuehandle.o \

 

6.      Add “Agent/mUDP set packetSize_ 1000” in the ns-default.tcl. (ns-default.tcl is under ~/ns-allinone-2.28/ns-2.28/tcl/lib)

具体插入位置如下:

########################################################

# Debojyoti added this
Agent/mUDP set packetSize_ 1000
Simulator set useasim_ 1
Asim set debug_ false

注:插入位置不是固定的,只是我插入在这里而已:D

7.      make clean ; make(要在路径ns-allinone-2.2x/ns-2.2x下)

尤其注意步骤5和7。

http://140.116.72.80/~smallko/ns2/80211b.htm中的test代码拷入你的ns2种的test.tcl文件,然后在命令行输入ns test.tcl 3000 144
呵呵,是否成功运行了呢?以后的分析工作,我就不具体介绍了,大家自己研究一下吧,在此申明,我的仿真平台是winxp sp2+cygwin+ns2-2.27,是可以成功运行这个test.tcl例子的,其他平台我不敢保证,但希望大家都能成功运行仿真。

我也是ns2的初学者,希望大家能够共同学习,共同进步。

摘自http://hi.baidu.com/savin2009/blog/item/2f8eee3ffab07a3571cf6c39.html

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值