Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions consumer/nf_management.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"github.com/omec-project/udm/logger"
)

const errServerNoResponse = "server no response"

func BuildNFInstance(udmContext *udmContext.UDMContext) (profile models.NfProfile, err error) {
profile.NfInstanceId = udmContext.NfId
profile.NfStatus = models.NfStatus_REGISTERED
Expand Down Expand Up @@ -116,7 +118,7 @@ func SendDeregisterNFInstance() (problemDetails *models.ProblemDetails, err erro
problem := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails)
problemDetails = &problem
} else {
err = openapi.ReportError("server no response")
err = openapi.ReportError(errServerNoResponse)
}
return
}
Expand Down Expand Up @@ -146,7 +148,7 @@ var SendUpdateNFInstance = func(patchItem []models.PatchItem) (nfProfile models.
problem := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails)
problemDetails = &problem
} else {
err = openapi.ReportError("server no response")
err = openapi.ReportError(errServerNoResponse)
}
return
}
Expand Down Expand Up @@ -176,7 +178,7 @@ func SendCreateSubscription(nrfUri string, nrfSubscriptionData models.NrfSubscri
problem := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails)
problemDetails = &problem
} else {
err = openapi.ReportError("server no response")
err = openapi.ReportError(errServerNoResponse)
}
return
}
Expand Down Expand Up @@ -206,7 +208,7 @@ func SendRemoveSubscription(subscriptionId string) (problemDetails *models.Probl
problem := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails)
problemDetails = &problem
} else {
err = openapi.ReportError("server no response")
err = openapi.ReportError(errServerNoResponse)
}
return
}
8 changes: 5 additions & 3 deletions context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ const (
LocationUriAuthEvents // New constant for AuthEvent resource URI type.
)

const uecmUriPrefix = "/nudm-uecm/v1/"

func init() {
UDM_Self().NfService = make(map[models.ServiceName]models.NfService)
UDM_Self().EeSubscriptionIDGenerator = idgenerator.NewGenerator(1, math.MaxInt32)
Expand Down Expand Up @@ -357,11 +359,11 @@ func (context *UDMContext) GetAmfNon3gppRegContext(supi string) *models.AmfNon3G
func (ue *UdmUeContext) GetLocationURI(types int) string {
switch types {
case LocationUriAmf3GppAccessRegistration:
return UDM_Self().GetIPv4Uri() + "/nudm-uecm/v1/" + ue.Supi + "/registrations/amf-3gpp-access"
return UDM_Self().GetIPv4Uri() + uecmUriPrefix + ue.Supi + "/registrations/amf-3gpp-access"
case LocationUriAmfNon3GppAccessRegistration:
return UDM_Self().GetIPv4Uri() + "/nudm-uecm/v1/" + ue.Supi + "/registrations/amf-non-3gpp-access"
return UDM_Self().GetIPv4Uri() + uecmUriPrefix + ue.Supi + "/registrations/amf-non-3gpp-access"
case LocationUriSmfRegistration:
return UDM_Self().GetIPv4Uri() + "/nudm-uecm/v1/" + ue.Supi + "/registrations/smf-registrations/" + ue.PduSessionID
return UDM_Self().GetIPv4Uri() + uecmUriPrefix + ue.Supi + "/registrations/smf-registrations/" + ue.PduSessionID
}
return ""
}
Expand Down
8 changes: 5 additions & 3 deletions eventexposure/api_create_ee_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"github.com/omec-project/util/httpwrapper"
)

const contentTypeJson = "application/json"

