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