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.implementation.config;
10 import org.opendaylight.lispflowmapping.interfaces.mappingservice.IMappingService;
11 import org.osgi.framework.Bundle;
12 import org.osgi.framework.BundleContext;
13 import org.osgi.framework.FrameworkUtil;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
17 public final class ConfigIni {
19 protected static final Logger LOG = LoggerFactory.getLogger(ConfigIni.class);
20 private boolean mappingMerge;
21 private boolean mappingOverwrite;
23 private String elpPolicy;
24 private IMappingService.LookupPolicy lookupPolicy;
25 private long registrationValiditySb;
27 // 'lisp.mappingMerge' and 'lisp.mappingOverWrite' are not independent, and they can't be both 'true'
28 // when there is a conflict, the setting in 'lisp.mappingMerge' takes precendence
29 // 'lisp.mappingOverwrite' defines the database behavior while 'lisp.mappingMerge' affects the result
30 // returned in Map-Replies
32 private static final String LISP_LOOKUP_POLICY = "lisp.lookupPolicy";
33 private static final String LISP_MAPPING_MERGE = "lisp.mappingMerge";
34 private static final String LISP_MAPPING_OVERWRITE = "lisp.mappingOverwrite";
35 private static final String LISP_SMR = "lisp.smr";
36 private static final String LISP_ELP_POLICY = "lisp.elpPolicy";
37 private static final String LISP_REGISTER_VALIDITY_SB = "lisp.registerValiditySb";
39 // SB Map Register validity period in milliseconds. Default is 3.3 minutes.
40 public static final long MIN_REGISTRATION_VALIDITY_SB = 200000L;
42 private static final ConfigIni INSTANCE = new ConfigIni();
45 Bundle bundle = FrameworkUtil.getBundle(this.getClass());
46 BundleContext context = null;
48 context = bundle.getBundleContext();
51 // Initialize mappingMerge first, since mappingOverwrite depends on it
52 initMappingMerge(context);
53 initMappingOverwrite(context);
55 initElpPolicy(context);
56 initLookupPolicy(context);
57 initRegisterValiditySb(context);
60 private void initRegisterValiditySb(BundleContext context) {
61 // set the default value first
62 this.registrationValiditySb = MIN_REGISTRATION_VALIDITY_SB;
66 if (context != null) {
67 str = context.getProperty(LISP_REGISTER_VALIDITY_SB);
71 str = System.getProperty(LISP_REGISTER_VALIDITY_SB);
73 LOG.debug("Configuration variable '{}' is unset. Setting to default value: '3.33 minutes' ",
74 LISP_REGISTER_VALIDITY_SB);
80 final long regValidity = Long.parseLong(str.trim());
81 if (regValidity >= MIN_REGISTRATION_VALIDITY_SB) {
82 this.registrationValiditySb = regValidity;
84 } catch (NumberFormatException e) {
85 this.registrationValiditySb = MIN_REGISTRATION_VALIDITY_SB;
86 LOG.debug("Configuration variable 'registerValiditySb' was not set correctly. Registration validity for"
87 + "South Bound Map Registers is set to default value of 3.3 minutes");
91 private void initLookupPolicy(BundleContext context) {
92 // set the default value first
93 this.lookupPolicy = IMappingService.LookupPolicy.NB_FIRST;
97 if (context != null) {
98 str = context.getProperty(LISP_LOOKUP_POLICY);
102 str = System.getProperty(LISP_LOOKUP_POLICY);
104 LOG.debug("Configuration variable '{}' is unset. Setting to default value: 'northboundFirst' "
105 + "(Southbound is only looked up if Northbound is empty) ", LISP_LOOKUP_POLICY);
110 if (str.trim().equalsIgnoreCase("northboundAndSouthbound")) {
111 this.lookupPolicy = IMappingService.LookupPolicy.NB_AND_SB;
112 LOG.debug("Setting configuration variable '{}' to 'northboundAndSouthbound' (Southbound is always "
113 + "looked up and can filter Northbound if intersection is not empty)", LISP_LOOKUP_POLICY);
115 LOG.debug("Setting configuration variable '{}' to 'northboundFirst' (Southbound is only looked up "
116 + "if Northbound is empty)", LISP_LOOKUP_POLICY);
120 private void initMappingMerge(BundleContext context) {
121 // set the default value first
122 this.mappingMerge = false;
126 if (context != null) {
127 str = context.getProperty(LISP_MAPPING_MERGE);
131 str = System.getProperty(LISP_MAPPING_MERGE);
133 LOG.debug("Configuration variable '{}' is unset. Setting to default value: 'false'",
139 if (str.trim().equalsIgnoreCase("true")) {
140 this.mappingMerge = true;
141 LOG.debug("Setting configuration variable '{}' to 'true'", LISP_MAPPING_MERGE);
143 LOG.debug("Setting configuration variable '{}' to 'false'", LISP_MAPPING_MERGE);
147 private void initMappingOverwrite(BundleContext context) {
148 // set the default value first
149 this.mappingOverwrite = true;
153 if (context != null) {
154 str = context.getProperty(LISP_MAPPING_OVERWRITE);
158 str = System.getProperty(LISP_MAPPING_OVERWRITE);
160 if (this.mappingMerge) {
161 // If merge is enabled and overwriting configuration is not set, disable it
162 LOG.debug("Configuration variable '{}' is unset. Since '{}'=true setting to 'false'",
163 LISP_MAPPING_OVERWRITE, LISP_MAPPING_MERGE);
164 this.mappingOverwrite = false;
166 LOG.debug("Configuration variable '{}' is unset. Setting to default value: 'true'",
167 LISP_MAPPING_OVERWRITE);
173 if (str.trim().equalsIgnoreCase("false")) {
174 this.mappingOverwrite = false;
175 LOG.debug("Setting configuration variable '{}' to 'false'", LISP_MAPPING_OVERWRITE);
177 if (this.mappingMerge) {
178 LOG.warn("Can't set configuration variable '{}' to 'true' since '{}' is enabled",
179 LISP_MAPPING_OVERWRITE, LISP_MAPPING_MERGE);
180 LOG.warn("If you really need to enable overwriting, please disable merging.");
181 LOG.debug("Setting configuration variable '{}' to 'false'", LISP_MAPPING_OVERWRITE);
182 this.mappingOverwrite = false;
184 LOG.debug("Setting configuration variable '{}' to 'true'", LISP_MAPPING_OVERWRITE);
189 private void initSmr(BundleContext context) {
190 // set the default value first
195 if (context != null) {
196 str = context.getProperty(LISP_SMR);
200 str = System.getProperty(LISP_SMR);
202 LOG.debug("Configuration variable '{}' is unset. Setting to default value: 'true'", LISP_SMR);
207 if (str.trim().equalsIgnoreCase("false")) {
209 LOG.debug("Setting configuration variable '{}' to 'false'", LISP_SMR);
211 LOG.debug("Setting configuration variable '{}' to 'true'", LISP_SMR);
215 private void initElpPolicy(BundleContext context) {
216 // set the default value first
217 this.elpPolicy = "default";
221 if (context != null) {
222 str = context.getProperty(LISP_ELP_POLICY);
226 str = System.getProperty(LISP_ELP_POLICY);
228 LOG.debug("Configuration variable '{}' is unset. Setting to default value: 'default' (ELP only)",
234 if (str.trim().equalsIgnoreCase("both")) {
235 this.elpPolicy = "both";
236 LOG.debug("Setting configuration variable '{}' to 'both' (keep ELP, add next hop)", LISP_ELP_POLICY);
237 } else if (str.trim().equalsIgnoreCase("replace")) {
238 this.elpPolicy = "replace";
239 LOG.debug("Setting configuration variable '{}' to 'replace' (next hop only)", LISP_ELP_POLICY);
241 LOG.debug("Setting configuration variable '{}' to 'default' (ELP only)", LISP_ELP_POLICY);
245 public boolean mappingMergeIsSet() {
249 public boolean mappingOverwriteIsSet() {
250 return mappingOverwrite;
253 public void setMappingOverwrite(boolean mappingOverwrite) {
254 LOG.debug("Setting configuration variable '{}' to '{}'", LISP_MAPPING_OVERWRITE, mappingOverwrite);
255 this.mappingOverwrite = mappingOverwrite;
256 LOG.debug("Setting configuration variable '{}' to '{}'", LISP_MAPPING_MERGE, !(mappingOverwrite));
257 this.mappingMerge = !(mappingOverwrite);
260 public boolean smrIsSet() {
264 public void setSmr(boolean smr) {
265 LOG.debug("Setting configuration variable '{}' to '{}'", LISP_SMR, smr);
269 public String getElpPolicy() {
273 public IMappingService.LookupPolicy getLookupPolicy() {
277 public long getRegistrationValiditySb() {
278 return registrationValiditySb;
281 public void setLookupPolicy(IMappingService.LookupPolicy lookupPolicy) {
282 this.lookupPolicy = lookupPolicy;
285 public static ConfigIni getInstance() {