blob: 84649c00647ebd3332d787eaa9313fd608581953 [file] [log] [blame]
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +02001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +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 */
Yuta HIGUCHId95d5902016-06-27 00:18:45 -070016package org.onosproject.net.optical.intent.impl.compiler;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +020017
Thomas Vachuska2048c1f2017-05-10 19:32:22 -070018import com.google.common.collect.ImmutableList;
19import com.google.common.collect.ImmutableMap;
20import com.google.common.collect.ImmutableSet;
21import com.google.common.collect.Sets;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +020022import org.easymock.EasyMock;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +020023import org.junit.Before;
HIGUCHI Yuta7a004ae2016-05-28 10:26:03 -070024import org.junit.BeforeClass;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +020025import org.junit.Test;
26import org.onlab.packet.ChassisId;
27import org.onosproject.TestApplicationId;
28import org.onosproject.cfg.ComponentConfigService;
29import org.onosproject.core.ApplicationId;
30import org.onosproject.core.CoreService;
HIGUCHI Yuta7a004ae2016-05-28 10:26:03 -070031import org.onosproject.net.AbstractProjectableModel;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +020032import org.onosproject.net.Annotations;
33import org.onosproject.net.ChannelSpacing;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +020034import org.onosproject.net.CltSignalType;
35import org.onosproject.net.ConnectPoint;
Thomas Vachuska2048c1f2017-05-10 19:32:22 -070036import org.onosproject.net.DefaultAnnotations;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +020037import org.onosproject.net.DefaultDevice;
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -080038import org.onosproject.net.DefaultPort;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +020039import org.onosproject.net.Device;
40import org.onosproject.net.DeviceId;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +020041import org.onosproject.net.OchSignal;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +020042import org.onosproject.net.OduSignalId;
43import org.onosproject.net.OduSignalType;
Rimon Ashkenazy27438ff2016-03-22 15:57:45 +020044import org.onosproject.net.OduSignalUtils;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +020045import org.onosproject.net.Port;
46import org.onosproject.net.PortNumber;
47import org.onosproject.net.TributarySlot;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +020048import org.onosproject.net.behaviour.TributarySlotQuery;
49import org.onosproject.net.device.DeviceServiceAdapter;
50import org.onosproject.net.driver.Behaviour;
51import org.onosproject.net.driver.DefaultDriver;
52import org.onosproject.net.driver.Driver;
53import org.onosproject.net.driver.DriverHandler;
54import org.onosproject.net.driver.DriverService;
HIGUCHI Yuta7a004ae2016-05-28 10:26:03 -070055import org.onosproject.net.driver.DriverServiceAdapter;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +020056import org.onosproject.net.driver.TestBehaviourImpl;
57import org.onosproject.net.driver.TestBehaviourTwoImpl;
Thomas Vachuska2048c1f2017-05-10 19:32:22 -070058import org.onosproject.net.flow.DefaultTrafficSelector;
59import org.onosproject.net.flow.DefaultTrafficTreatment;
60import org.onosproject.net.flow.FlowRule;
61import org.onosproject.net.flow.TrafficSelector;
62import org.onosproject.net.flow.TrafficTreatment;
63import org.onosproject.net.flow.criteria.Criteria;
64import org.onosproject.net.flow.instructions.Instructions;
65import org.onosproject.net.intent.AbstractIntentTest;
66import org.onosproject.net.intent.FlowRuleIntent;
67import org.onosproject.net.intent.Intent;
68import org.onosproject.net.intent.IntentExtensionService;
69import org.onosproject.net.intent.IntentId;
70import org.onosproject.net.intent.IntentServiceAdapter;
71import org.onosproject.net.intent.IntentSetMultimap;
72import org.onosproject.net.intent.Key;
73import org.onosproject.net.intent.OpticalCircuitIntent;
74import org.onosproject.net.optical.OchPort;
75import org.onosproject.net.optical.OduCltPort;
76import org.onosproject.net.optical.impl.DefaultOchPort;
77import org.onosproject.net.optical.impl.DefaultOduCltPort;
78import org.onosproject.net.provider.ProviderId;
79import org.onosproject.net.resource.MockResourceService;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +020080
81import java.util.ArrayList;
82import java.util.Collection;
83import java.util.Collections;
84import java.util.HashSet;
85import java.util.List;
86import java.util.Set;
Yuta HIGUCHI652f27f2016-10-31 16:54:30 -070087import java.util.stream.Collectors;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +020088
Thomas Vachuska2048c1f2017-05-10 19:32:22 -070089import static org.easymock.EasyMock.*;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +020090import static org.hamcrest.MatcherAssert.assertThat;
Thomas Vachuska2048c1f2017-05-10 19:32:22 -070091import static org.hamcrest.Matchers.*;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +020092import static org.junit.Assert.assertEquals;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +020093import static org.onosproject.net.AnnotationKeys.PORT_NAME;
Thomas Vachuska2048c1f2017-05-10 19:32:22 -070094import static org.onosproject.net.AnnotationKeys.STATIC_PORT;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +020095import static org.onosproject.net.Device.Type.ROADM;
96import static org.onosproject.net.DeviceId.deviceId;
97import static org.onosproject.net.NetTestTools.APP_ID;
98
Thomas Vachuska2048c1f2017-05-10 19:32:22 -070099public class OpticalCircuitIntentCompilerTest extends AbstractIntentTest {
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200100
101 private static final String DEV1 = "of:1";
102 private static final String DEV2 = "of:2";
103
104 static final Key KEY1 = Key.of(5L, APP_ID);
105
106 private static final String STATIC_TRUE = "true";
107 private static final String PNAME = "p2";
108
109 private CoreService coreService;
110 private IntentExtensionService intentExtensionService;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200111 private OpticalCircuitIntentCompiler sut;
112
113 private final ApplicationId appId = new TestApplicationId("test");
114 private static Device device1 = new DefaultDevice(ProviderId.NONE, deviceId(DEV1), ROADM,
115 "m", "h", "s", "n", new ChassisId(0L));
116 private static Device device2 = new DefaultDevice(ProviderId.NONE, deviceId(DEV2), ROADM,
117 "m", "h", "s", "n", new ChassisId(1L));
118
119 private static Annotations annotations1 = DefaultAnnotations.builder().set(STATIC_PORT, STATIC_TRUE).build();
120 private static Annotations annotations2 = DefaultAnnotations.builder().set(PORT_NAME, PNAME).build();
121
122 // OduClt ports with signalType=1GBE
123 private static final OduCltPort D1P1 =
HIGUCHI Yuta4c0ef6b2016-05-02 19:45:41 -0700124 new DefaultOduCltPort(new DefaultPort(device1, PortNumber.portNumber(1), true, annotations1),
125 CltSignalType.CLT_1GBE);
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200126 private static final OduCltPort D2P1 =
HIGUCHI Yuta4c0ef6b2016-05-02 19:45:41 -0700127 new DefaultOduCltPort(new DefaultPort(device2, PortNumber.portNumber(1), true, annotations1),
128 CltSignalType.CLT_1GBE);
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200129
130 // Och ports with signalType=ODU2
131 private static final OchPort D1P2 =
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -0800132 new DefaultOchPort(new DefaultPort(device1, PortNumber.portNumber(2), true, annotations2),
133 OduSignalType.ODU2,
134 true, OchSignal.newDwdmSlot(ChannelSpacing.CHL_50GHZ, 1));
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200135 private static final OchPort D2P2 =
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -0800136 new DefaultOchPort(new DefaultPort(device2, PortNumber.portNumber(2), true, annotations2),
137 OduSignalType.ODU2,
138 true, OchSignal.newDwdmSlot(ChannelSpacing.CHL_50GHZ, 1));
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200139
140 // OduClt ports with signalType=10GBE
141 private static final OduCltPort D1P3 =
HIGUCHI Yuta4c0ef6b2016-05-02 19:45:41 -0700142 new DefaultOduCltPort(new DefaultPort(device1, PortNumber.portNumber(3), true, annotations1),
143 CltSignalType.CLT_10GBE);
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200144 private static final OduCltPort D2P3 =
HIGUCHI Yuta4c0ef6b2016-05-02 19:45:41 -0700145 new DefaultOduCltPort(new DefaultPort(device2, PortNumber.portNumber(3), true, annotations1),
146 CltSignalType.CLT_10GBE);
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200147
148
149 private OpticalCircuitIntent intent;
150
151 /**
152 * Mocks the device service so that devices and ports appear available in the test.
153 */
154 private static class MockDeviceService extends DeviceServiceAdapter {
155 @Override
156 public boolean isAvailable(DeviceId deviceId) {
157 return true;
158 }
159
160 @Override
161 public List<Port> getPorts(DeviceId deviceId) {
162 if (deviceId.equals(deviceId(DEV1))) {
163 return ImmutableList.of((Port) D1P1, (Port) D1P2, (Port) D1P3);
164 }
165
166 if (deviceId.equals(deviceId(DEV2))) {
167 return ImmutableList.of((Port) D2P1, (Port) D2P2, (Port) D2P3);
168 }
169 return Collections.emptyList();
170 }
171
172 @Override
173 public Port getPort(DeviceId deviceId, PortNumber portNumber) {
174 if (deviceId.equals(deviceId(DEV1))) {
175 switch (portNumber.toString()) {
176 case "1":
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -0800177 return D1P1;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200178 case "2":
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -0800179 return D1P2;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200180 case "3":
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -0800181 return D1P3;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200182 default:
183 return null;
184 }
185 }
186 if (deviceId.equals(deviceId(DEV2))) {
187 switch (portNumber.toString()) {
188 case "1":
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -0800189 return D2P1;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200190 case "2":
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -0800191 return D2P2;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200192 case "3":
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -0800193 return D2P3;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200194 default:
195 return null;
196 }
197 }
198 return null;
199 }
200 }
201
202 /**
203 * Mocks the driver service so it will appear supporting TributarySlotQuery Behaviour in the test.
204 */
205 private static class MockDriverServiceWithTs implements DriverService {
206 @Override
207 public Driver getDriver(String driverName) {
208 // TODO Auto-generated method stub
209 return null;
210 }
211
212 @Override
213 public Set<Driver> getDrivers() {
214 // TODO Auto-generated method stub
215 return null;
216 }
217
218 @Override
219 public Set<Driver> getDrivers(Class<? extends Behaviour> withBehaviour) {
220 // TODO Auto-generated method stub
221 return null;
222 }
223
224 @Override
225 public Driver getDriver(String mfr, String hw, String sw) {
226 // TODO Auto-generated method stub
227 return null;
228 }
229
230 @Override
231 public Driver getDriver(DeviceId deviceId) {
232 DefaultDriver ddp = new DefaultDriver("foo.base", new ArrayList<>(), "Circus", "lux", "1.2a",
233 ImmutableMap.of(Behaviour.class,
234 TestBehaviourImpl.class,
235 TributarySlotQuery.class,
236 TestBehaviourTwoImpl.class),
237 ImmutableMap.of("foo", "bar"));
238 return ddp;
239 }
240
241 @Override
242 public DriverHandler createHandler(DeviceId deviceId,
243 String... credentials) {
244 // TODO Auto-generated method stub
245 return null;
246 }
247 }
248
249 /**
250 * Mocks the driver service so it will appear not-supporting TributarySlotQuery Behaviour in the test.
251 */
252 private static class MockDriverServiceNoTs implements DriverService {
253 @Override
254 public Driver getDriver(String driverName) {
255 // TODO Auto-generated method stub
256 return null;
257 }
258
259 @Override
260 public Set<Driver> getDrivers() {
261 // TODO Auto-generated method stub
262 return null;
263 }
264
265 @Override
266 public Set<Driver> getDrivers(Class<? extends Behaviour> withBehaviour) {
267 // TODO Auto-generated method stub
268 return null;
269 }
270
271 @Override
272 public Driver getDriver(String mfr, String hw, String sw) {
273 // TODO Auto-generated method stub
274 return null;
275 }
276
277 @Override
278 public Driver getDriver(DeviceId deviceId) {
279 DefaultDriver ddp = new DefaultDriver("foo.base", new ArrayList<>(), "Circus", "lux", "1.2a",
280 ImmutableMap.of(Behaviour.class,
281 TestBehaviourImpl.class),
282 ImmutableMap.of("foo", "bar"));
283 return ddp;
284 }
285
286 @Override
287 public DriverHandler createHandler(DeviceId deviceId,
288 String... credentials) {
289 // TODO Auto-generated method stub
290 return null;
291 }
292 }
293
294 private static class MockIntentSetMultimap implements IntentSetMultimap {
295 @Override
296 public boolean allocateMapping(IntentId keyIntentId,
297 IntentId valIntentId) {
298 // TODO Auto-generated method stub
299 return false;
300 }
301
302 @Override
303 public Set<IntentId> getMapping(IntentId intentId) {
304 // TODO Auto-generated method stub
305 return null;
306 }
307
308 @Override
309 public void releaseMapping(IntentId intentId) {
310 // TODO Auto-generated method stub
311 }
312
313 }
314
315 /**
316 * Represents a fake IntentService class that easily allows to store and
317 * retrieve intents without implementing the IntentService logic.
318 */
319 private class TestIntentService extends IntentServiceAdapter {
320
321 private Set<Intent> intents;
322
323 public TestIntentService() {
324 intents = Sets.newHashSet();
325 }
326
327 @Override
328 public void submit(Intent intent) {
329 intents.add(intent);
330 }
331
332 @Override
333 public long getIntentCount() {
334 return intents.size();
335 }
336
337 @Override
338 public Iterable<Intent> getIntents() {
339 return intents;
340 }
341
342 @Override
343 public Intent getIntent(Key intentKey) {
344 for (Intent intent : intents) {
345 if (intent.key().equals(intentKey)) {
346 return intent;
347 }
348 }
349 return null;
350 }
351 }
352
HIGUCHI Yuta7a004ae2016-05-28 10:26:03 -0700353 @BeforeClass
354 public static void setUpClass() {
355 AbstractProjectableModel.setDriverService("key", new DriverServiceAdapter());
356 }
357
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200358 @Before
359 public void setUp() {
360 sut = new OpticalCircuitIntentCompiler();
361 coreService = createMock(CoreService.class);
362 expect(coreService.registerApplication("org.onosproject.net.intent"))
363 .andReturn(appId);
364 sut.coreService = coreService;
365 sut.deviceService = new MockDeviceService();
366 sut.resourceService = new MockResourceService();
367 sut.intentService = new TestIntentService();
368 sut.intentSetMultimap = new MockIntentSetMultimap();
369
Thomas Vachuska2048c1f2017-05-10 19:32:22 -0700370 super.setUp();
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200371
372 intentExtensionService = createMock(IntentExtensionService.class);
373 intentExtensionService.registerCompiler(OpticalCircuitIntent.class, sut);
374 intentExtensionService.unregisterCompiler(OpticalCircuitIntent.class);
375 sut.intentManager = intentExtensionService;
376 replay(coreService, intentExtensionService);
377
378 // mocking ComponentConfigService
379 ComponentConfigService mockConfigService =
380 EasyMock.createMock(ComponentConfigService.class);
381 expect(mockConfigService.getProperties(anyObject())).andReturn(ImmutableSet.of());
382 mockConfigService.registerProperties(sut.getClass());
383 expectLastCall();
384 mockConfigService.unregisterProperties(sut.getClass(), false);
385 expectLastCall();
386 expect(mockConfigService.getProperties(anyObject())).andReturn(ImmutableSet.of());
387 sut.cfgService = mockConfigService;
388 replay(mockConfigService);
389
390 }
391
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200392 /**
393 * Tests compile of OpticalCircuitIntent with allocation of TributarySlots.
394 * Compile two ODUCLT ports (with CLT_1GBE), over OCH ports (with ODU2):
395 * - only one TributarySlot is used
396 */
397 @Test
398 public void test1GbeMultiplexOverOdu2() {
399
400 // Use driver with TributarySlotQuery Behaviour
401 sut.driverService = new MockDriverServiceWithTs();
402
403 ConnectPoint oduCltSrcCP = new ConnectPoint(device1.id(), D1P1.number());
404 ConnectPoint oduCltDstCP = new ConnectPoint(device2.id(), D2P1.number());
405 ConnectPoint ochSrcCP = new ConnectPoint(device1.id(), D1P2.number());
406 ConnectPoint ochDstCP = new ConnectPoint(device2.id(), D2P2.number());
407
408 intent = OpticalCircuitIntent.builder()
409 .appId(APP_ID)
410 .key(KEY1)
411 .src(oduCltSrcCP)
412 .dst(oduCltDstCP)
413 .signalType(D1P1.signalType())
414 .bidirectional(false)
415 .build();
416
417 sut.activate(null);
418
Sho SHIMIZUec07ffd2016-02-22 20:45:21 -0800419 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200420 assertThat(compiled, hasSize(1));
421
Yuta HIGUCHI652f27f2016-10-31 16:54:30 -0700422 assertThat("key is inherited",
423 compiled.stream().map(Intent::key).collect(Collectors.toList()),
424 everyItem(is(intent.key())));
425
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200426 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
427
428 FlowRule rule1 = rules.stream()
429 .filter(x -> x.deviceId().equals(device1.id()))
430 .findFirst()
431 .get();
432 // validate SRC selector
433 TrafficSelector.Builder selectorBuilder1 = DefaultTrafficSelector.builder();
434 selectorBuilder1.matchInPort(oduCltSrcCP.port());
435 selectorBuilder1.add(Criteria.matchOduSignalType(OduSignalType.ODU0));
436 assertThat(rule1.selector(), is(selectorBuilder1.build()));
437
438 // validate SRC treatment (with OduSignalId, where 1 TributarySlot is used)
439 TrafficTreatment.Builder treatmentBuilder1 = DefaultTrafficTreatment.builder();
440 Set<TributarySlot> slots = new HashSet<>();
441 slots.add(TributarySlot.of(1));
Rimon Ashkenazy27438ff2016-03-22 15:57:45 +0200442 OduSignalId oduSignalId = OduSignalUtils.buildOduSignalId(D1P2.signalType(), slots);
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200443 treatmentBuilder1.add(Instructions.modL1OduSignalId(oduSignalId));
444 treatmentBuilder1.setOutput(ochSrcCP.port());
445 assertThat(rule1.treatment(), is(treatmentBuilder1.build()));
446
447 FlowRule rule2 = rules.stream()
448 .filter(x -> x.deviceId().equals(device2.id()))
449 .findFirst()
450 .get();
451 // validate DST selector (with OduSignalId, where the same TributarySlot is used)
452 TrafficSelector.Builder selectorBuilder2 = DefaultTrafficSelector.builder();
453 selectorBuilder2.matchInPort(ochDstCP.port());
454 selectorBuilder2.add(Criteria.matchOduSignalType(OduSignalType.ODU0));
455 selectorBuilder2.add(Criteria.matchOduSignalId(oduSignalId));
456 assertThat(rule2.selector(), is(selectorBuilder2.build()));
457
458 // validate DST treatment
459 assertThat(rule2.treatment(), is(
460 DefaultTrafficTreatment.builder().setOutput(oduCltDstCP.port()).build()
461 ));
462
463 rules.forEach(rule -> assertEquals("FlowRule priority is incorrect",
464 intent.priority(), rule.priority()));
465
466 sut.deactivate();
467 }
468
469 /**
470 * Tests compile of OpticalCircuitIntent with allocation of TributarySlots.
471 * Compile two ODUCLT ports (with CLT_10GBE), over OCH ports (with ODU2):
472 * - All TributarySlots are used
473 */
474 @Test
475 public void test10GbeMultiplexOverOdu2() {
476
477 // Use driver with TributarySlotQuery Behaviour
478 sut.driverService = new MockDriverServiceWithTs();
479
480 ConnectPoint oduCltSrcCP = new ConnectPoint(device1.id(), D1P3.number());
481 ConnectPoint oduCltDstCP = new ConnectPoint(device2.id(), D2P3.number());
482 ConnectPoint ochSrcCP = new ConnectPoint(device1.id(), D1P2.number());
483 ConnectPoint ochDstCP = new ConnectPoint(device2.id(), D2P2.number());
484
485 intent = OpticalCircuitIntent.builder()
486 .appId(APP_ID)
487 .key(KEY1)
488 .src(oduCltSrcCP)
489 .dst(oduCltDstCP)
490 .signalType(D1P3.signalType())
491 .bidirectional(false)
492 .build();
493
494 sut.activate(null);
495
Sho SHIMIZUec07ffd2016-02-22 20:45:21 -0800496 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200497 assertThat(compiled, hasSize(1));
498
Yuta HIGUCHI652f27f2016-10-31 16:54:30 -0700499 assertThat("key is inherited",
500 compiled.stream().map(Intent::key).collect(Collectors.toList()),
501 everyItem(is(intent.key())));
502
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200503 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
504
505 FlowRule rule1 = rules.stream()
506 .filter(x -> x.deviceId().equals(device1.id()))
507 .findFirst()
508 .get();
509 // validate SRC selector
510 TrafficSelector.Builder selectorBuilder1 = DefaultTrafficSelector.builder();
511 selectorBuilder1.matchInPort(oduCltSrcCP.port());
512 selectorBuilder1.add(Criteria.matchOduSignalType(OduSignalType.ODU2));
513 assertThat(rule1.selector(), is(selectorBuilder1.build()));
514
515 // validate SRC treatment (without OduSignalId, i.e. All TributarySlots are used)
516 TrafficTreatment.Builder treatmentBuilder1 = DefaultTrafficTreatment.builder();
517 treatmentBuilder1.setOutput(ochSrcCP.port());
518 assertThat(rule1.treatment(), is(treatmentBuilder1.build()));
519
520 FlowRule rule2 = rules.stream()
521 .filter(x -> x.deviceId().equals(device2.id()))
522 .findFirst()
523 .get();
524 // validate DST selector (without OduSignalId, i.e. All TributarySlots are used)
525 TrafficSelector.Builder selectorBuilder2 = DefaultTrafficSelector.builder();
526 selectorBuilder2.matchInPort(ochDstCP.port());
527 selectorBuilder2.add(Criteria.matchOduSignalType(OduSignalType.ODU2));
528 assertThat(rule2.selector(), is(selectorBuilder2.build()));
529
530 // validate DST treatment
531 assertThat(rule2.treatment(), is(
532 DefaultTrafficTreatment.builder().setOutput(oduCltDstCP.port()).build()
533 ));
534
535 rules.forEach(rule -> assertEquals("FlowRule priority is incorrect",
536 intent.priority(), rule.priority()));
537
538 sut.deactivate();
539 }
540
541 /**
542 * Tests compile of OpticalCircuitIntent without allocation of TributarySlots.
543 * Compile two ODUCLT ports (with CLT_10GBE), over OCH ports (with ODU2):
544 * - No TributarySlots are used
545 */
546 @Test
547 public void test10GbeNoMuxOverOdu2() {
548
549 // Use driver without support for TributarySlotQuery Behaviour
550 sut.driverService = new MockDriverServiceNoTs();
551
552 ConnectPoint oduCltSrcCP = new ConnectPoint(device1.id(), D1P3.number());
553 ConnectPoint oduCltDstCP = new ConnectPoint(device2.id(), D2P3.number());
554 ConnectPoint ochSrcCP = new ConnectPoint(device1.id(), D1P2.number());
555 ConnectPoint ochDstCP = new ConnectPoint(device2.id(), D2P2.number());
556
557 intent = OpticalCircuitIntent.builder()
558 .appId(APP_ID)
559 .key(KEY1)
560 .src(oduCltSrcCP)
561 .dst(oduCltDstCP)
562 .signalType(D1P3.signalType())
563 .bidirectional(false)
564 .build();
565
566 sut.activate(null);
567
Sho SHIMIZUec07ffd2016-02-22 20:45:21 -0800568 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200569 assertThat(compiled, hasSize(1));
570
Yuta HIGUCHI652f27f2016-10-31 16:54:30 -0700571 assertThat("key is inherited",
572 compiled.stream().map(Intent::key).collect(Collectors.toList()),
573 everyItem(is(intent.key())));
574
575
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200576 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
577
578 FlowRule rule1 = rules.stream()
579 .filter(x -> x.deviceId().equals(device1.id()))
580 .findFirst()
581 .get();
582 // validate SRC selector
583 TrafficSelector.Builder selectorBuilder1 = DefaultTrafficSelector.builder();
584 selectorBuilder1.matchInPort(oduCltSrcCP.port());
585 assertThat(rule1.selector(), is(selectorBuilder1.build()));
586
587 // validate SRC treatment (without OduSignalType and OduSignalId: i.e. No TributarySlots are used)
588 TrafficTreatment.Builder treatmentBuilder1 = DefaultTrafficTreatment.builder();
589 treatmentBuilder1.setOutput(ochSrcCP.port());
590 assertThat(rule1.treatment(), is(treatmentBuilder1.build()));
591
592 FlowRule rule2 = rules.stream()
593 .filter(x -> x.deviceId().equals(device2.id()))
594 .findFirst()
595 .get();
596 // validate DST selector (without OduSignalType and OduSignalId: i.e. No TributarySlots are used)
597 TrafficSelector.Builder selectorBuilder2 = DefaultTrafficSelector.builder();
598 selectorBuilder2.matchInPort(ochDstCP.port());
599 assertThat(rule2.selector(), is(selectorBuilder2.build()));
600 // validate DST treatment
601 assertThat(rule2.treatment(), is(
602 DefaultTrafficTreatment.builder().setOutput(oduCltDstCP.port()).build()
603 ));
604
605 rules.forEach(rule -> assertEquals("FlowRule priority is incorrect",
606 intent.priority(), rule.priority()));
607
608 sut.deactivate();
609 }
610
611}