]>
Commit | Line | Data |
---|---|---|
f5ace7cd HH |
1 | /* |
2 | * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2015 Nicira, Inc. | |
3 | * Copyright (c) 2019 Intel Corperation. | |
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_H | |
19 | #define DPIF_NETDEV_PRIVATE_H 1 | |
20 | ||
21 | #include <stdbool.h> | |
22 | #include <stdint.h> | |
23 | ||
24 | #include "dpif.h" | |
25 | #include "cmap.h" | |
26 | ||
27 | #ifdef __cplusplus | |
28 | extern "C" { | |
29 | #endif | |
30 | ||
31 | /* Forward declaration for lookup_func typedef. */ | |
32 | struct dpcls_subtable; | |
33 | struct dpcls_rule; | |
34 | ||
35 | /* Must be public as it is instantiated in subtable struct below. */ | |
36 | struct netdev_flow_key { | |
37 | uint32_t hash; /* Hash function differs for different users. */ | |
38 | uint32_t len; /* Length of the following miniflow (incl. map). */ | |
39 | struct miniflow mf; | |
40 | uint64_t buf[FLOW_MAX_PACKET_U64S]; | |
41 | }; | |
42 | ||
43 | /* A rule to be inserted to the classifier. */ | |
44 | struct dpcls_rule { | |
45 | struct cmap_node cmap_node; /* Within struct dpcls_subtable 'rules'. */ | |
46 | struct netdev_flow_key *mask; /* Subtable's mask. */ | |
47 | struct netdev_flow_key flow; /* Matching key. */ | |
48 | /* 'flow' must be the last field, additional space is allocated here. */ | |
49 | }; | |
50 | ||
51 | /* Lookup function for a subtable in the dpcls. This function is called | |
52 | * by each subtable with an array of packets, and a bitmask of packets to | |
53 | * perform the lookup on. Using a function pointer gives flexibility to | |
54 | * optimize the lookup function based on subtable properties and the | |
55 | * CPU instruction set available at runtime. | |
56 | */ | |
57 | typedef | |
58 | uint32_t (*dpcls_subtable_lookup_func)(struct dpcls_subtable *subtable, | |
59 | uint32_t keys_map, | |
60 | const struct netdev_flow_key *keys[], | |
61 | struct dpcls_rule **rules); | |
62 | ||
a0b36b39 | 63 | /* Prototype for generic lookup func, using generic scalar code path. */ |
f5ace7cd HH |
64 | uint32_t |
65 | dpcls_subtable_lookup_generic(struct dpcls_subtable *subtable, | |
66 | uint32_t keys_map, | |
67 | const struct netdev_flow_key *keys[], | |
68 | struct dpcls_rule **rules); | |
69 | ||
f54d8f00 HH |
70 | /* Probe function to select a specialized version of the generic lookup |
71 | * implementation. This provides performance benefit due to compile-time | |
72 | * optimizations such as loop-unrolling. These are enabled by the compile-time | |
73 | * constants in the specific function implementations. | |
74 | */ | |
75 | dpcls_subtable_lookup_func | |
76 | dpcls_subtable_generic_probe(uint32_t u0_bit_count, uint32_t u1_bit_count); | |
77 | ||
f5ace7cd HH |
78 | /* A set of rules that all have the same fields wildcarded. */ |
79 | struct dpcls_subtable { | |
80 | /* The fields are only used by writers. */ | |
81 | struct cmap_node cmap_node OVS_GUARDED; /* Within dpcls 'subtables_map'. */ | |
82 | ||
83 | /* These fields are accessed by readers. */ | |
84 | struct cmap rules; /* Contains "struct dpcls_rule"s. */ | |
85 | uint32_t hit_cnt; /* Number of match hits in subtable in current | |
86 | optimization interval. */ | |
87 | ||
a0b36b39 HH |
88 | /* Miniflow fingerprint that the subtable matches on. The miniflow "bits" |
89 | * are used to select the actual dpcls lookup implementation at subtable | |
90 | * creation time. | |
91 | */ | |
92 | uint8_t mf_bits_set_unit0; | |
93 | uint8_t mf_bits_set_unit1; | |
94 | ||
f5ace7cd HH |
95 | /* The lookup function to use for this subtable. If there is a known |
96 | * property of the subtable (eg: only 3 bits of miniflow metadata is | |
97 | * used for the lookup) then this can point at an optimized version of | |
98 | * the lookup function for this particular subtable. */ | |
99 | dpcls_subtable_lookup_func lookup_func; | |
100 | ||
a0b36b39 HH |
101 | /* Caches the masks to match a packet to, reducing runtime calculations. */ |
102 | uint64_t *mf_masks; | |
103 | ||
f5ace7cd HH |
104 | struct netdev_flow_key mask; /* Wildcards for fields (const). */ |
105 | /* 'mask' must be the last field, additional space is allocated here. */ | |
106 | }; | |
107 | ||
108 | /* Iterate through netdev_flow_key TNL u64 values specified by 'FLOWMAP'. */ | |
109 | #define NETDEV_FLOW_KEY_FOR_EACH_IN_FLOWMAP(VALUE, KEY, FLOWMAP) \ | |
110 | MINIFLOW_FOR_EACH_IN_FLOWMAP (VALUE, &(KEY)->mf, FLOWMAP) | |
111 | ||
112 | /* Generates a mask for each bit set in the subtable's miniflow. */ | |
113 | void | |
114 | netdev_flow_key_gen_masks(const struct netdev_flow_key *tbl, | |
115 | uint64_t *mf_masks, | |
116 | const uint32_t mf_bits_u0, | |
117 | const uint32_t mf_bits_u1); | |
118 | ||
119 | /* Matches a dpcls rule against the incoming packet in 'target' */ | |
120 | bool dpcls_rule_matches_key(const struct dpcls_rule *rule, | |
121 | const struct netdev_flow_key *target); | |
122 | ||
123 | #ifdef __cplusplus | |
124 | } | |
125 | #endif | |
126 | ||
127 | #endif /* netdev-private.h */ |