NS2中的数据包common头结构hdr_cmn

aomdv_rqueue.cc中多次遇到了HDR_CMN(p),查遍了AOMDV协议都没有找到定义,最后还是度娘出了结果,在下边列出。不得不说,看得越深入,涉及到NS底层的实现也越多。

-----------------------------------------------------------------------------------------------------------------

HDR_CMN(p)的定义位于/ns-allinone-2.35/ns-2.35/common/packet.h中,是宏定义,返回结构体hdr_cmn的access(p):

#define HDR_CMN(p)      (hdr_cmn::access(p))

hdr_cmn代表数据包的common头。AOMDV协议中用到的有时间戳参数ts,以及函数access(p)(在aomdv_rqueue.cc中):

struct hdr_cmn {
	enum dir_t { DOWN= -1, NONE= 0, UP= 1 };
	packet_t ptype_;	// packet type (see above)
	int	size_;		// simulated packet size
	int	uid_;		// unique id
	int	error_;		// error flag
	int     errbitcnt_;     // # of corrupted bits jahn
	int     fecsize_;
	double	ts_;		// timestamp: for q-delay measurement//时间戳在这里
	int	iface_;		// receiving interface (label)
	dir_t	direction_;	// direction: 0=none, 1=up, -1=down
	// source routing 
        char src_rt_valid;
	double ts_arr_; // Required by Marker of JOBS 

	//Monarch extn begins
	nsaddr_t prev_hop_;     // IP addr of forwarding hop
	nsaddr_t next_hop_;	// next hop for this packet
	int      addr_type_;    // type of next_hop_ addr
	nsaddr_t last_hop_;     // for tracing on multi-user channels
	
	// AOMDV patch
	int aomdv_salvage_count_;
	
        // called if pkt can't obtain media or isn't ack'd. not called if
        // droped by a queue
        FailureCallback xmit_failure_; 
        void *xmit_failure_data_;

        /*
         * MONARCH wants to know if the MAC layer is passing this back because
         * it could not get the RTS through or because it did not receive
         * an ACK.
         */
        int     xmit_reason_;
#define XMIT_REASON_RTS 0x01
#define XMIT_REASON_ACK 0x02

        // filled in by GOD on first transmission, used for trace analysis
        int num_forwards_;	// how many times this pkt was forwarded
        int opt_num_forwards_;   // optimal #forwards
	// Monarch extn ends;

	// tx time for this packet in sec
	double txtime_;
	inline double& txtime() { return(txtime_); }

	static int offset_;	// offset for this header
	inline static int& offset() { return offset_; }
	inline static hdr_cmn* access(const Packet* p) { //access()在这里
		return (hdr_cmn*) p->access(offset_);
	}
	
        /* per-field member functions */
	inline packet_t& ptype() { return (ptype_); }
	inline int& size() { return (size_); }
	inline int& uid() { return (uid_); }
	inline int& error() { return error_; }
	inline int& errbitcnt() {return errbitcnt_; }
	inline int& fecsize() {return fecsize_; }
	inline double& timestamp() { return (ts_); }
	inline int& iface() { return (iface_); }
	inline dir_t& direction() { return (direction_); }
	// monarch_begin
	inline nsaddr_t& next_hop() { return (next_hop_); }
	inline int& addr_type() { return (addr_type_); }
	inline int& num_forwards() { return (num_forwards_); }
	inline int& opt_num_forwards() { return (opt_num_forwards_); }
        //monarch_end

	ModulationScheme mod_scheme_;
	inline ModulationScheme& mod_scheme() { return (mod_scheme_); }
};

hdr_cmn的access(p)调用了Packet类的access(off)函数,off为偏移量,若偏移量大于0,则返回包头指针bits_ 偏移了off后的指针:

	inline unsigned char* access(int off) const {
		if (off < 0)
			abort();
		return (&bits_[off]);
	}

包头指针bits_是packet类的成员变量:

unsigned char* bits_;	// header bits



你可能感兴趣的:(C++,ns2,AOMDV协议)