1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
3 * Copyright 2007 University of Washington
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;
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.
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
19 #ifndef __UDP_ECHO_CLIENT_H__
20 #define __UDP_ECHO_CLIENT_H__
22 #include "ns3/application.h"
23 #include "ns3/event-id.h"
25 #include "ns3/ipv4-address.h"
26 #include "ns3/traced-callback.h"
35 * \brief A Udp Echo client
37 * Every packet sent should be returned by the server and received here.
39 class UdpEchoClient : public Application
42 static TypeId GetTypeId (void);
46 virtual ~UdpEchoClient ();
48 void SetRemote (Ipv4Address ip, uint16_t port);
51 * Set the data size of the packet (the number of bytes that are sent as data
52 * to the server). The contents of the data are set to unspecified (don't
55 * \warning If you have set the fill data for the echo client using one of the
56 * SetFill calls, this will undo those effects.
58 * \param dataSize The size of the echo data you want to sent.
60 void SetDataSize (uint32_t dataSize);
63 * Get the number of data bytes that will be sent to the server.
65 * \warning The number of bytes may be modified by calling any one of the
66 * SetFill methods. If you have called SetFill, then the number of
67 * data bytes will correspond to the size of an initialized data buffer.
68 * If you have not called a SetFill method, the number of data bytes will
69 * correspond to the number of don't care bytes that will be sent.
71 * \returns The number of data bytes.
73 uint32_t GetDataSize (void) const;
76 * Set the data fill of the packet (what is sent as data to the server) to
77 * the zero-terminated contents of the fill string string.
79 * \warning The size of resulting echo packets will be automatically adjusted
80 * to reflect the size of the fill string -- this means that the PacketSize
81 * attribute may be changed as a result of this call.
83 * \param fill The string to use as the actual echo data bytes.
85 void SetFill (std::string fill);
88 * Set the data fill of the packet (what is sent as data to the server) to
89 * the repeated contents of the fill byte. i.e., the fill byte will be
90 * used to initialize the contents of the data packet.
92 * \warning The size of resulting echo packets will be automatically adjusted
93 * to reflect the dataSize parameter -- this means that the PacketSize
94 * attribute may be changed as a result of this call.
96 * \param fill The byte to be repeated in constructing the packet data..
97 * \param dataSize The desired size of the resulting echo packet data.
99 void SetFill (uint8_t fill, uint32_t dataSize);
102 * Set the data fill of the packet (what is sent as data to the server) to
103 * the contents of the fill buffer, repeated as many times as is required.
105 * Initializing the packet to the contents of a provided single buffer is
106 * accomplished by setting the fillSize set to your desired dataSize
107 * (and providing an appropriate buffer).
109 * \warning The size of resulting echo packets will be automatically adjusted
110 * to reflect the dataSize parameter -- this means that the PacketSize
111 * attribute of the Application may be changed as a result of this call.
113 * \param fill The fill pattern to use when constructing packets.
114 * \param fillSize The number of bytes in the provided fill pattern.
115 * \param dataSize The desired size of the final echo data.
117 void SetFill (uint8_t *fill, uint32_t fillSize, uint32_t dataSize);
120 virtual void DoDispose (void);
124 virtual void StartApplication (void);
125 virtual void StopApplication (void);
127 void ScheduleTransmit (Time dt);
130 void HandleRead (Ptr<Socket> socket);
140 Ptr<Socket> m_socket;
141 Ipv4Address m_peerAddress;
144 /// Callbacks for tracing the packet Tx events
145 TracedCallback<Ptr<const Packet> > m_txTrace;
150 #endif // __UDP_ECHO_CLIENT_H__