#include "openvswitch/ofpbuf.h"
#include "openvswitch/vconn.h"
#include "openvswitch/vlog.h"
+#include "ovs-atomic.h"
#include "pinsched.h"
#include "poll-loop.h"
#include "rconn.h"
enum ofconn_type type; /* Type. */
enum ofproto_band band; /* In-band or out-of-band? */
bool enable_async_msgs; /* Initially enable async messages? */
+ bool want_packet_in_on_miss;
/* State that should be cleared from one connection to the next. */
struct sockaddr_in *extra_in_band_remotes;
size_t n_extra_remotes;
int in_band_queue;
+
+ ATOMIC(int) want_packet_in_on_miss; /* Sum of ofconns' values. */
};
static void update_in_band_remotes(struct connmgr *);
mgr->n_extra_remotes = 0;
mgr->in_band_queue = -1;
+ atomic_init(&mgr->want_packet_in_on_miss, 0);
+
return mgr;
}
+/* The default "table-miss" behaviour for OpenFlow1.3+ is to drop the
+ * packet rather than to send the packet to the controller.
+ *
+ * This function maintains the count of pre-OpenFlow1.3 with controller_id 0,
+ * as we assume these are the controllers that should receive "table-miss"
+ * notifications. */
+static void
+update_want_packet_in_on_miss(struct ofconn *ofconn)
+{
+ /* We want a packet-in on miss when controller_id is zero and OpenFlow is
+ * lower than version 1.3. */
+ enum ofputil_protocol p = ofconn->protocol;
+ int new_want = (ofconn->controller_id == 0 &&
+ (p == OFPUTIL_P_NONE ||
+ ofputil_protocol_to_ofp_version(p) < OFP13_VERSION));
+
+ /* Update the setting and the count if necessary. */
+ int old_want = ofconn->want_packet_in_on_miss;
+ if (old_want != new_want) {
+ atomic_int *dst = &ofconn->connmgr->want_packet_in_on_miss;
+ int count;
+ atomic_read_relaxed(dst, &count);
+ atomic_store_relaxed(dst, count - old_want + new_want);
+
+ ofconn->want_packet_in_on_miss = new_want;
+ }
+}
+
/* Frees 'mgr' and all of its resources. */
void
connmgr_destroy(struct connmgr *mgr)
ofconn_set_protocol(struct ofconn *ofconn, enum ofputil_protocol protocol)
{
ofconn->protocol = protocol;
+ update_want_packet_in_on_miss(ofconn);
}
/* Returns the currently configured packet in format for 'ofconn', one of
ofconn_set_controller_id(struct ofconn *ofconn, uint16_t controller_id)
{
ofconn->controller_id = controller_id;
+ update_want_packet_in_on_miss(ofconn);
}
/* Returns the default miss send length for 'ofconn'. */
{
ofconn_flush(ofconn);
+ /* Force clearing of want_packet_in_on_miss to keep the global count
+ * accurate. */
+ ofconn->controller_id = 1;
+ update_want_packet_in_on_miss(ofconn);
+
if (ofconn->type == OFCONN_PRIMARY) {
hmap_remove(&ofconn->connmgr->controllers, &ofconn->hmap_node);
}
return (masks[type] & (1u << reason)) != 0;
}
-/* The default "table-miss" behaviour for OpenFlow1.3+ is to drop the
- * packet rather than to send the packet to the controller.
- *
- * This function returns true to indicate that a packet_in message
+/* This function returns true to indicate that a packet_in message
* for a "table-miss" should be sent to at least one controller.
- * That is there is at least one controller with controller_id 0
- * which connected using an OpenFlow version earlier than OpenFlow1.3.
- *
- * False otherwise.
*
- * This logic assumes that "table-miss" packet_in messages
- * are always sent to controller_id 0. */
+ * False otherwise. */
bool
-connmgr_wants_packet_in_on_miss(struct connmgr *mgr) OVS_EXCLUDED(ofproto_mutex)
+connmgr_wants_packet_in_on_miss(struct connmgr *mgr)
{
- struct ofconn *ofconn;
-
- ovs_mutex_lock(&ofproto_mutex);
- LIST_FOR_EACH (ofconn, node, &mgr->all_conns) {
- enum ofputil_protocol protocol = ofconn_get_protocol(ofconn);
+ int count;
- if (ofconn->controller_id == 0 &&
- (protocol == OFPUTIL_P_NONE ||
- ofputil_protocol_to_ofp_version(protocol) < OFP13_VERSION)) {
- ovs_mutex_unlock(&ofproto_mutex);
- return true;
- }
- }
- ovs_mutex_unlock(&ofproto_mutex);
-
- return false;
+ atomic_read_relaxed(&mgr->want_packet_in_on_miss, &count);
+ return count > 0;
}
/* Returns a human-readable name for an OpenFlow connection between 'mgr' and