Skip to content

Commit

Permalink
paging fix,handle deregistration notification implimentation (#214)
Browse files Browse the repository at this point in the history
Co-authored-by: gab-arrobo <[email protected]>
  • Loading branch information
akhila-s06 and gab-arrobo committed Apr 19, 2024
1 parent bc05cf2 commit 6664805
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 1 deletion.
1 change: 0 additions & 1 deletion context/amf_ran.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ func (ran *AmfRan) SetRanId(ranNodeId *ngapType.GlobalRANNodeID) {
if ranId.GNbId != nil {
ran.GnbId += ranId.GNbId.GNBValue
}
AMF_Self().AmfRanPool.Store(ran.GnbId, ran)
}

func (ran *AmfRan) ConvertGnbIdToRanId(gnbId string) (ranNodeId *models.GlobalRanNodeId) {
Expand Down
68 changes: 68 additions & 0 deletions httpcallback/api_dereg_notify.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// SPDX-FileCopyrightText: 2022 Infosys Limited
// Copyright 2019 free5GC.org
//
// SPDX-License-Identifier: Apache-2.0
//

package httpcallback

import (
"net/http"

"github.com/gin-gonic/gin"
"github.com/omec-project/amf/logger"
"github.com/omec-project/amf/producer"
"github.com/omec-project/openapi"
"github.com/omec-project/openapi/models"
"github.com/omec-project/util/httpwrapper"
)

func HTTPDeregistrationNotification(c *gin.Context) {
var deregistrationData models.DeregistrationData

requestBody, err := c.GetRawData()
if err != nil {
logger.CallbackLog.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(&deregistrationData, 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, deregistrationData)
if supi, exists := c.Params.Get("supi"); exists {
req.Params["supi"] = supi
}
rsp := producer.HandleDeregistrationNotification(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)
}

}
6 changes: 6 additions & 0 deletions httpcallback/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,10 @@ var routes = Routes{
"/nf-status-notify",
HTTPNfSubscriptionStatusNotify,
},
{
"DeregistrationNotify",
strings.ToUpper("Post"),
":supi/deregistration-notify",
HTTPDeregistrationNotification,
},
}
49 changes: 49 additions & 0 deletions producer/callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,3 +493,52 @@ func NfSubscriptionStatusNotifyProcedure(notificationData models.NotificationDat

return nil
}

func HandleDeregistrationNotification(request *httpwrapper.Request) *httpwrapper.Response {
logger.ProducerLog.Infoln("Handle Deregistration Notification")
deregistrationData := request.Body.(models.DeregistrationData)

switch deregistrationData.DeregReason {
case "SUBSCRIPTION_WITHDRAWN":
amfSelf := context.AMF_Self()
if supi, exists := request.Params["supi"]; exists {
reqUri := request.URL.RequestURI()
if ue, ok := amfSelf.AmfUeFindBySupi(supi); ok {
logger.ProducerLog.Debugln("amf ue found: ", ue.Supi)
sbiMsg := context.SbiMsg{
UeContextId: ue.Supi,
ReqUri: reqUri,
Msg: nil,
Result: make(chan context.SbiResponseMsg, 10),
}
ue.EventChannel.UpdateSbiHandler(HandleOAMPurgeUEContextRequest)
ue.EventChannel.SubmitMessage(sbiMsg)
msg := <-sbiMsg.Result
if msg.ProblemDetails != nil {
return httpwrapper.NewResponse(int(msg.ProblemDetails.(*models.ProblemDetails).Status), nil, msg.ProblemDetails.(*models.ProblemDetails))
} else {
return httpwrapper.NewResponse(http.StatusNoContent, nil, nil)
}
} else {
return httpwrapper.NewResponse(http.StatusNotFound, nil, nil)
}
}

case "":
problemDetails := &models.ProblemDetails{
Status: http.StatusBadRequest,
Cause: "MANDATORY_IE_MISSING", // Defined in TS 29.503 6.2.5.2
Detail: "Missing IE [DeregReason] in DeregistrationData",
}
return httpwrapper.NewResponse(int(problemDetails.Status), nil, problemDetails)

default:
problemDetails := &models.ProblemDetails{
Status: http.StatusNotImplemented,
Cause: "NOT_IMPLEMENTED", // Defined in TS 29.503
Detail: "Unsupported [DeregReason] in DeregistrationData",
}
return httpwrapper.NewResponse(int(problemDetails.Status), nil, problemDetails)
}
return nil
}

0 comments on commit 6664805

Please sign in to comment.