blob: ab0d39585fd9e4084ea5f38d4de4e5cdc59b97bf [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'Connorabafb502014-12-02 22:26:20 -080025import org.onosproject.net.resource.ResourceRequest;
Brian O'Connorfe0f4b12014-10-30 21:19:02 -070026
Brian O'Connorfe0f4b12014-10-30 21:19:02 -070027/**
28 * Lists allocations by link.
29 */
30@Command(scope = "onos", name = "resource-available",
31 description = "Lists available resources by link")
32public class ResourceAvailableCommand extends AbstractShellCommand {
33
34 private static final String FMT = "src=%s/%s, dst=%s/%s, type=%s%s";
35 private static final String COMPACT = "%s/%s-%s/%s";
36
37 @Argument(index = 0, name = "srcString", description = "Link source",
38 required = false, multiValued = false)
39 String srcString = null;
40 @Argument(index = 1, name = "dstString", description = "Link destination",
41 required = false, multiValued = false)
42 String dstString = null;
43
44 @Override
45 protected void execute() {
46 LinkResourceService resourceService = get(LinkResourceService.class);
47 LinkService linkService = get(LinkService.class);
48
49 Iterable<ResourceRequest> itr = null;
50 try {
Jonathan Hartc3af35a2015-04-30 22:20:29 -070051 ConnectPoint src = ConnectPoint.deviceConnectPoint(srcString);
Brian O'Connorfe0f4b12014-10-30 21:19:02 -070052
Jonathan Hartc3af35a2015-04-30 22:20:29 -070053 ConnectPoint dst = ConnectPoint.deviceConnectPoint(dstString);
Brian O'Connorfe0f4b12014-10-30 21:19:02 -070054
55 Link link = linkService.getLink(src, dst);
56
57 itr = resourceService.getAvailableResources(link);
58
59 int lambdaCount = 0;
60 for (ResourceRequest req : itr) {
61 switch (req.type()) {
62 case LAMBDA:
63 lambdaCount++;
64 break;
65 case BANDWIDTH:
66 print("%s", req);
67 break;
68 default:
69 break;
70 }
71 }
72 if (lambdaCount > 0) {
73 print("Number of available lambdas: %d", lambdaCount);
74 }
75
76 } catch (Exception e) {
Yuta HIGUCHI6b38ee32014-11-14 02:02:59 -080077 print("Invalid link %s", e.getMessage());
Brian O'Connorfe0f4b12014-10-30 21:19:02 -070078 }
79 }
80}