From a0da41b243661a039481d2c254d7db8f55f18d2b Mon Sep 17 00:00:00 2001 From: Mauro Sardara Date: Mon, 23 Sep 2019 19:34:23 +0200 Subject: [HICN-279] Added libmemif packaging. Change-Id: Ie8662059163b7a01211bb18fb8f6b77bbbc07279 Signed-off-by: Mauro Sardara --- .../hicn-light/plugin/CMakeLists.txt | 60 ++++++ .../sysrepo-plugins/hicn-light/plugin/hicn_light.c | 120 ++++++++++++ .../sysrepo-plugins/hicn-light/plugin/hicn_light.h | 25 +++ .../hicn-light/plugin/hicn_light_comm.c | 33 ++++ .../hicn-light/plugin/hicn_light_comm.h | 81 ++++++++ .../hicn-light/plugin/model/hicn_model.c | 206 +++++++++++++++++++++ .../hicn-light/plugin/model/hicn_model.h | 42 +++++ .../hicn-light/plugin/model/tlock.c | 21 +++ .../hicn-light/plugin/model/tlock.h | 31 ++++ 9 files changed, 619 insertions(+) create mode 100644 ctrl/sysrepo-plugins/hicn-light/plugin/CMakeLists.txt create mode 100644 ctrl/sysrepo-plugins/hicn-light/plugin/hicn_light.c create mode 100644 ctrl/sysrepo-plugins/hicn-light/plugin/hicn_light.h create mode 100644 ctrl/sysrepo-plugins/hicn-light/plugin/hicn_light_comm.c create mode 100644 ctrl/sysrepo-plugins/hicn-light/plugin/hicn_light_comm.h create mode 100644 ctrl/sysrepo-plugins/hicn-light/plugin/model/hicn_model.c create mode 100644 ctrl/sysrepo-plugins/hicn-light/plugin/model/hicn_model.h create mode 100644 ctrl/sysrepo-plugins/hicn-light/plugin/model/tlock.c create mode 100644 ctrl/sysrepo-plugins/hicn-light/plugin/model/tlock.h (limited to 'ctrl/sysrepo-plugins/hicn-light/plugin') diff --git a/ctrl/sysrepo-plugins/hicn-light/plugin/CMakeLists.txt b/ctrl/sysrepo-plugins/hicn-light/plugin/CMakeLists.txt new file mode 100644 index 000000000..e1d3dd39a --- /dev/null +++ b/ctrl/sysrepo-plugins/hicn-light/plugin/CMakeLists.txt @@ -0,0 +1,60 @@ +# +# 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. +# + +# 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") + +cmake_minimum_required(VERSION 2.8) +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 new file mode 100644 index 000000000..ae436a8ad --- /dev/null +++ b/ctrl/sysrepo-plugins/hicn-light/plugin/hicn_light.c @@ -0,0 +1,120 @@ +/* + * 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. + */ +#include +#include +#include +#include +#include + +#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) { + HICN_INVOKE_BEGIN + 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 + hicn_subscribe_events(session, &subscription); + + + /* set subscription as our private context */ + *private_ctx = subscription; + HICN_INVOKE_END; + return SR_ERR_OK; +} + +void sr_plugin_cleanup_cb(sr_session_ctx_t *session, void *private_ctx) { + HICN_INVOKE_BEGIN; + /* subscription was set as our private context */ + sr_unsubscribe(session, private_ctx); + HICN_LOG_DBG_MSG("hicn light unload plugin ok."); + hicn_disconnect_light(); + HICN_LOG_DBG_MSG("hicn light disconnect ok."); + HICN_INVOKE_END; +} + +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("cpe_application", 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, SR_SESS_DEFAULT, &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(session, 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 new file mode 100644 index 000000000..16f65e5c4 --- /dev/null +++ b/ctrl/sysrepo-plugins/hicn-light/plugin/hicn_light.h @@ -0,0 +1,25 @@ +/* + * 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. + */ + +#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 new file mode 100644 index 000000000..6c4f938ce --- /dev/null +++ b/ctrl/sysrepo-plugins/hicn-light/plugin/hicn_light_comm.c @@ -0,0 +1,33 @@ +/* + * 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. + */ +#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 new file mode 100644 index 000000000..adb7737aa --- /dev/null +++ b/ctrl/sysrepo-plugins/hicn-light/plugin/hicn_light_comm.h @@ -0,0 +1,81 @@ +/* + * 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. + */ + +#ifndef __HICN_LIGHT_COMMM_H__ +#define __HICN_LIGHT_COMMM_H__ +#include +#include +#include + + +#include + +#ifndef HICN_THIS_FUNC +#ifdef __FUNCTION__ +#define HICN_THIS_FUNC __FUNCTION__ +#else +#define HICN_THIS_FUNC __func__ +#endif +#endif + +#ifndef _NOLOG +#define HICN_LOG_DBG SRP_LOG_DBG +#define HICN_LOG_ERR SRP_LOG_ERR +#define HICN_LOG_DBG_MSG SRP_LOG_DBG_MSG +#define HICN_LOG_ERR_MSG SRP_LOG_ERR_MSG +#else +#define HICN_LOG_DBG // printf +#define HICN_LOG_DBG // SRP_LOG_DBG +#define HICN_LOG_ERR // SRP_LOG_ERR +#define HICN_LOG_DBG_MSG // SRP_LOG_DBG_MSG +#define HICN_LOG_ERR_MSG // SRP_LOG_ERR_MSG +#endif + +//Here it is the definition + +#define HICN_INVOKE_BEGIN HICN_LOG_DBG("inovke %s bein.", HICN_THIS_FUNC); +#define HICN_INVOKE_END \ + HICN_LOG_DBG("inovke %s end,with return OK.", HICN_THIS_FUNC); +#define HICN_INVOKE_ENDX(...) \ + HICN_LOG_DBG("inovke %s end,with %s.", HICN_THIS_FUNC, ##__VA_ARGS__) + +#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 new file mode 100644 index 000000000..7cfb8363a --- /dev/null +++ b/ctrl/sysrepo-plugins/hicn-light/plugin/model/hicn_model.c @@ -0,0 +1,206 @@ +/* + * 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. + */ +#include +#include +#include + +/* Hicn headers */ + +#include "hicn_model.h" +#include "tlock.h" +#include "../hicn_light.h" +#include "../hicn_light_comm.h" + + + +/** + * @brief API to add hicn face ip in hicn-light. + */ +static int hicn_face_ip_add_cb(const char *xpath, const sr_val_t *input, + const size_t input_cnt, sr_val_t **output, + size_t *output_cnt, void *private_ctx) { + + SRP_LOG_DBG_MSG("hicn face ip add received successfully"); + + hc_face_t face; + + if(strcmp(input[0].data.string_val,"-1")){ + + struct sockaddr_in sa; + // store this IP address in sa: + inet_pton(AF_INET, input[0].data.string_val, &(sa.sin_addr)); + face.face.hicn.family=AF_INET; + face.face.hicn.local_addr.v4.as_inaddr=sa.sin_addr; + + + }else if(strcmp(input[1].data.string_val,"-1")){ + + struct in6_addr *dst = malloc(sizeof(struct in6_addr)); + inet_pton(AF_INET6, input[1].data.string_val, dst); + face.face.hicn.family=AF_INET6; + face.face.hicn.local_addr.v6.as_in6addr = *dst; + + }else{ + SRP_LOG_DBG_MSG("Invalid local IP address"); + return SR_ERR_OPERATION_FAILED; + } + + if(strcmp(input[2].data.string_val,"-1")){ + + struct sockaddr_in sa; + // store this IP address in sa: + inet_pton(AF_INET, input[2].data.string_val, &(sa.sin_addr)); + face.face.hicn.family=AF_INET; + face.face.hicn.remote_addr.v4.as_inaddr=sa.sin_addr; + + + }else if(strcmp(input[3].data.string_val,"-1")){ + + struct in6_addr *dst = malloc(sizeof(struct in6_addr)); + inet_pton(AF_INET6, input[3].data.string_val, dst); + face.face.hicn.family=AF_INET6; + face.face.hicn.remote_addr.v6.as_in6addr = *dst; + + }else{ + SRP_LOG_DBG_MSG("Invalid local IP address"); + return SR_ERR_OPERATION_FAILED; + } + + + // strncpy(face.face.hicn.netdevice.name,"ens39"); // Can we work only with Idx number ? + face.face.hicn.netdevice.index = input[4].data.uint32_val; // This is the idx number of interface + + + face.id=0;//can be empty + face.face.tags=0;//can be empty + strcpy(face.name,"hicn_face"); + face.face.type=1; + + int rc; + rc = hc_face_create(hsocket, &face); + if (rc > 0) { + SRP_LOG_DBG_MSG("Face added successfully"); + return SR_ERR_OK; + } + + SRP_LOG_DBG_MSG("Operation Failed"); + return SR_ERR_OPERATION_FAILED; +} + +/** + * @brief API to del hicn face ip in vpp. + */ +static int hicn_face_ip_del_cb(const char *xpath, const sr_val_t *input, + const size_t input_cnt, sr_val_t **output, + size_t *output_cnt, void *private_ctx) { + + SRP_LOG_DBG_MSG("hicn face ip del received successfully"); + face_t * face=NULL; + + // msg->payload.faceid = input[0].data.uint16_val; + //lookup(face); + face_free(face); + + // if(!resp->payload.retval){ + // SRP_LOG_DBG_MSG("Successfully Done"); + // return SR_ERR_OK; + // } + + SRP_LOG_DBG_MSG("Operation Failed"); + return SR_ERR_OPERATION_FAILED; + +} + + +/** + * @brief API to del hicn face ip in vpp. + */ +static int hicn_route_add_cb(const char *xpath, const sr_val_t *input, + const size_t input_cnt, sr_val_t **output, + size_t *output_cnt, void *private_ctx) { + +/* + + SRP_LOG_DBG_MSG("hicn route add received successfully"); + + hc_route_t * route; + + if(strcmp(input[0].data.string_val,"-1")){ + + struct sockaddr_in sa; + // store this IP address in sa: + inet_pton(AF_INET, input[0].data.string_val, &(sa.sin_addr)); + route.family=AF_INET; + route.face.hicn.local_addr.v4.as_inaddr=sa.sin_addr; + + + }else if(strcmp(input[1].data.string_val,"-1")){ + + struct in6_addr *dst = malloc(sizeof(struct in6_addr)); + inet_pton(AF_INET6, input[1].data.string_val, dst); + face.face.hicn.family=AF_INET6; + face.face.hicn.local_addr.v6.as_in6addr = *dst; + + }else{ + SRP_LOG_DBG_MSG("Invalid local IP address"); + return SR_ERR_OPERATION_FAILED; + } + + +hc_route_create(hsocket, route); +*/ + return SR_ERR_OK; +} + + + +int hicn_subscribe_events(sr_session_ctx_t *session, + sr_subscription_ctx_t **subscription) { + + + int rc; + rc = sr_rpc_subscribe(session, "/hicn:face-ip-add", hicn_face_ip_add_cb, + session, SR_SUBSCR_CTX_REUSE, subscription); + if (rc != SR_ERR_OK) { + SRP_LOG_DBG_MSG("Problem in subscription stat-get\n"); + goto error; + } + + + rc = sr_rpc_subscribe(session, "/hicn:face-ip-del", hicn_face_ip_del_cb, + session, SR_SUBSCR_CTX_REUSE, subscription); + if (rc != SR_ERR_OK) { + SRP_LOG_DBG_MSG("Problem in subscription face-ip-del\n"); + goto error; + } + + + rc = sr_rpc_subscribe(session, "/hicn:route-nhops-add", + hicn_route_add_cb, session, SR_SUBSCR_CTX_REUSE, subscription); + if (rc!= SR_ERR_OK) { + SRP_LOG_DBG_MSG("Problem in subscription route-nhops-add\n"); + goto error; + } + + + SRP_LOG_INF_MSG("hicn light initialized successfully."); + return SR_ERR_OK; + +error: + SRP_LOG_ERR_MSG("Error by initialization of the hicn plugin."); + sr_plugin_cleanup_cb(session, hsocket); + return rc; + +} \ No newline at end of file diff --git a/ctrl/sysrepo-plugins/hicn-light/plugin/model/hicn_model.h b/ctrl/sysrepo-plugins/hicn-light/plugin/model/hicn_model.h new file mode 100644 index 000000000..e6e857bff --- /dev/null +++ b/ctrl/sysrepo-plugins/hicn-light/plugin/model/hicn_model.h @@ -0,0 +1,42 @@ +/* + * 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. + */ + +#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 new file mode 100644 index 000000000..2f7b11efa --- /dev/null +++ b/ctrl/sysrepo-plugins/hicn-light/plugin/model/tlock.c @@ -0,0 +1,21 @@ +#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 new file mode 100644 index 000000000..36698115a --- /dev/null +++ b/ctrl/sysrepo-plugins/hicn-light/plugin/model/tlock.h @@ -0,0 +1,31 @@ +/* + * 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. + */ + + +#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 -- cgit 1.2.3-korg