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