diff --git a/src/main/java/net/floodlightcontroller/core/OFSwitchBase.java b/src/main/java/net/floodlightcontroller/core/OFSwitchBase.java index 1c4e03f5c56e200dc94b86bdd702eb89d4250dcb..3881792e62cd65d7d45a5e1c441ccf9290036236 100644 --- a/src/main/java/net/floodlightcontroller/core/OFSwitchBase.java +++ b/src/main/java/net/floodlightcontroller/core/OFSwitchBase.java @@ -41,6 +41,7 @@ import net.floodlightcontroller.core.annotations.LogMessageDocs; import net.floodlightcontroller.core.internal.Controller; import net.floodlightcontroller.core.internal.OFFeaturesReplyFuture; import net.floodlightcontroller.core.internal.OFStatisticsFuture; +import net.floodlightcontroller.core.util.AppCookie; import net.floodlightcontroller.core.web.serializers.DPIDSerializer; import net.floodlightcontroller.devicemanager.SwitchPort; import net.floodlightcontroller.packet.Ethernet; @@ -144,9 +145,8 @@ public abstract class OFSwitchBase implements IOFSwitch { } }; - // for managing our map sizes - protected static int MAX_MACS_PER_SWITCH = 1000; - + public static final int OFSWITCH_APP_ID = 5; + public OFSwitchBase() { this.stringId = null; this.attributes = new ConcurrentHashMap<Object, Object>(); @@ -930,7 +930,8 @@ public abstract class OFSwitchBase implements IOFSwitch { int port = pin.getInPort(); SwitchPort swPort = new SwitchPort(getId(), port); 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", srcMac.toString(), swPort); } @@ -954,7 +955,8 @@ public abstract class OFSwitchBase implements IOFSwitch { // write out drop flow per port SwitchPort swPort = new SwitchPort(getId(), port); 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", swPort); } diff --git a/src/main/java/net/floodlightcontroller/core/util/AppCookie.java b/src/main/java/net/floodlightcontroller/core/util/AppCookie.java index 210823efc38410b6b518878dcd77d486ac1ff8cb..3ea5075958e5ba9f61b65bf0c76df45a371310d4 100644 --- a/src/main/java/net/floodlightcontroller/core/util/AppCookie.java +++ b/src/main/java/net/floodlightcontroller/core/util/AppCookie.java @@ -17,6 +17,8 @@ package net.floodlightcontroller.core.util; +import java.util.concurrent.ConcurrentHashMap; + /*** * FIXME Need a system for registering/binding applications to a unique ID * @@ -31,6 +33,8 @@ public class AppCookie { static final int USER_BITS = 32; 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 @@ -51,4 +55,22 @@ public class AppCookie { static public int extractUser(long cookie) { 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); + } + } } diff --git a/src/main/java/net/floodlightcontroller/core/util/AppIDInUseException.java b/src/main/java/net/floodlightcontroller/core/util/AppIDInUseException.java new file mode 100644 index 0000000000000000000000000000000000000000..0353c024fad225ad8c612b712e00a0a8f56bf50c --- /dev/null +++ b/src/main/java/net/floodlightcontroller/core/util/AppIDInUseException.java @@ -0,0 +1,9 @@ +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 diff --git a/src/main/java/net/floodlightcontroller/forwarding/Forwarding.java b/src/main/java/net/floodlightcontroller/forwarding/Forwarding.java index ba31a3adf9b680e0ad48d715c57dbf0d602b2021..267ad58c733db378655d4b4610bae887886c3911 100644 --- a/src/main/java/net/floodlightcontroller/forwarding/Forwarding.java +++ b/src/main/java/net/floodlightcontroller/forwarding/Forwarding.java @@ -38,6 +38,7 @@ import net.floodlightcontroller.core.module.FloodlightModuleException; import net.floodlightcontroller.core.module.IFloodlightModule; import net.floodlightcontroller.core.module.IFloodlightService; import net.floodlightcontroller.core.util.AppCookie; +import net.floodlightcontroller.core.util.AppIDInUseException; import net.floodlightcontroller.counter.ICounterStoreService; import net.floodlightcontroller.packet.Ethernet; import net.floodlightcontroller.routing.ForwardingBase; @@ -443,6 +444,13 @@ public class Forwarding extends ForwardingBase implements IFloodlightModule { FLOWMOD_DEFAULT_IDLE_TIMEOUT); log.debug("FlowMod hard timeout set to {} seconds", 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 diff --git a/src/main/java/net/floodlightcontroller/staticflowentry/StaticFlowEntryPusher.java b/src/main/java/net/floodlightcontroller/staticflowentry/StaticFlowEntryPusher.java index 106716dc748f0b7fa7d9cf27d9b976c5e636ef37..b253eda23dbb54cf19d54e038c57cee04dd63e65 100644 --- a/src/main/java/net/floodlightcontroller/staticflowentry/StaticFlowEntryPusher.java +++ b/src/main/java/net/floodlightcontroller/staticflowentry/StaticFlowEntryPusher.java @@ -43,6 +43,7 @@ import net.floodlightcontroller.core.module.FloodlightModuleException; import net.floodlightcontroller.core.module.IFloodlightModule; import net.floodlightcontroller.core.module.IFloodlightService; import net.floodlightcontroller.core.util.AppCookie; +import net.floodlightcontroller.core.util.AppIDInUseException; import net.floodlightcontroller.restserver.IRestApiService; import net.floodlightcontroller.staticflowentry.web.StaticFlowEntryWebRoutable; import net.floodlightcontroller.storage.IResultSet; @@ -656,6 +657,12 @@ public class StaticFlowEntryPusher restApi = context.getServiceImpl(IRestApiService.class); 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 diff --git a/src/main/java/net/floodlightcontroller/virtualnetwork/VirtualNetworkFilter.java b/src/main/java/net/floodlightcontroller/virtualnetwork/VirtualNetworkFilter.java index 3e227bde13f3853eb45f8586a04cb3369346bf6d..627103905377827ec2b9432874a62da3838de065 100644 --- a/src/main/java/net/floodlightcontroller/virtualnetwork/VirtualNetworkFilter.java +++ b/src/main/java/net/floodlightcontroller/virtualnetwork/VirtualNetworkFilter.java @@ -48,6 +48,7 @@ import net.floodlightcontroller.core.module.FloodlightModuleException; import net.floodlightcontroller.core.module.IFloodlightModule; import net.floodlightcontroller.core.module.IFloodlightService; import net.floodlightcontroller.core.util.AppCookie; +import net.floodlightcontroller.core.util.AppIDInUseException; import net.floodlightcontroller.devicemanager.IDevice; import net.floodlightcontroller.devicemanager.IDeviceListener; import net.floodlightcontroller.devicemanager.IDeviceService; @@ -311,6 +312,12 @@ public class VirtualNetworkFilter portToMac = new ConcurrentHashMap<String, MACAddress>(); macToGateway = new ConcurrentHashMap<MACAddress, Integer>(); 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