Commit 12336c75 authored by Yann Garcia's avatar Yann Garcia
Browse files

Bugs fixed on meep-dederation during TTF T043 validation

parent b4e9ae9b
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@ spec:
      port: 31120
      targetPort: 31120
    - name: onboarded-demo1
      port: 31121
      port: 31122
      targetPort: 31122
    - name: onboarded-demo2
      port: 31123
+44 −24
Original line number Diff line number Diff line
@@ -686,26 +686,26 @@ func setupECSConfiguration() error {

// getECSConfig retrieves the ECS configuration from Redis and returns it as a map.
// An error is returned if the configuration is missing or cannot be unmarshaled.
func getECSConfig() (map[string]interface{}, error) {
	// Define the Redis key for the ECS configuration
	ecsKey := baseKey + "ecs:config"
	ecsConfigJson, err := rc.JSONGetEntry(ecsKey, ".")
	if err != nil {
		log.Error("getECSConfig: failed to get ECS configuration from Redis", "error", err.Error())
		return nil, fmt.Errorf("failed to get ECS configuration: %v", err)
	}

	// Unmarshal the JSON configuration into a map
	var ecsConfig map[string]interface{}
	err = json.Unmarshal([]byte(ecsConfigJson), &ecsConfig)
	if err != nil {
		log.Error("getECSConfig: failed to unmarshal ECS configuration", "error", err.Error())
		return nil, fmt.Errorf("failed to unmarshal ECS configuration: %v", err)
	}

	log.Info("getECSConfig: successfully retrieved ECS configuration from Redis", "key", ecsKey)
	return ecsConfig, nil
}
// func getECSConfig() (map[string]interface{}, error) {
// 	// Define the Redis key for the ECS configuration
// 	ecsKey := baseKey + "ecs:config"
// 	ecsConfigJson, err := rc.JSONGetEntry(ecsKey, ".")
// 	if err != nil {
// 		log.Error("getECSConfig: failed to get ECS configuration from Redis", "error", err.Error())
// 		return nil, fmt.Errorf("failed to get ECS configuration: %v", err)
// 	}

// 	// Unmarshal the JSON configuration into a map
// 	var ecsConfig map[string]interface{}
// 	err = json.Unmarshal([]byte(ecsConfigJson), &ecsConfig)
// 	if err != nil {
// 		log.Error("getECSConfig: failed to unmarshal ECS configuration", "error", err.Error())
// 		return nil, fmt.Errorf("failed to unmarshal ECS configuration: %v", err)
// 	}

// 	log.Info("getECSConfig: successfully retrieved ECS configuration from Redis", "key", ecsKey)
// 	return ecsConfig, nil
// }

// getRegistration retrieves the EEC registration details for a given RegistrationId.
// It extracts the registrationId from the request URL, looks up the corresponding entry in Redis,
@@ -744,7 +744,12 @@ func getRegistration(w http.ResponseWriter, r *http.Request) {

	// Send the JSON response with a 200 OK status
	w.WriteHeader(http.StatusOK)
	w.Write(jsonResponse)
	_, err = w.Write(jsonResponse)
	if err != nil {
		log.Error("getRegistration: failed to create the response", "error", err.Error())
		errHandlerProblemDetails(w, "Internal server error", http.StatusInternalServerError)
		return
	}
	log.Info("getRegistration: successfully retrieved registration", "registrationId", registrationId)
}

@@ -854,7 +859,12 @@ func updateRegistrationPut(w http.ResponseWriter, r *http.Request) {
	}

	w.WriteHeader(http.StatusOK)
	w.Write(jsonResponse)
	_, err = w.Write(jsonResponse)
	if err != nil {
		log.Error("updateRegistrationPut: failed to create the response", "error", err.Error())
		errHandlerProblemDetails(w, "Internal server error", http.StatusInternalServerError)
		return
	}
	log.Info("updateRegistrationPut: registration updated successfully", "registrationId", registrationId)
}

@@ -998,7 +1008,12 @@ func createEECReg(w http.ResponseWriter, r *http.Request) {

	// Send the successful creation response
	w.WriteHeader(http.StatusOK)
	w.Write(jsonResponse)
	_, err = w.Write(jsonResponse)
	if err != nil {
		log.Error("createEECReg: failed to create the response", "error", err.Error())
		errHandlerProblemDetails(w, "Internal server error", http.StatusInternalServerError)
		return
	}
	log.Info("createEECReg: registration created successfully", "registrationId", registrationId)
}

