[ovs-dev] [PATCH v1 2/3] Vlan Support in ovn, add nbctl commands to set network type
Ankur Sharma
ankur.sharma at nutanix.com
Fri Oct 26 01:39:43 UTC 2018
As a part of proposal for distributed virtual routing
for VLAN networks through OVN, this series has code changes
for Layer 2.
[1] https://mail.openvswitch.org/pipermail/ovs-dev/2018-October/353066.html
[2] https://docs.google.com/document/d/1uoQH478wM1OZ16HrxzbOUvk5LvFnfNEWbkPT6Zmm9OU/edit?usp=sharing
This Series:
a. Changes in OVN NB Schema to introduce a logical switch type.
b. Changes in ovn-nbctl to configure a logical switch type.
c. Changes in ovn-northd to process and save a logical switch type.
Adding a logical switch type would be helpful in following:
a. Debugging, since VLAN backed logical switch is dependent on
localnet ports, hence basic validations like localnet port
configured or not etc., can be done with ease.
b. Helps with Layer 3 implementation
(https://mail.openvswitch.org/pipermail/ovs-dev/2018-October/353179.html).
This Patch:
a. By default set network_type as overlay during ls_add handling.
b. Add a new ovn-nbctl command to set network type of a logical
switch.
ovn-nbctl ls-set-network-type LS_NAME vlan|overlay
c. Display network type along with logical switch, for example:
# ovn-nbctl ls-list
d94d7531-128b-43a2-bff0-56f2aa2ea878 (bar) (type: overlay)
531e6f24-f6ae-4ea3-856d-ac986f900770 (foo) (type: vlan)
d. Unit tests to validate this command
Signed-off-by: Ankur Sharma <ankur.sharma at nutanix.com>
---
ovn/utilities/ovn-nbctl.c | 38 ++++++++++++++++++++++++++++++++++----
tests/ovn-nbctl.at | 40 ++++++++++++++++++++++++++++------------
2 files changed, 62 insertions(+), 16 deletions(-)
diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c
index 75dcb07..68afb5a 100644
--- a/ovn/utilities/ovn-nbctl.c
+++ b/ovn/utilities/ovn-nbctl.c
@@ -971,8 +971,9 @@ print_lr(const struct nbrec_logical_router *lr, struct ds *s)
static void
print_ls(const struct nbrec_logical_switch *ls, struct ds *s)
{
- ds_put_format(s, "switch "UUID_FMT" (%s)",
- UUID_ARGS(&ls->header_.uuid), ls->name);
+ ds_put_format(s, "switch "UUID_FMT" (%s) (type: %s)",
+ UUID_ARGS(&ls->header_.uuid), ls->name,
+ strlen(ls->network_type) ? ls->network_type : "overlay");
print_alias(&ls->external_ids, "neutron:network_name", s);
ds_put_char(s, '\n');
@@ -1111,6 +1112,31 @@ nbctl_ls_add(struct ctl_context *ctx)
if (ls_name) {
nbrec_logical_switch_set_name(ls, ls_name);
}
+
+ nbrec_logical_switch_set_network_type(ls, "overlay");
+}
+
+static void
+nbctl_ls_set_network_type(struct ctl_context *ctx)
+{
+ const char *ls_name = ctx->argv[1];
+ const char *ls_type = ctx->argv[2];
+ const struct nbrec_logical_switch *ls = NULL;
+
+ char *error = ls_by_name_or_uuid(ctx, ls_name, true, &ls);
+
+ if (!ls || error) {
+ ctx->error = error;
+ return;
+ }
+
+ if (strcmp(ls_type, "vlan") && strcmp(ls_type, "overlay")) {
+ ctl_error(ctx, "Invalid type: \"%s\", supported types are \"vlan\" "
+ "and \"overlay\"", ls_type);
+ return;
+ }
+
+ nbrec_logical_switch_set_network_type(ls, ls_type);
}
static void
@@ -1140,8 +1166,10 @@ nbctl_ls_list(struct ctl_context *ctx)
smap_init(&switches);
NBREC_LOGICAL_SWITCH_FOR_EACH(ls, ctx->idl) {
- smap_add_format(&switches, ls->name, UUID_FMT " (%s)",
- UUID_ARGS(&ls->header_.uuid), ls->name);
+ smap_add_format(&switches, ls->name, UUID_FMT " (%s) (type: %s)",
+ UUID_ARGS(&ls->header_.uuid), ls->name,
+ strlen(ls->network_type) ? ls->network_type :
+ "overlay");
}
const struct smap_node **nodes = smap_sort(&switches);
for (size_t i = 0; i < smap_count(&switches); i++) {
@@ -5048,6 +5076,8 @@ static const struct ctl_command_syntax nbctl_commands[] = {
"--may-exist,--add-duplicate", RW },
{ "ls-del", 1, 1, "SWITCH", NULL, nbctl_ls_del, NULL, "--if-exists", RW },
{ "ls-list", 0, 0, "", NULL, nbctl_ls_list, NULL, "", RO },
+ { "ls-set-network-type", 2, 2, "SWITCH TYPE", NULL,
+ nbctl_ls_set_network_type, NULL, "", RW },
/* acl commands. */
{ "acl-add", 5, 6, "{SWITCH | PORTGROUP} DIRECTION PRIORITY MATCH ACTION",
diff --git a/tests/ovn-nbctl.at b/tests/ovn-nbctl.at
index 25414b8..7d07811 100644
--- a/tests/ovn-nbctl.at
+++ b/tests/ovn-nbctl.at
@@ -56,31 +56,31 @@ m4_define([OVN_NBCTL_TEST],
OVN_NBCTL_TEST([ovn_nbctl_basic_switch], [basic switch commands], [
AT_CHECK([ovn-nbctl ls-add ls0])
AT_CHECK([ovn-nbctl ls-list | uuidfilt], [0], [dnl
-<0> (ls0)
+<0> (ls0) (type: overlay)
])
AT_CHECK([ovn-nbctl ls-add ls1])
AT_CHECK([ovn-nbctl ls-list | uuidfilt], [0], [dnl
-<0> (ls0)
-<1> (ls1)
+<0> (ls0) (type: overlay)
+<1> (ls1) (type: overlay)
])
AT_CHECK([ovn-nbctl ls-del ls0])
AT_CHECK([ovn-nbctl ls-list | uuidfilt], [0], [dnl
-<0> (ls1)
+<0> (ls1) (type: overlay)
])
AT_CHECK([ovn-nbctl show ls0])
AT_CHECK([ovn-nbctl ls-add ls0])
AT_CHECK([ovn-nbctl show ls0 | uuidfilt], [0],
- [switch <0> (ls0)
+ [switch <0> (ls0) (type: overlay)
])
AT_CHECK([ovn-nbctl ls-add ls0], [1], [],
[ovn-nbctl: ls0: a switch with this name already exists
])
AT_CHECK([ovn-nbctl --may-exist ls-add ls0])
AT_CHECK([ovn-nbctl show ls0 | uuidfilt], [0],
- [switch <0> (ls0)
+ [switch <0> (ls0) (type: overlay)
])
AT_CHECK([ovn-nbctl --add-duplicate ls-add ls0])
AT_CHECK([ovn-nbctl --may-exist --add-duplicate ls-add ls0], [1], [],
@@ -102,7 +102,23 @@ AT_CHECK([ovn-nbctl --add-duplicate ls-add], [1], [],
])
AT_CHECK([ovn-nbctl --may-exist ls-add], [1], [],
[ovn-nbctl: --may-exist requires specifying a name
-])])
+])
+
+AT_CHECK([ovn-nbctl ls-set-network-type ls1 vlan])
+AT_CHECK([ovn-nbctl show ls1 | uuidfilt], [0],
+ [switch <0> (ls1) (type: vlan)
+])
+
+AT_CHECK([ovn-nbctl ls-set-network-type ls1 overlay])
+AT_CHECK([ovn-nbctl show ls1 | uuidfilt], [0],
+ [switch <0> (ls1) (type: overlay)
+])
+
+AT_CHECK([ovn-nbctl ls-set-network-type ls1 temp], [1], [],
+ [ovn-nbctl: Invalid type: "temp", supported types are "vlan" and "overlay"
+])
+
+])
dnl ---------------------------------------------------------------------
@@ -1411,7 +1427,7 @@ dnl ---------------------------------------------------------------------
OVN_NBCTL_TEST([ovn_nbctl_dry_run_mode], [dry run mode], [
dnl Check that dry run has no permanent effect.
AT_CHECK([ovn-nbctl --dry-run ls-add ls0 -- ls-list | uuidfilt], [0], [dnl
-<0> (ls0)
+<0> (ls0) (type: overlay)
])
AT_CHECK([ovn-nbctl ls-list | uuidfilt], [0], [dnl
])
@@ -1419,7 +1435,7 @@ AT_CHECK([ovn-nbctl ls-list | uuidfilt], [0], [dnl
dnl Check that dry-run mode is not sticky.
AT_CHECK([ovn-nbctl ls-add ls0])
AT_CHECK([ovn-nbctl ls-list | uuidfilt], [0], [dnl
-<0> (ls0)
+<0> (ls0) (type: overlay)
])])
dnl ---------------------------------------------------------------------
@@ -1429,13 +1445,13 @@ AT_CHECK([ovn-nbctl ls-add ls0 -- ls-add ls1])
dnl Expect one line for one command.
AT_CHECK([ovn-nbctl --oneline ls-list | uuidfilt], [0], [dnl
-<0> (ls0)\n<1> (ls1)
+<0> (ls0) (type: overlay)\n<1> (ls1) (type: overlay)
])
dnl Expect lines for two commands.
AT_CHECK([ovn-nbctl --oneline ls-list -- ls-list | uuidfilt], [0], [dnl
-<0> (ls0)\n<1> (ls1)
-<0> (ls0)\n<1> (ls1)
+<0> (ls0) (type: overlay)\n<1> (ls1) (type: overlay)
+<0> (ls0) (type: overlay)\n<1> (ls1) (type: overlay)
])])
dnl ---------------------------------------------------------------------
--
1.8.3.1
More information about the dev
mailing list