Skip to content
Snippets Groups Projects
Commit af0fb439 authored by Alex Reimers's avatar Alex Reimers
Browse files

Added an API to list all static flows by switch. The URL is:

/wm/staticflowentrypusher/list/{switch}/json
{switch} can be 'all' or a DPID in Hex format, i.e. '00:00:00:00:00:00:00:01'
parent 50242748
No related branches found
No related tags found
No related merge requests found
package net.floodlightcontroller.staticflowentry;
import java.util.Map;
import org.openflow.protocol.OFFlowMod;
import net.floodlightcontroller.core.module.IFloodlightService;
......@@ -29,4 +31,14 @@ public interface IStaticFlowEntryPusherService extends IFloodlightService {
* Deletes all flows.
*/
public void deleteAllFlows();
/**
* Gets all list of all flows
*/
public Map<String, Map<String, OFFlowMod>> getFlows();
/**
* Gets a list of flows by switch
*/
public Map<String, OFFlowMod> getFlows(String dpid);
}
......@@ -11,6 +11,7 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import net.floodlightcontroller.core.FloodlightContext;
import net.floodlightcontroller.core.IFloodlightProviderService;
......@@ -86,7 +87,7 @@ public class StaticFlowEntryPusher
protected IRestApiService restApi;
// Map<DPID, Map<Name, FlowMod>> ; FlowMod can be null to indicate non-active
protected HashMap<String, Map<String, OFFlowMod>> entriesFromStorage;
protected Map<String, Map<String, OFFlowMod>> entriesFromStorage;
// Entry Name -> DPID of Switch it's on
protected Map<String, String> entry2dpid;
......@@ -176,7 +177,7 @@ public class StaticFlowEntryPusher
*/
protected Map<String, String> computeEntry2DpidMap(
HashMap<String, Map<String, OFFlowMod>> map) {
Map<String, Map<String, OFFlowMod>> map) {
Map<String, String> ret = new HashMap<String, String>();
for(String dpid : map.keySet()) {
for( String entry: map.get(dpid).keySet())
......@@ -191,8 +192,8 @@ public class StaticFlowEntryPusher
* @return
*/
private HashMap<String, Map<String, OFFlowMod>> readEntriesFromStorage() {
HashMap<String, Map<String, OFFlowMod>> entries = new HashMap<String, Map<String, OFFlowMod>>();
private Map<String, Map<String, OFFlowMod>> readEntriesFromStorage() {
Map<String, Map<String, OFFlowMod>> entries = new ConcurrentHashMap<String, Map<String, OFFlowMod>>();
try {
Map<String, Object> row;
// null1=no predicate, null2=no ordering
......@@ -221,7 +222,7 @@ public class StaticFlowEntryPusher
*/
void parseRow(Map<String, Object> row,
HashMap<String, Map<String, OFFlowMod>> entries) {
Map<String, Map<String, OFFlowMod>> entries) {
String switchName = null;
String entryName = null;
......@@ -590,4 +591,14 @@ public class StaticFlowEntryPusher
deleteFlow(e.getKey());
}
}
@Override
public Map<String, Map<String, OFFlowMod>> getFlows() {
return entriesFromStorage;
}
@Override
public Map<String, OFFlowMod> getFlows(String dpid) {
return entriesFromStorage.get(dpid);
}
}
......@@ -12,7 +12,7 @@ public class ClearStaticFlowEntriesResource extends ServerResource {
protected static Logger log = LoggerFactory.getLogger(ClearStaticFlowEntriesResource.class);
@Get
public void IStaticFlowEntryPusherService() {
public void ClearStaticFlowEntries() {
IStaticFlowEntryPusherService sfpService =
(IStaticFlowEntryPusherService)getContext().getAttributes().
get(IStaticFlowEntryPusherService.class.getCanonicalName());
......
package net.floodlightcontroller.staticflowentry.web;
import java.util.HashMap;
import java.util.Map;
import net.floodlightcontroller.staticflowentry.IStaticFlowEntryPusherService;
import org.openflow.protocol.OFFlowMod;
import org.restlet.resource.Get;
import org.restlet.resource.ServerResource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ListStaticFlowEntriesResource extends ServerResource {
protected static Logger log = LoggerFactory.getLogger(ListStaticFlowEntriesResource.class);
@Get
public Map<String, Map<String, OFFlowMod>> ListStaticFlowEntries() {
IStaticFlowEntryPusherService sfpService =
(IStaticFlowEntryPusherService)getContext().getAttributes().
get(IStaticFlowEntryPusherService.class.getCanonicalName());
String param = (String) getRequestAttributes().get("switch");
if (log.isDebugEnabled())
log.debug("Listing all static flow entires for switch: " + param);
if (param.toLowerCase().equals("all")) {
return sfpService.getFlows();
} else {
try {
Map<String, Map<String, OFFlowMod>> retMap =
new HashMap<String, Map<String, OFFlowMod>>();
retMap.put(param, sfpService.getFlows(param));
return retMap;
} catch (NumberFormatException e){
log.error("Could not parse switch DPID: " + e.getMessage());
}
}
return null;
}
}
......@@ -15,6 +15,7 @@ public class StaticFlowEntryWebRoutable implements RestletRoutable {
Router router = new Router(context);
router.attach("/json", StaticFlowEntryPusherResource.class);
router.attach("/clear/{switch}/json", ClearStaticFlowEntriesResource.class);
router.attach("/list/{switch}/json", ListStaticFlowEntriesResource.class);
return router;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment