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

Change-Id: Id97fd9cb85ee018ced73836ead8be4d653e0e55f
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