Skip to content

Commit

Permalink
ofp-util: Define struct ofputil_async_cfg to hold async message config.
Browse files Browse the repository at this point in the history
This seems a little better than a pair of bare arrays.

Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Jarno Rajahalme <jarno@ovn.org>
  • Loading branch information
blp committed Jan 20, 2016
1 parent 2da7974 commit a930d4c
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 179 deletions.
24 changes: 23 additions & 1 deletion include/openflow/openflow-common.h
@@ -1,4 +1,4 @@
/* Copyright (c) 2008, 2011, 2012, 2013, 2014 The Board of Trustees of The Leland Stanford
/* Copyright (c) 2008, 2011, 2012, 2013, 2014, 2016 The Board of Trustees of The Leland Stanford
* Junior University
*
* We are making the OpenFlow specification and associated documentation
Expand Down Expand Up @@ -280,6 +280,13 @@ enum ofp_packet_in_reason {
OFPR_ACTION_SET, /* Output to controller in action set */
OFPR_GROUP, /* Output to controller in group bucket */
OFPR_PACKET_OUT, /* Output to controller in packet-out */

#define OFPR10_BITS \
((1u << OFPR_NO_MATCH) | (1u << OFPR_ACTION) | (1u << OFPR_INVALID_TTL))
#define OFPR14_BITS \
(OFPR10_BITS | \
(1u << OFPR_ACTION_SET) | (1u << OFPR_GROUP) | (1u << OFPR_PACKET_OUT))

OFPR_N_REASONS
};

Expand All @@ -306,6 +313,16 @@ enum ofp_flow_removed_reason {
OFPRR_METER_DELETE, /* Meter was removed. */
OFPRR_EVICTION, /* Switch eviction to free resources. */

#define OFPRR10_BITS \
((1u << OFPRR_IDLE_TIMEOUT) | \
(1u << OFPRR_HARD_TIMEOUT) | \
(1u << OFPRR_DELETE))
#define OFPRR14_BITS \
(OFPRR10_BITS | \
(1u << OFPRR_GROUP_DELETE) | \
(1u << OFPRR_METER_DELETE) | \
(1u << OFPRR_EVICTION))

OVS_OFPRR_NONE /* OVS internal_use only, keep last!. */
};

Expand All @@ -314,6 +331,11 @@ 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. */

#define OFPPR_BITS ((1u << OFPPR_ADD) | \
(1u << OFPPR_DELETE) | \
(1u << OFPPR_MODIFY))

OFPPR_N_REASONS /* Denotes number of reasons. */
};

