Jonathan Hart
Committed by Gerrit Code Review

Add CLI command to view groups on switches

Change-Id: I0ce3cca85e8b38d2e713bf1f0abd4303629e15e4
/*
* Copyright 2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.cli.net;
import org.apache.karaf.shell.commands.Command;
import org.onosproject.cli.AbstractShellCommand;
import org.onosproject.net.DeviceId;
import org.onosproject.net.device.DeviceService;
import org.onosproject.net.group.Group;
import org.onosproject.net.group.GroupService;
/**
* Lists all groups in the system.
*/
@Command(scope = "onos", name = "groups",
description = "Lists all groups in the system")
public class GroupsListCommand extends AbstractShellCommand {
private static final String FORMAT =
" key=%s, id=%s, state=%s, bytes=%s, packets=%s, appId=%s, buckets=%s";
@Override
protected void execute() {
DeviceService deviceService = get(DeviceService.class);
GroupService groupService = get(GroupService.class);
deviceService.getDevices().forEach(d ->
printGroups(d.id(), groupService.getGroups(d.id()))
);
}
private void printGroups(DeviceId deviceId, Iterable<Group> groups) {
print("deviceId=%s", deviceId);
for (Group group : groups) {
print(FORMAT, group.appCookie(), group.id(), group.state(),
group.bytes(), group.packets(), group.appId(), group.buckets());
}
}
}
......@@ -276,6 +276,10 @@
</command>
<command>
<action class="org.onosproject.cli.net.GroupsListCommand"/>
</command>
<command>
<action class="org.onosproject.cli.net.FlowsListCommand"/>
<completers>
<ref component-id="flowRuleStatusCompleter"/>
......
......@@ -127,6 +127,14 @@ public interface GroupService {
Iterable<Group> getGroups(DeviceId deviceId, ApplicationId appId);
/**
* Returns all groups associated with the given device.
*
* @param deviceId device ID to get groups for
* @return iterable of device's groups
*/
Iterable<Group> getGroups(DeviceId deviceId);
/**
* Adds the specified group listener.
*
* @param listener group listener
......
......@@ -15,13 +15,7 @@
*/
package org.onosproject.net.group.impl;
import static org.slf4j.LoggerFactory.getLogger;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.Set;
import com.google.common.collect.Sets;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
......@@ -54,7 +48,12 @@ import org.onosproject.net.provider.AbstractProviderRegistry;
import org.onosproject.net.provider.AbstractProviderService;
import org.slf4j.Logger;
import com.google.common.collect.Sets;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.Set;
import static org.slf4j.LoggerFactory.getLogger;
/**
* Provides implementation of the group service APIs.
......@@ -206,6 +205,11 @@ public class GroupManager
return store.getGroups(deviceId);
}
@Override
public Iterable<Group> getGroups(DeviceId deviceId) {
return store.getGroups(deviceId);
}
/**
* Adds the specified group listener.
*
......