From 6a0a5bbbca747ef3b12bb6810cc5e16a5fd7068e Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Mon, 13 Aug 2012 09:41:59 -0700 Subject: [PATCH] ofproto-dpif: Make sure one-packet flows have zero duration. A Nicira internal build recently failed the "ofproto-dpif - NetFlow flow expiration" test because of the following difference in output: header: v5, seq 0, engine 2,1 -rec: [...], 1 pkts, 60 bytes, ICMP 8:0, time +rec: [...], 1 pkts, 60 bytes, ICMP 8:0, time Looking at the actual output, it is: rec: 192.168.0.1 > 192.168.0.2, if 1 > 65535, 1 pkts, 60 bytes, ICMP 8:0, time 8...9 That is, a one-packet flow was shown to have more than a momentary duration, which doesn't make sense. This commit fixes the problem by making sure that creating a facet and then its initial subfacet only checks the current time once. Signed-off-by: Ben Pfaff --- ofproto/ofproto-dpif.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c index 6da74c48..77378004 100644 --- a/ofproto/ofproto-dpif.c +++ b/ofproto/ofproto-dpif.c @@ -4257,6 +4257,14 @@ subfacet_create(struct facet *facet, enum odp_key_fitness key_fitness, if (list_is_empty(&facet->subfacets)) { subfacet = &facet->one_subfacet; + + /* This subfacet should conceptually be created, and have its first + * packet pass through, at the same time that its facet was created. + * If we called time_msec() here, then the subfacet could look + * (occasionally) as though it was used some time after the facet was + * used. That can make a one-packet flow look like it has a nonzero + * duration, which looks odd in e.g. NetFlow statistics. */ + subfacet->used = facet->used; } else { subfacet = subfacet_find__(ofproto, key, key_len, key_hash, &facet->flow); @@ -4271,6 +4279,7 @@ subfacet_create(struct facet *facet, enum odp_key_fitness key_fitness, } subfacet = xmalloc(sizeof *subfacet); + subfacet->used = time_msec(); } hmap_insert(&ofproto->subfacets, &subfacet->hmap_node, key_hash); @@ -4284,7 +4293,6 @@ subfacet_create(struct facet *facet, enum odp_key_fitness key_fitness, subfacet->key = NULL; subfacet->key_len = 0; } - subfacet->used = time_msec(); subfacet->dp_packet_count = 0; subfacet->dp_byte_count = 0; subfacet->actions_len = 0; -- 2.30.2