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

📄 new_app_agent.html

📁 相关搜索: ns2仿真结果分析 all-awk ns2 ns2 无限网络中awk文件 ... [2.tcl.rar] - 在ns2平台上实现对AODV协议的模拟
💻 HTML
字号:
<html><head><title>Add New Application and Agent</title></head><body background="parchment.gif" tppabs="http://nile.wpi.edu/NS/Icons/parchment.gif" text="#000000" link="#0000FF"vlink="#000080" alink="#FF0000"><br><center><h2>Add New Application and Agent</h2></center><center><h3>(Tested with ns-2.1b8a, ns-2.1b9a and ns-2.26)</h3></center><br><br><li><b>Objective</b></li><p>We want to build a multimedia application that runs over a UDPconnection, which simulates the behavior of an imaginary multimediaapplication that implements "five rate media scaling" that can respondto network congestion to some extent by changing encoding andtransmission policy pairs associated with scale parameter values. </p><br><li><b>Application Description</b></li><p>In this implementation, it is assumed that when a connection isestablished, the sender and the receiver agree on 5 different sets ofencoding and transmission policy pairs, and associate them with 5scale values (0-4). For simplicity reasons, it is also assumed that aconstant transmission rate is determined for each of the encoding andtransmission policy pairs, and every pair uses packets of the samesize regardless of the encoding scheme. </p><p>Basically, "five rate media scaling" works as follow. The senderstarts with transmission rate associated with scale 0, and changestransmission rates according to the scale value that the receivernotifies. The receiver is responsible for monitoring networkcongestion and determining the scale factor. For congestionmonitoring, a simple periodical (for every RTT second) packet lossmonitoring is used, and even a single packet loss for each period isregarded as network congestion. If congestion is detected, thereceiver reduces the scale parameter value to half and notifies thesender of this value. If no packet loss is detected, the receiverincreases the value by one and notifies the sender. </p><br><li><b>Problem Analysis</b></li><p>Before implementing this application, the UDP agent implementationis examined and one major problem is found. Since a UDP agentallocates and sends network packets, all the information needed forapplication level communication should be handed to the UDP agent as adata stream. However, the UDP implementation allocates packets thatonly have a header stack. Therefore, we need to modify the UDPimplementation to add a mechanism to send the data received from theapplication. It is also noted that we might want to use thisapplication for further research on IP router queue managementmechanisms. Therefore, we need a way to distinguish this type ofmultimedia stream from other types of streams. That is, we also needto modify UDP agent to record data type in one of IP header fieldsthat is currently not used. </p><br><li><b>Note on NS Versions</b></li><p>The locations of C++ source files in NS version 2.1b9a are slightlychanged from 2.1b8a.  In ns-2.1b9a, C++ source files are categorizedand placed in sub-directories under the main ns-2 directory.  For example,"packet.h" to "common/packet.h", "agent.h" to "common/agent.h" and "app.h"is moved to "apps/app.h".  However, the locations of OTcl files are sameas before ("tcl/lib/ns-packet.tcl", "tcl/lib/ns-default.tcl" and etc.)</p><li><b>Design and Implementation</b></li><p>For the application, we decided to take the CBR implementation andmodify it to have the "five level media scaling" feature. We examinedthe C++ class hierarchy, and decided to name the class of thisapplication as "<font color=RED>MmApp</font>" and implement as a childclass of "Application". The matching OTcl hierarchy name is "<fontcolor=GREEN>Application/MmApp</font>". The sender and receiverbehavior of the application is implemented together in "MmApp". Forthe modified UDP agent that supports "MmApp", we decided to name it"<font color=RED>UdpMmAgent</font>" and implement it as a child classof "UdpAgent". The matching OTcl hierarchy name is "<fontcolor=GREEN>Agent/UDP/UDPmm</font>"</p><ul><li><b>MmApp Header:</b> For the application level communication, wedecided to define a header of which the structure named in C++ "<fontcolor=PURPLE>hdr_mm</font>". Whenever the application has informationto transmit, it will hand it to "UdpMmAgent" in the "hdr_mm" structureformat. Then, "UdpMmAgent" allocates one or more packets (depending onthe simulated data packet size) and writes the data to the multimediaheader of each packet. Figure 23 shows the header definition, in whicha structure for the header and a header class object, "<fontcolor=RED>MultimediaHeaderClass</font>" that should be derived from"<font color=BLUE>PacketHeaderCalss</font>" is defined. In definingthis class, the OTcl name for the header ("<fontcolor=GREEN>PacketHeader/Multimedia</font>") and the size of theheader structure defined are presented. Notice that bind_offset() mustbe called in the constructor of this class.<p align="center"><img src="fig23.gif" tppabs="http://nile.wpi.edu/NS/Figure/fig23.gif"><br><b>Figure 23.</b> MM Header Structure & Class (in "udp-mm.h" &"udp-mm.cc")</p><br><p align="center"><img src="fig24_a.gif" tppabs="http://nile.wpi.edu/NS/Figure/fig24_a.gif"><br><b>Figure 24 (a).</b> Add to the "packet.h" file (C++) </p><p align="center"><img src="fig24_b.gif" tppabs="http://nile.wpi.edu/NS/Figure/fig24_b.gif"><br><b>Figure 24 (b).</b> Add to the "ns-packet.tcl" file (Otcl) </p>We also add lines to packet.h and ns-packet.tcl as shown in Figure 24(a) and (b) to add our "Mulltimedia" header to the header stack. Atthis point, the header creation process is finished, and"UdpMmAgent" will access the new header via hdr_mm::access() member function. Please refer to <a href="javascript:if(confirm('http://www.isi.edu/nsnam/ns/ns-documentation.html  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?'))window.location='http://www.isi.edu/nsnam/ns/ns-documentation.html'" tppabs="http://www.isi.edu/nsnam/ns/ns-documentation.html">NS Manual</a>for detailed information on header creation and access methods.For the rest of the application and the modified UDP agent description,refer directly to "<a href="mm-app.h" tppabs="http://nile.wpi.edu/NS/Example/mm-app.h">mm-app.h</a>", "<a href="mm-app.cc" tppabs="http://nile.wpi.edu/NS/Example/mm-app.cc">mm-app.cc</a>", "<a href="udp-mm.h" tppabs="http://nile.wpi.edu/NS/Example/udp-mm.h">udp-mm.h</a>" and "<a href="udp-mm.cc.htm" tppabs="http://nile.wpi.edu/NS/Example/udp-mm.cc">udp-mm.cc</a>" files asneeded. <br>&nbsp;</li><li><b>MmApp Sender:</b> The sender uses a timer for scheduling thenext application data packet transmission. We defined the "<fontcolor=BROWN>SendTimer</font>" class derived from the "TimerHandler"class, and wrote its "<font color=BROWN>expire()</font>" memberfunction to call "<font color=RED>send_mm_pkt()</font>" memberfunction of the "MmApp" object. Then, we included an instance of thisobject as a private member of "MmApp" object referred to as "<fontcolor=RED>snd_timer_</font>". Figure 25 shows the "SendTimer"implementation.<p align="center"><img src="fig25.gif" tppabs="http://nile.wpi.edu/NS/Figure/fig25.gif"><br><b>Figure 25.</b> SendTimer Implementation.</p>Before setting this timer, "MmApp" re-calculates the next transmissiontime using the transmission rate associated with the current scalevalue and the size of application data packet that is given in theinput simulation script (or use the default size). The "MmApp" sender,when an ACK application packet arrives from the receiver side, updatesthe scale parameter. <br>&nbsp;</li><li><b>MmApp Receiver:</b> The receiver uses a timer, named "<fontcolor=RED>ack_timer_</font>", to schedule the next application ACKpacket transmission of which the interval is equal to the meanRTT. When receiving an application data packet from the sender, thereceiver counts the number of received packets and also counts thenumber of lost packets using the packet sequence number. When the"ack_timer_" expires, it invokes the "<fontcolor=RED>send_ack_pkt</font>" member function of "MmApp", whichadjusts the scale value looking at the received and lost packetaccounting information, resets the received and lost count to 0, andsends an ACK packet with the adjusted scale value. Note that thereceiver doesn't have any connection establishment or closingmethods. Therefore, starting from the first packet arrival, thereceiver periodically sends ACK packets and never stops (this is abug). <br>&nbsp;</li><li><b>UdpMmAgent:</b> The "UdpMmAgent" is modified from the"UdpAgent" to have the following additional features: (1) writing tothe sending data packet MM header the information received from a"MmApp" (or reading information from the received data packet MMheader and handing it to the "MmApp"), (2) segmentation andre-assembly ("UdpAgent" only implements segmentation), and (3) settingthe priority bit (IPv6) to 15 (max priority) for the "MmApp"packets. <br>&nbsp;</li><li><b>Modify "agent.h": </b> To make the new application and agentrunning with your NS distribution, you should add two methods to"Agent" class as public. In the "command" member function of the"MmApp" class, there defined an "attach-agent" OTcl command. When thiscommand is received from OTcl, "MmApp" tries to attach itself to theunderlying agent. Before the attachment, it invokes the "supportMM()"member function of the underlying agent to check if the underlyingagent support for multimedia transmission (i.e. can it carry data fromapplication to application), and invokes "enableMM()" if it does. Eventhough these two member functions are defined in the "UdpMmAgnet"class, it is not defined in its base ancestor "Agent" class, and thetwo member functions of the general "Agent" class arecalled. Therefore, when trying to compile the code, it will give anerror message. Inserting the two methods as public member functions ofthe "Agent" class (in "agent.h") as follows will solve this problem.<p align="center"><img src="fig26_a.gif" tppabs="http://nile.wpi.edu/NS/Figure/fig26_a.gif"><br><b>Figure 26 (a).</b> Add two member functions to "Agent" class.</p></li><li><b>Modify "app.h":</b> You also need to add an additional member function "recv_msg(int nbytes, const char *msg)" to "Application" class as shown in Figure 26 (b). This member function,which was included in the "Application" class in the old versions ofNS (ns-2.1b4a for sure), is removed from the class in the latestversions (ns-2.1b8a for sure). Our multimedia application was initially written for the ns-2.1.b4a, and therefore requires"Application::recv_msg()" member function for ns-2.1b8a or later versions.<p align="center"><img src="fig26_b.gif" tppabs="http://nile.wpi.edu/NS/Figure/fig26_b.gif"><br><b>Figure 26 (b).</b> Add a member function to "Application" class.</p></li><li><b>Set default values for new parameter in the"ns-default.tcl":</b> After implementing all the parts of theapplication and agent, the last thing to do is to set default valuesfor the newly introduced configurable parameters in the"ns-default.tcl" file. Figure 26 shows an example of setting thedefault values for configurable parameters introduced by "MmApp".<p align="center"><img src="fig27.gif" tppabs="http://nile.wpi.edu/NS/Figure/fig27.gif"><br><b>Figure 27.</b> Default parameter value settings </p></li></ul><br><li><b>Download and Compile</b></li><p>Here is a checklist that should be done before recompiling your NS.</p><ol type=1 start=1><li>Download "<a href="mm-app.h" tppabs="http://nile.wpi.edu/NS/Example/mm-app.h">mm-app.h</a>", "<a     href="mm-app.cc" tppabs="http://nile.wpi.edu/NS/Example/mm-app.cc">mm-app.cc</a>", "<a href="udp-mm.h" tppabs="http://nile.wpi.edu/NS/Example/udp-mm.h">udp-mm.h</a>"     and "<a href="udp-mm.cc.htm" tppabs="http://nile.wpi.edu/NS/Example/udp-mm.cc">udp-mm.cc</a>") to the "ns-2" directory.</li><li>Make sure you registered the new application header by modifying "packet.h" and     "ns-packet.tcl" as shown in Figure 24 (a) and (b). </li><li>Add supportMM() and enableMM() methods to the "Agent" class in "agent.h" as     shown in Figure 26 (a).</li><li>Add recv_msg() method to the "Application" class in "app.h" as shown in     Figure 26 (b).</li><li>Set default values for the newly introduced configurable parameters in "ns-default.tcl"     as described in Figure 27.  Be SURE to complete this last step. Otherwise, all five-scale     rates are initialized to zero unless specified in the input simulation script     (i.e., the test simulation script given below will not transmit any frames).</li></ol><p>Be SURE to complete the last (5th) step.  Otherwise, all five-scale    rates are initialized to zero unless specifically given in the input simulation    script (i.e., the test simulation script given below will not transmit any frames).<p><p>After you've done all things in the checklist, modify your "Makefile" as needed (include "mm-app.o" and "udp-mm.o" in the object file list) and re-compile your NS.  Be SURE to run "make clean" and "make depend" before you re-compile your modified NS, otherwise the newapplication may not transmit any packets.  It is generally a good practice to do"make depend" after you make changes in "Makefile" before a re-compile.</p><br><li><b>Test Simulation</b></li><p>Figure 28 shows a simulation topology and scenario that is used to test "MmApp", and Figure 29 shows the <a href="ex-mm-app.tcl" tppabs="http://nile.wpi.edu/NS/Example/ex-mm-app.tcl">test simulation script</a>. Download this script and test the newly added components.</p><p align="center"><img src="fig28.gif" tppabs="http://nile.wpi.edu/NS/Figure/fig28.gif"><br><b>Figure 28.</b> Test Simulation Topology and Scenario </p><br><p align="center"><a href="ex-mm-app.tcl" tppabs="http://nile.wpi.edu/NS/Example/ex-mm-app.tcl"><img src="fig29.gif" tppabs="http://nile.wpi.edu/NS/Figure/fig29.gif" border=1 alt="ex-mm-app.tcl"></a><br><br><b>Figure 29.</b> "MmApp" Test Simulation Script </p></body></html>

⌨️ 快捷键说明

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