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