summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatus Fabian <matfabia@cisco.com>2016-05-11 04:49:46 -0700
committerDamjan Marion <damarion@cisco.com>2016-05-18 17:14:46 +0000
commit82e29c455833b5b12e04c89d2dec1106b499e6b0 (patch)
tree4e7fc87fd853113d5ab47dd92aec04968f7551cc
parent5a206eafdbf9370fead2dd26fcab09e7ff5544c4 (diff)
Add netmap API
JIRA: VPP-66 Change-Id: I421529fa8eafe5268745a34a4fcd40156defcdf8 Signed-off-by: Matus Fabian <matfabia@cisco.com>
-rw-r--r--vnet/vnet/devices/netmap/cli.c4
-rw-r--r--vnet/vnet/devices/netmap/device.c5
-rw-r--r--vnet/vnet/devices/netmap/netmap.h9
-rw-r--r--vnet/vnet/devices/netmap/node.c5
-rw-r--r--vpp-api-test/vat/api_format.c101
-rw-r--r--vpp/api/api.c44
-rw-r--r--vpp/api/vpe.api50
7 files changed, 208 insertions, 10 deletions
diff --git a/vnet/vnet/devices/netmap/cli.c b/vnet/vnet/devices/netmap/cli.c
index e3d61460b6c..584d68002d3 100644
--- a/vnet/vnet/devices/netmap/cli.c
+++ b/vnet/vnet/devices/netmap/cli.c
@@ -14,11 +14,15 @@
* limitations under the License.
*------------------------------------------------------------------
*/
+#include <stdint.h>
+#include <net/if.h>
+#include <sys/ioctl.h>
#include <vlib/vlib.h>
#include <vlib/unix/unix.h>
#include <vnet/ethernet/ethernet.h>
+#include <vnet/devices/netmap/net_netmap.h>
#include <vnet/devices/netmap/netmap.h>
static clib_error_t *
diff --git a/vnet/vnet/devices/netmap/device.c b/vnet/vnet/devices/netmap/device.c
index dcd04733613..f04e0672c90 100644
--- a/vnet/vnet/devices/netmap/device.c
+++ b/vnet/vnet/devices/netmap/device.c
@@ -15,10 +15,15 @@
*------------------------------------------------------------------
*/
+#include <stdint.h>
+#include <net/if.h>
+#include <sys/ioctl.h>
+
#include <vlib/vlib.h>
#include <vlib/unix/unix.h>
#include <vnet/ethernet/ethernet.h>
+#include <vnet/devices/netmap/net_netmap.h>
#include <vnet/devices/netmap/netmap.h>
#define foreach_netmap_tx_func_error \
diff --git a/vnet/vnet/devices/netmap/netmap.h b/vnet/vnet/devices/netmap/netmap.h
index 026f0001f96..c5b3dfbc71a 100644
--- a/vnet/vnet/devices/netmap/netmap.h
+++ b/vnet/vnet/devices/netmap/netmap.h
@@ -40,11 +40,6 @@
* SUCH DAMAGE.
*/
-#include <stdint.h>
-#include <net/if.h>
-#include <sys/ioctl.h>
-#include <vnet/devices/netmap/net_netmap.h>
-
typedef struct {
CLIB_CACHE_LINE_ALIGN_MARK(cacheline0);
u8 * host_if_name;
@@ -101,6 +96,8 @@ int netmap_delete_if(vlib_main_t * vm, u8 * host_if_name);
/* Macros and helper functions from sys/net/netmap_user.h */
+#ifdef _NET_NETMAP_H_
+
#define _NETMAP_OFFSET(type, ptr, offset) \
((type)(void *)((char *)(ptr) + (offset)))
@@ -144,5 +141,5 @@ nm_ring_space(struct netmap_ring *ring)
ret += ring->num_slots;
return ret;
}
-
+#endif
diff --git a/vnet/vnet/devices/netmap/node.c b/vnet/vnet/devices/netmap/node.c
index d4c01411904..3986c7e4762 100644
--- a/vnet/vnet/devices/netmap/node.c
+++ b/vnet/vnet/devices/netmap/node.c
@@ -15,10 +15,15 @@
*------------------------------------------------------------------
*/
+#include <stdint.h>
+#include <net/if.h>
+#include <sys/ioctl.h>
+
#include <vlib/vlib.h>
#include <vlib/unix/unix.h>
#include <vnet/ethernet/ethernet.h>
+#include <vnet/devices/netmap/net_netmap.h>
#include <vnet/devices/netmap/netmap.h>
#define foreach_netmap_input_error
diff --git a/vpp-api-test/vat/api_format.c b/vpp-api-test/vat/api_format.c
index 4776e2adca1..ceda982d645 100644
--- a/vpp-api-test/vat/api_format.c
+++ b/vpp-api-test/vat/api_format.c
@@ -2231,7 +2231,9 @@ _(lisp_enable_disable_reply) \
_(vxlan_gpe_add_del_tunnel_reply) \
_(af_packet_create_reply) \
_(af_packet_delete_reply) \
-_(policer_add_del_reply)
+_(policer_add_del_reply) \
+_(netmap_create_reply) \
+_(netmap_delete_reply)
#define _(n) \
static void vl_api_##n##_t_handler \
@@ -2412,7 +2414,9 @@ _(LISP_ENABLE_DISABLE_STATUS_DETAILS, \
lisp_enable_disable_status_details) \
_(AF_PACKET_CREATE_REPLY, af_packet_create_reply) \
_(AF_PACKET_DELETE_REPLY, af_packet_delete_reply) \
-_(POLICER_ADD_DEL_REPLY, policer_add_del_reply)
+_(POLICER_ADD_DEL_REPLY, policer_add_del_reply) \
+_(NETMAP_CREATE_REPLY, netmap_create_reply) \
+_(NETMAP_DELETE_REPLY, netmap_delete_reply)
/* M: construct, but don't yet send a message */
@@ -10328,6 +10332,94 @@ api_policer_add_del (vat_main_t * vam)
return 0;
}
+static int
+api_netmap_create (vat_main_t * vam)
+{
+ unformat_input_t * i = vam->input;
+ vl_api_netmap_create_t * mp;
+ f64 timeout;
+ u8 * if_name = 0;
+ u8 hw_addr[6];
+ u8 random_hw_addr = 1;
+ u8 is_pipe = 0;
+ u8 is_master = 0;
+
+ memset (hw_addr, 0, sizeof (hw_addr));
+
+ while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
+ if (unformat (i, "name %s", &if_name))
+ vec_add1 (if_name, 0);
+ else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
+ random_hw_addr = 0;
+ else if (unformat (i, "pipe"))
+ is_pipe = 1;
+ else if (unformat (i, "master"))
+ is_master = 1;
+ else if (unformat (i, "slave"))
+ is_master = 0;
+ else
+ break;
+ }
+
+ if (!vec_len (if_name)) {
+ errmsg ("interface name must be specified");
+ return -99;
+ }
+
+ if (vec_len (if_name) > 64) {
+ errmsg ("interface name too long");
+ return -99;
+ }
+
+ M(NETMAP_CREATE, netmap_create);
+
+ clib_memcpy (mp->if_name, if_name, vec_len (if_name));
+ clib_memcpy (mp->hw_addr, hw_addr, 6);
+ mp->use_random_hw_addr = random_hw_addr;
+ mp->is_pipe = is_pipe;
+ mp->is_master = is_master;
+ vec_free (if_name);
+
+ S; W;
+ /* NOTREACHED */
+ return 0;
+}
+
+static int
+api_netmap_delete (vat_main_t * vam)
+{
+ unformat_input_t * i = vam->input;
+ vl_api_netmap_delete_t * mp;
+ f64 timeout;
+ u8 * if_name = 0;
+
+ while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
+ if (unformat (i, "name %s", &if_name))
+ vec_add1 (if_name, 0);
+ else
+ break;
+ }
+
+ if (!vec_len (if_name)) {
+ errmsg ("interface name must be specified");
+ return -99;
+ }
+
+ if (vec_len (if_name) > 64) {
+ errmsg ("interface name too long");
+ return -99;
+ }
+
+ M(NETMAP_DELETE, netmap_delete);
+
+ clib_memcpy (mp->if_name, if_name, vec_len (if_name));
+ vec_free (if_name);
+
+ S; W;
+ /* NOTREACHED */
+ return 0;
+}
+
static int q_or_quit (vat_main_t * vam)
{
longjmp (vam->jump_buf, 1);
@@ -10814,7 +10906,10 @@ _(lisp_map_resolver_dump, "") \
_(lisp_enable_disable_status_dump, "") \
_(af_packet_create, "name <host interface name> [hw_addr <mac>]") \
_(af_packet_delete, "name <host interface name>") \
-_(policer_add_del, "name <policer name> <params> [del]")
+_(policer_add_del, "name <policer name> <params> [del]") \
+_(netmap_create, "name <interface name> [hw-addr <mac>] [pipe] " \
+ "[master|slave]") \
+_(netmap_delete, "name <interface name>")
/* List of command functions, CLI names map directly to functions */
#define foreach_cli_function \
diff --git a/vpp/api/api.c b/vpp/api/api.c
index f81b9c98af3..39ea0aa4b1d 100644
--- a/vpp/api/api.c
+++ b/vpp/api/api.c
@@ -75,6 +75,7 @@
#include <vnet/ip/ip6_hop_by_hop.h>
#include <vnet/devices/af_packet/af_packet.h>
#include <vnet/policer/policer.h>
+#include <vnet/devices/netmap/netmap.h>
#undef BIHASH_TYPE
#undef __included_bihash_template_h__
@@ -337,7 +338,9 @@ _(LISP_ENABLE_DISABLE_STATUS_DUMP, \
_(SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del) \
_(AF_PACKET_CREATE, af_packet_create) \
_(AF_PACKET_DELETE, af_packet_delete) \
-_(POLICER_ADD_DEL, policer_add_del)
+_(POLICER_ADD_DEL, policer_add_del) \
+_(NETMAP_CREATE, netmap_create) \
+_(NETMAP_DELETE, netmap_delete)
#define QUOTE_(x) #x
#define QUOTE(x) QUOTE_(x)
@@ -5964,6 +5967,45 @@ vl_api_policer_add_del_t_handler
REPLY_MACRO(VL_API_POLICER_ADD_DEL_REPLY);
}
+static void
+vl_api_netmap_create_t_handler
+(vl_api_netmap_create_t *mp)
+{
+ vlib_main_t *vm = vlib_get_main();
+ vl_api_netmap_create_reply_t *rmp;
+ int rv = 0;
+ u8 *if_name = NULL;
+
+ if_name = format(0, "%s", mp->if_name);
+ vec_add1 (if_name, 0);
+
+ rv = netmap_create_if(vm, if_name, mp->use_random_hw_addr ? 0 : mp->hw_addr,
+ mp->is_pipe, mp->is_master);
+
+ vec_free(if_name);
+
+ REPLY_MACRO(VL_API_NETMAP_CREATE_REPLY);
+}
+
+static void
+vl_api_netmap_delete_t_handler
+(vl_api_netmap_delete_t *mp)
+{
+ vlib_main_t * vm = vlib_get_main();
+ vl_api_netmap_delete_reply_t *rmp;
+ int rv = 0;
+ u8 *if_name = NULL;
+
+ if_name = format(0, "%s", mp->if_name);
+ vec_add1 (if_name, 0);
+
+ rv = netmap_delete_if(vm, if_name);
+
+ vec_free(if_name);
+
+ REPLY_MACRO(VL_API_NETMAP_DELETE_REPLY);
+}
+
#define BOUNCE_HANDLER(nn) \
static void vl_api_##nn##_t_handler ( \
vl_api_##nn##_t *mp) \
diff --git a/vpp/api/vpe.api b/vpp/api/vpe.api
index 021cd0c0aa3..e2d23594b5c 100644
--- a/vpp/api/vpe.api
+++ b/vpp/api/vpe.api
@@ -3460,3 +3460,53 @@ define policer_add_del_reply {
u32 context;
i32 retval;
};
+
+/** \brief Create netmap
+ @param client_index - opaque cookie to identify the sender
+ @param context - sender context, to match reply w/ request
+ @param if_name - interface name
+ @param hw_addr - interface MAC
+ @param use_random_hw_addr - use random generated MAC
+ @param is_pipe - is pipe
+ @param is_master - 0=slave, 1=master
+*/
+define netmap_create {
+ u32 client_index;
+ u32 context;
+
+ u8 if_name[64];
+ u8 hw_addr[6];
+ u8 use_random_hw_addr;
+ u8 is_pipe;
+ u8 is_master;
+};
+
+/** \brief Create netmap response
+ @param context - sender context, to match reply w/ request
+ @param retval - return value for request
+*/
+define netmap_create_reply {
+ u32 context;
+ i32 retval;
+};
+
+/** \brief Delete netmap
+ @param client_index - opaque cookie to identify the sender
+ @param context - sender context, to match reply w/ request
+ @param if_name - interface name
+*/
+define netmap_delete {
+ u32 client_index;
+ u32 context;
+
+ u8 if_name[64];
+};
+
+/** \brief Delete netmap response
+ @param context - sender context, to match reply w/ request
+ @param retval - return value for request
+*/
+define netmap_delete_reply {
+ u32 context;
+ i32 retval;
+};