#include <stdlib.h>
#include <string.h>
#include "crc32.h"
-#include "flow.h"
#include "datapath.h"
+#include "flow.h"
+#include "switch-flow.h"
struct sw_table_hash {
struct sw_table swt;
} else {
struct sw_flow *old_flow = *bucket;
if (!flow_compare(&old_flow->key.flow, &flow->key.flow)) {
+ /* Keep stats from the original flow */
+ flow->used = old_flow->used;
+ flow->created = old_flow->created;
+ flow->packet_count = old_flow->packet_count;
+ flow->byte_count = old_flow->byte_count;
+
*bucket = flow;
flow_free(old_flow);
retval = 1;
return retval;
}
+static int table_hash_modify(struct sw_table *swt,
+ const struct sw_flow_key *key,
+ const struct ofp_action *actions, int n_actions)
+{
+ struct sw_table_hash *th = (struct sw_table_hash *) swt;
+ unsigned int count = 0;
+
+ if (key->wildcards == 0) {
+ struct sw_flow **bucket = find_bucket(swt, key);
+ struct sw_flow *flow = *bucket;
+ if (flow && flow_matches_1wild(&flow->key, key)) {
+ flow_replace_acts(flow, actions, n_actions);
+ count = 1;
+ }
+ } else {
+ unsigned int i;
+
+ for (i = 0; i <= th->bucket_mask; i++) {
+ struct sw_flow **bucket = &th->buckets[i];
+ struct sw_flow *flow = *bucket;
+ if (flow && flow_matches_1wild(&flow->key, key)) {
+ flow_replace_acts(flow, actions, n_actions);
+ count++;
+ }
+ }
+ }
+ return count;
+}
+
/* Caller must update n_flows. */
static void
do_delete(struct sw_flow **bucket)
{
struct sw_table_hash *th = (struct sw_table_hash *) swt;
stats->name = "hash";
- stats->n_flows = th->n_flows;
+ stats->wildcards = 0; /* No wildcards are supported. */
+ stats->n_flows = th->n_flows;
stats->max_flows = th->bucket_mask + 1;
stats->n_matched = swt->n_matched;
}
th = malloc(sizeof *th);
if (th == NULL)
return NULL;
+ memset(th, '\0', sizeof *th);
assert(!(n_buckets & (n_buckets - 1)));
th->buckets = calloc(n_buckets, sizeof *th->buckets);
swt = &th->swt;
swt->lookup = table_hash_lookup;
swt->insert = table_hash_insert;
+ swt->modify = table_hash_modify;
swt->delete = table_hash_delete;
swt->timeout = table_hash_timeout;
swt->destroy = table_hash_destroy;
return table_hash_insert(t2->subtable[1], flow);
}
+static int table_hash2_modify(struct sw_table *swt,
+ const struct sw_flow_key *key,
+ const struct ofp_action *actions, int n_actions)
+{
+ struct sw_table_hash2 *t2 = (struct sw_table_hash2 *) swt;
+ return (table_hash_modify(t2->subtable[0], key, actions, n_actions)
+ + table_hash_modify(t2->subtable[1], key, actions, n_actions));
+}
+
static int table_hash2_delete(struct sw_table *swt,
const struct sw_flow_key *key,
uint16_t priority, int strict)
for (i = 0; i < 2; i++)
table_hash_stats(t2->subtable[i], &substats[i]);
stats->name = "hash2";
- stats->n_flows = substats[0].n_flows + substats[1].n_flows;
+ stats->wildcards = 0; /* No wildcards are supported. */
+ stats->n_flows = substats[0].n_flows + substats[1].n_flows;
stats->max_flows = substats[0].max_flows + substats[1].max_flows;
stats->n_matched = swt->n_matched;
}
t2 = malloc(sizeof *t2);
if (t2 == NULL)
return NULL;
+ memset(t2, '\0', sizeof *t2);
t2->subtable[0] = table_hash_create(poly0, buckets0);
if (t2->subtable[0] == NULL)
swt = &t2->swt;
swt->lookup = table_hash2_lookup;
swt->insert = table_hash2_insert;
+ swt->modify = table_hash2_modify;
swt->delete = table_hash2_delete;
swt->timeout = table_hash2_timeout;
swt->destroy = table_hash2_destroy;