diff options
Diffstat (limited to 'ctrl/sysrepo-plugins/hicn-light/plugin')
9 files changed, 130 insertions, 163 deletions
diff --git a/ctrl/sysrepo-plugins/hicn-light/plugin/CMakeLists.txt b/ctrl/sysrepo-plugins/hicn-light/plugin/CMakeLists.txt index 85da0d3e9..b5faab705 100644 --- a/ctrl/sysrepo-plugins/hicn-light/plugin/CMakeLists.txt +++ b/ctrl/sysrepo-plugins/hicn-light/plugin/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 Cisco and/or its affiliates. +# Copyright (c) 2021 Cisco and/or its affiliates. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at: diff --git a/ctrl/sysrepo-plugins/hicn-light/plugin/hicn_light.c b/ctrl/sysrepo-plugins/hicn-light/plugin/hicn_light.c index 6cfc0b52b..b2495f730 100644 --- a/ctrl/sysrepo-plugins/hicn-light/plugin/hicn_light.c +++ b/ctrl/sysrepo-plugins/hicn-light/plugin/hicn_light.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Cisco and/or its affiliates. + * Copyright (c) 2021 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: @@ -21,8 +21,6 @@ #include "hicn_light.h" #include "model/hicn_model.h" - - sr_subscription_ctx_t *subscription = NULL; volatile int exit_application = 0; @@ -37,7 +35,6 @@ int sr_plugin_init_cb(sr_session_ctx_t *session, void **private_ctx) { hicn_subscribe_events(session, &subscription); - /* set subscription as our private context */ *private_ctx = subscription; return SR_ERR_OK; diff --git a/ctrl/sysrepo-plugins/hicn-light/plugin/hicn_light.h b/ctrl/sysrepo-plugins/hicn-light/plugin/hicn_light.h index 16f65e5c4..cea2851c9 100644 --- a/ctrl/sysrepo-plugins/hicn-light/plugin/hicn_light.h +++ b/ctrl/sysrepo-plugins/hicn-light/plugin/hicn_light.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Cisco and/or its affiliates. + * Copyright (c) 2021 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: diff --git a/ctrl/sysrepo-plugins/hicn-light/plugin/hicn_light_comm.c b/ctrl/sysrepo-plugins/hicn-light/plugin/hicn_light_comm.c index 6c4f938ce..08551b470 100644 --- a/ctrl/sysrepo-plugins/hicn-light/plugin/hicn_light_comm.c +++ b/ctrl/sysrepo-plugins/hicn-light/plugin/hicn_light_comm.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Cisco and/or its affiliates. + * Copyright (c) 2021 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: @@ -14,20 +14,17 @@ */ #include "hicn_light_comm.h" -hc_sock_t * hsocket; +hc_sock_t* hsocket; int hicn_connect_light() { - - hsocket = hc_sock_create(); - if (!hsocket) - HICN_LOG_ERR_MSG("Error creating socket\n"); - if (hc_sock_connect(hsocket) < 0) - HICN_LOG_ERR_MSG("Error connecting to the forwarder\n"); - return 0; - + hsocket = hc_sock_create(); + if (!hsocket) HICN_LOG_ERR_MSG("Error creating socket\n"); + if (hc_sock_connect(hsocket) < 0) + HICN_LOG_ERR_MSG("Error connecting to the forwarder\n"); + return 0; } int hicn_disconnect_light() { - hc_sock_free(hsocket); + hc_sock_free(hsocket); return 0; }
\ No newline at end of file diff --git a/ctrl/sysrepo-plugins/hicn-light/plugin/hicn_light_comm.h b/ctrl/sysrepo-plugins/hicn-light/plugin/hicn_light_comm.h index ca67cf0b7..c03d59c30 100644 --- a/ctrl/sysrepo-plugins/hicn-light/plugin/hicn_light_comm.h +++ b/ctrl/sysrepo-plugins/hicn-light/plugin/hicn_light_comm.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Cisco and/or its affiliates. + * Copyright (c) 2021 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: @@ -18,7 +18,6 @@ #include <sysrepo.h> #include <sysrepo/values.h> - #include <hicn/ctrl/api.h> #ifndef HICN_THIS_FUNC @@ -37,23 +36,20 @@ } \ } while (0) - - #define ARG_CHECK2(retval, arg1, arg2) \ - ARG_CHECK(retval, arg1); \ - ARG_CHECK(retval, arg2) + ARG_CHECK(retval, arg1); \ + ARG_CHECK(retval, arg2) #define ARG_CHECK5(retval, arg1, arg2, arg3, arg4, arg5) \ - ARG_CHECK(retval, arg1); \ - ARG_CHECK(retval, arg2); \ - ARG_CHECK(retval, arg3); \ - ARG_CHECK(retval, arg4); \ - ARG_CHECK(retval, arg5) - + ARG_CHECK(retval, arg1); \ + ARG_CHECK(retval, arg2); \ + ARG_CHECK(retval, arg3); \ + ARG_CHECK(retval, arg4); \ + ARG_CHECK(retval, arg5) #define MEM_ALIGN 4096 int hicn_connect_light(); int hicn_disconnect_light(); -extern hc_sock_t * hsocket; +extern hc_sock_t* hsocket; #endif //__HICN_LIGHT_COMMM_H__ diff --git a/ctrl/sysrepo-plugins/hicn-light/plugin/model/hicn_model.c b/ctrl/sysrepo-plugins/hicn-light/plugin/model/hicn_model.c index 47e07d196..d32fd55ef 100644 --- a/ctrl/sysrepo-plugins/hicn-light/plugin/model/hicn_model.c +++ b/ctrl/sysrepo-plugins/hicn-light/plugin/model/hicn_model.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Cisco and/or its affiliates. + * Copyright (c) 2021 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: @@ -22,72 +22,67 @@ #include "tlock.h" #include "../hicn_light.h" #include "../hicn_light_comm.h" - - +#include <hicn/util/sstrncpy.h> /** * @brief API to add hicn face ip in hicn-light. */ -static int hicn_face_ip_add_cb(sr_session_ctx_t *session, const char *path, const sr_val_t *input, const size_t input_cnt, - sr_event_t event, uint32_t request_id, sr_val_t **output, size_t *output_cnt, void *private_data) { - +static int hicn_face_ip_add_cb(sr_session_ctx_t *session, const char *path, + const sr_val_t *input, const size_t input_cnt, + sr_event_t event, uint32_t request_id, + sr_val_t **output, size_t *output_cnt, + void *private_data) { SRP_LOG_DBGMSG("hicn face ip add received successfully"); hc_face_t face; - if(strcmp(input[0].data.string_val,"-1")){ - - struct sockaddr_in sa; - // store this IP address in sa: - inet_pton(AF_INET, input[0].data.string_val, &(sa.sin_addr)); - face.face.family=AF_INET; - face.face.local_addr.v4.as_inaddr=sa.sin_addr; - - - }else if(strcmp(input[1].data.string_val,"-1")){ - + if (strcmp(input[0].data.string_val, "-1")) { + struct sockaddr_in sa; + // store this IP address in sa: + inet_pton(AF_INET, input[0].data.string_val, &(sa.sin_addr)); + face.face.family = AF_INET; + face.face.local_addr.v4.as_inaddr = sa.sin_addr; + + } else if (strcmp(input[1].data.string_val, "-1")) { struct in6_addr *dst = malloc(sizeof(struct in6_addr)); inet_pton(AF_INET6, input[1].data.string_val, dst); - face.face.family=AF_INET6; + face.face.family = AF_INET6; face.face.local_addr.v6.as_in6addr = *dst; - }else{ - SRP_LOG_DBGMSG("Invalid local IP address"); - return SR_ERR_OPERATION_FAILED; + } else { + SRP_LOG_DBGMSG("Invalid local IP address"); + return SR_ERR_OPERATION_FAILED; } - if(strcmp(input[2].data.string_val,"-1")){ - - struct sockaddr_in sa; - // store this IP address in sa: - inet_pton(AF_INET, input[2].data.string_val, &(sa.sin_addr)); - face.face.family=AF_INET; - face.face.remote_addr.v4.as_inaddr=sa.sin_addr; - - - }else if(strcmp(input[3].data.string_val,"-1")){ + if (strcmp(input[2].data.string_val, "-1")) { + struct sockaddr_in sa; + // store this IP address in sa: + inet_pton(AF_INET, input[2].data.string_val, &(sa.sin_addr)); + face.face.family = AF_INET; + face.face.remote_addr.v4.as_inaddr = sa.sin_addr; + } else if (strcmp(input[3].data.string_val, "-1")) { struct in6_addr *dst = malloc(sizeof(struct in6_addr)); inet_pton(AF_INET6, input[3].data.string_val, dst); - face.face.family=AF_INET6; + face.face.family = AF_INET6; face.face.remote_addr.v6.as_in6addr = *dst; - }else{ - SRP_LOG_DBGMSG("Invalid local IP address"); - return SR_ERR_OPERATION_FAILED; + } else { + SRP_LOG_DBGMSG("Invalid local IP address"); + return SR_ERR_OPERATION_FAILED; } - - face.face.netdevice.index = input[4].data.uint32_val; // This is the idx number of interface - - - face.id=0;//can be empty - strcpy(face.name,"hicn_face"); - face.face.type=1; + face.face.netdevice.index = + input[4].data.uint32_val; // This is the idx number of interface int rc; + face.id = 0; // can be empty + rc = strcpy_s(face.name, sizeof(face.name), "hicn_face"); + if (rc != EOK) return SR_ERR_OPERATION_FAILED; + face.face.type = 1; + rc = hc_face_create(hsocket, &face); if (rc > 0) { - SRP_LOG_DBGMSG("Face added successfully"); - return SR_ERR_OK; + SRP_LOG_DBGMSG("Face added successfully"); + return SR_ERR_OK; } SRP_LOG_DBGMSG("Operation Failed"); @@ -97,92 +92,84 @@ static int hicn_face_ip_add_cb(sr_session_ctx_t *session, const char *path, cons /** * @brief API to del hicn face ip in vpp. */ -static int hicn_face_ip_del_cb(sr_session_ctx_t *session, const char *path, const sr_val_t *input, const size_t input_cnt, - sr_event_t event, uint32_t request_id, sr_val_t **output, size_t *output_cnt, void *private_data) { - +static int hicn_face_ip_del_cb(sr_session_ctx_t *session, const char *path, + const sr_val_t *input, const size_t input_cnt, + sr_event_t event, uint32_t request_id, + sr_val_t **output, size_t *output_cnt, + void *private_data) { SRP_LOG_DBGMSG("hicn face ip del received successfully"); - face_t * face=NULL; - + face_t *face = NULL; face_free(face); - - SRP_LOG_DBGMSG("Operation Failed"); return SR_ERR_OPERATION_FAILED; - } - /** * @brief API to del hicn face ip in vpp. */ -static int hicn_route_add_cb(sr_session_ctx_t *session, const char *path, const sr_val_t *input, const size_t input_cnt, - sr_event_t event, uint32_t request_id, sr_val_t **output, size_t *output_cnt, void *private_data) { +static int hicn_route_add_cb(sr_session_ctx_t *session, const char *path, + const sr_val_t *input, const size_t input_cnt, + sr_event_t event, uint32_t request_id, + sr_val_t **output, size_t *output_cnt, + void *private_data) { + /* -/* + SRP_LOG_DBG_MSG("hicn route add received successfully"); - SRP_LOG_DBG_MSG("hicn route add received successfully"); + hc_route_t * route; - hc_route_t * route; + if(strcmp(input[0].data.string_val,"-1")){ - if(strcmp(input[0].data.string_val,"-1")){ + struct sockaddr_in sa; + // store this IP address in sa: + inet_pton(AF_INET, input[0].data.string_val, &(sa.sin_addr)); + route.family=AF_INET; + route.face.hicn.local_addr.v4.as_inaddr=sa.sin_addr; - struct sockaddr_in sa; - // store this IP address in sa: - inet_pton(AF_INET, input[0].data.string_val, &(sa.sin_addr)); - route.family=AF_INET; - route.face.hicn.local_addr.v4.as_inaddr=sa.sin_addr; + }else if(strcmp(input[1].data.string_val,"-1")){ - }else if(strcmp(input[1].data.string_val,"-1")){ + struct in6_addr *dst = malloc(sizeof(struct in6_addr)); + inet_pton(AF_INET6, input[1].data.string_val, dst); + face.face.hicn.family=AF_INET6; + face.face.hicn.local_addr.v6.as_in6addr = *dst; - struct in6_addr *dst = malloc(sizeof(struct in6_addr)); - inet_pton(AF_INET6, input[1].data.string_val, dst); - face.face.hicn.family=AF_INET6; - face.face.hicn.local_addr.v6.as_in6addr = *dst; - - }else{ - SRP_LOG_DBG_MSG("Invalid local IP address"); - return SR_ERR_OPERATION_FAILED; - } + }else{ + SRP_LOG_DBG_MSG("Invalid local IP address"); + return SR_ERR_OPERATION_FAILED; + } -hc_route_create(hsocket, route); -*/ - return SR_ERR_OK; + hc_route_create(hsocket, route); + */ + return SR_ERR_OK; } - - int hicn_subscribe_events(sr_session_ctx_t *session, sr_subscription_ctx_t **subscription) { - - int rc; - rc = sr_rpc_subscribe(session, "/hicn:face-ip-add", hicn_face_ip_add_cb, - session, 100,SR_SUBSCR_CTX_REUSE, subscription); - if (rc != SR_ERR_OK) { - SRP_LOG_DBGMSG("Problem in subscription stat-get\n"); - goto error; - } - - - rc = sr_rpc_subscribe(session, "/hicn:face-ip-del", hicn_face_ip_del_cb, - session, 100,SR_SUBSCR_CTX_REUSE, subscription); - if (rc != SR_ERR_OK) { - SRP_LOG_DBGMSG("Problem in subscription face-ip-del\n"); - goto error; - } - + rc = sr_rpc_subscribe(session, "/hicn:face-ip-add", hicn_face_ip_add_cb, + session, 100, SR_SUBSCR_CTX_REUSE, subscription); + if (rc != SR_ERR_OK) { + SRP_LOG_DBGMSG("Problem in subscription stat-get\n"); + goto error; + } - rc = sr_rpc_subscribe(session, "/hicn:route-nhops-add", - hicn_route_add_cb, session, 100,SR_SUBSCR_CTX_REUSE, subscription); - if (rc!= SR_ERR_OK) { - SRP_LOG_DBGMSG("Problem in subscription route-nhops-add\n"); - goto error; - } + rc = sr_rpc_subscribe(session, "/hicn:face-ip-del", hicn_face_ip_del_cb, + session, 100, SR_SUBSCR_CTX_REUSE, subscription); + if (rc != SR_ERR_OK) { + SRP_LOG_DBGMSG("Problem in subscription face-ip-del\n"); + goto error; + } + rc = sr_rpc_subscribe(session, "/hicn:route-nhops-add", hicn_route_add_cb, + session, 100, SR_SUBSCR_CTX_REUSE, subscription); + if (rc != SR_ERR_OK) { + SRP_LOG_DBGMSG("Problem in subscription route-nhops-add\n"); + goto error; + } SRP_LOG_DBGMSG("hicn light initialized successfully."); return SR_ERR_OK; @@ -191,5 +178,4 @@ error: SRP_LOG_ERRMSG("Error by initialization of the hicn plugin."); sr_plugin_cleanup_cb(session, hsocket); return rc; - } diff --git a/ctrl/sysrepo-plugins/hicn-light/plugin/model/hicn_model.h b/ctrl/sysrepo-plugins/hicn-light/plugin/model/hicn_model.h index e6e857bff..be70bc711 100644 --- a/ctrl/sysrepo-plugins/hicn-light/plugin/model/hicn_model.h +++ b/ctrl/sysrepo-plugins/hicn-light/plugin/model/hicn_model.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Cisco and/or its affiliates. + * Copyright (c) 2021 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: @@ -18,7 +18,6 @@ #include "../hicn_light_comm.h" - #define MEM_ALIGN 4096 // Number of locks is equal to number of nodes in hicn-state @@ -27,8 +26,7 @@ #define NLOCKS 5 #define LOCK_INIT 0 - -enum locks_name {lstate, lstrategy, lstrategies, lroute, lface_ip_params}; +enum locks_name { lstate, lstrategy, lstrategies, lroute, lface_ip_params }; #define NSTATE_LEAVES 15 #define NSTRATEGY_LEAVES 1 diff --git a/ctrl/sysrepo-plugins/hicn-light/plugin/model/tlock.c b/ctrl/sysrepo-plugins/hicn-light/plugin/model/tlock.c index 2f7b11efa..ba788d3a0 100644 --- a/ctrl/sysrepo-plugins/hicn-light/plugin/model/tlock.c +++ b/ctrl/sysrepo-plugins/hicn-light/plugin/model/tlock.c @@ -1,21 +1,16 @@ -#include"tlock.h" +#include "tlock.h" - -void Ticket_init ( int Lock_Number , long int init ){ - -__atomic_store( &En[Lock_Number] , &init , __ATOMIC_SEQ_CST ); -__atomic_store( &De[Lock_Number] , &init , __ATOMIC_SEQ_CST ); -//En[Lock_Number]=init; -//De[Lock_Number]=init; +void Ticket_init(int Lock_Number, long int init) { + __atomic_store(&En[Lock_Number], &init, __ATOMIC_SEQ_CST); + __atomic_store(&De[Lock_Number], &init, __ATOMIC_SEQ_CST); + // En[Lock_Number]=init; + // De[Lock_Number]=init; } -void Ticket_Lock(int Lock_Number ){ - - int my_ticket = __sync_fetch_and_add(&En[Lock_Number] , 1 ); - while ( my_ticket != De[ Lock_Number ] ) {}; - +void Ticket_Lock(int Lock_Number) { + int my_ticket = __sync_fetch_and_add(&En[Lock_Number], 1); + while (my_ticket != De[Lock_Number]) { + }; } -void Ticket_Unlock(int Lock_Number ){ -De[Lock_Number]++; -} +void Ticket_Unlock(int Lock_Number) { De[Lock_Number]++; } diff --git a/ctrl/sysrepo-plugins/hicn-light/plugin/model/tlock.h b/ctrl/sysrepo-plugins/hicn-light/plugin/model/tlock.h index 36698115a..6840be1c0 100644 --- a/ctrl/sysrepo-plugins/hicn-light/plugin/model/tlock.h +++ b/ctrl/sysrepo-plugins/hicn-light/plugin/model/tlock.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Cisco and/or its affiliates. + * Copyright (c) 2021 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: @@ -13,19 +13,17 @@ * limitations under the License. */ - #ifndef __TLOCK_H__ #define __TLOCK_H__ +// limit on the number of locks: it shoud be matched with the number of +// hicn-state leaves +#define MAX_LOCK_SIZE 5 -// limit on the number of locks: it shoud be matched with the number of hicn-state leaves -#define MAX_LOCK_SIZE 5 - -volatile long int En[MAX_LOCK_SIZE] , De[MAX_LOCK_SIZE] ; // For Ticket Algorithm - +volatile long int En[MAX_LOCK_SIZE], De[MAX_LOCK_SIZE]; // For Ticket Algorithm -void Ticket_init ( int Lock_Number , long int init ); -void Ticket_Lock(int Lock_Number ); -void Ticket_Unlock(int Lock_Number ); +void Ticket_init(int Lock_Number, long int init); +void Ticket_Lock(int Lock_Number); +void Ticket_Unlock(int Lock_Number); #endif /* __IETF_HICN_H__ */
\ No newline at end of file |