[VOL-4179] Multi UNI changes for Sadis

Review fixes finished

Multi UNI changes for Sadis implemented. New bandwidth profile fields are added for Olt device.

Inside of constructor made it more readible

Change-Id: I82bf45a6a4e7aa056fdfb555ba32a63da3a01284
diff --git a/api/src/main/java/org/opencord/sadis/UniTagInformation.java b/api/src/main/java/org/opencord/sadis/UniTagInformation.java
index 5841d5e..05fa7ff 100644
--- a/api/src/main/java/org/opencord/sadis/UniTagInformation.java
+++ b/api/src/main/java/org/opencord/sadis/UniTagInformation.java
@@ -53,6 +53,12 @@
     @JsonProperty(value = "downstreamBandwidthProfile")
     private String downstreamBandwidthProfile;
 
+    @JsonProperty(value = "upstreamOltBandwidthProfile")
+    private String upstreamOltBandwidthProfile;
+
+    @JsonProperty(value = "downstreamOltBandwidthProfile")
+    private String downstreamOltBandwidthProfile;
+
     @JsonProperty(value = "serviceName")
     private String serviceName;
 
@@ -71,12 +77,15 @@
     public UniTagInformation() {
 
     }
-
+    //CHECKSTYLE:OFF
     private UniTagInformation(final VlanId uniTagMatch, final VlanId ponCTag, final VlanId ponSTag,
                               final int usPonCTagPriority, final int usPonSTagPriority,
                               final int dsPonCTagPriority, final int dsPonSTagPriority,
                               final int technologyProfileId,
-                              final String upstreamBandwidthProfile, final String downstreamBandwidthProfile,
+                              final String upstreamBandwidthProfile,
+                              final String downstreamBandwidthProfile,
+                              final String upstreamOltBandwidthProfile,
+                              final String downstreamOltBandwidthProfile,
                               final String serviceName, final boolean enableMacLearning,
                               final String configuredMacAddress, final boolean isDhcpRequired,
                               final boolean isIgmpRequired) {
@@ -90,12 +99,15 @@
         this.technologyProfileId = technologyProfileId;
         this.upstreamBandwidthProfile = upstreamBandwidthProfile;
         this.downstreamBandwidthProfile = downstreamBandwidthProfile;
+        this.upstreamOltBandwidthProfile = upstreamOltBandwidthProfile;
+        this.downstreamOltBandwidthProfile = downstreamOltBandwidthProfile;
         this.serviceName = serviceName;
         this.enableMacLearning = enableMacLearning;
         this.configuredMacAddress = configuredMacAddress;
         this.isDhcpRequired = isDhcpRequired;
         this.isIgmpRequired = isIgmpRequired;
     }
+    //CHECKSTYLE:ON
 
     public final VlanId getUniTagMatch() {
         return uniTagMatch;
@@ -137,6 +149,14 @@
         return downstreamBandwidthProfile;
     }
 
+    public final String getUpstreamOltBandwidthProfile() {
+        return upstreamOltBandwidthProfile;
+    }
+
+    public final String getDownstreamOltBandwidthProfile() {
+        return downstreamOltBandwidthProfile;
+    }
+
     public final String getServiceName() {
         return serviceName;
     }
@@ -212,6 +232,16 @@
                 that.downstreamBandwidthProfile != null) {
             return false;
         }
+        if (upstreamOltBandwidthProfile != null ?
+                !upstreamOltBandwidthProfile.equals(that.upstreamOltBandwidthProfile) :
+                that.upstreamOltBandwidthProfile != null) {
+            return false;
+        }
+        if (downstreamOltBandwidthProfile != null ?
+                !downstreamOltBandwidthProfile.equals(that.downstreamOltBandwidthProfile) :
+                that.downstreamOltBandwidthProfile != null) {
+            return false;
+        }
         return serviceName != null ? serviceName.equals(that.serviceName) : that.serviceName == null;
     }
 
@@ -227,6 +257,8 @@
         result = 31 * result + technologyProfileId;
         result = 31 * result + (upstreamBandwidthProfile != null ? upstreamBandwidthProfile.hashCode() : 0);
         result = 31 * result + (downstreamBandwidthProfile != null ? downstreamBandwidthProfile.hashCode() : 0);
