blob: 2c9961f4ee5a289ec52d0a1fe6dae6dca43f3b7a [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;
Avantika-Huawei56c11842016-04-28 00:56:56 +053050import org.onosproject.pcepio.types.StatefulIPv4LspIdentifiersTlv;
Phanendra Manda972ee9e2015-08-21 19:08:20 +053051
Avantika-Huawei56c11842016-04-28 00:56:56 +053052import static org.onosproject.provider.pcep.tunnel.impl.LspType.WITH_SIGNALLING;
53import static org.onosproject.provider.pcep.tunnel.impl.LspType.SR_WITHOUT_SIGNALLING;
54import static org.onosproject.provider.pcep.tunnel.impl.LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR;
Priyanka Bd2b28882016-04-04 16:57:04 +053055/**
56 * Test for PCEP update tunnel.
57 */
Phanendra Manda972ee9e2015-08-21 19:08:20 +053058public class PcepUpdateTunnelProviderTest {
59
Brian Stanke9a108972016-04-11 15:25:17 -040060 private static final String PROVIDER_ID = "org.onosproject.provider.tunnel.pcep";
Priyanka Bd2b28882016-04-04 16:57:04 +053061 private PcepTunnelProvider tunnelProvider = new PcepTunnelProvider();
Phanendra Manda972ee9e2015-08-21 19:08:20 +053062 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();
chengfan2fff70f2015-08-24 18:20:19 -050066 private final TunnelServiceAdapter tunnelService = new TunnelServiceAdapter();
67
Priyanka Bd2b28882016-04-04 16:57:04 +053068 @Before
69 public void setUp() throws IOException {
Phanendra Manda972ee9e2015-08-21 19:08:20 +053070 tunnelProvider.tunnelProviderRegistry = registry;
71 tunnelProvider.pcepClientController = controller;
72 tunnelProvider.controller = ctl;
Jonathan Hart51539b82015-10-29 09:53:04 -070073 tunnelProvider.pcepTunnelApiMapper = pcepTunnelAPIMapper;
chengfan2fff70f2015-08-24 18:20:19 -050074 tunnelProvider.cfgService = new ComponentConfigAdapter();
75 tunnelProvider.tunnelService = tunnelService;
Phanendra Manda972ee9e2015-08-21 19:08:20 +053076 tunnelProvider.activate();
Priyanka Bd2b28882016-04-04 16:57:04 +053077 }
Phanendra Manda972ee9e2015-08-21 19:08:20 +053078
Priyanka Bd2b28882016-04-04 16:57:04 +053079 /**
80 * Send update message to PCC.
81 */
82 @Test
83 public void testCasePcepUpdateTunnel() {
Phanendra Manda972ee9e2015-08-21 19:08:20 +053084 Tunnel tunnel;
85 Path path;
86 ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
Avantika-Huawei56c11842016-04-28 00:56:56 +053087 List<Link> links = new ArrayList<>();
Phanendra Manda972ee9e2015-08-21 19:08:20 +053088 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 Milkey2693bda2016-01-22 16:08:14 -0800104 Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
105 .type(Link.Type.DIRECT).build();
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530106 links.add(link);
107
108 path = new DefaultPath(pid, links, 20, EMPTY);
109
Avantika-Huawei56c11842016-04-28 00:56:56 +0530110 Annotations annotations = DefaultAnnotations.builder()
111 .set(LSP_SIG_TYPE, WITH_SIGNALLING.name())
112 .build();
113
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530114 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
Brian Stanke9a108972016-04-11 15:25:17 -0400115 new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
Avantika-Huawei56c11842016-04-28 00:56:56 +0530116 path, annotations);
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530117
118 // for updating tunnel tunnel should exist in db
119 PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, RequestType.UPDATE);
120 pcepTunnelData.setPlspId(1);
Avantika-Huawei56c11842016-04-28 00:56:56 +0530121 StatefulIPv4LspIdentifiersTlv tlv = new StatefulIPv4LspIdentifiersTlv(0, (short) 1, (short) 2, 3, 4);
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530122 pcepTunnelData.setStatefulIpv4IndentifierTlv(tlv);
Jonathan Hart51539b82015-10-29 09:53:04 -0700123 tunnelProvider.pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530124
Jonathan Hart51539b82015-10-29 09:53:04 -0700125 tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData);
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530126
127 tunnelProvider.updateTunnel(tunnel, path);
Priyanka Bd2b28882016-04-04 16:57:04 +0530128 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-Huawei56c11842016-04-28 00:56:56 +0530139 List<Link> links = new ArrayList<>();
Priyanka Bd2b28882016-04-04 16:57:04 +0530140 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-Huawei56c11842016-04-28 00:56:56 +0530162 Annotations annotations = DefaultAnnotations.builder()
163 .set(LSP_SIG_TYPE, WITH_SIGNALLING.name())
164 .build();
165
Priyanka Bd2b28882016-04-04 16:57:04 +0530166 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
Brian Stanke9a108972016-04-11 15:25:17 -0400167 new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
Avantika-Huawei56c11842016-04-28 00:56:56 +0530168 path, annotations);
Priyanka Bd2b28882016-04-04 16:57:04 +0530169
170 // for updating tunnel tunnel should exist in db
171 PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, RequestType.UPDATE);
172 pcepTunnelData.setPlspId(1);
Avantika-Huawei56c11842016-04-28 00:56:56 +0530173 StatefulIPv4LspIdentifiersTlv tlv = new StatefulIPv4LspIdentifiersTlv(0, (short) 1, (short) 2, 3, 4);
Priyanka Bd2b28882016-04-04 16:57:04 +0530174 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 Manda972ee9e2015-08-21 19:08:20 +0530181 }
182
Avantika-Huawei56c11842016-04-28 00:56:56 +0530183 /**
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 Manda972ee9e2015-08-21 19:08:20 +0530287 @After
288 public void tearDown() throws IOException {
289 tunnelProvider.deactivate();
290 tunnelProvider.controller = null;
291 tunnelProvider.pcepClientController = null;
292 tunnelProvider.tunnelProviderRegistry = null;
293 }
294}