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;
24 private static boolean DEFAULT_L3_FLAT_ENABLED = false;
26 private IpAddress odlTenantIp;
27 private boolean lispOverlayEnabled = DEFAULT_LISP_OVERLAY_ENABLED;
28 private boolean lispMapRegisterEnbled = DEFAULT_LISP_MAPREGISTER_ENABLED;
29 private boolean l3FlatEnabled = DEFAULT_L3_FLAT_ENABLED;
32 public static String ODL_TENANT_IP = "odl.ip.tenant";
33 public static String LISP_OVERLAY_ENABLED = "gbp.lisp.enabled";
34 public static String LISP_MAPREGISTER_ENABLED = "vpp.lisp.mapregister.enabled";
35 public static String L3_FLAT_ENABLED = "vpp.l3.flat.enabled";
37 private static ConfigUtil INSTANCE = new ConfigUtil();
39 private ConfigUtil() {
43 public static ConfigUtil getInstance() {
47 private void configureDefaults() {
48 configureOdlTenantIp(null);
49 configureLispOverlayEnabled(null);
50 configureMapRegister(null);
53 public 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 {} is being unset. Setting the variable to {}",
60 LISP_OVERLAY_ENABLED, DEFAULT_LISP_OVERLAY_ENABLED);
65 configStr = configStr.trim();
67 if (configStr.equalsIgnoreCase("true")) {
68 lispOverlayEnabled = true;
70 lispOverlayEnabled = false;
74 public void configureOdlTenantIp(String configStr) {
75 if (configStr == null) {
77 LOG.debug("Configuration variable {} is being unset. Setting the variable to null",
82 configStr = configStr.trim();
83 odlTenantIp = new IpAddress(configStr.toCharArray());
86 public void configureMapRegister(String configStr) {
87 if (configStr == null) {
88 lispMapRegisterEnbled = DEFAULT_LISP_MAPREGISTER_ENABLED;
89 LOG.debug("Configuration variable {} is being unset. Setting the variable to {}",
90 LISP_MAPREGISTER_ENABLED, DEFAULT_LISP_MAPREGISTER_ENABLED);
94 configStr = configStr.trim();
96 if (configStr.equalsIgnoreCase("true")) {
97 lispMapRegisterEnbled = true;
99 lispOverlayEnabled = false;
103 public void configL3FlatEnabled(String configStr) {
104 if (configStr == null) {
105 l3FlatEnabled = DEFAULT_L3_FLAT_ENABLED;
106 LOG.debug("Configuration variable {} is being unset. Setting the variable to {}",
107 L3_FLAT_ENABLED, DEFAULT_L3_FLAT_ENABLED);
110 configStr = configStr.trim();
112 if (configStr.equalsIgnoreCase("true")) {
113 l3FlatEnabled = true;
115 l3FlatEnabled = false;
119 public IpAddress getOdlTenantIp() {
123 public boolean isLispOverlayEnabled() {
124 if (lispOverlayEnabled) {
125 Preconditions.checkNotNull(odlTenantIp, "Configuration variable {} is not set. " +
126 "So, {} can't be used for chances of invalid config!", LISP_OVERLAY_ENABLED);
128 return lispOverlayEnabled;
131 public boolean isLispMapRegisterEnbled() {
132 return lispMapRegisterEnbled;
135 public boolean isL3FlatEnabled() {
136 return l3FlatEnabled;