LEFT | RIGHT |
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2011 Yufei Cheng | 3 * Copyright (c) 2011 Yufei Cheng |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or modify | 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 | 6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 11 matching lines...) Expand all Loading... |
22 * Information and Telecommunication Technology Center (ITTC) | 22 * Information and Telecommunication Technology Center (ITTC) |
23 * and Department of Electrical Engineering and Computer Science | 23 * and Department of Electrical Engineering and Computer Science |
24 * The University of Kansas Lawrence, KS USA. | 24 * The University of Kansas Lawrence, KS USA. |
25 * | 25 * |
26 * Work supported in part by NSF FIND (Future Internet Design) Program | 26 * Work supported in part by NSF FIND (Future Internet Design) Program |
27 * under grant CNS-0626918 (Postmodern Internet Architecture), | 27 * under grant CNS-0626918 (Postmodern Internet Architecture), |
28 * NSF grant CNS-1050226 (Multilayer Network Resilience Analysis and Experimenta
tion on GENI), | 28 * NSF grant CNS-1050226 (Multilayer Network Resilience Analysis and Experimenta
tion on GENI), |
29 * US Department of Defense (DoD), and ITTC at The University of Kansas. | 29 * US Department of Defense (DoD), and ITTC at The University of Kansas. |
30 */ | 30 */ |
31 | 31 |
32 #ifndef HTTP_SERVER_H | 32 #ifndef HTTP_SERVER |
33 #define HTTP_SERVER_H | 33 #define HTTP_SERVER |
34 | 34 |
| 35 #include <iostream> |
| 36 #include <fstream> |
35 #include <vector> | 37 #include <vector> |
| 38 #include <deque> |
| 39 |
| 40 #include "ns3/nstime.h" |
36 #include "ns3/application.h" | 41 #include "ns3/application.h" |
37 #include "ns3/event-id.h" | 42 #include "ns3/address.h" |
| 43 #include "ns3/object.h" |
38 #include "ns3/ptr.h" | 44 #include "ns3/ptr.h" |
39 #include "ns3/node.h" | 45 #include "ns3/node.h" |
40 #include "ns3/ipv4.h" | 46 #include "ns3/socket.h" |
41 #include "ns3/traced-callback.h" | |
42 #include "ns3/address.h" | |
43 | 47 |
44 #include "http-client.h" | 48 #include "http-client.h" |
45 #include "http-distribution.h" | 49 |
46 #include "http-runtime-variable.h" | 50 using namespace std; |
47 | 51 |
48 namespace ns3 { | 52 namespace ns3 { |
49 | |
50 class Address; | |
51 class Socket; | |
52 class Packet; | |
53 class RuntimeVariable; | |
54 | |
55 namespace http { | 53 namespace http { |
56 | 54 |
| 55 /** |
| 56 * \brief Implements the HttpServer applications. |
| 57 * |
| 58 * This class deals with http server side operations, like receiving http reques
t and |
| 59 * sending back http response. |
| 60 * |
| 61 * \see HttpHelper |
| 62 */ |
57 class HttpServer : public Application | 63 class HttpServer : public Application |
58 { | 64 { |
59 public: | 65 public: |
60 /** | 66 static TypeId |
61 * \brief Get the type identificator. | 67 GetTypeId (void); |
62 * \return type identificator | 68 |
63 */ | |
64 static TypeId GetTypeId (void); | |
65 /** | 69 /** |
66 * \brief Constructor. | 70 * \brief Constructor. |
67 */ | 71 */ |
68 HttpServer (); | 72 HttpServer (); |
| 73 ~HttpServer (); |
| 74 |
| 75 void SetServerApplication (); |
69 /** | 76 /** |
70 * \brief Destructor. | 77 * \brief Notify that the connection has requested |
| 78 * \param socket the socket we used for http connection |
| 79 * \param address the address |
71 */ | 80 */ |
72 virtual ~HttpServer (); | 81 bool ConnectionRequested (Ptr<Socket> socket, const Address& address); |
73 void SetRuntimeVariable (Ptr<http::RuntimeVariable>); | 82 /** |
74 Ptr<http::RuntimeVariable> GetRuntimeVariable () const; | 83 * \brief Notify that the new connection has been created |
75 | 84 * \param socket the socket we used for http connection |
76 protected: | 85 * \param address the address |
77 virtual void DoDispose (void); | 86 */ |
| 87 void ConnectionAccepted (Ptr<Socket> socket, const Address& address); |
| 88 /** |
| 89 * \brief The server starts to receive packet from the client |
| 90 * \param socket the socket we used for http connection |
| 91 */ |
| 92 void ServerReceive (Ptr<Socket> socket); |
| 93 /** |
| 94 * \brief Find the first in-line request ADU size |
| 95 * \param requestSize The request ADU size |
| 96 */ |
| 97 uint32_t FindFirstRequestSize (AduContainer & serverContainer); |
| 98 /** |
| 99 * \brief Update the first in-line request ADU size |
| 100 * \param requestSize The request ADU size to be updated to |
| 101 */ |
| 102 void UpdateFirstRequestSize (AduContainer & serverContainer, uint32_t requestS
ize); |
| 103 /** |
| 104 * \brief Remove the first in-line request ADU |
| 105 */ |
| 106 void RemoveFirstRequestSize (AduContainer & serverContainer); |
| 107 /** |
| 108 * Set and get the http controller |
| 109 */ |
| 110 void SetController (Ptr<HttpController> r); |
| 111 Ptr<HttpController> GetController () const; |
| 112 void PrintContainer (const AduContainer & container); |
78 | 113 |
79 private: | 114 private: |
80 // inherited from Application base class. | 115 /** |
81 // Called at time specified by Start | 116 * \brief Called at time specified by Start to start application |
| 117 */ |
82 virtual void StartApplication (void); | 118 virtual void StartApplication (void); |
83 // Called at time specified by Stop | 119 /** |
| 120 * \brief Called at time specified by Stop to terminate application |
| 121 */ |
84 virtual void StopApplication (void); | 122 virtual void StopApplication (void); |
85 // Called when the connection has been requested | |
86 virtual bool ConnectionRequested (Ptr<Socket>, const Address&); | |
87 // Called when the connection has been accepted | |
88 virtual void ConnectionAccepted (Ptr<Socket>, const Address&); | |
89 // Handle the packet received from socket | |
90 void HandleRead (Ptr<Socket> socket); | |
91 // Call the next web session | |
92 void NextSession (); | |
93 // Call the http response | |
94 void CallHttpResponse (); | |
95 // Generate the response based predefined response size after receiving the re
quest | |
96 void ResponseGen (uint32_t rspsizeS, uint16_t session, uint8_t page, uint8_t o
bject); | |
97 | 123 |
98 Ptr<Socket> m_socket; // Associated socket | 124 bool m_firstConnection; ///< The first c
onnection or not |
99 Address m_local; // Local address to bind to | 125 bool m_persistent; ///< The persist
ent connection or not |
100 TypeId m_tid; // Protocol TypeId | 126 Address m_local; ///< Address whe
re this HttpServer application is running. |
101 uint32_t m_connections; // Current active connection cou
nt | 127 Ptr<HttpController> m_controller; ///< The pointer
to http controller |
102 uint32_t m_maxConnections; // Maximum simultaneous connecti
ons allowed | 128 Ptr<Socket> m_socket; ///< The socket
to work with |
103 uint32_t m_reqsizeS; // The request size | 129 uint32_t m_pageTimeout; ///< The page ti
me out value |
104 uint32_t m_rspsizeS; // The response size | 130 uint32_t m_run; ///< The number
of simulation runs |
105 uint32_t m_reqs; // total number of requests | 131 TypeId m_tid; ///< The transpo
rt protocol id to pass in (default. tcp) |
106 bool m_lastreq; // is this the last request? | |
107 uint32_t m_totalbytes; // total bytes received so far | |
108 double m_serverDelay; // The server delay time | |
109 uint32_t m_mtu; // The MTU of the TCP connection
s | |
110 uint32_t m_seqHeader; // The header to identify differ
ent page and object | |
111 Ipv4Address m_server; // The ip address of server | |
112 std::vector<Ipv4Address> m_connection; // The connection identification
based ip addresses | |
113 /* | |
114 * The pointers | |
115 */ | |
116 Ptr<Node> m_node; | |
117 Ptr<Ipv4> m_ipv4; | |
118 Ptr<http::RuntimeVariable> m_runtimeVariable; | |
119 }; | 132 }; |
| 133 |
| 134 } // namespace ns3 |
120 } // namespace http | 135 } // namespace http |
121 } // namespace ns3 | |
122 | 136 |
123 #endif | 137 #endif /* HTTP_SERVER */ |
LEFT | RIGHT |