A Discrete-Event Network Simulator
API
three-gpp-http-server.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_SERVER_H
23 #define THREE_GPP_HTTP_SERVER_H
24 
25 #include <ns3/ptr.h>
26 #include <ns3/simple-ref-count.h>
27 #include <ns3/nstime.h>
28 #include <ns3/event-id.h>
29 #include <ns3/three-gpp-http-header.h>
30 #include <ns3/application.h>
31 #include <ns3/address.h>
32 #include <ns3/traced-callback.h>
33 #include <map>
34 #include <ostream>
35 
36 
37 namespace ns3 {
38 
39 
40 class Socket;
41 class Packet;
42 class ThreeGppHttpVariables;
43 class ThreeGppHttpServerTxBuffer;
44 
45 
70 {
71 public:
84 
89  static TypeId GetTypeId ();
90 
100  void SetMtuSize (uint32_t mtuSize);
101 
106  Ptr<Socket> GetSocket () const;
107 
109  enum State_t
110  {
113  STOPPED
114  };
115 
120  State_t GetState () const;
121 
126  std::string GetStateString () const;
127 
133  static std::string GetStateString (State_t state);
134 
140  typedef void (*ThreeGppHttpObjectCallback)(uint32_t size);
141 
149  Ptr<Socket> socket);
150 
151 protected:
152  // Inherited from Object base class
153  virtual void DoDispose ();
154 
155  // Inherited from Application base class
156  virtual void StartApplication ();
157  virtual void StopApplication ();
158 
159 private:
160  // SOCKET CALLBACK METHODS
161 
171  const Address &address);
179  const Address &address);
185  void NormalCloseCallback (Ptr<Socket> socket);
191  void ErrorCloseCallback (Ptr<Socket> socket);
201  void ReceivedDataCallback (Ptr<Socket> socket);
210  void SendCallback (Ptr<Socket> socket, uint32_t availableBufferSize);
211 
212  // TX-RELATED METHODS
213 
224  void ServeNewMainObject (Ptr<Socket> socket);
235  void ServeNewEmbeddedObject (Ptr<Socket> socket);
255  uint32_t ServeFromTxBuffer (Ptr<Socket> socket);
256 
261  void SwitchToState (State_t state);
262 
269 
270  // ATTRIBUTES
271 
277  uint16_t m_localPort;
279  uint32_t m_mtuSize;
280 
281  // TRACE SOURCES
282 
297 
298 }; // end of `class ThreeGppHttpServer`
299 
300 
316 class ThreeGppHttpServerTxBuffer : public SimpleRefCount<ThreeGppHttpServerTxBuffer>
317 {
318 public:
321 
322  // SOCKET MANAGEMENT
323 
333  bool IsSocketAvailable (Ptr<Socket> socket) const;
334 
344  void AddSocket (Ptr<Socket> socket);
345 
362  void RemoveSocket (Ptr<Socket> socket);
363 
379  void CloseSocket (Ptr<Socket> socket);
380 
384  void CloseAllSockets ();
385 
386  // BUFFER MANAGEMENT
387 
396  bool IsBufferEmpty (Ptr<Socket> socket) const;
397 
405  Time GetClientTs (Ptr<Socket> socket) const;
406 
419 
428  uint32_t GetBufferSize (Ptr<Socket> socket) const;
429 
441  bool HasTxedPartOfObject (Ptr<Socket> socket) const;
442 
459  void WriteNewObject (Ptr<Socket> socket,
461  uint32_t objectSize);
462 
479  void RecordNextServe (Ptr<Socket> socket,
480  const EventId &eventId,
481  const Time &clientTs);
482 
502  void DepleteBufferSize (Ptr<Socket> socket, uint32_t amount);
503 
512  void PrepareClose (Ptr<Socket> socket);
513 
514 private:
519  struct TxBuffer_t
520  {
541  uint32_t txBufferSize;
547  bool isClosing;
553  };
554 
556  std::map<Ptr<Socket>, TxBuffer_t> m_txBuffer;
557 
558 }; // end of `class ThreeGppHttpServerTxBuffer`
559 
560 
561 } // end of `namespace ns3`
562 
563 
564 #endif /* THREE_GPP_HTTP_SERVER_H */
ns3::TypeId
a unique identifier for an interface.
Definition: type-id.h:59
ns3::ThreeGppHttpServer::NewConnectionCreatedCallback
void NewConnectionCreatedCallback(Ptr< Socket > socket, const Address &address)
Invoked when a new connection has been established.
Definition: three-gpp-http-server.cc:323
ns3::ThreeGppHttpServer::State_t
State_t
The possible states of the application.
Definition: three-gpp-http-server.h:110
ns3::ThreeGppHttpServer::StopApplication
virtual void StopApplication()
Application specific shutdown code.
Definition: three-gpp-http-server.cc:290
ns3::ThreeGppHttpServerTxBuffer::CloseAllSockets
void CloseAllSockets()
Close and remove all stored sockets, hence clearing the buffer.
Definition: three-gpp-http-server.cc:784
ns3::EventId
An identifier for simulation events.
Definition: event-id.h:54
ns3::ThreeGppHttpServer::GetState
State_t GetState() const
Returns the current state of the application.
Definition: three-gpp-http-server.cc:149
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::ThreeGppHttpServerTxBuffer::ThreeGppHttpServerTxBuffer
ThreeGppHttpServerTxBuffer()
Create an empty instance of transmission buffer.
Definition: three-gpp-http-server.cc:690
ns3::ThreeGppHttpServerTxBuffer::HasTxedPartOfObject
bool HasTxedPartOfObject(Ptr< Socket > socket) const
Definition: three-gpp-http-server.cc:855
ns3::ThreeGppHttpServer::StartApplication
virtual void StartApplication()
Application specific startup code.
Definition: three-gpp-http-server.cc:200
ns3::ThreeGppHttpServerTxBuffer
Definition: three-gpp-http-server.h:317
ns3::ThreeGppHttpServer::SetMtuSize
void SetMtuSize(uint32_t mtuSize)
Sets the maximum transmission unit (MTU) size used by the application.
Definition: three-gpp-http-server.cc:134
ns3::ThreeGppHttpServerTxBuffer::GetBufferSize
uint32_t GetBufferSize(Ptr< Socket > socket) const
Definition: three-gpp-http-server.cc:844
ns3::ThreeGppHttpServer::m_localPort
uint16_t m_localPort
The LocalPort attribute.
Definition: three-gpp-http-server.h:277
ns3::ThreeGppHttpServer::m_localAddress
Address m_localAddress
The LocalAddress attribute.
Definition: three-gpp-http-server.h:275
ns3::ThreeGppHttpServer::NormalCloseCallback
void NormalCloseCallback(Ptr< Socket > socket)
Invoked when a connection with a web client is terminated.
Definition: three-gpp-http-server.cc:355
ns3::ThreeGppHttpServerTxBuffer::TxBuffer_t::hasTxedPartOfObject
bool hasTxedPartOfObject
True if the buffer content has been read since it is written.
Definition: three-gpp-http-server.h:552
ns3::SimpleRefCount
A template-based reference counting class.
Definition: simple-ref-count.h:74
ns3::ThreeGppHttpServer::m_mtuSize
uint32_t m_mtuSize
The Mtu attribute.
Definition: three-gpp-http-server.h:279
ns3::ThreeGppHttpServerTxBuffer::IsSocketAvailable
bool IsSocketAvailable(Ptr< Socket > socket) const
This method is typically used before calling other methods.
Definition: three-gpp-http-server.cc:696
ns3::ThreeGppHttpServerTxBuffer::CloseSocket
void CloseSocket(Ptr< Socket > socket)
Close and remove a socket and its associated transmission buffer, and then unset the socket's callbac...
Definition: three-gpp-http-server.cc:749
ns3::ThreeGppHttpServer::ThreeGppHttpServer
ThreeGppHttpServer()
Creates a new instance of HTTP server application.
Definition: three-gpp-http-server.cc:52
ns3::ThreeGppHttpServer::ServeNewMainObject
void ServeNewMainObject(Ptr< Socket > socket)
Generates a new main object and push it into the Tx buffer.
Definition: three-gpp-http-server.cc:543
ns3::ThreeGppHttpServer::m_initialSocket
Ptr< Socket > m_initialSocket
The listening socket, for receiving connection requests from clients.
Definition: three-gpp-http-server.h:266
ns3::ThreeGppHttpServerTxBuffer::RemoveSocket
void RemoveSocket(Ptr< Socket > socket)
Remove a socket and its associated transmission buffer, and then unset the socket's callbacks to prev...
Definition: three-gpp-http-server.cc:722
ns3::ThreeGppHttpServerTxBuffer::TxBuffer_t::txBufferContentType
ThreeGppHttpHeader::ContentType_t txBufferContentType
The content type of the current data inside the transmission buffer.
Definition: three-gpp-http-server.h:536
ns3::ThreeGppHttpServerTxBuffer::AddSocket
void AddSocket(Ptr< Socket > socket)
Add a new socket and create an empty transmission buffer for it.
Definition: three-gpp-http-server.cc:704
ns3::ThreeGppHttpServerTxBuffer::GetBufferContentType
ThreeGppHttpHeader::ContentType_t GetBufferContentType(Ptr< Socket > socket) const
Returns ThreeGppHttpHeader::NOT_SET when the buffer is new and never been filled with any data before...
Definition: three-gpp-http-server.cc:833
ns3::ThreeGppHttpServerTxBuffer::TxBuffer_t::nextServe
EventId nextServe
Pending transmission event which will be automatically canceled when the associated socket is closed.
Definition: three-gpp-http-server.h:525
ns3::ThreeGppHttpServerTxBuffer::TxBuffer_t::isClosing
bool isClosing
True if the remote end has issued a request to close, which means that this socket will immediately c...
Definition: three-gpp-http-server.h:547
ns3::ThreeGppHttpServer::ServeNewEmbeddedObject
void ServeNewEmbeddedObject(Ptr< Socket > socket)
Generates a new embedded object and push it into the Tx buffer.
Definition: three-gpp-http-server.cc:568
ns3::ThreeGppHttpServerTxBuffer::TxBuffer_t
Set of fields representing a single transmission buffer, which will be associated with a socket.
Definition: three-gpp-http-server.h:520
ns3::ThreeGppHttpServerTxBuffer::GetClientTs
Time GetClientTs(Ptr< Socket > socket) const
Definition: three-gpp-http-server.cc:822
ns3::ThreeGppHttpServerTxBuffer::PrepareClose
void PrepareClose(Ptr< Socket > socket)
Tell the buffer to close the associated socket once the buffer becomes empty.
Definition: three-gpp-http-server.cc:935
ns3::ThreeGppHttpServerTxBuffer::TxBuffer_t::clientTs
Time clientTs
The client time stamp that comes from the request packet.
Definition: three-gpp-http-server.h:531
ns3::ThreeGppHttpServer::m_httpVariables
Ptr< ThreeGppHttpVariables > m_httpVariables
The Variables attribute.
Definition: three-gpp-http-server.h:273
ns3::Ptr< Socket >
ns3::ThreeGppHttpServer::ReceivedDataCallback
void ReceivedDataCallback(Ptr< Socket > socket)
Invoked when m_initialSocket receives some packet data.
Definition: three-gpp-http-server.cc:412
ns3::ThreeGppHttpServer::STOPPED
@ STOPPED
After StopApplication() is invoked.
Definition: three-gpp-http-server.h:113
ns3::Address
a polymophic address class
Definition: address.h:91
ns3::ThreeGppHttpServer::NOT_STARTED
@ NOT_STARTED
Before StartApplication() is invoked.
Definition: three-gpp-http-server.h:111
first.address
address
Definition: first.py:44
ns3::ThreeGppHttpServer::ConnectionRequestCallback
bool ConnectionRequestCallback(Ptr< Socket > socket, const Address &address)
Invoked when m_initialSocket receives a connection request.
Definition: three-gpp-http-server.cc:314
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:104
ns3::ThreeGppHttpServer::GetSocket
Ptr< Socket > GetSocket() const
Returns a pointer to the listening socket.
Definition: three-gpp-http-server.cc:142
ns3::ThreeGppHttpServerTxBuffer::IsBufferEmpty
bool IsBufferEmpty(Ptr< Socket > socket) const
Definition: three-gpp-http-server.cc:811
ns3::ThreeGppHttpServer::m_rxDelayTrace
TracedCallback< const Time &, const Address & > m_rxDelayTrace
The RxDelay trace source.
Definition: three-gpp-http-server.h:294
ns3::ThreeGppHttpServerTxBuffer::DepleteBufferSize
void DepleteBufferSize(Ptr< Socket > socket, uint32_t amount)
Decrements a buffer size by a given amount.
Definition: three-gpp-http-server.cc:907
ns3::ThreeGppHttpServer::m_txBuffer
Ptr< ThreeGppHttpServerTxBuffer > m_txBuffer
Pointer to the transmission buffer.
Definition: three-gpp-http-server.h:268
ns3::ThreeGppHttpServer::DoDispose
virtual void DoDispose()
Destructor implementation.
Definition: three-gpp-http-server.cc:186
ns3::ThreeGppHttpServer::m_state
State_t m_state
The current state of the client application. Begins with NOT_STARTED.
Definition: three-gpp-http-server.h:264
ns3::ThreeGppHttpHeader::ContentType_t
ContentType_t
The possible types of content (default = NOT_SET).
Definition: three-gpp-http-header.h:83
ns3::ThreeGppHttpServerTxBuffer::RecordNextServe
void RecordNextServe(Ptr< Socket > socket, const EventId &eventId, const Time &clientTs)
Informs about a pending transmission event associated with the socket, so that it would be automatica...
Definition: three-gpp-http-server.cc:891
ns3::ThreeGppHttpServer::ErrorCloseCallback
void ErrorCloseCallback(Ptr< Socket > socket)
Invoked when a connection with a web client is terminated.
Definition: three-gpp-http-server.cc:392
ns3::ThreeGppHttpServer
Model application which simulates the traffic of a web server.
Definition: three-gpp-http-server.h:70
ns3::ThreeGppHttpServer::ServeFromTxBuffer
uint32_t ServeFromTxBuffer(Ptr< Socket > socket)
Creates a packet out of a pending object in the Tx buffer send it over the given socket.
Definition: three-gpp-http-server.cc:593
ns3::ThreeGppHttpServer::ThreeGppHttpObjectCallback
void(* ThreeGppHttpObjectCallback)(uint32_t size)
Common callback signature for MainObject and EmbeddedObject trace sources.
Definition: three-gpp-http-server.h:140
ns3::ThreeGppHttpServerTxBuffer::m_txBuffer
std::map< Ptr< Socket >, TxBuffer_t > m_txBuffer
Collection of accepted sockets and its individual transmission buffer.
Definition: three-gpp-http-server.h:556
ns3::ThreeGppHttpServer::m_embeddedObjectTrace
TracedCallback< uint32_t > m_embeddedObjectTrace
The EmbeddedObject trace source.
Definition: three-gpp-http-server.h:288
ns3::ThreeGppHttpServerTxBuffer::WriteNewObject
void WriteNewObject(Ptr< Socket > socket, ThreeGppHttpHeader::ContentType_t contentType, uint32_t objectSize)
Writes a data representing a new main object or embedded object to the transmission buffer.
Definition: three-gpp-http-server.cc:866
ns3::ThreeGppHttpServer::GetStateString
std::string GetStateString() const
Returns the current state of the application in string format.
Definition: three-gpp-http-server.cc:156
ns3::ThreeGppHttpServer::m_mainObjectTrace
TracedCallback< uint32_t > m_mainObjectTrace
The MainObject trace source.
Definition: three-gpp-http-server.h:286
ns3::ThreeGppHttpServer::m_stateTransitionTrace
TracedCallback< const std::string &, const std::string & > m_stateTransitionTrace
The StateTransition trace source.
Definition: three-gpp-http-server.h:296
ns3::TracedCallback
Forward calls to a chain of Callback.
Definition: traced-callback.h:53
ns3::ThreeGppHttpServerTxBuffer::TxBuffer_t::txBufferSize
uint32_t txBufferSize
The length (in bytes) of the current data inside the transmission buffer.
Definition: three-gpp-http-server.h:541
ns3::ThreeGppHttpServer::SendCallback
void SendCallback(Ptr< Socket > socket, uint32_t availableBufferSize)
Invoked when more buffer space for transmission is added to a socket.
Definition: three-gpp-http-server.cc:488
ns3::ThreeGppHttpServer::GetTypeId
static TypeId GetTypeId()
Returns the object TypeId.
Definition: three-gpp-http-server.cc:68
ns3::Application
The base class for all ns3 applications.
Definition: application.h:61
ns3::ThreeGppHttpServer::m_rxTrace
TracedCallback< Ptr< const Packet >, const Address & > m_rxTrace
The Rx trace source.
Definition: three-gpp-http-server.h:292
ns3::ThreeGppHttpServer::SwitchToState
void SwitchToState(State_t state)
Change the state of the server.
Definition: three-gpp-http-server.cc:675
ns3::ThreeGppHttpServer::m_connectionEstablishedTrace
TracedCallback< Ptr< const ThreeGppHttpServer >, Ptr< Socket > > m_connectionEstablishedTrace
The ConnectionEstablished trace source.
Definition: three-gpp-http-server.h:284
ns3::ThreeGppHttpServer::ConnectionEstablishedCallback
void(* ConnectionEstablishedCallback)(Ptr< const ThreeGppHttpServer > httpServer, Ptr< Socket > socket)
Callback signature for ConnectionEstablished trace source.
Definition: three-gpp-http-server.h:148
ns3::ThreeGppHttpServer::m_txTrace
TracedCallback< Ptr< const Packet > > m_txTrace
The Tx trace source.
Definition: three-gpp-http-server.h:290
ns3::ThreeGppHttpServer::STARTED
@ STARTED
Passively listening and responding to requests.
Definition: three-gpp-http-server.h:112