OLD | NEW |
(Empty) | |
| 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 /* |
| 3 * Copyright 2012 |
| 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 |
| 19 #ifndef TCP_ECHO_CLIENT |
| 20 #define TCP_ECHO_CLIENT |
| 21 |
| 22 |
| 23 #include "ns3/application.h" |
| 24 #include "ns3/event-id.h" |
| 25 #include "ns3/ptr.h" |
| 26 #include "ns3/ipv4-address.h" |
| 27 #include "ns3/ipv6-address.h" |
| 28 #include "ns3/traced-callback.h" |
| 29 |
| 30 namespace ns3 { |
| 31 |
| 32 class Socket; |
| 33 class Packet; |
| 34 |
| 35 /** |
| 36 * \ingroup tcpecho |
| 37 * \brief A Tcp Echo client |
| 38 * |
| 39 * Every packet sent should be returned by the server and received here. |
| 40 */ |
| 41 class TcpEchoClient : public Application |
| 42 { |
| 43 public: |
| 44 static TypeId GetTypeId (void); |
| 45 |
| 46 TcpEchoClient (); |
| 47 |
| 48 virtual ~TcpEchoClient (); |
| 49 |
| 50 /** |
| 51 * \param ip destination address |
| 52 * \param port destination port |
| 53 */ |
| 54 void SetRemote (Address ip, uint16_t port); |
| 55 |
| 56 /** |
| 57 * Set the data size of the packet (the number of bytes that are sent as data |
| 58 * to the server). The contents of the data are set to unspecified (don't |
| 59 * care) by this call. |
| 60 * |
| 61 * \warning If you have set the fill data for the echo client using one of the |
| 62 * SetFill calls, this will undo those effects. |
| 63 * |
| 64 * \param dataSize The size of the echo data you want to sent. |
| 65 */ |
| 66 void SetDataSize (uint32_t dataSize); |
| 67 |
| 68 /** |
| 69 * Get the number of data bytes that will be sent to the server. |
| 70 * |
| 71 * \warning The number of bytes may be modified by calling any one of the |
| 72 * SetFill methods. If you have called SetFill, then the number of |
| 73 * data bytes will correspond to the size of an initialized data buffer. |
| 74 * If you have not called a SetFill method, the number of data bytes will |
| 75 * correspond to the number of don't care bytes that will be sent. |
| 76 * |
| 77 * \returns The number of data bytes. |
| 78 */ |
| 79 uint32_t GetDataSize (void) const; |
| 80 |
| 81 /** |
| 82 * Set the data fill of the packet (what is sent as data to the server) to |
| 83 * the zero-terminated contents of the fill string string. |
| 84 * |
| 85 * \warning The size of resulting echo packets will be automatically adjusted |
| 86 * to reflect the size of the fill string -- this means that the PacketSize |
| 87 * attribute may be changed as a result of this call. |
| 88 * |
| 89 * \param fill The string to use as the actual echo data bytes. |
| 90 */ |
| 91 void SetFill (std::string fill); |
| 92 |
| 93 /** |
| 94 * Set the data fill of the packet (what is sent as data to the server) to |
| 95 * the repeated contents of the fill byte. i.e., the fill byte will be |
| 96 * used to initialize the contents of the data packet. |
| 97 * |
| 98 * \warning The size of resulting echo packets will be automatically adjusted |
| 99 * to reflect the dataSize parameter -- this means that the PacketSize |
| 100 * attribute may be changed as a result of this call. |
| 101 * |
| 102 * \param fill The byte to be repeated in constructing the packet data.. |
| 103 * \param dataSize The desired size of the resulting echo packet data. |
| 104 */ |
| 105 void SetFill (uint8_t fill, uint32_t dataSize); |
| 106 |
| 107 /** |
| 108 * Set the data fill of the packet (what is sent as data to the server) to |
| 109 * the contents of the fill buffer, repeated as many times as is required. |
| 110 * |
| 111 * Initializing the packet to the contents of a provided single buffer is |
| 112 * accomplished by setting the fillSize set to your desired dataSize |
| 113 * (and providing an appropriate buffer). |
| 114 * |
| 115 * \warning The size of resulting echo packets will be automatically adjusted |
| 116 * to reflect the dataSize parameter -- this means that the PacketSize |
| 117 * attribute of the Application may be changed as a result of this call. |
| 118 * |
| 119 * \param fill The fill pattern to use when constructing packets. |
| 120 * \param fillSize The number of bytes in the provided fill pattern. |
| 121 * \param dataSize The desired size of the final echo data. |
| 122 */ |
| 123 void SetFill (uint8_t *fill, uint32_t fillSize, uint32_t dataSize); |
| 124 |
| 125 // mainly to the automated test |
| 126 uint32_t GetPacketsSent (void) { return m_sent; }; |
| 127 uint64_t GetBytesSent (void) { return m_bytesSent; }; |
| 128 uint32_t GetPacketsReceivedBack (void) { return m_recvBack; }; |
| 129 uint64_t GetBytesReceivedBack (void) { return m_bytesRecvBack; }; |
| 130 |
| 131 protected: |
| 132 virtual void DoDispose (void); |
| 133 |
| 134 private: |
| 135 |
| 136 virtual void StartApplication (void); |
| 137 virtual void StopApplication (void); |
| 138 |
| 139 void ScheduleTransmit (Time dt); |
| 140 void Send (void); |
| 141 |
| 142 void ReceivePacket (Ptr<Socket> socket); |
| 143 |
| 144 uint32_t m_count; |
| 145 Time m_interval; |
| 146 uint32_t m_size; |
| 147 |
| 148 uint32_t m_dataSize; |
| 149 uint8_t *m_data; |
| 150 |
| 151 uint32_t m_sent; |
| 152 uint64_t m_bytesSent; |
| 153 uint32_t m_recvBack; |
| 154 uint64_t m_bytesRecvBack; |
| 155 Ptr<Socket> m_socket; |
| 156 Address m_peerAddress; |
| 157 uint16_t m_peerPort; |
| 158 EventId m_sendEvent; |
| 159 /// Callbacks for tracing the packet Tx events |
| 160 TracedCallback<Ptr<const Packet> > m_txTrace; |
| 161 }; |
| 162 |
| 163 } // namespace ns3 |
| 164 |
| 165 |
| 166 #endif /* TCP_ECHO_CLIENT */ |
OLD | NEW |