From 8f668bb5b9c4e6083823f335b1cc5c038bd98eee Mon Sep 17 00:00:00 2001 From: ubuntu Date: Wed, 29 May 2024 07:24:27 +0000 Subject: [PATCH] delete: remove legacy code --- .../api_create_ee_subscription.go | 75 - .../api_delete_ee_subscription.go | 28 - .../api_update_ee_subscription.go | 76 - internal/sbi/eventexposure/routers.go | 106 -- .../data_change_notification_to_nf.go | 61 - internal/sbi/httpcallback/router.go | 81 - .../api_subscription_data_update.go | 73 - .../api_subscription_data_update_test.go | 76 - internal/sbi/parameterprovision/routers.go | 91 - .../sbi/processor/ue_context_management.go | 5 +- internal/sbi/producer/callback.go | 29 - internal/sbi/producer/callback/callback.go | 97 -- internal/sbi/producer/event_exposure.go | 234 --- internal/sbi/producer/generate_auth_data.go | 591 ------- internal/sbi/producer/parameter_provision.go | 56 - .../producer/subscriber_data_management.go | 1543 ----------------- .../sbi/producer/ue_context_management.go | 742 -------- ...nd_mobility_subscription_data_retrieval.go | 45 - .../api_gpsi_to_supi_translation.go | 44 - ..._acknowledgement_of_steering_of_roaming.go | 21 - ...acknowledgement_of_ue_parameters_update.go | 21 - .../api_retrieval_of_multiple_data_sets.go | 45 - .../api_retrieval_of_shared_data.go | 45 - ..._management_subscription_data_retrieval.go | 47 - ...e_selection_subscription_data_retrieval.go | 45 - ...f_selection_subscription_data_retrieval.go | 44 - ..._management_subscription_data_retrieval.go | 21 - .../api_sms_subscription_data_retrieval.go | 21 - .../api_subscription_creation.go | 76 - ...i_subscription_creation_for_shared_data.go | 73 - .../api_subscription_deletion.go | 47 - ...i_subscription_deletion_for_shared_data.go | 42 - .../api_subscription_modification.go | 123 -- .../api_trace_configuration_data_retrieval.go | 44 - .../api_ue_context_in_smf_data_retrieval.go | 44 - .../api_ue_context_in_smsf_data_retrieval.go | 21 - .../sbi/subscriberdatamanagement/routers.go | 458 ----- .../sbi/ueauthentication/api_confirm_auth.go | 72 - .../api_generate_auth_data.go | 73 - internal/sbi/ueauthentication/routers.go | 123 -- ..._gpp_access_registration_info_retrieval.go | 44 - ..._gpp_access_registration_info_retrieval.go | 44 - .../api_amf_registration_for3_gpp_access.go | 76 - ...pi_amf_registration_for_non3_gpp_access.go | 76 - ...in_the_amf_registration_for3_gpp_access.go | 73 - ...he_amf_registration_for_non3_gpp_access.go | 72 - .../api_smf_deregistration.go | 44 - .../api_smf_registration.go | 76 - ..._gpp_access_registration_info_retrieval.go | 21 - ...api_smsf_deregistration_for3_gpp_access.go | 21 - ...smsf_deregistration_for_non3_gpp_access.go | 21 - ..._gpp_access_registration_info_retrieval.go | 21 - .../api_smsf_registration_for3_gpp_access.go | 21 - ...i_smsf_registration_for_non3_gpp_access.go | 21 - internal/sbi/uecontextmanagement/routers.go | 183 -- 55 files changed, 2 insertions(+), 6371 deletions(-) delete mode 100644 internal/sbi/eventexposure/api_create_ee_subscription.go delete mode 100644 internal/sbi/eventexposure/api_delete_ee_subscription.go delete mode 100644 internal/sbi/eventexposure/api_update_ee_subscription.go delete mode 100644 internal/sbi/eventexposure/routers.go delete mode 100644 internal/sbi/httpcallback/data_change_notification_to_nf.go delete mode 100644 internal/sbi/httpcallback/router.go delete mode 100644 internal/sbi/parameterprovision/api_subscription_data_update.go delete mode 100644 internal/sbi/parameterprovision/api_subscription_data_update_test.go delete mode 100644 internal/sbi/parameterprovision/routers.go delete mode 100644 internal/sbi/producer/callback.go delete mode 100644 internal/sbi/producer/callback/callback.go delete mode 100644 internal/sbi/producer/event_exposure.go delete mode 100644 internal/sbi/producer/generate_auth_data.go delete mode 100644 internal/sbi/producer/parameter_provision.go delete mode 100644 internal/sbi/producer/subscriber_data_management.go delete mode 100644 internal/sbi/producer/ue_context_management.go delete mode 100644 internal/sbi/subscriberdatamanagement/api_access_and_mobility_subscription_data_retrieval.go delete mode 100644 internal/sbi/subscriberdatamanagement/api_gpsi_to_supi_translation.go delete mode 100644 internal/sbi/subscriberdatamanagement/api_providing_acknowledgement_of_steering_of_roaming.go delete mode 100644 internal/sbi/subscriberdatamanagement/api_providing_acknowledgement_of_ue_parameters_update.go delete mode 100644 internal/sbi/subscriberdatamanagement/api_retrieval_of_multiple_data_sets.go delete mode 100644 internal/sbi/subscriberdatamanagement/api_retrieval_of_shared_data.go delete mode 100644 internal/sbi/subscriberdatamanagement/api_session_management_subscription_data_retrieval.go delete mode 100644 internal/sbi/subscriberdatamanagement/api_slice_selection_subscription_data_retrieval.go delete mode 100644 internal/sbi/subscriberdatamanagement/api_smf_selection_subscription_data_retrieval.go delete mode 100644 internal/sbi/subscriberdatamanagement/api_sms_management_subscription_data_retrieval.go delete mode 100644 internal/sbi/subscriberdatamanagement/api_sms_subscription_data_retrieval.go delete mode 100644 internal/sbi/subscriberdatamanagement/api_subscription_creation.go delete mode 100644 internal/sbi/subscriberdatamanagement/api_subscription_creation_for_shared_data.go delete mode 100644 internal/sbi/subscriberdatamanagement/api_subscription_deletion.go delete mode 100644 internal/sbi/subscriberdatamanagement/api_subscription_deletion_for_shared_data.go delete mode 100644 internal/sbi/subscriberdatamanagement/api_subscription_modification.go delete mode 100644 internal/sbi/subscriberdatamanagement/api_trace_configuration_data_retrieval.go delete mode 100644 internal/sbi/subscriberdatamanagement/api_ue_context_in_smf_data_retrieval.go delete mode 100644 internal/sbi/subscriberdatamanagement/api_ue_context_in_smsf_data_retrieval.go delete mode 100644 internal/sbi/subscriberdatamanagement/routers.go delete mode 100644 internal/sbi/ueauthentication/api_confirm_auth.go delete mode 100644 internal/sbi/ueauthentication/api_generate_auth_data.go delete mode 100644 internal/sbi/ueauthentication/routers.go delete mode 100644 internal/sbi/uecontextmanagement/api_amf3_gpp_access_registration_info_retrieval.go delete mode 100644 internal/sbi/uecontextmanagement/api_amf_non3_gpp_access_registration_info_retrieval.go delete mode 100644 internal/sbi/uecontextmanagement/api_amf_registration_for3_gpp_access.go delete mode 100644 internal/sbi/uecontextmanagement/api_amf_registration_for_non3_gpp_access.go delete mode 100644 internal/sbi/uecontextmanagement/api_parameter_update_in_the_amf_registration_for3_gpp_access.go delete mode 100644 internal/sbi/uecontextmanagement/api_parameter_update_in_the_amf_registration_for_non3_gpp_access.go delete mode 100644 internal/sbi/uecontextmanagement/api_smf_deregistration.go delete mode 100644 internal/sbi/uecontextmanagement/api_smf_registration.go delete mode 100644 internal/sbi/uecontextmanagement/api_smsf3_gpp_access_registration_info_retrieval.go delete mode 100644 internal/sbi/uecontextmanagement/api_smsf_deregistration_for3_gpp_access.go delete mode 100644 internal/sbi/uecontextmanagement/api_smsf_deregistration_for_non3_gpp_access.go delete mode 100644 internal/sbi/uecontextmanagement/api_smsf_non3_gpp_access_registration_info_retrieval.go delete mode 100644 internal/sbi/uecontextmanagement/api_smsf_registration_for3_gpp_access.go delete mode 100644 internal/sbi/uecontextmanagement/api_smsf_registration_for_non3_gpp_access.go delete mode 100644 internal/sbi/uecontextmanagement/routers.go diff --git a/internal/sbi/eventexposure/api_create_ee_subscription.go b/internal/sbi/eventexposure/api_create_ee_subscription.go deleted file mode 100644 index 2e11a38..0000000 --- a/internal/sbi/eventexposure/api_create_ee_subscription.go +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Nudm_EE - * - * Nudm Event Exposure Service - * - * API version: 1.0.1 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package eventexposure - -import ( - "net/http" - - "github.com/gin-gonic/gin" - - "github.com/free5gc/openapi" - "github.com/free5gc/openapi/models" - "github.com/free5gc/udm/internal/logger" - "github.com/free5gc/udm/internal/sbi/producer" -) - -// HTTPCreateEeSubscription - Subscribe -func HTTPCreateEeSubscription(c *gin.Context) { - var eesubscription models.EeSubscription - - requestBody, err := c.GetRawData() - if err != nil { - logger.EeLog.Errorf("Get Request Body error: %+v", err) - problemDetail := models.ProblemDetails{ - Title: "System failure", - Status: http.StatusInternalServerError, - Detail: err.Error(), - Cause: "SYSTEM_FAILURE", - } - c.JSON(http.StatusInternalServerError, problemDetail) - return - } - - // err = openapi.Deserialize(&eeSubscription, requestBody, "application/json") - err = openapi.Deserialize(nil, requestBody, "application/json") - if err != nil { - problemDetail := "[Request Body] " + err.Error() - rsp := models.ProblemDetails{ - Title: "Malformed request syntax", - Status: http.StatusBadRequest, - Detail: problemDetail, - } - logger.EeLog.Errorln(problemDetail) - c.JSON(http.StatusBadRequest, rsp) - return - } - - // Start - logger.EeLog.Infoln("Handle Create EE Subscription") - - ueIdentity := c.Params.ByName("ueIdentity") - - createdEESubscription, problemDetails := producer.CreateEeSubscriptionProcedure(ueIdentity, eesubscription) - - if createdEESubscription != nil { - c.JSON(http.StatusCreated, createdEESubscription) - return - } else if problemDetails != nil { - c.JSON(int(problemDetails.Status), problemDetails) - return - } else { - problemDetails = &models.ProblemDetails{ - Status: http.StatusInternalServerError, - Cause: "UNSPECIFIED_NF_FAILURE", - } - c.JSON(http.StatusInternalServerError, problemDetails) - return - } -} diff --git a/internal/sbi/eventexposure/api_delete_ee_subscription.go b/internal/sbi/eventexposure/api_delete_ee_subscription.go deleted file mode 100644 index 8b7343e..0000000 --- a/internal/sbi/eventexposure/api_delete_ee_subscription.go +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Nudm_EE - * - * Nudm Event Exposure Service - * - * API version: 1.0.1 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package eventexposure - -import ( - "github.com/gin-gonic/gin" - - "github.com/free5gc/udm/internal/sbi/producer" - "github.com/free5gc/util/httpwrapper" -) - -// DeleteEeSubscription - Unsubscribe -func HTTPDeleteEeSubscription(c *gin.Context) { - req := httpwrapper.NewRequest(c.Request, nil) - req.Params["ueIdentity"] = c.Params.ByName("ueIdentity") - req.Params["subscriptionID"] = c.Params.ByName("subscriptionId") - - rsp := producer.HandleDeleteEeSubscription(req) - // only return 204 no content - c.Status(rsp.Status) -} diff --git a/internal/sbi/eventexposure/api_update_ee_subscription.go b/internal/sbi/eventexposure/api_update_ee_subscription.go deleted file mode 100644 index f310ce2..0000000 --- a/internal/sbi/eventexposure/api_update_ee_subscription.go +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Nudm_EE - * - * Nudm Event Exposure Service - * - * API version: 1.0.1 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package eventexposure - -import ( - "net/http" - - "github.com/gin-gonic/gin" - - "github.com/free5gc/openapi" - "github.com/free5gc/openapi/models" - "github.com/free5gc/udm/internal/logger" - "github.com/free5gc/udm/internal/sbi/producer" - "github.com/free5gc/util/httpwrapper" -) - -// UpdateEeSubscription - Patch -func HTTPUpdateEeSubscription(c *gin.Context) { - var patchList []models.PatchItem - - requestBody, err := c.GetRawData() - if err != nil { - logger.EeLog.Errorf("Get Request Body error: %+v", err) - problemDetail := models.ProblemDetails{ - Title: "System failure", - Status: http.StatusInternalServerError, - Detail: err.Error(), - Cause: "SYSTEM_FAILURE", - } - c.JSON(http.StatusInternalServerError, problemDetail) - return - } - - err = openapi.Deserialize(&patchList, requestBody, "application/json") - if err != nil { - problemDetail := "[Request Body] " + err.Error() - rsp := models.ProblemDetails{ - Title: "Malformed request syntax", - Status: http.StatusBadRequest, - Detail: problemDetail, - } - logger.EeLog.Errorln(problemDetail) - c.JSON(http.StatusBadRequest, rsp) - return - } - - req := httpwrapper.NewRequest(c.Request, patchList) - req.Params["ueIdentity"] = c.Params.ByName("ueIdentity") - req.Params["subscriptionID"] = c.Params.ByName("subscriptionId") - - rsp := producer.HandleUpdateEeSubscription(req) - - if rsp.Status == http.StatusNoContent { - c.Status(rsp.Status) - } else { - responseBody, err := openapi.Serialize(rsp.Body, "application/json") - if err != nil { - logger.EeLog.Errorln(err) - problemDetails := models.ProblemDetails{ - Status: http.StatusInternalServerError, - Cause: "SYSTEM_FAILURE", - Detail: err.Error(), - } - c.JSON(http.StatusInternalServerError, problemDetails) - } else { - c.Data(rsp.Status, "application/json", responseBody) - } - } -} diff --git a/internal/sbi/eventexposure/routers.go b/internal/sbi/eventexposure/routers.go deleted file mode 100644 index a6f7400..0000000 --- a/internal/sbi/eventexposure/routers.go +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Nudm_EE - * - * Nudm Event Exposure Service - * - * API version: 1.0.1 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package eventexposure - -import ( - "net/http" - "strings" - - "github.com/gin-gonic/gin" - - "github.com/free5gc/openapi/models" - udm_context "github.com/free5gc/udm/internal/context" - "github.com/free5gc/udm/internal/logger" - "github.com/free5gc/udm/internal/util" - "github.com/free5gc/udm/pkg/factory" - logger_util "github.com/free5gc/util/logger" -) - -// Route is the information for every URI. -type Route struct { - // Name is the name of this Route. - Name string - // Method is the string for the HTTP method. ex) GET, POST etc.. - Method string - // Pattern is the pattern of the URI. - Pattern string - // HandlerFunc is the handler function of this route. - HandlerFunc gin.HandlerFunc -} - -// Routes is the list of the generated Route. -type Routes []Route - -// NewRouter returns a new router. -func NewRouter() *gin.Engine { - router := logger_util.NewGinWithLogrus(logger.GinLog) - - AddService(router) - return router -} - -func AddService(engine *gin.Engine) *gin.RouterGroup { - group := engine.Group(factory.UdmEeResUriPrefix) - - routerAuthorizationCheck := util.NewRouterAuthorizationCheck(models.ServiceName_NUDM_EE) - group.Use(func(c *gin.Context) { - routerAuthorizationCheck.Check(c, udm_context.GetSelf()) - }) - for _, route := range routes { - switch route.Method { - case "GET": - group.GET(route.Pattern, route.HandlerFunc) - case "POST": - group.POST(route.Pattern, route.HandlerFunc) - case "PUT": - group.PUT(route.Pattern, route.HandlerFunc) - case "DELETE": - group.DELETE(route.Pattern, route.HandlerFunc) - case "PATCH": - group.PATCH(route.Pattern, route.HandlerFunc) - } - } - return group -} - -// Index is the index handler. -func Index(c *gin.Context) { - c.String(http.StatusOK, "Hello World!") -} - -var routes = Routes{ - { - "Index", - "GET", - "/", - Index, - }, - - { - "HTTPCreateEeSubscription", - strings.ToUpper("Post"), - "/:ueIdentity/ee-subscriptions", - HTTPCreateEeSubscription, - }, - - { - "HTTPDeleteEeSubscription", - strings.ToUpper("Delete"), - "/:ueIdentity/ee-subscriptions/:subscriptionId", - HTTPDeleteEeSubscription, - }, - - { - "HTTPUpdateEeSubscription", - strings.ToUpper("Patch"), - "/:ueIdentity/ee-subscriptions/:subscriptionId", - HTTPUpdateEeSubscription, - }, -} diff --git a/internal/sbi/httpcallback/data_change_notification_to_nf.go b/internal/sbi/httpcallback/data_change_notification_to_nf.go deleted file mode 100644 index dfc6be4..0000000 --- a/internal/sbi/httpcallback/data_change_notification_to_nf.go +++ /dev/null @@ -1,61 +0,0 @@ -package httpcallback - -import ( - "net/http" - - "github.com/gin-gonic/gin" - - "github.com/free5gc/openapi" - "github.com/free5gc/openapi/models" - "github.com/free5gc/udm/internal/logger" - "github.com/free5gc/udm/internal/sbi/producer" - "github.com/free5gc/util/httpwrapper" -) - -func HTTPDataChangeNotificationToNF(c *gin.Context) { - var dataChangeNotify models.DataChangeNotify - // step 1: retrieve http request body - requestBody, err := c.GetRawData() - if err != nil { - problemDetail := models.ProblemDetails{ - Title: "System failure", - Status: http.StatusInternalServerError, - Detail: err.Error(), - Cause: "SYSTEM_FAILURE", - } - logger.CallbackLog.Errorf("Get Request Body error: %+v", err) - c.JSON(http.StatusInternalServerError, problemDetail) - return - } - - // step 2: convert requestBody to openapi models - err = openapi.Deserialize(&dataChangeNotify, requestBody, "application/json") - if err != nil { - problemDetail := "[Request Body] " + err.Error() - rsp := models.ProblemDetails{ - Title: "Malformed request syntax", - Status: http.StatusBadRequest, - Detail: problemDetail, - } - logger.CallbackLog.Errorln(problemDetail) - c.JSON(http.StatusBadRequest, rsp) - return - } - - req := httpwrapper.NewRequest(c.Request, dataChangeNotify) - req.Params["supi"] = c.Params.ByName("supi") - - rsp := producer.HandleDataChangeNotificationToNFRequest(req) - responseBody, err := openapi.Serialize(rsp.Body, "application/json") - if err != nil { - logger.CallbackLog.Errorln(err) - problemDetails := models.ProblemDetails{ - Status: http.StatusInternalServerError, - Cause: "SYSTEM_FAILURE", - Detail: err.Error(), - } - c.JSON(http.StatusInternalServerError, problemDetails) - } else { - c.Data(rsp.Status, "application/json", responseBody) - } -} diff --git a/internal/sbi/httpcallback/router.go b/internal/sbi/httpcallback/router.go deleted file mode 100644 index 2d926b6..0000000 --- a/internal/sbi/httpcallback/router.go +++ /dev/null @@ -1,81 +0,0 @@ -package httpcallback - -import ( - "net/http" - "strings" - - "github.com/gin-gonic/gin" - "github.com/sirupsen/logrus" - - "github.com/free5gc/udm/internal/logger" - logger_util "github.com/free5gc/util/logger" -) - -var HttpLog *logrus.Entry - -func init() { - HttpLog = logger.HttpLog -} - -// Route is the information for every URI. -type Route struct { - // Name is the name of this Route. - Name string - // Method is the string for the HTTP method. ex) GET, POST etc.. - Method string - // Pattern is the pattern of the URI. - Pattern string - // HandlerFunc is the handler function of this route. - HandlerFunc gin.HandlerFunc -} - -// Routes is the list of the generated Route. -type Routes []Route - -// NewRouter returns a new router -func NewRouter() *gin.Engine { - router := logger_util.NewGinWithLogrus(logger.GinLog) - AddService(router) - return router -} - -func AddService(engine *gin.Engine) *gin.RouterGroup { - group := engine.Group("") - - for _, route := range routes { - switch route.Method { - case "GET": - group.GET(route.Pattern, route.HandlerFunc) - case "POST": - group.POST(route.Pattern, route.HandlerFunc) - case "PUT": - group.PUT(route.Pattern, route.HandlerFunc) - case "PATCH": - group.PATCH(route.Pattern, route.HandlerFunc) - case "DELETE": - group.DELETE(route.Pattern, route.HandlerFunc) - } - } - return group -} - -// Index is the index handler. -func Index(c *gin.Context) { - c.String(http.StatusOK, "Hello World!") -} - -var routes = Routes{ - { - "Index", - "GET", - "/", - Index, - }, - - { - "DataChangeNotificationToNF", - strings.ToUpper("Post"), - "/sdm-subscriptions", - HTTPDataChangeNotificationToNF, - }, -} diff --git a/internal/sbi/parameterprovision/api_subscription_data_update.go b/internal/sbi/parameterprovision/api_subscription_data_update.go deleted file mode 100644 index aec820c..0000000 --- a/internal/sbi/parameterprovision/api_subscription_data_update.go +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Nudm_PP - * - * Nudm Parameter Provision Service - * - * API version: 1.0.0 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package parameterprovision - -import ( - "net/http" - - "github.com/gin-gonic/gin" - - "github.com/free5gc/openapi" - "github.com/free5gc/openapi/models" - "github.com/free5gc/udm/internal/logger" - "github.com/free5gc/udm/internal/sbi/producer" - "github.com/free5gc/util/httpwrapper" -) - -// Update - provision parameters -func HTTPUpdate(c *gin.Context) { - var ppDataReq models.PpData - - // step 1: retrieve http request body - requestBody, err := c.GetRawData() - if err != nil { - problemDetail := models.ProblemDetails{ - Title: "System failure", - Status: http.StatusInternalServerError, - Detail: err.Error(), - Cause: "SYSTEM_FAILURE", - } - logger.PpLog.Errorf("Get Request Body error: %+v", err) - c.JSON(http.StatusInternalServerError, problemDetail) - return - } - - // step 2: convert requestBody to openapi models - err = openapi.Deserialize(&ppDataReq, requestBody, "application/json") - if err != nil { - problemDetail := "[Request Body] " + err.Error() - rsp := models.ProblemDetails{ - Title: "Malformed request syntax", - Status: http.StatusBadRequest, - Detail: problemDetail, - } - logger.PpLog.Errorln(problemDetail) - c.JSON(http.StatusBadRequest, rsp) - return - } - - req := httpwrapper.NewRequest(c.Request, ppDataReq) - req.Params["gspi"] = c.Params.ByName("gpsi") - - rsp := producer.HandleUpdateRequest(req) - - responseBody, err := openapi.Serialize(rsp.Body, "application/json") - if err != nil { - logger.PpLog.Errorln(err) - problemDetails := models.ProblemDetails{ - Status: http.StatusInternalServerError, - Cause: "SYSTEM_FAILURE", - Detail: err.Error(), - } - c.JSON(http.StatusInternalServerError, problemDetails) - } else { - c.Data(rsp.Status, "application/json", responseBody) - } -} diff --git a/internal/sbi/parameterprovision/api_subscription_data_update_test.go b/internal/sbi/parameterprovision/api_subscription_data_update_test.go deleted file mode 100644 index abb4fb6..0000000 --- a/internal/sbi/parameterprovision/api_subscription_data_update_test.go +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Nudm_PP - * - * Nudm Parameter Provision Service - * - * API version: 1.0.0 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package parameterprovision_test - -import ( - "testing" -) - -// Update - provision parameters -func TestUpdate(t *testing.T) { - /*go handler.Handle() - go func() { // udm server - router := gin.Default() - Nudm_PP_Server.AddService(router) - - udmLogPath := path_util.Free5gcPath("free5gc/udmsslkey.log") - udmPemPath := path_util.Free5gcPath("free5gc/support/TLS/udm.pem") - udmKeyPath := path_util.Free5gcPath("free5gc/support/TLS/udm.key") - server, err := http2_util.NewServer(":29503", udmLogPath, router) - if err == nil && server != nil { - logger.InitLog.Infoln(server.ListenAndServeTLS(udmPemPath, udmKeyPath)) - assert.True(t, err == nil) - } - }() - - go func() { // fake udr server - router := gin.Default() - - router.PATCH("/nudr-dr/v1/:gpsi/pp-data", func(c *gin.Context) { - gpsi := c.Param("gpsi") - fmt.Println("==========CreateEeSubscription - Subscribe==========") - fmt.Println("ueIdentity: ", gpsi) - var testppData models.PpData - if err := c.ShouldBindJSON(&testppData); err != nil { - fmt.Println("fake udm server error: ", err.Error()) - c.JSON(http.StatusInternalServerError, gin.H{}) - return - } - fmt.Println("patchItems: ", testppData) - c.JSON(http.StatusCreated, gin.H{}) - }) - - udrLogPath := path_util.Free5gcPath("free5gc/udrsslkey.log") - udrPemPath := path_util.Free5gcPath("free5gc/support/TLS/udr.pem") - udrKeyPath := path_util.Free5gcPath("free5gc/support/TLS/udr.key") - - server, err := http2_util.NewServer(":29504", udrLogPath, router) - if err == nil && server != nil { - logger.InitLog.Infoln(server.ListenAndServeTLS(udrPemPath, udrKeyPath)) - assert.True(t, err == nil) - } - }() - - udm_context.Init() - cfg := Nudm_PP_Client.NewConfiguration() - cfg.SetBasePath("https://localhost:29503") - clientAPI := Nudm_PP_Client.NewAPIClient(cfg) - - var ppData models.PpData - ppData.SupportedFeatures = "Test001" - gpsi := "SDM1234" - resp, err := clientAPI.SubscriptionDataUpdateApi.Update(context.Background(), gpsi, ppData) - if err != nil { - fmt.Println(err.Error()) - } else { - fmt.Println("resp: ", resp) - } - */ -} diff --git a/internal/sbi/parameterprovision/routers.go b/internal/sbi/parameterprovision/routers.go deleted file mode 100644 index 1066db4..0000000 --- a/internal/sbi/parameterprovision/routers.go +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Nudm_PP - * - * Nudm Parameter Provision Service - * - * API version: 1.0.0 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package parameterprovision - -import ( - "net/http" - "strings" - - "github.com/gin-gonic/gin" - - "github.com/free5gc/openapi/models" - udm_context "github.com/free5gc/udm/internal/context" - "github.com/free5gc/udm/internal/logger" - "github.com/free5gc/udm/internal/util" - "github.com/free5gc/udm/pkg/factory" - logger_util "github.com/free5gc/util/logger" -) - -// Route is the information for every URI. -type Route struct { - // Name is the name of this Route. - Name string - // Method is the string for the HTTP method. ex) GET, POST etc.. - Method string - // Pattern is the pattern of the URI. - Pattern string - // HandlerFunc is the handler function of this route. - HandlerFunc gin.HandlerFunc -} - -// Routes is the list of the generated Route. -type Routes []Route - -// NewRouter returns a new router. -func NewRouter() *gin.Engine { - router := logger_util.NewGinWithLogrus(logger.GinLog) - - AddService(router) - return router -} - -func AddService(engine *gin.Engine) *gin.RouterGroup { - group := engine.Group(factory.UdmPpResUriPrefix) - routerAuthorizationCheck := util.NewRouterAuthorizationCheck(models.ServiceName_NUDM_PP) - group.Use(func(c *gin.Context) { - routerAuthorizationCheck.Check(c, udm_context.GetSelf()) - }) - for _, route := range routes { - switch route.Method { - case "GET": - group.GET(route.Pattern, route.HandlerFunc) - case "POST": - group.POST(route.Pattern, route.HandlerFunc) - case "PUT": - group.PUT(route.Pattern, route.HandlerFunc) - case "DELETE": - group.DELETE(route.Pattern, route.HandlerFunc) - case "PATCH": - group.PATCH(route.Pattern, route.HandlerFunc) - } - } - return group -} - -// Index is the index handler. -func Index(c *gin.Context) { - c.String(http.StatusOK, "Hello World!") -} - -var routes = Routes{ - { - "Index", - "GET", - "/", - Index, - }, - - { - "Update", - strings.ToUpper("Patch"), - "/:gpsi/pp-data", - HTTPUpdate, - }, -} diff --git a/internal/sbi/processor/ue_context_management.go b/internal/sbi/processor/ue_context_management.go index 29456d6..2d4b087 100644 --- a/internal/sbi/processor/ue_context_management.go +++ b/internal/sbi/processor/ue_context_management.go @@ -11,7 +11,6 @@ import ( "github.com/free5gc/openapi/models" udm_context "github.com/free5gc/udm/internal/context" "github.com/free5gc/udm/internal/logger" - "github.com/free5gc/udm/internal/sbi/producer/callback" ) // ue_context_managemanet_service @@ -145,7 +144,7 @@ func (p *Processor) RegistrationAmf3gppAccessProcedure( go func() { logger.UecmLog.Infof("Send DeregNotify to old AMF GUAMI=%v", oldAmf3GppAccessRegContext.Guami) - pd := callback.SendOnDeregistrationNotification(ueID, + pd := p.SendOnDeregistrationNotification(ueID, oldAmf3GppAccessRegContext.DeregCallbackUri, deregistData) // Deregistration Notify Triggered if pd != nil { @@ -212,7 +211,7 @@ func (p *Processor) RegisterAmfNon3gppAccessProcedure( DeregReason: models.DeregistrationReason_UE_INITIAL_REGISTRATION, AccessType: models.AccessType_NON_3_GPP_ACCESS, } - callback.SendOnDeregistrationNotification(ueID, oldAmfNon3GppAccessRegContext.DeregCallbackUri, + p.SendOnDeregistrationNotification(ueID, oldAmfNon3GppAccessRegContext.DeregCallbackUri, deregistData) // Deregistration Notify Triggered return nil, nil, nil diff --git a/internal/sbi/producer/callback.go b/internal/sbi/producer/callback.go deleted file mode 100644 index c4c84ca..0000000 --- a/internal/sbi/producer/callback.go +++ /dev/null @@ -1,29 +0,0 @@ -package producer - -import ( - "net/http" - - "github.com/free5gc/openapi/models" - "github.com/free5gc/udm/internal/logger" - "github.com/free5gc/udm/internal/sbi/producer/callback" - "github.com/free5gc/util/httpwrapper" -) - -// HandleDataChangeNotificationToNFRequest ... Send Data Change Notification -func HandleDataChangeNotificationToNFRequest(request *httpwrapper.Request) *httpwrapper.Response { - // step 1: log - logger.CallbackLog.Infof("Handle DataChangeNotificationToNF") - - // step 2: retrieve request - dataChangeNotify := request.Body.(models.DataChangeNotify) - supi := request.Params["supi"] - - problemDetails := callback.DataChangeNotificationProcedure(dataChangeNotify.NotifyItems, supi) - - // step 4: process the return value from step 3 - if problemDetails != nil { - return httpwrapper.NewResponse(int(problemDetails.Status), nil, problemDetails) - } else { - return httpwrapper.NewResponse(http.StatusNoContent, nil, nil) - } -} diff --git a/internal/sbi/producer/callback/callback.go b/internal/sbi/producer/callback/callback.go deleted file mode 100644 index cf22d03..0000000 --- a/internal/sbi/producer/callback/callback.go +++ /dev/null @@ -1,97 +0,0 @@ -package callback - -import ( - "net/http" - - "github.com/free5gc/openapi/Nudm_SubscriberDataManagement" - "github.com/free5gc/openapi/Nudm_UEContextManagement" - "github.com/free5gc/openapi/models" - udm_context "github.com/free5gc/udm/internal/context" - "github.com/free5gc/udm/internal/logger" -) - -func DataChangeNotificationProcedure(notifyItems []models.NotifyItem, supi string) *models.ProblemDetails { - ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NUDM_SDM, models.NfType_UDM) - if err != nil { - return pd - } - - ue, _ := udm_context.GetSelf().UdmUeFindBySupi(supi) - configuration := Nudm_SubscriberDataManagement.NewConfiguration() - clientAPI := Nudm_SubscriberDataManagement.NewAPIClient(configuration) - - var problemDetails *models.ProblemDetails - for _, subscriptionDataSubscription := range ue.UdmSubsToNotify { - onDataChangeNotificationurl := subscriptionDataSubscription.OriginalCallbackReference - dataChangeNotification := models.ModificationNotification{} - dataChangeNotification.NotifyItems = notifyItems - - httpResponse, err := clientAPI.DataChangeNotificationCallbackDocumentApi.OnDataChangeNotification( - ctx, onDataChangeNotificationurl, dataChangeNotification) - if err != nil { - if httpResponse == nil { - logger.HttpLog.Error(err.Error()) - problemDetails = &models.ProblemDetails{ - Status: http.StatusForbidden, - Detail: err.Error(), - } - } else { - logger.HttpLog.Errorln(err.Error()) - - problemDetails = &models.ProblemDetails{ - Status: int32(httpResponse.StatusCode), - Detail: err.Error(), - } - } - } - defer func() { - if rspCloseErr := httpResponse.Body.Close(); rspCloseErr != nil { - logger.HttpLog.Errorf("OnDataChangeNotification response body cannot close: %+v", rspCloseErr) - } - }() - } - - return problemDetails -} - -func SendOnDeregistrationNotification(ueId string, onDeregistrationNotificationUrl string, - deregistData models.DeregistrationData, -) *models.ProblemDetails { - ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NUDM_UECM, models.NfType_UDM) - if err != nil { - return pd - } - configuration := Nudm_UEContextManagement.NewConfiguration() - clientAPI := Nudm_UEContextManagement.NewAPIClient(configuration) - - httpResponse, err := clientAPI.DeregistrationNotificationCallbackApi.DeregistrationNotify( - ctx, onDeregistrationNotificationUrl, deregistData) - if err != nil { - if httpResponse == nil { - logger.HttpLog.Error(err.Error()) - problemDetails := &models.ProblemDetails{ - Status: http.StatusInternalServerError, - Cause: "DEREGISTRATION_NOTIFICATION_ERROR", - Detail: err.Error(), - } - - return problemDetails - } else { - logger.HttpLog.Errorln(err.Error()) - problemDetails := &models.ProblemDetails{ - Status: int32(httpResponse.StatusCode), - Cause: "DEREGISTRATION_NOTIFICATION_ERROR", - Detail: err.Error(), - } - - return problemDetails - } - } - defer func() { - if rspCloseErr := httpResponse.Body.Close(); rspCloseErr != nil { - logger.HttpLog.Errorf("DeregistrationNotify response body cannot close: %+v", rspCloseErr) - } - }() - - return nil -} diff --git a/internal/sbi/producer/event_exposure.go b/internal/sbi/producer/event_exposure.go deleted file mode 100644 index 93a06b0..0000000 --- a/internal/sbi/producer/event_exposure.go +++ /dev/null @@ -1,234 +0,0 @@ -package producer - -import ( - "net/http" - "strconv" - "strings" - - "github.com/free5gc/openapi/models" - udm_context "github.com/free5gc/udm/internal/context" - "github.com/free5gc/udm/internal/logger" - "github.com/free5gc/util/httpwrapper" -) - -// TODO: complete this procedure based on TS 29503 5.5 -func CreateEeSubscriptionProcedure(ueIdentity string, - eesubscription models.EeSubscription, -) (*models.CreatedEeSubscription, *models.ProblemDetails) { - udmSelf := udm_context.GetSelf() - logger.EeLog.Debugf("udIdentity: %s", ueIdentity) - switch { - // GPSI (MSISDN identifier) represents a single UE - case strings.HasPrefix(ueIdentity, "msisdn-"): - fallthrough - // GPSI (External identifier) represents a single UE - case strings.HasPrefix(ueIdentity, "extid-"): - if ue, ok := udmSelf.UdmUeFindByGpsi(ueIdentity); ok { - id, err := udmSelf.EeSubscriptionIDGenerator.Allocate() - if err != nil { - problemDetails := &models.ProblemDetails{ - Status: http.StatusInternalServerError, - Cause: "UNSPECIFIED_NF_FAILURE", - } - return nil, problemDetails - } - - subscriptionID := strconv.Itoa(int(id)) - ue.EeSubscriptions[subscriptionID] = &eesubscription - createdEeSubscription := &models.CreatedEeSubscription{ - EeSubscription: &eesubscription, - } - return createdEeSubscription, nil - } else { - problemDetails := &models.ProblemDetails{ - Status: http.StatusNotFound, - Cause: "USER_NOT_FOUND", - } - return nil, problemDetails - } - // external groupID represents a group of UEs - case strings.HasPrefix(ueIdentity, "extgroupid-"): - id, err := udmSelf.EeSubscriptionIDGenerator.Allocate() - if err != nil { - problemDetails := &models.ProblemDetails{ - Status: http.StatusInternalServerError, - Cause: "UNSPECIFIED_NF_FAILURE", - } - return nil, problemDetails - } - subscriptionID := strconv.Itoa(int(id)) - createdEeSubscription := &models.CreatedEeSubscription{ - EeSubscription: &eesubscription, - } - - udmSelf.UdmUePool.Range(func(key, value interface{}) bool { - ue := value.(*udm_context.UdmUeContext) - if ue.ExternalGroupID == ueIdentity { - ue.EeSubscriptions[subscriptionID] = &eesubscription - } - return true - }) - return createdEeSubscription, nil - // represents any UEs - case ueIdentity == "anyUE": - id, err := udmSelf.EeSubscriptionIDGenerator.Allocate() - if err != nil { - problemDetails := &models.ProblemDetails{ - Status: http.StatusInternalServerError, - Cause: "UNSPECIFIED_NF_FAILURE", - } - return nil, problemDetails - } - subscriptionID := strconv.Itoa(int(id)) - createdEeSubscription := &models.CreatedEeSubscription{ - EeSubscription: &eesubscription, - } - udmSelf.UdmUePool.Range(func(key, value interface{}) bool { - ue := value.(*udm_context.UdmUeContext) - ue.EeSubscriptions[subscriptionID] = &eesubscription - return true - }) - return createdEeSubscription, nil - default: - problemDetails := &models.ProblemDetails{ - Status: http.StatusBadRequest, - Cause: "MANDATORY_IE_INCORRECT", - InvalidParams: []models.InvalidParam{ - { - Param: "ueIdentity", - Reason: "incorrect format", - }, - }, - } - return nil, problemDetails - } -} - -func HandleDeleteEeSubscription(request *httpwrapper.Request) *httpwrapper.Response { - ueIdentity := request.Params["ueIdentity"] - subscriptionID := request.Params["subscriptionID"] - - DeleteEeSubscriptionProcedure(ueIdentity, subscriptionID) - return httpwrapper.NewResponse(http.StatusNoContent, nil, nil) -} - -// TODO: complete this procedure based on TS 29503 5.5 -func DeleteEeSubscriptionProcedure(ueIdentity string, subscriptionID string) { - udmSelf := udm_context.GetSelf() - - switch { - case strings.HasPrefix(ueIdentity, "msisdn-"): - fallthrough - case strings.HasPrefix(ueIdentity, "extid-"): - if ue, ok := udmSelf.UdmUeFindByGpsi(ueIdentity); ok { - delete(ue.EeSubscriptions, subscriptionID) - } - case strings.HasPrefix(ueIdentity, "extgroupid-"): - udmSelf.UdmUePool.Range(func(key, value interface{}) bool { - ue := value.(*udm_context.UdmUeContext) - if ue.ExternalGroupID == ueIdentity { - delete(ue.EeSubscriptions, subscriptionID) - } - return true - }) - case ueIdentity == "anyUE": - udmSelf.UdmUePool.Range(func(key, value interface{}) bool { - ue := value.(*udm_context.UdmUeContext) - delete(ue.EeSubscriptions, subscriptionID) - return true - }) - } - if id, err := strconv.ParseInt(subscriptionID, 10, 64); err != nil { - logger.EeLog.Warnf("subscriptionID covert type error: %+v", err) - } else { - udmSelf.EeSubscriptionIDGenerator.FreeID(id) - } -} - -func HandleUpdateEeSubscription(request *httpwrapper.Request) *httpwrapper.Response { - logger.EeLog.Infoln("Handle Update EE subscription") - logger.EeLog.Warnln("Update EE Subscription is not implemented") - - patchList := request.Body.([]models.PatchItem) - ueIdentity := request.Params["ueIdentity"] - subscriptionID := request.Params["subscriptionID"] - - problemDetails := UpdateEeSubscriptionProcedure(ueIdentity, subscriptionID, patchList) - if problemDetails != nil { - return httpwrapper.NewResponse(int(problemDetails.Status), nil, problemDetails) - } else { - return httpwrapper.NewResponse(http.StatusNoContent, nil, nil) - } -} - -// TODO: complete this procedure based on TS 29503 5.5 -func UpdateEeSubscriptionProcedure(ueIdentity string, subscriptionID string, - patchList []models.PatchItem, -) *models.ProblemDetails { - udmSelf := udm_context.GetSelf() - - switch { - case strings.HasPrefix(ueIdentity, "msisdn-"): - fallthrough - case strings.HasPrefix(ueIdentity, "extid-"): - if ue, ok := udmSelf.UdmUeFindByGpsi(ueIdentity); ok { - if _, ok := ue.EeSubscriptions[subscriptionID]; ok { - for _, patchItem := range patchList { - logger.EeLog.Debugf("patch item: %+v", patchItem) - // TODO: patch the Eesubscription - } - return nil - } else { - problemDetails := &models.ProblemDetails{ - Status: http.StatusNotFound, - Cause: "SUBSCRIPTION_NOT_FOUND", - } - return problemDetails - } - } else { - problemDetails := &models.ProblemDetails{ - Status: http.StatusNotFound, - Cause: "SUBSCRIPTION_NOT_FOUND", - } - return problemDetails - } - case strings.HasPrefix(ueIdentity, "extgroupid-"): - udmSelf.UdmUePool.Range(func(key, value interface{}) bool { - ue := value.(*udm_context.UdmUeContext) - if ue.ExternalGroupID == ueIdentity { - if _, ok := ue.EeSubscriptions[subscriptionID]; ok { - for _, patchItem := range patchList { - logger.EeLog.Debugf("patch item: %+v", patchItem) - // TODO: patch the Eesubscription - } - } - } - return true - }) - return nil - case ueIdentity == "anyUE": - udmSelf.UdmUePool.Range(func(key, value interface{}) bool { - ue := value.(*udm_context.UdmUeContext) - if _, ok := ue.EeSubscriptions[subscriptionID]; ok { - for _, patchItem := range patchList { - logger.EeLog.Debugf("patch item: %+v", patchItem) - // TODO: patch the Eesubscription - } - } - return true - }) - return nil - default: - problemDetails := &models.ProblemDetails{ - Status: http.StatusBadRequest, - Cause: "MANDATORY_IE_INCORRECT", - InvalidParams: []models.InvalidParam{ - { - Param: "ueIdentity", - Reason: "incorrect format", - }, - }, - } - return problemDetails - } -} diff --git a/internal/sbi/producer/generate_auth_data.go b/internal/sbi/producer/generate_auth_data.go deleted file mode 100644 index a09c0ae..0000000 --- a/internal/sbi/producer/generate_auth_data.go +++ /dev/null @@ -1,591 +0,0 @@ -package producer - -import ( - cryptoRand "crypto/rand" - "encoding/hex" - "fmt" - "math/big" - "math/rand" - "net/http" - "reflect" - "strconv" - "strings" - "time" - - "github.com/antihax/optional" - - "github.com/free5gc/openapi" - "github.com/free5gc/openapi/Nudr_DataRepository" - "github.com/free5gc/openapi/models" - udm_context "github.com/free5gc/udm/internal/context" - "github.com/free5gc/udm/internal/logger" - "github.com/free5gc/udm/pkg/suci" - "github.com/free5gc/util/httpwrapper" - "github.com/free5gc/util/milenage" - "github.com/free5gc/util/ueauth" -) - -const ( - SqnMAx int64 = 0xFFFFFFFFFFFF - ind int64 = 32 - keyStrLen int = 32 - opStrLen int = 32 - opcStrLen int = 32 -) - -const ( - authenticationRejected string = "AUTHENTICATION_REJECTED" - resyncAMF string = "0000" -) - -func aucSQN(opc, k, auts, rand []byte) ([]byte, []byte) { - AK, SQNms := make([]byte, 6), make([]byte, 6) - macS := make([]byte, 8) - ConcSQNms := auts[:6] - AMF, err := hex.DecodeString(resyncAMF) - if err != nil { - return nil, nil - } - - logger.UeauLog.Tracef("aucSQN: ConcSQNms=[%x]", ConcSQNms) - - err = milenage.F2345(opc, k, rand, nil, nil, nil, nil, AK) - if err != nil { - logger.UeauLog.Errorln("aucSQN milenage F2345 err:", err) - } - - for i := 0; i < 6; i++ { - SQNms[i] = AK[i] ^ ConcSQNms[i] - } - - logger.UeauLog.Tracef("aucSQN: opc=[%x], k=[%x], rand=[%x], AMF=[%x], SQNms=[%x]\n", opc, k, rand, AMF, SQNms) - // The AMF used to calculate MAC-S assumes a dummy value of all zeros - err = milenage.F1(opc, k, rand, SQNms, AMF, nil, macS) - if err != nil { - logger.UeauLog.Errorln("aucSQN milenage F1 err:", err) - } - logger.UeauLog.Tracef("aucSQN: macS=[%x]\n", macS) - return SQNms, macS -} - -func strictHex(s string, n int) string { - l := len(s) - if l < n { - return strings.Repeat("0", n-l) + s - } else { - return s[l-n : l] - } -} - -func HandleGenerateAuthDataRequest(request *httpwrapper.Request) *httpwrapper.Response { - // step 1: log - logger.UeauLog.Infoln("Handle GenerateAuthDataRequest") - - // step 2: retrieve request - authInfoRequest := request.Body.(models.AuthenticationInfoRequest) - supiOrSuci := request.Params["supiOrSuci"] - - // step 3: handle the message - response, problemDetails := GenerateAuthDataProcedure(authInfoRequest, supiOrSuci) - - // step 4: process the return value from step 3 - if response != nil { - // status code is based on SPEC, and option headers - return httpwrapper.NewResponse(http.StatusOK, nil, response) - } else if problemDetails != nil { - return httpwrapper.NewResponse(int(problemDetails.Status), nil, problemDetails) - } - problemDetails = &models.ProblemDetails{ - Status: http.StatusForbidden, - Cause: "UNSPECIFIED", - } - return httpwrapper.NewResponse(http.StatusForbidden, nil, problemDetails) -} - -func HandleConfirmAuthDataRequest(request *httpwrapper.Request) *httpwrapper.Response { - logger.UeauLog.Infoln("Handle ConfirmAuthDataRequest") - - authEvent := request.Body.(models.AuthEvent) - supi := request.Params["supi"] - - problemDetails := ConfirmAuthDataProcedure(authEvent, supi) - - if problemDetails != nil { - return httpwrapper.NewResponse(int(problemDetails.Status), nil, problemDetails) - } else { - return httpwrapper.NewResponse(http.StatusCreated, nil, nil) - } -} - -func ConfirmAuthDataProcedure(authEvent models.AuthEvent, supi string) (problemDetails *models.ProblemDetails) { - ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) - if err != nil { - return pd - } - var createAuthParam Nudr_DataRepository.CreateAuthenticationStatusParamOpts - optInterface := optional.NewInterface(authEvent) - createAuthParam.AuthEvent = optInterface - - client, err := createUDMClientToUDR(supi) - if err != nil { - return openapi.ProblemDetailsSystemFailure(err.Error()) - } - - resp, err := client.AuthenticationStatusDocumentApi.CreateAuthenticationStatus( - ctx, supi, &createAuthParam) - if err != nil { - problemDetails = &models.ProblemDetails{ - Status: int32(resp.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), - } - - logger.UeauLog.Errorln("ConfirmAuth err:", err.Error()) - return problemDetails - } - defer func() { - if rspCloseErr := resp.Body.Close(); rspCloseErr != nil { - logger.UeauLog.Errorf("CreateAuthenticationStatus response body cannot close: %+v", rspCloseErr) - } - }() - - return nil -} - -func GenerateAuthDataProcedure(authInfoRequest models.AuthenticationInfoRequest, supiOrSuci string) ( - response *models.AuthenticationInfoResult, problemDetails *models.ProblemDetails, -) { - ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) - if err != nil { - return nil, pd - } - logger.UeauLog.Traceln("In GenerateAuthDataProcedure") - - response = &models.AuthenticationInfoResult{} - rand.New(rand.NewSource(time.Now().UnixNano())) - supi, err := suci.ToSupi(supiOrSuci, udm_context.GetSelf().SuciProfiles) - if err != nil { - problemDetails = &models.ProblemDetails{ - Status: http.StatusForbidden, - Cause: authenticationRejected, - Detail: err.Error(), - } - - logger.UeauLog.Errorln("suciToSupi error: ", err.Error()) - return nil, problemDetails - } - - logger.UeauLog.Tracef("supi conversion => [%s]", supi) - - client, err := createUDMClientToUDR(supi) - if err != nil { - return nil, openapi.ProblemDetailsSystemFailure(err.Error()) - } - authSubs, res, err := client.AuthenticationDataDocumentApi.QueryAuthSubsData(ctx, supi, nil) - if err != nil { - problemDetails = &models.ProblemDetails{ - Status: http.StatusForbidden, - Cause: authenticationRejected, - Detail: err.Error(), - } - - switch res.StatusCode { - case http.StatusNotFound: - logger.UeauLog.Warnf("Return from UDR QueryAuthSubsData error") - default: - logger.UeauLog.Errorln("Return from UDR QueryAuthSubsData error") - } - return nil, problemDetails - } - defer func() { - if rspCloseErr := res.Body.Close(); rspCloseErr != nil { - logger.SdmLog.Errorf("QueryAuthSubsData response body cannot close: %+v", rspCloseErr) - } - }() - - /* - K, RAND, CK, IK: 128 bits (16 bytes) (hex len = 32) - SQN, AK: 48 bits (6 bytes) (hex len = 12) TS33.102 - 6.3.2 - AMF: 16 bits (2 bytes) (hex len = 4) TS33.102 - Annex H - */ - - hasK, hasOP, hasOPC := false, false, false - var kStr, opStr, opcStr string - var k, op, opc []byte - - if authSubs.PermanentKey != nil { - kStr = authSubs.PermanentKey.PermanentKeyValue - if len(kStr) == keyStrLen { - k, err = hex.DecodeString(kStr) - if err != nil { - logger.UeauLog.Errorln("err:", err) - } else { - hasK = true - } - } else { - problemDetails = &models.ProblemDetails{ - Status: http.StatusForbidden, - Cause: authenticationRejected, - } - - logger.UeauLog.Errorln("kStr length is ", len(kStr)) - return nil, problemDetails - } - } else { - problemDetails = &models.ProblemDetails{ - Status: http.StatusForbidden, - Cause: authenticationRejected, - } - - logger.UeauLog.Errorln("Nil PermanentKey") - return nil, problemDetails - } - - if authSubs.Milenage != nil { - if authSubs.Milenage.Op != nil && authSubs.Milenage.Op.OpValue != "" { - opStr = authSubs.Milenage.Op.OpValue - if len(opStr) == opStrLen { - op, err = hex.DecodeString(opStr) - if err != nil { - logger.UeauLog.Errorln("err:", err) - } else { - hasOP = true - } - } else { - logger.UeauLog.Errorln("opStr length is ", len(opStr)) - } - } else { - logger.UeauLog.Infoln("Nil Op") - } - } else { - problemDetails = &models.ProblemDetails{ - Status: http.StatusForbidden, - Cause: authenticationRejected, - } - - logger.UeauLog.Infoln("Nil Milenage") - return nil, problemDetails - } - - if authSubs.Opc != nil && authSubs.Opc.OpcValue != "" { - opcStr = authSubs.Opc.OpcValue - if len(opcStr) == opcStrLen { - opc, err = hex.DecodeString(opcStr) - if err != nil { - logger.UeauLog.Errorln("err:", err) - } else { - hasOPC = true - } - } else { - logger.UeauLog.Errorln("opcStr length is ", len(opcStr)) - } - } else { - logger.UeauLog.Infoln("Nil Opc") - } - - if !hasOPC && !hasOP { - problemDetails = &models.ProblemDetails{ - Status: http.StatusForbidden, - Cause: authenticationRejected, - } - - return nil, problemDetails - } - - if !hasOPC { - if hasK && hasOP { - opc, err = milenage.GenerateOPC(k, op) - if err != nil { - logger.UeauLog.Errorln("milenage GenerateOPC err:", err) - } - } else { - problemDetails = &models.ProblemDetails{ - Status: http.StatusForbidden, - Cause: authenticationRejected, - } - - logger.UeauLog.Errorln("Unable to derive OPC") - return nil, problemDetails - } - } - - sqnStr := strictHex(authSubs.SequenceNumber, 12) - logger.UeauLog.Traceln("sqnStr", sqnStr) - sqn, err := hex.DecodeString(sqnStr) - if err != nil { - problemDetails = &models.ProblemDetails{ - Status: http.StatusForbidden, - Cause: authenticationRejected, - Detail: err.Error(), - } - - logger.UeauLog.Errorln("err:", err) - return nil, problemDetails - } - - logger.UeauLog.Tracef("K=[%x], sqn=[%x], OP=[%x], OPC=[%x]", k, sqn, op, opc) - - RAND := make([]byte, 16) - _, err = cryptoRand.Read(RAND) - if err != nil { - problemDetails = &models.ProblemDetails{ - Status: http.StatusForbidden, - Cause: authenticationRejected, - Detail: err.Error(), - } - - logger.UeauLog.Errorln("err:", err) - return nil, problemDetails - } - - amfStr := strictHex(authSubs.AuthenticationManagementField, 4) - logger.UeauLog.Traceln("amfStr", amfStr) - AMF, err := hex.DecodeString(amfStr) - if err != nil { - problemDetails = &models.ProblemDetails{ - Status: http.StatusForbidden, - Cause: authenticationRejected, - Detail: err.Error(), - } - - logger.UeauLog.Errorln("err:", err) - return nil, problemDetails - } - - logger.UeauLog.Tracef("RAND=[%x], AMF=[%x]", RAND, AMF) - - // re-synchronization - if authInfoRequest.ResynchronizationInfo != nil { - logger.UeauLog.Infof("Authentication re-synchronization") - - Auts, deCodeErr := hex.DecodeString(authInfoRequest.ResynchronizationInfo.Auts) - if deCodeErr != nil { - problemDetails = &models.ProblemDetails{ - Status: http.StatusForbidden, - Cause: authenticationRejected, - Detail: deCodeErr.Error(), - } - - logger.UeauLog.Errorln("err:", deCodeErr) - return nil, problemDetails - } - - randHex, deCodeErr := hex.DecodeString(authInfoRequest.ResynchronizationInfo.Rand) - if deCodeErr != nil { - problemDetails = &models.ProblemDetails{ - Status: http.StatusForbidden, - Cause: authenticationRejected, - Detail: deCodeErr.Error(), - } - - logger.UeauLog.Errorln("err:", deCodeErr) - return nil, problemDetails - } - - SQNms, macS := aucSQN(opc, k, Auts, randHex) - if reflect.DeepEqual(macS, Auts[6:]) { - _, err = cryptoRand.Read(RAND) - if err != nil { - problemDetails = &models.ProblemDetails{ - Status: http.StatusForbidden, - Cause: authenticationRejected, - Detail: deCodeErr.Error(), - } - - logger.UeauLog.Errorln("err:", deCodeErr) - return nil, problemDetails - } - - // increment sqn authSubs.SequenceNumber - bigSQN := big.NewInt(0) - sqnStr = hex.EncodeToString(SQNms) - logger.UeauLog.Tracef("SQNstr=[%s]", sqnStr) - bigSQN.SetString(sqnStr, 16) - - bigInc := big.NewInt(ind + 1) - - bigP := big.NewInt(SqnMAx) - bigSQN = bigInc.Add(bigSQN, bigInc) - bigSQN = bigSQN.Mod(bigSQN, bigP) - sqnStr = fmt.Sprintf("%x", bigSQN) - sqnStr = strictHex(sqnStr, 12) - } else { - logger.UeauLog.Errorln("Re-Sync MAC failed ", supiOrSuci) - // Check if suci - suciPart := strings.Split(supiOrSuci, "-") - if suciPart[suci.PrefixPlace] == suci.PrefixSUCI && - suciPart[suci.SupiTypePlace] == suci.SupiTypeIMSI && - suciPart[suci.SchemePlace] != suci.NullScheme { - // Get SuciProfile index and write public key - keyIndex, err1 := strconv.Atoi(suciPart[suci.HNPublicKeyIDPlace]) - if err1 != nil { - logger.UeauLog.Errorln("Re-Sync Failed UDM Public Key HNPublicKeyIDPlace parse Error") - } else if keyIndex < 1 { - logger.UeauLog.Errorf("Re-Sync Failed UDM Public Key HNPublicKeyIDPlace keyIndex[%d] < 1", - keyIndex) - } else { - logger.UeauLog.Errorln("Re-Sync Failed UDM Public Key ", - udm_context.GetSelf().SuciProfiles[keyIndex-1].PublicKey) - } - } - logger.UeauLog.Errorln("MACS ", macS) - logger.UeauLog.Errorln("Auts[6:] ", Auts[6:]) - logger.UeauLog.Errorln("Sqn ", SQNms) - problemDetails = &models.ProblemDetails{ - Status: http.StatusForbidden, - Cause: "modification is rejected", - } - return nil, problemDetails - } - } - - // increment sqn - bigSQN := big.NewInt(0) - sqn, err = hex.DecodeString(sqnStr) - if err != nil { - problemDetails = &models.ProblemDetails{ - Status: http.StatusForbidden, - Cause: authenticationRejected, - Detail: err.Error(), - } - - logger.UeauLog.Errorln("err:", err) - return nil, problemDetails - } - - bigSQN.SetString(sqnStr, 16) - - bigInc := big.NewInt(1) - bigSQN = bigInc.Add(bigSQN, bigInc) - - SQNheStr := fmt.Sprintf("%x", bigSQN) - SQNheStr = strictHex(SQNheStr, 12) - patchItemArray := []models.PatchItem{ - { - Op: models.PatchOperation_REPLACE, - Path: "/sequenceNumber", - Value: SQNheStr, - }, - } - - var rsp *http.Response - - rsp, err = client.AuthenticationDataDocumentApi.ModifyAuthentication( - ctx, supi, patchItemArray) - if err != nil { - problemDetails = &models.ProblemDetails{ - Status: http.StatusForbidden, - Cause: "modification is rejected ", - Detail: err.Error(), - } - - logger.UeauLog.Errorln("update sqn error:", err) - return nil, problemDetails - } - defer func() { - if rspCloseErr := rsp.Body.Close(); rspCloseErr != nil { - logger.SdmLog.Errorf("ModifyAuthentication response body cannot close: %+v", rspCloseErr) - } - }() - - // Run milenage - macA, macS := make([]byte, 8), make([]byte, 8) - CK, IK := make([]byte, 16), make([]byte, 16) - RES := make([]byte, 8) - AK, AKstar := make([]byte, 6), make([]byte, 6) - - // Generate macA, macS - err = milenage.F1(opc, k, RAND, sqn, AMF, macA, macS) - if err != nil { - logger.UeauLog.Errorln("milenage F1 err:", err) - } - - // Generate RES, CK, IK, AK, AKstar - // RES == XRES (expected RES) for server - err = milenage.F2345(opc, k, RAND, RES, CK, IK, AK, AKstar) - if err != nil { - logger.UeauLog.Errorln("milenage F2345 err:", err) - } - logger.UeauLog.Tracef("milenage RES=[%s]", hex.EncodeToString(RES)) - - // Generate AUTN - logger.UeauLog.Tracef("SQN=[%x], AK=[%x]", sqn, AK) - logger.UeauLog.Tracef("AMF=[%x], macA=[%x]", AMF, macA) - SQNxorAK := make([]byte, 6) - for i := 0; i < len(sqn); i++ { - SQNxorAK[i] = sqn[i] ^ AK[i] - } - logger.UeauLog.Tracef("SQN xor AK=[%x]", SQNxorAK) - AUTN := append(append(SQNxorAK, AMF...), macA...) - logger.UeauLog.Tracef("AUTN=[%x]", AUTN) - - var av models.AuthenticationVector - if authSubs.AuthenticationMethod == models.AuthMethod__5_G_AKA { - response.AuthType = models.AuthType__5_G_AKA - - // derive XRES* - key := append(CK, IK...) - FC := ueauth.FC_FOR_RES_STAR_XRES_STAR_DERIVATION - P0 := []byte(authInfoRequest.ServingNetworkName) - P1 := RAND - P2 := RES - - kdfValForXresStar, err := ueauth.GetKDFValue( - key, FC, P0, ueauth.KDFLen(P0), P1, ueauth.KDFLen(P1), P2, ueauth.KDFLen(P2)) - if err != nil { - logger.UeauLog.Errorf("Get kdfValForXresStar err: %+v", err) - } - xresStar := kdfValForXresStar[len(kdfValForXresStar)/2:] - logger.UeauLog.Tracef("xresStar=[%x]", xresStar) - - // derive Kausf - FC = ueauth.FC_FOR_KAUSF_DERIVATION - P0 = []byte(authInfoRequest.ServingNetworkName) - P1 = SQNxorAK - kdfValForKausf, err := ueauth.GetKDFValue(key, FC, P0, ueauth.KDFLen(P0), P1, ueauth.KDFLen(P1)) - if err != nil { - logger.UeauLog.Errorf("Get kdfValForKausf err: %+v", err) - } - logger.UeauLog.Tracef("Kausf=[%x]", kdfValForKausf) - - // Fill in rand, xresStar, autn, kausf - av.Rand = hex.EncodeToString(RAND) - av.XresStar = hex.EncodeToString(xresStar) - av.Autn = hex.EncodeToString(AUTN) - av.Kausf = hex.EncodeToString(kdfValForKausf) - av.AvType = models.AvType__5_G_HE_AKA - } else { // EAP-AKA' - response.AuthType = models.AuthType_EAP_AKA_PRIME - - // derive CK' and IK' - key := append(CK, IK...) - FC := ueauth.FC_FOR_CK_PRIME_IK_PRIME_DERIVATION - P0 := []byte(authInfoRequest.ServingNetworkName) - P1 := SQNxorAK - kdfVal, err := ueauth.GetKDFValue(key, FC, P0, ueauth.KDFLen(P0), P1, ueauth.KDFLen(P1)) - if err != nil { - logger.UeauLog.Errorf("Get kdfVal err: %+v", err) - } - logger.UeauLog.Tracef("kdfVal=[%x] (len=%d)", kdfVal, len(kdfVal)) - - // For TS 35.208 test set 19 & RFC 5448 test vector 1 - // CK': 0093 962d 0dd8 4aa5 684b 045c 9edf fa04 - // IK': ccfc 230c a74f cc96 c0a5 d611 64f5 a76 - - ckPrime := kdfVal[:len(kdfVal)/2] - ikPrime := kdfVal[len(kdfVal)/2:] - logger.UeauLog.Tracef("ckPrime=[%x], kPrime=[%x]", ckPrime, ikPrime) - - // Fill in rand, xres, autn, ckPrime, ikPrime - av.Rand = hex.EncodeToString(RAND) - av.Xres = hex.EncodeToString(RES) - av.Autn = hex.EncodeToString(AUTN) - av.CkPrime = hex.EncodeToString(ckPrime) - av.IkPrime = hex.EncodeToString(ikPrime) - av.AvType = models.AvType_EAP_AKA_PRIME - } - - response.AuthenticationVector = &av - response.Supi = supi - return response, nil -} diff --git a/internal/sbi/producer/parameter_provision.go b/internal/sbi/producer/parameter_provision.go deleted file mode 100644 index d3dfae1..0000000 --- a/internal/sbi/producer/parameter_provision.go +++ /dev/null @@ -1,56 +0,0 @@ -package producer - -import ( - "net/http" - - "github.com/free5gc/openapi" - "github.com/free5gc/openapi/models" - udm_context "github.com/free5gc/udm/internal/context" - "github.com/free5gc/udm/internal/logger" - "github.com/free5gc/util/httpwrapper" -) - -func HandleUpdateRequest(request *httpwrapper.Request) *httpwrapper.Response { - // step 1: log - logger.PpLog.Infoln("Handle UpdateRequest") - - // step 2: retrieve request - updateRequest := request.Body.(models.PpData) - gpsi := request.Params["gpsi"] - - // step 3: handle the message - problemDetails := UpdateProcedure(updateRequest, gpsi) - - // step 4: process the return value from step 3 - if problemDetails != nil { - return httpwrapper.NewResponse(int(problemDetails.Status), nil, problemDetails) - } else { - return httpwrapper.NewResponse(http.StatusNoContent, nil, nil) - } -} - -func UpdateProcedure(updateRequest models.PpData, gpsi string) (problemDetails *models.ProblemDetails) { - ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) - if err != nil { - return pd - } - clientAPI, err := createUDMClientToUDR(gpsi) - if err != nil { - return openapi.ProblemDetailsSystemFailure(err.Error()) - } - res, err := clientAPI.ProvisionedParameterDataDocumentApi.ModifyPpData(ctx, gpsi, nil) - if err != nil { - problemDetails = &models.ProblemDetails{ - Status: int32(res.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), - } - return problemDetails - } - defer func() { - if rspCloseErr := res.Body.Close(); rspCloseErr != nil { - logger.PpLog.Errorf("ModifyPpData response body cannot close: %+v", rspCloseErr) - } - }() - return nil -} diff --git a/internal/sbi/producer/subscriber_data_management.go b/internal/sbi/producer/subscriber_data_management.go deleted file mode 100644 index cf36bcd..0000000 --- a/internal/sbi/producer/subscriber_data_management.go +++ /dev/null @@ -1,1543 +0,0 @@ -package producer - -import ( - "encoding/json" - "net/http" - "net/url" - "strconv" - "strings" - - "github.com/antihax/optional" - - "github.com/free5gc/openapi" - "github.com/free5gc/openapi/Nudm_SubscriberDataManagement" - Nudr "github.com/free5gc/openapi/Nudr_DataRepository" - "github.com/free5gc/openapi/models" - udm_context "github.com/free5gc/udm/internal/context" - "github.com/free5gc/udm/internal/logger" - "github.com/free5gc/util/httpwrapper" -) - -func HandleGetAmDataRequest(request *httpwrapper.Request) *httpwrapper.Response { - // step 1: log - logger.SdmLog.Infof("Handle GetAmData") - - // step 2: retrieve request - supi := request.Params["supi"] - plmnIDStruct, problemDetails := getPlmnIDStruct(request.Query) - if problemDetails != nil { - return httpwrapper.NewResponse(int(problemDetails.Status), nil, problemDetails) - } - plmnID := plmnIDStruct.Mcc + plmnIDStruct.Mnc - supportedFeatures := request.Query.Get("supported-features") - - // step 3: handle the message - response, problemDetails := getAmDataProcedure(supi, plmnID, supportedFeatures) - - // step 4: process the return value from step 3 - if response != nil { - // status code is based on SPEC, and option headers - return httpwrapper.NewResponse(http.StatusOK, nil, response) - } else if problemDetails != nil { - return httpwrapper.NewResponse(int(problemDetails.Status), nil, problemDetails) - } - problemDetails = &models.ProblemDetails{ - Status: http.StatusForbidden, - Cause: "UNSPECIFIED", - } - return httpwrapper.NewResponse(http.StatusForbidden, nil, problemDetails) -} - -// TS 29.503 5.2.2.2.3 -// Access and Mobility Subscription Data Retrieval -func getAmDataProcedure(supi string, plmnID string, supportedFeatures string) ( - response *models.AccessAndMobilitySubscriptionData, problemDetails *models.ProblemDetails, -) { - ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) - if err != nil { - return nil, pd - } - var queryAmDataParamOpts Nudr.QueryAmDataParamOpts - queryAmDataParamOpts.SupportedFeatures = optional.NewString(supportedFeatures) - - clientAPI, err := createUDMClientToUDR(supi) - if err != nil { - return nil, openapi.ProblemDetailsSystemFailure(err.Error()) - } - - accessAndMobilitySubscriptionDataResp, res, err := clientAPI.AccessAndMobilitySubscriptionDataDocumentApi. - QueryAmData(ctx, supi, plmnID, &queryAmDataParamOpts) - if err != nil { - if res == nil { - logger.SdmLog.Errorf(err.Error()) - } else if err.Error() != res.Status { - logger.SdmLog.Errorf("Response State: %+v", err.Error()) - } else { - problemDetails = &models.ProblemDetails{ - Status: int32(res.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), - } - return nil, problemDetails - } - } - defer func() { - if rspCloseErr := res.Body.Close(); rspCloseErr != nil { - logger.SdmLog.Errorf("QueryAmData response body cannot close: %+v", rspCloseErr) - } - }() - - if res.StatusCode == http.StatusOK { - udmUe, ok := udm_context.GetSelf().UdmUeFindBySupi(supi) - if !ok { - udmUe = udm_context.GetSelf().NewUdmUe(supi) - } - udmUe.SetAMSubsriptionData(&accessAndMobilitySubscriptionDataResp) - return &accessAndMobilitySubscriptionDataResp, nil - } else { - problemDetails = &models.ProblemDetails{ - Status: http.StatusNotFound, - Cause: "DATA_NOT_FOUND", - } - return nil, problemDetails - } -} - -func HandleGetIdTranslationResultRequest(request *httpwrapper.Request) *httpwrapper.Response { - // step 1: log - logger.SdmLog.Infof("Handle GetIdTranslationResultRequest") - - // step 2: retrieve request - gpsi := request.Params["gpsi"] - - // step 3: handle the message - response, problemDetails := getIdTranslationResultProcedure(gpsi) - - // step 4: process the return value from step 3 - if response != nil { - // status code is based on SPEC, and option headers - return httpwrapper.NewResponse(http.StatusOK, nil, response) - } else if problemDetails != nil { - return httpwrapper.NewResponse(int(problemDetails.Status), nil, problemDetails) - } - problemDetails = &models.ProblemDetails{ - Status: http.StatusForbidden, - Cause: "UNSPECIFIED", - } - return httpwrapper.NewResponse(http.StatusForbidden, nil, problemDetails) -} - -// TS 29.503 5.2.2.2.10 -// Identifier Translation -func getIdTranslationResultProcedure(gpsi string) (response *models.IdTranslationResult, - problemDetails *models.ProblemDetails, -) { - ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) - if err != nil { - return nil, pd - } - var idTranslationResult models.IdTranslationResult - var getIdentityDataParamOpts Nudr.GetIdentityDataParamOpts - - clientAPI, err := createUDMClientToUDR(gpsi) - if err != nil { - return nil, openapi.ProblemDetailsSystemFailure(err.Error()) - } - - idTranslationResultResp, res, err := clientAPI.QueryIdentityDataBySUPIOrGPSIDocumentApi.GetIdentityData( - ctx, gpsi, &getIdentityDataParamOpts) - if err != nil { - if res == nil { - logger.SdmLog.Errorf(err.Error()) - } else if err.Error() != res.Status { - logger.SdmLog.Errorf("Response State: %+v", err.Error()) - } else { - problemDetails = &models.ProblemDetails{ - Status: int32(res.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), - } - - return nil, problemDetails - } - } - defer func() { - if rspCloseErr := res.Body.Close(); rspCloseErr != nil { - logger.SdmLog.Errorf("GetIdentityData response body cannot close: %+v", rspCloseErr) - } - }() - - if res.StatusCode == http.StatusOK { - if idList := idTranslationResultResp; idList.SupiList != nil { - // GetCorrespondingSupi get corresponding Supi(here IMSI) matching the given Gpsi from the queried SUPI list from UDR - idTranslationResult.Supi = udm_context.GetCorrespondingSupi(idList) - idTranslationResult.Gpsi = gpsi - - return &idTranslationResult, nil - } else { - problemDetails = &models.ProblemDetails{ - Status: http.StatusNotFound, - Cause: "USER_NOT_FOUND", - } - - return nil, problemDetails - } - } else { - problemDetails = &models.ProblemDetails{ - Status: http.StatusNotFound, - Cause: "DATA_NOT_FOUND", - } - - return nil, problemDetails - } -} - -func HandleGetSupiRequest(request *httpwrapper.Request) *httpwrapper.Response { - // step 1: log - logger.SdmLog.Infof("Handle GetSupiRequest") - - // step 2: retrieve request - supi := request.Params["supi"] - plmnIDStruct, problemDetails := getPlmnIDStruct(request.Query) - if problemDetails != nil { - return httpwrapper.NewResponse(int(problemDetails.Status), nil, problemDetails) - } - plmnID := plmnIDStruct.Mcc + plmnIDStruct.Mnc - dataSetNames := strings.Split(request.Query.Get("dataset-names"), ",") - supportedFeatures := request.Query.Get("supported-features") - - // step 3: handle the message - response, problemDetails := getSupiProcedure(supi, plmnID, dataSetNames, supportedFeatures) - - // step 4: process the return value from step 3 - if response != nil { - // status code is based on SPEC, and option headers - return httpwrapper.NewResponse(http.StatusOK, nil, response) - } else if problemDetails != nil { - return httpwrapper.NewResponse(int(problemDetails.Status), nil, problemDetails) - } - problemDetails = &models.ProblemDetails{ - Status: http.StatusForbidden, - Cause: "UNSPECIFIED", - } - return httpwrapper.NewResponse(http.StatusForbidden, nil, problemDetails) -} - -// TS 29.503 5.2.2.2.9 -// Retrieval Of Multiple Data Set -func getSupiProcedure(supi string, plmnID string, dataSetNames []string, supportedFeatures string) ( - response *models.SubscriptionDataSets, problemDetails *models.ProblemDetails, -) { - ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) - if err != nil { - return nil, pd - } - if len(dataSetNames) < 2 { - problemDetails = &models.ProblemDetails{ - Status: http.StatusBadRequest, - Cause: "BAD_REQUEST", - Detail: "datasetNames must have at least 2 elements", - } - return nil, problemDetails - } - - clientAPI, err := createUDMClientToUDR(supi) - if err != nil { - return nil, openapi.ProblemDetailsSystemFailure(err.Error()) - } - - var subscriptionDataSets, subsDataSetBody models.SubscriptionDataSets - var ueContextInSmfDataResp models.UeContextInSmfData - pduSessionMap := make(map[string]models.PduSession) - var pgwInfoArray []models.PgwInfo - - var queryAmDataParamOpts Nudr.QueryAmDataParamOpts - queryAmDataParamOpts.SupportedFeatures = optional.NewString(supportedFeatures) - var querySmfSelectDataParamOpts Nudr.QuerySmfSelectDataParamOpts - var queryTraceDataParamOpts Nudr.QueryTraceDataParamOpts - var querySmDataParamOpts Nudr.QuerySmDataParamOpts - - queryAmDataParamOpts.SupportedFeatures = optional.NewString(supportedFeatures) - querySmfSelectDataParamOpts.SupportedFeatures = optional.NewString(supportedFeatures) - udm_context.GetSelf().CreateSubsDataSetsForUe(supi, subsDataSetBody) - - if containDataSetName(dataSetNames, string(models.DataSetName_AM)) { - var body models.AccessAndMobilitySubscriptionData - udm_context.GetSelf().CreateAccessMobilitySubsDataForUe(supi, body) - - amData, res, err := clientAPI.AccessAndMobilitySubscriptionDataDocumentApi.QueryAmData( - ctx, supi, plmnID, &queryAmDataParamOpts) - if err != nil { - if res == nil { - logger.SdmLog.Errorf(err.Error()) - } else if err.Error() != res.Status { - logger.SdmLog.Errorf("Response State: %+v", err.Error()) - } else { - problemDetails = &models.ProblemDetails{ - Status: int32(res.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), - } - - return nil, problemDetails - } - } - defer func() { - if rspCloseErr := res.Body.Close(); rspCloseErr != nil { - logger.SdmLog.Errorf("QueryAmData response body cannot close: %+v", rspCloseErr) - } - }() - if res.StatusCode == http.StatusOK { - udmUe, ok := udm_context.GetSelf().UdmUeFindBySupi(supi) - if !ok { - udmUe = udm_context.GetSelf().NewUdmUe(supi) - } - udmUe.SetAMSubsriptionData(&amData) - subscriptionDataSets.AmData = &amData - } else { - problemDetails = &models.ProblemDetails{ - Status: http.StatusNotFound, - Cause: "DATA_NOT_FOUND", - } - - return nil, problemDetails - } - } - - if containDataSetName(dataSetNames, string(models.DataSetName_SMF_SEL)) { - var smfSelSubsbody models.SmfSelectionSubscriptionData - udm_context.GetSelf().CreateSmfSelectionSubsDataforUe(supi, smfSelSubsbody) - - smfSelData, res, err := clientAPI.SMFSelectionSubscriptionDataDocumentApi.QuerySmfSelectData(ctx, - supi, plmnID, &querySmfSelectDataParamOpts) - if err != nil { - if res == nil { - logger.SdmLog.Errorln(err.Error()) - } else if err.Error() != res.Status { - logger.SdmLog.Errorln(err.Error()) - } else { - problemDetails = &models.ProblemDetails{ - Status: int32(res.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), - } - - return nil, problemDetails - } - } - defer func() { - if rspCloseErr := res.Body.Close(); rspCloseErr != nil { - logger.SdmLog.Errorf("QuerySmfSelectData response body cannot close: %+v", rspCloseErr) - } - }() - if res.StatusCode == http.StatusOK { - udmUe, ok := udm_context.GetSelf().UdmUeFindBySupi(supi) - if !ok { - udmUe = udm_context.GetSelf().NewUdmUe(supi) - } - udmUe.SetSmfSelectionSubsData(&smfSelData) - subscriptionDataSets.SmfSelData = &smfSelData - } else { - problemDetails = &models.ProblemDetails{ - Status: http.StatusNotFound, - Cause: "DATA_NOT_FOUND", - } - - return nil, problemDetails - } - } - - if containDataSetName(dataSetNames, string(models.DataSetName_UEC_SMF)) { - var UeContextInSmfbody models.UeContextInSmfData - var querySmfRegListParamOpts Nudr.QuerySmfRegListParamOpts - querySmfRegListParamOpts.SupportedFeatures = optional.NewString(supportedFeatures) - udm_context.GetSelf().CreateUeContextInSmfDataforUe(supi, UeContextInSmfbody) - - pdusess, res, err := clientAPI.SMFRegistrationsCollectionApi.QuerySmfRegList( - ctx, supi, &querySmfRegListParamOpts) - if err != nil { - if res == nil { - logger.SdmLog.Errorf(err.Error()) - } else if err.Error() != res.Status { - logger.SdmLog.Errorf("Response State: %+v", err.Error()) - } else { - problemDetails = &models.ProblemDetails{ - Status: int32(res.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), - } - - return nil, problemDetails - } - } - defer func() { - if rspCloseErr := res.Body.Close(); rspCloseErr != nil { - logger.SdmLog.Errorf("QuerySmfRegList response body cannot close: %+v", rspCloseErr) - } - }() - - for _, element := range pdusess { - var pduSession models.PduSession - pduSession.Dnn = element.Dnn - pduSession.SmfInstanceId = element.SmfInstanceId - pduSession.PlmnId = element.PlmnId - pduSessionMap[strconv.Itoa(int(element.PduSessionId))] = pduSession - } - ueContextInSmfDataResp.PduSessions = pduSessionMap - - for _, element := range pdusess { - var pgwInfo models.PgwInfo - pgwInfo.Dnn = element.Dnn - pgwInfo.PgwFqdn = element.PgwFqdn - pgwInfo.PlmnId = element.PlmnId - pgwInfoArray = append(pgwInfoArray, pgwInfo) - } - ueContextInSmfDataResp.PgwInfo = pgwInfoArray - - if res.StatusCode == http.StatusOK { - udmUe, ok := udm_context.GetSelf().UdmUeFindBySupi(supi) - if !ok { - udmUe = udm_context.GetSelf().NewUdmUe(supi) - } - udmUe.UeCtxtInSmfData = &ueContextInSmfDataResp - subscriptionDataSets.UecSmfData = &ueContextInSmfDataResp - } else { - var problemDetails models.ProblemDetails - problemDetails.Cause = "DATA_NOT_FOUND" - logger.SdmLog.Errorf(problemDetails.Cause) - } - } - - // TODO: UE Context in SMSF Data - // if containDataSetName(dataSetNames, string(models.DataSetName_UEC_SMSF)) { - // } - - // TODO: SMS Subscription Data - // if containDataSetName(dataSetNames, string(models.DataSetName_SMS_SUB)) { - // } - - if containDataSetName(dataSetNames, string(models.DataSetName_SM)) { - sessionManagementSubscriptionData, res, err := clientAPI.SessionManagementSubscriptionDataApi. - QuerySmData(ctx, supi, plmnID, &querySmDataParamOpts) - if err != nil { - if res == nil { - logger.SdmLog.Errorf(err.Error()) - } else if err.Error() != res.Status { - logger.SdmLog.Errorf("Response State: %+v", err.Error()) - } else { - problemDetails = &models.ProblemDetails{ - Status: int32(res.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), - } - - return nil, problemDetails - } - } - defer func() { - if rspCloseErr := res.Body.Close(); rspCloseErr != nil { - logger.SdmLog.Errorf("QuerySmData response body cannot close: %+v", rspCloseErr) - } - }() - if res.StatusCode == http.StatusOK { - udmUe, ok := udm_context.GetSelf().UdmUeFindBySupi(supi) - if !ok { - udmUe = udm_context.GetSelf().NewUdmUe(supi) - } - smData, _, _, _ := udm_context.GetSelf().ManageSmData(sessionManagementSubscriptionData, "", "") - udmUe.SetSMSubsData(smData) - subscriptionDataSets.SmData = sessionManagementSubscriptionData - } else { - problemDetails = &models.ProblemDetails{ - Status: http.StatusNotFound, - Cause: "DATA_NOT_FOUND", - } - - return nil, problemDetails - } - } - - if containDataSetName(dataSetNames, string(models.DataSetName_TRACE)) { - var TraceDatabody models.TraceData - udm_context.GetSelf().CreateTraceDataforUe(supi, TraceDatabody) - - traceData, res, err := clientAPI.TraceDataDocumentApi.QueryTraceData( - ctx, supi, plmnID, &queryTraceDataParamOpts) - if err != nil { - if res == nil { - logger.SdmLog.Errorf(err.Error()) - } else if err.Error() != res.Status { - logger.SdmLog.Errorf("Response State: %+v", err.Error()) - } else { - problemDetails = &models.ProblemDetails{ - Status: int32(res.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), - } - } - return nil, problemDetails - } - defer func() { - if rspCloseErr := res.Body.Close(); rspCloseErr != nil { - logger.SdmLog.Errorf("QueryTraceData response body cannot close: %+v", rspCloseErr) - } - }() - if res.StatusCode == http.StatusOK { - udmUe, ok := udm_context.GetSelf().UdmUeFindBySupi(supi) - if !ok { - udmUe = udm_context.GetSelf().NewUdmUe(supi) - } - udmUe.TraceData = &traceData - udmUe.TraceDataResponse.TraceData = &traceData - subscriptionDataSets.TraceData = &traceData - } else { - problemDetails = &models.ProblemDetails{ - Status: http.StatusNotFound, - Cause: "DATA_NOT_FOUND", - } - - return nil, problemDetails - } - } - - // TODO: SMS Management Subscription Data - // if containDataSetName(dataSetNames, string(models.DataSetName_SMS_MNG)) { - // } - - return &subscriptionDataSets, nil -} - -func HandleGetSharedDataRequest(request *httpwrapper.Request) *httpwrapper.Response { - // step 1: log - logger.SdmLog.Infof("Handle GetSharedData") - - // step 2: retrieve request - sharedDataIds := request.Query["sharedDataIds"] - supportedFeatures := request.Query.Get("supported-features") - // step 3: handle the message - response, problemDetails := getSharedDataProcedure(sharedDataIds, supportedFeatures) - - // step 4: process the return value from step 3 - if response != nil { - // status code is based on SPEC, and option headers - return httpwrapper.NewResponse(http.StatusOK, nil, response) - } else if problemDetails != nil { - return httpwrapper.NewResponse(int(problemDetails.Status), nil, problemDetails) - } - problemDetails = &models.ProblemDetails{ - Status: http.StatusForbidden, - Cause: "UNSPECIFIED", - } - return httpwrapper.NewResponse(http.StatusForbidden, nil, problemDetails) -} - -// TS 29.503 5.2.2.2.11 -// Shared Subscription Data Retrieval -func getSharedDataProcedure(sharedDataIds []string, supportedFeatures string) ( - response []models.SharedData, problemDetails *models.ProblemDetails, -) { - ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) - if err != nil { - return nil, pd - } - clientAPI, err := createUDMClientToUDR("") - if err != nil { - return nil, openapi.ProblemDetailsSystemFailure(err.Error()) - } - - var getSharedDataParamOpts Nudr.GetSharedDataParamOpts - getSharedDataParamOpts.SupportedFeatures = optional.NewString(supportedFeatures) - - sharedDataResp, res, err := clientAPI.RetrievalOfSharedDataApi.GetSharedData(ctx, sharedDataIds, - &getSharedDataParamOpts) - if err != nil { - if res == nil { - logger.SdmLog.Warnln(err) - } else if err.Error() != res.Status { - logger.SdmLog.Warnln(err) - } else { - logger.SdmLog.Warnln(err) - problemDetails = &models.ProblemDetails{ - Status: int32(res.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), - } - - return nil, problemDetails - } - } - defer func() { - if rspCloseErr := res.Body.Close(); rspCloseErr != nil { - logger.SdmLog.Errorf("GetShareData response body cannot close: %+v", rspCloseErr) - } - }() - - if res.StatusCode == http.StatusOK { - udm_context.GetSelf().SharedSubsDataMap = udm_context.MappingSharedData(sharedDataResp) - sharedData := udm_context.ObtainRequiredSharedData(sharedDataIds, sharedDataResp) - return sharedData, nil - } else { - problemDetails = &models.ProblemDetails{ - Status: http.StatusNotFound, - Cause: "DATA_NOT_FOUND", - } - return nil, problemDetails - } -} - -func HandleGetSmDataRequest(request *httpwrapper.Request) *httpwrapper.Response { - // step 1: log - logger.SdmLog.Infof("Handle GetSmData") - - // step 2: retrieve request - supi := request.Params["supi"] - plmnIDStruct, problemDetails := getPlmnIDStruct(request.Query) - if problemDetails != nil { - return httpwrapper.NewResponse(int(problemDetails.Status), nil, problemDetails) - } - plmnID := plmnIDStruct.Mcc + plmnIDStruct.Mnc - Dnn := request.Query.Get("dnn") - Snssai := request.Query.Get("single-nssai") - supportedFeatures := request.Query.Get("supported-features") - - // step 3: handle the message - response, problemDetails := getSmDataProcedure(supi, plmnID, Dnn, Snssai, supportedFeatures) - - // step 4: process the return value from step 3 - if response != nil { - // status code is based on SPEC, and option headers - return httpwrapper.NewResponse(http.StatusOK, nil, response) - } else if problemDetails != nil { - return httpwrapper.NewResponse(int(problemDetails.Status), nil, problemDetails) - } - problemDetails = &models.ProblemDetails{ - Status: http.StatusForbidden, - Cause: "UNSPECIFIED", - } - return httpwrapper.NewResponse(http.StatusForbidden, nil, problemDetails) -} - -// TS 29.503 5.2.2.2.5 -// Session Management Subscription Data Retrieval -func getSmDataProcedure(supi string, plmnID string, Dnn string, Snssai string, supportedFeatures string) ( - response interface{}, problemDetails *models.ProblemDetails, -) { - ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) - if err != nil { - return nil, pd - } - logger.SdmLog.Infof("getSmDataProcedure: SUPI[%s] PLMNID[%s] DNN[%s] SNssai[%s]", supi, plmnID, Dnn, Snssai) - - clientAPI, err := createUDMClientToUDR(supi) - if err != nil { - return nil, openapi.ProblemDetailsSystemFailure(err.Error()) - } - - var querySmDataParamOpts Nudr.QuerySmDataParamOpts - querySmDataParamOpts.SingleNssai = optional.NewInterface(Snssai) - - sessionManagementSubscriptionDataResp, res, err := clientAPI.SessionManagementSubscriptionDataApi. - QuerySmData(ctx, supi, plmnID, &querySmDataParamOpts) - if err != nil { - if res == nil { - logger.SdmLog.Warnln(err) - } else if err.Error() != res.Status { - logger.SdmLog.Warnln(err) - } else { - logger.SdmLog.Warnln(err) - problemDetails = &models.ProblemDetails{ - Status: int32(res.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), - } - - return nil, problemDetails - } - } - defer func() { - if rspCloseErr := res.Body.Close(); rspCloseErr != nil { - logger.SdmLog.Errorf("QuerySmData response body cannot close: %+v", rspCloseErr) - } - }() - - if res.StatusCode == http.StatusOK { - udmUe, ok := udm_context.GetSelf().UdmUeFindBySupi(supi) - if !ok { - udmUe = udm_context.GetSelf().NewUdmUe(supi) - } - smData, snssaikey, AllDnnConfigsbyDnn, AllDnns := udm_context.GetSelf().ManageSmData( - sessionManagementSubscriptionDataResp, Snssai, Dnn) - udmUe.SetSMSubsData(smData) - - rspSMSubDataList := make([]models.SessionManagementSubscriptionData, 0, 4) - - udmUe.SmSubsDataLock.RLock() - for _, eachSMSubData := range udmUe.SessionManagementSubsData { - rspSMSubDataList = append(rspSMSubDataList, eachSMSubData) - } - udmUe.SmSubsDataLock.RUnlock() - - switch { - case Snssai == "" && Dnn == "": - return AllDnns, nil - case Snssai != "" && Dnn == "": - udmUe.SmSubsDataLock.RLock() - defer udmUe.SmSubsDataLock.RUnlock() - return udmUe.SessionManagementSubsData[snssaikey].DnnConfigurations, nil - case Snssai == "" && Dnn != "": - return AllDnnConfigsbyDnn, nil - case Snssai != "" && Dnn != "": - return rspSMSubDataList, nil - default: - udmUe.SmSubsDataLock.RLock() - defer udmUe.SmSubsDataLock.RUnlock() - return udmUe.SessionManagementSubsData, nil - } - } else { - problemDetails = &models.ProblemDetails{ - Status: http.StatusNotFound, - Cause: "DATA_NOT_FOUND", - } - - return nil, problemDetails - } -} - -func HandleGetNssaiRequest(request *httpwrapper.Request) *httpwrapper.Response { - // step 1: log - logger.SdmLog.Infof("Handle GetNssai") - - // step 2: retrieve request - supi := request.Params["supi"] - plmnIDStruct, problemDetails := getPlmnIDStruct(request.Query) - if problemDetails != nil { - return httpwrapper.NewResponse(int(problemDetails.Status), nil, problemDetails) - } - plmnID := plmnIDStruct.Mcc + plmnIDStruct.Mnc - supportedFeatures := request.Query.Get("supported-features") - - // step 3: handle the message - response, problemDetails := getNssaiProcedure(supi, plmnID, supportedFeatures) - - // step 4: process the return value from step 3 - if response != nil { - // status code is based on SPEC, and option headers - return httpwrapper.NewResponse(http.StatusOK, nil, response) - } else if problemDetails != nil { - return httpwrapper.NewResponse(int(problemDetails.Status), nil, problemDetails) - } - problemDetails = &models.ProblemDetails{ - Status: http.StatusForbidden, - Cause: "UNSPECIFIED", - } - return httpwrapper.NewResponse(http.StatusForbidden, nil, problemDetails) -} - -// TS 29.503 5.2.2.2.2 -// Slice Selection Subscription Data Retrieval -func getNssaiProcedure(supi string, plmnID string, supportedFeatures string) ( - *models.Nssai, *models.ProblemDetails, -) { - ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) - if err != nil { - return nil, pd - } - var queryAmDataParamOpts Nudr.QueryAmDataParamOpts - queryAmDataParamOpts.SupportedFeatures = optional.NewString(supportedFeatures) - var nssaiResp models.Nssai - clientAPI, err := createUDMClientToUDR(supi) - if err != nil { - return nil, openapi.ProblemDetailsSystemFailure(err.Error()) - } - - accessAndMobilitySubscriptionDataResp, res, err := clientAPI.AccessAndMobilitySubscriptionDataDocumentApi. - QueryAmData(ctx, supi, plmnID, &queryAmDataParamOpts) - if err != nil { - if res == nil { - logger.SdmLog.Warnln(err) - } else if err.Error() != res.Status { - logger.SdmLog.Warnln(err) - } else { - logger.SdmLog.Warnln(err) - problemDetails := &models.ProblemDetails{ - Status: int32(res.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), - } - - return nil, problemDetails - } - } - defer func() { - if rspCloseErr := res.Body.Close(); rspCloseErr != nil { - logger.SdmLog.Errorf("QueryAmData response body cannot close: %+v", rspCloseErr) - } - }() - - nssaiResp = *accessAndMobilitySubscriptionDataResp.Nssai - - if res.StatusCode == http.StatusOK { - udmUe, ok := udm_context.GetSelf().UdmUeFindBySupi(supi) - if !ok { - udmUe = udm_context.GetSelf().NewUdmUe(supi) - } - udmUe.Nssai = &nssaiResp - return udmUe.Nssai, nil - } else { - problemDetails := &models.ProblemDetails{ - Status: http.StatusNotFound, - Cause: "DATA_NOT_FOUND", - } - return nil, problemDetails - } -} - -func HandleGetSmfSelectDataRequest(request *httpwrapper.Request) *httpwrapper.Response { - // step 1: log - logger.SdmLog.Infof("Handle GetSmfSelectData") - - // step 2: retrieve request - supi := request.Params["supi"] - plmnIDStruct, problemDetails := getPlmnIDStruct(request.Query) - if problemDetails != nil { - return httpwrapper.NewResponse(int(problemDetails.Status), nil, problemDetails) - } - plmnID := plmnIDStruct.Mcc + plmnIDStruct.Mnc - supportedFeatures := request.Query.Get("supported-features") - - // step 3: handle the message - response, problemDetails := getSmfSelectDataProcedure(supi, plmnID, supportedFeatures) - - // step 4: process the return value from step 3 - if response != nil { - // status code is based on SPEC, and option headers - return httpwrapper.NewResponse(http.StatusOK, nil, response) - } else if problemDetails != nil { - return httpwrapper.NewResponse(int(problemDetails.Status), nil, problemDetails) - } - problemDetails = &models.ProblemDetails{ - Status: http.StatusForbidden, - Cause: "UNSPECIFIED", - } - return httpwrapper.NewResponse(http.StatusForbidden, nil, problemDetails) -} - -// TS 29.503 5.2.2.2.4 -// SMF Selection Subscription Data Retrieval -func getSmfSelectDataProcedure(supi string, plmnID string, supportedFeatures string) ( - response *models.SmfSelectionSubscriptionData, problemDetails *models.ProblemDetails, -) { - ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) - if err != nil { - return nil, pd - } - var querySmfSelectDataParamOpts Nudr.QuerySmfSelectDataParamOpts - querySmfSelectDataParamOpts.SupportedFeatures = optional.NewString(supportedFeatures) - var body models.SmfSelectionSubscriptionData - - clientAPI, err := createUDMClientToUDR(supi) - if err != nil { - return nil, openapi.ProblemDetailsSystemFailure(err.Error()) - } - - udm_context.GetSelf().CreateSmfSelectionSubsDataforUe(supi, body) - - smfSelectionSubscriptionDataResp, res, err := clientAPI.SMFSelectionSubscriptionDataDocumentApi. - QuerySmfSelectData(ctx, supi, plmnID, &querySmfSelectDataParamOpts) - if err != nil { - if res == nil { - logger.SdmLog.Warnln(err) - } else if err.Error() != res.Status { - logger.SdmLog.Warnln(err) - } else { - logger.SdmLog.Warnln(err) - problemDetails = &models.ProblemDetails{ - Status: int32(res.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), - } - return nil, problemDetails - } - return nil, problemDetails - } - defer func() { - if rspCloseErr := res.Body.Close(); rspCloseErr != nil { - logger.SdmLog.Errorf("QuerySmfSelectData response body cannot close: %+v", rspCloseErr) - } - }() - - if res.StatusCode == http.StatusOK { - udmUe, ok := udm_context.GetSelf().UdmUeFindBySupi(supi) - if !ok { - udmUe = udm_context.GetSelf().NewUdmUe(supi) - } - udmUe.SetSmfSelectionSubsData(&smfSelectionSubscriptionDataResp) - return udmUe.SmfSelSubsData, nil - } else { - problemDetails = &models.ProblemDetails{ - Status: http.StatusNotFound, - Cause: "DATA_NOT_FOUND", - } - return nil, problemDetails - } -} - -func HandleSubscribeToSharedDataRequest(request *httpwrapper.Request) *httpwrapper.Response { - // step 1: log - logger.SdmLog.Infof("Handle SubscribeToSharedData") - - // step 2: retrieve request - sdmSubscription := request.Body.(models.SdmSubscription) - - // step 3: handle the message - header, response, problemDetails := subscribeToSharedDataProcedure(&sdmSubscription) - - // step 4: process the return value from step 3 - if response != nil { - // status code is based on SPEC, and option headers - return httpwrapper.NewResponse(http.StatusCreated, header, response) - } else if problemDetails != nil { - return httpwrapper.NewResponse(int(problemDetails.Status), nil, problemDetails) - } else { - return httpwrapper.NewResponse(http.StatusNotFound, nil, nil) - } -} - -// TS 29.503 5.2.2.3.3 -// Subscription to notifications of shared data change -func subscribeToSharedDataProcedure(sdmSubscription *models.SdmSubscription) ( - header http.Header, response *models.SdmSubscription, problemDetails *models.ProblemDetails, -) { - ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NUDM_SDM, models.NfType_UDM) - if err != nil { - return nil, nil, pd - } - cfg := Nudm_SubscriberDataManagement.NewConfiguration() - udmClientAPI := Nudm_SubscriberDataManagement.NewAPIClient(cfg) - - sdmSubscriptionResp, res, err := udmClientAPI.SubscriptionCreationForSharedDataApi.SubscribeToSharedData( - ctx, *sdmSubscription) - if err != nil { - if res == nil { - logger.SdmLog.Warnln(err) - } else if err.Error() != res.Status { - logger.SdmLog.Warnln(err) - } else { - problemDetails = &models.ProblemDetails{ - Status: int32(res.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), - } - return nil, nil, problemDetails - } - } - defer func() { - if rspCloseErr := res.Body.Close(); rspCloseErr != nil { - logger.SdmLog.Errorf("SubscribeToSharedData response body cannot close: %+v", rspCloseErr) - } - }() - - if res.StatusCode == http.StatusCreated { - header = make(http.Header) - udm_context.GetSelf().CreateSubstoNotifSharedData(sdmSubscriptionResp.SubscriptionId, &sdmSubscriptionResp) - reourceUri := udm_context.GetSelf().GetSDMUri() + "//shared-data-subscriptions/" + sdmSubscriptionResp.SubscriptionId - header.Set("Location", reourceUri) - return header, &sdmSubscriptionResp, nil - } else if res.StatusCode == http.StatusNotFound { - problemDetails = &models.ProblemDetails{ - Status: http.StatusNotFound, - Cause: "DATA_NOT_FOUND", - } - - return nil, nil, problemDetails - } else { - problemDetails = &models.ProblemDetails{ - Status: http.StatusNotImplemented, - Cause: "UNSUPPORTED_RESOURCE_URI", - } - - return nil, nil, problemDetails - } -} - -func HandleSubscribeRequest(request *httpwrapper.Request) *httpwrapper.Response { - // step 1: log - logger.SdmLog.Infof("Handle Subscribe") - - // step 2: retrieve request - sdmSubscription := request.Body.(models.SdmSubscription) - supi := request.Params["supi"] - - // step 3: handle the message - header, response, problemDetails := subscribeProcedure(&sdmSubscription, supi) - - // step 4: process the return value from step 3 - if response != nil { - // status code is based on SPEC, and option headers - return httpwrapper.NewResponse(http.StatusCreated, header, response) - } else if problemDetails != nil { - return httpwrapper.NewResponse(int(problemDetails.Status), nil, problemDetails) - } else { - return httpwrapper.NewResponse(http.StatusNotFound, nil, nil) - } -} - -// TS 29.503 5.2.2.3.2 -// Subscription to notifications of data change -func subscribeProcedure(sdmSubscription *models.SdmSubscription, supi string) ( - header http.Header, response *models.SdmSubscription, problemDetails *models.ProblemDetails, -) { - ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) - if err != nil { - return nil, nil, pd - } - clientAPI, err := createUDMClientToUDR(supi) - if err != nil { - return nil, nil, openapi.ProblemDetailsSystemFailure(err.Error()) - } - - sdmSubscriptionResp, res, err := clientAPI.SDMSubscriptionsCollectionApi.CreateSdmSubscriptions( - ctx, supi, *sdmSubscription) - if err != nil { - if res == nil { - logger.SdmLog.Warnln(err) - } else if err.Error() != res.Status { - logger.SdmLog.Warnln(err) - } else { - logger.SdmLog.Warnln(err) - problemDetails = &models.ProblemDetails{ - Status: int32(res.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), - } - return nil, nil, problemDetails - } - } - defer func() { - if rspCloseErr := res.Body.Close(); rspCloseErr != nil { - logger.SdmLog.Errorf("CreateSdmSubscriptions response body cannot close: %+v", rspCloseErr) - } - }() - - if res.StatusCode == http.StatusCreated { - header = make(http.Header) - udmUe, _ := udm_context.GetSelf().UdmUeFindBySupi(supi) - if udmUe == nil { - udmUe = udm_context.GetSelf().NewUdmUe(supi) - } - udmUe.CreateSubscriptiontoNotifChange(sdmSubscriptionResp.SubscriptionId, &sdmSubscriptionResp) - header.Set("Location", udmUe.GetLocationURI2(udm_context.LocationUriSdmSubscription, supi)) - return header, &sdmSubscriptionResp, nil - } else if res.StatusCode == http.StatusNotFound { - problemDetails = &models.ProblemDetails{ - Status: http.StatusNotFound, - Cause: "DATA_NOT_FOUND", - } - return nil, nil, problemDetails - } else { - problemDetails = &models.ProblemDetails{ - Status: http.StatusNotImplemented, - Cause: "UNSUPPORTED_RESOURCE_URI", - } - return nil, nil, problemDetails - } -} - -func HandleUnsubscribeForSharedDataRequest(request *httpwrapper.Request) *httpwrapper.Response { - logger.SdmLog.Infof("Handle UnsubscribeForSharedData") - - // step 2: retrieve request - subscriptionID := request.Params["subscriptionId"] - // step 3: handle the message - problemDetails := unsubscribeForSharedDataProcedure(subscriptionID) - - // step 4: process the return value from step 3 - if problemDetails != nil { - return httpwrapper.NewResponse(int(problemDetails.Status), nil, problemDetails) - } - - return httpwrapper.NewResponse(http.StatusNoContent, nil, nil) -} - -// TS 29.503 5.2.2.4.3 -// Unsubscribe to notifications of data change -func unsubscribeForSharedDataProcedure(subscriptionID string) *models.ProblemDetails { - ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NUDM_SDM, models.NfType_UDM) - if err != nil { - return pd - } - cfg := Nudm_SubscriberDataManagement.NewConfiguration() - udmClientAPI := Nudm_SubscriberDataManagement.NewAPIClient(cfg) - - res, err := udmClientAPI.SubscriptionDeletionForSharedDataApi.UnsubscribeForSharedData( - ctx, subscriptionID) - if err != nil { - if res == nil { - logger.SdmLog.Warnln(err) - } else if err.Error() != res.Status { - logger.SdmLog.Warnln(err) - } else { - logger.SdmLog.Warnln(err) - problemDetails := &models.ProblemDetails{ - Status: int32(res.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), - } - return problemDetails - } - } - defer func() { - if rspCloseErr := res.Body.Close(); rspCloseErr != nil { - logger.SdmLog.Errorf("UnsubscribeForSharedData response body cannot close: %+v", rspCloseErr) - } - }() - - if res.StatusCode == http.StatusNoContent { - return nil - } else { - problemDetails := &models.ProblemDetails{ - Status: http.StatusNotFound, - Cause: "DATA_NOT_FOUND", - } - return problemDetails - } -} - -func HandleUnsubscribeRequest(request *httpwrapper.Request) *httpwrapper.Response { - logger.SdmLog.Infof("Handle Unsubscribe") - - // step 2: retrieve request - supi := request.Params["supi"] - subscriptionID := request.Params["subscriptionId"] - - // step 3: handle the message - problemDetails := unsubscribeProcedure(supi, subscriptionID) - - // step 4: process the return value from step 3 - if problemDetails != nil { - return httpwrapper.NewResponse(int(problemDetails.Status), nil, problemDetails) - } - - return httpwrapper.NewResponse(http.StatusNoContent, nil, nil) -} - -// TS 29.503 5.2.2.4.2 -// Unsubscribe to notifications of data change -func unsubscribeProcedure(supi string, subscriptionID string) *models.ProblemDetails { - ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) - if err != nil { - return pd - } - clientAPI, err := createUDMClientToUDR(supi) - if err != nil { - return openapi.ProblemDetailsSystemFailure(err.Error()) - } - - res, err := clientAPI.SDMSubscriptionDocumentApi.RemovesdmSubscriptions(ctx, supi, subscriptionID) - if err != nil { - if res == nil { - logger.SdmLog.Warnln(err) - } else if err.Error() != res.Status { - logger.SdmLog.Warnln(err) - } else { - logger.SdmLog.Warnln(err) - problemDetails := &models.ProblemDetails{ - Status: int32(res.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), - } - return problemDetails - } - } - defer func() { - if rspCloseErr := res.Body.Close(); rspCloseErr != nil { - logger.SdmLog.Errorf("RemovesdmSubscriptions response body cannot close: %+v", rspCloseErr) - } - }() - - if res.StatusCode == http.StatusNoContent { - return nil - } else { - problemDetails := &models.ProblemDetails{ - Status: http.StatusNotFound, - Cause: "USER_NOT_FOUND", - } - return problemDetails - } -} - -func HandleModifyRequest(request *httpwrapper.Request) *httpwrapper.Response { - // step 1: log - logger.SdmLog.Infof("Handle Modify") - - // step 2: retrieve request - sdmSubsModification := request.Body.(models.SdmSubsModification) - supi := request.Params["supi"] - subscriptionID := request.Params["subscriptionId"] - - // step 3: handle the message - response, problemDetails := modifyProcedure(&sdmSubsModification, supi, subscriptionID) - - // step 4: process the return value from step 3 - if response != nil { - // status code is based on SPEC, and option headers - return httpwrapper.NewResponse(http.StatusOK, nil, response) - } else if problemDetails != nil { - return httpwrapper.NewResponse(int(problemDetails.Status), nil, problemDetails) - } - problemDetails = &models.ProblemDetails{ - Status: http.StatusForbidden, - Cause: "UNSPECIFIED", - } - return httpwrapper.NewResponse(http.StatusForbidden, nil, problemDetails) -} - -// TS 29.503 5.2.2.7.2 -// Modification of a subscription to notifications of data change -func modifyProcedure(sdmSubsModification *models.SdmSubsModification, supi string, subscriptionID string) ( - response *models.SdmSubscription, problemDetails *models.ProblemDetails, -) { - ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) - if err != nil { - return nil, pd - } - clientAPI, err := createUDMClientToUDR(supi) - if err != nil { - return nil, openapi.ProblemDetailsSystemFailure(err.Error()) - } - - sdmSubscription := models.SdmSubscription{} - body := Nudr.UpdatesdmsubscriptionsParamOpts{ - SdmSubscription: optional.NewInterface(sdmSubscription), - } - - res, err := clientAPI.SDMSubscriptionDocumentApi.Updatesdmsubscriptions( - ctx, supi, subscriptionID, &body) - if err != nil { - if res == nil { - logger.SdmLog.Warnln(err) - } else if err.Error() != res.Status { - logger.SdmLog.Warnln(err) - } else { - problemDetails = &models.ProblemDetails{ - Status: int32(res.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), - } - return nil, problemDetails - } - } - defer func() { - if rspCloseErr := res.Body.Close(); rspCloseErr != nil { - logger.SdmLog.Errorf("Updatesdmsubscriptions response body cannot close: %+v", rspCloseErr) - } - }() - - if res.StatusCode == http.StatusOK { - return &sdmSubscription, nil - } else { - problemDetails = &models.ProblemDetails{ - Status: http.StatusNotFound, - Cause: "USER_NOT_FOUND", - } - - return nil, problemDetails - } -} - -func HandleModifyForSharedDataRequest(request *httpwrapper.Request) *httpwrapper.Response { - // step 1: log - logger.SdmLog.Infof("Handle ModifyForSharedData") - - // step 2: retrieve request - sdmSubsModification := request.Body.(models.SdmSubsModification) - supi := request.Params["supi"] - subscriptionID := request.Params["subscriptionId"] - - // step 3: handle the message - response, problemDetails := modifyForSharedDataProcedure(&sdmSubsModification, supi, subscriptionID) - - // step 4: process the return value from step 3 - if response != nil { - // status code is based on SPEC, and option headers - return httpwrapper.NewResponse(http.StatusOK, nil, response) - } else if problemDetails != nil { - return httpwrapper.NewResponse(int(problemDetails.Status), nil, problemDetails) - } - problemDetails = &models.ProblemDetails{ - Status: http.StatusForbidden, - Cause: "UNSPECIFIED", - } - return httpwrapper.NewResponse(http.StatusForbidden, nil, problemDetails) -} - -// TS 29.503 5.2.2.7.3 -// Modification of a subscription to notifications of shared data change -func modifyForSharedDataProcedure(sdmSubsModification *models.SdmSubsModification, supi string, - subscriptionID string, -) (response *models.SdmSubscription, problemDetails *models.ProblemDetails) { - ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) - if err != nil { - return nil, pd - } - clientAPI, err := createUDMClientToUDR(supi) - if err != nil { - return nil, openapi.ProblemDetailsSystemFailure(err.Error()) - } - - var sdmSubscription models.SdmSubscription - sdmSubs := models.SdmSubscription{} - body := Nudr.UpdatesdmsubscriptionsParamOpts{ - SdmSubscription: optional.NewInterface(sdmSubs), - } - - res, err := clientAPI.SDMSubscriptionDocumentApi.Updatesdmsubscriptions( - ctx, supi, subscriptionID, &body) - if err != nil { - if res == nil { - logger.SdmLog.Warnln(err) - } else if err.Error() != res.Status { - logger.SdmLog.Warnln(err) - } else { - problemDetails = &models.ProblemDetails{ - Status: int32(res.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), - } - return nil, problemDetails - } - } - defer func() { - if rspCloseErr := res.Body.Close(); rspCloseErr != nil { - logger.SdmLog.Errorf("Updatesdmsubscriptions response body cannot close: %+v", rspCloseErr) - } - }() - - if res.StatusCode == http.StatusOK { - return &sdmSubscription, nil - } else { - problemDetails = &models.ProblemDetails{ - Status: http.StatusNotFound, - Cause: "USER_NOT_FOUND", - } - - return nil, problemDetails - } -} - -func HandleGetTraceDataRequest(request *httpwrapper.Request) *httpwrapper.Response { - // step 1: log - logger.SdmLog.Infof("Handle GetTraceData") - - // step 2: retrieve request - supi := request.Params["supi"] - plmnID := request.Query.Get("plmn-id") - - // step 3: handle the message - response, problemDetails := getTraceDataProcedure(supi, plmnID) - - // step 4: process the return value from step 3 - if response != nil { - // status code is based on SPEC, and option headers - return httpwrapper.NewResponse(http.StatusOK, nil, response) - } else if problemDetails != nil { - return httpwrapper.NewResponse(int(problemDetails.Status), nil, problemDetails) - } - problemDetails = &models.ProblemDetails{ - Status: http.StatusForbidden, - Cause: "UNSPECIFIED", - } - return httpwrapper.NewResponse(http.StatusForbidden, nil, problemDetails) -} - -func getTraceDataProcedure(supi string, plmnID string) ( - response *models.TraceData, problemDetails *models.ProblemDetails, -) { - ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) - if err != nil { - return nil, pd - } - var body models.TraceData - var queryTraceDataParamOpts Nudr.QueryTraceDataParamOpts - - clientAPI, err := createUDMClientToUDR(supi) - if err != nil { - return nil, openapi.ProblemDetailsSystemFailure(err.Error()) - } - - udm_context.GetSelf().CreateTraceDataforUe(supi, body) - - traceDataRes, res, err := clientAPI.TraceDataDocumentApi.QueryTraceData( - ctx, supi, plmnID, &queryTraceDataParamOpts) - if err != nil { - if res == nil { - logger.SdmLog.Warnln(err) - } else if err.Error() != res.Status { - logger.SdmLog.Warnln(err) - } else { - problemDetails = &models.ProblemDetails{ - Status: int32(res.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), - } - - return nil, problemDetails - } - } - defer func() { - if rspCloseErr := res.Body.Close(); rspCloseErr != nil { - logger.SdmLog.Errorf("QueryTraceData response body cannot close: %+v", rspCloseErr) - } - }() - - if res.StatusCode == http.StatusOK { - udmUe, ok := udm_context.GetSelf().UdmUeFindBySupi(supi) - if !ok { - udmUe = udm_context.GetSelf().NewUdmUe(supi) - } - udmUe.TraceData = &traceDataRes - udmUe.TraceDataResponse.TraceData = &traceDataRes - - return udmUe.TraceDataResponse.TraceData, nil - } else { - problemDetails = &models.ProblemDetails{ - Status: http.StatusNotFound, - Cause: "USER_NOT_FOUND", - } - - return nil, problemDetails - } -} - -func HandleGetUeContextInSmfDataRequest(request *httpwrapper.Request) *httpwrapper.Response { - // step 1: log - logger.SdmLog.Infof("Handle GetUeContextInSmfData") - - // step 2: retrieve request - supi := request.Params["supi"] - supportedFeatures := request.Query.Get("supported-features") - - // step 3: handle the message - response, problemDetails := getUeContextInSmfDataProcedure(supi, supportedFeatures) - - // step 4: process the return value from step 3 - if response != nil { - // status code is based on SPEC, and option headers - return httpwrapper.NewResponse(http.StatusOK, nil, response) - } else if problemDetails != nil { - return httpwrapper.NewResponse(int(problemDetails.Status), nil, problemDetails) - } - problemDetails = &models.ProblemDetails{ - Status: http.StatusForbidden, - Cause: "UNSPECIFIED", - } - return httpwrapper.NewResponse(http.StatusForbidden, nil, problemDetails) -} - -func getUeContextInSmfDataProcedure(supi string, supportedFeatures string) ( - response *models.UeContextInSmfData, problemDetails *models.ProblemDetails, -) { - var body models.UeContextInSmfData - var ueContextInSmfData models.UeContextInSmfData - var pgwInfoArray []models.PgwInfo - var querySmfRegListParamOpts Nudr.QuerySmfRegListParamOpts - querySmfRegListParamOpts.SupportedFeatures = optional.NewString(supportedFeatures) - - clientAPI, err := createUDMClientToUDR(supi) - if err != nil { - return nil, openapi.ProblemDetailsSystemFailure(err.Error()) - } - - pduSessionMap := make(map[string]models.PduSession) - udm_context.GetSelf().CreateUeContextInSmfDataforUe(supi, body) - - ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) - if err != nil { - return nil, pd - } - - pdusess, res, err := clientAPI.SMFRegistrationsCollectionApi.QuerySmfRegList( - ctx, supi, &querySmfRegListParamOpts) - if err != nil { - if res == nil { - logger.SdmLog.Infoln(err) - } else if err.Error() != res.Status { - logger.SdmLog.Infoln(err) - } else { - logger.SdmLog.Infoln(err) - problemDetails = &models.ProblemDetails{ - Status: int32(res.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), - } - - return nil, problemDetails - } - } - defer func() { - if rspCloseErr := res.Body.Close(); rspCloseErr != nil { - logger.SdmLog.Errorf("QuerySmfRegList response body cannot close: %+v", rspCloseErr) - } - }() - - for _, element := range pdusess { - var pduSession models.PduSession - pduSession.Dnn = element.Dnn - pduSession.SmfInstanceId = element.SmfInstanceId - pduSession.PlmnId = element.PlmnId - pduSessionMap[strconv.Itoa(int(element.PduSessionId))] = pduSession - } - ueContextInSmfData.PduSessions = pduSessionMap - - for _, element := range pdusess { - var pgwInfo models.PgwInfo - pgwInfo.Dnn = element.Dnn - pgwInfo.PgwFqdn = element.PgwFqdn - pgwInfo.PlmnId = element.PlmnId - pgwInfoArray = append(pgwInfoArray, pgwInfo) - } - ueContextInSmfData.PgwInfo = pgwInfoArray - - if res.StatusCode == http.StatusOK { - udmUe, ok := udm_context.GetSelf().UdmUeFindBySupi(supi) - if !ok { - udmUe = udm_context.GetSelf().NewUdmUe(supi) - } - udmUe.UeCtxtInSmfData = &ueContextInSmfData - return udmUe.UeCtxtInSmfData, nil - } else { - problemDetails = &models.ProblemDetails{ - Status: http.StatusNotFound, - Cause: "DATA_NOT_FOUND", - } - return nil, problemDetails - } -} - -func getPlmnIDStruct(queryParameters url.Values) (plmnIDStruct *models.PlmnId, problemDetails *models.ProblemDetails) { - if queryParameters["plmn-id"] != nil { - plmnIDJson := queryParameters["plmn-id"][0] - plmnIDStruct := &models.PlmnId{} - err := json.Unmarshal([]byte(plmnIDJson), plmnIDStruct) - if err != nil { - logger.SdmLog.Warnln("Unmarshal Error in targetPlmnListtruct: ", err) - } - return plmnIDStruct, nil - } else { - problemDetails := &models.ProblemDetails{ - Title: "Invalid Parameter", - Status: http.StatusBadRequest, - Cause: "No get plmn-id", - } - return nil, problemDetails - } -} - -func containDataSetName(dataSetNames []string, target string) bool { - for _, dataSetName := range dataSetNames { - if dataSetName == target { - return true - } - } - return false -} diff --git a/internal/sbi/producer/ue_context_management.go b/internal/sbi/producer/ue_context_management.go deleted file mode 100644 index f1f9b0c..0000000 --- a/internal/sbi/producer/ue_context_management.go +++ /dev/null @@ -1,742 +0,0 @@ -package producer - -import ( - "fmt" - "net/http" - "strconv" - "strings" - - "github.com/antihax/optional" - - "github.com/free5gc/openapi" - "github.com/free5gc/openapi/Nudr_DataRepository" - "github.com/free5gc/openapi/models" - udm_context "github.com/free5gc/udm/internal/context" - "github.com/free5gc/udm/internal/logger" - "github.com/free5gc/udm/internal/sbi/consumer" - "github.com/free5gc/udm/internal/sbi/producer/callback" - "github.com/free5gc/util/httpwrapper" -) - -func createUDMClientToUDR(id string) (*Nudr_DataRepository.APIClient, error) { - uri := getUdrURI(id) - if uri == "" { - logger.ProcLog.Errorf("ID[%s] does not match any UDR", id) - return nil, fmt.Errorf("No UDR URI found") - } - cfg := Nudr_DataRepository.NewConfiguration() - cfg.SetBasePath(uri) - clientAPI := Nudr_DataRepository.NewAPIClient(cfg) - return clientAPI, nil -} - -func getUdrURI(id string) string { - if strings.Contains(id, "imsi") || strings.Contains(id, "nai") { // supi - ue, ok := udm_context.GetSelf().UdmUeFindBySupi(id) - if ok { - if ue.UdrUri == "" { - ue.UdrUri = consumer.SendNFIntancesUDR(id, consumer.NFDiscoveryToUDRParamSupi) - } - return ue.UdrUri - } else { - ue = udm_context.GetSelf().NewUdmUe(id) - ue.UdrUri = consumer.SendNFIntancesUDR(id, consumer.NFDiscoveryToUDRParamSupi) - return ue.UdrUri - } - } else if strings.Contains(id, "pei") { - var udrURI string - udm_context.GetSelf().UdmUePool.Range(func(key, value interface{}) bool { - ue := value.(*udm_context.UdmUeContext) - if ue.Amf3GppAccessRegistration != nil && ue.Amf3GppAccessRegistration.Pei == id { - if ue.UdrUri == "" { - ue.UdrUri = consumer.SendNFIntancesUDR(ue.Supi, consumer.NFDiscoveryToUDRParamSupi) - } - udrURI = ue.UdrUri - return false - } else if ue.AmfNon3GppAccessRegistration != nil && ue.AmfNon3GppAccessRegistration.Pei == id { - if ue.UdrUri == "" { - ue.UdrUri = consumer.SendNFIntancesUDR(ue.Supi, consumer.NFDiscoveryToUDRParamSupi) - } - udrURI = ue.UdrUri - return false - } - return true - }) - return udrURI - } else if strings.Contains(id, "extgroupid") { - // extra group id - return consumer.SendNFIntancesUDR(id, consumer.NFDiscoveryToUDRParamExtGroupId) - } else if strings.Contains(id, "msisdn") || strings.Contains(id, "extid") { - // gpsi - return consumer.SendNFIntancesUDR(id, consumer.NFDiscoveryToUDRParamGpsi) - } - return consumer.SendNFIntancesUDR("", consumer.NFDiscoveryToUDRParamNone) -} - -func HandleGetAmf3gppAccessRequest(request *httpwrapper.Request) *httpwrapper.Response { - // step 1: log - logger.UecmLog.Infof("Handle HandleGetAmf3gppAccessRequest") - - // step 2: retrieve request - ueID := request.Params["ueId"] - supportedFeatures := request.Query.Get("supported-features") - - // step 3: handle the message - response, problemDetails := GetAmf3gppAccessProcedure(ueID, supportedFeatures) - - // step 4: process the return value from step 3 - if response != nil { - // status code is based on SPEC, and option headers - return httpwrapper.NewResponse(http.StatusOK, nil, response) - } else if problemDetails != nil { - return httpwrapper.NewResponse(int(problemDetails.Status), nil, problemDetails) - } - problemDetails = &models.ProblemDetails{ - Status: http.StatusForbidden, - Cause: "UNSPECIFIED", - } - return httpwrapper.NewResponse(http.StatusForbidden, nil, problemDetails) -} - -func GetAmf3gppAccessProcedure(ueID string, supportedFeatures string) ( - response *models.Amf3GppAccessRegistration, problemDetails *models.ProblemDetails, -) { - ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) - if err != nil { - return nil, pd - } - var queryAmfContext3gppParamOpts Nudr_DataRepository.QueryAmfContext3gppParamOpts - queryAmfContext3gppParamOpts.SupportedFeatures = optional.NewString(supportedFeatures) - - clientAPI, err := createUDMClientToUDR(ueID) - if err != nil { - return nil, openapi.ProblemDetailsSystemFailure(err.Error()) - } - - amf3GppAccessRegistration, resp, err := clientAPI.AMF3GPPAccessRegistrationDocumentApi. - QueryAmfContext3gpp(ctx, ueID, &queryAmfContext3gppParamOpts) - if err != nil { - problemDetails = &models.ProblemDetails{ - Status: int32(resp.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), - } - return nil, problemDetails - } - defer func() { - if rspCloseErr := resp.Body.Close(); rspCloseErr != nil { - logger.SdmLog.Errorf("QueryAmfContext3gpp response body cannot close: %+v", rspCloseErr) - } - }() - - return &amf3GppAccessRegistration, nil -} - -func HandleGetAmfNon3gppAccessRequest(request *httpwrapper.Request) *httpwrapper.Response { - // step 1: log - logger.UecmLog.Infoln("Handle GetAmfNon3gppAccessRequest") - - // step 2: retrieve request - ueId := request.Params["ueId"] - supportedFeatures := request.Query.Get("supported-features") - - var queryAmfContextNon3gppParamOpts Nudr_DataRepository.QueryAmfContextNon3gppParamOpts - queryAmfContextNon3gppParamOpts.SupportedFeatures = optional.NewString(supportedFeatures) - // step 3: handle the message - response, problemDetails := GetAmfNon3gppAccessProcedure(queryAmfContextNon3gppParamOpts, ueId) - - // step 4: process the return value from step 3 - if response != nil { - // status code is based on SPEC, and option headers - return httpwrapper.NewResponse(http.StatusOK, nil, response) - } else if problemDetails != nil { - return httpwrapper.NewResponse(int(problemDetails.Status), nil, problemDetails) - } - problemDetails = &models.ProblemDetails{ - Status: http.StatusForbidden, - Cause: "UNSPECIFIED", - } - return httpwrapper.NewResponse(http.StatusForbidden, nil, problemDetails) -} - -func GetAmfNon3gppAccessProcedure(queryAmfContextNon3gppParamOpts Nudr_DataRepository. - QueryAmfContextNon3gppParamOpts, ueID string) (response *models.AmfNon3GppAccessRegistration, - problemDetails *models.ProblemDetails, -) { - ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) - if err != nil { - return nil, pd - } - clientAPI, err := createUDMClientToUDR(ueID) - if err != nil { - return nil, openapi.ProblemDetailsSystemFailure(err.Error()) - } - - amfNon3GppAccessRegistration, resp, err := clientAPI.AMFNon3GPPAccessRegistrationDocumentApi. - QueryAmfContextNon3gpp(ctx, ueID, &queryAmfContextNon3gppParamOpts) - if err != nil { - problemDetails = &models.ProblemDetails{ - Status: int32(resp.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), - } - return nil, problemDetails - } - defer func() { - if rspCloseErr := resp.Body.Close(); rspCloseErr != nil { - logger.SdmLog.Errorf("QueryAmfContext3gpp response body cannot close: %+v", rspCloseErr) - } - }() - - return &amfNon3GppAccessRegistration, nil -} - -func HandleRegistrationAmf3gppAccessRequest(request *httpwrapper.Request) *httpwrapper.Response { - // step 1: log - logger.UecmLog.Infof("Handle RegistrationAmf3gppAccess") - - // step 2: retrieve request - registerRequest := request.Body.(models.Amf3GppAccessRegistration) - ueID := request.Params["ueId"] - logger.UecmLog.Info("UEID: ", ueID) - - // step 3: handle the message - header, response, problemDetails := RegistrationAmf3gppAccessProcedure(registerRequest, ueID) - - // step 4: process the return value from step 3 - if response != nil { - if header != nil { - // status code is based on SPEC, and option headers - return httpwrapper.NewResponse(http.StatusCreated, header, response) - } - return httpwrapper.NewResponse(http.StatusOK, nil, response) - } else if problemDetails != nil { - return httpwrapper.NewResponse(int(problemDetails.Status), nil, problemDetails) - } else { - return httpwrapper.NewResponse(http.StatusNoContent, nil, nil) - } -} - -// TS 29.503 5.3.2.2.2 -func RegistrationAmf3gppAccessProcedure(registerRequest models.Amf3GppAccessRegistration, ueID string) ( - header http.Header, response *models.Amf3GppAccessRegistration, problemDetails *models.ProblemDetails, -) { - ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) - if err != nil { - return nil, nil, pd - } - // TODO: EPS interworking with N26 is not supported yet in this stage - var oldAmf3GppAccessRegContext *models.Amf3GppAccessRegistration - var ue *udm_context.UdmUeContext - - if udm_context.GetSelf().UdmAmf3gppRegContextExists(ueID) { - ue, _ = udm_context.GetSelf().UdmUeFindBySupi(ueID) - oldAmf3GppAccessRegContext = ue.Amf3GppAccessRegistration - } - - udm_context.GetSelf().CreateAmf3gppRegContext(ueID, registerRequest) - - clientAPI, err := createUDMClientToUDR(ueID) - if err != nil { - return nil, nil, openapi.ProblemDetailsSystemFailure(err.Error()) - } - - var createAmfContext3gppParamOpts Nudr_DataRepository.CreateAmfContext3gppParamOpts - optInterface := optional.NewInterface(registerRequest) - createAmfContext3gppParamOpts.Amf3GppAccessRegistration = optInterface - resp, err := clientAPI.AMF3GPPAccessRegistrationDocumentApi.CreateAmfContext3gpp(ctx, - ueID, &createAmfContext3gppParamOpts) - if err != nil { - logger.UecmLog.Errorln("CreateAmfContext3gpp error : ", err) - problemDetails = &models.ProblemDetails{ - Status: int32(resp.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), - } - return nil, nil, problemDetails - } - defer func() { - if rspCloseErr := resp.Body.Close(); rspCloseErr != nil { - logger.UecmLog.Errorf("CreateAmfContext3gpp response body cannot close: %+v", rspCloseErr) - } - }() - - // TS 23.502 4.2.2.2.2 14d: UDM initiate a Nudm_UECM_DeregistrationNotification to the old AMF - // corresponding to the same (e.g. 3GPP) access, if one exists - if oldAmf3GppAccessRegContext != nil { - if !ue.SameAsStoredGUAMI3gpp(*oldAmf3GppAccessRegContext.Guami) { - // Based on TS 23.502 4.2.2.2.2, If the serving NF removal reason indicated by the UDM is Initial Registration, - // the old AMF invokes the Nsmf_PDUSession_ReleaseSMContext (SM Context ID). Thus we give different - // dereg cause based on registration parameter from serving AMF - deregReason := models.DeregistrationReason_UE_REGISTRATION_AREA_CHANGE - if registerRequest.InitialRegistrationInd { - deregReason = models.DeregistrationReason_UE_INITIAL_REGISTRATION - } - deregistData := models.DeregistrationData{ - DeregReason: deregReason, - AccessType: models.AccessType__3_GPP_ACCESS, - } - - go func() { - logger.UecmLog.Infof("Send DeregNotify to old AMF GUAMI=%v", oldAmf3GppAccessRegContext.Guami) - pd := callback.SendOnDeregistrationNotification(ueID, - oldAmf3GppAccessRegContext.DeregCallbackUri, - deregistData) // Deregistration Notify Triggered - if pd != nil { - logger.UecmLog.Errorf("RegistrationAmf3gppAccess: send DeregNotify fail %v", pd) - } - }() - } - return nil, ®isterRequest, nil - } else { - header = make(http.Header) - udmUe, _ := udm_context.GetSelf().UdmUeFindBySupi(ueID) - header.Set("Location", udmUe.GetLocationURI(udm_context.LocationUriAmf3GppAccessRegistration)) - return header, ®isterRequest, nil - } -} - -// TS 29.503 5.3.2.2.3 -func HandleRegisterAmfNon3gppAccessRequest(request *httpwrapper.Request) *httpwrapper.Response { - // step 1: log - logger.UecmLog.Infof("Handle RegisterAmfNon3gppAccessRequest") - - // step 2: retrieve request - registerRequest := request.Body.(models.AmfNon3GppAccessRegistration) - ueID := request.Params["ueId"] - - // step 3: handle the message - header, response, problemDetails := RegisterAmfNon3gppAccessProcedure(registerRequest, ueID) - - // step 4: process the return value from step 3 - if response != nil { - // status code is based on SPEC, and option headers - return httpwrapper.NewResponse(http.StatusCreated, header, response) - } else if problemDetails != nil { - return httpwrapper.NewResponse(int(problemDetails.Status), nil, problemDetails) - } else { - return httpwrapper.NewResponse(http.StatusNoContent, nil, nil) - } -} - -func RegisterAmfNon3gppAccessProcedure(registerRequest models.AmfNon3GppAccessRegistration, ueID string) ( - header http.Header, response *models.AmfNon3GppAccessRegistration, problemDetails *models.ProblemDetails, -) { - ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) - if err != nil { - return nil, nil, pd - } - var oldAmfNon3GppAccessRegContext *models.AmfNon3GppAccessRegistration - if udm_context.GetSelf().UdmAmfNon3gppRegContextExists(ueID) { - ue, _ := udm_context.GetSelf().UdmUeFindBySupi(ueID) - oldAmfNon3GppAccessRegContext = ue.AmfNon3GppAccessRegistration - } - - udm_context.GetSelf().CreateAmfNon3gppRegContext(ueID, registerRequest) - - clientAPI, err := createUDMClientToUDR(ueID) - if err != nil { - return nil, nil, openapi.ProblemDetailsSystemFailure(err.Error()) - } - - var createAmfContextNon3gppParamOpts Nudr_DataRepository.CreateAmfContextNon3gppParamOpts - optInterface := optional.NewInterface(registerRequest) - createAmfContextNon3gppParamOpts.AmfNon3GppAccessRegistration = optInterface - - resp, err := clientAPI.AMFNon3GPPAccessRegistrationDocumentApi.CreateAmfContextNon3gpp( - ctx, ueID, &createAmfContextNon3gppParamOpts) - if err != nil { - problemDetails = &models.ProblemDetails{ - Status: int32(resp.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), - } - return nil, nil, problemDetails - } - defer func() { - if rspCloseErr := resp.Body.Close(); rspCloseErr != nil { - logger.UecmLog.Errorf("CreateAmfContext3gpp response body cannot close: %+v", rspCloseErr) - } - }() - - // TS 23.502 4.2.2.2.2 14d: UDM initiate a Nudm_UECM_DeregistrationNotification to the old AMF - // corresponding to the same (e.g. 3GPP) access, if one exists - if oldAmfNon3GppAccessRegContext != nil { - deregistData := models.DeregistrationData{ - DeregReason: models.DeregistrationReason_UE_INITIAL_REGISTRATION, - AccessType: models.AccessType_NON_3_GPP_ACCESS, - } - callback.SendOnDeregistrationNotification(ueID, oldAmfNon3GppAccessRegContext.DeregCallbackUri, - deregistData) // Deregistration Notify Triggered - - return nil, nil, nil - } else { - header = make(http.Header) - udmUe, _ := udm_context.GetSelf().UdmUeFindBySupi(ueID) - header.Set("Location", udmUe.GetLocationURI(udm_context.LocationUriAmfNon3GppAccessRegistration)) - return header, ®isterRequest, nil - } -} - -// TODO: ueID may be SUPI or GPSI, but this function did not handle this condition -func HandleUpdateAmf3gppAccessRequest(request *httpwrapper.Request) *httpwrapper.Response { - // step 1: log - logger.UecmLog.Infof("Handle UpdateAmf3gppAccessRequest") - - // step 2: retrieve request - amf3GppAccessRegistrationModification := request.Body.(models.Amf3GppAccessRegistrationModification) - ueID := request.Params["ueId"] - - // step 3: handle the message - problemDetails := UpdateAmf3gppAccessProcedure(amf3GppAccessRegistrationModification, ueID) - - // step 4: process the return value from step 3 - if problemDetails != nil { - return httpwrapper.NewResponse(int(problemDetails.Status), nil, problemDetails) - } else { - return httpwrapper.NewResponse(http.StatusNoContent, nil, nil) - } -} - -func UpdateAmf3gppAccessProcedure(request models.Amf3GppAccessRegistrationModification, ueID string) ( - problemDetails *models.ProblemDetails, -) { - ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) - if err != nil { - return pd - } - var patchItemReqArray []models.PatchItem - currentContext := udm_context.GetSelf().GetAmf3gppRegContext(ueID) - if currentContext == nil { - logger.UecmLog.Errorln("[UpdateAmf3gppAccess] Empty Amf3gppRegContext") - problemDetails = &models.ProblemDetails{ - Status: http.StatusNotFound, - Cause: "CONTEXT_NOT_FOUND", - } - return problemDetails - } - - if request.Guami != nil { - udmUe, _ := udm_context.GetSelf().UdmUeFindBySupi(ueID) - if udmUe.SameAsStoredGUAMI3gpp(*request.Guami) { // deregistration - logger.UecmLog.Infoln("UpdateAmf3gppAccess - deregistration") - request.PurgeFlag = true - } else { - logger.UecmLog.Errorln("INVALID_GUAMI") - problemDetails = &models.ProblemDetails{ - Status: http.StatusForbidden, - Cause: "INVALID_GUAMI", - } - return problemDetails - } - - var patchItemTmp models.PatchItem - patchItemTmp.Path = "/" + "guami" - patchItemTmp.Op = models.PatchOperation_REPLACE - patchItemTmp.Value = *request.Guami - patchItemReqArray = append(patchItemReqArray, patchItemTmp) - } - - if request.PurgeFlag { - var patchItemTmp models.PatchItem - patchItemTmp.Path = "/" + "purgeFlag" - patchItemTmp.Op = models.PatchOperation_REPLACE - patchItemTmp.Value = request.PurgeFlag - patchItemReqArray = append(patchItemReqArray, patchItemTmp) - } - - if request.Pei != "" { - var patchItemTmp models.PatchItem - patchItemTmp.Path = "/" + "pei" - patchItemTmp.Op = models.PatchOperation_REPLACE - patchItemTmp.Value = request.Pei - patchItemReqArray = append(patchItemReqArray, patchItemTmp) - } - - if request.ImsVoPs != "" { - var patchItemTmp models.PatchItem - patchItemTmp.Path = "/" + "imsVoPs" - patchItemTmp.Op = models.PatchOperation_REPLACE - patchItemTmp.Value = request.ImsVoPs - patchItemReqArray = append(patchItemReqArray, patchItemTmp) - } - - if request.BackupAmfInfo != nil { - var patchItemTmp models.PatchItem - patchItemTmp.Path = "/" + "backupAmfInfo" - patchItemTmp.Op = models.PatchOperation_REPLACE - patchItemTmp.Value = request.BackupAmfInfo - patchItemReqArray = append(patchItemReqArray, patchItemTmp) - } - - clientAPI, err := createUDMClientToUDR(ueID) - if err != nil { - return openapi.ProblemDetailsSystemFailure(err.Error()) - } - - resp, err := clientAPI.AMF3GPPAccessRegistrationDocumentApi.AmfContext3gpp(ctx, ueID, - patchItemReqArray) - if err != nil { - problemDetails = &models.ProblemDetails{ - Status: int32(resp.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), - } - - return problemDetails - } - - if request.PurgeFlag { - udmUe, _ := udm_context.GetSelf().UdmUeFindBySupi(ueID) - udmUe.Amf3GppAccessRegistration = nil - } - - defer func() { - if rspCloseErr := resp.Body.Close(); rspCloseErr != nil { - logger.UecmLog.Errorf("AmfContext3gpp response body cannot close: %+v", rspCloseErr) - } - }() - - return nil -} - -// TODO: ueID may be SUPI or GPSI, but this function did not handle this condition -func HandleUpdateAmfNon3gppAccessRequest(request *httpwrapper.Request) *httpwrapper.Response { - // step 1: log - logger.UecmLog.Infof("Handle UpdateAmfNon3gppAccessRequest") - - // step 2: retrieve request - requestMSG := request.Body.(models.AmfNon3GppAccessRegistrationModification) - ueID := request.Params["ueId"] - - // step 3: handle the message - problemDetails := UpdateAmfNon3gppAccessProcedure(requestMSG, ueID) - - // step 4: process the return value from step 3 - if problemDetails != nil { - return httpwrapper.NewResponse(int(problemDetails.Status), nil, problemDetails) - } else { - return httpwrapper.NewResponse(http.StatusNoContent, nil, nil) - } -} - -func UpdateAmfNon3gppAccessProcedure(request models.AmfNon3GppAccessRegistrationModification, ueID string) ( - problemDetails *models.ProblemDetails, -) { - ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) - if err != nil { - return pd - } - var patchItemReqArray []models.PatchItem - currentContext := udm_context.GetSelf().GetAmfNon3gppRegContext(ueID) - if currentContext == nil { - logger.UecmLog.Errorln("[UpdateAmfNon3gppAccess] Empty AmfNon3gppRegContext") - problemDetails = &models.ProblemDetails{ - Status: http.StatusNotFound, - Cause: "CONTEXT_NOT_FOUND", - } - return problemDetails - } - - if request.Guami != nil { - udmUe, _ := udm_context.GetSelf().UdmUeFindBySupi(ueID) - if udmUe.SameAsStoredGUAMINon3gpp(*request.Guami) { // deregistration - logger.UecmLog.Infoln("UpdateAmfNon3gppAccess - deregistration") - request.PurgeFlag = true - } else { - logger.UecmLog.Errorln("INVALID_GUAMI") - problemDetails = &models.ProblemDetails{ - Status: http.StatusForbidden, - Cause: "INVALID_GUAMI", - } - } - - var patchItemTmp models.PatchItem - patchItemTmp.Path = "/" + "guami" - patchItemTmp.Op = models.PatchOperation_REPLACE - patchItemTmp.Value = *request.Guami - patchItemReqArray = append(patchItemReqArray, patchItemTmp) - } - - if request.PurgeFlag { - var patchItemTmp models.PatchItem - patchItemTmp.Path = "/" + "purgeFlag" - patchItemTmp.Op = models.PatchOperation_REPLACE - patchItemTmp.Value = request.PurgeFlag - patchItemReqArray = append(patchItemReqArray, patchItemTmp) - } - - if request.Pei != "" { - var patchItemTmp models.PatchItem - patchItemTmp.Path = "/" + "pei" - patchItemTmp.Op = models.PatchOperation_REPLACE - patchItemTmp.Value = request.Pei - patchItemReqArray = append(patchItemReqArray, patchItemTmp) - } - - if request.ImsVoPs != "" { - var patchItemTmp models.PatchItem - patchItemTmp.Path = "/" + "imsVoPs" - patchItemTmp.Op = models.PatchOperation_REPLACE - patchItemTmp.Value = request.ImsVoPs - patchItemReqArray = append(patchItemReqArray, patchItemTmp) - } - - if request.BackupAmfInfo != nil { - var patchItemTmp models.PatchItem - patchItemTmp.Path = "/" + "backupAmfInfo" - patchItemTmp.Op = models.PatchOperation_REPLACE - patchItemTmp.Value = request.BackupAmfInfo - patchItemReqArray = append(patchItemReqArray, patchItemTmp) - } - - clientAPI, err := createUDMClientToUDR(ueID) - if err != nil { - return openapi.ProblemDetailsSystemFailure(err.Error()) - } - - resp, err := clientAPI.AMFNon3GPPAccessRegistrationDocumentApi.AmfContextNon3gpp(ctx, - ueID, patchItemReqArray) - if err != nil { - problemDetails = &models.ProblemDetails{ - Status: int32(resp.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), - } - return problemDetails - } - defer func() { - if rspCloseErr := resp.Body.Close(); rspCloseErr != nil { - logger.UecmLog.Errorf("AmfContextNon3gpp response body cannot close: %+v", rspCloseErr) - } - }() - - return problemDetails -} - -func HandleDeregistrationSmfRegistrations(request *httpwrapper.Request) *httpwrapper.Response { - // step 1: log - logger.UecmLog.Infof("Handle DeregistrationSmfRegistrations") - - // step 2: retrieve request - ueID := request.Params["ueId"] - pduSessionID := request.Params["pduSessionId"] - - // step 3: handle the message - problemDetails := DeregistrationSmfRegistrationsProcedure(ueID, pduSessionID) - - // step 4: process the return value from step 3 - if problemDetails != nil { - return httpwrapper.NewResponse(int(problemDetails.Status), nil, problemDetails) - } else { - return httpwrapper.NewResponse(http.StatusNoContent, nil, nil) - } -} - -func DeregistrationSmfRegistrationsProcedure(ueID string, pduSessionID string) (problemDetails *models.ProblemDetails) { - ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) - if err != nil { - return pd - } - clientAPI, err := createUDMClientToUDR(ueID) - if err != nil { - return openapi.ProblemDetailsSystemFailure(err.Error()) - } - - resp, err := clientAPI.SMFRegistrationDocumentApi.DeleteSmfContext(ctx, ueID, pduSessionID) - if err != nil { - problemDetails = &models.ProblemDetails{ - Status: int32(resp.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), - } - return problemDetails - } - defer func() { - if rspCloseErr := resp.Body.Close(); rspCloseErr != nil { - logger.UecmLog.Errorf("DeleteSmfContext response body cannot close: %+v", rspCloseErr) - } - }() - - return nil -} - -// SmfRegistrations -func HandleRegistrationSmfRegistrationsRequest(request *httpwrapper.Request) *httpwrapper.Response { - // step 1: log - logger.UecmLog.Infof("Handle RegistrationSmfRegistrations") - - // step 2: retrieve request - registerRequest := request.Body.(models.SmfRegistration) - ueID := request.Params["ueId"] - pduSessionID := request.Params["pduSessionId"] - - // step 3: handle the message - header, response, problemDetails := RegistrationSmfRegistrationsProcedure(®isterRequest, ueID, pduSessionID) - - // step 4: process the return value from step 3 - if response != nil { - // status code is based on SPEC, and option headers - return httpwrapper.NewResponse(http.StatusCreated, header, response) - } else if problemDetails != nil { - return httpwrapper.NewResponse(int(problemDetails.Status), nil, problemDetails) - } else { - // all nil - return httpwrapper.NewResponse(http.StatusNoContent, nil, nil) - } -} - -// SmfRegistrationsProcedure -func RegistrationSmfRegistrationsProcedure(request *models.SmfRegistration, ueID string, pduSessionID string) ( - header http.Header, response *models.SmfRegistration, problemDetails *models.ProblemDetails, -) { - ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) - if err != nil { - return nil, nil, pd - } - contextExisted := false - udm_context.GetSelf().CreateSmfRegContext(ueID, pduSessionID) - if !udm_context.GetSelf().UdmSmfRegContextNotExists(ueID) { - contextExisted = true - } - - pduID64, err := strconv.ParseInt(pduSessionID, 10, 32) - if err != nil { - logger.UecmLog.Errorln(err.Error()) - } - pduID32 := int32(pduID64) - - var createSmfContextNon3gppParamOpts Nudr_DataRepository.CreateSmfContextNon3gppParamOpts - optInterface := optional.NewInterface(*request) - createSmfContextNon3gppParamOpts.SmfRegistration = optInterface - - clientAPI, err := createUDMClientToUDR(ueID) - if err != nil { - return nil, nil, openapi.ProblemDetailsSystemFailure(err.Error()) - } - - resp, err := clientAPI.SMFRegistrationDocumentApi.CreateSmfContextNon3gpp(ctx, ueID, - pduID32, &createSmfContextNon3gppParamOpts) - if err != nil { - problemDetails = &models.ProblemDetails{ - Status: int32(resp.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), - } - return nil, nil, problemDetails - } - defer func() { - if rspCloseErr := resp.Body.Close(); rspCloseErr != nil { - logger.UecmLog.Errorf("CreateSmfContextNon3gpp response body cannot close: %+v", rspCloseErr) - } - }() - - if contextExisted { - return nil, nil, nil - } else { - header = make(http.Header) - udmUe, _ := udm_context.GetSelf().UdmUeFindBySupi(ueID) - header.Set("Location", udmUe.GetLocationURI(udm_context.LocationUriSmfRegistration)) - return header, request, nil - } -} diff --git a/internal/sbi/subscriberdatamanagement/api_access_and_mobility_subscription_data_retrieval.go b/internal/sbi/subscriberdatamanagement/api_access_and_mobility_subscription_data_retrieval.go deleted file mode 100644 index d1150f3..0000000 --- a/internal/sbi/subscriberdatamanagement/api_access_and_mobility_subscription_data_retrieval.go +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Nudm_SDM - * - * Nudm Subscriber Data Management Service - * - * API version: 2.0.0 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package subscriberdatamanagement - -import ( - "net/http" - - "github.com/gin-gonic/gin" - - "github.com/free5gc/openapi" - "github.com/free5gc/openapi/models" - "github.com/free5gc/udm/internal/logger" - "github.com/free5gc/udm/internal/sbi/producer" - "github.com/free5gc/util/httpwrapper" -) - -// GetAmData - retrieve a UE's Access and Mobility Subscription Data -func HTTPGetAmData(c *gin.Context) { - req := httpwrapper.NewRequest(c.Request, nil) - req.Params["supi"] = c.Params.ByName("supi") - req.Query.Set("plmn-id", c.Query("plmn-id")) - req.Query.Set("supported-features", c.Query("plmn-id")) - - rsp := producer.HandleGetAmDataRequest(req) - - responseBody, err := openapi.Serialize(rsp.Body, "application/json") - if err != nil { - logger.SdmLog.Errorln(err) - problemDetails := models.ProblemDetails{ - Status: http.StatusInternalServerError, - Cause: "SYSTEM_FAILURE", - Detail: err.Error(), - } - c.JSON(http.StatusInternalServerError, problemDetails) - } else { - c.Data(rsp.Status, "application/json", responseBody) - } -} diff --git a/internal/sbi/subscriberdatamanagement/api_gpsi_to_supi_translation.go b/internal/sbi/subscriberdatamanagement/api_gpsi_to_supi_translation.go deleted file mode 100644 index 2627f48..0000000 --- a/internal/sbi/subscriberdatamanagement/api_gpsi_to_supi_translation.go +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Nudm_SDM - * - * Nudm Subscriber Data Management Service - * - * API version: 2.0.0 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package subscriberdatamanagement - -import ( - "net/http" - - "github.com/gin-gonic/gin" - - "github.com/free5gc/openapi" - "github.com/free5gc/openapi/models" - "github.com/free5gc/udm/internal/logger" - "github.com/free5gc/udm/internal/sbi/producer" - "github.com/free5gc/util/httpwrapper" -) - -// GetIdTranslationResult - retrieve a UE's SUPI -func HTTPGetIdTranslationResult(c *gin.Context) { - req := httpwrapper.NewRequest(c.Request, nil) - req.Params["gpsi"] = c.Params.ByName("gpsi") - req.Query.Set("SupportedFeatures", c.Query("supported-features")) - - rsp := producer.HandleGetIdTranslationResultRequest(req) - - responseBody, err := openapi.Serialize(rsp.Body, "application/json") - if err != nil { - logger.SdmLog.Errorln(err) - problemDetails := models.ProblemDetails{ - Status: http.StatusInternalServerError, - Cause: "SYSTEM_FAILURE", - Detail: err.Error(), - } - c.JSON(http.StatusInternalServerError, problemDetails) - } else { - c.Data(rsp.Status, "application/json", responseBody) - } -} diff --git a/internal/sbi/subscriberdatamanagement/api_providing_acknowledgement_of_steering_of_roaming.go b/internal/sbi/subscriberdatamanagement/api_providing_acknowledgement_of_steering_of_roaming.go deleted file mode 100644 index b85f54e..0000000 --- a/internal/sbi/subscriberdatamanagement/api_providing_acknowledgement_of_steering_of_roaming.go +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Nudm_SDM - * - * Nudm Subscriber Data Management Service - * - * API version: 2.0.0 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package subscriberdatamanagement - -import ( - "net/http" - - "github.com/gin-gonic/gin" -) - -// Info - Nudm_Sdm Info service operation -func HTTPInfo(c *gin.Context) { - c.JSON(http.StatusOK, gin.H{}) -} diff --git a/internal/sbi/subscriberdatamanagement/api_providing_acknowledgement_of_ue_parameters_update.go b/internal/sbi/subscriberdatamanagement/api_providing_acknowledgement_of_ue_parameters_update.go deleted file mode 100644 index ac34c44..0000000 --- a/internal/sbi/subscriberdatamanagement/api_providing_acknowledgement_of_ue_parameters_update.go +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Nudm_SDM - * - * Nudm Subscriber Data Management Service - * - * API version: 2.0.0 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package subscriberdatamanagement - -import ( - "net/http" - - "github.com/gin-gonic/gin" -) - -// PutUpuAck - Nudm_Sdm Info for UPU service operation -func HTTPPutUpuAck(c *gin.Context) { - c.JSON(http.StatusOK, gin.H{}) -} diff --git a/internal/sbi/subscriberdatamanagement/api_retrieval_of_multiple_data_sets.go b/internal/sbi/subscriberdatamanagement/api_retrieval_of_multiple_data_sets.go deleted file mode 100644 index ae5fb82..0000000 --- a/internal/sbi/subscriberdatamanagement/api_retrieval_of_multiple_data_sets.go +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Nudm_SDM - * - * Nudm Subscriber Data Management Service - * - * API version: 2.0.0 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package subscriberdatamanagement - -import ( - "net/http" - - "github.com/gin-gonic/gin" - - "github.com/free5gc/openapi" - "github.com/free5gc/openapi/models" - "github.com/free5gc/udm/internal/logger" - "github.com/free5gc/udm/internal/sbi/producer" - "github.com/free5gc/util/httpwrapper" -) - -// GetSupi - retrieve multiple data sets -func HTTPGetSupi(c *gin.Context) { - req := httpwrapper.NewRequest(c.Request, nil) - req.Params["supi"] = c.Params.ByName("supi") - req.Query.Set("plmn-id", c.Query("plmn-id")) - req.Query.Set("dataset-names", c.Query("dataset-names")) - req.Query.Set("supported-features", c.Query("supported-features")) - - rsp := producer.HandleGetSupiRequest(req) - responseBody, err := openapi.Serialize(rsp.Body, "application/json") - if err != nil { - logger.SdmLog.Errorln(err) - problemDetails := models.ProblemDetails{ - Status: http.StatusInternalServerError, - Cause: "SYSTEM_FAILURE", - Detail: err.Error(), - } - c.JSON(http.StatusInternalServerError, problemDetails) - } else { - c.Data(rsp.Status, "application/json", responseBody) - } -} diff --git a/internal/sbi/subscriberdatamanagement/api_retrieval_of_shared_data.go b/internal/sbi/subscriberdatamanagement/api_retrieval_of_shared_data.go deleted file mode 100644 index 2a97023..0000000 --- a/internal/sbi/subscriberdatamanagement/api_retrieval_of_shared_data.go +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Nudm_SDM - * - * Nudm Subscriber Data Management Service - * - * API version: 2.0.0 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package subscriberdatamanagement - -import ( - "net/http" - - "github.com/gin-gonic/gin" - - "github.com/free5gc/openapi" - "github.com/free5gc/openapi/models" - "github.com/free5gc/udm/internal/logger" - "github.com/free5gc/udm/internal/sbi/producer" - "github.com/free5gc/util/httpwrapper" -) - -// GetSharedData - retrieve shared data -func HTTPGetSharedData(c *gin.Context) { - req := httpwrapper.NewRequest(c.Request, nil) - req.Query["sharedDataIds"] = c.QueryArray("shared-data-ids") - req.Query["supported-features"] = c.QueryArray("supported-features") - - rsp := producer.HandleGetSharedDataRequest(req) - - // step 5: response - responseBody, err := openapi.Serialize(rsp.Body, "application/json") - if err != nil { - logger.SdmLog.Errorln(err) - problemDetails := models.ProblemDetails{ - Status: http.StatusInternalServerError, - Cause: "SYSTEM_FAILURE", - Detail: err.Error(), - } - c.JSON(http.StatusInternalServerError, problemDetails) - } else { - c.Data(rsp.Status, "application/json", responseBody) - } -} diff --git a/internal/sbi/subscriberdatamanagement/api_session_management_subscription_data_retrieval.go b/internal/sbi/subscriberdatamanagement/api_session_management_subscription_data_retrieval.go deleted file mode 100644 index d8c2cb3..0000000 --- a/internal/sbi/subscriberdatamanagement/api_session_management_subscription_data_retrieval.go +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Nudm_SDM - * - * Nudm Subscriber Data Management Service - * - * API version: 2.0.0 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package subscriberdatamanagement - -import ( - "net/http" - - "github.com/gin-gonic/gin" - - "github.com/free5gc/openapi" - "github.com/free5gc/openapi/models" - "github.com/free5gc/udm/internal/logger" - "github.com/free5gc/udm/internal/sbi/producer" - "github.com/free5gc/util/httpwrapper" -) - -// GetSmData - retrieve a UE's Session Management Subscription Data -func HTTPGetSmData(c *gin.Context) { - req := httpwrapper.NewRequest(c.Request, nil) - req.Params["supi"] = c.Param("supi") - req.Query.Set("plmn-id", c.Query("plmn-id")) - req.Query.Set("dnn", c.Query("dnn")) - req.Query.Set("single-nssai", c.Query("single-nssai")) - req.Query.Set("supported-features", c.Query("supported-features")) - - rsp := producer.HandleGetSmDataRequest(req) - - responseBody, err := openapi.Serialize(rsp.Body, "application/json") - if err != nil { - logger.SdmLog.Errorln(err) - problemDetails := models.ProblemDetails{ - Status: http.StatusInternalServerError, - Cause: "SYSTEM_FAILURE", - Detail: err.Error(), - } - c.JSON(http.StatusInternalServerError, problemDetails) - } else { - c.Data(rsp.Status, "application/json", responseBody) - } -} diff --git a/internal/sbi/subscriberdatamanagement/api_slice_selection_subscription_data_retrieval.go b/internal/sbi/subscriberdatamanagement/api_slice_selection_subscription_data_retrieval.go deleted file mode 100644 index 61cb6c7..0000000 --- a/internal/sbi/subscriberdatamanagement/api_slice_selection_subscription_data_retrieval.go +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Nudm_SDM - * - * Nudm Subscriber Data Management Service - * - * API version: 2.0.0 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package subscriberdatamanagement - -import ( - "net/http" - - "github.com/gin-gonic/gin" - - "github.com/free5gc/openapi" - "github.com/free5gc/openapi/models" - "github.com/free5gc/udm/internal/logger" - "github.com/free5gc/udm/internal/sbi/producer" - "github.com/free5gc/util/httpwrapper" -) - -// GetNssai - retrieve a UE's subscribed NSSAI -func HTTPGetNssai(c *gin.Context) { - req := httpwrapper.NewRequest(c.Request, nil) - req.Params["supi"] = c.Params.ByName("supi") - req.Query.Set("plmn-id", c.Query("plmn-id")) - req.Query.Set("supported-features", c.Query("supported-features")) - - rsp := producer.HandleGetNssaiRequest(req) - - responseBody, err := openapi.Serialize(rsp.Body, "application/json") - if err != nil { - logger.SdmLog.Errorln(err) - problemDetails := models.ProblemDetails{ - Status: http.StatusInternalServerError, - Cause: "SYSTEM_FAILURE", - Detail: err.Error(), - } - c.JSON(http.StatusInternalServerError, problemDetails) - } else { - c.Data(rsp.Status, "application/json", responseBody) - } -} diff --git a/internal/sbi/subscriberdatamanagement/api_smf_selection_subscription_data_retrieval.go b/internal/sbi/subscriberdatamanagement/api_smf_selection_subscription_data_retrieval.go deleted file mode 100644 index 6d1a289..0000000 --- a/internal/sbi/subscriberdatamanagement/api_smf_selection_subscription_data_retrieval.go +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Nudm_SDM - * - * Nudm Subscriber Data Management Service - * - * API version: 2.0.0 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package subscriberdatamanagement - -import ( - "net/http" - - "github.com/gin-gonic/gin" - - "github.com/free5gc/openapi" - "github.com/free5gc/openapi/models" - "github.com/free5gc/udm/internal/logger" - "github.com/free5gc/udm/internal/sbi/producer" - "github.com/free5gc/util/httpwrapper" -) - -// GetSmfSelectData - retrieve a UE's SMF Selection Subscription Data -func HTTPGetSmfSelectData(c *gin.Context) { - req := httpwrapper.NewRequest(c.Request, nil) - req.Params["supi"] = c.Params.ByName("supi") - req.Query.Set("plmn-id", c.Query("plmn-id")) - req.Query.Set("supported-features", c.Query("supported-features")) - - rsp := producer.HandleGetSmfSelectDataRequest(req) - responseBody, err := openapi.Serialize(rsp.Body, "application/json") - if err != nil { - logger.SdmLog.Errorln(err) - problemDetails := models.ProblemDetails{ - Status: http.StatusInternalServerError, - Cause: "SYSTEM_FAILURE", - Detail: err.Error(), - } - c.JSON(http.StatusInternalServerError, problemDetails) - } else { - c.Data(rsp.Status, "application/json", responseBody) - } -} diff --git a/internal/sbi/subscriberdatamanagement/api_sms_management_subscription_data_retrieval.go b/internal/sbi/subscriberdatamanagement/api_sms_management_subscription_data_retrieval.go deleted file mode 100644 index cf4cc6d..0000000 --- a/internal/sbi/subscriberdatamanagement/api_sms_management_subscription_data_retrieval.go +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Nudm_SDM - * - * Nudm Subscriber Data Management Service - * - * API version: 2.0.0 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package subscriberdatamanagement - -import ( - "net/http" - - "github.com/gin-gonic/gin" -) - -// GetSmsMngData - retrieve a UE's SMS Management Subscription Data -func HTTPGetSmsMngData(c *gin.Context) { - c.JSON(http.StatusOK, gin.H{}) -} diff --git a/internal/sbi/subscriberdatamanagement/api_sms_subscription_data_retrieval.go b/internal/sbi/subscriberdatamanagement/api_sms_subscription_data_retrieval.go deleted file mode 100644 index ec535c3..0000000 --- a/internal/sbi/subscriberdatamanagement/api_sms_subscription_data_retrieval.go +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Nudm_SDM - * - * Nudm Subscriber Data Management Service - * - * API version: 2.0.0 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package subscriberdatamanagement - -import ( - "net/http" - - "github.com/gin-gonic/gin" -) - -// GetSmsData - retrieve a UE's SMS Subscription Data -func HTTPGetSmsData(c *gin.Context) { - c.JSON(http.StatusOK, gin.H{}) -} diff --git a/internal/sbi/subscriberdatamanagement/api_subscription_creation.go b/internal/sbi/subscriberdatamanagement/api_subscription_creation.go deleted file mode 100644 index 51adf05..0000000 --- a/internal/sbi/subscriberdatamanagement/api_subscription_creation.go +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Nudm_SDM - * - * Nudm Subscriber Data Management Service - * - * API version: 2.0.0 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package subscriberdatamanagement - -import ( - "net/http" - - "github.com/gin-gonic/gin" - - "github.com/free5gc/openapi" - "github.com/free5gc/openapi/models" - "github.com/free5gc/udm/internal/logger" - "github.com/free5gc/udm/internal/sbi/producer" - "github.com/free5gc/util/httpwrapper" -) - -// Subscribe - subscribe to notifications -func HTTPSubscribe(c *gin.Context) { - var sdmSubscriptionReq models.SdmSubscription - - // step 1: retrieve http request body - requestBody, err := c.GetRawData() - if err != nil { - problemDetail := models.ProblemDetails{ - Title: "System failure", - Status: http.StatusInternalServerError, - Detail: err.Error(), - Cause: "SYSTEM_FAILURE", - } - logger.SdmLog.Errorf("Get Request Body error: %+v", err) - c.JSON(http.StatusInternalServerError, problemDetail) - return - } - - // step 2: convert requestBody to openapi models - err = openapi.Deserialize(&sdmSubscriptionReq, requestBody, "application/json") - if err != nil { - problemDetail := "[Request Body] " + err.Error() - rsp := models.ProblemDetails{ - Title: "Malformed request syntax", - Status: http.StatusBadRequest, - Detail: problemDetail, - } - logger.SdmLog.Errorln(problemDetail) - c.JSON(http.StatusBadRequest, rsp) - return - } - - req := httpwrapper.NewRequest(c.Request, sdmSubscriptionReq) - req.Params["supi"] = c.Params.ByName("supi") - - rsp := producer.HandleSubscribeRequest(req) - - for key, val := range rsp.Header { // header response is optional - c.Header(key, val[0]) - } - responseBody, err := openapi.Serialize(rsp.Body, "application/json") - if err != nil { - logger.SdmLog.Errorln(err) - problemDetails := models.ProblemDetails{ - Status: http.StatusInternalServerError, - Cause: "SYSTEM_FAILURE", - Detail: err.Error(), - } - c.JSON(http.StatusInternalServerError, problemDetails) - } else { - c.Data(rsp.Status, "application/json", responseBody) - } -} diff --git a/internal/sbi/subscriberdatamanagement/api_subscription_creation_for_shared_data.go b/internal/sbi/subscriberdatamanagement/api_subscription_creation_for_shared_data.go deleted file mode 100644 index a6c8744..0000000 --- a/internal/sbi/subscriberdatamanagement/api_subscription_creation_for_shared_data.go +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Nudm_SDM - * - * Nudm Subscriber Data Management Service - * - * API version: 2.0.0 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package subscriberdatamanagement - -import ( - "net/http" - - "github.com/gin-gonic/gin" - - "github.com/free5gc/openapi" - "github.com/free5gc/openapi/models" - "github.com/free5gc/udm/internal/logger" - "github.com/free5gc/udm/internal/sbi/producer" - "github.com/free5gc/util/httpwrapper" -) - -// SubscribeToSharedData - subscribe to notifications for shared data -func HTTPSubscribeToSharedData(c *gin.Context) { - var sharedDataSubsReq models.SdmSubscription - // step 1: retrieve http request body - requestBody, err := c.GetRawData() - if err != nil { - problemDetail := models.ProblemDetails{ - Title: "System failure", - Status: http.StatusInternalServerError, - Detail: err.Error(), - Cause: "SYSTEM_FAILURE", - } - logger.SdmLog.Errorf("Get Request Body error: %+v", err) - c.JSON(http.StatusInternalServerError, problemDetail) - return - } - - // step 2: convert requestBody to openapi models - err = openapi.Deserialize(&sharedDataSubsReq, requestBody, "application/json") - if err != nil { - problemDetail := "[Request Body] " + err.Error() - rsp := models.ProblemDetails{ - Title: "Malformed request syntax", - Status: http.StatusBadRequest, - Detail: problemDetail, - } - logger.SdmLog.Errorln(problemDetail) - c.JSON(http.StatusBadRequest, rsp) - return - } - - req := httpwrapper.NewRequest(c.Request, sharedDataSubsReq) - rsp := producer.HandleSubscribeToSharedDataRequest(req) - // step 5: response - for key, val := range rsp.Header { // header response is optional - c.Header(key, val[0]) - } - responseBody, err := openapi.Serialize(rsp.Body, "application/json") - if err != nil { - logger.SdmLog.Errorln(err) - problemDetails := models.ProblemDetails{ - Status: http.StatusInternalServerError, - Cause: "SYSTEM_FAILURE", - Detail: err.Error(), - } - c.JSON(http.StatusInternalServerError, problemDetails) - } else { - c.Data(rsp.Status, "application/json", responseBody) - } -} diff --git a/internal/sbi/subscriberdatamanagement/api_subscription_deletion.go b/internal/sbi/subscriberdatamanagement/api_subscription_deletion.go deleted file mode 100644 index c7870d9..0000000 --- a/internal/sbi/subscriberdatamanagement/api_subscription_deletion.go +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Nudm_SDM - * - * Nudm Subscriber Data Management Service - * - * API version: 2.0.0 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package subscriberdatamanagement - -import ( - "net/http" - - "github.com/gin-gonic/gin" - - "github.com/free5gc/openapi" - "github.com/free5gc/openapi/models" - "github.com/free5gc/udm/internal/logger" - "github.com/free5gc/udm/internal/sbi/producer" - "github.com/free5gc/util/httpwrapper" -) - -// Unsubscribe - unsubscribe from notifications -func HTTPUnsubscribe(c *gin.Context) { - req := httpwrapper.NewRequest(c.Request, nil) - req.Params["supi"] = c.Params.ByName("supi") - req.Params["subscriptionId"] = c.Params.ByName("subscriptionId") - - rsp := producer.HandleUnsubscribeRequest(req) - // step 5: response - for key, val := range rsp.Header { // header response is optional - c.Header(key, val[0]) - } - responseBody, err := openapi.Serialize(rsp.Body, "application/json") - if err != nil { - logger.SdmLog.Errorln(err) - problemDetails := models.ProblemDetails{ - Status: http.StatusInternalServerError, - Cause: "SYSTEM_FAILURE", - Detail: err.Error(), - } - c.JSON(http.StatusInternalServerError, problemDetails) - } else { - c.Data(rsp.Status, "application/json", responseBody) - } -} diff --git a/internal/sbi/subscriberdatamanagement/api_subscription_deletion_for_shared_data.go b/internal/sbi/subscriberdatamanagement/api_subscription_deletion_for_shared_data.go deleted file mode 100644 index 306d347..0000000 --- a/internal/sbi/subscriberdatamanagement/api_subscription_deletion_for_shared_data.go +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Nudm_SDM - * - * Nudm Subscriber Data Management Service - * - * API version: 2.0.0 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package subscriberdatamanagement - -import ( - "net/http" - - "github.com/gin-gonic/gin" - - "github.com/free5gc/openapi" - "github.com/free5gc/openapi/models" - "github.com/free5gc/udm/internal/logger" - "github.com/free5gc/udm/internal/sbi/producer" - "github.com/free5gc/util/httpwrapper" -) - -// UnsubscribeForSharedData - unsubscribe from notifications for shared data -func HTTPUnsubscribeForSharedData(c *gin.Context) { - req := httpwrapper.NewRequest(c.Request, nil) - req.Params["subscriptionId"] = c.Params.ByName("subscriptionId") - - rsp := producer.HandleUnsubscribeForSharedDataRequest(req) - responseBody, err := openapi.Serialize(rsp.Body, "application/json") - if err != nil { - logger.SdmLog.Errorln(err) - problemDetails := models.ProblemDetails{ - Status: http.StatusInternalServerError, - Cause: "SYSTEM_FAILURE", - Detail: err.Error(), - } - c.JSON(http.StatusInternalServerError, problemDetails) - } else { - c.Data(rsp.Status, "application/json", responseBody) - } -} diff --git a/internal/sbi/subscriberdatamanagement/api_subscription_modification.go b/internal/sbi/subscriberdatamanagement/api_subscription_modification.go deleted file mode 100644 index b0f543e..0000000 --- a/internal/sbi/subscriberdatamanagement/api_subscription_modification.go +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Nudm_SDM - * - * Nudm Subscriber Data Management Service - * - * API version: 2.0.0 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package subscriberdatamanagement - -import ( - "net/http" - - "github.com/gin-gonic/gin" - - "github.com/free5gc/openapi" - "github.com/free5gc/openapi/models" - "github.com/free5gc/udm/internal/logger" - "github.com/free5gc/udm/internal/sbi/producer" - "github.com/free5gc/util/httpwrapper" -) - -// Modify - modify the subscription -func HTTPModify(c *gin.Context) { - var sdmSubsModificationReq models.SdmSubsModification - // step 1: retrieve http request body - requestBody, err := c.GetRawData() - if err != nil { - problemDetail := models.ProblemDetails{ - Title: "System failure", - Status: http.StatusInternalServerError, - Detail: err.Error(), - Cause: "SYSTEM_FAILURE", - } - logger.SdmLog.Errorf("Get Request Body error: %+v", err) - c.JSON(http.StatusInternalServerError, problemDetail) - return - } - - // step 2: convert requestBody to openapi models - err = openapi.Deserialize(&sdmSubsModificationReq, requestBody, "application/json") - if err != nil { - problemDetail := "[Request Body] " + err.Error() - rsp := models.ProblemDetails{ - Title: "Malformed request syntax", - Status: http.StatusBadRequest, - Detail: problemDetail, - } - logger.SdmLog.Errorln(problemDetail) - c.JSON(http.StatusBadRequest, rsp) - return - } - - req := httpwrapper.NewRequest(c.Request, sdmSubsModificationReq) - req.Params["supi"] = c.Params.ByName("supi") - req.Params["subscriptionId"] = c.Params.ByName("subscriptionId") - - rsp := producer.HandleModifyRequest(req) - responseBody, err := openapi.Serialize(rsp.Body, "application/json") - if err != nil { - logger.SdmLog.Errorln(err) - problemDetails := models.ProblemDetails{ - Status: http.StatusInternalServerError, - Cause: "SYSTEM_FAILURE", - Detail: err.Error(), - } - c.JSON(http.StatusInternalServerError, problemDetails) - } else { - c.Data(rsp.Status, "application/json", responseBody) - } -} - -// ModifyForSharedData - modify the subscription -func HTTPModifyForSharedData(c *gin.Context) { - var sharedDataSubscriptions models.SdmSubsModification - // step 1: retrieve http request body - requestBody, err := c.GetRawData() - if err != nil { - problemDetail := models.ProblemDetails{ - Title: "System failure", - Status: http.StatusInternalServerError, - Detail: err.Error(), - Cause: "SYSTEM_FAILURE", - } - logger.SdmLog.Errorf("Get Request Body error: %+v", err) - c.JSON(http.StatusInternalServerError, problemDetail) - return - } - - // step 2: convert requestBody to openapi models - err = openapi.Deserialize(&sharedDataSubscriptions, requestBody, "application/json") - if err != nil { - problemDetail := "[Request Body] " + err.Error() - rsp := models.ProblemDetails{ - Title: "Malformed request syntax", - Status: http.StatusBadRequest, - Detail: problemDetail, - } - logger.SdmLog.Errorln(problemDetail) - c.JSON(http.StatusBadRequest, rsp) - return - } - - req := httpwrapper.NewRequest(c.Request, sharedDataSubscriptions) - req.Params["supi"] = c.Params.ByName("supi") - req.Params["subscriptionId"] = c.Params.ByName("subscriptionId") - - rsp := producer.HandleModifyForSharedDataRequest(req) - - responseBody, err := openapi.Serialize(rsp.Body, "application/json") - if err != nil { - logger.SdmLog.Errorln(err) - problemDetails := models.ProblemDetails{ - Status: http.StatusInternalServerError, - Cause: "SYSTEM_FAILURE", - Detail: err.Error(), - } - c.JSON(http.StatusInternalServerError, problemDetails) - } else { - c.Data(rsp.Status, "application/json", responseBody) - } -} diff --git a/internal/sbi/subscriberdatamanagement/api_trace_configuration_data_retrieval.go b/internal/sbi/subscriberdatamanagement/api_trace_configuration_data_retrieval.go deleted file mode 100644 index 6ae6aff..0000000 --- a/internal/sbi/subscriberdatamanagement/api_trace_configuration_data_retrieval.go +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Nudm_SDM - * - * Nudm Subscriber Data Management Service - * - * API version: 2.0.0 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package subscriberdatamanagement - -import ( - "net/http" - - "github.com/gin-gonic/gin" - - "github.com/free5gc/openapi" - "github.com/free5gc/openapi/models" - "github.com/free5gc/udm/internal/logger" - "github.com/free5gc/udm/internal/sbi/producer" - "github.com/free5gc/util/httpwrapper" -) - -// GetTraceData - retrieve a UE's Trace Configuration Data -func HTTPGetTraceData(c *gin.Context) { - req := httpwrapper.NewRequest(c.Request, nil) - req.Params["supi"] = c.Params.ByName("supi") - req.Query.Set("plmn-id", c.Query("plmn-id")) - - rsp := producer.HandleGetTraceDataRequest(req) - - responseBody, err := openapi.Serialize(rsp.Body, "application/json") - if err != nil { - logger.SdmLog.Errorln(err) - problemDetails := models.ProblemDetails{ - Status: http.StatusInternalServerError, - Cause: "SYSTEM_FAILURE", - Detail: err.Error(), - } - c.JSON(http.StatusInternalServerError, problemDetails) - } else { - c.Data(rsp.Status, "application/json", responseBody) - } -} diff --git a/internal/sbi/subscriberdatamanagement/api_ue_context_in_smf_data_retrieval.go b/internal/sbi/subscriberdatamanagement/api_ue_context_in_smf_data_retrieval.go deleted file mode 100644 index 2486cc7..0000000 --- a/internal/sbi/subscriberdatamanagement/api_ue_context_in_smf_data_retrieval.go +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Nudm_SDM - * - * Nudm Subscriber Data Management Service - * - * API version: 2.0.0 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package subscriberdatamanagement - -import ( - "net/http" - - "github.com/gin-gonic/gin" - - "github.com/free5gc/openapi" - "github.com/free5gc/openapi/models" - "github.com/free5gc/udm/internal/logger" - "github.com/free5gc/udm/internal/sbi/producer" - "github.com/free5gc/util/httpwrapper" -) - -// GetUeContextInSmfData - retrieve a UE's UE Context In SMF Data -func HTTPGetUeContextInSmfData(c *gin.Context) { - req := httpwrapper.NewRequest(c.Request, nil) - req.Params["supi"] = c.Params.ByName("supi") - req.Query.Set("supported-features", c.Query("supported-features")) - - rsp := producer.HandleGetUeContextInSmfDataRequest(req) - - responseBody, err := openapi.Serialize(rsp.Body, "application/json") - if err != nil { - logger.SdmLog.Errorln(err) - problemDetails := models.ProblemDetails{ - Status: http.StatusInternalServerError, - Cause: "SYSTEM_FAILURE", - Detail: err.Error(), - } - c.JSON(http.StatusInternalServerError, problemDetails) - } else { - c.Data(rsp.Status, "application/json", responseBody) - } -} diff --git a/internal/sbi/subscriberdatamanagement/api_ue_context_in_smsf_data_retrieval.go b/internal/sbi/subscriberdatamanagement/api_ue_context_in_smsf_data_retrieval.go deleted file mode 100644 index 804d0d2..0000000 --- a/internal/sbi/subscriberdatamanagement/api_ue_context_in_smsf_data_retrieval.go +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Nudm_SDM - * - * Nudm Subscriber Data Management Service - * - * API version: 2.0.0 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package subscriberdatamanagement - -import ( - "net/http" - - "github.com/gin-gonic/gin" -) - -// GetUeContextInSmsfData - retrieve a UE's UE Context In SMSF Data -func HTTPGetUeContextInSmsfData(c *gin.Context) { - c.JSON(http.StatusOK, gin.H{}) -} diff --git a/internal/sbi/subscriberdatamanagement/routers.go b/internal/sbi/subscriberdatamanagement/routers.go deleted file mode 100644 index 82469d1..0000000 --- a/internal/sbi/subscriberdatamanagement/routers.go +++ /dev/null @@ -1,458 +0,0 @@ -/* - * Nudm_SDM - * - * Nudm Subscriber Data Management Service - * - * API version: 1.0.0 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package subscriberdatamanagement - -import ( - "net/http" - "strings" - - "github.com/gin-gonic/gin" - - "github.com/free5gc/openapi/models" - udm_context "github.com/free5gc/udm/internal/context" - "github.com/free5gc/udm/internal/logger" - "github.com/free5gc/udm/internal/util" - "github.com/free5gc/udm/pkg/factory" - logger_util "github.com/free5gc/util/logger" -) - -// Route is the information for every URI. -type Route struct { - // Name is the name of this Route. - Name string - // Method is the string for the HTTP method. ex) GET, POST etc.. - Method string - // Pattern is the pattern of the URI. - Pattern string - // HandlerFunc is the handler function of this route. - HandlerFunc gin.HandlerFunc -} - -// Routes is the list of the generated Route. -type Routes []Route - -// NewRouter returns a new router. -func NewRouter() *gin.Engine { - router := logger_util.NewGinWithLogrus(logger.GinLog) - - AddService(router) - return router -} - -func oneLayerPathHandlerFunc(c *gin.Context) { - supi := c.Param("supi") - for _, route := range oneLayerPathRouter { - if strings.Contains(route.Pattern, supi) && route.Method == c.Request.Method { - route.HandlerFunc(c) - return - } - } - - // special case for :supi - if c.Request.Method == strings.ToUpper("Get") { - HTTPGetSupi(c) - return - } - - c.String(http.StatusNotFound, "404 page not found") -} - -func twoLayerPathHandlerFunc(c *gin.Context) { - supi := c.Param("supi") - op := c.Param("subscriptionId") - - // for "/shared-data-subscriptions/:subscriptionId" - if supi == "shared-data-subscriptions" && strings.ToUpper("Delete") == c.Request.Method { - HTTPUnsubscribeForSharedData(c) - return - } - - // for "/shared-data-subscriptions/:subscriptionId" - if supi == "shared-data-subscriptions" && strings.ToUpper("Patch") == c.Request.Method { - HTTPModifyForSharedData(c) - return - } - - // for "/:gpsi/id-translation-result" - if op == "id-translation-result" && strings.ToUpper("Get") == c.Request.Method { - c.Params = append(c.Params, gin.Param{Key: "gpsi", Value: c.Param("supi")}) - HTTPGetIdTranslationResult(c) - return - } - - for _, route := range twoLayerPathRouter { - if strings.Contains(route.Pattern, op) && route.Method == c.Request.Method { - route.HandlerFunc(c) - return - } - } - - c.String(http.StatusNotFound, "404 page not found") -} - -func threeLayerPathHandlerFunc(c *gin.Context) { - op := c.Param("subscriptionId") - - // for "/:supi/sdm-subscriptions/:subscriptionId" - if op == "sdm-subscriptions" && strings.ToUpper("Delete") == c.Request.Method { - var tmpParams gin.Params - tmpParams = append(tmpParams, gin.Param{Key: "supi", Value: c.Param("supi")}) - tmpParams = append(tmpParams, gin.Param{Key: "subscriptionId", Value: c.Param("thirdLayer")}) - c.Params = tmpParams - HTTPUnsubscribe(c) - return - } - - // for "/:supi/am-data/sor-ack" - if op == "am-data" && strings.ToUpper("Put") == c.Request.Method { - HTTPInfo(c) - return - } - - // for "/:supi/sdm-subscriptions/:subscriptionId" - if op == "sdm-subscriptions" && strings.ToUpper("Patch") == c.Request.Method { - var tmpParams gin.Params - tmpParams = append(tmpParams, gin.Param{Key: "supi", Value: c.Param("supi")}) - tmpParams = append(tmpParams, gin.Param{Key: "subscriptionId", Value: c.Param("thirdLayer")}) - c.Params = tmpParams - HTTPModify(c) - return - } - - c.String(http.StatusNotFound, "404 page not found") -} - -func AddService(engine *gin.Engine) *gin.RouterGroup { - group := engine.Group(factory.UdmSdmResUriPrefix) - - routerAuthorizationCheck := util.NewRouterAuthorizationCheck(models.ServiceName_NUDM_SDM) - group.Use(func(c *gin.Context) { - routerAuthorizationCheck.Check(c, udm_context.GetSelf()) - }) - for _, route := range routes { - switch route.Method { - case "GET": - group.GET(route.Pattern, route.HandlerFunc) - case "POST": - group.POST(route.Pattern, route.HandlerFunc) - case "PUT": - group.PUT(route.Pattern, route.HandlerFunc) - case "DELETE": - group.DELETE(route.Pattern, route.HandlerFunc) - case "PATCH": - group.PATCH(route.Pattern, route.HandlerFunc) - } - } - - oneLayerPath := "/:supi" - group.Any(oneLayerPath, oneLayerPathHandlerFunc) - - twoLayerPath := "/:supi/:subscriptionId" - group.Any(twoLayerPath, twoLayerPathHandlerFunc) - - threeLayerPath := "/:supi/:subscriptionId/:thirdLayer" - group.Any(threeLayerPath, threeLayerPathHandlerFunc) - - return group -} - -// Index is the index handler. -func Index(c *gin.Context) { - c.String(http.StatusOK, "Hello World!") -} - -var routes = Routes{ - { - "Index", - "GET", - "/", - Index, - }, -} - -/* -var specialRouter = Routes{ - { - "GetIdTranslationResult", - strings.ToUpper("Get"), - "/:gpsi/id-translation-result", - HTTPGetIdTranslationResult, - }, - - { - "UnsubscribeForSharedData", - strings.ToUpper("Delete"), - "/shared-data-subscriptions/:subscriptionId", - HTTPUnsubscribeForSharedData, - }, - - { - "ModifyForSharedData", - strings.ToUpper("Patch"), - "/shared-data-subscriptions/:subscriptionId", - HTTPModifyForSharedData, - }, -} -*/ - -var oneLayerPathRouter = Routes{ - { - "GetSupi", - strings.ToUpper("Get"), - "/:supi", - HTTPGetSupi, - }, - - { - "GetSharedData", - strings.ToUpper("Get"), - "/shared-data", - HTTPGetSharedData, - }, - - { - "SubscribeToSharedData", - strings.ToUpper("Post"), - "/shared-data-subscriptions", - HTTPSubscribeToSharedData, - }, -} - -var twoLayerPathRouter = Routes{ - { - "GetAmData", - strings.ToUpper("Get"), - "/:supi/am-data", - HTTPGetAmData, - }, - - { - "GetSmfSelectData", - strings.ToUpper("Get"), - "/:supi/smf-select-data", - HTTPGetSmfSelectData, - }, - - { - "GetSmsMngData", - strings.ToUpper("Get"), - "/:supi/sms-mng-data", - HTTPGetSmsMngData, - }, - - { - "GetSmsData", - strings.ToUpper("Get"), - "/:supi/sms-data", - HTTPGetSmsData, - }, - - { - "GetSmData", - strings.ToUpper("Get"), - "/:supi/sm-data", - HTTPGetSmData, - }, - - { - "GetNssai", - strings.ToUpper("Get"), - "/:supi/nssai", - HTTPGetNssai, - }, - - { - "Subscribe", - strings.ToUpper("Post"), - "/:supi/sdm-subscriptions", - HTTPSubscribe, - }, - - { - "GetTraceData", - strings.ToUpper("Get"), - "/:supi/trace-data", - HTTPGetTraceData, - }, - - { - "GetUeContextInSmfData", - strings.ToUpper("Get"), - "/:supi/ue-context-in-smf-data", - HTTPGetUeContextInSmfData, - }, - - { - "GetUeContextInSmsfData", - strings.ToUpper("Get"), - "/:supi/ue-context-in-smsf-data", - HTTPGetUeContextInSmsfData, - }, -} - -/* -var threeLayerPathRouter = Routes{ - { - "Unsubscribe", - strings.ToUpper("Delete"), - "/:supi/sdm-subscriptions/:subscriptionId", - HTTPUnsubscribe, - }, - - { - "Info", - strings.ToUpper("Put"), - "/:supi/am-data/sor-ack", - HTTPInfo, - }, - - { - "PutUpuAck", - strings.ToUpper("Put"), - "/:supi/am-data/upu-ack", - HTTPPutUpuAck, - }, - - { - "Modify", - strings.ToUpper("Patch"), - "/:supi/sdm-subscriptions/:subscriptionId", - HTTPModify, - }, -} - -var routesBackup = Routes{ - { - "Index", - "GET", - "/", - Index, - }, - - { - "GetAmData", - strings.ToUpper("Get"), - "/:supi/am-data", - HTTPGetAmData, - }, - - { - "Info", - strings.ToUpper("Put"), - "/:supi/am-data/sor-ack", - HTTPInfo, - }, - - { - "GetSupi", - strings.ToUpper("Get"), - "/:supi", - HTTPGetSupi, - }, - - { - "GetSharedData", - strings.ToUpper("Get"), - "/shared-data", - HTTPGetSharedData, - }, - - { - "GetSmfSelectData", - strings.ToUpper("Get"), - "/:supi/smf-select-data", - HTTPGetSmfSelectData, - }, - - { - "GetSmsMngData", - strings.ToUpper("Get"), - "/:supi/sms-mng-data", - HTTPGetSmsMngData, - }, - - { - "GetSmsData", - strings.ToUpper("Get"), - "/:supi/sms-data", - HTTPGetSmsData, - }, - - { - "GetSmData", - strings.ToUpper("Get"), - "/:supi/sm-data", - HTTPGetSmData, - }, - - { - "GetNssai", - strings.ToUpper("Get"), - "/:supi/nssai", - HTTPGetNssai, - }, - - { - "Subscribe", - strings.ToUpper("Post"), - "/:supi/sdm-subscriptions", - HTTPSubscribe, - }, - - { - "SubscribeToSharedData", - strings.ToUpper("Post"), - "/shared-data-subscriptions", - HTTPSubscribeToSharedData, - }, - - { - "Unsubscribe", - strings.ToUpper("Delete"), - "/:supi/sdm-subscriptions/:subscriptionId", - HTTPUnsubscribe, - }, - - { - "UnsubscribeForSharedData", - strings.ToUpper("Delete"), - "/shared-data-subscriptions/:subscriptionId", - HTTPUnsubscribeForSharedData, - }, - - { - "GetTraceData", - strings.ToUpper("Get"), - "/:supi/trace-data", - HTTPGetTraceData, - }, - - { - "GetUeContextInSmfData", - strings.ToUpper("Get"), - "/:supi/ue-context-in-smf-data", - HTTPGetUeContextInSmfData, - }, - - { - "GetUeContextInSmsfData", - strings.ToUpper("Get"), - "/:supi/ue-context-in-smsf-data", - HTTPGetUeContextInSmsfData, - }, - - { - "GetIdTranslationResult", - strings.ToUpper("Get"), - "/:gpsi/id-translation-result", - HTTPGetIdTranslationResult, - }, -} -*/ diff --git a/internal/sbi/ueauthentication/api_confirm_auth.go b/internal/sbi/ueauthentication/api_confirm_auth.go deleted file mode 100644 index 6e6e79d..0000000 --- a/internal/sbi/ueauthentication/api_confirm_auth.go +++ /dev/null @@ -1,72 +0,0 @@ -/* - * NudmUEAU - * - * UDM UE Authentication Service - * - * API version: 1.0.0 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package ueauthentication - -import ( - "net/http" - - "github.com/gin-gonic/gin" - - "github.com/free5gc/openapi" - "github.com/free5gc/openapi/models" - "github.com/free5gc/udm/internal/logger" - "github.com/free5gc/udm/internal/sbi/producer" - "github.com/free5gc/util/httpwrapper" -) - -// ConfirmAuth - Create a new confirmation event -func HTTPConfirmAuth(c *gin.Context) { - var authEvent models.AuthEvent - // step 1: retrieve http request body - requestBody, err := c.GetRawData() - if err != nil { - problemDetail := models.ProblemDetails{ - Title: "System failure", - Status: http.StatusInternalServerError, - Detail: err.Error(), - Cause: "SYSTEM_FAILURE", - } - logger.UeauLog.Errorf("Get Request Body error: %+v", err) - c.JSON(http.StatusInternalServerError, problemDetail) - return - } - - // step 2: convert requestBody to openapi models - err = openapi.Deserialize(&authEvent, requestBody, "application/json") - if err != nil { - problemDetail := "[Request Body] " + err.Error() - rsp := models.ProblemDetails{ - Title: "Malformed request syntax", - Status: http.StatusBadRequest, - Detail: problemDetail, - } - logger.UeauLog.Errorln(problemDetail) - c.JSON(http.StatusBadRequest, rsp) - return - } - - req := httpwrapper.NewRequest(c.Request, authEvent) - req.Params["supi"] = c.Params.ByName("supi") - - rsp := producer.HandleConfirmAuthDataRequest(req) - - responseBody, err := openapi.Serialize(rsp.Body, "application/json") - if err != nil { - logger.UeauLog.Errorln(err) - problemDetails := models.ProblemDetails{ - Status: http.StatusInternalServerError, - Cause: "SYSTEM_FAILURE", - Detail: err.Error(), - } - c.JSON(http.StatusInternalServerError, problemDetails) - } else { - c.Data(rsp.Status, "application/json", responseBody) - } -} diff --git a/internal/sbi/ueauthentication/api_generate_auth_data.go b/internal/sbi/ueauthentication/api_generate_auth_data.go deleted file mode 100644 index a4e0680..0000000 --- a/internal/sbi/ueauthentication/api_generate_auth_data.go +++ /dev/null @@ -1,73 +0,0 @@ -/* - * NudmUEAU - * - * UDM UE Authentication Service - * - * API version: 1.0.0 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package ueauthentication - -import ( - "net/http" - - "github.com/gin-gonic/gin" - - "github.com/free5gc/openapi" - "github.com/free5gc/openapi/models" - "github.com/free5gc/udm/internal/logger" - "github.com/free5gc/udm/internal/sbi/producer" - "github.com/free5gc/util/httpwrapper" -) - -// GenerateAuthData - Generate authentication data for the UE -func HttpGenerateAuthData(c *gin.Context) { - var authInfoReq models.AuthenticationInfoRequest - - // step 1: retrieve http request body - requestBody, err := c.GetRawData() - if err != nil { - problemDetail := models.ProblemDetails{ - Title: "System failure", - Status: http.StatusInternalServerError, - Detail: err.Error(), - Cause: "SYSTEM_FAILURE", - } - logger.UeauLog.Errorf("Get Request Body error: %+v", err) - c.JSON(http.StatusInternalServerError, problemDetail) - return - } - - // step 2: convert requestBody to openapi models - err = openapi.Deserialize(&authInfoReq, requestBody, "application/json") - if err != nil { - problemDetail := "[Request Body] " + err.Error() - rsp := models.ProblemDetails{ - Title: "Malformed request syntax", - Status: http.StatusBadRequest, - Detail: problemDetail, - } - logger.UeauLog.Errorln(problemDetail) - c.JSON(http.StatusBadRequest, rsp) - return - } - - req := httpwrapper.NewRequest(c.Request, authInfoReq) - req.Params["supiOrSuci"] = c.Param("supiOrSuci") - - rsp := producer.HandleGenerateAuthDataRequest(req) - - responseBody, err := openapi.Serialize(rsp.Body, "application/json") - if err != nil { - logger.UeauLog.Errorln(err) - problemDetails := models.ProblemDetails{ - Status: http.StatusInternalServerError, - Cause: "SYSTEM_FAILURE", - Detail: err.Error(), - } - c.JSON(http.StatusInternalServerError, problemDetails) - } else { - c.Data(rsp.Status, "application/json", responseBody) - } -} diff --git a/internal/sbi/ueauthentication/routers.go b/internal/sbi/ueauthentication/routers.go deleted file mode 100644 index 2ca5def..0000000 --- a/internal/sbi/ueauthentication/routers.go +++ /dev/null @@ -1,123 +0,0 @@ -/* - * NudmUEAU - * - * UDM UE Authentication Service - * - * API version: 1.0.0 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package ueauthentication - -import ( - "net/http" - "strings" - - "github.com/gin-gonic/gin" - "github.com/sirupsen/logrus" - - "github.com/free5gc/openapi/models" - udm_context "github.com/free5gc/udm/internal/context" - "github.com/free5gc/udm/internal/logger" - "github.com/free5gc/udm/internal/util" - "github.com/free5gc/udm/pkg/factory" - logger_util "github.com/free5gc/util/logger" -) - -var HttpLog *logrus.Entry - -func init() { - HttpLog = logger.HttpLog -} - -// Route is the information for every URI. -type Route struct { - // Name is the name of this Route. - Name string - // Method is the string for the HTTP method. ex) GET, POST etc.. - Method string - // Pattern is the pattern of the URI. - Pattern string - // HandlerFunc is the handler function of this route. - HandlerFunc gin.HandlerFunc -} - -// Routes is the list of the generated Route. -type Routes []Route - -// NewRouter returns a new router. -func NewRouter() *gin.Engine { - router := logger_util.NewGinWithLogrus(logger.GinLog) - - AddService(router) - return router -} - -func genAuthDataHandlerFunc(c *gin.Context) { - c.Params = append(c.Params, gin.Param{Key: "supiOrSuci", Value: c.Param("supi")}) - if strings.ToUpper("Post") == c.Request.Method { - HttpGenerateAuthData(c) - return - } - - c.String(http.StatusNotFound, "404 page not found") -} - -func AddService(engine *gin.Engine) *gin.RouterGroup { - group := engine.Group(factory.UdmUeauResUriPrefix) - routerAuthorizationCheck := util.NewRouterAuthorizationCheck(models.ServiceName_NUDM_UEAU) - group.Use(func(c *gin.Context) { - routerAuthorizationCheck.Check(c, udm_context.GetSelf()) - }) - for _, route := range routes { - switch route.Method { - case "GET": - group.GET(route.Pattern, route.HandlerFunc) - case "POST": - group.POST(route.Pattern, route.HandlerFunc) - case "PUT": - group.PUT(route.Pattern, route.HandlerFunc) - case "DELETE": - group.DELETE(route.Pattern, route.HandlerFunc) - case "PATCH": - group.PATCH(route.Pattern, route.HandlerFunc) - } - } - - genAuthDataPath := "/:supi/security-information/generate-auth-data" - group.Any(genAuthDataPath, genAuthDataHandlerFunc) - - return group -} - -// Index is the index handler. -func Index(c *gin.Context) { - c.String(http.StatusOK, "Hello World!") -} - -var routes = Routes{ - { - "Index", - "GET", - "/", - Index, - }, - - { - "ConfirmAuth", - strings.ToUpper("Post"), - "/:supi/auth-events", - HTTPConfirmAuth, - }, -} - -/* -var specialRoutes = Routes{ - { - "GenerateAuthData", - strings.ToUpper("Post"), - "/:supiOrSuci/security-information/generate-auth-data", - HttpGenerateAuthData, - }, -} -*/ diff --git a/internal/sbi/uecontextmanagement/api_amf3_gpp_access_registration_info_retrieval.go b/internal/sbi/uecontextmanagement/api_amf3_gpp_access_registration_info_retrieval.go deleted file mode 100644 index 4a0acd5..0000000 --- a/internal/sbi/uecontextmanagement/api_amf3_gpp_access_registration_info_retrieval.go +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Nudm_UECM - * - * Nudm Context Management Service - * - * API version: 1.0.1 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package uecontextmanagement - -import ( - "net/http" - - "github.com/gin-gonic/gin" - - "github.com/free5gc/openapi" - "github.com/free5gc/openapi/models" - "github.com/free5gc/udm/internal/logger" - "github.com/free5gc/udm/internal/sbi/producer" - "github.com/free5gc/util/httpwrapper" -) - -// GetAmf3gppAccess - retrieve the AMF registration for 3GPP access information -func HTTPGetAmf3gppAccess(c *gin.Context) { - req := httpwrapper.NewRequest(c.Request, nil) - req.Params["ueId"] = c.Param("ueId") - req.Query.Add("supported-features", c.Query("supported-features")) - - rsp := producer.HandleGetAmf3gppAccessRequest(req) - - responseBody, err := openapi.Serialize(rsp.Body, "application/json") - if err != nil { - logger.UecmLog.Errorln(err) - problemDetails := models.ProblemDetails{ - Status: http.StatusInternalServerError, - Cause: "SYSTEM_FAILURE", - Detail: err.Error(), - } - c.JSON(http.StatusInternalServerError, problemDetails) - } else { - c.Data(rsp.Status, "application/json", responseBody) - } -} diff --git a/internal/sbi/uecontextmanagement/api_amf_non3_gpp_access_registration_info_retrieval.go b/internal/sbi/uecontextmanagement/api_amf_non3_gpp_access_registration_info_retrieval.go deleted file mode 100644 index b33fb42..0000000 --- a/internal/sbi/uecontextmanagement/api_amf_non3_gpp_access_registration_info_retrieval.go +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Nudm_UECM - * - * Nudm Context Management Service - * - * API version: 1.0.1 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package uecontextmanagement - -import ( - "net/http" - - "github.com/gin-gonic/gin" - - "github.com/free5gc/openapi" - "github.com/free5gc/openapi/models" - "github.com/free5gc/udm/internal/logger" - "github.com/free5gc/udm/internal/sbi/producer" - "github.com/free5gc/util/httpwrapper" -) - -// GetAmfNon3gppAccess - retrieve the AMF registration for non-3GPP access information -func HTTPGetAmfNon3gppAccess(c *gin.Context) { - req := httpwrapper.NewRequest(c.Request, nil) - req.Params["ueId"] = c.Param("ueId") - req.Query.Add("supported-features", c.Query("supported-features")) - - rsp := producer.HandleGetAmfNon3gppAccessRequest(req) - - responseBody, err := openapi.Serialize(rsp.Body, "application/json") - if err != nil { - logger.UecmLog.Errorln(err) - problemDetails := models.ProblemDetails{ - Status: http.StatusInternalServerError, - Cause: "SYSTEM_FAILURE", - Detail: err.Error(), - } - c.JSON(http.StatusInternalServerError, problemDetails) - } else { - c.Data(rsp.Status, "application/json", responseBody) - } -} diff --git a/internal/sbi/uecontextmanagement/api_amf_registration_for3_gpp_access.go b/internal/sbi/uecontextmanagement/api_amf_registration_for3_gpp_access.go deleted file mode 100644 index 7e39c21..0000000 --- a/internal/sbi/uecontextmanagement/api_amf_registration_for3_gpp_access.go +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Nudm_UECM - * - * Nudm Context Management Service - * - * API version: 1.0.1 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package uecontextmanagement - -import ( - "net/http" - - "github.com/gin-gonic/gin" - - "github.com/free5gc/openapi" - "github.com/free5gc/openapi/models" - "github.com/free5gc/udm/internal/logger" - "github.com/free5gc/udm/internal/sbi/producer" - "github.com/free5gc/util/httpwrapper" -) - -// RegistrationAmf3gppAccess - register as AMF for 3GPP access -func HTTPRegistrationAmf3gppAccess(c *gin.Context) { - var amf3GppAccessRegistration models.Amf3GppAccessRegistration - // step 1: retrieve http request body - requestBody, err := c.GetRawData() - if err != nil { - problemDetail := models.ProblemDetails{ - Title: "System failure", - Status: http.StatusInternalServerError, - Detail: err.Error(), - Cause: "SYSTEM_FAILURE", - } - logger.UecmLog.Errorf("Get Request Body error: %+v", err) - c.JSON(http.StatusInternalServerError, problemDetail) - return - } - - // step 2: convert requestBody to openapi models - err = openapi.Deserialize(&amf3GppAccessRegistration, requestBody, "application/json") - if err != nil { - problemDetail := "[Request Body] " + err.Error() - rsp := models.ProblemDetails{ - Title: "Malformed request syntax", - Status: http.StatusBadRequest, - Detail: problemDetail, - } - logger.UecmLog.Errorln(problemDetail) - c.JSON(http.StatusBadRequest, rsp) - return - } - - req := httpwrapper.NewRequest(c.Request, amf3GppAccessRegistration) - req.Params["ueId"] = c.Param("ueId") - - rsp := producer.HandleRegistrationAmf3gppAccessRequest(req) - - // step 5: response - for key, val := range rsp.Header { // header response is optional - c.Header(key, val[0]) - } - responseBody, err := openapi.Serialize(rsp.Body, "application/json") - if err != nil { - logger.UecmLog.Errorln(err) - problemDetails := models.ProblemDetails{ - Status: http.StatusInternalServerError, - Cause: "SYSTEM_FAILURE", - Detail: err.Error(), - } - c.JSON(http.StatusInternalServerError, problemDetails) - } else { - c.Data(rsp.Status, "application/json", responseBody) - } -} diff --git a/internal/sbi/uecontextmanagement/api_amf_registration_for_non3_gpp_access.go b/internal/sbi/uecontextmanagement/api_amf_registration_for_non3_gpp_access.go deleted file mode 100644 index 6190365..0000000 --- a/internal/sbi/uecontextmanagement/api_amf_registration_for_non3_gpp_access.go +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Nudm_UECM - * - * Nudm Context Management Service - * - * API version: 1.0.1 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package uecontextmanagement - -import ( - "net/http" - - "github.com/gin-gonic/gin" - - "github.com/free5gc/openapi" - "github.com/free5gc/openapi/models" - "github.com/free5gc/udm/internal/logger" - "github.com/free5gc/udm/internal/sbi/producer" - "github.com/free5gc/util/httpwrapper" -) - -// Register - register as AMF for non-3GPP access -func HTTPRegistrationAmfNon3gppAccess(c *gin.Context) { - var amfNon3GppAccessRegistration models.AmfNon3GppAccessRegistration - - // step 1: retrieve http request body - requestBody, err := c.GetRawData() - if err != nil { - problemDetail := models.ProblemDetails{ - Title: "System failure", - Status: http.StatusInternalServerError, - Detail: err.Error(), - Cause: "SYSTEM_FAILURE", - } - logger.UecmLog.Errorf("Get Request Body error: %+v", err) - c.JSON(http.StatusInternalServerError, problemDetail) - return - } - - // step 2: convert requestBody to openapi models - err = openapi.Deserialize(&amfNon3GppAccessRegistration, requestBody, "application/json") - if err != nil { - problemDetail := "[Request Body] " + err.Error() - rsp := models.ProblemDetails{ - Title: "Malformed request syntax", - Status: http.StatusBadRequest, - Detail: problemDetail, - } - logger.UecmLog.Errorln(problemDetail) - c.JSON(http.StatusBadRequest, rsp) - return - } - - req := httpwrapper.NewRequest(c.Request, amfNon3GppAccessRegistration) - req.Params["ueId"] = c.Param("ueId") - - rsp := producer.HandleRegisterAmfNon3gppAccessRequest(req) - - for key, val := range rsp.Header { // header response is optional - c.Header(key, val[0]) - } - responseBody, err := openapi.Serialize(rsp.Body, "application/json") - if err != nil { - logger.UecmLog.Errorln(err) - problemDetails := models.ProblemDetails{ - Status: http.StatusInternalServerError, - Cause: "SYSTEM_FAILURE", - Detail: err.Error(), - } - c.JSON(http.StatusInternalServerError, problemDetails) - } else { - c.Data(rsp.Status, "application/json", responseBody) - } -} diff --git a/internal/sbi/uecontextmanagement/api_parameter_update_in_the_amf_registration_for3_gpp_access.go b/internal/sbi/uecontextmanagement/api_parameter_update_in_the_amf_registration_for3_gpp_access.go deleted file mode 100644 index 3646f85..0000000 --- a/internal/sbi/uecontextmanagement/api_parameter_update_in_the_amf_registration_for3_gpp_access.go +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Nudm_UECM - * - * Nudm Context Management Service - * - * API version: 1.0.1 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package uecontextmanagement - -import ( - "net/http" - - "github.com/gin-gonic/gin" - - "github.com/free5gc/openapi" - "github.com/free5gc/openapi/models" - "github.com/free5gc/udm/internal/logger" - "github.com/free5gc/udm/internal/sbi/producer" - "github.com/free5gc/util/httpwrapper" -) - -// UpdateAmf3gppAccess - Update a parameter in the AMF registration for 3GPP access -func HTTPUpdateAmf3gppAccess(c *gin.Context) { - var amf3GppAccessRegistrationModification models.Amf3GppAccessRegistrationModification - - // step 1: retrieve http request body - requestBody, err := c.GetRawData() - if err != nil { - problemDetail := models.ProblemDetails{ - Title: "System failure", - Status: http.StatusInternalServerError, - Detail: err.Error(), - Cause: "SYSTEM_FAILURE", - } - logger.UecmLog.Errorf("Get Request Body error: %+v", err) - c.JSON(http.StatusInternalServerError, problemDetail) - return - } - - // step 2: convert requestBody to openapi models - err = openapi.Deserialize(&amf3GppAccessRegistrationModification, requestBody, "application/json") - if err != nil { - problemDetail := "[Request Body] " + err.Error() - rsp := models.ProblemDetails{ - Title: "Malformed request syntax", - Status: http.StatusBadRequest, - Detail: problemDetail, - } - logger.UecmLog.Errorln(problemDetail) - c.JSON(http.StatusBadRequest, rsp) - return - } - - req := httpwrapper.NewRequest(c.Request, amf3GppAccessRegistrationModification) - req.Params["ueId"] = c.Param("ueId") - - rsp := producer.HandleUpdateAmf3gppAccessRequest(req) - - responseBody, err := openapi.Serialize(rsp.Body, "application/json") - if err != nil { - logger.UecmLog.Errorln(err) - problemDetails := models.ProblemDetails{ - Status: http.StatusInternalServerError, - Cause: "SYSTEM_FAILURE", - Detail: err.Error(), - } - c.JSON(http.StatusInternalServerError, problemDetails) - } else { - c.Data(rsp.Status, "application/json", responseBody) - } -} diff --git a/internal/sbi/uecontextmanagement/api_parameter_update_in_the_amf_registration_for_non3_gpp_access.go b/internal/sbi/uecontextmanagement/api_parameter_update_in_the_amf_registration_for_non3_gpp_access.go deleted file mode 100644 index 775071e..0000000 --- a/internal/sbi/uecontextmanagement/api_parameter_update_in_the_amf_registration_for_non3_gpp_access.go +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Nudm_UECM - * - * Nudm Context Management Service - * - * API version: 1.0.1 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package uecontextmanagement - -import ( - "net/http" - - "github.com/gin-gonic/gin" - - "github.com/free5gc/openapi" - "github.com/free5gc/openapi/models" - "github.com/free5gc/udm/internal/logger" - "github.com/free5gc/udm/internal/sbi/producer" - "github.com/free5gc/util/httpwrapper" -) - -// UpdateAmfNon3gppAccess - update a parameter in the AMF registration for non-3GPP access -func HTTPUpdateAmfNon3gppAccess(c *gin.Context) { - var amfNon3GppAccessRegistrationModification models.AmfNon3GppAccessRegistrationModification - // step 1: retrieve http request body - requestBody, err := c.GetRawData() - if err != nil { - problemDetail := models.ProblemDetails{ - Title: "System failure", - Status: http.StatusInternalServerError, - Detail: err.Error(), - Cause: "SYSTEM_FAILURE", - } - logger.UecmLog.Errorf("Get Request Body error: %+v", err) - c.JSON(http.StatusInternalServerError, problemDetail) - return - } - - // step 2: convert requestBody to openapi models - err = openapi.Deserialize(&amfNon3GppAccessRegistrationModification, requestBody, "application/json") - if err != nil { - problemDetail := "[Request Body] " + err.Error() - rsp := models.ProblemDetails{ - Title: "Malformed request syntax", - Status: http.StatusBadRequest, - Detail: problemDetail, - } - logger.UecmLog.Errorln(problemDetail) - c.JSON(http.StatusBadRequest, rsp) - return - } - - req := httpwrapper.NewRequest(c.Request, amfNon3GppAccessRegistrationModification) - req.Params["ueId"] = c.Param("ueId") - - rsp := producer.HandleUpdateAmfNon3gppAccessRequest(req) - - responseBody, err := openapi.Serialize(rsp.Body, "application/json") - if err != nil { - logger.UecmLog.Errorln(err) - problemDetails := models.ProblemDetails{ - Status: http.StatusInternalServerError, - Cause: "SYSTEM_FAILURE", - Detail: err.Error(), - } - c.JSON(http.StatusInternalServerError, problemDetails) - } else { - c.Data(rsp.Status, "application/json", responseBody) - } -} diff --git a/internal/sbi/uecontextmanagement/api_smf_deregistration.go b/internal/sbi/uecontextmanagement/api_smf_deregistration.go deleted file mode 100644 index bdbc0a0..0000000 --- a/internal/sbi/uecontextmanagement/api_smf_deregistration.go +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Nudm_UECM - * - * Nudm Context Management Service - * - * API version: 1.0.1 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package uecontextmanagement - -import ( - "net/http" - - "github.com/gin-gonic/gin" - - "github.com/free5gc/openapi" - "github.com/free5gc/openapi/models" - "github.com/free5gc/udm/internal/logger" - "github.com/free5gc/udm/internal/sbi/producer" - "github.com/free5gc/util/httpwrapper" -) - -// DeregistrationSmfRegistrations - delete an SMF registration -func HTTPDeregistrationSmfRegistrations(c *gin.Context) { - req := httpwrapper.NewRequest(c.Request, nil) - req.Params["ueId"] = c.Params.ByName("ueId") - req.Params["pduSessionId"] = c.Params.ByName("pduSessionId") - - rsp := producer.HandleDeregistrationSmfRegistrations(req) - - responseBody, err := openapi.Serialize(rsp.Body, "application/json") - if err != nil { - logger.UecmLog.Errorln(err) - problemDetails := models.ProblemDetails{ - Status: http.StatusInternalServerError, - Cause: "SYSTEM_FAILURE", - Detail: err.Error(), - } - c.JSON(http.StatusInternalServerError, problemDetails) - } else { - c.Data(rsp.Status, "application/json", responseBody) - } -} diff --git a/internal/sbi/uecontextmanagement/api_smf_registration.go b/internal/sbi/uecontextmanagement/api_smf_registration.go deleted file mode 100644 index 03b2f13..0000000 --- a/internal/sbi/uecontextmanagement/api_smf_registration.go +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Nudm_UECM - * - * Nudm Context Management Service - * - * API version: 1.0.1 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package uecontextmanagement - -import ( - "net/http" - - "github.com/gin-gonic/gin" - - "github.com/free5gc/openapi" - "github.com/free5gc/openapi/models" - "github.com/free5gc/udm/internal/logger" - "github.com/free5gc/udm/internal/sbi/producer" - "github.com/free5gc/util/httpwrapper" -) - -// RegistrationSmfRegistrations - register as SMF -func HTTPRegistrationSmfRegistrations(c *gin.Context) { - var smfRegistration models.SmfRegistration - - // step 1: retrieve http request body - requestBody, err := c.GetRawData() - if err != nil { - problemDetail := models.ProblemDetails{ - Title: "System failure", - Status: http.StatusInternalServerError, - Detail: err.Error(), - Cause: "SYSTEM_FAILURE", - } - logger.UecmLog.Errorf("Get Request Body error: %+v", err) - c.JSON(http.StatusInternalServerError, problemDetail) - return - } - - // step 2: convert requestBody to openapi models - err = openapi.Deserialize(&smfRegistration, requestBody, "application/json") - if err != nil { - problemDetail := "[Request Body] " + err.Error() - rsp := models.ProblemDetails{ - Title: "Malformed request syntax", - Status: http.StatusBadRequest, - Detail: problemDetail, - } - logger.UecmLog.Errorln(problemDetail) - c.JSON(http.StatusBadRequest, rsp) - return - } - req := httpwrapper.NewRequest(c.Request, smfRegistration) - req.Params["ueId"] = c.Params.ByName("ueId") - req.Params["pduSessionId"] = c.Params.ByName("pduSessionId") - - rsp := producer.HandleRegistrationSmfRegistrationsRequest(req) - // step 5: response - for key, val := range rsp.Header { // header response is optional - c.Header(key, val[0]) - } - responseBody, err := openapi.Serialize(rsp.Body, "application/json") - if err != nil { - logger.UecmLog.Errorln(err) - problemDetails := models.ProblemDetails{ - Status: http.StatusInternalServerError, - Cause: "SYSTEM_FAILURE", - Detail: err.Error(), - } - c.JSON(http.StatusInternalServerError, problemDetails) - } else { - c.Data(rsp.Status, "application/json", responseBody) - } -} diff --git a/internal/sbi/uecontextmanagement/api_smsf3_gpp_access_registration_info_retrieval.go b/internal/sbi/uecontextmanagement/api_smsf3_gpp_access_registration_info_retrieval.go deleted file mode 100644 index 98e7dda..0000000 --- a/internal/sbi/uecontextmanagement/api_smsf3_gpp_access_registration_info_retrieval.go +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Nudm_UECM - * - * Nudm Context Management Service - * - * API version: 1.0.1 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package uecontextmanagement - -import ( - "net/http" - - "github.com/gin-gonic/gin" -) - -// GetSmsf3gppAccess - retrieve the SMSF registration for 3GPP access information -func HTTPGetSmsf3gppAccess(c *gin.Context) { - c.JSON(http.StatusOK, gin.H{}) -} diff --git a/internal/sbi/uecontextmanagement/api_smsf_deregistration_for3_gpp_access.go b/internal/sbi/uecontextmanagement/api_smsf_deregistration_for3_gpp_access.go deleted file mode 100644 index 3634298..0000000 --- a/internal/sbi/uecontextmanagement/api_smsf_deregistration_for3_gpp_access.go +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Nudm_UECM - * - * Nudm Context Management Service - * - * API version: 1.0.1 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package uecontextmanagement - -import ( - "net/http" - - "github.com/gin-gonic/gin" -) - -// DeregistrationSmsf3gppAccess - delete the SMSF registration for 3GPP access -func HTTPDeregistrationSmsf3gppAccess(c *gin.Context) { - c.JSON(http.StatusOK, gin.H{}) -} diff --git a/internal/sbi/uecontextmanagement/api_smsf_deregistration_for_non3_gpp_access.go b/internal/sbi/uecontextmanagement/api_smsf_deregistration_for_non3_gpp_access.go deleted file mode 100644 index 7411f58..0000000 --- a/internal/sbi/uecontextmanagement/api_smsf_deregistration_for_non3_gpp_access.go +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Nudm_UECM - * - * Nudm Context Management Service - * - * API version: 1.0.1 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package uecontextmanagement - -import ( - "net/http" - - "github.com/gin-gonic/gin" -) - -// DeregistrationSmsfNon3gppAccess - delete SMSF registration for non 3GPP access -func HTTPDeregistrationSmsfNon3gppAccess(c *gin.Context) { - c.JSON(http.StatusOK, gin.H{}) -} diff --git a/internal/sbi/uecontextmanagement/api_smsf_non3_gpp_access_registration_info_retrieval.go b/internal/sbi/uecontextmanagement/api_smsf_non3_gpp_access_registration_info_retrieval.go deleted file mode 100644 index 75b32fe..0000000 --- a/internal/sbi/uecontextmanagement/api_smsf_non3_gpp_access_registration_info_retrieval.go +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Nudm_UECM - * - * Nudm Context Management Service - * - * API version: 1.0.1 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package uecontextmanagement - -import ( - "net/http" - - "github.com/gin-gonic/gin" -) - -// GetSmsfNon3gppAccess - retrieve the SMSF registration for non-3GPP access information -func HTTPGetSmsfNon3gppAccess(c *gin.Context) { - c.JSON(http.StatusOK, gin.H{}) -} diff --git a/internal/sbi/uecontextmanagement/api_smsf_registration_for3_gpp_access.go b/internal/sbi/uecontextmanagement/api_smsf_registration_for3_gpp_access.go deleted file mode 100644 index 8474685..0000000 --- a/internal/sbi/uecontextmanagement/api_smsf_registration_for3_gpp_access.go +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Nudm_UECM - * - * Nudm Context Management Service - * - * API version: 1.0.1 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package uecontextmanagement - -import ( - "net/http" - - "github.com/gin-gonic/gin" -) - -// UpdateSMSFReg3GPP - register as SMSF for 3GPP access -func HTTPUpdateSMSFReg3GPP(c *gin.Context) { - c.JSON(http.StatusOK, gin.H{}) -} diff --git a/internal/sbi/uecontextmanagement/api_smsf_registration_for_non3_gpp_access.go b/internal/sbi/uecontextmanagement/api_smsf_registration_for_non3_gpp_access.go deleted file mode 100644 index 1d32047..0000000 --- a/internal/sbi/uecontextmanagement/api_smsf_registration_for_non3_gpp_access.go +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Nudm_UECM - * - * Nudm Context Management Service - * - * API version: 1.0.1 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package uecontextmanagement - -import ( - "net/http" - - "github.com/gin-gonic/gin" -) - -// RegistrationSmsfNon3gppAccess - register as SMSF for non-3GPP access -func HTTPRegistrationSmsfNon3gppAccess(c *gin.Context) { - c.JSON(http.StatusOK, gin.H{}) -} diff --git a/internal/sbi/uecontextmanagement/routers.go b/internal/sbi/uecontextmanagement/routers.go deleted file mode 100644 index ab67e22..0000000 --- a/internal/sbi/uecontextmanagement/routers.go +++ /dev/null @@ -1,183 +0,0 @@ -/* - * Nudm_UECM - * - * Nudm Context Management Service - * - * API version: 1.0.0 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package uecontextmanagement - -import ( - "net/http" - "strings" - - "github.com/gin-gonic/gin" - - "github.com/free5gc/openapi/models" - udm_context "github.com/free5gc/udm/internal/context" - "github.com/free5gc/udm/internal/logger" - "github.com/free5gc/udm/internal/util" - "github.com/free5gc/udm/pkg/factory" - logger_util "github.com/free5gc/util/logger" -) - -// Route is the information for every URI. -type Route struct { - // Name is the name of this Route. - Name string - // Method is the string for the HTTP method. ex) GET, POST etc.. - Method string - // Pattern is the pattern of the URI. - Pattern string - // HandlerFunc is the handler function of this route. - HandlerFunc gin.HandlerFunc -} - -// Routes is the list of the generated Route. -type Routes []Route - -// NewRouter returns a new router. -func NewRouter() *gin.Engine { - router := logger_util.NewGinWithLogrus(logger.GinLog) - - AddService(router) - return router -} - -func AddService(engine *gin.Engine) *gin.RouterGroup { - group := engine.Group(factory.UdmUecmResUriPrefix) - routerAuthorizationCheck := util.NewRouterAuthorizationCheck(models.ServiceName_NUDM_UECM) - group.Use(func(c *gin.Context) { - routerAuthorizationCheck.Check(c, udm_context.GetSelf()) - }) - for _, route := range routes { - switch route.Method { - case "GET": - group.GET(route.Pattern, route.HandlerFunc) - case "POST": - group.POST(route.Pattern, route.HandlerFunc) - case "PUT": - group.PUT(route.Pattern, route.HandlerFunc) - case "DELETE": - group.DELETE(route.Pattern, route.HandlerFunc) - case "PATCH": - group.PATCH(route.Pattern, route.HandlerFunc) - } - } - - return group -} - -// Index is the index handler. -func Index(c *gin.Context) { - c.String(http.StatusOK, "Hello World!") -} - -var routes = Routes{ - { - "Index", - "GET", - "/", - Index, - }, - - { - "GetAmf3gppAccess", - strings.ToUpper("Get"), - "/:ueId/registrations/amf-3gpp-access", - HTTPGetAmf3gppAccess, - }, - - { - "GetAmfNon3gppAccess", - strings.ToUpper("Get"), - "/:ueId/registrations/amf-non-3gpp-access", - HTTPGetAmfNon3gppAccess, - }, - - { - "RegistrationAmf3gppAccess", - strings.ToUpper("Put"), - "/:ueId/registrations/amf-3gpp-access", - HTTPRegistrationAmf3gppAccess, - }, - - { - "Register", - strings.ToUpper("Put"), - "/:ueId/registrations/amf-non-3gpp-access", - HTTPRegistrationAmfNon3gppAccess, - }, - - { - "UpdateAmf3gppAccess", - strings.ToUpper("Patch"), - "/:ueId/registrations/amf-3gpp-access", - HTTPUpdateAmf3gppAccess, - }, - - { - "UpdateAmfNon3gppAccess", - strings.ToUpper("Patch"), - "/:ueId/registrations/amf-non-3gpp-access", - HTTPUpdateAmfNon3gppAccess, - }, - - { - "DeregistrationSmfRegistrations", - strings.ToUpper("Delete"), - "/:ueId/registrations/smf-registrations/:pduSessionId", - HTTPDeregistrationSmfRegistrations, - }, - - { - "RegistrationSmfRegistrations", - strings.ToUpper("Put"), - "/:ueId/registrations/smf-registrations/:pduSessionId", - HTTPRegistrationSmfRegistrations, - }, - - { - "GetSmsf3gppAccess", - strings.ToUpper("Get"), - "/:ueId/registrations/smsf-3gpp-access", - HTTPGetSmsf3gppAccess, - }, - - { - "DeregistrationSmsf3gppAccess", - strings.ToUpper("Delete"), - "/:ueId/registrations/smsf-3gpp-access", - HTTPDeregistrationSmsf3gppAccess, - }, - - { - "DeregistrationSmsfNon3gppAccess", - strings.ToUpper("Delete"), - "/:ueId/registrations/smsf-non-3gpp-access", - HTTPDeregistrationSmsfNon3gppAccess, - }, - - { - "GetSmsfNon3gppAccess", - strings.ToUpper("Get"), - "/:ueId/registrations/smsf-non-3gpp-access", - HTTPGetSmsfNon3gppAccess, - }, - - { - "UpdateSMSFReg3GPP", - strings.ToUpper("Put"), - "/:ueId/registrations/smsf-3gpp-access", - HTTPUpdateSMSFReg3GPP, - }, - - { - "RegistrationSmsfNon3gppAccess", - strings.ToUpper("Put"), - "/:ueId/registrations/smsf-non-3gpp-access", - HTTPRegistrationSmsfNon3gppAccess, - }, -}