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 | |
| 5 | import net.floodlightcontroller.flowcache.IFlowService; |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame^] | 6 | import net.floodlightcontroller.util.DataPathEndpoints; |
| 7 | import net.floodlightcontroller.util.Dpid; |
Pavlin Radoslavov | 5ab6851 | 2013-02-18 09:59:33 -0800 | [diff] [blame] | 8 | import net.floodlightcontroller.util.FlowPath; |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame^] | 9 | import net.floodlightcontroller.util.Port; |
| 10 | import net.floodlightcontroller.util.SwitchPort; |
Pavlin Radoslavov | 5ab6851 | 2013-02-18 09:59:33 -0800 | [diff] [blame] | 11 | |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame^] | 12 | import org.openflow.util.HexString; |
Pavlin Radoslavov | 5ab6851 | 2013-02-18 09:59:33 -0800 | [diff] [blame] | 13 | import org.restlet.resource.Get; |
| 14 | import org.restlet.resource.ServerResource; |
| 15 | import org.slf4j.Logger; |
| 16 | import org.slf4j.LoggerFactory; |
| 17 | |
| 18 | public 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 Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame^] | 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 Radoslavov | 5ab6851 | 2013-02-18 09:59:33 -0800 | [diff] [blame] | 39 | |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame^] | 40 | 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 Radoslavov | 5ab6851 | 2013-02-18 09:59:33 -0800 | [diff] [blame] | 53 | |
| 54 | return result; |
| 55 | } |
| 56 | } |