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

The controller module for HttpTools simulations. More...

#include <HttpController.h>

Inheritance diagram for inet::httptools::HttpController:

Classes

struct  WebServerEntry
 Registration entry for Web servers. More...
 

Public Member Functions

 HttpController ()
 
 ~HttpController ()
 
public interface used by server and browser objects in the simulation
void registerServer (const char *objectName, const char *wwwName, int port, int rank=INSERT_RANDOM, simtime_t activationTime=0.0)
 Register a WWW server object. More...
 
cModule * getServerModule (const char *wwwName)
 Get a specific server module reference. More...
 
cModule * getAnyServerModule ()
 Get a random server object. More...
 
int getServerInfo (const char *wwwName, char *module, int &port)
 Get module and port for a server. More...
 
int getAnyServerInfo (char *wwwName, char *module, int &port)
 Get module and port for a random server. More...
 

Protected Types

enum  ServerStatus { SS_NORMAL, SS_SPECIAL }
 

Protected Member Functions

cModule * getTcpApp (const char *node)
 Helper used by the server registration to locate the tcpApp getModule(server or browser) More...
 
void setSpecialStatus (const char *www, ServerStatus status, double p, double amortize)
 Set special status of a WWW server. More...
 
void cancelSpecialStatus (const char *www)
 Cancel special popularity status for a server. More...
 
WebServerEntryselectFromSpecialList ()
 Select a server from the special list. More...
 
std::string listRegisteredServers ()
 List the registered servers. More...
 
std::string listSpecials ()
 List the servers on the special list, i.e. More...
 
std::string listPickOrder ()
 List the registered servers in the order of the general population pick list. More...
 
void parseOptionsFile (std::string file, std::string section)
 Parse a popularity modification events definition file at startup (if defined). More...
 
cSimpleModule redefinitions
virtual void initialize (int stage) override
 Initialization of the component and startup of browse event scheduling. More...
 
virtual void finish () override
 Report final statistics. More...
 
virtual void handleMessage (cMessage *msg) override
 Handle incoming messages. More...
 
virtual int numInitStages () const override
 Returns the number of initialization stages. More...
 

Protected Attributes

std::map< std::string, WebServerEntry * > webSiteList
 A list of registered web sites (server objects) More...
 
std::vector< WebServerEntry * > pickList
 The picklist used to select sites at random. More...
 
std::list< WebServerEntry * > specialList
 The special list – contains sites with active popularity modification events. More...
 
double pspecial = NaN
 The probability [0,1) of selecting a site from the special list. More...
 
unsigned long totalLookups = 0
 A counter for the total number of lookups. More...
 
rdObjectrdServerSelection = nullptr
 The random object for the server selection. More...
 

Private Member Functions

WebServerEntry__getRandomServerInfo ()
 Get a random server from the special list with p=pspecial or from the general population with p=1-pspecial. More...
 

Detailed Description

The controller module for HttpTools simulations.

A controller object for OMNeT++ simulations which use the HttpTools browser and server components. A single controller must exist at the scenario level in each simulation.

See also
HttpBrowserBase
HttpServerBase
Author
Kristjan V. Jonsson

Member Enumeration Documentation

Enumerator
SS_NORMAL 
SS_SPECIAL 
Definition: HttpController.h:59
Definition: HttpController.h:59

Constructor & Destructor Documentation

inet::httptools::HttpController::HttpController ( )
27  :
28  rdServerSelection(nullptr)
29 {
30 }
rdObject * rdServerSelection
The random object for the server selection.
Definition: HttpController.h:86
inet::httptools::HttpController::~HttpController ( )
33 {
34  // Clean up the server references
35  for (auto & elem : webSiteList)
36  delete elem.second;
37 
38  delete rdServerSelection;
39 }
std::map< std::string, WebServerEntry * > webSiteList
A list of registered web sites (server objects)
Definition: HttpController.h:79
rdObject * rdServerSelection
The random object for the server selection.
Definition: HttpController.h:86

Member Function Documentation

HttpController::WebServerEntry * inet::httptools::HttpController::__getRandomServerInfo ( )
private

Get a random server from the special list with p=pspecial or from the general population with p=1-pspecial.

Referenced by getAnyServerInfo(), and getAnyServerModule().

