/*
- * Copyright (c) 2009, 2010, 2011 Nicira Networks.
+ * Copyright (c) 2009, 2010, 2011, 2012 Nicira Networks.
* Copyright (c) 2010 Jean Tourrilhes - HP-Labs.
*
* Licensed under the Apache License, Version 2.0 (the "License");
\f
/* Registers a mirror associated with client data pointer 'aux' in 'ofproto'.
* If 'aux' is already registered then this function updates its configuration
- * to 's'. Otherwise, this function registers a new mirror.
- *
- * Mirrors affect only the treatment of packets output to the OFPP_NORMAL
- * port. */
+ * to 's'. Otherwise, this function registers a new mirror. */
int
ofproto_mirror_register(struct ofproto *ofproto, void *aux,
const struct ofproto_mirror_settings *s)
return ofproto_mirror_register(ofproto, aux, NULL);
}
+/* Retrieves statistics from mirror associated with client data pointer
+ * 'aux' in 'ofproto'. Stores packet and byte counts in 'packets' and
+ * 'bytes', respectively. If a particular counters is not supported,
+ * the appropriate argument is set to UINT64_MAX. */
+int
+ofproto_mirror_get_stats(struct ofproto *ofproto, void *aux,
+ uint64_t *packets, uint64_t *bytes)
+{
+ if (!ofproto->ofproto_class->mirror_get_stats) {
+ *packets = *bytes = UINT64_MAX;
+ return EOPNOTSUPP;
+ }
+
+ return ofproto->ofproto_class->mirror_get_stats(ofproto, aux,
+ packets, bytes);
+}
+
/* Configures the VLANs whose bits are set to 1 in 'flood_vlans' as VLANs on
* which all packets are flooded, instead of using MAC learning. If
* 'flood_vlans' is NULL, then MAC learning applies to all VLANs.
int error;
error = p->ofproto_class->run(p);
- if (error == ENODEV) {
- /* Someone destroyed the datapath behind our back. The caller
- * better destroy us and give up, because we're just going to
- * spin from here on out. */
- static struct vlog_rate_limit rl2 = VLOG_RATE_LIMIT_INIT(1, 5);
- VLOG_ERR_RL(&rl2, "%s: datapath was destroyed externally",
- p->name);
- return ENODEV;
+ if (error && error != EAGAIN) {
+ VLOG_ERR_RL(&rl, "%s: run failed (%s)", p->name, strerror(error));
}
if (p->ofproto_class->port_poll) {
NOT_REACHED();
}
- return 0;
+ return error;
+}
+
+/* Performs periodic activity required by 'ofproto' that needs to be done
+ * with the least possible latency.
+ *
+ * It makes sense to call this function a couple of times per poll loop, to
+ * provide a significant performance boost on some benchmarks with the
+ * ofproto-dpif implementation. */
+int
+ofproto_run_fast(struct ofproto *p)
+{
+ int error;
+
+ error = p->ofproto_class->run_fast ? p->ofproto_class->run_fast(p) : 0;
+ if (error && error != EAGAIN) {
+ VLOG_ERR_RL(&rl, "%s: fastpath run failed (%s)",
+ p->name, strerror(error));
+ }
+ return error;
}
void
return NULL;
}
+int
+ofproto_port_get_stats(const struct ofport *port, struct netdev_stats *stats)
+{
+ struct ofproto *ofproto = port->ofproto;
+ int error;
+
+ if (ofproto->ofproto_class->port_get_stats) {
+ error = ofproto->ofproto_class->port_get_stats(port, stats);
+ } else {
+ error = EOPNOTSUPP;
+ }
+
+ return error;
+}
+
static void
update_port(struct ofproto *ofproto, const char *name)
{
/* Intentionally ignore return value, since errors will set
* 'stats' to all-1s, which is correct for OpenFlow, and
* netdev_get_stats() will log errors. */
- netdev_get_stats(port->netdev, &stats);
+ ofproto_port_get_stats(port, &stats);
ops = ofputil_append_stats_reply(sizeof *ops, replies);
ops->port_no = port->opp.port_no;
* Returns 0 on success, otherwise an OpenFlow error code. */
static int
collect_rules_loose(struct ofproto *ofproto, uint8_t table_id,
- const struct cls_rule *match, uint16_t out_port,
- struct list *rules)
+ const struct cls_rule *match,
+ ovs_be64 cookie, ovs_be64 cookie_mask,
+ uint16_t out_port, struct list *rules)
{
struct classifier *cls;
int error;
if (rule->pending) {
return OFPROTO_POSTPONE;
}
- if (!rule_is_hidden(rule) && rule_has_out_port(rule, out_port)) {
+ if (!rule_is_hidden(rule) && rule_has_out_port(rule, out_port)
+ && !((rule->flow_cookie ^ cookie) & cookie_mask)) {
list_push_back(rules, &rule->ofproto_node);
}
}
* Returns 0 on success, otherwise an OpenFlow error code. */
static int
collect_rules_strict(struct ofproto *ofproto, uint8_t table_id,
- const struct cls_rule *match, uint16_t out_port,
- struct list *rules)
+ const struct cls_rule *match,
+ ovs_be64 cookie, ovs_be64 cookie_mask,
+ uint16_t out_port, struct list *rules)
{
struct classifier *cls;
int error;
if (rule->pending) {
return OFPROTO_POSTPONE;
}
- if (!rule_is_hidden(rule) && rule_has_out_port(rule, out_port)) {
+ if (!rule_is_hidden(rule) && rule_has_out_port(rule, out_port)
+ && !((rule->flow_cookie ^ cookie) & cookie_mask)) {
list_push_back(rules, &rule->ofproto_node);
}
}
}
error = collect_rules_loose(ofproto, fsr.table_id, &fsr.match,
+ fsr.cookie, fsr.cookie_mask,
fsr.out_port, &rules);
if (error) {
return error;
}
error = collect_rules_loose(ofproto, request.table_id, &request.match,
+ request.cookie, request.cookie_mask,
request.out_port, &rules);
if (error) {
return error;
struct list rules;
int error;
- error = collect_rules_loose(ofproto, fm->table_id, &fm->cr, OFPP_NONE,
- &rules);
+ error = collect_rules_loose(ofproto, fm->table_id, &fm->cr,
+ fm->cookie, fm->cookie_mask,
+ OFPP_NONE, &rules);
return (error ? error
: list_is_empty(&rules) ? add_flow(ofproto, ofconn, fm, request)
: modify_flows__(ofproto, ofconn, fm, request, &rules));
struct list rules;
int error;
- error = collect_rules_strict(ofproto, fm->table_id, &fm->cr, OFPP_NONE,
- &rules);
+ error = collect_rules_strict(ofproto, fm->table_id, &fm->cr,
+ fm->cookie, fm->cookie_mask,
+ OFPP_NONE, &rules);
return (error ? error
: list_is_empty(&rules) ? add_flow(ofproto, ofconn, fm, request)
: list_is_singleton(&rules) ? modify_flows__(ofproto, ofconn,
struct list rules;
int error;
- error = collect_rules_loose(ofproto, fm->table_id, &fm->cr, fm->out_port,
- &rules);
+ error = collect_rules_loose(ofproto, fm->table_id, &fm->cr,
+ fm->cookie, fm->cookie_mask,
+ fm->out_port, &rules);
return (error ? error
: !list_is_empty(&rules) ? delete_flows__(ofproto, ofconn, request,
&rules)
struct list rules;
int error;
- error = collect_rules_strict(ofproto, fm->table_id, &fm->cr, fm->out_port,
- &rules);
+ error = collect_rules_strict(ofproto, fm->table_id, &fm->cr,
+ fm->cookie, fm->cookie_mask,
+ fm->out_port, &rules);
return (error ? error
: list_is_singleton(&rules) ? delete_flows__(ofproto, ofconn,
request, &rules)
handle_nxt_flow_mod_table_id(struct ofconn *ofconn,
const struct ofp_header *oh)
{
- const struct nxt_flow_mod_table_id *msg
- = (const struct nxt_flow_mod_table_id *) oh;
+ const struct nx_flow_mod_table_id *msg
+ = (const struct nx_flow_mod_table_id *) oh;
ofconn_set_flow_mod_table_id(ofconn, msg->set != 0);
return 0;
static int
handle_nxt_set_flow_format(struct ofconn *ofconn, const struct ofp_header *oh)
{
- const struct nxt_set_flow_format *msg
- = (const struct nxt_set_flow_format *) oh;
+ const struct nx_set_flow_format *msg
+ = (const struct nx_set_flow_format *) oh;
uint32_t format;
format = ntohl(msg->format);
return 0;
}
+static int
+handle_nxt_set_packet_in_format(struct ofconn *ofconn,
+ const struct ofp_header *oh)
+{
+ const struct nx_set_packet_in_format *msg;
+ uint32_t format;
+
+ msg = (const struct nx_set_packet_in_format *) oh;
+ format = ntohl(msg->format);
+ if (format != NXFF_OPENFLOW10 && format != NXPIF_NXM) {
+ return ofp_mkerr(OFPET_BAD_REQUEST, OFPBRC_EPERM);
+ }
+
+ if (format != ofconn_get_packet_in_format(ofconn)
+ && ofconn_has_pending_opgroups(ofconn)) {
+ /* Avoid sending async message in surprsing packet in format. */
+ return OFPROTO_POSTPONE;
+ }
+
+ ofconn_set_packet_in_format(ofconn, format);
+ return 0;
+}
+
static int
handle_barrier_request(struct ofconn *ofconn, const struct ofp_header *oh)
{
case OFPUTIL_NXT_SET_FLOW_FORMAT:
return handle_nxt_set_flow_format(ofconn, oh);
+ case OFPUTIL_NXT_SET_PACKET_IN_FORMAT:
+ return handle_nxt_set_packet_in_format(ofconn, oh);
+
case OFPUTIL_NXT_FLOW_MOD:
return handle_flow_mod(ofconn, oh);
case OFPUTIL_OFPST_AGGREGATE_REPLY:
case OFPUTIL_NXT_ROLE_REPLY:
case OFPUTIL_NXT_FLOW_REMOVED:
+ case OFPUTIL_NXT_PACKET_IN:
case OFPUTIL_NXST_FLOW_REPLY:
case OFPUTIL_NXST_AGGREGATE_REPLY:
default:
if (op->victim) {
ofproto_rule_destroy__(op->victim);
}
- if (!(rule->cr.wc.vlan_tci_mask & htons(VLAN_VID_MASK))
- && ofproto->vlan_bitmap) {
- uint16_t vid = vlan_tci_to_vid(rule->cr.flow.vlan_tci);
-
- if (!bitmap_is_set(ofproto->vlan_bitmap, vid)) {
- bitmap_set1(ofproto->vlan_bitmap, vid);
+ if ((rule->cr.wc.vlan_tci_mask & htons(VLAN_VID_MASK))
+ == htons(VLAN_VID_MASK)) {
+ if (ofproto->vlan_bitmap) {
+ uint16_t vid = vlan_tci_to_vid(rule->cr.flow.vlan_tci);
+
+ if (!bitmap_is_set(ofproto->vlan_bitmap, vid)) {
+ bitmap_set1(ofproto->vlan_bitmap, vid);
+ ofproto->vlans_changed = true;
+ }
+ } else {
ofproto->vlans_changed = true;
}
}
}
static void
-ofproto_unixctl_list(struct unixctl_conn *conn, const char *arg OVS_UNUSED,
- void *aux OVS_UNUSED)
+ofproto_unixctl_list(struct unixctl_conn *conn, int argc OVS_UNUSED,
+ const char *argv[] OVS_UNUSED, void *aux OVS_UNUSED)
{
struct ofproto *ofproto;
struct ds results;
}
registered = true;
- unixctl_command_register("ofproto/list", "", ofproto_unixctl_list, NULL);
+ unixctl_command_register("ofproto/list", "", 0, 0,
+ ofproto_unixctl_list, NULL);
}
\f
/* Linux VLAN device support (e.g. "eth0.10" for VLAN 10.)
const struct cls_table *table;
HMAP_FOR_EACH (table, hmap_node, &cls->tables) {
- if (!(table->wc.vlan_tci_mask & htons(VLAN_VID_MASK))) {
+ if ((table->wc.vlan_tci_mask & htons(VLAN_VID_MASK))
+ == htons(VLAN_VID_MASK)) {
const struct cls_rule *rule;
HMAP_FOR_EACH (rule, hmap_node, &table->rules) {