Committed by
Gerrit Code Review
Remove deprecated interface, its implementation and CLIs
Change-Id: Id644a8cd07abd6e0ece6392790943d401a81d180
Showing
7 changed files
with
1 additions
and
658 deletions
| 1 | -/* | ||
| 2 | - * Copyright 2015 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.cli.net; | ||
| 17 | - | ||
| 18 | -import com.google.common.collect.Lists; | ||
| 19 | -import org.apache.karaf.shell.commands.Argument; | ||
| 20 | -import org.apache.karaf.shell.commands.Command; | ||
| 21 | -import org.apache.karaf.shell.commands.Option; | ||
| 22 | -import org.onosproject.cli.AbstractShellCommand; | ||
| 23 | -import org.onosproject.net.DeviceId; | ||
| 24 | -import org.onosproject.net.Link; | ||
| 25 | -import org.onosproject.net.Path; | ||
| 26 | -import org.onosproject.net.intent.IntentId; | ||
| 27 | -import org.onosproject.net.resource.link.DefaultLinkResourceRequest; | ||
| 28 | -import org.onosproject.net.resource.link.LinkResourceAllocations; | ||
| 29 | -import org.onosproject.net.resource.link.LinkResourceRequest; | ||
| 30 | -import org.onosproject.net.resource.link.LinkResourceService; | ||
| 31 | -import org.onosproject.net.topology.PathService; | ||
| 32 | - | ||
| 33 | -import java.util.List; | ||
| 34 | -import java.util.Set; | ||
| 35 | - | ||
| 36 | -/** | ||
| 37 | - * Commands to test out LinkResourceManager directly. | ||
| 38 | - * | ||
| 39 | - * @deprecated in Emu release | ||
| 40 | - */ | ||
| 41 | -@Deprecated | ||
| 42 | -@Command(scope = "onos", name = "resource-request", | ||
| 43 | - description = "request or remove resources" | ||
| 44 | - + "[Using deprecated LinkResourceService]") | ||
| 45 | -public class LinkResourceTestCommand extends AbstractShellCommand { | ||
| 46 | - | ||
| 47 | - // default is bandwidth. | ||
| 48 | - @Option(name = "-m", aliases = "--mpls", description = "MPLS resource", | ||
| 49 | - required = false, multiValued = false) | ||
| 50 | - private boolean isMpls = false; | ||
| 51 | - | ||
| 52 | - @Option(name = "-o", aliases = "--optical", description = "Optical resource", | ||
| 53 | - required = false, multiValued = false) | ||
| 54 | - private boolean isOptical = false; | ||
| 55 | - | ||
| 56 | - @Option(name = "-d", aliases = "--delete", description = "Delete resource by intent ID", | ||
| 57 | - required = false, multiValued = false) | ||
| 58 | - private boolean remove = false; | ||
| 59 | - | ||
| 60 | - @Argument(index = 0, name = "srcString", description = "Link source", | ||
| 61 | - required = true, multiValued = false) | ||
| 62 | - String srcString = null; | ||
| 63 | - | ||
| 64 | - @Argument(index = 1, name = "dstString", description = "Link destination", | ||
| 65 | - required = true, multiValued = false) | ||
| 66 | - String dstString = null; | ||
| 67 | - | ||
| 68 | - @Argument(index = 2, name = "id", description = "Identifier", | ||
| 69 | - required = true, multiValued = false) | ||
| 70 | - int id; | ||
| 71 | - | ||
| 72 | - private LinkResourceService resService; | ||
| 73 | - private PathService pathService; | ||
| 74 | - | ||
| 75 | - private static final int BANDWIDTH = 1_000_000; | ||
| 76 | - | ||
| 77 | - @Override | ||
| 78 | - protected void execute() { | ||
| 79 | - resService = get(LinkResourceService.class); | ||
| 80 | - pathService = get(PathService.class); | ||
| 81 | - | ||
| 82 | - DeviceId src = DeviceId.deviceId(getDeviceId(srcString)); | ||
| 83 | - DeviceId dst = DeviceId.deviceId(getDeviceId(dstString)); | ||
| 84 | - IntentId intId = IntentId.valueOf(id); | ||
| 85 | - | ||
| 86 | - Set<Path> paths = pathService.getPaths(src, dst); | ||
| 87 | - | ||
| 88 | - if (paths == null || paths.isEmpty()) { | ||
| 89 | - print("No path between %s and %s", srcString, dstString); | ||
| 90 | - return; | ||
| 91 | - } | ||
| 92 | - | ||
| 93 | - if (remove) { | ||
| 94 | - LinkResourceAllocations lra = resService.getAllocations(intId); | ||
| 95 | - resService.releaseResources(lra); | ||
| 96 | - return; | ||
| 97 | - } | ||
| 98 | - | ||
| 99 | - for (Path p : paths) { | ||
| 100 | - List<Link> links = p.links(); | ||
| 101 | - LinkResourceRequest.Builder request = null; | ||
| 102 | - if (isMpls) { | ||
| 103 | - List<Link> nlinks = Lists.newArrayList(); | ||
| 104 | - try { | ||
| 105 | - nlinks.addAll(links.subList(1, links.size() - 2)); | ||
| 106 | - request = DefaultLinkResourceRequest.builder(intId, nlinks) | ||
| 107 | - .addMplsRequest(); | ||
| 108 | - } catch (IndexOutOfBoundsException e) { | ||
| 109 | - log.warn("could not allocate MPLS path", e); | ||
| 110 | - continue; | ||
| 111 | - } | ||
| 112 | - } else if (isOptical) { | ||
| 113 | - request = DefaultLinkResourceRequest.builder(intId, links) | ||
| 114 | - .addLambdaRequest(); | ||
| 115 | - } else { | ||
| 116 | - request = DefaultLinkResourceRequest.builder(intId, links) | ||
| 117 | - .addBandwidthRequest(BANDWIDTH); | ||
| 118 | - } | ||
| 119 | - | ||
| 120 | - if (request != null) { | ||
| 121 | - LinkResourceRequest lrr = request.build(); | ||
| 122 | - LinkResourceAllocations lra = resService.requestResources(lrr); | ||
| 123 | - if (lra != null) { | ||
| 124 | - break; | ||
| 125 | - } | ||
| 126 | - print("Allocated:\n%s", lra); | ||
| 127 | - } else { | ||
| 128 | - log.info("nothing to request"); | ||
| 129 | - } | ||
| 130 | - } | ||
| 131 | - } | ||
| 132 | - | ||
| 133 | - public String getDeviceId(String deviceString) { | ||
| 134 | - int slash = deviceString.indexOf('/'); | ||
| 135 | - if (slash <= 0) { | ||
| 136 | - return ""; | ||
| 137 | - } | ||
| 138 | - return deviceString.substring(0, slash); | ||
| 139 | - } | ||
| 140 | - | ||
| 141 | -} |
| 1 | -/* | ||
| 2 | - * Copyright 2014 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.cli.net; | ||
| 17 | - | ||
| 18 | -import org.apache.karaf.shell.commands.Argument; | ||
| 19 | -import org.apache.karaf.shell.commands.Command; | ||
| 20 | -import org.onosproject.cli.AbstractShellCommand; | ||
| 21 | -import org.onosproject.net.ConnectPoint; | ||
| 22 | -import org.onosproject.net.Link; | ||
| 23 | -import org.onosproject.net.link.LinkService; | ||
| 24 | -import org.onosproject.net.resource.link.LinkResourceService; | ||
| 25 | - | ||
| 26 | -/** | ||
| 27 | - * Lists allocations by link. Lists all allocations if link is unspecified. | ||
| 28 | - * | ||
| 29 | - * @deprecated in Emu release | ||
| 30 | - */ | ||
| 31 | -@Deprecated | ||
| 32 | -@Command(scope = "onos", name = "resource-allocations", | ||
| 33 | - description = "Lists allocations by link. Lists all allocations if link is unspecified." | ||
| 34 | - + "[Using deprecated LinkResourceService]") | ||
| 35 | -public class ResourceAllocationsCommand extends AbstractShellCommand { | ||
| 36 | - | ||
| 37 | - private static final String FMT = "src=%s/%s, dst=%s/%s, type=%s%s"; | ||
| 38 | - private static final String COMPACT = "%s/%s-%s/%s"; | ||
| 39 | - | ||
| 40 | - @Argument(index = 0, name = "srcString", description = "Link source", | ||
| 41 | - required = false, multiValued = false) | ||
| 42 | - String srcString = null; | ||
| 43 | - @Argument(index = 1, name = "dstString", description = "Link destination", | ||
| 44 | - required = false, multiValued = false) | ||
| 45 | - String dstString = null; | ||
| 46 | - | ||
| 47 | - @Override | ||
| 48 | - protected void execute() { | ||
| 49 | - LinkResourceService resourceService = get(LinkResourceService.class); | ||
| 50 | - LinkService linkService = get(LinkService.class); | ||
| 51 | - | ||
| 52 | - if (srcString == null || dstString == null) { | ||
| 53 | - print("----- Displaying all resource allocations -----"); | ||
| 54 | - resourceService.getAllocations().forEach(alloc -> print("%s", alloc)); | ||
| 55 | - return; | ||
| 56 | - } | ||
| 57 | - | ||
| 58 | - ConnectPoint src = ConnectPoint.deviceConnectPoint(srcString); | ||
| 59 | - ConnectPoint dst = ConnectPoint.deviceConnectPoint(dstString); | ||
| 60 | - | ||
| 61 | - Link link = linkService.getLink(src, dst); | ||
| 62 | - if (link != null) { | ||
| 63 | - resourceService.getAllocations(link).forEach(alloc -> print("%s", alloc)); | ||
| 64 | - } else { | ||
| 65 | - print("No path found for endpoints: %s, %s", src, dst); | ||
| 66 | - } | ||
| 67 | - } | ||
| 68 | -} |
| 1 | -/* | ||
| 2 | - * Copyright 2014 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.cli.net; | ||
| 17 | - | ||
| 18 | -import org.apache.karaf.shell.commands.Argument; | ||
| 19 | -import org.apache.karaf.shell.commands.Command; | ||
| 20 | -import org.onosproject.cli.AbstractShellCommand; | ||
| 21 | -import org.onosproject.net.ConnectPoint; | ||
| 22 | -import org.onosproject.net.Link; | ||
| 23 | -import org.onosproject.net.link.LinkService; | ||
| 24 | -import org.onosproject.net.resource.link.LinkResourceService; | ||
| 25 | -import org.onosproject.net.resource.ResourceRequest; | ||
| 26 | - | ||
| 27 | -/** | ||
| 28 | - * Lists allocations by link. | ||
| 29 | - * | ||
| 30 | - * @deprecated in Emu release | ||
| 31 | - */ | ||
| 32 | -@Deprecated | ||
| 33 | -@Command(scope = "onos", name = "resource-available", | ||
| 34 | - description = "Lists available resources by link" | ||
| 35 | - + "[Using deprecated LinkResourceService]") | ||
| 36 | -public class ResourceAvailableCommand extends AbstractShellCommand { | ||
| 37 | - | ||
| 38 | - private static final String FMT = "src=%s/%s, dst=%s/%s, type=%s%s"; | ||
| 39 | - private static final String COMPACT = "%s/%s-%s/%s"; | ||
| 40 | - | ||
| 41 | - @Argument(index = 0, name = "srcString", description = "Link source", | ||
| 42 | - required = false, multiValued = false) | ||
| 43 | - String srcString = null; | ||
| 44 | - @Argument(index = 1, name = "dstString", description = "Link destination", | ||
| 45 | - required = false, multiValued = false) | ||
| 46 | - String dstString = null; | ||
| 47 | - | ||
| 48 | - @Override | ||
| 49 | - protected void execute() { | ||
| 50 | - LinkResourceService resourceService = get(LinkResourceService.class); | ||
| 51 | - LinkService linkService = get(LinkService.class); | ||
| 52 | - | ||
| 53 | - Iterable<ResourceRequest> itr = null; | ||
| 54 | - try { | ||
| 55 | - ConnectPoint src = ConnectPoint.deviceConnectPoint(srcString); | ||
| 56 | - | ||
| 57 | - ConnectPoint dst = ConnectPoint.deviceConnectPoint(dstString); | ||
| 58 | - | ||
| 59 | - Link link = linkService.getLink(src, dst); | ||
| 60 | - | ||
| 61 | - itr = resourceService.getAvailableResources(link); | ||
| 62 | - | ||
| 63 | - int lambdaCount = 0; | ||
| 64 | - for (ResourceRequest req : itr) { | ||
| 65 | - switch (req.type()) { | ||
| 66 | - case LAMBDA: | ||
| 67 | - lambdaCount++; | ||
| 68 | - break; | ||
| 69 | - case BANDWIDTH: | ||
| 70 | - print("%s", req); | ||
| 71 | - break; | ||
| 72 | - default: | ||
| 73 | - break; | ||
| 74 | - } | ||
| 75 | - } | ||
| 76 | - if (lambdaCount > 0) { | ||
| 77 | - print("Number of available lambdas: %d", lambdaCount); | ||
| 78 | - } | ||
| 79 | - | ||
| 80 | - } catch (Exception e) { | ||
| 81 | - print("Invalid link %s", e.getMessage()); | ||
| 82 | - } | ||
| 83 | - } | ||
| 84 | -} |
| ... | @@ -368,29 +368,6 @@ | ... | @@ -368,29 +368,6 @@ |
| 368 | </completers> | 368 | </completers> |
| 369 | </command> | 369 | </command> |
| 370 | 370 | ||
| 371 | - <!-- Should deprecate following 3 commands soon. --> | ||
| 372 | - <command> | ||
| 373 | - <action class="org.onosproject.cli.net.ResourceAllocationsCommand"/> | ||
| 374 | - <completers> | ||
| 375 | - <ref component-id="connectPointCompleter"/> | ||
| 376 | - <ref component-id="connectPointCompleter"/> | ||
| 377 | - </completers> | ||
| 378 | - </command> | ||
| 379 | - <command> | ||
| 380 | - <action class="org.onosproject.cli.net.ResourceAvailableCommand"/> | ||
| 381 | - <completers> | ||
| 382 | - <ref component-id="connectPointCompleter"/> | ||
| 383 | - <ref component-id="connectPointCompleter"/> | ||
| 384 | - </completers> | ||
| 385 | - </command> | ||
| 386 | - <command> | ||
| 387 | - <action class="org.onosproject.cli.net.LinkResourceTestCommand"/> | ||
| 388 | - <completers> | ||
| 389 | - <ref component-id="connectPointCompleter"/> | ||
| 390 | - <ref component-id="connectPointCompleter"/> | ||
| 391 | - <null/> | ||
| 392 | - </completers> | ||
| 393 | - </command> | ||
| 394 | <command> | 371 | <command> |
| 395 | <action class="org.onosproject.cli.net.ClustersListCommand"/> | 372 | <action class="org.onosproject.cli.net.ClustersListCommand"/> |
| 396 | </command> | 373 | </command> | ... | ... |
core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceService.java
deleted
100644 → 0
| 1 | -/* | ||
| 2 | - * Copyright 2014 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.net.resource.link; | ||
| 17 | - | ||
| 18 | -import org.onosproject.event.ListenerService; | ||
| 19 | -import org.onosproject.net.Link; | ||
| 20 | -import org.onosproject.net.intent.IntentId; | ||
| 21 | -import org.onosproject.net.resource.ResourceRequest; | ||
| 22 | - | ||
| 23 | -/** | ||
| 24 | - * Service for providing link resource allocation. | ||
| 25 | - * | ||
| 26 | - * @deprecated in Emu Release | ||
| 27 | - */ | ||
| 28 | -@Deprecated | ||
| 29 | -public interface LinkResourceService | ||
| 30 | - extends ListenerService<LinkResourceEvent, LinkResourceListener> { | ||
| 31 | - | ||
| 32 | - /** | ||
| 33 | - * Requests resources. | ||
| 34 | - * | ||
| 35 | - * @param req resources to be allocated | ||
| 36 | - * @return allocated resources | ||
| 37 | - * @deprecated in Emu Release | ||
| 38 | - */ | ||
| 39 | - @Deprecated | ||
| 40 | - LinkResourceAllocations requestResources(LinkResourceRequest req); | ||
| 41 | - | ||
| 42 | - /** | ||
| 43 | - * Releases resources. | ||
| 44 | - * | ||
| 45 | - * @param allocations resources to be released | ||
| 46 | - * @deprecated in Emu Release | ||
| 47 | - */ | ||
| 48 | - @Deprecated | ||
| 49 | - void releaseResources(LinkResourceAllocations allocations); | ||
| 50 | - | ||
| 51 | - /** | ||
| 52 | - * Updates previously made allocations with a new resource request. | ||
| 53 | - * | ||
| 54 | - * @param req updated resource request | ||
| 55 | - * @param oldAllocations old resource allocations | ||
| 56 | - * @return new resource allocations | ||
| 57 | - * @deprecated in Emu Release | ||
| 58 | - */ | ||
| 59 | - @Deprecated | ||
| 60 | - LinkResourceAllocations updateResources(LinkResourceRequest req, | ||
| 61 | - LinkResourceAllocations oldAllocations); | ||
| 62 | - | ||
| 63 | - /** | ||
| 64 | - * Returns all allocated resources. | ||
| 65 | - * | ||
| 66 | - * @return allocated resources | ||
| 67 | - * @deprecated in Emu Release | ||
| 68 | - */ | ||
| 69 | - @Deprecated | ||
| 70 | - Iterable<LinkResourceAllocations> getAllocations(); | ||
| 71 | - | ||
| 72 | - /** | ||
| 73 | - * Returns all allocated resources to given link. | ||
| 74 | - * | ||
| 75 | - * @param link a target link | ||
| 76 | - * @return allocated resources | ||
| 77 | - * @deprecated in Emu Release | ||
| 78 | - */ | ||
| 79 | - @Deprecated | ||
| 80 | - Iterable<LinkResourceAllocations> getAllocations(Link link); | ||
| 81 | - | ||
| 82 | - /** | ||
| 83 | - * Returns the resources allocated for an Intent. | ||
| 84 | - * | ||
| 85 | - * @param intentId the target Intent's id | ||
| 86 | - * @return allocated resources for Intent | ||
| 87 | - * @deprecated in Emu Release | ||
| 88 | - */ | ||
| 89 | - @Deprecated | ||
| 90 | - LinkResourceAllocations getAllocations(IntentId intentId); | ||
| 91 | - | ||
| 92 | - /** | ||
| 93 | - * Returns available resources for given link. | ||
| 94 | - * | ||
| 95 | - * @param link a target link | ||
| 96 | - * @return available resources for the target link | ||
| 97 | - * @deprecated in Emu Release | ||
| 98 | - */ | ||
| 99 | - @Deprecated | ||
| 100 | - Iterable<ResourceRequest> getAvailableResources(Link link); | ||
| 101 | - | ||
| 102 | - /** | ||
| 103 | - * Returns available resources for given link. | ||
| 104 | - * | ||
| 105 | - * @param link a target link | ||
| 106 | - * @param allocations allocations to be included as available | ||
| 107 | - * @return available resources for the target link | ||
| 108 | - * @deprecated in Emu Release | ||
| 109 | - */ | ||
| 110 | - @Deprecated | ||
| 111 | - Iterable<ResourceRequest> getAvailableResources(Link link, | ||
| 112 | - LinkResourceAllocations allocations); | ||
| 113 | - | ||
| 114 | -} |
core/net/src/main/java/org/onosproject/net/resource/impl/LinkResourceManager.java
deleted
100644 → 0
| 1 | -/* | ||
| 2 | - * Copyright 2014-2015 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.net.resource.impl; | ||
| 17 | - | ||
| 18 | -import com.google.common.collect.Sets; | ||
| 19 | -import org.apache.felix.scr.annotations.Activate; | ||
| 20 | -import org.apache.felix.scr.annotations.Component; | ||
| 21 | -import org.apache.felix.scr.annotations.Deactivate; | ||
| 22 | -import org.apache.felix.scr.annotations.Reference; | ||
| 23 | -import org.apache.felix.scr.annotations.ReferenceCardinality; | ||
| 24 | -import org.apache.felix.scr.annotations.Service; | ||
| 25 | -import org.onosproject.event.AbstractListenerManager; | ||
| 26 | -import org.onosproject.net.Link; | ||
| 27 | -import org.onosproject.net.intent.IntentId; | ||
| 28 | -import org.onosproject.net.resource.ResourceAllocation; | ||
| 29 | -import org.onosproject.net.resource.ResourceRequest; | ||
| 30 | -import org.onosproject.net.resource.ResourceType; | ||
| 31 | -import org.onosproject.net.resource.link.BandwidthResourceAllocation; | ||
| 32 | -import org.onosproject.net.resource.link.BandwidthResourceRequest; | ||
| 33 | -import org.onosproject.net.resource.link.DefaultLinkResourceAllocations; | ||
| 34 | -import org.onosproject.net.resource.link.LambdaResourceAllocation; | ||
| 35 | -import org.onosproject.net.resource.link.LambdaResourceRequest; | ||
| 36 | -import org.onosproject.net.resource.link.LinkResourceAllocations; | ||
| 37 | -import org.onosproject.net.resource.link.LinkResourceEvent; | ||
| 38 | -import org.onosproject.net.resource.link.LinkResourceListener; | ||
| 39 | -import org.onosproject.net.resource.link.LinkResourceRequest; | ||
| 40 | -import org.onosproject.net.resource.link.LinkResourceService; | ||
| 41 | -import org.onosproject.net.resource.link.LinkResourceStore; | ||
| 42 | -import org.onosproject.net.resource.link.LinkResourceStoreDelegate; | ||
| 43 | -import org.onosproject.net.resource.link.MplsLabel; | ||
| 44 | -import org.onosproject.net.resource.link.MplsLabelResourceAllocation; | ||
| 45 | -import org.onosproject.net.resource.link.MplsLabelResourceRequest; | ||
| 46 | -import org.slf4j.Logger; | ||
| 47 | - | ||
| 48 | -import java.util.HashMap; | ||
| 49 | -import java.util.HashSet; | ||
| 50 | -import java.util.Map; | ||
| 51 | -import java.util.Optional; | ||
| 52 | -import java.util.Set; | ||
| 53 | - | ||
| 54 | -import static org.onosproject.security.AppGuard.checkPermission; | ||
| 55 | -import static org.slf4j.LoggerFactory.getLogger; | ||
| 56 | -import static org.onosproject.security.AppPermission.Type.*; | ||
| 57 | - | ||
| 58 | - | ||
| 59 | -/** | ||
| 60 | - * Provides basic implementation of link resources allocation. | ||
| 61 | - */ | ||
| 62 | -@Component(immediate = true) | ||
| 63 | -@Service | ||
| 64 | -public class LinkResourceManager | ||
| 65 | - extends AbstractListenerManager<LinkResourceEvent, LinkResourceListener> | ||
| 66 | - implements LinkResourceService { | ||
| 67 | - | ||
| 68 | - private final Logger log = getLogger(getClass()); | ||
| 69 | - | ||
| 70 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 71 | - private LinkResourceStore store; | ||
| 72 | - | ||
| 73 | - @Activate | ||
| 74 | - public void activate() { | ||
| 75 | - eventDispatcher.addSink(LinkResourceEvent.class, listenerRegistry); | ||
| 76 | - log.info("Started"); | ||
| 77 | - } | ||
| 78 | - | ||
| 79 | - @Deactivate | ||
| 80 | - public void deactivate() { | ||
| 81 | - eventDispatcher.removeSink(LinkResourceEvent.class); | ||
| 82 | - log.info("Stopped"); | ||
| 83 | - } | ||
| 84 | - | ||
| 85 | - | ||
| 86 | - @Override | ||
| 87 | - public LinkResourceAllocations requestResources(LinkResourceRequest req) { | ||
| 88 | - checkPermission(LINK_WRITE); | ||
| 89 | - | ||
| 90 | - // TODO Concatenate multiple bandwidth requests. | ||
| 91 | - // TODO Support multiple lambda resource requests. | ||
| 92 | - // TODO Throw appropriate exception. | ||
| 93 | - Set<ResourceAllocation> allocs = new HashSet<>(); | ||
| 94 | - Map<Link, Set<ResourceAllocation>> allocsPerLink = new HashMap<>(); | ||
| 95 | - for (ResourceRequest r : req.resources()) { | ||
| 96 | - switch (r.type()) { | ||
| 97 | - case BANDWIDTH: | ||
| 98 | - BandwidthResourceRequest br = (BandwidthResourceRequest) r; | ||
| 99 | - allocs.add(new BandwidthResourceAllocation(br.bandwidth())); | ||
| 100 | - break; | ||
| 101 | - case LAMBDA: | ||
| 102 | - LambdaResourceRequest lr = (LambdaResourceRequest) r; | ||
| 103 | - allocs.add(new LambdaResourceAllocation(lr.lambda())); | ||
| 104 | - break; | ||
| 105 | - case MPLS_LABEL: | ||
| 106 | - for (Link link : req.links()) { | ||
| 107 | - if (allocsPerLink.get(link) == null) { | ||
| 108 | - allocsPerLink.put(link, new HashSet<>()); | ||
| 109 | - } | ||
| 110 | - | ||
| 111 | - Optional<MplsLabel> label = req.resources(link).stream() | ||
| 112 | - .filter(x -> x.type() == ResourceType.MPLS_LABEL) | ||
| 113 | - .map(x -> (MplsLabelResourceRequest) x) | ||
| 114 | - .map(MplsLabelResourceRequest::mplsLabel) | ||
| 115 | - .findFirst(); | ||
| 116 | - | ||
| 117 | - if (label.isPresent()) { | ||
| 118 | - allocsPerLink.get(link).add(new MplsLabelResourceAllocation(label.get())); | ||
| 119 | - } else { | ||
| 120 | - log.info("Failed to allocate MPLS resource."); | ||
| 121 | - break; | ||
| 122 | - } | ||
| 123 | - } | ||
| 124 | - break; | ||
| 125 | - default: | ||
| 126 | - break; | ||
| 127 | - } | ||
| 128 | - } | ||
| 129 | - | ||
| 130 | - Map<Link, Set<ResourceAllocation>> allocations = new HashMap<>(); | ||
| 131 | - for (Link link : req.links()) { | ||
| 132 | - allocations.put(link, new HashSet<>(allocs)); | ||
| 133 | - Set<ResourceAllocation> linkAllocs = allocsPerLink.get(link); | ||
| 134 | - if (linkAllocs != null) { | ||
| 135 | - allocations.get(link).addAll(linkAllocs); | ||
| 136 | - } | ||
| 137 | - } | ||
| 138 | - LinkResourceAllocations result = | ||
| 139 | - new DefaultLinkResourceAllocations(req, allocations); | ||
| 140 | - store.allocateResources(result); | ||
| 141 | - return result; | ||
| 142 | - | ||
| 143 | - } | ||
| 144 | - | ||
| 145 | - @Override | ||
| 146 | - public void releaseResources(LinkResourceAllocations allocations) { | ||
| 147 | - checkPermission(LINK_WRITE); | ||
| 148 | - final LinkResourceEvent event = store.releaseResources(allocations); | ||
| 149 | - if (event != null) { | ||
| 150 | - post(event); | ||
| 151 | - } | ||
| 152 | - } | ||
| 153 | - | ||
| 154 | - @Override | ||
| 155 | - public LinkResourceAllocations updateResources(LinkResourceRequest req, | ||
| 156 | - LinkResourceAllocations oldAllocations) { | ||
| 157 | - checkPermission(LINK_WRITE); | ||
| 158 | - releaseResources(oldAllocations); | ||
| 159 | - return requestResources(req); | ||
| 160 | - } | ||
| 161 | - | ||
| 162 | - @Override | ||
| 163 | - public Iterable<LinkResourceAllocations> getAllocations() { | ||
| 164 | - checkPermission(LINK_READ); | ||
| 165 | - return store.getAllocations(); | ||
| 166 | - } | ||
| 167 | - | ||
| 168 | - @Override | ||
| 169 | - public Iterable<LinkResourceAllocations> getAllocations(Link link) { | ||
| 170 | - checkPermission(LINK_READ); | ||
| 171 | - return store.getAllocations(link); | ||
| 172 | - } | ||
| 173 | - | ||
| 174 | - @Override | ||
| 175 | - public LinkResourceAllocations getAllocations(IntentId intentId) { | ||
| 176 | - checkPermission(LINK_READ); | ||
| 177 | - return store.getAllocations(intentId); | ||
| 178 | - } | ||
| 179 | - | ||
| 180 | - @Override | ||
| 181 | - public Iterable<ResourceRequest> getAvailableResources(Link link) { | ||
| 182 | - checkPermission(LINK_READ); | ||
| 183 | - | ||
| 184 | - Set<ResourceAllocation> freeRes = store.getFreeResources(link); | ||
| 185 | - Set<ResourceRequest> result = new HashSet<>(); | ||
| 186 | - for (ResourceAllocation alloc : freeRes) { | ||
| 187 | - switch (alloc.type()) { | ||
| 188 | - case BANDWIDTH: | ||
| 189 | - result.add(new BandwidthResourceRequest( | ||
| 190 | - ((BandwidthResourceAllocation) alloc).bandwidth())); | ||
| 191 | - break; | ||
| 192 | - case LAMBDA: | ||
| 193 | - result.add(new LambdaResourceRequest( | ||
| 194 | - ((LambdaResourceAllocation) alloc).lambda())); | ||
| 195 | - break; | ||
| 196 | - case MPLS_LABEL: | ||
| 197 | - result.add(new MplsLabelResourceRequest( | ||
| 198 | - ((MplsLabelResourceAllocation) alloc).mplsLabel())); | ||
| 199 | - break; | ||
| 200 | - default: | ||
| 201 | - break; | ||
| 202 | - } | ||
| 203 | - } | ||
| 204 | - return result; | ||
| 205 | - } | ||
| 206 | - | ||
| 207 | - @Override | ||
| 208 | - public Iterable<ResourceRequest> getAvailableResources(Link link, | ||
| 209 | - LinkResourceAllocations allocations) { | ||
| 210 | - checkPermission(LINK_READ); | ||
| 211 | - | ||
| 212 | - Set<ResourceAllocation> allocatedRes = allocations.getResourceAllocation(link); | ||
| 213 | - Set<ResourceRequest> result = Sets.newHashSet(getAvailableResources(link)); | ||
| 214 | - result.removeAll(allocatedRes); | ||
| 215 | - return result; | ||
| 216 | - } | ||
| 217 | - | ||
| 218 | - /** | ||
| 219 | - * Store delegate to re-post events emitted from the store. | ||
| 220 | - */ | ||
| 221 | - private class InternalStoreDelegate implements LinkResourceStoreDelegate { | ||
| 222 | - @Override | ||
| 223 | - public void notify(LinkResourceEvent event) { | ||
| 224 | - post(event); | ||
| 225 | - } | ||
| 226 | - } | ||
| 227 | -} |
-
Please register or login to post a comment