[ONOS-7208] Improves policer with rate type

Change-Id: Idf20fce19bfc071193f55609d3bb7297d2dee479
diff --git a/core/api/src/main/java/org/onosproject/net/behaviour/trafficcontrol/DefaultTokenBucket.java b/core/api/src/main/java/org/onosproject/net/behaviour/trafficcontrol/DefaultTokenBucket.java
index f3920b2..8313f3f 100644
--- a/core/api/src/main/java/org/onosproject/net/behaviour/trafficcontrol/DefaultTokenBucket.java
+++ b/core/api/src/main/java/org/onosproject/net/behaviour/trafficcontrol/DefaultTokenBucket.java
@@ -18,6 +18,7 @@
 
 import com.google.common.annotations.Beta;
 import com.google.common.base.Objects;
+import org.onosproject.net.behaviour.trafficcontrol.TokenBucket.Type;
 
 import static com.google.common.base.MoreObjects.toStringHelper;
 import static com.google.common.base.Preconditions.checkArgument;
@@ -36,16 +37,18 @@
     private final long burstSize;
     private final Action action;
     private final short dscp;
+    private final Type type;
 
     // Mutable parameters
     private long processedPackets;
     private long processedBytes;
 
-    private DefaultTokenBucket(long r, long bS, Action a, short d) {
+    private DefaultTokenBucket(long r, long bS, Action a, short d, Type t) {
         rate = r;
         burstSize = bS;
         action = a;
         dscp = d;
+        type = t;
     }
 
     @Override
@@ -69,6 +72,11 @@
     }
 
     @Override
+    public Type type() {
+        return type;
+    }
+
+    @Override
     public long processedPackets() {
         return processedPackets;
     }
@@ -94,7 +102,8 @@
                 .add("rate", rate())
                 .add("burstSize", burstSize())
                 .add("action", action())
-                .add("dscp", dscp()).toString();
+                .add("dscp", dscp())
+                .add("type", type()).toString();
     }
 
     @Override
@@ -109,12 +118,13 @@
         return rate == that.rate &&
                 burstSize == that.burstSize &&
                 Objects.equal(action, that.action) &&
-                dscp == that.dscp;
+                dscp == that.dscp &&
+                Objects.equal(type, that.type);
     }
 
     @Override
     public int hashCode() {
-        return Objects.hashCode(rate, burstSize, action, dscp);
+        return Objects.hashCode(rate, burstSize, action, dscp, type);
     }
 
     /**
@@ -136,6 +146,7 @@
         private long burstSize = 2 * 1500;
         private Action action;
         private short dscp;
+        private Type type;
 
         @Override
         public TokenBucket.Builder withRate(long r) {
@@ -162,9 +173,16 @@
         }
 
         @Override
+        public TokenBucket.Builder withType(Type t) {
+            type = t;
+            return this;
+        }
+
+        @Override
         public DefaultTokenBucket build() {
-            // Not null condition on the action
+            // Not null condition on the action and on the type
             checkNotNull(action, "Must specify an action");
+            checkNotNull(type, "Must specify a type");
 
             // If action is based on DSCP modification
             if (action == DSCP_CLASS || action == DSCP_PRECEDENCE) {
@@ -173,7 +191,7 @@
             }
 
             // Finally we build the token bucket
-            return new DefaultTokenBucket(rate, burstSize, action, dscp);
+            return new DefaultTokenBucket(rate, burstSize, action, dscp, type);
         }
     }
 }
diff --git a/core/api/src/main/java/org/onosproject/net/behaviour/trafficcontrol/TokenBucket.java b/core/api/src/main/java/org/onosproject/net/behaviour/trafficcontrol/TokenBucket.java
index a86466b..7e3a943 100644
--- a/core/api/src/main/java/org/onosproject/net/behaviour/trafficcontrol/TokenBucket.java
+++ b/core/api/src/main/java/org/onosproject/net/behaviour/trafficcontrol/TokenBucket.java
@@ -36,8 +36,26 @@
     short MIN_DSCP = 0;
 
     /**
+     * Token bucket type.
+     */
+    enum Type {
+        /**
+         * Committed rate.
+         */
+        COMMITTED,
+        /**
+         * Excess rate.
+         */
+        EXCESS,
+        /**
+         * Peak rate.
+         */
+        PEAK
+    }
+
+    /**
      * Action applied to the exceeding traffic.
-     * Action depends on the tocken bucket type
+     * Action in general depends on the token bucket type.
      */
     enum Action {
         /**
@@ -90,6 +108,13 @@
     short dscp();
 
     /**
+     * Token bucket type.
+     *
+     * @return the token bucket type
+     */
+    Type type();
+
+    /**
      * Stats which reports how many packets have been
      * processed so far.
      *
@@ -152,6 +177,16 @@
         Builder withDscp(short dscp);
 
         /**
+         * Assigns the type to this token bucket.
+         * <p>
+         * Note: mandatory setter for this builder
+         * </p>
+         * @param type the type
+         * @return this
+         */
+        Builder withType(Type type);
+
+        /**
          * Builds the token bucket based on the specified
          * parameters when possible.
          *