blob: c0257c0f384a08ed0908752f825957210787dbe5 [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
18import org.junit.Test;
Ray Milkeya2cf3a12018-02-15 16:13:56 -080019import org.onosproject.net.FilteredConnectPoint;
Daniele Moro3a6e1512017-12-22 12:14:44 +010020import org.onosproject.net.Link;
Brian O'Connorf3d06162014-10-02 15:54:12 -070021
Daniele Moro3a6e1512017-12-22 12:14:44 +010022import java.util.LinkedList;
23import java.util.List;
24
25import static org.hamcrest.MatcherAssert.assertThat;
26import static org.hamcrest.Matchers.containsString;
Brian O'Connorf3d06162014-10-02 15:54:12 -070027import static org.junit.Assert.assertEquals;
Daniele Moro3a6e1512017-12-22 12:14:44 +010028import static org.junit.Assert.fail;
Ray Milkey37f6a382014-11-25 14:54:42 -080029import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutableBaseClass;
Brian O'Connorf3d06162014-10-02 15:54:12 -070030
31/**
32 * Suite of tests of the point-to-point intent descriptor.
33 */
34public class PointToPointIntentTest extends ConnectivityIntentTest {
35
Ray Milkey37f6a382014-11-25 14:54:42 -080036 /**
helenyrwu2a674902016-07-20 09:48:04 -070037 * Checks that the PointToPointIntent class is immutable.
Ray Milkey37f6a382014-11-25 14:54:42 -080038 */
39 @Test
40 public void checkImmutability() {
41 assertThatClassIsImmutableBaseClass(PointToPointIntent.class);
42 }
43
Brian O'Connorf3d06162014-10-02 15:54:12 -070044 @Test
45 public void basics() {
46 PointToPointIntent intent = createOne();
Thomas Vachuskac96058a2014-10-20 23:00:16 -070047 assertEquals("incorrect id", APPID, intent.appId());
tom85258ee2014-10-07 00:10:02 -070048 assertEquals("incorrect match", MATCH, intent.selector());
Ray Milkeya2cf3a12018-02-15 16:13:56 -080049 assertEquals("incorrect ingress", P1, intent.filteredIngressPoint().connectPoint());
50 assertEquals("incorrect egress", P2, intent.filteredEgressPoint().connectPoint());
Luca Prete670ac5d2017-02-03 15:55:43 -080051
52 intent = createWithResourceGroup();
53 assertEquals("incorrect id", APPID, intent.appId());
54 assertEquals("incorrect match", MATCH, intent.selector());
Ray Milkeya2cf3a12018-02-15 16:13:56 -080055 assertEquals("incorrect ingress", P1, intent.filteredIngressPoint().connectPoint());
56 assertEquals("incorrect egress", P2, intent.filteredEgressPoint().connectPoint());
Luca Prete670ac5d2017-02-03 15:55:43 -080057 assertEquals("incorrect resource group", RESOURCE_GROUP, intent.resourceGroup());
Brian O'Connorf3d06162014-10-02 15:54:12 -070058 }
59
Pier Ventreffe88d62016-10-13 14:34:40 -070060 @Test
61 public void filtered() {
62 PointToPointIntent intent = createOneFiltered();
63 assertEquals("incorrect id", APPID, intent.appId());
64 assertEquals("incorrect match", MATCH, intent.selector());
65 assertEquals("incorrect ingress", FP1, intent.filteredIngressPoint());
66 assertEquals("incorrect egress", FP2, intent.filteredEgressPoint());
67 }
68
Daniele Moro3a6e1512017-12-22 12:14:44 +010069 @Test
70 public void suggestedPath() {
71 List<Link> suggestedPath = new LinkedList<>();
72 suggestedPath.add(new IntentTestsMocks.FakeLink(FP1.connectPoint(), FP2.connectPoint()));
73
74 PointToPointIntent intent = createWithSuggestedPath(suggestedPath);
75 assertEquals("incorrect id", APPID, intent.appId());
76 assertEquals("incorrect match", MATCH, intent.selector());
77 assertEquals("incorrect ingress", FP1, intent.filteredIngressPoint());
78 assertEquals("incorrect egress", FP2, intent.filteredEgressPoint());
79 assertEquals("incorrect suggested path", suggestedPath, intent.suggestedPath());
80
81 }
82
83 @Test
84 public void failSuggestedPath() {
85 List<Link> suggestedPath = new LinkedList<>();
86 try {
87 suggestedPath.add(new IntentTestsMocks.FakeLink(FP3.connectPoint(), FP2.connectPoint()));
88
89 createWithSuggestedPath(suggestedPath);
90 fail("Point to Point intent building with incompatible suggested path "
91 + "not throw exception.");
92 } catch (IllegalArgumentException exception) {
93 assertThat(exception.getMessage(), containsString("Suggested path not compatible"));
94 }
95 }
96
Brian O'Connorf3d06162014-10-02 15:54:12 -070097 @Override
98 protected PointToPointIntent createOne() {
Ray Milkey3e3ec5f2015-03-17 17:00:38 -070099 return PointToPointIntent.builder()
100 .appId(APPID)
101 .selector(MATCH)
102 .treatment(NOP)
Ray Milkeya2cf3a12018-02-15 16:13:56 -0800103 .filteredIngressPoint(new FilteredConnectPoint(P1))
104 .filteredEgressPoint(new FilteredConnectPoint(P2))
Ray Milkey3e3ec5f2015-03-17 17:00:38 -0700105 .build();
Brian O'Connorf3d06162014-10-02 15:54:12 -0700106 }
107
Luca Prete670ac5d2017-02-03 15:55:43 -0800108 protected PointToPointIntent createWithResourceGroup() {
109 return PointToPointIntent.builder()
110 .appId(APPID)
111 .selector(MATCH)
112 .treatment(NOP)
Ray Milkeya2cf3a12018-02-15 16:13:56 -0800113 .filteredIngressPoint(new FilteredConnectPoint(P1))
114 .filteredEgressPoint(new FilteredConnectPoint(P2))
Luca Prete670ac5d2017-02-03 15:55:43 -0800115 .resourceGroup(RESOURCE_GROUP)
116 .build();
117 }
118
Brian O'Connorf3d06162014-10-02 15:54:12 -0700119 @Override
120 protected PointToPointIntent createAnother() {
Ray Milkey3e3ec5f2015-03-17 17:00:38 -0700121 return PointToPointIntent.builder()
122 .appId(APPID)
123 .selector(MATCH)
124 .treatment(NOP)
Ray Milkeya2cf3a12018-02-15 16:13:56 -0800125 .filteredIngressPoint(new FilteredConnectPoint(P2))
126 .filteredEgressPoint(new FilteredConnectPoint(P1))
Ray Milkey3e3ec5f2015-03-17 17:00:38 -0700127 .build();
Brian O'Connorf3d06162014-10-02 15:54:12 -0700128 }
Pier Ventreffe88d62016-10-13 14:34:40 -0700129
130 protected PointToPointIntent createOneFiltered() {
131 return PointToPointIntent.builder()
132 .appId(APPID)
133 .selector(MATCH)
134 .treatment(NOP)
135 .filteredIngressPoint(FP1)
136 .filteredEgressPoint(FP2)
137 .build();
138 }
Daniele Moro3a6e1512017-12-22 12:14:44 +0100139
140 protected PointToPointIntent createWithSuggestedPath(List<Link> suggestedPath) {
141 return PointToPointIntent.builder()
142 .appId(APPID)
143 .selector(MATCH)
144 .treatment(NOP)
145 .filteredIngressPoint(FP1)
146 .filteredEgressPoint(FP2)
147 .suggestedPath(suggestedPath)
148 .build();
149 }
Brian O'Connorf3d06162014-10-02 15:54:12 -0700150}