Expand Down
22 changes: 7 additions & 15 deletions lib/ofp-print.c
Expand Up @@ -2131,31 +2131,23 @@ 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;

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);
}
struct ofputil_async_cfg ac = OFPUTIL_ASYNC_CFG_INIT;
bool is_reply = raw == OFPRAW_OFPT14_GET_ASYNC_REPLY;
enum ofperr error = ofputil_decode_set_async_config(oh, is_reply, &ac);
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");
for (type = 0; type < OAM_N_TYPES; type++) {
for (uint32_t type = 0; type < OAM_N_TYPES; type++) {
ds_put_format(string, "%16s:",
ofputil_async_msg_type_to_string(type));

uint32_t role = i == 0 ? ac.master[type] : ac.slave[type];
for (j = 0; j < 32; j++) {
if (role[i][type] & (1u << j)) {
if (role & (1u << j)) {
char reasonbuf[OFP_ASYNC_CONFIG_REASON_BUFSIZE];
const char *reason;

Expand All @@ -2165,7 +2157,7 @@ ofp_print_nxt_set_async_config(struct ds *string,
ds_put_format(string, " %s", reason);
}
}
if (!role[i][type]) {
if (!role) {
ds_put_cstr(string, " (off)");
}
ds_put_char(string, '\n');
Expand Down
79 changes: 46 additions & 33 deletions lib/ofp-util.c
Expand Up @@ -9485,7 +9485,7 @@ ofputil_async_msg_type_to_string(enum ofputil_async_msg_type type)
}

/* Decodes the OpenFlow "set async config" request and "get async config
* reply" message in '*oh' into an abstract form in 'master' and 'slave'.
* reply" message in '*oh' into an abstract form in 'ac'.
*
* If 'loose' is true, this function ignores properties and values that it does
* not understand, as a controller would want to do when interpreting
Expand All @@ -9501,10 +9501,8 @@ ofputil_async_msg_type_to_string(enum ofputil_async_msg_type type)
* 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],
uint32_t slave[OAM_N_TYPES],
bool loose)
ofputil_decode_set_async_config(const struct ofp_header *oh, bool loose,
struct ofputil_async_cfg *ac)
{
enum ofpraw raw;
struct ofpbuf b;
Expand All @@ -9517,14 +9515,13 @@ ofputil_decode_set_async_config(const struct ofp_header *oh,
raw == OFPRAW_OFPT13_GET_ASYNC_REPLY) {
const struct nx_async_config *msg = ofpmsg_body(oh);

master[OAM_PACKET_IN] = ntohl(msg->packet_in_mask[0]);
master[OAM_PORT_STATUS] = ntohl(msg->port_status_mask[0]);
master[OAM_FLOW_REMOVED] = ntohl(msg->flow_removed_mask[0]);

slave[OAM_PACKET_IN] = ntohl(msg->packet_in_mask[1]);
slave[OAM_PORT_STATUS] = ntohl(msg->port_status_mask[1]);
slave[OAM_FLOW_REMOVED] = ntohl(msg->flow_removed_mask[1]);
ac->master[OAM_PACKET_IN] = ntohl(msg->packet_in_mask[0]);
ac->master[OAM_PORT_STATUS] = ntohl(msg->port_status_mask[0]);
ac->master[OAM_FLOW_REMOVED] = ntohl(msg->flow_removed_mask[0]);

ac->slave[OAM_PACKET_IN] = ntohl(msg->packet_in_mask[1]);
ac->slave[OAM_PORT_STATUS] = ntohl(msg->port_status_mask[1]);
ac->slave[OAM_FLOW_REMOVED] = ntohl(msg->flow_removed_mask[1]);
} else if (raw == OFPRAW_OFPT14_SET_ASYNC ||
raw == OFPRAW_OFPT14_GET_ASYNC_REPLY) {

Expand Down Expand Up @@ -9553,51 +9550,51 @@ ofputil_decode_set_async_config(const struct ofp_header *oh,

switch (type) {
case OFPACPT_PACKET_IN_SLAVE:
slave[OAM_PACKET_IN] = mask;
ac->slave[OAM_PACKET_IN] = mask;
break;

case OFPACPT_PACKET_IN_MASTER:
master[OAM_PACKET_IN] = mask;
ac->master[OAM_PACKET_IN] = mask;
break;

case OFPACPT_PORT_STATUS_SLAVE:
slave[OAM_PORT_STATUS] = mask;
ac->slave[OAM_PORT_STATUS] = mask;
break;

case OFPACPT_PORT_STATUS_MASTER:
master[OAM_PORT_STATUS] = mask;
ac->master[OAM_PORT_STATUS] = mask;
break;

case OFPACPT_FLOW_REMOVED_SLAVE:
slave[OAM_FLOW_REMOVED] = mask;
ac->slave[OAM_FLOW_REMOVED] = mask;
break;

case OFPACPT_FLOW_REMOVED_MASTER:
master[OAM_FLOW_REMOVED] = mask;
ac->master[OAM_FLOW_REMOVED] = mask;
break;

case OFPACPT_ROLE_STATUS_SLAVE:
slave[OAM_ROLE_STATUS] = mask;
ac->slave[OAM_ROLE_STATUS] = mask;
break;

case OFPACPT_ROLE_STATUS_MASTER:
master[OAM_ROLE_STATUS] = mask;
ac->master[OAM_ROLE_STATUS] = mask;
break;

case OFPACPT_TABLE_STATUS_SLAVE:
slave[OAM_TABLE_STATUS] = mask;
ac->slave[OAM_TABLE_STATUS] = mask;
break;

case OFPACPT_TABLE_STATUS_MASTER:
master[OAM_TABLE_STATUS] = mask;
ac->master[OAM_TABLE_STATUS] = mask;
break;

case OFPACPT_REQUESTFORWARD_SLAVE:
slave[OAM_REQUESTFORWARD] = mask;
ac->slave[OAM_REQUESTFORWARD] = mask;
break;

case OFPACPT_REQUESTFORWARD_MASTER:
master[OAM_REQUESTFORWARD] = mask;
ac->master[OAM_REQUESTFORWARD] = mask;
break;

default:
Expand Down Expand Up @@ -9667,8 +9664,7 @@ ofputil_get_async_reply(struct ofpbuf *buf, const uint32_t master_mask,
* as a reply to get async config request. */
struct ofpbuf *
ofputil_encode_get_async_config(const struct ofp_header *oh,
uint32_t master[OAM_N_TYPES],
uint32_t slave[OAM_N_TYPES])
const struct ofputil_async_cfg *ac)
{
struct ofpbuf *buf;
uint32_t type;
Expand All @@ -9681,18 +9677,35 @@ ofputil_encode_get_async_config(const struct ofp_header *oh,
struct nx_async_config *msg;
msg = ofpbuf_put_zeros(buf, sizeof *msg);

msg->packet_in_mask[0] = htonl(master[OAM_PACKET_IN]);
msg->port_status_mask[0] = htonl(master[OAM_PORT_STATUS]);
msg->flow_removed_mask[0] = htonl(master[OAM_FLOW_REMOVED]);
msg->packet_in_mask[0] = htonl(ac->master[OAM_PACKET_IN]);
msg->port_status_mask[0] = htonl(ac->master[OAM_PORT_STATUS]);
msg->flow_removed_mask[0] = htonl(ac->master[OAM_FLOW_REMOVED]);

msg->packet_in_mask[1] = htonl(slave[OAM_PACKET_IN]);
msg->port_status_mask[1] = htonl(slave[OAM_PORT_STATUS]);
msg->flow_removed_mask[1] = htonl(slave[OAM_FLOW_REMOVED]);
msg->packet_in_mask[1] = htonl(ac->slave[OAM_PACKET_IN]);
msg->port_status_mask[1] = htonl(ac->slave[OAM_PORT_STATUS]);
msg->flow_removed_mask[1] = htonl(ac->slave[OAM_FLOW_REMOVED]);
} else if (oh->version == OFP14_VERSION) {
for (type = 0; type < OAM_N_TYPES; type++) {
ofputil_get_async_reply(buf, master[type], slave[type], type);
ofputil_get_async_reply(buf, ac->master[type], ac->slave[type],
type);
}
}

return buf;
}

struct ofputil_async_cfg
ofputil_async_cfg_default(enum ofp_version version)
{
return (struct ofputil_async_cfg) {
.master[OAM_PACKET_IN]
= ((version >= OFP14_VERSION ? OFPR14_BITS : OFPR10_BITS)
& ~(1u << OFPR_INVALID_TTL)),

.master[OAM_FLOW_REMOVED]
= (version >= OFP14_VERSION ? OFPRR14_BITS : OFPRR10_BITS),

.master[OAM_PORT_STATUS] = OFPPR_BITS,
.slave[OAM_PORT_STATUS] = OFPPR_BITS,
};
}
20 changes: 13 additions & 7 deletions lib/ofp-util.h
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Nicira, Inc.
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -1325,14 +1325,20 @@ enum ofputil_async_msg_type {
};
const char *ofputil_async_msg_type_to_string(enum ofputil_async_msg_type);

struct ofputil_async_cfg {
uint32_t master[OAM_N_TYPES];
uint32_t slave[OAM_N_TYPES];
};
#define OFPUTIL_ASYNC_CFG_INIT (struct ofputil_async_cfg) { .master[0] = 0 }

enum ofperr ofputil_decode_set_async_config(const struct ofp_header *,
uint32_t master[OAM_N_TYPES],
uint32_t slave[OAM_N_TYPES],
bool loose);
bool loose,
struct ofputil_async_cfg *);

struct ofpbuf *ofputil_encode_get_async_config(
const struct ofp_header *, const struct ofputil_async_cfg *);

struct ofpbuf *ofputil_encode_get_async_config(const struct ofp_header *,
uint32_t master[OAM_N_TYPES],
uint32_t slave[OAM_N_TYPES]);
struct ofputil_async_cfg ofputil_async_cfg_default(enum ofp_version);

struct ofputil_requestforward {
ovs_be32 xid;
Expand Down

0 comments on commit a930d4c

Please sign in to comment.