📄 node108.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>10.5.1 Creating the Agent</TITLE><META NAME="description" CONTENT="10.5.1 Creating the Agent"><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="node109.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node109.html"><LINK REL="previous" HREF="node107.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node107.html"><LINK REL="up" HREF="node107.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node107.html"><LINK REL="next" HREF="node109.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node109.html"></HEAD><BODY ><!--Navigation Panel--><A NAME="tex2html2970" HREF="node109.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node109.html"><IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="file:/usr/share/latex2html/icons/next.png"></A> <A NAME="tex2html2964" HREF="node107.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node107.html"><IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="file:/usr/share/latex2html/icons/up.png"></A> <A NAME="tex2html2958" HREF="node107.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node107.html"><IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="file:/usr/share/latex2html/icons/prev.png"></A> <A NAME="tex2html2966" 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="tex2html2968" 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="tex2html2971" HREF="node109.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node109.html">10.5.2 Starting the Agent</A><B> Up:</B> <A NAME="tex2html2965" HREF="node107.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node107.html">10.5 Examples: Tcp, TCP</A><B> Previous:</B> <A NAME="tex2html2959" HREF="node107.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node107.html">10.5 Examples: Tcp, TCP</A>   <B> <A NAME="tex2html2967" HREF="node1.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node1.html">Contents</A></B>   <B> <A NAME="tex2html2969" HREF="node590.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node590.html">Index</A></B> <BR><BR><!--End of Navigation Panel--><H2><A NAME="SECTION03751000000000000000"></A><A NAME="sec:createtcpsimple"></A><BR>10.5.1 Creating the Agent</H2><P>The following OTcl code fragment creates a <TT>TCP</TT> agentand sets it up:<PRE> set tcp [new Agent/TCP] # create sender agent; $tcp set fid_ 2 # set IP-layer flow ID; set sink [new Agent/TCPSink] # create receiver agent; $ns attach-agent $n0 $tcp # put sender on node $n0; $ns attach-agent $n3 $sink # put receiver on node $n3; $ns connect $tcp $sink # establish TCP connection; set ftp [new Application/FTP] # create an FTP source "application"; $ftp attach-agent $tcp # associate FTP with the TCP sender; $ns at 1.2 "$ftp start" #arrange for FTP to start at time 1.2 sec;</PRE>The OTcl instruction <TT>new Agent/TCP</TT> results in thecreation of a C++ <TT>TcpAgent</TT> class object.Its constructor first invokes the constructor of the<TT>Agent</TT> base class and then performs its own bindings.These two constructors appear as follows:<PRE>{\rm The TcpSimpleAgent constructor (\nsf{tcp.cc}):} TcpAgent::TcpAgent() : Agent(PT_TCP), rtt_active_(0), rtt_seq_(-1), rtx_timer_(this), delsnd_timer_(this) { bind("window_", &wnd_); bind("windowInit_", &wnd_init_); bind("windowOption_", &wnd_option_); bind("windowConstant_", &wnd_const_); \ldots bind("off_ip_", &off_ip_); bind("off_tcp_", &off_tcp_); \ldots }{\rm The Agent constructor (\nsf{agent.cc}):} Agent::Agent(int pkttype) : addr_(-1), dst_(-1), size_(0), type_(pkttype), fid_(-1), prio_(-1), flags_(0) { memset(pending_, 0, sizeof(pending_)); /* timers / // this is really an IP agent, so set up // for generating the appropriate IP fields\ldots bind("addr_", (int*)&addr_); bind("dst_", (int*)&dst_); bind("fid_", (int*)&fid_); bind("prio_", (int*)&prio_); bind("flags_", (int*)&flags_); \ldots }</PRE>These code fragments illustrate the common case where an agent'sconstructor passes a packet type identifier to the <TT>Agent</TT>constructor.The values for the various packet types areused by the packet tracing facilitySectionsec:traceptypeand are defined in trace.h.The variables which are bound in the <TT>TcpAgent</TT> constructorare ordinary instance/member variables for the classwith the exception of the special integer values <TT>off_tcp_</TT>and <TT>off_ip_</TT>.These are needed in order to access a TCP header and IP header, respectively.Additional details are in the section on packet headersSectionsec:ppackethdr.<P>Note that the <TT>TcpAgent</TT> constructor contains initializations fortwo timers, <TT>rtx_timer_</TT> and <TT>delsnd_timer_</TT>.<P><TT>TimerHandler</TT> objects are initialized by providing a pointer (the <TT>this</TT> pointer) tothe relevant agent.<P><HR><!--Navigation Panel--><A NAME="tex2html2970" HREF="node109.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node109.html"><IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="file:/usr/share/latex2html/icons/next.png"></A> <A NAME="tex2html2964" HREF="node107.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node107.html"><IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="file:/usr/share/latex2html/icons/up.png"></A> <A NAME="tex2html2958" HREF="node107.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node107.html"><IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="file:/usr/share/latex2html/icons/prev.png"></A> <A NAME="tex2html2966" 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="tex2html2968" 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="tex2html2971" HREF="node109.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node109.html">10.5.2 Starting the Agent</A><B> Up:</B> <A NAME="tex2html2965" HREF="node107.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node107.html">10.5 Examples: Tcp, TCP</A><B> Previous:</B> <A NAME="tex2html2959" HREF="node107.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node107.html">10.5 Examples: Tcp, TCP</A>   <B> <A NAME="tex2html2967" HREF="node1.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node1.html">Contents</A></B>   <B> <A NAME="tex2html2969" 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 + -