460 {
461  WebServerEntry *en;
462  int selected = 0;
463  // @todo Reimplement! This is a ugly hack to enable easy activation of servers - can lead to problems if no servers active!!!
464  do {
465  if (pspecial > 0.0 && bernoulli(pspecial)) {
466  // Pick from the special list. Each node can have different probabilities
467  en = selectFromSpecialList();
468  EV_DEBUG << "Selecting from special list. Got node " << en->name << endl;
469  }
470  else {
471  // Pick from the probability distribution which applies to the general population.
472  selected = (int)rdServerSelection->draw();
473  en = pickList[selected];
474  if (en == nullptr)
475  throw cRuntimeError("Invalid node selected at index %d", selected);
476  EV_DEBUG << "Selecting from normal list. Got node " << en->name << endl;
477  }
478  EV_DEBUG << "Activation time of the node is " << en->activationTime << " and the current time is " << simTime() << endl;
479  } while (en->activationTime > simTime());
480  return en;
481 }
WebServerEntry * selectFromSpecialList()
Select a server from the special list.
Definition: HttpController.cc:327
rdObject * rdServerSelection
The random object for the server selection.
Definition: HttpController.h:86
virtual double draw()=0
double pspecial
The probability [0,1) of selecting a site from the special list.
Definition: HttpController.h:82
std::vector< WebServerEntry * > pickList
The picklist used to select sites at random.
Definition: HttpController.h:80
void inet::httptools::HttpController::cancelSpecialStatus ( const char *  www)
protected

Cancel special popularity status for a server.

Called when popularity has been amortized to zero.

Referenced by selectFromSpecialList().

303 {
304  if (specialList.size() == 0)
305  return;
306  WebServerEntry *en;
307  for (auto i = specialList.begin(); i != specialList.end(); i++) {
308  en = (*i);
309  if (strcmp(en->name.c_str(), www) == 0) {
310  pspecial -= en->pvalue;
311  en->statusSetTime = simTime();
312  en->serverStatus = SS_NORMAL;
313  en->pvalue = 0.0;
314  en->pamortize = 0.0;
315  specialList.erase(i);
316  EV_DEBUG << "Special status for " << www << " cancelled" << endl;
317  break;
318  }
319  }
320  if (pspecial < 0.0)
321  pspecial = 0.0;
322  if (specialList.size() == 0)
323  pspecial = 0.0;
324  EV_DEBUG << "Size of special list is now " << specialList.size() << endl;
325 }
std::list< WebServerEntry * > specialList
The special list – contains sites with active popularity modification events.
Definition: HttpController.h:81
double pspecial
The probability [0,1) of selecting a site from the special list.
Definition: HttpController.h:82
Definition: HttpController.h:59
void inet::httptools::HttpController::finish ( )
overrideprotectedvirtual

Report final statistics.

92 {
93  EV_INFO << "Invoking finish on the controller. Total lookups " << totalLookups << endl;
94 
95  WebServerEntry *en;
96  std::map<std::string, WebServerEntry *>::const_iterator iter;
97  for (iter = webSiteList.begin(); iter != webSiteList.end(); ++iter) {
98  en = (*iter).second;
99  EV_INFO << "Server " << (*iter).first << ": Access count " << en->accessCount << endl;
100  }
101 
102  // Clean up the server references
103  for (iter = webSiteList.begin(); iter != webSiteList.end(); ++iter)
104  delete (*iter).second;
105  webSiteList.clear();
106 }
std::map< std::string, WebServerEntry * > webSiteList
A list of registered web sites (server objects)
Definition: HttpController.h:79
unsigned long totalLookups
A counter for the total number of lookups.
Definition: HttpController.h:84
int inet::httptools::HttpController::getAnyServerInfo ( char *  wwwName,
char *  module,
int &  port 
)

Get module and port for a random server.

Returns a OMNeT++ module name and port number for a randomly chosen server. The general popularity distribution is used in conjunction with the special list to determine the module returned. Called by browser modules to get a random communications partner.

See also
HttpBrowserBase

Referenced by inet::httptools::HttpBrowser::sendRequestToRandomServer().

