Branch data Line data Source code
1 : : /*
2 : : * Copyright (c) 2010, 2011, 2012, 2013, 2014, 2016 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 NX_MATCH_H
18 : : #define NX_MATCH_H 1
19 : :
20 : : #include <stdint.h>
21 : : #include <sys/types.h>
22 : : #include <netinet/in.h>
23 : : #include "compiler.h"
24 : : #include "flow.h"
25 : : #include "openvswitch/meta-flow.h"
26 : : #include "openvswitch/ofp-errors.h"
27 : : #include "openvswitch/types.h"
28 : :
29 : : struct ds;
30 : : struct match;
31 : : struct ofpact_reg_move;
32 : : struct ofpact_reg_load;
33 : : struct ofpact_stack;
34 : : struct ofpbuf;
35 : : struct nx_action_reg_load;
36 : : struct nx_action_reg_move;
37 : :
38 : :
39 : : /* Nicira Extended Match (NXM) flexible flow match helper functions.
40 : : *
41 : : * See include/openflow/nicira-ext.h for NXM specification.
42 : : */
43 : :
44 : : void mf_format_subfield(const struct mf_subfield *, struct ds *);
45 : : char *mf_parse_subfield__(struct mf_subfield *sf, const char **s)
46 : : OVS_WARN_UNUSED_RESULT;
47 : : char *mf_parse_subfield(struct mf_subfield *, const char *s)
48 : : OVS_WARN_UNUSED_RESULT;
49 : :
50 : : /* Decoding matches. */
51 : : enum ofperr nx_pull_match(struct ofpbuf *, unsigned int match_len,
52 : : struct match *,
53 : : ovs_be64 *cookie, ovs_be64 *cookie_mask);
54 : : enum ofperr nx_pull_match_loose(struct ofpbuf *, unsigned int match_len,
55 : : struct match *, ovs_be64 *cookie,
56 : : ovs_be64 *cookie_mask);
57 : : enum ofperr oxm_pull_match(struct ofpbuf *, struct match *);
58 : : enum ofperr oxm_pull_match_loose(struct ofpbuf *, struct match *);
59 : : enum ofperr oxm_decode_match(const void *, size_t, struct match *);
60 : : enum ofperr oxm_pull_field_array(const void *, size_t fields_len,
61 : : struct field_array *);
62 : :
63 : : /* Encoding matches. */
64 : : int nx_put_match(struct ofpbuf *, const struct match *,
65 : : ovs_be64 cookie, ovs_be64 cookie_mask);
66 : : int oxm_put_match(struct ofpbuf *, const struct match *, enum ofp_version);
67 : : void oxm_put_raw(struct ofpbuf *, const struct match *, enum ofp_version);
68 : : void oxm_format_field_array(struct ds *, const struct field_array *);
69 : : int oxm_put_field_array(struct ofpbuf *, const struct field_array *,
70 : : enum ofp_version version);
71 : :
72 : : /* Decoding and encoding OXM/NXM headers (just a field ID) or entries (a field
73 : : * ID followed by a value and possibly a mask). */
74 : : enum ofperr nx_pull_entry(struct ofpbuf *, const struct mf_field **,
75 : : union mf_value *value, union mf_value *mask);
76 : : enum ofperr nx_pull_header(struct ofpbuf *, const struct mf_field **,
77 : : bool *masked);
78 : : void nxm_put__(struct ofpbuf *b, enum mf_field_id field,
79 : : enum ofp_version version, const void *value,
80 : : const void *mask, size_t n_bytes);
81 : : void nx_put_entry(struct ofpbuf *, enum mf_field_id, enum ofp_version,
82 : : const union mf_value *value, const union mf_value *mask);
83 : : void nx_put_header(struct ofpbuf *, enum mf_field_id, enum ofp_version,
84 : : bool masked);
85 : :
86 : : /* NXM and OXM protocol headers values.
87 : : *
88 : : * These are often alternatives to nx_pull_entry/header() and
89 : : * nx_put_entry/header() for decoding and encoding OXM/NXM. In those cases,
90 : : * the nx_*() functions should be preferred because they can support the 64-bit
91 : : * "experimenter" OXM format (even though it is not yet implemented). */
92 : : uint32_t mf_nxm_header(enum mf_field_id);
93 : : const struct mf_field *mf_from_nxm_header(uint32_t nxm_header);
94 : :
95 : : char *nx_match_to_string(const uint8_t *, unsigned int match_len);
96 : : char *oxm_match_to_string(const struct ofpbuf *, unsigned int match_len);
97 : : int nx_match_from_string(const char *, struct ofpbuf *);
98 : : int oxm_match_from_string(const char *, struct ofpbuf *);
99 : :
100 : : void nx_format_field_name(enum mf_field_id, enum ofp_version, struct ds *);
101 : :
102 : : char *nxm_parse_reg_move(struct ofpact_reg_move *, const char *)
103 : : OVS_WARN_UNUSED_RESULT;
104 : :
105 : : void nxm_format_reg_move(const struct ofpact_reg_move *, struct ds *);
106 : :
107 : : enum ofperr nxm_reg_move_check(const struct ofpact_reg_move *,
108 : : const struct flow *);
109 : :
110 : : void nxm_reg_load(const struct mf_subfield *, uint64_t src_data,
111 : : struct flow *, struct flow_wildcards *);
112 : :
113 : : char *nxm_parse_stack_action(struct ofpact_stack *, const char *)
114 : : OVS_WARN_UNUSED_RESULT;
115 : :
116 : : void nxm_format_stack_push(const struct ofpact_stack *, struct ds *);
117 : : void nxm_format_stack_pop(const struct ofpact_stack *, struct ds *);
118 : :
119 : : enum ofperr nxm_stack_push_check(const struct ofpact_stack *,
120 : : const struct flow *);
121 : : enum ofperr nxm_stack_pop_check(const struct ofpact_stack *,
122 : : const struct flow *);
123 : :
124 : : void nxm_execute_stack_push(const struct ofpact_stack *,
125 : : const struct flow *, struct flow_wildcards *,
126 : : struct ofpbuf *);
127 : : void nxm_execute_stack_pop(const struct ofpact_stack *,
128 : : struct flow *, struct flow_wildcards *,
129 : : struct ofpbuf *);
130 : :
131 : : ovs_be64 oxm_bitmap_from_mf_bitmap(const struct mf_bitmap *, enum ofp_version);
132 : : struct mf_bitmap oxm_bitmap_to_mf_bitmap(ovs_be64 oxm_bitmap,
133 : : enum ofp_version);
134 : : struct mf_bitmap oxm_writable_fields(void);
135 : : struct mf_bitmap oxm_matchable_fields(void);
136 : : struct mf_bitmap oxm_maskable_fields(void);
137 : :
138 : : /* Dealing with the 'ofs_nbits' members in several Nicira extensions. */
139 : :
140 : : static inline ovs_be16
141 : 22283 : nxm_encode_ofs_nbits(int ofs, int n_bits)
142 : : {
143 : 22283 : return htons((ofs << 6) | (n_bits - 1));
144 : : }
145 : :
146 : : static inline int
147 : 17688 : nxm_decode_ofs(ovs_be16 ofs_nbits)
148 : : {
149 : 17688 : return ntohs(ofs_nbits) >> 6;
150 : : }
151 : :
152 : : static inline int
153 : 17688 : nxm_decode_n_bits(ovs_be16 ofs_nbits)
154 : : {
155 : 17688 : return (ntohs(ofs_nbits) & 0x3f) + 1;
156 : : }
157 : :
158 : : /* This is my guess at the length of a "typical" nx_match, for use in
159 : : * predicting space requirements. */
160 : : #define NXM_TYPICAL_LEN 64
161 : :
162 : : #endif /* nx-match.h */
|