blob: 353925ede761dd40eecc017bccb6232711aab99b [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;
90
91import static org.easymock.EasyMock.anyObject;
92import static org.easymock.EasyMock.createMock;
93import static org.easymock.EasyMock.expect;
94import static org.easymock.EasyMock.expectLastCall;
95import static org.easymock.EasyMock.replay;
96import static org.hamcrest.MatcherAssert.assertThat;
97import static org.hamcrest.Matchers.hasSize;
98import static org.hamcrest.Matchers.is;
99import static org.junit.Assert.assertEquals;
100import static org.onosproject.net.AnnotationKeys.STATIC_PORT;
101import static org.onosproject.net.AnnotationKeys.PORT_NAME;
102import static org.onosproject.net.Device.Type.ROADM;
103import static org.onosproject.net.DeviceId.deviceId;
104import static org.onosproject.net.NetTestTools.APP_ID;
105
106public class OpticalCircuitIntentCompilerTest {
107
108 private static final String DEV1 = "of:1";
109 private static final String DEV2 = "of:2";
110
111 static final Key KEY1 = Key.of(5L, APP_ID);
112
113 private static final String STATIC_TRUE = "true";
114 private static final String PNAME = "p2";
115
116 private CoreService coreService;
117 private IntentExtensionService intentExtensionService;
118 private final IdGenerator idGenerator = new MockIdGenerator();
119 private OpticalCircuitIntentCompiler sut;
120
121 private final ApplicationId appId = new TestApplicationId("test");
122 private static Device device1 = new DefaultDevice(ProviderId.NONE, deviceId(DEV1), ROADM,
123 "m", "h", "s", "n", new ChassisId(0L));
124 private static Device device2 = new DefaultDevice(ProviderId.NONE, deviceId(DEV2), ROADM,
125 "m", "h", "s", "n", new ChassisId(1L));
126
127 private static Annotations annotations1 = DefaultAnnotations.builder().set(STATIC_PORT, STATIC_TRUE).build();
128 private static Annotations annotations2 = DefaultAnnotations.builder().set(PORT_NAME, PNAME).build();
129
130 // OduClt ports with signalType=1GBE
131 private static final OduCltPort D1P1 =
HIGUCHI Yuta4c0ef6b2016-05-02 19:45:41 -0700132 new DefaultOduCltPort(new DefaultPort(device1, PortNumber.portNumber(1), true, annotations1),
133 CltSignalType.CLT_1GBE);
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200134 private static final OduCltPort D2P1 =
HIGUCHI Yuta4c0ef6b2016-05-02 19:45:41 -0700135 new DefaultOduCltPort(new DefaultPort(device2, PortNumber.portNumber(1), true, annotations1),
136 CltSignalType.CLT_1GBE);
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200137
138 // Och ports with signalType=ODU2
139 private static final OchPort D1P2 =
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -0800140 new DefaultOchPort(new DefaultPort(device1, PortNumber.portNumber(2), true, annotations2),
141 OduSignalType.ODU2,
142 true, OchSignal.newDwdmSlot(ChannelSpacing.CHL_50GHZ, 1));
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200143 private static final OchPort D2P2 =
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -0800144 new DefaultOchPort(new DefaultPort(device2, PortNumber.portNumber(2), true, annotations2),
145 OduSignalType.ODU2,
146 true, OchSignal.newDwdmSlot(ChannelSpacing.CHL_50GHZ, 1));
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200147
148 // OduClt ports with signalType=10GBE
149 private static final OduCltPort D1P3 =
HIGUCHI Yuta4c0ef6b2016-05-02 19:45:41 -0700150 new DefaultOduCltPort(new DefaultPort(device1, PortNumber.portNumber(3), true, annotations1),
151 CltSignalType.CLT_10GBE);
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200152 private static final OduCltPort D2P3 =
HIGUCHI Yuta4c0ef6b2016-05-02 19:45:41 -0700153 new DefaultOduCltPort(new DefaultPort(device2, PortNumber.portNumber(3), true, annotations1),
154 CltSignalType.CLT_10GBE);
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200155
156
157 private OpticalCircuitIntent intent;
158
159 /**
160 * Mocks the device service so that devices and ports appear available in the test.
161 */
162 private static class MockDeviceService extends DeviceServiceAdapter {
163 @Override
164 public boolean isAvailable(DeviceId deviceId) {
165 return true;
166 }
167
168 @Override
169 public List<Port> getPorts(DeviceId deviceId) {
170 if (deviceId.equals(deviceId(DEV1))) {
171 return ImmutableList.of((Port) D1P1, (Port) D1P2, (Port) D1P3);
172 }
173
174 if (deviceId.equals(deviceId(DEV2))) {
175 return ImmutableList.of((Port) D2P1, (Port) D2P2, (Port) D2P3);
176 }
177 return Collections.emptyList();
178 }
179
180 @Override
181 public Port getPort(DeviceId deviceId, PortNumber portNumber) {
182 if (deviceId.equals(deviceId(DEV1))) {
183 switch (portNumber.toString()) {
184 case "1":
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -0800185 return D1P1;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200186 case "2":
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -0800187 return D1P2;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200188 case "3":
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -0800189 return D1P3;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200190 default:
191 return null;
192 }
193 }
194 if (deviceId.equals(deviceId(DEV2))) {
195 switch (portNumber.toString()) {
196 case "1":
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -0800197 return D2P1;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200198 case "2":
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -0800199 return D2P2;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200200 case "3":
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -0800201 return D2P3;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200202 default:
203 return null;
204 }
205 }
206 return null;
207 }
208 }
209
210 /**
211 * Mocks the driver service so it will appear supporting TributarySlotQuery Behaviour in the test.
212 */
213 private static class MockDriverServiceWithTs implements DriverService {
214 @Override
215 public Driver getDriver(String driverName) {
216 // TODO Auto-generated method stub
217 return null;
218 }
219
220 @Override
221 public Set<Driver> getDrivers() {
222 // TODO Auto-generated method stub
223 return null;
224 }
225
226 @Override
227 public Set<Driver> getDrivers(Class<? extends Behaviour> withBehaviour) {
228 // TODO Auto-generated method stub
229 return null;
230 }
231
232 @Override
233 public Driver getDriver(String mfr, String hw, String sw) {
234 // TODO Auto-generated method stub
235 return null;
236 }
237
238 @Override
239 public Driver getDriver(DeviceId deviceId) {
240 DefaultDriver ddp = new DefaultDriver("foo.base", new ArrayList<>(), "Circus", "lux", "1.2a",
241 ImmutableMap.of(Behaviour.class,
242 TestBehaviourImpl.class,
243 TributarySlotQuery.class,
244 TestBehaviourTwoImpl.class),
245 ImmutableMap.of("foo", "bar"));
246 return ddp;
247 }
248
249 @Override
250 public DriverHandler createHandler(DeviceId deviceId,
251 String... credentials) {
252 // TODO Auto-generated method stub
253 return null;
254 }
255 }
256
257 /**
258 * Mocks the driver service so it will appear not-supporting TributarySlotQuery Behaviour in the test.
259 */
260 private static class MockDriverServiceNoTs implements DriverService {
261 @Override
262 public Driver getDriver(String driverName) {
263 // TODO Auto-generated method stub
264 return null;
265 }
266
267 @Override
268 public Set<Driver> getDrivers() {
269 // TODO Auto-generated method stub
270 return null;
271 }
272
273 @Override
274 public Set<Driver> getDrivers(Class<? extends Behaviour> withBehaviour) {
275 // TODO Auto-generated method stub
276 return null;
277 }
278
279 @Override
280 public Driver getDriver(String mfr, String hw, String sw) {
281 // TODO Auto-generated method stub
282 return null;
283 }
284
285 @Override
286 public Driver getDriver(DeviceId deviceId) {
287 DefaultDriver ddp = new DefaultDriver("foo.base", new ArrayList<>(), "Circus", "lux", "1.2a",
288 ImmutableMap.of(Behaviour.class,
289 TestBehaviourImpl.class),
290 ImmutableMap.of("foo", "bar"));
291 return ddp;
292 }
293
294 @Override
295 public DriverHandler createHandler(DeviceId deviceId,
296 String... credentials) {
297 // TODO Auto-generated method stub
298 return null;
299 }
300 }
301
302 private static class MockIntentSetMultimap implements IntentSetMultimap {
303 @Override
304 public boolean allocateMapping(IntentId keyIntentId,
305 IntentId valIntentId) {
306 // TODO Auto-generated method stub
307 return false;
308 }
309
310 @Override
311 public Set<IntentId> getMapping(IntentId intentId) {
312 // TODO Auto-generated method stub
313 return null;
314 }
315
316 @Override
317 public void releaseMapping(IntentId intentId) {
318 // TODO Auto-generated method stub
319 }
320
321 }
322
323 /**
324 * Represents a fake IntentService class that easily allows to store and
325 * retrieve intents without implementing the IntentService logic.
326 */
327 private class TestIntentService extends IntentServiceAdapter {
328
329 private Set<Intent> intents;
330
331 public TestIntentService() {
332 intents = Sets.newHashSet();
333 }
334
335 @Override
336 public void submit(Intent intent) {
337 intents.add(intent);
338 }
339
340 @Override
341 public long getIntentCount() {
342 return intents.size();
343 }
344
345 @Override
346 public Iterable<Intent> getIntents() {
347 return intents;
348 }
349
350 @Override
351 public Intent getIntent(Key intentKey) {
352 for (Intent intent : intents) {
353 if (intent.key().equals(intentKey)) {
354 return intent;
355 }
356 }
357 return null;
358 }
359 }
360
HIGUCHI Yuta7a004ae2016-05-28 10:26:03 -0700361 @BeforeClass
362 public static void setUpClass() {
363 AbstractProjectableModel.setDriverService("key", new DriverServiceAdapter());
364 }
365
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200366 @Before
367 public void setUp() {
368 sut = new OpticalCircuitIntentCompiler();
369 coreService = createMock(CoreService.class);
370 expect(coreService.registerApplication("org.onosproject.net.intent"))
371 .andReturn(appId);
372 sut.coreService = coreService;
373 sut.deviceService = new MockDeviceService();
374 sut.resourceService = new MockResourceService();
375 sut.intentService = new TestIntentService();
376 sut.intentSetMultimap = new MockIntentSetMultimap();
377
378 Intent.bindIdGenerator(idGenerator);
379
380 intentExtensionService = createMock(IntentExtensionService.class);
381 intentExtensionService.registerCompiler(OpticalCircuitIntent.class, sut);
382 intentExtensionService.unregisterCompiler(OpticalCircuitIntent.class);
383 sut.intentManager = intentExtensionService;
384 replay(coreService, intentExtensionService);
385
386 // mocking ComponentConfigService
387 ComponentConfigService mockConfigService =
388 EasyMock.createMock(ComponentConfigService.class);
389 expect(mockConfigService.getProperties(anyObject())).andReturn(ImmutableSet.of());
390 mockConfigService.registerProperties(sut.getClass());
391 expectLastCall();
392 mockConfigService.unregisterProperties(sut.getClass(), false);
393 expectLastCall();
394 expect(mockConfigService.getProperties(anyObject())).andReturn(ImmutableSet.of());
395 sut.cfgService = mockConfigService;
396 replay(mockConfigService);
397
398 }
399
400 @After
401 public void tearDown() {
402 Intent.unbindIdGenerator(idGenerator);
403 }
404
405 /**
406 * Tests compile of OpticalCircuitIntent with allocation of TributarySlots.
407 * Compile two ODUCLT ports (with CLT_1GBE), over OCH ports (with ODU2):
408 * - only one TributarySlot is used
409 */
410 @Test
411 public void test1GbeMultiplexOverOdu2() {
412
413 // Use driver with TributarySlotQuery Behaviour
414 sut.driverService = new MockDriverServiceWithTs();
415
416 ConnectPoint oduCltSrcCP = new ConnectPoint(device1.id(), D1P1.number());
417 ConnectPoint oduCltDstCP = new ConnectPoint(device2.id(), D2P1.number());
418 ConnectPoint ochSrcCP = new ConnectPoint(device1.id(), D1P2.number());
419 ConnectPoint ochDstCP = new ConnectPoint(device2.id(), D2P2.number());
420
421 intent = OpticalCircuitIntent.builder()
422 .appId(APP_ID)
423 .key(KEY1)
424 .src(oduCltSrcCP)
425 .dst(oduCltDstCP)
426 .signalType(D1P1.signalType())
427 .bidirectional(false)
428 .build();
429
430 sut.activate(null);
431
Sho SHIMIZUec07ffd2016-02-22 20:45:21 -0800432 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200433 assertThat(compiled, hasSize(1));
434
435 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
436
437 FlowRule rule1 = rules.stream()
438 .filter(x -> x.deviceId().equals(device1.id()))
439 .findFirst()
440 .get();
441 // validate SRC selector
442 TrafficSelector.Builder selectorBuilder1 = DefaultTrafficSelector.builder();
443 selectorBuilder1.matchInPort(oduCltSrcCP.port());
444 selectorBuilder1.add(Criteria.matchOduSignalType(OduSignalType.ODU0));
445 assertThat(rule1.selector(), is(selectorBuilder1.build()));
446
447 // validate SRC treatment (with OduSignalId, where 1 TributarySlot is used)
448 TrafficTreatment.Builder treatmentBuilder1 = DefaultTrafficTreatment.builder();
449 Set<TributarySlot> slots = new HashSet<>();
450 slots.add(TributarySlot.of(1));
Rimon Ashkenazy27438ff2016-03-22 15:57:45 +0200451 OduSignalId oduSignalId = OduSignalUtils.buildOduSignalId(D1P2.signalType(), slots);
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200452 treatmentBuilder1.add(Instructions.modL1OduSignalId(oduSignalId));
453 treatmentBuilder1.setOutput(ochSrcCP.port());
454 assertThat(rule1.treatment(), is(treatmentBuilder1.build()));
455
456 FlowRule rule2 = rules.stream()
457 .filter(x -> x.deviceId().equals(device2.id()))
458 .findFirst()
459 .get();
460 // validate DST selector (with OduSignalId, where the same TributarySlot is used)
461 TrafficSelector.Builder selectorBuilder2 = DefaultTrafficSelector.builder();
462 selectorBuilder2.matchInPort(ochDstCP.port());
463 selectorBuilder2.add(Criteria.matchOduSignalType(OduSignalType.ODU0));
464 selectorBuilder2.add(Criteria.matchOduSignalId(oduSignalId));
465 assertThat(rule2.selector(), is(selectorBuilder2.build()));
466
467 // validate DST treatment
468 assertThat(rule2.treatment(), is(
469 DefaultTrafficTreatment.builder().setOutput(oduCltDstCP.port()).build()
470 ));
471
472 rules.forEach(rule -> assertEquals("FlowRule priority is incorrect",
473 intent.priority(), rule.priority()));
474
475 sut.deactivate();
476 }
477
478 /**
479 * Tests compile of OpticalCircuitIntent with allocation of TributarySlots.
480 * Compile two ODUCLT ports (with CLT_10GBE), over OCH ports (with ODU2):
481 * - All TributarySlots are used
482 */
483 @Test
484 public void test10GbeMultiplexOverOdu2() {
485
486 // Use driver with TributarySlotQuery Behaviour
487 sut.driverService = new MockDriverServiceWithTs();
488
489 ConnectPoint oduCltSrcCP = new ConnectPoint(device1.id(), D1P3.number());
490 ConnectPoint oduCltDstCP = new ConnectPoint(device2.id(), D2P3.number());
491 ConnectPoint ochSrcCP = new ConnectPoint(device1.id(), D1P2.number());
492 ConnectPoint ochDstCP = new ConnectPoint(device2.id(), D2P2.number());
493
494 intent = OpticalCircuitIntent.builder()
495 .appId(APP_ID)
496 .key(KEY1)
497 .src(oduCltSrcCP)
498 .dst(oduCltDstCP)
499 .signalType(D1P3.signalType())
500 .bidirectional(false)
501 .build();
502
503 sut.activate(null);
504
Sho SHIMIZUec07ffd2016-02-22 20:45:21 -0800505 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200506 assertThat(compiled, hasSize(1));
507
508 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
509
510 FlowRule rule1 = rules.stream()
511 .filter(x -> x.deviceId().equals(device1.id()))
512 .findFirst()
513 .get();
514 // validate SRC selector
515 TrafficSelector.Builder selectorBuilder1 = DefaultTrafficSelector.builder();
516 selectorBuilder1.matchInPort(oduCltSrcCP.port());
517 selectorBuilder1.add(Criteria.matchOduSignalType(OduSignalType.ODU2));
518 assertThat(rule1.selector(), is(selectorBuilder1.build()));
519
520 // validate SRC treatment (without OduSignalId, i.e. All TributarySlots are used)
521 TrafficTreatment.Builder treatmentBuilder1 = DefaultTrafficTreatment.builder();
522 treatmentBuilder1.setOutput(ochSrcCP.port());
523 assertThat(rule1.treatment(), is(treatmentBuilder1.build()));
524
525 FlowRule rule2 = rules.stream()
526 .filter(x -> x.deviceId().equals(device2.id()))
527 .findFirst()
528 .get();
529 // validate DST selector (without OduSignalId, i.e. All TributarySlots are used)
530 TrafficSelector.Builder selectorBuilder2 = DefaultTrafficSelector.builder();
531 selectorBuilder2.matchInPort(ochDstCP.port());
532 selectorBuilder2.add(Criteria.matchOduSignalType(OduSignalType.ODU2));
533 assertThat(rule2.selector(), is(selectorBuilder2.build()));
534
535 // validate DST treatment
536 assertThat(rule2.treatment(), is(
537 DefaultTrafficTreatment.builder().setOutput(oduCltDstCP.port()).build()
538 ));
539
540 rules.forEach(rule -> assertEquals("FlowRule priority is incorrect",
541 intent.priority(), rule.priority()));
542
543 sut.deactivate();
544 }
545
546 /**
547 * Tests compile of OpticalCircuitIntent without allocation of TributarySlots.
548 * Compile two ODUCLT ports (with CLT_10GBE), over OCH ports (with ODU2):
549 * - No TributarySlots are used
550 */
551 @Test
552 public void test10GbeNoMuxOverOdu2() {
553
554 // Use driver without support for TributarySlotQuery Behaviour
555 sut.driverService = new MockDriverServiceNoTs();
556
557 ConnectPoint oduCltSrcCP = new ConnectPoint(device1.id(), D1P3.number());
558 ConnectPoint oduCltDstCP = new ConnectPoint(device2.id(), D2P3.number());
559 ConnectPoint ochSrcCP = new ConnectPoint(device1.id(), D1P2.number());
560 ConnectPoint ochDstCP = new ConnectPoint(device2.id(), D2P2.number());
561
562 intent = OpticalCircuitIntent.builder()
563 .appId(APP_ID)
564 .key(KEY1)
565 .src(oduCltSrcCP)
566 .dst(oduCltDstCP)
567 .signalType(D1P3.signalType())
568 .bidirectional(false)
569 .build();
570
571 sut.activate(null);
572
Sho SHIMIZUec07ffd2016-02-22 20:45:21 -0800573 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200574 assertThat(compiled, hasSize(1));
575
576 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}