15#ifndef LOAD_BALANCER_H
16#define LOAD_BALANCER_H
109 std::string generate_random_ip();
std::vector< WebServer * > servers
Vector holding pointers to all heap-allocated web servers.
Definition load_balancer.h:63
int time_to_run
Total number of cycles to run the load balancer.
Definition load_balancer.h:33
int min_request_time
Minimum duration (in cycles) for a request.
Definition load_balancer.h:43
int num_servers
Number of active web servers managed by the load balancer.
Definition load_balancer.h:28
bool is_finished()
Checks if the load balancer has finished running.
Definition load_balancer.h:84
int max_request_time
Maximum duration (in cycles) for a request.
Definition load_balancer.h:48
std::queue< Request > request_queue
Queue storing all pending requests.
Definition load_balancer.h:58
~LoadBalancer()
Destructor. Cleans up all heap-allocated web servers and logs final state.
Definition load_balancer.cpp:49
int time_elapsed
Number of cycles elapsed since the load balancer started.
Definition load_balancer.h:38
LoadBalancer(int num_servers, int time_to_run, std::ostream &output_stream)
Constructs a LoadBalancer with a given number of servers and run time.
Definition load_balancer.cpp:16
void handle_requests()
Main loop for handling requests and managing servers. Continues until the specified run time is reach...
Definition load_balancer.cpp:116
std::ostream & output_stream
Output stream for logging and status messages.
Definition load_balancer.h:53
void add_request(const Request &req)
Adds a request to the request queue.
Definition load_balancer.h:96
Request generate_random_request()
Generates a random request with random IPs and duration.
Definition load_balancer.cpp:101
Definition of the Request struct for representing network requests.
Represents a network request with source and destination IPs and a processing time.
Definition request.h:17
Declaration of the WebServer class for simulating a web server handling requests.