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> --- v3 * Rebase v2 * No change --- lib/ofp-parse.c | 16 ++++++++-------- lib/ofp-print.c | 4 +++- lib/ofp-util.c | 37 ++++++++++++++++++++++++++++++++++--- 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, 68 insertions(+), 33 deletions(-) diff --git a/lib/ofp-parse.c b/lib/ofp-parse.c index 93bdbea..fbbe896 100644 --- a/lib/ofp-parse.c +++ b/lib/ofp-parse.c @@ -1724,8 +1724,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_NO_ABBREV | OFPFMF14_INSTRUCTIONS); fmr->out_port = OFPP_NONE; fmr->table_id = 0xff; match_init_catchall(&fmr->match); @@ -1735,17 +1735,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 9cd658e..94ece8f 100644 --- a/lib/ofp-util.c +++ b/lib/ofp-util.c @@ -5194,6 +5194,37 @@ 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); + + /* No other flags should be present. */ + ovs_assert(!(ofp_flags & ~nx_flags)); + + 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 + | OFPFMF14_NO_ABBREV); + + /* No other flags should be present. */ + ovs_assert(!(nx_flags & ~ofp_flags)); + + return nx_flags; +} + /* Converts an NXST_FLOW_MONITOR request in 'msg' into an abstract * ofputil_flow_monitor_request in 'rq'. * @@ -5209,7 +5240,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); @@ -5240,7 +5271,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; @@ -5265,7 +5296,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 878bcf8..2913e5a 100644 --- a/lib/ofp-util.h +++ b/lib/ofp-util.h @@ -837,15 +837,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 41a58c9..fd78d04 100644 --- a/ofproto/connmgr.c +++ b/ofproto/connmgr.c @@ -2072,7 +2072,7 @@ ofmonitor_report(struct connmgr *mgr, struct rule *rule, const struct rule_actions *old_actions) OVS_REQUIRES(ofproto_mutex) { - enum nx_flow_monitor_flags update; + enum ofp14_flow_monitor_flags update; struct ofconn *ofconn; if (rule_is_hidden(rule)) { @@ -2081,16 +2081,16 @@ ofmonitor_report(struct connmgr *mgr, struct rule *rule, 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; @@ -2100,7 +2100,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) { @@ -2131,7 +2131,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; @@ -2149,7 +2149,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 75a1ffe..196b8b9 100644 --- a/ofproto/connmgr.h +++ b/ofproto/connmgr.h @@ -199,7 +199,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 6d1fb14..60cba62 100644 --- a/ofproto/ofproto-provider.h +++ b/ofproto/ofproto-provider.h @@ -367,7 +367,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 50ba91a..b5abcb8 100644 --- a/ofproto/ofproto.c +++ b/ofproto/ofproto.c @@ -4699,7 +4699,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) { @@ -4707,7 +4707,7 @@ ofproto_compose_flow_refresh_update(const struct rule *rule, struct ofputil_flow_update fu; struct match match; - 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); @@ -4720,7 +4720,7 @@ ofproto_compose_flow_refresh_update(const struct rule *rule, fu.match = &match; fu.priority = rule->cr.priority; - actions = flags & NXFMF_ACTIONS ? rule_get_actions(rule) : NULL; + actions = flags & OFPFMF14_INSTRUCTIONS ? rule_get_actions(rule) : NULL; fu.ofpacts = actions ? actions->ofpacts : NULL; fu.ofpacts_len = actions ? actions->ofpacts_len : 0; @@ -4739,7 +4739,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); @@ -4752,7 +4752,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 (rule_is_hidden(rule)) { return; @@ -4764,9 +4764,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; } @@ -4775,13 +4775,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 @@ -4814,7 +4814,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