blob: 4106dfbae80f965a22963e51806319cc637eaa02 [file] [log] [blame]
Phanendra Manda972ee9e2015-08-21 19:08:20 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
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;
Avantika-Huawei56c11842016-04-28 00:56:56 +053023import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.LSP_SIG_TYPE;
Phanendra Manda972ee9e2015-08-21 19:08:20 +053024
25import java.io.IOException;
26import java.util.ArrayList;
27import java.util.List;
28
29import org.junit.After;
Priyanka Bd2b28882016-04-04 16:57:04 +053030import org.junit.Before;
Phanendra Manda972ee9e2015-08-21 19:08:20 +053031import org.junit.Test;
32import org.onlab.packet.IpAddress;
chengfan2fff70f2015-08-24 18:20:19 -050033import org.onosproject.cfg.ComponentConfigAdapter;
Phanendra Manda972ee9e2015-08-21 19:08:20 +053034import org.onosproject.core.DefaultGroupId;
35import org.onosproject.incubator.net.tunnel.DefaultTunnel;
36import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint;
37import org.onosproject.incubator.net.tunnel.Tunnel;
38import org.onosproject.incubator.net.tunnel.TunnelId;
39import org.onosproject.incubator.net.tunnel.TunnelName;
Avantika-Huawei56c11842016-04-28 00:56:56 +053040import org.onosproject.net.Annotations;
Phanendra Manda972ee9e2015-08-21 19:08:20 +053041import org.onosproject.net.ConnectPoint;
Avantika-Huawei56c11842016-04-28 00:56:56 +053042import org.onosproject.net.DefaultAnnotations;
Phanendra Manda972ee9e2015-08-21 19:08:20 +053043import org.onosproject.net.DefaultLink;
44import org.onosproject.net.DefaultPath;
45import org.onosproject.net.IpElementId;
46import org.onosproject.net.Link;
47import org.onosproject.net.Path;
48import org.onosproject.net.PortNumber;
49import org.onosproject.net.provider.ProviderId;
Priyanka B413fbe82016-05-26 11:44:45 +053050import org.onosproject.pcep.controller.ClientCapability;
51import org.onosproject.pcep.controller.LspKey;
52import org.onosproject.pcep.controller.PccId;
53import org.onosproject.pcepio.protocol.PcepVersion;
Avantika-Huawei56c11842016-04-28 00:56:56 +053054import org.onosproject.pcepio.types.StatefulIPv4LspIdentifiersTlv;
Phanendra Manda972ee9e2015-08-21 19:08:20 +053055
Avantika-Huawei56c11842016-04-28 00:56:56 +053056import static org.onosproject.provider.pcep.tunnel.impl.LspType.WITH_SIGNALLING;
57import static org.onosproject.provider.pcep.tunnel.impl.LspType.SR_WITHOUT_SIGNALLING;
58import static org.onosproject.provider.pcep.tunnel.impl.LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR;
Priyanka Bd2b28882016-04-04 16:57:04 +053059/**
60 * Test for PCEP update tunnel.
61 */
Phanendra Manda972ee9e2015-08-21 19:08:20 +053062public class PcepUpdateTunnelProviderTest {
63
Brian Stanke9a108972016-04-11 15:25:17 -040064 private static final String PROVIDER_ID = "org.onosproject.provider.tunnel.pcep";
Priyanka Bd2b28882016-04-04 16:57:04 +053065 private PcepTunnelProvider tunnelProvider = new PcepTunnelProvider();
Phanendra Manda972ee9e2015-08-21 19:08:20 +053066 private final TunnelProviderRegistryAdapter registry = new TunnelProviderRegistryAdapter();
67 private final PcepClientControllerAdapter controller = new PcepClientControllerAdapter();
68 private final PcepControllerAdapter ctl = new PcepControllerAdapter();
69 private final PcepTunnelApiMapper pcepTunnelAPIMapper = new PcepTunnelApiMapper();
chengfan2fff70f2015-08-24 18:20:19 -050070 private final TunnelServiceAdapter tunnelService = new TunnelServiceAdapter();
71
Priyanka Bd2b28882016-04-04 16:57:04 +053072 @Before
73 public void setUp() throws IOException {
Phanendra Manda972ee9e2015-08-21 19:08:20 +053074 tunnelProvider.tunnelProviderRegistry = registry;
75 tunnelProvider.pcepClientController = controller;
76 tunnelProvider.controller = ctl;
Jonathan Hart51539b82015-10-29 09:53:04 -070077 tunnelProvider.pcepTunnelApiMapper = pcepTunnelAPIMapper;
chengfan2fff70f2015-08-24 18:20:19 -050078 tunnelProvider.cfgService = new ComponentConfigAdapter();
79 tunnelProvider.tunnelService = tunnelService;
Phanendra Manda972ee9e2015-08-21 19:08:20 +053080 tunnelProvider.activate();
Priyanka Bd2b28882016-04-04 16:57:04 +053081 }
Phanendra Manda972ee9e2015-08-21 19:08:20 +053082
Priyanka Bd2b28882016-04-04 16:57:04 +053083 /**
84 * Send update message to PCC.
85 */
86 @Test
87 public void testCasePcepUpdateTunnel() {
Phanendra Manda972ee9e2015-08-21 19:08:20 +053088 Tunnel tunnel;
89 Path path;
90 ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
Avantika-Huawei56c11842016-04-28 00:56:56 +053091 List<Link> links = new ArrayList<>();
Phanendra Manda972ee9e2015-08-21 19:08:20 +053092 IpAddress srcIp = IpAddress.valueOf(0xD010101);
93 IpElementId srcElementId = IpElementId.ipElement(srcIp);
94
95 IpAddress dstIp = IpAddress.valueOf(0xD010102);
96 IpElementId dstElementId = IpElementId.ipElement(dstIp);
97
98 IpTunnelEndPoint ipTunnelEndPointSrc;
99 ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp);
100
101 IpTunnelEndPoint ipTunnelEndPointDst;
102 ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp);
103
104 ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023));
105
Priyanka B413fbe82016-05-26 11:44:45 +0530106 ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10024));
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530107
Ray Milkey2693bda2016-01-22 16:08:14 -0800108 Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
109 .type(Link.Type.DIRECT).build();
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530110 links.add(link);
111
112 path = new DefaultPath(pid, links, 20, EMPTY);
113
Avantika-Huawei56c11842016-04-28 00:56:56 +0530114 Annotations annotations = DefaultAnnotations.builder()
Priyanka B413fbe82016-05-26 11:44:45 +0530115 .set(PcepAnnotationKeys.PLSP_ID, "1")
116 .set(PcepAnnotationKeys.LOCAL_LSP_ID, "1")
Avantika-Huawei56c11842016-04-28 00:56:56 +0530117 .set(LSP_SIG_TYPE, WITH_SIGNALLING.name())
118 .build();
119
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530120 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
Brian Stanke9a108972016-04-11 15:25:17 -0400121 new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
Avantika-Huawei56c11842016-04-28 00:56:56 +0530122 path, annotations);
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530123
124 // for updating tunnel tunnel should exist in db
125 PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, RequestType.UPDATE);
126 pcepTunnelData.setPlspId(1);
Avantika-Huawei56c11842016-04-28 00:56:56 +0530127 StatefulIPv4LspIdentifiersTlv tlv = new StatefulIPv4LspIdentifiersTlv(0, (short) 1, (short) 2, 3, 4);
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530128 pcepTunnelData.setStatefulIpv4IndentifierTlv(tlv);
Jonathan Hart51539b82015-10-29 09:53:04 -0700129 tunnelProvider.pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530130
Jonathan Hart51539b82015-10-29 09:53:04 -0700131 tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData);
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530132
Priyanka B413fbe82016-05-26 11:44:45 +0530133 PccId pccId = PccId.pccId(IpAddress.valueOf(0xD010101));
134 PcepClientAdapter pc = new PcepClientAdapter();
135 pc.init(pccId, PcepVersion.PCEP_1);
136 controller.getClient(pccId).setLspAndDelegationInfo(new LspKey(1, (short) 1), true);
137 controller.getClient(pccId).setCapability(new ClientCapability(true, true, true, true, true));
138
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530139 tunnelProvider.updateTunnel(tunnel, path);
Priyanka Bd2b28882016-04-04 16:57:04 +0530140 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
141 }
142
143 /**
144 * Doesn't send update message because PCC doesn't supports PCE stateful capability.
145 */
146 @Test
147 public void testCasePcepUpdateTunnel2() {
148 Tunnel tunnel;
149 Path path;
150 ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
Avantika-Huawei56c11842016-04-28 00:56:56 +0530151 List<Link> links = new ArrayList<>();
Priyanka B413fbe82016-05-26 11:44:45 +0530152 IpAddress srcIp = IpAddress.valueOf(0xD010101);
Priyanka Bd2b28882016-04-04 16:57:04 +0530153 IpElementId srcElementId = IpElementId.ipElement(srcIp);
154
155 IpAddress dstIp = IpAddress.valueOf(0xD010102);
156 IpElementId dstElementId = IpElementId.ipElement(dstIp);
157
158 IpTunnelEndPoint ipTunnelEndPointSrc;
159 ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp);
160
161 IpTunnelEndPoint ipTunnelEndPointDst;
162 ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp);
163
164 ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023));
165
Priyanka B413fbe82016-05-26 11:44:45 +0530166 ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10024));
Priyanka Bd2b28882016-04-04 16:57:04 +0530167
168 Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
169 .type(Link.Type.DIRECT).build();
170 links.add(link);
171
172 path = new DefaultPath(pid, links, 20, EMPTY);
173
Avantika-Huawei56c11842016-04-28 00:56:56 +0530174 Annotations annotations = DefaultAnnotations.builder()
175 .set(LSP_SIG_TYPE, WITH_SIGNALLING.name())
Priyanka B413fbe82016-05-26 11:44:45 +0530176 .set(PcepAnnotationKeys.PLSP_ID, "1")
177 .set(PcepAnnotationKeys.LOCAL_LSP_ID, "1")
Avantika-Huawei56c11842016-04-28 00:56:56 +0530178 .build();
179
Priyanka Bd2b28882016-04-04 16:57:04 +0530180 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
Brian Stanke9a108972016-04-11 15:25:17 -0400181 new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
Avantika-Huawei56c11842016-04-28 00:56:56 +0530182 path, annotations);
Priyanka Bd2b28882016-04-04 16:57:04 +0530183
184 // for updating tunnel tunnel should exist in db
185 PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, RequestType.UPDATE);
186 pcepTunnelData.setPlspId(1);
Avantika-Huawei56c11842016-04-28 00:56:56 +0530187 StatefulIPv4LspIdentifiersTlv tlv = new StatefulIPv4LspIdentifiersTlv(0, (short) 1, (short) 2, 3, 4);
Priyanka Bd2b28882016-04-04 16:57:04 +0530188 pcepTunnelData.setStatefulIpv4IndentifierTlv(tlv);
189 tunnelProvider.pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
190
191 tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData);
192
Priyanka B413fbe82016-05-26 11:44:45 +0530193 PccId pccId = PccId.pccId(IpAddress.valueOf(0xD010101));
194 PcepClientAdapter pc = new PcepClientAdapter();
195 pc.init(pccId, PcepVersion.PCEP_1);
196 controller.getClient(pccId).setLspAndDelegationInfo(new LspKey(1, (short) 1), true);
197 controller.getClient(pccId).setCapability(new ClientCapability(true, true, true, true, true));
198
Priyanka Bd2b28882016-04-04 16:57:04 +0530199 tunnelProvider.updateTunnel(tunnel, path);
200 assertThat(tunnelProvider.pcepTunnelApiMapper.checkFromTunnelRequestQueue(1), is(false));
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530201 }
202
Avantika-Huawei56c11842016-04-28 00:56:56 +0530203 /**
204 * Sends update message to PCC for SR based tunnel.
205 */
206 @Test
207 public void testCasePcepUpdateSrTunnel() {
208 Tunnel tunnel;
209 Path path;
210 ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
211 List<Link> links = new ArrayList<>();
212 IpAddress srcIp = IpAddress.valueOf(0xD010101);
213 IpElementId srcElementId = IpElementId.ipElement(srcIp);
214
215 IpAddress dstIp = IpAddress.valueOf(0xD010102);
216 IpElementId dstElementId = IpElementId.ipElement(dstIp);
217
218 IpTunnelEndPoint ipTunnelEndPointSrc;
219 ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp);
220
221 IpTunnelEndPoint ipTunnelEndPointDst;
222 ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp);
223
224 ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023));
225
Priyanka B413fbe82016-05-26 11:44:45 +0530226 ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10024));
Avantika-Huawei56c11842016-04-28 00:56:56 +0530227
228 Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
229 .type(Link.Type.DIRECT).build();
230 links.add(link);
231
232 path = new DefaultPath(pid, links, 20, EMPTY);
233
234 Annotations annotations = DefaultAnnotations.builder()
235 .set(LSP_SIG_TYPE, SR_WITHOUT_SIGNALLING.name())
Priyanka B413fbe82016-05-26 11:44:45 +0530236 .set(PcepAnnotationKeys.PLSP_ID, "1")
237 .set(PcepAnnotationKeys.LOCAL_LSP_ID, "1")
Avantika-Huawei56c11842016-04-28 00:56:56 +0530238 .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 // for updating tunnel tunnel should exist in db
245 PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, RequestType.UPDATE);
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);
252
Priyanka B413fbe82016-05-26 11:44:45 +0530253 PccId pccId = PccId.pccId(IpAddress.valueOf(0xD010101));
254 PcepClientAdapter pc = new PcepClientAdapter();
255 pc.init(pccId, PcepVersion.PCEP_1);
256 controller.getClient(pccId).setLspAndDelegationInfo(new LspKey(1, (short) 1), true);
257 controller.getClient(pccId).setCapability(new ClientCapability(true, true, true, true, true));
258
Avantika-Huawei56c11842016-04-28 00:56:56 +0530259 tunnelProvider.updateTunnel(tunnel, path);
260 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
261 }
262
263 /**
264 * Sends update message to PCC for tunnel without signalling and without SR.
265 */
266 @Test
267 public void testCasePcepUpdateTunnelWithoutSigSr() {
268 Tunnel tunnel;
269 Path path;
270 ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
271 List<Link> links = new ArrayList<>();
272 IpAddress srcIp = IpAddress.valueOf(0xD010101);
273 IpElementId srcElementId = IpElementId.ipElement(srcIp);
274
275 IpAddress dstIp = IpAddress.valueOf(0xD010102);
276 IpElementId dstElementId = IpElementId.ipElement(dstIp);
277
278 IpTunnelEndPoint ipTunnelEndPointSrc;
279 ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp);
280
281 IpTunnelEndPoint ipTunnelEndPointDst;
282 ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp);
283
284 ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023));
285
Priyanka B413fbe82016-05-26 11:44:45 +0530286 ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10024));
Avantika-Huawei56c11842016-04-28 00:56:56 +0530287
288 Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
289 .type(Link.Type.DIRECT).build();
290 links.add(link);
291
292 path = new DefaultPath(pid, links, 20, EMPTY);
293
294 Annotations annotations = DefaultAnnotations.builder()
295 .set(LSP_SIG_TYPE, WITHOUT_SIGNALLING_AND_WITHOUT_SR.name())
Priyanka B413fbe82016-05-26 11:44:45 +0530296 .set(PcepAnnotationKeys.PLSP_ID, "1")
297 .set(PcepAnnotationKeys.LOCAL_LSP_ID, "1")
Avantika-Huawei56c11842016-04-28 00:56:56 +0530298 .build();
299
300 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
301 new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
302 path, annotations);
303
304 // for updating tunnel tunnel should exist in db
305 PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, RequestType.UPDATE);
306 pcepTunnelData.setPlspId(1);
307 StatefulIPv4LspIdentifiersTlv tlv = new StatefulIPv4LspIdentifiersTlv(0, (short) 1, (short) 2, 3, 4);
308 pcepTunnelData.setStatefulIpv4IndentifierTlv(tlv);
309 tunnelProvider.pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
310
311 tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData);
312
Priyanka B413fbe82016-05-26 11:44:45 +0530313 PccId pccId = PccId.pccId(IpAddress.valueOf(0xD010101));
314 PcepClientAdapter pc = new PcepClientAdapter();
315 pc.init(pccId, PcepVersion.PCEP_1);
316 controller.getClient(pccId).setLspAndDelegationInfo(new LspKey(1, (short) 1), true);
317 controller.getClient(pccId).setCapability(new ClientCapability(true, true, true, true, true));
318
Avantika-Huawei56c11842016-04-28 00:56:56 +0530319 tunnelProvider.updateTunnel(tunnel, path);
320 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
321 }
322
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530323 @After
324 public void tearDown() throws IOException {
325 tunnelProvider.deactivate();
326 tunnelProvider.controller = null;
327 tunnelProvider.pcepClientController = null;
328 tunnelProvider.tunnelProviderRegistry = null;
329 }
330}