From 3b2275f5570fc11f17301ccf080df21a6a0573a6 Mon Sep 17 00:00:00 2001 From: Andrej Kozemcak Date: Fri, 8 Mar 2019 13:52:16 +0100 Subject: Move sys_util files to plugins root directory Change-Id: I2c7041fd34a99ebbe8e7a20ce87da9f39e548458 Signed-off-by: Andrej Kozemcak --- src/plugins/CMakeLists.txt | 2 +- src/plugins/openconfig/openconfig_interfaces.c | 2 +- src/plugins/openconfig/openconfig_local_routing.c | 2 +- src/plugins/openconfig/sys_util.c | 83 ----------------------- src/plugins/openconfig/sys_util.h | 38 ----------- src/plugins/sys_util.c | 83 +++++++++++++++++++++++ src/plugins/sys_util.h | 37 ++++++++++ 7 files changed, 123 insertions(+), 124 deletions(-) delete mode 100644 src/plugins/openconfig/sys_util.c delete mode 100644 src/plugins/openconfig/sys_util.h create mode 100644 src/plugins/sys_util.c create mode 100644 src/plugins/sys_util.h diff --git a/src/plugins/CMakeLists.txt b/src/plugins/CMakeLists.txt index f9bc5ea..e8b69e7 100644 --- a/src/plugins/CMakeLists.txt +++ b/src/plugins/CMakeLists.txt @@ -46,10 +46,10 @@ endif() set(PLUGINS_SOURCES sc_plugins.c sc_model.c + sys_util.c ietf/ietf_interface.c openconfig/openconfig_interfaces.c openconfig/openconfig_local_routing.c - openconfig/sys_util.c ) # build the source code into shared library diff --git a/src/plugins/openconfig/openconfig_interfaces.c b/src/plugins/openconfig/openconfig_interfaces.c index 85339af..c72ad7f 100644 --- a/src/plugins/openconfig/openconfig_interfaces.c +++ b/src/plugins/openconfig/openconfig_interfaces.c @@ -18,7 +18,7 @@ #include #include "openconfig_interfaces.h" -#include "sys_util.h" +#include "../sys_util.h" #include "sc_vpp_comm.h" #include "sc_vpp_interface.h" diff --git a/src/plugins/openconfig/openconfig_local_routing.c b/src/plugins/openconfig/openconfig_local_routing.c index 39481e1..5c63eaa 100644 --- a/src/plugins/openconfig/openconfig_local_routing.c +++ b/src/plugins/openconfig/openconfig_local_routing.c @@ -19,7 +19,7 @@ #include "openconfig_local_routing.h" -#include "sys_util.h" +#include "../sys_util.h" #include "sc_vpp_comm.h" #include "sc_vpp_interface.h" diff --git a/src/plugins/openconfig/sys_util.c b/src/plugins/openconfig/sys_util.c deleted file mode 100644 index 1a0ee9b..0000000 --- a/src/plugins/openconfig/sys_util.c +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 2018 PANTHEON.tech. - * - * 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 "sys_util.h" -#include "sc_vpp_comm.h" - -#include -#include - -char* xpath_find_first_key(const char *xpath, char *key, sr_xpath_ctx_t *state) -{ - char *value = NULL; - - if (sr_xpath_next_node((char *)xpath, state) == NULL) { - return NULL; - } - - while (((value = sr_xpath_node_key_value(NULL, - key, state)) == NULL) && - (sr_xpath_next_node(NULL, state) != NULL)); - - return value; -} - -// we can call sr_get_item after change is called to see if the value has or has not -// changed (simpleton solution :D) -// sr_get_item(sess, "/ietf-interfaces:interfaces/interface[name='eth0']/enabled", &value); - -void log_recv_event(sr_notif_event_t event, const char *msg) { - const char *event_s; - switch (event) { - case SR_EV_VERIFY: event_s = "SR_EV_VERIFY"; break; - case SR_EV_APPLY: event_s = "SR_EV_APPLY"; break; - case SR_EV_ABORT: event_s = "SR_EV_ABORT"; break; - default: event_s = "SR_EV_UNKNOWN"; - } - SRP_LOG_DBG("%s: %s\n", msg, event_s); -} - -void log_recv_oper(sr_change_oper_t oper, const char *msg) { - const char *oper_s; - switch (oper) { - case SR_OP_CREATED: oper_s = "SR_OP_CREATED"; break; - case SR_OP_DELETED: oper_s = "SR_OP_DELETED"; break; - case SR_OP_MODIFIED: oper_s = "SR_OP_MODIFIED"; break; - case SR_OP_MOVED: oper_s = "SR_OP_MOVED"; break; - default: oper_s = "SR_OP_UNKNOWN"; break; - } - SRP_LOG_DBG("%s: %s\n", msg, oper_s); -} - -int ip_prefix_split(const char* ip_prefix) -{ - //find the slash - char* slash = strchr(ip_prefix, '/'); - if (NULL == slash) - return -1; - - //extract subnet mask length - char * eptr = NULL; - u8 mask = strtoul(slash + 1, &eptr, 10); - if (*eptr || mask <= 0) - return -1; - - //keep just the address part - *slash = '\0'; //replace '/' with 0 - - //return mask length - return mask; -} diff --git a/src/plugins/openconfig/sys_util.h b/src/plugins/openconfig/sys_util.h deleted file mode 100644 index d525066..0000000 --- a/src/plugins/openconfig/sys_util.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2018 PANTHEON.tech. - * - * 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 __SYS_UTIL_H__ -#define __SYS_UTIL_H__ - -#include -#include -#include - -#define XPATH_SIZE 2000 - -typedef struct -{ - char xpath_root[XPATH_SIZE]; - sr_val_t * values; - size_t values_cnt; -} sysr_values_ctx_t; - -char* xpath_find_first_key(const char *xpath, char *key, sr_xpath_ctx_t *state); -void log_recv_event(sr_notif_event_t event, const char *msg); -void log_recv_oper(sr_change_oper_t oper, const char *msg); -int ip_prefix_split(const char* ip_prefix); - -#endif /* __SYS_UTIL_H__ */ diff --git a/src/plugins/sys_util.c b/src/plugins/sys_util.c new file mode 100644 index 0000000..7bd0937 --- /dev/null +++ b/src/plugins/sys_util.c @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2018 PANTHEON.tech. + * + * 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 "sys_util.h" +#include "sc_vpp_comm.h" + +#include +#include + +char* xpath_find_first_key(const char *xpath, char *key, sr_xpath_ctx_t *state) +{ + char *value = NULL; + + if (sr_xpath_next_node((char *)xpath, state) == NULL) { + return NULL; + } + + while (((value = sr_xpath_node_key_value(NULL, + key, state)) == NULL) && + (sr_xpath_next_node(NULL, state) != NULL)); + + return value; +} + +// we can call sr_get_item after change is called to see if the value has or has not +// changed (simpleton solution :D) +// sr_get_item(sess, "/ietf-interfaces:interfaces/interface[name='eth0']/enabled", &value); + +void log_recv_event(sr_notif_event_t event, const char *msg) { + const char *event_s; + switch (event) { + case SR_EV_VERIFY: event_s = "SR_EV_VERIFY"; break; + case SR_EV_APPLY: event_s = "SR_EV_APPLY"; break; + case SR_EV_ABORT: event_s = "SR_EV_ABORT"; break; + default: event_s = "SR_EV_UNKNOWN"; + } + SRP_LOG_DBG("%s: %s\n", msg, event_s); +} + +void log_recv_oper(sr_change_oper_t oper, const char *msg) { + const char *oper_s; + switch (oper) { + case SR_OP_CREATED: oper_s = "SR_OP_CREATED"; break; + case SR_OP_DELETED: oper_s = "SR_OP_DELETED"; break; + case SR_OP_MODIFIED: oper_s = "SR_OP_MODIFIED"; break; + case SR_OP_MOVED: oper_s = "SR_OP_MOVED"; break; + default: oper_s = "SR_OP_UNKNOWN"; break; + } + SRP_LOG_DBG("%s: %s\n", msg, oper_s); +} + +int ip_prefix_split(const char* ip_prefix) +{ + //find the slash + char* slash = strchr(ip_prefix, '/'); + if (NULL == slash) + return -1; + + //extract subnet mask length + char * eptr = NULL; + u8 mask = strtoul(slash + 1, &eptr, 10); + if (*eptr || mask <= 0) + return -1; + + //keep just the address part + *slash = '\0'; //replace '/' with 0 + + //return mask length + return mask; +} diff --git a/src/plugins/sys_util.h b/src/plugins/sys_util.h new file mode 100644 index 0000000..6c227c3 --- /dev/null +++ b/src/plugins/sys_util.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2018 PANTHEON.tech. + * + * 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 __SYS_UTIL_H__ +#define __SYS_UTIL_H__ + +#include +#include + +#define XPATH_SIZE 2000 + +typedef struct +{ + char xpath_root[XPATH_SIZE]; + sr_val_t * values; + size_t values_cnt; +} sysr_values_ctx_t; + +char* xpath_find_first_key(const char *xpath, char *key, sr_xpath_ctx_t *state); +void log_recv_event(sr_notif_event_t event, const char *msg); +void log_recv_oper(sr_change_oper_t oper, const char *msg); +int ip_prefix_split(const char* ip_prefix); + +#endif /* __SYS_UTIL_H__ */ -- cgit 1.2.3-korg