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

add minimal PredictQosPerTrafficLoad functionality in meep-vis-traffic-mgr

parent e0fe8708
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
/*
 * Copyright (c) 2022  InterDigital Communications, Inc
 *
 * Licensed under the Apache License, Version 2.0 (the \"License\");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an \"AS IS\" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * AdvantEDGE V2X Information Service REST API
 *
 * V2X Information Service is AdvantEDGE's implementation of [ETSI MEC ISG MEC030 V2XI API](http://www.etsi.org/deliver/etsi_gs/MEC/001_099/030/02.02.01_60/gs_MEC030v020201p.pdf) <p>[Copyright (c) ETSI 2017](https://forge.etsi.org/etsi-forge-copyright-notice.txt) <p>**Micro-service**<br>[meep-vis](https://github.com/InterDigitalInc/AdvantEDGE/tree/master/go-apps/meep-vis) <p>**Type & Usage**<br>Edge Service used by edge applications that want to get information about radio conditions in the network <p>**Note**<br>AdvantEDGE supports a selected subset of RNI API endpoints (see below) and a subset of subscription types.
 *
 * API version: 2.2.1
 * Contact: AdvantEDGE@InterDigital.com
 * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
 */
package server

type TimeStamp struct {
	// The nanoseconds part of the time. Time is defined as Unix-time since January 1, 1970, 00:00:00 UTC.
	NanoSeconds int32 `json:"nanoSeconds"`
	// The seconds part of the time. Time is defined as Unixtime since January 1, 1970, 00:00:00 UTC.
	Seconds int32 `json:"seconds"`
}
+101 −0
Original line number Diff line number Diff line
@@ -812,3 +812,104 @@ func (tm *TrafficMgr) PopulateStaticPoaLoad(poaNameList []string) (err error) {

	return nil
}

// Returns Predicted QoS in terms of RSRQ and RSRP values based on Traffic Load patterns
func (tm *TrafficMgr) PredictQosPerTrafficLoad(estimatedTime TimeStamp, inRsrp int32, inRsrq int32, poaName string) (outRsrp int32, outRsrq int32, err error) {

	// Convert unix time to UTC time
	utcTime := time.Unix(int64(estimatedTime.Seconds), int64(estimatedTime.NanoSeconds))
	hour := utcTime.Hour()

	// Get time range for DB query
	timeRange := InTimeRange(hour)

	// Get predicted load for a given PoA in a desired time slot from the traffic patterns table

	var predictedUserTraffic int

	var entry *sql.Rows
	entry, err = tm.db.Query(`
		SELECT "` + timeRange + `" FROM ` + TrafficTable + ` WHERE poa_name = '` + poaName + `'`)
	if err != nil {
		log.Error(err)
	}

	entry.Close()

	for entry.Next() {
		entry.Scan(&predictedUserTraffic)
	}

	err = entry.Err()

	if err != nil {
		log.Error(err)
		log.Error("Could not find estimated user load in the traffic_patterns table")
		// returning the same values for Rsrp and Rsrq received in request
		return inRsrp, inRsrq, err
	}

	// Get average PoA load throughout the day
	poaLoad, err := tm.GetPoaLoad(poaName)
	if err != nil {
		log.Error(err)
		log.Error("Could not find PoA load in the traffic_patterns table")
		// returning the same values for Rsrp and Rsrq received in request
		return inRsrp, inRsrq, err
	}

	averageLoad := (poaLoad.ZeroToThree + poaLoad.ThreeToSix + poaLoad.SixToNine + poaLoad.NineToTwelve + poaLoad.TwelveToFifteen + poaLoad.FifteenToEighteen + poaLoad.EighteenToTwentyOne + poaLoad.TwentyOneToTwentyFour) / 8

	// Find reduced signal strength as a function of number of users in the area
	outRsrp, outRsrq, err = FindReducedSignalStrength(inRsrp, inRsrq, predictedUserTraffic, int(averageLoad))

	return

}

// Returns the time range as key in the traffic load map against vehicle ETA
func InTimeRange(hour int) (key string) {

	var TimeWindows = map[string][]int{
		"0000-0300": {0, 1, 2},
		"0300-0600": {3, 4, 5},
		"0600-0900": {6, 7, 8},
		"0900-1200": {9, 10, 11},
		"1200-1500": {12, 13, 14},
		"1500-1800": {15, 16, 17},
		"1800-2100": {18, 19, 20},
		"2100-2400": {21, 22, 23},
	}

	for key, hours := range TimeWindows {
		for i := range hours {
			if hours[i] == hour {
				return key
			}
		}
	}

	return ""
}

// Returns reduced signal strength based on the deviation in predicted user traffic from average user load in that area
// This is a simplistic version, considering only the user load in one particular area
// It will be extended to contain average user load for all active cells and those calculations will be used in further refining the algorithm
func FindReducedSignalStrength(inRsrp int32, inRsrq int32, users int, averageLoad int) (redRsrp int32, redRsrq int32, err error) {

	// case: crowded area
	if users > averageLoad {
		diff := users - averageLoad
		propConstant := int32(1 / diff)
		redRsrp = propConstant * inRsrp
		redRsrq = propConstant * inRsrq

		return redRsrp, redRsrq, nil

	} else {
		// no change in RSRP and RSRQ values
		return inRsrp, inRsrq, nil
	}

	return
}