From: Ben Pfaff Date: Fri, 8 Jan 2016 22:49:32 +0000 (-0800) Subject: ofp-util: Add function to encode OFPT_SET_ASYNC messages. X-Git-Url: http://git.cascardo.eti.br/?p=cascardo%2Fovs.git;a=commitdiff_plain;h=af7bc161f5ea9b6ae3e1405d6c619b734c2529a7 ofp-util: Add function to encode OFPT_SET_ASYNC messages. This isn't used yet but it will be in future commits. This also looks forward to supporting Open vSwitch extensions to OAM_*, which will be coming up soon. Signed-off-by: Ben Pfaff Acked-by: Jarno Rajahalme --- diff --git a/lib/ofp-msgs.h b/lib/ofp-msgs.h index 54018b444..4f95607a6 100644 --- a/lib/ofp-msgs.h +++ b/lib/ofp-msgs.h @@ -238,6 +238,8 @@ enum ofpraw { OFPRAW_OFPT13_SET_ASYNC, /* NXT 1.0+ (19): struct nx_async_config. */ OFPRAW_NXT_SET_ASYNC_CONFIG, + /* NXT 1.0-1.3 (27): uint8_t[8][]. */ + OFPRAW_NXT_SET_ASYNC_CONFIG2, /* OFPT 1.4+ (28): uint8_t[8][]. */ OFPRAW_OFPT14_SET_ASYNC, @@ -560,6 +562,7 @@ enum ofptype { OFPTYPE_GET_ASYNC_REPLY, /* OFPRAW_OFPT13_GET_ASYNC_REPLY. * OFPRAW_OFPT14_GET_ASYNC_REPLY. */ OFPTYPE_SET_ASYNC_CONFIG, /* OFPRAW_NXT_SET_ASYNC_CONFIG. + * OFPRAW_NXT_SET_ASYNC_CONFIG2. * OFPRAW_OFPT13_SET_ASYNC. * OFPRAW_OFPT14_SET_ASYNC. */ diff --git a/lib/ofp-util.c b/lib/ofp-util.c index 1e3d5b2c4..b22f796b7 100644 --- a/lib/ofp-util.c +++ b/lib/ofp-util.c @@ -9614,7 +9614,8 @@ ofputil_decode_set_async_config(const struct ofp_header *oh, bool loose, decode_legacy_async_masks(msg->flow_removed_mask, OAM_FLOW_REMOVED, oh->version, ac); } else if (raw == OFPRAW_OFPT14_SET_ASYNC || - raw == OFPRAW_OFPT14_GET_ASYNC_REPLY) { + raw == OFPRAW_OFPT14_GET_ASYNC_REPLY || + raw == OFPRAW_NXT_SET_ASYNC_CONFIG2) { *ac = *basis; while (b.size > 0) { struct ofpbuf property; @@ -9695,8 +9696,8 @@ ofputil_put_async_config__(const struct ofputil_async_cfg *ac, /* Encodes and returns a reply to the OFPT_GET_ASYNC_REQUEST in 'oh' that * states that the asynchronous message configuration is 'ac'. */ struct ofpbuf * -ofputil_encode_get_async_config(const struct ofp_header *oh, - const struct ofputil_async_cfg *ac) +ofputil_encode_get_async_reply(const struct ofp_header *oh, + const struct ofputil_async_cfg *ac) { struct ofpbuf *buf; @@ -9712,6 +9713,31 @@ ofputil_encode_get_async_config(const struct ofp_header *oh, return buf; } +/* Encodes and returns a message, in a format appropriate for OpenFlow version + * 'ofp_version', that sets the asynchronous message configuration to 'ac'. + * + * Specify 'oams' as a bitmap of OAM_* that indicate the asynchronous messages + * to configure. OF1.0 through OF1.3 can't natively configure a subset of + * messages, so more messages than requested may be configured. OF1.0 through + * OF1.3 also can't configure OVS extension OAM_* values, so if 'oam' includes + * any extensions then this function encodes an Open vSwitch extension message + * that does support configuring OVS extension OAM_*. */ +struct ofpbuf * +ofputil_encode_set_async_config(const struct ofputil_async_cfg *ac, + uint32_t oams, enum ofp_version ofp_version) +{ + enum ofpraw raw = (ofp_version >= OFP14_VERSION ? OFPRAW_OFPT14_SET_ASYNC + : oams & OAM_EXTENSIONS ? OFPRAW_NXT_SET_ASYNC_CONFIG2 + : ofp_version >= OFP13_VERSION ? OFPRAW_OFPT13_SET_ASYNC + : OFPRAW_NXT_SET_ASYNC_CONFIG); + struct ofpbuf *request = ofpraw_alloc(raw, ofp_version, 0); + ofputil_put_async_config__(ac, request, + (raw == OFPRAW_OFPT14_SET_ASYNC || + raw == OFPRAW_NXT_SET_ASYNC_CONFIG2), + ofp_version, oams); + return request; +} + struct ofputil_async_cfg ofputil_async_cfg_default(enum ofp_version version) { diff --git a/lib/ofp-util.h b/lib/ofp-util.h index 88c67f994..1c359b369 100644 --- a/lib/ofp-util.h +++ b/lib/ofp-util.h @@ -1299,12 +1299,17 @@ enum ofperr ofputil_decode_tlv_table_reply(const struct ofp_header *, void ofputil_uninit_tlv_table(struct ovs_list *mappings); enum ofputil_async_msg_type { + /* Standard asynchronous messages. */ OAM_PACKET_IN, /* OFPT_PACKET_IN or NXT_PACKET_IN. */ OAM_PORT_STATUS, /* OFPT_PORT_STATUS. */ OAM_FLOW_REMOVED, /* OFPT_FLOW_REMOVED or NXT_FLOW_REMOVED. */ OAM_ROLE_STATUS, /* OFPT_ROLE_STATUS. */ OAM_TABLE_STATUS, /* OFPT_TABLE_STATUS. */ OAM_REQUESTFORWARD, /* OFPT_REQUESTFORWARD. */ + + /* Extension asynchronous messages (none yet--coming soon!). */ +#define OAM_EXTENSIONS 0 /* Bitmap of all extensions. */ + OAM_N_TYPES }; const char *ofputil_async_msg_type_to_string(enum ofputil_async_msg_type); @@ -1320,8 +1325,10 @@ enum ofperr ofputil_decode_set_async_config(const struct ofp_header *, const struct ofputil_async_cfg *, struct ofputil_async_cfg *); -struct ofpbuf *ofputil_encode_get_async_config( +struct ofpbuf *ofputil_encode_get_async_reply( const struct ofp_header *, const struct ofputil_async_cfg *); +struct ofpbuf *ofputil_encode_set_async_config( + const struct ofputil_async_cfg *, uint32_t oams, enum ofp_version); struct ofputil_async_cfg ofputil_async_cfg_default(enum ofp_version); diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c index 957e32312..cbd9c47ec 100644 --- a/ofproto/ofproto.c +++ b/ofproto/ofproto.c @@ -5425,7 +5425,7 @@ static enum ofperr handle_nxt_get_async_request(struct ofconn *ofconn, const struct ofp_header *oh) { struct ofputil_async_cfg ac = ofconn_get_async_config(ofconn); - ofconn_send_reply(ofconn, ofputil_encode_get_async_config(oh, &ac)); + ofconn_send_reply(ofconn, ofputil_encode_get_async_reply(oh, &ac)); return 0; }