blob: 2149b26f2e41f1825c6aca4212b5ab08eaa2556e [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'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.intent;
Brian O'Connorf3d06162014-10-02 15:54:12 -070017
Ray Milkeyebc5d222015-03-18 15:45:36 -070018import java.util.Arrays;
19
Brian O'Connorf3d06162014-10-02 15:54:12 -070020import org.junit.Test;
Brian O'Connorabafb502014-12-02 22:26:20 -080021import org.onosproject.net.ConnectPoint;
22import org.onosproject.net.DefaultLink;
23import org.onosproject.net.DefaultPath;
24import org.onosproject.net.DeviceId;
25import org.onosproject.net.NetTestTools;
26import org.onosproject.net.Path;
27import org.onosproject.net.PortNumber;
28import org.onosproject.net.provider.ProviderId;
Sho SHIMIZU3908fde2014-11-19 16:30:22 -080029
Ray Milkeycaa450b2014-10-29 15:54:24 -070030import static org.junit.Assert.assertEquals;
Brian O'Connorabafb502014-12-02 22:26:20 -080031import static org.onosproject.net.DeviceId.deviceId;
32import static org.onosproject.net.Link.Type.DIRECT;
33import static org.onosproject.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() {
Ray Milkeyebc5d222015-03-18 15:45:36 -070068 return PathIntent.builder()
69 .appId(APPID)
70 .selector(MATCH)
71 .treatment(NOP)
72 .path(PATH1)
73 .build();
Brian O'Connorf3d06162014-10-02 15:54:12 -070074 }
75
76 @Override
77 protected PathIntent createAnother() {
Ray Milkeyebc5d222015-03-18 15:45:36 -070078 return PathIntent.builder()
79 .appId(APPID)
80 .selector(MATCH)
81 .treatment(NOP)
82 .path(PATH2)
83 .build();
Brian O'Connorf3d06162014-10-02 15:54:12 -070084 }
Sho SHIMIZU3908fde2014-11-19 16:30:22 -080085
86 /**
87 * Tests the constructor raises IllegalArgumentException when the same device is specified in
88 * source and destination of a link.
89 */
90 @Test(expected = IllegalArgumentException.class)
91 public void testRaiseExceptionWhenSameDevices() {
Ray Milkeyebc5d222015-03-18 15:45:36 -070092 PathIntent.builder()
93 .appId(APPID)
94 .selector(MATCH)
95 .treatment(NOP)
96 .path(new DefaultPath(provider1, Arrays.asList(link1), cost))
97 .build();
Sho SHIMIZU3908fde2014-11-19 16:30:22 -080098 }
99
100 /**
101 * Tests the constructor raises IllegalArgumentException when the different elements are specified
102 * in source element of the first link and destination element of the second link.
103 */
104 @Test(expected = IllegalArgumentException.class)
105 public void testRaiseExceptionWhenDifferentDevice() {
Ray Milkeyebc5d222015-03-18 15:45:36 -0700106 PathIntent.builder()
107 .appId(APPID)
108 .selector(MATCH)
109 .treatment(NOP)
110 .path(new DefaultPath(provider1, Arrays.asList(link1, link2), cost))
111 .build();
Sho SHIMIZU3908fde2014-11-19 16:30:22 -0800112 }
113
Brian O'Connorf3d06162014-10-02 15:54:12 -0700114}