/src/openvswitch/lib/dpif-netdev-dpcls.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2015 Nicira, Inc. |
3 | | * Copyright (c) 2019, 2020, 2021 Intel Corporation. |
4 | | * |
5 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
6 | | * you may not use this file except in compliance with the License. |
7 | | * You may obtain a copy of the License at: |
8 | | * |
9 | | * http://www.apache.org/licenses/LICENSE-2.0 |
10 | | * |
11 | | * Unless required by applicable law or agreed to in writing, software |
12 | | * distributed under the License is distributed on an "AS IS" BASIS, |
13 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 | | * See the License for the specific language governing permissions and |
15 | | * limitations under the License. |
16 | | */ |
17 | | |
18 | | #ifndef DPIF_NETDEV_DPCLS_H |
19 | | #define DPIF_NETDEV_DPCLS_H 1 |
20 | | |
21 | | #include "dpif.h" |
22 | | |
23 | | #include <stdbool.h> |
24 | | #include <stdint.h> |
25 | | |
26 | | #include "cmap.h" |
27 | | #include "openvswitch/thread.h" |
28 | | |
29 | | #ifdef __cplusplus |
30 | | extern "C" { |
31 | | #endif |
32 | | |
33 | | /* Forward declaration for lookup_func typedef. */ |
34 | | struct dpcls_subtable; |
35 | | struct dpcls_rule; |
36 | | struct dpcls; |
37 | | |
38 | | /* Must be public as it is instantiated in subtable struct below. */ |
39 | | struct netdev_flow_key { |
40 | | uint32_t hash; /* Hash function differs for different users. */ |
41 | | uint32_t len; /* Length of the following miniflow (incl. map). */ |
42 | | struct miniflow mf; |
43 | | uint64_t buf[FLOW_MAX_PACKET_U64S]; |
44 | | }; |
45 | | |
46 | | /* A rule to be inserted to the classifier. */ |
47 | | struct dpcls_rule { |
48 | | struct cmap_node cmap_node; /* Within struct dpcls_subtable 'rules'. */ |
49 | | struct netdev_flow_key *mask; /* Subtable's mask. */ |
50 | | struct netdev_flow_key flow; /* Matching key. */ |
51 | | /* 'flow' must be the last field, additional space is allocated here. */ |
52 | | }; |
53 | | |
54 | | /* Lookup function for a subtable in the dpcls. This function is called |
55 | | * by each subtable with an array of packets, and a bitmask of packets to |
56 | | * perform the lookup on. Using a function pointer gives flexibility to |
57 | | * optimize the lookup function based on subtable properties and the |
58 | | * CPU instruction set available at runtime. |
59 | | */ |
60 | | typedef |
61 | | uint32_t (*dpcls_subtable_lookup_func)(struct dpcls_subtable *subtable, |
62 | | uint32_t keys_map, |
63 | | const struct netdev_flow_key *keys[], |
64 | | struct dpcls_rule **rules); |
65 | | |
66 | | /* Probe function to lookup an available specialized lookup function. |
67 | | * Returns the most optimal implementation for the miniflow fingerprint. |
68 | | */ |
69 | | dpcls_subtable_lookup_func dpcls_subtable_lookup_probe(uint32_t u0_bits, |
70 | | uint32_t u1_bits); |
71 | | |
72 | | /* A set of rules that all have the same fields wildcarded. */ |
73 | | struct dpcls_subtable { |
74 | | /* The fields are only used by writers. */ |
75 | | struct cmap_node cmap_node; /* Within dpcls 'subtables_map'. */ |
76 | | |
77 | | /* These fields are accessed by readers. */ |
78 | | struct cmap rules; /* Contains "struct dpcls_rule"s. */ |
79 | | uint32_t hit_cnt; /* Number of match hits in subtable in current |
80 | | optimization interval. */ |
81 | | |
82 | | /* Miniflow fingerprint that the subtable matches on. The miniflow "bits" |
83 | | * are used to select the actual dpcls lookup implementation at subtable |
84 | | * creation time. |
85 | | */ |
86 | | uint8_t mf_bits_set_unit0; |
87 | | uint8_t mf_bits_set_unit1; |
88 | | |
89 | | /* The lookup function to use for this subtable. If there is a known |
90 | | * property of the subtable (eg: only 3 bits of miniflow metadata is |
91 | | * used for the lookup) then this can point at an optimized version of |
92 | | * the lookup function for this particular subtable. */ |
93 | | dpcls_subtable_lookup_func lookup_func; |
94 | | |
95 | | /* Caches the masks to match a packet to, reducing runtime calculations. */ |
96 | | uint64_t *mf_masks; |
97 | | |
98 | | struct netdev_flow_key mask; /* Wildcards for fields (const). */ |
99 | | /* 'mask' must be the last field, additional space is allocated here. */ |
100 | | }; |
101 | | |
102 | | /* Iterate through netdev_flow_key TNL u64 values specified by 'FLOWMAP'. */ |
103 | | #define NETDEV_FLOW_KEY_FOR_EACH_IN_FLOWMAP(VALUE, KEY, FLOWMAP) \ |
104 | 0 | MINIFLOW_FOR_EACH_IN_FLOWMAP (VALUE, &(KEY)->mf, FLOWMAP) |
105 | | |
106 | | /* Generates a mask for each bit set in the subtable's miniflow. */ |
107 | | void |
108 | | dpcls_flow_key_gen_masks(const struct netdev_flow_key *tbl, uint64_t *mf_masks, |
109 | | const uint32_t mf_bits_u0, const uint32_t mf_bits_u1); |
110 | | |
111 | | /* Matches a dpcls rule against the incoming packet in 'target' */ |
112 | | bool dpcls_rule_matches_key(const struct dpcls_rule *rule, |
113 | | const struct netdev_flow_key *target); |
114 | | |
115 | | static inline uint32_t |
116 | | dpif_netdev_packet_get_rss_hash_orig_pkt(struct dp_packet *packet, |
117 | | const struct miniflow *mf) |
118 | 0 | { |
119 | 0 | uint32_t hash; |
120 | |
|
121 | 0 | if (OVS_LIKELY(dp_packet_rss_valid(packet))) { |
122 | 0 | hash = dp_packet_get_rss_hash(packet); |
123 | 0 | } else { |
124 | 0 | hash = miniflow_hash_5tuple(mf, 0); |
125 | 0 | dp_packet_set_rss_hash(packet, hash); |
126 | 0 | } |
127 | |
|
128 | 0 | return hash; |
129 | 0 | } Unexecuted instantiation: dpif-netdev.c:dpif_netdev_packet_get_rss_hash_orig_pkt Unexecuted instantiation: dpif-netdev-dfc.c:dpif_netdev_packet_get_rss_hash_orig_pkt Unexecuted instantiation: dpif-netdev-dpcls.c:dpif_netdev_packet_get_rss_hash_orig_pkt |
130 | | |
131 | | /* Allow other implementations to call dpcls_lookup() for subtable search. */ |
132 | | bool |
133 | | dpcls_lookup(struct dpcls *cls, const struct netdev_flow_key *keys[], |
134 | | struct dpcls_rule **rules, const size_t cnt, |
135 | | int *num_lookups_p); |
136 | | |
137 | | #ifdef __cplusplus |
138 | | } |
139 | | #endif |
140 | | |
141 | | #endif /* dpif-netdev-dpcls.h */ |