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