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