⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 node128.html

📁 相关搜索: ns2仿真结果分析 all-awk ns2 ns2 无限网络中awk文件 ... [2.tcl.rar] - 在ns2平台上实现对AODV协议的模拟
💻 HTML
字号:
<html><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><!--Converted with jLaTeX2HTML 2002 (1.62) JA patch-1.4patched version by:  Kenshi Muto, Debian Project.LaTeX2HTML 2002 (1.62),original version by:  Nikos Drakos, CBLU, University of Leeds* revised and updated by:  Marcus Hennecke, Ross Moore, Herb Swan* with significant contributions from:  Jens Lippmann, Marek Rouchal, Martin Wilck and others --><HTML><HEAD><TITLE>12.1 A Protocol-Specific Packet Header</TITLE><META NAME="description" CONTENT="12.1 A Protocol-Specific Packet Header"><META NAME="keywords" CONTENT="everything"><META NAME="resource-type" CONTENT="document"><META NAME="distribution" CONTENT="global"><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"><META NAME="Generator" CONTENT="jLaTeX2HTML v2002 JA patch-1.4"><META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css"><LINK REL="STYLESHEET" HREF="everything.css" tppabs="http://www.isi.edu/nsnam/ns/doc/everything.css"><LINK REL="next" HREF="node131.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node131.html"><LINK REL="previous" HREF="node127.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node127.html"><LINK REL="up" HREF="node127.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node127.html"><LINK REL="next" HREF="node129.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node129.html"></HEAD><BODY ><!--Navigation Panel--><A NAME="tex2html3260"  HREF="node129.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node129.html"><IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="file:/usr/share/latex2html/icons/next.png"></A> <A NAME="tex2html3254"  HREF="node127.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node127.html"><IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="file:/usr/share/latex2html/icons/up.png"></A> <A NAME="tex2html3248"  HREF="node127.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node127.html"><IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="file:/usr/share/latex2html/icons/prev.png"></A> <A NAME="tex2html3256"  HREF="node1.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node1.html"><IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="file:/usr/share/latex2html/icons/contents.png"></A> <A NAME="tex2html3258"  HREF="node590.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node590.html"><IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="file:/usr/share/latex2html/icons/index.png"></A> <BR><B> Next:</B> <A NAME="tex2html3261"  HREF="node129.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node129.html">12.1.1 Adding a New</A><B> Up:</B> <A NAME="tex2html3255"  HREF="node127.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node127.html">12. Packet Headers and</A><B> Previous:</B> <A NAME="tex2html3249"  HREF="node127.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node127.html">12. Packet Headers and</A> &nbsp <B>  <A NAME="tex2html3257"  HREF="node1.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node1.html">Contents</A></B>  &nbsp <B>  <A NAME="tex2html3259"  HREF="node590.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node590.html">Index</A></B> <BR><BR><!--End of Navigation Panel--><H1><A NAME="SECTION03910000000000000000"></A><A NAME="sec:ppackethdr"></A><BR>12.1 A Protocol-Specific Packet Header</H1><P>Protocol developerswill often wish to provide a specific header type to be used in packets.Doing so allows a new protocol implementationto avoid overloading already-existing header fields.We consider a simplified version of RTP as an example.The RTP header will require a sequence number fields and a sourceidentifier field.The following classes create the needed header(see rtp.h and rtp.cc):<PRE>{\rm From rtp.h:}        /* rtp packet.  For now, just have srcid + seqno. */        struct hdr_rtp {                 u_int32_t srcid_;                int seqno_;                /* per-field member functions  */                u_int32_t&amp; srcid() { return (srcid_); }                int&amp; seqno() { return (seqno_); }                /* Packet header access functions */                static int offset_;                inline static int&amp; offset() { return offset_; }                inline static hdr_rtp* access(const Packet* p) {                        return (hdr_rtp*) p-\&gt;access(offset_);                }        };{\rm From rtp.cc:}        class RTPHeaderClass : public PacketHeaderClass {        public:                 RTPHeaderClass() : PacketHeaderClass("PacketHeader/RTP",                                                     sizeof(hdr_rtp)) {                        bind_offset(&amp;hdr_rtp::offset_);                }        } class_rtphdr;        void RTPAgent::sendpkt()        {                Packet* p = allocpkt();                hdr_rtp *rh = hdr_rtp::access(p);                lastpkttime_ = Scheduler::instance().clock();                /* Fill in srcid_ and seqno */                rh-\&gt;seqno() = seqno_++;                rh-\&gt;srcid() = session_-\&gt;srcid();                target_-\&gt;recv(p, 0);        }        RTPAgent::RTPAgent()                : session_(0), lastpkttime_(-1e6)        {                type_ = PT_RTP;                bind("seqno_", &amp;seqno_);        }</PRE>The first structure, <TT>hdr_rtp</TT>, defines the layoutof the RTP packet header (in terms of words and their placement):which fields are needed and how big they are.This structure definition is only used by thecompiler to compute byte offsets of fields;no objects of this structure type are ever directly allocated.The structure also provides member functions which in turnprovide a layer of data hiding for objects wishing to reador modify header fields of packets.Note that the static class variable <TT>offset_</TT> is usedto find the byte offset at which the rtp header is locatedin an arbitrary packet.Two methods are provided to utilize this variable to access thisheader in any packet: <TT>offset()</TT> and <TT>access()</TT>.The latter is what most users should choose to access this particularheader in a packet; the former is used by the packet header managementclass and should seldom be used.For example, to access the RTP packet header in a packet pointed by<TT>p</TT>, one simply says <TT>hdr_rtp::access(p)</TT>.The actual binding of <TT>offset_</TT> to the position of this header ina packet is done by routines inside tcl/lib/ns-packet.tcl andpacket.cc.The <TT>const</TT> in <TT>access()</TT>'s argument provides (presumably)read-only access to a <TT>const</TT> Packet, lthough read-only isenforced since the return pointer is not <TT>const</TT>. One correct way to do this is to provide two methods, one for writeaccess, the other for read-only access.However, this is not currently implemented.<P><B>IMPORTANT</B>: Notice that this is completely different from the<EM>original</EM> (and obsolete) method to access a packet header, whichrequires that an integer variable, <TT>off_hdrname_</TT>, be defined for any packetheader that one needs to access.This method is now obsolete; its usage is tricky and its misuse canbe very difficult to detect. <P>The static object <TT>class_rtphdr</TT> ofRTPHeaderClass../ns-2/rtp.cc is used to provide linkage to OTcl when the RTP header isenabled at configuration time.When the simulator executes, this static object callsthe <TT>PacketHeaderClass</TT> constructor with arguments<TT>"PacketHeader/RTP"</TT> and <TT>sizeof(hdr_rtp)</TT>.This causes the size of the RTP header to be storedand made available to the packet header managerat configuration time (see below, Section&nbsp;<A HREF="node135.html#sec:packethdrmgr" tppabs="http://www.isi.edu/nsnam/ns/doc/node135.html#sec:packethdrmgr">12.2.4</A>).Notice that <TT>bind_offset()</TT> <B>MUST</B> be called in the constructor of this class, so that the packetheader manager knows where to store the offset for this particularpacket header. <P>The sample member function []sendpkt methodof <TT>RTPAgent</TT> creates a new packetto send by calling []allocpkt, which handles assignmentof all the network-layer packet header fields (in this case, IP).Headers other than IP are handled separately.In this case, the agent uses the <TT>RTPHeader</TT> defined above.The Packet::access member function returns the addressof the first byte in a buffer used to hold header information (see below).Its return value is cast as a pointer to the header of interest,after which member functions of the <TT>RTPHeader</TT>object are used to access individual fields.<P><BR><HR><!--Table of Child-Links--><A NAME="CHILD_LINKS"><STRONG>Subsections</STRONG></A><UL><LI><A NAME="tex2html3262"  HREF="node129.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node129.html">12.1.1 Adding a New Packet Header Type</A><LI><A NAME="tex2html3263"  HREF="node130.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node130.html">12.1.2 Selectively Including Packet Headers in Your Simulation</A></UL><!--End of Table of Child-Links--><HR><!--Navigation Panel--><A NAME="tex2html3260"  HREF="node129.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node129.html"><IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="file:/usr/share/latex2html/icons/next.png"></A> <A NAME="tex2html3254"  HREF="node127.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node127.html"><IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="file:/usr/share/latex2html/icons/up.png"></A> <A NAME="tex2html3248"  HREF="node127.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node127.html"><IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="file:/usr/share/latex2html/icons/prev.png"></A> <A NAME="tex2html3256"  HREF="node1.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node1.html"><IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="file:/usr/share/latex2html/icons/contents.png"></A> <A NAME="tex2html3258"  HREF="node590.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node590.html"><IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="file:/usr/share/latex2html/icons/index.png"></A> <BR><B> Next:</B> <A NAME="tex2html3261"  HREF="node129.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node129.html">12.1.1 Adding a New</A><B> Up:</B> <A NAME="tex2html3255"  HREF="node127.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node127.html">12. Packet Headers and</A><B> Previous:</B> <A NAME="tex2html3249"  HREF="node127.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node127.html">12. Packet Headers and</A> &nbsp <B>  <A NAME="tex2html3257"  HREF="node1.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node1.html">Contents</A></B>  &nbsp <B>  <A NAME="tex2html3259"  HREF="node590.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node590.html">Index</A></B> <!--End of Navigation Panel--><ADDRESS>2003-09-23</ADDRESS></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -