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