blob: 12579ae6cd6eba669d5b60cd42a62fee6b870fcd [file] [log] [blame]
Phanendra Manda972ee9e2015-08-21 19:08:20 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Phanendra Manda972ee9e2015-08-21 19:08:20 +05303 *
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 */
16package org.onosproject.provider.pcep.tunnel.impl;
17
Phanendra Manda972ee9e2015-08-21 19:08:20 +053018import org.junit.After;
Priyanka Bd2b28882016-04-04 16:57:04 +053019import org.junit.Before;
Phanendra Manda972ee9e2015-08-21 19:08:20 +053020import org.junit.Test;
Ray Milkeya7cf8c82018-02-08 15:07:06 -080021import org.onlab.graph.ScalarWeight;
Phanendra Manda972ee9e2015-08-21 19:08:20 +053022import org.onlab.packet.IpAddress;
chengfan2fff70f2015-08-24 18:20:19 -050023import org.onosproject.cfg.ComponentConfigAdapter;
Yi Tsengfa394de2017-02-01 11:26:40 -080024import org.onosproject.core.GroupId;
Phanendra Manda972ee9e2015-08-21 19:08:20 +053025import org.onosproject.incubator.net.tunnel.DefaultTunnel;
26import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint;
27import org.onosproject.incubator.net.tunnel.Tunnel;
28import org.onosproject.incubator.net.tunnel.TunnelId;
29import org.onosproject.incubator.net.tunnel.TunnelName;
Ray Milkeyd1c34da2018-06-22 18:10:53 -070030import org.onosproject.incubator.net.tunnel.TunnelServiceAdapter;
Priyanka B413fbe82016-05-26 11:44:45 +053031import org.onosproject.mastership.MastershipServiceAdapter;
Avantika-Huawei56c11842016-04-28 00:56:56 +053032import org.onosproject.net.Annotations;
Phanendra Manda972ee9e2015-08-21 19:08:20 +053033import org.onosproject.net.ConnectPoint;
Avantika-Huawei56c11842016-04-28 00:56:56 +053034import org.onosproject.net.DefaultAnnotations;
Phanendra Manda972ee9e2015-08-21 19:08:20 +053035import org.onosproject.net.DefaultLink;
36import org.onosproject.net.DefaultPath;
37import org.onosproject.net.IpElementId;
38import org.onosproject.net.Link;
39import org.onosproject.net.Path;
40import org.onosproject.net.PortNumber;
Priyanka B413fbe82016-05-26 11:44:45 +053041import org.onosproject.net.device.DeviceServiceAdapter;
Phanendra Manda972ee9e2015-08-21 19:08:20 +053042import org.onosproject.net.provider.ProviderId;
Ray Milkeyd1c34da2018-06-22 18:10:53 -070043import org.onosproject.pcep.api.PcepControllerAdapter;
harikrushna-Huaweia2c7c202017-04-10 18:22:00 +053044import org.onosproject.pcep.server.ClientCapability;
45import org.onosproject.pcep.server.PccId;
Ray Milkeyd1c34da2018-06-22 18:10:53 -070046import org.onosproject.pcep.server.PcepClientControllerAdapter;
Avantika-Huawei56c11842016-04-28 00:56:56 +053047import org.onosproject.pcepio.types.StatefulIPv4LspIdentifiersTlv;
Phanendra Manda972ee9e2015-08-21 19:08:20 +053048
Ray Milkeyd1c34da2018-06-22 18:10:53 -070049import java.io.IOException;
50import java.util.ArrayList;
51import java.util.List;
52
53import static org.hamcrest.MatcherAssert.assertThat;
54import static org.hamcrest.Matchers.nullValue;
55import static org.hamcrest.core.Is.is;
56import static org.hamcrest.core.IsNot.not;
57import static org.onosproject.net.DefaultAnnotations.EMPTY;
58import static org.onosproject.pcep.server.LspType.SR_WITHOUT_SIGNALLING;
59import static org.onosproject.pcep.server.LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR;
60import static org.onosproject.pcep.server.LspType.WITH_SIGNALLING;
61import static org.onosproject.pcep.server.PcepAnnotationKeys.LSP_SIG_TYPE;
62
Priyanka Bd2b28882016-04-04 16:57:04 +053063/**
64 * Test for PCEP release tunnel.
65 */
Phanendra Manda972ee9e2015-08-21 19:08:20 +053066public class PcepReleaseTunnelProviderTest {
67
Brian Stanke9a108972016-04-11 15:25:17 -040068 private static final String PROVIDER_ID = "org.onosproject.provider.tunnel.pcep";
Priyanka Bd2b28882016-04-04 16:57:04 +053069 private PcepTunnelProvider tunnelProvider = new PcepTunnelProvider();
Phanendra Manda972ee9e2015-08-21 19:08:20 +053070 private final TunnelProviderRegistryAdapter registry = new TunnelProviderRegistryAdapter();
71 private final PcepClientControllerAdapter controller = new PcepClientControllerAdapter();
72 private final PcepControllerAdapter ctl = new PcepControllerAdapter();
73 private final PcepTunnelApiMapper pcepTunnelAPIMapper = new PcepTunnelApiMapper();
Ray Milkeyd1c34da2018-06-22 18:10:53 -070074 private final TunnelServiceAdapter tunnelService = new TunnelServiceAdapter();
Priyanka B413fbe82016-05-26 11:44:45 +053075 private final DeviceServiceAdapter deviceService = new DeviceServiceAdapter();
76 private final MastershipServiceAdapter mastershipService = new MastershipServiceAdapter();
Phanendra Manda972ee9e2015-08-21 19:08:20 +053077
Priyanka Bd2b28882016-04-04 16:57:04 +053078 @Before
79 public void setUp() throws IOException {
Phanendra Manda972ee9e2015-08-21 19:08:20 +053080 tunnelProvider.tunnelProviderRegistry = registry;
81 tunnelProvider.pcepClientController = controller;
82 tunnelProvider.controller = ctl;
Priyanka B413fbe82016-05-26 11:44:45 +053083 tunnelProvider.deviceService = deviceService;
84 tunnelProvider.mastershipService = mastershipService;
chengfan2fff70f2015-08-24 18:20:19 -050085 tunnelProvider.tunnelService = tunnelService;
Jonathan Hart51539b82015-10-29 09:53:04 -070086 tunnelProvider.pcepTunnelApiMapper = pcepTunnelAPIMapper;
chengfan2fff70f2015-08-24 18:20:19 -050087 tunnelProvider.cfgService = new ComponentConfigAdapter();
Phanendra Manda972ee9e2015-08-21 19:08:20 +053088 tunnelProvider.activate();
Priyanka Bd2b28882016-04-04 16:57:04 +053089 }
Phanendra Manda972ee9e2015-08-21 19:08:20 +053090
Priyanka Bd2b28882016-04-04 16:57:04 +053091 /**
92 * Release tunnel with negotiated capability.
93 */
94 @Test
95 public void testCasePcepReleaseTunnel() {
Phanendra Manda972ee9e2015-08-21 19:08:20 +053096 Tunnel tunnel;
97 Path path;
Avantika-Huawei56c11842016-04-28 00:56:56 +053098 List<Link> links = new ArrayList<>();
Phanendra Manda972ee9e2015-08-21 19:08:20 +053099
100 ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
101
102 IpAddress srcIp = IpAddress.valueOf(0xB6024E20);
103 IpElementId srcElementId = IpElementId.ipElement(srcIp);
104
105 IpAddress dstIp = IpAddress.valueOf(0xB6024E21);
106 IpElementId dstElementId = IpElementId.ipElement(dstIp);
107
108 IpTunnelEndPoint ipTunnelEndPointSrc;
109 ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp);
110
111 IpTunnelEndPoint ipTunnelEndPointDst;
112 ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp);
113
114 ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023));
115
116 ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023));
117
Ray Milkey2693bda2016-01-22 16:08:14 -0800118 Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
119 .type(Link.Type.DIRECT).build();
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530120 links.add(link);
121
Ray Milkeya7cf8c82018-02-08 15:07:06 -0800122 path = new DefaultPath(pid, links, ScalarWeight.toWeight(20), EMPTY);
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530123
Avantika-Huawei56c11842016-04-28 00:56:56 +0530124 Annotations annotations = DefaultAnnotations.builder()
125 .set(LSP_SIG_TYPE, WITH_SIGNALLING.name())
126 .build();
127
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530128 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
Yi Tsengfa394de2017-02-01 11:26:40 -0800129 new GroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
Avantika-Huawei56c11842016-04-28 00:56:56 +0530130 path, annotations);
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530131
132 // for releasing tunnel tunnel should exist in db
133 PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, RequestType.DELETE);
134 pcepTunnelData.setPlspId(1);
Avantika-Huawei56c11842016-04-28 00:56:56 +0530135 StatefulIPv4LspIdentifiersTlv tlv = new StatefulIPv4LspIdentifiersTlv(0, (short) 1, (short) 2, 3, 4);
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530136 pcepTunnelData.setStatefulIpv4IndentifierTlv(tlv);
Jonathan Hart51539b82015-10-29 09:53:04 -0700137 tunnelProvider.pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530138
Jonathan Hart51539b82015-10-29 09:53:04 -0700139 tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData);
Priyanka B413fbe82016-05-26 11:44:45 +0530140 controller.getClient(PccId.pccId(IpAddress.valueOf(0xB6024E20))).setCapability(
141 new ClientCapability(true, true, true, true, true));
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530142
143 tunnelProvider.releaseTunnel(tunnel);
Priyanka Bd2b28882016-04-04 16:57:04 +0530144 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530145 }
146
Priyanka Bd2b28882016-04-04 16:57:04 +0530147 /**
148 * Doesn't send initiate message because PCC doesn't supports PCInitiate and stateful capability.
149 */
150 @Test
151 public void testCasePcepReleaseTunnel2() {
152 Tunnel tunnel;
153 Path path;
Avantika-Huawei56c11842016-04-28 00:56:56 +0530154 List<Link> links = new ArrayList<>();
Priyanka Bd2b28882016-04-04 16:57:04 +0530155
156 ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
157
158 IpAddress srcIp = IpAddress.valueOf(0xB6024E22);
159 IpElementId srcElementId = IpElementId.ipElement(srcIp);
160
161 IpAddress dstIp = IpAddress.valueOf(0xB6024E21);
162 IpElementId dstElementId = IpElementId.ipElement(dstIp);
163
164 IpTunnelEndPoint ipTunnelEndPointSrc;
165 ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp);
166
167 IpTunnelEndPoint ipTunnelEndPointDst;
168 ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp);
169
170 ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023));
171
172 ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023));
173
174 Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
175 .type(Link.Type.DIRECT).build();
176 links.add(link);
177
Ray Milkeya7cf8c82018-02-08 15:07:06 -0800178 path = new DefaultPath(pid, links, ScalarWeight.toWeight(20), EMPTY);
Priyanka Bd2b28882016-04-04 16:57:04 +0530179
Avantika-Huawei56c11842016-04-28 00:56:56 +0530180 Annotations annotations = DefaultAnnotations.builder()
181 .set(LSP_SIG_TYPE, WITH_SIGNALLING.name())
182 .build();
183
Priyanka Bd2b28882016-04-04 16:57:04 +0530184 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
Yi Tsengfa394de2017-02-01 11:26:40 -0800185 new GroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
Avantika-Huawei56c11842016-04-28 00:56:56 +0530186 path, annotations);
Priyanka Bd2b28882016-04-04 16:57:04 +0530187
188 // for releasing tunnel tunnel should exist in db
189 PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, RequestType.DELETE);
190 pcepTunnelData.setPlspId(1);
Avantika-Huawei56c11842016-04-28 00:56:56 +0530191 StatefulIPv4LspIdentifiersTlv tlv = new StatefulIPv4LspIdentifiersTlv(0, (short) 1, (short) 2, 3, 4);
Priyanka Bd2b28882016-04-04 16:57:04 +0530192 pcepTunnelData.setStatefulIpv4IndentifierTlv(tlv);
193 tunnelProvider.pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
194
195 tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData);
Priyanka B413fbe82016-05-26 11:44:45 +0530196 controller.getClient(PccId.pccId(IpAddress.valueOf(0xB6024E22))).setCapability(
197 new ClientCapability(true, false, false, true, true));
Priyanka Bd2b28882016-04-04 16:57:04 +0530198
199 tunnelProvider.releaseTunnel(tunnel);
200 assertThat(tunnelProvider.pcepTunnelApiMapper.checkFromTunnelRequestQueue(1), is(false));
201 }
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530202
Avantika-Huawei56c11842016-04-28 00:56:56 +0530203 /**
204 * Tests releasing SR based tunnel.
205 */
206 @Test
207 public void testCasePcepReleaseSrTunnel() {
208 Tunnel tunnel;
209 Path path;
210 List<Link> links = new ArrayList<>();
211
212 ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
213
214 IpAddress srcIp = IpAddress.valueOf(0xB6024E20);
215 IpElementId srcElementId = IpElementId.ipElement(srcIp);
216
217 IpAddress dstIp = IpAddress.valueOf(0xB6024E21);
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
Ray Milkeya7cf8c82018-02-08 15:07:06 -0800234 path = new DefaultPath(pid, links, ScalarWeight.toWeight(20), EMPTY);
Avantika-Huawei56c11842016-04-28 00:56:56 +0530235
236 Annotations annotations = DefaultAnnotations.builder()
237 .set(LSP_SIG_TYPE, SR_WITHOUT_SIGNALLING.name())
238 .build();
239
240 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
Yi Tsengfa394de2017-02-01 11:26:40 -0800241 new GroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
Avantika-Huawei56c11842016-04-28 00:56:56 +0530242 path, annotations);
243
244 // for releasing tunnel tunnel should exist in db
245 PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, RequestType.DELETE);
246 pcepTunnelData.setPlspId(1);
247 StatefulIPv4LspIdentifiersTlv tlv = new StatefulIPv4LspIdentifiersTlv(0, (short) 1, (short) 2, 3, 4);
248 pcepTunnelData.setStatefulIpv4IndentifierTlv(tlv);
249 tunnelProvider.pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
250
251 tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData);
Priyanka B413fbe82016-05-26 11:44:45 +0530252 controller.getClient(PccId.pccId(IpAddress.valueOf(0xB6024E20))).setCapability(
253 new ClientCapability(true, true, true, true, true));
Avantika-Huawei56c11842016-04-28 00:56:56 +0530254
255 tunnelProvider.releaseTunnel(tunnel);
256 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
257 }
258
259 /**
260 * Tests releasing tunnel without SR and without signalling.
261 */
262 @Test
263 public void testCasePcepReleaseTunnelWithoutSigSr() {
264 Tunnel tunnel;
265 Path path;
266 List<Link> links = new ArrayList<>();
267
268 ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
269
270 IpAddress srcIp = IpAddress.valueOf(0xB6024E20);
271 IpElementId srcElementId = IpElementId.ipElement(srcIp);
272
273 IpAddress dstIp = IpAddress.valueOf(0xB6024E21);
274 IpElementId dstElementId = IpElementId.ipElement(dstIp);
275
276 IpTunnelEndPoint ipTunnelEndPointSrc;
277 ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp);
278
279 IpTunnelEndPoint ipTunnelEndPointDst;
280 ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp);
281
282 ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023));
283
284 ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023));
285
286 Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
287 .type(Link.Type.DIRECT).build();
288 links.add(link);
289
Ray Milkeya7cf8c82018-02-08 15:07:06 -0800290 path = new DefaultPath(pid, links, ScalarWeight.toWeight(20), EMPTY);
Avantika-Huawei56c11842016-04-28 00:56:56 +0530291
292 Annotations annotations = DefaultAnnotations.builder()
293 .set(LSP_SIG_TYPE, WITHOUT_SIGNALLING_AND_WITHOUT_SR.name())
294 .build();
295
296 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
Yi Tsengfa394de2017-02-01 11:26:40 -0800297 new GroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
Avantika-Huawei56c11842016-04-28 00:56:56 +0530298 path, annotations);
299
300 // for releasing tunnel tunnel should exist in db
301 PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, RequestType.DELETE);
302 pcepTunnelData.setPlspId(1);
303 StatefulIPv4LspIdentifiersTlv tlv = new StatefulIPv4LspIdentifiersTlv(0, (short) 1, (short) 2, 3, 4);
304 pcepTunnelData.setStatefulIpv4IndentifierTlv(tlv);
305 tunnelProvider.pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
306
307 tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData);
Priyanka B413fbe82016-05-26 11:44:45 +0530308 controller.getClient(PccId.pccId(IpAddress.valueOf(0xB6024E20))).setCapability(
309 new ClientCapability(true, true, true, true, true));
Avantika-Huawei56c11842016-04-28 00:56:56 +0530310
311 tunnelProvider.releaseTunnel(tunnel);
312 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
313 }
314
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530315 @After
316 public void tearDown() throws IOException {
317 tunnelProvider.deactivate();
318 tunnelProvider.controller = null;
319 tunnelProvider.pcepClientController = null;
320 tunnelProvider.tunnelProviderRegistry = null;
Priyanka B413fbe82016-05-26 11:44:45 +0530321 tunnelProvider.deviceService = null;
322 tunnelProvider.mastershipService = null;
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530323 }
324}