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