Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.provider.pcep.tunnel.impl; |
| 17 | |
| 18 | import static org.onosproject.net.DefaultAnnotations.EMPTY; |
Priyanka B | d2b2888 | 2016-04-04 16:57:04 +0530 | [diff] [blame] | 19 | import static org.hamcrest.MatcherAssert.assertThat; |
| 20 | import static org.hamcrest.core.Is.is; |
| 21 | import static org.hamcrest.core.IsNot.not; |
| 22 | import static org.hamcrest.Matchers.nullValue; |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 23 | import static org.onosproject.provider.pcep.tunnel.impl.LspType.WITH_SIGNALLING; |
| 24 | import static org.onosproject.provider.pcep.tunnel.impl.LspType.SR_WITHOUT_SIGNALLING; |
| 25 | import static org.onosproject.provider.pcep.tunnel.impl.LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR; |
| 26 | import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.LSP_SIG_TYPE; |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 27 | |
| 28 | import java.io.IOException; |
| 29 | import java.util.ArrayList; |
| 30 | import java.util.List; |
| 31 | |
| 32 | import org.junit.After; |
Priyanka B | d2b2888 | 2016-04-04 16:57:04 +0530 | [diff] [blame] | 33 | import org.junit.Before; |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 34 | import org.junit.Test; |
| 35 | import org.onlab.packet.IpAddress; |
chengfan | 2fff70f | 2015-08-24 18:20:19 -0500 | [diff] [blame] | 36 | import org.onosproject.cfg.ComponentConfigAdapter; |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 37 | import org.onosproject.core.DefaultGroupId; |
| 38 | import org.onosproject.incubator.net.tunnel.DefaultTunnel; |
| 39 | import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint; |
| 40 | import org.onosproject.incubator.net.tunnel.Tunnel; |
| 41 | import org.onosproject.incubator.net.tunnel.TunnelId; |
| 42 | import org.onosproject.incubator.net.tunnel.TunnelName; |
Priyanka B | 413fbe8 | 2016-05-26 11:44:45 +0530 | [diff] [blame^] | 43 | import org.onosproject.mastership.MastershipServiceAdapter; |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 44 | import org.onosproject.net.Annotations; |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 45 | import org.onosproject.net.ConnectPoint; |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 46 | import org.onosproject.net.DefaultAnnotations; |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 47 | import org.onosproject.net.DefaultLink; |
| 48 | import org.onosproject.net.DefaultPath; |
| 49 | import org.onosproject.net.IpElementId; |
| 50 | import org.onosproject.net.Link; |
| 51 | import org.onosproject.net.Path; |
| 52 | import org.onosproject.net.PortNumber; |
Priyanka B | 413fbe8 | 2016-05-26 11:44:45 +0530 | [diff] [blame^] | 53 | import org.onosproject.net.device.DeviceServiceAdapter; |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 54 | import org.onosproject.net.provider.ProviderId; |
Priyanka B | 413fbe8 | 2016-05-26 11:44:45 +0530 | [diff] [blame^] | 55 | import org.onosproject.pcep.controller.ClientCapability; |
| 56 | import org.onosproject.pcep.controller.PccId; |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 57 | |
Priyanka B | d2b2888 | 2016-04-04 16:57:04 +0530 | [diff] [blame] | 58 | /** |
| 59 | * Test for PCEP setup tunnel. |
| 60 | */ |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 61 | public class PcepSetupTunnelProviderTest { |
| 62 | |
Brian Stanke | 9a10897 | 2016-04-11 15:25:17 -0400 | [diff] [blame] | 63 | private static final String PROVIDER_ID = "org.onosproject.provider.tunnel.pcep"; |
Priyanka B | d2b2888 | 2016-04-04 16:57:04 +0530 | [diff] [blame] | 64 | private PcepTunnelProvider tunnelProvider = new PcepTunnelProvider(); |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 65 | private final TunnelProviderRegistryAdapter registry = new TunnelProviderRegistryAdapter(); |
| 66 | private final PcepClientControllerAdapter controller = new PcepClientControllerAdapter(); |
| 67 | private final PcepControllerAdapter ctl = new PcepControllerAdapter(); |
chengfan | 2fff70f | 2015-08-24 18:20:19 -0500 | [diff] [blame] | 68 | private final TunnelServiceAdapter tunnelService = new TunnelServiceAdapter(); |
Priyanka B | 413fbe8 | 2016-05-26 11:44:45 +0530 | [diff] [blame^] | 69 | private final DeviceServiceAdapter deviceService = new DeviceServiceAdapter(); |
| 70 | private final MastershipServiceAdapter mastershipService = new MastershipServiceAdapter(); |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 71 | |
Priyanka B | d2b2888 | 2016-04-04 16:57:04 +0530 | [diff] [blame] | 72 | @Before |
| 73 | public void setUp() throws IOException { |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 74 | tunnelProvider.tunnelProviderRegistry = registry; |
| 75 | tunnelProvider.pcepClientController = controller; |
| 76 | tunnelProvider.controller = ctl; |
Priyanka B | 413fbe8 | 2016-05-26 11:44:45 +0530 | [diff] [blame^] | 77 | tunnelProvider.deviceService = deviceService; |
| 78 | tunnelProvider.mastershipService = mastershipService; |
chengfan | 2fff70f | 2015-08-24 18:20:19 -0500 | [diff] [blame] | 79 | tunnelProvider.cfgService = new ComponentConfigAdapter(); |
| 80 | tunnelProvider.tunnelService = tunnelService; |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 81 | tunnelProvider.activate(); |
Priyanka B | d2b2888 | 2016-04-04 16:57:04 +0530 | [diff] [blame] | 82 | } |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 83 | |
Priyanka B | d2b2888 | 2016-04-04 16:57:04 +0530 | [diff] [blame] | 84 | /** |
| 85 | * Send PcInitiate message to PCC. |
| 86 | */ |
| 87 | @Test |
| 88 | public void testCasePcepSetupTunnel() { |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 89 | Tunnel tunnel; |
| 90 | Path path; |
| 91 | ProviderId pid = new ProviderId("pcep", PROVIDER_ID); |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 92 | List<Link> links = new ArrayList<>(); |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 93 | IpAddress srcIp = IpAddress.valueOf(0xC010101); |
| 94 | IpElementId srcElementId = IpElementId.ipElement(srcIp); |
| 95 | |
| 96 | IpAddress dstIp = IpAddress.valueOf(0xC010102); |
| 97 | IpElementId dstElementId = IpElementId.ipElement(dstIp); |
| 98 | |
| 99 | IpTunnelEndPoint ipTunnelEndPointSrc; |
| 100 | ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp); |
| 101 | |
| 102 | IpTunnelEndPoint ipTunnelEndPointDst; |
| 103 | ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp); |
| 104 | |
| 105 | ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023)); |
| 106 | |
| 107 | ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023)); |
| 108 | |
Ray Milkey | 2693bda | 2016-01-22 16:08:14 -0800 | [diff] [blame] | 109 | Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst) |
| 110 | .type(Link.Type.DIRECT).build(); |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 111 | links.add(link); |
| 112 | |
| 113 | path = new DefaultPath(pid, links, 10, EMPTY); |
| 114 | |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 115 | Annotations annotations = DefaultAnnotations.builder() |
| 116 | .set(LSP_SIG_TYPE, WITH_SIGNALLING.name()) |
| 117 | .build(); |
| 118 | |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 119 | tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS, |
Brian Stanke | 9a10897 | 2016-04-11 15:25:17 -0400 | [diff] [blame] | 120 | new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"), |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 121 | path, annotations); |
Priyanka B | 413fbe8 | 2016-05-26 11:44:45 +0530 | [diff] [blame^] | 122 | controller.getClient(PccId.pccId(IpAddress.valueOf(0xC010101))).setCapability( |
| 123 | new ClientCapability(true, true, true, true, true)); |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 124 | |
| 125 | tunnelProvider.setupTunnel(tunnel, path); |
Priyanka B | d2b2888 | 2016-04-04 16:57:04 +0530 | [diff] [blame] | 126 | assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue())); |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * Doesn't send PCInitiate message because PCC doesn't supports PCInitiate and stateful capability. |
| 131 | */ |
| 132 | @Test |
| 133 | public void testCasePcepSetupTunnel2() { |
| 134 | Tunnel tunnel; |
| 135 | Path path; |
| 136 | ProviderId pid = new ProviderId("pcep", PROVIDER_ID); |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 137 | List<Link> links = new ArrayList<>(); |
Priyanka B | d2b2888 | 2016-04-04 16:57:04 +0530 | [diff] [blame] | 138 | IpAddress srcIp = IpAddress.valueOf(0xC010103); |
| 139 | IpElementId srcElementId = IpElementId.ipElement(srcIp); |
| 140 | |
| 141 | IpAddress dstIp = IpAddress.valueOf(0xC010102); |
| 142 | IpElementId dstElementId = IpElementId.ipElement(dstIp); |
| 143 | |
| 144 | IpTunnelEndPoint ipTunnelEndPointSrc; |
| 145 | ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp); |
| 146 | |
| 147 | IpTunnelEndPoint ipTunnelEndPointDst; |
| 148 | ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp); |
| 149 | |
| 150 | ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023)); |
| 151 | |
| 152 | ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023)); |
| 153 | |
| 154 | Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst) |
| 155 | .type(Link.Type.DIRECT).build(); |
| 156 | links.add(link); |
| 157 | |
| 158 | path = new DefaultPath(pid, links, 10, EMPTY); |
| 159 | |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 160 | Annotations annotations = DefaultAnnotations.builder() |
| 161 | .set(LSP_SIG_TYPE, WITH_SIGNALLING.name()) |
| 162 | .build(); |
| 163 | |
Priyanka B | d2b2888 | 2016-04-04 16:57:04 +0530 | [diff] [blame] | 164 | tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS, |
Brian Stanke | 9a10897 | 2016-04-11 15:25:17 -0400 | [diff] [blame] | 165 | new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"), |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 166 | path, annotations); |
Priyanka B | 413fbe8 | 2016-05-26 11:44:45 +0530 | [diff] [blame^] | 167 | controller.getClient(PccId.pccId(IpAddress.valueOf(0xC010103))).setCapability( |
| 168 | new ClientCapability(true, true, true, true, true)); |
Priyanka B | d2b2888 | 2016-04-04 16:57:04 +0530 | [diff] [blame] | 169 | |
| 170 | tunnelProvider.setupTunnel(tunnel, path); |
| 171 | assertThat(tunnelProvider.pcepTunnelApiMapper.checkFromTunnelRequestQueue(1), is(false)); |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 172 | } |
| 173 | |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 174 | /** |
| 175 | * Sends PCInitiate msg to setup a SR based tunnel. |
| 176 | */ |
| 177 | @Test |
| 178 | public void testCasePcepSetupSrTunnel() { |
| 179 | Tunnel tunnel; |
| 180 | Path path; |
| 181 | ProviderId pid = new ProviderId("pcep", PROVIDER_ID); |
| 182 | List<Link> links = new ArrayList<>(); |
| 183 | IpAddress srcIp = IpAddress.valueOf(0xC010101); |
| 184 | IpElementId srcElementId = IpElementId.ipElement(srcIp); |
| 185 | |
| 186 | IpAddress dstIp = IpAddress.valueOf(0xC010102); |
| 187 | IpElementId dstElementId = IpElementId.ipElement(dstIp); |
| 188 | |
| 189 | IpTunnelEndPoint ipTunnelEndPointSrc; |
| 190 | ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp); |
| 191 | |
| 192 | IpTunnelEndPoint ipTunnelEndPointDst; |
| 193 | ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp); |
| 194 | |
| 195 | ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023)); |
| 196 | |
| 197 | ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023)); |
| 198 | |
| 199 | Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst) |
| 200 | .type(Link.Type.DIRECT).build(); |
| 201 | links.add(link); |
| 202 | |
| 203 | path = new DefaultPath(pid, links, 10, EMPTY); |
| 204 | |
| 205 | Annotations annotations = DefaultAnnotations.builder() |
| 206 | .set(LSP_SIG_TYPE, SR_WITHOUT_SIGNALLING.name()) |
| 207 | .build(); |
| 208 | |
| 209 | tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS, |
| 210 | new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"), |
| 211 | path, annotations); |
Priyanka B | 413fbe8 | 2016-05-26 11:44:45 +0530 | [diff] [blame^] | 212 | controller.getClient(PccId.pccId(IpAddress.valueOf(0xC010101))).setCapability( |
| 213 | new ClientCapability(true, true, true, true, true)); |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 214 | |
| 215 | tunnelProvider.setupTunnel(tunnel, path); |
| 216 | assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue())); |
| 217 | } |
| 218 | |
| 219 | /** |
| 220 | * Sends PCInitiate msg to setup a tunnel without signalling and without SR. |
| 221 | */ |
| 222 | @Test |
| 223 | public void testCasePcepSetupTunnelWithoutSigSr() { |
| 224 | Tunnel tunnel; |
| 225 | Path path; |
| 226 | ProviderId pid = new ProviderId("pcep", PROVIDER_ID); |
| 227 | List<Link> links = new ArrayList<>(); |
| 228 | IpAddress srcIp = IpAddress.valueOf(0xC010101); |
| 229 | IpElementId srcElementId = IpElementId.ipElement(srcIp); |
| 230 | |
| 231 | IpAddress dstIp = IpAddress.valueOf(0xC010102); |
| 232 | IpElementId dstElementId = IpElementId.ipElement(dstIp); |
| 233 | |
| 234 | IpTunnelEndPoint ipTunnelEndPointSrc; |
| 235 | ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp); |
| 236 | |
| 237 | IpTunnelEndPoint ipTunnelEndPointDst; |
| 238 | ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp); |
| 239 | |
| 240 | ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023)); |
| 241 | |
| 242 | ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023)); |
| 243 | |
| 244 | Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst) |
| 245 | .type(Link.Type.DIRECT).build(); |
| 246 | links.add(link); |
| 247 | |
| 248 | path = new DefaultPath(pid, links, 10, EMPTY); |
| 249 | |
| 250 | Annotations annotations = DefaultAnnotations.builder() |
| 251 | .set(LSP_SIG_TYPE, WITHOUT_SIGNALLING_AND_WITHOUT_SR.name()) |
| 252 | .build(); |
| 253 | |
| 254 | tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS, |
| 255 | new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"), |
| 256 | path, annotations); |
Priyanka B | 413fbe8 | 2016-05-26 11:44:45 +0530 | [diff] [blame^] | 257 | controller.getClient(PccId.pccId(IpAddress.valueOf(0xC010101))).setCapability( |
| 258 | new ClientCapability(true, true, true, true, true)); |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 259 | |
| 260 | tunnelProvider.setupTunnel(tunnel, path); |
| 261 | assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue())); |
| 262 | } |
| 263 | |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 264 | @After |
| 265 | public void tearDown() throws IOException { |
| 266 | tunnelProvider.deactivate(); |
| 267 | tunnelProvider.controller = null; |
| 268 | tunnelProvider.pcepClientController = null; |
| 269 | tunnelProvider.tunnelProviderRegistry = null; |
Priyanka B | 413fbe8 | 2016-05-26 11:44:45 +0530 | [diff] [blame^] | 270 | tunnelProvider.deviceService = null; |
| 271 | tunnelProvider.mastershipService = null; |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 272 | } |
| 273 | } |