blob: 1ce3e6c53f18269be6bf978337c1f6eb0e77f785 [file] [log] [blame]
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +02001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
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
18import org.easymock.EasyMock;
19import org.junit.After;
20import org.junit.Before;
HIGUCHI Yuta7a004ae2016-05-28 10:26:03 -070021import org.junit.BeforeClass;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +020022import org.junit.Test;
23import org.onlab.packet.ChassisId;
24import org.onosproject.TestApplicationId;
25import org.onosproject.cfg.ComponentConfigService;
26import org.onosproject.core.ApplicationId;
27import org.onosproject.core.CoreService;
28import org.onosproject.core.IdGenerator;
HIGUCHI Yuta7a004ae2016-05-28 10:26:03 -070029import org.onosproject.net.AbstractProjectableModel;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +020030import org.onosproject.net.Annotations;
31import org.onosproject.net.ChannelSpacing;
32import org.onosproject.net.DefaultAnnotations;
33import org.onosproject.net.CltSignalType;
34import org.onosproject.net.ConnectPoint;
35import org.onosproject.net.DefaultDevice;
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -080036import org.onosproject.net.DefaultPort;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +020037import org.onosproject.net.Device;
38import org.onosproject.net.DeviceId;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +020039import org.onosproject.net.OchSignal;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +020040import org.onosproject.net.OduSignalId;
41import org.onosproject.net.OduSignalType;
Rimon Ashkenazy27438ff2016-03-22 15:57:45 +020042import org.onosproject.net.OduSignalUtils;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +020043import org.onosproject.net.Port;
44import org.onosproject.net.PortNumber;
45import org.onosproject.net.TributarySlot;
46import org.onosproject.net.flow.DefaultTrafficSelector;
47import org.onosproject.net.flow.DefaultTrafficTreatment;
48import org.onosproject.net.flow.FlowRule;
49import org.onosproject.net.flow.TrafficSelector;
50import org.onosproject.net.flow.TrafficTreatment;
51import org.onosproject.net.flow.criteria.Criteria;
52import org.onosproject.net.flow.instructions.Instructions;
53import org.onosproject.net.intent.FlowRuleIntent;
54import org.onosproject.net.intent.Intent;
55import org.onosproject.net.intent.IntentExtensionService;
56import org.onosproject.net.intent.IntentId;
57import org.onosproject.net.intent.IntentServiceAdapter;
58import org.onosproject.net.intent.Key;
59import org.onosproject.net.intent.MockIdGenerator;
60import org.onosproject.net.intent.OpticalCircuitIntent;
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -080061import org.onosproject.net.optical.OchPort;
HIGUCHI Yuta4c0ef6b2016-05-02 19:45:41 -070062import org.onosproject.net.optical.OduCltPort;
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -080063import org.onosproject.net.optical.impl.DefaultOchPort;
HIGUCHI Yuta4c0ef6b2016-05-02 19:45:41 -070064import org.onosproject.net.optical.impl.DefaultOduCltPort;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +020065import org.onosproject.net.provider.ProviderId;
Yuta HIGUCHId95d5902016-06-27 00:18:45 -070066import org.onosproject.net.resource.MockResourceService;
Sho SHIMIZU739873b2016-02-23 17:02:12 -080067import org.onosproject.net.intent.IntentSetMultimap;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +020068import org.onosproject.net.behaviour.TributarySlotQuery;
69import org.onosproject.net.device.DeviceServiceAdapter;
70import org.onosproject.net.driver.Behaviour;
71import org.onosproject.net.driver.DefaultDriver;
72import org.onosproject.net.driver.Driver;
73import org.onosproject.net.driver.DriverHandler;
74import org.onosproject.net.driver.DriverService;
HIGUCHI Yuta7a004ae2016-05-28 10:26:03 -070075import org.onosproject.net.driver.DriverServiceAdapter;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +020076import org.onosproject.net.driver.TestBehaviourImpl;
77import org.onosproject.net.driver.TestBehaviourTwoImpl;
78
79import com.google.common.collect.ImmutableList;
80import com.google.common.collect.ImmutableMap;
81import com.google.common.collect.ImmutableSet;
82import com.google.common.collect.Sets;
83
84import java.util.ArrayList;
85import java.util.Collection;
86import java.util.Collections;
87import java.util.HashSet;
88import java.util.List;
89import java.util.Set;
Yuta HIGUCHI652f27f2016-10-31 16:54:30 -070090import java.util.stream.Collectors;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +020091
92import static org.easymock.EasyMock.anyObject;
93import static org.easymock.EasyMock.createMock;
94import static org.easymock.EasyMock.expect;
95import static org.easymock.EasyMock.expectLastCall;
96import static org.easymock.EasyMock.replay;
97import static org.hamcrest.MatcherAssert.assertThat;
Yuta HIGUCHI652f27f2016-10-31 16:54:30 -070098import static org.hamcrest.Matchers.everyItem;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +020099import static org.hamcrest.Matchers.hasSize;
100import static org.hamcrest.Matchers.is;
101import static org.junit.Assert.assertEquals;
102import static org.onosproject.net.AnnotationKeys.STATIC_PORT;
103import static org.onosproject.net.AnnotationKeys.PORT_NAME;
104import static org.onosproject.net.Device.Type.ROADM;
105import static org.onosproject.net.DeviceId.deviceId;
106import static org.onosproject.net.NetTestTools.APP_ID;
107
108public class OpticalCircuitIntentCompilerTest {
109
110 private static final String DEV1 = "of:1";
111 private static final String DEV2 = "of:2";
112
113 static final Key KEY1 = Key.of(5L, APP_ID);
114
115 private static final String STATIC_TRUE = "true";
116 private static final String PNAME = "p2";
117
118 private CoreService coreService;
119 private IntentExtensionService intentExtensionService;
120 private final IdGenerator idGenerator = new MockIdGenerator();
121 private OpticalCircuitIntentCompiler sut;
122
123 private final ApplicationId appId = new TestApplicationId("test");
124 private static Device device1 = new DefaultDevice(ProviderId.NONE, deviceId(DEV1), ROADM,
125 "m", "h", "s", "n", new ChassisId(0L));
126 private static Device device2 = new DefaultDevice(ProviderId.NONE, deviceId(DEV2), ROADM,
127 "m", "h", "s", "n", new ChassisId(1L));
128
129 private static Annotations annotations1 = DefaultAnnotations.builder().set(STATIC_PORT, STATIC_TRUE).build();
130 private static Annotations annotations2 = DefaultAnnotations.builder().set(PORT_NAME, PNAME).build();
131
132 // OduClt ports with signalType=1GBE
133 private static final OduCltPort D1P1 =
HIGUCHI Yuta4c0ef6b2016-05-02 19:45:41 -0700134 new DefaultOduCltPort(new DefaultPort(device1, PortNumber.portNumber(1), true, annotations1),
135 CltSignalType.CLT_1GBE);
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200136 private static final OduCltPort D2P1 =
HIGUCHI Yuta4c0ef6b2016-05-02 19:45:41 -0700137 new DefaultOduCltPort(new DefaultPort(device2, PortNumber.portNumber(1), true, annotations1),
138 CltSignalType.CLT_1GBE);
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200139
140 // Och ports with signalType=ODU2
141 private static final OchPort D1P2 =
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -0800142 new DefaultOchPort(new DefaultPort(device1, PortNumber.portNumber(2), true, annotations2),
143 OduSignalType.ODU2,
144 true, OchSignal.newDwdmSlot(ChannelSpacing.CHL_50GHZ, 1));
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200145 private static final OchPort D2P2 =
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -0800146 new DefaultOchPort(new DefaultPort(device2, PortNumber.portNumber(2), true, annotations2),
147 OduSignalType.ODU2,
148 true, OchSignal.newDwdmSlot(ChannelSpacing.CHL_50GHZ, 1));
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200149
150 // OduClt ports with signalType=10GBE
151 private static final OduCltPort D1P3 =
HIGUCHI Yuta4c0ef6b2016-05-02 19:45:41 -0700152 new DefaultOduCltPort(new DefaultPort(device1, PortNumber.portNumber(3), true, annotations1),
153 CltSignalType.CLT_10GBE);
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200154 private static final OduCltPort D2P3 =
HIGUCHI Yuta4c0ef6b2016-05-02 19:45:41 -0700155 new DefaultOduCltPort(new DefaultPort(device2, PortNumber.portNumber(3), true, annotations1),
156 CltSignalType.CLT_10GBE);
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200157
158
159 private OpticalCircuitIntent intent;
160
161 /**
162 * Mocks the device service so that devices and ports appear available in the test.
163 */
164 private static class MockDeviceService extends DeviceServiceAdapter {
165 @Override
166 public boolean isAvailable(DeviceId deviceId) {
167 return true;
168 }
169
170 @Override
171 public List<Port> getPorts(DeviceId deviceId) {
172 if (deviceId.equals(deviceId(DEV1))) {
173 return ImmutableList.of((Port) D1P1, (Port) D1P2, (Port) D1P3);
174 }
175
176 if (deviceId.equals(deviceId(DEV2))) {
177 return ImmutableList.of((Port) D2P1, (Port) D2P2, (Port) D2P3);
178 }
179 return Collections.emptyList();
180 }
181
182 @Override
183 public Port getPort(DeviceId deviceId, PortNumber portNumber) {
184 if (deviceId.equals(deviceId(DEV1))) {
185 switch (portNumber.toString()) {
186 case "1":
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -0800187 return D1P1;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200188 case "2":
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -0800189 return D1P2;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200190 case "3":
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -0800191 return D1P3;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200192 default:
193 return null;
194 }
195 }
196 if (deviceId.equals(deviceId(DEV2))) {
197 switch (portNumber.toString()) {
198 case "1":
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -0800199 return D2P1;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200200 case "2":
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -0800201 return D2P2;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200202 case "3":
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -0800203 return D2P3;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200204 default:
205 return null;
206 }
207 }
208 return null;
209 }
210 }
211
212 /**
213 * Mocks the driver service so it will appear supporting TributarySlotQuery Behaviour in the test.
214 */
215 private static class MockDriverServiceWithTs implements DriverService {
216 @Override
217 public Driver getDriver(String driverName) {
218 // TODO Auto-generated method stub
219 return null;
220 }
221
222 @Override
223 public Set<Driver> getDrivers() {
224 // TODO Auto-generated method stub
225 return null;
226 }
227
228 @Override
229 public Set<Driver> getDrivers(Class<? extends Behaviour> withBehaviour) {
230 // TODO Auto-generated method stub
231 return null;
232 }
233
234 @Override
235 public Driver getDriver(String mfr, String hw, String sw) {
236 // TODO Auto-generated method stub
237 return null;
238 }
239
240 @Override
241 public Driver getDriver(DeviceId deviceId) {
242 DefaultDriver ddp = new DefaultDriver("foo.base", new ArrayList<>(), "Circus", "lux", "1.2a",
243 ImmutableMap.of(Behaviour.class,
244 TestBehaviourImpl.class,
245 TributarySlotQuery.class,
246 TestBehaviourTwoImpl.class),
247 ImmutableMap.of("foo", "bar"));
248 return ddp;
249 }
250
251 @Override
252 public DriverHandler createHandler(DeviceId deviceId,
253 String... credentials) {
254 // TODO Auto-generated method stub
255 return null;
256 }
257 }
258
259 /**
260 * Mocks the driver service so it will appear not-supporting TributarySlotQuery Behaviour in the test.
261 */
262 private static class MockDriverServiceNoTs implements DriverService {
263 @Override
264 public Driver getDriver(String driverName) {
265 // TODO Auto-generated method stub
266 return null;
267 }
268
269 @Override
270 public Set<Driver> getDrivers() {
271 // TODO Auto-generated method stub
272 return null;
273 }
274
275 @Override
276 public Set<Driver> getDrivers(Class<? extends Behaviour> withBehaviour) {
277 // TODO Auto-generated method stub
278 return null;
279 }
280
281 @Override
282 public Driver getDriver(String mfr, String hw, String sw) {
283 // TODO Auto-generated method stub
284 return null;
285 }
286
287 @Override
288 public Driver getDriver(DeviceId deviceId) {
289 DefaultDriver ddp = new DefaultDriver("foo.base", new ArrayList<>(), "Circus", "lux", "1.2a",
290 ImmutableMap.of(Behaviour.class,
291 TestBehaviourImpl.class),
292 ImmutableMap.of("foo", "bar"));
293 return ddp;
294 }
295
296 @Override
297 public DriverHandler createHandler(DeviceId deviceId,
298 String... credentials) {
299 // TODO Auto-generated method stub
300 return null;
301 }
302 }
303
304 private static class MockIntentSetMultimap implements IntentSetMultimap {
305 @Override
306 public boolean allocateMapping(IntentId keyIntentId,
307 IntentId valIntentId) {
308 // TODO Auto-generated method stub
309 return false;
310 }
311
312 @Override
313 public Set<IntentId> getMapping(IntentId intentId) {
314 // TODO Auto-generated method stub
315 return null;
316 }
317
318 @Override
319 public void releaseMapping(IntentId intentId) {
320 // TODO Auto-generated method stub
321 }
322
323 }
324
325 /**
326 * Represents a fake IntentService class that easily allows to store and
327 * retrieve intents without implementing the IntentService logic.
328 */
329 private class TestIntentService extends IntentServiceAdapter {
330
331 private Set<Intent> intents;
332
333 public TestIntentService() {
334 intents = Sets.newHashSet();
335 }
336
337 @Override
338 public void submit(Intent intent) {
339 intents.add(intent);
340 }
341
342 @Override
343 public long getIntentCount() {
344 return intents.size();
345 }
346
347 @Override
348 public Iterable<Intent> getIntents() {
349 return intents;
350 }
351
352 @Override
353 public Intent getIntent(Key intentKey) {
354 for (Intent intent : intents) {
355 if (intent.key().equals(intentKey)) {
356 return intent;
357 }
358 }
359 return null;
360 }
361 }
362
HIGUCHI Yuta7a004ae2016-05-28 10:26:03 -0700363 @BeforeClass
364 public static void setUpClass() {
365 AbstractProjectableModel.setDriverService("key", new DriverServiceAdapter());
366 }
367
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200368 @Before
369 public void setUp() {
370 sut = new OpticalCircuitIntentCompiler();
371 coreService = createMock(CoreService.class);
372 expect(coreService.registerApplication("org.onosproject.net.intent"))
373 .andReturn(appId);
374 sut.coreService = coreService;
375 sut.deviceService = new MockDeviceService();
376 sut.resourceService = new MockResourceService();
377 sut.intentService = new TestIntentService();
378 sut.intentSetMultimap = new MockIntentSetMultimap();
379
Thomas Vachuska23235962017-02-03 11:44:15 -0800380 Intent.unbindIdGenerator(idGenerator);
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200381 Intent.bindIdGenerator(idGenerator);
382
383 intentExtensionService = createMock(IntentExtensionService.class);
384 intentExtensionService.registerCompiler(OpticalCircuitIntent.class, sut);
385 intentExtensionService.unregisterCompiler(OpticalCircuitIntent.class);
386 sut.intentManager = intentExtensionService;
387 replay(coreService, intentExtensionService);
388
389 // mocking ComponentConfigService
390 ComponentConfigService mockConfigService =
391 EasyMock.createMock(ComponentConfigService.class);
392 expect(mockConfigService.getProperties(anyObject())).andReturn(ImmutableSet.of());
393 mockConfigService.registerProperties(sut.getClass());
394 expectLastCall();
395 mockConfigService.unregisterProperties(sut.getClass(), false);
396 expectLastCall();
397 expect(mockConfigService.getProperties(anyObject())).andReturn(ImmutableSet.of());
398 sut.cfgService = mockConfigService;
399 replay(mockConfigService);
400
401 }
402
403 @After
404 public void tearDown() {
405 Intent.unbindIdGenerator(idGenerator);
406 }
407
408 /**
409 * Tests compile of OpticalCircuitIntent with allocation of TributarySlots.
410 * Compile two ODUCLT ports (with CLT_1GBE), over OCH ports (with ODU2):
411 * - only one TributarySlot is used
412 */
413 @Test
414 public void test1GbeMultiplexOverOdu2() {
415
416 // Use driver with TributarySlotQuery Behaviour
417 sut.driverService = new MockDriverServiceWithTs();
418
419 ConnectPoint oduCltSrcCP = new ConnectPoint(device1.id(), D1P1.number());
420 ConnectPoint oduCltDstCP = new ConnectPoint(device2.id(), D2P1.number());
421 ConnectPoint ochSrcCP = new ConnectPoint(device1.id(), D1P2.number());
422 ConnectPoint ochDstCP = new ConnectPoint(device2.id(), D2P2.number());
423
424 intent = OpticalCircuitIntent.builder()
425 .appId(APP_ID)
426 .key(KEY1)
427 .src(oduCltSrcCP)
428 .dst(oduCltDstCP)
429 .signalType(D1P1.signalType())
430 .bidirectional(false)
431 .build();
432
433 sut.activate(null);
434
Sho SHIMIZUec07ffd2016-02-22 20:45:21 -0800435 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200436 assertThat(compiled, hasSize(1));
437
Yuta HIGUCHI652f27f2016-10-31 16:54:30 -0700438 assertThat("key is inherited",
439 compiled.stream().map(Intent::key).collect(Collectors.toList()),
440 everyItem(is(intent.key())));
441
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200442 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
443
444 FlowRule rule1 = rules.stream()
445 .filter(x -> x.deviceId().equals(device1.id()))
446 .findFirst()
447 .get();
448 // validate SRC selector
449 TrafficSelector.Builder selectorBuilder1 = DefaultTrafficSelector.builder();
450 selectorBuilder1.matchInPort(oduCltSrcCP.port());
451 selectorBuilder1.add(Criteria.matchOduSignalType(OduSignalType.ODU0));
452 assertThat(rule1.selector(), is(selectorBuilder1.build()));
453
454 // validate SRC treatment (with OduSignalId, where 1 TributarySlot is used)
455 TrafficTreatment.Builder treatmentBuilder1 = DefaultTrafficTreatment.builder();
456 Set<TributarySlot> slots = new HashSet<>();
457 slots.add(TributarySlot.of(1));
Rimon Ashkenazy27438ff2016-03-22 15:57:45 +0200458 OduSignalId oduSignalId = OduSignalUtils.buildOduSignalId(D1P2.signalType(), slots);
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200459 treatmentBuilder1.add(Instructions.modL1OduSignalId(oduSignalId));
460 treatmentBuilder1.setOutput(ochSrcCP.port());
461 assertThat(rule1.treatment(), is(treatmentBuilder1.build()));
462
463 FlowRule rule2 = rules.stream()
464 .filter(x -> x.deviceId().equals(device2.id()))
465 .findFirst()
466 .get();
467 // validate DST selector (with OduSignalId, where the same TributarySlot is used)
468 TrafficSelector.Builder selectorBuilder2 = DefaultTrafficSelector.builder();
469 selectorBuilder2.matchInPort(ochDstCP.port());
470 selectorBuilder2.add(Criteria.matchOduSignalType(OduSignalType.ODU0));
471 selectorBuilder2.add(Criteria.matchOduSignalId(oduSignalId));
472 assertThat(rule2.selector(), is(selectorBuilder2.build()));
473
474 // validate DST treatment
475 assertThat(rule2.treatment(), is(
476 DefaultTrafficTreatment.builder().setOutput(oduCltDstCP.port()).build()
477 ));
478
479 rules.forEach(rule -> assertEquals("FlowRule priority is incorrect",
480 intent.priority(), rule.priority()));
481
482 sut.deactivate();
483 }
484
485 /**
486 * Tests compile of OpticalCircuitIntent with allocation of TributarySlots.
487 * Compile two ODUCLT ports (with CLT_10GBE), over OCH ports (with ODU2):
488 * - All TributarySlots are used
489 */
490 @Test
491 public void test10GbeMultiplexOverOdu2() {
492
493 // Use driver with TributarySlotQuery Behaviour
494 sut.driverService = new MockDriverServiceWithTs();
495
496 ConnectPoint oduCltSrcCP = new ConnectPoint(device1.id(), D1P3.number());
497 ConnectPoint oduCltDstCP = new ConnectPoint(device2.id(), D2P3.number());
498 ConnectPoint ochSrcCP = new ConnectPoint(device1.id(), D1P2.number());
499 ConnectPoint ochDstCP = new ConnectPoint(device2.id(), D2P2.number());
500
501 intent = OpticalCircuitIntent.builder()
502 .appId(APP_ID)
503 .key(KEY1)
504 .src(oduCltSrcCP)
505 .dst(oduCltDstCP)
506 .signalType(D1P3.signalType())
507 .bidirectional(false)
508 .build();
509
510 sut.activate(null);
511
Sho SHIMIZUec07ffd2016-02-22 20:45:21 -0800512 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200513 assertThat(compiled, hasSize(1));
514
Yuta HIGUCHI652f27f2016-10-31 16:54:30 -0700515 assertThat("key is inherited",
516 compiled.stream().map(Intent::key).collect(Collectors.toList()),
517 everyItem(is(intent.key())));
518
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200519 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
520
521 FlowRule rule1 = rules.stream()
522 .filter(x -> x.deviceId().equals(device1.id()))
523 .findFirst()
524 .get();
525 // validate SRC selector
526 TrafficSelector.Builder selectorBuilder1 = DefaultTrafficSelector.builder();
527 selectorBuilder1.matchInPort(oduCltSrcCP.port());
528 selectorBuilder1.add(Criteria.matchOduSignalType(OduSignalType.ODU2));
529 assertThat(rule1.selector(), is(selectorBuilder1.build()));
530
531 // validate SRC treatment (without OduSignalId, i.e. All TributarySlots are used)
532 TrafficTreatment.Builder treatmentBuilder1 = DefaultTrafficTreatment.builder();
533 treatmentBuilder1.setOutput(ochSrcCP.port());
534 assertThat(rule1.treatment(), is(treatmentBuilder1.build()));
535
536 FlowRule rule2 = rules.stream()
537 .filter(x -> x.deviceId().equals(device2.id()))
538 .findFirst()
539 .get();
540 // validate DST selector (without OduSignalId, i.e. All TributarySlots are used)
541 TrafficSelector.Builder selectorBuilder2 = DefaultTrafficSelector.builder();
542 selectorBuilder2.matchInPort(ochDstCP.port());
543 selectorBuilder2.add(Criteria.matchOduSignalType(OduSignalType.ODU2));
544 assertThat(rule2.selector(), is(selectorBuilder2.build()));
545
546 // validate DST treatment
547 assertThat(rule2.treatment(), is(
548 DefaultTrafficTreatment.builder().setOutput(oduCltDstCP.port()).build()
549 ));
550
551 rules.forEach(rule -> assertEquals("FlowRule priority is incorrect",
552 intent.priority(), rule.priority()));
553
554 sut.deactivate();
555 }
556
557 /**
558 * Tests compile of OpticalCircuitIntent without allocation of TributarySlots.
559 * Compile two ODUCLT ports (with CLT_10GBE), over OCH ports (with ODU2):
560 * - No TributarySlots are used
561 */
562 @Test
563 public void test10GbeNoMuxOverOdu2() {
564
565 // Use driver without support for TributarySlotQuery Behaviour
566 sut.driverService = new MockDriverServiceNoTs();
567
568 ConnectPoint oduCltSrcCP = new ConnectPoint(device1.id(), D1P3.number());
569 ConnectPoint oduCltDstCP = new ConnectPoint(device2.id(), D2P3.number());
570 ConnectPoint ochSrcCP = new ConnectPoint(device1.id(), D1P2.number());
571 ConnectPoint ochDstCP = new ConnectPoint(device2.id(), D2P2.number());
572
573 intent = OpticalCircuitIntent.builder()
574 .appId(APP_ID)
575 .key(KEY1)
576 .src(oduCltSrcCP)
577 .dst(oduCltDstCP)
578 .signalType(D1P3.signalType())
579 .bidirectional(false)
580 .build();
581
582 sut.activate(null);
583
Sho SHIMIZUec07ffd2016-02-22 20:45:21 -0800584 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200585 assertThat(compiled, hasSize(1));
586
Yuta HIGUCHI652f27f2016-10-31 16:54:30 -0700587 assertThat("key is inherited",
588 compiled.stream().map(Intent::key).collect(Collectors.toList()),
589 everyItem(is(intent.key())));
590
591
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200592 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
593
594 FlowRule rule1 = rules.stream()
595 .filter(x -> x.deviceId().equals(device1.id()))
596 .findFirst()
597 .get();
598 // validate SRC selector
599 TrafficSelector.Builder selectorBuilder1 = DefaultTrafficSelector.builder();
600 selectorBuilder1.matchInPort(oduCltSrcCP.port());
601 assertThat(rule1.selector(), is(selectorBuilder1.build()));
602
603 // validate SRC treatment (without OduSignalType and OduSignalId: i.e. No TributarySlots are used)
604 TrafficTreatment.Builder treatmentBuilder1 = DefaultTrafficTreatment.builder();
605 treatmentBuilder1.setOutput(ochSrcCP.port());
606 assertThat(rule1.treatment(), is(treatmentBuilder1.build()));
607
608 FlowRule rule2 = rules.stream()
609 .filter(x -> x.deviceId().equals(device2.id()))
610 .findFirst()
611 .get();
612 // validate DST selector (without OduSignalType and OduSignalId: i.e. No TributarySlots are used)
613 TrafficSelector.Builder selectorBuilder2 = DefaultTrafficSelector.builder();
614 selectorBuilder2.matchInPort(ochDstCP.port());
615 assertThat(rule2.selector(), is(selectorBuilder2.build()));
616 // validate DST treatment
617 assertThat(rule2.treatment(), is(
618 DefaultTrafficTreatment.builder().setOutput(oduCltDstCP.port()).build()
619 ));
620
621 rules.forEach(rule -> assertEquals("FlowRule priority is incorrect",
622 intent.priority(), rule.priority()));
623
624 sut.deactivate();
625 }
626
627}