Loading examples/demo10/Dockerfile 0 → 100644 +26 −0 Original line number Diff line number Diff line # Copyright (c) 2022 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. # 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. FROM golang # Some ENV variables ENV SERVICE_NAME = "demo10" COPY ./demo10 /demo10 COPY entrypoint.sh / RUN chmod +x /entrypoint.sh ENTRYPOINT ["/entrypoint.sh"] examples/demo10/MEC/Get_App_Instances.go +16 −6 Original line number Diff line number Diff line package mec import ( model "demo10/Model" utils "demo10/utils" "encoding/json" "fmt" "net/http" model "estimed_demo/Model" utils "estimed_demo/utils" "io" "encoding/json" "net/http" ) // Get MEC APP instances // GetAppInstances retrieves all MEC Application Instances from the platform // // This function queries the MEC platform's application management API to obtain // a list of all available application instances, including their IDs, names, and node names. // // Reference: ETSI GS MEC 011 - MEC Application Lifecycle Management API // // @param url The URL endpoint for querying application instances // (e.g., /sandbox-ctrl/v1/applications) // @return []model.AppInstanceID Array of application instance information // @return error Returns nil on success, or an error if the request fails func GetAppInstances(url string) ([]model.AppInstanceID, error) { resp, err := utils.SendMECRequest("GET", url, nil) if err != nil { Loading examples/demo10/MEC/ams.go +90 −7 Original line number Diff line number Diff line package mec import ( model "demo10/Model" utils "demo10/utils" "encoding/json" model "estimed_demo/Model" utils "estimed_demo/utils" "fmt" "log" "net/http" "regexp" ) // Create MEC AMS service registration // CreateAMSRegistration creates a MEC Application Mobility Service (AMS) registration // // This function creates an AMS registration for a given application instance ID. // The registration includes device information if provided, which is used to // associate the device with the application instance for mobility management. // // Reference: ETSI GS MEC 021 - Application Mobility Service API // // @param url The URL endpoint for AMS registration (e.g., /amsi/v1/app_mobility_services) // @param app_instance_id The MEC Application Instance ID to register // @param device_info Optional device information for the registration (can be nil) // @return *model.RegistrationInfo The registration information returned by the MEC platform // @return error Returns nil on success, or an error if the registration fails func CreateAMSRegistration(url string, app_instance_id string, device_info *model.RegistrationInfoDeviceInformation) (*model.RegistrationInfo, error) { payload := &model.RegistrationInfo{} if device_info != nil { Loading Loading @@ -44,8 +56,20 @@ func CreateAMSRegistration(url string, app_instance_id string, device_info *mode return ®istrationInfo, nil } // Create MEC AMS subscription // CreateAMSSubscription creates a MEC Application Mobility Service (AMS) subscription // // This function creates a subscription for mobility procedure notifications. // The subscription allows the application to receive notifications when mobility // events occur, such as when the application instance moves to a different MEC host. // // Reference: ETSI GS MEC 021 - Application Mobility Service API // // @param url The URL endpoint for AMS subscription (e.g., /amsi/v1/subscriptions) // @param app_instance_id The MEC Application Instance ID to subscribe to // @param callbackURL The callback URL where mobility notifications will be sent // @param associateId Optional associate ID (e.g., UE IP address) for filtering notifications // @return *model.InlineSubscription The subscription information returned by the MEC platform // @return error Returns nil on success, or an error if the subscription creation fails func CreateAMSSubscription(url string, app_instance_id string, callbackURL string, associateId *model.AssociateId) (*model.InlineSubscription, error) { payload := &model.InlineSubscription{} if associateId != nil { Loading Loading @@ -85,7 +109,18 @@ func CreateAMSSubscription(url string, app_instance_id string, callbackURL strin return &subscriptionInfo, nil } // AMSNotificationHandler handles incoming AMS notifications // AMSNotificationHandler handles incoming AMS mobility procedure notifications // // This HTTP handler processes POST requests containing AMS notifications. // It extracts the target application instance ID from the notification payload, // which indicates that the application should migrate to a new MEC host. // // Reference: ETSI GS MEC 021 - Application Mobility Service API // // @param w HTTP response writer // @param r HTTP request containing the AMS notification // @return string The target application instance ID extracted from the notification // @return error Returns nil on success, or an error if the notification cannot be processed func AMSNotificationHandler(w http.ResponseWriter, r *http.Request) (string, error) { if r.Method != http.MethodPost { http.Error(w, "Invalid request method", http.StatusMethodNotAllowed) Loading Loading @@ -114,6 +149,26 @@ func AMSNotificationHandler(w http.ResponseWriter, r *http.Request) (string, err return targetAppInstanceID, nil } // RegistrationAndSubscriptionHandler creates AMS registrations and subscriptions for multiple app instances // // This function iterates through matching application instances and creates: // - AMS registration for each app instance (with device info for the first instance) // - AMS subscription for each app instance to receive mobility notifications // // It collects platform information (AMS service ID, subscription ID, node name) for each // app instance and returns it in a structured format. // // Reference: ETSI GS MEC 021 - Application Mobility Service API // // @param matchingAppInstances Array of matching MEC Application Instance IDs // @param platformURL Base URL of the MEC platform // @param sandbox_name Name of the MEC sandbox // @param callbackURL URL where AMS notifications will be sent // @param currentAppInstanceId Pointer to store the current app instance ID (first instance) // @param deviceInfo Device information for registration (used for first instance) // @param associateId Associate ID for subscription filtering (used for first instance) // @return []map[string]model.PlatformInfo Array of platform information maps keyed by app instance ID // @return error Returns nil on success, or an error if registration/subscription fails func RegistrationAndSubscriptionHandler(matchingAppInstances []model.AppInstanceID, platformURL string, sandbox_name string, callbackURL string, currentAppInstanceId *string, deviceInfo *model.RegistrationInfoDeviceInformation, associateId *model.AssociateId) ([]map[string]model.PlatformInfo, error) { Loading Loading @@ -180,7 +235,20 @@ func RegistrationAndSubscriptionHandler(matchingAppInstances []model.AppInstance return platformDetails, nil } // TODO: Complete the function to update AMS registration info // PutAMSRegistrationInfo updates AMS registration information for mobility handover // // This function updates the AMS registration for both the current and target application // instances during a mobility handover procedure. It updates the context transfer state // to reflect the mobility status. // // Reference: ETSI GS MEC 021 - Application Mobility Service API // // @param url The base URL endpoint for AMS registration updates // @param targetappinstance The target application instance ID for the handover // @param platformDetails Array of platform information maps containing AMS service IDs // @param current_app_instance Pointer to the current application instance ID // @param associateID Associate ID (e.g., UE IP address) for the registration // @return error Returns nil on success, or an error if the update fails func PutAMSRegistrationInfo(url string, targetappinstance string, platformDetails []map[string]model.PlatformInfo, current_app_instance *string, associateID *model.AssociateId) error { if len(platformDetails) == 0 { Loading Loading @@ -258,6 +326,21 @@ func PutAMSRegistrationInfo(url string, targetappinstance string, platformDetail return nil } // PUTAMSSubscriptionInfo updates AMS subscription information for mobility handover // // This function updates the AMS subscription for both the current and target application // instances during a mobility handover. It updates the mobility status filter criteria // to reflect the current state of the handover procedure. // // Reference: ETSI GS MEC 021 - Application Mobility Service API // // @param url The base URL endpoint for AMS subscription updates // @param targetappinstance The target application instance ID for the handover // @param platformDetails Array of platform information maps containing subscription IDs // @param current_app_instance Pointer to the current application instance ID // @param call_back_url The callback URL for receiving mobility notifications // @param associateid Associate ID (e.g., UE IP address) for subscription filtering // @return error Returns nil on success, or an error if the update fails func PUTAMSSubscriptionInfo(url string, targetappinstance string, platformDetails []map[string]model.PlatformInfo, current_app_instance *string, call_back_url string, associateid *model.AssociateId) error { if len(platformDetails) == 0 { Loading examples/demo10/MEC/iot_api.go +14 −4 Original line number Diff line number Diff line package mec import ( utils "demo10/utils" "encoding/json" utils "estimed_demo/utils" "fmt" "net/http" ) // Fetch for platform info // GETIotPlatformInfo retrieves IoT platform information from the MEC platform // // This function queries the MEC platform's IoT API to obtain information about // registered IoT platforms, including their endpoints and connection details. // // Reference: ETSI GS MEC 040 - MEC IoT API // // @param url The URL endpoint for querying registered IoT platforms // (e.g., /iots/v1/registered_iot_platforms) // @return []map[string]interface{} Array of IoT platform information maps // @return error Returns nil on success, or an error if the request fails func GETIotPlatformInfo(url string) ([]map[string]interface{}, error) { resp, err := utils.SendMECRequest("GET", url, nil) if err != nil { Loading examples/demo10/MEC/match_for_target_app_instance.go +10 −2 Original line number Diff line number Diff line package mec import ( model "estimed_demo/Model" model "demo10/Model" "fmt" "regexp" ) // Match for target App Instance ID // MatchForTargetAppInstance matches application instances by CSE name using regex // // This function filters the list of all application instances to find those // whose names match the provided CSE name pattern using regular expression matching. // // @param allAppInstances Array of all available MEC Application Instance IDs // @param cse_name The CSE name pattern (regex) to match against // @return []model.AppInstanceID Array of matching application instances // @return error Returns nil on success, or an error if no matches are found or regex is invalid func MatchForTargetAppInstance(allAppInstances []model.AppInstanceID, cse_name string) ([]model.AppInstanceID, error) { // Compile regex for cse_name once reCSE, err := regexp.Compile(cse_name) Loading Loading
examples/demo10/Dockerfile 0 → 100644 +26 −0 Original line number Diff line number Diff line # Copyright (c) 2022 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. # 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. FROM golang # Some ENV variables ENV SERVICE_NAME = "demo10" COPY ./demo10 /demo10 COPY entrypoint.sh / RUN chmod +x /entrypoint.sh ENTRYPOINT ["/entrypoint.sh"]
examples/demo10/MEC/Get_App_Instances.go +16 −6 Original line number Diff line number Diff line package mec import ( model "demo10/Model" utils "demo10/utils" "encoding/json" "fmt" "net/http" model "estimed_demo/Model" utils "estimed_demo/utils" "io" "encoding/json" "net/http" ) // Get MEC APP instances // GetAppInstances retrieves all MEC Application Instances from the platform // // This function queries the MEC platform's application management API to obtain // a list of all available application instances, including their IDs, names, and node names. // // Reference: ETSI GS MEC 011 - MEC Application Lifecycle Management API // // @param url The URL endpoint for querying application instances // (e.g., /sandbox-ctrl/v1/applications) // @return []model.AppInstanceID Array of application instance information // @return error Returns nil on success, or an error if the request fails func GetAppInstances(url string) ([]model.AppInstanceID, error) { resp, err := utils.SendMECRequest("GET", url, nil) if err != nil { Loading
examples/demo10/MEC/ams.go +90 −7 Original line number Diff line number Diff line package mec import ( model "demo10/Model" utils "demo10/utils" "encoding/json" model "estimed_demo/Model" utils "estimed_demo/utils" "fmt" "log" "net/http" "regexp" ) // Create MEC AMS service registration // CreateAMSRegistration creates a MEC Application Mobility Service (AMS) registration // // This function creates an AMS registration for a given application instance ID. // The registration includes device information if provided, which is used to // associate the device with the application instance for mobility management. // // Reference: ETSI GS MEC 021 - Application Mobility Service API // // @param url The URL endpoint for AMS registration (e.g., /amsi/v1/app_mobility_services) // @param app_instance_id The MEC Application Instance ID to register // @param device_info Optional device information for the registration (can be nil) // @return *model.RegistrationInfo The registration information returned by the MEC platform // @return error Returns nil on success, or an error if the registration fails func CreateAMSRegistration(url string, app_instance_id string, device_info *model.RegistrationInfoDeviceInformation) (*model.RegistrationInfo, error) { payload := &model.RegistrationInfo{} if device_info != nil { Loading Loading @@ -44,8 +56,20 @@ func CreateAMSRegistration(url string, app_instance_id string, device_info *mode return ®istrationInfo, nil } // Create MEC AMS subscription // CreateAMSSubscription creates a MEC Application Mobility Service (AMS) subscription // // This function creates a subscription for mobility procedure notifications. // The subscription allows the application to receive notifications when mobility // events occur, such as when the application instance moves to a different MEC host. // // Reference: ETSI GS MEC 021 - Application Mobility Service API // // @param url The URL endpoint for AMS subscription (e.g., /amsi/v1/subscriptions) // @param app_instance_id The MEC Application Instance ID to subscribe to // @param callbackURL The callback URL where mobility notifications will be sent // @param associateId Optional associate ID (e.g., UE IP address) for filtering notifications // @return *model.InlineSubscription The subscription information returned by the MEC platform // @return error Returns nil on success, or an error if the subscription creation fails func CreateAMSSubscription(url string, app_instance_id string, callbackURL string, associateId *model.AssociateId) (*model.InlineSubscription, error) { payload := &model.InlineSubscription{} if associateId != nil { Loading Loading @@ -85,7 +109,18 @@ func CreateAMSSubscription(url string, app_instance_id string, callbackURL strin return &subscriptionInfo, nil } // AMSNotificationHandler handles incoming AMS notifications // AMSNotificationHandler handles incoming AMS mobility procedure notifications // // This HTTP handler processes POST requests containing AMS notifications. // It extracts the target application instance ID from the notification payload, // which indicates that the application should migrate to a new MEC host. // // Reference: ETSI GS MEC 021 - Application Mobility Service API // // @param w HTTP response writer // @param r HTTP request containing the AMS notification // @return string The target application instance ID extracted from the notification // @return error Returns nil on success, or an error if the notification cannot be processed func AMSNotificationHandler(w http.ResponseWriter, r *http.Request) (string, error) { if r.Method != http.MethodPost { http.Error(w, "Invalid request method", http.StatusMethodNotAllowed) Loading Loading @@ -114,6 +149,26 @@ func AMSNotificationHandler(w http.ResponseWriter, r *http.Request) (string, err return targetAppInstanceID, nil } // RegistrationAndSubscriptionHandler creates AMS registrations and subscriptions for multiple app instances // // This function iterates through matching application instances and creates: // - AMS registration for each app instance (with device info for the first instance) // - AMS subscription for each app instance to receive mobility notifications // // It collects platform information (AMS service ID, subscription ID, node name) for each // app instance and returns it in a structured format. // // Reference: ETSI GS MEC 021 - Application Mobility Service API // // @param matchingAppInstances Array of matching MEC Application Instance IDs // @param platformURL Base URL of the MEC platform // @param sandbox_name Name of the MEC sandbox // @param callbackURL URL where AMS notifications will be sent // @param currentAppInstanceId Pointer to store the current app instance ID (first instance) // @param deviceInfo Device information for registration (used for first instance) // @param associateId Associate ID for subscription filtering (used for first instance) // @return []map[string]model.PlatformInfo Array of platform information maps keyed by app instance ID // @return error Returns nil on success, or an error if registration/subscription fails func RegistrationAndSubscriptionHandler(matchingAppInstances []model.AppInstanceID, platformURL string, sandbox_name string, callbackURL string, currentAppInstanceId *string, deviceInfo *model.RegistrationInfoDeviceInformation, associateId *model.AssociateId) ([]map[string]model.PlatformInfo, error) { Loading Loading @@ -180,7 +235,20 @@ func RegistrationAndSubscriptionHandler(matchingAppInstances []model.AppInstance return platformDetails, nil } // TODO: Complete the function to update AMS registration info // PutAMSRegistrationInfo updates AMS registration information for mobility handover // // This function updates the AMS registration for both the current and target application // instances during a mobility handover procedure. It updates the context transfer state // to reflect the mobility status. // // Reference: ETSI GS MEC 021 - Application Mobility Service API // // @param url The base URL endpoint for AMS registration updates // @param targetappinstance The target application instance ID for the handover // @param platformDetails Array of platform information maps containing AMS service IDs // @param current_app_instance Pointer to the current application instance ID // @param associateID Associate ID (e.g., UE IP address) for the registration // @return error Returns nil on success, or an error if the update fails func PutAMSRegistrationInfo(url string, targetappinstance string, platformDetails []map[string]model.PlatformInfo, current_app_instance *string, associateID *model.AssociateId) error { if len(platformDetails) == 0 { Loading Loading @@ -258,6 +326,21 @@ func PutAMSRegistrationInfo(url string, targetappinstance string, platformDetail return nil } // PUTAMSSubscriptionInfo updates AMS subscription information for mobility handover // // This function updates the AMS subscription for both the current and target application // instances during a mobility handover. It updates the mobility status filter criteria // to reflect the current state of the handover procedure. // // Reference: ETSI GS MEC 021 - Application Mobility Service API // // @param url The base URL endpoint for AMS subscription updates // @param targetappinstance The target application instance ID for the handover // @param platformDetails Array of platform information maps containing subscription IDs // @param current_app_instance Pointer to the current application instance ID // @param call_back_url The callback URL for receiving mobility notifications // @param associateid Associate ID (e.g., UE IP address) for subscription filtering // @return error Returns nil on success, or an error if the update fails func PUTAMSSubscriptionInfo(url string, targetappinstance string, platformDetails []map[string]model.PlatformInfo, current_app_instance *string, call_back_url string, associateid *model.AssociateId) error { if len(platformDetails) == 0 { Loading
examples/demo10/MEC/iot_api.go +14 −4 Original line number Diff line number Diff line package mec import ( utils "demo10/utils" "encoding/json" utils "estimed_demo/utils" "fmt" "net/http" ) // Fetch for platform info // GETIotPlatformInfo retrieves IoT platform information from the MEC platform // // This function queries the MEC platform's IoT API to obtain information about // registered IoT platforms, including their endpoints and connection details. // // Reference: ETSI GS MEC 040 - MEC IoT API // // @param url The URL endpoint for querying registered IoT platforms // (e.g., /iots/v1/registered_iot_platforms) // @return []map[string]interface{} Array of IoT platform information maps // @return error Returns nil on success, or an error if the request fails func GETIotPlatformInfo(url string) ([]map[string]interface{}, error) { resp, err := utils.SendMECRequest("GET", url, nil) if err != nil { Loading
examples/demo10/MEC/match_for_target_app_instance.go +10 −2 Original line number Diff line number Diff line package mec import ( model "estimed_demo/Model" model "demo10/Model" "fmt" "regexp" ) // Match for target App Instance ID // MatchForTargetAppInstance matches application instances by CSE name using regex // // This function filters the list of all application instances to find those // whose names match the provided CSE name pattern using regular expression matching. // // @param allAppInstances Array of all available MEC Application Instance IDs // @param cse_name The CSE name pattern (regex) to match against // @return []model.AppInstanceID Array of matching application instances // @return error Returns nil on success, or an error if no matches are found or regex is invalid func MatchForTargetAppInstance(allAppInstances []model.AppInstanceID, cse_name string) ([]model.AppInstanceID, error) { // Compile regex for cse_name once reCSE, err := regexp.Compile(cse_name) Loading