Re: [ovs-dev] [PATCH V3] add lrouter and lrport related commands to ovn-nbctl
On Mon, Apr 18, 2016 at 10:04:11AM -0700, ngh...@us.ibm.com wrote: > ovn-nbctl provides a shortcut to perform commands related lswitch, lport > and such but it doesn't have similar commands related to logical routers > and logical router ports. Also, 'ovn-nbctl show' is supposed to show an > overview of database contents, which means it should show the routers > as well. "ovn-nbctl show LSWITCH" shows the switch details, similarly > "ovn-nbctl show LROUTER" should show the router details too. This patch > takes care of all of these. > > Modifications; > 1) ovn-nbctl show -- will now show lrouters as well > 2) ovn-nbctl show -- will show the router now > > New commands added: > 3) ovn-nbctl lrouter-add [LROUTER] > 4) ovn-nbctl lrouter-del LROUTER > 5) ovn-nbctl lrouter-list > 6) lrport-add LROUTER LRPORT > 7) lrport-del LRPORT > 8) lrport-list LROUTER > 9) lrport-set-mac-address LRPORT [ADDRESS] > 10) lrport-get-mac-address LRPORT > 11) lrport-set-enabled LRPORT STATE > 12) lrport-get-enabled LRPORT > > Unit test cases have been added to test all of these modifications and > additions. Thanks for the patch. Please document the new commands in ovn-nbctl.8.xml. ___ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev
[ovs-dev] [PATCH V3] add lrouter and lrport related commands to ovn-nbctl
ovn-nbctl provides a shortcut to perform commands related lswitch, lport and such but it doesn't have similar commands related to logical routers and logical router ports. Also, 'ovn-nbctl show' is supposed to show an overview of database contents, which means it should show the routers as well. "ovn-nbctl show LSWITCH" shows the switch details, similarly "ovn-nbctl show LROUTER" should show the router details too. This patch takes care of all of these. Modifications; 1) ovn-nbctl show -- will now show lrouters as well 2) ovn-nbctl show -- will show the router now New commands added: 3) ovn-nbctl lrouter-add [LROUTER] 4) ovn-nbctl lrouter-del LROUTER 5) ovn-nbctl lrouter-list 6) lrport-add LROUTER LRPORT 7) lrport-del LRPORT 8) lrport-list LROUTER 9) lrport-set-mac-address LRPORT [ADDRESS] 10) lrport-get-mac-address LRPORT 11) lrport-set-enabled LRPORT STATE 12) lrport-get-enabled LRPORT Unit test cases have been added to test all of these modifications and additions. Author: Nirapada GhoshDate: Fri, 8 Apr 2016 18:44:21 -0700 Signed-off-by: Nirapada Ghosh --- diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c index bdad368..6d18005 100644 --- a/ovn/utilities/ovn-nbctl.c +++ b/ovn/utilities/ovn-nbctl.c @@ -290,12 +290,18 @@ usage: %s [OPTIONS] COMMAND [ARG...]\n\ General commands:\n\ show print overview of database contents\n\ show LSWITCH print overview of database contents for LSWITCH\n\ + show LROUTER print overview of database contents for LROUTER\n\ \n\ Logical switch commands:\n\ lswitch-add [LSWITCH] create a logical switch named LSWITCH\n\ lswitch-del LSWITCH delete LSWITCH and all its ports\n\ lswitch-list print the names of all logical switches\n\ \n\ +Logical router commands:\n\ + lrouter-add [LROUTER] create a logical router named LROUTER\n\ + lrouter-del LROUTER delete LROUTER and all its ports\n\ + lrouter-list print the names of all logical routers\n\ +\n\ ACL commands:\n\ acl-add LSWITCH DIRECTION PRIORITY MATCH ACTION [log]\n\ add an ACL to LSWITCH\n\ @@ -303,6 +309,19 @@ ACL commands:\n\ remove ACLs from LSWITCH\n\ acl-list LSWITCH print ACLs for LSWITCH\n\ \n\ +Logical router port commands:\n\ + lrport-add LROUTER LRPORT add logical router port LRPORT to LROUTER\n\ + lrport-del LRPORT delete LRPORT from its attached router\n\ + lrport-list LROUTERprint the names of all logical ports on LROUTER\n\ + lrport-set-mac-address LRPORT [ADDRESS]\n\ +set MAC address for LRPORT.\n\ + lrport-get-mac-address LRPORT get MAC addresses on LRPORT\n\ + lrport-set-enabled LRPORT STATE\n\ +set administrative state LRPORT\n\ +('enabled' or 'disabled')\n\ + lrport-get-enabled LRPORT get administrative state LRPORT\n\ +('enabled' or 'disabled')\n\ +\n\ Logical port commands:\n\ lport-add LSWITCH LPORT add logical port LPORT on LSWITCH\n\ lport-add LSWITCH LPORT PARENT TAG\n\ @@ -349,8 +368,49 @@ Other options:\n\ exit(EXIT_SUCCESS); } + +/* Following function finds out the lrouter given it's id. */ +static const struct nbrec_logical_router * +lrouter_by_name_or_uuid(struct ctl_context *ctx, const char *id, bool silent) +{ +const struct nbrec_logical_router *lrouter = NULL; +bool is_uuid = false; +bool duplicate = false; +struct uuid lrouter_uuid; + +if (uuid_from_string(_uuid, id)) { +is_uuid = true; +lrouter = nbrec_logical_router_get_for_uuid(ctx->idl, +_uuid); +} + +if (!lrouter) { +const struct nbrec_logical_router *iter; + +NBREC_LOGICAL_ROUTER_FOR_EACH(iter, ctx->idl) { +if (strcmp(iter->name, id)) { +continue; +} +if (lrouter) { +VLOG_WARN("There is more than one logical router named '%s'. " +"Use a UUID.", id); +lrouter = NULL; +duplicate = true; +break; +} +lrouter = iter; +} +} + +if (!lrouter && !duplicate && !silent) { +VLOG_WARN("lrouter not found for %s: '%s'", +is_uuid ? "UUID" : "name", id); +} + +return lrouter; +} static const struct nbrec_logical_switch * -lswitch_by_name_or_uuid(struct ctl_context *ctx, const char *id) +lswitch_by_name_or_uuid(struct ctl_context *ctx, const char *id, bool silent) { const struct nbrec_logical_switch *lswitch = NULL; bool is_uuid = false; @@ -381,7 +441,7 @@ lswitch_by_name_or_uuid(struct ctl_context *ctx, const char *id) } } -if (!lswitch && !duplicate) { +if (!lswitch && !duplicate &&
[ovs-dev] [PATCH V3] add lrouter and lrport related commands to ovn-nbctl
ovn-nbctl provides a shortcut to perform commands related lswitch, lport and such but it doesn't have similar commands related to logical routers and logical router ports. Also, 'ovn-nbctl show' is supposed to show an overview of database contents, which means it should show the routers as well. "ovn-nbctl show LSWITCH" shows the switch details, similarly "ovn-nbctl show LROUTER" should show the router details too. This patch takes care of all of these. Modifications; 1) ovn-nbctl show -- will now show lrouters as well 2) ovn-nbctl show -- will show the router now New commands added: 3) ovn-nbctl lrouter-add [LROUTER] 4) ovn-nbctl lrouter-del LROUTER 5) ovn-nbctl lrouter-list 6) lrport-add LROUTER LRPORT 7) lrport-del LRPORT 8) lrport-list LROUTER 9) lrport-set-mac-address LRPORT [ADDRESS] 10) lrport-get-mac-address LRPORT 11) lrport-set-enabled LRPORT STATE 12) lrport-get-enabled LRPORT Unit test cases have been added to test all of these modifications and additions. Author: Nirapada GhoshDate: Fri, 8 Apr 2016 18:44:21 -0700 Signed-off-by: Nirapada Ghosh --- diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c index bdad368..6d18005 100644 --- a/ovn/utilities/ovn-nbctl.c +++ b/ovn/utilities/ovn-nbctl.c @@ -290,12 +290,18 @@ usage: %s [OPTIONS] COMMAND [ARG...]\n\ General commands:\n\ show print overview of database contents\n\ show LSWITCH print overview of database contents for LSWITCH\n\ + show LROUTER print overview of database contents for LROUTER\n\ \n\ Logical switch commands:\n\ lswitch-add [LSWITCH] create a logical switch named LSWITCH\n\ lswitch-del LSWITCH delete LSWITCH and all its ports\n\ lswitch-list print the names of all logical switches\n\ \n\ +Logical router commands:\n\ + lrouter-add [LROUTER] create a logical router named LROUTER\n\ + lrouter-del LROUTER delete LROUTER and all its ports\n\ + lrouter-list print the names of all logical routers\n\ +\n\ ACL commands:\n\ acl-add LSWITCH DIRECTION PRIORITY MATCH ACTION [log]\n\ add an ACL to LSWITCH\n\ @@ -303,6 +309,19 @@ ACL commands:\n\ remove ACLs from LSWITCH\n\ acl-list LSWITCH print ACLs for LSWITCH\n\ \n\ +Logical router port commands:\n\ + lrport-add LROUTER LRPORT add logical router port LRPORT to LROUTER\n\ + lrport-del LRPORT delete LRPORT from its attached router\n\ + lrport-list LROUTERprint the names of all logical ports on LROUTER\n\ + lrport-set-mac-address LRPORT [ADDRESS]\n\ +set MAC address for LRPORT.\n\ + lrport-get-mac-address LRPORT get MAC addresses on LRPORT\n\ + lrport-set-enabled LRPORT STATE\n\ +set administrative state LRPORT\n\ +('enabled' or 'disabled')\n\ + lrport-get-enabled LRPORT get administrative state LRPORT\n\ +('enabled' or 'disabled')\n\ +\n\ Logical port commands:\n\ lport-add LSWITCH LPORT add logical port LPORT on LSWITCH\n\ lport-add LSWITCH LPORT PARENT TAG\n\ @@ -349,8 +368,49 @@ Other options:\n\ exit(EXIT_SUCCESS); } + +/* Following function finds out the lrouter given it's id. */ +static const struct nbrec_logical_router * +lrouter_by_name_or_uuid(struct ctl_context *ctx, const char *id, bool silent) +{ +const struct nbrec_logical_router *lrouter = NULL; +bool is_uuid = false; +bool duplicate = false; +struct uuid lrouter_uuid; + +if (uuid_from_string(_uuid, id)) { +is_uuid = true; +lrouter = nbrec_logical_router_get_for_uuid(ctx->idl, +_uuid); +} + +if (!lrouter) { +const struct nbrec_logical_router *iter; + +NBREC_LOGICAL_ROUTER_FOR_EACH(iter, ctx->idl) { +if (strcmp(iter->name, id)) { +continue; +} +if (lrouter) { +VLOG_WARN("There is more than one logical router named '%s'. " +"Use a UUID.", id); +lrouter = NULL; +duplicate = true; +break; +} +lrouter = iter; +} +} + +if (!lrouter && !duplicate && !silent) { +VLOG_WARN("lrouter not found for %s: '%s'", +is_uuid ? "UUID" : "name", id); +} + +return lrouter; +} static const struct nbrec_logical_switch * -lswitch_by_name_or_uuid(struct ctl_context *ctx, const char *id) +lswitch_by_name_or_uuid(struct ctl_context *ctx, const char *id, bool silent) { const struct nbrec_logical_switch *lswitch = NULL; bool is_uuid = false; @@ -381,7 +441,7 @@ lswitch_by_name_or_uuid(struct ctl_context *ctx, const char *id) } } -if (!lswitch && !duplicate) { +if (!lswitch && !duplicate &&