diff options
author | Luca Muscariello <lumuscar@cisco.com> | 2022-03-30 22:29:28 +0200 |
---|---|---|
committer | Mauro Sardara <msardara@cisco.com> | 2022-03-31 19:51:47 +0200 |
commit | c46e5df56b67bb8ea7a068d39324c640084ead2b (patch) | |
tree | eddeb17785938e09bc42eec98ee09b8a28846de6 /ctrl/sysrepo-plugins | |
parent | 18fa668f25d3cc5463417ce7df6637e31578e898 (diff) |
feat: boostrap hicn 22.02
The current patch provides several new features, improvements,
bug fixes and also complete rewrite of entire components.
- lib
The hicn packet parser has been improved with a new packet
format fully based on UDP. The TCP header is still temporarily
supported but the UDP header will replace completely the new hicn
packet format. Improvements have been made to make sure every
packet parsing operation is made via this library. The current
new header can be used as header between the payload and the
UDP header or as trailer in the UDP surplus area to be tested
when UDP options will start to be used.
- hicn-light
The portable packet forwarder has been completely rewritten from
scratch with the twofold objective to improve performance and
code size but also to drop dependencies such as libparc which is
now removed by the current implementation.
- hicn control
the control library is the agent that is used to program the
packet forwarders via their binary API. This component has
benefited from significant improvements in terms of interaction
model which is now event driven and more robust to failures.
- VPP plugin has been updated to support VPP 22.02
- transport
Major improvement have been made to the RTC protocol, to the
support of IO modules and to the security sub system. Signed
manifests are the default data authenticity and integrity framework.
Confidentiality can be enabled by sharing the encryption key to the
prod/cons layer. The library has been tested with group key based
applications such as broadcast/multicast and real-time on-line
meetings with trusted server keys or MLS.
- testing
Unit testing has been introduced using GoogleTest. One third of
the code base is covered by unit testing with priority on
critical features. Functional testing has also been introduce
using Docker, linux bridging and Robot Framework to define
test with Less Code techniques to facilitate the extension
of the coverage.
Co-authored-by: Mauro Sardara <msardara@cisco.com>
Co-authored-by: Jordan Augé <jordan.auge+fdio@cisco.com>
Co-authored-by: Michele Papalini <micpapal@cisco.com>
Co-authored-by: Angelo Mantellini <manangel@cisco.com>
Co-authored-by: Jacques Samain <jsamain@cisco.com>
Co-authored-by: Olivier Roques <oroques+fdio@cisco.com>
Co-authored-by: Enrico Loparco <eloparco@cisco.com>
Co-authored-by: Giulio Grassi <gigrassi@cisco.com>
Change-Id: I75d0ef70f86d921e3ef503c99271216ff583c215
Signed-off-by: Luca Muscariello <muscariello@ieee.org>
Signed-off-by: Mauro Sardara <msardara@cisco.com>
Diffstat (limited to 'ctrl/sysrepo-plugins')
25 files changed, 824 insertions, 900 deletions
diff --git a/ctrl/sysrepo-plugins/CMakeLists.txt b/ctrl/sysrepo-plugins/CMakeLists.txt index 2412d5688..0765f75d8 100644 --- a/ctrl/sysrepo-plugins/CMakeLists.txt +++ b/ctrl/sysrepo-plugins/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 Cisco and/or its affiliates. +# Copyright (c) 2021-2022 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: @@ -41,13 +41,13 @@ if (NOT SRPD_PLUGINS_PATH) message(FATAL_ERROR "Cannot get sysrepo plugins directory due to missing pkg-config, set SRPD_PLUGINS_PATH manually.") endif() -find_package(Vpp REQUIRED) +find_package(Vpp ${VPP_DEFAULT_VERSION} REQUIRED) if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) - find_package(HicnPlugin REQUIRED) + find_package(HicnPlugin ${CURRENT_VERSION} REQUIRED) else() list(APPEND DEPENDENCIES - hicn_plugin + ${HICNPLUGIN_SHARED} ) endif() diff --git a/ctrl/sysrepo-plugins/cmake/Modules/Packaging.cmake b/ctrl/sysrepo-plugins/cmake/Modules/Packaging.cmake index 323c9d01a..cba9adf1f 100644 --- a/ctrl/sysrepo-plugins/cmake/Modules/Packaging.cmake +++ b/ctrl/sysrepo-plugins/cmake/Modules/Packaging.cmake @@ -1,4 +1,4 @@ -# Copyright (c) 2017-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: @@ -15,17 +15,22 @@ # Packages section ###################### +############################################################## +# Get VPP version +############################################################## +list(GET VPP_DEFAULT_VERSION 0 VPP_VERSION) + set(hicn-sysrepo-plugin_DESCRIPTION "A Plugin to enable hICN VPP in sysrepo." CACHE STRING "Description for deb/rpm package." ) set(hicn-sysrepo-plugin_DEB_DEPENDENCIES - "hicn-plugin (>= stable_version-release), sysrepo (>= 1.0)" + "hicn-plugin (= ${VPP_VERSION}-release), sysrepo (>= 1.0)" CACHE STRING "Dependencies for deb/rpm package." ) set(hicn-sysrepo-plugin_RPM_DEPENDENCIES - "hicn-plugin >= stable_version-release, sysrepo >= 1.0" + "hicn-plugin = ${VPP_VERSION}-release, sysrepo >= 1.0" CACHE STRING "Dependencies for deb/rpm package." ) diff --git a/ctrl/sysrepo-plugins/hicn-light/CMakeLists.txt b/ctrl/sysrepo-plugins/hicn-light/CMakeLists.txt index 5ba7045c1..f8a1e64aa 100644 --- a/ctrl/sysrepo-plugins/hicn-light/CMakeLists.txt +++ b/ctrl/sysrepo-plugins/hicn-light/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/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 diff --git a/ctrl/sysrepo-plugins/hicn-plugin/CMakeLists.txt b/ctrl/sysrepo-plugins/hicn-plugin/CMakeLists.txt index 10e106f51..9204e2766 100644 --- a/ctrl/sysrepo-plugins/hicn-plugin/CMakeLists.txt +++ b/ctrl/sysrepo-plugins/hicn-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-plugin/plugin/hicn_plugin.c b/ctrl/sysrepo-plugins/hicn-plugin/plugin/hicn_plugin.c index bbcc2e9bf..fe2e6350f 100644 --- a/ctrl/sysrepo-plugins/hicn-plugin/plugin/hicn_plugin.c +++ b/ctrl/sysrepo-plugins/hicn-plugin/plugin/hicn_plugin.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2020 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,12 +22,10 @@ #include "model/hicn_model.h" #include "ietf/ietf_interface.h" - sr_subscription_ctx_t *subscription = NULL; volatile int exit_application = 0; int sr_plugin_init_cb(sr_session_ctx_t *session, void **private_ctx) { - sr_subscription_ctx_t *subscription = NULL; int rc = SR_ERR_OK; rc = hicn_connect_vpp(); @@ -38,11 +36,10 @@ int sr_plugin_init_cb(sr_session_ctx_t *session, void **private_ctx) { // HICN subscribe hicn_subscribe_events(session, &subscription); - //sr_subscription_ctx_t *subscription2 = NULL; + // sr_subscription_ctx_t *subscription2 = NULL; // IETF subscribe - //ietf_subscribe_events(session, &subscription2); - + // ietf_subscribe_events(session, &subscription2); /* set subscription as our private context */ *private_ctx = subscription; @@ -51,7 +48,6 @@ int sr_plugin_init_cb(sr_session_ctx_t *session, void **private_ctx) { } void sr_plugin_cleanup_cb(sr_session_ctx_t *session, void *private_ctx) { - /* subscription was set as our private context */ sr_unsubscribe(private_ctx); hicn_disconnect_vpp(); diff --git a/ctrl/sysrepo-plugins/hicn-plugin/plugin/hicn_plugin.h b/ctrl/sysrepo-plugins/hicn-plugin/plugin/hicn_plugin.h index 0890c3f03..15aea72d6 100644 --- a/ctrl/sysrepo-plugins/hicn-plugin/plugin/hicn_plugin.h +++ b/ctrl/sysrepo-plugins/hicn-plugin/plugin/hicn_plugin.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: @@ -23,7 +23,6 @@ #include "hicn_vpp_comm.h" - /** * @brief initialize function for sysrepo plugin, * In this function we connect to vpp from one side diff --git a/ctrl/sysrepo-plugins/hicn-plugin/plugin/hicn_vpp_comm.c b/ctrl/sysrepo-plugins/hicn-plugin/plugin/hicn_vpp_comm.c index 73eab66ea..41ab3d057 100644 --- a/ctrl/sysrepo-plugins/hicn-plugin/plugin/hicn_vpp_comm.c +++ b/ctrl/sysrepo-plugins/hicn-plugin/plugin/hicn_vpp_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: @@ -19,15 +19,9 @@ #define MAX_OUTSTANDING_REQUESTS 4 #define RESPONSE_QUEUE_SIZE 2 - -vapi_ctx_t g_vapi_ctx_instance=NULL; - - - - +vapi_ctx_t g_vapi_ctx_instance = NULL; int hicn_connect_vpp() { - if (g_vapi_ctx_instance == NULL) { vapi_error_e rv = vapi_ctx_alloc(&g_vapi_ctx_instance); rv = vapi_connect(g_vapi_ctx_instance, APP_NAME, NULL, diff --git a/ctrl/sysrepo-plugins/hicn-plugin/plugin/hicn_vpp_comm.h b/ctrl/sysrepo-plugins/hicn-plugin/plugin/hicn_vpp_comm.h index 9abe4e5d4..cb5eefcbe 100644 --- a/ctrl/sysrepo-plugins/hicn-plugin/plugin/hicn_vpp_comm.h +++ b/ctrl/sysrepo-plugins/hicn-plugin/plugin/hicn_vpp_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: @@ -13,13 +13,11 @@ * limitations under the License. */ - /** * @file hicn_vpp_comm.h * @brief This file contains binary api to connect to the VPP. */ - #ifndef __HICN_VPP_COMMM_H__ #define __HICN_VPP_COMMM_H__ #include <sysrepo.h> @@ -40,7 +38,6 @@ extern vapi_ctx_t g_vapi_ctx_instance; - /** * @brief This macro is interface.c to communicate with vpp */ @@ -48,36 +45,34 @@ extern vapi_ctx_t g_vapi_ctx_instance; #define VPP_MAC_ADDRESS_LEN 8 #define VPP_IP6_ADDRESS_LEN 16 - - /** - * @brief This macro checks the arg is NULL or not, if the arg is NULL it returns retval + * @brief This macro checks the arg is NULL or not, if the arg is NULL it + * returns retval */ -#define ARG_CHECK(retval, arg) \ - do { \ - if (NULL == (arg)) { \ - SRP_LOG_DBGMSG("NULL pointer passed."); \ - return (retval); \ - } \ +#define ARG_CHECK(retval, arg) \ + do { \ + if (NULL == (arg)) { \ + SRP_LOG_DBGMSG("NULL pointer passed."); \ + return (retval); \ + } \ } while (0) - /** * @brief Please check ARG_CHECK */ #define ARG_CHECK2(retval, arg1, arg2) \ - ARG_CHECK(retval, arg1); \ - ARG_CHECK(retval, arg2) + ARG_CHECK(retval, arg1); \ + ARG_CHECK(retval, arg2) /** * @brief This Macro is the multiple check of ARG_CHECK */ #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) /** * @brief This function is used to connect to the vpp diff --git a/ctrl/sysrepo-plugins/hicn-plugin/plugin/ietf/ietf_interface.c b/ctrl/sysrepo-plugins/hicn-plugin/plugin/ietf/ietf_interface.c index 3e0c90cf9..9a74e6280 100644 --- a/ctrl/sysrepo-plugins/hicn-plugin/plugin/ietf/ietf_interface.c +++ b/ctrl/sysrepo-plugins/hicn-plugin/plugin/ietf/ietf_interface.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2020 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: @@ -29,11 +29,9 @@ #include "ietf_interface.h" #include "../hicn_vpp_comm.h" - DEFINE_VAPI_MSG_IDS_INTERFACE_API_JSON; -typedef struct hicn_interface_ -{ +typedef struct hicn_interface_ { u32 sw_if_index; char interface_name[VPP_INTFC_NAME_LEN]; u8 l2_address[VPP_MAC_ADDRESS_LEN]; @@ -44,207 +42,202 @@ typedef struct hicn_interface_ u8 link_up_down; } hicnIntfc; -typedef struct _ietf_sw_interface_dump_ctx -{ +typedef struct _ietf_sw_interface_dump_ctx { u8 last_called; int num_ifs; int capacity; - hicnIntfc * intfcArray; + hicnIntfc *intfcArray; } ietf_sw_interface_dump_ctx; static i32 ietf_setInterfaceFlags(u32 sw_if_index, u8 admin_up_down); -static i32 ietf_interface_name2index(const char *name, u32* if_index); +static i32 ietf_interface_name2index(const char *name, u32 *if_index); static i32 ietf_interface_add_del_addr(u32 sw_if_index, u8 is_add, u8 is_ipv6, u8 del_all, u8 address_length, u8 address[VPP_IP6_ADDRESS_LEN]); -static int ietf_initSwInterfaceDumpCTX(ietf_sw_interface_dump_ctx * dctx); -static int ietf_freeSwInterfaceDumpCTX(ietf_sw_interface_dump_ctx * dctx); +static int ietf_initSwInterfaceDumpCTX(ietf_sw_interface_dump_ctx *dctx); +static int ietf_freeSwInterfaceDumpCTX(ietf_sw_interface_dump_ctx *dctx); /** * @brief Helper function for converting netmask into prefix length. */ -static uint8_t -netmask_to_prefix(const char *netmask) -{ - in_addr_t n = 0; - uint8_t i = 0; +static uint8_t netmask_to_prefix(const char *netmask) { + in_addr_t n = 0; + uint8_t i = 0; - inet_pton(AF_INET, netmask, &n); + inet_pton(AF_INET, netmask, &n); - while (n > 0) { - n = n >> 1; - i++; - } + while (n > 0) { + n = n >> 1; + i++; + } - return i; + return i; } /** - * @brief Helper function for converting IPv4/IPv6 address string into binary representation. + * @brief Helper function for converting IPv4/IPv6 address string into binary + * representation. */ -static int -ip_addr_str_to_binary(const char *ip_address_str, uint8_t *ip_address_bin, bool is_ipv6) -{ - struct in6_addr addr6 = { 0, }; - struct in_addr addr4 = { 0, }; - int ret = 0; - - if (is_ipv6) { - ret = inet_pton(AF_INET6, ip_address_str, &(addr6)); - if (1 == ret) - { - memcpy(ip_address_bin, &addr6, sizeof(addr6)); - } - } else { - ret = inet_pton(AF_INET, ip_address_str, &(addr4)); - if (1 == ret) - { - memcpy(ip_address_bin, &addr4, sizeof(addr4)); - } +static int ip_addr_str_to_binary(const char *ip_address_str, + uint8_t *ip_address_bin, bool is_ipv6) { + struct in6_addr addr6 = { + 0, + }; + struct in_addr addr4 = { + 0, + }; + int ret = 0; + + if (is_ipv6) { + ret = inet_pton(AF_INET6, ip_address_str, &(addr6)); + if (1 == ret) { + memcpy(ip_address_bin, &addr6, sizeof(addr6)); + } + } else { + ret = inet_pton(AF_INET, ip_address_str, &(addr4)); + if (1 == ret) { + memcpy(ip_address_bin, &addr4, sizeof(addr4)); } + } - return ret; + return ret; } /** * @brief Enable or disable given interface. */ -static int -interface_enable_disable(const char *if_name, bool enable) -{ - uint32_t if_index = ~0; - int rc = 0; - - - /* get interface index */ - rc = ietf_interface_name2index(if_name, &if_index); - if (0 != rc) { - SRP_LOG_ERRMSG("Invalid interface name"); - return SR_ERR_INVAL_ARG; - } +static int interface_enable_disable(const char *if_name, bool enable) { + uint32_t if_index = ~0; + int rc = 0; + + /* get interface index */ + rc = ietf_interface_name2index(if_name, &if_index); + if (0 != rc) { + SRP_LOG_ERRMSG("Invalid interface name"); + return SR_ERR_INVAL_ARG; + } - /* enable/disable interface */ - rc = ietf_setInterfaceFlags(if_index, (uint8_t)enable); - if (0 != rc) { - SRP_LOG_ERRMSG("Error by processing of the sw_interface_set_flags request"); - return SR_ERR_OPERATION_FAILED; - } else { - return SR_ERR_OK; - } + /* enable/disable interface */ + rc = ietf_setInterfaceFlags(if_index, (uint8_t)enable); + if (0 != rc) { + SRP_LOG_ERRMSG("Error by processing of the sw_interface_set_flags request"); + return SR_ERR_OPERATION_FAILED; + } else { + return SR_ERR_OK; + } } - -vapi_error_e call_sw_interface_add_del_address(struct vapi_ctx_s *ctx, - void *callback_ctx, - vapi_error_e rv, - bool is_last, - vapi_payload_sw_interface_add_del_address_reply *reply){ -if(!reply->retval){ - SRP_LOG_DBGMSG("Successfully done"); - return VAPI_OK; - }else - return VAPI_EUSER; +vapi_error_e call_sw_interface_add_del_address( + struct vapi_ctx_s *ctx, void *callback_ctx, vapi_error_e rv, bool is_last, + vapi_payload_sw_interface_add_del_address_reply *reply) { + if (!reply->retval) { + SRP_LOG_DBGMSG("Successfully done"); + return VAPI_OK; + } else + return VAPI_EUSER; } -vapi_error_e call_sw_interface_set_flags(struct vapi_ctx_s *ctx, - void *callback_ctx, - vapi_error_e rv, - bool is_last, - vapi_payload_sw_interface_set_flags_reply *reply){ -if(!reply->retval){ - SRP_LOG_DBGMSG("Successfully done"); - return VAPI_OK; - }else - return VAPI_EUSER; +vapi_error_e call_sw_interface_set_flags( + struct vapi_ctx_s *ctx, void *callback_ctx, vapi_error_e rv, bool is_last, + vapi_payload_sw_interface_set_flags_reply *reply) { + if (!reply->retval) { + SRP_LOG_DBGMSG("Successfully done"); + return VAPI_OK; + } else + return VAPI_EUSER; } - - /** - * @brief Callback to be called by any config change of "/ietf-interfaces:interfaces/interface/enabled" leaf. + * @brief Callback to be called by any config change of + * "/ietf-interfaces:interfaces/interface/enabled" leaf. */ -static int -ietf_interface_enable_disable_cb(sr_session_ctx_t *session, const char *module_name, const char *xpath, sr_event_t event, - uint32_t request_id, void *private_data) -{ - char *if_name = NULL; - sr_change_iter_t *iter = NULL; - sr_change_oper_t op = SR_OP_CREATED; - sr_val_t *old_val = NULL; - sr_val_t *new_val = NULL; - sr_xpath_ctx_t xpath_ctx = { 0, }; - int rc = SR_ERR_OK, op_rc = SR_ERR_OK; - - /* no-op for apply, we only care about SR_EV_ENABLED, SR_EV_VERIFY, SR_EV_ABORT */ - if (SR_EV_DONE == event) { - return SR_ERR_OK; - } +static int ietf_interface_enable_disable_cb(sr_session_ctx_t *session, + const char *module_name, + const char *xpath, sr_event_t event, + uint32_t request_id, + void *private_data) { + char *if_name = NULL; + sr_change_iter_t *iter = NULL; + sr_change_oper_t op = SR_OP_CREATED; + sr_val_t *old_val = NULL; + sr_val_t *new_val = NULL; + sr_xpath_ctx_t xpath_ctx = { + 0, + }; + int rc = SR_ERR_OK, op_rc = SR_ERR_OK; + + /* no-op for apply, we only care about SR_EV_ENABLED, SR_EV_VERIFY, + * SR_EV_ABORT */ + if (SR_EV_DONE == event) { + return SR_ERR_OK; + } - /* get changes iterator */ - rc = sr_get_changes_iter(session, xpath, &iter); - if (SR_ERR_OK != rc) { - SRP_LOG_ERRMSG("Unable to retrieve change iterator"); - return rc; - } + /* get changes iterator */ + rc = sr_get_changes_iter(session, xpath, &iter); + if (SR_ERR_OK != rc) { + SRP_LOG_ERRMSG("Unable to retrieve change iterator"); + return rc; + } - /* iterate over all changes */ - while ((SR_ERR_OK == op_rc || event == SR_EV_ABORT) && - (SR_ERR_OK == (rc = sr_get_change_next(session, iter, &op, &old_val, &new_val)))) { - - SRP_LOG_DBGMSG("A change detected"); - if_name = sr_xpath_key_value(new_val ? new_val->xpath : old_val->xpath, "interface", "name", &xpath_ctx); - switch (op) { - case SR_OP_CREATED: - case SR_OP_MODIFIED: - op_rc = interface_enable_disable(if_name, new_val->data.bool_val); - break; - case SR_OP_DELETED: - op_rc = interface_enable_disable(if_name, false /* !enable */); - break; - default: - break; - } - sr_xpath_recover(&xpath_ctx); - if (SR_ERR_INVAL_ARG == op_rc) { - sr_set_error(session, "Invalid interface name.", new_val ? new_val->xpath : old_val->xpath); - } - sr_free_val(old_val); - sr_free_val(new_val); + /* iterate over all changes */ + while ((SR_ERR_OK == op_rc || event == SR_EV_ABORT) && + (SR_ERR_OK == + (rc = sr_get_change_next(session, iter, &op, &old_val, &new_val)))) { + SRP_LOG_DBGMSG("A change detected"); + if_name = sr_xpath_key_value(new_val ? new_val->xpath : old_val->xpath, + "interface", "name", &xpath_ctx); + switch (op) { + case SR_OP_CREATED: + case SR_OP_MODIFIED: + op_rc = interface_enable_disable(if_name, new_val->data.bool_val); + break; + case SR_OP_DELETED: + op_rc = interface_enable_disable(if_name, false /* !enable */); + break; + default: + break; } - sr_free_change_iter(iter); + sr_xpath_recover(&xpath_ctx); + if (SR_ERR_INVAL_ARG == op_rc) { + sr_set_error(session, "Invalid interface name.", + new_val ? new_val->xpath : old_val->xpath); + } + sr_free_val(old_val); + sr_free_val(new_val); + } + sr_free_change_iter(iter); - return op_rc; + return op_rc; } /** * @brief Add or remove IPv4/IPv6 address to/from an interface. */ -static int -interface_ipv46_config_add_remove(const char *if_name, uint8_t *addr, uint8_t prefix, bool is_ipv6, bool add) -{ - uint32_t if_index = ~0; - int rc = 0; - - /* get interface index */ - rc = ietf_interface_name2index(if_name, &if_index); - if (0 != rc) { - SRP_LOG_ERRMSG("Invalid interface name"); - return SR_ERR_INVAL_ARG; - } +static int interface_ipv46_config_add_remove(const char *if_name, uint8_t *addr, + uint8_t prefix, bool is_ipv6, + bool add) { + uint32_t if_index = ~0; + int rc = 0; + + /* get interface index */ + rc = ietf_interface_name2index(if_name, &if_index); + if (0 != rc) { + SRP_LOG_ERRMSG("Invalid interface name"); + return SR_ERR_INVAL_ARG; + } - /* add del addr */ - rc = ietf_interface_add_del_addr(if_index, (uint8_t)add, (uint8_t)is_ipv6, 0, prefix, addr); - if (0 != rc) { - SRP_LOG_ERRMSG("Error by processing of the sw_interface_set_flags request"); - return SR_ERR_OPERATION_FAILED; - } else { - return SR_ERR_OK; - } + /* add del addr */ + rc = ietf_interface_add_del_addr(if_index, (uint8_t)add, (uint8_t)is_ipv6, 0, + prefix, addr); + if (0 != rc) { + SRP_LOG_ERRMSG("Error by processing of the sw_interface_set_flags request"); + return SR_ERR_OPERATION_FAILED; + } else { + return SR_ERR_OK; + } } -int ietf_initSwInterfaceDumpCTX(ietf_sw_interface_dump_ctx * dctx) -{ - if(dctx == NULL) - return -1; +int ietf_initSwInterfaceDumpCTX(ietf_sw_interface_dump_ctx *dctx) { + if (dctx == NULL) return -1; dctx->intfcArray = NULL; dctx->last_called = false; @@ -252,66 +245,56 @@ int ietf_initSwInterfaceDumpCTX(ietf_sw_interface_dump_ctx * dctx) dctx->num_ifs = 0; return 0; } -int ietf_freeSwInterfaceDumpCTX(ietf_sw_interface_dump_ctx * dctx) -{ - if(dctx == NULL) - return -1; - - if(dctx->intfcArray != NULL) - { - free(dctx->intfcArray); - } +int ietf_freeSwInterfaceDumpCTX(ietf_sw_interface_dump_ctx *dctx) { + if (dctx == NULL) return -1; + + if (dctx->intfcArray != NULL) { + free(dctx->intfcArray); + } return ietf_initSwInterfaceDumpCTX(dctx); } -vapi_error_e -ietf_sw_interface_dump_cb (struct vapi_ctx_s *ctx, void *callback_ctx, - vapi_error_e rv, bool is_last, - vapi_payload_sw_interface_details * reply) -{ +vapi_error_e ietf_sw_interface_dump_cb( + struct vapi_ctx_s *ctx, void *callback_ctx, vapi_error_e rv, bool is_last, + vapi_payload_sw_interface_details *reply) { ietf_sw_interface_dump_ctx *dctx = callback_ctx; - if (is_last) - { - dctx->last_called = true; + if (is_last) { + dctx->last_called = true; + } else { + if (dctx->capacity == 0 && dctx->intfcArray == NULL) { + dctx->capacity = 10; + dctx->intfcArray = + (hicnIntfc *)malloc(sizeof(hicnIntfc) * dctx->capacity); + } + if (dctx->num_ifs >= dctx->capacity - 1) { + dctx->capacity += 10; + dctx->intfcArray = (hicnIntfc *)realloc( + dctx->intfcArray, sizeof(hicnIntfc) * dctx->capacity); } - else - { - if(dctx->capacity == 0 && dctx->intfcArray == NULL) - { - dctx->capacity = 10; - dctx->intfcArray = (hicnIntfc*)malloc( sizeof(hicnIntfc)*dctx->capacity ); - } - if(dctx->num_ifs >= dctx->capacity-1) - { - - dctx->capacity += 10; - dctx->intfcArray = (hicnIntfc*)realloc(dctx->intfcArray, sizeof(hicnIntfc)*dctx->capacity ); - } - hicnIntfc * thisIntfc = &dctx->intfcArray[dctx->num_ifs]; + hicnIntfc *thisIntfc = &dctx->intfcArray[dctx->num_ifs]; - thisIntfc->sw_if_index = reply->sw_if_index; - memcpy(thisIntfc->interface_name, reply->interface_name, VPP_INTFC_NAME_LEN); - memcpy(thisIntfc->l2_address, reply->l2_address, VPP_MAC_ADDRESS_LEN ); - //thisIntfc->link_speed = reply->link_speed; + thisIntfc->sw_if_index = reply->sw_if_index; + memcpy(thisIntfc->interface_name, reply->interface_name, + VPP_INTFC_NAME_LEN); + memcpy(thisIntfc->l2_address, reply->l2_address, VPP_MAC_ADDRESS_LEN); + // thisIntfc->link_speed = reply->link_speed; #define ONE_MEGABIT (uint64_t)1000000 - switch (reply->link_speed << VNET_HW_INTERFACE_FLAG_SPEED_SHIFT) - { - default: - thisIntfc->link_speed = 0; - break; - } + switch (reply->link_speed << VNET_HW_INTERFACE_FLAG_SPEED_SHIFT) { + default: + thisIntfc->link_speed = 0; + break; + } - thisIntfc->link_mtu = reply->link_mtu; - thisIntfc->flags = reply->flags; + thisIntfc->link_mtu = reply->link_mtu; + thisIntfc->flags = reply->flags; - dctx->num_ifs += 1; - } + dctx->num_ifs += 1; + } return VAPI_OK; } -static i32 ietf_interface_name2index(const char *name, u32* if_index) -{ +static i32 ietf_interface_name2index(const char *name, u32 *if_index) { ARG_CHECK2(-1, name, if_index); i32 ret = -1; @@ -324,14 +307,14 @@ static i32 ietf_interface_name2index(const char *name, u32* if_index) dump->payload.name_filter_valid = true; memcpy(&dump->payload.name_filter, name, sizeof(dump->payload.name_filter)); - while (VAPI_EAGAIN == (rv = vapi_sw_interface_dump(g_vapi_ctx_instance, dump, ietf_sw_interface_dump_cb, &dctx))) + while (VAPI_EAGAIN == + (rv = vapi_sw_interface_dump(g_vapi_ctx_instance, dump, + ietf_sw_interface_dump_cb, &dctx))) ; int i = 0; - for (; i < dctx.num_ifs; ++i) - { - if (strcmp(dctx.intfcArray[i].interface_name, name) == 0) - { + for (; i < dctx.num_ifs; ++i) { + if (strcmp(dctx.intfcArray[i].interface_name, name) == 0) { *if_index = dctx.intfcArray[i].sw_if_index; ret = 0; break; @@ -342,11 +325,12 @@ static i32 ietf_interface_name2index(const char *name, u32* if_index) return ret; } -i32 ietf_interface_add_del_addr( u32 sw_if_index, u8 is_add, u8 is_ipv6, u8 del_all, - u8 address_length, u8 address[VPP_IP6_ADDRESS_LEN] ) -{ +i32 ietf_interface_add_del_addr(u32 sw_if_index, u8 is_add, u8 is_ipv6, + u8 del_all, u8 address_length, + u8 address[VPP_IP6_ADDRESS_LEN]) { i32 ret = -1; - vapi_msg_sw_interface_add_del_address *msg = vapi_alloc_sw_interface_add_del_address(g_vapi_ctx_instance); + vapi_msg_sw_interface_add_del_address *msg = + vapi_alloc_sw_interface_add_del_address(g_vapi_ctx_instance); msg->payload.sw_if_index = sw_if_index; msg->payload.is_add = is_add; msg->payload.prefix.address.af = is_ipv6 ? ADDRESS_IP6 : ADDRESS_IP4; @@ -354,7 +338,9 @@ i32 ietf_interface_add_del_addr( u32 sw_if_index, u8 is_add, u8 is_ipv6, u8 del_ msg->payload.prefix.len = address_length; memcpy(msg->payload.prefix.address.un.ip6, address, VPP_IP6_ADDRESS_LEN); - if(vapi_sw_interface_add_del_address(g_vapi_ctx_instance,msg,call_sw_interface_add_del_address,NULL)!=VAPI_OK){ + if (vapi_sw_interface_add_del_address(g_vapi_ctx_instance, msg, + call_sw_interface_add_del_address, + NULL) != VAPI_OK) { SRP_LOG_DBGMSG("Operation failed"); return SR_ERR_OPERATION_FAILED; } @@ -362,246 +348,274 @@ i32 ietf_interface_add_del_addr( u32 sw_if_index, u8 is_add, u8 is_ipv6, u8 del_ return ret; } -i32 ietf_setInterfaceFlags(u32 sw_if_index, u8 admin_up_down) -{ +i32 ietf_setInterfaceFlags(u32 sw_if_index, u8 admin_up_down) { i32 ret = -1; - vapi_msg_sw_interface_set_flags *msg = vapi_alloc_sw_interface_set_flags(g_vapi_ctx_instance); + vapi_msg_sw_interface_set_flags *msg = + vapi_alloc_sw_interface_set_flags(g_vapi_ctx_instance); msg->payload.sw_if_index = sw_if_index; - msg->payload.flags = admin_up_down? IF_STATUS_API_FLAG_ADMIN_UP : 0; + msg->payload.flags = admin_up_down ? IF_STATUS_API_FLAG_ADMIN_UP : 0; - if(vapi_sw_interface_set_flags(g_vapi_ctx_instance,msg,call_sw_interface_set_flags,NULL)!=VAPI_OK){ + if (vapi_sw_interface_set_flags(g_vapi_ctx_instance, msg, + call_sw_interface_set_flags, + NULL) != VAPI_OK) { SRP_LOG_DBGMSG("Operation failed"); return SR_ERR_OPERATION_FAILED; } - return ret; } - /** * @brief Modify existing IPv4/IPv6 config on an interface. */ -static int -interface_ipv46_config_modify(sr_session_ctx_t *session, const char *if_name, - sr_val_t *old_val, sr_val_t *new_val, bool is_ipv6) -{ - sr_xpath_ctx_t xpath_ctx = { 0, }; - char *addr_str = NULL; - uint8_t addr[16] = { 0, }; - uint8_t prefix = 0; - int rc = SR_ERR_OK; - - SRP_LOG_DBGMSG("Updating IP config on interface"); - - /* get old config to be deleted */ - if (SR_UINT8_T == old_val->type) { - prefix = old_val->data.uint8_val; - } else if (SR_STRING_T == old_val->type) { - prefix = netmask_to_prefix(old_val->data.string_val); - } else { - return SR_ERR_INVAL_ARG; - } - addr_str = sr_xpath_key_value((char*)old_val->xpath, "address", "ip", &xpath_ctx); - ip_addr_str_to_binary(addr_str, addr, is_ipv6); - sr_xpath_recover(&xpath_ctx); - - /* delete old IP config */ - rc = interface_ipv46_config_add_remove(if_name, addr, prefix, is_ipv6, false /* remove */); - if (SR_ERR_OK != rc) { - SRP_LOG_ERRMSG("Unable to remove old IP address config"); - return rc; - } - - /* update the config with the new value */ - if (sr_xpath_node_name_eq(new_val->xpath, "prefix-length")) { - prefix = new_val->data.uint8_val; - } else if (sr_xpath_node_name_eq(new_val->xpath, "netmask")) { - prefix = netmask_to_prefix(new_val->data.string_val); - } +static int interface_ipv46_config_modify(sr_session_ctx_t *session, + const char *if_name, sr_val_t *old_val, + sr_val_t *new_val, bool is_ipv6) { + sr_xpath_ctx_t xpath_ctx = { + 0, + }; + char *addr_str = NULL; + uint8_t addr[16] = { + 0, + }; + uint8_t prefix = 0; + int rc = SR_ERR_OK; + + SRP_LOG_DBGMSG("Updating IP config on interface"); + + /* get old config to be deleted */ + if (SR_UINT8_T == old_val->type) { + prefix = old_val->data.uint8_val; + } else if (SR_STRING_T == old_val->type) { + prefix = netmask_to_prefix(old_val->data.string_val); + } else { + return SR_ERR_INVAL_ARG; + } + addr_str = + sr_xpath_key_value((char *)old_val->xpath, "address", "ip", &xpath_ctx); + ip_addr_str_to_binary(addr_str, addr, is_ipv6); + sr_xpath_recover(&xpath_ctx); + + /* delete old IP config */ + rc = interface_ipv46_config_add_remove(if_name, addr, prefix, is_ipv6, + false /* remove */); + if (SR_ERR_OK != rc) { + SRP_LOG_ERRMSG("Unable to remove old IP address config"); + return rc; + } - /* set new IP config */ - rc = interface_ipv46_config_add_remove(if_name, addr, prefix, is_ipv6, true /* add */); - if (SR_ERR_OK != rc) { - SRP_LOG_ERRMSG("Unable to remove old IP address config"); - return rc; - } + /* update the config with the new value */ + if (sr_xpath_node_name_eq(new_val->xpath, "prefix-length")) { + prefix = new_val->data.uint8_val; + } else if (sr_xpath_node_name_eq(new_val->xpath, "netmask")) { + prefix = netmask_to_prefix(new_val->data.string_val); + } + /* set new IP config */ + rc = interface_ipv46_config_add_remove(if_name, addr, prefix, is_ipv6, + true /* add */); + if (SR_ERR_OK != rc) { + SRP_LOG_ERRMSG("Unable to remove old IP address config"); return rc; + } + + return rc; } /** - * @brief Callback to be called by any config change in subtrees "/ietf-interfaces:interfaces/interface/ietf-ip:ipv4/address" - * or "/ietf-interfaces:interfaces/interface/ietf-ip:ipv6/address". + * @brief Callback to be called by any config change in subtrees + * "/ietf-interfaces:interfaces/interface/ietf-ip:ipv4/address" or + * "/ietf-interfaces:interfaces/interface/ietf-ip:ipv6/address". */ -static int -ietf_interface_ipv46_address_change_cb(sr_session_ctx_t *session, const char *module_name, const char *xpath, sr_event_t event, - uint32_t request_id, void *private_data) -{ - sr_change_iter_t *iter = NULL; - sr_change_oper_t op = SR_OP_CREATED; - sr_val_t *old_val = NULL; - sr_val_t *new_val = NULL; - sr_xpath_ctx_t xpath_ctx = { 0 }; - bool is_ipv6 = false, has_addr = false, has_prefix = false; - uint8_t addr[16] = { 0, }; - uint8_t prefix = 0; - char *node_name = NULL, *if_name = NULL; - int rc = SR_ERR_OK, op_rc = SR_ERR_OK; - - /* no-op for apply, we only care about SR_EV_ENABLED, SR_EV_VERIFY, SR_EV_ABORT */ - if (SR_EV_DONE == event) { - return SR_ERR_OK; - } +static int ietf_interface_ipv46_address_change_cb( + sr_session_ctx_t *session, const char *module_name, const char *xpath, + sr_event_t event, uint32_t request_id, void *private_data) { + sr_change_iter_t *iter = NULL; + sr_change_oper_t op = SR_OP_CREATED; + sr_val_t *old_val = NULL; + sr_val_t *new_val = NULL; + sr_xpath_ctx_t xpath_ctx = {0}; + bool is_ipv6 = false, has_addr = false, has_prefix = false; + uint8_t addr[16] = { + 0, + }; + uint8_t prefix = 0; + char *node_name = NULL, *if_name = NULL; + int rc = SR_ERR_OK, op_rc = SR_ERR_OK; + + /* no-op for apply, we only care about SR_EV_ENABLED, SR_EV_VERIFY, + * SR_EV_ABORT */ + if (SR_EV_DONE == event) { + return SR_ERR_OK; + } - /* check whether we are handling ipv4 or ipv6 config */ - node_name = sr_xpath_node_idx((char*)xpath, 2, &xpath_ctx); - if (NULL != node_name && 0 == strcmp(node_name, "ipv6")) { - is_ipv6 = true; - } - sr_xpath_recover(&xpath_ctx); + /* check whether we are handling ipv4 or ipv6 config */ + node_name = sr_xpath_node_idx((char *)xpath, 2, &xpath_ctx); + if (NULL != node_name && 0 == strcmp(node_name, "ipv6")) { + is_ipv6 = true; + } + sr_xpath_recover(&xpath_ctx); - /* get changes iterator */ - rc = sr_get_changes_iter(session, xpath, &iter); - if (SR_ERR_OK != rc) { - // SRP_LOG_ERR("Unable to retrieve change iterator: %s", sr_strerror(rc)); - return rc; - } + /* get changes iterator */ + rc = sr_get_changes_iter(session, xpath, &iter); + if (SR_ERR_OK != rc) { + // SRP_LOG_ERR("Unable to retrieve change iterator: %s", sr_strerror(rc)); + return rc; + } - /* iterate over all changes */ - while ((SR_ERR_OK == op_rc || event == SR_EV_ABORT) && - (SR_ERR_OK == (rc = sr_get_change_next(session, iter, &op, &old_val, &new_val)))) { - - if_name = strdup(sr_xpath_key_value(new_val ? new_val->xpath : old_val->xpath, "interface", "name", &xpath_ctx)); - sr_xpath_recover(&xpath_ctx); - - switch (op) { - case SR_OP_CREATED: - if (SR_LIST_T == new_val->type) { - /* create on list item - reset state vars */ - has_addr = has_prefix = false; - } else { - if (sr_xpath_node_name_eq(new_val->xpath, "ip")) { - ip_addr_str_to_binary(new_val->data.string_val, addr, is_ipv6); - has_addr = true; - } else if (sr_xpath_node_name_eq(new_val->xpath, "prefix-length")) { - prefix = new_val->data.uint8_val; - has_prefix = true; - } else if (sr_xpath_node_name_eq(new_val->xpath, "netmask")) { - prefix = netmask_to_prefix(new_val->data.string_val); - has_prefix = true; - } - if (has_addr && has_prefix) { - op_rc = interface_ipv46_config_add_remove(if_name, addr, prefix, is_ipv6, true /* add */); - } - } - break; - case SR_OP_MODIFIED: - op_rc = interface_ipv46_config_modify(session, if_name, old_val, new_val, is_ipv6); - break; - case SR_OP_DELETED: - if (SR_LIST_T == old_val->type) { - /* delete on list item - reset state vars */ - has_addr = has_prefix = false; - } else { - if (sr_xpath_node_name_eq(old_val->xpath, "ip")) { - ip_addr_str_to_binary(old_val->data.string_val, addr, is_ipv6); - has_addr = true; - } else if (sr_xpath_node_name_eq(old_val->xpath, "prefix-length")) { - prefix = old_val->data.uint8_val; - has_prefix = true; - } else if (sr_xpath_node_name_eq(old_val->xpath, "netmask")) { - prefix = netmask_to_prefix(old_val->data.string_val); - has_prefix = true; - } - if (has_addr && has_prefix) { - op_rc = interface_ipv46_config_add_remove(if_name, addr, prefix, is_ipv6, false /* !add */); - } - } - break; - default: - break; + /* iterate over all changes */ + while ((SR_ERR_OK == op_rc || event == SR_EV_ABORT) && + (SR_ERR_OK == + (rc = sr_get_change_next(session, iter, &op, &old_val, &new_val)))) { + if_name = + strdup(sr_xpath_key_value(new_val ? new_val->xpath : old_val->xpath, + "interface", "name", &xpath_ctx)); + sr_xpath_recover(&xpath_ctx); + + switch (op) { + case SR_OP_CREATED: + if (SR_LIST_T == new_val->type) { + /* create on list item - reset state vars */ + has_addr = has_prefix = false; + } else { + if (sr_xpath_node_name_eq(new_val->xpath, "ip")) { + ip_addr_str_to_binary(new_val->data.string_val, addr, is_ipv6); + has_addr = true; + } else if (sr_xpath_node_name_eq(new_val->xpath, "prefix-length")) { + prefix = new_val->data.uint8_val; + has_prefix = true; + } else if (sr_xpath_node_name_eq(new_val->xpath, "netmask")) { + prefix = netmask_to_prefix(new_val->data.string_val); + has_prefix = true; + } + if (has_addr && has_prefix) { + op_rc = interface_ipv46_config_add_remove(if_name, addr, prefix, + is_ipv6, true /* add */); + } } - if (SR_ERR_INVAL_ARG == op_rc) { - sr_set_error(session, "Invalid interface name.", new_val ? new_val->xpath : old_val->xpath); + break; + case SR_OP_MODIFIED: + op_rc = interface_ipv46_config_modify(session, if_name, old_val, + new_val, is_ipv6); + break; + case SR_OP_DELETED: + if (SR_LIST_T == old_val->type) { + /* delete on list item - reset state vars */ + has_addr = has_prefix = false; + } else { + if (sr_xpath_node_name_eq(old_val->xpath, "ip")) { + ip_addr_str_to_binary(old_val->data.string_val, addr, is_ipv6); + has_addr = true; + } else if (sr_xpath_node_name_eq(old_val->xpath, "prefix-length")) { + prefix = old_val->data.uint8_val; + has_prefix = true; + } else if (sr_xpath_node_name_eq(old_val->xpath, "netmask")) { + prefix = netmask_to_prefix(old_val->data.string_val); + has_prefix = true; + } + if (has_addr && has_prefix) { + op_rc = interface_ipv46_config_add_remove( + if_name, addr, prefix, is_ipv6, false /* !add */); + } } - free(if_name); - sr_free_val(old_val); - sr_free_val(new_val); + break; + default: + break; + } + if (SR_ERR_INVAL_ARG == op_rc) { + sr_set_error(session, "Invalid interface name.", + new_val ? new_val->xpath : old_val->xpath); } - sr_free_change_iter(iter); + free(if_name); + sr_free_val(old_val); + sr_free_val(new_val); + } + sr_free_change_iter(iter); - return op_rc; + return op_rc; } /** - * @brief Callback to be called by any config change under "/ietf-interfaces:interfaces-state/interface" path. - * Does not provide any functionality, needed just to cover not supported config leaves. + * @brief Callback to be called by any config change under + * "/ietf-interfaces:interfaces-state/interface" path. Does not provide any + * functionality, needed just to cover not supported config leaves. */ -static int -ietf_interface_change_cb(sr_session_ctx_t *session, const char *module_name, const char *xpath, sr_event_t event, - uint32_t request_id, void *private_data) -{ - return SR_ERR_OK; +static int ietf_interface_change_cb(sr_session_ctx_t *session, + const char *module_name, const char *xpath, + sr_event_t event, uint32_t request_id, + void *private_data) { + return SR_ERR_OK; } - int ietf_subscribe_events(sr_session_ctx_t *session, - sr_subscription_ctx_t **subscription){ - - int rc = SR_ERR_OK; - SRP_LOG_DBGMSG("Subscriging ietf."); - - // - rc = sr_module_change_subscribe(session, "ietf-interfaces","/ietf-interfaces:interfaces/interface", ietf_interface_change_cb, - NULL, - 0, SR_SUBSCR_CTX_REUSE | SR_SUBSCR_ENABLED, subscription); - - if (rc != SR_ERR_OK) { - SRP_LOG_DBGMSG("Problem in subscription /ietf-interfaces:interfaces/interface\n"); - goto error; - } - - rc = sr_module_change_subscribe(session, "ietf-interfaces","/ietf-interfaces:interfaces/interface/enabled", ietf_interface_enable_disable_cb, - NULL, - 100, SR_SUBSCR_CTX_REUSE | SR_SUBSCR_ENABLED, subscription); - if (rc != SR_ERR_OK) { - SRP_LOG_DBGMSG("Problem in subscription /ietf-interfaces:interfaces/interface/enabled\n"); - goto error; - } - - //rc = sr_module_change_subscribe(session, "ietf-interfaces","/ietf-interfaces:interfaces/interface/ietf-ip:ipv4/address", ietf_interface_ipv46_address_change_cb, - rc = sr_module_change_subscribe(session, "ietf-interfaces","/ietf-interfaces:interfaces", ietf_interface_ipv46_address_change_cb, - NULL, - 99, SR_SUBSCR_CTX_REUSE | SR_SUBSCR_ENABLED, subscription); - - if (rc != SR_ERR_OK) { - SRP_LOG_DBGMSG("Problem in subscription /ietf-interfaces:interfaces/interface/ietf-ip:ipv4/address\n"); - goto error; - } + sr_subscription_ctx_t **subscription) { + int rc = SR_ERR_OK; + SRP_LOG_DBGMSG("Subscriging ietf."); + + // + rc = sr_module_change_subscribe( + session, "ietf-interfaces", "/ietf-interfaces:interfaces/interface", + ietf_interface_change_cb, NULL, 0, + SR_SUBSCR_CTX_REUSE | SR_SUBSCR_ENABLED, subscription); + + if (rc != SR_ERR_OK) { + SRP_LOG_DBGMSG( + "Problem in subscription /ietf-interfaces:interfaces/interface\n"); + goto error; + } - //rc = sr_module_change_subscribe(session, "ietf-interfaces","/ietf-interfaces:interfaces/interface/ietf-ip:ipv6/address", ietf_interface_ipv46_address_change_cb, - // NULL, - // 98, SR_SUBSCR_CTX_REUSE | SR_SUBSCR_ENABLED, subscription); + rc = sr_module_change_subscribe( + session, "ietf-interfaces", + "/ietf-interfaces:interfaces/interface/enabled", + ietf_interface_enable_disable_cb, NULL, 100, + SR_SUBSCR_CTX_REUSE | SR_SUBSCR_ENABLED, subscription); + if (rc != SR_ERR_OK) { + SRP_LOG_DBGMSG( + "Problem in subscription " + "/ietf-interfaces:interfaces/interface/enabled\n"); + goto error; + } - if (rc != SR_ERR_OK) { - SRP_LOG_DBGMSG("Problem in subscription /ietf-interfaces:interfaces/interface/ietf-ip:ipv6/address\n"); - goto error; - } + // rc = sr_module_change_subscribe(session, + // "ietf-interfaces","/ietf-interfaces:interfaces/interface/ietf-ip:ipv4/address", + // ietf_interface_ipv46_address_change_cb, + rc = sr_module_change_subscribe( + session, "ietf-interfaces", "/ietf-interfaces:interfaces", + ietf_interface_ipv46_address_change_cb, NULL, 99, + SR_SUBSCR_CTX_REUSE | SR_SUBSCR_ENABLED, subscription); + + if (rc != SR_ERR_OK) { + SRP_LOG_DBGMSG( + "Problem in subscription " + "/ietf-interfaces:interfaces/interface/ietf-ip:ipv4/address\n"); + goto error; + } - /* rc = sr_dp_get_items_subscribe(session, "/ietf-interfaces:interfaces-state", ietf_interface_state_cb, - NULL, SR_SUBSCR_CTX_REUSE, - subscription); - if (rc != SR_ERR_OK) { - SRP_LOG_DBG_MSG("Problem in subscription /ietf-interfaces:interfaces-state\n"); + // rc = sr_module_change_subscribe(session, + // "ietf-interfaces","/ietf-interfaces:interfaces/interface/ietf-ip:ipv6/address", + // ietf_interface_ipv46_address_change_cb, + // NULL, + // 98, SR_SUBSCR_CTX_REUSE | + // SR_SUBSCR_ENABLED, subscription); + + if (rc != SR_ERR_OK) { + SRP_LOG_DBGMSG( + "Problem in subscription " + "/ietf-interfaces:interfaces/interface/ietf-ip:ipv6/address\n"); goto error; - }*/ + } + /* rc = sr_dp_get_items_subscribe(session, + "/ietf-interfaces:interfaces-state", ietf_interface_state_cb, NULL, + SR_SUBSCR_CTX_REUSE, subscription); if (rc != SR_ERR_OK) { + SRP_LOG_DBG_MSG("Problem in subscription + /ietf-interfaces:interfaces-state\n"); goto error; + }*/ SRP_LOG_INFMSG("ietf initialized successfully."); return SR_ERR_OK; - error: +error: SRP_LOG_ERRMSG("Error by initialization of the ietf."); return rc; } diff --git a/ctrl/sysrepo-plugins/hicn-plugin/plugin/ietf/ietf_interface.h b/ctrl/sysrepo-plugins/hicn-plugin/plugin/ietf/ietf_interface.h index 0f6c7f8b4..cf5430464 100644 --- a/ctrl/sysrepo-plugins/hicn-plugin/plugin/ietf/ietf_interface.h +++ b/ctrl/sysrepo-plugins/hicn-plugin/plugin/ietf/ietf_interface.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 HUACHENTEL and/or its affiliates. + * Copyright (c) 2021 HUACHENTEL 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: @@ -19,5 +19,4 @@ int ietf_subscribe_events(sr_session_ctx_t *session, sr_subscription_ctx_t **subscription); - #endif /* __IETF_INTERFACE_H__ */ diff --git a/ctrl/sysrepo-plugins/hicn-plugin/plugin/model/hicn_model.c b/ctrl/sysrepo-plugins/hicn-plugin/plugin/model/hicn_model.c index 63685e10a..f1b804267 100644 --- a/ctrl/sysrepo-plugins/hicn-plugin/plugin/model/hicn_model.c +++ b/ctrl/sysrepo-plugins/hicn-plugin/plugin/model/hicn_model.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2020 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-plugin/plugin/model/hicn_model.h b/ctrl/sysrepo-plugins/hicn-plugin/plugin/model/hicn_model.h index 62fb15340..866eafd5e 100644 --- a/ctrl/sysrepo-plugins/hicn-plugin/plugin/model/hicn_model.h +++ b/ctrl/sysrepo-plugins/hicn-plugin/plugin/model/hicn_model.h @@ -1,21 +1,22 @@ /* -* Copyright (c) 2019 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: -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ + * 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: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ /** * @file hicn_model.h - * @brief This file contains main calls for hICN events coresponding to the hICN yang models + * @brief This file contains main calls for hICN events coresponding to the hICN + * yang models */ #ifndef __IETF_HICN_H__ @@ -55,12 +56,10 @@ /** * @brief enumeration for the locks */ -enum locks_name {lstate, lstrategy, lstrategies, lroute, lfaces}; - +enum locks_name { lstate, lstrategy, lstrategies, lroute, lfaces }; // It is a coarse grain approach later can be changed to fine grained - /** * @brief This indicates the number of leaves for the hICN state */ @@ -78,61 +77,60 @@ enum locks_name {lstate, lstrategy, lstrategies, lroute, lfaces}; */ #define MAX_FACE_POOL 100 /** - * @brief This indicates the maximum routes which can be read as operational data + * @brief This indicates the maximum routes which can be read as operational + * data */ #define MAX_ROUTE_POOL 100 /** * @brief This indicates the number of leaves for faces */ -#define FACES_CHILDREN 9 /*this is the number of children of each leave in face except the key*/ +#define FACES_CHILDREN \ + 9 /*this is the number of children of each leave in face except the key*/ /** * @brief This indicates the number of leaves for routes */ -#define ROUTES_CHILDREN 2 /*this is the number of children of each leave in face except the key*/ - -typedef struct __attribute__ ((__packed__)) { - int32_t retval; - uint64_t pkts_processed; - uint64_t pkts_interest_count; - uint64_t pkts_data_count; - uint64_t pkts_from_cache_count; - uint64_t pkts_no_pit_count; - uint64_t pit_expired_count; - uint64_t cs_expired_count; - uint64_t cs_lru_count; - uint64_t pkts_drop_no_buf; - uint64_t interests_aggregated; - uint64_t interests_retx; - uint64_t interests_hash_collision; - uint64_t pit_entries_count; - uint64_t cs_entries_count; - uint64_t cs_entries_ntw_count; +#define ROUTES_CHILDREN \ + 2 /*this is the number of children of each leave in face except the key*/ + +typedef struct __attribute__((__packed__)) { + int32_t retval; + uint64_t pkts_processed; + uint64_t pkts_interest_count; + uint64_t pkts_data_count; + uint64_t pkts_from_cache_count; + uint64_t pkts_no_pit_count; + uint64_t pit_expired_count; + uint64_t cs_expired_count; + uint64_t cs_lru_count; + uint64_t pkts_drop_no_buf; + uint64_t interests_aggregated; + uint64_t interests_retx; + uint64_t interests_hash_collision; + uint64_t pit_entries_count; + uint64_t cs_entries_count; + uint64_t cs_entries_ntw_count; } hicn_state_t; - -typedef struct __attribute__ ((__packed__)) { - - uint8_t n_strategies; - uint32_t strategy_id[256]; - int32_t retval; +typedef struct __attribute__((__packed__)) { + uint8_t n_strategies; + uint32_t strategy_id[256]; + int32_t retval; } hicn_strategies_t; - -typedef struct __attribute__ ((__packed__)) { - uint32_t faceid; - uint32_t intfc; - uint64_t irx_packets; - uint64_t irx_bytes; - uint64_t itx_packets; - uint64_t itx_bytes; - uint64_t drx_packets; - uint64_t drx_bytes; - uint64_t dtx_packets; - uint64_t dtx_bytes; +typedef struct __attribute__((__packed__)) { + uint32_t faceid; + uint32_t intfc; + uint64_t irx_packets; + uint64_t irx_bytes; + uint64_t itx_packets; + uint64_t itx_bytes; + uint64_t drx_packets; + uint64_t drx_bytes; + uint64_t dtx_packets; + uint64_t dtx_bytes; } hicn_face_inf_t; - -typedef struct __attribute__ ((__packed__)) { +typedef struct __attribute__((__packed__)) { u32 route_id; vapi_type_prefix prefix; u32 faceids[5]; @@ -143,29 +141,27 @@ typedef struct __attribute__ ((__packed__)) { /** * @brief This is the link list to maintain the statistics of the faces */ -struct hicn_faces_s{ - hicn_face_inf_t face; - struct hicn_faces_s * next; +struct hicn_faces_s { + hicn_face_inf_t face; + struct hicn_faces_s *next; }; - -typedef struct __attribute__ ((__packed__)) { - uint32_t nface; - struct hicn_faces_s * next; +typedef struct __attribute__((__packed__)) { + uint32_t nface; + struct hicn_faces_s *next; } hicn_faces_t; /** * @brief This is the link list to maintain the route informations */ -struct hicn_routes_s{ - hicn_route_inf_t route; - struct hicn_routes_s * next; +struct hicn_routes_s { + hicn_route_inf_t route; + struct hicn_routes_s *next; }; - -typedef struct __attribute__ ((__packed__)) { - uint32_t nroute; - struct hicn_routes_s * next; +typedef struct __attribute__((__packed__)) { + uint32_t nroute; + struct hicn_routes_s *next; } hicn_routes_t; /** @@ -173,6 +169,6 @@ typedef struct __attribute__ ((__packed__)) { * as well as operational data */ int hicn_subscribe_events(sr_session_ctx_t *session, - sr_subscription_ctx_t **subscription); + sr_subscription_ctx_t **subscription); #endif /* __IETF_HICN_H__ */ diff --git a/ctrl/sysrepo-plugins/hicn-plugin/plugin/model/tlock.c b/ctrl/sysrepo-plugins/hicn-plugin/plugin/model/tlock.c index d27ae6492..c3c225ef7 100644 --- a/ctrl/sysrepo-plugins/hicn-plugin/plugin/model/tlock.c +++ b/ctrl/sysrepo-plugins/hicn-plugin/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 tlock(int Lock_Number ){ - - int my_ticket = __sync_fetch_and_add(&En[Lock_Number] , 1 ); - while ( my_ticket != De[ Lock_Number ] ) {}; - +void tlock(int Lock_Number) { + int my_ticket = __sync_fetch_and_add(&En[Lock_Number], 1); + while (my_ticket != De[Lock_Number]) { + }; } -void tunlock(int Lock_Number ){ -De[Lock_Number]++; -} +void tunlock(int Lock_Number) { De[Lock_Number]++; } diff --git a/ctrl/sysrepo-plugins/hicn-plugin/plugin/model/tlock.h b/ctrl/sysrepo-plugins/hicn-plugin/plugin/model/tlock.h index a871705a3..be3342d3f 100644 --- a/ctrl/sysrepo-plugins/hicn-plugin/plugin/model/tlock.h +++ b/ctrl/sysrepo-plugins/hicn-plugin/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,8 +13,6 @@ * limitations under the License. */ - - /** * @file tlock.h * @brief This file contains ticket lock APIs. @@ -23,42 +21,40 @@ #ifndef __TLOCK_H__ #define __TLOCK_H__ - /** * @brief limit the number of locks: it shoud be matched with the * number of hicn-state leaves */ -#define MAX_LOCK_SIZE 5 +#define MAX_LOCK_SIZE 5 /** * @brief Ticket lock counters */ -volatile long int En[MAX_LOCK_SIZE] ; +volatile long int En[MAX_LOCK_SIZE]; /** * @brief Ticket lock counters */ -volatile long int De[MAX_LOCK_SIZE] ; - +volatile long int De[MAX_LOCK_SIZE]; /** * @brief This function initialize the ticket lock * @param Lock_Number describes the number of locks need to be initialized * @param init describes the init number */ -void ticket_init ( int Lock_Number , long int init ); +void ticket_init(int Lock_Number, long int init); /** * @brief this function acquire the lock * Description of what the function does. This part may refer to the parameters * @param Lock_Number pass the lock */ -void tlock(int Lock_Number ); +void tlock(int Lock_Number); /** * @briefthis function release the lock * @param Lock_Number lock number */ -void tunlock(int Lock_Number ); +void tunlock(int Lock_Number); #endif /* __IETF_HICN_H__ */
\ No newline at end of file diff --git a/ctrl/sysrepo-plugins/hicn-plugin/test/vapi-test/test.c b/ctrl/sysrepo-plugins/hicn-plugin/test/vapi-test/test.c index f7b92c3c5..d3e47c970 100755..100644 --- a/ctrl/sysrepo-plugins/hicn-plugin/test/vapi-test/test.c +++ b/ctrl/sysrepo-plugins/hicn-plugin/test/vapi-test/test.c @@ -5,177 +5,149 @@ #include <signal.h> #include <inttypes.h> -#include<vapi/hicn.api.vapi.h> - +#include <vapi/hicn.api.vapi.h> DEFINE_VAPI_MSG_IDS_HICN_API_JSON; vapi_ctx_t g_vapi_ctx_instance; - #define APP_NAME "test_hicn_plugin" #define MAX_OUTSTANDING_REQUESTS 4 #define RESPONSE_QUEUE_SIZE 2 vapi_ctx_t g_vapi_ctx_instance = NULL; - -void usage(){ - printf("choose the test [route_add [4|6], punt_add [4|6], face_add [4|6], route_dump, face_dump]\n"); +void usage() { + printf( + "choose the test [route_add [4|6], punt_add [4|6], face_add [4|6], " + "route_dump, face_dump]\n"); } -static vapi_error_e call_hicn_api_punting_add(struct vapi_ctx_s *ctx, - void *callback_ctx, - vapi_error_e rv, - bool is_last, - vapi_payload_hicn_api_punting_add_reply *reply){ -if(!reply->retval){ - printf("Successfully done"); - return VAPI_OK; - }else - return VAPI_EUSER; +static vapi_error_e call_hicn_api_punting_add( + struct vapi_ctx_s *ctx, void *callback_ctx, vapi_error_e rv, bool is_last, + vapi_payload_hicn_api_punting_add_reply *reply) { + if (!reply->retval) { + printf("Successfully done"); + return VAPI_OK; + } else + return VAPI_EUSER; } -static vapi_error_e call_hicn_api_face_ip_add(struct vapi_ctx_s *ctx, - void *callback_ctx, - vapi_error_e rv, - bool is_last, - vapi_payload_hicn_api_face_ip_add_reply *reply){ -if(!reply->retval){ - printf("Successfully done"); - return VAPI_OK; - }else - return VAPI_EUSER; - +static vapi_error_e call_hicn_api_face_ip_add( + struct vapi_ctx_s *ctx, void *callback_ctx, vapi_error_e rv, bool is_last, + vapi_payload_hicn_api_face_ip_add_reply *reply) { + if (!reply->retval) { + printf("Successfully done"); + return VAPI_OK; + } else + return VAPI_EUSER; } -static vapi_error_e call_hicn_api_route_nhops_add(struct vapi_ctx_s *ctx, - void *callback_ctx, - vapi_error_e rv, - bool is_last, - vapi_payload_hicn_api_route_nhops_add_reply *reply){ -if(!reply->retval){ - printf("Successfully done"); - return VAPI_OK; - }else - return VAPI_EUSER; +static vapi_error_e call_hicn_api_route_nhops_add( + struct vapi_ctx_s *ctx, void *callback_ctx, vapi_error_e rv, bool is_last, + vapi_payload_hicn_api_route_nhops_add_reply *reply) { + if (!reply->retval) { + printf("Successfully done"); + return VAPI_OK; + } else + return VAPI_EUSER; } -static vapi_error_e -hicn_api_routes_dump_cb(struct vapi_ctx_s *ctx, void *callback_ctx, - vapi_error_e rv, bool is_last, - vapi_payload_hicn_api_routes_details *reply) -{ - - char buf[20]; - if (reply!=NULL){ - memset(buf, 0x00, 20); - if (reply->prefix.address.af==ADDRESS_IP4){ - struct sockaddr_in sa; - memcpy(&sa.sin_addr.s_addr, reply->prefix.address.un.ip4, 4); - inet_ntop(AF_INET, &(sa.sin_addr.s_addr), buf, INET_ADDRSTRLEN); - printf("Prefix:%s\n",buf); - }else{ - struct sockaddr_in6 sa; - memcpy(&sa.sin6_addr,reply->prefix.address.un.ip6,6); - inet_ntop(AF_INET6, &(sa.sin6_addr), buf, INET6_ADDRSTRLEN); - printf("Prefix:%s\n",buf); - } - }else - { - printf("---------Routes------- \n"); - } - return 0; - +static vapi_error_e hicn_api_routes_dump_cb( + struct vapi_ctx_s *ctx, void *callback_ctx, vapi_error_e rv, bool is_last, + vapi_payload_hicn_api_routes_details *reply) { + char buf[20]; + if (reply != NULL) { + memset(buf, 0x00, 20); + if (reply->prefix.address.af == ADDRESS_IP4) { + struct sockaddr_in sa; + memcpy(&sa.sin_addr.s_addr, reply->prefix.address.un.ip4, 4); + inet_ntop(AF_INET, &(sa.sin_addr.s_addr), buf, INET_ADDRSTRLEN); + printf("Prefix:%s\n", buf); + } else { + struct sockaddr_in6 sa; + memcpy(&sa.sin6_addr, reply->prefix.address.un.ip6, 6); + inet_ntop(AF_INET6, &(sa.sin6_addr), buf, INET6_ADDRSTRLEN); + printf("Prefix:%s\n", buf); + } + } else { + printf("---------Routes------- \n"); + } + return 0; } - - -static vapi_error_e -hicn_api_face_stats_dump_cb(struct vapi_ctx_s *ctx, void *callback_ctx, - vapi_error_e rv, bool is_last, - vapi_payload_hicn_api_face_stats_details *reply) -{ - if (reply!=NULL){ - - printf("face_id:%d \n", reply->faceid); - printf("irx_packets:%" PRId64 "\n", reply->irx_packets); - printf("irx_bytes:%" PRId64 "\n", reply->irx_bytes); - printf("itx_packets:%" PRId64 "\n", reply->itx_packets); - printf("itx_bytes:%" PRId64 "\n", reply->itx_bytes); - printf("drx_packets:%" PRId64 "\n", reply->drx_packets); - printf("drx_bytes:%" PRId64 "\n", reply->drx_bytes); - printf("dtx_packets:%" PRId64 "\n", reply->dtx_packets); - printf("dtx_bytes:%" PRId64 "\n", reply->dtx_bytes); - - }else - { - printf("---------Facees------- \n"); - } - return 0; +static vapi_error_e hicn_api_face_stats_dump_cb( + struct vapi_ctx_s *ctx, void *callback_ctx, vapi_error_e rv, bool is_last, + vapi_payload_hicn_api_face_stats_details *reply) { + if (reply != NULL) { + printf("face_id:%d \n", reply->faceid); + printf("irx_packets:%" PRId64 "\n", reply->irx_packets); + printf("irx_bytes:%" PRId64 "\n", reply->irx_bytes); + printf("itx_packets:%" PRId64 "\n", reply->itx_packets); + printf("itx_bytes:%" PRId64 "\n", reply->itx_bytes); + printf("drx_packets:%" PRId64 "\n", reply->drx_packets); + printf("drx_bytes:%" PRId64 "\n", reply->drx_bytes); + printf("dtx_packets:%" PRId64 "\n", reply->dtx_packets); + printf("dtx_bytes:%" PRId64 "\n", reply->dtx_bytes); + + } else { + printf("---------Facees------- \n"); + } + return 0; } - -int hicn_connect_vpp() -{ - - if (g_vapi_ctx_instance == NULL) - { - vapi_error_e rv = vapi_ctx_alloc(&g_vapi_ctx_instance); - rv = vapi_connect(g_vapi_ctx_instance, APP_NAME, NULL, MAX_OUTSTANDING_REQUESTS, RESPONSE_QUEUE_SIZE, VAPI_MODE_BLOCKING, true); - if (rv != VAPI_OK) - { - vapi_ctx_free(g_vapi_ctx_instance); - return -1; - } - } - else - { - } - return 0; +int hicn_connect_vpp() { + if (g_vapi_ctx_instance == NULL) { + vapi_error_e rv = vapi_ctx_alloc(&g_vapi_ctx_instance); + rv = vapi_connect(g_vapi_ctx_instance, APP_NAME, NULL, + MAX_OUTSTANDING_REQUESTS, RESPONSE_QUEUE_SIZE, + VAPI_MODE_BLOCKING, true); + if (rv != VAPI_OK) { + vapi_ctx_free(g_vapi_ctx_instance); + return -1; + } + } else { + } + return 0; } -int hicn_disconnect_vpp() -{ - if (NULL != g_vapi_ctx_instance) - { - vapi_disconnect(g_vapi_ctx_instance); - vapi_ctx_free(g_vapi_ctx_instance); - g_vapi_ctx_instance = NULL; - } - return 0; +int hicn_disconnect_vpp() { + if (NULL != g_vapi_ctx_instance) { + vapi_disconnect(g_vapi_ctx_instance); + vapi_ctx_free(g_vapi_ctx_instance); + g_vapi_ctx_instance = NULL; + } + return 0; } -int main(int argc, char **argv) -{ - - if (argc<2){ +int main(int argc, char **argv) { + if (argc < 2) { usage(); return 1; } - /* connect to vpp */ + /* connect to vpp */ int rc = hicn_connect_vpp(); - if (-1 == rc){ + if (-1 == rc) { perror("vpp connect error"); return -1; } - if (!strcmp(argv[1],"route_add")){ + if (!strcmp(argv[1], "route_add")) { vapi_msg_hicn_api_route_nhops_add *msg; msg = vapi_alloc_hicn_api_route_nhops_add(g_vapi_ctx_instance); - if (!strcmp(argv[2],"4")){ + if (!strcmp(argv[2], "4")) { struct sockaddr_in sa; - inet_pton(AF_INET, "192.168.10.10", &(sa.sin_addr)); - unsigned char * tmp = (unsigned char *) &sa.sin_addr.s_addr; - memcpy(&msg->payload.prefix.address.un.ip4[0],tmp,4); + inet_pton(AF_INET, "192.168.10.10", &(sa.sin_addr)); + unsigned char *tmp = (unsigned char *)&sa.sin_addr.s_addr; + memcpy(&msg->payload.prefix.address.un.ip4[0], tmp, 4); msg->payload.prefix.address.af = ADDRESS_IP4; - }else{ + } else { void *dst = malloc(sizeof(struct in6_addr)); inet_pton(AF_INET6, "2001::1", dst); - unsigned char * tmp = (unsigned char *) ((struct in6_addr *)dst)->s6_addr; - memcpy(&msg->payload.prefix.address.un.ip6[0],tmp,16); + unsigned char *tmp = (unsigned char *)((struct in6_addr *)dst)->s6_addr; + memcpy(&msg->payload.prefix.address.un.ip6[0], tmp, 16); msg->payload.prefix.address.af = ADDRESS_IP6; } @@ -189,97 +161,93 @@ int main(int argc, char **argv) msg->payload.face_ids[6] = 0; msg->payload.n_faces = 1; - if(vapi_hicn_api_route_nhops_add(g_vapi_ctx_instance,msg,call_hicn_api_route_nhops_add,NULL)!=VAPI_OK){ + if (vapi_hicn_api_route_nhops_add(g_vapi_ctx_instance, msg, + call_hicn_api_route_nhops_add, + NULL) != VAPI_OK) { perror("Operation failed"); return -1; } - }else if (!strcmp(argv[1],"face_add")){ - + } else if (!strcmp(argv[1], "face_add")) { vapi_msg_hicn_api_face_ip_add *fmsg; fmsg = vapi_alloc_hicn_api_face_ip_add(g_vapi_ctx_instance); - - if (!strcmp(argv[2],"4")){ + if (!strcmp(argv[2], "4")) { struct sockaddr_in sa; - inet_pton(AF_INET, "192.168.50.19", &(sa.sin_addr)); - unsigned char * tmp = (unsigned char *) &sa.sin_addr.s_addr; - memcpy(&fmsg->payload.face.local_addr.un.ip4[0],tmp,4); + inet_pton(AF_INET, "192.168.50.19", &(sa.sin_addr)); + unsigned char *tmp = (unsigned char *)&sa.sin_addr.s_addr; + memcpy(&fmsg->payload.face.local_addr.un.ip4[0], tmp, 4); fmsg->payload.face.local_addr.af = ADDRESS_IP4; - - inet_pton(AF_INET, "192.168.60.10", &(sa.sin_addr)); + inet_pton(AF_INET, "192.168.60.10", &(sa.sin_addr)); tmp = (unsigned char *)&sa.sin_addr.s_addr; - memcpy(&fmsg->payload.face.remote_addr.un.ip4[0],tmp,4); + memcpy(&fmsg->payload.face.remote_addr.un.ip4[0], tmp, 4); fmsg->payload.face.remote_addr.af = ADDRESS_IP4; - }else{ - + } else { void *dst = malloc(sizeof(struct in6_addr)); inet_pton(AF_INET6, "2001::1", dst); - unsigned char * tmp = (unsigned char *) ((struct in6_addr *)dst)->s6_addr; - memcpy(&fmsg->payload.face.local_addr.un.ip6[0],tmp,16); + unsigned char *tmp = (unsigned char *)((struct in6_addr *)dst)->s6_addr; + memcpy(&fmsg->payload.face.local_addr.un.ip6[0], tmp, 16); fmsg->payload.face.local_addr.af = ADDRESS_IP6; - inet_pton(AF_INET6, "3001::1", dst); - tmp =(unsigned char *) ((struct in6_addr *)dst)->s6_addr; - memcpy(&fmsg->payload.face.remote_addr.un.ip6[0],tmp,16); + tmp = (unsigned char *)((struct in6_addr *)dst)->s6_addr; + memcpy(&fmsg->payload.face.remote_addr.un.ip6[0], tmp, 16); fmsg->payload.face.remote_addr.af = ADDRESS_IP6; } - fmsg->payload.face.swif = 0; // This is the idx number of interface + fmsg->payload.face.swif = 0; // This is the idx number of interface - if(vapi_hicn_api_face_ip_add(g_vapi_ctx_instance,fmsg,call_hicn_api_face_ip_add,NULL)!=VAPI_OK){ - perror("Operation failed"); - return -1; + if (vapi_hicn_api_face_ip_add(g_vapi_ctx_instance, fmsg, + call_hicn_api_face_ip_add, NULL) != VAPI_OK) { + perror("Operation failed"); + return -1; } - }else if (!strcmp(argv[1],"route_dump")){ - // routes dump + } else if (!strcmp(argv[1], "route_dump")) { + // routes dump vapi_msg_hicn_api_routes_dump *rmsg; rmsg = vapi_alloc_hicn_api_routes_dump(g_vapi_ctx_instance); - vapi_hicn_api_routes_dump(g_vapi_ctx_instance, rmsg, hicn_api_routes_dump_cb, NULL); + vapi_hicn_api_routes_dump(g_vapi_ctx_instance, rmsg, + hicn_api_routes_dump_cb, NULL); - }else if (!strcmp(argv[1],"face_dump")){ - // faces dump + } else if (!strcmp(argv[1], "face_dump")) { + // faces dump vapi_msg_hicn_api_face_stats_dump *fmsg; fmsg = vapi_alloc_hicn_api_face_stats_dump(g_vapi_ctx_instance); - vapi_hicn_api_face_stats_dump(g_vapi_ctx_instance, fmsg, hicn_api_face_stats_dump_cb, NULL); - }else if (!strcmp(argv[1],"punt_add")){ - + vapi_hicn_api_face_stats_dump(g_vapi_ctx_instance, fmsg, + hicn_api_face_stats_dump_cb, NULL); + } else if (!strcmp(argv[1], "punt_add")) { vapi_msg_hicn_api_punting_add *pmsg; pmsg = vapi_alloc_hicn_api_punting_add(g_vapi_ctx_instance); - pmsg->payload.type=IP_PUNT; - - if(!strcmp(argv[2],"4")){ + pmsg->payload.type = IP_PUNT; + if (!strcmp(argv[2], "4")) { struct sockaddr_in sa; // store this IP address in sa: - inet_pton(AF_INET, "192.168.10.20", &(sa.sin_addr)); - unsigned char * tmp = (unsigned char *) &sa.sin_addr.s_addr; - memcpy(&pmsg->payload.rule.ip.prefix.address.un.ip4[0],tmp,4); + inet_pton(AF_INET, "192.168.10.20", &(sa.sin_addr)); + unsigned char *tmp = (unsigned char *)&sa.sin_addr.s_addr; + memcpy(&pmsg->payload.rule.ip.prefix.address.un.ip4[0], tmp, 4); pmsg->payload.rule.ip.prefix.address.af = ADDRESS_IP4; - - }else{ - + } else { void *dst = malloc(sizeof(struct in6_addr)); inet_pton(AF_INET6, "3001::1", dst); - unsigned char * tmp =(unsigned char *) ((struct in6_addr *)dst)->s6_addr; - memcpy(&pmsg->payload.rule.ip.prefix.address.un.ip6[0],tmp,16); + unsigned char *tmp = (unsigned char *)((struct in6_addr *)dst)->s6_addr; + memcpy(&pmsg->payload.rule.ip.prefix.address.un.ip6[0], tmp, 16); pmsg->payload.rule.ip.prefix.address.af = ADDRESS_IP6; } pmsg->payload.rule.ip.prefix.len = 24; pmsg->payload.rule.ip.swif = 0; - if (vapi_hicn_api_punting_add(g_vapi_ctx_instance, pmsg, call_hicn_api_punting_add, NULL)!=VAPI_OK){ - perror("Operation failed"); - return -1; + if (vapi_hicn_api_punting_add(g_vapi_ctx_instance, pmsg, + call_hicn_api_punting_add, NULL) != VAPI_OK) { + perror("Operation failed"); + return -1; } - }else - { + } else { usage(); return 1; } diff --git a/ctrl/sysrepo-plugins/yang/ietf/ietf-interfaces.yang b/ctrl/sysrepo-plugins/yang/ietf/ietf-interfaces.yang index f66c205ce..a9251d14d 100644 --- a/ctrl/sysrepo-plugins/yang/ietf/ietf-interfaces.yang +++ b/ctrl/sysrepo-plugins/yang/ietf/ietf-interfaces.yang @@ -21,7 +21,7 @@ module ietf-interfaces { "This module contains a collection of YANG definitions for managing network interfaces. - Copyright (c) 2018 IETF Trust and the persons identified as + Copyright (c) 2021 IETF Trust and the persons identified as authors of the code. All rights reserved. Redistribution and use in source and binary forms, with or |