blob: e3043dce6bb893881725f001353e0336feae1cdc [file] [log] [blame]
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -08001package net.floodlightcontroller.flowcache.web;
2
Pavlin Radoslavov706df052013-03-06 10:49:07 -08003import java.util.ArrayList;
4
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -08005import net.floodlightcontroller.flowcache.IFlowService;
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -08006import net.floodlightcontroller.util.CallerId;
7import net.floodlightcontroller.util.DataPathEndpoints;
8import net.floodlightcontroller.util.Dpid;
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -08009import net.floodlightcontroller.util.FlowPath;
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -080010import net.floodlightcontroller.util.Port;
11import net.floodlightcontroller.util.SwitchPort;
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -080012
13import org.restlet.resource.Get;
14import org.restlet.resource.ServerResource;
15import org.slf4j.Logger;
16import org.slf4j.LoggerFactory;
17
Pavlin Radoslavov706df052013-03-06 10:49:07 -080018public class GetAllFlowsByInstallerIdResource extends ServerResource {
19 protected static Logger log = LoggerFactory.getLogger(GetAllFlowsByInstallerIdResource.class);
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -080020
21 @Get("json")
Pavlin Radoslavov706df052013-03-06 10:49:07 -080022 public ArrayList<FlowPath> retrieve() {
23 ArrayList<FlowPath> result = null;
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -080024
25 IFlowService flowService =
26 (IFlowService)getContext().getAttributes().
27 get(IFlowService.class.getCanonicalName());
28
29 if (flowService == null) {
30 log.debug("ONOS Flow Service not found");
31 return result;
32 }
33
34 // Extract the arguments
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -080035 String installerIdStr = (String) getRequestAttributes().get("installer-id");
36 String srcDpidStr = (String) getRequestAttributes().get("src-dpid");
37 String srcPortStr = (String) getRequestAttributes().get("src-port");
38 String dstDpidStr = (String) getRequestAttributes().get("dst-dpid");
39 String dstPortStr = (String) getRequestAttributes().get("dst-port");
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -080040
Pavlin Radoslavov706df052013-03-06 10:49:07 -080041 log.debug("Get All Flow By Installer: " + installerIdStr +
42 " Endpoints: " +
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -080043 srcDpidStr + "--" + srcPortStr + "--" +
44 dstDpidStr + "--" + dstPortStr);
45
46 CallerId installerId = new CallerId(installerIdStr);
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080047 Dpid srcDpid = new Dpid(srcDpidStr);
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -080048 Port srcPort = new Port(Short.parseShort(srcPortStr));
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080049 Dpid dstDpid = new Dpid(dstDpidStr);
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -080050 Port dstPort = new Port(Short.parseShort(dstPortStr));
51 SwitchPort srcSwitchPort = new SwitchPort(srcDpid, srcPort);
52 SwitchPort dstSwitchPort = new SwitchPort(dstDpid, dstPort);
53 DataPathEndpoints dataPathEndpoints =
54 new DataPathEndpoints(srcSwitchPort, dstSwitchPort);
55
Pavlin Radoslavov706df052013-03-06 10:49:07 -080056 result = flowService.getAllFlows(installerId, dataPathEndpoints);
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -080057
58 return result;
59 }
60}