2 * Copyright (c) 2014, 2015, 2016 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.
20 /* OpenFlow 1.3+ property support
21 * ==============================
23 * Several OpenFlow 1.3+ messages use type-length-value (TLV) properties that
24 * take the common form shown by "struct ofp_prop_header". This module
25 * provides support for serializing and deserializing properties in this
32 * This module uses uint64_t values to identify property types
34 * - OpenFlow assigns 16-bit type values to its own standardized
35 * properties. ofpprop uses these values directly in uint64_t.
37 * The 16-bit value 0xffff (and for some kinds of properties 0xfffe) is
38 * reserved as a kind of escape to introduce an "experimenter" property
41 * - Vendor-specific "experimenter" properties have a 32-bit "experimenter
42 * ID" (generally an Ethernet OUI) and a 32-bit experimenter-defined
43 * "exp_type". ofpprop encodes these with the experimenter ID in the
44 * high 32 bits and exp_type in the low 32 bits. (All existing
45 * experimenter IDs are nonzero, so this is unambiguous.) Use
46 * OFPPROP_EXP to encode these property types.
52 #include "ofp-errors.h"
53 #include "openvswitch/types.h"
58 /* Given an OpenFlow experimenter ID (e.g. NX_VENDOR_ID) 'exp_id' and type
59 * 'exp_type', yields the code that ofpprop_pull() would use to identify the
60 * given experimenter property. */
61 #define OFPPROP_EXP(EXP_ID, EXP_TYPE) \
62 (((uint64_t) (EXP_ID) << 32) | (EXP_TYPE))
64 /* Returns true if 'type' represents an experimenter property type,
65 * false if it represents a standard property type.*/
67 ofpprop_is_experimenter(uint64_t type)
69 return type > UINT16_MAX;
72 /* Deserializing properties. */
73 enum ofperr ofpprop_pull__(struct ofpbuf *msg, struct ofpbuf *property,
74 unsigned int alignment, unsigned int min_exp,
76 enum ofperr ofpprop_pull(struct ofpbuf *msg, struct ofpbuf *property,
79 enum ofperr ofpprop_parse_be16(const struct ofpbuf *, ovs_be16 *value);
80 enum ofperr ofpprop_parse_be32(const struct ofpbuf *, ovs_be32 *value);
81 enum ofperr ofpprop_parse_u16(const struct ofpbuf *, uint16_t *value);
82 enum ofperr ofpprop_parse_u32(const struct ofpbuf *, uint32_t *value);
84 /* Serializing properties. */
85 void ofpprop_put(struct ofpbuf *, uint64_t type,
86 const void *value, size_t len);
87 void ofpprop_put_be16(struct ofpbuf *, uint64_t type, ovs_be16 value);
88 void ofpprop_put_be32(struct ofpbuf *, uint64_t type, ovs_be32 value);
89 void ofpprop_put_u16(struct ofpbuf *, uint64_t type, uint16_t value);
90 void ofpprop_put_u32(struct ofpbuf *, uint64_t type, uint32_t value);
91 void ofpprop_put_bitmap(struct ofpbuf *, uint64_t type, uint64_t bitmap);
93 size_t ofpprop_start(struct ofpbuf *, uint64_t type);
94 void ofpprop_end(struct ofpbuf *, size_t start_ofs);
96 /* Logging errors while deserializing properties.
98 * The attitude that a piece of code should take when it deserializes an
99 * unknown property type depends on the code in question:
101 * - In a "loose" context (with LOOSE set to true), that is, where the code
102 * is parsing the property to find out about the state or the capabilities
103 * of some piece of the system, generally an unknown property type is not
104 * a big deal, because it only means that there is additional information
105 * that the receiver does not understand.
107 * - In a "strict" context (with LOOSE set to false), that is, where the
108 * code is parsing the property to change the state or configuration of a
109 * part of the system, generally an unknown property type is an error,
110 * because it means that the receiver is being asked to configure the
111 * system in some way it doesn't understand.
113 * Given LOOSE, this macro automatically logs chooses an appropriate log
115 #define OFPPROP_LOG(RL, LOOSE, ...) \
116 VLOG_RL(RL, (LOOSE) ? VLL_DBG : VLL_WARN, __VA_ARGS__)
118 enum ofperr ofpprop_unknown(struct vlog_module *, bool loose, const char *msg,
120 #define OFPPROP_UNKNOWN(LOOSE, MSG, TYPE) \
121 ofpprop_unknown(THIS_MODULE, LOOSE, MSG, TYPE)
123 #endif /* ofp-prop.h */