Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame^] | 2 | * Copyright 2016-present Open Networking Foundation |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [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 | */ |
| 16 | package org.onosproject.pce.pceservice; |
| 17 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 18 | import com.fasterxml.jackson.databind.JsonNode; |
| 19 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 20 | import com.fasterxml.jackson.databind.node.JsonNodeFactory; |
| 21 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 22 | import com.google.common.collect.ImmutableList; |
| 23 | import com.google.common.collect.ImmutableSet; |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 24 | import org.junit.After; |
| 25 | import org.junit.Before; |
| 26 | import org.junit.Test; |
| 27 | import org.onlab.graph.AbstractGraphPathSearch; |
| 28 | import org.onlab.graph.AdjacencyListsGraph; |
| 29 | import org.onlab.graph.DijkstraGraphSearch; |
| 30 | import org.onlab.graph.Graph; |
| 31 | import org.onlab.graph.GraphPathSearch; |
| 32 | import org.onlab.packet.ChassisId; |
| 33 | import org.onlab.util.Bandwidth; |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 34 | import org.onosproject.net.AnnotationKeys; |
| 35 | import org.onosproject.net.ConnectPoint; |
| 36 | import org.onosproject.net.DefaultAnnotations; |
| 37 | import org.onosproject.net.DefaultDevice; |
| 38 | import org.onosproject.net.DefaultLink; |
| 39 | import org.onosproject.net.DefaultPath; |
| 40 | import org.onosproject.net.Device; |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 41 | import org.onosproject.net.Device.Type; |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 42 | import org.onosproject.net.DeviceId; |
| 43 | import org.onosproject.net.Link; |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 44 | import org.onosproject.net.LinkKey; |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 45 | import org.onosproject.net.Path; |
| 46 | import org.onosproject.net.PortNumber; |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 47 | import org.onosproject.net.config.Config; |
| 48 | import org.onosproject.net.config.ConfigApplyDelegate; |
| 49 | import org.onosproject.net.config.ConfigFactory; |
| 50 | import org.onosproject.net.config.NetworkConfigRegistryAdapter; |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 51 | import org.onosproject.net.device.DeviceServiceAdapter; |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 52 | import org.onosproject.net.intent.Constraint; |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 53 | import org.onosproject.net.provider.ProviderId; |
| 54 | import org.onosproject.net.topology.DefaultTopologyEdge; |
| 55 | import org.onosproject.net.topology.DefaultTopologyVertex; |
| 56 | import org.onosproject.net.topology.LinkWeight; |
| 57 | import org.onosproject.net.topology.TopologyEdge; |
| 58 | import org.onosproject.net.topology.TopologyVertex; |
| 59 | import org.onosproject.pce.pceservice.constraint.CapabilityConstraint; |
| 60 | import org.onosproject.pce.pceservice.constraint.CostConstraint; |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 61 | import org.onosproject.pce.pceservice.constraint.PceBandwidthConstraint; |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 62 | import org.onosproject.pce.pceservice.constraint.SharedBandwidthConstraint; |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 63 | import org.onosproject.pcep.api.DeviceCapability; |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 64 | import org.onosproject.pcep.api.TeLinkConfig; |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 65 | |
| 66 | import java.util.Collections; |
| 67 | import java.util.HashMap; |
| 68 | import java.util.HashSet; |
| 69 | import java.util.Iterator; |
| 70 | import java.util.LinkedList; |
| 71 | import java.util.List; |
| 72 | import java.util.Map; |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 73 | import java.util.Set; |
| 74 | import java.util.stream.Collectors; |
| 75 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 76 | import static com.google.common.base.Preconditions.checkNotNull; |
| 77 | import static com.google.common.collect.ImmutableSet.of; |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 78 | import static org.hamcrest.MatcherAssert.assertThat; |
| 79 | import static org.hamcrest.core.Is.is; |
| 80 | import static org.onlab.graph.GraphPathSearch.ALL_PATHS; |
| 81 | import static org.onosproject.core.CoreService.CORE_PROVIDER_ID; |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 82 | import static org.onosproject.net.DeviceId.deviceId; |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 83 | import static org.onosproject.net.Link.State.ACTIVE; |
| 84 | import static org.onosproject.net.Link.Type.DIRECT; |
Andrey Komarov | 2398d96 | 2016-09-26 15:11:23 +0300 | [diff] [blame] | 85 | import static org.onosproject.net.topology.AdapterLinkWeigher.adapt; |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 86 | import static org.onosproject.pce.pceservice.constraint.CostConstraint.Type.COST; |
| 87 | import static org.onosproject.pce.pceservice.constraint.CostConstraint.Type.TE_COST; |
| 88 | |
| 89 | /** |
| 90 | * Test for CSPF path computation. |
| 91 | */ |
| 92 | public class PathComputationTest { |
| 93 | |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 94 | private final MockDeviceService deviceService = new MockDeviceService(); |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 95 | private final MockNetConfigRegistryAdapter netConfigRegistry = new MockNetConfigRegistryAdapter(); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 96 | private PceManager pceManager = new PceManager(); |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 97 | private final MockBandwidthMgmtService bandwidthMgmtService = new MockBandwidthMgmtService(); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 98 | public static ProviderId providerId = new ProviderId("pce", "foo"); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 99 | public static final String DEVICE1 = "D001"; |
| 100 | public static final String DEVICE2 = "D002"; |
| 101 | public static final String DEVICE3 = "D003"; |
| 102 | public static final String DEVICE4 = "D004"; |
| 103 | public static final String DEVICE5 = "D005"; |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 104 | public static final String PCEPDEVICE1 = "PD001"; |
| 105 | public static final String PCEPDEVICE2 = "PD002"; |
| 106 | public static final String PCEPDEVICE3 = "PD003"; |
| 107 | public static final String PCEPDEVICE4 = "PD004"; |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 108 | public static final TopologyVertex D1 = new DefaultTopologyVertex(DeviceId.deviceId("D001")); |
| 109 | public static final TopologyVertex D2 = new DefaultTopologyVertex(DeviceId.deviceId("D002")); |
| 110 | public static final TopologyVertex D3 = new DefaultTopologyVertex(DeviceId.deviceId("D003")); |
| 111 | public static final TopologyVertex D4 = new DefaultTopologyVertex(DeviceId.deviceId("D004")); |
| 112 | public static final TopologyVertex D5 = new DefaultTopologyVertex(DeviceId.deviceId("D005")); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 113 | private static final String ANNOTATION_COST = "cost"; |
| 114 | private static final String ANNOTATION_TE_COST = "teCost"; |
| 115 | private static final String UNKNOWN = "unknown"; |
| 116 | public static final String LSRID = "lsrId"; |
| 117 | public static final String L3 = "L3"; |
| 118 | public static final String PCECC_CAPABILITY = "pceccCapability"; |
| 119 | public static final String SR_CAPABILITY = "srCapability"; |
| 120 | public static final String LABEL_STACK_CAPABILITY = "labelStackCapability"; |
| 121 | |
| 122 | @Before |
| 123 | public void startUp() { |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 124 | pceManager.deviceService = deviceService; |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 125 | pceManager.netCfgService = netConfigRegistry; |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | /** |
| 129 | * Selects path computation algorithm. |
| 130 | * |
| 131 | * @return graph path search algorithm |
| 132 | */ |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 133 | public static AbstractGraphPathSearch<TopologyVertex, TopologyEdge> graphSearch() { |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 134 | return new DijkstraGraphSearch<>(); |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * Returns link for two devices. |
| 139 | * |
| 140 | * @param device source device |
| 141 | * @param port source port |
| 142 | * @param device2 destination device |
| 143 | * @param port2 destination port |
| 144 | * @return link |
| 145 | */ |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 146 | 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] | 147 | ConnectPoint src = new ConnectPoint(DeviceId.deviceId(device), PortNumber.portNumber(port)); |
| 148 | ConnectPoint dst = new ConnectPoint(DeviceId.deviceId(device2), PortNumber.portNumber(port2)); |
| 149 | Link curLink; |
| 150 | DefaultAnnotations.Builder annotationBuilder = DefaultAnnotations.builder(); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 151 | |
| 152 | //TODO:If cost not set cost : default value case |
| 153 | curLink = DefaultLink.builder().src(src).dst(dst).state(ACTIVE).type(DIRECT) |
| 154 | .providerId(PathComputationTest.providerId).annotations(annotationBuilder.build()).build(); |
| 155 | return curLink; |
| 156 | } |
| 157 | |
| 158 | @After |
| 159 | public void tearDown() { |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 160 | pceManager.deviceService = null; |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 161 | pceManager.netCfgService = null; |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | /** |
| 165 | * Returns an edge-weight capable of evaluating links on the basis of the |
| 166 | * specified constraints. |
| 167 | * |
| 168 | * @param constraints path constraints |
| 169 | * @return edge-weight function |
| 170 | */ |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 171 | private LinkWeight weight(List<Constraint> constraints) { |
| 172 | return new MockTeConstraintBasedLinkWeight(constraints); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | private Set<Path> computePath(Link link1, Link link2, Link link3, Link link4, List<Constraint> constraints) { |
| 176 | Graph<TopologyVertex, TopologyEdge> graph = new AdjacencyListsGraph<>(of(D1, D2, D3, D4), |
| 177 | of(new DefaultTopologyEdge(D1, D2, link1), |
| 178 | new DefaultTopologyEdge(D2, D4, link2), |
| 179 | new DefaultTopologyEdge(D1, D3, link3), |
| 180 | new DefaultTopologyEdge(D3, D4, link4))); |
| 181 | |
| 182 | GraphPathSearch.Result<TopologyVertex, TopologyEdge> result = |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 183 | graphSearch().search(graph, D1, D4, adapt(weight(constraints)), ALL_PATHS); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 184 | ImmutableSet.Builder<Path> builder = ImmutableSet.builder(); |
| 185 | for (org.onlab.graph.Path<TopologyVertex, TopologyEdge> path : result.paths()) { |
| 186 | builder.add(networkPath(path)); |
| 187 | } |
| 188 | return builder.build(); |
| 189 | } |
| 190 | |
| 191 | private class MockDeviceService extends DeviceServiceAdapter { |
| 192 | List<Device> devices = new LinkedList<>(); |
| 193 | |
| 194 | private void addDevice(Device dev) { |
| 195 | devices.add(dev); |
| 196 | } |
| 197 | |
| 198 | @Override |
| 199 | public Device getDevice(DeviceId deviceId) { |
| 200 | for (Device dev : devices) { |
| 201 | if (dev.id().equals(deviceId)) { |
| 202 | return dev; |
| 203 | } |
| 204 | } |
| 205 | return null; |
| 206 | } |
| 207 | |
| 208 | @Override |
| 209 | public Iterable<Device> getAvailableDevices() { |
| 210 | return devices; |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | private class MockTeConstraintBasedLinkWeight implements LinkWeight { |
| 215 | |
| 216 | private final List<Constraint> constraints; |
| 217 | |
| 218 | /** |
| 219 | * Creates a new edge-weight function capable of evaluating links |
| 220 | * on the basis of the specified constraints. |
| 221 | * |
| 222 | * @param constraints path constraints |
| 223 | */ |
| 224 | MockTeConstraintBasedLinkWeight(List<Constraint> constraints) { |
| 225 | if (constraints == null) { |
| 226 | this.constraints = Collections.emptyList(); |
| 227 | } else { |
| 228 | this.constraints = ImmutableList.copyOf(constraints); |
| 229 | } |
| 230 | } |
| 231 | |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 232 | @Override |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 233 | public double weight(TopologyEdge edge) { |
| 234 | if (!constraints.iterator().hasNext()) { |
| 235 | //Takes default cost/hopcount as 1 if no constraints specified |
| 236 | return 1.0; |
| 237 | } |
| 238 | |
| 239 | Iterator<Constraint> it = constraints.iterator(); |
| 240 | double cost = 1; |
| 241 | |
| 242 | //If any constraint fails return -1 also value of cost returned from cost constraint can't be negative |
| 243 | while (it.hasNext() && cost > 0) { |
| 244 | Constraint constraint = it.next(); |
| 245 | if (constraint instanceof CapabilityConstraint) { |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 246 | cost = ((CapabilityConstraint) constraint).isValidLink(edge.link(), deviceService, |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 247 | netConfigRegistry) ? 1 : -1; |
| 248 | } else if (constraint instanceof PceBandwidthConstraint) { |
| 249 | cost = ((PceBandwidthConstraint) constraint).isValidLink(edge.link(), |
| 250 | bandwidthMgmtService) ? 1 : -1; |
| 251 | |
| 252 | } else if (constraint instanceof SharedBandwidthConstraint) { |
| 253 | cost = ((SharedBandwidthConstraint) constraint).isValidLink(edge.link(), |
| 254 | bandwidthMgmtService) ? 1 : -1; |
| 255 | |
| 256 | } else if (constraint instanceof CostConstraint) { |
| 257 | cost = ((CostConstraint) constraint).isValidLink(edge.link(), netConfigRegistry); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 258 | } else { |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 259 | cost = constraint.cost(edge.link(), null); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 260 | } |
| 261 | } |
| 262 | return cost; |
| 263 | } |
| 264 | } |
| 265 | |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 266 | /** |
| 267 | * Returns the path in Path object format. |
| 268 | */ |
| 269 | public static Path networkPath(org.onlab.graph.Path<TopologyVertex, TopologyEdge> path) { |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 270 | List<Link> links = path.edges().stream().map(TopologyEdge::link).collect(Collectors.toList()); |
| 271 | return new DefaultPath(CORE_PROVIDER_ID, links, path.cost()); |
| 272 | } |
| 273 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 274 | public static class MockBandwidthMgmtService extends BandwidthMgmtServiceAdapter { |
| 275 | private Map<LinkKey, Double> teCost = new HashMap<>(); |
| 276 | // Locally maintain unreserved bandwidth of each link. |
| 277 | private Map<LinkKey, Set<Double>> unResvBw = new HashMap<>(); |
| 278 | |
| 279 | // Mapping tunnel with link key with local reserved bandwidth |
| 280 | private Map<LinkKey, Double> localReservedBw = new HashMap<>(); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 281 | |
| 282 | @Override |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 283 | public boolean allocLocalReservedBw(LinkKey linkkey, Double bandwidth) { |
| 284 | Double allocatedBw = localReservedBw.get(linkkey); |
| 285 | if (allocatedBw != null) { |
| 286 | localReservedBw.put(linkkey, (allocatedBw + bandwidth)); |
| 287 | } else { |
| 288 | localReservedBw.put(linkkey, bandwidth); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 289 | } |
| 290 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 291 | return true; |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | @Override |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 295 | public boolean releaseLocalReservedBw(LinkKey linkkey, Double bandwidth) { |
| 296 | Double allocatedBw = localReservedBw.get(linkkey); |
| 297 | if (allocatedBw == null || allocatedBw < bandwidth) { |
| 298 | return false; |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 299 | } |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 300 | |
| 301 | Double releasedBw = allocatedBw - bandwidth; |
| 302 | if (releasedBw == 0.0) { |
| 303 | localReservedBw.remove(linkkey); |
| 304 | } else { |
| 305 | localReservedBw.put(linkkey, releasedBw); |
| 306 | } |
| 307 | return true; |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | @Override |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 311 | public Double getAllocatedLocalReservedBw(LinkKey linkkey) { |
| 312 | return localReservedBw.get(linkkey); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | @Override |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 316 | public boolean addUnreservedBw(LinkKey linkkey, Set<Double> bandwidth) { |
| 317 | unResvBw.put(linkkey, bandwidth); |
| 318 | return true; |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | @Override |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 322 | public boolean removeUnreservedBw(LinkKey linkkey) { |
| 323 | unResvBw.remove(linkkey); |
| 324 | return true; |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | @Override |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 328 | public Set<Double> getUnreservedBw(LinkKey linkkey) { |
| 329 | checkNotNull(linkkey); |
| 330 | return unResvBw.get(linkkey); |
| 331 | } |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 332 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 333 | @Override |
| 334 | public boolean isBandwidthAvailable(Link link, Double bandwidth) { |
| 335 | LinkKey linkKey = LinkKey.linkKey(link); |
| 336 | Double localAllocBw = getAllocatedLocalReservedBw(linkKey); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 337 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 338 | Set<Double> unResvBw = getUnreservedBw(linkKey); |
| 339 | |
| 340 | Double prirZeroBw = unResvBw.iterator().next(); |
| 341 | return (bandwidth <= prirZeroBw - (localAllocBw != null ? localAllocBw : 0)); |
| 342 | } |
| 343 | |
| 344 | @Override |
| 345 | public Double getTeCost(LinkKey linkKey) { |
| 346 | if (teCost.get(linkKey) != null) { |
| 347 | return teCost.get(linkKey); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 348 | } |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 349 | return null; |
| 350 | } |
| 351 | |
| 352 | @Override |
| 353 | public Double getAvailableBandwidth(LinkKey linkKey) { |
| 354 | if (unResvBw.get(linkKey) != null && localReservedBw.get(linkKey) != null) { |
| 355 | |
| 356 | return unResvBw.get(linkKey).iterator().next().doubleValue() |
| 357 | - localReservedBw.get(linkKey).doubleValue(); |
| 358 | } |
| 359 | return unResvBw.get(linkKey).iterator().next().doubleValue(); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 360 | } |
| 361 | } |
| 362 | |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 363 | /* Mock test for network config registry. */ |
| 364 | public static class MockNetConfigRegistryAdapter extends NetworkConfigRegistryAdapter { |
| 365 | private ConfigFactory cfgFactory; |
| 366 | private Map<DeviceId, DeviceCapability> classConfig = new HashMap<>(); |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 367 | private Map<LinkKey, TeLinkConfig> teLinkConfig = new HashMap<>(); |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 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; |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 390 | } else if (configClass == TeLinkConfig.class) { |
| 391 | TeLinkConfig teConfig = new TeLinkConfig(); |
| 392 | teLinkConfig.put((LinkKey) subject, teConfig); |
| 393 | |
| 394 | JsonNode node = new ObjectNode(new MockJsonNode()); |
| 395 | ObjectMapper mapper = new ObjectMapper(); |
| 396 | ConfigApplyDelegate delegate = new InternalApplyDelegate(); |
| 397 | teConfig.init((LinkKey) subject, null, node, mapper, delegate); |
| 398 | return (C) teConfig; |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | return null; |
| 402 | } |
| 403 | |
| 404 | @Override |
| 405 | public <S, C extends Config<S>> void removeConfig(S subject, Class<C> configClass) { |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 406 | if (configClass == DeviceCapability.class) { |
| 407 | classConfig.remove(subject); |
| 408 | } else if (configClass == TeLinkConfig.class) { |
| 409 | teLinkConfig.remove(subject); |
| 410 | } |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | @Override |
| 414 | public <S, C extends Config<S>> C getConfig(S subject, Class<C> configClass) { |
| 415 | if (configClass == DeviceCapability.class) { |
| 416 | return (C) classConfig.get(subject); |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 417 | } else if (configClass == TeLinkConfig.class) { |
| 418 | return (C) teLinkConfig.get(subject); |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 419 | } |
| 420 | return null; |
| 421 | } |
| 422 | |
| 423 | private class MockJsonNode extends JsonNodeFactory { |
| 424 | } |
| 425 | |
| 426 | // Auxiliary delegate to receive notifications about changes applied to |
| 427 | // the network configuration - by the apps. |
| 428 | private class InternalApplyDelegate implements ConfigApplyDelegate { |
| 429 | @Override |
| 430 | public void onApply(Config config) { |
| 431 | //configs.put(config.subject(), config.node()); |
| 432 | } |
| 433 | } |
| 434 | } |
| 435 | |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 436 | /** |
| 437 | * All links with different costs with L1-L2 as least cost path. |
| 438 | */ |
| 439 | @Test |
| 440 | public void testpathComputationCase1() { |
| 441 | Link link1 = addLink(DEVICE1, 10, DEVICE2, 20, true, 50); |
| 442 | Link link2 = addLink(DEVICE2, 30, DEVICE4, 40, true, 20); |
| 443 | Link link3 = addLink(DEVICE1, 80, DEVICE3, 70, true, 100); |
| 444 | Link link4 = addLink(DEVICE3, 60, DEVICE4, 50, true, 50); |
| 445 | |
| 446 | CostConstraint costConst = CostConstraint.of(COST); |
| 447 | List<Constraint> constraints = new LinkedList<>(); |
| 448 | constraints.add(costConst); |
| 449 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 450 | TeLinkConfig teLinkConfig = netConfigRegistry.addConfig(LinkKey.linkKey(link1), TeLinkConfig.class); |
| 451 | teLinkConfig.igpCost(50) |
| 452 | .apply(); |
| 453 | |
| 454 | |
| 455 | TeLinkConfig teLinkConfig2 = netConfigRegistry.addConfig(LinkKey.linkKey(link2), TeLinkConfig.class); |
| 456 | teLinkConfig2.igpCost(20) |
| 457 | .apply(); |
| 458 | |
| 459 | TeLinkConfig teLinkConfig3 = netConfigRegistry.addConfig(LinkKey.linkKey(link3), TeLinkConfig.class); |
| 460 | teLinkConfig3.igpCost(100) |
| 461 | .apply(); |
| 462 | |
| 463 | TeLinkConfig teLinkConfig4 = netConfigRegistry.addConfig(LinkKey.linkKey(link4), TeLinkConfig.class); |
| 464 | teLinkConfig4.igpCost(50) |
| 465 | .apply(); |
| 466 | |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 467 | Set<Path> paths = computePath(link1, link2, link3, link4, constraints); |
| 468 | |
| 469 | List<Link> links = new LinkedList<>(); |
| 470 | |
| 471 | links.add(link1); |
| 472 | links.add(link2); |
| 473 | |
| 474 | assertThat(paths.iterator().next().links(), is(links)); |
| 475 | assertThat(paths.iterator().next().cost(), is((double) 70)); |
| 476 | } |
| 477 | |
| 478 | /** |
| 479 | * Links with same cost 100 except link3. |
| 480 | */ |
| 481 | @Test |
| 482 | public void testpathComputationCase2() { |
| 483 | Link link1 = addLink(DEVICE1, 10, DEVICE2, 20, true, 100); |
| 484 | Link link2 = addLink(DEVICE2, 30, DEVICE4, 40, true, 100); |
| 485 | Link link3 = addLink(DEVICE1, 80, DEVICE3, 70, true, 1000); |
| 486 | Link link4 = addLink(DEVICE3, 60, DEVICE4, 50, true, 100); |
| 487 | |
| 488 | CostConstraint costConst = CostConstraint.of(COST); |
| 489 | List<Constraint> constraints = new LinkedList<>(); |
| 490 | constraints.add(costConst); |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 491 | |
| 492 | TeLinkConfig teLinkConfig = netConfigRegistry.addConfig(LinkKey.linkKey(link1), TeLinkConfig.class); |
| 493 | teLinkConfig.igpCost(100) |
| 494 | .apply(); |
| 495 | |
| 496 | |
| 497 | TeLinkConfig teLinkConfig2 = netConfigRegistry.addConfig(LinkKey.linkKey(link2), TeLinkConfig.class); |
| 498 | teLinkConfig2.igpCost(100) |
| 499 | .apply(); |
| 500 | |
| 501 | TeLinkConfig teLinkConfig3 = netConfigRegistry.addConfig(LinkKey.linkKey(link3), TeLinkConfig.class); |
| 502 | teLinkConfig3.igpCost(1000) |
| 503 | .apply(); |
| 504 | |
| 505 | TeLinkConfig teLinkConfig4 = netConfigRegistry.addConfig(LinkKey.linkKey(link4), TeLinkConfig.class); |
| 506 | teLinkConfig4.igpCost(100) |
| 507 | .apply(); |
| 508 | |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 509 | Set<Path> paths = computePath(link1, link2, link3, link4, constraints); |
| 510 | |
| 511 | List<Link> links = new LinkedList<>(); |
| 512 | links.add(link1); |
| 513 | links.add(link2); |
| 514 | |
| 515 | assertThat(paths.iterator().next().links(), is(links)); |
| 516 | assertThat(paths.iterator().next().cost(), is((double) 200)); |
| 517 | } |
| 518 | |
| 519 | /** |
| 520 | * Path which satisfy bandwidth as a constraint with 10bps. |
| 521 | */ |
| 522 | @Test |
| 523 | public void testpathComputationCase3() { |
| 524 | Link link1 = addLink(DEVICE1, 10, DEVICE2, 20, true, 50); |
| 525 | Link link2 = addLink(DEVICE2, 30, DEVICE4, 40, true, 20); |
| 526 | Link link3 = addLink(DEVICE1, 80, DEVICE3, 70, true, 100); |
| 527 | Link link4 = addLink(DEVICE3, 60, DEVICE4, 50, true, 50); |
| 528 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 529 | Set<Double> unreserved = new HashSet<>(); |
| 530 | unreserved.add(new Double(50)); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 531 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 532 | bandwidthMgmtService.addUnreservedBw(LinkKey.linkKey(link1), unreserved); |
| 533 | bandwidthMgmtService.allocLocalReservedBw(LinkKey.linkKey(link1), new Double(0)); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 534 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 535 | bandwidthMgmtService.addUnreservedBw(LinkKey.linkKey(link2), unreserved); |
| 536 | bandwidthMgmtService.allocLocalReservedBw(LinkKey.linkKey(link2), new Double(0)); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 537 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 538 | unreserved.remove(new Double(50)); |
| 539 | unreserved.add(new Double(100)); |
| 540 | bandwidthMgmtService.addUnreservedBw(LinkKey.linkKey(link3), unreserved); |
| 541 | bandwidthMgmtService.allocLocalReservedBw(LinkKey.linkKey(link3), new Double(0)); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 542 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 543 | bandwidthMgmtService.addUnreservedBw(LinkKey.linkKey(link4), unreserved); |
| 544 | bandwidthMgmtService.allocLocalReservedBw(LinkKey.linkKey(link4), new Double(0)); |
| 545 | |
| 546 | PceBandwidthConstraint bandwidthConst = new PceBandwidthConstraint(Bandwidth.bps(10.0)); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 547 | |
| 548 | List<Constraint> constraints = new LinkedList<>(); |
| 549 | constraints.add(bandwidthConst); |
| 550 | |
| 551 | Set<Path> paths = computePath(link1, link2, link3, link4, constraints); |
| 552 | |
| 553 | assertThat(paths.iterator().next().cost(), is((double) 2)); |
| 554 | } |
| 555 | |
| 556 | /** |
| 557 | * Path which satisfy bandwidth as a constraint with 60bps. |
| 558 | */ |
| 559 | @Test |
| 560 | public void testpathComputationCase4() { |
| 561 | Link link1 = addLink(DEVICE1, 10, DEVICE2, 20, true, 50); |
| 562 | Link link2 = addLink(DEVICE2, 30, DEVICE4, 40, true, 50); |
| 563 | Link link3 = addLink(DEVICE1, 80, DEVICE3, 70, true, 100); |
| 564 | Link link4 = addLink(DEVICE3, 60, DEVICE4, 50, true, 100); |
| 565 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 566 | Set<Double> unreserved = new HashSet<>(); |
| 567 | unreserved.add(new Double(50)); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 568 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 569 | bandwidthMgmtService.addUnreservedBw(LinkKey.linkKey(link1), unreserved); |
| 570 | bandwidthMgmtService.allocLocalReservedBw(LinkKey.linkKey(link1), new Double(0)); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 571 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 572 | bandwidthMgmtService.addUnreservedBw(LinkKey.linkKey(link2), unreserved); |
| 573 | bandwidthMgmtService.allocLocalReservedBw(LinkKey.linkKey(link2), new Double(0)); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 574 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 575 | unreserved.remove(new Double(50)); |
| 576 | unreserved.add(new Double(100)); |
| 577 | bandwidthMgmtService.addUnreservedBw(LinkKey.linkKey(link3), unreserved); |
| 578 | bandwidthMgmtService.allocLocalReservedBw(LinkKey.linkKey(link3), new Double(0)); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 579 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 580 | bandwidthMgmtService.addUnreservedBw(LinkKey.linkKey(link4), unreserved); |
| 581 | bandwidthMgmtService.allocLocalReservedBw(LinkKey.linkKey(link4), new Double(0)); |
| 582 | |
| 583 | PceBandwidthConstraint bandwidthConst = new PceBandwidthConstraint(Bandwidth.bps(60.0)); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 584 | |
| 585 | List<Constraint> constraints = new LinkedList<>(); |
| 586 | constraints.add(bandwidthConst); |
| 587 | Set<Path> paths = computePath(link1, link2, link3, link4, constraints); |
| 588 | |
| 589 | assertThat(paths.iterator().next().cost(), is((double) 2)); |
| 590 | } |
| 591 | |
| 592 | /** |
| 593 | * Shared bandwidth as L1, L2 with its value 10 bps and bandwidth constraint as 20 bps. |
| 594 | */ |
| 595 | @Test |
| 596 | public void testpathComputationCase5() { |
| 597 | Link link1 = addLink(DEVICE1, 10, DEVICE2, 20, true, 50); |
| 598 | Link link2 = addLink(DEVICE2, 30, DEVICE4, 40, true, 20); |
| 599 | Link link3 = addLink(DEVICE1, 80, DEVICE3, 70, true, 100); |
| 600 | Link link4 = addLink(DEVICE3, 60, DEVICE4, 50, true, 80); |
| 601 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 602 | Set<Double> unreserved = new HashSet<>(); |
| 603 | unreserved.add(new Double(50)); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 604 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 605 | bandwidthMgmtService.addUnreservedBw(LinkKey.linkKey(link1), unreserved); |
| 606 | bandwidthMgmtService.allocLocalReservedBw(LinkKey.linkKey(link1), new Double(0)); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 607 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 608 | bandwidthMgmtService.addUnreservedBw(LinkKey.linkKey(link2), unreserved); |
| 609 | bandwidthMgmtService.allocLocalReservedBw(LinkKey.linkKey(link2), new Double(0)); |
| 610 | |
| 611 | unreserved.remove(new Double(50)); |
| 612 | unreserved.add(new Double(100)); |
| 613 | bandwidthMgmtService.addUnreservedBw(LinkKey.linkKey(link3), unreserved); |
| 614 | bandwidthMgmtService.allocLocalReservedBw(LinkKey.linkKey(link3), new Double(0)); |
| 615 | |
| 616 | bandwidthMgmtService.addUnreservedBw(LinkKey.linkKey(link4), unreserved); |
| 617 | bandwidthMgmtService.allocLocalReservedBw(LinkKey.linkKey(link4), new Double(0)); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 618 | |
| 619 | List<Constraint> constraints = new LinkedList<>(); |
| 620 | |
| 621 | List<Link> sharedLinks = new LinkedList<>(); |
| 622 | |
| 623 | List<Link> links = new LinkedList<>(); |
| 624 | links.add(link1); |
| 625 | links.add(link2); |
| 626 | |
| 627 | CostConstraint costConst = CostConstraint.of(COST); |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 628 | |
| 629 | |
| 630 | TeLinkConfig teLinkConfig = netConfigRegistry.addConfig(LinkKey.linkKey(link1), TeLinkConfig.class); |
| 631 | teLinkConfig.igpCost(50) |
| 632 | .apply(); |
| 633 | |
| 634 | |
| 635 | TeLinkConfig teLinkConfig2 = netConfigRegistry.addConfig(LinkKey.linkKey(link2), TeLinkConfig.class); |
| 636 | teLinkConfig2.igpCost(20) |
| 637 | .apply(); |
| 638 | |
| 639 | TeLinkConfig teLinkConfig3 = netConfigRegistry.addConfig(LinkKey.linkKey(link3), TeLinkConfig.class); |
| 640 | teLinkConfig3.igpCost(100) |
| 641 | .apply(); |
| 642 | |
| 643 | TeLinkConfig teLinkConfig4 = netConfigRegistry.addConfig(LinkKey.linkKey(link4), TeLinkConfig.class); |
| 644 | teLinkConfig4.igpCost(50) |
| 645 | .apply(); |
| 646 | |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 647 | sharedLinks.addAll(links); |
| 648 | SharedBandwidthConstraint sharedBw = new SharedBandwidthConstraint(sharedLinks, Bandwidth.bps(10), |
| 649 | Bandwidth.bps(20.0)); |
| 650 | constraints.add(sharedBw); |
| 651 | constraints.add(costConst); |
| 652 | Set<Path> paths = computePath(link1, link2, link3, link4, constraints); |
| 653 | assertThat(paths.iterator().next().links(), is(links)); |
| 654 | assertThat(paths.iterator().next().cost(), is((double) 70)); |
| 655 | } |
| 656 | |
| 657 | /** |
| 658 | * Shared bandwidth as L1, L2 with its value 20 bps and bandwidth constraint as 10 bps. |
| 659 | */ |
| 660 | @Test |
| 661 | public void testpathComputationCase6() { |
| 662 | Link link1 = addLink(DEVICE1, 10, DEVICE2, 20, true, 50); |
| 663 | Link link2 = addLink(DEVICE2, 30, DEVICE4, 40, true, 20); |
| 664 | Link link3 = addLink(DEVICE1, 80, DEVICE3, 70, true, 100); |
| 665 | Link link4 = addLink(DEVICE3, 60, DEVICE4, 50, true, 80); |
| 666 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 667 | Set<Double> unreserved = new HashSet<>(); |
| 668 | unreserved.add(new Double(50)); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 669 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 670 | bandwidthMgmtService.addUnreservedBw(LinkKey.linkKey(link1), unreserved); |
| 671 | bandwidthMgmtService.allocLocalReservedBw(LinkKey.linkKey(link1), new Double(0)); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 672 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 673 | bandwidthMgmtService.addUnreservedBw(LinkKey.linkKey(link2), unreserved); |
| 674 | bandwidthMgmtService.allocLocalReservedBw(LinkKey.linkKey(link2), new Double(0)); |
| 675 | |
| 676 | unreserved.remove(new Double(50)); |
| 677 | unreserved.add(new Double(100)); |
| 678 | bandwidthMgmtService.addUnreservedBw(LinkKey.linkKey(link3), unreserved); |
| 679 | bandwidthMgmtService.allocLocalReservedBw(LinkKey.linkKey(link3), new Double(0)); |
| 680 | |
| 681 | bandwidthMgmtService.addUnreservedBw(LinkKey.linkKey(link4), unreserved); |
| 682 | bandwidthMgmtService.allocLocalReservedBw(LinkKey.linkKey(link4), new Double(0)); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 683 | |
| 684 | List<Constraint> constraints = new LinkedList<>(); |
| 685 | |
| 686 | List<Link> sharedLinks = new LinkedList<>(); |
| 687 | |
| 688 | List<Link> links = new LinkedList<>(); |
| 689 | links.add(link1); |
| 690 | links.add(link2); |
| 691 | CostConstraint costConst = CostConstraint.of(COST); |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 692 | |
| 693 | |
| 694 | TeLinkConfig teLinkConfig = netConfigRegistry.addConfig(LinkKey.linkKey(link1), TeLinkConfig.class); |
| 695 | teLinkConfig.igpCost(50) |
| 696 | .apply(); |
| 697 | |
| 698 | |
| 699 | TeLinkConfig teLinkConfig2 = netConfigRegistry.addConfig(LinkKey.linkKey(link2), TeLinkConfig.class); |
| 700 | teLinkConfig2.igpCost(20) |
| 701 | .apply(); |
| 702 | |
| 703 | TeLinkConfig teLinkConfig3 = netConfigRegistry.addConfig(LinkKey.linkKey(link3), TeLinkConfig.class); |
| 704 | teLinkConfig3.igpCost(100) |
| 705 | .apply(); |
| 706 | |
| 707 | TeLinkConfig teLinkConfig4 = netConfigRegistry.addConfig(LinkKey.linkKey(link4), TeLinkConfig.class); |
| 708 | teLinkConfig4.igpCost(80) |
| 709 | .apply(); |
| 710 | |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 711 | sharedLinks.addAll(links); |
| 712 | SharedBandwidthConstraint sharedBwConst = new SharedBandwidthConstraint(sharedLinks, Bandwidth.bps(20), |
| 713 | Bandwidth.bps(10.0)); |
| 714 | constraints.add(sharedBwConst); |
| 715 | constraints.add(costConst); |
| 716 | Set<Path> paths = computePath(link1, link2, link3, link4, constraints); |
| 717 | |
| 718 | assertThat(paths.iterator().next().links(), is(links)); |
| 719 | assertThat(paths.iterator().next().cost(), is((double) 70)); |
| 720 | } |
| 721 | |
| 722 | /** |
| 723 | * Path without constraints. |
| 724 | */ |
| 725 | @Test |
| 726 | public void testpathComputationCase7() { |
| 727 | Link link1 = addLink(DEVICE1, 10, DEVICE2, 20, true, 50); |
| 728 | Link link2 = addLink(DEVICE2, 30, DEVICE4, 40, true, 20); |
| 729 | Link link3 = addLink(DEVICE1, 80, DEVICE3, 70, true, 100); |
| 730 | Link link4 = addLink(DEVICE3, 60, DEVICE4, 50, true, 80); |
| 731 | List<Constraint> constraints = new LinkedList<>(); |
| 732 | Set<Path> paths = computePath(link1, link2, link3, link4, constraints); |
| 733 | |
| 734 | assertThat(paths.iterator().next().cost(), is((double) 2)); |
| 735 | } |
| 736 | |
| 737 | /** |
| 738 | * With TeCost as a constraints. |
| 739 | */ |
| 740 | @Test |
| 741 | public void testpathComputationCase8() { |
| 742 | Link link1 = addLink(DEVICE1, 10, DEVICE2, 20, false, 50); |
| 743 | Link link2 = addLink(DEVICE2, 30, DEVICE4, 40, false, 20); |
| 744 | Link link3 = addLink(DEVICE1, 80, DEVICE3, 70, false, 100); |
| 745 | Link link4 = addLink(DEVICE3, 60, DEVICE4, 50, false, 80); |
| 746 | |
| 747 | CostConstraint tecostConst = CostConstraint.of(TE_COST); |
| 748 | |
| 749 | List<Constraint> constraints = new LinkedList<>(); |
| 750 | constraints.add(tecostConst); |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 751 | |
| 752 | |
| 753 | TeLinkConfig teLinkConfig = netConfigRegistry.addConfig(LinkKey.linkKey(link1), TeLinkConfig.class); |
| 754 | teLinkConfig.teCost(50) |
| 755 | .apply(); |
| 756 | |
| 757 | |
| 758 | TeLinkConfig teLinkConfig2 = netConfigRegistry.addConfig(LinkKey.linkKey(link2), TeLinkConfig.class); |
| 759 | teLinkConfig2.teCost(20) |
| 760 | .apply(); |
| 761 | |
| 762 | TeLinkConfig teLinkConfig3 = netConfigRegistry.addConfig(LinkKey.linkKey(link3), TeLinkConfig.class); |
| 763 | teLinkConfig3.teCost(100) |
| 764 | .apply(); |
| 765 | |
| 766 | TeLinkConfig teLinkConfig4 = netConfigRegistry.addConfig(LinkKey.linkKey(link4), TeLinkConfig.class); |
| 767 | teLinkConfig4.teCost(80) |
| 768 | .apply(); |
| 769 | |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 770 | Set<Path> paths = computePath(link1, link2, link3, link4, constraints); |
| 771 | |
| 772 | List<Link> links = new LinkedList<>(); |
| 773 | links.add(link1); |
| 774 | links.add(link2); |
| 775 | assertThat(paths.iterator().next().links(), is(links)); |
| 776 | assertThat(paths.iterator().next().cost(), is((double) 70)); |
| 777 | } |
| 778 | |
| 779 | /** |
| 780 | * With device supporting RSVP capability as a constraints. |
| 781 | */ |
| 782 | @Test |
| 783 | public void testpathComputationCase9() { |
| 784 | Link link1 = addLink(DEVICE1, 10, DEVICE2, 20, false, 50); |
| 785 | Link link2 = addLink(DEVICE2, 30, DEVICE4, 40, false, 20); |
| 786 | Link link3 = addLink(DEVICE1, 80, DEVICE3, 70, false, 100); |
| 787 | Link link4 = addLink(DEVICE3, 60, DEVICE4, 50, false, 80); |
| 788 | |
| 789 | CostConstraint tecostConst = CostConstraint.of(TE_COST); |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 790 | |
| 791 | TeLinkConfig teLinkConfig = netConfigRegistry.addConfig(LinkKey.linkKey(link1), TeLinkConfig.class); |
| 792 | teLinkConfig.teCost(50) |
| 793 | .apply(); |
| 794 | |
| 795 | |
| 796 | TeLinkConfig teLinkConfig2 = netConfigRegistry.addConfig(LinkKey.linkKey(link2), TeLinkConfig.class); |
| 797 | teLinkConfig2.teCost(20) |
| 798 | .apply(); |
| 799 | |
| 800 | TeLinkConfig teLinkConfig3 = netConfigRegistry.addConfig(LinkKey.linkKey(link3), TeLinkConfig.class); |
| 801 | teLinkConfig3.teCost(100) |
| 802 | .apply(); |
| 803 | |
| 804 | TeLinkConfig teLinkConfig4 = netConfigRegistry.addConfig(LinkKey.linkKey(link4), TeLinkConfig.class); |
| 805 | teLinkConfig4.teCost(80) |
| 806 | .apply(); |
| 807 | |
| 808 | |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 809 | CapabilityConstraint capabilityConst = CapabilityConstraint |
| 810 | .of(CapabilityConstraint.CapabilityType.WITH_SIGNALLING); |
| 811 | |
| 812 | List<Constraint> constraints = new LinkedList<>(); |
| 813 | constraints.add(capabilityConst); |
| 814 | constraints.add(tecostConst); |
| 815 | //Device1 |
| 816 | DefaultAnnotations.Builder builder = DefaultAnnotations.builder(); |
| 817 | builder.set(AnnotationKeys.TYPE, L3); |
| 818 | builder.set(LSRID, "1.1.1.1"); |
| 819 | addDevice(DEVICE1, builder); |
| 820 | |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 821 | DeviceCapability device1Cap = netConfigRegistry.addConfig(DeviceId.deviceId("1.1.1.1"), DeviceCapability.class); |
| 822 | device1Cap.setLabelStackCap(false) |
| 823 | .setLocalLabelCap(false) |
| 824 | .setSrCap(false) |
| 825 | .apply(); |
| 826 | |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 827 | //Device2 |
| 828 | builder = DefaultAnnotations.builder(); |
| 829 | builder.set(AnnotationKeys.TYPE, L3); |
| 830 | builder.set(LSRID, "2.2.2.2"); |
| 831 | addDevice(DEVICE2, builder); |
| 832 | |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 833 | DeviceCapability device2Cap = netConfigRegistry.addConfig(DeviceId.deviceId("2.2.2.2"), DeviceCapability.class); |
| 834 | device2Cap.setLabelStackCap(false) |
| 835 | .setLocalLabelCap(false) |
| 836 | .setSrCap(false) |
| 837 | .apply(); |
| 838 | |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 839 | //Device3 |
| 840 | builder = DefaultAnnotations.builder(); |
| 841 | builder.set(AnnotationKeys.TYPE, L3); |
| 842 | builder.set(LSRID, "3.3.3.3"); |
| 843 | addDevice(DEVICE3, builder); |
| 844 | |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 845 | DeviceCapability device3Cap = netConfigRegistry.addConfig(DeviceId.deviceId("3.3.3.3"), DeviceCapability.class); |
| 846 | device3Cap.setLabelStackCap(false) |
| 847 | .setLocalLabelCap(false) |
| 848 | .setSrCap(false) |
| 849 | .apply(); |
| 850 | |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 851 | //Device4 |
| 852 | builder = DefaultAnnotations.builder(); |
| 853 | builder.set(AnnotationKeys.TYPE, L3); |
| 854 | builder.set(LSRID, "4.4.4.4"); |
| 855 | addDevice(DEVICE4, builder); |
| 856 | |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 857 | DeviceCapability device4Cap = netConfigRegistry.addConfig(DeviceId.deviceId("4.4.4.4"), DeviceCapability.class); |
| 858 | device4Cap.setLabelStackCap(false) |
| 859 | .setLocalLabelCap(false) |
| 860 | .setSrCap(false) |
| 861 | .apply(); |
| 862 | |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 863 | Set<Path> paths = computePath(link1, link2, link3, link4, constraints); |
| 864 | |
| 865 | List<Link> links = new LinkedList<>(); |
| 866 | links.add(link1); |
| 867 | links.add(link2); |
| 868 | assertThat(paths.iterator().next().links(), is(links)); |
| 869 | assertThat(paths.iterator().next().cost(), is((double) 70)); |
| 870 | } |
| 871 | |
| 872 | /** |
| 873 | * Devices supporting CR capability. |
| 874 | */ |
| 875 | @Test |
| 876 | public void testpathComputationCase10() { |
| 877 | Link link1 = addLink(DEVICE1, 10, DEVICE2, 20, true, 50); |
| 878 | Link link2 = addLink(DEVICE2, 30, DEVICE4, 40, true, 20); |
| 879 | Link link3 = addLink(DEVICE1, 80, DEVICE3, 70, true, 100); |
| 880 | Link link4 = addLink(DEVICE3, 60, DEVICE4, 50, true, 80); |
| 881 | |
| 882 | CapabilityConstraint capabilityConst = CapabilityConstraint |
| 883 | .of(CapabilityConstraint.CapabilityType.WITHOUT_SIGNALLING_AND_WITHOUT_SR); |
| 884 | |
| 885 | List<Constraint> constraints = new LinkedList<>(); |
| 886 | constraints.add(capabilityConst); |
| 887 | CostConstraint costConst = CostConstraint.of(COST); |
| 888 | constraints.add(costConst); |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 889 | TeLinkConfig teLinkConfig = netConfigRegistry.addConfig(LinkKey.linkKey(link1), TeLinkConfig.class); |
| 890 | teLinkConfig.igpCost(50) |
| 891 | .apply(); |
| 892 | |
| 893 | |
| 894 | TeLinkConfig teLinkConfig2 = netConfigRegistry.addConfig(LinkKey.linkKey(link2), TeLinkConfig.class); |
| 895 | teLinkConfig2.igpCost(20) |
| 896 | .apply(); |
| 897 | |
| 898 | TeLinkConfig teLinkConfig3 = netConfigRegistry.addConfig(LinkKey.linkKey(link3), TeLinkConfig.class); |
| 899 | teLinkConfig3.igpCost(100) |
| 900 | .apply(); |
| 901 | |
| 902 | TeLinkConfig teLinkConfig4 = netConfigRegistry.addConfig(LinkKey.linkKey(link4), TeLinkConfig.class); |
| 903 | teLinkConfig4.igpCost(80) |
| 904 | .apply(); |
| 905 | |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 906 | //Device1 |
| 907 | DefaultAnnotations.Builder builder = DefaultAnnotations.builder(); |
| 908 | builder.set(AnnotationKeys.TYPE, L3); |
| 909 | builder.set(LSRID, "1.1.1.1"); |
| 910 | addDevice(DEVICE1, builder); |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 911 | DeviceCapability device1Cap = netConfigRegistry.addConfig(DeviceId.deviceId("1.1.1.1"), DeviceCapability.class); |
| 912 | device1Cap.setLabelStackCap(false) |
| 913 | .setLocalLabelCap(true) |
| 914 | .setSrCap(false) |
| 915 | .apply(); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 916 | |
| 917 | //Device2 |
| 918 | builder = DefaultAnnotations.builder(); |
| 919 | builder.set(AnnotationKeys.TYPE, L3); |
| 920 | builder.set(LSRID, "2.2.2.2"); |
| 921 | addDevice(DEVICE2, builder); |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 922 | DeviceCapability device2Cap = netConfigRegistry.addConfig(DeviceId.deviceId("2.2.2.2"), DeviceCapability.class); |
| 923 | device2Cap.setLabelStackCap(false) |
| 924 | .setLocalLabelCap(true) |
| 925 | .setSrCap(false) |
| 926 | .apply(); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 927 | |
| 928 | //Device3 |
| 929 | builder = DefaultAnnotations.builder(); |
| 930 | builder.set(AnnotationKeys.TYPE, L3); |
| 931 | builder.set(LSRID, "3.3.3.3"); |
| 932 | addDevice(DEVICE3, builder); |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 933 | DeviceCapability device3Cap = netConfigRegistry.addConfig(DeviceId.deviceId("3.3.3.3"), DeviceCapability.class); |
| 934 | device3Cap.setLabelStackCap(false) |
| 935 | .setLocalLabelCap(true) |
| 936 | .setSrCap(false) |
| 937 | .apply(); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 938 | |
| 939 | //Device4 |
| 940 | builder = DefaultAnnotations.builder(); |
| 941 | builder.set(AnnotationKeys.TYPE, L3); |
| 942 | builder.set(LSRID, "4.4.4.4"); |
| 943 | addDevice(DEVICE4, builder); |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 944 | DeviceCapability device4Cap = netConfigRegistry.addConfig(DeviceId.deviceId("4.4.4.4"), DeviceCapability.class); |
| 945 | device4Cap.setLabelStackCap(false) |
| 946 | .setLocalLabelCap(true) |
| 947 | .setSrCap(false) |
| 948 | .apply(); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 949 | |
| 950 | Set<Path> paths = computePath(link1, link2, link3, link4, constraints); |
| 951 | |
| 952 | List<Link> links = new LinkedList<>(); |
| 953 | links.add(link1); |
| 954 | links.add(link2); |
| 955 | assertThat(paths.iterator().next().links(), is(links)); |
| 956 | assertThat(paths.iterator().next().cost(), is((double) 70)); |
| 957 | } |
| 958 | |
| 959 | /** |
| 960 | * Device supporting SR capability. |
| 961 | */ |
| 962 | @Test |
| 963 | public void testpathComputationCase11() { |
| 964 | Link link1 = addLink(DEVICE1, 10, DEVICE2, 20, true, 50); |
| 965 | Link link2 = addLink(DEVICE2, 30, DEVICE4, 40, true, 20); |
| 966 | Link link3 = addLink(DEVICE1, 80, DEVICE3, 70, true, 100); |
| 967 | Link link4 = addLink(DEVICE3, 60, DEVICE4, 50, true, 80); |
| 968 | |
| 969 | CapabilityConstraint capabilityConst = CapabilityConstraint |
| 970 | .of(CapabilityConstraint.CapabilityType.SR_WITHOUT_SIGNALLING); |
| 971 | |
| 972 | List<Constraint> constraints = new LinkedList<>(); |
| 973 | constraints.add(capabilityConst); |
| 974 | CostConstraint costConst = CostConstraint.of(COST); |
| 975 | constraints.add(costConst); |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 976 | |
| 977 | TeLinkConfig teLinkConfig = netConfigRegistry.addConfig(LinkKey.linkKey(link1), TeLinkConfig.class); |
| 978 | teLinkConfig.igpCost(50) |
| 979 | .apply(); |
| 980 | |
| 981 | |
| 982 | TeLinkConfig teLinkConfig2 = netConfigRegistry.addConfig(LinkKey.linkKey(link2), TeLinkConfig.class); |
| 983 | teLinkConfig2.igpCost(20) |
| 984 | .apply(); |
| 985 | |
| 986 | TeLinkConfig teLinkConfig3 = netConfigRegistry.addConfig(LinkKey.linkKey(link3), TeLinkConfig.class); |
| 987 | teLinkConfig3.igpCost(100) |
| 988 | .apply(); |
| 989 | |
| 990 | TeLinkConfig teLinkConfig4 = netConfigRegistry.addConfig(LinkKey.linkKey(link4), TeLinkConfig.class); |
| 991 | teLinkConfig4.igpCost(80) |
| 992 | .apply(); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 993 | //Device1 |
| 994 | DefaultAnnotations.Builder builder = DefaultAnnotations.builder(); |
| 995 | builder.set(AnnotationKeys.TYPE, L3); |
| 996 | builder.set(LSRID, "1.1.1.1"); |
| 997 | addDevice(DEVICE1, builder); |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 998 | DeviceCapability device1Cap = netConfigRegistry.addConfig(DeviceId.deviceId("1.1.1.1"), DeviceCapability.class); |
| 999 | device1Cap.setLabelStackCap(true) |
| 1000 | .setLocalLabelCap(false) |
| 1001 | .setSrCap(true) |
| 1002 | .apply(); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 1003 | |
| 1004 | //Device2 |
| 1005 | builder = DefaultAnnotations.builder(); |
| 1006 | builder.set(AnnotationKeys.TYPE, L3); |
| 1007 | builder.set(LSRID, "2.2.2.2"); |
| 1008 | addDevice(DEVICE2, builder); |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 1009 | DeviceCapability device2Cap = netConfigRegistry.addConfig(DeviceId.deviceId("2.2.2.2"), DeviceCapability.class); |
| 1010 | device2Cap.setLabelStackCap(true) |
| 1011 | .setLocalLabelCap(false) |
| 1012 | .setSrCap(true) |
| 1013 | .apply(); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 1014 | |
| 1015 | //Device3 |
| 1016 | builder = DefaultAnnotations.builder(); |
| 1017 | builder.set(AnnotationKeys.TYPE, L3); |
| 1018 | builder.set(LSRID, "3.3.3.3"); |
| 1019 | addDevice(DEVICE3, builder); |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 1020 | DeviceCapability device3Cap = netConfigRegistry.addConfig(DeviceId.deviceId("3.3.3.3"), DeviceCapability.class); |
| 1021 | device3Cap.setLabelStackCap(true) |
| 1022 | .setLocalLabelCap(false) |
| 1023 | .setSrCap(true) |
| 1024 | .apply(); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 1025 | |
| 1026 | //Device4 |
| 1027 | builder = DefaultAnnotations.builder(); |
| 1028 | builder.set(AnnotationKeys.TYPE, L3); |
| 1029 | builder.set(LSRID, "4.4.4.4"); |
| 1030 | addDevice(DEVICE4, builder); |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 1031 | DeviceCapability device4Cap = netConfigRegistry.addConfig(DeviceId.deviceId("4.4.4.4"), DeviceCapability.class); |
| 1032 | device4Cap.setLabelStackCap(true) |
| 1033 | .setLocalLabelCap(false) |
| 1034 | .setSrCap(true) |
| 1035 | .apply(); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 1036 | Set<Path> paths = computePath(link1, link2, link3, link4, constraints); |
| 1037 | |
| 1038 | List<Link> links = new LinkedList<>(); |
| 1039 | links.add(link1); |
| 1040 | links.add(link2); |
| 1041 | assertThat(paths.iterator().next().links(), is(links)); |
| 1042 | assertThat(paths.iterator().next().cost(), is((double) 70)); |
| 1043 | } |
| 1044 | |
| 1045 | /** |
| 1046 | * Path with TE and SR capability constraint. |
| 1047 | */ |
| 1048 | @Test |
| 1049 | public void testpathComputationCase12() { |
| 1050 | Link link1 = addLink(DEVICE1, 10, DEVICE2, 20, false, 50); |
| 1051 | Link link2 = addLink(DEVICE2, 30, DEVICE4, 40, false, 20); |
| 1052 | Link link3 = addLink(DEVICE1, 80, DEVICE3, 70, false, 100); |
| 1053 | Link link4 = addLink(DEVICE3, 60, DEVICE4, 50, false, 80); |
| 1054 | |
| 1055 | CostConstraint tecostConst = CostConstraint.of(TE_COST); |
| 1056 | CapabilityConstraint capabilityConst = CapabilityConstraint |
| 1057 | .of(CapabilityConstraint.CapabilityType.SR_WITHOUT_SIGNALLING); |
| 1058 | |
| 1059 | List<Constraint> constraints = new LinkedList<>(); |
| 1060 | |
| 1061 | constraints.add(capabilityConst); |
| 1062 | constraints.add(tecostConst); |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1063 | |
| 1064 | TeLinkConfig teLinkConfig = netConfigRegistry.addConfig(LinkKey.linkKey(link1), TeLinkConfig.class); |
| 1065 | teLinkConfig.teCost(50) |
| 1066 | .apply(); |
| 1067 | |
| 1068 | |
| 1069 | TeLinkConfig teLinkConfig2 = netConfigRegistry.addConfig(LinkKey.linkKey(link2), TeLinkConfig.class); |
| 1070 | teLinkConfig2.teCost(20) |
| 1071 | .apply(); |
| 1072 | |
| 1073 | TeLinkConfig teLinkConfig3 = netConfigRegistry.addConfig(LinkKey.linkKey(link3), TeLinkConfig.class); |
| 1074 | teLinkConfig3.teCost(100) |
| 1075 | .apply(); |
| 1076 | |
| 1077 | TeLinkConfig teLinkConfig4 = netConfigRegistry.addConfig(LinkKey.linkKey(link4), TeLinkConfig.class); |
| 1078 | teLinkConfig4.teCost(80) |
| 1079 | .apply(); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 1080 | //Device1 |
| 1081 | DefaultAnnotations.Builder builder = DefaultAnnotations.builder(); |
| 1082 | builder.set(AnnotationKeys.TYPE, L3); |
| 1083 | builder.set(LSRID, "1.1.1.1"); |
| 1084 | addDevice(DEVICE1, builder); |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 1085 | DeviceCapability device1Cap = netConfigRegistry.addConfig(DeviceId.deviceId("1.1.1.1"), DeviceCapability.class); |
| 1086 | device1Cap.setLabelStackCap(true) |
| 1087 | .setLocalLabelCap(false) |
| 1088 | .setSrCap(true) |
| 1089 | .apply(); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 1090 | |
| 1091 | //Device2 |
| 1092 | builder = DefaultAnnotations.builder(); |
| 1093 | builder.set(AnnotationKeys.TYPE, L3); |
| 1094 | builder.set(LSRID, "2.2.2.2"); |
| 1095 | addDevice(DEVICE2, builder); |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 1096 | DeviceCapability device2Cap = netConfigRegistry.addConfig(DeviceId.deviceId("2.2.2.2"), DeviceCapability.class); |
| 1097 | device2Cap.setLabelStackCap(true) |
| 1098 | .setLocalLabelCap(false) |
| 1099 | .setSrCap(true) |
| 1100 | .apply(); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 1101 | |
| 1102 | //Device3 |
| 1103 | builder = DefaultAnnotations.builder(); |
| 1104 | builder.set(AnnotationKeys.TYPE, L3); |
| 1105 | builder.set(LSRID, "3.3.3.3"); |
| 1106 | addDevice(DEVICE3, builder); |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 1107 | DeviceCapability device3Cap = netConfigRegistry.addConfig(DeviceId.deviceId("3.3.3.3"), DeviceCapability.class); |
| 1108 | device3Cap.setLabelStackCap(true) |
| 1109 | .setLocalLabelCap(false) |
| 1110 | .setSrCap(true) |
| 1111 | .apply(); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 1112 | |
| 1113 | //Device4 |
| 1114 | builder = DefaultAnnotations.builder(); |
| 1115 | builder.set(AnnotationKeys.TYPE, L3); |
| 1116 | builder.set(LSRID, "4.4.4.4"); |
| 1117 | addDevice(DEVICE4, builder); |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 1118 | DeviceCapability device4Cap = netConfigRegistry.addConfig(DeviceId.deviceId("4.4.4.4"), DeviceCapability.class); |
| 1119 | device4Cap.setLabelStackCap(true) |
| 1120 | .setLocalLabelCap(false) |
| 1121 | .setSrCap(true) |
| 1122 | .apply(); |
| 1123 | |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 1124 | Set<Path> paths = computePath(link1, link2, link3, link4, constraints); |
| 1125 | |
| 1126 | List<Link> links = new LinkedList<>(); |
| 1127 | links.add(link1); |
| 1128 | links.add(link2); |
| 1129 | assertThat(paths.iterator().next().links(), is(links)); |
| 1130 | assertThat(paths.iterator().next().cost(), is((double) 70)); |
| 1131 | } |
| 1132 | |
| 1133 | /** |
| 1134 | * Path with capability constraint and with default cost. |
| 1135 | */ |
| 1136 | @Test |
| 1137 | public void testpathComputationCase13() { |
| 1138 | Link link1 = addLink(DEVICE1, 10, DEVICE2, 20, false, 50); |
| 1139 | Link link2 = addLink(DEVICE2, 30, DEVICE4, 40, false, 20); |
| 1140 | Link link3 = addLink(DEVICE1, 80, DEVICE3, 70, false, 100); |
| 1141 | Link link4 = addLink(DEVICE3, 60, DEVICE4, 50, false, 80); |
| 1142 | |
| 1143 | CapabilityConstraint capabilityConst = CapabilityConstraint |
| 1144 | .of(CapabilityConstraint.CapabilityType.SR_WITHOUT_SIGNALLING); |
| 1145 | |
| 1146 | List<Constraint> constraints = new LinkedList<>(); |
| 1147 | constraints.add(capabilityConst); |
| 1148 | //Device1 |
| 1149 | DefaultAnnotations.Builder builder = DefaultAnnotations.builder(); |
| 1150 | builder.set(AnnotationKeys.TYPE, L3); |
| 1151 | builder.set(LSRID, "1.1.1.1"); |
| 1152 | addDevice(DEVICE1, builder); |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 1153 | DeviceCapability device1Cap = netConfigRegistry.addConfig(DeviceId.deviceId("1.1.1.1"), DeviceCapability.class); |
| 1154 | device1Cap.setLabelStackCap(true) |
| 1155 | .setLocalLabelCap(false) |
| 1156 | .setSrCap(true) |
| 1157 | .apply(); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 1158 | |
| 1159 | //Device2 |
| 1160 | builder = DefaultAnnotations.builder(); |
| 1161 | builder.set(AnnotationKeys.TYPE, L3); |
| 1162 | builder.set(LSRID, "2.2.2.2"); |
| 1163 | addDevice(DEVICE2, builder); |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 1164 | DeviceCapability device2Cap = netConfigRegistry.addConfig(DeviceId.deviceId("2.2.2.2"), DeviceCapability.class); |
| 1165 | device2Cap.setLabelStackCap(true) |
| 1166 | .setLocalLabelCap(false) |
| 1167 | .setSrCap(true) |
| 1168 | .apply(); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 1169 | |
| 1170 | //Device3 |
| 1171 | builder = DefaultAnnotations.builder(); |
| 1172 | builder.set(AnnotationKeys.TYPE, L3); |
| 1173 | builder.set(LSRID, "3.3.3.3"); |
| 1174 | addDevice(DEVICE3, builder); |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 1175 | DeviceCapability device3Cap = netConfigRegistry.addConfig(DeviceId.deviceId("3.3.3.3"), DeviceCapability.class); |
| 1176 | device3Cap.setLabelStackCap(true) |
| 1177 | .setLocalLabelCap(false) |
| 1178 | .setSrCap(true) |
| 1179 | .apply(); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 1180 | |
| 1181 | //Device4 |
| 1182 | builder = DefaultAnnotations.builder(); |
| 1183 | builder.set(AnnotationKeys.TYPE, L3); |
| 1184 | builder.set(LSRID, "4.4.4.4"); |
| 1185 | addDevice(DEVICE4, builder); |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 1186 | DeviceCapability device4Cap = netConfigRegistry.addConfig(DeviceId.deviceId("4.4.4.4"), DeviceCapability.class); |
| 1187 | device4Cap.setLabelStackCap(true) |
| 1188 | .setLocalLabelCap(false) |
| 1189 | .setSrCap(true) |
| 1190 | .apply(); |
| 1191 | |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 1192 | Set<Path> paths = computePath(link1, link2, link3, link4, constraints); |
| 1193 | |
| 1194 | List<Link> links = new LinkedList<>(); |
| 1195 | links.add(link1); |
| 1196 | links.add(link2); |
| 1197 | assertThat(paths.iterator().next().cost(), is((double) 2)); |
| 1198 | } |
| 1199 | |
| 1200 | /** |
| 1201 | * Test case with empty constraints. |
| 1202 | */ |
| 1203 | @Test |
| 1204 | public void testpathComputationCase14() { |
| 1205 | Link link1 = addLink(DEVICE1, 10, DEVICE2, 20, false, 50); |
| 1206 | Link link2 = addLink(DEVICE2, 30, DEVICE4, 40, false, 20); |
| 1207 | Link link3 = addLink(DEVICE1, 80, DEVICE3, 70, false, 100); |
| 1208 | Link link4 = addLink(DEVICE3, 60, DEVICE4, 50, false, 80); |
| 1209 | |
| 1210 | List<Constraint> constraints = new LinkedList<>(); |
| 1211 | Set<Path> paths = computePath(link1, link2, link3, link4, constraints); |
| 1212 | |
| 1213 | assertThat(paths.iterator().next().cost(), is((double) 2)); |
| 1214 | } |
| 1215 | |
| 1216 | /** |
| 1217 | * Test case with constraints as null. |
| 1218 | */ |
| 1219 | @Test |
| 1220 | public void testpathComputationCase15() { |
| 1221 | Link link1 = addLink(DEVICE1, 10, DEVICE2, 20, false, 50); |
| 1222 | Link link2 = addLink(DEVICE2, 30, DEVICE4, 40, false, 20); |
| 1223 | Link link3 = addLink(DEVICE1, 80, DEVICE3, 70, false, 100); |
| 1224 | Link link4 = addLink(DEVICE3, 60, DEVICE4, 50, false, 80); |
| 1225 | |
| 1226 | List<Constraint> constraints = null; |
| 1227 | Set<Path> paths = computePath(link1, link2, link3, link4, constraints); |
| 1228 | |
| 1229 | assertThat(paths.iterator().next().cost(), is((double) 2)); |
| 1230 | } |
| 1231 | |
| 1232 | /** |
| 1233 | * Path with cost constraint. |
| 1234 | */ |
| 1235 | @Test |
| 1236 | public void testpathComputationCase16() { |
| 1237 | Link link1 = addLink(DEVICE1, 10, DEVICE2, 20, true, 50); |
| 1238 | Link link2 = addLink(DEVICE2, 30, DEVICE4, 40, true, 100); |
| 1239 | Link link3 = addLink(DEVICE1, 80, DEVICE3, 70, true, 10); |
| 1240 | Link link4 = addLink(DEVICE3, 60, DEVICE4, 50, true, 10); |
| 1241 | Link link5 = addLink(DEVICE4, 90, DEVICE5, 100, true, 20); |
| 1242 | |
| 1243 | CostConstraint costConst = CostConstraint.of(COST); |
| 1244 | |
| 1245 | List<Constraint> constraints = new LinkedList<>(); |
| 1246 | constraints.add(costConst); |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1247 | |
| 1248 | TeLinkConfig teLinkConfig = netConfigRegistry.addConfig(LinkKey.linkKey(link1), TeLinkConfig.class); |
| 1249 | teLinkConfig.igpCost(50) |
| 1250 | .apply(); |
| 1251 | |
| 1252 | |
| 1253 | TeLinkConfig teLinkConfig2 = netConfigRegistry.addConfig(LinkKey.linkKey(link2), TeLinkConfig.class); |
| 1254 | teLinkConfig2.igpCost(100) |
| 1255 | .apply(); |
| 1256 | |
| 1257 | TeLinkConfig teLinkConfig3 = netConfigRegistry.addConfig(LinkKey.linkKey(link3), TeLinkConfig.class); |
| 1258 | teLinkConfig3.igpCost(10) |
| 1259 | .apply(); |
| 1260 | |
| 1261 | TeLinkConfig teLinkConfig4 = netConfigRegistry.addConfig(LinkKey.linkKey(link4), TeLinkConfig.class); |
| 1262 | teLinkConfig4.igpCost(10) |
| 1263 | .apply(); |
| 1264 | |
| 1265 | TeLinkConfig teLinkConfig5 = netConfigRegistry.addConfig(LinkKey.linkKey(link5), TeLinkConfig.class); |
| 1266 | teLinkConfig5.igpCost(20) |
| 1267 | .apply(); |
| 1268 | |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 1269 | Graph<TopologyVertex, TopologyEdge> graph = new AdjacencyListsGraph<>(of(D1, D2, D3, D4, D5), |
| 1270 | of(new DefaultTopologyEdge(D1, D2, link1), |
| 1271 | new DefaultTopologyEdge(D2, D4, link2), |
| 1272 | new DefaultTopologyEdge(D1, D3, link3), |
| 1273 | new DefaultTopologyEdge(D3, D4, link4), |
| 1274 | new DefaultTopologyEdge(D4, D5, link5))); |
| 1275 | |
| 1276 | GraphPathSearch.Result<TopologyVertex, TopologyEdge> result = |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1277 | graphSearch().search(graph, D1, D5, adapt(weight(constraints)), ALL_PATHS); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 1278 | ImmutableSet.Builder<Path> builder = ImmutableSet.builder(); |
| 1279 | for (org.onlab.graph.Path<TopologyVertex, TopologyEdge> path : result.paths()) { |
| 1280 | builder.add(networkPath(path)); |
| 1281 | } |
| 1282 | |
| 1283 | List<Link> links = new LinkedList<>(); |
| 1284 | links.add(link3); |
| 1285 | links.add(link4); |
| 1286 | links.add(link5); |
| 1287 | assertThat(builder.build().iterator().next().links(), is(links)); |
| 1288 | assertThat(builder.build().iterator().next().cost(), is((double) 40)); |
| 1289 | } |
| 1290 | |
| 1291 | /** |
| 1292 | * D3 doesn't support capability constraint, so path is L1-L2. |
| 1293 | */ |
| 1294 | @Test |
| 1295 | public void testpathComputationCase17() { |
| 1296 | Link link1 = addLink(DEVICE1, 10, DEVICE2, 20, false, 50); |
| 1297 | Link link2 = addLink(DEVICE2, 30, DEVICE4, 40, false, 20); |
| 1298 | Link link3 = addLink(DEVICE1, 80, DEVICE3, 70, false, 100); |
| 1299 | Link link4 = addLink(DEVICE3, 60, DEVICE4, 50, false, 80); |
| 1300 | |
| 1301 | CapabilityConstraint capabilityConst = CapabilityConstraint |
| 1302 | .of(CapabilityConstraint.CapabilityType.WITHOUT_SIGNALLING_AND_WITHOUT_SR); |
| 1303 | |
| 1304 | List<Constraint> constraints = new LinkedList<>(); |
| 1305 | constraints.add(capabilityConst); |
| 1306 | //Device1 |
| 1307 | DefaultAnnotations.Builder builder = DefaultAnnotations.builder(); |
| 1308 | builder.set(AnnotationKeys.TYPE, L3); |
| 1309 | builder.set(LSRID, "1.1.1.1"); |
| 1310 | addDevice(DEVICE1, builder); |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 1311 | DeviceCapability device1Cap = netConfigRegistry.addConfig(DeviceId.deviceId("1.1.1.1"), DeviceCapability.class); |
| 1312 | device1Cap.setLabelStackCap(false) |
| 1313 | .setLocalLabelCap(true) |
| 1314 | .setSrCap(false) |
| 1315 | .apply(); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 1316 | |
| 1317 | //Device2 |
| 1318 | builder = DefaultAnnotations.builder(); |
| 1319 | builder.set(AnnotationKeys.TYPE, L3); |
| 1320 | builder.set(LSRID, "2.2.2.2"); |
| 1321 | addDevice(DEVICE2, builder); |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 1322 | DeviceCapability device2Cap = netConfigRegistry.addConfig(DeviceId.deviceId("2.2.2.2"), DeviceCapability.class); |
| 1323 | device2Cap.setLabelStackCap(false) |
| 1324 | .setLocalLabelCap(true) |
| 1325 | .setSrCap(false) |
| 1326 | .apply(); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 1327 | |
| 1328 | //Device4 |
| 1329 | builder = DefaultAnnotations.builder(); |
| 1330 | builder.set(AnnotationKeys.TYPE, L3); |
| 1331 | builder.set(LSRID, "4.4.4.4"); |
| 1332 | addDevice(DEVICE4, builder); |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 1333 | DeviceCapability device4Cap = netConfigRegistry.addConfig(DeviceId.deviceId("4.4.4.4"), DeviceCapability.class); |
| 1334 | device4Cap.setLabelStackCap(false) |
| 1335 | .setLocalLabelCap(true) |
| 1336 | .setSrCap(false) |
| 1337 | .apply(); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 1338 | Set<Path> paths = computePath(link1, link2, link3, link4, constraints); |
| 1339 | |
| 1340 | List<Link> links = new LinkedList<>(); |
| 1341 | links.add(link1); |
| 1342 | links.add(link2); |
| 1343 | |
| 1344 | assertThat(paths.iterator().next().links(), is(links)); |
| 1345 | assertThat(paths.iterator().next().cost(), is((double) 2)); |
| 1346 | } |
| 1347 | |
| 1348 | /** |
| 1349 | * L2 doesn't support cost constraint and D3 doesn't support capability constraint, both constraint fails hence no |
| 1350 | * path. |
| 1351 | */ |
| 1352 | @Test |
| 1353 | public void testpathComputationCase18() { |
| 1354 | Link link1 = addLink(DEVICE1, 10, DEVICE2, 20, true, 50); |
| 1355 | Link link2 = addLink(DEVICE2, 30, DEVICE4, 40, false, 20); |
| 1356 | Link link3 = addLink(DEVICE1, 80, DEVICE3, 70, true, 10); |
| 1357 | Link link4 = addLink(DEVICE3, 60, DEVICE4, 50, true, 10); |
| 1358 | |
| 1359 | CapabilityConstraint capabilityConst = CapabilityConstraint |
| 1360 | .of(CapabilityConstraint.CapabilityType.WITHOUT_SIGNALLING_AND_WITHOUT_SR); |
| 1361 | CostConstraint costConst = CostConstraint.of(COST); |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1362 | |
| 1363 | TeLinkConfig teLinkConfig = netConfigRegistry.addConfig(LinkKey.linkKey(link1), TeLinkConfig.class); |
| 1364 | teLinkConfig.igpCost(50) |
| 1365 | .apply(); |
| 1366 | |
| 1367 | |
| 1368 | TeLinkConfig teLinkConfig2 = netConfigRegistry.addConfig(LinkKey.linkKey(link2), TeLinkConfig.class); |
| 1369 | teLinkConfig2.igpCost(20) |
| 1370 | .apply(); |
| 1371 | |
| 1372 | TeLinkConfig teLinkConfig3 = netConfigRegistry.addConfig(LinkKey.linkKey(link3), TeLinkConfig.class); |
| 1373 | teLinkConfig3.igpCost(10) |
| 1374 | .apply(); |
| 1375 | |
| 1376 | TeLinkConfig teLinkConfig4 = netConfigRegistry.addConfig(LinkKey.linkKey(link4), TeLinkConfig.class); |
| 1377 | teLinkConfig4.igpCost(10) |
| 1378 | .apply(); |
| 1379 | |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 1380 | List<Constraint> constraints = new LinkedList<>(); |
| 1381 | constraints.add(capabilityConst); |
| 1382 | constraints.add(costConst); |
| 1383 | //Device1 |
| 1384 | DefaultAnnotations.Builder builder = DefaultAnnotations.builder(); |
| 1385 | builder.set(AnnotationKeys.TYPE, L3); |
| 1386 | builder.set(LSRID, "1.1.1.1"); |
| 1387 | addDevice(DEVICE2, builder); |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 1388 | DeviceCapability device1Cap = netConfigRegistry.addConfig(DeviceId.deviceId("1.1.1.1"), DeviceCapability.class); |
| 1389 | device1Cap.setLabelStackCap(false) |
| 1390 | .setLocalLabelCap(true) |
| 1391 | .setSrCap(false) |
| 1392 | .apply(); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 1393 | |
| 1394 | //Device2 |
| 1395 | builder = DefaultAnnotations.builder(); |
| 1396 | builder.set(AnnotationKeys.TYPE, L3); |
| 1397 | builder.set(LSRID, "2.2.2.2"); |
| 1398 | addDevice(DEVICE2, builder); |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 1399 | DeviceCapability device2Cap = netConfigRegistry.addConfig(DeviceId.deviceId("2.2.2.2"), DeviceCapability.class); |
| 1400 | device2Cap.setLabelStackCap(false) |
| 1401 | .setLocalLabelCap(true) |
| 1402 | .setSrCap(false) |
| 1403 | .apply(); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 1404 | |
| 1405 | //Device4 |
| 1406 | builder = DefaultAnnotations.builder(); |
| 1407 | builder.set(AnnotationKeys.TYPE, L3); |
| 1408 | builder.set(LSRID, "4.4.4.4"); |
| 1409 | addDevice(DEVICE4, builder); |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 1410 | DeviceCapability device4Cap = netConfigRegistry.addConfig(DeviceId.deviceId("4.4.4.4"), DeviceCapability.class); |
| 1411 | device4Cap.setLabelStackCap(false) |
| 1412 | .setLocalLabelCap(true) |
| 1413 | .setSrCap(false) |
| 1414 | .apply(); |
Priyanka B | b696358 | 2016-05-20 20:21:20 +0530 | [diff] [blame] | 1415 | Set<Path> paths = computePath(link1, link2, link3, link4, constraints); |
| 1416 | |
| 1417 | assertThat(paths, is(new HashSet<>())); |
| 1418 | } |
| 1419 | |
| 1420 | private void addDevice(String device, DefaultAnnotations.Builder builder) { |
| 1421 | deviceService.addDevice(new DefaultDevice(ProviderId.NONE, deviceId(device), Type.ROUTER, |
| 1422 | UNKNOWN, UNKNOWN, UNKNOWN, |
| 1423 | UNKNOWN, new ChassisId(), builder.build())); |
| 1424 | } |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1425 | } |