blob: 43f161894e7ff5c45d654c374848f695f8dc5e41 [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
Pavlin Radoslavov706df052013-03-06 10:49:07 -08003import 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.CallerId;
7import net.onrc.onos.ofcontroller.util.DataPathEndpoints;
8import net.onrc.onos.ofcontroller.util.Dpid;
9import net.onrc.onos.ofcontroller.util.FlowPath;
10import net.onrc.onos.ofcontroller.util.Port;
11import net.onrc.onos.ofcontroller.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
admin944ef4f2013-10-08 17:48:37 -070018/**
HIGUCHI Yutaeb567aa2013-10-08 19:27:35 -070019 * Flow Manager REST API implementation: Get all Flow state for a given
admin944ef4f2013-10-08 17:48:37 -070020 * Installer ID and given source and destination switches and ports.
21 *
22 * The "{installer-id}" request attribute value is the Installer ID of the
23 * flows to get.
24 * The "{src-dpid}" request attribute value is the source DPID of the flows to
25 * get.
26 * The "{src-port}" request attribute value is the source port of the flows to
27 * get.
28 * The "{dst-dpid}" request attribute value is the destination DPID of the
29 * flows to get.
30 * The "{dst-port}" request attribute value is the destination port of the
31 * flows to get.
32 *
33 * GET /wm/flow/getall-by-installer-id/{installer-id}/{src-dpid}/{src-port}/{dst-dpid}/{dst-port}/json"
34 */
Pavlin Radoslavov706df052013-03-06 10:49:07 -080035public class GetAllFlowsByInstallerIdResource extends ServerResource {
36 protected static Logger log = LoggerFactory.getLogger(GetAllFlowsByInstallerIdResource.class);
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -080037
admin944ef4f2013-10-08 17:48:37 -070038 /**
39 * Implement the API.
40 *
41 * @return the collection of Flow states if any found, otherwise null.
42 */
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -080043 @Get("json")
Pavlin Radoslavov706df052013-03-06 10:49:07 -080044 public ArrayList<FlowPath> retrieve() {
45 ArrayList<FlowPath> result = null;
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -080046
47 IFlowService flowService =
48 (IFlowService)getContext().getAttributes().
49 get(IFlowService.class.getCanonicalName());
50
51 if (flowService == null) {
52 log.debug("ONOS Flow Service not found");
53 return result;
54 }
55
56 // Extract the arguments
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -080057 String installerIdStr = (String) getRequestAttributes().get("installer-id");
58 String srcDpidStr = (String) getRequestAttributes().get("src-dpid");
59 String srcPortStr = (String) getRequestAttributes().get("src-port");
60 String dstDpidStr = (String) getRequestAttributes().get("dst-dpid");
61 String dstPortStr = (String) getRequestAttributes().get("dst-port");
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -080062
Pavlin Radoslavov706df052013-03-06 10:49:07 -080063 log.debug("Get All Flow By Installer: " + installerIdStr +
64 " Endpoints: " +
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -080065 srcDpidStr + "--" + srcPortStr + "--" +
66 dstDpidStr + "--" + dstPortStr);
67
68 CallerId installerId = new CallerId(installerIdStr);
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080069 Dpid srcDpid = new Dpid(srcDpidStr);
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -080070 Port srcPort = new Port(Short.parseShort(srcPortStr));
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080071 Dpid dstDpid = new Dpid(dstDpidStr);
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -080072 Port dstPort = new Port(Short.parseShort(dstPortStr));
73 SwitchPort srcSwitchPort = new SwitchPort(srcDpid, srcPort);
74 SwitchPort dstSwitchPort = new SwitchPort(dstDpid, dstPort);
75 DataPathEndpoints dataPathEndpoints =
76 new DataPathEndpoints(srcSwitchPort, dstSwitchPort);
77
Pavlin Radoslavov706df052013-03-06 10:49:07 -080078 result = flowService.getAllFlows(installerId, dataPathEndpoints);
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -080079
80 return result;
81 }
82}