blob: 1c0eceb8ae25a4609a711c782871809e441654ba [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
380 Intent.bindIdGenerator(idGenerator);
381
382 intentExtensionService = createMock(IntentExtensionService.class);
383 intentExtensionService.registerCompiler(OpticalCircuitIntent.class, sut);
384 intentExtensionService.unregisterCompiler(OpticalCircuitIntent.class);
385 sut.intentManager = intentExtensionService;
386 replay(coreService, intentExtensionService);
387
388 // mocking ComponentConfigService
389 ComponentConfigService mockConfigService =
390 EasyMock.createMock(ComponentConfigService.class);
391 expect(mockConfigService.getProperties(anyObject())).andReturn(ImmutableSet.of());
392 mockConfigService.registerProperties(sut.getClass());
393 expectLastCall();
394 mockConfigService.unregisterProperties(sut.getClass(), false);
395 expectLastCall();
396 expect(mockConfigService.getProperties(anyObject())).andReturn(ImmutableSet.of());
397 sut.cfgService = mockConfigService;
398 replay(mockConfigService);
399
400 }
401
402 @After
403 public void tearDown() {
404 Intent.unbindIdGenerator(idGenerator);
405 }
406
407 /**
408 * Tests compile of OpticalCircuitIntent with allocation of TributarySlots.
409 * Compile two ODUCLT ports (with CLT_1GBE), over OCH ports (with ODU2):
410 * - only one TributarySlot is used
411 */
412 @Test
413 public void test1GbeMultiplexOverOdu2() {
414
415 // Use driver with TributarySlotQuery Behaviour
416 sut.driverService = new MockDriverServiceWithTs();
417
418 ConnectPoint oduCltSrcCP = new ConnectPoint(device1.id(), D1P1.number());
419 ConnectPoint oduCltDstCP = new ConnectPoint(device2.id(), D2P1.number());
420 ConnectPoint ochSrcCP = new ConnectPoint(device1.id(), D1P2.number());
421 ConnectPoint ochDstCP = new ConnectPoint(device2.id(), D2P2.number());
422
423 intent = OpticalCircuitIntent.builder()
424 .appId(APP_ID)
425 .key(KEY1)
426 .src(oduCltSrcCP)
427 .dst(oduCltDstCP)
428 .signalType(D1P1.signalType())
429 .bidirectional(false)
430 .build();
431
432 sut.activate(null);
433
Sho SHIMIZUec07ffd2016-02-22 20:45:21 -0800434 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200435 assertThat(compiled, hasSize(1));
436
Yuta HIGUCHI652f27f2016-10-31 16:54:30 -0700437 assertThat("key is inherited",
438 compiled.stream().map(Intent::key).collect(Collectors.toList()),
439 everyItem(is(intent.key())));
440
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200441 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
442
443 FlowRule rule1 = rules.stream()
444 .filter(x -> x.deviceId().equals(device1.id()))
445 .findFirst()
446 .get();
447 // validate SRC selector
448 TrafficSelector.Builder selectorBuilder1 = DefaultTrafficSelector.builder();
449 selectorBuilder1.matchInPort(oduCltSrcCP.port());
450 selectorBuilder1.add(Criteria.matchOduSignalType(OduSignalType.ODU0));
451 assertThat(rule1.selector(), is(selectorBuilder1.build()));
452
453 // validate SRC treatment (with OduSignalId, where 1 TributarySlot is used)
454 TrafficTreatment.Builder treatmentBuilder1 = DefaultTrafficTreatment.builder();
455 Set<TributarySlot> slots = new HashSet<>();
456 slots.add(TributarySlot.of(1));
Rimon Ashkenazy27438ff2016-03-22 15:57:45 +0200457 OduSignalId oduSignalId = OduSignalUtils.buildOduSignalId(D1P2.signalType(), slots);
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200458 treatmentBuilder1.add(Instructions.modL1OduSignalId(oduSignalId));
459 treatmentBuilder1.setOutput(ochSrcCP.port());
460 assertThat(rule1.treatment(), is(treatmentBuilder1.build()));
461
462 FlowRule rule2 = rules.stream()
463 .filter(x -> x.deviceId().equals(device2.id()))
464 .findFirst()
465 .get();
466 // validate DST selector (with OduSignalId, where the same TributarySlot is used)
467 TrafficSelector.Builder selectorBuilder2 = DefaultTrafficSelector.builder();
468 selectorBuilder2.matchInPort(ochDstCP.port());
469 selectorBuilder2.add(Criteria.matchOduSignalType(OduSignalType.ODU0));
470 selectorBuilder2.add(Criteria.matchOduSignalId(oduSignalId));
471 assertThat(rule2.selector(), is(selectorBuilder2.build()));
472
473 // validate DST treatment
474 assertThat(rule2.treatment(), is(
475 DefaultTrafficTreatment.builder().setOutput(oduCltDstCP.port()).build()
476 ));
477
478 rules.forEach(rule -> assertEquals("FlowRule priority is incorrect",
479 intent.priority(), rule.priority()));
480
481 sut.deactivate();
482 }
483
484 /**
485 * Tests compile of OpticalCircuitIntent with allocation of TributarySlots.
486 * Compile two ODUCLT ports (with CLT_10GBE), over OCH ports (with ODU2):
487 * - All TributarySlots are used
488 */
489 @Test
490 public void test10GbeMultiplexOverOdu2() {
491
492 // Use driver with TributarySlotQuery Behaviour
493 sut.driverService = new MockDriverServiceWithTs();
494
495 ConnectPoint oduCltSrcCP = new ConnectPoint(device1.id(), D1P3.number());
496 ConnectPoint oduCltDstCP = new ConnectPoint(device2.id(), D2P3.number());
497 ConnectPoint ochSrcCP = new ConnectPoint(device1.id(), D1P2.number());
498 ConnectPoint ochDstCP = new ConnectPoint(device2.id(), D2P2.number());
499
500 intent = OpticalCircuitIntent.builder()
501 .appId(APP_ID)
502 .key(KEY1)
503 .src(oduCltSrcCP)
504 .dst(oduCltDstCP)
505 .signalType(D1P3.signalType())
506 .bidirectional(false)
507 .build();
508
509 sut.activate(null);
510
Sho SHIMIZUec07ffd2016-02-22 20:45:21 -0800511 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200512 assertThat(compiled, hasSize(1));
513
Yuta HIGUCHI652f27f2016-10-31 16:54:30 -0700514 assertThat("key is inherited",
515 compiled.stream().map(Intent::key).collect(Collectors.toList()),
516 everyItem(is(intent.key())));
517
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200518 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
519
520 FlowRule rule1 = rules.stream()
521 .filter(x -> x.deviceId().equals(device1.id()))
522 .findFirst()
523 .get();
524 // validate SRC selector
525 TrafficSelector.Builder selectorBuilder1 = DefaultTrafficSelector.builder();
526 selectorBuilder1.matchInPort(oduCltSrcCP.port());
527 selectorBuilder1.add(Criteria.matchOduSignalType(OduSignalType.ODU2));
528 assertThat(rule1.selector(), is(selectorBuilder1.build()));
529
530 // validate SRC treatment (without OduSignalId, i.e. All TributarySlots are used)
531 TrafficTreatment.Builder treatmentBuilder1 = DefaultTrafficTreatment.builder();
532 treatmentBuilder1.setOutput(ochSrcCP.port());
533 assertThat(rule1.treatment(), is(treatmentBuilder1.build()));
534
535 FlowRule rule2 = rules.stream()
536 .filter(x -> x.deviceId().equals(device2.id()))
537 .findFirst()
538 .get();
539 // validate DST selector (without OduSignalId, i.e. All TributarySlots are used)
540 TrafficSelector.Builder selectorBuilder2 = DefaultTrafficSelector.builder();
541 selectorBuilder2.matchInPort(ochDstCP.port());
542 selectorBuilder2.add(Criteria.matchOduSignalType(OduSignalType.ODU2));
543 assertThat(rule2.selector(), is(selectorBuilder2.build()));
544
545 // validate DST treatment
546 assertThat(rule2.treatment(), is(
547 DefaultTrafficTreatment.builder().setOutput(oduCltDstCP.port()).build()
548 ));
549
550 rules.forEach(rule -> assertEquals("FlowRule priority is incorrect",
551 intent.priority(), rule.priority()));
552
553 sut.deactivate();
554 }
555
556 /**
557 * Tests compile of OpticalCircuitIntent without allocation of TributarySlots.
558 * Compile two ODUCLT ports (with CLT_10GBE), over OCH ports (with ODU2):
559 * - No TributarySlots are used
560 */
561 @Test
562 public void test10GbeNoMuxOverOdu2() {
563
564 // Use driver without support for TributarySlotQuery Behaviour
565 sut.driverService = new MockDriverServiceNoTs();
566
567 ConnectPoint oduCltSrcCP = new ConnectPoint(device1.id(), D1P3.number());
568 ConnectPoint oduCltDstCP = new ConnectPoint(device2.id(), D2P3.number());
569 ConnectPoint ochSrcCP = new ConnectPoint(device1.id(), D1P2.number());
570 ConnectPoint ochDstCP = new ConnectPoint(device2.id(), D2P2.number());
571
572 intent = OpticalCircuitIntent.builder()
573 .appId(APP_ID)
574 .key(KEY1)
575 .src(oduCltSrcCP)
576 .dst(oduCltDstCP)
577 .signalType(D1P3.signalType())
578 .bidirectional(false)
579 .build();
580
581 sut.activate(null);
582
Sho SHIMIZUec07ffd2016-02-22 20:45:21 -0800583 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200584 assertThat(compiled, hasSize(1));
585
Yuta HIGUCHI652f27f2016-10-31 16:54:30 -0700586 assertThat("key is inherited",
587 compiled.stream().map(Intent::key).collect(Collectors.toList()),
588 everyItem(is(intent.key())));
589
590
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200591 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
592
593 FlowRule rule1 = rules.stream()
594 .filter(x -> x.deviceId().equals(device1.id()))
595 .findFirst()
596 .get();
597 // validate SRC selector
598 TrafficSelector.Builder selectorBuilder1 = DefaultTrafficSelector.builder();
599 selectorBuilder1.matchInPort(oduCltSrcCP.port());
600 assertThat(rule1.selector(), is(selectorBuilder1.build()));
601
602 // validate SRC treatment (without OduSignalType and OduSignalId: i.e. No TributarySlots are used)
603 TrafficTreatment.Builder treatmentBuilder1 = DefaultTrafficTreatment.builder();
604 treatmentBuilder1.setOutput(ochSrcCP.port());
605 assertThat(rule1.treatment(), is(treatmentBuilder1.build()));
606
607 FlowRule rule2 = rules.stream()
608 .filter(x -> x.deviceId().equals(device2.id()))
609 .findFirst()
610 .get();
611 // validate DST selector (without OduSignalType and OduSignalId: i.e. No TributarySlots are used)
612 TrafficSelector.Builder selectorBuilder2 = DefaultTrafficSelector.builder();
613 selectorBuilder2.matchInPort(ochDstCP.port());
614 assertThat(rule2.selector(), is(selectorBuilder2.build()));
615 // validate DST treatment
616 assertThat(rule2.treatment(), is(
617 DefaultTrafficTreatment.builder().setOutput(oduCltDstCP.port()).build()
618 ));
619
620 rules.forEach(rule -> assertEquals("FlowRule priority is incorrect",
621 intent.priority(), rule.priority()));
622
623 sut.deactivate();
624 }
625
626}