2 * Copyright (c) 2010, 2011, 2012 Nicira, Inc.
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <sys/types.h>
22 #include <netinet/in.h>
24 #include "ofp-errors.h"
25 #include "openvswitch/types.h"
30 struct ofpact_reg_move;
31 struct ofpact_reg_load;
34 struct nx_action_reg_load;
35 struct nx_action_reg_move;
38 /* Nicira Extended Match (NXM) flexible flow match helper functions.
40 * See include/openflow/nicira-ext.h for NXM specification.
43 enum ofperr nx_pull_match(struct ofpbuf *, unsigned int match_len,
45 ovs_be64 *cookie, ovs_be64 *cookie_mask);
46 enum ofperr nx_pull_match_loose(struct ofpbuf *, unsigned int match_len,
47 struct match *, ovs_be64 *cookie,
48 ovs_be64 *cookie_mask);
49 enum ofperr oxm_pull_match(struct ofpbuf *, struct match *);
50 enum ofperr oxm_pull_match_loose(struct ofpbuf *, struct match *);
51 int nx_put_match(struct ofpbuf *, const struct match *,
52 ovs_be64 cookie, ovs_be64 cookie_mask);
53 int oxm_put_match(struct ofpbuf *, const struct match *);
55 char *nx_match_to_string(const uint8_t *, unsigned int match_len);
56 char *oxm_match_to_string(const uint8_t *, unsigned int match_len);
57 int nx_match_from_string(const char *, struct ofpbuf *);
58 int oxm_match_from_string(const char *, struct ofpbuf *);
60 void nxm_parse_reg_move(struct ofpact_reg_move *, const char *);
61 void nxm_parse_reg_load(struct ofpact_reg_load *, const char *);
63 void nxm_format_reg_move(const struct ofpact_reg_move *, struct ds *);
64 void nxm_format_reg_load(const struct ofpact_reg_load *, struct ds *);
66 enum ofperr nxm_reg_move_from_openflow(const struct nx_action_reg_move *,
67 struct ofpbuf *ofpacts);
68 enum ofperr nxm_reg_load_from_openflow(const struct nx_action_reg_load *,
69 struct ofpbuf *ofpacts);
70 enum ofperr nxm_reg_load_from_openflow12_set_field(
71 const struct ofp12_action_set_field * oasf, struct ofpbuf *ofpacts);
73 enum ofperr nxm_reg_move_check(const struct ofpact_reg_move *,
75 enum ofperr nxm_reg_load_check(const struct ofpact_reg_load *,
78 void nxm_reg_move_to_nxast(const struct ofpact_reg_move *,
79 struct ofpbuf *openflow);
80 void nxm_reg_load_to_nxast(const struct ofpact_reg_load *,
81 struct ofpbuf *openflow);
83 void nxm_execute_reg_move(const struct ofpact_reg_move *, struct flow *,
84 struct flow_wildcards *);
85 void nxm_execute_reg_load(const struct ofpact_reg_load *, struct flow *);
86 void nxm_reg_load(const struct mf_subfield *, uint64_t src_data,
89 void nxm_parse_stack_action(struct ofpact_stack *, const char *);
91 void nxm_format_stack_push(const struct ofpact_stack *, struct ds *);
92 void nxm_format_stack_pop(const struct ofpact_stack *, struct ds *);
94 enum ofperr nxm_stack_push_from_openflow(const struct nx_action_stack *,
95 struct ofpbuf *ofpacts);
96 enum ofperr nxm_stack_pop_from_openflow(const struct nx_action_stack *,
97 struct ofpbuf *ofpacts);
98 enum ofperr nxm_stack_push_check(const struct ofpact_stack *,
100 enum ofperr nxm_stack_pop_check(const struct ofpact_stack *,
101 const struct flow *);
103 void nxm_stack_push_to_nxast(const struct ofpact_stack *,
104 struct ofpbuf *openflow);
105 void nxm_stack_pop_to_nxast(const struct ofpact_stack *,
106 struct ofpbuf *openflow);
108 void nxm_execute_stack_push(const struct ofpact_stack *,
109 const struct flow *, struct flow_wildcards *,
111 void nxm_execute_stack_pop(const struct ofpact_stack *,
112 struct flow *, struct ofpbuf *);
114 int nxm_field_bytes(uint32_t header);
115 int nxm_field_bits(uint32_t header);
117 /* Dealing with the 'ofs_nbits' members in several Nicira extensions. */
119 static inline ovs_be16
120 nxm_encode_ofs_nbits(int ofs, int n_bits)
122 return htons((ofs << 6) | (n_bits - 1));
126 nxm_decode_ofs(ovs_be16 ofs_nbits)
128 return ntohs(ofs_nbits) >> 6;
132 nxm_decode_n_bits(ovs_be16 ofs_nbits)
134 return (ntohs(ofs_nbits) & 0x3f) + 1;
137 /* This is my guess at the length of a "typical" nx_match, for use in
138 * predicting space requirements. */
139 #define NXM_TYPICAL_LEN 64
141 #endif /* nx-match.h */