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