BUG-4084: Li:Save flows in operational based on barrier success
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / device / DeviceContextImpl.java
index 0f70c7ac1e06c65102ceca7f13df3d198db97ea1..16ae98f5996fd690e030f2bd7e4359cb4f90eb86 100644 (file)
@@ -41,6 +41,7 @@ import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceContex
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.MultiMsgCollector;
 import org.opendaylight.openflowplugin.api.openflow.md.core.SwitchConnectionDistinguisher;
 import org.opendaylight.openflowplugin.api.openflow.md.core.TranslatorKey;
+import org.opendaylight.openflowplugin.api.openflow.registry.ItemLifeCycleRegistry;
 import org.opendaylight.openflowplugin.api.openflow.registry.flow.DeviceFlowRegistry;
 import org.opendaylight.openflowplugin.api.openflow.registry.group.DeviceGroupRegistry;
 import org.opendaylight.openflowplugin.api.openflow.registry.meter.DeviceMeterRegistry;
@@ -84,11 +85,12 @@ public class DeviceContextImpl implements DeviceContext {
 
     private static final Logger LOG = LoggerFactory.getLogger(DeviceContextImpl.class);
 
-    // TODO: watermarks should be derived from effective rpc limit (75%|95%)
-    private static final int PACKETIN_LOW_WATERMARK = 15000;
-    private static final int PACKETIN_HIGH_WATERMARK = 19000;
     // TODO: drain factor should be parametrized
     public static final float REJECTED_DRAIN_FACTOR = 0.25f;
+    // TODO: low water mark factor should be parametrized
+    private static final float LOW_WATERMARK_FACTOR = 0.75f;
+    // TODO: high water mark factor should be parametrized
+    private static final float HIGH_WATERMARK_FACTOR = 0.95f;
 
     private final ConnectionContext primaryConnectionContext;
     private final DeviceState deviceState;
@@ -110,6 +112,7 @@ public class DeviceContextImpl implements DeviceContext {
     private final MessageTranslator<PacketInMessage, PacketReceived> packetInTranslator;
     private final TranslatorLibrary translatorLibrary;
     private Map<Long, NodeConnectorRef> nodeConnectorCache;
+    private ItemLifeCycleRegistry itemLifeCycleSourceRegistry;
 
 
     @VisibleForTesting
@@ -134,7 +137,7 @@ public class DeviceContextImpl implements DeviceContext {
         messageSpy = _messageSpy;
 
         packetInLimiter = new PacketInRateLimiter(primaryConnectionContext.getConnectionAdapter(),
-                PACKETIN_LOW_WATERMARK, PACKETIN_HIGH_WATERMARK, messageSpy, REJECTED_DRAIN_FACTOR);
+                /*initial*/ 1000, /*initial*/2000, messageSpy, REJECTED_DRAIN_FACTOR);
 
         this.translatorLibrary = translatorLibrary;
         portStatusTranslator = translatorLibrary.lookupTranslator(
@@ -142,6 +145,8 @@ public class DeviceContextImpl implements DeviceContext {
         packetInTranslator = translatorLibrary.lookupTranslator(
                 new TranslatorKey(deviceState.getVersion(), PacketIn.class.getName()));
         nodeConnectorCache = new ConcurrentHashMap<>();
+
+        itemLifeCycleSourceRegistry = new ItemLifeCycleRegistryImpl();
     }
 
     /**
@@ -351,6 +356,8 @@ public class DeviceContextImpl implements DeviceContext {
         deviceFlowRegistry.close();
         deviceMeterRegistry.close();
 
+        itemLifeCycleSourceRegistry.clear();
+
 
         for (final DeviceContextClosedHandler deviceContextClosedHandler : closeHandlers) {
             deviceContextClosedHandler.onDeviceContextClosed(this);
@@ -430,4 +437,14 @@ public class DeviceContextImpl implements DeviceContext {
                 Preconditions.checkNotNull(portNumber),
                 Preconditions.checkNotNull(nodeConnectorRef));
     }
+
+    @Override
+    public void updatePacketInRateLimit(long upperBound) {
+        packetInLimiter.changeWaterMarks((int) (LOW_WATERMARK_FACTOR * upperBound), (int) (HIGH_WATERMARK_FACTOR * upperBound));
+    }
+
+    @Override
+    public ItemLifeCycleRegistry getItemLifeCycleSourceRegistry() {
+        return itemLifeCycleSourceRegistry;
+    }
 }