OLD | NEW |
(Empty) | |
| 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 /* |
| 3 * Copyright (c) 2014 Magister Solutions Ltd |
| 4 * |
| 5 * This program is free software; you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 2 as |
| 7 * published by the Free Software Foundation; |
| 8 * |
| 9 * This program is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. |
| 13 * |
| 14 * You should have received a copy of the GNU General Public License |
| 15 * along with this program; if not, write to the Free Software |
| 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 * |
| 18 * Author: Sami Rantanen <sami.rantanen@magister.fi> |
| 19 */ |
| 20 |
| 21 #ifndef CBR_APPLICATION_H |
| 22 #define CBR_APPLICATION_H |
| 23 |
| 24 #include <ns3/address.h> |
| 25 #include <ns3/application.h> |
| 26 #include <ns3/event-id.h> |
| 27 #include <ns3/ptr.h> |
| 28 #include <ns3/traced-callback.h> |
| 29 #include <ns3/nstime.h> |
| 30 |
| 31 namespace ns3 { |
| 32 |
| 33 class Socket; |
| 34 |
| 35 /** |
| 36 * \ingroup traffic |
| 37 * |
| 38 * \brief Generate traffic to a single destination according to a CBR pattern. |
| 39 * |
| 40 * This traffic generator follows a CBR pattern: after CbrApplication::StartAppli
cation |
| 41 * is called, CBR sending starts. The sending continues as long as applications r
uns. |
| 42 * This CBR traffic is characterized by the specified "data rate", "packet size"
and "interval". |
| 43 * |
| 44 * Note: When an application is started, the first packet transmission |
| 45 * occurs after given interval. The application sends a packet right after previo
us packet, |
| 46 * if interval is shorter than time needed for sending the packet. |
| 47 * |
| 48 * If the underlying socket type supports broadcast, this application |
| 49 * will automatically enable the SetAllowBroadcast(true) socket option. |
| 50 */ |
| 51 class CbrApplication : public Application |
| 52 { |
| 53 public: |
| 54 static TypeId GetTypeId (void); |
| 55 |
| 56 /// Constructor for Cbr application. |
| 57 CbrApplication (); |
| 58 |
| 59 /// Destructor for Cbr application. |
| 60 virtual ~CbrApplication (); |
| 61 |
| 62 /// Get the pointer to associated socket. |
| 63 Ptr<Socket> GetSocket (void) const; |
| 64 |
| 65 /** |
| 66 * \brief Get the number of sent bytes |
| 67 * \return the number of sent bytes |
| 68 */ |
| 69 uint32_t GetSent (void) const; |
| 70 |
| 71 /** |
| 72 * \brief Get the destination address of the application |
| 73 * \return the destination address |
| 74 */ |
| 75 const Address GetRemote (void) const; |
| 76 |
| 77 protected: |
| 78 /// Do dispose actions. |
| 79 virtual void DoDispose (void); |
| 80 private: |
| 81 Ptr<Socket> m_socket; // Associated socket |
| 82 Address m_peer; // Peer address |
| 83 Time m_interval; // Time interval for cbr sending |
| 84 uint32_t m_pktSize; // Size of packets |
| 85 Time m_lastStartTime; // Time last packet sent |
| 86 uint32_t m_totTxBytes; // Total bytes sent so far |
| 87 EventId m_sendEvent; // Event id of pending "send packet" event |
| 88 TypeId m_tid; |
| 89 bool m_isStatisticsTagsEnabled; ///< `EnableStatisticsTags` attrib
ute. |
| 90 TracedCallback<Ptr<const Packet> > m_txTrace; |
| 91 |
| 92 // inherited from Application base class. |
| 93 virtual void StartApplication (void); // Called at time specified by Start |
| 94 virtual void StopApplication (void); // Called at time specified by Stop |
| 95 |
| 96 /// Create and send packet by scheduling next TX event. |
| 97 void SendPacket (); |
| 98 |
| 99 /// schedule next packet sending |
| 100 void ScheduleNextTx (); |
| 101 |
| 102 /** |
| 103 * Callback method to handle connection succeeded events |
| 104 * |
| 105 * \param socket Pointer to socket. |
| 106 */ |
| 107 void ConnectionSucceeded (Ptr<Socket> socket); |
| 108 |
| 109 /** |
| 110 * Callback method to handle connection failed events |
| 111 * |
| 112 * \param socket Pointer to socket. |
| 113 */ |
| 114 void ConnectionFailed (Ptr<Socket> socket); |
| 115 }; |
| 116 |
| 117 } // namespace ns3 |
| 118 |
| 119 #endif /* CBR_APPLICATION_H */ |
OLD | NEW |