INET Framework for OMNeT++/OMNEST
inet::httptools::HttpBrowser Class Reference

Browser module. More...

#include <HttpBrowser.h>

Inheritance diagram for inet::httptools::HttpBrowser:
inet::httptools::HttpBrowserBase inet::TCPSocket::CallbackInterface inet::httptools::HttpNodeBase inet::ILifecycle

Classes

struct  SockData
 

Public Member Functions

 HttpBrowser ()
 
virtual ~HttpBrowser ()
 
- Public Member Functions inherited from inet::httptools::HttpBrowserBase
 HttpBrowserBase ()
 
virtual ~HttpBrowserBase ()
 
- Public Member Functions inherited from inet::httptools::HttpNodeBase
 HttpNodeBase ()
 
- Public Member Functions inherited from inet::ILifecycle
virtual ~ILifecycle ()
 
- Public Member Functions inherited from inet::TCPSocket::CallbackInterface
virtual ~CallbackInterface ()
 

Protected Member Functions

virtual void initialize (int stage) override
 
virtual void finish () override
 
virtual void handleMessage (cMessage *msg) override
 
int numInitStages () const override
 
virtual void sendRequestToServer (BrowseEvent be) override
 
virtual void sendRequestToServer (HttpRequestMessage *request) override
 
virtual void sendRequestToRandomServer () override
 
virtual void sendRequestsToServer (std::string www, HttpRequestQueue queue) override
 
virtual void socketEstablished (int connId, void *yourPtr) override
 
virtual void socketDataArrived (int connId, void *yourPtr, cPacket *msg, bool urgent) override
 
virtual void socketPeerClosed (int connId, void *yourPtr) override
 
virtual void socketClosed (int connId, void *yourPtr) override
 
virtual void socketFailure (int connId, void *yourPtr, int code) override
 
virtual void socketStatusArrived (int connId, void *yourPtr, TCPStatusInfo *status) override
 
virtual void socketDeleted (int connId, void *yourPtr) override
 
void submitToSocket (const char *moduleName, int connectPort, HttpRequestMessage *msg)
 
void submitToSocket (const char *moduleName, int connectPort, HttpRequestQueue &queue)
 Establishes a socket and assigns a queue of messages to be transmitted. More...
 
- Protected Member Functions inherited from inet::httptools::HttpBrowserBase
void handleDataMessage (cMessage *msg)
 
void handleSelfMessages (cMessage *msg)
 
void handleSelfActivityStart ()
 
void handleSelfStartSession ()
 
void handleSelfNextMessage ()
 
void handleSelfScriptedEvent ()
 
void handleSelfDelayedRequestMessage (cMessage *msg)
 
void scheduleNextBrowseEvent ()
 
HttpRequestMessagegeneratePageRequest (std::string www, std::string page, bool bad=false, int size=0)
 
HttpRequestMessagegenerateRandomPageRequest (std::string www, bool bad=false, int size=0)
 
HttpRequestMessagegenerateResourceRequest (std::string www, std::string resource="", int serial=0, bool bad=false, int size=0)
 
void readScriptedEvents (const char *filename)
 
- Protected Member Functions inherited from inet::httptools::HttpNodeBase
void sendDirectToModule (HttpNodeBase *receiver, cPacket *packet, simtime_t constdelay=0.0, rdObject *rd=nullptr)
 
double transmissionDelay (cPacket *packet)
 
void logRequest (const HttpRequestMessage *httpRequest)
 
void logResponse (const HttpReplyMessage *httpResponse)
 
void logEntry (std::string line)
 
std::string formatHttpRequestShort (const HttpRequestMessage *httpRequest)
 
std::string formatHttpResponseShort (const HttpReplyMessage *httpResponse)
 
std::string formatHttpRequestLong (const HttpRequestMessage *httpRequest)
 
std::string formatHttpResponseLong (const HttpReplyMessage *httpResponse)
 
virtual bool handleOperationStage (LifecycleOperation *operation, int stage, IDoneCallback *doneCallback) override
 Perform one stage of a lifecycle operation. More...
 

Protected Attributes

TCPSocketMap sockCollection
 
