From patchwork Thu Mar 9 22:50:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Zhou X-Patchwork-Id: 737162 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 3vfQbr3NMXz9s7h for ; Fri, 10 Mar 2017 09:51:04 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id BC653BA4; Thu, 9 Mar 2017 22:50:32 +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 6E683BA2 for ; Thu, 9 Mar 2017 22:50:31 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-pf0-f193.google.com (mail-pf0-f193.google.com [209.85.192.193]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id E855416B for ; Thu, 9 Mar 2017 22:50:30 +0000 (UTC) Received: by mail-pf0-f193.google.com with SMTP id o126so8664223pfb.1 for ; Thu, 09 Mar 2017 14:50:30 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=cb21TKmD1y65i8L1BQ4iuoh6BeRRkH1aZsk52ApkktU=; b=aRVarQLoGo4ulirB5lJHYeb9SZNjxQmH+x1mr4vE/AqnubdlmTYevFwUOnJ1T9P4z/ MJMl5hHdtIgYGCVM9oL7STFseX4xx2L5d0X5HRu+uKBbv4DNNwbtipcgbJamCdHJC+yE X8VHUjFWH6TOVLeAtWCKyTbAg9KGfWZLM+zNuDpC5ay26+XpG8wihbjoJ4dRSzOYHAVy nCSIgXRKHJAEahUFTPcjXjYrD0pCM50CZIwY0Ro+wSs9J3C9QvrzZ+o7qSyVQ5Id2ebW CPpFaic8fBlMBsc3YctU7MLDkFrqcS3yzZjPpkYNKgp1HGTKBsXKqv9ON3kQ1UNmTPxk 7ldA== X-Gm-Message-State: AMke39lsZBx7e9pkT9yEtPAI9U7Gy7FUvxFC9RlxYgkYzgNMULrf+3TV+GclOa/a4cbD3w== X-Received: by 10.99.0.65 with SMTP id 62mr16595357pga.114.1489099830540; Thu, 09 Mar 2017 14:50:30 -0800 (PST) Received: from ubuntu.localdomain ([208.91.1.34]) by smtp.gmail.com with ESMTPSA id d63sm14343059pfg.132.2017.03.09.14.50.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 09 Mar 2017 14:50:29 -0800 (PST) From: Andy Zhou To: dev@openvswitch.org Date: Thu, 9 Mar 2017 14:50:09 -0800 Message-Id: <1489099810-68023-2-git-send-email-azhou@ovn.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1489099810-68023-1-git-send-email-azhou@ovn.org> References: <1489099810-68023-1-git-send-email-azhou@ovn.org> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH 2/3] ofproto: Probe for sample nesting level. 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: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org Add logics to detect the max level of nesting allowed by the sample action implemented in the datapath. Future patch allows xlate code to generate different odp actions based on this information. Signed-off-by: Andy Zhou Acked-by: Joe Stringer --- include/openvswitch/flow.h | 3 +++ lib/dpif.c | 2 +- ofproto/ofproto-dpif.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++ ofproto/ofproto-dpif.h | 3 +++ 4 files changed, 67 insertions(+), 1 deletion(-) diff --git a/include/openvswitch/flow.h b/include/openvswitch/flow.h index 5cd78e4..6606d3c 100644 --- a/include/openvswitch/flow.h +++ b/include/openvswitch/flow.h @@ -61,6 +61,9 @@ const char *flow_tun_flag_to_string(uint32_t flags); /* Maximum number of supported MPLS labels. */ #define FLOW_MAX_MPLS_LABELS 3 +/* Maximum number of supported SAMPLE action nesting. */ +#define FLOW_MAX_SAMPLE_NESTING 10 + /* * A flow in the network. * diff --git a/lib/dpif.c b/lib/dpif.c index dad0fcd..1760de8 100644 --- a/lib/dpif.c +++ b/lib/dpif.c @@ -916,7 +916,7 @@ dpif_probe_feature(struct dpif *dpif, const char *name, nl_actions, nl_actions_size, ufid, NON_PMD_CORE_ID, NULL); if (error) { - if (error != EINVAL) { + if (error != EINVAL && error != EOVERFLOW) { VLOG_WARN("%s: %s flow probe failed (%s)", dpif_name(dpif), name, ovs_strerror(error)); } diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c index 5289693..4b88d4b 100644 --- a/ofproto/ofproto-dpif.c +++ b/ofproto/ofproto-dpif.c @@ -983,6 +983,65 @@ check_max_mpls_depth(struct dpif_backer *backer) return n; } +static void +add_sample_actions(struct ofpbuf *actions, int nesting) +{ + if (nesting == 0) { + nl_msg_put_odp_port(actions, OVS_ACTION_ATTR_OUTPUT, u32_to_odp(1)); + return; + } + + size_t start, actions_start; + + start = nl_msg_start_nested(actions, OVS_ACTION_ATTR_SAMPLE); + actions_start = nl_msg_start_nested(actions, OVS_SAMPLE_ATTR_ACTIONS); + add_sample_actions(actions, nesting - 1); + nl_msg_end_nested(actions, actions_start); + nl_msg_put_u32(actions, OVS_SAMPLE_ATTR_PROBABILITY, UINT32_MAX); + nl_msg_end_nested(actions, start); +} + +/* Tests the nested sample actions levels supported by 'backer''s datapath. + * + * Returns the number of nested sample actions accepted by the datapath + * Otherwise returns the number of MPLS push actions supported by + * the datapath. */ +static size_t +check_max_sample_nesting(struct dpif_backer *backer) +{ + struct odputil_keybuf keybuf; + struct ofpbuf key; + struct flow flow; + int n; + + struct odp_flow_key_parms odp_parms = { + .flow = &flow, + }; + + memset(&flow, 0, sizeof flow); + ofpbuf_use_stack(&key, &keybuf, sizeof keybuf); + odp_flow_key_from_flow(&odp_parms, &key); + + /* OVS datapath has always supported at least 3 nested leves. */ + for (n = 3; n < FLOW_MAX_SAMPLE_NESTING; n++) { + struct ofpbuf actions; + bool ok; + + ofpbuf_init(&actions, 300); + add_sample_actions(&actions, n); + ok = dpif_probe_feature(backer->dpif, "Sample action nesting", &key, + &actions, NULL); + ofpbuf_uninit(&actions); + if (!ok) { + break; + } + } + + VLOG_INFO("%s: Max sample nesting level probed as %d", + dpif_name(backer->dpif), n); + return n; +} + /* Tests whether 'backer''s datapath supports masked data in * OVS_ACTION_ATTR_SET actions. We need to disable some features on older * datapaths that don't support this feature. */ @@ -1203,6 +1262,7 @@ check_support(struct dpif_backer *backer) backer->support.ufid = check_ufid(backer); backer->support.tnl_push_pop = dpif_supports_tnl_push_pop(backer->dpif); backer->support.clone = check_clone(backer); + backer->support.sample_nesting = check_max_sample_nesting(backer); /* Flow fields. */ backer->support.odp.ct_state = check_ct_state(backer); diff --git a/ofproto/ofproto-dpif.h b/ofproto/ofproto-dpif.h index 533fadf..cc514d2 100644 --- a/ofproto/ofproto-dpif.h +++ b/ofproto/ofproto-dpif.h @@ -168,6 +168,9 @@ struct dpif_backer_support { /* True if the datapath supports OVS_ACTION_ATTR_CLONE action. */ bool clone; + + /* Maximum level of nesting allowed by OVS_ACTION_ATTR_SAMPLE action. */ + size_t sample_nesting; }; /* Reasons that we might need to revalidate every datapath flow, and