From b45f0cac02954f73cb5b6718232c81451e09effa Mon Sep 17 00:00:00 2001 From: Yann Garcia Date: Thu, 7 Nov 2024 09:35:26 +0000 Subject: [PATCH] Add GET services for CAPIF --- examples/demo6/golang/app_instance.yaml | 4 +- examples/demo6/golang/main.go | 203 +++++++++++++++++++++++- examples/demo6/golang/routers.go | 6 + 3 files changed, 207 insertions(+), 6 deletions(-) diff --git a/examples/demo6/golang/app_instance.yaml b/examples/demo6/golang/app_instance.yaml index 53b978e9e..d71965f94 100644 --- a/examples/demo6/golang/app_instance.yaml +++ b/examples/demo6/golang/app_instance.yaml @@ -13,6 +13,6 @@ localurl: 'http://' # Set host port number of demo-6. Example field: '8093' port: '80' # Callback base URL -callbackUrl: 'http://mec-platform2.etsi.org' +callbackUrl: 'http://lab-oai.etsi.org' # Callback port for listener -callbackPort: '31111' +callbackPort: '80' diff --git a/examples/demo6/golang/main.go b/examples/demo6/golang/main.go index b7e04c27e..e7d5c7281 100644 --- a/examples/demo6/golang/main.go +++ b/examples/demo6/golang/main.go @@ -324,6 +324,13 @@ const ( MEC040_FED_SUB_POST = "3" MEC040_FED_SUB_GET = "4" MEC040_FED_SUB_DEL = "5" + CAPIF_GET_ALL_SVCS = "10" + CAPIF_GET_SVC = "11" + CAPIF_CREATE_SVC = "12" + CAPIF_DELETE_SVC = "13" + CAPIF_SUB_POST = "14" + CAPIF_SUB_GET = "15" + CAPIF_SUB_DELETE = "16" STATUS = "T" QUIT = "q" ) @@ -349,15 +356,17 @@ func menu(message string) []string { "MEC 011 Service Management:\n"+ "\t%s: Create new service, %s: Delete service, %s: Get list of MEC services\n"+ "MEC 013:\n"+ - "\t%s : Get UE location', %s : UE location subscription, %s : UE location subscription\n"+ + "\t%s : Get UE location, %s : UE location subscription, %s : UE location subscription\n"+ "MEC 030:\n"+ - "\t%s: Get V2X UU unicast setting', %s: V2X Msg subscription, %s : Delete V2X subscription, %s <[latitudes] [longitudes] [timestamps]: Provide PredictedQoS\n"+ + "\t%s: Get V2X UU unicast setting, %s: V2X Msg subscription, %s : Delete V2X subscription, %s <[latitudes] [longitudes] [timestamps]: Provide PredictedQoS\n"+ "\t\t[latitudes] is a set of latitudes separated by comma, [longitudes] is a set of longitudes separated by comma, [timestamps]\n"+ "\t\tE.g. 43.729416,43.732456 7.414853,7.418417 1653295620,1653299220\n"+ "MEC 040:\n"+ - "\t%s: Get Federation Systems list', %s : Get Federation Services list, %s : Get Federation Service, %s: Subscribe, %s []: Get subscription, %s : Delete subscription\n"+ + "\t%s: Get Federation Systems list, %s : Get Federation Services list, %s : Get Federation Service, %s: Subscribe, %s []: Get subscription, %s : Delete subscription\n"+ + "MEC CAPIF:\n"+ + "\t%s: Get all services, %s: Get service for the current application instance\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, STATUS, MEC011_CONFIRM_READY, MEC011_REGISTRATION, MEC011_DEREGISTRATION, MEC011_CREATE_SVC, MEC011_DELETE_SVC, MEC011_GET_SVC, MEC013_UE_LOC, MEC013_UE_LOC_SUB, MEC013_UE_LOC_DEL_SUB, MEC030_UU_SETTINGS, MEC030_V2X_SUB, MEC030_V2X_DEL_SUB, MEC030_V2X_QOS, MEC040_FED_SYS_GET, MEC040_FED_SRVS_GET, MEC040_FED_SRV_GET, MEC040_FED_SUB_POST, MEC040_FED_SUB_GET, MEC040_FED_SUB_DEL, QUIT) + LOGIN, NAMESPACE, LOGOUT, LIST_SC, ACTIVATE, DEACTIVATE, SC, LIST_SERVICES, LIST_APP, CREATE_APP, DELETE_APP, LIST_UES, INC_UE, DEC_UE, STATUS, MEC011_CONFIRM_READY, MEC011_REGISTRATION, MEC011_DEREGISTRATION, MEC011_CREATE_SVC, MEC011_DELETE_SVC, MEC011_GET_SVC, MEC013_UE_LOC, MEC013_UE_LOC_SUB, MEC013_UE_LOC_DEL_SUB, MEC030_UU_SETTINGS, MEC030_V2X_SUB, MEC030_V2X_DEL_SUB, MEC030_V2X_QOS, MEC040_FED_SYS_GET, MEC040_FED_SRVS_GET, MEC040_FED_SRV_GET, MEC040_FED_SUB_POST, MEC040_FED_SUB_GET, MEC040_FED_SUB_DEL, CAPIF_GET_ALL_SVCS, CAPIF_GET_SVC, QUIT) if message != "" { fmt.Println("Last message: ", message) } @@ -1481,6 +1490,139 @@ func mec40_delete_subscriptions(choice string) (response *http.Response, err err return response, nil } +func capif_get_all_svcs() (body []byte, response *http.Response, err error) { + fmt.Println(">>> capif_get_all_svcs") + + // Sanity checks + if sandboxName == "" { + return nil, nil, errors.New("No sandbox available") + } else if scenarioId == -1 { + return nil, nil, errors.New("No network scenario available") + } + + // Set URL + url := mecUrl + "/" + sandboxName + "/" + mecPlateform + "/service-apis/v1/allServiceAPIs" + fmt.Println("capif_get_all_svcs: 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 + } + defer response.Body.Close() + + return body, response, nil +} + +func capif_get_svc() (body []byte, response *http.Response, err error) { + fmt.Println(">>> capif_get_svc") + + // Sanity checks + if sandboxName == "" { + return nil, nil, errors.New("No sandbox available") + } else if scenarioId == -1 { + return nil, nil, errors.New("No network scenario available") + } else if appsInfo.Id == "" { + return nil, nil, errors.New("No appInstanceId available") + } + + // Set URL + url := mecUrl + "/" + sandboxName + "/" + mecPlateform + "/published-apis/v1/" + appsInfo.Id + "/service-apis" + fmt.Println("capif_get_svc: 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 + } + defer response.Body.Close() + + return body, response, nil +} + +func capif_create_svc() (body []byte, response *http.Response, err error) { + fmt.Println(">>> capif_create_svc") + + // Sanity checks + if sandboxName == "" { + return nil, nil, errors.New("No sandbox available") + } else if scenarioId == -1 { + return nil, nil, errors.New("No network scenario available") + } else if appsInfo.Id == "" { + return nil, nil, errors.New("No network scenario available") + } + + return nil, nil, errors.New("Not implemented") +} + +func capif_delete_svc(choice string) (response *http.Response, err error) { + fmt.Println(">>> capif_delete_svc: ", choice) + + // Sanity checks + if sandboxName == "" { + return nil, errors.New("No sandbox available") + } else if scenarioId == -1 { + return nil, errors.New("No network scenario available") + } else if appsInfo.Id == "" { + return nil, errors.New("No appInstanceId available") + } + if choice == "" { + return nil, errors.New("Wrong parameter") + } + + return nil, errors.New("Not implemented") +} + +func capif_create_subscription() (body []byte, response *http.Response, err error) { + fmt.Println(">>> capif_create_subscription") + + // Sanity checks + if sandboxName == "" { + return nil, nil, errors.New("No sandbox available") + } else if scenarioId == -1 { + return nil, nil, errors.New("No network scenario available") + } else if appsInfo.Id == "" { + return nil, nil, errors.New("No network scenario available") + } + + // Set URL + url := mecUrl + "/" + sandboxName + "/" + mecPlateform + "/service-apis/v1/" + appsInfo.Id + "/subscriptions" + fmt.Println("capif_create_subscription: url: " + url) + + return nil, nil, errors.New("Not implemented") +} + +func capif_get_subscriptions() (body []byte, response *http.Response, err error) { + fmt.Println(">>> capif_get_subscriptions") + + // Sanity checks + if sandboxName == "" { + return nil, nil, errors.New("No sandbox available") + } else if scenarioId == -1 { + return nil, nil, errors.New("No network scenario available") + } else if appsInfo.Id == "" { + return nil, nil, errors.New("No appInstanceId available") + } + + return nil, nil, errors.New("Not implemented") +} + +func capif_delete_subscriptions(choice string) (response *http.Response, err error) { + fmt.Println(">>> capif_delete_subscriptions: ", choice) + + // Sanity checks + if sandboxName == "" { + return nil, errors.New("No sandbox available") + } else if scenarioId == -1 { + return nil, errors.New("No network scenario available") + } else if appsInfo.Id == "" { + return nil, errors.New("No appInstanceId available") + } + if choice == "" { + return nil, errors.New("Wrong parameter") + } + + return nil, errors.New("Not implemented") +} + func app_status() (resp string) { resp = "" if sandboxName != "" { @@ -1565,6 +1707,11 @@ func fed_notification(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) } +func capif_notification(w http.ResponseWriter, r *http.Request) { + fmt.Println(">>> capif_notification: ", r) + w.WriteHeader(http.StatusOK) +} + func mec011_service_statistic_get(w http.ResponseWriter, r *http.Request) { fmt.Println(">>> mec011_service_statistic_get: ", r) w.WriteHeader(http.StatusOK) @@ -1980,6 +2127,54 @@ func process_choice(choice []string) string { return err.Error() } message = fmt.Sprintf("response: %s", response.Status) + } else if strings.Compare(choice[0], CAPIF_GET_ALL_SVCS) == 0 { + body, _, err := capif_get_all_svcs() + if err != nil { + return err.Error() + } + message = fmt.Sprintf("response: %s", string(body)) + } else if strings.Compare(choice[0], CAPIF_GET_SVC) == 0 { + body, _, err := capif_get_svc() + if err != nil { + return err.Error() + } + message = fmt.Sprintf("response: %s", string(body)) + } else if strings.Compare(choice[0], CAPIF_CREATE_SVC) == 0 { + body, _, err := capif_create_svc() + if err != nil { + return err.Error() + } + message = fmt.Sprintf("response: %s", string(body)) + } else if strings.Compare(choice[0], CAPIF_DELETE_SVC) == 0 { + if len(choice) == 1 { + return "apiId is not set" + } + response, err := capif_delete_svc(choice[1]) + if err != nil { + return err.Error() + } + message = fmt.Sprintf("response: %s", response.Status) + } else if strings.Compare(choice[0], CAPIF_SUB_POST) == 0 { + body, _, err := capif_create_subscription() + if err != nil { + return err.Error() + } + message = fmt.Sprintf("response body: %s", string(body)) + } else if strings.Compare(choice[0], CAPIF_SUB_GET) == 0 { + body, _, err := capif_get_subscriptions() + if err != nil { + return err.Error() + } + message = fmt.Sprintf("response body: %s", string(body)) + } else if strings.Compare(choice[0], CAPIF_SUB_DELETE) == 0 { + if len(choice) == 1 { + return "Subscription ID is not set" + } + response, err := capif_delete_subscriptions(choice[1]) + if err != nil { + return err.Error() + } + message = fmt.Sprintf("response: %s", response.Status) } else if strings.Compare(choice[0], STATUS) == 0 { resp := app_status() message = fmt.Sprintf("Current status: %s", resp) diff --git a/examples/demo6/golang/routers.go b/examples/demo6/golang/routers.go index 94ce07834..40a3e30ac 100644 --- a/examples/demo6/golang/routers.go +++ b/examples/demo6/golang/routers.go @@ -83,6 +83,12 @@ var routes = HttpRoutes{ "/fed/v1/notification", fed_notification, }, + HttpRoute{ + "capif_notification", + "POST", + "/mec_capif_mgmt/v1/notification", + capif_notification, + }, HttpRoute{ "mec011_service_statistic_get", "GET", -- GitLab