Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +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 | */ |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 16 | package org.onosproject.pcelabelstore.label; |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 17 | |
| 18 | import static org.hamcrest.MatcherAssert.assertThat; |
| 19 | import static org.hamcrest.Matchers.is; |
| 20 | import static org.hamcrest.Matchers.notNullValue; |
| 21 | import static org.hamcrest.Matchers.nullValue; |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 22 | import static org.onosproject.net.Link.Type.DIRECT; |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 23 | import java.util.Iterator; |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 24 | import java.util.List; |
| 25 | import java.util.LinkedList; |
| 26 | |
| 27 | import org.junit.After; |
| 28 | import org.junit.Before; |
| 29 | import org.junit.Test; |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 30 | import org.onlab.packet.IpAddress; |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 31 | import org.onosproject.incubator.net.resource.label.LabelResourceId; |
| 32 | import org.onosproject.incubator.net.resource.label.LabelResourceAdminService; |
| 33 | import org.onosproject.incubator.net.resource.label.LabelResourceService; |
| 34 | import org.onosproject.incubator.net.tunnel.LabelStack; |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 35 | import org.onosproject.net.AnnotationKeys; |
| 36 | import org.onosproject.net.Annotations; |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 37 | import org.onosproject.net.ConnectPoint; |
| 38 | import org.onosproject.net.DefaultAnnotations; |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 39 | import org.onosproject.net.DefaultDevice; |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 40 | import org.onosproject.net.DefaultPath; |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 41 | import org.onosproject.net.Device; |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 42 | import org.onosproject.net.DeviceId; |
| 43 | import org.onosproject.net.PortNumber; |
| 44 | import org.onosproject.net.Path; |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 45 | import org.onosproject.net.provider.ProviderId; |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 46 | import org.onosproject.pcelabelstore.api.PceLabelStore; |
| 47 | import org.onosproject.pcelabelstore.util.LabelResourceAdapter; |
| 48 | import org.onosproject.pcelabelstore.util.MockDeviceService; |
| 49 | import org.onosproject.pcelabelstore.util.MockNetConfigRegistryAdapter; |
| 50 | import org.onosproject.pcelabelstore.util.MockPcepClientController; |
| 51 | import org.onosproject.pcelabelstore.util.PceLabelStoreAdapter; |
| 52 | import org.onosproject.pcelabelstore.util.PcepClientAdapter; |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 53 | import org.onosproject.pcep.api.DeviceCapability; |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 54 | import org.onosproject.pcep.controller.PccId; |
| 55 | import org.onosproject.pcep.controller.impl.PceccSrTeBeHandler; |
| 56 | import org.onosproject.pcepio.protocol.PcepVersion; |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 57 | import org.onosproject.net.DefaultLink; |
| 58 | import org.onosproject.net.Link; |
| 59 | |
| 60 | /** |
| 61 | * Unit tests for PceccSrTeBeHandler class. |
| 62 | */ |
| 63 | public class PceccSrTeBeHandlerTest { |
| 64 | |
| 65 | public static final long GLOBAL_LABEL_SPACE_MIN = 4097; |
| 66 | public static final long GLOBAL_LABEL_SPACE_MAX = 5121; |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 67 | private static final String L3 = "L3"; |
| 68 | private static final String LSRID = "lsrId"; |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 69 | |
| 70 | private PceccSrTeBeHandler srTeHandler; |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 71 | private LabelResourceAdminService labelRsrcAdminService; |
| 72 | private LabelResourceService labelRsrcService; |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 73 | private PceLabelStore pceStore; |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 74 | private MockDeviceService deviceService; |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 75 | private MockNetConfigRegistryAdapter netCfgService = new MockNetConfigRegistryAdapter(); |
| 76 | private MockPcepClientController clientController = new MockPcepClientController(); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 77 | private ProviderId providerId; |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 78 | private DeviceId deviceId1, deviceId2, deviceId3, deviceId4, deviceId5; |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 79 | private Device deviceD1; |
| 80 | private Device deviceD2; |
| 81 | private Device deviceD3; |
| 82 | private Device deviceD4; |
| 83 | private Device deviceD5; |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 84 | private PortNumber port1; |
| 85 | private PortNumber port2; |
| 86 | private PortNumber port3; |
| 87 | private PortNumber port4; |
| 88 | private PortNumber port5; |
| 89 | private Link link1; |
| 90 | private Link link2; |
| 91 | private Link link3; |
| 92 | private Link link4; |
| 93 | private Path path1; |
| 94 | LabelResourceId labelId; |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 95 | |
| 96 | @Before |
| 97 | public void setUp() throws Exception { |
| 98 | // Initialization of member variables |
| 99 | srTeHandler = PceccSrTeBeHandler.getInstance(); |
| 100 | labelRsrcService = new LabelResourceAdapter(); |
| 101 | labelRsrcAdminService = new LabelResourceAdapter(); |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 102 | pceStore = new PceLabelStoreAdapter(); |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 103 | deviceService = new MockDeviceService(); |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 104 | |
| 105 | srTeHandler.initialize(labelRsrcAdminService, |
| 106 | labelRsrcService, |
| 107 | clientController, |
| 108 | pceStore, |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 109 | deviceService); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 110 | |
| 111 | // Creates path |
| 112 | // Creates list of links |
| 113 | providerId = new ProviderId("of", "foo"); |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 114 | |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 115 | PccId pccId1 = PccId.pccId(IpAddress.valueOf("11.1.1.1")); |
| 116 | PccId pccId2 = PccId.pccId(IpAddress.valueOf("12.1.1.1")); |
| 117 | PccId pccId3 = PccId.pccId(IpAddress.valueOf("13.1.1.1")); |
| 118 | PccId pccId4 = PccId.pccId(IpAddress.valueOf("14.1.1.1")); |
| 119 | PccId pccId5 = PccId.pccId(IpAddress.valueOf("15.1.1.1")); |
| 120 | |
| 121 | PcepClientAdapter pc1 = new PcepClientAdapter(); |
| 122 | pc1.init(pccId1, PcepVersion.PCEP_1); |
| 123 | |
| 124 | PcepClientAdapter pc2 = new PcepClientAdapter(); |
| 125 | pc2.init(pccId2, PcepVersion.PCEP_1); |
| 126 | |
| 127 | PcepClientAdapter pc3 = new PcepClientAdapter(); |
| 128 | pc3.init(pccId3, PcepVersion.PCEP_1); |
| 129 | |
| 130 | PcepClientAdapter pc4 = new PcepClientAdapter(); |
| 131 | pc4.init(pccId4, PcepVersion.PCEP_1); |
| 132 | |
| 133 | PcepClientAdapter pc5 = new PcepClientAdapter(); |
| 134 | pc5.init(pccId5, PcepVersion.PCEP_1); |
| 135 | |
| 136 | clientController.addClient(pccId1, pc1); |
| 137 | clientController.addClient(pccId2, pc2); |
| 138 | clientController.addClient(pccId3, pc3); |
| 139 | clientController.addClient(pccId4, pc4); |
| 140 | clientController.addClient(pccId5, pc5); |
| 141 | |
| 142 | deviceId1 = DeviceId.deviceId("11.1.1.1"); |
| 143 | deviceId2 = DeviceId.deviceId("12.1.1.1"); |
| 144 | deviceId3 = DeviceId.deviceId("13.1.1.1"); |
| 145 | deviceId4 = DeviceId.deviceId("14.1.1.1"); |
| 146 | deviceId5 = DeviceId.deviceId("15.1.1.1"); |
| 147 | |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 148 | // Devices |
| 149 | DefaultAnnotations.Builder builderDev1 = DefaultAnnotations.builder(); |
| 150 | DefaultAnnotations.Builder builderDev2 = DefaultAnnotations.builder(); |
| 151 | DefaultAnnotations.Builder builderDev3 = DefaultAnnotations.builder(); |
| 152 | DefaultAnnotations.Builder builderDev4 = DefaultAnnotations.builder(); |
| 153 | DefaultAnnotations.Builder builderDev5 = DefaultAnnotations.builder(); |
| 154 | |
| 155 | builderDev1.set(AnnotationKeys.TYPE, L3); |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 156 | builderDev1.set(LSRID, "11.1.1.1"); |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 157 | |
| 158 | builderDev2.set(AnnotationKeys.TYPE, L3); |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 159 | builderDev2.set(LSRID, "12.1.1.1"); |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 160 | |
| 161 | builderDev3.set(AnnotationKeys.TYPE, L3); |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 162 | builderDev3.set(LSRID, "13.1.1.1"); |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 163 | |
| 164 | builderDev4.set(AnnotationKeys.TYPE, L3); |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 165 | builderDev4.set(LSRID, "14.1.1.1"); |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 166 | |
| 167 | builderDev5.set(AnnotationKeys.TYPE, L3); |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 168 | builderDev5.set(LSRID, "15.1.1.1"); |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 169 | |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 170 | deviceD1 = new MockDevice(deviceId1, builderDev1.build()); |
| 171 | deviceD2 = new MockDevice(deviceId2, builderDev2.build()); |
| 172 | deviceD3 = new MockDevice(deviceId3, builderDev3.build()); |
| 173 | deviceD4 = new MockDevice(deviceId4, builderDev4.build()); |
| 174 | deviceD5 = new MockDevice(deviceId5, builderDev5.build()); |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 175 | |
| 176 | deviceService.addDevice(deviceD1); |
| 177 | deviceService.addDevice(deviceD2); |
| 178 | deviceService.addDevice(deviceD3); |
| 179 | deviceService.addDevice(deviceD4); |
| 180 | deviceService.addDevice(deviceD5); |
| 181 | |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 182 | DeviceCapability device1Cap = netCfgService.addConfig(deviceId1, DeviceCapability.class); |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 183 | device1Cap.setLabelStackCap(true).setLocalLabelCap(false).setSrCap(true).apply(); |
| 184 | |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 185 | DeviceCapability device2Cap = netCfgService.addConfig(deviceId2, DeviceCapability.class); |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 186 | device2Cap.setLabelStackCap(true).setLocalLabelCap(false).setSrCap(true).apply(); |
| 187 | |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 188 | DeviceCapability device3Cap = netCfgService.addConfig(deviceId3, DeviceCapability.class); |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 189 | device3Cap.setLabelStackCap(true).setLocalLabelCap(false).setSrCap(true).apply(); |
| 190 | |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 191 | DeviceCapability device4Cap = netCfgService.addConfig(deviceId4, DeviceCapability.class); |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 192 | device4Cap.setLabelStackCap(true).setLocalLabelCap(false).setSrCap(true).apply(); |
| 193 | |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 194 | DeviceCapability device5Cap = netCfgService.addConfig(deviceId5, DeviceCapability.class); |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 195 | device5Cap.setLabelStackCap(true).setLocalLabelCap(false).setSrCap(true).apply(); |
| 196 | |
| 197 | // Port Numbers |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 198 | port1 = PortNumber.portNumber(1); |
| 199 | port2 = PortNumber.portNumber(2); |
| 200 | port3 = PortNumber.portNumber(3); |
| 201 | port4 = PortNumber.portNumber(4); |
| 202 | port5 = PortNumber.portNumber(5); |
| 203 | List<Link> linkList = new LinkedList<>(); |
| 204 | |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 205 | link1 = DefaultLink.builder().providerId(providerId) |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 206 | .annotations(DefaultAnnotations.builder().set("key1", "yahoo").build()) |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 207 | .src(new ConnectPoint(deviceD1.id(), port1)).dst(new ConnectPoint(deviceD2.id(), port2)).type(DIRECT) |
| 208 | .state(Link.State.ACTIVE).build(); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 209 | linkList.add(link1); |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 210 | link2 = DefaultLink.builder().providerId(providerId) |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 211 | .annotations(DefaultAnnotations.builder().set("key2", "yahoo").build()) |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 212 | .src(new ConnectPoint(deviceD2.id(), port2)).dst(new ConnectPoint(deviceD3.id(), port3)).type(DIRECT) |
| 213 | .state(Link.State.ACTIVE).build(); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 214 | linkList.add(link2); |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 215 | link3 = DefaultLink.builder().providerId(providerId) |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 216 | .annotations(DefaultAnnotations.builder().set("key3", "yahoo").build()) |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 217 | .src(new ConnectPoint(deviceD3.id(), port3)).dst(new ConnectPoint(deviceD4.id(), port4)).type(DIRECT) |
| 218 | .state(Link.State.ACTIVE).build(); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 219 | linkList.add(link3); |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 220 | link4 = DefaultLink.builder().providerId(providerId) |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 221 | .annotations(DefaultAnnotations.builder().set("key4", "yahoo").build()) |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 222 | .src(new ConnectPoint(deviceD4.id(), port4)).dst(new ConnectPoint(deviceD5.id(), port5)).type(DIRECT) |
| 223 | .state(Link.State.ACTIVE).build(); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 224 | linkList.add(link4); |
| 225 | |
| 226 | // Path |
| 227 | path1 = new DefaultPath(providerId, linkList, 10); |
| 228 | } |
| 229 | |
| 230 | @After |
| 231 | public void tearDown() throws Exception { |
| 232 | } |
| 233 | |
| 234 | /** |
| 235 | * Checks the operation of getInstance() method. |
| 236 | */ |
| 237 | @Test |
| 238 | public void testGetInstance() { |
| 239 | assertThat(srTeHandler, is(notNullValue())); |
| 240 | } |
| 241 | |
| 242 | /** |
| 243 | * Checks the operation of reserveGlobalPool() method. |
| 244 | */ |
| 245 | @Test |
| 246 | public void testReserveGlobalPool() { |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 247 | assertThat(srTeHandler.reserveGlobalPool(GLOBAL_LABEL_SPACE_MIN, GLOBAL_LABEL_SPACE_MAX), is(true)); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | /** |
| 251 | * Checks the operation of allocateNodeLabel() method on node label. |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 252 | */ |
| 253 | @Test |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 254 | public void testAllocateNodeLabel() { |
| 255 | // Specific device D1.deviceId |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 256 | |
| 257 | //device 1 |
| 258 | String lsrId1 = "11.1.1.1"; |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 259 | // Allocate node label for specific device D1deviceId |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 260 | assertThat(srTeHandler.allocateNodeLabel(deviceId1, lsrId1), is(true)); |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 261 | // Retrieve label from store |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 262 | LabelResourceId labelId = pceStore.getGlobalNodeLabel(deviceId1); |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 263 | // Check whether label is generated for this device D1.deviceId() |
| 264 | assertThat(labelId, is(notNullValue())); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 265 | |
| 266 | // device 2 |
| 267 | String lsrId2 = "12.1.1.1"; |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 268 | // Allocate node label for specific device D2.deviceId() |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 269 | assertThat(srTeHandler.allocateNodeLabel(deviceId2, lsrId2), is(true)); |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 270 | // Retrieve label from store |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 271 | labelId = pceStore.getGlobalNodeLabel(deviceId2); |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 272 | // Check whether label is generated for this device D2.deviceId() |
| 273 | assertThat(labelId, is(notNullValue())); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 274 | |
| 275 | // device 3 |
| 276 | String lsrId3 = "13.1.1.1"; |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 277 | // Allocate node label for specific device D3.deviceId() |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 278 | assertThat(srTeHandler.allocateNodeLabel(deviceId3, lsrId3), is(true)); |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 279 | // Retrieve label from store |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 280 | labelId = pceStore.getGlobalNodeLabel(deviceId3); |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 281 | // Check whether label is generated for this device D3.deviceId() |
| 282 | assertThat(labelId, is(notNullValue())); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 283 | |
| 284 | // device 4 |
| 285 | String lsrId4 = "14.1.1.1"; |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 286 | // Allocate node label for specific device D4.deviceId() |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 287 | assertThat(srTeHandler.allocateNodeLabel(deviceId4, lsrId4), is(true)); |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 288 | // Retrieve label from store |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 289 | labelId = pceStore.getGlobalNodeLabel(deviceId4); |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 290 | // Check whether label is generated for this device D4.deviceId() |
| 291 | assertThat(labelId, is(notNullValue())); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 292 | |
| 293 | // device 5 |
| 294 | String lsrId5 = "15.1.1.1"; |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 295 | // Allocate node label for specific device D5.deviceId() |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 296 | assertThat(srTeHandler.allocateNodeLabel(deviceId5, lsrId5), is(true)); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 297 | // Retrieve label from store |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 298 | labelId = pceStore.getGlobalNodeLabel(deviceId5); |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 299 | // Check whether label is generated for this device D5.deviceId() |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 300 | assertThat(labelId, is(notNullValue())); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | /** |
| 304 | * Checks the operation of releaseNodeLabel() method on node label. |
| 305 | */ |
| 306 | @Test |
| 307 | public void testReleaseNodeLabelSuccess() { |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 308 | testAllocateNodeLabel(); |
| 309 | // Specific device D1.deviceId() |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 310 | |
| 311 | //device 1 |
| 312 | String lsrId1 = "11.1.1.1"; |
| 313 | // Check whether successfully released node label |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 314 | assertThat(srTeHandler.releaseNodeLabel(deviceId1, lsrId1), is(true)); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 315 | // Check whether successfully removed label from store |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 316 | LabelResourceId labelId = pceStore.getGlobalNodeLabel(deviceId1); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 317 | assertThat(labelId, is(nullValue())); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 318 | |
| 319 | //device 2 |
| 320 | String lsrId2 = "12.1.1.1"; |
| 321 | // Check whether successfully released node label |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 322 | assertThat(srTeHandler.releaseNodeLabel(deviceId2, lsrId2), is(true)); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 323 | // Check whether successfully removed label from store |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 324 | labelId = pceStore.getGlobalNodeLabel(deviceId2); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 325 | assertThat(labelId, is(nullValue())); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 326 | |
| 327 | //device 3 |
| 328 | String lsrId3 = "13.1.1.1"; |
| 329 | // Check whether successfully released node label |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 330 | assertThat(srTeHandler.releaseNodeLabel(deviceId3, lsrId3), is(true)); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 331 | // Check whether successfully removed label from store |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 332 | labelId = pceStore.getGlobalNodeLabel(deviceId3); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 333 | assertThat(labelId, is(nullValue())); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 334 | |
| 335 | //device 4 |
| 336 | String lsrId4 = "14.1.1.1"; |
| 337 | // Check whether successfully released node label |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 338 | assertThat(srTeHandler.releaseNodeLabel(deviceId4, lsrId4), is(true)); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 339 | // Check whether successfully removed label from store |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 340 | labelId = pceStore.getGlobalNodeLabel(deviceId4); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 341 | assertThat(labelId, is(nullValue())); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 342 | |
| 343 | //device 5 |
| 344 | String lsrId5 = "15.1.1.1"; |
| 345 | // Check whether successfully released node label |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 346 | assertThat(srTeHandler.releaseNodeLabel(deviceId5, lsrId5), is(true)); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 347 | // Check whether successfully removed label from store |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 348 | labelId = pceStore.getGlobalNodeLabel(deviceId5); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 349 | assertThat(labelId, is(nullValue())); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | @Test |
| 353 | public void testReleaseNodeLabelFailure() { |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 354 | testAllocateNodeLabel(); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 355 | |
| 356 | //device 6 |
| 357 | String lsrId6 = "16.1.1.1"; |
| 358 | // Check whether successfully released node label |
| 359 | DeviceId deviceId6 = DeviceId.deviceId("foo6"); |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 360 | assertThat(srTeHandler.releaseNodeLabel(deviceId6, lsrId6), is(false)); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | /** |
| 364 | * Checks the operation of allocateAdjacencyLabel() method on adjacency label. |
| 365 | */ |
| 366 | @Test |
| 367 | public void testAllocateAdjacencyLabel() { |
| 368 | // test link1 |
| 369 | // Check whether adjacency label is allocated successfully. |
| 370 | assertThat(srTeHandler.allocateAdjacencyLabel(link1), is(true)); |
| 371 | // Retrieve from store and check whether adjacency label is generated successfully for this device. |
| 372 | LabelResourceId labelId = pceStore.getAdjLabel(link1); |
| 373 | assertThat(labelId, is(notNullValue())); |
| 374 | |
| 375 | // test link2 |
| 376 | // Check whether adjacency label is allocated successfully. |
| 377 | assertThat(srTeHandler.allocateAdjacencyLabel(link2), is(true)); |
| 378 | // Retrieve from store and check whether adjacency label is generated successfully for this device. |
| 379 | labelId = pceStore.getAdjLabel(link2); |
| 380 | assertThat(labelId, is(notNullValue())); |
| 381 | |
| 382 | // test link3 |
| 383 | // Check whether adjacency label is allocated successfully. |
| 384 | assertThat(srTeHandler.allocateAdjacencyLabel(link3), is(true)); |
| 385 | // Retrieve from store and check whether adjacency label is generated successfully for this device. |
| 386 | labelId = pceStore.getAdjLabel(link3); |
| 387 | assertThat(labelId, is(notNullValue())); |
| 388 | |
| 389 | // test link4 |
| 390 | // Check whether adjacency label is allocated successfully. |
| 391 | assertThat(srTeHandler.allocateAdjacencyLabel(link4), is(true)); |
| 392 | // Retrieve from store and check whether adjacency label is generated successfully for this device. |
| 393 | labelId = pceStore.getAdjLabel(link4); |
| 394 | assertThat(labelId, is(notNullValue())); |
| 395 | } |
| 396 | |
| 397 | /** |
| 398 | * Checks the operation of releaseAdjacencyLabel() method on adjacency label. |
| 399 | */ |
| 400 | @Test |
| 401 | public void testReleaseAdjacencyLabel() { |
| 402 | // Test link1 |
| 403 | // Check whether adjacency label is released successfully. |
| 404 | assertThat(srTeHandler.allocateAdjacencyLabel(link1), is(true)); |
| 405 | assertThat(srTeHandler.releaseAdjacencyLabel(link1), is(true)); |
| 406 | // Retrieve from store and check whether adjacency label is removed successfully for this device. |
| 407 | LabelResourceId labelId = pceStore.getAdjLabel(link1); |
| 408 | assertThat(labelId, is(nullValue())); |
| 409 | |
| 410 | // Test link2 |
| 411 | // Check whether adjacency label is released successfully. |
| 412 | assertThat(srTeHandler.allocateAdjacencyLabel(link2), is(true)); |
| 413 | assertThat(srTeHandler.releaseAdjacencyLabel(link2), is(true)); |
| 414 | // Retrieve from store and check whether adjacency label is removed successfully for this device. |
| 415 | labelId = pceStore.getAdjLabel(link2); |
| 416 | assertThat(labelId, is(nullValue())); |
| 417 | } |
| 418 | |
| 419 | /** |
| 420 | * Checks the operation of computeLabelStack() method. |
| 421 | */ |
| 422 | @Test |
| 423 | public void testComputeLabelStack() { |
| 424 | // Allocate node labels to each devices |
| 425 | labelId = LabelResourceId.labelResourceId(4097); |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 426 | pceStore.addGlobalNodeLabel(deviceId1, labelId); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 427 | labelId = LabelResourceId.labelResourceId(4098); |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 428 | pceStore.addGlobalNodeLabel(deviceId2, labelId); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 429 | labelId = LabelResourceId.labelResourceId(4099); |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 430 | pceStore.addGlobalNodeLabel(deviceId3, labelId); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 431 | labelId = LabelResourceId.labelResourceId(4100); |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 432 | pceStore.addGlobalNodeLabel(deviceId4, labelId); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 433 | labelId = LabelResourceId.labelResourceId(4101); |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 434 | pceStore.addGlobalNodeLabel(deviceId5, labelId); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 435 | |
| 436 | // Allocate adjacency labels to each devices |
| 437 | labelId = LabelResourceId.labelResourceId(5122); |
| 438 | pceStore.addAdjLabel(link1, labelId); |
| 439 | labelId = LabelResourceId.labelResourceId(5123); |
| 440 | pceStore.addAdjLabel(link2, labelId); |
| 441 | labelId = LabelResourceId.labelResourceId(5124); |
| 442 | pceStore.addAdjLabel(link3, labelId); |
| 443 | labelId = LabelResourceId.labelResourceId(5125); |
| 444 | pceStore.addAdjLabel(link4, labelId); |
| 445 | |
| 446 | // Compute label stack |
| 447 | LabelStack labelStack = srTeHandler.computeLabelStack(path1); |
| 448 | |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 449 | List<LabelResourceId> labelList = labelStack.labelResources(); |
| 450 | Iterator<LabelResourceId> iterator = labelList.iterator(); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 451 | |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 452 | // check adjacency label of D1.deviceId() |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 453 | labelId = iterator.next(); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 454 | assertThat(labelId, is(LabelResourceId.labelResourceId(5122))); |
| 455 | |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 456 | // check node-label of D2.deviceId() |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 457 | labelId = iterator.next(); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 458 | assertThat(labelId, is(LabelResourceId.labelResourceId(4098))); |
| 459 | |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 460 | // check adjacency label of D2.deviceId() |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 461 | labelId = iterator.next(); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 462 | assertThat(labelId, is(LabelResourceId.labelResourceId(5123))); |
| 463 | |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 464 | // check node-label of D3.deviceId() |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 465 | labelId = iterator.next(); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 466 | assertThat(labelId, is(LabelResourceId.labelResourceId(4099))); |
| 467 | |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 468 | // check adjacency label of D3.deviceId() |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 469 | labelId = iterator.next(); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 470 | assertThat(labelId, is(LabelResourceId.labelResourceId(5124))); |
| 471 | |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 472 | // check node-label of D4.deviceId() |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 473 | labelId = iterator.next(); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 474 | assertThat(labelId, is(LabelResourceId.labelResourceId(4100))); |
| 475 | |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 476 | // check adjacency label of D4.deviceId() |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 477 | labelId = iterator.next(); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 478 | assertThat(labelId, is(LabelResourceId.labelResourceId(5125))); |
| 479 | |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 480 | // check node-label of D5.deviceId() |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 481 | labelId = iterator.next(); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 482 | assertThat(labelId, is(LabelResourceId.labelResourceId(4101))); |
| 483 | } |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame] | 484 | |
| 485 | private class MockDevice extends DefaultDevice { |
| 486 | MockDevice(DeviceId id, Annotations annotations) { |
| 487 | super(null, id, null, null, null, null, null, null, annotations); |
| 488 | } |
| 489 | } |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 490 | } |