+        result = 31 * result + (upstreamOltBandwidthProfile != null ? upstreamOltBandwidthProfile.hashCode() : 0);
+        result = 31 * result + (downstreamOltBandwidthProfile != null ? downstreamOltBandwidthProfile.hashCode() : 0);
         result = 31 * result + (serviceName != null ? serviceName.hashCode() : 0);
         result = 31 * result + (enableMacLearning ? 1 : 0);
         result = 31 * result + (configuredMacAddress != null ? configuredMacAddress.hashCode() : 0);
@@ -249,6 +281,8 @@
         sb.append(", enableMacLearning=").append(enableMacLearning);
         sb.append(", upstreamBandwidthProfile='").append(upstreamBandwidthProfile).append('\'');
         sb.append(", downstreamBandwidthProfile='").append(downstreamBandwidthProfile).append('\'');
+        sb.append(", upstreamOltBandwidthProfile='").append(upstreamOltBandwidthProfile).append('\'');
+        sb.append(", downstreamOltBandwidthProfile='").append(downstreamOltBandwidthProfile).append('\'');
         sb.append(", serviceName='").append(serviceName).append('\'');
         sb.append(", configuredMacAddress='").append(configuredMacAddress).append('\'');
         sb.append(", isDhcpRequired=").append(isDhcpRequired);
@@ -269,6 +303,8 @@
         private int technologyProfileId;
         private String upstreamBandwidthProfile;
         private String downstreamBandwidthProfile;
+        private String upstreamOltBandwidthProfile;
+        private String downstreamOltBandwidthProfile;
         private String serviceName;
         private boolean enableMacLearning;
         private String configuredMacAddress;
@@ -325,6 +361,16 @@
             return this;
         }
 
+        public final Builder setUpstreamOltBandwidthProfile(final String upstreamOltBandwidthProfile) {
+            this.upstreamOltBandwidthProfile = upstreamOltBandwidthProfile;
+            return this;
+        }
+
+        public final Builder setDownstreamOltBandwidthProfile(final String downstreamOltBandwidthProfile) {
+            this.downstreamOltBandwidthProfile = downstreamOltBandwidthProfile;
+            return this;
+        }
+
         public final Builder setServiceName(final String serviceName) {
             this.serviceName = serviceName;
             return this;
@@ -354,8 +400,10 @@
             return new UniTagInformation(this.uniTagMatch, this.ponCTag,
                     this.ponSTag, this.usPonCTagPriority, this.usPonSTagPriority,
                     this.dsPonCTagPriority, this.dsPonSTagPriority, this.technologyProfileId,
-                    this.upstreamBandwidthProfile, this.downstreamBandwidthProfile, this.serviceName,
-                    this.enableMacLearning, this.configuredMacAddress, this.isDhcpRequired, this.isIgmpRequired);
+                    this.upstreamBandwidthProfile, this.downstreamBandwidthProfile,
+                    this.upstreamOltBandwidthProfile, this.downstreamOltBandwidthProfile,
+                    this.serviceName, this.enableMacLearning,
+                    this.configuredMacAddress, this.isDhcpRequired, this.isIgmpRequired);
         }
     }
 }
