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