From patchwork Tue Sep 5 23:53:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Kumar X-Patchwork-Id: 810334 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xn3Sd4KS0z9t2W for ; Wed, 6 Sep 2017 09:53:20 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 37DE6A88; Tue, 5 Sep 2017 23:53:17 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 01D0394B for ; Tue, 5 Sep 2017 23:53:16 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from EX13-EDG-OU-001.vmware.com (ex13-edg-ou-001.vmware.com [208.91.0.189]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 6B7F0463 for ; Tue, 5 Sep 2017 23:53:15 +0000 (UTC) Received: from sc9-mailhost2.vmware.com (10.113.161.72) by EX13-EDG-OU-001.vmware.com (10.113.208.155) with Microsoft SMTP Server id 15.0.1156.6; Tue, 5 Sep 2017 16:53:07 -0700 Received: from localhost.localdomain (htb-1s-eng-dhcp106.eng.vmware.com [10.33.78.106]) by sc9-mailhost2.vmware.com (Postfix) with ESMTP id 9AF1AB0030; Tue, 5 Sep 2017 16:53:14 -0700 (PDT) From: Anand Kumar To: Date: Tue, 5 Sep 2017 16:53:04 -0700 Message-ID: <20170905235304.4016-1-kumaranand@vmware.com> X-Mailer: git-send-email 2.9.3.windows.1 MIME-Version: 1.0 Received-SPF: None (EX13-EDG-OU-001.vmware.com: kumaranand@vmware.com does not designate permitted sender hosts) X-Spam-Status: No, score=-2.3 required=5.0 tests=RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD autolearn=disabled version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH] datapath-windows: Increment ct packet counters based on ct_state. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org For a given packet, packet counters in conntrack should be accounted only once, even if the packet is processed multiple times by conntrack. When a packet is processed by conntrack, ct_state flag is set to OVS_CS_F_TRACKED. Use this state to identify if a packet has been processed previously by conntrack. Also update the ct packet counters when ct entry is created. With this patch, the conntrack's packet counters behavior is similar to linux Signed-off-by: Anand Kumar Acked-by: Shashank Ram Acked-by: Sairam Venugopal Acked-by: Alin Serdean --- datapath-windows/ovsext/Conntrack.c | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/datapath-windows/ovsext/Conntrack.c b/datapath-windows/ovsext/Conntrack.c index 8bcda05..0adb6d5 100644 --- a/datapath-windows/ovsext/Conntrack.c +++ b/datapath-windows/ovsext/Conntrack.c @@ -169,6 +169,18 @@ OvsPostCtEventEntry(POVS_CT_ENTRY entry, UINT8 type) OvsPostCtEvent(&ctEventEntry); } +static __inline VOID +OvsCtIncrementCounters(POVS_CT_ENTRY entry, BOOLEAN reply, PNET_BUFFER_LIST nbl) +{ + if (reply) { + entry->rev_key.byteCount+= OvsPacketLenNBL(nbl); + entry->rev_key.packetCount++; + } else { + entry->key.byteCount += OvsPacketLenNBL(nbl); + entry->key.packetCount++; + } +} + static __inline BOOLEAN OvsCtAddEntry(POVS_CT_ENTRY entry, OvsConntrackKeyLookupCtx *ctx, PNAT_ACTION_INFO natInfo, UINT64 now) @@ -287,6 +299,9 @@ OvsCtEntryCreate(OvsForwardingContext *fwdCtx, } OvsCtUpdateFlowKey(key, state, ctx->key.zone, 0, NULL); + if (entry) { + OvsCtIncrementCounters(entry, ctx->reply, curNbl); + } return entry; } @@ -382,18 +397,6 @@ OvsCtKeyAreSame(OVS_CT_KEY ctxKey, OVS_CT_KEY entryKey) (ctxKey.zone == entryKey.zone)); } -static __inline VOID -OvsCtIncrementCounters(POVS_CT_ENTRY entry, BOOLEAN reply, PNET_BUFFER_LIST nbl) -{ - if (reply) { - entry->rev_key.byteCount+= OvsPacketLenNBL(nbl); - entry->rev_key.packetCount++; - } else { - entry->key.byteCount += OvsPacketLenNBL(nbl); - entry->key.packetCount++; - } -} - POVS_CT_ENTRY OvsCtLookup(OvsConntrackKeyLookupCtx *ctx) { @@ -730,6 +733,12 @@ OvsCtExecute_(OvsForwardingContext *fwdCtx, NdisReleaseRWLock(ovsConntrackLockObj, &lockState); OVS_LOG_ERROR("Conntrack Limit hit: %lu", ctTotalEntries); return NDIS_STATUS_RESOURCES; + + /* Increment the counters soon after the lookup, since we set ct.state + * to OVS_CS_F_TRACKED after processing the ct entry. + */ + if (entry && (!(key->ct.state & OVS_CS_F_TRACKED))) { + OvsCtIncrementCounters(entry, ctx.reply, curNbl); } if (!entry) { @@ -740,7 +749,6 @@ OvsCtExecute_(OvsForwardingContext *fwdCtx, &entryCreated); } else { /* Process the entry and update CT flags */ - OvsCtIncrementCounters(entry, ctx.reply, curNbl); entry = OvsProcessConntrackEntry(fwdCtx, layers->l4Offset, &ctx, key, zone, natInfo, commit, currentTime, &entryCreated);