diff --git a/app/src/main/java/org/opencord/sadis/impl/InformationAdapter.java b/app/src/main/java/org/opencord/sadis/impl/InformationAdapter.java
index 7656cf0..216b5f8 100644
--- a/app/src/main/java/org/opencord/sadis/impl/InformationAdapter.java
+++ b/app/src/main/java/org/opencord/sadis/impl/InformationAdapter.java
@@ -227,6 +227,7 @@
 
         if (info != null) {
             local.put(id, info);
+            log.debug("Returning Info {}", info);
             return info;
         } else {
             log.warn("Data not found for id {}", id);
diff --git a/app/src/main/java/org/opencord/sadis/impl/SubscriberAndDeviceInformationConfig.java b/app/src/main/java/org/opencord/sadis/impl/SubscriberAndDeviceInformationConfig.java
index d794433..43170a8 100644
--- a/app/src/main/java/org/opencord/sadis/impl/SubscriberAndDeviceInformationConfig.java
+++ b/app/src/main/java/org/opencord/sadis/impl/SubscriberAndDeviceInformationConfig.java
@@ -62,23 +62,25 @@
  *             "remoteId"                   : string,
  *             "uniTagList": [
  *                  {
- *                  "uniTagMatch"               : int,
- *                  "ponCTag"                   : string,
- *                  "ponSTag"                   : string,
- *                  "usPonCTagPriority"         : int,
- *                  "dsPonCTagPriority"         : int,
- *                  "usPonSTagPriority"         : int,
- *                  "dsPonSTagPriority"         : int,
- *                  "technologyProfileId"       : int,
- *                  "upstreamBandwidthProfile"  : string,
- *                  "downstreamBandwidthProfile": string,
- *                  "enableMacLearning"         : string,
- *                  "configuredDacAddress"      : string,
- *                  "isDhcpRequired"            : string,
- *                  "isIgmpRequired"            : string,
- *                  "serviceName"               : string
+ *                  "uniTagMatch"                   : int,
+ *                  "ponCTag"                       : string,
+ *                  "ponSTag"                       : string,
+ *                  "usPonCTagPriority"             : int,
+ *                  "dsPonCTagPriority"             : int,
+ *                  "usPonSTagPriority"             : int,
+ *                  "dsPonSTagPriority"             : int,
+ *                  "technologyProfileId"           : int,
+ *                  "upstreamBandwidthProfile"      : string,
+ *                  "downstreamBandwidthProfile"    : string,
+ *                  "upstreamOltBandwidthProfile"   : string,
+ *                  "downstreamOltBandwidthProfile" : string,
+ *                  "enableMacLearning"             : string,
+ *                  "configuredDacAddress"          : string,
+ *                  "isDhcpRequired"                : string,
+ *                  "isIgmpRequired"                : string,
+ *                  "serviceName"                   : string
  *                 }
- *                 ]
+ *              ]
  *         }, ...
  *     ]
  * }
@@ -100,6 +102,8 @@
     private static final String TP_ID = "technologyProfileId";
     private static final String US_BW = "upstreamBandwidthProfile";
     private static final String DS_BW = "downstreamBandwidthProfile";
+    private static final String US_OLT_BW = "upstreamOltBandwidthProfile";
+    private static final String DS_OLT_BW = "downstreamOltBandwidthProfile";
     private static final String SERVICE_NAME = "serviceName";
     private static final String IS_DHCP_REQ = "isDhcpRequired";
     private static final String IS_IGMP_REQ = "isIgmpRequired";
@@ -156,6 +160,8 @@
     }
 
     public UniTagInformation getUniTagInformation(JsonNode node) {
+        String usBw = node.get(US_BW) == null ? null : node.get(US_BW).asText();
+        String dsBw = node.get(DS_BW) == null ? null : node.get(DS_BW).asText();
         return new UniTagInformation.Builder()
                 .setUniTagMatch(VlanId.vlanId(node.get(UNI_TAG_MATCH) == null ? VlanId.NO_VID
                         : (short) node.get(UNI_TAG_MATCH).asInt()))
@@ -172,10 +178,12 @@
                 .setEnableMacLearning(node.get(MAC_LEARNING) == null ? false :
                         node.get(MAC_LEARNING).asBoolean())
                 .setTechnologyProfileId(node.get(TP_ID).asInt())
-                .setUpstreamBandwidthProfile(node.get(US_BW) == null ? null
-                        : node.get(US_BW).asText())
-                .setDownstreamBandwidthProfile(node.get(DS_BW) == null ? null
-                        : node.get(DS_BW).asText())
+                .setUpstreamBandwidthProfile(usBw)
+                .setDownstreamBandwidthProfile(dsBw)
+                .setUpstreamOltBandwidthProfile(node.get(US_OLT_BW) == null ? usBw
+                        : node.get(US_OLT_BW).asText())
+                .setDownstreamOltBandwidthProfile(node.get(DS_OLT_BW) == null ? dsBw
+                        : node.get(DS_OLT_BW).asText())
                 .setServiceName(node.get(SERVICE_NAME) == null ? NO_SN :
                         node.get(SERVICE_NAME).asText())
                 .setIsDhcpRequired(node.get(IS_DHCP_REQ) == null ? false : node.get(IS_DHCP_REQ).asBoolean())
diff --git a/app/src/main/java/org/opencord/sadis/impl/SubscriberManager.java b/app/src/main/java/org/opencord/sadis/impl/SubscriberManager.java
index b0de0c4..01f948f 100644
--- a/app/src/main/java/org/opencord/sadis/impl/SubscriberManager.java
+++ b/app/src/main/java/org/opencord/sadis/impl/SubscriberManager.java
@@ -29,6 +29,7 @@
 import org.onosproject.core.ApplicationId;
 import org.onosproject.net.config.ConfigFactory;
 import org.opencord.sadis.SubscriberAndDeviceInformation;
+import org.opencord.sadis.UniTagInformation;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -74,8 +75,10 @@
         SubscriberAndDeviceInformationConfig config = new SubscriberAndDeviceInformationConfig();
         SubscriberAndDeviceInformationConfig.VlanIdDeserializer vlanID = config.new VlanIdDeserializer();
         SubscriberAndDeviceInformationConfig.Ip4AddressDeserializer ip4Address = config.new Ip4AddressDeserializer();
+        SubscriberAndDeviceInformationConfig.UniTagDeserializer uniTagSerializer = config.new UniTagDeserializer();
         module.addDeserializer(VlanId.class, vlanID);
         module.addDeserializer(Ip4Address.class, ip4Address);
+        module.addDeserializer(UniTagInformation.class, uniTagSerializer);
         mapper.registerModule(module);
     }
 