unsigned long numBroken = 0
 
unsigned long socketsOpened = 0
 
- Protected Attributes inherited from inet::httptools::HttpBrowserBase
cMessage * eventTimer = nullptr
 
HttpControllercontroller = nullptr
 
bool scriptedMode = false
 
BrowseEventsList browseEvents
 
int reqInCurSession = 0
 
int reqNoInCurSession = 0
 
simtime_t acitivityPeriodEnd
 
rdObjectrdProcessingDelay = nullptr
 
rdObjectrdActivityLength = nullptr
 
rdObjectrdInterRequestInterval = nullptr
 
rdObjectrdInterSessionInterval = nullptr
 
rdObjectrdRequestSize = nullptr
 
rdObjectrdReqInSession = nullptr
 
long htmlRequested = 0
 
long htmlReceived = 0
 
long htmlErrorsReceived = 0
 
long imgResourcesRequested = 0
 
long imgResourcesReceived = 0
 
long textResourcesRequested = 0
 
long textResourcesReceived = 0
 
long messagesInCurrentSession = 0
 
long sessionCount = 0
 
long connectionsCount = 0
 
- Protected Attributes inherited from inet::httptools::HttpNodeBase
unsigned long linkSpeed = 0
 
int httpProtocol = 0
 
std::string logFileName
 
bool enableLogging = true
 
LOG_FORMAT outputFormat = lf_short
 
bool m_bDisplayMessage = true
 
bool m_bDisplayResponseContent = true
 
cModule * host = nullptr
 

Additional Inherited Members

- Protected Types inherited from inet::httptools::HttpBrowserBase
typedef std::deque< BrowseEventBrowseEventsList
 
typedef std::deque< HttpRequestMessage * > HttpRequestQueue
 

Detailed Description

Browser module.

The component is designed to plug into the existing INET StandardHost module as a tcpApp. See the INET documentation and examples for details.

This component uses the TCP/IP modeling of the INET framework for transport. Specifically, the TCPSocket class is used to interface with the TCP component from the INET framework. A light-weight module which uses direct message passing is also available (HttpBrowserDirect).

Author
Kristjan V. Jonsson (krist.nosp@m.janv.nosp@m.j@gma.nosp@m.il.c.nosp@m.om)
See also
HttpBrowserBase
HttpBrowserDirect

Constructor & Destructor Documentation

inet::httptools::HttpBrowser::HttpBrowser ( )
27 {
28 }
inet::httptools::HttpBrowser::~HttpBrowser ( )
virtual
31 {
32  // @todo Delete socket data structures
34 }
void deleteSockets()
Deletes the socket objects.
Definition: TCPSocketMap.cc:50
TCPSocketMap sockCollection
Definition: HttpBrowser.h:62

Member Function Documentation

void inet::httptools::HttpBrowser::finish ( )
overrideprotectedvirtual

Reimplemented from inet::httptools::HttpBrowserBase.

43 {
44  // Call the parent class finish. Takes care of most of the reporting.
46 
47  // Report sockets related statistics.
48  EV_INFO << "Sockets opened: " << socketsOpened << endl;
49  EV_INFO << "Broken connections: " << numBroken << endl;
50  // Record the sockets related statistics
51  recordScalar("sock.opened", socketsOpened);
52  recordScalar("sock.broken", numBroken);
53 }
unsigned long socketsOpened
Definition: HttpBrowser.h:64
virtual void finish() override
Definition: HttpBrowserBase.cc:166
unsigned long numBroken
Definition: HttpBrowser.h:63
void inet::httptools::HttpBrowser::handleMessage ( cMessage *  msg)
overrideprotectedvirtual

Implements inet::httptools::HttpBrowserBase.

