diff options
Diffstat (limited to 'framework/src/onos/core/api/src/test')
4 files changed, 160 insertions, 124 deletions
diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/OduSignalIdTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/OduSignalIdTest.java new file mode 100644 index 00000000..2ed15ff9 --- /dev/null +++ b/framework/src/onos/core/api/src/test/java/org/onosproject/net/OduSignalIdTest.java @@ -0,0 +1,39 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.net; + +import com.google.common.testing.EqualsTester; +import org.junit.Test; +import static org.onosproject.net.OduSignalId.oduSignalId; + +/** + * Test for OduSignalId. + */ +public class OduSignalIdTest { + + private final OduSignalId odu1 = oduSignalId(7, 80, new byte[] {16, 16, 16, 16, 16, 16, 16, 16, 16, 16}); + private final OduSignalId sameOdu1 = oduSignalId(7, 80, new byte[] {16, 16, 16, 16, 16, 16, 16, 16, 16, 16}); + private final OduSignalId odu2 = oduSignalId(21, 80, new byte[] {10, 5, 10, 5, 10, 5, 10, 5, 10, 5}); + private final OduSignalId sameOdu2 = oduSignalId(21, 80, new byte[] {10, 5, 10, 5, 10, 5, 10, 5, 10, 5}); + + @Test + public void testEquality() { + new EqualsTester() + .addEqualityGroup(odu1, sameOdu1) + .addEqualityGroup(odu2, sameOdu2) + .testEquals(); + } +} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/criteria/CriteriaTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/criteria/CriteriaTest.java index 95d605c6..d86744df 100644 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/criteria/CriteriaTest.java +++ b/framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/criteria/CriteriaTest.java @@ -15,6 +15,16 @@ */ package org.onosproject.net.flow.criteria; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.instanceOf; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; +import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; +import static org.onlab.junit.UtilityClassChecker.assertThatClassIsUtility; +import static org.onosproject.net.OduSignalId.oduSignalId; +import static org.onosproject.net.PortNumber.portNumber; + import org.junit.Test; import org.onlab.packet.EthType; import org.onlab.packet.Ip6Address; @@ -26,20 +36,12 @@ import org.onlab.packet.VlanId; import org.onosproject.net.ChannelSpacing; import org.onosproject.net.GridType; import org.onosproject.net.Lambda; +import org.onosproject.net.OchSignalType; +import org.onosproject.net.OduSignalId; +import org.onosproject.net.OduSignalType; import org.onosproject.net.PortNumber; import com.google.common.testing.EqualsTester; -import org.onosproject.net.OchSignalType; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.instanceOf; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; -import static org.onlab.junit.UtilityClassChecker.assertThatClassIsUtility; -import static org.onosproject.net.PortNumber.portNumber; - /** * Unit tests for the Criteria class and its subclasses. */ @@ -240,6 +242,18 @@ public class CriteriaTest { Criterion matchOchSignal2 = Criteria.matchLambda(Lambda.ochSignal(GridType.DWDM, ChannelSpacing.CHL_50GHZ, 4, 8)); + final OduSignalId odu1 = oduSignalId(1, 80, new byte [] {1, 1, 2, 2, 1, 2, 2, 1, 2, 2}); + final OduSignalId odu2 = oduSignalId(3, 8, new byte [] {1, 0, 0, 0, 0, 0, 0, 0, 0, 0}); + Criterion matchOduSignalId1 = Criteria.matchOduSignalId(odu1); + Criterion sameAsMatchOduSignalId1 = Criteria.matchOduSignalId(odu1); + Criterion matchOduSignalId2 = Criteria.matchOduSignalId(odu2); + + final OduSignalType oduSigType1 = OduSignalType.ODU2; + final OduSignalType oduSigType2 = OduSignalType.ODU4; + Criterion matchOduSignalType1 = Criteria.matchOduSignalType(oduSigType1); + Criterion sameAsMatchOduSignalType1 = Criteria.matchOduSignalType(oduSigType1); + Criterion matchOduSignalType2 = Criteria.matchOduSignalType(oduSigType2); + /** * Checks that a Criterion object has the proper type, and then converts * it to the proper type. @@ -294,6 +308,8 @@ public class CriteriaTest { assertThatClassIsImmutable(MplsCriterion.class); assertThatClassIsImmutable(IPv6ExthdrFlagsCriterion.class); assertThatClassIsImmutable(LambdaCriterion.class); + assertThatClassIsImmutable(OduSignalIdCriterion.class); + assertThatClassIsImmutable(OduSignalTypeCriterion.class); } // PortCriterion class @@ -1070,4 +1086,57 @@ public class CriteriaTest { .addEqualityGroup(matchOchSignalType2) .testEquals(); } + + /** + * Test the OduSignalId method. + */ + @Test + public void testMatchOduSignalIdMethod() { + OduSignalId odu = oduSignalId(1, 80, new byte[]{2, 1, 1, 3, 1, 1, 3, 1, 1, 3}); + + Criterion matchoduSignalId = Criteria.matchOduSignalId(odu); + OduSignalIdCriterion oduSignalIdCriterion = + checkAndConvert(matchoduSignalId, + Criterion.Type.ODU_SIGID, + OduSignalIdCriterion.class); + assertThat(oduSignalIdCriterion.oduSignalId(), is(equalTo(odu))); + } + + /** + * Test the equals() method of the OduSignalIdCriterion class. + */ + @Test + public void testOduSignalIdCriterionEquals() { + new EqualsTester() + .addEqualityGroup(matchOduSignalId1, sameAsMatchOduSignalId1) + .addEqualityGroup(matchOduSignalId2) + .testEquals(); + } + + // OduSignalTypeCriterion class + + /** + * Test the OduSignalType method. + */ + @Test + public void testMatchOduSignalTypeMethod() { + OduSignalType oduSigType = OduSignalType.ODU2; + Criterion matchoduSignalType = Criteria.matchOduSignalType(oduSigType); + OduSignalTypeCriterion oduSignalTypeCriterion = + checkAndConvert(matchoduSignalType, + Criterion.Type.ODU_SIGTYPE, + OduSignalTypeCriterion.class); + assertThat(oduSignalTypeCriterion.signalType(), is(equalTo(oduSigType))); + } + + /** + * Test the equals() method of the OduSignalTypeCriterion class. + */ + @Test + public void testOduSignalTypeCriterionEquals() { + new EqualsTester() + .addEqualityGroup(matchOduSignalType1, sameAsMatchOduSignalType1) + .addEqualityGroup(matchOduSignalType2) + .testEquals(); + } } diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/instructions/InstructionsTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/instructions/InstructionsTest.java index 410349b5..a25783f9 100644 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/instructions/InstructionsTest.java +++ b/framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/instructions/InstructionsTest.java @@ -25,6 +25,7 @@ import org.onosproject.net.ChannelSpacing; import org.onosproject.net.GridType; import org.onosproject.net.IndexedLambda; import org.onosproject.net.Lambda; +import org.onosproject.net.OduSignalId; import org.onosproject.net.PortNumber; import com.google.common.testing.EqualsTester; @@ -38,6 +39,7 @@ import static org.hamcrest.Matchers.notNullValue; import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; import static org.onlab.junit.UtilityClassChecker.assertThatClassIsUtility; import static org.onosproject.net.PortNumber.portNumber; +import static org.onosproject.net.OduSignalId.oduSignalId; /** * Unit tests for the Instructions class. @@ -96,6 +98,7 @@ public class InstructionsTest { assertThatClassIsImmutable(Instructions.OutputInstruction.class); assertThatClassIsImmutable(L0ModificationInstruction.ModLambdaInstruction.class); assertThatClassIsImmutable(L0ModificationInstruction.ModOchSignalInstruction.class); + assertThatClassIsImmutable(L1ModificationInstruction.ModOduSignalIdInstruction.class); assertThatClassIsImmutable(L2ModificationInstruction.ModEtherInstruction.class); assertThatClassIsImmutable(L2ModificationInstruction.ModVlanIdInstruction.class); assertThatClassIsImmutable(L2ModificationInstruction.ModVlanPcpInstruction.class); @@ -259,6 +262,44 @@ public class InstructionsTest { assertThat(ochInstruction1.hashCode(), is(not(ochInstruction2.hashCode()))); } + // ModOduSignalIdInstruction + + private final OduSignalId odu1 = oduSignalId(1, 80, new byte[] {8, 7, 6, 5, 7, 6, 5, 7, 6, 5}); + private final OduSignalId odu2 = oduSignalId(2, 80, new byte[] {1, 1, 2, 2, 1, 2, 2, 1, 2, 2}); + private final Instruction oduInstruction1 = Instructions.modL1OduSignalId(odu1); + private final Instruction sameAsOduInstruction1 = Instructions.modL1OduSignalId(odu1); + private final Instruction oduInstruction2 = Instructions.modL1OduSignalId(odu2); + + /** + * Test the modL1OduSignalId(). + */ + @Test + public void testModL1OduSignalIdMethod() { + Instruction instruction = Instructions.modL1OduSignalId(odu1); + L1ModificationInstruction.ModOduSignalIdInstruction oduInstruction = + checkAndConvert(instruction, Instruction.Type.L1MODIFICATION, + L1ModificationInstruction.ModOduSignalIdInstruction.class); + assertThat(oduInstruction.oduSignalId(), is(odu1)); + } + + /** + * Test the equals() method of the ModOduSignalInstruction class. + */ + @Test + public void testModOduSignalIdInstructionEquals() { + checkEqualsAndToString(oduInstruction1, sameAsOduInstruction1, oduInstruction2); + } + + /** + * Test the hashCode() method of the ModOduSignalInstruction class. + */ + @Test + public void testModOduSignalIdInstructionHashCode() { + assertThat(oduInstruction1.hashCode(), is(sameAsOduInstruction1.hashCode())); + assertThat(oduInstruction1.hashCode(), is(not(oduInstruction2.hashCode()))); + } + + // ModEtherInstruction private static final String MAC1 = "00:00:00:00:00:01"; diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/host/PortAddressesTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/host/PortAddressesTest.java deleted file mode 100644 index 7c10cd15..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/host/PortAddressesTest.java +++ /dev/null @@ -1,113 +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.net.host; - -import java.util.Set; - -import org.junit.Before; -import org.junit.Test; -import org.onlab.packet.IpAddress; -import org.onlab.packet.IpPrefix; -import org.onlab.packet.MacAddress; -import org.onlab.packet.VlanId; -import org.onosproject.net.ConnectPoint; -import org.onosproject.net.NetTestTools; - -import static org.hamcrest.Matchers.is; -import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; - -import com.google.common.collect.ImmutableSet; -import com.google.common.testing.EqualsTester; -import static org.hamcrest.MatcherAssert.assertThat; - -/** - * Unit tests for port addresses class. - */ -public class PortAddressesTest { - - PortAddresses addresses1; - PortAddresses sameAsAddresses1; - PortAddresses addresses2; - PortAddresses addresses3; - - private static final ConnectPoint CONNECT_POINT1 = - NetTestTools.connectPoint("cp1", 1); - private static final IpAddress IP_ADDRESS1 = IpAddress.valueOf("1.2.3.4"); - private static final IpPrefix SUBNET_ADDRESS1 = - IpPrefix.valueOf("1.2.0.0/16"); - private static final InterfaceIpAddress INTERFACE_ADDRESS_1 = - new InterfaceIpAddress(IP_ADDRESS1, SUBNET_ADDRESS1); - - private static final ConnectPoint CONNECT_POINT2 = - NetTestTools.connectPoint("cp2", 1); - private static final IpAddress IP_ADDRESS2 = IpAddress.valueOf("1.2.3.5"); - private static final IpPrefix SUBNET_ADDRESS2 = - IpPrefix.valueOf("1.3.0.0/16"); - private static final InterfaceIpAddress INTERFACE_ADDRESS_2 = - new InterfaceIpAddress(IP_ADDRESS2, SUBNET_ADDRESS2); - - Set<InterfaceIpAddress> ipAddresses; - - - /** - * Initializes local data used by all test cases. - */ - @Before - public void setUpAddresses() { - ipAddresses = ImmutableSet.of(INTERFACE_ADDRESS_1, - INTERFACE_ADDRESS_2); - addresses1 = new PortAddresses(CONNECT_POINT1, ipAddresses, - MacAddress.BROADCAST, VlanId.NONE); - sameAsAddresses1 = new PortAddresses(CONNECT_POINT1, ipAddresses, - MacAddress.BROADCAST, VlanId.NONE); - addresses2 = new PortAddresses(CONNECT_POINT2, ipAddresses, - MacAddress.BROADCAST, VlanId.NONE); - addresses3 = new PortAddresses(CONNECT_POINT2, ipAddresses, - MacAddress.ZERO, VlanId.NONE); - } - - /** - * Checks that the PortAddresses class is immutable. - */ - @Test - public void testImmutability() { - assertThatClassIsImmutable(PortAddresses.class); - } - - /** - * Checks the operation of the equals(), hash() and toString() - * methods. - */ - @Test - public void testEquals() { - new EqualsTester() - .addEqualityGroup(addresses1, sameAsAddresses1) - .addEqualityGroup(addresses2) - .addEqualityGroup(addresses3) - .testEquals(); - } - - /** - * Tests that object are created correctly. - */ - @Test - public void testConstruction() { - assertThat(addresses1.mac(), is(MacAddress.BROADCAST)); - assertThat(addresses1.connectPoint(), is(CONNECT_POINT1)); - assertThat(addresses1.ipAddresses(), is(ipAddresses)); - assertThat(addresses1.vlan(), is(VlanId.NONE)); - } -} |