mirror of
https://github.com/Hizenberg469/Event-Loop-in-C.git
synced 2026-04-19 16:52:24 +03:00
Updated code base
This commit is contained in:
@@ -35,7 +35,7 @@ _udp_server_create_and_start(void* arg) {
|
||||
|
||||
struct sockaddr_in server_addr;
|
||||
server_addr.sin_family = AF_INET;
|
||||
server_addr.sin_port = port_no;
|
||||
server_addr.sin_port = htons(port_no);
|
||||
server_addr.sin_addr.s_addr = INADDR_ANY;
|
||||
|
||||
if (bind(udp_sock_fd, (struct sockaddr*)&server_addr,
|
||||
@@ -110,25 +110,37 @@ send_udp_msg(char* dest_ip_addr,
|
||||
int sock_fd) {
|
||||
|
||||
struct sockaddr_in dest;
|
||||
struct hostent* host;
|
||||
|
||||
// Clear the dest structure
|
||||
memset(&dest, 0, sizeof(dest));
|
||||
|
||||
dest.sin_family = AF_INET;
|
||||
dest.sin_port = dest_port_no;
|
||||
struct hostent* host = (struct hostent*)gethostbyname(dest_ip_addr);
|
||||
dest.sin_addr = *((struct in_addr*)host->h_addr_list);
|
||||
int addr_len = sizeof(struct sockaddr);
|
||||
dest.sin_port = htons(dest_port_no); // Convert port to network byte order
|
||||
|
||||
// Get the host by name
|
||||
host = gethostbyname(dest_ip_addr);
|
||||
if (host == NULL) {
|
||||
printf("Error resolving hostname: %s\n", dest_ip_addr);
|
||||
return -1;
|
||||
}
|
||||
dest.sin_addr = *((struct in_addr*)host->h_addr_list[0]); // Assign IP address
|
||||
|
||||
if (sock_fd < 0) {
|
||||
|
||||
sock_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
|
||||
sock_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); // Create UDP socket
|
||||
if (sock_fd < 0) {
|
||||
printf("socket creation failed, errno = %d\n", errno);
|
||||
printf("Socket creation failed, errno = %d\n", errno);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
sendto(sock_fd, msg, msg_size,
|
||||
0, (struct sockaddr*)&dest,
|
||||
sizeof(struct sockaddr));
|
||||
|
||||
// Send the message
|
||||
int bytes_sent = sendto(sock_fd, msg, msg_size, 0, (struct sockaddr*)&dest, sizeof(dest));
|
||||
if (bytes_sent < 0) {
|
||||
printf("Sendto failed, errno = %d\n", errno);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return sock_fd;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include "utils.h"
|
||||
#include "rt.h"
|
||||
#include "stp_el.h"
|
||||
#include "timerlib.h"
|
||||
#include "stp_el.h"
|
||||
|
||||
rt_table_t*
|
||||
rt_create_new_rt_table(char* name) {
|
||||
@@ -18,6 +19,7 @@ rt_create_new_rt_table(char* name) {
|
||||
|
||||
static void
|
||||
rt_entry_exp_timer_cbk(Timer_t* timer, void* arg) {
|
||||
|
||||
rt_table_t* rt_table;
|
||||
rt_table_entry_t* rt_table_entry = (rt_table_entry_t*)arg;
|
||||
|
||||
@@ -47,7 +49,6 @@ rt_insert_new_entry(rt_table_t* rt,
|
||||
|
||||
rt_table_entry->rt_table = rt;
|
||||
|
||||
|
||||
strncpy(rt_table_entry->dest, dest, 16);
|
||||
rt_table_entry->mask = mask;
|
||||
strncpy(rt_table_entry->gw, gw, 16);
|
||||
@@ -56,7 +57,6 @@ rt_insert_new_entry(rt_table_t* rt,
|
||||
rt_table_entry->prev = 0;
|
||||
time(&rt_table_entry->last_updated_time);
|
||||
|
||||
|
||||
if (exp_timer_in_millisec) {
|
||||
rt_table_entry->exp_timer = setup_timer(
|
||||
rt_entry_exp_timer_cbk,
|
||||
@@ -151,6 +151,12 @@ rt_update_rt_entry(rt_table_t* rt,
|
||||
rt_table_entry->mask == mask &&
|
||||
strncmp(rt_table_entry->gw, new_gw, 16) == 0 &&
|
||||
strncmp(rt_table_entry->oif, new_oif, 32) == 0) {
|
||||
|
||||
/* Refresh the timer */
|
||||
if (rt_table_entry->exp_timer) {
|
||||
restart_timer(rt_table_entry->exp_timer);
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -159,6 +165,13 @@ rt_update_rt_entry(rt_table_t* rt,
|
||||
strncpy(rt_table_entry->gw, new_gw, 16);
|
||||
strncpy(rt_table_entry->oif, new_oif, 32);
|
||||
time(&rt_table_entry->last_updated_time);
|
||||
|
||||
/* Refresh the timer */
|
||||
if (rt_table_entry->exp_timer) {
|
||||
|
||||
restart_timer(rt_table_entry->exp_timer);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -178,16 +191,16 @@ rt_display_rt_table(rt_table_t* rt) {
|
||||
uptime_in_seconds = (unsigned int)difftime(
|
||||
curr_time, rt_table_entry->last_updated_time);
|
||||
|
||||
printf("%d. %-18s %-4d %-18s %-18s ", i,
|
||||
printf("%d. %-18s %-4d %-18s %-18s", i,
|
||||
rt_table_entry->dest,
|
||||
rt_table_entry->mask,
|
||||
rt_table_entry->gw,
|
||||
rt_table_entry->oif);
|
||||
printf("Last updated : %s\n", hrs_min_sec_format(uptime_in_seconds));
|
||||
|
||||
printf("Exp time : %lu\n",
|
||||
rt_table_entry->exp_timer ? \
|
||||
timer_get_time_remaining_in_mill_sec(rt_table_entry->exp_timer) : 0);
|
||||
printf("Last updated : %s ", hrs_min_sec_format(uptime_in_seconds)),
|
||||
printf("Exp time : %lu\n",
|
||||
rt_table_entry->exp_timer ? \
|
||||
timer_get_time_remaining_in_mill_sec(rt_table_entry->exp_timer) : 0);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,9 +6,9 @@ typedef struct rt_table_ rt_table_t;
|
||||
typedef struct rt_table_entry_ rt_table_entry_t;
|
||||
typedef struct Timer_ Timer_t;
|
||||
|
||||
|
||||
#define RT_ENTRY_EXP_TIMER 30 // 30 sec
|
||||
|
||||
|
||||
#define ROUTE_CREATE 1
|
||||
#define ROUTE_UPDATE 2
|
||||
#define ROUTE_DELETE 3
|
||||
@@ -20,12 +20,11 @@ struct rt_table_entry_ {
|
||||
char gw[16];
|
||||
char oif[32];
|
||||
time_t last_updated_time;
|
||||
Timer_t* exp_timer;
|
||||
struct rt_table_entry_* next;
|
||||
struct rt_table_entry_* prev;
|
||||
rt_table_t* rt_table; /* back ptr to owning rt table*/
|
||||
|
||||
Timer_t* exp_timer;
|
||||
int exp_timer_msec;
|
||||
rt_table_t* rt_table; /* back ptr to owning rt table*/
|
||||
};
|
||||
|
||||
struct rt_table_ {
|
||||
|
||||
@@ -6,8 +6,9 @@
|
||||
#include "rt.h"
|
||||
#include "stp_el.h"
|
||||
|
||||
|
||||
/* Import external global variable */
|
||||
extern event_loop_t el;
|
||||
|
||||
rt_table_t* rt_table = NULL;
|
||||
|
||||
int
|
||||
@@ -37,7 +38,7 @@ pkt_process_fn(char* msg_recvd, uint32_t msg_size, char* sender_ip, uint32_t por
|
||||
uint32_t* cmd_code = (uint32_t*)msg_recvd;
|
||||
rt_table_entry_t* rt_entry = (rt_table_entry_t*)(cmd_code + 1);
|
||||
rt_entry->exp_timer_msec = RT_ENTRY_EXP_TIMER * 1000;
|
||||
|
||||
//stp_update_routing_table(rt_table, *cmd_code, rt_entry);
|
||||
el_stp_update_routing_table(rt_table, *cmd_code, rt_entry);
|
||||
}
|
||||
|
||||
@@ -48,8 +49,7 @@ cli_handler(int choice)
|
||||
{
|
||||
case 1:
|
||||
//rt_display_rt_table(rt_table);
|
||||
|
||||
rt_display_rt_table_preemption_context_save(rt_table);
|
||||
rt_display_rt_table_preemption_conext_save(rt_table);
|
||||
printf("\n\n");
|
||||
break;
|
||||
case 2:
|
||||
@@ -61,6 +61,8 @@ cli_handler(int choice)
|
||||
scanf("%s", rt_entry.gw);
|
||||
printf("Enter OIF name : ");
|
||||
scanf("%s", rt_entry.oif);
|
||||
rt_entry.exp_timer_msec = 0; /* rt entries created by CLI must never expire*/
|
||||
//stp_update_routing_table(rt_table, ROUTE_CREATE, &rt_entry);
|
||||
el_stp_update_routing_table(rt_table, ROUTE_CREATE, &rt_entry);
|
||||
}
|
||||
break;
|
||||
@@ -72,10 +74,13 @@ cli_handler(int choice)
|
||||
rt_table_entry_t rt_entry;
|
||||
printf("Enter Dest Address : ");
|
||||
scanf("%s", rt_entry.dest);
|
||||
if (el_stp_update_routing_table(rt_table, ROUTE_DELETE, &rt_entry))
|
||||
#if 0
|
||||
if (stp_update_routing_table(rt_table, ROUTE_DELETE, &rt_entry))
|
||||
{
|
||||
printf("No Such entry\n");
|
||||
}
|
||||
#endif
|
||||
el_stp_update_routing_table(rt_table, ROUTE_DELETE, &rt_entry);
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
@@ -89,17 +94,15 @@ cli_handler(int choice)
|
||||
break;
|
||||
case 6:
|
||||
{
|
||||
rt_table_entry_t rt_entry_template;
|
||||
printf("Entry Dest Address : ");
|
||||
scanf("%s", rt_entry_template.dest);
|
||||
el_stp_serialize_and_send_rt_entry(rt_table, &rt_entry_template);
|
||||
rt_table_entry_t rt_entry_tmplate;
|
||||
printf("Enter Dest Address : ");
|
||||
scanf("%s", rt_entry_tmplate.dest);
|
||||
el_stp_serialize_and_send_rt_entry(rt_table, &rt_entry_tmplate);
|
||||
}
|
||||
break;
|
||||
case 7:
|
||||
{
|
||||
el_stp_delete_rt_table(rt_table);
|
||||
}
|
||||
break;
|
||||
break;
|
||||
case 8:
|
||||
exit(0);
|
||||
default:
|
||||
@@ -116,6 +119,8 @@ main(int argc, char** argv) {
|
||||
printf(" New Routing Table Created\n");
|
||||
}
|
||||
|
||||
stp_init_el(&el);
|
||||
|
||||
for (;;) {
|
||||
|
||||
printf("Main Menu\n");
|
||||
|
||||
@@ -6,10 +6,10 @@
|
||||
#include <stdio.h>
|
||||
#include "utils.h"
|
||||
#include "network_utils.h"
|
||||
#include "stp_el.h"
|
||||
#include "timerlib.h"
|
||||
#include "stp_el.h"
|
||||
|
||||
/* Take Event loop global variable */
|
||||
/* Take Event Loop global variable */
|
||||
event_loop_t el;
|
||||
|
||||
/* Import external function */
|
||||
@@ -18,233 +18,238 @@ stp_update_routing_table(rt_table_t* rt_table, uint32_t cmd_code, rt_table_entry
|
||||
|
||||
void
|
||||
stp_init_el(event_loop_t* el) {
|
||||
event_loop_init(el);
|
||||
event_loop_run(el);
|
||||
|
||||
event_loop_init(el);
|
||||
event_loop_run(el);
|
||||
}
|
||||
|
||||
static EL_RES_T
|
||||
el_stp_update_routing_table_cbk(void* arg) {
|
||||
|
||||
el_rt_table_update_data_t* el_rt_table_update_data =
|
||||
(el_rt_table_update_data_t*)arg;
|
||||
el_rt_table_update_data_t* el_rt_table_update_data =
|
||||
(el_rt_table_update_data_t*)arg;
|
||||
|
||||
stp_update_routing_table(el_rt_table_update_data->rt_table,
|
||||
el_rt_table_update_data->cmd_code,
|
||||
el_rt_table_update_data->rt_entry);
|
||||
stp_update_routing_table(el_rt_table_update_data->rt_table,
|
||||
el_rt_table_update_data->cmd_code,
|
||||
el_rt_table_update_data->rt_entry);
|
||||
|
||||
free(el_rt_table_update_data->rt_entry);
|
||||
free(el_rt_table_update_data);
|
||||
return EL_FINISH;
|
||||
free(el_rt_table_update_data->rt_entry);
|
||||
free(el_rt_table_update_data);
|
||||
return EL_FINISH;
|
||||
}
|
||||
|
||||
task_t*
|
||||
el_stp_update_routing_table(rt_table_t* rt, int cmd_code, rt_table_entry_t* rt_entry) {
|
||||
el_rt_table_update_data_t* el_rt_table_update_data =
|
||||
(el_rt_table_update_data_t*)calloc(1, sizeof(el_rt_table_update_data_t));
|
||||
el_stp_update_routing_table(rt_table_t* rt_table, int cmd_code, rt_table_entry_t* rt_entry) {
|
||||
|
||||
el_rt_table_update_data->rt_table = rt;
|
||||
el_rt_table_update_data->cmd_code = cmd_code;
|
||||
el_rt_table_update_data_t* el_rt_table_update_data =
|
||||
(el_rt_table_update_data_t*)calloc(1, sizeof(el_rt_table_update_data_t));
|
||||
|
||||
el_rt_table_update_data->rt_entry = (rt_table_entry_t*)calloc(1, sizeof(rt_table_entry_t));
|
||||
el_rt_table_update_data->rt_table = rt_table;
|
||||
el_rt_table_update_data->cmd_code = cmd_code;
|
||||
|
||||
memcpy((char*)el_rt_table_update_data->rt_entry,
|
||||
rt_entry, sizeof(*rt_entry));
|
||||
el_rt_table_update_data->rt_entry = (rt_table_entry_t*)calloc(1, sizeof(rt_table_entry_t));
|
||||
|
||||
task_t* task = task_create_new_job(&el,
|
||||
el_stp_update_routing_table_cbk,
|
||||
(void*)el_rt_table_update_data, cmd_code == ROUTE_DELETE ? TASK_PRIORITY_LOW : TASK_PRIORITY_MEDIUM);
|
||||
memcpy((char*)el_rt_table_update_data->rt_entry,
|
||||
rt_entry, sizeof(*rt_entry));
|
||||
|
||||
return task;
|
||||
task_t* task = task_create_new_job(&el,
|
||||
el_stp_update_routing_table_cbk,
|
||||
(void*)el_rt_table_update_data,
|
||||
cmd_code == ROUTE_DELETE ? TASK_PRIORITY_LOW : TASK_PRIORITY_MEDIUM);
|
||||
return task;
|
||||
}
|
||||
|
||||
|
||||
typedef struct rt_table_print_cntxt_ {
|
||||
int i;
|
||||
rt_table_entry_t* rt_table_entry;
|
||||
}rt_table_print_cntxt_t;
|
||||
|
||||
int i;
|
||||
rt_table_entry_t* rt_table_entry;
|
||||
|
||||
} rt_table_print_cntxt_t;
|
||||
|
||||
|
||||
static EL_RES_T
|
||||
rt_display_rt_table_preemption_context_save_cbk(void* arg) {
|
||||
rt_display_rt_table_preemption_conext_save_cbk(void* arg) {
|
||||
|
||||
time_t curr_time = time(NULL);
|
||||
unsigned int uptime_in_seconds = 0;
|
||||
rt_table_print_cntxt_t* cntxt = (rt_table_print_cntxt_t*)arg;
|
||||
time_t curr_time = time(NULL);
|
||||
unsigned int uptime_in_seconds = 0;
|
||||
rt_table_print_cntxt_t* cntxt = (rt_table_print_cntxt_t*)arg;
|
||||
|
||||
rt_table_entry_t* rt_table_entry = cntxt->rt_table_entry;
|
||||
int i = cntxt->i;
|
||||
rt_table_entry_t* rt_table_entry = cntxt->rt_table_entry;
|
||||
int i = cntxt->i;
|
||||
|
||||
for (; rt_table_entry;
|
||||
rt_table_entry = rt_table_entry->next) {
|
||||
for (; rt_table_entry;
|
||||
rt_table_entry = rt_table_entry->next) {
|
||||
|
||||
uptime_in_seconds = (unsigned int)difftime(
|
||||
curr_time, rt_table_entry->last_updated_time);
|
||||
|
||||
uptime_in_seconds = (unsigned int)difftime(
|
||||
curr_time, rt_table_entry->last_updated_time);
|
||||
printf("%d. %-18s %-4d %-18s %-18s", i,
|
||||
rt_table_entry->dest,
|
||||
rt_table_entry->mask,
|
||||
rt_table_entry->gw,
|
||||
rt_table_entry->oif);
|
||||
|
||||
printf("%d. %-18s %-4d %18s %-18s", i,
|
||||
rt_table_entry->dest,
|
||||
rt_table_entry->mask,
|
||||
rt_table_entry->gw,
|
||||
rt_table_entry->oif);
|
||||
printf("Last updated : %s ", hrs_min_sec_format(uptime_in_seconds)),
|
||||
printf("Exp time : %lu\n",
|
||||
rt_table_entry->exp_timer ? \
|
||||
timer_get_time_remaining_in_mill_sec(rt_table_entry->exp_timer) : 0);
|
||||
i++;
|
||||
|
||||
printf("Last updated : %s ", hrs_min_sec_format(uptime_in_seconds));
|
||||
/* Save the context*/
|
||||
if (i % 10 == 0 && rt_table_entry->next) {
|
||||
|
||||
printf("Exp time : %lu\n",
|
||||
rt_table_entry->exp_timer ? \
|
||||
timer_get_time_remaining_in_mill_sec(rt_table_entry->exp_timer) : 0);
|
||||
i++;
|
||||
cntxt->rt_table_entry = rt_table_entry->next;
|
||||
cntxt->i = i++;
|
||||
return EL_CONTINUE;
|
||||
}
|
||||
}
|
||||
|
||||
/* Save the context */
|
||||
if (i % 10 == 0 && rt_table_entry->next) {
|
||||
cntxt->rt_table_entry = rt_table_entry->next;
|
||||
cntxt->i = i++;
|
||||
return EL_CONTINUE;
|
||||
}
|
||||
}
|
||||
|
||||
free(cntxt);
|
||||
return EL_FINISH;
|
||||
free(cntxt);
|
||||
return EL_FINISH;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
rt_display_rt_table_preemption_context_save(rt_table_t* rt) {
|
||||
rt_display_rt_table_preemption_conext_save(rt_table_t* rt) {
|
||||
|
||||
rt_table_entry_t* rt_table_entry = rt->head;
|
||||
rt_table_entry_t* rt_table_entry = rt->head;
|
||||
|
||||
if (!rt_table_entry) return;
|
||||
if (!rt_table_entry) return;
|
||||
|
||||
printf("# count = %u\n", rt->count);
|
||||
printf("# count = %u\n", rt->count);
|
||||
|
||||
rt_table_print_cntxt_t* cntxt =
|
||||
(rt_table_print_cntxt_t*)calloc(1, sizeof(rt_table_print_cntxt_t));
|
||||
rt_table_print_cntxt_t* cntxt =
|
||||
(rt_table_print_cntxt_t*)calloc(1, sizeof(rt_table_print_cntxt_t));
|
||||
|
||||
cntxt->i = 1;
|
||||
cntxt->rt_table_entry = rt_table_entry;
|
||||
cntxt->i = 1;
|
||||
cntxt->rt_table_entry = rt_table_entry;
|
||||
|
||||
task_create_new_job(&el,
|
||||
rt_display_rt_table_preemption_context_save_cbk,
|
||||
(void*)cntxt, TASK_PRIORITY_HIGH);
|
||||
task_create_new_job(&el,
|
||||
rt_display_rt_table_preemption_conext_save_cbk,
|
||||
(void*)cntxt, TASK_PRIORITY_HIGH);
|
||||
}
|
||||
|
||||
|
||||
static EL_RES_T
|
||||
rt_entry_serialize_and_send_task_cbk(void* arg) {
|
||||
rt_entry_serlialize_and_send_task_cbk(void* arg) {
|
||||
|
||||
rt_table_entry_t* rt_entry = (rt_table_entry_t*)arg;
|
||||
rt_table_entry_t* rt_entry = (rt_table_entry_t*)arg;
|
||||
|
||||
/* look up RT Entry in RT table */
|
||||
rt_table_entry_t* actual_rt_entry = rt_look_up_rt_table_entry(
|
||||
rt_entry->rt_table,
|
||||
rt_entry->dest,
|
||||
rt_entry->mask
|
||||
);
|
||||
/* look up RT entry in RT table*/
|
||||
rt_table_entry_t* actual_rt_entry = rt_look_up_rt_table_entry(
|
||||
rt_entry->rt_table,
|
||||
rt_entry->dest,
|
||||
rt_entry->mask);
|
||||
|
||||
if (!actual_rt_entry) {
|
||||
printf("Serialize Task : RT Entry do not exist\n");
|
||||
free(rt_entry);
|
||||
return EL_FINISH;
|
||||
}
|
||||
if (!actual_rt_entry) {
|
||||
|
||||
int udp_sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
printf("Serialize Task : RT Entry do not exist\n");
|
||||
free(rt_entry);
|
||||
return EL_FINISH;
|
||||
}
|
||||
|
||||
if (udp_sockfd < 0) {
|
||||
printf("Error : Failed to create UDP socket\n");
|
||||
free(rt_entry);
|
||||
return EL_FINISH;
|
||||
}
|
||||
int udp_sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
|
||||
int msg_size = sizeof(uint32_t) + sizeof(rt_table_entry_t);
|
||||
uint32_t* msg_to_send = (uint32_t*)calloc(1, msg_size);
|
||||
*msg_to_send = ROUTE_CREATE;
|
||||
memcpy((char*)(msg_to_send + 1), (char*)actual_rt_entry, sizeof(rt_table_entry_t));
|
||||
if (udp_sockfd < 0) {
|
||||
printf("Error : Failed to create UDP socket\n");
|
||||
free(rt_entry);
|
||||
return EL_FINISH;
|
||||
}
|
||||
|
||||
send_udp_msg("127.0.0.1",
|
||||
50000,
|
||||
(char*)msg_to_send, msg_size,
|
||||
udp_sockfd);
|
||||
int msg_size = sizeof(uint32_t) + sizeof(rt_table_entry_t);
|
||||
uint32_t* msg_to_send = (uint32_t*)calloc(1, msg_size);
|
||||
*msg_to_send = ROUTE_CREATE;
|
||||
memcpy((char*)(msg_to_send + 1), (char*)actual_rt_entry, sizeof(rt_table_entry_t));
|
||||
|
||||
close(udp_sockfd);
|
||||
free(msg_to_send);
|
||||
free(rt_entry);
|
||||
return EL_FINISH;
|
||||
send_udp_msg("127.0.0.1",
|
||||
50000,
|
||||
(char*)msg_to_send, msg_size,
|
||||
udp_sockfd);
|
||||
|
||||
close(udp_sockfd);
|
||||
free(msg_to_send);
|
||||
free(rt_entry);
|
||||
return EL_FINISH;
|
||||
}
|
||||
|
||||
void
|
||||
el_stp_serialize_and_send_rt_entry(rt_table_t* rt, rt_table_entry_t* rt_entry_template) {
|
||||
el_stp_serialize_and_send_rt_entry(rt_table_t* rt_table, rt_table_entry_t* rt_entry_tmplate) {
|
||||
|
||||
/* This new rt_entry serves the purpose of context-save structure for task */
|
||||
/* This new rt_entry serves the purpose of context-save structure for this task*/
|
||||
rt_table_entry_t* rt_entry = (rt_table_entry_t*)calloc(1, sizeof(rt_table_entry_t));
|
||||
strncpy(rt_entry->dest, rt_entry_tmplate->dest, 16);
|
||||
rt_entry->mask = 32;
|
||||
rt_entry->rt_table = rt_table;
|
||||
|
||||
rt_table_entry_t* rt_entry = (rt_table_entry_t*)calloc(1, sizeof(rt_table_entry_t));
|
||||
|
||||
strncpy(rt_entry->dest, rt_entry_template->dest, 16);
|
||||
|
||||
rt_entry->mask = 32;
|
||||
rt_entry->rt_table = rt;
|
||||
|
||||
task_create_new_job(&el,
|
||||
rt_entry_serialize_and_send_task_cbk,
|
||||
(void*)rt_entry, TASK_PRIORITY_MEDIUM);
|
||||
task_create_new_job(&el,
|
||||
rt_entry_serlialize_and_send_task_cbk,
|
||||
(void*)rt_entry, TASK_PRIORITY_MEDIUM);
|
||||
}
|
||||
|
||||
|
||||
|
||||
typedef struct rt_table_delete_context_ {
|
||||
rt_table_entry_t* rt_entry;
|
||||
}rt_table_delete_context_t;
|
||||
|
||||
rt_table_entry_t* rt_entry;
|
||||
|
||||
} rt_table_delete_context_t;
|
||||
|
||||
|
||||
EL_RES_T
|
||||
rt_table_delete_cbk(void* arg) {
|
||||
int i = 0;
|
||||
|
||||
rt_table_delete_context_t* cntxt = (rt_table_delete_context_t*)arg;
|
||||
int i = 0;
|
||||
|
||||
rt_table_entry_t* rt_entry = cntxt->rt_entry;
|
||||
rt_table_entry_t* rt_entry_next;
|
||||
rt_table_delete_context_t* cntxt = (rt_table_delete_context_t*)arg;
|
||||
|
||||
printf("Resuming rt_table deletion Task\n");
|
||||
rt_table_entry_t* rt_entry = cntxt->rt_entry;
|
||||
rt_table_entry_t* rt_entry_next;
|
||||
|
||||
do {
|
||||
rt_entry_next = rt_entry->next;
|
||||
printf("Resuming rt_table deletion Task\n");
|
||||
|
||||
if (rt_entry->exp_timer) {
|
||||
delete_timer(rt_entry->exp_timer);
|
||||
rt_entry->exp_timer = NULL;
|
||||
}
|
||||
do {
|
||||
|
||||
printf("Deleting rt_entry = %s/%d\n", rt_entry->dest, rt_entry->mask);
|
||||
free(rt_entry);
|
||||
i++;
|
||||
rt_entry_next = rt_entry->next;
|
||||
|
||||
if (i % 10 == 0 && rt_entry_next) {
|
||||
cntxt->rt_entry = rt_entry_next;
|
||||
printf("Preempting rt_table deletion Task\n");
|
||||
return EL_CONTINUE;
|
||||
}
|
||||
if (rt_entry->exp_timer) {
|
||||
delete_timer(rt_entry->exp_timer);
|
||||
rt_entry->exp_timer = NULL;
|
||||
}
|
||||
|
||||
printf("Deleting rt_entry = %s/%d\n", rt_entry->dest, rt_entry->mask);
|
||||
free(rt_entry);
|
||||
i++;
|
||||
|
||||
rt_entry = rt_entry_next;
|
||||
} while (rt_entry);
|
||||
if (i % 10 == 0 && rt_entry_next) {
|
||||
cntxt->rt_entry = rt_entry_next;
|
||||
printf("Preempting rt_table deletion Task\n");
|
||||
return EL_CONTINUE;
|
||||
}
|
||||
|
||||
free(cntxt);
|
||||
printf("rt_table deletion Task Finished\n");
|
||||
return EL_FINISH;
|
||||
rt_entry = rt_entry_next;
|
||||
|
||||
} while (rt_entry);
|
||||
|
||||
free(cntxt);
|
||||
printf("rt_table deletion Task Finished\n");
|
||||
return EL_FINISH;
|
||||
}
|
||||
|
||||
void
|
||||
el_stp_delete_rt_table(rt_table_t* rt_table) {
|
||||
|
||||
/* This is the case when we need to delete a container data structures.
|
||||
Container data structures must be isolated from remaining application data structures first */
|
||||
/* This is the case when we need to delete a container data structures.
|
||||
Container data structures must be isloted from remaining application data structures first*/
|
||||
if (!rt_table) return;
|
||||
if (!rt_table->head) return;
|
||||
|
||||
if (!rt_table) return;
|
||||
if (!rt_table->head) return;
|
||||
/* Isolate RT Table*/
|
||||
rt_table_entry_t* rt_entry = rt_table->head;
|
||||
rt_table->head = NULL;
|
||||
|
||||
/* Isolate RT Table */
|
||||
rt_table_entry_t* rt_entry = rt_table->head;
|
||||
rt_table->head = NULL;
|
||||
rt_table_delete_context_t* cntxt = (rt_table_delete_context_t*)calloc(1, sizeof(rt_table_delete_context_t));
|
||||
cntxt->rt_entry = rt_entry;
|
||||
|
||||
rt_table_delete_context_t* cntxt = (rt_table_delete_context_t*)calloc(1, sizeof(rt_table_delete_context_t));
|
||||
cntxt->rt_entry = rt_entry;
|
||||
|
||||
task_create_new_job(&el, rt_table_delete_cbk,
|
||||
(void*)cntxt, TASK_PRIORITY_LOW);
|
||||
task_create_new_job(&el, rt_table_delete_cbk,
|
||||
(void*)cntxt, TASK_PRIORITY_LOW);
|
||||
}
|
||||
@@ -1,32 +1,30 @@
|
||||
#ifndef __STP_EL__
|
||||
#define __STP_EL__
|
||||
|
||||
#include <event_loop.h>
|
||||
|
||||
#include "event_loop.h"
|
||||
#include "rt.h"
|
||||
|
||||
/* Data structure to pack all argument to one single argument */
|
||||
/* Data Structure to pack all arguments as one single argument */
|
||||
|
||||
typedef struct el_rt_table_update_data_ {
|
||||
|
||||
rt_table_t* rt_table;
|
||||
int cmd_code;
|
||||
rt_table_entry_t* rt_entry;
|
||||
}el_rt_table_update_data_t;
|
||||
rt_table_t* rt_table;
|
||||
int cmd_code;
|
||||
rt_table_entry_t* rt_entry;
|
||||
} el_rt_table_update_data_t;
|
||||
|
||||
void
|
||||
stp_init_el(event_loop_t* el);
|
||||
|
||||
/* Now create APIs' to update routing table using Event loop */
|
||||
|
||||
/* Now create an API to update routing table using Event Loop */
|
||||
task_t*
|
||||
el_stp_update_routing_table(rt_table_t* rt, int cmd_code, rt_table_entry_t* rt_entry);
|
||||
|
||||
void
|
||||
rt_display_rt_table_preemption_context_save(rt_table_t* rt);
|
||||
rt_display_rt_table_preemption_conext_save(rt_table_t* rt);
|
||||
|
||||
void
|
||||
el_stp_serialize_and_send_rt_entry(rt_table_t* rt, rt_table_entry_t* rt_entry_template);
|
||||
el_stp_serialize_and_send_rt_entry(rt_table_t* rt, rt_table_entry_t* rt_entry);
|
||||
|
||||
void
|
||||
el_stp_delete_rt_table(rt_table_t* rt_table);
|
||||
|
||||
@@ -42,18 +42,12 @@ typedef struct Timer_ {
|
||||
* return a pointer to Timer object*/
|
||||
Timer_t*
|
||||
setup_timer(
|
||||
/* Timer Callback with user data and user size*/
|
||||
void (*)(Timer_t*, void*),
|
||||
/* First expiration time interval in msec */
|
||||
unsigned long,
|
||||
/* Subsequent expiration time interval in msec */
|
||||
unsigned long,
|
||||
/* Max no of expirations, 0 for infinite*/
|
||||
uint32_t,
|
||||
/* Arg to timer callback */
|
||||
void*,
|
||||
/* Is timer Exp back off */
|
||||
bool);
|
||||
void (*timer_cb)(Timer_t*, void*), /* Timer Callback with user data*/
|
||||
unsigned long exp_timer, /* First expiration time interval in msec */
|
||||
unsigned long sec_exp_timer, /* Subsequent expiration time interval in msec */
|
||||
uint32_t threshold, /* Max no of expirations, 0 for infinite*/
|
||||
void* user_arg, /* Arg to timer callback */
|
||||
bool exponential_backoff);
|
||||
|
||||
static inline void
|
||||
timer_delete_user_data(Timer_t* timer) {
|
||||
|
||||
Reference in New Issue
Block a user