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  {
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 */
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.
Time m_objectClientTs
The client time stamp of the ThreeGppHttpHeader from the last received packet.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
User reading a web page that has just been received.
ns3::TracedCallback< Ptr< const Packet > > m_rxEmbeddedObjectPacketTrace
The TxEmbeddedObjectPacket trace source.
void EnterReadingTime()
Becomes idle for a randomly determined amount of time, and then triggers RequestMainObject().
uint32_t m_objectBytesToBeReceived
According to the content length specified by the ThreeGppHttpHeader.
Forward calls to a chain of Callback.
void OpenConnection()
Initialize m_socket to connect to the destination web server at m_remoteServerAddress and m_remoteSer...
Parsing a main object that has just been received.
State_t GetState() const
Returns the current state of the application.
void ReceiveMainObject(Ptr< Packet > packet, const Address &from)
Receive a packet of main object from the destination web server.
Sent the server a request for a main object and waiting to receive the packets.
void ErrorCloseCallback(Ptr< Socket > socket)
Invoked when connection between m_socket and the web sever is terminated.
static TypeId GetTypeId()
Returns the object TypeId.
a polymophic address class
Definition: address.h:90
ns3::TracedCallback< Ptr< const Packet > > m_txEmbeddedObjectRequestTrace
The TxEmbeddedObjectRequest trace source.
ns3::TracedCallback< Ptr< const ThreeGppHttpClient > > m_connectionEstablishedTrace
The ConnectionEstablished trace source.
The base class for all ns3 applications.
Definition: application.h:60
Model application which simulates the traffic of a web browser.
ns3::TracedCallback< Ptr< const Packet >, const Address & > m_rxTrace
The Rx trace source.
ns3::TracedCallback< const Time &, const Address & > m_rxDelayTrace
The RxDelay trace source.
State_t m_state
The current state of the client application. Begins with NOT_STARTED.
ns3::TracedCallback< Ptr< const Packet > > m_txMainObjectRequestTrace
The TxMainObjectRequest trace source.
void ReceiveEmbeddedObject(Ptr< Packet > packet, const Address &from)
Receive a packet of embedded object from the destination web server.
EventId m_eventRequestMainObject
An event of either RequestMainObject() or OpenConnection(), scheduled to trigger after a connection h...
void RequestMainObject()
Send a request object for a main object to the destination web server.
void ParseMainObject()
Randomly determines the number of embedded objects in the main object.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void ReceivedDataCallback(Ptr< Socket > socket)
Invoked when m_socket receives some packet data.
Ptr< ThreeGppHttpVariables > m_httpVariables
The Variables attribute.
Before StartApplication() is invoked.
std::string GetStateString() const
Returns the current state of the application in string format.
void EnterParsingTime()
Becomes idle for a randomly determined amount of time, and then triggers ParseMainObject().
State_t
The possible states of the application.
void SwitchToState(State_t state)
Change the state of the client.
void RequestEmbeddedObject()
Send a request object for an embedded object to the destination web server.
ns3::TracedCallback< Ptr< const ThreeGppHttpClient >, Ptr< const Packet > > m_rxMainObjectTrace
The TxMainObject trace source.
Sent the server a connection request and waiting for the server to be accept it.
ns3::TracedCallback< const Time &, const Address & > m_rxRttTrace
The RxRtt trace source.
void Receive(Ptr< Packet > packet)
Simulate a consumption of the received packet by subtracting the packet size from the internal counte...
An identifier for simulation events.
Definition: event-id.h:53
Ptr< Packet > m_constructedPacket
The packet constructed of one or more parts with ThreeGppHttpHeader.
ns3::TracedCallback< Ptr< const Packet > > m_rxMainObjectPacketTrace
The TxMainObjectPacket trace source.
virtual void StartApplication()
Application specific startup code.
ns3::TracedCallback< Ptr< const ThreeGppHttpClient >, Ptr< const Packet > > m_rxEmbeddedObjectTrace
The TxEmbeddedObject trace source.
Ptr< Socket > GetSocket() const
Returns a pointer to the associated socket.
ns3::TracedCallback< Ptr< const ThreeGppHttpClient > > m_connectionClosedTrace
The ConnectionClosed trace source.
Address m_remoteServerAddress
The RemoteServerAddress attribute. The address of the web server.
uint16_t m_remoteServerPort
The RemoteServerPort attribute.
EventId m_eventRequestEmbeddedObject
An event of either RequestEmbeddedObject() or OpenConnection().
void CancelAllPendingEvents()
Cancels m_eventRequestMainObject, m_eventRequestEmbeddedObject, and m_eventParseMainObject.
ThreeGppHttpClient()
Creates a new instance of HTTP client application.
virtual void StopApplication()
Application specific shutdown code.
Sent the server a request for an embedded object and waiting to receive the packets.
ns3::TracedCallback< Ptr< const Packet > > m_txTrace
The Tx trace source.
void ConnectionFailedCallback(Ptr< Socket > socket)
Invoked when m_socket cannot establish a connection with the web server.
uint32_t m_embeddedObjectsToBeRequested
Determined after parsing the main object.
a unique identifier for an interface.
Definition: type-id.h:58
void ConnectionSucceededCallback(Ptr< Socket > socket)
Invoked when a connection is established successfully on m_socket.
Ptr< Socket > m_socket
The socket for sending and receiving packets to/from the web server.
virtual void DoDispose()
Destructor implementation.
EventId m_eventParseMainObject
An event of ParseMainObject(), scheduled to trigger after parsing time has elapsed.
After StopApplication() is invoked.
ns3::TracedCallback< const std::string &, const std::string & > m_stateTransitionTrace
The StateTransition trace source.