A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
three-gpp-http-server.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2013 Magister Solutions
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Budiarto Herman <budiarto.herman@magister.fi>
18 *
19 */
20
21#ifndef THREE_GPP_HTTP_SERVER_H
22#define THREE_GPP_HTTP_SERVER_H
23
24#include <ns3/address.h>
25#include <ns3/application.h>
26#include <ns3/event-id.h>
27#include <ns3/nstime.h>
28#include <ns3/ptr.h>
29#include <ns3/simple-ref-count.h>
30#include <ns3/three-gpp-http-header.h>
31#include <ns3/traced-callback.h>
32
33#include <map>
34#include <ostream>
35
36namespace ns3
37{
38
39class Socket;
40class Packet;
41class ThreeGppHttpVariables;
42class ThreeGppHttpServerTxBuffer;
43
68{
69 public:
82
87 static TypeId GetTypeId();
88
98 void SetMtuSize(uint32_t mtuSize);
99
104 Ptr<Socket> GetSocket() const;
105
108 {
111 STOPPED
112 };
113
118 State_t GetState() const;
119
124 std::string GetStateString() const;
125
131 static std::string GetStateString(State_t state);
132
139
147 Ptr<Socket> socket);
148
149 protected:
150 // Inherited from Object base class
151 void DoDispose() override;
152
153 // Inherited from Application base class
154 void StartApplication() override;
155 void StopApplication() override;
156
157 private:
158 // SOCKET CALLBACK METHODS
159
168 bool ConnectionRequestCallback(Ptr<Socket> socket, const Address& address);
175 void NewConnectionCreatedCallback(Ptr<Socket> socket, const Address& address);
181 void NormalCloseCallback(Ptr<Socket> socket);
187 void ErrorCloseCallback(Ptr<Socket> socket);
206 void SendCallback(Ptr<Socket> socket, uint32_t availableBufferSize);
207
208 // TX-RELATED METHODS
209
220 void ServeNewMainObject(Ptr<Socket> socket);
252
257 void SwitchToState(State_t state);
258
265
266 // ATTRIBUTES
267
273 uint16_t m_localPort;
276
277 // TRACE SOURCES
278
293
294}; // end of `class ThreeGppHttpServer`
295
311class ThreeGppHttpServerTxBuffer : public SimpleRefCount<ThreeGppHttpServerTxBuffer>
312{
313 public:
316
317 // SOCKET MANAGEMENT
318
328 bool IsSocketAvailable(Ptr<Socket> socket) const;
329
339 void AddSocket(Ptr<Socket> socket);
340
357 void RemoveSocket(Ptr<Socket> socket);
358
374 void CloseSocket(Ptr<Socket> socket);
375
379 void CloseAllSockets();
380
381 // BUFFER MANAGEMENT
382
391 bool IsBufferEmpty(Ptr<Socket> socket) const;
392
400 Time GetClientTs(Ptr<Socket> socket) const;
401
414
423 uint32_t GetBufferSize(Ptr<Socket> socket) const;
424
436 bool HasTxedPartOfObject(Ptr<Socket> socket) const;
437
454 void WriteNewObject(Ptr<Socket> socket,
456 uint32_t objectSize);
457
474 void RecordNextServe(Ptr<Socket> socket, const EventId& eventId, const Time& clientTs);
475
495 void DepleteBufferSize(Ptr<Socket> socket, uint32_t amount);
496
505 void PrepareClose(Ptr<Socket> socket);
506
507 private:
513 {
546 };
547
549 std::map<Ptr<Socket>, TxBuffer_t> m_txBuffer;
550
551}; // end of `class ThreeGppHttpServerTxBuffer`
552
553} // namespace ns3
554
555#endif /* THREE_GPP_HTTP_SERVER_H */
a polymophic address class
Definition: address.h:100
The base class for all ns3 applications.
Definition: application.h:61
An identifier for simulation events.
Definition: event-id.h:55
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
A template-based reference counting class.
ContentType_t
The possible types of content (default = NOT_SET).
Model application which simulates the traffic of a web server.
State_t
The possible states of the application.
@ NOT_STARTED
Before StartApplication() is invoked.
@ STOPPED
After StopApplication() is invoked.
@ STARTED
Passively listening and responding to requests.
void StartApplication() override
Application specific startup code.
uint32_t ServeFromTxBuffer(Ptr< Socket > socket)
Creates a packet out of a pending object in the Tx buffer send it over the given socket.
State_t m_state
The current state of the client application. Begins with NOT_STARTED.
void(* ThreeGppHttpObjectCallback)(uint32_t size)
Common callback signature for MainObject and EmbeddedObject trace sources.
Ptr< ThreeGppHttpVariables > m_httpVariables
The Variables attribute.
uint16_t m_localPort
The LocalPort attribute.
TracedCallback< uint32_t > m_embeddedObjectTrace
The EmbeddedObject trace source.
Address m_localAddress
The LocalAddress attribute.
void ReceivedDataCallback(Ptr< Socket > socket)
Invoked when m_initialSocket receives some packet data.
void ServeNewMainObject(Ptr< Socket > socket)
Generates a new main object and push it into the Tx buffer.
TracedCallback< uint32_t > m_mainObjectTrace
The MainObject trace source.
uint32_t m_mtuSize
The Mtu attribute.
TracedCallback< const Time &, const Address & > m_rxDelayTrace
The RxDelay trace source.
State_t GetState() const
Returns the current state of the application.
Ptr< ThreeGppHttpServerTxBuffer > m_txBuffer
Pointer to the transmission buffer.
void(* ConnectionEstablishedCallback)(Ptr< const ThreeGppHttpServer > httpServer, Ptr< Socket > socket)
Callback signature for ConnectionEstablished trace source.
bool ConnectionRequestCallback(Ptr< Socket > socket, const Address &address)
Invoked when m_initialSocket receives a connection request.
void ServeNewEmbeddedObject(Ptr< Socket > socket)
Generates a new embedded object and push it into the Tx buffer.
TracedCallback< const std::string &, const std::string & > m_stateTransitionTrace
The StateTransition trace source.
void ErrorCloseCallback(Ptr< Socket > socket)
Invoked when a connection with a web client is terminated.
void SendCallback(Ptr< Socket > socket, uint32_t availableBufferSize)
Invoked when more buffer space for transmission is added to a socket.
TracedCallback< Ptr< const Packet >, const Address & > m_rxTrace
The Rx trace source.
Ptr< Socket > GetSocket() const
Returns a pointer to the listening socket.
TracedCallback< Ptr< const ThreeGppHttpServer >, Ptr< Socket > > m_connectionEstablishedTrace
The ConnectionEstablished trace source.
Ptr< Socket > m_initialSocket
The listening socket, for receiving connection requests from clients.
static TypeId GetTypeId()
Returns the object TypeId.
std::string GetStateString() const
Returns the current state of the application in string format.
ThreeGppHttpServer()
Creates a new instance of HTTP server application.
TracedCallback< Ptr< const Packet > > m_txTrace
The Tx trace source.
void NormalCloseCallback(Ptr< Socket > socket)
Invoked when a connection with a web client is terminated.
void DoDispose() override
Destructor implementation.
void StopApplication() override
Application specific shutdown code.
void NewConnectionCreatedCallback(Ptr< Socket > socket, const Address &address)
Invoked when a new connection has been established.
void SetMtuSize(uint32_t mtuSize)
Sets the maximum transmission unit (MTU) size used by the application.
void SwitchToState(State_t state)
Change the state of the server.
void DepleteBufferSize(Ptr< Socket > socket, uint32_t amount)
Decrements a buffer size by a given amount.
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...
uint32_t GetBufferSize(Ptr< Socket > socket) const
void CloseAllSockets()
Close and remove all stored sockets, hence clearing the buffer.
bool HasTxedPartOfObject(Ptr< Socket > socket) const
void PrepareClose(Ptr< Socket > socket)
Tell the buffer to close the associated socket once the buffer becomes empty.
Time GetClientTs(Ptr< Socket > socket) const
void CloseSocket(Ptr< Socket > socket)
Close and remove a socket and its associated transmission buffer, and then unset the socket's callbac...
ThreeGppHttpServerTxBuffer()
Create an empty instance of transmission buffer.
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...
std::map< Ptr< Socket >, TxBuffer_t > m_txBuffer
Collection of accepted sockets and its individual transmission buffer.
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.
bool IsBufferEmpty(Ptr< Socket > socket) const
bool IsSocketAvailable(Ptr< Socket > socket) const
This method is typically used before calling other methods.
void AddSocket(Ptr< Socket > socket)
Add a new socket and create an empty transmission buffer for it.
void RemoveSocket(Ptr< Socket > socket)
Remove a socket and its associated transmission buffer, and then unset the socket's callbacks to prev...
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
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.
Set of fields representing a single transmission buffer, which will be associated with a socket.
ThreeGppHttpHeader::ContentType_t txBufferContentType
The content type of the current data inside the transmission buffer.
uint32_t txBufferSize
The length (in bytes) of the current data inside the transmission buffer.
EventId nextServe
Pending transmission event which will be automatically canceled when the associated socket is closed.
bool isClosing
True if the remote end has issued a request to close, which means that this socket will immediately c...
bool hasTxedPartOfObject
True if the buffer content has been read since it is written.
Time clientTs
The client time stamp that comes from the request packet.