blob: 0f5c9b020ef41466953ded8d32bd05aa74cdfd0f [file] [log] [blame]
Sho SHIMIZU0e51fe52014-11-05 12:04:23 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present Open Networking Laboratory
Sho SHIMIZU0e51fe52014-11-05 12:04:23 -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 SHIMIZU0e51fe52014-11-05 12:04:23 -080017
Sho SHIMIZU14ccab52014-11-06 11:11:40 -080018import com.google.common.testing.EqualsTester;
Sho SHIMIZU0e51fe52014-11-05 12:04:23 -080019import org.junit.Before;
20import org.junit.Test;
Brian O'Connorabafb502014-12-02 22:26:20 -080021import org.onosproject.net.DefaultLink;
22import org.onosproject.net.DefaultPath;
23import org.onosproject.net.DeviceId;
24import org.onosproject.net.Path;
25import org.onosproject.net.PortNumber;
26import org.onosproject.net.intent.Constraint;
Sho SHIMIZUb1681bd2016-02-22 12:47:50 -080027import org.onosproject.net.intent.ResourceContext;
Brian O'Connorabafb502014-12-02 22:26:20 -080028import org.onosproject.net.provider.ProviderId;
Sho SHIMIZU0e51fe52014-11-05 12:04:23 -080029
30import java.util.Arrays;
31
32import static org.easymock.EasyMock.createMock;
33import static org.hamcrest.Matchers.is;
34import static org.junit.Assert.assertThat;
Brian O'Connorabafb502014-12-02 22:26:20 -080035import static org.onosproject.net.DefaultLinkTest.cp;
36import static org.onosproject.net.DeviceId.deviceId;
37import static org.onosproject.net.Link.Type.DIRECT;
Sho SHIMIZU0e51fe52014-11-05 12:04:23 -080038
39/**
40 * Test for constraint of intermediate elements.
41 */
42public class WaypointConstraintTest {
43
Sho SHIMIZU1332b172014-11-06 16:03:09 -080044 private static final DeviceId DID1 = deviceId("of:1");
45 private static final DeviceId DID2 = deviceId("of:2");
46 private static final DeviceId DID3 = deviceId("of:3");
47 private static final DeviceId DID4 = deviceId("of:4");
48 private static final PortNumber PN1 = PortNumber.portNumber(1);
49 private static final PortNumber PN2 = PortNumber.portNumber(2);
50 private static final PortNumber PN3 = PortNumber.portNumber(3);
51 private static final PortNumber PN4 = PortNumber.portNumber(4);
52 private static final ProviderId PROVIDER_ID = new ProviderId("of", "foo");
Sho SHIMIZU0e51fe52014-11-05 12:04:23 -080053
54 private WaypointConstraint sut;
Sho SHIMIZUb1681bd2016-02-22 12:47:50 -080055 private ResourceContext resourceContext;
Sho SHIMIZU0e51fe52014-11-05 12:04:23 -080056
57 private Path path;
58 private DefaultLink link2;
59 private DefaultLink link1;
60
61 @Before
62 public void setUp() {
Sho SHIMIZUb1681bd2016-02-22 12:47:50 -080063 resourceContext = createMock(ResourceContext.class);
Sho SHIMIZU0e51fe52014-11-05 12:04:23 -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();
77
Sho SHIMIZU0e51fe52014-11-05 12:04:23 -080078 path = new DefaultPath(PROVIDER_ID, Arrays.asList(link1, link2), 10);
79 }
80
81 /**
82 * Tests that all of the specified waypoints are included in the specified path in order.
83 */
84 @Test
85 public void testSatisfyWaypoints() {
86 sut = new WaypointConstraint(DID1, DID2, DID3);
87
Sho SHIMIZUb1681bd2016-02-22 12:47:50 -080088 assertThat(sut.validate(path, resourceContext), is(true));
Sho SHIMIZU0e51fe52014-11-05 12:04:23 -080089 }
90
91 /**
92 * Tests that the specified path does not includes the specified waypoint.
93 */
94 @Test
95 public void testNotSatisfyWaypoint() {
96 sut = new WaypointConstraint(DID4);
97
Sho SHIMIZUb1681bd2016-02-22 12:47:50 -080098 assertThat(sut.validate(path, resourceContext), is(false));
Sho SHIMIZU0e51fe52014-11-05 12:04:23 -080099 }
Sho SHIMIZU14ccab52014-11-06 11:11:40 -0800100
101 @Test
102 public void testEquality() {
103 Constraint c1 = new WaypointConstraint(DID1, DID2);
104 Constraint c2 = new WaypointConstraint(DID1, DID2);
105
106 Constraint c3 = new WaypointConstraint(DID2);
107 Constraint c4 = new WaypointConstraint(DID3);
108
109 new EqualsTester()
110 .addEqualityGroup(c1, c2)
111 .addEqualityGroup(c3)
112 .addEqualityGroup(c4)
113 .testEquals();
114 }
Sho SHIMIZU0e51fe52014-11-05 12:04:23 -0800115}