blob: 968781f1c631b33825d52bde41930873909724d3 [file] [log] [blame]
Brian O'Connorfe0f4b12014-10-30 21:19:02 -07001/*
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'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.cli.net;
Brian O'Connorfe0f4b12014-10-30 21:19:02 -070017
18import org.apache.karaf.shell.commands.Argument;
19import org.apache.karaf.shell.commands.Command;
Brian O'Connorabafb502014-12-02 22:26:20 -080020import org.onosproject.cli.AbstractShellCommand;
21import org.onosproject.net.ConnectPoint;
Brian O'Connorabafb502014-12-02 22:26:20 -080022import org.onosproject.net.Link;
Brian O'Connorabafb502014-12-02 22:26:20 -080023import org.onosproject.net.link.LinkService;
Brian O'Connor6de2e202015-05-21 14:30:41 -070024import org.onosproject.net.resource.link.LinkResourceService;
Brian O'Connorfe0f4b12014-10-30 21:19:02 -070025
Brian O'Connorfe0f4b12014-10-30 21:19:02 -070026/**
Ayaka Koshibee114f042015-05-01 11:43:00 -070027 * Lists allocations by link. Lists all allocations if link is unspecified.
HIGUCHI Yuta14869be2015-12-08 13:22:33 -080028 *
29 * @deprecated in Emu release
Brian O'Connorfe0f4b12014-10-30 21:19:02 -070030 */
HIGUCHI Yuta14869be2015-12-08 13:22:33 -080031@Deprecated
Brian O'Connorfe0f4b12014-10-30 21:19:02 -070032@Command(scope = "onos", name = "resource-allocations",
HIGUCHI Yuta14869be2015-12-08 13:22:33 -080033 description = "Lists allocations by link. Lists all allocations if link is unspecified."
34 + "[Using deprecated LinkResourceService]")
Brian O'Connorfe0f4b12014-10-30 21:19:02 -070035public 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 Koshibee114f042015-05-01 11:43:00 -070052 if (srcString == null || dstString == null) {
53 print("----- Displaying all resource allocations -----");
54 resourceService.getAllocations().forEach(alloc -> print("%s", alloc));
55 return;
56 }
Brian O'Connorfe0f4b12014-10-30 21:19:02 -070057
Ayaka Koshibee114f042015-05-01 11:43:00 -070058 ConnectPoint src = ConnectPoint.deviceConnectPoint(srcString);
59 ConnectPoint dst = ConnectPoint.deviceConnectPoint(dstString);
Brian O'Connorfe0f4b12014-10-30 21:19:02 -070060
Ayaka Koshibee114f042015-05-01 11:43:00 -070061 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'Connorfe0f4b12014-10-30 21:19:02 -070066 }
67 }
68}