Setting tag sliver-openvswitch-2.2.90-1
[sliver-openvswitch.git] / lib / nx-match.h
1 /*
2  * Copyright (c) 2010, 2011, 2012, 2013, 2014 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 "ofp-errors.h"
26 #include "openvswitch/types.h"
27
28 struct ds;
29 struct match;
30 struct mf_field;
31 struct mf_subfield;
32 struct ofpact_reg_move;
33 struct ofpact_reg_load;
34 struct ofpact_stack;
35 struct ofpbuf;
36 struct nx_action_reg_load;
37 struct nx_action_reg_move;
38
39
40 /* Nicira Extended Match (NXM) flexible flow match helper functions.
41  *
42  * See include/openflow/nicira-ext.h for NXM specification.
43  */
44
45 enum ofperr nx_pull_match(struct ofpbuf *, unsigned int match_len,
46                           struct match *,
47                           ovs_be64 *cookie, ovs_be64 *cookie_mask);
48 enum ofperr nx_pull_match_loose(struct ofpbuf *, unsigned int match_len,
49                                 struct match *, ovs_be64 *cookie,
50                                 ovs_be64 *cookie_mask);
51 enum ofperr oxm_pull_match(struct ofpbuf *, struct match *);
52 enum ofperr oxm_pull_match_loose(struct ofpbuf *, struct match *);
53 int nx_put_match(struct ofpbuf *, const struct match *,
54                  ovs_be64 cookie, ovs_be64 cookie_mask);
55 int oxm_put_match(struct ofpbuf *, const struct match *);
56
57 char *nx_match_to_string(const uint8_t *, unsigned int match_len);
58 char *oxm_match_to_string(const struct ofpbuf *, unsigned int match_len);
59 int nx_match_from_string(const char *, struct ofpbuf *);
60 int oxm_match_from_string(const char *, struct ofpbuf *);
61
62 char *nxm_parse_reg_move(struct ofpact_reg_move *, const char *)
63     WARN_UNUSED_RESULT;
64 char *nxm_parse_reg_load(struct ofpact_reg_load *, const char *)
65     WARN_UNUSED_RESULT;
66
67 void nxm_format_reg_move(const struct ofpact_reg_move *, struct ds *);
68 void nxm_format_reg_load(const struct ofpact_reg_load *, struct ds *);
69
70 enum ofperr nxm_reg_move_from_openflow(const struct nx_action_reg_move *,
71                                        struct ofpbuf *ofpacts);
72 enum ofperr nxm_reg_load_from_openflow(const struct nx_action_reg_load *,
73                                        struct ofpbuf *ofpacts);
74
75 enum ofperr nxm_reg_move_check(const struct ofpact_reg_move *,
76                                const struct flow *);
77 enum ofperr nxm_reg_load_check(const struct ofpact_reg_load *,
78                                const struct flow *);
79
80 void nxm_reg_move_to_nxast(const struct ofpact_reg_move *,
81                            struct ofpbuf *openflow);
82 void nxm_reg_load_to_nxast(const struct ofpact_reg_load *,
83                            struct ofpbuf *openflow);
84
85 void nxm_execute_reg_move(const struct ofpact_reg_move *, struct flow *,
86                           struct flow_wildcards *);
87 void nxm_execute_reg_load(const struct ofpact_reg_load *, struct flow *,
88                           struct flow_wildcards *);
89 void nxm_reg_load(const struct mf_subfield *, uint64_t src_data,
90                   struct flow *, struct flow_wildcards *);
91
92 char *nxm_parse_stack_action(struct ofpact_stack *, const char *)
93     WARN_UNUSED_RESULT;
94
95 void nxm_format_stack_push(const struct ofpact_stack *, struct ds *);
96 void nxm_format_stack_pop(const struct ofpact_stack *, struct ds *);
97
98 enum ofperr nxm_stack_push_from_openflow(const struct nx_action_stack *,
99                                        struct ofpbuf *ofpacts);
100 enum ofperr nxm_stack_pop_from_openflow(const struct nx_action_stack *,
101                                        struct ofpbuf *ofpacts);
102 enum ofperr nxm_stack_push_check(const struct ofpact_stack *,
103                                  const  struct flow *);
104 enum ofperr nxm_stack_pop_check(const struct ofpact_stack *,
105                                const struct flow *);
106
107 void nxm_stack_push_to_nxast(const struct ofpact_stack *,
108                            struct ofpbuf *openflow);
109 void nxm_stack_pop_to_nxast(const struct ofpact_stack *,
110                            struct ofpbuf *openflow);
111
112 void nxm_execute_stack_push(const struct ofpact_stack *,
113                             const struct flow *, struct flow_wildcards *,
114                             struct ofpbuf *);
115 void nxm_execute_stack_pop(const struct ofpact_stack *,
116                             struct flow *, struct flow_wildcards *,
117                             struct ofpbuf *);
118
119 int nxm_field_bytes(uint32_t header);
120 int nxm_field_bits(uint32_t header);
121
122 /* Dealing with the 'ofs_nbits' members in several Nicira extensions. */
123
124 static inline ovs_be16
125 nxm_encode_ofs_nbits(int ofs, int n_bits)
126 {
127     return htons((ofs << 6) | (n_bits - 1));
128 }
129
130 static inline int
131 nxm_decode_ofs(ovs_be16 ofs_nbits)
132 {
133     return ntohs(ofs_nbits) >> 6;
134 }
135
136 static inline int
137 nxm_decode_n_bits(ovs_be16 ofs_nbits)
138 {
139     return (ntohs(ofs_nbits) & 0x3f) + 1;
140 }
141 \f
142 /* This is my guess at the length of a "typical" nx_match, for use in
143  * predicting space requirements. */
144 #define NXM_TYPICAL_LEN 64
145
146 #endif /* nx-match.h */