Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [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 | */ |
| 16 | package org.onosproject.provider.pcep.tunnel.impl; |
| 17 | |
| 18 | import static org.hamcrest.MatcherAssert.assertThat; |
| 19 | import static org.hamcrest.core.Is.is; |
| 20 | import static org.onosproject.incubator.net.tunnel.Tunnel.Type.MPLS; |
| 21 | import static org.onosproject.incubator.net.tunnel.Tunnel.State.INIT; |
| 22 | import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.BANDWIDTH; |
| 23 | import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.LOCAL_LSP_ID; |
| 24 | import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.LSP_SIG_TYPE; |
| 25 | import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.PCC_TUNNEL_ID; |
| 26 | import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.PLSP_ID; |
Priyanka B | 413fbe8 | 2016-05-26 11:44:45 +0530 | [diff] [blame] | 27 | import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.DELEGATE; |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 28 | import static org.onosproject.provider.pcep.tunnel.impl.LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR; |
Avantika-Huawei | 7f7376a | 2016-05-11 17:07:50 +0530 | [diff] [blame] | 29 | import static org.onosproject.pcep.controller.PcepSyncStatus.SYNCED; |
Priyanka B | 413fbe8 | 2016-05-26 11:44:45 +0530 | [diff] [blame] | 30 | import static org.onosproject.net.Device.Type.ROUTER; |
| 31 | import static org.onosproject.net.MastershipRole.MASTER; |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 32 | |
| 33 | import java.io.IOException; |
| 34 | import java.util.Collection; |
| 35 | import java.util.Collections; |
| 36 | import java.util.HashMap; |
| 37 | import java.util.HashSet; |
Priyanka B | 413fbe8 | 2016-05-26 11:44:45 +0530 | [diff] [blame] | 38 | import java.util.LinkedList; |
| 39 | import java.util.List; |
| 40 | import java.util.concurrent.TimeUnit; |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 41 | |
| 42 | import org.jboss.netty.buffer.ChannelBuffer; |
| 43 | import org.jboss.netty.buffer.ChannelBuffers; |
| 44 | import org.junit.After; |
| 45 | import org.junit.Before; |
| 46 | import org.junit.Test; |
Priyanka B | 413fbe8 | 2016-05-26 11:44:45 +0530 | [diff] [blame] | 47 | import org.onlab.packet.ChassisId; |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 48 | import org.onlab.packet.IpAddress; |
| 49 | import org.onosproject.cfg.ComponentConfigAdapter; |
| 50 | import org.onosproject.core.ApplicationId; |
| 51 | import org.onosproject.incubator.net.tunnel.DefaultTunnel; |
| 52 | import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint; |
| 53 | import org.onosproject.incubator.net.tunnel.Tunnel; |
Priyanka B | 413fbe8 | 2016-05-26 11:44:45 +0530 | [diff] [blame] | 54 | import org.onosproject.incubator.net.tunnel.Tunnel.Type; |
| 55 | import org.onosproject.incubator.net.tunnel.TunnelAdminService; |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 56 | import org.onosproject.incubator.net.tunnel.TunnelDescription; |
| 57 | import org.onosproject.incubator.net.tunnel.TunnelEndPoint; |
| 58 | import org.onosproject.incubator.net.tunnel.TunnelId; |
| 59 | import org.onosproject.incubator.net.tunnel.TunnelName; |
| 60 | import org.onosproject.incubator.net.tunnel.TunnelProvider; |
| 61 | import org.onosproject.incubator.net.tunnel.TunnelProviderService; |
| 62 | import org.onosproject.incubator.net.tunnel.Tunnel.State; |
Priyanka B | 413fbe8 | 2016-05-26 11:44:45 +0530 | [diff] [blame] | 63 | import org.onosproject.mastership.MastershipServiceAdapter; |
| 64 | import org.onosproject.net.AnnotationKeys; |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 65 | import org.onosproject.net.DefaultAnnotations; |
Priyanka B | 413fbe8 | 2016-05-26 11:44:45 +0530 | [diff] [blame] | 66 | import org.onosproject.net.DefaultDevice; |
| 67 | import org.onosproject.net.Device; |
| 68 | import org.onosproject.net.DeviceId; |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 69 | import org.onosproject.net.ElementId; |
Priyanka B | 413fbe8 | 2016-05-26 11:44:45 +0530 | [diff] [blame] | 70 | import org.onosproject.net.MastershipRole; |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 71 | import org.onosproject.net.Path; |
| 72 | import org.onosproject.net.SparseAnnotations; |
Priyanka B | 413fbe8 | 2016-05-26 11:44:45 +0530 | [diff] [blame] | 73 | import org.onosproject.net.device.DeviceServiceAdapter; |
| 74 | import org.onosproject.net.provider.ProviderId; |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 75 | import org.onosproject.pcepio.exceptions.PcepOutOfBoundMessageException; |
| 76 | import org.onosproject.pcepio.exceptions.PcepParseException; |
| 77 | import org.onosproject.pcepio.protocol.PcepFactories; |
| 78 | import org.onosproject.pcepio.protocol.PcepMessage; |
| 79 | import org.onosproject.pcepio.protocol.PcepMessageReader; |
Priyanka B | 413fbe8 | 2016-05-26 11:44:45 +0530 | [diff] [blame] | 80 | import org.onosproject.pcepio.protocol.PcepVersion; |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 81 | import org.onosproject.pcep.controller.ClientCapability; |
Priyanka B | 413fbe8 | 2016-05-26 11:44:45 +0530 | [diff] [blame] | 82 | import org.onosproject.pcep.controller.LspKey; |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 83 | import org.onosproject.pcep.controller.PccId; |
| 84 | |
| 85 | import com.google.common.collect.ImmutableSet; |
| 86 | |
| 87 | /** |
| 88 | * Tests handling of PCEP report message. |
| 89 | */ |
| 90 | public class PcepTunnelAddedTest { |
| 91 | |
Priyanka B | 413fbe8 | 2016-05-26 11:44:45 +0530 | [diff] [blame] | 92 | public static final String PROVIDER_ID = "org.onosproject.provider.tunnel.pcep"; |
| 93 | public static final String UNKOWN = "UNKOWN"; |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 94 | PcepTunnelProvider tunnelProvider = new PcepTunnelProvider(); |
| 95 | private final MockTunnelProviderRegistryAdapter registry = new MockTunnelProviderRegistryAdapter(); |
| 96 | private final PcepClientControllerAdapter controller = new PcepClientControllerAdapter(); |
| 97 | private final PcepControllerAdapter ctl = new PcepControllerAdapter(); |
| 98 | private final PcepTunnelApiMapper pcepTunnelAPIMapper = new PcepTunnelApiMapper(); |
| 99 | private final MockTunnelServiceAdapter tunnelService = new MockTunnelServiceAdapter(); |
Priyanka B | 413fbe8 | 2016-05-26 11:44:45 +0530 | [diff] [blame] | 100 | public final MockDeviceService deviceService = new MockDeviceService(); |
| 101 | private final MockMasterShipService masterShipService = new MockMasterShipService(); |
| 102 | private final MockTunnelAdminService tunnelAdminService = new MockTunnelAdminService(); |
| 103 | |
| 104 | private class MockTunnelAdminService implements TunnelAdminService { |
| 105 | |
| 106 | @Override |
| 107 | public void removeTunnel(TunnelId tunnelId) { |
| 108 | // TODO Auto-generated method stub |
| 109 | } |
| 110 | |
| 111 | @Override |
| 112 | public void removeTunnels(TunnelEndPoint src, TunnelEndPoint dst, ProviderId producerName) { |
| 113 | // TODO Auto-generated method stub |
| 114 | } |
| 115 | |
| 116 | @Override |
| 117 | public void removeTunnels(TunnelEndPoint src, TunnelEndPoint dst, Type type, ProviderId producerName) { |
| 118 | // TODO Auto-generated method stub |
| 119 | } |
| 120 | |
| 121 | @Override |
| 122 | public void updateTunnel(Tunnel tunnel, Path path) { |
| 123 | if (tunnelService.tunnelIdAsKeyStore.containsKey(tunnel.tunnelId())) { |
| 124 | tunnelService.tunnelIdAsKeyStore.replace(tunnel.tunnelId(), tunnel); |
| 125 | } |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | private class MockMasterShipService extends MastershipServiceAdapter { |
| 130 | boolean set; |
| 131 | |
| 132 | private void setMaster(boolean isMaster) { |
| 133 | this.set = isMaster; |
| 134 | } |
| 135 | |
| 136 | @Override |
| 137 | public MastershipRole getLocalRole(DeviceId deviceId) { |
| 138 | return set ? MastershipRole.MASTER : MastershipRole.STANDBY; |
| 139 | } |
| 140 | |
| 141 | @Override |
| 142 | public boolean isLocalMaster(DeviceId deviceId) { |
| 143 | return getLocalRole(deviceId) == MASTER; |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | private class MockDeviceService extends DeviceServiceAdapter { |
| 148 | List<Device> devices = new LinkedList<>(); |
| 149 | |
| 150 | private void addDevice(Device dev) { |
| 151 | devices.add(dev); |
| 152 | } |
| 153 | |
| 154 | @Override |
| 155 | public Iterable<Device> getAvailableDevices() { |
| 156 | return devices; |
| 157 | } |
| 158 | } |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 159 | |
| 160 | private class MockTunnelProviderRegistryAdapter extends TunnelProviderRegistryAdapter { |
| 161 | public long tunnelIdCounter; |
| 162 | |
| 163 | @Override |
| 164 | public TunnelProviderService register(TunnelProvider provider) { |
| 165 | this.provider = provider; |
| 166 | return new TestProviderService(); |
| 167 | } |
| 168 | |
| 169 | private class TestProviderService implements TunnelProviderService { |
| 170 | |
| 171 | @Override |
| 172 | public TunnelProvider provider() { |
| 173 | return null; |
| 174 | } |
| 175 | |
| 176 | @Override |
| 177 | public TunnelId tunnelAdded(TunnelDescription tunnel) { |
Priyanka B | 413fbe8 | 2016-05-26 11:44:45 +0530 | [diff] [blame] | 178 | TunnelId id = TunnelId.valueOf(String.valueOf(++tunnelIdCounter)); |
| 179 | Tunnel storedTunnel = new DefaultTunnel(ProviderId.NONE, |
| 180 | tunnel.src(), tunnel.dst(), |
| 181 | tunnel.type(), |
| 182 | tunnel.groupId(), |
| 183 | id, |
| 184 | tunnel.tunnelName(), |
| 185 | tunnel.path(), |
| 186 | tunnel.resource(), |
| 187 | tunnel.annotations()); |
| 188 | tunnelService.tunnelIdAsKeyStore.put(id, storedTunnel); |
| 189 | return id; |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | @Override |
| 193 | public TunnelId tunnelAdded(TunnelDescription tunnel, State state) { |
Priyanka B | 413fbe8 | 2016-05-26 11:44:45 +0530 | [diff] [blame] | 194 | TunnelId id = TunnelId.valueOf(String.valueOf(++tunnelIdCounter)); |
| 195 | Tunnel storedTunnel = new DefaultTunnel(ProviderId.NONE, |
| 196 | tunnel.src(), tunnel.dst(), |
| 197 | tunnel.type(), |
| 198 | tunnel.groupId(), |
| 199 | id, |
| 200 | tunnel.tunnelName(), |
| 201 | tunnel.path(), |
| 202 | tunnel.resource(), |
| 203 | tunnel.annotations()); |
| 204 | tunnelService.tunnelIdAsKeyStore.put(id, storedTunnel); |
| 205 | return id; |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | @Override |
| 209 | public void tunnelRemoved(TunnelDescription tunnel) { |
| 210 | } |
| 211 | |
| 212 | @Override |
| 213 | public void tunnelUpdated(TunnelDescription tunnel) { |
| 214 | } |
| 215 | |
| 216 | @Override |
| 217 | public void tunnelUpdated(TunnelDescription tunnel, State state) { |
| 218 | } |
| 219 | |
| 220 | @Override |
| 221 | public Tunnel tunnelQueryById(TunnelId tunnelId) { |
| 222 | return null; |
| 223 | } |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | private class MockTunnelServiceAdapter extends TunnelServiceAdapter { |
| 228 | private HashMap<TunnelId, Tunnel> tunnelIdAsKeyStore = new HashMap<>(); |
| 229 | private int tunnelIdCounter = 0; |
| 230 | |
| 231 | @Override |
| 232 | public TunnelId setupTunnel(ApplicationId producerId, ElementId srcElementId, Tunnel tunnel, Path path) { |
| 233 | TunnelId tunnelId = TunnelId.valueOf(String.valueOf(++tunnelIdCounter)); |
| 234 | tunnelIdAsKeyStore.put(tunnelId, tunnel); |
| 235 | return tunnelId; |
| 236 | } |
| 237 | |
| 238 | @Override |
| 239 | public Collection<Tunnel> queryTunnel(TunnelEndPoint src, TunnelEndPoint dst) { |
| 240 | Collection<Tunnel> result = new HashSet<>(); |
| 241 | Tunnel tunnel = null; |
| 242 | for (TunnelId tunnelId : tunnelIdAsKeyStore.keySet()) { |
| 243 | tunnel = tunnelIdAsKeyStore.get(tunnelId); |
| 244 | |
| 245 | if ((null != tunnel) && (src.equals(tunnel.src())) && (dst.equals(tunnel.dst()))) { |
| 246 | result.add(tunnel); |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | return result.isEmpty() ? Collections.emptySet() : ImmutableSet.copyOf(result); |
| 251 | } |
| 252 | |
| 253 | @Override |
| 254 | public Collection<Tunnel> queryAllTunnels() { |
| 255 | Collection<Tunnel> result = new HashSet<>(); |
| 256 | |
| 257 | for (TunnelId tunnelId : tunnelIdAsKeyStore.keySet()) { |
| 258 | result.add(tunnelIdAsKeyStore.get(tunnelId)); |
| 259 | } |
| 260 | |
| 261 | return result.isEmpty() ? Collections.emptySet() : ImmutableSet.copyOf(result); |
| 262 | |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | @Before |
| 267 | public void preSetup() { |
| 268 | tunnelProvider.tunnelProviderRegistry = registry; |
| 269 | tunnelProvider.pcepClientController = controller; |
| 270 | tunnelProvider.controller = ctl; |
Priyanka B | 413fbe8 | 2016-05-26 11:44:45 +0530 | [diff] [blame] | 271 | tunnelProvider.deviceService = deviceService; |
| 272 | tunnelProvider.mastershipService = masterShipService; |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 273 | tunnelProvider.pcepTunnelApiMapper = pcepTunnelAPIMapper; |
| 274 | tunnelProvider.cfgService = new ComponentConfigAdapter(); |
| 275 | tunnelProvider.tunnelService = tunnelService; |
Priyanka B | 413fbe8 | 2016-05-26 11:44:45 +0530 | [diff] [blame] | 276 | tunnelProvider.tunnelAdminService = tunnelAdminService; |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 277 | tunnelProvider.service = registry.register(tunnelProvider); |
| 278 | tunnelProvider.activate(); |
| 279 | } |
| 280 | |
| 281 | /** |
| 282 | * Tests PCRpt msg with sync flag set. |
| 283 | */ |
| 284 | @Test |
| 285 | public void tunnelProviderAddedTest1() throws PcepParseException, PcepOutOfBoundMessageException { |
| 286 | byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x84, |
| 287 | 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP object |
| 288 | 0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV |
| 289 | 0x00, 0x00, 0x00, 0x02, |
| 290 | 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x03, //LSP object |
| 291 | 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv |
| 292 | 0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV |
| 293 | 0x01, 0x01, 0x01, 0x01, |
| 294 | 0x00, 0x01, 0x00, 0x01, |
| 295 | 0x01, 0x01, 0x01, 0x01, |
| 296 | 0x05, 0x05, 0x05, 0x05, |
| 297 | |
| 298 | 0x07, 0x10, 0x00, 0x14, //ERO object |
| 299 | 0x01, 0x08, (byte) 0x01, 0x01, 0x01, 0x01, 0x04, 0x00, // ERO IPv4 sub objects |
| 300 | 0x01, 0x08, (byte) 0x05, 0x05, 0x05, 0x05, 0x04, 0x00, |
| 301 | |
| 302 | 0x08, 0x10, 0x00, 0x34, //RRO object |
| 303 | 0x01, 0x08, 0x11, 0x01, 0x01, 0x01, 0x04, 0x00, // RRO IPv4 sub objects |
| 304 | 0x01, 0x08, 0x11, 0x01, 0x01, 0x02, 0x04, 0x00, |
| 305 | 0x01, 0x08, 0x06, 0x06, 0x06, 0x06, 0x04, 0x00, |
| 306 | 0x01, 0x08, 0x12, 0x01, 0x01, 0x02, 0x04, 0x00, |
| 307 | 0x01, 0x08, 0x12, 0x01, 0x01, 0x01, 0x04, 0x00, |
| 308 | 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00 |
| 309 | }; |
| 310 | |
| 311 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 312 | buffer.writeBytes(reportMsg); |
| 313 | |
| 314 | PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); |
| 315 | PcepMessage message = reader.readFrom(buffer); |
Priyanka B | 413fbe8 | 2016-05-26 11:44:45 +0530 | [diff] [blame] | 316 | |
| 317 | DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder(); |
| 318 | newBuilder.set(PcepTunnelProvider.LSRID, "1.1.1.1"); |
| 319 | newBuilder.set(AnnotationKeys.TYPE, "L3"); |
| 320 | Device device = new DefaultDevice(ProviderId.NONE, DeviceId.deviceId("1.1.1.1"), ROUTER, |
| 321 | UNKOWN, UNKOWN, UNKOWN, |
| 322 | UNKOWN, new ChassisId(), |
| 323 | newBuilder.build()); |
| 324 | |
| 325 | deviceService.addDevice(device); |
| 326 | controller.getClient(PccId.pccId(IpAddress.valueOf("1.1.1.1"))).setCapability( |
| 327 | new ClientCapability(true, true, true, true, true)); |
| 328 | masterShipService.setMaster(true); |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 329 | controller.processClientMessage(PccId.pccId(IpAddress.valueOf("1.1.1.1")), message); |
| 330 | |
| 331 | assertThat(registry.tunnelIdCounter, is((long) 1)); |
| 332 | } |
| 333 | |
| 334 | /** |
| 335 | * Tests updating an existing tunnel on receiving asynchronous PCRpt msg, |
| 336 | * i.e. without any SRP id. |
| 337 | */ |
| 338 | @Test |
| 339 | public void tunnelProviderAddedTest2() throws PcepParseException, PcepOutOfBoundMessageException { |
| 340 | byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x50, |
| 341 | 0x21, 0x10, 0x00, 0x14, //SRP object |
| 342 | 0x00, 0x00, 0x00, 0x00, |
| 343 | 0x00, 0x00, 0x00, 0x00, |
| 344 | 0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV |
| 345 | 0x00, 0x00, 0x00, 0x02, |
| 346 | 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x19, //LSP object |
| 347 | 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path TLV |
| 348 | 0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV |
| 349 | 0x4e, 0x1f, 0x04, 0x00, |
| 350 | 0x00, 0x01, 0x00, 0x01, |
| 351 | 0x4e, 0x1f, 0x04, 0x00, |
| 352 | 0x4e, 0x20, 0x04, 0x00, |
| 353 | 0x07, 0x10, 0x00, 0x14, //ERO object |
| 354 | 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, // ERO IPv4 sub objects |
| 355 | 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00, |
| 356 | }; |
| 357 | |
| 358 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 359 | buffer.writeBytes(reportMsg); |
| 360 | |
| 361 | PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); |
| 362 | PcepMessage message = reader.readFrom(buffer); |
| 363 | |
| 364 | // create an existing tunnel. |
| 365 | IpTunnelEndPoint tunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(0x4e1f0400)); |
| 366 | IpTunnelEndPoint tunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(0x4e200400)); |
| 367 | |
| 368 | SparseAnnotations annotations = DefaultAnnotations.builder() |
| 369 | .set(BANDWIDTH, (new Integer(1)).toString()) |
| 370 | .set(LSP_SIG_TYPE, WITHOUT_SIGNALLING_AND_WITHOUT_SR.name()) |
| 371 | .set(PCC_TUNNEL_ID, String.valueOf(1)) |
| 372 | .set(PLSP_ID, String.valueOf(1)) |
Priyanka B | 413fbe8 | 2016-05-26 11:44:45 +0530 | [diff] [blame] | 373 | .set(LOCAL_LSP_ID, String.valueOf(1)) |
| 374 | .set(DELEGATE, String.valueOf("true")) |
| 375 | .build(); |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 376 | |
| 377 | Tunnel tunnel = new DefaultTunnel(null, tunnelEndPointSrc, tunnelEndPointDst, MPLS, INIT, null, null, |
| 378 | TunnelName.tunnelName("T123"), null, annotations); |
| 379 | tunnelService.setupTunnel(null, null, tunnel, null); |
| 380 | |
| 381 | PccId pccId = PccId.pccId(IpAddress.valueOf(0x4e1f0400)); |
Priyanka B | 413fbe8 | 2016-05-26 11:44:45 +0530 | [diff] [blame] | 382 | PcepClientAdapter pc = new PcepClientAdapter(); |
| 383 | pc.init(pccId, PcepVersion.PCEP_1); |
| 384 | masterShipService.setMaster(true); |
| 385 | controller.getClient(pccId).setLspAndDelegationInfo(new LspKey(1, (short) 1), true); |
| 386 | controller.getClient(pccId).setCapability(new ClientCapability(true, true, true, true, true)); |
Avantika-Huawei | 7f7376a | 2016-05-11 17:07:50 +0530 | [diff] [blame] | 387 | controller.getClient(pccId).setLspDbSyncStatus(SYNCED); |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 388 | |
| 389 | // Process update message. |
| 390 | controller.processClientMessage(pccId, message); |
| 391 | assertThat(tunnelService.queryAllTunnels().size(), is(1)); |
| 392 | } |
| 393 | |
| 394 | /** |
| 395 | * Tests adding a new tunnel on receiving asynchronous PCRpt msg, |
| 396 | * i.e. without any SRP id. |
| 397 | */ |
| 398 | @Test |
| 399 | public void tunnelProviderAddedTest3() throws PcepParseException, PcepOutOfBoundMessageException { |
| 400 | byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x84, |
| 401 | 0x21, 0x10, 0x00, 0x14, //SRP object |
| 402 | 0x00, 0x00, 0x00, 0x00, |
| 403 | 0x00, 0x00, 0x00, 0x00, |
| 404 | 0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV |
| 405 | 0x00, 0x00, 0x00, 0x02, |
Avantika-Huawei | d1e36bd | 2016-05-26 12:47:16 +0530 | [diff] [blame^] | 406 | 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x1B, // LSP object |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 407 | 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, // symbolic path TLV |
| 408 | 0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV |
| 409 | 0x01, 0x01, 0x01, 0x01, |
| 410 | 0x00, 0x01, 0x00, 0x01, |
| 411 | 0x01, 0x01, 0x01, 0x01, |
| 412 | 0x05, 0x05, 0x05, 0x05, |
| 413 | |
| 414 | 0x07, 0x10, 0x00, 0x14, //ERO object |
| 415 | 0x01, 0x08, (byte) 0x01, 0x01, 0x01, 0x01, 0x04, 0x00, // ERO IPv4 sub objects |
| 416 | 0x01, 0x08, (byte) 0x05, 0x05, 0x05, 0x05, 0x04, 0x00, |
| 417 | |
| 418 | 0x08, 0x10, 0x00, 0x34, //RRO object |
| 419 | 0x01, 0x08, 0x11, 0x01, 0x01, 0x01, 0x04, 0x00, // RRO IPv4 sub objects |
| 420 | 0x01, 0x08, 0x11, 0x01, 0x01, 0x02, 0x04, 0x00, |
| 421 | 0x01, 0x08, 0x06, 0x06, 0x06, 0x06, 0x04, 0x00, |
| 422 | 0x01, 0x08, 0x12, 0x01, 0x01, 0x02, 0x04, 0x00, |
| 423 | 0x01, 0x08, 0x12, 0x01, 0x01, 0x01, 0x04, 0x00, |
| 424 | 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00 |
| 425 | }; |
| 426 | |
| 427 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 428 | buffer.writeBytes(reportMsg); |
| 429 | |
| 430 | PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); |
| 431 | PcepMessage message = reader.readFrom(buffer); |
| 432 | |
Priyanka B | 413fbe8 | 2016-05-26 11:44:45 +0530 | [diff] [blame] | 433 | DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder(); |
| 434 | newBuilder.set(PcepTunnelProvider.LSRID, "1.1.1.1"); |
| 435 | newBuilder.set(AnnotationKeys.TYPE, "L3"); |
| 436 | Device device = new DefaultDevice(ProviderId.NONE, DeviceId.deviceId("1.1.1.1"), ROUTER, |
| 437 | UNKOWN, UNKOWN, UNKOWN, |
| 438 | UNKOWN, new ChassisId(), |
| 439 | newBuilder.build()); |
| 440 | |
| 441 | deviceService.addDevice(device); |
| 442 | |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 443 | PccId pccId = PccId.pccId(IpAddress.valueOf("1.1.1.1")); |
Avantika-Huawei | 7f7376a | 2016-05-11 17:07:50 +0530 | [diff] [blame] | 444 | controller.getClient(pccId).setLspDbSyncStatus(SYNCED); |
Priyanka B | 413fbe8 | 2016-05-26 11:44:45 +0530 | [diff] [blame] | 445 | controller.getClient(pccId).setCapability(new ClientCapability(true, true, true, true, true)); |
| 446 | |
| 447 | PcepClientAdapter pc = new PcepClientAdapter(); |
| 448 | pc.init(pccId, PcepVersion.PCEP_1); |
| 449 | controller.getClient(pccId).setLspAndDelegationInfo(new LspKey(1, (short) 1), true); |
| 450 | masterShipService.setMaster(true); |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 451 | controller.processClientMessage(pccId, message); |
| 452 | |
| 453 | assertThat(registry.tunnelIdCounter, is((long) 1)); |
| 454 | } |
| 455 | |
Avantika-Huawei | 7f7376a | 2016-05-11 17:07:50 +0530 | [diff] [blame] | 456 | /** |
Priyanka B | 413fbe8 | 2016-05-26 11:44:45 +0530 | [diff] [blame] | 457 | * Tests PCRpt msg with D flag set and delegated to non-master. |
| 458 | * |
| 459 | * @throws InterruptedException while waiting for delay |
| 460 | */ |
| 461 | @Test |
| 462 | public void tunnelProviderAddedTest4() throws PcepParseException, PcepOutOfBoundMessageException, |
| 463 | InterruptedException { |
| 464 | byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x84, |
| 465 | 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP object |
| 466 | 0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV |
| 467 | 0x00, 0x00, 0x00, 0x02, |
| 468 | 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x02, //LSP object |
| 469 | 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv |
| 470 | 0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV |
| 471 | 0x01, 0x01, 0x01, 0x01, |
| 472 | 0x00, 0x01, 0x00, 0x01, |
| 473 | 0x01, 0x01, 0x01, 0x01, |
| 474 | 0x05, 0x05, 0x05, 0x05, |
| 475 | |
| 476 | 0x07, 0x10, 0x00, 0x14, //ERO object |
| 477 | 0x01, 0x08, (byte) 0x01, 0x01, 0x01, 0x01, 0x04, 0x00, // ERO IPv4 sub objects |
| 478 | 0x01, 0x08, (byte) 0x05, 0x05, 0x05, 0x05, 0x04, 0x00, |
| 479 | |
| 480 | 0x08, 0x10, 0x00, 0x34, //RRO object |
| 481 | 0x01, 0x08, 0x11, 0x01, 0x01, 0x01, 0x04, 0x00, // RRO IPv4 sub objects |
| 482 | 0x01, 0x08, 0x11, 0x01, 0x01, 0x02, 0x04, 0x00, |
| 483 | 0x01, 0x08, 0x06, 0x06, 0x06, 0x06, 0x04, 0x00, |
| 484 | 0x01, 0x08, 0x12, 0x01, 0x01, 0x02, 0x04, 0x00, |
| 485 | 0x01, 0x08, 0x12, 0x01, 0x01, 0x01, 0x04, 0x00, |
| 486 | 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00 |
| 487 | }; |
| 488 | |
| 489 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 490 | buffer.writeBytes(reportMsg); |
| 491 | |
| 492 | PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); |
| 493 | PcepMessage message = reader.readFrom(buffer); |
| 494 | |
| 495 | //PCC 1.1.1.1, D=0, ONOS as master |
| 496 | masterShipService.setMaster(true); |
| 497 | DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder(); |
| 498 | newBuilder.set(PcepTunnelProvider.LSRID, "1.1.1.1"); |
| 499 | newBuilder.set(AnnotationKeys.TYPE, "L3"); |
| 500 | Device device = new DefaultDevice(ProviderId.NONE, DeviceId.deviceId("1.1.1.1"), ROUTER, |
| 501 | UNKOWN, UNKOWN, UNKOWN, |
| 502 | UNKOWN, new ChassisId(), |
| 503 | newBuilder.build()); |
| 504 | |
| 505 | deviceService.addDevice(device); |
| 506 | controller.getClient(PccId.pccId(IpAddress.valueOf("1.1.1.1"))).setCapability( |
| 507 | new ClientCapability(true, true, true, true, true)); |
| 508 | controller.processClientMessage(PccId.pccId(IpAddress.valueOf("1.1.1.1")), message); |
| 509 | assertThat(tunnelService.tunnelIdAsKeyStore.values().iterator().next().annotations().value(DELEGATE), |
| 510 | is("false")); |
| 511 | |
| 512 | //PCC 1.1.1.1, D=1, non-master |
| 513 | masterShipService.setMaster(false); |
| 514 | |
| 515 | reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x84, |
| 516 | 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP object |
| 517 | 0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV |
| 518 | 0x00, 0x00, 0x00, 0x02, |
| 519 | 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x03, //LSP object |
| 520 | 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv |
| 521 | 0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV |
| 522 | 0x01, 0x01, 0x01, 0x01, |
| 523 | 0x00, 0x01, 0x00, 0x01, |
| 524 | 0x01, 0x01, 0x01, 0x01, |
| 525 | 0x05, 0x05, 0x05, 0x05, |
| 526 | |
| 527 | 0x07, 0x10, 0x00, 0x14, //ERO object |
| 528 | 0x01, 0x08, (byte) 0x01, 0x01, 0x01, 0x01, 0x04, 0x00, // ERO IPv4 sub objects |
| 529 | 0x01, 0x08, (byte) 0x05, 0x05, 0x05, 0x05, 0x04, 0x00, |
| 530 | |
| 531 | 0x08, 0x10, 0x00, 0x34, //RRO object |
| 532 | 0x01, 0x08, 0x11, 0x01, 0x01, 0x01, 0x04, 0x00, // RRO IPv4 sub objects |
| 533 | 0x01, 0x08, 0x11, 0x01, 0x01, 0x02, 0x04, 0x00, |
| 534 | 0x01, 0x08, 0x06, 0x06, 0x06, 0x06, 0x04, 0x00, |
| 535 | 0x01, 0x08, 0x12, 0x01, 0x01, 0x02, 0x04, 0x00, |
| 536 | 0x01, 0x08, 0x12, 0x01, 0x01, 0x01, 0x04, 0x00, |
| 537 | 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00 |
| 538 | }; |
| 539 | |
| 540 | buffer = ChannelBuffers.dynamicBuffer(); |
| 541 | buffer.writeBytes(reportMsg); |
| 542 | |
| 543 | reader = PcepFactories.getGenericReader(); |
| 544 | message = reader.readFrom(buffer); |
| 545 | |
| 546 | controller.processClientMessage(PccId.pccId(IpAddress.valueOf("1.1.1.1")), message); |
| 547 | TimeUnit.MILLISECONDS.sleep(4000); |
| 548 | assertThat(registry.tunnelIdCounter, is((long) 1)); |
| 549 | assertThat(tunnelService.tunnelIdAsKeyStore.values().iterator().next().annotations().value(DELEGATE), |
| 550 | is("true")); |
| 551 | } |
| 552 | |
| 553 | /** |
Avantika-Huawei | d1e36bd | 2016-05-26 12:47:16 +0530 | [diff] [blame^] | 554 | * Tests adding PCC Init LSP after LSP DB sync is over. |
Avantika-Huawei | 7f7376a | 2016-05-11 17:07:50 +0530 | [diff] [blame] | 555 | */ |
| 556 | @Test |
Avantika-Huawei | d1e36bd | 2016-05-26 12:47:16 +0530 | [diff] [blame^] | 557 | public void tunnelProviderAddedTest5() throws PcepParseException, PcepOutOfBoundMessageException { |
| 558 | byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x84, |
Avantika-Huawei | 7f7376a | 2016-05-11 17:07:50 +0530 | [diff] [blame] | 559 | 0x21, 0x10, 0x00, 0x14, //SRP object |
| 560 | 0x00, 0x00, 0x00, 0x00, |
| 561 | 0x00, 0x00, 0x00, 0x00, |
| 562 | 0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV |
Avantika-Huawei | d1e36bd | 2016-05-26 12:47:16 +0530 | [diff] [blame^] | 563 | 0x00, 0x00, 0x00, 0x02, |
Avantika-Huawei | 7f7376a | 2016-05-11 17:07:50 +0530 | [diff] [blame] | 564 | 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x19, // LSP object |
Avantika-Huawei | d1e36bd | 2016-05-26 12:47:16 +0530 | [diff] [blame^] | 565 | 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, // symbolic path TLV |
Avantika-Huawei | 7f7376a | 2016-05-11 17:07:50 +0530 | [diff] [blame] | 566 | 0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV |
| 567 | 0x01, 0x01, 0x01, 0x01, |
| 568 | 0x00, 0x01, 0x00, 0x01, |
| 569 | 0x01, 0x01, 0x01, 0x01, |
| 570 | 0x05, 0x05, 0x05, 0x05, |
| 571 | |
| 572 | 0x07, 0x10, 0x00, 0x14, //ERO object |
| 573 | 0x01, 0x08, (byte) 0x01, 0x01, 0x01, 0x01, 0x04, 0x00, // ERO IPv4 sub objects |
| 574 | 0x01, 0x08, (byte) 0x05, 0x05, 0x05, 0x05, 0x04, 0x00, |
| 575 | |
| 576 | 0x08, 0x10, 0x00, 0x34, //RRO object |
| 577 | 0x01, 0x08, 0x11, 0x01, 0x01, 0x01, 0x04, 0x00, // RRO IPv4 sub objects |
| 578 | 0x01, 0x08, 0x11, 0x01, 0x01, 0x02, 0x04, 0x00, |
| 579 | 0x01, 0x08, 0x06, 0x06, 0x06, 0x06, 0x04, 0x00, |
| 580 | 0x01, 0x08, 0x12, 0x01, 0x01, 0x02, 0x04, 0x00, |
| 581 | 0x01, 0x08, 0x12, 0x01, 0x01, 0x01, 0x04, 0x00, |
| 582 | 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00 |
| 583 | }; |
| 584 | |
Avantika-Huawei | d1e36bd | 2016-05-26 12:47:16 +0530 | [diff] [blame^] | 585 | ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); |
| 586 | buffer.writeBytes(reportMsg); |
Avantika-Huawei | 7f7376a | 2016-05-11 17:07:50 +0530 | [diff] [blame] | 587 | |
Avantika-Huawei | d1e36bd | 2016-05-26 12:47:16 +0530 | [diff] [blame^] | 588 | PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); |
| 589 | PcepMessage message = reader.readFrom(buffer); |
Avantika-Huawei | 7f7376a | 2016-05-11 17:07:50 +0530 | [diff] [blame] | 590 | |
Priyanka B | 413fbe8 | 2016-05-26 11:44:45 +0530 | [diff] [blame] | 591 | DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder(); |
| 592 | newBuilder.set(PcepTunnelProvider.LSRID, "1.1.1.1"); |
| 593 | newBuilder.set(AnnotationKeys.TYPE, "L3"); |
| 594 | Device device = new DefaultDevice(ProviderId.NONE, DeviceId.deviceId("1.1.1.1"), ROUTER, |
| 595 | UNKOWN, UNKOWN, UNKOWN, |
| 596 | UNKOWN, new ChassisId(), |
| 597 | newBuilder.build()); |
| 598 | |
| 599 | deviceService.addDevice(device); |
| 600 | |
Avantika-Huawei | 7f7376a | 2016-05-11 17:07:50 +0530 | [diff] [blame] | 601 | PccId pccId = PccId.pccId(IpAddress.valueOf("1.1.1.1")); |
Avantika-Huawei | d1e36bd | 2016-05-26 12:47:16 +0530 | [diff] [blame^] | 602 | controller.getClient(pccId).setLspDbSyncStatus(SYNCED); |
Priyanka B | 413fbe8 | 2016-05-26 11:44:45 +0530 | [diff] [blame] | 603 | controller.getClient(pccId).setCapability(new ClientCapability(true, true, true, true, true)); |
| 604 | |
| 605 | PcepClientAdapter pc = new PcepClientAdapter(); |
| 606 | pc.init(pccId, PcepVersion.PCEP_1); |
Avantika-Huawei | d1e36bd | 2016-05-26 12:47:16 +0530 | [diff] [blame^] | 607 | controller.getClient(pccId).setLspAndDelegationInfo(new LspKey(1, (short) 1), true); |
Priyanka B | 413fbe8 | 2016-05-26 11:44:45 +0530 | [diff] [blame] | 608 | masterShipService.setMaster(true); |
Avantika-Huawei | d1e36bd | 2016-05-26 12:47:16 +0530 | [diff] [blame^] | 609 | controller.processClientMessage(pccId, message); |
Avantika-Huawei | 7f7376a | 2016-05-11 17:07:50 +0530 | [diff] [blame] | 610 | |
Avantika-Huawei | d1e36bd | 2016-05-26 12:47:16 +0530 | [diff] [blame^] | 611 | assertThat(registry.tunnelIdCounter, is((long) 0)); |
Avantika-Huawei | 7f7376a | 2016-05-11 17:07:50 +0530 | [diff] [blame] | 612 | } |
| 613 | |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 614 | @After |
| 615 | public void tearDown() throws IOException { |
| 616 | tunnelProvider.deactivate(); |
| 617 | tunnelProvider.controller = null; |
| 618 | tunnelProvider.pcepClientController = null; |
| 619 | tunnelProvider.tunnelProviderRegistry = null; |
| 620 | |
| 621 | tunnelProvider.pcepTunnelApiMapper = null; |
| 622 | tunnelProvider.cfgService = null; |
| 623 | tunnelProvider.tunnelService = null; |
Priyanka B | 413fbe8 | 2016-05-26 11:44:45 +0530 | [diff] [blame] | 624 | tunnelProvider.tunnelAdminService = null; |
| 625 | tunnelProvider.deviceService = null; |
| 626 | tunnelProvider.mastershipService = null; |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 627 | tunnelProvider.service = null; |
| 628 | } |
| 629 | } |