最近正在研究怎样把自己新写的协议添加到NS2中去,正好借鉴了一些朋友的文章,现在整理下来,以便以后参考,也希望能给广大博友一些方便。step1:比如我们新建的协议名字就叫做protoname,,。,,,,五个文件。其中五个文件的具体功能和作用如下:(1)(2)执行计时器、路由代理和Tcl文件(3)(4)(5)执行路由选择表step2:相应文件的代码(1)#ifndef__protoname_h__#define__protoname_h__//下面包含一些需要的头文件#include""//数据包报头#include""#include<> //代理基本类#include<>//数据包类#include<>//跟踪类,用于在跟踪文件里记录输出的仿真结果#include<timer->//计时器基本类,创建我们自定义的计时器#include<>//随机类,用于产生伪随机数#include<classifier->//端口分类器类,用于淘汰向上层传输的数据包#include<>#include""#include""#include""#include""#include""#defineCURRENT_TIMEScheduler::instance().clock()//定义了一个用于得到当前仿真时间的宏 //通过一个调度类的实例完成#defineJITTER(Random::uniform()*)//在0-;//forwarddeclaration/*Timers*/ //自定义计时器发送定时的控制包classProtoname_PktTimer:publicTimerHandler{ public: Protoname_PktTimer(Protoname*agent):TimerHandler(){ agent_=agent; } protected: Protoname*agent_; virtualvoidexpire(Event*e);};/*Agent*///定义Protoname类classProtoname:publicAgent{/*Friends*/friendclassProtoname_PktTimer;/*Privatemembers*///封装了自身的地址、内状态、路由表、可变的Tcl //以及一个负责指定输出数量的计数器nsaddr_tra_addr_;//protoname_statestate_;protoname_rtablertable_;esible_var_;//用来读取Tcl代码或脚本语言u_int8_tseq_num_;protected:MobileNode*node_;PortClassifier*dmux_;//*logtarget_;//;////内部属性inlinensaddr_t&ra_addr(){returnra_addr_;}//inlineprotoname_state&state(){returnstate_;}inlineint&accessible_var(){esible_var_;}voidforward_data(Packet*);//数据包被正确传输的目的地voidrecv_protoname_pkt(Packet*);voidsend_protoname_pkt();voidreset_protoname_pkt_timer();public:Protoname(nsad
百思论坛整理ns下开发新协议 来自淘豆网m.daumloan.com转载请标明出处.