Commit 73fccfb5 authored by Simon Pastor's avatar Simon Pastor Committed by Kevin Di Lallo
Browse files

unit testing

parent df1f79d7
Loading
Loading
Loading
Loading
+2 −4
Original line number Diff line number Diff line
@@ -691,14 +691,14 @@ func applyNetCharFilterRules() {
			filterInfo.UniqueNumber = dstElementPtr.NextUniqueNumber
			filterInfo.LatencyCorrelation = COMMON_CORRELATION
			needUpdateFilter := false
			needCreate := false
			needCreate := true
			if dstElementPtr.FilterInfoList == nil {
				dstElementPtr.FilterInfoList = append(dstElementPtr.FilterInfoList, filterInfo)
				needCreate = true
			} else { //check to see if it exists
				index := 0
				for indx, storedFilterInfo := range dstElementPtr.FilterInfoList {
					if storedFilterInfo.SrcName == filterInfo.SrcName {
						needCreate = false
						//it has to be unique so check the other values
						if !(storedFilterInfo.PodName == filterInfo.PodName &&
							storedFilterInfo.SrcIp == filterInfo.SrcIp &&
@@ -718,8 +718,6 @@ func applyNetCharFilterRules() {
							index = indx
						}
						break
					} else {
						needCreate = true
					}
				}
				if needCreate {
+37 −18
Original line number Diff line number Diff line
@@ -152,10 +152,11 @@ func (algo *SegmentAlgorithm) ProcessScenario(model *mod.Model) error {
	if model.GetScenarioName() == "" {
		// Remove any existing metrics
		algo.deleteMetricsEntries()
		//reset the map
		algo.FlowMap = make(map[string]*SegAlgoFlow)
	}

	// Clear segment & flow maps
	algo.FlowMap = make(map[string]*SegAlgoFlow)
	algo.SegmentMap = make(map[string]*SegAlgoSegment)
	// Process active scenario
	procNames := model.GetNodeNames("CLOUD-APP")
@@ -257,19 +258,33 @@ func (algo *SegmentAlgorithm) CalculateNetChar() []FlowNetChar {

	// Prepare list of updated flows
	for _, flow := range algo.FlowMap {
		if (flow.MaxPlannedThroughput != flow.AllocatedThroughput && flow.MaxPlannedThroughput != MAX_THROUGHPUT) ||
			(flow.ComputedLatency != flow.AppliedNetChar.Latency) ||
			(flow.ComputedJitter != flow.AppliedNetChar.Jitter) ||
			(flow.ComputedPacketLoss != flow.AppliedNetChar.PacketLoss) {
			log.Info("Update allocated bandwidth for ", flow.Name, " to ", flow.MaxPlannedThroughput, "-", flow.ComputedLatency, "-", flow.ComputedJitter, "-", flow.ComputedPacketLoss)
		updateNeeded := false
		if flow.MaxPlannedThroughput != flow.AllocatedThroughput && flow.MaxPlannedThroughput != MAX_THROUGHPUT {
			if algo.Config.LogVerbose {
				log.Info("Update allocated bandwidth for ", flow.Name, " to ", flow.MaxPlannedThroughput, " from ", flow.AllocatedThroughput)
			}

			flow.AllocatedThroughput = flow.MaxPlannedThroughput
			flow.AllocatedThroughputLowerBound = flow.MaxPlannedLowerBound
			flow.AllocatedThroughputUpperBound = flow.MaxPlannedUpperBound
			flow.AppliedNetChar.Throughput = flow.AllocatedThroughput
			updateNeeded = true
		}

		if (flow.ComputedLatency != flow.AppliedNetChar.Latency) ||
			(flow.ComputedJitter != flow.AppliedNetChar.Jitter) ||
			(flow.ComputedPacketLoss != flow.AppliedNetChar.PacketLoss) {
			if algo.Config.LogVerbose {
				log.Info("Update other netchars for ", flow.Name, " to ", flow.ComputedLatency, "-", flow.ComputedJitter, "-", flow.ComputedPacketLoss, " from ", flow.AppliedNetChar.Latency, "-", flow.AppliedNetChar.Jitter, "-", flow.AppliedNetChar.PacketLoss)
			}

			flow.AppliedNetChar.Latency = flow.ComputedLatency
			flow.AppliedNetChar.Jitter = flow.ComputedJitter
			flow.AppliedNetChar.PacketLoss = flow.ComputedPacketLoss
			updateNeeded = true
		}

		if updateNeeded {
			netchar := NetChar{flow.AppliedNetChar.Latency, flow.AppliedNetChar.Jitter, flow.AppliedNetChar.PacketLoss, flow.AppliedNetChar.Throughput}
			flowNetChar := FlowNetChar{flow.SrcNetElem, flow.DstNetElem, netchar}
			updatedNetCharList = append(updatedNetCharList, flowNetChar)
@@ -449,7 +464,7 @@ func (algo *SegmentAlgorithm) createPath(flowName string, srcElement *SegAlgoNet
	}

	//zone ul, dl
	if srcElement.Type != "CLOUD" {
	if srcElement.Type != "DC" {
		direction = "uplink"
		segmentName = srcElement.ZoneName + direction
		segment = algo.createSegment(segmentName, flowName, srcElement.ZoneName, model)
@@ -457,7 +472,7 @@ func (algo *SegmentAlgorithm) createPath(flowName string, srcElement *SegAlgoNet

	}

	if destElement.Type != "CLOUD" {
	if destElement.Type != "DC" {
		direction = "downlink"
		segmentName = destElement.ZoneName + direction
		segment = algo.createSegment(segmentName, flowName, destElement.ZoneName, model)
@@ -471,7 +486,7 @@ func (algo *SegmentAlgorithm) createPath(flowName string, srcElement *SegAlgoNet
	}

	//domain ul, dl
	if srcElement.Type != "CLOUD" {
	if srcElement.Type != "DC" {
		direction = "uplink"
		segmentName = srcElement.DomainName + direction
		segment = algo.createSegment(segmentName, flowName, srcElement.DomainName, model)
@@ -479,7 +494,7 @@ func (algo *SegmentAlgorithm) createPath(flowName string, srcElement *SegAlgoNet

	}

	if destElement.Type != "CLOUD" {
	if destElement.Type != "DC" {
		direction = "downlink"
		segmentName = destElement.DomainName + direction
		segment = algo.createSegment(segmentName, flowName, destElement.DomainName, model)
@@ -493,7 +508,7 @@ func (algo *SegmentAlgorithm) createPath(flowName string, srcElement *SegAlgoNet
	}

	//cloud ul, dl
	if srcElement.Type == "CLOUD" {
	if srcElement.Type == "DC" {
		direction = "uplink"
		segmentName = model.GetScenarioName() + "-cloud-" + direction
		segment = algo.createSegment(segmentName, flowName, model.GetScenarioName(), model)
@@ -501,7 +516,7 @@ func (algo *SegmentAlgorithm) createPath(flowName string, srcElement *SegAlgoNet

	}

	if destElement.Type == "CLOUD" {
	if destElement.Type == "DC" {
		direction = "downlink"
		segmentName = model.GetScenarioName() + "-cloud-" + direction
		segment = algo.createSegment(segmentName, flowName, model.GetScenarioName(), model)
@@ -750,7 +765,7 @@ func (algo *SegmentAlgorithm) getMetricsThroughputEntryHandler(key string, field
	return nil
}

// reCalculateThroughputs -
// reCalculateNetChar -
func (algo *SegmentAlgorithm) reCalculateNetChar() {
	//reset every planned throughput values for every flow since they will start to populate those
	for _, flow := range algo.FlowMap {
@@ -930,11 +945,9 @@ func needToReevaluate(segment *SegAlgoSegment) (unusedBw float64, list []*SegAlg
			list = append(list, flow)
		} else {
			//no need to reevalute algo one, so removing its allocated bw from the available one
			if flow.CurrentThroughput >= segment.MinActivityThreshold {
				unusedBw -= flow.AllocatedThroughput
			}
		if flow.CurrentThroughput < segment.MinActivityThreshold {
			//we just re-add the bw for inactive connections
			unusedBw += flow.AllocatedThroughput
		}
	}
	return unusedBw, list
@@ -1080,3 +1093,9 @@ func printPath(path *SegAlgoPath) string {
	}
	return str
}

// printElement -
func printElement(elem *SegAlgoNetElem) string {
	str := elem.Name + "-" + elem.Type + "-" + elem.PhyLocName + "-" + elem.PoaName + "-" + elem.ZoneName + "-" + elem.DomainName
	return str
}
+36 −26
Original line number Diff line number Diff line
@@ -74,7 +74,8 @@ func TestSegAlgoSegmentation(t *testing.T) {
	if len(algo.FlowMap) != 90 {
		t.Errorf("Invalid Flow Map entry count")
	}
	if len(algo.SegmentMap) != 26 {

	if len(algo.SegmentMap) != 42 {
		t.Errorf("Invalid Segment Map entry count")
	}

@@ -88,7 +89,13 @@ func TestSegAlgoSegmentation(t *testing.T) {
	}

	// Validate algorithm Calculations
	fmt.Println("Test algo calculation without metrics")
	fmt.Println("Test algo calculation with some flows updated with metrics")
	updatedNetCharList = algo.CalculateNetChar()
	if len(updatedNetCharList) != 58 {
		t.Errorf("Updated net char list not partially filled")
	}

	fmt.Println("Test algo calculation without changes in metrics")
	updatedNetCharList = algo.CalculateNetChar()
	if len(updatedNetCharList) != 0 {
		t.Errorf("Updated net char list not empty")
@@ -111,11 +118,11 @@ func TestSegAlgoSegmentation(t *testing.T) {
	if len(algo.FlowMap) != 90 {
		t.Errorf("Invalid Flow Map entry count")
	}
	if len(algo.SegmentMap) != 26 {
	if len(algo.SegmentMap) != 42 {
		t.Errorf("Invalid Segment Map entry count")
	}
	updatedNetCharList = algo.CalculateNetChar()
	if len(updatedNetCharList) != 0 {
	if len(updatedNetCharList) != 34 {
		t.Errorf("Updated net char list not empty")
	}

@@ -132,7 +139,7 @@ func TestSegAlgoSegmentation(t *testing.T) {
	if len(algo.FlowMap) != 90 {
		t.Errorf("Invalid Flow Map entry count")
	}
	if len(algo.SegmentMap) != 30 {
	if len(algo.SegmentMap) != 44 {
		t.Errorf("Invalid Segment Map entry count")
	}

@@ -147,7 +154,7 @@ func TestSegAlgoSegmentation(t *testing.T) {

	// Validate algorithm Calculations
	updatedNetCharList = algo.CalculateNetChar()
	if len(updatedNetCharList) != 0 {
	if len(updatedNetCharList) != 18 {
		t.Errorf("Updated net char list not empty")
	}

@@ -164,7 +171,7 @@ func TestSegAlgoSegmentation(t *testing.T) {
	if len(algo.FlowMap) != 90 {
		t.Errorf("Invalid Flow Map entry count")
	}
	if len(algo.SegmentMap) != 26 {
	if len(algo.SegmentMap) != 42 {
		t.Errorf("Invalid Segment Map entry count")
	}

@@ -179,7 +186,7 @@ func TestSegAlgoSegmentation(t *testing.T) {

	// Validate algorithm Calculations
	updatedNetCharList = algo.CalculateNetChar()
	if len(updatedNetCharList) != 0 {
	if len(updatedNetCharList) != 18 {
		t.Errorf("Updated net char list not empty")
	}

@@ -244,8 +251,8 @@ func TestSegAlgoCalculation(t *testing.T) {
	// Validate algorithm Calculations
	fmt.Println("Test algorithm calculations with & without metrics")
	updatedNetCharList := algo.CalculateNetChar()
	if len(updatedNetCharList) != 0 {
		t.Errorf("Updated net char list not empty")
	if len(updatedNetCharList) != 58 {
		t.Errorf("Updated net char list not filled properly")
	}

	// Update metrics & recalculate
@@ -259,10 +266,10 @@ func TestSegAlgoCalculation(t *testing.T) {
	if len(updatedNetCharList) != 2 {
		t.Errorf("Invalid net char update list")
	}
	if !validateNetCharUpdate(updatedNetCharList, "zone1-fog1-iperf", "ue1-iperf", 0, 0, 0, 500) {
	if !validateNetCharUpdate(updatedNetCharList, "zone1-fog1-iperf", "ue1-iperf", 1, 1, 0, 500) {
		t.Errorf("Error in Net Char update")
	}
	if !validateNetCharUpdate(updatedNetCharList, "zone1-fog1-svc", "ue2-svc", 0, 0, 0, 500) {
	if !validateNetCharUpdate(updatedNetCharList, "zone1-fog1-svc", "ue2-svc", 1, 1, 0, 500) {
		t.Errorf("Error in Net Char update")
	}

@@ -271,6 +278,9 @@ func TestSegAlgoCalculation(t *testing.T) {
	var netCharUpdateEvent ceModel.EventNetworkCharacteristicsUpdate
	netCharUpdateEvent.ElementName = "zone1-poa1"
	netCharUpdateEvent.ElementType = "POA"
	netCharUpdateEvent.Latency = 1          // no change
	netCharUpdateEvent.LatencyVariation = 1 // no change
	netCharUpdateEvent.PacketLoss = 0       // no change
	netCharUpdateEvent.Throughput = 100
	err = activeModel.UpdateNetChar(&netCharUpdateEvent)
	if err != nil {
@@ -284,10 +294,10 @@ func TestSegAlgoCalculation(t *testing.T) {
	if len(updatedNetCharList) != 2 {
		t.Errorf("Invalid net char update list")
	}
	if !validateNetCharUpdate(updatedNetCharList, "zone1-fog1-iperf", "ue1-iperf", 0, 0, 0, 50) {
	if !validateNetCharUpdate(updatedNetCharList, "zone1-fog1-iperf", "ue1-iperf", 1, 1, 0, 50) {
		t.Errorf("Error in Net Char update")
	}
	if !validateNetCharUpdate(updatedNetCharList, "zone1-fog1-svc", "ue2-svc", 0, 0, 0, 50) {
	if !validateNetCharUpdate(updatedNetCharList, "zone1-fog1-svc", "ue2-svc", 1, 1, 0, 50) {
		t.Errorf("Error in Net Char update")
	}

@@ -325,16 +335,16 @@ func TestSegAlgoCalculation(t *testing.T) {
		t.Errorf("Error updating metrics")
	}
	updatedNetCharList = algo.CalculateNetChar()
	if len(updatedNetCharList) != 3 {
	if len(updatedNetCharList) != 15 {
		t.Errorf("Invalid net char update list")
	}
	if !validateNetCharUpdate(updatedNetCharList, "zone1-fog1-iperf", "ue1-iperf", 0, 0, 0, 10) {
	if !validateNetCharUpdate(updatedNetCharList, "zone1-fog1-iperf", "ue1-iperf", 41, 9, 0, 10) {
		t.Errorf("Error in Net Char update")
	}
	if !validateNetCharUpdate(updatedNetCharList, "zone2-edge1-iperf", "ue1-iperf", 0, 0, 0, 10) {
	if !validateNetCharUpdate(updatedNetCharList, "zone2-edge1-iperf", "ue1-iperf", 11, 3, 0, 10) {
		t.Errorf("Error in Net Char update")
	}
	if !validateNetCharUpdate(updatedNetCharList, "zone1-fog1-svc", "ue2-svc", 0, 0, 0, 100) {
	if !validateNetCharUpdate(updatedNetCharList, "zone1-fog1-svc", "ue2-svc", 1, 1, 0, 100) {
		t.Errorf("Error in Net Char update")
	}

@@ -352,10 +362,10 @@ func TestSegAlgoCalculation(t *testing.T) {
	if len(updatedNetCharList) != 2 {
		t.Errorf("Invalid net char update list")
	}
	if !validateNetCharUpdate(updatedNetCharList, "zone1-fog1-iperf", "ue1-iperf", 0, 0, 0, 6) {
	if !validateNetCharUpdate(updatedNetCharList, "zone1-fog1-iperf", "ue1-iperf", 41, 9, 0, 6) {
		t.Errorf("Error in Net Char update")
	}
	if !validateNetCharUpdate(updatedNetCharList, "zone2-edge1-iperf", "ue1-iperf", 0, 0, 0, 20) {
	if !validateNetCharUpdate(updatedNetCharList, "zone2-edge1-iperf", "ue1-iperf", 11, 3, 0, 20) {
		t.Errorf("Error in Net Char update")
	}

@@ -384,13 +394,13 @@ func TestSegAlgoCalculation(t *testing.T) {
		t.Errorf("Error updating metrics")
	}
	updatedNetCharList = algo.CalculateNetChar()
	if len(updatedNetCharList) != 2 {
	if len(updatedNetCharList) != 15 {
		t.Errorf("Invalid net char update list")
	}
	if !validateNetCharUpdate(updatedNetCharList, "zone2-edge1-iperf", "ue1-iperf", 0, 0, 0, 23) {
	if !validateNetCharUpdate(updatedNetCharList, "zone2-edge1-iperf", "ue1-iperf", 41, 9, 0, 23) {
		t.Errorf("Error in Net Char update")
	}
	if !validateNetCharUpdate(updatedNetCharList, "zone1-fog1-svc", "ue2-svc", 0, 0, 0, 77) {
	if !validateNetCharUpdate(updatedNetCharList, "zone1-fog1-svc", "ue2-svc", 1, 1, 0, 77) {
		t.Errorf("Error in Net Char update")
	}

@@ -408,13 +418,13 @@ func TestSegAlgoCalculation(t *testing.T) {
	if len(updatedNetCharList) != 3 {
		t.Errorf("Invalid net char update list")
	}
	if !validateNetCharUpdate(updatedNetCharList, "zone1-fog1-iperf", "ue1-iperf", 0, 0, 0, 26) {
	if !validateNetCharUpdate(updatedNetCharList, "zone1-fog1-iperf", "ue1-iperf", 1, 1, 0, 26) {
		t.Errorf("Error in Net Char update")
	}
	if !validateNetCharUpdate(updatedNetCharList, "zone2-edge1-iperf", "ue1-iperf", 0, 0, 0, 20) {
	if !validateNetCharUpdate(updatedNetCharList, "zone2-edge1-iperf", "ue1-iperf", 41, 9, 0, 20) {
		t.Errorf("Error in Net Char update")
	}
	if !validateNetCharUpdate(updatedNetCharList, "zone1-fog1-svc", "ue2-svc", 0, 0, 0, 74) {
	if !validateNetCharUpdate(updatedNetCharList, "zone1-fog1-svc", "ue2-svc", 1, 1, 0, 74) {
		t.Errorf("Error in Net Char update")
	}
}