Make map register cache timeout configurable. 29/42229/2
authorJozef Gloncak <jgloncak@cisco.com>
Thu, 21 Jul 2016 10:39:53 +0000 (12:39 +0200)
committerJozef Gloncak <jgloncak@cisco.com>
Fri, 22 Jul 2016 11:42:19 +0000 (13:42 +0200)
Currently it is possible to configure map register cache
timeout from blueprint.

Change-Id: Ic6ddd8aaf1fed605ca476e8660ebe073a929330f
Signed-off-by: Jozef Gloncak <jgloncak@cisco.com>
mappingservice/southbound/src/main/java/org/opendaylight/lispflowmapping/southbound/LispSouthboundPlugin.java
mappingservice/southbound/src/main/java/org/opendaylight/lispflowmapping/southbound/lisp/LispSouthboundHandler.java
mappingservice/southbound/src/main/resources/org/opendaylight/blueprint/mappingservice-southbound.xml
mappingservice/southbound/src/test/java/org/opendaylight/lispflowmapping/southbound/lisp/LispSouthboundServiceTest.java

index e994cb657b947fe110fc30164afbd6fb4ec9ee7c..a437edd6f282be5964cb66b3564e4565487494a5 100644 (file)
@@ -51,6 +51,8 @@ public class LispSouthboundPlugin implements IConfigLispSouthboundPlugin, AutoCl
 
     private volatile String bindingAddress;
     private boolean mapRegisterCacheEnabled;
+    private long mapRegisterCacheTimeout;
+
     private static Object startLock = new Object();
     private final ClusterNodeModulSwitcherImpl clusterNodeModulSwitcher;
     private LispSouthboundHandler lispSouthboundHandler;
@@ -84,6 +86,7 @@ public class LispSouthboundPlugin implements IConfigLispSouthboundPlugin, AutoCl
             lispSouthboundHandler.setDataBroker(dataBroker);
             lispSouthboundHandler.setNotificationProvider(this.notificationPublishService);
             lispSouthboundHandler.setMapRegisterCacheEnabled(mapRegisterCacheEnabled);
+            lispSouthboundHandler.setMapRegisterCacheTimeout(mapRegisterCacheTimeout);
             lispSouthboundHandler.init();
             lispSouthboundHandler.restoreDaoFromDatastore();
 
@@ -266,6 +269,10 @@ public class LispSouthboundPlugin implements IConfigLispSouthboundPlugin, AutoCl
         }
     }
 
+    public void setMapRegisterCacheTimeout(long mapRegisterCacheTimeout) {
+        this.mapRegisterCacheTimeout = mapRegisterCacheTimeout;
+    }
+
     public void setBindingAddress(String bindingAddress) {
         this.bindingAddress = bindingAddress;
     }
