#include "sflow_api.h"
+struct rule;
+
struct ofport {
struct hmap_node hmap_node; /* In struct ofproto's "ports" hmap. */
struct netdev *netdev;
static void ofport_free(struct ofport *);
static void hton_ofp_phy_port(struct ofp_phy_port *);
-static int xlate_actions(const union ofp_action *in, size_t n_in,
- const struct flow *, struct ofproto *,
- const struct ofpbuf *packet,
- struct odp_actions *out, tag_type *tags,
- bool *may_set_up_flow, uint16_t *nf_output_iface);
+struct action_xlate_ctx {
+/* action_xlate_ctx_init() initializes these members. */
+
+ /* The ofproto. */
+ struct ofproto *ofproto;
+
+ /* Flow to which the OpenFlow actions apply. xlate_actions() will modify
+ * this flow when actions change header fields. */
+ struct flow flow;
+
+ /* The packet corresponding to 'flow', or a null pointer if we are
+ * revalidating without a packet to refer to. */
+ const struct ofpbuf *packet;
+
+ /* If nonnull, called just before executing a resubmit action.
+ *
+ * This is normally null so the client has to set it manually after
+ * calling action_xlate_ctx_init(). */
+ void (*resubmit_hook)(struct action_xlate_ctx *, const struct rule *);
+
+/* xlate_actions() initializes and uses these members. The client might want
+ * to look at them after it returns. */
+
+ /* Datapath action set. This is xlate_actions()'s primary output. */
+ struct odp_actions out;
+
+ tag_type tags; /* Tags associated with OFPP_NORMAL actions. */
+ bool may_set_up_flow; /* True ordinarily; false if the actions must
+ * be reassessed for every packet. */
+ uint16_t nf_output_iface; /* Output interface index for NetFlow. */
+
+/* xlate_actions() initializes and uses these members, but the client has no
+ * reason to look at them. */
+
+ int recurse; /* Recursion level, via xlate_table_action. */
+};
+
+static void action_xlate_ctx_init(struct action_xlate_ctx *,
+ struct ofproto *, const struct flow *,
+ const struct ofpbuf *);
+static int xlate_actions(struct action_xlate_ctx *ctx,
+ const union ofp_action *in, size_t n_in);
/* An OpenFlow flow. */
struct rule {
struct mac_learning *ml;
};
+/* Map from dpif name to struct ofproto, for use by unixctl commands. */
+static struct shash all_ofprotos = SHASH_INITIALIZER(&all_ofprotos);
+
static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
static const struct ofhooks default_ofhooks;
static int init_ports(struct ofproto *);
static void reinit_ports(struct ofproto *);
+static void ofproto_unixctl_init(void);
+
int
ofproto_create(const char *datapath, const char *datapath_type,
const struct ofhooks *ofhooks, void *aux,
*ofprotop = NULL;
+ ofproto_unixctl_init();
+
/* Connect to datapath and start listening for messages. */
error = dpif_open(datapath, datapath_type, &dpif);
if (error) {
p->datapath_id = pick_datapath_id(p);
VLOG_INFO("using datapath ID %016"PRIx64, p->datapath_id);
+ shash_add_once(&all_ofprotos, dpif_name(p->dpif), p);
+
*ofprotop = p;
return 0;
}
return;
}
+ shash_find_and_delete(&all_ofprotos, dpif_name(p->dpif));
+
/* Destroy fail-open and in-band early, since they touch the classifier. */
fail_open_destroy(p->fail_open);
p->fail_open = NULL;
const union ofp_action *actions, size_t n_actions,
const struct ofpbuf *packet)
{
- struct odp_actions odp_actions;
+ struct action_xlate_ctx ctx;
int error;
- error = xlate_actions(actions, n_actions, flow, p, packet, &odp_actions,
- NULL, NULL, NULL);
+ action_xlate_ctx_init(&ctx, p, flow, packet);
+ error = xlate_actions(&ctx, actions, n_actions);
if (error) {
return error;
}
/* XXX Should we translate the dpif_execute() errno value into an OpenFlow
* error code? */
- dpif_execute(p->dpif, odp_actions.actions, odp_actions.n_actions, packet);
+ dpif_execute(p->dpif, ctx.out.actions, ctx.out.n_actions, packet);
return 0;
}
rule_execute(struct ofproto *ofproto, struct rule *rule, uint16_t in_port,
struct ofpbuf *packet)
{
+ struct action_xlate_ctx ctx;
struct facet *facet;
- struct odp_actions a;
struct flow flow;
size_t size;
/* We can't account anything to a facet. If we were to try, then that
* facet would have a non-matching rule, busting our invariants. */
- if (xlate_actions(rule->actions, rule->n_actions, &flow, ofproto,
- packet, &a, NULL, 0, NULL)) {
+ action_xlate_ctx_init(&ctx, ofproto, &flow, packet);
+ if (xlate_actions(&ctx, rule->actions, rule->n_actions)) {
ofpbuf_delete(packet);
return;
}
+
size = packet->size;
if (execute_odp_actions(ofproto, in_port,
- a.actions, a.n_actions, packet)) {
+ ctx.out.actions, ctx.out.n_actions, packet)) {
rule->used = time_msec();
rule->packet_count++;
rule->byte_count += size;
const struct ofpbuf *packet)
{
const struct rule *rule = facet->rule;
- struct odp_actions a;
+ struct action_xlate_ctx ctx;
size_t actions_len;
- xlate_actions(rule->actions, rule->n_actions, &facet->flow, p,
- packet, &a, &facet->tags, &facet->may_install,
- &facet->nf_flow.output_iface);
+ action_xlate_ctx_init(&ctx, p, &facet->flow, packet);
+ xlate_actions(&ctx, rule->actions, rule->n_actions);
+ facet->tags = ctx.tags;
+ facet->may_install = ctx.may_set_up_flow;
+ facet->nf_flow.output_iface = ctx.nf_output_iface;
- actions_len = a.n_actions * sizeof *a.actions;
- if (facet->n_actions != a.n_actions
- || memcmp(facet->actions, a.actions, actions_len)) {
+ actions_len = ctx.out.n_actions * sizeof *ctx.out.actions;
+ if (facet->n_actions != ctx.out.n_actions
+ || memcmp(facet->actions, ctx.out.actions, actions_len)) {
free(facet->actions);
- facet->n_actions = a.n_actions;
- facet->actions = xmemdup(a.actions, actions_len);
+ facet->n_actions = ctx.out.n_actions;
+ facet->actions = xmemdup(ctx.out.actions, actions_len);
}
}
static bool
facet_revalidate(struct ofproto *ofproto, struct facet *facet)
{
+ struct action_xlate_ctx ctx;
struct rule *new_rule;
- struct odp_actions a;
size_t actions_len;
- uint16_t new_nf_output_iface;
bool actions_changed;
COVERAGE_INC(facet_revalidate);
* We are very cautious about actually modifying 'facet' state at this
* point, because we might need to, e.g., emit a NetFlow expiration and, if
* so, we need to have the old state around to properly compose it. */
- xlate_actions(new_rule->actions, new_rule->n_actions, &facet->flow,
- ofproto, NULL, &a, &facet->tags, &facet->may_install,
- &new_nf_output_iface);
- actions_len = a.n_actions * sizeof *a.actions;
- actions_changed = (facet->n_actions != a.n_actions
- || memcmp(facet->actions, a.actions, actions_len));
+ action_xlate_ctx_init(&ctx, ofproto, &facet->flow, NULL);
+ xlate_actions(&ctx, new_rule->actions, new_rule->n_actions);
+ actions_len = ctx.out.n_actions * sizeof *ctx.out.actions;
+ actions_changed = (facet->n_actions != ctx.out.n_actions
+ || memcmp(facet->actions, ctx.out.actions,
+ actions_len));
/* If the ODP actions changed or the installability changed, then we need
* to talk to the datapath. */
memset(&put.flow.stats, 0, sizeof put.flow.stats);
odp_flow_key_from_flow(&put.flow.key, &facet->flow);
- put.flow.actions = a.actions;
- put.flow.n_actions = a.n_actions;
+ put.flow.actions = ctx.out.actions;
+ put.flow.n_actions = ctx.out.n_actions;
put.flow.flags = 0;
put.flags = ODPPF_CREATE | ODPPF_MODIFY | ODPPF_ZERO_STATS;
dpif_flow_put(ofproto->dpif, &put);
}
/* Update 'facet' now that we've taken care of all the old state. */
- facet->nf_flow.output_iface = new_nf_output_iface;
+ facet->tags = ctx.tags;
+ facet->nf_flow.output_iface = ctx.nf_output_iface;
+ facet->may_install = ctx.may_set_up_flow;
if (actions_changed) {
free(facet->actions);
- facet->n_actions = a.n_actions;
- facet->actions = xmemdup(a.actions, actions_len);
+ facet->n_actions = ctx.out.n_actions;
+ facet->actions = xmemdup(ctx.out.actions, actions_len);
}
if (facet->rule != new_rule) {
COVERAGE_INC(facet_changed_rule);
a->controller.arg = max_len;
}
-struct action_xlate_ctx {
- /* Input. */
- struct flow flow; /* Flow to which these actions correspond. */
- int recurse; /* Recursion level, via xlate_table_action. */
- struct ofproto *ofproto;
- const struct ofpbuf *packet; /* The packet corresponding to 'flow', or a
- * null pointer if we are revalidating
- * without a packet to refer to. */
-
- /* Output. */
- struct odp_actions *out; /* Datapath actions. */
- tag_type tags; /* Tags associated with OFPP_NORMAL actions. */
- bool may_set_up_flow; /* True ordinarily; false if the actions must
- * be reassessed for every packet. */
- uint16_t nf_output_iface; /* Output interface index for NetFlow. */
-};
-
/* Maximum depth of flow table recursion (due to NXAST_RESUBMIT actions) in a
* flow translation. */
#define MAX_RESUBMIT_RECURSION 8
*/
}
- odp_actions_add(ctx->out, ODPAT_OUTPUT)->output.port = port;
+ odp_actions_add(&ctx->out, ODPAT_OUTPUT)->output.port = port;
ctx->nf_output_iface = port;
}
rule = rule_lookup(ctx->ofproto, &ctx->flow);
ctx->flow.in_port = old_in_port;
+ if (ctx->resubmit_hook) {
+ ctx->resubmit_hook(ctx, rule);
+ }
+
if (rule) {
ctx->recurse++;
do_xlate_actions(rule->actions, rule->n_actions, ctx);
break;
case OFPP_NORMAL:
if (!ctx->ofproto->ofhooks->normal_cb(&ctx->flow, ctx->packet,
- ctx->out, &ctx->tags,
+ &ctx->out, &ctx->tags,
&ctx->nf_output_iface,
ctx->ofproto->aux)) {
COVERAGE_INC(ofproto_uninstallable);
break;
case OFPP_FLOOD:
flood_packets(ctx->ofproto, ctx->flow.in_port, OFPPC_NO_FLOOD,
- &ctx->nf_output_iface, ctx->out);
+ &ctx->nf_output_iface, &ctx->out);
break;
case OFPP_ALL:
flood_packets(ctx->ofproto, ctx->flow.in_port, 0,
- &ctx->nf_output_iface, ctx->out);
+ &ctx->nf_output_iface, &ctx->out);
break;
case OFPP_CONTROLLER:
- add_controller_action(ctx->out, max_len);
+ add_controller_action(&ctx->out, max_len);
break;
case OFPP_LOCAL:
add_output_action(ctx, ODPP_LOCAL);
static void
remove_pop_action(struct action_xlate_ctx *ctx)
{
- size_t n = ctx->out->n_actions;
- if (n > 0 && ctx->out->actions[n - 1].type == ODPAT_POP_PRIORITY) {
- ctx->out->n_actions--;
+ size_t n = ctx->out.n_actions;
+ if (n > 0 && ctx->out.actions[n - 1].type == ODPAT_POP_PRIORITY) {
+ ctx->out.n_actions--;
}
}
/* Add ODP actions. */
remove_pop_action(ctx);
- odp_actions_add(ctx->out, ODPAT_SET_PRIORITY)->priority.priority
+ odp_actions_add(&ctx->out, ODPAT_SET_PRIORITY)->priority.priority
= priority;
add_output_action(ctx, odp_port);
- odp_actions_add(ctx->out, ODPAT_POP_PRIORITY);
+ odp_actions_add(&ctx->out, ODPAT_POP_PRIORITY);
/* Update NetFlow output port. */
if (ctx->nf_output_iface == NF_OUT_DROP) {
}
remove_pop_action(ctx);
- odp_actions_add(ctx->out, ODPAT_SET_PRIORITY)->priority.priority
+ odp_actions_add(&ctx->out, ODPAT_SET_PRIORITY)->priority.priority
= priority;
}
{
ovs_be16 tci = ctx->flow.vlan_tci;
if (!(tci & htons(VLAN_CFI))) {
- odp_actions_add(ctx->out, ODPAT_STRIP_VLAN);
+ odp_actions_add(&ctx->out, ODPAT_STRIP_VLAN);
} else {
- union odp_action *oa = odp_actions_add(ctx->out, ODPAT_SET_DL_TCI);
+ union odp_action *oa = odp_actions_add(&ctx->out, ODPAT_SET_DL_TCI);
oa->dl_tci.tci = tci & ~htons(VLAN_CFI);
}
}
const struct nx_action_set_tunnel *nast;
const struct nx_action_set_queue *nasq;
union odp_action *oa;
- int subtype = ntohs(nah->subtype);
+ enum nx_action_subtype subtype = ntohs(nah->subtype);
assert(nah->vendor == htonl(NX_VENDOR_ID));
switch (subtype) {
case NXAST_SET_TUNNEL:
nast = (const struct nx_action_set_tunnel *) nah;
- oa = odp_actions_add(ctx->out, ODPAT_SET_TUNNEL);
+ oa = odp_actions_add(&ctx->out, ODPAT_SET_TUNNEL);
ctx->flow.tun_id = oa->tunnel.tun_id = nast->tun_id;
break;
case NXAST_DROP_SPOOFED_ARP:
if (ctx->flow.dl_type == htons(ETH_TYPE_ARP)) {
- odp_actions_add(ctx->out, ODPAT_DROP_SPOOFED_ARP);
+ odp_actions_add(&ctx->out, ODPAT_DROP_SPOOFED_ARP);
}
break;
break;
case NXAST_POP_QUEUE:
- odp_actions_add(ctx->out, ODPAT_POP_PRIORITY);
+ odp_actions_add(&ctx->out, ODPAT_POP_PRIORITY);
break;
case NXAST_REG_MOVE:
/* If you add a new action here that modifies flow data, don't forget to
* update the flow key in ctx->flow at the same time. */
+ case NXAST_SNAT__OBSOLETE:
default:
- VLOG_DBG_RL(&rl, "unknown Nicira action type %"PRIu16, subtype);
+ VLOG_DBG_RL(&rl, "unknown Nicira action type %d", (int) subtype);
break;
}
}
}
for (ia = actions_first(&iter, in, n_in); ia; ia = actions_next(&iter)) {
- uint16_t type = ntohs(ia->type);
+ enum ofp_action_type type = ntohs(ia->type);
union odp_action *oa;
switch (type) {
break;
case OFPAT_SET_DL_SRC:
- oa = odp_actions_add(ctx->out, ODPAT_SET_DL_SRC);
+ oa = odp_actions_add(&ctx->out, ODPAT_SET_DL_SRC);
memcpy(oa->dl_addr.dl_addr,
((struct ofp_action_dl_addr *) ia)->dl_addr, ETH_ADDR_LEN);
memcpy(ctx->flow.dl_src,
break;
case OFPAT_SET_DL_DST:
- oa = odp_actions_add(ctx->out, ODPAT_SET_DL_DST);
+ oa = odp_actions_add(&ctx->out, ODPAT_SET_DL_DST);
memcpy(oa->dl_addr.dl_addr,
((struct ofp_action_dl_addr *) ia)->dl_addr, ETH_ADDR_LEN);
memcpy(ctx->flow.dl_dst,
break;
case OFPAT_SET_NW_SRC:
- oa = odp_actions_add(ctx->out, ODPAT_SET_NW_SRC);
+ oa = odp_actions_add(&ctx->out, ODPAT_SET_NW_SRC);
ctx->flow.nw_src = oa->nw_addr.nw_addr = ia->nw_addr.nw_addr;
break;
case OFPAT_SET_NW_DST:
- oa = odp_actions_add(ctx->out, ODPAT_SET_NW_DST);
+ oa = odp_actions_add(&ctx->out, ODPAT_SET_NW_DST);
ctx->flow.nw_dst = oa->nw_addr.nw_addr = ia->nw_addr.nw_addr;
break;
case OFPAT_SET_NW_TOS:
- oa = odp_actions_add(ctx->out, ODPAT_SET_NW_TOS);
+ oa = odp_actions_add(&ctx->out, ODPAT_SET_NW_TOS);
ctx->flow.nw_tos = oa->nw_tos.nw_tos = ia->nw_tos.nw_tos;
break;
case OFPAT_SET_TP_SRC:
- oa = odp_actions_add(ctx->out, ODPAT_SET_TP_SRC);
+ oa = odp_actions_add(&ctx->out, ODPAT_SET_TP_SRC);
ctx->flow.tp_src = oa->tp_port.tp_port = ia->tp_port.tp_port;
break;
case OFPAT_SET_TP_DST:
- oa = odp_actions_add(ctx->out, ODPAT_SET_TP_DST);
+ oa = odp_actions_add(&ctx->out, ODPAT_SET_TP_DST);
ctx->flow.tp_dst = oa->tp_port.tp_port = ia->tp_port.tp_port;
break;
break;
default:
- VLOG_DBG_RL(&rl, "unknown action type %"PRIu16, type);
+ VLOG_DBG_RL(&rl, "unknown action type %d", (int) type);
break;
}
}
}
-static int
-xlate_actions(const union ofp_action *in, size_t n_in,
- const struct flow *flow, struct ofproto *ofproto,
- const struct ofpbuf *packet,
- struct odp_actions *out, tag_type *tags, bool *may_set_up_flow,
- uint16_t *nf_output_iface)
+static void
+action_xlate_ctx_init(struct action_xlate_ctx *ctx,
+ struct ofproto *ofproto, const struct flow *flow,
+ const struct ofpbuf *packet)
{
- struct action_xlate_ctx ctx;
+ ctx->ofproto = ofproto;
+ ctx->flow = *flow;
+ ctx->packet = packet;
+ ctx->resubmit_hook = NULL;
+}
+static int
+xlate_actions(struct action_xlate_ctx *ctx,
+ const union ofp_action *in, size_t n_in)
+{
COVERAGE_INC(ofproto_ofp2odp);
- odp_actions_init(out);
- ctx.flow = *flow;
- ctx.recurse = 0;
- ctx.ofproto = ofproto;
- ctx.packet = packet;
- ctx.out = out;
- ctx.tags = 0;
- ctx.may_set_up_flow = true;
- ctx.nf_output_iface = NF_OUT_DROP;
- do_xlate_actions(in, n_in, &ctx);
- remove_pop_action(&ctx);
+ odp_actions_init(&ctx->out);
+ ctx->tags = 0;
+ ctx->may_set_up_flow = true;
+ ctx->nf_output_iface = NF_OUT_DROP;
+ ctx->recurse = 0;
+ do_xlate_actions(in, n_in, ctx);
+ remove_pop_action(ctx);
/* Check with in-band control to see if we're allowed to set up this
* flow. */
- if (!in_band_rule_check(ofproto->in_band, flow, out)) {
- ctx.may_set_up_flow = false;
+ if (!in_band_rule_check(ctx->ofproto->in_band, &ctx->flow, &ctx->out)) {
+ ctx->may_set_up_flow = false;
}
- if (tags) {
- *tags = ctx.tags;
- }
- if (may_set_up_flow) {
- *may_set_up_flow = ctx.may_set_up_flow;
- }
- if (nf_output_iface) {
- *nf_output_iface = ctx.nf_output_iface;
- }
- if (odp_actions_overflow(out)) {
+ if (odp_actions_overflow(&ctx->out)) {
COVERAGE_INC(odp_overflow);
- odp_actions_init(out);
+ odp_actions_init(&ctx->out);
return ofp_mkerr(OFPET_BAD_ACTION, OFPBAC_TOO_MANY);
}
return 0;
struct ofp_packet_out *opo;
struct ofpbuf payload, *buffer;
union ofp_action *ofp_actions;
- struct odp_actions odp_actions;
+ struct action_xlate_ctx ctx;
struct ofpbuf request;
struct flow flow;
size_t n_ofp_actions;
}
/* Send. */
- error = xlate_actions(ofp_actions, n_ofp_actions, &flow, p, &payload,
- &odp_actions, NULL, NULL, NULL);
+ action_xlate_ctx_init(&ctx, p, &flow, &payload);
+ error = xlate_actions(&ctx, ofp_actions, n_ofp_actions);
if (!error) {
- dpif_execute(p->dpif, odp_actions.actions, odp_actions.n_actions,
- &payload);
+ dpif_execute(p->dpif, ctx.out.actions, ctx.out.n_actions, &payload);
}
exit:
return eth_addr_to_uint64(ea);
}
\f
+static void
+ofproto_unixctl_list(struct unixctl_conn *conn, const char *arg OVS_UNUSED,
+ void *aux OVS_UNUSED)
+{
+ const struct shash_node *node;
+ struct ds results;
+
+ ds_init(&results);
+ SHASH_FOR_EACH (node, &all_ofprotos) {
+ ds_put_format(&results, "%s\n", node->name);
+ }
+ unixctl_command_reply(conn, 200, ds_cstr(&results));
+ ds_destroy(&results);
+}
+
+struct ofproto_trace {
+ struct action_xlate_ctx ctx;
+ struct flow flow;
+ struct ds *result;
+};
+
+static void
+trace_format_rule(struct ds *result, int level, const struct rule *rule)
+{
+ ds_put_char_multiple(result, '\t', level);
+ if (!rule) {
+ ds_put_cstr(result, "No match\n");
+ return;
+ }
+
+ ds_put_format(result, "Rule: cookie=%#"PRIx64" ",
+ ntohll(rule->flow_cookie));
+ cls_rule_format(&rule->cr, result);
+ ds_put_char(result, '\n');
+
+ ds_put_char_multiple(result, '\t', level);
+ ds_put_cstr(result, "OpenFlow ");
+ ofp_print_actions(result, (const struct ofp_action_header *) rule->actions,
+ rule->n_actions * sizeof *rule->actions);
+ ds_put_char(result, '\n');
+}
+
+static void
+trace_format_flow(struct ds *result, int level, const char *title,
+ struct ofproto_trace *trace)
+{
+ ds_put_char_multiple(result, '\t', level);
+ ds_put_format(result, "%s: ", title);
+ if (flow_equal(&trace->ctx.flow, &trace->flow)) {
+ ds_put_cstr(result, "unchanged");
+ } else {
+ flow_format(result, &trace->ctx.flow);
+ trace->flow = trace->ctx.flow;
+ }
+ ds_put_char(result, '\n');
+}
+
+static void
+trace_resubmit(struct action_xlate_ctx *ctx, const struct rule *rule)
+{
+ struct ofproto_trace *trace = CONTAINER_OF(ctx, struct ofproto_trace, ctx);
+ struct ds *result = trace->result;
+
+ ds_put_char(result, '\n');
+ trace_format_flow(result, ctx->recurse + 1, "Resubmitted flow", trace);
+ trace_format_rule(result, ctx->recurse + 1, rule);
+}
+
+static void
+ofproto_unixctl_trace(struct unixctl_conn *conn, const char *args_,
+ void *aux OVS_UNUSED)
+{
+ char *dpname, *in_port_s, *tun_id_s, *packet_s;
+ char *args = xstrdup(args_);
+ char *save_ptr = NULL;
+ struct ofproto *ofproto;
+ struct ofpbuf packet;
+ struct rule *rule;
+ struct ds result;
+ struct flow flow;
+ uint16_t in_port;
+ ovs_be32 tun_id;
+ char *s;
+
+ ofpbuf_init(&packet, strlen(args) / 2);
+ ds_init(&result);
+
+ dpname = strtok_r(args, " ", &save_ptr);
+ tun_id_s = strtok_r(NULL, " ", &save_ptr);
+ in_port_s = strtok_r(NULL, " ", &save_ptr);
+ packet_s = strtok_r(NULL, "", &save_ptr); /* Get entire rest of line. */
+ if (!dpname || !in_port_s || !packet_s) {
+ unixctl_command_reply(conn, 501, "Bad command syntax");
+ goto exit;
+ }
+
+ ofproto = shash_find_data(&all_ofprotos, dpname);
+ if (!ofproto) {
+ unixctl_command_reply(conn, 501, "Unknown ofproto (use ofproto/list "
+ "for help)");
+ goto exit;
+ }
+
+ tun_id = ntohl(strtoul(tun_id_s, NULL, 10));
+ in_port = ofp_port_to_odp_port(atoi(in_port_s));
+
+ packet_s = ofpbuf_put_hex(&packet, packet_s, NULL);
+ packet_s += strspn(packet_s, " ");
+ if (*packet_s != '\0') {
+ unixctl_command_reply(conn, 501, "Trailing garbage in command");
+ goto exit;
+ }
+ if (packet.size < ETH_HEADER_LEN) {
+ unixctl_command_reply(conn, 501, "Packet data too short for Ethernet");
+ goto exit;
+ }
+
+ ds_put_cstr(&result, "Packet: ");
+ s = ofp_packet_to_string(packet.data, packet.size, packet.size);
+ ds_put_cstr(&result, s);
+ free(s);
+
+ flow_extract(&packet, tun_id, in_port, &flow);
+ ds_put_cstr(&result, "Flow: ");
+ flow_format(&result, &flow);
+ ds_put_char(&result, '\n');
+
+ rule = rule_lookup(ofproto, &flow);
+ trace_format_rule(&result, 0, rule);
+ if (rule) {
+ struct ofproto_trace trace;
+
+ trace.result = &result;
+ trace.flow = flow;
+ action_xlate_ctx_init(&trace.ctx, ofproto, &flow, &packet);
+ trace.ctx.resubmit_hook = trace_resubmit;
+ xlate_actions(&trace.ctx, rule->actions, rule->n_actions);
+
+ ds_put_char(&result, '\n');
+ trace_format_flow(&result, 0, "Final flow", &trace);
+ ds_put_cstr(&result, "Datapath actions: ");
+ format_odp_actions(&result,
+ trace.ctx.out.actions, trace.ctx.out.n_actions);
+ }
+
+ unixctl_command_reply(conn, 200, ds_cstr(&result));
+
+exit:
+ ds_destroy(&result);
+ ofpbuf_uninit(&packet);
+ free(args);
+}
+
+static void
+ofproto_unixctl_init(void)
+{
+ static bool registered;
+ if (registered) {
+ return;
+ }
+ registered = true;
+
+ unixctl_command_register("ofproto/list", ofproto_unixctl_list, NULL);
+ unixctl_command_register("ofproto/trace", ofproto_unixctl_trace, NULL);
+}
+\f
static bool
default_normal_ofhook_cb(const struct flow *flow, const struct ofpbuf *packet,
struct odp_actions *actions, tag_type *tags,