blob: f127a6d4ca822098d31f426387651a0c41ad0667 [file] [log] [blame]
Thomas Szyrkowiec770093f2017-05-05 13:06:53 +02001/*
Brian O'Connorce2a03d2017-08-03 19:21:03 -07002 * Copyright 2016-present Open Networking Foundation
Thomas Szyrkowiec770093f2017-05-05 13:06:53 +02003 *
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 */
16
17package org.onosproject.net.intent.impl.compiler;
18
19import com.google.common.collect.ImmutableList;
20import com.google.common.collect.ImmutableSet;
Thomas Szyrkowiec770093f2017-05-05 13:06:53 +020021import org.junit.Before;
22import org.junit.Test;
23import org.onosproject.cfg.ComponentConfigAdapter;
24import org.onosproject.core.CoreService;
25import org.onosproject.net.ConnectPoint;
26import org.onosproject.net.FilteredConnectPoint;
27import org.onosproject.net.domain.DomainPointToPointIntent;
28import org.onosproject.net.domain.DomainService;
29import org.onosproject.net.flow.FlowRule;
30import org.onosproject.net.intent.Constraint;
31import org.onosproject.net.intent.FlowRuleIntent;
32import org.onosproject.net.intent.Intent;
33import org.onosproject.net.intent.IntentExtensionService;
34import org.onosproject.net.intent.LinkCollectionIntent;
35import org.onosproject.net.intent.constraint.DomainConstraint;
36import org.onosproject.net.resource.MockResourceService;
37
38import java.util.Collection;
39import java.util.Collections;
40import java.util.List;
41
Thomas Vachuska2048c1f2017-05-10 19:32:22 -070042import static org.easymock.EasyMock.*;
Thomas Szyrkowiec770093f2017-05-05 13:06:53 +020043import static org.hamcrest.MatcherAssert.assertThat;
44import static org.hamcrest.Matchers.equalTo;
45import static org.hamcrest.Matchers.hasSize;
46import static org.onosproject.net.NetTestTools.APP_ID;
47import static org.onosproject.net.NetTestTools.link;
48import static org.onosproject.net.domain.DomainId.LOCAL;
49
50/**
51 * Those tests verify the compilation process with domains included in the path.
52 */
53public class LinkCollectionIntentCompilerDomainP2PTest extends AbstractLinkCollectionTest {
54
55 private static List<Constraint> domainConstraint =
56 ImmutableList.of(DomainConstraint.domain());
57
58 @Before
59 public void setUp() {
60 sut = new LinkCollectionIntentCompiler();
61 coreService = createMock(CoreService.class);
62 expect(coreService.registerApplication("org.onosproject.net.intent"))
63 .andReturn(appId);
64 sut.coreService = coreService;
65
66 // defining the domain assignments
67 domainService = createMock(DomainService.class);
68 expect(domainService.getDomain(d1Id)).andReturn(LOCAL).anyTimes();
69 expect(domainService.getDomain(d2Id)).andReturn(domain).anyTimes();
70 expect(domainService.getDomain(d4Id)).andReturn(domain).anyTimes();
71 expect(domainService.getDomain(d3Id)).andReturn(LOCAL).anyTimes();
72 sut.domainService = domainService;
73
Thomas Vachuska2048c1f2017-05-10 19:32:22 -070074 super.setUp();
Thomas Szyrkowiec770093f2017-05-05 13:06:53 +020075
76 intentExtensionService = createMock(IntentExtensionService.class);
77 intentExtensionService
78 .registerCompiler(LinkCollectionIntent.class, sut);
79 intentExtensionService.unregisterCompiler(LinkCollectionIntent.class);
80
81 registrator = new IntentConfigurableRegistrator();
82 registrator.extensionService = intentExtensionService;
83 registrator.cfgService = new ComponentConfigAdapter();
84 registrator.activate();
85
86 sut.registrator = registrator;
87 sut.resourceService = new MockResourceService();
88
89 LinkCollectionCompiler.optimizeInstructions = false;
90 LinkCollectionCompiler.copyTtl = false;
91
92 replay(coreService, domainService, intentExtensionService);
93 }
94
Thomas Szyrkowiec770093f2017-05-05 13:06:53 +020095 /**
96 * We test the proper compilation of one domain device.
97 */
98 @Test
99 public void testCompilationSingleDeviceDomainP2P() {
100
101 intent = LinkCollectionIntent.builder()
102 .appId(APP_ID)
103 .selector(selector)
104 .treatment(treatment)
105 .applyTreatmentOnEgress(true)
106 .links(p2pLinks)
107 .filteredIngressPoints(ImmutableSet.of(
108 new FilteredConnectPoint(d1p10)
109 ))
110 .filteredEgressPoints(ImmutableSet.of(
111 new FilteredConnectPoint(d3p10)
112 ))
113 .constraints(domainConstraint)
114 .build();
115
116 sut.activate();
117
118 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
119 assertThat(compiled, hasSize(2));
120
121 DomainPointToPointIntent domainIntent =
122 ((DomainPointToPointIntent) compiled.get(0));
123 ConnectPoint ingress =
124 domainIntent.filteredIngressPoints().iterator().next()
125 .connectPoint();
126 assertThat(ingress, equalTo(d2p0));
127 ConnectPoint egress =
128 domainIntent.filteredEgressPoints().iterator().next()
129 .connectPoint();
130 assertThat(egress, equalTo(d2p1));
131 assertThat(domainIntent.links(), hasSize(0));
132
133 Collection<FlowRule> rules =
134 ((FlowRuleIntent) compiled.get(1)).flowRules();
135 assertThat(rules, hasSize(2));
136
137 sut.deactivate();
138
139 }
140
141 /**
142 * We test the proper compilation of a domain with two devices.
143 */
144 @Test
145 public void testCompilationMultiHopDomainP2P() {
146
147 intent = LinkCollectionIntent.builder()
148 .appId(APP_ID)
149 .selector(selector)
150 .treatment(treatment)
151 .applyTreatmentOnEgress(true)
152 .links(domainP2Plinks)
153 .filteredIngressPoints(ImmutableSet.of(
154 new FilteredConnectPoint(d1p10)
155 ))
156 .filteredEgressPoints(ImmutableSet.of(
157 new FilteredConnectPoint(d3p10)
158 ))
159 .constraints(domainConstraint)
160 .build();
161
162 sut.activate();
163
164 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
165 assertThat(compiled, hasSize(2));
166
167 DomainPointToPointIntent domainIntent =
168 ((DomainPointToPointIntent) compiled.get(0));
169 ConnectPoint ingress =
170 domainIntent.filteredIngressPoints().iterator().next()
171 .connectPoint();
172 assertThat(ingress, equalTo(d2p0));
173 ConnectPoint egress =
174 domainIntent.filteredEgressPoints().iterator().next()
175 .connectPoint();
176 assertThat(egress, equalTo(d4p0));
177 assertThat(domainIntent.links(), hasSize(1));
178
179 Collection<FlowRule> rules =
180 ((FlowRuleIntent) compiled.get(1)).flowRules();
181 assertThat(rules, hasSize(2));
182
183 sut.deactivate();
184
185 }
186
187
188 /**
189 * We test the proper compilation of a domain starting with a domain device.
190 */
191 @Test
192 public void testCompilationDomainStartP2P() {
193
194 intent = LinkCollectionIntent.builder()
195 .appId(APP_ID)
196 .selector(selector)
197 .treatment(treatment)
198 .applyTreatmentOnEgress(true)
199 .links(ImmutableSet.of(
200 link(d2p0, d1p0)
201 ))
202 .filteredIngressPoints(ImmutableSet.of(
203 new FilteredConnectPoint(d2p10)
204 ))
205 .filteredEgressPoints(ImmutableSet.of(
206 new FilteredConnectPoint(d1p10)
207 ))
208 .constraints(domainConstraint)
209 .build();
210
211 sut.activate();
212
213 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
214 assertThat(compiled, hasSize(2));
215
216 DomainPointToPointIntent domainIntent =
217 ((DomainPointToPointIntent) compiled.get(0));
218 ConnectPoint ingress =
219 domainIntent.filteredIngressPoints().iterator().next()
220 .connectPoint();
221 assertThat(ingress, equalTo(d2p10));
222 ConnectPoint egress =
223 domainIntent.filteredEgressPoints().iterator().next()
224 .connectPoint();
225 assertThat(egress, equalTo(d2p0));
226 assertThat(domainIntent.links(), hasSize(0));
227
228 Collection<FlowRule> rules =
229 ((FlowRuleIntent) compiled.get(1)).flowRules();
230 assertThat(rules, hasSize(1));
231
232 sut.deactivate();
233
234 }
235
236 /**
237 * We test the proper compilation of a domain ending with a domain device.
238 */
239 @Test
240 public void testCompilationDomainEndP2P() {
241
242 intent = LinkCollectionIntent.builder()
243 .appId(APP_ID)
244 .selector(selector)
245 .treatment(treatment)
246 .applyTreatmentOnEgress(true)
247 .links(ImmutableSet.of(
248 link(d1p0, d2p0)
249 ))
250 .filteredIngressPoints(ImmutableSet.of(
251 new FilteredConnectPoint(d1p10)
252 ))
253 .filteredEgressPoints(ImmutableSet.of(
254 new FilteredConnectPoint(d2p10)
255 ))
256 .constraints(domainConstraint)
257 .build();
258
259 sut.activate();
260
261 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
262 assertThat(compiled, hasSize(2));
263
264 DomainPointToPointIntent domainIntent =
265 ((DomainPointToPointIntent) compiled.get(0));
266 ConnectPoint ingress =
267 domainIntent.filteredIngressPoints().iterator().next()
268 .connectPoint();
269 assertThat(ingress, equalTo(d2p0));
270 ConnectPoint egress =
271 domainIntent.filteredEgressPoints().iterator().next()
272 .connectPoint();
273 assertThat(egress, equalTo(d2p10));
274 assertThat(domainIntent.links(), hasSize(0));
275
276 Collection<FlowRule> rules =
277 ((FlowRuleIntent) compiled.get(1)).flowRules();
278 assertThat(rules, hasSize(1));
279
280 sut.deactivate();
281
282 }
283
284 /**
285 * We test the proper compilation of a path fully inside of a domain.
286 */
287 @Test
288 public void testCompilationDomainFullP2P() {
289
290 intent = LinkCollectionIntent.builder()
291 .appId(APP_ID)
292 .selector(selector)
293 .treatment(treatment)
294 .applyTreatmentOnEgress(true)
295 .links(ImmutableSet.of(
296 link(d2p0, d4p0)
297 ))
298 .filteredIngressPoints(ImmutableSet.of(
299 new FilteredConnectPoint(d2p10)
300 ))
301 .filteredEgressPoints(ImmutableSet.of(
302 new FilteredConnectPoint(d4p10)
303 ))
304 .constraints(domainConstraint)
305 .build();
306
307 sut.activate();
308
309 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
310 assertThat(compiled, hasSize(1));
311
312 DomainPointToPointIntent domainIntent =
313 ((DomainPointToPointIntent) compiled.get(0));
314 ConnectPoint ingress =
315 domainIntent.filteredIngressPoints().iterator().next()
316 .connectPoint();
317 assertThat(ingress, equalTo(d2p10));
318 ConnectPoint egress =
319 domainIntent.filteredEgressPoints().iterator().next()
320 .connectPoint();
321 assertThat(egress, equalTo(d4p10));
322 assertThat(domainIntent.links(), hasSize(1));
323
324 sut.deactivate();
325
326 }
327
328}