]> git.proxmox.com Git - mirror_ovs.git/blame - lib/nx-match.h
netdev: Take responsibility for polling MII registers.
[mirror_ovs.git] / lib / nx-match.h
CommitLineData
09246b99
BP
1/*
2 * Copyright (c) 2010 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>
c979df05
BP
21#include <sys/types.h>
22#include <netinet/in.h>
23#include "openvswitch/types.h"
09246b99
BP
24
25struct cls_rule;
f393f81e 26struct ds;
b6c9e612 27struct flow;
09246b99 28struct ofpbuf;
b6c9e612
BP
29struct nx_action_reg_load;
30struct nx_action_reg_move;
09246b99
BP
31
32/* Nicira Extended Match (NXM) flexible flow match helper functions.
33 *
34 * See include/openflow/nicira-ext.h for NXM specification.
35 */
36
37int nx_pull_match(struct ofpbuf *, unsigned int match_len, uint16_t priority,
38 struct cls_rule *);
39int nx_put_match(struct ofpbuf *, const struct cls_rule *);
40
41char *nx_match_to_string(const uint8_t *, unsigned int match_len);
42int nx_match_from_string(const char *, struct ofpbuf *);
43
f393f81e
BP
44void nxm_parse_reg_move(struct nx_action_reg_move *, const char *);
45void nxm_parse_reg_load(struct nx_action_reg_load *, const char *);
46
47void nxm_format_reg_move(const struct nx_action_reg_move *, struct ds *);
48void nxm_format_reg_load(const struct nx_action_reg_load *, struct ds *);
49
b6c9e612
BP
50int nxm_check_reg_move(const struct nx_action_reg_move *, const struct flow *);
51int nxm_check_reg_load(const struct nx_action_reg_load *, const struct flow *);
52
53void nxm_execute_reg_move(const struct nx_action_reg_move *, struct flow *);
54void nxm_execute_reg_load(const struct nx_action_reg_load *, struct flow *);
55
4291acd2
BP
56int nxm_field_bytes(uint32_t header);
57int nxm_field_bits(uint32_t header);
58
36b4c892
BP
59const char *nxm_parse_field_bits(const char *s,
60 uint32_t *headerp, int *ofsp, int *n_bitsp);
61void nxm_format_field_bits(struct ds *, uint32_t header, int ofs, int n_bits);
62
c979df05
BP
63/* Dealing with the 'ofs_nbits' members of struct nx_action_reg_load and struct
64 * nx_action_multipath. */
65
66static inline ovs_be16
67nxm_encode_ofs_nbits(int ofs, int n_bits)
68{
69 return htons((ofs << 6) | (n_bits - 1));
70}
71
72static inline int
73nxm_decode_ofs(ovs_be16 ofs_nbits)
74{
75 return ntohs(ofs_nbits) >> 6;
76}
77
78static inline int
79nxm_decode_n_bits(ovs_be16 ofs_nbits)
80{
81 return (ntohs(ofs_nbits) & 0x3f) + 1;
82}
83\f
09246b99
BP
84/* Upper bound on the length of an nx_match. The longest nx_match (assuming
85 * we implement 4 registers) would be:
86 *
87 * header value mask total
88 * ------ ----- ---- -----
89 * NXM_OF_IN_PORT 4 2 -- 6
90 * NXM_OF_ETH_DST_W 4 6 6 16
91 * NXM_OF_ETH_SRC 4 6 -- 10
92 * NXM_OF_ETH_TYPE 4 2 -- 6
93 * NXM_OF_VLAN_TCI 4 2 2 8
94 * NXM_OF_IP_TOS 4 1 -- 5
95 * NXM_OF_IP_PROTO 4 2 -- 6
d31f1109
JP
96 * NXM_OF_IPV6_SRC_W 4 16 16 36
97 * NXM_OF_IPV6_DST_W 4 16 16 36
685a51a5
JP
98 * NXM_OF_ICMP_TYPE 4 1 -- 5
99 * NXM_OF_ICMP_CODE 4 1 -- 5
100 * NXM_NX_ND_TARGET 4 16 -- 20
101 * NXM_NX_ND_SLL 4 6 -- 10
09246b99
BP
102 * NXM_NX_REG_W(0) 4 4 4 12
103 * NXM_NX_REG_W(1) 4 4 4 12
104 * NXM_NX_REG_W(2) 4 4 4 12
105 * NXM_NX_REG_W(3) 4 4 4 12
106 * NXM_NX_TUN_ID_W 4 8 8 20
107 * -------------------------------------------
685a51a5 108 * total 237
09246b99
BP
109 *
110 * So this value is conservative.
111 */
d31f1109 112#define NXM_MAX_LEN 256
09246b99 113
2e4f5fcf
BP
114/* This is my guess at the length of a "typical" nx_match, for use in
115 * predicting space requirements. */
116#define NXM_TYPICAL_LEN 64
117
09246b99 118#endif /* nx-match.h */