blob: d12539984942faa77fb20df2f7ac93699aac4ca1 [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.LinkResourceAllocations;
27import org.onosproject.net.resource.LinkResourceService;
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-allocations",
38 description = "Lists allocations by link")
39public class ResourceAllocationsCommand 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<LinkResourceAllocations> 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.getAllocations(link);
69
70 for (LinkResourceAllocations allocation : itr) {
71 print("%s", allocation.getResourceAllocation(link));
72 }
73
74 } catch (Exception e) {
75 print("----- Displaying all resource allocations -----", e.getMessage());
76 itr = resourceService.getAllocations();
77 for (LinkResourceAllocations allocation : itr) {
78 print("%s", allocation);
79 }
80
81 }
82 }
83}