Unverified Commit f951b175 authored by Kevin Di Lallo's avatar Kevin Di Lallo Committed by GitHub
Browse files

Merge pull request #12 from pastorsx/sp_dev_sp26

Basic Edge Application Mobility + Network characteristics for physical locations & applications
parents 0f025739 79ec104f
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@ To see how to make this your own, look here:
[README](https://github.com/swagger-api/swagger-codegen/blob/master/README.md)

- API version: 0.0.1
- Build date: 2019-09-16T16:47:27.201-04:00
- Build date: 2019-09-17T14:39:27.445-04:00


### Running the server
+1 −1
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@ To see how to make this your own, look here:
[README](https://github.com/swagger-api/swagger-codegen/blob/master/README.md)

- API version: 0.0.1
- Build date: 2019-09-16T16:47:29.306-04:00
- Build date: 2019-09-17T14:39:29.528-04:00


### Running the server
+52 −15
Original line number Diff line number Diff line
@@ -661,6 +661,23 @@ definitions:
        type: "array"
        items:
          $ref: "#/definitions/Process"
      linkLatency:
        type: "integer"
        description: "Latency in ms between the physical location and the network\
          \ (wired interface, air interface)"
      linkLatencyVariation:
        type: "integer"
        description: "Latency variation in ms between the physical location and the\
          \ network (wired interface, air interface)"
      linkThroughput:
        type: "integer"
        description: "The limit of the traffic supported between the physical location\
          \ and the network (wired interface, air interface)"
      linkPacketLoss:
        type: "number"
        format: "double"
        description: "Packet lost (in terms of percentage) between the physical location\
          \ and the network (wired interface, air interface)"
    description: "Physical location object"
    example: {}
  Process:
@@ -727,6 +744,19 @@ definitions:
        description: "Key/Value Pair Map (string, string)"
        additionalProperties:
          type: "string"
      appLatency:
        type: "integer"
        description: "Latency in ms caused by the application"
      appLatencyVariation:
        type: "integer"
        description: "Latency variation in ms caused by the application"
      appThroughput:
        type: "integer"
        description: "The limit of the traffic supported by the application"
      appPacketLoss:
        type: "number"
        format: "double"
        description: "Packet lost (in terms of percentage) caused by the application"
    description: "Application or service object"
    example: {}
  ServiceConfig:
@@ -843,7 +873,7 @@ definitions:
        items:
          $ref: "#/definitions/Event"
    description: "Event list object"
    example: "null"
    example: {}
  Event:
    type: "object"
    properties:
@@ -855,13 +885,13 @@ definitions:
        description: "Event type"
        enum:
        - "NETWORK-CHARACTERISTICS-UPDATE"
        - "UE-MOBILITY"
        - "MOBILITY"
        - "POAS-IN-RANGE"
        - "OTHER"
      eventNetworkCharacteristicsUpdate:
        $ref: "#/definitions/EventNetworkCharacteristicsUpdate"
      eventUeMobility:
        $ref: "#/definitions/EventUeMobility"
      eventMobility:
        $ref: "#/definitions/EventMobility"
      eventPoasInRange:
        $ref: "#/definitions/EventPoasInRange"
      eventOther:
@@ -869,10 +899,10 @@ definitions:
    description: "Event object"
    example:
      name: "name"
      type: "UE-MOBILITY"
      eventUeMobility:
        ue: "ue"
        dest: "dest"
      type: "MOBILITY"
      eventMobility:
        elementName: "ue1"
        dest: "poa2"
  EventNetworkCharacteristicsUpdate:
    type: "object"
    properties:
@@ -889,6 +919,13 @@ definitions:
        - "ZONE-INTER-EDGE"
        - "ZONE-INTER-FOG"
        - "ZONE-EDGE-FOG"
        - "EDGE"
        - "FOG"
        - "UE"
        - "DISTANT-CLOUD"
        - "UE-APP"
        - "EDGE-APP"
        - "CLOUD-APP"
      latency:
        type: "integer"
        description: "Latency in ms"
@@ -904,19 +941,19 @@ definitions:
        description: "Packet loss percentage"
    description: "Network Characteristics update Event object"
    example: {}
  EventUeMobility:
  EventMobility:
    type: "object"
    properties:
      ue:
      elementName:
        type: "string"
        description: "UE identifier"
        description: "Name of the network element to be updated"
      dest:
        type: "string"
        description: "Destination identifier"
    description: "UE Mobility Event object"
        description: "Destination element identifier"
    description: "Mobility Event object"
    example:
      ue: "ue"
      dest: "dest"
      elementName: "ue1"
      dest: "poa2"
  EventPoasInRange:
    type: "object"
    properties:
+1 −1
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@ To see how to make this your own, look here:
[README](https://github.com/swagger-api/swagger-codegen/blob/master/README.md)

- API version: 1.0.0
- Build date: 2019-09-16T16:47:13.712-04:00
- Build date: 2019-09-17T14:39:13.849-04:00


### Running the server
+119 −30
Original line number Diff line number Diff line
@@ -771,6 +771,31 @@ func sendEventNetworkCharacteristics(event Event) (string, int) {
					break

				}
				// Parse Physical Locations
				for plIndex, pl := range nl.PhysicalLocations {
					if (elementType == "DISTANT CLOUD" || elementType == "EDGE" || elementType == "FOG" || elementType == "UE") && elementName == pl.Name {
						phyloc := &scenario.Deployment.Domains[dIndex].Zones[zIndex].NetworkLocations[nlIndex].PhysicalLocations[plIndex]
						phyloc.LinkLatency = netChar.Latency
						phyloc.LinkLatencyVariation = netChar.LatencyVariation
						phyloc.LinkThroughput = netChar.Throughput
						phyloc.LinkPacketLoss = netChar.PacketLoss
						elementFound = true
						break
					}
					// Parse Processes
					for procIndex, proc := range pl.Processes {
						if (elementType == "CLOUD APPLICATION" || elementType == "EDGE APPLICATION" || elementType == "UE APPLICATION") && elementName == proc.Name {
							procloc := &scenario.Deployment.Domains[dIndex].Zones[zIndex].NetworkLocations[nlIndex].PhysicalLocations[plIndex].Processes[procIndex]
							procloc.AppLatency = netChar.Latency
							procloc.AppLatencyVariation = netChar.LatencyVariation
							procloc.AppThroughput = netChar.Throughput
							procloc.AppPacketLoss = netChar.PacketLoss
							elementFound = true
							break
						}
					}
				}

			}
		}
	}
