HIGUCHI Yuta | 60a1014 | 2013-06-14 15:50:10 -0700 | [diff] [blame^] | 1 | package net.onrc.onos.ofcontroller.flowmanager.web; |
Pavlin Radoslavov | 4ef543e | 2013-05-07 13:36:57 -0700 | [diff] [blame] | 2 | |
| 3 | import java.io.IOException; |
| 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.FlowId; |
| 7 | import net.onrc.onos.ofcontroller.util.FlowPath; |
Pavlin Radoslavov | 4ef543e | 2013-05-07 13:36:57 -0700 | [diff] [blame] | 8 | |
| 9 | import org.codehaus.jackson.JsonGenerationException; |
Pavlin Radoslavov | 4ef543e | 2013-05-07 13:36:57 -0700 | [diff] [blame] | 10 | import org.codehaus.jackson.map.JsonMappingException; |
| 11 | import org.codehaus.jackson.map.ObjectMapper; |
| 12 | import org.restlet.resource.Post; |
| 13 | import org.restlet.resource.ServerResource; |
| 14 | import org.slf4j.Logger; |
| 15 | import org.slf4j.LoggerFactory; |
| 16 | |
| 17 | public class MeasurementStorePathFlowResource extends ServerResource { |
| 18 | |
| 19 | protected static Logger log = LoggerFactory.getLogger(MeasurementStorePathFlowResource.class); |
| 20 | |
| 21 | @Post("json") |
| 22 | public FlowId store(String flowJson) { |
| 23 | FlowId result = new FlowId(); |
| 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 | // |
| 35 | // Extract the arguments |
| 36 | // NOTE: The "flow" is specified in JSON format. |
| 37 | // |
| 38 | ObjectMapper mapper = new ObjectMapper(); |
| 39 | String flowPathStr = flowJson; |
| 40 | FlowPath flowPath = null; |
| 41 | log.debug("Measurement Store Flow Path: " + flowPathStr); |
| 42 | try { |
| 43 | flowPath = mapper.readValue(flowPathStr, FlowPath.class); |
| 44 | } catch (JsonGenerationException e) { |
| 45 | e.printStackTrace(); |
| 46 | } catch (JsonMappingException e) { |
| 47 | e.printStackTrace(); |
| 48 | } catch (IOException e) { |
| 49 | e.printStackTrace(); |
| 50 | } |
| 51 | |
| 52 | // Process the request |
| 53 | if (flowPath != null) { |
| 54 | FlowPath addedFlowPath = |
| 55 | flowService.measurementStorePathFlow(flowPath); |
| 56 | if (addedFlowPath == null) |
| 57 | result = new FlowId(); // Error: Return empty Flow Id |
| 58 | else |
| 59 | result = addedFlowPath.flowId(); |
| 60 | } |
| 61 | |
| 62 | return result; |
| 63 | } |
| 64 | } |