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