Commit 97907908 authored by hammad zafar's avatar hammad zafar
Browse files

Merge branch 'STF625_MEC030' of https://forge.etsi.org/rep/mec/AdvantEDGE into STF625_MEC030

parents aab920d6 e045c247
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -815,6 +815,15 @@ func (tm *TrafficMgr) PopulateStaticPoaLoad(poaNameList []string) (err error) {

// Returns Predicted QoS in terms of RSRQ and RSRP values based on Traffic Load patterns
func (tm *TrafficMgr) PredictQosPerTrafficLoad(hour int32, inRsrp int32, inRsrq int32, poaName string) (outRsrp int32, outRsrq int32, err error) {
	// Validate input
	if hour > 24 {
		err = errors.New("Invalid hour value")
		return 0, 0, err
	}
	if poaName == "" {
		err = errors.New("Missing POA Name")
		return 0, 0, err
	}

	// Get time range for DB query
	timeRange := inTimeRange(hour)
@@ -827,7 +836,7 @@ func (tm *TrafficMgr) PredictQosPerTrafficLoad(hour int32, inRsrp int32, inRsrq
	log.Debug("Collecting traffic load pattern of POA " + poaName + " for the time range: " + timeRange)
	rows, err = tm.db.Query(`SELECT "`+timeRange+`" FROM `+TrafficTable+` WHERE poa_name = ($1)`, poaName)
	if err != nil {
		log.Error(err)
		return 0, 0, err
	}

	rows.Close()
+31 −14
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ const ( // FIXME To be update with correct values at the end
	fifteenToEighteen1     = 0
	eighteenToTwentyOne1   = 0
	twentyOneToTwentyFour1 = 0
	hour1                  = 133
	hour1                  = 13
	inRsrp1                = 10
	inRsrq1                = 10
)
@@ -285,34 +285,39 @@ func TestPredictQosPerTrafficLoad(t *testing.T) {
	}
	_ = tm.CreateCategoryLoad(category1, catData)
	_ = tm.CreatePoaLoad(poaName1, category1)
	fmt.Println("Tables initialized")

	// Invalid poaName
	_, _, err := tm.PredictQosPerTrafficLoad(14, 0, 0, "")
	if err == nil {
		t.Fatalf("Should have failed due to invalid poaName")
	}
	// Invalid hour
	_, _, err = tm.PredictQosPerTrafficLoad(25, 0, 0, poaName1)
	_, _, err := tm.PredictQosPerTrafficLoad(25, 0, 0, poaName1)
	if err == nil {
		t.Fatalf("Should have failed due to invalid hour")
	}
	// Invalid inRsrp
	_, _, err = tm.PredictQosPerTrafficLoad(25, -1, 0, poaName1)
	// Invalid poaName
	_, _, err = tm.PredictQosPerTrafficLoad(14, 0, 0, "")
	if err == nil {
		t.Fatalf("Should have failed due to invalid poaName")
	}
	// FIXME Are there any invalid Rsrp/Rsrq values?
	/*_, _, err = tm.PredictQosPerTrafficLoad(14, -1, 0, poaName1)
	if err == nil {
		t.Fatalf("Should have failed due to invalid inRsrp")
	}
	// Invalid inRsrq
	_, _, err = tm.PredictQosPerTrafficLoad(25, 0, -1, poaName1)
	_, _, err = tm.PredictQosPerTrafficLoad(14, 0, -1, poaName1)
	if err == nil {
		t.Fatalf("Should have failed due to invalid inRsrq")
	}
	}*/
	fmt.Println("Invalid checks done")

	// FIXME Execute the test with proper values for inRsrp1 and inRsrq1
	rsrp, rsrq, err := tm.PredictQosPerTrafficLoad(hour1, inRsrp1, inRsrq1, poaName1)
	if err != nil {
		t.Fatalf("Failed to delete all Traffic")
		t.Fatal("Failed to get predicted Qos per Traffic load:", err.Error())
	}
	// Validate
	if !validatePredictQosPerTrafficLoad(rsrp, rsrq, inRsrp1, inRsrq1) {
		t.Fatalf("Category validation failed")
	}
	fmt.Println("rsrp: ", rsrp)
	fmt.Println("rsrq: ", rsrq)

	// Delete all & validate updatespoaMap
	fmt.Println("Delete all & validate updates")
@@ -415,3 +420,15 @@ func validatePoaLoads(poaLoads *PoaLoads, poaName string, category string, zeroT

	return true
}

func validatePredictQosPerTrafficLoad(rsrp int32, rsrq int32, expectedRsrp int32, expectedRsrq int32) bool {
	if (rsrp != expectedRsrp) {
		fmt.Println("rsrp != expectedRsrp")
		return false
	}
	if (rsrq != expectedRsrq) {
		fmt.Println("rsrq != expectedRsrq")
		return false
	}
	return true
}