blob: ab0af5a552608112b5ba9aba54403b133890cb2a [file] [log] [blame]
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +02001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +02003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Yuta HIGUCHId95d5902016-06-27 00:18:45 -070016package org.onosproject.net.optical.intent.impl.compiler;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +020017
Thomas Vachuska2048c1f2017-05-10 19:32:22 -070018import com.google.common.collect.ImmutableList;
19import com.google.common.collect.ImmutableMap;
20import com.google.common.collect.ImmutableSet;
21import com.google.common.collect.Sets;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +020022import org.easymock.EasyMock;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +020023import org.junit.Before;
HIGUCHI Yuta7a004ae2016-05-28 10:26:03 -070024import org.junit.BeforeClass;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +020025import org.junit.Test;
26import org.onlab.packet.ChassisId;
27import org.onosproject.TestApplicationId;
28import org.onosproject.cfg.ComponentConfigService;
29import org.onosproject.core.ApplicationId;
30import org.onosproject.core.CoreService;
HIGUCHI Yuta7a004ae2016-05-28 10:26:03 -070031import org.onosproject.net.AbstractProjectableModel;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +020032import org.onosproject.net.Annotations;
33import org.onosproject.net.ChannelSpacing;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +020034import org.onosproject.net.CltSignalType;
35import org.onosproject.net.ConnectPoint;
Thomas Vachuska2048c1f2017-05-10 19:32:22 -070036import org.onosproject.net.DefaultAnnotations;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +020037import org.onosproject.net.DefaultDevice;
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -080038import org.onosproject.net.DefaultPort;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +020039import org.onosproject.net.Device;
40import org.onosproject.net.DeviceId;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +020041import org.onosproject.net.OchSignal;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +020042import org.onosproject.net.OduSignalId;
43import org.onosproject.net.OduSignalType;
Rimon Ashkenazy27438ff2016-03-22 15:57:45 +020044import org.onosproject.net.OduSignalUtils;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +020045import org.onosproject.net.Port;
46import org.onosproject.net.PortNumber;
47import org.onosproject.net.TributarySlot;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +020048import org.onosproject.net.behaviour.TributarySlotQuery;
49import org.onosproject.net.device.DeviceServiceAdapter;
50import org.onosproject.net.driver.Behaviour;
51import org.onosproject.net.driver.DefaultDriver;
52import org.onosproject.net.driver.Driver;
HIGUCHI Yuta7a004ae2016-05-28 10:26:03 -070053import org.onosproject.net.driver.DriverServiceAdapter;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +020054import org.onosproject.net.driver.TestBehaviourImpl;
55import org.onosproject.net.driver.TestBehaviourTwoImpl;
Thomas Vachuska2048c1f2017-05-10 19:32:22 -070056import org.onosproject.net.flow.DefaultTrafficSelector;
57import org.onosproject.net.flow.DefaultTrafficTreatment;
58import org.onosproject.net.flow.FlowRule;
59import org.onosproject.net.flow.TrafficSelector;
60import org.onosproject.net.flow.TrafficTreatment;
61import org.onosproject.net.flow.criteria.Criteria;
62import org.onosproject.net.flow.instructions.Instructions;
63import org.onosproject.net.intent.AbstractIntentTest;
64import org.onosproject.net.intent.FlowRuleIntent;
65import org.onosproject.net.intent.Intent;
66import org.onosproject.net.intent.IntentExtensionService;
67import org.onosproject.net.intent.IntentId;
68import org.onosproject.net.intent.IntentServiceAdapter;
69import org.onosproject.net.intent.IntentSetMultimap;
70import org.onosproject.net.intent.Key;
71import org.onosproject.net.intent.OpticalCircuitIntent;
72import org.onosproject.net.optical.OchPort;
73import org.onosproject.net.optical.OduCltPort;
74import org.onosproject.net.optical.impl.DefaultOchPort;
75import org.onosproject.net.optical.impl.DefaultOduCltPort;
76import org.onosproject.net.provider.ProviderId;
77import org.onosproject.net.resource.MockResourceService;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +020078
79import java.util.ArrayList;
80import java.util.Collection;
81import java.util.Collections;
82import java.util.HashSet;
83import java.util.List;
84import java.util.Set;
Yuta HIGUCHI652f27f2016-10-31 16:54:30 -070085import java.util.stream.Collectors;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +020086
Thomas Vachuska2048c1f2017-05-10 19:32:22 -070087import static org.easymock.EasyMock.*;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +020088import static org.hamcrest.MatcherAssert.assertThat;
Thomas Vachuska2048c1f2017-05-10 19:32:22 -070089import static org.hamcrest.Matchers.*;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +020090import static org.junit.Assert.assertEquals;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +020091import static org.onosproject.net.AnnotationKeys.PORT_NAME;
Thomas Vachuska2048c1f2017-05-10 19:32:22 -070092import static org.onosproject.net.AnnotationKeys.STATIC_PORT;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +020093import static org.onosproject.net.Device.Type.ROADM;
94import static org.onosproject.net.DeviceId.deviceId;
95import static org.onosproject.net.NetTestTools.APP_ID;
96
Thomas Vachuska2048c1f2017-05-10 19:32:22 -070097public class OpticalCircuitIntentCompilerTest extends AbstractIntentTest {
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +020098
99 private static final String DEV1 = "of:1";
100 private static final String DEV2 = "of:2";
101
102 static final Key KEY1 = Key.of(5L, APP_ID);
103
104 private static final String STATIC_TRUE = "true";
105 private static final String PNAME = "p2";
106
107 private CoreService coreService;
108 private IntentExtensionService intentExtensionService;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200109 private OpticalCircuitIntentCompiler sut;
110
111 private final ApplicationId appId = new TestApplicationId("test");
112 private static Device device1 = new DefaultDevice(ProviderId.NONE, deviceId(DEV1), ROADM,
113 "m", "h", "s", "n", new ChassisId(0L));
114 private static Device device2 = new DefaultDevice(ProviderId.NONE, deviceId(DEV2), ROADM,
115 "m", "h", "s", "n", new ChassisId(1L));
116
117 private static Annotations annotations1 = DefaultAnnotations.builder().set(STATIC_PORT, STATIC_TRUE).build();
118 private static Annotations annotations2 = DefaultAnnotations.builder().set(PORT_NAME, PNAME).build();
119
120 // OduClt ports with signalType=1GBE
121 private static final OduCltPort D1P1 =
HIGUCHI Yuta4c0ef6b2016-05-02 19:45:41 -0700122 new DefaultOduCltPort(new DefaultPort(device1, PortNumber.portNumber(1), true, annotations1),
123 CltSignalType.CLT_1GBE);
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200124 private static final OduCltPort D2P1 =
HIGUCHI Yuta4c0ef6b2016-05-02 19:45:41 -0700125 new DefaultOduCltPort(new DefaultPort(device2, PortNumber.portNumber(1), true, annotations1),
126 CltSignalType.CLT_1GBE);
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200127
128 // Och ports with signalType=ODU2
129 private static final OchPort D1P2 =
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -0800130 new DefaultOchPort(new DefaultPort(device1, PortNumber.portNumber(2), true, annotations2),
131 OduSignalType.ODU2,
132 true, OchSignal.newDwdmSlot(ChannelSpacing.CHL_50GHZ, 1));
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200133 private static final OchPort D2P2 =
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -0800134 new DefaultOchPort(new DefaultPort(device2, PortNumber.portNumber(2), true, annotations2),
135 OduSignalType.ODU2,
136 true, OchSignal.newDwdmSlot(ChannelSpacing.CHL_50GHZ, 1));
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200137
138 // OduClt ports with signalType=10GBE
139 private static final OduCltPort D1P3 =
HIGUCHI Yuta4c0ef6b2016-05-02 19:45:41 -0700140 new DefaultOduCltPort(new DefaultPort(device1, PortNumber.portNumber(3), true, annotations1),
141 CltSignalType.CLT_10GBE);
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200142 private static final OduCltPort D2P3 =
HIGUCHI Yuta4c0ef6b2016-05-02 19:45:41 -0700143 new DefaultOduCltPort(new DefaultPort(device2, PortNumber.portNumber(3), true, annotations1),
144 CltSignalType.CLT_10GBE);
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200145
146
147 private OpticalCircuitIntent intent;
148
149 /**
150 * Mocks the device service so that devices and ports appear available in the test.
151 */
152 private static class MockDeviceService extends DeviceServiceAdapter {
153 @Override
154 public boolean isAvailable(DeviceId deviceId) {
155 return true;
156 }
157
158 @Override
159 public List<Port> getPorts(DeviceId deviceId) {
160 if (deviceId.equals(deviceId(DEV1))) {
161 return ImmutableList.of((Port) D1P1, (Port) D1P2, (Port) D1P3);
162 }
163
164 if (deviceId.equals(deviceId(DEV2))) {
165 return ImmutableList.of((Port) D2P1, (Port) D2P2, (Port) D2P3);
166 }
167 return Collections.emptyList();
168 }
169
170 @Override
171 public Port getPort(DeviceId deviceId, PortNumber portNumber) {
172 if (deviceId.equals(deviceId(DEV1))) {
173 switch (portNumber.toString()) {
174 case "1":
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -0800175 return D1P1;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200176 case "2":
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -0800177 return D1P2;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200178 case "3":
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -0800179 return D1P3;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200180 default:
181 return null;
182 }
183 }
184 if (deviceId.equals(deviceId(DEV2))) {
185 switch (portNumber.toString()) {
186 case "1":
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -0800187 return D2P1;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200188 case "2":
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -0800189 return D2P2;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200190 case "3":
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -0800191 return D2P3;
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200192 default:
193 return null;
194 }
195 }
196 return null;
197 }
198 }
199
200 /**
201 * Mocks the driver service so it will appear supporting TributarySlotQuery Behaviour in the test.
202 */
Thomas Vachuskae6a57412017-08-23 14:09:14 -0700203 private static class MockDriverServiceWithTs extends DriverServiceAdapter {
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200204 @Override
205 public Driver getDriver(DeviceId deviceId) {
206 DefaultDriver ddp = new DefaultDriver("foo.base", new ArrayList<>(), "Circus", "lux", "1.2a",
207 ImmutableMap.of(Behaviour.class,
208 TestBehaviourImpl.class,
209 TributarySlotQuery.class,
210 TestBehaviourTwoImpl.class),
211 ImmutableMap.of("foo", "bar"));
212 return ddp;
213 }
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200214 }
215
216 /**
217 * Mocks the driver service so it will appear not-supporting TributarySlotQuery Behaviour in the test.
218 */
Thomas Vachuskae6a57412017-08-23 14:09:14 -0700219 private static class MockDriverServiceNoTs extends DriverServiceAdapter {
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200220 @Override
221 public Driver getDriver(DeviceId deviceId) {
222 DefaultDriver ddp = new DefaultDriver("foo.base", new ArrayList<>(), "Circus", "lux", "1.2a",
223 ImmutableMap.of(Behaviour.class,
224 TestBehaviourImpl.class),
225 ImmutableMap.of("foo", "bar"));
226 return ddp;
227 }
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200228 }
229
230 private static class MockIntentSetMultimap implements IntentSetMultimap {
231 @Override
232 public boolean allocateMapping(IntentId keyIntentId,
233 IntentId valIntentId) {
234 // TODO Auto-generated method stub
235 return false;
236 }
237
238 @Override
239 public Set<IntentId> getMapping(IntentId intentId) {
240 // TODO Auto-generated method stub
241 return null;
242 }
243
244 @Override
245 public void releaseMapping(IntentId intentId) {
246 // TODO Auto-generated method stub
247 }
248
249 }
250
251 /**
252 * Represents a fake IntentService class that easily allows to store and
253 * retrieve intents without implementing the IntentService logic.
254 */
255 private class TestIntentService extends IntentServiceAdapter {
256
257 private Set<Intent> intents;
258
259 public TestIntentService() {
260 intents = Sets.newHashSet();
261 }
262
263 @Override
264 public void submit(Intent intent) {
265 intents.add(intent);
266 }
267
268 @Override
269 public long getIntentCount() {
270 return intents.size();
271 }
272
273 @Override
274 public Iterable<Intent> getIntents() {
275 return intents;
276 }
277
278 @Override
279 public Intent getIntent(Key intentKey) {
280 for (Intent intent : intents) {
281 if (intent.key().equals(intentKey)) {
282 return intent;
283 }
284 }
285 return null;
286 }
287 }
288
HIGUCHI Yuta7a004ae2016-05-28 10:26:03 -0700289 @BeforeClass
290 public static void setUpClass() {
291 AbstractProjectableModel.setDriverService("key", new DriverServiceAdapter());
292 }
293
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200294 @Before
295 public void setUp() {
296 sut = new OpticalCircuitIntentCompiler();
297 coreService = createMock(CoreService.class);
298 expect(coreService.registerApplication("org.onosproject.net.intent"))
299 .andReturn(appId);
300 sut.coreService = coreService;
301 sut.deviceService = new MockDeviceService();
302 sut.resourceService = new MockResourceService();
303 sut.intentService = new TestIntentService();
304 sut.intentSetMultimap = new MockIntentSetMultimap();
305
Thomas Vachuska2048c1f2017-05-10 19:32:22 -0700306 super.setUp();
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200307
308 intentExtensionService = createMock(IntentExtensionService.class);
309 intentExtensionService.registerCompiler(OpticalCircuitIntent.class, sut);
310 intentExtensionService.unregisterCompiler(OpticalCircuitIntent.class);
311 sut.intentManager = intentExtensionService;
312 replay(coreService, intentExtensionService);
313
314 // mocking ComponentConfigService
315 ComponentConfigService mockConfigService =
316 EasyMock.createMock(ComponentConfigService.class);
317 expect(mockConfigService.getProperties(anyObject())).andReturn(ImmutableSet.of());
318 mockConfigService.registerProperties(sut.getClass());
319 expectLastCall();
320 mockConfigService.unregisterProperties(sut.getClass(), false);
321 expectLastCall();
322 expect(mockConfigService.getProperties(anyObject())).andReturn(ImmutableSet.of());
323 sut.cfgService = mockConfigService;
324 replay(mockConfigService);
325
326 }
327
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200328 /**
329 * Tests compile of OpticalCircuitIntent with allocation of TributarySlots.
330 * Compile two ODUCLT ports (with CLT_1GBE), over OCH ports (with ODU2):
331 * - only one TributarySlot is used
332 */
333 @Test
334 public void test1GbeMultiplexOverOdu2() {
335
336 // Use driver with TributarySlotQuery Behaviour
337 sut.driverService = new MockDriverServiceWithTs();
338
339 ConnectPoint oduCltSrcCP = new ConnectPoint(device1.id(), D1P1.number());
340 ConnectPoint oduCltDstCP = new ConnectPoint(device2.id(), D2P1.number());
341 ConnectPoint ochSrcCP = new ConnectPoint(device1.id(), D1P2.number());
342 ConnectPoint ochDstCP = new ConnectPoint(device2.id(), D2P2.number());
343
344 intent = OpticalCircuitIntent.builder()
345 .appId(APP_ID)
346 .key(KEY1)
347 .src(oduCltSrcCP)
348 .dst(oduCltDstCP)
349 .signalType(D1P1.signalType())
350 .bidirectional(false)
351 .build();
352
353 sut.activate(null);
354
Sho SHIMIZUec07ffd2016-02-22 20:45:21 -0800355 List<Intent> compiled = sut.compile(intent, Collections.emptyList());
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200356 assertThat(compiled, hasSize(1));
357
Yuta HIGUCHI652f27f2016-10-31 16:54:30 -0700358 assertThat("key is inherited",
359 compiled.stream().map(Intent::key).collect(Collectors.toList()),
360 everyItem(is(intent.key())));
361
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200362 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
363
364 FlowRule rule1 = rules.stream()
365 .filter(x -> x.deviceId().equals(device1.id()))
366 .findFirst()
367 .get();
368 // validate SRC selector
369 TrafficSelector.Builder selectorBuilder1 = DefaultTrafficSelector.builder();
370 selectorBuilder1.matchInPort(oduCltSrcCP.port());
371 selectorBuilder1.add(Criteria.matchOduSignalType(OduSignalType.ODU0));
372 assertThat(rule1.selector(), is(selectorBuilder1.build()));
373
374 // validate SRC treatment (with OduSignalId, where 1 TributarySlot is used)
375 TrafficTreatment.Builder treatmentBuilder1 = DefaultTrafficTreatment.builder();
376 Set<TributarySlot> slots = new HashSet<>();
377 slots.add(TributarySlot.of(1));
Rimon Ashkenazy27438ff2016-03-22 15:57:45 +0200378 OduSignalId oduSignalId = OduSignalUtils.buildOduSignalId(D1P2.signalType(), slots);
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200379 treatmentBuilder1.add(Instructions.modL1OduSignalId(oduSignalId));
380 treatmentBuilder1.setOutput(ochSrcCP.port());
381 assertThat(rule1.treatment(), is(treatmentBuilder1.build()));
382
383 FlowRule rule2 = rules.stream()
384 .filter(x -> x.deviceId().equals(device2.id()))
385 .findFirst()
386 .get();
387 // validate DST selector (with OduSignalId, where the same TributarySlot is used)
388 TrafficSelector.Builder selectorBuilder2 = DefaultTrafficSelector.builder();
389 selectorBuilder2.matchInPort(ochDstCP.port());
390 selectorBuilder2.add(Criteria.matchOduSignalType(OduSignalType.ODU0));
391 selectorBuilder2.add(Criteria.matchOduSignalId(oduSignalId));
392 assertThat(rule2.selector(), is(selectorBuilder2.build()));
393
394 // validate DST treatment
395 assertThat(rule2.treatment(), is(
396 DefaultTrafficTreatment.builder().setOutput(oduCltDstCP.port()).build()
397 ));
398
399 rules.forEach(rule -> assertEquals("FlowRule priority is incorrect",
400 intent.priority(), rule.priority()));
401
402 sut.deactivate();
403 }
404
405 /**
406 * Tests compile of OpticalCircuitIntent with allocation of TributarySlots.
407 * Compile two ODUCLT ports (with CLT_10GBE), over OCH ports (with ODU2):
408 * - All TributarySlots are used
409 */
410 @Test
411 public void test10GbeMultiplexOverOdu2() {
412
413 // Use driver with TributarySlotQuery Behaviour
414 sut.driverService = new MockDriverServiceWithTs();
415
416 ConnectPoint oduCltSrcCP = new ConnectPoint(device1.id(), D1P3.number());
417 ConnectPoint oduCltDstCP = new ConnectPoint(device2.id(), D2P3.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(D1P3.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
Yuta HIGUCHI652f27f2016-10-31 16:54:30 -0700435 assertThat("key is inherited",
436 compiled.stream().map(Intent::key).collect(Collectors.toList()),
437 everyItem(is(intent.key())));
438
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200439 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
440
441 FlowRule rule1 = rules.stream()
442 .filter(x -> x.deviceId().equals(device1.id()))
443 .findFirst()
444 .get();
445 // validate SRC selector
446 TrafficSelector.Builder selectorBuilder1 = DefaultTrafficSelector.builder();
447 selectorBuilder1.matchInPort(oduCltSrcCP.port());
448 selectorBuilder1.add(Criteria.matchOduSignalType(OduSignalType.ODU2));
449 assertThat(rule1.selector(), is(selectorBuilder1.build()));
450
451 // validate SRC treatment (without OduSignalId, i.e. All TributarySlots are used)
452 TrafficTreatment.Builder treatmentBuilder1 = DefaultTrafficTreatment.builder();
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 (without OduSignalId, i.e. All TributarySlots are used)
461 TrafficSelector.Builder selectorBuilder2 = DefaultTrafficSelector.builder();
462 selectorBuilder2.matchInPort(ochDstCP.port());
463 selectorBuilder2.add(Criteria.matchOduSignalType(OduSignalType.ODU2));
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 without allocation of TributarySlots.
479 * Compile two ODUCLT ports (with CLT_10GBE), over OCH ports (with ODU2):
480 * - No TributarySlots are used
481 */
482 @Test
483 public void test10GbeNoMuxOverOdu2() {
484
485 // Use driver without support for TributarySlotQuery Behaviour
486 sut.driverService = new MockDriverServiceNoTs();
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
Yuta HIGUCHI652f27f2016-10-31 16:54:30 -0700507 assertThat("key is inherited",
508 compiled.stream().map(Intent::key).collect(Collectors.toList()),
509 everyItem(is(intent.key())));
510
511
Rimon Ashkenazya4e3bd32016-02-22 16:12:20 +0200512 Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
513
514 FlowRule rule1 = rules.stream()
515 .filter(x -> x.deviceId().equals(device1.id()))
516 .findFirst()
517 .get();
518 // validate SRC selector
519 TrafficSelector.Builder selectorBuilder1 = DefaultTrafficSelector.builder();
520 selectorBuilder1.matchInPort(oduCltSrcCP.port());
521 assertThat(rule1.selector(), is(selectorBuilder1.build()));
522
523 // validate SRC treatment (without OduSignalType and OduSignalId: i.e. No TributarySlots are used)
524 TrafficTreatment.Builder treatmentBuilder1 = DefaultTrafficTreatment.builder();
525 treatmentBuilder1.setOutput(ochSrcCP.port());
526 assertThat(rule1.treatment(), is(treatmentBuilder1.build()));
527
528 FlowRule rule2 = rules.stream()
529 .filter(x -> x.deviceId().equals(device2.id()))
530 .findFirst()
531 .get();
532 // validate DST selector (without OduSignalType and OduSignalId: i.e. No TributarySlots are used)
533 TrafficSelector.Builder selectorBuilder2 = DefaultTrafficSelector.builder();
534 selectorBuilder2.matchInPort(ochDstCP.port());
535 assertThat(rule2.selector(), is(selectorBuilder2.build()));
536 // validate DST treatment
537 assertThat(rule2.treatment(), is(
538 DefaultTrafficTreatment.builder().setOutput(oduCltDstCP.port()).build()
539 ));
540
541 rules.forEach(rule -> assertEquals("FlowRule priority is incorrect",
542 intent.priority(), rule.priority()));
543
544 sut.deactivate();
545 }
546
547}