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

Wenyu Zhang wenyuz at vmware.com
Thu Jul 30 07:02:34 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 no packet need be sampled when the probability is 0.

Signed-off-by: Wenyu Zhang <wenyuz at vmware.com>
---
 datapath/actions.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/datapath/actions.c b/datapath/actions.c
index 4941ca0..456f56b 100644
--- a/datapath/actions.c
+++ b/datapath/actions.c
@@ -675,12 +675,14 @@ static int sample(struct datapath *dp, struct sk_buff *skb,
 	const struct nlattr *acts_list = NULL;
 	const struct nlattr *a;
 	int rem;
+	uint32_t probability;
 
 	for (a = nla_data(attr), rem = nla_len(attr); rem > 0;
 		 a = nla_next(a, &rem)) {
 		switch (nla_type(a)) {
 		case OVS_SAMPLE_ATTR_PROBABILITY:
-			if (prandom_u32() >= nla_get_u32(a))
+			probability = nla_get_u32(a);
+			if (!probability || (prandom_u32() > probability))
 				return 0;
 			break;
 
-- 
1.7.9.5




More information about the dev mailing list