blob: e176771d0c184663adb9438d984516ab29478aa9 [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;
22import org.onlab.graph.Weight;
Phanendra Manda972ee9e2015-08-21 19:08:20 +053023import org.onlab.packet.IpAddress;
chengfan2fff70f2015-08-24 18:20:19 -050024import org.onosproject.cfg.ComponentConfigAdapter;
Yi Tsengfa394de2017-02-01 11:26:40 -080025import org.onosproject.core.GroupId;
Phanendra Manda972ee9e2015-08-21 19:08:20 +053026import org.onosproject.incubator.net.tunnel.DefaultTunnel;
27import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint;
28import org.onosproject.incubator.net.tunnel.Tunnel;
29import org.onosproject.incubator.net.tunnel.TunnelId;
30import org.onosproject.incubator.net.tunnel.TunnelName;
Ray Milkeyd1c34da2018-06-22 18:10:53 -070031import org.onosproject.incubator.net.tunnel.TunnelServiceAdapter;
Priyanka B413fbe82016-05-26 11:44:45 +053032import org.onosproject.mastership.MastershipServiceAdapter;
Avantika-Huawei56c11842016-04-28 00:56:56 +053033import org.onosproject.net.Annotations;
Phanendra Manda972ee9e2015-08-21 19:08:20 +053034import org.onosproject.net.ConnectPoint;
Avantika-Huawei56c11842016-04-28 00:56:56 +053035import org.onosproject.net.DefaultAnnotations;
Phanendra Manda972ee9e2015-08-21 19:08:20 +053036import org.onosproject.net.DefaultLink;
37import org.onosproject.net.DefaultPath;
38import org.onosproject.net.IpElementId;
39import org.onosproject.net.Link;
40import org.onosproject.net.Path;
41import org.onosproject.net.PortNumber;
Priyanka B413fbe82016-05-26 11:44:45 +053042import org.onosproject.net.device.DeviceServiceAdapter;
Phanendra Manda972ee9e2015-08-21 19:08:20 +053043import org.onosproject.net.provider.ProviderId;
Ray Milkeyd1c34da2018-06-22 18:10:53 -070044import org.onosproject.pcep.api.PcepControllerAdapter;
harikrushna-Huaweia2c7c202017-04-10 18:22:00 +053045import org.onosproject.pcep.server.ClientCapability;
46import org.onosproject.pcep.server.PccId;
Ray Milkeyd1c34da2018-06-22 18:10:53 -070047import org.onosproject.pcep.server.PcepClientControllerAdapter;
48
49import 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;
Phanendra Manda972ee9e2015-08-21 19:08:20 +053062
Priyanka Bd2b28882016-04-04 16:57:04 +053063/**
64 * Test for PCEP setup tunnel.
65 */
Phanendra Manda972ee9e2015-08-21 19:08:20 +053066public class PcepSetupTunnelProviderTest {
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();
Ray Milkeyd1c34da2018-06-22 18:10:53 -070073 private final TunnelServiceAdapter tunnelService = new TunnelServiceAdapter();
Priyanka B413fbe82016-05-26 11:44:45 +053074 private final DeviceServiceAdapter deviceService = new DeviceServiceAdapter();
75 private final MastershipServiceAdapter mastershipService = new MastershipServiceAdapter();
Ray Milkeya7cf8c82018-02-08 15:07:06 -080076 private static final Weight TEN_WEIGHT = ScalarWeight.toWeight(10);
77
Phanendra Manda972ee9e2015-08-21 19:08:20 +053078
Priyanka Bd2b28882016-04-04 16:57:04 +053079 @Before
80 public void setUp() throws IOException {
Phanendra Manda972ee9e2015-08-21 19:08:20 +053081 tunnelProvider.tunnelProviderRegistry = registry;
82 tunnelProvider.pcepClientController = controller;
83 tunnelProvider.controller = ctl;
Priyanka B413fbe82016-05-26 11:44:45 +053084 tunnelProvider.deviceService = deviceService;
85 tunnelProvider.mastershipService = mastershipService;
chengfan2fff70f2015-08-24 18:20:19 -050086 tunnelProvider.cfgService = new ComponentConfigAdapter();
87 tunnelProvider.tunnelService = tunnelService;
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 * Send PcInitiate message to PCC.
93 */
94 @Test
95 public void testCasePcepSetupTunnel() {
Phanendra Manda972ee9e2015-08-21 19:08:20 +053096 Tunnel tunnel;
97 Path path;
98 ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
Avantika-Huawei56c11842016-04-28 00:56:56 +053099 List<Link> links = new ArrayList<>();
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530100 IpAddress srcIp = IpAddress.valueOf(0xC010101);
101 IpElementId srcElementId = IpElementId.ipElement(srcIp);
102
103 IpAddress dstIp = IpAddress.valueOf(0xC010102);
104 IpElementId dstElementId = IpElementId.ipElement(dstIp);
105
106 IpTunnelEndPoint ipTunnelEndPointSrc;
107 ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp);
108
109 IpTunnelEndPoint ipTunnelEndPointDst;
110 ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp);
111
112 ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023));
113
114 ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023));
115
Ray Milkey2693bda2016-01-22 16:08:14 -0800116 Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
117 .type(Link.Type.DIRECT).build();
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530118 links.add(link);
119
Ray Milkeya7cf8c82018-02-08 15:07:06 -0800120 path = new DefaultPath(pid, links, TEN_WEIGHT, EMPTY);
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530121
Avantika-Huawei56c11842016-04-28 00:56:56 +0530122 Annotations annotations = DefaultAnnotations.builder()
123 .set(LSP_SIG_TYPE, WITH_SIGNALLING.name())
124 .build();
125
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530126 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
Yi Tsengfa394de2017-02-01 11:26:40 -0800127 new GroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
Avantika-Huawei56c11842016-04-28 00:56:56 +0530128 path, annotations);
Priyanka B413fbe82016-05-26 11:44:45 +0530129 controller.getClient(PccId.pccId(IpAddress.valueOf(0xC010101))).setCapability(
130 new ClientCapability(true, true, true, true, true));
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530131
132 tunnelProvider.setupTunnel(tunnel, path);
Priyanka Bd2b28882016-04-04 16:57:04 +0530133 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
134 }
135
136 /**
137 * Doesn't send PCInitiate message because PCC doesn't supports PCInitiate and stateful capability.
138 */
139 @Test
140 public void testCasePcepSetupTunnel2() {
141 Tunnel tunnel;
142 Path path;
143 ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
Avantika-Huawei56c11842016-04-28 00:56:56 +0530144 List<Link> links = new ArrayList<>();
Priyanka Bd2b28882016-04-04 16:57:04 +0530145 IpAddress srcIp = IpAddress.valueOf(0xC010103);
146 IpElementId srcElementId = IpElementId.ipElement(srcIp);
147
148 IpAddress dstIp = IpAddress.valueOf(0xC010102);
149 IpElementId dstElementId = IpElementId.ipElement(dstIp);
150
151 IpTunnelEndPoint ipTunnelEndPointSrc;
152 ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp);
153
154 IpTunnelEndPoint ipTunnelEndPointDst;
155 ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp);
156
157 ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023));
158
159 ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023));
160
161 Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
162 .type(Link.Type.DIRECT).build();
163 links.add(link);
164
Ray Milkeya7cf8c82018-02-08 15:07:06 -0800165 path = new DefaultPath(pid, links, TEN_WEIGHT, EMPTY);
Priyanka Bd2b28882016-04-04 16:57:04 +0530166
Avantika-Huawei56c11842016-04-28 00:56:56 +0530167 Annotations annotations = DefaultAnnotations.builder()
168 .set(LSP_SIG_TYPE, WITH_SIGNALLING.name())
169 .build();
170
Priyanka Bd2b28882016-04-04 16:57:04 +0530171 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
Yi Tsengfa394de2017-02-01 11:26:40 -0800172 new GroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
Avantika-Huawei56c11842016-04-28 00:56:56 +0530173 path, annotations);
Priyanka B413fbe82016-05-26 11:44:45 +0530174 controller.getClient(PccId.pccId(IpAddress.valueOf(0xC010103))).setCapability(
175 new ClientCapability(true, true, true, true, true));
Priyanka Bd2b28882016-04-04 16:57:04 +0530176
177 tunnelProvider.setupTunnel(tunnel, path);
178 assertThat(tunnelProvider.pcepTunnelApiMapper.checkFromTunnelRequestQueue(1), is(false));
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530179 }
180
Avantika-Huawei56c11842016-04-28 00:56:56 +0530181 /**
182 * Sends PCInitiate msg to setup a SR based tunnel.
183 */
184 @Test
185 public void testCasePcepSetupSrTunnel() {
186 Tunnel tunnel;
187 Path path;
188 ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
189 List<Link> links = new ArrayList<>();
190 IpAddress srcIp = IpAddress.valueOf(0xC010101);
191 IpElementId srcElementId = IpElementId.ipElement(srcIp);
192
193 IpAddress dstIp = IpAddress.valueOf(0xC010102);
194 IpElementId dstElementId = IpElementId.ipElement(dstIp);
195
196 IpTunnelEndPoint ipTunnelEndPointSrc;
197 ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp);
198
199 IpTunnelEndPoint ipTunnelEndPointDst;
200 ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp);
201
202 ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023));
203
204 ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023));
205
206 Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
207 .type(Link.Type.DIRECT).build();
208 links.add(link);
209
Ray Milkeya7cf8c82018-02-08 15:07:06 -0800210 path = new DefaultPath(pid, links, TEN_WEIGHT, EMPTY);
Avantika-Huawei56c11842016-04-28 00:56:56 +0530211
212 Annotations annotations = DefaultAnnotations.builder()
213 .set(LSP_SIG_TYPE, SR_WITHOUT_SIGNALLING.name())
214 .build();
215
216 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
Yi Tsengfa394de2017-02-01 11:26:40 -0800217 new GroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
Avantika-Huawei56c11842016-04-28 00:56:56 +0530218 path, annotations);
Priyanka B413fbe82016-05-26 11:44:45 +0530219 controller.getClient(PccId.pccId(IpAddress.valueOf(0xC010101))).setCapability(
220 new ClientCapability(true, true, true, true, true));
Avantika-Huawei56c11842016-04-28 00:56:56 +0530221
222 tunnelProvider.setupTunnel(tunnel, path);
223 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
224 }
225
226 /**
227 * Sends PCInitiate msg to setup a tunnel without signalling and without SR.
228 */
229 @Test
230 public void testCasePcepSetupTunnelWithoutSigSr() {
231 Tunnel tunnel;
232 Path path;
233 ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
234 List<Link> links = new ArrayList<>();
235 IpAddress srcIp = IpAddress.valueOf(0xC010101);
236 IpElementId srcElementId = IpElementId.ipElement(srcIp);
237
238 IpAddress dstIp = IpAddress.valueOf(0xC010102);
239 IpElementId dstElementId = IpElementId.ipElement(dstIp);
240
241 IpTunnelEndPoint ipTunnelEndPointSrc;
242 ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp);
243
244 IpTunnelEndPoint ipTunnelEndPointDst;
245 ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp);
246
247 ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023));
248
249 ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023));
250
251 Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
252 .type(Link.Type.DIRECT).build();
253 links.add(link);
254
Ray Milkeya7cf8c82018-02-08 15:07:06 -0800255 path = new DefaultPath(pid, links, TEN_WEIGHT, EMPTY);
Avantika-Huawei56c11842016-04-28 00:56:56 +0530256
257 Annotations annotations = DefaultAnnotations.builder()
258 .set(LSP_SIG_TYPE, WITHOUT_SIGNALLING_AND_WITHOUT_SR.name())
259 .build();
260
261 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
Yi Tsengfa394de2017-02-01 11:26:40 -0800262 new GroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
Avantika-Huawei56c11842016-04-28 00:56:56 +0530263 path, annotations);
Priyanka B413fbe82016-05-26 11:44:45 +0530264 controller.getClient(PccId.pccId(IpAddress.valueOf(0xC010101))).setCapability(
265 new ClientCapability(true, true, true, true, true));
Avantika-Huawei56c11842016-04-28 00:56:56 +0530266
267 tunnelProvider.setupTunnel(tunnel, path);
268 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
269 }
270
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530271 @After
272 public void tearDown() throws IOException {
273 tunnelProvider.deactivate();
274 tunnelProvider.controller = null;
275 tunnelProvider.pcepClientController = null;
276 tunnelProvider.tunnelProviderRegistry = null;
Priyanka B413fbe82016-05-26 11:44:45 +0530277 tunnelProvider.deviceService = null;
278 tunnelProvider.mastershipService = null;
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530279 }
280}