Committed by
Mahesh Poojary Huawei
[ONOS-4164] Basic PCECC and SR-TE Handlers
Change-Id: I7fbf86d845ec6b5d780f63518776fa841e9fb57c
Showing
6 changed files
with
1712 additions
and
0 deletions
| 1 | +/* | ||
| 2 | + * Copyright 2016-present Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | +package org.onosproject.pce.pceservice; | ||
| 17 | + | ||
| 18 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
| 19 | + | ||
| 20 | +import java.util.Collection; | ||
| 21 | +import java.util.Iterator; | ||
| 22 | +import java.util.List; | ||
| 23 | +import java.util.ListIterator; | ||
| 24 | +import java.util.LinkedList; | ||
| 25 | + | ||
| 26 | +import org.onosproject.incubator.net.resource.label.DefaultLabelResource; | ||
| 27 | +import org.onosproject.incubator.net.resource.label.LabelResource; | ||
| 28 | +import org.onosproject.incubator.net.resource.label.LabelResourceId; | ||
| 29 | +import org.onosproject.incubator.net.resource.label.LabelResourceService; | ||
| 30 | +import org.onosproject.incubator.net.tunnel.Tunnel; | ||
| 31 | +import org.onosproject.net.DeviceId; | ||
| 32 | +import org.onosproject.net.PortNumber; | ||
| 33 | +import org.onosproject.pce.pcestore.api.PceStore; | ||
| 34 | +import org.onosproject.pce.pcestore.api.LspLocalLabelInfo; | ||
| 35 | +import org.onosproject.pce.pcestore.PceccTunnelInfo; | ||
| 36 | +import org.onosproject.pce.pcestore.DefaultLspLocalLabelInfo; | ||
| 37 | +import org.onosproject.net.Link; | ||
| 38 | + | ||
| 39 | +import org.slf4j.Logger; | ||
| 40 | +import org.slf4j.LoggerFactory; | ||
| 41 | + | ||
| 42 | +import com.google.common.collect.ArrayListMultimap; | ||
| 43 | +import com.google.common.collect.Multimap; | ||
| 44 | + | ||
| 45 | +/** | ||
| 46 | + * Basic PCECC handler. | ||
| 47 | + * In Basic PCECC, after path computation will configure IN and OUT label to nodes. | ||
| 48 | + * [X]OUT---link----IN[Y]OUT---link-----IN[Z] where X, Y and Z are nodes. | ||
| 49 | + * For generating labels, will go thorough links in the path from Egress to Ingress. | ||
| 50 | + * In each link, will take label from destination node local pool as IN label, | ||
| 51 | + * and assign this label as OUT label to source node. | ||
| 52 | + */ | ||
| 53 | +public final class BasicPceccHandler { | ||
| 54 | + private static final Logger log = LoggerFactory.getLogger(BasicPceccHandler.class); | ||
| 55 | + | ||
| 56 | + private static final String LABEL_RESOURCE_SERVICE_NULL = "Label Resource Service cannot be null"; | ||
| 57 | + private static final String PCE_STORE_NULL = "PCE Store cannot be null"; | ||
| 58 | + private static BasicPceccHandler crHandlerInstance = null; | ||
| 59 | + private LabelResourceService labelRsrcService; | ||
| 60 | + private PceStore pceStore; | ||
| 61 | + | ||
| 62 | + /** | ||
| 63 | + * Initializes default values. | ||
| 64 | + */ | ||
| 65 | + private BasicPceccHandler() { | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + /** | ||
| 69 | + * Returns single instance of this class. | ||
| 70 | + * | ||
| 71 | + * @return this class single instance | ||
| 72 | + */ | ||
| 73 | + public static BasicPceccHandler getInstance() { | ||
| 74 | + if (crHandlerInstance == null) { | ||
| 75 | + crHandlerInstance = new BasicPceccHandler(); | ||
| 76 | + } | ||
| 77 | + return crHandlerInstance; | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + /** | ||
| 81 | + * Initialization of label manager and pce store. | ||
| 82 | + * | ||
| 83 | + * @param labelRsrcService label resource service | ||
| 84 | + * @param pceStore pce label store | ||
| 85 | + */ | ||
| 86 | + public void initialize(LabelResourceService labelRsrcService, PceStore pceStore) { | ||
| 87 | + this.labelRsrcService = labelRsrcService; | ||
| 88 | + this.pceStore = pceStore; | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + /** | ||
| 92 | + * Allocates labels from local resource pool and configure these (IN and OUT) labels into devices. | ||
| 93 | + * | ||
| 94 | + * @param tunnel tunnel between ingress to egress | ||
| 95 | + * @return success or failure | ||
| 96 | + */ | ||
| 97 | + public boolean allocateLabel(Tunnel tunnel) { | ||
| 98 | + long applyNum = 1; | ||
| 99 | + boolean isLastLabelToPush = false; | ||
| 100 | + Collection<LabelResource> labelRscList; | ||
| 101 | + | ||
| 102 | + checkNotNull(labelRsrcService, LABEL_RESOURCE_SERVICE_NULL); | ||
| 103 | + checkNotNull(pceStore, PCE_STORE_NULL); | ||
| 104 | + | ||
| 105 | + List<Link> linkList = tunnel.path().links(); | ||
| 106 | + if ((linkList != null) && (linkList.size() > 0)) { | ||
| 107 | + // Sequence through reverse order to push local labels into devices | ||
| 108 | + // Generation of labels from egress to ingress | ||
| 109 | + for (ListIterator iterator = linkList.listIterator(linkList.size()); iterator.hasPrevious();) { | ||
| 110 | + Link link = (Link) iterator.previous(); | ||
| 111 | + DeviceId dstDeviceId = link.dst().deviceId(); | ||
| 112 | + DeviceId srcDeviceId = link.src().deviceId(); | ||
| 113 | + labelRscList = labelRsrcService.applyFromDevicePool(dstDeviceId, applyNum); | ||
| 114 | + if ((labelRscList != null) && (labelRscList.size() > 0)) { | ||
| 115 | + // Link label value is taken from destination device local pool. | ||
| 116 | + // [X]OUT---link----IN[Y]OUT---link-----IN[Z] where X, Y and Z are nodes. | ||
| 117 | + // Link label value is used as OUT and IN for both ends | ||
| 118 | + // (source and destination devices) of the link. | ||
| 119 | + // Currently only one label is allocated to a device (destination device). | ||
| 120 | + // So, no need to iterate through list | ||
| 121 | + Iterator<LabelResource> labelIterator = labelRscList.iterator(); | ||
| 122 | + DefaultLabelResource defaultLabelResource = (DefaultLabelResource) labelIterator.next(); | ||
| 123 | + LabelResourceId labelId = defaultLabelResource.labelResourceId(); | ||
| 124 | + log.debug("Allocated local label: " + labelId.toString() | ||
| 125 | + + "to device: " + defaultLabelResource.deviceId().toString()); | ||
| 126 | + PortNumber dstPort = link.dst().port(); | ||
| 127 | + | ||
| 128 | + // Check whether this is last link label to push | ||
| 129 | + if (!iterator.hasPrevious()) { | ||
| 130 | + isLastLabelToPush = true; | ||
| 131 | + } | ||
| 132 | + | ||
| 133 | + // Push into destination device | ||
| 134 | + //TODO: uncomment below lines once installLocalLabelRule() method is ready | ||
| 135 | + // Destination device IN port is link.dst().port() | ||
| 136 | + //installLocalLabelRule(dstDeviceId, labelId, dstPort, tunnel.tunnelId(), isLastLabelToPush, | ||
| 137 | + // LabelType.IN, Objective.Operation.ADD); | ||
| 138 | + | ||
| 139 | + // Push into source device | ||
| 140 | + //TODO: uncomment below lines once installLocalLabelRule() method is ready | ||
| 141 | + // Source device OUT port will be link.dst().port(). Means its remote port used to send packet. | ||
| 142 | + //installLocalLabelRule(srcDeviceId, labelId, dstPort, tunnel.tunnelId(), isLastLabelToPush, | ||
| 143 | + // LabelType.OUT, Objective.Operation.ADD); | ||
| 144 | + | ||
| 145 | + // Add or update pcecc tunnel info in pce store. | ||
| 146 | + updatePceccTunnelInfoInStore(srcDeviceId, dstDeviceId, labelId, dstPort, | ||
| 147 | + tunnel, isLastLabelToPush); | ||
| 148 | + } else { | ||
| 149 | + log.error("Unable to allocate label to device id {}.", dstDeviceId.toString()); | ||
| 150 | + releaseLabel(tunnel); | ||
| 151 | + return false; | ||
| 152 | + } | ||
| 153 | + } | ||
| 154 | + } else { | ||
| 155 | + log.error("Tunnel {} is having empty links.", tunnel.toString()); | ||
| 156 | + return false; | ||
| 157 | + } | ||
| 158 | + | ||
| 159 | + return true; | ||
| 160 | + } | ||
| 161 | + | ||
| 162 | + /** | ||
| 163 | + * Updates list of local labels of PCECC tunnel info in pce store. | ||
| 164 | + * | ||
| 165 | + * @param srcDeviceId source device in a link | ||
| 166 | + * @param dstDeviceId destination device in a link | ||
| 167 | + * @param labelId label id of a link | ||
| 168 | + * @param dstPort destination device port number of a link | ||
| 169 | + * @param tunnel tunnel | ||
| 170 | + * @param isLastLabelToPush indicates this is the last label to push in Basic PCECC case | ||
| 171 | + */ | ||
| 172 | + public void updatePceccTunnelInfoInStore(DeviceId srcDeviceId, DeviceId dstDeviceId, LabelResourceId labelId, | ||
| 173 | + PortNumber dstPort, Tunnel tunnel, boolean isLastLabelToPush) { | ||
| 174 | + // First try to retrieve device from store and update its label id if it is exists, | ||
| 175 | + // otherwise add it | ||
| 176 | + boolean dstDeviceUpdated = false; | ||
| 177 | + boolean srcDeviceUpdated = false; | ||
| 178 | + | ||
| 179 | + PceccTunnelInfo pceccTunnelInfo = pceStore.getTunnelInfo(tunnel.tunnelId()); | ||
| 180 | + List<LspLocalLabelInfo> lspLabelInfoList; | ||
| 181 | + if (pceccTunnelInfo != null) { | ||
| 182 | + lspLabelInfoList = pceccTunnelInfo.lspLocalLabelInfoList(); | ||
| 183 | + if ((lspLabelInfoList != null) && (lspLabelInfoList.size() > 0)) { | ||
| 184 | + for (int i = 0; i < lspLabelInfoList.size(); ++i) { | ||
| 185 | + LspLocalLabelInfo lspLocalLabelInfo = | ||
| 186 | + (DefaultLspLocalLabelInfo) lspLabelInfoList.get(i); | ||
| 187 | + LspLocalLabelInfo.Builder lspLocalLabelInfoBuilder = null; | ||
| 188 | + if (dstDeviceId.equals(lspLocalLabelInfo.deviceId())) { | ||
| 189 | + lspLocalLabelInfoBuilder = DefaultLspLocalLabelInfo.builder(lspLocalLabelInfo); | ||
| 190 | + lspLocalLabelInfoBuilder.inLabelId(labelId); | ||
| 191 | + // Destination device IN port will be link destination port | ||
| 192 | + lspLocalLabelInfoBuilder.inPort(dstPort); | ||
| 193 | + dstDeviceUpdated = true; | ||
| 194 | + } else if (srcDeviceId.equals(lspLocalLabelInfo.deviceId())) { | ||
| 195 | + lspLocalLabelInfoBuilder = DefaultLspLocalLabelInfo.builder(lspLocalLabelInfo); | ||
| 196 | + lspLocalLabelInfoBuilder.outLabelId(labelId); | ||
| 197 | + // Source device OUT port will be link destination (remote) port | ||
| 198 | + lspLocalLabelInfoBuilder.outPort(dstPort); | ||
| 199 | + srcDeviceUpdated = true; | ||
| 200 | + } | ||
| 201 | + | ||
| 202 | + // Update | ||
| 203 | + if ((lspLocalLabelInfoBuilder != null) && (dstDeviceUpdated || srcDeviceUpdated)) { | ||
| 204 | + lspLabelInfoList.set(i, lspLocalLabelInfoBuilder.build()); | ||
| 205 | + } | ||
| 206 | + } | ||
| 207 | + } | ||
| 208 | + } | ||
| 209 | + | ||
| 210 | + // If it is not found in store then add it to store | ||
| 211 | + if (!dstDeviceUpdated || !srcDeviceUpdated) { | ||
| 212 | + // If tunnel info itself not available then create new one, otherwise add node to list. | ||
| 213 | + if (pceccTunnelInfo == null) { | ||
| 214 | + pceccTunnelInfo = new PceccTunnelInfo(); | ||
| 215 | + lspLabelInfoList = new LinkedList<>(); | ||
| 216 | + } else { | ||
| 217 | + lspLabelInfoList = pceccTunnelInfo.lspLocalLabelInfoList(); | ||
| 218 | + if (lspLabelInfoList == null) { | ||
| 219 | + lspLabelInfoList = new LinkedList<>(); | ||
| 220 | + } | ||
| 221 | + } | ||
| 222 | + | ||
| 223 | + if (!dstDeviceUpdated) { | ||
| 224 | + LspLocalLabelInfo lspLocalLabelInfo = DefaultLspLocalLabelInfo.builder() | ||
| 225 | + .deviceId(dstDeviceId) | ||
| 226 | + .inLabelId(labelId) | ||
| 227 | + .outLabelId(null) | ||
| 228 | + .inPort(dstPort) // Destination device IN port will be link destination port | ||
| 229 | + .outPort(null) | ||
| 230 | + .build(); | ||
| 231 | + lspLabelInfoList.add(lspLocalLabelInfo); | ||
| 232 | + } | ||
| 233 | + | ||
| 234 | + if (!srcDeviceUpdated) { | ||
| 235 | + LspLocalLabelInfo lspLocalLabelInfo = DefaultLspLocalLabelInfo.builder() | ||
| 236 | + .deviceId(srcDeviceId) | ||
| 237 | + .inLabelId(null) | ||
| 238 | + .outLabelId(labelId) | ||
| 239 | + .inPort(null) | ||
| 240 | + .outPort(dstPort) // Source device OUT port will be link destination (remote) port | ||
| 241 | + .build(); | ||
| 242 | + lspLabelInfoList.add(lspLocalLabelInfo); | ||
| 243 | + } | ||
| 244 | + | ||
| 245 | + pceccTunnelInfo.lspLocalLabelInfoList(lspLabelInfoList); | ||
| 246 | + pceStore.addTunnelInfo(tunnel.tunnelId(), pceccTunnelInfo); | ||
| 247 | + } | ||
| 248 | + } | ||
| 249 | + | ||
| 250 | + /** | ||
| 251 | + * Deallocates unused labels to device pools. | ||
| 252 | + * | ||
| 253 | + * @param tunnel tunnel between ingress to egress | ||
| 254 | + */ | ||
| 255 | + public void releaseLabel(Tunnel tunnel) { | ||
| 256 | + boolean isLastLabelToPush = false; | ||
| 257 | + | ||
| 258 | + checkNotNull(labelRsrcService, LABEL_RESOURCE_SERVICE_NULL); | ||
| 259 | + checkNotNull(pceStore, PCE_STORE_NULL); | ||
| 260 | + | ||
| 261 | + Multimap<DeviceId, LabelResource> release = ArrayListMultimap.create(); | ||
| 262 | + PceccTunnelInfo pceccTunnelInfo = pceStore.getTunnelInfo(tunnel.tunnelId()); | ||
| 263 | + if (pceccTunnelInfo != null) { | ||
| 264 | + List<LspLocalLabelInfo> lspLocalLabelInfoList = pceccTunnelInfo.lspLocalLabelInfoList(); | ||
| 265 | + if ((lspLocalLabelInfoList != null) && (lspLocalLabelInfoList.size() > 0)) { | ||
| 266 | + for (Iterator<LspLocalLabelInfo> iterator = lspLocalLabelInfoList.iterator(); iterator.hasNext();) { | ||
| 267 | + LspLocalLabelInfo lspLocalLabelInfo = (DefaultLspLocalLabelInfo) iterator.next(); | ||
| 268 | + DeviceId deviceId = lspLocalLabelInfo.deviceId(); | ||
| 269 | + LabelResourceId inLabelId = lspLocalLabelInfo.inLabelId(); | ||
| 270 | + LabelResourceId outLabelId = lspLocalLabelInfo.outLabelId(); | ||
| 271 | + PortNumber inPort = lspLocalLabelInfo.inPort(); | ||
| 272 | + PortNumber outPort = lspLocalLabelInfo.outPort(); | ||
| 273 | + | ||
| 274 | + // Check whether this is last link label to push | ||
| 275 | + if (!iterator.hasNext()) { | ||
| 276 | + isLastLabelToPush = true; | ||
| 277 | + } | ||
| 278 | + | ||
| 279 | + // Push into device | ||
| 280 | + if ((inLabelId != null) && (inPort != null)) { | ||
| 281 | + //TODO: uncomment below lines once installLocalLabelRule() method is ready | ||
| 282 | + //installLocalLabelRule(deviceId, inLabelId, inPort, tunnelId, isLastLabelToPush, | ||
| 283 | + // LabelType.IN, Objective.Operation.REMOVE); | ||
| 284 | + } | ||
| 285 | + | ||
| 286 | + if ((outLabelId != null) && (outPort != null)) { | ||
| 287 | + //TODO: uncomment below lines once installLocalLabelRule() method is ready | ||
| 288 | + //installLocalLabelRule(deviceId, outLabelId, outPort, tunnelId, isLastLabelToPush, | ||
| 289 | + // LabelType.OUT, Objective.Operation.REMOVE); | ||
| 290 | + } | ||
| 291 | + | ||
| 292 | + // List is stored from egress to ingress. So, using IN label id to release. | ||
| 293 | + // Only one local label is assigned to device (destination node) | ||
| 294 | + // and that is used as OUT label for source node. | ||
| 295 | + // No need to release label for last node in the list from pool because label was not allocated to | ||
| 296 | + // ingress node (source node). | ||
| 297 | + if ((iterator.hasNext()) && (inLabelId != null)) { | ||
| 298 | + LabelResource labelRsc = new DefaultLabelResource(deviceId, inLabelId); | ||
| 299 | + release.put(deviceId, labelRsc); | ||
| 300 | + } | ||
| 301 | + } | ||
| 302 | + } | ||
| 303 | + | ||
| 304 | + // Release from label pool | ||
| 305 | + if (!release.isEmpty()) { | ||
| 306 | + labelRsrcService.releaseToDevicePool(release); | ||
| 307 | + } | ||
| 308 | + | ||
| 309 | + // Remove tunnel info only if tunnel consumer id is not saved. | ||
| 310 | + // If tunnel consumer id is saved, this tunnel info will be removed during releasing bandwidth. | ||
| 311 | + if (pceccTunnelInfo.tunnelConsumerId() == null) { | ||
| 312 | + pceStore.removeTunnelInfo(tunnel.tunnelId()); | ||
| 313 | + } | ||
| 314 | + } else { | ||
| 315 | + log.error("Unable to find PCECC tunnel info in store for a tunnel {}.", tunnel.toString()); | ||
| 316 | + } | ||
| 317 | + } | ||
| 318 | +} |
| 1 | +/* | ||
| 2 | + * Copyright 2016-present Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | + | ||
| 17 | +package org.onosproject.pce.pceservice; | ||
| 18 | + | ||
| 19 | +/** | ||
| 20 | + * Describes about Label type. | ||
| 21 | + */ | ||
| 22 | +public enum LabelType { | ||
| 23 | + /** | ||
| 24 | + * Signifies in label id of a device. | ||
| 25 | + */ | ||
| 26 | + OUT_LABEL(0), | ||
| 27 | + | ||
| 28 | + /** | ||
| 29 | + * Signifies out label id of a device. | ||
| 30 | + */ | ||
| 31 | + IN_LABEL(1); | ||
| 32 | + | ||
| 33 | + int value; | ||
| 34 | + | ||
| 35 | + /** | ||
| 36 | + * Assign val with the value as the Label type. | ||
| 37 | + * | ||
| 38 | + * @param val Label type | ||
| 39 | + */ | ||
| 40 | + LabelType(int val) { | ||
| 41 | + value = val; | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + /** | ||
| 45 | + * Returns value of Label type. | ||
| 46 | + * | ||
| 47 | + * @return label type | ||
| 48 | + */ | ||
| 49 | + public byte type() { | ||
| 50 | + return (byte) value; | ||
| 51 | + } | ||
| 52 | +} |
| 1 | +/* | ||
| 2 | + * Copyright 2016-present Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | +package org.onosproject.pce.pceservice; | ||
| 17 | + | ||
| 18 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
| 19 | + | ||
| 20 | +import java.util.Collection; | ||
| 21 | +import java.util.Iterator; | ||
| 22 | +import java.util.HashSet; | ||
| 23 | +import java.util.List; | ||
| 24 | +import java.util.LinkedList; | ||
| 25 | +import java.util.Map; | ||
| 26 | +import java.util.Set; | ||
| 27 | + | ||
| 28 | +import org.onosproject.incubator.net.resource.label.DefaultLabelResource; | ||
| 29 | +import org.onosproject.incubator.net.resource.label.LabelResource; | ||
| 30 | +import org.onosproject.incubator.net.resource.label.LabelResourceId; | ||
| 31 | +import org.onosproject.incubator.net.resource.label.LabelResourceAdminService; | ||
| 32 | +import org.onosproject.incubator.net.resource.label.LabelResourceService; | ||
| 33 | +import org.onosproject.incubator.net.tunnel.DefaultLabelStack; | ||
| 34 | +import org.onosproject.incubator.net.tunnel.LabelStack; | ||
| 35 | +import org.onosproject.net.DeviceId; | ||
| 36 | +import org.onosproject.pce.pcestore.api.PceStore; | ||
| 37 | +import org.onosproject.net.Link; | ||
| 38 | +import org.onosproject.net.Path; | ||
| 39 | + | ||
| 40 | +import org.slf4j.Logger; | ||
| 41 | +import org.slf4j.LoggerFactory; | ||
| 42 | + | ||
| 43 | +import com.google.common.collect.ArrayListMultimap; | ||
| 44 | +import com.google.common.collect.Multimap; | ||
| 45 | + | ||
| 46 | +/** | ||
| 47 | + * PCE SR-BE and SR-TE functionality. | ||
| 48 | + * SR-BE: Each node (PCC) is allocated a node-SID (label) by the PCECC. The PCECC sends PCLabelUpd to | ||
| 49 | + * update the label map of each node to all the nodes in the domain. | ||
| 50 | + * SR-TE: apart from node-SID, Adj-SID is used where each adjacency is allocated an Adj-SID (label) by the PCECC. | ||
| 51 | + * The PCECC sends PCLabelUpd to update the label map of each Adj to the corresponding nodes in the domain. | ||
| 52 | + */ | ||
| 53 | +public final class PceccSrTeBeHandler { | ||
| 54 | + private static final Logger log = LoggerFactory.getLogger(PceccSrTeBeHandler.class); | ||
| 55 | + | ||
| 56 | + private static final String LABEL_RESOURCE_ADMIN_SERVICE_NULL = "Label Resource Admin Service cannot be null"; | ||
| 57 | + private static final String LABEL_RESOURCE_SERVICE_NULL = "Label Resource Service cannot be null"; | ||
| 58 | + private static final String PCE_STORE_NULL = "PCE Store cannot be null"; | ||
| 59 | + private static final String DEVICE_SERVICE_NULL = "Device Service cannot be null"; | ||
| 60 | + private static final String DEVICE_ID_NULL = "Device-Id cannot be null"; | ||
| 61 | + private static final String LSR_ID_NULL = "LSR-Id cannot be null"; | ||
| 62 | + private static final String DEVICE_ID_LSR_ID_MAP_NULL = "Device-Id and LSR-Id map cannot be null"; | ||
| 63 | + private static final String LINK_NULL = "Link cannot be null"; | ||
| 64 | + private static final String PATH_NULL = "Path cannot be null"; | ||
| 65 | + private static final String LSR_ID = "lsrId"; | ||
| 66 | + private static final int PREFIX_LENGTH = 32; | ||
| 67 | + private static PceccSrTeBeHandler srTeHandlerInstance = null; | ||
| 68 | + private LabelResourceAdminService labelRsrcAdminService; | ||
| 69 | + private LabelResourceService labelRsrcService; | ||
| 70 | + private PceStore pceStore; | ||
| 71 | + | ||
| 72 | + /** | ||
| 73 | + * Initializes default values. | ||
| 74 | + */ | ||
| 75 | + private PceccSrTeBeHandler() { | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + /** | ||
| 79 | + * Returns single instance of this class. | ||
| 80 | + * | ||
| 81 | + * @return this class single instance | ||
| 82 | + */ | ||
| 83 | + public static PceccSrTeBeHandler getInstance() { | ||
| 84 | + if (srTeHandlerInstance == null) { | ||
| 85 | + srTeHandlerInstance = new PceccSrTeBeHandler(); | ||
| 86 | + } | ||
| 87 | + return srTeHandlerInstance; | ||
| 88 | + } | ||
| 89 | + | ||
| 90 | + /** | ||
| 91 | + * Initialization of label manager interfaces and pce store. | ||
| 92 | + * | ||
| 93 | + * @param labelRsrcAdminService label resource admin service | ||
| 94 | + * @param labelRsrcService label resource service | ||
| 95 | + * @param pceStore PCE label store | ||
| 96 | + */ | ||
| 97 | + public void initialize(LabelResourceAdminService labelRsrcAdminService, | ||
| 98 | + LabelResourceService labelRsrcService, PceStore pceStore) { | ||
| 99 | + this.labelRsrcAdminService = labelRsrcAdminService; | ||
| 100 | + this.labelRsrcService = labelRsrcService; | ||
| 101 | + this.pceStore = pceStore; | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | + /** | ||
| 105 | + * Reserves the global label pool. | ||
| 106 | + * | ||
| 107 | + * @param beginLabel minimum value of global label space | ||
| 108 | + * @param endLabel maximum value of global label space | ||
| 109 | + * @return success or failure | ||
| 110 | + */ | ||
| 111 | + public boolean reserveGlobalPool(long beginLabel, long endLabel) { | ||
| 112 | + checkNotNull(labelRsrcAdminService, LABEL_RESOURCE_ADMIN_SERVICE_NULL); | ||
| 113 | + return labelRsrcAdminService.createGlobalPool(LabelResourceId.labelResourceId(beginLabel), | ||
| 114 | + LabelResourceId.labelResourceId(endLabel)); | ||
| 115 | + } | ||
| 116 | + | ||
| 117 | + /** | ||
| 118 | + * Allocates node label from global node label pool to specific device. | ||
| 119 | + * Configure this device with labels and lsrid mapping of all other devices and vice versa. | ||
| 120 | + * | ||
| 121 | + * @param specificDeviceId node label needs to be allocated to specific device | ||
| 122 | + * @param specificLsrId lsrid of specific device | ||
| 123 | + * @param deviceIdLsrIdMap deviceid and lsrid mapping | ||
| 124 | + * @return success or failure | ||
| 125 | + */ | ||
| 126 | + public boolean allocateNodeLabel(DeviceId specificDeviceId, String specificLsrId, | ||
| 127 | + Map<DeviceId, String> deviceIdLsrIdMap) { | ||
| 128 | + long applyNum = 1; // For each node only one node label | ||
| 129 | + LabelResourceId specificLabelId = null; | ||
| 130 | + | ||
| 131 | + checkNotNull(specificDeviceId, DEVICE_ID_NULL); | ||
| 132 | + checkNotNull(specificLsrId, LSR_ID_NULL); | ||
| 133 | + checkNotNull(deviceIdLsrIdMap, DEVICE_ID_LSR_ID_MAP_NULL); | ||
| 134 | + checkNotNull(labelRsrcService, LABEL_RESOURCE_SERVICE_NULL); | ||
| 135 | + checkNotNull(pceStore, PCE_STORE_NULL); | ||
| 136 | + | ||
| 137 | + // The specificDeviceId is the new device and is not there in the deviceIdLsrIdMap. | ||
| 138 | + // So, first generate its label and configure label and its lsr-id to it. | ||
| 139 | + Collection<LabelResource> result = labelRsrcService.applyFromGlobalPool(applyNum); | ||
| 140 | + if (result.size() > 0) { | ||
| 141 | + // Only one element (label-id) to retrieve | ||
| 142 | + Iterator<LabelResource> iterator = result.iterator(); | ||
| 143 | + DefaultLabelResource defaultLabelResource = (DefaultLabelResource) iterator.next(); | ||
| 144 | + specificLabelId = defaultLabelResource.labelResourceId(); | ||
| 145 | + if (specificLabelId == null) { | ||
| 146 | + log.error("Unable to retrieve global node label for a device id {}.", specificDeviceId.toString()); | ||
| 147 | + return false; | ||
| 148 | + } | ||
| 149 | + } else { | ||
| 150 | + log.error("Unable to allocate global node label for a device id {}.", specificDeviceId.toString()); | ||
| 151 | + return false; | ||
| 152 | + } | ||
| 153 | + | ||
| 154 | + pceStore.addGlobalNodeLabel(specificDeviceId, specificLabelId); | ||
| 155 | + //TODO: uncomment below line once advertiseNodeLabelRule() is ready | ||
| 156 | + // Push its label information into specificDeviceId | ||
| 157 | + //advertiseNodeLabelRule(specificDeviceId, specificLabelId, | ||
| 158 | + // IpPrefix.valueOf(IpAddress.valueOf(specificLsrId), PREFIX_LENGTH), | ||
| 159 | + | ||
| 160 | + // Configure (node-label, lsr-id) mapping of each devices in list to specific device and vice versa. | ||
| 161 | + for (Map.Entry element:deviceIdLsrIdMap.entrySet()) { | ||
| 162 | + DeviceId otherDevId = (DeviceId) element.getKey(); | ||
| 163 | + String otherLsrId = (String) element.getValue(); | ||
| 164 | + if (otherLsrId == null) { | ||
| 165 | + log.error("The lsr-id of device id {} is null.", otherDevId.toString()); | ||
| 166 | + releaseNodeLabel(specificDeviceId, specificLsrId, deviceIdLsrIdMap); | ||
| 167 | + return false; | ||
| 168 | + } | ||
| 169 | + | ||
| 170 | + // Label for other device in list should be already allocated. | ||
| 171 | + LabelResourceId otherLabelId = pceStore.getGlobalNodeLabel(otherDevId); | ||
| 172 | + if (otherLabelId == null) { | ||
| 173 | + log.error("Unable to find global node label in store for a device id {}.", otherDevId.toString()); | ||
| 174 | + releaseNodeLabel(specificDeviceId, specificLsrId, deviceIdLsrIdMap); | ||
| 175 | + return false; | ||
| 176 | + } | ||
| 177 | + | ||
| 178 | + // Push to device | ||
| 179 | + // TODO: uncomment below line once advertiseNodeLabelRule() is ready | ||
| 180 | + // Push label information of specificDeviceId to otherDevId in list and vice versa. | ||
| 181 | + //advertiseNodeLabelRule(otherDevId, specificLabelId, IpPrefix.valueOf(IpAddress.valueOf(specificLsrId), | ||
| 182 | + // PREFIX_LENGTH), Objective.Operation.ADD); | ||
| 183 | + //advertiseNodeLabelRule(specificDeviceId, otherLabelId, IpPrefix.valueOf(IpAddress.valueOf(otherLsrId), | ||
| 184 | + // PREFIX_LENGTH), Objective.Operation.ADD); | ||
| 185 | + } | ||
| 186 | + | ||
| 187 | + return true; | ||
| 188 | + } | ||
| 189 | + | ||
| 190 | + /** | ||
| 191 | + * Releases assigned node label of specific device from global node label pool and pce store. | ||
| 192 | + * and remove configured this node label from all other devices. | ||
| 193 | + * | ||
| 194 | + * @param specificDeviceId node label needs to be released for specific device | ||
| 195 | + * @param specificLsrId lsrid of specific device | ||
| 196 | + * @param deviceIdLsrIdMap deviceid and lsrid mapping | ||
| 197 | + * @return success or failure | ||
| 198 | + */ | ||
| 199 | + public boolean releaseNodeLabel(DeviceId specificDeviceId, String specificLsrId, | ||
| 200 | + Map<DeviceId, String> deviceIdLsrIdMap) { | ||
| 201 | + checkNotNull(specificDeviceId, DEVICE_ID_NULL); | ||
| 202 | + checkNotNull(specificLsrId, LSR_ID_NULL); | ||
| 203 | + checkNotNull(deviceIdLsrIdMap, DEVICE_ID_LSR_ID_MAP_NULL); | ||
| 204 | + checkNotNull(labelRsrcService, LABEL_RESOURCE_SERVICE_NULL); | ||
| 205 | + checkNotNull(pceStore, PCE_STORE_NULL); | ||
| 206 | + boolean retValue = true; | ||
| 207 | + | ||
| 208 | + // Release node label entry of this specific device from all other devices | ||
| 209 | + // Retrieve node label of this specific device from store | ||
| 210 | + LabelResourceId labelId = pceStore.getGlobalNodeLabel(specificDeviceId); | ||
| 211 | + if (labelId == null) { | ||
| 212 | + log.error("Unable to retrieve label of a device id {} from store.", specificDeviceId.toString()); | ||
| 213 | + return false; | ||
| 214 | + } | ||
| 215 | + | ||
| 216 | + // Go through all devices in the map and remove label entry | ||
| 217 | + for (Map.Entry element:deviceIdLsrIdMap.entrySet()) { | ||
| 218 | + DeviceId otherDevId = (DeviceId) element.getKey(); | ||
| 219 | + | ||
| 220 | + // Remove this specific device label information from all other nodes except | ||
| 221 | + // this specific node where connection already lost. | ||
| 222 | + if (!specificDeviceId.equals(otherDevId)) { | ||
| 223 | + //TODO: uncomment below lines once advertiseNodeLabelRule() is ready | ||
| 224 | + //advertiseNodeLabelRule(otherDevId, labelId, IpPrefix.valueOf(IpAddress.valueOf(specificLsrId), | ||
| 225 | + // PREFIX_LENGTH), Objective.Operation.REMOVE); | ||
| 226 | + } | ||
| 227 | + } | ||
| 228 | + | ||
| 229 | + // Release from label manager | ||
| 230 | + Set<LabelResourceId> release = new HashSet<>(); | ||
| 231 | + release.add(labelId); | ||
| 232 | + if (!labelRsrcService.releaseToGlobalPool(release)) { | ||
| 233 | + log.error("Unable to release label id {} from label manager.", labelId.toString()); | ||
| 234 | + retValue = false; | ||
| 235 | + } | ||
| 236 | + | ||
| 237 | + // Remove from store | ||
| 238 | + if (!pceStore.removeGlobalNodeLabel(specificDeviceId)) { | ||
| 239 | + log.error("Unable to remove global node label id {} from store.", labelId.toString()); | ||
| 240 | + retValue = false; | ||
| 241 | + } | ||
| 242 | + | ||
| 243 | + return retValue; | ||
| 244 | + } | ||
| 245 | + | ||
| 246 | + /** | ||
| 247 | + * Allocates adjacency label to a link from local resource pool by a specific device id. | ||
| 248 | + * | ||
| 249 | + * @param link between devices | ||
| 250 | + * @return success or failure | ||
| 251 | + */ | ||
| 252 | + public boolean allocateAdjacencyLabel(Link link) { | ||
| 253 | + long applyNum = 1; // Single label to each link. | ||
| 254 | + DeviceId srcDeviceId = link.src().deviceId(); | ||
| 255 | + Collection<LabelResource> labelList; | ||
| 256 | + | ||
| 257 | + checkNotNull(link, LINK_NULL); | ||
| 258 | + checkNotNull(labelRsrcService, LABEL_RESOURCE_SERVICE_NULL); | ||
| 259 | + checkNotNull(pceStore, PCE_STORE_NULL); | ||
| 260 | + | ||
| 261 | + // Allocate adjacency label to a link from label manager. | ||
| 262 | + // Take label from source device pool to allocate. | ||
| 263 | + labelList = labelRsrcService.applyFromDevicePool(srcDeviceId, applyNum); | ||
| 264 | + if (labelList.size() <= 0) { | ||
| 265 | + log.error("Unable to allocate label to a device id {}.", srcDeviceId.toString()); | ||
| 266 | + return false; | ||
| 267 | + } | ||
| 268 | + | ||
| 269 | + // Currently only one label to a device. So, no need to iterate through list | ||
| 270 | + Iterator<LabelResource> iterator = labelList.iterator(); | ||
| 271 | + DefaultLabelResource defaultLabelResource = (DefaultLabelResource) iterator.next(); | ||
| 272 | + LabelResourceId labelId = defaultLabelResource.labelResourceId(); | ||
| 273 | + if (labelId == null) { | ||
| 274 | + log.error("Unable to allocate label to a device id {}.", srcDeviceId.toString()); | ||
| 275 | + return false; | ||
| 276 | + } | ||
| 277 | + log.debug("Allocated adjacency label {} to a link {}.", labelId.toString(), | ||
| 278 | + link.toString()); | ||
| 279 | + | ||
| 280 | + // Push adjacency label to device | ||
| 281 | + //TODO: uncomment below line once installAdjLabelRule() method is ready | ||
| 282 | + //installAdjLabelRule(srcDeviceId, labelId, link.src().port(), link.dst().port(), Objective.Operation.ADD); | ||
| 283 | + | ||
| 284 | + // Save in store | ||
| 285 | + pceStore.addAdjLabel(link, labelId); | ||
| 286 | + return true; | ||
| 287 | + } | ||
| 288 | + | ||
| 289 | + /** | ||
| 290 | + * Releases unused adjacency labels from device pools. | ||
| 291 | + * | ||
| 292 | + * @param link between devices | ||
| 293 | + * @return success or failure | ||
| 294 | + */ | ||
| 295 | + public boolean releaseAdjacencyLabel(Link link) { | ||
| 296 | + checkNotNull(link, LINK_NULL); | ||
| 297 | + checkNotNull(labelRsrcService, LABEL_RESOURCE_SERVICE_NULL); | ||
| 298 | + checkNotNull(pceStore, PCE_STORE_NULL); | ||
| 299 | + boolean retValue = true; | ||
| 300 | + | ||
| 301 | + // Retrieve link label from store | ||
| 302 | + LabelResourceId labelId = pceStore.getAdjLabel(link); | ||
| 303 | + if (labelId == null) { | ||
| 304 | + log.error("Unabel to retrieve label for a link {} from store.", link.toString()); | ||
| 305 | + return false; | ||
| 306 | + } | ||
| 307 | + | ||
| 308 | + // Device | ||
| 309 | + DeviceId srcDeviceId = link.src().deviceId(); | ||
| 310 | + | ||
| 311 | + // Release adjacency label from device | ||
| 312 | + //TODO: uncomment below line once installAdjLabelRule() method is ready | ||
| 313 | + //installAdjLabelRule(srcDeviceId, labelId, link.src().port(), link.dst().port(), Objective.Operation.REMOVE); | ||
| 314 | + | ||
| 315 | + // Release link label from label manager | ||
| 316 | + Multimap<DeviceId, LabelResource> release = ArrayListMultimap.create(); | ||
| 317 | + DefaultLabelResource defaultLabelResource = new DefaultLabelResource(srcDeviceId, labelId); | ||
| 318 | + release.put(srcDeviceId, defaultLabelResource); | ||
| 319 | + if (!labelRsrcService.releaseToDevicePool(release)) { | ||
| 320 | + log.error("Unable to release label id {} from label manager.", labelId.toString()); | ||
| 321 | + retValue = false; | ||
| 322 | + } | ||
| 323 | + | ||
| 324 | + // Remove adjacency label from store | ||
| 325 | + if (!pceStore.removeAdjLabel(link)) { | ||
| 326 | + log.error("Unable to remove adjacency label id {} from store.", labelId.toString()); | ||
| 327 | + retValue = false; | ||
| 328 | + } | ||
| 329 | + return retValue; | ||
| 330 | + } | ||
| 331 | + | ||
| 332 | + /** | ||
| 333 | + * Computes label stack for a path. | ||
| 334 | + * | ||
| 335 | + * @param path lsp path | ||
| 336 | + * @return label stack | ||
| 337 | + */ | ||
| 338 | + public LabelStack computeLabelStack(Path path) { | ||
| 339 | + checkNotNull(path, PATH_NULL); | ||
| 340 | + // Label stack is linked list to make labels in order. | ||
| 341 | + List<LabelResourceId> labelStack = new LinkedList<>(); | ||
| 342 | + List<Link> linkList = path.links(); | ||
| 343 | + if ((linkList != null) && (linkList.size() > 0)) { | ||
| 344 | + // Path: [x] ---- [y] ---- [z] | ||
| 345 | + // For other than last link, add only source[x] device label. | ||
| 346 | + // For the last link, add both source[y] and destination[z] device labels. | ||
| 347 | + // For all links add adjacency label | ||
| 348 | + Link link = null; | ||
| 349 | + LabelResourceId nodeLabelId = null; | ||
| 350 | + LabelResourceId adjLabelId = null; | ||
| 351 | + DeviceId deviceId = null; | ||
| 352 | + for (Iterator<Link> iterator = linkList.iterator(); iterator.hasNext();) { | ||
| 353 | + link = (Link) iterator.next(); | ||
| 354 | + // Add source device label now | ||
| 355 | + deviceId = link.src().deviceId(); | ||
| 356 | + nodeLabelId = pceStore.getGlobalNodeLabel(deviceId); | ||
| 357 | + if (nodeLabelId == null) { | ||
| 358 | + log.error("Unable to find node label for a device id {} in store.", deviceId.toString()); | ||
| 359 | + return null; | ||
| 360 | + } | ||
| 361 | + labelStack.add(nodeLabelId); | ||
| 362 | + | ||
| 363 | + // Add adjacency label for this link | ||
| 364 | + adjLabelId = pceStore.getAdjLabel(link); | ||
| 365 | + if (adjLabelId == null) { | ||
| 366 | + log.error("Adjacency label id is null for a link {}.", link.toString()); | ||
| 367 | + return null; | ||
| 368 | + } | ||
| 369 | + labelStack.add(adjLabelId); | ||
| 370 | + } | ||
| 371 | + | ||
| 372 | + // This is the last link in path | ||
| 373 | + // Add destination device label now. | ||
| 374 | + if (link != null) { | ||
| 375 | + deviceId = link.dst().deviceId(); | ||
| 376 | + nodeLabelId = pceStore.getGlobalNodeLabel(deviceId); | ||
| 377 | + if (nodeLabelId == null) { | ||
| 378 | + log.error("Unable to find node label for a device id {} in store.", deviceId.toString()); | ||
| 379 | + return null; | ||
| 380 | + } | ||
| 381 | + labelStack.add(nodeLabelId); | ||
| 382 | + } | ||
| 383 | + } else { | ||
| 384 | + log.debug("Empty link in path."); | ||
| 385 | + return null; | ||
| 386 | + } | ||
| 387 | + return new DefaultLabelStack(labelStack); | ||
| 388 | + } | ||
| 389 | +} |
| 1 | +/* | ||
| 2 | + * Copyright 2016-present Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | +package org.onosproject.pce.pceservice; | ||
| 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; | ||
| 22 | + | ||
| 23 | +import static org.onosproject.net.Link.Type.DIRECT; | ||
| 24 | + | ||
| 25 | +import java.util.Iterator; | ||
| 26 | +import java.util.List; | ||
| 27 | +import java.util.LinkedList; | ||
| 28 | + | ||
| 29 | +import org.junit.After; | ||
| 30 | +import org.junit.Before; | ||
| 31 | +import org.junit.Test; | ||
| 32 | + | ||
| 33 | +import org.onlab.packet.IpAddress; | ||
| 34 | +import org.onosproject.core.DefaultGroupId; | ||
| 35 | +import org.onosproject.incubator.net.tunnel.Tunnel; | ||
| 36 | +import org.onosproject.incubator.net.tunnel.TunnelEndPoint; | ||
| 37 | +import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint; | ||
| 38 | +import org.onosproject.incubator.net.tunnel.TunnelName; | ||
| 39 | +import org.onosproject.incubator.net.tunnel.TunnelId; | ||
| 40 | +import org.onosproject.incubator.net.tunnel.DefaultTunnel; | ||
| 41 | +import org.onosproject.incubator.net.resource.label.LabelResourceId; | ||
| 42 | +import org.onosproject.incubator.net.resource.label.LabelResourceService; | ||
| 43 | +import org.onosproject.net.ConnectPoint; | ||
| 44 | +import org.onosproject.net.DefaultAnnotations; | ||
| 45 | +import org.onosproject.net.DefaultPath; | ||
| 46 | +import org.onosproject.net.DeviceId; | ||
| 47 | +import org.onosproject.net.PortNumber; | ||
| 48 | +import org.onosproject.net.Path; | ||
| 49 | +import org.onosproject.pce.pcestore.api.LspLocalLabelInfo; | ||
| 50 | +import org.onosproject.pce.pcestore.api.PceStore; | ||
| 51 | +import org.onosproject.pce.pcestore.PceccTunnelInfo; | ||
| 52 | +import org.onosproject.pce.pcestore.DefaultLspLocalLabelInfo; | ||
| 53 | +import org.onosproject.net.provider.ProviderId; | ||
| 54 | +import org.onosproject.pce.util.LabelResourceAdapter; | ||
| 55 | +import org.onosproject.pce.util.PceStoreAdapter; | ||
| 56 | +import org.onosproject.net.DefaultLink; | ||
| 57 | +import org.onosproject.net.Link; | ||
| 58 | + | ||
| 59 | +/** | ||
| 60 | + * Unit tests for BasicPceccHandler class. | ||
| 61 | + */ | ||
| 62 | +public class BasicPceccHandlerTest { | ||
| 63 | + | ||
| 64 | + public static final long LOCAL_LABEL_SPACE_MIN = 5122; | ||
| 65 | + public static final long LOCAL_LABEL_SPACE_MAX = 9217; | ||
| 66 | + | ||
| 67 | + private BasicPceccHandler pceccHandler; | ||
| 68 | + protected LabelResourceService labelRsrcService; | ||
| 69 | + protected PceStore pceStore; | ||
| 70 | + private TunnelEndPoint src = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(23423)); | ||
| 71 | + private TunnelEndPoint dst = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(32421)); | ||
| 72 | + private DefaultGroupId groupId = new DefaultGroupId(92034); | ||
| 73 | + private TunnelName tunnelName = TunnelName.tunnelName("TunnelName"); | ||
| 74 | + private TunnelId tunnelId = TunnelId.valueOf("41654654"); | ||
| 75 | + private ProviderId producerName = new ProviderId("producer1", "13"); | ||
| 76 | + private Path path; | ||
| 77 | + private Tunnel tunnel; | ||
| 78 | + private PceccTunnelInfo pceccTunnelInfo; | ||
| 79 | + private DeviceId deviceId1; | ||
| 80 | + private DeviceId deviceId2; | ||
| 81 | + private DeviceId deviceId3; | ||
| 82 | + private DeviceId deviceId4; | ||
| 83 | + private DeviceId deviceId5; | ||
| 84 | + private PortNumber port1; | ||
| 85 | + private PortNumber port2; | ||
| 86 | + private PortNumber port3; | ||
| 87 | + private PortNumber port4; | ||
| 88 | + private PortNumber port5; | ||
| 89 | + | ||
| 90 | + @Before | ||
| 91 | + public void setUp() throws Exception { | ||
| 92 | + pceccHandler = BasicPceccHandler.getInstance(); | ||
| 93 | + labelRsrcService = new LabelResourceAdapter(); | ||
| 94 | + pceStore = new PceStoreAdapter(); | ||
| 95 | + pceccHandler.initialize(labelRsrcService, pceStore); | ||
| 96 | + | ||
| 97 | + // Cretae tunnel test | ||
| 98 | + // Link | ||
| 99 | + ProviderId providerId = new ProviderId("of", "foo"); | ||
| 100 | + deviceId1 = DeviceId.deviceId("of:A"); | ||
| 101 | + deviceId2 = DeviceId.deviceId("of:B"); | ||
| 102 | + deviceId3 = DeviceId.deviceId("of:C"); | ||
| 103 | + deviceId4 = DeviceId.deviceId("of:D"); | ||
| 104 | + deviceId5 = DeviceId.deviceId("of:E"); | ||
| 105 | + port1 = PortNumber.portNumber(1); | ||
| 106 | + port2 = PortNumber.portNumber(2); | ||
| 107 | + port3 = PortNumber.portNumber(3); | ||
| 108 | + port4 = PortNumber.portNumber(4); | ||
| 109 | + port5 = PortNumber.portNumber(5); | ||
| 110 | + List<Link> linkList = new LinkedList<>(); | ||
| 111 | + | ||
| 112 | + Link l1 = DefaultLink.builder() | ||
| 113 | + .providerId(providerId) | ||
| 114 | + .annotations(DefaultAnnotations.builder().set("key1", "yahoo").build()) | ||
| 115 | + .src(new ConnectPoint(deviceId1, port1)) | ||
| 116 | + .dst(new ConnectPoint(deviceId2, port2)) | ||
| 117 | + .type(DIRECT) | ||
| 118 | + .state(Link.State.ACTIVE) | ||
| 119 | + .build(); | ||
| 120 | + linkList.add(l1); | ||
| 121 | + Link l2 = DefaultLink.builder() | ||
| 122 | + .providerId(providerId) | ||
| 123 | + .annotations(DefaultAnnotations.builder().set("key2", "yahoo").build()) | ||
| 124 | + .src(new ConnectPoint(deviceId2, port2)) | ||
| 125 | + .dst(new ConnectPoint(deviceId3, port3)) | ||
| 126 | + .type(DIRECT) | ||
| 127 | + .state(Link.State.ACTIVE) | ||
| 128 | + .build(); | ||
| 129 | + linkList.add(l2); | ||
| 130 | + Link l3 = DefaultLink.builder() | ||
| 131 | + .providerId(providerId) | ||
| 132 | + .annotations(DefaultAnnotations.builder().set("key3", "yahoo").build()) | ||
| 133 | + .src(new ConnectPoint(deviceId3, port3)) | ||
| 134 | + .dst(new ConnectPoint(deviceId4, port4)) | ||
| 135 | + .type(DIRECT) | ||
| 136 | + .state(Link.State.ACTIVE) | ||
| 137 | + .build(); | ||
| 138 | + linkList.add(l3); | ||
| 139 | + Link l4 = DefaultLink.builder() | ||
| 140 | + .providerId(providerId) | ||
| 141 | + .annotations(DefaultAnnotations.builder().set("key4", "yahoo").build()) | ||
| 142 | + .src(new ConnectPoint(deviceId4, port4)) | ||
| 143 | + .dst(new ConnectPoint(deviceId5, port5)) | ||
| 144 | + .type(DIRECT) | ||
| 145 | + .state(Link.State.ACTIVE) | ||
| 146 | + .build(); | ||
| 147 | + linkList.add(l4); | ||
| 148 | + | ||
| 149 | + // Path | ||
| 150 | + path = new DefaultPath(providerId, linkList, 10); | ||
| 151 | + | ||
| 152 | + // Tunnel | ||
| 153 | + tunnel = new DefaultTunnel(producerName, src, dst, Tunnel.Type.VXLAN, | ||
| 154 | + Tunnel.State.ACTIVE, groupId, tunnelId, | ||
| 155 | + tunnelName, path); | ||
| 156 | + } | ||
| 157 | + | ||
| 158 | + @After | ||
| 159 | + public void tearDown() throws Exception { | ||
| 160 | + } | ||
| 161 | + | ||
| 162 | + /** | ||
| 163 | + * Checks the operation of getInstance() method. | ||
| 164 | + */ | ||
| 165 | + @Test | ||
| 166 | + public void testGetInstance() { | ||
| 167 | + assertThat(pceccHandler, is(notNullValue())); | ||
| 168 | + } | ||
| 169 | + | ||
| 170 | + /** | ||
| 171 | + * Checks the operation of allocateLabel() method. | ||
| 172 | + */ | ||
| 173 | + @Test | ||
| 174 | + public void testAllocateLabel() { | ||
| 175 | + List<LspLocalLabelInfo> lspLocalLabelInfoList; | ||
| 176 | + Iterator<LspLocalLabelInfo> iterator; | ||
| 177 | + LspLocalLabelInfo lspLocalLabelInfo; | ||
| 178 | + DeviceId deviceId; | ||
| 179 | + LabelResourceId inLabelId; | ||
| 180 | + LabelResourceId outLabelId; | ||
| 181 | + PortNumber inPort; | ||
| 182 | + PortNumber outPort; | ||
| 183 | + | ||
| 184 | + // check allocation result | ||
| 185 | + assertThat(pceccHandler.allocateLabel(tunnel), is(true)); | ||
| 186 | + | ||
| 187 | + // Check list of devices with IN and OUT labels whether stored properly in store | ||
| 188 | + pceccTunnelInfo = pceStore.getTunnelInfo(tunnel.tunnelId()); | ||
| 189 | + lspLocalLabelInfoList = pceccTunnelInfo.lspLocalLabelInfoList(); | ||
| 190 | + iterator = lspLocalLabelInfoList.iterator(); | ||
| 191 | + | ||
| 192 | + // Retrieve values and check device5 | ||
| 193 | + lspLocalLabelInfo = (DefaultLspLocalLabelInfo) iterator.next(); | ||
| 194 | + deviceId = lspLocalLabelInfo.deviceId(); | ||
| 195 | + inLabelId = lspLocalLabelInfo.inLabelId(); | ||
| 196 | + outLabelId = lspLocalLabelInfo.outLabelId(); | ||
| 197 | + inPort = lspLocalLabelInfo.inPort(); | ||
| 198 | + outPort = lspLocalLabelInfo.outPort(); | ||
| 199 | + | ||
| 200 | + assertThat(deviceId, is(deviceId5)); | ||
| 201 | + assertThat(inLabelId, is(notNullValue())); | ||
| 202 | + assertThat(outLabelId, is(nullValue())); | ||
| 203 | + assertThat(inPort, is(port5)); | ||
| 204 | + assertThat(outPort, is(nullValue())); | ||
| 205 | + | ||
| 206 | + // Next element check | ||
| 207 | + // Retrieve values and check device4 | ||
| 208 | + lspLocalLabelInfo = (DefaultLspLocalLabelInfo) iterator.next(); | ||
| 209 | + deviceId = lspLocalLabelInfo.deviceId(); | ||
| 210 | + inLabelId = lspLocalLabelInfo.inLabelId(); | ||
| 211 | + outLabelId = lspLocalLabelInfo.outLabelId(); | ||
| 212 | + inPort = lspLocalLabelInfo.inPort(); | ||
| 213 | + outPort = lspLocalLabelInfo.outPort(); | ||
| 214 | + | ||
| 215 | + assertThat(deviceId, is(deviceId4)); | ||
| 216 | + assertThat(inLabelId, is(notNullValue())); | ||
| 217 | + assertThat(outLabelId, is(notNullValue())); | ||
| 218 | + assertThat(inPort, is(port4)); | ||
| 219 | + assertThat(outPort, is(port5)); | ||
| 220 | + | ||
| 221 | + // Next element check | ||
| 222 | + // Retrieve values and check device3 | ||
| 223 | + lspLocalLabelInfo = (DefaultLspLocalLabelInfo) iterator.next(); | ||
| 224 | + deviceId = lspLocalLabelInfo.deviceId(); | ||
| 225 | + inLabelId = lspLocalLabelInfo.inLabelId(); | ||
| 226 | + outLabelId = lspLocalLabelInfo.outLabelId(); | ||
| 227 | + inPort = lspLocalLabelInfo.inPort(); | ||
| 228 | + outPort = lspLocalLabelInfo.outPort(); | ||
| 229 | + | ||
| 230 | + assertThat(deviceId, is(deviceId3)); | ||
| 231 | + assertThat(inLabelId, is(notNullValue())); | ||
| 232 | + assertThat(outLabelId, is(notNullValue())); | ||
| 233 | + assertThat(inPort, is(port3)); | ||
| 234 | + assertThat(outPort, is(port4)); | ||
| 235 | + | ||
| 236 | + // Next element check | ||
| 237 | + // Retrieve values and check device2 | ||
| 238 | + lspLocalLabelInfo = (DefaultLspLocalLabelInfo) iterator.next(); | ||
| 239 | + deviceId = lspLocalLabelInfo.deviceId(); | ||
| 240 | + inLabelId = lspLocalLabelInfo.inLabelId(); | ||
| 241 | + outLabelId = lspLocalLabelInfo.outLabelId(); | ||
| 242 | + inPort = lspLocalLabelInfo.inPort(); | ||
| 243 | + outPort = lspLocalLabelInfo.outPort(); | ||
| 244 | + | ||
| 245 | + assertThat(deviceId, is(deviceId2)); | ||
| 246 | + assertThat(inLabelId, is(notNullValue())); | ||
| 247 | + assertThat(outLabelId, is(notNullValue())); | ||
| 248 | + assertThat(inPort, is(port2)); | ||
| 249 | + assertThat(outPort, is(port3)); | ||
| 250 | + | ||
| 251 | + // Next element check | ||
| 252 | + // Retrieve values and check device1 | ||
| 253 | + lspLocalLabelInfo = (DefaultLspLocalLabelInfo) iterator.next(); | ||
| 254 | + deviceId = lspLocalLabelInfo.deviceId(); | ||
| 255 | + inLabelId = lspLocalLabelInfo.inLabelId(); | ||
| 256 | + outLabelId = lspLocalLabelInfo.outLabelId(); | ||
| 257 | + inPort = lspLocalLabelInfo.inPort(); | ||
| 258 | + outPort = lspLocalLabelInfo.outPort(); | ||
| 259 | + | ||
| 260 | + assertThat(deviceId, is(deviceId1)); | ||
| 261 | + assertThat(inLabelId, is(nullValue())); | ||
| 262 | + assertThat(outLabelId, is(notNullValue())); | ||
| 263 | + assertThat(inPort, is(nullValue())); | ||
| 264 | + assertThat(outPort, is(port2)); | ||
| 265 | + } | ||
| 266 | + | ||
| 267 | + /** | ||
| 268 | + * Checks the operation of releaseLabel() method. | ||
| 269 | + */ | ||
| 270 | + @Test | ||
| 271 | + public void testReleaseLabel() { | ||
| 272 | + // Release tunnels | ||
| 273 | + assertThat(pceccHandler.allocateLabel(tunnel), is(true)); | ||
| 274 | + pceccHandler.releaseLabel(tunnel); | ||
| 275 | + | ||
| 276 | + // Retrieve from store. Store should not contain this tunnel info. | ||
| 277 | + pceccTunnelInfo = pceStore.getTunnelInfo(tunnel.tunnelId()); | ||
| 278 | + assertThat(pceccTunnelInfo, is(nullValue())); | ||
| 279 | + } | ||
| 280 | +} |
| 1 | +/* | ||
| 2 | + * Copyright 2016-present Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | +package org.onosproject.pce.pceservice; | ||
| 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; | ||
| 22 | + | ||
| 23 | +import static org.onosproject.net.Link.Type.DIRECT; | ||
| 24 | + | ||
| 25 | +import java.util.HashMap; | ||
| 26 | +import java.util.Iterator; | ||
| 27 | +import java.util.Map; | ||
| 28 | +import java.util.List; | ||
| 29 | +import java.util.LinkedList; | ||
| 30 | + | ||
| 31 | +import org.junit.After; | ||
| 32 | +import org.junit.Before; | ||
| 33 | +import org.junit.Test; | ||
| 34 | + | ||
| 35 | +import org.onosproject.incubator.net.resource.label.LabelResourceId; | ||
| 36 | +import org.onosproject.incubator.net.resource.label.LabelResourceAdminService; | ||
| 37 | +import org.onosproject.incubator.net.resource.label.LabelResourceService; | ||
| 38 | +import org.onosproject.incubator.net.tunnel.LabelStack; | ||
| 39 | +import org.onosproject.net.ConnectPoint; | ||
| 40 | +import org.onosproject.net.DefaultAnnotations; | ||
| 41 | +import org.onosproject.net.DefaultPath; | ||
| 42 | +import org.onosproject.net.DeviceId; | ||
| 43 | +import org.onosproject.net.PortNumber; | ||
| 44 | +import org.onosproject.net.Path; | ||
| 45 | +import org.onosproject.pce.pcestore.api.PceStore; | ||
| 46 | +import org.onosproject.net.provider.ProviderId; | ||
| 47 | +import org.onosproject.pce.util.LabelResourceAdapter; | ||
| 48 | +import org.onosproject.pce.util.PceStoreAdapter; | ||
| 49 | +import org.onosproject.net.DefaultLink; | ||
| 50 | +import org.onosproject.net.Link; | ||
| 51 | + | ||
| 52 | +/** | ||
| 53 | + * Unit tests for PceccSrTeBeHandler class. | ||
| 54 | + */ | ||
| 55 | +public class PceccSrTeBeHandlerTest { | ||
| 56 | + | ||
| 57 | + public static final long GLOBAL_LABEL_SPACE_MIN = 4097; | ||
| 58 | + public static final long GLOBAL_LABEL_SPACE_MAX = 5121; | ||
| 59 | + | ||
| 60 | + private PceccSrTeBeHandler srTeHandler; | ||
| 61 | + protected LabelResourceAdminService labelRsrcAdminService; | ||
| 62 | + protected LabelResourceService labelRsrcService; | ||
| 63 | + protected PceStore pceStore; | ||
| 64 | + private ProviderId providerId; | ||
| 65 | + private DeviceId deviceId1; | ||
| 66 | + private DeviceId deviceId2; | ||
| 67 | + private DeviceId deviceId3; | ||
| 68 | + private DeviceId deviceId4; | ||
| 69 | + private DeviceId deviceId5; | ||
| 70 | + private PortNumber port1; | ||
| 71 | + private PortNumber port2; | ||
| 72 | + private PortNumber port3; | ||
| 73 | + private PortNumber port4; | ||
| 74 | + private PortNumber port5; | ||
| 75 | + private Link link1; | ||
| 76 | + private Link link2; | ||
| 77 | + private Link link3; | ||
| 78 | + private Link link4; | ||
| 79 | + private Path path1; | ||
| 80 | + LabelResourceId labelId; | ||
| 81 | + private LabelResourceId labelId1 = LabelResourceId.labelResourceId(4098); | ||
| 82 | + private LabelResourceId labelId2 = LabelResourceId.labelResourceId(4099); | ||
| 83 | + private Map<DeviceId, String> deviceIdLsrIdMap; | ||
| 84 | + | ||
| 85 | + @Before | ||
| 86 | + public void setUp() throws Exception { | ||
| 87 | + // Initialization of member variables | ||
| 88 | + srTeHandler = PceccSrTeBeHandler.getInstance(); | ||
| 89 | + labelRsrcService = new LabelResourceAdapter(); | ||
| 90 | + labelRsrcAdminService = new LabelResourceAdapter(); | ||
| 91 | + pceStore = new PceStoreAdapter(); | ||
| 92 | + srTeHandler.initialize(labelRsrcAdminService, labelRsrcService, pceStore); | ||
| 93 | + | ||
| 94 | + // Creates path | ||
| 95 | + // Creates list of links | ||
| 96 | + providerId = new ProviderId("of", "foo"); | ||
| 97 | + deviceId1 = DeviceId.deviceId("of:A"); | ||
| 98 | + deviceId2 = DeviceId.deviceId("of:B"); | ||
| 99 | + deviceId3 = DeviceId.deviceId("of:C"); | ||
| 100 | + deviceId4 = DeviceId.deviceId("of:D"); | ||
| 101 | + deviceId5 = DeviceId.deviceId("of:E"); | ||
| 102 | + port1 = PortNumber.portNumber(1); | ||
| 103 | + port2 = PortNumber.portNumber(2); | ||
| 104 | + port3 = PortNumber.portNumber(3); | ||
| 105 | + port4 = PortNumber.portNumber(4); | ||
| 106 | + port5 = PortNumber.portNumber(5); | ||
| 107 | + List<Link> linkList = new LinkedList<>(); | ||
| 108 | + | ||
| 109 | + link1 = DefaultLink.builder() | ||
| 110 | + .providerId(providerId) | ||
| 111 | + .annotations(DefaultAnnotations.builder().set("key1", "yahoo").build()) | ||
| 112 | + .src(new ConnectPoint(deviceId1, port1)) | ||
| 113 | + .dst(new ConnectPoint(deviceId2, port2)) | ||
| 114 | + .type(DIRECT) | ||
| 115 | + .state(Link.State.ACTIVE) | ||
| 116 | + .build(); | ||
| 117 | + linkList.add(link1); | ||
| 118 | + link2 = DefaultLink.builder() | ||
| 119 | + .providerId(providerId) | ||
| 120 | + .annotations(DefaultAnnotations.builder().set("key2", "yahoo").build()) | ||
| 121 | + .src(new ConnectPoint(deviceId2, port2)) | ||
| 122 | + .dst(new ConnectPoint(deviceId3, port3)) | ||
| 123 | + .type(DIRECT) | ||
| 124 | + .state(Link.State.ACTIVE) | ||
| 125 | + .build(); | ||
| 126 | + linkList.add(link2); | ||
| 127 | + link3 = DefaultLink.builder() | ||
| 128 | + .providerId(providerId) | ||
| 129 | + .annotations(DefaultAnnotations.builder().set("key3", "yahoo").build()) | ||
| 130 | + .src(new ConnectPoint(deviceId3, port3)) | ||
| 131 | + .dst(new ConnectPoint(deviceId4, port4)) | ||
| 132 | + .type(DIRECT) | ||
| 133 | + .state(Link.State.ACTIVE) | ||
| 134 | + .build(); | ||
| 135 | + linkList.add(link3); | ||
| 136 | + link4 = DefaultLink.builder() | ||
| 137 | + .providerId(providerId) | ||
| 138 | + .annotations(DefaultAnnotations.builder().set("key4", "yahoo").build()) | ||
| 139 | + .src(new ConnectPoint(deviceId4, port4)) | ||
| 140 | + .dst(new ConnectPoint(deviceId5, port5)) | ||
| 141 | + .type(DIRECT) | ||
| 142 | + .state(Link.State.ACTIVE) | ||
| 143 | + .build(); | ||
| 144 | + linkList.add(link4); | ||
| 145 | + | ||
| 146 | + // Path | ||
| 147 | + path1 = new DefaultPath(providerId, linkList, 10); | ||
| 148 | + } | ||
| 149 | + | ||
| 150 | + @After | ||
| 151 | + public void tearDown() throws Exception { | ||
| 152 | + } | ||
| 153 | + | ||
| 154 | + /** | ||
| 155 | + * Checks the operation of getInstance() method. | ||
| 156 | + */ | ||
| 157 | + @Test | ||
| 158 | + public void testGetInstance() { | ||
| 159 | + assertThat(srTeHandler, is(notNullValue())); | ||
| 160 | + } | ||
| 161 | + | ||
| 162 | + /** | ||
| 163 | + * Checks the operation of reserveGlobalPool() method. | ||
| 164 | + */ | ||
| 165 | + @Test | ||
| 166 | + public void testReserveGlobalPool() { | ||
| 167 | + assertThat(srTeHandler.reserveGlobalPool(GLOBAL_LABEL_SPACE_MIN, | ||
| 168 | + GLOBAL_LABEL_SPACE_MAX), is(true)); | ||
| 169 | + } | ||
| 170 | + | ||
| 171 | + /** | ||
| 172 | + * Checks the operation of allocateNodeLabel() method on node label. | ||
| 173 | + * Considered some nodes are already available before PceManager came up. | ||
| 174 | + */ | ||
| 175 | + @Test | ||
| 176 | + public void testAllocateNodeLabel1() { | ||
| 177 | + // Specific device deviceId1 | ||
| 178 | + | ||
| 179 | + // Devices mapping with lsr-id | ||
| 180 | + deviceIdLsrIdMap = new HashMap<>(); | ||
| 181 | + | ||
| 182 | + //device 1 | ||
| 183 | + String lsrId1 = "11.1.1.1"; | ||
| 184 | + deviceIdLsrIdMap.put(deviceId1, lsrId1); | ||
| 185 | + | ||
| 186 | + // device 2 | ||
| 187 | + String lsrId2 = "12.1.1.1"; | ||
| 188 | + deviceIdLsrIdMap.put(deviceId2, lsrId2); | ||
| 189 | + | ||
| 190 | + // device 3 | ||
| 191 | + String lsrId3 = "13.1.1.1"; | ||
| 192 | + deviceIdLsrIdMap.put(deviceId3, lsrId3); | ||
| 193 | + | ||
| 194 | + // device 4 | ||
| 195 | + String lsrId4 = "14.1.1.1"; | ||
| 196 | + deviceIdLsrIdMap.put(deviceId4, lsrId4); | ||
| 197 | + | ||
| 198 | + // device 5 | ||
| 199 | + String lsrId5 = "15.1.1.1"; | ||
| 200 | + deviceIdLsrIdMap.put(deviceId5, lsrId5); | ||
| 201 | + | ||
| 202 | + // Considered devices are stored in deviceIdLsrIdMap. | ||
| 203 | + // Creating temporary tempDeviceIdLsrIdMap to pass to allocateNodeLabel() | ||
| 204 | + Map<DeviceId, String> tempDeviceIdLsrIdMap = new HashMap<>(); | ||
| 205 | + for (Map.Entry element : deviceIdLsrIdMap.entrySet()) { | ||
| 206 | + DeviceId devId = (DeviceId) element.getKey(); | ||
| 207 | + String lsrId = (String) element.getValue(); | ||
| 208 | + | ||
| 209 | + // Allocate node label for specific device devId | ||
| 210 | + assertThat(srTeHandler.allocateNodeLabel(devId, lsrId, tempDeviceIdLsrIdMap), is(true)); | ||
| 211 | + | ||
| 212 | + // Retrieve label from store | ||
| 213 | + LabelResourceId labelId = pceStore.getGlobalNodeLabel(devId); | ||
| 214 | + | ||
| 215 | + // Check whether label is generated for this device devId | ||
| 216 | + assertThat(labelId, is(notNullValue())); | ||
| 217 | + | ||
| 218 | + //Now add device to tempDeviceIdLsrIdMap | ||
| 219 | + tempDeviceIdLsrIdMap.put(devId, lsrId); | ||
| 220 | + } | ||
| 221 | + } | ||
| 222 | + | ||
| 223 | + /** | ||
| 224 | + * Checks the operation of allocateNodeLabel() method on node label. | ||
| 225 | + * Considered initially map is empty and keep on getting new devices from event. | ||
| 226 | + */ | ||
| 227 | + @Test | ||
| 228 | + public void testAllocateNodeLabel2() { | ||
| 229 | + // Specific device deviceId1 | ||
| 230 | + | ||
| 231 | + // Device-id mapping with lsr-id | ||
| 232 | + deviceIdLsrIdMap = new HashMap<>(); | ||
| 233 | + | ||
| 234 | + //device 1 | ||
| 235 | + String lsrId1 = "11.1.1.1"; | ||
| 236 | + // Allocate node label for specific device deviceId1 | ||
| 237 | + assertThat(srTeHandler.allocateNodeLabel(deviceId1, lsrId1, deviceIdLsrIdMap), is(true)); | ||
| 238 | + // Retrieve label from store | ||
| 239 | + LabelResourceId labelId = pceStore.getGlobalNodeLabel(deviceId1); | ||
| 240 | + // Check whether label is generated for this device deviceId1 | ||
| 241 | + assertThat(labelId, is(notNullValue())); | ||
| 242 | + //Now add device to deviceIdLsrIdMap | ||
| 243 | + deviceIdLsrIdMap.put(deviceId1, lsrId1); | ||
| 244 | + | ||
| 245 | + // device 2 | ||
| 246 | + String lsrId2 = "12.1.1.1"; | ||
| 247 | + // Allocate node label for specific device deviceId2 | ||
| 248 | + assertThat(srTeHandler.allocateNodeLabel(deviceId2, lsrId2, deviceIdLsrIdMap), is(true)); | ||
| 249 | + // Retrieve label from store | ||
| 250 | + labelId = pceStore.getGlobalNodeLabel(deviceId2); | ||
| 251 | + // Check whether label is generated for this device deviceId2 | ||
| 252 | + assertThat(labelId, is(notNullValue())); | ||
| 253 | + //Now add device to deviceIdLsrIdMap | ||
| 254 | + deviceIdLsrIdMap.put(deviceId2, lsrId2); | ||
| 255 | + | ||
| 256 | + // device 3 | ||
| 257 | + String lsrId3 = "13.1.1.1"; | ||
| 258 | + // Allocate node label for specific device deviceId3 | ||
| 259 | + assertThat(srTeHandler.allocateNodeLabel(deviceId3, lsrId3, deviceIdLsrIdMap), is(true)); | ||
| 260 | + // Retrieve label from store | ||
| 261 | + labelId = pceStore.getGlobalNodeLabel(deviceId3); | ||
| 262 | + // Check whether label is generated for this device deviceId3 | ||
| 263 | + assertThat(labelId, is(notNullValue())); | ||
| 264 | + //Now add device to deviceIdLsrIdMap | ||
| 265 | + deviceIdLsrIdMap.put(deviceId3, lsrId3); | ||
| 266 | + | ||
| 267 | + // device 4 | ||
| 268 | + String lsrId4 = "14.1.1.1"; | ||
| 269 | + // Allocate node label for specific device deviceId4 | ||
| 270 | + assertThat(srTeHandler.allocateNodeLabel(deviceId4, lsrId4, deviceIdLsrIdMap), is(true)); | ||
| 271 | + // Retrieve label from store | ||
| 272 | + labelId = pceStore.getGlobalNodeLabel(deviceId4); | ||
| 273 | + // Check whether label is generated for this device deviceId4 | ||
| 274 | + assertThat(labelId, is(notNullValue())); | ||
| 275 | + //Now add device to deviceIdLsrIdMap | ||
| 276 | + deviceIdLsrIdMap.put(deviceId4, lsrId4); | ||
| 277 | + | ||
| 278 | + // device 5 | ||
| 279 | + String lsrId5 = "15.1.1.1"; | ||
| 280 | + // Allocate node label for specific device deviceId5 | ||
| 281 | + assertThat(srTeHandler.allocateNodeLabel(deviceId5, lsrId5, deviceIdLsrIdMap), is(true)); | ||
| 282 | + // Retrieve label from store | ||
| 283 | + labelId = pceStore.getGlobalNodeLabel(deviceId5); | ||
| 284 | + // Check whether label is generated for this device deviceId5 | ||
| 285 | + assertThat(labelId, is(notNullValue())); | ||
| 286 | + //Now add device to deviceIdLsrIdMap | ||
| 287 | + deviceIdLsrIdMap.put(deviceId5, lsrId5); | ||
| 288 | + } | ||
| 289 | + | ||
| 290 | + /** | ||
| 291 | + * Checks the operation of releaseNodeLabel() method on node label. | ||
| 292 | + */ | ||
| 293 | + @Test | ||
| 294 | + public void testReleaseNodeLabelSuccess() { | ||
| 295 | + testAllocateNodeLabel2(); | ||
| 296 | + // Specific device deviceId1 | ||
| 297 | + | ||
| 298 | + //device 1 | ||
| 299 | + String lsrId1 = "11.1.1.1"; | ||
| 300 | + // Check whether successfully released node label | ||
| 301 | + assertThat(srTeHandler.releaseNodeLabel(deviceId1, lsrId1, deviceIdLsrIdMap), is(true)); | ||
| 302 | + // Check whether successfully removed label from store | ||
| 303 | + LabelResourceId labelId = pceStore.getGlobalNodeLabel(deviceId1); | ||
| 304 | + assertThat(labelId, is(nullValue())); | ||
| 305 | + // Remove released deviceId1 | ||
| 306 | + deviceIdLsrIdMap.remove(deviceId1); | ||
| 307 | + | ||
| 308 | + //device 2 | ||
| 309 | + String lsrId2 = "12.1.1.1"; | ||
| 310 | + // Check whether successfully released node label | ||
| 311 | + assertThat(srTeHandler.releaseNodeLabel(deviceId2, lsrId2, deviceIdLsrIdMap), is(true)); | ||
| 312 | + // Check whether successfully removed label from store | ||
| 313 | + labelId = pceStore.getGlobalNodeLabel(deviceId2); | ||
| 314 | + assertThat(labelId, is(nullValue())); | ||
| 315 | + // Remove released deviceId2 | ||
| 316 | + deviceIdLsrIdMap.remove(deviceId2); | ||
| 317 | + | ||
| 318 | + //device 3 | ||
| 319 | + String lsrId3 = "13.1.1.1"; | ||
| 320 | + // Check whether successfully released node label | ||
| 321 | + assertThat(srTeHandler.releaseNodeLabel(deviceId3, lsrId3, deviceIdLsrIdMap), is(true)); | ||
| 322 | + // Check whether successfully removed label from store | ||
| 323 | + labelId = pceStore.getGlobalNodeLabel(deviceId3); | ||
| 324 | + assertThat(labelId, is(nullValue())); | ||
| 325 | + // Remove released deviceId3 | ||
| 326 | + deviceIdLsrIdMap.remove(deviceId3); | ||
| 327 | + | ||
| 328 | + //device 4 | ||
| 329 | + String lsrId4 = "14.1.1.1"; | ||
| 330 | + // Check whether successfully released node label | ||
| 331 | + assertThat(srTeHandler.releaseNodeLabel(deviceId4, lsrId4, deviceIdLsrIdMap), is(true)); | ||
| 332 | + // Check whether successfully removed label from store | ||
| 333 | + labelId = pceStore.getGlobalNodeLabel(deviceId4); | ||
| 334 | + assertThat(labelId, is(nullValue())); | ||
| 335 | + // Remove released deviceId4 | ||
| 336 | + deviceIdLsrIdMap.remove(deviceId4); | ||
| 337 | + | ||
| 338 | + //device 5 | ||
| 339 | + String lsrId5 = "15.1.1.1"; | ||
| 340 | + // Check whether successfully released node label | ||
| 341 | + assertThat(srTeHandler.releaseNodeLabel(deviceId5, lsrId5, deviceIdLsrIdMap), is(true)); | ||
| 342 | + // Check whether successfully removed label from store | ||
| 343 | + labelId = pceStore.getGlobalNodeLabel(deviceId5); | ||
| 344 | + assertThat(labelId, is(nullValue())); | ||
| 345 | + // Remove released deviceId5 | ||
| 346 | + deviceIdLsrIdMap.remove(deviceId5); | ||
| 347 | + } | ||
| 348 | + | ||
| 349 | + @Test | ||
| 350 | + public void testReleaseNodeLabelFailure() { | ||
| 351 | + testAllocateNodeLabel2(); | ||
| 352 | + | ||
| 353 | + //device 6 | ||
| 354 | + String lsrId6 = "16.1.1.1"; | ||
| 355 | + // Check whether successfully released node label | ||
| 356 | + DeviceId deviceId6 = DeviceId.deviceId("foo6"); | ||
| 357 | + assertThat(srTeHandler.releaseNodeLabel(deviceId6, lsrId6, deviceIdLsrIdMap), is(false)); | ||
| 358 | + } | ||
| 359 | + | ||
| 360 | + /** | ||
| 361 | + * Checks the operation of allocateAdjacencyLabel() method on adjacency label. | ||
| 362 | + */ | ||
| 363 | + @Test | ||
| 364 | + public void testAllocateAdjacencyLabel() { | ||
| 365 | + // test link1 | ||
| 366 | + // Check whether adjacency label is allocated successfully. | ||
| 367 | + assertThat(srTeHandler.allocateAdjacencyLabel(link1), is(true)); | ||
| 368 | + // Retrieve from store and check whether adjacency label is generated successfully for this device. | ||
| 369 | + LabelResourceId labelId = pceStore.getAdjLabel(link1); | ||
| 370 | + assertThat(labelId, is(notNullValue())); | ||
| 371 | + | ||
| 372 | + // test link2 | ||
| 373 | + // Check whether adjacency label is allocated successfully. | ||
| 374 | + assertThat(srTeHandler.allocateAdjacencyLabel(link2), is(true)); | ||
| 375 | + // Retrieve from store and check whether adjacency label is generated successfully for this device. | ||
| 376 | + labelId = pceStore.getAdjLabel(link2); | ||
| 377 | + assertThat(labelId, is(notNullValue())); | ||
| 378 | + | ||
| 379 | + // test link3 | ||
| 380 | + // Check whether adjacency label is allocated successfully. | ||
| 381 | + assertThat(srTeHandler.allocateAdjacencyLabel(link3), is(true)); | ||
| 382 | + // Retrieve from store and check whether adjacency label is generated successfully for this device. | ||
| 383 | + labelId = pceStore.getAdjLabel(link3); | ||
| 384 | + assertThat(labelId, is(notNullValue())); | ||
| 385 | + | ||
| 386 | + // test link4 | ||
| 387 | + // Check whether adjacency label is allocated successfully. | ||
| 388 | + assertThat(srTeHandler.allocateAdjacencyLabel(link4), is(true)); | ||
| 389 | + // Retrieve from store and check whether adjacency label is generated successfully for this device. | ||
| 390 | + labelId = pceStore.getAdjLabel(link4); | ||
| 391 | + assertThat(labelId, is(notNullValue())); | ||
| 392 | + } | ||
| 393 | + | ||
| 394 | + /** | ||
| 395 | + * Checks the operation of releaseAdjacencyLabel() method on adjacency label. | ||
| 396 | + */ | ||
| 397 | + @Test | ||
| 398 | + public void testReleaseAdjacencyLabel() { | ||
| 399 | + // Test link1 | ||
| 400 | + // Check whether adjacency label is released successfully. | ||
| 401 | + assertThat(srTeHandler.allocateAdjacencyLabel(link1), is(true)); | ||
| 402 | + assertThat(srTeHandler.releaseAdjacencyLabel(link1), is(true)); | ||
| 403 | + // Retrieve from store and check whether adjacency label is removed successfully for this device. | ||
| 404 | + LabelResourceId labelId = pceStore.getAdjLabel(link1); | ||
| 405 | + assertThat(labelId, is(nullValue())); | ||
| 406 | + | ||
| 407 | + // Test link2 | ||
| 408 | + // Check whether adjacency label is released successfully. | ||
| 409 | + assertThat(srTeHandler.allocateAdjacencyLabel(link2), is(true)); | ||
| 410 | + assertThat(srTeHandler.releaseAdjacencyLabel(link2), is(true)); | ||
| 411 | + // Retrieve from store and check whether adjacency label is removed successfully for this device. | ||
| 412 | + labelId = pceStore.getAdjLabel(link2); | ||
| 413 | + assertThat(labelId, is(nullValue())); | ||
| 414 | + } | ||
| 415 | + | ||
| 416 | + /** | ||
| 417 | + * Checks the operation of computeLabelStack() method. | ||
| 418 | + */ | ||
| 419 | + @Test | ||
| 420 | + public void testComputeLabelStack() { | ||
| 421 | + // Allocate node labels to each devices | ||
| 422 | + labelId = LabelResourceId.labelResourceId(4097); | ||
| 423 | + pceStore.addGlobalNodeLabel(deviceId1, labelId); | ||
| 424 | + labelId = LabelResourceId.labelResourceId(4098); | ||
| 425 | + pceStore.addGlobalNodeLabel(deviceId2, labelId); | ||
| 426 | + labelId = LabelResourceId.labelResourceId(4099); | ||
| 427 | + pceStore.addGlobalNodeLabel(deviceId3, labelId); | ||
| 428 | + labelId = LabelResourceId.labelResourceId(4100); | ||
| 429 | + pceStore.addGlobalNodeLabel(deviceId4, labelId); | ||
| 430 | + labelId = LabelResourceId.labelResourceId(4101); | ||
| 431 | + pceStore.addGlobalNodeLabel(deviceId5, labelId); | ||
| 432 | + | ||
| 433 | + // Allocate adjacency labels to each devices | ||
| 434 | + labelId = LabelResourceId.labelResourceId(5122); | ||
| 435 | + pceStore.addAdjLabel(link1, labelId); | ||
| 436 | + labelId = LabelResourceId.labelResourceId(5123); | ||
| 437 | + pceStore.addAdjLabel(link2, labelId); | ||
| 438 | + labelId = LabelResourceId.labelResourceId(5124); | ||
| 439 | + pceStore.addAdjLabel(link3, labelId); | ||
| 440 | + labelId = LabelResourceId.labelResourceId(5125); | ||
| 441 | + pceStore.addAdjLabel(link4, labelId); | ||
| 442 | + | ||
| 443 | + // Compute label stack | ||
| 444 | + LabelStack labelStack = srTeHandler.computeLabelStack(path1); | ||
| 445 | + | ||
| 446 | + // check node-label of deviceId1 | ||
| 447 | + List<LabelResourceId> labelList = labelStack.labelResources(); | ||
| 448 | + Iterator<LabelResourceId> iterator = labelList.iterator(); | ||
| 449 | + labelId = (LabelResourceId) iterator.next(); | ||
| 450 | + assertThat(labelId, is(LabelResourceId.labelResourceId(4097))); | ||
| 451 | + | ||
| 452 | + // check adjacency label of deviceId1 | ||
| 453 | + labelId = (LabelResourceId) iterator.next(); | ||
| 454 | + assertThat(labelId, is(LabelResourceId.labelResourceId(5122))); | ||
| 455 | + | ||
| 456 | + // check node-label of deviceId2 | ||
| 457 | + labelId = (LabelResourceId) iterator.next(); | ||
| 458 | + assertThat(labelId, is(LabelResourceId.labelResourceId(4098))); | ||
| 459 | + | ||
| 460 | + // check adjacency label of deviceId2 | ||
| 461 | + labelId = (LabelResourceId) iterator.next(); | ||
| 462 | + assertThat(labelId, is(LabelResourceId.labelResourceId(5123))); | ||
| 463 | + | ||
| 464 | + // check node-label of deviceId3 | ||
| 465 | + labelId = (LabelResourceId) iterator.next(); | ||
| 466 | + assertThat(labelId, is(LabelResourceId.labelResourceId(4099))); | ||
| 467 | + | ||
| 468 | + // check adjacency label of deviceId3 | ||
| 469 | + labelId = (LabelResourceId) iterator.next(); | ||
| 470 | + assertThat(labelId, is(LabelResourceId.labelResourceId(5124))); | ||
| 471 | + | ||
| 472 | + // check node-label of deviceId4 | ||
| 473 | + labelId = (LabelResourceId) iterator.next(); | ||
| 474 | + assertThat(labelId, is(LabelResourceId.labelResourceId(4100))); | ||
| 475 | + | ||
| 476 | + // check adjacency label of deviceId4 | ||
| 477 | + labelId = (LabelResourceId) iterator.next(); | ||
| 478 | + assertThat(labelId, is(LabelResourceId.labelResourceId(5125))); | ||
| 479 | + | ||
| 480 | + // check node-label of deviceId5 | ||
| 481 | + labelId = (LabelResourceId) iterator.next(); | ||
| 482 | + assertThat(labelId, is(LabelResourceId.labelResourceId(4101))); | ||
| 483 | + } | ||
| 484 | +} |
| 1 | +/* | ||
| 2 | + * Copyright 2016-present Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | +package org.onosproject.pce.util; | ||
| 17 | + | ||
| 18 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
| 19 | + | ||
| 20 | +import java.util.Collection; | ||
| 21 | +import java.util.LinkedList; | ||
| 22 | +import java.util.Random; | ||
| 23 | +import java.util.Set; | ||
| 24 | + | ||
| 25 | +import org.onosproject.incubator.net.resource.label.DefaultLabelResource; | ||
| 26 | +import org.onosproject.incubator.net.resource.label.LabelResource; | ||
| 27 | +import org.onosproject.incubator.net.resource.label.LabelResourceAdminService; | ||
| 28 | +import org.onosproject.incubator.net.resource.label.LabelResourceDelegate; | ||
| 29 | +import org.onosproject.incubator.net.resource.label.LabelResourceEvent; | ||
| 30 | +import org.onosproject.incubator.net.resource.label.LabelResourceId; | ||
| 31 | +import org.onosproject.incubator.net.resource.label.LabelResourceListener; | ||
| 32 | +import org.onosproject.incubator.net.resource.label.LabelResourcePool; | ||
| 33 | +import org.onosproject.incubator.net.resource.label.LabelResourceProvider; | ||
| 34 | +import org.onosproject.incubator.net.resource.label.LabelResourceProviderRegistry; | ||
| 35 | +import org.onosproject.incubator.net.resource.label.LabelResourceProviderService; | ||
| 36 | +import org.onosproject.incubator.net.resource.label.LabelResourceService; | ||
| 37 | +import org.onosproject.net.Device; | ||
| 38 | +import org.onosproject.net.DeviceId; | ||
| 39 | +import org.onosproject.net.device.DeviceEvent; | ||
| 40 | +import org.onosproject.net.device.DeviceEvent.Type; | ||
| 41 | +import org.onosproject.net.device.DeviceListener; | ||
| 42 | +import org.onosproject.net.provider.AbstractListenerProviderRegistry; | ||
| 43 | +import org.onosproject.net.provider.AbstractProviderService; | ||
| 44 | + | ||
| 45 | +import com.google.common.collect.Multimap; | ||
| 46 | + | ||
| 47 | +/** | ||
| 48 | + * Provides test implementation of class LabelResourceService. | ||
| 49 | + */ | ||
| 50 | +public class LabelResourceAdapter | ||
| 51 | + extends AbstractListenerProviderRegistry<LabelResourceEvent, LabelResourceListener, | ||
| 52 | + LabelResourceProvider, LabelResourceProviderService> | ||
| 53 | + implements LabelResourceService, LabelResourceAdminService, LabelResourceProviderRegistry { | ||
| 54 | + public static final long GLOBAL_LABEL_SPACE_MIN = 4097; | ||
| 55 | + public static final long GLOBAL_LABEL_SPACE_MAX = 5121; | ||
| 56 | + public static final long LOCAL_LABEL_SPACE_MIN = 5122; | ||
| 57 | + public static final long LOCAL_LABEL_SPACE_MAX = 9217; | ||
| 58 | + | ||
| 59 | + private Random random = new Random(); | ||
| 60 | + | ||
| 61 | + @Override | ||
| 62 | + public boolean createDevicePool(DeviceId deviceId, | ||
| 63 | + LabelResourceId beginLabel, | ||
| 64 | + LabelResourceId endLabel) { | ||
| 65 | + return true; | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + @Override | ||
| 69 | + public boolean createGlobalPool(LabelResourceId beginLabel, | ||
| 70 | + LabelResourceId endLabel) { | ||
| 71 | + return true; | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + @Override | ||
| 75 | + public boolean destroyDevicePool(DeviceId deviceId) { | ||
| 76 | + return true; | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + @Override | ||
| 80 | + public boolean destroyGlobalPool() { | ||
| 81 | + return true; | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + public long getLabelId(long min, long max) { | ||
| 85 | + return random.nextInt((int) max - (int) min + 1) + (int) min; | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + public Collection<LabelResource> applyFromDevicePool(DeviceId deviceId, | ||
| 89 | + long applyNum) { | ||
| 90 | + Collection<LabelResource> labelList = new LinkedList<>(); | ||
| 91 | + LabelResource label = new DefaultLabelResource(deviceId, | ||
| 92 | + LabelResourceId.labelResourceId( | ||
| 93 | + getLabelId(LOCAL_LABEL_SPACE_MIN, LOCAL_LABEL_SPACE_MAX))); | ||
| 94 | + labelList.add(label); | ||
| 95 | + return labelList; | ||
| 96 | + } | ||
| 97 | + | ||
| 98 | + public Collection<LabelResource> applyFromGlobalPool(long applyNum) { | ||
| 99 | + Collection<LabelResource> labelList = new LinkedList<>(); | ||
| 100 | + LabelResource label = new DefaultLabelResource(DeviceId.deviceId("foo"), | ||
| 101 | + LabelResourceId.labelResourceId( | ||
| 102 | + getLabelId(GLOBAL_LABEL_SPACE_MIN, GLOBAL_LABEL_SPACE_MAX))); | ||
| 103 | + labelList.add(label); | ||
| 104 | + return labelList; | ||
| 105 | + } | ||
| 106 | + | ||
| 107 | + public boolean releaseToDevicePool(Multimap<DeviceId, LabelResource> release) { | ||
| 108 | + return true; | ||
| 109 | + } | ||
| 110 | + | ||
| 111 | + public boolean releaseToGlobalPool(Set<LabelResourceId> release) { | ||
| 112 | + return true; | ||
| 113 | + } | ||
| 114 | + | ||
| 115 | + public boolean isDevicePoolFull(DeviceId deviceId) { | ||
| 116 | + return false; | ||
| 117 | + } | ||
| 118 | + | ||
| 119 | + public boolean isGlobalPoolFull() { | ||
| 120 | + return false; | ||
| 121 | + } | ||
| 122 | + | ||
| 123 | + public long getFreeNumOfDevicePool(DeviceId deviceId) { | ||
| 124 | + return 4; | ||
| 125 | + } | ||
| 126 | + | ||
| 127 | + public long getFreeNumOfGlobalPool() { | ||
| 128 | + return 4; | ||
| 129 | + } | ||
| 130 | + | ||
| 131 | + @Override | ||
| 132 | + public LabelResourcePool getDeviceLabelResourcePool(DeviceId deviceId) { | ||
| 133 | + return null; | ||
| 134 | + } | ||
| 135 | + | ||
| 136 | + @Override | ||
| 137 | + public LabelResourcePool getGlobalLabelResourcePool() { | ||
| 138 | + return null; | ||
| 139 | + } | ||
| 140 | + | ||
| 141 | + private class InternalLabelResourceDelegate implements LabelResourceDelegate { | ||
| 142 | + @Override | ||
| 143 | + public void notify(LabelResourceEvent event) { | ||
| 144 | + post(event); | ||
| 145 | + } | ||
| 146 | + | ||
| 147 | + } | ||
| 148 | + | ||
| 149 | + private class InternalDeviceListener implements DeviceListener { | ||
| 150 | + @Override | ||
| 151 | + public void event(DeviceEvent event) { | ||
| 152 | + Device device = event.subject(); | ||
| 153 | + if (Type.DEVICE_REMOVED.equals(event.type())) { | ||
| 154 | + destroyDevicePool(device.id()); | ||
| 155 | + } | ||
| 156 | + } | ||
| 157 | + } | ||
| 158 | + | ||
| 159 | + private class InternalLabelResourceProviderService | ||
| 160 | + extends AbstractProviderService<LabelResourceProvider> | ||
| 161 | + implements LabelResourceProviderService { | ||
| 162 | + | ||
| 163 | + protected InternalLabelResourceProviderService(LabelResourceProvider provider) { | ||
| 164 | + super(provider); | ||
| 165 | + } | ||
| 166 | + | ||
| 167 | + @Override | ||
| 168 | + public void deviceLabelResourcePoolDetected(DeviceId deviceId, | ||
| 169 | + LabelResourceId beginLabel, | ||
| 170 | + LabelResourceId endLabel) { | ||
| 171 | + checkNotNull(deviceId, "deviceId is not null"); | ||
| 172 | + checkNotNull(beginLabel, "beginLabel is not null"); | ||
| 173 | + checkNotNull(endLabel, "endLabel is not null"); | ||
| 174 | + createDevicePool(deviceId, beginLabel, endLabel); | ||
| 175 | + } | ||
| 176 | + | ||
| 177 | + @Override | ||
| 178 | + public void deviceLabelResourcePoolDestroyed(DeviceId deviceId) { | ||
| 179 | + checkNotNull(deviceId, "deviceId is not null"); | ||
| 180 | + destroyDevicePool(deviceId); | ||
| 181 | + } | ||
| 182 | + | ||
| 183 | + } | ||
| 184 | + | ||
| 185 | + @Override | ||
| 186 | + protected LabelResourceProviderService createProviderService(LabelResourceProvider provider) { | ||
| 187 | + return null; | ||
| 188 | + } | ||
| 189 | +} |
-
Please register or login to post a comment