Commit c41c7324 authored by Ricardo Martínez's avatar Ricardo Martínez
Browse files

- Added Shortest Path Algorithm

- Added support of the GET method to check status of PathComp
-Added support for showing logs via either Screen (stdout) or defined Log file
parent 8b9da5fa
Loading
Loading
Loading
Loading
+10 −7
Original line number Diff line number Diff line
@@ -33,16 +33,16 @@ coverage: CFLAGS += -O0 -ggdb -g -DDEBUG -fprofile-arcs -ftest-coverage -DGCOV
coverage: LDFLAGS += -g -lgcov --coverage -fprofile-arcs -ftest-coverage -DGCOV
coverage: pathComp-cvr

pathComp: pathComp.o pathComp_log.o pathComp_cjson.o pathComp_tools.o pathComp_ksp.o pathComp_RESTapi.o 
	gcc -o pathComp pathComp.o pathComp_log.o pathComp_cjson.o pathComp_tools.o pathComp_ksp.o pathComp_RESTapi.o \
pathComp: pathComp.o pathComp_log.o pathComp_cjson.o pathComp_tools.o pathComp_ksp.o pathComp_sp.o pathComp_RESTapi.o 
	gcc -o pathComp pathComp.o pathComp_log.o pathComp_cjson.o pathComp_tools.o pathComp_ksp.o pathComp_sp.o pathComp_RESTapi.o \
		-L/usr/lib/x86_64-linux-gnu/ -lglib-2.0 -luuid $(LDFLAGS) $(LDLIBS)

pathComp-dbg: pathComp.o pathComp_log.o pathComp_cjson.o pathComp_tools.o pathComp_ksp.o pathComp_RESTapi.o 
	gcc -o pathComp-dbg pathComp.o pathComp_log.o pathComp_cjson.o pathComp_tools.o pathComp_ksp.o pathComp_RESTapi.o \
pathComp-dbg: pathComp.o pathComp_log.o pathComp_cjson.o pathComp_tools.o pathComp_ksp.o pathComp_sp.o pathComp_RESTapi.o 
	gcc -o pathComp-dbg pathComp.o pathComp_log.o pathComp_cjson.o pathComp_tools.o pathComp_ksp.o pathComp_sp.o pathComp_RESTapi.o \
		-L/usr/lib/x86_64-linux-gnu/ -lglib-2.0 -luuid $(LDFLAGS) $(LDLIBS)

pathComp-cvr: pathComp.o pathComp_log.o pathComp_cjson.o pathComp_tools.o pathComp_ksp.o pathComp_RESTapi.o 
	gcc -o pathComp-cvr pathComp.o pathComp_log.o pathComp_cjson.o pathComp_tools.o pathComp_ksp.o pathComp_RESTapi.o \
pathComp-cvr: pathComp.o pathComp_log.o pathComp_cjson.o pathComp_tools.o pathComp_ksp.o pathComp_sp.o pathComp_RESTapi.o 
	gcc -o pathComp-cvr pathComp.o pathComp_log.o pathComp_cjson.o pathComp_tools.o pathComp_ksp.o pathComp_sp.o pathComp_RESTapi.o \
		-L/usr/lib/x86_64-linux-gnu/ -lglib-2.0 -luuid $(LDFLAGS) $(LDLIBS)

pathComp_log.o: pathComp_log.h pathComp_log.c
@@ -57,7 +57,10 @@ pathComp_tools.o: pathComp_log.h pathComp_tools.h pathComp_tools.c
pathComp_ksp.o: pathComp_log.h pathComp_tools.h pathComp_ksp.h pathComp_ksp.c
	$(CC) $(CFLAGS) -c pathComp_ksp.c -o pathComp_ksp.o

pathComp_RESTapi.o: pathComp_tools.h pathComp_log.h pathComp_cjson.h pathComp_ksp.h pathComp_RESTapi.h pathComp_RESTapi.c
pathComp_sp.o: pathComp_log.h pathComp_tools.h pathComp_sp.h pathComp_sp.c
	$(CC) $(CFLAGS) -c pathComp_sp.c -o pathComp_sp.o
	
