143 int currentServerIndex = 0;
144 int processedRequests = 0;
145 int rejectedRequests = 0;
146 int activeServers = 0;
147 int totalServers = 0;
149 const int maxServers = 50;
150 const int minServers = 1;
151 std::vector<std::string> blockedIpRanges;
152 std::vector<WebServer> servers;
157 void initializeBlockedIpRanges();
164 void logRejectedRequest(
const Request& r);
Manages incoming requests and distributes them among a set of web servers.
Definition loadbalancer.h:19
int getInactiveServers() const
Gets the total number of inactive servers.
Definition loadbalancer.cpp:122
int getTime() const
Gets the current simulation time.
Definition loadbalancer.cpp:19
void addRequest(const Request &r)
Adds a request to the request queue.
Definition loadbalancer.cpp:160
int getActiveServers() const
Gets the total number of active servers.
Definition loadbalancer.cpp:113
Request getRequest()
Retrieves and removes the next request from the request queue.
Definition loadbalancer.cpp:35
bool isRequestQueueEmpty() const
Checks if the request queue is empty.
Definition loadbalancer.cpp:44
bool isIpBlocked(const std::string &ip) const
Checks if a given IP address is blocked.
Definition loadbalancer.cpp:90
void allocateServer()
Allocates additional servers if needed.
Definition loadbalancer.cpp:176
void deallocateServer()
Deallocates servers that are no longer active.
Definition loadbalancer.cpp:194
WebServer & getNextServer()
Retrieves the next available server for processing requests.
Definition loadbalancer.cpp:78
LoadBalancer(LogManager &logger)
Constructs a LoadBalancer with a specified LogManager for logging.
Definition loadbalancer.cpp:9
void incrementProcessedRequests()
Increments the count of processed requests by one.
Definition loadbalancer.cpp:69
int getProcessedRequests() const
Gets the total number of processed requests.
Definition loadbalancer.cpp:62
size_t getRequestQueueSize() const
Gets the size of the request queue.
Definition loadbalancer.cpp:53
int getRejectedRequests() const
Gets the total number of rejected requests.
Definition loadbalancer.cpp:104
void setTotalServers(int total)
Sets the total number of servers managed by the LoadBalancer.
Definition loadbalancer.cpp:131
void incTime()
Increments the current simulation time by one unit.
Definition loadbalancer.cpp:26
A class to represent a network request.
Definition request.h:15
A class to represent a queue of requests.
Definition requestqueue.h:16
A class to represent a server that processes a request.
Definition webserver.h:23