blob: 0f2366333408f6bd0f6ac535565bd23a4854426c [file] [log] [blame]
HIGUCHI Yuta60a10142013-06-14 15:50:10 -07001package net.onrc.onos.ofcontroller.flowmanager.web;
Pavlin Radoslavov4ef543e2013-05-07 13:36:57 -07002
3import java.io.IOException;
4
HIGUCHI Yuta60a10142013-06-14 15:50:10 -07005import net.onrc.onos.ofcontroller.flowmanager.IFlowService;
HIGUCHI Yuta356086e2013-06-12 15:21:19 -07006import net.onrc.onos.ofcontroller.util.FlowId;
7import net.onrc.onos.ofcontroller.util.FlowPath;
Pavlin Radoslavov4ef543e2013-05-07 13:36:57 -07008
9import org.codehaus.jackson.JsonGenerationException;
Pavlin Radoslavov4ef543e2013-05-07 13:36:57 -070010import org.codehaus.jackson.map.JsonMappingException;
11import org.codehaus.jackson.map.ObjectMapper;
12import org.restlet.resource.Post;
13import org.restlet.resource.ServerResource;
14import org.slf4j.Logger;
15import org.slf4j.LoggerFactory;
16
17public 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}