summaryrefslogtreecommitdiff
path: root/tests/test-classifier.c
diff options
context:
space:
mode:
authorJarno Rajahalme <jrajahalme@nicira.com>2013-12-11 11:07:01 -0800
committerJarno Rajahalme <jrajahalme@nicira.com>2013-12-11 11:07:01 -0800
commit13751fd88c4b7464f9453c03659201c10b3b87a0 (patch)
tree5e3948feee5b405327d60c4f083988021d51191b /tests/test-classifier.c
parent8c301900fc6f7faface4a2cbd016411f966d0601 (diff)
downloadopenvswitch-13751fd88c4b7464f9453c03659201c10b3b87a0.tar.gz
Classifier: Track address prefixes.
Add a prefix tree (trie) structure for tracking the used address space, enabling skipping classifier tables containing longer masks than necessary for an address field value in a packet header being classified. This enables less unwildcarding for datapath flows in parts of the address space without host routes. Trie lookup is interwoven to the staged lookup, so that a trie is searched only when the configured trie field becomes relevant for the lookup. The trie lookup results are retained so that each trie is checked at most once for each classifier lookup. This implementation tracks the number of rules at each address prefix for the whole classifier. More aggressive table skipping would be possible by maintaining lists of tables that have prefixes at the lengths encountered on tree traversal, or by maintaining separate tries for subsets of rules separated by metadata fields. Prefix tracking is configured via OVSDB. A new column "prefixes" is added to the database table "Flow_Table". "prefixes" is a set of string values listing the field names for which prefix lookup should be used. As of now, the fields for which prefix lookup can be enabled are: - tun_id, tun_src, tun_dst - nw_src, nw_dst (or aliases ip_src and ip_dst) - ipv6_src, ipv6_dst There is a maximum number of fields that can be enabled for any one flow table. Currently this limit is 3. Examples: ovs-vsctl set Bridge br0 flow_tables:0=@N1 -- \ --id=@N1 create Flow_Table name=table0 ovs-vsctl set Bridge br0 flow_tables:1=@N1 -- \ --id=@N1 create Flow_Table name=table1 ovs-vsctl set Flow_Table table0 prefixes=ip_dst,ip_src ovs-vsctl set Flow_Table table1 prefixes=[] Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com> Acked-by: Ben Pfaff <blp@nicira.com>
Diffstat (limited to 'tests/test-classifier.c')
-rw-r--r--tests/test-classifier.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/tests/test-classifier.c b/tests/test-classifier.c
index ee7e76cbd..7555feba9 100644
--- a/tests/test-classifier.c
+++ b/tests/test-classifier.c
@@ -609,6 +609,10 @@ shuffle_u32s(uint32_t *p, size_t n)
/* Classifier tests. */
+static enum mf_field_id trie_fields[2] = {
+ MFF_IPV4_DST, MFF_IPV4_SRC
+};
+
/* Tests an empty classifier. */
static void
test_empty(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
@@ -617,7 +621,8 @@ test_empty(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
struct tcls tcls;
classifier_init(&cls, flow_segment_u32s);
- ovs_rwlock_rdlock(&cls.rwlock);
+ ovs_rwlock_wrlock(&cls.rwlock);
+ classifier_set_prefix_fields(&cls, trie_fields, ARRAY_SIZE(trie_fields));
tcls_init(&tcls);
assert(classifier_is_empty(&cls));
assert(tcls_is_empty(&tcls));
@@ -650,6 +655,8 @@ test_single_rule(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
classifier_init(&cls, flow_segment_u32s);
ovs_rwlock_wrlock(&cls.rwlock);
+ classifier_set_prefix_fields(&cls, trie_fields,
+ ARRAY_SIZE(trie_fields));
tcls_init(&tcls);
tcls_rule = tcls_insert(&tcls, rule);
@@ -689,6 +696,8 @@ test_rule_replacement(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
classifier_init(&cls, flow_segment_u32s);
ovs_rwlock_wrlock(&cls.rwlock);
+ classifier_set_prefix_fields(&cls, trie_fields,
+ ARRAY_SIZE(trie_fields));
tcls_init(&tcls);
tcls_insert(&tcls, rule1);
classifier_insert(&cls, &rule1->cls_rule);
@@ -801,6 +810,8 @@ test_many_rules_in_one_list (int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
classifier_init(&cls, flow_segment_u32s);
ovs_rwlock_wrlock(&cls.rwlock);
+ classifier_set_prefix_fields(&cls, trie_fields,
+ ARRAY_SIZE(trie_fields));
tcls_init(&tcls);
for (i = 0; i < ARRAY_SIZE(ops); i++) {
@@ -903,6 +914,8 @@ test_many_rules_in_one_table(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
classifier_init(&cls, flow_segment_u32s);
ovs_rwlock_wrlock(&cls.rwlock);
+ classifier_set_prefix_fields(&cls, trie_fields,
+ ARRAY_SIZE(trie_fields));
tcls_init(&tcls);
for (i = 0; i < N_RULES; i++) {
@@ -965,6 +978,8 @@ test_many_rules_in_n_tables(int n_tables)
classifier_init(&cls, flow_segment_u32s);
ovs_rwlock_wrlock(&cls.rwlock);
+ classifier_set_prefix_fields(&cls, trie_fields,
+ ARRAY_SIZE(trie_fields));
tcls_init(&tcls);
for (i = 0; i < MAX_RULES; i++) {