blob: da13af06303075f5c076c3db1df94b7ae0b07a57 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present Open Networking Laboratory
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07003 *
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;
Sho SHIMIZU98ffca82015-05-11 08:39:24 -070019import java.util.Collections;
Ray Milkeyebc5d222015-03-18 15:45:36 -070020
Brian O'Connorf3d06162014-10-02 15:54:12 -070021import org.junit.Test;
Brian O'Connorabafb502014-12-02 22:26:20 -080022import org.onosproject.net.ConnectPoint;
23import org.onosproject.net.DefaultLink;
24import org.onosproject.net.DefaultPath;
25import org.onosproject.net.DeviceId;
26import org.onosproject.net.NetTestTools;
27import org.onosproject.net.Path;
28import org.onosproject.net.PortNumber;
29import org.onosproject.net.provider.ProviderId;
Sho SHIMIZU3908fde2014-11-19 16:30:22 -080030
Ray Milkeycaa450b2014-10-29 15:54:24 -070031import static org.junit.Assert.assertEquals;
Brian O'Connorabafb502014-12-02 22:26:20 -080032import static org.onosproject.net.DeviceId.deviceId;
33import static org.onosproject.net.Link.Type.DIRECT;
34import static org.onosproject.net.PortNumber.portNumber;
Brian O'Connorf3d06162014-10-02 15:54:12 -070035
36public class PathIntentTest extends ConnectivityIntentTest {
37 // 111:11 --> 222:22
38 private static final Path PATH1 = NetTestTools.createPath("111", "222");
39
40 // 111:11 --> 333:33
41 private static final Path PATH2 = NetTestTools.createPath("222", "333");
42
Sho SHIMIZU3908fde2014-11-19 16:30:22 -080043 private final ProviderId provider1 = new ProviderId("of", "1");
44 private final DeviceId device1 = deviceId("1");
45 private final DeviceId device2 = deviceId("2");
46 private final PortNumber port1 = portNumber(1);
47 private final PortNumber port2 = portNumber(2);
48 private final PortNumber port3 = portNumber(3);
49 private final PortNumber port4 = portNumber(4);
50 private final ConnectPoint cp1 = new ConnectPoint(device1, port1);
51 private final ConnectPoint cp2 = new ConnectPoint(device1, port2);
52 private final ConnectPoint cp3 = new ConnectPoint(device2, port3);
53 private final ConnectPoint cp4 = new ConnectPoint(device2, port4);
Ray Milkey2693bda2016-01-22 16:08:14 -080054 private final DefaultLink link1 = DefaultLink.builder()
55 .providerId(provider1)
56 .src(cp1)
57 .dst(cp2)
58 .type(DIRECT)
59 .build();
60 private final DefaultLink link2 = DefaultLink.builder()
61 .providerId(provider1)
62 .src(cp1)
63 .dst(cp2)
64 .type(DIRECT)
65 .build();
Sho SHIMIZU3908fde2014-11-19 16:30:22 -080066 private final double cost = 1;
67
Brian O'Connorf3d06162014-10-02 15:54:12 -070068 @Test
69 public void basics() {
70 PathIntent intent = createOne();
Thomas Vachuskac96058a2014-10-20 23:00:16 -070071 assertEquals("incorrect id", APPID, intent.appId());
tom85258ee2014-10-07 00:10:02 -070072 assertEquals("incorrect match", MATCH, intent.selector());
73 assertEquals("incorrect action", NOP, intent.treatment());
tom85258ee2014-10-07 00:10:02 -070074 assertEquals("incorrect path", PATH1, intent.path());
ilhem fajjarib0a06842015-11-02 18:59:02 +010075 assertEquals("incorrect key", KEY, intent.key());
Luca Prete670ac5d2017-02-03 15:55:43 -080076
77 intent = createAnother();
78 assertEquals("incorrect id", APPID, intent.appId());
79 assertEquals("incorrect match", MATCH, intent.selector());
80 assertEquals("incorrect action", NOP, intent.treatment());
81 assertEquals("incorrect path", PATH2, intent.path());
82 assertEquals("incorrect key", KEY, intent.key());
83
84 intent = createWithResourceGroup();
85 assertEquals("incorrect id", APPID, intent.appId());
86 assertEquals("incorrect match", MATCH, intent.selector());
87 assertEquals("incorrect action", NOP, intent.treatment());
88 assertEquals("incorrect path", PATH2, intent.path());
89 assertEquals("incorrect key", KEY, intent.key());
90 assertEquals("incorrect resource group", RESOURCE_GROUP, intent.resourceGroup());
Brian O'Connorf3d06162014-10-02 15:54:12 -070091 }
92
93 @Override
94 protected PathIntent createOne() {
Ray Milkeyebc5d222015-03-18 15:45:36 -070095 return PathIntent.builder()
96 .appId(APPID)
ilhem fajjarib0a06842015-11-02 18:59:02 +010097 .key(KEY)
Ray Milkeyebc5d222015-03-18 15:45:36 -070098 .selector(MATCH)
99 .treatment(NOP)
100 .path(PATH1)
101 .build();
Brian O'Connorf3d06162014-10-02 15:54:12 -0700102 }
103
104 @Override
105 protected PathIntent createAnother() {
Ray Milkeyebc5d222015-03-18 15:45:36 -0700106 return PathIntent.builder()
107 .appId(APPID)
Luca Prete670ac5d2017-02-03 15:55:43 -0800108 .key(KEY)
Ray Milkeyebc5d222015-03-18 15:45:36 -0700109 .selector(MATCH)
110 .treatment(NOP)
111 .path(PATH2)
112 .build();
Brian O'Connorf3d06162014-10-02 15:54:12 -0700113 }
Sho SHIMIZU3908fde2014-11-19 16:30:22 -0800114
Luca Prete670ac5d2017-02-03 15:55:43 -0800115 protected PathIntent createWithResourceGroup() {
116 return PathIntent.builder()
117 .appId(APPID)
118 .key(KEY)
119 .selector(MATCH)
120 .treatment(NOP)
121 .path(PATH2)
122 .resourceGroup(RESOURCE_GROUP)
123 .build();
124 }
125
Sho SHIMIZU3908fde2014-11-19 16:30:22 -0800126 /**
127 * Tests the constructor raises IllegalArgumentException when the same device is specified in
128 * source and destination of a link.
129 */
130 @Test(expected = IllegalArgumentException.class)
131 public void testRaiseExceptionWhenSameDevices() {
Ray Milkeyebc5d222015-03-18 15:45:36 -0700132 PathIntent.builder()
133 .appId(APPID)
134 .selector(MATCH)
135 .treatment(NOP)
Sho SHIMIZU98ffca82015-05-11 08:39:24 -0700136 .path(new DefaultPath(provider1, Collections.singletonList(link1), cost))
Ray Milkeyebc5d222015-03-18 15:45:36 -0700137 .build();
Sho SHIMIZU3908fde2014-11-19 16:30:22 -0800138 }
139
140 /**
141 * Tests the constructor raises IllegalArgumentException when the different elements are specified
142 * in source element of the first link and destination element of the second link.
143 */
144 @Test(expected = IllegalArgumentException.class)
145 public void testRaiseExceptionWhenDifferentDevice() {
Ray Milkeyebc5d222015-03-18 15:45:36 -0700146 PathIntent.builder()
147 .appId(APPID)
148 .selector(MATCH)
149 .treatment(NOP)
150 .path(new DefaultPath(provider1, Arrays.asList(link1, link2), cost))
151 .build();
Sho SHIMIZU3908fde2014-11-19 16:30:22 -0800152 }
153
Brian O'Connorf3d06162014-10-02 15:54:12 -0700154}