blob: 65416b248088974223096fd83493914afd583333 [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;
22import org.onosproject.net.DeviceId;
23import org.onosproject.net.Link;
24import org.onosproject.net.PortNumber;
25import org.onosproject.net.link.LinkService;
26import org.onosproject.net.resource.LinkResourceService;
27import org.onosproject.net.resource.ResourceRequest;
Brian O'Connorfe0f4b12014-10-30 21:19:02 -070028
Brian O'Connorabafb502014-12-02 22:26:20 -080029import static org.onosproject.cli.net.AddPointToPointIntentCommand.getDeviceId;
30import static org.onosproject.cli.net.AddPointToPointIntentCommand.getPortNumber;
31import static org.onosproject.net.DeviceId.deviceId;
32import static org.onosproject.net.PortNumber.portNumber;
Brian O'Connorfe0f4b12014-10-30 21:19:02 -070033
34/**
35 * Lists allocations by link.
36 */
37@Command(scope = "onos", name = "resource-available",
38 description = "Lists available resources by link")
39public class ResourceAvailableCommand extends AbstractShellCommand {
40
41 private static final String FMT = "src=%s/%s, dst=%s/%s, type=%s%s";
42 private static final String COMPACT = "%s/%s-%s/%s";
43
44 @Argument(index = 0, name = "srcString", description = "Link source",
45 required = false, multiValued = false)
46 String srcString = null;
47 @Argument(index = 1, name = "dstString", description = "Link destination",
48 required = false, multiValued = false)
49 String dstString = null;
50
51 @Override
52 protected void execute() {
53 LinkResourceService resourceService = get(LinkResourceService.class);
54 LinkService linkService = get(LinkService.class);
55
56 Iterable<ResourceRequest> itr = null;
57 try {
58 DeviceId ingressDeviceId = deviceId(getDeviceId(srcString));
59 PortNumber ingressPortNumber = portNumber(getPortNumber(srcString));
60 ConnectPoint src = new ConnectPoint(ingressDeviceId, ingressPortNumber);
61
62 DeviceId egressDeviceId = deviceId(getDeviceId(dstString));
63 PortNumber egressPortNumber = portNumber(getPortNumber(dstString));
64 ConnectPoint dst = new ConnectPoint(egressDeviceId, egressPortNumber);
65
66 Link link = linkService.getLink(src, dst);
67
68 itr = resourceService.getAvailableResources(link);
69
70 int lambdaCount = 0;
71 for (ResourceRequest req : itr) {
72 switch (req.type()) {
73 case LAMBDA:
74 lambdaCount++;
75 break;
76 case BANDWIDTH:
77 print("%s", req);
78 break;
79 default:
80 break;
81 }
82 }
83 if (lambdaCount > 0) {
84 print("Number of available lambdas: %d", lambdaCount);
85 }
86
87 } catch (Exception e) {
Yuta HIGUCHI6b38ee32014-11-14 02:02:59 -080088 print("Invalid link %s", e.getMessage());
Brian O'Connorfe0f4b12014-10-30 21:19:02 -070089 }
90 }
91}