]>
git.proxmox.com Git - mirror_ovs.git/blob - lib/classifier.h
2 * Copyright (c) 2009, 2010, 2011 Nicira Networks.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #define CLASSIFIER_H 1
22 * A classifier is a "struct classifier",
23 * a hash map from a set of wildcards to a "struct cls_table",
24 * a hash map from fixed field values to "struct cls_rule",
25 * which can contain a list of otherwise identical rules
26 * with lower priorities.
32 #include "openflow/nicira-ext.h"
33 #include "openflow/openflow.h"
35 /* A flow classifier. */
37 int n_rules
; /* Total number of rules. */
38 struct hmap tables
; /* Contains "struct cls_table"s. */
41 /* A set of rules that all have the same fields wildcarded. */
43 struct hmap_node hmap_node
; /* Within struct classifier 'wctables'. */
44 struct hmap rules
; /* Contains "struct cls_rule"s. */
45 struct flow_wildcards wc
; /* Wildcards for fields. */
46 int n_table_rules
; /* Number of rules, including duplicates. */
49 /* A flow classification rule.
51 * Use one of the cls_rule_*() functions to initialize a cls_rule.
53 * The cls_rule_*() functions below maintain the following important
54 * invariant that the classifier depends on:
56 * - If a bit or a field is wildcarded in 'wc', then the corresponding bit or
57 * field in 'flow' is set to all-0-bits. (The
58 * cls_rule_zero_wildcarded_fields() function can be used to restore this
59 * invariant after adding wildcards.)
62 struct hmap_node hmap_node
; /* Within struct cls_table 'rules'. */
63 struct list list
; /* List of identical, lower-priority rules. */
64 struct flow flow
; /* All field values. */
65 struct flow_wildcards wc
; /* Wildcards for fields. */
66 unsigned int priority
; /* Larger numbers are higher priorities. */
69 void cls_rule_init(const struct flow
*, const struct flow_wildcards
*,
70 unsigned int priority
, struct cls_rule
*);
71 void cls_rule_init_exact(const struct flow
*, unsigned int priority
,
73 void cls_rule_init_catchall(struct cls_rule
*, unsigned int priority
);
75 void cls_rule_zero_wildcarded_fields(struct cls_rule
*);
77 void cls_rule_set_reg(struct cls_rule
*, unsigned int reg_idx
, uint32_t value
);
78 void cls_rule_set_reg_masked(struct cls_rule
*, unsigned int reg_idx
,
79 uint32_t value
, uint32_t mask
);
80 void cls_rule_set_tun_id(struct cls_rule
*, ovs_be64 tun_id
);
81 void cls_rule_set_tun_id_masked(struct cls_rule
*,
82 ovs_be64 tun_id
, ovs_be64 mask
);
83 void cls_rule_set_in_port(struct cls_rule
*, uint16_t odp_port
);
84 void cls_rule_set_dl_type(struct cls_rule
*, ovs_be16
);
85 void cls_rule_set_dl_src(struct cls_rule
*, const uint8_t[6]);
86 void cls_rule_set_dl_dst(struct cls_rule
*, const uint8_t[6]);
87 void cls_rule_set_dl_dst_masked(struct cls_rule
*, const uint8_t dl_dst
[6],
88 const uint8_t mask
[6]);
89 void cls_rule_set_dl_tci(struct cls_rule
*, ovs_be16 tci
);
90 void cls_rule_set_dl_tci_masked(struct cls_rule
*,
91 ovs_be16 tci
, ovs_be16 mask
);
92 void cls_rule_set_any_vid(struct cls_rule
*);
93 void cls_rule_set_dl_vlan(struct cls_rule
*, ovs_be16
);
94 void cls_rule_set_any_pcp(struct cls_rule
*);
95 void cls_rule_set_dl_vlan_pcp(struct cls_rule
*, uint8_t);
96 void cls_rule_set_tp_src(struct cls_rule
*, ovs_be16
);
97 void cls_rule_set_tp_dst(struct cls_rule
*, ovs_be16
);
98 void cls_rule_set_nw_proto(struct cls_rule
*, uint8_t);
99 void cls_rule_set_nw_src(struct cls_rule
*, ovs_be32
);
100 bool cls_rule_set_nw_src_masked(struct cls_rule
*, ovs_be32 ip
, ovs_be32 mask
);
101 void cls_rule_set_nw_dst(struct cls_rule
*, ovs_be32
);
102 bool cls_rule_set_nw_dst_masked(struct cls_rule
*, ovs_be32 ip
, ovs_be32 mask
);
103 void cls_rule_set_nw_tos(struct cls_rule
*, uint8_t);
104 void cls_rule_set_icmp_type(struct cls_rule
*, uint8_t);
105 void cls_rule_set_icmp_code(struct cls_rule
*, uint8_t);
106 void cls_rule_set_arp_sha(struct cls_rule
*, const uint8_t[6]);
107 void cls_rule_set_arp_tha(struct cls_rule
*, const uint8_t[6]);
108 void cls_rule_set_ipv6_src(struct cls_rule
*, const struct in6_addr
*);
109 bool cls_rule_set_ipv6_src_masked(struct cls_rule
*, const struct in6_addr
*,
110 const struct in6_addr
*);
111 void cls_rule_set_ipv6_dst(struct cls_rule
*, const struct in6_addr
*);
112 bool cls_rule_set_ipv6_dst_masked(struct cls_rule
*, const struct in6_addr
*,
113 const struct in6_addr
*);
114 void cls_rule_set_nd_target(struct cls_rule
*, const struct in6_addr
);
116 bool cls_rule_equal(const struct cls_rule
*, const struct cls_rule
*);
117 uint32_t cls_rule_hash(const struct cls_rule
*, uint32_t basis
);
119 void cls_rule_format(const struct cls_rule
*, struct ds
*);
120 char *cls_rule_to_string(const struct cls_rule
*);
121 void cls_rule_print(const struct cls_rule
*);
123 void classifier_init(struct classifier
*);
124 void classifier_destroy(struct classifier
*);
125 bool classifier_is_empty(const struct classifier
*);
126 int classifier_count(const struct classifier
*);
127 void classifier_insert(struct classifier
*, struct cls_rule
*);
128 struct cls_rule
*classifier_replace(struct classifier
*, struct cls_rule
*);
129 void classifier_remove(struct classifier
*, struct cls_rule
*);
130 struct cls_rule
*classifier_lookup(const struct classifier
*,
131 const struct flow
*);
132 bool classifier_rule_overlaps(const struct classifier
*,
133 const struct cls_rule
*);
135 typedef void cls_cb_func(struct cls_rule
*, void *aux
);
137 struct cls_rule
*classifier_find_rule_exactly(const struct classifier
*,
138 const struct cls_rule
*);
143 const struct classifier
*cls
;
144 const struct cls_table
*table
;
145 const struct cls_rule
*target
;
148 void cls_cursor_init(struct cls_cursor
*, const struct classifier
*,
149 const struct cls_rule
*match
);
150 struct cls_rule
*cls_cursor_first(struct cls_cursor
*);
151 struct cls_rule
*cls_cursor_next(struct cls_cursor
*, struct cls_rule
*);
153 #define CLS_CURSOR_FOR_EACH(RULE, MEMBER, CURSOR) \
154 for (ASSIGN_CONTAINER(RULE, cls_cursor_first(CURSOR), MEMBER); \
155 &(RULE)->MEMBER != NULL; \
156 ASSIGN_CONTAINER(RULE, cls_cursor_next(CURSOR, &(RULE)->MEMBER), \
159 #define CLS_CURSOR_FOR_EACH_SAFE(RULE, NEXT, MEMBER, CURSOR) \
160 for (ASSIGN_CONTAINER(RULE, cls_cursor_first(CURSOR), MEMBER); \
161 (&(RULE)->MEMBER != NULL \
162 ? ASSIGN_CONTAINER(NEXT, cls_cursor_next(CURSOR, &(RULE)->MEMBER), \
167 #endif /* classifier.h */