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

The base class for browser and server nodes. More...

#include <HttpNodeBase.h>

Inheritance diagram for inet::httptools::HttpNodeBase:
inet::ILifecycle inet::httptools::HttpBrowserBase inet::httptools::HttpServerBase inet::httptools::HttpBrowser inet::httptools::HttpBrowserDirect inet::httptools::HttpServer inet::httptools::HttpServerDirect inet::httptools::HttpServerEvilA inet::httptools::HttpServerEvilB inet::httptools::HttpServerDirectEvilA inet::httptools::HttpServerDirectEvilB

Public Member Functions

 HttpNodeBase ()
 
virtual void initialize (int stage) override
 
virtual int numInitStages () const override
 
- Public Member Functions inherited from inet::ILifecycle
virtual ~ILifecycle ()
 

Protected Member Functions

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

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

The base class for browser and server nodes.

See the derived classes HttpBrowserBase and HttpServerBase for details

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

Constructor & Destructor Documentation

inet::httptools::HttpNodeBase::HttpNodeBase ( )
27 {
28  m_bDisplayMessage = false;
30 }
bool m_bDisplayResponseContent
Definition: HttpNodeBase.h:65
bool m_bDisplayMessage
Definition: HttpNodeBase.h:64

Member Function Documentation

std::string inet::httptools::HttpNodeBase::formatHttpRequestLong ( const HttpRequestMessage httpRequest)
protected

Referenced by logRequest().

142 {
143  std::ostringstream str;
144 
145  str << "REQUEST: " << httpRequest->getName() << " -- " << httpRequest->getByteLength() << " bytes\n";
146  str << "Target URL:" << httpRequest->targetUrl() << " Originator URL:" << httpRequest->originatorUrl() << endl;
147 
148  str << "PROTOCOL:";
149  switch (httpRequest->protocol()) { // MIGRATE40: kvj
150  case 10:
151  str << "HTTP/1.0";
152  break;
153 
154  case 11:
155  str << "HTTP/1.1";
156  break;
157 
158  default:
159  str << "UNKNOWN";
160  break;
161  }
162  str << " ";
163 
164  str << "KEEP-ALIVE:" << httpRequest->keepAlive() << " ";
165  str << "BAD-REQ:" << httpRequest->badRequest() << " ";
166  str << "SERIAL:" << httpRequest->serial() << " " << endl;
167 
168  str << "REQUEST:" << httpRequest->heading() << endl;
169 
170  return str.str();
171 }
std::string inet::httptools::HttpNodeBase::formatHttpRequestShort ( const HttpRequestMessage httpRequest)
protected

Referenced by logRequest().

107 {
108  std::ostringstream str;
109 
110  std::string originatorStr = "";
111  cModule *originator = findContainingNode(httpRequest->getSenderModule());
112  if (originator != nullptr)
113  originatorStr = originator->getFullName();
114 
115  str << originatorStr << ";";
116  str << "REQ;" << httpRequest->originatorUrl() << ";" << httpRequest->targetUrl() << ";";
117  str << httpRequest->protocol() << ";" << httpRequest->keepAlive() << ";" << httpRequest->serial() << ";";
118  str << httpRequest->heading() << ";" << httpRequest->badRequest() << ";;"; // Skip the response specific fields
119 
120  return str.str();
121 }
cModule * findContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:56
std::string inet::httptools::HttpNodeBase::formatHttpResponseLong ( const HttpReplyMessage httpResponse)
protected

Referenced by logResponse().

174 {
175  std::ostringstream str;
176 
177  str << "RESPONSE: " << httpResponse->getName() << " -- " << httpResponse->getByteLength() << " bytes\n";
178 
179  str << "Target URL:" << httpResponse->targetUrl() << " Originator URL:" << httpResponse->originatorUrl() << endl;
180 
181  str << "PROTOCOL:";
182  switch (httpResponse->protocol()) {
183  case 10:
184  str << "HTTP/1.0";
185  break;
186 
187  case 11:
188  str << "HTTP/1.1";
189  break;
190 
191  default:
192  str << "UNKNOWN";
193  break;
194  }
195  str << " ";
196 
197  str << "RESULT:" << httpResponse->result() << " ";
198  str << "KEEP-ALIVE:" << httpResponse->keepAlive() << " ";
199  str << "SERIAL:" << httpResponse->serial() << " " << endl;
200 
201  str << "RESPONSE: " << httpResponse->heading() << endl;
202 
203  str << "CONTENT-TYPE:";
204  switch (httpResponse->contentType()) {
205  case CT_HTML:
206  str << "HTML DOC";
207  break;
208 
209  case CT_TEXT:
210  str << "Text/HTML RES";
211  break;
212 
213  case CT_IMAGE:
214  str << "IMG RES";
215  break;
216 
217  default:
218  str << "UNKNOWN";
219  break;
220  }
221  str << endl;
222 
224  str << "CONTENT:" << endl;
225  str << httpResponse->payload() << endl;
226  }
227 
228  return str.str();
229 }
Definition: HttpMessages_m.h:163
bool m_bDisplayResponseContent
Definition: HttpNodeBase.h:65
Definition: HttpMessages_m.h:162
Definition: HttpMessages_m.h:164
std::string inet::httptools::HttpNodeBase::formatHttpResponseShort ( const HttpReplyMessage httpResponse)
protected