56 {
57  if (msg->isSelfMessage()) {
58  handleSelfMessages(msg);
59  }
60  else {
61  EV_DEBUG << "Message received: " << msg->getName() << endl;
62 
63  TCPCommand *ind = dynamic_cast<TCPCommand *>(msg->getControlInfo());
64  if (!ind) {
65  EV_DEBUG << "No control info for the message" << endl;
66  }
67  else {
68  int connId = ind->getConnId();
69  EV_DEBUG << "Connection ID: " << connId << endl;
70  }
71 
72  // Locate the socket for the incoming message. One should definitely exist.
73  TCPSocket *socket = sockCollection.findSocketFor(msg);
74  if (socket == nullptr) {
75  // Handle errors. @todo error instead of warning?
76  EV_WARN << "No socket found for message " << msg->getName() << endl;
77  delete msg;
78  return;
79  }
80  // Submit to the socket handler. Calls the TCPSocket::CallbackInterface methods.
81  // Message is deleted in the socket handler
82  socket->processMessage(msg);
83  }
84 }
az accept haszálja pcb új connId
Definition: lwip_tcp.txt:38
void handleSelfMessages(cMessage *msg)
Definition: HttpBrowserBase.cc:187
TCPSocketMap sockCollection
Definition: HttpBrowser.h:62
TCPSocket * findSocketFor(cMessage *msg)
Finds the socket (by connId) for the given message.
Definition: TCPSocketMap.cc:24
void processMessage(cMessage *msg)
Examines the message (which should have arrived from TCP), updates socket state, and if there is a ca...
Definition: TCPSocket.cc:251
void inet::httptools::HttpBrowser::initialize ( int  stage)
overrideprotectedvirtual

Reimplemented from inet::httptools::HttpBrowserBase.

37 {
38  EV_DEBUG << "Initializing HTTP browser component (sockets version), stage " << stage << endl;
40 }
virtual void initialize(int stage) override
Definition: HttpBrowserBase.cc:45
int inet::httptools::HttpBrowser::numInitStages ( ) const
inlineoverrideprotectedvirtual

Reimplemented from inet::httptools::HttpBrowserBase.

70 { return NUM_INIT_STAGES; }
The number of initialization stages.
Definition: InitStages.h:116
void inet::httptools::HttpBrowser::sendRequestsToServer ( std::string  www,
HttpRequestQueue  queue 
)
overrideprotectedvirtual

Implements inet::httptools::HttpBrowserBase.

131 {
132  int connectPort;
133  char szModuleName[127];
134 
135  if (controller->getServerInfo(www.c_str(), szModuleName, connectPort) != 0) {
136  EV_ERROR << "Unable to get server info for URL " << www << endl;
137  while (!queue.empty()) {
138  HttpRequestMessage *msg = queue.back();
139  queue.pop_back();
140  delete msg;
141  }
142  return;
143  }
144 
145  EV_DEBUG << "Sending requests to server " << www << " (" << szModuleName << ") on port " << connectPort
146  << ". Total messages queued are " << queue.size() << endl;
147  submitToSocket(szModuleName, connectPort, queue);
148 }
HttpController * controller
Definition: HttpBrowserBase.h:88
void submitToSocket(const char *moduleName, int connectPort, HttpRequestMessage *msg)
Definition: HttpBrowser.cc:279
int getServerInfo(const char *wwwName, char *module, int &port)
Get module and port for a server.
Definition: HttpController.cc:221
void inet::httptools::HttpBrowser::sendRequestToRandomServer ( )
overrideprotectedvirtual

Implements inet::httptools::HttpBrowserBase.

116 {
117  int connectPort;
118  char szWWW[127];
119  char szModuleName[127];
120 
121  if (controller->getAnyServerInfo(szWWW, szModuleName, connectPort) != 0) {
122  EV_ERROR << "Unable to get a random server from controller" << endl;
123  return;
124  }
125 
126  EV_DEBUG << "Sending request to random server " << szWWW << " (" << szModuleName << ") on port " << connectPort << endl;
127  submitToSocket(szModuleName, connectPort, generateRandomPageRequest(szWWW));
128 }
HttpController * controller
Definition: HttpBrowserBase.h:88
HttpRequestMessage * generateRandomPageRequest(std::string www, bool bad=false, int size=0)
Definition: HttpBrowserBase.cc:422
int getAnyServerInfo(char *wwwName, char *module, int &port)
Get module and port for a random server.
Definition: HttpController.cc:244
void submitToSocket(const char *moduleName, int connectPort, HttpRequestMessage *msg)
Definition: HttpBrowser.cc:279
void inet::httptools::HttpBrowser::sendRequestToServer ( BrowseEvent  be)
overrideprotectedvirtual

