A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
three-gpp-http-client.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2013 Magister Solutions
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Budiarto Herman <budiarto.herman@magister.fi>
18 *
19 */
20
21#ifndef THREE_GPP_HTTP_CLIENT_H
22#define THREE_GPP_HTTP_CLIENT_H
23
25
26#include <ns3/address.h>
27#include <ns3/application.h>
28#include <ns3/traced-callback.h>
29
30namespace ns3
31{
32
33class Socket;
34class Packet;
35class ThreeGppHttpVariables;
36
37/**
38 * \ingroup applications
39 * \defgroup http ThreeGppHttpClientServer
40 *
41 * This traffic generator simulates web browsing traffic using the Hypertext
42 * Transfer Protocol (HTTP). It consists of one or more ThreeGppHttpClient
43 * applications which connect to an ThreeGppHttpServer application. The client
44 * models a web browser which requests web pages to the server. The server
45 * is then responsible to serve the web pages as requested. Please refer to
46 * ThreeGppHttpClientHelper and ThreeGppHttpServerHelper for usage instructions.
47 *
48 * Technically speaking, the client transmits *request objects* to demand a
49 * service from the server. Depending on the type of request received, the
50 * server transmits either:
51 * - a *main object*, i.e., the HTML file of the web page; or
52 * - an *embedded object*, e.g., an image referenced by the HTML file.
53 *
54 * A major portion of the traffic pattern is *reading time*, which does not
55 * generate any traffic. Because of this, one may need to simulate a good
56 * number of clients and/or sufficiently long simulation duration in order to
57 * generate any significant traffic in the system.
58 *
59 * Many aspects of the traffic are randomly determined by ThreeGppHttpVariables.
60 * These characteristics are based on a legacy 3GPP specification. The description
61 * can be found in the following references:
62 * - 3GPP TR 25.892, "Feasibility Study for Orthogonal Frequency Division
63 * Multiplexing (OFDM) for UTRAN enhancement"
64 * - IEEE 802.16m, "Evaluation Methodology Document (EMD)",
65 * IEEE 802.16m-08/004r5, July 2008.
66 * - NGMN Alliance, "NGMN Radio Access Performance Evaluation Methodology",
67 * v1.0, January 2008.
68 * - 3GPP2-TSGC5, "HTTP, FTP and TCP models for 1xEV-DV simulations", 2001.
69 */
70
71/**
72 * \ingroup http
73 * Model application which simulates the traffic of a web browser. This
74 * application works in conjunction with an ThreeGppHttpServer application.
75 *
76 * In summary, the application works as follows.
77 * 1. Upon start, it opens a connection to the destination web server
78 * (ThreeGppHttpServer).
79 * 2. After the connection is established, the application immediately requests
80 * a *main object* from the server by sending a request packet.
81 * 3. After receiving a main object (which can take some time if it consists of
82 * several packets), the application "parses" the main object.
83 * 4. The parsing takes a short time (randomly determined) to determine the
84 * number of *embedded objects* (also randomly determined) in the web page.
85 * - If at least one embedded object is determined, the application requests
86 * the first embedded object from the server. The request for the next
87 * embedded object follows after the previous embedded object has been
88 * completely received.
89 * - If there is no more embedded object to request, the application enters
90 * the *reading time*.
91 * 5. Reading time is a long delay (again, randomly determined) where the
92 * application does not induce any network traffic, thus simulating the user
93 * reading the downloaded web page.
94 * 6. After the reading time is finished, the process repeats to step #2.
95 *
96 * The client models HTTP *persistent connection*, i.e., HTTP 1.1, where the
97 * connection to the server is maintained and used for transmitting and receiving
98 * all objects.
99 *
100 * Each request by default has a constant size of 350 bytes. A ThreeGppHttpHeader
101 * is attached to each request packet. The header contains information
102 * such as the content type requested (either main object or embedded object)
103 * and the timestamp when the packet is transmitted (which will be used to
104 * compute the delay and RTT of the packet).
105 */
107{
108 public:
109 /**
110 * Creates a new instance of HTTP client application.
111 *
112 * After creation, the application must be further configured through
113 * attributes. To avoid having to do this process manually, please use
114 * ThreeGppHttpClientHelper.
115 */
117
118 /**
119 * Returns the object TypeId.
120 * \return The object TypeId.
121 */
122 static TypeId GetTypeId();
123
124 /**
125 * Returns a pointer to the associated socket.
126 * \return Pointer to the associated socket.
127 */
128 Ptr<Socket> GetSocket() const;
129
130 /// The possible states of the application.
132 {
133 /// Before StartApplication() is invoked.
135 /// Sent the server a connection request and waiting for the server to be accept it.
137 /// Sent the server a request for a main object and waiting to receive the packets.
139 /// Parsing a main object that has just been received.
141 /// Sent the server a request for an embedded object and waiting to receive the packets.
143 /// User reading a web page that has just been received.
145 /// After StopApplication() is invoked.
146 STOPPED
147 };
148
149 /**
150 * Returns the current state of the application.
151 * \return The current state of the application.
152 */
153 State_t GetState() const;
154
155 /**
156 * Returns the current state of the application in string format.
157 * \return The current state of the application in string format.
158 */
159 std::string GetStateString() const;
160
161 /**
162 * Returns the given state in string format.
163 * \param state An arbitrary state of an application.
164 * \return The given state equivalently expressed in string format.
165 */
166 static std::string GetStateString(State_t state);
167
168 /**
169 * Common callback signature for `ConnectionEstablished`, `RxMainObject`, and
170 * `RxEmbeddedObject` trace sources.
171 * \param httpClient Pointer to this instance of ThreeGppHttpClient,
172 * which is where the trace originated.
173 */
175
176 /**
177 * Callback signature for `RxPage` trace sources.
178 * \param httpClient Pointer to this instance of ThreeGppHttpClient,
179 * which is where the trace originated.
180 * \param time Elapsed time from the start to the end of the request.
181 * \param numObjects Number of objects downloaded, including main and
182 * embedded objects.
183 * \param numBytes Total number of bytes included in the page.
184 */
186 const Time& time,
187 uint32_t numObjects,
188 uint32_t numBytes);
189
190 protected:
191 void DoDispose() override;
192
193 private:
194 void StartApplication() override;
195 void StopApplication() override;
196
197 // SOCKET CALLBACK METHODS
198
199 /**
200 * Invoked when a connection is established successfully on #m_socket. This
201 * triggers a request for a main object.
202 * \param socket Pointer to the socket where the event originates from.
203 */
205 /**
206 * Invoked when #m_socket cannot establish a connection with the web server.
207 * Simulation will stop and error will be raised.
208 * \param socket Pointer to the socket where the event originates from.
209 */
211 /**
212 * Invoked when connection between #m_socket and the web sever is terminated.
213 * Error will be logged, but simulation continues.
214 * \param socket Pointer to the socket where the event originates from.
215 */
216 void NormalCloseCallback(Ptr<Socket> socket);
217 /**
218 * Invoked when connection between #m_socket and the web sever is terminated.
219 * Error will be logged, but simulation continues.
220 * \param socket Pointer to the socket where the event originates from.
221 */
222 void ErrorCloseCallback(Ptr<Socket> socket);
223 /**
224 * Invoked when #m_socket receives some packet data. Fires the `Rx` trace
225 * source and triggers ReceiveMainObject() or ReceiveEmbeddedObject().
226 * \param socket Pointer to the socket where the event originates from.
227 */
229
230 // CONNECTION-RELATED METHOD
231
232 /**
233 * Initialize #m_socket to connect to the destination web server at
234 * #m_remoteServerAddress and #m_remoteServerPort and set up callbacks to
235 * listen to its event. Invoked upon the start of the application.
236 */
237 void OpenConnection();
238
239 // TX-RELATED METHODS
240
241 /**
242 * Send a request object for a main object to the destination web server.
243 * The size of the request packet is randomly determined by HttpVariables and
244 * is assumed to be smaller than 536 bytes. Fires the `TxMainObjectRequest`
245 * trace source.
246 *
247 * The method is invoked after a connection is established or after a
248 * reading time has elapsed.
249 */
250 void RequestMainObject();
251 /**
252 * Send a request object for an embedded object to the destination web
253 * server. The size of the request packet is randomly determined by
254 * ThreeGppHttpVariables and is assumed to be smaller than 536 bytes. Fires the
255 * `TxEmbeddedObjectRequest` trace source.
256 */
258
259 // RX-RELATED METHODS
260
261 /**
262 * Receive a packet of main object from the destination web server. Fires the
263 * `RxMainObjectPacket` trace source.
264 *
265 * A main object may come from more than one packets. This is determined by
266 * comparing the content length specified in the ThreeGppHttpHeader of the packet and
267 * the actual packet size. #m_objectBytesToBeReceived keeps track of the
268 * number of bytes that has been received.
269 *
270 * If the received packet is not the last packet of the object, then the
271 * method simply quits, expecting it to be invoked again when the next packet
272 * comes.
273 *
274 * If the received packet is the last packet of the object, then the method
275 * fires the `RxMainObject`, `RxDelay`, and `RxRtt` trace sources. The client
276 * then triggers EnterParsingTime().
277 *
278 * \param packet The received packet.
279 * \param from Address of the sender.
280 */
281 void ReceiveMainObject(Ptr<Packet> packet, const Address& from);
282 /**
283 * Receive a packet of embedded object from the destination web server. Fires
284 * the `RxEmbeddedObjectPacket` trace source.
285 *
286 * An embedded object may come from more than one packets. This is determined
287 * by comparing the content length specified in the TheeGppHttpHeader of the packet and
288 * the actual packet size. #m_objectBytesToBeReceived keeps track of the
289 * number of bytes that has been received.
290 *
291 * If the received packet is not the last packet of the object, then the
292 * method simply quits, expecting it to be invoked again when the next packet
293 * comes.
294 *
295 * If the received packet is the last packet of the object, then the method
296 * fires the `RxEmbeddedObject`, `RxDelay`, and `RxRtt` trace sources.
297 * Depending on the number of embedded objects remaining
298 * (#m_embeddedObjectsToBeRequested) the client can either trigger
299 * RequestEmbeddedObject() or EnterReadingTime().
300 *
301 * \param packet The received packet.
302 * \param from Address of the sender.
303 */
304 void ReceiveEmbeddedObject(Ptr<Packet> packet, const Address& from);
305 /**
306 * Simulate a consumption of the received packet by subtracting the packet
307 * size from the internal counter at #m_objectBytesToBeReceived. Also updates
308 * #m_objectClientTs and #m_objectServerTs according to the ThreeGppHttpHeader
309 * found in the packet.
310 *
311 * This method is invoked as a sub-procedure of ReceiveMainObject() and
312 * ReceiveEmbeddedObject().
313 *
314 * \param packet The received packet. If it is the first packet of the object,
315 * then it must have a ThreeGppHttpHeader attached to it.
316 */
317 void Receive(Ptr<Packet> packet);
318
319 // OFF-TIME-RELATED METHODS
320
321 /**
322 * Becomes idle for a randomly determined amount of time, and then triggers
323 * ParseMainObject(). The length of idle time is determined by
324 * TheeGppHttpVariables.
325 *
326 * The method is invoked after a complete main object has been received.
327 */
328 void EnterParsingTime();
329 /**
330 * Randomly determines the number of embedded objects in the main object.
331 * ThreeGppHttpVariables is utilized for this purpose. Then proceeds with
332 * RequestEmbeddedObject(). If the number of embedded objects has been
333 * determined as zero, then EnterReadingTime() is triggered.
334 *
335 * The method is invoked after parsing time has elapsed.
336 */
337 void ParseMainObject();
338 /**
339 * Becomes idle for a randomly determined amount of time, and then triggers
340 * RequestMainObject(). The length of idle time is determined by
341 * ThreeGppHttpVariables.
342 *
343 * The method is invoked after a complete web page has been received.
344 */
345 void EnterReadingTime();
346 /**
347 * Cancels #m_eventRequestMainObject, #m_eventRequestEmbeddedObject, and
348 * #m_eventParseMainObject. Invoked by StopApplication() and when connection
349 * has been terminated.
350 */
352
353 /**
354 * Change the state of the client. Fires the `StateTransition` trace source.
355 * \param state The new state.
356 */
357 void SwitchToState(State_t state);
358
359 /**
360 * Finish receiving a page. This function should be called when a full-page
361 * finishes loading, including the main object and all embedded objects.
362 */
363 void FinishReceivingPage();
364
365 /// The current state of the client application. Begins with NOT_STARTED.
367 /// The socket for sending and receiving packets to/from the web server.
369 /// According to the content length specified by the ThreeGppHttpHeader.
371 /// The packet constructed of one or more parts with ThreeGppHttpHeader.
373 /// The client time stamp of the ThreeGppHttpHeader from the last received packet.
375 /// The server time stamp of the ThreeGppHttpHeader from the last received packet.
377 /// Determined after parsing the main object.
379 /// The time stamp when the page started loading.
381 /// Number of embedded objects to requested in the current page.
383 /// Number of bytes received for the current page.
385
386 // ATTRIBUTES
387
388 /// The `Variables` attribute.
390 /// The `RemoteServerAddress` attribute. The address of the web server.
392 /// The `RemoteServerPort` attribute.
394 /// The `Tos` attribute.
395 uint8_t m_tos;
396
397 // TRACE SOURCES
398
399 /// The `RxPage` trace source.
402 /// The `ConnectionEstablished` trace source.
404 /// The `ConnectionClosed` trace source.
406 /// The `Tx` trace source.
408 /// The `TxMainObjectRequest` trace source.
410 /// The `TxEmbeddedObjectRequest` trace source.
412 /// The `TxMainObjectPacket` trace source.
414 /// The `TxMainObject` trace source.
416 /// The `TxEmbeddedObjectPacket` trace source.
418 /// The `TxEmbeddedObject` trace source.
420 /// The `Rx` trace source.
422 /// The `RxDelay` trace source.
424 /// The `RxRtt` trace source.
426 /// The `StateTransition` trace source.
428
429 // EVENTS
430
431 /**
432 * An event of either RequestMainObject() or OpenConnection(), scheduled to
433 * trigger after a connection has been established or reading time has
434 * elapsed.
435 */
437 /**
438 * An event of either RequestEmbeddedObject() or OpenConnection().
439 */
441 /**
442 * An event of ParseMainObject(), scheduled to trigger after parsing time has
443 * elapsed.
444 */
446
447}; // end of `class ThreeGppHttpClient`
448
449} // namespace ns3
450
451#endif /* THREE_GPP_HTTP_CLIENT_H */
a polymophic address class
Definition: address.h:101
The base class for all ns3 applications.
Definition: application.h:62
An identifier for simulation events.
Definition: event-id.h:55
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Model application which simulates the traffic of a web browser.
ns3::TracedCallback< const Time &, const Address & > m_rxRttTrace
The RxRtt trace source.
Time m_pageLoadStartTs
The time stamp when the page started loading.
ns3::TracedCallback< Ptr< const ThreeGppHttpClient >, const Time &, uint32_t, uint32_t > m_rxPageTrace
The RxPage trace source.
void ReceiveMainObject(Ptr< Packet > packet, const Address &from)
Receive a packet of main object from the destination web server.
ns3::TracedCallback< Ptr< const ThreeGppHttpClient > > m_connectionClosedTrace
The ConnectionClosed trace source.
ns3::TracedCallback< const Time &, const Address & > m_rxDelayTrace
The RxDelay trace source.
ns3::TracedCallback< Ptr< const ThreeGppHttpClient >, Ptr< const Packet > > m_rxEmbeddedObjectTrace
The TxEmbeddedObject trace source.
Ptr< ThreeGppHttpVariables > m_httpVariables
The Variables attribute.
uint32_t m_embeddedObjectsToBeRequested
Determined after parsing the main object.
EventId m_eventParseMainObject
An event of ParseMainObject(), scheduled to trigger after parsing time has elapsed.
void SwitchToState(State_t state)
Change the state of the client.
uint32_t m_numberEmbeddedObjectsRequested
Number of embedded objects to requested in the current page.
void ConnectionFailedCallback(Ptr< Socket > socket)
Invoked when m_socket cannot establish a connection with the web server.
ThreeGppHttpClient()
Creates a new instance of HTTP client application.
ns3::TracedCallback< Ptr< const Packet >, const Address & > m_rxTrace
The Rx trace source.
void EnterParsingTime()
Becomes idle for a randomly determined amount of time, and then triggers ParseMainObject().
State_t m_state
The current state of the client application. Begins with NOT_STARTED.
void FinishReceivingPage()
Finish receiving a page.
Ptr< Socket > m_socket
The socket for sending and receiving packets to/from the web server.
void RequestEmbeddedObject()
Send a request object for an embedded object to the destination web server.
void ParseMainObject()
Randomly determines the number of embedded objects in the main object.
ns3::TracedCallback< Ptr< const ThreeGppHttpClient >, Ptr< const Packet > > m_rxMainObjectTrace
The TxMainObject trace source.
State_t GetState() const
Returns the current state of the application.
void EnterReadingTime()
Becomes idle for a randomly determined amount of time, and then triggers RequestMainObject().
void DoDispose() override
Destructor implementation.
void StartApplication() override
Application specific startup code.
Ptr< Packet > m_constructedPacket
The packet constructed of one or more parts with ThreeGppHttpHeader.
uint32_t m_objectBytesToBeReceived
According to the content length specified by the ThreeGppHttpHeader.
void ConnectionSucceededCallback(Ptr< Socket > socket)
Invoked when a connection is established successfully on m_socket.
static TypeId GetTypeId()
Returns the object TypeId.
void ErrorCloseCallback(Ptr< Socket > socket)
Invoked when connection between m_socket and the web sever is terminated.
EventId m_eventRequestMainObject
An event of either RequestMainObject() or OpenConnection(), scheduled to trigger after a connection h...
uint16_t m_remoteServerPort
The RemoteServerPort attribute.
uint32_t m_numberBytesPage
Number of bytes received for the current page.
Address m_remoteServerAddress
The RemoteServerAddress attribute. The address of the web server.
void(* RxPageTracedCallback)(Ptr< const ThreeGppHttpClient > httpClient, const Time &time, uint32_t numObjects, uint32_t numBytes)
Callback signature for RxPage trace sources.
void CancelAllPendingEvents()
Cancels m_eventRequestMainObject, m_eventRequestEmbeddedObject, and m_eventParseMainObject.
Ptr< Socket > GetSocket() const
Returns a pointer to the associated socket.
ns3::TracedCallback< Ptr< const Packet > > m_txTrace
The Tx trace source.
uint8_t m_tos
The Tos attribute.
Time m_objectClientTs
The client time stamp of the ThreeGppHttpHeader from the last received packet.
State_t
The possible states of the application.
@ CONNECTING
Sent the server a connection request and waiting for the server to be accept it.
@ NOT_STARTED
Before StartApplication() is invoked.
@ READING
User reading a web page that has just been received.
@ EXPECTING_MAIN_OBJECT
Sent the server a request for a main object and waiting to receive the packets.
@ STOPPED
After StopApplication() is invoked.
@ PARSING_MAIN_OBJECT
Parsing a main object that has just been received.
@ EXPECTING_EMBEDDED_OBJECT
Sent the server a request for an embedded object and waiting to receive the packets.
ns3::TracedCallback< Ptr< const Packet > > m_txMainObjectRequestTrace
The TxMainObjectRequest trace source.
void StopApplication() override
Application specific shutdown code.
ns3::TracedCallback< Ptr< const Packet > > m_rxMainObjectPacketTrace
The TxMainObjectPacket trace source.
ns3::TracedCallback< const std::string &, const std::string & > m_stateTransitionTrace
The StateTransition trace source.
void RequestMainObject()
Send a request object for a main object to the destination web server.
Time m_objectServerTs
The server time stamp of the ThreeGppHttpHeader from the last received packet.
void NormalCloseCallback(Ptr< Socket > socket)
Invoked when connection between m_socket and the web sever is terminated.
ns3::TracedCallback< Ptr< const ThreeGppHttpClient > > m_connectionEstablishedTrace
The ConnectionEstablished trace source.
ns3::TracedCallback< Ptr< const Packet > > m_txEmbeddedObjectRequestTrace
The TxEmbeddedObjectRequest trace source.
void ReceivedDataCallback(Ptr< Socket > socket)
Invoked when m_socket receives some packet data.
ns3::TracedCallback< Ptr< const Packet > > m_rxEmbeddedObjectPacketTrace
The TxEmbeddedObjectPacket trace source.
void Receive(Ptr< Packet > packet)
Simulate a consumption of the received packet by subtracting the packet size from the internal counte...
void ReceiveEmbeddedObject(Ptr< Packet > packet, const Address &from)
Receive a packet of embedded object from the destination web server.
void OpenConnection()
Initialize m_socket to connect to the destination web server at m_remoteServerAddress and m_remoteSer...
std::string GetStateString() const
Returns the current state of the application in string format.
EventId m_eventRequestEmbeddedObject
An event of either RequestEmbeddedObject() or OpenConnection().
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition: type-id.h:59
Every class exported by the ns3 library is enclosed in the ns3 namespace.