2 * Copyright (c) 2010 Nicira Networks.
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>
23 #include "openvswitch/types.h"
29 struct nx_action_reg_load;
30 struct nx_action_reg_move;
32 /* Nicira Extended Match (NXM) flexible flow match helper functions.
34 * See include/openflow/nicira-ext.h for NXM specification.
37 int nx_pull_match(struct ofpbuf *, unsigned int match_len, uint16_t priority,
39 int nx_put_match(struct ofpbuf *, const struct cls_rule *);
41 char *nx_match_to_string(const uint8_t *, unsigned int match_len);
42 int nx_match_from_string(const char *, struct ofpbuf *);
44 uint64_t nxm_read_field_bits(ovs_be32 header, ovs_be16 ofs_nbits,
47 void nxm_parse_reg_move(struct nx_action_reg_move *, const char *);
48 void nxm_parse_reg_load(struct nx_action_reg_load *, const char *);
50 void nxm_format_reg_move(const struct nx_action_reg_move *, struct ds *);
51 void nxm_format_reg_load(const struct nx_action_reg_load *, struct ds *);
53 int nxm_check_reg_move(const struct nx_action_reg_move *, const struct flow *);
54 int nxm_check_reg_load(const struct nx_action_reg_load *, const struct flow *);
55 int nxm_src_check(ovs_be32 src, unsigned int ofs, unsigned int n_bits,
57 int nxm_dst_check(ovs_be32 dst, unsigned int ofs, unsigned int n_bits,
60 void nxm_execute_reg_move(const struct nx_action_reg_move *, struct flow *);
61 void nxm_execute_reg_load(const struct nx_action_reg_load *, struct flow *);
62 void nxm_reg_load(ovs_be32 dst, ovs_be16 ofs_nbits, uint64_t src_data,
65 int nxm_field_bytes(uint32_t header);
66 int nxm_field_bits(uint32_t header);
68 const char *nxm_parse_field_bits(const char *s,
69 uint32_t *headerp, int *ofsp, int *n_bitsp);
70 void nxm_format_field_bits(struct ds *, uint32_t header, int ofs, int n_bits);
72 /* Dealing with the 'ofs_nbits' members of struct nx_action_reg_load and struct
73 * nx_action_multipath. */
75 static inline ovs_be16
76 nxm_encode_ofs_nbits(int ofs, int n_bits)
78 return htons((ofs << 6) | (n_bits - 1));
82 nxm_decode_ofs(ovs_be16 ofs_nbits)
84 return ntohs(ofs_nbits) >> 6;
88 nxm_decode_n_bits(ovs_be16 ofs_nbits)
90 return (ntohs(ofs_nbits) & 0x3f) + 1;
93 /* Upper bound on the length of an nx_match. The longest nx_match (assuming
94 * we implement 4 registers) would be:
96 * header value mask total
97 * ------ ----- ---- -----
98 * NXM_OF_IN_PORT 4 2 -- 6
99 * NXM_OF_ETH_DST_W 4 6 6 16
100 * NXM_OF_ETH_SRC 4 6 -- 10
101 * NXM_OF_ETH_TYPE 4 2 -- 6
102 * NXM_OF_VLAN_TCI 4 2 2 8
103 * NXM_OF_IP_TOS 4 1 -- 5
104 * NXM_OF_IP_PROTO 4 2 -- 6
105 * NXM_OF_IPV6_SRC_W 4 16 16 36
106 * NXM_OF_IPV6_DST_W 4 16 16 36
107 * NXM_OF_ICMP_TYPE 4 1 -- 5
108 * NXM_OF_ICMP_CODE 4 1 -- 5
109 * NXM_NX_ND_TARGET 4 16 -- 20
110 * NXM_NX_ND_SLL 4 6 -- 10
111 * NXM_NX_REG_W(0) 4 4 4 12
112 * NXM_NX_REG_W(1) 4 4 4 12
113 * NXM_NX_REG_W(2) 4 4 4 12
114 * NXM_NX_REG_W(3) 4 4 4 12
115 * NXM_NX_TUN_ID_W 4 8 8 20
116 * -------------------------------------------
119 * So this value is conservative.
121 #define NXM_MAX_LEN 256
123 /* This is my guess at the length of a "typical" nx_match, for use in
124 * predicting space requirements. */
125 #define NXM_TYPICAL_LEN 64
127 #endif /* nx-match.h */