/src/openvswitch/lib/dpif-netdev-private-dpcls.h
Line | Count | Source (jump to first uncovered line) |
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_PRIVATE_DPCLS_H |
19 | | #define DPIF_NETDEV_PRIVATE_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 | | /* A set of rules that all have the same fields wildcarded. */ |
67 | | struct dpcls_subtable { |
68 | | /* The fields are only used by writers. */ |
69 | | struct cmap_node cmap_node OVS_GUARDED; /* Within dpcls 'subtables_map'. */ |
70 | | |
71 | | /* These fields are accessed by readers. */ |
72 | | struct cmap rules; /* Contains "struct dpcls_rule"s. */ |
73 | | uint32_t hit_cnt; /* Number of match hits in subtable in current |
74 | | optimization interval. */ |
75 | | |
76 | | /* Miniflow fingerprint that the subtable matches on. The miniflow "bits" |
77 | | * are used to select the actual dpcls lookup implementation at subtable |
78 | | * creation time. |
79 | | */ |
80 | | uint8_t mf_bits_set_unit0; |
81 | | uint8_t mf_bits_set_unit1; |
82 | | |
83 | | /* The lookup function to use for this subtable. If there is a known |
84 | | * property of the subtable (eg: only 3 bits of miniflow metadata is |
85 | | * used for the lookup) then this can point at an optimized version of |
86 | | * the lookup function for this particular subtable. The lookup function |
87 | | * can be used at any time by a PMD thread, so it's declared as an atomic |
88 | | * here to prevent garbage from being read. */ |
89 | | ATOMIC(dpcls_subtable_lookup_func) lookup_func; |
90 | | struct dpcls_subtable_lookup_info_t *lookup_func_info; |
91 | | |
92 | | /* Caches the masks to match a packet to, reducing runtime calculations. */ |
93 | | uint64_t *mf_masks; |
94 | | |
95 | | struct netdev_flow_key mask; /* Wildcards for fields (const). */ |
96 | | /* 'mask' must be the last field, additional space is allocated here. */ |
97 | | }; |
98 | | |
99 | | /* Iterate through netdev_flow_key TNL u64 values specified by 'FLOWMAP'. */ |
100 | | #define NETDEV_FLOW_KEY_FOR_EACH_IN_FLOWMAP(VALUE, KEY, FLOWMAP) \ |
101 | 0 | MINIFLOW_FOR_EACH_IN_FLOWMAP (VALUE, &(KEY)->mf, FLOWMAP) |
102 | | |
103 | | /* Generates a mask for each bit set in the subtable's miniflow. */ |
104 | | void |
105 | | dpcls_flow_key_gen_masks(const struct netdev_flow_key *tbl, uint64_t *mf_masks, |
106 | | const uint32_t mf_bits_u0, const uint32_t mf_bits_u1); |
107 | | |
108 | | /* Matches a dpcls rule against the incoming packet in 'target' */ |
109 | | bool dpcls_rule_matches_key(const struct dpcls_rule *rule, |
110 | | const struct netdev_flow_key *target); |
111 | | |
112 | | static inline uint32_t |
113 | | dpif_netdev_packet_get_rss_hash_orig_pkt(struct dp_packet *packet, |
114 | | const struct miniflow *mf) |
115 | 0 | { |
116 | 0 | uint32_t hash; |
117 | |
|
118 | 0 | if (OVS_LIKELY(dp_packet_rss_valid(packet))) { |
119 | 0 | hash = dp_packet_get_rss_hash(packet); |
120 | 0 | } else { |
121 | 0 | hash = miniflow_hash_5tuple(mf, 0); |
122 | 0 | dp_packet_set_rss_hash(packet, hash); |
123 | 0 | } |
124 | |
|
125 | 0 | return hash; |
126 | 0 | } Unexecuted instantiation: dpif-netdev.c:dpif_netdev_packet_get_rss_hash_orig_pkt Unexecuted instantiation: dpif-netdev-private-dfc.c:dpif_netdev_packet_get_rss_hash_orig_pkt Unexecuted instantiation: dpif-netdev-private-dpif.c:dpif_netdev_packet_get_rss_hash_orig_pkt Unexecuted instantiation: dpif-netdev-private-extract.c:dpif_netdev_packet_get_rss_hash_orig_pkt Unexecuted instantiation: dpif-netdev-extract-study.c:dpif_netdev_packet_get_rss_hash_orig_pkt Unexecuted instantiation: dpif-netdev-lookup.c:dpif_netdev_packet_get_rss_hash_orig_pkt Unexecuted instantiation: dpif-netdev-lookup-autovalidator.c:dpif_netdev_packet_get_rss_hash_orig_pkt Unexecuted instantiation: dpif-netdev-lookup-generic.c:dpif_netdev_packet_get_rss_hash_orig_pkt |
127 | | |
128 | | /* Allow other implementations to call dpcls_lookup() for subtable search. */ |
129 | | bool |
130 | | dpcls_lookup(struct dpcls *cls, const struct netdev_flow_key *keys[], |
131 | | struct dpcls_rule **rules, const size_t cnt, |
132 | | int *num_lookups_p); |
133 | | |
134 | | #ifdef __cplusplus |
135 | | } |
136 | | #endif |
137 | | |
138 | | #endif /* dpif-netdev-private-dpcls.h */ |