Rimon Ashkenazy | a4e3bd3 | 2016-02-22 16:12:20 +0200 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Rimon Ashkenazy | a4e3bd3 | 2016-02-22 16:12:20 +0200 | [diff] [blame] | 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 | */ |
Yuta HIGUCHI | d95d590 | 2016-06-27 00:18:45 -0700 | [diff] [blame] | 16 | package org.onosproject.net.optical.intent.impl.compiler; |
Rimon Ashkenazy | a4e3bd3 | 2016-02-22 16:12:20 +0200 | [diff] [blame] | 17 | |
| 18 | import org.easymock.EasyMock; |
| 19 | import org.junit.After; |
| 20 | import org.junit.Before; |
HIGUCHI Yuta | 7a004ae | 2016-05-28 10:26:03 -0700 | [diff] [blame] | 21 | import org.junit.BeforeClass; |
Rimon Ashkenazy | a4e3bd3 | 2016-02-22 16:12:20 +0200 | [diff] [blame] | 22 | import org.junit.Test; |
| 23 | import org.onlab.packet.ChassisId; |
| 24 | import org.onosproject.TestApplicationId; |
| 25 | import org.onosproject.cfg.ComponentConfigService; |
| 26 | import org.onosproject.core.ApplicationId; |
| 27 | import org.onosproject.core.CoreService; |
| 28 | import org.onosproject.core.IdGenerator; |
HIGUCHI Yuta | 7a004ae | 2016-05-28 10:26:03 -0700 | [diff] [blame] | 29 | import org.onosproject.net.AbstractProjectableModel; |
Rimon Ashkenazy | a4e3bd3 | 2016-02-22 16:12:20 +0200 | [diff] [blame] | 30 | import org.onosproject.net.Annotations; |
| 31 | import org.onosproject.net.ChannelSpacing; |
| 32 | import org.onosproject.net.DefaultAnnotations; |
| 33 | import org.onosproject.net.CltSignalType; |
| 34 | import org.onosproject.net.ConnectPoint; |
| 35 | import org.onosproject.net.DefaultDevice; |
HIGUCHI Yuta | 34a3f69 | 2016-01-09 21:08:57 -0800 | [diff] [blame] | 36 | import org.onosproject.net.DefaultPort; |
Rimon Ashkenazy | a4e3bd3 | 2016-02-22 16:12:20 +0200 | [diff] [blame] | 37 | import org.onosproject.net.Device; |
| 38 | import org.onosproject.net.DeviceId; |
Rimon Ashkenazy | a4e3bd3 | 2016-02-22 16:12:20 +0200 | [diff] [blame] | 39 | import org.onosproject.net.OchSignal; |
Rimon Ashkenazy | a4e3bd3 | 2016-02-22 16:12:20 +0200 | [diff] [blame] | 40 | import org.onosproject.net.OduSignalId; |
| 41 | import org.onosproject.net.OduSignalType; |
Rimon Ashkenazy | 27438ff | 2016-03-22 15:57:45 +0200 | [diff] [blame] | 42 | import org.onosproject.net.OduSignalUtils; |
Rimon Ashkenazy | a4e3bd3 | 2016-02-22 16:12:20 +0200 | [diff] [blame] | 43 | import org.onosproject.net.Port; |
| 44 | import org.onosproject.net.PortNumber; |
| 45 | import org.onosproject.net.TributarySlot; |
| 46 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 47 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 48 | import org.onosproject.net.flow.FlowRule; |
| 49 | import org.onosproject.net.flow.TrafficSelector; |
| 50 | import org.onosproject.net.flow.TrafficTreatment; |
| 51 | import org.onosproject.net.flow.criteria.Criteria; |
| 52 | import org.onosproject.net.flow.instructions.Instructions; |
| 53 | import org.onosproject.net.intent.FlowRuleIntent; |
| 54 | import org.onosproject.net.intent.Intent; |
| 55 | import org.onosproject.net.intent.IntentExtensionService; |
| 56 | import org.onosproject.net.intent.IntentId; |
| 57 | import org.onosproject.net.intent.IntentServiceAdapter; |
| 58 | import org.onosproject.net.intent.Key; |
| 59 | import org.onosproject.net.intent.MockIdGenerator; |
| 60 | import org.onosproject.net.intent.OpticalCircuitIntent; |
HIGUCHI Yuta | 34a3f69 | 2016-01-09 21:08:57 -0800 | [diff] [blame] | 61 | import org.onosproject.net.optical.OchPort; |
HIGUCHI Yuta | 4c0ef6b | 2016-05-02 19:45:41 -0700 | [diff] [blame] | 62 | import org.onosproject.net.optical.OduCltPort; |
HIGUCHI Yuta | 34a3f69 | 2016-01-09 21:08:57 -0800 | [diff] [blame] | 63 | import org.onosproject.net.optical.impl.DefaultOchPort; |
HIGUCHI Yuta | 4c0ef6b | 2016-05-02 19:45:41 -0700 | [diff] [blame] | 64 | import org.onosproject.net.optical.impl.DefaultOduCltPort; |
Rimon Ashkenazy | a4e3bd3 | 2016-02-22 16:12:20 +0200 | [diff] [blame] | 65 | import org.onosproject.net.provider.ProviderId; |
Yuta HIGUCHI | d95d590 | 2016-06-27 00:18:45 -0700 | [diff] [blame] | 66 | import org.onosproject.net.resource.MockResourceService; |
Sho SHIMIZU | 739873b | 2016-02-23 17:02:12 -0800 | [diff] [blame] | 67 | import org.onosproject.net.intent.IntentSetMultimap; |
Rimon Ashkenazy | a4e3bd3 | 2016-02-22 16:12:20 +0200 | [diff] [blame] | 68 | import org.onosproject.net.behaviour.TributarySlotQuery; |
| 69 | import org.onosproject.net.device.DeviceServiceAdapter; |
| 70 | import org.onosproject.net.driver.Behaviour; |
| 71 | import org.onosproject.net.driver.DefaultDriver; |
| 72 | import org.onosproject.net.driver.Driver; |
| 73 | import org.onosproject.net.driver.DriverHandler; |
| 74 | import org.onosproject.net.driver.DriverService; |
HIGUCHI Yuta | 7a004ae | 2016-05-28 10:26:03 -0700 | [diff] [blame] | 75 | import org.onosproject.net.driver.DriverServiceAdapter; |
Rimon Ashkenazy | a4e3bd3 | 2016-02-22 16:12:20 +0200 | [diff] [blame] | 76 | import org.onosproject.net.driver.TestBehaviourImpl; |
| 77 | import org.onosproject.net.driver.TestBehaviourTwoImpl; |
| 78 | |
| 79 | import com.google.common.collect.ImmutableList; |
| 80 | import com.google.common.collect.ImmutableMap; |
| 81 | import com.google.common.collect.ImmutableSet; |
| 82 | import com.google.common.collect.Sets; |
| 83 | |
| 84 | import java.util.ArrayList; |
| 85 | import java.util.Collection; |
| 86 | import java.util.Collections; |
| 87 | import java.util.HashSet; |
| 88 | import java.util.List; |
| 89 | import java.util.Set; |
| 90 | |
| 91 | import static org.easymock.EasyMock.anyObject; |
| 92 | import static org.easymock.EasyMock.createMock; |
| 93 | import static org.easymock.EasyMock.expect; |
| 94 | import static org.easymock.EasyMock.expectLastCall; |
| 95 | import static org.easymock.EasyMock.replay; |
| 96 | import static org.hamcrest.MatcherAssert.assertThat; |
| 97 | import static org.hamcrest.Matchers.hasSize; |
| 98 | import static org.hamcrest.Matchers.is; |
| 99 | import static org.junit.Assert.assertEquals; |
| 100 | import static org.onosproject.net.AnnotationKeys.STATIC_PORT; |
| 101 | import static org.onosproject.net.AnnotationKeys.PORT_NAME; |
| 102 | import static org.onosproject.net.Device.Type.ROADM; |
| 103 | import static org.onosproject.net.DeviceId.deviceId; |
| 104 | import static org.onosproject.net.NetTestTools.APP_ID; |
| 105 | |
| 106 | public 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 Yuta | 4c0ef6b | 2016-05-02 19:45:41 -0700 | [diff] [blame] | 132 | new DefaultOduCltPort(new DefaultPort(device1, PortNumber.portNumber(1), true, annotations1), |
| 133 | CltSignalType.CLT_1GBE); |
Rimon Ashkenazy | a4e3bd3 | 2016-02-22 16:12:20 +0200 | [diff] [blame] | 134 | private static final OduCltPort D2P1 = |
HIGUCHI Yuta | 4c0ef6b | 2016-05-02 19:45:41 -0700 | [diff] [blame] | 135 | new DefaultOduCltPort(new DefaultPort(device2, PortNumber.portNumber(1), true, annotations1), |
| 136 | CltSignalType.CLT_1GBE); |
Rimon Ashkenazy | a4e3bd3 | 2016-02-22 16:12:20 +0200 | [diff] [blame] | 137 | |
| 138 | // Och ports with signalType=ODU2 |
| 139 | private static final OchPort D1P2 = |
HIGUCHI Yuta | 34a3f69 | 2016-01-09 21:08:57 -0800 | [diff] [blame] | 140 | new DefaultOchPort(new DefaultPort(device1, PortNumber.portNumber(2), true, annotations2), |
| 141 | OduSignalType.ODU2, |
| 142 | true, OchSignal.newDwdmSlot(ChannelSpacing.CHL_50GHZ, 1)); |
Rimon Ashkenazy | a4e3bd3 | 2016-02-22 16:12:20 +0200 | [diff] [blame] | 143 | private static final OchPort D2P2 = |
HIGUCHI Yuta | 34a3f69 | 2016-01-09 21:08:57 -0800 | [diff] [blame] | 144 | new DefaultOchPort(new DefaultPort(device2, PortNumber.portNumber(2), true, annotations2), |
| 145 | OduSignalType.ODU2, |
| 146 | true, OchSignal.newDwdmSlot(ChannelSpacing.CHL_50GHZ, 1)); |
Rimon Ashkenazy | a4e3bd3 | 2016-02-22 16:12:20 +0200 | [diff] [blame] | 147 | |
| 148 | // OduClt ports with signalType=10GBE |
| 149 | private static final OduCltPort D1P3 = |
HIGUCHI Yuta | 4c0ef6b | 2016-05-02 19:45:41 -0700 | [diff] [blame] | 150 | new DefaultOduCltPort(new DefaultPort(device1, PortNumber.portNumber(3), true, annotations1), |
| 151 | CltSignalType.CLT_10GBE); |
Rimon Ashkenazy | a4e3bd3 | 2016-02-22 16:12:20 +0200 | [diff] [blame] | 152 | private static final OduCltPort D2P3 = |
HIGUCHI Yuta | 4c0ef6b | 2016-05-02 19:45:41 -0700 | [diff] [blame] | 153 | new DefaultOduCltPort(new DefaultPort(device2, PortNumber.portNumber(3), true, annotations1), |
| 154 | CltSignalType.CLT_10GBE); |
Rimon Ashkenazy | a4e3bd3 | 2016-02-22 16:12:20 +0200 | [diff] [blame] | 155 | |
| 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 Yuta | 34a3f69 | 2016-01-09 21:08:57 -0800 | [diff] [blame] | 185 | return D1P1; |
Rimon Ashkenazy | a4e3bd3 | 2016-02-22 16:12:20 +0200 | [diff] [blame] | 186 | case "2": |
HIGUCHI Yuta | 34a3f69 | 2016-01-09 21:08:57 -0800 | [diff] [blame] | 187 | return D1P2; |
Rimon Ashkenazy | a4e3bd3 | 2016-02-22 16:12:20 +0200 | [diff] [blame] | 188 | case "3": |
HIGUCHI Yuta | 34a3f69 | 2016-01-09 21:08:57 -0800 | [diff] [blame] | 189 | return D1P3; |
Rimon Ashkenazy | a4e3bd3 | 2016-02-22 16:12:20 +0200 | [diff] [blame] | 190 | default: |
| 191 | return null; |
| 192 | } |
| 193 | } |
| 194 | if (deviceId.equals(deviceId(DEV2))) { |
| 195 | switch (portNumber.toString()) { |
| 196 | case "1": |
HIGUCHI Yuta | 34a3f69 | 2016-01-09 21:08:57 -0800 | [diff] [blame] | 197 | return D2P1; |
Rimon Ashkenazy | a4e3bd3 | 2016-02-22 16:12:20 +0200 | [diff] [blame] | 198 | case "2": |
HIGUCHI Yuta | 34a3f69 | 2016-01-09 21:08:57 -0800 | [diff] [blame] | 199 | return D2P2; |
Rimon Ashkenazy | a4e3bd3 | 2016-02-22 16:12:20 +0200 | [diff] [blame] | 200 | case "3": |
HIGUCHI Yuta | 34a3f69 | 2016-01-09 21:08:57 -0800 | [diff] [blame] | 201 | return D2P3; |
Rimon Ashkenazy | a4e3bd3 | 2016-02-22 16:12:20 +0200 | [diff] [blame] | 202 | 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 Yuta | 7a004ae | 2016-05-28 10:26:03 -0700 | [diff] [blame] | 361 | @BeforeClass |
| 362 | public static void setUpClass() { |
| 363 | AbstractProjectableModel.setDriverService("key", new DriverServiceAdapter()); |
| 364 | } |
| 365 | |
Rimon Ashkenazy | a4e3bd3 | 2016-02-22 16:12:20 +0200 | [diff] [blame] | 366 | @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 SHIMIZU | ec07ffd | 2016-02-22 20:45:21 -0800 | [diff] [blame] | 432 | List<Intent> compiled = sut.compile(intent, Collections.emptyList()); |
Rimon Ashkenazy | a4e3bd3 | 2016-02-22 16:12:20 +0200 | [diff] [blame] | 433 | 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 Ashkenazy | 27438ff | 2016-03-22 15:57:45 +0200 | [diff] [blame] | 451 | OduSignalId oduSignalId = OduSignalUtils.buildOduSignalId(D1P2.signalType(), slots); |
Rimon Ashkenazy | a4e3bd3 | 2016-02-22 16:12:20 +0200 | [diff] [blame] | 452 | 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 SHIMIZU | ec07ffd | 2016-02-22 20:45:21 -0800 | [diff] [blame] | 505 | List<Intent> compiled = sut.compile(intent, Collections.emptyList()); |
Rimon Ashkenazy | a4e3bd3 | 2016-02-22 16:12:20 +0200 | [diff] [blame] | 506 | 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 SHIMIZU | ec07ffd | 2016-02-22 20:45:21 -0800 | [diff] [blame] | 573 | List<Intent> compiled = sut.compile(intent, Collections.emptyList()); |
Rimon Ashkenazy | a4e3bd3 | 2016-02-22 16:12:20 +0200 | [diff] [blame] | 574 | 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 | } |