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 | fe0f4b1 | 2014-10-30 21:19:02 -0700 | [diff] [blame] | 25 | |
Brian O'Connor | fe0f4b1 | 2014-10-30 21:19:02 -0700 | [diff] [blame] | 26 | /** |
Ayaka Koshibe | e114f04 | 2015-05-01 11:43:00 -0700 | [diff] [blame] | 27 | * Lists allocations by link. Lists all allocations if link is unspecified. |
HIGUCHI Yuta | 14869be | 2015-12-08 13:22:33 -0800 | [diff] [blame] | 28 | * |
| 29 | * @deprecated in Emu release |
Brian O'Connor | fe0f4b1 | 2014-10-30 21:19:02 -0700 | [diff] [blame] | 30 | */ |
HIGUCHI Yuta | 14869be | 2015-12-08 13:22:33 -0800 | [diff] [blame] | 31 | @Deprecated |
Brian O'Connor | fe0f4b1 | 2014-10-30 21:19:02 -0700 | [diff] [blame] | 32 | @Command(scope = "onos", name = "resource-allocations", |
HIGUCHI Yuta | 14869be | 2015-12-08 13:22:33 -0800 | [diff] [blame] | 33 | description = "Lists allocations by link. Lists all allocations if link is unspecified." |
| 34 | + "[Using deprecated LinkResourceService]") |
Brian O'Connor | fe0f4b1 | 2014-10-30 21:19:02 -0700 | [diff] [blame] | 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 | |
Ayaka Koshibe | e114f04 | 2015-05-01 11:43:00 -0700 | [diff] [blame] | 52 | if (srcString == null || dstString == null) { |
| 53 | print("----- Displaying all resource allocations -----"); |
| 54 | resourceService.getAllocations().forEach(alloc -> print("%s", alloc)); |
| 55 | return; |
| 56 | } |
Brian O'Connor | fe0f4b1 | 2014-10-30 21:19:02 -0700 | [diff] [blame] | 57 | |
Ayaka Koshibe | e114f04 | 2015-05-01 11:43:00 -0700 | [diff] [blame] | 58 | ConnectPoint src = ConnectPoint.deviceConnectPoint(srcString); |
| 59 | ConnectPoint dst = ConnectPoint.deviceConnectPoint(dstString); |
Brian O'Connor | fe0f4b1 | 2014-10-30 21:19:02 -0700 | [diff] [blame] | 60 | |
Ayaka Koshibe | e114f04 | 2015-05-01 11:43:00 -0700 | [diff] [blame] | 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); |
Brian O'Connor | fe0f4b1 | 2014-10-30 21:19:02 -0700 | [diff] [blame] | 66 | } |
| 67 | } |
| 68 | } |