Commit 8279ca3e authored by Kevin Di Lallo's avatar Kevin Di Lallo
Browse files

app lifecycle MG Manager bug fixes

parent 52040ddd
Loading
Loading
Loading
Loading
+40 −7
Original line number Diff line number Diff line
@@ -451,17 +451,35 @@ func processScenario(model *mod.Model) error {
		}
	}

	// Remove elements no longer in active scenario
	// Remove stale elements
	for procName := range mgm.netElemInfoMap {
		if _, found := procNamesMap[procName]; !found {
			log.Debug("Removing stale element: ", procName)
			delete(mgm.netElemInfoMap, procName)
		}
	}

	// Remove Mobility Groups that no longer exist
	for mgName := range mgm.mgInfoMap {
	// Remove stale Mobility Groups
	for mgName, mgInfo := range mgm.mgInfoMap {
		if _, found := mgm.mgList[mgName]; !found {
			log.Debug("Removing stale MG: ", mgName)
			delete(mgm.mgInfoMap, mgName)
		} else {
			// Remove stale MG Apps
			for appName := range mgInfo.appInfoMap {
				if _, found := procNamesMap[appName]; !found {
					log.Debug("Removing stale MG App: ", appName)
					delete(mgInfo.appInfoMap, appName)
				}
			}
			// Remove stale UEs
			for ueName := range mgInfo.ueInfoMap {
				ueNodeType := model.GetNodeType(ueName)
				if ueNodeType != mod.NodeTypeUE {
					log.Debug("Removing stale UE: ", ueName)
					delete(mgInfo.ueInfoMap, ueName)
				}
			}
		}
	}

@@ -707,8 +725,13 @@ func startStateTransfer(group *mgInfo, elem *netElemInfo, ue *ueInfo, app string
		event.Type_ = eventTypeStateTransferStart
		event.UeId = ue.ue.Id
		startTime := time.Now()
		appInfo := group.appInfoMap[app]
		if appInfo == nil {
			log.Error("App not found: ", app)
			return
		}
		//lint:ignore SA1012 context.TODO not supported here
		resp, err := group.appInfoMap[app].appClient.StateTransferApi.HandleEvent(nil, event)
		resp, err := appInfo.appClient.StateTransferApi.HandleEvent(nil, event)
		duration := float64(time.Since(startTime).Microseconds()) / 1000.0
		if err != nil {
			log.Error(err.Error())
@@ -731,8 +754,13 @@ func completeStateTransfer(group *mgInfo, elem *netElemInfo, ue *ueInfo, app str
		event.Type_ = eventTypeStateTransferComplete
		event.UeId = ue.ue.Id
		startTime := time.Now()
		appInfo := group.appInfoMap[app]
		if appInfo == nil {
			log.Error("App not found: ", app)
			return
		}
		//lint:ignore SA1012 context.TODO not supported here
		resp, err := group.appInfoMap[app].appClient.StateTransferApi.HandleEvent(nil, event)
		resp, err := appInfo.appClient.StateTransferApi.HandleEvent(nil, event)
		duration := float64(time.Since(startTime).Microseconds()) / 1000.0
		if err != nil {
			log.Error(err.Error())
@@ -742,7 +770,7 @@ func completeStateTransfer(group *mgInfo, elem *netElemInfo, ue *ueInfo, app str
		met.ObserveNotification(mgm.sandboxName, serviceName, notifStateTransferComplete, "", resp, duration)
	}()

	// Set flag indicating transfer has been started
	// Set flag indicating transfer has been completed
	elem.transferInProgress = false
}

@@ -755,8 +783,13 @@ func cancelStateTransfer(group *mgInfo, elem *netElemInfo, ue *ueInfo, app strin
		event.Type_ = eventTypeStateTransferCancel
		event.UeId = ue.ue.Id
		startTime := time.Now()
		appInfo := group.appInfoMap[app]
		if appInfo == nil {
			log.Error("App not found: ", app)
			return
		}
		//lint:ignore SA1012 context.TODO not supported here
		resp, err := group.appInfoMap[app].appClient.StateTransferApi.HandleEvent(nil, event)
		resp, err := appInfo.appClient.StateTransferApi.HandleEvent(nil, event)
		duration := float64(time.Since(startTime).Microseconds()) / 1000.0
		if err != nil {
			log.Error(err.Error())
+3 −50
Original line number Diff line number Diff line
@@ -674,7 +674,6 @@ func sendEventPoasInRange(event dataModel.Event) (error, int, string) {
		err := errors.New("Malformed request: missing EventPoasInRange")
		return err, http.StatusBadRequest, ""
	}
	var ue *dataModel.PhysicalLocation

	// Retrieve UE name
	ueName := event.EventPoasInRange.Ue
@@ -685,41 +684,9 @@ func sendEventPoasInRange(event dataModel.Event) (error, int, string) {

	description := "[" + ueName + "] poas in range: " + strings.Join(poasInRange, ", ")

	// Find UE
	log.Debug("Searching for UE in active scenario")
	n := sbxCtrl.activeModel.GetNode(ueName)
	if n == nil {
		err := errors.New("Node not found " + ueName)
		return err, http.StatusNotFound, ""
	}
	ue, ok := n.(*dataModel.PhysicalLocation)
	if !ok {
		ue = nil
	} else if ue.Type_ != "UE" {
		ue = nil
	}

	// Update POAS in range if necessary
	if ue != nil {
		log.Debug("UE Found. Checking for update to visible POAs")

		// Compare new list of poas with current UE list and update if necessary
		if !equal(poasInRange, ue.NetworkLocationsInRange) {
			log.Debug("Updating POAs in range for UE: " + ue.Name)
			ue.NetworkLocationsInRange = poasInRange

			//Publish updated scenario
			err := sbxCtrl.activeModel.Activate()
	// Update active model
	err := sbxCtrl.activeModel.UpdatePoasInRange(ueName, poasInRange, nil)
	if err != nil {
				return err, http.StatusInternalServerError, ""
			}

			log.Debug("Active scenario updated")
		} else {
			log.Debug("POA list unchanged. Ignoring.")
		}
	} else {
		err := errors.New("Failed to find UE")
		return err, http.StatusNotFound, ""
	}
	return nil, -1, description
@@ -786,20 +753,6 @@ func getScenarioNodeName(node *dataModel.ScenarioNode) string {
	return name
}

// Equal tells whether a and b contain the same elements.
// A nil argument is equivalent to an empty slice.
func equal(a, b []string) bool {
	if len(a) != len(b) {
		return false
	}
	for i, v := range a {
		if v != b[i] {
			return false
		}
	}
	return true
}

func ceCreateReplayFile(w http.ResponseWriter, r *http.Request) {
	log.Debug("ceCreateReplayFile")
	vars := mux.Vars(r)
+2 −0
Original line number Diff line number Diff line
@@ -96,6 +96,8 @@ func (re *RoutingEngine) RefreshLbRules() {
		for _, svcMap := range netElem.ServiceMaps {
			if svcInfo, found := svcInfoMap[svcMap.LbSvcName]; found {
				podInfo.MgSvcMap[svcMap.MgSvcName] = svcInfo
			} else {
				log.Error("failed to find service instance: ", svcMap.LbSvcName)
			}
		}
	}
+2 −8
Original line number Diff line number Diff line
@@ -150,7 +150,7 @@ func (u *destination) compute() (st stat) {
	return
}

func (u *destination) processRxTx(ifbStatsStr string) float64 {
func (u *destination) processRxTx(ifbStatsStr string, curTime time.Time) float64 {

	// Retrieve ifb statistics from passed string
	// NOTE: we have to read the ifbStats from the back since based on the results are always at
@@ -164,9 +164,6 @@ func (u *destination) processRxTx(ifbStatsStr string) float64 {
		log.Error("Error in the ifb statistics output: ", ifbStats)
	}

	// Get timestamp for calculations
	curTime := time.Now()

	// Calculate throughput in Mbps
	var tput float64
	rxBytes := curRxBytes - u.prevRx.rxBytes
@@ -182,7 +179,7 @@ func (u *destination) processRxTx(ifbStatsStr string) float64 {
	return tput
}

func (u *destination) logRxTx(ifbStatsStr string) {
func (u *destination) logRxTx(ifbStatsStr string, curTime time.Time) {

	// Retrieve ifb statistics from passed string
	// NOTE: we have to read the ifbStats from the back since based on the results are always at
@@ -199,9 +196,6 @@ func (u *destination) logRxTx(ifbStatsStr string) {
		log.Error("Error in the ifb statistics output: ", ifbStats)
	}

	// Get timestamp for calculations
	curTime := time.Now()

	// Calculate packet loss percentage
	var loss float64
	rxPkt := curRxPkt - u.prevRxLog.rxPkt
+10 −2
Original line number Diff line number Diff line
@@ -680,6 +680,10 @@ func workRxTxPackets() {
			semOptsDests.Unlock()
			return
		}

		// Get timestamp for calculations
		curTime := time.Now()

		//split line by line
		lineStrings := strings.Split(out, "\n")

@@ -706,7 +710,7 @@ func workRxTxPackets() {

		// Get throughput metrics for each dest
		for _, dest := range opts.dests {
			tputStats[dest.remoteName] = dest.processRxTx(qdiscResults["ifb"+dest.ifbNumber])
			tputStats[dest.remoteName] = dest.processRxTx(qdiscResults["ifb"+dest.ifbNumber], curTime)
		}

		key := metricsBaseKey + PodName + ":throughput"
@@ -733,6 +737,10 @@ func workLogRxTxData() {
			semOptsDests.Unlock()
			return
		}

		// Get timestamp for calculations
		curTime := time.Now()

		//split line by line
		lineStrings := strings.Split(out, "\n")

@@ -756,7 +764,7 @@ func workLogRxTxData() {

		// Get NC metrics for each dest
		for _, dest := range opts.dests {
			dest.logRxTx(qdiscResults["ifb"+dest.ifbNumber])
			dest.logRxTx(qdiscResults["ifb"+dest.ifbNumber], curTime)
		}
		semOptsDests.Unlock()

Loading