|
craigdo@1496
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
|
craigdo@1496
|
2 |
/*
|
|
craigdo@1496
|
3 |
* Copyright 2007 University of Washington
|
|
craigdo@1496
|
4 |
*
|
|
craigdo@1496
|
5 |
* This program is free software; you can redistribute it and/or modify
|
|
craigdo@1496
|
6 |
* it under the terms of the GNU General Public License version 2 as
|
|
craigdo@1496
|
7 |
* published by the Free Software Foundation;
|
|
craigdo@1496
|
8 |
*
|
|
craigdo@1496
|
9 |
* This program is distributed in the hope that it will be useful,
|
|
craigdo@1496
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
craigdo@1496
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
craigdo@1496
|
12 |
* GNU General Public License for more details.
|
|
craigdo@1496
|
13 |
*
|
|
craigdo@1496
|
14 |
* You should have received a copy of the GNU General Public License
|
|
craigdo@1496
|
15 |
* along with this program; if not, write to the Free Software
|
|
craigdo@1496
|
16 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
craigdo@1496
|
17 |
*/
|
|
craigdo@1496
|
18 |
|
|
craigdo@1496
|
19 |
#ifndef __UDP_ECHO_CLIENT_H__
|
|
craigdo@1496
|
20 |
#define __UDP_ECHO_CLIENT_H__
|
|
craigdo@1496
|
21 |
|
|
craigdo@1496
|
22 |
#include "ns3/application.h"
|
|
craigdo@1496
|
23 |
#include "ns3/event-id.h"
|
|
craigdo@1496
|
24 |
#include "ns3/ptr.h"
|
|
mathieu@2764
|
25 |
#include "ns3/ipv4-address.h"
|
|
wilsonwk@4710
|
26 |
#include "ns3/traced-callback.h"
|
|
craigdo@1496
|
27 |
|
|
craigdo@1496
|
28 |
namespace ns3 {
|
|
craigdo@1496
|
29 |
|
|
craigdo@1496
|
30 |
class Socket;
|
|
craigdo@1496
|
31 |
class Packet;
|
|
craigdo@1496
|
32 |
|
|
mathieu@2962
|
33 |
/**
|
|
tomh@3264
|
34 |
* \ingroup udpecho
|
|
mathieu@2962
|
35 |
* \brief A Udp Echo client
|
|
mathieu@2962
|
36 |
*
|
|
mathieu@2962
|
37 |
* Every packet sent should be returned by the server and received here.
|
|
mathieu@2962
|
38 |
*/
|
|
craigdo@1496
|
39 |
class UdpEchoClient : public Application
|
|
craigdo@1496
|
40 |
{
|
|
craigdo@1496
|
41 |
public:
|
|
mathieu@2494
|
42 |
static TypeId GetTypeId (void);
|
|
mathieu@2494
|
43 |
|
|
mathieu@2494
|
44 |
UdpEchoClient ();
|
|
craigdo@1496
|
45 |
|
|
craigdo@1496
|
46 |
virtual ~UdpEchoClient ();
|
|
craigdo@1496
|
47 |
|
|
mathieu@2766
|
48 |
void SetRemote (Ipv4Address ip, uint16_t port);
|
|
mathieu@2766
|
49 |
|
|
craigdo@4577
|
50 |
/**
|
|
craigdo@4577
|
51 |
* Set the data size of the packet (the number of bytes that are sent as data
|
|
craigdo@4577
|
52 |
* to the server). The contents of the data are set to unspecified (don't
|
|
craigdo@4577
|
53 |
* care) by this call.
|
|
craigdo@4577
|
54 |
*
|
|
mathieu@4645
|
55 |
* \warning If you have set the fill data for the echo client using one of the
|
|
craigdo@4577
|
56 |
* SetFill calls, this will undo those effects.
|
|
craigdo@4577
|
57 |
*
|
|
craigdo@4577
|
58 |
* \param dataSize The size of the echo data you want to sent.
|
|
craigdo@4577
|
59 |
*/
|
|
craigdo@4577
|
60 |
void SetDataSize (uint32_t dataSize);
|
|
craigdo@4577
|
61 |
|
|
craigdo@4577
|
62 |
/**
|
|
craigdo@4577
|
63 |
* Get the number of data bytes that will be sent to the server.
|
|
craigdo@4577
|
64 |
*
|
|
mathieu@4645
|
65 |
* \warning The number of bytes may be modified by calling any one of the
|
|
craigdo@4577
|
66 |
* SetFill methods. If you have called SetFill, then the number of
|
|
craigdo@4577
|
67 |
* data bytes will correspond to the size of an initialized data buffer.
|
|
craigdo@4577
|
68 |
* If you have not called a SetFill method, the number of data bytes will
|
|
craigdo@4577
|
69 |
* correspond to the number of don't care bytes that will be sent.
|
|
craigdo@4577
|
70 |
*
|
|
craigdo@4577
|
71 |
* \returns The number of data bytes.
|
|
craigdo@4577
|
72 |
*/
|
|
craigdo@4577
|
73 |
uint32_t GetDataSize (void) const;
|
|
craigdo@4577
|
74 |
|
|
craigdo@4577
|
75 |
/**
|
|
craigdo@4577
|
76 |
* Set the data fill of the packet (what is sent as data to the server) to
|
|
craigdo@4577
|
77 |
* the zero-terminated contents of the fill string string.
|
|
craigdo@4577
|
78 |
*
|
|
mathieu@4645
|
79 |
* \warning The size of resulting echo packets will be automatically adjusted
|
|
craigdo@4577
|
80 |
* to reflect the size of the fill string -- this means that the PacketSize
|
|
craigdo@4577
|
81 |
* attribute may be changed as a result of this call.
|
|
craigdo@4577
|
82 |
*
|
|
craigdo@4577
|
83 |
* \param fill The string to use as the actual echo data bytes.
|
|
craigdo@4577
|
84 |
*/
|
|
craigdo@4577
|
85 |
void SetFill (std::string fill);
|
|
craigdo@4577
|
86 |
|
|
craigdo@4577
|
87 |
/**
|
|
craigdo@4577
|
88 |
* Set the data fill of the packet (what is sent as data to the server) to
|
|
craigdo@4577
|
89 |
* the repeated contents of the fill byte. i.e., the fill byte will be
|
|
craigdo@4577
|
90 |
* used to initialize the contents of the data packet.
|
|
craigdo@4577
|
91 |
*
|
|
mathieu@4645
|
92 |
* \warning The size of resulting echo packets will be automatically adjusted
|
|
craigdo@4577
|
93 |
* to reflect the dataSize parameter -- this means that the PacketSize
|
|
craigdo@4577
|
94 |
* attribute may be changed as a result of this call.
|
|
craigdo@4577
|
95 |
*
|
|
craigdo@4577
|
96 |
* \param fill The byte to be repeated in constructing the packet data..
|
|
craigdo@4577
|
97 |
* \param dataSize The desired size of the resulting echo packet data.
|
|
craigdo@4577
|
98 |
*/
|
|
craigdo@4577
|
99 |
void SetFill (uint8_t fill, uint32_t dataSize);
|
|
craigdo@4577
|
100 |
|
|
craigdo@4577
|
101 |
/**
|
|
craigdo@4577
|
102 |
* Set the data fill of the packet (what is sent as data to the server) to
|
|
craigdo@4577
|
103 |
* the contents of the fill buffer, repeated as many times as is required.
|
|
craigdo@4577
|
104 |
*
|
|
craigdo@4577
|
105 |
* Initializing the packet to the contents of a provided single buffer is
|
|
craigdo@4577
|
106 |
* accomplished by setting the fillSize set to your desired dataSize
|
|
craigdo@4577
|
107 |
* (and providing an appropriate buffer).
|
|
craigdo@4577
|
108 |
*
|
|
mathieu@4645
|
109 |
* \warning The size of resulting echo packets will be automatically adjusted
|
|
craigdo@4577
|
110 |
* to reflect the dataSize parameter -- this means that the PacketSize
|
|
craigdo@4577
|
111 |
* attribute of the Application may be changed as a result of this call.
|
|
craigdo@4577
|
112 |
*
|
|
craigdo@4577
|
113 |
* \param fill The fill pattern to use when constructing packets.
|
|
craigdo@4577
|
114 |
* \param fillSize The number of bytes in the provided fill pattern.
|
|
craigdo@4577
|
115 |
* \param dataSize The desired size of the final echo data.
|
|
craigdo@4577
|
116 |
*/
|
|
craigdo@4577
|
117 |
void SetFill (uint8_t *fill, uint32_t fillSize, uint32_t dataSize);
|
|
craigdo@4577
|
118 |
|
|
craigdo@1496
|
119 |
protected:
|
|
craigdo@1496
|
120 |
virtual void DoDispose (void);
|
|
craigdo@1496
|
121 |
|
|
craigdo@1496
|
122 |
private:
|
|
craigdo@1496
|
123 |
|
|
craigdo@1496
|
124 |
virtual void StartApplication (void);
|
|
craigdo@1496
|
125 |
virtual void StopApplication (void);
|
|
craigdo@1496
|
126 |
|
|
craigdo@1496
|
127 |
void ScheduleTransmit (Time dt);
|
|
craigdo@1496
|
128 |
void Send (void);
|
|
craigdo@1496
|
129 |
|
|
tomh@3098
|
130 |
void HandleRead (Ptr<Socket> socket);
|
|
craigdo@1500
|
131 |
|
|
craigdo@1496
|
132 |
uint32_t m_count;
|
|
craigdo@1496
|
133 |
Time m_interval;
|
|
craigdo@1496
|
134 |
uint32_t m_size;
|
|
craigdo@1496
|
135 |
|
|
craigdo@4577
|
136 |
uint32_t m_dataSize;
|
|
craigdo@4577
|
137 |
uint8_t *m_data;
|
|
craigdo@4577
|
138 |
|
|
craigdo@1496
|
139 |
uint32_t m_sent;
|
|
craigdo@1496
|
140 |
Ptr<Socket> m_socket;
|
|
mathieu@2494
|
141 |
Ipv4Address m_peerAddress;
|
|
mathieu@2494
|
142 |
uint16_t m_peerPort;
|
|
craigdo@1496
|
143 |
EventId m_sendEvent;
|
|
wilsonwk@4710
|
144 |
/// Callbacks for tracing the packet Tx events
|
|
wilsonwk@4710
|
145 |
TracedCallback<Ptr<const Packet> > m_txTrace;
|
|
craigdo@1496
|
146 |
};
|
|
craigdo@1496
|
147 |
|
|
craigdo@1496
|
148 |
} // namespace ns3
|
|
craigdo@1496
|
149 |
|
|
craigdo@1496
|
150 |
#endif // __UDP_ECHO_CLIENT_H__
|
|
craigdo@1496
|
151 |
|