Unverified Commit 9fb94f47 authored by Kevin Di Lallo's avatar Kevin Di Lallo Committed by GitHub
Browse files

Merge pull request #189 from pastorsx/sp_dev_meas_rep_ue

RNIS Meas Rep UE and Nr Meas Rep Ue subscriptions/notifications
parents c1c69694 fa433e75
Loading
Loading
Loading
Loading
+92 −24
Original line number Diff line number Diff line
@@ -31,7 +31,9 @@ const moduleName string = "meep-rnis-sbi"
type SbiCfg struct {
	SandboxName    string
	RedisAddr      string
	UeDataCb       func(string, string, string, string, bool)
	UeDataCb       func(string, string, string, string, string, bool)
	MeasInfoCb     func(string, string, []string, []int32, []int32)
	PoaInfoCb      func(string, string, string, string, string)
	AppEcgiInfoCb  func(string, string, string, string)
	DomainDataCb   func(string, string, string, string)
	ScenarioNameCb func(string)
@@ -45,7 +47,9 @@ type RnisSbi struct {
	activeModel          *mod.Model
	gisCache             *gc.GisCache
	refreshTicker        *time.Ticker
	updateUeDataCB       func(string, string, string, string, bool)
	updateUeDataCB       func(string, string, string, string, string, bool)
	updateMeasInfoCB     func(string, string, []string, []int32, []int32)
	updatePoaInfoCB      func(string, string, string, string, string)
	updateAppEcgiInfoCB  func(string, string, string, string)
	updateDomainDataCB   func(string, string, string, string)
	updateScenarioNameCB func(string)
@@ -64,6 +68,8 @@ func Init(cfg SbiCfg) (err error) {
	sbi = new(RnisSbi)
	sbi.sandboxName = cfg.SandboxName
	sbi.updateUeDataCB = cfg.UeDataCb
	sbi.updateMeasInfoCB = cfg.MeasInfoCb
	sbi.updatePoaInfoCB = cfg.PoaInfoCb
	sbi.updateAppEcgiInfoCB = cfg.AppEcgiInfoCb
	sbi.updateDomainDataCB = cfg.DomainDataCb
	sbi.updateScenarioNameCB = cfg.ScenarioNameCb
@@ -234,6 +240,7 @@ func processActiveScenarioUpdate() {
					mnc := ""
					mcc := ""
					cellId := ""
					nrcellId := ""
					erabIdValid := false
					if domain.CellularDomainConfig != nil {
						mnc = domain.CellularDomainConfig.Mnc
@@ -242,26 +249,28 @@ func processActiveScenarioUpdate() {
					}
					switch poa.Type_ {
					case mod.NodeTypePoa4G:
						//using the default cellId if no poa4GConfig is set
						if poa.Poa4GConfig != nil {
							if poa.Poa4GConfig.CellId != "" {
								cellId = poa.Poa4GConfig.CellId
							}
						}
						erabIdValid = true
					/*no support for RNIS on 5G elements anymore
					/*no support for RNIS on 5G elements anymore, but need the info for meas_rep_ue*/
					case mod.NodeTypePoa5G:
						//clearing the cellId filled by the domain since it does not apply to 5G elements
						cellId = ""
						if poa.Poa5GConfig != nil {
							if poa.Poa5GConfig.CellId != "" {
								cellId = poa.Poa5GConfig.CellId
								nrcellId = poa.Poa5GConfig.CellId
							}
						}
					*/
					default:
						//empty cells for POAs not supporting RNIS
						cellId = ""
					}

					sbi.updateUeDataCB(name, mnc, mcc, cellId, erabIdValid)
					sbi.updateUeDataCB(name, mnc, mcc, cellId, nrcellId, erabIdValid)
				}
			}
		}
@@ -277,7 +286,7 @@ func processActiveScenarioUpdate() {
			}
		}
		if !found {
			sbi.updateUeDataCB(prevUeName, "", "", "", false)
			sbi.updateUeDataCB(prevUeName, "", "", "", "", false)
			log.Info("Ue removed : ", prevUeName)
		}
	}
