[VOL-2761][VOL-2905] Support for DT workflow

Change-Id: I9fe1fae20d3a5970a474a234aa3bde0f9110569e
diff --git a/internal/bbsim/responders/sadis/sadis.go b/internal/bbsim/responders/sadis/sadis.go
index d24daeb..fc2b451 100644
--- a/internal/bbsim/responders/sadis/sadis.go
+++ b/internal/bbsim/responders/sadis/sadis.go
@@ -93,10 +93,10 @@
 	NasPortID  string        `json:"nasPortId"`
 	CircuitID  string        `json:"circuitId"`
 	RemoteID   string        `json:"remoteId"`
-	UniTagList []SadisUniTag `json:"uniTagList"`
+	UniTagList []interface{} `json:"uniTagList"` // this can be SadisUniTagAtt, SadisUniTagDt
 }
 
-type SadisUniTag struct {
+type SadisUniTagAtt struct {
 	PonCTag                    int    `json:"ponCTag, omitempty"`
 	PonSTag                    int    `json:"ponSTag, omitempty"`
 	TechnologyProfileID        int    `json:"technologyProfileId, omitempty"`
@@ -106,6 +106,15 @@
 	IsIgmpRequired             bool   `json:"isIgmpRequired, omitempty"`
 }
 
+type SadisUniTagDt struct {
+	UniTagMatch                int    `json:"uniTagMatch, omitempty"`
+	PonCTag                    int    `json:"ponCTag, omitempty"`
+	PonSTag                    int    `json:"ponSTag, omitempty"`
+	TechnologyProfileID        int    `json:"technologyProfileId, omitempty"`
+	UpstreamBandwidthProfile   string `json:"upstreamBandwidthProfile, omitempty"`
+	DownstreamBandwidthProfile string `json:"downstreamBandwidthProfile, omitempty"`
+}
+
 // SADIS BandwithProfile Entry
 type SadisBWPEntry struct {
 	ID  string `json:"id"`
@@ -189,18 +198,34 @@
 		RemoteID:  onu.Sn() + uniSuffix,
 	}
 
-	// TODO this sadis config only works for the ATT workflow
-	// address VOL-2761 to support DT
-	sonuUniTag := SadisUniTag{
-		PonCTag:             onu.CTag,
-		PonSTag:             onu.STag,
-		TechnologyProfileID: 64,
-		// NOTE do we want to select a random bandwidth profile?
-		// if so use bandwidthProfiles[rand.Intn(len(bandwidthProfiles))].ID
-		UpstreamBandwidthProfile:   "Default",
-		DownstreamBandwidthProfile: "User_Bandwidth1",
-		IsDhcpRequired:             true,
-		IsIgmpRequired:             true,
+	// base structure common to all use cases
+	var sonuUniTag interface{}
+
+	// set workflow specific params
+	switch common.Options.BBSim.SadisFormat {
+	case common.SadisFormatAtt:
+		sonuUniTag = SadisUniTagAtt{
+			PonCTag:             onu.CTag,
+			PonSTag:             onu.STag,
+			TechnologyProfileID: 64,
+			// NOTE do we want to select a random bandwidth profile?
+			// if so use bandwidthProfiles[rand.Intn(len(bandwidthProfiles))].ID
+			UpstreamBandwidthProfile:   "Default",
+			DownstreamBandwidthProfile: "User_Bandwidth1",
+			IsDhcpRequired:             true,
+			IsIgmpRequired:             true,
+		}
+	case common.SadisFormatDt:
+		sonuUniTag = SadisUniTagDt{
+			PonCTag:             4096,
+			PonSTag:             onu.STag,
+			TechnologyProfileID: 64,
+			// NOTE do we want to select a random bandwidth profile?
+			// if so use bandwidthProfiles[rand.Intn(len(bandwidthProfiles))].ID
+			UpstreamBandwidthProfile:   "Default",
+			DownstreamBandwidthProfile: "User_Bandwidth1",
+			UniTagMatch:                4096,
+		}
 	}
 
 	sonuv2.UniTagList = append(sonuv2.UniTagList, sonuUniTag)
diff --git a/internal/bbsim/responders/sadis/sadis_test.go b/internal/bbsim/responders/sadis/sadis_test.go
new file mode 100644
index 0000000..7c8bc1b
--- /dev/null
+++ b/internal/bbsim/responders/sadis/sadis_test.go
@@ -0,0 +1,121 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+
+ * http://www.apache.org/licenses/LICENSE-2.0
+
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package sadis
+
+import (
+	"fmt"
+	"github.com/opencord/bbsim/internal/bbsim/devices"
+	"github.com/opencord/bbsim/internal/common"
+	"gotest.tools/assert"
+	"net"
+	"testing"
+)
+
+func createMockDevices() (devices.OltDevice, devices.Onu) {
+	olt := devices.OltDevice{
+		ID: 0,
+	}
+
+	onu := devices.Onu{
+		ID:        1,
+		PonPortID: 1,
+		STag:      900,
+		CTag:      923,
+		HwAddress: net.HardwareAddr{0x2e, 0x60, 0x70, 0x13, byte(1), byte(1)},
+		PortNo:    0,
+	}
+	onu.SerialNumber = onu.NewSN(0, onu.PonPortID, onu.ID)
+
+	return olt, onu
+}
+
+func TestSadisServer_GetOnuEntryV1(t *testing.T) {
+
+	olt, onu := createMockDevices()
+
+	uni := "1"
+
+	res, err := GetOnuEntryV1(&olt, &onu, uni)
+	if err != nil {
+		t.Fatal(err)
+	}
+
+	assert.Equal(t, res.ID, fmt.Sprintf("%s-%s",onu.Sn(), uni))
+	assert.Equal(t, res.CTag, 923)
+	assert.Equal(t, res.STag, 900)
+	assert.Equal(t, res.RemoteID, string(olt.SerialNumber))
+	assert.Equal(t, res.DownstreamBandwidthProfile, "Default")
+	assert.Equal(t, res.UpstreamBandwidthProfile, "User_Bandwidth1")
+	assert.Equal(t, res.TechnologyProfileID, 64)
+
+}
+
+func TestSadisServer_GetOnuEntryV2_Att(t *testing.T) {
+	olt, onu := createMockDevices()
+
+	uni := "1"
+
+	res, err := GetOnuEntryV2(&olt, &onu, uni)
+	if err != nil {
+		t.Fatal(err)
+	}
+
+	assert.Equal(t, res.ID, fmt.Sprintf("%s-%s",onu.Sn(), uni))
+	assert.Equal(t, res.RemoteID, fmt.Sprintf("%s-%s",onu.Sn(), uni))
+
+	// assert the correct type
+	uniTagList, ok := res.UniTagList[0].(SadisUniTagAtt)
+	if !ok {
+		t.Fatal("UniTagList has the wrong type")
+	}
+
+	assert.Equal(t, uniTagList.PonCTag, 923)
+	assert.Equal(t, uniTagList.PonSTag, 900)
+	assert.Equal(t, uniTagList.DownstreamBandwidthProfile, "User_Bandwidth1")
+	assert.Equal(t, uniTagList.UpstreamBandwidthProfile, "Default")
+	assert.Equal(t, uniTagList.TechnologyProfileID, 64)
+	assert.Equal(t, uniTagList.IsDhcpRequired, true)
+	assert.Equal(t, uniTagList.IsIgmpRequired, true)
+}
+
+func TestSadisServer_GetOnuEntryV2_Dt(t *testing.T) {
+	common.Options.BBSim.SadisFormat = common.SadisFormatDt
+	olt, onu := createMockDevices()
+
+	uni := "1"
+
+	res, err := GetOnuEntryV2(&olt, &onu, uni)
+	if err != nil {
+		t.Fatal(err)
+	}
+
+	assert.Equal(t, res.ID, fmt.Sprintf("%s-%s",onu.Sn(), uni))
+	assert.Equal(t, res.RemoteID, fmt.Sprintf("%s-%s",onu.Sn(), uni))
+
+	// assert the correct type
+	uniTagList, ok := res.UniTagList[0].(SadisUniTagDt)
+	if !ok {
+		t.Fatal("UniTagList has the wrong type")
+	}
+
+	assert.Equal(t, uniTagList.PonCTag, 4096)
+	assert.Equal(t, uniTagList.PonSTag, 900)
+	assert.Equal(t, uniTagList.DownstreamBandwidthProfile, "User_Bandwidth1")
+	assert.Equal(t, uniTagList.UpstreamBandwidthProfile, "Default")
+	assert.Equal(t, uniTagList.TechnologyProfileID, 64)
+	assert.Equal(t, uniTagList.UniTagMatch, 4096)
+}
\ No newline at end of file