Communication with global controller from runtime. More...
#include "controller_communication.h"
#include "communication.h"
#include "logging.h"
#include "socket_monitor.h"
#include "dedos_threads.h"
#include "thread_message.h"
#include "runtime_dfg.h"
#include "rt_stats.h"
#include "worker_thread.h"
#include "output_thread.h"
#include <stdlib.h>
#include <arpa/inet.h>
#include <string.h>
Go to the source code of this file.
Macros | |
#define | CHECK_MSG_SIZE(msg, target) |
Macro to check whether the size of a message matches the size of the struct it's supposed to be. More... | |
Functions | |
int | send_to_controller (struct rt_controller_msg_hdr *hdr, void *payload) |
Sends a message to the global controller. More... | |
static int | send_ctl_init_msg () |
Sends the initilization message containing runtime ID, ip and port to global controller. More... | |
static int | connect_to_controller (struct sockaddr_in *addr) |
Initializes a connection to the global controller. More... | |
static int | verify_msg_size (struct ctrl_runtime_msg_hdr *msg) |
Checks whether the size of a message matches the size of its target struct. More... | |
static int | process_connect_to_runtime (struct ctrl_add_runtime_msg *msg) |
Processes a received ctrl_add_runtime_msg. More... | |
static int | process_create_thread_msg (struct ctrl_create_thread_msg *msg) |
Processes a received ctrl_create_thread_msg. More... | |
static int | process_ctrl_route_msg (struct ctrl_route_msg *msg) |
Processes a received ctrl_route_msg. More... | |
static enum thread_msg_type | get_thread_msg_type (enum ctrl_runtime_msg_type type) |
Gets the corresponding thread_msg_type for a ctrl_runtime_msg_type. More... | |
static struct thread_msg * | thread_msg_from_ctrl_hdr (struct ctrl_runtime_msg_hdr *hdr, int fd) |
Constructs a thread message from a ctrl_runtime_msg_hdr, reading any additional information it needs off of the associated socket. More... | |
static int | pass_ctrl_msg_to_thread (struct ctrl_runtime_msg_hdr *hdr, int fd) |
Constructs a thread_msg from a control-runtime message and passes it to the relevant thread. More... | |
static int | process_ctrl_message (struct ctrl_runtime_msg_hdr *hdr, int fd) |
Processes a received control message that is due for delivery to this thread. More... | |
int | send_ack_message (int id, bool success) |
WILL Send an acknoweledgement of success for a specific message. More... | |
static int | process_ctrl_message_hdr (struct ctrl_runtime_msg_hdr *hdr, int fd) |
Processes any received control message. More... | |
int | handle_controller_communication (int fd) |
Reads and processes a controller message off of the provided file descriptor. More... | |
bool | is_controller_fd (int fd) |
Checks if fd is file descriptor for controller. More... | |
int | init_controller_socket (struct sockaddr_in *addr) |
Initilizes a connection with the global controller located at the provided address. More... | |
int | send_stats_to_controller () |
Samples the relevant statistics and sends them to the controller. More... | |
Variables | |
static int | controller_sock = -1 |
Static (global) variable to hold the socket connecting to the global controller. More... | |
Communication with global controller from runtime.
Definition in file controller_communication.c.
#define CHECK_MSG_SIZE | ( | msg, | |
target | |||
) |
Macro to check whether the size of a message matches the size of the struct it's supposed to be.
Definition at line 137 of file controller_communication.c.
|
static |
Initializes a connection to the global controller.
Definition at line 105 of file controller_communication.c.
|
static |
Gets the corresponding thread_msg_type for a ctrl_runtime_msg_type.
Definition at line 257 of file controller_communication.c.
int handle_controller_communication | ( | int | fd | ) |
Reads and processes a controller message off of the provided file descriptor.
Controller message should start with ctrl_runtime_msg_hdr. fd File descriptor off of which to read the message
Definition at line 419 of file controller_communication.c.
int init_controller_socket | ( | struct sockaddr_in * | addr | ) |
Initilizes a connection with the global controller located at the provided address.
Definition at line 448 of file controller_communication.c.
bool is_controller_fd | ( | int | fd | ) |
Checks if fd
is file descriptor for controller.
Definition at line 443 of file controller_communication.c.
|
static |
Constructs a thread_msg from a control-runtime message and passes it to the relevant thread.
hdr | Header describing info available to read |
fd | File descriptor to read message from |
Definition at line 304 of file controller_communication.c.
|
static |
Processes a received ctrl_add_runtime_msg.
Definition at line 174 of file controller_communication.c.
|
static |
Processes a received ctrl_create_thread_msg.
Definition at line 191 of file controller_communication.c.
|
static |
Processes a received control message that is due for delivery to this thread.
hdr | The header for the control message |
fd | File descriptor off of which to read the control message |
Definition at line 332 of file controller_communication.c.
|
static |
Processes any received control message.
Definition at line 386 of file controller_communication.c.
|
static |
Processes a received ctrl_route_msg.
Definition at line 205 of file controller_communication.c.
int send_ack_message | ( | int | ack_id, |
bool | success | ||
) |
WILL Send an acknoweledgement of success for a specific message.
Not yet used
Definition at line 380 of file controller_communication.c.
|
static |
Sends the initilization message containing runtime ID, ip and port to global controller.
Definition at line 78 of file controller_communication.c.
int send_stats_to_controller | ( | ) |
Samples the relevant statistics and sends them to the controller.
Definition at line 462 of file controller_communication.c.
int send_to_controller | ( | struct rt_controller_msg_hdr * | msg, |
void * | payload | ||
) |
Sends a message to the global controller.
msg | Message to send. Must define payload_len. |
Definition at line 47 of file controller_communication.c.
|
static |
Constructs a thread message from a ctrl_runtime_msg_hdr, reading any additional information it needs off of the associated socket.
hdr | Header describing the information available to read |
fd | The file descriptor off of which to read the remainder of the control message |
Definition at line 278 of file controller_communication.c.
|
static |
Checks whether the size of a message matches the size of its target struct.
Definition at line 149 of file controller_communication.c.
|
static |
Static (global) variable to hold the socket connecting to the global controller.
Definition at line 44 of file controller_communication.c.