aboutsummaryrefslogtreecommitdiffstats
path: root/ctrl/sysrepo-plugins/hicn-plugin/plugin
diff options
context:
space:
mode:
Diffstat (limited to 'ctrl/sysrepo-plugins/hicn-plugin/plugin')
-rw-r--r--ctrl/sysrepo-plugins/hicn-plugin/plugin/hicn_plugin.c120
-rw-r--r--ctrl/sysrepo-plugins/hicn-plugin/plugin/hicn_plugin.h46
-rw-r--r--ctrl/sysrepo-plugins/hicn-plugin/plugin/hicn_vpp_comm.c55
-rw-r--r--ctrl/sysrepo-plugins/hicn-plugin/plugin/hicn_vpp_comm.h91
-rw-r--r--ctrl/sysrepo-plugins/hicn-plugin/plugin/ietf/ietf_interface.c607
-rw-r--r--ctrl/sysrepo-plugins/hicn-plugin/plugin/ietf/ietf_interface.h23
-rw-r--r--ctrl/sysrepo-plugins/hicn-plugin/plugin/mainpage.dox211
-rw-r--r--ctrl/sysrepo-plugins/hicn-plugin/plugin/model/hicn_model.c875
-rw-r--r--ctrl/sysrepo-plugins/hicn-plugin/plugin/model/hicn_model.h178
-rw-r--r--ctrl/sysrepo-plugins/hicn-plugin/plugin/model/tlock.c21
-rw-r--r--ctrl/sysrepo-plugins/hicn-plugin/plugin/model/tlock.h64
11 files changed, 0 insertions, 2291 deletions
diff --git a/ctrl/sysrepo-plugins/hicn-plugin/plugin/hicn_plugin.c b/ctrl/sysrepo-plugins/hicn-plugin/plugin/hicn_plugin.c
deleted file mode 100644
index bbcc2e9bf..000000000
--- a/ctrl/sysrepo-plugins/hicn-plugin/plugin/hicn_plugin.c
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * Copyright (c) 2019-2020 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_plugin.h"
-#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();
- if (SR_ERR_OK != rc) {
- return SR_ERR_INTERNAL;
- }
-
- // HICN subscribe
- hicn_subscribe_events(session, &subscription);
-
- //sr_subscription_ctx_t *subscription2 = NULL;
-
- // IETF subscribe
- //ietf_subscribe_events(session, &subscription2);
-
-
- /* 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_disconnect_vpp();
-}
-
-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 vpp */
- rc = hicn_connect_vpp();
- if (-1 == rc) {
- fprintf(stderr, "vpp 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_vpp();
- return rc;
-} \ No newline at end of file
diff --git a/ctrl/sysrepo-plugins/hicn-plugin/plugin/hicn_plugin.h b/ctrl/sysrepo-plugins/hicn-plugin/plugin/hicn_plugin.h
deleted file mode 100644
index 0890c3f03..000000000
--- a/ctrl/sysrepo-plugins/hicn-plugin/plugin/hicn_plugin.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * 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.
- */
-
-/**
- * @file hicn_plugin.h
- * @brief This file contains init and cleanup for the sysrepo.
- */
-
-#ifndef __HICN_PLUGIN_H__
-#define __HICN_PLUGIN_H__
-
-#include "hicn_vpp_comm.h"
-
-
-/**
- * @brief initialize function for sysrepo plugin,
- * In this function we connect to vpp from one side
- * and subscribe for all hICN events as well as interface events (if any)
- * @param session pointer to the sesssion context
- * @param private_ctx pointer to the context
- * @return in success the function returns SR_ERR_OK otherwise it pass error
- */
-int sr_plugin_init_cb(sr_session_ctx_t *session, void **private_ctx);
-
-/**
- * @brief cleanup function for sysrepo,
- * In this function we connect to vpp from one side
- * and and unsubscribe for all hICN events as well as interface events (if any)
- * @param session pointer to the sesssion context
- * @param private_ctx pointer to the context
- */
-void sr_plugin_cleanup_cb(sr_session_ctx_t *session, void *private_ctx);
-
-#endif //__HICN_PLUGIN_H__ \ No newline at end of file
diff --git a/ctrl/sysrepo-plugins/hicn-plugin/plugin/hicn_vpp_comm.c b/ctrl/sysrepo-plugins/hicn-plugin/plugin/hicn_vpp_comm.c
deleted file mode 100644
index 73eab66ea..000000000
--- a/ctrl/sysrepo-plugins/hicn-plugin/plugin/hicn_vpp_comm.c
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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_vpp_comm.h"
-#include <vapi/vapi.h>
-
-#define APP_NAME "hicn_plugin"
-#define MAX_OUTSTANDING_REQUESTS 4
-#define RESPONSE_QUEUE_SIZE 2
-
-
-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,
- MAX_OUTSTANDING_REQUESTS, RESPONSE_QUEUE_SIZE,
- VAPI_MODE_BLOCKING, true);
- if (rv != VAPI_OK) {
- SRP_LOG_DBGMSG("Error connection");
- vapi_ctx_free(g_vapi_ctx_instance);
- return -1;
- }
- SRP_LOG_DBGMSG("*connected ok");
- } else {
- SRP_LOG_DBGMSG("connection keeping");
- }
- 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;
-} \ No newline at end of file
diff --git a/ctrl/sysrepo-plugins/hicn-plugin/plugin/hicn_vpp_comm.h b/ctrl/sysrepo-plugins/hicn-plugin/plugin/hicn_vpp_comm.h
deleted file mode 100644
index 9abe4e5d4..000000000
--- a/ctrl/sysrepo-plugins/hicn-plugin/plugin/hicn_vpp_comm.h
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * 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.
- */
-
-
-/**
- * @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>
-#include <sysrepo/values.h>
-#include <vapi/vapi.h>
-
-#ifndef HICN_THIS_FUNC
-#ifdef __FUNCTION__
-#define HICN_THIS_FUNC __FUNCTION__
-#else
-#define HICN_THIS_FUNC __func__
-#endif
-#endif
-
-/**
- * @brief This is the context to connect to the vpp
- */
-
-extern vapi_ctx_t g_vapi_ctx_instance;
-
-
-/**
- * @brief This macro is interface.c to communicate with vpp
- */
-#define VPP_INTFC_NAME_LEN 64
-#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
- */
-#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)
-
-/**
- * @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)
-
-/**
- * @brief This function is used to connect to the vpp
- */
-int hicn_connect_vpp();
-/**
- * @brief This function is used to close the connection of the vpp
- */
-int hicn_disconnect_vpp();
-
-#endif //__HICN_VPP_COMMM_H__
diff --git a/ctrl/sysrepo-plugins/hicn-plugin/plugin/ietf/ietf_interface.c b/ctrl/sysrepo-plugins/hicn-plugin/plugin/ietf/ietf_interface.c
deleted file mode 100644
index 3e0c90cf9..000000000
--- a/ctrl/sysrepo-plugins/hicn-plugin/plugin/ietf/ietf_interface.c
+++ /dev/null
@@ -1,607 +0,0 @@
-/*
- * Copyright (c) 2016-2020 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 <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-#include <sysrepo.h>
-#include <sysrepo/values.h>
-#include <sysrepo/xpath.h>
-#include <vnet/interface.h>
-#include <vnet/vnet.h>
-#include <vnet/ip/ip.h>
-#include <vapi/interface.api.vapi.h>
-
-#include "ietf_interface.h"
-#include "../hicn_vpp_comm.h"
-
-
-DEFINE_VAPI_MSG_IDS_INTERFACE_API_JSON;
-
-typedef struct hicn_interface_
-{
- u32 sw_if_index;
- char interface_name[VPP_INTFC_NAME_LEN];
- u8 l2_address[VPP_MAC_ADDRESS_LEN];
- u64 link_speed;
- u32 flags;
- u16 link_mtu;
- u8 admin_up_down;
- u8 link_up_down;
-} hicnIntfc;
-
-typedef struct _ietf_sw_interface_dump_ctx
-{
- u8 last_called;
- int num_ifs;
- int capacity;
- 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_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);
-
-/**
- * @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;
-
- inet_pton(AF_INET, netmask, &n);
-
- while (n > 0) {
- n = n >> 1;
- i++;
- }
-
- return i;
-}
-
-/**
- * @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));
- }
- }
-
- 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;
- }
-
- /* 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_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.
- */
-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;
- }
-
- /* 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);
- }
- sr_free_change_iter(iter);
-
- 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;
- }
-
- /* 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;
-
- dctx->intfcArray = NULL;
- dctx->last_called = false;
- dctx->capacity = 0;
- 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);
- }
-
- 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)
-{
- ietf_sw_interface_dump_ctx *dctx = callback_ctx;
- 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 );
- }
-
- 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;
-#define ONE_MEGABIT (uint64_t)1000000
- 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;
-
- dctx->num_ifs += 1;
- }
- return VAPI_OK;
-}
-
-static i32 ietf_interface_name2index(const char *name, u32* if_index)
-{
- ARG_CHECK2(-1, name, if_index);
-
- i32 ret = -1;
- ietf_sw_interface_dump_ctx dctx = {false, 0, 0, 0};
- vapi_msg_sw_interface_dump *dump;
- vapi_error_e rv;
- dctx.last_called = false;
-
- dump = vapi_alloc_sw_interface_dump(g_vapi_ctx_instance);
- 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)))
- ;
-
- int i = 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;
- }
- }
- ietf_freeSwInterfaceDumpCTX(&dctx);
-
- 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 ret = -1;
- 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;
- msg->payload.del_all = del_all;
- 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){
- SRP_LOG_DBGMSG("Operation failed");
- return SR_ERR_OPERATION_FAILED;
- }
-
- return ret;
-}
-
-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);
- msg->payload.sw_if_index = sw_if_index;
- 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){
- 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);
- }
-
- /* 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".
- */
-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);
-
- /* 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;
- }
- if (SR_ERR_INVAL_ARG == op_rc) {
- sr_set_error(session, "Invalid interface name.", new_val ? new_val->xpath : old_val->xpath);
- }
- free(if_name);
- sr_free_val(old_val);
- sr_free_val(new_val);
- }
- sr_free_change_iter(iter);
-
- 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.
- */
-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;
- }
-
- //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:
- 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
deleted file mode 100644
index 0f6c7f8b4..000000000
--- a/ctrl/sysrepo-plugins/hicn-plugin/plugin/ietf/ietf_interface.h
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Copyright (c) 2018 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:
- *
- * 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_INTERFACE_H__
-#define __IETF_INTERFACE_H__
-
-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/mainpage.dox b/ctrl/sysrepo-plugins/hicn-plugin/plugin/mainpage.dox
deleted file mode 100644
index 978578039..000000000
--- a/ctrl/sysrepo-plugins/hicn-plugin/plugin/mainpage.dox
+++ /dev/null
@@ -1,211 +0,0 @@
-/** @mainpage About hICN sysrepo plugin
-*This plugin serves as a data management agent. It provides yang models via
-*NETCONF to allow the management of hicn-plugin which runs in VPP instance from out-of-box.
-
-*The following sections contain more details:
-*- @subpage subp1 "hICN yang model"
-*- @subpage subp2 "User Guide"
-*- @subpage subp3 "Developer Guide"
-*/
-
-/** @page subp1
-*hicn.yang consists of one container for providing the state data (i.e., hicn-state).
-*It consists of state, route, and face-ip-params
-*nodes with the corresponding leaves. In the hicn model a variety of RPCs are provided
-*to allow controller to communicate with the hicn-plugin as well as update the state
-*data in hicn-state. You can install the yang model using the following bash script:
-
-```
-EXIT_CODE=0
-command -v sysrepoctl > /dev/null
-if [ $? != 0 ]; then
- echo "Could not find command \"sysrepoctl\"."
- exit ${EXIT_CODE}
-else
-sysrepoctl --install path_to_hicn_yang_model
-fi
-```
-
-*Here you can find different examples to run RPC in the yang-model.
-
-```
-<hicn-enable xmlns="urn:sysrepo:hicn">
- <prefix>b001::/64</prefix>
-</hicn-enable>
-
-<hicn-disable xmlns="urn:sysrepo:hicn">
- <prefix>b001::/64</prefix>
-</hicn-disable>
-```
- */
-
-/** @page subp2
-
-*Firstly, verify the plugin and binary libraries are located correctly, then run
-*the vpp through (service vpp start). Next, run the sysrepo plugin (sysrepo-plugind),
-*for debug mode: sysrep-plugind -d -v 4 which
-*runs with high verbosity. When the hicn sysrepo plugin is loaded, run the
-*netopeer2-server which serves as NETCONF server.
-
-
-*## Connect from netopeer2-cli
-
-*In order to connect through the netopeer client run the netopeer2-cli. Then, follow these steps:
-```
-*- connect --host XXX --login XXX
-*- get (you can get the configuration and operational data)
-*- user-rpc (you can call one of the rpc proposed by hicn model but it needs an xml input)
-```
-
-*## Connect from OpenDaylight (ODL) controller
-
-
-*In order to connect through the OpenDaylight follow these procedure:
-
-*- run karaf distribution (./opendayligh_installation_folder/bin/karaf)
-*- install the required feature list in DOL (feature:install odl-netconf-server
-* odl-netconf-connector odl-restconf-all odl-netconf-topology or
-* odl-netconf-clustered-topology)
-*- run a rest client program (e.g., postman or RESTClient)
-*- mount the remote netopeer2-server to the OpenDaylight by the following REST API:
-
-*PUT http://localhost:8181/restconf/config/network-topology:network-topology/topology/topology-netconf/node/hicn-node
-
-* with the following body
-```
- <node xmlns="urn:TBD:params:xml:ns:yang:network-topology">
- <node-id>hicn-node</node-id>
- <host xmlns="urn:opendaylight:netconf-node-topology">Remote_NETCONF_SERVER_IP</host>
- <port xmlns="urn:opendaylight:netconf-node-topology">830</port>
- <username xmlns="urn:opendaylight:netconf-node-topology">username</username>
- <password xmlns="urn:opendaylight:netconf-node-topology">password</password>
- <tcp-only xmlns="urn:opendaylight:netconf-node-topology">false</tcp-only>
- <keepalive-delay xmlns="urn:opendaylight:netconf-node-topology">1</keepalive-delay>
- </node>
-```
-*Note that the header files must be set to Content-Type: application/xml, Accept: application/xml.
-
-*- send the operation through the following REST API:
-
-*POST http://localhost:8181/restconf/operations/network-topology:network-topology/topology/topology-netconf/node/hicn-node/yang-ext:mount/ietf-netconf:edit-config
-
-*The body can be used the same as edit-config in netopeer2-cli.
-
-*## Connect from Network Services Orchestrator (NSO)
-
-*To connect NSO to the netopeer2-server, first, you need to write a NED package
-*for your device. The procedure to create NED for hicn is explained in the following:
-
-*Place hicn.yang model in a folder called hicn-yang-model, and follow these steps:
-
-*- ncs-make-package --netconf-ned ./hicn-yang-model ./hicn-nso
-*- cd hicn-nso/src; make
-*- ncs-setup --ned-package ./hicn-nso --dest ./hicn-nso-project
-*- cd hicn-nso-project
-*- ncs
-*- ncs_cli -C -u admin
-*- configure
-*- devices authgroups group authhicn default-map remote-name user_name remote-password password
-*- devices device hicn address IP_device port 830 authgroup authhicn device-type netconf
-*- state admin-state unlocked
-*- commit
-*- ssh fetch-host-keys
-
-
-*At this point, we are able to connect to the remote device.
-
-
- */
-
- /** @page subp3
-
-*This guide contains information intended for developers that need to extend/modify the hICN yang model.
-
-*# Adding configuration data
-*In order to add configuration data, firstly it requires to update yang model and define the configuration paramters
-*through a container and define the leaves. Once the yang model is updated in the sysrepo plugin you need to subscribe
-*for ```sr_module_change_subscribe``` and provide the appropriate callback.
-*
-*
-*# Adding new RPC
-*
-*In order to add RPC call, firstly it requires to update the yang model by new ```rpc``` statements and define the input to them.
-
-
-*# Adding new operational data
-*
-*In order to add operational data, firstly it requires to add operational data in yang model by adding ```confg false``` to the container.
-*Then, update the sysrepo plugin by the adding the ```sr_oper_get_items_subscribe```.
-
- Example:
-I have a switch with two ports. I am going to write an RPC call to switch them on/off
-, moreover I need to read operational data from each port. So, the following yang model can be proposed:
-
-```
-module switch {
-namespace "urn:sysrepo:switch";
-prefix swtch;
-
-revision 2019-12-08{
- description "Initial revision.";
-}
-
-
-grouping status-reply{
- list port{
- key portid;
- leaf portid {
- description "the port id.";
- type uint32;
- }
- leaf status {
- description "the status of the port.";
- type boolean;
- }
-
-}
-}
-
-rpc power {
- description "Operation to power on/off switch.";
- input {
- leaf turned-on {
- description "indicating on or off.";
- type boolean;
- default false;
- }
- }
-}
-
-
-container switch-state {
-
- config false;
- description "operational data container for the switch.";
- container status{
- uses status-reply;
- }
-```
-Afterwards, the following subscribes are required in the sysrepo plugin.
-
-```
-sr_rpc_subscribe(session, "/switch:power", callback,
- session, 100,SR_SUBSCR_CTX_REUSE, subscription);
-
-```
-
-session is the opened session with sysrepo, xpath is the path in the yang model, callback is the function
-when RPC arrives, private context passed to the callback function, priprity which is set to 100 here indicates the priority if there re multiple RPCs,
-options can alter the normal behaviour, and subscription is the subscribtion when initialize the connection towards the sysrepo
-
-
-```
- rc = sr_oper_get_items_subscribe(session, "switch","/switch:switch-state/status",
- callback, NULL, SR_SUBSCR_CTX_REUSE,
- subscription);
-```
-session is the opened session with sysrepo, xpath is the path in the yang model, callback is the function
-when RPC arrives, private context passed to the callback which is NULL here,
-options can alter the normal behaviour, and subscription is the subscribtion when initialize the connection towards the sysrepo
-
-*/ \ No newline at end of file
diff --git a/ctrl/sysrepo-plugins/hicn-plugin/plugin/model/hicn_model.c b/ctrl/sysrepo-plugins/hicn-plugin/plugin/model/hicn_model.c
deleted file mode 100644
index 63685e10a..000000000
--- a/ctrl/sysrepo-plugins/hicn-plugin/plugin/model/hicn_model.c
+++ /dev/null
@@ -1,875 +0,0 @@
-/*
- * Copyright (c) 2019-2020 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.c
- * @brief This file contains implementations of the main calls
- */
-
-#define _GNU_SOURCE
-
-#include <inttypes.h>
-#include <malloc.h>
-#include <pthread.h>
-#include <sched.h>
-#include <stdio.h>
-#include <string.h>
-#include <sysrepo/xpath.h>
-#include <unistd.h>
-/* Hicn headers */
-
-#include <hicn/util/ip_address.h>
-
-#include "../hicn_plugin.h"
-#include "../hicn_vpp_comm.h"
-#include "hicn_model.h"
-#include "tlock.h"
-
-DEFINE_VAPI_MSG_IDS_HICN_API_JSON
-
-// Shared local variables between state and RPCs
-
-/**
- * @brief this shared variable keeps the hicn state
- */
-volatile hicn_state_t *hicn_state = NULL;
-/**
- * @brief this shared variable keeps hicn strategies
- */
-volatile hicn_strategies_t *hicn_strategies = NULL;
-/**
- * @brief this shared variable keeps statistics of hicn faces
- */
-volatile hicn_faces_t *hicn_faces = NULL;
-/**
- * @brief this shared variable keeps routes information in hicn
- */
-volatile hicn_routes_t *hicn_routes = NULL;
-/**
- * @brief this shared variable is the link list to maintain all the faces (up to
- * MAX_FACES)
- */
-struct hicn_faces_s *fcurrent = NULL;
-/**
- * @brief this shared variable is the link list to maintain all the routes
- */
-struct hicn_routes_s *rcurrent = NULL;
-
-static int init_buffer(void) {
- hicn_state = memalign(MEM_ALIGN, sizeof(hicn_state_t));
- memset((hicn_state_t *)hicn_state, 0, sizeof(hicn_state_t));
-
- hicn_strategies = memalign(MEM_ALIGN, sizeof(hicn_strategies_t));
- memset((hicn_strategies_t *)hicn_strategies, 0, sizeof(hicn_strategies_t));
-
- hicn_faces = memalign(MEM_ALIGN, sizeof(hicn_faces_t));
- hicn_faces->next = memalign(MEM_ALIGN, sizeof(struct hicn_faces_s));
- fcurrent = hicn_faces->next;
-
- hicn_routes = memalign(MEM_ALIGN, sizeof(hicn_routes_t));
- hicn_routes->next = memalign(MEM_ALIGN, sizeof(struct hicn_routes_s));
- rcurrent = hicn_routes->next;
-
- int retval = -1;
- ARG_CHECK5(retval, hicn_state, hicn_strategies, fcurrent, hicn_faces,
- hicn_routes);
- hicn_routes->nroute = 0;
- hicn_faces->nface = 0;
- retval = 0;
-
- return retval;
-}
-
-static int init_face_pool(struct hicn_faces_s *head) {
- for (int i = 0; i < MAX_FACE_POOL; i++) {
- head->next = memalign(MEM_ALIGN, sizeof(struct hicn_faces_s));
- head = head->next;
- }
- SRP_LOG_DBGMSG("Face memory pool allocated\n");
- head->next = NULL;
- return 0;
-}
-
-static int init_route_pool(struct hicn_routes_s *head) {
- for (int i = 0; i < MAX_ROUTE_POOL; i++) {
- head->next = memalign(MEM_ALIGN, sizeof(struct hicn_routes_s));
- head = head->next;
- }
- SRP_LOG_DBGMSG("Route memory pool allocated\n");
- head->next = NULL;
- return 0;
-}
-
-/* VAPI CALLBACKS */
-
-static vapi_error_e call_hicn_api_strategies_get(
- struct vapi_ctx_s *ctx, void *callback_ctx, vapi_error_e rv, bool is_last,
- vapi_payload_hicn_api_strategies_get_reply *reply) {
- if (!reply->retval) {
- SRP_LOG_DBGMSG("Successfully done");
- return VAPI_OK;
- } else
- return VAPI_EUSER;
-}
-
-static vapi_error_e call_hicn_api_face_params_get(
- struct vapi_ctx_s *ctx, void *callback_ctx, vapi_error_e rv, bool is_last,
- vapi_payload_hicn_api_face_params_get_reply *reply) {
- if (!reply->retval) {
- if (callback_ctx != NULL) {
- struct hicn_faces_s *tmp;
- tmp = (struct hicn_faces_s *)callback_ctx;
- tmp->face.intfc = reply->swif;
- }
- return VAPI_OK;
- } else
- return VAPI_EUSER;
-}
-
-static vapi_error_e call_vapi_hicn_api_node_stats_get(
- struct vapi_ctx_s *ctx, void *callback_ctx, vapi_error_e rv, bool is_last,
- vapi_payload_hicn_api_node_stats_get_reply *reply) {
- if (!reply->retval) {
- hicn_state->pkts_processed = reply->pkts_processed;
- hicn_state->pkts_interest_count = reply->pkts_interest_count;
- hicn_state->pkts_data_count = reply->pkts_data_count;
- hicn_state->pkts_from_cache_count = reply->pkts_from_cache_count;
- hicn_state->pkts_no_pit_count = reply->pkts_no_pit_count;
- hicn_state->pit_expired_count = reply->pit_expired_count;
- hicn_state->cs_expired_count = reply->cs_expired_count;
- hicn_state->cs_lru_count = reply->cs_lru_count;
- hicn_state->pkts_drop_no_buf = reply->pkts_drop_no_buf;
- hicn_state->interests_aggregated = reply->interests_aggregated;
- hicn_state->interests_retx = reply->interests_retx;
- hicn_state->pit_entries_count = reply->pit_entries_count;
- hicn_state->cs_entries_count = reply->cs_entries_count;
- hicn_state->cs_entries_ntw_count = reply->cs_entries_ntw_count;
- return VAPI_OK;
- } else
- return VAPI_EUSER;
-}
-
-static inline void state_update(sr_val_t *vals, struct lyd_node **parent,
- sr_session_ctx_t *session) {
- char buf[20];
-
- sr_val_set_xpath(&vals[0], "/hicn:hicn-state/states/pkts_processed");
- vals[0].type = SR_UINT64_T;
- vals[0].data.uint64_val = hicn_state->pkts_processed;
- memset(buf, 0x00, 20);
- sprintf(buf, "%" PRIu64, hicn_state->pkts_processed);
- *parent =
- lyd_new_path(NULL, sr_get_context(sr_session_get_connection(session)),
- vals[0].xpath, buf, 0, 0);
-
- sr_val_set_xpath(&vals[1], "/hicn:hicn-state/states/pkts_interest_count");
- vals[1].type = SR_UINT64_T;
- vals[1].data.uint64_val = hicn_state->pkts_interest_count;
- memset(buf, 0x00, 20);
- sprintf(buf, "%" PRIu64, hicn_state->pkts_interest_count);
- lyd_new_path(*parent, NULL, vals[1].xpath, buf, 0, 0);
-
- sr_val_set_xpath(&vals[2], "/hicn:hicn-state/states/pkts_data_count");
- vals[2].type = SR_UINT64_T;
- vals[2].data.uint64_val = hicn_state->pkts_data_count;
- memset(buf, 0x00, 20);
- sprintf(buf, "%" PRIu64, hicn_state->pkts_data_count);
- lyd_new_path(*parent, NULL, vals[2].xpath, buf, 0, 0);
-
- sr_val_set_xpath(&vals[3], "/hicn:hicn-state/states/pkts_from_cache_count");
- vals[3].type = SR_UINT64_T;
- vals[3].data.uint64_val = hicn_state->pkts_from_cache_count;
- memset(buf, 0x00, 20);
- sprintf(buf, "%" PRIu64, hicn_state->pkts_from_cache_count);
- lyd_new_path(*parent, NULL, vals[3].xpath, buf, 0, 0);
-
- sr_val_set_xpath(&vals[4], "/hicn:hicn-state/states/pkts_no_pit_count");
- vals[4].type = SR_UINT64_T;
- vals[4].data.uint64_val = hicn_state->pkts_no_pit_count;
- memset(buf, 0x00, 20);
- sprintf(buf, "%" PRIu64, hicn_state->pkts_no_pit_count);
- lyd_new_path(*parent, NULL, vals[4].xpath, buf, 0, 0);
-
- sr_val_set_xpath(&vals[5], "/hicn:hicn-state/states/pit_expired_count");
- vals[5].type = SR_UINT64_T;
- vals[5].data.uint64_val = hicn_state->pit_expired_count;
- memset(buf, 0x00, 20);
- sprintf(buf, "%" PRIu64, hicn_state->pit_expired_count);
- lyd_new_path(*parent, NULL, vals[5].xpath, buf, 0, 0);
-
- sr_val_set_xpath(&vals[6], "/hicn:hicn-state/states/cs_expired_count");
- vals[6].type = SR_UINT64_T;
- vals[6].data.uint64_val = hicn_state->cs_expired_count;
- memset(buf, 0x00, 20);
- sprintf(buf, "%" PRIu64, hicn_state->cs_expired_count);
- lyd_new_path(*parent, NULL, vals[6].xpath, buf, 0, 0);
-
- sr_val_set_xpath(&vals[7], "/hicn:hicn-state/states/cs_lru_count");
- vals[7].type = SR_UINT64_T;
- vals[7].data.uint64_val = hicn_state->cs_lru_count;
- memset(buf, 0x00, 20);
- sprintf(buf, "%" PRIu64, hicn_state->cs_lru_count);
- lyd_new_path(*parent, NULL, vals[7].xpath, buf, 0, 0);
-
- sr_val_set_xpath(&vals[8], "/hicn:hicn-state/states/pkts_drop_no_buf");
- vals[8].type = SR_UINT64_T;
- vals[8].data.uint64_val = hicn_state->pkts_drop_no_buf;
- memset(buf, 0x00, 20);
- sprintf(buf, "%" PRIu64, hicn_state->pkts_drop_no_buf);
- lyd_new_path(*parent, NULL, vals[8].xpath, buf, 0, 0);
-
- sr_val_set_xpath(&vals[9], "/hicn:hicn-state/states/interests_aggregated");
- vals[9].type = SR_UINT64_T;
- vals[9].data.uint64_val = hicn_state->interests_aggregated;
- memset(buf, 0x00, 20);
- sprintf(buf, "%" PRIu64, hicn_state->interests_aggregated);
- lyd_new_path(*parent, NULL, vals[9].xpath, buf, 0, 0);
-
- sr_val_set_xpath(&vals[10], "/hicn:hicn-state/states/interests_retx");
- vals[10].type = SR_UINT64_T;
- vals[10].data.uint64_val = hicn_state->interests_retx;
- memset(buf, 0x00, 20);
- sprintf(buf, "%" PRIu64, hicn_state->interests_retx);
- lyd_new_path(*parent, NULL, vals[10].xpath, buf, 0, 0);
-
- sr_val_set_xpath(&vals[11],
- "/hicn:hicn-state/states/interests_hash_collision");
- vals[11].type = SR_UINT64_T;
- vals[11].data.uint64_val = hicn_state->interests_hash_collision;
- memset(buf, 0x00, 20);
- sprintf(buf, "%" PRIu64, hicn_state->interests_hash_collision);
- lyd_new_path(*parent, NULL, vals[11].xpath, buf, 0, 0);
-
- sr_val_set_xpath(&vals[12], "/hicn:hicn-state/states/pit_entries_count");
- vals[12].type = SR_UINT64_T;
- vals[12].data.uint64_val = hicn_state->pit_entries_count;
- memset(buf, 0x00, 20);
- sprintf(buf, "%" PRIu64, hicn_state->pit_entries_count);
- lyd_new_path(*parent, NULL, vals[12].xpath, buf, 0, 0);
-
- sr_val_set_xpath(&vals[13], "/hicn:hicn-state/states/cs_entries_count");
- vals[13].type = SR_UINT64_T;
- vals[13].data.uint64_val = hicn_state->cs_entries_count;
- memset(buf, 0x00, 20);
- sprintf(buf, "%" PRIu64, hicn_state->cs_entries_count);
- lyd_new_path(*parent, NULL, vals[13].xpath, buf, 0, 0);
-
- sr_val_set_xpath(&vals[14], "/hicn:hicn-state/states/cs_entries_ntw_count");
- vals[14].type = SR_UINT64_T;
- vals[14].data.uint64_val = hicn_state->cs_entries_ntw_count;
- memset(buf, 0x00, 20);
- sprintf(buf, "%" PRIu64, hicn_state->cs_entries_ntw_count);
- lyd_new_path(*parent, NULL, vals[14].xpath, buf, 0, 0);
-}
-
-static inline int routes_update(sr_val_t *vals, uint32_t nleaves,
- struct lyd_node **parent,
- sr_session_ctx_t *session) {
- struct hicn_routes_s *temp = hicn_routes->next;
- char buf[20];
- int route = 0;
- for (int count = 0; count < nleaves; count++) {
- sr_val_build_xpath(&vals[route], "%s[routeid='%d']/prefix",
- "/hicn:hicn-state/routes/route", temp->route.route_id);
- vals[route].type = SR_STRING_T;
-
- memset(buf, 0x00, 20);
- if (temp->route.prefix.address.af == ADDRESS_IP4) {
- struct sockaddr_in sa;
- memcpy(&sa.sin_addr.s_addr, temp->route.prefix.address.un.ip4,
- IPV4_ADDR_LEN);
- inet_ntop(AF_INET, &(sa.sin_addr), buf, INET_ADDRSTRLEN);
- vals[route].data.string_val = buf;
- } else {
- struct sockaddr_in6 sa;
- memcpy(&sa.sin6_addr, temp->route.prefix.address.un.ip6, IPV6_ADDR_LEN);
- inet_ntop(AF_INET6, &(sa.sin6_addr), buf, INET6_ADDRSTRLEN);
- vals[route].data.string_val = buf;
- }
-
- lyd_new_path(*parent, NULL, vals[route].xpath, buf, 0, 0);
-
- route++;
-
- sr_val_build_xpath(&vals[route], "%s[routeid='%d']/strategy_id",
- "/hicn:hicn-state/routes/route", temp->route.route_id);
- vals[route].type = SR_UINT32_T;
- vals[route].data.uint32_val = temp->route.strategy_id;
- memset(buf, 0x00, 20);
- sprintf(buf, "%d", temp->route.strategy_id);
- lyd_new_path(*parent, NULL, vals[route].xpath, buf, 0, 0);
-
- route++;
-
- temp = temp->next;
- }
-
- SRP_LOG_DBGMSG("Routes state updated \n");
- return SR_ERR_OK;
-}
-
-static inline int faces_update(sr_val_t *vals, uint32_t nleaves,
- struct lyd_node **parent,
- sr_session_ctx_t *session) {
- struct hicn_faces_s *temp = hicn_faces->next;
- char buf[20];
- int face = 0;
-
- for (int count = 0; count < nleaves; count++) {
- vapi_msg_hicn_api_face_params_get *msg;
- msg = vapi_alloc_hicn_api_face_params_get(g_vapi_ctx_instance);
-
- msg->payload.faceid = temp->face.faceid;
-
- if (vapi_hicn_api_face_params_get(g_vapi_ctx_instance, msg,
- call_hicn_api_face_params_get,
- (void *)temp) != VAPI_OK) {
- SRP_LOG_DBGMSG("Operation failed");
- return SR_ERR_OPERATION_FAILED;
- }
-
- sr_val_build_xpath(&vals[face], "%s[faceid='%d']/intfc",
- "/hicn:hicn-state/faces/face", temp->face.faceid);
- vals[face].type = SR_UINT32_T;
- vals[face].data.uint32_val = temp->face.intfc;
- memset(buf, 0x00, 20);
- sprintf(buf, "%u", temp->face.intfc);
- lyd_new_path(*parent, NULL, vals[face].xpath, buf, 0, 0);
-
- face++;
-
- sr_val_build_xpath(&vals[face], "%s[faceid='%d']/irx_packets",
- "/hicn:hicn-state/faces/face", temp->face.faceid);
- vals[face].type = SR_UINT64_T;
- vals[face].data.uint64_val = temp->face.irx_packets;
- memset(buf, 0x00, 20);
- sprintf(buf, "%" PRIu64, temp->face.irx_packets);
- lyd_new_path(*parent, NULL, vals[face].xpath, buf, 0, 0);
-
- face++;
-
- sr_val_build_xpath(&vals[face], "%s[faceid='%d']/irx_bytes",
- "/hicn:hicn-state/faces/face", temp->face.faceid);
- vals[face].type = SR_UINT64_T;
- vals[face].data.uint64_val = temp->face.irx_bytes;
- memset(buf, 0x00, 20);
- sprintf(buf, "%" PRIu64, temp->face.irx_bytes);
- lyd_new_path(*parent, NULL, vals[face].xpath, buf, 0, 0);
-
- face++;
-
- sr_val_build_xpath(&vals[face], "%s[faceid='%d']/itx_packets",
- "/hicn:hicn-state/faces/face", temp->face.faceid);
- vals[face].type = SR_UINT64_T;
- vals[face].data.uint64_val = temp->face.itx_packets;
- memset(buf, 0x00, 20);
- sprintf(buf, "%" PRIu64, temp->face.itx_packets);
- lyd_new_path(*parent, NULL, vals[face].xpath, buf, 0, 0);
-
- face++;
-
- sr_val_build_xpath(&vals[face], "%s[faceid='%d']/itx_bytes",
- "/hicn:hicn-state/faces/face", temp->face.faceid);
- vals[face].type = SR_UINT64_T;
- vals[face].data.uint64_val = temp->face.itx_bytes;
- memset(buf, 0x00, 20);
- sprintf(buf, "%" PRIu64, temp->face.itx_bytes);
- lyd_new_path(*parent, NULL, vals[face].xpath, buf, 0, 0);
-
- face++;
-
- sr_val_build_xpath(&vals[face], "%s[faceid='%d']/drx_packets",
- "/hicn:hicn-state/faces/face", temp->face.faceid);
- vals[face].type = SR_UINT64_T;
- vals[face].data.uint64_val = temp->face.drx_packets;
- memset(buf, 0x00, 20);
- sprintf(buf, "%" PRIu64, temp->face.drx_packets);
- lyd_new_path(*parent, NULL, vals[face].xpath, buf, 0, 0);
-
- face++;
-
- sr_val_build_xpath(&vals[face], "%s[faceid='%d']/drx_bytes",
- "/hicn:hicn-state/faces/face", temp->face.faceid);
- vals[face].type = SR_UINT64_T;
- vals[face].data.uint64_val = temp->face.drx_bytes;
- memset(buf, 0x00, 20);
- sprintf(buf, "%" PRIu64, temp->face.drx_packets);
- lyd_new_path(*parent, NULL, vals[face].xpath, buf, 0, 0);
-
- face++;
-
- sr_val_build_xpath(&vals[face], "%s[faceid='%d']/dtx_packets",
- "/hicn:hicn-state/faces/face", temp->face.faceid);
- vals[face].type = SR_UINT64_T;
- vals[face].data.uint64_val = temp->face.dtx_packets;
- memset(buf, 0x00, 20);
- sprintf(buf, "%" PRIu64, temp->face.dtx_packets);
- lyd_new_path(*parent, NULL, vals[face].xpath, buf, 0, 0);
-
- face++;
-
- sr_val_build_xpath(&vals[face], "%s[faceid='%d']/dtx_bytes",
- "/hicn:hicn-state/faces/face", temp->face.faceid);
- vals[face].type = SR_UINT64_T;
- vals[face].data.uint64_val = temp->face.dtx_bytes;
- memset(buf, 0x00, 20);
- sprintf(buf, "%" PRIu64, temp->face.dtx_bytes);
- lyd_new_path(*parent, NULL, vals[face].xpath, buf, 0, 0);
-
- face++;
-
- temp = temp->next;
- }
- SRP_LOG_DBGMSG("Faces state updated \n");
- return SR_ERR_OK;
-}
-
-static int hicn_state_states_cb(sr_session_ctx_t *session,
- const char *module_name, const char *path,
- const char *request_xpath, uint32_t request_id,
- struct lyd_node **parent, void *private_data) {
- sr_val_t *vals;
- int rc;
- enum locks_name state;
- state = lstate;
- SRP_LOG_DBGMSG("Requesting state data");
-
- rc = sr_new_values(NSTATE_LEAVES, &vals);
- if (SR_ERR_OK != rc) {
- return rc;
- }
-
- tlock(state);
- state_update(vals, parent, session);
- tunlock(state);
-
- return SR_ERR_OK;
-}
-
-static int hicn_state_route_cb(sr_session_ctx_t *session,
- const char *module_name, const char *path,
- const char *request_xpath, uint32_t request_id,
- struct lyd_node **parent, void *private_data) {
- sr_val_t *vals;
- int rc;
- enum locks_name route;
- route = lroute;
- uint32_t NROUTE_NODES = hicn_routes->nroute * ROUTES_CHILDREN;
-
- rc = sr_new_values(NROUTE_NODES, &vals);
- if (SR_ERR_OK != rc) {
- return rc;
- }
-
- tlock(route);
- routes_update(vals, NROUTE_NODES / ROUTES_CHILDREN, parent, session);
- tunlock(route);
-
- return SR_ERR_OK;
-}
-
-static int hicn_state_faces_cb(sr_session_ctx_t *session,
- const char *module_name, const char *path,
- const char *request_xpath, uint32_t request_id,
- struct lyd_node **parent, void *private_data) {
- sr_val_t *vals;
- int rc;
- enum locks_name faces;
- faces = lfaces;
- uint32_t NFACES_NODES = hicn_faces->nface * FACES_CHILDREN;
-
- rc = sr_new_values(NFACES_NODES, &vals);
- if (SR_ERR_OK != rc) {
- return rc;
- }
-
- tlock(faces);
- faces_update(vals, NFACES_NODES / FACES_CHILDREN, parent, session);
- tunlock(faces);
-
- return SR_ERR_OK;
-}
-
-static int hicn_strategies_get_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 strategies received successfully");
- vapi_msg_hicn_api_strategies_get *msg;
-
- msg = vapi_alloc_hicn_api_strategies_get(g_vapi_ctx_instance);
-
- if (vapi_hicn_api_strategies_get(g_vapi_ctx_instance, msg,
- call_hicn_api_strategies_get,
- NULL) != VAPI_OK) {
- SRP_LOG_DBGMSG("Operation failed");
- return SR_ERR_OPERATION_FAILED;
- }
- return SR_ERR_OK;
-}
-
-static int hicn_face_params_get_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 params get received successfully");
- vapi_msg_hicn_api_face_params_get *msg;
-
- msg = vapi_alloc_hicn_api_face_params_get(g_vapi_ctx_instance);
-
- msg->payload.faceid = input[0].data.uint32_val;
-
- if (vapi_hicn_api_face_params_get(g_vapi_ctx_instance, msg,
- call_hicn_api_face_params_get,
- NULL) != VAPI_OK) {
- SRP_LOG_DBGMSG("Operation failed");
- return SR_ERR_OPERATION_FAILED;
- }
-
- return SR_ERR_OK;
-}
-
-static vapi_error_e call_hicn_api_enable_disable(
- struct vapi_ctx_s *ctx, void *callback_ctx, vapi_error_e rv, bool is_last,
- vapi_payload_hicn_api_enable_disable_reply *reply) {
- if (!reply->retval) {
- SRP_LOG_DBGMSG("Successfully done");
- return VAPI_OK;
- } else
- return VAPI_EUSER;
-}
-
-static int hicn_enable_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 enable received successfully");
- vapi_msg_hicn_api_enable_disable *msg;
-
- msg = vapi_alloc_hicn_api_enable_disable(g_vapi_ctx_instance);
-
- const char *delim = "/";
- if (input->type != SR_STRING_T) {
- SRP_LOG_DBGMSG("Expected prefix of type string");
- return SR_ERR_OPERATION_FAILED;
- }
- char *token;
-
- /* get the first token */
- token = strtok(input->data.string_val, delim);
-
- /* if null the address is ipv4 else ipv6*/
- if (strrchr(token, ':') == NULL) {
- struct sockaddr_in sa;
- inet_pton(AF_INET, token, &(sa.sin_addr));
- unsigned char *tmp = (unsigned char *)&sa.sin_addr.s_addr;
- memcpy(&msg->payload.prefix.address.un.ip4[0], tmp, B32);
- msg->payload.prefix.address.af = ADDRESS_IP4;
- } else {
- void *dst = malloc(sizeof(struct in6_addr));
- inet_pton(AF_INET6, token, dst);
- unsigned char *tmp = (unsigned char *)((struct in6_addr *)dst)->s6_addr;
- memcpy(&msg->payload.prefix.address.un.ip6[0], tmp, B128);
- msg->payload.prefix.address.af = ADDRESS_IP6;
- }
-
- /* The second token is the prefix len*/
- token = strtok(NULL, delim);
-
- msg->payload.prefix.len = atoi(token);
- msg->payload.enable_disable = 1;
-
- if (vapi_hicn_api_enable_disable(g_vapi_ctx_instance, msg,
- call_hicn_api_enable_disable,
- NULL) != VAPI_OK) {
- SRP_LOG_DBGMSG("Operation failed");
- return SR_ERR_OPERATION_FAILED;
- }
-
- return SR_ERR_OK;
-}
-
-static int hicn_disable_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 disable received successfully");
- vapi_msg_hicn_api_enable_disable *msg;
-
- msg = vapi_alloc_hicn_api_enable_disable(g_vapi_ctx_instance);
-
- const char *delim = "/";
- if (input->type != SR_STRING_T) {
- SRP_LOG_DBGMSG("Expected prefix of type string");
- return SR_ERR_OPERATION_FAILED;
- }
- char *token;
-
- /* get the first token */
- token = strtok(input->data.string_val, delim);
-
- /* if null the address is ipv4 else ipv6*/
- if (strrchr(token, ':') == NULL) {
- struct sockaddr_in sa;
- inet_pton(AF_INET, token, &(sa.sin_addr));
- unsigned char *tmp = (unsigned char *)&sa.sin_addr.s_addr;
- memcpy(&msg->payload.prefix.address.un.ip4[0], tmp, B32);
- msg->payload.prefix.address.af = ADDRESS_IP4;
- } else {
- void *dst = malloc(sizeof(struct in6_addr));
- inet_pton(AF_INET6, token, dst);
- unsigned char *tmp = (unsigned char *)((struct in6_addr *)dst)->s6_addr;
- memcpy(&msg->payload.prefix.address.un.ip6[0], tmp, B128);
- msg->payload.prefix.address.af = ADDRESS_IP6;
- }
-
- /* The second token is the prefix len*/
- token = strtok(NULL, delim);
-
- msg->payload.prefix.len = atoi(token);
- msg->payload.enable_disable = 0;
-
- if (vapi_hicn_api_enable_disable(g_vapi_ctx_instance, msg,
- call_hicn_api_enable_disable,
- NULL) != VAPI_OK) {
- SRP_LOG_DBGMSG("Operation failed");
- return SR_ERR_OPERATION_FAILED;
- }
-
- return SR_ERR_OK;
-}
-
-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) {
- static int counter = 0;
-
- tlock(lroute);
- if (reply != NULL) {
- rcurrent->route.route_id = counter;
- rcurrent->route.prefix = reply->prefix;
- rcurrent->route.nfaces = reply->nfaces;
- rcurrent->route.strategy_id = reply->strategy_id;
- for (int cnt = 0; cnt < rcurrent->route.nfaces; cnt++)
- rcurrent->route.faceids[cnt] = rcurrent->route.faceids[cnt];
-
- counter++;
- rcurrent = rcurrent->next;
-
- SRP_LOG_DBG("nfaces %d", reply->nfaces);
- SRP_LOG_DBG("strategy_id %d", reply->strategy_id);
-
- } else {
- SRP_LOG_DBGMSG("---------Routes------- \n");
- hicn_routes->nroute = counter;
- counter = 0;
- rcurrent = hicn_routes->next;
- }
- tunlock(lroute);
- return SR_ERR_OK;
-}
-
-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) {
- static int counter = 0;
-
- tlock(lfaces);
- if (reply != NULL) {
- fcurrent->face.faceid = reply->faceid;
- fcurrent->face.intfc = 1;
- fcurrent->face.irx_packets = reply->irx_packets;
- fcurrent->face.irx_bytes = reply->irx_bytes;
- fcurrent->face.itx_packets = reply->itx_packets;
- fcurrent->face.itx_bytes = reply->itx_bytes;
- fcurrent->face.drx_packets = reply->drx_packets;
- fcurrent->face.drx_bytes = reply->drx_bytes;
- fcurrent->face.dtx_packets = reply->dtx_packets;
- fcurrent->face.dtx_bytes = reply->dtx_bytes;
- counter++;
- fcurrent = fcurrent->next;
- SRP_LOG_DBG("faceid %d", reply->faceid);
- SRP_LOG_DBG("drxB %d", reply->drx_bytes);
- SRP_LOG_DBG("dtxB %d", reply->dtx_bytes);
-
- } else {
- SRP_LOG_DBGMSG("---------Faces------- \n");
- hicn_faces->nface = counter;
- counter = 0;
- fcurrent = hicn_faces->next;
- }
- tunlock(lfaces);
- return SR_ERR_OK;
-}
-
-static void *state_thread(void *arg) {
- // mapping can be retrieved by cpuinfo
- int map = 0;
- cpu_set_t cpuset;
- CPU_ZERO(&cpuset);
- CPU_SET(map, &cpuset);
-
- // pin the thread to a core
- if (pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset)) {
- SRP_LOG_DBGMSG("Thread pining failed\n");
- exit(1);
- }
-
- vapi_msg_hicn_api_node_stats_get *msg = NULL;
- enum locks_name state;
- state = lstate;
-
- while (true) {
- tlock(state);
- // dump faces
- 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, fcurrent);
-
- // dump routes
- 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, rcurrent);
-
- msg = vapi_alloc_hicn_api_node_stats_get(g_vapi_ctx_instance);
-
- if (vapi_hicn_api_node_stats_get(g_vapi_ctx_instance, msg,
- call_vapi_hicn_api_node_stats_get,
- NULL) != VAPI_OK) {
- SRP_LOG_DBGMSG(" State operation failed");
- }
-
- tunlock(state);
- sleep(1);
-
- SRP_LOG_DBGMSG("state cached");
- }
- return NULL;
-}
-
-int hicn_subscribe_events(sr_session_ctx_t *session,
- sr_subscription_ctx_t **subscription) {
- int rc = SR_ERR_OK;
- SRP_LOG_DBGMSG("Subscriging hicn.");
-
- // Initializing the locks
- for (int i = 0; i < NLOCKS; i++) ticket_init(i, LOCK_INIT);
-
- // Initializing the buffer
- rc = init_buffer();
- if (rc != SR_ERR_OK) {
- SRP_LOG_DBGMSG("Problem in initializing the buffers\n");
- goto error;
- }
-
- SRP_LOG_DBGMSG("buffer initialized successfully.");
-
- rc = init_face_pool(fcurrent);
- if (rc) {
- SRP_LOG_DBGMSG("Problem in initializing the pools\n");
- goto error;
- }
-
- rc = init_route_pool(rcurrent);
- if (rc) {
- SRP_LOG_DBGMSG("Problem in initializing the pools\n");
- goto error;
- }
-
- SRP_LOG_DBGMSG("pools created successfully.");
-
- // Create state thread observation
- pthread_t state_tid;
- rc = pthread_create((pthread_t *)&state_tid, NULL, state_thread, NULL);
- if (rc != 0) {
- SRP_LOG_DBGMSG("Error making hicn state thread");
- return SR_ERR_OPERATION_FAILED;
- }
- SRP_LOG_DBGMSG("State thread created successfully.");
-
- // strategies subscriptions
-
- rc = sr_rpc_subscribe(session, "/hicn:strategies-get", hicn_strategies_get_cb,
- session, 98, SR_SUBSCR_CTX_REUSE, subscription);
- if (rc != SR_ERR_OK) {
- SRP_LOG_DBGMSG("Problem in subscription strategies-get\n");
- goto error;
- }
-
- // face ip subscriptions
-
- rc = sr_rpc_subscribe(session, "/hicn:face-params-get",
- hicn_face_params_get_cb, session, 93,
- SR_SUBSCR_CTX_REUSE, subscription);
- if (rc != SR_ERR_OK) {
- SRP_LOG_DBGMSG("Problem in subscription face-params-get\n");
- goto error;
- }
-
- // hICN enable-disable subscriptions
-
- rc = sr_rpc_subscribe(session, "/hicn:hicn-enable", hicn_enable_cb, session,
- 94, SR_SUBSCR_CTX_REUSE, subscription);
- if (rc != SR_ERR_OK) {
- SRP_LOG_DBGMSG("Problem in subscription hicn-enable\n");
- goto error;
- }
-
- rc = sr_rpc_subscribe(session, "/hicn:hicn-disable", hicn_disable_cb, session,
- 95, SR_SUBSCR_CTX_REUSE, subscription);
- if (rc != SR_ERR_OK) {
- SRP_LOG_DBGMSG("Problem in subscription hicn-enable\n");
- goto error;
- }
-
- // subscribe as hicn state data provider
-
- rc = sr_oper_get_items_subscribe(session, "hicn", "/hicn:hicn-state/states",
- hicn_state_states_cb, NULL,
- SR_SUBSCR_CTX_REUSE, subscription);
- if (rc != SR_ERR_OK) {
- SRP_LOG_DBGMSG("Problem in subscription /hicn:hicn-state/states\n");
- goto error;
- }
-
- rc = sr_oper_get_items_subscribe(session, "hicn", "/hicn:hicn-state/routes",
- hicn_state_route_cb, NULL,
- SR_SUBSCR_CTX_REUSE, subscription);
- if (rc != SR_ERR_OK) {
- SRP_LOG_DBGMSG("Problem in subscription /hicn:hicn-state/routes\n");
- goto error;
- }
-
- rc = sr_oper_get_items_subscribe(session, "hicn", "/hicn:hicn-state/faces",
- hicn_state_faces_cb, NULL,
- SR_SUBSCR_CTX_REUSE, subscription);
- if (rc != SR_ERR_OK) {
- SRP_LOG_DBGMSG("Problem in subscription /hicn:hicn-state/faces\n");
- goto error;
- }
-
- SRP_LOG_DBGMSG("hicn plugin initialized successfully.\n");
- return SR_ERR_OK;
-
-error:
- SRP_LOG_ERRMSG("Error by initialization of the hicn plugin.");
- sr_plugin_cleanup_cb(session, &g_vapi_ctx_instance);
- return rc;
-}
diff --git a/ctrl/sysrepo-plugins/hicn-plugin/plugin/model/hicn_model.h b/ctrl/sysrepo-plugins/hicn-plugin/plugin/model/hicn_model.h
deleted file mode 100644
index 62fb15340..000000000
--- a/ctrl/sysrepo-plugins/hicn-plugin/plugin/model/hicn_model.h
+++ /dev/null
@@ -1,178 +0,0 @@
-/*
-* 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.
-*/
-
-/**
- * @file hicn_model.h
- * @brief This file contains main calls for hICN events coresponding to the hICN yang models
- */
-
-#ifndef __IETF_HICN_H__
-#define __IETF_HICN_H__
-
-#include "../hicn_vpp_comm.h"
-#include <vapi/hicn.api.vapi.h>
-
-/**
- * @brief Align memory to one page boundary
- */
-#define MEM_ALIGN 4096
-
-/**
- * @brief 32 bits = 4 bytes
- */
-#define B32 4
-/**
- * @brief 64bits = 8 bytes
- */
-#define B64 8
-/**
- * @brief 128 bits = 16 bytes
- */
-#define B128 16
-
-/**
- * @brief set number of lock to 5
- */
-#define NLOCKS 5
-
-/**
- * @brief initialize all locks by 0, better to initialize by 0 :)
- */
-#define LOCK_INIT 0
-
-/**
- * @brief enumeration for the locks
- */
-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
- */
-#define NSTATE_LEAVES 15
-/**
- * @brief This indicates the number of leaves for strategy
- */
-#define NSTRATEGY_LEAVES 1
-/**
- * @brief This indicates the number of leaves for strategies
- */
-#define NSTRATEGIES_LEAVES 2
-/**
- * @brief This indicates the maximum faces which can be read as operational data
- */
-#define MAX_FACE_POOL 100
-/**
- * @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*/
-/**
- * @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;
-} hicn_state_t;
-
-
-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;
-} hicn_face_inf_t;
-
-
-typedef struct __attribute__ ((__packed__)) {
- u32 route_id;
- vapi_type_prefix prefix;
- u32 faceids[5];
- u8 nfaces;
- u32 strategy_id;
-} hicn_route_inf_t;
-
-/**
- * @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;
-};
-
-
-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;
-};
-
-
-typedef struct __attribute__ ((__packed__)) {
- uint32_t nroute;
- struct hicn_routes_s * next;
-} hicn_routes_t;
-
-/**
- * @brief This function subscribes the hICN evens consisting of all RPCs
- * as well as operational data
- */
-int hicn_subscribe_events(sr_session_ctx_t *session,
- 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
deleted file mode 100644
index d27ae6492..000000000
--- a/ctrl/sysrepo-plugins/hicn-plugin/plugin/model/tlock.c
+++ /dev/null
@@ -1,21 +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 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]++;
-}
diff --git a/ctrl/sysrepo-plugins/hicn-plugin/plugin/model/tlock.h b/ctrl/sysrepo-plugins/hicn-plugin/plugin/model/tlock.h
deleted file mode 100644
index a871705a3..000000000
--- a/ctrl/sysrepo-plugins/hicn-plugin/plugin/model/tlock.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * 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.
- */
-
-
-
-/**
- * @file tlock.h
- * @brief This file contains ticket lock APIs.
- */
-
-#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
-
-/**
- * @brief Ticket lock counters
- */
-volatile long int En[MAX_LOCK_SIZE] ;
-
-/**
- * @brief Ticket lock counters
- */
-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 );
-/**
- * @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 );
-/**
- * @briefthis function release the lock
- * @param Lock_Number lock number
-
- */
-void tunlock(int Lock_Number );
-
-#endif /* __IETF_HICN_H__ */ \ No newline at end of file