diff options
Diffstat (limited to 'framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli')
14 files changed, 953 insertions, 0 deletions
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/floatingip/FloatingIpCreateCommand.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/floatingip/FloatingIpCreateCommand.java new file mode 100644 index 00000000..00758dd2 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/floatingip/FloatingIpCreateCommand.java @@ -0,0 +1,95 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.vtnrsc.cli.floatingip; + +import java.util.Set; + +import org.apache.karaf.shell.commands.Argument; +import org.apache.karaf.shell.commands.Command; +import org.apache.karaf.shell.commands.Option; +import org.onlab.packet.IpAddress; +import org.onosproject.cli.AbstractShellCommand; +import org.onosproject.vtnrsc.DefaultFloatingIp; +import org.onosproject.vtnrsc.FloatingIpId; +import org.onosproject.vtnrsc.FloatingIp; +import org.onosproject.vtnrsc.FloatingIp.Status; +import org.onosproject.vtnrsc.RouterId; +import org.onosproject.vtnrsc.TenantId; +import org.onosproject.vtnrsc.TenantNetworkId; +import org.onosproject.vtnrsc.VirtualPortId; +import org.onosproject.vtnrsc.floatingip.FloatingIpService; + +import com.google.common.collect.Sets; + +/** + * Supports for create a floating IP. + */ +@Command(scope = "onos", name = "floatingip-create", + description = "Supports for creating a floating IP") +public class FloatingIpCreateCommand extends AbstractShellCommand { + @Argument(index = 0, name = "id", description = "The floating IP identifier", + required = true, multiValued = false) + String id = null; + + @Argument(index = 1, name = "networkId", description = "The network identifier of floating IP", + required = true, multiValued = false) + String networkId = null; + + @Argument(index = 2, name = "tenantId", description = "The tenant identifier of floating IP", + required = true, multiValued = false) + String tenantId = null; + + @Argument(index = 3, name = "routerId", description = "The router identifier of floating IP", + required = true, multiValued = false) + String routerId = null; + + @Argument(index = 4, name = "fixedIp", description = "The fixed IP of floating IP", + required = true, multiValued = false) + String fixedIp = null; + + @Argument(index = 5, name = "floatingIp", description = "The floating IP of floating IP", + required = true, multiValued = false) + String floatingIp = null; + + @Option(name = "-p", aliases = "--portId", description = "The port identifier of floating IP", + required = false, multiValued = false) + String portId = null; + + @Option(name = "-s", aliases = "--status", description = "The status of floating IP", + required = false, multiValued = false) + String status = null; + + @Override + protected void execute() { + FloatingIpService service = get(FloatingIpService.class); + try { + FloatingIp floatingIpObj = new DefaultFloatingIp( + FloatingIpId.of(id), + TenantId.tenantId(tenantId), + TenantNetworkId.networkId(networkId), + VirtualPortId.portId(portId), + RouterId.valueOf(routerId), + floatingIp == null ? null : IpAddress.valueOf(floatingIp), + fixedIp == null ? null : IpAddress.valueOf(fixedIp), + status == null ? Status.ACTIVE + : Status.valueOf(status)); + Set<FloatingIp> floatingIpSet = Sets.newHashSet(floatingIpObj); + service.createFloatingIps(floatingIpSet); + } catch (Exception e) { + print(null, e.getMessage()); + } + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/floatingip/FloatingIpQueryCommand.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/floatingip/FloatingIpQueryCommand.java new file mode 100644 index 00000000..c441d535 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/floatingip/FloatingIpQueryCommand.java @@ -0,0 +1,92 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.vtnrsc.cli.floatingip; + +import org.apache.karaf.shell.commands.Command; +import org.apache.karaf.shell.commands.Option; +import org.onosproject.cli.AbstractShellCommand; +import org.onosproject.vtnrsc.FloatingIpId; +import org.onosproject.vtnrsc.FloatingIp; +import org.onosproject.vtnrsc.floatingip.FloatingIpService; + +/** + * Supports for query a floating IP. + */ +@Command(scope = "onos", name = "floatingips", description = "Supports for querying a floating IP") +public class FloatingIpQueryCommand extends AbstractShellCommand { + @Option(name = "-I", aliases = "--id", description = "The floating IP identifier", + required = false, multiValued = false) + String id = null; + + @Option(name = "-i", aliases = "--fixedIp", description = "The fixed IP of floating IP", + required = false, multiValued = false) + String fixedIp = null; + + @Option(name = "-l", aliases = "--floatingIp", description = "The floating IP of floating IP", + required = false, multiValued = false) + String floatingIp = null; + + private static final String FMT = "floatingIpId=%s, networkId=%s, tenantId=%s, portId=%s," + + "routerId=%s, fixedIp=%s, floatingIp=%s, status=%s"; + + @Override + protected void execute() { + FloatingIpService service = get(FloatingIpService.class); + if (id != null) { + FloatingIp floatingIp = service.getFloatingIp(FloatingIpId + .of(id)); + printFloatingIp(floatingIp); + } else if (fixedIp != null || floatingIp != null) { + Iterable<FloatingIp> floatingIps = service.getFloatingIps(); + if (floatingIps == null) { + return; + } + if (fixedIp != null) { + for (FloatingIp floatingIp : floatingIps) { + if (floatingIp.fixedIp().toString().equals(fixedIp)) { + printFloatingIp(floatingIp); + return; + } + } + print(null, "The fixedIp is not existed"); + } + if (floatingIp != null) { + for (FloatingIp floatingIpObj : floatingIps) { + if (floatingIpObj.fixedIp().toString().equals(floatingIp)) { + printFloatingIp(floatingIpObj); + return; + } + } + print(null, "The floatingIp is not existed"); + } + } else { + Iterable<FloatingIp> floatingIps = service.getFloatingIps(); + if (floatingIps == null) { + return; + } + for (FloatingIp floatingIp : floatingIps) { + printFloatingIp(floatingIp); + } + } + } + + private void printFloatingIp(FloatingIp floatingIp) { + print(FMT, floatingIp.id(), floatingIp.networkId(), + floatingIp.tenantId(), floatingIp.portId(), + floatingIp.routerId(), floatingIp.fixedIp(), + floatingIp.floatingIp(), floatingIp.status()); + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/floatingip/FloatingIpRemoveCommand.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/floatingip/FloatingIpRemoveCommand.java new file mode 100644 index 00000000..a413503a --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/floatingip/FloatingIpRemoveCommand.java @@ -0,0 +1,90 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.vtnrsc.cli.floatingip; + +import java.util.Set; + +import org.apache.karaf.shell.commands.Command; +import org.apache.karaf.shell.commands.Option; +import org.onosproject.cli.AbstractShellCommand; +import org.onosproject.vtnrsc.FloatingIp; +import org.onosproject.vtnrsc.FloatingIpId; +import org.onosproject.vtnrsc.floatingip.FloatingIpService; + +import com.google.common.collect.Sets; + +/** + * Supports for remove a floating IP. + */ +@Command(scope = "onos", name = "floatingip-remove", description = "Supports for removing a floating IP") +public class FloatingIpRemoveCommand extends AbstractShellCommand { + @Option(name = "-I", aliases = "--id", description = "The floating IP identifier", + required = false, multiValued = false) + String id = null; + + @Option(name = "-i", aliases = "--fixedIp", description = "The fixed IP of floating IP", + required = false, multiValued = false) + String fixedIp = null; + + @Option(name = "-l", aliases = "--floatingIp", description = "The floating IP of floating IP", + required = false, multiValued = false) + String floatingIp = null; + + @Override + protected void execute() { + FloatingIpService service = get(FloatingIpService.class); + if (id == null && fixedIp == null && floatingIp == null) { + print(null, "one of id, fixedIp, floatingIp should not be null"); + } + try { + Set<FloatingIpId> floatingIpSet = Sets.newHashSet(); + if (id != null) { + floatingIpSet.add(FloatingIpId.of(id)); + service.removeFloatingIps(floatingIpSet); + } else { + Iterable<FloatingIp> floatingIps = service.getFloatingIps(); + if (floatingIps == null) { + return; + } + if (fixedIp != null) { + for (FloatingIp floatingIp : floatingIps) { + if (floatingIp.fixedIp().toString().equals(fixedIp)) { + floatingIpSet.add(floatingIp.id()); + service.removeFloatingIps(floatingIpSet); + return; + } + } + print(null, "The fixedIp is not existed"); + return; + } + if (floatingIp != null) { + for (FloatingIp floatingIpObj : floatingIps) { + if (floatingIpObj.fixedIp().toString() + .equals(floatingIp)) { + floatingIpSet.add(floatingIpObj.id()); + service.removeFloatingIps(floatingIpSet); + return; + } + } + print(null, "The floatingIp is not existed"); + return; + } + } + } catch (Exception e) { + print(null, e.getMessage()); + } + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/floatingip/FloatingIpUpdateCommand.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/floatingip/FloatingIpUpdateCommand.java new file mode 100644 index 00000000..413b3bdb --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/floatingip/FloatingIpUpdateCommand.java @@ -0,0 +1,103 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.vtnrsc.cli.floatingip; + +import java.util.Set; + +import org.apache.karaf.shell.commands.Argument; +import org.apache.karaf.shell.commands.Command; +import org.apache.karaf.shell.commands.Option; +import org.onlab.packet.IpAddress; +import org.onosproject.cli.AbstractShellCommand; +import org.onosproject.vtnrsc.DefaultFloatingIp; +import org.onosproject.vtnrsc.FloatingIpId; +import org.onosproject.vtnrsc.FloatingIp; +import org.onosproject.vtnrsc.FloatingIp.Status; +import org.onosproject.vtnrsc.RouterId; +import org.onosproject.vtnrsc.TenantId; +import org.onosproject.vtnrsc.TenantNetworkId; +import org.onosproject.vtnrsc.VirtualPortId; +import org.onosproject.vtnrsc.floatingip.FloatingIpService; + +import com.google.common.collect.Sets; + +/** + * Supports for update a floating IP. + */ +@Command(scope = "onos", name = "floatingip-update", + description = "Supports for updating a floating IP") +public class FloatingIpUpdateCommand extends AbstractShellCommand { + @Argument(index = 0, name = "id", description = "The floating IP identifier", + required = true, multiValued = false) + String id = null; + + @Option(name = "-n", aliases = "--networkId", description = "The network identifier of floating IP", + required = false, multiValued = false) + String networkId = null; + + @Option(name = "-t", aliases = "--tenantId", description = "The tenant identifier of floating IP", + required = false, multiValued = false) + String tenantId = null; + + @Option(name = "-r", aliases = "--routerId", description = "The router identifier of floating IP", + required = false, multiValued = false) + String routerId = null; + + @Option(name = "-p", aliases = "--portId", description = "The port identifier of floating IP", + required = false, multiValued = false) + String portId = null; + + @Option(name = "-s", aliases = "--status", description = "The status of floating IP", + required = false, multiValued = false) + String status = null; + + @Option(name = "-i", aliases = "--fixedIp", description = "The fixed IP of floating IP", + required = false, multiValued = false) + String fixedIp = null; + + @Option(name = "-l", aliases = "--floatingIp", description = "The floating IP of floating IP", + required = false, multiValued = false) + String floatingIp = null; + + @Override + protected void execute() { + FloatingIpService service = get(FloatingIpService.class); + FloatingIpId floatingIpId = FloatingIpId.of(id); + FloatingIp floatingIpStore = get(FloatingIpService.class).getFloatingIp(floatingIpId); + try { + FloatingIp floatingIpObj = new DefaultFloatingIp( + floatingIpId, + tenantId == null ? floatingIpStore.tenantId() + : TenantId.tenantId(tenantId), + networkId == null ? floatingIpStore.networkId() + : TenantNetworkId.networkId(networkId), + portId == null ? floatingIpStore.portId() + : VirtualPortId.portId(portId), + routerId == null ? floatingIpStore.routerId() + : RouterId.valueOf(routerId), + floatingIp == null ? floatingIpStore.floatingIp() + : IpAddress.valueOf(floatingIp), + fixedIp == null ? floatingIpStore.fixedIp() + : IpAddress.valueOf(fixedIp), + status == null ? floatingIpStore.status() + : Status.valueOf(status)); + Set<FloatingIp> floatingIpSet = Sets.newHashSet(floatingIpObj); + service.updateFloatingIps(floatingIpSet); + } catch (Exception e) { + print(null, e.getMessage()); + } + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/floatingip/package-info.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/floatingip/package-info.java new file mode 100644 index 00000000..ac560771 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/floatingip/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Command line interface for floatingIP. + */ +package org.onosproject.vtnrsc.cli.floatingip; diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/router/RouterCreateCommand.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/router/RouterCreateCommand.java new file mode 100644 index 00000000..3a736deb --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/router/RouterCreateCommand.java @@ -0,0 +1,97 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.vtnrsc.cli.router; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import org.apache.karaf.shell.commands.Argument; +import org.apache.karaf.shell.commands.Command; +import org.apache.karaf.shell.commands.Option; +import org.onosproject.cli.AbstractShellCommand; +import org.onosproject.vtnrsc.DefaultRouter; +import org.onosproject.vtnrsc.Router; +import org.onosproject.vtnrsc.Router.Status; +import org.onosproject.vtnrsc.RouterId; +import org.onosproject.vtnrsc.TenantId; +import org.onosproject.vtnrsc.VirtualPortId; +import org.onosproject.vtnrsc.router.RouterService; + +import com.google.common.collect.Sets; + +/** + * Supports for create a router. + */ +@Command(scope = "onos", name = "router-create", + description = "Supports for creating a router") +public class RouterCreateCommand extends AbstractShellCommand { + @Argument(index = 0, name = "id", description = "The router identifier", + required = true, multiValued = false) + String id = null; + + @Argument(index = 1, name = "routerName", description = "The name of router", + required = true, multiValued = false) + String routerName = null; + + @Argument(index = 2, name = "tenantId", description = "The tenant identifier of router", + required = true, multiValued = false) + String tenantId = null; + + @Option(name = "-g", aliases = "--gatewayPortId", description = "The gatewayPort identifier of router", + required = false, multiValued = false) + String gatewayPortId = null; + + @Option(name = "-e", aliases = "--externalGatewayInfo", description = "The external gateway info of router", + required = false, multiValued = false) + String externalGatewayInfo = null; + + @Option(name = "-s", aliases = "--status", description = "The status of router", + required = false, multiValued = false) + String status = null; + + @Option(name = "-a", aliases = "--adminStateUp", description = "The boolean adminStateUp of router", + required = false, multiValued = false) + boolean adminStateUp = true; + + @Option(name = "-d", aliases = "--distributed", description = "The boolean distributed of router", + required = false, multiValued = false) + boolean distributed = false; + + @Override + protected void execute() { + RouterService service = get(RouterService.class); + try { + List<String> routes = new ArrayList<String>(); + Router router = new DefaultRouter( + RouterId.valueOf(id), + routerName, + adminStateUp, + status == null ? Status.ACTIVE + : Status.valueOf(status), + distributed, + null, + VirtualPortId.portId(gatewayPortId), + TenantId.tenantId(tenantId), + routes); + Set<Router> routerSet = Sets.newHashSet(router); + service.createRouters(routerSet); + } catch (Exception e) { + print(null, e.getMessage()); + } + } + +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/router/RouterQueryCommand.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/router/RouterQueryCommand.java new file mode 100644 index 00000000..a8a4b585 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/router/RouterQueryCommand.java @@ -0,0 +1,76 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.vtnrsc.cli.router; + +import org.apache.karaf.shell.commands.Command; +import org.apache.karaf.shell.commands.Option; +import org.onosproject.cli.AbstractShellCommand; +import org.onosproject.vtnrsc.Router; +import org.onosproject.vtnrsc.RouterId; +import org.onosproject.vtnrsc.router.RouterService; + +/** + * Supports for query a list of router. + */ +@Command(scope = "onos", name = "routers", description = "Supports for creating a router") +public class RouterQueryCommand extends AbstractShellCommand { + @Option(name = "-i", aliases = "--id", description = "The router identifier", + required = false, multiValued = false) + String id = null; + + @Option(name = "-n", aliases = "--routerName", description = "The name of router", + required = false, multiValued = false) + String routerName = null; + + private static final String FMT = "routerId=%s, routerName=%s, tenantId=%s, gatewayPortId=%s," + + "externalGatewayInfo=%s, status=%s, adminStateUp=%s, distributed=%s, routers=%s"; + + @Override + protected void execute() { + RouterService service = get(RouterService.class); + if (id != null) { + Router router = service.getRouter(RouterId.valueOf(id)); + printFloatingIp(router); + } else if (routerName != null) { + Iterable<Router> routers = service.getRouters(); + if (routers == null) { + return; + } + for (Router router : routers) { + if (router.name().equals(routerName)) { + printFloatingIp(router); + return; + } + } + print(null, "The routerName is not existed"); + } else { + Iterable<Router> routers = service.getRouters(); + if (routers == null) { + return; + } + for (Router router : routers) { + printFloatingIp(router); + } + } + } + + private void printFloatingIp(Router router) { + print(FMT, router.id(), router.name(), router.tenantId(), + router.gatewayPortid(), router.externalGatewayInfo(), + router.status(), router.adminStateUp(), router.distributed(), + router.routes()); + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/router/RouterRemoveCommand.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/router/RouterRemoveCommand.java new file mode 100644 index 00000000..b48434a1 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/router/RouterRemoveCommand.java @@ -0,0 +1,71 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.vtnrsc.cli.router; + +import java.util.Set; + +import org.apache.karaf.shell.commands.Command; +import org.apache.karaf.shell.commands.Option; +import org.onosproject.cli.AbstractShellCommand; +import org.onosproject.vtnrsc.Router; +import org.onosproject.vtnrsc.RouterId; +import org.onosproject.vtnrsc.router.RouterService; + +import com.google.common.collect.Sets; + +/** + * Supports for remove a router. + */ +@Command(scope = "onos", name = "router-remove", description = "Supports for removing a router") +public class RouterRemoveCommand extends AbstractShellCommand { + @Option(name = "-i", aliases = "--id", description = "The router identifier", + required = false, multiValued = false) + String id = null; + + @Option(name = "-n", aliases = "--routerName", description = "The name of router", + required = false, multiValued = false) + String routerName = null; + + @Override + protected void execute() { + RouterService service = get(RouterService.class); + if (id == null && routerName == null) { + print(null, "one of id, routerName should not be null"); + } + try { + Set<RouterId> routerSet = Sets.newHashSet(); + if (id != null) { + routerSet.add(RouterId.valueOf(id)); + service.removeRouters(routerSet); + } else { + Iterable<Router> routers = service.getRouters(); + if (routers == null) { + return; + } + for (Router router : routers) { + if (router.name().equals(routerName)) { + routerSet.add(router.id()); + service.removeRouters(routerSet); + return; + } + } + } + } catch (Exception e) { + print(null, e.getMessage()); + } + } + +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/router/RouterUpdateCommand.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/router/RouterUpdateCommand.java new file mode 100644 index 00000000..699874b3 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/router/RouterUpdateCommand.java @@ -0,0 +1,99 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.vtnrsc.cli.router; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import org.apache.karaf.shell.commands.Argument; +import org.apache.karaf.shell.commands.Command; +import org.apache.karaf.shell.commands.Option; +import org.onosproject.cli.AbstractShellCommand; +import org.onosproject.vtnrsc.DefaultRouter; +import org.onosproject.vtnrsc.Router; +import org.onosproject.vtnrsc.Router.Status; +import org.onosproject.vtnrsc.RouterId; +import org.onosproject.vtnrsc.TenantId; +import org.onosproject.vtnrsc.VirtualPortId; +import org.onosproject.vtnrsc.router.RouterService; + +import com.google.common.collect.Sets; + +/** + * Supports for update a router. + */ +@Command(scope = "onos", name = "router-update", description = "Supports for updating a router") +public class RouterUpdateCommand extends AbstractShellCommand { + @Argument(index = 0, name = "id", description = "The router identifier", + required = true, multiValued = false) + String id = null; + + @Option(name = "-r", aliases = "--routerName", description = "The name of router", + required = false, multiValued = false) + String routerName = null; + + @Option(name = "-t", aliases = "--tenantId", description = "The tenant identifier of router", + required = false, multiValued = false) + String tenantId = null; + + @Option(name = "-g", aliases = "--gatewayPortId", description = "The gatewayPort identifier of router", + required = false, multiValued = false) + String gatewayPortId = null; + + @Option(name = "-e", aliases = "--externalGatewayInfo", description = "The externalGatewayInfo of router", + required = false, multiValued = false) + String externalGatewayInfo = null; + + @Option(name = "-s", aliases = "--status", description = "The status of router", + required = false, multiValued = false) + String status = null; + + @Option(name = "-a", aliases = "--adminStateUp", description = "The boolean adminStateUp of router", + required = false, multiValued = false) + boolean adminStateUp = true; + + @Option(name = "-d", aliases = "--distributed", description = "The boolean distributed of router", + required = false, multiValued = false) + boolean distributed = false; + + @Override + protected void execute() { + RouterService service = get(RouterService.class); + RouterId routerId = RouterId.valueOf(id); + Router router = get(RouterService.class).getRouter(routerId); + try { + List<String> routes = new ArrayList<String>(); + Router routerObj = new DefaultRouter( + RouterId.valueOf(id), + routerName == null ? router.name() : routerName, + adminStateUp, + status == null ? Status.ACTIVE + : Status.valueOf(status), + distributed, + null, + gatewayPortId == null ? router.gatewayPortid() + : VirtualPortId.portId(gatewayPortId), + tenantId == null ? router.tenantId() + : TenantId.tenantId(tenantId), + routes); + Set<Router> routerSet = Sets.newHashSet(routerObj); + service.createRouters(routerSet); + } catch (Exception e) { + print(null, e.getMessage()); + } + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/router/package-info.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/router/package-info.java new file mode 100644 index 00000000..4f1768ac --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/router/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Command line interface for router. + */ +package org.onosproject.vtnrsc.cli.router; diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/routerinterface/RouterInterfaceCreateCommand.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/routerinterface/RouterInterfaceCreateCommand.java new file mode 100644 index 00000000..a3a174c9 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/routerinterface/RouterInterfaceCreateCommand.java @@ -0,0 +1,64 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.vtnrsc.cli.routerinterface; + +import org.apache.karaf.shell.commands.Argument; +import org.apache.karaf.shell.commands.Command; +import org.onosproject.cli.AbstractShellCommand; +import org.onosproject.vtnrsc.RouterId; +import org.onosproject.vtnrsc.RouterInterface; +import org.onosproject.vtnrsc.SubnetId; +import org.onosproject.vtnrsc.TenantId; +import org.onosproject.vtnrsc.VirtualPortId; +import org.onosproject.vtnrsc.routerinterface.RouterInterfaceService; + +/** + * Supports for create a router interface. + */ +@Command(scope = "onos", name = "routerinterface-create", description = "Supports for creating a router interface") +public class RouterInterfaceCreateCommand extends AbstractShellCommand { + @Argument(index = 0, name = "routerId", description = "The router identifier of router interface", + required = true, multiValued = false) + String routerId = null; + + @Argument(index = 1, name = "tenantId", description = "The tenant identifier of router interface", + required = true, multiValued = false) + String tenantId = null; + + @Argument(index = 2, name = "portId", description = "The port identifier of router interface", + required = true, multiValued = false) + String portId = null; + + @Argument(index = 3, name = "subnetId", description = "The subnet identifier of router interface", + required = true, multiValued = false) + String subnetId = null; + + @Override + protected void execute() { + RouterInterfaceService service = get(RouterInterfaceService.class); + try { + RouterInterface routerInterface = RouterInterface.routerInterface( + SubnetId.subnetId(subnetId), + VirtualPortId.portId(portId), + RouterId.valueOf(routerId), + TenantId.tenantId(tenantId)); + service.addRouterInterface(routerInterface); + } catch (Exception e) { + print(null, e.getMessage()); + } + } + +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/routerinterface/RouterInterfaceQueryCommand.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/routerinterface/RouterInterfaceQueryCommand.java new file mode 100644 index 00000000..5de35aee --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/routerinterface/RouterInterfaceQueryCommand.java @@ -0,0 +1,56 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.vtnrsc.cli.routerinterface; + +import org.apache.karaf.shell.commands.Command; +import org.apache.karaf.shell.commands.Option; +import org.onosproject.cli.AbstractShellCommand; +import org.onosproject.vtnrsc.RouterInterface; +import org.onosproject.vtnrsc.SubnetId; +import org.onosproject.vtnrsc.routerinterface.RouterInterfaceService; + +/** + * Supports for query a router interface. + */ +@Command(scope = "onos", name = "routerinterfaces", description = "Supports for querying a router interface") +public class RouterInterfaceQueryCommand extends AbstractShellCommand { + @Option(name = "-s", aliases = "--subnetId", description = "The subnet identifier of router interface", + required = false, multiValued = false) + String subnetId = null; + + private static final String FMT = "subnetId=%s, tenantId=%s, portId=%s, routerId=%s"; + + @Override + protected void execute() { + RouterInterfaceService service = get(RouterInterfaceService.class); + if (subnetId != null) { + RouterInterface routerInterface = service + .getRouterInterface(SubnetId.subnetId(subnetId)); + printRouterInterface(routerInterface); + } else { + Iterable<RouterInterface> routerInterfaces = service + .getRouterInterfaces(); + for (RouterInterface routerInterface : routerInterfaces) { + printRouterInterface(routerInterface); + } + } + } + + private void printRouterInterface(RouterInterface routerInterface) { + print(FMT, routerInterface.subnetId(), routerInterface.tenantId(), + routerInterface.portId(), routerInterface.routerId()); + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/routerinterface/RouterInterfaceRemoveCommand.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/routerinterface/RouterInterfaceRemoveCommand.java new file mode 100644 index 00000000..4e838e26 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/routerinterface/RouterInterfaceRemoveCommand.java @@ -0,0 +1,50 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.vtnrsc.cli.routerinterface; + +import org.apache.karaf.shell.commands.Command; +import org.apache.karaf.shell.commands.Option; +import org.onosproject.cli.AbstractShellCommand; +import org.onosproject.vtnrsc.RouterInterface; +import org.onosproject.vtnrsc.SubnetId; +import org.onosproject.vtnrsc.routerinterface.RouterInterfaceService; + +/** + * Supports for remove a router interface. + */ +@Command(scope = "onos", name = "routerinterface-remove", description = "Supports for removing a router interface") +public class RouterInterfaceRemoveCommand extends AbstractShellCommand { + @Option(name = "-s", aliases = "--subnetId", description = "The subnet identifier of router interface", + required = true, multiValued = false) + String subnetId = null; + + @Override + protected void execute() { + RouterInterfaceService service = get(RouterInterfaceService.class); + try { + RouterInterface routerInterface = service + .getRouterInterface(SubnetId.subnetId(subnetId)); + if (routerInterface == null) { + print(null, "subnet ID of interface doesn't exist"); + return; + } + service.removeRouterInterface(routerInterface); + } catch (Exception e) { + print(null, e.getMessage()); + } + + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/routerinterface/package-info.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/routerinterface/package-info.java new file mode 100644 index 00000000..7b82004e --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/routerinterface/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Command line interface for router interface. + */ +package org.onosproject.vtnrsc.cli.routerinterface; |