blob: cb5ba424a550f480aec754f1d32f39c7592bd151 [file] [log] [blame]
Jonathan Hart32600692015-03-09 10:38:40 -07001/*
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 */
16package org.onosproject.cli.net;
17
18import org.apache.karaf.shell.commands.Command;
19import org.onosproject.cli.AbstractShellCommand;
20import org.onosproject.net.DeviceId;
21import org.onosproject.net.device.DeviceService;
22import org.onosproject.net.group.Group;
23import 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")
30public 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}