245 {
246  Enter_Method_Silent();
247 
248  if (webSiteList.size() == 0) {
249  EV_WARN << "No modules registered. Cannot select a random module" << endl;
250  return -1;
251  }
252 
253  if (pickList.size() == 0) {
254  EV_ERROR << "No modules currently in the picklist. Cannot select a random module" << endl;
255  return -2;
256  }
257 
258  EV_DEBUG << "Getting a random server module with pspecial=" << pspecial << endl;
259 
260  WebServerEntry *en = __getRandomServerInfo();
261  EV_DEBUG << "Got a random www module: " << en->name << ", " << en->host << " (" << en->port << ")\n";
262 
263  totalLookups++;
264  en->accessCount++;
265 
266  strcpy(wwwName, en->name.c_str());
267  strcpy(module, en->host.c_str());
268  port = en->port;
269 
270  return 0;
271 }
std::map< std::string, WebServerEntry * > webSiteList
A list of registered web sites (server objects)
Definition: HttpController.h:79
WebServerEntry * __getRandomServerInfo()
Get a random server from the special list with p=pspecial or from the general population with p=1-psp...
Definition: HttpController.cc:459
double pspecial
The probability [0,1) of selecting a site from the special list.
Definition: HttpController.h:82
std::vector< WebServerEntry * > pickList
The picklist used to select sites at random.
Definition: HttpController.h:80
unsigned long totalLookups
A counter for the total number of lookups.
Definition: HttpController.h:84
cModule * inet::httptools::HttpController::getAnyServerModule ( )

Get a random server object.

Returns a OMNeT++ module reference to a randomly chosen server. The general popularity distribution is used in conjunction with the special list to determine the module returned. Called by browser modules to get a random communications partner.

See also
HttpBrowserBase

Referenced by inet::httptools::HttpBrowserDirect::sendRequestToRandomServer().

197 {
198  Enter_Method_Silent();
199 
200  if (webSiteList.size() == 0) {
201  EV_WARN << "No modules registered. Cannot select a random module" << endl;
202  return nullptr;
203  }
204 
205  if (pickList.size() == 0) {
206  EV_ERROR << "No modules currently in the picklist. Cannot select a random module" << endl;
207  return nullptr;
208  }
209 
210  EV_DEBUG << "Getting a random server module with pspecial=" << pspecial << endl;
211 
212  WebServerEntry *en = __getRandomServerInfo();
213  EV_DEBUG << "Got a random www module: " << en->name << ", " << en->host << " (" << en->port << ")\n";
214 
215  totalLookups++;
216  en->accessCount++;
217 
218  return en->module;
219 }
std::map< std::string, WebServerEntry * > webSiteList
A list of registered web sites (server objects)
Definition: HttpController.h:79
WebServerEntry * __getRandomServerInfo()
Get a random server from the special list with p=pspecial or from the general population with p=1-psp...
Definition: HttpController.cc:459
double pspecial
The probability [0,1) of selecting a site from the special list.
Definition: HttpController.h:82
std::vector< WebServerEntry * > pickList
The picklist used to select sites at random.
Definition: HttpController.h:80
unsigned long totalLookups
A counter for the total number of lookups.
Definition: HttpController.h:84
int inet::httptools::HttpController::getServerInfo ( const char *  wwwName,
char *  module,
int &  port 
)

Get module and port for a server.

Get a module reference and port number for a specific www name. Used by the browser modules when using TCP transport.

See also
HttpBrowser

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

222 {
223  Enter_Method_Silent();
224 
225  std::string serverUrl = extractServerName(wwwName);
226 
227  if (webSiteList.find(serverUrl) == webSiteList.end()) { // The www name is not in the map
228  EV_ERROR << "Could not find module name for " << wwwName << endl;
229  return -1;
230  }
231 
232  WebServerEntry *en = webSiteList[serverUrl];
233  EV_DEBUG << "Got module object for www name " << wwwName << ": " << en->host << " (" << en->port << ")\n";
234 
235  totalLookups++;
236  en->accessCount++;
237 
238  strcpy(module, en->host.c_str());
239  port = en->port;
240 
241  return 0;
242 }
std::map< std::string, WebServerEntry * > webSiteList
A list of registered web sites (server objects)
Definition: HttpController.h:79
std::string extractServerName(const char *url)
Definition: HttpUtils.cc:60
unsigned long totalLookups
A counter for the total number of lookups.
Definition: HttpController.h:84
cModule * inet::httptools::HttpController::getServerModule ( const char *  wwwName)

Get a specific server module reference.

Returns a OMNeT++ module reference for a specific WWW name. Called by browser modules to get a communications partner.

See also
HttpBrowserBase

Referenced by inet::httptools::HttpBrowserBase::readScriptedEvents(), inet::httptools::HttpBrowserDirect::sendRequestsToServer(), and inet::httptools::HttpBrowserDirect::sendRequestToServer().

