INET Framework for OMNeT++/OMNEST
inet::httptools::HttpBrowserBase Class Referenceabstract

A simulated browser module for OMNeT++ simulations. More...

#include <HttpBrowserBase.h>

Inheritance diagram for inet::httptools::HttpBrowserBase:
inet::httptools::HttpNodeBase inet::ILifecycle inet::httptools::HttpBrowser inet::httptools::HttpBrowserDirect

Classes

struct  BrowseEvent
 

Public Member Functions

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

Protected Types

typedef std::deque< BrowseEventBrowseEventsList
 
typedef std::deque< HttpRequestMessage * > HttpRequestQueue
 

Protected Member Functions

virtual void initialize (int stage) override
 
virtual int numInitStages () const override
 
virtual void finish () override
 
virtual void handleMessage (cMessage *msg) override=0
 
void handleDataMessage (cMessage *msg)
 
void handleSelfMessages (cMessage *msg)
 
void handleSelfActivityStart ()
 
void handleSelfStartSession ()
 
void handleSelfNextMessage ()
 
void handleSelfScriptedEvent ()
 
void handleSelfDelayedRequestMessage (cMessage *msg)
 
void scheduleNextBrowseEvent ()
 
virtual void sendRequestToServer (BrowseEvent be)=0
 
virtual void sendRequestToServer (HttpRequestMessage *request)=0
 
virtual void sendRequestToRandomServer ()=0
 
virtual void sendRequestsToServer (std::string www, HttpRequestQueue queue)=0
 
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

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
 

Detailed Description

A simulated browser module for OMNeT++ simulations.

A part of HttpTools.

The component is designed to plug into the existing INET StandardHost module as a tcpApp. See the INET documentation and examples for details. It can also be used with the simplified DirectHost, which only supports direct message passing.

The browser can operate in two modes:

  • Random request mode: The browser uses the parameters supplied and statistical distributions to make requests.
  • Scripted mode: The browser operates using a script file – requests are issued to specific URLs and at specific times.

The browser can operate in two communications modes:

  • Direct mode, in which messages are passed directly using sendDirect. This removes topology variables from the simulation and simplifies setup considerably. This mode should be used whenever the topology of the network and the resulting effects are not of interest. This is implemented in the derived HttpBrowserDirect class.
  • Socket mode, in which the INET TCPSocket is used to handle messages sent and received. This mode uses the full INET TCP/IP simulation. Requires the network topology to be set up – routers, links, etc. This is implemented in the derived HttpBrowser class.
See also
HttpBrowser
HttpBrowserDirect
Author
Kristjan V. Jonsson (krist.nosp@m.janv.nosp@m.j@gma.nosp@m.il.c.nosp@m.om)

Member Typedef Documentation

Constructor & Destructor Documentation

inet::httptools::HttpBrowserBase::HttpBrowserBase ( )
28 {
29  m_bDisplayMessage = true;
31 }
bool m_bDisplayResponseContent
Definition: HttpNodeBase.h:65
bool m_bDisplayMessage
Definition: HttpNodeBase.h:64
inet::httptools::HttpBrowserBase::~HttpBrowserBase ( )
virtual
34 {
35  delete rdProcessingDelay;
36  delete rdActivityLength;
39  delete rdRequestSize;
40  delete rdReqInSession;
41 
42  cancelAndDelete(eventTimer);
43 }
rdObject * rdProcessingDelay
Definition: HttpBrowserBase.h:99
rdObject * rdInterSessionInterval
Definition: HttpBrowserBase.h:102
cMessage * eventTimer
Definition: HttpBrowserBase.h:87
rdObject * rdRequestSize
Definition: HttpBrowserBase.h:103
rdObject * rdReqInSession
Definition: HttpBrowserBase.h:104
rdObject * rdInterRequestInterval
Definition: HttpBrowserBase.h:101
rdObject * rdActivityLength
Definition: HttpBrowserBase.h:100

Member Function Documentation

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

Reimplemented in inet::httptools::HttpBrowser, and inet::httptools::HttpBrowserDirect.

Referenced by inet::httptools::HttpBrowserDirect::finish(), and inet::httptools::HttpBrowser::finish().

