At this time the encoding function is always called with OFP10_VERSION. A subsequent patch will call it with the prevailing version.
Signed-off-by: Simon Horman <ho...@verge.net.au> --- v2 * Re-arrange case statement to group unsupported versions with default --- lib/ofp-util.c | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++--- lib/ofp-util.h | 3 +- ofproto/connmgr.c | 2 +- ofproto/ofproto.c | 2 +- 4 files changed, 106 insertions(+), 9 deletions(-) diff --git a/lib/ofp-util.c b/lib/ofp-util.c index 7296d89..c2767fb 100644 --- a/lib/ofp-util.c +++ b/lib/ofp-util.c @@ -5622,20 +5622,35 @@ ofputil_encode_flow_monitor_cancel(uint32_t id) } void -ofputil_start_flow_update(struct list *replies) +ofputil_start_flow_update(enum ofp_version ofp_version, struct list *replies) { struct ofpbuf *msg; + enum ofpraw raw; + + switch (ofp_version) { + case OFP10_VERSION: + raw = OFPRAW_NXST_FLOW_MONITOR_REPLY; + break; + case OFP14_VERSION: + case OFP15_VERSION: + raw = OFPRAW_OFPST14_FLOW_MONITOR_REPLY; + break; + case OFP11_VERSION: + case OFP12_VERSION: + case OFP13_VERSION: /* XXX: Use OF extension! */ + default: + OVS_NOT_REACHED(); + } - msg = ofpraw_alloc_xid(OFPRAW_NXST_FLOW_MONITOR_REPLY, OFP10_VERSION, - htonl(0), 1024); + msg = ofpraw_alloc_xid(raw, ofp_version, htonl(0), 1024); list_init(replies); list_push_back(replies, &msg->list_node); } -void -ofputil_append_flow_update(const struct ofputil_flow_update *update, - struct list *replies) +static void +ofputil_nx_append_flow_update(const struct ofputil_flow_update *update, + struct list *replies) { enum ofp_version version = ofpmp_version(replies); struct nx_flow_update_header *nfuh; @@ -5691,6 +5706,87 @@ ofputil_append_flow_update(const struct ofputil_flow_update *update, ofpmp_postappend(replies, start_ofs); } + +static void +ofputil_of_append_flow_update(const struct ofputil_flow_update *update, + struct list *replies) +{ + enum ofp_version version = ofpmp_version(replies); + struct ofp14_flow_update_header *ofpfuh; + struct ofpbuf *msg; + size_t start_ofs; + + msg = ofpbuf_from_list(list_back(replies)); + start_ofs = ofpbuf_size(msg); + + switch(update->event) { + case OFPFME14_ABBREV: { + struct ofp14_flow_update_abbrev *ofpfua; + + ofpfua = ofpbuf_put_zeros(msg, sizeof *ofpfua); + ofpfua->xid = update->xid; + break; + } + case OFPFME14_INITIAL: + case OFPFME14_ADDED: + case OFPFME14_REMOVED: + case OFPFME14_MODIFIED: { + struct ofp14_flow_update_full *ofpfuf; + + ofpbuf_put_zeros(msg, sizeof *ofpfuf); + oxm_put_match(msg, update->match, version); + ofpacts_put_openflow_instructions(update->ofpacts, update->ofpacts_len, + msg, version); + ofpfuf = ofpbuf_at_assert(msg, start_ofs, sizeof *ofpfuf); + ofpfuf->table_id = update->table_id; + ofpfuf->reason = update->reason; + ofpfuf->idle_timeout = htons(update->idle_timeout); + ofpfuf->hard_timeout = htons(update->hard_timeout); + ofpfuf->priority = htons(update->priority); + ofpfuf->cookie = update->cookie; + break; + } + case OFPFME14_PAUSED: + case OFPFME14_RESUMED: { + struct ofp14_flow_update_paused *ofpfup; + + ofpfup = ofpbuf_put_zeros(msg, sizeof *ofpfup); + /* Other than values present in the header, which is set below, + * there is only a pad. So there nothing more to do here. */ + break; + } + default: + OVS_NOT_REACHED(); + } + + ofpfuh = ofpbuf_at_assert(msg, start_ofs, sizeof *ofpfuh); + ofpfuh->length = htons(ofpbuf_size(msg) - start_ofs); + ofpfuh->event = htons(update->event); + + ofpmp_postappend(replies, start_ofs); +} + +void +ofputil_append_flow_update(const struct ofputil_flow_update *update, + struct list *replies) +{ + enum ofp_version version = ofpmp_version(replies); + + switch (version) { + case OFP10_VERSION: + ofputil_nx_append_flow_update(update, replies); + break; + case OFP14_VERSION: + case OFP15_VERSION: + ofputil_of_append_flow_update(update, replies); + break; + case OFP11_VERSION: + case OFP12_VERSION: + case OFP13_VERSION: /* XXX: Use OF extension! */ + default: + OVS_NOT_REACHED(); + } +} struct ofpbuf * ofputil_encode_packet_out(const struct ofputil_packet_out *po, diff --git a/lib/ofp-util.h b/lib/ofp-util.h index ef0c33e..4d280e7 100644 --- a/lib/ofp-util.h +++ b/lib/ofp-util.h @@ -877,7 +877,8 @@ struct ofputil_flow_update { int ofputil_decode_flow_update(struct ofputil_flow_update *, struct ofpbuf *msg, struct ofpbuf *ofpacts); -void ofputil_start_flow_update(struct list *replies); +void ofputil_start_flow_update(enum ofp_version ofp_version, + struct list *replies); void ofputil_append_flow_update(const struct ofputil_flow_update *, struct list *replies); diff --git a/ofproto/connmgr.c b/ofproto/connmgr.c index d525227..2cc0bd4 100644 --- a/ofproto/connmgr.c +++ b/ofproto/connmgr.c @@ -2139,7 +2139,7 @@ ofmonitor_report(struct connmgr *mgr, struct rule *rule, if (flags) { if (list_is_empty(&ofconn->updates)) { - ofputil_start_flow_update(&ofconn->updates); + ofputil_start_flow_update(OFP10_VERSION, &ofconn->updates); ofconn->sent_abbrev_update = false; } diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c index cfef4ad..6bbf53a 100644 --- a/ofproto/ofproto.c +++ b/ofproto/ofproto.c @@ -4730,7 +4730,7 @@ ofproto_compose_flow_refresh_update(const struct rule *rule, fu.ofpacts_len = actions ? actions->ofpacts_len : 0; if (list_is_empty(msgs)) { - ofputil_start_flow_update(msgs); + ofputil_start_flow_update(OFP10_VERSION, msgs); } ofputil_append_flow_update(&fu, msgs); } -- 2.0.0.rc2 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev