A Discrete-Event Network Simulator
API
three-gpp-http-client.h
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013 Magister Solutions
4  *
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;
8  *
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.
13  *
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
17  *
18  * Author: Budiarto Herman <budiarto.herman@magister.fi>
19  *
20  */
21 
22 #ifndef THREE_GPP_HTTP_CLIENT_H
23 #define THREE_GPP_HTTP_CLIENT_H
24 
25 #include <ns3/application.h>
26 #include <ns3/address.h>
27 #include <ns3/traced-callback.h>
28 #include <ns3/three-gpp-http-header.h>
29 
30 
31 namespace ns3 {
32 
33 
34 class Socket;
35 class Packet;
36 class ThreeGppHttpVariables;
37 
38 
109 {
110 public:
119 
124  static TypeId GetTypeId ();
125 
130  Ptr<Socket> GetSocket () const;
131 
133  enum State_t
134  {
148  STOPPED
149  };
150 
155  State_t GetState () const;
156 
161  std::string GetStateString () const;
162 
168  static std::string GetStateString (State_t state);
169 
176  typedef void (*TracedCallback)(Ptr<const ThreeGppHttpClient> httpClient);
177 
178 protected:
179  // Inherited from Object base class.
180  virtual void DoDispose ();
181 
182  // Inherited from Application base class.
183  virtual void StartApplication ();
184  virtual void StopApplication ();
185 
186 private:
187  // SOCKET CALLBACK METHODS
188 
206  void NormalCloseCallback (Ptr<Socket> socket);
212  void ErrorCloseCallback (Ptr<Socket> socket);
218  void ReceivedDataCallback (Ptr<Socket> socket);
219 
220  // CONNECTION-RELATED METHOD
221 
227  void OpenConnection ();
228 
229  // TX-RELATED METHODS
230 
240  void RequestMainObject ();
247  void RequestEmbeddedObject ();
248 
249  // RX-RELATED METHODS
250 
271  void ReceiveMainObject (Ptr<Packet> packet, const Address &from);
294  void ReceiveEmbeddedObject (Ptr<Packet> packet, const Address &from);
307  void Receive (Ptr<Packet> packet);
308 
309  // OFF-TIME-RELATED METHODS
310 
318  void EnterParsingTime ();
327  void ParseMainObject ();
335  void EnterReadingTime ();
341  void CancelAllPendingEvents ();
342 
347  void SwitchToState (State_t state);
348 
363 
364  // ATTRIBUTES
365 
372 
373  // TRACE SOURCES
374 
401 
402  // EVENTS
403 
419 
420 }; // end of `class ThreeGppHttpClient`
421 
422 
423 } // end of `namespace ns3`
424 
425 
426 #endif /* THREE_GPP_HTTP_CLIENT_H */
a polymophic address class
Definition: address.h:91
The base class for all ns3 applications.
Definition: application.h:61
An identifier for simulation events.
Definition: event-id.h:54
Model application which simulates the traffic of a web browser.
virtual void StartApplication()
Application specific startup code.
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< 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.
void ConnectionFailedCallback(Ptr< Socket > socket)
Invoked when m_socket cannot establish a connection with the web server.
ns3::TracedCallback< Ptr< const Packet >, const Address & > m_rxTrace
The Rx trace source.
ThreeGppHttpClient()
Creates a new instance of HTTP client application.
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.
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.
ns3::TracedCallback< const Time &, const Address & > m_rxRttTrace
The RxRtt trace source.
void EnterReadingTime()
Becomes idle for a randomly determined amount of time, and then triggers RequestMainObject().
ns3::TracedCallback< const std::string &, const std::string & > m_stateTransitionTrace
The StateTransition trace source.
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.
virtual void StopApplication()
Application specific shutdown code.
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.
Address m_remoteServerAddress
The RemoteServerAddress attribute. The address of the web server.
virtual void DoDispose()
Destructor implementation.
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.
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 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< const Time &, const Address & > m_rxDelayTrace
The RxDelay trace source.
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:103
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.