167 {
168  EV_INFO << "Sessions: " << sessionCount << endl;
169  EV_INFO << "HTML requested " << htmlRequested << "\n";
170  EV_INFO << "HTML received " << htmlReceived << "\n";
171  EV_INFO << "HTML errors received " << htmlErrorsReceived << "\n";
172  EV_INFO << "Image resources requested " << imgResourcesRequested << "\n";
173  EV_INFO << "Image resources received " << imgResourcesReceived << "\n";
174  EV_INFO << "Text resources requested " << textResourcesRequested << "\n";
175  EV_INFO << "Text resources received " << textResourcesReceived << "\n";
176 
177  recordScalar("session.count", sessionCount);
178  recordScalar("html.requested", htmlRequested);
179  recordScalar("html.received", htmlReceived);
180  recordScalar("html.errors", htmlErrorsReceived);
181  recordScalar("html.image.requested", imgResourcesRequested);
182  recordScalar("html.image.received", imgResourcesReceived);
183  recordScalar("html.text.requested", textResourcesRequested);
184  recordScalar("html.text.received", textResourcesReceived);
185 }
long sessionCount
Definition: HttpBrowserBase.h:114
long textResourcesReceived
Definition: HttpBrowserBase.h:112
long htmlErrorsReceived
Definition: HttpBrowserBase.h:108
long imgResourcesReceived
Definition: HttpBrowserBase.h:110
long imgResourcesRequested
Definition: HttpBrowserBase.h:109
long htmlReceived
Definition: HttpBrowserBase.h:107
long textResourcesRequested
Definition: HttpBrowserBase.h:111
long htmlRequested
Definition: HttpBrowserBase.h:106
HttpRequestMessage * inet::httptools::HttpBrowserBase::generatePageRequest ( std::string  www,
std::string  page,
bool  bad = false,
int  size = 0 
)
protected

Referenced by generateRandomPageRequest(), inet::httptools::HttpBrowserDirect::sendRequestToServer(), and inet::httptools::HttpBrowser::sendRequestToServer().

389 {
390  EV_DEBUG << "Generating page request for URL " << www << ", page " << pageName << endl;
391 
392  if (www.size() + pageName.size() > MAX_URL_LENGTH) {
393  EV_ERROR << "URL for site " << www << " exceeds allowed maximum size" << endl;
394  return nullptr;
395  }
396 
397  long requestLength = (long)rdRequestSize->draw();
398 
399  if (pageName.empty())
400  pageName = "/";
401  else if (pageName[0] != '/')
402  pageName.insert(0, "/");
403 
404  char szReq[MAX_URL_LENGTH + 24];
405  sprintf(szReq, "GET %s HTTP/1.1", pageName.c_str());
406  HttpRequestMessage *msg = new HttpRequestMessage(szReq);
407  msg->setTargetUrl(www.c_str());
408  msg->setProtocol(httpProtocol);
409  msg->setHeading(szReq);
410  msg->setSerial(0);
411  msg->setByteLength(requestLength + size); // Add extra request size if specified
412  msg->setKeepAlive(httpProtocol == 11);
413  msg->setBadRequest(bad); // Simulates willingly requesting a non-existing resource.
414  msg->setKind(HTTPT_REQUEST_MESSAGE);
415 
416  logRequest(msg);
417  htmlRequested++;
418 
419  return msg;
420 }
void logRequest(const HttpRequestMessage *httpRequest)
Definition: HttpNodeBase.cc:61
rdObject * rdRequestSize
Definition: HttpBrowserBase.h:103
int httpProtocol
Definition: HttpNodeBase.h:60
virtual double draw()=0
#define HTTPT_REQUEST_MESSAGE
Definition: HttpNodeBase.h:39
#define MAX_URL_LENGTH
Definition: HttpBrowserBase.h:34
long htmlRequested
Definition: HttpBrowserBase.h:106
HttpRequestMessage * inet::httptools::HttpBrowserBase::generateRandomPageRequest ( std::string  www,
bool  bad = false,
int  size = 0 
)
protected

Referenced by inet::httptools::HttpBrowserDirect::sendRequestToRandomServer(), and inet::httptools::HttpBrowser::sendRequestToRandomServer().

423 {
424  EV_DEBUG << "Generating random page request, URL: " << www << endl;
425  return generatePageRequest(www, "random_page.html", bad, size);
426 }
HttpRequestMessage * generatePageRequest(std::string www, std::string page, bool bad=false, int size=0)
Definition: HttpBrowserBase.cc:388
HttpRequestMessage * inet::httptools::HttpBrowserBase::generateResourceRequest ( std::string  www,
std::string  resource = "",
int  serial = 0,
bool  bad = false,
int  size = 0 
)
protected

Referenced by handleDataMessage().

