Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame^] | 2 | * Copyright 2016-present Open Networking Foundation |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 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 | |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 18 | import org.junit.After; |
| 19 | import org.junit.AfterClass; |
| 20 | import org.junit.Before; |
| 21 | import org.junit.BeforeClass; |
| 22 | import org.junit.Test; |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 23 | import org.onlab.util.DataRateUnit; |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 24 | import org.onosproject.incubator.net.resource.label.LabelResourceId; |
| 25 | import org.onosproject.incubator.net.tunnel.TunnelId; |
| 26 | import org.onosproject.net.ConnectPoint; |
| 27 | import org.onosproject.net.DefaultAnnotations; |
| 28 | import org.onosproject.net.DefaultLink; |
| 29 | import org.onosproject.net.DeviceId; |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 30 | import org.onosproject.net.Link; |
| 31 | import org.onosproject.net.PortNumber; |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 32 | import org.onosproject.net.intent.Constraint; |
| 33 | import org.onosproject.net.intent.constraint.BandwidthConstraint; |
| 34 | import org.onosproject.net.provider.ProviderId; |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 35 | import org.onosproject.net.resource.ResourceConsumer; |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 36 | import org.onosproject.pce.pceservice.ExplicitPathInfo; |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 37 | import org.onosproject.pce.pceservice.LspType; |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 38 | import org.onosproject.pce.pceservice.TunnelConsumerId; |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 39 | import org.onosproject.store.service.TestStorageService; |
| 40 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 41 | import java.util.LinkedList; |
| 42 | import java.util.List; |
| 43 | |
| 44 | import static org.hamcrest.MatcherAssert.assertThat; |
| 45 | import static org.hamcrest.Matchers.is; |
| 46 | import static org.hamcrest.Matchers.notNullValue; |
| 47 | |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 48 | /** |
| 49 | * Unit tests for DistributedPceStore class. |
| 50 | */ |
| 51 | public 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-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 66 | 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 S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 70 | private Link link1; |
| 71 | private Link link2; |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 72 | 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-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 76 | private ResourceConsumer tunnelConsumerId1 = TunnelConsumerId.valueOf(10); |
| 77 | private ResourceConsumer tunnelConsumerId2 = TunnelConsumerId.valueOf(20); |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 78 | private PcePathInfo failedPathInfo1; |
| 79 | private PcePathInfo failedPathInfo2; |
| 80 | private PcePathInfo failedPathInfo3; |
| 81 | private PcePathInfo failedPathInfo4; |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 82 | |
| 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 S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 112 | |
| 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 K | ba1c912 | 2017-04-05 15:27:23 +0530 | [diff] [blame] | 122 | failedPathInfo1 = new PcePathInfo(src1, dst1, name1, constraints1, lspType1, null, false); |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 123 | |
| 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 K | ba1c912 | 2017-04-05 15:27:23 +0530 | [diff] [blame] | 133 | failedPathInfo2 = new PcePathInfo(src2, dst2, name2, constraints2, lspType2, null, false); |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 134 | |
| 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 K | ba1c912 | 2017-04-05 15:27:23 +0530 | [diff] [blame] | 144 | failedPathInfo3 = new PcePathInfo(src3, dst3, name3, constraints3, lspType3, null, false); |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 145 | |
| 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 K | ba1c912 | 2017-04-05 15:27:23 +0530 | [diff] [blame] | 155 | failedPathInfo4 = new PcePathInfo(src4, dst4, name4, constraints4, lspType4, null, false); |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | @After |
| 159 | public void tearDown() throws Exception { |
| 160 | } |
| 161 | |
| 162 | /** |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 163 | * Checks the operation of addTunnelInfo() method. |
| 164 | */ |
| 165 | @Test |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 166 | public void testAddExplicitPathInfo() { |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 167 | // initialization |
| 168 | distrPceStore.storageService = new TestStorageService(); |
| 169 | distrPceStore.activate(); |
| 170 | |
Satish K | 2eb5d84 | 2017-04-04 16:28:37 +0530 | [diff] [blame] | 171 | 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 S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | /** |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 179 | * 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 S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 195 | * 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 S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 208 | * 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 S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 218 | * 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 S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 230 | * 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 S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 241 | } |