blob: fe708776b08222232d43800fa0c24dfb498de0a6 [file] [log] [blame]
HIGUCHI Yuta8d0d1842013-06-12 11:46:01 -07001package net.onrc.onos.ofcontroller.core.web;
Jonathan Hart02102892013-04-10 12:55:50 -07002
3import java.io.IOException;
4import java.util.ArrayList;
5import java.util.List;
6import java.util.Map;
7
8import net.floodlightcontroller.core.IFloodlightProviderService;
9import net.floodlightcontroller.core.IOFSwitch;
10
11import org.codehaus.jackson.map.ObjectMapper;
12import org.openflow.util.HexString;
13import org.restlet.resource.Post;
14import org.restlet.resource.ServerResource;
15import org.slf4j.Logger;
16import org.slf4j.LoggerFactory;
17
18public class ClearFlowTableResource extends ServerResource {
Yuta HIGUCHI6ac8d182013-10-22 15:24:56 -070019 final static Logger log = LoggerFactory.getLogger(ClearFlowTableResource.class);
Jonathan Hart02102892013-04-10 12:55:50 -070020
21 @Post("json")
22 public List<String> ClearFlowTable(String jsonData){
23 IFloodlightProviderService floodlightProvider =
24 (IFloodlightProviderService) getContext().getAttributes()
25 .get(IFloodlightProviderService.class.getCanonicalName());
26
27 Map<Long, IOFSwitch> switches = floodlightProvider.getSwitches();
28
29 List<String> response = new ArrayList<String>();
30 ObjectMapper mapper = new ObjectMapper();
31 String[] dpids = null;
32 try {
33 dpids = mapper.readValue(jsonData, String[].class);
34 } catch (IOException e) {
35 log.debug("Error parsing switch dpid array: {}", e.getMessage());
36 response.add("Error parsing input");
37 return response;
38 }
39
40
41 for (String dpid : dpids){
42 IOFSwitch sw = switches.get(HexString.toLong(dpid));
43 if (sw != null){
44 sw.clearAllFlowMods();
45 response.add(dpid + " cleared");
46 }
47 else {
48 response.add(dpid + " not found");
49 }
50 }
51
52 return response;
53 }
54
55}