429 {
430  EV_DEBUG << "Generating resource request for URL " << www << ", resource: " << resource << endl;
431 
432  if (www.size() + resource.size() > MAX_URL_LENGTH) {
433  EV_ERROR << "URL for site " << www << " exceeds allowed maximum size" << endl;
434  return nullptr;
435  }
436 
437  long requestLength = (long)rdRequestSize->draw() + size;
438 
439  if (resource.empty()) {
440  EV_ERROR << "Unable to request resource -- empty resource string" << endl;
441  return nullptr;
442  }
443  else if (resource[0] != '/')
444  resource.insert(0, "/");
445 
446  std::string ext = trimLeft(resource, ".");
448  if (rc == CT_IMAGE)
450  else if (rc == CT_TEXT)
452 
453  char szReq[MAX_URL_LENGTH + 24];
454  sprintf(szReq, "GET %s HTTP/1.1", resource.c_str());
455 
456  HttpRequestMessage *msg = new HttpRequestMessage(szReq);
457  msg->setTargetUrl(www.c_str());
458  msg->setProtocol(httpProtocol);
459  msg->setHeading(szReq);
460  msg->setSerial(serial);
461  msg->setByteLength(requestLength); // Add extra request size if specified
462  msg->setKeepAlive(httpProtocol == 11);
463  msg->setBadRequest(bad); // Simulates willingly requesting a non-existing resource.
464  msg->setKind(HTTPT_REQUEST_MESSAGE);
465 
466  logRequest(msg);
467 
468  return msg;
469 }
HttpContentType
Enum generated from inet/applications/httptools/common/HttpMessages.msg:99 by nedtool.
Definition: HttpMessages_m.h:160
void logRequest(const HttpRequestMessage *httpRequest)
Definition: HttpNodeBase.cc:61
std::string trimLeft(std::string s)
Definition: HttpUtils.cc:29
rdObject * rdRequestSize
Definition: HttpBrowserBase.h:103
Definition: HttpMessages_m.h:163
int httpProtocol
Definition: HttpNodeBase.h:60
HttpContentType getResourceCategory(std::vector< std::string > res)
Definition: HttpUtils.cc:142
virtual double draw()=0
#define HTTPT_REQUEST_MESSAGE
Definition: HttpNodeBase.h:39
#define MAX_URL_LENGTH
Definition: HttpBrowserBase.h:34
long imgResourcesRequested
Definition: HttpBrowserBase.h:109
Definition: HttpMessages_m.h:164
long textResourcesRequested
Definition: HttpBrowserBase.h:111
void inet::httptools::HttpBrowserBase::handleDataMessage ( cMessage *  msg)
protected

Referenced by inet::httptools::HttpBrowserDirect::handleMessage(), and inet::httptools::HttpBrowser::socketDataArrived().

277 {
278  HttpReplyMessage *appmsg = check_and_cast<HttpReplyMessage *>(msg);
279  if (appmsg == nullptr)
280  throw cRuntimeError("Message (%s)%s is not a valid reply message", msg->getClassName(), msg->getName());
281 
282  logResponse(appmsg);
283 
285 
286  int serial = appmsg->serial();
287 
288  std::string senderWWW = appmsg->originatorUrl();
289  EV_DEBUG << "Handling received message from " << senderWWW << ": " << msg->getName() << ". Received @T=" << simTime() << endl;
290 
291  if (appmsg->result() != 200 || (HttpContentType)appmsg->contentType() == CT_UNKNOWN) {
292  EV_INFO << "Result for " << appmsg->getName() << " was other than OK. Code: " << appmsg->result() << endl;
294  delete msg;
295  return;
296  }
297  else {
298  switch ((HttpContentType)appmsg->contentType()) {
299  case CT_HTML:
300  EV_INFO << "HTML Document received: " << appmsg->getName() << "'. Size is " << appmsg->getByteLength() << " bytes and serial " << serial << endl;
301  if (strlen(appmsg->payload()) != 0)
302  EV_DEBUG << "Payload of " << appmsg->getName() << " is: " << endl << appmsg->payload()
303  << ", " << strlen(appmsg->payload()) << " bytes" << endl;
304  else
305  EV_DEBUG << appmsg->getName() << " has no referenced resources. No GETs will be issued in parsing" << endl;
306  htmlReceived++;
307  if (hasGUI())
308  bubble("Received a HTML document");
309  break;
310 
311  case CT_TEXT:
312  EV_INFO << "Text resource received: " << appmsg->getName() << "'. Size is " << appmsg->getByteLength() << " bytes and serial " << serial << endl;
314  if (hasGUI())
315  bubble("Received a text resource");
316  break;
317 
318  case CT_IMAGE:
319  EV_INFO << "Image resource received: " << appmsg->getName() << "'. Size is " << appmsg->getByteLength() << " bytes and serial " << serial << endl;
321  if (hasGUI())
322  bubble("Received an image resource");
323  break;
324 
325  case CT_UNKNOWN:
326  EV_DEBUG << "UNKNOWN RESOURCE TYPE RECEIVED: " << (HttpContentType)appmsg->contentType() << endl;
327  if (hasGUI())
328  bubble("Received an unknown resource type");
329  break;
330  }
331  // Parse the html page body
332  if ((HttpContentType)appmsg->contentType() == CT_HTML && strlen(appmsg->payload()) != 0) {
333  EV_DEBUG << "Processing HTML document body:\n";
334  cStringTokenizer lineTokenizer((const char *)appmsg->payload(), "\n");
335  std::vector<std::string> lines = lineTokenizer.asVector();
336  std::map<std::string, HttpRequestQueue> requestQueues;
337  for (auto resourceLine : lines) {
338  cStringTokenizer fieldTokenizer(resourceLine.c_str(), ";");
339  std::vector<std::string> fields = fieldTokenizer.asVector();
340  if (fields.size() < 1) {
341  EV_ERROR << "Invalid resource reference in received message: " << resourceLine << endl;
342  continue;
343  }
344  // Get the resource name -- this is mandatory for all references
345  std::string resourceName = fields[0];
346 
347  std::string providerName = senderWWW;
348  if (fields.size() > 1)
349  providerName = fields[1];
350 
351  double delay = 0.0;
352  if (fields.size() > 2)
353  delay = safeatof(fields[2].c_str());
354 
355  bool bad = false;
356  if (fields.size() > 3)
357  bad = safeatobool(fields[3].c_str());
358 
359  int refSize = 0;
360  if (fields.size() > 4)
361  refSize = safeatoi(fields[4].c_str());
362 
363  EV_DEBUG << "Generating resource request: " << resourceName << ". Provider: " << providerName
364  << ", delay: " << delay << ", bad: " << bad << ", ref.size: " << refSize << endl;
365 
366  // Generate a request message and push on queue for the intended recipient
367  HttpRequestMessage *reqmsg = generateResourceRequest(providerName, resourceName, serial++, bad, refSize); // TODO: KVJ: CHECK HERE FOR XSITE
368  if (delay == 0.0) {
369  requestQueues[providerName].push_front(reqmsg);
370  }
371  else {
372  reqmsg->setKind(HTTPT_DELAYED_REQUEST_MESSAGE);
373  scheduleAt(simTime() + delay, reqmsg); // Schedule the message as a self message
374  }
375  }
376  // Iterate through the list of queues (one for each recipient encountered) and submit each queue.
377  // A single socket will thus be opened for each recipient for a rough HTTP/1.1 emulation.
378  // This is only done for messages which are not delayed in the simulated page.
379  auto i = requestQueues.begin();
380  for ( ; i != requestQueues.end(); i++)
381  sendRequestsToServer((*i).first, (*i).second);
382  }
383  }
384 
385  delete msg;
386 }
HttpContentType
Enum generated from inet/applications/httptools/common/HttpMessages.msg:99 by nedtool.
Definition: HttpMessages_m.h:160
int safeatobool(const char *strval, bool defaultVal)
Definition: HttpUtils.cc:199
double safeatof(const char *strval, double defaultVal)
Definition: HttpUtils.cc:179
#define HTTPT_DELAYED_REQUEST_MESSAGE
Definition: HttpNodeBase.h:40
virtual void sendRequestsToServer(std::string www, HttpRequestQueue queue)=0
long textResourcesReceived
Definition: HttpBrowserBase.h:112
Definition: HttpMessages_m.h:163
long htmlErrorsReceived
Definition: HttpBrowserBase.h:108
Definition: HttpMessages_m.h:161
HttpRequestMessage * generateResourceRequest(std::string www, std::string resource="", int serial=0, bool bad=false, int size=0)
Definition: HttpBrowserBase.cc:428
void logResponse(const HttpReplyMessage *httpResponse)
Definition: HttpNodeBase.cc:73
int safeatoi(const char *strval, int defaultVal)
Definition: HttpUtils.cc:189
long imgResourcesReceived
Definition: HttpBrowserBase.h:110
Definition: HttpMessages_m.h:162
long messagesInCurrentSession
Definition: HttpBrowserBase.h:113
Definition: HttpMessages_m.h:164
long htmlReceived
Definition: HttpBrowserBase.h:107
virtual void inet::httptools::HttpBrowserBase::handleMessage ( cMessage *  msg)
overrideprotectedpure virtual
void inet::httptools::HttpBrowserBase::handleSelfActivityStart ( )
protected