@@ -1178,7 +1193,12 @@ func requestServProv(w http.ResponseWriter, r *http.Request) {

	// Send the successful response with HTTP 200 OK.
	w.WriteHeader(http.StatusOK)
	w.Write(jsonResponse)
	_, err = w.Write(jsonResponse)
	if err != nil {
		log.Error("requestServProv: failed to create the response", "error", err.Error())
		errHandlerProblemDetails(w, "Internal server error", http.StatusInternalServerError)
		return
	}
	log.Info("requestServProv: successfully processed service provisioning request", "EecId", ecsServReq.EecId)
}

+57 −4
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@ externalDocs:
  description: "ETSI GS MEC 040 Federation enablement API, v3.2.1"
  url: https://www.etsi.org/deliver/etsi_gs/MEC/001_099/040/03.02.01_60/gs_MEC040v030201p.pdf
servers:
- url: https://localhost/sandboxname/fed_enablement/v1
- url: https://localhost/sandboxname/sandboxname/sandboxname/sandboxname/fed_enablement/v1
tags:
- name: systemInfo
- name: subscription
@@ -710,7 +710,8 @@ paths:
        x-exportParamName: Path.serviceId
      responses:
        "200":
          description: "Upon success, a response body containing data type describing the specific subscription data type is returned."
          description: "Upon success, a response body containing data type describing\
            \ the specific subscription data type is returned."
          content:
            application/json:
              schema:
@@ -949,8 +950,60 @@ components:
        \ as a part of the \nUpdate of MEC system(s) to the federation.\n"
    EndPointInfo:
      title: EndPointInfo
      type: object
      properties:
        uris:
          type: array
          description: "Entry point information of the service as string, formatted\
            \ according to URI syntax (see IETF RFC 3986 [8]). Shall be used for REST\
            \ APIs. See note."
          items:
            type: string
      description: "Endpoint information (e.g. URI, FQDN, IP address) of MEC federator."
        fqdn:
          type: array
          description: Fully Qualified Domain Name of the service. See note.
          items:
            type: string
        addresses:
          type: array
          items:
            $ref: '#/components/schemas/Addresses'
        alternative:
          type: string
          description: "Entry point information of the service in a format defined\
            \ by an implementation, or in an external specification. See\_note."
      description: "NOTE: Exactly one of \"uris\", \"fqdn\", \"addresses\" or \"alternative\"\
        \ shall be present. \n"
      example:
        uris:
        - uris
        - uris
        addresses:
        - port: 0
          host: host
        - port: 0
          host: host
        fqdn:
        - fqdn
        - fqdn
        alternative: alternative
    Addresses:
      required:
      - host
      - port
      type: object
      properties:
        host:
          type: string
          description: Host portion of the address.
        port:
          type: integer
          description: Port portion of the address.
      description: Entry point information of the service as one or more pairs of
        IP address and port. See note.
      example:
        port: 0
        host: host
    SystemUpdateNotificationSubscription:
      title: SystemUpdateNotificationSubscription
      required:
