[ovs-dev] [PATCH v3] ofproto-dpif-ipfix: add support for per-flow drop counters

Przemyslaw Szczerbik przemyslawx.szczerbik at intel.com
Fri Jul 28 06:17:44 UTC 2017


Patch based on RFC 5102, section 5.10. It implements per-flow drop counters:
- droppedPacketDeltaCount
- droppedPacketTotalCount
- droppedOctetDeltaCount
- droppedOctetTotalCount

In order to determine if packet is going to be dropped, flow actions associated
with packet are read. If at least one of the following conditions is met,
packet is not marked as dropped.

 Packet has at least one:
 - OVS_ACTION_ATTR_OUTPUT action
 - OVS_ACTION_ATTR_CLONE action with nested OVS_ACTION_ATTR_OUTPUT action
 - OVS_ACTION_ATTR_SAMPLE action with nested OVS_ACTION_ATTR_OUTPUT action and
   sampling probability is set to 100%

Signed-off-by: Przemyslaw Szczerbik <przemyslawx.szczerbik at intel.com>
---
v1->v2
* Prevent segfault when dereferencing ipfix_actions in ipfix_cache_entry_init
* Handle OVS_ACTION_ATTR_CLONE action

v2->v3
* Handle OVS_ACTION_ATTR_SAMPLE action

 ofproto/ofproto-dpif-ipfix.c  | 170 +++++++++++++++++++++++++++++++++++++++---
 ofproto/ofproto-dpif-ipfix.h  |  16 +++-
 ofproto/ofproto-dpif-upcall.c |  95 +++++++++++++++++------
 3 files changed, 247 insertions(+), 34 deletions(-)

