/*
- * Copyright (c) 2011, 2012, 2013, 2014 Nicira, Inc.
+ * Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include "learn.h"
#include "byte-order.h"
-#include "dynamic-string.h"
-#include "match.h"
-#include "meta-flow.h"
+#include "colors.h"
#include "nx-match.h"
-#include "ofp-actions.h"
-#include "ofp-errors.h"
-#include "ofp-util.h"
-#include "ofpbuf.h"
#include "openflow/openflow.h"
+#include "openvswitch/dynamic-string.h"
+#include "openvswitch/match.h"
+#include "openvswitch/meta-flow.h"
+#include "openvswitch/ofp-actions.h"
+#include "openvswitch/ofp-errors.h"
+#include "openvswitch/ofp-util.h"
+#include "openvswitch/ofpbuf.h"
#include "unaligned.h"
case NX_LEARN_DST_OUTPUT:
if (spec->n_bits <= 16
|| is_all_zeros(value.u8, sizeof value - 2)) {
- ovs_be16 *last_be16 = &value.be16[ARRAY_SIZE(value.be16) - 1];
- ofp_port_t port = u16_to_ofp(ntohs(*last_be16));
+ ofp_port_t port = u16_to_ofp(ntohll(value.integer));
if (ofp_to_u16(port) < ofp_to_u16(OFPP_MAX)
|| port == OFPP_IN_PORT
break;
}
}
- ofpact_pad(ofpacts);
- fm->ofpacts = ofpbuf_data(ofpacts);
- fm->ofpacts_len = ofpbuf_size(ofpacts);
+ fm->ofpacts = ofpacts->data;
+ fm->ofpacts_len = ofpacts->size;
}
/* Perform a bitwise-OR on 'wc''s fields that are relevant as sources in
/* Returns NULL if successful, otherwise a malloc()'d string describing the
* error. The caller is responsible for freeing the returned string. */
-static char * WARN_UNUSED_RESULT
+static char * OVS_WARN_UNUSED_RESULT
learn_parse_load_immediate(const char *s, struct ofpact_learn_spec *spec)
{
const char *full_s = s;
- const char *arrow = strstr(s, "->");
struct mf_subfield dst;
union mf_subvalue imm;
char *error;
+ int err;
- memset(&imm, 0, sizeof imm);
- if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X') && arrow) {
- const char *in = arrow - 1;
- uint8_t *out = imm.u8 + sizeof imm.u8 - 1;
- int n = arrow - (s + 2);
- int i;
-
- for (i = 0; i < n; i++) {
- int hexit = hexit_value(in[-i]);
- if (hexit < 0) {
- return xasprintf("%s: bad hex digit in value", full_s);
- }
- out[-(i / 2)] |= i % 2 ? hexit << 4 : hexit;
- }
- s = arrow;
- } else {
- ovs_be64 *last_be64 = &imm.be64[ARRAY_SIZE(imm.be64) - 1];
- *last_be64 = htonll(strtoull(s, (char **) &s, 0));
+ err = parse_int_string(s, imm.u8, sizeof imm.u8, (char **) &s);
+ if (err) {
+ return xasprintf("%s: too many bits in immediate value", full_s);
}
if (strncmp(s, "->", 2)) {
/* Returns NULL if successful, otherwise a malloc()'d string describing the
* error. The caller is responsible for freeing the returned string. */
-static char * WARN_UNUSED_RESULT
+static char * OVS_WARN_UNUSED_RESULT
learn_parse_spec(const char *orig, char *name, char *value,
struct ofpact_learn_spec *spec)
{
/* Returns NULL if successful, otherwise a malloc()'d string describing the
* error. The caller is responsible for freeing the returned string. */
-static char * WARN_UNUSED_RESULT
+static char * OVS_WARN_UNUSED_RESULT
learn_parse__(char *orig, char *arg, struct ofpbuf *ofpacts)
{
struct ofpact_learn *learn;
char *error;
spec = ofpbuf_put_zeros(ofpacts, sizeof *spec);
- learn = ofpacts->frame;
+ learn = ofpacts->header;
learn->n_specs++;
error = learn_parse_spec(orig, name, value, spec);
}
}
}
- ofpact_update_len(ofpacts, &learn->ofpact);
+ ofpact_finish_LEARN(ofpacts, &learn);
return NULL;
}
* the action's arguments.
*
* Modifies 'arg'. */
-char * WARN_UNUSED_RESULT
+char * OVS_WARN_UNUSED_RESULT
learn_parse(char *arg, struct ofpbuf *ofpacts)
{
char *orig = xstrdup(arg);
match_init_catchall(&match);
- ds_put_format(s, "learn(table=%"PRIu8, learn->table_id);
+ ds_put_format(s, "%slearn(%s%stable=%s%"PRIu8,
+ colors.learn, colors.end, colors.special, colors.end,
+ learn->table_id);
if (learn->idle_timeout != OFP_FLOW_PERMANENT) {
- ds_put_format(s, ",idle_timeout=%"PRIu16, learn->idle_timeout);
+ ds_put_format(s, ",%sidle_timeout=%s%"PRIu16,
+ colors.param, colors.end, learn->idle_timeout);
}
if (learn->hard_timeout != OFP_FLOW_PERMANENT) {
- ds_put_format(s, ",hard_timeout=%"PRIu16, learn->hard_timeout);
+ ds_put_format(s, ",%shard_timeout=%s%"PRIu16,
+ colors.param, colors.end, learn->hard_timeout);
}
if (learn->fin_idle_timeout) {
- ds_put_format(s, ",fin_idle_timeout=%"PRIu16, learn->fin_idle_timeout);
+ ds_put_format(s, ",%sfin_idle_timeout=%s%"PRIu16,
+ colors.param, colors.end, learn->fin_idle_timeout);
}
if (learn->fin_hard_timeout) {
- ds_put_format(s, ",fin_hard_timeout=%"PRIu16, learn->fin_hard_timeout);
+ ds_put_format(s, "%s,fin_hard_timeout=%s%"PRIu16,
+ colors.param, colors.end, learn->fin_hard_timeout);
}
if (learn->priority != OFP_DEFAULT_PRIORITY) {
- ds_put_format(s, ",priority=%"PRIu16, learn->priority);
+ ds_put_format(s, "%s,priority=%s%"PRIu16,
+ colors.special, colors.end, learn->priority);
}
if (learn->flags & NX_LEARN_F_SEND_FLOW_REM) {
- ds_put_cstr(s, ",send_flow_rem");
+ ds_put_format(s, ",%ssend_flow_rem%s", colors.value, colors.end);
}
if (learn->flags & NX_LEARN_F_DELETE_LEARNED) {
- ds_put_cstr(s, ",delete_learned");
+ ds_put_format(s, ",%sdelete_learned%s", colors.value, colors.end);
}
if (learn->cookie != 0) {
- ds_put_format(s, ",cookie=%#"PRIx64, ntohll(learn->cookie));
+ ds_put_format(s, ",%scookie=%s%#"PRIx64,
+ colors.param, colors.end, ntohll(learn->cookie));
}
for (spec = learn->specs; spec < &learn->specs[learn->n_specs]; spec++) {
bitwise_copy(&spec->src_imm, sizeof spec->src_imm, 0,
&value, spec->dst.field->n_bytes, 0,
spec->dst.field->n_bits);
- ds_put_format(s, "%s=", spec->dst.field->name);
+ ds_put_format(s, "%s%s=%s", colors.param,
+ spec->dst.field->name, colors.end);
mf_format(spec->dst.field, &value, NULL, s);
} else {
+ ds_put_format(s, "%s", colors.param);
mf_format_subfield(&spec->dst, s);
- ds_put_char(s, '=');
+ ds_put_format(s, "=%s", colors.end);
mf_format_subvalue(&spec->src_imm, s);
}
break;
case NX_LEARN_SRC_FIELD | NX_LEARN_DST_MATCH:
+ ds_put_format(s, "%s", colors.param);
mf_format_subfield(&spec->dst, s);
+ ds_put_format(s, "%s", colors.end);
if (spec->src.field != spec->dst.field ||
spec->src.ofs != spec->dst.ofs) {
- ds_put_char(s, '=');
+ ds_put_format(s, "%s=%s", colors.param, colors.end);
mf_format_subfield(&spec->src, s);
}
break;
case NX_LEARN_SRC_IMMEDIATE | NX_LEARN_DST_LOAD:
- ds_put_format(s, "load:");
+ ds_put_format(s, "%sload:%s", colors.special, colors.end);
mf_format_subvalue(&spec->src_imm, s);
- ds_put_cstr(s, "->");
+ ds_put_format(s, "%s->%s", colors.special, colors.end);
mf_format_subfield(&spec->dst, s);
break;
case NX_LEARN_SRC_FIELD | NX_LEARN_DST_LOAD:
- ds_put_cstr(s, "load:");
+ ds_put_format(s, "%sload:%s", colors.special, colors.end);
mf_format_subfield(&spec->src, s);
- ds_put_cstr(s, "->");
+ ds_put_format(s, "%s->%s", colors.special, colors.end);
mf_format_subfield(&spec->dst, s);
break;
case NX_LEARN_SRC_FIELD | NX_LEARN_DST_OUTPUT:
- ds_put_cstr(s, "output:");
+ ds_put_format(s, "%soutput:%s", colors.special, colors.end);
mf_format_subfield(&spec->src, s);
break;
}
}
- ds_put_char(s, ')');
+ ds_put_format(s, "%s)%s", colors.learn, colors.end);
}