[ovs-dev] [PATCH v9 03/11] dpif: Introduce register sFlow upcall callback API

Chris Mi cmi at nvidia.com
Tue Dec 15 03:38:04 UTC 2020


When offloading sample action to TC, psample sends the sampled packets
to userspace by a netlink message. The thread polling psample socket
will translate the psample netlink message to an sFlow format and call
the sFlow upcall callback to send the sFlow packet to right monitoring
host.

Introduce register sFlow upcall callback API.

Signed-off-by: Chris Mi <cmi at nvidia.com>
Reviewed-by: Eli Britstein <elibr at nvidia.com>
---
 lib/dpif-netdev.c   |  1 +
 lib/dpif-netlink.c  |  1 +
 lib/dpif-provider.h | 10 ++++++++++
 lib/dpif.c          |  8 ++++++++
 lib/dpif.h          | 23 +++++++++++++++++++++++
 5 files changed, 43 insertions(+)

diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c
index 300861ca5..f47a3fdab 100644
--- a/lib/dpif-netdev.c
+++ b/lib/dpif-netdev.c
@@ -8426,6 +8426,7 @@ const struct dpif_class dpif_netdev_class = {
     dpif_netdev_register_upcall_cb,
     dpif_netdev_enable_upcall,
     dpif_netdev_disable_upcall,
+    NULL,                       /* register_sflow_upcall_cb */
     dpif_netdev_get_datapath_version,
     dpif_netdev_ct_dump_start,
     dpif_netdev_ct_dump_next,
diff --git a/lib/dpif-netlink.c b/lib/dpif-netlink.c
index 6858ba612..2a47d483c 100644
--- a/lib/dpif-netlink.c
+++ b/lib/dpif-netlink.c
@@ -3987,6 +3987,7 @@ const struct dpif_class dpif_netlink_class = {
     NULL,                       /* register_upcall_cb */
     NULL,                       /* enable_upcall */
     NULL,                       /* disable_upcall */
+    NULL,                       /* register_sflow_upcall_cb */
     dpif_netlink_get_datapath_version, /* get_datapath_version */
     dpif_netlink_ct_dump_start,
     dpif_netlink_ct_dump_next,
diff --git a/lib/dpif-provider.h b/lib/dpif-provider.h
index b817fceac..589f11be4 100644
--- a/lib/dpif-provider.h
+++ b/lib/dpif-provider.h
@@ -427,6 +427,16 @@ struct dpif_class {
     /* Disables upcalls if 'dpif' directly executes upcall functions. */
     void (*disable_upcall)(struct dpif *);
 
+    /* When offloading sample action, psample sends the sampled packets to
+     * userspace by a netlink message. The thread polling psample socket
+     * will translate the psample netlink message to an sFlow format and call
+     * the sFlow upcall callback to send the sFlow packet to right monitoring
+     * host.
+     *
+     * Registers an upcall callback to process sFlow packet.
+     */
+    void (*register_sflow_upcall_cb)(struct dpif *, sflow_upcall_callback *);
+
     /* Get datapath version. Caller is responsible for freeing the string
      * returned.  */
     char *(*get_datapath_version)(void);
diff --git a/lib/dpif.c b/lib/dpif.c
index ac2860764..6e72b2087 100644
--- a/lib/dpif.c
+++ b/lib/dpif.c
@@ -1520,6 +1520,14 @@ dpif_disable_upcall(struct dpif *dpif)
     }
 }
 
+void
+dpif_register_sflow_upcall_cb(struct dpif *dpif, sflow_upcall_callback *cb)
+{
+    if (dpif->dpif_class->register_sflow_upcall_cb) {
+        dpif->dpif_class->register_sflow_upcall_cb(dpif, cb);
+    }
+}
+
 void
 dpif_print_packet(struct dpif *dpif, struct dpif_upcall *upcall)
 {
diff --git a/lib/dpif.h b/lib/dpif.h
index 7ef148c6d..7c6f5134a 100644
--- a/lib/dpif.h
+++ b/lib/dpif.h
@@ -870,6 +870,29 @@ typedef int upcall_callback(const struct dp_packet *packet,
 
 void dpif_register_upcall_cb(struct dpif *, upcall_callback *, void *aux);
 
+/* When offloading sample action, userspace creates a unique ID to map
+ * sFlow action and tunnel info and passes this ID to datapath instead
+ * of the sFlow info. Datapath will send this ID and sampled packet to
+ * userspace. Using the ID, userspace can recover the sFlow info and send
+ * sampled packet to the right sFlow monitoring host.
+ */
+struct dpif_sflow_attr {
+    const struct nlattr *sflow; /* sFlow action */
+    void *userdata;             /* struct user_action_cookie */
+    size_t userdata_len;        /* struct user_action_cookie length */
+    struct flow_tnl *tunnel;    /* Tunnel info */
+};
+
+/* A sampled packet passed up from datapath to userspace. */
+struct dpif_upcall_sflow {
+    struct dp_packet packet;    /* packet data */
+    uint32_t iifindex;          /* input ifindex */
+    const struct dpif_sflow_attr *sflow_attr;
+};
+
+typedef int sflow_upcall_callback(struct dpif_upcall_sflow *dupcall);
+void dpif_register_sflow_upcall_cb(struct dpif *, sflow_upcall_callback *);
+
 int dpif_recv_set(struct dpif *, bool enable);
 int dpif_handlers_set(struct dpif *, uint32_t n_handlers);
 int dpif_set_config(struct dpif *, const struct smap *cfg);
-- 
2.26.2



More information about the dev mailing list