From 688e86e1d09ee779c3a3e0abf1e969e85f9e91c6 Mon Sep 17 00:00:00 2001 From: Simon Horman Date: Wed, 1 Aug 2012 16:01:49 +0900 Subject: [PATCH] ofp-error: Remove ofperr_domain from external API It seems that ofp_version suffices in all cases. Signed-off-by: Simon Horman Signed-off-by: Ben Pfaff --- build-aux/extract-ofp-errors | 2 +- lib/ofp-errors.c | 75 ++++++++++++++++++++---------------- lib/ofp-errors.h | 18 +++------ utilities/ovs-ofctl.c | 13 +++---- 4 files changed, 54 insertions(+), 54 deletions(-) diff --git a/build-aux/extract-ofp-errors b/build-aux/extract-ofp-errors index 1ec5ba4d..e513b7f4 100755 --- a/build-aux/extract-ofp-errors +++ b/build-aux/extract-ofp-errors @@ -343,7 +343,7 @@ static enum ofperr }""" print """ -const struct ofperr_domain %s = { +static const struct ofperr_domain %s = { "%s", %d, %s_decode, diff --git a/lib/ofp-errors.c b/lib/ofp-errors.c index f5af6ba0..2c71312e 100644 --- a/lib/ofp-errors.c +++ b/lib/ofp-errors.c @@ -21,20 +21,27 @@ struct pair { * 'version' (one of the possible values of struct ofp_header's 'version' * member). Returns NULL if the version isn't defined or isn't understood by * OVS. */ -const struct ofperr_domain * -ofperr_domain_from_version(uint8_t version) +static const struct ofperr_domain * +ofperr_domain_from_version(enum ofp_version version) { - return (version == ofperr_of10.version ? &ofperr_of10 - : version == ofperr_of11.version ? &ofperr_of11 - : version == ofperr_of12.version ? &ofperr_of12 - : NULL); + switch (version) { + case OFP10_VERSION: + return &ofperr_of10; + case OFP11_VERSION: + return &ofperr_of11; + case OFP12_VERSION: + return &ofperr_of12; + default: + return NULL; + } } -/* Returns the name (e.g. "OpenFlow 1.0") of OpenFlow error domain 'domain'. */ +/* Returns the name (e.g. "OpenFlow 1.0") of OpenFlow version 'version'. */ const char * -ofperr_domain_get_name(const struct ofperr_domain *domain) +ofperr_domain_get_name(enum ofp_version version) { - return domain->name; + const struct ofperr_domain *domain = ofperr_domain_from_version(version); + return domain ? domain->name : NULL; } /* Returns true if 'error' is a valid OFPERR_* value, false otherwise. */ @@ -71,26 +78,31 @@ ofperr_is_nx_extension(enum ofperr error) * A given error may not be encodable in some domains because each OpenFlow * version tends to introduce new errors and retire some old ones. */ bool -ofperr_is_encodable(enum ofperr error, const struct ofperr_domain *domain) +ofperr_is_encodable(enum ofperr error, enum ofp_version version) { + const struct ofperr_domain *domain = ofperr_domain_from_version(version); return (ofperr_is_valid(error) - && domain->errors[error - OFPERR_OFS].code >= 0); + && domain && domain->errors[error - OFPERR_OFS].code >= 0); } /* Returns the OFPERR_* value that corresponds to 'type' and 'code' within - * 'domain', or 0 if no such OFPERR_* value exists. */ + * 'version', or 0 if either no such OFPERR_* value exists or 'version' is + * unknown. */ enum ofperr -ofperr_decode(const struct ofperr_domain *domain, uint16_t type, uint16_t code) +ofperr_decode(enum ofp_version version, uint16_t type, uint16_t code) { - return domain->decode(type, code); + const struct ofperr_domain *domain = ofperr_domain_from_version(version); + return domain ? domain->decode(type, code) : 0; } /* Returns the OFPERR_* value that corresponds to the category 'type' within - * 'domain', or 0 if no such OFPERR_* value exists. */ + * 'version', or 0 if either no such OFPERR_* value exists or 'version' is + * unknown. */ enum ofperr -ofperr_decode_type(const struct ofperr_domain *domain, uint16_t type) +ofperr_decode_type(enum ofp_version version, uint16_t type) { - return domain->decode_type(type); + const struct ofperr_domain *domain = ofperr_domain_from_version(version); + return domain ? domain->decode_type(type) : 0; } /* Returns the name of 'error', e.g. "OFPBRC_BAD_TYPE" if 'error' is @@ -158,7 +170,7 @@ ofperr_encode_msg__(enum ofperr error, enum ofp_version ofp_version, return NULL; } - if (!ofperr_is_encodable(error, domain)) { + if (!ofperr_is_encodable(error, ofp_version)) { static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5); if (!ofperr_is_valid(error)) { @@ -256,24 +268,28 @@ ofperr_encode_hello(enum ofperr error, enum ofp_version ofp_version, /* Returns the value that would go into an OFPT_ERROR message's 'type' for * encoding 'error' in 'domain'. Returns -1 if 'error' is not encodable in - * 'domain'. + * 'version' or 'version' is unknown. * * 'error' must be a valid OFPERR_* code, as checked by ofperr_is_valid(). */ int -ofperr_get_type(enum ofperr error, const struct ofperr_domain *domain) +ofperr_get_type(enum ofperr error, enum ofp_version version) { - return ofperr_get_pair__(error, domain)->type; + const struct ofperr_domain *domain = ofperr_domain_from_version(version); + return domain ? ofperr_get_pair__(error, domain)->type : -1; } /* Returns the value that would go into an OFPT_ERROR message's 'code' for * encoding 'error' in 'domain'. Returns -1 if 'error' is not encodable in - * 'domain' or if 'error' represents a category rather than a specific error. + * 'version', 'version' is unknown or if 'error' represents a category + * rather than a specific error. + * * * 'error' must be a valid OFPERR_* code, as checked by ofperr_is_valid(). */ int -ofperr_get_code(enum ofperr error, const struct ofperr_domain *domain) +ofperr_get_code(enum ofperr error, enum ofp_version version) { - return ofperr_get_pair__(error, domain)->code; + const struct ofperr_domain *domain = ofperr_domain_from_version(version); + return domain ? ofperr_get_pair__(error, domain)->code : -1; } /* Tries to decodes 'oh', which should be an OpenFlow OFPT_ERROR message. @@ -286,7 +302,6 @@ ofperr_decode_msg(const struct ofp_header *oh, struct ofpbuf *payload) { static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5); - const struct ofperr_domain *domain; const struct ofp_error_msg *oem; enum ofpraw raw; uint16_t type, code; @@ -305,12 +320,6 @@ ofperr_decode_msg(const struct ofp_header *oh, struct ofpbuf *payload) } oem = ofpbuf_pull(&b, sizeof *oem); - /* Check version. */ - domain = ofperr_domain_from_version(oh->version); - if (!domain) { - return 0; - } - /* Get the error type and code. */ type = ntohs(oem->type); code = ntohs(oem->code); @@ -331,9 +340,9 @@ ofperr_decode_msg(const struct ofp_header *oh, struct ofpbuf *payload) /* Translate the error type and code into an ofperr. * If we don't know the error type and code, at least try for the type. */ - error = ofperr_decode(domain, type, code); + error = ofperr_decode(oh->version, type, code); if (!error) { - error = ofperr_decode_type(domain, type); + error = ofperr_decode_type(oh->version, type); } if (error && payload) { ofpbuf_use_const(payload, b.data, b.size); diff --git a/lib/ofp-errors.h b/lib/ofp-errors.h index ecf10ba1..2f28a420 100644 --- a/lib/ofp-errors.h +++ b/lib/ofp-errors.h @@ -496,21 +496,15 @@ enum ofperr { OFPERR_OFPET_EXPERIMENTER, }; -extern const struct ofperr_domain ofperr_of10; -extern const struct ofperr_domain ofperr_of11; -extern const struct ofperr_domain ofperr_of12; - -const struct ofperr_domain *ofperr_domain_from_version(uint8_t version); -const char *ofperr_domain_get_name(const struct ofperr_domain *); +const char *ofperr_domain_get_name(enum ofp_version); bool ofperr_is_valid(enum ofperr); bool ofperr_is_category(enum ofperr); bool ofperr_is_nx_extension(enum ofperr); -bool ofperr_is_encodable(enum ofperr, const struct ofperr_domain *); +bool ofperr_is_encodable(enum ofperr, enum ofp_version); -enum ofperr ofperr_decode(const struct ofperr_domain *, - uint16_t type, uint16_t code); -enum ofperr ofperr_decode_type(const struct ofperr_domain *, uint16_t type); +enum ofperr ofperr_decode(enum ofp_version, uint16_t type, uint16_t code); +enum ofperr ofperr_decode_type(enum ofp_version, uint16_t type); enum ofperr ofperr_from_name(const char *); enum ofperr ofperr_decode_msg(const struct ofp_header *, @@ -518,8 +512,8 @@ enum ofperr ofperr_decode_msg(const struct ofp_header *, struct ofpbuf *ofperr_encode_reply(enum ofperr, const struct ofp_header *); struct ofpbuf *ofperr_encode_hello(enum ofperr, enum ofp_version ofp_version, const char *); -int ofperr_get_type(enum ofperr, const struct ofperr_domain *); -int ofperr_get_code(enum ofperr, const struct ofperr_domain *); +int ofperr_get_type(enum ofperr, enum ofp_version); +int ofperr_get_code(enum ofperr, enum ofp_version); const char *ofperr_get_name(enum ofperr); const char *ofperr_get_description(enum ofperr); diff --git a/utilities/ovs-ofctl.c b/utilities/ovs-ofctl.c index b4f44835..13dd0e3c 100644 --- a/utilities/ovs-ofctl.c +++ b/utilities/ovs-ofctl.c @@ -2660,17 +2660,14 @@ ofctl_print_error(int argc OVS_UNUSED, char *argv[]) } for (version = 0; version <= UINT8_MAX; version++) { - const struct ofperr_domain *domain; - - domain = ofperr_domain_from_version(version); - if (!domain) { + const char *name = ofperr_domain_get_name(version); + if (!name) { continue; } - printf("%s: %d,%d\n", - ofperr_domain_get_name(domain), - ofperr_get_type(error, domain), - ofperr_get_code(error, domain)); + ofperr_domain_get_name(version), + ofperr_get_type(error, version), + ofperr_get_code(error, version)); } } -- 2.30.2