Committed by
Gerrit Code Review
[ONOS-2828] add router service cli
Change-Id: I633c5c9e4ac51cac2f7dc327aeb35713a201fd74
Showing
5 changed files
with
363 additions
and
0 deletions
| 1 | +/* | ||
| 2 | + * Copyright 2015 Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | +package org.onosproject.vtnrsc.cli.router; | ||
| 17 | + | ||
| 18 | +import java.util.ArrayList; | ||
| 19 | +import java.util.List; | ||
| 20 | +import java.util.Set; | ||
| 21 | + | ||
| 22 | +import org.apache.karaf.shell.commands.Argument; | ||
| 23 | +import org.apache.karaf.shell.commands.Command; | ||
| 24 | +import org.apache.karaf.shell.commands.Option; | ||
| 25 | +import org.onosproject.cli.AbstractShellCommand; | ||
| 26 | +import org.onosproject.vtnrsc.DefaultRouter; | ||
| 27 | +import org.onosproject.vtnrsc.Router; | ||
| 28 | +import org.onosproject.vtnrsc.Router.Status; | ||
| 29 | +import org.onosproject.vtnrsc.RouterId; | ||
| 30 | +import org.onosproject.vtnrsc.TenantId; | ||
| 31 | +import org.onosproject.vtnrsc.VirtualPortId; | ||
| 32 | +import org.onosproject.vtnrsc.router.RouterService; | ||
| 33 | + | ||
| 34 | +import com.google.common.collect.Sets; | ||
| 35 | + | ||
| 36 | +/** | ||
| 37 | + * Supports for create a router. | ||
| 38 | + */ | ||
| 39 | +@Command(scope = "onos", name = "router-create", | ||
| 40 | + description = "Supports for creating a router") | ||
| 41 | +public class RouterCreateCommand extends AbstractShellCommand { | ||
| 42 | + @Argument(index = 0, name = "id", description = "The router identifier", | ||
| 43 | + required = true, multiValued = false) | ||
| 44 | + String id = null; | ||
| 45 | + | ||
| 46 | + @Argument(index = 1, name = "routerName", description = "The name of router", | ||
| 47 | + required = true, multiValued = false) | ||
| 48 | + String routerName = null; | ||
| 49 | + | ||
| 50 | + @Argument(index = 2, name = "tenantId", description = "The tenant identifier of router", | ||
| 51 | + required = true, multiValued = false) | ||
| 52 | + String tenantId = null; | ||
| 53 | + | ||
| 54 | + @Option(name = "-g", aliases = "--gatewayPortId", description = "The gatewayPort identifier of router", | ||
| 55 | + required = false, multiValued = false) | ||
| 56 | + String gatewayPortId = null; | ||
| 57 | + | ||
| 58 | + @Option(name = "-e", aliases = "--externalGatewayInfo", description = "The external gateway info of router", | ||
| 59 | + required = false, multiValued = false) | ||
| 60 | + String externalGatewayInfo = null; | ||
| 61 | + | ||
| 62 | + @Option(name = "-s", aliases = "--status", description = "The status of router", | ||
| 63 | + required = false, multiValued = false) | ||
| 64 | + String status = null; | ||
| 65 | + | ||
| 66 | + @Option(name = "-a", aliases = "--adminStateUp", description = "The boolean adminStateUp of router", | ||
| 67 | + required = false, multiValued = false) | ||
| 68 | + boolean adminStateUp = true; | ||
| 69 | + | ||
| 70 | + @Option(name = "-d", aliases = "--distributed", description = "The boolean distributed of router", | ||
| 71 | + required = false, multiValued = false) | ||
| 72 | + boolean distributed = false; | ||
| 73 | + | ||
| 74 | + @Override | ||
| 75 | + protected void execute() { | ||
| 76 | + RouterService service = get(RouterService.class); | ||
| 77 | + try { | ||
| 78 | + List<String> routes = new ArrayList<String>(); | ||
| 79 | + Router router = new DefaultRouter( | ||
| 80 | + RouterId.valueOf(id), | ||
| 81 | + routerName, | ||
| 82 | + adminStateUp, | ||
| 83 | + status == null ? Status.ACTIVE | ||
| 84 | + : Status.valueOf(status), | ||
| 85 | + distributed, | ||
| 86 | + null, | ||
| 87 | + VirtualPortId.portId(gatewayPortId), | ||
| 88 | + TenantId.tenantId(tenantId), | ||
| 89 | + routes); | ||
| 90 | + Set<Router> routerSet = Sets.newHashSet(router); | ||
| 91 | + service.createRouters(routerSet); | ||
| 92 | + } catch (Exception e) { | ||
| 93 | + print(null, e.getMessage()); | ||
| 94 | + } | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | +} |
| 1 | +/* | ||
| 2 | + * Copyright 2015 Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | +package org.onosproject.vtnrsc.cli.router; | ||
| 17 | + | ||
| 18 | +import org.apache.karaf.shell.commands.Command; | ||
| 19 | +import org.apache.karaf.shell.commands.Option; | ||
| 20 | +import org.onosproject.cli.AbstractShellCommand; | ||
| 21 | +import org.onosproject.vtnrsc.Router; | ||
| 22 | +import org.onosproject.vtnrsc.RouterId; | ||
| 23 | +import org.onosproject.vtnrsc.router.RouterService; | ||
| 24 | + | ||
| 25 | +/** | ||
| 26 | + * Supports for query a list of router. | ||
| 27 | + */ | ||
| 28 | +@Command(scope = "onos", name = "routers", description = "Supports for creating a router") | ||
| 29 | +public class RouterQueryCommand extends AbstractShellCommand { | ||
| 30 | + @Option(name = "-i", aliases = "--id", description = "The router identifier", | ||
| 31 | + required = false, multiValued = false) | ||
| 32 | + String id = null; | ||
| 33 | + | ||
| 34 | + @Option(name = "-n", aliases = "--routerName", description = "The name of router", | ||
| 35 | + required = false, multiValued = false) | ||
| 36 | + String routerName = null; | ||
| 37 | + | ||
| 38 | + private static final String FMT = "routerId=%s, routerName=%s, tenantId=%s, gatewayPortId=%s," | ||
| 39 | + + "externalGatewayInfo=%s, status=%s, adminStateUp=%s, distributed=%s, routers=%s"; | ||
| 40 | + | ||
| 41 | + @Override | ||
| 42 | + protected void execute() { | ||
| 43 | + RouterService service = get(RouterService.class); | ||
| 44 | + if (id != null) { | ||
| 45 | + Router router = service.getRouter(RouterId.valueOf(id)); | ||
| 46 | + printFloatingIp(router); | ||
| 47 | + } else if (routerName != null) { | ||
| 48 | + Iterable<Router> routers = service.getRouters(); | ||
| 49 | + if (routers == null) { | ||
| 50 | + return; | ||
| 51 | + } | ||
| 52 | + for (Router router : routers) { | ||
| 53 | + if (router.name().equals(routerName)) { | ||
| 54 | + printFloatingIp(router); | ||
| 55 | + return; | ||
| 56 | + } | ||
| 57 | + } | ||
| 58 | + print(null, "The routerName is not existed"); | ||
| 59 | + } else { | ||
| 60 | + Iterable<Router> routers = service.getRouters(); | ||
| 61 | + if (routers == null) { | ||
| 62 | + return; | ||
| 63 | + } | ||
| 64 | + for (Router router : routers) { | ||
| 65 | + printFloatingIp(router); | ||
| 66 | + } | ||
| 67 | + } | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + private void printFloatingIp(Router router) { | ||
| 71 | + print(FMT, router.id(), router.name(), router.tenantId(), | ||
| 72 | + router.gatewayPortid(), router.externalGatewayInfo(), | ||
| 73 | + router.status(), router.adminStateUp(), router.distributed(), | ||
| 74 | + router.routes()); | ||
| 75 | + } | ||
| 76 | +} |
| 1 | +/* | ||
| 2 | + * Copyright 2015 Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | +package org.onosproject.vtnrsc.cli.router; | ||
| 17 | + | ||
| 18 | +import java.util.Set; | ||
| 19 | + | ||
| 20 | +import org.apache.karaf.shell.commands.Command; | ||
| 21 | +import org.apache.karaf.shell.commands.Option; | ||
| 22 | +import org.onosproject.cli.AbstractShellCommand; | ||
| 23 | +import org.onosproject.vtnrsc.Router; | ||
| 24 | +import org.onosproject.vtnrsc.RouterId; | ||
| 25 | +import org.onosproject.vtnrsc.router.RouterService; | ||
| 26 | + | ||
| 27 | +import com.google.common.collect.Sets; | ||
| 28 | + | ||
| 29 | +/** | ||
| 30 | + * Supports for remove a router. | ||
| 31 | + */ | ||
| 32 | +@Command(scope = "onos", name = "router-remove", description = "Supports for removing a router") | ||
| 33 | +public class RouterRemoveCommand extends AbstractShellCommand { | ||
| 34 | + @Option(name = "-i", aliases = "--id", description = "The router identifier", | ||
| 35 | + required = false, multiValued = false) | ||
| 36 | + String id = null; | ||
| 37 | + | ||
| 38 | + @Option(name = "-n", aliases = "--routerName", description = "The name of router", | ||
| 39 | + required = false, multiValued = false) | ||
| 40 | + String routerName = null; | ||
| 41 | + | ||
| 42 | + @Override | ||
| 43 | + protected void execute() { | ||
| 44 | + RouterService service = get(RouterService.class); | ||
| 45 | + if (id == null && routerName == null) { | ||
| 46 | + print(null, "one of id, routerName should not be null"); | ||
| 47 | + } | ||
| 48 | + try { | ||
| 49 | + Set<RouterId> routerSet = Sets.newHashSet(); | ||
| 50 | + if (id != null) { | ||
| 51 | + routerSet.add(RouterId.valueOf(id)); | ||
| 52 | + service.removeRouters(routerSet); | ||
| 53 | + } else { | ||
| 54 | + Iterable<Router> routers = service.getRouters(); | ||
| 55 | + if (routers == null) { | ||
| 56 | + return; | ||
| 57 | + } | ||
| 58 | + for (Router router : routers) { | ||
| 59 | + if (router.name().equals(routerName)) { | ||
| 60 | + routerSet.add(router.id()); | ||
| 61 | + service.removeRouters(routerSet); | ||
| 62 | + return; | ||
| 63 | + } | ||
| 64 | + } | ||
| 65 | + } | ||
| 66 | + } catch (Exception e) { | ||
| 67 | + print(null, e.getMessage()); | ||
| 68 | + } | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | +} |
| 1 | +/* | ||
| 2 | + * Copyright 2015 Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | +package org.onosproject.vtnrsc.cli.router; | ||
| 17 | + | ||
| 18 | +import java.util.ArrayList; | ||
| 19 | +import java.util.List; | ||
| 20 | +import java.util.Set; | ||
| 21 | + | ||
| 22 | +import org.apache.karaf.shell.commands.Argument; | ||
| 23 | +import org.apache.karaf.shell.commands.Command; | ||
| 24 | +import org.apache.karaf.shell.commands.Option; | ||
| 25 | +import org.onosproject.cli.AbstractShellCommand; | ||
| 26 | +import org.onosproject.vtnrsc.DefaultRouter; | ||
| 27 | +import org.onosproject.vtnrsc.Router; | ||
| 28 | +import org.onosproject.vtnrsc.Router.Status; | ||
| 29 | +import org.onosproject.vtnrsc.RouterId; | ||
| 30 | +import org.onosproject.vtnrsc.TenantId; | ||
| 31 | +import org.onosproject.vtnrsc.VirtualPortId; | ||
| 32 | +import org.onosproject.vtnrsc.router.RouterService; | ||
| 33 | + | ||
| 34 | +import com.google.common.collect.Sets; | ||
| 35 | + | ||
| 36 | +/** | ||
| 37 | + * Supports for update a router. | ||
| 38 | + */ | ||
| 39 | +@Command(scope = "onos", name = "router-update", description = "Supports for updating a router") | ||
| 40 | +public class RouterUpdateCommand extends AbstractShellCommand { | ||
| 41 | + @Argument(index = 0, name = "id", description = "The router identifier", | ||
| 42 | + required = true, multiValued = false) | ||
| 43 | + String id = null; | ||
| 44 | + | ||
| 45 | + @Option(name = "-r", aliases = "--routerName", description = "The name of router", | ||
| 46 | + required = false, multiValued = false) | ||
| 47 | + String routerName = null; | ||
| 48 | + | ||
| 49 | + @Option(name = "-t", aliases = "--tenantId", description = "The tenant identifier of router", | ||
| 50 | + required = false, multiValued = false) | ||
| 51 | + String tenantId = null; | ||
| 52 | + | ||
| 53 | + @Option(name = "-g", aliases = "--gatewayPortId", description = "The gatewayPort identifier of router", | ||
| 54 | + required = false, multiValued = false) | ||
| 55 | + String gatewayPortId = null; | ||
| 56 | + | ||
| 57 | + @Option(name = "-e", aliases = "--externalGatewayInfo", description = "The externalGatewayInfo of router", | ||
| 58 | + required = false, multiValued = false) | ||
| 59 | + String externalGatewayInfo = null; | ||
| 60 | + | ||
| 61 | + @Option(name = "-s", aliases = "--status", description = "The status of router", | ||
| 62 | + required = false, multiValued = false) | ||
| 63 | + String status = null; | ||
| 64 | + | ||
| 65 | + @Option(name = "-a", aliases = "--adminStateUp", description = "The boolean adminStateUp of router", | ||
| 66 | + required = false, multiValued = false) | ||
| 67 | + boolean adminStateUp = true; | ||
| 68 | + | ||
| 69 | + @Option(name = "-d", aliases = "--distributed", description = "The boolean distributed of router", | ||
| 70 | + required = false, multiValued = false) | ||
| 71 | + boolean distributed = false; | ||
| 72 | + | ||
| 73 | + @Override | ||
| 74 | + protected void execute() { | ||
| 75 | + RouterService service = get(RouterService.class); | ||
| 76 | + RouterId routerId = RouterId.valueOf(id); | ||
| 77 | + Router router = get(RouterService.class).getRouter(routerId); | ||
| 78 | + try { | ||
| 79 | + List<String> routes = new ArrayList<String>(); | ||
| 80 | + Router routerObj = new DefaultRouter( | ||
| 81 | + RouterId.valueOf(id), | ||
| 82 | + routerName == null ? router.name() : routerName, | ||
| 83 | + adminStateUp, | ||
| 84 | + status == null ? Status.ACTIVE | ||
| 85 | + : Status.valueOf(status), | ||
| 86 | + distributed, | ||
| 87 | + null, | ||
| 88 | + gatewayPortId == null ? router.gatewayPortid() | ||
| 89 | + : VirtualPortId.portId(gatewayPortId), | ||
| 90 | + tenantId == null ? router.tenantId() | ||
| 91 | + : TenantId.tenantId(tenantId), | ||
| 92 | + routes); | ||
| 93 | + Set<Router> routerSet = Sets.newHashSet(routerObj); | ||
| 94 | + service.createRouters(routerSet); | ||
| 95 | + } catch (Exception e) { | ||
| 96 | + print(null, e.getMessage()); | ||
| 97 | + } | ||
| 98 | + } | ||
| 99 | +} |
| 1 | +/* | ||
| 2 | + * Copyright 2015 Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | + | ||
| 17 | +/** | ||
| 18 | + * Command line interface for router. | ||
| 19 | + */ | ||
| 20 | +package org.onosproject.vtnrsc.cli.router; |
-
Please register or login to post a comment