Fahad Naeem Khan | 5b558f2 | 2014-10-16 10:35:20 -0700 | [diff] [blame] | 1 | package net.onrc.onos.apps.segmentrouting.web; |
| 2 | |
| 3 | import java.util.HashMap; |
| 4 | |
| 5 | import net.floodlightcontroller.core.web.ControllerSwitchesResource; |
| 6 | import net.onrc.onos.core.topology.ITopologyService; |
| 7 | import net.onrc.onos.core.topology.MutableTopology; |
| 8 | |
| 9 | import org.restlet.resource.ResourceException; |
| 10 | import org.restlet.resource.ServerResource; |
| 11 | import org.restlet.representation.Representation; |
| 12 | import org.restlet.resource.Get; |
| 13 | import static net.onrc.onos.core.topology.web.TopologyResource.eval; |
| 14 | /** |
| 15 | * Base class for return router statistics |
| 16 | * |
| 17 | */ |
| 18 | public class RouterStatisticsResource extends ServerResource { |
| 19 | /** |
| 20 | * Gets the switches and ports information from the network topology. |
| 21 | * |
| 22 | * @return a Representation of a Collection of switches from the network |
| 23 | * topology. Each switch contains the switch ports. |
| 24 | */ |
| 25 | @Get("json") |
| 26 | public Representation retrieve() { |
| 27 | ITopologyService topologyService = |
| 28 | (ITopologyService) getContext().getAttributes() |
| 29 | .get(ITopologyService.class.getCanonicalName()); |
| 30 | |
| 31 | MutableTopology mutableTopology = topologyService.getTopology(); |
| 32 | mutableTopology.acquireReadLock(); |
| 33 | try { |
| 34 | return eval(toRepresentation(mutableTopology.getSwitches(), null)); |
| 35 | } finally { |
| 36 | mutableTopology.releaseReadLock(); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | |
| 41 | |
| 42 | } |