pathComp_RESTapi.o: pathComp_tools.h pathComp_log.h pathComp_cjson.h pathComp_ksp.h pathComp_sp.h pathComp_RESTapi.h pathComp_RESTapi.c
	$(CC) $(CFLAGS) -c pathComp_RESTapi.c -o pathComp_RESTapi.o

pathComp.o: pathComp_log.h pathComp_RESTapi.h pathComp.c pathComp.h
+11 −5
Original line number Diff line number Diff line
@@ -137,11 +137,17 @@ int main(int argc, char *argv[])
	// argv[2] specifies the folder and the log file
	gchar log[50];
	strcpy (log, argv[2]);
	gint screen = strcmp(log, "screen_only");
	if (screen == 0) {
		DEBUG_PC("All logs shown through stdout, i.e.,screen");
		logfile = NULL;
	}
	else {
		DEBUG_PC("PATH COMP log File: %s", log);

		// open the log file	
		logfile = fopen(log, "w");
		DEBUG_PC("log file is opened");
	}
	
	// Read the pathComp.conf file
	FILE *pathComp_config = NULL;	
+52 −20
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@
#include "pathComp_tools.h"
#include "pathComp_cjson.h"
#include "pathComp_ksp.h"
#include "pathComp_sp.h"
#include "pathComp_RESTapi.h"

