blob: 4e96c0cc95f3fe0fd0f7d8a3844a013296168ce6 [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
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -080012import org.openflow.util.HexString;
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -080013import org.restlet.resource.Get;
14import org.restlet.resource.ServerResource;
15import org.slf4j.Logger;
16import org.slf4j.LoggerFactory;
17
18public class GetAllFlowsByEndpointsResource extends ServerResource {
19 protected static Logger log = LoggerFactory.getLogger(GetAllFlowsByEndpointsResource.class);
20
21 @Get("json")
22 public ArrayList<FlowPath> retrieve() {
23 ArrayList<FlowPath> result = new ArrayList<FlowPath>();
24
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 srcDpidStr = (String) getRequestAttributes().get("src-dpid");
36 String srcPortStr = (String) getRequestAttributes().get("src-port");
37 String dstDpidStr = (String) getRequestAttributes().get("dst-dpid");
38 String dstPortStr = (String) getRequestAttributes().get("dst-port");
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -080039
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -080040 log.debug("Get All Flows Endpoints: " + srcDpidStr + "--" +
41 srcPortStr + "--" + dstDpidStr + "--" + dstPortStr);
42
43 Dpid srcDpid = new Dpid(HexString.toLong(srcDpidStr));
44 Port srcPort = new Port(Short.parseShort(srcPortStr));
45 Dpid dstDpid = new Dpid(HexString.toLong(dstDpidStr));
46 Port dstPort = new Port(Short.parseShort(dstPortStr));
47 SwitchPort srcSwitchPort = new SwitchPort(srcDpid, srcPort);
48 SwitchPort dstSwitchPort = new SwitchPort(dstDpid, dstPort);
49 DataPathEndpoints dataPathEndpoints =
50 new DataPathEndpoints(srcSwitchPort, dstSwitchPort);
51
52 flowService.getAllFlows(dataPathEndpoints, result);
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -080053
54 return result;
55 }
56}