Implements inet::httptools::HttpBrowserBase.

87 {
88  int connectPort;
89  char szModuleName[127];
90 
91  if (controller->getServerInfo(be.wwwhost.c_str(), szModuleName, connectPort) != 0) {
92  EV_ERROR << "Unable to get server info for URL " << be.wwwhost << endl;
93  return;
94  }
95 
96  EV_DEBUG << "Sending request to server " << be.wwwhost << " (" << szModuleName << ") on port " << connectPort << endl;
97  submitToSocket(szModuleName, connectPort, generatePageRequest(be.wwwhost, be.resourceName));
98 }
HttpController * controller
Definition: HttpBrowserBase.h:88
HttpRequestMessage * generatePageRequest(std::string www, std::string page, bool bad=false, int size=0)
Definition: HttpBrowserBase.cc:388
void submitToSocket(const char *moduleName, int connectPort, HttpRequestMessage *msg)
Definition: HttpBrowser.cc:279
int getServerInfo(const char *wwwName, char *module, int &port)
Get module and port for a server.
Definition: HttpController.cc:221
void inet::httptools::HttpBrowser::sendRequestToServer ( HttpRequestMessage request)
overrideprotectedvirtual

Implements inet::httptools::HttpBrowserBase.

101 {
102  int connectPort;
103  char szModuleName[127];
104 
105  if (controller->getServerInfo(request->targetUrl(), szModuleName, connectPort) != 0) {
106  EV_ERROR << "Unable to get server info for URL " << request->targetUrl() << endl;
107  delete request;
108  return;
109  }
110 
111  EV_DEBUG << "Sending request to server " << request->targetUrl() << " (" << szModuleName << ") on port " << connectPort << endl;
112  submitToSocket(szModuleName, connectPort, request);
113 }
HttpController * controller
Definition: HttpBrowserBase.h:88
void submitToSocket(const char *moduleName, int connectPort, HttpRequestMessage *msg)
Definition: HttpBrowser.cc:279
int getServerInfo(const char *wwwName, char *module, int &port)
Get module and port for a server.
Definition: HttpController.cc:221
void inet::httptools::HttpBrowser::socketClosed ( int  connId,
void *  yourPtr 
)
overrideprotectedvirtual

Reimplemented from inet::TCPSocket::CallbackInterface.

226 {
227  EV_INFO << "Socket " << connId << " closed" << endl;
228 
229  if (yourPtr == nullptr) {
230  EV_ERROR << "socketClosed failure. Null pointer" << endl;
231  return;
232  }
233 
234  SockData *sockdata = (SockData *)yourPtr;
235  TCPSocket *socket = sockdata->socket;
237  delete socket;
238 }
az accept haszálja pcb új connId
Definition: lwip_tcp.txt:38
TCPSocket * removeSocket(TCPSocket *socket)
Removes the given socket from the data structure.
Definition: TCPSocketMap.cc:42
TCPSocketMap sockCollection
Definition: HttpBrowser.h:62
void inet::httptools::HttpBrowser::socketDataArrived ( int  connId,
void *  yourPtr,
cPacket *  msg,
bool  urgent 
)
overrideprotectedvirtual

Implements inet::TCPSocket::CallbackInterface.

183 {
184  EV_DEBUG << "Socket data arrived on connection " << connId << ": " << msg->getName() << endl;
185  if (yourPtr == nullptr) {
186  EV_ERROR << "socketDataArrivedfailure. Null pointer" << endl;
187  return;
188  }
189 
190  SockData *sockdata = (SockData *)yourPtr;
191  TCPSocket *socket = sockdata->socket;
192  handleDataMessage(msg);
193 
194  if (--sockdata->pending == 0) {
195  EV_DEBUG << "Received last expected reply on this socket. Issuing a close" << endl;
196  socket->close();
197  }
198  // Message deleted in handler - do not delete here!
199 }
az accept haszálja pcb új connId
Definition: lwip_tcp.txt:38
void handleDataMessage(cMessage *msg)
Definition: HttpBrowserBase.cc:276
void inet::httptools::HttpBrowser::socketDeleted ( int  connId,
void *  yourPtr 
)
overrideprotectedvirtual