Referenced by handleSelfMessages().

213 {
214  EV_DEBUG << "Starting new activity period @ T=" << simTime() << endl;
217  reqNoInCurSession = 0;
218  double activityPeriodLength = rdActivityLength->draw(); // Get the length of the activity period
219  acitivityPeriodEnd = simTime() + activityPeriodLength; // The end of the activity period
220  EV_INFO << "Activity period starts @ T=" << simTime() << ". Activity period is " << activityPeriodLength / 3600 << " hours." << endl;
221  scheduleAt(simTime() + (simtime_t)rdInterSessionInterval->draw() / 2, eventTimer);
222 }
rdObject * rdInterSessionInterval
Definition: HttpBrowserBase.h:102
cMessage * eventTimer
Definition: HttpBrowserBase.h:87
int reqNoInCurSession
Definition: HttpBrowserBase.h:95
#define MSGKIND_START_SESSION
Definition: HttpBrowserBase.h:29
virtual double draw()=0
long messagesInCurrentSession
Definition: HttpBrowserBase.h:113
rdObject * rdActivityLength
Definition: HttpBrowserBase.h:100
simtime_t acitivityPeriodEnd
Definition: HttpBrowserBase.h:96
void inet::httptools::HttpBrowserBase::handleSelfDelayedRequestMessage ( cMessage *  msg)
protected

Referenced by handleSelfMessages().

269 {
270  EV_DEBUG << "Sending delayed message " << msg->getName() << " @ T=" << simTime() << endl;
271  HttpRequestMessage *reqmsg = check_and_cast<HttpRequestMessage *>(msg);
272  reqmsg->setKind(HTTPT_REQUEST_MESSAGE);
273  sendRequestToServer(reqmsg);
274 }
virtual void sendRequestToServer(BrowseEvent be)=0
#define HTTPT_REQUEST_MESSAGE
Definition: HttpNodeBase.h:39
void inet::httptools::HttpBrowserBase::handleSelfMessages ( cMessage *  msg)
protected

