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