mirror of
https://github.com/openvswitch/ovs
synced 2025-08-31 14:25:26 +00:00
ovs-ofctl: Avoid unnecessary flow replacement in "replace-flows" command.
The ovs-ofctl "diff-flows" and "replace-flows" command compare the flows
in two flow tables. Until now, the "replace-flows" command has considered
certain almost meaningless differences related to the version of OpenFlow
used to add a flow as significant, which caused it to replace a flow by an
identical-in-practice version, e.g. in the following, the "replace-flows"
command prints a FLOW_MOD that adds the flow that was already added
previously:
$ cat > flows
actions=resubmit(,1)
$ ovs-vsctl add-br br0
$ ovs-ofctl del-flows br0
$ ovs-ofctl add-flows br0 flows
$ ovs-ofctl -vvconn replace-flows br0 flows 2>&1 | grep FLOW_MOD
Re-adding an existing flow has some effects, for example, it resets the
flow's duration, so it's better to avoid it.
This commit fixes the problem using the same trick previously used for a
similar problem with the "diff-flows" command, which was fixed in commit
98f7f427bf
("ovs-ofctl: Avoid printing false differences on "ovs-ofctl
diff-flows".").
Reported-by: Kevin Lin <kevin@quilt.io>
Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Andy Zhou <azhou@ovn.org>
This commit is contained in:
@@ -8662,6 +8662,8 @@ ofpacts_output_to_group(const struct ofpact *ofpacts, size_t ofpacts_len,
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Returns true if the 'a_len' bytes of actions in 'a' and the 'b_len' bytes of
|
||||
* actions in 'b' are bytewise identical. */
|
||||
bool
|
||||
ofpacts_equal(const struct ofpact *a, size_t a_len,
|
||||
const struct ofpact *b, size_t b_len)
|
||||
@@ -8669,6 +8671,28 @@ ofpacts_equal(const struct ofpact *a, size_t a_len,
|
||||
return a_len == b_len && !memcmp(a, b, a_len);
|
||||
}
|
||||
|
||||
/* Returns true if the 'a_len' bytes of actions in 'a' and the 'b_len' bytes of
|
||||
* actions in 'b' are identical when formatted as strings. (Converting actions
|
||||
* to string form suppresses some rarely meaningful differences, such as the
|
||||
* 'compat' member of actions.) */
|
||||
bool
|
||||
ofpacts_equal_stringwise(const struct ofpact *a, size_t a_len,
|
||||
const struct ofpact *b, size_t b_len)
|
||||
{
|
||||
struct ds a_s = DS_EMPTY_INITIALIZER;
|
||||
struct ds b_s = DS_EMPTY_INITIALIZER;
|
||||
|
||||
ofpacts_format(a, a_len, NULL, &a_s);
|
||||
ofpacts_format(b, b_len, NULL, &b_s);
|
||||
|
||||
bool equal = !strcmp(ds_cstr(&a_s), ds_cstr(&b_s));
|
||||
|
||||
ds_destroy(&a_s);
|
||||
ds_destroy(&b_s);
|
||||
|
||||
return equal;
|
||||
}
|
||||
|
||||
/* Finds the OFPACT_METER action, if any, in the 'ofpacts_len' bytes of
|
||||
* 'ofpacts'. If found, returns its meter ID; if not, returns 0.
|
||||
*
|
||||
|
Reference in New Issue
Block a user