Referenced by inet::httptools::HttpBrowserDirect::handleMessage(), and inet::httptools::HttpBrowser::handleMessage().

188 {
189  switch (msg->getKind()) {
192  break;
193 
196  break;
197 
200  break;
201 
204  break;
205 
208  break;
209  }
210 }
void handleSelfActivityStart()
Definition: HttpBrowserBase.cc:212
#define MSGKIND_NEXT_MESSAGE
Definition: HttpBrowserBase.h:30
#define HTTPT_DELAYED_REQUEST_MESSAGE
Definition: HttpNodeBase.h:40
#define MSGKIND_SCRIPT_EVENT
Definition: HttpBrowserBase.h:31
void handleSelfDelayedRequestMessage(cMessage *msg)
Definition: HttpBrowserBase.cc:268
void handleSelfScriptedEvent()
Definition: HttpBrowserBase.cc:245
#define MSGKIND_START_SESSION
Definition: HttpBrowserBase.h:29
#define MSGKIND_ACTIVITY_START
Definition: HttpBrowserBase.h:32
void handleSelfNextMessage()
Definition: HttpBrowserBase.cc:236
void handleSelfStartSession()
Definition: HttpBrowserBase.cc:224
void inet::httptools::HttpBrowserBase::handleSelfNextMessage ( )
protected

Referenced by handleSelfMessages().

237 {
238  EV_DEBUG << "New browse event triggered @ T=" << simTime() << endl;
239  EV_INFO << "Next message in session # " << sessionCount << " @ T=" << simTime() << ". "
240  << "Current request is " << reqInCurSession << "/" << reqNoInCurSession << "\n";
243 }
int reqInCurSession
Definition: HttpBrowserBase.h:94
void scheduleNextBrowseEvent()
Definition: HttpBrowserBase.cc:471
long sessionCount
Definition: HttpBrowserBase.h:114
int reqNoInCurSession
Definition: HttpBrowserBase.h:95
virtual void sendRequestToRandomServer()=0
void inet::httptools::HttpBrowserBase::handleSelfScriptedEvent ( )
protected

Referenced by handleSelfMessages().

246 {
247  EV_DEBUG << "Scripted browse event @ T=" << simTime() << "\n";
248  sessionCount++;
250  // Get the browse event
251  if (browseEvents.empty())
252  throw cRuntimeError("No event entry in queue");
253  BrowseEvent be = browseEvents.back();
254  browseEvents.pop_back();
256  // Schedule the next event
257  if (!browseEvents.empty()) {
258  be = browseEvents.back();
259  EV_DEBUG << "Scheduling next event @ " << be.time << "\n";
261  scheduleAt(be.time, eventTimer);
262  }
263  else {
264  EV_DEBUG << "No more browsing events\n";
265  }
266 }
virtual void sendRequestToServer(BrowseEvent be)=0
BrowseEventsList browseEvents
Definition: HttpBrowserBase.h:91
long sessionCount
Definition: HttpBrowserBase.h:114
cMessage * eventTimer
Definition: HttpBrowserBase.h:87
#define MSGKIND_SCRIPT_EVENT
Definition: HttpBrowserBase.h:31
long messagesInCurrentSession
Definition: HttpBrowserBase.h:113
void inet::httptools::HttpBrowserBase::handleSelfStartSession ( )
protected

Referenced by handleSelfMessages().

225 {
226  EV_DEBUG << "Starting new session @ T=" << simTime() << endl;
227  sessionCount++;
229  reqInCurSession = 0;
231  EV_INFO << "Starting session # " << sessionCount << " @ T=" << simTime() << ". Requests in session are " << reqNoInCurSession << "\n";
234 }
int reqInCurSession
Definition: HttpBrowserBase.h:94
void scheduleNextBrowseEvent()
Definition: HttpBrowserBase.cc:471
long sessionCount
Definition: HttpBrowserBase.h:114
int reqNoInCurSession
Definition: HttpBrowserBase.h:95
rdObject * rdReqInSession
Definition: HttpBrowserBase.h:104
virtual double draw()=0
long messagesInCurrentSession
Definition: HttpBrowserBase.h:113
virtual void sendRequestToRandomServer()=0
void inet::httptools::HttpBrowserBase::initialize ( int  stage)
overrideprotectedvirtual

Reimplemented from inet::httptools::HttpNodeBase.

Reimplemented in inet::httptools::HttpBrowser, and inet::httptools::HttpBrowserDirect.

Referenced by inet::httptools::HttpBrowserDirect::initialize(), and inet::httptools::HttpBrowser::initialize().

