/src/openvswitch/include/openvswitch/ofp-group.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 2008-2017 Nicira, Inc. |
3 | | * |
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: |
7 | | * |
8 | | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | | * |
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. |
15 | | */ |
16 | | |
17 | | #ifndef OPENVSWITCH_OFP_GROUP_H |
18 | | #define OPENVSWITCH_OFP_GROUP_H 1 |
19 | | |
20 | | #include "openflow/openflow.h" |
21 | | #include "openflow/netronome-ext.h" |
22 | | #include "openvswitch/list.h" |
23 | | #include "openvswitch/meta-flow.h" |
24 | | #include "openvswitch/type-props.h" |
25 | | |
26 | | struct ds; |
27 | | |
28 | | #ifdef __cplusplus |
29 | | extern "C" { |
30 | | #endif |
31 | | |
32 | | struct ofputil_table_map; |
33 | | |
34 | | /* Group numbers. */ |
35 | | enum { MAX_GROUP_NAME_LEN = INT_STRLEN(uint32_t) }; |
36 | | bool ofputil_group_from_string(const char *, uint32_t *group_id); |
37 | | void ofputil_format_group(uint32_t group_id, struct ds *); |
38 | | void ofputil_group_to_string(uint32_t group_id, |
39 | | char namebuf[MAX_GROUP_NAME_LEN + 1], |
40 | | size_t bufsize); |
41 | | |
42 | | struct bucket_counter { |
43 | | uint64_t packet_count; /* Number of packets processed by bucket. */ |
44 | | uint64_t byte_count; /* Number of bytes processed by bucket. */ |
45 | | }; |
46 | | |
47 | | /* Bucket for use in groups. */ |
48 | | struct ofputil_bucket { |
49 | | struct ovs_list list_node; |
50 | | uint16_t weight; /* Relative weight, for "select" groups. */ |
51 | | ofp_port_t watch_port; /* Port whose state affects whether this bucket |
52 | | * is live. Only required for fast failover |
53 | | * groups. */ |
54 | | uint32_t watch_group; /* Group whose state affects whether this |
55 | | * bucket is live. Only required for fast |
56 | | * failover groups. */ |
57 | | uint32_t bucket_id; /* Bucket Id used to identify bucket*/ |
58 | | struct ofpact *ofpacts; /* Series of "struct ofpact"s. */ |
59 | | size_t ofpacts_len; /* Length of ofpacts, in bytes. */ |
60 | | |
61 | | struct bucket_counter stats; |
62 | | }; |
63 | | |
64 | | void ofputil_bucket_list_destroy(struct ovs_list *buckets); |
65 | | void ofputil_bucket_clone_list(struct ovs_list *dest, |
66 | | const struct ovs_list *src, |
67 | | const struct ofputil_bucket *); |
68 | | struct ofputil_bucket *ofputil_bucket_find(const struct ovs_list *, |
69 | | uint32_t bucket_id); |
70 | | bool ofputil_bucket_check_duplicate_id(const struct ovs_list *); |
71 | | struct ofputil_bucket *ofputil_bucket_list_front(const struct ovs_list *); |
72 | | struct ofputil_bucket *ofputil_bucket_list_back(const struct ovs_list *); |
73 | | void ofputil_bucket_format(struct ds *, const struct ofputil_bucket *, |
74 | | enum ofp11_group_type, enum ofp_version, |
75 | | const struct ofputil_port_map *, |
76 | | const struct ofputil_table_map *); |
77 | | |
78 | | static inline bool |
79 | | ofputil_bucket_has_liveness(const struct ofputil_bucket *bucket) |
80 | 0 | { |
81 | 0 | return (bucket->watch_port != OFPP_ANY || |
82 | 0 | bucket->watch_group != OFPG_ANY); |
83 | 0 | } Unexecuted instantiation: ofp-print.c:ofputil_bucket_has_liveness Unexecuted instantiation: ofp-bundle.c:ofputil_bucket_has_liveness Unexecuted instantiation: ofp-flow.c:ofputil_bucket_has_liveness Unexecuted instantiation: ofp-group.c:ofputil_bucket_has_liveness Unexecuted instantiation: ofp-monitor.c:ofputil_bucket_has_liveness |
84 | | |
85 | | struct ofputil_group_props { |
86 | | /* NTR selection method */ |
87 | | char selection_method[NTR_MAX_SELECTION_METHOD_LEN]; |
88 | | uint64_t selection_method_param; |
89 | | struct field_array fields; |
90 | | }; |
91 | | |
92 | | void ofputil_group_properties_destroy(struct ofputil_group_props *); |
93 | | void ofputil_group_properties_copy(struct ofputil_group_props *to, |
94 | | const struct ofputil_group_props *from); |
95 | | void ofputil_group_properties_format(const struct ofputil_group_props *, |
96 | | struct ds *); |
97 | | /* Protocol-independent group_mod. */ |
98 | | struct ofputil_group_mod { |
99 | | uint16_t command; /* One of OFPGC15_*. */ |
100 | | uint8_t type; /* One of OFPGT11_*. */ |
101 | | uint32_t group_id; /* Group identifier. */ |
102 | | uint32_t command_bucket_id; /* Bucket Id used as part of |
103 | | * OFPGC15_INSERT_BUCKET and |
104 | | * OFPGC15_REMOVE_BUCKET commands |
105 | | * execution.*/ |
106 | | struct ovs_list buckets; /* Contains "struct ofputil_bucket"s. */ |
107 | | struct ofputil_group_props props; /* Group properties. */ |
108 | | }; |
109 | | |
110 | | void ofputil_uninit_group_mod(struct ofputil_group_mod *gm); |
111 | | struct ofpbuf *ofputil_encode_group_mod(enum ofp_version ofp_version, |
112 | | const struct ofputil_group_mod *gm, |
113 | | const struct ovs_list *new_buckets, |
114 | | int group_existed); |
115 | | |
116 | | enum ofperr ofputil_decode_group_mod(const struct ofp_header *, |
117 | | struct ofputil_group_mod *); |
118 | | |
119 | | void ofputil_group_mod_format__(struct ds *, enum ofp_version, |
120 | | const struct ofputil_group_mod *, |
121 | | const struct ofputil_port_map *, |
122 | | const struct ofputil_table_map *); |
123 | | enum ofperr ofputil_group_mod_format(struct ds *, const struct ofp_header *, |
124 | | const struct ofputil_port_map *, |
125 | | const struct ofputil_table_map *); |
126 | | |
127 | | char *parse_ofp_group_mod_file(const char *file_name, |
128 | | const struct ofputil_port_map *, |
129 | | const struct ofputil_table_map *, int command, |
130 | | struct ofputil_group_mod **gms, size_t *n_gms, |
131 | | enum ofputil_protocol *usable_protocols) |
132 | | OVS_WARN_UNUSED_RESULT; |
133 | | |
134 | | char *parse_ofp_group_mod_str(struct ofputil_group_mod *, int command, |
135 | | const char *string, |
136 | | const struct ofputil_port_map *, |
137 | | const struct ofputil_table_map *, |
138 | | enum ofputil_protocol *usable_protocols) |
139 | | OVS_WARN_UNUSED_RESULT; |
140 | | |
141 | | /* Group stats reply, independent of protocol. */ |
142 | | struct ofputil_group_stats { |
143 | | uint32_t group_id; /* Group identifier. */ |
144 | | uint32_t ref_count; |
145 | | uint64_t packet_count; /* Packet count, UINT64_MAX if unknown. */ |
146 | | uint64_t byte_count; /* Byte count, UINT64_MAX if unknown. */ |
147 | | uint32_t duration_sec; /* UINT32_MAX if unknown. */ |
148 | | uint32_t duration_nsec; |
149 | | uint32_t n_buckets; |
150 | | struct bucket_counter *bucket_stats; |
151 | | }; |
152 | | |
153 | | struct ofpbuf *ofputil_encode_group_stats_request(enum ofp_version, |
154 | | uint32_t group_id); |
155 | | enum ofperr ofputil_decode_group_stats_request( |
156 | | const struct ofp_header *request, uint32_t *group_id); |
157 | | void ofputil_append_group_stats(struct ovs_list *replies, |
158 | | const struct ofputil_group_stats *); |
159 | | enum ofperr ofputil_group_stats_request_format(struct ds *, |
160 | | const struct ofp_header *); |
161 | | |
162 | | int ofputil_decode_group_stats_reply(struct ofpbuf *, |
163 | | struct ofputil_group_stats *); |
164 | | enum ofperr ofputil_group_stats_format(struct ds *, const struct ofp_header *); |
165 | | |
166 | | /* Group features reply, independent of protocol. |
167 | | * |
168 | | * Only OF1.2 and later support group features replies. */ |
169 | | struct ofputil_group_features { |
170 | | uint32_t types; /* Bitmap of OFPGT_* values supported. */ |
171 | | uint32_t capabilities; /* Bitmap of OFPGFC12_* capability supported. */ |
172 | | uint32_t max_groups[4]; /* Maximum number of groups for each type. */ |
173 | | uint64_t ofpacts[4]; /* Bitmaps of supported OFPACT_* */ |
174 | | }; |
175 | | |
176 | | struct ofpbuf *ofputil_encode_group_features_request(enum ofp_version); |
177 | | struct ofpbuf *ofputil_encode_group_features_reply( |
178 | | const struct ofputil_group_features *, const struct ofp_header *request); |
179 | | void ofputil_decode_group_features_reply(const struct ofp_header *, |
180 | | struct ofputil_group_features *); |
181 | | |
182 | | /* Group desc reply, independent of protocol. */ |
183 | | struct ofputil_group_desc { |
184 | | uint8_t type; /* One of OFPGT_*. */ |
185 | | uint32_t group_id; /* Group identifier. */ |
186 | | struct ovs_list buckets; /* Contains "struct ofputil_bucket"s. */ |
187 | | struct ofputil_group_props props; /* Group properties. */ |
188 | | }; |
189 | | |
190 | | void ofputil_uninit_group_desc(struct ofputil_group_desc *gd); |
191 | | uint32_t ofputil_decode_group_desc_request(const struct ofp_header *); |
192 | | struct ofpbuf *ofputil_encode_group_desc_request(enum ofp_version, |
193 | | uint32_t group_id); |
194 | | enum ofperr ofputil_group_desc_request_format(struct ds *, |
195 | | const struct ofp_header *); |
196 | | |
197 | | int ofputil_decode_group_desc_reply(struct ofputil_group_desc *, |
198 | | struct ofpbuf *, enum ofp_version); |
199 | | void ofputil_append_group_desc_reply(const struct ofputil_group_desc *, |
200 | | const struct ovs_list *buckets, |
201 | | struct ovs_list *replies); |
202 | | enum ofperr ofputil_group_desc_format(struct ds *, const struct ofp_header *, |
203 | | const struct ofputil_port_map *, |
204 | | const struct ofputil_table_map *); |
205 | | enum ofperr ofputil_group_features_format(struct ds *, |
206 | | const struct ofp_header *); |
207 | | |
208 | | /* Group formatting. */ |
209 | | void ofputil_group_format(struct ds *s, uint32_t group_id, uint8_t type, |
210 | | const struct ofputil_bucket *, |
211 | | const struct ovs_list *p_buckets, |
212 | | const struct ofputil_group_props *, |
213 | | enum ofp_version, bool suppress_type, |
214 | | const struct ofputil_port_map *, |
215 | | const struct ofputil_table_map *); |
216 | | #ifdef __cplusplus |
217 | | } |
218 | | #endif |
219 | | |
220 | | #endif /* ofp-group.h */ |