aodv包头分析-上

AODV路由协议提供了一个特定的头部,在aodv_packet.h里面

/*
 * General AODV Header - shared by all formats
 */
struct hdr_aodv {
        u_int8_t        ah_type;
	/*
        u_int8_t        ah_reserved[2];
        u_int8_t        ah_hopcount;
	*/
		// Header access methods
	static int offset_; // required by PacketHeaderManager
	inline static int& offset() { return offset_; }
	inline static hdr_aodv* access(const Packet* p) {
		return (hdr_aodv*) p->access(offset_);
	}
};
在结构体hdr_aodv中,它定义了分组的类型ah_type,静态变量offset_用于在任意一个ns分组中找到AODV分组头的位置。access()方法是用来访问分组头的方法,下面的语句就是用此方法获得AODV分组头:
#define HDR_AODV(p)		((struct hdr_aodv*)hdr_aodv::access(p))
#define HDR_AODV_REQUEST(p)  	((struct hdr_aodv_request*)hdr_aodv::access(p))
#define HDR_AODV_REPLY(p)	((struct hdr_aodv_reply*)hdr_aodv::access(p))
#define HDR_AODV_ERROR(p)	((struct hdr_aodv_error*)hdr_aodv::access(p))
#define HDR_AODV_RREP_ACK(p)	((struct hdr_aodv_rrep_ack*)hdr_aodv::access(p))

offset()方法一般是被分组头管理类调用,一般很少使用。

在aodv.cc里面,定义了AODV路由协议的分组头及相应操作函数:
int hdr_aodv::offset_;
static class AODVHeaderClass : public PacketHeaderClass {
public:
        AODVHeaderClass() : PacketHeaderClass("PacketHeader/AODV",
                                              sizeof(hdr_all_aodv)) {
	  bind_offset(&hdr_aodv::offset_);
	} 
} class_rtProtoAODV_hdr;

当模拟器运行的时候,静态对象class_rtProtoAODV_hdr以’PacketHeader/AODV’和’ sizeof(hdr_all_aodv)’为参数,调用PacketHeaderClass的构造函数:

PacketHeaderClass::PacketHeaderClass(const char* classname, int hdrlen) : 
	TclClass(classname), hdrlen_(hdrlen), offset_(0)
{
}

这为AODV分组头的大小分配了空间,并在配置时刻由分组头管理器使用。bind_offset()函数在构造函数中被调用,分组头管理器知道在哪里为这个分组头存储偏移量。举个例子,当执行语句:

struct hdr_aodv_request *rq = HDR_AODV_REQUEST(p);

时,由前面介绍得知,它会调用aodv_packet.h里面的
return (hdr_aodv*) p->access(offset_);

返回分组头的位置。




转载于:https://www.cnblogs.com/yue-/archive/2012/06/01/6260062.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值