Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.pce.pcestore; |
| 17 | |
| 18 | import static org.hamcrest.MatcherAssert.assertThat; |
| 19 | import static org.hamcrest.Matchers.is; |
| 20 | import static org.hamcrest.Matchers.notNullValue; |
| 21 | |
| 22 | import java.util.LinkedList; |
| 23 | import java.util.List; |
| 24 | import java.util.Map; |
| 25 | |
| 26 | import org.junit.After; |
| 27 | import org.junit.AfterClass; |
| 28 | import org.junit.Before; |
| 29 | import org.junit.BeforeClass; |
| 30 | import org.junit.Test; |
| 31 | |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 32 | import org.onlab.util.DataRateUnit; |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 33 | import org.onosproject.incubator.net.resource.label.LabelResourceId; |
| 34 | import org.onosproject.incubator.net.tunnel.TunnelId; |
| 35 | import org.onosproject.net.ConnectPoint; |
| 36 | import org.onosproject.net.DefaultAnnotations; |
| 37 | import org.onosproject.net.DefaultLink; |
| 38 | import org.onosproject.net.DeviceId; |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 39 | import org.onosproject.net.intent.Constraint; |
| 40 | import org.onosproject.net.intent.constraint.BandwidthConstraint; |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 41 | import org.onosproject.net.Link; |
| 42 | import org.onosproject.net.PortNumber; |
| 43 | import org.onosproject.net.resource.ResourceConsumer; |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 44 | import org.onosproject.pce.pceservice.LspType; |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 45 | import org.onosproject.pce.pceservice.TunnelConsumerId; |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 46 | import org.onosproject.net.provider.ProviderId; |
| 47 | import org.onosproject.store.service.TestStorageService; |
| 48 | |
| 49 | /** |
| 50 | * Unit tests for DistributedPceStore class. |
| 51 | */ |
| 52 | public 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-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 67 | 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 S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 71 | private Link link1; |
| 72 | private Link link2; |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 73 | 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-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 77 | private ResourceConsumer tunnelConsumerId1 = TunnelConsumerId.valueOf(10); |
| 78 | private ResourceConsumer tunnelConsumerId2 = TunnelConsumerId.valueOf(20); |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 79 | private PcePathInfo failedPathInfo1; |
| 80 | private PcePathInfo failedPathInfo2; |
| 81 | private PcePathInfo failedPathInfo3; |
| 82 | private PcePathInfo failedPathInfo4; |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 83 | |
| 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 S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 113 | |
| 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 B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 123 | failedPathInfo1 = new PcePathInfo(src1, dst1, name1, constraints1, lspType1, null); |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 124 | |
| 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 B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 134 | failedPathInfo2 = new PcePathInfo(src2, dst2, name2, constraints2, lspType2, null); |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 135 | |
| 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 B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 145 | failedPathInfo3 = new PcePathInfo(src3, dst3, name3, constraints3, lspType3, null); |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 146 | |
| 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 B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 156 | failedPathInfo4 = new PcePathInfo(src4, dst4, name4, constraints4, lspType4, null); |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | @After |
| 160 | public void tearDown() throws Exception { |
| 161 | } |
| 162 | |
| 163 | /** |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 164 | * 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-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 173 | distrPceStore.addTunnelInfo(tunnelId1, tunnelConsumerId1); |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 174 | assertThat(distrPceStore.existsTunnelInfo(tunnelId1), is(true)); |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 175 | assertThat(distrPceStore.getTunnelInfo(tunnelId1), is(tunnelConsumerId1)); |
| 176 | distrPceStore.addTunnelInfo(tunnelId2, tunnelConsumerId2); |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 177 | assertThat(distrPceStore.existsTunnelInfo(tunnelId2), is(true)); |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 178 | assertThat(distrPceStore.getTunnelInfo(tunnelId2), is(tunnelConsumerId2)); |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | /** |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 182 | * 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 S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 198 | * 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 S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 211 | * 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 S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 224 | * 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 S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 234 | * 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 S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 244 | * Checks the operation of getTunnelInfos() method. |
| 245 | */ |
| 246 | @Test |
| 247 | public void testGetTunnelInfos() { |
| 248 | testAddTunnelInfo(); |
| 249 | |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 250 | Map<TunnelId, ResourceConsumer> tunnelInfoMap = distrPceStore.getTunnelInfos(); |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 251 | assertThat(tunnelInfoMap, is(notNullValue())); |
| 252 | assertThat(tunnelInfoMap.isEmpty(), is(false)); |
| 253 | assertThat(tunnelInfoMap.size(), is(2)); |
| 254 | } |
| 255 | |
| 256 | /** |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 257 | * 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 S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 269 | * 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-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 277 | assertThat(distrPceStore.getTunnelInfo(tunnelId1), is(tunnelConsumerId1)); |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 278 | |
| 279 | // tunnelId2 with device label store info |
| 280 | assertThat(tunnelId2, is(notNullValue())); |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 281 | assertThat(distrPceStore.getTunnelInfo(tunnelId2), is(tunnelConsumerId2)); |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 282 | } |
| 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 S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 294 | |
| 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 S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 307 | } |