46 {
47  EV_DEBUG << "Initializing base HTTP browser component -- stage " << stage << endl;
48 
50 
51  if (stage == INITSTAGE_LOCAL) {
52  cXMLElement *rootelement = par("config").xmlValue();
53  if (rootelement == nullptr)
54  throw cRuntimeError("Configuration file is not defined");
55 
56  cXMLAttributeMap attributes;
57  rdObjectFactory rdFactory;
58 
59  // Activity period length -- the waking period
60  cXMLElement *element = rootelement->getFirstChildWithTag("activityPeriod");
61  if (element == nullptr) {
62  rdActivityLength = nullptr; // Disabled if this parameter is not defined in the file
63  }
64  else {
65  attributes = element->getAttributes();
66  rdActivityLength = rdFactory.create(attributes);
67  if (rdActivityLength == nullptr)
68  throw cRuntimeError("Activity period random object could not be created");
69  }
70 
71  // Inter-session interval
72  element = rootelement->getFirstChildWithTag("interSessionInterval");
73  if (element == nullptr)
74  throw cRuntimeError("Inter-request interval parameter undefined in XML configuration");
75  attributes = element->getAttributes();
76  rdInterSessionInterval = rdFactory.create(attributes);
77  if (rdInterSessionInterval == nullptr)
78  throw cRuntimeError("Inter-session interval random object could not be created");
79 
80  // Inter-request interval
81  element = rootelement->getFirstChildWithTag("InterRequestInterval");
82  if (element == nullptr)
83  throw cRuntimeError("Inter-request interval parameter undefined in XML configuration");
84  attributes = element->getAttributes();
85  rdInterRequestInterval = rdFactory.create(attributes);
86  if (rdInterRequestInterval == nullptr)
87  throw cRuntimeError("Inter-request interval random object could not be created");
88 
89  // Request size
90  element = rootelement->getFirstChildWithTag("requestSize");
91  if (element == nullptr)
92  throw cRuntimeError("Inter-request interval parameter undefined in XML configuration");
93  attributes = element->getAttributes();
94  rdRequestSize = rdFactory.create(attributes);
95  if (rdRequestSize == nullptr)
96  throw cRuntimeError("Request size random object could not be created");
97 
98  // Requests in session
99  element = rootelement->getFirstChildWithTag("reqInSession");
100  if (element == nullptr)
101  throw cRuntimeError("requests in session parameter undefined in XML configuration");
102  attributes = element->getAttributes();
103  rdReqInSession = rdFactory.create(attributes);
104  if (rdReqInSession == nullptr)
105  throw cRuntimeError("Requests in session random object could not be created");
106 
107  // Processing delay
108  element = rootelement->getFirstChildWithTag("processingDelay");
109  if (element == nullptr)
110  throw cRuntimeError("processing delay parameter undefined in XML configuration");
111  attributes = element->getAttributes();
112  rdProcessingDelay = rdFactory.create(attributes);
113  if (rdProcessingDelay == nullptr)
114  throw cRuntimeError("Processing delay random object could not be created");
115 
116  controller = getModuleFromPar<HttpController>(par("httpBrowserControllerModule"), this);
117 
118  httpProtocol = par("httpProtocol");
119 
120  logFileName = par("logFile").stdstringValue();
121  enableLogging = logFileName != "";
123 
124  // Initialize counters
125  htmlRequested = 0;
126  htmlReceived = 0;
127  htmlErrorsReceived = 0;
133  connectionsCount = 0;
134  sessionCount = 0;
135 
136  reqInCurSession = 0;
137  reqNoInCurSession = 0;
138 
139  eventTimer = new cMessage("eventTimer");
140  }
141  else if (stage == INITSTAGE_APPLICATION_LAYER) {
142  EV_DEBUG << "Initializing base HTTP browser component -- phase 1\n";
143 
144  NodeStatus *nodeStatus = dynamic_cast<NodeStatus *>(findContainingNode(this)->getSubmodule("status"));
145  bool isOperational = (!nodeStatus) || nodeStatus->getState() == NodeStatus::UP;
146  if (!isOperational)
147  throw cRuntimeError("This module doesn't support starting in node DOWN state");
148 
149  std::string scriptFile = par("scriptFile").stdstringValue();
150  scriptedMode = !scriptFile.empty();
151  if (scriptedMode) {
152  EV_DEBUG << "Scripted mode. Script file: " << scriptFile << endl;
153  readScriptedEvents(scriptFile.c_str());
154  }
155  else {
156  double activationTime = par("activationTime"); // This is the activation delay. Optional
157  if (rdActivityLength != nullptr)
158  activationTime += (86400.0 - rdActivityLength->draw()) / 2; // First activate after half the sleep period
159  EV_INFO << "Initial activation time is " << activationTime << endl;
161  scheduleAt(simTime() + (simtime_t)activationTime, eventTimer);
162  }
163  }
164 }
int reqInCurSession
Definition: HttpBrowserBase.h:94
rdObject * rdProcessingDelay
Definition: HttpBrowserBase.h:99
rdObject * rdInterSessionInterval
Definition: HttpBrowserBase.h:102
HttpController * controller
Definition: HttpBrowserBase.h:88
virtual void initialize(int stage) override
Definition: HttpNodeBase.cc:32
long sessionCount
Definition: HttpBrowserBase.h:114
long textResourcesReceived
Definition: HttpBrowserBase.h:112
cMessage * eventTimer
Definition: HttpBrowserBase.h:87
rdObject * rdRequestSize
Definition: HttpBrowserBase.h:103
int httpProtocol
Definition: HttpNodeBase.h:60
int reqNoInCurSession
Definition: HttpBrowserBase.h:95
void readScriptedEvents(const char *filename)
Definition: HttpBrowserBase.cc:506
LOG_FORMAT outputFormat
Definition: HttpNodeBase.h:63
long htmlErrorsReceived
Definition: HttpBrowserBase.h:108
rdObject * rdReqInSession
Definition: HttpBrowserBase.h:104
std::string logFileName
Definition: HttpNodeBase.h:61
#define MSGKIND_ACTIVITY_START
Definition: HttpBrowserBase.h:32
cModule * findContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:56
virtual double draw()=0
Local initializations.
Definition: InitStages.h:35
long connectionsCount
Definition: HttpBrowserBase.h:115
rdObject * rdInterRequestInterval
Definition: HttpBrowserBase.h:101
bool scriptedMode
Definition: HttpBrowserBase.h:90
long imgResourcesReceived
Definition: HttpBrowserBase.h:110
bool enableLogging
Definition: HttpNodeBase.h:62
long messagesInCurrentSession
Definition: HttpBrowserBase.h:113
rdObject * rdActivityLength
Definition: HttpBrowserBase.h:100
long imgResourcesRequested
Definition: HttpBrowserBase.h:109
long htmlReceived
Definition: HttpBrowserBase.h:107
long textResourcesRequested
Definition: HttpBrowserBase.h:111
Definition: HttpNodeBase.h:44
long htmlRequested
Definition: HttpBrowserBase.h:106
Initialization of applications.
Definition: InitStages.h:106
Definition: NodeStatus.h:40
virtual int inet::httptools::HttpBrowserBase::numInitStages ( ) const
inlineoverrideprotectedvirtual

