[ovs-dev] [PATCH v2] Make 100 percents packets sampled when sampling rate is 1.

Wenyu Zhang wenyuz at vmware.com
Mon Aug 3 06:54:09 UTC 2015


When sampling rate is 1, the sampling probability is UINT32_MAX. The packet
should be sampled even the prandom32() generate the number of UINT32_MAX.
And none packet need be sampled when the probability is 0.
---
 lib/odp-execute.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/lib/odp-execute.c b/lib/odp-execute.c
index c676451..3258639 100644
--- a/lib/odp-execute.c
+++ b/lib/odp-execute.c
@@ -435,13 +435,15 @@ odp_execute_sample(void *dp, struct dp_packet *packet, bool steal,
     const struct nlattr *subactions = NULL;
     const struct nlattr *a;
     size_t left;
-
+ 
     NL_NESTED_FOR_EACH_UNSAFE (a, left, action) {
         int type = nl_attr_type(a);
+        uint32_t probability;
 
         switch ((enum ovs_sample_attr) type) {
         case OVS_SAMPLE_ATTR_PROBABILITY:
-            if (random_uint32() >= nl_attr_get_u32(a)) {
+            probability = nl_attr_get_u32(a);
+            if (!probability || random_uint32() > probability) {
                 if (steal) {
                     dp_packet_delete(packet);
                 }
-- 
1.7.9.5




More information about the dev mailing list