Commit b1111193 authored by Yann Garcia's avatar Yann Garcia
Browse files

Validate Registration GET/POST mechanism; Update demo6 with MEC 040 basic features

parent c3b0f335
Loading
Loading
Loading
Loading
+1 −1
Changes for charts/meep-federation/values-template.yaml: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@ image:
    MEEP_SANDBOX_NAME: {{.SandboxName}}
    MEEP_SVC_PATH: /fed_enablement/v1
    MEEP_HOST_URL: {{.HostUrl}}
    MEEP_BROKER: mqtt://mec-platform2.etsi.org:1883
    MEEP_BROKER: mqtt://172.29.10.56:1883
    MEEP_TOPIC: ETSI/MEC/Federation
    {{- if .IsMepService }}
    MEEP_MEP_NAME: {{.MepName}}
+66 −1
Changes for examples/demo6/golang/main.go: 66 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -146,6 +146,9 @@ type V2xMsgSubscriptionFilterCriteria struct {
	StdOrganization string  `json:"stdOrganization"`
}

// MEC 040
// TODO

// MEC Common types
type LinkType struct {
	// URI referring to a resource
@@ -214,6 +217,8 @@ const (
	MEC030_UU_SETTINGS    = "Y"
	MEC030_V2X_SUB        = "z"
	MEC030_V2X_DEL_SUB    = "Z"
	MEC040_FED_SYS_GET    = "0"
	MEC040_FED_SRV_GET    = "1"
	STATUS                = "Q"
	QUIT                  = "q"
)
@@ -239,9 +244,11 @@ func menu(message string) []string {
			"\t%s: Create new service, %s: Delete service, %s: Get list of MEC services\n"+
			"MEC 030:\n"+
			"\t%s: Get V2X UU unicast setting', %s: V2X Msg subscription, %s <subID>: Delete V2X subscription\n"+
			"MEC 040:\n"+
			"\t%s: Get Federation Systems list', %s <systemId>: Get Federation Services list\n"+
			"\t%s: Current status:\n"+
			"%s: Quit\n",
		LOGIN, NAMESPACE, LOGOUT, LIST_SC, ACTIVATE, DEACTIVATE, SC, LIST_SERVICES, LIST_APP, CREATE_APP, DELETE_APP, LIST_UES, INC_UE, DEC_UE, MEC011_CONFIRM_READY, MEC011_REGISTRATION, MEC011_DEREGISTRATION, MEC011_CREATE_SVC, MEC011_DELETE_SVC, MEC011_GET_SVC, MEC030_UU_SETTINGS, MEC030_V2X_SUB, MEC030_V2X_DEL_SUB, STATUS, QUIT)
		LOGIN, NAMESPACE, LOGOUT, LIST_SC, ACTIVATE, DEACTIVATE, SC, LIST_SERVICES, LIST_APP, CREATE_APP, DELETE_APP, LIST_UES, INC_UE, DEC_UE, MEC011_CONFIRM_READY, MEC011_REGISTRATION, MEC011_DEREGISTRATION, MEC011_CREATE_SVC, MEC011_DELETE_SVC, MEC011_GET_SVC, MEC030_UU_SETTINGS, MEC030_V2X_SUB, MEC030_V2X_DEL_SUB, MEC040_FED_SYS_GET, MEC040_FED_SRV_GET, STATUS, QUIT)
	if message != "" {
		fmt.Println("Last message: ", message)
	}
