Ray Milkey | 8526700 | 2016-11-16 11:06:35 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Ray Milkey | 8526700 | 2016-11-16 11:06:35 -0800 | [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 | */ |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 16 | package org.onosproject.pce.pceservice; |
| 17 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 18 | import com.google.common.collect.ImmutableSet; |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 19 | import com.google.common.collect.Lists; |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 20 | import org.junit.After; |
| 21 | import org.junit.Before; |
| 22 | import org.junit.Test; |
| 23 | import org.onlab.graph.GraphPathSearch; |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 24 | import org.onlab.junit.TestUtils; |
| 25 | import org.onlab.junit.TestUtils.TestUtilsException; |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 26 | import org.onlab.util.Bandwidth; |
| 27 | import org.onosproject.common.DefaultTopologyGraph; |
| 28 | import org.onosproject.core.ApplicationId; |
| 29 | import org.onosproject.core.CoreServiceAdapter; |
| 30 | import org.onosproject.core.DefaultApplicationId; |
| 31 | import org.onosproject.core.IdGenerator; |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 32 | import org.onosproject.event.Event; |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 33 | import org.onosproject.incubator.net.tunnel.DefaultTunnel; |
| 34 | import org.onosproject.incubator.net.tunnel.Tunnel; |
| 35 | import org.onosproject.incubator.net.tunnel.Tunnel.State; |
| 36 | import org.onosproject.incubator.net.tunnel.TunnelEndPoint; |
| 37 | import org.onosproject.incubator.net.tunnel.TunnelEvent; |
| 38 | import org.onosproject.incubator.net.tunnel.TunnelId; |
| 39 | import org.onosproject.incubator.net.tunnel.TunnelListener; |
Ray Milkey | d1c34da | 2018-06-22 18:10:53 -0700 | [diff] [blame] | 40 | import org.onosproject.incubator.net.tunnel.TunnelServiceAdapter; |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 41 | import org.onosproject.mastership.MastershipServiceAdapter; |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 42 | import org.onosproject.net.AnnotationKeys; |
| 43 | import org.onosproject.net.Annotations; |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 44 | import org.onosproject.net.DefaultAnnotations; |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 45 | import org.onosproject.net.DefaultAnnotations.Builder; |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 46 | import org.onosproject.net.DefaultDevice; |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 47 | import org.onosproject.net.Device; |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 48 | import org.onosproject.net.DeviceId; |
| 49 | import org.onosproject.net.ElementId; |
| 50 | import org.onosproject.net.Link; |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 51 | import org.onosproject.net.LinkKey; |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 52 | import org.onosproject.net.MastershipRole; |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 53 | import org.onosproject.net.Path; |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 54 | import org.onosproject.net.SparseAnnotations; |
| 55 | import org.onosproject.net.intent.Constraint; |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 56 | import org.onosproject.net.link.LinkEvent; |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 57 | import org.onosproject.net.provider.ProviderId; |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 58 | import org.onosproject.net.topology.DefaultTopologyEdge; |
| 59 | import org.onosproject.net.topology.DefaultTopologyVertex; |
Ray Milkey | 7483e1b | 2018-02-07 15:43:01 -0800 | [diff] [blame] | 60 | import org.onosproject.net.topology.LinkWeigher; |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 61 | import org.onosproject.net.topology.PathServiceAdapter; |
| 62 | import org.onosproject.net.topology.Topology; |
| 63 | import org.onosproject.net.topology.TopologyEdge; |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 64 | import org.onosproject.net.topology.TopologyEvent; |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 65 | import org.onosproject.net.topology.TopologyGraph; |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 66 | import org.onosproject.net.topology.TopologyListener; |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 67 | import org.onosproject.net.topology.TopologyServiceAdapter; |
| 68 | import org.onosproject.net.topology.TopologyVertex; |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 69 | import org.onosproject.pce.pceservice.PathComputationTest.MockNetConfigRegistryAdapter; |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 70 | import org.onosproject.pce.pceservice.constraint.CostConstraint; |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 71 | import org.onosproject.pce.pceservice.constraint.PceBandwidthConstraint; |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 72 | import org.onosproject.pce.pcestore.api.PceStore; |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 73 | import org.onosproject.pce.util.MockDeviceService; |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 74 | import org.onosproject.pce.util.PceStoreAdapter; |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 75 | import org.onosproject.pcep.api.DeviceCapability; |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 76 | import org.onosproject.pcep.api.TeLinkConfig; |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 77 | import org.onosproject.store.service.TestStorageService; |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 78 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 79 | import java.util.Collection; |
| 80 | import java.util.Collections; |
| 81 | import java.util.HashMap; |
| 82 | import java.util.HashSet; |
| 83 | import java.util.LinkedList; |
| 84 | import java.util.List; |
| 85 | import java.util.Set; |
| 86 | import java.util.concurrent.atomic.AtomicLong; |
| 87 | import java.util.function.Consumer; |
| 88 | |
| 89 | import static org.hamcrest.MatcherAssert.assertThat; |
| 90 | import static org.hamcrest.core.Is.is; |
| 91 | import static org.onlab.graph.GraphPathSearch.ALL_PATHS; |
| 92 | import static org.onosproject.incubator.net.tunnel.Tunnel.State.ESTABLISHED; |
| 93 | import static org.onosproject.incubator.net.tunnel.Tunnel.State.UNSTABLE; |
| 94 | import static org.onosproject.net.MastershipRole.MASTER; |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 95 | import static org.onosproject.pce.pceservice.LspType.SR_WITHOUT_SIGNALLING; |
| 96 | import static org.onosproject.pce.pceservice.LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR; |
| 97 | import static org.onosproject.pce.pceservice.LspType.WITH_SIGNALLING; |
| 98 | import static org.onosproject.pce.pceservice.PathComputationTest.D1; |
| 99 | import static org.onosproject.pce.pceservice.PathComputationTest.D2; |
| 100 | import static org.onosproject.pce.pceservice.PathComputationTest.D3; |
| 101 | import static org.onosproject.pce.pceservice.PathComputationTest.D4; |
| 102 | import static org.onosproject.pce.pceservice.PathComputationTest.D5; |
| 103 | import static org.onosproject.pce.pceservice.PathComputationTest.DEVICE1; |
| 104 | import static org.onosproject.pce.pceservice.PathComputationTest.DEVICE2; |
| 105 | import static org.onosproject.pce.pceservice.PathComputationTest.DEVICE3; |
| 106 | import static org.onosproject.pce.pceservice.PathComputationTest.DEVICE4; |
| 107 | import static org.onosproject.pce.pceservice.PathComputationTest.DEVICE5; |
| 108 | import static org.onosproject.pce.pceservice.PcepAnnotationKeys.LOCAL_LSP_ID; |
| 109 | import static org.onosproject.pce.pceservice.PcepAnnotationKeys.PLSP_ID; |
| 110 | import static org.onosproject.pce.pceservice.constraint.CostConstraint.Type.COST; |
| 111 | import static org.onosproject.pce.pceservice.constraint.CostConstraint.Type.TE_COST; |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 112 | |
| 113 | /** |
| 114 | * Tests the functions of PceManager. |
| 115 | */ |
| 116 | public class PceManagerTest { |
| 117 | |
| 118 | private PathComputationTest pathCompTest = new PathComputationTest(); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 119 | private MockTopologyService topologyService = new MockTopologyService(); |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 120 | private MockMastershipService mastershipService = new MockMastershipService(); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 121 | private MockPathService pathService = new MockPathService(); |
| 122 | private PceManager pceManager = new PceManager(); |
| 123 | private MockCoreService coreService = new MockCoreService(); |
| 124 | private MockTunnelServiceAdapter tunnelService = new MockTunnelServiceAdapter(); |
| 125 | private TestStorageService storageService = new TestStorageService(); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 126 | private MockDeviceService deviceService = new MockDeviceService(); |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 127 | private MockNetConfigRegistryAdapter netConfigRegistry = new PathComputationTest.MockNetConfigRegistryAdapter(); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 128 | private PceStore pceStore = new PceStoreAdapter(); |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 129 | private PathComputationTest.MockBandwidthMgmtService bandwidthMgmtService = new PathComputationTest |
| 130 | .MockBandwidthMgmtService(); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 131 | |
| 132 | public static ProviderId providerId = new ProviderId("pce", "foo"); |
| 133 | private static final String L3 = "L3"; |
| 134 | private static final String LSRID = "lsrId"; |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 135 | private static final String PCECC_CAPABILITY = "pceccCapability"; |
| 136 | private static final String SR_CAPABILITY = "srCapability"; |
| 137 | private static final String LABEL_STACK_CAPABILITY = "labelStackCapability"; |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 138 | |
| 139 | private TopologyGraph graph = null; |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 140 | private Device deviceD1, deviceD2, deviceD3, deviceD4, deviceD5; |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 141 | private Device pcepDeviceD1, pcepDeviceD2, pcepDeviceD3, pcepDeviceD4; |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 142 | private Link link1, link2, link3, link4, link5, link6; |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 143 | protected static int flowsDownloaded; |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 144 | private TunnelListener tunnelListener; |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 145 | private TopologyListener listener; |
| 146 | private Topology topology; |
| 147 | private Set<TopologyEdge> edges; |
| 148 | private Set<TopologyVertex> vertexes; |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 149 | |
| 150 | @Before |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 151 | public void startUp() throws TestUtilsException { |
| 152 | listener = TestUtils.getField(pceManager, "topologyListener"); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 153 | pceManager.pathService = pathService; |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 154 | pceManager.topologyService = topologyService; |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 155 | pceManager.tunnelService = tunnelService; |
| 156 | pceManager.coreService = coreService; |
| 157 | pceManager.storageService = storageService; |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 158 | pceManager.deviceService = deviceService; |
Avantika-Huawei | 032a987 | 2016-05-27 22:57:38 +0530 | [diff] [blame] | 159 | pceManager.netCfgService = netConfigRegistry; |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 160 | pceManager.netConfigRegistry = netConfigRegistry; |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 161 | pceManager.pceStore = pceStore; |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 162 | pceManager.mastershipService = mastershipService; |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 163 | pceManager.bandwidthMgmtService = bandwidthMgmtService; |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 164 | pceManager.activate(); |
| 165 | } |
| 166 | |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 167 | private class MockMastershipService extends MastershipServiceAdapter { |
| 168 | @Override |
| 169 | public MastershipRole getLocalRole(DeviceId deviceId) { |
| 170 | return MASTER; |
| 171 | } |
| 172 | |
| 173 | @Override |
| 174 | public boolean isLocalMaster(DeviceId deviceId) { |
| 175 | return getLocalRole(deviceId) == MASTER; |
| 176 | } |
| 177 | } |
| 178 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 179 | private void build4RouterTopo(boolean setCost, boolean setPceccCap, boolean setSrCap, |
| 180 | boolean setLabelStackCap, int bandwidth) { |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 181 | link1 = PathComputationTest.addLink(DEVICE1, 10, DEVICE2, 20, setCost, 50); |
| 182 | link2 = PathComputationTest.addLink(DEVICE2, 30, DEVICE4, 40, setCost, 20); |
| 183 | link3 = PathComputationTest.addLink(DEVICE1, 80, DEVICE3, 70, setCost, 100); |
| 184 | link4 = PathComputationTest.addLink(DEVICE3, 60, DEVICE4, 50, setCost, 80); |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 185 | link5 = PathComputationTest.addLink(DEVICE2, 60, DEVICE5, 50, setCost, 80); |
| 186 | link6 = PathComputationTest.addLink(DEVICE4, 60, DEVICE5, 50, setCost, 80); |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 187 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 188 | if (setCost) { |
| 189 | TeLinkConfig teLinkConfig = netConfigRegistry.addConfig(LinkKey.linkKey(link1), TeLinkConfig.class); |
| 190 | teLinkConfig.igpCost(50) |
| 191 | .apply(); |
| 192 | |
| 193 | TeLinkConfig teLinkConfig2 = netConfigRegistry.addConfig(LinkKey.linkKey(link2), TeLinkConfig.class); |
| 194 | teLinkConfig2.igpCost(20) |
| 195 | .apply(); |
| 196 | |
| 197 | TeLinkConfig teLinkConfig3 = netConfigRegistry.addConfig(LinkKey.linkKey(link3), TeLinkConfig.class); |
| 198 | teLinkConfig3.igpCost(100) |
| 199 | .apply(); |
| 200 | |
| 201 | TeLinkConfig teLinkConfig4 = netConfigRegistry.addConfig(LinkKey.linkKey(link4), TeLinkConfig.class); |
| 202 | teLinkConfig4.igpCost(80) |
| 203 | .apply(); |
| 204 | |
| 205 | TeLinkConfig teLinkConfig5 = netConfigRegistry.addConfig(LinkKey.linkKey(link5), TeLinkConfig.class); |
| 206 | teLinkConfig5.igpCost(80) |
| 207 | .apply(); |
| 208 | |
| 209 | TeLinkConfig teLinkConfig6 = netConfigRegistry.addConfig(LinkKey.linkKey(link6), TeLinkConfig.class); |
| 210 | teLinkConfig6.igpCost(80) |
| 211 | .apply(); |
| 212 | } else { |
| 213 | TeLinkConfig teLinkConfig = netConfigRegistry.addConfig(LinkKey.linkKey(link1), TeLinkConfig.class); |
| 214 | teLinkConfig.teCost(50) |
| 215 | .apply(); |
| 216 | |
| 217 | |
| 218 | TeLinkConfig teLinkConfig2 = netConfigRegistry.addConfig(LinkKey.linkKey(link2), TeLinkConfig.class); |
| 219 | teLinkConfig2.teCost(20) |
| 220 | .apply(); |
| 221 | |
| 222 | TeLinkConfig teLinkConfig3 = netConfigRegistry.addConfig(LinkKey.linkKey(link3), TeLinkConfig.class); |
| 223 | teLinkConfig3.teCost(100) |
| 224 | .apply(); |
| 225 | |
| 226 | TeLinkConfig teLinkConfig4 = netConfigRegistry.addConfig(LinkKey.linkKey(link4), TeLinkConfig.class); |
| 227 | teLinkConfig4.teCost(80) |
| 228 | .apply(); |
| 229 | |
| 230 | TeLinkConfig teLinkConfig5 = netConfigRegistry.addConfig(LinkKey.linkKey(link5), TeLinkConfig.class); |
| 231 | teLinkConfig5.teCost(80) |
| 232 | .apply(); |
| 233 | |
| 234 | TeLinkConfig teLinkConfig6 = netConfigRegistry.addConfig(LinkKey.linkKey(link6), TeLinkConfig.class); |
| 235 | teLinkConfig6.teCost(80) |
| 236 | .apply(); |
| 237 | } |
| 238 | |
| 239 | |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 240 | Set<TopologyVertex> vertexes = new HashSet<TopologyVertex>(); |
| 241 | vertexes.add(D1); |
| 242 | vertexes.add(D2); |
| 243 | vertexes.add(D3); |
| 244 | vertexes.add(D4); |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 245 | vertexes.add(D5); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 246 | |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 247 | this.vertexes = vertexes; |
| 248 | |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 249 | Set<TopologyEdge> edges = new HashSet<TopologyEdge>(); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 250 | TopologyEdge edge1 = new DefaultTopologyEdge(D1, D2, link1); |
| 251 | edges.add(edge1); |
| 252 | |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 253 | TopologyEdge edge2 = new DefaultTopologyEdge(D2, D4, link2); |
| 254 | edges.add(edge2); |
| 255 | |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 256 | TopologyEdge edge3 = new DefaultTopologyEdge(D1, D3, link3); |
| 257 | edges.add(edge3); |
| 258 | |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 259 | TopologyEdge edge4 = new DefaultTopologyEdge(D3, D4, link4); |
| 260 | edges.add(edge4); |
| 261 | |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 262 | TopologyEdge edge5 = new DefaultTopologyEdge(D2, D5, link5); |
| 263 | edges.add(edge5); |
| 264 | |
| 265 | TopologyEdge edge6 = new DefaultTopologyEdge(D4, D5, link6); |
| 266 | edges.add(edge6); |
| 267 | |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 268 | this.edges = edges; |
| 269 | |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 270 | graph = new DefaultTopologyGraph(vertexes, edges); |
| 271 | |
| 272 | DefaultAnnotations.Builder builderDev1 = DefaultAnnotations.builder(); |
| 273 | DefaultAnnotations.Builder builderDev2 = DefaultAnnotations.builder(); |
| 274 | DefaultAnnotations.Builder builderDev3 = DefaultAnnotations.builder(); |
| 275 | DefaultAnnotations.Builder builderDev4 = DefaultAnnotations.builder(); |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 276 | DefaultAnnotations.Builder builderDev5 = DefaultAnnotations.builder(); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 277 | |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 278 | // Making L3 devices |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 279 | builderDev1.set(AnnotationKeys.TYPE, L3); |
| 280 | builderDev1.set(LSRID, "1.1.1.1"); |
| 281 | |
| 282 | builderDev2.set(AnnotationKeys.TYPE, L3); |
| 283 | builderDev2.set(LSRID, "2.2.2.2"); |
| 284 | |
| 285 | builderDev3.set(AnnotationKeys.TYPE, L3); |
| 286 | builderDev3.set(LSRID, "3.3.3.3"); |
| 287 | |
| 288 | builderDev4.set(AnnotationKeys.TYPE, L3); |
| 289 | builderDev4.set(LSRID, "4.4.4.4"); |
| 290 | |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 291 | builderDev5.set(AnnotationKeys.TYPE, L3); |
| 292 | builderDev5.set(LSRID, "5.5.5.5"); |
| 293 | |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 294 | deviceD1 = new MockDevice(D1.deviceId(), builderDev1.build()); |
| 295 | deviceD2 = new MockDevice(D2.deviceId(), builderDev2.build()); |
| 296 | deviceD3 = new MockDevice(D3.deviceId(), builderDev3.build()); |
| 297 | deviceD4 = new MockDevice(D4.deviceId(), builderDev4.build()); |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 298 | deviceD5 = new MockDevice(D5.deviceId(), builderDev5.build()); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 299 | |
| 300 | deviceService.addDevice(deviceD1); |
| 301 | deviceService.addDevice(deviceD2); |
| 302 | deviceService.addDevice(deviceD3); |
| 303 | deviceService.addDevice(deviceD4); |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 304 | deviceService.addDevice(deviceD5); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 305 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 306 | DeviceCapability device1Cap = netConfigRegistry.addConfig(DeviceId.deviceId("1.1.1.1"), DeviceCapability.class); |
| 307 | device1Cap.setLabelStackCap(setLabelStackCap) |
| 308 | .setLocalLabelCap(setPceccCap) |
| 309 | .setSrCap(setSrCap) |
| 310 | .apply(); |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 311 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 312 | DeviceCapability device2Cap = netConfigRegistry.addConfig(DeviceId.deviceId("2.2.2.2"), DeviceCapability.class); |
| 313 | device2Cap.setLabelStackCap(setLabelStackCap) |
| 314 | .setLocalLabelCap(setPceccCap) |
| 315 | .setSrCap(setSrCap) |
| 316 | .apply(); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 317 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 318 | DeviceCapability device3Cap = netConfigRegistry.addConfig(DeviceId.deviceId("3.3.3.3"), DeviceCapability.class); |
| 319 | device3Cap.setLabelStackCap(setLabelStackCap) |
| 320 | .setLocalLabelCap(setPceccCap) |
| 321 | .setSrCap(setSrCap) |
| 322 | .apply(); |
Andrey Komarov | 2398d96 | 2016-09-26 15:11:23 +0300 | [diff] [blame] | 323 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 324 | DeviceCapability device4Cap = netConfigRegistry.addConfig(DeviceId.deviceId("4.4.4.4"), DeviceCapability.class); |
| 325 | device4Cap.setLabelStackCap(setLabelStackCap) |
| 326 | .setLocalLabelCap(setPceccCap) |
| 327 | .setSrCap(setSrCap) |
| 328 | .apply(); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 329 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 330 | DeviceCapability device5Cap = netConfigRegistry.addConfig(DeviceId.deviceId("5.5.5.5"), DeviceCapability.class); |
| 331 | device4Cap.setLabelStackCap(setLabelStackCap) |
Andrey Komarov | 2398d96 | 2016-09-26 15:11:23 +0300 | [diff] [blame] | 332 | .setLocalLabelCap(setPceccCap) |
| 333 | .setSrCap(setSrCap) |
| 334 | .apply(); |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 335 | |
| 336 | if (bandwidth != 0) { |
| 337 | Set<Double> unreserved = new HashSet<>(); |
| 338 | unreserved.add(new Double(bandwidth)); |
| 339 | |
| 340 | bandwidthMgmtService.addUnreservedBw(LinkKey.linkKey(link1), unreserved); |
| 341 | bandwidthMgmtService.allocLocalReservedBw(LinkKey.linkKey(link1), new Double(0)); |
| 342 | |
| 343 | bandwidthMgmtService.addUnreservedBw(LinkKey.linkKey(link2), unreserved); |
| 344 | bandwidthMgmtService.allocLocalReservedBw(LinkKey.linkKey(link2), new Double(0)); |
| 345 | |
| 346 | bandwidthMgmtService.addUnreservedBw(LinkKey.linkKey(link3), unreserved); |
| 347 | bandwidthMgmtService.allocLocalReservedBw(LinkKey.linkKey(link3), new Double(0)); |
| 348 | |
| 349 | bandwidthMgmtService.addUnreservedBw(LinkKey.linkKey(link4), unreserved); |
| 350 | bandwidthMgmtService.allocLocalReservedBw(LinkKey.linkKey(link4), new Double(0)); |
| 351 | |
| 352 | bandwidthMgmtService.addUnreservedBw(LinkKey.linkKey(link5), unreserved); |
| 353 | bandwidthMgmtService.allocLocalReservedBw(LinkKey.linkKey(link5), new Double(0)); |
| 354 | |
| 355 | bandwidthMgmtService.addUnreservedBw(LinkKey.linkKey(link6), unreserved); |
| 356 | bandwidthMgmtService.allocLocalReservedBw(LinkKey.linkKey(link6), new Double(0)); |
| 357 | } |
Andrey Komarov | 2398d96 | 2016-09-26 15:11:23 +0300 | [diff] [blame] | 358 | } |
| 359 | |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 360 | /** |
| 361 | * Tests path success with (IGP) cost constraint for signalled LSP. |
| 362 | */ |
| 363 | @Test |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 364 | public void setupPathTest1() { |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 365 | build4RouterTopo(true, false, false, false, 0); // IGP cost is set here. |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 366 | List<Constraint> constraints = new LinkedList<Constraint>(); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 367 | CostConstraint costConstraint = new CostConstraint(COST); |
| 368 | constraints.add(costConstraint); |
| 369 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 370 | boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, WITH_SIGNALLING, null); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 371 | assertThat(result, is(true)); |
| 372 | } |
| 373 | |
| 374 | /** |
| 375 | * Tests path failure with (IGP) cost constraint for signalled LSP. |
| 376 | */ |
| 377 | @Test |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 378 | public void setupPathTest2() { |
| 379 | build4RouterTopo(false, false, false, false, 0); // TE cost is set here, not IGP. |
| 380 | List<Constraint> constraints = new LinkedList<Constraint>(); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 381 | CostConstraint costConstraint = new CostConstraint(COST); |
| 382 | constraints.add(costConstraint); |
| 383 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 384 | boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, WITH_SIGNALLING, null); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 385 | assertThat(result, is(false)); |
| 386 | } |
| 387 | |
| 388 | /** |
| 389 | * Tests path success with TE-cost constraint for signalled LSP. |
| 390 | */ |
| 391 | @Test |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 392 | public void setupPathTest3() { |
| 393 | build4RouterTopo(false, false, false, false, 0); // TE cost is set here. |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 394 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 395 | List<Constraint> constraints = new LinkedList<Constraint>(); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 396 | CostConstraint costConstraint = new CostConstraint(TE_COST); |
| 397 | constraints.add(costConstraint); |
| 398 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 399 | boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, WITH_SIGNALLING, null); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 400 | assertThat(result, is(true)); |
| 401 | } |
| 402 | |
| 403 | /** |
| 404 | * Tests path failure with TE-cost constraint for signalled LSP. |
| 405 | */ |
| 406 | @Test |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 407 | public void setupPathTest4() { |
| 408 | build4RouterTopo(true, false, false, false, 0); // IGP cost is set here, not TE. |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 409 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 410 | List<Constraint> constraints = new LinkedList<Constraint>(); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 411 | CostConstraint costConstraint = new CostConstraint(TE_COST); |
| 412 | constraints.add(costConstraint); |
| 413 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 414 | boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, WITH_SIGNALLING, null); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 415 | assertThat(result, is(false)); |
| 416 | } |
| 417 | |
| 418 | /** |
| 419 | * Tests path success with (IGP) cost constraint for non-SR non-signalled LSP. |
| 420 | */ |
| 421 | @Test |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 422 | public void setupPathTest5() { |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 423 | build4RouterTopo(true, true, false, false, 0); |
| 424 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 425 | List<Constraint> constraints = new LinkedList<Constraint>(); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 426 | CostConstraint costConstraint = new CostConstraint(COST); |
| 427 | constraints.add(costConstraint); |
| 428 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 429 | boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, |
| 430 | WITHOUT_SIGNALLING_AND_WITHOUT_SR, null); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 431 | assertThat(result, is(true)); |
| 432 | } |
| 433 | |
| 434 | /** |
| 435 | * Tests path success with TE-cost constraint for non-SR non-sgnalled LSP. |
| 436 | */ |
| 437 | @Test |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 438 | public void setupPathTest6() { |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 439 | build4RouterTopo(false, true, false, false, 0); |
| 440 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 441 | List<Constraint> constraints = new LinkedList<Constraint>(); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 442 | CostConstraint costConstraint = new CostConstraint(TE_COST); |
| 443 | constraints.add(costConstraint); |
| 444 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 445 | boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, |
| 446 | WITHOUT_SIGNALLING_AND_WITHOUT_SR, null); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 447 | assertThat(result, is(true)); |
| 448 | } |
| 449 | |
| 450 | /** |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 451 | * Tests path failure with TE-cost constraint for non-SR non-signalled LSP(CR). Label capability not registered. |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 452 | */ |
| 453 | @Test |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 454 | public void setupPathTest7() { |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 455 | build4RouterTopo(true, false, false, false, 0); |
| 456 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 457 | List<Constraint> constraints = new LinkedList<Constraint>(); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 458 | CostConstraint costConstraint = new CostConstraint(TE_COST); |
| 459 | constraints.add(costConstraint); |
| 460 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 461 | boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, |
| 462 | WITHOUT_SIGNALLING_AND_WITHOUT_SR, null); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 463 | assertThat(result, is(false)); |
| 464 | } |
| 465 | |
| 466 | /** |
| 467 | * Tests path failure as bandwidth is requested but is not registered. |
| 468 | */ |
| 469 | @Test |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 470 | public void setupPathTest8() { |
| 471 | build4RouterTopo(true, false, false, false, 2); |
| 472 | |
Andrey Komarov | 2398d96 | 2016-09-26 15:11:23 +0300 | [diff] [blame] | 473 | List<Constraint> constraints = new LinkedList<>(); |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 474 | PceBandwidthConstraint bwConstraint = new PceBandwidthConstraint(Bandwidth.bps(10.0)); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 475 | CostConstraint costConstraint = new CostConstraint(TE_COST); |
| 476 | |
| 477 | constraints.add(costConstraint); |
| 478 | constraints.add(bwConstraint); |
| 479 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 480 | boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, |
| 481 | WITH_SIGNALLING, null); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 482 | assertThat(result, is(false)); |
| 483 | } |
| 484 | |
| 485 | /** |
| 486 | * Tests path failure as bandwidth requested is more than registered. |
| 487 | */ |
| 488 | @Test |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 489 | public void setupPathTest9() { |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 490 | build4RouterTopo(false, false, false, false, 5); |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 491 | List<Constraint> constraints = new LinkedList<Constraint>(); |
| 492 | PceBandwidthConstraint bwConstraint = new PceBandwidthConstraint(Bandwidth.bps(10.0)); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 493 | CostConstraint costConstraint = new CostConstraint(TE_COST); |
| 494 | |
| 495 | constraints.add(costConstraint); |
| 496 | constraints.add(bwConstraint); |
| 497 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 498 | boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", |
| 499 | constraints, WITH_SIGNALLING, null); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 500 | assertThat(result, is(false)); |
| 501 | } |
| 502 | |
| 503 | /** |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 504 | * Tests path setup failure(without signalling). Label capability is not present. |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 505 | */ |
| 506 | @Test |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 507 | public void setupPathTest10() { |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 508 | build4RouterTopo(false, false, false, false, 0); |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 509 | List<Constraint> constraints = new LinkedList<Constraint>(); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 510 | CostConstraint costConstraint = new CostConstraint(TE_COST); |
| 511 | constraints.add(costConstraint); |
| 512 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 513 | boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, |
| 514 | SR_WITHOUT_SIGNALLING, null); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 515 | assertThat(result, is(false)); |
| 516 | } |
| 517 | |
| 518 | /** |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 519 | * Tests path setup without signalling and with bandwidth reservation. |
| 520 | */ |
| 521 | @Test |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 522 | public void setupPathTest12() { |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 523 | build4RouterTopo(false, true, true, true, 15); |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 524 | List<Constraint> constraints = new LinkedList<Constraint>(); |
| 525 | PceBandwidthConstraint bwConstraint = new PceBandwidthConstraint(Bandwidth.bps(10.0)); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 526 | CostConstraint costConstraint = new CostConstraint(TE_COST); |
| 527 | |
| 528 | constraints.add(costConstraint); |
| 529 | constraints.add(bwConstraint); |
| 530 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 531 | boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", |
| 532 | constraints, SR_WITHOUT_SIGNALLING, null); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 533 | assertThat(result, is(true)); |
| 534 | } |
| 535 | |
| 536 | /** |
| 537 | * Tests path setup without cost/bandwidth constraints. |
| 538 | */ |
| 539 | @Test |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 540 | public void setupPathTest13() { |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 541 | build4RouterTopo(false, false, false, false, 0); |
| 542 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 543 | boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", null, WITH_SIGNALLING, null); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 544 | assertThat(result, is(true)); |
| 545 | } |
| 546 | |
| 547 | /** |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 548 | * Tests path setup with explicit path with loose node D2. |
| 549 | */ |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 550 | @Test |
| 551 | public void setupPathTest14() { |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 552 | build4RouterTopo(false, false, false, false, 0); |
| 553 | |
| 554 | List<ExplicitPathInfo> explicitPathInfoList = Lists.newLinkedList(); |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 555 | ExplicitPathInfo obj = new ExplicitPathInfo(ExplicitPathInfo.Type.LOOSE, D2.deviceId()); |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 556 | explicitPathInfoList.add(obj); |
| 557 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 558 | boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", null, WITH_SIGNALLING, |
| 559 | explicitPathInfoList); |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 560 | |
| 561 | Tunnel tunnel = pceManager.queryAllPath().iterator().next(); |
| 562 | List<Link> links = new LinkedList<>(); |
| 563 | links.add(link1); |
| 564 | links.add(link2); |
| 565 | |
| 566 | assertThat(result, is(true)); |
| 567 | assertThat(tunnel.path().links().equals(links), is(true)); |
| 568 | } |
| 569 | |
| 570 | /** |
| 571 | * Tests path setup with explicit path with loose node D3. |
| 572 | */ |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 573 | @Test |
| 574 | public void setupPathTest15() { |
| 575 | build4RouterTopo(false, false, false, false, 0); |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 576 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 577 | List<ExplicitPathInfo> explicitPathInfoList = Lists.newLinkedList(); |
| 578 | ExplicitPathInfo obj = new ExplicitPathInfo(ExplicitPathInfo.Type.LOOSE, D3.deviceId()); |
| 579 | explicitPathInfoList.add(obj); |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 580 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 581 | boolean result = pceManager.setupPath(D1.deviceId(), D5.deviceId(), "T123", null, WITH_SIGNALLING, |
| 582 | explicitPathInfoList); |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 583 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 584 | Tunnel tunnel = pceManager.queryAllPath().iterator().next(); |
| 585 | List<Link> links = new LinkedList<>(); |
| 586 | links.add(link3); |
| 587 | links.add(link4); |
| 588 | links.add(link6); |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 589 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 590 | assertThat(result, is(true)); |
| 591 | assertThat(tunnel.path().links().equals(links), is(true)); |
| 592 | } |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 593 | |
| 594 | /** |
| 595 | * Tests path setup with explicit path with loose node D4 , D3 - path fails. |
| 596 | */ |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 597 | @Test |
| 598 | public void setupPathTest16() { |
| 599 | build4RouterTopo(false, false, false, false, 0); |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 600 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 601 | List<ExplicitPathInfo> explicitPathInfoList = Lists.newLinkedList(); |
| 602 | ExplicitPathInfo obj = new ExplicitPathInfo(ExplicitPathInfo.Type.LOOSE, D4.deviceId()); |
| 603 | explicitPathInfoList.add(obj); |
| 604 | obj = new ExplicitPathInfo(ExplicitPathInfo.Type.LOOSE, D3.deviceId()); |
| 605 | explicitPathInfoList.add(obj); |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 606 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 607 | boolean result = pceManager.setupPath(D1.deviceId(), D5.deviceId(), "T123", null, WITH_SIGNALLING, |
| 608 | explicitPathInfoList); |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 609 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 610 | assertThat(result, is(false)); |
| 611 | } |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 612 | |
| 613 | /** |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 614 | * Tests path setup with explicit path with strict node D2 - without reacble to src - path fails. |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 615 | */ |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 616 | @Test |
| 617 | public void setupPathTest17() { |
| 618 | build4RouterTopo(false, false, false, false, 0); |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 619 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 620 | List<ExplicitPathInfo> explicitPathInfoList = Lists.newLinkedList(); |
| 621 | ExplicitPathInfo obj = new ExplicitPathInfo(ExplicitPathInfo.Type.STRICT, D2.deviceId()); |
| 622 | explicitPathInfoList.add(obj); |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 623 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 624 | boolean result = pceManager.setupPath(D1.deviceId(), D5.deviceId(), "T123", null, WITH_SIGNALLING, |
| 625 | explicitPathInfoList); |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 626 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 627 | assertThat(result, is(false)); |
| 628 | } |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 629 | |
| 630 | /** |
| 631 | * Tests path setup with explicit path with loose node D2, strict D2. |
| 632 | */ |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 633 | @Test |
| 634 | public void setupPathTest18() { |
| 635 | build4RouterTopo(false, false, false, false, 0); |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 636 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 637 | List<ExplicitPathInfo> explicitPathInfoList = Lists.newLinkedList(); |
| 638 | ExplicitPathInfo obj = new ExplicitPathInfo(ExplicitPathInfo.Type.LOOSE, D2.deviceId()); |
| 639 | explicitPathInfoList.add(obj); |
| 640 | obj = new ExplicitPathInfo(ExplicitPathInfo.Type.STRICT, D2.deviceId()); |
| 641 | explicitPathInfoList.add(obj); |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 642 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 643 | boolean result = pceManager.setupPath(D1.deviceId(), D5.deviceId(), "T123", null, WITH_SIGNALLING, |
| 644 | explicitPathInfoList); |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 645 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 646 | Tunnel tunnel = pceManager.queryAllPath().iterator().next(); |
| 647 | List<Link> links = new LinkedList<>(); |
| 648 | links.add(link1); |
| 649 | links.add(link5); |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 650 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 651 | assertThat(result, is(true)); |
| 652 | assertThat(tunnel.path().links().equals(links), is(true)); |
| 653 | } |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 654 | |
| 655 | /** |
| 656 | * Tests path setup with explicit path with loose D1-D2, strict D2. |
| 657 | */ |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 658 | @Test |
| 659 | public void setupPathTest19() { |
| 660 | build4RouterTopo(false, false, false, false, 0); |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 661 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 662 | List<ExplicitPathInfo> explicitPathInfoList = Lists.newLinkedList(); |
| 663 | ExplicitPathInfo obj = new ExplicitPathInfo(ExplicitPathInfo.Type.LOOSE, link1); |
| 664 | explicitPathInfoList.add(obj); |
| 665 | obj = new ExplicitPathInfo(ExplicitPathInfo.Type.STRICT, D2.deviceId()); |
| 666 | explicitPathInfoList.add(obj); |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 667 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 668 | boolean result = pceManager.setupPath(D1.deviceId(), D5.deviceId(), "T123", null, WITH_SIGNALLING, |
| 669 | explicitPathInfoList); |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 670 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 671 | Tunnel tunnel = pceManager.queryAllPath().iterator().next(); |
| 672 | List<Link> links = new LinkedList<>(); |
| 673 | links.add(link1); |
| 674 | links.add(link5); |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 675 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 676 | assertThat(result, is(true)); |
| 677 | assertThat(tunnel.path().links().equals(links), is(true)); |
| 678 | } |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 679 | |
| 680 | /** |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 681 | * Tests path update with increase in bandwidth. |
| 682 | */ |
| 683 | @Test |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 684 | public void updatePathTest1() { |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 685 | build4RouterTopo(false, true, true, true, 100); |
| 686 | |
| 687 | // Setup tunnel. |
| 688 | List<Constraint> constraints = new LinkedList<>(); |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 689 | PceBandwidthConstraint bwConstraint = new PceBandwidthConstraint(Bandwidth.bps(60.0)); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 690 | constraints.add(bwConstraint); |
| 691 | CostConstraint costConstraint = new CostConstraint(TE_COST); |
| 692 | constraints.add(costConstraint); |
| 693 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 694 | boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", |
| 695 | constraints, WITH_SIGNALLING, null); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 696 | assertThat(result, is(true)); |
| 697 | |
| 698 | // Change constraint and update it. |
| 699 | constraints = new LinkedList<>(); |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 700 | bwConstraint = new PceBandwidthConstraint(Bandwidth.bps(50.0)); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 701 | constraints.add(bwConstraint); |
| 702 | constraints.add(costConstraint); |
| 703 | |
| 704 | Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath(); |
| 705 | assertThat(tunnels.size(), is(1)); |
| 706 | |
| 707 | Tunnel tunnel = tunnels.iterator().next(); |
| 708 | |
| 709 | // Stimulate the effect of LSP ids from protocol msg. |
| 710 | tunnelService.updateTunnelWithLspIds(tunnel, "123", "1", State.ACTIVE); |
| 711 | |
| 712 | result = pceManager.updatePath(tunnel.tunnelId(), constraints); |
| 713 | assertThat(result, is(true)); |
| 714 | |
| 715 | tunnels = (Collection<Tunnel>) pceManager.queryAllPath(); |
| 716 | assertThat(tunnels.size(), is(2)); |
| 717 | } |
| 718 | |
| 719 | /** |
| 720 | * Tests path update with decrease in bandwidth. |
| 721 | */ |
| 722 | @Test |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 723 | public void updatePathTest2() { |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 724 | build4RouterTopo(false, true, true, true, 100); |
| 725 | |
| 726 | // Setup tunnel. |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 727 | List<Constraint> constraints = new LinkedList<Constraint>(); |
| 728 | PceBandwidthConstraint bwConstraint = new PceBandwidthConstraint(Bandwidth.bps(60.0)); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 729 | constraints.add(bwConstraint); |
| 730 | CostConstraint costConstraint = new CostConstraint(TE_COST); |
| 731 | constraints.add(costConstraint); |
| 732 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 733 | boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", |
| 734 | constraints, SR_WITHOUT_SIGNALLING, null); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 735 | assertThat(result, is(true)); |
| 736 | |
| 737 | // Change constraint and update it. |
| 738 | constraints.remove(bwConstraint); |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 739 | bwConstraint = new PceBandwidthConstraint(Bandwidth.bps(70.0)); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 740 | constraints.add(bwConstraint); |
| 741 | |
| 742 | Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath(); |
| 743 | assertThat(tunnels.size(), is(1)); |
| 744 | |
| 745 | for (Tunnel tunnel : tunnels) { |
| 746 | result = pceManager.updatePath(tunnel.tunnelId(), constraints); |
| 747 | assertThat(result, is(true)); |
| 748 | } |
| 749 | |
| 750 | tunnels = (Collection<Tunnel>) pceManager.queryAllPath(); |
| 751 | assertThat(tunnels.size(), is(2)); |
| 752 | } |
| 753 | |
| 754 | /** |
| 755 | * Tests path update without cost/bandwidth constraints. |
| 756 | */ |
| 757 | @Test |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 758 | public void updatePathTest3() { |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 759 | build4RouterTopo(false, true, true, true, 100); |
| 760 | |
| 761 | // Setup tunnel. |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 762 | List<Constraint> constraints = new LinkedList<Constraint>(); |
Priyanka B | 3fdb9dd | 2016-08-08 10:47:24 +0530 | [diff] [blame] | 763 | CostConstraint costConstraint = new CostConstraint(TE_COST); |
| 764 | constraints.add(costConstraint); |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 765 | boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", |
| 766 | constraints, WITH_SIGNALLING, null); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 767 | assertThat(result, is(true)); |
| 768 | |
| 769 | Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath(); |
| 770 | assertThat(tunnels.size(), is(1)); |
| 771 | |
| 772 | for (Tunnel tunnel : tunnels) { |
| 773 | result = pceManager.updatePath(tunnel.tunnelId(), null); |
| 774 | assertThat(result, is(true)); |
| 775 | } |
| 776 | |
| 777 | Iterable<Tunnel> queryTunnelResult = pceManager.queryAllPath(); |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 778 | assertThat((int) queryTunnelResult.spliterator().getExactSizeIfKnown(), is(2)); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | /** |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 782 | * Tests path update without cost/bandwidth constraints and with explicit path object. |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 783 | */ |
| 784 | @Test |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 785 | public void updatePathTest4() { |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 786 | build4RouterTopo(false, true, true, true, 100); |
| 787 | |
| 788 | // Setup tunnel. |
| 789 | List<Constraint> constraints = new LinkedList<>(); |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 790 | PceBandwidthConstraint bwConstraint = new PceBandwidthConstraint(Bandwidth.bps(60.0)); |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 791 | constraints.add(bwConstraint); |
| 792 | CostConstraint costConstraint = new CostConstraint(TE_COST); |
| 793 | constraints.add(costConstraint); |
| 794 | |
| 795 | List<ExplicitPathInfo> explicitPathInfoList = Lists.newLinkedList(); |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 796 | ExplicitPathInfo obj = new ExplicitPathInfo(ExplicitPathInfo.Type.LOOSE, link1); |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 797 | explicitPathInfoList.add(obj); |
| 798 | obj = new ExplicitPathInfo(ExplicitPathInfo.Type.STRICT, D2.deviceId()); |
| 799 | explicitPathInfoList.add(obj); |
| 800 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 801 | boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", |
| 802 | constraints, WITH_SIGNALLING, explicitPathInfoList); |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 803 | assertThat(result, is(true)); |
| 804 | |
| 805 | // Change constraint and update it. |
| 806 | constraints = new LinkedList<>(); |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 807 | bwConstraint = new PceBandwidthConstraint(Bandwidth.bps(50.0)); |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 808 | constraints.add(bwConstraint); |
| 809 | constraints.add(costConstraint); |
| 810 | |
| 811 | Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath(); |
| 812 | assertThat(tunnels.size(), is(1)); |
| 813 | |
| 814 | Tunnel tunnel = tunnels.iterator().next(); |
| 815 | |
| 816 | // Stimulate the effect of LSP ids from protocol msg. |
| 817 | tunnelService.updateTunnelWithLspIds(tunnel, "123", "1", State.ACTIVE); |
| 818 | |
| 819 | result = pceManager.updatePath(tunnel.tunnelId(), constraints); |
| 820 | assertThat(result, is(true)); |
| 821 | |
| 822 | tunnels = (Collection<Tunnel>) pceManager.queryAllPath(); |
| 823 | assertThat(tunnels.size(), is(2)); |
| 824 | } |
| 825 | |
| 826 | /** |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 827 | * Tests path release. |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 828 | */ |
| 829 | @Test |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 830 | public void releasePathTest1() { |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 831 | build4RouterTopo(false, false, false, false, 5); |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 832 | List<Constraint> constraints = new LinkedList<Constraint>(); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 833 | CostConstraint costConstraint = new CostConstraint(TE_COST); |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 834 | PceBandwidthConstraint bwConst = new PceBandwidthConstraint(Bandwidth.bps(3)); |
Priyanka B | 4c3b451 | 2016-07-22 11:41:49 +0530 | [diff] [blame] | 835 | constraints.add(bwConst); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 836 | constraints.add(costConstraint); |
| 837 | |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 838 | List<ExplicitPathInfo> explicitPathInfoList = Lists.newLinkedList(); |
| 839 | ExplicitPathInfo obj = new ExplicitPathInfo(ExplicitPathInfo.Type.LOOSE, link1); |
| 840 | explicitPathInfoList.add(obj); |
| 841 | obj = new ExplicitPathInfo(ExplicitPathInfo.Type.STRICT, D2.deviceId()); |
| 842 | explicitPathInfoList.add(obj); |
| 843 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 844 | pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, WITH_SIGNALLING, explicitPathInfoList); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 845 | |
| 846 | Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath(); |
| 847 | assertThat(tunnels.size(), is(1)); |
| 848 | boolean result; |
| 849 | for (Tunnel tunnel : tunnels) { |
| 850 | result = pceManager.releasePath(tunnel.tunnelId()); |
| 851 | assertThat(result, is(true)); |
| 852 | } |
| 853 | tunnels = (Collection<Tunnel>) pceManager.queryAllPath(); |
| 854 | assertThat(tunnels.size(), is(0)); |
| 855 | } |
| 856 | |
| 857 | /** |
| 858 | * Tests path release failure. |
| 859 | */ |
| 860 | @Test |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 861 | public void releasePathTest2() { |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 862 | build4RouterTopo(false, false, false, false, 5); |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 863 | List<Constraint> constraints = new LinkedList<Constraint>(); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 864 | CostConstraint costConstraint = new CostConstraint(TE_COST); |
| 865 | constraints.add(costConstraint); |
| 866 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 867 | pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, WITH_SIGNALLING, null); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 868 | |
| 869 | Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath(); |
| 870 | assertThat(tunnels.size(), is(1)); |
| 871 | |
| 872 | // Random tunnel id. |
| 873 | boolean result = pceManager.releasePath(TunnelId.valueOf("111")); |
| 874 | assertThat(result, is(false)); |
| 875 | |
| 876 | tunnels = (Collection<Tunnel>) pceManager.queryAllPath(); |
| 877 | assertThat(tunnels.size(), is(1)); |
| 878 | } |
| 879 | |
| 880 | /** |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 881 | * Tests path release failure. |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 882 | */ |
| 883 | @Test |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 884 | public void releasePathTest3() { |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 885 | build4RouterTopo(false, false, false, false, 5); |
| 886 | List<Constraint> constraints = new LinkedList<Constraint>(); |
| 887 | CostConstraint costConstraint = new CostConstraint(TE_COST); |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 888 | PceBandwidthConstraint bwConst = new PceBandwidthConstraint(Bandwidth.bps(3)); |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 889 | constraints.add(bwConst); |
| 890 | constraints.add(costConstraint); |
| 891 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 892 | pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, WITH_SIGNALLING, null); |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 893 | |
| 894 | Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath(); |
| 895 | assertThat(tunnels.size(), is(1)); |
| 896 | boolean result; |
| 897 | for (Tunnel tunnel : tunnels) { |
| 898 | result = pceManager.releasePath(tunnel.tunnelId()); |
| 899 | assertThat(result, is(true)); |
| 900 | } |
| 901 | tunnels = (Collection<Tunnel>) pceManager.queryAllPath(); |
| 902 | assertThat(tunnels.size(), is(0)); |
| 903 | } |
| 904 | |
| 905 | /** |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 906 | * Tests tunnel events added and removed. |
| 907 | */ |
| 908 | @Test |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 909 | public void tunnelEventTest1() { |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 910 | build4RouterTopo(false, true, true, true, 15); |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 911 | List<Constraint> constraints = new LinkedList<Constraint>(); |
| 912 | PceBandwidthConstraint bwConstraint = new PceBandwidthConstraint(Bandwidth.bps(10.0)); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 913 | CostConstraint costConstraint = new CostConstraint(TE_COST); |
| 914 | |
| 915 | constraints.add(costConstraint); |
| 916 | constraints.add(bwConstraint); |
| 917 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 918 | boolean isSuccess = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T1", constraints, |
Andrey Komarov | 2398d96 | 2016-09-26 15:11:23 +0300 | [diff] [blame] | 919 | SR_WITHOUT_SIGNALLING, null); |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 920 | assertThat(isSuccess, is(true)); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 921 | |
| 922 | Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath(); |
| 923 | |
| 924 | for (Tunnel tunnel : tunnels) { |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 925 | TunnelEvent event = new TunnelEvent(TunnelEvent.Type.TUNNEL_ADDED, tunnel); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 926 | tunnelListener.event(event); |
| 927 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 928 | isSuccess = pceManager.releasePath(tunnel.tunnelId()); |
| 929 | assertThat(isSuccess, is(true)); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 930 | |
| 931 | event = new TunnelEvent(TunnelEvent.Type.TUNNEL_REMOVED, tunnel); |
| 932 | tunnelListener.event(event); |
| 933 | } |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 934 | } |
| 935 | |
| 936 | /** |
| 937 | * Tests label allocation/removal in CR case based on tunnel event. |
| 938 | */ |
| 939 | @Test |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 940 | public void tunnelEventTest2() { |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 941 | build4RouterTopo(false, true, true, true, 15); |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 942 | List<Constraint> constraints = new LinkedList<Constraint>(); |
| 943 | PceBandwidthConstraint bwConstraint = new PceBandwidthConstraint(Bandwidth.bps(10.0)); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 944 | CostConstraint costConstraint = new CostConstraint(TE_COST); |
| 945 | |
| 946 | constraints.add(costConstraint); |
| 947 | constraints.add(bwConstraint); |
| 948 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 949 | boolean isSuccess = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T2", constraints, |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 950 | WITHOUT_SIGNALLING_AND_WITHOUT_SR, null); |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 951 | assertThat(isSuccess, is(true)); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 952 | |
| 953 | TunnelEvent event; |
| 954 | Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath(); |
| 955 | for (Tunnel tunnel : tunnels) { |
| 956 | event = new TunnelEvent(TunnelEvent.Type.TUNNEL_ADDED, tunnel); |
| 957 | tunnelListener.event(event); |
| 958 | |
| 959 | // Stimulate the effect of LSP ids from protocol msg. |
| 960 | tunnelService.updateTunnelWithLspIds(tunnel, "123", "1", ESTABLISHED); |
| 961 | } |
| 962 | |
| 963 | tunnels = (Collection<Tunnel>) pceManager.queryAllPath(); |
| 964 | for (Tunnel tunnel : tunnels) { |
| 965 | event = new TunnelEvent(TunnelEvent.Type.TUNNEL_UPDATED, tunnel); |
| 966 | tunnelListener.event(event); |
| 967 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 968 | isSuccess = pceManager.releasePath(tunnel.tunnelId()); |
| 969 | assertThat(isSuccess, is(true)); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 970 | |
| 971 | event = new TunnelEvent(TunnelEvent.Type.TUNNEL_REMOVED, tunnel); |
| 972 | tunnelListener.event(event); |
| 973 | } |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 974 | } |
| 975 | |
| 976 | /** |
| 977 | * Tests handling UNSTABLE state based on tunnel event. |
| 978 | */ |
| 979 | @Test |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 980 | public void tunnelEventTest3() { |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 981 | build4RouterTopo(false, true, true, true, 15); |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 982 | List<Constraint> constraints = new LinkedList<Constraint>(); |
| 983 | PceBandwidthConstraint bwConstraint = new PceBandwidthConstraint(Bandwidth.bps(10.0)); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 984 | CostConstraint costConstraint = new CostConstraint(TE_COST); |
| 985 | |
| 986 | constraints.add(costConstraint); |
| 987 | constraints.add(bwConstraint); |
| 988 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 989 | boolean isSuccess = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T2", constraints, |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 990 | WITHOUT_SIGNALLING_AND_WITHOUT_SR, null); |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 991 | assertThat(isSuccess, is(true)); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 992 | assertThat(pceStore.getFailedPathInfoCount(), is(0)); |
| 993 | |
| 994 | TunnelEvent event; |
| 995 | Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath(); |
| 996 | for (Tunnel tunnel : tunnels) { |
| 997 | event = new TunnelEvent(TunnelEvent.Type.TUNNEL_ADDED, tunnel); |
| 998 | tunnelListener.event(event); |
| 999 | |
| 1000 | // Stimulate the effect of LSP ids from protocol msg. |
| 1001 | tunnelService.updateTunnelWithLspIds(tunnel, "123", "1", UNSTABLE); |
| 1002 | } |
| 1003 | |
| 1004 | tunnels = (Collection<Tunnel>) pceManager.queryAllPath(); |
| 1005 | for (Tunnel tunnel : tunnels) { |
| 1006 | event = new TunnelEvent(TunnelEvent.Type.TUNNEL_UPDATED, tunnel); |
| 1007 | tunnelListener.event(event); |
| 1008 | } |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1009 | |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 1010 | assertThat(pceStore.getFailedPathInfoCount(), is(1)); |
| 1011 | } |
| 1012 | |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1013 | /** |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1014 | * Tests resilency when L2 link is down. |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1015 | */ |
| 1016 | @Test |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1017 | public void resilencyTest1() { |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1018 | build4RouterTopo(true, false, false, false, 10); |
| 1019 | |
| 1020 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1021 | List<Constraint> constraints = new LinkedList<Constraint>(); |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1022 | CostConstraint costConstraint = new CostConstraint(COST); |
| 1023 | constraints.add(costConstraint); |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1024 | PceBandwidthConstraint localBwConst = new PceBandwidthConstraint(Bandwidth.bps(10)); |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1025 | constraints.add(localBwConst); |
| 1026 | |
| 1027 | //Setup the path , tunnel created |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1028 | boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", |
| 1029 | constraints, WITH_SIGNALLING, null); |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1030 | assertThat(result, is(true)); |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1031 | assertThat(pceStore.getFailedPathInfoCount(), is(0)); |
| 1032 | |
| 1033 | List<Event> reasons = new LinkedList<>(); |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1034 | final LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2); |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1035 | reasons.add(linkEvent); |
| 1036 | final TopologyEvent event = new TopologyEvent( |
| 1037 | TopologyEvent.Type.TOPOLOGY_CHANGED, |
| 1038 | topology, |
| 1039 | reasons); |
| 1040 | |
| 1041 | //Change Topology : remove link2 |
| 1042 | Set<TopologyEdge> tempEdges = new HashSet<>(); |
| 1043 | tempEdges.add(new DefaultTopologyEdge(D2, D4, link2)); |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1044 | topologyService.changeInTopology(getGraph(null, tempEdges)); |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1045 | listener.event(event); |
| 1046 | |
| 1047 | List<Link> links = new LinkedList<>(); |
| 1048 | links.add(link3); |
| 1049 | links.add(link4); |
| 1050 | |
| 1051 | //Path is D1-D3-D4 |
| 1052 | assertThat(pathService.paths().iterator().next().links(), is(links)); |
| 1053 | assertThat(pathService.paths().iterator().next().cost(), is((double) 180)); |
| 1054 | } |
| 1055 | |
| 1056 | /** |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1057 | * Tests resilency when L2 and L4 link is down. |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1058 | */ |
| 1059 | @Test |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1060 | public void resilencyTest2() { |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1061 | build4RouterTopo(true, false, false, false, 10); |
| 1062 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1063 | List<Constraint> constraints = new LinkedList<Constraint>(); |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1064 | CostConstraint costConstraint = new CostConstraint(COST); |
| 1065 | constraints.add(costConstraint); |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1066 | PceBandwidthConstraint localBwConst = new PceBandwidthConstraint(Bandwidth.bps(10)); |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1067 | constraints.add(localBwConst); |
| 1068 | |
| 1069 | //Setup the path , tunnel created |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1070 | boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", |
| 1071 | constraints, WITH_SIGNALLING, null); |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1072 | assertThat(result, is(true)); |
| 1073 | |
| 1074 | List<Event> reasons = new LinkedList<>(); |
| 1075 | LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2); |
| 1076 | reasons.add(linkEvent); |
| 1077 | linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link4); |
| 1078 | reasons.add(linkEvent); |
| 1079 | final TopologyEvent event = new TopologyEvent( |
| 1080 | TopologyEvent.Type.TOPOLOGY_CHANGED, |
| 1081 | topology, |
| 1082 | reasons); |
| 1083 | |
| 1084 | //Change Topology : remove link2 and link4 |
| 1085 | Set<TopologyEdge> tempEdges = new HashSet<>(); |
| 1086 | tempEdges.add(new DefaultTopologyEdge(D2, D4, link2)); |
| 1087 | tempEdges.add(new DefaultTopologyEdge(D3, D4, link4)); |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1088 | topologyService.changeInTopology(getGraph(null, tempEdges)); |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1089 | listener.event(event); |
| 1090 | |
| 1091 | //No Path |
| 1092 | assertThat(pathService.paths().size(), is(0)); |
| 1093 | } |
| 1094 | |
| 1095 | /** |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1096 | * Tests resilency when D2 device is down. |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1097 | */ |
| 1098 | @Test |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1099 | public void resilencyTest3() { |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1100 | build4RouterTopo(true, false, false, false, 10); |
| 1101 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1102 | List<Constraint> constraints = new LinkedList<Constraint>(); |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1103 | CostConstraint costConstraint = new CostConstraint(COST); |
| 1104 | constraints.add(costConstraint); |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1105 | PceBandwidthConstraint localBwConst = new PceBandwidthConstraint(Bandwidth.bps(10)); |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1106 | constraints.add(localBwConst); |
| 1107 | |
| 1108 | //Setup the path , tunnel created |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1109 | boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", |
| 1110 | constraints, WITH_SIGNALLING, null); |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1111 | assertThat(result, is(true)); |
| 1112 | |
| 1113 | List<Event> reasons = new LinkedList<>(); |
| 1114 | LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2); |
| 1115 | reasons.add(linkEvent); |
| 1116 | linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link1); |
| 1117 | reasons.add(linkEvent); |
| 1118 | final TopologyEvent event = new TopologyEvent( |
| 1119 | TopologyEvent.Type.TOPOLOGY_CHANGED, |
| 1120 | topology, |
| 1121 | reasons); |
| 1122 | |
| 1123 | //Change Topology : remove link2 and link1 |
| 1124 | Set<TopologyEdge> tempEdges = new HashSet<>(); |
| 1125 | tempEdges.add(new DefaultTopologyEdge(D2, D4, link2)); |
| 1126 | tempEdges.add(new DefaultTopologyEdge(D1, D2, link1)); |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1127 | topologyService.changeInTopology(getGraph(null, tempEdges)); |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1128 | listener.event(event); |
| 1129 | |
| 1130 | List<Link> links = new LinkedList<>(); |
| 1131 | links.add(link3); |
| 1132 | links.add(link4); |
| 1133 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1134 | Path path = tunnelService.queryAllTunnels().iterator().next().path(); |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1135 | //Path is D1-D3-D4 |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1136 | assertThat(path.links(), is(links)); |
| 1137 | assertThat(path.cost(), is((double) 180)); |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1138 | } |
| 1139 | |
| 1140 | /** |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1141 | * Tests resilency when ingress device is down. |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1142 | */ |
| 1143 | @Test |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1144 | public void resilencyTest4() { |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1145 | build4RouterTopo(true, false, false, false, 10); |
| 1146 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1147 | List<Constraint> constraints = new LinkedList<Constraint>(); |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1148 | CostConstraint costConstraint = new CostConstraint(COST); |
| 1149 | constraints.add(costConstraint); |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1150 | PceBandwidthConstraint localBwConst = new PceBandwidthConstraint(Bandwidth.bps(10)); |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1151 | constraints.add(localBwConst); |
| 1152 | |
| 1153 | //Setup the path , tunnel created |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1154 | boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", |
| 1155 | constraints, WITH_SIGNALLING, null); |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1156 | assertThat(result, is(true)); |
| 1157 | |
| 1158 | List<Event> reasons = new LinkedList<>(); |
| 1159 | LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link3); |
| 1160 | reasons.add(linkEvent); |
| 1161 | linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link1); |
| 1162 | reasons.add(linkEvent); |
| 1163 | final TopologyEvent event = new TopologyEvent( |
| 1164 | TopologyEvent.Type.TOPOLOGY_CHANGED, |
| 1165 | topology, |
| 1166 | reasons); |
| 1167 | |
| 1168 | //Change Topology : remove link2 and link1 |
| 1169 | Set<TopologyEdge> tempEdges = new HashSet<>(); |
| 1170 | tempEdges.add(new DefaultTopologyEdge(D1, D3, link3)); |
| 1171 | tempEdges.add(new DefaultTopologyEdge(D1, D2, link1)); |
| 1172 | topologyService.changeInTopology(getGraph(null, tempEdges)); |
| 1173 | listener.event(event); |
| 1174 | |
| 1175 | //No path |
| 1176 | assertThat(pathService.paths().size(), is(0)); |
| 1177 | } |
| 1178 | |
| 1179 | /** |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1180 | * Tests resilency when D2 and D3 devices are down. |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1181 | */ |
| 1182 | @Test |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1183 | public void resilencyTest5() { |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1184 | build4RouterTopo(true, false, false, false, 10); |
| 1185 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1186 | List<Constraint> constraints = new LinkedList<Constraint>(); |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1187 | CostConstraint costConstraint = new CostConstraint(COST); |
| 1188 | constraints.add(costConstraint); |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1189 | PceBandwidthConstraint localBwConst = new PceBandwidthConstraint(Bandwidth.bps(10)); |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1190 | constraints.add(localBwConst); |
| 1191 | |
| 1192 | //Setup the path , tunnel created |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1193 | boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", |
| 1194 | constraints, WITH_SIGNALLING, null); |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1195 | assertThat(result, is(true)); |
| 1196 | |
| 1197 | List<Event> reasons = new LinkedList<>(); |
| 1198 | LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2); |
| 1199 | reasons.add(linkEvent); |
| 1200 | linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link1); |
| 1201 | reasons.add(linkEvent); |
| 1202 | linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link3); |
| 1203 | reasons.add(linkEvent); |
| 1204 | linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link4); |
| 1205 | reasons.add(linkEvent); |
| 1206 | |
| 1207 | final TopologyEvent event = new TopologyEvent( |
| 1208 | TopologyEvent.Type.TOPOLOGY_CHANGED, |
| 1209 | topology, |
| 1210 | reasons); |
| 1211 | |
| 1212 | //Change Topology : remove device2, device3 and all links |
| 1213 | Set<TopologyEdge> tempEdges = new HashSet<>(); |
| 1214 | tempEdges.add(new DefaultTopologyEdge(D1, D2, link1)); |
| 1215 | tempEdges.add(new DefaultTopologyEdge(D2, D4, link2)); |
| 1216 | tempEdges.add(new DefaultTopologyEdge(D1, D3, link3)); |
| 1217 | tempEdges.add(new DefaultTopologyEdge(D3, D4, link4)); |
| 1218 | Set<TopologyVertex> tempVertexes = new HashSet<>(); |
| 1219 | tempVertexes.add(D2); |
| 1220 | tempVertexes.add(D3); |
| 1221 | topologyService.changeInTopology(getGraph(tempVertexes, tempEdges)); |
| 1222 | listener.event(event); |
| 1223 | |
| 1224 | //No path |
| 1225 | assertThat(pathService.paths().size(), is(0)); |
| 1226 | } |
| 1227 | |
| 1228 | /** |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1229 | * Tests resilency when egress device is down. |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1230 | */ |
| 1231 | @Test |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1232 | public void resilencyTest6() { |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1233 | build4RouterTopo(true, false, false, false, 10); |
| 1234 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1235 | List<Constraint> constraints = new LinkedList<Constraint>(); |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1236 | CostConstraint costConstraint = new CostConstraint(COST); |
| 1237 | constraints.add(costConstraint); |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1238 | PceBandwidthConstraint localBwConst = new PceBandwidthConstraint(Bandwidth.bps(10)); |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1239 | constraints.add(localBwConst); |
| 1240 | |
| 1241 | //Setup the path , tunnel created |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1242 | boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", |
| 1243 | constraints, WITH_SIGNALLING, null); |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1244 | assertThat(result, is(true)); |
| 1245 | |
| 1246 | List<Event> reasons = new LinkedList<>(); |
| 1247 | LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2); |
| 1248 | reasons.add(linkEvent); |
| 1249 | linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link4); |
| 1250 | reasons.add(linkEvent); |
| 1251 | |
| 1252 | final TopologyEvent event = new TopologyEvent( |
| 1253 | TopologyEvent.Type.TOPOLOGY_CHANGED, |
| 1254 | topology, |
| 1255 | reasons); |
| 1256 | |
| 1257 | //Change Topology : remove device4 , link2 and link4 |
| 1258 | Set<TopologyEdge> tempEdges = new HashSet<>(); |
| 1259 | tempEdges.add(new DefaultTopologyEdge(D2, D4, link2)); |
| 1260 | tempEdges.add(new DefaultTopologyEdge(D3, D4, link4)); |
| 1261 | Set<TopologyVertex> tempVertexes = new HashSet<>(); |
| 1262 | tempVertexes.add(D4); |
| 1263 | topologyService.changeInTopology(getGraph(tempVertexes, tempEdges)); |
| 1264 | listener.event(event); |
| 1265 | |
| 1266 | //No path |
| 1267 | assertThat(pathService.paths().size(), is(0)); |
| 1268 | } |
| 1269 | |
| 1270 | /** |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1271 | * Tests resilency when egress device is down. |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1272 | */ |
| 1273 | @Test |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1274 | public void resilencyTest7() { |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1275 | build4RouterTopo(true, false, false, false, 10); |
| 1276 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1277 | List<Constraint> constraints = new LinkedList<Constraint>(); |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1278 | CostConstraint costConstraint = new CostConstraint(COST); |
| 1279 | constraints.add(costConstraint); |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1280 | PceBandwidthConstraint localBwConst = new PceBandwidthConstraint(Bandwidth.bps(10)); |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1281 | constraints.add(localBwConst); |
| 1282 | |
| 1283 | //Setup the path , tunnel created |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1284 | boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", |
| 1285 | constraints, WITH_SIGNALLING, null); |
| 1286 | assertThat(result, is(true)); |
| 1287 | |
| 1288 | List<Event> reasons = new LinkedList<>(); |
| 1289 | LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2); |
| 1290 | reasons.add(linkEvent); |
| 1291 | linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link4); |
| 1292 | reasons.add(linkEvent); |
| 1293 | |
| 1294 | final TopologyEvent event = new TopologyEvent( |
| 1295 | TopologyEvent.Type.TOPOLOGY_CHANGED, |
| 1296 | topology, |
| 1297 | reasons); |
| 1298 | |
| 1299 | //Change Topology : remove device4 , link2 and link4 |
| 1300 | Set<TopologyEdge> tempEdges = new HashSet<>(); |
| 1301 | tempEdges.add(new DefaultTopologyEdge(D2, D4, link2)); |
| 1302 | tempEdges.add(new DefaultTopologyEdge(D3, D4, link4)); |
| 1303 | Set<TopologyVertex> tempVertexes = new HashSet<>(); |
| 1304 | tempVertexes.add(D4); |
| 1305 | topologyService.changeInTopology(getGraph(tempVertexes, tempEdges)); |
| 1306 | listener.event(event); |
| 1307 | |
| 1308 | //No path |
| 1309 | assertThat(pathService.paths().size(), is(0)); |
| 1310 | } |
| 1311 | |
| 1312 | /** |
| 1313 | * Tests resilency when D2 device is suspended. |
| 1314 | */ |
| 1315 | @Test |
| 1316 | public void resilencyTest8() { |
| 1317 | build4RouterTopo(true, false, false, false, 10); |
| 1318 | |
| 1319 | List<Constraint> constraints = new LinkedList<Constraint>(); |
| 1320 | CostConstraint costConstraint = new CostConstraint(COST); |
| 1321 | constraints.add(costConstraint); |
| 1322 | PceBandwidthConstraint localBwConst = new PceBandwidthConstraint(Bandwidth.bps(10)); |
| 1323 | constraints.add(localBwConst); |
| 1324 | |
| 1325 | //Setup the path , tunnel created |
| 1326 | boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", |
| 1327 | constraints, WITH_SIGNALLING, null); |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1328 | assertThat(result, is(true)); |
| 1329 | |
| 1330 | List<Event> reasons = new LinkedList<>(); |
| 1331 | LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link1); |
| 1332 | reasons.add(linkEvent); |
| 1333 | linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2); |
| 1334 | reasons.add(linkEvent); |
| 1335 | |
| 1336 | final TopologyEvent event = new TopologyEvent( |
| 1337 | TopologyEvent.Type.TOPOLOGY_CHANGED, |
| 1338 | topology, |
| 1339 | reasons); |
| 1340 | |
| 1341 | //Change Topology : remove device2 , link1 and link2 |
| 1342 | Set<TopologyEdge> tempEdges = new HashSet<>(); |
| 1343 | tempEdges.add(new DefaultTopologyEdge(D1, D2, link1)); |
| 1344 | tempEdges.add(new DefaultTopologyEdge(D2, D4, link2)); |
| 1345 | Set<TopologyVertex> tempVertexes = new HashSet<>(); |
| 1346 | tempVertexes.add(D2); |
| 1347 | topologyService.changeInTopology(getGraph(tempVertexes, tempEdges)); |
| 1348 | listener.event(event); |
| 1349 | |
| 1350 | List<Link> links = new LinkedList<>(); |
| 1351 | links.add(link3); |
| 1352 | links.add(link4); |
| 1353 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1354 | Path path = tunnelService.queryAllTunnels().iterator().next().path(); |
| 1355 | |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1356 | //Path is D1-D3-D4 |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1357 | assertThat(path.links(), is(links)); |
| 1358 | assertThat(path.cost(), is((double) 180)); |
| 1359 | } |
| 1360 | |
| 1361 | /** |
| 1362 | * Tests resilency when D2 device availability is changed. |
| 1363 | */ |
| 1364 | @Test |
| 1365 | public void resilencyTest11() { |
| 1366 | build4RouterTopo(true, false, false, false, 10); |
| 1367 | |
| 1368 | List<Constraint> constraints = new LinkedList<Constraint>(); |
| 1369 | CostConstraint costConstraint = new CostConstraint(COST); |
| 1370 | constraints.add(costConstraint); |
| 1371 | PceBandwidthConstraint localBwConst = new PceBandwidthConstraint(Bandwidth.bps(10)); |
| 1372 | constraints.add(localBwConst); |
| 1373 | |
| 1374 | //Setup the path , tunnel created |
| 1375 | boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", |
| 1376 | constraints, WITH_SIGNALLING, null); |
| 1377 | assertThat(result, is(true)); |
| 1378 | |
| 1379 | List<Event> reasons = new LinkedList<>(); |
| 1380 | LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link1); |
| 1381 | reasons.add(linkEvent); |
| 1382 | linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2); |
| 1383 | reasons.add(linkEvent); |
| 1384 | |
| 1385 | final TopologyEvent event = new TopologyEvent( |
| 1386 | TopologyEvent.Type.TOPOLOGY_CHANGED, |
| 1387 | topology, |
| 1388 | reasons); |
| 1389 | |
| 1390 | //Change Topology : remove device2 , link1 and link2 |
| 1391 | Set<TopologyEdge> tempEdges = new HashSet<>(); |
| 1392 | tempEdges.add(new DefaultTopologyEdge(D1, D2, link1)); |
| 1393 | tempEdges.add(new DefaultTopologyEdge(D2, D4, link2)); |
| 1394 | Set<TopologyVertex> tempVertexes = new HashSet<>(); |
| 1395 | tempVertexes.add(D2); |
| 1396 | topologyService.changeInTopology(getGraph(tempVertexes, tempEdges)); |
| 1397 | listener.event(event); |
| 1398 | |
| 1399 | List<Link> links = new LinkedList<>(); |
| 1400 | links.add(link3); |
| 1401 | links.add(link4); |
| 1402 | |
| 1403 | Path path = tunnelService.queryAllTunnels().iterator().next().path(); |
| 1404 | |
| 1405 | //Path is D1-D3-D4 |
| 1406 | assertThat(path.links(), is(links)); |
| 1407 | assertThat(path.cost(), is((double) 180)); |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1408 | } |
| 1409 | |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 1410 | /** |
| 1411 | * Tests resilency when link2 availability is changed. |
| 1412 | */ |
| 1413 | @Test |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1414 | public void resilencyTest12() { |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 1415 | build4RouterTopo(true, false, false, false, 10); |
| 1416 | |
| 1417 | List<Constraint> constraints = new LinkedList<Constraint>(); |
| 1418 | CostConstraint costConstraint = new CostConstraint(COST); |
| 1419 | constraints.add(costConstraint); |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1420 | PceBandwidthConstraint localBwConst = new PceBandwidthConstraint(Bandwidth.bps(10)); |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 1421 | constraints.add(localBwConst); |
| 1422 | |
| 1423 | List<ExplicitPathInfo> explicitPathInfoList = Lists.newLinkedList(); |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1424 | ExplicitPathInfo obj = new ExplicitPathInfo(ExplicitPathInfo.Type.LOOSE, link1); |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 1425 | explicitPathInfoList.add(obj); |
| 1426 | obj = new ExplicitPathInfo(ExplicitPathInfo.Type.STRICT, D2.deviceId()); |
| 1427 | explicitPathInfoList.add(obj); |
| 1428 | |
| 1429 | //Setup the path , tunnel created |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1430 | boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", |
| 1431 | constraints, WITH_SIGNALLING, explicitPathInfoList); |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 1432 | assertThat(result, is(true)); |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 1433 | assertThat(pceStore.getFailedPathInfoCount(), is(0)); |
| 1434 | |
| 1435 | List<Event> reasons = new LinkedList<>(); |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1436 | final LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2); |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 1437 | reasons.add(linkEvent); |
| 1438 | final TopologyEvent event = new TopologyEvent( |
| 1439 | TopologyEvent.Type.TOPOLOGY_CHANGED, |
| 1440 | topology, |
| 1441 | reasons); |
| 1442 | |
| 1443 | //Change Topology : remove link2 |
| 1444 | Set<TopologyEdge> tempEdges = new HashSet<>(); |
| 1445 | tempEdges.add(new DefaultTopologyEdge(D2, D4, link2)); |
| 1446 | topologyService.changeInTopology(getGraph(null, tempEdges)); |
| 1447 | listener.event(event); |
| 1448 | |
| 1449 | List<Link> links = new LinkedList<>(); |
| 1450 | links.add(link3); |
| 1451 | links.add(link4); |
| 1452 | |
| 1453 | //Path fails - no alternate path |
| 1454 | assertThat(pathService.paths().iterator().hasNext(), is(false)); |
| 1455 | } |
| 1456 | |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 1457 | @After |
| 1458 | public void tearDown() { |
| 1459 | pceManager.deactivate(); |
| 1460 | pceManager.pathService = null; |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 1461 | pceManager.tunnelService = null; |
| 1462 | pceManager.coreService = null; |
| 1463 | pceManager.storageService = null; |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 1464 | pceManager.deviceService = null; |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 1465 | pceManager.netCfgService = null; |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 1466 | pceManager.pceStore = null; |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1467 | pceManager.topologyService = null; |
| 1468 | pceManager.mastershipService = null; |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1469 | flowsDownloaded = 0; |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 1470 | } |
| 1471 | |
| 1472 | private class MockTopologyService extends TopologyServiceAdapter { |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1473 | private void changeInTopology(TopologyGraph graphModified) { |
| 1474 | graph = graphModified; |
| 1475 | } |
| 1476 | |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 1477 | @Override |
Ray Milkey | 7483e1b | 2018-02-07 15:43:01 -0800 | [diff] [blame] | 1478 | public Set<Path> getPaths(Topology topology, DeviceId src, DeviceId dst, LinkWeigher weight) { |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 1479 | DefaultTopologyVertex srcV = new DefaultTopologyVertex(src); |
| 1480 | DefaultTopologyVertex dstV = new DefaultTopologyVertex(dst); |
| 1481 | Set<TopologyVertex> vertices = graph.getVertexes(); |
| 1482 | if (!vertices.contains(srcV) || !vertices.contains(dstV)) { |
| 1483 | // src or dst not part of the current graph |
| 1484 | return ImmutableSet.of(); |
| 1485 | } |
| 1486 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1487 | GraphPathSearch.Result<TopologyVertex, TopologyEdge> result = PathComputationTest.graphSearch() |
Ray Milkey | 7483e1b | 2018-02-07 15:43:01 -0800 | [diff] [blame] | 1488 | .search(graph, srcV, dstV, weight, ALL_PATHS); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 1489 | ImmutableSet.Builder<Path> builder = ImmutableSet.builder(); |
| 1490 | for (org.onlab.graph.Path<TopologyVertex, TopologyEdge> path : result.paths()) { |
| 1491 | builder.add(PathComputationTest.networkPath(path)); |
| 1492 | } |
| 1493 | return builder.build(); |
| 1494 | } |
| 1495 | } |
| 1496 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1497 | private TopologyGraph getGraph(Set<TopologyVertex> removedVertex, Set<TopologyEdge> removedEdges) { |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1498 | if (removedVertex != null) { |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1499 | vertexes.remove(removedVertex); |
| 1500 | removedVertex.forEach(new Consumer<TopologyVertex>() { |
| 1501 | @Override |
| 1502 | public void accept(TopologyVertex v) { |
| 1503 | vertexes.remove(v); |
| 1504 | } |
| 1505 | }); |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1506 | } |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 1507 | |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1508 | if (removedEdges != null) { |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1509 | removedEdges.forEach(new Consumer<TopologyEdge>() { |
| 1510 | @Override |
| 1511 | public void accept(TopologyEdge e) { |
| 1512 | edges.remove(e); |
| 1513 | } |
| 1514 | }); |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1515 | } |
| 1516 | |
| 1517 | return new DefaultTopologyGraph(vertexes, edges); |
| 1518 | } |
| 1519 | |
| 1520 | private class MockPathService extends PathServiceAdapter { |
| 1521 | Set<Path> computedPaths; |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 1522 | @Override |
Ray Milkey | 7483e1b | 2018-02-07 15:43:01 -0800 | [diff] [blame] | 1523 | public Set<Path> getPaths(ElementId src, ElementId dst, LinkWeigher weight) { |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 1524 | // If either edge is null, bail with no paths. |
| 1525 | if (src == null || dst == null) { |
| 1526 | return ImmutableSet.of(); |
| 1527 | } |
| 1528 | |
| 1529 | // Otherwise get all paths between the source and destination edge |
| 1530 | // devices. |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1531 | computedPaths = topologyService.getPaths(null, (DeviceId) src, (DeviceId) dst, weight); |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1532 | return computedPaths; |
| 1533 | } |
| 1534 | |
| 1535 | private Set<Path> paths() { |
| 1536 | return computedPaths; |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 1537 | } |
| 1538 | } |
| 1539 | |
| 1540 | private class MockTunnelServiceAdapter extends TunnelServiceAdapter { |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1541 | private HashMap<TunnelId, Tunnel> tunnelIdAsKeyStore = new HashMap<TunnelId, Tunnel>(); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 1542 | private int tunnelIdCounter = 0; |
| 1543 | |
| 1544 | @Override |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1545 | public TunnelId setupTunnel(ApplicationId producerId, ElementId srcElementId, Tunnel tunnel, Path path) { |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 1546 | TunnelId tunnelId = TunnelId.valueOf(String.valueOf(++tunnelIdCounter)); |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1547 | Tunnel tunnelToInsert = new DefaultTunnel(tunnel.providerId(), tunnel.src(), tunnel.dst(), tunnel.type(), |
| 1548 | tunnel.state(), tunnel.groupId(), tunnelId, tunnel.tunnelName(), |
| 1549 | path, tunnel.annotations()); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 1550 | tunnelIdAsKeyStore.put(tunnelId, tunnelToInsert); |
| 1551 | return tunnelId; |
| 1552 | } |
| 1553 | |
| 1554 | @Override |
| 1555 | public void addListener(TunnelListener listener) { |
| 1556 | tunnelListener = listener; |
| 1557 | } |
| 1558 | |
| 1559 | /** |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1560 | * Stimulates the effect of receiving PLSP id and LSP id from protocol PCRpt msg. |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 1561 | */ |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1562 | public TunnelId updateTunnelWithLspIds(Tunnel tunnel, String pLspId, String localLspId, State state) { |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 1563 | TunnelId tunnelId = tunnel.tunnelId(); |
| 1564 | Builder annotationBuilder = DefaultAnnotations.builder(); |
| 1565 | annotationBuilder.putAll(tunnel.annotations()); |
| 1566 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1567 | // PCRpt in response to PCInitate msg will carry PLSP id allocated by PCC. |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 1568 | if (tunnel.annotations().value(PLSP_ID) == null) { |
| 1569 | annotationBuilder.set(PLSP_ID, pLspId); |
| 1570 | } |
| 1571 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1572 | // Signalled LSPs will carry local LSP id allocated by signalling protocol(PCC). |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 1573 | if (tunnel.annotations().value(LOCAL_LSP_ID) == null) { |
| 1574 | annotationBuilder.set(LOCAL_LSP_ID, localLspId); |
| 1575 | } |
| 1576 | SparseAnnotations annotations = annotationBuilder.build(); |
| 1577 | tunnelIdAsKeyStore.remove(tunnelId, tunnel); |
| 1578 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1579 | Tunnel tunnelToInsert = new DefaultTunnel(tunnel.providerId(), tunnel.src(), tunnel.dst(), tunnel.type(), |
| 1580 | state, tunnel.groupId(), tunnelId, tunnel.tunnelName(), |
| 1581 | tunnel.path(), annotations); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 1582 | |
| 1583 | tunnelIdAsKeyStore.put(tunnelId, tunnelToInsert); |
| 1584 | |
| 1585 | return tunnelId; |
| 1586 | } |
| 1587 | |
| 1588 | @Override |
| 1589 | public boolean downTunnel(ApplicationId producerId, TunnelId tunnelId) { |
| 1590 | for (TunnelId tunnelIdKey : tunnelIdAsKeyStore.keySet()) { |
| 1591 | if (tunnelIdKey.equals(tunnelId)) { |
| 1592 | tunnelIdAsKeyStore.remove(tunnelId); |
| 1593 | return true; |
| 1594 | } |
| 1595 | } |
| 1596 | return false; |
| 1597 | } |
| 1598 | |
| 1599 | @Override |
| 1600 | public Tunnel queryTunnel(TunnelId tunnelId) { |
| 1601 | for (TunnelId tunnelIdKey : tunnelIdAsKeyStore.keySet()) { |
| 1602 | if (tunnelIdKey.equals(tunnelId)) { |
| 1603 | return tunnelIdAsKeyStore.get(tunnelId); |
| 1604 | } |
| 1605 | } |
| 1606 | return null; |
| 1607 | } |
| 1608 | |
| 1609 | @Override |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1610 | public Collection<Tunnel> queryTunnel(TunnelEndPoint src, TunnelEndPoint dst) { |
| 1611 | Collection<Tunnel> result = new HashSet<Tunnel>(); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 1612 | Tunnel tunnel = null; |
| 1613 | for (TunnelId tunnelId : tunnelIdAsKeyStore.keySet()) { |
| 1614 | tunnel = tunnelIdAsKeyStore.get(tunnelId); |
| 1615 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1616 | if ((null != tunnel) && (src.equals(tunnel.src())) && (dst.equals(tunnel.dst()))) { |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 1617 | result.add(tunnel); |
| 1618 | } |
| 1619 | } |
| 1620 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1621 | return result.size() == 0 ? Collections.emptySet() : ImmutableSet.copyOf(result); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 1622 | } |
| 1623 | |
| 1624 | @Override |
| 1625 | public Collection<Tunnel> queryTunnel(Tunnel.Type type) { |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1626 | Collection<Tunnel> result = new HashSet<Tunnel>(); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 1627 | |
| 1628 | for (TunnelId tunnelId : tunnelIdAsKeyStore.keySet()) { |
| 1629 | result.add(tunnelIdAsKeyStore.get(tunnelId)); |
| 1630 | } |
| 1631 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1632 | return result.size() == 0 ? Collections.emptySet() : ImmutableSet.copyOf(result); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 1633 | } |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1634 | |
| 1635 | @Override |
| 1636 | public Collection<Tunnel> queryAllTunnels() { |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1637 | Collection<Tunnel> result = new HashSet<Tunnel>(); |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1638 | |
| 1639 | for (TunnelId tunnelId : tunnelIdAsKeyStore.keySet()) { |
| 1640 | result.add(tunnelIdAsKeyStore.get(tunnelId)); |
| 1641 | } |
| 1642 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1643 | return result.size() == 0 ? Collections.emptySet() : ImmutableSet.copyOf(result); |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1644 | } |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 1645 | |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1646 | @Override |
| 1647 | public Iterable<Tunnel> getTunnels(DeviceId deviceId) { |
| 1648 | List<Tunnel> tunnelList = new LinkedList<>(); |
| 1649 | |
| 1650 | for (Tunnel t : tunnelIdAsKeyStore.values()) { |
| 1651 | for (Link l : t.path().links()) { |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 1652 | if (l.src().deviceId().equals(deviceId) || l.dst().deviceId().equals(deviceId)) { |
Priyanka B | 3f92c5a | 2016-05-27 10:14:16 +0530 | [diff] [blame] | 1653 | tunnelList.add(t); |
| 1654 | break; |
| 1655 | } |
| 1656 | } |
| 1657 | } |
| 1658 | return tunnelList; |
| 1659 | } |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 1660 | } |
| 1661 | |
| 1662 | public static class MockCoreService extends CoreServiceAdapter { |
| 1663 | |
| 1664 | @Override |
| 1665 | public ApplicationId registerApplication(String name) { |
| 1666 | return new DefaultApplicationId(1, name); |
| 1667 | } |
| 1668 | |
| 1669 | @Override |
| 1670 | public IdGenerator getIdGenerator(String topic) { |
| 1671 | return new IdGenerator() { |
| 1672 | private AtomicLong counter = new AtomicLong(0); |
| 1673 | |
| 1674 | @Override |
| 1675 | public long getNewId() { |
| 1676 | return counter.getAndIncrement(); |
| 1677 | } |
| 1678 | }; |
| 1679 | } |
| 1680 | } |
| 1681 | |
| 1682 | private class MockDevice extends DefaultDevice { |
| 1683 | MockDevice(DeviceId id, Annotations annotations) { |
| 1684 | super(null, id, null, null, null, null, null, null, annotations); |
| 1685 | } |
| 1686 | } |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 1687 | } |