From 643ee33289bd2cb9e6afbfb09b4ed72d467ba1c2 Mon Sep 17 00:00:00 2001 From: Ashlee Young Date: Tue, 3 Nov 2015 14:08:10 -0800 Subject: This updates ONOS src tree to commit id 03fa5e571cabbd001ddb1598847e1150b11c7333 Change-Id: I13b554026d6f902933e35887d29bd5fdb669c0bd Signed-off-by: Ashlee Young --- .../onosproject/vtnrsc/DefaultFlowClassifier.java | 413 +++++++++++++++++++++ .../org/onosproject/vtnrsc/DefaultPortChain.java | 201 ++++++++++ .../org/onosproject/vtnrsc/DefaultPortPair.java | 198 ++++++++++ .../onosproject/vtnrsc/DefaultPortPairGroup.java | 183 +++++++++ .../org/onosproject/vtnrsc/FlowClassifier.java | 259 +++++++++++++ .../org/onosproject/vtnrsc/FlowClassifierId.java | 91 +++++ .../java/org/onosproject/vtnrsc/PortChain.java | 148 ++++++++ .../java/org/onosproject/vtnrsc/PortChainId.java | 95 +++++ .../main/java/org/onosproject/vtnrsc/PortPair.java | 139 +++++++ .../java/org/onosproject/vtnrsc/PortPairGroup.java | 126 +++++++ .../org/onosproject/vtnrsc/PortPairGroupId.java | 95 +++++ .../java/org/onosproject/vtnrsc/PortPairId.java | 95 +++++ .../flowClassifier/FlowClassifierService.java | 72 ++++ .../flowClassifier/impl/FlowClassifierManager.java | 108 ++++++ .../vtnrsc/flowClassifier/impl/package-info.java | 20 + .../vtnrsc/flowClassifier/package-info.java | 20 + .../vtnrsc/portchain/PortChainService.java | 80 ++++ .../onosproject/vtnrsc/portchain/package-info.java | 20 + .../vtnrsc/portpairgroup/PortPairGroupService.java | 80 ++++ .../vtnrsc/portpairgroup/package-info.java | 20 + .../vtnrsc/tunnel/TunnelConfigService.java | 72 ---- .../onosproject/vtnrsc/tunnel/package-info.java | 20 - .../virtualport/impl/VirtualPortManager.java | 40 +- .../vtnrsc/web/AllocationPoolsCodec.java | 40 -- .../vtnrsc/web/AllowedAddressPairCodec.java | 40 -- .../org/onosproject/vtnrsc/web/FixedIpCodec.java | 40 -- .../vtnrsc/web/FlowClassifierCodec.java | 134 +++++++ .../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 --- .../flowclassifier/FlowClassifierIdTest.java | 68 ++++ .../vtnrsc/subnet/DefaultAllocationPoolTest.java | 68 ++++ .../vtnrsc/subnet/DefaultHostRouteTest.java | 68 ++++ .../onosproject/vtnrsc/subnet/SubnetIdTest.java | 64 ++++ .../tenantnetwork/DefaultNeutronNetworkTest.java | 83 +++++ .../vtnrsc/tenantnetwork/PhysicalNetworkTest.java | 65 ++++ .../vtnrsc/tenantnetwork/SegmentationIdTest.java | 64 ++++ .../vtnrsc/tenantnetwork/TenantIdTest.java | 64 ++++ .../vtnrsc/tenantnetwork/TenantNetworkIdTest.java | 64 ++++ .../vtnrsc/virtualport/AllowedAddressPairTest.java | 76 ++++ .../vtnrsc/virtualport/DefaultVirtualPortTest.java | 142 +++++++ .../vtnrsc/virtualport/FixedIpTest.java | 72 ++++ .../vtnrsc/virtualport/SecurityGroupTest.java | 66 ++++ .../vtnrsc/virtualport/VirtualPortIdTest.java | 66 ++++ 46 files changed, 3645 insertions(+), 470 deletions(-) create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultFlowClassifier.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultPortChain.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultPortPair.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultPortPairGroup.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/FlowClassifier.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/FlowClassifierId.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PortChain.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PortChainId.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PortPair.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PortPairGroup.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PortPairGroupId.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PortPairId.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowClassifier/FlowClassifierService.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowClassifier/impl/FlowClassifierManager.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowClassifier/impl/package-info.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowClassifier/package-info.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portchain/PortChainService.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portchain/package-info.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpairgroup/PortPairGroupService.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpairgroup/package-info.java delete mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/tunnel/TunnelConfigService.java delete mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/tunnel/package-info.java delete mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/AllocationPoolsCodec.java delete mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/AllowedAddressPairCodec.java delete 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/FlowClassifierCodec.java delete mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/HostRoutesCodec.java delete mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/SecurityGroupCodec.java delete mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/SubnetCodec.java delete mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/TenantNetworkCodec.java delete 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/test/java/org/onosproject/vtnrsc/flowclassifier/FlowClassifierIdTest.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/subnet/DefaultAllocationPoolTest.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/subnet/DefaultHostRouteTest.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/subnet/SubnetIdTest.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/DefaultNeutronNetworkTest.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/PhysicalNetworkTest.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/SegmentationIdTest.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/TenantIdTest.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/TenantNetworkIdTest.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/AllowedAddressPairTest.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/DefaultVirtualPortTest.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/FixedIpTest.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/SecurityGroupTest.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/VirtualPortIdTest.java (limited to 'framework/src/onos/apps/vtn/vtnrsc') diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultFlowClassifier.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultFlowClassifier.java new file mode 100644 index 00000000..39df2cff --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultFlowClassifier.java @@ -0,0 +1,413 @@ +/* + * 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 org.onlab.packet.IpPrefix; + +import com.google.common.base.MoreObjects; +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * Provides Default flow classifier. + */ +public final class DefaultFlowClassifier implements FlowClassifier { + + private final FlowClassifierId flowClassifierId; + private final TenantId tenantId; + private final String name; + private final String description; + private final String etherType; + private final String protocol; + private final int minSrcPortRange; + private final int maxSrcPortRange; + private final int minDstPortRange; + private final int maxDstPortRange; + private final IpPrefix srcIpPrefix; + private final IpPrefix dstIpPrefix; + private final VirtualPortId srcPort; + private final VirtualPortId dstPort; + private static final int NULL_PORT = 0; + private static final String FLOW_CLASSIFIER_ID_NOT_NULL = "FlowClassifier id can not be null."; + private static final String TENANT_ID_NOT_NULL = "Tenant id can not be null."; + + /** + * Constructor to create default flow classifier. + * + * @param flowClassifierId flow classifier Id + * @param tenantId Tenant ID + * @param name flow classifier name + * @param description flow classifier description + * @param etherType etherType + * @param protocol IP protocol + * @param minSrcPortRange Minimum Source port range + * @param maxSrcPortRange Maximum Source port range + * @param minDstPortRange Minimum destination port range + * @param maxDstPortRange Maximum destination port range + * @param srcIpPrefix Source IP prefix + * @param dstIpPrefix destination IP prefix + * @param srcPort Source VirtualPort + * @param dstPort destination VirtualPort + */ + private DefaultFlowClassifier(FlowClassifierId flowClassifierId, TenantId tenantId, String name, + String description, String etherType, String protocol, int minSrcPortRange, int maxSrcPortRange, + int minDstPortRange, int maxDstPortRange, IpPrefix srcIpPrefix, IpPrefix dstIpPrefix, + VirtualPortId srcPort, VirtualPortId dstPort) { + this.flowClassifierId = flowClassifierId; + this.tenantId = tenantId; + this.name = name; + this.description = description; + this.etherType = etherType; + this.protocol = protocol; + this.minSrcPortRange = minSrcPortRange; + this.maxSrcPortRange = maxSrcPortRange; + this.minDstPortRange = minDstPortRange; + this.maxDstPortRange = maxDstPortRange; + this.srcIpPrefix = srcIpPrefix; + this.dstIpPrefix = dstIpPrefix; + this.srcPort = srcPort; + this.dstPort = dstPort; + } + + @Override + public FlowClassifierId flowClassifierId() { + return flowClassifierId; + } + + @Override + public TenantId tenantId() { + return tenantId; + } + + @Override + public String name() { + return name; + } + + @Override + public String description() { + return description; + } + + @Override + public String etherType() { + return etherType; + } + + @Override + public String protocol() { + return protocol; + } + + @Override + public int minSrcPortRange() { + return minSrcPortRange; + } + + @Override + public int maxSrcPortRange() { + return maxSrcPortRange; + } + + @Override + public int minDstPortRange() { + return minDstPortRange; + } + + @Override + public int maxDstPortRange() { + return maxDstPortRange; + } + + @Override + public IpPrefix srcIpPrefix() { + return srcIpPrefix; + } + + @Override + public IpPrefix dstIpPrefix() { + return dstIpPrefix; + } + + @Override + public VirtualPortId srcPort() { + return srcPort; + } + + @Override + public VirtualPortId dstPort() { + return dstPort; + } + + /** + * Builder class for constructing Flow classifier. + */ + public static class Builder implements FlowClassifier.Builder { + + private FlowClassifierId flowClassifierId; + private TenantId tenantId; + private String name; + private boolean isFlowClassifierNameSet = false; + private String description; + private boolean isFlowClassifierDescriptionSet = false; + private String etherType; + private boolean isEtherTypeSet = false; + private String protocol; + private boolean isProtocolSet = false; + private int minSrcPortRange; + private boolean isMinSrcPortRangeSet = false; + private int maxSrcPortRange; + private boolean isMaxSrcPortRangeSet = false; + private int minDstPortRange; + private boolean isMinDstPortRangeSet = false; + private int maxDstPortRange; + private boolean isMaxDstPortRangeSet = false; + private IpPrefix srcIpPrefix; + private boolean isSrcIpPrefixSet = false; + private IpPrefix dstIpPrefix; + private boolean isDstIpPrefixSet = false; + private VirtualPortId srcPort; + private boolean isSrcPortSet = false; + private VirtualPortId dstPort; + private boolean isDstPortSet = false; + + @Override + public FlowClassifier build() { + + checkNotNull(flowClassifierId, FLOW_CLASSIFIER_ID_NOT_NULL); + checkNotNull(tenantId, TENANT_ID_NOT_NULL); + String name = null; + String description = null; + String etherType = null; + String protocol = null; + int minSrcPortRange = NULL_PORT; + int maxSrcPortRange = NULL_PORT; + int minDstPortRange = NULL_PORT; + int maxDstPortRange = NULL_PORT; + IpPrefix srcIpPrefix = null; + IpPrefix dstIpPrefix = null; + VirtualPortId srcPort = null; + VirtualPortId dstPort = null; + + if (isFlowClassifierNameSet) { + name = this.name; + } + if (isFlowClassifierDescriptionSet) { + description = this.description; + } + if (isEtherTypeSet) { + etherType = this.etherType; + } + if (isProtocolSet) { + protocol = this.protocol; + } + if (isMinSrcPortRangeSet) { + minSrcPortRange = this.minSrcPortRange; + } + if (isMaxSrcPortRangeSet) { + maxSrcPortRange = this.maxSrcPortRange; + } + if (isMinDstPortRangeSet) { + minDstPortRange = this.minDstPortRange; + } + if (isMaxDstPortRangeSet) { + maxDstPortRange = this.maxDstPortRange; + } + if (isSrcIpPrefixSet) { + srcIpPrefix = this.srcIpPrefix; + } + if (isDstIpPrefixSet) { + dstIpPrefix = this.dstIpPrefix; + } + if (isSrcPortSet) { + srcPort = this.srcPort; + } + if (isDstPortSet) { + dstPort = this.dstPort; + } + + return new DefaultFlowClassifier(flowClassifierId, tenantId, name, description, etherType, protocol, + minSrcPortRange, maxSrcPortRange, minDstPortRange, maxDstPortRange, srcIpPrefix, dstIpPrefix, + srcPort, dstPort); + } + + @Override + public Builder setFlowClassifierId(FlowClassifierId flowClassifierId) { + this.flowClassifierId = flowClassifierId; + return this; + } + + @Override + public Builder setTenantId(TenantId tenantId) { + this.tenantId = tenantId; + return this; + } + + @Override + public Builder setName(String name) { + this.name = name; + this.isFlowClassifierNameSet = true; + return this; + } + + @Override + public Builder setDescription(String description) { + this.description = description; + this.isFlowClassifierDescriptionSet = true; + return this; + } + + @Override + public Builder setEtherType(String etherType) { + this.etherType = etherType; + this.isEtherTypeSet = true; + return this; + } + + @Override + public Builder setProtocol(String protocol) { + this.protocol = protocol; + this.isProtocolSet = true; + return this; + } + + @Override + public Builder setMinSrcPortRange(int minSrcPortRange) { + this.minSrcPortRange = minSrcPortRange; + this.isMinSrcPortRangeSet = true; + return this; + } + + @Override + public Builder setMaxSrcPortRange(int maxSrcPortRange) { + this.maxSrcPortRange = maxSrcPortRange; + this.isMaxSrcPortRangeSet = true; + return this; + } + + @Override + public Builder setMinDstPortRange(int minDstPortRange) { + this.minDstPortRange = minDstPortRange; + this.isMinDstPortRangeSet = true; + return this; + } + + @Override + public Builder setMaxDstPortRange(int maxDstPortRange) { + this.maxDstPortRange = maxDstPortRange; + this.isMaxDstPortRangeSet = true; + return this; + } + + @Override + public Builder setSrcIpPrefix(IpPrefix srcIpPrefix) { + this.srcIpPrefix = srcIpPrefix; + this.isSrcIpPrefixSet = true; + return this; + } + + @Override + public Builder setDstIpPrefix(IpPrefix dstIpPrefix) { + this.dstIpPrefix = dstIpPrefix; + this.isDstIpPrefixSet = true; + return this; + } + + @Override + public Builder setSrcPort(VirtualPortId srcPort) { + this.srcPort = srcPort; + this.isSrcPortSet = true; + return this; + } + + @Override + public Builder setDstPort(VirtualPortId dstPort) { + this.dstPort = dstPort; + this.isDstPortSet = true; + return this; + } + } + + @Override + public int hashCode() { + return Objects.hash(flowClassifierId, tenantId, name, description, etherType, protocol, minSrcPortRange, + maxSrcPortRange, minDstPortRange, maxDstPortRange, srcIpPrefix, dstIpPrefix, srcPort, dstPort); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof DefaultFlowClassifier) { + DefaultFlowClassifier other = (DefaultFlowClassifier) obj; + return Objects.equals(this.flowClassifierId, other.flowClassifierId) + && Objects.equals(this.tenantId, other.tenantId) + && Objects.equals(this.name, other.name) + && Objects.equals(this.description, other.description) + && Objects.equals(this.etherType, other.etherType) + && Objects.equals(this.protocol, other.protocol) + && Objects.equals(this.minSrcPortRange, other.minSrcPortRange) + && Objects.equals(this.maxSrcPortRange, other.maxSrcPortRange) + && Objects.equals(this.minDstPortRange, other.minDstPortRange) + && Objects.equals(this.maxDstPortRange, other.maxDstPortRange) + && Objects.equals(this.srcIpPrefix, other.srcIpPrefix) + && Objects.equals(this.dstIpPrefix, other.dstIpPrefix) + && Objects.equals(this.srcPort, other.srcPort) + && Objects.equals(this.dstPort, other.dstPort); + } + return false; + } + + @Override + public boolean exactMatch(FlowClassifier flowClassifier) { + return this.equals(flowClassifier) + && Objects.equals(this.flowClassifierId, flowClassifier.flowClassifierId()) + && Objects.equals(this.tenantId, flowClassifier.tenantId()) + && Objects.equals(this.name, flowClassifier.name()) + && Objects.equals(this.description, flowClassifier.description()) + && Objects.equals(this.etherType, flowClassifier.etherType()) + && Objects.equals(this.protocol, flowClassifier.protocol()) + && Objects.equals(this.minSrcPortRange, flowClassifier.minSrcPortRange()) + && Objects.equals(this.maxSrcPortRange, flowClassifier.maxSrcPortRange()) + && Objects.equals(this.minDstPortRange, flowClassifier.minDstPortRange()) + && Objects.equals(this.maxDstPortRange, flowClassifier.maxDstPortRange()) + && Objects.equals(this.srcIpPrefix, flowClassifier.srcIpPrefix()) + && Objects.equals(this.dstIpPrefix, flowClassifier.dstIpPrefix()) + && Objects.equals(this.srcPort, flowClassifier.srcPort()) + && Objects.equals(this.dstPort, flowClassifier.dstPort()); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(getClass()) + .add("FlowClassifierId", flowClassifierId) + .add("TenantId", tenantId) + .add("Name", name) + .add("Description", description) + .add("String", etherType) + .add("Protocol", protocol) + .add("MinSrcPortRange", minSrcPortRange) + .add("MaxSrcPortRange", maxSrcPortRange) + .add("MinDstPortRange", minDstPortRange) + .add("MaxDstPortRange", maxDstPortRange) + .add("SrcIpPrefix", srcIpPrefix) + .add("DstIpPrefix", dstIpPrefix) + .add("SrcPort", srcPort) + .add("DstPort", dstPort) + .toString(); + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultPortChain.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultPortChain.java new file mode 100644 index 00000000..89b94b3e --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultPortChain.java @@ -0,0 +1,201 @@ +/* + * 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.List; +import java.util.Objects; + +import com.google.common.collect.ImmutableList; + +/** + * Implementation of port chain. + */ +public final class DefaultPortChain implements PortChain { + + private final PortChainId portChainId; + private final TenantId tenantId; + private final String name; + private final String description; + private final List portPairGroupList; + private final List flowClassifierList; + + /** + * Default constructor to create port chain. + * + * @param portChainId port chain id + * @param tenantId tenant id + * @param name name of port chain + * @param description description of port chain + * @param portPairGroupList port pair group list + * @param flowClassifierList flow classifier list + */ + private DefaultPortChain(PortChainId portChainId, TenantId tenantId, + String name, String description, + List portPairGroupList, + List flowClassifierList) { + + this.portChainId = portChainId; + this.tenantId = tenantId; + this.name = name; + this.description = description; + this.portPairGroupList = portPairGroupList; + this.flowClassifierList = flowClassifierList; + } + + @Override + public PortChainId portChainId() { + return portChainId; + } + + @Override + public TenantId tenantId() { + return tenantId; + } + + @Override + public String name() { + return name; + } + + @Override + public String description() { + return description; + } + + @Override + public List portPairGroups() { + return ImmutableList.copyOf(portPairGroupList); + } + + @Override + public List flowClassifiers() { + return ImmutableList.copyOf(flowClassifierList); + } + + @Override + public int hashCode() { + return Objects.hash(portChainId, tenantId, name, description, + portPairGroupList, flowClassifierList); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof DefaultPortChain) { + DefaultPortChain that = (DefaultPortChain) obj; + return Objects.equals(portChainId, that.portChainId) && + Objects.equals(tenantId, that.tenantId) && + Objects.equals(name, that.name) && + Objects.equals(description, that.description) && + Objects.equals(portPairGroupList, that.portPairGroupList) && + Objects.equals(flowClassifierList, that.flowClassifierList); + } + return false; + } + + @Override + public boolean exactMatch(PortChain portChain) { + return this.equals(portChain) && + Objects.equals(this.portChainId, portChain.portChainId()) && + Objects.equals(this.tenantId, portChain.tenantId()); + } + + @Override + public String toString() { + return toStringHelper(this) + .add("id", portChainId.toString()) + .add("tenantId", tenantId.toString()) + .add("name", name) + .add("description", description) + .add("portPairGroupList", portPairGroupList) + .add("flowClassifier", flowClassifierList) + .toString(); + } + + /** + * To create an instance of the builder. + * + * @return instance of builder + */ + public static Builder builder() { + return new Builder(); + } + + /** + * Builder class for Port chain. + */ + public static final class Builder implements PortChain.Builder { + + private PortChainId portChainId; + private TenantId tenantId; + private String name; + private String description; + private List portPairGroupList; + private List flowClassifierList; + + @Override + public Builder setId(PortChainId portChainId) { + this.portChainId = portChainId; + return this; + } + + @Override + public Builder setTenantId(TenantId tenantId) { + this.tenantId = tenantId; + return this; + } + + @Override + public Builder setName(String name) { + this.name = name; + return this; + } + + @Override + public Builder setDescription(String description) { + this.description = description; + return this; + } + + @Override + public Builder setPortPairGroups(List portPairGroups) { + this.portPairGroupList = portPairGroups; + return this; + } + + @Override + public Builder setFlowClassifiers(List flowClassifiers) { + this.flowClassifierList = flowClassifiers; + return this; + } + + @Override + public PortChain build() { + + checkNotNull(portChainId, "Port chain id cannot be null"); + checkNotNull(tenantId, "Tenant id cannot be null"); + checkNotNull(portPairGroupList, "Port pair groups cannot be null"); + + return new DefaultPortChain(portChainId, tenantId, name, description, + portPairGroupList, flowClassifierList); + } + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultPortPair.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultPortPair.java new file mode 100644 index 00000000..4b3b7cf3 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultPortPair.java @@ -0,0 +1,198 @@ +/* + * 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; + +/** + * Implementation of port pair. + */ +public final class DefaultPortPair implements PortPair { + + private final PortPairId portPairId; + private final TenantId tenantId; + private final String name; + private final String description; + private final String ingress; + private final String egress; + + /** + * Default constructor to create Port Pair. + * + * @param portPairId port pair id + * @param tenantId tenant id + * @param name name of port pair + * @param description description of port pair + * @param ingress ingress port + * @param egress egress port + */ + private DefaultPortPair(PortPairId portPairId, TenantId tenantId, + String name, String description, + String ingress, String egress) { + + this.portPairId = portPairId; + this.tenantId = tenantId; + this.name = name; + this.description = description; + this.ingress = ingress; + this.egress = egress; + } + + @Override + public PortPairId portPairId() { + return portPairId; + } + + @Override + public TenantId tenantId() { + return tenantId; + } + + @Override + public String name() { + return name; + } + + @Override + public String description() { + return description; + } + + @Override + public String ingress() { + return ingress; + } + + @Override + public String egress() { + return egress; + } + + @Override + public int hashCode() { + return Objects.hash(portPairId, tenantId, name, description, + ingress, egress); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof DefaultPortPair) { + DefaultPortPair that = (DefaultPortPair) obj; + return Objects.equals(portPairId, that.portPairId) && + Objects.equals(tenantId, that.tenantId) && + Objects.equals(name, that.name) && + Objects.equals(description, that.description) && + Objects.equals(ingress, that.ingress) && + Objects.equals(egress, that.egress); + } + return false; + } + + @Override + public boolean exactMatch(PortPair portPair) { + return this.equals(portPair) && + Objects.equals(this.portPairId, portPair.portPairId()) && + Objects.equals(this.tenantId, portPair.tenantId()); + } + + @Override + public String toString() { + return toStringHelper(this) + .add("id", portPairId.toString()) + .add("tenantId", tenantId.tenantId()) + .add("name", name) + .add("description", description) + .add("ingress", ingress) + .add("egress", egress) + .toString(); + } + + /** + * To create an instance of the builder. + * + * @return instance of builder + */ + public static Builder builder() { + return new Builder(); + } + + /** + * Builder class for Port pair. + */ + public static final class Builder implements PortPair.Builder { + + private PortPairId portPairId; + private TenantId tenantId; + private String name; + private String description; + private String ingress; + private String egress; + + @Override + public Builder setId(PortPairId portPairId) { + this.portPairId = portPairId; + return this; + } + + @Override + public Builder setTenantId(TenantId tenantId) { + this.tenantId = tenantId; + return this; + } + + @Override + public Builder setName(String name) { + this.name = name; + return this; + } + + @Override + public Builder setDescription(String description) { + this.description = description; + return this; + } + + @Override + public Builder setIngress(String ingress) { + this.ingress = ingress; + return this; + } + + @Override + public Builder setEgress(String egress) { + this.egress = egress; + return this; + } + + @Override + public PortPair build() { + + checkNotNull(portPairId, "Port pair id cannot be null"); + checkNotNull(tenantId, "Tenant id cannot be null"); + checkNotNull(ingress, "Ingress of a port pair cannot be null"); + checkNotNull(egress, "Egress of a port pair cannot be null"); + + return new DefaultPortPair(portPairId, tenantId, name, description, + ingress, egress); + } + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultPortPairGroup.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultPortPairGroup.java new file mode 100644 index 00000000..877cc6c9 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultPortPairGroup.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 static com.google.common.base.Preconditions.checkNotNull; + +import java.util.List; +import java.util.Objects; + +import com.google.common.collect.ImmutableList; + +/** + * Implementation of port pair group. + */ +public final class DefaultPortPairGroup implements PortPairGroup { + + private final PortPairGroupId portPairGroupId; + private final TenantId tenantId; + private final String name; + private final String description; + private final List portPairList; + + /** + * Default constructor to create Port Pair Group. + * + * @param portPairGroupId port pair group id + * @param tenantId tenant id + * @param name name of port pair group + * @param description description of port pair group + * @param portPairList list of port pairs + */ + private DefaultPortPairGroup(PortPairGroupId portPairGroupId, TenantId tenantId, + String name, String description, + List portPairList) { + + this.portPairGroupId = portPairGroupId; + this.tenantId = tenantId; + this.name = name; + this.description = description; + this.portPairList = portPairList; + } + + @Override + public PortPairGroupId portPairGroupId() { + return portPairGroupId; + } + + @Override + public TenantId tenantId() { + return tenantId; + } + + @Override + public String name() { + return name; + } + + @Override + public String description() { + return description; + } + + @Override + public List portPairs() { + return ImmutableList.copyOf(portPairList); + } + + @Override + public int hashCode() { + return Objects.hash(portPairGroupId, tenantId, name, description, + portPairList); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof DefaultPortPairGroup) { + DefaultPortPairGroup that = (DefaultPortPairGroup) obj; + return Objects.equals(portPairGroupId, that.portPairGroupId) && + Objects.equals(tenantId, that.tenantId) && + Objects.equals(name, that.name) && + Objects.equals(description, that.description) && + Objects.equals(portPairList, that.portPairList); + } + return false; + } + + @Override + public boolean exactMatch(PortPairGroup portPairGroup) { + return this.equals(portPairGroup) && + Objects.equals(this.portPairGroupId, portPairGroup.portPairGroupId()) && + Objects.equals(this.tenantId, portPairGroup.tenantId()); + } + + @Override + public String toString() { + return toStringHelper(this) + .add("id", portPairGroupId.toString()) + .add("tenantId", tenantId.toString()) + .add("name", name) + .add("description", description) + .add("portPairGroupList", portPairList) + .toString(); + } + + /** + * To create an instance of the builder. + * + * @return instance of builder + */ + public static Builder builder() { + return new Builder(); + } + + /** + * Builder class for Port pair group. + */ + public static final class Builder implements PortPairGroup.Builder { + + private PortPairGroupId portPairGroupId; + private TenantId tenantId; + private String name; + private String description; + private List portPairList; + + @Override + public Builder setId(PortPairGroupId portPairGroupId) { + this.portPairGroupId = portPairGroupId; + return this; + } + + @Override + public Builder setTenantId(TenantId tenantId) { + this.tenantId = tenantId; + return this; + } + + @Override + public Builder setName(String name) { + this.name = name; + return this; + } + + @Override + public Builder setDescription(String description) { + this.description = description; + return this; + } + + @Override + public Builder setPortPairs(List portPairs) { + this.portPairList = portPairs; + return this; + } + + @Override + public PortPairGroup build() { + + checkNotNull(portPairGroupId, "Port pair group id cannot be null"); + checkNotNull(tenantId, "Tenant id cannot be null"); + checkNotNull(portPairList, "Port pairs cannot be null"); + + return new DefaultPortPairGroup(portPairGroupId, tenantId, name, description, + portPairList); + } + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/FlowClassifier.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/FlowClassifier.java new file mode 100644 index 00000000..7b4108dc --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/FlowClassifier.java @@ -0,0 +1,259 @@ +/* + * 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.IpPrefix; + +/** + * Abstraction of an entity which provides flow classifier for service function chain. + * FlowClassifier classify the traffic based on the criteria defined in the request. + * The classification can be based on port range or source and destination IP address or + * other flow classifier elements. + */ +public interface FlowClassifier { + + /** + * Returns flow classifier ID. + * + * @return flow classifier id + */ + FlowClassifierId flowClassifierId(); + + /** + * Returns Tenant ID. + * + * @return tenant Id + */ + TenantId tenantId(); + + /** + * Returns flow classifier name. + * + * @return flow classifier name + */ + String name(); + + /** + * Returns flow classifier description. + * + * @return flow classifier description + */ + String description(); + + /** + * Returns EtherType. + * + * @return EtherType + */ + String etherType(); + + /** + * Returns IP Protocol. + * + * @return IP protocol + */ + String protocol(); + + /** + * Returns minimum source port range. + * + * @return minimum source port range + */ + int minSrcPortRange(); + + /** + * Returns maximum source port range. + * + * @return maximum source port range + */ + int maxSrcPortRange(); + + /** + * Returns minimum destination port range. + * + * @return minimum destination port range + */ + int minDstPortRange(); + + /** + * Returns maximum destination port range. + * + * @return maximum destination port range. + */ + int maxDstPortRange(); + + /** + * Returns Source IP prefix. + * + * @return Source IP prefix + */ + IpPrefix srcIpPrefix(); + + /** + * Returns Destination IP prefix. + * + * @return Destination IP prefix + */ + IpPrefix dstIpPrefix(); + + /** + * Returns Source virtual port. + * + * @return Source virtual port + */ + VirtualPortId srcPort(); + + /** + * Returns Destination virtual port. + * + * @return Destination virtual port + */ + VirtualPortId dstPort(); + + /** + * Returns whether this Flow classifier is an exact match to the + * Flow classifier given in the argument. + * + * @param flowClassifier other flowClassifier to match against + * @return true if the flowClassifiers are an exact match, otherwise false + */ + boolean exactMatch(FlowClassifier flowClassifier); + + /** + * Builder for flow Classifier. + */ + interface Builder { + + /** + * Returns Flow Classifier. + * + * @return flow classifier. + */ + FlowClassifier build(); + + /** + * Sets Flow Classifier ID. + * + * @param flowClassifierId flow classifier id. + * @return Builder object by setting flow classifier Id. + */ + Builder setFlowClassifierId(FlowClassifierId flowClassifierId); + + /** + * Sets Tenant ID. + * + * @param tenantId tenant id. + * @return Builder object by setting Tenant ID. + */ + Builder setTenantId(TenantId tenantId); + + /** + * Sets Flow classifier name. + * + * @param name flow classifier name + * @return builder object by setting flow classifier name + */ + Builder setName(String name); + + /** + * Sets flow classifier description. + * + * @param description flow classifier description + * @return flow classifier description + */ + Builder setDescription(String description); + + /** + * Sets EtherType. + * + * @param etherType EtherType + * @return EtherType + */ + Builder setEtherType(String etherType); + + /** + * Sets IP protocol. + * + * @param protocol IP protocol + * @return builder object by setting IP protocol + */ + Builder setProtocol(String protocol); + + /** + * Set minimum source port range. + * + * @param minRange minimum source port range + * @return builder object by setting minimum source port range + */ + Builder setMinSrcPortRange(int minRange); + + /** + * Sets maximum source port range. + * + * @param maxRange maximum source port range + * @return builder object by setting maximum source port range + */ + Builder setMaxSrcPortRange(int maxRange); + + /** + * Sets minimum destination port range. + * + * @param minRange minimum destination port range + * @return builder object by setting minimum destination port range + */ + Builder setMinDstPortRange(int minRange); + + /** + * Sets maximum destination port range. + * + * @param maxRange maximum destination port range. + * @return builder object by setting maximum destination port range. + */ + Builder setMaxDstPortRange(int maxRange); + + /** + * Sets Source IP prefix. + * + * @param srcIpPrefix Source IP prefix + * @return builder object by setting Source IP prefix + */ + Builder setSrcIpPrefix(IpPrefix srcIpPrefix); + + /** + * Sets Destination IP prefix. + * + * @param dstIpPrefix Destination IP prefix + * @return builder object by setting Destination IP prefix + */ + Builder setDstIpPrefix(IpPrefix dstIpPrefix); + + /** + * Sets Source virtual port. + * + * @param srcPort Source virtual port + * @return builder object by setting Source virtual port + */ + Builder setSrcPort(VirtualPortId srcPort); + + /** + * Sets Destination virtual port. + * + * @param dstPort Destination virtual port + * @return builder object by setting Destination virtual port + */ + Builder setDstPort(VirtualPortId dstPort); + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/FlowClassifierId.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/FlowClassifierId.java new file mode 100644 index 00000000..b789abe3 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/FlowClassifierId.java @@ -0,0 +1,91 @@ +/* + * 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 com.google.common.base.MoreObjects; + +import java.util.UUID; +import java.util.Objects; + +/** + * Flow classification identifier. + */ +public final class FlowClassifierId { + + private final UUID flowClassifierId; + + /** + * Constructor to create flow classifier id. + * + * @param flowClassifierId flow classifier id. + */ + private FlowClassifierId(final UUID flowClassifierId) { + this.flowClassifierId = flowClassifierId; + } + + /** + * Returns new flow classifier id. + * + * @param flowClassifierId flow classifier id + * @return new flow classifier id + */ + public static FlowClassifierId flowClassifierId(final UUID flowClassifierId) { + return new FlowClassifierId(flowClassifierId); + } + + /** + * Returns new flow classifier id. + * + * @param flowClassifierId flow classifier id + * @return new flow classifier id + */ + public static FlowClassifierId flowClassifierId(final String flowClassifierId) { + return new FlowClassifierId(UUID.fromString(flowClassifierId)); + } + + /** + * Returns the value of flow classifier id. + * + * @return flow classifier id. + */ + public UUID value() { + return flowClassifierId; + } + + @Override + public int hashCode() { + return Objects.hashCode(this.flowClassifierId); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof FlowClassifierId) { + final FlowClassifierId other = (FlowClassifierId) obj; + return Objects.equals(this.flowClassifierId, other.flowClassifierId); + } + return false; + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(getClass()) + .add("FlowClassifierId", flowClassifierId) + .toString(); + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PortChain.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PortChain.java new file mode 100644 index 00000000..d147eaaa --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PortChain.java @@ -0,0 +1,148 @@ +/* + * 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.List; + +/** + * Abstraction of an entity providing Port Chain information. + * A Port Chain (Service Function Path) consists of + * a set of Neutron ports, to define the sequence of service functions + * a set of flow classifiers, to specify the classified traffic flows to enter the chain + */ +public interface PortChain { + + /** + * Returns the ID of this port chain. + * + * @return the port chain id + */ + PortChainId portChainId(); + + /** + * Returns the tenant id of this port chain. + * + * @return the tenant id + */ + TenantId tenantId(); + + /** + * Returns the name of this port chain. + * + * @return name of port chain + */ + String name(); + + /** + * Returns the description of this port chain. + * + * @return description of port chain + */ + String description(); + + /** + * Returns the list of port pair groups associated with + * this port chain. + * + * @return list of port pair groups + */ + List portPairGroups(); + + /** + * Returns the list of flow classifiers associated with + * this port chain. + * + * @return list of flow classifiers + */ + List flowClassifiers(); + + /** + * Returns whether this port chain is an exact match to the port chain given + * in the argument. + *

+ * Exact match means the port pair groups and flow classifiers match + * with the given port chain. It does not consider the port chain id, name + * and description. + *

+ * + * @param portChain other port chain to match against + * @return true if the port chains are an exact match, otherwise false + */ + boolean exactMatch(PortChain portChain); + + /** + * A port chain builder.. + */ + interface Builder { + + /** + * Assigns the port chain id to this object. + * + * @param portChainId the port chain id + * @return this the builder object + */ + Builder setId(PortChainId portChainId); + + /** + * Assigns tenant id to this object. + * + * @param tenantId tenant id of the port chain + * @return this the builder object + */ + Builder setTenantId(TenantId tenantId); + + /** + * Assigns the name to this object. + * + * @param name name of the port chain + * @return this the builder object + */ + Builder setName(String name); + + /** + * Assigns the description to this object. + * + * @param description description of the port chain + * @return this the builder object + */ + Builder setDescription(String description); + + /** + * Assigns the port pair groups associated with the port chain + * to this object. + * + * @param portPairGroups list of port pair groups + * @return this the builder object + */ + Builder setPortPairGroups(List portPairGroups); + + /** + * Assigns the flow classifiers associated with the port chain + * to this object. + * + * @param flowClassifiers list of flow classifiers + * @return this the builder object + */ + Builder setFlowClassifiers(List flowClassifiers); + + /** + * Builds a port chain object. + * + * @return a port chain. + */ + PortChain build(); + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PortChainId.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PortChainId.java new file mode 100644 index 00000000..66edbdcc --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PortChainId.java @@ -0,0 +1,95 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.vtnrsc; + +import static com.google.common.base.MoreObjects.toStringHelper; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.UUID; + +import com.google.common.base.Objects; + +/** + * Representation of a Port Chain ID. + */ +public final class PortChainId { + + private final UUID portChainId; + + /** + * Private constructor for port chain id. + * + * @param id UUID id of port chain + */ + private PortChainId(UUID id) { + checkNotNull(id, "Port chain id can not be null"); + this.portChainId = id; + } + + /** + * Constructor to create port chain id from UUID. + * + * @param id UUID of port chain + * @return object of port chain id + */ + public static PortChainId portChainId(UUID id) { + return new PortChainId(id); + } + + /** + * Constructor to create port chain id from string. + * + * @param id port chain id in string + * @return object of port chain id + */ + public static PortChainId portChainId(String id) { + return new PortChainId(UUID.fromString(id)); + } + + /** + * Returns the value of port chain id. + * + * @return port chain id + */ + public UUID value() { + return portChainId; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + + if (obj.getClass() == this.getClass()) { + PortChainId that = (PortChainId) obj; + return Objects.equal(this.portChainId, that.portChainId); + } + return false; + } + + @Override + public int hashCode() { + return Objects.hashCode(this.portChainId); + } + + @Override + public String toString() { + return toStringHelper(this) + .add("portChainId", portChainId.toString()) + .toString(); + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PortPair.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PortPair.java new file mode 100644 index 00000000..f6285e61 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PortPair.java @@ -0,0 +1,139 @@ +/* + * 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; + + +/** + * Abstraction of an entity providing Port Pair information. + * A port pair represents a service function instance. + */ +public interface PortPair { + + /** + * Returns the ID of this port Pair. + * + * @return the port pair id + */ + PortPairId portPairId(); + + /** + * Returns the tenant id of this port pair. + * + * @return an tenant id + */ + TenantId tenantId(); + + /** + * Returns the description of this port pair. + * + * @return description of port pair + */ + String name(); + + /** + * Returns the description of this port pair. + * + * @return description of port pair + */ + String description(); + + /** + * Returns the ingress port of this port pair. + * + * @return ingress of port pair + */ + String ingress(); + + /** + * Returns the egress port of this port pair. + * + * @return egress of port pair + */ + String egress(); + + /** + * Returns whether this port pair is an exact match to the port pair given + * in the argument. + *

+ * Exact match means the Port port pairs match with the given port pair. + * It does not consider the port pair id, name and description. + *

+ * @param portPair other port pair to match against + * @return true if the port pairs are an exact match, otherwise false + */ + boolean exactMatch(PortPair portPair); + + /** + * A port pair builder.. + */ + interface Builder { + + /** + * Assigns the port pair id to this object. + * + * @param portPairId the port pair id + * @return this the builder object + */ + Builder setId(PortPairId portPairId); + + /** + * Assigns tenant id to this object. + * + * @param tenantId tenant id of the port pair + * @return this the builder object + */ + Builder setTenantId(TenantId tenantId); + + /** + * Assigns the name to this object. + * + * @param name name of the port pair + * @return this the builder object + */ + Builder setName(String name); + + /** + * Assigns the description to this object. + * + * @param description description of the port pair + * @return this the builder object + */ + Builder setDescription(String description); + + /** + * Assigns the ingress port to this object. + * + * @param port ingress port of the port pair + * @return this the builder object + */ + Builder setIngress(String port); + + /** + * Assigns the egress port to this object. + * + * @param port egress port of the port pair + * @return this the builder object + */ + Builder setEgress(String port); + + /** + * Builds a port pair object. + * + * @return a port pair. + */ + PortPair build(); + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PortPairGroup.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PortPairGroup.java new file mode 100644 index 00000000..f647b57f --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PortPairGroup.java @@ -0,0 +1,126 @@ +/* + * 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.List; + +/** + * Abstraction of an entity providing Port Pair Group information. + * A port pair group consists of one or more port pairs. + */ +public interface PortPairGroup { + + /** + * Returns the ID of this port pair group. + * + * @return the port pair group id + */ + PortPairGroupId portPairGroupId(); + + /** + * Returns the tenant id of this port pair group. + * + * @return the tenant id + */ + TenantId tenantId(); + + /** + * Returns the name of this port pair group. + * + * @return name of port pair group + */ + String name(); + + /** + * Returns the description of this port pair group. + * + * @return description of port pair group + */ + String description(); + + /** + * Returns the list of port pairs associated with this port pair group. + * + * @return list of port pairs + */ + List portPairs(); + + /** + * Returns whether this port pair group is an exact match to the + * port pair group given in the argument. + *

+ * Exact match means the Port pairs match with the given port pair group. + * It does not consider the port pair group id, name and description. + *

+ * @param portPairGroup other port pair group to match against + * @return true if the port pairs are an exact match, otherwise false + */ + boolean exactMatch(PortPairGroup portPairGroup); + + /** + * A port pair group builder.. + */ + interface Builder { + + /** + * Assigns the port pair group id to this object. + * + * @param portPairGroupId the port pair group id + * @return this the builder object + */ + Builder setId(PortPairGroupId portPairGroupId); + + /** + * Assigns tenant id to this object. + * + * @param tenantId tenant id of port pair group + * @return this the builder object + */ + Builder setTenantId(TenantId tenantId); + + /** + * Assigns the name to this object. + * + * @param name name of the port pair group + * @return this the builder object + */ + Builder setName(String name); + + /** + * Assigns the description to this object. + * + * @param description description of the port pair group + * @return this the builder object + */ + Builder setDescription(String description); + + /** + * Assigns the port pairs associated with the port pair group + * to this object. + * + * @param portPairs list of port pairs + * @return this the builder object + */ + Builder setPortPairs(List portPairs); + + /** + * Builds a port pair group object. + * + * @return a port pair group object. + */ + PortPairGroup build(); + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PortPairGroupId.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PortPairGroupId.java new file mode 100644 index 00000000..0474901c --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PortPairGroupId.java @@ -0,0 +1,95 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.vtnrsc; + +import static com.google.common.base.MoreObjects.toStringHelper; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.UUID; + +import com.google.common.base.Objects; + +/** + * Representation of a Port Pair Group ID. + */ +public final class PortPairGroupId { + + private final UUID portPairGroupId; + + /** + * Private constructor for port pair group id. + * + * @param id UUID id of port pair group + */ + private PortPairGroupId(UUID id) { + checkNotNull(id, "Port pair group id can not be null"); + this.portPairGroupId = id; + } + + /** + * Constructor to create port pair group id from UUID. + * + * @param id UUID of port pair group id + * @return object of port pair group id + */ + public static PortPairGroupId portPairGroupId(UUID id) { + return new PortPairGroupId(id); + } + + /** + * Constructor to create port pair group id from string. + * + * @param id port pair group id in string + * @return object of port pair group id + */ + public static PortPairGroupId portPairGroupId(String id) { + return new PortPairGroupId(UUID.fromString(id)); + } + + /** + * Returns the value of port pair group id. + * + * @return port pair group id + */ + public UUID value() { + return portPairGroupId; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + + if (obj.getClass() == this.getClass()) { + PortPairGroupId that = (PortPairGroupId) obj; + return Objects.equal(this.portPairGroupId, that.portPairGroupId); + } + return false; + } + + @Override + public int hashCode() { + return Objects.hashCode(this.portPairGroupId); + } + + @Override + public String toString() { + return toStringHelper(this) + .add("portPairGroupId", portPairGroupId.toString()) + .toString(); + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PortPairId.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PortPairId.java new file mode 100644 index 00000000..05c31aac --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PortPairId.java @@ -0,0 +1,95 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.vtnrsc; + +import static com.google.common.base.MoreObjects.toStringHelper; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.UUID; + +import com.google.common.base.Objects; + +/** + * Representation of a Port Pair ID. + */ +public final class PortPairId { + + private final UUID portPairId; + + /** + * Private constructor for port pair id. + * + * @param id UUID id of port pair + */ + private PortPairId(UUID id) { + checkNotNull(id, "Port chain id can not be null"); + this.portPairId = id; + } + + /** + * Constructor to create port pair id from UUID. + * + * @param id UUID of port pair id + * @return object of port pair id + */ + public static PortPairId portPairId(UUID id) { + return new PortPairId(id); + } + + /** + * Constructor to create port pair id from string. + * + * @param id port pair id in string + * @return object of port pair id + */ + public static PortPairId portPairId(String id) { + return new PortPairId(UUID.fromString(id)); + } + + /** + * Returns teh value of port pair id. + * + * @return port pair id + */ + public UUID value() { + return portPairId; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + + if (obj.getClass() == this.getClass()) { + PortPairId that = (PortPairId) obj; + return Objects.equal(this.portPairId, that.portPairId); + } + return false; + } + + @Override + public int hashCode() { + return Objects.hashCode(this.portPairId); + } + + @Override + public String toString() { + return toStringHelper(this) + .add("portPairId", portPairId.toString()) + .toString(); + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowClassifier/FlowClassifierService.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowClassifier/FlowClassifierService.java new file mode 100644 index 00000000..e379be81 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowClassifier/FlowClassifierService.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.flowClassifier; + +import org.onosproject.vtnrsc.FlowClassifier; +import org.onosproject.vtnrsc.FlowClassifierId; + +/** + * Provides Services for Flow Classifier. + */ +public interface FlowClassifierService { + + /** + * Store Flow Classifier. + * + * @param flowClassifier Flow Classifier + * @return true if adding Flow Classifier into store is success otherwise return false. + */ + boolean createFlowClassifier(FlowClassifier flowClassifier); + + /** + * Return the existing collection of Flow Classifier. + * + * @return Flow Classifier collections. + */ + Iterable getFlowClassifiers(); + + /** + * Check whether Flow Classifier is present based on given Flow Classifier Id. + * + * @param id Flow Classifier. + * @return true if Flow Classifier is present otherwise return false. + */ + boolean hasFlowClassifier(FlowClassifierId id); + + /** + * Retrieve the Flow Classifier based on given Flow Classifier id. + * + * @param id Flow Classifier Id. + * @return Flow Classifier if present otherwise returns null. + */ + FlowClassifier getFlowClassifier(FlowClassifierId id); + + /** + * Update Flow Classifier based on given Flow Classifier Id. + * + * @param flowClassifier Flow Classifier. + * @return true if update is success otherwise return false. + */ + boolean updateFlowClassifier(FlowClassifier flowClassifier); + + /** + * Remove Flow Classifier from store based on given Flow Classifier Id. + * + * @param id Flow Classifier Id. + * @return true if Flow Classifier removal is success otherwise return false. + */ + boolean removeFlowClassifier(FlowClassifierId id); +} \ No newline at end of file diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowClassifier/impl/FlowClassifierManager.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowClassifier/impl/FlowClassifierManager.java new file mode 100644 index 00000000..7238558a --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowClassifier/impl/FlowClassifierManager.java @@ -0,0 +1,108 @@ +/* + * 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.flowClassifier.impl; + +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; + +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.Service; +import org.onosproject.vtnrsc.FlowClassifierId; +import org.onosproject.vtnrsc.FlowClassifier; +import org.onosproject.vtnrsc.flowClassifier.FlowClassifierService; + +import org.slf4j.Logger; +import static org.slf4j.LoggerFactory.getLogger; + +import static com.google.common.base.Preconditions.checkNotNull; +import com.google.common.collect.ImmutableList; + +/** + * Provides implementation of the Flow Classifier Service. + */ +@Component(immediate = true) +@Service +public class FlowClassifierManager implements FlowClassifierService { + + private final Logger log = getLogger(FlowClassifierManager.class); + + private static final String FLOW_CLASSIFIER_NOT_NULL = "Flow Classifier cannot be null"; + private static final String FLOW_CLASSIFIER_ID_NOT_NULL = "Flow Classifier Id cannot be null"; + + private ConcurrentMap flowClassifierStore + = new ConcurrentHashMap(); + + @Activate + private void activate() { + log.info("Flow Classifier service activated"); + } + + @Deactivate + private void deactivate() { + log.info("Flow Classifier service deactivated"); + } + + @Override + public boolean createFlowClassifier(FlowClassifier flowClassifier) { + log.debug("createFlowClassifier"); + checkNotNull(flowClassifier, FLOW_CLASSIFIER_NOT_NULL); + FlowClassifierId id = flowClassifier.flowClassifierId(); + + flowClassifierStore.put(id, flowClassifier); + if (!flowClassifierStore.containsKey(id)) { + log.debug("Flow Classifier creation is failed whose identifier is {}.", id.toString()); + return false; + } + return true; + } + + @Override + public Iterable getFlowClassifiers() { + return ImmutableList.copyOf(flowClassifierStore.values()); + } + + @Override + public boolean hasFlowClassifier(FlowClassifierId id) { + checkNotNull(id, FLOW_CLASSIFIER_ID_NOT_NULL); + return flowClassifierStore.containsKey(id); + } + + @Override + public FlowClassifier getFlowClassifier(FlowClassifierId id) { + checkNotNull(id, FLOW_CLASSIFIER_ID_NOT_NULL); + return flowClassifierStore.get(id); + } + + @Override + public boolean updateFlowClassifier(FlowClassifier flowClassifier) { + checkNotNull(flowClassifier, FLOW_CLASSIFIER_NOT_NULL); + FlowClassifierId id = flowClassifier.flowClassifierId(); + return flowClassifierStore.replace(id, flowClassifierStore.get(id), flowClassifier); + } + + @Override + public boolean removeFlowClassifier(FlowClassifierId id) { + checkNotNull(id, FLOW_CLASSIFIER_ID_NOT_NULL); + flowClassifierStore.remove(id); + if (flowClassifierStore.containsKey(id)) { + log.debug("The Flow Classifier removal is failed whose identifier is {}", id.toString()); + return false; + } + return true; + } +} \ No newline at end of file diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowClassifier/impl/package-info.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowClassifier/impl/package-info.java new file mode 100644 index 00000000..4ea050b3 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowClassifier/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 flow Classifier service. + */ +package org.onosproject.vtnrsc.flowClassifier.impl; diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowClassifier/package-info.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowClassifier/package-info.java new file mode 100644 index 00000000..07584170 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowClassifier/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 flow Classifier of SFC. + */ +package org.onosproject.vtnrsc.flowClassifier; diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portchain/PortChainService.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portchain/PortChainService.java new file mode 100644 index 00000000..b4ff917e --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portchain/PortChainService.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.portchain; + +import org.onosproject.vtnrsc.PortChain; +import org.onosproject.vtnrsc.PortChainId; + +/** + * Service for interacting with the inventory of port chains. + */ +public interface PortChainService { + + /** + * Returns if the port chain is existed. + * + * @param portChainId port chain identifier + * @return true or false if one with the given identifier exists. + */ + boolean exists(PortChainId portChainId); + + /** + * Returns the number of port chains known to the system. + * + * @return number of port chains. + */ + int getPortChainCount(); + + /** + * Returns an iterable collection of the currently known port chains. + * + * @return collection of port chains. + */ + Iterable getPortChains(); + + /** + * Returns the portChain with the given identifier. + * + * @param portChainId port chain identifier + * @return PortChain or null if port chain with the given identifier is not + * known. + */ + PortChain getPortChain(PortChainId portChainId); + + /** + * Creates a PortChain in the store. + * + * @param portChain the port chain to create + * @return true if given port chain is created successfully. + */ + boolean createPortChain(PortChain portChain); + + /** + * Updates the portChain in the store. + * + * @param portChain the port chain to update + * @return true if given port chain is updated successfully. + */ + boolean updatePortChain(PortChain portChain); + + /** + * Deletes portChain by given portChainId. + * + * @param portChainId id of port chain to remove + * @return true if the give port chain is deleted successfully. + */ + boolean removePortChain(PortChainId portChainId); +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portchain/package-info.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portchain/package-info.java new file mode 100644 index 00000000..74642bc3 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portchain/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 port chains. + */ +package org.onosproject.vtnrsc.portchain; diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpairgroup/PortPairGroupService.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpairgroup/PortPairGroupService.java new file mode 100644 index 00000000..77f483fc --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpairgroup/PortPairGroupService.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.portpairgroup; + +import org.onosproject.vtnrsc.PortPairGroup; +import org.onosproject.vtnrsc.PortPairGroupId; + +/** + * Service for interacting with the inventory of port pair groups. + */ +public interface PortPairGroupService { + + /** + * Returns if the port pair group is existed. + * + * @param portPairGroupId port pair group identifier + * @return true or false if one with the given identifier exists. + */ + boolean exists(PortPairGroupId portPairGroupId); + + /** + * Returns the number of port pair groups known to the system. + * + * @return number of port pair groups. + */ + int getPortPairGroupCount(); + + /** + * Returns an iterable collection of the currently known port pair groups. + * + * @return collection of port pair groups. + */ + Iterable getPortPairGroups(); + + /** + * Returns the portPairGroup with the given identifier. + * + * @param portPairGroupId port pair group identifier + * @return PortPairGroup or null if port pair group with the given identifier is not + * known. + */ + PortPairGroup getPortPairGroup(PortPairGroupId portPairGroupId); + + /** + * Creates a PortPairGroup in the store. + * + * @param portPairGroup the port pair group to create + * @return true if given port pair group is created successfully. + */ + boolean createPortPairGroup(PortPairGroup portPairGroup); + + /** + * Updates the portPairGroup in the store. + * + * @param portPairGroup the port pair group to update + * @return true if given port pair group is updated successfully. + */ + boolean updatePortPairGroup(PortPairGroup portPairGroup); + + /** + * Deletes portPairGroup by given portPairGroupId. + * + * @param portPairGroupId id of port pair group to remove + * @return true if the give port pair group is deleted successfully. + */ + boolean removePortPairGroup(PortPairGroupId portPairGroupId); +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpairgroup/package-info.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpairgroup/package-info.java new file mode 100644 index 00000000..8a79fe97 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpairgroup/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 port pair groups. + */ +package org.onosproject.vtnrsc.portpairgroup; 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 deleted file mode 100644 index 6f3cf653..00000000 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/tunnel/TunnelConfigService.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * 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 deleted file mode 100644 index 3a84e6e3..00000000 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/tunnel/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/impl/VirtualPortManager.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/virtualport/impl/VirtualPortManager.java index c45373b9..daec7839 100644 --- 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 @@ -191,22 +191,20 @@ public class VirtualPortManager implements VirtualPortService { @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; - } + 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); + 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; - } + if (!vPort.equals(vPortStore.get(vPort.portId()))) { + log.debug("The virtualPort is updated failed whose identifier is {}", + vPort.portId().toString()); + return false; } } return true; @@ -215,14 +213,12 @@ public class VirtualPortManager implements VirtualPortService { @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; - } + 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/web/AllocationPoolsCodec.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/AllocationPoolsCodec.java deleted file mode 100644 index 57c97c1c..00000000 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/AllocationPoolsCodec.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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 deleted file mode 100644 index 7960808f..00000000 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/AllowedAddressPairCodec.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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 deleted file mode 100644 index 96c9bb4e..00000000 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/FixedIpCodec.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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/FlowClassifierCodec.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/FlowClassifierCodec.java new file mode 100644 index 00000000..fd5b1ee4 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/FlowClassifierCodec.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.web; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.onlab.util.Tools.nullIsIllegal; + +import java.util.UUID; + +import org.onlab.packet.IpPrefix; +import org.onosproject.codec.CodecContext; +import org.onosproject.codec.JsonCodec; +import org.onosproject.vtnrsc.DefaultFlowClassifier; +import org.onosproject.vtnrsc.FlowClassifier; +import org.onosproject.vtnrsc.FlowClassifierId; +import org.onosproject.vtnrsc.VirtualPortId; +import org.onosproject.vtnrsc.TenantId; + +import com.fasterxml.jackson.databind.node.ObjectNode; + +/** + * Flow Classifier JSON codec. + */ +public final class FlowClassifierCodec extends JsonCodec { + + private static final String FLOW_CLASSIFIER_ID = "id"; + private static final String TENANT_ID = "tenant_id"; + private static final String NAME = "name"; + private static final String DESCRIPTION = "description"; + private static final String ETHER_TYPE = "etherType"; + private static final String PROTOCOL = "protocol"; + private static final String MIN_SRC_PORT_RANGE = "source_port_range_min"; + private static final String MAX_SRC_PORT_RANGE = "source_port_range_max"; + private static final String MIN_DST_PORT_RANGE = "destination_port_range_min"; + private static final String MAX_DST_PORT_RANGE = "destination_port_range_max"; + private static final String SRC_IP_PREFIX = "source_ip_prefix"; + private static final String DST_IP_PREFIX = "destination_ip_prefix"; + private static final String SRC_PORT = "logical_source_port"; + private static final String DST_PORT = "logical_destination_port"; + private static final String MISSING_MEMBER_MESSAGE = " member is required in Flow Classifier."; + + @Override + public FlowClassifier decode(ObjectNode json, CodecContext context) { + if (json == null || !json.isObject()) { + return null; + } + + FlowClassifier.Builder resultBuilder = new DefaultFlowClassifier.Builder(); + + String flowClassifierId = nullIsIllegal(json.get(FLOW_CLASSIFIER_ID), + FLOW_CLASSIFIER_ID + MISSING_MEMBER_MESSAGE).asText(); + resultBuilder.setFlowClassifierId(FlowClassifierId.flowClassifierId(UUID.fromString(flowClassifierId))); + + String tenantId = nullIsIllegal(json.get(TENANT_ID), TENANT_ID + MISSING_MEMBER_MESSAGE).asText(); + resultBuilder.setTenantId(TenantId.tenantId(tenantId)); + + String flowClassiferName = nullIsIllegal(json.get(NAME), NAME + MISSING_MEMBER_MESSAGE).asText(); + resultBuilder.setName(flowClassiferName); + + String flowClassiferDescription = nullIsIllegal(json.get(DESCRIPTION), DESCRIPTION + MISSING_MEMBER_MESSAGE) + .asText(); + resultBuilder.setDescription(flowClassiferDescription); + + String etherType = nullIsIllegal(json.get(ETHER_TYPE), ETHER_TYPE + MISSING_MEMBER_MESSAGE).asText(); + resultBuilder.setEtherType(etherType); + + String protocol = nullIsIllegal(json.get(PROTOCOL), PROTOCOL + MISSING_MEMBER_MESSAGE).asText(); + resultBuilder.setProtocol(protocol); + + int minSrcPortRange = nullIsIllegal(json.get(MIN_SRC_PORT_RANGE), MIN_SRC_PORT_RANGE + MISSING_MEMBER_MESSAGE) + .asInt(); + resultBuilder.setMinSrcPortRange(minSrcPortRange); + + int maxSrcPortRange = nullIsIllegal(json.get(MAX_SRC_PORT_RANGE), MAX_SRC_PORT_RANGE + MISSING_MEMBER_MESSAGE) + .asInt(); + resultBuilder.setMaxSrcPortRange(maxSrcPortRange); + + int minDstPortRange = nullIsIllegal(json.get(MIN_DST_PORT_RANGE), MIN_DST_PORT_RANGE + MISSING_MEMBER_MESSAGE) + .asInt(); + resultBuilder.setMinDstPortRange(minDstPortRange); + + int maxDstPortRange = nullIsIllegal(json.get(MAX_DST_PORT_RANGE), MAX_DST_PORT_RANGE + MISSING_MEMBER_MESSAGE) + .asInt(); + resultBuilder.setMaxDstPortRange(maxDstPortRange); + + String srcIpPrefix = nullIsIllegal(json.get(SRC_IP_PREFIX), SRC_IP_PREFIX + MISSING_MEMBER_MESSAGE).asText(); + resultBuilder.setSrcIpPrefix(IpPrefix.valueOf(srcIpPrefix)); + + String dstIpPrefix = nullIsIllegal(json.get(DST_IP_PREFIX), DST_IP_PREFIX + MISSING_MEMBER_MESSAGE).asText(); + resultBuilder.setDstIpPrefix(IpPrefix.valueOf(dstIpPrefix)); + + String srcPort = nullIsIllegal(json.get(SRC_PORT), SRC_PORT + MISSING_MEMBER_MESSAGE).asText(); + resultBuilder.setSrcPort(VirtualPortId.portId(srcPort)); + + String dstPort = nullIsIllegal(json.get(DST_PORT), DST_PORT + MISSING_MEMBER_MESSAGE).asText(); + resultBuilder.setDstPort(VirtualPortId.portId(dstPort)); + + return resultBuilder.build(); + } + + @Override + public ObjectNode encode(FlowClassifier flowClassifier, CodecContext context) { + checkNotNull(flowClassifier, "flowClassifier cannot be null"); + ObjectNode result = context.mapper().createObjectNode() + .put("FLOW_CLASSIFIER_ID", flowClassifier.flowClassifierId().toString()) + .put("TENANT_ID", flowClassifier.tenantId().toString()) + .put("NAME", flowClassifier.name()) + .put("DESCRIPTION", flowClassifier.description()) + .put("ETHER_TYPE", flowClassifier.etherType()) + .put("PROTOCOL", flowClassifier.protocol()) + .put("MIN_SRC_PORT_RANGE", flowClassifier.minSrcPortRange()) + .put("MAX_SRC_PORT_RANGE", flowClassifier.maxSrcPortRange()) + .put("MIN_DST_PORT_RANGE", flowClassifier.minDstPortRange()) + .put("MAX_DST_PORT_RANGE", flowClassifier.maxDstPortRange()) + .put("SRC_IP_PREFIX", flowClassifier.srcIpPrefix().toString()) + .put("DST_IP_PREFIX", flowClassifier.dstIpPrefix().toString()) + .put("SRC_PORT", flowClassifier.srcPort().toString()) + .put("DST_PORT", flowClassifier.dstPort().toString()); + return result; + } +} \ No newline at end of file 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 deleted file mode 100644 index 69ca6b3f..00000000 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/HostRoutesCodec.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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 deleted file mode 100644 index c2ded196..00000000 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/SecurityGroupCodec.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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 deleted file mode 100644 index 122b75a9..00000000 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/SubnetCodec.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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 deleted file mode 100644 index 48ba3b97..00000000 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/TenantNetworkCodec.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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 deleted file mode 100644 index e57d56bc..00000000 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/VirtualPortCodec.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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/test/java/org/onosproject/vtnrsc/flowclassifier/FlowClassifierIdTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/flowclassifier/FlowClassifierIdTest.java new file mode 100644 index 00000000..b2fed347 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/flowclassifier/FlowClassifierIdTest.java @@ -0,0 +1,68 @@ +/* + * 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.flowclassifier; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; +import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; + +import org.junit.Test; +import org.onosproject.vtnrsc.FlowClassifierId; + +import com.google.common.testing.EqualsTester; +import java.util.UUID; + +/** + * Unit tests for FlowClassifierId class. + */ +public class FlowClassifierIdTest { + + final FlowClassifierId flowClassifierId1 = FlowClassifierId + .flowClassifierId("78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae"); + final FlowClassifierId sameAsFlowClassifierId1 = FlowClassifierId + .flowClassifierId("78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae"); + final FlowClassifierId flowClassifierId2 = FlowClassifierId + .flowClassifierId("dace4513-24fc-4fae-af4b-321c5e2eb3d1"); + + /** + * Checks that the FlowClassifierId class is immutable. + */ + @Test + public void testImmutability() { + assertThatClassIsImmutable(FlowClassifierId.class); + } + + /** + * Checks the operation of equals() methods. + */ + @Test + public void testEquals() { + new EqualsTester().addEqualityGroup(flowClassifierId1, sameAsFlowClassifierId1) + .addEqualityGroup(flowClassifierId2).testEquals(); + } + + /** + * Checks the construction of a FlowClassifierId object. + */ + @Test + public void testConstruction() { + final String flowClassifierIdValue = "dace4513-24fc-4fae-af4b-321c5e2eb3d1"; + final FlowClassifierId flowClassifierId = FlowClassifierId.flowClassifierId(flowClassifierIdValue); + assertThat(flowClassifierId, is(notNullValue())); + assertThat(flowClassifierId.value(), is(UUID.fromString(flowClassifierIdValue))); + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/subnet/DefaultAllocationPoolTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/subnet/DefaultAllocationPoolTest.java new file mode 100644 index 00000000..4ce4def2 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/subnet/DefaultAllocationPoolTest.java @@ -0,0 +1,68 @@ +/* + * 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 static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; + +import org.junit.Test; +import org.onlab.packet.IpAddress; +import org.onosproject.vtnrsc.AllocationPool; +import org.onosproject.vtnrsc.DefaultAllocationPool; + +import com.google.common.testing.EqualsTester; + +/** + * Unit tests for DefaultAllocationPool class. + */ +public class DefaultAllocationPoolTest { + + final IpAddress startIP1 = IpAddress.valueOf("192.168.1.1"); + final IpAddress startIP2 = IpAddress.valueOf("192.168.1.2"); + final IpAddress endIP1 = IpAddress.valueOf("192.168.1.1"); + final IpAddress endIP2 = IpAddress.valueOf("192.168.1.2"); + + /** + * Checks that the DefaultAllocationPool class is immutable. + */ + @Test + public void testImmutability() { + assertThatClassIsImmutable(DefaultAllocationPool.class); + } + + /** + * Checks the operation of equals() methods. + */ + @Test + public void testEquals() { + AllocationPool pool1 = new DefaultAllocationPool(startIP1, endIP1); + AllocationPool pool2 = new DefaultAllocationPool(startIP1, endIP1); + AllocationPool pool3 = new DefaultAllocationPool(startIP2, endIP2); + new EqualsTester().addEqualityGroup(pool1, pool2) + .addEqualityGroup(pool3).testEquals(); + } + + /** + * Checks the construction of a DefaultAllocationPool object. + */ + @Test + public void testConstruction() { + final AllocationPool apool = new DefaultAllocationPool(startIP1, endIP1); + assertThat(startIP1, is(apool.startIp())); + assertThat(endIP1, is(apool.endIp())); + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/subnet/DefaultHostRouteTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/subnet/DefaultHostRouteTest.java new file mode 100644 index 00000000..2f751742 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/subnet/DefaultHostRouteTest.java @@ -0,0 +1,68 @@ +/* + * 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 static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; + +import org.junit.Test; +import org.onlab.packet.IpAddress; +import org.onlab.packet.IpPrefix; +import org.onosproject.vtnrsc.DefaultHostRoute; +import org.onosproject.vtnrsc.HostRoute; + +import com.google.common.testing.EqualsTester; + +/** + * Unit tests for DefaultHostRoute class. + */ +public class DefaultHostRouteTest { + final IpAddress nexthop1 = IpAddress.valueOf("192.168.1.1"); + final IpAddress nexthop2 = IpAddress.valueOf("192.168.1.2"); + final IpPrefix destination1 = IpPrefix.valueOf("1.1.1.1/1"); + final IpPrefix destination2 = IpPrefix.valueOf("1.1.1.1/2"); + + /** + * Checks that the DefaultHostRoute class is immutable. + */ + @Test + public void testImmutability() { + assertThatClassIsImmutable(DefaultHostRoute.class); + } + + /** + * Checks the operation of equals() methods. + */ + @Test + public void testEquals() { + HostRoute route1 = new DefaultHostRoute(nexthop1, destination1); + HostRoute route2 = new DefaultHostRoute(nexthop1, destination1); + HostRoute route3 = new DefaultHostRoute(nexthop2, destination2); + new EqualsTester().addEqualityGroup(route1, route2) + .addEqualityGroup(route3).testEquals(); + } + + /** + * Checks the construction of a DefaultHostRoute object. + */ + @Test + public void testConstruction() { + final HostRoute host = new DefaultHostRoute(nexthop1, destination1); + assertThat(nexthop1, is(host.nexthop())); + assertThat(destination1, is(host.destination())); + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/subnet/SubnetIdTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/subnet/SubnetIdTest.java new file mode 100644 index 00000000..d18dd41a --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/subnet/SubnetIdTest.java @@ -0,0 +1,64 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.vtnrsc.subnet; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; +import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; + +import org.junit.Test; +import org.onosproject.vtnrsc.SubnetId; + +import com.google.common.testing.EqualsTester; + +/** + * Unit tests for SubnetId class. + */ +public class SubnetIdTest { + + final SubnetId subnetId1 = SubnetId.subnetId("1"); + final SubnetId sameAsSubnetId1 = SubnetId.subnetId("1"); + final SubnetId subnetId2 = SubnetId.subnetId("2"); + + /** + * Checks that the SubnetId class is immutable. + */ + @Test + public void testImmutability() { + assertThatClassIsImmutable(SubnetId.class); + } + + /** + * Checks the operation of equals() methods. + */ + @Test + public void testEquals() { + new EqualsTester().addEqualityGroup(subnetId1, sameAsSubnetId1).addEqualityGroup(subnetId2) + .testEquals(); + } + + /** + * Checks the construction of a SubnetId object. + */ + @Test + public void testConstruction() { + final String subnetIdValue = "s"; + final SubnetId subnetId = SubnetId.subnetId(subnetIdValue); + assertThat(subnetId, is(notNullValue())); + assertThat(subnetId.subnetId(), is(subnetIdValue)); + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/DefaultNeutronNetworkTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/DefaultNeutronNetworkTest.java new file mode 100644 index 00000000..742d5933 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/DefaultNeutronNetworkTest.java @@ -0,0 +1,83 @@ +/* + * 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 static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; + +import org.junit.Test; +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 com.google.common.testing.EqualsTester; + +/** + * Unit tests for DefaultNeutronNetwork class. + */ +public class DefaultNeutronNetworkTest { + + private String networkIdStr1 = "123"; + private String networkIdStr2 = "234"; + private String physicalNetworkStr = "1234"; + private String tenantIdStr = "345"; + private String segmentationIdStr = "1"; + private String name = "456"; + + /** + * Checks that the DefaultNeutronNetwork class is immutable. + */ + @Test + public void testImmutability() { + assertThatClassIsImmutable(DefaultTenantNetwork.class); + } + + /** + * Checks the operation of equals() methods. + */ + @Test + public void testEquality() { + TenantNetworkId networkid1 = TenantNetworkId.networkId(networkIdStr1); + TenantNetworkId networkid2 = TenantNetworkId.networkId(networkIdStr2); + PhysicalNetwork physicalNetwork = PhysicalNetwork + .physicalNetwork(physicalNetworkStr); + TenantId tenantId = TenantId.tenantId(tenantIdStr); + SegmentationId segmentationID = SegmentationId + .segmentationId(segmentationIdStr); + TenantNetwork p1 = new DefaultTenantNetwork(networkid1, name, false, + TenantNetwork.State.ACTIVE, + false, tenantId, false, + TenantNetwork.Type.LOCAL, + physicalNetwork, + segmentationID); + TenantNetwork p2 = new DefaultTenantNetwork(networkid1, name, false, + TenantNetwork.State.ACTIVE, + false, tenantId, false, + TenantNetwork.Type.LOCAL, + physicalNetwork, + segmentationID); + TenantNetwork p3 = new DefaultTenantNetwork(networkid2, name, false, + TenantNetwork.State.ACTIVE, + false, tenantId, false, + TenantNetwork.Type.LOCAL, + physicalNetwork, + segmentationID); + new EqualsTester().addEqualityGroup(p1, p2).addEqualityGroup(p3) + .testEquals(); + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/PhysicalNetworkTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/PhysicalNetworkTest.java new file mode 100644 index 00000000..e101795e --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/PhysicalNetworkTest.java @@ -0,0 +1,65 @@ +/* + * 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 static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; +import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; + +import org.junit.Test; +import org.onosproject.vtnrsc.PhysicalNetwork; + +import com.google.common.testing.EqualsTester; + +/** + * Unit tests for PhysicalNetwork class. + */ +public class PhysicalNetworkTest { + + final PhysicalNetwork physicalNetwork1 = PhysicalNetwork.physicalNetwork("1"); + final PhysicalNetwork sameAsPhysicalNetwork1 = PhysicalNetwork.physicalNetwork("1"); + final PhysicalNetwork physicalNetwork2 = PhysicalNetwork.physicalNetwork("2"); + + /** + * Checks that the PhysicalNetwork class is immutable. + */ + @Test + public void testImmutability() { + assertThatClassIsImmutable(PhysicalNetwork.class); + } + + /** + * Checks the operation of equals() methods. + */ + @Test + public void testEquals() { + new EqualsTester().addEqualityGroup(physicalNetwork1, sameAsPhysicalNetwork1) + .addEqualityGroup(physicalNetwork2).testEquals(); + } + + /** + * Checks the construction of a PhysicalNetwork object. + */ + @Test + public void testConstruction() { + final String physicalNetworkValue = "s"; + final PhysicalNetwork physicalNetwork = PhysicalNetwork + .physicalNetwork(physicalNetworkValue); + assertThat(physicalNetwork, is(notNullValue())); + assertThat(physicalNetwork.physicalNetwork(), is(physicalNetworkValue)); + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/SegmentationIdTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/SegmentationIdTest.java new file mode 100644 index 00000000..dea7baf6 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/SegmentationIdTest.java @@ -0,0 +1,64 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.vtnrsc.tenantnetwork; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; +import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; + +import org.junit.Test; +import org.onosproject.vtnrsc.SegmentationId; + +import com.google.common.testing.EqualsTester; + +/** + * Unit tests for SegmentationId class. + */ +public class SegmentationIdTest { + + final SegmentationId segmentationID1 = SegmentationId.segmentationId("1"); + final SegmentationId sameAsSegmentationID1 = SegmentationId.segmentationId("1"); + final SegmentationId segmentationID2 = SegmentationId.segmentationId("2"); + + /** + * Checks that the SegmentationId class is immutable. + */ + @Test + public void testImmutability() { + assertThatClassIsImmutable(SegmentationId.class); + } + + /** + * Checks the operation of equals() methods. + */ + @Test + public void testEquals() { + new EqualsTester().addEqualityGroup(segmentationID1, sameAsSegmentationID1) + .addEqualityGroup(segmentationID2).testEquals(); + } + + /** + * Checks the construction of a segmentationId object. + */ + @Test + public void testConstruction() { + final String segmentationIdValue = "s"; + final SegmentationId segmentationId = SegmentationId.segmentationId(segmentationIdValue); + assertThat(segmentationId, is(notNullValue())); + assertThat(segmentationId.segmentationId(), is(segmentationIdValue)); + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/TenantIdTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/TenantIdTest.java new file mode 100644 index 00000000..e9216383 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/TenantIdTest.java @@ -0,0 +1,64 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.vtnrsc.tenantnetwork; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; +import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; + +import org.junit.Test; +import org.onosproject.vtnrsc.TenantId; + +import com.google.common.testing.EqualsTester; + +/** + * Unit tests for TenantId class. + */ +public class TenantIdTest { + + final TenantId tenantId1 = TenantId.tenantId("1"); + final TenantId sameAsTenantId1 = TenantId.tenantId("1"); + final TenantId tenantId2 = TenantId.tenantId("2"); + + /** + * Checks that the TenantId class is immutable. + */ + @Test + public void testImmutability() { + assertThatClassIsImmutable(TenantId.class); + } + + /** + * Checks the operation of equals() methods. + */ + @Test + public void testEquals() { + new EqualsTester().addEqualityGroup(tenantId1, sameAsTenantId1).addEqualityGroup(tenantId2) + .testEquals(); + } + + /** + * Checks the construction of a TenantId object. + */ + @Test + public void testConstruction() { + final String tenantIdValue = "s"; + final TenantId tenantId = TenantId.tenantId(tenantIdValue); + assertThat(tenantId, is(notNullValue())); + assertThat(tenantId.tenantId(), is(tenantIdValue)); + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/TenantNetworkIdTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/TenantNetworkIdTest.java new file mode 100644 index 00000000..8271b51c --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/TenantNetworkIdTest.java @@ -0,0 +1,64 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.vtnrsc.tenantnetwork; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; +import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; + +import org.junit.Test; +import org.onosproject.vtnrsc.TenantNetworkId; + +import com.google.common.testing.EqualsTester; + +/** + * Unit tests for TenantNetworkId class. + */ +public class TenantNetworkIdTest { + + final TenantNetworkId networkId1 = TenantNetworkId.networkId("1"); + final TenantNetworkId sameAsnetworkId1 = TenantNetworkId.networkId("1"); + final TenantNetworkId networkId2 = TenantNetworkId.networkId("2"); + + /** + * Checks that the TenantNetworkId class is immutable. + */ + @Test + public void testImmutability() { + assertThatClassIsImmutable(TenantNetworkId.class); + } + + /** + * Checks the operation of equals() methods. + */ + @Test + public void testEquals() { + new EqualsTester().addEqualityGroup(networkId1, sameAsnetworkId1) + .addEqualityGroup(networkId2).testEquals(); + } + + /** + * Checks the construction of a TenantNetworkId object. + */ + @Test + public void testConstruction() { + final String networkIdValue = "s"; + final TenantNetworkId networkId = TenantNetworkId.networkId(networkIdValue); + assertThat(networkId, is(notNullValue())); + assertThat(networkId.networkId(), is(networkIdValue)); + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/AllowedAddressPairTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/AllowedAddressPairTest.java new file mode 100644 index 00000000..dabe5896 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/AllowedAddressPairTest.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.virtualport; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; +import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; + +import org.junit.Test; +import org.onlab.packet.IpAddress; +import org.onlab.packet.MacAddress; +import org.onosproject.vtnrsc.AllowedAddressPair; + +import com.google.common.testing.EqualsTester; + +/** + * Unit tests for AllowedAddressPair class. + */ +public class AllowedAddressPairTest { + + final IpAddress ip1 = IpAddress.valueOf("192.168.0.1"); + final IpAddress ip2 = IpAddress.valueOf("192.168.0.2"); + final MacAddress mac1 = MacAddress.valueOf("fa:16:3e:76:83:88"); + final MacAddress mac2 = MacAddress.valueOf("aa:16:3e:76:83:88"); + + /** + * Checks that the AllowedAddressPair class is immutable. + */ + @Test + public void testImmutability() { + assertThatClassIsImmutable(AllowedAddressPair.class); + } + + /** + * Checks the operation of equals(). + */ + @Test + public void testEquals() { + AllowedAddressPair p1 = AllowedAddressPair + .allowedAddressPair(ip1, mac1); + AllowedAddressPair p2 = AllowedAddressPair + .allowedAddressPair(ip1, mac1); + AllowedAddressPair p3 = AllowedAddressPair + .allowedAddressPair(ip2, mac2); + new EqualsTester().addEqualityGroup(p1, p2).addEqualityGroup(p3) + .testEquals(); + } + + /** + * Checks the construction of a AllowedAddressPair object. + */ + @Test + public void testConstruction() { + AllowedAddressPair allowedAddressPair = AllowedAddressPair + .allowedAddressPair(ip1, mac1); + assertThat(ip1, is(notNullValue())); + assertThat(ip1, is(allowedAddressPair.ip())); + assertThat(mac1, is(notNullValue())); + assertThat(mac1, is(allowedAddressPair.mac())); + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/DefaultVirtualPortTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/DefaultVirtualPortTest.java new file mode 100644 index 00000000..8a0c8004 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/DefaultVirtualPortTest.java @@ -0,0 +1,142 @@ +/* + * 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 static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; + +import java.util.Map; +import java.util.Set; + +import org.junit.Test; +import org.onlab.packet.IpAddress; +import org.onlab.packet.MacAddress; +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.SubnetId; +import org.onosproject.vtnrsc.TenantId; +import org.onosproject.vtnrsc.TenantNetworkId; +import org.onosproject.vtnrsc.VirtualPort; +import org.onosproject.vtnrsc.VirtualPortId; + +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; +import com.google.common.testing.EqualsTester; + +/** + * Unit tests for DefaultVirtualPort class. + */ +public class DefaultVirtualPortTest { + + private Set fixedIps; + private Map propertyMap; + private Set allowedAddressPairs; + private Set securityGroups; + private VirtualPortId id1; + private VirtualPortId id2; + private String macAddressStr = "fa:12:3e:56:ee:a2"; + private String ipAddress = "10.1.1.1"; + private String deviceStr = "of:000000000000001"; + private String tenantIdStr = "123"; + private String portId1 = "1241"; + private String portId2 = "1242"; + private String tenantNetworkId = "1234567"; + private String subnet = "1212"; + private String hostIdStr = "fa:e2:3e:56:ee:a2"; + + private void initVirtualPortId() { + id1 = VirtualPortId.portId(portId1); + id2 = VirtualPortId.portId(portId2); + } + + private void initFixedIpSet() { + FixedIp fixedIp = FixedIp.fixedIp(SubnetId.subnetId(subnet), + IpAddress.valueOf(ipAddress)); + fixedIps = Sets.newHashSet(); + fixedIps.add(fixedIp); + } + + private void initPropertyMap() { + String deviceOwner = "james"; + propertyMap = Maps.newHashMap(); + propertyMap.putIfAbsent("deviceOwner", deviceOwner); + } + + private void initAddressPairSet() { + allowedAddressPairs = Sets.newHashSet(); + AllowedAddressPair allowedAddressPair = AllowedAddressPair + .allowedAddressPair(IpAddress.valueOf(ipAddress), + MacAddress.valueOf(macAddressStr)); + allowedAddressPairs.add(allowedAddressPair); + } + + private void initSecurityGroupSet() { + securityGroups = Sets.newHashSet(); + } + + /** + * Checks that the DefaultVirtualPort class is immutable. + */ + @Test + public void testImmutability() { + assertThatClassIsImmutable(SecurityGroup.class); + } + + /** + * Checks the operation of equals(). + */ + @Test + public void testEquals() { + initVirtualPortId(); + initFixedIpSet(); + initPropertyMap(); + initAddressPairSet(); + initSecurityGroupSet(); + TenantNetworkId networkId = TenantNetworkId.networkId(tenantNetworkId); + MacAddress macAddress = MacAddress.valueOf(macAddressStr); + TenantId tenantId = TenantId.tenantId(tenantIdStr); + DeviceId deviceId = DeviceId.deviceId(deviceStr); + BindingHostId bindingHostId = BindingHostId.bindingHostId(hostIdStr); + + VirtualPort d1 = new DefaultVirtualPort(id1, networkId, true, + propertyMap, + VirtualPort.State.ACTIVE, + macAddress, tenantId, deviceId, + fixedIps, bindingHostId, + allowedAddressPairs, + securityGroups); + VirtualPort d2 = new DefaultVirtualPort(id1, networkId, true, + propertyMap, + VirtualPort.State.ACTIVE, + macAddress, tenantId, deviceId, + fixedIps, bindingHostId, + allowedAddressPairs, + securityGroups); + VirtualPort d3 = new DefaultVirtualPort(id2, networkId, true, + propertyMap, + VirtualPort.State.ACTIVE, + macAddress, tenantId, deviceId, + fixedIps, bindingHostId, + allowedAddressPairs, + securityGroups); + new EqualsTester().addEqualityGroup(d1, d2).addEqualityGroup(d3) + .testEquals(); + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/FixedIpTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/FixedIpTest.java new file mode 100644 index 00000000..1e33da09 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/FixedIpTest.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.virtualport; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; +import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; + +import org.junit.Test; +import org.onlab.packet.IpAddress; +import org.onosproject.vtnrsc.FixedIp; +import org.onosproject.vtnrsc.SubnetId; + +import com.google.common.testing.EqualsTester; + +/** + * Unit tests for FixedIp class. + */ +public class FixedIpTest { + + final SubnetId subnetId1 = SubnetId.subnetId("lef11-95w-4er-9c9c"); + final SubnetId subnetId2 = SubnetId.subnetId("lefaa-95w-4er-9c9c"); + final IpAddress ip1 = IpAddress.valueOf("192.168.0.1"); + final IpAddress ip2 = IpAddress.valueOf("192.168.1.1"); + + /** + * Checks that the FixedIp class is immutable. + */ + @Test + public void testImmutability() { + assertThatClassIsImmutable(FixedIp.class); + } + + /** + * Checks the operation of equals(). + */ + @Test + public void testEquals() { + FixedIp fixedIp1 = FixedIp.fixedIp(subnetId1, ip1); + FixedIp fixedIp2 = FixedIp.fixedIp(subnetId1, ip1); + FixedIp fixedIp3 = FixedIp.fixedIp(subnetId2, ip2); + new EqualsTester().addEqualityGroup(fixedIp1, fixedIp2) + .addEqualityGroup(fixedIp3).testEquals(); + } + + /** + * Checks the construction of a FixedIp object. + */ + @Test + public void testConstruction() { + FixedIp fixedIp = FixedIp.fixedIp(subnetId1, ip1); + assertThat(ip1, is(notNullValue())); + assertThat(ip1, is(fixedIp.ip())); + assertThat(subnetId1, is(notNullValue())); + assertThat(subnetId1, is(fixedIp.subnetId())); + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/SecurityGroupTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/SecurityGroupTest.java new file mode 100644 index 00000000..8c04e499 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/SecurityGroupTest.java @@ -0,0 +1,66 @@ +/* + * 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 static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; +import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; + +import org.junit.Test; +import org.onosproject.vtnrsc.SecurityGroup; + +import com.google.common.testing.EqualsTester; + +/** + * Unit tests for SecurityGroup class. + */ +public class SecurityGroupTest { + + final SecurityGroup securityGroup1 = SecurityGroup.securityGroup("1"); + final SecurityGroup sameAssecurityGroup = SecurityGroup.securityGroup("1"); + final SecurityGroup securityGroup2 = SecurityGroup.securityGroup("2"); + + /** + * Checks that the SecurityGroup class is immutable. + */ + @Test + public void testImmutability() { + assertThatClassIsImmutable(SecurityGroup.class); + } + + /** + * Checks the operation of equals(). + */ + @Test + public void testEquals() { + new EqualsTester().addEqualityGroup(securityGroup1, sameAssecurityGroup) + .addEqualityGroup(securityGroup2).testEquals(); + } + + /** + * Checks the construction of a SecurityGroup object. + */ + @Test + public void testConstruction() { + final String securityGroupValue = "1"; + final SecurityGroup securityGroup = SecurityGroup.securityGroup(securityGroupValue); + assertThat(securityGroup, is(notNullValue())); + assertThat(securityGroup.securityGroup(), is(securityGroupValue)); + + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/VirtualPortIdTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/VirtualPortIdTest.java new file mode 100644 index 00000000..2d63e91c --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/VirtualPortIdTest.java @@ -0,0 +1,66 @@ +/* + * 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 static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; +import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; + +import org.junit.Test; +import org.onosproject.vtnrsc.VirtualPortId; + +import com.google.common.testing.EqualsTester; + +/** + * Unit tests for VirtualPortId class. + */ +public class VirtualPortIdTest { + + final VirtualPortId virtualPortId1 = VirtualPortId.portId("1"); + final VirtualPortId sameAsVirtualPortId1 = VirtualPortId.portId("1"); + final VirtualPortId virtualPortId2 = VirtualPortId.portId("2"); + + /** + * Checks that the VirtualPortId class is immutable. + */ + @Test + public void testImmutability() { + assertThatClassIsImmutable(VirtualPortId.class); + } + + /** + * Checks the operation of equals(). + */ + @Test + public void testEquals() { + new EqualsTester().addEqualityGroup(virtualPortId1, sameAsVirtualPortId1) + .addEqualityGroup(virtualPortId2).testEquals(); + } + + /** + * Checks the construction of a VirtualPortId object. + */ + @Test + public void testConstruction() { + final String vPortIdValue = "aaa"; + final VirtualPortId virtualPortId = VirtualPortId.portId(vPortIdValue); + assertThat(virtualPortId, is(notNullValue())); + assertThat(virtualPortId.portId(), is(vPortIdValue)); + + } +} -- cgit 1.2.3-korg