Use enum ofp14_flow_monitor_flags in place of enum nx_flow_monitor_flags in struct ofputil_flow_monitor_request and struct rule, translating between the two enumerations as necessary.
The motivation for this patch is to move towards supporting OpenFlow1.4 flow monitor requests. Signed-off-by: Simon Horman <ho...@verge.net.au> --- v2 * No change --- lib/ofp-parse.c | 16 ++++++++-------- lib/ofp-print.c | 4 +++- lib/ofp-util.c | 44 +++++++++++++++++++++++++++++++++++++++++--- lib/ofp-util.h | 6 ++++-- ofproto/connmgr.c | 14 +++++++------- ofproto/connmgr.h | 2 +- ofproto/ofproto-provider.h | 2 +- ofproto/ofproto.c | 20 ++++++++++---------- 8 files changed, 75 insertions(+), 33 deletions(-) diff --git a/lib/ofp-parse.c b/lib/ofp-parse.c index c759f03..500478a 100644 --- a/lib/ofp-parse.c +++ b/lib/ofp-parse.c @@ -1723,8 +1723,8 @@ parse_flow_monitor_request__(struct ofputil_flow_monitor_request *fmr, atomic_add(&id, 1, &fmr->id); - fmr->flags = (NXFMF_INITIAL | NXFMF_ADD | NXFMF_DELETE | NXFMF_MODIFY - | NXFMF_OWN | NXFMF_ACTIONS); + fmr->flags = (OFPFMF14_INITIAL | OFPFMF14_ADD | OFPFMF14_REMOVED | + OFPFMF14_MODIFY | OFPFMF14_INSTRUCTIONS); fmr->out_port = OFPP_NONE; fmr->table_id = 0xff; match_init_catchall(&fmr->match); @@ -1734,17 +1734,17 @@ parse_flow_monitor_request__(struct ofputil_flow_monitor_request *fmr, const struct protocol *p; if (!strcmp(name, "!initial")) { - fmr->flags &= ~NXFMF_INITIAL; + fmr->flags &= ~OFPFMF14_INITIAL; } else if (!strcmp(name, "!add")) { - fmr->flags &= ~NXFMF_ADD; + fmr->flags &= ~OFPFMF14_ADD; } else if (!strcmp(name, "!delete")) { - fmr->flags &= ~NXFMF_DELETE; + fmr->flags &= ~OFPFMF14_REMOVED; } else if (!strcmp(name, "!modify")) { - fmr->flags &= ~NXFMF_MODIFY; + fmr->flags &= ~OFPFMF14_MODIFY; } else if (!strcmp(name, "!actions")) { - fmr->flags &= ~NXFMF_ACTIONS; + fmr->flags &= ~OFPFMF14_INSTRUCTIONS; } else if (!strcmp(name, "!own")) { - fmr->flags &= ~NXFMF_OWN; + fmr->flags |= OFPFMF14_NO_ABBREV; } else if (parse_protocol(name, &p)) { match_set_dl_type(&fmr->match, htons(p->dl_type)); if (p->nw_proto) { diff --git a/lib/ofp-print.c b/lib/ofp-print.c index a2c2434..81cac90 100644 --- a/lib/ofp-print.c +++ b/lib/ofp-print.c @@ -2193,6 +2193,7 @@ ofp_print_nxst_flow_monitor_request(struct ds *string, ofpbuf_use_const(&b, oh, ntohs(oh->length)); for (;;) { struct ofputil_flow_monitor_request request; + enum nx_flow_monitor_flags nx_flags; int retval; retval = ofputil_decode_flow_monitor_request(&request, &b); @@ -2204,7 +2205,8 @@ ofp_print_nxst_flow_monitor_request(struct ds *string, } ds_put_format(string, "\n id=%"PRIu32" flags=", request.id); - ofp_print_bit_names(string, request.flags, + nx_flags = nx_from_ofp14_flow_monitor_flags(request.flags); + ofp_print_bit_names(string, nx_flags, nx_flow_monitor_flags_to_name, ','); if (request.out_port != OFPP_NONE) { diff --git a/lib/ofp-util.c b/lib/ofp-util.c index 09e4438..bcefc9a 100644 --- a/lib/ofp-util.c +++ b/lib/ofp-util.c @@ -5186,6 +5186,44 @@ ofputil_encode_table_stats_reply(const struct ofp12_table_stats stats[], int n, /* ofputil_flow_monitor_request */ +static enum ofp14_flow_monitor_flags +nx_to_ofp14_flow_monitor_flags(enum nx_flow_monitor_flags nx_flags) +{ + enum ofp14_flow_monitor_flags ofp_flags; + + /* These NXFMF flags are identity mapped to OFPFMF14 flags */ + ofp_flags = nx_flags & (NXFMF_INITIAL | NXFMF_ADD | NXFMF_DELETE + | NXFMF_MODIFY | NXFMF_ACTIONS); + /* NXFMF_OWN and OFPFMF14_NO_ABBREV have inverted sense */ + if (!(nx_flags & NXFMF_OWN)) { + ofp_flags |= OFPFMF14_NO_ABBREV; + } + + /* No other flags should be present. */ + ovs_assert(!((ofp_flags | OFPFMF14_NO_ABBREV) & ~(nx_flags | NXFMF_OWN))); + + return ofp_flags; +} + +enum nx_flow_monitor_flags +nx_from_ofp14_flow_monitor_flags(enum ofp14_flow_monitor_flags ofp_flags) +{ + enum nx_flow_monitor_flags nx_flags; + + /* These OFPFMF14 flags are identity mapped to NX flags */ + nx_flags = ofp_flags & (OFPFMF14_INITIAL | OFPFMF14_ADD | OFPFMF14_REMOVED + | OFPFMF14_MODIFY | OFPFMF14_INSTRUCTIONS); + /* NXFMF_OWN and OFPFMF14_NO_ABBREV have inverted sense */ + if (!(ofp_flags & OFPFMF14_NO_ABBREV)) { + nx_flags |= NXFMF_OWN; + } + + /* No other flags should be present. */ + ovs_assert(!((nx_flags | NXFMF_OWN) & ~(ofp_flags | OFPFMF14_NO_ABBREV))); + + return nx_flags; +} + /* Converts an NXST_FLOW_MONITOR request in 'msg' into an abstract * ofputil_flow_monitor_request in 'rq'. * @@ -5201,7 +5239,7 @@ ofputil_decode_flow_monitor_request(struct ofputil_flow_monitor_request *rq, struct ofpbuf *msg) { struct nx_flow_monitor_request *nfmr; - uint16_t flags; + enum nx_flow_monitor_flags flags; if (!msg->frame) { ofpraw_pull_assert(msg); @@ -5232,7 +5270,7 @@ ofputil_decode_flow_monitor_request(struct ofputil_flow_monitor_request *rq, } rq->id = ntohl(nfmr->id); - rq->flags = flags; + rq->flags = nx_to_ofp14_flow_monitor_flags(flags); rq->out_port = u16_to_ofp(ntohs(nfmr->out_port)); rq->table_id = nfmr->table_id; @@ -5257,7 +5295,7 @@ ofputil_append_flow_monitor_request( nfmr = ofpbuf_at_assert(msg, start_ofs, sizeof *nfmr); nfmr->id = htonl(rq->id); - nfmr->flags = htons(rq->flags); + nfmr->flags = htons(nx_from_ofp14_flow_monitor_flags(rq->flags)); nfmr->out_port = htons(ofp_to_u16(rq->out_port)); nfmr->match_len = htons(match_len); nfmr->table_id = rq->table_id; diff --git a/lib/ofp-util.h b/lib/ofp-util.h index 552b006..39afa51 100644 --- a/lib/ofp-util.h +++ b/lib/ofp-util.h @@ -834,15 +834,17 @@ int ofputil_pull_queue_get_config_reply(struct ofpbuf *reply, struct ofputil_queue_config *); -/* Abstract nx_flow_monitor_request. */ +/* Abstract {nx,ofp14}_flow_monitor_request. */ struct ofputil_flow_monitor_request { uint32_t id; - enum nx_flow_monitor_flags flags; + enum ofp14_flow_monitor_flags flags; ofp_port_t out_port; uint8_t table_id; struct match match; }; +enum nx_flow_monitor_flags nx_from_ofp14_flow_monitor_flags( + enum ofp14_flow_monitor_flags ofp_flags); int ofputil_decode_flow_monitor_request(struct ofputil_flow_monitor_request *, struct ofpbuf *msg); void ofputil_append_flow_monitor_request( diff --git a/ofproto/connmgr.c b/ofproto/connmgr.c index 4eaede4..9561c45 100644 --- a/ofproto/connmgr.c +++ b/ofproto/connmgr.c @@ -2150,21 +2150,21 @@ ofmonitor_report(struct connmgr *mgr, struct rule *rule, const struct ofconn *abbrev_ofconn, ovs_be32 abbrev_xid) OVS_REQUIRES(ofproto_mutex) { - enum nx_flow_monitor_flags update; + enum ofp14_flow_monitor_flags update; struct ofconn *ofconn; switch (event) { case NXFME_ADDED: - update = NXFMF_ADD; + update = OFPFMF14_ADD; rule->add_seqno = rule->modify_seqno = monitor_seqno++; break; case NXFME_DELETED: - update = NXFMF_DELETE; + update = OFPFMF14_REMOVED; break; case NXFME_MODIFIED: - update = NXFMF_MODIFY; + update = OFPFMF14_MODIFY; rule->modify_seqno = monitor_seqno++; break; @@ -2174,7 +2174,7 @@ ofmonitor_report(struct connmgr *mgr, struct rule *rule, } LIST_FOR_EACH (ofconn, node, &mgr->all_conns) { - enum nx_flow_monitor_flags flags = 0; + enum ofp14_flow_monitor_flags flags = 0; struct ofmonitor *m; if (ofconn->monitor_paused) { @@ -2201,7 +2201,7 @@ ofmonitor_report(struct connmgr *mgr, struct rule *rule, ofconn->sent_abbrev_update = false; } - if (!(flags & NXFMF_OWN) || ofconn != abbrev_ofconn + if ((flags & OFPFMF14_NO_ABBREV) || ofconn != abbrev_ofconn || ofconn->monitor_paused) { struct ofputil_flow_update fu; struct match match; @@ -2219,7 +2219,7 @@ ofmonitor_report(struct connmgr *mgr, struct rule *rule, fu.hard_timeout = rule->hard_timeout; ovs_mutex_unlock(&rule->mutex); - if (flags & NXFMF_ACTIONS) { + if (flags & OFPFMF14_INSTRUCTIONS) { const struct rule_actions *actions = rule_get_actions(rule); fu.ofpacts = actions->ofpacts; fu.ofpacts_len = actions->ofpacts_len; diff --git a/ofproto/connmgr.h b/ofproto/connmgr.h index b6fc90b..c0cf6f0 100644 --- a/ofproto/connmgr.h +++ b/ofproto/connmgr.h @@ -202,7 +202,7 @@ struct ofmonitor { struct hmap_node ofconn_node; /* In ofconn's 'monitors' hmap. */ uint32_t id; - enum nx_flow_monitor_flags flags; + enum ofp14_flow_monitor_flags flags; /* Matching. */ ofp_port_t out_port; diff --git a/ofproto/ofproto-provider.h b/ofproto/ofproto-provider.h index 7741044..aa5adf9 100644 --- a/ofproto/ofproto-provider.h +++ b/ofproto/ofproto-provider.h @@ -384,7 +384,7 @@ struct rule { * 'add_seqno' is the sequence number when this rule was created. * 'modify_seqno' is the sequence number when this rule was last modified. * See 'monitor_seqno' in connmgr.c for more information. */ - enum nx_flow_monitor_flags monitor_flags OVS_GUARDED_BY(ofproto_mutex); + enum ofp14_flow_monitor_flags monitor_flags OVS_GUARDED_BY(ofproto_mutex); uint64_t add_seqno OVS_GUARDED_BY(ofproto_mutex); uint64_t modify_seqno OVS_GUARDED_BY(ofproto_mutex); diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c index 4615f7e..648d2dc 100644 --- a/ofproto/ofproto.c +++ b/ofproto/ofproto.c @@ -4719,7 +4719,7 @@ handle_barrier_request(struct ofconn *ofconn, const struct ofp_header *oh) static void ofproto_compose_flow_refresh_update(const struct rule *rule, - enum nx_flow_monitor_flags flags, + enum ofp14_flow_monitor_flags flags, struct list *msgs) OVS_REQUIRES(ofproto_mutex) { @@ -4734,7 +4734,7 @@ ofproto_compose_flow_refresh_update(const struct rule *rule, return; } - fu.event = (flags & (NXFMF_INITIAL | NXFMF_ADD) + fu.event = (flags & (OFPFMF14_INITIAL | OFPFMF14_ADD) ? NXFME_ADDED : NXFME_MODIFIED); fu.reason = 0; ovs_mutex_lock(&rule->mutex); @@ -4747,7 +4747,7 @@ ofproto_compose_flow_refresh_update(const struct rule *rule, fu.match = &match; fu.priority = rule->cr.priority; - if (!(flags & NXFMF_ACTIONS)) { + if (!(flags & OFPFMF14_INSTRUCTIONS)) { actions = NULL; } else if (!op) { actions = rule_get_actions(rule); @@ -4789,7 +4789,7 @@ ofmonitor_compose_refresh_updates(struct rule_collection *rules, for (i = 0; i < rules->n; i++) { struct rule *rule = rules->rules[i]; - enum nx_flow_monitor_flags flags = rule->monitor_flags; + enum ofp14_flow_monitor_flags flags = rule->monitor_flags; rule->monitor_flags = 0; ofproto_compose_flow_refresh_update(rule, flags, msgs); @@ -4802,7 +4802,7 @@ ofproto_collect_ofmonitor_refresh_rule(const struct ofmonitor *m, struct rule_collection *rules) OVS_REQUIRES(ofproto_mutex) { - enum nx_flow_monitor_flags update; + enum ofp14_flow_monitor_flags update; if (ofproto_rule_is_hidden(rule)) { return; @@ -4816,9 +4816,9 @@ ofproto_collect_ofmonitor_refresh_rule(const struct ofmonitor *m, if (seqno) { if (rule->add_seqno > seqno) { - update = NXFMF_ADD | NXFMF_MODIFY; + update = OFPFMF14_ADD | OFPFMF14_MODIFY; } else if (rule->modify_seqno > seqno) { - update = NXFMF_MODIFY; + update = OFPFMF14_MODIFY; } else { return; } @@ -4827,13 +4827,13 @@ ofproto_collect_ofmonitor_refresh_rule(const struct ofmonitor *m, return; } } else { - update = NXFMF_INITIAL; + update = OFPFMF14_INITIAL; } if (!rule->monitor_flags) { rule_collection_add(rules, rule); } - rule->monitor_flags |= update | (m->flags & NXFMF_ACTIONS); + rule->monitor_flags |= update | (m->flags & OFPFMF14_INSTRUCTIONS); } static void @@ -4879,7 +4879,7 @@ ofproto_collect_ofmonitor_initial_rules(struct ofmonitor *m, struct rule_collection *rules) OVS_REQUIRES(ofproto_mutex) { - if (m->flags & NXFMF_INITIAL) { + if (m->flags & OFPFMF14_INITIAL) { ofproto_collect_ofmonitor_refresh_rules(m, 0, rules); } } -- 2.0.0.rc2 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev