Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.pce.pceservice; |
| 17 | |
| 18 | import org.junit.After; |
| 19 | import org.junit.Before; |
| 20 | import org.junit.Test; |
| 21 | import org.onlab.graph.AbstractGraphPathSearch; |
| 22 | import org.onlab.graph.AdjacencyListsGraph; |
| 23 | import org.onlab.graph.DijkstraGraphSearch; |
| 24 | import org.onlab.graph.Graph; |
| 25 | import org.onlab.graph.GraphPathSearch; |
| 26 | import org.onlab.packet.ChassisId; |
| 27 | import org.onlab.util.Bandwidth; |
| 28 | import org.onlab.util.Tools; |
| 29 | import org.onosproject.net.AnnotationKeys; |
| 30 | import org.onosproject.net.ConnectPoint; |
| 31 | import org.onosproject.net.DefaultAnnotations; |
| 32 | import org.onosproject.net.DefaultDevice; |
| 33 | import org.onosproject.net.DefaultLink; |
| 34 | import org.onosproject.net.DefaultPath; |
| 35 | import org.onosproject.net.Device; |
| 36 | import org.onosproject.net.DeviceId; |
| 37 | import org.onosproject.net.Link; |
| 38 | import org.onosproject.net.Path; |
| 39 | import org.onosproject.net.PortNumber; |
| 40 | import org.onosproject.net.intent.Constraint; |
| 41 | import org.onosproject.net.intent.IntentId; |
| 42 | import org.onosproject.net.Device.Type; |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 43 | import org.onosproject.net.config.Config; |
| 44 | import org.onosproject.net.config.ConfigApplyDelegate; |
| 45 | import org.onosproject.net.config.ConfigFactory; |
| 46 | import org.onosproject.net.config.NetworkConfigRegistryAdapter; |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 47 | import org.onosproject.net.intent.constraint.BandwidthConstraint; |
| 48 | import org.onosproject.net.device.DeviceServiceAdapter; |
| 49 | import org.onosproject.net.resource.ContinuousResource; |
| 50 | import org.onosproject.net.resource.ContinuousResourceId; |
| 51 | import org.onosproject.net.resource.DiscreteResource; |
| 52 | import org.onosproject.net.resource.DiscreteResourceId; |
| 53 | import org.onosproject.net.resource.Resource; |
| 54 | import org.onosproject.net.resource.ResourceAllocation; |
| 55 | import org.onosproject.net.resource.ResourceConsumer; |
| 56 | import org.onosproject.net.resource.ResourceId; |
| 57 | import org.onosproject.net.resource.Resources; |
| 58 | import org.onosproject.net.provider.ProviderId; |
| 59 | import org.onosproject.net.topology.DefaultTopologyEdge; |
| 60 | import org.onosproject.net.topology.DefaultTopologyVertex; |
Andrey Komarov | 2398d96 | 2016-09-26 15:11:23 +0300 | [diff] [blame] | 61 | import org.onosproject.net.topology.LinkWeigher; |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 62 | import org.onosproject.net.topology.LinkWeight; |
| 63 | import org.onosproject.net.topology.TopologyEdge; |
| 64 | import org.onosproject.net.topology.TopologyVertex; |
| 65 | import org.onosproject.pce.pceservice.constraint.CapabilityConstraint; |
| 66 | import org.onosproject.pce.pceservice.constraint.CostConstraint; |
| 67 | import org.onosproject.pce.pceservice.constraint.SharedBandwidthConstraint; |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 68 | import org.onosproject.pcep.api.DeviceCapability; |
| 69 | import com.fasterxml.jackson.databind.JsonNode; |
| 70 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 71 | import com.fasterxml.jackson.databind.node.JsonNodeFactory; |
| 72 | import com.fasterxml.jackson.databind.node.ObjectNode; |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 73 | import com.google.common.collect.ImmutableList; |
| 74 | import com.google.common.collect.ImmutableSet; |
| 75 | |
| 76 | import java.util.Collections; |
| 77 | import java.util.HashMap; |
| 78 | import java.util.HashSet; |
| 79 | import java.util.Iterator; |
| 80 | import java.util.LinkedList; |
| 81 | import java.util.List; |
| 82 | import java.util.Map; |
| 83 | import java.util.Optional; |
| 84 | import java.util.Set; |
| 85 | import java.util.stream.Collectors; |
| 86 | |
| 87 | import static org.hamcrest.MatcherAssert.assertThat; |
| 88 | import static org.hamcrest.core.Is.is; |
| 89 | import static org.onlab.graph.GraphPathSearch.ALL_PATHS; |
| 90 | import static org.onosproject.core.CoreService.CORE_PROVIDER_ID; |
| 91 | import static com.google.common.collect.ImmutableSet.of; |
| 92 | import static org.onosproject.net.resource.Resources.continuous; |
| 93 | import static org.onosproject.net.Link.Type.DIRECT; |
| 94 | import static org.onosproject.net.Link.State.ACTIVE; |
| 95 | import static org.onosproject.net.DeviceId.deviceId; |
Andrey Komarov | 2398d96 | 2016-09-26 15:11:23 +0300 | [diff] [blame] | 96 | import static org.onosproject.net.topology.AdapterLinkWeigher.adapt; |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 97 | import static org.onosproject.pce.pceservice.constraint.CostConstraint.Type.COST; |
| 98 | import static org.onosproject.pce.pceservice.constraint.CostConstraint.Type.TE_COST; |
| 99 | |
| 100 | /** |
| 101 | * Test for CSPF path computation. |
| 102 | */ |
| 103 | public class PathComputationTest { |
| 104 | |
| 105 | private final MockPathResourceService resourceService = new MockPathResourceService(); |
| 106 | private final MockDeviceService deviceService = new MockDeviceService(); |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 107 | private final MockNetConfigRegistryAdapter netConfigRegistry = new MockNetConfigRegistryAdapter(); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 108 | private PceManager pceManager = new PceManager(); |
| 109 | public static ProviderId providerId = new ProviderId("pce", "foo"); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 110 | public static final String DEVICE1 = "D001"; |
| 111 | public static final String DEVICE2 = "D002"; |
| 112 | public static final String DEVICE3 = "D003"; |
| 113 | public static final String DEVICE4 = "D004"; |
| 114 | public static final String DEVICE5 = "D005"; |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 115 | public static final String PCEPDEVICE1 = "PD001"; |
| 116 | public static final String PCEPDEVICE2 = "PD002"; |
| 117 | public static final String PCEPDEVICE3 = "PD003"; |
| 118 | public static final String PCEPDEVICE4 = "PD004"; |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 119 | public static final TopologyVertex D1 = new DefaultTopologyVertex(DeviceId.deviceId("D001")); |
| 120 | public static final TopologyVertex D2 = new DefaultTopologyVertex(DeviceId.deviceId("D002")); |
| 121 | public static final TopologyVertex D3 = new DefaultTopologyVertex(DeviceId.deviceId("D003")); |
| 122 | public static final TopologyVertex D4 = new DefaultTopologyVertex(DeviceId.deviceId("D004")); |
| 123 | public static final TopologyVertex D5 = new DefaultTopologyVertex(DeviceId.deviceId("D005")); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 124 | private static final String ANNOTATION_COST = "cost"; |
| 125 | private static final String ANNOTATION_TE_COST = "teCost"; |
| 126 | private static final String UNKNOWN = "unknown"; |
| 127 | public static final String LSRID = "lsrId"; |
| 128 | public static final String L3 = "L3"; |
| 129 | public static final String PCECC_CAPABILITY = "pceccCapability"; |
| 130 | public static final String SR_CAPABILITY = "srCapability"; |
| 131 | public static final String LABEL_STACK_CAPABILITY = "labelStackCapability"; |
| 132 | |
| 133 | @Before |
| 134 | public void startUp() { |
| 135 | pceManager.resourceService = resourceService; |
| 136 | pceManager.deviceService = deviceService; |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 137 | pceManager.netCfgService = netConfigRegistry; |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | /** |
| 141 | * Selects path computation algorithm. |
| 142 | * |
| 143 | * @return graph path search algorithm |
| 144 | */ |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 145 | public static AbstractGraphPathSearch<TopologyVertex, TopologyEdge> graphSearch() { |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 146 | return new DijkstraGraphSearch<>(); |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * Returns link for two devices. |
| 151 | * |
| 152 | * @param device source device |
| 153 | * @param port source port |
| 154 | * @param device2 destination device |
| 155 | * @param port2 destination port |
| 156 | * @return link |
| 157 | */ |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 158 | public static Link addLink(String device, long port, String device2, long port2, boolean setCost, int value) { |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 159 | ConnectPoint src = new ConnectPoint(DeviceId.deviceId(device), PortNumber.portNumber(port)); |
| 160 | ConnectPoint dst = new ConnectPoint(DeviceId.deviceId(device2), PortNumber.portNumber(port2)); |
| 161 | Link curLink; |
| 162 | DefaultAnnotations.Builder annotationBuilder = DefaultAnnotations.builder(); |
| 163 | if (setCost) { |
| 164 | annotationBuilder.set(ANNOTATION_COST, String.valueOf(value)); |
| 165 | } else { |
| 166 | annotationBuilder.set(ANNOTATION_TE_COST, String.valueOf(value)); |
| 167 | } |
| 168 | |
| 169 | //TODO:If cost not set cost : default value case |
| 170 | curLink = DefaultLink.builder().src(src).dst(dst).state(ACTIVE).type(DIRECT) |
| 171 | .providerId(PathComputationTest.providerId).annotations(annotationBuilder.build()).build(); |
| 172 | return curLink; |
| 173 | } |
| 174 | |
| 175 | @After |
| 176 | public void tearDown() { |
| 177 | pceManager.resourceService = null; |
| 178 | pceManager.deviceService = null; |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 179 | pceManager.netCfgService = null; |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | /** |
| 183 | * Returns an edge-weight capable of evaluating links on the basis of the |
| 184 | * specified constraints. |
| 185 | * |
| 186 | * @param constraints path constraints |
| 187 | * @return edge-weight function |
| 188 | */ |
Andrey Komarov | 2398d96 | 2016-09-26 15:11:23 +0300 | [diff] [blame] | 189 | private LinkWeigher weight(List<Constraint> constraints) { |
| 190 | return adapt(new MockTeConstraintBasedLinkWeight(constraints)); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | private Set<Path> computePath(Link link1, Link link2, Link link3, Link link4, List<Constraint> constraints) { |
| 194 | Graph<TopologyVertex, TopologyEdge> graph = new AdjacencyListsGraph<>(of(D1, D2, D3, D4), |
| 195 | of(new DefaultTopologyEdge(D1, D2, link1), |
| 196 | new DefaultTopologyEdge(D2, D4, link2), |
| 197 | new DefaultTopologyEdge(D1, D3, link3), |
| 198 | new DefaultTopologyEdge(D3, D4, link4))); |
| 199 | |
| 200 | GraphPathSearch.Result<TopologyVertex, TopologyEdge> result = |
| 201 | graphSearch().search(graph, D1, D4, weight(constraints), ALL_PATHS); |
| 202 | ImmutableSet.Builder<Path> builder = ImmutableSet.builder(); |
| 203 | for (org.onlab.graph.Path<TopologyVertex, TopologyEdge> path : result.paths()) { |
| 204 | builder.add(networkPath(path)); |
| 205 | } |
| 206 | return builder.build(); |
| 207 | } |
| 208 | |
| 209 | private class MockDeviceService extends DeviceServiceAdapter { |
| 210 | List<Device> devices = new LinkedList<>(); |
| 211 | |
| 212 | private void addDevice(Device dev) { |
| 213 | devices.add(dev); |
| 214 | } |
| 215 | |
| 216 | @Override |
| 217 | public Device getDevice(DeviceId deviceId) { |
| 218 | for (Device dev : devices) { |
| 219 | if (dev.id().equals(deviceId)) { |
| 220 | return dev; |
| 221 | } |
| 222 | } |
| 223 | return null; |
| 224 | } |
| 225 | |
| 226 | @Override |
| 227 | public Iterable<Device> getAvailableDevices() { |
| 228 | return devices; |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | private class MockTeConstraintBasedLinkWeight implements LinkWeight { |
| 233 | |
| 234 | private final List<Constraint> constraints; |
| 235 | |
| 236 | /** |
| 237 | * Creates a new edge-weight function capable of evaluating links |
| 238 | * on the basis of the specified constraints. |
| 239 | * |
| 240 | * @param constraints path constraints |
| 241 | */ |
| 242 | MockTeConstraintBasedLinkWeight(List<Constraint> constraints) { |
| 243 | if (constraints == null) { |
| 244 | this.constraints = Collections.emptyList(); |
| 245 | } else { |
| 246 | this.constraints = ImmutableList.copyOf(constraints); |
| 247 | } |
| 248 | } |
| 249 | |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 250 | @Override |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 251 | public double weight(TopologyEdge edge) { |
| 252 | if (!constraints.iterator().hasNext()) { |
| 253 | //Takes default cost/hopcount as 1 if no constraints specified |
| 254 | return 1.0; |
| 255 | } |
| 256 | |
| 257 | Iterator<Constraint> it = constraints.iterator(); |
| 258 | double cost = 1; |
| 259 | |
| 260 | //If any constraint fails return -1 also value of cost returned from cost constraint can't be negative |
| 261 | while (it.hasNext() && cost > 0) { |
| 262 | Constraint constraint = it.next(); |
| 263 | if (constraint instanceof CapabilityConstraint) { |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 264 | cost = ((CapabilityConstraint) constraint).isValidLink(edge.link(), deviceService, |
| 265 | netConfigRegistry) ? 1 : -1; |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 266 | } else { |
| 267 | cost = constraint.cost(edge.link(), resourceService::isAvailable); |
| 268 | } |
| 269 | } |
| 270 | return cost; |
| 271 | } |
| 272 | } |
| 273 | |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 274 | /** |
| 275 | * Returns the path in Path object format. |
| 276 | */ |
| 277 | public static Path networkPath(org.onlab.graph.Path<TopologyVertex, TopologyEdge> path) { |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 278 | List<Link> links = path.edges().stream().map(TopologyEdge::link).collect(Collectors.toList()); |
| 279 | return new DefaultPath(CORE_PROVIDER_ID, links, path.cost()); |
| 280 | } |
| 281 | |
| 282 | /** |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 283 | * Tests Resource service for path computation. |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 284 | */ |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 285 | public class MockPathResourceService extends ResourceServiceAdapter { |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 286 | private final Map<Resource, ResourceConsumer> assignment = new HashMap<>(); |
| 287 | private Map<ResourceId, List<ResourceAllocation>> resourcesAllocations = new HashMap<>(); |
| 288 | |
| 289 | @Override |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 290 | public Optional<ResourceAllocation> allocate(ResourceConsumer consumer, Resource resources) { |
| 291 | List<ResourceAllocation> allocations = allocate(consumer, ImmutableList.of(resources)); |
| 292 | if (allocations.isEmpty()) { |
| 293 | return Optional.empty(); |
| 294 | } |
| 295 | |
| 296 | assert allocations.size() == 1; |
| 297 | ResourceAllocation allocation = allocations.get(0); |
| 298 | assert allocation.resource().equals(resources); |
| 299 | |
| 300 | // cast is ensured by the assertions above |
| 301 | return Optional.of(allocation); |
| 302 | } |
| 303 | |
| 304 | @Override |
Sho SHIMIZU | ef835c9 | 2016-08-08 13:51:17 -0700 | [diff] [blame] | 305 | public List<ResourceAllocation> allocate(ResourceConsumer consumer, List<? extends Resource> resources) { |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 306 | for (Resource resource: resources) { |
| 307 | if (resource instanceof ContinuousResource) { |
| 308 | List<ResourceAllocation> allocs = new LinkedList<>(); |
| 309 | allocs.add(new ResourceAllocation(resource, consumer)); |
| 310 | resourcesAllocations.put(resource.id(), allocs); |
| 311 | } |
| 312 | } |
| 313 | return resources.stream() |
| 314 | .map(x -> new ResourceAllocation(x, consumer)) |
| 315 | .collect(Collectors.toList()); |
| 316 | } |
| 317 | |
| 318 | @Override |
| 319 | public List<ResourceAllocation> getResourceAllocations(ResourceId id) { |
| 320 | if (id instanceof ContinuousResourceId) { |
| 321 | return resourcesAllocations.get(id); |
| 322 | } |
| 323 | DiscreteResource discrete = Resources.discrete((DiscreteResourceId) id).resource(); |
| 324 | return Optional.ofNullable(assignment.get(discrete)) |
| 325 | .map(x -> ImmutableList.of(new ResourceAllocation(discrete, x))) |
| 326 | .orElse(ImmutableList.of()); |
| 327 | } |
| 328 | |
| 329 | @Override |
| 330 | public <T> Set<Resource> getAvailableResources(DiscreteResourceId parent, Class<T> cls) { |
| 331 | return getAvailableResources(parent).stream() |
| 332 | .filter(x -> x.isTypeOf(cls)) |
| 333 | .collect(Collectors.toSet()); |
| 334 | } |
| 335 | |
| 336 | @Override |
| 337 | public <T> Set<T> getAvailableResourceValues(DiscreteResourceId parent, Class<T> cls) { |
| 338 | return getAvailableResources(parent).stream() |
| 339 | .filter(x -> x.isTypeOf(cls)) |
| 340 | .flatMap(x -> Tools.stream(x.valueAs(cls))) |
| 341 | .collect(Collectors.toSet()); |
| 342 | } |
| 343 | |
| 344 | @Override |
| 345 | public boolean isAvailable(Resource resource) { |
| 346 | if (resource instanceof DiscreteResource) { |
| 347 | return true; |
| 348 | } |
| 349 | |
| 350 | if (resource instanceof ContinuousResource) { |
| 351 | List<ResourceAllocation> resalloc = resourcesAllocations.get(resource.id()); |
| 352 | |
| 353 | if ((resalloc != null) && (!resalloc.isEmpty())) { |
| 354 | if (((ContinuousResource) resalloc.iterator().next().resource()).value() |
| 355 | >= ((ContinuousResource) resource).value()) { |
| 356 | return true; |
| 357 | } |
| 358 | } |
| 359 | } |
| 360 | return false; |
| 361 | } |
| 362 | } |
| 363 | |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 364 | /* Mock test for network config registry. */ |
| 365 | public static class MockNetConfigRegistryAdapter extends NetworkConfigRegistryAdapter { |
| 366 | private ConfigFactory cfgFactory; |
| 367 | private Map<DeviceId, DeviceCapability> classConfig = new HashMap<>(); |
| 368 | |
| 369 | @Override |
| 370 | public void registerConfigFactory(ConfigFactory configFactory) { |
| 371 | cfgFactory = configFactory; |
| 372 | } |
| 373 | |
| 374 | @Override |
| 375 | public void unregisterConfigFactory(ConfigFactory configFactory) { |
| 376 | cfgFactory = null; |
| 377 | } |
| 378 | |
| 379 | @Override |
| 380 | public <S, C extends Config<S>> C addConfig(S subject, Class<C> configClass) { |
| 381 | if (configClass == DeviceCapability.class) { |
| 382 | DeviceCapability devCap = new DeviceCapability(); |
| 383 | classConfig.put((DeviceId) subject, devCap); |
| 384 | |
| 385 | JsonNode node = new ObjectNode(new MockJsonNode()); |
| 386 | ObjectMapper mapper = new ObjectMapper(); |
| 387 | ConfigApplyDelegate delegate = new InternalApplyDelegate(); |
| 388 | devCap.init((DeviceId) subject, null, node, mapper, delegate); |
| 389 | return (C) devCap; |
| 390 | } |
| 391 | |
| 392 | return null; |
| 393 | } |
| 394 | |
| 395 | @Override |
| 396 | public <S, C extends Config<S>> void removeConfig(S subject, Class<C> configClass) { |
| 397 | classConfig.remove(subject); |
| 398 | } |
| 399 | |
| 400 | @Override |
| 401 | public <S, C extends Config<S>> C getConfig(S subject, Class<C> configClass) { |
| 402 | if (configClass == DeviceCapability.class) { |
| 403 | return (C) classConfig.get(subject); |
| 404 | } |
| 405 | return null; |
| 406 | } |
| 407 | |
| 408 | private class MockJsonNode extends JsonNodeFactory { |
| 409 | } |
| 410 | |
| 411 | // Auxiliary delegate to receive notifications about changes applied to |
| 412 | // the network configuration - by the apps. |
| 413 | private class InternalApplyDelegate implements ConfigApplyDelegate { |
| 414 | @Override |
| 415 | public void onApply(Config config) { |
| 416 | //configs.put(config.subject(), config.node()); |
| 417 | } |
| 418 | } |
| 419 | } |
| 420 | |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 421 | /** |
| 422 | * All links with different costs with L1-L2 as least cost path. |
| 423 | */ |
| 424 | @Test |
| 425 | public void testpathComputationCase1() { |
| 426 | Link link1 = addLink(DEVICE1, 10, DEVICE2, 20, true, 50); |
| 427 | Link link2 = addLink(DEVICE2, 30, DEVICE4, 40, true, 20); |
| 428 | Link link3 = addLink(DEVICE1, 80, DEVICE3, 70, true, 100); |
| 429 | Link link4 = addLink(DEVICE3, 60, DEVICE4, 50, true, 50); |
| 430 | |
| 431 | CostConstraint costConst = CostConstraint.of(COST); |
| 432 | List<Constraint> constraints = new LinkedList<>(); |
| 433 | constraints.add(costConst); |
| 434 | |
| 435 | Set<Path> paths = computePath(link1, link2, link3, link4, constraints); |
| 436 | |
| 437 | List<Link> links = new LinkedList<>(); |
| 438 | |
| 439 | links.add(link1); |
| 440 | links.add(link2); |
| 441 | |
| 442 | assertThat(paths.iterator().next().links(), is(links)); |
| 443 | assertThat(paths.iterator().next().cost(), is((double) 70)); |
| 444 | } |
| 445 | |
| 446 | /** |
| 447 | * Links with same cost 100 except link3. |
| 448 | */ |
| 449 | @Test |
| 450 | public void testpathComputationCase2() { |
| 451 | Link link1 = addLink(DEVICE1, 10, DEVICE2, 20, true, 100); |
| 452 | Link link2 = addLink(DEVICE2, 30, DEVICE4, 40, true, 100); |
| 453 | Link link3 = addLink(DEVICE1, 80, DEVICE3, 70, true, 1000); |
| 454 | Link link4 = addLink(DEVICE3, 60, DEVICE4, 50, true, 100); |
| 455 | |
| 456 | CostConstraint costConst = CostConstraint.of(COST); |
| 457 | List<Constraint> constraints = new LinkedList<>(); |
| 458 | constraints.add(costConst); |
| 459 | Set<Path> paths = computePath(link1, link2, link3, link4, constraints); |
| 460 | |
| 461 | List<Link> links = new LinkedList<>(); |
| 462 | links.add(link1); |
| 463 | links.add(link2); |
| 464 | |
| 465 | assertThat(paths.iterator().next().links(), is(links)); |
| 466 | assertThat(paths.iterator().next().cost(), is((double) 200)); |
| 467 | } |
| 468 | |
| 469 | /** |
| 470 | * Path which satisfy bandwidth as a constraint with 10bps. |
| 471 | */ |
| 472 | @Test |
| 473 | public void testpathComputationCase3() { |
| 474 | Link link1 = addLink(DEVICE1, 10, DEVICE2, 20, true, 50); |
| 475 | Link link2 = addLink(DEVICE2, 30, DEVICE4, 40, true, 20); |
| 476 | Link link3 = addLink(DEVICE1, 80, DEVICE3, 70, true, 100); |
| 477 | Link link4 = addLink(DEVICE3, 60, DEVICE4, 50, true, 50); |
| 478 | |
| 479 | List<Resource> resources = new LinkedList<>(); |
| 480 | |
| 481 | resources.add(continuous(link1.src().deviceId(), link1.src().port(), Bandwidth.class) |
| 482 | .resource(50)); |
| 483 | resources.add(continuous(link2.src().deviceId(), link2.src().port(), Bandwidth.class) |
| 484 | .resource(50)); |
| 485 | resources.add(continuous(link3.src().deviceId(), link3.src().port(), Bandwidth.class) |
| 486 | .resource(100)); |
| 487 | resources.add(continuous(link4.src().deviceId(), link4.src().port(), Bandwidth.class) |
| 488 | .resource(100)); |
| 489 | |
| 490 | resources.add(continuous(link1.dst().deviceId(), link1.dst().port(), Bandwidth.class) |
| 491 | .resource(50)); |
| 492 | resources.add(continuous(link2.dst().deviceId(), link2.dst().port(), Bandwidth.class) |
| 493 | .resource(50)); |
| 494 | resources.add(continuous(link3.dst().deviceId(), link3.src().port(), Bandwidth.class) |
| 495 | .resource(100)); |
| 496 | resources.add(continuous(link4.dst().deviceId(), link4.dst().port(), Bandwidth.class) |
| 497 | .resource(100)); |
| 498 | |
| 499 | resourceService.allocate(IntentId.valueOf(70), resources); |
| 500 | |
| 501 | BandwidthConstraint bandwidthConst = new BandwidthConstraint(Bandwidth.bps(10.0)); |
| 502 | |
| 503 | List<Constraint> constraints = new LinkedList<>(); |
| 504 | constraints.add(bandwidthConst); |
| 505 | |
| 506 | Set<Path> paths = computePath(link1, link2, link3, link4, constraints); |
| 507 | |
| 508 | assertThat(paths.iterator().next().cost(), is((double) 2)); |
| 509 | } |
| 510 | |
| 511 | /** |
| 512 | * Path which satisfy bandwidth as a constraint with 60bps. |
| 513 | */ |
| 514 | @Test |
| 515 | public void testpathComputationCase4() { |
| 516 | Link link1 = addLink(DEVICE1, 10, DEVICE2, 20, true, 50); |
| 517 | Link link2 = addLink(DEVICE2, 30, DEVICE4, 40, true, 50); |
| 518 | Link link3 = addLink(DEVICE1, 80, DEVICE3, 70, true, 100); |
| 519 | Link link4 = addLink(DEVICE3, 60, DEVICE4, 50, true, 100); |
| 520 | |
| 521 | List<Resource> resources = new LinkedList<>(); |
| 522 | |
| 523 | resources.add(continuous(link1.src().deviceId(), link1.src().port(), Bandwidth.class).resource(50)); |
| 524 | resources.add(continuous(link2.src().deviceId(), link2.src().port(), Bandwidth.class).resource(50)); |
| 525 | resources.add(continuous(link3.src().deviceId(), link3.src().port(), Bandwidth.class).resource(100)); |
| 526 | resources.add(continuous(link4.src().deviceId(), link4.src().port(), Bandwidth.class).resource(100)); |
| 527 | |
| 528 | resources.add(continuous(link1.dst().deviceId(), link1.dst().port(), Bandwidth.class).resource(50)); |
| 529 | resources.add(continuous(link2.dst().deviceId(), link2.dst().port(), Bandwidth.class).resource(50)); |
| 530 | resources.add(continuous(link3.dst().deviceId(), link3.dst().port(), Bandwidth.class).resource(100)); |
| 531 | resources.add(continuous(link4.dst().deviceId(), link4.dst().port(), Bandwidth.class).resource(100)); |
| 532 | |
| 533 | resourceService.allocate(IntentId.valueOf(70), resources); |
| 534 | |
| 535 | BandwidthConstraint bandwidthConst = new BandwidthConstraint(Bandwidth.bps(60.0)); |
| 536 | |
| 537 | List<Constraint> constraints = new LinkedList<>(); |
| 538 | constraints.add(bandwidthConst); |
| 539 | Set<Path> paths = computePath(link1, link2, link3, link4, constraints); |
| 540 | |
| 541 | assertThat(paths.iterator().next().cost(), is((double) 2)); |
| 542 | } |
| 543 | |
| 544 | /** |
| 545 | * Shared bandwidth as L1, L2 with its value 10 bps and bandwidth constraint as 20 bps. |
| 546 | */ |
| 547 | @Test |
| 548 | public void testpathComputationCase5() { |
| 549 | Link link1 = addLink(DEVICE1, 10, DEVICE2, 20, true, 50); |
| 550 | Link link2 = addLink(DEVICE2, 30, DEVICE4, 40, true, 20); |
| 551 | Link link3 = addLink(DEVICE1, 80, DEVICE3, 70, true, 100); |
| 552 | Link link4 = addLink(DEVICE3, 60, DEVICE4, 50, true, 80); |
| 553 | |
| 554 | List<Resource> resources = new LinkedList<>(); |
| 555 | |
| 556 | resources.add(continuous(link1.src().deviceId(), link1.src().port(), Bandwidth.class).resource(50)); |
| 557 | resources.add(continuous(link2.src().deviceId(), link2.src().port(), Bandwidth.class).resource(50)); |
| 558 | resources.add(continuous(link3.src().deviceId(), link3.src().port(), Bandwidth.class).resource(100)); |
| 559 | resources.add(continuous(link4.src().deviceId(), link4.src().port(), Bandwidth.class).resource(100)); |
| 560 | |
| 561 | resources.add(continuous(link1.dst().deviceId(), link1.dst().port(), Bandwidth.class).resource(50)); |
| 562 | resources.add(continuous(link2.dst().deviceId(), link2.dst().port(), Bandwidth.class).resource(50)); |
| 563 | resources.add(continuous(link3.dst().deviceId(), link3.dst().port(), Bandwidth.class).resource(100)); |
| 564 | resources.add(continuous(link4.dst().deviceId(), link4.dst().port(), Bandwidth.class).resource(100)); |
| 565 | resourceService.allocate(IntentId.valueOf(70), resources); |
| 566 | |
| 567 | List<Constraint> constraints = new LinkedList<>(); |
| 568 | |
| 569 | List<Link> sharedLinks = new LinkedList<>(); |
| 570 | |
| 571 | List<Link> links = new LinkedList<>(); |
| 572 | links.add(link1); |
| 573 | links.add(link2); |
| 574 | |
| 575 | CostConstraint costConst = CostConstraint.of(COST); |
| 576 | sharedLinks.addAll(links); |
| 577 | SharedBandwidthConstraint sharedBw = new SharedBandwidthConstraint(sharedLinks, Bandwidth.bps(10), |
| 578 | Bandwidth.bps(20.0)); |
| 579 | constraints.add(sharedBw); |
| 580 | constraints.add(costConst); |
| 581 | Set<Path> paths = computePath(link1, link2, link3, link4, constraints); |
| 582 | assertThat(paths.iterator().next().links(), is(links)); |
| 583 | assertThat(paths.iterator().next().cost(), is((double) 70)); |
| 584 | } |
| 585 | |
| 586 | /** |
| 587 | * Shared bandwidth as L1, L2 with its value 20 bps and bandwidth constraint as 10 bps. |
| 588 | */ |
| 589 | @Test |
| 590 | public void testpathComputationCase6() { |
| 591 | Link link1 = addLink(DEVICE1, 10, DEVICE2, 20, true, 50); |
| 592 | Link link2 = addLink(DEVICE2, 30, DEVICE4, 40, true, 20); |
| 593 | Link link3 = addLink(DEVICE1, 80, DEVICE3, 70, true, 100); |
| 594 | Link link4 = addLink(DEVICE3, 60, DEVICE4, 50, true, 80); |
| 595 | |
| 596 | List<Resource> resources = new LinkedList<>(); |
| 597 | |
| 598 | resources.add(continuous(link1.src().deviceId(), link1.src().port(), Bandwidth.class).resource(50)); |
| 599 | resources.add(continuous(link2.src().deviceId(), link2.src().port(), Bandwidth.class).resource(50)); |
| 600 | resources.add(continuous(link3.src().deviceId(), link3.src().port(), Bandwidth.class).resource(100)); |
| 601 | resources.add(continuous(link4.src().deviceId(), link4.src().port(), Bandwidth.class).resource(100)); |
| 602 | |
| 603 | resources.add(continuous(link1.dst().deviceId(), link1.dst().port(), Bandwidth.class).resource(50)); |
| 604 | resources.add(continuous(link2.dst().deviceId(), link2.dst().port(), Bandwidth.class).resource(50)); |
| 605 | resources.add(continuous(link3.dst().deviceId(), link3.dst().port(), Bandwidth.class).resource(100)); |
| 606 | resources.add(continuous(link4.dst().deviceId(), link4.dst().port(), Bandwidth.class).resource(100)); |
| 607 | resourceService.allocate(IntentId.valueOf(70), resources); |
| 608 | |
| 609 | List<Constraint> constraints = new LinkedList<>(); |
| 610 | |
| 611 | List<Link> sharedLinks = new LinkedList<>(); |
| 612 | |
| 613 | List<Link> links = new LinkedList<>(); |
| 614 | links.add(link1); |
| 615 | links.add(link2); |
| 616 | CostConstraint costConst = CostConstraint.of(COST); |
| 617 | sharedLinks.addAll(links); |
| 618 | SharedBandwidthConstraint sharedBwConst = new SharedBandwidthConstraint(sharedLinks, Bandwidth.bps(20), |
| 619 | Bandwidth.bps(10.0)); |
| 620 | constraints.add(sharedBwConst); |
| 621 | constraints.add(costConst); |
| 622 | Set<Path> paths = computePath(link1, link2, link3, link4, constraints); |
| 623 | |
| 624 | assertThat(paths.iterator().next().links(), is(links)); |
| 625 | assertThat(paths.iterator().next().cost(), is((double) 70)); |
| 626 | } |
| 627 | |
| 628 | /** |
| 629 | * Path without constraints. |
| 630 | */ |
| 631 | @Test |
| 632 | public void testpathComputationCase7() { |
| 633 | Link link1 = addLink(DEVICE1, 10, DEVICE2, 20, true, 50); |
| 634 | Link link2 = addLink(DEVICE2, 30, DEVICE4, 40, true, 20); |
| 635 | Link link3 = addLink(DEVICE1, 80, DEVICE3, 70, true, 100); |
| 636 | Link link4 = addLink(DEVICE3, 60, DEVICE4, 50, true, 80); |
| 637 | List<Constraint> constraints = new LinkedList<>(); |
| 638 | Set<Path> paths = computePath(link1, link2, link3, link4, constraints); |
| 639 | |
| 640 | assertThat(paths.iterator().next().cost(), is((double) 2)); |
| 641 | } |
| 642 | |
| 643 | /** |
| 644 | * With TeCost as a constraints. |
| 645 | */ |
| 646 | @Test |
| 647 | public void testpathComputationCase8() { |
| 648 | Link link1 = addLink(DEVICE1, 10, DEVICE2, 20, false, 50); |
| 649 | Link link2 = addLink(DEVICE2, 30, DEVICE4, 40, false, 20); |
| 650 | Link link3 = addLink(DEVICE1, 80, DEVICE3, 70, false, 100); |
| 651 | Link link4 = addLink(DEVICE3, 60, DEVICE4, 50, false, 80); |
| 652 | |
| 653 | CostConstraint tecostConst = CostConstraint.of(TE_COST); |
| 654 | |
| 655 | List<Constraint> constraints = new LinkedList<>(); |
| 656 | constraints.add(tecostConst); |
| 657 | Set<Path> paths = computePath(link1, link2, link3, link4, constraints); |
| 658 | |
| 659 | List<Link> links = new LinkedList<>(); |
| 660 | links.add(link1); |
| 661 | links.add(link2); |
| 662 | assertThat(paths.iterator().next().links(), is(links)); |
| 663 | assertThat(paths.iterator().next().cost(), is((double) 70)); |
| 664 | } |
| 665 | |
| 666 | /** |
| 667 | * With device supporting RSVP capability as a constraints. |
| 668 | */ |
| 669 | @Test |
| 670 | public void testpathComputationCase9() { |
| 671 | Link link1 = addLink(DEVICE1, 10, DEVICE2, 20, false, 50); |
| 672 | Link link2 = addLink(DEVICE2, 30, DEVICE4, 40, false, 20); |
| 673 | Link link3 = addLink(DEVICE1, 80, DEVICE3, 70, false, 100); |
| 674 | Link link4 = addLink(DEVICE3, 60, DEVICE4, 50, false, 80); |
| 675 | |
| 676 | CostConstraint tecostConst = CostConstraint.of(TE_COST); |
| 677 | CapabilityConstraint capabilityConst = CapabilityConstraint |
| 678 | .of(CapabilityConstraint.CapabilityType.WITH_SIGNALLING); |
| 679 | |
| 680 | List<Constraint> constraints = new LinkedList<>(); |
| 681 | constraints.add(capabilityConst); |
| 682 | constraints.add(tecostConst); |
| 683 | //Device1 |
| 684 | DefaultAnnotations.Builder builder = DefaultAnnotations.builder(); |
| 685 | builder.set(AnnotationKeys.TYPE, L3); |
| 686 | builder.set(LSRID, "1.1.1.1"); |
| 687 | addDevice(DEVICE1, builder); |
| 688 | |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 689 | DeviceCapability device1Cap = netConfigRegistry.addConfig(DeviceId.deviceId("1.1.1.1"), DeviceCapability.class); |
| 690 | device1Cap.setLabelStackCap(false) |
| 691 | .setLocalLabelCap(false) |
| 692 | .setSrCap(false) |
| 693 | .apply(); |
| 694 | |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 695 | //Device2 |
| 696 | builder = DefaultAnnotations.builder(); |
| 697 | builder.set(AnnotationKeys.TYPE, L3); |
| 698 | builder.set(LSRID, "2.2.2.2"); |
| 699 | addDevice(DEVICE2, builder); |
| 700 | |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 701 | DeviceCapability device2Cap = netConfigRegistry.addConfig(DeviceId.deviceId("2.2.2.2"), DeviceCapability.class); |
| 702 | device2Cap.setLabelStackCap(false) |
| 703 | .setLocalLabelCap(false) |
| 704 | .setSrCap(false) |
| 705 | .apply(); |
| 706 | |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 707 | //Device3 |
| 708 | builder = DefaultAnnotations.builder(); |
| 709 | builder.set(AnnotationKeys.TYPE, L3); |
| 710 | builder.set(LSRID, "3.3.3.3"); |
| 711 | addDevice(DEVICE3, builder); |
| 712 | |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 713 | DeviceCapability device3Cap = netConfigRegistry.addConfig(DeviceId.deviceId("3.3.3.3"), DeviceCapability.class); |
| 714 | device3Cap.setLabelStackCap(false) |
| 715 | .setLocalLabelCap(false) |
| 716 | .setSrCap(false) |
| 717 | .apply(); |
| 718 | |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 719 | //Device4 |
| 720 | builder = DefaultAnnotations.builder(); |
| 721 | builder.set(AnnotationKeys.TYPE, L3); |
| 722 | builder.set(LSRID, "4.4.4.4"); |
| 723 | addDevice(DEVICE4, builder); |
| 724 | |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 725 | DeviceCapability device4Cap = netConfigRegistry.addConfig(DeviceId.deviceId("4.4.4.4"), DeviceCapability.class); |
| 726 | device4Cap.setLabelStackCap(false) |
| 727 | .setLocalLabelCap(false) |
| 728 | .setSrCap(false) |
| 729 | .apply(); |
| 730 | |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 731 | Set<Path> paths = computePath(link1, link2, link3, link4, constraints); |
| 732 | |
| 733 | List<Link> links = new LinkedList<>(); |
| 734 | links.add(link1); |
| 735 | links.add(link2); |
| 736 | assertThat(paths.iterator().next().links(), is(links)); |
| 737 | assertThat(paths.iterator().next().cost(), is((double) 70)); |
| 738 | } |
| 739 | |
| 740 | /** |
| 741 | * Devices supporting CR capability. |
| 742 | */ |
| 743 | @Test |
| 744 | public void testpathComputationCase10() { |
| 745 | Link link1 = addLink(DEVICE1, 10, DEVICE2, 20, true, 50); |
| 746 | Link link2 = addLink(DEVICE2, 30, DEVICE4, 40, true, 20); |
| 747 | Link link3 = addLink(DEVICE1, 80, DEVICE3, 70, true, 100); |
| 748 | Link link4 = addLink(DEVICE3, 60, DEVICE4, 50, true, 80); |
| 749 | |
| 750 | CapabilityConstraint capabilityConst = CapabilityConstraint |
| 751 | .of(CapabilityConstraint.CapabilityType.WITHOUT_SIGNALLING_AND_WITHOUT_SR); |
| 752 | |
| 753 | List<Constraint> constraints = new LinkedList<>(); |
| 754 | constraints.add(capabilityConst); |
| 755 | CostConstraint costConst = CostConstraint.of(COST); |
| 756 | constraints.add(costConst); |
| 757 | //Device1 |
| 758 | DefaultAnnotations.Builder builder = DefaultAnnotations.builder(); |
| 759 | builder.set(AnnotationKeys.TYPE, L3); |
| 760 | builder.set(LSRID, "1.1.1.1"); |
| 761 | addDevice(DEVICE1, builder); |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 762 | DeviceCapability device1Cap = netConfigRegistry.addConfig(DeviceId.deviceId("1.1.1.1"), DeviceCapability.class); |
| 763 | device1Cap.setLabelStackCap(false) |
| 764 | .setLocalLabelCap(true) |
| 765 | .setSrCap(false) |
| 766 | .apply(); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 767 | |
| 768 | //Device2 |
| 769 | builder = DefaultAnnotations.builder(); |
| 770 | builder.set(AnnotationKeys.TYPE, L3); |
| 771 | builder.set(LSRID, "2.2.2.2"); |
| 772 | addDevice(DEVICE2, builder); |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 773 | DeviceCapability device2Cap = netConfigRegistry.addConfig(DeviceId.deviceId("2.2.2.2"), DeviceCapability.class); |
| 774 | device2Cap.setLabelStackCap(false) |
| 775 | .setLocalLabelCap(true) |
| 776 | .setSrCap(false) |
| 777 | .apply(); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 778 | |
| 779 | //Device3 |
| 780 | builder = DefaultAnnotations.builder(); |
| 781 | builder.set(AnnotationKeys.TYPE, L3); |
| 782 | builder.set(LSRID, "3.3.3.3"); |
| 783 | addDevice(DEVICE3, builder); |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 784 | DeviceCapability device3Cap = netConfigRegistry.addConfig(DeviceId.deviceId("3.3.3.3"), DeviceCapability.class); |
| 785 | device3Cap.setLabelStackCap(false) |
| 786 | .setLocalLabelCap(true) |
| 787 | .setSrCap(false) |
| 788 | .apply(); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 789 | |
| 790 | //Device4 |
| 791 | builder = DefaultAnnotations.builder(); |
| 792 | builder.set(AnnotationKeys.TYPE, L3); |
| 793 | builder.set(LSRID, "4.4.4.4"); |
| 794 | addDevice(DEVICE4, builder); |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 795 | DeviceCapability device4Cap = netConfigRegistry.addConfig(DeviceId.deviceId("4.4.4.4"), DeviceCapability.class); |
| 796 | device4Cap.setLabelStackCap(false) |
| 797 | .setLocalLabelCap(true) |
| 798 | .setSrCap(false) |
| 799 | .apply(); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 800 | |
| 801 | Set<Path> paths = computePath(link1, link2, link3, link4, constraints); |
| 802 | |
| 803 | List<Link> links = new LinkedList<>(); |
| 804 | links.add(link1); |
| 805 | links.add(link2); |
| 806 | assertThat(paths.iterator().next().links(), is(links)); |
| 807 | assertThat(paths.iterator().next().cost(), is((double) 70)); |
| 808 | } |
| 809 | |
| 810 | /** |
| 811 | * Device supporting SR capability. |
| 812 | */ |
| 813 | @Test |
| 814 | public void testpathComputationCase11() { |
| 815 | Link link1 = addLink(DEVICE1, 10, DEVICE2, 20, true, 50); |
| 816 | Link link2 = addLink(DEVICE2, 30, DEVICE4, 40, true, 20); |
| 817 | Link link3 = addLink(DEVICE1, 80, DEVICE3, 70, true, 100); |
| 818 | Link link4 = addLink(DEVICE3, 60, DEVICE4, 50, true, 80); |
| 819 | |
| 820 | CapabilityConstraint capabilityConst = CapabilityConstraint |
| 821 | .of(CapabilityConstraint.CapabilityType.SR_WITHOUT_SIGNALLING); |
| 822 | |
| 823 | List<Constraint> constraints = new LinkedList<>(); |
| 824 | constraints.add(capabilityConst); |
| 825 | CostConstraint costConst = CostConstraint.of(COST); |
| 826 | constraints.add(costConst); |
| 827 | //Device1 |
| 828 | DefaultAnnotations.Builder builder = DefaultAnnotations.builder(); |
| 829 | builder.set(AnnotationKeys.TYPE, L3); |
| 830 | builder.set(LSRID, "1.1.1.1"); |
| 831 | addDevice(DEVICE1, builder); |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 832 | DeviceCapability device1Cap = netConfigRegistry.addConfig(DeviceId.deviceId("1.1.1.1"), DeviceCapability.class); |
| 833 | device1Cap.setLabelStackCap(true) |
| 834 | .setLocalLabelCap(false) |
| 835 | .setSrCap(true) |
| 836 | .apply(); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 837 | |
| 838 | //Device2 |
| 839 | builder = DefaultAnnotations.builder(); |
| 840 | builder.set(AnnotationKeys.TYPE, L3); |
| 841 | builder.set(LSRID, "2.2.2.2"); |
| 842 | addDevice(DEVICE2, builder); |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 843 | DeviceCapability device2Cap = netConfigRegistry.addConfig(DeviceId.deviceId("2.2.2.2"), DeviceCapability.class); |
| 844 | device2Cap.setLabelStackCap(true) |
| 845 | .setLocalLabelCap(false) |
| 846 | .setSrCap(true) |
| 847 | .apply(); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 848 | |
| 849 | //Device3 |
| 850 | builder = DefaultAnnotations.builder(); |
| 851 | builder.set(AnnotationKeys.TYPE, L3); |
| 852 | builder.set(LSRID, "3.3.3.3"); |
| 853 | addDevice(DEVICE3, builder); |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 854 | DeviceCapability device3Cap = netConfigRegistry.addConfig(DeviceId.deviceId("3.3.3.3"), DeviceCapability.class); |
| 855 | device3Cap.setLabelStackCap(true) |
| 856 | .setLocalLabelCap(false) |
| 857 | .setSrCap(true) |
| 858 | .apply(); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 859 | |
| 860 | //Device4 |
| 861 | builder = DefaultAnnotations.builder(); |
| 862 | builder.set(AnnotationKeys.TYPE, L3); |
| 863 | builder.set(LSRID, "4.4.4.4"); |
| 864 | addDevice(DEVICE4, builder); |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 865 | DeviceCapability device4Cap = netConfigRegistry.addConfig(DeviceId.deviceId("4.4.4.4"), DeviceCapability.class); |
| 866 | device4Cap.setLabelStackCap(true) |
| 867 | .setLocalLabelCap(false) |
| 868 | .setSrCap(true) |
| 869 | .apply(); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 870 | Set<Path> paths = computePath(link1, link2, link3, link4, constraints); |
| 871 | |
| 872 | List<Link> links = new LinkedList<>(); |
| 873 | links.add(link1); |
| 874 | links.add(link2); |
| 875 | assertThat(paths.iterator().next().links(), is(links)); |
| 876 | assertThat(paths.iterator().next().cost(), is((double) 70)); |
| 877 | } |
| 878 | |
| 879 | /** |
| 880 | * Path with TE and SR capability constraint. |
| 881 | */ |
| 882 | @Test |
| 883 | public void testpathComputationCase12() { |
| 884 | Link link1 = addLink(DEVICE1, 10, DEVICE2, 20, false, 50); |
| 885 | Link link2 = addLink(DEVICE2, 30, DEVICE4, 40, false, 20); |
| 886 | Link link3 = addLink(DEVICE1, 80, DEVICE3, 70, false, 100); |
| 887 | Link link4 = addLink(DEVICE3, 60, DEVICE4, 50, false, 80); |
| 888 | |
| 889 | CostConstraint tecostConst = CostConstraint.of(TE_COST); |
| 890 | CapabilityConstraint capabilityConst = CapabilityConstraint |
| 891 | .of(CapabilityConstraint.CapabilityType.SR_WITHOUT_SIGNALLING); |
| 892 | |
| 893 | List<Constraint> constraints = new LinkedList<>(); |
| 894 | |
| 895 | constraints.add(capabilityConst); |
| 896 | constraints.add(tecostConst); |
| 897 | //Device1 |
| 898 | DefaultAnnotations.Builder builder = DefaultAnnotations.builder(); |
| 899 | builder.set(AnnotationKeys.TYPE, L3); |
| 900 | builder.set(LSRID, "1.1.1.1"); |
| 901 | addDevice(DEVICE1, builder); |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 902 | DeviceCapability device1Cap = netConfigRegistry.addConfig(DeviceId.deviceId("1.1.1.1"), DeviceCapability.class); |
| 903 | device1Cap.setLabelStackCap(true) |
| 904 | .setLocalLabelCap(false) |
| 905 | .setSrCap(true) |
| 906 | .apply(); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 907 | |
| 908 | //Device2 |
| 909 | builder = DefaultAnnotations.builder(); |
| 910 | builder.set(AnnotationKeys.TYPE, L3); |
| 911 | builder.set(LSRID, "2.2.2.2"); |
| 912 | addDevice(DEVICE2, builder); |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 913 | DeviceCapability device2Cap = netConfigRegistry.addConfig(DeviceId.deviceId("2.2.2.2"), DeviceCapability.class); |
| 914 | device2Cap.setLabelStackCap(true) |
| 915 | .setLocalLabelCap(false) |
| 916 | .setSrCap(true) |
| 917 | .apply(); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 918 | |
| 919 | //Device3 |
| 920 | builder = DefaultAnnotations.builder(); |
| 921 | builder.set(AnnotationKeys.TYPE, L3); |
| 922 | builder.set(LSRID, "3.3.3.3"); |
| 923 | addDevice(DEVICE3, builder); |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 924 | DeviceCapability device3Cap = netConfigRegistry.addConfig(DeviceId.deviceId("3.3.3.3"), DeviceCapability.class); |
| 925 | device3Cap.setLabelStackCap(true) |
| 926 | .setLocalLabelCap(false) |
| 927 | .setSrCap(true) |
| 928 | .apply(); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 929 | |
| 930 | //Device4 |
| 931 | builder = DefaultAnnotations.builder(); |
| 932 | builder.set(AnnotationKeys.TYPE, L3); |
| 933 | builder.set(LSRID, "4.4.4.4"); |
| 934 | addDevice(DEVICE4, builder); |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 935 | DeviceCapability device4Cap = netConfigRegistry.addConfig(DeviceId.deviceId("4.4.4.4"), DeviceCapability.class); |
| 936 | device4Cap.setLabelStackCap(true) |
| 937 | .setLocalLabelCap(false) |
| 938 | .setSrCap(true) |
| 939 | .apply(); |
| 940 | |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 941 | Set<Path> paths = computePath(link1, link2, link3, link4, constraints); |
| 942 | |
| 943 | List<Link> links = new LinkedList<>(); |
| 944 | links.add(link1); |
| 945 | links.add(link2); |
| 946 | assertThat(paths.iterator().next().links(), is(links)); |
| 947 | assertThat(paths.iterator().next().cost(), is((double) 70)); |
| 948 | } |
| 949 | |
| 950 | /** |
| 951 | * Path with capability constraint and with default cost. |
| 952 | */ |
| 953 | @Test |
| 954 | public void testpathComputationCase13() { |
| 955 | Link link1 = addLink(DEVICE1, 10, DEVICE2, 20, false, 50); |
| 956 | Link link2 = addLink(DEVICE2, 30, DEVICE4, 40, false, 20); |
| 957 | Link link3 = addLink(DEVICE1, 80, DEVICE3, 70, false, 100); |
| 958 | Link link4 = addLink(DEVICE3, 60, DEVICE4, 50, false, 80); |
| 959 | |
| 960 | CapabilityConstraint capabilityConst = CapabilityConstraint |
| 961 | .of(CapabilityConstraint.CapabilityType.SR_WITHOUT_SIGNALLING); |
| 962 | |
| 963 | List<Constraint> constraints = new LinkedList<>(); |
| 964 | constraints.add(capabilityConst); |
| 965 | //Device1 |
| 966 | DefaultAnnotations.Builder builder = DefaultAnnotations.builder(); |
| 967 | builder.set(AnnotationKeys.TYPE, L3); |
| 968 | builder.set(LSRID, "1.1.1.1"); |
| 969 | addDevice(DEVICE1, builder); |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 970 | DeviceCapability device1Cap = netConfigRegistry.addConfig(DeviceId.deviceId("1.1.1.1"), DeviceCapability.class); |
| 971 | device1Cap.setLabelStackCap(true) |
| 972 | .setLocalLabelCap(false) |
| 973 | .setSrCap(true) |
| 974 | .apply(); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 975 | |
| 976 | //Device2 |
| 977 | builder = DefaultAnnotations.builder(); |
| 978 | builder.set(AnnotationKeys.TYPE, L3); |
| 979 | builder.set(LSRID, "2.2.2.2"); |
| 980 | addDevice(DEVICE2, builder); |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 981 | DeviceCapability device2Cap = netConfigRegistry.addConfig(DeviceId.deviceId("2.2.2.2"), DeviceCapability.class); |
| 982 | device2Cap.setLabelStackCap(true) |
| 983 | .setLocalLabelCap(false) |
| 984 | .setSrCap(true) |
| 985 | .apply(); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 986 | |
| 987 | //Device3 |
| 988 | builder = DefaultAnnotations.builder(); |
| 989 | builder.set(AnnotationKeys.TYPE, L3); |
| 990 | builder.set(LSRID, "3.3.3.3"); |
| 991 | addDevice(DEVICE3, builder); |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 992 | DeviceCapability device3Cap = netConfigRegistry.addConfig(DeviceId.deviceId("3.3.3.3"), DeviceCapability.class); |
| 993 | device3Cap.setLabelStackCap(true) |
| 994 | .setLocalLabelCap(false) |
| 995 | .setSrCap(true) |
| 996 | .apply(); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 997 | |
| 998 | //Device4 |
| 999 | builder = DefaultAnnotations.builder(); |
| 1000 | builder.set(AnnotationKeys.TYPE, L3); |
| 1001 | builder.set(LSRID, "4.4.4.4"); |
| 1002 | addDevice(DEVICE4, builder); |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 1003 | DeviceCapability device4Cap = netConfigRegistry.addConfig(DeviceId.deviceId("4.4.4.4"), DeviceCapability.class); |
| 1004 | device4Cap.setLabelStackCap(true) |
| 1005 | .setLocalLabelCap(false) |
| 1006 | .setSrCap(true) |
| 1007 | .apply(); |
| 1008 | |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 1009 | Set<Path> paths = computePath(link1, link2, link3, link4, constraints); |
| 1010 | |
| 1011 | List<Link> links = new LinkedList<>(); |
| 1012 | links.add(link1); |
| 1013 | links.add(link2); |
| 1014 | assertThat(paths.iterator().next().cost(), is((double) 2)); |
| 1015 | } |
| 1016 | |
| 1017 | /** |
| 1018 | * Test case with empty constraints. |
| 1019 | */ |
| 1020 | @Test |
| 1021 | public void testpathComputationCase14() { |
| 1022 | Link link1 = addLink(DEVICE1, 10, DEVICE2, 20, false, 50); |
| 1023 | Link link2 = addLink(DEVICE2, 30, DEVICE4, 40, false, 20); |
| 1024 | Link link3 = addLink(DEVICE1, 80, DEVICE3, 70, false, 100); |
| 1025 | Link link4 = addLink(DEVICE3, 60, DEVICE4, 50, false, 80); |
| 1026 | |
| 1027 | List<Constraint> constraints = new LinkedList<>(); |
| 1028 | Set<Path> paths = computePath(link1, link2, link3, link4, constraints); |
| 1029 | |
| 1030 | assertThat(paths.iterator().next().cost(), is((double) 2)); |
| 1031 | } |
| 1032 | |
| 1033 | /** |
| 1034 | * Test case with constraints as null. |
| 1035 | */ |
| 1036 | @Test |
| 1037 | public void testpathComputationCase15() { |
| 1038 | Link link1 = addLink(DEVICE1, 10, DEVICE2, 20, false, 50); |
| 1039 | Link link2 = addLink(DEVICE2, 30, DEVICE4, 40, false, 20); |
| 1040 | Link link3 = addLink(DEVICE1, 80, DEVICE3, 70, false, 100); |
| 1041 | Link link4 = addLink(DEVICE3, 60, DEVICE4, 50, false, 80); |
| 1042 | |
| 1043 | List<Constraint> constraints = null; |
| 1044 | Set<Path> paths = computePath(link1, link2, link3, link4, constraints); |
| 1045 | |
| 1046 | assertThat(paths.iterator().next().cost(), is((double) 2)); |
| 1047 | } |
| 1048 | |
| 1049 | /** |
| 1050 | * Path with cost constraint. |
| 1051 | */ |
| 1052 | @Test |
| 1053 | public void testpathComputationCase16() { |
| 1054 | Link link1 = addLink(DEVICE1, 10, DEVICE2, 20, true, 50); |
| 1055 | Link link2 = addLink(DEVICE2, 30, DEVICE4, 40, true, 100); |
| 1056 | Link link3 = addLink(DEVICE1, 80, DEVICE3, 70, true, 10); |
| 1057 | Link link4 = addLink(DEVICE3, 60, DEVICE4, 50, true, 10); |
| 1058 | Link link5 = addLink(DEVICE4, 90, DEVICE5, 100, true, 20); |
| 1059 | |
| 1060 | CostConstraint costConst = CostConstraint.of(COST); |
| 1061 | |
| 1062 | List<Constraint> constraints = new LinkedList<>(); |
| 1063 | constraints.add(costConst); |
| 1064 | Graph<TopologyVertex, TopologyEdge> graph = new AdjacencyListsGraph<>(of(D1, D2, D3, D4, D5), |
| 1065 | of(new DefaultTopologyEdge(D1, D2, link1), |
| 1066 | new DefaultTopologyEdge(D2, D4, link2), |
| 1067 | new DefaultTopologyEdge(D1, D3, link3), |
| 1068 | new DefaultTopologyEdge(D3, D4, link4), |
| 1069 | new DefaultTopologyEdge(D4, D5, link5))); |
| 1070 | |
| 1071 | GraphPathSearch.Result<TopologyVertex, TopologyEdge> result = |
| 1072 | graphSearch().search(graph, D1, D5, weight(constraints), ALL_PATHS); |
| 1073 | ImmutableSet.Builder<Path> builder = ImmutableSet.builder(); |
| 1074 | for (org.onlab.graph.Path<TopologyVertex, TopologyEdge> path : result.paths()) { |
| 1075 | builder.add(networkPath(path)); |
| 1076 | } |
| 1077 | |
| 1078 | List<Link> links = new LinkedList<>(); |
| 1079 | links.add(link3); |
| 1080 | links.add(link4); |
| 1081 | links.add(link5); |
| 1082 | assertThat(builder.build().iterator().next().links(), is(links)); |
| 1083 | assertThat(builder.build().iterator().next().cost(), is((double) 40)); |
| 1084 | } |
| 1085 | |
| 1086 | /** |
| 1087 | * D3 doesn't support capability constraint, so path is L1-L2. |
| 1088 | */ |
| 1089 | @Test |
| 1090 | public void testpathComputationCase17() { |
| 1091 | Link link1 = addLink(DEVICE1, 10, DEVICE2, 20, false, 50); |
| 1092 | Link link2 = addLink(DEVICE2, 30, DEVICE4, 40, false, 20); |
| 1093 | Link link3 = addLink(DEVICE1, 80, DEVICE3, 70, false, 100); |
| 1094 | Link link4 = addLink(DEVICE3, 60, DEVICE4, 50, false, 80); |
| 1095 | |
| 1096 | CapabilityConstraint capabilityConst = CapabilityConstraint |
| 1097 | .of(CapabilityConstraint.CapabilityType.WITHOUT_SIGNALLING_AND_WITHOUT_SR); |
| 1098 | |
| 1099 | List<Constraint> constraints = new LinkedList<>(); |
| 1100 | constraints.add(capabilityConst); |
| 1101 | //Device1 |
| 1102 | DefaultAnnotations.Builder builder = DefaultAnnotations.builder(); |
| 1103 | builder.set(AnnotationKeys.TYPE, L3); |
| 1104 | builder.set(LSRID, "1.1.1.1"); |
| 1105 | addDevice(DEVICE1, builder); |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 1106 | DeviceCapability device1Cap = netConfigRegistry.addConfig(DeviceId.deviceId("1.1.1.1"), DeviceCapability.class); |
| 1107 | device1Cap.setLabelStackCap(false) |
| 1108 | .setLocalLabelCap(true) |
| 1109 | .setSrCap(false) |
| 1110 | .apply(); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 1111 | |
| 1112 | //Device2 |
| 1113 | builder = DefaultAnnotations.builder(); |
| 1114 | builder.set(AnnotationKeys.TYPE, L3); |
| 1115 | builder.set(LSRID, "2.2.2.2"); |
| 1116 | addDevice(DEVICE2, builder); |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 1117 | DeviceCapability device2Cap = netConfigRegistry.addConfig(DeviceId.deviceId("2.2.2.2"), DeviceCapability.class); |
| 1118 | device2Cap.setLabelStackCap(false) |
| 1119 | .setLocalLabelCap(true) |
| 1120 | .setSrCap(false) |
| 1121 | .apply(); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 1122 | |
| 1123 | //Device4 |
| 1124 | builder = DefaultAnnotations.builder(); |
| 1125 | builder.set(AnnotationKeys.TYPE, L3); |
| 1126 | builder.set(LSRID, "4.4.4.4"); |
| 1127 | addDevice(DEVICE4, builder); |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 1128 | DeviceCapability device4Cap = netConfigRegistry.addConfig(DeviceId.deviceId("4.4.4.4"), DeviceCapability.class); |
| 1129 | device4Cap.setLabelStackCap(false) |
| 1130 | .setLocalLabelCap(true) |
| 1131 | .setSrCap(false) |
| 1132 | .apply(); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 1133 | Set<Path> paths = computePath(link1, link2, link3, link4, constraints); |
| 1134 | |
| 1135 | List<Link> links = new LinkedList<>(); |
| 1136 | links.add(link1); |
| 1137 | links.add(link2); |
| 1138 | |
| 1139 | assertThat(paths.iterator().next().links(), is(links)); |
| 1140 | assertThat(paths.iterator().next().cost(), is((double) 2)); |
| 1141 | } |
| 1142 | |
| 1143 | /** |
| 1144 | * L2 doesn't support cost constraint and D3 doesn't support capability constraint, both constraint fails hence no |
| 1145 | * path. |
| 1146 | */ |
| 1147 | @Test |
| 1148 | public void testpathComputationCase18() { |
| 1149 | Link link1 = addLink(DEVICE1, 10, DEVICE2, 20, true, 50); |
| 1150 | Link link2 = addLink(DEVICE2, 30, DEVICE4, 40, false, 20); |
| 1151 | Link link3 = addLink(DEVICE1, 80, DEVICE3, 70, true, 10); |
| 1152 | Link link4 = addLink(DEVICE3, 60, DEVICE4, 50, true, 10); |
| 1153 | |
| 1154 | CapabilityConstraint capabilityConst = CapabilityConstraint |
| 1155 | .of(CapabilityConstraint.CapabilityType.WITHOUT_SIGNALLING_AND_WITHOUT_SR); |
| 1156 | CostConstraint costConst = CostConstraint.of(COST); |
| 1157 | List<Constraint> constraints = new LinkedList<>(); |
| 1158 | constraints.add(capabilityConst); |
| 1159 | constraints.add(costConst); |
| 1160 | //Device1 |
| 1161 | DefaultAnnotations.Builder builder = DefaultAnnotations.builder(); |
| 1162 | builder.set(AnnotationKeys.TYPE, L3); |
| 1163 | builder.set(LSRID, "1.1.1.1"); |
| 1164 | addDevice(DEVICE2, builder); |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 1165 | DeviceCapability device1Cap = netConfigRegistry.addConfig(DeviceId.deviceId("1.1.1.1"), DeviceCapability.class); |
| 1166 | device1Cap.setLabelStackCap(false) |
| 1167 | .setLocalLabelCap(true) |
| 1168 | .setSrCap(false) |
| 1169 | .apply(); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 1170 | |
| 1171 | //Device2 |
| 1172 | builder = DefaultAnnotations.builder(); |
| 1173 | builder.set(AnnotationKeys.TYPE, L3); |
| 1174 | builder.set(LSRID, "2.2.2.2"); |
| 1175 | addDevice(DEVICE2, builder); |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 1176 | DeviceCapability device2Cap = netConfigRegistry.addConfig(DeviceId.deviceId("2.2.2.2"), DeviceCapability.class); |
| 1177 | device2Cap.setLabelStackCap(false) |
| 1178 | .setLocalLabelCap(true) |
| 1179 | .setSrCap(false) |
| 1180 | .apply(); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 1181 | |
| 1182 | //Device4 |
| 1183 | builder = DefaultAnnotations.builder(); |
| 1184 | builder.set(AnnotationKeys.TYPE, L3); |
| 1185 | builder.set(LSRID, "4.4.4.4"); |
| 1186 | addDevice(DEVICE4, builder); |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 1187 | DeviceCapability device4Cap = netConfigRegistry.addConfig(DeviceId.deviceId("4.4.4.4"), DeviceCapability.class); |
| 1188 | device4Cap.setLabelStackCap(false) |
| 1189 | .setLocalLabelCap(true) |
| 1190 | .setSrCap(false) |
| 1191 | .apply(); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 1192 | Set<Path> paths = computePath(link1, link2, link3, link4, constraints); |
| 1193 | |
| 1194 | assertThat(paths, is(new HashSet<>())); |
| 1195 | } |
| 1196 | |
| 1197 | private void addDevice(String device, DefaultAnnotations.Builder builder) { |
| 1198 | deviceService.addDevice(new DefaultDevice(ProviderId.NONE, deviceId(device), Type.ROUTER, |
| 1199 | UNKNOWN, UNKNOWN, UNKNOWN, |
| 1200 | UNKNOWN, new ChassisId(), builder.build())); |
| 1201 | } |
Sho SHIMIZU | ef835c9 | 2016-08-08 13:51:17 -0700 | [diff] [blame] | 1202 | } |