Brian O'Connor | fe0f4b1 | 2014-10-30 21:19:02 -0700 | [diff] [blame] | 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 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.cli.net; |
Brian O'Connor | fe0f4b1 | 2014-10-30 21:19:02 -0700 | [diff] [blame] | 17 | |
| 18 | import org.apache.karaf.shell.commands.Argument; |
| 19 | import org.apache.karaf.shell.commands.Command; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 20 | import org.onosproject.cli.AbstractShellCommand; |
| 21 | import org.onosproject.net.ConnectPoint; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 22 | import org.onosproject.net.Link; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 23 | import org.onosproject.net.link.LinkService; |
Brian O'Connor | 6de2e20 | 2015-05-21 14:30:41 -0700 | [diff] [blame] | 24 | import org.onosproject.net.resource.link.LinkResourceService; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 25 | import org.onosproject.net.resource.ResourceRequest; |
Brian O'Connor | fe0f4b1 | 2014-10-30 21:19:02 -0700 | [diff] [blame] | 26 | |
Brian O'Connor | fe0f4b1 | 2014-10-30 21:19:02 -0700 | [diff] [blame] | 27 | /** |
| 28 | * Lists allocations by link. |
HIGUCHI Yuta | 14869be | 2015-12-08 13:22:33 -0800 | [diff] [blame] | 29 | * |
| 30 | * @deprecated in Emu release |
Brian O'Connor | fe0f4b1 | 2014-10-30 21:19:02 -0700 | [diff] [blame] | 31 | */ |
HIGUCHI Yuta | 14869be | 2015-12-08 13:22:33 -0800 | [diff] [blame] | 32 | @Deprecated |
Brian O'Connor | fe0f4b1 | 2014-10-30 21:19:02 -0700 | [diff] [blame] | 33 | @Command(scope = "onos", name = "resource-available", |
HIGUCHI Yuta | 14869be | 2015-12-08 13:22:33 -0800 | [diff] [blame] | 34 | description = "Lists available resources by link" |
| 35 | + "[Using deprecated LinkResourceService]") |
Brian O'Connor | fe0f4b1 | 2014-10-30 21:19:02 -0700 | [diff] [blame] | 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 { |
Jonathan Hart | c3af35a | 2015-04-30 22:20:29 -0700 | [diff] [blame] | 55 | ConnectPoint src = ConnectPoint.deviceConnectPoint(srcString); |
Brian O'Connor | fe0f4b1 | 2014-10-30 21:19:02 -0700 | [diff] [blame] | 56 | |
Jonathan Hart | c3af35a | 2015-04-30 22:20:29 -0700 | [diff] [blame] | 57 | ConnectPoint dst = ConnectPoint.deviceConnectPoint(dstString); |
Brian O'Connor | fe0f4b1 | 2014-10-30 21:19:02 -0700 | [diff] [blame] | 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) { |
Yuta HIGUCHI | 6b38ee3 | 2014-11-14 02:02:59 -0800 | [diff] [blame] | 81 | print("Invalid link %s", e.getMessage()); |
Brian O'Connor | fe0f4b1 | 2014-10-30 21:19:02 -0700 | [diff] [blame] | 82 | } |
| 83 | } |
| 84 | } |