blob: 34d79c8dbdfccd149feb027bcbfbd33468c4a600 [file] [log] [blame]
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -08001package net.floodlightcontroller.flowcache.web;
2
3import java.util.ArrayList;
4
5import net.floodlightcontroller.flowcache.IFlowService;
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -08006import net.floodlightcontroller.util.DataPathEndpoints;
7import net.floodlightcontroller.util.Dpid;
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -08008import net.floodlightcontroller.util.FlowPath;
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -08009import net.floodlightcontroller.util.Port;
10import net.floodlightcontroller.util.SwitchPort;
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -080011
12import org.restlet.resource.Get;
13import org.restlet.resource.ServerResource;
14import org.slf4j.Logger;
15import org.slf4j.LoggerFactory;
16
17public class GetAllFlowsByEndpointsResource extends ServerResource {
18 protected static Logger log = LoggerFactory.getLogger(GetAllFlowsByEndpointsResource.class);
19
20 @Get("json")
21 public ArrayList<FlowPath> retrieve() {
Pavlin Radoslavovb6f53542013-03-01 16:02:14 -080022 ArrayList<FlowPath> result = null;
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -080023
24 IFlowService flowService =
25 (IFlowService)getContext().getAttributes().
26 get(IFlowService.class.getCanonicalName());
27
28 if (flowService == null) {
29 log.debug("ONOS Flow Service not found");
30 return result;
31 }
32
33 // Extract the arguments
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -080034 String srcDpidStr = (String) getRequestAttributes().get("src-dpid");
35 String srcPortStr = (String) getRequestAttributes().get("src-port");
36 String dstDpidStr = (String) getRequestAttributes().get("dst-dpid");
37 String dstPortStr = (String) getRequestAttributes().get("dst-port");
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -080038
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -080039 log.debug("Get All Flows Endpoints: " + srcDpidStr + "--" +
40 srcPortStr + "--" + dstDpidStr + "--" + dstPortStr);
41
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080042 Dpid srcDpid = new Dpid(srcDpidStr);
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -080043 Port srcPort = new Port(Short.parseShort(srcPortStr));
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080044 Dpid dstDpid = new Dpid(dstDpidStr);
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -080045 Port dstPort = new Port(Short.parseShort(dstPortStr));
46 SwitchPort srcSwitchPort = new SwitchPort(srcDpid, srcPort);
47 SwitchPort dstSwitchPort = new SwitchPort(dstDpid, dstPort);
48 DataPathEndpoints dataPathEndpoints =
49 new DataPathEndpoints(srcSwitchPort, dstSwitchPort);
50
Pavlin Radoslavovb6f53542013-03-01 16:02:14 -080051 result = flowService.getAllFlows(dataPathEndpoints);
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -080052
53 return result;
54 }
55}