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