]> git.proxmox.com Git - ovs.git/blob - lib/nx-match.h
nicira-ext: Increase the number of NXM registers to 8.
[ovs.git] / lib / nx-match.h
1 /*
2 * Copyright (c) 2010, 2011, 2012 Nicira Networks.
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 "flow.h"
24 #include "openvswitch/types.h"
25 #include "ofp-errors.h"
26
27 struct cls_rule;
28 struct ds;
29 struct flow;
30 struct mf_subfield;
31 struct ofpbuf;
32 struct nx_action_reg_load;
33 struct nx_action_reg_move;
34
35 /* Nicira Extended Match (NXM) flexible flow match helper functions.
36 *
37 * See include/openflow/nicira-ext.h for NXM specification.
38 */
39
40 enum ofperr nx_pull_match(struct ofpbuf *, unsigned int match_len,
41 uint16_t priority, struct cls_rule *,
42 ovs_be64 *cookie, ovs_be64 *cookie_mask);
43 enum ofperr nx_pull_match_loose(struct ofpbuf *, unsigned int match_len,
44 uint16_t priority, struct cls_rule *,
45 ovs_be64 *cookie, ovs_be64 *cookie_mask);
46 int nx_put_match(struct ofpbuf *, const struct cls_rule *,
47 ovs_be64 cookie, ovs_be64 cookie_mask);
48
49 char *nx_match_to_string(const uint8_t *, unsigned int match_len);
50 int nx_match_from_string(const char *, struct ofpbuf *);
51
52 void nxm_parse_reg_move(struct nx_action_reg_move *, const char *);
53 void nxm_parse_reg_load(struct nx_action_reg_load *, const char *);
54
55 void nxm_format_reg_move(const struct nx_action_reg_move *, struct ds *);
56 void nxm_format_reg_load(const struct nx_action_reg_load *, struct ds *);
57
58 enum ofperr nxm_check_reg_move(const struct nx_action_reg_move *,
59 const struct flow *);
60 enum ofperr nxm_check_reg_load(const struct nx_action_reg_load *,
61 const struct flow *);
62
63 void nxm_execute_reg_move(const struct nx_action_reg_move *, struct flow *);
64 void nxm_execute_reg_load(const struct nx_action_reg_load *, struct flow *);
65
66 int nxm_field_bytes(uint32_t header);
67 int nxm_field_bits(uint32_t header);
68
69 /* Dealing with the 'ofs_nbits' members in several Nicira extensions. */
70
71 static inline ovs_be16
72 nxm_encode_ofs_nbits(int ofs, int n_bits)
73 {
74 return htons((ofs << 6) | (n_bits - 1));
75 }
76
77 static inline int
78 nxm_decode_ofs(ovs_be16 ofs_nbits)
79 {
80 return ntohs(ofs_nbits) >> 6;
81 }
82
83 static inline int
84 nxm_decode_n_bits(ovs_be16 ofs_nbits)
85 {
86 return (ntohs(ofs_nbits) & 0x3f) + 1;
87 }
88
89 void nxm_decode(struct mf_subfield *, ovs_be32 header, ovs_be16 ofs_nbits);
90 void nxm_decode_discrete(struct mf_subfield *, ovs_be32 header,
91 ovs_be16 ofs, ovs_be16 n_bits);
92 \f
93 BUILD_ASSERT_DECL(FLOW_WC_SEQ == 9);
94 /* Upper bound on the length of an nx_match. The longest nx_match (an
95 * IPV6 neighbor discovery message using 5 registers) would be:
96 *
97 * header value mask total
98 * ------ ----- ---- -----
99 * NXM_OF_IN_PORT 4 2 -- 6
100 * NXM_OF_ETH_DST_W 4 6 6 16
101 * NXM_OF_ETH_SRC 4 6 -- 10
102 * NXM_OF_ETH_TYPE 4 2 -- 6
103 * NXM_OF_VLAN_TCI 4 2 2 8
104 * NXM_OF_IP_TOS 4 1 -- 5
105 * NXM_NX_IP_ECN 4 1 -- 5
106 * NXM_OF_IP_TTL 4 1 -- 5
107 * NXM_NX_IP_FRAG 4 1 1 8
108 * NXM_OF_IP_PROTO 4 2 -- 6
109 * NXM_OF_IPV6_SRC_W 4 16 16 36
110 * NXM_OF_IPV6_DST_W 4 16 16 36
111 * NXM_OF_IPV6_LABEL 4 4 -- 8
112 * NXM_OF_ICMP_TYPE 4 1 -- 5
113 * NXM_OF_ICMP_CODE 4 1 -- 5
114 * NXM_NX_ND_TARGET 4 16 -- 20
115 * NXM_NX_ND_SLL 4 6 -- 10
116 * NXM_NX_REG_W(0) 4 4 4 12
117 * NXM_NX_REG_W(1) 4 4 4 12
118 * NXM_NX_REG_W(2) 4 4 4 12
119 * NXM_NX_REG_W(3) 4 4 4 12
120 * NXM_NX_REG_W(4) 4 4 4 12
121 * NXM_NX_REG_W(5) 4 4 4 12
122 * NXM_NX_REG_W(6) 4 4 4 12
123 * NXM_NX_REG_W(7) 4 4 4 12
124 * NXM_NX_TUN_ID_W 4 8 8 20
125 * -------------------------------------------
126 * total 311
127 *
128 * So this value is conservative.
129 */
130 #define NXM_MAX_LEN 384
131
132 /* This is my guess at the length of a "typical" nx_match, for use in
133 * predicting space requirements. */
134 #define NXM_TYPICAL_LEN 64
135
136 #endif /* nx-match.h */