Skip to content
Snippets Groups Projects
Commit 19257038 authored by abat's avatar abat
Browse files

Merge into master from pull request #3237:

Add AppCookie.registerApp() and block flow mod cookies (https://github.com/bigswitch/bigswitchcontroller/pull/3237)
parents 4da18150 d09adf83
No related branches found
No related tags found
No related merge requests found
...@@ -41,6 +41,7 @@ import net.floodlightcontroller.core.annotations.LogMessageDocs; ...@@ -41,6 +41,7 @@ import net.floodlightcontroller.core.annotations.LogMessageDocs;
import net.floodlightcontroller.core.internal.Controller; import net.floodlightcontroller.core.internal.Controller;
import net.floodlightcontroller.core.internal.OFFeaturesReplyFuture; import net.floodlightcontroller.core.internal.OFFeaturesReplyFuture;
import net.floodlightcontroller.core.internal.OFStatisticsFuture; import net.floodlightcontroller.core.internal.OFStatisticsFuture;
import net.floodlightcontroller.core.util.AppCookie;
import net.floodlightcontroller.core.web.serializers.DPIDSerializer; import net.floodlightcontroller.core.web.serializers.DPIDSerializer;
import net.floodlightcontroller.devicemanager.SwitchPort; import net.floodlightcontroller.devicemanager.SwitchPort;
import net.floodlightcontroller.packet.Ethernet; import net.floodlightcontroller.packet.Ethernet;
...@@ -144,9 +145,8 @@ public abstract class OFSwitchBase implements IOFSwitch { ...@@ -144,9 +145,8 @@ public abstract class OFSwitchBase implements IOFSwitch {
} }
}; };
// for managing our map sizes public static final int OFSWITCH_APP_ID = 5;
protected static int MAX_MACS_PER_SWITCH = 1000;
public OFSwitchBase() { public OFSwitchBase() {
this.stringId = null; this.stringId = null;
this.attributes = new ConcurrentHashMap<Object, Object>(); this.attributes = new ConcurrentHashMap<Object, Object>();
...@@ -930,7 +930,8 @@ public abstract class OFSwitchBase implements IOFSwitch { ...@@ -930,7 +930,8 @@ public abstract class OFSwitchBase implements IOFSwitch {
int port = pin.getInPort(); int port = pin.getInPort();
SwitchPort swPort = new SwitchPort(getId(), port); SwitchPort swPort = new SwitchPort(getId(), port);
ForwardingBase.blockHost(floodlightProvider, ForwardingBase.blockHost(floodlightProvider,
swPort, srcMac.toLong(), (short) 5, 0); swPort, srcMac.toLong(), (short) 5,
AppCookie.makeCookie(OFSWITCH_APP_ID, 0));
log.info("Excessive packet in from {} on {}, block host for 5 sec", log.info("Excessive packet in from {} on {}, block host for 5 sec",
srcMac.toString(), swPort); srcMac.toString(), swPort);
} }
...@@ -954,7 +955,8 @@ public abstract class OFSwitchBase implements IOFSwitch { ...@@ -954,7 +955,8 @@ public abstract class OFSwitchBase implements IOFSwitch {
// write out drop flow per port // write out drop flow per port
SwitchPort swPort = new SwitchPort(getId(), port); SwitchPort swPort = new SwitchPort(getId(), port);
ForwardingBase.blockHost(floodlightProvider, ForwardingBase.blockHost(floodlightProvider,
swPort, -1L, (short) 5, 0); swPort, -1L, (short) 5,
AppCookie.makeCookie(OFSWITCH_APP_ID, 1));
log.info("Excessive packet in from {}, block port for 5 sec", log.info("Excessive packet in from {}, block port for 5 sec",
swPort); swPort);
} }
......
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
package net.floodlightcontroller.core.util; package net.floodlightcontroller.core.util;
import java.util.concurrent.ConcurrentHashMap;
/*** /***
* FIXME Need a system for registering/binding applications to a unique ID * FIXME Need a system for registering/binding applications to a unique ID
* *
...@@ -31,6 +33,8 @@ public class AppCookie { ...@@ -31,6 +33,8 @@ public class AppCookie {
static final int USER_BITS = 32; static final int USER_BITS = 32;
static final int USER_SHIFT = 0; static final int USER_SHIFT = 0;
private static ConcurrentHashMap<Integer, String> appIdMap =
new ConcurrentHashMap<Integer, String>();
/** /**
* Encapsulate an application ID and a user block of stuff into a cookie * Encapsulate an application ID and a user block of stuff into a cookie
...@@ -51,4 +55,22 @@ public class AppCookie { ...@@ -51,4 +55,22 @@ public class AppCookie {
static public int extractUser(long cookie) { static public int extractUser(long cookie) {
return (int)((cookie>> USER_SHIFT) & ((1L << USER_BITS) - 1)); return (int)((cookie>> USER_SHIFT) & ((1L << USER_BITS) - 1));
} }
/**
* A lame attempt to prevent duplicate application ID.
* TODO: Once bigdb is merged, we should expose appID->appName map
* via REST API so CLI doesn't need a separate copy of the map.
*
* @param application
* @param appName
* @throws AppIDInUseException
*/
static public void registerApp(int application, String appName)
throws AppIDInUseException
{
String oldApp = appIdMap.putIfAbsent(application, appName);
if (oldApp != null) {
throw new AppIDInUseException(application, oldApp);
}
}
} }
package net.floodlightcontroller.core.util;
public class AppIDInUseException extends Exception {
private static final long serialVersionUID = 3167241821651094997L;
public AppIDInUseException(int appId, String appName) {
super("Application ID " + appId + " already used by " + appName);
}
}
\ No newline at end of file
...@@ -38,6 +38,7 @@ import net.floodlightcontroller.core.module.FloodlightModuleException; ...@@ -38,6 +38,7 @@ import net.floodlightcontroller.core.module.FloodlightModuleException;
import net.floodlightcontroller.core.module.IFloodlightModule; import net.floodlightcontroller.core.module.IFloodlightModule;
import net.floodlightcontroller.core.module.IFloodlightService; import net.floodlightcontroller.core.module.IFloodlightService;
import net.floodlightcontroller.core.util.AppCookie; import net.floodlightcontroller.core.util.AppCookie;
import net.floodlightcontroller.core.util.AppIDInUseException;
import net.floodlightcontroller.counter.ICounterStoreService; import net.floodlightcontroller.counter.ICounterStoreService;
import net.floodlightcontroller.packet.Ethernet; import net.floodlightcontroller.packet.Ethernet;
import net.floodlightcontroller.routing.ForwardingBase; import net.floodlightcontroller.routing.ForwardingBase;
...@@ -443,6 +444,13 @@ public class Forwarding extends ForwardingBase implements IFloodlightModule { ...@@ -443,6 +444,13 @@ public class Forwarding extends ForwardingBase implements IFloodlightModule {
FLOWMOD_DEFAULT_IDLE_TIMEOUT); FLOWMOD_DEFAULT_IDLE_TIMEOUT);
log.debug("FlowMod hard timeout set to {} seconds", log.debug("FlowMod hard timeout set to {} seconds",
FLOWMOD_DEFAULT_HARD_TIMEOUT); FLOWMOD_DEFAULT_HARD_TIMEOUT);
try {
AppCookie.registerApp(FORWARDING_APP_ID, "Forwarding");
} catch (AppIDInUseException e) {
// This is not fatal, CLI will be confused
log.error("Failed register application ID", e);
}
} }
@Override @Override
......
...@@ -43,6 +43,7 @@ import net.floodlightcontroller.core.module.FloodlightModuleException; ...@@ -43,6 +43,7 @@ import net.floodlightcontroller.core.module.FloodlightModuleException;
import net.floodlightcontroller.core.module.IFloodlightModule; import net.floodlightcontroller.core.module.IFloodlightModule;
import net.floodlightcontroller.core.module.IFloodlightService; import net.floodlightcontroller.core.module.IFloodlightService;
import net.floodlightcontroller.core.util.AppCookie; import net.floodlightcontroller.core.util.AppCookie;
import net.floodlightcontroller.core.util.AppIDInUseException;
import net.floodlightcontroller.restserver.IRestApiService; import net.floodlightcontroller.restserver.IRestApiService;
import net.floodlightcontroller.staticflowentry.web.StaticFlowEntryWebRoutable; import net.floodlightcontroller.staticflowentry.web.StaticFlowEntryWebRoutable;
import net.floodlightcontroller.storage.IResultSet; import net.floodlightcontroller.storage.IResultSet;
...@@ -656,6 +657,12 @@ public class StaticFlowEntryPusher ...@@ -656,6 +657,12 @@ public class StaticFlowEntryPusher
restApi = restApi =
context.getServiceImpl(IRestApiService.class); context.getServiceImpl(IRestApiService.class);
haListener = new HAListenerDelegate(); haListener = new HAListenerDelegate();
try {
AppCookie.registerApp(STATIC_FLOW_APP_ID, StaticFlowName);
} catch (AppIDInUseException e) {
// This is not fatal, CLI will be confused
log.error("Failed register application ID", e);
}
} }
@Override @Override
......
...@@ -48,6 +48,7 @@ import net.floodlightcontroller.core.module.FloodlightModuleException; ...@@ -48,6 +48,7 @@ import net.floodlightcontroller.core.module.FloodlightModuleException;
import net.floodlightcontroller.core.module.IFloodlightModule; import net.floodlightcontroller.core.module.IFloodlightModule;
import net.floodlightcontroller.core.module.IFloodlightService; import net.floodlightcontroller.core.module.IFloodlightService;
import net.floodlightcontroller.core.util.AppCookie; import net.floodlightcontroller.core.util.AppCookie;
import net.floodlightcontroller.core.util.AppIDInUseException;
import net.floodlightcontroller.devicemanager.IDevice; import net.floodlightcontroller.devicemanager.IDevice;
import net.floodlightcontroller.devicemanager.IDeviceListener; import net.floodlightcontroller.devicemanager.IDeviceListener;
import net.floodlightcontroller.devicemanager.IDeviceService; import net.floodlightcontroller.devicemanager.IDeviceService;
...@@ -311,6 +312,12 @@ public class VirtualNetworkFilter ...@@ -311,6 +312,12 @@ public class VirtualNetworkFilter
portToMac = new ConcurrentHashMap<String, MACAddress>(); portToMac = new ConcurrentHashMap<String, MACAddress>();
macToGateway = new ConcurrentHashMap<MACAddress, Integer>(); macToGateway = new ConcurrentHashMap<MACAddress, Integer>();
deviceListener = new DeviceListenerImpl(); deviceListener = new DeviceListenerImpl();
try {
AppCookie.registerApp(APP_ID, "VirtualNetworkFilter");
} catch (AppIDInUseException e) {
// This is not fatal, CLI will be confused
log.error("Failed register application ID", e);
}
} }
@Override @Override
......
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