// HTTPCreateEeSubscription - Subscribe
func HTTPCreateEeSubscription(c *gin.Context) {
var eeSubscriptionReq models.EeSubscription
Expand All @@ -42,7 +44,7 @@ func HTTPCreateEeSubscription(c *gin.Context) {
return
}

err = openapi.Deserialize(&eeSubscriptionReq, requestBody, "application/json")
err = openapi.Deserialize(&eeSubscriptionReq, requestBody, contentTypeJson)
if err != nil {
problemDetail := "[Request Body] " + err.Error()
rsp := models.ProblemDetails{
Expand All @@ -60,7 +62,7 @@ func HTTPCreateEeSubscription(c *gin.Context) {

rsp := producer.HandleCreateEeSubscription(req)

responseBody, err := openapi.Serialize(rsp.Body, "application/json")
responseBody, err := openapi.Serialize(rsp.Body, contentTypeJson)
if err != nil {
logger.EeLog.Errorln(err)
problemDetails := models.ProblemDetails{
Expand All @@ -70,6 +72,6 @@ func HTTPCreateEeSubscription(c *gin.Context) {
}
c.JSON(http.StatusInternalServerError, problemDetails)
} else {
c.Data(rsp.Status, "application/json", responseBody)
c.Data(rsp.Status, contentTypeJson, responseBody)
}
}
6 changes: 3 additions & 3 deletions eventexposure/api_update_ee_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func HTTPUpdateEeSubscription(c *gin.Context) {
return
}

err = openapi.Deserialize(&patchList, requestBody, "application/json")
err = openapi.Deserialize(&patchList, requestBody, contentTypeJson)
if err != nil {
problemDetail := "[Request Body] " + err.Error()
rsp := models.ProblemDetails{
Expand All @@ -64,7 +64,7 @@ func HTTPUpdateEeSubscription(c *gin.Context) {
if rsp.Status == http.StatusNoContent {
c.Status(rsp.Status)
} else {
responseBody, err := openapi.Serialize(rsp.Body, "application/json")
responseBody, err := openapi.Serialize(rsp.Body, contentTypeJson)
if err != nil {
logger.EeLog.Errorln(err)
problemDetails := models.ProblemDetails{
Expand All @@ -74,7 +74,7 @@ func HTTPUpdateEeSubscription(c *gin.Context) {
}
c.JSON(http.StatusInternalServerError, problemDetails)
} else {
c.Data(rsp.Status, "application/json", responseBody)
c.Data(rsp.Status, contentTypeJson, responseBody)
}
}
}
8 changes: 5 additions & 3 deletions httpcallback/data_change_notification_to_nf.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
"github.com/omec-project/util/httpwrapper"
)

const contentTypeJson = "application/json"

func HTTPDataChangeNotificationToNF(c *gin.Context) {
var dataChangeNotify models.DataChangeNotify
// step 1: retrieve http request body
Expand All @@ -33,7 +35,7 @@ func HTTPDataChangeNotificationToNF(c *gin.Context) {
}

// step 2: convert requestBody to openapi models
err = openapi.Deserialize(&dataChangeNotify, requestBody, "application/json")
err = openapi.Deserialize(&dataChangeNotify, requestBody, contentTypeJson)
if err != nil {
problemDetail := "[Request Body] " + err.Error()
rsp := models.ProblemDetails{
Expand All @@ -50,7 +52,7 @@ func HTTPDataChangeNotificationToNF(c *gin.Context) {
req.Params["supi"] = c.Params.ByName("supi")

rsp := producer.HandleDataChangeNotificationToNFRequest(req)
responseBody, err := openapi.Serialize(rsp.Body, "application/json")
responseBody, err := openapi.Serialize(rsp.Body, contentTypeJson)
if err != nil {
logger.CallbackLog.Errorln(err)
problemDetails := models.ProblemDetails{
Expand All @@ -60,6 +62,6 @@ func HTTPDataChangeNotificationToNF(c *gin.Context) {
}
c.JSON(http.StatusInternalServerError, problemDetails)
} else {
c.Data(rsp.Status, "application/json", responseBody)
c.Data(rsp.Status, contentTypeJson, responseBody)
}
}
8 changes: 5 additions & 3 deletions parameterprovision/api_subscription_data_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"github.com/omec-project/util/httpwrapper"
)

const contentTypeJson = "application/json"

// Update - provision parameters
func HTTPUpdate(c *gin.Context) {
var ppDataReq models.PpData
Expand All @@ -44,7 +46,7 @@ func HTTPUpdate(c *gin.Context) {
}

// step 2: convert requestBody to openapi models
err = openapi.Deserialize(&ppDataReq, requestBody, "application/json")
err = openapi.Deserialize(&ppDataReq, requestBody, contentTypeJson)
if err != nil {
problemDetail := "[Request Body] " + err.Error()
rsp := models.ProblemDetails{
Expand All @@ -62,7 +64,7 @@ func HTTPUpdate(c *gin.Context) {

rsp := producer.HandleUpdateRequest(req)

responseBody, err := openapi.Serialize(rsp.Body, "application/json")
responseBody, err := openapi.Serialize(rsp.Body, contentTypeJson)
if err != nil {
logger.PpLog.Errorln(err)
problemDetails := models.ProblemDetails{
Expand All @@ -72,6 +74,6 @@ func HTTPUpdate(c *gin.Context) {
}
c.JSON(http.StatusInternalServerError, problemDetails)
} else {
c.Data(rsp.Status, "application/json", responseBody)
c.Data(rsp.Status, contentTypeJson, responseBody)
}
}
85 changes: 38 additions & 47 deletions producer/event_exposure.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ import (
"github.com/omec-project/util/httpwrapper"
)

const anyUE = "anyUE"
const (
anyUE = "anyUE"
prefixMsisdn = "msisdn-"
prefixExtid = "extid-"
prefixExtgroupId = "extgroupid-"
fmtPatchItem = "patch item: %+v"
)

func HandleCreateEeSubscription(request *httpwrapper.Request) *httpwrapper.Response {
logger.EeLog.Infoln("Handle Create EE Subscription")
Expand Down Expand Up @@ -47,10 +53,10 @@ func CreateEeSubscriptionProcedure(ueIdentity string,
logger.EeLog.Debugf("udIdentity: %s", ueIdentity)
switch {
// GPSI (MSISDN identifier) represents a single UE
case strings.HasPrefix(ueIdentity, "msisdn-"):
case strings.HasPrefix(ueIdentity, prefixMsisdn):
fallthrough
// GPSI (External identifier) represents a single UE
case strings.HasPrefix(ueIdentity, "extid-"):
case strings.HasPrefix(ueIdentity, prefixExtid):
if ue, ok := udmSelf.UdmUeFindByGpsi(ueIdentity); ok {
id, err := udmSelf.EeSubscriptionIDGenerator.Allocate()
if err != nil {
Expand All @@ -75,7 +81,7 @@ func CreateEeSubscriptionProcedure(ueIdentity string,
return nil, problemDetails
}
// external groupID represents a group of UEs
case strings.HasPrefix(ueIdentity, "extgroupid-"):
case strings.HasPrefix(ueIdentity, prefixExtgroupId):
id, err := udmSelf.EeSubscriptionIDGenerator.Allocate()
if err != nil {
problemDetails := &models.ProblemDetails{
Expand Down Expand Up @@ -145,13 +151,13 @@ func DeleteEeSubscriptionProcedure(ueIdentity string, subscriptionID string) {
udmSelf := udm_context.UDM_Self()

switch {
case strings.HasPrefix(ueIdentity, "msisdn-"):
case strings.HasPrefix(ueIdentity, prefixMsisdn):
fallthrough
case strings.HasPrefix(ueIdentity, "extid-"):
case strings.HasPrefix(ueIdentity, prefixExtid):
if ue, ok := udmSelf.UdmUeFindByGpsi(ueIdentity); ok {
delete(ue.EeSubscriptions, subscriptionID)
}
case strings.HasPrefix(ueIdentity, "extgroupid-"):
case strings.HasPrefix(ueIdentity, prefixExtgroupId):
udmSelf.UdmUePool.Range(func(key, value interface{}) bool {
ue := value.(*udm_context.UdmUeContext)
if ue.ExternalGroupID == ueIdentity {
Expand Down Expand Up @@ -190,73 +196,58 @@ func HandleUpdateEeSubscription(request *httpwrapper.Request) *httpwrapper.Respo
}

// TODO: complete this procedure based on TS 29503 5.5
// applyPatchToUe localizes the patching logic and reduces nesting in the main caller.
func applyPatchToUe(ue *udm_context.UdmUeContext, subscriptionID string, patchList []models.PatchItem) bool {
if _, ok := ue.EeSubscriptions[subscriptionID]; !ok {
return false
}
for _, patchItem := range patchList {
logger.EeLog.Debugf(fmtPatchItem, patchItem)
// TODO: patch the Eesubscription
}
return true
}

func UpdateEeSubscriptionProcedure(ueIdentity string, subscriptionID string,
patchList []models.PatchItem,
) *models.ProblemDetails {
udmSelf := udm_context.UDM_Self()

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{
case strings.HasPrefix(ueIdentity, prefixMsisdn), strings.HasPrefix(ueIdentity, prefixExtid):
ue, ok := udmSelf.UdmUeFindByGpsi(ueIdentity)
if !ok || !applyPatchToUe(ue, subscriptionID, patchList) {
return &models.ProblemDetails{
Status: http.StatusNotFound,
Cause: "SUBSCRIPTION_NOT_FOUND",
}
return problemDetails
}
case strings.HasPrefix(ueIdentity, "extgroupid-"):
return nil

case strings.HasPrefix(ueIdentity, prefixExtgroupId):
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
}
}
applyPatchToUe(ue, subscriptionID, patchList)
}
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
}
}
applyPatchToUe(value.(*udm_context.UdmUeContext), subscriptionID, patchList)
return true
})
return nil

default:
problemDetails := &models.ProblemDetails{
return &models.ProblemDetails{
Status: http.StatusBadRequest,
Cause: "MANDATORY_IE_INCORRECT",
InvalidParams: []models.InvalidParam{
{
Param: "ueIdentity",
Reason: "incorrect format",
},
{Param: "ueIdentity", Reason: "incorrect format"},
},
}
return problemDetails
}
}
Loading
Loading