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 | |
Priyanka B | d2b2888 | 2016-04-04 16:57:04 +0530 | [diff] [blame] | 18 | import static org.hamcrest.MatcherAssert.assertThat; |
| 19 | import static org.hamcrest.Matchers.nullValue; |
| 20 | import static org.hamcrest.core.Is.is; |
| 21 | import static org.hamcrest.core.IsNot.not; |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 22 | import static org.onosproject.net.DefaultAnnotations.EMPTY; |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame^] | 23 | import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.LSP_SIG_TYPE; |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 24 | |
| 25 | import java.io.IOException; |
| 26 | import java.util.ArrayList; |
| 27 | import java.util.List; |
| 28 | |
| 29 | import org.junit.After; |
Priyanka B | d2b2888 | 2016-04-04 16:57:04 +0530 | [diff] [blame] | 30 | import org.junit.Before; |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 31 | import org.junit.Test; |
| 32 | import org.onlab.packet.IpAddress; |
chengfan | 2fff70f | 2015-08-24 18:20:19 -0500 | [diff] [blame] | 33 | import org.onosproject.cfg.ComponentConfigAdapter; |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 34 | import org.onosproject.core.DefaultGroupId; |
| 35 | import org.onosproject.incubator.net.tunnel.DefaultTunnel; |
| 36 | import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint; |
| 37 | import org.onosproject.incubator.net.tunnel.Tunnel; |
| 38 | import org.onosproject.incubator.net.tunnel.TunnelId; |
| 39 | import org.onosproject.incubator.net.tunnel.TunnelName; |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame^] | 40 | import org.onosproject.net.Annotations; |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 41 | import org.onosproject.net.ConnectPoint; |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame^] | 42 | import org.onosproject.net.DefaultAnnotations; |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 43 | import org.onosproject.net.DefaultLink; |
| 44 | import org.onosproject.net.DefaultPath; |
| 45 | import org.onosproject.net.IpElementId; |
| 46 | import org.onosproject.net.Link; |
| 47 | import org.onosproject.net.Path; |
| 48 | import org.onosproject.net.PortNumber; |
| 49 | import org.onosproject.net.provider.ProviderId; |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame^] | 50 | import org.onosproject.pcepio.types.StatefulIPv4LspIdentifiersTlv; |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 51 | |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame^] | 52 | import static org.onosproject.provider.pcep.tunnel.impl.LspType.WITH_SIGNALLING; |
| 53 | import static org.onosproject.provider.pcep.tunnel.impl.LspType.SR_WITHOUT_SIGNALLING; |
| 54 | import static org.onosproject.provider.pcep.tunnel.impl.LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR; |
Priyanka B | d2b2888 | 2016-04-04 16:57:04 +0530 | [diff] [blame] | 55 | /** |
| 56 | * Test for PCEP update tunnel. |
| 57 | */ |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 58 | public class PcepUpdateTunnelProviderTest { |
| 59 | |
Brian Stanke | 9a10897 | 2016-04-11 15:25:17 -0400 | [diff] [blame] | 60 | private static final String PROVIDER_ID = "org.onosproject.provider.tunnel.pcep"; |
Priyanka B | d2b2888 | 2016-04-04 16:57:04 +0530 | [diff] [blame] | 61 | private PcepTunnelProvider tunnelProvider = new PcepTunnelProvider(); |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 62 | private final TunnelProviderRegistryAdapter registry = new TunnelProviderRegistryAdapter(); |
| 63 | private final PcepClientControllerAdapter controller = new PcepClientControllerAdapter(); |
| 64 | private final PcepControllerAdapter ctl = new PcepControllerAdapter(); |
| 65 | private final PcepTunnelApiMapper pcepTunnelAPIMapper = new PcepTunnelApiMapper(); |
chengfan | 2fff70f | 2015-08-24 18:20:19 -0500 | [diff] [blame] | 66 | private final TunnelServiceAdapter tunnelService = new TunnelServiceAdapter(); |
| 67 | |
Priyanka B | d2b2888 | 2016-04-04 16:57:04 +0530 | [diff] [blame] | 68 | @Before |
| 69 | public void setUp() throws IOException { |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 70 | tunnelProvider.tunnelProviderRegistry = registry; |
| 71 | tunnelProvider.pcepClientController = controller; |
| 72 | tunnelProvider.controller = ctl; |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 73 | tunnelProvider.pcepTunnelApiMapper = pcepTunnelAPIMapper; |
chengfan | 2fff70f | 2015-08-24 18:20:19 -0500 | [diff] [blame] | 74 | tunnelProvider.cfgService = new ComponentConfigAdapter(); |
| 75 | tunnelProvider.tunnelService = tunnelService; |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 76 | tunnelProvider.activate(); |
Priyanka B | d2b2888 | 2016-04-04 16:57:04 +0530 | [diff] [blame] | 77 | } |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 78 | |
Priyanka B | d2b2888 | 2016-04-04 16:57:04 +0530 | [diff] [blame] | 79 | /** |
| 80 | * Send update message to PCC. |
| 81 | */ |
| 82 | @Test |
| 83 | public void testCasePcepUpdateTunnel() { |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 84 | Tunnel tunnel; |
| 85 | Path path; |
| 86 | ProviderId pid = new ProviderId("pcep", PROVIDER_ID); |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame^] | 87 | List<Link> links = new ArrayList<>(); |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 88 | IpAddress srcIp = IpAddress.valueOf(0xD010101); |
| 89 | IpElementId srcElementId = IpElementId.ipElement(srcIp); |
| 90 | |
| 91 | IpAddress dstIp = IpAddress.valueOf(0xD010102); |
| 92 | IpElementId dstElementId = IpElementId.ipElement(dstIp); |
| 93 | |
| 94 | IpTunnelEndPoint ipTunnelEndPointSrc; |
| 95 | ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp); |
| 96 | |
| 97 | IpTunnelEndPoint ipTunnelEndPointDst; |
| 98 | ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp); |
| 99 | |
| 100 | ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023)); |
| 101 | |
| 102 | ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023)); |
| 103 | |
Ray Milkey | 2693bda | 2016-01-22 16:08:14 -0800 | [diff] [blame] | 104 | Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst) |
| 105 | .type(Link.Type.DIRECT).build(); |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 106 | links.add(link); |
| 107 | |
| 108 | path = new DefaultPath(pid, links, 20, EMPTY); |
| 109 | |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame^] | 110 | Annotations annotations = DefaultAnnotations.builder() |
| 111 | .set(LSP_SIG_TYPE, WITH_SIGNALLING.name()) |
| 112 | .build(); |
| 113 | |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 114 | tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS, |
Brian Stanke | 9a10897 | 2016-04-11 15:25:17 -0400 | [diff] [blame] | 115 | new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"), |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame^] | 116 | path, annotations); |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 117 | |
| 118 | // for updating tunnel tunnel should exist in db |
| 119 | PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, RequestType.UPDATE); |
| 120 | pcepTunnelData.setPlspId(1); |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame^] | 121 | StatefulIPv4LspIdentifiersTlv tlv = new StatefulIPv4LspIdentifiersTlv(0, (short) 1, (short) 2, 3, 4); |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 122 | pcepTunnelData.setStatefulIpv4IndentifierTlv(tlv); |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 123 | tunnelProvider.pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData); |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 124 | |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 125 | tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData); |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 126 | |
| 127 | tunnelProvider.updateTunnel(tunnel, path); |
Priyanka B | d2b2888 | 2016-04-04 16:57:04 +0530 | [diff] [blame] | 128 | assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue())); |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * Doesn't send update message because PCC doesn't supports PCE stateful capability. |
| 133 | */ |
| 134 | @Test |
| 135 | public void testCasePcepUpdateTunnel2() { |
| 136 | Tunnel tunnel; |
| 137 | Path path; |
| 138 | ProviderId pid = new ProviderId("pcep", PROVIDER_ID); |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame^] | 139 | List<Link> links = new ArrayList<>(); |
Priyanka B | d2b2888 | 2016-04-04 16:57:04 +0530 | [diff] [blame] | 140 | IpAddress srcIp = IpAddress.valueOf(0xC010103); |
| 141 | IpElementId srcElementId = IpElementId.ipElement(srcIp); |
| 142 | |
| 143 | IpAddress dstIp = IpAddress.valueOf(0xD010102); |
| 144 | IpElementId dstElementId = IpElementId.ipElement(dstIp); |
| 145 | |
| 146 | IpTunnelEndPoint ipTunnelEndPointSrc; |
| 147 | ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp); |
| 148 | |
| 149 | IpTunnelEndPoint ipTunnelEndPointDst; |
| 150 | ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp); |
| 151 | |
| 152 | ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023)); |
| 153 | |
| 154 | ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023)); |
| 155 | |
| 156 | Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst) |
| 157 | .type(Link.Type.DIRECT).build(); |
| 158 | links.add(link); |
| 159 | |
| 160 | path = new DefaultPath(pid, links, 20, EMPTY); |
| 161 | |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame^] | 162 | Annotations annotations = DefaultAnnotations.builder() |
| 163 | .set(LSP_SIG_TYPE, WITH_SIGNALLING.name()) |
| 164 | .build(); |
| 165 | |
Priyanka B | d2b2888 | 2016-04-04 16:57:04 +0530 | [diff] [blame] | 166 | tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS, |
Brian Stanke | 9a10897 | 2016-04-11 15:25:17 -0400 | [diff] [blame] | 167 | new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"), |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame^] | 168 | path, annotations); |
Priyanka B | d2b2888 | 2016-04-04 16:57:04 +0530 | [diff] [blame] | 169 | |
| 170 | // for updating tunnel tunnel should exist in db |
| 171 | PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, RequestType.UPDATE); |
| 172 | pcepTunnelData.setPlspId(1); |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame^] | 173 | StatefulIPv4LspIdentifiersTlv tlv = new StatefulIPv4LspIdentifiersTlv(0, (short) 1, (short) 2, 3, 4); |
Priyanka B | d2b2888 | 2016-04-04 16:57:04 +0530 | [diff] [blame] | 174 | pcepTunnelData.setStatefulIpv4IndentifierTlv(tlv); |
| 175 | tunnelProvider.pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData); |
| 176 | |
| 177 | tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData); |
| 178 | |
| 179 | tunnelProvider.updateTunnel(tunnel, path); |
| 180 | assertThat(tunnelProvider.pcepTunnelApiMapper.checkFromTunnelRequestQueue(1), is(false)); |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 181 | } |
| 182 | |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame^] | 183 | /** |
| 184 | * Sends update message to PCC for SR based tunnel. |
| 185 | */ |
| 186 | @Test |
| 187 | public void testCasePcepUpdateSrTunnel() { |
| 188 | Tunnel tunnel; |
| 189 | Path path; |
| 190 | ProviderId pid = new ProviderId("pcep", PROVIDER_ID); |
| 191 | List<Link> links = new ArrayList<>(); |
| 192 | IpAddress srcIp = IpAddress.valueOf(0xD010101); |
| 193 | IpElementId srcElementId = IpElementId.ipElement(srcIp); |
| 194 | |
| 195 | IpAddress dstIp = IpAddress.valueOf(0xD010102); |
| 196 | IpElementId dstElementId = IpElementId.ipElement(dstIp); |
| 197 | |
| 198 | IpTunnelEndPoint ipTunnelEndPointSrc; |
| 199 | ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp); |
| 200 | |
| 201 | IpTunnelEndPoint ipTunnelEndPointDst; |
| 202 | ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp); |
| 203 | |
| 204 | ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023)); |
| 205 | |
| 206 | ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023)); |
| 207 | |
| 208 | Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst) |
| 209 | .type(Link.Type.DIRECT).build(); |
| 210 | links.add(link); |
| 211 | |
| 212 | path = new DefaultPath(pid, links, 20, EMPTY); |
| 213 | |
| 214 | Annotations annotations = DefaultAnnotations.builder() |
| 215 | .set(LSP_SIG_TYPE, SR_WITHOUT_SIGNALLING.name()) |
| 216 | .build(); |
| 217 | |
| 218 | tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS, |
| 219 | new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"), |
| 220 | path, annotations); |
| 221 | |
| 222 | // for updating tunnel tunnel should exist in db |
| 223 | PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, RequestType.UPDATE); |
| 224 | pcepTunnelData.setPlspId(1); |
| 225 | StatefulIPv4LspIdentifiersTlv tlv = new StatefulIPv4LspIdentifiersTlv(0, (short) 1, (short) 2, 3, 4); |
| 226 | pcepTunnelData.setStatefulIpv4IndentifierTlv(tlv); |
| 227 | tunnelProvider.pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData); |
| 228 | |
| 229 | tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData); |
| 230 | |
| 231 | tunnelProvider.updateTunnel(tunnel, path); |
| 232 | assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue())); |
| 233 | } |
| 234 | |
| 235 | /** |
| 236 | * Sends update message to PCC for tunnel without signalling and without SR. |
| 237 | */ |
| 238 | @Test |
| 239 | public void testCasePcepUpdateTunnelWithoutSigSr() { |
| 240 | Tunnel tunnel; |
| 241 | Path path; |
| 242 | ProviderId pid = new ProviderId("pcep", PROVIDER_ID); |
| 243 | List<Link> links = new ArrayList<>(); |
| 244 | IpAddress srcIp = IpAddress.valueOf(0xD010101); |
| 245 | IpElementId srcElementId = IpElementId.ipElement(srcIp); |
| 246 | |
| 247 | IpAddress dstIp = IpAddress.valueOf(0xD010102); |
| 248 | IpElementId dstElementId = IpElementId.ipElement(dstIp); |
| 249 | |
| 250 | IpTunnelEndPoint ipTunnelEndPointSrc; |
| 251 | ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp); |
| 252 | |
| 253 | IpTunnelEndPoint ipTunnelEndPointDst; |
| 254 | ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp); |
| 255 | |
| 256 | ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023)); |
| 257 | |
| 258 | ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023)); |
| 259 | |
| 260 | Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst) |
| 261 | .type(Link.Type.DIRECT).build(); |
| 262 | links.add(link); |
| 263 | |
| 264 | path = new DefaultPath(pid, links, 20, EMPTY); |
| 265 | |
| 266 | Annotations annotations = DefaultAnnotations.builder() |
| 267 | .set(LSP_SIG_TYPE, WITHOUT_SIGNALLING_AND_WITHOUT_SR.name()) |
| 268 | .build(); |
| 269 | |
| 270 | tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS, |
| 271 | new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"), |
| 272 | path, annotations); |
| 273 | |
| 274 | // for updating tunnel tunnel should exist in db |
| 275 | PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, RequestType.UPDATE); |
| 276 | pcepTunnelData.setPlspId(1); |
| 277 | StatefulIPv4LspIdentifiersTlv tlv = new StatefulIPv4LspIdentifiersTlv(0, (short) 1, (short) 2, 3, 4); |
| 278 | pcepTunnelData.setStatefulIpv4IndentifierTlv(tlv); |
| 279 | tunnelProvider.pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData); |
| 280 | |
| 281 | tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData); |
| 282 | |
| 283 | tunnelProvider.updateTunnel(tunnel, path); |
| 284 | assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue())); |
| 285 | } |
| 286 | |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 287 | @After |
| 288 | public void tearDown() throws IOException { |
| 289 | tunnelProvider.deactivate(); |
| 290 | tunnelProvider.controller = null; |
| 291 | tunnelProvider.pcepClientController = null; |
| 292 | tunnelProvider.tunnelProviderRegistry = null; |
| 293 | } |
| 294 | } |