diff options
author | Masoud Hemmatpour <mhemmatp@cisco.com> | 2019-04-04 13:34:04 +0200 |
---|---|---|
committer | Mauro Sardara <msardara@cisco.com> | 2019-05-03 08:54:29 +0000 |
commit | e9a02cb3a565daab16e295c551dff80501f94974 (patch) | |
tree | 891701aac1b440c4e74c31f485dad667bfab3924 /utils/sysrepo-plugins/hicn-light/plugin/model | |
parent | 305e7617be61d21ebd0dee043588c469bc28ad3b (diff) |
[HICN-153] vapi definition warning
Change-Id: I50f381540e171fe2808d4e56cc24ba6d66e8a2ab
Signed-off-by: Masoud Hemmatpour <mhemmatp@cisco.com>
Diffstat (limited to 'utils/sysrepo-plugins/hicn-light/plugin/model')
-rw-r--r-- | utils/sysrepo-plugins/hicn-light/plugin/model/hicn_model.c | 175 | ||||
-rw-r--r-- | utils/sysrepo-plugins/hicn-light/plugin/model/hicn_model.h | 2 |
2 files changed, 174 insertions, 3 deletions
diff --git a/utils/sysrepo-plugins/hicn-light/plugin/model/hicn_model.c b/utils/sysrepo-plugins/hicn-light/plugin/model/hicn_model.c index 0c34325d6..7cfb8363a 100644 --- a/utils/sysrepo-plugins/hicn-light/plugin/model/hicn_model.c +++ b/utils/sysrepo-plugins/hicn-light/plugin/model/hicn_model.c @@ -21,13 +21,186 @@ #include "hicn_model.h" #include "tlock.h" #include "../hicn_light.h" +#include "../hicn_light_comm.h" + + + +/** + * @brief API to add hicn face ip in hicn-light. + */ +static int hicn_face_ip_add_cb(const char *xpath, const sr_val_t *input, + const size_t input_cnt, sr_val_t **output, + size_t *output_cnt, void *private_ctx) { + + SRP_LOG_DBG_MSG("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.hicn.family=AF_INET; + face.face.hicn.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.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; + } + + 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.hicn.family=AF_INET; + face.face.hicn.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.hicn.family=AF_INET6; + face.face.hicn.remote_addr.v6.as_in6addr = *dst; + + }else{ + SRP_LOG_DBG_MSG("Invalid local IP address"); + return SR_ERR_OPERATION_FAILED; + } + + + // strncpy(face.face.hicn.netdevice.name,"ens39"); // Can we work only with Idx number ? + face.face.hicn.netdevice.index = input[4].data.uint32_val; // This is the idx number of interface + + + face.id=0;//can be empty + face.face.tags=0;//can be empty + strcpy(face.name,"hicn_face"); + face.face.type=1; + + int rc; + rc = hc_face_create(hsocket, &face); + if (rc > 0) { + SRP_LOG_DBG_MSG("Face added successfully"); + return SR_ERR_OK; + } + + SRP_LOG_DBG_MSG("Operation Failed"); + return SR_ERR_OPERATION_FAILED; +} + +/** + * @brief API to del hicn face ip in vpp. + */ +static int hicn_face_ip_del_cb(const char *xpath, const sr_val_t *input, + const size_t input_cnt, sr_val_t **output, + size_t *output_cnt, void *private_ctx) { + + SRP_LOG_DBG_MSG("hicn face ip del received successfully"); + face_t * face=NULL; + + // msg->payload.faceid = input[0].data.uint16_val; + //lookup(face); + face_free(face); + + // if(!resp->payload.retval){ + // SRP_LOG_DBG_MSG("Successfully Done"); + // return SR_ERR_OK; + // } + + SRP_LOG_DBG_MSG("Operation Failed"); + return SR_ERR_OPERATION_FAILED; + +} + + +/** + * @brief API to del hicn face ip in vpp. + */ +static int hicn_route_add_cb(const char *xpath, const sr_val_t *input, + const size_t input_cnt, sr_val_t **output, + size_t *output_cnt, void *private_ctx) { + +/* + + SRP_LOG_DBG_MSG("hicn route add received successfully"); + + hc_route_t * route; + + 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; + + + }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; + + }else{ + SRP_LOG_DBG_MSG("Invalid local IP address"); + return SR_ERR_OPERATION_FAILED; + } + + +hc_route_create(hsocket, route); +*/ + return SR_ERR_OK; +} int hicn_subscribe_events(sr_session_ctx_t *session, sr_subscription_ctx_t **subscription) { - SRP_LOG_INF_MSG("hicn light plugin initialized successfully."); + + int rc; + rc = sr_rpc_subscribe(session, "/hicn:face-ip-add", hicn_face_ip_add_cb, + session, SR_SUBSCR_CTX_REUSE, subscription); + if (rc != SR_ERR_OK) { + SRP_LOG_DBG_MSG("Problem in subscription stat-get\n"); + goto error; + } + + + rc = sr_rpc_subscribe(session, "/hicn:face-ip-del", hicn_face_ip_del_cb, + session, SR_SUBSCR_CTX_REUSE, subscription); + if (rc != SR_ERR_OK) { + SRP_LOG_DBG_MSG("Problem in subscription face-ip-del\n"); + goto error; + } + + + rc = sr_rpc_subscribe(session, "/hicn:route-nhops-add", + hicn_route_add_cb, session, SR_SUBSCR_CTX_REUSE, subscription); + if (rc!= SR_ERR_OK) { + SRP_LOG_DBG_MSG("Problem in subscription route-nhops-add\n"); + goto error; + } + + + SRP_LOG_INF_MSG("hicn light initialized successfully."); return SR_ERR_OK; +error: + SRP_LOG_ERR_MSG("Error by initialization of the hicn plugin."); + sr_plugin_cleanup_cb(session, hsocket); + return rc; + }
\ No newline at end of file diff --git a/utils/sysrepo-plugins/hicn-light/plugin/model/hicn_model.h b/utils/sysrepo-plugins/hicn-light/plugin/model/hicn_model.h index 59befe68c..e6e857bff 100644 --- a/utils/sysrepo-plugins/hicn-light/plugin/model/hicn_model.h +++ b/utils/sysrepo-plugins/hicn-light/plugin/model/hicn_model.h @@ -36,8 +36,6 @@ enum locks_name {lstate, lstrategy, lstrategies, lroute, lface_ip_params}; #define NROUTE_LEAVES 2 #define NFACE_IP_PARAMS_LEAVES 3 - - int hicn_subscribe_events(sr_session_ctx_t *session, sr_subscription_ctx_t **subscription); |