@@ -969,6 +976,9 @@ func mec030_delete_v2x_messages_subscription(choice string) (response *http.Resp
	if sandboxName == "" {
		return nil, errors.New("No sandbox available")
	}
	if choice == "" {
		return nil, errors.New("Wrong parameter")
	}

	// Set URL
	url := mecUrl + "/" + sandboxName + "/" + mecPlateform + "/vis/v2/subscriptions/" + choice
@@ -987,6 +997,49 @@ func v2x_msg_notification(w http.ResponseWriter, r *http.Request) {
	w.WriteHeader(http.StatusOK)
}

func mec40_get_systems_list() (body []byte, response *http.Response, err error) {
	fmt.Println(">>> mec40_get_systems_list")

	// Sanity checks
	if sandboxName == "" {
		return nil, nil, errors.New("No sandbox available")
	}

	// Set URL
	url := mecUrl + "/" + sandboxName + "/" + mecPlateform + "/fed_enablement/v1/fed_resources/systems"
	fmt.Println("mec40_get_systems_list: url: " + url)
	// Send request and await response
	body, response, err = send_mec_service_request(http.MethodGet, url, nil, nil, nil, nil)
	if err != nil {
		return nil, nil, err
	}

	return body, response, nil
}

func mec40_get_services_list(choice string) (body []byte, response *http.Response, err error) {
	fmt.Println(">>> mec40_get_services_list")

	// Sanity checks
	if sandboxName == "" {
		return nil, nil, errors.New("No sandbox available")
	}
	if choice == "" {
		return nil, nil, errors.New("Wrong parameter")
	}

	// Set URL
	url := mecUrl + "/" + sandboxName + "/" + mecPlateform + "systems/" + choice + "/services"
	fmt.Println("mec40_get_services_list: url: " + url)
	// Send request and await response
	body, response, err = send_mec_service_request(http.MethodGet, url, nil, nil, nil, nil)
	if err != nil {
		return nil, nil, err
	}

	return body, response, nil
}

func app_status() (resp string) {
	resp = ""
	if sandboxName != "" {
@@ -1336,6 +1389,18 @@ func process_choice(choice []string) string {
			return err.Error()
		}
		message = fmt.Sprintf("response body:  Subscription %s deleted", choice[1])
	} else if strings.Compare(choice[0], MEC040_FED_SYS_GET) == 0 {
		body, _, err := mec40_get_systems_list()
		if err != nil {
			return err.Error()
		}
		message = fmt.Sprintf("response body:  %s", string(body))
	} else if strings.Compare(choice[0], MEC040_FED_SRV_GET) == 0 {
		body, _, err := mec40_get_services_list(choice[1])
		if err != nil {
			return err.Error()
		}
		message = fmt.Sprintf("response body:  %s", string(body))
	} else if strings.Compare(choice[0], STATUS) == 0 {
		resp := app_status()
		message = fmt.Sprintf("Current status: %s", resp)
+14 −4
Changes for go-apps/meep-federation/api/swagger.yaml: 14 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -605,6 +605,15 @@ paths:
        system associated with the systemId
      operationId: servicesGET
      parameters:
      - name: systemId
        in: path
        description: Identifier of the MEC system.
        required: true
        style: simple
        explode: false
        schema:
          type: string
        x-exportParamName: Path.systemId
      - name: seInstancerId
        in: query
        description: Indicator of a MEC service offered for MEC federation.
@@ -683,24 +692,25 @@ paths:
      parameters:
      - name: systemId
        in: path
        description: MEC system identifier
        description: Identifier of the MEC system.
        required: true
        style: simple
        explode: false
        schema:
          type: string
          format: uri
        x-exportParamName: Path.systemId
      - name: serviceId
        in: path
        description: Service identifier
        description: Service identifier.
        required: true
        style: simple
        explode: false
        schema:
          type: string
          format: uri
        x-exportParamName: Path.serviceId
      responses:
        "200":
          description: "Upon success, a response body containing data type describing the specific subscription data type is returned."
          content:
            application/json:
              schema:
+16 −0
Changes for go-apps/meep-federation/sbi/federation-sbi.go: 16 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -33,6 +33,8 @@ const moduleName string = "meep-federation-sbi"
type SbiCfg struct {
	ModuleName     string
	SandboxName    string
	FedBasePath    string
	HostUrl        string
	FedBroker      string
	FedTopic       string
	MepName        string
@@ -47,7 +49,9 @@ type SbiCfg struct {
type FedSbi struct {
	moduleName           string
	sandboxName          string
	hostUrl              string
	mepName              string
	fedBasePath          string
	scenarioName         string
	localityEnabled      bool
	locality             map[string]bool
@@ -87,6 +91,8 @@ func Init(cfg SbiCfg) (err error) {
	sbi = new(FedSbi)
	sbi.moduleName = cfg.ModuleName
	sbi.sandboxName = cfg.SandboxName
	sbi.fedBasePath = cfg.FedBasePath
	sbi.hostUrl = cfg.HostUrl
	sbi.mepName = cfg.MepName
	sbi.scenarioName = ""
	sbi.fedBroker = cfg.FedBroker
@@ -114,6 +120,16 @@ func Init(cfg SbiCfg) (err error) {
	}
	log.Info("Message Queue created")

	// Indicate MEC-FED mepName
	msg := sbi.mqLocal.CreateMsg(mq.MecFedConfig, mq.TargetAll, sbi.sandboxName)
	msg.Payload["URL"] = "http://" + sbi.mepName + "-meep-federation/" + sbi.fedBasePath
	log.Debug("TX MSG: ", mq.PrintMsg(msg))
	err = sbi.mqLocal.SendMsg(msg)
	if err != nil {
		log.Error("Failed to send message. Error: ", err.Error())
		return err
	}

	// Create Swagger API Manager
	sbi.apiMgr, err = sam.NewSwaggerApiMgr(sbi.moduleName, sbi.sandboxName, sbi.mepName, sbi.mqLocal)
	if err != nil {
+10 −7
Changes for go-apps/meep-federation/server/federation.go: 10 added lines, 7 removed lines.
Original line number Diff line number Diff line
@@ -369,6 +369,7 @@ func Init() (err error) {

	// Set base storage key
	baseKey = dkm.GetKeyRoot(sandboxName) + fedKey + ":mep:" + mepName + ":"
	log.Error("FED baseKey: ", baseKey)

	// Connect to Redis DB (FED_DB)
	rc, err = redis.NewConnector(redisAddr, FED_DB)
@@ -392,6 +393,8 @@ func Init() (err error) {
	sbiCfg := sbi.SbiCfg{
		ModuleName:     moduleName,
		SandboxName:    sandboxName,
		FedBasePath:    fedBasePath,
		HostUrl:        hostUrl.String() + basePath,
		RedisAddr:      redisAddr,
		Locality:       locality,
		ScenarioNameCb: updateStoreName,
@@ -772,7 +775,7 @@ func systeminfoPOST(w http.ResponseWriter, r *http.Request) {
	log.Debug(">>> systeminfoPOST: ", r)

	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	var requestData SystemInfo
	var requestData FedResourcesSystemsBody
	decoder := json.NewDecoder(r.Body)
	err := decoder.Decode(&requestData)
	if err != nil {
@@ -783,19 +786,19 @@ func systeminfoPOST(w http.ResponseWriter, r *http.Request) {
	log.Debug("systeminfoPOST: requestData: ", requestData)

	// Validating mandatory parameters in request
	if requestData.SystemId != "" {
	if requestData.SystemInfo.SystemId != "" {
		log.Error("Mandatory systemId parameter shall be absent")
		errHandlerProblemDetails(w, "Mandatory attribute systemId shall be absent in the request body.", http.StatusBadRequest)
		return
	}

	if requestData.SystemName == "" {
	if requestData.SystemInfo.SystemName == "" {
		log.Error("Mandatory systemName parameter not present")
		errHandlerProblemDetails(w, "Mandatory attribute systemName is missing in the request body.", http.StatusBadRequest)
		return
	}

	if requestData.SystemProvider == "" {
	if requestData.SystemInfo.SystemProvider == "" {
		log.Error("Mandatory systemProvider parameter not present")
		errHandlerProblemDetails(w, "Mandatory attribute systemProvider is missing in the request body.", http.StatusBadRequest)
		return
@@ -803,8 +806,8 @@ func systeminfoPOST(w http.ResponseWriter, r *http.Request) {

	var s = sbi.SystemInfo{
		SystemId:       uuid.New().String(),
		SystemName:     requestData.SystemName,
		SystemProvider: requestData.SystemProvider,
		SystemName:     requestData.SystemInfo.SystemName,
		SystemProvider: requestData.SystemInfo.SystemProvider,
		TransportTypes: "HTTP",
		Protocol:       "REST_HTTP",
		SerializerType: "JSON",
@@ -813,7 +816,7 @@ func systeminfoPOST(w http.ResponseWriter, r *http.Request) {
	responseData, err := sbi.RegisterSystemInfo(s)
	if err != nil {
		log.Error("Failed to register SystemInfo: ", err)
		errHandlerProblemDetails(w, err.Error(), http.StatusBadRequest)
		errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError)
		return
	}
	// Same data type
Loading