blob: 2bb53bac12794428c8bddd56c7e37a09dc5021e9 [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001package net.floodlightcontroller.staticflowentry.web;
2
3import java.util.HashMap;
4import java.util.Map;
5
6import net.floodlightcontroller.core.web.ControllerSwitchesResource;
7import net.floodlightcontroller.staticflowentry.IStaticFlowEntryPusherService;
8
9import org.openflow.protocol.OFFlowMod;
10import org.restlet.data.Status;
11import org.restlet.resource.Get;
12import org.restlet.resource.ServerResource;
13import org.slf4j.Logger;
14import org.slf4j.LoggerFactory;
15
16public class ListStaticFlowEntriesResource extends ServerResource {
Yuta HIGUCHI6ac8d182013-10-22 15:24:56 -070017 protected final static Logger log = LoggerFactory.getLogger(ListStaticFlowEntriesResource.class);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080018
19 @Get
20 public Map<String, Map<String, OFFlowMod>> ListStaticFlowEntries() {
21 IStaticFlowEntryPusherService sfpService =
22 (IStaticFlowEntryPusherService)getContext().getAttributes().
23 get(IStaticFlowEntryPusherService.class.getCanonicalName());
24
25 String param = (String) getRequestAttributes().get("switch");
26 if (log.isDebugEnabled())
27 log.debug("Listing all static flow entires for switch: " + param);
28
29 if (param.toLowerCase().equals("all")) {
30 return sfpService.getFlows();
31 } else {
32 try {
33 Map<String, Map<String, OFFlowMod>> retMap =
34 new HashMap<String, Map<String, OFFlowMod>>();
35 retMap.put(param, sfpService.getFlows(param));
36 return retMap;
37
38 } catch (NumberFormatException e){
39 setStatus(Status.CLIENT_ERROR_BAD_REQUEST,
40 ControllerSwitchesResource.DPID_ERROR);
41 }
42 }
43 return null;
44 }
45}