}
return def;
}
+
+/* l3gateway, chassisredirect, and patch
+ * are not in this list since they are
+ * only set in the SB DB by northd
+ */
+static const char *OVN_NB_LSP_TYPES[] = {
+ "l2gateway",
+ "localnet",
+ "localport",
+ "router",
+ "vtep",
+};
+
+bool
+ovn_is_known_nb_lsp_type(const char *type)
+{
+ int i;
+
+ if (!type || !type[0]) {
+ return true;
+ }
+
+ for (i = 0; i < ARRAY_SIZE(OVN_NB_LSP_TYPES); ++i) {
+ if (!strcmp(OVN_NB_LSP_TYPES[i], type)) {
+ return true;
+ }
+ }
+
+ return false;
+}
}
sbrec_port_binding_set_options(op->sb, &options);
smap_destroy(&options);
- sbrec_port_binding_set_type(op->sb, op->nbsp->type);
+ if (ovn_is_known_nb_lsp_type(op->nbsp->type)) {
+ sbrec_port_binding_set_type(op->sb, op->nbsp->type);
+ } else {
+ static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
+ VLOG_WARN_RL(
+ &rl, "Unknown port type '%s' set on logical switch '%s'.",
+ op->nbsp->type, op->nbsp->name);
+ }
} else {
const char *chassis = NULL;
if (op->peer && op->peer->od && op->peer->od->nbr) {
const struct nbrec_logical_switch_port *lsp;
lsp = lsp_by_name_or_uuid(ctx, id, true);
- nbrec_logical_switch_port_set_type(lsp, type);
+ if (ovn_is_known_nb_lsp_type(type)) {
+ nbrec_logical_switch_port_set_type(lsp, type);
+ } else {
+ ctl_fatal("Logical switch port type '%s' is unrecognized. "
+ "Not setting type.", type);
+ }
}
static void
OVN_NBCTL_TEST_STOP
AT_CLEANUP
+
+dnl ---------------------------------------------------------------------
+
+AT_SETUP([ovn-nbctl - lsp types])
+OVN_NBCTL_TEST_START
+
+AT_CHECK([ovn-nbctl ls-add ls0])
+AT_CHECK([ovn-nbctl lsp-add ls0 lp0])
+
+dnl switchport type defaults to empty
+AT_CHECK([ovn-nbctl lsp-get-type lp0], [0], [dnl
+
+])
+
+dnl The following are the valid entries for
+dnl switchport type
+AT_CHECK([ovn-nbctl lsp-set-type lp0 l2gateway])
+AT_CHECK([ovn-nbctl lsp-get-type lp0], [0], [dnl
+l2gateway
+])
+
+AT_CHECK([ovn-nbctl lsp-set-type lp0 router])
+AT_CHECK([ovn-nbctl lsp-get-type lp0], [0], [dnl
+router
+])
+
+AT_CHECK([ovn-nbctl lsp-set-type lp0 localnet])
+AT_CHECK([ovn-nbctl lsp-get-type lp0], [0], [dnl
+localnet
+])
+
+AT_CHECK([ovn-nbctl lsp-set-type lp0 localport])
+AT_CHECK([ovn-nbctl lsp-get-type lp0], [0], [dnl
+localport
+])
+
+AT_CHECK([ovn-nbctl lsp-set-type lp0 vtep])
+AT_CHECK([ovn-nbctl lsp-get-type lp0], [0], [dnl
+vtep
+])
+
+dnl All of these are valid southbound port types but
+dnl should be rejected for northbound logical switch
+dnl ports.
+AT_CHECK([ovn-nbctl lsp-set-type lp0 l3gateway], [1], [], [dnl
+ovn-nbctl: Logical switch port type 'l3gateway' is unrecognized. Not setting type.
+])
+AT_CHECK([ovn-nbctl lsp-set-type lp0 patch], [1], [], [dnl
+ovn-nbctl: Logical switch port type 'patch' is unrecognized. Not setting type.
+])
+AT_CHECK([ovn-nbctl lsp-set-type lp0 chassisredirect], [1], [], [dnl
+ovn-nbctl: Logical switch port type 'chassisredirect' is unrecognized. Not setting type.
+])
+
+dnl switch port type should still be "vtep" since previous
+dnl commands failed.
+AT_CHECK([ovn-nbctl lsp-get-type lp0], [0], [dnl
+vtep
+])
+
+dnl Attempt a nonsense type
+AT_CHECK([ovn-nbctl lsp-set-type lp0 eggs], [1], [], [dnl
+ovn-nbctl: Logical switch port type 'eggs' is unrecognized. Not setting type.
+])
+
+dnl Empty string should work too
+AT_CHECK([ovn-nbctl lsp-set-type lp0 ""])
+AT_CHECK([ovn-nbctl lsp-get-type lp0], [0], [dnl
+
+])
+
+OVN_NBCTL_TEST_STOP
+AT_CLEANUP