blob: c7e6ac93ba7be1a10c661331bebc0da42099c50b [file] [log] [blame]
Mahesh Poojary Sba827292016-05-09 11:31:12 +05301/*
2 * Copyright 2016-present Open Networking Laboratory
3 *
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.pce.pcestore;
17
18import static org.hamcrest.MatcherAssert.assertThat;
19import static org.hamcrest.Matchers.is;
20import static org.hamcrest.Matchers.notNullValue;
21
22import java.util.LinkedList;
23import java.util.List;
24import java.util.Map;
25
26import org.junit.After;
27import org.junit.AfterClass;
28import org.junit.Before;
29import org.junit.BeforeClass;
30import org.junit.Test;
31
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053032import org.onlab.util.DataRateUnit;
Mahesh Poojary Sba827292016-05-09 11:31:12 +053033import org.onosproject.incubator.net.resource.label.LabelResourceId;
34import org.onosproject.incubator.net.tunnel.TunnelId;
35import org.onosproject.net.ConnectPoint;
36import org.onosproject.net.DefaultAnnotations;
37import org.onosproject.net.DefaultLink;
38import org.onosproject.net.DeviceId;
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053039import org.onosproject.net.intent.Constraint;
40import org.onosproject.net.intent.constraint.BandwidthConstraint;
Mahesh Poojary Sba827292016-05-09 11:31:12 +053041import org.onosproject.net.Link;
42import org.onosproject.net.PortNumber;
43import org.onosproject.net.resource.ResourceConsumer;
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053044import org.onosproject.pce.pceservice.LspType;
Mahesh Poojary Sba827292016-05-09 11:31:12 +053045import org.onosproject.pce.pceservice.TunnelConsumerId;
Mahesh Poojary Sba827292016-05-09 11:31:12 +053046import org.onosproject.net.provider.ProviderId;
47import org.onosproject.store.service.TestStorageService;
48
49/**
50 * Unit tests for DistributedPceStore class.
51 */
52public class DistributedPceStoreTest {
53
54 private DistributedPceStore distrPceStore;
55 private DeviceId deviceId1 = DeviceId.deviceId("foo");
56 private DeviceId deviceId2 = DeviceId.deviceId("goo");
57 private DeviceId deviceId3 = DeviceId.deviceId("yaa");
58 private DeviceId deviceId4 = DeviceId.deviceId("zoo");
59 private LabelResourceId labelId1 = LabelResourceId.labelResourceId(1);
60 private LabelResourceId labelId2 = LabelResourceId.labelResourceId(2);
61 private LabelResourceId labelId3 = LabelResourceId.labelResourceId(3);
62 private LabelResourceId labelId4 = LabelResourceId.labelResourceId(4);
63 private PortNumber portNumber1 = PortNumber.portNumber(1);
64 private PortNumber portNumber2 = PortNumber.portNumber(2);
65 private PortNumber portNumber3 = PortNumber.portNumber(3);
66 private PortNumber portNumber4 = PortNumber.portNumber(4);
Avantika-Huawei9e848e82016-09-01 12:12:42 +053067 private ConnectPoint srcConnectionPoint1 = new ConnectPoint(deviceId1, portNumber1);
68 private ConnectPoint dstConnectionPoint2 = new ConnectPoint(deviceId2, portNumber2);
69 private ConnectPoint srcConnectionPoint3 = new ConnectPoint(deviceId3, portNumber3);
70 private ConnectPoint dstConnectionPoint4 = new ConnectPoint(deviceId4, portNumber4);
Mahesh Poojary Sba827292016-05-09 11:31:12 +053071 private Link link1;
72 private Link link2;
Mahesh Poojary Sba827292016-05-09 11:31:12 +053073 private TunnelId tunnelId1 = TunnelId.valueOf("1");
74 private TunnelId tunnelId2 = TunnelId.valueOf("2");
75 private TunnelId tunnelId3 = TunnelId.valueOf("3");
76 private TunnelId tunnelId4 = TunnelId.valueOf("4");
Avantika-Huawei9e848e82016-09-01 12:12:42 +053077 private ResourceConsumer tunnelConsumerId1 = TunnelConsumerId.valueOf(10);
78 private ResourceConsumer tunnelConsumerId2 = TunnelConsumerId.valueOf(20);
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053079 private PcePathInfo failedPathInfo1;
80 private PcePathInfo failedPathInfo2;
81 private PcePathInfo failedPathInfo3;
82 private PcePathInfo failedPathInfo4;
Mahesh Poojary Sba827292016-05-09 11:31:12 +053083
84 @BeforeClass
85 public static void setUpBeforeClass() throws Exception {
86 }
87
88 @AfterClass
89 public static void tearDownAfterClass() throws Exception {
90 }
91
92 @Before
93 public void setUp() throws Exception {
94 distrPceStore = new DistributedPceStore();
95
96 // Initialization of member variables
97 link1 = DefaultLink.builder()
98 .providerId(new ProviderId("eth", "1"))
99 .annotations(DefaultAnnotations.builder().set("key1", "yahoo").build())
100 .src(srcConnectionPoint1)
101 .dst(dstConnectionPoint2)
102 .type(Link.Type.DIRECT)
103 .state(Link.State.ACTIVE)
104 .build();
105 link2 = DefaultLink.builder()
106 .providerId(new ProviderId("mac", "2"))
107 .annotations(DefaultAnnotations.builder().set("key2", "google").build())
108 .src(srcConnectionPoint3)
109 .dst(dstConnectionPoint4)
110 .type(Link.Type.DIRECT)
111 .state(Link.State.ACTIVE)
112 .build();
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530113
114 // Creates failedPathInfo1
115 DeviceId src1 = DeviceId.deviceId("foo1");
116 DeviceId dst1 = DeviceId.deviceId("goo1");
117 String name1 = "pcc1";
118 LspType lspType1 = LspType.SR_WITHOUT_SIGNALLING;
119 List<Constraint> constraints1 = new LinkedList<>();
120 Constraint bandwidth1 = BandwidthConstraint.of(200, DataRateUnit.BPS);
121 constraints1.add(bandwidth1);
122
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530123 failedPathInfo1 = new PcePathInfo(src1, dst1, name1, constraints1, lspType1, null);
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530124
125 // Creates failedPathInfo2
126 DeviceId src2 = DeviceId.deviceId("foo2");
127 DeviceId dst2 = DeviceId.deviceId("goo2");
128 String name2 = "pcc2";
129 LspType lspType2 = LspType.SR_WITHOUT_SIGNALLING;
130 List<Constraint> constraints2 = new LinkedList<>();
131 Constraint bandwidth2 = BandwidthConstraint.of(400, DataRateUnit.BPS);
132 constraints2.add(bandwidth2);
133
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530134 failedPathInfo2 = new PcePathInfo(src2, dst2, name2, constraints2, lspType2, null);
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530135
136 // Creates failedPathInfo3
137 DeviceId src3 = DeviceId.deviceId("foo3");
138 DeviceId dst3 = DeviceId.deviceId("goo3");
139 String name3 = "pcc3";
140 LspType lspType3 = LspType.SR_WITHOUT_SIGNALLING;
141 List<Constraint> constraints3 = new LinkedList<>();
142 Constraint bandwidth3 = BandwidthConstraint.of(500, DataRateUnit.BPS);
143 constraints3.add(bandwidth3);
144
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530145 failedPathInfo3 = new PcePathInfo(src3, dst3, name3, constraints3, lspType3, null);
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530146
147 // Creates failedPathInfo4
148 DeviceId src4 = DeviceId.deviceId("foo4");
149 DeviceId dst4 = DeviceId.deviceId("goo4");
150 String name4 = "pcc4";
151 LspType lspType4 = LspType.SR_WITHOUT_SIGNALLING;
152 List<Constraint> constraints4 = new LinkedList<>();
153 Constraint bandwidth4 = BandwidthConstraint.of(600, DataRateUnit.BPS);
154 constraints4.add(bandwidth4);
155
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530156 failedPathInfo4 = new PcePathInfo(src4, dst4, name4, constraints4, lspType4, null);
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530157 }
158
159 @After
160 public void tearDown() throws Exception {
161 }
162
163 /**
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530164 * Checks the operation of addTunnelInfo() method.
165 */
166 @Test
167 public void testAddTunnelInfo() {
168 // initialization
169 distrPceStore.storageService = new TestStorageService();
170 distrPceStore.activate();
171
172 // TunnelId with device label store information
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530173 distrPceStore.addTunnelInfo(tunnelId1, tunnelConsumerId1);
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530174 assertThat(distrPceStore.existsTunnelInfo(tunnelId1), is(true));
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530175 assertThat(distrPceStore.getTunnelInfo(tunnelId1), is(tunnelConsumerId1));
176 distrPceStore.addTunnelInfo(tunnelId2, tunnelConsumerId2);
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530177 assertThat(distrPceStore.existsTunnelInfo(tunnelId2), is(true));
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530178 assertThat(distrPceStore.getTunnelInfo(tunnelId2), is(tunnelConsumerId2));
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530179 }
180
181 /**
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530182 * Checks the operation of addFailedPathInfo() method.
183 */
184 @Test
185 public void testAddFailedPathInfo() {
186 // initialization
187 distrPceStore.storageService = new TestStorageService();
188 distrPceStore.activate();
189
190 // PcePathInfo with pce path input information
191 distrPceStore.addFailedPathInfo(failedPathInfo1);
192 assertThat(distrPceStore.existsFailedPathInfo(failedPathInfo1), is(true));
193 distrPceStore.addFailedPathInfo(failedPathInfo2);
194 assertThat(distrPceStore.existsFailedPathInfo(failedPathInfo2), is(true));
195 }
196
197 /**
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530198 * Checks the operation of existsTunnelInfo() method.
199 */
200 @Test
201 public void testExistsTunnelInfo() {
202 testAddTunnelInfo();
203
204 assertThat(distrPceStore.existsTunnelInfo(tunnelId1), is(true));
205 assertThat(distrPceStore.existsTunnelInfo(tunnelId2), is(true));
206 assertThat(distrPceStore.existsTunnelInfo(tunnelId3), is(false));
207 assertThat(distrPceStore.existsTunnelInfo(tunnelId4), is(false));
208 }
209
210 /**
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530211 * Checks the operation of existsFailedPathInfo() method.
212 */
213 @Test
214 public void testExistsFailedPathInfo() {
215 testAddFailedPathInfo();
216
217 assertThat(distrPceStore.existsFailedPathInfo(failedPathInfo1), is(true));
218 assertThat(distrPceStore.existsFailedPathInfo(failedPathInfo2), is(true));
219 assertThat(distrPceStore.existsFailedPathInfo(failedPathInfo3), is(false));
220 assertThat(distrPceStore.existsFailedPathInfo(failedPathInfo4), is(false));
221 }
222
223 /**
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530224 * Checks the operation of getTunnelInfoCount() method.
225 */
226 @Test
227 public void testGetTunnelInfoCount() {
228 testAddTunnelInfo();
229
230 assertThat(distrPceStore.getTunnelInfoCount(), is(2));
231 }
232
233 /**
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530234 * Checks the operation of getFailedPathInfoCount() method.
235 */
236 @Test
237 public void testGetFailedPathInfoCount() {
238 testAddFailedPathInfo();
239
240 assertThat(distrPceStore.getFailedPathInfoCount(), is(2));
241 }
242
243 /**
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530244 * Checks the operation of getTunnelInfos() method.
245 */
246 @Test
247 public void testGetTunnelInfos() {
248 testAddTunnelInfo();
249
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530250 Map<TunnelId, ResourceConsumer> tunnelInfoMap = distrPceStore.getTunnelInfos();
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530251 assertThat(tunnelInfoMap, is(notNullValue()));
252 assertThat(tunnelInfoMap.isEmpty(), is(false));
253 assertThat(tunnelInfoMap.size(), is(2));
254 }
255
256 /**
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530257 * Checks the operation of getFailedPathInfos() method.
258 */
259 @Test
260 public void testGetFailedPathInfos() {
261 testAddFailedPathInfo();
262
263 Iterable<PcePathInfo> failedPathInfoSet = distrPceStore.getFailedPathInfos();
264 assertThat(failedPathInfoSet, is(notNullValue()));
265 assertThat(failedPathInfoSet.iterator().hasNext(), is(true));
266 }
267
268 /**
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530269 * Checks the operation of getTunnelInfo() method.
270 */
271 @Test
272 public void testGetTunnelInfo() {
273 testAddTunnelInfo();
274
275 // tunnelId1 with device label store info
276 assertThat(tunnelId1, is(notNullValue()));
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530277 assertThat(distrPceStore.getTunnelInfo(tunnelId1), is(tunnelConsumerId1));
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530278
279 // tunnelId2 with device label store info
280 assertThat(tunnelId2, is(notNullValue()));
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530281 assertThat(distrPceStore.getTunnelInfo(tunnelId2), is(tunnelConsumerId2));
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530282 }
283
284 /**
285 * Checks the operation of removeTunnelInfo() method.
286 */
287 @Test
288 public void testRemoveTunnelInfo() {
289 testAddTunnelInfo();
290
291 assertThat(distrPceStore.removeTunnelInfo(tunnelId1), is(true));
292 assertThat(distrPceStore.removeTunnelInfo(tunnelId2), is(true));
293 }
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530294
295 /**
296 * Checks the operation of removeFailedPathInfo() method.
297 */
298 @Test
299 public void testRemoveFailedPathInfo() {
300 testAddFailedPathInfo();
301
302 assertThat(distrPceStore.removeFailedPathInfo(failedPathInfo1), is(true));
303 assertThat(distrPceStore.removeFailedPathInfo(failedPathInfo2), is(true));
304 assertThat(distrPceStore.removeFailedPathInfo(failedPathInfo3), is(false));
305 assertThat(distrPceStore.removeFailedPathInfo(failedPathInfo4), is(false));
306 }
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530307}