blob: f32d124ffdaf9c987dc7363deccb1c680bbd3158 [file] [log] [blame]
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -08001package net.floodlightcontroller.flowcache.web;
2
3import net.floodlightcontroller.flowcache.IFlowService;
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -08004import net.floodlightcontroller.util.FlowId;
5import net.floodlightcontroller.util.FlowPath;
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -08006
7import org.restlet.resource.Get;
8import org.restlet.resource.ServerResource;
9import org.slf4j.Logger;
10import org.slf4j.LoggerFactory;
11
12public class AddFlowResource extends ServerResource {
13
14 protected static Logger log = LoggerFactory.getLogger(AddFlowResource.class);
15
16 @Get("json")
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -080017 public FlowId retrieve() {
18 FlowId result = new FlowId();
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -080019
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 Radoslavova10a9a82013-02-22 11:47:54 -080031 FlowPath flowPath = new FlowPath(flowPathStr);
32
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -080033 log.debug("Add Flow Path: " + flowPathStr);
34
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -080035 if (flowService.addFlow(flowPath, result) != true) {
36 result = new FlowId(); // Error: Empty Flow Id
37 }
Pavlin Radoslavov5ab68512013-02-18 09:59:33 -080038
39 return result;
40 }
41}