diff --git a/ofproto/ofproto-dpif-ipfix.c b/ofproto/ofproto-dpif-ipfix.c
index 13ff426..eeee309 100644
--- a/ofproto/ofproto-dpif-ipfix.c
+++ b/ofproto/ofproto-dpif-ipfix.c
@@ -93,6 +93,8 @@ enum dpif_ipfix_tunnel_type {
 typedef struct ofputil_ipfix_stats ofproto_ipfix_stats;
 
 struct dpif_ipfix_global_stats {
+    uint64_t dropped_packet_total_count;
+    uint64_t dropped_octet_total_count;
     uint64_t packet_total_count;
     uint64_t octet_total_count;
     uint64_t octet_total_sum_of_squares;
@@ -409,6 +411,8 @@ OVS_PACKED(
 struct ipfix_data_record_aggregated_common {
     ovs_be32 flow_start_delta_microseconds; /* FLOW_START_DELTA_MICROSECONDS */
     ovs_be32 flow_end_delta_microseconds; /* FLOW_END_DELTA_MICROSECONDS */
+    ovs_be64 dropped_packet_delta_count;  /* DROPPED_PACKET_DELTA_COUNT */
+    ovs_be64 dropped_packet_total_count;  /* DROPPED_PACKET_TOTAL_COUNT */
     ovs_be64 packet_delta_count;  /* PACKET_DELTA_COUNT */
     ovs_be64 packet_total_count;  /* PACKET_TOTAL_COUNT */
     /* INGRESS_UNICAST_PACKET_TOTAL_COUNT */
@@ -427,11 +431,13 @@ struct ipfix_data_record_aggregated_common {
     ovs_be64 layer2_octet_total_count;  /* LAYER2_OCTET_TOTAL_COUNT */
     uint8_t flow_end_reason;  /* FLOW_END_REASON */
 });
-BUILD_ASSERT_DECL(sizeof(struct ipfix_data_record_aggregated_common) == 97);
+BUILD_ASSERT_DECL(sizeof(struct ipfix_data_record_aggregated_common) == 113);
 
 /* Part of data record for IP aggregated elements. */
 OVS_PACKED(
 struct ipfix_data_record_aggregated_ip {
+    ovs_be64 dropped_octet_delta_count;  /* DROPPED_OCTET_DELTA_COUNT */
+    ovs_be64 dropped_octet_total_count;  /* DROPPED_OCTET_TOTAL_COUNT */
     ovs_be64 octet_delta_count;  /* OCTET_DELTA_COUNT */
     ovs_be64 octet_total_count;  /* OCTET_TOTAL_COUNT */
     ovs_be64 octet_delta_sum_of_squares;  /* OCTET_DELTA_SUM_OF_SQUARES */
@@ -441,7 +447,7 @@ struct ipfix_data_record_aggregated_ip {
     ovs_be64 post_mcast_octet_delta_count; /* POST_MCAST_OCTET_DELTA_COUNT */
     ovs_be64 post_mcast_octet_total_count; /* POST_MCAST_OCTET_TOTAL_COUNT */
 });
-BUILD_ASSERT_DECL(sizeof(struct ipfix_data_record_aggregated_ip) == 64);
+BUILD_ASSERT_DECL(sizeof(struct ipfix_data_record_aggregated_ip) == 80);
 
 /* Part of data record for TCP aggregated elements. */
 OVS_PACKED(
@@ -541,6 +547,8 @@ struct ipfix_flow_cache_entry {
     /* Common aggregated elements. */
     uint64_t flow_start_timestamp_usec;
     uint64_t flow_end_timestamp_usec;
+    uint64_t dropped_packet_delta_count;
+    uint64_t dropped_packet_total_count;
     uint64_t packet_delta_count;
     uint64_t packet_total_count;
     uint64_t in_ucast_packet_total_count;
@@ -554,6 +562,8 @@ struct ipfix_flow_cache_entry {
     uint64_t post_mcast_octet_delta_count;
     uint64_t layer2_octet_delta_count;
     uint64_t layer2_octet_total_count;
+    uint64_t dropped_octet_delta_count;
+    uint64_t dropped_octet_total_count;
     uint64_t octet_delta_count;
     uint64_t octet_total_count;
     uint64_t octet_delta_sum_of_squares;  /* 0 if not IP. */
@@ -1394,6 +1404,8 @@ ipfix_define_template_fields(enum ipfix_proto_l2 l2, enum ipfix_proto_l3 l3,
 
     DEF(FLOW_START_DELTA_MICROSECONDS);
     DEF(FLOW_END_DELTA_MICROSECONDS);
+    DEF(DROPPED_PACKET_DELTA_COUNT);
+    DEF(DROPPED_PACKET_TOTAL_COUNT);
     DEF(PACKET_DELTA_COUNT);
     DEF(PACKET_TOTAL_COUNT);
     DEF(INGRESS_UNICAST_PACKET_TOTAL_COUNT);
@@ -1408,6 +1420,8 @@ ipfix_define_template_fields(enum ipfix_proto_l2 l2, enum ipfix_proto_l3 l3,
     DEF(FLOW_END_REASON);
 
     if (l3 != IPFIX_PROTO_L3_UNKNOWN) {
+        DEF(DROPPED_OCTET_DELTA_COUNT);
+        DEF(DROPPED_OCTET_TOTAL_COUNT);
         DEF(OCTET_DELTA_COUNT);
         DEF(OCTET_TOTAL_COUNT);
         DEF(OCTET_DELTA_SUM_OF_SQUARES);
@@ -1687,9 +1701,14 @@ ipfix_cache_aggregate_entries(struct ipfix_flow_cache_entry *from_entry,
         *to_end = *from_end;
     }
 
+
+    to_entry->dropped_packet_delta_count +=
+        from_entry->dropped_packet_delta_count;
     to_entry->packet_delta_count += from_entry->packet_delta_count;
     to_entry->layer2_octet_delta_count += from_entry->layer2_octet_delta_count;
 
+    to_entry->dropped_packet_total_count =
+        from_entry->dropped_packet_total_count;
     to_entry->packet_total_count = from_entry->packet_total_count;
     to_entry->in_ucast_packet_total_count =
         from_entry->in_ucast_packet_total_count;
@@ -1707,10 +1726,14 @@ ipfix_cache_aggregate_entries(struct ipfix_flow_cache_entry *from_entry,
     to_entry->post_mcast_octet_delta_count +=
         from_entry->post_mcast_octet_delta_count;
 
+    to_entry->dropped_octet_delta_count +=
+        from_entry->dropped_octet_delta_count;
     to_entry->octet_delta_count += from_entry->octet_delta_count;
     to_entry->octet_delta_sum_of_squares +=
         from_entry->octet_delta_sum_of_squares;
 
+    to_entry->dropped_octet_total_count =
+        from_entry->dropped_octet_total_count;
     to_entry->octet_total_count = from_entry->octet_total_count;
     to_entry->octet_total_sum_of_squares =
         from_entry->octet_total_sum_of_squares;
@@ -1886,7 +1909,8 @@ ipfix_cache_entry_init(struct ipfix_flow_cache_entry *entry,
                        enum nx_action_sample_direction direction,
                        const struct dpif_ipfix_port *tunnel_port,
                        const struct flow_tnl *tunnel_key,
-                       struct dpif_ipfix_global_stats *stats)
+                       struct dpif_ipfix_global_stats *stats,
+                       const struct dpif_ipfix_actions *ipfix_actions)
 {
     struct ipfix_flow_key *flow_key;
     struct dp_packet msg;
@@ -2090,9 +2114,17 @@ ipfix_cache_entry_init(struct ipfix_flow_cache_entry *entry,
         xgettimeofday(&now);
         entry->flow_end_timestamp_usec = now.tv_usec + 1000000LL * now.tv_sec;
         entry->flow_start_timestamp_usec = entry->flow_end_timestamp_usec;
+
+        if (ipfix_actions && ipfix_actions->output_action) {
+            entry->dropped_packet_delta_count = 0;
+        } else {
+            entry->dropped_packet_delta_count = packet_delta_count;
+        }
+
         entry->packet_delta_count = packet_delta_count;
         entry->layer2_octet_delta_count = layer2_octet_delta_count;
 
+        stats->dropped_packet_total_count += entry->dropped_packet_delta_count;
         stats->packet_total_count += packet_delta_count;
         stats->layer2_octet_total_count += layer2_octet_delta_count;
 
@@ -2118,6 +2150,7 @@ ipfix_cache_entry_init(struct ipfix_flow_cache_entry *entry,
             }
         }
 
+        entry->dropped_packet_total_count = stats->dropped_packet_total_count;
         entry->packet_total_count = stats->packet_total_count;
         entry->in_ucast_packet_total_count =
             stats->in_ucast_packet_total_count;
@@ -2144,11 +2177,18 @@ ipfix_cache_entry_init(struct ipfix_flow_cache_entry *entry,
          * length. */
         octet_delta_count = packet_delta_count * ip_total_length;
 
+        if (ipfix_actions && ipfix_actions->output_action) {
+            entry->dropped_octet_delta_count = 0;
+        } else {
+            entry->dropped_octet_delta_count = octet_delta_count;
+        }
+
         entry->octet_delta_count = octet_delta_count;
         entry->octet_delta_sum_of_squares = octet_delta_count * ip_total_length;
         entry->minimum_ip_total_length = ip_total_length;
         entry->maximum_ip_total_length = ip_total_length;
 
+        stats->dropped_octet_total_count += entry->dropped_octet_delta_count;
         stats->octet_total_count += octet_delta_count;
         stats->octet_total_sum_of_squares += entry->octet_delta_sum_of_squares;
 
@@ -2164,6 +2204,7 @@ ipfix_cache_entry_init(struct ipfix_flow_cache_entry *entry,
         entry->maximum_ip_total_length = 0;
     }
 
+    entry->dropped_octet_total_count = stats->dropped_octet_total_count;
     entry->octet_total_sum_of_squares = stats->octet_total_sum_of_squares;
     entry->octet_total_count = stats->octet_total_count;
     entry->post_mcast_octet_total_count =
@@ -2256,6 +2297,10 @@ ipfix_put_data_set(uint32_t export_time_sec,
             flow_start_delta_usec);
         data_aggregated_common->flow_end_delta_microseconds = htonl(
             flow_end_delta_usec);
+        data_aggregated_common->dropped_packet_delta_count = htonll(
+            entry->dropped_packet_delta_count);
+        data_aggregated_common->dropped_packet_total_count = htonll(
+            entry->dropped_packet_total_count);
         data_aggregated_common->packet_delta_count = htonll(
             entry->packet_delta_count);
         data_aggregated_common->packet_total_count = htonll(
@@ -2286,6 +2331,10 @@ ipfix_put_data_set(uint32_t export_time_sec,
 
         data_aggregated_ip = dp_packet_put_zeros(
             msg, sizeof *data_aggregated_ip);
+        data_aggregated_ip->dropped_octet_delta_count = htonll(
+            entry->dropped_octet_delta_count);
+        data_aggregated_ip->dropped_octet_total_count = htonll(
+            entry->dropped_octet_total_count);
         data_aggregated_ip->octet_delta_count = htonll(
             entry->octet_delta_count);
         data_aggregated_ip->octet_total_count = htonll(
@@ -2420,7 +2469,8 @@ dpif_ipfix_sample(struct dpif_ipfix_exporter *exporter,
                   uint32_t obs_point_id, odp_port_t output_odp_port,
                   enum nx_action_sample_direction direction,
                   const struct dpif_ipfix_port *tunnel_port,
-                  const struct flow_tnl *tunnel_key)
+                  const struct flow_tnl *tunnel_key,
+                  const struct dpif_ipfix_actions *ipfix_actions)
 {
     struct ipfix_flow_cache_entry *entry;
     enum ipfix_sampled_packet_type sampled_packet_type;
@@ -2433,7 +2483,8 @@ dpif_ipfix_sample(struct dpif_ipfix_exporter *exporter,
                                    obs_domain_id, obs_point_id,
                                    output_odp_port, direction,
                                    tunnel_port, tunnel_key,
-                                   &exporter->ipfix_global_stats);
+                                   &exporter->ipfix_global_stats,
+                                   ipfix_actions);
 
     ipfix_cache_update(exporter, entry, sampled_packet_type);
 }
@@ -2448,7 +2499,8 @@ void
 dpif_ipfix_bridge_sample(struct dpif_ipfix *di, const struct dp_packet *packet,
                          const struct flow *flow,
                          odp_port_t input_odp_port, odp_port_t output_odp_port,
-                         const struct flow_tnl *output_tunnel_key)
+                         const struct flow_tnl *output_tunnel_key,
+                         const struct dpif_ipfix_actions *ipfix_actions)
     OVS_EXCLUDED(mutex)
 {
     uint64_t packet_delta_count;
@@ -2498,7 +2550,7 @@ dpif_ipfix_bridge_sample(struct dpif_ipfix *di, const struct dp_packet *packet,
                       di->bridge_exporter.options->obs_domain_id,
                       di->bridge_exporter.options->obs_point_id,
                       output_odp_port, NX_ACTION_SAMPLE_DEFAULT,
-                      tunnel_port, tunnel_key);
+                      tunnel_port, tunnel_key, ipfix_actions);
     ovs_mutex_unlock(&mutex);
 }
 
@@ -2507,7 +2559,8 @@ dpif_ipfix_flow_sample(struct dpif_ipfix *di, const struct dp_packet *packet,
                        const struct flow *flow,
                        const union user_action_cookie *cookie,
                        odp_port_t input_odp_port,
-                       const struct flow_tnl *output_tunnel_key)
+                       const struct flow_tnl *output_tunnel_key,
+                       const struct dpif_ipfix_actions *ipfix_actions)
     OVS_EXCLUDED(mutex)
 {
     struct dpif_ipfix_flow_exporter_map_node *node;
@@ -2542,7 +2595,7 @@ dpif_ipfix_flow_sample(struct dpif_ipfix *di, const struct dp_packet *packet,
                           cookie->flow_sample.obs_domain_id,
                           cookie->flow_sample.obs_point_id,
                           output_odp_port, cookie->flow_sample.direction,
-                          tunnel_port, tunnel_key);
+                          tunnel_port, tunnel_key, ipfix_actions);
     }
     ovs_mutex_unlock(&mutex);
 }
@@ -2679,3 +2732,102 @@ dpif_ipfix_wait(struct dpif_ipfix *di) OVS_EXCLUDED(mutex)
     }
     ovs_mutex_unlock(&mutex);
 }
+
+static void
+dpif_ipfix_read_sample_actions(const struct flow *flow,
+                               const struct nlattr *actions,
+                               size_t actions_len,
+                               struct dpif_ipfix_actions *ipfix_actions)
+{
+    const struct nlattr *a;
+    unsigned int left;
+    uint32_t probability = 0;
+    struct dpif_ipfix_actions sample_actions = {0};
+
+    if (actions_len == 0) {
+        return;
+    }
+
+    NL_ATTR_FOR_EACH(a, left, actions, actions_len) {
+
+        enum ovs_sample_attr type = nl_attr_type(a);
+        switch (type) {
+        case OVS_SAMPLE_ATTR_PROBABILITY:
+            probability = nl_attr_get_u32(a);
+            break;
+
+        case OVS_SAMPLE_ATTR_ACTIONS:
+            dpif_ipfix_read_actions(flow, nl_attr_get(a), nl_attr_get_size(a),
+                                    &sample_actions);
+            break;
+
+        case OVS_SAMPLE_ATTR_UNSPEC:
+        case __OVS_SAMPLE_ATTR_MAX:
+        default:
+            OVS_NOT_REACHED();
+        }
+    }
+
+    /* An output action inside sample action is truly an output if the sampling
+     * probability is set to 100% */
+    if (probability == UINT32_MAX && sample_actions.output_action == true) {
+        ipfix_actions->output_action = true;
+    }
+}
+
+void
+dpif_ipfix_read_actions(const struct flow *flow,
+                        const struct nlattr *actions,
+                        size_t actions_len,
+                        struct dpif_ipfix_actions *ipfix_actions)
+{
+    const struct nlattr *a;
+    unsigned int left;
+
+    if (actions_len == 0) {
+        return;
+    }
+
+    NL_ATTR_FOR_EACH (a, left, actions, actions_len) {
+        enum ovs_action_attr type = nl_attr_type(a);
+        switch (type) {
+        case OVS_ACTION_ATTR_OUTPUT:
+            ipfix_actions->output_action = true;
+            break;
+        case OVS_ACTION_ATTR_SAMPLE:
+            dpif_ipfix_read_sample_actions(flow, nl_attr_get(a),
+                                           nl_attr_get_size(a), ipfix_actions);
+            break;
+        case OVS_ACTION_ATTR_CLONE:
+            dpif_ipfix_read_actions(flow, nl_attr_get(a), nl_attr_get_size(a),
+                                    ipfix_actions);
+            break;
+
+        /* OVS_ACTION_ATTR_USERSPACE and OVS_ACTION_ATTR_RECIRC actions can
+         * yield absolutely any kind of behavior. Let's assume that flow drops
+         * the packet if there isn't another clear OVS_ACTION_ATTR_OUTPUT
+         * action associated with packet */
+        case OVS_ACTION_ATTR_USERSPACE:
+        case OVS_ACTION_ATTR_RECIRC:
+
+        case OVS_ACTION_ATTR_TUNNEL_POP:
+        case OVS_ACTION_ATTR_TUNNEL_PUSH:
+        case OVS_ACTION_ATTR_TRUNC:
+        case OVS_ACTION_ATTR_HASH:
+        case OVS_ACTION_ATTR_CT:
+        case OVS_ACTION_ATTR_METER:
+        case OVS_ACTION_ATTR_SET_MASKED:
+        case OVS_ACTION_ATTR_SET:
+        case OVS_ACTION_ATTR_PUSH_VLAN:
+        case OVS_ACTION_ATTR_POP_VLAN:
+        case OVS_ACTION_ATTR_PUSH_MPLS:
+        case OVS_ACTION_ATTR_POP_MPLS:
+        case OVS_ACTION_ATTR_PUSH_ETH:
+        case OVS_ACTION_ATTR_POP_ETH:
+        case OVS_ACTION_ATTR_UNSPEC:
+        case __OVS_ACTION_ATTR_MAX:
+        default:
+            break;
+        }
+    }
+}
diff --git a/ofproto/ofproto-dpif-ipfix.h b/ofproto/ofproto-dpif-ipfix.h
index 0808ede..f91d041 100644
--- a/ofproto/ofproto-dpif-ipfix.h
+++ b/ofproto/ofproto-dpif-ipfix.h
@@ -29,6 +29,11 @@ struct ofproto_ipfix_flow_exporter_options;
 struct flow_tnl;
 struct ofport;
 
+struct dpif_ipfix_actions {
+    bool output_action;     /* Set to true if packet has at least one
+                               OVS_ACTION_ATTR_OUTPUT action. */
+};
+
 struct dpif_ipfix *dpif_ipfix_create(void);
 struct dpif_ipfix *dpif_ipfix_ref(const struct dpif_ipfix *);
 void dpif_ipfix_unref(struct dpif_ipfix *);
@@ -52,12 +57,19 @@ int dpif_ipfix_get_stats(const struct dpif_ipfix *, bool, struct ovs_list *);
 
 void dpif_ipfix_bridge_sample(struct dpif_ipfix *, const struct dp_packet *,
                               const struct flow *,
-                              odp_port_t, odp_port_t, const struct flow_tnl *);
+                              odp_port_t, odp_port_t, const struct flow_tnl *,
+                              const struct dpif_ipfix_actions *);
 void dpif_ipfix_flow_sample(struct dpif_ipfix *, const struct dp_packet *,
                             const struct flow *, const union user_action_cookie *,
-                            odp_port_t, const struct flow_tnl *);
+                            odp_port_t, const struct flow_tnl *,
+                            const struct dpif_ipfix_actions *);
 
 void dpif_ipfix_run(struct dpif_ipfix *);
 void dpif_ipfix_wait(struct dpif_ipfix *);
 
+void dpif_ipfix_read_actions(const struct flow *flow,
+                             const struct nlattr *actions,
+                             size_t actions_len,
+                             struct dpif_ipfix_actions *ipfix_actions);
+
 #endif /* ofproto/ofproto-dpif-ipfix.h */
diff --git a/ofproto/ofproto-dpif-upcall.c b/ofproto/ofproto-dpif-upcall.c
index b2f9d91..ea517a9 100644
--- a/ofproto/ofproto-dpif-upcall.c
+++ b/ofproto/ofproto-dpif-upcall.c
@@ -1279,6 +1279,59 @@ out:
     return error;
 }
 
+static size_t
+dpif_get_actions(struct udpif *udpif, struct upcall *upcall,
+                 const struct nlattr **actions)
+{
+    size_t actions_len = 0;
+
+    if (upcall->actions) {
+        /* Actions were passed up from datapath. */
+        *actions = nl_attr_get(upcall->actions);
+        actions_len = nl_attr_get_size(upcall->actions);
+    }
+
+    if (actions_len == 0) {
+        /* Lookup actions in userspace cache. */
+        struct udpif_key *ukey = ukey_lookup(udpif, upcall->ufid,
+                                             upcall->pmd_id);
+        if (ukey) {
+            ukey_get_actions(ukey, actions, &actions_len);
+        }
+    }
+
+    return actions_len;
+}
+
+static size_t
+dpif_read_actions(struct udpif *udpif, struct upcall *upcall,
+                  const struct flow *flow, enum upcall_type type,
+                  void *upcall_data)
+{
+    const struct nlattr *actions = NULL;
+    size_t actions_len = dpif_get_actions(udpif, upcall, &actions);
+
+    if (!actions || !actions_len) {
+        return 0;
+    }
+
+    switch (type) {
+    case SFLOW_UPCALL:
+        dpif_sflow_read_actions(flow, actions, actions_len, upcall_data);
+        break;
+    case FLOW_SAMPLE_UPCALL:
+    case IPFIX_UPCALL:
+        dpif_ipfix_read_actions(flow, actions, actions_len, upcall_data);
+        break;
+    case BAD_UPCALL:
+    case MISS_UPCALL:
+    default:
+        break;
+    }
+
+    return actions_len;
+}
+
 static int
 process_upcall(struct udpif *udpif, struct upcall *upcall,
                struct ofpbuf *odp_actions, struct flow_wildcards *wc)
@@ -1286,8 +1339,10 @@ process_upcall(struct udpif *udpif, struct upcall *upcall,
     const struct nlattr *userdata = upcall->userdata;
     const struct dp_packet *packet = upcall->packet;
     const struct flow *flow = upcall->flow;
+    size_t actions_len = 0;
+    enum upcall_type upcall_type = classify_upcall(upcall->type, userdata);
 
-    switch (classify_upcall(upcall->type, userdata)) {
+    switch (upcall_type) {
     case MISS_UPCALL:
         upcall_xlate(udpif, upcall, odp_actions, wc);
         return 0;
@@ -1295,31 +1350,14 @@ process_upcall(struct udpif *udpif, struct upcall *upcall,
     case SFLOW_UPCALL:
         if (upcall->sflow) {
             union user_action_cookie cookie;
-            const struct nlattr *actions;
-            size_t actions_len = 0;
             struct dpif_sflow_actions sflow_actions;
+
             memset(&sflow_actions, 0, sizeof sflow_actions);
             memset(&cookie, 0, sizeof cookie);
             memcpy(&cookie, nl_attr_get(userdata), sizeof cookie.sflow);
-            if (upcall->actions) {
-                /* Actions were passed up from datapath. */
-                actions = nl_attr_get(upcall->actions);
-                actions_len = nl_attr_get_size(upcall->actions);
-                if (actions && actions_len) {
-                    dpif_sflow_read_actions(flow, actions, actions_len,
-                                            &sflow_actions);
-                }
-            }
-            if (actions_len == 0) {
-                /* Lookup actions in userspace cache. */
-                struct udpif_key *ukey = ukey_lookup(udpif, upcall->ufid,
-                                                     upcall->pmd_id);
-                if (ukey) {
-                    ukey_get_actions(ukey, &actions, &actions_len);
-                    dpif_sflow_read_actions(flow, actions, actions_len,
+
+            actions_len = dpif_read_actions(udpif, upcall, flow, upcall_type,
                                             &sflow_actions);
-                }
-            }
             dpif_sflow_received(upcall->sflow, packet, flow,
                                 flow->in_port.odp_port, &cookie,
                                 actions_len > 0 ? &sflow_actions : NULL);
@@ -1330,18 +1368,24 @@ process_upcall(struct udpif *udpif, struct upcall *upcall,
         if (upcall->ipfix) {
             union user_action_cookie cookie;
             struct flow_tnl output_tunnel_key;
+            struct dpif_ipfix_actions ipfix_actions;
 
             memset(&cookie, 0, sizeof cookie);
             memcpy(&cookie, nl_attr_get(userdata), sizeof cookie.ipfix);
+            memset(&ipfix_actions, 0, sizeof ipfix_actions);
 
             if (upcall->out_tun_key) {
                 odp_tun_key_from_attr(upcall->out_tun_key, &output_tunnel_key);
             }
+
+            actions_len = dpif_read_actions(udpif, upcall, flow, upcall_type,
+                                            &ipfix_actions);
             dpif_ipfix_bridge_sample(upcall->ipfix, packet, flow,
                                      flow->in_port.odp_port,
                                      cookie.ipfix.output_odp_port,
                                      upcall->out_tun_key ?
-                                         &output_tunnel_key : NULL);
+                                         &output_tunnel_key : NULL,
+                                     actions_len > 0 ? &ipfix_actions: NULL);
         }
         break;
 
@@ -1349,20 +1393,25 @@ process_upcall(struct udpif *udpif, struct upcall *upcall,
         if (upcall->ipfix) {
             union user_action_cookie cookie;
             struct flow_tnl output_tunnel_key;
+            struct dpif_ipfix_actions ipfix_actions;
 
             memset(&cookie, 0, sizeof cookie);
             memcpy(&cookie, nl_attr_get(userdata), sizeof cookie.flow_sample);
+            memset(&ipfix_actions, 0, sizeof ipfix_actions);
 
             if (upcall->out_tun_key) {
                 odp_tun_key_from_attr(upcall->out_tun_key, &output_tunnel_key);
             }
 
+            actions_len = dpif_read_actions(udpif, upcall, flow, upcall_type,
+                                            &ipfix_actions);
             /* The flow reflects exactly the contents of the packet.
              * Sample the packet using it. */
             dpif_ipfix_flow_sample(upcall->ipfix, packet, flow,
                                    &cookie, flow->in_port.odp_port,
                                    upcall->out_tun_key ?
-                                       &output_tunnel_key : NULL);
+                                       &output_tunnel_key : NULL,
+                                   actions_len > 0 ? &ipfix_actions: NULL);
         }
         break;
 
-- 
1.8.3.1

--------------------------------------------------------------
Intel Research and Development Ireland Limited
Registered in Ireland
Registered Office: Collinstown Industrial Park, Leixlip, County Kildare
Registered Number: 308263


This e-mail and any attachments may contain confidential material for the sole
use of the intended recipient(s). Any review or distribution by others is
strictly prohibited. If you are not the intended recipient, please contact the
sender and delete all copies.



More information about the dev mailing list