Reimplemented from inet::httptools::HttpNodeBase.

Reimplemented in inet::httptools::HttpBrowser, and inet::httptools::HttpBrowserDirect.

119 { return NUM_INIT_STAGES; }
The number of initialization stages.
Definition: InitStages.h:116
void inet::httptools::HttpBrowserBase::readScriptedEvents ( const char *  filename)
protected

Referenced by initialize().

507 {
508  EV_DEBUG << "Reading scripted events from " << filename << "\n";
509 
510  std::ifstream scriptfilestream;
511  scriptfilestream.open(filename);
512  if (!scriptfilestream.is_open())
513  throw cRuntimeError("Could not open script file %s", filename);
514 
515  std::string line;
516  std::string timepart;
517  std::string wwwpart;
518  int pos;
519  simtime_t t;
520  while (!std::getline(scriptfilestream, line).eof()) {
521  line = trim(line);
522  if (line.find("#") == 0)
523  continue;
524 
525  pos = line.find(";");
526  if (pos == -1)
527  continue;
528  timepart = line.substr(0, pos);
529  wwwpart = line.substr(pos + 1, line.size() - pos - 1);
530 
531  try {
532  t = (simtime_t)atof(timepart.c_str());
533  }
534  catch (...) {
535  continue;
536  }
537  std::vector<std::string> path = parseResourceName(wwwpart);
538 
539  BrowseEvent be;
540  be.time = t;
541  be.wwwhost = extractServerName(wwwpart.c_str());
542  be.resourceName = extractResourceName(wwwpart.c_str());
543  be.serverModule = dynamic_cast<HttpNodeBase *>(controller->getServerModule(wwwpart.c_str()));
544  if (be.serverModule == nullptr)
545  throw cRuntimeError("Unable to locate server %s in the scenario", wwwpart.c_str());
546 
547  EV_DEBUG << "Creating scripted browse event @ T=" << t << ", " << be.wwwhost << " / " << be.resourceName << endl;
548  browseEvents.push_front(be);
549  }
550  scriptfilestream.close();
551 
552  if (!browseEvents.empty()) {
553  BrowseEvent be = browseEvents.back();
555  scheduleAt(be.time, eventTimer);
556  }
557 }
HttpController * controller
Definition: HttpBrowserBase.h:88
BrowseEventsList browseEvents
Definition: HttpBrowserBase.h:91
cModule * getServerModule(const char *wwwName)
Get a specific server module reference.
Definition: HttpController.cc:174
HttpNodeBase()
Definition: HttpNodeBase.cc:26
cMessage * eventTimer
Definition: HttpBrowserBase.h:87
#define MSGKIND_SCRIPT_EVENT
Definition: HttpBrowserBase.h:31
std::string extractServerName(const char *url)
Definition: HttpUtils.cc:60
std::vector< std::string > parseResourceName(std::string resource)
Definition: HttpUtils.cc:103
std::string extractResourceName(const char *url)
Definition: HttpUtils.cc:82
std::string trim(std::string str)
Definition: HttpUtils.cc:53
void inet::httptools::HttpBrowserBase::scheduleNextBrowseEvent ( )
protected