@@ -795,7 +820,7 @@ func sendEventNetworkCharacteristics(event Event) (string, int) {
	return "", -1
}

func sendEventUeMobility(event Event) (string, int) {
func sendEventMobility(event Event) (string, int) {

	// Retrieve active scenario
	var scenario Scenario
@@ -804,17 +829,25 @@ func sendEventUeMobility(event Event) (string, int) {
		return err.Error(), http.StatusNotFound
	}

	// Retrieve UE name and destination PoA name
	ueName := event.EventUeMobility.Ue
	poaName := event.EventUeMobility.Dest
	// Retrieve target name (src) and destination parent name
	elemName := event.EventMobility.ElementName
	destName := event.EventMobility.Dest

	var oldNL *NetworkLocation
	var oldPL *PhysicalLocation
	var newNL *NetworkLocation
	var ue *PhysicalLocation
	var ueIndex int

	// Find UE & destination PoA
	log.Debug("Searching for UE and destination PoA in active scenario")
	var newPL *PhysicalLocation
	var pl *PhysicalLocation
	var pr *Process
	var index int

	oldLocName := ""
	newLocName := ""
	isProcess := false
	isMoveable := true

	// Find PL & destination element
	log.Debug("Searching for ", elemName, " and destination in active scenario")
	for i := range scenario.Deployment.Domains {
		domain := &scenario.Deployment.Domains[i]

@@ -825,48 +858,104 @@ func sendEventUeMobility(event Event) (string, int) {
				nl := &zone.NetworkLocations[k]

				// Destination PoA
				if nl.Name == poaName {
				if nl.Name == destName {
					newNL = nl
				}
				//all edges are under a "default" network location element
				if zone.Name == destName && nl.Type_ == "DEFAULT" {
					newNL = nl
				}

				for l := range nl.PhysicalLocations {
					pl := &nl.PhysicalLocations[l]
					currentPl := &nl.PhysicalLocations[l]

					// Destination Physical location
					if currentPl.Name == destName {
						newPL = currentPl
					}

					// UE to move
					if pl.Type_ == "UE" && pl.Name == ueName {
					if currentPl.Name == elemName {
						if currentPl.Type_ == "UE" || currentPl.Type_ == "FOG" || currentPl.Type_ == "EDGE" {
							oldNL = nl
						ue = pl
						ueIndex = l
							pl = currentPl
							index = l
						}

					}
					for p := range currentPl.Processes {
						currentP := &currentPl.Processes[p]

						// APP to move
						if currentP.Name == elemName {
							if currentP.Type_ == "EDGE-APP" {
								//exception, we do not move if we are part of a mobility group
								if currentP.ServiceConfig != nil {
									if currentP.ServiceConfig.MeSvcName != "" {
										//this app shouldn't be allowed to move
										isMoveable = false
										break
									}
								}
								oldPL = currentPl
								pr = currentP
								index = p
								isProcess = true
							}
						}

	// Update UE location if necessary
	if ue != nil && oldNL != nil && newNL != nil && oldNL != newNL {
		log.Debug("Found UE and destination PoA. Updating UE location.")
					}

		// Add UE to new location
		newNL.PhysicalLocations = append(newNL.PhysicalLocations, *ue)
				}
			}
		}
	}

	if !isMoveable {
		//edge app cannot be moved
		log.Debug("Edge App cannot be moved, nothing should be done")
		err := "Edge App is part of a mobility group, it can't be moved"
		return err, http.StatusForbidden
	}

	// Update PL location if necessary
	if (pl != nil && oldNL != nil && newNL != nil && oldNL != newNL) ||
		(pr != nil && oldPL != nil && newPL != nil && oldPL != newPL) {
		log.Debug("Found src location and its destination. Updating location.")

		if isProcess {
			// Add Process to new location
			newPL.Processes = append(newPL.Processes, *pr)
			// Remove Process from old location
			oldPL.Processes[index] = oldPL.Processes[len(oldPL.Processes)-1]
			oldPL.Processes = oldPL.Processes[:len(oldPL.Processes)-1]

			oldLocName = oldPL.Name
			newLocName = newPL.Name
		} else {
			// Add PL to new location
			newNL.PhysicalLocations = append(newNL.PhysicalLocations, *pl)
			// Remove UE from old location
		oldNL.PhysicalLocations[ueIndex] = oldNL.PhysicalLocations[len(oldNL.PhysicalLocations)-1]
			oldNL.PhysicalLocations[index] = oldNL.PhysicalLocations[len(oldNL.PhysicalLocations)-1]
			oldNL.PhysicalLocations = oldNL.PhysicalLocations[:len(oldNL.PhysicalLocations)-1]

			oldLocName = oldNL.Name
			newLocName = newNL.Name
		}
		// Store updated active scenario in DB
		rev, err := setScenario(db, activeScenarioName, scenario)
		if err != nil {
			return err.Error(), http.StatusNotFound
		}
		log.Debug("Active scenario updated with rev: ", rev)

		log.WithFields(log.Fields{
			"meep.log.component": "ctrl-engine",
			"meep.log.msgType":   "mobilityEvent",
			"meep.log.oldPoa":    oldNL.Name,
			"meep.log.newPoa":    newNL.Name,
			"meep.log.src":       ue.Name,
			"meep.log.dest":      ue.Name,
			"meep.log.oldLoc":    oldLocName,
			"meep.log.newLoc":    newLocName,
			"meep.log.src":       elemName,
			"meep.log.dest":      elemName,
		}).Info("Measurements log")

		// TODO in Execution Engine:
@@ -874,7 +963,7 @@ func sendEventUeMobility(event Event) (string, int) {
		//    - Inform monitoring engine?

	} else {
		err := "Failed to find UE or destination PoA"
		err := "Failed to find target element or destination location"
		return err, http.StatusNotFound
	}
	return "", -1
@@ -991,8 +1080,8 @@ func ceSendEvent(w http.ResponseWriter, r *http.Request) {
	var httpStatus int
	var error string
	switch eventType {
	case "UE-MOBILITY":
		error, httpStatus = sendEventUeMobility(event)
	case "MOBILITY":
		error, httpStatus = sendEventMobility(event)
	case "NETWORK-CHARACTERISTICS-UPDATE":
		error, httpStatus = sendEventNetworkCharacteristics(event)
	case "POAS-IN-RANGE":
Loading