175 {
176  Enter_Method_Silent();
177 
178  std::string serverUrl = extractServerName(wwwName);
179 
180  if (webSiteList.find(serverUrl) == webSiteList.end()) { // The www name is not in the map
181  EV_ERROR << "Could not find module name for " << wwwName << endl;
182  return nullptr;
183  }
184 
185  WebServerEntry *en = webSiteList[serverUrl];
186  EV_DEBUG << "Got module object for www name " << wwwName << ": " << en->host << " (" << en->port << ")\n";
187 
188  totalLookups++;
189  en->accessCount++;
190 
191  if (en->module == nullptr)
192  EV_ERROR << "Undefined module for " << wwwName << endl;
193  return en->module;
194 }
std::map< std::string, WebServerEntry * > webSiteList
A list of registered web sites (server objects)
Definition: HttpController.h:79
std::string extractServerName(const char *url)
Definition: HttpUtils.cc:60
unsigned long totalLookups
A counter for the total number of lookups.
Definition: HttpController.h:84
cModule * inet::httptools::HttpController::getTcpApp ( const char *  node)
protected

Helper used by the server registration to locate the tcpApp getModule(server or browser)

Referenced by registerServer().

274 {
275  cModule *receiverModule = getSimulation()->getModuleByPath(node);
276  ASSERT(receiverModule != nullptr);
277 
278  return receiverModule->getSubmodule("tcpApp", 0); // TODO: CHECK INDEX
279 }
void inet::httptools::HttpController::handleMessage ( cMessage *  msg)
overrideprotectedvirtual

Handle incoming messages.

109 {
110  if (msg->isSelfMessage()) {
111  HttpServerStatusUpdateMsg *statusMsg = check_and_cast<HttpServerStatusUpdateMsg *>(msg);
112  EV_DEBUG << "Handling a status change message @T=" << simTime() << " for www " << statusMsg->www() << endl;
113  setSpecialStatus(statusMsg->www(), (ServerStatus)statusMsg->eventKind(), statusMsg->pvalue(), statusMsg->pamortize());
114  delete statusMsg;
115  }
116  else {
117  delete msg;
118  }
119 }
void setSpecialStatus(const char *www, ServerStatus status, double p, double amortize)
Set special status of a WWW server.
Definition: HttpController.cc:281
ServerStatus
Definition: HttpController.h:59
void inet::httptools::HttpController::initialize ( int  stage)
overrideprotectedvirtual

Initialization of the component and startup of browse event scheduling.

Multi-stage is required to properly initialize the object for random site selection after all servers have been registered.

42 {
43  cSimpleModule::initialize(stage);
44 
45  EV_DEBUG << "Initializing stage " << stage << endl;
46 
47  if (stage == INITSTAGE_LOCAL) {
48  EV_INFO << "Initializing HTTP controller. First stage" << endl;
49 
50  cXMLElement *rootelement = par("config").xmlValue();
51  if (rootelement == nullptr)
52  throw cRuntimeError("Configuration file is not defined");
53 
54  cXMLAttributeMap attributes;
55  cXMLElement *element;
56  // Initialize the random object for random site selection
57  rdObjectFactory rdFactory;
58  element = rootelement->getFirstChildWithTag("serverPopularityDistribution");
59  if (element == nullptr)
60  throw cRuntimeError("Server popularity distribution parameter undefined in XML configuration");
61  attributes = element->getAttributes();
62  rdServerSelection = rdFactory.create(attributes);
63  if (rdServerSelection == nullptr)
64  throw cRuntimeError("Server popularity distribution random object could not be created");
65  EV_INFO << "Using " << rdServerSelection->typeStr() << " for server popularity distribution." << endl;
66 
67  pspecial = 0.0; // No special events by default
68  totalLookups = 0;
69  }
70  else if (stage == INITSTAGE_APPLICATION_LAYER) {
71  // Two stages are required to finalize the initialization of the random object for the site selection
72  // once the final number of web sites is known.
73 
74  EV_INFO << "Initializing HTTP controller. Second stage" << endl;
75  EV_INFO << "Registered servers are " << webSiteList.size() << endl;
76  // Finish initialization of the probability distribution objects which depend on the number of servers.
78  ((rdUniform *)rdServerSelection)->setEnd(webSiteList.size());
79  else if (rdServerSelection->getType() == dt_zipf)
80  ((rdZipf *)rdServerSelection)->setN(webSiteList.size());
81 
82  EV_DEBUG << "Server selection probability distribution: " << rdServerSelection->toString() << endl;
83 
84  std::string optionsfile = (const char *)par("events");
85  std::string optionssection = (const char *)par("eventsSection");
86  if (optionsfile.size() != 0)
87  parseOptionsFile(optionsfile, optionssection);
88  }
89 }
std::string typeStr()
Definition: HttpRandom.cc:24
void parseOptionsFile(std::string file, std::string section)
Parse a popularity modification events definition file at startup (if defined).
Definition: HttpController.cc:402
std::map< std::string, WebServerEntry * > webSiteList
A list of registered web sites (server objects)
Definition: HttpController.h:79
Definition: HttpRandom.h:33
rdObject * rdServerSelection
The random object for the server selection.
Definition: HttpController.h:86
Definition: HttpRandom.h:33
Local initializations.
Definition: InitStages.h:35
double pspecial
The probability [0,1) of selecting a site from the special list.
Definition: HttpController.h:82
DISTR_TYPE getType()
Definition: HttpRandom.h:56
unsigned long totalLookups
A counter for the total number of lookups.
Definition: HttpController.h:84
virtual std::string toString()
Definition: HttpRandom.h:58
Initialization of applications.
Definition: InitStages.h:106
std::string inet::httptools::HttpController::listPickOrder ( )
protected

