blob: dd438c57e52c1d9a11c20dafd7d81b962f30ceee [file] [log] [blame]
Sho SHIMIZU075268b2014-11-05 15:16:32 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present Open Networking Laboratory
Sho SHIMIZU075268b2014-11-05 15:16:32 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.intent.constraint;
Sho SHIMIZU075268b2014-11-05 15:16:32 -080017
18/**
19 * Test for constraint of intermediate nodes not passed.
20 */
21import com.google.common.testing.EqualsTester;
22import org.junit.Before;
23import org.junit.Test;
Brian O'Connorabafb502014-12-02 22:26:20 -080024import org.onosproject.net.DefaultLink;
25import org.onosproject.net.DefaultPath;
26import org.onosproject.net.DeviceId;
27import org.onosproject.net.Path;
28import org.onosproject.net.PortNumber;
Sho SHIMIZUb1681bd2016-02-22 12:47:50 -080029import org.onosproject.net.intent.ResourceContext;
Brian O'Connorabafb502014-12-02 22:26:20 -080030import org.onosproject.net.provider.ProviderId;
Sho SHIMIZU075268b2014-11-05 15:16:32 -080031
32import java.util.Arrays;
33
34import static org.easymock.EasyMock.createMock;
35import static org.hamcrest.Matchers.is;
36import static org.junit.Assert.*;
Brian O'Connorabafb502014-12-02 22:26:20 -080037import static org.onosproject.net.DefaultLinkTest.cp;
38import static org.onosproject.net.DeviceId.deviceId;
39import static org.onosproject.net.Link.Type.DIRECT;
Sho SHIMIZU075268b2014-11-05 15:16:32 -080040
41public class ObstacleConstraintTest {
42
43 private static final DeviceId DID1 = deviceId("of:1");
44 private static final DeviceId DID2 = deviceId("of:2");
45 private static final DeviceId DID3 = deviceId("of:3");
46 private static final DeviceId DID4 = deviceId("of:4");
47 private static final PortNumber PN1 = PortNumber.portNumber(1);
48 private static final PortNumber PN2 = PortNumber.portNumber(2);
49 private static final PortNumber PN3 = PortNumber.portNumber(3);
50 private static final PortNumber PN4 = PortNumber.portNumber(4);
51 private static final ProviderId PROVIDER_ID = new ProviderId("of", "foo");
52
Sho SHIMIZUb1681bd2016-02-22 12:47:50 -080053 private ResourceContext resourceContext;
Sho SHIMIZU075268b2014-11-05 15:16:32 -080054
55 private Path path;
56 private DefaultLink link2;
57 private DefaultLink link1;
58
59 private ObstacleConstraint sut;
60
61 @Before
62 public void setUp() {
Sho SHIMIZUb1681bd2016-02-22 12:47:50 -080063 resourceContext = createMock(ResourceContext.class);
Sho SHIMIZU075268b2014-11-05 15:16:32 -080064
Ray Milkey2693bda2016-01-22 16:08:14 -080065 link1 = DefaultLink.builder()
66 .providerId(PROVIDER_ID)
67 .src(cp(DID1, PN1))
68 .dst(cp(DID2, PN2))
69 .type(DIRECT)
70 .build();
71 link2 = DefaultLink.builder()
72 .providerId(PROVIDER_ID)
73 .src(cp(DID2, PN3))
74 .dst(cp(DID3, PN4))
75 .type(DIRECT)
76 .build();
Sho SHIMIZU075268b2014-11-05 15:16:32 -080077 path = new DefaultPath(PROVIDER_ID, Arrays.asList(link1, link2), 10);
78 }
79
80 @Test
81 public void testEquality() {
82 ObstacleConstraint o1 = new ObstacleConstraint(DID1, DID2, DID3);
83 ObstacleConstraint o2 = new ObstacleConstraint(DID3, DID2, DID1);
84 ObstacleConstraint o3 = new ObstacleConstraint(DID1, DID2);
85 ObstacleConstraint o4 = new ObstacleConstraint(DID2, DID1);
86
87 new EqualsTester()
88 .addEqualityGroup(o1, o2)
89 .addEqualityGroup(o3, o4)
90 .testEquals();
91 }
92
93 /**
94 * Tests the specified path avoids the specified obstacle.
95 */
96 @Test
97 public void testPathNotThroughObstacles() {
98 sut = new ObstacleConstraint(DID4);
99
Sho SHIMIZUb1681bd2016-02-22 12:47:50 -0800100 assertThat(sut.validate(path, resourceContext), is(true));
Sho SHIMIZU075268b2014-11-05 15:16:32 -0800101 }
102
103 /**
104 * Test the specified path does not avoid the specified obstacle.
105 */
106 @Test
107 public void testPathThroughObstacle() {
108 sut = new ObstacleConstraint(DID1);
109
Sho SHIMIZUb1681bd2016-02-22 12:47:50 -0800110 assertThat(sut.validate(path, resourceContext), is(false));
Sho SHIMIZU075268b2014-11-05 15:16:32 -0800111 }
112}