Reimplemented from inet::TCPSocket::CallbackInterface.

262 {
263  if (yourPtr == nullptr) {
264  throw cRuntimeError("Model error: socketDelete failure. yourPtr is null pointer");
265  }
266 
267  SockData *sockdata = (SockData *)yourPtr;
268  TCPSocket *socket = sockdata->socket;
269  ASSERT(connId == socket->getConnectionId());
270  HttpRequestQueue& queue = sockdata->messageQueue;
271  while (!queue.empty()) {
272  HttpRequestMessage *msg = queue.back();
273  queue.pop_back();
274  delete msg;
275  }
276  delete sockdata;
277 }
az accept haszálja pcb új connId
Definition: lwip_tcp.txt:38
std::deque< HttpRequestMessage * > HttpRequestQueue
Definition: HttpBrowserBase.h:85
void inet::httptools::HttpBrowser::socketEstablished ( int  connId,
void *  yourPtr 
)
overrideprotectedvirtual

Reimplemented from inet::TCPSocket::CallbackInterface.

151 {
152  EV_DEBUG << "Socket with id " << connId << " established" << endl;
153 
154  socketsOpened++;
155 
156  if (yourPtr == nullptr) {
157  EV_ERROR << "SocketEstablished failure. Null pointer" << endl;
158  return;
159  }
160 
161  // Get the socket and associated data structure.
162  SockData *sockdata = (SockData *)yourPtr;
163  TCPSocket *socket = sockdata->socket;
164  if (sockdata->messageQueue.empty()) {
165  EV_INFO << "No data to send on socket with connection id " << connId << ". Closing" << endl;
166  socket->close();
167  return;
168  }
169 
170  // Send pending messages on the established socket.
171  EV_DEBUG << "Proceeding to send messages on socket " << connId << endl;
172  while (!sockdata->messageQueue.empty()) {
173  cMessage *msg = sockdata->messageQueue.back();
174  cPacket *pckt = check_and_cast<cPacket *>(msg);
175  sockdata->messageQueue.pop_back();
176  EV_DEBUG << "Submitting request " << msg->getName() << " to socket " << connId << ". size is " << pckt->getByteLength() << " bytes" << endl;
177  socket->send(msg);
178  sockdata->pending++;
179  }
180 }
az accept haszálja pcb új connId
Definition: lwip_tcp.txt:38
unsigned long socketsOpened
Definition: HttpBrowser.h:64
void inet::httptools::HttpBrowser::socketFailure ( int  connId,
void *  yourPtr,
int  code 
)
overrideprotectedvirtual

Reimplemented from inet::TCPSocket::CallbackInterface.

241 {
242  EV_WARN << "connection broken. Connection id " << connId << endl;
243  numBroken++;
244 
245  if (yourPtr == nullptr) {
246  EV_ERROR << "socketFailure failure. Null pointer" << endl;
247  return;
248  }
249 
250  if (code == TCP_I_CONNECTION_RESET)
251  EV_WARN << "Connection reset!\n";
252  else if (code == TCP_I_CONNECTION_REFUSED)
253  EV_WARN << "Connection refused!\n";
254 
255  SockData *sockdata = (SockData *)yourPtr;
256  TCPSocket *socket = sockdata->socket;
258  delete socket;
259 }
az accept haszálja pcb új connId
Definition: lwip_tcp.txt:38
Definition: TCPCommand_m.h:104
TCPSocket * removeSocket(TCPSocket *socket)
Removes the given socket from the data structure.
Definition: TCPSocketMap.cc:42
TCPSocketMap sockCollection
Definition: HttpBrowser.h:62
unsigned long numBroken
Definition: HttpBrowser.h:63
Definition: TCPCommand_m.h:103
void inet::httptools::HttpBrowser::socketPeerClosed ( int  connId,
void *  yourPtr 
)
overrideprotectedvirtual

