Make negative mapping TTL configurable 60/59560/4
authorLorand Jakab <lojakab@cisco.com>
Tue, 27 Jun 2017 11:34:24 +0000 (14:34 +0300)
committerLorand Jakab <lojakab@cisco.com>
Tue, 27 Jun 2017 19:32:55 +0000 (22:32 +0300)
Change-Id: I08c6ad1517f4cc34747a4762dc604b0de87b2bea
Signed-off-by: Lorand Jakab <lojakab@cisco.com>
mappingservice/config/src/main/java/org/opendaylight/lispflowmapping/config/ConfigIni.java
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/MappingSystem.java

index 32b08fc814808912d67b7ffead8dfaec47e2a2fa..5814cacd3fb05d64906f57688cbfe3454822ba1b 100644 (file)
@@ -26,6 +26,7 @@ public final class ConfigIni {
     private long smrTimeout;
     private int smrRetryCount;
     private boolean authEnabled;
+    private int negativeMappingTTL;
     private int numberOfBucketsInTimeBucketWheel;
 
     /*
@@ -46,11 +47,13 @@ public final class ConfigIni {
     private static final String LISP_SMR_RETRY_COUNT = "lisp.smrRetryCount";
     private static final String LISP_SMR_TIMEOUT = "lisp.smrTimeout";
     private static final String LISP_AUTH_ENABLED = "lisp.authEnabled";
+    private static final String LISP_NEGATIVE_MAPPING_TTL = "lisp.negativeMappingTTL";
 
     // SB Map Register validity period in milliseconds. Default is 3.3 minutes.
     private static final long MIN_REGISTRATION_VALIDITY_SB = 200000L;
     private static final long DEFAULT_SMR_TIMEOUT = 3000L;
     private static final int DEFAULT_SMR_RETRY_COUNT = 5;
+    private static final int DEFAULT_NEGATIVE_MAPPING_TTL = 15;
     private static final int MIN_NUMBER_OF_BUCKETS_IN_TIME_BUCKET_WHEEL = 2;
     private static final int TIMEOUT_TOLERANCE_MULTIPLIER_IN_TIME_BUCKET_WHEEL = 2;
 
@@ -82,6 +85,7 @@ public final class ConfigIni {
         initSmrRetryCount(context);
         initSmrTimeout(context);
         initAuthEnabled(context);
+        initNegativeMappingTTL(context);
         initBucketNumber();
     }
 
@@ -327,6 +331,34 @@ public final class ConfigIni {
         }
     }
 
+    private void initNegativeMappingTTL(BundleContext context) {
+        // set the default value first
+        this.negativeMappingTTL = DEFAULT_NEGATIVE_MAPPING_TTL;
+
+        String str = null;
+
+        if (context != null) {
+            str = context.getProperty(LISP_NEGATIVE_MAPPING_TTL);
+        }
+
+        if (str == null) {
+            str = System.getProperty(LISP_NEGATIVE_MAPPING_TTL);
+            if (str == null) {
+                LOG.debug("Configuration variable '{}' is unset. Setting to default value: '{}'",
+                        LISP_NEGATIVE_MAPPING_TTL, negativeMappingTTL);
+                return;
+            }
+        }
+
+        try {
+            this.negativeMappingTTL = Integer.valueOf(str);
+            LOG.debug("Setting configuration variable '{}' to '{}'", LISP_NEGATIVE_MAPPING_TTL, negativeMappingTTL);
+        } catch (NumberFormatException e) {
+            LOG.debug("Configuration variable '{}' was not set correctly. Negative TTL "
+                    + "is set to default value ({} minutes)", LISP_NEGATIVE_MAPPING_TTL, negativeMappingTTL);
+        }
+    }
+
     //one bucket should contain mapping of approximate 1 min time frame
     private void initBucketNumber() {
         numberOfBucketsInTimeBucketWheel = (int) (TimeUnit.MILLISECONDS.toMinutes(getRegistrationValiditySb()) + 1);
@@ -403,6 +435,15 @@ public final class ConfigIni {
         this.authEnabled = authEnabled;
     }
 
+    public void setNegativeMappingTTL(int negativeMappingTTL) {
+        LOG.debug("Setting configuration variable '{}' to '{}'", LISP_NEGATIVE_MAPPING_TTL, negativeMappingTTL);
+        this.negativeMappingTTL = negativeMappingTTL;
+    }
+
+    public int getNegativeMappingTTL() {
+        return this.negativeMappingTTL;
+    }
+
     public int getNumberOfBucketsInTimeBucketWheel() {
         return numberOfBucketsInTimeBucketWheel;
     }
index f175952ca856fb4d03c9699f5152d195338dc675..ef6f94060307c52f239919797a0ee5632262b8d4 100644 (file)
@@ -80,8 +80,8 @@ import org.slf4j.LoggerFactory;
 public class MappingSystem implements IMappingSystem {
     private static final Logger LOG = LoggerFactory.getLogger(MappingSystem.class);
     private static final String AUTH_KEY_TABLE = "authentication";
-    private static final int TTL_RLOC_TIMED_OUT = 1;
-    private static final int TTL_NO_RLOC_KNOWN = 15;
+    //private static final int TTL_RLOC_TIMED_OUT = 1;
+    private static final int TTL_NO_RLOC_KNOWN = ConfigIni.getInstance().getNegativeMappingTTL();
     private NotificationPublishService notificationPublishService;
     private boolean mappingMerge;
     private ILispDAO dao;
@@ -221,11 +221,11 @@ public class MappingSystem implements IMappingSystem {
             }
         }
         recordBuilder.setAction(LispMessage.NEGATIVE_MAPPING_ACTION);
-        if (getAuthenticationKey(eid) != null) {
-            recordBuilder.setRecordTtl(TTL_RLOC_TIMED_OUT);
-        } else {
-            recordBuilder.setRecordTtl(TTL_NO_RLOC_KNOWN);
-        }
+        //if (getAuthenticationKey(eid) != null) {
+        //    recordBuilder.setRecordTtl(TTL_RLOC_TIMED_OUT);
+        //} else {
+        recordBuilder.setRecordTtl(TTL_NO_RLOC_KNOWN);
+        //}
         return recordBuilder.build();
     }