Referenced by logResponse().

124 {
125  std::ostringstream str;
126 
127  std::string originatorStr = "";
128  cModule *originator = findContainingNode(httpResponse->getSenderModule());
129  if (originator != nullptr)
130  originatorStr = originator->getFullName();
131 
132  str << originatorStr << ";";
133  str << "RESP;" << httpResponse->originatorUrl() << ";" << httpResponse->targetUrl() << ";";
134  str << httpResponse->protocol() << ";" << httpResponse->keepAlive() << ";" << httpResponse->serial() << ";";
135  str << httpResponse->heading() << ";;"; // Skip the request specific fields
136  str << httpResponse->result() << ";" << httpResponse->contentType();
137 
138  return str.str();
139 }
cModule * findContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:56
virtual bool inet::httptools::HttpNodeBase::handleOperationStage ( LifecycleOperation operation,
int  stage,
IDoneCallback doneCallback 
)
inlineoverrideprotectedvirtual

Perform one stage of a lifecycle operation.

Processing may be done entirely within this method, or may be a longer process that involves nonzero simulation time or several events, and is triggered by this method call.

Return value: true = "done"; false = "not yet done, will invoke doneCallback when done"

Implements inet::ILifecycle.

95  { Enter_Method_Silent(); throw cRuntimeError("Unsupported lifecycle operation '%s'", operation->getClassName()); return true; }
void inet::httptools::HttpNodeBase::initialize ( int  stage)
overridevirtual

Reimplemented in inet::httptools::HttpBrowserBase, inet::httptools::HttpServerBase, inet::httptools::HttpBrowser, inet::httptools::HttpServer, inet::httptools::HttpServerDirectEvilA, inet::httptools::HttpServerDirectEvilB, inet::httptools::HttpServerEvilA, inet::httptools::HttpServerEvilB, inet::httptools::HttpServerDirect, and inet::httptools::HttpBrowserDirect.

Referenced by inet::httptools::HttpServerBase::initialize(), and inet::httptools::HttpBrowserBase::initialize().

33 {
34  EV_DEBUG << "Initializing base HTTP browser component -- stage " << stage << endl;
35 
36  cSimpleModule::initialize(stage);
37 
38  if (stage == INITSTAGE_LOCAL) {
39  host = getContainingNode(this);
40  }
41 }
cModule * host
Definition: HttpNodeBase.h:66
Local initializations.
Definition: InitStages.h:35
cModule * getContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:65
void inet::httptools::HttpNodeBase::logEntry ( std::string  line)
protected

Referenced by logRequest(), and logResponse().

86 {
87  if (!enableLogging || logFileName.empty())
88  return;
89 
90  std::ofstream outfile;
91  time_t curtime;
92  time(&curtime);
93 
94  outfile.open(logFileName.c_str(), std::ios::app);
95  if (outfile.tellp() == 0)
96  outfile << "time;simtime;logging-node;sending-node;type;originator-url;target-url;protocol;keep-alive;serial;heading;bad-req;result-code;content-type" << endl;
97  outfile << curtime << ";" << simTime() << ";" << host->getName();
98  if (outputFormat == lf_short)
99  outfile << ";";
100  else
101  outfile << endl;
102  outfile << line << endl;
103  outfile.close();
104 }
cModule * host
Definition: HttpNodeBase.h:66
LOG_FORMAT outputFormat
Definition: HttpNodeBase.h:63
std::string logFileName
Definition: HttpNodeBase.h:61
bool enableLogging
Definition: HttpNodeBase.h:62
Definition: HttpNodeBase.h:44
void inet::httptools::HttpNodeBase::logRequest ( const HttpRequestMessage httpRequest)
protected