@@ -355,26 +364,85 @@ func processActiveScenarioUpdate() {
			log.Info("App removed : ", prevApp)
		}
	}

	// Update POA Cellular and Wifi info
	poaNameList := sbi.activeModel.GetNodeNames(mod.NodeTypePoa4G, mod.NodeTypePoa5G, mod.NodeTypePoaWifi, mod.NodeTypePoa)
	for _, name := range poaNameList {
		node := sbi.activeModel.GetNode(name)
		if node != nil {
			nl := node.(*dataModel.NetworkLocation)

			mnc := ""
			mcc := ""
			cellId := ""

			switch nl.Type_ {
			case mod.NodeTypePoa4G, mod.NodeTypePoa5G:
				poaParent := sbi.activeModel.GetNodeParent(name)
				if zone, ok := poaParent.(*dataModel.Zone); ok {
					zoneParent := sbi.activeModel.GetNodeParent(zone.Name)
					if domain, ok := zoneParent.(*dataModel.Domain); ok {
						if domain.CellularDomainConfig != nil {
							mnc = domain.CellularDomainConfig.Mnc
							mcc = domain.CellularDomainConfig.Mcc
							cellId = domain.CellularDomainConfig.DefaultCellId
						}
					}
				}
				if nl.Poa4GConfig != nil {
					cellId = nl.Poa4GConfig.CellId
				} else if nl.Poa5GConfig != nil {
					cellId = nl.Poa5GConfig.CellId
				}

				sbi.updatePoaInfoCB(name, nl.Type_, mnc, mcc, cellId)
			}
		}
	}
}

func refreshMeasurements() {
	// // Update UE measurements
	// ueMeasMap, _ := sbi.gisCache.GetAllMeasurements()
	// ueNameList := sbi.activeModel.GetNodeNames("UE")
	// for _, name := range ueNameList {
	// 	// Ignore disconnected UEs
	// 	if !isUeConnected(name) {
	// 		continue
	// 	}

	// 	// TODO - Update RSRP & RSRQ in RNIS
	// 	if ueMeas, found := ueMeasMap[name]; found {
	// 		log.Debug("UE Measurements for ", name, ":")
	// 		for poaName, meas := range ueMeas.Measurements {
	// 			log.Debug("  ", poaName, ": ", fmt.Sprintf("%+v", *meas))
	// 		}
	// 	}
	// }
	// Update UE measurements
	ueMeasMap, _ := sbi.gisCache.GetAllMeasurements()
	ueNameList := sbi.activeModel.GetNodeNames("UE")
	for _, name := range ueNameList {
		// Ignore disconnected UEs
		if !isUeConnected(name) {
			sbi.updateMeasInfoCB(name, "", nil, nil, nil)
			continue
		}

		ueParent := sbi.activeModel.GetNodeParent(name)
		if poa, ok := ueParent.(*dataModel.NetworkLocation); ok {
			poaNames, rsrps, rsrqs := getMeas(name, "", ueMeasMap)
			sbi.updateMeasInfoCB(name, poa.Name, poaNames, rsrps, rsrqs)
		} else {
			sbi.updateMeasInfoCB(name, "", nil, nil, nil)
		}
	}
}

func getMeas(ue string, poaName string, ueMeasMap map[string]*gc.UeMeasurement) ([]string, []int32, []int32) {
	var poaNames []string
	var rsrps []int32
	var rsrqs []int32

	if ueMeas, ueFound := ueMeasMap[ue]; ueFound {
		if poaName == "" {
			for poaName, meas := range ueMeas.Measurements {
				poaNames = append(poaNames, poaName)
				rsrps = append(rsrps, int32(meas.Rsrp))
				rsrqs = append(rsrqs, int32(meas.Rsrq))
			}
		} else {
			if meas, poaFound := ueMeas.Measurements[poaName]; poaFound {
				poaNames = append(poaNames, poaName)
				rsrps = append(rsrps, int32(meas.Rsrp))
				rsrqs = append(rsrqs, int32(meas.Rsrq))
			}
		}
	}
	return poaNames, rsrps, rsrqs
}

