Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 1 | package net.floodlightcontroller.staticflowentry.web; |
| 2 | |
| 3 | import java.util.HashMap; |
| 4 | import java.util.Map; |
| 5 | |
| 6 | import net.floodlightcontroller.core.web.ControllerSwitchesResource; |
| 7 | import net.floodlightcontroller.staticflowentry.IStaticFlowEntryPusherService; |
| 8 | |
| 9 | import org.openflow.protocol.OFFlowMod; |
| 10 | import org.restlet.data.Status; |
| 11 | import org.restlet.resource.Get; |
| 12 | import org.restlet.resource.ServerResource; |
| 13 | import org.slf4j.Logger; |
| 14 | import org.slf4j.LoggerFactory; |
| 15 | |
| 16 | public class ListStaticFlowEntriesResource extends ServerResource { |
Yuta HIGUCHI | 6ac8d18 | 2013-10-22 15:24:56 -0700 | [diff] [blame] | 17 | protected final static Logger log = LoggerFactory.getLogger(ListStaticFlowEntriesResource.class); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 18 | |
| 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 | } |