Referenced by inet::httptools::HttpBrowserBase::generatePageRequest(), inet::httptools::HttpBrowserBase::generateResourceRequest(), and inet::httptools::HttpServerBase::handleReceivedMessage().

62 {
63  if (!enableLogging)
64  return;
65  if (outputFormat == lf_short)
66  logEntry(formatHttpRequestShort(httpRequest));
67  else
68  logEntry(formatHttpRequestLong(httpRequest));
70  EV_INFO << "Request:\n" << formatHttpRequestLong(httpRequest);
71 }
std::string formatHttpRequestShort(const HttpRequestMessage *httpRequest)
Definition: HttpNodeBase.cc:106
void logEntry(std::string line)
Definition: HttpNodeBase.cc:85
LOG_FORMAT outputFormat
Definition: HttpNodeBase.h:63
std::string formatHttpRequestLong(const HttpRequestMessage *httpRequest)
Definition: HttpNodeBase.cc:141
bool enableLogging
Definition: HttpNodeBase.h:62
bool m_bDisplayMessage
Definition: HttpNodeBase.h:64
Definition: HttpNodeBase.h:44
void inet::httptools::HttpNodeBase::logResponse ( const HttpReplyMessage httpResponse)
protected

Referenced by inet::httptools::HttpBrowserBase::handleDataMessage(), and inet::httptools::HttpServerBase::handleReceivedMessage().

74 {
75  if (!enableLogging)
76  return;
77  if (outputFormat == lf_short)
78  logEntry(formatHttpResponseShort(httpResponse));
79  else
80  logEntry(formatHttpResponseLong(httpResponse));
82  EV_INFO << "Response:\n" << formatHttpResponseLong(httpResponse);
83 }
void logEntry(std::string line)
Definition: HttpNodeBase.cc:85
std::string formatHttpResponseLong(const HttpReplyMessage *httpResponse)
Definition: HttpNodeBase.cc:173
LOG_FORMAT outputFormat
Definition: HttpNodeBase.h:63
bool enableLogging
Definition: HttpNodeBase.h:62
bool m_bDisplayMessage
Definition: HttpNodeBase.h:64
Definition: HttpNodeBase.h:44
std::string formatHttpResponseShort(const HttpReplyMessage *httpResponse)
Definition: HttpNodeBase.cc:123
void inet::httptools::HttpNodeBase::sendDirectToModule ( HttpNodeBase receiver,
cPacket *  packet,
simtime_t  constdelay = 0.0,
rdObject rd = nullptr 
)
protected

Referenced by inet::httptools::HttpServerDirect::handleMessage(), inet::httptools::HttpBrowserDirect::sendRequestsToServer(), inet::httptools::HttpBrowserDirect::sendRequestToRandomServer(), and inet::httptools::HttpBrowserDirect::sendRequestToServer().

44 {
45  if (pckt == nullptr)
46  return;
47  simtime_t delay = constdelay + transmissionDelay(pckt);
48  if (rdDelay != nullptr)
49  delay += rdDelay->draw();
50  EV_DEBUG << "Sending " << pckt->getName() << " direct to " << getContainingNode(receiver)->getName() << " with a delay of " << delay << " s\n";
51  sendDirect(pckt, delay, 0, receiver, "httpIn");
52 }
double transmissionDelay(cPacket *packet)
Definition: HttpNodeBase.cc:54
cModule * getContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:65
double inet::httptools::HttpNodeBase::transmissionDelay ( cPacket *  packet)
protected

Referenced by sendDirectToModule().

55 {
56  if (linkSpeed == 0)
57  return 0.0; // No delay if link speed unspecified
58  return pckt->getBitLength() / ((double)linkSpeed); // The link speed is in bit/s
59 }
unsigned long linkSpeed
Definition: HttpNodeBase.h:59

Member Data Documentation

bool inet::httptools::HttpNodeBase::enableLogging = true
protected
unsigned long inet::httptools::HttpNodeBase::linkSpeed = 0
protected
std::string inet::httptools::HttpNodeBase::logFileName
protected
bool inet::httptools::HttpNodeBase::m_bDisplayMessage = true
protected
bool inet::httptools::HttpNodeBase::m_bDisplayResponseContent = true
protected

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