diff options
author | Ben Pfaff <blp@ovn.org> | 2017-05-31 16:06:12 -0700 |
---|---|---|
committer | Ben Pfaff <blp@ovn.org> | 2017-05-31 16:06:12 -0700 |
commit | 50f96b10e1c87db9fbe4df297f9b2fea13436bc0 (patch) | |
tree | 9122b84ecb6d90d0ba343f1f7b451b2db057870f /ofproto | |
parent | 52182c5f50198d0f985b10677e47a9ac49ee709b (diff) | |
download | openvswitch-50f96b10e1c87db9fbe4df297f9b2fea13436bc0.tar.gz |
Support accepting and displaying port names in OVS tools.
Until now, most ovs-ofctl commands have not accepted names for ports, only
numbers, and have not been able to display port names either. It's a lot
easier for users if they can use and see meaningful names instead of
arbitrary numbers. This commit adds that support.
For backward compatibility, only interactive ovs-ofctl commands by default
display port names; to display them in scripts, use the new --names
option.
Signed-off-by: Ben Pfaff <blp@ovn.org>
Tested-by: Aaron Conole <aconole@redhat.com>
Diffstat (limited to 'ofproto')
-rw-r--r-- | ofproto/bond.c | 6 | ||||
-rw-r--r-- | ofproto/ofproto-dpif-trace.c | 18 | ||||
-rw-r--r-- | ofproto/ofproto-dpif-xlate.c | 20 | ||||
-rw-r--r-- | ofproto/ofproto-dpif.c | 6 | ||||
-rw-r--r-- | ofproto/ofproto.c | 4 | ||||
-rw-r--r-- | ofproto/tunnel.c | 12 |
6 files changed, 37 insertions, 29 deletions
diff --git a/ofproto/bond.c b/ofproto/bond.c index 441ca44fa..21370b5f9 100644 --- a/ofproto/bond.c +++ b/ofproto/bond.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Nicira, Inc. + * Copyright (c) 2008-2017 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -372,7 +372,7 @@ update_recirc_rules__(struct bond *bond) RECIRC_RULE_PRIORITY, 0, &ofpacts, pr_op->pr_rule); if (error) { - char *err_s = match_to_string(&pr_op->match, + char *err_s = match_to_string(&pr_op->match, NULL, RECIRC_RULE_PRIORITY); VLOG_ERR("failed to add post recirculation flow %s", err_s); @@ -385,7 +385,7 @@ update_recirc_rules__(struct bond *bond) &pr_op->match, RECIRC_RULE_PRIORITY); if (error) { - char *err_s = match_to_string(&pr_op->match, + char *err_s = match_to_string(&pr_op->match, NULL, RECIRC_RULE_PRIORITY); VLOG_ERR("failed to remove post recirculation flow %s", err_s); diff --git a/ofproto/ofproto-dpif-trace.c b/ofproto/ofproto-dpif-trace.c index d1cb1ddbb..c7f0e48ca 100644 --- a/ofproto/ofproto-dpif-trace.c +++ b/ofproto/ofproto-dpif-trace.c @@ -253,9 +253,16 @@ parse_flow_and_packet(int argc, const char *argv[], goto exit; } + struct ofputil_port_map map = OFPUTIL_PORT_MAP_INITIALIZER(&map); + const struct ofport *ofport; + HMAP_FOR_EACH (ofport, hmap_node, &(*ofprotop)->up.ports) { + ofputil_port_map_put(&map, ofport->ofp_port, + netdev_get_name(ofport->netdev)); + } err = parse_ofp_exact_flow(flow, NULL, ofproto_get_tun_tab(&(*ofprotop)->up), - argv[argc - 1], NULL); + argv[argc - 1], &map); + ofputil_port_map_destroy(&map); if (err) { m_err = xasprintf("Bad openflow flow syntax: %s", err); free(err); @@ -336,7 +343,8 @@ ofproto_unixctl_trace_actions(struct unixctl_conn *conn, int argc, ofpbuf_init(&ofpacts, 0); /* Parse actions. */ - error = ofpacts_parse_actions(argv[--argc], &ofpacts, &usable_protocols); + error = ofpacts_parse_actions(argv[--argc], NULL, + &ofpacts, &usable_protocols); if (error) { unixctl_command_reply_error(conn, error); free(error); @@ -444,7 +452,7 @@ ofproto_trace(struct ofproto_dpif *ofproto, struct flow *flow, * xlate_in_init() initializes actset_output to OFPP_UNSET. */ struct flow initial_flow = xin.flow; ds_put_cstr(output, "Flow: "); - flow_format(output, &initial_flow); + flow_format(output, &initial_flow, NULL); ds_put_char(output, '\n'); struct xlate_out xout; @@ -456,14 +464,14 @@ ofproto_trace(struct ofproto_dpif *ofproto, struct flow *flow, if (flow_equal(&initial_flow, &xin.flow)) { ds_put_cstr(output, "unchanged"); } else { - flow_format(output, &xin.flow); + flow_format(output, &xin.flow, NULL); } ds_put_char(output, '\n'); ds_put_cstr(output, "Megaflow: "); struct match match; match_init(&match, flow, &wc); - match_format(&match, output, OFP_DEFAULT_PRIORITY); + match_format(&match, NULL, output, OFP_DEFAULT_PRIORITY); ds_put_char(output, '\n'); ds_put_cstr(output, "Datapath actions: "); diff --git a/ofproto/ofproto-dpif-xlate.c b/ofproto/ofproto-dpif-xlate.c index f71a9db0a..84efaaba1 100644 --- a/ofproto/ofproto-dpif-xlate.c +++ b/ofproto/ofproto-dpif-xlate.c @@ -625,7 +625,7 @@ xlate_report_error(const struct xlate_ctx *ctx, const char *format, ...) oftrace_report(ctx->xin->trace, OFT_ERROR, ds_cstr(&s)); } else { ds_put_cstr(&s, " while processing "); - flow_format(&s, &ctx->base_flow); + flow_format(&s, &ctx->base_flow, NULL); ds_put_format(&s, " on bridge %s", ctx->xbridge->name); VLOG_WARN("%s", ds_cstr(&s)); } @@ -672,7 +672,7 @@ xlate_report_actions(const struct xlate_ctx *ctx, enum oftrace_node_type type, if (OVS_UNLIKELY(ctx->xin->trace)) { struct ds s = DS_EMPTY_INITIALIZER; ds_put_format(&s, "%s: ", title); - ofpacts_format(ofpacts, ofpacts_len, &s); + ofpacts_format(ofpacts, ofpacts_len, NULL, &s); oftrace_report(ctx->xin->trace, type, ds_cstr(&s)); ds_destroy(&s); } @@ -693,7 +693,7 @@ xlate_report_action_set(const struct xlate_ctx *ctx, const char *verb) ofpacts_execute_action_set(&action_list, &ctx->action_set); if (action_list.size) { struct ds s = DS_EMPTY_INITIALIZER; - ofpacts_format(action_list.data, action_list.size, &s); + ofpacts_format(action_list.data, action_list.size, NULL, &s); xlate_report(ctx, OFT_DETAIL, "action set %s: %s", verb, ds_cstr(&s)); ds_destroy(&s); @@ -732,7 +732,7 @@ xlate_report_table(const struct xlate_ctx *ctx, struct rule_dpif *rule, } else { minimatch_format(&rule->up.cr.match, ofproto_get_tun_tab(&ctx->xin->ofproto->up), - &s, OFP_DEFAULT_PRIORITY); + NULL, &s, OFP_DEFAULT_PRIORITY); if (ds_last(&s) != ' ') { ds_put_cstr(&s, ", "); } @@ -763,7 +763,7 @@ xlate_report_subfield(const struct xlate_ctx *ctx, if (sf->ofs == 0 && sf->n_bits >= sf->field->n_bits) { union mf_value value; mf_get_value(sf->field, &ctx->xin->flow, &value); - mf_format(sf->field, &value, NULL, &s); + mf_format(sf->field, &value, NULL, NULL, &s); } else { union mf_subvalue cst; mf_read_subfield(sf, &ctx->xin->flow, &cst); @@ -4620,7 +4620,7 @@ xlate_output_trunc_action(struct xlate_ctx *ctx, case OFPP_ALL: case OFPP_CONTROLLER: case OFPP_NONE: - ofputil_port_to_string(port, name, sizeof name); + ofputil_port_to_string(port, NULL, name, sizeof name); xlate_report(ctx, OFT_WARN, "output_trunc does not support port: %s", name); break; @@ -4634,7 +4634,7 @@ xlate_output_trunc_action(struct xlate_ctx *ctx, /* Since truncate happens at its following output action, if * the output port is a patch port, the behavior is somehow * unpredictable. For simplicity, disallow this case. */ - ofputil_port_to_string(port, name, sizeof name); + ofputil_port_to_string(port, NULL, name, sizeof name); xlate_report_error(ctx, "output_trunc does not support " "patch port %s", name); break; @@ -4767,7 +4767,7 @@ xlate_learn_action(struct xlate_ctx *ctx, const struct ofpact_learn *learn) if (OVS_UNLIKELY(ctx->xin->trace)) { struct ds s = DS_EMPTY_INITIALIZER; ds_put_format(&s, "table=%"PRIu8" ", fm.table_id); - match_format(&fm.match, &s, OFP_DEFAULT_PRIORITY); + match_format(&fm.match, NULL, &s, OFP_DEFAULT_PRIORITY); ds_chomp(&s, ' '); ds_put_format(&s, " priority=%d", fm.priority); if (fm.new_cookie) { @@ -4783,7 +4783,7 @@ xlate_learn_action(struct xlate_ctx *ctx, const struct ofpact_learn *learn) ds_put_cstr(&s, " send_flow_rem"); } ds_put_cstr(&s, " actions="); - ofpacts_format(fm.ofpacts, fm.ofpacts_len, &s); + ofpacts_format(fm.ofpacts, fm.ofpacts_len, NULL, &s); xlate_report(ctx, OFT_DETAIL, "%s", ds_cstr(&s)); ds_destroy(&s); } @@ -5564,7 +5564,7 @@ do_xlate_actions(const struct ofpact *ofpacts, size_t ofpacts_len, if (OVS_UNLIKELY(ctx->xin->trace)) { struct ds s = DS_EMPTY_INITIALIZER; - ofpacts_format(a, OFPACT_ALIGN(a->len), &s); + ofpacts_format(a, OFPACT_ALIGN(a->len), NULL, &s); xlate_report(ctx, OFT_ACTION, "%s", ds_cstr(&s)); ds_destroy(&s); } diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c index afc169db6..5d247e3e6 100644 --- a/ofproto/ofproto-dpif.c +++ b/ofproto/ofproto-dpif.c @@ -5016,7 +5016,7 @@ ofproto_unixctl_fdb_show(struct unixctl_conn *conn, int argc OVS_UNUSED, char name[OFP10_MAX_PORT_NAME_LEN]; ofputil_port_to_string(ofbundle_get_a_port(bundle)->up.ofp_port, - name, sizeof name); + NULL, name, sizeof name); ds_put_format(&ds, "%5s %4d "ETH_ADDR_FMT" %3d\n", name, e->vlan, ETH_ADDR_ARGS(e->mac), mac_entry_age(ofproto->ml, e)); @@ -5058,7 +5058,7 @@ ofproto_unixctl_mcast_snooping_show(struct unixctl_conn *conn, bundle = b->port; ofputil_port_to_string(ofbundle_get_a_port(bundle)->up.ofp_port, - name, sizeof name); + NULL, name, sizeof name); ds_put_format(&ds, "%5s %4d ", name, grp->vlan); ipv6_format_mapped(&grp->addr, &ds); ds_put_format(&ds, " %3d\n", @@ -5072,7 +5072,7 @@ ofproto_unixctl_mcast_snooping_show(struct unixctl_conn *conn, bundle = mrouter->port; ofputil_port_to_string(ofbundle_get_a_port(bundle)->up.ofp_port, - name, sizeof name); + NULL, name, sizeof name); ds_put_format(&ds, "%5s %4d querier %3d\n", name, mrouter->vlan, mcast_mrouter_age(ofproto->ms, mrouter)); diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c index bfa6917b7..a75d41411 100644 --- a/ofproto/ofproto.c +++ b/ofproto/ofproto.c @@ -4385,11 +4385,11 @@ flow_stats_ds(struct ofproto *ofproto, struct rule *rule, struct ds *results) ds_put_format(results, "duration=%llds, ", (time_msec() - created) / 1000); ds_put_format(results, "n_packets=%"PRIu64", ", packet_count); ds_put_format(results, "n_bytes=%"PRIu64", ", byte_count); - cls_rule_format(&rule->cr, ofproto_get_tun_tab(ofproto), results); + cls_rule_format(&rule->cr, ofproto_get_tun_tab(ofproto), NULL, results); ds_put_char(results, ','); ds_put_cstr(results, "actions="); - ofpacts_format(actions->ofpacts, actions->ofpacts_len, results); + ofpacts_format(actions->ofpacts, actions->ofpacts_len, NULL, results); ds_put_cstr(results, "\n"); } diff --git a/ofproto/tunnel.c b/ofproto/tunnel.c index e285d5464..1129547d7 100644 --- a/ofproto/tunnel.c +++ b/ofproto/tunnel.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2013, 2014, 2015 Nicira, Inc. +/* Copyright (c) 2013, 2014, 2015, 2017 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -301,7 +301,7 @@ tnl_port_receive(const struct flow *flow) OVS_EXCLUDED(rwlock) tnl_port = tnl_find(flow); ofport = tnl_port ? tnl_port->ofport : NULL; if (!tnl_port) { - char *flow_str = flow_to_string(flow); + char *flow_str = flow_to_string(flow, NULL); VLOG_WARN_RL(&rl, "receive tunnel port not found (%s)", flow_str); free(flow_str); @@ -309,11 +309,11 @@ tnl_port_receive(const struct flow *flow) OVS_EXCLUDED(rwlock) } if (!VLOG_DROP_DBG(&dbg_rl)) { - pre_flow_str = flow_to_string(flow); + pre_flow_str = flow_to_string(flow, NULL); } if (pre_flow_str) { - char *post_flow_str = flow_to_string(flow); + char *post_flow_str = flow_to_string(flow, NULL); char *tnl_str = tnl_port_fmt(tnl_port); VLOG_DBG("flow received\n" "%s" @@ -408,7 +408,7 @@ tnl_port_send(const struct ofport_dpif *ofport, struct flow *flow, ovs_assert(cfg); if (!VLOG_DROP_DBG(&dbg_rl)) { - pre_flow_str = flow_to_string(flow); + pre_flow_str = flow_to_string(flow, NULL); } if (!cfg->ip_src_flow) { @@ -467,7 +467,7 @@ tnl_port_send(const struct ofport_dpif *ofport, struct flow *flow, } if (pre_flow_str) { - char *post_flow_str = flow_to_string(flow); + char *post_flow_str = flow_to_string(flow, NULL); char *tnl_str = tnl_port_fmt(tnl_port); VLOG_DBG("flow sent\n" "%s" |