summaryrefslogtreecommitdiffstats
path: root/src/scvpp/src/sc_vpp_interface.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/scvpp/src/sc_vpp_interface.c')
-rw-r--r--src/scvpp/src/sc_vpp_interface.c250
1 files changed, 133 insertions, 117 deletions
diff --git a/src/scvpp/src/sc_vpp_interface.c b/src/scvpp/src/sc_vpp_interface.c
index 333ddd7..73b29ae 100644
--- a/src/scvpp/src/sc_vpp_interface.c
+++ b/src/scvpp/src/sc_vpp_interface.c
@@ -14,15 +14,18 @@
* limitations under the License.
*/
-#include "sc_vpp_interface.h"
-
#include <assert.h>
#include <stdbool.h>
+
#include <vapi/l2.api.vapi.h>
#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)
@@ -36,66 +39,109 @@ void sw_interface_details_query_set_name(sw_interface_details_query_t * query,
}
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)
+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)
{
- sw_interface_details_query_t *dctx = callback_ctx;
- assert(dctx);
+ vapi_payload_sw_interface_details *passed;
- if (!dctx->interface_found)
- {
- if (is_last)
- {
- assert(NULL == reply);
- }
- else
- {
- assert(NULL != reply);
- SC_LOG_DBG("Interface dump entry: [%u]: %s\n", reply->sw_if_index,
- reply->interface_name);
+ ARG_CHECK(-EINVAL, callback_ctx);
- 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;
- }
- }
- }
+ 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;
}
-bool get_interface_id(sw_interface_details_query_t * sw_interface_details_query)
+static vapi_error_e
+bin_api_sw_interface_dump(vapi_payload_sw_interface_details *details)
{
- ARG_CHECK(false, sw_interface_details_query);
- sw_interface_details_query->interface_found = false;
+ vapi_msg_sw_interface_dump *mp;
+ vapi_error_e rv;
- vapi_msg_sw_interface_dump *mp = vapi_alloc_sw_interface_dump (g_vapi_ctx_instance);
+ 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);
- 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, sw_interface_dump_cb, details));
+ if (!rv)
+ return -EINVAL;
- vapi_error_e rv;
- VAPI_CALL(vapi_sw_interface_dump(g_vapi_ctx_instance, mp, get_interface_id_cb, sw_interface_details_query));
+ return rv;
+}
- if (VAPI_OK != rv) {
- SC_LOG_DBG_MSG("vapi_sw_interface_dump");
- return false;
+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)
+{
+ 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 );
}
- if (!sw_interface_details_query->interface_found)
- SC_LOG_ERR("interface name %s: Can't find index",
- sw_interface_details_query->sw_interface_details.interface_name);
+ vpp_interface_t * iface = &dctx->intfcArray[dctx->num_ifs];
- return sw_interface_details_query->interface_found;
+ iface->sw_if_index = reply->sw_if_index;
+ strncpy(iface->interface_name, 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_name_cb (struct vapi_ctx_s *ctx, void *callback_ctx,
+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)
{
@@ -110,10 +156,10 @@ get_interface_name_cb (struct vapi_ctx_s *ctx, void *callback_ctx,
}
else
{
- assert(reply && dctx);
- SC_LOG_DBG("Interface dump entry: [%u]: %s\n", reply->sw_if_index, reply->interface_name);
+ assert(NULL != reply);
- if (dctx->sw_interface_details.sw_if_index == reply->sw_if_index)
+ 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;
@@ -124,74 +170,48 @@ get_interface_name_cb (struct vapi_ctx_s *ctx, void *callback_ctx,
return VAPI_OK;
}
-bool get_interface_name(sw_interface_details_query_t * sw_interface_details_query)
+// 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);
- vapi_error_e rv;
- VAPI_CALL(vapi_sw_interface_dump (g_vapi_ctx_instance, mp, get_interface_name_cb, sw_interface_details_query));
+ 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));
- if (VAPI_OK != rv) {
- SC_LOG_DBG_MSG("vapi_sw_interface_dump");
+ 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;
- }
-
- if (!sw_interface_details_query->interface_found)
- SC_LOG_ERR("interface index %u: Can't find name",
- sw_interface_details_query->sw_interface_details.sw_if_index);
return sw_interface_details_query->interface_found;
}
-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)
+int get_interface_name(sw_interface_details_query_t *query)
{
- if (is_last)
- {
- assert (NULL == reply);
- }
- else
- {
- assert (NULL != reply);
- SC_LOG_DBG("Interface dump entry: [%u]: %s\n", reply->sw_if_index,
- reply->interface_name);
- }
+ vapi_error_e rv;
- return VAPI_OK;
-}
+ ARG_CHECK(-EINVAL, query);
-vapi_error_e bin_api_sw_interface_dump(const char * interface_name)
-{
- vapi_msg_sw_interface_dump *mp = vapi_alloc_sw_interface_dump (g_vapi_ctx_instance);
- assert(NULL != mp);
+ query->interface_found = false;
- if (NULL != interface_name)
- {
- mp->payload.name_filter_valid = true;
- strncpy((char *)mp->payload.name_filter, interface_name, sizeof(mp->payload.name_filter));
- }
- else
- {
- mp->payload.name_filter_valid = false;
- memset(mp->payload.name_filter, 0, sizeof (mp->payload.name_filter));
- }
+ rv = bin_api_sw_interface_dump(&query->sw_interface_details);
+ if (rv == VAPI_OK)
+ query->interface_found = true;
- vapi_error_e rv;
- VAPI_CALL(vapi_sw_interface_dump (g_vapi_ctx_instance, mp, sw_interface_dump_cb, NULL));
-
- return rv;
+ return query->interface_found;
}
-
VAPI_RETVAL_CB(sw_interface_set_flags);
-vapi_error_e bin_api_sw_interface_set_flags(uint32_t if_index, uint8_t up)
+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);
@@ -207,46 +227,42 @@ vapi_error_e bin_api_sw_interface_set_flags(uint32_t if_index, uint8_t up)
VAPI_RETVAL_CB(sw_interface_set_l2_bridge);
-vapi_error_e bin_api_sw_interface_set_l2_bridge(u32 bd_id, u32 rx_sw_if_index,
- bool enable)
+//set interface l2 bridge <interface> <bridge-domain-id> [bvi|uu-fwd] [shg]
+static vapi_error_e
+bin_api_sw_interface_set_l2_bridge(u32 bd_id, u32 rx_sw_if_index, bool enable)
{
- vapi_msg_sw_interface_set_l2_bridge *mp =
- vapi_alloc_sw_interface_set_l2_bridge (g_vapi_ctx_instance);
+ vapi_msg_sw_interface_set_l2_bridge *mp;
+ vapi_error_e rv;
+
+ mp = vapi_alloc_sw_interface_set_l2_bridge (g_vapi_ctx_instance);
assert(NULL != mp);
- //set interface l2 bridge <interface> <bridge-domain-id> [bvi|uu-fwd] [shg]
- /*
- typedef struct __attribute__ ((__packed__)) {
- u32 rx_sw_if_index;
- u32 bd_id;
- vapi_enum_l2_port_type port_type;
- u8 shg;
- u8 enable;
- } vapi_payload_sw_interface_set_l2_bridge;
- */
+
mp->payload.enable = enable;
mp->payload.bd_id = bd_id;
mp->payload.rx_sw_if_index = rx_sw_if_index;
- vapi_error_e rv;
VAPI_CALL(vapi_sw_interface_set_l2_bridge (g_vapi_ctx_instance, mp,
sw_interface_set_l2_bridge_cb, NULL));
return rv;
}
-VAPI_COPY_CB(create_loopback)
-
-vapi_error_e bin_api_create_loopback(vapi_payload_create_loopback_reply *reply)
+int interface_enable(const char *interface_name, const bool enable)
{
- ARG_CHECK(VAPI_EINVAL, reply);
+ ARG_CHECK(-1, interface_name);
- vapi_msg_create_loopback *mp = vapi_alloc_create_loopback (g_vapi_ctx_instance);
- assert(NULL != mp);
+ int rc = 0;
+ sw_interface_details_query_t query = {0};
+ sw_interface_details_query_set_name(&query, interface_name);
- //mp->payload.mac_address =
+ rc = get_interface_id(&query);
+ if (!rc)
+ return -1;
- vapi_error_e rv;
- VAPI_CALL(vapi_create_loopback (g_vapi_ctx_instance, mp, create_loopback_cb, reply));
+ rc = bin_api_sw_interface_set_flags(query.sw_interface_details.sw_if_index,
+ enable);
+ if (VAPI_OK != rc)
+ return -1;
- return rv;
+ return 0;
}