}
}
+static bool
+any_pending_ops(const struct ofproto *p)
+{
+ return !list_is_empty(&p->pending);
+}
+
int
ofproto_run(struct ofproto *p)
{
case S_EVICT:
connmgr_run(p->connmgr, NULL);
ofproto_evict(p);
- if (list_is_empty(&p->pending) && hmap_is_empty(&p->deletions)) {
+ if (!any_pending_ops(p)) {
p->state = S_OPENFLOW;
}
break;
case S_FLUSH:
connmgr_run(p->connmgr, NULL);
ofproto_flush__(p);
- if (list_is_empty(&p->pending) && hmap_is_empty(&p->deletions)) {
+ if (!any_pending_ops(p)) {
connmgr_flushed(p->connmgr);
p->state = S_OPENFLOW;
}
case S_EVICT:
case S_FLUSH:
connmgr_wait(p->connmgr, false);
- if (list_is_empty(&p->pending) && hmap_is_empty(&p->deletions)) {
+ if (!any_pending_ops(p)) {
poll_immediate_wake();
}
break;
static void
ofproto_rule_destroy__(struct rule *rule)
{
- cls_rule_destroy(&rule->cr);
+ cls_rule_destroy(CONST_CAST(struct cls_rule *, &rule->cr));
rule_actions_unref(rule->actions);
ovs_mutex_destroy(&rule->mutex);
rule->ofproto->ofproto_class->rule_dealloc(rule);
return false;
}
-static enum ofperr
-evict_rule_from_table(struct ofproto *ofproto, struct oftable *table)
+static bool
+should_evict_a_rule(struct oftable *table, unsigned int extra_space)
{
- struct rule *rule;
- size_t n_rules;
+ size_t count;
ovs_rwlock_rdlock(&table->cls.rwlock);
- n_rules = classifier_count(&table->cls);
+ count = classifier_count(&table->cls);
ovs_rwlock_unlock(&table->cls.rwlock);
- if (n_rules < table->max_flows) {
- return 0;
- } else if (!choose_rule_to_evict(table, &rule)) {
- return OFPERR_OFPFMFC_TABLE_FULL;
- } else if (rule->pending) {
- ovs_mutex_unlock(&rule->mutex);
- return OFPROTO_POSTPONE;
- } else {
- struct ofopgroup *group;
+ return count + extra_space > table->max_flows;
+}
- group = ofopgroup_create_unattached(ofproto);
- delete_flow__(rule, group, OFPRR_EVICTION);
- ofopgroup_submit(group);
+static enum ofperr
+evict_rules_from_table(struct ofproto *ofproto, struct oftable *table,
+ unsigned int extra_space)
+{
+ while (should_evict_a_rule(table, extra_space)) {
+ struct rule *rule;
- return 0;
+ if (!choose_rule_to_evict(table, &rule)) {
+ return OFPERR_OFPFMFC_TABLE_FULL;
+ } else if (rule->pending) {
+ ovs_mutex_unlock(&rule->mutex);
+ return OFPROTO_POSTPONE;
+ } else {
+ struct ofopgroup *group = ofopgroup_create_unattached(ofproto);
+ ofoperation_create(group, rule,
+ OFOPERATION_DELETE, OFPRR_EVICTION);
+ oftable_remove_rule(rule);
+ ofproto->ofproto_class->rule_delete(rule);
+ }
}
+
+ return 0;
}
/* Implements OFPFC_ADD and the cases for OFPFC_MODIFY and OFPFC_MODIFY_STRICT
}
/* If necessary, evict an existing rule to clear out space. */
- error = evict_rule_from_table(ofproto, table);
+ error = evict_rules_from_table(ofproto, table, 1);
if (error) {
cls_rule_destroy(&cr);
return error;
}
/* Initialize base state. */
- rule->ofproto = ofproto;
- cls_rule_move(&rule->cr, &cr);
+ *CONST_CAST(struct ofproto **, &rule->ofproto) = ofproto;
+ cls_rule_move(CONST_CAST(struct cls_rule *, &rule->cr), &cr);
atomic_init(&rule->ref_count, 1);
rule->pending = NULL;
rule->flow_cookie = fm->new_cookie;
rule->hard_timeout = fm->hard_timeout;
ovs_mutex_unlock(&rule->mutex);
- rule->table_id = table - ofproto->tables;
+ *CONST_CAST(uint8_t *, &rule->table_id) = table - ofproto->tables;
rule->flags = fm->flags & OFPUTIL_FF_STATE;
rule->actions = rule_actions_create(fm->ofpacts, fm->ofpacts_len);
list_init(&rule->meter_list_node);
static void
ofproto_evict(struct ofproto *ofproto)
{
- struct ofopgroup *group;
struct oftable *table;
- group = ofopgroup_create_unattached(ofproto);
OFPROTO_FOR_EACH_TABLE (table, ofproto) {
- while (table->eviction_fields) {
- struct rule *rule;
- size_t n_rules;
-
- ovs_rwlock_rdlock(&table->cls.rwlock);
- n_rules = classifier_count(&table->cls);
- ovs_rwlock_unlock(&table->cls.rwlock);
-
- if (n_rules <= table->max_flows) {
- break;
- }
-
- if (!choose_rule_to_evict(table, &rule)) {
- break;
- }
-
- if (rule->pending) {
- ovs_mutex_unlock(&rule->mutex);
- break;
- }
-
- ofoperation_create(group, rule,
- OFOPERATION_DELETE, OFPRR_EVICTION);
- oftable_remove_rule(rule);
- ofproto->ofproto_class->rule_delete(rule);
- }
+ evict_rules_from_table(ofproto, table, 0);
}
- ofopgroup_submit(group);
}
\f
/* Eviction groups. */
struct rule *rule)
OVS_REQ_WRLOCK(cls->rwlock) OVS_RELEASES(rule->mutex)
{
- classifier_remove(cls, &rule->cr);
+ classifier_remove(cls, CONST_CAST(struct cls_rule *, &rule->cr));
ovs_mutex_lock(&ofproto_mutex);
cookies_remove(ofproto, rule);
list_insert(&meter->rules, &rule->meter_list_node);
}
ovs_rwlock_wrlock(&table->cls.rwlock);
- classifier_insert(&table->cls, &rule->cr);
+ classifier_insert(&table->cls, CONST_CAST(struct cls_rule *, &rule->cr));
ovs_rwlock_unlock(&table->cls.rwlock);
eviction_group_add_rule(rule);
}