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 {
20 private static final Logger LOG = LoggerFactory.getLogger(ConfigUtil.class);
22 private static boolean DEFAULT_LISP_OVERLAY_ENABLED = false;
23 private static boolean DEFAULT_LISP_MAPREGISTER_ENABLED = true;
25 private IpAddress odlTenantIp;
26 private boolean lispOverlayEnabled = DEFAULT_LISP_OVERLAY_ENABLED;
27 private boolean lispMapRegisterEnbled = DEFAULT_LISP_MAPREGISTER_ENABLED;
29 public static String ODL_TENANT_IP = "odl.ip.tenant";
30 public static String LISP_OVERLAY_ENABLED = "gbp.lisp.enabled";
31 public static String LISP_MAPREGISTER_ENABLED = "vpp.lisp.mapregister.enabled";
33 private static ConfigUtil INSTANCE = new ConfigUtil();
35 private ConfigUtil() {
39 public static ConfigUtil getInstance() {
43 private void configureDefaults() {
44 configureOdlTenantIp(null);
45 configureLispOverlayEnabled(null);
46 configureMapRegister(null);
49 public void configureLispOverlayEnabled(String configStr) {
50 if (configStr == null) {
51 configStr = System.getProperty(LISP_OVERLAY_ENABLED);
53 if (configStr == null) {
54 lispOverlayEnabled = DEFAULT_LISP_OVERLAY_ENABLED;
55 LOG.debug("Configuration variable {} is being unset. Setting the variable to {}",
56 LISP_OVERLAY_ENABLED, DEFAULT_LISP_OVERLAY_ENABLED);
61 configStr = configStr.trim();
63 if (configStr.equalsIgnoreCase("true")) {
64 lispOverlayEnabled = true;
66 lispOverlayEnabled = false;
70 public void configureOdlTenantIp(String configStr) {
71 if (configStr == null) {
73 LOG.debug("Configuration variable {} is being unset. Setting the variable to null",
78 configStr = configStr.trim();
79 odlTenantIp = new IpAddress(configStr.toCharArray());
82 public void configureMapRegister(String configStr) {
83 if (configStr == null) {
84 lispMapRegisterEnbled = DEFAULT_LISP_MAPREGISTER_ENABLED;
85 LOG.debug("Configuration variable {} is being unset. Setting the variable to {}",
86 LISP_MAPREGISTER_ENABLED, DEFAULT_LISP_MAPREGISTER_ENABLED);
90 configStr = configStr.trim();
92 if (configStr.equalsIgnoreCase("true")) {
93 lispMapRegisterEnbled = true;
95 lispOverlayEnabled = false;
99 public IpAddress getOdlTenantIp() {
103 public boolean isLispOverlayEnabled() {
104 if (lispOverlayEnabled) {
105 Preconditions.checkNotNull(odlTenantIp, "Configuration variable {} is not set. " +
106 "So, {} can't be used for chances of invalid config!", LISP_OVERLAY_ENABLED);
108 return lispOverlayEnabled;
111 public boolean isLispMapRegisterEnbled() {
112 return lispMapRegisterEnbled;