List the registered servers in the order of the general population pick list.

Useful for debug.

391 {
392  std::ostringstream str;
393  WebServerEntry *en;
394  for (auto & elem : pickList) {
395  en = (elem);
396  str << en->name << ";" << en->host << ";" << en->port << ";" << en->serverStatus
397  << ";" << en->pvalue << ";" << en->pamortize << endl;
398  }
399  return str.str();
400 }
std::vector< WebServerEntry * > pickList
The picklist used to select sites at random.
Definition: HttpController.h:80
std::string inet::httptools::HttpController::listRegisteredServers ( )
protected

List the registered servers.

Useful for debug.

367 {
368  std::ostringstream str;
369  WebServerEntry *en;
370  std::map<std::string, WebServerEntry *>::const_iterator iter;
371  for (iter = webSiteList.begin(); iter != webSiteList.end(); ++iter) {
372  en = (*iter).second;
373  str << (*iter).first << ";" << en->host << ";" << en->port << endl;
374  }
375  return str.str();
376 }
std::map< std::string, WebServerEntry * > webSiteList
A list of registered web sites (server objects)
Definition: HttpController.h:79
std::string inet::httptools::HttpController::listSpecials ( )
protected

List the servers on the special list, i.e.

those with custom selection probability. Useful for debug.

379 {
380  std::ostringstream str;
381  WebServerEntry *en;
382  for (auto & elem : specialList) {
383  en = (elem);
384  str << en->name << ";" << en->host << ";" << en->port << ";" << en->serverStatus
385  << ";" << en->pvalue << ";" << en->pamortize << endl;
386  }
387  return str.str();
388 }
std::list< WebServerEntry * > specialList
The special list – contains sites with active popularity modification events.
Definition: HttpController.h:81
virtual int inet::httptools::HttpController::numInitStages ( ) const
inlineoverrideprotectedvirtual

Returns the number of initialization stages.

Two required.

105 { return NUM_INIT_STAGES; }
The number of initialization stages.
Definition: InitStages.h:116
void inet::httptools::HttpController::parseOptionsFile ( std::string  file,
std::string  section 
)
protected

Parse a popularity modification events definition file at startup (if defined).

Format: {time};{www name};{event kind};{p value};{amortization factor} Event kind is not used at the present – use 1 as a default here.

Referenced by initialize().

