diff options
Diffstat (limited to 'framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/constraint')
5 files changed, 0 insertions, 558 deletions
diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/constraint/AnnotationConstraintTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/constraint/AnnotationConstraintTest.java deleted file mode 100644 index b87dc12b..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/constraint/AnnotationConstraintTest.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * 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. - */ -package org.onosproject.net.intent.constraint; - -import com.google.common.testing.EqualsTester; -import org.junit.Before; -import org.junit.Test; -import org.onosproject.net.DefaultAnnotations; -import org.onosproject.net.DefaultLink; -import org.onosproject.net.DeviceId; -import org.onosproject.net.Link; -import org.onosproject.net.PortNumber; -import org.onosproject.net.provider.ProviderId; -import org.onosproject.net.resource.link.LinkResourceService; - -import static org.easymock.EasyMock.createMock; -import static org.hamcrest.Matchers.closeTo; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.lessThan; -import static org.junit.Assert.assertThat; -import static org.onosproject.net.DefaultLinkTest.cp; -import static org.onosproject.net.DeviceId.deviceId; -import static org.onosproject.net.Link.Type.DIRECT; -import static org.onosproject.net.PortNumber.portNumber; - -/** - * Test for link annotated value threshold. - */ -public class AnnotationConstraintTest { - - private static final ProviderId PID = new ProviderId("of", "foo"); - private static final DeviceId DID1 = deviceId("of:1"); - private static final DeviceId DID2 = deviceId("of:2"); - private static final PortNumber PID1 = portNumber(1); - private static final PortNumber PID2 = portNumber(2); - private static final String KEY = "distance"; - private static final double VALUE = 100; - - private AnnotationConstraint sut; - private Link link; - private LinkResourceService linkResourceService; - - @Before - public void setUp() { - linkResourceService = createMock(LinkResourceService.class); - - DefaultAnnotations annotations = DefaultAnnotations.builder().set(KEY, String.valueOf(VALUE)).build(); - - link = new DefaultLink(PID, cp(DID1, PID1), cp(DID2, PID2), DIRECT, annotations); - } - - /** - * Tests the specified annotated value is less than the threshold. - */ - @Test - public void testLessThanThreshold() { - double value = 120; - sut = new AnnotationConstraint(KEY, value); - - assertThat(sut.isValid(link, linkResourceService), is(true)); - assertThat(sut.cost(link, linkResourceService), is(closeTo(VALUE, 1.0e-6))); - } - - /** - * Tests the specified annotated value is more than the threshold. - */ - @Test - public void testMoreThanThreshold() { - double value = 80; - sut = new AnnotationConstraint(KEY, value); - - assertThat(sut.isValid(link, linkResourceService), is(false)); - assertThat(sut.cost(link, linkResourceService), is(lessThan(0.0))); - } - - @Test - public void testEquality() { - new EqualsTester() - .addEqualityGroup(new AnnotationConstraint(KEY, 100), new AnnotationConstraint(KEY, 100)) - .addEqualityGroup(new AnnotationConstraint(KEY, 120)) - .addEqualityGroup(new AnnotationConstraint("latency", 100)) - .testEquals(); - } -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/constraint/ConstraintObjectsTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/constraint/ConstraintObjectsTest.java deleted file mode 100644 index d2e99400..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/constraint/ConstraintObjectsTest.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright 2014-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.intent.constraint; - -import org.junit.Test; -import org.onlab.util.Bandwidth; -import org.onosproject.net.IndexedLambda; -import org.onosproject.net.Link; - -import com.google.common.testing.EqualsTester; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.contains; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.is; - -/** - * Unit tests for Constraint objects. - */ -public class ConstraintObjectsTest { - - // Bandwidth Constraint - - private final Bandwidth bandwidth1 = Bandwidth.bps(100.0); - private final Bandwidth sameAsBandwidth1 = Bandwidth.bps(100.0); - private final Bandwidth bandwidth2 = Bandwidth.bps(200.0); - - final BandwidthConstraint bandwidthConstraint1 = new BandwidthConstraint(bandwidth1); - final BandwidthConstraint bandwidthConstraintSameAs1 = new BandwidthConstraint(sameAsBandwidth1); - final BandwidthConstraint bandwidthConstraint2 = new BandwidthConstraint(bandwidth2); - - /** - * Checks that the objects were created properly. - */ - @Test - public void testBandwidthConstraintCreation() { - assertThat(bandwidthConstraint1.bandwidth().bps(), is(equalTo(100.0))); - assertThat(bandwidthConstraintSameAs1.bandwidth().bps(), is(equalTo(100.0))); - assertThat(bandwidthConstraint2.bandwidth().bps(), is(equalTo(200.0))); - } - - /** - * Checks the correctness of the equals() method. - */ - @Test - public void testBandwidthConstraintEquals() { - new EqualsTester() - .addEqualityGroup(bandwidthConstraint1, bandwidthConstraintSameAs1) - .addEqualityGroup(bandwidthConstraint2) - .testEquals(); - } - - // Lambda Constraint - - final LambdaConstraint lambdaConstraint1 = - new LambdaConstraint(new IndexedLambda(100)); - final LambdaConstraint lambdaConstraintSameAs1 = - new LambdaConstraint(new IndexedLambda(100)); - final LambdaConstraint lambdaConstraint2 = - new LambdaConstraint(new IndexedLambda(200)); - - /** - * Checks that the objects were created properly. - */ - @Test - public void testLambdaConstraintCreation() { - assertThat(lambdaConstraint1.lambda().index(), is(equalTo(100L))); - assertThat(lambdaConstraintSameAs1.lambda().index(), is(equalTo(100L))); - assertThat(lambdaConstraint2.lambda().index(), is(equalTo(200L))); - } - - /** - * Checks the correctness of the equals() method. - */ - @Test - public void testLambdaConstraintEquals() { - new EqualsTester() - .addEqualityGroup(lambdaConstraint1, lambdaConstraintSameAs1) - .addEqualityGroup(lambdaConstraint2) - .testEquals(); - } - - // LinkType Constraint - - final LinkTypeConstraint linkTypeConstraint1 = - new LinkTypeConstraint(true, Link.Type.OPTICAL, Link.Type.TUNNEL); - final LinkTypeConstraint linkTypeConstraintSameAs1 = - new LinkTypeConstraint(true, Link.Type.OPTICAL, Link.Type.TUNNEL); - final LinkTypeConstraint linkTypeConstraint2 = - new LinkTypeConstraint(true, Link.Type.OPTICAL, Link.Type.DIRECT); - - /** - * Checks that the objects were created properly. - */ - @Test - public void testLinkTypeConstraintCreation() { - assertThat(linkTypeConstraint1.isInclusive(), is(true)); - assertThat(linkTypeConstraint1.types(), - contains(Link.Type.OPTICAL, Link.Type.TUNNEL)); - assertThat(linkTypeConstraintSameAs1.isInclusive(), is(true)); - assertThat(linkTypeConstraintSameAs1.types(), - contains(Link.Type.OPTICAL, Link.Type.TUNNEL)); - assertThat(linkTypeConstraint2.isInclusive(), is(true)); - assertThat(linkTypeConstraint2.types(), - contains(Link.Type.OPTICAL, Link.Type.DIRECT)); - } - - /** - * Checks the correctness of the equals() method. - */ - @Test - public void testLinkTypeConstraintEquals() { - new EqualsTester() - .addEqualityGroup(linkTypeConstraint1, linkTypeConstraintSameAs1) - .addEqualityGroup(linkTypeConstraint2) - .testEquals(); - } -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/constraint/LatencyConstraintTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/constraint/LatencyConstraintTest.java deleted file mode 100644 index bab17495..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/constraint/LatencyConstraintTest.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * 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. - */ -package org.onosproject.net.intent.constraint; - -import com.google.common.testing.EqualsTester; -import org.junit.Before; -import org.junit.Test; -import org.onosproject.net.Annotations; -import org.onosproject.net.DefaultAnnotations; -import org.onosproject.net.DefaultLink; -import org.onosproject.net.DefaultPath; -import org.onosproject.net.DeviceId; -import org.onosproject.net.Link; -import org.onosproject.net.Path; -import org.onosproject.net.PortNumber; -import org.onosproject.net.provider.ProviderId; -import org.onosproject.net.resource.link.LinkResourceService; - -import java.time.Duration; -import java.time.temporal.ChronoUnit; -import java.util.Arrays; - -import static org.easymock.EasyMock.createMock; -import static org.hamcrest.Matchers.closeTo; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; -import static org.onosproject.net.AnnotationKeys.LATENCY; -import static org.onosproject.net.DefaultLinkTest.cp; -import static org.onosproject.net.DeviceId.deviceId; -import static org.onosproject.net.Link.Type.DIRECT; - -public class LatencyConstraintTest { - - private static final DeviceId DID1 = deviceId("of:1"); - private static final DeviceId DID2 = deviceId("of:2"); - private static final DeviceId DID3 = deviceId("of:3"); - private static final PortNumber PN1 = PortNumber.portNumber(1); - private static final PortNumber PN2 = PortNumber.portNumber(2); - private static final PortNumber PN3 = PortNumber.portNumber(3); - private static final PortNumber PN4 = PortNumber.portNumber(4); - private static final ProviderId PROVIDER_ID = new ProviderId("of", "foo"); - private static final String LATENCY1 = "3.0"; - private static final String LATENCY2 = "4.0"; - - private LatencyConstraint sut; - private LinkResourceService linkResourceService; - - private Path path; - private Link link1; - private Link link2; - - @Before - public void setUp() { - linkResourceService = createMock(LinkResourceService.class); - - Annotations annotations1 = DefaultAnnotations.builder().set(LATENCY, LATENCY1).build(); - Annotations annotations2 = DefaultAnnotations.builder().set(LATENCY, LATENCY2).build(); - - link1 = new DefaultLink(PROVIDER_ID, cp(DID1, PN1), cp(DID2, PN2), DIRECT, annotations1); - link2 = new DefaultLink(PROVIDER_ID, cp(DID2, PN3), cp(DID3, PN4), DIRECT, annotations2); - path = new DefaultPath(PROVIDER_ID, Arrays.asList(link1, link2), 10); - } - - /** - * Tests the path latency is less than the supplied constraint. - */ - @Test - public void testLessThanLatency() { - sut = new LatencyConstraint(Duration.of(10, ChronoUnit.MICROS)); - - assertThat(sut.validate(path, linkResourceService), is(true)); - } - - /** - * Tests the path latency is more than the supplied constraint. - */ - @Test - public void testMoreThanLatency() { - sut = new LatencyConstraint(Duration.of(3, ChronoUnit.MICROS)); - - assertThat(sut.validate(path, linkResourceService), is(false)); - } - - /** - * Tests the link latency is equal to "latency" annotated value. - */ - @Test - public void testCost() { - sut = new LatencyConstraint(Duration.of(10, ChronoUnit.MICROS)); - - assertThat(sut.cost(link1, linkResourceService), is(closeTo(Double.parseDouble(LATENCY1), 1.0e-6))); - assertThat(sut.cost(link2, linkResourceService), is(closeTo(Double.parseDouble(LATENCY2), 1.0e-6))); - } - - /** - * Tests equality of the instances. - */ - @Test - public void testEquality() { - LatencyConstraint c1 = new LatencyConstraint(Duration.of(1, ChronoUnit.SECONDS)); - LatencyConstraint c2 = new LatencyConstraint(Duration.of(1000, ChronoUnit.MILLIS)); - - LatencyConstraint c3 = new LatencyConstraint(Duration.of(2, ChronoUnit.SECONDS)); - LatencyConstraint c4 = new LatencyConstraint(Duration.of(2000, ChronoUnit.MILLIS)); - - new EqualsTester() - .addEqualityGroup(c1, c2) - .addEqualityGroup(c3, c4) - .testEquals(); - } -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/constraint/ObstacleConstraintTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/constraint/ObstacleConstraintTest.java deleted file mode 100644 index f02787f3..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/constraint/ObstacleConstraintTest.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * 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. - */ -package org.onosproject.net.intent.constraint; - -/** - * Test for constraint of intermediate nodes not passed. - */ -import com.google.common.testing.EqualsTester; -import org.junit.Before; -import org.junit.Test; -import org.onosproject.net.DefaultLink; -import org.onosproject.net.DefaultPath; -import org.onosproject.net.DeviceId; -import org.onosproject.net.Path; -import org.onosproject.net.PortNumber; -import org.onosproject.net.provider.ProviderId; -import org.onosproject.net.resource.link.LinkResourceService; - -import java.util.Arrays; - -import static org.easymock.EasyMock.createMock; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.*; -import static org.onosproject.net.DefaultLinkTest.cp; -import static org.onosproject.net.DeviceId.deviceId; -import static org.onosproject.net.Link.Type.DIRECT; - -public class ObstacleConstraintTest { - - private static final DeviceId DID1 = deviceId("of:1"); - private static final DeviceId DID2 = deviceId("of:2"); - private static final DeviceId DID3 = deviceId("of:3"); - private static final DeviceId DID4 = deviceId("of:4"); - private static final PortNumber PN1 = PortNumber.portNumber(1); - private static final PortNumber PN2 = PortNumber.portNumber(2); - private static final PortNumber PN3 = PortNumber.portNumber(3); - private static final PortNumber PN4 = PortNumber.portNumber(4); - private static final ProviderId PROVIDER_ID = new ProviderId("of", "foo"); - - private LinkResourceService linkResourceService; - - private Path path; - private DefaultLink link2; - private DefaultLink link1; - - private ObstacleConstraint sut; - - @Before - public void setUp() { - linkResourceService = createMock(LinkResourceService.class); - - link1 = new DefaultLink(PROVIDER_ID, cp(DID1, PN1), cp(DID2, PN2), DIRECT); - link2 = new DefaultLink(PROVIDER_ID, cp(DID2, PN3), cp(DID3, PN4), DIRECT); - path = new DefaultPath(PROVIDER_ID, Arrays.asList(link1, link2), 10); - } - - @Test - public void testEquality() { - ObstacleConstraint o1 = new ObstacleConstraint(DID1, DID2, DID3); - ObstacleConstraint o2 = new ObstacleConstraint(DID3, DID2, DID1); - ObstacleConstraint o3 = new ObstacleConstraint(DID1, DID2); - ObstacleConstraint o4 = new ObstacleConstraint(DID2, DID1); - - new EqualsTester() - .addEqualityGroup(o1, o2) - .addEqualityGroup(o3, o4) - .testEquals(); - } - - /** - * Tests the specified path avoids the specified obstacle. - */ - @Test - public void testPathNotThroughObstacles() { - sut = new ObstacleConstraint(DID4); - - assertThat(sut.validate(path, linkResourceService), is(true)); - } - - /** - * Test the specified path does not avoid the specified obstacle. - */ - @Test - public void testPathThroughObstacle() { - sut = new ObstacleConstraint(DID1); - - assertThat(sut.validate(path, linkResourceService), is(false)); - } -} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/constraint/WaypointConstraintTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/constraint/WaypointConstraintTest.java deleted file mode 100644 index f7e212a3..00000000 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/constraint/WaypointConstraintTest.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * 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. - */ -package org.onosproject.net.intent.constraint; - -import com.google.common.testing.EqualsTester; -import org.junit.Before; -import org.junit.Test; -import org.onosproject.net.DefaultLink; -import org.onosproject.net.DefaultPath; -import org.onosproject.net.DeviceId; -import org.onosproject.net.Path; -import org.onosproject.net.PortNumber; -import org.onosproject.net.intent.Constraint; -import org.onosproject.net.provider.ProviderId; -import org.onosproject.net.resource.link.LinkResourceService; - -import java.util.Arrays; - -import static org.easymock.EasyMock.createMock; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; -import static org.onosproject.net.DefaultLinkTest.cp; -import static org.onosproject.net.DeviceId.deviceId; -import static org.onosproject.net.Link.Type.DIRECT; - -/** - * Test for constraint of intermediate elements. - */ -public class WaypointConstraintTest { - - private static final DeviceId DID1 = deviceId("of:1"); - private static final DeviceId DID2 = deviceId("of:2"); - private static final DeviceId DID3 = deviceId("of:3"); - private static final DeviceId DID4 = deviceId("of:4"); - private static final PortNumber PN1 = PortNumber.portNumber(1); - private static final PortNumber PN2 = PortNumber.portNumber(2); - private static final PortNumber PN3 = PortNumber.portNumber(3); - private static final PortNumber PN4 = PortNumber.portNumber(4); - private static final ProviderId PROVIDER_ID = new ProviderId("of", "foo"); - - private WaypointConstraint sut; - private LinkResourceService linkResourceService; - - private Path path; - private DefaultLink link2; - private DefaultLink link1; - - @Before - public void setUp() { - linkResourceService = createMock(LinkResourceService.class); - - link1 = new DefaultLink(PROVIDER_ID, cp(DID1, PN1), cp(DID2, PN2), DIRECT); - link2 = new DefaultLink(PROVIDER_ID, cp(DID2, PN3), cp(DID3, PN4), DIRECT); - path = new DefaultPath(PROVIDER_ID, Arrays.asList(link1, link2), 10); - } - - /** - * Tests that all of the specified waypoints are included in the specified path in order. - */ - @Test - public void testSatisfyWaypoints() { - sut = new WaypointConstraint(DID1, DID2, DID3); - - assertThat(sut.validate(path, linkResourceService), is(true)); - } - - /** - * Tests that the specified path does not includes the specified waypoint. - */ - @Test - public void testNotSatisfyWaypoint() { - sut = new WaypointConstraint(DID4); - - assertThat(sut.validate(path, linkResourceService), is(false)); - } - - @Test - public void testEquality() { - Constraint c1 = new WaypointConstraint(DID1, DID2); - Constraint c2 = new WaypointConstraint(DID1, DID2); - - Constraint c3 = new WaypointConstraint(DID2); - Constraint c4 = new WaypointConstraint(DID3); - - new EqualsTester() - .addEqualityGroup(c1, c2) - .addEqualityGroup(c3) - .addEqualityGroup(c4) - .testEquals(); - } -} |