blob: b02e3e34a688db20df4f6d9130edf76ced2788e5 [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
18import static org.onosproject.net.DefaultAnnotations.EMPTY;
Priyanka Bd2b28882016-04-04 16:57:04 +053019import static org.hamcrest.MatcherAssert.assertThat;
20import static org.hamcrest.core.Is.is;
21import static org.hamcrest.core.IsNot.not;
22import static org.hamcrest.Matchers.nullValue;
harikrushna-Huaweia2c7c202017-04-10 18:22:00 +053023import static org.onosproject.pcep.server.LspType.WITH_SIGNALLING;
24import static org.onosproject.pcep.server.LspType.SR_WITHOUT_SIGNALLING;
25import static org.onosproject.pcep.server.LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR;
26import static org.onosproject.pcep.server.PcepAnnotationKeys.LSP_SIG_TYPE;
Phanendra Manda972ee9e2015-08-21 19:08:20 +053027
28import java.io.IOException;
29import java.util.ArrayList;
30import java.util.List;
31
32import org.junit.After;
Priyanka Bd2b28882016-04-04 16:57:04 +053033import org.junit.Before;
Phanendra Manda972ee9e2015-08-21 19:08:20 +053034import org.junit.Test;
Ray Milkeya7cf8c82018-02-08 15:07:06 -080035import org.onlab.graph.ScalarWeight;
36import org.onlab.graph.Weight;
Phanendra Manda972ee9e2015-08-21 19:08:20 +053037import org.onlab.packet.IpAddress;
chengfan2fff70f2015-08-24 18:20:19 -050038import org.onosproject.cfg.ComponentConfigAdapter;
Yi Tsengfa394de2017-02-01 11:26:40 -080039import org.onosproject.core.GroupId;
Phanendra Manda972ee9e2015-08-21 19:08:20 +053040import org.onosproject.incubator.net.tunnel.DefaultTunnel;
41import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint;
42import org.onosproject.incubator.net.tunnel.Tunnel;
43import org.onosproject.incubator.net.tunnel.TunnelId;
44import org.onosproject.incubator.net.tunnel.TunnelName;
Priyanka B413fbe82016-05-26 11:44:45 +053045import org.onosproject.mastership.MastershipServiceAdapter;
Avantika-Huawei56c11842016-04-28 00:56:56 +053046import org.onosproject.net.Annotations;
Phanendra Manda972ee9e2015-08-21 19:08:20 +053047import org.onosproject.net.ConnectPoint;
Avantika-Huawei56c11842016-04-28 00:56:56 +053048import org.onosproject.net.DefaultAnnotations;
Phanendra Manda972ee9e2015-08-21 19:08:20 +053049import org.onosproject.net.DefaultLink;
50import org.onosproject.net.DefaultPath;
51import org.onosproject.net.IpElementId;
52import org.onosproject.net.Link;
53import org.onosproject.net.Path;
54import org.onosproject.net.PortNumber;
Priyanka B413fbe82016-05-26 11:44:45 +053055import org.onosproject.net.device.DeviceServiceAdapter;
Phanendra Manda972ee9e2015-08-21 19:08:20 +053056import org.onosproject.net.provider.ProviderId;
harikrushna-Huaweia2c7c202017-04-10 18:22:00 +053057import org.onosproject.pcep.server.ClientCapability;
58import org.onosproject.pcep.server.PccId;
Phanendra Manda972ee9e2015-08-21 19:08:20 +053059
Priyanka Bd2b28882016-04-04 16:57:04 +053060/**
61 * Test for PCEP setup tunnel.
62 */
Phanendra Manda972ee9e2015-08-21 19:08:20 +053063public class PcepSetupTunnelProviderTest {
64
Brian Stanke9a108972016-04-11 15:25:17 -040065 private static final String PROVIDER_ID = "org.onosproject.provider.tunnel.pcep";
Priyanka Bd2b28882016-04-04 16:57:04 +053066 private PcepTunnelProvider tunnelProvider = new PcepTunnelProvider();
Phanendra Manda972ee9e2015-08-21 19:08:20 +053067 private final TunnelProviderRegistryAdapter registry = new TunnelProviderRegistryAdapter();
68 private final PcepClientControllerAdapter controller = new PcepClientControllerAdapter();
69 private final PcepControllerAdapter ctl = new PcepControllerAdapter();
chengfan2fff70f2015-08-24 18:20:19 -050070 private final TunnelServiceAdapter tunnelService = new TunnelServiceAdapter();
Priyanka B413fbe82016-05-26 11:44:45 +053071 private final DeviceServiceAdapter deviceService = new DeviceServiceAdapter();
72 private final MastershipServiceAdapter mastershipService = new MastershipServiceAdapter();
Ray Milkeya7cf8c82018-02-08 15:07:06 -080073 private static final Weight TEN_WEIGHT = ScalarWeight.toWeight(10);
74
Phanendra Manda972ee9e2015-08-21 19:08:20 +053075
Priyanka Bd2b28882016-04-04 16:57:04 +053076 @Before
77 public void setUp() throws IOException {
Phanendra Manda972ee9e2015-08-21 19:08:20 +053078 tunnelProvider.tunnelProviderRegistry = registry;
79 tunnelProvider.pcepClientController = controller;
80 tunnelProvider.controller = ctl;
Priyanka B413fbe82016-05-26 11:44:45 +053081 tunnelProvider.deviceService = deviceService;
82 tunnelProvider.mastershipService = mastershipService;
chengfan2fff70f2015-08-24 18:20:19 -050083 tunnelProvider.cfgService = new ComponentConfigAdapter();
84 tunnelProvider.tunnelService = tunnelService;
Phanendra Manda972ee9e2015-08-21 19:08:20 +053085 tunnelProvider.activate();
Priyanka Bd2b28882016-04-04 16:57:04 +053086 }
Phanendra Manda972ee9e2015-08-21 19:08:20 +053087
Priyanka Bd2b28882016-04-04 16:57:04 +053088 /**
89 * Send PcInitiate message to PCC.
90 */
91 @Test
92 public void testCasePcepSetupTunnel() {
Phanendra Manda972ee9e2015-08-21 19:08:20 +053093 Tunnel tunnel;
94 Path path;
95 ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
Avantika-Huawei56c11842016-04-28 00:56:56 +053096 List<Link> links = new ArrayList<>();
Phanendra Manda972ee9e2015-08-21 19:08:20 +053097 IpAddress srcIp = IpAddress.valueOf(0xC010101);
98 IpElementId srcElementId = IpElementId.ipElement(srcIp);
99
100 IpAddress dstIp = IpAddress.valueOf(0xC010102);
101 IpElementId dstElementId = IpElementId.ipElement(dstIp);
102
103 IpTunnelEndPoint ipTunnelEndPointSrc;
104 ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp);
105
106 IpTunnelEndPoint ipTunnelEndPointDst;
107 ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp);
108
109 ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023));
110
111 ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023));
112
Ray Milkey2693bda2016-01-22 16:08:14 -0800113 Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
114 .type(Link.Type.DIRECT).build();
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530115 links.add(link);
116
Ray Milkeya7cf8c82018-02-08 15:07:06 -0800117 path = new DefaultPath(pid, links, TEN_WEIGHT, EMPTY);
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530118
Avantika-Huawei56c11842016-04-28 00:56:56 +0530119 Annotations annotations = DefaultAnnotations.builder()
120 .set(LSP_SIG_TYPE, WITH_SIGNALLING.name())
121 .build();
122
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530123 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
Yi Tsengfa394de2017-02-01 11:26:40 -0800124 new GroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
Avantika-Huawei56c11842016-04-28 00:56:56 +0530125 path, annotations);
Priyanka B413fbe82016-05-26 11:44:45 +0530126 controller.getClient(PccId.pccId(IpAddress.valueOf(0xC010101))).setCapability(
127 new ClientCapability(true, true, true, true, true));
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530128
129 tunnelProvider.setupTunnel(tunnel, path);
Priyanka Bd2b28882016-04-04 16:57:04 +0530130 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
131 }
132
133 /**
134 * Doesn't send PCInitiate message because PCC doesn't supports PCInitiate and stateful capability.
135 */
136 @Test
137 public void testCasePcepSetupTunnel2() {
138 Tunnel tunnel;
139 Path path;
140 ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
Avantika-Huawei56c11842016-04-28 00:56:56 +0530141 List<Link> links = new ArrayList<>();
Priyanka Bd2b28882016-04-04 16:57:04 +0530142 IpAddress srcIp = IpAddress.valueOf(0xC010103);
143 IpElementId srcElementId = IpElementId.ipElement(srcIp);
144
145 IpAddress dstIp = IpAddress.valueOf(0xC010102);
146 IpElementId dstElementId = IpElementId.ipElement(dstIp);
147
148 IpTunnelEndPoint ipTunnelEndPointSrc;
149 ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp);
150
151 IpTunnelEndPoint ipTunnelEndPointDst;
152 ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp);
153
154 ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023));
155
156 ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023));
157
158 Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
159 .type(Link.Type.DIRECT).build();
160 links.add(link);
161
Ray Milkeya7cf8c82018-02-08 15:07:06 -0800162 path = new DefaultPath(pid, links, TEN_WEIGHT, EMPTY);
Priyanka Bd2b28882016-04-04 16:57:04 +0530163
Avantika-Huawei56c11842016-04-28 00:56:56 +0530164 Annotations annotations = DefaultAnnotations.builder()
165 .set(LSP_SIG_TYPE, WITH_SIGNALLING.name())
166 .build();
167
Priyanka Bd2b28882016-04-04 16:57:04 +0530168 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
Yi Tsengfa394de2017-02-01 11:26:40 -0800169 new GroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
Avantika-Huawei56c11842016-04-28 00:56:56 +0530170 path, annotations);
Priyanka B413fbe82016-05-26 11:44:45 +0530171 controller.getClient(PccId.pccId(IpAddress.valueOf(0xC010103))).setCapability(
172 new ClientCapability(true, true, true, true, true));
Priyanka Bd2b28882016-04-04 16:57:04 +0530173
174 tunnelProvider.setupTunnel(tunnel, path);
175 assertThat(tunnelProvider.pcepTunnelApiMapper.checkFromTunnelRequestQueue(1), is(false));
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530176 }
177
Avantika-Huawei56c11842016-04-28 00:56:56 +0530178 /**
179 * Sends PCInitiate msg to setup a SR based tunnel.
180 */
181 @Test
182 public void testCasePcepSetupSrTunnel() {
183 Tunnel tunnel;
184 Path path;
185 ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
186 List<Link> links = new ArrayList<>();
187 IpAddress srcIp = IpAddress.valueOf(0xC010101);
188 IpElementId srcElementId = IpElementId.ipElement(srcIp);
189
190 IpAddress dstIp = IpAddress.valueOf(0xC010102);
191 IpElementId dstElementId = IpElementId.ipElement(dstIp);
192
193 IpTunnelEndPoint ipTunnelEndPointSrc;
194 ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp);
195
196 IpTunnelEndPoint ipTunnelEndPointDst;
197 ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp);
198
199 ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023));
200
201 ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023));
202
203 Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
204 .type(Link.Type.DIRECT).build();
205 links.add(link);
206
Ray Milkeya7cf8c82018-02-08 15:07:06 -0800207 path = new DefaultPath(pid, links, TEN_WEIGHT, EMPTY);
Avantika-Huawei56c11842016-04-28 00:56:56 +0530208
209 Annotations annotations = DefaultAnnotations.builder()
210 .set(LSP_SIG_TYPE, SR_WITHOUT_SIGNALLING.name())
211 .build();
212
213 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
Yi Tsengfa394de2017-02-01 11:26:40 -0800214 new GroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
Avantika-Huawei56c11842016-04-28 00:56:56 +0530215 path, annotations);
Priyanka B413fbe82016-05-26 11:44:45 +0530216 controller.getClient(PccId.pccId(IpAddress.valueOf(0xC010101))).setCapability(
217 new ClientCapability(true, true, true, true, true));
Avantika-Huawei56c11842016-04-28 00:56:56 +0530218
219 tunnelProvider.setupTunnel(tunnel, path);
220 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
221 }
222
223 /**
224 * Sends PCInitiate msg to setup a tunnel without signalling and without SR.
225 */
226 @Test
227 public void testCasePcepSetupTunnelWithoutSigSr() {
228 Tunnel tunnel;
229 Path path;
230 ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
231 List<Link> links = new ArrayList<>();
232 IpAddress srcIp = IpAddress.valueOf(0xC010101);
233 IpElementId srcElementId = IpElementId.ipElement(srcIp);
234
235 IpAddress dstIp = IpAddress.valueOf(0xC010102);
236 IpElementId dstElementId = IpElementId.ipElement(dstIp);
237
238 IpTunnelEndPoint ipTunnelEndPointSrc;
239 ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp);
240
241 IpTunnelEndPoint ipTunnelEndPointDst;
242 ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp);
243
244 ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023));
245
246 ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023));
247
248 Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
249 .type(Link.Type.DIRECT).build();
250 links.add(link);
251
Ray Milkeya7cf8c82018-02-08 15:07:06 -0800252 path = new DefaultPath(pid, links, TEN_WEIGHT, EMPTY);
Avantika-Huawei56c11842016-04-28 00:56:56 +0530253
254 Annotations annotations = DefaultAnnotations.builder()
255 .set(LSP_SIG_TYPE, WITHOUT_SIGNALLING_AND_WITHOUT_SR.name())
256 .build();
257
258 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
Yi Tsengfa394de2017-02-01 11:26:40 -0800259 new GroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
Avantika-Huawei56c11842016-04-28 00:56:56 +0530260 path, annotations);
Priyanka B413fbe82016-05-26 11:44:45 +0530261 controller.getClient(PccId.pccId(IpAddress.valueOf(0xC010101))).setCapability(
262 new ClientCapability(true, true, true, true, true));
Avantika-Huawei56c11842016-04-28 00:56:56 +0530263
264 tunnelProvider.setupTunnel(tunnel, path);
265 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
266 }
267
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530268 @After
269 public void tearDown() throws IOException {
270 tunnelProvider.deactivate();
271 tunnelProvider.controller = null;
272 tunnelProvider.pcepClientController = null;
273 tunnelProvider.tunnelProviderRegistry = null;
Priyanka B413fbe82016-05-26 11:44:45 +0530274 tunnelProvider.deviceService = null;
275 tunnelProvider.mastershipService = null;
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530276 }
277}