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