blob: 944bf1c8e0116f3ac6bfb16980d82f57ad4bf55e [file] [log] [blame]
Fahad Naeem Khan5b558f22014-10-16 10:35:20 -07001package net.onrc.onos.apps.segmentrouting.web;
2
Fahad Naeem Khan5b558f22014-10-16 10:35:20 -07003
Fahad Naeem Khan6ead4622014-10-16 12:33:29 -07004import java.util.List;
5import java.util.concurrent.Future;
6
7import net.floodlightcontroller.core.IFloodlightProviderService;
8import net.floodlightcontroller.core.IOFSwitch;
Fahad Naeem Khan5b558f22014-10-16 10:35:20 -07009import net.onrc.onos.core.topology.ITopologyService;
10import net.onrc.onos.core.topology.MutableTopology;
Fahad Naeem Khan6ead4622014-10-16 12:33:29 -070011import net.onrc.onos.core.util.Dpid;
Fahad Naeem Khan5b558f22014-10-16 10:35:20 -070012
Fahad Naeem Khan6ead4622014-10-16 12:33:29 -070013import org.apache.commons.codec.binary.Hex;
14import org.projectfloodlight.openflow.util.HexString;
Fahad Naeem Khan5b558f22014-10-16 10:35:20 -070015import org.restlet.resource.ServerResource;
16import org.restlet.representation.Representation;
17import org.restlet.resource.Get;
Fahad Naeem Khan6ead4622014-10-16 12:33:29 -070018
19import com.esotericsoftware.minlog.Log;
20
Fahad Naeem Khan5b558f22014-10-16 10:35:20 -070021import static net.onrc.onos.core.topology.web.TopologyResource.eval;
22/**
23 * Base class for return router statistics
24 *
25 */
26public class RouterStatisticsResource extends ServerResource {
27 /**
Fahad Naeem Khan6ead4622014-10-16 12:33:29 -070028 * Gets the switches/routers and ports information from the network topology.
Fahad Naeem Khan5b558f22014-10-16 10:35:20 -070029 *
Fahad Naeem Khan6ead4622014-10-16 12:33:29 -070030 * @return a Representation of a Collection of switches/routers from the network
Fahad Naeem Khan5b558f22014-10-16 10:35:20 -070031 * topology. Each switch contains the switch ports.
32 */
33 @Get("json")
34 public Representation retrieve() {
Fahad Naeem Khan6ead4622014-10-16 12:33:29 -070035 String routerId = (String) getRequestAttributes().get("routerId");
36 String statsType = (String) getRequestAttributes().get("statsType");
37 //if (routerId == null && statsType == null){
Fahad Naeem Khan5b558f22014-10-16 10:35:20 -070038 ITopologyService topologyService =
Fahad Naeem Khan6ead4622014-10-16 12:33:29 -070039 (ITopologyService) getContext().getAttributes()
Fahad Naeem Khan5b558f22014-10-16 10:35:20 -070040 .get(ITopologyService.class.getCanonicalName());
41
42 MutableTopology mutableTopology = topologyService.getTopology();
43 mutableTopology.acquireReadLock();
44 try {
Fahad Naeem Khan6ead4622014-10-16 12:33:29 -070045 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 Khan5b558f22014-10-16 10:35:20 -070054 } finally {
55 mutableTopology.releaseReadLock();
56 }
Fahad Naeem Khan6ead4622014-10-16 12:33:29 -070057 // }
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 Khan5b558f22014-10-16 10:35:20 -070069 }
Fahad Naeem Khan6ead4622014-10-16 12:33:29 -070070
71
Fahad Naeem Khan5b558f22014-10-16 10:35:20 -070072
73
74
75}