Fahad Naeem Khan | 5b558f2 | 2014-10-16 10:35:20 -0700 | [diff] [blame] | 1 | package net.onrc.onos.apps.segmentrouting.web; |
| 2 | |
Fahad Naeem Khan | 5b558f2 | 2014-10-16 10:35:20 -0700 | [diff] [blame] | 3 | |
Fahad Naeem Khan | 6ead462 | 2014-10-16 12:33:29 -0700 | [diff] [blame] | 4 | import java.util.List; |
| 5 | import java.util.concurrent.Future; |
| 6 | |
| 7 | import net.floodlightcontroller.core.IFloodlightProviderService; |
| 8 | import net.floodlightcontroller.core.IOFSwitch; |
Fahad Naeem Khan | 5b558f2 | 2014-10-16 10:35:20 -0700 | [diff] [blame] | 9 | import net.onrc.onos.core.topology.ITopologyService; |
| 10 | import net.onrc.onos.core.topology.MutableTopology; |
Fahad Naeem Khan | 6ead462 | 2014-10-16 12:33:29 -0700 | [diff] [blame] | 11 | import net.onrc.onos.core.util.Dpid; |
Fahad Naeem Khan | 5b558f2 | 2014-10-16 10:35:20 -0700 | [diff] [blame] | 12 | |
Fahad Naeem Khan | 6ead462 | 2014-10-16 12:33:29 -0700 | [diff] [blame] | 13 | import org.apache.commons.codec.binary.Hex; |
| 14 | import org.projectfloodlight.openflow.util.HexString; |
Fahad Naeem Khan | 5b558f2 | 2014-10-16 10:35:20 -0700 | [diff] [blame] | 15 | import org.restlet.resource.ServerResource; |
| 16 | import org.restlet.representation.Representation; |
| 17 | import org.restlet.resource.Get; |
Fahad Naeem Khan | 6ead462 | 2014-10-16 12:33:29 -0700 | [diff] [blame] | 18 | |
| 19 | import com.esotericsoftware.minlog.Log; |
| 20 | |
Fahad Naeem Khan | 5b558f2 | 2014-10-16 10:35:20 -0700 | [diff] [blame] | 21 | import static net.onrc.onos.core.topology.web.TopologyResource.eval; |
| 22 | /** |
| 23 | * Base class for return router statistics |
| 24 | * |
| 25 | */ |
| 26 | public class RouterStatisticsResource extends ServerResource { |
| 27 | /** |
Fahad Naeem Khan | 6ead462 | 2014-10-16 12:33:29 -0700 | [diff] [blame] | 28 | * Gets the switches/routers and ports information from the network topology. |
Fahad Naeem Khan | 5b558f2 | 2014-10-16 10:35:20 -0700 | [diff] [blame] | 29 | * |
Fahad Naeem Khan | 6ead462 | 2014-10-16 12:33:29 -0700 | [diff] [blame] | 30 | * @return a Representation of a Collection of switches/routers from the network |
Fahad Naeem Khan | 5b558f2 | 2014-10-16 10:35:20 -0700 | [diff] [blame] | 31 | * topology. Each switch contains the switch ports. |
| 32 | */ |
| 33 | @Get("json") |
| 34 | public Representation retrieve() { |
Fahad Naeem Khan | 6ead462 | 2014-10-16 12:33:29 -0700 | [diff] [blame] | 35 | String routerId = (String) getRequestAttributes().get("routerId"); |
| 36 | String statsType = (String) getRequestAttributes().get("statsType"); |
| 37 | //if (routerId == null && statsType == null){ |
Fahad Naeem Khan | 5b558f2 | 2014-10-16 10:35:20 -0700 | [diff] [blame] | 38 | ITopologyService topologyService = |
Fahad Naeem Khan | 6ead462 | 2014-10-16 12:33:29 -0700 | [diff] [blame] | 39 | (ITopologyService) getContext().getAttributes() |
Fahad Naeem Khan | 5b558f2 | 2014-10-16 10:35:20 -0700 | [diff] [blame] | 40 | .get(ITopologyService.class.getCanonicalName()); |
| 41 | |
| 42 | MutableTopology mutableTopology = topologyService.getTopology(); |
| 43 | mutableTopology.acquireReadLock(); |
| 44 | try { |
Fahad Naeem Khan | 6ead462 | 2014-10-16 12:33:29 -0700 | [diff] [blame] | 45 | if (routerId == null && statsType == null){ |
| 46 | return eval(toRepresentation(mutableTopology.getSwitches(), null)); |
| 47 | } |
| 48 | else if(routerId != null && statsType == "port"){ |
| 49 | Log.debug("\n\n\nGot router port stats request\n\n\n"); |
| 50 | System.out.println("\n\n\nGot router port stats request\n\n\n"); |
| 51 | Long rId = HexString.toLong(routerId); |
| 52 | return eval(toRepresentation(mutableTopology.getSwitch(new Dpid(rId)), null)); |
| 53 | } |
Fahad Naeem Khan | 5b558f2 | 2014-10-16 10:35:20 -0700 | [diff] [blame] | 54 | } finally { |
| 55 | mutableTopology.releaseReadLock(); |
| 56 | } |
Fahad Naeem Khan | 6ead462 | 2014-10-16 12:33:29 -0700 | [diff] [blame] | 57 | // } |
| 58 | /*else if(routerId != null && statsType == "port"){ |
| 59 | Long rId = HexString.toLong(routerId); |
| 60 | IFloodlightProviderService floodlightProvider = |
| 61 | (IFloodlightProviderService) getContext().getAttributes(). |
| 62 | get(IFloodlightProviderService.class.getCanonicalName()); |
| 63 | IOFSwitch sw = floodlightProvider.getSwitches().get(rId); |
| 64 | Future<List<OFStatsReply>> future; |
| 65 | List<OFStatsReply> values = null; |
| 66 | |
| 67 | }*/ |
| 68 | return null; |
Fahad Naeem Khan | 5b558f2 | 2014-10-16 10:35:20 -0700 | [diff] [blame] | 69 | } |
Fahad Naeem Khan | 6ead462 | 2014-10-16 12:33:29 -0700 | [diff] [blame] | 70 | |
| 71 | |
Fahad Naeem Khan | 5b558f2 | 2014-10-16 10:35:20 -0700 | [diff] [blame] | 72 | |
| 73 | |
| 74 | |
| 75 | } |