blob: d2c4d5e849eb636d2954b2fa6995551d61f0e440 [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;
Avantika-Huawei56c11842016-04-28 00:56:56 +053043import org.onosproject.net.Annotations;
Phanendra Manda972ee9e2015-08-21 19:08:20 +053044import org.onosproject.net.ConnectPoint;
Avantika-Huawei56c11842016-04-28 00:56:56 +053045import org.onosproject.net.DefaultAnnotations;
Phanendra Manda972ee9e2015-08-21 19:08:20 +053046import org.onosproject.net.DefaultLink;
47import org.onosproject.net.DefaultPath;
48import org.onosproject.net.IpElementId;
49import org.onosproject.net.Link;
50import org.onosproject.net.Path;
51import org.onosproject.net.PortNumber;
52import org.onosproject.net.provider.ProviderId;
53
Priyanka Bd2b28882016-04-04 16:57:04 +053054/**
55 * Test for PCEP setup tunnel.
56 */
Phanendra Manda972ee9e2015-08-21 19:08:20 +053057public class PcepSetupTunnelProviderTest {
58
Brian Stanke9a108972016-04-11 15:25:17 -040059 private static final String PROVIDER_ID = "org.onosproject.provider.tunnel.pcep";
Priyanka Bd2b28882016-04-04 16:57:04 +053060 private PcepTunnelProvider tunnelProvider = new PcepTunnelProvider();
Phanendra Manda972ee9e2015-08-21 19:08:20 +053061 private final TunnelProviderRegistryAdapter registry = new TunnelProviderRegistryAdapter();
62 private final PcepClientControllerAdapter controller = new PcepClientControllerAdapter();
63 private final PcepControllerAdapter ctl = new PcepControllerAdapter();
chengfan2fff70f2015-08-24 18:20:19 -050064 private final TunnelServiceAdapter tunnelService = new TunnelServiceAdapter();
Phanendra Manda972ee9e2015-08-21 19:08:20 +053065
Priyanka Bd2b28882016-04-04 16:57:04 +053066 @Before
67 public void setUp() throws IOException {
Phanendra Manda972ee9e2015-08-21 19:08:20 +053068 tunnelProvider.tunnelProviderRegistry = registry;
69 tunnelProvider.pcepClientController = controller;
70 tunnelProvider.controller = ctl;
chengfan2fff70f2015-08-24 18:20:19 -050071 tunnelProvider.cfgService = new ComponentConfigAdapter();
72 tunnelProvider.tunnelService = tunnelService;
Phanendra Manda972ee9e2015-08-21 19:08:20 +053073 tunnelProvider.activate();
Priyanka Bd2b28882016-04-04 16:57:04 +053074 }
Phanendra Manda972ee9e2015-08-21 19:08:20 +053075
Priyanka Bd2b28882016-04-04 16:57:04 +053076 /**
77 * Send PcInitiate message to PCC.
78 */
79 @Test
80 public void testCasePcepSetupTunnel() {
Phanendra Manda972ee9e2015-08-21 19:08:20 +053081 Tunnel tunnel;
82 Path path;
83 ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
Avantika-Huawei56c11842016-04-28 00:56:56 +053084 List<Link> links = new ArrayList<>();
Phanendra Manda972ee9e2015-08-21 19:08:20 +053085 IpAddress srcIp = IpAddress.valueOf(0xC010101);
86 IpElementId srcElementId = IpElementId.ipElement(srcIp);
87
88 IpAddress dstIp = IpAddress.valueOf(0xC010102);
89 IpElementId dstElementId = IpElementId.ipElement(dstIp);
90
91 IpTunnelEndPoint ipTunnelEndPointSrc;
92 ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp);
93
94 IpTunnelEndPoint ipTunnelEndPointDst;
95 ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp);
96
97 ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023));
98
99 ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023));
100
Ray Milkey2693bda2016-01-22 16:08:14 -0800101 Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
102 .type(Link.Type.DIRECT).build();
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530103 links.add(link);
104
105 path = new DefaultPath(pid, links, 10, EMPTY);
106
Avantika-Huawei56c11842016-04-28 00:56:56 +0530107 Annotations annotations = DefaultAnnotations.builder()
108 .set(LSP_SIG_TYPE, WITH_SIGNALLING.name())
109 .build();
110
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530111 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
Brian Stanke9a108972016-04-11 15:25:17 -0400112 new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
Avantika-Huawei56c11842016-04-28 00:56:56 +0530113 path, annotations);
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530114
115 tunnelProvider.setupTunnel(tunnel, path);
Priyanka Bd2b28882016-04-04 16:57:04 +0530116 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
117 }
118
119 /**
120 * Doesn't send PCInitiate message because PCC doesn't supports PCInitiate and stateful capability.
121 */
122 @Test
123 public void testCasePcepSetupTunnel2() {
124 Tunnel tunnel;
125 Path path;
126 ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
Avantika-Huawei56c11842016-04-28 00:56:56 +0530127 List<Link> links = new ArrayList<>();
Priyanka Bd2b28882016-04-04 16:57:04 +0530128 IpAddress srcIp = IpAddress.valueOf(0xC010103);
129 IpElementId srcElementId = IpElementId.ipElement(srcIp);
130
131 IpAddress dstIp = IpAddress.valueOf(0xC010102);
132 IpElementId dstElementId = IpElementId.ipElement(dstIp);
133
134 IpTunnelEndPoint ipTunnelEndPointSrc;
135 ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp);
136
137 IpTunnelEndPoint ipTunnelEndPointDst;
138 ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp);
139
140 ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023));
141
142 ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023));
143
144 Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
145 .type(Link.Type.DIRECT).build();
146 links.add(link);
147
148 path = new DefaultPath(pid, links, 10, EMPTY);
149
Avantika-Huawei56c11842016-04-28 00:56:56 +0530150 Annotations annotations = DefaultAnnotations.builder()
151 .set(LSP_SIG_TYPE, WITH_SIGNALLING.name())
152 .build();
153
Priyanka Bd2b28882016-04-04 16:57:04 +0530154 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
Brian Stanke9a108972016-04-11 15:25:17 -0400155 new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
Avantika-Huawei56c11842016-04-28 00:56:56 +0530156 path, annotations);
Priyanka Bd2b28882016-04-04 16:57:04 +0530157
158 tunnelProvider.setupTunnel(tunnel, path);
159 assertThat(tunnelProvider.pcepTunnelApiMapper.checkFromTunnelRequestQueue(1), is(false));
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530160 }
161
Avantika-Huawei56c11842016-04-28 00:56:56 +0530162 /**
163 * Sends PCInitiate msg to setup a SR based tunnel.
164 */
165 @Test
166 public void testCasePcepSetupSrTunnel() {
167 Tunnel tunnel;
168 Path path;
169 ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
170 List<Link> links = new ArrayList<>();
171 IpAddress srcIp = IpAddress.valueOf(0xC010101);
172 IpElementId srcElementId = IpElementId.ipElement(srcIp);
173
174 IpAddress dstIp = IpAddress.valueOf(0xC010102);
175 IpElementId dstElementId = IpElementId.ipElement(dstIp);
176
177 IpTunnelEndPoint ipTunnelEndPointSrc;
178 ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp);
179
180 IpTunnelEndPoint ipTunnelEndPointDst;
181 ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp);
182
183 ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023));
184
185 ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023));
186
187 Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
188 .type(Link.Type.DIRECT).build();
189 links.add(link);
190
191 path = new DefaultPath(pid, links, 10, EMPTY);
192
193 Annotations annotations = DefaultAnnotations.builder()
194 .set(LSP_SIG_TYPE, SR_WITHOUT_SIGNALLING.name())
195 .build();
196
197 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
198 new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
199 path, annotations);
200
201 tunnelProvider.setupTunnel(tunnel, path);
202 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
203 }
204
205 /**
206 * Sends PCInitiate msg to setup a tunnel without signalling and without SR.
207 */
208 @Test
209 public void testCasePcepSetupTunnelWithoutSigSr() {
210 Tunnel tunnel;
211 Path path;
212 ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
213 List<Link> links = new ArrayList<>();
214 IpAddress srcIp = IpAddress.valueOf(0xC010101);
215 IpElementId srcElementId = IpElementId.ipElement(srcIp);
216
217 IpAddress dstIp = IpAddress.valueOf(0xC010102);
218 IpElementId dstElementId = IpElementId.ipElement(dstIp);
219
220 IpTunnelEndPoint ipTunnelEndPointSrc;
221 ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp);
222
223 IpTunnelEndPoint ipTunnelEndPointDst;
224 ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp);
225
226 ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023));
227
228 ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023));
229
230 Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
231 .type(Link.Type.DIRECT).build();
232 links.add(link);
233
234 path = new DefaultPath(pid, links, 10, EMPTY);
235
236 Annotations annotations = DefaultAnnotations.builder()
237 .set(LSP_SIG_TYPE, WITHOUT_SIGNALLING_AND_WITHOUT_SR.name())
238 .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 tunnelProvider.setupTunnel(tunnel, path);
245 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
246 }
247
Phanendra Manda972ee9e2015-08-21 19:08:20 +0530248 @After
249 public void tearDown() throws IOException {
250 tunnelProvider.deactivate();
251 tunnelProvider.controller = null;
252 tunnelProvider.pcepClientController = null;
253 tunnelProvider.tunnelProviderRegistry = null;
254 }
255}