Pavlin Radoslavov | 5ab6851 | 2013-02-18 09:59:33 -0800 | [diff] [blame] | 1 | package net.floodlightcontroller.flowcache.web; |
| 2 | |
| 3 | import net.floodlightcontroller.flowcache.IFlowService; |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame] | 4 | import net.floodlightcontroller.util.FlowId; |
| 5 | import net.floodlightcontroller.util.FlowPath; |
Pavlin Radoslavov | 5ab6851 | 2013-02-18 09:59:33 -0800 | [diff] [blame] | 6 | |
| 7 | import org.restlet.resource.Get; |
| 8 | import org.restlet.resource.ServerResource; |
| 9 | import org.slf4j.Logger; |
| 10 | import org.slf4j.LoggerFactory; |
| 11 | |
| 12 | public class AddFlowResource extends ServerResource { |
| 13 | |
| 14 | protected static Logger log = LoggerFactory.getLogger(AddFlowResource.class); |
| 15 | |
| 16 | @Get("json") |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame] | 17 | public FlowId retrieve() { |
| 18 | FlowId result = new FlowId(); |
Pavlin Radoslavov | 5ab6851 | 2013-02-18 09:59:33 -0800 | [diff] [blame] | 19 | |
| 20 | IFlowService flowService = |
| 21 | (IFlowService)getContext().getAttributes(). |
| 22 | get(IFlowService.class.getCanonicalName()); |
| 23 | |
| 24 | if (flowService == null) { |
| 25 | log.debug("ONOS Flow Service not found"); |
| 26 | return result; |
| 27 | } |
| 28 | |
| 29 | // Extract the arguments |
| 30 | String flowPathStr = (String) getRequestAttributes().get("flow"); |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame] | 31 | FlowPath flowPath = new FlowPath(flowPathStr); |
| 32 | |
Pavlin Radoslavov | 5ab6851 | 2013-02-18 09:59:33 -0800 | [diff] [blame] | 33 | log.debug("Add Flow Path: " + flowPathStr); |
| 34 | |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame] | 35 | if (flowService.addFlow(flowPath, result) != true) { |
| 36 | result = new FlowId(); // Error: Empty Flow Id |
| 37 | } |
Pavlin Radoslavov | 5ab6851 | 2013-02-18 09:59:33 -0800 | [diff] [blame] | 38 | |
| 39 | return result; |
| 40 | } |
| 41 | } |