Commit 4c0fc4bf authored by M. Rehan Abbasi's avatar M. Rehan Abbasi
Browse files

clean up VIS code

parent fd031792
Loading
Loading
Loading
Loading
+19 −274
Original line number Diff line number Diff line
@@ -43,8 +43,6 @@ type SbiCfg struct {
	PostgisHost    string
	PostgisPort    string
	Locality       []string
	// StaInfoCb      func(string, string, string, *int32, *int32, *int32)
	// ApInfoCb       func(string, string, *float32, *float32, []string)
	ScenarioNameCb func(string)
	CleanUpCb      func()
}
@@ -61,9 +59,6 @@ type VisSbi struct {
	apiMgr               *sam.SwaggerApiMgr
	activeModel          *mod.Model
	gisCache             *gc.GisCache
	// refreshTicker   *time.Ticker
	// updateStaInfoCB         func(string, string, string, *int32, *int32, *int32)
	// updateAccessPointInfoCB func(string, string, *float32, *float32, []string)
	updateScenarioNameCB func(string)
	cleanUpCB            func()
	mutex                sync.Mutex
@@ -83,8 +78,6 @@ func Init(cfg SbiCfg) (err error) {
	sbi.sandboxName = cfg.SandboxName
	sbi.mepName = cfg.MepName
	sbi.scenarioName = ""
	// sbi.updateStaInfoCB = cfg.StaInfoCb
	// sbi.updateAccessPointInfoCB = cfg.ApInfoCb
	sbi.updateScenarioNameCB = cfg.ScenarioNameCb
	sbi.cleanUpCB = cfg.CleanUpCb
	redisAddr = cfg.RedisAddr
@@ -202,25 +195,6 @@ func Stop() (err error) {
	return nil
}

// func startRefreshTicker() {
// 	log.Debug("Starting refresh loop")
// 	sbi.refreshTicker = time.NewTicker(1000 * time.Millisecond)
// 	go func() {
// 		for range sbi.refreshTicker.C {
// 			refreshPositions()
// 			// refreshMeasurements()
// 		}
// 	}()
// }

// func stopRefreshTicker() {
// 	if sbi.refreshTicker != nil {
// 		sbi.refreshTicker.Stop()
// 		sbi.refreshTicker = nil
// 		log.Debug("Refresh loop stopped")
// 	}
// }

// Message Queue handler
func msgHandler(msg *mq.Msg, userData interface{}) {
	switch msg.Message {
@@ -247,29 +221,6 @@ func processActiveScenarioTerminate() {
	sbi.cleanUpCB()
}

// func getAppSumUlDl(apps []string) (float32, float32) {
// 	sumUl := 0.0
// 	sumDl := 0.0
// 	//var appNames []string
// 	for _, appName := range apps {
// 		//appNames = append(appNames, process.Name)
// 		if metricStore != nil {
// 			metricsArray, err := metricStore.GetCachedNetworkMetrics("*", appName)
// 			if err != nil {
// 				log.Error("Failed to get network metric:", err)
// 			}

// 			//downlink for the app is uplink for the UE, and vice-versa
// 			for _, metrics := range metricsArray {
// 				sumUl += metrics.DlTput
// 				sumDl += metrics.UlTput
// 			}
// 		}
// 	}

// 	return float32(sumUl), float32(sumDl)
// }

func processActiveScenarioUpdate() {

	sbi.mutex.Lock()
@@ -277,15 +228,6 @@ func processActiveScenarioUpdate() {

	log.Debug("processActiveScenarioUpdate")

	// Get previous list of connected UEs
	// prevUeNames := []string{}
	// prevUeNameList := sbi.activeModel.GetNodeNames("UE")
	// for _, name := range prevUeNameList {
	// 	if isUeConnected(name) && isInLocality(name) {
	// 		prevUeNames = append(prevUeNames, name)
	// 	}
	// }

	sbi.activeModel.UpdateScenario()

	scenarioName := sbi.activeModel.GetScenarioName()
@@ -302,201 +244,4 @@ func processActiveScenarioUpdate() {
			log.Error("Failed connection to metric-store: ", err)
		}
	}
	// Get all POA positions & UE measurments
	// poaPositionMap, _ := sbi.gisCache.GetAllPositions(gc.TypePoa)
	// ueMeasMap, _ := sbi.gisCache.GetAllMeasurements()

	// Update UE info
	// ueNames := []string{}
	// ueNameList := sbi.activeModel.GetNodeNames("UE")
	// for _, name := range ueNameList {
	// 	// Ignore disconnected UEs
	// 	if !isUeConnected(name) || !isInLocality(name) {
	// 		continue
	// 	}
	// 	ueNames = append(ueNames, name)

	// 	// Update STA Info
	// 	ueParent := sbi.activeModel.GetNodeParent(name)
	// 	if poa, ok := ueParent.(*dataModel.NetworkLocation); ok {
	// 		apMacId := ""
	// 		var rssi *int32
	// 		switch poa.Type_ {
	// 		case mod.NodeTypePoaWifi:
	// 			apMacId = poa.PoaWifiConfig.MacId
	// 			rssi = getRssi(name, poa.Name, ueMeasMap)
	// 		}
	// 		ue := (sbi.activeModel.GetNode(name)).(*dataModel.PhysicalLocation)

	// 		//get all appNames under the UE
	// 		apps := (sbi.activeModel.GetNodeChild(name)).(*[]dataModel.Process)

	// 		var appNames []string
	// 		for _, process := range *apps {
	// 			appNames = append(appNames, process.Name)
	// 		}

	// 		sumUl, sumDl := getAppSumUlDl(appNames)
	// 		sumUlKbps := int32(sumUl * 1000)
	// 		sumDlKbps := int32(sumDl * 1000)
	// 		sbi.updateStaInfoCB(name, ue.MacId, apMacId, rssi, &sumUlKbps, &sumDlKbps)
	// 	}
	// }

	// // Update UEs that were removed
	// for _, prevUeName := range prevUeNames {
	// 	found := false
	// 	for _, ueName := range ueNames {
	// 		if ueName == prevUeName {
	// 			found = true
	// 			break
	// 		}
	// 	}
	// 	if !found {
	// 		sbi.updateStaInfoCB(prevUeName, "", "", nil, nil, nil)
	// 		log.Info("Ue removed : ", prevUeName)
	// 	}
	// }

	// // Update POA Wifi info
	// poaNameList := sbi.activeModel.GetNodeNames(mod.NodeTypePoaWifi)
	// for _, name := range poaNameList {
	// 	// Ignore POAs not in locality
	// 	if !isInLocality(name) {
	// 		continue
	// 	}

	// 	poa := (sbi.activeModel.GetNode(name)).(*dataModel.NetworkLocation)
	// 	if poa == nil {
	// 		log.Error("Can't find poa named " + name)
	// 		continue
	// 	}

	// 	var longitude *float32
	// 	var latitude *float32
	// 	if position, found := poaPositionMap[name]; found {
	// 		longitude = &position.Longitude
	// 		latitude = &position.Latitude
	// 	}
	// 	//list of Ues MacIds
	// 	var ueMacIdList []string

	// 	for _, pl := range poa.PhysicalLocations {
	// 		if pl.Connected {
	// 			ueMacIdList = append(ueMacIdList, pl.MacId)
	// 		}
	// 	}
	// 	sbi.updateAccessPointInfoCB(name, poa.PoaWifiConfig.MacId, longitude, latitude, ueMacIdList)
	// }
}

// func refreshPositions() {

// 	sbi.mutex.Lock()
// 	defer sbi.mutex.Unlock()

// 	// Update POA Positions
// 	poaPositionMap, _ := sbi.gisCache.GetAllPositions(gc.TypePoa)
// 	poaNameList := sbi.activeModel.GetNodeNames(mod.NodeTypePoaWifi)
// 	for _, name := range poaNameList {
// 		// Ignore POAs not in locality
// 		if !isInLocality(name) {
// 			continue
// 		}
// 		// Get Network Location
// 		poa := (sbi.activeModel.GetNode(name)).(*dataModel.NetworkLocation)
// 		if poa == nil {
// 			log.Error("Can't find poa named " + name)
// 			continue
// 		}

// 		// Get position
// 		var longitude *float32
// 		var latitude *float32
// 		if position, found := poaPositionMap[name]; found {
// 			longitude = &position.Longitude
// 			latitude = &position.Latitude
// 		}

// 		// Get list UE MacIds
// 		var ueMacIdList []string
// 		for _, pl := range poa.PhysicalLocations {
// 			if pl.Connected {
// 				ueMacIdList = append(ueMacIdList, pl.MacId)
// 			}
// 		}

// 		sbi.updateAccessPointInfoCB(name, poa.PoaWifiConfig.MacId, longitude, latitude, ueMacIdList)
// 	}
// }

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

// 		// Update STA Info
// 		ueParent := sbi.activeModel.GetNodeParent(name)
// 		if poa, ok := ueParent.(*dataModel.NetworkLocation); ok {
// 			apMacId := ""
// 			var rssi *int32
// 			switch poa.Type_ {
// 			case mod.NodeTypePoaWifi:
// 				apMacId = poa.PoaWifiConfig.MacId
// 				rssi = getRssi(name, poa.Name, ueMeasMap)
// 			}
// 			ue := (sbi.activeModel.GetNode(name)).(*dataModel.PhysicalLocation)
// 			apps := (sbi.activeModel.GetNodeChild(name)).(*[]dataModel.Process)

// 			var appNames []string
// 			for _, process := range *apps {
// 				appNames = append(appNames, process.Name)
// 			}

// 			sumUl, sumDl := getAppSumUlDl(appNames)
// 			sumUlKbps := int32(sumUl * 1000)
// 			sumDlKbps := int32(sumDl * 1000)
// 			sbi.updateStaInfoCB(name, ue.MacId, apMacId, rssi, &sumUlKbps, &sumDlKbps)
// 		}
// 	}
// }

// func getRssi(ue string, poa string, ueMeasMap map[string]*gc.UeMeasurement) *int32 {
// 	if ueMeas, ueFound := ueMeasMap[ue]; ueFound {
// 		if meas, poaFound := ueMeas.Measurements[poa]; poaFound {
// 			rssi := int32(meas.Rssi)
// 			return &rssi
// 		}
// 	}
// 	return nil
// }

// func isUeConnected(name string) bool {
// 	node := sbi.activeModel.GetNode(name)
// 	if node != nil {
// 		pl := node.(*dataModel.PhysicalLocation)
// 		if pl.Connected {
// 			return true
// 		}
// 	}
// 	return false
// }

// func isInLocality(name string) bool {
// 	if sbi.localityEnabled {
// 		ctx := sbi.activeModel.GetNodeContext(name)
// 		if ctx == nil {
// 			log.Error("Error getting context for: " + name)
// 			return false
// 		}
// 		if _, found := sbi.locality[ctx.Parents[mod.Zone]]; !found {
// 			return false
// 		}
// 	}
// 	return true
// }
+8 −67
Original line number Diff line number Diff line
@@ -52,53 +52,12 @@ const defaultScopeOfLocality = "MEC_SYSTEM"
const defaultConsumedLocalOnly = true
const appTerminationPath = "notifications/mec011/appTermination"

// const (
// 	notifCellChange = "CellChangeNotification"
// 	notifRabEst     = "RabEstNotification"
// 	notifRabMod      = "RabModNotification"
// 	notifRabRel    = "RabRelNotification"
// 	notifMeasRepUe = "MeasRepUeNotification"
// 	notifMeasTa      = "MeasTaNotification"
// 	notifCaReConf    = "CaReConfNotification"
// 	notifExpiry = "ExpiryNotification"
// 	notifS1Bearer    = "S1BearerNotification"
// 	notifNrMeasRepUe = "NrMeasRepUeNotification"
// )

// var metricStore *met.MetricStore

var redisAddr string = "meep-redis-master.default.svc.cluster.local:6379"
var influxAddr string = "http://meep-influxdb.default.svc.cluster.local:8086"
var sbxCtrlUrl string = "http://meep-sandbox-ctrl"

// const cellChangeSubscriptionType = "cell_change"
// const rabEstSubscriptionType = "rab_est"
// const rabRelSubscriptionType = "rab_rel"
// const measRepUeSubscriptionType = "meas_rep_ue"
// const nrMeasRepUeSubscriptionType = "nr_meas_rep_ue"
// const poaType4G = "POA-4G"
// const poaType5G = "POA-5G"
// const plTypeUE = "UE"

// var ccSubscriptionMap = map[int]*CellChangeSubscription{}
// var reSubscriptionMap = map[int]*RabEstSubscription{}
// var rrSubscriptionMap = map[int]*RabRelSubscription{}
// var mrSubscriptionMap = map[int]*MeasRepUeSubscription{}
// var nrMrSubscriptionMap = map[int]*NrMeasRepUeSubscription{}
// var subscriptionExpiryMap = map[int][]int{}
var currentStoreName = ""

// const CELL_CHANGE_SUBSCRIPTION = "CellChangeSubscription"
// const RAB_EST_SUBSCRIPTION = "RabEstSubscription"
// const RAB_REL_SUBSCRIPTION = "RabRelSubscription"
// const MEAS_REP_UE_SUBSCRIPTION = "MeasRepUeSubscription"
// const NR_MEAS_REP_UE_SUBSCRIPTION = "NrMeasRepUeSubscription"
// const CELL_CHANGE_NOTIFICATION = "CellChangeNotification"
// const RAB_EST_NOTIFICATION = "RabEstNotification"
// const RAB_REL_NOTIFICATION = "RabRelNotification"
// const MEAS_REP_UE_NOTIFICATION = "MeasRepUeNotification"
// const NR_MEAS_REP_UE_NOTIFICATION = "NrMeasRepUeNotification"

var VIS_DB = 0

var rc *redis.Connector
@@ -116,20 +75,6 @@ var baseKey string
var gisAppClient *gisClient.APIClient
var gisAppClientUrl string = "http://meep-gis-engine"

// var mutex sync.Mutex

// var expiryTicker *time.Ticker

// var periodicTriggerTicker *time.Ticker
// var periodicNrTriggerTicker *time.Ticker

// var nextSubscriptionIdAvailable int
// var nextAvailableErabId int

// const defaultSupportedQci = 80
// const defaultMeasRepUePeriodicTriggerInterval = 1
// const defaultNrMeasRepUePeriodicTriggerInterval = 1

const serviceAppVersion = "2.1.1"

var serviceAppInstanceId string
@@ -424,11 +369,6 @@ func Init() (err error) {
		SandboxName:    sandboxName,
		RedisAddr:      redisAddr,
		Locality:       locality,
		// UeDataCb:       updateUeData,
		// MeasInfoCb:     updateMeasInfo,
		// PoaInfoCb:      updatePoaInfo,
		// AppInfoCb:      updateAppInfo,
		// DomainDataCb:   updateDomainData,
		ScenarioNameCb: updateStoreName,
		CleanUpCb:      cleanUp,
	}
@@ -639,13 +579,13 @@ func predictedQosPost(w http.ResponseWriter, r *http.Request) {
	for i, route := range requestData.Routes {
		if route.RouteInfo == nil {
			log.Error("Mandatory routeInfo parameter not present in routes")
			http.Error(w, "Mandatory routeInfo parameter not present in route", http.StatusBadRequest)
			http.Error(w, "Mandatory routeInfo parameter not present in routes", http.StatusBadRequest)
			return
		}

		if len(route.RouteInfo) < 2 {
			log.Error("At least two routeInfo required in a route")
			http.Error(w, "At least two routeInfo required in a route", http.StatusBadRequest)
			log.Error("At least two location points required in routeInfo")
			http.Error(w, "At least two location points required in routeInfo", http.StatusBadRequest)
			return
		}

@@ -692,6 +632,7 @@ func predictedQosPost(w http.ResponseWriter, r *http.Request) {
				routeInfoList[j].Rsrq = currGeoCoordinate.Rsrq
				routeInfoList[j].Rsrp = currGeoCoordinate.Rsrp
			}
			routeInfo.Location.Ecgi = nil
		}
	}