00001 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ 00002 // 00003 // Copyright (c) 2006 Georgia Tech Research Corporation 00004 // 00005 // This program is free software; you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License version 2 as 00007 // published by the Free Software Foundation; 00008 // 00009 // This program is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with this program; if not, write to the Free Software 00016 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 // 00018 // Author: George F. Riley<riley@ece.gatech.edu> 00019 // 00020 00021 // ns3 - On/Off Data Source Application class 00022 // George F. Riley, Georgia Tech, Spring 2007 00023 // Adapted from ApplicationOnOff in GTNetS. 00024 00025 #ifndef __onoff_application_h__ 00026 #define __onoff_application_h__ 00027 00028 #include "ns3/address.h" 00029 #include "ns3/application.h" 00030 #include "ns3/event-id.h" 00031 #include "ns3/ptr.h" 00032 #include "ns3/data-rate.h" 00033 #include "ns3/random-variable.h" 00034 #include "ns3/traced-callback.h" 00035 00036 namespace ns3 { 00037 00038 class Address; 00039 class RandomVariable; 00040 class Socket; 00041 00042 /** 00043 * \ingroup applications 00044 * \defgroup onoff OnOffApplication 00045 * 00046 * This traffic generator follows an On/Off pattern: after 00047 * Application::StartApplication 00048 * is called, "On" and "Off" states alternate. The duration of each of 00049 * these states is determined with the onTime and the offTime random 00050 * variables. During the "Off" state, no traffic is generated. 00051 * During the "On" state, cbr traffic is generated. This cbr traffic is 00052 * characterized by the specified "data rate" and "packet size". 00053 */ 00054 /** 00055 * \ingroup onoff 00056 * 00057 * \brief Generate traffic to a single destination according to an 00058 * OnOff pattern. 00059 * 00060 * This traffic generator follows an On/Off pattern: after 00061 * Application::StartApplication 00062 * is called, "On" and "Off" states alternate. The duration of each of 00063 * these states is determined with the onTime and the offTime random 00064 * variables. During the "Off" state, no traffic is generated. 00065 * During the "On" state, cbr traffic is generated. This cbr traffic is 00066 * characterized by the specified "data rate" and "packet size". 00067 */ 00068 class OnOffApplication : public Application 00069 { 00070 public: 00071 static TypeId GetTypeId (void); 00072 00073 OnOffApplication (); 00074 00075 virtual ~OnOffApplication(); 00076 00077 void SetMaxBytes(uint32_t maxBytes); 00078 00079 protected: 00080 virtual void DoDispose (void); 00081 private: 00082 // inherited from Application base class. 00083 virtual void StartApplication (void); // Called at time specified by Start 00084 virtual void StopApplication (void); // Called at time specified by Stop 00085 00086 //helpers 00087 void CancelEvents (); 00088 00089 void Construct (Ptr<Node> n, 00090 const Address &remote, 00091 std::string tid, 00092 const RandomVariable& ontime, 00093 const RandomVariable& offtime, 00094 uint32_t size); 00095 00096 00097 // Event handlers 00098 void StartSending(); 00099 void StopSending(); 00100 void SendPacket(); 00101 00102 Ptr<Socket> m_socket; // Associated socket 00103 Address m_peer; // Peer address 00104 bool m_connected; // True if connected 00105 RandomVariable m_onTime; // rng for On Time 00106 RandomVariable m_offTime; // rng for Off Time 00107 DataRate m_cbrRate; // Rate that data is generated 00108 uint32_t m_pktSize; // Size of packets 00109 RandomVariable m_jitter; // CBR interval jitter between sends 00110 uint32_t m_residualBits; // Number of generated, but not sent, bits 00111 Time m_lastStartTime;// Time last packet sent 00112 uint32_t m_maxBytes; // Limit total number of bytes sent 00113 uint32_t m_totBytes; // Total bytes sent so far 00114 EventId m_startStopEvent; // Event id for next start or stop event 00115 EventId m_sendEvent; // Eventid of pending "send packet" event 00116 bool m_sending; // True if currently in sending state 00117 TypeId m_tid; 00118 TracedCallback<Ptr<const Packet> > m_txTrace; 00119 00120 private: 00121 void ScheduleNextTx(); 00122 void ScheduleStartEvent(); 00123 void ScheduleStopEvent(); 00124 void ConnectionSucceeded(Ptr<Socket>); 00125 void ConnectionFailed(Ptr<Socket>); 00126 void Ignore(Ptr<Socket>); 00127 }; 00128 00129 } // namespace ns3 00130 00131 #endif 00132