From patchwork Tue Nov 24 12:10:19 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: 548027 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from archives.nicira.com (li376-54.members.linode.com [96.126.127.54]) by ozlabs.org (Postfix) with ESMTP id 6C84B140316 for ; Tue, 24 Nov 2015 23:10:48 +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=iZkuiwak; dkim-atps=neutral Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id 2F4FF108C4; Tue, 24 Nov 2015 04:10:47 -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 933BA108C1 for ; Tue, 24 Nov 2015 04:10:45 -0800 (PST) Received: from bar5.cudamail.com (localhost [127.0.0.1]) by mx1e3.cudamail.com (Postfix) with ESMTPS id F07D642005A for ; Tue, 24 Nov 2015 05:10:44 -0700 (MST) X-ASG-Debug-ID: 1448367043-09eadd53d0311680001-byXFYA Received: from mx1-pf2.cudamail.com ([192.168.24.2]) by bar5.cudamail.com with ESMTP id tWVgNjbBGlgy4B53 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 24 Nov 2015 05:10:43 -0700 (MST) X-Barracuda-Envelope-From: ambikaarora92@gmail.com X-Barracuda-RBL-Trusted-Forwarder: 192.168.24.2 Received: from unknown (HELO mail-pa0-f47.google.com) (209.85.220.47) by mx1-pf2.cudamail.com with ESMTPS (RC4-SHA encrypted); 24 Nov 2015 12:10:42 -0000 Received-SPF: pass (mx1-pf2.cudamail.com: SPF record at _netblocks.google.com designates 209.85.220.47 as permitted sender) X-Barracuda-RBL-Trusted-Forwarder: 209.85.220.47 Received: by padhx2 with SMTP id hx2so21080189pad.1 for ; Tue, 24 Nov 2015 04:10:42 -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=nnKvqHueQBYBjzGin/6kUhlJhVB7yIpejpyBLovf1r8=; b=iZkuiwakZY2t4cEJeqnsCSxtjYfHf/XdpHFSxjvwD/3fDl6QM/ROkHR0rNam9grL1i yfDZvSwHFjB9jUZtuHhO8UQ6umQgrf6ogOl4b/LVBd66dZA33lMUWT+/Tf//o0yIQWaC jmNfgGougrFNJeKmCXWunfz42iEL/HW9afSt5nH8CZjFVvFR019H5Q8dvY90mCywAbfK SyF1rZes3IOlBsKag3+kSOmCsopE9fPOr1j1s56snELsr9GcSrU1DudUTSk1N3U/xZdt XgwgyfCPsGr0/qZHl0BAul1WE64G6auuxuLzkB6ZDi4fcDZx7gGg7K83qGG09rAnYNDo cyAw== X-Received: by 10.98.14.26 with SMTP id w26mr22344852pfi.110.1448367041817; Tue, 24 Nov 2015 04:10:41 -0800 (PST) Received: from localhost.localdomain ([14.98.135.109]) by smtp.gmail.com with ESMTPSA id 132sm13983131pfc.63.2015.11.24.04.10.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 24 Nov 2015 04:10:40 -0800 (PST) X-CudaMail-Envelope-Sender: ambikaarora92@gmail.com X-Barracuda-Apparent-Source-IP: 14.98.135.109 From: Ambika Arora X-Google-Original-From: Ambika Arora To: dev@openvswitch.org X-CudaMail-MID: CM-E2-1123011400 X-CudaMail-DTE: 112415 X-CudaMail-Originating-IP: 209.85.220.47 Date: Tue, 24 Nov 2015 17:40:19 +0530 X-ASG-Orig-Subj: [##CM-E2-1123011400##][PATCH v3] ofproto: Implement OF1.4 error code for set-async-config Message-Id: <1448367019-4775-1-git-send-email-ambika.arora@tcs.com> X-Mailer: git-send-email 2.5.0 X-GBUdb-Analysis: 0, 209.85.220.47, Ugly c=0.488067 p=-0.508772 Source Normal X-MessageSniffer-Rules: 0-0-0-22849-c X-Barracuda-Connect: UNKNOWN[192.168.24.2] X-Barracuda-Start-Time: 1448367043 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, RDNS_NONE X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.24678 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 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 v3] 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" 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 --- 1. Implemented review comments. 2. 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 240ba84..e26d301 100644 --- a/lib/ofp-print.c +++ b/lib/ofp-print.c @@ -1847,6 +1847,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(); } @@ -1905,6 +1906,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; @@ -1928,6 +1930,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; @@ -1948,6 +1951,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; @@ -1968,6 +1972,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; @@ -2074,10 +2079,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"); @@ -3086,6 +3103,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 342be54..503d53a 100644 --- a/lib/ofp-util.c +++ b/lib/ofp-util.c @@ -134,6 +134,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 > 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) { @@ -5394,6 +5444,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(); } @@ -5492,6 +5543,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(); } } @@ -9409,7 +9464,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], @@ -9455,6 +9516,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); @@ -9505,10 +9573,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 8914342..0cf304d 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 2cdc8d4..507399f 100644 --- a/ofproto/ofproto.c +++ b/ofproto/ofproto.c @@ -5397,10 +5397,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 fce7671..60e74b7 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 "\