My Project
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
Macros | Functions | Variables
controller_communication.c File Reference

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_msgthread_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...
 

Detailed Description

Communication with global controller from runtime.

Definition in file controller_communication.c.

Macro Definition Documentation

#define CHECK_MSG_SIZE (   msg,
  target 
)
Value:
if (msg->payload_size != sizeof(target)) { \
log_warn("Message data size (%d) does not match size" \
"of target type (%d)" #target, (int)msg->payload_size , \
(int)sizeof(target)); \
return -1; \
} \
return 0;
#define log_warn(fmt,...)
Definition: logging.h:113

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.

Function Documentation

static int connect_to_controller ( struct sockaddr_in *  addr)
static

Initializes a connection to the global controller.

Returns
0 on success, -1 on error

Definition at line 105 of file controller_communication.c.

static enum thread_msg_type get_thread_msg_type ( enum ctrl_runtime_msg_type  type)
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 int pass_ctrl_msg_to_thread ( struct ctrl_runtime_msg_hdr hdr,
int  fd 
)
static

Constructs a thread_msg from a control-runtime message and passes it to the relevant thread.

Parameters
hdrHeader describing info available to read
fdFile descriptor to read message from
Returns
0 on success, -1 on error

Definition at line 304 of file controller_communication.c.

static int process_connect_to_runtime ( struct ctrl_add_runtime_msg msg)
static

Processes a received ctrl_add_runtime_msg.

Definition at line 174 of file controller_communication.c.

static int process_create_thread_msg ( struct ctrl_create_thread_msg msg)
static

Processes a received ctrl_create_thread_msg.

Definition at line 191 of file controller_communication.c.

static int process_ctrl_message ( struct ctrl_runtime_msg_hdr hdr,
int  fd 
)
static

Processes a received control message that is due for delivery to this thread.

Parameters
hdrThe header for the control message
fdFile descriptor off of which to read the control message
Returns
0 on success, -1 on error

Definition at line 332 of file controller_communication.c.

static int process_ctrl_message_hdr ( struct ctrl_runtime_msg_hdr hdr,
int  fd 
)
static

Processes any received control message.

Definition at line 386 of file controller_communication.c.

static int process_ctrl_route_msg ( struct ctrl_route_msg msg)
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 int send_ctl_init_msg ( )
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.

Parameters
msgMessage to send. Must define payload_len.
Returns
-1 on error, 0 on success

Definition at line 47 of file controller_communication.c.

static struct thread_msg* thread_msg_from_ctrl_hdr ( struct ctrl_runtime_msg_hdr hdr,
int  fd 
)
static

Constructs a thread message from a ctrl_runtime_msg_hdr, reading any additional information it needs off of the associated socket.

Parameters
hdrHeader describing the information available to read
fdThe file descriptor off of which to read the remainder of the control message
Returns
Created thread_msg on success, NULL on error

Definition at line 278 of file controller_communication.c.

static int verify_msg_size ( struct ctrl_runtime_msg_hdr msg)
static

Checks whether the size of a message matches the size of its target struct.

Definition at line 149 of file controller_communication.c.

Variable Documentation

int controller_sock = -1
static

Static (global) variable to hold the socket connecting to the global controller.

Definition at line 44 of file controller_communication.c.