func isUeConnected(name string) bool {
+66 −0
Original line number Diff line number Diff line
@@ -44,6 +44,28 @@ func convertEcgiToJson(obj *Ecgi) string {
	return string(jsonInfo)
}

func convertJsonToPoaInfo(jsonInfo string) *PoaInfo {

	var obj PoaInfo
	err := json.Unmarshal([]byte(jsonInfo), &obj)
	if err != nil {
		log.Error(err.Error())
		return nil
	}
	return &obj
}

func convertPoaInfoToJson(obj *PoaInfo) string {

	jsonInfo, err := json.Marshal(*obj)
	if err != nil {
		log.Error(err.Error())
		return ""
	}

	return string(jsonInfo)
}

func convertJsonToUeData(jsonData string) *UeData {

	var obj UeData
@@ -176,3 +198,47 @@ func convertRabRelSubscriptionToJson(obj *RabRelSubscription) string {

	return string(jsonInfo)
}

func convertJsonToMeasRepUeSubscription(jsonInfo string) *MeasRepUeSubscription {

	var obj MeasRepUeSubscription
	err := json.Unmarshal([]byte(jsonInfo), &obj)
	if err != nil {
		log.Error(err.Error())
		return nil
	}
	return &obj
}

func convertMeasRepUeSubscriptionToJson(obj *MeasRepUeSubscription) string {

	jsonInfo, err := json.Marshal(*obj)
	if err != nil {
		log.Error(err.Error())
		return ""
	}

	return string(jsonInfo)
}

func convertJsonToNrMeasRepUeSubscription(jsonInfo string) *NrMeasRepUeSubscription {

	var obj NrMeasRepUeSubscription
	err := json.Unmarshal([]byte(jsonInfo), &obj)
	if err != nil {
		log.Error(err.Error())
		return nil
	}
	return &obj
}

func convertNrMeasRepUeSubscriptionToJson(obj *NrMeasRepUeSubscription) string {

	jsonInfo, err := json.Marshal(*obj)
	if err != nil {
		log.Error(err.Error())
		return ""
	}

	return string(jsonInfo)
}
+941 −44

File changed.

Preview size limit exceeded, changes collapsed.

+534 −3
Original line number Diff line number Diff line
@@ -680,6 +680,120 @@ func TestFailSubscriptionRabRel(t *testing.T) {
	terminateScenario()
}

func TestSuccessSubscriptionMeasRepUe(t *testing.T) {
	fmt.Println("--- ", t.Name())
	log.MeepTextLogInit(t.Name())

	initializeVars()
	err := Init()
	if err != nil {
		t.Fatalf("Error initializing test basic procedure")
	}
	err = Run()
	if err != nil {
		t.Fatalf("Error running test basic procedure")
	}
	fmt.Println("Set a scenario")
	initialiseScenario(testScenario)
	//post
	expectedGetResp := testSubscriptionMeasRepUePost(t)
	//get
	testSubscriptionGet(t, strconv.Itoa(nextSubscriptionIdAvailable-1), expectedGetResp)
	//put
	expectedGetResp = testSubscriptionMeasRepUePut(t, strconv.Itoa(nextSubscriptionIdAvailable-1), true)
	//get
	testSubscriptionGet(t, strconv.Itoa(nextSubscriptionIdAvailable-1), expectedGetResp)
	//delete
	testSubscriptionDelete(t, strconv.Itoa(nextSubscriptionIdAvailable-1), true)
	terminateScenario()
}

func TestFailSubscriptionMeasRepUe(t *testing.T) {
	fmt.Println("--- ", t.Name())
	log.MeepTextLogInit(t.Name())

	initializeVars()

	err := Init()
	if err != nil {
		t.Fatalf("Error initializing test basic procedure")
	}
	err = Run()
	if err != nil {
		t.Fatalf("Error running test basic procedure")
	}

	fmt.Println("Set a scenario")
	initialiseScenario(testScenario)

	//get
	testSubscriptionGet(t, strconv.Itoa(nextSubscriptionIdAvailable), "")

	//put
	_ = testSubscriptionMeasRepUePut(t, strconv.Itoa(nextSubscriptionIdAvailable), false)

	//delete
	testSubscriptionDelete(t, strconv.Itoa(nextSubscriptionIdAvailable), false)
	terminateScenario()
}

func TestSuccessSubscriptionNrMeasRepUe(t *testing.T) {
	fmt.Println("--- ", t.Name())
	log.MeepTextLogInit(t.Name())

	initializeVars()
	err := Init()
	if err != nil {
		t.Fatalf("Error initializing test basic procedure")
	}
	err = Run()
	if err != nil {
		t.Fatalf("Error running test basic procedure")
	}
	fmt.Println("Set a scenario")
	initialiseScenario(testScenario)
	//post
	expectedGetResp := testSubscriptionNrMeasRepUePost(t)
	//get
	testSubscriptionGet(t, strconv.Itoa(nextSubscriptionIdAvailable-1), expectedGetResp)
	//put
	expectedGetResp = testSubscriptionNrMeasRepUePut(t, strconv.Itoa(nextSubscriptionIdAvailable-1), true)
	//get
	testSubscriptionGet(t, strconv.Itoa(nextSubscriptionIdAvailable-1), expectedGetResp)
	//delete
	testSubscriptionDelete(t, strconv.Itoa(nextSubscriptionIdAvailable-1), true)
	terminateScenario()
}

func TestFailSubscriptionNrMeasRepUe(t *testing.T) {
	fmt.Println("--- ", t.Name())
	log.MeepTextLogInit(t.Name())

	initializeVars()

	err := Init()
	if err != nil {
		t.Fatalf("Error initializing test basic procedure")
	}
	err = Run()
	if err != nil {
		t.Fatalf("Error running test basic procedure")
	}

	fmt.Println("Set a scenario")
	initialiseScenario(testScenario)

	//get
	testSubscriptionGet(t, strconv.Itoa(nextSubscriptionIdAvailable), "")

	//put
	_ = testSubscriptionNrMeasRepUePut(t, strconv.Itoa(nextSubscriptionIdAvailable), false)

	//delete
	testSubscriptionDelete(t, strconv.Itoa(nextSubscriptionIdAvailable), false)
	terminateScenario()
}

func TestSubscriptionsListGet(t *testing.T) {
	fmt.Println("--- ", t.Name())
	log.MeepTextLogInit(t.Name())
@@ -705,11 +819,19 @@ func TestSubscriptionsListGet(t *testing.T) {
	_ = testSubscriptionRabEstPost(t)
	_ = testSubscriptionRabRelPost(t)
	_ = testSubscriptionRabRelPost(t)
	_ = testSubscriptionMeasRepUePost(t)
	_ = testSubscriptionMeasRepUePost(t)
	_ = testSubscriptionNrMeasRepUePost(t)
	_ = testSubscriptionNrMeasRepUePost(t)

	//get list
	testSubscriptionListGet(t)

	//delete
	testSubscriptionDelete(t, strconv.Itoa(nextSubscriptionIdAvailable-10), true)
	testSubscriptionDelete(t, strconv.Itoa(nextSubscriptionIdAvailable-9), true)
	testSubscriptionDelete(t, strconv.Itoa(nextSubscriptionIdAvailable-8), true)
	testSubscriptionDelete(t, strconv.Itoa(nextSubscriptionIdAvailable-7), true)
	testSubscriptionDelete(t, strconv.Itoa(nextSubscriptionIdAvailable-6), true)
	testSubscriptionDelete(t, strconv.Itoa(nextSubscriptionIdAvailable-5), true)
	testSubscriptionDelete(t, strconv.Itoa(nextSubscriptionIdAvailable-4), true)
@@ -724,7 +846,7 @@ func testSubscriptionListGet(t *testing.T) {
	/******************************
	 * expected response section
	 ******************************/
	expectedSubscriptionNb := 6
	expectedSubscriptionNb := 10

	/******************************
	 * request vars section
@@ -1219,6 +1341,262 @@ func testSubscriptionRabRelPut(t *testing.T, subscriptionId string, expectSucces
	}
}

func testSubscriptionMeasRepUePost(t *testing.T) string {

	/******************************
	 * expected response section
	 ******************************/
	expectedEcgi1 := Ecgi{"1234567", &Plmn{"111", "222"}}
	expectedEcgi := []Ecgi{expectedEcgi1}
	expectedAssocId1 := AssociateId{1, "2.2.2.2"}
	expectedAssocId := []AssociateId{expectedAssocId1}
	expectedFilter := MeasRepUeSubscriptionFilterCriteriaAssocTri{"myApp", expectedAssocId, expectedEcgi, []Trigger{1}}
	expectedCallBackRef := "myCallbakRef"
	expectedLinkType := LinkType{"/" + testScenarioName + "/rni/v2/subscriptions/" + strconv.Itoa(nextSubscriptionIdAvailable)}
	//expectedExpiry := TimeStamp{0, 1988599770}
	expectedResponse := MeasRepUeSubscription{&CaReconfSubscriptionLinks{&expectedLinkType}, expectedCallBackRef, nil, &expectedFilter, MEAS_REP_UE_SUBSCRIPTION}

	expectedResponseStr, err := json.Marshal(expectedResponse)
	if err != nil {
		t.Fatalf(err.Error())
	}

	/******************************
	 * request vars section
	 ******************************/

	/******************************
	 * request body section
	 ******************************/

	//filter is not exactly the same in response and request
	subscriptionPost1 := MeasRepUeSubscription{nil, expectedCallBackRef, nil, &expectedFilter, MEAS_REP_UE_SUBSCRIPTION}

	body, err := json.Marshal(subscriptionPost1)
	if err != nil {
		t.Fatalf(err.Error())
	}

	/******************************
	 * request queries section
	 ******************************/

	/******************************
	 * request execution section
	 ******************************/

	mr, err := sendRequest(http.MethodPost, "/subscriptions", bytes.NewBuffer(body), nil, nil, http.StatusCreated, SubscriptionsPOST)
	if err != nil {
		t.Fatalf("Failed to get expected response")
	}

	var respBody MeasRepUeSubscription
	err = json.Unmarshal([]byte(mr), &respBody)
	if err != nil {
		t.Fatalf("Failed to get expected response")
	}
	if mr != string(expectedResponseStr) {
		t.Fatalf("Failed to get expected response")
	}
	return string(expectedResponseStr)
}

func testSubscriptionMeasRepUePut(t *testing.T, subscriptionId string, expectSuccess bool) string {

	/******************************
	 * expected response section
	 ******************************/
	expectedEcgi1 := Ecgi{"1234567", &Plmn{"111", "222"}}
	expectedEcgi := []Ecgi{expectedEcgi1}
	expectedAssocId1 := AssociateId{1, "2.2.2.2"}
	expectedAssocId := []AssociateId{expectedAssocId1}
	expectedFilter := MeasRepUeSubscriptionFilterCriteriaAssocTri{"myApp", expectedAssocId, expectedEcgi, []Trigger{1}}
	expectedCallBackRef := "myCallbakRef"
	expectedLinkType := LinkType{"/" + testScenarioName + "/rni/v2/subscriptions/" + subscriptionId}
	expectedResponse := MeasRepUeSubscription{&CaReconfSubscriptionLinks{&expectedLinkType}, expectedCallBackRef, nil, &expectedFilter, MEAS_REP_UE_SUBSCRIPTION}

	expectedResponseStr, err := json.Marshal(expectedResponse)
	if err != nil {
		t.Fatalf(err.Error())
	}

	/******************************
	 * request vars section
	 ******************************/
	vars := make(map[string]string)
	vars["subscriptionId"] = subscriptionId

	/******************************
	 * request body section
	 ******************************/

	subscription1 := MeasRepUeSubscription{&CaReconfSubscriptionLinks{&expectedLinkType}, expectedCallBackRef, nil, &expectedFilter, MEAS_REP_UE_SUBSCRIPTION}

	body, err := json.Marshal(subscription1)
	if err != nil {
		t.Fatalf(err.Error())
	}

	/******************************
	 * request queries section
	 ******************************/

	/******************************
	 * request execution section
	 ******************************/

	if expectSuccess {
		mr, err := sendRequest(http.MethodPost, "/subscriptions", bytes.NewBuffer(body), vars, nil, http.StatusOK, SubscriptionsPUT)
		if err != nil {
			t.Fatalf("Failed to get expected response")
		}

		var respBody MeasRepUeSubscription
		err = json.Unmarshal([]byte(mr), &respBody)
		if err != nil {
			t.Fatalf("Failed to get expected response")
		}
		if mr != string(expectedResponseStr) {
			t.Fatalf("Failed to get expected response")
		}
		return string(expectedResponseStr)
	} else {
		_, err = sendRequest(http.MethodPost, "/subscriptions", bytes.NewBuffer(body), vars, nil, http.StatusNotFound, SubscriptionsPUT)
		if err != nil {
			t.Fatalf("Failed to get expected response")
		}
		return ""
	}
}

func testSubscriptionNrMeasRepUePost(t *testing.T) string {

	/******************************
	 * expected response section
	 ******************************/
	expectedNrcgi1 := NRcgi{"1234567", &Plmn{"111", "222"}}
	expectedNrcgi := []NRcgi{expectedNrcgi1}
	expectedAssocId1 := AssociateId{1, "2.2.2.2"}
	expectedAssocId := []AssociateId{expectedAssocId1}
	expectedFilter := NrMeasRepUeSubscriptionFilterCriteriaNrMrs{"myApp", expectedAssocId, expectedNrcgi, []TriggerNr{1}}
	expectedCallBackRef := "myCallbakRef"
	expectedLinkType := LinkType{"/" + testScenarioName + "/rni/v2/subscriptions/" + strconv.Itoa(nextSubscriptionIdAvailable)}
	//expectedExpiry := TimeStamp{0, 1988599770}
	expectedResponse := NrMeasRepUeSubscription{&CaReconfSubscriptionLinks{&expectedLinkType}, expectedCallBackRef, nil, &expectedFilter, NR_MEAS_REP_UE_SUBSCRIPTION}

	expectedResponseStr, err := json.Marshal(expectedResponse)
	if err != nil {
		t.Fatalf(err.Error())
	}

	/******************************
	 * request vars section
	 ******************************/

	/******************************
	 * request body section
	 ******************************/

	//filter is not exactly the same in response and request
	subscriptionPost1 := NrMeasRepUeSubscription{nil, expectedCallBackRef, nil, &expectedFilter, NR_MEAS_REP_UE_SUBSCRIPTION}

	body, err := json.Marshal(subscriptionPost1)
	if err != nil {
		t.Fatalf(err.Error())
	}

	/******************************
	 * request queries section
	 ******************************/

	/******************************
	 * request execution section
	 ******************************/

	nrMr, err := sendRequest(http.MethodPost, "/subscriptions", bytes.NewBuffer(body), nil, nil, http.StatusCreated, SubscriptionsPOST)
	if err != nil {
		t.Fatalf("Failed to get expected response")
	}

	var respBody NrMeasRepUeSubscription
	err = json.Unmarshal([]byte(nrMr), &respBody)
	if err != nil {
		t.Fatalf("Failed to get expected response")
	}
	if nrMr != string(expectedResponseStr) {
		t.Fatalf("Failed to get expected response")
	}
	return string(expectedResponseStr)
}

func testSubscriptionNrMeasRepUePut(t *testing.T, subscriptionId string, expectSuccess bool) string {

	/******************************
	 * expected response section
	 ******************************/
	expectedNrcgi1 := NRcgi{"1234567", &Plmn{"111", "222"}}
	expectedNrcgi := []NRcgi{expectedNrcgi1}
	expectedAssocId1 := AssociateId{1, "2.2.2.2"}
	expectedAssocId := []AssociateId{expectedAssocId1}
	expectedFilter := NrMeasRepUeSubscriptionFilterCriteriaNrMrs{"myApp", expectedAssocId, expectedNrcgi, []TriggerNr{1}}
	expectedCallBackRef := "myCallbakRef"
	expectedLinkType := LinkType{"/" + testScenarioName + "/rni/v2/subscriptions/" + subscriptionId}
	expectedResponse := NrMeasRepUeSubscription{&CaReconfSubscriptionLinks{&expectedLinkType}, expectedCallBackRef, nil, &expectedFilter, NR_MEAS_REP_UE_SUBSCRIPTION}

	expectedResponseStr, err := json.Marshal(expectedResponse)
	if err != nil {
		t.Fatalf(err.Error())
	}

	/******************************
	 * request vars section
	 ******************************/
	vars := make(map[string]string)
	vars["subscriptionId"] = subscriptionId

	/******************************
	 * request body section
	 ******************************/

	subscription1 := NrMeasRepUeSubscription{&CaReconfSubscriptionLinks{&expectedLinkType}, expectedCallBackRef, nil, &expectedFilter, NR_MEAS_REP_UE_SUBSCRIPTION}

	body, err := json.Marshal(subscription1)
	if err != nil {
		t.Fatalf(err.Error())
	}

	/******************************
	 * request queries section
	 ******************************/

	/******************************
	 * request execution section
	 ******************************/

	if expectSuccess {
		nrMr, err := sendRequest(http.MethodPost, "/subscriptions", bytes.NewBuffer(body), vars, nil, http.StatusOK, SubscriptionsPUT)
		if err != nil {
			t.Fatalf("Failed to get expected response")
		}

		var respBody MeasRepUeSubscription
		err = json.Unmarshal([]byte(nrMr), &respBody)
		if err != nil {
			t.Fatalf("Failed to get expected response")
		}
		if nrMr != string(expectedResponseStr) {
			t.Fatalf("Failed to get expected response")
		}
		return string(expectedResponseStr)
	} else {
		_, err = sendRequest(http.MethodPost, "/subscriptions", bytes.NewBuffer(body), vars, nil, http.StatusNotFound, SubscriptionsPUT)
		if err != nil {
			t.Fatalf("Failed to get expected response")
		}
		return ""
	}
}

func TestSubscriptionCellChangeNotification(t *testing.T) {

	fmt.Println("--- ", t.Name())
@@ -1651,6 +2029,131 @@ func TestSubscriptionRabRelNotification(t *testing.T) {

}

func TestSubscriptionMeasRepUeNotification(t *testing.T) {

	fmt.Println("--- ", t.Name())
	log.MeepTextLogInit(t.Name())

	initializeVars()

	err := Init()
	if err != nil {
		t.Fatalf("Error initializing test basic procedure")
	}
	err = Run()
	if err != nil {
		t.Fatalf("Error running test basic procedure")
	}

	fmt.Println("Set a scenario")
	initialiseScenario(testScenario)

	//******************************
	// * expected response section
	// ****************************** /
	expectedPlmnInNotif := Plmn{Mcc: "123", Mnc: "456"}
	expectedCellId := "2345678"
	expectedEcgi := Ecgi{Plmn: &expectedPlmnInNotif, CellId: expectedCellId}
	movingUeAddr := "ue1" //based on the scenario change
	expectedAssocIdInNotif1 := AssociateId{Type_: 1, Value: movingUeAddr}
	expectedAssocIdInNotif := []AssociateId{expectedAssocIdInNotif1}
	expectedTrigger := []Trigger{1}
	expectedFilter := MeasRepUeSubscriptionFilterCriteriaAssocTri{Trigger: expectedTrigger}
	expectedCallBackRef := "myCallbakRef"
	//expectedExpiry := TimeStamp{0, 1988599770}

	//******************************
	// * request vars section
	// ****************************** /

	//******************************
	// * request body section
	// ****************************** /

	measRepUeSubscriptionPost1 := MeasRepUeSubscription{nil, expectedCallBackRef, nil, &expectedFilter, MEAS_REP_UE_SUBSCRIPTION}

	body, err := json.Marshal(measRepUeSubscriptionPost1)
	if err != nil {
		t.Fatalf(err.Error())
	}

	//******************************
	// * request queries section
	// ****************************** /

	//******************************
	// * request execution section
	// ****************************** /

	_, err = sendRequest(http.MethodPost, "/subscriptions", bytes.NewBuffer(body), nil, nil, http.StatusCreated, SubscriptionsPOST)
	if err != nil {
		t.Fatalf("Failed to get expected response")
	}

	//	updateScenario("mobility1")
	time.Sleep(100 * time.Millisecond)
	//	updateScenario("mobility2")

	metricStore, err := ms.NewMetricStore(currentStoreName, sandboxName, influxTestAddr, redisTestAddr)
	if err != nil {
		t.Fatalf("Failed to create a store")
	}

	httpLog, err := metricStore.GetHttpMetric(logModuleRNIS, "TX", "", 1)
	if err != nil || len(httpLog) != 1 {
		t.Fatalf("Failed to get metric")
	}

	var notification MeasRepUeNotification
	err = json.Unmarshal([]byte(httpLog[0].Body), &notification)
	if err != nil {
		t.Fatalf("Failed to get expected response")
	}

	//transform the assocId in string for comparison purpose
	jsonResult, err := json.Marshal(notification.AssociateId)
	if err != nil {
		t.Fatalf(err.Error())
	}
	notificationAssocIdStr := string(jsonResult)

	//transform the ecgi in string for comparison purpose
	jsonResult, err = json.Marshal(notification.Ecgi)
	if err != nil {
		t.Fatalf(err.Error())
	}
	notificationEcgiStr := string(jsonResult)

	jsonResult, err = json.Marshal(expectedAssocIdInNotif)
	if err != nil {
		t.Fatalf(err.Error())
	}
	expectedAssocIdStr := string(jsonResult)

	jsonResult, err = json.Marshal(expectedEcgi)
	if err != nil {
		t.Fatalf(err.Error())
	}
	expectedEcgiStr := string(jsonResult)

	//only check for ecgi, erabId, erabQosParameters and assocId, other values are dynamic such as the timestamp
	if (notificationEcgiStr != expectedEcgiStr) ||
		notification.Rsrp != 0 ||
		notification.Rsrq != 0 ||
		(notificationAssocIdStr != expectedAssocIdStr) {
		t.Fatalf("Failed to get expected response")
	}

	//cleanup allocated subscription
	testSubscriptionDelete(t, strconv.Itoa(nextSubscriptionIdAvailable-1), true)

	//******************************
	// * back to initial state section
	// ****************************** /
	terminateScenario()

}

func TestSbi(t *testing.T) {

	fmt.Println("--- ", t.Name())
@@ -1669,20 +2172,26 @@ func TestSbi(t *testing.T) {

	ueName := "ue1"
	appName := "zone1-edge1-iperf"
	poaName := "zone1-poa-cell1"

	/******************************
	 * expected values section
	 ******************************/
	var expectedUeDataStr [2]string
	var expectedUeData [2]UeData
	expectedUeData[INITIAL] = UeData{ueName, 1, &Ecgi{"2345678", &Plmn{"123", "456"}}, 80}
	expectedUeData[UPDATED] = UeData{ueName, -1, &Ecgi{"", &Plmn{"123", "456"}}, 80}
	expectedUeData[INITIAL] = UeData{ueName, 1, &Ecgi{"2345678", &Plmn{"123", "456"}}, &NRcgi{"", &Plmn{"123", "456"}}, 80, "", nil}
	expectedUeData[UPDATED] = UeData{ueName, -1, &Ecgi{"", &Plmn{"123", "456"}}, &NRcgi{"", &Plmn{"123", "456"}}, 80, "", nil}

	var expectedAppEcgiStr [2]string
	var expectedAppEcgi [2]Ecgi
	expectedAppEcgi[INITIAL] = Ecgi{"", &Plmn{"123", "456"}}
	expectedAppEcgi[UPDATED] = Ecgi{"", &Plmn{"123", "456"}}

	var expectedPoaInfoStr [2]string
	var expectedPoaInfo [2]PoaInfo
	expectedPoaInfo[INITIAL] = PoaInfo{"POA-4G", Ecgi{"2345678", &Plmn{"123", "456"}}, NRcgi{"", nil}}
	expectedPoaInfo[UPDATED] = PoaInfo{"POA-4G", Ecgi{"2345678", &Plmn{"123", "456"}}, NRcgi{"", nil}}

	j, err := json.Marshal(expectedUeData[INITIAL])
	if err != nil {
		t.Fatalf(err.Error())
@@ -1707,6 +2216,18 @@ func TestSbi(t *testing.T) {
	}
	expectedAppEcgiStr[UPDATED] = string(j)

	j, err = json.Marshal(expectedPoaInfo[INITIAL])
	if err != nil {
		t.Fatalf(err.Error())
	}
	expectedPoaInfoStr[INITIAL] = string(j)

	j, err = json.Marshal(expectedPoaInfo[UPDATED])
	if err != nil {
		t.Fatalf(err.Error())
	}
	expectedPoaInfoStr[UPDATED] = string(j)

	/******************************
	 * execution section
	 ******************************/
@@ -1724,6 +2245,11 @@ func TestSbi(t *testing.T) {
		t.Fatalf("Failed to get expected response")
	}

	jsonPoaInfo, _ := rc.JSONGetEntry(baseKey+"POA:"+poaName, ".")
	if string(jsonPoaInfo) != expectedPoaInfoStr[INITIAL] {
		t.Fatalf("Failed to get expected response")
	}

	updateScenario("mobility1")

	jsonEcgiInfo, _ = rc.JSONGetEntry(baseKey+"UE:"+ueName, ".")
@@ -1737,6 +2263,11 @@ func TestSbi(t *testing.T) {
		t.Fatalf("Failed to get expected response")
	}

	jsonPoaInfo, _ = rc.JSONGetEntry(baseKey+"POA:"+poaName, ".")
	if string(jsonPoaInfo) != expectedPoaInfoStr[UPDATED] {
		t.Fatalf("Failed to get expected response")
	}

	/******************************
	 * back to initial state section
	 ******************************/
+31 −0

File changed.

Preview size limit exceeded, changes collapsed.

Loading