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