From 6a07d2d622eaa06953f3353e39c080984076e8de Mon Sep 17 00:00:00 2001 From: Ashlee Young Date: Fri, 9 Oct 2015 18:32:44 -0700 Subject: Updated master to commit id 6ee8aa3e67ce89908a8c93aa9445c6f71a18f986 Change-Id: I94b055ee2f298daf71e2ec794fd0f2495bd8081f --- framework/src/onos/apps/vtn/vtnrsc/pom.xml | 56 +++++ .../org/onosproject/vtnrsc/AllocationPool.java | 38 ++++ .../org/onosproject/vtnrsc/AllowedAddressPair.java | 94 +++++++++ .../java/org/onosproject/vtnrsc/BindingHostId.java | 72 +++++++ .../onosproject/vtnrsc/DefaultAllocationPool.java | 81 ++++++++ .../org/onosproject/vtnrsc/DefaultHostRoute.java | 79 +++++++ .../java/org/onosproject/vtnrsc/DefaultSubnet.java | 183 ++++++++++++++++ .../onosproject/vtnrsc/DefaultTenantNetwork.java | 160 ++++++++++++++ .../org/onosproject/vtnrsc/DefaultVirtualPort.java | 229 +++++++++++++++++++++ .../main/java/org/onosproject/vtnrsc/FixedIp.java | 93 +++++++++ .../java/org/onosproject/vtnrsc/HostRoute.java | 39 ++++ .../org/onosproject/vtnrsc/PhysicalNetwork.java | 78 +++++++ .../java/org/onosproject/vtnrsc/SecurityGroup.java | 77 +++++++ .../org/onosproject/vtnrsc/SegmentationId.java | 77 +++++++ .../main/java/org/onosproject/vtnrsc/Subnet.java | 129 ++++++++++++ .../main/java/org/onosproject/vtnrsc/SubnetId.java | 76 +++++++ .../main/java/org/onosproject/vtnrsc/TenantId.java | 77 +++++++ .../java/org/onosproject/vtnrsc/TenantNetwork.java | 130 ++++++++++++ .../org/onosproject/vtnrsc/TenantNetworkId.java | 76 +++++++ .../java/org/onosproject/vtnrsc/VirtualPort.java | 156 ++++++++++++++ .../java/org/onosproject/vtnrsc/VirtualPortId.java | 70 +++++++ .../cli/network/TenantNetworkCreateCommand.java | 97 +++++++++ .../cli/network/TenantNetworkQueryCommand.java | 60 ++++++ .../cli/network/TenantNetworkRemoveCommand.java | 45 ++++ .../cli/network/TenantNetworkUpdateCommand.java | 99 +++++++++ .../vtnrsc/cli/network/package-info.java | 20 ++ .../vtnrsc/cli/subnet/SubnetCreateCommand.java | 118 +++++++++++ .../vtnrsc/cli/subnet/SubnetQueryCommand.java | 61 ++++++ .../vtnrsc/cli/subnet/SubnetRemoveCommand.java | 46 +++++ .../vtnrsc/cli/subnet/SubnetUpdateCommand.java | 118 +++++++++++ .../vtnrsc/cli/subnet/package-info.java | 20 ++ .../cli/virtualport/VirtualPortCreateCommand.java | 134 ++++++++++++ .../cli/virtualport/VirtualPortQueryCommand.java | 94 +++++++++ .../cli/virtualport/VirtualPortRemoveCommand.java | 45 ++++ .../cli/virtualport/VirtualPortUpdateCommand.java | 135 ++++++++++++ .../vtnrsc/cli/virtualport/package-info.java | 20 ++ .../java/org/onosproject/vtnrsc/package-info.java | 20 ++ .../onosproject/vtnrsc/subnet/SubnetService.java | 72 +++++++ .../vtnrsc/subnet/impl/SubnetManager.java | 183 ++++++++++++++++ .../vtnrsc/subnet/impl/package-info.java | 20 ++ .../onosproject/vtnrsc/subnet/package-info.java | 20 ++ .../vtnrsc/tenantnetwork/TenantNetworkService.java | 80 +++++++ .../tenantnetwork/impl/TenantNetworkManager.java | 167 +++++++++++++++ .../vtnrsc/tenantnetwork/impl/package-info.java | 20 ++ .../vtnrsc/tenantnetwork/package-info.java | 20 ++ .../vtnrsc/tunnel/TunnelConfigService.java | 72 +++++++ .../onosproject/vtnrsc/tunnel/package-info.java | 20 ++ .../vtnrsc/virtualport/VirtualPortService.java | 100 +++++++++ .../virtualport/impl/VirtualPortManager.java | 208 +++++++++++++++++++ .../vtnrsc/virtualport/impl/package-info.java | 20 ++ .../vtnrsc/virtualport/package-info.java | 20 ++ .../vtnrsc/web/AllocationPoolsCodec.java | 40 ++++ .../vtnrsc/web/AllowedAddressPairCodec.java | 40 ++++ .../org/onosproject/vtnrsc/web/FixedIpCodec.java | 40 ++++ .../onosproject/vtnrsc/web/HostRoutesCodec.java | 40 ++++ .../onosproject/vtnrsc/web/SecurityGroupCodec.java | 39 ++++ .../org/onosproject/vtnrsc/web/SubnetCodec.java | 53 +++++ .../onosproject/vtnrsc/web/TenantNetworkCodec.java | 47 +++++ .../onosproject/vtnrsc/web/VirtualPortCodec.java | 57 +++++ .../org/onosproject/vtnrsc/web/package-info.java | 20 ++ .../resources/OSGI-INF/blueprint/shell-config.xml | 56 +++++ 61 files changed, 4656 insertions(+) create mode 100644 framework/src/onos/apps/vtn/vtnrsc/pom.xml create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/AllocationPool.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/AllowedAddressPair.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/BindingHostId.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultAllocationPool.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultHostRoute.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultSubnet.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultTenantNetwork.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultVirtualPort.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/FixedIp.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/HostRoute.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PhysicalNetwork.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/SecurityGroup.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/SegmentationId.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/Subnet.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/SubnetId.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/TenantId.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/TenantNetwork.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/TenantNetworkId.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/VirtualPort.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/VirtualPortId.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/network/TenantNetworkCreateCommand.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/network/TenantNetworkQueryCommand.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/network/TenantNetworkRemoveCommand.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/network/TenantNetworkUpdateCommand.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/network/package-info.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/subnet/SubnetCreateCommand.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/subnet/SubnetQueryCommand.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/subnet/SubnetRemoveCommand.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/subnet/SubnetUpdateCommand.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/subnet/package-info.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/virtualport/VirtualPortCreateCommand.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/virtualport/VirtualPortQueryCommand.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/virtualport/VirtualPortRemoveCommand.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/virtualport/VirtualPortUpdateCommand.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/virtualport/package-info.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/package-info.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/subnet/SubnetService.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/subnet/impl/SubnetManager.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/subnet/impl/package-info.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/subnet/package-info.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/tenantnetwork/TenantNetworkService.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/tenantnetwork/impl/TenantNetworkManager.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/tenantnetwork/impl/package-info.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/tenantnetwork/package-info.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/tunnel/TunnelConfigService.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/tunnel/package-info.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/virtualport/VirtualPortService.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/virtualport/impl/VirtualPortManager.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/virtualport/impl/package-info.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/virtualport/package-info.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/AllocationPoolsCodec.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/AllowedAddressPairCodec.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/FixedIpCodec.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/HostRoutesCodec.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/SecurityGroupCodec.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/SubnetCodec.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/TenantNetworkCodec.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/VirtualPortCodec.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/package-info.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/resources/OSGI-INF/blueprint/shell-config.xml (limited to 'framework/src/onos/apps/vtn/vtnrsc') diff --git a/framework/src/onos/apps/vtn/vtnrsc/pom.xml b/framework/src/onos/apps/vtn/vtnrsc/pom.xml new file mode 100644 index 00000000..8696295c --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/pom.xml @@ -0,0 +1,56 @@ + + + + 4.0.0 + + org.onosproject + onos-app-vtn + 1.4.0-SNAPSHOT + ../pom.xml + + + + onos-app-vtn-rsc + bundle + + + + org.onosproject + onos-api + + + org.onosproject + onos-cli + ${project.version} + + + org.apache.felix + org.apache.felix.scr.annotations + + + org.apache.karaf.shell + org.apache.karaf.shell.console + + + org.onosproject + onos-core-serializers + ${project.version} + + + diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/AllocationPool.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/AllocationPool.java new file mode 100644 index 00000000..3d6ba8e8 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/AllocationPool.java @@ -0,0 +1,38 @@ +/* + * 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; + +import org.onlab.packet.IpAddress; + +/** + * The continuous IP address range between the start address and the end address for the allocation pools. + */ +public interface AllocationPool { + + /** + * The start address for the allocation pool. + * + * @return startIp + */ + IpAddress startIp(); + + /** + * The end address for the allocation pool. + * + * @return endIp + */ + IpAddress endIp(); +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/AllowedAddressPair.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/AllowedAddressPair.java new file mode 100644 index 00000000..4e1028d8 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/AllowedAddressPair.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; + +import static com.google.common.base.MoreObjects.toStringHelper; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Objects; + +import org.onlab.packet.IpAddress; +import org.onlab.packet.MacAddress; + +/** + * Immutable representation of a allowed address pair. + */ +public final class AllowedAddressPair { + private final IpAddress ip; + private final MacAddress mac; + // Public construction is prohibited + private AllowedAddressPair(IpAddress ip, MacAddress mac) { + checkNotNull(ip, "IpAddress cannot be null"); + checkNotNull(mac, "MacAddress cannot be null"); + this.ip = ip; + this.mac = mac; + } + /** + * Returns the AllowedAddressPair ip address. + * + * @return ip address + */ + public IpAddress ip() { + return ip; + } + + /** + * Returns the AllowedAddressPair MAC address. + * + * @return MAC address + */ + public MacAddress mac() { + return mac; + } + + + /** + * Creates a allowedAddressPair using the supplied ipAddress & + * macAddress. + * + * @param ip IP address + * @param mac MAC address + * @return AllowedAddressPair + */ + public static AllowedAddressPair allowedAddressPair(IpAddress ip, + MacAddress mac) { + return new AllowedAddressPair(ip, mac); + } + + @Override + public int hashCode() { + return Objects.hash(ip, mac); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof AllowedAddressPair) { + final AllowedAddressPair that = (AllowedAddressPair) obj; + return Objects.equals(this.ip, that.ip) + && Objects.equals(this.mac, that.mac); + } + return false; + } + + @Override + public String toString() { + return toStringHelper(this).add("ip", ip).add("mac", mac).toString(); + } + +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/BindingHostId.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/BindingHostId.java new file mode 100644 index 00000000..c715d08a --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/BindingHostId.java @@ -0,0 +1,72 @@ +/* + * 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; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Objects; + +public final class BindingHostId { + private final String bindingHostId; + + // Public construction is prohibited + private BindingHostId(String bindingHostId) { + checkNotNull(bindingHostId, "BindingHosttId cannot be null"); + this.bindingHostId = bindingHostId; + } + + /** + * Creates a BindingHostId identifier. + * + * @param bindingHostId the bindingHostId identifier + * @return the bindingHostId identifier + */ + public static BindingHostId bindingHostId(String bindingHostId) { + return new BindingHostId(bindingHostId); + } + + /** + * Returns the bindingHostId identifier. + * + * @return the bindingHostId identifier + */ + public String bindingHostId() { + return bindingHostId; + } + + @Override + public int hashCode() { + return Objects.hash(bindingHostId); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof BindingHostId) { + final BindingHostId that = (BindingHostId) obj; + return this.getClass() == that.getClass() + && Objects.equals(this.bindingHostId, that.bindingHostId); + } + return false; + } + + @Override + public String toString() { + return bindingHostId; + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultAllocationPool.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultAllocationPool.java new file mode 100644 index 00000000..8a480194 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultAllocationPool.java @@ -0,0 +1,81 @@ +/* + * 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; + +import static com.google.common.base.MoreObjects.toStringHelper; +import static com.google.common.base.Preconditions.checkNotNull; +import java.util.Objects; + +import org.onlab.packet.IpAddress; + +/** + * The continuous IP address range between the start address and the end address + * for the allocation pools. + */ +public final class DefaultAllocationPool implements AllocationPool { + + private final IpAddress startIp; + private final IpAddress endIp; + + /** + * Creates an AllocationPool by using the start IP address and the end IP + * address. + * + * @param startIp the start IP address of the allocation pool + * @param endIp the end IP address of the allocation pool + */ + public DefaultAllocationPool(IpAddress startIp, IpAddress endIp) { + checkNotNull(startIp, "StartIp cannot be null"); + checkNotNull(endIp, "EndIp cannot be null"); + this.startIp = startIp; + this.endIp = endIp; + } + + @Override + public IpAddress startIp() { + return startIp; + } + + @Override + public IpAddress endIp() { + return endIp; + } + + @Override + public int hashCode() { + return Objects.hash(startIp, endIp); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof DefaultAllocationPool) { + final DefaultAllocationPool other = (DefaultAllocationPool) obj; + return Objects.equals(this.startIp, other.startIp) + && Objects.equals(this.endIp, other.endIp); + } + return false; + } + + @Override + public String toString() { + return toStringHelper(this).add("startIp", startIp).add("endIp", endIp) + .toString(); + } +} + diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultHostRoute.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultHostRoute.java new file mode 100644 index 00000000..8679100d --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultHostRoute.java @@ -0,0 +1,79 @@ +/* + * 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; + +import static com.google.common.base.MoreObjects.toStringHelper; + +import java.util.Objects; + +import org.onlab.packet.IpAddress; +import org.onlab.packet.IpPrefix; + +/** + * Host route dictionaries for the subnet. + */ +public final class DefaultHostRoute implements HostRoute { + + private final IpAddress nexthop; + private final IpPrefix destination; + + /** + * + * Creates a DefaultHostRoute by using the next hop and the destination. + * + * @param nexthop of the DefaultHostRoute + * @param destination of the DefaultHostRoute + */ + public DefaultHostRoute(IpAddress nexthop, IpPrefix destination) { + this.nexthop = nexthop; + this.destination = destination; + } + + @Override + public IpAddress nexthop() { + return nexthop; + } + + @Override + public IpPrefix destination() { + return destination; + } + + @Override + public String toString() { + return toStringHelper(this).add("nexthop", nexthop) + .add("destination", destination).toString(); + } + + @Override + public int hashCode() { + return Objects.hash(nexthop, destination); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof DefaultHostRoute) { + final DefaultHostRoute other = (DefaultHostRoute) obj; + return Objects.equals(this.nexthop, other.nexthop) + && Objects.equals(this.destination, other.destination); + } + return false; + } + +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultSubnet.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultSubnet.java new file mode 100644 index 00000000..6049b558 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultSubnet.java @@ -0,0 +1,183 @@ +/* + * 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; + +import static com.google.common.base.MoreObjects.toStringHelper; + +import java.util.Objects; +import java.util.Set; + +import org.onlab.packet.IpAddress; +import org.onlab.packet.IpAddress.Version; +import org.onlab.packet.IpPrefix; + +/** + * Default implementation of Subnet interface . + */ +public final class DefaultSubnet implements Subnet { + private final SubnetId id; + private final String subnetName; + private final TenantNetworkId networkId; + private final TenantId tenantId; + private final Version ipVersion; + private final IpPrefix cidr; + private final IpAddress gatewayIp; + private final boolean dhcpEnabled; + private final boolean shared; + private final Mode ipV6AddressMode; + private final Mode ipV6RaMode; + private final Set hostRoutes; + private final Set allocationPools; + + /** + * Creates a subnet object. + * + * @param id subnet identifier + * @param subnetName the name of subnet + * @param networkId network identifier + * @param tenantId tenant identifier + * @param ipVersion Version of ipv4 or ipv6 + * @param cidr the cidr + * @param gatewayIp gateway ip + * @param dhcpEnabled dhcp enabled or not + * @param shared indicates whether this network is shared across all + * tenants, By default, only administrative user can change this + * value + * @param hostRoutes a collection of host routes + * @param ipV6AddressMode ipV6AddressMode + * @param ipV6RaMode ipV6RaMode + * @param allocationPoolsIt a collection of allocationPools + */ + public DefaultSubnet(SubnetId id, String subnetName, + TenantNetworkId networkId, TenantId tenantId, + Version ipVersion, IpPrefix cidr, IpAddress gatewayIp, + boolean dhcpEnabled, boolean shared, + Set hostRoutes, Mode ipV6AddressMode, + Mode ipV6RaMode, + Set allocationPoolsIt) { + this.id = id; + this.subnetName = subnetName; + this.networkId = networkId; + this.tenantId = tenantId; + this.ipVersion = ipVersion; + this.cidr = cidr; + this.gatewayIp = gatewayIp; + this.dhcpEnabled = dhcpEnabled; + this.shared = shared; + this.ipV6AddressMode = ipV6AddressMode; + this.ipV6RaMode = ipV6RaMode; + this.hostRoutes = hostRoutes; + this.allocationPools = allocationPoolsIt; + } + + @Override + public SubnetId id() { + return id; + } + + @Override + public String subnetName() { + return subnetName; + } + + @Override + public TenantNetworkId networkId() { + return networkId; + } + + @Override + public TenantId tenantId() { + return tenantId; + } + + @Override + public Version ipVersion() { + return ipVersion; + } + + @Override + public IpPrefix cidr() { + return cidr; + } + + @Override + public IpAddress gatewayIp() { + return gatewayIp; + } + + @Override + public boolean dhcpEnabled() { + return dhcpEnabled; + } + + @Override + public boolean shared() { + return shared; + } + + @Override + public Iterable hostRoutes() { + return hostRoutes; + } + + @Override + public Mode ipV6AddressMode() { + return ipV6AddressMode; + } + + @Override + public Mode ipV6RaMode() { + return ipV6RaMode; + } + + @Override + public Iterable allocationPools() { + return allocationPools; + } + + @Override + public int hashCode() { + return Objects.hash(id, subnetName, ipVersion, cidr, gatewayIp, + dhcpEnabled, shared, tenantId); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof DefaultSubnet) { + final DefaultSubnet that = (DefaultSubnet) obj; + return Objects.equals(this.id, that.id) + && Objects.equals(this.subnetName, that.subnetName) + && Objects.equals(this.ipVersion, that.ipVersion) + && Objects.equals(this.cidr, that.cidr) + && Objects.equals(this.shared, that.shared) + && Objects.equals(this.gatewayIp, that.gatewayIp) + && Objects.equals(this.dhcpEnabled, that.dhcpEnabled); + } + return false; + } + + @Override + public String toString() { + return toStringHelper(this).add("id", id).add("subnetName", subnetName) + .add("ipVersion", ipVersion).add("cidr", cidr) + .add("shared", shared).add("gatewayIp", gatewayIp) + .add("dhcpEnabled", dhcpEnabled).toString(); + } + +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultTenantNetwork.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultTenantNetwork.java new file mode 100644 index 00000000..8c941ea2 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultTenantNetwork.java @@ -0,0 +1,160 @@ +/* + * 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; + +import static com.google.common.base.MoreObjects.toStringHelper; + +import java.util.Objects; + +/** + * Default implementation of TenantNetwork interface. + */ +public final class DefaultTenantNetwork implements TenantNetwork { + private final TenantNetworkId id; + private final String name; + private final boolean adminStateUp; + private final State state; + private final boolean shared; + private final Type type; + private final TenantId tenantId; + private final boolean routerExternal; + private final PhysicalNetwork physicalNetwork; + private final SegmentationId segmentationId; + + /** + * Creates a neutronNetwork element attributed to the specified provider. + * + * @param id network identifier + * @param name the network name + * @param adminStateUp administrative state of the network + * @param state the network state + * @param shared indicates whether this network is shared across all + * tenants, By default, only administrative user can change this + * value + * @param tenantId tenant identifier + * @param routerExternal network routerExternal + * @param type the network type + * @param physicalNetwork physicalNetwork identifier + * @param segmentationId segmentation identifier + */ + public DefaultTenantNetwork(TenantNetworkId id, String name, + boolean adminStateUp, State state, + boolean shared, TenantId tenantId, + boolean routerExternal, Type type, + PhysicalNetwork physicalNetwork, + SegmentationId segmentationId) { + this.id = id; + this.name = name; + this.adminStateUp = adminStateUp; + this.state = state; + this.shared = shared; + this.type = type; + this.tenantId = tenantId; + this.routerExternal = routerExternal; + this.physicalNetwork = physicalNetwork; + this.segmentationId = segmentationId; + } + + @Override + public TenantNetworkId id() { + return id; + } + + @Override + public String name() { + return name; + } + + @Override + public boolean adminStateUp() { + return adminStateUp; + } + + @Override + public State state() { + return state; + } + + @Override + public boolean shared() { + return shared; + } + + @Override + public TenantId tenantId() { + return tenantId; + } + + @Override + public boolean routerExternal() { + return routerExternal; + } + + @Override + public Type type() { + return type; + } + + @Override + public PhysicalNetwork physicalNetwork() { + return physicalNetwork; + } + + @Override + public SegmentationId segmentationId() { + return segmentationId; + } + + @Override + public int hashCode() { + return Objects.hash(id, name, adminStateUp, state, shared, tenantId, + routerExternal, type, physicalNetwork, + segmentationId); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof DefaultTenantNetwork) { + final DefaultTenantNetwork that = (DefaultTenantNetwork) obj; + return Objects.equals(this.id, that.id) + && Objects.equals(this.name, that.name) + && Objects.equals(this.adminStateUp, that.adminStateUp) + && Objects.equals(this.state, that.state) + && Objects.equals(this.shared, that.shared) + && Objects.equals(this.tenantId, that.tenantId) + && Objects.equals(this.routerExternal, that.routerExternal) + && Objects.equals(this.type, that.type) + && Objects.equals(this.physicalNetwork, + that.physicalNetwork) + && Objects.equals(this.segmentationId, that.segmentationId); + } + return false; + } + + @Override + public String toString() { + return toStringHelper(this).add("id", id).add("name", name) + .add("adminStateUp", adminStateUp).add("state", state) + .add("shared", shared).add("tenantId", tenantId) + .add("routeExternal", routerExternal).add("type", type) + .add("physicalNetwork", physicalNetwork) + .add("segmentationId", segmentationId).toString(); + } + +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultVirtualPort.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultVirtualPort.java new file mode 100644 index 00000000..9ee85da7 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultVirtualPort.java @@ -0,0 +1,229 @@ +/* + * 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; + +import static com.google.common.base.MoreObjects.toStringHelper; + +import java.util.Collection; +import java.util.Map; +import java.util.Objects; +import java.util.Set; + +import org.onlab.packet.MacAddress; +import org.onosproject.net.DeviceId; + +/** + * Default implementation of VirtualPort interface . + */ +public final class DefaultVirtualPort implements VirtualPort { + private final VirtualPortId id; + private final TenantNetworkId networkId; + private final Boolean adminStateUp; + private final String name; + private final State state; + private final MacAddress macAddress; + private final TenantId tenantId; + private final String deviceOwner; + private final DeviceId deviceId; + private final Set fixedIps; + private final BindingHostId bindingHostId; + private final String bindingVnicType; + private final String bindingVifType; + private final String bindingVifDetails; + private final Set allowedAddressPairs; + private final Set securityGroups; + + /** + * Creates a VirtualPort object. + * + * @param id the virtual port identifier + * @param networkId the network identifier + * @param adminStateUp adminStateup true or false + * @param strMap the map of properties of virtual port + * @param state virtual port state + * @param macAddress the MAC address + * @param tenantId the tenant identifier + * @param deviceId the device identifier + * @param fixedIps set of fixed IP + * @param bindingHostId the binding host identifier + * @param allowedAddressPairs the collection of allowdeAddressPairs + * @param securityGroups the collection of securityGroups + */ + public DefaultVirtualPort(VirtualPortId id, + TenantNetworkId networkId, + Boolean adminStateUp, + Map strMap, + State state, + MacAddress macAddress, + TenantId tenantId, + DeviceId deviceId, + Set fixedIps, + BindingHostId bindingHostId, + Set allowedAddressPairs, + Set securityGroups) { + this.id = id; + this.networkId = networkId; + this.adminStateUp = adminStateUp; + this.name = strMap.get("name"); + this.state = state; + this.macAddress = macAddress; + this.tenantId = tenantId; + this.deviceOwner = strMap.get("deviceOwner"); + this.deviceId = deviceId; + this.fixedIps = fixedIps; + this.bindingHostId = bindingHostId; + this.bindingVnicType = strMap.get("bindingVnicType"); + this.bindingVifType = strMap.get("bindingVifType"); + this.bindingVifDetails = strMap.get("bindingVifDetails"); + this.allowedAddressPairs = allowedAddressPairs; + this.securityGroups = securityGroups; + } + + @Override + public VirtualPortId portId() { + return id; + } + + @Override + public TenantNetworkId networkId() { + return networkId; + } + + @Override + public String name() { + return name; + } + + @Override + public boolean adminStateUp() { + return adminStateUp; + } + + @Override + public State state() { + return state; + } + + @Override + public MacAddress macAddress() { + return macAddress; + } + + @Override + public TenantId tenantId() { + return tenantId; + } + + @Override + public DeviceId deviceId() { + return deviceId; + } + + @Override + public String deviceOwner() { + return deviceOwner; + } + + @Override + public Collection allowedAddressPairs() { + return allowedAddressPairs; + } + + @Override + public Set fixedIps() { + return fixedIps; + } + + @Override + public BindingHostId bindingHostId() { + return bindingHostId; + } + + @Override + public String bindingVnicType() { + return bindingVifType; + } + + @Override + public String bindingVifType() { + return bindingVifType; + } + + @Override + public String bindingVifDetails() { + return bindingVifDetails; + } + + @Override + public Collection securityGroups() { + return securityGroups; + } + + @Override + public int hashCode() { + return Objects.hash(id, networkId, adminStateUp, name, state, + macAddress, tenantId, deviceId, deviceOwner, + allowedAddressPairs, fixedIps, bindingHostId, + bindingVnicType, bindingVifType, bindingVifDetails, + securityGroups); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof DefaultVirtualPort) { + final DefaultVirtualPort that = (DefaultVirtualPort) obj; + return Objects.equals(this.id, that.id) + && Objects.equals(this.networkId, that.networkId) + && Objects.equals(this.adminStateUp, that.adminStateUp) + && Objects.equals(this.state, that.state) + && Objects.equals(this.name, that.name) + && Objects.equals(this.tenantId, that.tenantId) + && Objects.equals(this.macAddress, that.macAddress) + && Objects.equals(this.deviceId, that.deviceId) + && Objects.equals(this.deviceOwner, that.deviceOwner) + && Objects.equals(this.allowedAddressPairs, + that.allowedAddressPairs) + && Objects.equals(this.fixedIps, that.fixedIps) + && Objects.equals(this.bindingHostId, that.bindingHostId) + && Objects.equals(this.bindingVifDetails, + that.bindingVifDetails) + && Objects.equals(this.bindingVifType, that.bindingVifType) + && Objects.equals(this.bindingVnicType, + that.bindingVnicType) + && Objects.equals(this.securityGroups, that.securityGroups); + } + return false; + } + + @Override + public String toString() { + return toStringHelper(this).add("id", id).add("network_id", networkId) + .add("adminStateUp", adminStateUp).add("state", state) + .add("name", name).add("state", state) + .add("macAddress", macAddress).add("tenantId", tenantId) + .add("deviced", deviceId).add("deviceOwner", deviceOwner) + .add("allowedAddressPairs", allowedAddressPairs) + .add("fixedIp", fixedIps).add("bindingHostId", bindingHostId) + .add("bindingVnicType", bindingVnicType) + .add("bindingVifDetails", bindingVifDetails) + .add("bindingVifType", bindingVifType) + .add("securityGroups", securityGroups).toString(); + } + +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/FixedIp.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/FixedIp.java new file mode 100644 index 00000000..c6569a7b --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/FixedIp.java @@ -0,0 +1,93 @@ +/* + * 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; + +import static com.google.common.base.MoreObjects.toStringHelper; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Objects; + +import org.onlab.packet.IpAddress; + +/** + * Immutable representation of a IP address for the port, Include the IP address + * and subnet identity. + */ +public final class FixedIp { + private final SubnetId subnetId; + private final IpAddress ip; + // Public construction is prohibited + private FixedIp(SubnetId subnetId, IpAddress ip) { + checkNotNull(subnetId, "SubnetId cannot be null"); + checkNotNull(ip, "IpAddress cannot be null"); + this.subnetId = subnetId; + this.ip = ip; + } + + /** + * Returns the FixedIp subnet identifier. + * + * @return subnet identifier + */ + public SubnetId subnetId() { + return subnetId; + } + + /** + * Returns the FixedIp IP address. + * + * @return IP address + */ + public IpAddress ip() { + return ip; + } + + /** + * Creates a fixed ip using the supplied fixedIp. + * + * @param subnetId subnet identity + * @param ip IP address + * @return FixedIp + */ + public static FixedIp fixedIp(SubnetId subnetId, IpAddress ip) { + return new FixedIp(subnetId, ip); + } + + @Override + public int hashCode() { + return Objects.hash(subnetId, ip); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof FixedIp) { + final FixedIp that = (FixedIp) obj; + return Objects.equals(this.subnetId, that.subnetId) + && Objects.equals(this.ip, that.ip); + } + return false; + } + + @Override + public String toString() { + return toStringHelper(this).add("subnetId", subnetId).add("ip", ip) + .toString(); + } + +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/HostRoute.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/HostRoute.java new file mode 100644 index 00000000..b18cb950 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/HostRoute.java @@ -0,0 +1,39 @@ +/* + * 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; + +import org.onlab.packet.IpAddress; +import org.onlab.packet.IpPrefix; + +/** + * Host route dictionaries for the subnet. + */ +public interface HostRoute { + + /** + * Returns the next hop address. + * + * @return next hop address + */ + IpAddress nexthop(); + + /** + * Returns the destination address. + * + * @return destination address + */ + IpPrefix destination(); +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PhysicalNetwork.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PhysicalNetwork.java new file mode 100644 index 00000000..e96e666a --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PhysicalNetwork.java @@ -0,0 +1,78 @@ +/* + * 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; + +import java.util.Objects; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * Immutable representation of a physical network identity. + */ +public final class PhysicalNetwork { + + private final String physicalNetwork; + + // Public construction is prohibited + private PhysicalNetwork(String physicalNetwork) { + checkNotNull(physicalNetwork, "PhysicalNetwork cannot be null"); + this.physicalNetwork = physicalNetwork; + } + + /** + * Creates a PhysicalNetwork object. + * + * @param physicalNetwork physical network + * @return physical network + */ + public static PhysicalNetwork physicalNetwork(String physicalNetwork) { + return new PhysicalNetwork(physicalNetwork); + } + + /** + * Returns a physicalNetwork. + * + * @return physical network + */ + public String physicalNetwork() { + return physicalNetwork; + } + + @Override + public int hashCode() { + return Objects.hash(physicalNetwork); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof PhysicalNetwork) { + final PhysicalNetwork that = (PhysicalNetwork) obj; + return this.getClass() == that.getClass() + && Objects.equals(this.physicalNetwork, + that.physicalNetwork); + } + return false; + } + + @Override + public String toString() { + return physicalNetwork; + } + +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/SecurityGroup.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/SecurityGroup.java new file mode 100644 index 00000000..9ec1dc63 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/SecurityGroup.java @@ -0,0 +1,77 @@ +/* + * 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; + +import java.util.Objects; + +import static com.google.common.base.MoreObjects.toStringHelper; +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * Immutable representation of a security group. + */ +public final class SecurityGroup { + private final String securityGroup; + + /** + * Returns the securityGroup. + * + * @return securityGroup + */ + public String securityGroup() { + return securityGroup; + } + // Public construction is prohibited + private SecurityGroup(String securityGroup) { + checkNotNull(securityGroup, "SecurityGroup cannot be null"); + this.securityGroup = securityGroup; + } + + /** + * Creates a securityGroup using the supplied securityGroup. + * + * @param securityGroup security group + * @return securityGroup + */ + public static SecurityGroup securityGroup(String securityGroup) { + return new SecurityGroup(securityGroup); + } + + @Override + public int hashCode() { + return Objects.hash(securityGroup); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof SecurityGroup) { + final SecurityGroup that = (SecurityGroup) obj; + return this.getClass() == that.getClass() + && Objects.equals(this.securityGroup, that.securityGroup); + } + return false; + } + + @Override + public String toString() { + return toStringHelper(this).add("securityGroup", securityGroup) + .toString(); + } + +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/SegmentationId.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/SegmentationId.java new file mode 100644 index 00000000..a076265f --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/SegmentationId.java @@ -0,0 +1,77 @@ +/* + * 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; + +import java.util.Objects; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * Immutable representation of a Segmentation identifier. + */ +public final class SegmentationId { + + private final String segmentationId; + + // Public construction is prohibited + private SegmentationId(String segmentationId) { + checkNotNull(segmentationId, "SegmentationId cannot be null"); + this.segmentationId = segmentationId; + } + + /** + * Creates a SegmentationId object. + * + * @param segmentationId segmentation identifier + * @return SegmentationId + */ + public static SegmentationId segmentationId(String segmentationId) { + return new SegmentationId(segmentationId); + } + + /** + * Returns the segmentation identifier. + * + * @return segmentationId + */ + public String segmentationId() { + return segmentationId; + } + + @Override + public int hashCode() { + return Objects.hash(segmentationId); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof SegmentationId) { + final SegmentationId that = (SegmentationId) obj; + return this.getClass() == that.getClass() + && Objects.equals(this.segmentationId, that.segmentationId); + } + return false; + } + + @Override + public String toString() { + return segmentationId; + } + +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/Subnet.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/Subnet.java new file mode 100644 index 00000000..f563a78f --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/Subnet.java @@ -0,0 +1,129 @@ +/* + * 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; + +import org.onlab.packet.IpAddress; +import org.onlab.packet.IpAddress.Version; +import org.onlab.packet.IpPrefix; + +/** + * Representation of a subnet. + */ +public interface Subnet { + + /** + * Coarse classification of the type of the ipV6Mode. + */ + enum Mode { + DHCPV6_STATEFUL, DHCPV6_STATELESS, SLAAC + } + + /** + * Returns the subnet identifier. + * + * @return identifier + */ + SubnetId id(); + + /** + * Returns the name of the subnet. + * + * @return subnetName + */ + String subnetName(); + + /** + * Returns the network identifier. + * + * @return the network identifier + */ + TenantNetworkId networkId(); + + /** + * Returns tenant identifier. + * + * @return the tenant identifier + */ + TenantId tenantId(); + + /** + * Returns the IP version, which is 4 or 6. + * + * @return ipVersion + */ + Version ipVersion(); + + /** + * Returns the cidr. + * + * @return cidr + */ + IpPrefix cidr(); + + /** + * Returns the gateway IP address. + * + * @return gatewayIp + */ + IpAddress gatewayIp(); + + /** + * Returns true if DHCP is enabled and return false if DHCP is disabled. + * + * @return true or false + */ + boolean dhcpEnabled(); + + /** + * Indicates whether this tenantNetwork is shared across all tenants. By + * default, only administrative user can change this value. + * + * @return true or false + */ + boolean shared(); + + /** + * Returns a collection of hostRoutes. + * + * @return a collection of hostRoutes + */ + Iterable hostRoutes(); + + /** + * Returns the ipV6AddressMode. A valid value is dhcpv6-stateful, + * dhcpv6-stateless, or slaac. + * + * @return ipV6AddressMode whose value is dhcpv6-stateful, dhcpv6-stateless + * or slaac + */ + Mode ipV6AddressMode(); + + /** + * Returns the ipV6RaMode.A valid value is dhcpv6-stateful, + * dhcpv6-stateless, or slaac. + * + * @return ipV6RaMode whose value is dhcpv6-stateful, dhcpv6-stateless or + * slaac + */ + Mode ipV6RaMode(); + + /** + * Returns a collection of allocation_pools. + * + * @return a collection of allocationPools + */ + Iterable allocationPools(); +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/SubnetId.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/SubnetId.java new file mode 100644 index 00000000..4bcc3329 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/SubnetId.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; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Objects; + +/** + * Immutable representation of a subnet identifier. + */ +public final class SubnetId { + + private final String subnetId; + + // Public construction is prohibited + private SubnetId(String subnetId) { + checkNotNull(subnetId, "SubnetId cannot be null"); + this.subnetId = subnetId; + } + + /** + * Creates a Subnet identifier. + * + * @param subnetId the subnet identifier + * @return the subnet identifier + */ + public static SubnetId subnetId(String subnetId) { + return new SubnetId(subnetId); + } + + /** + * Returns the subnet identifier. + * + * @return the subnet identifier + */ + public String subnetId() { + return subnetId; + } + + @Override + public int hashCode() { + return Objects.hash(subnetId); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof SubnetId) { + final SubnetId that = (SubnetId) obj; + return this.getClass() == that.getClass() + && Objects.equals(this.subnetId, that.subnetId); + } + return false; + } + + @Override + public String toString() { + return subnetId; + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/TenantId.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/TenantId.java new file mode 100644 index 00000000..c4d99e49 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/TenantId.java @@ -0,0 +1,77 @@ +/* + * 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; + +import java.util.Objects; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * Immutable representation of a tenant identifier. + */ +public final class TenantId { + + private final String tenantId; + + // Public construction is prohibited + private TenantId(String tenantId) { + this.tenantId = tenantId; + } + + /** + * Creates a network id using the tenantid. + * + * @param tenantid network String + * @return TenantId + */ + public static TenantId tenantId(String tenantid) { + checkNotNull(tenantid, "Tenantid can not be null"); + return new TenantId(tenantid); + } + + /** + * Returns the tenant identifier. + * + * @return the tenant identifier + */ + public String tenantId() { + return tenantId; + } + + @Override + public int hashCode() { + return Objects.hash(tenantId); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof TenantId) { + final TenantId that = (TenantId) obj; + return this.getClass() == that.getClass() + && Objects.equals(this.tenantId, that.tenantId); + } + return false; + } + + @Override + public String toString() { + return tenantId; + } + +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/TenantNetwork.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/TenantNetwork.java new file mode 100644 index 00000000..256352f4 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/TenantNetwork.java @@ -0,0 +1,130 @@ +/* + * 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; + +/** + * Representation of the tenantNetwork. + */ +public interface TenantNetwork { + + /** + * Coarse classification of the state of the tenantNetwork. + */ + enum State { + /** + * Signifies that a tenantNetwork is currently active.This state means + * that this network is available. + */ + ACTIVE, + /** + * Signifies that a tenantNetwork is currently built. + */ + BUILD, + /** + * Signifies that a tenantNetwork is currently unavailable. + */ + DOWN, + /** + * Signifies that a tenantNetwork is currently error. + */ + ERROR + } + + /** + * Coarse classification of the type of the tenantNetwork. + */ + enum Type { + /** + * Signifies that a tenantNetwork is local. + */ + LOCAL + } + + /** + * Returns the tenantNetwork identifier. + * + * @return tenantNetwork identifier + */ + TenantNetworkId id(); + + /** + * Returns the tenantNetwork name. + * + * @return tenantNetwork name + */ + String name(); + + /** + * Returns the administrative state of the tenantNetwork,which is up(true) + * or down(false). + * + * @return true or false + */ + boolean adminStateUp(); + + /** + * Returns the tenantNetwork state. + * + * @return tenant network state + */ + State state(); + + /** + * Indicates whether this tenantNetwork is shared across all tenants. By + * default,only administrative user can change this value. + * + * @return true or false + */ + boolean shared(); + + /** + * Returns the UUID of the tenant that will own the tenantNetwork. This + * tenant can be different from the tenant that makes the create + * tenantNetwork request. + * + * @return the tenant identifier + */ + TenantId tenantId(); + + /** + * Returns the routerExternal.Indicates whether this network is externally + * accessible. + * + * @return true or false + */ + boolean routerExternal(); + + /** + * Returns the tenantNetwork Type. + * + * @return tenantNetwork Type + */ + Type type(); + + /** + * Returns the tenantNetwork physical network. + * + * @return tenantNetwork physical network + */ + PhysicalNetwork physicalNetwork(); + + /** + * Returns the tenantNetwork segmentation id. + * + * @return tenantNetwork segmentation id + */ + SegmentationId segmentationId(); +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/TenantNetworkId.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/TenantNetworkId.java new file mode 100644 index 00000000..fbb9e480 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/TenantNetworkId.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; + +import java.util.Objects; +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * Immutable representation of a tenantNetwork identity. + */ +public final class TenantNetworkId { + + private final String networkId; + + // Public construction is prohibited + private TenantNetworkId(String networkId) { + this.networkId = networkId; + } + + /** + * Creates a TenantNetwork identifier. + * + * @param networkId tenantNetwork identify string + * @return the attached tenantNetwork identifier + */ + public static TenantNetworkId networkId(String networkId) { + checkNotNull(networkId, "Networkid cannot be null"); + return new TenantNetworkId(networkId); + } + + /** + * Returns tenantNetwork identifier. + * + * @return the tenantNetwork identifier + */ + public String networkId() { + return networkId; + } + + @Override + public int hashCode() { + return Objects.hash(networkId); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof TenantNetworkId) { + final TenantNetworkId that = (TenantNetworkId) obj; + return this.getClass() == that.getClass() + && Objects.equals(this.networkId, that.networkId); + } + return false; + } + + @Override + public String toString() { + return networkId; + } + +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/VirtualPort.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/VirtualPort.java new file mode 100644 index 00000000..d2d7c146 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/VirtualPort.java @@ -0,0 +1,156 @@ +/* + * 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; + +import java.util.Collection; +import java.util.Set; + +import org.onlab.packet.MacAddress; +import org.onosproject.net.DeviceId; + +/** + * Representation of the VirtualPort. + */ +public interface VirtualPort { + /** + * Coarse classification of the type of the virtual port. + */ + enum State { + /** + * Signifies that a virtualPort is currently active,This state mean that + * this virtualPort is available. + */ + ACTIVE, + /** + * Signifies that a virtualPort is currently unavailable. + */ + DOWN; + } + + /** + * Returns the virtualPort identifier. + * + * @return virtualPort identifier + */ + VirtualPortId portId(); + + /** + * Returns the network identifier. + * + * @return tenantNetwork identifier + */ + TenantNetworkId networkId(); + + /** + * Returns the symbolic name for the virtualPort. + * + * @return virtualPort name + */ + String name(); + + /** + * Returns the administrative status of the port,which is up(true) or + * down(false). + * + * @return true if the administrative status of the port is up + */ + boolean adminStateUp(); + + /** + * Returns the state. + * + * @return state + */ + State state(); + + /** + * Returns the MAC address. + * + * @return MAC Address + */ + MacAddress macAddress(); + + /** + * Returns the port tenantId. + * + * @return port tenantId + */ + TenantId tenantId(); + + /** + * Returns the device identifier. + * + * @return deviceId + */ + DeviceId deviceId(); + + /** + * Returns the identifier of the entity that uses this port. + * + * @return deviceOwner + */ + String deviceOwner(); + + /** + * Returns the virtualPort allowedAddressPairs. + * + * @return virtualPort allowedAddressPairs + */ + Collection allowedAddressPairs(); + + /** + * Returns set of IP addresses for the port, include the IP addresses and subnet + * identity. + * + * @return FixedIps Set of fixedIp + */ + Set fixedIps(); + + /** + * Returns the virtualPort bindinghostId. + * + * @return virtualPort bindinghostId + */ + BindingHostId bindingHostId(); + + /** + * Returns the virtualPort bindingVnicType. + * + * @return virtualPort bindingVnicType + */ + String bindingVnicType(); + + /** + * Returns the virtualPort bindingVifType. + * + * @return virtualPort bindingVifType + */ + String bindingVifType(); + + /** + * Returns the virtualPort bindingvifDetail. + * + * @return virtualPort bindingvifDetail + */ + String bindingVifDetails(); + + /** + * Returns the security groups. + * + * @return port security groups + */ + Iterable securityGroups(); +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/VirtualPortId.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/VirtualPortId.java new file mode 100644 index 00000000..3038bdff --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/VirtualPortId.java @@ -0,0 +1,70 @@ +/* + * 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; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Objects; + +/** + * Immutable representation of a virtual port identifier. + */ +public final class VirtualPortId { + private final String portId; + // Public construction is prohibited + private VirtualPortId(String virtualPortId) { + checkNotNull(virtualPortId, "VirtualPortId cannot be null"); + this.portId = virtualPortId; + } + + public String portId() { + return portId; + } + + /** + * Creates a virtualPort id using the supplied portId. + * + * @param portId virtualport identifier + * @return VirtualPortId + */ + public static VirtualPortId portId(String portId) { + return new VirtualPortId(portId); + } + + @Override + public int hashCode() { + return Objects.hash(portId); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof VirtualPortId) { + final VirtualPortId that = (VirtualPortId) obj; + return this.getClass() == that.getClass() + && Objects.equals(this.portId, that.portId); + } + return false; + } + + @Override + public String toString() { + return portId; + } + +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/network/TenantNetworkCreateCommand.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/network/TenantNetworkCreateCommand.java new file mode 100644 index 00000000..bcfdacfa --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/network/TenantNetworkCreateCommand.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.network; + +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.DefaultTenantNetwork; +import org.onosproject.vtnrsc.PhysicalNetwork; +import org.onosproject.vtnrsc.SegmentationId; +import org.onosproject.vtnrsc.TenantId; +import org.onosproject.vtnrsc.TenantNetwork; +import org.onosproject.vtnrsc.TenantNetworkId; +import org.onosproject.vtnrsc.tenantnetwork.TenantNetworkService; + +import com.google.common.collect.Sets; + +/** + * Supports for creating a TenantNetwork. + */ +@Command(scope = "onos", name = "tenantnetwork-create", + description = "Supports for creating a TenantNetwork") +public class TenantNetworkCreateCommand extends AbstractShellCommand { + + @Argument(index = 0, name = "id", description = "TenantNetwork network id", required = true, + multiValued = false) + String id = null; + + @Argument(index = 1, name = "tenantID", description = "The tenant id of TenantNetwork", + required = true, multiValued = false) + String tenantID = null; + + @Argument(index = 2, name = "type", description = "The type of TenantNetwork", required = true, + multiValued = false) + String type = null; + + @Argument(index = 3, name = "segmentationID", description = "The segmentation id of TenantNetwork", + required = true, multiValued = false) + String segmentationID = ""; + + @Option(name = "-n", aliases = "--name", description = "TenantNetwork name", required = false, + multiValued = false) + String name = null; + + @Option(name = "-a", aliases = "--adminStateUp", description = "TenantNetwork adminStateUp is true or false", + required = false, multiValued = false) + boolean adminStateUp = false; + + @Option(name = "-s", aliases = "--state", description = "The state of TenantNetwork", + required = false, multiValued = false) + String state = null; + + @Option(name = "-d", aliases = "--shared", description = "TenantNetwork is shared or not", + required = false, multiValued = false) + boolean shared = false; + + @Option(name = "-r", aliases = "--routerExternal", + description = "TenantNetwork is routerExternal or not", required = false, + multiValued = false) + boolean routerExternal = false; + + @Option(name = "-p", aliases = "--physicalNetwork", description = "The physical network of Tenant", + required = false, multiValued = false) + String physicalNetwork = ""; + + @Override + protected void execute() { + TenantNetworkService service = get(TenantNetworkService.class); + TenantNetwork network = new DefaultTenantNetwork(TenantNetworkId.networkId(id), name, + adminStateUp, + TenantNetwork.State.valueOf(state), + shared, TenantId.tenantId(tenantID), + routerExternal, + TenantNetwork.Type.valueOf(type), + PhysicalNetwork.physicalNetwork(physicalNetwork), + SegmentationId.segmentationId(segmentationID)); + + Set networksSet = Sets.newHashSet(network); + service.createNetworks(networksSet); + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/network/TenantNetworkQueryCommand.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/network/TenantNetworkQueryCommand.java new file mode 100644 index 00000000..47ea83c2 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/network/TenantNetworkQueryCommand.java @@ -0,0 +1,60 @@ +/* + * 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.network; + +import org.apache.karaf.shell.commands.Command; +import org.apache.karaf.shell.commands.Option; +import org.onosproject.cli.AbstractShellCommand; +import org.onosproject.vtnrsc.TenantNetwork; +import org.onosproject.vtnrsc.TenantNetworkId; +import org.onosproject.vtnrsc.tenantnetwork.TenantNetworkService; + +/** + * Supports for querying TenantNetworks by network id. + */ +@Command(scope = "onos", name = "tenantnetworks", description = "Supports for querying" + + "tenantNetworks by networkid") +public class TenantNetworkQueryCommand extends AbstractShellCommand { + + @Option(name = "-i", aliases = "--id", description = "TenantNetwork id", required = false, + multiValued = false) + String id = null; + + private static final String FMT = "networkId=%s, networkName=%s, segmentationId=%s," + + "tenantId=%s, type=%s, adminStateUp=%s"; + + @Override + protected void execute() { + TenantNetworkService service = get(TenantNetworkService.class); + if (id != null) { + TenantNetwork network = service.getNetwork(TenantNetworkId.networkId(id)); + printNetwork(network); + } else { + Iterable networks = service.getNetworks(); + for (TenantNetwork network : networks) { + printNetwork(network); + } + } + } + + private void printNetwork(TenantNetwork network) { + if (network == null) { + return; + } + print(FMT, network.id(), network.name(), network.segmentationId(), + network.tenantId(), network.type(), network.adminStateUp()); + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/network/TenantNetworkRemoveCommand.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/network/TenantNetworkRemoveCommand.java new file mode 100644 index 00000000..0ea22853 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/network/TenantNetworkRemoveCommand.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.network; + +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.TenantNetworkId; +import org.onosproject.vtnrsc.tenantnetwork.TenantNetworkService; + +import com.google.common.collect.Sets; + +/** + * Supports for removing a TenantNetwork by network id. + */ +@Command(scope = "onos", name = "tenantnetwork-remove", description = "Supports for removing" + + " a tenantNetwork by tenantNetworkid") +public class TenantNetworkRemoveCommand extends AbstractShellCommand { + + @Argument(index = 0, name = "id", description = "TenantNetwork neutronNetwork Id", + required = true, multiValued = false) + String id = null; + + @Override + protected void execute() { + TenantNetworkService service = get(TenantNetworkService.class); + Set networkIds = Sets.newHashSet(TenantNetworkId.networkId(id)); + service.removeNetworks(networkIds); + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/network/TenantNetworkUpdateCommand.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/network/TenantNetworkUpdateCommand.java new file mode 100644 index 00000000..2a738f72 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/network/TenantNetworkUpdateCommand.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.network; + +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.DefaultTenantNetwork; +import org.onosproject.vtnrsc.PhysicalNetwork; +import org.onosproject.vtnrsc.SegmentationId; +import org.onosproject.vtnrsc.TenantId; +import org.onosproject.vtnrsc.TenantNetwork; +import org.onosproject.vtnrsc.TenantNetworkId; +import org.onosproject.vtnrsc.tenantnetwork.TenantNetworkService; + +import com.google.common.collect.Sets; + +/** + * Supports for updating a TenantNetwork. + */ +@Command(scope = "onos", name = "tenantnetwork-update", + description = "Supports for updating a TenantNetwork") +public class TenantNetworkUpdateCommand extends AbstractShellCommand { + + @Argument(index = 0, name = "id", description = "TenantNetwork network id", required = true, + multiValued = false) + String id = null; + + @Argument(index = 1, name = "tenantID", description = "The tenant id of TenantNetwork", + required = true, multiValued = false) + String tenantID = null; + + @Argument(index = 2, name = "type", description = "The type of TenantNetwork", required = true, + multiValued = false) + String type = null; + + @Argument(index = 3, name = "segmentationID", description = "The segmentation id of TenantNetwork", + required = true, multiValued = false) + String segmentationID = ""; + + @Option(name = "-n", aliases = "--name", description = "TenantNetwork name", required = false, + multiValued = false) + String name = null; + + @Option(name = "-a", aliases = "--adminStateUp", description = "TenantNetwork adminStateUp is true or false", + required = false, multiValued = false) + boolean adminStateUp = false; + + @Option(name = "-s", aliases = "--state", description = "The state of TenantNetwork", + required = false, multiValued = false) + String state = null; + + @Option(name = "-d", aliases = "--shared", description = "TenantNetwork is shared or not", + required = false, multiValued = false) + boolean shared = false; + + @Option(name = "-r", aliases = "--routerExternal", + description = "TenantNetwork is routerExternal or not", required = false, + multiValued = false) + boolean routerExternal = false; + + @Option(name = "-p", aliases = "--physicalNetwork", description = "The physical network of Tenant", + required = false, multiValued = false) + String physicalNetwork = ""; + + @Override + protected void execute() { + TenantNetworkService service = get(TenantNetworkService.class); + TenantNetwork network = new DefaultTenantNetwork(TenantNetworkId.networkId(id), name, + adminStateUp, + TenantNetwork.State.valueOf(state), + shared, TenantId.tenantId(tenantID), + routerExternal, + TenantNetwork.Type.valueOf(type), + PhysicalNetwork.physicalNetwork(physicalNetwork), + SegmentationId.segmentationId(segmentationID)); + + Set networksSet = Sets.newHashSet(); + networksSet.add(network); + service.updateNetworks(networksSet); + } + +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/network/package-info.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/network/package-info.java new file mode 100644 index 00000000..1622c800 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/network/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 tenant networks. + */ +package org.onosproject.vtnrsc.cli.network; diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/subnet/SubnetCreateCommand.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/subnet/SubnetCreateCommand.java new file mode 100644 index 00000000..56236408 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/subnet/SubnetCreateCommand.java @@ -0,0 +1,118 @@ +/* + * 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.subnet; + +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.onlab.packet.IpAddress.Version; +import org.onlab.packet.IpPrefix; +import org.onosproject.cli.AbstractShellCommand; +import org.onosproject.vtnrsc.AllocationPool; +import org.onosproject.vtnrsc.DefaultSubnet; +import org.onosproject.vtnrsc.HostRoute; +import org.onosproject.vtnrsc.Subnet; +import org.onosproject.vtnrsc.Subnet.Mode; +import org.onosproject.vtnrsc.SubnetId; +import org.onosproject.vtnrsc.TenantId; +import org.onosproject.vtnrsc.TenantNetworkId; +import org.onosproject.vtnrsc.subnet.SubnetService; + +import com.google.common.collect.Sets; + +/** + * Supports for creating a subnet. + */ +@Command(scope = "onos", name = "subnet-create", description = "Supports for creating a subnet") +public class SubnetCreateCommand extends AbstractShellCommand { + + @Argument(index = 0, name = "id", description = "Subnet Id", required = true, + multiValued = false) + String id = null; + + @Argument(index = 1, name = "subnetName", description = "Subnet String name", required = true, + multiValued = false) + String subnetName = null; + + @Argument(index = 2, name = "networkId", description = "Subnet Network Id", required = true, + multiValued = false) + String networkId = null; + + @Argument(index = 3, name = "tenantId", description = "Subnet Tenant Id", required = true, + multiValued = false) + String tenantId = null; + + @Option(name = "-i", aliases = "--ipVersion", description = "Subnet Version ipVersion", + required = false, multiValued = false) + Version ipVersion = null; + + @Option(name = "-c", aliases = "--cidr", description = "Subnet IpPrefix cidr", + required = false, multiValued = false) + String cidr = "0.0.0.0/0"; + + @Option(name = "-g", aliases = "--gatewayIp", description = "Subnet IpAddress gatewayIp", + required = false, multiValued = false) + String gatewayIp = "0.0.0.0"; + + @Option(name = "-d", aliases = "--dhcpEnabled", description = "Subnet boolean dhcpEnabled", + required = false, multiValued = false) + boolean dhcpEnabled = false; + + @Option(name = "-s", aliases = "--shared", description = "Subnet boolean shared", + required = false, multiValued = false) + boolean shared = false; + + @Option(name = "-m", aliases = "--ipV6AddressMode", + description = "Subnet Mode ipV6AddressMode", required = false, multiValued = false) + String ipV6AddressMode = null; + + @Option(name = "-r", aliases = "--ipV6RaMode", description = "Subnet Mode ipV6RaMode", + required = false, multiValued = false) + String ipV6RaMode = null; + + @Option(name = "-h", aliases = "--hostRoutes", description = "Subnet jsonnode hostRoutes", + required = false, multiValued = false) + Set hostRoutes = Sets.newHashSet(); + + @Option(name = "-a", aliases = "--allocationPools", + description = "Subnet jsonnode allocationPools", required = false, multiValued = false) + Set allocationPools = Sets.newHashSet(); + + @Override + protected void execute() { + SubnetService service = get(SubnetService.class); + if (id == null || networkId == null || tenantId == null) { + print(null, "id,networkId,tenantId can not be null"); + return; + } + Subnet subnet = new DefaultSubnet(SubnetId.subnetId(id), subnetName, + TenantNetworkId.networkId(networkId), + TenantId.tenantId(tenantId), ipVersion, + cidr == null ? null : IpPrefix.valueOf(cidr), + gatewayIp == null ? null : IpAddress.valueOf(gatewayIp), + dhcpEnabled, shared, hostRoutes, + ipV6AddressMode == null ? null : Mode.valueOf(ipV6AddressMode), + ipV6RaMode == null ? null : Mode.valueOf(ipV6RaMode), + allocationPools); + + Set subnetsSet = Sets.newHashSet(subnet); + service.createSubnets(subnetsSet); + } + +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/subnet/SubnetQueryCommand.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/subnet/SubnetQueryCommand.java new file mode 100644 index 00000000..f5a94f0f --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/subnet/SubnetQueryCommand.java @@ -0,0 +1,61 @@ +/* + * 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.subnet; + +import org.apache.karaf.shell.commands.Command; +import org.apache.karaf.shell.commands.Option; +import org.onosproject.cli.AbstractShellCommand; +import org.onosproject.vtnrsc.Subnet; +import org.onosproject.vtnrsc.SubnetId; +import org.onosproject.vtnrsc.subnet.SubnetService; + +/** + * Supports for querying a subnet. + */ +@Command(scope = "onos", name = "subnets", description = "Supports for querying a subnet") +public class SubnetQueryCommand extends AbstractShellCommand { + + @Option(name = "-i", aliases = "--id", description = "Subnet id", required = false, + multiValued = false) + String id = null; + + private static final String FMT = "subnetId=%s, networkId=%s, subnetName=%s," + + "tenantId=%s, cidr=%s, dhcpEnabled=%s, gatewayIp=%s," + "ipVersion=%s"; + + @Override + protected void execute() { + SubnetService service = get(SubnetService.class); + if (id != null) { + Subnet subnet = service.getSubnet(SubnetId.subnetId(id)); + printSubnet(subnet); + } else { + Iterable subnets = service.getSubnets(); + if (subnets == null) { + return; + } + for (Subnet subnet : subnets) { + printSubnet(subnet); + } + } + } + + private void printSubnet(Subnet subnet) { + print(FMT, subnet.id(), subnet.networkId(), subnet.subnetName(), + subnet.tenantId(), subnet.cidr(), subnet.dhcpEnabled(), subnet + .gatewayIp(), subnet.ipVersion()); + + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/subnet/SubnetRemoveCommand.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/subnet/SubnetRemoveCommand.java new file mode 100644 index 00000000..241af87e --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/subnet/SubnetRemoveCommand.java @@ -0,0 +1,46 @@ +/* + * 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.subnet; + +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.SubnetId; +import org.onosproject.vtnrsc.subnet.SubnetService; + +import com.google.common.collect.Sets; + +/** + * Supports for removing a subnet. + */ +@Command(scope = "onos", name = "subnet-remove", description = "Supports for removing a subnet") +public class SubnetRemoveCommand extends AbstractShellCommand { + + @Argument(index = 0, name = "id", description = "Subnet SubnetId Id", required = true, + multiValued = false) + String id = null; + + @Override + protected void execute() { + SubnetService service = get(SubnetService.class); + Set subnetsSet = Sets.newHashSet(); + subnetsSet.add(SubnetId.subnetId(id)); + service.removeSubnets(subnetsSet); + } + +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/subnet/SubnetUpdateCommand.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/subnet/SubnetUpdateCommand.java new file mode 100644 index 00000000..b0578a1e --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/subnet/SubnetUpdateCommand.java @@ -0,0 +1,118 @@ +/* + * 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.subnet; + +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.onlab.packet.IpAddress.Version; +import org.onlab.packet.IpPrefix; +import org.onosproject.cli.AbstractShellCommand; +import org.onosproject.vtnrsc.AllocationPool; +import org.onosproject.vtnrsc.DefaultSubnet; +import org.onosproject.vtnrsc.HostRoute; +import org.onosproject.vtnrsc.Subnet; +import org.onosproject.vtnrsc.Subnet.Mode; +import org.onosproject.vtnrsc.SubnetId; +import org.onosproject.vtnrsc.TenantId; +import org.onosproject.vtnrsc.TenantNetworkId; +import org.onosproject.vtnrsc.subnet.SubnetService; + +import com.google.common.collect.Sets; + +/** + * Supports for updating a subnet. + */ +@Command(scope = "onos", name = "subnet-update", description = "Supports for updating a subnet") +public class SubnetUpdateCommand extends AbstractShellCommand { + + @Argument(index = 0, name = "id", description = "Subnet Id", required = true, + multiValued = false) + String id = null; + + @Argument(index = 1, name = "subnetName", description = "Subnet String name", required = true, + multiValued = false) + String subnetName = null; + + @Argument(index = 2, name = "networkId", description = "Subnet Network Id", required = true, + multiValued = false) + String networkId = null; + + @Argument(index = 3, name = "tenantId", description = "Subnet Tenant Id", required = true, + multiValued = false) + String tenantId = null; + + @Option(name = "-i", aliases = "--ipVersion", description = "Subnet Version ipVersion", + required = false, multiValued = false) + Version ipVersion = null; + + @Option(name = "-c", aliases = "--cidr", description = "Subnet IpPrefix cidr", required = false, + multiValued = false) + String cidr = "0.0.0.0/0"; + + @Option(name = "-g", aliases = "--gatewayIp", description = "Subnet IpAddress gatewayIp", + required = false, multiValued = false) + String gatewayIp = "0.0.0.0"; + + @Option(name = "-d", aliases = "--dhcpEnabled", description = "Subnet boolean dhcpEnabled", + required = false, multiValued = false) + boolean dhcpEnabled = false; + + @Option(name = "-s", aliases = "--shared", description = "Subnet boolean shared", required = false, + multiValued = false) + boolean shared = false; + + @Option(name = "-m", aliases = "--ipV6AddressMode", description = "Subnet Mode ipV6AddressMode", + required = false, multiValued = false) + String ipV6AddressMode = null; + + @Option(name = "-r", aliases = "--ipV6RaMode", description = "Subnet Mode ipV6RaMode", + required = false, multiValued = false) + String ipV6RaMode = null; + + @Option(name = "-h", aliases = "--hostRoutes", description = "Subnet jsonnode hostRoutes", + required = false, multiValued = false) + Set hostRoutes = Sets.newHashSet(); + + @Option(name = "-a", aliases = "--allocationPools", + description = "Subnet jsonnode allocationPools", required = false, multiValued = false) + Set allocationPools = Sets.newHashSet(); + + @Override + protected void execute() { + SubnetService service = get(SubnetService.class); + if (id == null || networkId == null || tenantId == null) { + print(null, "id,networkId,tenantId can not be null"); + return; + } + Subnet subnet = new DefaultSubnet(SubnetId.subnetId(id), subnetName, + TenantNetworkId.networkId(networkId), + TenantId.tenantId(tenantId), ipVersion, + cidr == null ? null : IpPrefix.valueOf(cidr), + gatewayIp == null ? null : IpAddress.valueOf(gatewayIp), + dhcpEnabled, shared, hostRoutes, + ipV6AddressMode == null ? null : Mode.valueOf(ipV6AddressMode), + ipV6RaMode == null ? null : Mode.valueOf(ipV6RaMode), + allocationPools); + Set subnetsSet = Sets.newHashSet(); + subnetsSet.add(subnet); + service.updateSubnets(subnetsSet); + } + +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/subnet/package-info.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/subnet/package-info.java new file mode 100644 index 00000000..b3a2ff51 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/subnet/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 subnets. + */ +package org.onosproject.vtnrsc.cli.subnet; diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/virtualport/VirtualPortCreateCommand.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/virtualport/VirtualPortCreateCommand.java new file mode 100644 index 00000000..4c555e33 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/virtualport/VirtualPortCreateCommand.java @@ -0,0 +1,134 @@ +/* + * 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.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) + Set allowedAddressPairs = Sets.newHashSet(); + + @Option(name = "-e", aliases = "--securityGroups", description = "virtualPort securityGroups.", + required = false, multiValued = false) + Set securityGroups = Sets.newHashSet(); + + @Override + protected void execute() { + Map 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 virtualPorts = Sets.newHashSet(virtualPort); + service.createPorts(virtualPorts); + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/virtualport/VirtualPortQueryCommand.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/virtualport/VirtualPortQueryCommand.java new file mode 100644 index 00000000..47126d1b --- /dev/null +++ b/framework/src/onos/apps/vtn/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 ports = service.getPorts(TenantNetworkId.networkId(networkId)); + printPorts(ports); + } else if (vPortId == null && networkId == null && deviceId != null && tenantId == null) { + Collection ports = service.getPorts(DeviceId.deviceId(deviceId)); + printPorts(ports); + } else if (vPortId == null && networkId == null && deviceId == null && tenantId != null) { + Collection ports = service.getPorts(DeviceId.deviceId(tenantId)); + printPorts(ports); + } else if (vPortId == null && networkId == null && deviceId == null && tenantId == null) { + Collection ports = service.getPorts(); + printPorts(ports); + } else { + print("cannot input more than one parameter"); + } + + } + + private void printPorts(Collection 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/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/virtualport/VirtualPortRemoveCommand.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/virtualport/VirtualPortRemoveCommand.java new file mode 100644 index 00000000..1a3cb4f0 --- /dev/null +++ b/framework/src/onos/apps/vtn/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 virtualPorts = Sets.newHashSet(VirtualPortId.portId(id)); + service.removePorts(virtualPorts); + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/virtualport/VirtualPortUpdateCommand.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/virtualport/VirtualPortUpdateCommand.java new file mode 100644 index 00000000..6df4b23c --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/virtualport/VirtualPortUpdateCommand.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.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) + Set allowedAddressPairs = Sets.newHashSet(); + + @Option(name = "-e", aliases = "--securityGroups", description = "virtualPort securityGroups.", + required = false, multiValued = false) + Set securityGroups = Sets.newHashSet(); + + @Override + protected void execute() { + VirtualPortService service = get(VirtualPortService.class); + Map 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 virtualPorts = Sets.newHashSet(virtualPort); + service.updatePorts(virtualPorts); + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/virtualport/package-info.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/virtualport/package-info.java new file mode 100644 index 00000000..fac214a1 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/virtualport/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 virtual ports. + */ +package org.onosproject.vtnrsc.cli.virtualport; diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/package-info.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/package-info.java new file mode 100644 index 00000000..b245fb14 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/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. + */ + +/** + * VTN resources that used by virtual tenant network. + */ +package org.onosproject.vtnrsc; diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/subnet/SubnetService.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/subnet/SubnetService.java new file mode 100644 index 00000000..82eb9611 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/subnet/SubnetService.java @@ -0,0 +1,72 @@ +/* + * 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.subnet; + +import org.onosproject.vtnrsc.Subnet; +import org.onosproject.vtnrsc.SubnetId; + + +/** + * Service for interacting with the inventory of subnets. + */ +public interface SubnetService { + /** + * Returns the subnet with the specified identifier. + * + * @param subnetId subnet identifier + * @return true or false + */ + boolean exists(SubnetId subnetId); + /** + * Returns a collection of the currently known subnets. + * + * @return iterable collection of subnets + */ + Iterable getSubnets(); + + /** + * Returns the subnet with the specified identifier. + * + * @param subnetId subnet identifier + * @return subnet or null if one with the given identifier is not known + */ + Subnet getSubnet(SubnetId subnetId); + /** + * Creates new subnets. + * + * @param subnets the iterable collection of subnets + * @return true if the identifier subnet has been created right + */ + boolean createSubnets(Iterable subnets); + + /** + * Updates existing subnets. + * + * @param subnets the iterable collection of subnets + * @return true if all subnets were updated successfully + */ + boolean updateSubnets(Iterable subnets); + + /** + * Administratively removes the specified subnets from the store. + * + * @param subnetIds the iterable collection of subnets identifier + * @return true if remove identifier subnets successfully + */ + boolean removeSubnets(Iterable subnetIds); + + +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/subnet/impl/SubnetManager.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/subnet/impl/SubnetManager.java new file mode 100644 index 00000000..890beb29 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/subnet/impl/SubnetManager.java @@ -0,0 +1,183 @@ +/* + * 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.subnet.impl; + +import org.apache.felix.scr.annotations.Activate; +import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.Deactivate; +import org.apache.felix.scr.annotations.Reference; +import org.apache.felix.scr.annotations.ReferenceCardinality; +import org.apache.felix.scr.annotations.Service; +import org.onlab.packet.IpAddress; +import org.onosproject.core.ApplicationId; +import org.onosproject.core.CoreService; +import org.onosproject.store.serializers.KryoNamespaces; +import org.onosproject.store.service.Serializer; +import org.onosproject.store.service.StorageService; +import org.onosproject.vtnrsc.AllocationPool; +import org.onosproject.vtnrsc.DefaultAllocationPool; +import org.onosproject.vtnrsc.DefaultHostRoute; +import org.onosproject.vtnrsc.DefaultSubnet; +import org.onosproject.vtnrsc.HostRoute; +import org.onosproject.vtnrsc.Subnet; +import org.onosproject.vtnrsc.SubnetId; +import org.onosproject.vtnrsc.TenantId; +import org.onosproject.vtnrsc.TenantNetworkId; +import org.onosproject.vtnrsc.subnet.SubnetService; +import org.onosproject.vtnrsc.tenantnetwork.TenantNetworkService; +import org.slf4j.Logger; + +import java.util.Arrays; +import java.util.Collections; +import java.util.Map; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.slf4j.LoggerFactory.getLogger; + +/** + * Provides implementation of the Subnet service. + */ +@Component(immediate = true) +@Service +public class SubnetManager implements SubnetService { + + private static final String SUBNET_ID_NULL = "Subnet ID cannot be null"; + private static final String SUBNET_NOT_NULL = "Subnet cannot be null"; + private static final String SUBNET = "vtn-subnet-store"; + private static final String VTNRSC_APP = "org.onosproject.vtnrsc"; + + + private final Logger log = getLogger(getClass()); + + protected Map subnetStore; + protected ApplicationId appId; + + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) + protected StorageService storageService; + + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) + protected CoreService coreService; + + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) + protected TenantNetworkService tenantNetworkService; + + @Activate + public void activate() { + + appId = coreService.registerApplication(VTNRSC_APP); + + subnetStore = storageService.consistentMapBuilder() + .withName(SUBNET) + .withApplicationId(appId) + .withPurgeOnUninstall() + .withSerializer(Serializer.using(Arrays.asList(KryoNamespaces.API), + Subnet.class, + SubnetId.class, + TenantNetworkId.class, + TenantId.class, + HostRoute.class, + DefaultHostRoute.class, + Subnet.Mode.class, + AllocationPool.class, + DefaultAllocationPool.class, + DefaultSubnet.class, + IpAddress.Version.class)) + .build().asJavaMap(); + + log.info("Started"); + } + + @Deactivate + public void deactivate() { + log.info("Stopped"); + } + + @Override + public Iterable getSubnets() { + return Collections.unmodifiableCollection(subnetStore.values()); + } + + @Override + public Subnet getSubnet(SubnetId subnetId) { + checkNotNull(subnetId, SUBNET_ID_NULL); + return subnetStore.get(subnetId); + } + + @Override + public boolean exists(SubnetId subnetId) { + checkNotNull(subnetId, SUBNET_ID_NULL); + return subnetStore.containsKey(subnetId); + } + + @Override + public boolean createSubnets(Iterable subnets) { + checkNotNull(subnets, SUBNET_NOT_NULL); + for (Subnet subnet : subnets) { + if (!tenantNetworkService.exists(subnet.networkId())) { + log.debug("The network identifier that the subnet {} belong to is not exist", + subnet.networkId().toString(), subnet.id().toString()); + return false; + } + subnetStore.put(subnet.id(), subnet); + if (!subnetStore.containsKey(subnet.id())) { + log.debug("The identified subnet whose identifier is {} create failed", + subnet.id().toString()); + return false; + } + } + return true; + } + + @Override + public boolean updateSubnets(Iterable subnets) { + checkNotNull(subnets, SUBNET_NOT_NULL); + if (subnets != null) { + for (Subnet subnet : subnets) { + if (!subnetStore.containsKey(subnet.id())) { + log.debug("The subnet is not exist whose identifier is {}", + subnet.id().toString()); + return false; + } + + subnetStore.put(subnet.id(), subnet); + + if (!subnet.equals(subnetStore.get(subnet.id()))) { + log.debug("The subnet is updated failed whose identifier is {}", + subnet.id().toString()); + return false; + } + } + } + return true; + } + + @Override + public boolean removeSubnets(Iterable subnetIds) { + checkNotNull(subnetIds, SUBNET_ID_NULL); + if (subnetIds != null) { + for (SubnetId subnetId : subnetIds) { + subnetStore.remove(subnetId); + if (subnetStore.containsKey(subnetId)) { + log.debug("The subnet created is failed whose identifier is {}", + subnetId.toString()); + return false; + } + } + } + return true; + } + +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/subnet/impl/package-info.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/subnet/impl/package-info.java new file mode 100644 index 00000000..79040d8d --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/subnet/impl/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. + */ + +/** + * Provides implementation of the Subnet service. + */ +package org.onosproject.vtnrsc.subnet.impl; diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/subnet/package-info.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/subnet/package-info.java new file mode 100644 index 00000000..7b2bdb90 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/subnet/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. + */ + +/** + * Service for interacting with the inventory of subnets. + */ +package org.onosproject.vtnrsc.subnet; diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/tenantnetwork/TenantNetworkService.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/tenantnetwork/TenantNetworkService.java new file mode 100644 index 00000000..e246cc4e --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/tenantnetwork/TenantNetworkService.java @@ -0,0 +1,80 @@ +/* + * 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.tenantnetwork; + +import org.onosproject.vtnrsc.TenantNetwork; +import org.onosproject.vtnrsc.TenantNetworkId; + +/** + * Service for interacting with the inventory of tenantNetwork. + */ +public interface TenantNetworkService { + + /** + * Returns if the tenantNetwork is existed. + * + * @param networkId tenantNetwork identifier + * @return true or false if one with the given identifier exists. + */ + boolean exists(TenantNetworkId networkId); + + /** + * Returns the number of tenantNetwork known to the system. + * + * @return number of tenantNetwork. + */ + int getNetworkCount(); + + /** + * Returns an iterable collection of the currently known tenantNetwork. + * + * @return collection of tenantNetwork. + */ + Iterable getNetworks(); + + /** + * Returns the tenantNetwork with the identifier. + * + * @param networkId TenantNetwork identifier + * @return TenantNetwork or null if one with the given identifier is not + * known. + */ + TenantNetwork getNetwork(TenantNetworkId networkId); + + /** + * Creates tenantNetworks by networks. + * + * @param networks the collection of tenantNetworks + * @return true if all given identifiers created successfully. + */ + boolean createNetworks(Iterable networks); + + /** + * Updates tenantNetworks by tenantNetworks. + * + * @param networks the collection of tenantNetworks + * @return true if all given identifiers updated successfully. + */ + boolean updateNetworks(Iterable networks); + + /** + * Deletes tenantNetwork by tenantNetworkIds. + * + * @param networksIds the collection of tenantNetworkIds + * @return true if the specified tenantNetworks deleted successfully. + */ + boolean removeNetworks(Iterable networksIds); +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/tenantnetwork/impl/TenantNetworkManager.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/tenantnetwork/impl/TenantNetworkManager.java new file mode 100644 index 00000000..0dfc99e2 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/tenantnetwork/impl/TenantNetworkManager.java @@ -0,0 +1,167 @@ +/* + * 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.tenantnetwork.impl; + +import org.apache.felix.scr.annotations.Activate; +import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.Deactivate; +import org.apache.felix.scr.annotations.Reference; +import org.apache.felix.scr.annotations.ReferenceCardinality; +import org.apache.felix.scr.annotations.Service; +import org.onosproject.core.ApplicationId; +import org.onosproject.core.CoreService; +import org.onosproject.store.serializers.KryoNamespaces; +import org.onosproject.store.service.Serializer; +import org.onosproject.store.service.StorageService; +import org.onosproject.vtnrsc.DefaultTenantNetwork; +import org.onosproject.vtnrsc.PhysicalNetwork; +import org.onosproject.vtnrsc.SegmentationId; +import org.onosproject.vtnrsc.TenantId; +import org.onosproject.vtnrsc.TenantNetwork; +import org.onosproject.vtnrsc.TenantNetworkId; +import org.onosproject.vtnrsc.tenantnetwork.TenantNetworkService; +import org.slf4j.Logger; + +import java.util.Arrays; +import java.util.Collections; +import java.util.Map; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.slf4j.LoggerFactory.getLogger; + +/** + * Provides implementation of the tenantNetworkService. + */ +@Component(immediate = true) +@Service +public class TenantNetworkManager implements TenantNetworkService { + + private static final String NETWORK_ID_NULL = "Network ID cannot be null"; + private static final String NETWORK_NOT_NULL = "Network ID cannot be null"; + private static final String TENANTNETWORK = "vtn-tenant-network-store"; + private static final String VTNRSC_APP = "org.onosproject.vtnrsc"; + + protected Map networkIdAsKeyStore; + protected ApplicationId appId; + + private final Logger log = getLogger(getClass()); + + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) + protected StorageService storageService; + + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) + protected CoreService coreService; + + + @Activate + public void activate() { + + appId = coreService.registerApplication(VTNRSC_APP); + + networkIdAsKeyStore = storageService.consistentMapBuilder() + .withName(TENANTNETWORK) + .withApplicationId(appId) + .withPurgeOnUninstall() + .withSerializer(Serializer.using(Arrays.asList(KryoNamespaces.API), + TenantNetworkId.class, + DefaultTenantNetwork.class, + TenantNetwork.State.class, + TenantId.class, + TenantNetwork.Type.class, + PhysicalNetwork.class, + SegmentationId.class)) + .build().asJavaMap(); + + log.info("Started"); + } + + @Deactivate + public void deactivate() { + log.info("Stopped"); + } + + @Override + public boolean exists(TenantNetworkId networkId) { + checkNotNull(networkId, NETWORK_ID_NULL); + return networkIdAsKeyStore.containsKey(networkId); + } + + @Override + public int getNetworkCount() { + return networkIdAsKeyStore.size(); + } + + @Override + public Iterable getNetworks() { + return Collections.unmodifiableCollection(networkIdAsKeyStore.values()); + } + + @Override + public TenantNetwork getNetwork(TenantNetworkId networkId) { + checkNotNull(networkId, NETWORK_ID_NULL); + return networkIdAsKeyStore.get(networkId); + } + + @Override + public boolean createNetworks(Iterable networks) { + checkNotNull(networks, NETWORK_NOT_NULL); + for (TenantNetwork network : networks) { + networkIdAsKeyStore.put(network.id(), network); + if (!networkIdAsKeyStore.containsKey(network.id())) { + log.debug("The tenantNetwork is created failed which identifier was {}", network.id() + .toString()); + return false; + } + } + return true; + } + + @Override + public boolean updateNetworks(Iterable networks) { + checkNotNull(networks, NETWORK_NOT_NULL); + for (TenantNetwork network : networks) { + if (!networkIdAsKeyStore.containsKey(network.id())) { + log.debug("The tenantNetwork is not exist whose identifier was {} ", + network.id().toString()); + return false; + } + + networkIdAsKeyStore.put(network.id(), network); + + if (!network.equals(networkIdAsKeyStore.get(network.id()))) { + log.debug("The tenantNetwork is updated failed whose identifier was {} ", + network.id().toString()); + return false; + } + + } + return true; + } + + @Override + public boolean removeNetworks(Iterable networkIds) { + checkNotNull(networkIds, NETWORK_NOT_NULL); + for (TenantNetworkId networkId : networkIds) { + networkIdAsKeyStore.remove(networkId); + if (networkIdAsKeyStore.containsKey(networkId)) { + log.debug("The tenantNetwork is removed failed whose identifier was {}", + networkId.toString()); + return false; + } + } + return true; + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/tenantnetwork/impl/package-info.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/tenantnetwork/impl/package-info.java new file mode 100644 index 00000000..f381fda6 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/tenantnetwork/impl/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. + */ + +/** + * Implementation of service for interacting with the inventory of tenant networks. + */ +package org.onosproject.vtnrsc.tenantnetwork.impl; diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/tenantnetwork/package-info.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/tenantnetwork/package-info.java new file mode 100644 index 00000000..1489c973 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/tenantnetwork/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. + */ + +/** + * Service for interacting with the inventory of tenant networks. + */ +package org.onosproject.vtnrsc.tenantnetwork; diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/tunnel/TunnelConfigService.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/tunnel/TunnelConfigService.java new file mode 100644 index 00000000..6f3cf653 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/tunnel/TunnelConfigService.java @@ -0,0 +1,72 @@ +/* + * 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.tunnel; + +import org.onosproject.vtnrsc.Subnet; +import org.onosproject.vtnrsc.SubnetId; + + +/** + * Service for interacting with the inventory of subnets. + */ +public interface TunnelConfigService { + /** + * Returns the subnet with the specified identifier. + * + * @param subnetId subnet identifier + * @return true or false + */ + boolean exists(SubnetId subnetId); + /** + * Returns a collection of the currently known subnets. + * + * @return iterable collection of subnets + */ + Iterable getSubnets(); + + /** + * Returns the subnet with the specified identifier. + * + * @param subnetId subnet identifier + * @return subnet or null if one with the given identifier is not known + */ + Subnet getSubnet(SubnetId subnetId); + /** + * Creates new subnets. + * + * @param subnets the iterable collection of subnets + * @return true if the identifier subnet has been created right + */ + boolean createSubnets(Iterable subnets); + + /** + * Updates existing subnets. + * + * @param subnets the iterable collection of subnets + * @return true if all subnets were updated successfully + */ + boolean updateSubnets(Iterable subnets); + + /** + * Administratively removes the specified subnets from the store. + * + * @param subnetIds the iterable collection of subnets identifier + * @return true if remove identifier subnets successfully + */ + boolean removeSubnets(Iterable subnetIds); + + +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/tunnel/package-info.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/tunnel/package-info.java new file mode 100644 index 00000000..3a84e6e3 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/tunnel/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. + */ + +/** + * Service for interacting with the inventory of subnets. + */ +package org.onosproject.vtnrsc.tunnel; diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/virtualport/VirtualPortService.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/virtualport/VirtualPortService.java new file mode 100644 index 00000000..05ebccf9 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/virtualport/VirtualPortService.java @@ -0,0 +1,100 @@ +/* + * 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.virtualport; + +import java.util.Collection; + +import org.onosproject.net.DeviceId; +import org.onosproject.vtnrsc.TenantId; +import org.onosproject.vtnrsc.TenantNetworkId; +import org.onosproject.vtnrsc.VirtualPort; +import org.onosproject.vtnrsc.VirtualPortId; + +/** + * Service for interacting with the inventory of virtualPort. + */ +public interface VirtualPortService { + /** + * Returns if the virtualPort is existed. + * + * @param virtualPortId virtualPort identifier + * @return true or false if one with the given identifier is not existed. + */ + boolean exists(VirtualPortId virtualPortId); + + /** + * Returns the virtualPort with the identifier. + * + * @param virtualPortId virtualPort ID + * @return VirtualPort or null if one with the given ID is not know. + */ + VirtualPort getPort(VirtualPortId virtualPortId); + + /** + * Returns the collection of the currently known virtualPort. + * @return collection of VirtualPort. + */ + Collection getPorts(); + + /** + * Returns the collection of the virtualPorts associated with the networkId. + * + * @param networkId the network identifer + * @return collection of virtualPort. + */ + Collection getPorts(TenantNetworkId networkId); + + /** + * Returns the collection of the virtualPorts associated with the tenantId. + * + * @param tenantId the tenant identifier + * @return collection of virtualPorts. + */ + Collection getPorts(TenantId tenantId); + + /** + * Returns the collection of the virtualPorts associated with the deviceId. + * + * @param deviceId the device identifier + * @return collection of virtualPort. + */ + Collection getPorts(DeviceId deviceId); + + /** + * Creates virtualPorts by virtualPorts. + * + * @param virtualPorts the iterable collection of virtualPorts + * @return true if all given identifiers created successfully. + */ + boolean createPorts(Iterable virtualPorts); + + /** + * Updates virtualPorts by virtualPorts. + * + * @param virtualPorts the iterable collection of virtualPorts + * @return true if all given identifiers updated successfully. + */ + boolean updatePorts(Iterable virtualPorts); + + /** + * Deletes virtualPortIds by virtualPortIds. + * + * @param virtualPortIds the iterable collection of virtualPort identifiers + * @return true or false if one with the given identifier to delete is + * successfully. + */ + boolean removePorts(Iterable virtualPortIds); +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/virtualport/impl/VirtualPortManager.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/virtualport/impl/VirtualPortManager.java new file mode 100644 index 00000000..926809c9 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/virtualport/impl/VirtualPortManager.java @@ -0,0 +1,208 @@ +/* + * 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.virtualport.impl; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Map; +import java.util.stream.Collectors; + +import org.apache.felix.scr.annotations.Activate; +import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.Deactivate; +import org.apache.felix.scr.annotations.Reference; +import org.apache.felix.scr.annotations.ReferenceCardinality; +import org.apache.felix.scr.annotations.Service; +import org.onlab.packet.IpAddress; +import org.onosproject.core.ApplicationId; +import org.onosproject.core.CoreService; +import org.onosproject.net.DeviceId; +import org.onosproject.store.serializers.KryoNamespaces; +import org.onosproject.store.service.Serializer; +import org.onosproject.store.service.StorageService; +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.SubnetId; +import org.onosproject.vtnrsc.TenantId; +import org.onosproject.vtnrsc.TenantNetworkId; +import org.onosproject.vtnrsc.VirtualPort; +import org.onosproject.vtnrsc.VirtualPortId; +import org.onosproject.vtnrsc.tenantnetwork.TenantNetworkService; +import org.onosproject.vtnrsc.virtualport.VirtualPortService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Provides implementation of the VirtualPort APIs. + */ +@Component(immediate = true) +@Service +public class VirtualPortManager implements VirtualPortService { + + private final Logger log = LoggerFactory.getLogger(getClass()); + + private static final String VIRTUALPORT = "vtn-virtual-port"; + private static final String VTNRSC_APP = "org.onosproject.vtnrsc"; + + private static final String VIRTUALPORT_ID_NULL = "VirtualPort ID cannot be null"; + private static final String VIRTUALPORT_NOT_NULL = "VirtualPort cannot be null"; + private static final String TENANTID_NOT_NULL = "TenantId cannot be null"; + private static final String NETWORKID_NOT_NULL = "NetworkId cannot be null"; + private static final String DEVICEID_NOT_NULL = "DeviceId cannot be null"; + + protected Map vPortStore; + protected ApplicationId appId; + + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) + protected StorageService storageService; + + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) + protected TenantNetworkService networkService; + + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) + protected CoreService coreService; + + @Activate + public void activate() { + + appId = coreService.registerApplication(VTNRSC_APP); + + vPortStore = storageService.consistentMapBuilder() + .withName(VIRTUALPORT) + .withApplicationId(appId) + .withPurgeOnUninstall() + .withSerializer(Serializer.using(Arrays.asList(KryoNamespaces.API), + VirtualPortId.class, + TenantNetworkId.class, + VirtualPort.State.class, + TenantId.class, + AllowedAddressPair.class, + FixedIp.class, + BindingHostId.class, + SecurityGroup.class, + SubnetId.class, + IpAddress.class, + DefaultVirtualPort.class)) + .build().asJavaMap(); + log.info("Started"); + } + + @Deactivate + public void deactivate() { + vPortStore.clear(); + log.info("Stoppped"); + } + + @Override + public boolean exists(VirtualPortId vPortId) { + checkNotNull(vPortId, VIRTUALPORT_ID_NULL); + return vPortStore.containsKey(vPortId); + } + + @Override + public VirtualPort getPort(VirtualPortId vPortId) { + checkNotNull(vPortId, VIRTUALPORT_ID_NULL); + return vPortStore.get(vPortId); + } + + @Override + public Collection getPorts() { + return Collections.unmodifiableCollection(vPortStore.values()); + } + + @Override + public Collection getPorts(TenantNetworkId networkId) { + checkNotNull(networkId, NETWORKID_NOT_NULL); + return vPortStore.values().stream().filter(d -> d.networkId().equals(networkId)) + .collect(Collectors.toList()); + } + + @Override + public Collection getPorts(TenantId tenantId) { + checkNotNull(tenantId, TENANTID_NOT_NULL); + return vPortStore.values().stream().filter(d -> d.tenantId().equals(tenantId)) + .collect(Collectors.toList()); + } + + @Override + public Collection getPorts(DeviceId deviceId) { + checkNotNull(deviceId, DEVICEID_NOT_NULL); + return vPortStore.values().stream().filter(d -> d.deviceId().equals(deviceId)) + .collect(Collectors.toList()); + } + + @Override + public boolean createPorts(Iterable vPorts) { + checkNotNull(vPorts, VIRTUALPORT_NOT_NULL); + for (VirtualPort vPort : vPorts) { + log.debug("vPortId is {} ", vPort.portId().toString()); + vPortStore.put(vPort.portId(), vPort); + if (!vPortStore.containsKey(vPort.portId())) { + log.debug("The virtualPort is created failed whose identifier is {} ", + vPort.portId().toString()); + return false; + } + } + return true; + } + + @Override + public boolean updatePorts(Iterable vPorts) { + checkNotNull(vPorts, VIRTUALPORT_NOT_NULL); + if (vPorts != null) { + for (VirtualPort vPort : vPorts) { + vPortStore.put(vPort.portId(), vPort); + if (!vPortStore.containsKey(vPort.portId())) { + log.debug("The virtualPort is not exist whose identifier is {}", + vPort.portId().toString()); + return false; + } + + vPortStore.put(vPort.portId(), vPort); + + if (!vPort.equals(vPortStore.get(vPort.portId()))) { + log.debug("The virtualPort is updated failed whose identifier is {}", + vPort.portId().toString()); + return false; + } + } + } + return true; + } + + @Override + public boolean removePorts(Iterable vPortIds) { + checkNotNull(vPortIds, VIRTUALPORT_ID_NULL); + if (vPortIds != null) { + for (VirtualPortId vPortId : vPortIds) { + vPortStore.remove(vPortId); + if (vPortStore.containsKey(vPortId)) { + log.debug("The virtualPort is removed failed whose identifier is {}", + vPortId.toString()); + return false; + } + } + } + return true; + } + +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/virtualport/impl/package-info.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/virtualport/impl/package-info.java new file mode 100644 index 00000000..24eb0d3f --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/virtualport/impl/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. + */ + +/** + * Implementation of service for interacting with the inventory of virtual ports. + */ +package org.onosproject.vtnrsc.virtualport.impl; diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/virtualport/package-info.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/virtualport/package-info.java new file mode 100644 index 00000000..06a01a04 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/virtualport/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. + */ + +/** + * Service for interacting with the inventory of virtual ports. + */ +package org.onosproject.vtnrsc.virtualport; diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/AllocationPoolsCodec.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/AllocationPoolsCodec.java new file mode 100644 index 00000000..57c97c1c --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/AllocationPoolsCodec.java @@ -0,0 +1,40 @@ +/* + * 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.web; + +import static com.google.common.base.Preconditions.checkNotNull; + +import org.onosproject.codec.CodecContext; +import org.onosproject.codec.JsonCodec; +import org.onosproject.vtnrsc.AllocationPool; + +import com.fasterxml.jackson.databind.node.ObjectNode; + +/** + * Subnet AllocationPool codec. + */ +public final class AllocationPoolsCodec extends JsonCodec { + + @Override + public ObjectNode encode(AllocationPool alocPool, CodecContext context) { + checkNotNull(alocPool, "AllocationPools cannot be null"); + ObjectNode result = context.mapper().createObjectNode() + .put("start", alocPool.startIp().toString()) + .put("end", alocPool.endIp().toString()); + return result; + } + +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/AllowedAddressPairCodec.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/AllowedAddressPairCodec.java new file mode 100644 index 00000000..7960808f --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/AllowedAddressPairCodec.java @@ -0,0 +1,40 @@ +/* + * 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.web; + +import static com.google.common.base.Preconditions.checkNotNull; + +import org.onosproject.codec.CodecContext; +import org.onosproject.codec.JsonCodec; +import org.onosproject.vtnrsc.AllowedAddressPair; + +import com.fasterxml.jackson.databind.node.ObjectNode; + +/** + * VirtualPort AllowedAddressPair codec. + */ +public final class AllowedAddressPairCodec extends JsonCodec { + + @Override + public ObjectNode encode(AllowedAddressPair alocAddPair, CodecContext context) { + checkNotNull(alocAddPair, "AllowedAddressPair cannot be null"); + ObjectNode result = context.mapper().createObjectNode() + .put("ip_address", alocAddPair.ip().toString()) + .put("mac_address", alocAddPair.mac().toString()); + return result; + } + +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/FixedIpCodec.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/FixedIpCodec.java new file mode 100644 index 00000000..96c9bb4e --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/FixedIpCodec.java @@ -0,0 +1,40 @@ +/* + * 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.web; + +import static com.google.common.base.Preconditions.checkNotNull; + +import org.onosproject.codec.CodecContext; +import org.onosproject.codec.JsonCodec; +import org.onosproject.vtnrsc.FixedIp; + +import com.fasterxml.jackson.databind.node.ObjectNode; + +/** + * VirtualPort FixedIp codec. + */ +public final class FixedIpCodec extends JsonCodec { + + @Override + public ObjectNode encode(FixedIp fixIp, CodecContext context) { + checkNotNull(fixIp, "FixedIp cannot be null"); + ObjectNode result = context.mapper().createObjectNode() + .put("subnet_id", fixIp.subnetId().toString()) + .put("ip_address", fixIp.ip().toString()); + return result; + } + +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/HostRoutesCodec.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/HostRoutesCodec.java new file mode 100644 index 00000000..69ca6b3f --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/HostRoutesCodec.java @@ -0,0 +1,40 @@ +/* + * 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.web; + +import static com.google.common.base.Preconditions.checkNotNull; + +import org.onosproject.codec.CodecContext; +import org.onosproject.codec.JsonCodec; +import org.onosproject.vtnrsc.HostRoute; + +import com.fasterxml.jackson.databind.node.ObjectNode; + +/** + * Subnet HostRoute codec. + */ +public final class HostRoutesCodec extends JsonCodec { + + @Override + public ObjectNode encode(HostRoute hostRoute, CodecContext context) { + checkNotNull(hostRoute, "HostRoute cannot be null"); + ObjectNode result = context.mapper().createObjectNode() + .put("nexthop", hostRoute.nexthop().toString()) + .put("destination", hostRoute.destination().toString()); + return result; + } + +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/SecurityGroupCodec.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/SecurityGroupCodec.java new file mode 100644 index 00000000..c2ded196 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/SecurityGroupCodec.java @@ -0,0 +1,39 @@ +/* + * 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.web; + +import static com.google.common.base.Preconditions.checkNotNull; + +import org.onosproject.codec.CodecContext; +import org.onosproject.codec.JsonCodec; +import org.onosproject.vtnrsc.SecurityGroup; + +import com.fasterxml.jackson.databind.node.ObjectNode; + +/** + * Virtualport SecurityGroup codec. + */ +public final class SecurityGroupCodec extends JsonCodec { + + @Override + public ObjectNode encode(SecurityGroup securGroup, CodecContext context) { + checkNotNull(securGroup, "SecurityGroup cannot be null"); + ObjectNode result = context.mapper().createObjectNode() + .put("security_group", securGroup.securityGroup()); + return result; + } + +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/SubnetCodec.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/SubnetCodec.java new file mode 100644 index 00000000..122b75a9 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/SubnetCodec.java @@ -0,0 +1,53 @@ +/* + * 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.web; + +import static com.google.common.base.Preconditions.checkNotNull; + +import org.onosproject.codec.CodecContext; +import org.onosproject.codec.JsonCodec; +import org.onosproject.vtnrsc.Subnet; + +import com.fasterxml.jackson.databind.node.ObjectNode; + +/** + * Subnet JSON codec. + */ +public final class SubnetCodec extends JsonCodec { + @Override + public ObjectNode encode(Subnet subnet, CodecContext context) { + checkNotNull(subnet, "Subnet cannot be null"); + ObjectNode result = context.mapper().createObjectNode() + .put("id", subnet.id().toString()) + .put("gateway_ip", subnet.gatewayIp().toString()) + .put("network_id", subnet.networkId().toString()) + .put("name", subnet.subnetName()) + .put("ip_version", subnet.ipVersion().toString()) + .put("cidr", subnet.cidr().toString()) + .put("shared", subnet.shared()) + .put("enabled_dchp", subnet.dhcpEnabled()) + .put("tenant_id", subnet.tenantId().toString()) + .put("ipv6_address_mode", subnet.ipV6AddressMode() == null ? null + : subnet.ipV6AddressMode().toString()) + .put("ipv6_ra_mode", subnet.ipV6RaMode() == null ? null + : subnet.ipV6RaMode().toString()); + result.set("allocation_pools", new AllocationPoolsCodec().encode(subnet + .allocationPools(), context)); + result.set("host_routes", + new HostRoutesCodec().encode(subnet.hostRoutes(), context)); + return result; + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/TenantNetworkCodec.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/TenantNetworkCodec.java new file mode 100644 index 00000000..48ba3b97 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/TenantNetworkCodec.java @@ -0,0 +1,47 @@ +/* + * 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.web; + +import static com.google.common.base.Preconditions.checkNotNull; + +import org.onosproject.codec.CodecContext; +import org.onosproject.codec.JsonCodec; +import org.onosproject.vtnrsc.TenantNetwork; + +import com.fasterxml.jackson.databind.node.ObjectNode; + +/** + * TenantNetwork JSON codec. + */ +public final class TenantNetworkCodec extends JsonCodec { + + @Override + public ObjectNode encode(TenantNetwork network, CodecContext context) { + checkNotNull(network, "Network cannot be null"); + ObjectNode result = context.mapper().createObjectNode() + .put("id", network.id().toString()) + .put("name", network.name()) + .put("admin_state_up", network.adminStateUp()) + .put("status", "" + network.state()) + .put("shared", network.shared()) + .put("tenant_id", network.tenantId().toString()) + .put("router:external", network.routerExternal()) + .put("provider:network_type", "" + network.type()) + .put("provider:physical_network", network.physicalNetwork().toString()) + .put("provider:segmentation_id", network.segmentationId().toString()); + return result; + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/VirtualPortCodec.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/VirtualPortCodec.java new file mode 100644 index 00000000..e57d56bc --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/VirtualPortCodec.java @@ -0,0 +1,57 @@ +/* + * 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.web; + +import static com.google.common.base.Preconditions.checkNotNull; + +import org.onosproject.codec.CodecContext; +import org.onosproject.codec.JsonCodec; +import org.onosproject.vtnrsc.VirtualPort; + +import com.fasterxml.jackson.databind.node.ObjectNode; + +/** + * VirtualPort JSON codec. + */ +public final class VirtualPortCodec extends JsonCodec { + @Override + public ObjectNode encode(VirtualPort vPort, CodecContext context) { + checkNotNull(vPort, "VPort cannot be null"); + ObjectNode result = context + .mapper() + .createObjectNode() + .put("id", vPort.portId().toString()) + .put("network_id", vPort.networkId().toString()) + .put("admin_state_up", vPort.adminStateUp()) + .put("name", vPort.name()) + .put("status", vPort.state().toString()) + .put("mac_address", vPort.macAddress().toString()) + .put("tenant_id", vPort.tenantId().toString()) + .put("device_id", vPort.deviceId().toString()) + .put("device_owner", vPort.deviceOwner()) + .put("binding:vnic_type", vPort.bindingVnicType()) + .put("binding:Vif_type", vPort.bindingVifType()) + .put("binding:host_id", vPort.bindingHostId().toString()) + .put("binding:vif_details", vPort.bindingVifDetails()); + result.set("allowed_address_pairs", new AllowedAddressPairCodec().encode( + vPort.allowedAddressPairs(), context)); + result.set("fixed_ips", new FixedIpCodec().encode( + vPort.fixedIps(), context)); + result.set("security_groups", new SecurityGroupCodec().encode( + vPort.securityGroups(), context)); + return result; + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/package-info.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/package-info.java new file mode 100644 index 00000000..34636a9f --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/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. + */ + +/** + * Codecs for virtual tenant objects. + */ +package org.onosproject.vtnrsc.web; diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/resources/OSGI-INF/blueprint/shell-config.xml b/framework/src/onos/apps/vtn/vtnrsc/src/main/resources/OSGI-INF/blueprint/shell-config.xml new file mode 100644 index 00000000..c6a9c81b --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/resources/OSGI-INF/blueprint/shell-config.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit 1.2.3-korg