diff --git a/app/src/main/java/org/opencord/sadis/impl/UniTagInformationCodec.java b/app/src/main/java/org/opencord/sadis/impl/UniTagInformationCodec.java
index 5e27e52..cad67c0 100644
--- a/app/src/main/java/org/opencord/sadis/impl/UniTagInformationCodec.java
+++ b/app/src/main/java/org/opencord/sadis/impl/UniTagInformationCodec.java
@@ -20,9 +20,14 @@
 import org.onosproject.codec.CodecContext;
 import org.onosproject.codec.JsonCodec;
 import org.opencord.sadis.UniTagInformation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class UniTagInformationCodec extends JsonCodec<UniTagInformation> {
 
+    private final Logger log = LoggerFactory.getLogger(this.getClass());
+
+
     private static final String UNI_TAG_MATCH = "uniTagMatch";
     private static final String PON_CTAG = "ponCTag";
     private static final String PON_STAG = "ponSTag";
@@ -33,6 +38,8 @@
     private static final String TP_ID = "technologyProfileId";
     private static final String US_BP = "upstreamBandwidthProfile";
     private static final String DS_BP = "downstreamBandwidthProfile";
+    private static final String US_OLT_BP = "upstreamOltBandwidthProfile";
+    private static final String DS_OLT_BP = "downstreamOltBandwidthProfile";
     private static final String SN = "serviceName";
     private static final String MAC_LEARN = "enableMacLearning";
     private static final String MAC = "configuredMacAddress";
@@ -60,6 +67,8 @@
                 .put(TP_ID, entry.getTechnologyProfileId())
                 .put(US_BP, entry.getUpstreamBandwidthProfile())
                 .put(DS_BP, entry.getDownstreamBandwidthProfile())
+                .put(US_OLT_BP, entry.getUpstreamOltBandwidthProfile())
+                .put(DS_OLT_BP, entry.getDownstreamOltBandwidthProfile())
                 .put(SN, entry.getServiceName())
                 .put(MAC_LEARN, entry.getEnableMacLearning())
                 .put(MAC, entry.getConfiguredMacAddress())
@@ -74,6 +83,12 @@
         }
 
         UniTagInformation.Builder tagInfoBuilder = new UniTagInformation.Builder();
+        String usBp = json.get(US_BP) == null ? EMPTY_BP :
+                json.get(US_BP).asText();
+        String dsBp = json.get(DS_BP) == null ? EMPTY_BP :
+                json.get(DS_BP).asText();
+        String usOltBp = json.get(US_OLT_BP) == null ? usBp : json.get(US_OLT_BP).asText();
+        String dsOltBp = json.get(DS_OLT_BP) == null ? dsBp : json.get(DS_OLT_BP).asText();
         tagInfoBuilder.setUniTagMatch(json.get(UNI_TAG_MATCH) == null ? VlanId.vlanId(VlanId.NO_VID) :
                 VlanId.vlanId(json.get(UNI_TAG_MATCH).shortValue()))
                 .setPonCTag(json.get(PON_CTAG) == null ? VlanId.vlanId(VlanId.NO_VID) :
@@ -90,10 +105,10 @@
                         json.get(DS_PON_STAG_PCP).asInt())
                 .setTechnologyProfileId(json.get(TP_ID) == null ? NO_TP :
                         json.get(TP_ID).asInt())
