blob: c3b0c839b4490e31c727427c6b5b5d7339454ad1 [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'Connorabafb502014-12-02 22:26:20 -080024import org.onosproject.net.resource.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.
Brian O'Connorfe0f4b12014-10-30 21:19:02 -070028 */
29@Command(scope = "onos", name = "resource-allocations",
Ayaka Koshibee114f042015-05-01 11:43:00 -070030 description = "Lists allocations by link. Lists all allocations if link is unspecified.")
Brian O'Connorfe0f4b12014-10-30 21:19:02 -070031public class ResourceAllocationsCommand extends AbstractShellCommand {
32
33 private static final String FMT = "src=%s/%s, dst=%s/%s, type=%s%s";
34 private static final String COMPACT = "%s/%s-%s/%s";
35
36 @Argument(index = 0, name = "srcString", description = "Link source",
37 required = false, multiValued = false)
38 String srcString = null;
39 @Argument(index = 1, name = "dstString", description = "Link destination",
40 required = false, multiValued = false)
41 String dstString = null;
42
43 @Override
44 protected void execute() {
45 LinkResourceService resourceService = get(LinkResourceService.class);
46 LinkService linkService = get(LinkService.class);
47
Ayaka Koshibee114f042015-05-01 11:43:00 -070048 if (srcString == null || dstString == null) {
49 print("----- Displaying all resource allocations -----");
50 resourceService.getAllocations().forEach(alloc -> print("%s", alloc));
51 return;
52 }
Brian O'Connorfe0f4b12014-10-30 21:19:02 -070053
Ayaka Koshibee114f042015-05-01 11:43:00 -070054 ConnectPoint src = ConnectPoint.deviceConnectPoint(srcString);
55 ConnectPoint dst = ConnectPoint.deviceConnectPoint(dstString);
Brian O'Connorfe0f4b12014-10-30 21:19:02 -070056
Ayaka Koshibee114f042015-05-01 11:43:00 -070057 Link link = linkService.getLink(src, dst);
58 if (link != null) {
59 resourceService.getAllocations(link).forEach(alloc -> print("%s", alloc));
60 } else {
61 print("No path found for endpoints: %s, %s", src, dst);
Brian O'Connorfe0f4b12014-10-30 21:19:02 -070062 }
63 }
64}