blob: ec1fc1a8944a5abc7bf1a9af626e42896d799c0a [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2014-present Open Networking Foundation
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;
Ray Milkeya7cf8c82018-02-08 15:07:06 -080022import org.onlab.graph.ScalarWeight;
Brian O'Connorabafb502014-12-02 22:26:20 -080023import org.onosproject.net.ConnectPoint;
24import org.onosproject.net.DefaultLink;
25import org.onosproject.net.DefaultPath;
26import org.onosproject.net.DeviceId;
27import org.onosproject.net.NetTestTools;
28import org.onosproject.net.Path;
29import org.onosproject.net.PortNumber;
30import org.onosproject.net.provider.ProviderId;
Sho SHIMIZU3908fde2014-11-19 16:30:22 -080031
Ray Milkeycaa450b2014-10-29 15:54:24 -070032import static org.junit.Assert.assertEquals;
Brian O'Connorabafb502014-12-02 22:26:20 -080033import static org.onosproject.net.DeviceId.deviceId;
34import static org.onosproject.net.Link.Type.DIRECT;
35import static org.onosproject.net.PortNumber.portNumber;
Brian O'Connorf3d06162014-10-02 15:54:12 -070036
37public class PathIntentTest extends ConnectivityIntentTest {
38 // 111:11 --> 222:22
39 private static final Path PATH1 = NetTestTools.createPath("111", "222");
40
41 // 111:11 --> 333:33
42 private static final Path PATH2 = NetTestTools.createPath("222", "333");
43
Sho SHIMIZU3908fde2014-11-19 16:30:22 -080044 private final ProviderId provider1 = new ProviderId("of", "1");
45 private final DeviceId device1 = deviceId("1");
46 private final DeviceId device2 = deviceId("2");
47 private final PortNumber port1 = portNumber(1);
48 private final PortNumber port2 = portNumber(2);
49 private final PortNumber port3 = portNumber(3);
50 private final PortNumber port4 = portNumber(4);
51 private final ConnectPoint cp1 = new ConnectPoint(device1, port1);
52 private final ConnectPoint cp2 = new ConnectPoint(device1, port2);
53 private final ConnectPoint cp3 = new ConnectPoint(device2, port3);
54 private final ConnectPoint cp4 = new ConnectPoint(device2, port4);
Ray Milkey2693bda2016-01-22 16:08:14 -080055 private final DefaultLink link1 = DefaultLink.builder()
56 .providerId(provider1)
57 .src(cp1)
58 .dst(cp2)
59 .type(DIRECT)
60 .build();
61 private final DefaultLink link2 = DefaultLink.builder()
62 .providerId(provider1)
63 .src(cp1)
64 .dst(cp2)
65 .type(DIRECT)
66 .build();
Sho SHIMIZU3908fde2014-11-19 16:30:22 -080067 private final double cost = 1;
68
Brian O'Connorf3d06162014-10-02 15:54:12 -070069 @Test
70 public void basics() {
71 PathIntent intent = createOne();
Thomas Vachuskac96058a2014-10-20 23:00:16 -070072 assertEquals("incorrect id", APPID, intent.appId());
tom85258ee2014-10-07 00:10:02 -070073 assertEquals("incorrect match", MATCH, intent.selector());
74 assertEquals("incorrect action", NOP, intent.treatment());
tom85258ee2014-10-07 00:10:02 -070075 assertEquals("incorrect path", PATH1, intent.path());
ilhem fajjarib0a06842015-11-02 18:59:02 +010076 assertEquals("incorrect key", KEY, intent.key());
Luca Prete670ac5d2017-02-03 15:55:43 -080077
78 intent = createAnother();
79 assertEquals("incorrect id", APPID, intent.appId());
80 assertEquals("incorrect match", MATCH, intent.selector());
81 assertEquals("incorrect action", NOP, intent.treatment());
82 assertEquals("incorrect path", PATH2, intent.path());
83 assertEquals("incorrect key", KEY, intent.key());
84
85 intent = createWithResourceGroup();
86 assertEquals("incorrect id", APPID, intent.appId());
87 assertEquals("incorrect match", MATCH, intent.selector());
88 assertEquals("incorrect action", NOP, intent.treatment());
89 assertEquals("incorrect path", PATH2, intent.path());
90 assertEquals("incorrect key", KEY, intent.key());
91 assertEquals("incorrect resource group", RESOURCE_GROUP, intent.resourceGroup());
Brian O'Connorf3d06162014-10-02 15:54:12 -070092 }
93
94 @Override
95 protected PathIntent createOne() {
Ray Milkeyebc5d222015-03-18 15:45:36 -070096 return PathIntent.builder()
97 .appId(APPID)
ilhem fajjarib0a06842015-11-02 18:59:02 +010098 .key(KEY)
Ray Milkeyebc5d222015-03-18 15:45:36 -070099 .selector(MATCH)
100 .treatment(NOP)
101 .path(PATH1)
102 .build();
Brian O'Connorf3d06162014-10-02 15:54:12 -0700103 }
104
105 @Override
106 protected PathIntent createAnother() {
Ray Milkeyebc5d222015-03-18 15:45:36 -0700107 return PathIntent.builder()
108 .appId(APPID)
Luca Prete670ac5d2017-02-03 15:55:43 -0800109 .key(KEY)
Ray Milkeyebc5d222015-03-18 15:45:36 -0700110 .selector(MATCH)
111 .treatment(NOP)
112 .path(PATH2)
113 .build();
Brian O'Connorf3d06162014-10-02 15:54:12 -0700114 }
Sho SHIMIZU3908fde2014-11-19 16:30:22 -0800115
Luca Prete670ac5d2017-02-03 15:55:43 -0800116 protected PathIntent createWithResourceGroup() {
117 return PathIntent.builder()
118 .appId(APPID)
119 .key(KEY)
120 .selector(MATCH)
121 .treatment(NOP)
122 .path(PATH2)
123 .resourceGroup(RESOURCE_GROUP)
124 .build();
125 }
126
Sho SHIMIZU3908fde2014-11-19 16:30:22 -0800127 /**
128 * Tests the constructor raises IllegalArgumentException when the same device is specified in
129 * source and destination of a link.
130 */
131 @Test(expected = IllegalArgumentException.class)
132 public void testRaiseExceptionWhenSameDevices() {
Ray Milkeyebc5d222015-03-18 15:45:36 -0700133 PathIntent.builder()
134 .appId(APPID)
135 .selector(MATCH)
136 .treatment(NOP)
Ray Milkeya7cf8c82018-02-08 15:07:06 -0800137 .path(new DefaultPath(provider1, Collections.singletonList(link1), ScalarWeight.toWeight(cost)))
Ray Milkeyebc5d222015-03-18 15:45:36 -0700138 .build();
Sho SHIMIZU3908fde2014-11-19 16:30:22 -0800139 }
140
141 /**
142 * Tests the constructor raises IllegalArgumentException when the different elements are specified
143 * in source element of the first link and destination element of the second link.
144 */
145 @Test(expected = IllegalArgumentException.class)
146 public void testRaiseExceptionWhenDifferentDevice() {
Ray Milkeyebc5d222015-03-18 15:45:36 -0700147 PathIntent.builder()
148 .appId(APPID)
149 .selector(MATCH)
150 .treatment(NOP)
Ray Milkeya7cf8c82018-02-08 15:07:06 -0800151 .path(new DefaultPath(provider1, Arrays.asList(link1, link2), ScalarWeight.toWeight(cost)))
Ray Milkeyebc5d222015-03-18 15:45:36 -0700152 .build();
Sho SHIMIZU3908fde2014-11-19 16:30:22 -0800153 }
154
Brian O'Connorf3d06162014-10-02 15:54:12 -0700155}