blob: 0d41dddca60c9ed5bac865a235d5cd7ef79b24ee [file] [log] [blame]
package net.onrc.onos.core.topology.web;
import net.onrc.onos.core.topology.ITopologyService;
import net.onrc.onos.core.topology.Topology;
import org.restlet.representation.Representation;
import org.restlet.resource.Get;
import org.restlet.resource.ServerResource;
/**
* A class to access switches and ports information from the network topology.
*/
public class TopologySwitchesResource extends ServerResource {
/**
* Gets the switches and ports information from the network topology.
*
* @return a Representation of a Collection of switches from the network
* topology. Each switch contains the switch ports.
*/
@Get("json")
public Representation retrieve() {
ITopologyService topologyService =
(ITopologyService) getContext().getAttributes()
.get(ITopologyService.class.getCanonicalName());
Topology topology = topologyService.getTopology();
topology.acquireReadLock();
try {
return toRepresentation(topology.getSwitches(), null);
} finally {
topology.releaseReadLock();
}
}
}