Adding resource-{available,allocated} CLI commands and lots of toStrings
Change-Id: Ib23eda2d9feb523e23dc33fb437994267b4cc555
Showing
10 changed files
with
245 additions
and
9 deletions
... | @@ -74,7 +74,7 @@ public class AddPointToPointIntentCommand extends ConnectivityIntentCommand { | ... | @@ -74,7 +74,7 @@ public class AddPointToPointIntentCommand extends ConnectivityIntentCommand { |
74 | * @param deviceString string representing the device/port | 74 | * @param deviceString string representing the device/port |
75 | * @return port number as a string, empty string if the port is not found | 75 | * @return port number as a string, empty string if the port is not found |
76 | */ | 76 | */ |
77 | - private String getPortNumber(String deviceString) { | 77 | + public static String getPortNumber(String deviceString) { |
78 | int slash = deviceString.indexOf('/'); | 78 | int slash = deviceString.indexOf('/'); |
79 | if (slash <= 0) { | 79 | if (slash <= 0) { |
80 | return ""; | 80 | return ""; |
... | @@ -88,7 +88,7 @@ public class AddPointToPointIntentCommand extends ConnectivityIntentCommand { | ... | @@ -88,7 +88,7 @@ public class AddPointToPointIntentCommand extends ConnectivityIntentCommand { |
88 | * @param deviceString string representing the device/port | 88 | * @param deviceString string representing the device/port |
89 | * @return device ID string | 89 | * @return device ID string |
90 | */ | 90 | */ |
91 | - private String getDeviceId(String deviceString) { | 91 | + public static String getDeviceId(String deviceString) { |
92 | int slash = deviceString.indexOf('/'); | 92 | int slash = deviceString.indexOf('/'); |
93 | if (slash <= 0) { | 93 | if (slash <= 0) { |
94 | return ""; | 94 | return ""; | ... | ... |
... | @@ -20,6 +20,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; | ... | @@ -20,6 +20,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; |
20 | import com.fasterxml.jackson.databind.node.ArrayNode; | 20 | import com.fasterxml.jackson.databind.node.ArrayNode; |
21 | import com.fasterxml.jackson.databind.node.ObjectNode; | 21 | import com.fasterxml.jackson.databind.node.ObjectNode; |
22 | import org.apache.karaf.shell.commands.Command; | 22 | import org.apache.karaf.shell.commands.Command; |
23 | +import org.apache.karaf.shell.commands.Option; | ||
23 | import org.onlab.onos.cli.AbstractShellCommand; | 24 | import org.onlab.onos.cli.AbstractShellCommand; |
24 | import org.onlab.onos.net.ConnectPoint; | 25 | import org.onlab.onos.net.ConnectPoint; |
25 | import org.onlab.onos.net.Link; | 26 | import org.onlab.onos.net.Link; |
... | @@ -44,6 +45,11 @@ import java.util.Set; | ... | @@ -44,6 +45,11 @@ import java.util.Set; |
44 | description = "Lists the inventory of intents and their states") | 45 | description = "Lists the inventory of intents and their states") |
45 | public class IntentsListCommand extends AbstractShellCommand { | 46 | public class IntentsListCommand extends AbstractShellCommand { |
46 | 47 | ||
48 | + @Option(name = "-i", aliases = "--installable", description = "Output Installable Intents", | ||
49 | + required = false, multiValued = false) | ||
50 | + private boolean showInstallable = false; | ||
51 | + | ||
52 | + | ||
47 | @Override | 53 | @Override |
48 | protected void execute() { | 54 | protected void execute() { |
49 | IntentService service = get(IntentService.class); | 55 | IntentService service = get(IntentService.class); |
... | @@ -93,7 +99,7 @@ public class IntentsListCommand extends AbstractShellCommand { | ... | @@ -93,7 +99,7 @@ public class IntentsListCommand extends AbstractShellCommand { |
93 | } | 99 | } |
94 | 100 | ||
95 | List<Intent> installable = service.getInstallableIntents(intent.id()); | 101 | List<Intent> installable = service.getInstallableIntents(intent.id()); |
96 | - if (installable != null && !installable.isEmpty()) { | 102 | + if (showInstallable && installable != null && !installable.isEmpty()) { |
97 | print(" installable=%s", installable); | 103 | print(" installable=%s", installable); |
98 | } | 104 | } |
99 | } | 105 | } | ... | ... |
1 | +/* | ||
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 | + */ | ||
16 | +package org.onlab.onos.cli.net; | ||
17 | + | ||
18 | +import org.apache.karaf.shell.commands.Argument; | ||
19 | +import org.apache.karaf.shell.commands.Command; | ||
20 | +import org.onlab.onos.cli.AbstractShellCommand; | ||
21 | +import org.onlab.onos.net.ConnectPoint; | ||
22 | +import org.onlab.onos.net.DeviceId; | ||
23 | +import org.onlab.onos.net.Link; | ||
24 | +import org.onlab.onos.net.PortNumber; | ||
25 | +import org.onlab.onos.net.link.LinkService; | ||
26 | +import org.onlab.onos.net.resource.LinkResourceAllocations; | ||
27 | +import org.onlab.onos.net.resource.LinkResourceService; | ||
28 | + | ||
29 | +import static org.onlab.onos.cli.net.AddPointToPointIntentCommand.getDeviceId; | ||
30 | +import static org.onlab.onos.cli.net.AddPointToPointIntentCommand.getPortNumber; | ||
31 | +import static org.onlab.onos.net.DeviceId.deviceId; | ||
32 | +import static org.onlab.onos.net.PortNumber.portNumber; | ||
33 | + | ||
34 | +/** | ||
35 | + * Lists allocations by link. | ||
36 | + */ | ||
37 | +@Command(scope = "onos", name = "resource-allocations", | ||
38 | + description = "Lists allocations by link") | ||
39 | +public 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 | +} |
1 | +/* | ||
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 | + */ | ||
16 | +package org.onlab.onos.cli.net; | ||
17 | + | ||
18 | +import org.apache.karaf.shell.commands.Argument; | ||
19 | +import org.apache.karaf.shell.commands.Command; | ||
20 | +import org.onlab.onos.cli.AbstractShellCommand; | ||
21 | +import org.onlab.onos.net.ConnectPoint; | ||
22 | +import org.onlab.onos.net.DeviceId; | ||
23 | +import org.onlab.onos.net.Link; | ||
24 | +import org.onlab.onos.net.PortNumber; | ||
25 | +import org.onlab.onos.net.link.LinkService; | ||
26 | +import org.onlab.onos.net.resource.LinkResourceService; | ||
27 | +import org.onlab.onos.net.resource.ResourceRequest; | ||
28 | + | ||
29 | +import static org.onlab.onos.cli.net.AddPointToPointIntentCommand.getDeviceId; | ||
30 | +import static org.onlab.onos.cli.net.AddPointToPointIntentCommand.getPortNumber; | ||
31 | +import static org.onlab.onos.net.DeviceId.deviceId; | ||
32 | +import static org.onlab.onos.net.PortNumber.portNumber; | ||
33 | + | ||
34 | +/** | ||
35 | + * Lists allocations by link. | ||
36 | + */ | ||
37 | +@Command(scope = "onos", name = "resource-available", | ||
38 | + description = "Lists available resources by link") | ||
39 | +public 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) { | ||
88 | + print("Invalid link", e.getMessage()); | ||
89 | + } | ||
90 | + } | ||
91 | +} |
... | @@ -158,7 +158,22 @@ | ... | @@ -158,7 +158,22 @@ |
158 | <null/> | 158 | <null/> |
159 | </completers> | 159 | </completers> |
160 | </command> | 160 | </command> |
161 | - | 161 | + <command> |
162 | + <action class="org.onlab.onos.cli.net.ResourceAllocationsCommand"/> | ||
163 | + <completers> | ||
164 | + <ref component-id="connectPointCompleter"/> | ||
165 | + <ref component-id="connectPointCompleter"/> | ||
166 | + <null/> | ||
167 | + </completers> | ||
168 | + </command> | ||
169 | + <command> | ||
170 | + <action class="org.onlab.onos.cli.net.ResourceAvailableCommand"/> | ||
171 | + <completers> | ||
172 | + <ref component-id="connectPointCompleter"/> | ||
173 | + <ref component-id="connectPointCompleter"/> | ||
174 | + <null/> | ||
175 | + </completers> | ||
176 | + </command> | ||
162 | <command> | 177 | <command> |
163 | <action class="org.onlab.onos.cli.net.ClustersListCommand"/> | 178 | <action class="org.onlab.onos.cli.net.ClustersListCommand"/> |
164 | </command> | 179 | </command> | ... | ... |
... | @@ -15,6 +15,8 @@ | ... | @@ -15,6 +15,8 @@ |
15 | */ | 15 | */ |
16 | package org.onlab.onos.net.resource; | 16 | package org.onlab.onos.net.resource; |
17 | 17 | ||
18 | +import com.google.common.base.MoreObjects; | ||
19 | + | ||
18 | /** | 20 | /** |
19 | * Representation of allocated bandwidth resource. | 21 | * Representation of allocated bandwidth resource. |
20 | */ | 22 | */ |
... | @@ -35,4 +37,11 @@ public class BandwidthResourceAllocation extends BandwidthResourceRequest | ... | @@ -35,4 +37,11 @@ public class BandwidthResourceAllocation extends BandwidthResourceRequest |
35 | public BandwidthResourceAllocation(Bandwidth bandwidth) { | 37 | public BandwidthResourceAllocation(Bandwidth bandwidth) { |
36 | super(bandwidth); | 38 | super(bandwidth); |
37 | } | 39 | } |
40 | + | ||
41 | + @Override | ||
42 | + public String toString() { | ||
43 | + return MoreObjects.toStringHelper(this) | ||
44 | + .add("bandwidth", bandwidth()) | ||
45 | + .toString(); | ||
46 | + } | ||
38 | } | 47 | } | ... | ... |
... | @@ -15,6 +15,8 @@ | ... | @@ -15,6 +15,8 @@ |
15 | */ | 15 | */ |
16 | package org.onlab.onos.net.resource; | 16 | package org.onlab.onos.net.resource; |
17 | 17 | ||
18 | +import com.google.common.base.MoreObjects; | ||
19 | + | ||
18 | /** | 20 | /** |
19 | * Representation of a request for bandwidth resource. | 21 | * Representation of a request for bandwidth resource. |
20 | */ | 22 | */ |
... | @@ -53,4 +55,11 @@ public class BandwidthResourceRequest implements ResourceRequest { | ... | @@ -53,4 +55,11 @@ public class BandwidthResourceRequest implements ResourceRequest { |
53 | public ResourceType type() { | 55 | public ResourceType type() { |
54 | return ResourceType.BANDWIDTH; | 56 | return ResourceType.BANDWIDTH; |
55 | } | 57 | } |
58 | + | ||
59 | + @Override | ||
60 | + public String toString() { | ||
61 | + return MoreObjects.toStringHelper(this) | ||
62 | + .add("bandwidth", bandwidth) | ||
63 | + .toString(); | ||
64 | + } | ||
56 | } | 65 | } | ... | ... |
... | @@ -15,6 +15,8 @@ | ... | @@ -15,6 +15,8 @@ |
15 | */ | 15 | */ |
16 | package org.onlab.onos.net.resource; | 16 | package org.onlab.onos.net.resource; |
17 | 17 | ||
18 | +import com.google.common.base.MoreObjects; | ||
19 | + | ||
18 | import java.util.Objects; | 20 | import java.util.Objects; |
19 | 21 | ||
20 | /** | 22 | /** |
... | @@ -64,4 +66,11 @@ public class LambdaResourceAllocation extends LambdaResourceRequest | ... | @@ -64,4 +66,11 @@ public class LambdaResourceAllocation extends LambdaResourceRequest |
64 | final LambdaResourceAllocation other = (LambdaResourceAllocation) obj; | 66 | final LambdaResourceAllocation other = (LambdaResourceAllocation) obj; |
65 | return Objects.equals(this.lambda, other.lambda); | 67 | return Objects.equals(this.lambda, other.lambda); |
66 | } | 68 | } |
69 | + | ||
70 | + @Override | ||
71 | + public String toString() { | ||
72 | + return MoreObjects.toStringHelper(this) | ||
73 | + .add("lambda", lambda) | ||
74 | + .toString(); | ||
75 | + } | ||
67 | } | 76 | } | ... | ... |
... | @@ -15,6 +15,8 @@ | ... | @@ -15,6 +15,8 @@ |
15 | */ | 15 | */ |
16 | package org.onlab.onos.net.resource; | 16 | package org.onlab.onos.net.resource; |
17 | 17 | ||
18 | +import com.google.common.base.MoreObjects; | ||
19 | + | ||
18 | /** | 20 | /** |
19 | * Representation of a request for lambda resource. | 21 | * Representation of a request for lambda resource. |
20 | */ | 22 | */ |
... | @@ -25,4 +27,9 @@ public class LambdaResourceRequest implements ResourceRequest { | ... | @@ -25,4 +27,9 @@ public class LambdaResourceRequest implements ResourceRequest { |
25 | return ResourceType.LAMBDA; | 27 | return ResourceType.LAMBDA; |
26 | } | 28 | } |
27 | 29 | ||
30 | + @Override | ||
31 | + public String toString() { | ||
32 | + return MoreObjects.toStringHelper(this) | ||
33 | + .toString(); | ||
34 | + } | ||
28 | } | 35 | } | ... | ... |
... | @@ -15,11 +15,7 @@ | ... | @@ -15,11 +15,7 @@ |
15 | */ | 15 | */ |
16 | package org.onlab.onos.net.resource.impl; | 16 | package org.onlab.onos.net.resource.impl; |
17 | 17 | ||
18 | -import java.util.Collection; | 18 | +import com.google.common.base.MoreObjects; |
19 | -import java.util.Collections; | ||
20 | -import java.util.Map; | ||
21 | -import java.util.Set; | ||
22 | - | ||
23 | import org.onlab.onos.net.Link; | 19 | import org.onlab.onos.net.Link; |
24 | import org.onlab.onos.net.intent.IntentId; | 20 | import org.onlab.onos.net.intent.IntentId; |
25 | import org.onlab.onos.net.resource.LinkResourceAllocations; | 21 | import org.onlab.onos.net.resource.LinkResourceAllocations; |
... | @@ -28,6 +24,11 @@ import org.onlab.onos.net.resource.ResourceAllocation; | ... | @@ -28,6 +24,11 @@ import org.onlab.onos.net.resource.ResourceAllocation; |
28 | import org.onlab.onos.net.resource.ResourceRequest; | 24 | import org.onlab.onos.net.resource.ResourceRequest; |
29 | import org.onlab.onos.net.resource.ResourceType; | 25 | import org.onlab.onos.net.resource.ResourceType; |
30 | 26 | ||
27 | +import java.util.Collection; | ||
28 | +import java.util.Collections; | ||
29 | +import java.util.Map; | ||
30 | +import java.util.Set; | ||
31 | + | ||
31 | /** | 32 | /** |
32 | * Implementation of {@link LinkResourceAllocations}. | 33 | * Implementation of {@link LinkResourceAllocations}. |
33 | */ | 34 | */ |
... | @@ -76,4 +77,10 @@ public class DefaultLinkResourceAllocations implements LinkResourceAllocations { | ... | @@ -76,4 +77,10 @@ public class DefaultLinkResourceAllocations implements LinkResourceAllocations { |
76 | return result; | 77 | return result; |
77 | } | 78 | } |
78 | 79 | ||
80 | + @Override | ||
81 | + public String toString() { | ||
82 | + return MoreObjects.toStringHelper(this) | ||
83 | + .add("allocations", allocations) | ||
84 | + .toString(); | ||
85 | + } | ||
79 | } | 86 | } | ... | ... |
-
Please register or login to post a comment