Load Balancer Simulator
CSCE 412 - Load Balancer Simulation Project
Request.cpp
Go to the documentation of this file.
1 
6 #include "Request.h"
7 #include <cstdlib>
8 
9 Request::Request(std::string ipIn, std::string ipOut, int time, char jobType) {
10  this->ipIn = ipIn;
11  this->ipOut = ipOut;
12  this->time = time;
13  this->jobType = jobType;
14 }
15 
17  return std::to_string(rand() % 256) + "." +
18  std::to_string(rand() % 256) + "." +
19  std::to_string(rand() % 256) + "." +
20  std::to_string(rand() % 256);
21 }
22 
23 Request Request::generateRandom(int minTime, int maxTime) {
24  std::string ipIn = generateRandomIP();
25  std::string ipOut = generateRandomIP();
26  int time = minTime + (rand() % (maxTime - minTime + 1));
27  char jobType = (rand() % 2 == 0) ? 'P' : 'S';
28  return Request(ipIn, ipOut, time, jobType);
29 }
Defines the Request struct representing a network request in the load balancer simulation.
Represents a single network request with source/destination IPs, processing time, and job type.
Definition: Request.h:14
static std::string generateRandomIP()
Generates a random IP address string in dotted-decimal format.
Definition: Request.cpp:16
int time
Processing time in clock cycles.
Definition: Request.h:17
static Request generateRandom(int minTime, int maxTime)
Generates a random Request with random IPs and a random processing time.
Definition: Request.cpp:23
Request(std::string ipIn, std::string ipOut, int time, char jobType)
Constructs a Request with the given parameters.
Definition: Request.cpp:9
std::string ipIn
Source IP address of the request.
Definition: Request.h:15
char jobType
Job type: 'P' for processing, 'S' for streaming.
Definition: Request.h:18
std::string ipOut
Destination IP address for the response.
Definition: Request.h:16