NS2添加协议步骤.docVIP

  • 6
  • 0
  • 约1.47万字
  • 约 15页
  • 2017-05-27 发布于河南
  • 举报
NS2添加协议步骤

NS2添加协议步骤 step 1:比如我们新建的协议名字就叫做protoname,以ns2.27平台为例,我们在ns2.27目录下建立一个protoname目录。此目录包含protoname.h,protoname.cc,protoname_pkt.h,protoname_rtable.h,protoname_rtable.cc五个文件。 其中五个文件的具体功能和作用如下: (1)protoname.h 定义必要的计时器和路由代理 (2)protoname.cc 执行计时器、路由代理和Tcl文件 (3)protoname_pkt.h 声明protoname路由协议需要在无线自组网节点交换的数据包 (4)protoname_rtable.h 声明我们自己的路由选择表 (5)protoname_rtable.cc 执行路由选择表 step 2:相应文件的代码 (1)protoname.h #ifndef __protoname_h__ #define __protoname_h__ // 下面包含一些需要的头文件 #include protoname_pkt.h //数据包报头 #include protoname_rtable.h #include agent.h??//代理基本类 #include packet.h //数据包类 #include trace.h //跟踪类,用于在跟踪文件里记录输出的仿真结果 #include timer-handler.h //计时器基本类,创建我们自定义的计时器 #include random.h //随机类,用于产生伪随机数 #include classifier-port.h //端口分类器类,用于淘汰向上层传输的数据包 #include mobilenode.h #include arp.h #include ll.h #include mac.h #include ip.h #include delay.h #define CURRENT_TIME Scheduler::instance().clock() //定义了一个用于得到当前仿真时间的宏 ??//通过一个调度类的实例完成 #define JITTER (Random::uniform()*0.5) //在0-0.5之间随机数作为发送数据的延迟时间 class Protoname; // forward declaration /* Timers */? ?//自定义计时器发送定时的控制包 class Protoname_PktTimer : public TimerHandler { ? ? public: ? ? Protoname_PktTimer(Protoname* agent) : TimerHandler() { ? ? agent_ = agent; ? ? } ? ? protected: ? ? Protoname* agent_; ? ? virtual void expire(Event* e); }; /* Agent */ //定义Protoname 类 class Protoname : public Agent { /* Friends */ friend class Protoname_PktTimer; /* Private members */ //封装了自身的地址、内状态、路由表、可变的Tcl ? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ???//以及一个负责指定输出数量的计数器 nsaddr_t ra_addr_; //protoname_state state_; protoname_rtable rtable_; int accesible_var_; //用来读取Tcl代码或脚本语言 u_int8_t seq_num_; protected: MobileNode* node_; PortClassifier* dmux_; // For passing packets up to agents.端口分类器 Trace* logtarget_; // For logging.跟踪器 Protoname_PktTimer pkt_timer_; // Timer for sending packets.自定义计时器 //内部属性 inline nsaddr_t ra_addr() { return ra_addr_; } //inline protoname_state state() { return state_; } inline int accessible_var() { return accesible_var_; } void forward_

文档评论(0)

1亿VIP精品文档

相关文档