blob: abef4039fca89d10f16baffbbd7ed2a980b3ad6a [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
Priyanka Bd2b28882016-04-04 16:57:04 +053018import static org.hamcrest.MatcherAssert.assertThat;
19import static org.hamcrest.Matchers.nullValue;
20import static org.hamcrest.core.Is.is;
21import static org.hamcrest.core.IsNot.not;
Phanendra Manda972ee9e2015-08-21 19:08:20 +053022import static org.onosproject.net.DefaultAnnotations.EMPTY;
harikrushna-Huawei6ecfc772017-04-10 18:22:00 +053023import static org.onosproject.pcep.server.PcepAnnotationKeys.LSP_SIG_TYPE;
24import static org.onosproject.pcep.server.PcepAnnotationKeys.LOCAL_LSP_ID;
25import static org.onosproject.pcep.server.PcepAnnotationKeys.PLSP_ID;
Phanendra Manda972ee9e2015-08-21 19:08:20 +053026
27import java.io.IOException;
28import java.util.ArrayList;
29import java.util.List;
30
31import org.junit.After;
Priyanka Bd2b28882016-04-04 16:57:04 +053032import org.junit.Before;
Phanendra Manda972ee9e2015-08-21 19:08:20 +053033import org.junit.Test;
34import org.onlab.packet.IpAddress;
chengfan2fff70f2015-08-24 18:20:19 -050035import org.onosproject.cfg.ComponentConfigAdapter;
Yi Tsengfa394de2017-02-01 11:26:40 -080036import org.onosproject.core.GroupId;
Phanendra Manda972ee9e2015-08-21 19:08:20 +053037import org.onosproject.incubator.net.tunnel.DefaultTunnel;
38import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint;
39import org.onosproject.incubator.net.tunnel.Tunnel;
40import org.onosproject.incubator.net.tunnel.TunnelId;
41import org.onosproject.incubator.net.tunnel.TunnelName;
Avantika-Huawei56c11842016-04-28 00:56:56 +053042import org.onosproject.net.Annotations;
Phanendra Manda972ee9e2015-08-21 19:08:20 +053043import org.onosproject.net.ConnectPoint;
Avantika-Huawei56c11842016-04-28 00:56:56 +053044import org.onosproject.net.DefaultAnnotations;
Phanendra Manda972ee9e2015-08-21 19:08:20 +053045import org.onosproject.net.DefaultLink;
46import org.onosproject.net.DefaultPath;
47import org.onosproject.net.IpElementId;
48import org.onosproject.net.Link;
49import org.onosproject.net.Path;
50import org.onosproject.net.PortNumber;
51import org.onosproject.net.provider.ProviderId;
harikrushna-Huawei6ecfc772017-04-10 18:22:00 +053052import org.onosproject.pcep.server.ClientCapability;
53import org.onosproject.pcep.server.LspKey;
54import org.onosproject.pcep.server.PccId;
Priyanka B413fbe82016-05-26 11:44:45 +053055import org.onosproject.pcepio.protocol.PcepVersion;
Avantika-Huawei56c11842016-04-28 00:56:56 +053056import org.onosproject.pcepio.types.StatefulIPv4LspIdentifiersTlv;
Phanendra Manda972ee9e2015-08-21 19:08:20 +053057
harikrushna-Huawei6ecfc772017-04-10 18:22:00 +053058import static org.onosproject.pcep.server.LspType.WITH_SIGNALLING;
59import static org.onosproject.pcep.server.LspType.SR_WITHOUT_SIGNALLING;
60import static org.onosproject.pcep.server.LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR;
Priyanka Bd2b28882016-04-04 16:57:04 +053061/**
62 * Test for PCEP update tunnel.
63 */
Phanendra Manda972ee9e2015-08-21 19:08:20 +053064public class PcepUpdateTunnelProviderTest {
65
Brian Stanke9a108972016-04-11 15:25:17 -040066 private static final String PROVIDER_ID = "org.onosproject.provider.tunnel.pcep";
Priyanka Bd2b28882016-04-04 16:57:04 +053067 private PcepTunnelProvider tunnelProvider = new PcepTunnelProvider();
Phanendra Manda972ee9e2015-08-21 19:08:20 +053068 private final TunnelProviderRegistryAdapter registry = new TunnelProviderRegistryAdapter();
69 private final PcepClientControllerAdapter controller = new PcepClientControllerAdapter();
70 private final PcepControllerAdapter ctl = new PcepControllerAdapter();
71 private final PcepTunnelApiMapper pcepTunnelAPIMapper = new PcepTunnelApiMapper();
chengfan2fff70f2015-08-24 18:20:19 -050072 private final TunnelServiceAdapter tunnelService = new TunnelServiceAdapter();
73
Priyanka Bd2b28882016-04-04 16:57:04 +053074 @Before
75 public void setUp() throws IOException {
Phanendra Manda972ee9e2015-08-21 19:08:20 +053076 tunnelProvider.tunnelProviderRegistry = registry;
77 tunnelProvider.pcepClientController = controller;
78 tunnelProvider.controller = ctl;
Jonathan Hart51539b82015-10-29 09:53:04 -070079 tunnelProvider.pcepTunnelApiMapper = pcepTunnelAPIMapper;
chengfan2fff70f2015-08-24 18:20:19 -050080 tunnelProvider.cfgService = new ComponentConfigAdapter();
81 tunnelProvider.tunnelService = tunnelService;
Phanendra Manda972ee9e2015-08-21 19:08:20 +053082 tunnelProvider.activate();
Priyanka Bd2b28882016-04-04 16:57:04 +053083 }
Phanendra Manda972ee9e2015-08-21 19:08:20 +053084
Priyanka Bd2b28882016-04-04 16:57:04 +053085 /**
86 * Send update message to PCC.
87 */
88 @Test
89 public void testCasePcepUpdateTunnel() {
Phanendra Manda972ee9e2015-08-21 19:08:20 +053090 Tunnel tunnel;
91 Path path;
92 ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
Avantika-Huawei56c11842016-04-28 00:56:56 +053093 List<Link> links = new ArrayList<>();
Phanendra Manda972ee9e2015-08-21 19:08:20 +053094 IpAddress srcIp = IpAddress.valueOf(0xD010101);
95 IpElementId srcElementId = IpElementId.ipElement(srcIp);
96
97 IpAddress dstIp = IpAddress.valueOf(0xD010102);
98 IpElementId dstElementId = IpElementId.ipElement(dstIp);
99
100 IpTunnelEndPoint ipTunnelEndPointSrc;
101 ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp);
102
103 IpTunnelEndPoint ipTunnelEndPointDst;
104 ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp);
105
106 ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023));
107
Priyanka B413fbe82016-05-26 11:44:45 +0530108 ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10024));
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530109
Ray Milkey2693bda2016-01-22 16:08:14 -0800110 Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
111 .type(Link.Type.DIRECT).build();
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530112 links.add(link);
113
114 path = new DefaultPath(pid, links, 20, EMPTY);
115
Avantika-Huawei56c11842016-04-28 00:56:56 +0530116 Annotations annotations = DefaultAnnotations.builder()
Avantika-Huaweifc10dca2016-06-10 16:13:55 +0530117 .set(PLSP_ID, "1")
118 .set(LOCAL_LSP_ID, "1")
Avantika-Huawei56c11842016-04-28 00:56:56 +0530119 .set(LSP_SIG_TYPE, WITH_SIGNALLING.name())
120 .build();
121
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530122 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
Yi Tsengfa394de2017-02-01 11:26:40 -0800123 new GroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
Avantika-Huawei56c11842016-04-28 00:56:56 +0530124 path, annotations);
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530125
126 // for updating tunnel tunnel should exist in db
127 PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, RequestType.UPDATE);
128 pcepTunnelData.setPlspId(1);
Avantika-Huawei56c11842016-04-28 00:56:56 +0530129 StatefulIPv4LspIdentifiersTlv tlv = new StatefulIPv4LspIdentifiersTlv(0, (short) 1, (short) 2, 3, 4);
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530130 pcepTunnelData.setStatefulIpv4IndentifierTlv(tlv);
Jonathan Hart51539b82015-10-29 09:53:04 -0700131 tunnelProvider.pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530132
Jonathan Hart51539b82015-10-29 09:53:04 -0700133 tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData);
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530134
Priyanka B413fbe82016-05-26 11:44:45 +0530135 PccId pccId = PccId.pccId(IpAddress.valueOf(0xD010101));
136 PcepClientAdapter pc = new PcepClientAdapter();
137 pc.init(pccId, PcepVersion.PCEP_1);
138 controller.getClient(pccId).setLspAndDelegationInfo(new LspKey(1, (short) 1), true);
139 controller.getClient(pccId).setCapability(new ClientCapability(true, true, true, true, true));
140
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530141 tunnelProvider.updateTunnel(tunnel, path);
Priyanka Bd2b28882016-04-04 16:57:04 +0530142 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
143 }
144
145 /**
146 * Doesn't send update message because PCC doesn't supports PCE stateful capability.
147 */
148 @Test
149 public void testCasePcepUpdateTunnel2() {
150 Tunnel tunnel;
151 Path path;
152 ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
Avantika-Huawei56c11842016-04-28 00:56:56 +0530153 List<Link> links = new ArrayList<>();
Priyanka B413fbe82016-05-26 11:44:45 +0530154 IpAddress srcIp = IpAddress.valueOf(0xD010101);
Priyanka Bd2b28882016-04-04 16:57:04 +0530155 IpElementId srcElementId = IpElementId.ipElement(srcIp);
156
157 IpAddress dstIp = IpAddress.valueOf(0xD010102);
158 IpElementId dstElementId = IpElementId.ipElement(dstIp);
159
160 IpTunnelEndPoint ipTunnelEndPointSrc;
161 ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp);
162
163 IpTunnelEndPoint ipTunnelEndPointDst;
164 ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp);
165
166 ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023));
167
Priyanka B413fbe82016-05-26 11:44:45 +0530168 ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10024));
Priyanka Bd2b28882016-04-04 16:57:04 +0530169
170 Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
171 .type(Link.Type.DIRECT).build();
172 links.add(link);
173
174 path = new DefaultPath(pid, links, 20, EMPTY);
175
Avantika-Huawei56c11842016-04-28 00:56:56 +0530176 Annotations annotations = DefaultAnnotations.builder()
177 .set(LSP_SIG_TYPE, WITH_SIGNALLING.name())
Avantika-Huaweifc10dca2016-06-10 16:13:55 +0530178 .set(PLSP_ID, "1")
179 .set(LOCAL_LSP_ID, "1")
Avantika-Huawei56c11842016-04-28 00:56:56 +0530180 .build();
181
Priyanka Bd2b28882016-04-04 16:57:04 +0530182 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
Yi Tsengfa394de2017-02-01 11:26:40 -0800183 new GroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
Avantika-Huawei56c11842016-04-28 00:56:56 +0530184 path, annotations);
Priyanka Bd2b28882016-04-04 16:57:04 +0530185
186 // for updating tunnel tunnel should exist in db
187 PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, RequestType.UPDATE);
188 pcepTunnelData.setPlspId(1);
Avantika-Huawei56c11842016-04-28 00:56:56 +0530189 StatefulIPv4LspIdentifiersTlv tlv = new StatefulIPv4LspIdentifiersTlv(0, (short) 1, (short) 2, 3, 4);
Priyanka Bd2b28882016-04-04 16:57:04 +0530190 pcepTunnelData.setStatefulIpv4IndentifierTlv(tlv);
191 tunnelProvider.pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
192
193 tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData);
194
Priyanka B413fbe82016-05-26 11:44:45 +0530195 PccId pccId = PccId.pccId(IpAddress.valueOf(0xD010101));
196 PcepClientAdapter pc = new PcepClientAdapter();
197 pc.init(pccId, PcepVersion.PCEP_1);
198 controller.getClient(pccId).setLspAndDelegationInfo(new LspKey(1, (short) 1), true);
199 controller.getClient(pccId).setCapability(new ClientCapability(true, true, true, true, true));
200
Priyanka Bd2b28882016-04-04 16:57:04 +0530201 tunnelProvider.updateTunnel(tunnel, path);
202 assertThat(tunnelProvider.pcepTunnelApiMapper.checkFromTunnelRequestQueue(1), is(false));
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530203 }
204
Avantika-Huawei56c11842016-04-28 00:56:56 +0530205 /**
206 * Sends update message to PCC for SR based tunnel.
207 */
208 @Test
209 public void testCasePcepUpdateSrTunnel() {
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(0xD010101);
215 IpElementId srcElementId = IpElementId.ipElement(srcIp);
216
217 IpAddress dstIp = IpAddress.valueOf(0xD010102);
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
Priyanka B413fbe82016-05-26 11:44:45 +0530228 ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10024));
Avantika-Huawei56c11842016-04-28 00:56:56 +0530229
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, 20, EMPTY);
235
236 Annotations annotations = DefaultAnnotations.builder()
237 .set(LSP_SIG_TYPE, SR_WITHOUT_SIGNALLING.name())
Avantika-Huaweifc10dca2016-06-10 16:13:55 +0530238 .set(PLSP_ID, "1")
239 .set(LOCAL_LSP_ID, "1")
Avantika-Huawei56c11842016-04-28 00:56:56 +0530240 .build();
241
242 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
Yi Tsengfa394de2017-02-01 11:26:40 -0800243 new GroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
Avantika-Huawei56c11842016-04-28 00:56:56 +0530244 path, annotations);
245
246 // for updating tunnel tunnel should exist in db
247 PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, RequestType.UPDATE);
248 pcepTunnelData.setPlspId(1);
249 StatefulIPv4LspIdentifiersTlv tlv = new StatefulIPv4LspIdentifiersTlv(0, (short) 1, (short) 2, 3, 4);
250 pcepTunnelData.setStatefulIpv4IndentifierTlv(tlv);
251 tunnelProvider.pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
252
253 tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData);
254
Priyanka B413fbe82016-05-26 11:44:45 +0530255 PccId pccId = PccId.pccId(IpAddress.valueOf(0xD010101));
256 PcepClientAdapter pc = new PcepClientAdapter();
257 pc.init(pccId, PcepVersion.PCEP_1);
258 controller.getClient(pccId).setLspAndDelegationInfo(new LspKey(1, (short) 1), true);
259 controller.getClient(pccId).setCapability(new ClientCapability(true, true, true, true, true));
260
Avantika-Huawei56c11842016-04-28 00:56:56 +0530261 tunnelProvider.updateTunnel(tunnel, path);
262 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
263 }
264
265 /**
266 * Sends update message to PCC for tunnel without signalling and without SR.
267 */
268 @Test
269 public void testCasePcepUpdateTunnelWithoutSigSr() {
270 Tunnel tunnel;
271 Path path;
272 ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
273 List<Link> links = new ArrayList<>();
274 IpAddress srcIp = IpAddress.valueOf(0xD010101);
275 IpElementId srcElementId = IpElementId.ipElement(srcIp);
276
277 IpAddress dstIp = IpAddress.valueOf(0xD010102);
278 IpElementId dstElementId = IpElementId.ipElement(dstIp);
279
280 IpTunnelEndPoint ipTunnelEndPointSrc;
281 ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp);
282
283 IpTunnelEndPoint ipTunnelEndPointDst;
284 ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp);
285
286 ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023));
287
Priyanka B413fbe82016-05-26 11:44:45 +0530288 ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10024));
Avantika-Huawei56c11842016-04-28 00:56:56 +0530289
290 Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
291 .type(Link.Type.DIRECT).build();
292 links.add(link);
293
294 path = new DefaultPath(pid, links, 20, EMPTY);
295
296 Annotations annotations = DefaultAnnotations.builder()
297 .set(LSP_SIG_TYPE, WITHOUT_SIGNALLING_AND_WITHOUT_SR.name())
Avantika-Huaweifc10dca2016-06-10 16:13:55 +0530298 .set(PLSP_ID, "1")
299 .set(LOCAL_LSP_ID, "1")
Avantika-Huawei56c11842016-04-28 00:56:56 +0530300 .build();
301
302 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
Yi Tsengfa394de2017-02-01 11:26:40 -0800303 new GroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
Avantika-Huawei56c11842016-04-28 00:56:56 +0530304 path, annotations);
305
306 // for updating tunnel tunnel should exist in db
307 PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, RequestType.UPDATE);
308 pcepTunnelData.setPlspId(1);
309 StatefulIPv4LspIdentifiersTlv tlv = new StatefulIPv4LspIdentifiersTlv(0, (short) 1, (short) 2, 3, 4);
310 pcepTunnelData.setStatefulIpv4IndentifierTlv(tlv);
311 tunnelProvider.pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
312
313 tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData);
314
Priyanka B413fbe82016-05-26 11:44:45 +0530315 PccId pccId = PccId.pccId(IpAddress.valueOf(0xD010101));
316 PcepClientAdapter pc = new PcepClientAdapter();
317 pc.init(pccId, PcepVersion.PCEP_1);
318 controller.getClient(pccId).setLspAndDelegationInfo(new LspKey(1, (short) 1), true);
319 controller.getClient(pccId).setCapability(new ClientCapability(true, true, true, true, true));
320
Avantika-Huawei56c11842016-04-28 00:56:56 +0530321 tunnelProvider.updateTunnel(tunnel, path);
322 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
323 }
324
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530325 @After
326 public void tearDown() throws IOException {
327 tunnelProvider.deactivate();
328 tunnelProvider.controller = null;
329 tunnelProvider.pcepClientController = null;
330 tunnelProvider.tunnelProviderRegistry = null;
331 }
332}