+77 −6
Original line number Diff line number Diff line
/*
 * Copyright (c) 2024  The AdvantEDGE Authors
 * Copyright (c) 2024-2025  The AdvantEDGE Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
@@ -81,10 +81,31 @@ type SystemInfo struct { // MEC Federation implementation of sharing MEC Platefo
	Host           string
}

var localSystemInfo SystemInfo
type SystemInfoUpdate struct {
	SystemId       string
	SystemName     string
	SystemProvider string
	Endpoint       EndPointInfo
}

type EndPointInfo struct {
	Uris        []string
	Fqdn        []string
	Addresses   []Addresses
	Alternative string
}

type Addresses struct {
	Host string
	Port int32
}

var localSystemInfo = SystemInfo{}

var sbi *FedSbi

var systemInfopMap = map[string]SystemInfo{} // List of discovered MEC Plateform

// Init - V2XI Service SBI initialization
func Init(cfg SbiCfg) (err error) {

@@ -165,6 +186,8 @@ func Init(cfg SbiCfg) (err error) {
	sbi.messageBrokerStarted = false
	log.Info("Connected to FED Traffic Manager")

	systemInfopMap = make(map[string]SystemInfo)

	// Initialize service
	processActiveScenarioUpdate()

@@ -219,6 +242,8 @@ func Stop() (err error) {
		}
	}

	systemInfopMap = nil

	// Delete FED Manager
	if sbi.federationMgr != nil {
		err = sbi.federationMgr.DeleteFederationMgr(localSystemInfo.SystemId)
@@ -280,7 +305,7 @@ func processActiveScenarioUpdate() {
}

func RegisterSystemInfo(requestData SystemInfo) (responseData SystemInfo, err error) {
	log.Info(">>> RegisterSystemInfo")
	log.Info(">>> RegisterSystemInfo: ", requestData)

	if !sbi.messageBrokerStarted {
		err = sbi.federationMgr.StartFedMessageBrokerServer()
@@ -297,22 +322,68 @@ func RegisterSystemInfo(requestData SystemInfo) (responseData SystemInfo, err er
		log.Error(err)
		return responseData, err
	}
	err = sbi.federationMgr.PublishMessageOnMessageBroker(s, requestData.SystemId)
	err = sbi.federationMgr.PublishMessageOnMessageBroker("", requestData.SystemId) // Remove emtry from brocker
	if err != nil {
		log.Error("Failed to publish message broker server: ", err)
		return responseData, err
	}

	responseData = requestData
	if localSystemInfo.SystemId == "" { // Self registration
		localSystemInfo = requestData
		log.Debug("RegisterSystemInfo: localSystemInfo=", localSystemInfo)
	} // otherwise, this is another MEC platform which is regsitering

	systemInfopMap[responseData.SystemId] = responseData
	log.Debug("RegisterSystemInfo: systemInfopMap=", systemInfopMap)

	return responseData, nil
}

func UpdateRegisteredSystemInfo(systemInfoUpdate SystemInfoUpdate) (err error) {
	log.Info(">>> UpdateRegisteredSystemInfo: ", systemInfoUpdate)

	// Sanity checks
	if len(systemInfoUpdate.Endpoint.Uris) == 0 && len(systemInfoUpdate.Endpoint.Fqdn) == 0 && len(systemInfoUpdate.Endpoint.Addresses) == 0 && systemInfoUpdate.Endpoint.Alternative == "" {
		err = errors.New("Invalid EndPointInfo value")
		return err
	}

	// if len(systemInfoUpdate.Endpoint.Uris) != 0 {
	// 	// FIXME FSCOM What to do with this???
	// } else if len(systemInfoUpdate.Endpoint.Fqdn) != 0 {
	// 	// FIXME FSCOM What to do with this???
	// } else if len(systemInfoUpdate.Endpoint.Addresses) != 0 {
	// 	// FIXME FSCOM What to do with this???
	// } else if systemInfoUpdate.Endpoint.Alternative != "" {
	// 	// FIXME FSCOM What to do with this???
	// }

	return nil
}

func DeregisterSystemInfo(systemId string) (err error) {
	log.Info(">>> DeregisterSystemInfo: ", systemId)

	if _, ok := systemInfopMap[systemId]; !ok {
		err = errors.New("Invalid SysemId: " + systemId)
		log.Error(err)
		return err
	}

	delete(systemInfopMap, systemId)
	log.Info("DeregisterSystemInfo: systemInfopMap: ", systemInfopMap)

	if sbi.messageBrokerStarted {
		err = sbi.federationMgr.DeleteFederationMgr(systemId)
		// Defer error processing
		if len(systemInfopMap) == 0 {
			log.Info("DeregisterSystemInfo: Call StopFedMessageBrokerServer")
			sbi.federationMgr.StopFedMessageBrokerServer()
			sbi.messageBrokerStarted = false
		}
	}

	if err != nil {
		log.Error(err)
		return err
+4 −4
Original line number Diff line number Diff line
@@ -12,10 +12,6 @@ import (
	"net/http"
)

func Mec011AppTerminationPOST(w http.ResponseWriter, r *http.Request) {
	mec011AppTerminationPost(w, r)
}

func SysteminfoByIdDELETE(w http.ResponseWriter, r *http.Request) {
	systeminfoByIdDELETE(w, r)
}
@@ -35,3 +31,7 @@ func SysteminfoGET(w http.ResponseWriter, r *http.Request) {
func SysteminfoPOST(w http.ResponseWriter, r *http.Request) {
	systeminfoPOST(w, r)
}

func Mec011AppTerminationPOST(w http.ResponseWriter, r *http.Request) {
	mec011AppTerminationPOST(w, r)
}
Loading