blob: 0308e89b05e2178fc89c629516a7c621d01635bf [file] [log] [blame]
HIGUCHI Yuta60a10142013-06-14 15:50:10 -07001package net.onrc.onos.ofcontroller.flowmanager.web;
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -08002
3import java.util.ArrayList;
4
HIGUCHI Yuta60a10142013-06-14 15:50:10 -07005import net.onrc.onos.ofcontroller.flowmanager.IFlowService;
HIGUCHI Yuta356086e2013-06-12 15:21:19 -07006import net.onrc.onos.ofcontroller.util.DataPathEndpoints;
7import net.onrc.onos.ofcontroller.util.Dpid;
8import net.onrc.onos.ofcontroller.util.FlowPath;
9import net.onrc.onos.ofcontroller.util.Port;
10import net.onrc.onos.ofcontroller.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
admin944ef4f2013-10-08 17:48:37 -070017/**
HIGUCHI Yutaeb567aa2013-10-08 19:27:35 -070018 * Flow Manager REST API implementation: Get all Flow state for given
admin944ef4f2013-10-08 17:48:37 -070019 * source and destination switches and ports.
20 *
21 * The "{src-dpid}" request attribute value is the source DPID of the flows to
22 * get.
23 * The "{src-port}" request attribute value is the source port of the flows to
24 * get.
25 * The "{dst-dpid}" request attribute value is the destination DPID of the
26 * flows to get.
27 * The "{dst-port}" request attribute value is the destination port of the
28 * flows to get.
29 *
30 * GET /wm/flow/getall-by-endpoints/{src-dpid}/{src-port}/{dst-dpid}/{dst-port}/json"
31 */
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -080032public class GetAllFlowsByEndpointsResource extends ServerResource {
33 protected static Logger log = LoggerFactory.getLogger(GetAllFlowsByEndpointsResource.class);
34
admin944ef4f2013-10-08 17:48:37 -070035 /**
36 * Implement the API.
37 *
38 * @return the collection of Flow states if any found, otherwise null.
39 */
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -080040 @Get("json")
41 public ArrayList<FlowPath> retrieve() {
Pavlin Radoslavovb6f53542013-03-01 16:02:14 -080042 ArrayList<FlowPath> result = null;
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -080043
44 IFlowService flowService =
45 (IFlowService)getContext().getAttributes().
46 get(IFlowService.class.getCanonicalName());
47
48 if (flowService == null) {
49 log.debug("ONOS Flow Service not found");
50 return result;
51 }
52
53 // Extract the arguments
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -080054 String srcDpidStr = (String) getRequestAttributes().get("src-dpid");
55 String srcPortStr = (String) getRequestAttributes().get("src-port");
56 String dstDpidStr = (String) getRequestAttributes().get("dst-dpid");
57 String dstPortStr = (String) getRequestAttributes().get("dst-port");
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -080058
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -080059 log.debug("Get All Flows Endpoints: " + srcDpidStr + "--" +
60 srcPortStr + "--" + dstDpidStr + "--" + dstPortStr);
61
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080062 Dpid srcDpid = new Dpid(srcDpidStr);
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -080063 Port srcPort = new Port(Short.parseShort(srcPortStr));
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080064 Dpid dstDpid = new Dpid(dstDpidStr);
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -080065 Port dstPort = new Port(Short.parseShort(dstPortStr));
66 SwitchPort srcSwitchPort = new SwitchPort(srcDpid, srcPort);
67 SwitchPort dstSwitchPort = new SwitchPort(dstDpid, dstPort);
68 DataPathEndpoints dataPathEndpoints =
69 new DataPathEndpoints(srcSwitchPort, dstSwitchPort);
70
Pavlin Radoslavovb6f53542013-03-01 16:02:14 -080071 result = flowService.getAllFlows(dataPathEndpoints);
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -080072
73 return result;
74 }
75}