#include <inttypes.h>
#include <stdbool.h>
#include <stdlib.h>
+#include <unistd.h>
#include "bitmap.h"
#include "byte-order.h"
#include "classifier.h"
static size_t allocated_ofproto_classes;
unsigned flow_eviction_threshold = OFPROTO_FLOW_EVICTION_THRESHOLD_DEFAULT;
+unsigned n_handler_threads;
enum ofproto_flow_miss_model flow_miss_model = OFPROTO_HANDLE_MISS_AUTO;
/* Map from datapath name to struct ofproto, for use by unixctl commands. */
hmap_init(&ofproto->ports);
shash_init(&ofproto->port_by_name);
simap_init(&ofproto->ofp_requests);
- ofproto->max_ports = OFPP_MAX;
+ ofproto->max_ports = ofp_to_u16(OFPP_MAX);
ofproto->tables = NULL;
ofproto->n_tables = 0;
hindex_init(&ofproto->cookies);
list_init(&ofproto->expirable);
- ovs_mutex_init(&ofproto->expirable_mutex, PTHREAD_MUTEX_RECURSIVE);
+ ovs_mutex_init_recursive(&ofproto->expirable_mutex);
ofproto->connmgr = connmgr_create(ofproto, datapath_name, datapath_name);
ofproto->state = S_OPENFLOW;
list_init(&ofproto->pending);
/* The "max_ports" member should have been set by ->construct(ofproto).
* Port 0 is not a valid OpenFlow port, so mark that as unavailable. */
- ofproto->ofp_port_ids = bitmap_allocate(ofp_to_u16(ofproto->max_ports));
+ ofproto->ofp_port_ids = bitmap_allocate(ofproto->max_ports);
bitmap_set1(ofproto->ofp_port_ids, 0);
/* Check that hidden tables, if any, are at the end. */
* Reserved ports numbered OFPP_MAX and higher are special and not subject to
* the 'max_ports' restriction. */
void
-ofproto_init_max_ports(struct ofproto *ofproto, ofp_port_t max_ports)
+ofproto_init_max_ports(struct ofproto *ofproto, uint16_t max_ports)
{
- ovs_assert(ofp_to_u16(max_ports) <= ofp_to_u16(OFPP_MAX));
+ ovs_assert(max_ports <= ofp_to_u16(OFPP_MAX));
ofproto->max_ports = max_ports;
}
}
}
+/* Sets number of upcall handler threads. The default is
+ * (number of online cores - 1). */
+void
+ofproto_set_n_handler_threads(unsigned limit)
+{
+ if (limit) {
+ n_handler_threads = limit;
+ } else {
+ n_handler_threads = MAX(1, sysconf(_SC_NPROCESSORS_ONLN) - 1);
+ }
+}
+
void
ofproto_set_dp_desc(struct ofproto *p, const char *dp_desc)
{
static ofp_port_t
alloc_ofp_port(struct ofproto *ofproto, const char *netdev_name)
{
- uint16_t max_ports = ofp_to_u16(ofproto->max_ports);
uint16_t port_idx;
port_idx = simap_get(&ofproto->ofp_requests, netdev_name);
- if (!port_idx) {
- port_idx = UINT16_MAX;
- }
+ port_idx = port_idx ? port_idx : UINT16_MAX;
- if (port_idx >= max_ports
+ if (port_idx >= ofproto->max_ports
|| bitmap_is_set(ofproto->ofp_port_ids, port_idx)) {
- uint16_t end_port_no = ofp_to_u16(ofproto->alloc_port_no);
- uint16_t alloc_port_no = end_port_no;
+ uint16_t end_port_no = ofproto->alloc_port_no;
/* Search for a free OpenFlow port number. We try not to
* immediately reuse them to prevent problems due to old
* flows. */
for (;;) {
- if (++alloc_port_no >= max_ports) {
- alloc_port_no = 0;
+ if (++ofproto->alloc_port_no >= ofproto->max_ports) {
+ ofproto->alloc_port_no = 0;
}
- if (!bitmap_is_set(ofproto->ofp_port_ids, alloc_port_no)) {
- port_idx = alloc_port_no;
- ofproto->alloc_port_no = u16_to_ofp(alloc_port_no);
+ if (!bitmap_is_set(ofproto->ofp_port_ids,
+ ofproto->alloc_port_no)) {
+ port_idx = ofproto->alloc_port_no;
break;
}
- if (alloc_port_no == end_port_no) {
+ if (ofproto->alloc_port_no == end_port_no) {
return OFPP_NONE;
}
}
static void
dealloc_ofp_port(const struct ofproto *ofproto, ofp_port_t ofp_port)
{
- if (ofp_to_u16(ofp_port) < ofp_to_u16(ofproto->max_ports)) {
+ if (ofp_to_u16(ofp_port) < ofproto->max_ports) {
bitmap_set0(ofproto->ofp_port_ids, ofp_to_u16(ofp_port));
}
}
netdev = ofport_open(p, &ofproto_port, &pp);
if (netdev) {
ofport_install(p, netdev, &pp);
+ if (ofp_to_u16(ofproto_port.ofp_port) < p->max_ports) {
+ p->alloc_port_no = MAX(p->alloc_port_no,
+ ofp_to_u16(ofproto_port.ofp_port));
+ }
}
}
}
enum ofperr error;
uint32_t mid;
- error = ofpacts_check(ofpacts, ofpacts_len, flow, ofproto->max_ports,
- table_id);
+ error = ofpacts_check(ofpacts, ofpacts_len, flow,
+ u16_to_ofp(ofproto->max_ports), table_id);
if (error) {
return error;
}
if (error) {
goto exit_free_ofpacts;
}
- if (ofp_to_u16(po.in_port) >= ofp_to_u16(p->max_ports)
+ if (ofp_to_u16(po.in_port) >= p->max_ports
&& ofp_to_u16(po.in_port) < ofp_to_u16(OFPP_MAX)) {
error = OFPERR_OFPBRC_BAD_PORT;
goto exit_free_ofpacts;
struct rule *victim;
struct rule *rule;
uint8_t table_id;
- bool overlaps;
int error;
error = check_table_id(ofproto, fm->table_id);
}
/* Check for overlap, if requested. */
- ovs_rwlock_rdlock(&table->cls.rwlock);
- overlaps = classifier_rule_overlaps(&table->cls, &rule->cr);
- ovs_rwlock_unlock(&table->cls.rwlock);
- if (fm->flags & OFPFF_CHECK_OVERLAP && overlaps) {
- cls_rule_destroy(&rule->cr);
- ofproto->ofproto_class->rule_dealloc(rule);
- return OFPERR_OFPFMFC_OVERLAP;
+ if (fm->flags & OFPFF_CHECK_OVERLAP) {
+ bool overlaps;
+
+ ovs_rwlock_rdlock(&table->cls.rwlock);
+ overlaps = classifier_rule_overlaps(&table->cls, &rule->cr);
+ ovs_rwlock_unlock(&table->cls.rwlock);
+
+ if (overlaps) {
+ cls_rule_destroy(&rule->cr);
+ ofproto->ofproto_class->rule_dealloc(rule);
+ return OFPERR_OFPFMFC_OVERLAP;
+ }
}
/* FIXME: Implement OFPFF12_RESET_COUNTS */
rule->flow_cookie = fm->new_cookie;
rule->created = rule->modified = rule->used = time_msec();
- ovs_mutex_init(&rule->timeout_mutex, OVS_MUTEX_ADAPTIVE);
+ ovs_mutex_init(&rule->timeout_mutex);
ovs_mutex_lock(&rule->timeout_mutex);
rule->idle_timeout = fm->idle_timeout;
rule->hard_timeout = fm->hard_timeout;
/* Verify actions. */
error = ofpacts_check(fm->ofpacts, fm->ofpacts_len, &fm->match.flow,
- ofproto->max_ports, rule->table_id);
+ u16_to_ofp(ofproto->max_ports), rule->table_id);
if (error) {
return error;
}
* group has no evictable rules.
*
* - The outer loop can exit only if table's 'max_flows' is all filled up
- * by unevictable rules'. */
+ * by unevictable rules. */
HEAP_FOR_EACH (evg, size_node, &table->eviction_groups_by_size) {
struct rule *rule;