-                .setUpstreamBandwidthProfile(json.get(US_BP) == null ? EMPTY_BP :
-                        json.get(US_BP).asText())
-                .setDownstreamBandwidthProfile(json.get(DS_BP) == null ? EMPTY_BP :
-                        json.get(DS_BP).asText())
+                .setUpstreamBandwidthProfile(usBp)
+                .setDownstreamBandwidthProfile(dsBp)
+                .setUpstreamOltBandwidthProfile(usOltBp)
+                .setDownstreamOltBandwidthProfile(dsOltBp)
                 .setServiceName(json.get(SN) == null ? EMPTY_SN :
                         json.get(SN).asText())
                 .setEnableMacLearning(json.get(MAC_LEARN) == null ? DEFAULT_MAC_LEARN :
@@ -104,7 +119,7 @@
                         json.get(DHCP_REQ).asBoolean())
                 .setIsIgmpRequired(json.get(IGMP_REQ) == null ? DEFAULT_IGMP_REQ :
                         json.get(IGMP_REQ).asBoolean());
-
+        log.info("Codec UniTagInformation Codec builder returning {}", tagInfoBuilder.build());
         return tagInfoBuilder.build();
     }
 }
diff --git a/app/src/test/java/org/opencord/sadis/impl/BaseSadis.java b/app/src/test/java/org/opencord/sadis/impl/BaseSadis.java
index 15492e6..eba613b 100644
--- a/app/src/test/java/org/opencord/sadis/impl/BaseSadis.java
+++ b/app/src/test/java/org/opencord/sadis/impl/BaseSadis.java
@@ -65,6 +65,7 @@
     private static final int TECH_PROF_ID_2 = 65;
 
     private static final String HSA = "HSA";
+    private static final String HSA_OLT = "HSA_OLT";
     private static final String IPTV = "IPTV";
     private static final String NAS_PORT_ID = "1/1/2";
 
@@ -107,6 +108,7 @@
     protected static final String ID3 = "3";
     protected static final String ID4 = "4";
     protected static final String ID5 = "5";
+    protected static final String ID6 = "6";
 
     UniTagInformation ttService1 = new UniTagInformation.Builder()
             .setUniTagMatch(VlanId.vlanId(UNI_TAG_MATCH_1))
@@ -140,6 +142,22 @@
             .setConfiguredMacAddress(MAC2)
             .build();
 
+    UniTagInformation ttService3 = new UniTagInformation.Builder()
+            .setUniTagMatch(VlanId.vlanId(UNI_TAG_MATCH_1))
+            .setPonCTag(VlanId.vlanId(C_TAG_1))
+            .setPonSTag(VlanId.vlanId(S_TAG_1))
+            .setUsPonCTagPriority(C_TAG_PRIORITY)
+            .setUsPonSTagPriority(S_TAG_PRIORITY)
+            .setDsPonCTagPriority(C_TAG_PRIORITY)
+            .setDsPonSTagPriority(S_TAG_PRIORITY)
+            .setTechnologyProfileId(TECH_PROF_ID_1)
+            .setUpstreamBandwidthProfile(HSA)
+            .setDownstreamBandwidthProfile(HSA)
+            .setUpstreamOltBandwidthProfile(HSA_OLT)
+            .setDownstreamOltBandwidthProfile(HSA_OLT)
+            .setServiceName(HSA)
+            .build();
+
     UniTagInformation attService1 = new UniTagInformation.Builder()
             .setPonCTag(VlanId.vlanId(C_TAG_1))
             .setPonSTag(VlanId.vlanId(S_TAG_2))
