[VOL-4111] Moving Services under the UNI struct
Controlling the UNI state via OMCI Set Messages
Upgraded APIs to reflect the new format

Change-Id: I3a6c166205fad4a381e562ab3b873d03b633303e
diff --git a/internal/bbsim/responders/sadis/sadis_test.go b/internal/bbsim/responders/sadis/sadis_test.go
index a3ca6df..8fbe789 100644
--- a/internal/bbsim/responders/sadis/sadis_test.go
+++ b/internal/bbsim/responders/sadis/sadis_test.go
@@ -17,8 +17,14 @@
 package sadis
 
 import (
+	"encoding/json"
 	"fmt"
+	"github.com/gorilla/mux"
+	"github.com/opencord/bbsim/internal/common"
+	omcilib "github.com/opencord/bbsim/internal/common/omci"
 	"net"
+	"net/http"
+	"net/http/httptest"
 	"testing"
 
 	"github.com/opencord/bbsim/internal/bbsim/devices"
@@ -26,21 +32,40 @@
 )
 
 func createMockDevices() (*devices.OltDevice, *devices.Onu) {
-	olt := &devices.OltDevice{
-		ID: 0,
-	}
 
+	// create a ONU
 	onu := &devices.Onu{
 		ID:        1,
 		PonPortID: 1,
-		PortNo:    0,
+	}
+	onu.SerialNumber = devices.NewSN(0, onu.PonPortID, onu.ID)
+
+	// create 2 UNIs for the ONU
+	unis := []devices.UniPortIf{
+		&devices.UniPort{ID: 0, Onu: onu, MeId: omcilib.GenerateUniPortEntityId(1)},
+		&devices.UniPort{ID: 1, Onu: onu, MeId: omcilib.GenerateUniPortEntityId(2)},
+	}
+	onu.UniPorts = unis
+
+	// create a service on each UNI
+	c_tag := 900
+	for i, u := range onu.UniPorts {
+		uni := u.(*devices.UniPort)
+		mac := net.HardwareAddr{0x2e, 0x01, byte(1), byte(1), byte(0), byte(i)}
+		uni.Services = []devices.ServiceIf{
+			&devices.Service{Name: "hsia", CTag: c_tag + i, STag: 900, NeedsEapol: true, NeedsDhcp: true, NeedsIgmp: true, HwAddress: mac, TechnologyProfileID: 64},
+		}
 	}
 
-	mac := net.HardwareAddr{0x2e, 0x60, 0x01, byte(1), byte(1), byte(0)}
-
-	onu.SerialNumber = devices.NewSN(0, onu.PonPortID, onu.ID)
-	onu.Services = []devices.ServiceIf{
-		&devices.Service{Name: "hsia", CTag: 923, STag: 900, NeedsEapol: true, NeedsDhcp: true, NeedsIgmp: true, HwAddress: mac, TechnologyProfileID: 64},
+	olt := &devices.OltDevice{
+		ID: 0,
+		Pons: []*devices.PonPort{
+			{
+				ID:     0,
+				NumOnu: 1,
+				Onus:   []*devices.Onu{onu},
+			},
+		},
 	}
 
 	return olt, onu
@@ -50,39 +75,94 @@
 
 	olt, onu := createMockDevices()
 
-	uni := "1"
+	for _, u := range onu.UniPorts {
+		uni := u.(*devices.UniPort)
 
-	entry, err := GetOnuEntryV2(olt, onu, uni)
+		entry, err := GetOnuEntryV2(olt, onu, fmt.Sprintf("%d", uni.ID+1))
 
-	assert.NilError(t, err)
+		assert.NilError(t, err)
 
-	assert.Equal(t, entry.ID, fmt.Sprintf("%s-%s", onu.Sn(), uni))
+		assert.Equal(t, fmt.Sprintf("%s-%d", onu.Sn(), uni.ID+1), entry.ID)
 
-	assert.Equal(t, entry.UniTagList[0].PonCTag, 923)
-	assert.Equal(t, entry.UniTagList[0].PonSTag, 900)
-	assert.Equal(t, entry.UniTagList[0].DownstreamBandwidthProfile, "User_Bandwidth2")
-	assert.Equal(t, entry.UniTagList[0].UpstreamBandwidthProfile, "User_Bandwidth1")
-	assert.Equal(t, entry.UniTagList[0].TechnologyProfileID, 64)
-	assert.Equal(t, entry.UniTagList[0].IsDhcpRequired, true)
-	assert.Equal(t, entry.UniTagList[0].IsIgmpRequired, true)
+		// we only have one service, thus get a single entry in the UniTagList
+		assert.Equal(t, len(entry.UniTagList), 1)
+		assert.Equal(t, entry.UniTagList[0].PonCTag, int(900+uni.ID))
+		assert.Equal(t, entry.UniTagList[0].PonSTag, 900)
+		assert.Equal(t, entry.UniTagList[0].DownstreamBandwidthProfile, "User_Bandwidth2")
+		assert.Equal(t, entry.UniTagList[0].UpstreamBandwidthProfile, "User_Bandwidth1")
+		assert.Equal(t, entry.UniTagList[0].TechnologyProfileID, 64)
+		assert.Equal(t, entry.UniTagList[0].IsDhcpRequired, true)
+		assert.Equal(t, entry.UniTagList[0].IsIgmpRequired, true)
+	}
+}
+
+func TestSadisServer_ServeStaticConfig(t *testing.T) {
+	olt, onu := createMockDevices()
+	common.Config = &common.GlobalConfig{
+		Olt: common.OltConfig{
+			ID:          olt.ID,
+			PonPorts:    1,
+			OnusPonPort: 1,
+			DeviceId:    net.HardwareAddr{0xA, 0xA, 0xA, 0xA, 0xA, byte(olt.ID)}.String(),
+		},
+	}
+
+	s := &SadisServer{
+		Olt: olt,
+	}
+
+	// Need to create a router that we can pass the request through so that the vars will be added to the context
+	rr := httptest.NewRecorder()
+	router := mux.NewRouter()
+	router.HandleFunc(StaticConfigUrl, s.ServeStaticConfig)
+
+	// check that v2 returns the expected result
+	req, err := http.NewRequest("GET", "/v2/static", nil)
+	if err != nil {
+		t.Fatal(err)
+	}
+	router.ServeHTTP(rr, req)
+
+	if status := rr.Code; status != http.StatusOK {
+		t.Errorf("handler returned wrong status code: got %v want %v",
+			status, http.StatusOK)
+	}
+
+	cfg := SadisConfig{}
+	if err := json.Unmarshal(rr.Body.Bytes(), &cfg); err != nil {
+		t.Fatal(err.Error())
+	}
+
+	assert.Equal(t, len(cfg.Sadis.Entries), 3) // 2 UNI and 1 OLT
+
+	// OLT
+	oltEntry := cfg.Sadis.Entries[0].(map[string]interface{})
+	assert.Equal(t, oltEntry["hardwareIdentifier"], common.Config.Olt.DeviceId)
+
+	// UNIs
+	for i, u := range onu.UniPorts {
+		uni := u.(*devices.UniPort)
+		uniEntry := cfg.Sadis.Entries[i+1].(map[string]interface{})
+		assert.Equal(t, uniEntry["id"], fmt.Sprintf("%s-%d", onu.Sn(), uni.ID+1))
+	}
 }
 
 func TestSadisServer_GetOnuEntryV2_multi_service(t *testing.T) {
 
-	mac := net.HardwareAddr{0x2e, 0x60, byte(1), byte(1), byte(1), byte(2)}
+	mac := net.HardwareAddr{0x2e, byte(1), byte(1), byte(1), byte(1), byte(2)}
 
-	hsia := devices.Service{Name: "hsia", HwAddress: net.HardwareAddr{0x2e, 0x60, byte(1), byte(1), byte(1), byte(1)},
+	hsia := devices.Service{Name: "hsia", HwAddress: net.HardwareAddr{0x2e, byte(1), byte(1), byte(1), byte(1), byte(1)},
 		CTag: 900, STag: 900, TechnologyProfileID: 64}
 
 	voip := devices.Service{Name: "voip", HwAddress: mac,
 		CTag: 901, STag: 900, TechnologyProfileID: 65}
 
-	vod := devices.Service{Name: "vod", HwAddress: net.HardwareAddr{0x2e, 0x60, byte(1), byte(1), byte(1), byte(3)},
+	vod := devices.Service{Name: "vod", HwAddress: net.HardwareAddr{0x2e, byte(1), byte(1), byte(1), byte(1), byte(3)},
 		CTag: 902, STag: 900, TechnologyProfileID: 66}
 
 	olt, onu := createMockDevices()
 
-	onu.Services = []devices.ServiceIf{&hsia, &voip, &vod}
+	onu.UniPorts[0].(*devices.UniPort).Services = []devices.ServiceIf{&hsia, &voip, &vod}
 
 	uni := "1"