Add a new API interface for offloading dpif flows to netdev.
The API consist on the following:
flow_put - offload a new flow
flow_get - query an offloaded flow
flow_del - delete an offloaded flow
flow_flush - flush all offloaded flows
flow_dump_* - dump all offloaded flows
In upcoming commits we will introduce an implementation of this
API for netdev-linux.
Signed-off-by: Paul Blakey <paulb@mellanox.com>
Reviewed-by: Roi Dayan <roid@mellanox.com>
Acked-by: Flavio Leitner <fbl@sysclose.org>
Signed-off-by: Simon Horman <simon.horman@netronome.com>
lib/if-notifier.h \
lib/netdev-linux.c \
lib/netdev-linux.h \
+ lib/netdev-tc-offloads.c \
+ lib/netdev-tc-offloads.h \
lib/netlink-conntrack.c \
lib/netlink-conntrack.h \
lib/netlink-notifier.c \
netdev_bsd_rxq_recv, \
netdev_bsd_rxq_wait, \
netdev_bsd_rxq_drain, \
+ \
+ NO_OFFLOAD_API \
}
const struct netdev_class netdev_bsd_class =
RXQ_RECV, \
NULL, /* rx_wait */ \
NULL, /* rxq_drain */ \
+ NO_OFFLOAD_API \
}
static const struct netdev_class dpdk_class =
netdev_dummy_rxq_recv, \
netdev_dummy_rxq_wait, \
netdev_dummy_rxq_drain, \
+ \
+ NO_OFFLOAD_API \
}
static const struct netdev_class dummy_class =
#include "hash.h"
#include "openvswitch/hmap.h"
#include "netdev-provider.h"
+#include "netdev-tc-offloads.h"
#include "netdev-vport.h"
#include "netlink-notifier.h"
#include "netlink-socket.h"
}
#define NETDEV_LINUX_CLASS(NAME, CONSTRUCT, GET_STATS, \
- GET_FEATURES, GET_STATUS) \
+ GET_FEATURES, GET_STATUS, \
+ FLOW_OFFLOAD_API) \
{ \
NAME, \
false, /* is_pmd */ \
netdev_linux_rxq_recv, \
netdev_linux_rxq_wait, \
netdev_linux_rxq_drain, \
+ \
+ FLOW_OFFLOAD_API \
}
const struct netdev_class netdev_linux_class =
netdev_linux_construct,
netdev_linux_get_stats,
netdev_linux_get_features,
- netdev_linux_get_status);
+ netdev_linux_get_status,
+ LINUX_FLOW_OFFLOAD_API);
const struct netdev_class netdev_tap_class =
NETDEV_LINUX_CLASS(
netdev_linux_construct_tap,
netdev_tap_get_stats,
netdev_linux_get_features,
- netdev_linux_get_status);
+ netdev_linux_get_status,
+ NO_OFFLOAD_API);
const struct netdev_class netdev_internal_class =
NETDEV_LINUX_CLASS(
netdev_linux_construct,
netdev_internal_get_stats,
NULL, /* get_features */
- netdev_internal_get_status);
+ netdev_internal_get_status,
+ NO_OFFLOAD_API);
\f
#define CODEL_N_QUEUES 0x0000
int netdev_linux_ethtool_set_flag(struct netdev *netdev, uint32_t flag,
const char *flag_name, bool enable);
+#define LINUX_FLOW_OFFLOAD_API \
+ netdev_tc_flow_flush, \
+ netdev_tc_flow_dump_create, \
+ netdev_tc_flow_dump_destroy, \
+ netdev_tc_flow_dump_next, \
+ netdev_tc_flow_put, \
+ netdev_tc_flow_get, \
+ netdev_tc_flow_del, \
+ netdev_tc_init_flow_api
#endif /* netdev-linux.h */
struct netdev *netdev_rxq_get_netdev(const struct netdev_rxq *);
+
+struct netdev_flow_dump {
+ struct netdev *netdev;
+ odp_port_t port;
+ struct nl_dump *nl_dump;
+ bool terse;
+};
+
/* Network device class structure, to be defined by each implementation of a
* network device.
*
/* Discards all packets waiting to be received from 'rx'. */
int (*rxq_drain)(struct netdev_rxq *rx);
+
+ /* ## -------------------------------- ## */
+ /* ## netdev flow offloading functions ## */
+ /* ## -------------------------------- ## */
+
+ /* If a particular netdev class does not support offloading flows,
+ * all these function pointers must be NULL. */
+
+ /* Flush all offloaded flows from a netdev.
+ * Return 0 if successful, otherwise returns a positive errno value. */
+ int (*flow_flush)(struct netdev *);
+
+ /* Flow dumping interface.
+ *
+ * This is the back-end for the flow dumping interface described in
+ * dpif.h. Please read the comments there first, because this code
+ * closely follows it.
+ *
+ * On success returns 0 and allocates data, on failure returns
+ * positive errno. */
+ int (*flow_dump_create)(struct netdev *, struct netdev_flow_dump **dump);
+ int (*flow_dump_destroy)(struct netdev_flow_dump *);
+
+ /* Returns true if there are more flows to dump.
+ * 'rbuffer' is used as a temporary buffer and needs to be pre allocated
+ * by the caller. While there are more flows the same 'rbuffer'
+ * should be provided. 'wbuffer' is used to store dumped actions and needs
+ * to be pre allocated by the caller. */
+ bool (*flow_dump_next)(struct netdev_flow_dump *, struct match *,
+ struct nlattr **actions,
+ struct dpif_flow_stats *stats, ovs_u128 *ufid,
+ struct ofpbuf *rbuffer, struct ofpbuf *wbuffer);
+
+ /* Offload the given flow on netdev.
+ * To modify a flow, use the same ufid.
+ * 'actions' are in netlink format, as with struct dpif_flow_put.
+ * 'info' is extra info needed to offload the flow.
+ * 'stats' is populated according to the rules set out in the description
+ * above 'struct dpif_flow_put'.
+ * Return 0 if successful, otherwise returns a positive errno value. */
+ int (*flow_put)(struct netdev *, struct match *, struct nlattr *actions,
+ size_t actions_len, const ovs_u128 *ufid,
+ struct offload_info *info, struct dpif_flow_stats *);
+
+ /* Queries a flow specified by ufid on netdev.
+ * Fills output buffer as 'wbuffer' in flow_dump_next, which
+ * needs to be be pre allocated.
+ * Return 0 if successful, otherwise returns a positive errno value. */
+ int (*flow_get)(struct netdev *, struct match *, struct nlattr **actions,
+ const ovs_u128 *ufid, struct dpif_flow_stats *,
+ struct ofpbuf *wbuffer);
+
+ /* Delete a flow specified by ufid from netdev.
+ * 'stats' is populated according to the rules set out in the description
+ * above 'struct dpif_flow_del'.
+ * Return 0 if successful, otherwise returns a positive errno value. */
+ int (*flow_del)(struct netdev *, const ovs_u128 *ufid,
+ struct dpif_flow_stats *);
+
+ /* Initializies the netdev flow api.
+ * Return 0 if successful, otherwise returns a positive errno value. */
+ int (*init_flow_api)(struct netdev *);
};
int netdev_register_provider(const struct netdev_class *);
}
#endif
+#define NO_OFFLOAD_API NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
+
#endif /* netdev.h */
--- /dev/null
+/*
+ * Copyright (c) 2016 Mellanox Technologies, Ltd.
+ *
+ * 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 <config.h>
+#include "netdev-tc-offloads.h"
+#include <errno.h>
+#include <linux/if_ether.h>
+#include "openvswitch/hmap.h"
+#include "openvswitch/match.h"
+#include "openvswitch/ofpbuf.h"
+#include "openvswitch/thread.h"
+#include "openvswitch/types.h"
+#include "openvswitch/vlog.h"
+#include "netdev-provider.h"
+#include "netlink.h"
+#include "netlink-socket.h"
+#include "odp-netlink.h"
+#include "unaligned.h"
+#include "util.h"
+#include "hash.h"
+#include "dpif.h"
+#include "tc.h"
+
+VLOG_DEFINE_THIS_MODULE(netdev_tc_offloads);
+
+int
+netdev_tc_flow_flush(struct netdev *netdev OVS_UNUSED)
+{
+ return EOPNOTSUPP;
+}
+
+int
+netdev_tc_flow_dump_create(struct netdev *netdev,
+ struct netdev_flow_dump **dump_out)
+{
+ struct netdev_flow_dump *dump = xzalloc(sizeof *dump);
+
+ dump->netdev = netdev_ref(netdev);
+
+ *dump_out = dump;
+
+ return 0;
+}
+
+int
+netdev_tc_flow_dump_destroy(struct netdev_flow_dump *dump)
+{
+ netdev_close(dump->netdev);
+ free(dump);
+
+ return 0;
+}
+
+bool
+netdev_tc_flow_dump_next(struct netdev_flow_dump *dump OVS_UNUSED,
+ struct match *match OVS_UNUSED,
+ struct nlattr **actions OVS_UNUSED,
+ struct dpif_flow_stats *stats OVS_UNUSED,
+ ovs_u128 *ufid OVS_UNUSED,
+ struct ofpbuf *rbuffer OVS_UNUSED,
+ struct ofpbuf *wbuffer OVS_UNUSED)
+{
+ return false;
+}
+
+int
+netdev_tc_flow_put(struct netdev *netdev OVS_UNUSED,
+ struct match *match OVS_UNUSED,
+ struct nlattr *actions OVS_UNUSED,
+ size_t actions_len OVS_UNUSED,
+ const ovs_u128 *ufid OVS_UNUSED,
+ struct offload_info *info OVS_UNUSED,
+ struct dpif_flow_stats *stats OVS_UNUSED)
+{
+ return EOPNOTSUPP;
+}
+
+int
+netdev_tc_flow_get(struct netdev *netdev OVS_UNUSED,
+ struct match *match OVS_UNUSED,
+ struct nlattr **actions OVS_UNUSED,
+ const ovs_u128 *ufid OVS_UNUSED,
+ struct dpif_flow_stats *stats OVS_UNUSED,
+ struct ofpbuf *buf OVS_UNUSED)
+{
+ return EOPNOTSUPP;
+}
+
+int
+netdev_tc_flow_del(struct netdev *netdev OVS_UNUSED,
+ const ovs_u128 *ufid OVS_UNUSED,
+ struct dpif_flow_stats *stats OVS_UNUSED)
+{
+ return EOPNOTSUPP;
+}
+
+int
+netdev_tc_init_flow_api(struct netdev *netdev OVS_UNUSED)
+{
+ return 0;
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Mellanox Technologies, Ltd.
+ *
+ * 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 NETDEV_TC_OFFLOADS_H
+#define NETDEV_TC_OFFLOADS_H 1
+
+#include "netdev-provider.h"
+
+int netdev_tc_flow_flush(struct netdev *);
+int netdev_tc_flow_dump_create(struct netdev *, struct netdev_flow_dump **);
+int netdev_tc_flow_dump_destroy(struct netdev_flow_dump *);
+bool netdev_tc_flow_dump_next(struct netdev_flow_dump *, struct match *,
+ struct nlattr **actions,
+ struct dpif_flow_stats *,
+ ovs_u128 *ufid,
+ struct ofpbuf *rbuffer,
+ struct ofpbuf *wbuffer);
+int netdev_tc_flow_put(struct netdev *, struct match *,
+ struct nlattr *actions, size_t actions_len,
+ const ovs_u128 *, struct offload_info *,
+ struct dpif_flow_stats *);
+int netdev_tc_flow_get(struct netdev *, struct match *,
+ struct nlattr **actions, const ovs_u128 *,
+ struct dpif_flow_stats *, struct ofpbuf *);
+int netdev_tc_flow_del(struct netdev *, const ovs_u128 *,
+ struct dpif_flow_stats *);
+int netdev_tc_init_flow_api(struct netdev *);
+
+#endif /* netdev-tc-offloads.h */
NULL, /* rx_dealloc */ \
NULL, /* rx_recv */ \
NULL, /* rx_wait */ \
- NULL, /* rx_drain */
+ NULL, /* rx_drain */ \
+ \
+ NULL, /* flow_flush */ \
+ NULL, /* flow_dump_create */ \
+ NULL, /* flow_dump_destroy */ \
+ NULL, /* flow_dump_next */ \
+ NULL, /* flow_put */ \
+ NULL, /* flow_get */ \
+ NULL, /* flow_del */ \
+ NULL, /* init_flow_api */
#define TUNNEL_CLASS(NAME, DPIF_PORT, BUILD_HEADER, PUSH_HEADER, POP_HEADER) \
? class->reconfigure(netdev)
: EOPNOTSUPP);
}
+
+int
+netdev_flow_flush(struct netdev *netdev)
+{
+ const struct netdev_class *class = netdev->netdev_class;
+
+ return (class->flow_flush
+ ? class->flow_flush(netdev)
+ : EOPNOTSUPP);
+}
+
+int
+netdev_flow_dump_create(struct netdev *netdev, struct netdev_flow_dump **dump)
+{
+ const struct netdev_class *class = netdev->netdev_class;
+
+ return (class->flow_dump_create
+ ? class->flow_dump_create(netdev, dump)
+ : EOPNOTSUPP);
+}
+
+int
+netdev_flow_dump_destroy(struct netdev_flow_dump *dump)
+{
+ const struct netdev_class *class = dump->netdev->netdev_class;
+
+ return (class->flow_dump_destroy
+ ? class->flow_dump_destroy(dump)
+ : EOPNOTSUPP);
+}
+
+bool
+netdev_flow_dump_next(struct netdev_flow_dump *dump, struct match *match,
+ struct nlattr **actions, struct dpif_flow_stats *stats,
+ ovs_u128 *ufid, struct ofpbuf *rbuffer,
+ struct ofpbuf *wbuffer)
+{
+ const struct netdev_class *class = dump->netdev->netdev_class;
+
+ return (class->flow_dump_next
+ ? class->flow_dump_next(dump, match, actions, stats, ufid,
+ rbuffer, wbuffer)
+ : false);
+}
+
+int
+netdev_flow_put(struct netdev *netdev, struct match *match,
+ struct nlattr *actions, size_t act_len,
+ const ovs_u128 *ufid, struct offload_info *info,
+ struct dpif_flow_stats *stats)
+{
+ const struct netdev_class *class = netdev->netdev_class;
+
+ return (class->flow_put
+ ? class->flow_put(netdev, match, actions, act_len, ufid,
+ info, stats)
+ : EOPNOTSUPP);
+}
+
+int
+netdev_flow_get(struct netdev *netdev, struct match *match,
+ struct nlattr **actions, const ovs_u128 *ufid,
+ struct dpif_flow_stats *stats, struct ofpbuf *buf)
+{
+ const struct netdev_class *class = netdev->netdev_class;
+
+ return (class->flow_get
+ ? class->flow_get(netdev, match, actions, ufid, stats, buf)
+ : EOPNOTSUPP);
+}
+
+int
+netdev_flow_del(struct netdev *netdev, const ovs_u128 *ufid,
+ struct dpif_flow_stats *stats)
+{
+ const struct netdev_class *class = netdev->netdev_class;
+
+ return (class->flow_del
+ ? class->flow_del(netdev, ufid, stats)
+ : EOPNOTSUPP);
+}
+
+int
+netdev_init_flow_api(struct netdev *netdev)
+{
+ const struct netdev_class *class = netdev->netdev_class;
+
+ return (class->init_flow_api
+ ? class->init_flow_api(netdev)
+ : EOPNOTSUPP);
+}
bool may_steal, bool concurrent_txq);
void netdev_send_wait(struct netdev *, int qid);
+/* Flow offloading. */
+struct offload_info {
+ const void *port_hmap_obj; /* To query ports info from netdev port map */
+ ovs_be16 tp_dst_port; /* Destination port for tunnel in SET action */
+};
+struct netdev_flow_dump;
+int netdev_flow_flush(struct netdev *);
+int netdev_flow_dump_create(struct netdev *, struct netdev_flow_dump **dump);
+int netdev_flow_dump_destroy(struct netdev_flow_dump *);
+bool netdev_flow_dump_next(struct netdev_flow_dump *, struct match *,
+ struct nlattr **actions, struct dpif_flow_stats *,
+ ovs_u128 *ufid, struct ofpbuf *rbuffer,
+ struct ofpbuf *wbuffer);
+int netdev_flow_put(struct netdev *, struct match *, struct nlattr *actions,
+ size_t actions_len, const ovs_u128 *,
+ struct offload_info *, struct dpif_flow_stats *);
+int netdev_flow_get(struct netdev *, struct match *, struct nlattr **actions,
+ const ovs_u128 *, struct dpif_flow_stats *,
+ struct ofpbuf *wbuffer);
+int netdev_flow_del(struct netdev *, const ovs_u128 *,
+ struct dpif_flow_stats *);
+int netdev_init_flow_api(struct netdev *);
+
/* native tunnel APIs */
/* Structure to pass parameters required to build a tunnel header. */
struct netdev_tnl_build_header_params {