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.osgi.framework.Bundle;
11 import org.osgi.framework.BundleContext;
12 import org.osgi.framework.FrameworkUtil;
13 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory;
16 public final class ConfigIni {
17 protected static final Logger LOG = LoggerFactory.getLogger(ConfigIni.class);
18 private boolean mappingMerge;
19 private boolean mappingOverwrite;
21 private String elpPolicy;
23 // 'lisp.mappingMerge' and 'lisp.mappingOverWrite' are not independent, and they can't be both 'true'
24 // when there is a conflict, the setting in 'lisp.mappingMerge' takes precendence
25 private static final String LISP_MAPPING_MERGE = "lisp.mappingMerge";
26 private static final String LISP_MAPPING_OVERWRITE = "lisp.mappingOverwrite";
27 private static final String LISP_SMR = "lisp.smr";
28 private static final String LISP_ELP_POLICY = "lisp.elpPolicy";
30 private static final ConfigIni INSTANCE = new ConfigIni();
33 Bundle b = FrameworkUtil.getBundle(this.getClass());
34 BundleContext context = null;
36 context = b.getBundleContext();
39 // Initialize mappingMerge first, since mappingOverwrite depends on it
40 initMappingMerge(context);
41 initMappingOverwrite(context);
43 initElpPolicy(context);
46 private void initMappingMerge(BundleContext context) {
47 // set the default value first
48 this.mappingMerge = false;
52 if (context != null) {
53 str = context.getProperty(LISP_MAPPING_MERGE);
57 str = System.getProperty(LISP_MAPPING_MERGE);
59 LOG.debug("Configuration variable '{}' is unset. Setting to default value: 'false'", LISP_MAPPING_MERGE);
64 if (str.trim().equalsIgnoreCase("true")) {
65 this.mappingMerge = true;
66 LOG.debug("Setting configuration variable '{}' to 'true'", LISP_MAPPING_MERGE);
68 LOG.debug("Setting configuration variable '{}' to 'false'", LISP_MAPPING_MERGE);
72 private void initMappingOverwrite(BundleContext context) {
73 // set the default value first
74 this.mappingOverwrite = true;
78 if (context != null) {
79 str = context.getProperty(LISP_MAPPING_OVERWRITE);
83 str = System.getProperty(LISP_MAPPING_OVERWRITE);
85 if (this.mappingMerge) {
86 // If merge is enabled and overwriting configuration is not set, disable it
87 LOG.debug("Configuration variable '{}' is unset. Since '{}'=true setting to 'false'",
88 LISP_MAPPING_OVERWRITE, LISP_MAPPING_MERGE);
89 this.mappingOverwrite = false;
91 LOG.debug("Configuration variable '{}' is unset. Setting to default value: 'true'",
92 LISP_MAPPING_OVERWRITE);
98 if (str.trim().equalsIgnoreCase("false")) {
99 this.mappingOverwrite = false;
100 LOG.debug("Setting configuration variable '{}' to 'false'", LISP_MAPPING_OVERWRITE);
102 if (this.mappingMerge) {
103 LOG.warn("Can't set configuration variable '{}' to 'true' since '{}' is enabled",
104 LISP_MAPPING_OVERWRITE, LISP_MAPPING_MERGE);
105 LOG.warn("If you really need to enable overwriting, please disable merging.");
106 LOG.debug("Setting configuration variable '{}' to 'false'", LISP_MAPPING_OVERWRITE);
107 this.mappingOverwrite = false;
109 LOG.debug("Setting configuration variable '{}' to 'true'", LISP_MAPPING_OVERWRITE);
114 private void initSmr(BundleContext context) {
115 // set the default value first
120 if (context != null) {
121 str = context.getProperty(LISP_SMR);
125 str = System.getProperty(LISP_SMR);
127 LOG.debug("Configuration variable '{}' is unset. Setting to default value: 'true'", LISP_SMR);
132 if (str.trim().equalsIgnoreCase("false")) {
134 LOG.debug("Setting configuration variable '{}' to 'false'", LISP_SMR);
136 LOG.debug("Setting configuration variable '{}' to 'true'", LISP_SMR);
140 private void initElpPolicy(BundleContext context) {
141 // set the default value first
142 this.elpPolicy = "default";
146 if (context != null) {
147 str = context.getProperty(LISP_ELP_POLICY);
151 str = System.getProperty(LISP_ELP_POLICY);
153 LOG.debug("Configuration variable '{}' is unset. Setting to default value: 'default' (ELP only)",
159 if (str.trim().equalsIgnoreCase("both")) {
160 this.elpPolicy = "both";
161 LOG.debug("Setting configuration variable '{}' to 'both' (keep ELP, add next hop)", LISP_ELP_POLICY);
162 } else if (str.trim().equalsIgnoreCase("replace")) {
163 this.elpPolicy = "replace";
164 LOG.debug("Setting configuration variable '{}' to 'replace' (next hop only)", LISP_ELP_POLICY);
166 LOG.debug("Setting configuration variable '{}' to 'default' (ELP only)", LISP_ELP_POLICY);
170 public boolean mappingMergeIsSet() {
174 public boolean mappingOverwriteIsSet() {
175 return mappingOverwrite;
178 public boolean smrIsSet() {
182 public String getElpPolicy() {
186 public static ConfigIni getInstance() {