aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJustin Pettit <jpettit@nicira.com>2012-05-08 00:01:11 -0700
committerJustin Pettit <jpettit@nicira.com>2012-05-08 09:51:46 -0700
commit5b5a3a674c975ed1ccfc38b4dae705d4fe4df0eb (patch)
tree40367c38aae3a6efed8632f72d8de148f9f3f6c0 /lib
parent347b7ac46a96f851a67179d25401255a7f6e0b3b (diff)
ofp-util: Factor out determining physical port size.
There are a few places where we determine the size of a physical port structure based on the OpenFlow version. Use a helper function to do that. Suggested-by: Ben Pfaff <blp@nicira.com> Signed-off-by: Justin Pettit <jpettit@nicira.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/ofp-util.c29
1 files changed, 14 insertions, 15 deletions
diff --git a/lib/ofp-util.c b/lib/ofp-util.c
index 69e2b175..48be7749 100644
--- a/lib/ofp-util.c
+++ b/lib/ofp-util.c
@@ -2371,6 +2371,13 @@ ofputil_decode_ofp11_port(struct ofputil_phy_port *pp,
return 0;
}
+static size_t
+ofputil_get_phy_port_size(uint8_t ofp_version)
+{
+ return ofp_version == OFP10_VERSION ? sizeof(struct ofp10_phy_port)
+ : sizeof(struct ofp11_port);
+}
+
static void
ofputil_encode_ofp10_phy_port(const struct ofputil_phy_port *pp,
struct ofp10_phy_port *opp)
@@ -2543,20 +2550,17 @@ ofputil_decode_switch_features(const struct ofp_switch_features *osf,
features->n_tables = osf->n_tables;
features->capabilities = ntohl(osf->capabilities) & OFPC_COMMON;
- if (osf->header.version == OFP10_VERSION) {
- if (b->size % sizeof(struct ofp10_phy_port)) {
- return OFPERR_OFPBRC_BAD_LEN;
- }
+ if (b->size % ofputil_get_phy_port_size(osf->header.version)) {
+ return OFPERR_OFPBRC_BAD_LEN;
+ }
+
+ if (osf->header.version == OFP10_VERSION) {
if (osf->capabilities & htonl(OFPC10_STP)) {
features->capabilities |= OFPUTIL_C_STP;
}
features->actions = decode_action_bits(osf->actions, of10_action_bits);
} else if (osf->header.version == OFP11_VERSION) {
- if (b->size % sizeof(struct ofp11_port)) {
- return OFPERR_OFPBRC_BAD_LEN;
- }
-
if (osf->capabilities & htonl(OFPC11_GROUP_STATS)) {
features->capabilities |= OFPUTIL_C_GROUP_STATS;
}
@@ -2572,10 +2576,7 @@ ofputil_decode_switch_features(const struct ofp_switch_features *osf,
static bool
max_ports_in_features(const struct ofp_switch_features *osf)
{
- size_t pp_size = osf->header.version == OFP10_VERSION ?
- sizeof(struct ofp10_phy_port) :
- sizeof(struct ofp11_port);
-
+ size_t pp_size = ofputil_get_phy_port_size(osf->header.version);
return ntohs(osf->header.length) + pp_size > UINT16_MAX;
}
@@ -3403,9 +3404,7 @@ ofputil_pull_phy_port(uint8_t ofp_version, struct ofpbuf *b,
* 'ofp_version', returns the number of elements. */
size_t ofputil_count_phy_ports(uint8_t ofp_version, struct ofpbuf *b)
{
- return (ofp_version == OFP10_VERSION
- ? b->size / sizeof(struct ofp10_phy_port)
- : b->size / sizeof(struct ofp11_port));
+ return b->size / ofputil_get_phy_port_size(ofp_version);
}
static enum ofperr