diff options
Diffstat (limited to 'framework/src/onos/apps/vtn')
7 files changed, 581 insertions, 74 deletions
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 @@ <?xml version="1.0" encoding="UTF-8"?> -<!-- ~ Copyright 2014 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. --> +<!-- ~ Copyright 2014 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. --> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.onosproject</groupId> - <artifactId>onos-app-vtn</artifactId> - <version>1.4.0-SNAPSHOT</version> - <relativePath>../pom.xml</relativePath> - </parent> + <parent> + <groupId>org.onosproject</groupId> + <artifactId>onos-app-vtn</artifactId> + <version>1.4.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> - <artifactId>onos-app-vtn-onosfw</artifactId> - <packaging>pom</packaging> + <artifactId>onos-app-vtn-onosfw</artifactId> + <packaging>pom</packaging> - <description>ONOS framework applications</description> + <description>ONOS framework applications</description> - <dependencies> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-app-vtn-rsc</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-app-vtn-web</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-app-vtn-mgr</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> + <dependencies> + <dependency> + <groupId>org.onosproject</groupId> + <artifactId>onos-app-vtn-rsc</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.onosproject</groupId> + <artifactId>onos-app-vtn-web</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.onosproject</groupId> + <artifactId>onos-app-vtn-mgr</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> </project> 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 @@ <module>vtnmgr</module> <module>vtnweb</module> <module>app</module> - </modules> - <dependencies> - <dependency> + </modules> + <dependencies> + <dependency> <groupId>org.onosproject</groupId> <artifactId>onlab-junit</artifactId> <scope>test</scope> 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. --> <project - 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"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.onosproject</groupId> - <artifactId>onos-app-vtn</artifactId> - <version>1.4.0-SNAPSHOT</version> - <relativePath>../pom.xml</relativePath> - </parent> + 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"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.onosproject</groupId> + <artifactId>onos-app-vtn</artifactId> + <version>1.4.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> - <artifactId>onos-app-vtn-rsc</artifactId> - <packaging>bundle</packaging> + <artifactId>onos-app-vtn-rsc</artifactId> + <packaging>bundle</packaging> - <dependencies> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-api</artifactId> - </dependency> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-cli</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.felix</groupId> - <artifactId>org.apache.felix.scr.annotations</artifactId> - </dependency> - <dependency> - <groupId>org.apache.karaf.shell</groupId> - <artifactId>org.apache.karaf.shell.console</artifactId> - </dependency> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-core-serializers</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> + <dependencies> + <dependency> + <groupId>org.onosproject</groupId> + <artifactId>onos-api</artifactId> + </dependency> + <dependency> + <groupId>org.onosproject</groupId> + <artifactId>onos-cli</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.felix</groupId> + <artifactId>org.apache.felix.scr.annotations</artifactId> + </dependency> + <dependency> + <groupId>org.apache.karaf.shell</groupId> + <artifactId>org.apache.karaf.shell.console</artifactId> + </dependency> + <dependency> + <groupId>org.onosproject</groupId> + <artifactId>onos-core-serializers</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> </project> 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<PortPairGroupId> portPairGroups = new LinkedList<PortPairGroupId>(); + 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<FlowClassifierId> flowClassifiers = new LinkedList<FlowClassifierId>(); + 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<PortPairGroupId> portPairGroups2 = new LinkedList<PortPairGroupId>(); + 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<FlowClassifierId> flowClassifiers2 = new LinkedList<FlowClassifierId>(); + 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<PortPairGroupId> portPairGroups = new LinkedList<PortPairGroupId>(); + 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<FlowClassifierId> flowClassifiers = new LinkedList<FlowClassifierId>(); + 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<PortPairId> portPairList = new LinkedList<PortPairId>(); + 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<PortPairId> portPairList2 = new LinkedList<PortPairId>(); + 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<PortPairId> portPairList = new LinkedList<PortPairId>(); + 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())); + } +} |