2 * Copyright (c) 2017 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
9 package org.opendaylight.groupbasedpolicy.renderer.vpp.config;
11 import com.google.common.base.Preconditions;
12 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
13 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory;
17 * Created by Shakib Ahmed on 4/13/17.
19 public class ConfigUtil {
21 private static final Logger LOG = LoggerFactory.getLogger(ConfigUtil.class);
23 private static final boolean DEFAULT_LISP_OVERLAY_ENABLED = false;
24 private static final boolean DEFAULT_LISP_MAPREGISTER_ENABLED = true;
25 private static final boolean DEFAULT_L3_FLAT_ENABLED = false;
26 private static final String DEFAULT_TRUE_STRING_VALUE = "true";
27 private static final String CONFIGURATION_VARIABLE_MESSAGE =
28 "Configuration variable {} is being unset. Setting the variable to {}";
30 private IpAddress odlTenantIp;
31 private boolean lispOverlayEnabled = DEFAULT_LISP_OVERLAY_ENABLED;
32 private boolean lispMapRegisterEnabled = DEFAULT_LISP_MAPREGISTER_ENABLED;
33 private boolean l3FlatEnabled = DEFAULT_L3_FLAT_ENABLED;
35 static final String ODL_TENANT_IP = "odl.ip.tenant";
36 static final String LISP_OVERLAY_ENABLED = "gbp.lisp.enabled";
37 static final String LISP_MAPREGISTER_ENABLED = "vpp.lisp.mapregister.enabled";
38 static final String L3_FLAT_ENABLED = "vpp.l3.flat.enabled";
40 private static final ConfigUtil INSTANCE = new ConfigUtil();
42 private ConfigUtil() {
43 configureOdlTenantIp(null);
44 configureLispOverlayEnabled(null);
45 configureMapRegister(null);
46 configL3FlatEnabled(null);
49 public static ConfigUtil getInstance() {
53 void configureLispOverlayEnabled(String configStr) {
54 if (configStr == null) {
55 configStr = System.getProperty(LISP_OVERLAY_ENABLED);
57 if (configStr == null) {
58 lispOverlayEnabled = DEFAULT_LISP_OVERLAY_ENABLED;
59 LOG.debug(CONFIGURATION_VARIABLE_MESSAGE, LISP_OVERLAY_ENABLED, DEFAULT_LISP_OVERLAY_ENABLED);
63 lispOverlayEnabled = configStr.trim().equalsIgnoreCase(DEFAULT_TRUE_STRING_VALUE);
66 void configureOdlTenantIp(String configStr) {
67 if (configStr == null) {
69 LOG.debug("Configuration variable {} is being unset. Setting the variable to null",
73 odlTenantIp = new IpAddress(configStr.trim().toCharArray());
76 void configureMapRegister(String configStr) {
77 if (configStr == null) {
78 lispMapRegisterEnabled = DEFAULT_LISP_MAPREGISTER_ENABLED;
79 LOG.debug(CONFIGURATION_VARIABLE_MESSAGE, LISP_MAPREGISTER_ENABLED, DEFAULT_LISP_MAPREGISTER_ENABLED);
82 lispMapRegisterEnabled = configStr.trim().equalsIgnoreCase(DEFAULT_TRUE_STRING_VALUE);
85 void configL3FlatEnabled(String configStr) {
86 if (configStr == null) {
87 l3FlatEnabled = DEFAULT_L3_FLAT_ENABLED;
88 LOG.debug(CONFIGURATION_VARIABLE_MESSAGE, L3_FLAT_ENABLED, DEFAULT_L3_FLAT_ENABLED);
91 l3FlatEnabled = configStr.trim().equalsIgnoreCase(DEFAULT_TRUE_STRING_VALUE);
94 public IpAddress getOdlTenantIp() {
98 public boolean isLispOverlayEnabled() {
99 if (lispOverlayEnabled) {
100 Preconditions.checkNotNull(odlTenantIp, "Configuration variable {} is not set. " +
101 "So, {} can't be used for chances of invalid config!", LISP_OVERLAY_ENABLED);
103 return lispOverlayEnabled;
106 public boolean isLispMapRegisterEnabled() {
107 return lispMapRegisterEnabled;
110 public boolean isL3FlatEnabled() {
111 return l3FlatEnabled;