index 2b4cef6af38fd0d26f9b5047fd585575544ca3c7..1f7347df5921165e2d379c6e986b9009a2b45809 100644 (file)
@@ -80,21 +80,15 @@ public class LispSouthboundHandler extends SimpleChannelInboundHandler<DatagramP
         implements ILispSouthboundService, AutoCloseable {
     private MapRegisterCache mapRegisterCache;
     private boolean mapRegisterCacheEnabled = true;
+    private long mapRegisterCacheTimeout;
 
-    /**
-     * How long is record supposed to be relevant. After this time record isn't valid.
-     *
-     * If you modify this value, please update the LispSouthboundServiceTest class too.
-     */
-    private static final long CACHE_RECORD_TIMEOUT = 90000;
     private DataBroker dataBroker;
-
     private NotificationPublishService notificationPublishService;
+
     protected static final Logger LOG = LoggerFactory.getLogger(LispSouthboundHandler.class);
 
     //TODO: think whether this field can be accessed through mappingservice or some other configuration parameter
     private boolean authenticationEnabled = true;
-
     private final LispSouthboundPlugin lispSbPlugin;
     private LispSouthboundStats lispSbStats = null;
     private SimpleMapCache smc;
@@ -271,7 +265,7 @@ public class LispSouthboundHandler extends SimpleChannelInboundHandler<DatagramP
     private MapRegisterCacheValue refreshAuthKeyIfNecessary(MapRegisterCacheValue mapRegisterCacheValue) {
         if (authenticationKeyDataListener.isAuthKeyRefreshing()) {
             final boolean shouldAuthKeyRefreshingStop = System.currentTimeMillis() - authenticationKeyDataListener
-                    .getAuthKeyRefreshingDate() > CACHE_RECORD_TIMEOUT;
+                    .getAuthKeyRefreshingDate() > mapRegisterCacheTimeout;
             if (shouldAuthKeyRefreshingStop) {
                 authenticationKeyDataListener.setAuthKeyRefreshing(false);
             } else {
@@ -299,7 +293,7 @@ public class LispSouthboundHandler extends SimpleChannelInboundHandler<DatagramP
             if (mapRegisterCacheValue != null) {
                 final long creationTime = mapRegisterCacheValue.getMapRegisterCacheMetadata().getTimestamp();
                 final long currentTime = System.currentTimeMillis();
-                if (currentTime - creationTime > CACHE_RECORD_TIMEOUT) {
+                if (currentTime - creationTime > mapRegisterCacheTimeout) {
                     mapRegisterCache.removeEntry(entry.getKey());
                     return null;
                 } else if (Arrays.equals(mapRegisterCacheValue.getPacketData(), entry.getValue())) {
@@ -576,4 +570,8 @@ public class LispSouthboundHandler extends SimpleChannelInboundHandler<DatagramP
     public void setIsReadFromChannelEnabled(boolean isReadFromChannelEnabled) {
         this.isReadFromChannelEnabled = isReadFromChannelEnabled;
     }
+
+    public void setMapRegisterCacheTimeout(long mapRegisterCacheTimeout) {
+        this.mapRegisterCacheTimeout = mapRegisterCacheTimeout;
+    }
 }
index 88dd9d11fd0646d2c56673a8ad12ad85b1e385ad..712a07ce909a6fa0ed312a8c9b104c180390a5fc 100644 (file)
@@ -18,6 +18,7 @@
     <cm:default-properties>
       <cm:property name="bindingAddressProperty" value="0.0.0.0" />
       <cm:property name="mapRegisterCacheEnabledProperty" value="true" />
+      <cm:property name="mapRegisterCacheTimeoutProperty" value="90000"/>
     </cm:default-properties>
   </cm:property-placeholder>
 
@@ -29,6 +30,7 @@
     <argument ref="entityOwnershipService" />
     <property name="bindingAddress" value="${bindingAddressProperty}"/>
     <property name="mapRegisterCacheEnabled" value="${mapRegisterCacheEnabledProperty}"/>
+    <property name="mapRegisterCacheTimeout" value="${mapRegisterCacheTimeoutProperty}"/>
   </bean>
   <service ref="lispSouthboundPlugin"
     interface="org.opendaylight.lispflowmapping.type.sbplugin.IConfigLispSouthboundPlugin"
index e3c04d7dba31687092850a994959224364cc7f1e..05dd45b7ae8fd686f93a26fcd7bfdfceed0912c8 100644 (file)
@@ -154,6 +154,7 @@ public class LispSouthboundServiceTest extends BaseTestCase {
         mockLispSouthboundPlugin = mock(LispSouthboundPlugin.class);
         Mockito.when(mockLispSouthboundPlugin.getStats()).thenReturn(Mockito.mock(LispSouthboundStats.class));
         testedLispService = new LispSouthboundHandler(mockLispSouthboundPlugin);
+        testedLispService.setMapRegisterCacheTimeout(90000);
         mapRegisterCache = new MapRegisterCache();
         testedLispService.setMapRegisterCache(mapRegisterCache);
         testedLispService.setDataBroker(Mockito.mock(DataBroker.class));