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