diff options
author | 2022-08-11 18:30:53 +0200 | |
---|---|---|
committer | 2022-08-11 18:30:53 +0200 | |
commit | 55343701359194493fbd9ff4950ac4f941bbdae3 (patch) | |
tree | 4583baaebd2a715d225054c845a36dc9f63c86ba /ctrl/sysrepo-plugins/hicn-light | |
parent | b9ed4b7dd6c2342bc87209d415b840d65ea5ccf0 (diff) |
feat: drop sysrepo and netconf/yang support
Signed-off-by: Luca Muscariello <muscariello@ieee.org>
Change-Id: I215af1b77a3f9da878f3894708f687a7e7ea03a2
Diffstat (limited to 'ctrl/sysrepo-plugins/hicn-light')
10 files changed, 0 insertions, 608 deletions
diff --git a/ctrl/sysrepo-plugins/hicn-light/CMakeLists.txt b/ctrl/sysrepo-plugins/hicn-light/CMakeLists.txt deleted file mode 100644 index f8a1e64aa..000000000 --- a/ctrl/sysrepo-plugins/hicn-light/CMakeLists.txt +++ /dev/null @@ -1,61 +0,0 @@ -# -# 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. -# - -# set compiler options -set(CMAKE_EXPORT_COMPILE_COMMANDS 1) -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -std=gnu99") -set(CMAKE_C_FLAGS_RELEASE "-DNDEBUG -O2") -set(CMAKE_C_FLAGS_DEBUG "-g -O0") -set (CMAKE_INSTALL_LIBDIR "/usr/lib") - -project(sysrepo-light-plugins) - -# Cmake find modules -list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/../cmake/Modules" -"${CMAKE_CURRENT_LIST_DIR}/../../../cmake/Modules" -) - -find_package(PkgConfig) -find_package(HicnLight) -find_package(Sysrepo) - -#pkg_check_modules(SYSREPO libsysrepo) - -# get sysrepo plugins directory from pkgconfig -if (NOT SR_PLUGINS_DIR) - if (PKG_CONFIG_FOUND) - execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} "--variable=SR_PLUGINS_DIR" "libsysrepo" OUTPUT_VARIABLE SR_PLUGINS_DIR) - string(STRIP ${SR_PLUGINS_DIR} SR_PLUGINS_DIR) - endif() -endif() -if (NOT SR_PLUGINS_DIR) - message(FATAL_ERROR "Cannot get sysrepo plugins directory due to missing pkg-config, set SR_PLUGINS_DIR manually.") -endif() - -# plugins sources -set(PLUGINS_SOURCES - plugin/model/hicn_model.c - plugin/model/tlock.c - plugin/hicn_light_comm.c - plugin/hicn_light.c -) - -# build the source code into shared library -add_library(hicnlight SHARED ${PLUGINS_SOURCES}) -target_include_directories(hicnlight PUBLIC ${HICNLIGHT_INCLUDE_DIRS}) -target_link_libraries(hicnlight ${SYSREPO_LIBRARIES} ${HICNLIGHT_LIBRARIES}) - -# install the plugin into plugins dir -install(TARGETS hicnlight DESTINATION ${SR_PLUGINS_DIR} COMPONENT hicn_sysrepo_plugin) diff --git a/ctrl/sysrepo-plugins/hicn-light/plugin/CMakeLists.txt b/ctrl/sysrepo-plugins/hicn-light/plugin/CMakeLists.txt deleted file mode 100644 index b5faab705..000000000 --- a/ctrl/sysrepo-plugins/hicn-light/plugin/CMakeLists.txt +++ /dev/null @@ -1,59 +0,0 @@ -# -# 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. -# - -# set compiler options -set(CMAKE_EXPORT_COMPILE_COMMANDS 1) -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -std=gnu99") -set(CMAKE_C_FLAGS_RELEASE "-DNDEBUG -O2") -set(CMAKE_C_FLAGS_DEBUG "-g -O0") -set (CMAKE_INSTALL_LIBDIR "/usr/lib") - -project(sysrepo-light-plugins) - -# Cmake find modules -list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/../cmake") - -find_package(PkgConfig) -find_package(HicnLight) -find_package(Sysrepo) - -#pkg_check_modules(SYSREPO libsysrepo) - -# get sysrepo plugins directory from pkgconfig -if (NOT SR_PLUGINS_DIR) - if (PKG_CONFIG_FOUND) - execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} "--variable=SR_PLUGINS_DIR" "libsysrepo" OUTPUT_VARIABLE SR_PLUGINS_DIR) - string(STRIP ${SR_PLUGINS_DIR} SR_PLUGINS_DIR) - endif() -endif() -if (NOT SR_PLUGINS_DIR) - message(FATAL_ERROR "Cannot get sysrepo plugins directory due to missing pkg-config, set SR_PLUGINS_DIR manually.") -endif() - -# plugins sources -set(PLUGINS_SOURCES - model/hicn_model.c - model/tlock.c - hicn_light_comm.c - hicn_light.c -) - -# build the source code into shared library -add_library(hicnlight SHARED ${PLUGINS_SOURCES}) -target_include_directories(hicnlight PUBLIC ${HICNLIGHT_INCLUDE_DIRS}) -target_link_libraries(hicnlight ${SYSREPO_LIBRARIES} ${HICNLIGHT_LIBRARIES}) - -# install the plugin into plugins dir -install(TARGETS hicnlight DESTINATION ${SR_PLUGINS_DIR} COMPONENT hicn_sysrepo_plugin)
\ No newline at end of file diff --git a/ctrl/sysrepo-plugins/hicn-light/plugin/hicn_light.c b/ctrl/sysrepo-plugins/hicn-light/plugin/hicn_light.c deleted file mode 100644 index b2495f730..000000000 --- a/ctrl/sysrepo-plugins/hicn-light/plugin/hicn_light.c +++ /dev/null @@ -1,112 +0,0 @@ -/* - * 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. - */ -#include <inttypes.h> -#include <signal.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> - -#include "hicn_light.h" -#include "model/hicn_model.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_light(); - if (SR_ERR_OK != rc) { - HICN_LOG_ERR("hicn light connect error , with return %d.", rc); - return SR_ERR_INTERNAL; - } - - hicn_subscribe_events(session, &subscription); - - /* set subscription as our private context */ - *private_ctx = subscription; - return SR_ERR_OK; -} - -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_LOG_DBG_MSG("hicn light unload plugin ok."); - hicn_disconnect_light(); - HICN_LOG_DBG_MSG("hicn light disconnect ok."); -} - -static void sigint_handler(int signum) { exit_application = 1; } -int subscribe_all_module_events(sr_session_ctx_t *session) { - sr_plugin_init_cb(session, (void **)&subscription); - return 0; -} - -int main(int argc, char **argv) { - sr_conn_ctx_t *connection = NULL; - sr_session_ctx_t *session = NULL; - int rc = SR_ERR_OK; - - /* connect to hicn light */ - rc = hicn_connect_light(); - if (-1 == rc) { - fprintf(stderr, "hicn light connect error"); - return -1; - } - - /* connect to sysrepo */ - rc = sr_connect(SR_CONN_DEFAULT, &connection); - if (SR_ERR_OK != rc) { - fprintf(stderr, "Error by sr_connect: %s\n", sr_strerror(rc)); - goto cleanup; - } - - /* start session */ - rc = sr_session_start(connection, SR_DS_STARTUP, &session); - if (SR_ERR_OK != rc) { - fprintf(stderr, "Error by sr_session_start: %s\n", sr_strerror(rc)); - goto cleanup; - } - - /* subscribe all module events */ - rc = subscribe_all_module_events(session); - if (SR_ERR_OK != rc) { - fprintf(stderr, "Error by subscribe module events: %s\n", sr_strerror(rc)); - goto cleanup; - } - - /* loop until ctrl-c is pressed / SIGINT is received */ - signal(SIGINT, sigint_handler); - signal(SIGPIPE, SIG_IGN); - - while (!exit_application) { - sleep(2); - } - - printf("Application exit requested, exiting.\n"); - -cleanup: - if (NULL != subscription) { - sr_unsubscribe(subscription); - } - if (NULL != session) { - sr_session_stop(session); - } - if (NULL != connection) { - sr_disconnect(connection); - } - hicn_disconnect_light(); - return rc; -}
\ No newline at end of file diff --git a/ctrl/sysrepo-plugins/hicn-light/plugin/hicn_light.h b/ctrl/sysrepo-plugins/hicn-light/plugin/hicn_light.h deleted file mode 100644 index cea2851c9..000000000 --- a/ctrl/sysrepo-plugins/hicn-light/plugin/hicn_light.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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. - */ - -#ifndef __HICN_LIGHT_H__ -#define __HICN_LIGHT_H__ - -#include "hicn_light_comm.h" - -// functions that sysrepo-plugin need -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); - -#endif //__HICN_LIGHT_H__
\ No newline at end of file diff --git a/ctrl/sysrepo-plugins/hicn-light/plugin/hicn_light_comm.c b/ctrl/sysrepo-plugins/hicn-light/plugin/hicn_light_comm.c deleted file mode 100644 index 08551b470..000000000 --- a/ctrl/sysrepo-plugins/hicn-light/plugin/hicn_light_comm.c +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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. - */ -#include "hicn_light_comm.h" - -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; -} - -int hicn_disconnect_light() { - 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 deleted file mode 100644 index c03d59c30..000000000 --- a/ctrl/sysrepo-plugins/hicn-light/plugin/hicn_light_comm.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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. - */ - -#ifndef __HICN_LIGHT_COMMM_H__ -#define __HICN_LIGHT_COMMM_H__ -#include <sysrepo.h> -#include <sysrepo/values.h> - -#include <hicn/ctrl/api.h> - -#ifndef HICN_THIS_FUNC -#ifdef __FUNCTION__ -#define HICN_THIS_FUNC __FUNCTION__ -#else -#define HICN_THIS_FUNC __func__ -#endif -#endif - -#define ARG_CHECK(retval, arg) \ - do { \ - if (NULL == (arg)) { \ - HICN_LOG_ERR_MSG(#arg ":NULL pointer passed."); \ - return (retval); \ - } \ - } while (0) - -#define ARG_CHECK2(retval, arg1, 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) - -#define MEM_ALIGN 4096 - -int hicn_connect_light(); -int hicn_disconnect_light(); -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 deleted file mode 100644 index d32fd55ef..000000000 --- a/ctrl/sysrepo-plugins/hicn-light/plugin/model/hicn_model.c +++ /dev/null @@ -1,181 +0,0 @@ -/* - * 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. - */ -#include <stdio.h> -#include <malloc.h> -#include <sysrepo/xpath.h> - -/* Hicn headers */ - -#include "hicn_model.h" -#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) { - 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")) { - 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.local_addr.v6.as_in6addr = *dst; - - } 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")) { - 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.remote_addr.v6.as_in6addr = *dst; - - } 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 - - 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("Operation Failed"); - return SR_ERR_OPERATION_FAILED; -} - -/** - * @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) { - SRP_LOG_DBGMSG("hicn face ip del received successfully"); - 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) { - /* - - 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) { - 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: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; - -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 deleted file mode 100644 index be70bc711..000000000 --- a/ctrl/sysrepo-plugins/hicn-light/plugin/model/hicn_model.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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. - */ - -#ifndef __IETF_HICN_H__ -#define __IETF_HICN_H__ - -#include "../hicn_light_comm.h" - -#define MEM_ALIGN 4096 - -// Number of locks is equal to number of nodes in hicn-state -// It is a coarse grain approach later can be changed to fine grained -// better to initialize the lock by 0 -#define NLOCKS 5 -#define LOCK_INIT 0 - -enum locks_name { lstate, lstrategy, lstrategies, lroute, lface_ip_params }; - -#define NSTATE_LEAVES 15 -#define NSTRATEGY_LEAVES 1 -#define NSTRATEGIES_LEAVES 2 -#define NROUTE_LEAVES 2 -#define NFACE_IP_PARAMS_LEAVES 3 - -int hicn_subscribe_events(sr_session_ctx_t *session, - sr_subscription_ctx_t **subscription); - -#endif /* __IETF_HICN_H__ */
\ No newline at end of file diff --git a/ctrl/sysrepo-plugins/hicn-light/plugin/model/tlock.c b/ctrl/sysrepo-plugins/hicn-light/plugin/model/tlock.c deleted file mode 100644 index ba788d3a0..000000000 --- a/ctrl/sysrepo-plugins/hicn-light/plugin/model/tlock.c +++ /dev/null @@ -1,16 +0,0 @@ -#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_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]++; } diff --git a/ctrl/sysrepo-plugins/hicn-light/plugin/model/tlock.h b/ctrl/sysrepo-plugins/hicn-light/plugin/model/tlock.h deleted file mode 100644 index 6840be1c0..000000000 --- a/ctrl/sysrepo-plugins/hicn-light/plugin/model/tlock.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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. - */ - -#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 - -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); - -#endif /* __IETF_HICN_H__ */
\ No newline at end of file |