load->len = htons(sizeof *load);
load->vendor = htonl(NX_VENDOR_ID);
load->subtype = htons(NXAST_REG_LOAD);
- load->ofs_nbits = htons((ofs << 6) | (n_bits - 1));
+ load->ofs_nbits = nxm_encode_ofs_nbits(ofs, n_bits);
load->dst = htonl(dst);
load->value = htonll(value);
}
void
nxm_format_reg_load(const struct nx_action_reg_load *load, struct ds *s)
{
- uint16_t ofs_nbits = ntohs(load->ofs_nbits);
- int ofs = ofs_nbits >> 6;
- int n_bits = (ofs_nbits & 0x3f) + 1;
+ int ofs = nxm_decode_ofs(load->ofs_nbits);
+ int n_bits = nxm_decode_n_bits(load->ofs_nbits);
uint32_t dst = ntohl(load->dst);
uint64_t value = ntohll(load->value);
const struct nxm_field *dst;
int ofs, n_bits;
- ofs = ntohs(action->ofs_nbits) >> 6;
- n_bits = (ntohs(action->ofs_nbits) & 0x3f) + 1;
+ ofs = nxm_decode_ofs(action->ofs_nbits);
+ n_bits = nxm_decode_n_bits(action->ofs_nbits);
dst = nxm_field_lookup(ntohl(action->dst));
if (!field_ok(dst, flow, ofs + n_bits)) {
return BAD_ARGUMENT;
struct flow *flow)
{
/* Preparation. */
- int n_bits = (ntohs(action->ofs_nbits) & 0x3f) + 1;
+ int n_bits = nxm_decode_n_bits(action->ofs_nbits);
uint32_t mask = n_bits == 32 ? UINT32_MAX : (UINT32_C(1) << n_bits) - 1;
uint32_t *reg = &flow->regs[NXM_NX_REG_IDX(ntohl(action->dst))];
uint32_t src_data = ntohll(action->value);
/* Get remaining bits of the destination field. */
- int dst_ofs = ntohs(action->ofs_nbits) >> 6;
+ int dst_ofs = nxm_decode_ofs(action->ofs_nbits);
uint32_t dst_data = *reg & ~(mask << dst_ofs);
*reg = dst_data | (src_data << dst_ofs);
#define NX_MATCH_H 1
#include <stdint.h>
+#include <sys/types.h>
+#include <netinet/in.h>
+#include "openvswitch/types.h"
struct cls_rule;
struct ds;
void nxm_execute_reg_move(const struct nx_action_reg_move *, struct flow *);
void nxm_execute_reg_load(const struct nx_action_reg_load *, struct flow *);
+/* Dealing with the 'ofs_nbits' members of struct nx_action_reg_load and struct
+ * nx_action_multipath. */
+
+static inline ovs_be16
+nxm_encode_ofs_nbits(int ofs, int n_bits)
+{
+ return htons((ofs << 6) | (n_bits - 1));
+}
+
+static inline int
+nxm_decode_ofs(ovs_be16 ofs_nbits)
+{
+ return ntohs(ofs_nbits) >> 6;
+}
+
+static inline int
+nxm_decode_n_bits(ovs_be16 ofs_nbits)
+{
+ return (ntohs(ofs_nbits) & 0x3f) + 1;
+}
+\f
/* Upper bound on the length of an nx_match. The longest nx_match (assuming
* we implement 4 registers) would be:
*