[ONOS-8084] Changes to Bgp Cfg

- Added route refresh params to BgpCfg
- Added default values and value checks

Change-Id: I835fd9bbcb6d0c627c216d98ac84fdb65d98eea8
diff --git a/protocols/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpCfg.java b/protocols/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpCfg.java
index 80eec64..6f87c3f 100644
--- a/protocols/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpCfg.java
+++ b/protocols/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpCfg.java
@@ -390,4 +390,60 @@
      */
     void setConnectionType(ConnectionType connectionType);
 
+    /**
+     * Gets route refresh is enabled or not.
+     *
+     * @return route refresh enabled
+     */
+    boolean isRouteRefreshEnabled();
+
+    /**
+     * Sets if route refresh is enabled or disabled.
+     *
+     * @param isEnabled is route refresh enabled
+     */
+    void setRouteRefreshEnabled(boolean isEnabled);
+
+    /**
+     * Gets the value of route refresh periodic timer.
+     *
+     * @return route refresh periodic timer value
+     */
+    long getRouteRefreshPeriodicTimer();
+
+    /**
+     * Sets the value of route refresh periodic timer.
+     *
+     * @param periodicTimer value for periodic timer
+     */
+    void setRouteRefreshPeriodicTimer(long periodicTimer);
+
+    /**
+     * Gets the value of route refresh warmup timer.
+     *
+     * @return route refresh warmup timer value
+     */
+    long getRouteRefreshWarmupTimer();
+
+    /**
+     * Sets the value of route refresh warmup timer.
+     *
+     * @param warmupTimer value for warmup timer
+     */
+    void setRouteRefreshWarmupTimer(long warmupTimer);
+
+    /**
+     * Gets the value of route refresh cooldown timer.
+     *
+     * @return route refresh cooldown timer value
+     */
+    long getRouteRefreshCooldownTimer();
+
+    /**
+     * Sets the value of route refresh cooldown timer.
+     *
+     * @param cooldownTimer value for cooldown timer
+     */
+    void setRouteRefreshCooldownTimer(long cooldownTimer);
+
 }
diff --git a/protocols/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BgpConfig.java b/protocols/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BgpConfig.java
index c9a9a09..bb4d153 100644
--- a/protocols/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BgpConfig.java
+++ b/protocols/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BgpConfig.java
@@ -65,6 +65,11 @@
     //Set default connection type as IPv4
     private ConnectionType connectionType = ConnectionType.IPV4;
 
+    private boolean isRouteRefreshEnabled = false;
+    private long periodicTimer;
+    private long warmupTimer;
+    private long cooldownTimer;
+
     /*
      * Constructor to initialize the values.
      */
@@ -166,6 +171,46 @@
     }
 
     @Override
