📄 aodvsec_packet.h
字号:
#ifndef __aodvsec_packet_h__
#define __aodvsec_packet_h__
//#include <config.h>
//#include "aodvsec.h"
#define AODVSEC_MAX_ERRORS 100
/* =====================================================================
Packet Formats...
===================================================================== */
#define AODVSECTYPE_HELLO 0x01
#define AODVSECTYPE_RREQ 0x02
#define AODVSECTYPE_RREP 0x04
#define AODVSECTYPE_RERR 0x08
#define AODVSECTYPE_RREP_ACK 0x10
/*
* AODVSEC Routing Protocol Header Macros
*/
#define HDR_AODVSEC(p) ((struct hdr_aodvsec*)hdr_aodvsec::access(p))
#define HDR_AODVSEC_REQUEST(p) ((struct hdr_aodvsec_request*)hdr_aodvsec::access(p))
#define HDR_AODVSEC_REPLY(p) ((struct hdr_aodvsec_reply*)hdr_aodvsec::access(p))
#define HDR_AODVSEC_ERROR(p) ((struct hdr_aodvsec_error*)hdr_aodvsec::access(p))
#define HDR_AODVSEC_RREP_ACK(p) ((struct hdr_aodvsec_rrep_ack*)hdr_aodvsec::access(p))
/*
* General AODVSEC Header - shared by all formats
*/
struct hdr_aodvsec {
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_aodvsec* access(const Packet* p) {
return (hdr_aodvsec*) p->access(offset_);
}
};
struct hdr_aodvsec_request {
u_int8_t rq_type; // Packet Type
u_int8_t reserved[2];
u_int8_t rq_hop_count; // Hop Count
u_int32_t rq_bcast_id; // Broadcast ID
nsaddr_t rq_dst; // Destination IP Address
u_int32_t rq_dst_seqno; // Destination Sequence Number
nsaddr_t rq_src; // Source IP Address
u_int32_t rq_src_seqno; // Source Sequence Number
double rq_timestamp; // when REQUEST sent;
// used to compute route discovery latency
// This define turns on gratuitous replies- see aodvsec.cc for implementation contributed by
// Anant Utgikar, 09/16/02.
//#define RREQ_GRAT_RREP 0x80
inline int size() {
int sz = 0;
/*
sz = sizeof(u_int8_t) // rq_type
+ 2*sizeof(u_int8_t) // reserved
+ sizeof(u_int8_t) // rq_hop_count
+ sizeof(double) // rq_timestamp
+ sizeof(u_int32_t) // rq_bcast_id
+ sizeof(nsaddr_t) // rq_dst
+ sizeof(u_int32_t) // rq_dst_seqno
+ sizeof(nsaddr_t) // rq_src
+ sizeof(u_int32_t); // rq_src_seqno
*/
sz = 7*sizeof(u_int32_t);
assert (sz >= 0);
return sz;
}
};
struct hdr_aodvsec_reply {
u_int8_t rp_type; // Packet Type
u_int8_t reserved[2];
u_int8_t rp_hop_count; // Hop Count
nsaddr_t rp_dst; // Destination IP Address
u_int32_t rp_dst_seqno; // Destination Sequence Number
nsaddr_t rp_src; // Source IP Address
double rp_lifetime; // Lifetime
double rp_timestamp; // when corresponding REQ sent;
// used to compute route discovery latency
u_int8_t signe_rreq_array[124];//来自RREQ的签名,用于存入路由表
nsaddr_t signe_rreq;//........................................
u_int32_t sip_rreq;//.............................................
u_int32_t lifetime_rreq; //...........................................
inline int size() {
int sz = 0;
/*
sz = sizeof(u_int8_t) // rp_type
+ 2*sizeof(u_int8_t) // rp_flags + reserved
+ sizeof(u_int8_t) // rp_hop_count
+ sizeof(double) // rp_timestamp
+ sizeof(nsaddr_t) // rp_dst
+ sizeof(u_int32_t) // rp_dst_seqno
+ sizeof(nsaddr_t) // rp_src
+ sizeof(u_int32_t); // rp_lifetime
*/
sz = 6*sizeof(u_int32_t)+128*8+32+32;
assert (sz >= 0);
return sz;
}
};
struct hdr_aodvsec_error {
u_int8_t re_type; // Type
u_int8_t reserved[2]; // Reserved
u_int8_t DestCount; // DestCount
// List of Unreachable destination IP addresses and sequence numbers
nsaddr_t unreachable_dst[AODVSEC_MAX_ERRORS];
u_int32_t unreachable_dst_seqno[AODVSEC_MAX_ERRORS];
inline int size() {
int sz = 0;
/*
sz = sizeof(u_int8_t) // type
+ 2*sizeof(u_int8_t) // reserved
+ sizeof(u_int8_t) // length
+ length*sizeof(nsaddr_t); // unreachable destinations
*/
sz = (DestCount*2 + 1)*sizeof(u_int32_t);
assert(sz);
return sz;
}
};
struct hdr_aodvsec_rrep_ack {
u_int8_t rpack_type;
u_int8_t reserved;
};
// for size calculation of header-space reservation
union hdr_all_aodvsec {
hdr_aodvsec ah;
hdr_aodvsec_request rreq;
hdr_aodvsec_reply rrep;
hdr_aodvsec_error rerr;
hdr_aodvsec_rrep_ack rrep_ack;
};
#endif /* __aodvsec_packet_h__ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -