[VOL-3869] Changes ONOS BW profile representation
to reflect IETF representation
* Addition of GIR
* Addition of PIR/PBS

Change-Id: Id97fd9cb85ee018ced73836ead8be4d653e0e55f
diff --git a/README-NEW-DESIGN.md b/README-NEW-DESIGN.md
index 8dc061c..45790aa 100644
--- a/README-NEW-DESIGN.md
+++ b/README-NEW-DESIGN.md
@@ -137,7 +137,7 @@
                     "cbs":348000,
                     "eir":10000000,
                     "ebs":348000,
-                    "air":10000000
+                    "gir":10000000
                  },
                  {
                     "id":"User1-Specific",
@@ -145,7 +145,7 @@
                     "cbs":348000,
                     "eir":20000000,
                     "ebs":348000,
-                    "air":30000000
+                    "gir":30000000
                  }
               ]
            }
@@ -202,7 +202,7 @@
       "cbs": 384000,
       "eir": 100000000,
       "ebs": 384000,
-      "air": 100000000
+      "gir": 100000000
    }
 
 ```
diff --git a/api/src/main/java/org/opencord/sadis/BandwidthProfileInformation.java b/api/src/main/java/org/opencord/sadis/BandwidthProfileInformation.java
index ccdf3fa..0ad0ad4 100644
--- a/api/src/main/java/org/opencord/sadis/BandwidthProfileInformation.java
+++ b/api/src/main/java/org/opencord/sadis/BandwidthProfileInformation.java
@@ -20,10 +20,16 @@
 import java.util.Objects;
 
 /**
- * Represents bandwidth profile details such as PIR, CIR, AIR values.
+ * Represents bandwidth profile details such as PIR, CIR, GIR values.
  */
 public class BandwidthProfileInformation extends BaseInformation {
 
+    @JsonProperty(value = "pir")
+    long peakInformationRate;
+
+    @JsonProperty(value = "pbs")
+    Long peakBurstSize;
+
     @JsonProperty(value = "cir")
     long committedInformationRate;
 
@@ -36,12 +42,33 @@
     @JsonProperty(value = "ebs")
     Long exceededBurstSize;
 
+    // Deprecated in VOLTHA 2.8 (sadis 5.4.0)
+    // Will be removed in 2.9, use GIR instead
     @JsonProperty(value = "air")
     long assuredInformationRate;
 
-    //note that: the burst size of assured bandwidth will be always 0
+    @JsonProperty(value = "gir")
+    long guaranteedInformationRate;
+
+    //note that: the burst size of guaranteed bandwidth will be always 0
     //the rate information must be in Kbps and burst must be in Kbits
 
+    public final long peakInformationRate() {
+        return this.peakInformationRate;
+    }
+
+    public final void setPeakInformationRate(final long peakInformationRate) {
+        this.peakInformationRate = peakInformationRate;
+    }
+
+    public final Long peakBurstSize() {
+        return this.peakBurstSize;
+    }
+
+    public final void setPeakBurstSize(final Long peakBurstSize) {
+        this.peakBurstSize = peakBurstSize;
+    }
+
     public final long committedInformationRate() {
         return this.committedInformationRate;
     }
@@ -74,14 +101,26 @@
         this.exceededBurstSize = exceededBurstSize;
     }
 
+    // Deprecated in VOLTHA 2.8 (sadis 5.4.0)
+    // Will be removed in 2.9, use guaranteedInformationRate instead.
     public final long assuredInformationRate() {
         return this.assuredInformationRate;
     }
 
+    // Deprecated in VOLTHA 2.8 (sadis 5.4.0)
+    // Will be removed in 2.9, use guaranteedInformationRate instead.
     public final void setAssuredInformationRate(final long assuredInformationRate) {
         this.assuredInformationRate = assuredInformationRate;
     }
 
+    public final long guaranteedInformationRate() {
+        return this.guaranteedInformationRate;
+    }
+
+    public final void setGuaranteedInformationRate(final long guaranteedInformationRate) {
+        this.guaranteedInformationRate = guaranteedInformationRate;
+    }
+
     @Override
     public boolean equals(Object o) {
         if (this == o) {
@@ -91,9 +130,12 @@
             return false;
         }
         BandwidthProfileInformation that = (BandwidthProfileInformation) o;
-        return committedInformationRate == that.committedInformationRate &&
+        return peakInformationRate == that.peakInformationRate &&
+                committedInformationRate == that.committedInformationRate &&
                 exceededInformationRate == that.exceededInformationRate &&
                 assuredInformationRate == that.assuredInformationRate &&
+                guaranteedInformationRate == that.guaranteedInformationRate &&
+                Objects.equals(peakBurstSize, that.peakBurstSize) &&
                 Objects.equals(committedBurstSize, that.committedBurstSize) &&
                 Objects.equals(exceededBurstSize, that.exceededBurstSize);
     }
@@ -101,19 +143,22 @@
     @Override
     public int hashCode() {
 
-        return Objects.hash(committedInformationRate, committedBurstSize, exceededInformationRate, exceededBurstSize,
-                assuredInformationRate);
+        return Objects.hash(peakInformationRate, peakBurstSize, committedInformationRate, committedBurstSize,
+                exceededInformationRate, exceededBurstSize, assuredInformationRate, guaranteedInformationRate);
     }
 
     @Override
     public String toString() {
         final StringBuilder sb = new StringBuilder("BandwidthProfileInformation{");
         sb.append("id=").append(id);
+        sb.append(", peakInformationRate=").append(peakInformationRate);
+        sb.append(", peakBurstSize=").append(peakBurstSize);
         sb.append(", committedInformationRate=").append(committedInformationRate);
         sb.append(", committedBurstSize=").append(committedBurstSize);
         sb.append(", exceededInformationRate=").append(exceededInformationRate);
         sb.append(", exceededBurstSize=").append(exceededBurstSize);
         sb.append(", assuredInformationRate=").append(assuredInformationRate);
+        sb.append(", guaranteedInformationRate=").append(guaranteedInformationRate);
         sb.append('}');
         return sb.toString();
     }
diff --git a/app/src/main/java/org/opencord/sadis/impl/BandwidthProfileCodec.java b/app/src/main/java/org/opencord/sadis/impl/BandwidthProfileCodec.java
index 8bd38f1..277246d 100644
--- a/app/src/main/java/org/opencord/sadis/impl/BandwidthProfileCodec.java
+++ b/app/src/main/java/org/opencord/sadis/impl/BandwidthProfileCodec.java
@@ -23,13 +23,23 @@
 public class BandwidthProfileCodec extends JsonCodec<BandwidthProfileInformation> {
     @Override
     public ObjectNode encode(BandwidthProfileInformation entry, CodecContext context) {
-        return context.mapper().createObjectNode()
+
+        ObjectNode node = context.mapper().createObjectNode()
                 .put("id", entry.id())
                 .put("cir", (entry.committedInformationRate()))
                 .put("cbs", (entry.committedBurstSize() == null) ? "" : entry.committedBurstSize().toString())
-                .put("eir", entry.exceededInformationRate())
-                .put("ebs", (entry.exceededBurstSize() == null) ? "" : entry.exceededBurstSize().toString())
-                .put("air", entry.assuredInformationRate());
+                .put("air", entry.assuredInformationRate())
+                .put("gir", entry.guaranteedInformationRate());
+
+        if (entry.peakInformationRate() == 0 && entry.peakBurstSize() == null) {
+            node.put("eir", entry.exceededInformationRate());
+            node.put("ebs", (entry.exceededBurstSize() == null) ? "" : entry.exceededBurstSize().toString());
+        } else {
+            node.put("pir", entry.peakInformationRate());
+            node.put("pbs", (entry.peakBurstSize() == null) ? "" : entry.peakBurstSize().toString());
+        }
+
+        return node;
     }
 
 }
diff --git a/app/src/main/java/org/opencord/sadis/impl/BandwidthProfileConfig.java b/app/src/main/java/org/opencord/sadis/impl/BandwidthProfileConfig.java
index b899f56..abd4751 100644
--- a/app/src/main/java/org/opencord/sadis/impl/BandwidthProfileConfig.java
+++ b/app/src/main/java/org/opencord/sadis/impl/BandwidthProfileConfig.java
@@ -47,9 +47,23 @@
  *             "cbs"                         : Long,
  *             "eir"                         : long,
  *             "ebs"                         : Long,
- *             "air"                         : long,
+ *             "gir"                         : long,
  *         }, ...
  *     ]
+ *
+ *     OR
+ *
+ *     "entries" : [
+ *          {
+ *             "name"                        : string,
+ *             "pir"                         : long,
+ *             "pbs"                         : Long,
+ *             "cir"                         : long,
+ *             "cbs"                         : Long,
+ *             "gir"                         : long,
+ *          },
+ *
+ *     ]
  * }
  * </pre>
  */
diff --git a/app/src/test/java/org/opencord/sadis/impl/BandwidthProfileManagerTest.java b/app/src/test/java/org/opencord/sadis/impl/BandwidthProfileManagerTest.java
index 9ea46c4..94ccf9a 100644
--- a/app/src/test/java/org/opencord/sadis/impl/BandwidthProfileManagerTest.java
+++ b/app/src/test/java/org/opencord/sadis/impl/BandwidthProfileManagerTest.java
@@ -23,17 +23,34 @@
 import org.opencord.sadis.BaseInformationService;
 
 import java.util.List;
+import java.util.Objects;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
 public class BandwidthProfileManagerTest extends BaseSadis {
 
-    BandwidthProfileBuilder bp1 = BandwidthProfileBuilder.build("High Speed", 1000000000, 384000L,
-            100000000, 384000L, 100000000);
+    BandwidthProfileBuilder bp1 = BandwidthProfileBuilder.build("High Speed", 0, null, 1000000000,
+            384000L, 100000000, 384000L, 100000000);
 
-    BandwidthProfileBuilder bp2 = BandwidthProfileBuilder.build("Home User Speed", 1000000000, 200000L,
-            100000000, 200000L, 100000000);
+    BandwidthProfileBuilder bp2 = BandwidthProfileBuilder.build("Home User Speed", 0, null, 1000000000,
+            200000L, 100000000, 200000L, 100000000);
+
+    BandwidthProfileBuilder bp3 = BandwidthProfileBuilder.build("TCONT_TYPE1_100Mbps_Fixed", 100000, 10000L,
+            0, 0L, 0, null, 100000);
+
+    BandwidthProfileBuilder bp4 = BandwidthProfileBuilder.build("TCONT_TYPE2_50Mbps_Assured", 50000, 10000L,
+            50000, 10000L, 0, null, 0);
+
+    BandwidthProfileBuilder bp5 = BandwidthProfileBuilder.build("TCONT_TYPE3_50Mbps_Assured_100Mbps_Peak",
+            100000, 10000L, 50000, 10000L, 0, null, 0);
+
+    BandwidthProfileBuilder bp6 = BandwidthProfileBuilder.build("TCONT_TYPE4_200Mbps_Peak", 200000, 10000L,
+            0, 0L, 0, null, 0);
+
+    BandwidthProfileBuilder bp7 = BandwidthProfileBuilder.build(
+            "TCONT_TYPE5_100Mbps_Peak_50Mbps_Assured_10Mbps_Fixed", 100000, 10000L, 50000, 10000L,
+            0, null, 10000);
 
     @Before
     public void setUp() throws Exception {
@@ -54,6 +71,11 @@
         BaseInformationService<BandwidthProfileInformation> bpService = sadis.getBandwidthProfileService();
         checkGetForExisting("High Speed", bp1, bpService);
         checkGetForExisting("Home User Speed", bp2, bpService);
+        checkGetForExisting("TCONT_TYPE1_100Mbps_Fixed", bp3, bpService);
+        checkGetForExisting("TCONT_TYPE2_50Mbps_Assured", bp4, bpService);
+        checkGetForExisting("TCONT_TYPE3_50Mbps_Assured_100Mbps_Peak", bp5, bpService);
+        checkGetForExisting("TCONT_TYPE4_200Mbps_Peak", bp6, bpService);
+        checkGetForExisting("TCONT_TYPE5_100Mbps_Peak_50Mbps_Assured_10Mbps_Fixed", bp7, bpService);
 
         invalidateId("High Speed", bpService);
         checkFromBoth("High Speed", bp1, bpService);
@@ -79,23 +101,33 @@
 
     private void checkEntriesForBandwidthProfiles(BaseConfig config) {
         List<BandwidthProfileInformation> entries = config.getEntries();
-        assertEquals(2, entries.size());
+        assertEquals(7, entries.size());
 
-        BandwidthProfileInformation bpi = BandwidthProfileBuilder.build("High Speed", 1000000000, 384000L, 100000000,
-                384000L, 100000000);
+        BandwidthProfileInformation bpi = BandwidthProfileBuilder.build("High Speed", 0, null,
+                1000000000, 384000L, 100000000, 384000L, 100000000);
         assertTrue(checkEquality(bpi, entries.get(0)));
 
-        bpi = BandwidthProfileBuilder.build("Home User Speed", 1000000000, 200000L, 100000000,
-                200000L, 100000000);
+        bpi = BandwidthProfileBuilder.build("Home User Speed", 0, null, 1000000000, 200000L,
+                100000000, 200000L, 100000000);
         assertTrue(checkEquality(bpi, entries.get(1)));
+
+        bpi = BandwidthProfileBuilder.build("TCONT_TYPE1_100Mbps_Fixed", 100000, 10000L, 0, 0L,
+                0, null, 100000);
+        assertTrue(checkEquality(bpi, entries.get(2)));
     }
 
     private static final class BandwidthProfileBuilder extends BandwidthProfileInformation {
 
-        public static BandwidthProfileBuilder build(String id, long cir, Long cbs, long eir, Long ebs, long air) {
+        public static BandwidthProfileBuilder build(String id, long pir, Long pbs,
+                                                    long cir, Long cbs, long eir, Long ebs, long gir) {
             BandwidthProfileBuilder info = new BandwidthProfileBuilder();
             info.setId(id);
 
+            if (pir != 0) {
+                info.setPeakInformationRate(pir);
+                info.setPeakBurstSize(pbs);
+            }
+
             if (cbs != null) {
                 info.setCommittedBurstSize(cbs);
             } else {
@@ -103,14 +135,12 @@
             }
             info.setCommittedInformationRate(cir);
 
-            info.setExceededInformationRate(eir);
-            if (ebs != null) {
+            if (eir != 0) {
+                info.setExceededInformationRate(eir);
                 info.setExceededBurstSize(ebs);
-            } else {
-                info.setExceededBurstSize(0L);
             }
 
-            info.setAssuredInformationRate(air);
+            info.setGuaranteedInformationRate(gir);
             return info;
         }
     }
@@ -132,6 +162,15 @@
             return false;
         }
 
+        if (bpi.peakInformationRate() != other.peakInformationRate()) {
+            return false;
+        }
+
+        if (!Objects.equals(bpi.peakBurstSize(), other.peakBurstSize())) {
+            return false;
+        }
+
+
         if (bpi.committedInformationRate() != other.committedInformationRate()) {
             return false;
         }
@@ -144,11 +183,11 @@
             return false;
         }
 
-        if (!bpi.exceededBurstSize().equals(other.exceededBurstSize())) {
+        if (!Objects.equals(bpi.exceededBurstSize(), other.exceededBurstSize())) {
             return false;
         }
 
-        if (bpi.assuredInformationRate() != other.assuredInformationRate()) {
+        if (bpi.guaranteedInformationRate() != other.guaranteedInformationRate()) {
             return false;
         }
 
diff --git a/app/src/test/resources/HighSpeed b/app/src/test/resources/HighSpeed
index f57465f..939d2dc 100644
--- a/app/src/test/resources/HighSpeed
+++ b/app/src/test/resources/HighSpeed
@@ -4,5 +4,5 @@
       "cbs": 384000,
       "eir": 100000000,
       "ebs": 384000,
-      "air": 100000000
+      "gir": 100000000
 }
\ No newline at end of file
diff --git a/app/src/test/resources/LocalBpConfig.json b/app/src/test/resources/LocalBpConfig.json
index aee463b..1169c3c 100644
--- a/app/src/test/resources/LocalBpConfig.json
+++ b/app/src/test/resources/LocalBpConfig.json
@@ -12,7 +12,7 @@
       "cbs": 384000,
       "eir": 100000000,
       "ebs": 384000,
-      "air": 100000000
+      "gir": 100000000
     },
     {
       "id": "Home User Speed",
@@ -20,7 +20,47 @@
       "cbs": 200000,
       "eir": 100000000,
       "ebs": 200000,
-      "air": 100000000
+      "gir": 100000000
+    },
+    {
+      "id": "TCONT_TYPE1_100Mbps_Fixed",
+      "pir": 100000,
+      "pbs": 10000,
+      "cir": 0,
+      "cbs": 0,
+      "gir": 100000
+    },
+    {
+      "id": "TCONT_TYPE2_50Mbps_Assured",
+      "pir": 50000,
+      "pbs": 10000,
+      "cir": 50000,
+      "cbs": 10000,
+      "gir": 0
+    },
+    {
+      "id": "TCONT_TYPE3_50Mbps_Assured_100Mbps_Peak",
+      "pir": 100000,
+      "pbs": 10000,
+      "cir": 50000,
+      "cbs": 10000,
+      "gir": 0
+    },
+    {
+      "id": "TCONT_TYPE4_200Mbps_Peak",
+      "pir": 200000,
+      "pbs": 10000,
+      "cir": 0,
+      "cbs": 0,
+      "gir": 0
+    },
+    {
+      "id": "TCONT_TYPE5_100Mbps_Peak_50Mbps_Assured_10Mbps_Fixed",
+      "pir": 100000,
+      "pbs": 10000,
+      "cir": 50000,
+      "cbs": 10000,
+      "gir": 10000
     }
   ]
 }
\ No newline at end of file