Revert "Revert "SEBA-814 To support Multi-Tcont on TT-workflow, SADIS configuration is updated.""

(Re-applying changes after releasing and bumping major version)

This reverts commit e4f4b63f171ffd2ec92ee6e3a3f35e8905bce215.

Change-Id: I7b34c094f95455becffa7fa55d1de9eba55d298a
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 7d2604a..7979223 100644
--- a/app/src/test/java/org/opencord/sadis/impl/BaseSadis.java
+++ b/app/src/test/java/org/opencord/sadis/impl/BaseSadis.java
@@ -17,6 +17,10 @@
 
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.collect.Lists;
+import org.onlab.packet.Ip4Address;
+import org.onlab.packet.MacAddress;
+import org.onlab.packet.VlanId;
 import org.onosproject.codec.impl.CodecManager;
 import org.onosproject.core.ApplicationId;
 import org.onosproject.core.CoreServiceAdapter;
@@ -26,8 +30,10 @@
 import org.onosproject.net.config.Config;
 import org.onosproject.net.config.NetworkConfigEvent;
 import org.opencord.sadis.BaseConfig;
-import org.opencord.sadis.BaseInformationService;
 import org.opencord.sadis.BaseInformation;
+import org.opencord.sadis.BaseInformationService;
+import org.opencord.sadis.SubscriberAndDeviceInformation;
+import org.opencord.sadis.UniTagInformation;
 
 import java.io.InputStream;
 import java.time.Duration;
@@ -48,6 +54,115 @@
     protected NetworkConfigEvent event;
     protected static NetworkConfigListener configListener;
 
+    private static final short UNI_TAG_MATCH_1 = 100;
+    private static final short UNI_TAG_MATCH_2 = 200;
+    private static final short C_TAG_1 = 2;
+    private static final short S_TAG_1 = 2;
+    private static final short S_TAG_2 = 3;
+    private static final int C_TAG_PRIORITY = 0;
+    private static final int S_TAG_PRIORITY = 1;
+    private static final int TECH_PROF_ID_1 = 64;
+    private static final int TECH_PROF_ID_2 = 65;
+
+    private static final String HSA = "HSA";
+    private static final String IPTV = "IPTV";
+    private static final String NAS_PORT_ID = "1/1/2";
+
+    private static final short PORT_1 = 125;
+    private static final short PORT_2 = 129;
+    private static final short PORT_3 = 130;
+    private static final short PORT_4 = 132;
+
+    private static final short SLOT_1 = 3;
+    private static final short SLOT_2 = 4;
+    private static final short SLOT_3 = 7;
+    private static final short SLOT_4 = 1;
+
+    private static final String MAC1 = "aa:bb:cc:dd:ee:ff";
+    private static final String MAC2 = "ff:aa:dd:cc:bb:ee";
+    private static final String MAC3 = "ff:cc:dd:aa:ee:bb";
+
+    private static final String NAS1 = "XXX-NASID";
+    private static final String NAS2 = "YYY-NASID";
+    private static final String NAS3 = "MNO-NASID";
+    private static final String NAS4 = "PQR-NASID";
+
+    private static final String CIRCUIT1 = "circuit123";
+    private static final String CIRCUIT2 = "circuit234";
+    private static final String CIRCUIT3 = "circuit567";
+    private static final String CIRCUIT4 = "circuit678";
+
+    private static final String REMOTE1 = "remote123";
+    private static final String REMOTE2 = "remote234";
+    private static final String REMOTE3 = "remote567";
+    private static final String REMOTE4 = "remote678";
+
+    private static final String IP1 = "10.10.10.10";
+    private static final String IP2 = "1.1.1.1";
+    private static final String IP3 = "30.30.30.30";
+    private static final String IP4 = "15.15.15.15";
+
+    protected static final String ID1 = "1";
+    protected static final String ID2 = "2";
+    protected static final String ID3 = "3";
+    protected static final String ID4 = "4";
+    protected static final String ID5 = "5";
+
+    UniTagInformation ttService1 = 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)
+            .setServiceName(HSA)
+            .build();
+
+    UniTagInformation ttService2 = new UniTagInformation.Builder()
+            .setUniTagMatch(VlanId.vlanId(UNI_TAG_MATCH_2))
+            .setPonCTag(VlanId.vlanId(C_TAG_1))
+            .setPonSTag(VlanId.vlanId(S_TAG_2))
+            .setUsPonCTagPriority(C_TAG_PRIORITY)
+            .setUsPonSTagPriority(S_TAG_PRIORITY)
+            .setDsPonCTagPriority(C_TAG_PRIORITY)
+            .setDsPonSTagPriority((S_TAG_PRIORITY))
+            .setTechnologyProfileId(TECH_PROF_ID_2)
+            .setUpstreamBandwidthProfile(IPTV)
+            .setDownstreamBandwidthProfile(IPTV)
+            .setServiceName(IPTV)
+            .setIsIgmpRequired(true)
+            .setIsDhcpRequired(true)
+            .setEnableMacLearning(true)
+            .setConfiguredMacAddress(MAC2)
+            .build();
+
+    UniTagInformation attService1 = new UniTagInformation.Builder()
+            .setPonCTag(VlanId.vlanId(C_TAG_1))
+            .setPonSTag(VlanId.vlanId(S_TAG_2))
+            .setTechnologyProfileId(TECH_PROF_ID_1)
+            .setUpstreamBandwidthProfile(HSA)
+            .setDownstreamBandwidthProfile(HSA)
+            .build();
+
+    List<UniTagInformation> uniTagListForTT = Lists.newArrayList(ttService1);
+    List<UniTagInformation> uniTagList2ForTT = Lists.newArrayList(ttService1, ttService2);
+    List<UniTagInformation> uniTagList3Att = Lists.newArrayList(attService1);
+
+    SubscriberAndDeviceInformationBuilder entry1 = SubscriberAndDeviceInformationBuilder.build(ID1, NAS_PORT_ID,
+            PORT_1, SLOT_1, MAC1, NAS1, IP1, CIRCUIT1, REMOTE1, uniTagListForTT);
+    SubscriberAndDeviceInformationBuilder entry2 = SubscriberAndDeviceInformationBuilder.build(ID2, NAS_PORT_ID,
+            PORT_2, SLOT_2, MAC1, NAS2, IP2, CIRCUIT2, REMOTE2, uniTagList2ForTT);
+    SubscriberAndDeviceInformationBuilder entry3 = SubscriberAndDeviceInformationBuilder.build(ID3, NAS_PORT_ID,
+            PORT_3, SLOT_3, MAC2, NAS3, IP3, CIRCUIT3, REMOTE3, uniTagListForTT);
+    SubscriberAndDeviceInformationBuilder entry4 = SubscriberAndDeviceInformationBuilder.build(ID4, NAS_PORT_ID,
+            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);
+
     public void setUp(String localConfig, Class configClass) throws Exception {
         sadis = new SadisManager();
         sadis.coreService = new MockCoreService();
@@ -104,6 +219,33 @@
         }
     }
 
