blob: 65b525bc8263d620f245729ce828cfbb038d01d7 [file] [log] [blame]
Sho SHIMIZU075268b2014-11-05 15:16:32 -08001/*
2 * Copyright 2014 Open Networking Laboratory
3 *
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 */
16package org.onlab.onos.net.intent.constraint;
17
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;
24import org.onlab.onos.net.DefaultLink;
25import org.onlab.onos.net.DefaultPath;
26import org.onlab.onos.net.DeviceId;
27import org.onlab.onos.net.Path;
28import org.onlab.onos.net.PortNumber;
29import org.onlab.onos.net.provider.ProviderId;
30import org.onlab.onos.net.resource.LinkResourceService;
31
32import java.util.Arrays;
33
34import static org.easymock.EasyMock.createMock;
35import static org.hamcrest.Matchers.is;
36import static org.junit.Assert.*;
37import static org.onlab.onos.net.DefaultLinkTest.cp;
38import static org.onlab.onos.net.DeviceId.deviceId;
39import static org.onlab.onos.net.Link.Type.DIRECT;
40
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
53 private LinkResourceService linkResourceService;
54
55 private Path path;
56 private DefaultLink link2;
57 private DefaultLink link1;
58
59 private ObstacleConstraint sut;
60
61 @Before
62 public void setUp() {
63 linkResourceService = createMock(LinkResourceService.class);
64
65 link1 = new DefaultLink(PROVIDER_ID, cp(DID1, PN1), cp(DID2, PN2), DIRECT);
66 link2 = new DefaultLink(PROVIDER_ID, cp(DID2, PN3), cp(DID3, PN4), DIRECT);
67 path = new DefaultPath(PROVIDER_ID, Arrays.asList(link1, link2), 10);
68 }
69
70 @Test
71 public void testEquality() {
72 ObstacleConstraint o1 = new ObstacleConstraint(DID1, DID2, DID3);
73 ObstacleConstraint o2 = new ObstacleConstraint(DID3, DID2, DID1);
74 ObstacleConstraint o3 = new ObstacleConstraint(DID1, DID2);
75 ObstacleConstraint o4 = new ObstacleConstraint(DID2, DID1);
76
77 new EqualsTester()
78 .addEqualityGroup(o1, o2)
79 .addEqualityGroup(o3, o4)
80 .testEquals();
81 }
82
83 /**
84 * Tests the specified path avoids the specified obstacle.
85 */
86 @Test
87 public void testPathNotThroughObstacles() {
88 sut = new ObstacleConstraint(DID4);
89
90 assertThat(sut.validate(path, linkResourceService), is(true));
91 }
92
93 /**
94 * Test the specified path does not avoid the specified obstacle.
95 */
96 @Test
97 public void testPathThroughObstacle() {
98 sut = new ObstacleConstraint(DID1);
99
100 assertThat(sut.validate(path, linkResourceService), is(false));
101 }
102}