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