+    private static final class SubscriberAndDeviceInformationBuilder extends SubscriberAndDeviceInformation {
+
+        public static SubscriberAndDeviceInformationBuilder build(String id, String nasPortId,
+                                                                  short port, short slot, String mac,
+                                                                  String nasId, String ipAddress, String circuitId,
+                                                                  String remoteId,
+                                                                  List<UniTagInformation> uniTagList) {
+
+            SubscriberAndDeviceInformationBuilder info = new SubscriberAndDeviceInformationBuilder();
+            info.setId(id);
+            if (slot != -1) {
+                info.setSlot(slot);
+            }
+            info.setNasPortId(nasPortId);
+            info.setUplinkPort(port);
+            info.setHardwareIdentifier(MacAddress.valueOf(mac));
+            info.setIPAddress(Ip4Address.valueOf(ipAddress));
+            info.setNasId(nasId);
+            info.setCircuitId(circuitId);
+            info.setRemoteId(remoteId);
+
+            info.setUniTagList(uniTagList);
+
+            return info;
+        }
+
+    }
 
     /**
      * Mocks an ONOS configuration delegate to allow JSON based configuration to
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 6ff5cc3..fa68966 100644
--- a/app/src/test/java/org/opencord/sadis/impl/SubscriberAndDeviceManagerTest.java
+++ b/app/src/test/java/org/opencord/sadis/impl/SubscriberAndDeviceManagerTest.java
@@ -24,34 +24,17 @@
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
-import org.onlab.packet.Ip4Address;
-import org.onlab.packet.MacAddress;
-import org.onlab.packet.VlanId;
 
-import org.opencord.sadis.SubscriberAndDeviceInformation;
 import org.opencord.sadis.BaseConfig;
-import org.opencord.sadis.BaseInformationService;
 import org.opencord.sadis.BaseInformation;
+import org.opencord.sadis.BaseInformationService;
+import org.opencord.sadis.SubscriberAndDeviceInformation;
 
 /**
  * Set of tests of the SADIS ONOS application component.
  */
 public class SubscriberAndDeviceManagerTest extends BaseSadis {
 
-    SubscriberAndDeviceInformationBuilder entry1 = SubscriberAndDeviceInformationBuilder.build("1", (short) 2,
-            (short) 2, "1/1/2", (short) 125, (short) 3, "aa:bb:cc:dd:ee:ff", "XXX-NASID", "10.10.10.10",
-            "circuit123", "remote123", 64, "1Gb", "1Gb");
-    SubscriberAndDeviceInformationBuilder entry2 = SubscriberAndDeviceInformationBuilder.build("2", (short) 4,
-            (short) 4, "1/1/2", (short) 129, (short) 4, "aa:bb:cc:dd:ee:ff", "YYY-NASID", "1.1.1.1",
-            "circuit234", "remote234", 64, "10Gb", "10Gb");
-    SubscriberAndDeviceInformationBuilder entry3 = SubscriberAndDeviceInformationBuilder.build("3", (short) 7,
-            (short) 8, "1/1/2", (short) 130, (short) 7, "ff:aa:dd:cc:bb:ee", "MNO-NASID", "30.30.30.30",
-            "circuit567", "remote567", 64, "10Gb", "10Gb");
-    SubscriberAndDeviceInformationBuilder entry4 = SubscriberAndDeviceInformationBuilder.build("4", (short) 2,
-            (short) 1, "1/1/2", (short) 132, (short) 1, "ff:cc:dd:aa:ee:bb", "PQR-NASID", "15.15.15.15",
-            "circuit678", "remote678", 64, "5Gb", "5Gb");
-
-
     @Before
     public void setUp() throws Exception {
         config = new SubscriberAndDeviceInformationConfig();
@@ -74,23 +57,9 @@
     private void checkEntriesForSubscriberAndAccessDevice(BaseConfig config) {
         List<SubscriberAndDeviceInformation> entries = config.getEntries();
         assertEquals(3, entries.size());
-
-        SubscriberAndDeviceInformation sub = SubscriberAndDeviceInformationBuilder.build("1", (short) 2, (short) 2,
-                "1/1/2", (short) 125,
-                (short) 3, "aa:bb:cc:dd:ee:ff", "XXX-NASID", "10.10.10.10", "circuit123", "remote123",
-                64, "1Gb", "1Gb");
-        assertTrue(checkEquality(sub, entries.get(0)));
-
-
-        sub = SubscriberAndDeviceInformationBuilder.build("2", (short) 4, (short) 4, "1/1/2", (short) 129,
-                (short) 4, "aa:bb:cc:dd:ee:ff", "YYY-NASID", "1.1.1.1", "circuit234", "remote234",
-                64, "10Gb", "10Gb");
-        assertTrue(checkEquality(sub, entries.get(1)));
-
-        sub = SubscriberAndDeviceInformationBuilder.build("cc:dd:ee:ff:aa:bb", (short) -1, (short) -1, null,
-                (short) -1, (short) -1, "cc:dd:ee:ff:aa:bb", "CCC-NASID", "12.12.12.12", "circuit345", "remote345",
-                64, "10Gb", "10Gb");
-        assertTrue(checkEquality(sub, entries.get(2)));
+        assertTrue(checkEquality(entry1, entries.get(0)));
+        assertTrue(checkEquality(entry2, entries.get(1)));
+        assertTrue(checkEquality(entry5, entries.get(2)));
     }
 
     @Test
@@ -98,14 +67,15 @@
 
         BaseInformationService<SubscriberAndDeviceInformation> subscriberService = sadis.getSubscriberInfoService();
 
-        checkGetForExisting("1", entry1, subscriberService);
-        checkGetForExisting("2", entry2, subscriberService);
+        checkGetForExisting(ID1, entry1, subscriberService);
+        checkGetForExisting(ID2, entry2, subscriberService);
+        checkGetForExisting(ID5, entry5, subscriberService);
 
-        invalidateId("1", subscriberService);
-        checkFromBoth("1", entry1, subscriberService);
+        invalidateId(ID1, subscriberService);
+        checkFromBoth(ID1, entry1, subscriberService);
 
         invalidateAll(subscriberService);
-        checkFromBoth("2", entry2, subscriberService);
+        checkFromBoth(ID2, entry2, subscriberService);
     }
 
 
@@ -120,14 +90,14 @@
         config.init(subject, "sadis-remote-mode-test", node("/RemoteConfig.json"), mapper, delegate);
         configListener.event(event);
 
-        checkGetForExisting("3", entry3, subscriberService);
-        checkGetForExisting("4", entry4, subscriberService);
+        checkGetForExisting(ID3, entry3, subscriberService);
+        checkGetForExisting(ID4, entry4, subscriberService);
 
-        invalidateId("3", subscriberService);
-        checkFromBoth("3", entry3, subscriberService);
+        invalidateId(ID3, subscriberService);
+        checkFromBoth(ID3, entry3, subscriberService);
 
         invalidateAll(subscriberService);
-        checkFromBoth("4", entry4, subscriberService);
+        checkFromBoth(ID4, entry4, subscriberService);
     }
 
     @Test
