HIGUCHI Yuta | 60a1014 | 2013-06-14 15:50:10 -0700 | [diff] [blame^] | 1 | package net.onrc.onos.ofcontroller.flowmanager.web; |
Pavlin Radoslavov | 5ab6851 | 2013-02-18 09:59:33 -0800 | [diff] [blame] | 2 | |
Pavlin Radoslavov | 706df05 | 2013-03-06 10:49:07 -0800 | [diff] [blame] | 3 | import java.util.ArrayList; |
| 4 | |
HIGUCHI Yuta | 60a1014 | 2013-06-14 15:50:10 -0700 | [diff] [blame^] | 5 | import net.onrc.onos.ofcontroller.flowmanager.IFlowService; |
HIGUCHI Yuta | 356086e | 2013-06-12 15:21:19 -0700 | [diff] [blame] | 6 | import net.onrc.onos.ofcontroller.util.CallerId; |
| 7 | import net.onrc.onos.ofcontroller.util.DataPathEndpoints; |
| 8 | import net.onrc.onos.ofcontroller.util.Dpid; |
| 9 | import net.onrc.onos.ofcontroller.util.FlowPath; |
| 10 | import net.onrc.onos.ofcontroller.util.Port; |
| 11 | import net.onrc.onos.ofcontroller.util.SwitchPort; |
Pavlin Radoslavov | 5ab6851 | 2013-02-18 09:59:33 -0800 | [diff] [blame] | 12 | |
| 13 | import org.restlet.resource.Get; |
| 14 | import org.restlet.resource.ServerResource; |
| 15 | import org.slf4j.Logger; |
| 16 | import org.slf4j.LoggerFactory; |
| 17 | |
Pavlin Radoslavov | 706df05 | 2013-03-06 10:49:07 -0800 | [diff] [blame] | 18 | public class GetAllFlowsByInstallerIdResource extends ServerResource { |
| 19 | protected static Logger log = LoggerFactory.getLogger(GetAllFlowsByInstallerIdResource.class); |
Pavlin Radoslavov | 5ab6851 | 2013-02-18 09:59:33 -0800 | [diff] [blame] | 20 | |
| 21 | @Get("json") |
Pavlin Radoslavov | 706df05 | 2013-03-06 10:49:07 -0800 | [diff] [blame] | 22 | public ArrayList<FlowPath> retrieve() { |
| 23 | ArrayList<FlowPath> result = null; |
Pavlin Radoslavov | 5ab6851 | 2013-02-18 09:59:33 -0800 | [diff] [blame] | 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 Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame] | 35 | String installerIdStr = (String) getRequestAttributes().get("installer-id"); |
| 36 | String srcDpidStr = (String) getRequestAttributes().get("src-dpid"); |
| 37 | String srcPortStr = (String) getRequestAttributes().get("src-port"); |
| 38 | String dstDpidStr = (String) getRequestAttributes().get("dst-dpid"); |
| 39 | String dstPortStr = (String) getRequestAttributes().get("dst-port"); |
Pavlin Radoslavov | 5ab6851 | 2013-02-18 09:59:33 -0800 | [diff] [blame] | 40 | |
Pavlin Radoslavov | 706df05 | 2013-03-06 10:49:07 -0800 | [diff] [blame] | 41 | log.debug("Get All Flow By Installer: " + installerIdStr + |
| 42 | " Endpoints: " + |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame] | 43 | srcDpidStr + "--" + srcPortStr + "--" + |
| 44 | dstDpidStr + "--" + dstPortStr); |
| 45 | |
| 46 | CallerId installerId = new CallerId(installerIdStr); |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 47 | Dpid srcDpid = new Dpid(srcDpidStr); |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame] | 48 | Port srcPort = new Port(Short.parseShort(srcPortStr)); |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 49 | Dpid dstDpid = new Dpid(dstDpidStr); |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame] | 50 | Port dstPort = new Port(Short.parseShort(dstPortStr)); |
| 51 | SwitchPort srcSwitchPort = new SwitchPort(srcDpid, srcPort); |
| 52 | SwitchPort dstSwitchPort = new SwitchPort(dstDpid, dstPort); |
| 53 | DataPathEndpoints dataPathEndpoints = |
| 54 | new DataPathEndpoints(srcSwitchPort, dstSwitchPort); |
| 55 | |
Pavlin Radoslavov | 706df05 | 2013-03-06 10:49:07 -0800 | [diff] [blame] | 56 | result = flowService.getAllFlows(installerId, dataPathEndpoints); |
Pavlin Radoslavov | 5ab6851 | 2013-02-18 09:59:33 -0800 | [diff] [blame] | 57 | |
| 58 | return result; |
| 59 | } |
| 60 | } |