blob: ec378c4d1aa74e67c15102faf7578aa77194107f [file] [log] [blame]
Mahesh Poojary Sba827292016-05-09 11:31:12 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Mahesh Poojary Sba827292016-05-09 11:31:12 +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.pce.pcestore;
17
Mahesh Poojary Sba827292016-05-09 11:31:12 +053018import org.junit.After;
19import org.junit.AfterClass;
20import org.junit.Before;
21import org.junit.BeforeClass;
22import org.junit.Test;
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053023import org.onlab.util.DataRateUnit;
Mahesh Poojary Sba827292016-05-09 11:31:12 +053024import org.onosproject.incubator.net.resource.label.LabelResourceId;
25import org.onosproject.incubator.net.tunnel.TunnelId;
26import org.onosproject.net.ConnectPoint;
27import org.onosproject.net.DefaultAnnotations;
28import org.onosproject.net.DefaultLink;
29import org.onosproject.net.DeviceId;
Mahesh Poojary Sba827292016-05-09 11:31:12 +053030import org.onosproject.net.Link;
31import org.onosproject.net.PortNumber;
Satish K2eb5d842017-04-04 16:28:37 +053032import org.onosproject.net.intent.Constraint;
33import org.onosproject.net.intent.constraint.BandwidthConstraint;
34import org.onosproject.net.provider.ProviderId;
Mahesh Poojary Sba827292016-05-09 11:31:12 +053035import org.onosproject.net.resource.ResourceConsumer;
Satish K2eb5d842017-04-04 16:28:37 +053036import org.onosproject.pce.pceservice.ExplicitPathInfo;
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053037import org.onosproject.pce.pceservice.LspType;
Mahesh Poojary Sba827292016-05-09 11:31:12 +053038import org.onosproject.pce.pceservice.TunnelConsumerId;
Mahesh Poojary Sba827292016-05-09 11:31:12 +053039import org.onosproject.store.service.TestStorageService;
40
Satish K2eb5d842017-04-04 16:28:37 +053041import java.util.LinkedList;
42import java.util.List;
43
44import static org.hamcrest.MatcherAssert.assertThat;
45import static org.hamcrest.Matchers.is;
46import static org.hamcrest.Matchers.notNullValue;
47
Mahesh Poojary Sba827292016-05-09 11:31:12 +053048/**
49 * Unit tests for DistributedPceStore class.
50 */
51public class DistributedPceStoreTest {
52
53 private DistributedPceStore distrPceStore;
54 private DeviceId deviceId1 = DeviceId.deviceId("foo");
55 private DeviceId deviceId2 = DeviceId.deviceId("goo");
56 private DeviceId deviceId3 = DeviceId.deviceId("yaa");
57 private DeviceId deviceId4 = DeviceId.deviceId("zoo");
58 private LabelResourceId labelId1 = LabelResourceId.labelResourceId(1);
59 private LabelResourceId labelId2 = LabelResourceId.labelResourceId(2);
60 private LabelResourceId labelId3 = LabelResourceId.labelResourceId(3);
61 private LabelResourceId labelId4 = LabelResourceId.labelResourceId(4);
62 private PortNumber portNumber1 = PortNumber.portNumber(1);
63 private PortNumber portNumber2 = PortNumber.portNumber(2);
64 private PortNumber portNumber3 = PortNumber.portNumber(3);
65 private PortNumber portNumber4 = PortNumber.portNumber(4);
Avantika-Huawei9e848e82016-09-01 12:12:42 +053066 private ConnectPoint srcConnectionPoint1 = new ConnectPoint(deviceId1, portNumber1);
67 private ConnectPoint dstConnectionPoint2 = new ConnectPoint(deviceId2, portNumber2);
68 private ConnectPoint srcConnectionPoint3 = new ConnectPoint(deviceId3, portNumber3);
69 private ConnectPoint dstConnectionPoint4 = new ConnectPoint(deviceId4, portNumber4);
Mahesh Poojary Sba827292016-05-09 11:31:12 +053070 private Link link1;
71 private Link link2;
Mahesh Poojary Sba827292016-05-09 11:31:12 +053072 private TunnelId tunnelId1 = TunnelId.valueOf("1");
73 private TunnelId tunnelId2 = TunnelId.valueOf("2");
74 private TunnelId tunnelId3 = TunnelId.valueOf("3");
75 private TunnelId tunnelId4 = TunnelId.valueOf("4");
Avantika-Huawei9e848e82016-09-01 12:12:42 +053076 private ResourceConsumer tunnelConsumerId1 = TunnelConsumerId.valueOf(10);
77 private ResourceConsumer tunnelConsumerId2 = TunnelConsumerId.valueOf(20);
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053078 private PcePathInfo failedPathInfo1;
79 private PcePathInfo failedPathInfo2;
80 private PcePathInfo failedPathInfo3;
81 private PcePathInfo failedPathInfo4;
Mahesh Poojary Sba827292016-05-09 11:31:12 +053082
83 @BeforeClass
84 public static void setUpBeforeClass() throws Exception {
85 }
86
87 @AfterClass
88 public static void tearDownAfterClass() throws Exception {
89 }
90
91 @Before
92 public void setUp() throws Exception {
93 distrPceStore = new DistributedPceStore();
94
95 // Initialization of member variables
96 link1 = DefaultLink.builder()
97 .providerId(new ProviderId("eth", "1"))
98 .annotations(DefaultAnnotations.builder().set("key1", "yahoo").build())
99 .src(srcConnectionPoint1)
100 .dst(dstConnectionPoint2)
101 .type(Link.Type.DIRECT)
102 .state(Link.State.ACTIVE)
103 .build();
104 link2 = DefaultLink.builder()
105 .providerId(new ProviderId("mac", "2"))
106 .annotations(DefaultAnnotations.builder().set("key2", "google").build())
107 .src(srcConnectionPoint3)
108 .dst(dstConnectionPoint4)
109 .type(Link.Type.DIRECT)
110 .state(Link.State.ACTIVE)
111 .build();
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530112
113 // Creates failedPathInfo1
114 DeviceId src1 = DeviceId.deviceId("foo1");
115 DeviceId dst1 = DeviceId.deviceId("goo1");
116 String name1 = "pcc1";
117 LspType lspType1 = LspType.SR_WITHOUT_SIGNALLING;
118 List<Constraint> constraints1 = new LinkedList<>();
119 Constraint bandwidth1 = BandwidthConstraint.of(200, DataRateUnit.BPS);
120 constraints1.add(bandwidth1);
121
Satish Kba1c9122017-04-05 15:27:23 +0530122 failedPathInfo1 = new PcePathInfo(src1, dst1, name1, constraints1, lspType1, null, false);
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530123
124 // Creates failedPathInfo2
125 DeviceId src2 = DeviceId.deviceId("foo2");
126 DeviceId dst2 = DeviceId.deviceId("goo2");
127 String name2 = "pcc2";
128 LspType lspType2 = LspType.SR_WITHOUT_SIGNALLING;
129 List<Constraint> constraints2 = new LinkedList<>();
130 Constraint bandwidth2 = BandwidthConstraint.of(400, DataRateUnit.BPS);
131 constraints2.add(bandwidth2);
132
Satish Kba1c9122017-04-05 15:27:23 +0530133 failedPathInfo2 = new PcePathInfo(src2, dst2, name2, constraints2, lspType2, null, false);
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530134
135 // Creates failedPathInfo3
136 DeviceId src3 = DeviceId.deviceId("foo3");
137 DeviceId dst3 = DeviceId.deviceId("goo3");
138 String name3 = "pcc3";
139 LspType lspType3 = LspType.SR_WITHOUT_SIGNALLING;
140 List<Constraint> constraints3 = new LinkedList<>();
141 Constraint bandwidth3 = BandwidthConstraint.of(500, DataRateUnit.BPS);
142 constraints3.add(bandwidth3);
143
Satish Kba1c9122017-04-05 15:27:23 +0530144 failedPathInfo3 = new PcePathInfo(src3, dst3, name3, constraints3, lspType3, null, false);
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530145
146 // Creates failedPathInfo4
147 DeviceId src4 = DeviceId.deviceId("foo4");
148 DeviceId dst4 = DeviceId.deviceId("goo4");
149 String name4 = "pcc4";
150 LspType lspType4 = LspType.SR_WITHOUT_SIGNALLING;
151 List<Constraint> constraints4 = new LinkedList<>();
152 Constraint bandwidth4 = BandwidthConstraint.of(600, DataRateUnit.BPS);
153 constraints4.add(bandwidth4);
154
Satish Kba1c9122017-04-05 15:27:23 +0530155 failedPathInfo4 = new PcePathInfo(src4, dst4, name4, constraints4, lspType4, null, false);
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530156 }
157
158 @After
159 public void tearDown() throws Exception {
160 }
161
162 /**
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530163 * Checks the operation of addTunnelInfo() method.
164 */
165 @Test
Satish K2eb5d842017-04-04 16:28:37 +0530166 public void testAddExplicitPathInfo() {
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530167 // initialization
168 distrPceStore.storageService = new TestStorageService();
169 distrPceStore.activate();
170
Satish K2eb5d842017-04-04 16:28:37 +0530171 List<ExplicitPathInfo> infoList = new LinkedList<>();
172 ExplicitPathInfo info1 = new ExplicitPathInfo(ExplicitPathInfo.Type.LOOSE, DeviceId.deviceId("D1"));
173 infoList.add(info1);
174 distrPceStore.tunnelNameExplicitPathInfoMap("Sample1", infoList);
175 assertThat(distrPceStore.getTunnelNameExplicitPathInfoMap("Sample1"), is(infoList));
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530176 }
177
178 /**
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530179 * Checks the operation of addFailedPathInfo() method.
180 */
181 @Test
182 public void testAddFailedPathInfo() {
183 // initialization
184 distrPceStore.storageService = new TestStorageService();
185 distrPceStore.activate();
186
187 // PcePathInfo with pce path input information
188 distrPceStore.addFailedPathInfo(failedPathInfo1);
189 assertThat(distrPceStore.existsFailedPathInfo(failedPathInfo1), is(true));
190 distrPceStore.addFailedPathInfo(failedPathInfo2);
191 assertThat(distrPceStore.existsFailedPathInfo(failedPathInfo2), is(true));
192 }
193
194 /**
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530195 * Checks the operation of existsFailedPathInfo() method.
196 */
197 @Test
198 public void testExistsFailedPathInfo() {
199 testAddFailedPathInfo();
200
201 assertThat(distrPceStore.existsFailedPathInfo(failedPathInfo1), is(true));
202 assertThat(distrPceStore.existsFailedPathInfo(failedPathInfo2), is(true));
203 assertThat(distrPceStore.existsFailedPathInfo(failedPathInfo3), is(false));
204 assertThat(distrPceStore.existsFailedPathInfo(failedPathInfo4), is(false));
205 }
206
207 /**
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530208 * Checks the operation of getFailedPathInfoCount() method.
209 */
210 @Test
211 public void testGetFailedPathInfoCount() {
212 testAddFailedPathInfo();
213
214 assertThat(distrPceStore.getFailedPathInfoCount(), is(2));
215 }
216
217 /**
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530218 * Checks the operation of getFailedPathInfos() method.
219 */
220 @Test
221 public void testGetFailedPathInfos() {
222 testAddFailedPathInfo();
223
224 Iterable<PcePathInfo> failedPathInfoSet = distrPceStore.getFailedPathInfos();
225 assertThat(failedPathInfoSet, is(notNullValue()));
226 assertThat(failedPathInfoSet.iterator().hasNext(), is(true));
227 }
228
229 /**
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +0530230 * Checks the operation of removeFailedPathInfo() method.
231 */
232 @Test
233 public void testRemoveFailedPathInfo() {
234 testAddFailedPathInfo();
235
236 assertThat(distrPceStore.removeFailedPathInfo(failedPathInfo1), is(true));
237 assertThat(distrPceStore.removeFailedPathInfo(failedPathInfo2), is(true));
238 assertThat(distrPceStore.removeFailedPathInfo(failedPathInfo3), is(false));
239 assertThat(distrPceStore.removeFailedPathInfo(failedPathInfo4), is(false));
240 }
Mahesh Poojary Sba827292016-05-09 11:31:12 +0530241}