const struct nlattr *key,
size_t key_len, ovs_be16 initial_tci);
static struct subfacet *subfacet_find(struct ofproto_dpif *,
- const struct nlattr *key, size_t key_len,
- const struct flow *);
+ const struct nlattr *key, size_t key_len);
static void subfacet_destroy(struct ofproto_dpif *, struct subfacet *);
static void subfacet_destroy__(struct ofproto_dpif *, struct subfacet *);
static void subfacet_reset_dp_stats(struct subfacet *,
struct list completions;
bool has_bundle_action; /* True when the first bundle action appears. */
+ struct netdev_stats stats; /* To account packets generated and consumed in
+ * userspace. */
/* Spanning tree. */
struct stp *stp;
hmap_init(&ofproto->realdev_vid_map);
*n_tablesp = N_TABLES;
+ memset(&ofproto->stats, 0, sizeof ofproto->stats);
return 0;
}
port->vlandev_vid = 0;
if (ofproto->sflow) {
- dpif_sflow_add_port(ofproto->sflow, port->odp_port,
- netdev_get_name(port->up.netdev));
+ dpif_sflow_add_port(ofproto->sflow, port_);
}
return 0;
ds = ofproto->sflow = dpif_sflow_create(ofproto->dpif);
HMAP_FOR_EACH (ofport, up.hmap_node, &ofproto->up.ports) {
- dpif_sflow_add_port(ds, ofport->odp_port,
- netdev_get_name(ofport->up.netdev));
+ dpif_sflow_add_port(ds, &ofport->up);
}
ofproto->need_revalidate = true;
}
return error;
}
+static int
+port_get_stats(const struct ofport *ofport_, struct netdev_stats *stats)
+{
+ struct ofport_dpif *ofport = ofport_dpif_cast(ofport_);
+ int error;
+
+ error = netdev_get_stats(ofport->up.netdev, stats);
+
+ if (!error && ofport->odp_port == OVSP_LOCAL) {
+ struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofport->up.ofproto);
+
+ /* ofproto->stats.tx_packets represents packets that we created
+ * internally and sent to some port (e.g. packets sent with
+ * send_packet()). Account for them as if they had come from
+ * OFPP_LOCAL and got forwarded. */
+
+ if (stats->rx_packets != UINT64_MAX) {
+ stats->rx_packets += ofproto->stats.tx_packets;
+ }
+
+ if (stats->rx_bytes != UINT64_MAX) {
+ stats->rx_bytes += ofproto->stats.tx_bytes;
+ }
+
+ /* ofproto->stats.rx_packets represents packets that were received on
+ * some port and we processed internally and dropped (e.g. STP).
+ * Account fro them as if they had been forwarded to OFPP_LOCAL. */
+
+ if (stats->tx_packets != UINT64_MAX) {
+ stats->tx_packets += ofproto->stats.rx_packets;
+ }
+
+ if (stats->tx_bytes != UINT64_MAX) {
+ stats->tx_bytes += ofproto->stats.rx_bytes;
+ }
+ }
+
+ return error;
+}
+
+/* Account packets for LOCAL port. */
+static void
+ofproto_update_local_port_stats(const struct ofproto *ofproto_,
+ size_t tx_size, size_t rx_size)
+{
+ struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
+
+ if (rx_size) {
+ ofproto->stats.rx_packets++;
+ ofproto->stats.rx_bytes += rx_size;
+ }
+ if (tx_size) {
+ ofproto->stats.tx_packets++;
+ ofproto->stats.tx_bytes += tx_size;
+ }
+}
+
struct port_dump_state {
struct dpif_port_dump dump;
bool done;
/* Handle 802.1ag, LACP, and STP specially. */
if (process_special(ofproto, &flow, upcall->packet)) {
+ ofproto_update_local_port_stats(&ofproto->up,
+ 0, upcall->packet->size);
ofpbuf_delete(upcall->packet);
ofproto->n_matches++;
continue;
dpif_flow_dump_start(&dump, p->dpif);
while (dpif_flow_dump_next(&dump, &key, &key_len, NULL, NULL, &stats)) {
- enum odp_key_fitness fitness;
struct subfacet *subfacet;
- struct flow flow;
-
- fitness = odp_flow_key_to_flow(key, key_len, &flow);
- if (fitness == ODP_FIT_ERROR) {
- continue;
- }
- subfacet = subfacet_find(p, key, key_len, &flow);
+ subfacet = subfacet_find(p, key, key_len);
if (subfacet && subfacet->installed) {
struct facet *facet = subfacet->facet;
facet_account(p, facet);
facet_push_stats(facet);
} else {
+ if (!VLOG_DROP_WARN(&rl)) {
+ struct ds s;
+
+ ds_init(&s);
+ odp_flow_key_format(key, key_len, &s);
+ VLOG_WARN("unexpected flow from datapath %s", ds_cstr(&s));
+ ds_destroy(&s);
+ }
+
+ COVERAGE_INC(facet_unexpected);
/* There's a flow in the datapath that we know nothing about, or a
* flow that shouldn't be installed but was anyway. Delete it. */
- COVERAGE_INC(facet_unexpected);
dpif_flow_del(p->dpif, key, key_len, NULL);
}
}
* 'flow'. Returns the subfacet if one exists, otherwise NULL. */
static struct subfacet *
subfacet_find(struct ofproto_dpif *ofproto,
- const struct nlattr *key, size_t key_len,
- const struct flow *flow)
+ const struct nlattr *key, size_t key_len)
{
uint32_t key_hash = odp_flow_key_hash(key, key_len);
+ enum odp_key_fitness fitness;
+ struct flow flow;
+
+ fitness = odp_flow_key_to_flow(key, key_len, &flow);
+ if (fitness == ODP_FIT_ERROR) {
+ return NULL;
+ }
- return subfacet_find__(ofproto, key, key_len, key_hash, flow);
+ return subfacet_find__(ofproto, key, key_len, key_hash, &flow);
}
/* Uninstalls 'subfacet' from the datapath, if it is installed, removes it from
VLOG_WARN_RL(&rl, "%s: failed to send packet on port %"PRIu32" (%s)",
ofproto->up.name, odp_port, strerror(error));
}
+ ofproto_update_local_port_stats(ofport->up.ofproto, packet->size, 0);
return error;
}
\f
port_query_by_name,
port_add,
port_del,
+ port_get_stats,
port_dump_start,
port_dump_next,
port_dump_done,