case NX_LEARN_DST_LOAD:
for (ofs = 0; ofs < spec->n_bits; ofs += chunk) {
struct ofpact_reg_load *load;
- ovs_be64 value_be;
chunk = MIN(spec->n_bits - ofs, 64);
load->dst.field = spec->dst.field;
load->dst.ofs = spec->dst.ofs + ofs;
load->dst.n_bits = chunk;
-
- memset(&value_be, 0, sizeof value_be);
- bitwise_copy(&value, sizeof value, ofs,
- &value_be, sizeof value_be, 0,
- chunk);
- load->value = ntohll(value_be);
+ load->subvalue = value;
}
break;
free(orig);
}
-static void
-format_subvalue(const union mf_subvalue *subvalue, struct ds *s)
-{
- int i;
-
- for (i = 0; i < ARRAY_SIZE(subvalue->u8); i++) {
- if (subvalue->u8[i]) {
- ds_put_format(s, "0x%"PRIx8, subvalue->u8[i]);
- for (i++; i < ARRAY_SIZE(subvalue->u8); i++) {
- ds_put_format(s, "%02"PRIx8, subvalue->u8[i]);
- }
- return;
- }
- }
- ds_put_char(s, '0');
-}
-
/* Appends a description of 'learn' to 's', in the format that ovs-ofctl(8)
* describes. */
void
} else {
mf_format_subfield(&spec->dst, s);
ds_put_char(s, '=');
- format_subvalue(&spec->src_imm, s);
+ mf_format_subvalue(&spec->src_imm, s);
}
break;
case NX_LEARN_SRC_IMMEDIATE | NX_LEARN_DST_LOAD:
ds_put_format(s, "load:");
- format_subvalue(&spec->src_imm, s);
+ mf_format_subvalue(&spec->src_imm, s);
ds_put_cstr(s, "->");
mf_format_subfield(&spec->dst, s);
break;
}
}
\f
+/* Makes subfield 'sf' within 'flow' exactly match the 'sf->n_bits'
+ * least-significant bits in 'x'.
+ */
+void
+mf_write_subfield_flow(const struct mf_subfield *sf,
+ const union mf_subvalue *x, struct flow *flow)
+{
+ const struct mf_field *field = sf->field;
+ union mf_value value;
+
+ mf_get_value(field, flow, &value);
+ bitwise_copy(x, sizeof *x, sf->ofs, &value, field->n_bytes,
+ sf->ofs, sf->n_bits);
+ mf_set_flow_value(field, &value, flow);
+}
+
/* Makes subfield 'sf' within 'match' exactly match the 'sf->n_bits'
* least-significant bits in 'x'.
*/
}
return s;
}
+
+void
+mf_format_subvalue(const union mf_subvalue *subvalue, struct ds *s)
+{
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(subvalue->u8); i++) {
+ if (subvalue->u8[i]) {
+ ds_put_format(s, "0x%"PRIx8, subvalue->u8[i]);
+ for (i++; i < ARRAY_SIZE(subvalue->u8); i++) {
+ ds_put_format(s, "%02"PRIx8, subvalue->u8[i]);
+ }
+ return;
+ }
+ }
+ ds_put_char(s, '0');
+}
nxm_parse_reg_load(struct ofpact_reg_load *load, const char *s)
{
const char *full_s = s;
+ uint64_t value = strtoull(s, (char **) &s, 0);
+ ovs_be64 value_be = htonll(value);
- load->value = strtoull(s, (char **) &s, 0);
if (strncmp(s, "->", 2)) {
ovs_fatal(0, "%s: missing `->' following value", full_s);
}
ovs_fatal(0, "%s: trailing garbage following destination", full_s);
}
- if (load->dst.n_bits < 64 && (load->value >> load->dst.n_bits) != 0) {
+ if (load->dst.n_bits < 64 && (value >> load->dst.n_bits) != 0) {
ovs_fatal(0, "%s: value %"PRIu64" does not fit into %d bits",
- full_s, load->value, load->dst.n_bits);
+ full_s, value, load->dst.n_bits);
}
+
+ memset(&load->subvalue, 0, sizeof &load->subvalue);
+ bitwise_copy(&value_be, sizeof value_be, 0,
+ &load->subvalue, sizeof load->subvalue, load->dst.ofs,
+ load->dst.n_bits);
}
\f
/* nxm_format_reg_move(), nxm_format_reg_load(). */
void
nxm_format_reg_load(const struct ofpact_reg_load *load, struct ds *s)
{
- ds_put_format(s, "load:%#"PRIx64"->", load->value);
+ union mf_subvalue right_justified;
+
+ memset(&right_justified, 0, sizeof right_justified);
+ bitwise_copy(&load->subvalue, sizeof load->subvalue, load->dst.ofs,
+ &right_justified, sizeof right_justified, 0,
+ load->dst.n_bits);
+
+ ds_put_cstr(s, "load:");
+ mf_format_subvalue(&right_justified, s);
+ ds_put_cstr(s, "->");
mf_format_subfield(&load->dst, s);
}
\f
load->dst.field = mf_from_nxm_header(ntohl(narl->dst));
load->dst.ofs = nxm_decode_ofs(narl->ofs_nbits);
load->dst.n_bits = nxm_decode_n_bits(narl->ofs_nbits);
- load->value = ntohll(narl->value);
+ memset(&load->subvalue, 0, sizeof &load->subvalue);
+ bitwise_copy(&narl->value, sizeof narl->value, 0,
+ &load->subvalue, sizeof load->subvalue, load->dst.ofs,
+ load->dst.n_bits);
/* Reject 'narl' if a bit numbered 'n_bits' or higher is set to 1 in
* narl->value. */
- if (load->dst.n_bits < 64 && load->value >> load->dst.n_bits) {
+ if (load->dst.n_bits < 64 &&
+ ntohll(narl->value) >> load->dst.n_bits) {
return OFPERR_OFPBAC_BAD_ARGUMENT;
}
narl = ofputil_put_NXAST_REG_LOAD(openflow);
narl->ofs_nbits = nxm_encode_ofs_nbits(load->dst.ofs, load->dst.n_bits);
narl->dst = htonl(load->dst.field->nxm_header);
- narl->value = htonll(load->value);
+ narl->value = htonll(0);
+ bitwise_copy(&load->subvalue, sizeof load->subvalue, load->dst.ofs,
+ &narl->value, sizeof narl->value, 0, load->dst.n_bits);
}
\f
/* nxm_execute_reg_move(), nxm_execute_reg_load(). */
void
nxm_execute_reg_load(const struct ofpact_reg_load *load, struct flow *flow)
{
- nxm_reg_load(&load->dst, load->value, flow);
+ mf_write_subfield_flow(&load->dst, &load->subvalue, flow);
}
void
nxm_reg_load(const struct mf_subfield *dst, uint64_t src_data,
struct flow *flow)
{
- union mf_value dst_value;
- union mf_value src_value;
+ union mf_subvalue src_subvalue;
+ ovs_be64 src_data_be = htonll(src_data);
- mf_get_value(dst->field, flow, &dst_value);
- src_value.be64 = htonll(src_data);
- bitwise_copy(&src_value, sizeof src_value.be64, 0,
- &dst_value, dst->field->n_bytes, dst->ofs,
- dst->n_bits);
- mf_set_flow_value(dst->field, &dst_value, flow);
+ bitwise_copy(&src_data_be, sizeof src_data_be, 0,
+ &src_subvalue, sizeof src_subvalue, 0,
+ sizeof src_data_be * 8);
+ mf_write_subfield_flow(dst, &src_subvalue, flow);
}