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

When you clear static flows via the REST API you can now specify "all" or a DPID in hex format.

parent 89f2dc1c
No related branches found
No related tags found
No related merge requests found
......@@ -19,6 +19,12 @@ public interface IStaticFlowEntryPusherService extends IFloodlightService {
*/
public void deleteFlow(String name);
/**
* Deletes all static flows for a practicular switch
* @param dpid The DPID of the switch to delete flows for.
*/
public void deleteFlowsForSwitch(long dpid);
/**
* Deletes all flows.
*/
......
......@@ -156,59 +156,61 @@ public class StaticFlowEntries {
* @return A string of the actions encoded for our database
*/
private static String flowModActionsToString(List<OFAction> fmActions) {
// TODO commas?, make a string array then join with commas in between
// TODO - some values may be in hex....i.e. ethertype
String actions = "";
StringBuilder sb = new StringBuilder();
for (OFAction a : fmActions) {
if (sb.length() > 0) {
sb.append(',');
}
switch(a.getType()) {
case OUTPUT:
actions += "output=" + Short.toString(((OFActionOutput)a).getPort());
sb.append("output=" + Short.toString(((OFActionOutput)a).getPort()));
break;
case OPAQUE_ENQUEUE:
actions += "enqueue=" + Integer.toString(((OFActionEnqueue)a).getQueueId());
sb.append("enqueue=" + Integer.toString(((OFActionEnqueue)a).getQueueId()));
break;
case SET_VLAN_ID:
actions += "set-vlan-id=" +
Short.toString(((OFActionVirtualLanIdentifier)a).getVirtualLanIdentifier());
sb.append("set-vlan-id=" +
Short.toString(((OFActionVirtualLanIdentifier)a).getVirtualLanIdentifier()));
break;
case SET_VLAN_PCP:
actions += "set-vlan-priority=" +
Byte.toString(((OFActionVirtualLanPriorityCodePoint)a).getVirtualLanPriorityCodePoint());
sb.append("set-vlan-priority=" +
Byte.toString(((OFActionVirtualLanPriorityCodePoint)a).getVirtualLanPriorityCodePoint()));
break;
case SET_DL_SRC:
actions += "set-src-mac=" +
HexString.toHexString(((OFActionDataLayerSource)a).getDataLayerAddress());
sb.append("set-src-mac=" +
HexString.toHexString(((OFActionDataLayerSource)a).getDataLayerAddress()));
break;
case SET_DL_DST:
actions += "set-dst-mac=" +
HexString.toHexString(((OFActionDataLayerDestination)a).getDataLayerAddress());
sb.append("set-dst-mac=" +
HexString.toHexString(((OFActionDataLayerDestination)a).getDataLayerAddress()));
break;
case SET_NW_TOS:
actions += "set-tos-bits=" +
Byte.toString(((OFActionNetworkTypeOfService)a).getNetworkTypeOfService());
sb.append("set-tos-bits=" +
Byte.toString(((OFActionNetworkTypeOfService)a).getNetworkTypeOfService()));
break;
case SET_NW_SRC:
actions += "set-nw-src=" +
IPv4.fromIPv4Address(((OFActionNetworkLayerSource)a).getNetworkAddress());
sb.append("set-nw-src=" +
IPv4.fromIPv4Address(((OFActionNetworkLayerSource)a).getNetworkAddress()));
break;
case SET_NW_DST:
actions += "set-nw-dst=" +
IPv4.fromIPv4Address(((OFActionNetworkLayerDestination)a).getNetworkAddress());
sb.append("set-nw-dst=" +
IPv4.fromIPv4Address(((OFActionNetworkLayerDestination)a).getNetworkAddress()));
break;
case SET_TP_SRC:
actions += "set-src-port=" +
Short.toString(((OFActionTransportLayerSource)a).getTransportPort());
sb.append("set-src-port=" +
Short.toString(((OFActionTransportLayerSource)a).getTransportPort()));
break;
case SET_TP_DST:
actions += "set-dst-port=" +
Short.toString(((OFActionTransportLayerDestination)a).getTransportPort());
sb.append("set-dst-port=" +
Short.toString(((OFActionTransportLayerDestination)a).getTransportPort()));
break;
default:
log.error("Could not decode action " + a);
break;
}
}
return actions;
return sb.toString();
}
/**
......
......@@ -9,6 +9,7 @@ import java.util.Iterator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import net.floodlightcontroller.core.FloodlightContext;
......@@ -579,4 +580,14 @@ public class StaticFlowEntryPusher
deleteFlow(entry);
}
}
@Override
public void deleteFlowsForSwitch(long dpid) {
String sDpid = HexString.toHexString(dpid);
for (Entry<String, String> e : entry2dpid.entrySet()) {
if (e.getValue().equals(sDpid))
deleteFlow(e.getKey());
}
}
}
......@@ -2,6 +2,7 @@ package net.floodlightcontroller.staticflowentry.web;
import net.floodlightcontroller.staticflowentry.IStaticFlowEntryPusherService;
import org.openflow.util.HexString;
import org.restlet.resource.Get;
import org.restlet.resource.ServerResource;
import org.slf4j.Logger;
......@@ -15,7 +16,19 @@ public class ClearStaticFlowEntriesResource extends ServerResource {
IStaticFlowEntryPusherService sfpService =
(IStaticFlowEntryPusherService)getContext().getAttributes().
get(IStaticFlowEntryPusherService.class.getCanonicalName());
log.debug("Clearing all static flow entires");
sfpService.deleteAllFlows();
String param = (String) getRequestAttributes().get("switch");
if (log.isDebugEnabled())
log.debug("Clearing all static flow entires for switch: " + param);
if (param.toLowerCase().equals("all")) {
sfpService.deleteAllFlows();
} else {
try {
sfpService.deleteFlowsForSwitch(HexString.toLong(param));
} catch (NumberFormatException e){
log.error("Could not parse switch DPID: " + e.getMessage());
}
}
}
}
......@@ -14,7 +14,7 @@ public class StaticFlowEntryWebRoutable implements RestletRoutable {
public Restlet getRestlet(Context context) {
Router router = new Router(context);
router.attach("/json", StaticFlowEntryPusherResource.class);
router.attach("/clear/json", ClearStaticFlowEntriesResource.class);
router.attach("/clear/{switch}/json", ClearStaticFlowEntriesResource.class);
return router;
}
......
......@@ -75,7 +75,7 @@ public class HexString {
return ret;
}
public static long toLong(String values) {
public static long toLong(String values) throws NumberFormatException {
return Long.parseLong(values.replaceAll(":", ""),16);
}
......
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