403 {
404  bool bSectionFound = false;
405  std::ifstream tracefilestream;
406  tracefilestream.open(file.c_str());
407  if (!tracefilestream.is_open())
408  throw cRuntimeError("Could not open events file %s", file.c_str());
409 
410  if (section.size() == 0)
411  bSectionFound = true; // Grab first section
412 
413  double pval;
414  double amortizeval;
415  simtime_t activationtime;
416  std::string line;
417  int linecount = 0;
418  HttpServerStatusUpdateMsg *statusChange;
419  while (!std::getline(tracefilestream, line).eof()) {
420  linecount++;
421  if (line.empty() || line[0] == '#')
422  continue;
423  if (line[0] == '[') {
424  // Section
425  bSectionFound = false;
426  std::string sectionsub = line.substr(1, line.size() - 2);
427  bSectionFound = sectionsub == section;
428  }
429  else {
430  if (bSectionFound) {
431  // Format: {time};{www name};{event kind};{p value};{amortization factor}
432  // Event kind is not used at the present
433 
434  cStringTokenizer tokenizer = cStringTokenizer(line.c_str(), ";");
435  std::vector<std::string> res = tokenizer.asVector();
436  if (res.size() != 5)
437  throw cRuntimeError("Invalid format of event config line in '%s' Line: '%s'", file.c_str(), line.c_str());
438  try {
439  activationtime = (simtime_t)atof(res[0].c_str());
440  pval = atof(res[3].c_str());
441  amortizeval = atof(res[4].c_str());
442  }
443  catch (...) {
444  throw cRuntimeError("Invalid format of event config line in '%s' Line: '%s'", file.c_str(), line.c_str());
445  }
446  EV_DEBUG << "Scheduling a status change for " << res[1] << " @ T=" << activationtime << ". Parameters: " << line << endl;
447  statusChange = new HttpServerStatusUpdateMsg();
448  statusChange->setWww(res[1].c_str());
449  statusChange->setEventKind(1);
450  statusChange->setPvalue(pval);
451  statusChange->setPamortize(amortizeval);
452  scheduleAt(activationtime, statusChange);
453  }
454  }
455  }
456  tracefilestream.close();
457 }
void inet::httptools::HttpController::registerServer ( const char *  objectName,
const char *  wwwName,
int  port,
int  rank = INSERT_RANDOM,
simtime_t  activationTime = 0.0 
)

Register a WWW server object.

Called by server objects at startup.

See also
HttpServerBase. A data structure is created for the registered server for easy lookup. It is entered into the site picklist which is used to select servers in the general population. The insertion is specified by the INSERT_* defines: Registered sites can be inserted at the end, in the middle or at random. This does play a role when zipf or other non-uniform selection probability is used (the pick list is basically mapped to the non-uniform distribution).

Referenced by inet::httptools::HttpServerBase::registerWithController().

122 {
123  Enter_Method_Silent();
124 
125  std::string serverName = extractServerName(wwwName);
126 
127  EV_DEBUG << "Registering www server: " << objectName << ", " << wwwName
128  << " (" << port << "). Activation time is " << activationTime << endl;
129 
130  if (webSiteList.find(wwwName) != webSiteList.end())
131  EV_ERROR << "Server " << wwwName << " is already registered\n";
132 
133  WebServerEntry *en = new WebServerEntry;
134 
135  en->name = serverName;
136  en->host = objectName;
137  en->port = port;
138  en->module = getTcpApp(objectName);
139  en->activationTime = activationTime;
140  en->statusSetTime = simTime();
141  en->serverStatus = SS_NORMAL;
142  en->pvalue = 0.0;
143  en->pamortize = 0.0;
144  en->accessCount = 0;
145 
146  if (en->module == nullptr)
147  throw cRuntimeError("Server %s does not have a WWW module", wwwName);
148 
149  webSiteList[en->name] = en;
150 
151  int pos;
152  auto begin = pickList.begin();
153  if (rank == INSERT_RANDOM) {
154  if (pickList.size() == 0) {
155  pickList.push_back(en);
156  }
157  else {
158  pos = (int)uniform(0, pickList.size() - 1);
159  pickList.insert(begin + pos, en);
160  }
161  }
162  else if (rank == INSERT_MIDDLE) {
163  pos = pickList.size() / 2;
164  pickList.insert(begin + pos, en);
165  }
166  else if (rank == INSERT_END || rank >= (int)pickList.size()) {
167  pickList.push_back(en);
168  }
169  else {
170  pickList.insert(begin + rank, en);
171  }
172 }
std::map< std::string, WebServerEntry * > webSiteList
A list of registered web sites (server objects)
Definition: HttpController.h:79
#define INSERT_MIDDLE
Definition: HttpController.h:40
cModule * getTcpApp(const char *node)
Helper used by the server registration to locate the tcpApp getModule(server or browser) ...
Definition: HttpController.cc:273
std::string extractServerName(const char *url)
Definition: HttpUtils.cc:60
#define INSERT_END
Definition: HttpController.h:38
std::vector< WebServerEntry * > pickList
The picklist used to select sites at random.
Definition: HttpController.h:80
Definition: HttpController.h:59
#define INSERT_RANDOM
Definition: HttpController.h:39
HttpController::WebServerEntry * inet::httptools::HttpController::selectFromSpecialList ( )
protected

Select a server from the special list.

This method is called with the pspecial probability.

Referenced by __getRandomServerInfo().

328 {
329 
330  if (specialList.empty()) {
331  EV_ERROR << "No entries in special list. Cannot select server with special probability" << endl;
332  return nullptr;
333  }
334 
335  WebServerEntry *en = specialList.front();
336 
337  if (specialList.size() > 1) {
338  double p = uniform(0, 1);
339  double pcumulative = 0.0;
340  for (auto & elem : specialList) {
341  en = (elem);
342  pcumulative += en->pvalue;
343  if (pcumulative / pspecial > p)
344  break;
345  }
346  }
347 
348  if (en->pamortize > 0.0) {
349  double newp = en->pvalue - en->pamortize;
350  if (newp > 0.0) {
351  en->pvalue = newp;
352  pspecial -= en->pamortize;
353  EV_DEBUG << "Amortizing special probability for " << en->name << ". Now at " << en->pvalue << endl;
354  }
355  else {
356  pspecial -= en->pvalue;
357  en->pvalue = 0.0;
358  cancelSpecialStatus(en->name.c_str());
359  EV_DEBUG << "Cancelling special status for " << en->name << endl;
360  }
361  }
362 
363  return en;
364 }
void cancelSpecialStatus(const char *www)
Cancel special popularity status for a server.
Definition: HttpController.cc:302
std::list< WebServerEntry * > specialList
The special list – contains sites with active popularity modification events.
Definition: HttpController.h:81
double pspecial
The probability [0,1) of selecting a site from the special list.
Definition: HttpController.h:82
void inet::httptools::HttpController::setSpecialStatus ( const char *  www,
ServerStatus  status,
double  p,
double  amortize 
)
protected

Set special status of a WWW server.

Triggered by an event message.

Referenced by handleMessage().

282 {
283  if (webSiteList.find(www) == webSiteList.end()) { // The www name is not in the map
284  EV_ERROR << "Could not find module name for " << www << ". Cannot set special status" << endl;
285  return;
286  }
287 
288  EV_DEBUG << "Setting special status for " << www << ", p=" << p << " and amortize=" << amortize << endl;
289 
290  WebServerEntry *en = webSiteList[www];
291 
292  en->statusSetTime = simTime();
293  en->serverStatus = status;
294  en->pvalue = p;
295  en->pamortize = amortize;
296 
297  specialList.push_front(en);
298 
299  pspecial += p;
300 }
std::map< std::string, WebServerEntry * > webSiteList
A list of registered web sites (server objects)
Definition: HttpController.h:79
std::list< WebServerEntry * > specialList
The special list – contains sites with active popularity modification events.
Definition: HttpController.h:81
double pspecial
The probability [0,1) of selecting a site from the special list.
Definition: HttpController.h:82

Member Data Documentation

std::vector<WebServerEntry *> inet::httptools::HttpController::pickList
protected

The picklist used to select sites at random.

Referenced by __getRandomServerInfo(), getAnyServerInfo(), getAnyServerModule(), listPickOrder(), and registerServer().

double inet::httptools::HttpController::pspecial = NaN
protected

The probability [0,1) of selecting a site from the special list.

Referenced by __getRandomServerInfo(), cancelSpecialStatus(), getAnyServerInfo(), getAnyServerModule(), initialize(), selectFromSpecialList(), and setSpecialStatus().

rdObject* inet::httptools::HttpController::rdServerSelection = nullptr
protected

The random object for the server selection.

Referenced by __getRandomServerInfo(), initialize(), and ~HttpController().

std::list<WebServerEntry *> inet::httptools::HttpController::specialList
protected

The special list – contains sites with active popularity modification events.

Referenced by cancelSpecialStatus(), listSpecials(), selectFromSpecialList(), and setSpecialStatus().

unsigned long inet::httptools::HttpController::totalLookups = 0
protected

A counter for the total number of lookups.

Referenced by finish(), getAnyServerInfo(), getAnyServerModule(), getServerInfo(), getServerModule(), and initialize().

std::map<std::string, WebServerEntry *> inet::httptools::HttpController::webSiteList
protected

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