]>
Commit | Line | Data |
---|---|---|
09246b99 | 1 | /* |
04f48a68 | 2 | * Copyright (c) 2010-2017 Nicira, Inc. |
09246b99 BP |
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 NX_MATCH_H | |
18 | #define NX_MATCH_H 1 | |
19 | ||
20 | #include <stdint.h> | |
c979df05 BP |
21 | #include <sys/types.h> |
22 | #include <netinet/in.h> | |
bdda5aca | 23 | #include "compiler.h" |
e9358af6 | 24 | #include "flow.h" |
064d7f84 | 25 | #include "openvswitch/meta-flow.h" |
e03c096d | 26 | #include "openvswitch/ofp-errors.h" |
c979df05 | 27 | #include "openvswitch/types.h" |
09246b99 | 28 | |
f393f81e | 29 | struct ds; |
81a76618 | 30 | struct match; |
f25d0cf3 BP |
31 | struct ofpact_reg_move; |
32 | struct ofpact_reg_load; | |
bd85dac1 | 33 | struct ofpact_stack; |
09246b99 | 34 | struct ofpbuf; |
b6c9e612 BP |
35 | struct nx_action_reg_load; |
36 | struct nx_action_reg_move; | |
aafee638 | 37 | struct vl_mff_map; |
09246b99 | 38 | |
bd85dac1 | 39 | |
09246b99 BP |
40 | /* Nicira Extended Match (NXM) flexible flow match helper functions. |
41 | * | |
42 | * See include/openflow/nicira-ext.h for NXM specification. | |
43 | */ | |
44 | ||
178742f9 BP |
45 | void mf_format_subfield(const struct mf_subfield *, struct ds *); |
46 | char *mf_parse_subfield__(struct mf_subfield *sf, const char **s) | |
cab50449 | 47 | OVS_WARN_UNUSED_RESULT; |
178742f9 | 48 | char *mf_parse_subfield(struct mf_subfield *, const char *s) |
cab50449 | 49 | OVS_WARN_UNUSED_RESULT; |
178742f9 | 50 | |
9f6e20b7 | 51 | /* Decoding matches. */ |
90bf1e07 | 52 | enum ofperr nx_pull_match(struct ofpbuf *, unsigned int match_len, |
d7892c81 YHW |
53 | struct match *, ovs_be64 *cookie, |
54 | ovs_be64 *cookie_mask, bool pipeline_fields_only, | |
3cddeff0 | 55 | const struct tun_table *, const struct vl_mff_map *); |
90bf1e07 | 56 | enum ofperr nx_pull_match_loose(struct ofpbuf *, unsigned int match_len, |
81a76618 | 57 | struct match *, ovs_be64 *cookie, |
8d8ab6c2 | 58 | ovs_be64 *cookie_mask, |
d7892c81 | 59 | bool pipeline_fields_only, |
8d8ab6c2 | 60 | const struct tun_table *); |
d7892c81 YHW |
61 | enum ofperr oxm_pull_match(struct ofpbuf *, bool pipeline_fields_only, |
62 | const struct tun_table *, const struct vl_mff_map *, | |
63 | struct match *); | |
64 | enum ofperr oxm_pull_match_loose(struct ofpbuf *, bool pipeline_fields_only, | |
65 | const struct tun_table *, struct match *); | |
87450a4e | 66 | enum ofperr oxm_decode_match(const void *, size_t, bool, |
3cddeff0 YHW |
67 | const struct tun_table *, |
68 | const struct vl_mff_map *, struct match *); | |
bc65c25a SH |
69 | enum ofperr oxm_pull_field_array(const void *, size_t fields_len, |
70 | struct field_array *); | |
9f6e20b7 BP |
71 | |
72 | /* Encoding matches. */ | |
81a76618 | 73 | int nx_put_match(struct ofpbuf *, const struct match *, |
e729e793 | 74 | ovs_be64 cookie, ovs_be64 cookie_mask); |
9d84066c | 75 | int oxm_put_match(struct ofpbuf *, const struct match *, enum ofp_version); |
9f6e20b7 | 76 | void oxm_put_raw(struct ofpbuf *, const struct match *, enum ofp_version); |
53eb84a5 SH |
77 | void oxm_format_field_array(struct ds *, const struct field_array *); |
78 | int oxm_put_field_array(struct ofpbuf *, const struct field_array *, | |
79 | enum ofp_version version); | |
09246b99 | 80 | |
178742f9 BP |
81 | /* Decoding and encoding OXM/NXM headers (just a field ID) or entries (a field |
82 | * ID followed by a value and possibly a mask). */ | |
04f48a68 YHW |
83 | enum ofperr nx_pull_entry(struct ofpbuf *, const struct vl_mff_map *, |
84 | const struct mf_field **, union mf_value *value, | |
85 | union mf_value *mask); | |
86 | enum ofperr nx_pull_header(struct ofpbuf *, const struct vl_mff_map *, | |
87 | const struct mf_field **, bool *masked); | |
1cb20095 JG |
88 | void nxm_put__(struct ofpbuf *b, enum mf_field_id field, |
89 | enum ofp_version version, const void *value, | |
90 | const void *mask, size_t n_bytes); | |
04f48a68 | 91 | void nx_put_entry(struct ofpbuf *, const struct mf_field *, enum ofp_version, |
178742f9 BP |
92 | const union mf_value *value, const union mf_value *mask); |
93 | void nx_put_header(struct ofpbuf *, enum mf_field_id, enum ofp_version, | |
94 | bool masked); | |
04f48a68 YHW |
95 | void nx_put_mff_header(struct ofpbuf *, const struct mf_field *, |
96 | enum ofp_version, bool); | |
178742f9 BP |
97 | |
98 | /* NXM and OXM protocol headers values. | |
99 | * | |
100 | * These are often alternatives to nx_pull_entry/header() and | |
101 | * nx_put_entry/header() for decoding and encoding OXM/NXM. In those cases, | |
102 | * the nx_*() functions should be preferred because they can support the 64-bit | |
103 | * "experimenter" OXM format (even though it is not yet implemented). */ | |
508a9338 | 104 | uint32_t mf_nxm_header(enum mf_field_id); |
04f48a68 YHW |
105 | uint32_t nxm_header_from_mff(const struct mf_field *); |
106 | const struct mf_field *mf_from_nxm_header(uint32_t nxm_header, | |
107 | const struct vl_mff_map *); | |
178742f9 | 108 | |
09246b99 | 109 | char *nx_match_to_string(const uint8_t *, unsigned int match_len); |
db5a1019 | 110 | char *oxm_match_to_string(const struct ofpbuf *, unsigned int match_len); |
09246b99 | 111 | int nx_match_from_string(const char *, struct ofpbuf *); |
7623f4dd | 112 | int oxm_match_from_string(const char *, struct ofpbuf *); |
09246b99 | 113 | |
178742f9 BP |
114 | void nx_format_field_name(enum mf_field_id, enum ofp_version, struct ds *); |
115 | ||
bdda5aca | 116 | char *nxm_parse_reg_move(struct ofpact_reg_move *, const char *) |
cab50449 | 117 | OVS_WARN_UNUSED_RESULT; |
f25d0cf3 BP |
118 | |
119 | void nxm_format_reg_move(const struct ofpact_reg_move *, struct ds *); | |
f393f81e | 120 | |
f25d0cf3 | 121 | enum ofperr nxm_reg_move_check(const struct ofpact_reg_move *, |
67210a55 | 122 | const struct match *); |
b6c9e612 | 123 | |
f25d0cf3 | 124 | void nxm_reg_load(const struct mf_subfield *, uint64_t src_data, |
f74e7df7 | 125 | struct flow *, struct flow_wildcards *); |
b6c9e612 | 126 | |
bdda5aca | 127 | char *nxm_parse_stack_action(struct ofpact_stack *, const char *) |
cab50449 | 128 | OVS_WARN_UNUSED_RESULT; |
bd85dac1 AZ |
129 | |
130 | void nxm_format_stack_push(const struct ofpact_stack *, struct ds *); | |
131 | void nxm_format_stack_pop(const struct ofpact_stack *, struct ds *); | |
132 | ||
bd85dac1 | 133 | enum ofperr nxm_stack_push_check(const struct ofpact_stack *, |
67210a55 | 134 | const struct match *); |
bd85dac1 | 135 | enum ofperr nxm_stack_pop_check(const struct ofpact_stack *, |
67210a55 | 136 | const struct match *); |
84cf3c1f JR |
137 | void nx_stack_push(struct ofpbuf *stack, const void *v, uint8_t bytes); |
138 | void nx_stack_push_bottom(struct ofpbuf *stack, const void *v, uint8_t bytes); | |
139 | void *nx_stack_pop(struct ofpbuf *stack, uint8_t *bytes); | |
bd85dac1 | 140 | |
bd85dac1 | 141 | void nxm_execute_stack_push(const struct ofpact_stack *, |
bcd2633a JP |
142 | const struct flow *, struct flow_wildcards *, |
143 | struct ofpbuf *); | |
2d9b49dd BP |
144 | bool nxm_execute_stack_pop(const struct ofpact_stack *, |
145 | struct flow *, struct flow_wildcards *, | |
146 | struct ofpbuf *); | |
bd85dac1 | 147 | |
178742f9 BP |
148 | ovs_be64 oxm_bitmap_from_mf_bitmap(const struct mf_bitmap *, enum ofp_version); |
149 | struct mf_bitmap oxm_bitmap_to_mf_bitmap(ovs_be64 oxm_bitmap, | |
150 | enum ofp_version); | |
151 | struct mf_bitmap oxm_writable_fields(void); | |
152 | struct mf_bitmap oxm_matchable_fields(void); | |
153 | struct mf_bitmap oxm_maskable_fields(void); | |
4291acd2 | 154 | |
816fd533 | 155 | /* Dealing with the 'ofs_nbits' members in several Nicira extensions. */ |
c979df05 BP |
156 | |
157 | static inline ovs_be16 | |
158 | nxm_encode_ofs_nbits(int ofs, int n_bits) | |
159 | { | |
160 | return htons((ofs << 6) | (n_bits - 1)); | |
161 | } | |
162 | ||
163 | static inline int | |
164 | nxm_decode_ofs(ovs_be16 ofs_nbits) | |
165 | { | |
166 | return ntohs(ofs_nbits) >> 6; | |
167 | } | |
168 | ||
169 | static inline int | |
170 | nxm_decode_n_bits(ovs_be16 ofs_nbits) | |
171 | { | |
172 | return (ntohs(ofs_nbits) & 0x3f) + 1; | |
173 | } | |
174 | \f | |
2e4f5fcf BP |
175 | /* This is my guess at the length of a "typical" nx_match, for use in |
176 | * predicting space requirements. */ | |
177 | #define NXM_TYPICAL_LEN 64 | |
178 | ||
09246b99 | 179 | #endif /* nx-match.h */ |