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