From e5df26295703f2f8f5f9b9ee406407a5684b8122 Mon Sep 17 00:00:00 2001 From: Ashlee Young Date: Fri, 13 Nov 2015 16:06:48 -0800 Subject: ONOS commit id 710293f3afa03540a1fd3be038da0ea6a488765c Change-Id: I66c2370960d7597bdbaf7bf58defca3e864c4215 Signed-off-by: Ashlee Young --- framework/src/onos/apps/routing/pom.xml | 2 +- .../org/onosproject/sdnip/IntentSynchronizer.java | 85 +++++------- .../onosproject/sdnip/PeerConnectivityManager.java | 10 +- .../src/main/java/org/onosproject/sdnip/SdnIp.java | 20 ++- framework/src/onos/apps/vtn/app/pom.xml | 72 +++++----- framework/src/onos/apps/vtn/pom.xml | 6 +- framework/src/onos/apps/vtn/vtnrsc/pom.xml | 70 +++++----- .../flowclassifier/DefaultFlowClassifierTest.java | 148 +++++++++++++++++++++ .../vtnrsc/portchain/DefaultPortChainTest.java | 140 +++++++++++++++++++ .../vtnrsc/portpair/DefaultPortPairTest.java | 102 ++++++++++++++ .../portpairgroup/DefaultPortPairGroupTest.java | 117 ++++++++++++++++ 11 files changed, 631 insertions(+), 141 deletions(-) create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/flowclassifier/DefaultFlowClassifierTest.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portchain/DefaultPortChainTest.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portpair/DefaultPortPairTest.java create mode 100644 framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portpairgroup/DefaultPortPairGroupTest.java (limited to 'framework/src/onos/apps') diff --git a/framework/src/onos/apps/routing/pom.xml b/framework/src/onos/apps/routing/pom.xml index c461ef3f..2882f52e 100644 --- a/framework/src/onos/apps/routing/pom.xml +++ b/framework/src/onos/apps/routing/pom.xml @@ -43,7 +43,7 @@ ${project.version} - + org.onosproject onlab-thirdparty diff --git a/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/IntentSynchronizer.java b/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/IntentSynchronizer.java index f2d5b5e2..a3cd6875 100644 --- a/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/IntentSynchronizer.java +++ b/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/IntentSynchronizer.java @@ -15,24 +15,25 @@ */ package org.onosproject.sdnip; -import org.onosproject.core.ApplicationId; -import org.onosproject.net.intent.Intent; -import org.onosproject.net.intent.IntentService; -import org.onosproject.net.intent.IntentState; -import org.onosproject.net.intent.Key; -import org.onosproject.routing.IntentSynchronizationService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import static java.util.concurrent.Executors.newSingleThreadExecutor; +import static org.onlab.util.Tools.groupedThreads; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutorService; -import static java.util.concurrent.Executors.newSingleThreadExecutor; -import static org.onlab.util.Tools.groupedThreads; +import org.onosproject.core.ApplicationId; +import org.onosproject.net.intent.Intent; +import org.onosproject.net.intent.IntentService; +import org.onosproject.net.intent.IntentState; +import org.onosproject.net.intent.Key; +import org.onosproject.routing.IntentSynchronizationService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Synchronizes intents between the in-memory intent store and the @@ -97,55 +98,30 @@ public class IntentSynchronizer implements IntentSynchronizationService { synchronized (this) { // Stop the thread(s) intentsSynchronizerExecutor.shutdownNow(); + log.info("Intents Synchronizer Executor shutdown completed"); - // - // Withdraw all app related intents - // - if (!isElectedLeader) { - return; // Nothing to do: not the leader anymore - } + } + } - // - // NOTE: We don't withdraw the intents during shutdown, because - // it creates flux in the data plane during switchover. - // - - /* - // - // Build a batch operation to withdraw all intents from this - // application. - // - log.debug("Intent Synchronizer shutdown: " + - "withdrawing all intents..."); - IntentOperations.Builder builder = IntentOperations.builder(appId); - for (Intent intent : intentService.getIntents()) { - // Skip the intents from other applications - if (!intent.appId().equals(appId)) { - continue; - } + /** + * Withdraws all intents. + */ + public void removeIntents() { + if (!isElectedLeader) { + // only leader will withdraw intents + return; + } - // Skip the intents that are already withdrawn - IntentState intentState = - intentService.getIntentState(intent.id()); - if ((intentState == null) || - intentState.equals(IntentState.WITHDRAWING) || - intentState.equals(IntentState.WITHDRAWN)) { - continue; - } + log.debug("Intent Synchronizer shutdown: withdrawing all intents..."); - log.trace("Intent Synchronizer withdrawing intent: {}", - intent); - builder.addWithdrawOperation(intent.id()); - } - IntentOperations intentOperations = builder.build(); - intentService.execute(intentOperations); - leaderChanged(false); - - peerIntents.clear(); - routeIntents.clear(); - log.debug("Intent Synchronizer shutdown completed"); - */ + for (Entry entry : intents.entrySet()) { + intentService.withdraw(entry.getValue()); + log.debug("Intent Synchronizer withdrawing intent: {}", + entry.getValue()); } + + intents.clear(); + log.info("Tried to clean all intents"); } @Override @@ -261,5 +237,4 @@ public class IntentSynchronizer implements IntentSynchronizationService { } log.debug("Intent synchronization completed"); } - } diff --git a/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/PeerConnectivityManager.java b/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/PeerConnectivityManager.java index a27baaf9..fb008aad 100644 --- a/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/PeerConnectivityManager.java +++ b/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/PeerConnectivityManager.java @@ -340,15 +340,15 @@ public class PeerConnectivityManager { private TrafficSelector buildSelector(byte ipProto, IpAddress srcIp, IpAddress dstIp, Short srcTcpPort, Short dstTcpPort) { - TrafficSelector.Builder builder = DefaultTrafficSelector.builder() - .matchEthType(Ethernet.TYPE_IPV4) - .matchIPProtocol(ipProto); + TrafficSelector.Builder builder = DefaultTrafficSelector.builder().matchIPProtocol(ipProto); if (dstIp.isIp4()) { - builder.matchIPSrc(IpPrefix.valueOf(srcIp, IpPrefix.MAX_INET_MASK_LENGTH)) + builder.matchEthType(Ethernet.TYPE_IPV4) + .matchIPSrc(IpPrefix.valueOf(srcIp, IpPrefix.MAX_INET_MASK_LENGTH)) .matchIPDst(IpPrefix.valueOf(dstIp, IpPrefix.MAX_INET_MASK_LENGTH)); } else { - builder.matchIPv6Src(IpPrefix.valueOf(srcIp, IpPrefix.MAX_INET6_MASK_LENGTH)) + builder.matchEthType(Ethernet.TYPE_IPV6) + .matchIPv6Src(IpPrefix.valueOf(srcIp, IpPrefix.MAX_INET6_MASK_LENGTH)) .matchIPv6Dst(IpPrefix.valueOf(dstIp, IpPrefix.MAX_INET6_MASK_LENGTH)); } diff --git a/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/SdnIp.java b/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/SdnIp.java index 1b3eda9d..ace888d1 100644 --- a/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/SdnIp.java +++ b/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/SdnIp.java @@ -15,12 +15,17 @@ */ package org.onosproject.sdnip; +import static org.slf4j.LoggerFactory.getLogger; + +import java.util.Objects; + import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.Deactivate; import org.apache.felix.scr.annotations.Reference; import org.apache.felix.scr.annotations.ReferenceCardinality; import org.apache.felix.scr.annotations.Service; +import org.onosproject.app.ApplicationService; import org.onosproject.cluster.ClusterService; import org.onosproject.cluster.ControllerNode; import org.onosproject.cluster.LeadershipEvent; @@ -28,8 +33,8 @@ import org.onosproject.cluster.LeadershipEventListener; import org.onosproject.cluster.LeadershipService; import org.onosproject.core.ApplicationId; import org.onosproject.core.CoreService; -import org.onosproject.net.config.NetworkConfigService; import org.onosproject.incubator.net.intf.InterfaceService; +import org.onosproject.net.config.NetworkConfigService; import org.onosproject.net.host.HostService; import org.onosproject.net.intent.IntentService; import org.onosproject.routing.IntentSynchronizationService; @@ -38,10 +43,6 @@ import org.onosproject.routing.SdnIpService; import org.onosproject.routing.config.RoutingConfigurationService; import org.slf4j.Logger; -import java.util.Objects; - -import static org.slf4j.LoggerFactory.getLogger; - /** * Component for the SDN-IP peering application. */ @@ -58,6 +59,9 @@ public class SdnIp implements SdnIpService { @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) protected IntentService intentService; + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) + protected ApplicationService applicationService; + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) protected HostService hostService; @@ -84,7 +88,7 @@ public class SdnIp implements SdnIpService { private SdnIpFib fib; private LeadershipEventListener leadershipEventListener = - new InnerLeadershipEventListener(); + new InnerLeadershipEventListener(); private ApplicationId appId; private ControllerNode localControllerNode; @@ -113,6 +117,10 @@ public class SdnIp implements SdnIpService { leadershipService.addListener(leadershipEventListener); leadershipService.runForLeadership(appId.name()); + + applicationService.registerDeactivateHook(appId, + intentSynchronizer::removeIntents); + } @Deactivate diff --git a/framework/src/onos/apps/vtn/app/pom.xml b/framework/src/onos/apps/vtn/app/pom.xml index 4ed66172..5a877363 100644 --- a/framework/src/onos/apps/vtn/app/pom.xml +++ b/framework/src/onos/apps/vtn/app/pom.xml @@ -1,44 +1,44 @@ - + - 4.0.0 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + 4.0.0 - - org.onosproject - onos-app-vtn - 1.4.0-SNAPSHOT - ../pom.xml - + + org.onosproject + onos-app-vtn + 1.4.0-SNAPSHOT + ../pom.xml + - onos-app-vtn-onosfw - pom + onos-app-vtn-onosfw + pom - ONOS framework applications + ONOS framework applications - - - org.onosproject - onos-app-vtn-rsc - ${project.version} - - - org.onosproject - onos-app-vtn-web - ${project.version} - - - org.onosproject - onos-app-vtn-mgr - ${project.version} - - + + + org.onosproject + onos-app-vtn-rsc + ${project.version} + + + org.onosproject + onos-app-vtn-web + ${project.version} + + + org.onosproject + onos-app-vtn-mgr + ${project.version} + + diff --git a/framework/src/onos/apps/vtn/pom.xml b/framework/src/onos/apps/vtn/pom.xml index e91b0c9b..e8387cb7 100644 --- a/framework/src/onos/apps/vtn/pom.xml +++ b/framework/src/onos/apps/vtn/pom.xml @@ -36,9 +36,9 @@ vtnmgr vtnweb app - - - + + + org.onosproject onlab-junit test diff --git a/framework/src/onos/apps/vtn/vtnrsc/pom.xml b/framework/src/onos/apps/vtn/vtnrsc/pom.xml index 8696295c..816624cb 100644 --- a/framework/src/onos/apps/vtn/vtnrsc/pom.xml +++ b/framework/src/onos/apps/vtn/vtnrsc/pom.xml @@ -15,42 +15,42 @@ ~ limitations under the License. --> - 4.0.0 - - org.onosproject - onos-app-vtn - 1.4.0-SNAPSHOT - ../pom.xml - + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" + xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + 4.0.0 + + org.onosproject + onos-app-vtn + 1.4.0-SNAPSHOT + ../pom.xml + - onos-app-vtn-rsc - bundle + onos-app-vtn-rsc + bundle - - - org.onosproject - onos-api - - - org.onosproject - onos-cli - ${project.version} - - - org.apache.felix - org.apache.felix.scr.annotations - - - org.apache.karaf.shell - org.apache.karaf.shell.console - - - org.onosproject - onos-core-serializers - ${project.version} - - + + + org.onosproject + onos-api + + + org.onosproject + onos-cli + ${project.version} + + + org.apache.felix + org.apache.felix.scr.annotations + + + org.apache.karaf.shell + org.apache.karaf.shell.console + + + org.onosproject + onos-core-serializers + ${project.version} + + diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/flowclassifier/DefaultFlowClassifierTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/flowclassifier/DefaultFlowClassifierTest.java new file mode 100644 index 00000000..6b0d9a64 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/flowclassifier/DefaultFlowClassifierTest.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.flowclassifier; + +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.IpPrefix; +import org.onosproject.vtnrsc.TenantId; +import org.onosproject.vtnrsc.DefaultFlowClassifier; +import org.onosproject.vtnrsc.FlowClassifierId; +import org.onosproject.vtnrsc.VirtualPortId; +import org.onosproject.vtnrsc.FlowClassifier; + +import com.google.common.testing.EqualsTester; + +/** + * Unit tests for DefaultFlowClassifier class. + */ +public class DefaultFlowClassifierTest { + /** + * Checks that the DefaultFlowClassifier class is immutable. + */ + @Test + public void testImmutability() { + assertThatClassIsImmutable(DefaultFlowClassifier.class); + } + + /** + * Checks the operation of equals() methods. + */ + @Test + public void testEquals() { + // Create same two flow classifier objects. + final String name = "FlowClassifier1"; + final String description = "FlowClassifier1"; + final String ethType = "IPv4"; + final String protocol = "tcp"; + final int minSrcPortRange = 5; + final int maxSrcPortRange = 10; + final int minDstPortRange = 5; + final int maxDstPortRange = 10; + final FlowClassifierId flowClassifierId = FlowClassifierId.of("78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae"); + final TenantId tenantId = TenantId.tenantId("1"); + final IpPrefix srcIpPrefix = IpPrefix.valueOf("0.0.0.0/0"); + final IpPrefix dstIpPrefix = IpPrefix.valueOf("10.10.10.10/0"); + final VirtualPortId virtualSrcPort = VirtualPortId.portId("1"); + final VirtualPortId virtualDstPort = VirtualPortId.portId("2"); + + DefaultFlowClassifier.Builder flowClassifierBuilder = new DefaultFlowClassifier.Builder(); + final FlowClassifier flowClassifier1 = flowClassifierBuilder.setFlowClassifierId(flowClassifierId) + .setTenantId(tenantId).setName(name).setDescription(description).setEtherType(ethType) + .setProtocol(protocol).setMinSrcPortRange(minSrcPortRange).setMaxSrcPortRange(maxSrcPortRange) + .setMinDstPortRange(minDstPortRange).setMaxDstPortRange(maxDstPortRange).setSrcIpPrefix(srcIpPrefix) + .setDstIpPrefix(dstIpPrefix).setSrcPort(virtualSrcPort).setDstPort(virtualDstPort).build(); + + flowClassifierBuilder = new DefaultFlowClassifier.Builder(); + final FlowClassifier sameAsFlowClassifier1 = flowClassifierBuilder.setFlowClassifierId(flowClassifierId) + .setTenantId(tenantId).setName(name).setDescription(description).setEtherType(ethType) + .setProtocol(protocol).setMinSrcPortRange(minSrcPortRange).setMaxSrcPortRange(maxSrcPortRange) + .setMinDstPortRange(minDstPortRange).setMaxDstPortRange(maxDstPortRange).setSrcIpPrefix(srcIpPrefix) + .setDstIpPrefix(dstIpPrefix).setSrcPort(virtualSrcPort).setDstPort(virtualDstPort).build(); + + // Create different classifier object. + final String name2 = "FlowClassifier2"; + final String description2 = "FlowClassifier2"; + final String ethType2 = "IPv6"; + final String protocol2 = "udp"; + final int minSrcPortRange2 = 5; + final int maxSrcPortRange2 = 10; + final int minDstPortRange2 = 5; + final int maxDstPortRange2 = 10; + final FlowClassifierId flowClassifierId2 = FlowClassifierId.of("78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae"); + final TenantId tenantId2 = TenantId.tenantId("2"); + final IpPrefix srcIpPrefix2 = IpPrefix.valueOf("0.0.0.0/0"); + final IpPrefix dstIpPrefix2 = IpPrefix.valueOf("10.10.10.10/0"); + final VirtualPortId virtualSrcPort2 = VirtualPortId.portId("3"); + final VirtualPortId virtualDstPort2 = VirtualPortId.portId("4"); + + DefaultFlowClassifier.Builder flowClassifierBuilder3 = new DefaultFlowClassifier.Builder(); + final FlowClassifier flowClassifier2 = flowClassifierBuilder3.setFlowClassifierId(flowClassifierId2) + .setTenantId(tenantId2).setName(name2).setDescription(description2).setEtherType(ethType2) + .setProtocol(protocol2).setMinSrcPortRange(minSrcPortRange2).setMaxSrcPortRange(maxSrcPortRange2) + .setMinDstPortRange(minDstPortRange2).setMaxDstPortRange(maxDstPortRange2).setSrcIpPrefix(srcIpPrefix2) + .setDstIpPrefix(dstIpPrefix2).setSrcPort(virtualSrcPort2).setDstPort(virtualDstPort2).build(); + + new EqualsTester().addEqualityGroup(flowClassifier1, sameAsFlowClassifier1).addEqualityGroup(flowClassifier2) + .testEquals(); + } + + /** + * Checks the construction of a DefaultFlowClassifier object. + */ + @Test + public void testConstruction() { + final String name = "FlowClassifier"; + final String description = "FlowClassifier"; + final String ethType = "IPv4"; + final String protocol = "tcp"; + final int minSrcPortRange = 5; + final int maxSrcPortRange = 10; + final int minDstPortRange = 5; + final int maxDstPortRange = 10; + final FlowClassifierId flowClassifierId = FlowClassifierId.of("78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae"); + final TenantId tenantId = TenantId.tenantId("1"); + final IpPrefix srcIpPrefix = IpPrefix.valueOf("0.0.0.0/0"); + final IpPrefix dstIpPrefix = IpPrefix.valueOf("10.10.10.10/0"); + final VirtualPortId virtualSrcPort = VirtualPortId.portId("1"); + final VirtualPortId virtualDstPort = VirtualPortId.portId("2"); + + DefaultFlowClassifier.Builder flowClassifierBuilder = new DefaultFlowClassifier.Builder(); + final FlowClassifier flowClassifier = flowClassifierBuilder.setFlowClassifierId(flowClassifierId) + .setTenantId(tenantId).setName(name).setDescription(description).setEtherType(ethType) + .setProtocol(protocol).setMinSrcPortRange(minSrcPortRange).setMaxSrcPortRange(maxSrcPortRange) + .setMinDstPortRange(minDstPortRange).setMaxDstPortRange(maxDstPortRange).setSrcIpPrefix(srcIpPrefix) + .setDstIpPrefix(dstIpPrefix).setSrcPort(virtualSrcPort).setDstPort(virtualDstPort).build(); + + assertThat(flowClassifierId, is(flowClassifier.flowClassifierId())); + assertThat(tenantId, is(flowClassifier.tenantId())); + assertThat(name, is(flowClassifier.name())); + assertThat(description, is(flowClassifier.description())); + assertThat(ethType, is(flowClassifier.etherType())); + assertThat(protocol, is(flowClassifier.protocol())); + assertThat(minSrcPortRange, is(flowClassifier.minSrcPortRange())); + assertThat(maxSrcPortRange, is(flowClassifier.maxSrcPortRange())); + assertThat(minDstPortRange, is(flowClassifier.minDstPortRange())); + assertThat(maxDstPortRange, is(flowClassifier.maxDstPortRange())); + assertThat(srcIpPrefix, is(flowClassifier.srcIpPrefix())); + assertThat(dstIpPrefix, is(flowClassifier.dstIpPrefix())); + assertThat(virtualSrcPort, is(flowClassifier.srcPort())); + assertThat(virtualDstPort, is(flowClassifier.dstPort())); + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portchain/DefaultPortChainTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portchain/DefaultPortChainTest.java new file mode 100644 index 00000000..b9ce73d8 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portchain/DefaultPortChainTest.java @@ -0,0 +1,140 @@ +/* + * 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.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; + +import org.junit.Test; +import java.util.List; +import java.util.LinkedList; + +import org.onosproject.vtnrsc.PortChainId; +import org.onosproject.vtnrsc.PortPairGroupId; +import org.onosproject.vtnrsc.TenantId; +import org.onosproject.vtnrsc.FlowClassifierId; +import org.onosproject.vtnrsc.PortChain; +import org.onosproject.vtnrsc.DefaultPortChain; + +import com.google.common.testing.EqualsTester; + +/** + * Unit tests for DefaultPortChain class. + */ +public class DefaultPortChainTest { + /** + * Checks that the DefaultPortChain class is immutable. + */ + @Test + public void testImmutability() { + assertThatClassIsImmutable(DefaultPortChain.class); + } + + /** + * Checks the operation of equals() methods. + */ + @Test + public void testEquals() { + // Create same two port chain objects. + final PortChainId portChainId = PortChainId.of("78888888-fc23-aeb6-f44b-56dc5e2fb3ae"); + final TenantId tenantId = TenantId.tenantId("1"); + final String name = "PortChain1"; + final String description = "PortChain1"; + // create list of Port Pair Groups. + final List portPairGroups = new LinkedList(); + PortPairGroupId portPairGroupId = PortPairGroupId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3ae"); + portPairGroups.add(portPairGroupId); + portPairGroupId = PortPairGroupId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3af"); + portPairGroups.add(portPairGroupId); + // create list of Flow classifiers. + final List flowClassifiers = new LinkedList(); + FlowClassifierId flowClassifierId = FlowClassifierId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3ae"); + flowClassifiers.add(flowClassifierId); + flowClassifierId = FlowClassifierId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3af"); + flowClassifiers.add(flowClassifierId); + + DefaultPortChain.Builder portChainBuilder = new DefaultPortChain.Builder(); + final PortChain portChain1 = portChainBuilder.setId(portChainId).setTenantId(tenantId).setName(name) + .setDescription(description).setPortPairGroups(portPairGroups).setFlowClassifiers(flowClassifiers) + .build(); + + portChainBuilder = new DefaultPortChain.Builder(); + final PortChain samePortChain1 = portChainBuilder.setId(portChainId).setTenantId(tenantId).setName(name) + .setDescription(description).setPortPairGroups(portPairGroups).setFlowClassifiers(flowClassifiers) + .build(); + + // Create different port chain object. + final PortChainId portChainId2 = PortChainId.of("79999999-fc23-aeb6-f44b-56dc5e2fb3ae"); + final TenantId tenantId2 = TenantId.tenantId("2"); + final String name2 = "PortChain2"; + final String description2 = "PortChain2"; + // create list of Port Pair Groups. + final List portPairGroups2 = new LinkedList(); + portPairGroupId = PortPairGroupId.of("75555555-fc23-aeb6-f44b-56dc5e2fb3ae"); + portPairGroups2.add(portPairGroupId); + portPairGroupId = PortPairGroupId.of("75555555-fc23-aeb6-f44b-56dc5e2fb3af"); + portPairGroups2.add(portPairGroupId); + // create list of Flow classifiers. + final List flowClassifiers2 = new LinkedList(); + flowClassifierId = FlowClassifierId.of("76666666-fc23-aeb6-f44b-56dc5e2fb3ae"); + flowClassifiers2.add(flowClassifierId); + flowClassifierId = FlowClassifierId.of("76666666-fc23-aeb6-f44b-56dc5e2fb3af"); + flowClassifiers2.add(flowClassifierId); + + portChainBuilder = new DefaultPortChain.Builder(); + final PortChain portChain2 = portChainBuilder.setId(portChainId2).setTenantId(tenantId2).setName(name2) + .setDescription(description2).setPortPairGroups(portPairGroups2).setFlowClassifiers(flowClassifiers2) + .build(); + + new EqualsTester().addEqualityGroup(portChain1, samePortChain1).addEqualityGroup(portChain2).testEquals(); + } + + /** + * Checks the construction of a DefaultPortChain object. + */ + @Test + public void testConstruction() { + final PortChainId portChainId = PortChainId.of("78888888-fc23-aeb6-f44b-56dc5e2fb3ae"); + final TenantId tenantId = TenantId.tenantId("1"); + final String name = "PortChain"; + final String description = "PortChain"; + // create list of Port Pair Groups. + final List portPairGroups = new LinkedList(); + PortPairGroupId portPairGroupId = PortPairGroupId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3ae"); + portPairGroups.add(portPairGroupId); + portPairGroupId = PortPairGroupId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3af"); + portPairGroups.add(portPairGroupId); + // create list of Flow classifiers. + final List flowClassifiers = new LinkedList(); + FlowClassifierId flowClassifierId = FlowClassifierId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3ae"); + flowClassifiers.add(flowClassifierId); + flowClassifierId = FlowClassifierId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3af"); + flowClassifiers.add(flowClassifierId); + + DefaultPortChain.Builder portChainBuilder = new DefaultPortChain.Builder(); + final PortChain portChain = portChainBuilder.setId(portChainId).setTenantId(tenantId).setName(name) + .setDescription(description).setPortPairGroups(portPairGroups).setFlowClassifiers(flowClassifiers) + .build(); + + assertThat(portChainId, is(portChain.portChainId())); + assertThat(tenantId, is(portChain.tenantId())); + assertThat(name, is(portChain.name())); + assertThat(description, is(portChain.description())); + assertThat(portPairGroups, is(portChain.portPairGroups())); + assertThat(flowClassifiers, is(portChain.flowClassifiers())); + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portpair/DefaultPortPairTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portpair/DefaultPortPairTest.java new file mode 100644 index 00000000..91e7ab37 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portpair/DefaultPortPairTest.java @@ -0,0 +1,102 @@ +/* + * 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.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; + +import org.junit.Test; + +import org.onosproject.vtnrsc.PortPairId; +import org.onosproject.vtnrsc.TenantId; +import org.onosproject.vtnrsc.PortPair; +import org.onosproject.vtnrsc.DefaultPortPair; + +import com.google.common.testing.EqualsTester; + +/** + * Unit tests for DefaultPortPair class. + */ +public class DefaultPortPairTest { + /** + * Checks that the DefaultPortPair class is immutable. + */ + @Test + public void testImmutability() { + assertThatClassIsImmutable(DefaultPortPair.class); + } + + /** + * Checks the operation of equals() methods. + */ + @Test + public void testEquals() { + // Create same two port pair objects. + final PortPairId portPairId = PortPairId.of("78888888-fc23-aeb6-f44b-56dc5e2fb3ae"); + final TenantId tenantId = TenantId.tenantId("1"); + final String name = "PortPair1"; + final String description = "PortPair1"; + final String ingress = "d3333333-24fc-4fae-af4b-321c5e2eb3d1"; + final String egress = "a4444444-4a56-2a6e-cd3a-9dee4e2ec345"; + + DefaultPortPair.Builder portPairBuilder = new DefaultPortPair.Builder(); + final PortPair portPair1 = portPairBuilder.setId(portPairId).setTenantId(tenantId).setName(name) + .setDescription(description).setIngress(ingress).setEgress(egress).build(); + + portPairBuilder = new DefaultPortPair.Builder(); + final PortPair samePortPair1 = portPairBuilder.setId(portPairId).setTenantId(tenantId).setName(name) + .setDescription(description).setIngress(ingress).setEgress(egress).build(); + + // Create different port pair object. + final PortPairId portPairId2 = PortPairId.of("79999999-fc23-aeb6-f44b-56dc5e2fb3ae"); + final TenantId tenantId2 = TenantId.tenantId("2"); + final String name2 = "PortPair2"; + final String description2 = "PortPair2"; + final String ingress2 = "d5555555-24fc-4fae-af4b-321c5e2eb3d1"; + final String egress2 = "a6666666-4a56-2a6e-cd3a-9dee4e2ec345"; + + portPairBuilder = new DefaultPortPair.Builder(); + final PortPair portPair2 = portPairBuilder.setId(portPairId2).setTenantId(tenantId2).setName(name2) + .setDescription(description2).setIngress(ingress2).setEgress(egress2).build(); + + new EqualsTester().addEqualityGroup(portPair1, samePortPair1).addEqualityGroup(portPair2).testEquals(); + } + + /** + * Checks the construction of a DefaultPortPair object. + */ + @Test + public void testConstruction() { + final PortPairId portPairId = PortPairId.of("78888888-fc23-aeb6-f44b-56dc5e2fb3ae"); + final TenantId tenantId = TenantId.tenantId("1"); + final String name = "PortPair"; + final String description = "PortPair"; + final String ingress = "d3333333-24fc-4fae-af4b-321c5e2eb3d1"; + final String egress = "a4444444-4a56-2a6e-cd3a-9dee4e2ec345"; + + DefaultPortPair.Builder portPairBuilder = new DefaultPortPair.Builder(); + final PortPair portPair = portPairBuilder.setId(portPairId).setTenantId(tenantId).setName(name) + .setDescription(description).setIngress(ingress).setEgress(egress).build(); + + assertThat(portPairId, is(portPair.portPairId())); + assertThat(tenantId, is(portPair.tenantId())); + assertThat(name, is(portPair.name())); + assertThat(description, is(portPair.description())); + assertThat(ingress, is(portPair.ingress())); + assertThat(egress, is(portPair.egress())); + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portpairgroup/DefaultPortPairGroupTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portpairgroup/DefaultPortPairGroupTest.java new file mode 100644 index 00000000..2528fb29 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portpairgroup/DefaultPortPairGroupTest.java @@ -0,0 +1,117 @@ +/* + * 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.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; + +import org.junit.Test; +import java.util.List; +import java.util.LinkedList; + +import org.onosproject.vtnrsc.PortPairGroupId; +import org.onosproject.vtnrsc.PortPairId; +import org.onosproject.vtnrsc.TenantId; +import org.onosproject.vtnrsc.PortPairGroup; +import org.onosproject.vtnrsc.DefaultPortPairGroup; + +import com.google.common.testing.EqualsTester; + +/** + * Unit tests for DefaultPortPairGroup class. + */ +public class DefaultPortPairGroupTest { + /** + * Checks that the DefaultPortPairGroup class is immutable. + */ + @Test + public void testImmutability() { + assertThatClassIsImmutable(DefaultPortPairGroup.class); + } + + /** + * Checks the operation of equals() methods. + */ + @Test + public void testEquals() { + // Create same two port-pair-group objects. + final PortPairGroupId portPairGroupId = PortPairGroupId.of("78888888-fc23-aeb6-f44b-56dc5e2fb3ae"); + final TenantId tenantId = TenantId.tenantId("1"); + final String name = "PortPairGroup1"; + final String description = "PortPairGroup1"; + // create port-pair-id list + final List portPairList = new LinkedList(); + PortPairId portPairId = PortPairId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3ae"); + portPairList.add(portPairId); + portPairId = PortPairId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3ae"); + portPairList.add(portPairId); + + DefaultPortPairGroup.Builder portPairGroupBuilder = new DefaultPortPairGroup.Builder(); + final PortPairGroup portPairGroup1 = portPairGroupBuilder.setId(portPairGroupId).setTenantId(tenantId) + .setName(name).setDescription(description).setPortPairs(portPairList).build(); + + portPairGroupBuilder = new DefaultPortPairGroup.Builder(); + final PortPairGroup samePortPairGroup1 = portPairGroupBuilder.setId(portPairGroupId).setTenantId(tenantId) + .setName(name).setDescription(description).setPortPairs(portPairList).build(); + + // Create different port-pair-group object. + final PortPairGroupId portPairGroupId2 = PortPairGroupId.of("79999999-fc23-aeb6-f44b-56dc5e2fb3ae"); + final TenantId tenantId2 = TenantId.tenantId("2"); + final String name2 = "PortPairGroup2"; + final String description2 = "PortPairGroup2"; + // create port-pair-id list + final List portPairList2 = new LinkedList(); + portPairId = PortPairId.of("75555555-fc23-aeb6-f44b-56dc5e2fb3ae"); + portPairList2.add(portPairId); + portPairId = PortPairId.of("75555555-fc23-aeb6-f44b-56dc5e2fb3ae"); + portPairList2.add(portPairId); + + portPairGroupBuilder = new DefaultPortPairGroup.Builder(); + final PortPairGroup portPairGroup2 = portPairGroupBuilder.setId(portPairGroupId2).setTenantId(tenantId2) + .setName(name2).setDescription(description2).setPortPairs(portPairList2).build(); + + new EqualsTester().addEqualityGroup(portPairGroup1, samePortPairGroup1).addEqualityGroup(portPairGroup2) + .testEquals(); + } + + /** + * Checks the construction of a DefaultPortPairGroup object. + */ + @Test + public void testConstruction() { + final PortPairGroupId portPairGroupId = PortPairGroupId.of("78888888-fc23-aeb6-f44b-56dc5e2fb3ae"); + final TenantId tenantId = TenantId.tenantId("1"); + final String name = "PortPairGroup"; + final String description = "PortPairGroup"; + // create port-pair-id list + final List portPairList = new LinkedList(); + PortPairId portPairId = PortPairId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3ae"); + portPairList.add(portPairId); + portPairId = PortPairId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3ae"); + portPairList.add(portPairId); + + DefaultPortPairGroup.Builder portPairGroupBuilder = new DefaultPortPairGroup.Builder(); + final PortPairGroup portPairGroup = portPairGroupBuilder.setId(portPairGroupId).setTenantId(tenantId) + .setName(name).setDescription(description).setPortPairs(portPairList).build(); + + assertThat(portPairGroupId, is(portPairGroup.portPairGroupId())); + assertThat(tenantId, is(portPairGroup.tenantId())); + assertThat(name, is(portPairGroup.name())); + assertThat(description, is(portPairGroup.description())); + assertThat(portPairList, is(portPairGroup.portPairs())); + } +} -- cgit