@@ -136,60 +106,16 @@
         config.init(subject, "sadis-remote-mode-test", node("/RemoteConfig.json"), mapper, delegate);
         configListener.event(event);
 
-        checkGetForExisting("3", null, service);
-        checkGetForNonExist("1", service);
+        checkGetForExisting(ID3, null, service);
+        checkGetForNonExist(ID1, service);
 
         config.init(subject, "sadis-local-mode-test", node("/LocalSubConfig.json"), mapper, delegate);
         configListener.event(event);
 
-        checkGetForExisting("1", null, service);
-        checkGetForNonExist("3", service);
+        checkGetForExisting(ID1, null, service);
+        checkGetForNonExist(ID3, service);
     }
 
-
-    private static final class SubscriberAndDeviceInformationBuilder extends SubscriberAndDeviceInformation {
-
-        public static SubscriberAndDeviceInformationBuilder build(String id, short cTag, short sTag, String nasPortId,
-                                                                  short port, short slot, String mac, String nasId,
-                                                                  String ipAddress, String circuitId, String remoteId,
-                                                                  int technologyProfileId,
-                                                                  String upstreamBandwidthProfile,
-                                                                  String downstreamBandwidthProfile) {
-
-            SubscriberAndDeviceInformationBuilder info = new SubscriberAndDeviceInformationBuilder();
-            info.setId(id);
-            if (cTag != -1) {
-                info.setCTag(VlanId.vlanId(cTag));
-            }
-            if (sTag != -1) {
-                info.setSTag(VlanId.vlanId(sTag));
-            }
-            info.setNasPortId(nasPortId);
-            if (port != -1) {
-                info.setUplinkPort(port);
-            }
-            if (slot != -1) {
-                info.setSlot(slot);
-            }
-            info.setHardwareIdentifier(MacAddress.valueOf(mac));
-            info.setIPAddress(Ip4Address.valueOf(ipAddress));
-            info.setNasId(nasId);
-            info.setCircuitId(circuitId);
-            info.setRemoteId(remoteId);
-
-            if (technologyProfileId != -1) {
-                info.setTechnologyProfileId(technologyProfileId);
-            }
-
-            info.setUpstreamBandwidthProfile(upstreamBandwidthProfile);
-            info.setDownstreamBandwidthProfile(downstreamBandwidthProfile);
-
-            return info;
-        }
-
-    }
-
-    @Override
     public boolean checkEquality(BaseInformation localEntry, BaseInformation entry) {
         SubscriberAndDeviceInformation sub = (SubscriberAndDeviceInformation) localEntry;
         SubscriberAndDeviceInformation other = (SubscriberAndDeviceInformation) localEntry;
@@ -197,13 +123,6 @@
         if (other == null) {
             return false;
         }
-        if (sub.cTag() == null) {
-            if (other.cTag() != null) {
-                return false;
-            }
-        } else if (!sub.cTag().equals(other.cTag())) {
-            return false;
-        }
         if (sub.hardwareIdentifier() == null) {
             if (other.hardwareIdentifier() != null) {
                 return false;
@@ -242,13 +161,6 @@
         if (sub.uplinkPort() != other.uplinkPort()) {
             return false;
         }
-        if (sub.sTag() == null) {
-            if (other.sTag() != null) {
-                return false;
-            }
-        } else if (!sub.sTag().equals(other.sTag())) {
-            return false;
-        }
         if (sub.slot() != other.slot()) {
             return false;
         }
@@ -266,25 +178,13 @@
         } else if (!sub.remoteId().equals(other.remoteId())) {
             return false;
         }
-        if (sub.technologyProfileId() != other.technologyProfileId()) {
-            return false;
-        }
-        if (sub.upstreamBandwidthProfile() == null) {
-            if (other.upstreamBandwidthProfile() != null) {
+        if (sub.uniTagList() == null) {
+            if (other.uniTagList() != null) {
                 return false;
             }
-        } else if (!sub.upstreamBandwidthProfile().equals(other.upstreamBandwidthProfile())) {
-            return false;
-        }
-        if (sub.downstreamBandwidthProfile() == null) {
-            if (other.downstreamBandwidthProfile() != null) {
-                return false;
-            }
-        } else if (!sub.downstreamBandwidthProfile().equals(other.downstreamBandwidthProfile())) {
+        } else if (!sub.uniTagList().equals(other.uniTagList())) {
             return false;
         }
         return true;
     }
-
-
 }