From b34f82bf11934fc6b938ef997d536a7ccea76c36 Mon Sep 17 00:00:00 2001 From: Ashlee Young Date: Thu, 5 Nov 2015 14:00:42 -0800 Subject: Updates ONOS tree to checkin id ca9cc8e28eba18da77f4fa021fb7c3a3f76e5d44 upstream. Change-Id: I49f8e41733afea8101ec50c0102213c8d18949ae Signed-off-by: Ashlee Young --- .../java/org/onosproject/vtnrsc/BindingHostId.java | 2 +- .../org/onosproject/vtnrsc/FlowClassifierId.java | 7 +- .../org/onosproject/vtnrsc/PhysicalNetwork.java | 2 +- .../java/org/onosproject/vtnrsc/PortChainId.java | 22 ++-- .../org/onosproject/vtnrsc/PortPairGroupId.java | 23 ++-- .../java/org/onosproject/vtnrsc/PortPairId.java | 20 ++- .../java/org/onosproject/vtnrsc/SecurityGroup.java | 2 +- .../org/onosproject/vtnrsc/SegmentationId.java | 2 +- .../main/java/org/onosproject/vtnrsc/SubnetId.java | 2 +- .../main/java/org/onosproject/vtnrsc/TenantId.java | 2 +- .../org/onosproject/vtnrsc/TenantNetworkId.java | 2 +- .../java/org/onosproject/vtnrsc/VirtualPortId.java | 2 +- .../flowClassifier/impl/FlowClassifierManager.java | 32 +++-- .../vtnrsc/portchain/impl/PortChainManager.java | 146 +++++++++++++++++++++ .../vtnrsc/portchain/impl/package-info.java | 20 +++ .../vtnrsc/portpair/PortPairService.java | 80 +++++++++++ .../vtnrsc/portpair/impl/PortPairManager.java | 146 +++++++++++++++++++++ .../vtnrsc/portpair/impl/package-info.java | 20 +++ .../onosproject/vtnrsc/portpair/package-info.java | 20 +++ .../portpairgroup/impl/PortPairGroupManager.java | 146 +++++++++++++++++++++ .../vtnrsc/portpairgroup/impl/package-info.java | 20 +++ .../vtnrsc/web/FlowClassifierCodec.java | 134 ------------------- .../org/onosproject/vtnrsc/web/package-info.java | 20 --- .../flowclassifier/FlowClassifierIdTest.java | 8 +- .../vtnrsc/portchain/PortChainIdTest.java | 65 +++++++++ .../vtnrsc/portpair/PortPairIdTest.java | 64 +++++++++ .../vtnrsc/portpairgroup/PortPairGroupIdTest.java | 66 ++++++++++ 27 files changed, 862 insertions(+), 213 deletions(-) create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portchain/impl/PortChainManager.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portchain/impl/package-info.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpair/PortPairService.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpair/impl/PortPairManager.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpair/impl/package-info.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpair/package-info.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpairgroup/impl/PortPairGroupManager.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpairgroup/impl/package-info.java delete 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/package-info.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portchain/PortChainIdTest.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portpair/PortPairIdTest.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portpairgroup/PortPairGroupIdTest.java (limited to 'framework/src/onos/apps/vtn/vtnrsc') diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/BindingHostId.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/BindingHostId.java index c715d08a..7dca32de 100644 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/BindingHostId.java +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/BindingHostId.java @@ -49,7 +49,7 @@ public final class BindingHostId { @Override public int hashCode() { - return Objects.hash(bindingHostId); + return bindingHostId.hashCode(); } @Override 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 index b789abe3..df180ebe 100644 --- 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 @@ -15,6 +15,8 @@ */ package org.onosproject.vtnrsc; +import static com.google.common.base.Preconditions.checkNotNull; + import com.google.common.base.MoreObjects; import java.util.UUID; @@ -33,6 +35,7 @@ public final class FlowClassifierId { * @param flowClassifierId flow classifier id. */ private FlowClassifierId(final UUID flowClassifierId) { + checkNotNull(flowClassifierId, "Flow classifier id can not be null"); this.flowClassifierId = flowClassifierId; } @@ -42,7 +45,7 @@ public final class FlowClassifierId { * @param flowClassifierId flow classifier id * @return new flow classifier id */ - public static FlowClassifierId flowClassifierId(final UUID flowClassifierId) { + public static FlowClassifierId of(final UUID flowClassifierId) { return new FlowClassifierId(flowClassifierId); } @@ -52,7 +55,7 @@ public final class FlowClassifierId { * @param flowClassifierId flow classifier id * @return new flow classifier id */ - public static FlowClassifierId flowClassifierId(final String flowClassifierId) { + public static FlowClassifierId of(final String flowClassifierId) { return new FlowClassifierId(UUID.fromString(flowClassifierId)); } diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PhysicalNetwork.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PhysicalNetwork.java index e96e666a..30631d28 100644 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PhysicalNetwork.java +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PhysicalNetwork.java @@ -53,7 +53,7 @@ public final class PhysicalNetwork { @Override public int hashCode() { - return Objects.hash(physicalNetwork); + return physicalNetwork.hashCode(); } @Override 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 index 66edbdcc..a42a700f 100644 --- 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 @@ -19,8 +19,7 @@ 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; +import java.util.Objects; /** * Representation of a Port Chain ID. @@ -40,22 +39,22 @@ public final class PortChainId { } /** - * Constructor to create port chain id from UUID. + * Returns newly created port chain id object. * * @param id UUID of port chain * @return object of port chain id */ - public static PortChainId portChainId(UUID id) { + public static PortChainId of(UUID id) { return new PortChainId(id); } /** - * Constructor to create port chain id from string. + * Returns newly created port chain id object. * * @param id port chain id in string * @return object of port chain id */ - public static PortChainId portChainId(String id) { + public static PortChainId of(String id) { return new PortChainId(UUID.fromString(id)); } @@ -73,10 +72,9 @@ public final class PortChainId { if (this == obj) { return true; } - - if (obj.getClass() == this.getClass()) { - PortChainId that = (PortChainId) obj; - return Objects.equal(this.portChainId, that.portChainId); + if (obj instanceof PortChainId) { + final PortChainId other = (PortChainId) obj; + return Objects.equals(this.portChainId, other.portChainId); } return false; } @@ -88,8 +86,6 @@ public final class PortChainId { @Override public String toString() { - return toStringHelper(this) - .add("portChainId", portChainId.toString()) - .toString(); + return toStringHelper(this).add("portChainId", portChainId).toString(); } } 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 index 0474901c..a52a2bb3 100644 --- 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 @@ -19,8 +19,7 @@ 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; +import java.util.Objects; /** * Representation of a Port Pair Group ID. @@ -40,22 +39,22 @@ public final class PortPairGroupId { } /** - * Constructor to create port pair group id from UUID. + * Returns newly created port pair group id object. * - * @param id UUID of port pair group id + * @param id port pair group id in UUID * @return object of port pair group id */ - public static PortPairGroupId portPairGroupId(UUID id) { + public static PortPairGroupId of(UUID id) { return new PortPairGroupId(id); } /** - * Constructor to create port pair group id from string. + * Returns newly created port pair group id object. * * @param id port pair group id in string * @return object of port pair group id */ - public static PortPairGroupId portPairGroupId(String id) { + public static PortPairGroupId of(String id) { return new PortPairGroupId(UUID.fromString(id)); } @@ -73,10 +72,9 @@ public final class PortPairGroupId { if (this == obj) { return true; } - - if (obj.getClass() == this.getClass()) { - PortPairGroupId that = (PortPairGroupId) obj; - return Objects.equal(this.portPairGroupId, that.portPairGroupId); + if (obj instanceof PortPairGroupId) { + final PortPairGroupId other = (PortPairGroupId) obj; + return Objects.equals(this.portPairGroupId, other.portPairGroupId); } return false; } @@ -88,8 +86,7 @@ public final class PortPairGroupId { @Override public String toString() { - return toStringHelper(this) - .add("portPairGroupId", portPairGroupId.toString()) + return toStringHelper(this).add("portPairGroupId", portPairGroupId) .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 index 05c31aac..1f45e80e 100644 --- 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 @@ -19,8 +19,7 @@ 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; +import java.util.Objects; /** * Representation of a Port Pair ID. @@ -40,22 +39,22 @@ public final class PortPairId { } /** - * Constructor to create port pair id from UUID. + * Returns newly created port pair id object. * * @param id UUID of port pair id * @return object of port pair id */ - public static PortPairId portPairId(UUID id) { + public static PortPairId of(UUID id) { return new PortPairId(id); } /** - * Constructor to create port pair id from string. + * Returns newly created port pair id object. * * @param id port pair id in string * @return object of port pair id */ - public static PortPairId portPairId(String id) { + public static PortPairId of(String id) { return new PortPairId(UUID.fromString(id)); } @@ -73,10 +72,9 @@ public final class PortPairId { if (this == obj) { return true; } - - if (obj.getClass() == this.getClass()) { - PortPairId that = (PortPairId) obj; - return Objects.equal(this.portPairId, that.portPairId); + if (obj instanceof PortPairId) { + final PortPairId other = (PortPairId) obj; + return Objects.equals(this.portPairId, other.portPairId); } return false; } @@ -89,7 +87,7 @@ public final class PortPairId { @Override public String toString() { return toStringHelper(this) - .add("portPairId", portPairId.toString()) + .add("portPairId", portPairId) .toString(); } } diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/SecurityGroup.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/SecurityGroup.java index 9ec1dc63..33ddcbfe 100644 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/SecurityGroup.java +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/SecurityGroup.java @@ -52,7 +52,7 @@ public final class SecurityGroup { @Override public int hashCode() { - return Objects.hash(securityGroup); + return securityGroup.hashCode(); } @Override diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/SegmentationId.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/SegmentationId.java index a076265f..651ebd89 100644 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/SegmentationId.java +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/SegmentationId.java @@ -53,7 +53,7 @@ public final class SegmentationId { @Override public int hashCode() { - return Objects.hash(segmentationId); + return segmentationId.hashCode(); } @Override diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/SubnetId.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/SubnetId.java index 4bcc3329..eb93d153 100644 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/SubnetId.java +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/SubnetId.java @@ -53,7 +53,7 @@ public final class SubnetId { @Override public int hashCode() { - return Objects.hash(subnetId); + return subnetId.hashCode(); } @Override diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/TenantId.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/TenantId.java index c4d99e49..0e7c9417 100644 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/TenantId.java +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/TenantId.java @@ -53,7 +53,7 @@ public final class TenantId { @Override public int hashCode() { - return Objects.hash(tenantId); + return tenantId.hashCode(); } @Override diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/TenantNetworkId.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/TenantNetworkId.java index fbb9e480..8680d28f 100644 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/TenantNetworkId.java +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/TenantNetworkId.java @@ -52,7 +52,7 @@ public final class TenantNetworkId { @Override public int hashCode() { - return Objects.hash(networkId); + return networkId.hashCode(); } @Override diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/VirtualPortId.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/VirtualPortId.java index 3038bdff..a3863483 100644 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/VirtualPortId.java +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/VirtualPortId.java @@ -46,7 +46,7 @@ public final class VirtualPortId { @Override public int hashCode() { - return Objects.hash(portId); + return portId.hashCode(); } @Override 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 index 7238558a..ca01c434 100644 --- 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 @@ -15,21 +15,26 @@ */ 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.Reference; +import org.apache.felix.scr.annotations.ReferenceCardinality; import org.apache.felix.scr.annotations.Service; +import org.onlab.util.KryoNamespace; +import org.onosproject.store.serializers.KryoNamespaces; +import org.onosproject.store.service.EventuallyConsistentMap; +import org.onosproject.store.service.MultiValuedTimestamp; +import org.onosproject.store.service.StorageService; +import org.onosproject.store.service.WallClockTimestamp; 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 org.slf4j.LoggerFactory.getLogger; import static com.google.common.base.Preconditions.checkNotNull; + import com.google.common.collect.ImmutableList; /** @@ -44,16 +49,26 @@ public class FlowClassifierManager implements FlowClassifierService { 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(); + private EventuallyConsistentMap flowClassifierStore; + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) + protected StorageService storageService; @Activate private void activate() { + KryoNamespace.Builder serializer = KryoNamespace.newBuilder() + .register(KryoNamespaces.API) + .register(MultiValuedTimestamp.class) + .register(FlowClassifier.class); + flowClassifierStore = storageService + .eventuallyConsistentMapBuilder() + .withName("flowclassifierstore").withSerializer(serializer) + .withTimestampProvider((k, v) -> new WallClockTimestamp()).build(); log.info("Flow Classifier service activated"); } @Deactivate private void deactivate() { + flowClassifierStore.destroy(); log.info("Flow Classifier service deactivated"); } @@ -92,7 +107,8 @@ public class FlowClassifierManager implements FlowClassifierService { public boolean updateFlowClassifier(FlowClassifier flowClassifier) { checkNotNull(flowClassifier, FLOW_CLASSIFIER_NOT_NULL); FlowClassifierId id = flowClassifier.flowClassifierId(); - return flowClassifierStore.replace(id, flowClassifierStore.get(id), flowClassifier); + flowClassifierStore.put(id, flowClassifier); + return true; } @Override diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portchain/impl/PortChainManager.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portchain/impl/PortChainManager.java new file mode 100644 index 00000000..5201a2ca --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portchain/impl/PortChainManager.java @@ -0,0 +1,146 @@ +/* + * 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.impl; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.slf4j.LoggerFactory.getLogger; + +import java.util.Collections; + +import org.apache.felix.scr.annotations.Activate; +import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.Deactivate; +import org.apache.felix.scr.annotations.Reference; +import org.apache.felix.scr.annotations.ReferenceCardinality; +import org.apache.felix.scr.annotations.Service; +import org.onlab.util.KryoNamespace; +import org.onosproject.store.serializers.KryoNamespaces; +import org.onosproject.store.service.EventuallyConsistentMap; +import org.onosproject.store.service.MultiValuedTimestamp; +import org.onosproject.store.service.StorageService; +import org.onosproject.store.service.WallClockTimestamp; +import org.onosproject.vtnrsc.PortChain; +import org.onosproject.vtnrsc.PortChainId; +import org.onosproject.vtnrsc.portchain.PortChainService; +import org.slf4j.Logger; + +/** + * Provides implementation of the portChainService. + */ +@Component(immediate = true) +@Service +public class PortChainManager implements PortChainService { + + private final Logger log = getLogger(getClass()); + + private static final String PORT_CHAIN_ID_NULL = "PortChain ID cannot be null"; + private static final String PORT_CHAIN_NULL = "PortChain cannot be null"; + + private EventuallyConsistentMap portChainStore; + + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) + protected StorageService storageService; + + @Activate + public void activate() { + + KryoNamespace.Builder serializer = KryoNamespace.newBuilder() + .register(KryoNamespaces.API) + .register(MultiValuedTimestamp.class) + .register(PortChain.class); + + portChainStore = storageService + .eventuallyConsistentMapBuilder() + .withName("portchainstore").withSerializer(serializer) + .withTimestampProvider((k, v) -> new WallClockTimestamp()).build(); + + log.info("Started"); + } + + @Deactivate + public void deactivate() { + portChainStore.destroy(); + log.info("Stopped"); + } + + @Override + public boolean exists(PortChainId portChainId) { + checkNotNull(portChainId, PORT_CHAIN_ID_NULL); + return portChainStore.containsKey(portChainId); + } + + @Override + public int getPortChainCount() { + return portChainStore.size(); + } + + @Override + public Iterable getPortChains() { + return Collections.unmodifiableCollection(portChainStore.values()); + } + + @Override + public PortChain getPortChain(PortChainId portChainId) { + checkNotNull(portChainId, PORT_CHAIN_ID_NULL); + return portChainStore.get(portChainId); + } + + @Override + public boolean createPortChain(PortChain portChain) { + checkNotNull(portChain, PORT_CHAIN_NULL); + + portChainStore.put(portChain.portChainId(), portChain); + if (!portChainStore.containsKey(portChain.portChainId())) { + log.debug("The portChain is created failed which identifier was {}", portChain.portChainId() + .toString()); + return false; + } + return true; + } + + @Override + public boolean updatePortChain(PortChain portChain) { + checkNotNull(portChain, PORT_CHAIN_NULL); + + if (!portChainStore.containsKey(portChain.portChainId())) { + log.debug("The portChain is not exist whose identifier was {} ", + portChain.portChainId().toString()); + return false; + } + + portChainStore.put(portChain.portChainId(), portChain); + + if (!portChain.equals(portChainStore.get(portChain.portChainId()))) { + log.debug("The portChain is updated failed whose identifier was {} ", + portChain.portChainId().toString()); + return false; + } + return true; + } + + @Override + public boolean removePortChain(PortChainId portChainId) { + checkNotNull(portChainId, PORT_CHAIN_NULL); + + portChainStore.remove(portChainId); + if (portChainStore.containsKey(portChainId)) { + log.debug("The portChain is removed failed whose identifier was {}", + portChainId.toString()); + return false; + } + return true; + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portchain/impl/package-info.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portchain/impl/package-info.java new file mode 100644 index 00000000..424d54ab --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portchain/impl/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Implementation of service for interacting with the inventory of port chains. + */ +package org.onosproject.vtnrsc.portchain.impl; diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpair/PortPairService.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpair/PortPairService.java new file mode 100644 index 00000000..f99cc2cf --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpair/PortPairService.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.portpair; + +import org.onosproject.vtnrsc.PortPair; +import org.onosproject.vtnrsc.PortPairId; + +/** + * Service for interacting with the inventory of port pairs. + */ +public interface PortPairService { + + /** + * Returns if the port pair is existed. + * + * @param portPairId port pair identifier + * @return true or false if one with the given identifier exists. + */ + boolean exists(PortPairId portPairId); + + /** + * Returns the number of port pairs known to the system. + * + * @return number of port pairs. + */ + int getPortPairCount(); + + /** + * Returns an iterable collection of the currently known port pairs. + * + * @return collection of port pairs. + */ + Iterable getPortPairs(); + + /** + * Returns the portPair with the given identifier. + * + * @param portPairId port pair identifier + * @return PortPair or null if port pair with the given identifier is not + * known. + */ + PortPair getPortPair(PortPairId portPairId); + + /** + * Creates a PortPair in the store. + * + * @param portPair the port pair to create + * @return true if given port pair is created successfully. + */ + boolean createPortPair(PortPair portPair); + + /** + * Updates the portPair in the store. + * + * @param portPair the port pair to update + * @return true if given port pair is updated successfully. + */ + boolean updatePortPair(PortPair portPair); + + /** + * Deletes portPair by given portPairId. + * + * @param portPairId id of port pair to remove + * @return true if the give port pair is deleted successfully. + */ + boolean removePortPair(PortPairId portPairId); +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpair/impl/PortPairManager.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpair/impl/PortPairManager.java new file mode 100644 index 00000000..93c8782a --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpair/impl/PortPairManager.java @@ -0,0 +1,146 @@ +/* + * 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.portpair.impl; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.slf4j.LoggerFactory.getLogger; + +import java.util.Collections; + +import org.apache.felix.scr.annotations.Activate; +import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.Deactivate; +import org.apache.felix.scr.annotations.Reference; +import org.apache.felix.scr.annotations.ReferenceCardinality; +import org.apache.felix.scr.annotations.Service; +import org.onlab.util.KryoNamespace; +import org.onosproject.store.serializers.KryoNamespaces; +import org.onosproject.store.service.EventuallyConsistentMap; +import org.onosproject.store.service.MultiValuedTimestamp; +import org.onosproject.store.service.StorageService; +import org.onosproject.store.service.WallClockTimestamp; +import org.onosproject.vtnrsc.PortPair; +import org.onosproject.vtnrsc.PortPairId; +import org.onosproject.vtnrsc.portpair.PortPairService; +import org.slf4j.Logger; + +/** + * Provides implementation of the portPairService. + */ +@Component(immediate = true) +@Service +public class PortPairManager implements PortPairService { + + private final Logger log = getLogger(getClass()); + + private static final String PORT_PAIR_ID_NULL = "PortPair ID cannot be null"; + private static final String PORT_PAIR_NULL = "PortPair cannot be null"; + + private EventuallyConsistentMap portPairStore; + + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) + protected StorageService storageService; + + @Activate + public void activate() { + + KryoNamespace.Builder serializer = KryoNamespace.newBuilder() + .register(KryoNamespaces.API) + .register(MultiValuedTimestamp.class) + .register(PortPair.class); + + portPairStore = storageService + .eventuallyConsistentMapBuilder() + .withName("portpairstore").withSerializer(serializer) + .withTimestampProvider((k, v) -> new WallClockTimestamp()).build(); + + log.info("Started"); + } + + @Deactivate + public void deactivate() { + portPairStore.destroy(); + log.info("Stopped"); + } + + @Override + public boolean exists(PortPairId portPairId) { + checkNotNull(portPairId, PORT_PAIR_ID_NULL); + return portPairStore.containsKey(portPairId); + } + + @Override + public int getPortPairCount() { + return portPairStore.size(); + } + + @Override + public Iterable getPortPairs() { + return Collections.unmodifiableCollection(portPairStore.values()); + } + + @Override + public PortPair getPortPair(PortPairId portPairId) { + checkNotNull(portPairId, PORT_PAIR_ID_NULL); + return portPairStore.get(portPairId); + } + + @Override + public boolean createPortPair(PortPair portPair) { + checkNotNull(portPair, PORT_PAIR_NULL); + + portPairStore.put(portPair.portPairId(), portPair); + if (!portPairStore.containsKey(portPair.portPairId())) { + log.debug("The portPair is created failed which identifier was {}", portPair.portPairId() + .toString()); + return false; + } + return true; + } + + @Override + public boolean updatePortPair(PortPair portPair) { + checkNotNull(portPair, PORT_PAIR_NULL); + + if (!portPairStore.containsKey(portPair.portPairId())) { + log.debug("The portPair is not exist whose identifier was {} ", + portPair.portPairId().toString()); + return false; + } + + portPairStore.put(portPair.portPairId(), portPair); + + if (!portPair.equals(portPairStore.get(portPair.portPairId()))) { + log.debug("The portPair is updated failed whose identifier was {} ", + portPair.portPairId().toString()); + return false; + } + return true; + } + + @Override + public boolean removePortPair(PortPairId portPairId) { + checkNotNull(portPairId, PORT_PAIR_NULL); + + portPairStore.remove(portPairId); + if (portPairStore.containsKey(portPairId)) { + log.debug("The portPair is removed failed whose identifier was {}", + portPairId.toString()); + return false; + } + return true; + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpair/impl/package-info.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpair/impl/package-info.java new file mode 100644 index 00000000..625fbdd4 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpair/impl/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Implementation of service for interacting with the inventory of port pairs. + */ +package org.onosproject.vtnrsc.portpair.impl; diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpair/package-info.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpair/package-info.java new file mode 100644 index 00000000..e2c61531 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpair/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 pairs. + */ +package org.onosproject.vtnrsc.portpair; diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpairgroup/impl/PortPairGroupManager.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpairgroup/impl/PortPairGroupManager.java new file mode 100644 index 00000000..55fb4e43 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpairgroup/impl/PortPairGroupManager.java @@ -0,0 +1,146 @@ +/* + * 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.impl; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.slf4j.LoggerFactory.getLogger; + +import java.util.Collections; + +import org.apache.felix.scr.annotations.Activate; +import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.Deactivate; +import org.apache.felix.scr.annotations.Reference; +import org.apache.felix.scr.annotations.ReferenceCardinality; +import org.apache.felix.scr.annotations.Service; +import org.onlab.util.KryoNamespace; +import org.onosproject.store.serializers.KryoNamespaces; +import org.onosproject.store.service.EventuallyConsistentMap; +import org.onosproject.store.service.MultiValuedTimestamp; +import org.onosproject.store.service.StorageService; +import org.onosproject.store.service.WallClockTimestamp; +import org.onosproject.vtnrsc.PortPairGroup; +import org.onosproject.vtnrsc.PortPairGroupId; +import org.onosproject.vtnrsc.portpairgroup.PortPairGroupService; +import org.slf4j.Logger; + +/** + * Provides implementation of the portPairGroupService. + */ +@Component(immediate = true) +@Service +public class PortPairGroupManager implements PortPairGroupService { + + private final Logger log = getLogger(getClass()); + + private static final String PORT_PAIR_GROUP_ID_NULL = "PortPairGroup ID cannot be null"; + private static final String PORT_PAIR_GROUP_NULL = "PortPairGroup cannot be null"; + + private EventuallyConsistentMap portPairGroupStore; + + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) + protected StorageService storageService; + + @Activate + public void activate() { + + KryoNamespace.Builder serializer = KryoNamespace.newBuilder() + .register(KryoNamespaces.API) + .register(MultiValuedTimestamp.class) + .register(PortPairGroup.class); + + portPairGroupStore = storageService + .eventuallyConsistentMapBuilder() + .withName("portpairgroupstore").withSerializer(serializer) + .withTimestampProvider((k, v) -> new WallClockTimestamp()).build(); + + log.info("Started"); + } + + @Deactivate + public void deactivate() { + portPairGroupStore.destroy(); + log.info("Stopped"); + } + + @Override + public boolean exists(PortPairGroupId portPairGroupId) { + checkNotNull(portPairGroupId, PORT_PAIR_GROUP_ID_NULL); + return portPairGroupStore.containsKey(portPairGroupId); + } + + @Override + public int getPortPairGroupCount() { + return portPairGroupStore.size(); + } + + @Override + public Iterable getPortPairGroups() { + return Collections.unmodifiableCollection(portPairGroupStore.values()); + } + + @Override + public PortPairGroup getPortPairGroup(PortPairGroupId portPairGroupId) { + checkNotNull(portPairGroupId, PORT_PAIR_GROUP_ID_NULL); + return portPairGroupStore.get(portPairGroupId); + } + + @Override + public boolean createPortPairGroup(PortPairGroup portPairGroup) { + checkNotNull(portPairGroup, PORT_PAIR_GROUP_NULL); + + portPairGroupStore.put(portPairGroup.portPairGroupId(), portPairGroup); + if (!portPairGroupStore.containsKey(portPairGroup.portPairGroupId())) { + log.debug("The portPairGroup is created failed which identifier was {}", portPairGroup.portPairGroupId() + .toString()); + return false; + } + return true; + } + + @Override + public boolean updatePortPairGroup(PortPairGroup portPairGroup) { + checkNotNull(portPairGroup, PORT_PAIR_GROUP_NULL); + + if (!portPairGroupStore.containsKey(portPairGroup.portPairGroupId())) { + log.debug("The portPairGroup is not exist whose identifier was {} ", + portPairGroup.portPairGroupId().toString()); + return false; + } + + portPairGroupStore.put(portPairGroup.portPairGroupId(), portPairGroup); + + if (!portPairGroup.equals(portPairGroupStore.get(portPairGroup.portPairGroupId()))) { + log.debug("The portPairGroup is updated failed whose identifier was {} ", + portPairGroup.portPairGroupId().toString()); + return false; + } + return true; + } + + @Override + public boolean removePortPairGroup(PortPairGroupId portPairGroupId) { + checkNotNull(portPairGroupId, PORT_PAIR_GROUP_NULL); + + portPairGroupStore.remove(portPairGroupId); + if (portPairGroupStore.containsKey(portPairGroupId)) { + log.debug("The portPairGroup is removed failed whose identifier was {}", + portPairGroupId.toString()); + return false; + } + return true; + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpairgroup/impl/package-info.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpairgroup/impl/package-info.java new file mode 100644 index 00000000..68c186bc --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpairgroup/impl/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Implementation of service for interacting with the inventory of port pair groups. + */ +package org.onosproject.vtnrsc.portpairgroup.impl; 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 deleted file mode 100644 index fd5b1ee4..00000000 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/FlowClassifierCodec.java +++ /dev/null @@ -1,134 +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 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/package-info.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/package-info.java deleted file mode 100644 index 34636a9f..00000000 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/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. - */ - -/** - * Codecs for virtual tenant objects. - */ -package org.onosproject.vtnrsc.web; 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 index b2fed347..4f521836 100644 --- 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 @@ -32,11 +32,11 @@ import java.util.UUID; public class FlowClassifierIdTest { final FlowClassifierId flowClassifierId1 = FlowClassifierId - .flowClassifierId("78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae"); + .of("78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae"); final FlowClassifierId sameAsFlowClassifierId1 = FlowClassifierId - .flowClassifierId("78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae"); + .of("78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae"); final FlowClassifierId flowClassifierId2 = FlowClassifierId - .flowClassifierId("dace4513-24fc-4fae-af4b-321c5e2eb3d1"); + .of("dace4513-24fc-4fae-af4b-321c5e2eb3d1"); /** * Checks that the FlowClassifierId class is immutable. @@ -61,7 +61,7 @@ public class FlowClassifierIdTest { @Test public void testConstruction() { final String flowClassifierIdValue = "dace4513-24fc-4fae-af4b-321c5e2eb3d1"; - final FlowClassifierId flowClassifierId = FlowClassifierId.flowClassifierId(flowClassifierIdValue); + final FlowClassifierId flowClassifierId = FlowClassifierId.of(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/portchain/PortChainIdTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portchain/PortChainIdTest.java new file mode 100644 index 00000000..88fecf8d --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portchain/PortChainIdTest.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.portpair; + +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.PortChainId; + +import com.google.common.testing.EqualsTester; +import java.util.UUID; + +/** + * Unit tests for PortChainId class. + */ +public class PortChainIdTest { + + final PortChainId portChainId1 = PortChainId.of("78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae"); + final PortChainId sameAsPortChainId1 = PortChainId.of("78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae"); + final PortChainId portChainId2 = PortChainId.of("dace4513-24fc-4fae-af4b-321c5e2eb3d1"); + + /** + * Checks that the PortChainId class is immutable. + */ + @Test + public void testImmutability() { + assertThatClassIsImmutable(PortChainId.class); + } + + /** + * Checks the operation of equals() methods. + */ + @Test + public void testEquals() { + new EqualsTester().addEqualityGroup(portChainId1, sameAsPortChainId1).addEqualityGroup(portChainId2) + .testEquals(); + } + + /** + * Checks the construction of a PortChainId object. + */ + @Test + public void testConstruction() { + final String portChainIdValue = "dace4513-24fc-4fae-af4b-321c5e2eb3d1"; + final PortChainId portChainId = PortChainId.of(portChainIdValue); + assertThat(portChainId, is(notNullValue())); + assertThat(portChainId.value(), is(UUID.fromString(portChainIdValue))); + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portpair/PortPairIdTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portpair/PortPairIdTest.java new file mode 100644 index 00000000..f176089e --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portpair/PortPairIdTest.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.portpair; + +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.PortPairId; + +import com.google.common.testing.EqualsTester; +import java.util.UUID; + +/** + * Unit tests for PortPairId class. + */ +public class PortPairIdTest { + + final PortPairId portPairId1 = PortPairId.of("78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae"); + final PortPairId sameAsPortPairId1 = PortPairId.of("78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae"); + final PortPairId portPairId2 = PortPairId.of("dace4513-24fc-4fae-af4b-321c5e2eb3d1"); + + /** + * Checks that the PortPairId class is immutable. + */ + @Test + public void testImmutability() { + assertThatClassIsImmutable(PortPairId.class); + } + + /** + * Checks the operation of equals() methods. + */ + @Test + public void testEquals() { + new EqualsTester().addEqualityGroup(portPairId1, sameAsPortPairId1).addEqualityGroup(portPairId2).testEquals(); + } + + /** + * Checks the construction of a PortPairId object. + */ + @Test + public void testConstruction() { + final String portPairIdValue = "dace4513-24fc-4fae-af4b-321c5e2eb3d1"; + final PortPairId portPairId = PortPairId.of(portPairIdValue); + assertThat(portPairId, is(notNullValue())); + assertThat(portPairId.value(), is(UUID.fromString(portPairIdValue))); + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portpairgroup/PortPairGroupIdTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portpairgroup/PortPairGroupIdTest.java new file mode 100644 index 00000000..7da4c489 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portpairgroup/PortPairGroupIdTest.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.portpair; + +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.PortPairGroupId; + +import com.google.common.testing.EqualsTester; +import java.util.UUID; + +/** + * Unit tests for PortPairGroupId class. + */ +public class PortPairGroupIdTest { + + final PortPairGroupId portPairGroupId1 = PortPairGroupId.of("78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae"); + final PortPairGroupId sameAsPortPairGroupId1 = PortPairGroupId + .of("78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae"); + final PortPairGroupId portPairGroupId2 = PortPairGroupId.of("dace4513-24fc-4fae-af4b-321c5e2eb3d1"); + + /** + * Checks that the PortPairGroupId class is immutable. + */ + @Test + public void testImmutability() { + assertThatClassIsImmutable(PortPairGroupId.class); + } + + /** + * Checks the operation of equals() methods. + */ + @Test + public void testEquals() { + new EqualsTester().addEqualityGroup(portPairGroupId1, sameAsPortPairGroupId1) + .addEqualityGroup(portPairGroupId2).testEquals(); + } + + /** + * Checks the construction of a PortPairGroupId object. + */ + @Test + public void testConstruction() { + final String portPairGroupIdValue = "dace4513-24fc-4fae-af4b-321c5e2eb3d1"; + final PortPairGroupId portPairGroupId = PortPairGroupId.of(portPairGroupIdValue); + assertThat(portPairGroupId, is(notNullValue())); + assertThat(portPairGroupId.value(), is(UUID.fromString(portPairGroupIdValue))); + } +} -- cgit 1.2.3-korg