2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.lispflowmapping.config;
10 import java.util.concurrent.TimeUnit;
11 import org.opendaylight.lispflowmapping.interfaces.mappingservice.IMappingService;
12 import org.osgi.framework.Bundle;
13 import org.osgi.framework.BundleContext;
14 import org.osgi.framework.FrameworkUtil;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
18 public final class ConfigIni {
20 protected static final Logger LOG = LoggerFactory.getLogger(ConfigIni.class);
21 private boolean mappingMerge;
23 private String elpPolicy;
24 private IMappingService.LookupPolicy lookupPolicy;
25 private long registrationValiditySb;
26 private long smrTimeout;
27 private int smrRetryCount;
28 private boolean authEnabled;
29 private int negativeMappingTTL;
30 private int numberOfBucketsInTimeBucketWheel;
33 * XXX When configuration options are added or removed, they should also be added/removed in the karaf
34 * `etc/custom.properties file`, hosted in the odlparent repository [0]. The "Configuring LISP Flow Mapping"
35 * section in the LISP Flow Mapping User Guide [1] has to be updated too, including when a configuration option's
36 * semantics or behavior is changed, in addition to having added/removed and option. Since we don't document
37 * options extensively in this file, the User Guide is the canonical documentation for them.
39 * [0] https://git.opendaylight.org/gerrit/gitweb?p=odlparent.git;a=blob;f=karaf/opendaylight-karaf-resources/src/main/resources/etc/custom.properties
40 * [1] https://git.opendaylight.org/gerrit/gitweb?p=docs.git;a=blob;f=docs/user-guide/lisp-flow-mapping-user-guide.rst
42 private static final String LISP_LOOKUP_POLICY = "lisp.lookupPolicy";
43 private static final String LISP_MAPPING_MERGE = "lisp.mappingMerge";
44 private static final String LISP_SMR = "lisp.smr";
45 private static final String LISP_ELP_POLICY = "lisp.elpPolicy";
46 private static final String LISP_REGISTER_VALIDITY_SB = "lisp.registerValiditySb";
47 private static final String LISP_SMR_RETRY_COUNT = "lisp.smrRetryCount";
48 private static final String LISP_SMR_TIMEOUT = "lisp.smrTimeout";
49 private static final String LISP_AUTH_ENABLED = "lisp.authEnabled";
50 private static final String LISP_NEGATIVE_MAPPING_TTL = "lisp.negativeMappingTTL";
52 // SB Map Register validity period in milliseconds. Default is 3.3 minutes.
53 private static final long MIN_REGISTRATION_VALIDITY_SB = 200000L;
54 private static final long DEFAULT_SMR_TIMEOUT = 3000L;
55 private static final int DEFAULT_SMR_RETRY_COUNT = 5;
56 private static final int DEFAULT_NEGATIVE_MAPPING_TTL = 15;
57 private static final int MIN_NUMBER_OF_BUCKETS_IN_TIME_BUCKET_WHEEL = 2;
58 private static final int TIMEOUT_TOLERANCE_MULTIPLIER_IN_TIME_BUCKET_WHEEL = 2;
60 private static final ConfigIni INSTANCE = new ConfigIni();
63 Bundle bundle = FrameworkUtil.getBundle(this.getClass());
64 BundleContext context = null;
66 context = bundle.getBundleContext();
67 if (context == null) {
68 LOG.warn("Couldn't get the BundleContext needed for reading the properties in the configuration file, "
69 + "bundle state is '{}'", bundleStateToString(bundle.getState()));
72 LOG.warn("Couldn't get the Bundle object needed for reading the properties in the configuration file, "
73 + "using built-in defaults");
79 private void initConfigs(BundleContext context) {
80 initMappingMerge(context);
82 initElpPolicy(context);
83 initLookupPolicy(context);
84 initRegisterValiditySb(context);
85 initSmrRetryCount(context);
86 initSmrTimeout(context);
87 initAuthEnabled(context);
88 initNegativeMappingTTL(context);
92 private String bundleStateToString(int state) {
96 case Bundle.INSTALLED:
100 case Bundle.STARTING:
102 case Bundle.STOPPING:
104 case Bundle.UNINSTALLED:
105 return "Uninstalled";
111 private void initRegisterValiditySb(BundleContext context) {
112 // set the default value first
113 this.registrationValiditySb = MIN_REGISTRATION_VALIDITY_SB;
117 if (context != null) {
118 str = context.getProperty(LISP_REGISTER_VALIDITY_SB);
122 str = System.getProperty(LISP_REGISTER_VALIDITY_SB);
124 LOG.debug("Configuration variable '{}' is unset. Setting to default value: '3.33 minutes' ",
125 LISP_REGISTER_VALIDITY_SB);
131 final long regValidity = Long.parseLong(str.trim());
132 setRegistrationValiditySb(regValidity);
133 } catch (NumberFormatException e) {
134 this.registrationValiditySb = MIN_REGISTRATION_VALIDITY_SB;
135 LOG.debug("Configuration variable 'registerValiditySb' was not set correctly. Registration validity for"
136 + "South Bound Map Registers is set to default value of 3.3 minutes");
140 private void initLookupPolicy(BundleContext context) {
141 // set the default value first
142 this.lookupPolicy = IMappingService.LookupPolicy.NB_FIRST;
146 if (context != null) {
147 str = context.getProperty(LISP_LOOKUP_POLICY);
151 str = System.getProperty(LISP_LOOKUP_POLICY);
153 LOG.debug("Configuration variable '{}' is unset. Setting to default value: 'northboundFirst' "
154 + "(Southbound is only looked up if Northbound is empty) ", LISP_LOOKUP_POLICY);
159 if (str.trim().equalsIgnoreCase("northboundAndSouthbound")) {
160 this.lookupPolicy = IMappingService.LookupPolicy.NB_AND_SB;
161 LOG.debug("Setting configuration variable '{}' to 'northboundAndSouthbound' (Southbound is always "
162 + "looked up and can filter Northbound if intersection is not empty)", LISP_LOOKUP_POLICY);
164 LOG.debug("Setting configuration variable '{}' to 'northboundFirst' (Southbound is only looked up "
165 + "if Northbound is empty)", LISP_LOOKUP_POLICY);
169 private void initMappingMerge(BundleContext context) {
170 // set the default value first
171 this.mappingMerge = false;
175 if (context != null) {
176 str = context.getProperty(LISP_MAPPING_MERGE);
180 str = System.getProperty(LISP_MAPPING_MERGE);
182 LOG.debug("Configuration variable '{}' is unset. Setting to default value: 'false'",
188 if (str.trim().equalsIgnoreCase("true")) {
189 this.mappingMerge = true;
190 LOG.debug("Setting configuration variable '{}' to 'true'", LISP_MAPPING_MERGE);
192 LOG.debug("Setting configuration variable '{}' to 'false'", LISP_MAPPING_MERGE);
196 private void initSmr(BundleContext context) {
197 // set the default value first
202 if (context != null) {
203 str = context.getProperty(LISP_SMR);
207 str = System.getProperty(LISP_SMR);
209 LOG.debug("Configuration variable '{}' is unset. Setting to default value: 'true'", LISP_SMR);
214 if (str.trim().equalsIgnoreCase("false")) {
216 LOG.debug("Setting configuration variable '{}' to 'false'", LISP_SMR);
218 LOG.debug("Setting configuration variable '{}' to 'true'", LISP_SMR);
222 private void initElpPolicy(BundleContext context) {
223 // set the default value first
224 this.elpPolicy = "default";
228 if (context != null) {
229 str = context.getProperty(LISP_ELP_POLICY);
233 str = System.getProperty(LISP_ELP_POLICY);
235 LOG.debug("Configuration variable '{}' is unset. Setting to default value: 'default' (ELP only)",
241 if (str.trim().equalsIgnoreCase("both")) {
242 this.elpPolicy = "both";
243 LOG.debug("Setting configuration variable '{}' to 'both' (keep ELP, add next hop)", LISP_ELP_POLICY);
244 } else if (str.trim().equalsIgnoreCase("replace")) {
245 this.elpPolicy = "replace";
246 LOG.debug("Setting configuration variable '{}' to 'replace' (next hop only)", LISP_ELP_POLICY);
248 LOG.debug("Setting configuration variable '{}' to 'default' (ELP only)", LISP_ELP_POLICY);
252 private void initSmrRetryCount(BundleContext context) {
253 // set the default value first
254 this.smrRetryCount = DEFAULT_SMR_RETRY_COUNT;
258 if (context != null) {
259 str = context.getProperty(LISP_SMR_RETRY_COUNT);
263 str = System.getProperty(LISP_SMR_RETRY_COUNT);
265 LOG.debug("Configuration variable '{}' is unset. Setting to default value: '{}'", LISP_SMR_RETRY_COUNT,
272 this.smrRetryCount = Integer.valueOf(str);
273 LOG.debug("Setting configuration variable '{}' to '{}'", LISP_SMR_RETRY_COUNT, smrRetryCount);
274 } catch (NumberFormatException e) {
275 LOG.debug("Configuration variable '{}' was not set correctly. SMR retry count "
276 + "is set to default value ({})", LISP_SMR_RETRY_COUNT, smrRetryCount);
280 private void initSmrTimeout(BundleContext context) {
281 // set the default value first
282 this.smrTimeout = DEFAULT_SMR_TIMEOUT;
286 if (context != null) {
287 str = context.getProperty(LISP_SMR_TIMEOUT);
291 str = System.getProperty(LISP_SMR_TIMEOUT);
293 LOG.debug("Configuration variable '{}' is unset. Setting to default value: '{}'", LISP_SMR_TIMEOUT,
300 this.smrTimeout = Long.valueOf(str);
301 LOG.debug("Setting configuration variable '{}' to '{}'", LISP_SMR_TIMEOUT, smrTimeout);
302 } catch (NumberFormatException e) {
303 LOG.debug("Configuration variable '{}' was not set correctly. SMR timeout "
304 + "is set to default value ({})", LISP_SMR_TIMEOUT, smrTimeout);
308 private void initAuthEnabled(BundleContext context) {
309 // set the default value first
310 this.authEnabled = true;
314 if (context != null) {
315 str = context.getProperty(LISP_AUTH_ENABLED);
319 str = System.getProperty(LISP_AUTH_ENABLED);
321 LOG.debug("Configuration variable '{}' is unset. Setting to default value: 'true'", LISP_AUTH_ENABLED);
326 if (str.trim().equalsIgnoreCase("false")) {
327 this.authEnabled = false;
328 LOG.debug("Setting configuration variable '{}' to 'false'", LISP_AUTH_ENABLED);
330 LOG.debug("Setting configuration variable '{}' to 'true'", LISP_AUTH_ENABLED);
334 private void initNegativeMappingTTL(BundleContext context) {
335 // set the default value first
336 this.negativeMappingTTL = DEFAULT_NEGATIVE_MAPPING_TTL;
340 if (context != null) {
341 str = context.getProperty(LISP_NEGATIVE_MAPPING_TTL);
345 str = System.getProperty(LISP_NEGATIVE_MAPPING_TTL);
347 LOG.debug("Configuration variable '{}' is unset. Setting to default value: '{}'",
348 LISP_NEGATIVE_MAPPING_TTL, negativeMappingTTL);
354 this.negativeMappingTTL = Integer.valueOf(str);
355 LOG.debug("Setting configuration variable '{}' to '{}'", LISP_NEGATIVE_MAPPING_TTL, negativeMappingTTL);
356 } catch (NumberFormatException e) {
357 LOG.debug("Configuration variable '{}' was not set correctly. Negative TTL "
358 + "is set to default value ({} minutes)", LISP_NEGATIVE_MAPPING_TTL, negativeMappingTTL);
362 //one bucket should contain mapping of approximate 1 min time frame
363 private void initBucketNumber() {
364 numberOfBucketsInTimeBucketWheel = (int) (TimeUnit.MILLISECONDS.toMinutes(getRegistrationValiditySb()) + 1);
366 numberOfBucketsInTimeBucketWheel = Math.max(numberOfBucketsInTimeBucketWheel,
367 MIN_NUMBER_OF_BUCKETS_IN_TIME_BUCKET_WHEEL);
370 public boolean mappingMergeIsSet() {
374 public void setMappingMerge(boolean mappingMerge) {
375 LOG.debug("Setting configuration variable '{}' to '{}'", LISP_MAPPING_MERGE, (mappingMerge));
376 this.mappingMerge = (mappingMerge);
379 public boolean smrIsSet() {
383 public void setSmr(boolean smr) {
384 LOG.debug("Setting configuration variable '{}' to '{}'", LISP_SMR, smr);
388 public String getElpPolicy() {
392 public IMappingService.LookupPolicy getLookupPolicy() {
396 public long getRegistrationValiditySb() {
397 return registrationValiditySb;
400 public long getDefaultRegistrationValiditySb() {
401 return MIN_REGISTRATION_VALIDITY_SB;
404 public void setRegistrationValiditySb(long registrationValiditySb) {
405 this.registrationValiditySb = registrationValiditySb;
406 if (registrationValiditySb < MIN_REGISTRATION_VALIDITY_SB) {
407 LOG.warn("Registration validity is less than the default 3.33 minutes!!!");
411 public void setLookupPolicy(IMappingService.LookupPolicy lookupPolicy) {
412 this.lookupPolicy = lookupPolicy;
415 public void setSmrRetryCount(int smrRetryCount) {
416 LOG.debug("Setting configuration variable '{}' to '{}'", LISP_SMR_RETRY_COUNT, smrRetryCount);
417 this.smrRetryCount = smrRetryCount;
420 public int getSmrRetryCount() {
421 return smrRetryCount;
424 public void setSmrTimeout(long smrTimeout) {
425 LOG.debug("Setting configuration variable '{}' to '{}'", LISP_SMR_TIMEOUT, smrTimeout);
426 this.smrTimeout = smrTimeout;
429 public long getSmrTimeout() {
430 return this.smrTimeout;
433 public boolean isAuthEnabled() {
434 return this.authEnabled;
437 public void setAuthEnabled(boolean authEnabled) {
438 LOG.debug("Setting configuration variable '{}' to '{}'", LISP_AUTH_ENABLED, authEnabled);
439 this.authEnabled = authEnabled;
442 public void setNegativeMappingTTL(int negativeMappingTTL) {
443 LOG.debug("Setting configuration variable '{}' to '{}'", LISP_NEGATIVE_MAPPING_TTL, negativeMappingTTL);
444 this.negativeMappingTTL = negativeMappingTTL;
447 public int getNegativeMappingTTL() {
448 return this.negativeMappingTTL;
451 public int getNumberOfBucketsInTimeBucketWheel() {
452 return numberOfBucketsInTimeBucketWheel;
455 public long getMaximumTimeoutTolerance() {
456 return TIMEOUT_TOLERANCE_MULTIPLIER_IN_TIME_BUCKET_WHEEL * getRegistrationValiditySb();
459 public static ConfigIni getInstance() {