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

📄 node576.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>41.1.10 Using Streams for Realtime Applications</TITLE><META NAME="description" CONTENT="41.1.10 Using Streams for Realtime Applications"><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="node577.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node577.html"><LINK REL="previous" HREF="node572.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node572.html"><LINK REL="up" HREF="node563.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node563.html"><LINK REL="next" HREF="node577.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node577.html"></HEAD><BODY ><!--Navigation Panel--><A NAME="tex2html10283"  HREF="node577.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node577.html"><IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="file:/usr/share/latex2html/icons/next.png"></A> <A NAME="tex2html10277"  HREF="node563.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node563.html"><IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="file:/usr/share/latex2html/icons/up.png"></A> <A NAME="tex2html10271"  HREF="node575.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node575.html"><IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="file:/usr/share/latex2html/icons/prev.png"></A> <A NAME="tex2html10279"  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="tex2html10281"  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="tex2html10284"  HREF="node577.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node577.html">41.1.11 Nam Trace File</A><B> Up:</B> <A NAME="tex2html10278"  HREF="node563.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node563.html">41.1 Nam Trace Format</A><B> Previous:</B> <A NAME="tex2html10272"  HREF="node575.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node575.html">41.1.9.3 Node Exec Button</A> &nbsp <B>  <A NAME="tex2html10280"  HREF="node1.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node1.html">Contents</A></B>  &nbsp <B>  <A NAME="tex2html10282"  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="SECTION0102110000000000000000">41.1.10 Using Streams for Realtime Applications</A></H2><P>In addtion to reading from files nam can also read from a stream such asSTDIN. Here is a little tutorial on how to send a nam trace stream to nam tomake it operate with real-time data.  First somebackground on how nam works internally.  Basically, it thinks it isreading from a nam tracefile.  The file has a format to it.  Each lineis a nam event.  The first character on the line defines the type ofevent and is followed by several flags to set options on that event.Each event is terminated by a newline character.  A nam tracefile has 2sections, static configuration events and animation events.  All eventswith -t * in them are configuration events and should be sent to nam inone burst.  Lines beginning with a # are comment lines.  Currentlycomments should only be place in the animation section of the file afterthe first animation event.<P>First of all you need to pipe your data to nam's stdin and add the '-'flag to the nam command.<P>For example:<P><PRE></PRE><P>nam will read the information from stdin<P>Following is a short wireless animation example.  The first part of thescript has line with -t * which tells nam that these are initialconfiguration information.<P><PRE>V -t * -v 1.0a5 -a 0W -t * -x 600 -y 600</PRE><P>The first 2 lines are used in the nam initialization.  They need to bethe first 2 lines sent to nam from your program. V is the minimum namversion needed to correctly run this script.  W means this is scriptcontains wireless nodes which will be within the canvas size of width xand height y.<P><PRE>n -t * -s 0 -x 0.0 -y 0.0 -z 20 -v circle -c black -wn -t * -s 1 -x 0.0 -y 200.0 -z 20 -v box -c black -w</PRE><P>Next is the network layout information.  The first line n creates awireless (-w) circular (-v circle) node with id 0 (-s 0) at position0.0,0.0 (-x 0.0 -y 0.0). It's size (-z) is 20 and it's color (-c) isblack.  The second is a wireless square (-v box) node with id 1 (-s 1)at 0.0,200.0.  Each node has to have a unique id number given by the -sflag.<P><PRE>A -t * -n 1 -p 0 -o 0xffffffff -c 31 -a 1A -t * -h 1 -m 2147483647 -s 0</PRE><P>The A event line has to do with setting up hierarchical addressing innam.  It is necessary in wireless nam because packets are treated asbroadcast to every node.<P>Now we are done with the configuration part of the nam file.  Next arethe animation events.  In order for nam to operate in a close toreal-time mode it needs to constantly receive updates.  As it is playingit will  keeps reading lines from the nam trace and playing them back.The sequence of events must be in chronological order.  For example thefollowing lines change the color of node 1 from black to green back toblack and then to black again.<PRE>n -t 0.0 -s 1 -S COLOR -c green -o blackn -t 0.01 -s 1 -S COLOR -c black -o greenn -t 0.02 -s 1 -S COLOR -c black -o black</PRE><P>Notice that the "-t &lt;time&gt;" flags are always increasing.  You cannotissue one event at -t 0.2 and then another later on at -t 0.1.  Nam hasan internal counter of time and it executes an event once it's timecounter passes that event time.  It will execute events in chronologicalorder but only if they are given to it in chronological order.  So thefollowing WILL NOT work.<PRE>n -t 0.0 -s 1 -S COLOR -c black -o blackn -t 0.02 -s 1 -S COLOR -c green -o blackn -t 0.01 -s 1 -S COLOR -c black -o green</PRE><P>Since nam has its own internal representation of time which is differentthan current real world time you have to try and synchronize them.There is no explicit and totally accurate way to do this but you canhave a rough synchronization of time by having you applicationperiodically send nam events even if nothing has happened. We have created a dummy or "no-op" event (T) for this purpose.<PRE>T -t 0.5</PRE><P>As described above, you MUST feed events to nam in non-decreasingtimestamp order. Successive events at the same time are OK. Before animating to a given time, nam needs to know that it's got allthe events for that time, and so it actually has to read an eventAFTER that time.  Therefore if you're driving nam from an externalprocess in real-time it will refuse to animate time t until it sees anevent at time t+i (for any i &gt; 0).  To make nam play out eventssmoothly, you may therefore need to generate dummy events withintermediate timestamps (so that nam knows it can advance).  Events oftype "T" are dummy events, so this stream would produce jerkyanimatation:<P><PRE>n -t 1.0 -s 1 -S COLOR -c green -o blackn -t 2.0 -s 1 -S COLOR -c black -o greenn -t 3.0 -s 1 -S COLOR -c black -o black</PRE><P>while this would be animatated much smoother:<P><PRE>T -t 0.0T -t 0.5n -t 1.0 -s 1 -S COLOR -c green -o blackT -t 1.5n -t 2.0 -s 1 -S COLOR -c black -o greenT -t 2.5n -t 3.0 -s 1 -S COLOR -c black -o blackT -t 3.5T -t 4.0...</PRE><P>If nam ever gets to the end of anevent stream it will block and the program will appear as if ithas frozen.  The screen will not be updated until it can read another eventso you must be sure to feed events to nam faster than or as fast as itcan read them.  This technique works pretty well and allows nam to lookas if it is running in real-time although in reality there will be aslight delay which is usually acceptable.<P>One other thing to remember is that your application should send these eventsbased on it's representation of time from when the application started.Also, when sending events to nam they should be unbuffered so you will want to fflush(stdout); after each event.<P>Another event which you can keep sending to nam would be an note whichwill show a the bottom of the nam window.<PRE>v -t 0.08 -e sim\_annotation 0.08 1 Time is 0.08v -t 0.09 -e sim\_annotation 0.09 2 Time is 0.09v -t 0.10 -e sim\_annotation 0.08 3 Time is 0.10</PRE><P>The 'v' event means that you will execute a tcl script at time -t,everything after -e is the script to execute.  sim_annotation writes anote at the bottom of the screen.  The numbers after it are the time towrite and a unique note id.  Notice how I incremented the note id witheach successive note.   The remaining is what is written to the screen.For example "Time is 0.08" followed by "Time is 0.09", etc...<P>That is the basic idea behind making nam work in a real-time fashion.Following are two examples on how to generate wireless packet animationswhen using nam.  To make a wireless broadcast which is shown as quicklyexpanding circle you can use the following.<P><PRE>+ -t 0.16 -s 0 -d -1 -p AODV -e 100 -c 2 -a 0 -i 0 -k MAC- -t 0.16 -s 0 -d -1 -p AODV -e 100 -c 2 -a 0 -i 0 -k MACh -t 0.16 -s 0 -d -1 -p AODV -e 100 -c 2 -a 0 -i 0 -k MAC</PRE><P>'+' event puts the packet onto the transmission queue'-' event remove the packet from the queue and makes it ready tobroadcast'h' send the packet to the next hop which actually causes the animationHere are the meanings of the flags  -t time  -s transmitting node id  -d destination node id (-1 indicates broadcast to world)  -e size of transmission  -c ultimate destination of the packet<P>To show a packet being send from one particular node to another use thefollowing<P><PRE>r -t 0.255 -s 1 -d -1 -p MAC -e 512 -c 0 -a 0 -i 0 -k MAC+ -t 0.255 -s 1 -d 0 -p AODV -e 512 -c 0 -a 0 -i 0 -k MAC- -t 0.255 -s 1 -d 0 -p AODV -e 512 -c 0 -a 0 -i 0 -k MACh -t 0.255 -s 1 -d 0 -p AODV -e 512 -c 0 -a 0 -i 0 -k MACr -t 0.255 -s 0 -d 1 -p AODV -e 512 -c 0 -a 0 -i 0 -k MAC</PRE><P>First the packet is received ('r') from the wireless broadcast to node1.  It is then added to the outgoing queue ('+') on node 1.  Next, it isremoved from the queue('-') and ready to be sent to node 0.  Then thepacket is sent to the next hop ('h') node 0.  This will trigger ananimation of a line the length of the packet size moving from node 1 tonode 0.  Finally it is received ('r') by node 0 from node 1.<P>For more nam events you can look at the nam section in the ns manual<P>Also, you can save a copy of the trace from a realtimesource using the unix 'tee' command. For example:<P><PRE></PRE><P>Sometimes it is a bug in nam and sometimes it is a problem with the wayyour tracefile is formatted.  You may expect nam to do something that itwon't do.  Part of the philosophy in the design of nam is that the detail ofan animation is handled by the tracefile which makes nam more flexiblebut pushes some of the animation complexity on to the programmergenerating the tracefile. <P><HR><!--Navigation Panel--><A NAME="tex2html10283"  HREF="node577.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node577.html"><IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="file:/usr/share/latex2html/icons/next.png"></A> <A NAME="tex2html10277"  HREF="node563.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node563.html"><IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="file:/usr/share/latex2html/icons/up.png"></A> <A NAME="tex2html10271"  HREF="node575.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node575.html"><IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="file:/usr/share/latex2html/icons/prev.png"></A> <A NAME="tex2html10279"  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="tex2html10281"  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="tex2html10284"  HREF="node577.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node577.html">41.1.11 Nam Trace File</A><B> Up:</B> <A NAME="tex2html10278"  HREF="node563.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node563.html">41.1 Nam Trace Format</A><B> Previous:</B> <A NAME="tex2html10272"  HREF="node575.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node575.html">41.1.9.3 Node Exec Button</A> &nbsp <B>  <A NAME="tex2html10280"  HREF="node1.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node1.html">Contents</A></B>  &nbsp <B>  <A NAME="tex2html10282"  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 + -