Skip to content

Commit

Permalink
ofp-prop: Add helper for parsing and storing of ovs_u128.
Browse files Browse the repository at this point in the history
Add helper methods that allow us to store and parse the
ovs_u128 type.

Signed-off-by: Ales Musil <amusil@redhat.com>
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
  • Loading branch information
almusil authored and igsilya committed Dec 14, 2023
1 parent cc670e7 commit 62c5d32
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/openvswitch/ofp-prop.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,12 @@ enum ofperr ofpprop_pull(struct ofpbuf *msg, struct ofpbuf *property,
enum ofperr ofpprop_parse_be16(const struct ofpbuf *, ovs_be16 *value);
enum ofperr ofpprop_parse_be32(const struct ofpbuf *, ovs_be32 *value);
enum ofperr ofpprop_parse_be64(const struct ofpbuf *, ovs_be64 *value);
enum ofperr ofpprop_parse_be128(const struct ofpbuf *, ovs_be128 *value);
enum ofperr ofpprop_parse_u8(const struct ofpbuf *, uint8_t *value);
enum ofperr ofpprop_parse_u16(const struct ofpbuf *, uint16_t *value);
enum ofperr ofpprop_parse_u32(const struct ofpbuf *, uint32_t *value);
enum ofperr ofpprop_parse_u64(const struct ofpbuf *, uint64_t *value);
enum ofperr ofpprop_parse_u128(const struct ofpbuf *, ovs_u128 *value);
enum ofperr ofpprop_parse_uuid(const struct ofpbuf *, struct uuid *);
enum ofperr ofpprop_parse_nested(const struct ofpbuf *, struct ofpbuf *);

Expand All @@ -98,10 +100,12 @@ void *ofpprop_put_zeros(struct ofpbuf *, uint64_t type, size_t len);
void ofpprop_put_be16(struct ofpbuf *, uint64_t type, ovs_be16 value);
void ofpprop_put_be32(struct ofpbuf *, uint64_t type, ovs_be32 value);
void ofpprop_put_be64(struct ofpbuf *, uint64_t type, ovs_be64 value);
void ofpprop_put_be128(struct ofpbuf *, uint64_t type, ovs_be128 value);
void ofpprop_put_u8(struct ofpbuf *, uint64_t type, uint8_t value);
void ofpprop_put_u16(struct ofpbuf *, uint64_t type, uint16_t value);
void ofpprop_put_u32(struct ofpbuf *, uint64_t type, uint32_t value);
void ofpprop_put_u64(struct ofpbuf *, uint64_t type, uint64_t value);
void ofpprop_put_u128(struct ofpbuf *, uint64_t type, ovs_u128 value);
void ofpprop_put_bitmap(struct ofpbuf *, uint64_t type, uint64_t bitmap);
void ofpprop_put_flag(struct ofpbuf *, uint64_t type);
void ofpprop_put_uuid(struct ofpbuf *, uint64_t type, const struct uuid *);
Expand Down
42 changes: 42 additions & 0 deletions lib/ofp-prop.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,20 @@ ofpprop_parse_be64(const struct ofpbuf *property, ovs_be64 *value)
return 0;
}

/* Attempts to parse 'property' as a property containing a 128-bit value. If
* successful, stores the value into '*value' and returns 0; otherwise returns
* an OpenFlow error. */
enum ofperr
ofpprop_parse_be128(const struct ofpbuf *property, ovs_be128 *value)
{
ovs_be128 *p = property->msg;
if (ofpbuf_msgsize(property) != sizeof *p) {
return OFPERR_OFPBPC_BAD_LEN;
}
*value = *p;
return 0;
}

/* Attempts to parse 'property' as a property containing a 8-bit value. If
* successful, stores the value into '*value' and returns 0; otherwise returns
* an OpenFlow error. */
Expand Down Expand Up @@ -250,6 +264,20 @@ ofpprop_parse_u64(const struct ofpbuf *property, uint64_t *value)
return 0;
}

/* Attempts to parse 'property' as a property containing a 128-bit value. If
* successful, stores the value into '*value' and returns 0; otherwise returns
* an OpenFlow error. */
enum ofperr
ofpprop_parse_u128(const struct ofpbuf *property, ovs_u128 *value)
{
ovs_be128 *p = property->msg;
if (ofpbuf_msgsize(property) != sizeof *p) {
return OFPERR_OFPBPC_BAD_LEN;
}
*value = ntoh128(*p);
return 0;
}

/* Attempts to parse 'property' as a property containing a UUID. If
* successful, stores the value into '*uuid' and returns 0; otherwise returns
* an OpenFlow error. */
Expand Down Expand Up @@ -351,6 +379,13 @@ ofpprop_put_be64(struct ofpbuf *msg, uint64_t type, ovs_be64 value)
ofpprop_end(msg, start);
}

/* Adds a property with the given 'type' and 128-bit 'value' to 'msg'. */
void
ofpprop_put_be128(struct ofpbuf *msg, uint64_t type, ovs_be128 value)
{
ofpprop_put(msg, type, &value, sizeof value);
}

/* Adds a property with the given 'type' and 8-bit 'value' to 'msg'. */
void
ofpprop_put_u8(struct ofpbuf *msg, uint64_t type, uint8_t value)
Expand Down Expand Up @@ -381,6 +416,13 @@ ofpprop_put_u64(struct ofpbuf *msg, uint64_t type, uint64_t value)
ofpprop_put_be64(msg, type, htonll(value));
}

/* Adds a property with the given 'type' and 128-bit 'value' to 'msg'. */
void
ofpprop_put_u128(struct ofpbuf *msg, uint64_t type, ovs_u128 value)
{
ofpprop_put_be128(msg, type, hton128(value));
}

/* Appends a property to 'msg' whose type is 'type' and whose contents is a
* series of property headers, one for each 1-bit in 'bitmap'. */
void
Expand Down

0 comments on commit 62c5d32

Please sign in to comment.