blob: 078deb11d018a92d1e6793fcdc04a2d4f343c7d2 [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
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;
Avantika-Huawei56c11842016-04-28 00:56:56 +053023import static org.onosproject.provider.pcep.tunnel.impl.LspType.WITH_SIGNALLING;
24import static org.onosproject.provider.pcep.tunnel.impl.LspType.SR_WITHOUT_SIGNALLING;
25import static org.onosproject.provider.pcep.tunnel.impl.LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR;
26import static org.onosproject.provider.pcep.tunnel.impl.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;
35import org.onlab.packet.IpAddress;
chengfan2fff70f2015-08-24 18:20:19 -050036import org.onosproject.cfg.ComponentConfigAdapter;
Phanendra Manda972ee9e2015-08-21 19:08:20 +053037import org.onosproject.core.DefaultGroupId;
38import org.onosproject.incubator.net.tunnel.DefaultTunnel;
39import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint;
40import org.onosproject.incubator.net.tunnel.Tunnel;
41import org.onosproject.incubator.net.tunnel.TunnelId;
42import org.onosproject.incubator.net.tunnel.TunnelName;
Priyanka B413fbe82016-05-26 11:44:45 +053043import org.onosproject.mastership.MastershipServiceAdapter;
Avantika-Huawei56c11842016-04-28 00:56:56 +053044import org.onosproject.net.Annotations;
Phanendra Manda972ee9e2015-08-21 19:08:20 +053045import org.onosproject.net.ConnectPoint;
Avantika-Huawei56c11842016-04-28 00:56:56 +053046import org.onosproject.net.DefaultAnnotations;
Phanendra Manda972ee9e2015-08-21 19:08:20 +053047import org.onosproject.net.DefaultLink;
48import org.onosproject.net.DefaultPath;
49import org.onosproject.net.IpElementId;
50import org.onosproject.net.Link;
51import org.onosproject.net.Path;
52import org.onosproject.net.PortNumber;
Priyanka B413fbe82016-05-26 11:44:45 +053053import org.onosproject.net.device.DeviceServiceAdapter;
Phanendra Manda972ee9e2015-08-21 19:08:20 +053054import org.onosproject.net.provider.ProviderId;
Priyanka B413fbe82016-05-26 11:44:45 +053055import org.onosproject.pcep.controller.ClientCapability;
56import org.onosproject.pcep.controller.PccId;
Phanendra Manda972ee9e2015-08-21 19:08:20 +053057
Priyanka Bd2b28882016-04-04 16:57:04 +053058/**
59 * Test for PCEP setup tunnel.
60 */
Phanendra Manda972ee9e2015-08-21 19:08:20 +053061public class PcepSetupTunnelProviderTest {
62
Brian Stanke9a108972016-04-11 15:25:17 -040063 private static final String PROVIDER_ID = "org.onosproject.provider.tunnel.pcep";
Priyanka Bd2b28882016-04-04 16:57:04 +053064 private PcepTunnelProvider tunnelProvider = new PcepTunnelProvider();
Phanendra Manda972ee9e2015-08-21 19:08:20 +053065 private final TunnelProviderRegistryAdapter registry = new TunnelProviderRegistryAdapter();
66 private final PcepClientControllerAdapter controller = new PcepClientControllerAdapter();
67 private final PcepControllerAdapter ctl = new PcepControllerAdapter();
chengfan2fff70f2015-08-24 18:20:19 -050068 private final TunnelServiceAdapter tunnelService = new TunnelServiceAdapter();
Priyanka B413fbe82016-05-26 11:44:45 +053069 private final DeviceServiceAdapter deviceService = new DeviceServiceAdapter();
70 private final MastershipServiceAdapter mastershipService = new MastershipServiceAdapter();
Phanendra Manda972ee9e2015-08-21 19:08:20 +053071
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;
Priyanka B413fbe82016-05-26 11:44:45 +053077 tunnelProvider.deviceService = deviceService;
78 tunnelProvider.mastershipService = mastershipService;
chengfan2fff70f2015-08-24 18:20:19 -050079 tunnelProvider.cfgService = new ComponentConfigAdapter();
80 tunnelProvider.tunnelService = tunnelService;
Phanendra Manda972ee9e2015-08-21 19:08:20 +053081 tunnelProvider.activate();
Priyanka Bd2b28882016-04-04 16:57:04 +053082 }
Phanendra Manda972ee9e2015-08-21 19:08:20 +053083
Priyanka Bd2b28882016-04-04 16:57:04 +053084 /**
85 * Send PcInitiate message to PCC.
86 */
87 @Test
88 public void testCasePcepSetupTunnel() {
Phanendra Manda972ee9e2015-08-21 19:08:20 +053089 Tunnel tunnel;
90 Path path;
91 ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
Avantika-Huawei56c11842016-04-28 00:56:56 +053092 List<Link> links = new ArrayList<>();
Phanendra Manda972ee9e2015-08-21 19:08:20 +053093 IpAddress srcIp = IpAddress.valueOf(0xC010101);
94 IpElementId srcElementId = IpElementId.ipElement(srcIp);
95
96 IpAddress dstIp = IpAddress.valueOf(0xC010102);
97 IpElementId dstElementId = IpElementId.ipElement(dstIp);
98
99 IpTunnelEndPoint ipTunnelEndPointSrc;
100 ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp);
101
102 IpTunnelEndPoint ipTunnelEndPointDst;
103 ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp);
104
105 ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023));
106
107 ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023));
108
Ray Milkey2693bda2016-01-22 16:08:14 -0800109 Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
110 .type(Link.Type.DIRECT).build();
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530111 links.add(link);
112
113 path = new DefaultPath(pid, links, 10, EMPTY);
114
Avantika-Huawei56c11842016-04-28 00:56:56 +0530115 Annotations annotations = DefaultAnnotations.builder()
116 .set(LSP_SIG_TYPE, WITH_SIGNALLING.name())
117 .build();
118
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530119 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
Brian Stanke9a108972016-04-11 15:25:17 -0400120 new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
Avantika-Huawei56c11842016-04-28 00:56:56 +0530121 path, annotations);
Priyanka B413fbe82016-05-26 11:44:45 +0530122 controller.getClient(PccId.pccId(IpAddress.valueOf(0xC010101))).setCapability(
123 new ClientCapability(true, true, true, true, true));
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530124
125 tunnelProvider.setupTunnel(tunnel, path);
Priyanka Bd2b28882016-04-04 16:57:04 +0530126 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
127 }
128
129 /**
130 * Doesn't send PCInitiate message because PCC doesn't supports PCInitiate and stateful capability.
131 */
132 @Test
133 public void testCasePcepSetupTunnel2() {
134 Tunnel tunnel;
135 Path path;
136 ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
Avantika-Huawei56c11842016-04-28 00:56:56 +0530137 List<Link> links = new ArrayList<>();
Priyanka Bd2b28882016-04-04 16:57:04 +0530138 IpAddress srcIp = IpAddress.valueOf(0xC010103);
139 IpElementId srcElementId = IpElementId.ipElement(srcIp);
140
141 IpAddress dstIp = IpAddress.valueOf(0xC010102);
142 IpElementId dstElementId = IpElementId.ipElement(dstIp);
143
144 IpTunnelEndPoint ipTunnelEndPointSrc;
145 ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp);
146
147 IpTunnelEndPoint ipTunnelEndPointDst;
148 ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp);
149
150 ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023));
151
152 ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023));
153
154 Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
155 .type(Link.Type.DIRECT).build();
156 links.add(link);
157
158 path = new DefaultPath(pid, links, 10, EMPTY);
159
Avantika-Huawei56c11842016-04-28 00:56:56 +0530160 Annotations annotations = DefaultAnnotations.builder()
161 .set(LSP_SIG_TYPE, WITH_SIGNALLING.name())
162 .build();
163
Priyanka Bd2b28882016-04-04 16:57:04 +0530164 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
Brian Stanke9a108972016-04-11 15:25:17 -0400165 new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
Avantika-Huawei56c11842016-04-28 00:56:56 +0530166 path, annotations);
Priyanka B413fbe82016-05-26 11:44:45 +0530167 controller.getClient(PccId.pccId(IpAddress.valueOf(0xC010103))).setCapability(
168 new ClientCapability(true, true, true, true, true));
Priyanka Bd2b28882016-04-04 16:57:04 +0530169
170 tunnelProvider.setupTunnel(tunnel, path);
171 assertThat(tunnelProvider.pcepTunnelApiMapper.checkFromTunnelRequestQueue(1), is(false));
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530172 }
173
Avantika-Huawei56c11842016-04-28 00:56:56 +0530174 /**
175 * Sends PCInitiate msg to setup a SR based tunnel.
176 */
177 @Test
178 public void testCasePcepSetupSrTunnel() {
179 Tunnel tunnel;
180 Path path;
181 ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
182 List<Link> links = new ArrayList<>();
183 IpAddress srcIp = IpAddress.valueOf(0xC010101);
184 IpElementId srcElementId = IpElementId.ipElement(srcIp);
185
186 IpAddress dstIp = IpAddress.valueOf(0xC010102);
187 IpElementId dstElementId = IpElementId.ipElement(dstIp);
188
189 IpTunnelEndPoint ipTunnelEndPointSrc;
190 ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp);
191
192 IpTunnelEndPoint ipTunnelEndPointDst;
193 ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp);
194
195 ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023));
196
197 ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023));
198
199 Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
200 .type(Link.Type.DIRECT).build();
201 links.add(link);
202
203 path = new DefaultPath(pid, links, 10, EMPTY);
204
205 Annotations annotations = DefaultAnnotations.builder()
206 .set(LSP_SIG_TYPE, SR_WITHOUT_SIGNALLING.name())
207 .build();
208
209 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
210 new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
211 path, annotations);
Priyanka B413fbe82016-05-26 11:44:45 +0530212 controller.getClient(PccId.pccId(IpAddress.valueOf(0xC010101))).setCapability(
213 new ClientCapability(true, true, true, true, true));
Avantika-Huawei56c11842016-04-28 00:56:56 +0530214
215 tunnelProvider.setupTunnel(tunnel, path);
216 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
217 }
218
219 /**
220 * Sends PCInitiate msg to setup a tunnel without signalling and without SR.
221 */
222 @Test
223 public void testCasePcepSetupTunnelWithoutSigSr() {
224 Tunnel tunnel;
225 Path path;
226 ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
227 List<Link> links = new ArrayList<>();
228 IpAddress srcIp = IpAddress.valueOf(0xC010101);
229 IpElementId srcElementId = IpElementId.ipElement(srcIp);
230
231 IpAddress dstIp = IpAddress.valueOf(0xC010102);
232 IpElementId dstElementId = IpElementId.ipElement(dstIp);
233
234 IpTunnelEndPoint ipTunnelEndPointSrc;
235 ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp);
236
237 IpTunnelEndPoint ipTunnelEndPointDst;
238 ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp);
239
240 ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023));
241
242 ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023));
243
244 Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
245 .type(Link.Type.DIRECT).build();
246 links.add(link);
247
248 path = new DefaultPath(pid, links, 10, EMPTY);
249
250 Annotations annotations = DefaultAnnotations.builder()
251 .set(LSP_SIG_TYPE, WITHOUT_SIGNALLING_AND_WITHOUT_SR.name())
252 .build();
253
254 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
255 new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
256 path, annotations);
Priyanka B413fbe82016-05-26 11:44:45 +0530257 controller.getClient(PccId.pccId(IpAddress.valueOf(0xC010101))).setCapability(
258 new ClientCapability(true, true, true, true, true));
Avantika-Huawei56c11842016-04-28 00:56:56 +0530259
260 tunnelProvider.setupTunnel(tunnel, path);
261 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
262 }
263
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530264 @After
265 public void tearDown() throws IOException {
266 tunnelProvider.deactivate();
267 tunnelProvider.controller = null;
268 tunnelProvider.pcepClientController = null;
269 tunnelProvider.tunnelProviderRegistry = null;
Priyanka B413fbe82016-05-26 11:44:45 +0530270 tunnelProvider.deviceService = null;
271 tunnelProvider.mastershipService = null;
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530272 }
273}