Committed by
Gerrit Code Review
Add CLI command to view groups on switches
Change-Id: I0ce3cca85e8b38d2e713bf1f0abd4303629e15e4
Showing
4 changed files
with
76 additions
and
8 deletions
1 | +/* | ||
2 | + * Copyright 2015 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.onosproject.cli.net; | ||
17 | + | ||
18 | +import org.apache.karaf.shell.commands.Command; | ||
19 | +import org.onosproject.cli.AbstractShellCommand; | ||
20 | +import org.onosproject.net.DeviceId; | ||
21 | +import org.onosproject.net.device.DeviceService; | ||
22 | +import org.onosproject.net.group.Group; | ||
23 | +import org.onosproject.net.group.GroupService; | ||
24 | + | ||
25 | +/** | ||
26 | + * Lists all groups in the system. | ||
27 | + */ | ||
28 | +@Command(scope = "onos", name = "groups", | ||
29 | + description = "Lists all groups in the system") | ||
30 | +public class GroupsListCommand extends AbstractShellCommand { | ||
31 | + | ||
32 | + private static final String FORMAT = | ||
33 | + " key=%s, id=%s, state=%s, bytes=%s, packets=%s, appId=%s, buckets=%s"; | ||
34 | + | ||
35 | + @Override | ||
36 | + protected void execute() { | ||
37 | + DeviceService deviceService = get(DeviceService.class); | ||
38 | + GroupService groupService = get(GroupService.class); | ||
39 | + | ||
40 | + deviceService.getDevices().forEach(d -> | ||
41 | + printGroups(d.id(), groupService.getGroups(d.id())) | ||
42 | + ); | ||
43 | + } | ||
44 | + | ||
45 | + private void printGroups(DeviceId deviceId, Iterable<Group> groups) { | ||
46 | + print("deviceId=%s", deviceId); | ||
47 | + for (Group group : groups) { | ||
48 | + print(FORMAT, group.appCookie(), group.id(), group.state(), | ||
49 | + group.bytes(), group.packets(), group.appId(), group.buckets()); | ||
50 | + } | ||
51 | + } | ||
52 | +} |
... | @@ -276,6 +276,10 @@ | ... | @@ -276,6 +276,10 @@ |
276 | </command> | 276 | </command> |
277 | 277 | ||
278 | <command> | 278 | <command> |
279 | + <action class="org.onosproject.cli.net.GroupsListCommand"/> | ||
280 | + </command> | ||
281 | + | ||
282 | + <command> | ||
279 | <action class="org.onosproject.cli.net.FlowsListCommand"/> | 283 | <action class="org.onosproject.cli.net.FlowsListCommand"/> |
280 | <completers> | 284 | <completers> |
281 | <ref component-id="flowRuleStatusCompleter"/> | 285 | <ref component-id="flowRuleStatusCompleter"/> | ... | ... |
... | @@ -127,6 +127,14 @@ public interface GroupService { | ... | @@ -127,6 +127,14 @@ public interface GroupService { |
127 | Iterable<Group> getGroups(DeviceId deviceId, ApplicationId appId); | 127 | Iterable<Group> getGroups(DeviceId deviceId, ApplicationId appId); |
128 | 128 | ||
129 | /** | 129 | /** |
130 | + * Returns all groups associated with the given device. | ||
131 | + * | ||
132 | + * @param deviceId device ID to get groups for | ||
133 | + * @return iterable of device's groups | ||
134 | + */ | ||
135 | + Iterable<Group> getGroups(DeviceId deviceId); | ||
136 | + | ||
137 | + /** | ||
130 | * Adds the specified group listener. | 138 | * Adds the specified group listener. |
131 | * | 139 | * |
132 | * @param listener group listener | 140 | * @param listener group listener | ... | ... |
... | @@ -15,13 +15,7 @@ | ... | @@ -15,13 +15,7 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.net.group.impl; | 16 | package org.onosproject.net.group.impl; |
17 | 17 | ||
18 | -import static org.slf4j.LoggerFactory.getLogger; | 18 | +import com.google.common.collect.Sets; |
19 | - | ||
20 | -import java.util.Arrays; | ||
21 | -import java.util.Collection; | ||
22 | -import java.util.Iterator; | ||
23 | -import java.util.Set; | ||
24 | - | ||
25 | import org.apache.felix.scr.annotations.Activate; | 19 | import org.apache.felix.scr.annotations.Activate; |
26 | import org.apache.felix.scr.annotations.Component; | 20 | import org.apache.felix.scr.annotations.Component; |
27 | import org.apache.felix.scr.annotations.Deactivate; | 21 | import org.apache.felix.scr.annotations.Deactivate; |
... | @@ -54,7 +48,12 @@ import org.onosproject.net.provider.AbstractProviderRegistry; | ... | @@ -54,7 +48,12 @@ import org.onosproject.net.provider.AbstractProviderRegistry; |
54 | import org.onosproject.net.provider.AbstractProviderService; | 48 | import org.onosproject.net.provider.AbstractProviderService; |
55 | import org.slf4j.Logger; | 49 | import org.slf4j.Logger; |
56 | 50 | ||
57 | -import com.google.common.collect.Sets; | 51 | +import java.util.Arrays; |
52 | +import java.util.Collection; | ||
53 | +import java.util.Iterator; | ||
54 | +import java.util.Set; | ||
55 | + | ||
56 | +import static org.slf4j.LoggerFactory.getLogger; | ||
58 | 57 | ||
59 | /** | 58 | /** |
60 | * Provides implementation of the group service APIs. | 59 | * Provides implementation of the group service APIs. |
... | @@ -206,6 +205,11 @@ public class GroupManager | ... | @@ -206,6 +205,11 @@ public class GroupManager |
206 | return store.getGroups(deviceId); | 205 | return store.getGroups(deviceId); |
207 | } | 206 | } |
208 | 207 | ||
208 | + @Override | ||
209 | + public Iterable<Group> getGroups(DeviceId deviceId) { | ||
210 | + return store.getGroups(deviceId); | ||
211 | + } | ||
212 | + | ||
209 | /** | 213 | /** |
210 | * Adds the specified group listener. | 214 | * Adds the specified group listener. |
211 | * | 215 | * | ... | ... |
-
Please register or login to post a comment