#define ISspace(x) isspace((int)(x))
@@ -457,18 +458,30 @@ void rapi_response_json_contents (char *body, gint *length, struct compRouteOutp
/////////////////////////////////////////////////////////////////////////////////////////
void rapi_response_ok (GIOChannel *source, gint httpCode, struct compRouteOutputList_t *compRouteOutputList) {
    
	g_assert(compRouteOutputList);
	gint ret = 0;
    
    //DEBUG_PC ("Creating the JSON Body and sending the response of the computed Route List");
    
    guchar buftmp[1024];
    char buftmp[1024];
    char *buf = g_malloc0 (sizeof (char) * 2048000); 
    // Create the Body of the Response 
    char * jsonBody = g_malloc0 (sizeof (char) * 2048000);    
    char * msgBody = g_malloc0 (sizeof (char) * 2048000);    
    gint length = 0;
	
    rapi_response_json_contents (jsonBody, &length, compRouteOutputList);
	//  If path computation was requested, the resulting computation is returned in the msg body
	if (compRouteOutputList != NULL) {
		rapi_response_json_contents(msgBody, &length, compRouteOutputList);
	}
	// no path computation was requested, then a basic msg is just added
	else {
		cJSON* root = cJSON_CreateObject();
		char status[3];
		sprintf(status, "OK");
		cJSON_AddItemToObject(root, "Status", cJSON_CreateString(status));
		msgBody = (char*)cJSON_Print(root);
		length = strlen((const char*)msgBody);
		cJSON_Delete(root);
	}
		
	sprintf((char *)buf, "HTTP/1.1 200 OK\r\n");    
	
@@ -480,9 +493,7 @@ void rapi_response_ok (GIOChannel *source, gint httpCode, struct compRouteOutput
    
    // Add the length of the JSON enconding to the Content_Length
    char buff_length[16];    
    
    sprintf(buff_length, "%d", length);
    //DEBUG_PC ("Buffer Length (JSON BODY): %d Added to the Content Length", length);
    
    sprintf ((char *)buftmp, "Content-Length: ");
    strcat ((char *)buftmp, (const char *)buff_length);
@@ -495,12 +506,13 @@ void rapi_response_ok (GIOChannel *source, gint httpCode, struct compRouteOutput
    sprintf((char *)buftmp, "\r\n");
    strcat ((char *)buf, (const char *)buftmp);

	strcat ((char *)buf, (const char *)jsonBody);		
	strcat((char*)buf, (const char*)msgBody);
			
	//DEBUG_PC ("%s", buf);	    
    ret = rapi_send_message (source, buf);    
    g_free (buf);
    memset (buftmp, '\0', sizeof ( buftmp));    
    g_free (jsonBody);
    g_free (msgBody);
    (void)ret;    
    return;
}
@@ -1560,12 +1572,17 @@ gint triggering_routeComp (struct compRouteOutputList_t *compRouteList, gchar *a
	gint httpCode = HTTP_RETURN_CODE_OK;
	DEBUG_PC("Requested Algorithm: %s", algId);
	//////////////////// Algorithm Selector (RAId)//////////////////////////////////////	
	// Connectivity Service Abstraction (CSA)
	// KSP algorithm
	if (strncmp ((const char*)algId, "KSP", 3) == 0)
	{
		DEBUG_PC ("Alg Id: KSP");
		httpCode = pathComp_ksp_alg(compRouteList);
	}
	// simple SP algorithm
	else if (strncmp((const char*)algId, "SP", 2) == 0) {
		DEBUG_PC("Alg Id: SP");
		httpCode = pathComp_sp_alg(compRouteList);
	}
#if 0
	// Infrastructure Abstraction (InA)
	else if (strncmp ((const char*)raId, "InA", 3) == 0) 
@@ -1643,8 +1660,7 @@ gboolean RESTapi_activity(GIOChannel *source, GIOCondition cond, gpointer data)
	gint i = 0, j = 0;
	// Get the REST Method
	guint RestApiMethod = RESTapi_get_method (buf, &j);
	if (RestApiMethod == 0)
	{
	if (RestApiMethod == 0) 	{
		DEBUG_PC ("The method is NOT supported ...");
		RESTapi_unimplemented (source);
		RESTapi_stop(client, source, fd);
@@ -1656,13 +1672,29 @@ gboolean RESTapi_activity(GIOChannel *source, GIOCondition cond, gpointer data)
	i = get_url (buf, &j, url);	
	url[i] = '\0';	

	// GET - used for checking status of pathComp ... used url /pathComp/api/v1/health
	if (RestApiMethod == REST_API_METHOD_GET) {
		if (strncmp((const char*)url, "/health", 7) != 0) {
			DEBUG_PC("unknown url [%s] for GET method -- Heatlh function", url);
			RESTapi_stop(client, source, fd);
			exit(-1);
		}
		else {
			DEBUG_PC("Sending API Response OK to health requests");
			rapi_response_ok(source, HTTP_RETURN_CODE_OK, NULL);
			return TRUE;
		}
	}

	// for method POST, PUT check that the url is "/pathComp"
	if (RestApiMethod == REST_API_METHOD_POST) {
		if (strncmp((const char*)url, "/pathComp/api/v1/compRoute", 26) != 0)
		{
			DEBUG_PC("Unknown url: %s", url);
			RESTapi_stop(client, source, fd);
			exit(-1);
		}
	}
	
	// get the version	
	i = get_version (buf, &j, version);
+6 −78
Original line number Diff line number Diff line
@@ -39,82 +39,9 @@
#include "pathComp_ksp.h"

// Global Variables
struct map_nodes_t *mapNodes = NULL;
struct graph_t *graph = NULL;
struct contextSet_t* contextSet = NULL;
//struct linkList_t* linkList;
//struct deviceList_t* deviceList;
//struct serviceList_t* serviceList;

gint numPathCompIntents = 0;  // number of events triggering the path computation
gint numSuccesPathComp = 0; // number of events resulting in succesfully path computations fulfilling the constraints
struct timeval total_path_comp_time;
gdouble totalReqBw = 0.0;
gdouble totalServedBw = 0.0;

///////////////////////////////////////////////////////////////////////////////////
/**
 * 	@file pathComp_ksp.c
 * 	@brief update statistics of the KSP path computation
 *
 *  @param routeConnList
 *	@param d
 *
 *	@author Ricardo Martínez <ricardo.martinez@cttc.es>
 *	@date 2021
 */
 /////////////////////////////////////////////////////////////////////////////////////////
void update_stats_ksp_path_comp(struct compRouteOutputList_t* routeConnList, struct timeval d)
{
	g_assert(routeConnList);
	g_assert(serviceList);
	
	total_path_comp_time.tv_sec = total_path_comp_time.tv_sec + d.tv_sec;
	total_path_comp_time.tv_usec = total_path_comp_time.tv_usec + d.tv_usec;
	total_path_comp_time = tv_adjust(total_path_comp_time);

	gdouble path_comp_time_msec = (((total_path_comp_time.tv_sec) * 1000) + ((total_path_comp_time.tv_usec) / 1000));
	gdouble av_alg_comp_time = ((path_comp_time_msec / numSuccesPathComp));
	DEBUG_PC("\t --- STATS KSP PATH COMP ----");
	DEBUG_PC("Succesfully Comp: %d | Path Comp Requests: %d", numSuccesPathComp, numPathCompIntents);
	DEBUG_PC("AV. PATH COMP ALG. TIME: %f ms", av_alg_comp_time);

	for (gint i = 0; i < serviceList->numServiceList; i++) {
		struct service_t* s = &(serviceList->services[i]);
		char* eptr;
		for (gint j = 0; j < s->num_service_constraints; j++) {
			struct constraint_t* constraints = &(s->constraints[j]);
			if (strncmp((const char*)(constraints->constraint_type), "bandwidth", 9) == 0) {
				totalReqBw += (gdouble)(strtod((char*)constraints->constraint_value, &eptr));
			}
		}
	}
	for (gint k = 0; k < routeConnList->numCompRouteConnList; k++) {
		struct compRouteOutput_t* rO = &(routeConnList->compRouteConnection[k]);
		if (rO->noPathIssue == NO_PATH_CONS_ISSUE) {
			continue;
		}
		// Get the requested service bw bound to that computed path
		struct path_t* p = &(rO->paths[0]);
		struct service_t* s = get_service_for_computed_path(rO->serviceId.service_uuid);
		if (s == NULL) {
			DEBUG_PC("Weird the service associated to a path is not found");
			exit(-1);
		}
		for (gint l = 0; l < s->num_service_constraints; l++) {
			struct constraint_t* constraints = &(s->constraints[l]);
			char* eptr;
			if (strncmp((const char*)(constraints->constraint_type), "bandwidth", 9) == 0) {
				totalServedBw += (gdouble)(strtod((char*)constraints->constraint_value, &eptr));
			}
		}
	}
	gdouble avServedRatio = totalServedBw / totalReqBw;
	DEBUG_PC("AV. Served Ratio: %f", avServedRatio);
	gdouble avBlockedBwRatio = (gdouble)(1.0 - avServedRatio);
	DEBUG_PC("AV. BBE: %f", avBlockedBwRatio);
	return;
}
struct map_nodes_t *mapNodes;
struct graph_t *graph;
struct contextSet_t* contextSet;

///////////////////////////////////////////////////////////////////////////////////
/**
@@ -260,7 +187,7 @@ gint ksp_comp(struct pred_t* pred, struct graph_t* g, struct service_t* s,
		return -1;
	}

	// Compute the shortes path route
	// Compute the shortest path route
	sp_comp(srcMapIndex, dstMapIndex, g, s, SN, RP);
		
	// Check that a feasible solution in term of latency and bandwidth is found
@@ -579,6 +506,7 @@ void ksp_alg_execution_services(struct compRouteOutputList_t* outputList) {
gint pathComp_ksp_alg(struct compRouteOutputList_t * routeConnList)
{   	
	g_assert(routeConnList);
	gint numSuccesPathComp = 0, numPathCompIntents = 0;
	
	DEBUG_PC ("================================================================");
	DEBUG_PC ("===========================   KSP   =========================");
@@ -608,7 +536,7 @@ gint pathComp_ksp_alg(struct compRouteOutputList_t * routeConnList)
	delta = tv_adjust(delta);

	numSuccesPathComp++;
	update_stats_ksp_path_comp(routeConnList, delta);
	update_stats_path_comp(routeConnList, delta, numSuccesPathComp, numPathCompIntents);
	print_path_connection_list(routeConnList);
#endif

+0 −12
Original line number Diff line number Diff line
@@ -25,18 +25,6 @@
#include <glib/gstdio.h>
#include <glib-2.0/glib/gtypes.h>

#define MAX_KSP_VALUE					3

// HTTP RETURN CODES
#define HTTP_CODE_OK					200
#define HTTP_CODE_CREATED 				201
#define HTTP_CODE_BAD_REQUEST    		400
#define HTTP_CODE_UNAUTHORIZED   		401
#define HTTP_CODE_FORBIDDEN      		403
#define HTTP_CODE_NOT_FOUND				404
#define HTTP_CODE_NOT_ACCEPTABLE		406


// Prototype of external declaration of functions
gint pathComp_ksp_alg (struct compRouteOutputList_t *);

Loading