NS2中的数据包common头结构hdr_cmn

来源:互联网 发布:人体断层解剖学软件 编辑:程序博客网 时间:2024/03/29 12:31

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)intsize_;// simulated packet sizeintuid_;// unique idinterror_;// error flagint     errbitcnt_;     // # of corrupted bits jahnint     fecsize_;doublets_;// timestamp: for q-delay measurement//时间戳在这里intiface_;// receiving interface (label)dir_tdirection_;// direction: 0=none, 1=up, -1=down// source routing         char src_rt_valid;double ts_arr_; // Required by Marker of JOBS //Monarch extn beginsnsaddr_t prev_hop_;     // IP addr of forwarding hopnsaddr_t next_hop_;// next hop for this packetint      addr_type_;    // type of next_hop_ addrnsaddr_t last_hop_;     // for tracing on multi-user channels// AOMDV patchint 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 secdouble txtime_;inline double& txtime() { return(txtime_); }static int offset_;// offset for this headerinline 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_begininline 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_endModulationScheme 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



0 0
原创粉丝点击