blob: 6b5f7f4d036b5df63ff00c2d4e30452ea242552c [file] [log] [blame]
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -08001package net.floodlightcontroller.flowcache.web;
2
3import net.floodlightcontroller.flowcache.IFlowService;
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -08004import net.floodlightcontroller.util.CallerId;
5import net.floodlightcontroller.util.DataPathEndpoints;
6import net.floodlightcontroller.util.Dpid;
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -08007import net.floodlightcontroller.util.FlowPath;
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -08008import net.floodlightcontroller.util.Port;
9import net.floodlightcontroller.util.SwitchPort;
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -080010
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -080011import org.openflow.util.HexString;
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -080012import org.restlet.resource.Get;
13import org.restlet.resource.ServerResource;
14import org.slf4j.Logger;
15import org.slf4j.LoggerFactory;
16
17public class GetFlowByInstallerIdResource extends ServerResource {
18 protected static Logger log = LoggerFactory.getLogger(GetFlowByInstallerIdResource.class);
19
20 @Get("json")
21 public FlowPath retrieve() {
22 FlowPath result = null;
23
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 installerIdStr = (String) getRequestAttributes().get("installer-id");
35 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 Flow By Installer: " + installerIdStr + " Endpoints: " +
41 srcDpidStr + "--" + srcPortStr + "--" +
42 dstDpidStr + "--" + dstPortStr);
43
44 CallerId installerId = new CallerId(installerIdStr);
45 Dpid srcDpid = new Dpid(HexString.toLong(srcDpidStr));
46 Port srcPort = new Port(Short.parseShort(srcPortStr));
47 Dpid dstDpid = new Dpid(HexString.toLong(dstDpidStr));
48 Port dstPort = new Port(Short.parseShort(dstPortStr));
49 SwitchPort srcSwitchPort = new SwitchPort(srcDpid, srcPort);
50 SwitchPort dstSwitchPort = new SwitchPort(dstDpid, dstPort);
51 DataPathEndpoints dataPathEndpoints =
52 new DataPathEndpoints(srcSwitchPort, dstSwitchPort);
53
54 flowService.getFlow(installerId, dataPathEndpoints, result);
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -080055
56 return result;
57 }
58}