blob: 4451e66e7eef9d924bb091aa754651e6b513cbaa [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
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 */
Brian O'Connorf3d06162014-10-02 15:54:12 -070016package org.onlab.onos.net.intent;
17
Brian O'Connorf3d06162014-10-02 15:54:12 -070018import org.junit.Test;
Sho SHIMIZU3908fde2014-11-19 16:30:22 -080019import org.onlab.onos.net.ConnectPoint;
20import org.onlab.onos.net.DefaultLink;
21import org.onlab.onos.net.DefaultPath;
22import org.onlab.onos.net.DeviceId;
Brian O'Connorf3d06162014-10-02 15:54:12 -070023import org.onlab.onos.net.NetTestTools;
24import org.onlab.onos.net.Path;
Sho SHIMIZU3908fde2014-11-19 16:30:22 -080025import org.onlab.onos.net.PortNumber;
26import org.onlab.onos.net.provider.ProviderId;
27
28import java.util.Arrays;
Ray Milkeycaa450b2014-10-29 15:54:24 -070029
30import static org.junit.Assert.assertEquals;
Sho SHIMIZU3908fde2014-11-19 16:30:22 -080031import static org.onlab.onos.net.DeviceId.deviceId;
32import static org.onlab.onos.net.Link.Type.DIRECT;
33import static org.onlab.onos.net.PortNumber.portNumber;
Brian O'Connorf3d06162014-10-02 15:54:12 -070034
35public class PathIntentTest extends ConnectivityIntentTest {
36 // 111:11 --> 222:22
37 private static final Path PATH1 = NetTestTools.createPath("111", "222");
38
39 // 111:11 --> 333:33
40 private static final Path PATH2 = NetTestTools.createPath("222", "333");
41
Sho SHIMIZU3908fde2014-11-19 16:30:22 -080042 private final ProviderId provider1 = new ProviderId("of", "1");
43 private final DeviceId device1 = deviceId("1");
44 private final DeviceId device2 = deviceId("2");
45 private final PortNumber port1 = portNumber(1);
46 private final PortNumber port2 = portNumber(2);
47 private final PortNumber port3 = portNumber(3);
48 private final PortNumber port4 = portNumber(4);
49 private final ConnectPoint cp1 = new ConnectPoint(device1, port1);
50 private final ConnectPoint cp2 = new ConnectPoint(device1, port2);
51 private final ConnectPoint cp3 = new ConnectPoint(device2, port3);
52 private final ConnectPoint cp4 = new ConnectPoint(device2, port4);
53 private final DefaultLink link1 = new DefaultLink(provider1, cp1, cp2, DIRECT);
54 private final DefaultLink link2 = new DefaultLink(provider1, cp1, cp2, DIRECT);
55 private final double cost = 1;
56
Brian O'Connorf3d06162014-10-02 15:54:12 -070057 @Test
58 public void basics() {
59 PathIntent intent = createOne();
Thomas Vachuskac96058a2014-10-20 23:00:16 -070060 assertEquals("incorrect id", APPID, intent.appId());
tom85258ee2014-10-07 00:10:02 -070061 assertEquals("incorrect match", MATCH, intent.selector());
62 assertEquals("incorrect action", NOP, intent.treatment());
tom85258ee2014-10-07 00:10:02 -070063 assertEquals("incorrect path", PATH1, intent.path());
Brian O'Connorf3d06162014-10-02 15:54:12 -070064 }
65
66 @Override
67 protected PathIntent createOne() {
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080068 return new PathIntent(APPID, MATCH, NOP, PATH1);
Brian O'Connorf3d06162014-10-02 15:54:12 -070069 }
70
71 @Override
72 protected PathIntent createAnother() {
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080073 return new PathIntent(APPID, MATCH, NOP, PATH2);
Brian O'Connorf3d06162014-10-02 15:54:12 -070074 }
Sho SHIMIZU3908fde2014-11-19 16:30:22 -080075
76 /**
77 * Tests the constructor raises IllegalArgumentException when the same device is specified in
78 * source and destination of a link.
79 */
80 @Test(expected = IllegalArgumentException.class)
81 public void testRaiseExceptionWhenSameDevices() {
82 new PathIntent(APPID, MATCH, NOP, new DefaultPath(provider1, Arrays.asList(link1), cost));
83 }
84
85 /**
86 * Tests the constructor raises IllegalArgumentException when the different elements are specified
87 * in source element of the first link and destination element of the second link.
88 */
89 @Test(expected = IllegalArgumentException.class)
90 public void testRaiseExceptionWhenDifferentDevice() {
91 new PathIntent(APPID, MATCH, NOP, new DefaultPath(provider1, Arrays.asList(link1, link2), cost));
92 }
93
Brian O'Connorf3d06162014-10-02 15:54:12 -070094}