Referenced by handleSelfNextMessage(), and handleSelfStartSession().

472 {
473  if (eventTimer->isScheduled())
474  cancelEvent(eventTimer);
475  simtime_t nextEventTime; // MIGRATE40: kvj
477  // The requests in the current round are done. Lets check what to do next.
478  if (rdActivityLength == nullptr || simTime() < acitivityPeriodEnd) {
479  // Scheduling next session start within an activity period.
480  nextEventTime = simTime() + (simtime_t)rdInterSessionInterval->draw();
481  EV_INFO << "Scheduling a new session start @ T=" << nextEventTime << endl;
484  scheduleAt(nextEventTime, eventTimer);
485  }
486  else {
487  // Schedule the next activity period start. This corresponds to to a working day or home time, ie. time
488  // when the user is near his workstation and periodically browsing the web. Inactivity periods then
489  // correspond to sleep time or time away from the office
490  simtime_t activationTime = simTime() + (simtime_t)(86400.0 - rdActivityLength->draw()); // Sleep for a while
491  EV_INFO << "Terminating current activity @ T=" << simTime() << ". Next activation time is " << activationTime << endl;
493  scheduleAt(activationTime, eventTimer);
494  }
495  }
496  else {
497  // Schedule another browse event in a while.
498  nextEventTime = simTime() + (simtime_t)rdInterRequestInterval->draw();
499  EV_INFO << "Scheduling a browse event @ T=" << nextEventTime
500  << ". Request " << reqInCurSession << " of " << reqNoInCurSession << endl;
502  scheduleAt(nextEventTime, eventTimer);
503  }
504 }
int reqInCurSession
Definition: HttpBrowserBase.h:94
rdObject * rdInterSessionInterval
Definition: HttpBrowserBase.h:102
#define MSGKIND_NEXT_MESSAGE
Definition: HttpBrowserBase.h:30
cMessage * eventTimer
Definition: HttpBrowserBase.h:87
int reqNoInCurSession
Definition: HttpBrowserBase.h:95
#define MSGKIND_START_SESSION
Definition: HttpBrowserBase.h:29
#define MSGKIND_ACTIVITY_START
Definition: HttpBrowserBase.h:32
virtual double draw()=0
rdObject * rdInterRequestInterval
Definition: HttpBrowserBase.h:101
long messagesInCurrentSession
Definition: HttpBrowserBase.h:113
rdObject * rdActivityLength
Definition: HttpBrowserBase.h:100
simtime_t acitivityPeriodEnd
Definition: HttpBrowserBase.h:96
virtual void inet::httptools::HttpBrowserBase::sendRequestsToServer ( std::string  www,
HttpRequestQueue  queue 
)
protectedpure virtual
virtual void inet::httptools::HttpBrowserBase::sendRequestToRandomServer ( )
protectedpure virtual
virtual void inet::httptools::HttpBrowserBase::sendRequestToServer ( BrowseEvent  be)
protectedpure virtual
virtual void inet::httptools::HttpBrowserBase::sendRequestToServer ( HttpRequestMessage request)
protectedpure virtual

Member Data Documentation

simtime_t inet::httptools::HttpBrowserBase::acitivityPeriodEnd
protected
BrowseEventsList inet::httptools::HttpBrowserBase::browseEvents
protected
long inet::httptools::HttpBrowserBase::connectionsCount = 0
protected

Referenced by initialize().

cMessage* inet::httptools::HttpBrowserBase::eventTimer = nullptr
protected
long inet::httptools::HttpBrowserBase::htmlErrorsReceived = 0
protected
long inet::httptools::HttpBrowserBase::htmlReceived = 0
protected
long inet::httptools::HttpBrowserBase::htmlRequested = 0
protected
long inet::httptools::HttpBrowserBase::imgResourcesReceived = 0
protected
long inet::httptools::HttpBrowserBase::imgResourcesRequested = 0
protected
long inet::httptools::HttpBrowserBase::messagesInCurrentSession = 0
protected
rdObject* inet::httptools::HttpBrowserBase::rdActivityLength = nullptr
protected
rdObject* inet::httptools::HttpBrowserBase::rdInterRequestInterval = nullptr
protected
rdObject* inet::httptools::HttpBrowserBase::rdInterSessionInterval = nullptr
protected
rdObject* inet::httptools::HttpBrowserBase::rdReqInSession = nullptr
protected
rdObject* inet::httptools::HttpBrowserBase::rdRequestSize = nullptr
protected
int inet::httptools::HttpBrowserBase::reqInCurSession = 0
protected
int inet::httptools::HttpBrowserBase::reqNoInCurSession = 0
protected
bool inet::httptools::HttpBrowserBase::scriptedMode = false
protected

Referenced by initialize().

long inet::httptools::HttpBrowserBase::sessionCount = 0
protected
long inet::httptools::HttpBrowserBase::textResourcesReceived = 0
protected
long inet::httptools::HttpBrowserBase::textResourcesRequested = 0
protected

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