Committed by
Gerrit Code Review
Add OpticalCircuitIntentCompiler unit-tests
Change-Id: I9cf002dcda128874b5fd4727ba0f99189fe9143d
Showing
3 changed files
with
607 additions
and
1 deletions
... | @@ -124,6 +124,10 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu | ... | @@ -124,6 +124,10 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu |
124 | 124 | ||
125 | @Modified | 125 | @Modified |
126 | public void modified(ComponentContext context) { | 126 | public void modified(ComponentContext context) { |
127 | + if (context == null) { | ||
128 | + return; | ||
129 | + } | ||
130 | + | ||
127 | Dictionary properties = context.getProperties(); | 131 | Dictionary properties = context.getProperties(); |
128 | 132 | ||
129 | //TODO for reduction check if the new capacity is smaller than the size of the current mapping | 133 | //TODO for reduction check if the new capacity is smaller than the size of the current mapping |
... | @@ -556,7 +560,7 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu | ... | @@ -556,7 +560,7 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu |
556 | return flowRule; | 560 | return flowRule; |
557 | } | 561 | } |
558 | 562 | ||
559 | - private OduSignalId buildOduSignalId(OduSignalType ochPortSignalType, Set<TributarySlot> slots) { | 563 | + protected OduSignalId buildOduSignalId(OduSignalType ochPortSignalType, Set<TributarySlot> slots) { |
560 | int tributaryPortNumber = findFirstTributarySlotIndex(slots); | 564 | int tributaryPortNumber = findFirstTributarySlotIndex(slots); |
561 | int tributarySlotLen = ochPortSignalType.tributarySlots(); | 565 | int tributarySlotLen = ochPortSignalType.tributarySlots(); |
562 | byte[] tributarySlotBitmap = new byte[OduSignalId.TRIBUTARY_SLOT_BITMAP_SIZE]; | 566 | byte[] tributarySlotBitmap = new byte[OduSignalId.TRIBUTARY_SLOT_BITMAP_SIZE]; | ... | ... |
... | @@ -17,9 +17,11 @@ package org.onosproject.net.intent.impl.compiler; | ... | @@ -17,9 +17,11 @@ package org.onosproject.net.intent.impl.compiler; |
17 | 17 | ||
18 | import com.google.common.collect.ImmutableList; | 18 | import com.google.common.collect.ImmutableList; |
19 | import com.google.common.collect.ImmutableSet; | 19 | import com.google.common.collect.ImmutableSet; |
20 | + | ||
20 | import org.onlab.packet.MplsLabel; | 21 | import org.onlab.packet.MplsLabel; |
21 | import org.onlab.packet.VlanId; | 22 | import org.onlab.packet.VlanId; |
22 | import org.onlab.util.Tools; | 23 | import org.onlab.util.Tools; |
24 | +import org.onosproject.net.TributarySlot; | ||
23 | import org.onosproject.net.newresource.ContinuousResourceId; | 25 | import org.onosproject.net.newresource.ContinuousResourceId; |
24 | import org.onosproject.net.newresource.DiscreteResource; | 26 | import org.onosproject.net.newresource.DiscreteResource; |
25 | import org.onosproject.net.newresource.DiscreteResourceId; | 27 | import org.onosproject.net.newresource.DiscreteResourceId; |
... | @@ -108,6 +110,14 @@ class MockResourceService implements ResourceService { | ... | @@ -108,6 +110,14 @@ class MockResourceService implements ResourceService { |
108 | Collection<Resource> resources = new HashSet<>(); | 110 | Collection<Resource> resources = new HashSet<>(); |
109 | resources.add(Resources.discrete(parent).resource().child(VlanId.vlanId((short) 10))); | 111 | resources.add(Resources.discrete(parent).resource().child(VlanId.vlanId((short) 10))); |
110 | resources.add(Resources.discrete(parent).resource().child(MplsLabel.mplsLabel(10))); | 112 | resources.add(Resources.discrete(parent).resource().child(MplsLabel.mplsLabel(10))); |
113 | + resources.add(Resources.discrete(parent).resource().child(TributarySlot.of(1))); | ||
114 | + resources.add(Resources.discrete(parent).resource().child(TributarySlot.of(2))); | ||
115 | + resources.add(Resources.discrete(parent).resource().child(TributarySlot.of(3))); | ||
116 | + resources.add(Resources.discrete(parent).resource().child(TributarySlot.of(4))); | ||
117 | + resources.add(Resources.discrete(parent).resource().child(TributarySlot.of(5))); | ||
118 | + resources.add(Resources.discrete(parent).resource().child(TributarySlot.of(6))); | ||
119 | + resources.add(Resources.discrete(parent).resource().child(TributarySlot.of(7))); | ||
120 | + resources.add(Resources.discrete(parent).resource().child(TributarySlot.of(8))); | ||
111 | return ImmutableSet.copyOf(resources); | 121 | return ImmutableSet.copyOf(resources); |
112 | } | 122 | } |
113 | 123 | ... | ... |
1 | +/* | ||
2 | + * Copyright 2016 Open Networking Laboratory | ||
3 | + * | ||
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 | + */ | ||
16 | +package org.onosproject.net.intent.impl.compiler; | ||
17 | + | ||
18 | +import org.easymock.EasyMock; | ||
19 | +import org.junit.After; | ||
20 | +import org.junit.Before; | ||
21 | +import org.junit.Test; | ||
22 | +import org.onlab.packet.ChassisId; | ||
23 | +import org.onosproject.TestApplicationId; | ||
24 | +import org.onosproject.cfg.ComponentConfigService; | ||
25 | +import org.onosproject.core.ApplicationId; | ||
26 | +import org.onosproject.core.CoreService; | ||
27 | +import org.onosproject.core.IdGenerator; | ||
28 | +import org.onosproject.net.Annotations; | ||
29 | +import org.onosproject.net.ChannelSpacing; | ||
30 | +import org.onosproject.net.DefaultAnnotations; | ||
31 | +import org.onosproject.net.CltSignalType; | ||
32 | +import org.onosproject.net.ConnectPoint; | ||
33 | +import org.onosproject.net.DefaultDevice; | ||
34 | +import org.onosproject.net.Device; | ||
35 | +import org.onosproject.net.DeviceId; | ||
36 | +import org.onosproject.net.OchPort; | ||
37 | +import org.onosproject.net.OchSignal; | ||
38 | +import org.onosproject.net.OduCltPort; | ||
39 | +import org.onosproject.net.OduSignalId; | ||
40 | +import org.onosproject.net.OduSignalType; | ||
41 | +import org.onosproject.net.Port; | ||
42 | +import org.onosproject.net.PortNumber; | ||
43 | +import org.onosproject.net.TributarySlot; | ||
44 | +import org.onosproject.net.flow.DefaultTrafficSelector; | ||
45 | +import org.onosproject.net.flow.DefaultTrafficTreatment; | ||
46 | +import org.onosproject.net.flow.FlowRule; | ||
47 | +import org.onosproject.net.flow.TrafficSelector; | ||
48 | +import org.onosproject.net.flow.TrafficTreatment; | ||
49 | +import org.onosproject.net.flow.criteria.Criteria; | ||
50 | +import org.onosproject.net.flow.instructions.Instructions; | ||
51 | +import org.onosproject.net.intent.FlowRuleIntent; | ||
52 | +import org.onosproject.net.intent.Intent; | ||
53 | +import org.onosproject.net.intent.IntentExtensionService; | ||
54 | +import org.onosproject.net.intent.IntentId; | ||
55 | +import org.onosproject.net.intent.IntentServiceAdapter; | ||
56 | +import org.onosproject.net.intent.Key; | ||
57 | +import org.onosproject.net.intent.MockIdGenerator; | ||
58 | +import org.onosproject.net.intent.OpticalCircuitIntent; | ||
59 | +import org.onosproject.net.provider.ProviderId; | ||
60 | +import org.onosproject.net.resource.device.IntentSetMultimap; | ||
61 | +import org.onosproject.net.behaviour.TributarySlotQuery; | ||
62 | +import org.onosproject.net.device.DeviceServiceAdapter; | ||
63 | +import org.onosproject.net.driver.Behaviour; | ||
64 | +import org.onosproject.net.driver.DefaultDriver; | ||
65 | +import org.onosproject.net.driver.Driver; | ||
66 | +import org.onosproject.net.driver.DriverHandler; | ||
67 | +import org.onosproject.net.driver.DriverService; | ||
68 | +import org.onosproject.net.driver.TestBehaviourImpl; | ||
69 | +import org.onosproject.net.driver.TestBehaviourTwoImpl; | ||
70 | + | ||
71 | +import com.google.common.collect.ImmutableList; | ||
72 | +import com.google.common.collect.ImmutableMap; | ||
73 | +import com.google.common.collect.ImmutableSet; | ||
74 | +import com.google.common.collect.Sets; | ||
75 | + | ||
76 | +import java.util.ArrayList; | ||
77 | +import java.util.Collection; | ||
78 | +import java.util.Collections; | ||
79 | +import java.util.HashSet; | ||
80 | +import java.util.List; | ||
81 | +import java.util.Set; | ||
82 | + | ||
83 | +import static org.easymock.EasyMock.anyObject; | ||
84 | +import static org.easymock.EasyMock.createMock; | ||
85 | +import static org.easymock.EasyMock.expect; | ||
86 | +import static org.easymock.EasyMock.expectLastCall; | ||
87 | +import static org.easymock.EasyMock.replay; | ||
88 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
89 | +import static org.hamcrest.Matchers.hasSize; | ||
90 | +import static org.hamcrest.Matchers.is; | ||
91 | +import static org.junit.Assert.assertEquals; | ||
92 | +import static org.onosproject.net.AnnotationKeys.STATIC_PORT; | ||
93 | +import static org.onosproject.net.AnnotationKeys.PORT_NAME; | ||
94 | +import static org.onosproject.net.Device.Type.ROADM; | ||
95 | +import static org.onosproject.net.DeviceId.deviceId; | ||
96 | +import static org.onosproject.net.NetTestTools.APP_ID; | ||
97 | + | ||
98 | +public class OpticalCircuitIntentCompilerTest { | ||
99 | + | ||
100 | + private static final String DEV1 = "of:1"; | ||
101 | + private static final String DEV2 = "of:2"; | ||
102 | + | ||
103 | + static final Key KEY1 = Key.of(5L, APP_ID); | ||
104 | + | ||
105 | + private static final String STATIC_TRUE = "true"; | ||
106 | + private static final String PNAME = "p2"; | ||
107 | + | ||
108 | + private CoreService coreService; | ||
109 | + private IntentExtensionService intentExtensionService; | ||
110 | + private final IdGenerator idGenerator = new MockIdGenerator(); | ||
111 | + private OpticalCircuitIntentCompiler sut; | ||
112 | + | ||
113 | + private final ApplicationId appId = new TestApplicationId("test"); | ||
114 | + private static Device device1 = new DefaultDevice(ProviderId.NONE, deviceId(DEV1), ROADM, | ||
115 | + "m", "h", "s", "n", new ChassisId(0L)); | ||
116 | + private static Device device2 = new DefaultDevice(ProviderId.NONE, deviceId(DEV2), ROADM, | ||
117 | + "m", "h", "s", "n", new ChassisId(1L)); | ||
118 | + | ||
119 | + private static Annotations annotations1 = DefaultAnnotations.builder().set(STATIC_PORT, STATIC_TRUE).build(); | ||
120 | + private static Annotations annotations2 = DefaultAnnotations.builder().set(PORT_NAME, PNAME).build(); | ||
121 | + | ||
122 | + // OduClt ports with signalType=1GBE | ||
123 | + private static final OduCltPort D1P1 = | ||
124 | + new OduCltPort(device1, PortNumber.portNumber(1), true, CltSignalType.CLT_1GBE, annotations1); | ||
125 | + private static final OduCltPort D2P1 = | ||
126 | + new OduCltPort(device2, PortNumber.portNumber(1), true, CltSignalType.CLT_1GBE, annotations1); | ||
127 | + | ||
128 | + // Och ports with signalType=ODU2 | ||
129 | + private static final OchPort D1P2 = | ||
130 | + new OchPort(device1, PortNumber.portNumber(2), true, OduSignalType.ODU2, | ||
131 | + true, OchSignal.newDwdmSlot(ChannelSpacing.CHL_50GHZ, 1), annotations2); | ||
132 | + private static final OchPort D2P2 = | ||
133 | + new OchPort(device2, PortNumber.portNumber(2), true, OduSignalType.ODU2, | ||
134 | + true, OchSignal.newDwdmSlot(ChannelSpacing.CHL_50GHZ, 1), annotations2); | ||
135 | + | ||
136 | + // OduClt ports with signalType=10GBE | ||
137 | + private static final OduCltPort D1P3 = | ||
138 | + new OduCltPort(device1, PortNumber.portNumber(3), true, CltSignalType.CLT_10GBE, annotations1); | ||
139 | + private static final OduCltPort D2P3 = | ||
140 | + new OduCltPort(device2, PortNumber.portNumber(3), true, CltSignalType.CLT_10GBE, annotations1); | ||
141 | + | ||
142 | + | ||
143 | + private OpticalCircuitIntent intent; | ||
144 | + | ||
145 | + /** | ||
146 | + * Mocks the device service so that devices and ports appear available in the test. | ||
147 | + */ | ||
148 | + private static class MockDeviceService extends DeviceServiceAdapter { | ||
149 | + @Override | ||
150 | + public boolean isAvailable(DeviceId deviceId) { | ||
151 | + return true; | ||
152 | + } | ||
153 | + | ||
154 | + @Override | ||
155 | + public List<Port> getPorts(DeviceId deviceId) { | ||
156 | + if (deviceId.equals(deviceId(DEV1))) { | ||
157 | + return ImmutableList.of((Port) D1P1, (Port) D1P2, (Port) D1P3); | ||
158 | + } | ||
159 | + | ||
160 | + if (deviceId.equals(deviceId(DEV2))) { | ||
161 | + return ImmutableList.of((Port) D2P1, (Port) D2P2, (Port) D2P3); | ||
162 | + } | ||
163 | + return Collections.emptyList(); | ||
164 | + } | ||
165 | + | ||
166 | + @Override | ||
167 | + public Port getPort(DeviceId deviceId, PortNumber portNumber) { | ||
168 | + if (deviceId.equals(deviceId(DEV1))) { | ||
169 | + switch (portNumber.toString()) { | ||
170 | + case "1": | ||
171 | + return (Port) D1P1; | ||
172 | + case "2": | ||
173 | + return (Port) D1P2; | ||
174 | + case "3": | ||
175 | + return (Port) D1P3; | ||
176 | + default: | ||
177 | + return null; | ||
178 | + } | ||
179 | + } | ||
180 | + if (deviceId.equals(deviceId(DEV2))) { | ||
181 | + switch (portNumber.toString()) { | ||
182 | + case "1": | ||
183 | + return (Port) D2P1; | ||
184 | + case "2": | ||
185 | + return (Port) D2P2; | ||
186 | + case "3": | ||
187 | + return (Port) D2P3; | ||
188 | + default: | ||
189 | + return null; | ||
190 | + } | ||
191 | + } | ||
192 | + return null; | ||
193 | + } | ||
194 | + } | ||
195 | + | ||
196 | + /** | ||
197 | + * Mocks the driver service so it will appear supporting TributarySlotQuery Behaviour in the test. | ||
198 | + */ | ||
199 | + private static class MockDriverServiceWithTs implements DriverService { | ||
200 | + @Override | ||
201 | + public Driver getDriver(String driverName) { | ||
202 | + // TODO Auto-generated method stub | ||
203 | + return null; | ||
204 | + } | ||
205 | + | ||
206 | + @Override | ||
207 | + public Set<Driver> getDrivers() { | ||
208 | + // TODO Auto-generated method stub | ||
209 | + return null; | ||
210 | + } | ||
211 | + | ||
212 | + @Override | ||
213 | + public Set<Driver> getDrivers(Class<? extends Behaviour> withBehaviour) { | ||
214 | + // TODO Auto-generated method stub | ||
215 | + return null; | ||
216 | + } | ||
217 | + | ||
218 | + @Override | ||
219 | + public Driver getDriver(String mfr, String hw, String sw) { | ||
220 | + // TODO Auto-generated method stub | ||
221 | + return null; | ||
222 | + } | ||
223 | + | ||
224 | + @Override | ||
225 | + public Driver getDriver(DeviceId deviceId) { | ||
226 | + DefaultDriver ddp = new DefaultDriver("foo.base", new ArrayList<>(), "Circus", "lux", "1.2a", | ||
227 | + ImmutableMap.of(Behaviour.class, | ||
228 | + TestBehaviourImpl.class, | ||
229 | + TributarySlotQuery.class, | ||
230 | + TestBehaviourTwoImpl.class), | ||
231 | + ImmutableMap.of("foo", "bar")); | ||
232 | + return ddp; | ||
233 | + } | ||
234 | + | ||
235 | + @Override | ||
236 | + public DriverHandler createHandler(DeviceId deviceId, | ||
237 | + String... credentials) { | ||
238 | + // TODO Auto-generated method stub | ||
239 | + return null; | ||
240 | + } | ||
241 | + } | ||
242 | + | ||
243 | + /** | ||
244 | + * Mocks the driver service so it will appear not-supporting TributarySlotQuery Behaviour in the test. | ||
245 | + */ | ||
246 | + private static class MockDriverServiceNoTs implements DriverService { | ||
247 | + @Override | ||
248 | + public Driver getDriver(String driverName) { | ||
249 | + // TODO Auto-generated method stub | ||
250 | + return null; | ||
251 | + } | ||
252 | + | ||
253 | + @Override | ||
254 | + public Set<Driver> getDrivers() { | ||
255 | + // TODO Auto-generated method stub | ||
256 | + return null; | ||
257 | + } | ||
258 | + | ||
259 | + @Override | ||
260 | + public Set<Driver> getDrivers(Class<? extends Behaviour> withBehaviour) { | ||
261 | + // TODO Auto-generated method stub | ||
262 | + return null; | ||
263 | + } | ||
264 | + | ||
265 | + @Override | ||
266 | + public Driver getDriver(String mfr, String hw, String sw) { | ||
267 | + // TODO Auto-generated method stub | ||
268 | + return null; | ||
269 | + } | ||
270 | + | ||
271 | + @Override | ||
272 | + public Driver getDriver(DeviceId deviceId) { | ||
273 | + DefaultDriver ddp = new DefaultDriver("foo.base", new ArrayList<>(), "Circus", "lux", "1.2a", | ||
274 | + ImmutableMap.of(Behaviour.class, | ||
275 | + TestBehaviourImpl.class), | ||
276 | + ImmutableMap.of("foo", "bar")); | ||
277 | + return ddp; | ||
278 | + } | ||
279 | + | ||
280 | + @Override | ||
281 | + public DriverHandler createHandler(DeviceId deviceId, | ||
282 | + String... credentials) { | ||
283 | + // TODO Auto-generated method stub | ||
284 | + return null; | ||
285 | + } | ||
286 | + } | ||
287 | + | ||
288 | + private static class MockIntentSetMultimap implements IntentSetMultimap { | ||
289 | + @Override | ||
290 | + public boolean allocateMapping(IntentId keyIntentId, | ||
291 | + IntentId valIntentId) { | ||
292 | + // TODO Auto-generated method stub | ||
293 | + return false; | ||
294 | + } | ||
295 | + | ||
296 | + @Override | ||
297 | + public Set<IntentId> getMapping(IntentId intentId) { | ||
298 | + // TODO Auto-generated method stub | ||
299 | + return null; | ||
300 | + } | ||
301 | + | ||
302 | + @Override | ||
303 | + public void releaseMapping(IntentId intentId) { | ||
304 | + // TODO Auto-generated method stub | ||
305 | + } | ||
306 | + | ||
307 | + } | ||
308 | + | ||
309 | + /** | ||
310 | + * Represents a fake IntentService class that easily allows to store and | ||
311 | + * retrieve intents without implementing the IntentService logic. | ||
312 | + */ | ||
313 | + private class TestIntentService extends IntentServiceAdapter { | ||
314 | + | ||
315 | + private Set<Intent> intents; | ||
316 | + | ||
317 | + public TestIntentService() { | ||
318 | + intents = Sets.newHashSet(); | ||
319 | + } | ||
320 | + | ||
321 | + @Override | ||
322 | + public void submit(Intent intent) { | ||
323 | + intents.add(intent); | ||
324 | + } | ||
325 | + | ||
326 | + @Override | ||
327 | + public long getIntentCount() { | ||
328 | + return intents.size(); | ||
329 | + } | ||
330 | + | ||
331 | + @Override | ||
332 | + public Iterable<Intent> getIntents() { | ||
333 | + return intents; | ||
334 | + } | ||
335 | + | ||
336 | + @Override | ||
337 | + public Intent getIntent(Key intentKey) { | ||
338 | + for (Intent intent : intents) { | ||
339 | + if (intent.key().equals(intentKey)) { | ||
340 | + return intent; | ||
341 | + } | ||
342 | + } | ||
343 | + return null; | ||
344 | + } | ||
345 | + } | ||
346 | + | ||
347 | + @Before | ||
348 | + public void setUp() { | ||
349 | + sut = new OpticalCircuitIntentCompiler(); | ||
350 | + coreService = createMock(CoreService.class); | ||
351 | + expect(coreService.registerApplication("org.onosproject.net.intent")) | ||
352 | + .andReturn(appId); | ||
353 | + sut.coreService = coreService; | ||
354 | + sut.deviceService = new MockDeviceService(); | ||
355 | + sut.resourceService = new MockResourceService(); | ||
356 | + sut.intentService = new TestIntentService(); | ||
357 | + sut.intentSetMultimap = new MockIntentSetMultimap(); | ||
358 | + | ||
359 | + Intent.bindIdGenerator(idGenerator); | ||
360 | + | ||
361 | + intentExtensionService = createMock(IntentExtensionService.class); | ||
362 | + intentExtensionService.registerCompiler(OpticalCircuitIntent.class, sut); | ||
363 | + intentExtensionService.unregisterCompiler(OpticalCircuitIntent.class); | ||
364 | + sut.intentManager = intentExtensionService; | ||
365 | + replay(coreService, intentExtensionService); | ||
366 | + | ||
367 | + // mocking ComponentConfigService | ||
368 | + ComponentConfigService mockConfigService = | ||
369 | + EasyMock.createMock(ComponentConfigService.class); | ||
370 | + expect(mockConfigService.getProperties(anyObject())).andReturn(ImmutableSet.of()); | ||
371 | + mockConfigService.registerProperties(sut.getClass()); | ||
372 | + expectLastCall(); | ||
373 | + mockConfigService.unregisterProperties(sut.getClass(), false); | ||
374 | + expectLastCall(); | ||
375 | + expect(mockConfigService.getProperties(anyObject())).andReturn(ImmutableSet.of()); | ||
376 | + sut.cfgService = mockConfigService; | ||
377 | + replay(mockConfigService); | ||
378 | + | ||
379 | + } | ||
380 | + | ||
381 | + @After | ||
382 | + public void tearDown() { | ||
383 | + Intent.unbindIdGenerator(idGenerator); | ||
384 | + } | ||
385 | + | ||
386 | + /** | ||
387 | + * Tests compile of OpticalCircuitIntent with allocation of TributarySlots. | ||
388 | + * Compile two ODUCLT ports (with CLT_1GBE), over OCH ports (with ODU2): | ||
389 | + * - only one TributarySlot is used | ||
390 | + */ | ||
391 | + @Test | ||
392 | + public void test1GbeMultiplexOverOdu2() { | ||
393 | + | ||
394 | + // Use driver with TributarySlotQuery Behaviour | ||
395 | + sut.driverService = new MockDriverServiceWithTs(); | ||
396 | + | ||
397 | + ConnectPoint oduCltSrcCP = new ConnectPoint(device1.id(), D1P1.number()); | ||
398 | + ConnectPoint oduCltDstCP = new ConnectPoint(device2.id(), D2P1.number()); | ||
399 | + ConnectPoint ochSrcCP = new ConnectPoint(device1.id(), D1P2.number()); | ||
400 | + ConnectPoint ochDstCP = new ConnectPoint(device2.id(), D2P2.number()); | ||
401 | + | ||
402 | + intent = OpticalCircuitIntent.builder() | ||
403 | + .appId(APP_ID) | ||
404 | + .key(KEY1) | ||
405 | + .src(oduCltSrcCP) | ||
406 | + .dst(oduCltDstCP) | ||
407 | + .signalType(D1P1.signalType()) | ||
408 | + .bidirectional(false) | ||
409 | + .build(); | ||
410 | + | ||
411 | + sut.activate(null); | ||
412 | + | ||
413 | + List<Intent> compiled = sut.compile(intent, Collections.emptyList(), Collections.emptySet()); | ||
414 | + assertThat(compiled, hasSize(1)); | ||
415 | + | ||
416 | + Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules(); | ||
417 | + | ||
418 | + FlowRule rule1 = rules.stream() | ||
419 | + .filter(x -> x.deviceId().equals(device1.id())) | ||
420 | + .findFirst() | ||
421 | + .get(); | ||
422 | + // validate SRC selector | ||
423 | + TrafficSelector.Builder selectorBuilder1 = DefaultTrafficSelector.builder(); | ||
424 | + selectorBuilder1.matchInPort(oduCltSrcCP.port()); | ||
425 | + selectorBuilder1.add(Criteria.matchOduSignalType(OduSignalType.ODU0)); | ||
426 | + assertThat(rule1.selector(), is(selectorBuilder1.build())); | ||
427 | + | ||
428 | + // validate SRC treatment (with OduSignalId, where 1 TributarySlot is used) | ||
429 | + TrafficTreatment.Builder treatmentBuilder1 = DefaultTrafficTreatment.builder(); | ||
430 | + Set<TributarySlot> slots = new HashSet<>(); | ||
431 | + slots.add(TributarySlot.of(1)); | ||
432 | + OduSignalId oduSignalId = sut.buildOduSignalId(D1P2.signalType(), slots); | ||
433 | + treatmentBuilder1.add(Instructions.modL1OduSignalId(oduSignalId)); | ||
434 | + treatmentBuilder1.setOutput(ochSrcCP.port()); | ||
435 | + assertThat(rule1.treatment(), is(treatmentBuilder1.build())); | ||
436 | + | ||
437 | + FlowRule rule2 = rules.stream() | ||
438 | + .filter(x -> x.deviceId().equals(device2.id())) | ||
439 | + .findFirst() | ||
440 | + .get(); | ||
441 | + // validate DST selector (with OduSignalId, where the same TributarySlot is used) | ||
442 | + TrafficSelector.Builder selectorBuilder2 = DefaultTrafficSelector.builder(); | ||
443 | + selectorBuilder2.matchInPort(ochDstCP.port()); | ||
444 | + selectorBuilder2.add(Criteria.matchOduSignalType(OduSignalType.ODU0)); | ||
445 | + selectorBuilder2.add(Criteria.matchOduSignalId(oduSignalId)); | ||
446 | + assertThat(rule2.selector(), is(selectorBuilder2.build())); | ||
447 | + | ||
448 | + // validate DST treatment | ||
449 | + assertThat(rule2.treatment(), is( | ||
450 | + DefaultTrafficTreatment.builder().setOutput(oduCltDstCP.port()).build() | ||
451 | + )); | ||
452 | + | ||
453 | + rules.forEach(rule -> assertEquals("FlowRule priority is incorrect", | ||
454 | + intent.priority(), rule.priority())); | ||
455 | + | ||
456 | + sut.deactivate(); | ||
457 | + } | ||
458 | + | ||
459 | + /** | ||
460 | + * Tests compile of OpticalCircuitIntent with allocation of TributarySlots. | ||
461 | + * Compile two ODUCLT ports (with CLT_10GBE), over OCH ports (with ODU2): | ||
462 | + * - All TributarySlots are used | ||
463 | + */ | ||
464 | + @Test | ||
465 | + public void test10GbeMultiplexOverOdu2() { | ||
466 | + | ||
467 | + // Use driver with TributarySlotQuery Behaviour | ||
468 | + sut.driverService = new MockDriverServiceWithTs(); | ||
469 | + | ||
470 | + ConnectPoint oduCltSrcCP = new ConnectPoint(device1.id(), D1P3.number()); | ||
471 | + ConnectPoint oduCltDstCP = new ConnectPoint(device2.id(), D2P3.number()); | ||
472 | + ConnectPoint ochSrcCP = new ConnectPoint(device1.id(), D1P2.number()); | ||
473 | + ConnectPoint ochDstCP = new ConnectPoint(device2.id(), D2P2.number()); | ||
474 | + | ||
475 | + intent = OpticalCircuitIntent.builder() | ||
476 | + .appId(APP_ID) | ||
477 | + .key(KEY1) | ||
478 | + .src(oduCltSrcCP) | ||
479 | + .dst(oduCltDstCP) | ||
480 | + .signalType(D1P3.signalType()) | ||
481 | + .bidirectional(false) | ||
482 | + .build(); | ||
483 | + | ||
484 | + sut.activate(null); | ||
485 | + | ||
486 | + List<Intent> compiled = sut.compile(intent, Collections.emptyList(), Collections.emptySet()); | ||
487 | + assertThat(compiled, hasSize(1)); | ||
488 | + | ||
489 | + Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules(); | ||
490 | + | ||
491 | + FlowRule rule1 = rules.stream() | ||
492 | + .filter(x -> x.deviceId().equals(device1.id())) | ||
493 | + .findFirst() | ||
494 | + .get(); | ||
495 | + // validate SRC selector | ||
496 | + TrafficSelector.Builder selectorBuilder1 = DefaultTrafficSelector.builder(); | ||
497 | + selectorBuilder1.matchInPort(oduCltSrcCP.port()); | ||
498 | + selectorBuilder1.add(Criteria.matchOduSignalType(OduSignalType.ODU2)); | ||
499 | + assertThat(rule1.selector(), is(selectorBuilder1.build())); | ||
500 | + | ||
501 | + // validate SRC treatment (without OduSignalId, i.e. All TributarySlots are used) | ||
502 | + TrafficTreatment.Builder treatmentBuilder1 = DefaultTrafficTreatment.builder(); | ||
503 | + treatmentBuilder1.setOutput(ochSrcCP.port()); | ||
504 | + assertThat(rule1.treatment(), is(treatmentBuilder1.build())); | ||
505 | + | ||
506 | + FlowRule rule2 = rules.stream() | ||
507 | + .filter(x -> x.deviceId().equals(device2.id())) | ||
508 | + .findFirst() | ||
509 | + .get(); | ||
510 | + // validate DST selector (without OduSignalId, i.e. All TributarySlots are used) | ||
511 | + TrafficSelector.Builder selectorBuilder2 = DefaultTrafficSelector.builder(); | ||
512 | + selectorBuilder2.matchInPort(ochDstCP.port()); | ||
513 | + selectorBuilder2.add(Criteria.matchOduSignalType(OduSignalType.ODU2)); | ||
514 | + assertThat(rule2.selector(), is(selectorBuilder2.build())); | ||
515 | + | ||
516 | + // validate DST treatment | ||
517 | + assertThat(rule2.treatment(), is( | ||
518 | + DefaultTrafficTreatment.builder().setOutput(oduCltDstCP.port()).build() | ||
519 | + )); | ||
520 | + | ||
521 | + rules.forEach(rule -> assertEquals("FlowRule priority is incorrect", | ||
522 | + intent.priority(), rule.priority())); | ||
523 | + | ||
524 | + sut.deactivate(); | ||
525 | + } | ||
526 | + | ||
527 | + /** | ||
528 | + * Tests compile of OpticalCircuitIntent without allocation of TributarySlots. | ||
529 | + * Compile two ODUCLT ports (with CLT_10GBE), over OCH ports (with ODU2): | ||
530 | + * - No TributarySlots are used | ||
531 | + */ | ||
532 | + @Test | ||
533 | + public void test10GbeNoMuxOverOdu2() { | ||
534 | + | ||
535 | + // Use driver without support for TributarySlotQuery Behaviour | ||
536 | + sut.driverService = new MockDriverServiceNoTs(); | ||
537 | + | ||
538 | + ConnectPoint oduCltSrcCP = new ConnectPoint(device1.id(), D1P3.number()); | ||
539 | + ConnectPoint oduCltDstCP = new ConnectPoint(device2.id(), D2P3.number()); | ||
540 | + ConnectPoint ochSrcCP = new ConnectPoint(device1.id(), D1P2.number()); | ||
541 | + ConnectPoint ochDstCP = new ConnectPoint(device2.id(), D2P2.number()); | ||
542 | + | ||
543 | + intent = OpticalCircuitIntent.builder() | ||
544 | + .appId(APP_ID) | ||
545 | + .key(KEY1) | ||
546 | + .src(oduCltSrcCP) | ||
547 | + .dst(oduCltDstCP) | ||
548 | + .signalType(D1P3.signalType()) | ||
549 | + .bidirectional(false) | ||
550 | + .build(); | ||
551 | + | ||
552 | + sut.activate(null); | ||
553 | + | ||
554 | + List<Intent> compiled = sut.compile(intent, Collections.emptyList(), Collections.emptySet()); | ||
555 | + assertThat(compiled, hasSize(1)); | ||
556 | + | ||
557 | + Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules(); | ||
558 | + | ||
559 | + FlowRule rule1 = rules.stream() | ||
560 | + .filter(x -> x.deviceId().equals(device1.id())) | ||
561 | + .findFirst() | ||
562 | + .get(); | ||
563 | + // validate SRC selector | ||
564 | + TrafficSelector.Builder selectorBuilder1 = DefaultTrafficSelector.builder(); | ||
565 | + selectorBuilder1.matchInPort(oduCltSrcCP.port()); | ||
566 | + assertThat(rule1.selector(), is(selectorBuilder1.build())); | ||
567 | + | ||
568 | + // validate SRC treatment (without OduSignalType and OduSignalId: i.e. No TributarySlots are used) | ||
569 | + TrafficTreatment.Builder treatmentBuilder1 = DefaultTrafficTreatment.builder(); | ||
570 | + treatmentBuilder1.setOutput(ochSrcCP.port()); | ||
571 | + assertThat(rule1.treatment(), is(treatmentBuilder1.build())); | ||
572 | + | ||
573 | + FlowRule rule2 = rules.stream() | ||
574 | + .filter(x -> x.deviceId().equals(device2.id())) | ||
575 | + .findFirst() | ||
576 | + .get(); | ||
577 | + // validate DST selector (without OduSignalType and OduSignalId: i.e. No TributarySlots are used) | ||
578 | + TrafficSelector.Builder selectorBuilder2 = DefaultTrafficSelector.builder(); | ||
579 | + selectorBuilder2.matchInPort(ochDstCP.port()); | ||
580 | + assertThat(rule2.selector(), is(selectorBuilder2.build())); | ||
581 | + // validate DST treatment | ||
582 | + assertThat(rule2.treatment(), is( | ||
583 | + DefaultTrafficTreatment.builder().setOutput(oduCltDstCP.port()).build() | ||
584 | + )); | ||
585 | + | ||
586 | + rules.forEach(rule -> assertEquals("FlowRule priority is incorrect", | ||
587 | + intent.priority(), rule.priority())); | ||
588 | + | ||
589 | + sut.deactivate(); | ||
590 | + } | ||
591 | + | ||
592 | +} |
-
Please register or login to post a comment