aboutsummaryrefslogtreecommitdiffstats
path: root/src/scvpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/scvpp')
-rw-r--r--src/scvpp/CMakeLists.txt101
-rw-r--r--src/scvpp/inc/scvpp/comm.h245
-rw-r--r--src/scvpp/inc/scvpp/interface.h69
-rw-r--r--src/scvpp/inc/scvpp/ip.h77
-rw-r--r--src/scvpp/inc/scvpp/nat.h61
-rw-r--r--src/scvpp/inc/scvpp/v3po.h54
-rw-r--r--src/scvpp/libscvpp.pc.in10
-rw-r--r--src/scvpp/src/comm.c191
-rw-r--r--src/scvpp/src/interface.c182
-rw-r--r--src/scvpp/src/ip.c259
-rw-r--r--src/scvpp/src/nat.c294
-rw-r--r--src/scvpp/src/v3po.c89
-rw-r--r--src/scvpp/tests/CMakeLists.txt42
-rw-r--r--src/scvpp/tests/scvpp_iface_test.c130
-rw-r--r--src/scvpp/tests/scvpp_ip_test.c184
-rw-r--r--src/scvpp/tests/scvpp_nat_test.c173
-rw-r--r--src/scvpp/tests/scvpp_test.c109
-rw-r--r--src/scvpp/tests/scvpp_test.h31
18 files changed, 0 insertions, 2301 deletions
diff --git a/src/scvpp/CMakeLists.txt b/src/scvpp/CMakeLists.txt
deleted file mode 100644
index c0d7087..0000000
--- a/src/scvpp/CMakeLists.txt
+++ /dev/null
@@ -1,101 +0,0 @@
-#
-# Copyright (c) 2018 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.
-#
-
-cmake_minimum_required(VERSION 3.0)
-
-project(scvpp)
-
-set(PROJECT_VERSION "19.08")
-
-# COMPILER & LINKER
-###################
-
-# scvpp sources
-set(SCVPP_SOURCES
- src/comm.c
- src/interface.c
- src/ip.c
- src/v3po.c
- src/nat.c
-)
-
-# scvpp public headers
-set(SCVPP_HEADERS
- inc/scvpp/comm.h
- inc/scvpp/interface.h
- inc/scvpp/ip.h
- inc/scvpp/v3po.h
- inc/scvpp/nat.h
-)
-
-#define CMAKE_INSTALL_LIBDIR/INCLUDEDIR
-include(GNUInstallDirs)
-
-# Generate a compile_commands.json with compile options
-set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
-
-#set compiler and linker flags
-set(RIGOROUS_C_FLAGS "-Wlogical-op -Wformat=2")
-set(CMAKE_C_FLAGS "-Wall -Wextra -std=gnu99 ${RIGOROUS_C_FLAGS}")
-set(CMAKE_C_FLAGS_DEBUG "-Wall -Wextra -std=gnu99 -g -O0 ${RIGOROUS_C_FLAGS}")
-#NDEBUG to skip assert checks
-set(CMAKE_C_FLAGS_RELEASE "-Wall -Wextra -std=gnu99 -DNDEBUG -O2 ${RIGOROUS_C_FLAGS}")
-
-# libraries to link with
-set(LINK_LIBRARIES vlibmemoryclient vapiclient vppapiclient svm vppinfra pthread rt dl)
-
-# build instructions
-add_library(scvpp SHARED ${SCVPP_SOURCES})
-add_library(scvpp_a ${SCVPP_SOURCES})
-
-# linker instructions
-target_link_libraries(scvpp ${LINK_LIBRARIES})
-target_link_libraries(scvpp_a ${LINK_LIBRARIES})
-
-# to build shared and static library for scvpp, include project private directory inc before installing header file
-target_include_directories(scvpp PRIVATE inc)
-target_include_directories(scvpp_a PRIVATE inc)
-
-# TESTING
-#########
-
-# enable testing if requested and possible
-SET(ENABLE_TESTS 1 CACHE BOOL "Enable unit tests.")
-if(ENABLE_TESTS)
- find_package(CMOCKA)
- if(CMOCKA_FOUND)
- MESSAGE(STATUS "CMocka found, tests are enabled.")
- enable_testing()
- add_subdirectory(tests)
- else(CMOCKA_FOUND)
- MESSAGE(WARNING "CMocka not found, tests are disabled.")
- endif(CMOCKA_FOUND)
-endif(ENABLE_TESTS)
-
-
-# INSTALL
-#########
-
-# install rules
-install(TARGETS scvpp DESTINATION ${CMAKE_INSTALL_LIBDIR})
-install(FILES ${SCVPP_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/scvpp)
-
-find_package(PkgConfig QUIET) #QUIET disables message if not found
-if(PKG_CONFIG_FOUND)
- # generate and install pkg-config file
- configure_file("libscvpp.pc.in" "libscvpp.pc" @ONLY)
- install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libscvpp.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
-endif()
-
diff --git a/src/scvpp/inc/scvpp/comm.h b/src/scvpp/inc/scvpp/comm.h
deleted file mode 100644
index a7bac5d..0000000
--- a/src/scvpp/inc/scvpp/comm.h
+++ /dev/null
@@ -1,245 +0,0 @@
-/*
- * Copyright (c) 2018 HUACHENTEL and/or its affiliates.
- * 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 __SC_VPP_COMMM_H__
-#define __SC_VPP_COMMM_H__
-
-#include <errno.h>
-
-#include <vapi/vapi.h>
-#include <vapi/vapi_common.h>
-#include <vapi/vpe.api.vapi.h>
-
-typedef enum {
- SCVPP_OK = 0, /* Success */
- SCVPP_EINVAL, /* Invalid value encountered */
- SCVPP_EAGAIN, /* Operation would block */
- SCVPP_ENOTSUP, /* Operation not supported */
- SCVPP_ENOMEM, /* Out of memory */
- SCVPP_NOT_FOUND, /* Required element can not be found */
-} scvpp_error_e;
-
-// Use VAPI macros to define symbols
-DEFINE_VAPI_MSG_IDS_VPE_API_JSON;
-
-#define VPP_IP4_HOST_PREFIX_LEN 32
-#define VPP_INTFC_NAME_LEN 64 /* Interface name max length */
-#define VPP_IP4_ADDRESS_LEN 4 /* IPv4 length in VPP format */
-#define VPP_IP6_ADDRESS_LEN 16 /* IPv6 length in VPP format */
-#define VPP_MAC_ADDRESS_LEN 8 /* MAC length in VPP format */
-/* IPv4 and IPv6 length in string format */
-#define VPP_IP4_ADDRESS_STRING_LEN INET_ADDRSTRLEN //16, include '\0'
-#define VPP_IP6_ADDRESS_STRING_LEN INET6_ADDRSTRLEN //46, include '\0'
-#define VPP_IP4_PREFIX_STRING_LEN \
- INET_ADDRSTRLEN + sizeof('/') + 2 // include '\0'
-#define VPP_IP6_PREFIX_STRING_LEN \
- INET6_ADDRSTRLEN + sizeof('/') + 3 // include '\0'
-
-/**********************************MACROS**********************************/
-#define ARG_CHECK(retval, arg) \
- do \
- { \
- if (NULL == (arg)) \
- { \
- return (retval); \
- } \
- } \
- while (0)
-
-#define ARG_CHECK2(retval, arg1, arg2) \
- ARG_CHECK(retval, arg1); \
- ARG_CHECK(retval, arg2)
-
-#define ARG_CHECK3(retval, arg1, arg2, arg3) \
- ARG_CHECK(retval, arg1); \
- ARG_CHECK(retval, arg2); \
- ARG_CHECK(retval, arg3)
-
-#define ARG_CHECK4(retval, arg1, arg2, arg3, arg4) \
- ARG_CHECK(retval, arg1); \
- ARG_CHECK(retval, arg2); \
- ARG_CHECK(retval, arg3); \
- ARG_CHECK(retval, arg4)
-
-/* Suppress compiler warning about unused variable.
- * This must be used only for callback function else suppress your unused
- * parameter in function prototype. */
-#define UNUSED(x) (void)x
-
-#define VAPI_REQUEST_CB(api_name) \
-static vapi_error_e \
-api_name##_cb (struct vapi_ctx_s *ctx, void *callback_ctx, vapi_error_e rv, \
- bool is_last, vapi_payload_##api_name##_reply * reply) \
-{ \
- UNUSED(ctx); UNUSED(rv); UNUSED(is_last); \
- if (callback_ctx) { \
- memcpy(callback_ctx, reply, sizeof(vapi_payload_##api_name##_reply)); \
- } \
- return reply->retval; \
-}
-
-#define VAPI_REQUEST_CB_EXTRA(api_name, member) \
-static vapi_error_e \
-api_name##_cb (struct vapi_ctx_s *ctx, void *callback_ctx, vapi_error_e rv, \
- bool is_last, vapi_payload_##api_name##_reply * reply) \
-{ \
- UNUSED(ctx); UNUSED(rv); UNUSED(is_last); \
- vapi_payload_##api_name##_reply **p = callback_ctx; \
- int size = sizeof(vapi_payload_##api_name##_reply) + reply->member; \
- if (p) { \
- *p = malloc(size); \
- if (!*p) { \
- return VAPI_ENOMEM; \
- } \
- memcpy(*p, reply, size); \
- } \
- return reply->retval; \
-}
-
-#define VAPI_CALL_MODE(call_code, vapi_mode) \
- do \
- { \
- pthread_mutex_lock (&sc_vpp_main.vapi_lock); \
- if (VAPI_MODE_BLOCKING == (vapi_mode)) \
- { \
- rv = call_code; \
- } \
- else \
- { \
- while (VAPI_EAGAIN == (rv = call_code)); \
- if (rv != VAPI_OK) { /* try once more to get reply */ \
- rv = vapi_dispatch (sc_vpp_main.vapi_ctx); \
- } \
- } \
- pthread_mutex_unlock (&sc_vpp_main.vapi_lock); \
- } \
- while (0)
-
-#define VAPI_CALL(call_code) VAPI_CALL_MODE(call_code, sc_vpp_main.vapi_mode)
-
-struct elt {
- void *data; //vapi_payload structure
- struct elt *next;
- int id; //id of the stack element to count total nb of elements
-};
-
-static inline int push(struct elt **stack, void *data, int length)
-{
- struct elt *el;
-
- //new stack node
- el = malloc(sizeof(struct elt));
- if (!el)
- return -ENOMEM;
- el->data = malloc(length);
- if (!el->data) {
- free(el);
- return -ENOMEM;
- }
-
-
- memcpy(el->data, data, length);
- if (*stack)
- el->id = (*stack)->id + 1;
- else
- el->id = 0;
- el->next = *stack; //point to old value of stack
- *stack = el; //el is new stack head
-
- return 0;
-}
-
-static inline void * pop(struct elt **stack)
-{
- struct elt *prev;
- void *data;
-
- if (!(*stack))
- return NULL;
-
- data = (*stack)->data; //get data at stack head
- prev = *stack; //save stack to free memory later
- *stack = (*stack)->next; //new stack
-
- free(prev);
- prev = NULL;
-
- return data;
-}
-
-#define VAPI_DUMP_LIST_CB(api_name) \
-static vapi_error_e \
-api_name##_all_cb(vapi_ctx_t ctx, void *caller_ctx, vapi_error_e rv, bool is_last, \
- vapi_payload_##api_name##_details *reply) \
-{ \
- UNUSED(ctx); UNUSED(rv); \
- struct elt **stackp; \
- \
- if (is_last) { \
- return VAPI_OK; \
- } \
- \
- ARG_CHECK2(VAPI_EINVAL, caller_ctx, reply); \
- \
- stackp = (struct elt**) caller_ctx; \
- push(stackp, reply, sizeof(*reply)); \
- \
- return VAPI_OK; \
-}
-
-#define foreach_stack_elt(stack) \
- for(void *data = pop(&stack); data != NULL ; data = pop(&stack))
-
-
-int sc_aton(const char *cp, u8 * buf, size_t length);
-char * sc_ntoa(const u8 * buf);
-int sc_pton(int af, const char *cp, u8 * buf);
-const char * sc_ntop(int af, const u8 * buf, char *addr);
-
-/**
- * @brief Function converts the u8 array from network byte order to host byte order.
- *
- * @param[in] host IPv4 address.
- * @return host byte order value.
- */
-uint32_t hardntohlu32(uint8_t host[4]);
-
-/*
- * VPP
- */
-
-typedef struct sc_vpp_main_t {
- /* VAPI context */
- vapi_ctx_t vapi_ctx;
-
- /* VAPI calling mode: VAPI_MODE_BLOCKING, VAPI_MODE_NONBLOCKING */
- vapi_mode_e vapi_mode;
-
- /* Mutex for keeping atomicity when calling VAPI */
- pthread_mutex_t vapi_lock;
-
- /* pid of VPP */
- pid_t pid;
-} sc_vpp_main_t;
-
-extern sc_vpp_main_t sc_vpp_main;
-
-sc_vpp_main_t *sc_connect_vpp();
-void sc_disconnect_vpp();
-pid_t sc_get_vpp_pid();
-int sc_end_with(const char* str, const char* end);
-
-#endif //__SC_VPP_COMMM_H__
diff --git a/src/scvpp/inc/scvpp/interface.h b/src/scvpp/inc/scvpp/interface.h
deleted file mode 100644
index 86cd185..0000000
--- a/src/scvpp/inc/scvpp/interface.h
+++ /dev/null
@@ -1,69 +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 __BAPI_INTERFACE_H__
-#define __BAPI_INTERFACE_H__
-
-#include <vapi/interface.api.vapi.h>
-#include <scvpp/comm.h>
-
-typedef vapi_payload_sw_interface_details sw_interface_dump_t;
-
-/**
- * @brief Change an interface state
- * @param interface_name - name of target interface
- * @param enable - true=state up, false=state down
- * @return 0 for success, else negative SCVPP error code
- */
-int interface_enable(const char *interface_name, const bool enable);
-
-/**
- * @brief Dump details about all existing interfaces
- * @return stack structure containing all interfaces or NULL if empty
- */
-extern struct elt * interface_dump_all();
-
-
-/**
- * @brief Dump details about a specific interface
- * @param details - where answer will be written
- * @param interface_name - name of the interface to dump
- * @return 0 for success or negative SCVPP error code
- */
-extern int interface_dump_iface(sw_interface_dump_t *details,
- const char *interface_name);
-
-/*
- * Library internal helper functions. Symbols should not be exported eventually
- */
-
-/*
- * @brief Get VPP internal index for an interface
- * @param interface_name - name of the interface to get id from
- * @param sw_if_index - pointer to interface index to be returned
- * @return 0 upon success or negative SCVPP error code
- */
-extern int get_interface_id(const char *interface_name, uint32_t *sw_if_index);
-
-/* @brief Get interface name from an interface ID. This is a super expensive
- * operation !!! Avoid using it.
- * @param interface_name - pointer to string holding returned interface name
- * @param sw_if_index - interface index provided
- * @return 0 upon success or negative SCVPP error code
- */
-extern int get_interface_name(char *interface_name, uint32_t sw_if_index);
-
-#endif /* __BAPI_INTERFACE_H__ */
diff --git a/src/scvpp/inc/scvpp/ip.h b/src/scvpp/inc/scvpp/ip.h
deleted file mode 100644
index f8805b3..0000000
--- a/src/scvpp/inc/scvpp/ip.h
+++ /dev/null
@@ -1,77 +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 __BAPI_IP_H__
-#define __BAPI_IP_H__
-
-#include <vapi/interface.api.vapi.h>
-#include <vapi/ip.api.vapi.h>
-
-typedef vapi_payload_ip_fib_details fib_dump_t;
-
-/*
- * @brief Dump IPv4/IPv6 address from an interface.
- * @param interface_name - name of the interface to get ip from.
- * @param ip_addr - where dump will store IP. If IP not found, returns 0.0.0.0
- * @param prefix_len - pointer where dump will store prefix
- * @param is_ipv6 - true = IPv6, false = IPv4
- * @return 0 on success, or nergative SCVPP error code
- */
-extern int ipv46_address_dump(const char *interface_name, char *ip_addr,
- u8 *prefix_len, bool is_ipv6);
-
-/**
- * @brief Add or remove IPv4/IPv6 address to/from an interface.
- * @param interface_name - name of interface to configure
- * @param addr - address to add
- * @param prefix_len - prefix length of interface
- * @param is_ipv6 - true if ipv6, false otherwise
- * @param add - true to add, false to remove
- */
-extern int ipv46_config_add_remove(const char *interface_name, const char *addr,
- uint8_t prefix_len, bool is_ipv6, bool add);
-
-/*
- * TODO should add a field is_ipv6 because it only do ipv4 now
- * @brief Add or remove an IP route
- * @param dst_address - subnet IP you wish to route
- * @param dst_address_length - prefix length for subnet you wish to route
- * @param next_address - Next hop IP (can use next_hop_interface instead)
- * @param is_add - true to add, false to remove
- * @param table_id - id of the tab in FIB
- * @param next_hop_interface - Next hop interface (can use next_address instead)
- */
-extern int
-ipv46_config_add_del_route(const char* dst_address, u8 dst_address_length,
- const char* next_address, u8 is_add, u32 table_id,
- const char *next_hop_interface);
-
-/**
- * @brief Dump all FIB tables entries
- * @return stacked answers on success, or NULL on failure
- */
-extern struct elt* ipv4_fib_dump_all();
-
-/*
- * @brief Dump information about a prefix, based on fib_dump_all
- * @param prefix_xpath - prefix to look for in FIB
- * @param reply - FIB entry dump replied
- * @return SCVPP_OK if prefix found or SCVPP_NOT_FOUND
- */
-extern int ipv4_fib_dump_prefix(const char *prefix_xpath, fib_dump_t **reply);
-
-#endif /* __BAPI_IP_H__ */
diff --git a/src/scvpp/inc/scvpp/nat.h b/src/scvpp/inc/scvpp/nat.h
deleted file mode 100644
index 40e727e..0000000
--- a/src/scvpp/inc/scvpp/nat.h
+++ /dev/null
@@ -1,61 +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 __BAPI_NAT_H__
-#define __BAPI_NAT_H__
-
-#include <vapi/nat.api.vapi.h>
-
-typedef vapi_payload_nat44_interface_details nat44_interface_details_t;
-typedef vapi_payload_nat44_add_del_interface_addr nat44_add_del_interface_addr_t;
-typedef vapi_payload_nat44_add_del_address_range nat44_add_del_address_range_t;
-typedef vapi_payload_nat44_add_del_static_mapping nat44_add_del_static_mapping_t;
-typedef vapi_payload_nat44_static_mapping_details nat44_static_mapping_details_t;
-typedef vapi_payload_nat44_forwarding_enable_disable nat44_forwarding_enable_disable_t;
-typedef vapi_payload_nat_set_workers nat_set_workers_t;
-
-
-//Wrapper function, if we want hide the VAPI return value
-extern int nat44_interface_dump(nat44_interface_details_t *reply);
-extern int nat44_add_del_interface_addr(
- const nat44_add_del_interface_addr_t *msg);
-extern int nat44_add_del_addr_range(const nat44_add_del_address_range_t *range);
-extern int nat44_add_del_static_mapping(
- const nat44_add_del_static_mapping_t *msg);
-extern int nat44_static_mapping_dump(nat44_static_mapping_details_t *reply);
-extern int nat44_forwarding_enable_disable(
- const nat44_forwarding_enable_disable_t *msg);
-extern int nat_set_workers(const nat_set_workers_t *msg);
-
-
-// Alternative, if we don't want hide VAPI return value
-
-// extern vapi_error_e bin_api_nat44_interface_dump(nat44_interface_details_t *reply);
-// extern vapi_error_e bin_api_nat44_add_del_interface_addr(
-// const nat44_add_del_interface_addr_t *msg);
-// extern vapi_error_e bin_api_nat44_add_del_addr_range(
-// const nat44_add_del_address_range_t *range);
-// extern vapi_error_e bin_api_nat44_add_del_static_mapping(
-// const nat44_add_del_static_mapping_t *msg);
-// extern vapi_error_e bin_api_nat44_static_mapping_dump(
-// nat44_static_mapping_details_t *reply);
-// extern vapi_error_e bin_api_nat44_forwarding_enable_disable(
-// const nat44_forwarding_enable_disable_t *msg);
-// extern vapi_error_e bin_api_nat_set_workers(const nat_set_workers_t *msg);
-
-
-#endif /* __BAPI_NAT_H__ */
-
diff --git a/src/scvpp/inc/scvpp/v3po.h b/src/scvpp/inc/scvpp/v3po.h
deleted file mode 100644
index f876ab4..0000000
--- a/src/scvpp/inc/scvpp/v3po.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (c) 2016 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 _V3PO__INTERFACE_H__
-#define _V3PO__INTERFACE_H__
-
-#include <vapi/tapv2.api.vapi.h>
-#include <vapi/l2.api.vapi.h>
-
-/**
- * V3PO defines operations for specific interfaces used by VPP like:
- * - tapv2
- */
-
-/* tapv2 */
-
-typedef vapi_payload_tap_create_v2 tapv2_create_t;
-typedef vapi_payload_sw_interface_tap_v2_details tapv2_dump_t;
-
-/**
- * TODO problem: vapi_payload_sw_interface_tap_v2_details reply is NULL
- * @brief Dump information about a tap interface
- * @param dump - where dump information will be stored
- * @return 0 on success, or negative SCVPP error code
- */
-extern int dump_tapv2(tapv2_dump_t *dump);
-
-/**
- * @brief Create a tapv2 interface
- * @param query - required structure for the creation of a VPP tapv2 interface
- * @return 0 on success, or negative SCVPP error code
- */
-extern int create_tapv2(tapv2_create_t *query);
-
-/**
- * @brief Delete a tapv2 interface
- * @param interface_name - name of the interface to delete
- * @return 0 on success, or negative SCVPP error code
- */
-extern int delete_tapv2(char *interface_name);
-
-#endif /* __V3PO_INTERFACE_H__ */
diff --git a/src/scvpp/libscvpp.pc.in b/src/scvpp/libscvpp.pc.in
deleted file mode 100644
index f11ed75..0000000
--- a/src/scvpp/libscvpp.pc.in
+++ /dev/null
@@ -1,10 +0,0 @@
-prefix=@CMAKE_INSTALL_PREFIX@
-includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
-libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
-
-Name: scvpp
-Description: VPP-Sweetcomb-Sysrepo integration library
-Version: @PROJECT_VERSION@
-Libs: -L${libdir} -lscvpp
-Cflags: -I${includedir}
-
diff --git a/src/scvpp/src/comm.c b/src/scvpp/src/comm.c
deleted file mode 100644
index 11ed8a9..0000000
--- a/src/scvpp/src/comm.c
+++ /dev/null
@@ -1,191 +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.
- */
-#include <scvpp/comm.h>
-
-#include <stdio.h>
-#include <dirent.h>
-
-#define APP_NAME "sweetcomb_vpp"
-#define MAX_OUTSTANDING_REQUESTS 4
-#define RESPONSE_QUEUE_SIZE 2
-
-sc_vpp_main_t sc_vpp_main = {
- .vapi_ctx = NULL,
- .vapi_mode = VAPI_MODE_BLOCKING,
- .pid = 0
-};
-
-sc_vpp_main_t *sc_connect_vpp()
-{
- vapi_error_e rv;
-
- if (sc_vpp_main.vapi_ctx == NULL) {
- if ((rv = vapi_ctx_alloc(&sc_vpp_main.vapi_ctx)) != VAPI_OK) {
- return NULL;
- }
-
- if ((rv =
- vapi_connect(sc_vpp_main.vapi_ctx, APP_NAME, NULL,
- MAX_OUTSTANDING_REQUESTS, RESPONSE_QUEUE_SIZE,
- sc_vpp_main.vapi_mode, true)) != VAPI_OK) {
- vapi_ctx_free(sc_vpp_main.vapi_ctx);
- sc_vpp_main.vapi_ctx = NULL;
- return NULL;
- }
- }
-
- sc_vpp_main.pid = sc_get_vpp_pid();
- pthread_mutex_init(&sc_vpp_main.vapi_lock, NULL);
- return &sc_vpp_main;
-}
-
-void sc_disconnect_vpp()
-{
- if (NULL != sc_vpp_main.vapi_ctx) {
- pthread_mutex_destroy(&sc_vpp_main.vapi_lock);
- sc_vpp_main.pid = 0;
- vapi_disconnect(sc_vpp_main.vapi_ctx);
- vapi_ctx_free(sc_vpp_main.vapi_ctx);
- sc_vpp_main.vapi_ctx = NULL;
- }
-}
-
-/* get vpp pid in system */
-pid_t sc_get_vpp_pid()
-{
- DIR *dir;
- struct dirent *ptr;
- FILE *fp;
- char cmdline_path[PATH_MAX];
- char cmdline_data[PATH_MAX];
- const char vpp_path[] = "/usr/bin/vpp";
-
- dir = opendir("/proc");
- pid_t pid = 0;
- /* read vpp pid file in proc, return pid of vpp */
- if (NULL != dir) {
- while (NULL != (ptr = readdir(dir))) {
- if ((0 == strcmp(ptr->d_name, "."))
- || (0 == strcmp(ptr->d_name, ".."))) {
- continue;
- }
-
- if (DT_DIR != ptr->d_type) {
- continue;
- }
-
- sprintf(cmdline_path, "/proc/%s/cmdline", ptr->d_name);
- fp = fopen(cmdline_path, "r");
-
- if (NULL != fp) {
- fread(cmdline_data, 1, sizeof(vpp_path), fp);
- cmdline_data[sizeof(vpp_path) - 1] = '\0';
-
- if (cmdline_data ==
- strstr(cmdline_data, "/usr/bin/vpp")) {
- pid = atoi(ptr->d_name);
- }
-
- fclose(fp);
- }
- }
- closedir(dir);
- }
-
- return pid;
-}
-
-int sc_end_with(const char* str, const char* end)
-{
- if (str != NULL && end != NULL)
- {
- int l1 = strlen(str);
- int l2 = strlen(end);
- if (l1 >= l2)
- {
- if (strcmp(str + l1 - l2, end) == 0)
- return 1;
- }
- }
- return 0;
-}
-
-int sc_aton(const char *cp, u8 * buf, size_t length)
-{
- ARG_CHECK2(false, cp, buf);
-
- struct in_addr addr;
- int ret = inet_aton(cp, &addr);
-
- if (0 == ret)
- return -EINVAL;
-
- if (sizeof(addr) > length)
- return -EINVAL;
-
- memcpy(buf, &addr, sizeof (addr));
-
- return 0;
-}
-
-char* sc_ntoa(const u8 * buf)
-{
- ARG_CHECK(NULL, buf);
-
- struct in_addr addr;
- memcpy(&addr, buf, sizeof(addr));
- return inet_ntoa(addr);
-}
-
-int sc_pton(int af, const char *cp, u8 * buf)
-{
- ARG_CHECK2(false, cp, buf);
-
- int ret = inet_pton(af, cp, buf);
-
- if (0 == ret)
- return -EINVAL;
-
- return 0;
-}
-
-const char* sc_ntop(int af, const u8 * buf, char *addr)
-{
- ARG_CHECK(NULL, buf);
- ARG_CHECK(NULL, addr);
-
- socklen_t size = 0;
- if (af == AF_INET)
- size = INET_ADDRSTRLEN;
- else if (af == AF_INET6)
- size = INET6_ADDRSTRLEN;
- else
- return NULL;
-
- return inet_ntop(af, (void*)buf, addr, size);
-}
-
-/**
- * @brief Function converts the u8 array from network byte order to host byte order.
- *
- * @param[in] host IPv4 address.
- * @return host byte order value.
- */
-uint32_t hardntohlu32(uint8_t host[4])
-{
- uint32_t tmp = host[3] | host[2] | host[1] | host[0];
-
- return ntohl(tmp);
-}
diff --git a/src/scvpp/src/interface.c b/src/scvpp/src/interface.c
deleted file mode 100644
index b6b1216..0000000
--- a/src/scvpp/src/interface.c
+++ /dev/null
@@ -1,182 +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 <assert.h>
-#include <stdbool.h>
-
-#include <scvpp/comm.h>
-#include <scvpp/interface.h>
-
-#define IFACE_SUBSTR 49
-
-// Use VAPI macros to define symbols
-DEFINE_VAPI_MSG_IDS_INTERFACE_API_JSON
-
-static vapi_error_e
-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)
-{
- UNUSED(rv); UNUSED(ctx); UNUSED(is_last);
-
- vapi_payload_sw_interface_details *passed;
-
- if (is_last) {
- return VAPI_OK;
- }
-
- ARG_CHECK2(VAPI_EINVAL, callback_ctx, reply);
-
- //copy
- passed = (vapi_payload_sw_interface_details *) callback_ctx;
- *passed = *reply;
-
- return VAPI_OK;
-}
-
-static vapi_error_e
-bin_api_sw_interface_dump(vapi_payload_sw_interface_details *details,
- const char *iface_name)
-{
- vapi_msg_sw_interface_dump *mp;
- vapi_error_e rv;
-
- mp = vapi_alloc_sw_interface_dump(sc_vpp_main.vapi_ctx);
- assert(NULL != mp);
-
- /* Dump a specific interfaces */
- mp->payload.name_filter_valid = true;
- strncpy((char *)mp->payload.name_filter, iface_name, IFACE_SUBSTR);
-
- VAPI_CALL(vapi_sw_interface_dump(sc_vpp_main.vapi_ctx, mp,
- sw_interface_dump_cb, details));
- if (rv != VAPI_OK)
- return -SCVPP_EINVAL;
-
- return rv;
-}
-
-int get_interface_id(const char *if_name, uint32_t *sw_if_index)
-{
- vapi_payload_sw_interface_details details = {0};
- vapi_error_e rv;
-
- ARG_CHECK2(-SCVPP_EINVAL, if_name, sw_if_index);
-
- rv = bin_api_sw_interface_dump(&details, if_name);
- if (rv != VAPI_OK)
- return -SCVPP_EINVAL;
-
- if (strncmp(if_name, (char*) details.interface_name, VPP_INTFC_NAME_LEN)
- != 0)
- return -SCVPP_NOT_FOUND;
-
- *sw_if_index = details.sw_if_index;
-
- return 0;
-}
-
-/*
- * dump only a specific interface
- */
-int interface_dump_iface(sw_interface_dump_t *details, const char *iface_name)
-{
- vapi_error_e rv;
-
- rv = bin_api_sw_interface_dump(details, iface_name);
- if (rv != VAPI_OK)
- return -SCVPP_EINVAL;
-
- if (strncmp(iface_name, (char*) details->interface_name, VPP_INTFC_NAME_LEN)
- != 0)
- return -SCVPP_NOT_FOUND;
-
- return SCVPP_OK;
-}
-
-VAPI_DUMP_LIST_CB(sw_interface)
-
-struct elt* interface_dump_all()
-{
- struct elt* stack = NULL;
- vapi_msg_sw_interface_dump *mp;
- vapi_error_e rv;
-
- mp = vapi_alloc_sw_interface_dump(sc_vpp_main.vapi_ctx);
-
- /* Dump all */
- mp->payload.name_filter_valid = false;
- memset(mp->payload.name_filter, 0, sizeof(mp->payload.name_filter));
-
- VAPI_CALL(vapi_sw_interface_dump(sc_vpp_main.vapi_ctx, mp, sw_interface_all_cb,
- &stack));
- if (VAPI_OK != rv)
- return NULL;
-
- return stack;
-}
-
-VAPI_REQUEST_CB(sw_interface_set_flags);
-
-int interface_enable(const char *interface_name, const bool enable)
-{
- vapi_msg_sw_interface_set_flags *mp;
- uint32_t sw_if_index;
- vapi_error_e rv;
- int rc;
-
- ARG_CHECK(-SCVPP_EINVAL, interface_name);
-
- rc = get_interface_id(interface_name, &sw_if_index);
- if (rc != 0)
- return -SCVPP_NOT_FOUND;
-
- mp = vapi_alloc_sw_interface_set_flags(sc_vpp_main.vapi_ctx);
- assert(NULL != mp);
- mp->payload.sw_if_index = sw_if_index;
- mp->payload.admin_up_down = enable;
-
- VAPI_CALL(vapi_sw_interface_set_flags(sc_vpp_main.vapi_ctx, mp,
- sw_interface_set_flags_cb, NULL));
- if (VAPI_OK != rv)
- return -SCVPP_EINVAL;
-
- return 0;
-}
-
-int get_interface_name(char *interface_name, uint32_t sw_if_index)
-{
- struct elt *stack= NULL;
- sw_interface_dump_t *dump;
- int rc = -SCVPP_NOT_FOUND;
-
- stack = interface_dump_all();
- if (!stack)
- return -SCVPP_NOT_FOUND;
-
- foreach_stack_elt(stack) {
- dump = (sw_interface_dump_t *) data;
-
- if (dump->sw_if_index == sw_if_index) {
- strncpy(interface_name, (char *)dump->interface_name, VPP_INTFC_NAME_LEN);
- rc = SCVPP_OK;
- }
-
- free(dump);
- }
-
- return rc;
-}
diff --git a/src/scvpp/src/ip.c b/src/scvpp/src/ip.c
deleted file mode 100644
index ec44f64..0000000
--- a/src/scvpp/src/ip.c
+++ /dev/null
@@ -1,259 +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 <scvpp/comm.h>
-#include <scvpp/ip.h>
-#include <scvpp/interface.h>
-
-#include <assert.h>
-#include <stdio.h>
-
-// Use VAPI macros to define symbols
-DEFINE_VAPI_MSG_IDS_IP_API_JSON
-
-VAPI_REQUEST_CB(sw_interface_add_del_address);
-
-static vapi_error_e
-bin_api_sw_interface_add_del_address(u32 sw_if_index, bool is_add, bool is_ipv6,
- bool del_all, u8 address_length,
- const char *ip_address)
-{
- vapi_msg_sw_interface_add_del_address *mp;
- vapi_error_e rv;
-
- ARG_CHECK(VAPI_EINVAL, ip_address);
-
- mp = vapi_alloc_sw_interface_add_del_address(sc_vpp_main.vapi_ctx);
- assert(NULL != mp);
-
- mp->payload.sw_if_index = sw_if_index;
- mp->payload.is_add = is_add;
- mp->payload.is_ipv6 = is_ipv6;
- mp->payload.del_all = del_all;
- mp->payload.address_length = address_length;
- if (sc_aton(ip_address, mp->payload.address, VPP_IP4_ADDRESS_LEN))
- return VAPI_EINVAL;
-
- VAPI_CALL(vapi_sw_interface_add_del_address(sc_vpp_main.vapi_ctx, mp,
- sw_interface_add_del_address_cb, NULL));
-
- return rv;
-}
-
-VAPI_REQUEST_CB(ip_add_del_route)
-
-static vapi_error_e
-bin_api_ip_add_del_route(vapi_payload_ip_add_del_route_reply * reply,
- const char* dst_address, uint8_t dst_address_length,
- const char* next_hop, uint8_t is_add,
- uint32_t table_id, const char *next_interface)
-{
- vapi_msg_ip_add_del_route *mp;
- uint32_t sw_if_index;
- vapi_error_e rv ;
- int rc;
-
- ARG_CHECK2(VAPI_EINVAL, reply, dst_address);
-
- //Require interface or next hop IP or both
- if (!next_interface && !next_hop)
- return VAPI_EINVAL;
-
- mp = vapi_alloc_ip_add_del_route(sc_vpp_main.vapi_ctx, 1);
- assert(NULL != mp);
-
- if (next_interface) {
- rc = get_interface_id(next_interface, &sw_if_index);
- if (rc < 0)
- return VAPI_EINVAL;
- }
-
- mp->payload.is_add = is_add;
- mp->payload.table_id = table_id;
- mp->payload.is_ipv6 = false;
- mp->payload.is_local = false;
- sc_aton(dst_address, mp->payload.dst_address, VPP_IP4_ADDRESS_LEN);
- mp->payload.dst_address_length = dst_address_length;
- if (next_interface) //interface is not mandatory
- mp->payload.next_hop_sw_if_index = sw_if_index;
- if (next_hop) //next hop ip is not mandatory
- sc_aton(next_hop, mp->payload.next_hop_address, VPP_IP4_ADDRESS_LEN);
-
- VAPI_CALL(vapi_ip_add_del_route(sc_vpp_main.vapi_ctx, mp,
- ip_add_del_route_cb, reply));
-
- return rv;
-}
-
-static vapi_error_e
-ip_address_dump_cb (struct vapi_ctx_s *ctx, void *callback_ctx, vapi_error_e rv,
- bool is_last, vapi_payload_ip_address_details *reply)
-{
- UNUSED(rv);
- vapi_payload_ip_address_details *passed;
-
- ARG_CHECK3(VAPI_EINVAL, ctx, callback_ctx, reply);
-
- //copy dump reply in callback context
- if (!is_last) {
- passed = (vapi_payload_ip_address_details *) callback_ctx;
- *passed = *reply;
- }
-
- return VAPI_OK;
-}
-
-static vapi_error_e
-bin_api_ip_address_dump(u32 sw_if_index, bool is_ipv6,
- vapi_payload_ip_address_details *dctx)
-{
- vapi_msg_ip_address_dump *mp;
- vapi_error_e rv;
-
- mp = vapi_alloc_ip_address_dump(sc_vpp_main.vapi_ctx);
- assert(mp != NULL);
-
- mp->payload.sw_if_index = sw_if_index;
- mp->payload.is_ipv6 = is_ipv6;
-
- VAPI_CALL(vapi_ip_address_dump(sc_vpp_main.vapi_ctx, mp, ip_address_dump_cb,
- dctx));
- if (rv != VAPI_OK)
- return rv;
-
- return VAPI_OK;
-}
-
-///VAPI_DUMP_LIST_CB(ip_fib); can not be used because of path flexible array
-
-static vapi_error_e
-ip_fib_all_cb(vapi_ctx_t ctx, void *caller_ctx, vapi_error_e rv, bool is_last,
- vapi_payload_ip_fib_details *reply)
-{
- UNUSED(ctx); UNUSED(rv); UNUSED(is_last);
- struct elt **stackp;
- ARG_CHECK2(VAPI_EINVAL, caller_ctx, reply);
-
- stackp = (struct elt**) caller_ctx;
- push(stackp, reply, sizeof(*reply)+reply->count*sizeof(vapi_type_fib_path));
-
- return VAPI_OK;
-}
-
-struct elt* ipv4_fib_dump_all()
-{
- struct elt *stack = NULL;
- vapi_msg_ip_fib_dump *mp;
- vapi_error_e rv;
-
- mp = vapi_alloc_ip_fib_dump(sc_vpp_main.vapi_ctx);
- assert(mp != NULL);
-
- VAPI_CALL(vapi_ip_fib_dump(sc_vpp_main.vapi_ctx, mp, ip_fib_all_cb, &stack));
- if(VAPI_OK != rv)
- return NULL;
-
- return stack;
-}
-
-int ipv4_fib_dump_prefix(const char *prefix_xpath, fib_dump_t **reply)
-{
- struct elt *stack = NULL;
- char prefix[VPP_IP4_PREFIX_STRING_LEN];
- fib_dump_t *dump;
- int rc = -SCVPP_NOT_FOUND;
-
- stack = ipv4_fib_dump_all();
- if (!stack)
- return rc;
-
- foreach_stack_elt(stack) {
- dump = (fib_dump_t *) data;
-
- if (rc == -SCVPP_NOT_FOUND) {
- snprintf(prefix, VPP_IP4_PREFIX_STRING_LEN, "%s/%u",
- sc_ntoa(dump->address), dump->address_length);
- if (!strncmp(prefix_xpath, prefix, VPP_IP4_PREFIX_STRING_LEN)) {
- *reply = dump;
- rc = SCVPP_OK;
- continue;
- }
- }
-
- free(dump);
- }
-
- return rc;
-}
-
-int ipv46_address_dump(const char *interface_name, char *ip_addr,
- u8 *prefix_len, bool is_ipv6)
-{
- vapi_payload_ip_address_details dctx = {0};
- uint32_t sw_if_index;
- vapi_error_e rv;
- int rc;
-
- rc = get_interface_id(interface_name, &sw_if_index);
- if (rc < 0)
- return rc;
-
- rv = bin_api_ip_address_dump(sw_if_index, is_ipv6, &dctx);
- if (rv != VAPI_OK)
- return -SCVPP_EINVAL;
-
- strcpy(ip_addr, sc_ntoa(dctx.ip)); //IP string
- *prefix_len = dctx.prefix_length; //prefix length
-
- return SCVPP_OK;
-}
-
-int ipv46_config_add_remove(const char *if_name, const char *addr,
- uint8_t prefix, bool is_ipv6, bool add)
-{
- vapi_error_e rv;
- uint32_t sw_if_index;
- int rc;
-
- ARG_CHECK2(-1, if_name, addr);
-
- rc = get_interface_id(if_name, &sw_if_index);
- if (rc < 0)
- return rc;
-
- /* add del addr */
- rv = bin_api_sw_interface_add_del_address(sw_if_index, add, is_ipv6, 0,
- prefix, addr);
- if (rv != VAPI_OK)
- return -SCVPP_EINVAL;
-
- return SCVPP_OK;
-}
-
-int ipv46_config_add_del_route(const char* dst_address, u8 dst_address_length,
- const char* next_address, u8 is_add,
- u32 table_id, const char *interface)
-{
- vapi_payload_ip_add_del_route_reply reply = {0};
- vapi_error_e rv;
-
- rv = bin_api_ip_add_del_route(&reply, dst_address, dst_address_length,
- next_address, is_add, table_id, interface);
- if (VAPI_OK != rv || reply.retval > 0)
- return -SCVPP_EINVAL;
-
- return SCVPP_OK;
-}
diff --git a/src/scvpp/src/nat.c b/src/scvpp/src/nat.c
deleted file mode 100644
index 4519c3e..0000000
--- a/src/scvpp/src/nat.c
+++ /dev/null
@@ -1,294 +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 <scvpp/comm.h>
-#include <scvpp/nat.h>
-
-#include <assert.h>
-#include <stdbool.h>
-
-
-DEFINE_VAPI_MSG_IDS_NAT_API_JSON
-
-static vapi_error_e
-nat44_interface_dump_cb(struct vapi_ctx_s *ctx, void *callback_ctx,
- vapi_error_e rv, bool is_last,
- vapi_payload_nat44_interface_details *reply)
-{
- UNUSED(ctx); UNUSED(rv);
- vapi_payload_nat44_interface_details *dctx = callback_ctx;
- assert(dctx);
-
- if (is_last)
- {
- assert(NULL == reply);
- }
- else
- {
- //TODO: Use LOG message for scvpp
-// SC_LOG_DBG("NAT Interface dump entry: [%u]: %u\n", reply->sw_if_index,
-// reply->is_inside);
- *dctx = *reply;
- }
-
- return VAPI_OK;
-}
-
-static vapi_error_e
-bin_api_nat44_interface_dump(vapi_payload_nat44_interface_details *reply)
-{
- vapi_error_e rv;
- vapi_msg_nat44_interface_dump *mp;
-
- ARG_CHECK(VAPI_EINVAL, reply);
-
- mp = vapi_alloc_nat44_interface_dump(sc_vpp_main.vapi_ctx);
- assert(NULL != mp);
-
- VAPI_CALL(vapi_nat44_interface_dump(sc_vpp_main.vapi_ctx, mp,
- nat44_interface_dump_cb, reply));
-
- return rv;
-}
-
-VAPI_REQUEST_CB(nat44_add_del_interface_addr);
-
-static vapi_error_e
-bin_api_nat44_add_del_interface_addr(
- const vapi_payload_nat44_add_del_interface_addr *msg)
-{
- vapi_error_e rv;
- vapi_msg_nat44_add_del_interface_addr *mp;
-
- ARG_CHECK(VAPI_EINVAL, msg);
-
- mp = vapi_alloc_nat44_add_del_interface_addr(sc_vpp_main.vapi_ctx);
- assert(NULL != mp);
-
- mp->payload = *msg;
-
- VAPI_CALL(vapi_nat44_add_del_interface_addr(sc_vpp_main.vapi_ctx, mp,
- nat44_add_del_interface_addr_cb,
- NULL));
-
- return rv;
-}
-
-VAPI_REQUEST_CB(nat44_add_del_address_range);
-
-static vapi_error_e
-bin_api_nat44_add_del_addr_range(
- const vapi_payload_nat44_add_del_address_range *range)
-{
- vapi_error_e rv;
- vapi_msg_nat44_add_del_address_range *mp;
-
- ARG_CHECK(VAPI_EINVAL, range);
-
- mp = vapi_alloc_nat44_add_del_address_range(sc_vpp_main.vapi_ctx);
-
- assert(NULL != mp);
-
- mp->payload = *range;
-
- VAPI_CALL(vapi_nat44_add_del_address_range(sc_vpp_main.vapi_ctx, mp,
- nat44_add_del_address_range_cb,
- NULL));
-
- return rv;
-}
-
-VAPI_REQUEST_CB(nat44_add_del_static_mapping);
-
-static vapi_error_e
-bin_api_nat44_add_del_static_mapping(
- const vapi_payload_nat44_add_del_static_mapping *msg)
-{
- vapi_error_e rv;
- vapi_msg_nat44_add_del_static_mapping *mp;
-
- ARG_CHECK(VAPI_EINVAL, msg);
-
- mp = vapi_alloc_nat44_add_del_static_mapping(sc_vpp_main.vapi_ctx);
- assert(NULL != mp);
-
- mp->payload = *msg;
-
- VAPI_CALL(vapi_nat44_add_del_static_mapping(sc_vpp_main.vapi_ctx, mp,
- nat44_add_del_static_mapping_cb,
- NULL));
-
- return rv;
-}
-
-static vapi_error_e nat44_static_mapping_dump_cb(
- struct vapi_ctx_s *ctx, void *callback_ctx, vapi_error_e rv,
- bool is_last,vapi_payload_nat44_static_mapping_details *reply)
-{
- UNUSED(rv); UNUSED(ctx);
- vapi_payload_nat44_static_mapping_details *dctx = callback_ctx;
- assert(dctx);
-
- if (is_last)
- {
- assert(NULL == reply);
- }
- else
- {
- *dctx = *reply;
- }
-
- return VAPI_OK;
-}
-
-static vapi_error_e
-bin_api_nat44_static_mapping_dump(
- vapi_payload_nat44_static_mapping_details *reply)
-{
- vapi_error_e rv;
- vapi_msg_nat44_static_mapping_dump *msg;
-
- ARG_CHECK(VAPI_EINVAL, reply);
-
- msg = vapi_alloc_nat44_static_mapping_dump(sc_vpp_main.vapi_ctx);
- assert(NULL != msg);
-
- VAPI_CALL(vapi_nat44_static_mapping_dump(sc_vpp_main.vapi_ctx, msg,
- nat44_static_mapping_dump_cb,
- reply));
-
- return rv;
-}
-
-VAPI_REQUEST_CB(nat44_forwarding_enable_disable);
-
-static vapi_error_e bin_api_nat44_forwarding_enable_disable(
- const vapi_payload_nat44_forwarding_enable_disable *msg)
-{
- vapi_error_e rv;
- vapi_msg_nat44_forwarding_enable_disable *mp;
-
- ARG_CHECK(VAPI_EINVAL, msg);
-
- mp = vapi_alloc_nat44_forwarding_enable_disable(sc_vpp_main.vapi_ctx);
- assert(NULL != mp);
-
- mp->payload = *msg;
-
- VAPI_CALL(vapi_nat44_forwarding_enable_disable(
- sc_vpp_main.vapi_ctx, mp, nat44_forwarding_enable_disable_cb, NULL));
-
- return rv;
-}
-
-VAPI_REQUEST_CB(nat_set_workers);
-
-static vapi_error_e
-bin_api_nat_set_workers(const vapi_payload_nat_set_workers *msg)
-{
- vapi_error_e rv;
- vapi_msg_nat_set_workers *mp;
-
- ARG_CHECK(VAPI_EINVAL, msg);
-
- mp = vapi_alloc_nat_set_workers(sc_vpp_main.vapi_ctx);
- assert(NULL != mp);
-
- mp->payload = *msg;
-
- VAPI_CALL(vapi_nat_set_workers(sc_vpp_main.vapi_ctx, mp, nat_set_workers_cb, NULL));
-
- return rv;
-}
-
-int nat44_interface_dump(nat44_interface_details_t *reply)
-{
- vapi_error_e rv;
-
- rv = bin_api_nat44_interface_dump(reply);
- if (VAPI_OK != rv)
- return -SCVPP_EINVAL;
-
- return SCVPP_OK;
-}
-
-int nat44_add_del_interface_addr(const nat44_add_del_interface_addr_t *msg)
-{
- vapi_error_e rv;
-
- rv = bin_api_nat44_add_del_interface_addr(msg);
- if (VAPI_OK != rv)
- return -SCVPP_EINVAL;
-
- return SCVPP_OK;
-}
-
-int nat44_add_del_addr_range(const nat44_add_del_address_range_t *range)
-{
- vapi_error_e rv;
-
- rv = bin_api_nat44_add_del_addr_range(range);
- if (VAPI_OK != rv)
- return -SCVPP_EINVAL;
-
- return SCVPP_OK;
-}
-
-int nat44_add_del_static_mapping(const nat44_add_del_static_mapping_t *msg)
-{
- vapi_error_e rv;
-
- rv = bin_api_nat44_add_del_static_mapping(msg);
- if (VAPI_OK != rv)
- return -SCVPP_EINVAL;
-
- return SCVPP_OK;
-}
-
-int nat44_static_mapping_dump(nat44_static_mapping_details_t *reply)
-{
- vapi_error_e rv;
-
- rv = bin_api_nat44_static_mapping_dump(reply);
- if (VAPI_OK != rv)
- return -SCVPP_EINVAL;
-
- return SCVPP_OK;
-}
-
-int
-nat44_forwarding_enable_disable(const nat44_forwarding_enable_disable_t *msg)
-{
- vapi_error_e rv;
-
- rv = bin_api_nat44_forwarding_enable_disable(msg);
- if (VAPI_OK != rv)
- return -SCVPP_EINVAL;
-
- return 0;
-}
-
-int nat_set_workers(const nat_set_workers_t *msg)
-{
- vapi_error_e rv;
-
- rv = bin_api_nat_set_workers(msg);
- if (VAPI_OK != rv)
- return -SCVPP_EINVAL;
-
- return SCVPP_OK;
-}
-
diff --git a/src/scvpp/src/v3po.c b/src/scvpp/src/v3po.c
deleted file mode 100644
index 8fd83ba..0000000
--- a/src/scvpp/src/v3po.c
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Copyright (c) 2016 Cisco and/or its affiliates.
- * 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 <assert.h>
-
-#include <scvpp/comm.h>
-#include <scvpp/v3po.h>
-#include <scvpp/interface.h>
-
-// Use VAPI macros to define symbols
-DEFINE_VAPI_MSG_IDS_L2_API_JSON;
-DEFINE_VAPI_MSG_IDS_TAPV2_API_JSON
-
-/*
- * tap-v2 interfaces
- */
-
-// Delete tapv2
-
-VAPI_REQUEST_CB(tap_delete_v2);
-
-static vapi_error_e bin_api_delete_tapv2(u32 sw_if_index)
-{
- vapi_msg_tap_delete_v2 *mp;
- vapi_error_e rv;
-
- mp = vapi_alloc_tap_delete_v2(sc_vpp_main.vapi_ctx);
- assert(NULL != mp);
-
- mp->payload.sw_if_index = sw_if_index;
-
- VAPI_CALL(vapi_tap_delete_v2(sc_vpp_main.vapi_ctx, mp, tap_delete_v2_cb, NULL));
- if (rv != VAPI_OK)
- return -rv;
-
- return VAPI_OK;
-}
-
-int delete_tapv2(char *iface_name)
-{
- uint32_t sw_if_index;
- vapi_error_e rv;
- int rc;
-
- rc = get_interface_id(iface_name, &sw_if_index);
- if (rc < 0)
- return rc;
-
- rv = bin_api_delete_tapv2(sw_if_index);
- if (VAPI_OK != rv)
- return -SCVPP_EINVAL;
-
- return SCVPP_OK;
-}
-
-// Create tapv2
-
-VAPI_REQUEST_CB(tap_create_v2);
-
-int create_tapv2(tapv2_create_t *query)
-{
- vapi_msg_tap_create_v2 *mp;
- vapi_error_e rv;
-
- mp = vapi_alloc_tap_create_v2(sc_vpp_main.vapi_ctx);
- assert(NULL != mp);
-
- memcpy(&mp->payload, query, sizeof(tapv2_create_t));
-
- VAPI_CALL(vapi_tap_create_v2(sc_vpp_main.vapi_ctx, mp, tap_create_v2_cb, NULL));
- if (rv != VAPI_OK)
- return -EAGAIN;
-
- return 0;
-}
diff --git a/src/scvpp/tests/CMakeLists.txt b/src/scvpp/tests/CMakeLists.txt
deleted file mode 100644
index 78e1861..0000000
--- a/src/scvpp/tests/CMakeLists.txt
+++ /dev/null
@@ -1,42 +0,0 @@
-#
-# Copyright (c) 2018 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_directories ("${PROJECT_SOURCE_DIR}/src")
-
-# check whether valgrind is installed
-find_program(valgrind_FOUND valgrind)
-
-set(TEST_SRC
- scvpp_test.h
- scvpp_test.c
- scvpp_iface_test.c
- scvpp_ip_test.c
- scvpp_nat_test.c
-)
-
-add_executable(scvpp_test ${TEST_SRC})
-target_link_libraries(scvpp_test ${CMOCKA_LIBRARIES} scvpp_a)
-target_include_directories(scvpp_test PRIVATE ../inc)
-add_test(scvpp_test ./scvpp_test)
-set_tests_properties(scvpp_test PROPERTIES TIMEOUT 60)
-
-if(valgrind_FOUND)
- add_test(scvpp_valgrind valgrind
- --error-exitcode=1 --read-var-info=yes
- --leak-check=full --show-leak-kinds=all
- ./scvpp_test
- )
- set_tests_properties(scvpp_valgrind PROPERTIES TIMEOUT 60)
-endif(valgrind_FOUND)
diff --git a/src/scvpp/tests/scvpp_iface_test.c b/src/scvpp/tests/scvpp_iface_test.c
deleted file mode 100644
index 6a96694..0000000
--- a/src/scvpp/tests/scvpp_iface_test.c
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- * Copyright (c) 2016 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 <unistd.h>
-#include <setjmp.h>
-#include <stdarg.h>
-#include <cmocka.h>
-
-#include "scvpp_test.h"
-
-#include <scvpp/interface.h>
-#include <scvpp/v3po.h>
-
-static void test_enable_disable(void **state)
-{
- UNUSED(state);
- sw_interface_dump_t dump = {0};
- int rc;
-
- rc = interface_enable("tap0", 1);
- assert_int_equal(rc, SCVPP_OK);
-
- rc = interface_dump_iface(&dump, "tap0");
- assert_int_equal(rc, SCVPP_OK);
-
- assert_int_equal(dump.admin_up_down, true);
-
- rc = interface_enable("tap0", 0);
- assert_int_equal(rc, SCVPP_OK);
-}
-
-static void test_create_tapv2(void **state)
-{
- UNUSED(state);
- tapv2_create_t query = {0};
- sw_interface_dump_t dump = {0};
- int rc;
-
- query.id = 1;
- query.use_random_mac = 1;
-
- rc = create_tapv2(&query);
- assert_int_equal(rc, SCVPP_OK);
-
- rc = interface_dump_iface(&dump, "tap1");
- assert_int_equal(rc, SCVPP_OK);
-}
-
-static int teardown_tapv2(void **state)
-{
- UNUSED(state);
- return delete_tapv2("tap1");
-}
-
-static void test_dump_iface_all(void **state)
-{
- UNUSED(state);
- struct elt *stack = NULL;
- sw_interface_dump_t *dump;
- bool exist = false;
-
- stack = interface_dump_all();
- assert_non_null(stack);
- foreach_stack_elt(stack) {
- dump = (sw_interface_dump_t *) data;
- if (!strncmp((char*) dump->interface_name, "tap0", VPP_INTFC_NAME_LEN))
- exist = true;
- free(dump);
- }
- assert_true(exist);
-}
-
-static void test_dump_iface_exist(void **state)
-{
- UNUSED(state);
- vapi_payload_sw_interface_details details = {0};
- int rc;
-
- rc = interface_dump_iface(&details, "local0");
- assert_int_equal(rc, SCVPP_OK);
-
- assert_string_equal(details.interface_name, "local0");
-}
-
-static void test_dump_iface_unexist(void **state)
-{
- UNUSED(state);
- vapi_payload_sw_interface_details details = {0};
- int rc;
-
- rc = interface_dump_iface(&details, "unexisting");
- assert_int_equal(rc, -SCVPP_NOT_FOUND);
-}
-
-static void test_get_interface_name(void **state)
-{
- UNUSED(state);
- char interface_name[VPP_INTFC_NAME_LEN];
- uint32_t tap0_if_index;
- int rc;
-
- rc = get_interface_id("tap0", &tap0_if_index);
- assert_int_equal(rc, SCVPP_OK);
-
- rc = get_interface_name(interface_name, tap0_if_index);
- assert_int_equal(rc, SCVPP_OK);
-
- assert_string_equal(interface_name, "tap0");
-}
-
-const struct CMUnitTest iface_tests[IFACE_TEST_SIZE] = {
- cmocka_unit_test_teardown(test_create_tapv2, teardown_tapv2),
- cmocka_unit_test(test_enable_disable),
- cmocka_unit_test(test_dump_iface_all),
- cmocka_unit_test(test_dump_iface_exist),
- cmocka_unit_test(test_dump_iface_unexist),
- cmocka_unit_test(test_get_interface_name),
-};
diff --git a/src/scvpp/tests/scvpp_ip_test.c b/src/scvpp/tests/scvpp_ip_test.c
deleted file mode 100644
index 5e28123..0000000
--- a/src/scvpp/tests/scvpp_ip_test.c
+++ /dev/null
@@ -1,184 +0,0 @@
-/*
- * Copyright (c) 2019 Cisco
- *
- * 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 <unistd.h>
-#include <setjmp.h>
-#include <stdarg.h>
-#include <cmocka.h>
-
-#include "scvpp_test.h"
-
-#include <scvpp/ip.h>
-#include <scvpp/interface.h>
-#include <scvpp/comm.h>
-
-static void test_add_remove_ipv4(void **state)
-{
- UNUSED(state);
- const char ip_q[VPP_IP4_ADDRESS_STRING_LEN] = "192.168.100.144";
- char ip_r[VPP_IP4_ADDRESS_STRING_LEN];
- u8 prefix_q = 24;
- u8 prefix_r;
- int rc;
-
- //add ipv4 on tap0
- rc = ipv46_config_add_remove("tap0", ip_q, prefix_q, false, true);
- assert_int_equal(rc, SCVPP_OK);
-
- //dump ipv4 on tap0 and check if it mach
- rc = ipv46_address_dump("tap0", ip_r, &prefix_r, false);
- assert_int_equal(rc, SCVPP_OK);
- assert_string_equal(ip_q, ip_r);
- assert_int_equal(prefix_q, prefix_r);
-
- //remove ipv4 on tap0
- rc = ipv46_config_add_remove("tap0", ip_q, prefix_q, false, false);
- assert_int_equal(rc, SCVPP_OK);
-
- //dump ipv4 after removal and check if equals 0.0.0.0
- rc = ipv46_address_dump("tap0", ip_r, &prefix_r, false);
- assert_int_equal(rc, SCVPP_OK);
- assert_string_equal(ip_r, "0.0.0.0");
-}
-
-static void test_ipv4_add_del_route_no_iface(void **state)
-{
- UNUSED(state);
- int rc;
- char dst_address[VPP_IP4_ADDRESS_STRING_LEN] = "192.168.100.0";
- uint8_t prefix_len = 24;
- char next_hop[VPP_IP4_ADDRESS_STRING_LEN] = "192.168.100.100";
- uint32_t table_id = 0;
- fib_dump_t *dump;
- struct elt *stack;
- bool route_found = false;
-
- /* Must fail, can not have both interface and next hop IP null */
- rc = ipv46_config_add_del_route(dst_address, prefix_len, NULL, true,
- table_id, NULL);
- assert_int_equal(rc, -SCVPP_EINVAL);
-
- rc = ipv46_config_add_del_route(dst_address, prefix_len, next_hop, true,
- table_id, NULL);
- assert_int_equal(rc, SCVPP_OK);
-
- /* Dump all FIB routes and check if we find ours */
- stack = ipv4_fib_dump_all();
- assert_non_null(stack);
- foreach_stack_elt(stack) {
- dump = (fib_dump_t *) data;
-
- if (strncmp(sc_ntoa(dump->address), dst_address,
- VPP_IP4_ADDRESS_STRING_LEN) == 0 &&
- dump->address_length == prefix_len) {
- route_found = true;
- assert_int_equal(dump->table_id, table_id);
- assert_int_equal(dump->count, 1);
- assert_string_equal(sc_ntoa(dump->path[0].next_hop), next_hop);
- }
- free(dump);
- }
- assert_true(route_found);
-
- /* Delete previously set route */
- rc = ipv46_config_add_del_route(dst_address, prefix_len, next_hop, false,
- table_id, NULL);
- assert_int_equal(rc, SCVPP_OK);
-
- /* Check our route has been deleted */
- route_found = false;
- stack = ipv4_fib_dump_all();
- assert_non_null(stack);
- foreach_stack_elt(stack) {
- dump = (fib_dump_t *) data;
- if (strncmp(sc_ntoa(dump->address), dst_address,
- VPP_IP4_ADDRESS_STRING_LEN) == 0 &&
- dump->address_length == prefix_len) {
- route_found = true;
- }
- free(dump);
- }
- assert_false(route_found);
-}
-
-static void test_ipv4_add_del_route_no_next_hop_ip(void **state)
-{
- UNUSED(state);
- int rc;
- char dst_address[VPP_IP4_ADDRESS_STRING_LEN] = "192.168.100.0";
- uint8_t prefix_len = 24;
- char interface[VPP_IP4_ADDRESS_STRING_LEN] = "tap0";
- uint32_t table_id = 0;
- uint32_t sw_if_index;
- fib_dump_t *dump;
- struct elt *stack;
- bool route_found = false;
-
- //Add a new route
- rc = ipv46_config_add_del_route(dst_address, prefix_len, NULL, true,
- table_id, interface);
- assert_int_equal(rc, SCVPP_OK);
-
- //Dump all FIB routes and check we find ours
- stack = ipv4_fib_dump_all();
- assert_non_null(stack);
-
- rc = get_interface_id(interface, &sw_if_index);
- assert_int_equal(rc, SCVPP_OK);
-
- foreach_stack_elt(stack) {
- dump = (fib_dump_t *) data;
-
- if (strncmp(sc_ntoa(dump->address), dst_address,
- VPP_IP4_ADDRESS_STRING_LEN) == 0 &&
- dump->address_length == prefix_len) {
- route_found = true;
- assert_int_equal(dump->table_id, table_id);
- assert_int_equal(dump->count, 1);
- assert_int_equal(dump->path[0].sw_if_index, sw_if_index);
- }
- free(dump);
- }
- assert_true(route_found);
-
- //Delete route
- rc = ipv46_config_add_del_route(dst_address, prefix_len, NULL, false,
- table_id, interface);
- assert_int_equal(rc, SCVPP_OK);
-
- //Check our route has been deleted
- route_found = false;
- stack = ipv4_fib_dump_all();
- assert_non_null(stack);
-
- foreach_stack_elt(stack) {
- dump = (fib_dump_t *) data;
- if (strncmp(sc_ntoa(dump->address), dst_address,
- VPP_IP4_ADDRESS_STRING_LEN) == 0 &&
- dump->address_length == prefix_len) {
- route_found = true;
- }
- free(dump);
- }
- assert_false(route_found);
-}
-
-
-const struct CMUnitTest ip_tests[IP_TEST_SIZE] = {
- cmocka_unit_test(test_add_remove_ipv4),
- cmocka_unit_test(test_ipv4_add_del_route_no_next_hop_ip),
- cmocka_unit_test(test_ipv4_add_del_route_no_iface),
-};
diff --git a/src/scvpp/tests/scvpp_nat_test.c b/src/scvpp/tests/scvpp_nat_test.c
deleted file mode 100644
index 93541e9..0000000
--- a/src/scvpp/tests/scvpp_nat_test.c
+++ /dev/null
@@ -1,173 +0,0 @@
-/*
- * Copyright (c) 2019 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 <stdlib.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <setjmp.h>
-#include <cmocka.h>
-
-#include "scvpp_test.h"
-
-#include <scvpp/comm.h>
-#include <scvpp/nat.h>
-
-
-void test_nat44_static_mapping(void **state)
-{
- UNUSED(state);
- nat44_add_del_static_mapping_t map = {0};
- nat44_static_mapping_details_t dump = {0};
- u8 empty_ip[4] = {0};
- int rc;
-
- /*Configure the static mapping
- Alternative to this CLI command:
- nat44 add static mapping local 172.168.0.1 external 172.168.8.5
- */
- sc_aton("172.168.0.1", map.local_ip_address,
- sizeof(map.local_ip_address));
- sc_aton("172.168.8.5", map.external_ip_address,
- sizeof(map.external_ip_address));
- map.external_sw_if_index = ~0;
- map.is_add = 1;
-
- rc = nat44_add_del_static_mapping(&map);
- assert_int_equal(rc, SCVPP_OK);
-
- rc = nat44_static_mapping_dump(&dump);
- assert_int_equal(rc, SCVPP_OK);
-
- assert_memory_equal(dump.local_ip_address, map.local_ip_address,
- sizeof(dump.local_ip_address));
-
- assert_memory_equal(dump.external_ip_address, map.external_ip_address,
- sizeof(dump.external_ip_address));
-
- /* Remove previous config*/
- map.is_add = 0;
-
- rc = nat44_add_del_static_mapping(&map);
- assert_int_equal(rc, SCVPP_OK);
-
- memset(&dump, 0, sizeof(dump));
-
- rc = nat44_static_mapping_dump(&dump);
- assert_int_equal(rc, SCVPP_OK);
-
- assert_memory_equal(dump.local_ip_address, empty_ip,
- sizeof(dump.local_ip_address));
-
- assert_memory_equal(dump.external_ip_address, empty_ip,
- sizeof(dump.external_ip_address));
-}
-
-void test_nat44_static_mapping_with_ports(void **state)
-{
- UNUSED(state);
- nat44_add_del_static_mapping_t map = {0};
- nat44_static_mapping_details_t dump = {0};
- nat44_add_del_address_range_t range = {0};
- u8 empty_ip[4] = {0};
- const u16 lport = 77;
- const u16 eport = 88;
- int rc;
-
- /*Configure address pool
- Alternative to this CLI:
- nat44 add address 5.4.4.4
- */
- sc_aton("5.4.4.4", range.first_ip_address,
- sizeof(range.first_ip_address));
-
- sc_aton("5.4.4.4", range.last_ip_address,
- sizeof(range.last_ip_address));
-
- range.is_add = 1;
-
- rc = nat44_add_del_addr_range(&range);
- assert_int_equal(rc, SCVPP_OK);
-
- /*Configure NAT with ports
- Alternative to this CLI:
- nat44 add static mapping tcp local 172.168.0.1 77 external 5.4.4.4 88
- */
-
- sc_aton("172.168.0.1", map.local_ip_address,
- sizeof(map.local_ip_address));
-
- sc_aton("5.4.4.4", map.external_ip_address,
- sizeof(map.external_ip_address));
-
- map.protocol = 6;
-
- map.external_sw_if_index = ~0;
-
- map.external_port = eport;
- map.local_port = lport;
-
- map.is_add = 1;
-
- rc = nat44_add_del_static_mapping(&map);
- assert_int_equal(rc, SCVPP_OK);
-
- rc = nat44_static_mapping_dump(&dump);
- assert_int_equal(rc, SCVPP_OK);
-
- assert_memory_equal(dump.local_ip_address, map.local_ip_address,
- sizeof(dump.local_ip_address));
-
- assert_memory_equal(dump.external_ip_address, map.external_ip_address,
- sizeof(dump.external_ip_address));
-
- assert_int_equal(dump.local_port, lport);
-
- assert_int_equal(dump.external_port, eport);
-
- /* Remove all previous config*/
-
- map.is_add = 0;
-
- rc = nat44_add_del_static_mapping(&map);
- assert_int_equal(rc, SCVPP_OK);
-
- memset(&dump, 0, sizeof(dump));
-
- rc = nat44_static_mapping_dump(&dump);
- assert_int_equal(rc, SCVPP_OK);
-
- assert_memory_equal(dump.local_ip_address, empty_ip,
- sizeof(dump.local_ip_address));
-
- assert_memory_equal(dump.external_ip_address, empty_ip,
- sizeof(dump.external_ip_address));
-
- assert_int_equal(dump.local_port, 0);
-
- assert_int_equal(dump.external_port, 0);
-
- range.is_add = 0;
-
- rc = nat44_add_del_addr_range(&range);
- assert_int_equal(rc, SCVPP_OK);
-}
-
-const struct CMUnitTest nat_tests[] = {
- cmocka_unit_test_setup_teardown(test_nat44_static_mapping, NULL,
- NULL),
- cmocka_unit_test_setup_teardown(test_nat44_static_mapping_with_ports,
- NULL, NULL),
- };
diff --git a/src/scvpp/tests/scvpp_test.c b/src/scvpp/tests/scvpp_test.c
deleted file mode 100644
index f6e99a0..0000000
--- a/src/scvpp/tests/scvpp_test.c
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * Copyright (c) 2016 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 <stdlib.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <setjmp.h>
-
-#include <scvpp/comm.h>
-#include <scvpp/v3po.h>
-
-#include "scvpp_test.h"
-
-/* test "AAA.BBB.CCC.DDD" -> {A, B, C, D} */
-static void test_sc_ntoa(void **state)
-{
- UNUSED(state);
- u8 buf[4] = {192, 168, 100, 44};
- char *res;
-
- res = sc_ntoa(buf);
- assert_string_equal(res, "192.168.100.44");
-}
-
-/* test {A, B, C, D} -> "AAA.BBB.CCC.DDD" */
-static void test_sc_aton(void **state)
-{
- UNUSED(state);
- char ip[VPP_IP4_ADDRESS_STRING_LEN] = "192.168.100.44";
- uint8_t buf[4];
- int rc;
-
- rc = sc_aton(ip, buf, VPP_IP4_ADDRESS_LEN);
- assert_int_equal(rc, 0);
-
- assert_int_equal(buf[0], 192);
- assert_int_equal(buf[1], 168);
- assert_int_equal(buf[2], 100);
- assert_int_equal(buf[3], 44);
-}
-
-static int setup(void **state)
-{
- UNUSED(state);
- tapv2_create_t query = {0};
-
- if (sc_connect_vpp() != 0) {
- fprintf(stderr, "Error connecting to VPP\n");
- return -1;
- }
-
- /* Create interface tap0 to test several functions */
- query.id = 0;
- query.use_random_mac = 1;
- if (create_tapv2(&query) != 0) {
- fprintf(stderr, "Error creating tap0\n");
- return -1;
- }
-
- return 0;
-}
-
-static int teardown(void **state)
-{
- UNUSED(state);
- /* Delete tap0 */
- if (delete_tapv2("tap0") != 0) {
- fprintf(stderr, "Failed deleting tap0\n");
- return -1;
- }
-
- sc_disconnect_vpp();
-
- return 0;
-}
-
-/* return code for scvpp-test binary is the number of failed test */
-int main()
-{
- int rc = 0;
-
- const struct CMUnitTest common_tests[] = {
- cmocka_unit_test(test_sc_ntoa),
- cmocka_unit_test(test_sc_aton),
- };
-
- print_message("Common tests\n");
- rc |= cmocka_run_group_tests(common_tests, NULL, NULL);
- print_message("Interface tests\n");
- rc |= cmocka_run_group_tests(iface_tests, setup, teardown);
- print_message("IP tests\n");
- rc |= cmocka_run_group_tests(ip_tests, setup, teardown);
- print_message("NAT tests\n");
- rc |= cmocka_run_group_tests(nat_tests, setup, teardown);
-
- return rc;
-}
diff --git a/src/scvpp/tests/scvpp_test.h b/src/scvpp/tests/scvpp_test.h
deleted file mode 100644
index 28bd514..0000000
--- a/src/scvpp/tests/scvpp_test.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright (c) 2019 Cisco
- *
- * 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 __SCVPP_TEST_H
-#define __SCVPP_TEST_H__
-
-#include <cmocka.h>
-
-#define IFACE_TEST_SIZE 6
-extern const struct CMUnitTest iface_tests[IFACE_TEST_SIZE];
-
-#define IP_TEST_SIZE 3
-extern const struct CMUnitTest ip_tests[IP_TEST_SIZE];
-
-#define NAT_TEST_SIZE 2
-extern const struct CMUnitTest nat_tests[NAT_TEST_SIZE];
-
-#endif /* __SCVPP_TEST_H__ */