@@ -150,6 +168,7 @@
 
     List<UniTagInformation> uniTagListForTT = Lists.newArrayList(ttService1);
     List<UniTagInformation> uniTagList2ForTT = Lists.newArrayList(ttService1, ttService2);
+    List<UniTagInformation> uniTagList3ForTT = Lists.newArrayList(ttService3);
     List<UniTagInformation> uniTagList3Att = Lists.newArrayList(attService1);
 
     SubscriberAndDeviceInformationBuilder entry1 = SubscriberAndDeviceInformationBuilder.build(ID1, NAS_PORT_ID,
@@ -162,6 +181,8 @@
             PORT_4, SLOT_4, MAC3, NAS4, IP4, CIRCUIT4, REMOTE4, uniTagList2ForTT);
     SubscriberAndDeviceInformationBuilder entry5 = SubscriberAndDeviceInformationBuilder.build(ID5, NAS_PORT_ID,
             PORT_3, SLOT_3, MAC2, NAS3, IP3, CIRCUIT3, REMOTE3, uniTagList3Att);
+    SubscriberAndDeviceInformationBuilder entry6 = SubscriberAndDeviceInformationBuilder.build(ID6, NAS_PORT_ID,
+            PORT_3, SLOT_3, MAC2, NAS3, IP3, CIRCUIT3, REMOTE3, uniTagList3ForTT);
 
     public void setUp(String localConfig, Class configClass) throws Exception {
         sadis = new SadisManager();
diff --git a/app/src/test/java/org/opencord/sadis/impl/SubscriberAndDeviceManagerTest.java b/app/src/test/java/org/opencord/sadis/impl/SubscriberAndDeviceManagerTest.java
index 1fbfbcd..d2bc07c 100644
--- a/app/src/test/java/org/opencord/sadis/impl/SubscriberAndDeviceManagerTest.java
+++ b/app/src/test/java/org/opencord/sadis/impl/SubscriberAndDeviceManagerTest.java
@@ -56,10 +56,11 @@
 
     private void checkEntriesForSubscriberAndAccessDevice(BaseConfig config) {
         List<SubscriberAndDeviceInformation> entries = config.getEntries();
-        assertEquals(3, entries.size());
+        assertEquals(4, entries.size());
         assertTrue(checkEquality(entry1, entries.get(0)));
         assertTrue(checkEquality(entry2, entries.get(1)));
         assertTrue(checkEquality(entry5, entries.get(2)));
+        assertTrue(checkEquality(entry6, entries.get(3)));
     }
 
     @Test
@@ -70,12 +71,14 @@
         checkGetForExisting(ID1, entry1, subscriberService);
         checkGetForExisting(ID2, entry2, subscriberService);
         checkGetForExisting(ID5, entry5, subscriberService);
+        checkGetForExisting(ID6, entry6, subscriberService);
 
         invalidateId(ID1, subscriberService);
         checkFromBoth(ID1, entry1, subscriberService);
 
         invalidateAll(subscriberService);
         checkFromBoth(ID2, entry2, subscriberService);
+        checkFromBoth(ID6, entry6, subscriberService);
     }
 
 
diff --git a/app/src/test/resources/LocalSubConfig.json b/app/src/test/resources/LocalSubConfig.json
index 1efee37..6eff750 100644
--- a/app/src/test/resources/LocalSubConfig.json
+++ b/app/src/test/resources/LocalSubConfig.json
@@ -98,6 +98,28 @@
 					"downstreamBandwidthProfile":"HSA"
 				}
 			]
+		},
+		{
+			"id": "6",
+			"nasPortId": "1/1/2",
+			"uplinkPort": 125,
+			"slot": 3,
+			"hardwareIdentifier": "aa:bb:cc:dd:ee:ff",
+			"ipAddress":"10.10.10.10",
+			"nasId":"XXX-NASID",
+			"circuitId":"circuit123",
+			"remoteId":"remote123",
+			"uniTagList": [
+				{
+					"ponCTag":"2,",
+					"ponSTag":"2",
+					"technologyProfileId":64,
+					"upstreamBandwidthProfile":"HSA",
+					"downstreamBandwidthProfile":"HSA",
+					"upstreamOltBandwidthProfile":"HSA_OLT",
+					"downstreamOltBandwidthProfile":"HSA_OLT"
+				}
+			]
 		}
 	]
 }