blob: 5eb8af065eefe06fe9a88b516a366dde34534586 [file] [log] [blame]
HIGUCHI Yutaefa54882013-06-12 13:13:02 -07001package net.onrc.onos.ofcontroller.flowcache.web;
Pavlin Radoslavov4ef543e2013-05-07 13:36:57 -07002
3import java.io.IOException;
4
HIGUCHI Yutaedf81d72013-06-12 12:06:57 -07005import net.onrc.onos.ofcontroller.flowcache.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;
10import org.codehaus.jackson.map.ObjectMapper;
11import org.codehaus.jackson.map.JsonMappingException;
12import org.codehaus.jackson.map.ObjectMapper;
13import org.restlet.resource.Post;
14import org.restlet.resource.ServerResource;
15import org.slf4j.Logger;
16import org.slf4j.LoggerFactory;
17
18public class MeasurementStorePathFlowResource extends ServerResource {
19
20 protected static Logger log = LoggerFactory.getLogger(MeasurementStorePathFlowResource.class);
21
22 @Post("json")
23 public FlowId store(String flowJson) {
24 FlowId result = new FlowId();
25
26 IFlowService flowService =
27 (IFlowService)getContext().getAttributes().
28 get(IFlowService.class.getCanonicalName());
29
30 if (flowService == null) {
31 log.debug("ONOS Flow Service not found");
32 return result;
33 }
34
35 //
36 // Extract the arguments
37 // NOTE: The "flow" is specified in JSON format.
38 //
39 ObjectMapper mapper = new ObjectMapper();
40 String flowPathStr = flowJson;
41 FlowPath flowPath = null;
42 log.debug("Measurement Store Flow Path: " + flowPathStr);
43 try {
44 flowPath = mapper.readValue(flowPathStr, FlowPath.class);
45 } catch (JsonGenerationException e) {
46 e.printStackTrace();
47 } catch (JsonMappingException e) {
48 e.printStackTrace();
49 } catch (IOException e) {
50 e.printStackTrace();
51 }
52
53 // Process the request
54 if (flowPath != null) {
55 FlowPath addedFlowPath =
56 flowService.measurementStorePathFlow(flowPath);
57 if (addedFlowPath == null)
58 result = new FlowId(); // Error: Return empty Flow Id
59 else
60 result = addedFlowPath.flowId();
61 }
62
63 return result;
64 }
65}