Skip to content

Commit

Permalink
Modify code to satisfy the coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
iamelisahi committed Aug 17, 2023
1 parent d4c64e9 commit 01a4c45
Showing 1 changed file with 41 additions and 8 deletions.
49 changes: 41 additions & 8 deletions internal/sbi/httpcallback/api_handle_dereg_notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import (
"context"
"net/http"

"github.com/gin-gonic/gin"

amf_context "github.com/free5gc/amf/internal/context"
"github.com/free5gc/amf/internal/logger"
"github.com/free5gc/amf/internal/sbi/consumer"
"github.com/free5gc/openapi"
"github.com/free5gc/openapi/Nudm_SubscriberDataManagement"
"github.com/free5gc/openapi/Nudm_UEContextManagement"
"github.com/free5gc/openapi/models"
"github.com/gin-gonic/gin"
)

func HTTPAmfHandleDeregistrationNotification(c *gin.Context) {
Expand Down Expand Up @@ -66,7 +68,8 @@ func HTTPAmfHandleDeregistrationNotification(c *gin.Context) {
smContext := value.(*amf_context.SmContext)

if smContext.AccessType() == deregData.AccessType {
problemDetails, err := consumer.SendReleaseSmContextRequest(ue, smContext, nil, "", nil)
var problemDetails *models.ProblemDetails
problemDetails, err = consumer.SendReleaseSmContextRequest(ue, smContext, nil, "", nil)
if problemDetails != nil {
ue.GmmLog.Errorf("Release SmContext Failed Problem[%+v]", problemDetails)
} else if err != nil {
Expand Down Expand Up @@ -98,11 +101,18 @@ func HTTPAmfHandleDeregistrationNotification(c *gin.Context) {
configuration := Nudm_UEContextManagement.NewConfiguration()
configuration.SetBasePath(ue.NudmUECMUri)
client := Nudm_UEContextManagement.NewAPIClient(configuration)
httpResp, err := client.ParameterUpdateInTheAMFRegistrationFor3GPPAccessApi.Update(
var httpResp *http.Response
httpResp, err = client.ParameterUpdateInTheAMFRegistrationFor3GPPAccessApi.Update(
context.Background(),
ue.Supi,
regModification,
)
defer func() {
err = httpResp.Body.Close()
if err != nil {
logger.CallbackLog.Errorf("Body close error %v", err)
}
}()

switch httpResp.StatusCode {
case 204:
Expand All @@ -118,17 +128,40 @@ func HTTPAmfHandleDeregistrationNotification(c *gin.Context) {
// TODO: How to handle the error?
problemDetails := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails)
logger.CallbackLog.Errorf("AMF Deregistration: %+v", problemDetails)
return
default:
logger.CallbackLog.Warningf("No handler for status during deregistration procedure: %v", httpResp.Status)
}
}

// TS 23.502 - 4.2.2.3.3 Network-initiated Deregistration
// The AMF also unsubscribes with the UDM using Nudm_SDM_Unsubscribe service operation.
problemDetails, err := consumer.SDMUnsubscribe(ue)
if problemDetails != nil {
logger.CallbackLog.Errorf("AMF SDM Unsubscribe: %+v", problemDetails)
configuration := Nudm_SubscriberDataManagement.NewConfiguration()
configuration.SetBasePath(ue.NudmSDMUri)
client := Nudm_SubscriberDataManagement.NewAPIClient(configuration)
var httpResp *http.Response
httpResp, err = client.SubscriptionDeletionApi.Unsubscribe(context.Background(), ue.Supi, ue.SdmSubscriptionId)
if err != nil {
logger.CallbackLog.Errorf("AMF unsubscribes the UE[%s] with the UDM: %v", ue.Supi, err)
}
defer func() {
err = httpResp.Body.Close()
if err != nil {
logger.CallbackLog.Errorf("Body close error %v", err)
}
}()

switch httpResp.StatusCode {
case 204:
// Successful response
case 404:
problemDetails := &models.ProblemDetails{
Status: http.StatusNotFound,
Cause: "CONTEXT_NOT_FOUND",
}
c.JSON(http.StatusNotFound, problemDetails)
return
default:
logger.CallbackLog.Warningf("No handler for status during unsubscribe procedure: %v", httpResp.Status)
}

// TS 23.502 - 4.2.2.2.2 General Registration
Expand All @@ -138,5 +171,5 @@ func HTTPAmfHandleDeregistrationNotification(c *gin.Context) {
// TS 23.503 - 5.3.2.3.2 UDM initiated NF Deregistration
// The AMF acknowledges the Nudm_UECM_DeRegistrationNotification to the UDM.
c.JSON(http.StatusNoContent, nil)
return
// return
}

0 comments on commit 01a4c45

Please sign in to comment.