Reimplemented from inet::TCPSocket::CallbackInterface.

208 {
209  EV_DEBUG << "Socket " << connId << " closed by peer" << endl;
210  if (yourPtr == nullptr) {
211  EV_ERROR << "socketPeerClosed failure. Null pointer" << endl;
212  return;
213  }
214 
215  SockData *sockdata = (SockData *)yourPtr;
216  TCPSocket *socket = sockdata->socket;
217 
218  // close the connection (if not already closed)
219  if (socket->getState() == TCPSocket::PEER_CLOSED) {
220  EV_INFO << "remote TCP closed, closing here as well. Connection id is " << connId << endl;
221  socket->close();
222  }
223 }
az accept haszálja pcb új connId
Definition: lwip_tcp.txt:38
Definition: TCPSocket.h:148
void inet::httptools::HttpBrowser::socketStatusArrived ( int  connId,
void *  yourPtr,
TCPStatusInfo status 
)
overrideprotectedvirtual

Reimplemented from inet::TCPSocket::CallbackInterface.

202 {
203  // This is obviously not used at the present time.
204  EV_INFO << "SOCKET STATUS ARRIVED. Socket: " << connId << endl;
205 }
az accept haszálja pcb új connId
Definition: lwip_tcp.txt:38
void inet::httptools::HttpBrowser::submitToSocket ( const char *  moduleName,
int  connectPort,
HttpRequestMessage msg 
)
protected

Referenced by sendRequestsToServer(), sendRequestToRandomServer(), and sendRequestToServer().

280 {
281  // Create a queue and push the single message
282  HttpRequestQueue queue;
283  queue.push_back(msg);
284  // Call the overloaded version with the queue as parameter
285  submitToSocket(moduleName, connectPort, queue);
286 }
std::deque< HttpRequestMessage * > HttpRequestQueue
Definition: HttpBrowserBase.h:85
void submitToSocket(const char *moduleName, int connectPort, HttpRequestMessage *msg)
Definition: HttpBrowser.cc:279
void inet::httptools::HttpBrowser::submitToSocket ( const char *  moduleName,
int  connectPort,
HttpRequestQueue queue 
)
protected

Establishes a socket and assigns a queue of messages to be transmitted.

Same as the overloaded version, except a number of messages are queued for transmission. The same socket instance is used for all the queued messages.

289 {
290  // Don't do anything if the queue is empty.
291  if (queue.empty()) {
292  EV_INFO << "Submitting to socket. No data to send to " << moduleName << ". Skipping connection." << endl;
293  return;
294  }
295 
296  EV_DEBUG << "Submitting to socket. Module: " << moduleName << ", port: " << connectPort << ". Total messages: " << queue.size() << endl;
297 
298  // Create and initialize the socket
299  TCPSocket *socket = new TCPSocket();
300  socket->setDataTransferMode(TCP_TRANSFER_OBJECT);
301  socket->setOutputGate(gate("tcpOut"));
302  sockCollection.addSocket(socket);
303 
304  // Initialize the associated data structure
305  SockData *sockdata = new SockData;
306  sockdata->messageQueue = HttpRequestQueue(queue);
307  sockdata->socket = socket;
308  sockdata->pending = 0;
309  socket->setCallbackObject(this, sockdata);
310 
311  // Issue a connect to the socket for the specified module and port.
312  socket->connect(L3AddressResolver().resolve(moduleName), connectPort);
313 }
std::deque< HttpRequestMessage * > HttpRequestQueue
Definition: HttpBrowserBase.h:85
void addSocket(TCPSocket *socket)
Registers the given socket.
Definition: TCPSocketMap.cc:36
TCPSocketMap sockCollection
Definition: HttpBrowser.h:62
Definition: TCPCommand_m.h:256

Member Data Documentation

unsigned long inet::httptools::HttpBrowser::numBroken = 0
protected

Referenced by finish(), and socketFailure().

TCPSocketMap inet::httptools::HttpBrowser::sockCollection
protected
unsigned long inet::httptools::HttpBrowser::socketsOpened = 0
protected

Referenced by finish(), and socketEstablished().


The documentation for this class was generated from the following files: