在NS2中添加路由协议
来源:互联网 发布:什么是端口 编辑:程序博客网 时间:2024/04/28 16:11
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 //代理基本类
#include //数据包类
#include //跟踪类,用于在跟踪文件里记录输出的仿真结果
#include //计时器基本类,创建我们自定义的计时器
#include //随机类,用于产生伪随机数
#include //端口分类器类,用于淘汰向上层传输的数据包
#include
#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
//自定义计时器发送定时的控制包
class Protoname_PktTimer : public TimerHandler {
public:
}
protected:
//定义Protoname 类
class Protoname : public Agent {
#endif
其中五个文件的具体功能和作用如下:
(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
#include //数据包类
#include //跟踪类,用于在跟踪文件里记录输出的仿真结果
#include //计时器基本类,创建我们自定义的计时器
#include //随机类,用于产生伪随机数
#include //端口分类器类,用于淘汰向上层传输的数据包
#include
#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
class Protoname_PktTimer : public TimerHandler {
Protoname_PktTimer(Protoname* agent) : TimerHandler() {
agent_ = agent;
};Protoname* agent_;
virtual void expire(Event* e);
//定义Protoname 类
class Protoname : public Agent {
protected:
friend class Protoname_PktTimer;
//封装了自身的地址、内状态、路由表、可变的Tcl
//以及一个负责指定输出数量的计数器
nsaddr_t ra_addr_;
//protoname_state state_;
protoname_rtable rtable_;
int accesible_var_; //用来读取Tcl代码或脚本语言
u_int8_t seq_num_;
MobileNode* node_;public:
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_data(Packet*); //数据包被正确传输的目的地
void recv_protoname_pkt(Packet*);
void send_protoname_pkt();
void reset_protoname_pkt_timer();
Protoname(nsaddr_t);};
int command(int, const char*const*);
void recv(Packet*, Handler*);
//void mac_failed(Packet*);
#endif
- 在NS2中添加路由协议
- 在NS2中添加路由协议
- 在NS2中添加路由协议
- 在NS2中添加路由协议
- 在NS2中添加路由协议(转)
- 怎么在NS2中添加一个协议
- 如何在NS2中增加新的路由协议
- NS2中添加Ping协议
- 如何在NS2中添加新的协议
- 在NS2 AODV协议中添加blackhole attacker(黑洞攻击)
- 在NS2中添加一个新的协议
- 向NS2中添加新的无线移动网络路由协议
- ns2.30下添加mflood-mflood路由协议
- NS2.35下添加新的无线路由协议要点
- 在ns2下添加新协议:
- 在 ns2.35 添加ZRP 协议
- NS2中添加GPSR(KeLiu)协议
- NS2.35中添加MAC协议
- ue使用技巧
- linux中shell变量$#,$@,$0,$1,$2的含义解释
- Service Provider Access resulted in exception 'oracle.apps.fnd.soa.util.SOAException'
- 数据库面试题--emp_employee、department
- SunOS 5.10 sparc C/C++ 初学者之编译参数
- 在NS2中添加路由协议
- Jenkins配置ios
- strong,weak小记
- H.264 CodecStream Architechture
- Android唯一识别码
- 广播通信
- Android开发笔记之HelloWord
- 邮箱附件 保存到指定的文件夹
- hibernate.hbm2ddl.auto 的设置