+    public boolean isRouteRefreshEnabled() {
+        return this.isRouteRefreshEnabled;
+    }
+
+    @Override
+    public void setRouteRefreshEnabled(boolean isEnabled) {
+        this.isRouteRefreshEnabled = isEnabled;
+    }
+
+    @Override
+    public long getRouteRefreshPeriodicTimer() {
+        return this.periodicTimer;
+    }
+
+    @Override
+    public void setRouteRefreshPeriodicTimer(long periodicTimer) {
+        this.periodicTimer = periodicTimer;
+    }
+
+    @Override
+    public long getRouteRefreshWarmupTimer() {
+        return this.warmupTimer;
+    }
+
+    @Override
+    public void setRouteRefreshWarmupTimer(long warmupTimer) {
+        this.warmupTimer = warmupTimer;
+    }
+
+    @Override
+    public long getRouteRefreshCooldownTimer() {
+        return this.cooldownTimer;
+    }
+
+    @Override
+    public void setRouteRefreshCooldownTimer(long cooldownTimer) {
+        this.cooldownTimer = cooldownTimer;
+    }
+
+    @Override
     public String getRouterId() {
         if (this.routerId != null) {
             return this.routerId.toString();
diff --git a/providers/bgp/cfg/src/main/java/org/onosproject/provider/bgp/cfg/impl/BgpAppConfig.java b/providers/bgp/cfg/src/main/java/org/onosproject/provider/bgp/cfg/impl/BgpAppConfig.java
index f76c401..d090420 100644
--- a/providers/bgp/cfg/src/main/java/org/onosproject/provider/bgp/cfg/impl/BgpAppConfig.java
+++ b/providers/bgp/cfg/src/main/java/org/onosproject/provider/bgp/cfg/impl/BgpAppConfig.java
@@ -67,6 +67,11 @@
     public static final String CONNECTION_TYPE_IPV6 = "IPV6";
     public static final String CONNECTION_TYPE_IPV4_AND_IPV6 = "IPV4_IPV6";
 
+    public static final String ROUTE_REFRESH_ENABLED = "routeRefreshEnabled";
+    public static final String RR_PERIODIC_TIMER = "rrPeriodicTimer";
+    public static final String RR_COOLDOWN_TIMER = "rrCooldownTimer";
+    public static final String RR_WARMUP_TIMER = "rrWarmupTimer";
+
     static final int MAX_SHORT_AS_NUMBER = 65535;
     static final long MAX_LONG_AS_NUMBER = 4294967295L;
 
@@ -76,6 +81,18 @@
     static final int MIN_HOLDTIME = 0;
     static final long MAX_HOLDTIME = 65535;
 
+    static final String RR_ENABLED_DEFAULT_VALUE = "false";
+    static final String PERIODIC_TIMER_DEFAULT_VALUE = "1800"; //30 minutes
+    static final String COOLDOWN_TIMER_DEFAULT_VALUE = "300"; //5 minutes
+    static final String WARMUP_TIMER_DEFAULT_VALUE = "30"; //30 seconds
+
+    static final long MIN_PERIODIC_TIMER = 1;
+    static final long MAX_PERIODIC_TIMER = Integer.MAX_VALUE;
+    static final long MIN_COOLDOWN_TIMER = 1;
+    static final long MAX_COOLDOWN_TIMER = Integer.MAX_VALUE;
+    static final long MIN_WARMUP_TIMER = 1;
+    static final long MAX_WARMUP_TIMER = Integer.MAX_VALUE;
+
     @Override
     public boolean isValid() {
         boolean fields = false;
@@ -85,13 +102,18 @@
 
         fields = hasOnlyFields(ROUTER_ID, LOCAL_AS, MAX_SESSION, LS_CAPABILITY,
                                HOLD_TIME, LARGE_AS_CAPABILITY, FLOW_SPEC_CAPABILITY,
-                               FLOW_SPEC_RPD_CAPABILITY, BGP_PEER, EVPN_CAPABILITY, CONNECTION_TYPE) &&
+                               FLOW_SPEC_RPD_CAPABILITY, BGP_PEER, EVPN_CAPABILITY, CONNECTION_TYPE,
+                               ROUTE_REFRESH_ENABLED, RR_PERIODIC_TIMER, RR_COOLDOWN_TIMER, RR_WARMUP_TIMER) &&
                 isIpAddress(ROUTER_ID, MANDATORY) && isNumber(LOCAL_AS, MANDATORY) &&
                 isNumber(MAX_SESSION, OPTIONAL, MIN_SESSION_NUMBER, MAX_SESSION_NUMBER)
                 && isNumber(HOLD_TIME, OPTIONAL, MIN_HOLDTIME, MAX_HOLDTIME) &&
                 isBoolean(LS_CAPABILITY, OPTIONAL) && isBoolean(LARGE_AS_CAPABILITY, OPTIONAL) &&
                 isString(FLOW_SPEC_CAPABILITY, OPTIONAL) && isBoolean(FLOW_SPEC_RPD_CAPABILITY, OPTIONAL)
-                && isBoolean(EVPN_CAPABILITY, OPTIONAL) && isString(CONNECTION_TYPE, OPTIONAL);
+                && isBoolean(EVPN_CAPABILITY, OPTIONAL) && isString(CONNECTION_TYPE, OPTIONAL)
+                && isBoolean(ROUTE_REFRESH_ENABLED, OPTIONAL)
+                && isNumber(RR_PERIODIC_TIMER, OPTIONAL, MIN_PERIODIC_TIMER, MAX_PERIODIC_TIMER)
+                && isNumber(RR_COOLDOWN_TIMER, OPTIONAL, MIN_COOLDOWN_TIMER, MAX_COOLDOWN_TIMER)
+                && isNumber(RR_WARMUP_TIMER, OPTIONAL, MIN_WARMUP_TIMER, MAX_WARMUP_TIMER);
 
         if (!fields) {
             return fields;
@@ -182,6 +204,42 @@
     }
 
     /**
+     * Returns if route refresh is enabled in the configuration.
+     *
+     * @return route refresh enabled
+     */
+    public boolean routeRefreshEnabled() {
+        return Boolean.parseBoolean(get(ROUTE_REFRESH_ENABLED, RR_ENABLED_DEFAULT_VALUE));
+    }
+
+    /**
+     * Returns value of route refresh periodic timer from the configuration.
+     *
+     * @return route refresh periodic timer
+     */
+    public long rrPeriodicTimer() {
+        return Long.parseLong(get(RR_PERIODIC_TIMER, PERIODIC_TIMER_DEFAULT_VALUE));
+    }
+
+    /**
+     * Returns value of route refresh warmup timer from the configuration.
+     *
+     * @return route refresh warmup timer
+     */
+    public long rrWarmupTimer() {
+        return Long.parseLong(get(RR_WARMUP_TIMER, WARMUP_TIMER_DEFAULT_VALUE));
+    }
+
+    /**
+     * Returns value of route refresh cooldown timer from the configuration.
+     *
+     * @return route refresh cooldown timer
+     */
+    public long rrCooldownTimer() {
+        return Long.parseLong(get(RR_COOLDOWN_TIMER, COOLDOWN_TIMER_DEFAULT_VALUE));
+    }
+
+    /**
      * Validates the BGP connection type.
      *
      * @return true if valid else false
diff --git a/providers/bgp/cfg/src/main/java/org/onosproject/provider/bgp/cfg/impl/BgpCfgProvider.java b/providers/bgp/cfg/src/main/java/org/onosproject/provider/bgp/cfg/impl/BgpCfgProvider.java
index d9268d8..798c0a2 100644
--- a/providers/bgp/cfg/src/main/java/org/onosproject/provider/bgp/cfg/impl/BgpCfgProvider.java
+++ b/providers/bgp/cfg/src/main/java/org/onosproject/provider/bgp/cfg/impl/BgpCfgProvider.java
@@ -154,6 +154,11 @@
         }
 
         bgpConfig.setConnectionType(getBgpConnectionTypeFromConfig(config));
+
+        bgpConfig.setRouteRefreshEnabled(config.routeRefreshEnabled());
+        bgpConfig.setRouteRefreshPeriodicTimer(config.rrPeriodicTimer());
+        bgpConfig.setRouteRefreshWarmupTimer(config.rrWarmupTimer());
+        bgpConfig.setRouteRefreshCooldownTimer(config.rrCooldownTimer());
     }
 
     /**
@@ -262,6 +267,11 @@
         }
 
         bgpConfig.setConnectionType(getBgpConnectionTypeFromConfig(config));
+
+        bgpConfig.setRouteRefreshEnabled(config.routeRefreshEnabled());
+        bgpConfig.setRouteRefreshPeriodicTimer(config.rrPeriodicTimer());
+        bgpConfig.setRouteRefreshWarmupTimer(config.rrWarmupTimer());
+        bgpConfig.setRouteRefreshCooldownTimer(config.rrCooldownTimer());
     }
 
     /**