blob: 007eb12482c77dfa622cf8dff2dc46ec63eb118f [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.
HIGUCHI Yuta14869be2015-12-08 13:22:33 -080029 *
30 * @deprecated in Emu release
Brian O'Connorfe0f4b12014-10-30 21:19:02 -070031 */
HIGUCHI Yuta14869be2015-12-08 13:22:33 -080032@Deprecated
Brian O'Connorfe0f4b12014-10-30 21:19:02 -070033@Command(scope = "onos", name = "resource-available",
HIGUCHI Yuta14869be2015-12-08 13:22:33 -080034 description = "Lists available resources by link"
35 + "[Using deprecated LinkResourceService]")
Brian O'Connorfe0f4b12014-10-30 21:19:02 -070036public 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 Hartc3af35a2015-04-30 22:20:29 -070055 ConnectPoint src = ConnectPoint.deviceConnectPoint(srcString);
Brian O'Connorfe0f4b12014-10-30 21:19:02 -070056
Jonathan Hartc3af35a2015-04-30 22:20:29 -070057 ConnectPoint dst = ConnectPoint.deviceConnectPoint(dstString);
Brian O'Connorfe0f4b12014-10-30 21:19:02 -070058
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 HIGUCHI6b38ee32014-11-14 02:02:59 -080081 print("Invalid link %s", e.getMessage());
Brian O'Connorfe0f4b12014-10-30 21:19:02 -070082 }
83 }
84}