From a760dfb253161911fc3aa3c8b879c461d53ade6e Mon Sep 17 00:00:00 2001 From: YohanPipereau Date: Wed, 6 Mar 2019 14:01:58 +0100 Subject: Sweetcomb global cleanup -Merge IETF and Openconfig to use SCVPP 2 -Move L2 bridge from sc_vpp_interface to sc_vpp_v3po -Implement tav2 dump -Make openconfig-interfaces functions static -Try one more dispatch after failure in VAPI_CALL -Add error return code for scvpp -Remove unused length maccros -Return appropriate error code for interface dump when interface not found -Improve scvpp test suite -Change get_interface_id prototype -Use interface_dump_iface in openconfig_interface. -No more vapi types in openconfig_interfaces.c -Move openconfig_local_routing VAPI operations to sc_vpp_ip -Implement a multiple dump with a stack data structure -Comment out state_cb code from openconfig_local_routing to use new functions later. -Rename YANG model to their fully qualified name : @ -Remove headers almost empty and put registration declaration in sc_model.h -Shorten vapi context global variable name -Reorganize scvpp unit test suite -Add instructions to Makefile to install/uninstall YANG models in sysrepo. -Add this new instructions to README.md. -Reimplement interface_dump_all -Use a common message at INFO Log Level to know when sysrepo callbacks are triggered -Remove old structure to perform dump of all interfaces -Reimplement get_interface_name and add scvpp test for it -Clean sys_util -Use UNUSED maccro everywhere to have lighter prototypes -Have ietf-interfaces:interfaces-state work with new dump function -Add setup and teardown for NAT tests -Remove unused tapv2 dump -Remove useless sysrepo module callback -Remove xpath_find_first_key usage in openconfig-interfaces -Remove xpath_find_first_key in oc_local_routing and in the rest of sweetcomb -Reorganize scvpp include dir and fix scvpp_test new warnings -Fix scvpp tests for ip routes -Factorize scvpp nat and test return code of its function -Correct test_dump_if_all if there is an existing hardware interface -Implement a per-prefix dump in scvpp -free changes iterator in ietf-interfaces -Add new XPATH in oc local-routing -Introduce helper methods for sysrepo config callbacks -Factorize config callback -Refactor the openconfig-local-routing config callback -Use common foreach_change to iterate over changes in all models -Create a sample directory gathering example of configurations supposed to work with sweetcomb -Fix state callback of oc-local-routing -Add new sample for get operation on next-hop -foreach_elt maccro condition forgets to read one element Change-Id: I8e87fce577a00337977588f057a6e095a20f457c Signed-off-by: YohanPipereau --- src/scvpp/src/sc_vpp_interface.c | 252 --------------------------------------- 1 file changed, 252 deletions(-) delete mode 100644 src/scvpp/src/sc_vpp_interface.c (limited to 'src/scvpp/src/sc_vpp_interface.c') diff --git a/src/scvpp/src/sc_vpp_interface.c b/src/scvpp/src/sc_vpp_interface.c deleted file mode 100644 index bc5befc..0000000 --- a/src/scvpp/src/sc_vpp_interface.c +++ /dev/null @@ -1,252 +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 -#include - -#include - -#include "sc_vpp_comm.h" -#include "sc_vpp_interface.h" - - -// Use VAPI macros to define symbols -DEFINE_VAPI_MSG_IDS_INTERFACE_API_JSON -DEFINE_VAPI_MSG_IDS_L2_API_JSON; - -void sw_interface_details_query_set_name(sw_interface_details_query_t * query, - const char * interface_name) -{ - assert(query && interface_name); - - memset(query, 0, sizeof(*query)); - - strncpy((char*) query->sw_interface_details.interface_name, interface_name, - sizeof(query->sw_interface_details.interface_name)); -} - -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; - - ARG_CHECK(-EINVAL, callback_ctx); - - passed = (vapi_payload_sw_interface_details *) callback_ctx; - - //Interface is found if index of query equals index of reply - if (passed->sw_if_index != reply->sw_if_index) - return -EINVAL; - - //copy - *passed = *reply; - - return VAPI_OK; -} - -static vapi_error_e -bin_api_sw_interface_dump(vapi_payload_sw_interface_details *details) -{ - vapi_msg_sw_interface_dump *mp; - vapi_error_e rv; - - mp = vapi_alloc_sw_interface_dump(g_vapi_ctx_instance); - - mp->payload.name_filter_valid = 0; - memset(mp->payload.name_filter, 0, sizeof(mp->payload.name_filter)); - assert(NULL != mp); - - VAPI_CALL(vapi_sw_interface_dump(g_vapi_ctx_instance, mp, sw_interface_dump_cb, details)); - if (!rv) - return -EINVAL; - - return rv; -} - -static vapi_error_e -interface_dump_all_cb(struct vapi_ctx_s *ctx, void *callback_ctx, - vapi_error_e rv, bool is_last, - vapi_payload_sw_interface_details * reply) -{ - UNUSED(ctx); UNUSED(rv); - dump_all_ctx *dctx = callback_ctx; - - if (is_last) - return VAPI_OK; - - if(dctx->capacity == 0 && dctx->intfcArray == NULL) { - dctx->capacity = 10; - dctx->intfcArray = (vpp_interface_t*)malloc( sizeof(vpp_interface_t)*dctx->capacity ); - } - if(dctx->num_ifs >= dctx->capacity-1) { - dctx->capacity += 10; - dctx->intfcArray = (vpp_interface_t*)realloc(dctx->intfcArray, sizeof(vpp_interface_t)*dctx->capacity ); - } - - vpp_interface_t * iface = &dctx->intfcArray[dctx->num_ifs]; - - iface->sw_if_index = reply->sw_if_index; - strncpy(iface->interface_name, (char*) reply->interface_name, - VPP_INTFC_NAME_LEN); - iface->l2_address_length = reply->l2_address_length; - memcpy(iface->l2_address, reply->l2_address, reply->l2_address_length ); - iface->link_speed = reply->link_speed; - - iface->link_mtu = reply->link_mtu; - iface->admin_up_down = reply->admin_up_down; - iface->link_up_down = reply->link_up_down; - - dctx->num_ifs += 1; - - return VAPI_OK; -} - -int interface_dump_all(dump_all_ctx * dctx) -{ - vapi_msg_sw_interface_dump *dump; - vapi_error_e rv; - - ARG_CHECK(-1, dctx); - - if(dctx == NULL) - return -1; - - dctx->intfcArray = NULL; - dctx->capacity = 0; - dctx->num_ifs = 0; - - dump = vapi_alloc_sw_interface_dump(g_vapi_ctx_instance); - - dump->payload.name_filter_valid = 0; - memset(dump->payload.name_filter, 0, sizeof(dump->payload.name_filter)); - while (VAPI_EAGAIN == - (rv = - vapi_sw_interface_dump(g_vapi_ctx_instance, dump, interface_dump_all_cb, - dctx))); - - return dctx->num_ifs; -} - -static vapi_error_e -get_interface_id_cb (struct vapi_ctx_s *ctx, void *callback_ctx, - vapi_error_e rv, bool is_last, - vapi_payload_sw_interface_details * reply) -{ - UNUSED(ctx); UNUSED(rv); - - sw_interface_details_query_t *dctx = callback_ctx; - assert(dctx); - - if (!dctx->interface_found) - { - if (is_last) - { - assert(NULL == reply); - } - else - { - assert(NULL != reply); - - if (0 == strcmp((const char*)dctx->sw_interface_details.interface_name, - (const char*)reply->interface_name)) - { - dctx->interface_found = true; - dctx->sw_interface_details = *reply; - } - } - } - - return VAPI_OK; -} - -// return error code instead of boolean -int get_interface_id(sw_interface_details_query_t * sw_interface_details_query) -{ - vapi_error_e rv; - - ARG_CHECK(false, sw_interface_details_query); - - sw_interface_details_query->interface_found = false; - - vapi_msg_sw_interface_dump *mp = vapi_alloc_sw_interface_dump (g_vapi_ctx_instance); - assert(NULL != mp); - - mp->payload.name_filter_valid = true; - memcpy(mp->payload.name_filter, sw_interface_details_query->sw_interface_details.interface_name, - sizeof(mp->payload.name_filter)); - - VAPI_CALL(vapi_sw_interface_dump(g_vapi_ctx_instance, mp, get_interface_id_cb, sw_interface_details_query)); - if (VAPI_OK != rv) - return false; - - return sw_interface_details_query->interface_found; -} - -int get_interface_name(sw_interface_details_query_t *query) -{ - vapi_error_e rv; - - ARG_CHECK(-EINVAL, query); - - query->interface_found = false; - - rv = bin_api_sw_interface_dump(&query->sw_interface_details); - if (rv == VAPI_OK) - query->interface_found = true; - - return query->interface_found; -} - -VAPI_RETVAL_CB(sw_interface_set_flags); - -static vapi_error_e -bin_api_sw_interface_set_flags(uint32_t if_index, uint8_t up) -{ - vapi_msg_sw_interface_set_flags *mp = vapi_alloc_sw_interface_set_flags (g_vapi_ctx_instance); - assert(NULL != mp); - - mp->payload.sw_if_index = if_index; - mp->payload.admin_up_down = up; - - vapi_error_e rv; - VAPI_CALL(vapi_sw_interface_set_flags(g_vapi_ctx_instance, mp, sw_interface_set_flags_cb, NULL)); - - return rv; -} - -int interface_enable(const char *interface_name, const bool enable) -{ - ARG_CHECK(-1, interface_name); - - int rc = 0; - sw_interface_details_query_t query = {0}; - sw_interface_details_query_set_name(&query, interface_name); - - rc = get_interface_id(&query); - if (!rc) - return -1; - - rc = bin_api_sw_interface_set_flags(query.sw_interface_details.sw_if_index, - enable); - if (VAPI_OK != rc) - return -1; - - return 0; -} -- cgit 1.2.3-korg