[ONOS-2254] The CLIs of port resource.
Change-Id: I35c3da7c0d6a7f5f170d74d63a1ab85415b34191
diff --git a/apps/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/virtualport/VirtualPortCreateCommand.java b/apps/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/virtualport/VirtualPortCreateCommand.java
new file mode 100644
index 0000000..956f8ce
--- /dev/null
+++ b/apps/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/virtualport/VirtualPortCreateCommand.java
@@ -0,0 +1,135 @@
+/*
+ * 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.virtualport;
+
+import java.util.Collection;
+import java.util.Map;
+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.MacAddress;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.net.DeviceId;
+import org.onosproject.vtnrsc.AllowedAddressPair;
+import org.onosproject.vtnrsc.BindingHostId;
+import org.onosproject.vtnrsc.DefaultVirtualPort;
+import org.onosproject.vtnrsc.FixedIp;
+import org.onosproject.vtnrsc.SecurityGroup;
+import org.onosproject.vtnrsc.TenantId;
+import org.onosproject.vtnrsc.TenantNetworkId;
+import org.onosproject.vtnrsc.VirtualPort;
+import org.onosproject.vtnrsc.VirtualPortId;
+import org.onosproject.vtnrsc.virtualport.VirtualPortService;
+
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+
+/**
+ * Supports for creating a virtualPort.
+ */
+@Command(scope = "onos", name = "virtualport-create",
+ description = "Supports for creating a virtualPort.")
+public class VirtualPortCreateCommand extends AbstractShellCommand {
+
+ @Argument(index = 0, name = "id", description = "virtualPort id.", required = true,
+ multiValued = false)
+ String id = null;
+
+ @Argument(index = 1, name = "networkId", description = "network id.", required = true,
+ multiValued = false)
+ String networkId = null;
+
+ @Argument(index = 2, name = "name", description = "virtualPort name.", required = true,
+ multiValued = false)
+ String name = null;
+
+ @Argument(index = 3, name = "tenantId", description = "tenant id.", required = true,
+ multiValued = false)
+ String tenantId = null;
+
+ @Argument(index = 4, name = "deviceId", description = "device id.", required = true,
+ multiValued = false)
+ String deviceId = null;
+
+ @Option(name = "-a", aliases = "--adminStateUp",
+ description = "administrative status of the virtualPort which is true or false.",
+ required = false, multiValued = false)
+ Boolean adminStateUp = false;
+
+ @Option(name = "-s", aliases = "--state", description = "virtualPort state.", required = false,
+ multiValued = false)
+ String state = null;
+
+ @Option(name = "-m", aliases = "--macAddress", description = "MAC address.", required = false,
+ multiValued = false)
+ String macAddress = "";
+
+ @Option(name = "-d", aliases = "--deviceOwner", description = "ID of the entity that uses this "
+ + "virtualPort.", required = false, multiValued = false)
+ String deviceOwner = null;
+
+ @Option(name = "-f", aliases = "--fixedIp",
+ description = "The IP address for the port,include the IP address "
+ + "and subnet identity.", required = false, multiValued = false)
+ FixedIp fixedIp = null;
+
+ @Option(name = "-i", aliases = "--bindingHostId", description = "virtualPort bindingHostId.",
+ required = false, multiValued = false)
+ String bindingHostId = null;
+
+ @Option(name = "-t", aliases = "--bindingvnicType", description = "virtualPort bindingvnicType.",
+ required = false, multiValued = false)
+ String bindingvnicType = null;
+
+ @Option(name = "-v", aliases = "--bindingvifType", description = "virtualPort bindingvifType.",
+ required = false, multiValued = false)
+ String bindingvifType = null;
+
+ @Option(name = "-b", aliases = "--bindingvnicDetails",
+ description = "virtualPort bindingvnicDetails.", required = false, multiValued = false)
+ String bindingvnicDetails = null;
+
+ @Option(name = "-l", aliases = "--allowedAddress", description = "virtual allowedAddressPair.",
+ required = false, multiValued = false)
+ Collection<AllowedAddressPair> allowedAddressPairs = Sets.newHashSet();
+
+ @Option(name = "-e", aliases = "--securityGroups", description = "virtualPort securityGroups.",
+ required = false, multiValued = false)
+ Collection<SecurityGroup> securityGroups = Sets.newHashSet();
+
+ @Override
+ protected void execute() {
+ Map<String, String> strMap = Maps.newHashMap();
+ strMap.putIfAbsent("name", name);
+ strMap.putIfAbsent("deviceOwner", deviceOwner);
+ strMap.putIfAbsent("bindingvnicType", bindingvnicType);
+ strMap.putIfAbsent("bindingvifType", bindingvifType);
+ strMap.putIfAbsent("bindingvnicDetails", bindingvnicDetails);
+ VirtualPortService service = get(VirtualPortService.class);
+ VirtualPort virtualPort = new DefaultVirtualPort(VirtualPortId.portId(id),
+ TenantNetworkId.networkId(networkId),
+ false, strMap, VirtualPort.State.ACTIVE,
+ MacAddress.valueOf(macAddress),
+ TenantId.tenantId(tenantId),
+ DeviceId.deviceId(deviceId), Sets.newHashSet(fixedIp),
+ BindingHostId.bindingHostId(bindingHostId),
+ allowedAddressPairs, securityGroups);
+ Set<VirtualPort> virtualPorts = Sets.newHashSet(virtualPort);
+ service.createPorts(virtualPorts);
+ }
+}
diff --git a/apps/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/virtualport/VirtualPortQueryCommand.java b/apps/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/virtualport/VirtualPortQueryCommand.java
new file mode 100644
index 0000000..47126d1
--- /dev/null
+++ b/apps/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/virtualport/VirtualPortQueryCommand.java
@@ -0,0 +1,94 @@
+/*
+ * 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.virtualport;
+
+import java.util.Collection;
+
+import org.apache.karaf.shell.commands.Command;
+import org.apache.karaf.shell.commands.Option;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.net.DeviceId;
+import org.onosproject.vtnrsc.TenantNetworkId;
+import org.onosproject.vtnrsc.VirtualPort;
+import org.onosproject.vtnrsc.VirtualPortId;
+import org.onosproject.vtnrsc.virtualport.VirtualPortService;
+
+/**
+ * Supports for querying virtualPorts.
+ */
+@Command(scope = "onos", name = "virtualports", description = "Supports for querying virtualPorts.")
+public class VirtualPortQueryCommand extends AbstractShellCommand {
+
+ @Option(name = "-v", aliases = "--vPortId", description = "virtualPort ID.", required = false,
+ multiValued = false)
+ String vPortId;
+
+ @Option(name = "-n", aliases = "--networkId", description = "network ID.", required = false,
+ multiValued = false)
+ String networkId;
+
+ @Option(name = "-d", aliases = "--deviceId", description = "device ID.", required = false,
+ multiValued = false)
+ String deviceId;
+
+ @Option(name = "-t", aliases = "--tenantId", description = "tenant ID.", required = false,
+ multiValued = false)
+ String tenantId;
+
+ private static final String FMT = "virtualPortId=%s, networkId=%s, name=%s,"
+ + " tenantId=%s, deviceId=%s, adminStateUp=%s, state=%s,"
+ + " macAddress=%s, deviceOwner=%s, fixedIp=%s, bindingHostId=%s,"
+ + " bindingvnicType=%s, bindingvifType=%s, bindingvnicDetails=%s,"
+ + " allowedAddress=%s, securityGroups=%s";
+
+ @Override
+ protected void execute() {
+ VirtualPortService service = get(VirtualPortService.class);
+ if (vPortId != null && networkId == null && deviceId == null && tenantId == null) {
+ VirtualPort port = service.getPort(VirtualPortId.portId(vPortId));
+ printPort(port);
+ } else if (vPortId == null && networkId != null && deviceId == null && tenantId == null) {
+ Collection<VirtualPort> ports = service.getPorts(TenantNetworkId.networkId(networkId));
+ printPorts(ports);
+ } else if (vPortId == null && networkId == null && deviceId != null && tenantId == null) {
+ Collection<VirtualPort> ports = service.getPorts(DeviceId.deviceId(deviceId));
+ printPorts(ports);
+ } else if (vPortId == null && networkId == null && deviceId == null && tenantId != null) {
+ Collection<VirtualPort> ports = service.getPorts(DeviceId.deviceId(tenantId));
+ printPorts(ports);
+ } else if (vPortId == null && networkId == null && deviceId == null && tenantId == null) {
+ Collection<VirtualPort> ports = service.getPorts();
+ printPorts(ports);
+ } else {
+ print("cannot input more than one parameter");
+ }
+
+ }
+
+ private void printPorts(Collection<VirtualPort> ports) {
+ for (VirtualPort port : ports) {
+ printPort(port);
+ }
+ }
+
+ private void printPort(VirtualPort port) {
+ print(FMT, port.portId(), port.networkId(), port.name(), port.tenantId(), port.deviceId(),
+ port.adminStateUp(), port.state(), port.macAddress(), port.deviceOwner(), port
+ .fixedIps(), port.bindingHostId(), port.bindingVnicType(),
+ port.bindingVifType(), port.bindingVifDetails(), port.allowedAddressPairs(),
+ port.securityGroups());
+ }
+}
diff --git a/apps/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/virtualport/VirtualPortRemoveCommand.java b/apps/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/virtualport/VirtualPortRemoveCommand.java
new file mode 100644
index 0000000..1a3cb4f
--- /dev/null
+++ b/apps/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/virtualport/VirtualPortRemoveCommand.java
@@ -0,0 +1,45 @@
+/*
+ * 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.virtualport;
+
+import java.util.Set;
+
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.vtnrsc.VirtualPortId;
+import org.onosproject.vtnrsc.virtualport.VirtualPortService;
+
+import com.google.common.collect.Sets;
+
+/**
+ * Supports for removing a virtualPort.
+ */
+@Command(scope = "onos", name = "virtualport-remove",
+ description = "Supports for removing a virtualPort.")
+public class VirtualPortRemoveCommand extends AbstractShellCommand {
+
+ @Argument(index = 0, name = "id", description = "virtualPort id.", required = true,
+ multiValued = false)
+ String id = null;
+
+ @Override
+ protected void execute() {
+ VirtualPortService service = get(VirtualPortService.class);
+ Set<VirtualPortId> virtualPorts = Sets.newHashSet(VirtualPortId.portId(id));
+ service.removePorts(virtualPorts);
+ }
+}
diff --git a/apps/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/virtualport/VirtualPortUpdateCommand.java b/apps/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/virtualport/VirtualPortUpdateCommand.java
new file mode 100644
index 0000000..fd218e0
--- /dev/null
+++ b/apps/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/virtualport/VirtualPortUpdateCommand.java
@@ -0,0 +1,136 @@
+/*
+ * 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.virtualport;
+
+import java.util.Collection;
+import java.util.Map;
+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.MacAddress;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.net.DeviceId;
+import org.onosproject.vtnrsc.AllowedAddressPair;
+import org.onosproject.vtnrsc.BindingHostId;
+import org.onosproject.vtnrsc.DefaultVirtualPort;
+import org.onosproject.vtnrsc.FixedIp;
+import org.onosproject.vtnrsc.SecurityGroup;
+import org.onosproject.vtnrsc.TenantId;
+import org.onosproject.vtnrsc.TenantNetworkId;
+import org.onosproject.vtnrsc.VirtualPort;
+import org.onosproject.vtnrsc.VirtualPortId;
+import org.onosproject.vtnrsc.virtualport.VirtualPortService;
+
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+
+/**
+ * Supports for updating a virtualPort.
+ */
+@Command(scope = "onos", name = "virtualport-update",
+ description = "Supports for updating a virtualPort.")
+public class VirtualPortUpdateCommand extends AbstractShellCommand {
+
+ @Argument(index = 0, name = "id", description = "virtualPort id.", required = true,
+ multiValued = false)
+ String id = null;
+
+ @Argument(index = 1, name = "networkId", description = "network id.", required = true,
+ multiValued = false)
+ String networkId = null;
+
+ @Argument(index = 2, name = "name", description = "virtualPort name.", required = true,
+ multiValued = false)
+ String name = null;
+
+ @Argument(index = 3, name = "tenantId", description = "tenant id.", required = true,
+ multiValued = false)
+ String tenantId = null;
+
+ @Argument(index = 4, name = "deviceId", description = "device id.", required = true,
+ multiValued = false)
+ String deviceId = null;
+
+ @Option(name = "-a", aliases = "--adminStateUp",
+ description = "administrative status of the virtualPort which is true or false.",
+ required = false, multiValued = false)
+ Boolean adminStateUp = false;
+
+ @Option(name = "-s", aliases = "--state", description = "virtualPort state.", required = false,
+ multiValued = false)
+ String state = null;
+
+ @Option(name = "-m", aliases = "--macAddress", description = "MAC address.", required = false,
+ multiValued = false)
+ String macAddress = "";
+
+ @Option(name = "-d", aliases = "--deviceOwner",
+ description = "ID of the entity that uses this " + "virtualPort.", required = false,
+ multiValued = false)
+ String deviceOwner = null;
+
+ @Option(name = "-f", aliases = "--fixedIp",
+ description = "The IP address for the port,include the IP address "
+ + "and subnet identity.", required = false, multiValued = false)
+ FixedIp fixedIp = null;
+
+ @Option(name = "-i", aliases = "--bindingHostId", description = "virtualPort bindingHostId.",
+ required = false, multiValued = false)
+ String bindingHostId = "";
+
+ @Option(name = "-t", aliases = "--bindingvnicType",
+ description = "virtualPort bindingvnicType.", required = false, multiValued = false)
+ String bindingvnicType = null;
+
+ @Option(name = "-v", aliases = "--bindingvifType", description = "virtualPort bindingvifType.",
+ required = false, multiValued = false)
+ String bindingvifType = null;
+
+ @Option(name = "-b", aliases = "--bindingvnicDetails",
+ description = "virtualPort bindingvnicDetails.", required = false, multiValued = false)
+ String bindingvnicDetails = null;
+
+ @Option(name = "-l", aliases = "--allowedAddress", description = "virtual allowedAddressPair.",
+ required = false, multiValued = false)
+ Collection<AllowedAddressPair> allowedAddressPairs = Sets.newHashSet();
+
+ @Option(name = "-e", aliases = "--securityGroups", description = "virtualPort securityGroups.",
+ required = false, multiValued = false)
+ Collection<SecurityGroup> securityGroups = Sets.newHashSet();
+
+ @Override
+ protected void execute() {
+ VirtualPortService service = get(VirtualPortService.class);
+ Map<String, String> strMap = Maps.newHashMap();
+ strMap.putIfAbsent("name", name);
+ strMap.putIfAbsent("deviceOwner", deviceOwner);
+ strMap.putIfAbsent("bindingvnicType", bindingvnicType);
+ strMap.putIfAbsent("bindingvifType", bindingvifType);
+ strMap.putIfAbsent("bindingvnicDetails", bindingvnicDetails);
+ VirtualPort virtualPort = new DefaultVirtualPort(VirtualPortId.portId(id),
+ TenantNetworkId.networkId(networkId),
+ false, strMap, VirtualPort.State.ACTIVE,
+ MacAddress.valueOf(macAddress),
+ TenantId.tenantId(tenantId),
+ DeviceId.deviceId(deviceId), Sets.newHashSet(fixedIp),
+ BindingHostId.bindingHostId(bindingHostId),
+ allowedAddressPairs, securityGroups);
+ Set<VirtualPort> virtualPorts = Sets.newHashSet(virtualPort);
+ service.updatePorts(virtualPorts);
+ }
+}
diff --git a/apps/vtnrsc/src/main/resources/OSGI-INF/blueprint/shell-config.xml b/apps/vtnrsc/src/main/resources/OSGI-INF/blueprint/shell-config.xml
new file mode 100644
index 0000000..c6a9c81
--- /dev/null
+++ b/apps/vtnrsc/src/main/resources/OSGI-INF/blueprint/shell-config.xml
@@ -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.
+ -->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
+
+ <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0">
+ <command>
+ <action class="org.onosproject.vtnrsc.cli.network.TenantNetworkCreateCommand"/>
+ </command>
+ <command>
+ <action class="org.onosproject.vtnrsc.cli.network.TenantNetworkQueryCommand"/>
+ </command>
+ <command>
+ <action class="org.onosproject.vtnrsc.cli.network.TenantNetworkRemoveCommand"/>
+ </command>
+ <command>
+ <action class="org.onosproject.vtnrsc.cli.network.TenantNetworkUpdateCommand"/>
+ </command>
+ <command>
+ <action class="org.onosproject.vtnrsc.cli.subnet.SubnetCreateCommand"/>
+ </command>
+ <command>
+ <action class="org.onosproject.vtnrsc.cli.subnet.SubnetQueryCommand"/>
+ </command>
+ <command>
+ <action class="org.onosproject.vtnrsc.cli.subnet.SubnetRemoveCommand"/>
+ </command>
+ <command>
+ <action class="org.onosproject.vtnrsc.cli.subnet.SubnetUpdateCommand"/>
+ </command>
+ <command>
+ <action class="org.onosproject.vtnrsc.cli.virtualport.VirtualPortCreateCommand"/>
+ </command>
+ <command>
+ <action class="org.onosproject.vtnrsc.cli.virtualport.VirtualPortQueryCommand"/>
+ </command>
+ <command>
+ <action class="org.onosproject.vtnrsc.cli.virtualport.VirtualPortRemoveCommand"/>
+ </command>
+ <command>
+ <action class="org.onosproject.vtnrsc.cli.virtualport.VirtualPortUpdateCommand"/>
+ </command>
+ </command-bundle>
+</blueprint>