Skip to content

Commit

Permalink
ovn-nbctl.c: Add an optional way to delete QoS by uuid
Browse files Browse the repository at this point in the history
We can delete qos by specify ls and more parameters.
If CMS want to delete it exactly, it must specify detailed "match" field.
It's not an easy way, also maybe deleted by mistake.
This change adds a way to specify ls and uuid, which is optional.
You can still use the previous method to delete.

usage:
ovn-nbctl qos-del ls0 [UUID0]

Author: Tao YunXiang <taoyunxiang@cmss.chinamobile.com>
Co-authored-by: Liu Chang <liuchang@cmss.chinamobile.com>
Co-authored-by: Rong Yin <rongyin@cmss.chinamobile.com>
Signed-off-by: Tao YunXiang <taoyunxiang@cmss.chinamobile.com>
Signed-off-by: Liu Chang <liuchang@cmss.chinamobile.com>
Signed-off-by: Rong Yin <rongyin@cmss.chinamobile.com>
Signed-off-by: Numan Siddique <numans@ovn.org>
  • Loading branch information
3 people authored and numansiddique committed May 12, 2020
1 parent c24920d commit 3aca9a5
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 19 deletions.
7 changes: 5 additions & 2 deletions tests/ovn-nbctl.at
Original file line number Diff line number Diff line change
Expand Up @@ -308,13 +308,16 @@ AT_CHECK([ovn-nbctl qos-list ls0], [0], [dnl

AT_CHECK([ovn-nbctl qos-add ls0 from-lport 600 ip rate=1000101])
AT_CHECK([ovn-nbctl qos-add ls0 from-lport 400 tcp dscp=44])
AT_CHECK([ovn-nbctl qos-add ls0 from-lport 200 ip burst=1000102 rate=301 dscp=19])

dnl Delete a single flow.
AT_CHECK([ovn-nbctl qos-del ls0 from-lport 400 tcp])
AT_CHECK([ovn-nbctl qos-list ls0], [0], [dnl
from-lport 600 (ip) rate=1000101
from-lport 200 (ip) rate=301 burst=1000102 dscp=19
])

dnl Delete QoS rule by specified uuid
AT_CHECK([ovn-nbctl qos-del ls0 $(ovn-nbctl --bare --column _uuid list qos)])
AT_CHECK([ovn-nbctl list qos], [0], [dnl
])

AT_CHECK([ovn-nbctl qos-add ls0 from-lport 600 ip rate=100010111111], [1], [],
Expand Down
19 changes: 13 additions & 6 deletions utilities/ovn-nbctl.8.xml
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,19 @@

<dt><code>qos-del</code> <var>switch</var> [<var>direction</var> [<var>priority</var> <var>match</var>]]</dt>
<dd>
Deletes QoS rules from <var>switch</var>. If only
<var>switch</var> is supplied, all the QoS rules from the logical
switch are deleted. If <var>direction</var> is also specified,
then all the flows in that direction will be deleted from the
logical switch. If all the fields are supplied, then a single
flow that matches the given fields will be deleted.
<p>
Deletes QoS rules from <var>switch</var>. If only
<var>switch</var> is supplied, all the QoS rules from the logical
switch are deleted. If <var>direction</var> is also specified,
then all the flows in that direction will be deleted from the
logical switch. If all the fields are supplied, then a single
flow that matches the given fields will be deleted.
</p>

<p>
If <var>switch</var> and <var>uuid</var> are supplied, then the
QoS rule with sepcified uuid is deleted.
</p>
</dd>

<dt><code>qos-list</code> <var>switch</var></dt>
Expand Down
43 changes: 32 additions & 11 deletions utilities/ovn-nbctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ ACL commands:\n\
QoS commands:\n\
qos-add SWITCH DIRECTION PRIORITY MATCH [rate=RATE [burst=BURST]] [dscp=DSCP]\n\
add an QoS rule to SWITCH\n\
qos-del SWITCH [DIRECTION [PRIORITY MATCH]]\n\
qos-del SWITCH [{DIRECTION | UUID} [PRIORITY MATCH]]\n\
remove QoS rules from SWITCH\n\
qos-list SWITCH print QoS rules for SWITCH\n\
\n\
Expand Down Expand Up @@ -2526,22 +2526,43 @@ nbctl_qos_del(struct ctl_context *ctx)
}

const char *direction;
error = parse_direction(ctx->argv[2], &direction);
if (error) {
ctx->error = error;
return;
const struct uuid *qos_rule_uuid = NULL;
struct uuid uuid_from_cmd;
if (uuid_from_string(&uuid_from_cmd, ctx->argv[2])) {
qos_rule_uuid = &uuid_from_cmd;
} else {
error = parse_direction(ctx->argv[2], &direction);
if (error) {
ctx->error = error;
return;
}
}

/* If priority and match are not specified, delete all qos_rules with the
* specified direction. */
/* If uuid was specified, delete qos_rule with the
* specified uuid. */
if (ctx->argc == 3) {
struct nbrec_qos **new_qos_rules
= xmalloc(sizeof *new_qos_rules * ls->n_qos_rules);

int n_qos_rules = 0;
for (size_t i = 0; i < ls->n_qos_rules; i++) {
if (strcmp(direction, ls->qos_rules[i]->direction)) {
new_qos_rules[n_qos_rules++] = ls->qos_rules[i];
if (qos_rule_uuid) {
for (size_t i = 0; i < ls->n_qos_rules; i++) {
if (!uuid_equals(qos_rule_uuid,
&(ls->qos_rules[i]->header_.uuid))) {
new_qos_rules[n_qos_rules++] = ls->qos_rules[i];
}
}
if (n_qos_rules == ls->n_qos_rules) {
ctl_error(ctx, "uuid is not found");
}

/* If priority and match are not specified, delete all qos_rules
* with the specified direction. */
} else {
for (size_t i = 0; i < ls->n_qos_rules; i++) {
if (strcmp(direction, ls->qos_rules[i]->direction)) {
new_qos_rules[n_qos_rules++] = ls->qos_rules[i];
}
}
}

Expand Down Expand Up @@ -6149,7 +6170,7 @@ static const struct ctl_command_syntax nbctl_commands[] = {
{ "qos-add", 5, 7,
"SWITCH DIRECTION PRIORITY MATCH [rate=RATE [burst=BURST]] [dscp=DSCP]",
NULL, nbctl_qos_add, NULL, "--may-exist", RW },
{ "qos-del", 1, 4, "SWITCH [DIRECTION [PRIORITY MATCH]]", NULL,
{ "qos-del", 1, 4, "SWITCH [{DIRECTION | UUID} [PRIORITY MATCH]]", NULL,
nbctl_qos_del, NULL, "", RW },
{ "qos-list", 1, 1, "SWITCH", NULL, nbctl_qos_list, NULL, "", RO },

Expand Down

0 comments on commit 3aca9a5

Please sign in to comment.