/*
- * Copyright (c) 2009, 2010 Nicira Networks.
+ * Copyright (c) 2009, 2010, 2011 Nicira Networks.
* Copyright (c) 2010 Jean Tourrilhes - HP-Labs.
*
* Licensed under the Apache License, Version 2.0 (the "License");
return !hmap_is_empty(&p->controllers);
}
+void
+ofproto_get_ofproto_controller_info(const struct ofproto * ofproto,
+ struct shash *info)
+{
+ const struct ofconn *ofconn;
+
+ shash_init(info);
+
+ HMAP_FOR_EACH (ofconn, hmap_node, &ofproto->controllers) {
+ const struct rconn *rconn = ofconn->rconn;
+ const int last_error = rconn_get_last_error(rconn);
+ struct ofproto_controller_info *cinfo = xmalloc(sizeof *cinfo);
+
+ shash_add(info, rconn_get_target(rconn), cinfo);
+
+ cinfo->is_connected = rconn_is_connected(rconn);
+ cinfo->role = ofconn->role;
+
+ cinfo->pairs.n = 0;
+
+ if (last_error == EOF) {
+ cinfo->pairs.keys[cinfo->pairs.n] = "last_error";
+ cinfo->pairs.values[cinfo->pairs.n++] = xstrdup("End of file");
+ } else if (last_error > 0) {
+ cinfo->pairs.keys[cinfo->pairs.n] = "last_error";
+ cinfo->pairs.values[cinfo->pairs.n++] =
+ xstrdup(strerror(last_error));
+ }
+
+ cinfo->pairs.keys[cinfo->pairs.n] = "state";
+ cinfo->pairs.values[cinfo->pairs.n++] =
+ xstrdup(rconn_get_state(rconn));
+
+ cinfo->pairs.keys[cinfo->pairs.n] = "time_in_state";
+ cinfo->pairs.values[cinfo->pairs.n++] =
+ xasprintf("%u", rconn_get_state_elapsed(rconn));
+ }
+}
+
+void
+ofproto_free_ofproto_controller_info(struct shash *info)
+{
+ struct shash_node *node;
+
+ SHASH_FOR_EACH (node, info) {
+ struct ofproto_controller_info *cinfo = node->data;
+ while (cinfo->pairs.n) {
+ free((char *) cinfo->pairs.values[--cinfo->pairs.n]);
+ }
+ free(cinfo);
+ }
+ shash_destroy(info);
+}
+
/* Deletes port number 'odp_port' from the datapath for 'ofproto'.
*
* This is almost the same as calling dpif_port_del() directly on the
static void
reinit_ports(struct ofproto *p)
{
- struct svec devnames;
+ struct shash_node *node;
+ struct shash devnames;
struct ofport *ofport;
struct odp_port *odp_ports;
size_t n_odp_ports;
COVERAGE_INC(ofproto_reinit_ports);
- svec_init(&devnames);
+ shash_init(&devnames);
HMAP_FOR_EACH (ofport, hmap_node, &p->ports) {
- svec_add (&devnames, ofport->opp.name);
+ shash_add_once (&devnames, ofport->opp.name, NULL);
}
dpif_port_list(p->dpif, &odp_ports, &n_odp_ports);
for (i = 0; i < n_odp_ports; i++) {
- svec_add (&devnames, odp_ports[i].devname);
+ shash_add_once (&devnames, odp_ports[i].devname, NULL);
}
free(odp_ports);
- svec_sort_unique(&devnames);
- for (i = 0; i < devnames.n; i++) {
- update_port(p, devnames.names[i]);
+ SHASH_FOR_EACH (node, &devnames) {
+ update_port(p, node->name);
}
- svec_destroy(&devnames);
+ shash_destroy(&devnames);
}
static struct ofport *
send_error_oh(const struct ofconn *ofconn, const struct ofp_header *oh,
int error)
{
- struct ofpbuf *buf = make_ofp_error_msg(error, oh);
+ struct ofpbuf *buf = ofputil_encode_error_msg(error, oh);
if (buf) {
COVERAGE_INC(ofproto_error);
queue_tx(buf, ofconn, ofconn->reply_counter);
/* Maximum depth of flow table recursion (due to NXAST_RESUBMIT actions) in a
* flow translation. */
-#define MAX_RESUBMIT_RECURSION 8
+#define MAX_RESUBMIT_RECURSION 16
static void do_xlate_actions(const union ofp_action *in, size_t n_in,
struct action_xlate_ctx *ctx);
ctx->recurse--;
}
} else {
- struct vlog_rate_limit recurse_rl = VLOG_RATE_LIMIT_INIT(1, 1);
+ static struct vlog_rate_limit recurse_rl = VLOG_RATE_LIMIT_INIT(1, 1);
VLOG_ERR_RL(&recurse_rl, "NXAST_RESUBMIT recursed over %d times",
MAX_RESUBMIT_RECURSION);
}
}
+struct xlate_reg_state {
+ ovs_be16 vlan_tci;
+ ovs_be64 tun_id;
+};
+
static void
-xlate_reg_move_action(struct action_xlate_ctx *ctx,
- const struct nx_action_reg_move *narm)
+save_reg_state(const struct action_xlate_ctx *ctx,
+ struct xlate_reg_state *state)
{
- ovs_be16 old_tci = ctx->flow.vlan_tci;
-
- nxm_execute_reg_move(narm, &ctx->flow);
+ state->vlan_tci = ctx->flow.vlan_tci;
+ state->tun_id = ctx->flow.tun_id;
+}
- if (ctx->flow.vlan_tci != old_tci) {
+static void
+update_reg_state(struct action_xlate_ctx *ctx,
+ const struct xlate_reg_state *state)
+{
+ if (ctx->flow.vlan_tci != state->vlan_tci) {
xlate_set_dl_tci(ctx);
}
+ if (ctx->flow.tun_id != state->tun_id) {
+ nl_msg_put_be64(ctx->odp_actions, ODPAT_SET_TUNNEL, ctx->flow.tun_id);
+ }
}
static void
const struct nx_action_set_queue *nasq;
const struct nx_action_multipath *nam;
enum nx_action_subtype subtype = ntohs(nah->subtype);
+ struct xlate_reg_state state;
ovs_be64 tun_id;
assert(nah->vendor == htonl(NX_VENDOR_ID));
break;
case NXAST_REG_MOVE:
- xlate_reg_move_action(ctx, (const struct nx_action_reg_move *) nah);
+ save_reg_state(ctx, &state);
+ nxm_execute_reg_move((const struct nx_action_reg_move *) nah,
+ &ctx->flow);
+ update_reg_state(ctx, &state);
break;
case NXAST_REG_LOAD:
+ save_reg_state(ctx, &state);
nxm_execute_reg_load((const struct nx_action_reg_load *) nah,
&ctx->flow);
+ update_reg_state(ctx, &state);
+ break;
case NXAST_NOTE:
/* Nothing to do. */
act_len = sizeof *rule->actions * rule->n_actions;
- start_len = (*replyp)->size;
append_nxstats_reply(sizeof *nfs + NXM_MAX_LEN + act_len, ofconn, replyp);
+ start_len = (*replyp)->size;
reply = *replyp;
nfs = ofpbuf_put_uninit(reply, sizeof *nfs);
static void
ofproto_update_used(struct ofproto *p)
{
- struct odp_flow *flows;
- size_t n_flows;
- size_t i;
- int error;
+ struct dpif_flow_dump dump;
+ struct odp_flow f;
- error = dpif_flow_list_all(p->dpif, &flows, &n_flows);
- if (error) {
- return;
- }
+ memset(&f, 0, sizeof f);
- for (i = 0; i < n_flows; i++) {
- struct odp_flow *f = &flows[i];
+ dpif_flow_dump_start(&dump, p->dpif);
+ while (dpif_flow_dump_next(&dump, &f)) {
struct facet *facet;
struct flow flow;
- odp_flow_key_to_flow(&f->key, &flow);
+ odp_flow_key_to_flow(&f.key, &flow);
facet = facet_find(p, &flow);
if (facet && facet->installed) {
- facet_update_time(p, facet, &f->stats);
- facet_account(p, facet, f->stats.n_bytes);
+ facet_update_time(p, facet, &f.stats);
+ facet_account(p, facet, f.stats.n_bytes);
} else {
/* There's a flow in the datapath that we know nothing about.
* Delete it. */
COVERAGE_INC(ofproto_unexpected_rule);
- dpif_flow_del(p->dpif, f);
+ dpif_flow_del(p->dpif, &f);
}
-
}
- free(flows);
+ dpif_flow_dump_done(&dump);
}
/* Calculates and returns the number of milliseconds of idle time after which
struct ds result;
struct flow flow;
uint16_t in_port;
- ovs_be32 tun_id;
+ ovs_be64 tun_id;
char *s;
ofpbuf_init(&packet, strlen(args) / 2);
goto exit;
}
- tun_id = ntohl(strtoul(tun_id_s, NULL, 10));
+ tun_id = htonll(strtoull(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);