From patchwork Mon Nov 30 11:22:47 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ambikaarora92@gmail.com X-Patchwork-Id: 549939 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from archives.nicira.com (unknown [IPv6:2600:3c00::f03c:91ff:fe6e:bdf7]) by ozlabs.org (Postfix) with ESMTP id B57EC1401F0 for ; Mon, 30 Nov 2015 22:23:27 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=Ii3c039S; dkim-atps=neutral Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id DF34510610; Mon, 30 Nov 2015 03:23:24 -0800 (PST) X-Original-To: dev@openvswitch.org Delivered-To: dev@openvswitch.org Received: from mx1e3.cudamail.com (mx1.cudamail.com [69.90.118.67]) by archives.nicira.com (Postfix) with ESMTPS id 165F41060B for ; Mon, 30 Nov 2015 03:23:24 -0800 (PST) Received: from bar2.cudamail.com (localhost [127.0.0.1]) by mx1e3.cudamail.com (Postfix) with ESMTPS id C82C2420280 for ; Mon, 30 Nov 2015 04:23:21 -0700 (MST) X-ASG-Debug-ID: 1448882600-03dc535f2a21ea0001-byXFYA Received: from mx1-pf2.cudamail.com ([192.168.24.2]) by bar2.cudamail.com with ESMTP id 6DdHkFMtVWzmKefn (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 30 Nov 2015 04:23:20 -0700 (MST) X-Barracuda-Envelope-From: ambikaarora92@gmail.com X-Barracuda-RBL-Trusted-Forwarder: 192.168.24.2 Received: from unknown (HELO mail-pa0-f43.google.com) (209.85.220.43) by mx1-pf2.cudamail.com with ESMTPS (RC4-SHA encrypted); 30 Nov 2015 11:23:20 -0000 Received-SPF: pass (mx1-pf2.cudamail.com: SPF record at _netblocks.google.com designates 209.85.220.43 as permitted sender) X-Barracuda-RBL-Trusted-Forwarder: 209.85.220.43 Received: by pacej9 with SMTP id ej9so182364471pac.2 for ; Mon, 30 Nov 2015 03:23:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=4Nb1IbOb9oTgvkujNPmNV5g5Z86DpQWdkn23Ca+3+vo=; b=Ii3c039SCyzPRWPq+McAIcIqyqgRPwookq/OY5m3VRD4I3hJHe1pRCDqvQLvYHQRek htOvC5Ui1M2tJJtScI6sUyCxQNb5RDQEntmJniYsTR+HTt/4uVar8Kb3cgvh9+qPRQ1N chPAtszr8vApfSMOkZqnEEMXI4WRX7tfjI21bNziVSoTwQmADQxQSjCoRAjejetR2h8o GXRP1txV4iG17pHVhVJo/qgwoXCg2o66JC8UEZU0cV52Wn+PpPJi6sWAGORRPVsc8P6U Ro59cJPe4p3IyZaC4PMhoEWvgfxmp5STC/k0jwPU2SP1zy+kJDggF6ZMvoh9A56Wa2fb BJ5Q== X-Received: by 10.98.69.7 with SMTP id s7mr68358156pfa.28.1448882599414; Mon, 30 Nov 2015 03:23:19 -0800 (PST) Received: from localhost.localdomain ([14.96.219.252]) by smtp.gmail.com with ESMTPSA id 87sm21851593pfj.23.2015.11.30.03.23.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 30 Nov 2015 03:23:18 -0800 (PST) X-CudaMail-Envelope-Sender: ambikaarora92@gmail.com X-Barracuda-Apparent-Source-IP: 14.96.219.252 From: ambikaarora92@gmail.com X-Google-Original-From: ambika.arora@tcs.com To: dev@openvswitch.org X-CudaMail-MID: CM-E2-1129009428 X-CudaMail-DTE: 113015 X-CudaMail-Originating-IP: 209.85.220.43 Date: Mon, 30 Nov 2015 16:52:47 +0530 X-ASG-Orig-Subj: [##CM-E2-1129009428##][PATCH v4] ofproto: Implement OF1.4 error code for set-async-config Message-Id: <1448882567-29008-1-git-send-email-ambika.arora@tcs.com> X-Mailer: git-send-email 2.5.0 X-GBUdb-Analysis: 0, 209.85.220.43, Ugly c=0.436326 p=-0.42029 Source Normal X-MessageSniffer-Rules: 0-0-0-22874-c X-Barracuda-Connect: UNKNOWN[192.168.24.2] X-Barracuda-Start-Time: 1448882600 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://web.cudamail.com:443/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at cudamail.com X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.60 X-Barracuda-Spam-Status: No, SCORE=0.60 using per-user scores of TAG_LEVEL=3.5 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=4.0 tests=BSF_SC5_MJ1963, DKIM_SIGNED, NO_REAL_NAME, RDNS_NONE X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.24846 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 0.00 NO_REAL_NAME From: does not include a real name 0.00 DKIM_SIGNED Domain Keys Identified Mail: message has a signature 0.10 RDNS_NONE Delivered to trusted network by a host with no rDNS 0.50 BSF_SC5_MJ1963 Custom Rule MJ1963 Cc: deepankar.gupta@tcs.com, partha.datta@tcs.com Subject: [ovs-dev] [PATCH v4] ofproto: Implement OF1.4 error code for set-async-config X-BeenThere: dev@openvswitch.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dev-bounces@openvswitch.org Sender: "dev" From: Ambika Arora This patch adds support for Openflow1.4 error codes for set-async-config. In this patch, a new error type, OFPET_ASYNC_CONFIG_FAILED is introduced that enables the switch to properly inform the controller when controller tries to set invalid mask or unsupported configuration. Signed-off-by: Ambika Arora --- Implemented review comments Rebased with latest master include/openflow/openflow-1.4.h | 3 ++ include/openflow/openflow-common.h | 3 +- lib/ofp-errors.h | 13 +++++++ lib/ofp-print.c | 22 ++++++++++- lib/ofp-util.c | 75 +++++++++++++++++++++++++++++++++++--- lib/ofp-util.h | 16 ++++++++ ofproto/ofproto.c | 6 ++- tests/ofp-print.at | 24 ++++++++++++ 8 files changed, 154 insertions(+), 8 deletions(-) diff --git a/include/openflow/openflow-1.4.h b/include/openflow/openflow-1.4.h index 9465b8e..e600cff 100644 --- a/include/openflow/openflow-1.4.h +++ b/include/openflow/openflow-1.4.h @@ -134,6 +134,7 @@ enum ofp14_table_mod_prop_eviction_flag { enum ofp14_table_reason { OFPTR_VACANCY_DOWN = 3, /* Vacancy down threshold event. */ OFPTR_VACANCY_UP = 4, /* Vacancy up threshold event. */ + OFPTR_N_REASONS /* Denotes number of reasons. */ }; struct ofp14_table_mod_prop_eviction { @@ -259,6 +260,7 @@ OFP_ASSERT(sizeof(struct ofp14_async_config) == 8); enum ofp14_requestforward_reason { OFPRFR_GROUP_MOD = 0, /* Forward group mod requests. */ OFPRFR_METER_MOD = 1, /* Forward meter mod requests. */ + OFPRFR_N_REASONS /* Denotes number of reasons. */ }; /* Async Config property types. @@ -332,6 +334,7 @@ enum ofp14_controller_role_reason { OFPCRR_MASTER_REQUEST = 0, /* Another controller asked to be master. */ OFPCRR_CONFIG = 1, /* Configuration changed on the switch. */ OFPCRR_EXPERIMENTER = 2, /* Experimenter data changed. */ + OFPCRR_N_REASONS /* Denotes number of reasons. */ }; /* Role property types. diff --git a/include/openflow/openflow-common.h b/include/openflow/openflow-common.h index b2b2d46..81f9120 100644 --- a/include/openflow/openflow-common.h +++ b/include/openflow/openflow-common.h @@ -308,7 +308,8 @@ enum ofp_flow_removed_reason { enum ofp_port_reason { OFPPR_ADD, /* The port was added. */ OFPPR_DELETE, /* The port was removed. */ - OFPPR_MODIFY /* Some attribute of the port has changed. */ + OFPPR_MODIFY, /* Some attribute of the port has changed. */ + OFPPR_N_REASONS /* Denotes number of reasons. */ }; /* A physical port has changed in the datapath */ diff --git a/lib/ofp-errors.h b/lib/ofp-errors.h index c020f7a..9c108d0 100644 --- a/lib/ofp-errors.h +++ b/lib/ofp-errors.h @@ -623,6 +623,19 @@ enum ofperr { /* ONF1.3(4448), OF1.4+(14,8). Permissions error. */ OFPERR_OFPBPC_EPERM, +/* ## -------------------------- ## */ +/* ## OFPET_ASYNC_CONFIG_FAILED ## */ +/* ## -------------------------- ## */ + + /* OF1.4+(15,0). One mask is invalid. */ + OFPERR_OFPACFC_INVALID, + + /* OF1.4+(15,1). Requested configuration not supported. */ + OFPERR_OFPACFC_UNSUPPORTED, + + /* OF1.4+(15,2). Permissions error. */ + OFPERR_OFPACFC_EPERM, + /* ## -------------------- ## */ /* ## OFPET_BUNDLE_FAILED ## */ /* ## -------------------- ## */ diff --git a/lib/ofp-print.c b/lib/ofp-print.c index d24eac1..d4f1972 100644 --- a/lib/ofp-print.c +++ b/lib/ofp-print.c @@ -1879,6 +1879,7 @@ ofp_print_role_status_message(struct ds *string, const struct ofp_header *oh) case OFPCRR_EXPERIMENTER: ds_put_cstr(string, "experimenter_data_changed"); break; + case OFPCRR_N_REASONS: default: OVS_NOT_REACHED(); } @@ -1937,6 +1938,7 @@ ofp_port_reason_to_string(enum ofp_port_reason reason, case OFPPR_MODIFY: return "modify"; + case OFPPR_N_REASONS: default: snprintf(reasonbuf, bufsize, "%d", (int) reason); return reasonbuf; @@ -1960,6 +1962,7 @@ ofp_role_reason_to_string(enum ofp14_controller_role_reason reason, case OFPCRR_EXPERIMENTER: return "experimenter_data_changed"; + case OFPCRR_N_REASONS: default: snprintf(reasonbuf, bufsize, "%d", (int) reason); return reasonbuf; @@ -1980,6 +1983,7 @@ ofp_table_reason_to_string(enum ofp14_table_reason reason, case OFPTR_VACANCY_UP: return "vacancy_up"; + case OFPTR_N_REASONS: default: snprintf(reasonbuf, bufsize, "%d", (int) reason); return reasonbuf; @@ -2000,6 +2004,7 @@ ofp_requestforward_reason_to_string(enum ofp14_requestforward_reason reason, case OFPRFR_METER_MOD: return "meter_mod_request"; + case OFPRFR_N_REASONS: default: snprintf(reasonbuf, bufsize, "%d", (int) reason); return reasonbuf; @@ -2106,10 +2111,22 @@ ofp_print_nxt_set_async_config(struct ds *string, } } else if (raw == OFPRAW_OFPT14_SET_ASYNC || raw == OFPRAW_OFPT14_GET_ASYNC_REPLY) { + enum ofperr error = 0; uint32_t role[2][OAM_N_TYPES] = {{0}}; uint32_t type; - ofputil_decode_set_async_config(oh, role[0], role[1], true); + if (raw == OFPRAW_OFPT14_GET_ASYNC_REPLY) { + error = ofputil_decode_set_async_config(oh, role[0], role[1], true); + } + else if (raw == OFPRAW_OFPT14_SET_ASYNC) { + error = ofputil_decode_set_async_config(oh, role[0], role[1], + false); + } + if (error) { + ofp_print_error(string, error); + return; + } + for (i = 0; i < 2; i++) { ds_put_format(string, "\n %s:\n", i == 0 ? "master" : "slave"); @@ -3118,6 +3135,9 @@ ofp_print_requestforward(struct ds *string, const struct ofp_header *oh) ds_put_cstr(string, "meter_mod"); ofp_print_meter_mod__(string, rf.meter_mod); break; + + case OFPRFR_N_REASONS: + OVS_NOT_REACHED(); } ofputil_destroy_requestforward(&rf); } diff --git a/lib/ofp-util.c b/lib/ofp-util.c index 885ceb1..2b49397 100644 --- a/lib/ofp-util.c +++ b/lib/ofp-util.c @@ -137,6 +137,56 @@ log_property(bool loose, const char *message, ...) } } +static enum ofperr +ofputil_check_mask(uint16_t type, uint32_t mask) +{ + switch (type) { + case OFPACPT_PACKET_IN_SLAVE: + case OFPACPT_PACKET_IN_MASTER: + if (mask > MAXIMUM_MASK_PACKET_IN) { + return OFPERR_OFPACFC_INVALID; + } + break; + + case OFPACPT_FLOW_REMOVED_SLAVE: + case OFPACPT_FLOW_REMOVED_MASTER: + if (mask > MAXIMUM_MASK_FLOW_REMOVED) { + return OFPERR_OFPACFC_INVALID; + } + break; + + case OFPACPT_PORT_STATUS_SLAVE: + case OFPACPT_PORT_STATUS_MASTER: + if (mask > MAXIMUM_MASK_PORT_STATUS) { + return OFPERR_OFPACFC_INVALID; + } + break; + + case OFPACPT_ROLE_STATUS_SLAVE: + case OFPACPT_ROLE_STATUS_MASTER: + if (mask > MAXIMUM_MASK_ROLE_STATUS) { + return OFPERR_OFPACFC_INVALID; + } + break; + + case OFPACPT_TABLE_STATUS_SLAVE: + case OFPACPT_TABLE_STATUS_MASTER: + if ((mask < MINIMUM_MASK_TABLE_STATUS && mask != 0) | + (mask > MAXIMUM_MASK_TABLE_STATUS)) { + return OFPERR_OFPACFC_INVALID; + } + break; + + case OFPACPT_REQUESTFORWARD_SLAVE: + case OFPACPT_REQUESTFORWARD_MASTER: + if (mask > MAXIMUM_MASK_REQUESTFORWARD) { + return OFPERR_OFPACFC_INVALID; + } + break; + } + return 0; +} + static size_t start_property(struct ofpbuf *msg, uint16_t type) { @@ -5501,6 +5551,7 @@ ofputil_encode_requestforward(const struct ofputil_requestforward *rf, inner = ofputil_encode_meter_mod(ofp_version, rf->meter_mod); break; + case OFPRFR_N_REASONS: default: OVS_NOT_REACHED(); } @@ -5599,6 +5650,10 @@ ofputil_destroy_requestforward(struct ofputil_requestforward *rf) case OFPRFR_METER_MOD: ofpbuf_uninit(&rf->bands); free(rf->meter_mod); + break; + + case OFPRFR_N_REASONS: + OVS_NOT_REACHED(); } } @@ -9517,7 +9572,13 @@ ofputil_uninit_geneve_table(struct ovs_list *mappings) * treats unknown properties and values as an error, as a switch would want to * do when interpreting a configuration request made by a controller. * - * Returns 0 if successful, otherwise an OFPERR_* value. */ + * Returns 0 if successful, otherwise an OFPERR_* value. + * + * Returns error code OFPERR_OFPACFC_INVALID if the value of mask is not in + * the valid range of mask. + * + * Returns error code OFPERR_OFPACFC_UNSUPPORTED if the configuration is not + * supported.*/ enum ofperr ofputil_decode_set_async_config(const struct ofp_header *oh, uint32_t master[OAM_N_TYPES], @@ -9563,6 +9624,13 @@ ofputil_decode_set_async_config(const struct ofp_header *oh, return OFPERR_OFPBRC_BAD_LEN; } + if (!loose) { + error = ofputil_check_mask(type, ntohl(msg->mask)); + if (error) { + return error; + } + } + switch (type) { case OFPACPT_PACKET_IN_SLAVE: slave[OAM_PACKET_IN] = ntohl(msg->mask); @@ -9613,10 +9681,7 @@ ofputil_decode_set_async_config(const struct ofp_header *oh, break; default: - error = loose ? 0 : OFPERR_OFPBPC_BAD_TYPE; - break; - } - if (error) { + error = loose ? 0 : OFPERR_OFPACFC_UNSUPPORTED; return error; } } diff --git a/lib/ofp-util.h b/lib/ofp-util.h index a6cb586..d106350 100644 --- a/lib/ofp-util.h +++ b/lib/ofp-util.h @@ -140,6 +140,22 @@ enum ofputil_protocol { OFPUTIL_P_ANY_OXM) }; + /* Valid value of mask for asynchronous messages. */ +#define MAXIMUM_MASK_PACKET_IN ((1 << OFPR_N_REASONS) - 1) + +#define MAXIMUM_MASK_FLOW_REMOVED ((1 << OVS_OFPRR_NONE) - 1) + +#define MAXIMUM_MASK_PORT_STATUS ((1 << OFPPR_N_REASONS) - 1) + +#define MAXIMUM_MASK_ROLE_STATUS ((1 << OFPCRR_N_REASONS) - 1) + +#define MINIMUM_MASK_TABLE_STATUS (1 << OFPTR_VACANCY_DOWN) + +#define MAXIMUM_MASK_TABLE_STATUS ((1 << OFPTR_N_REASONS) - \ + MINIMUM_MASK_TABLE_STATUS) + +#define MAXIMUM_MASK_REQUESTFORWARD ((1 << OFPRFR_N_REASONS) - 1) + /* Protocols to use for flow dumps, from most to least preferred. */ extern enum ofputil_protocol ofputil_flow_dump_protocols[]; extern size_t ofputil_n_flow_dump_protocols; diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c index 4f69cc2..5688c6e 100644 --- a/ofproto/ofproto.c +++ b/ofproto/ofproto.c @@ -5413,10 +5413,14 @@ handle_nxt_set_packet_in_format(struct ofconn *ofconn, static enum ofperr handle_nxt_set_async_config(struct ofconn *ofconn, const struct ofp_header *oh) { + enum ofperr error; uint32_t master[OAM_N_TYPES] = {0}; uint32_t slave[OAM_N_TYPES] = {0}; - ofputil_decode_set_async_config(oh, master, slave, false); + error = ofputil_decode_set_async_config(oh, master, slave, false); + if (error) { + return error; + } ofconn_set_async_config(ofconn, master, slave); if (ofconn_get_type(ofconn) == OFCONN_SERVICE && diff --git a/tests/ofp-print.at b/tests/ofp-print.at index d189efc..ed9ffdb 100644 --- a/tests/ofp-print.at +++ b/tests/ofp-print.at @@ -2824,6 +2824,30 @@ OFPT_SET_ASYNC (OF1.4) (xid=0x2): ]) AT_CLEANUP +AT_SETUP([OFPT_SET_ASYNC_CONFIG - invalid mask - OF1.4]) +AT_KEYWORDS([ofp-print]) +AT_CHECK([ovs-ofctl ofp-print "\ +05 1c 00 38 00 00 00 02 00 00 00 08 00 00 00 40 \ +00 01 00 08 00 00 00 02 00 02 00 08 00 00 00 02 \ +00 03 00 08 00 00 00 05 00 04 00 08 00 00 00 1c \ +00 05 00 08 00 00 00 05 \ +"], [0], [dnl +OFPT_SET_ASYNC (OF1.4) (xid=0x2): ***decode error: OFPACFC_INVALID*** +]) +AT_CLEANUP + +AT_SETUP([OFPT_SET_ASYNC_CONFIG - unsupported configuration - OF1.4]) +AT_KEYWORDS([ofp-print]) +AT_CHECK([ovs-ofctl ofp-print "\ +05 1c 00 38 00 00 00 02 00 00 00 08 00 00 00 05 \ +00 11 00 08 00 00 00 02 00 02 00 08 00 00 00 02 \ +00 03 00 08 00 00 00 05 00 04 00 08 00 00 00 1c \ +00 05 00 08 00 00 00 05\ +"], [0], [dnl +OFPT_SET_ASYNC (OF1.4) (xid=0x2): ***decode error: OFPACFC_UNSUPPORTED*** +]) +AT_CLEANUP + AT_SETUP([NXT_SET_CONTROLLER_ID]) AT_KEYWORDS([ofp-print]) AT_CHECK([ovs-ofctl ofp-print "\