Skip to content

Commit

Permalink
add2
Browse files Browse the repository at this point in the history
  • Loading branch information
KunLee76 committed Jan 28, 2024
1 parent 59cda0c commit 17abf70
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 22 deletions.
1 change: 1 addition & 0 deletions internal/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ type NFContext interface {
}

var _ NFContext = &PCFContext{}

//var pcfContext PCFContext

var pcfContext = PCFContext{}
Expand Down
1 change: 0 additions & 1 deletion internal/sbi/consumer/communication.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package consumer

import (
"context"
"fmt"
"strings"

Expand Down
13 changes: 10 additions & 3 deletions internal/sbi/consumer/influenceDataSubscription.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package consumer

import (
"context"
"strconv"
"strings"

Expand All @@ -20,10 +19,14 @@ func CreateInfluenceDataSubscription(ue *pcf_context.UeContext, request models.S
logger.ConsumerLog.Warnf("Can't find corresponding UDR with UE[%s]", ue.Supi)
return "", &problemDetail, nil
}
ctx, pd, err := pcf_context.GetSelf().GetTokenCtx("nnrf-nfm", models.NfType_NRF)
if err != nil {
return "", pd, err
}
udrClient := util.GetNudrClient(ue.UdrUri)
trafficInfluSub := buildTrafficInfluSub(request)
_, httpResp, localErr := udrClient.InfluenceDataSubscriptionsCollectionApi.
ApplicationDataInfluenceDataSubsToNotifyPost(context.Background(), trafficInfluSub)
ApplicationDataInfluenceDataSubsToNotifyPost(ctx, trafficInfluSub)
if localErr == nil {
locationHeader := httpResp.Header.Get("Location")
subscriptionID = locationHeader[strings.LastIndex(locationHeader, "/")+1:]
Expand Down Expand Up @@ -70,9 +73,13 @@ func RemoveInfluenceDataSubscription(ue *pcf_context.UeContext, subscriptionID s
logger.ConsumerLog.Warnf("Can't find corresponding UDR with UE[%s]", ue.Supi)
return &problemDetail, nil
}
ctx, pd, err := pcf_context.GetSelf().GetTokenCtx("nnrf-nfm", models.NfType_NRF)
if err != nil {
return pd, err
}
udrClient := util.GetNudrClient(ue.UdrUri)
httpResp, localErr := udrClient.IndividualInfluenceDataSubscriptionDocumentApi.
ApplicationDataInfluenceDataSubsToNotifySubscriptionIdDelete(context.Background(), subscriptionID)
ApplicationDataInfluenceDataSubsToNotifySubscriptionIdDelete(ctx, subscriptionID)
if localErr == nil {
logger.ConsumerLog.Debugf("Nudr_DataRepository Remove Influence Data Subscription Status %s",
httpResp.Status)
Expand Down
24 changes: 20 additions & 4 deletions internal/sbi/producer/ampolicy.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package producer

import (
"context"
"fmt"
"net/http"
"reflect"
Expand Down Expand Up @@ -235,10 +234,15 @@ func PostPoliciesProcedure(polAssoId string,
assolId := fmt.Sprintf("%s-%d", ue.Supi, ue.PolAssociationIDGenerator)
amPolicy := ue.AMPolicyData[assolId]

ctx, pd, err := pcf_context.GetSelf().GetTokenCtx("nnrf-nfm", models.NfType_NRF)
if err != nil {
return nil, "", pd
}

if amPolicy == nil || amPolicy.AmPolicyData == nil {
client := util.GetNudrClient(udrUri)
var response *http.Response
amData, response, err := client.DefaultApi.PolicyDataUesUeIdAmDataGet(context.Background(), ue.Supi)
amData, response, err := client.DefaultApi.PolicyDataUesUeIdAmDataGet(ctx, ue.Supi)
if err != nil || response == nil || response.StatusCode != http.StatusOK {
problemDetail := util.GetProblemDetail("Can't find UE AM Policy Data in UDR", util.USER_UNKNOWN)
logger.AmPolicyLog.Errorf("Can't find UE[%s] AM Policy Data in UDR", ue.Supi)
Expand Down Expand Up @@ -326,10 +330,16 @@ func SendAMPolicyUpdateNotification(ue *pcf_context.UeContext, PolId string, req
logger.AmPolicyLog.Warnf("Policy Update Notification Error[Can't find polAssoId[%s] in UE(%s)]", PolId, ue.Supi)
return
}

ctx, _, err := pcf_context.GetSelf().GetTokenCtx("nnrf-nfm", models.NfType_NRF)
if err != nil {
return
}

client := util.GetNpcfAMPolicyCallbackClient()
uri := amPolicyData.NotificationUri
for uri != "" {
rsp, err := client.DefaultCallbackApi.PolicyUpdateNotification(context.Background(), uri, request)
rsp, err := client.DefaultCallbackApi.PolicyUpdateNotification(ctx, uri, request)
if err != nil {
if rsp != nil && rsp.StatusCode != http.StatusNoContent {
logger.AmPolicyLog.Warnf("Policy Update Notification Error[%s]", rsp.Status)
Expand Down Expand Up @@ -378,9 +388,15 @@ func SendAMPolicyTerminationRequestNotification(ue *pcf_context.UeContext,
}
client := util.GetNpcfAMPolicyCallbackClient()
uri := amPolicyData.NotificationUri

ctx, _, err := pcf_context.GetSelf().GetTokenCtx("nnrf-nfm", models.NfType_NRF)
if err != nil {
return
}

for uri != "" {
rsp, err := client.DefaultCallbackApi.PolicyAssocitionTerminationRequestNotification(
context.Background(), uri, request)
ctx, uri, request)
if err != nil {
if rsp != nil && rsp.StatusCode != http.StatusNoContent {
logger.AmPolicyLog.Warnf("Policy Assocition Termination Request Notification Error[%s]", rsp.Status)
Expand Down
17 changes: 13 additions & 4 deletions internal/sbi/producer/bdtpolicy.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package producer

import (
"context"
"fmt"
"net/http"

Expand Down Expand Up @@ -119,7 +118,11 @@ func updateBDTPolicyContextProcedure(request models.BdtPolicyDataPatch, bdtPolic
BdtData: optional.NewInterface(bdtData),
}
client := util.GetNudrClient(getDefaultUdrUri(pcfSelf))
rsp, err := client.DefaultApi.PolicyDataBdtDataBdtReferenceIdPut(context.Background(), bdtData.BdtRefId, &param)
ctx, pd, err := pcf_context.GetSelf().GetTokenCtx("nnrf-nfm", models.NfType_NRF)
if err != nil {
return nil, pd
}
rsp, err := client.DefaultApi.PolicyDataBdtDataBdtReferenceIdPut(ctx, bdtData.BdtRefId, &param)
if err != nil {
logger.BdtPolicyLog.Warnf("UDR Put BdtDate error[%s]", err.Error())
}
Expand Down Expand Up @@ -189,8 +192,14 @@ func createBDTPolicyContextProcedure(request *models.BdtReqData) (
pcfSelf.SetDefaultUdrURI(udrUri)

// Query BDT DATA array from UDR

ctx, pd, err := pcf_context.GetSelf().GetTokenCtx("nnrf-nfm", models.NfType_NRF)
if err != nil {
return nil, nil, pd
}

client := util.GetNudrClient(udrUri)
bdtDatas, httpResponse, err := client.DefaultApi.PolicyDataBdtDataGet(context.Background())
bdtDatas, httpResponse, err := client.DefaultApi.PolicyDataBdtDataGet(ctx)
if err != nil || httpResponse == nil || httpResponse.StatusCode != http.StatusOK {
problemDetails = &models.ProblemDetails{
Status: http.StatusServiceUnavailable,
Expand Down Expand Up @@ -254,7 +263,7 @@ func createBDTPolicyContextProcedure(request *models.BdtReqData) (
}

var updateRsp *http.Response
if rsp, rspErr := client.DefaultApi.PolicyDataBdtDataBdtReferenceIdPut(context.Background(),
if rsp, rspErr := client.DefaultApi.PolicyDataBdtDataBdtReferenceIdPut(ctx,
bdtPolicyData.BdtRefId, &param); rspErr != nil {
logger.BdtPolicyLog.Warnf("UDR Put BdtDate error[%s]", rspErr.Error())
} else {
Expand Down
25 changes: 21 additions & 4 deletions internal/sbi/producer/policyauthorization.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package producer

import (
"context"
"fmt"
"net/http"
"strings"
Expand Down Expand Up @@ -895,12 +894,18 @@ func SendAppSessionEventNotification(appSession *pcf_context.AppSessionData, req
return
}
uri := appSession.EventUri

ctx, _, err := pcf_context.GetSelf().GetTokenCtx("nnrf-nfm", models.NfType_NRF)
if err != nil {
return
}

if uri != "" {
request.EvSubsUri = fmt.Sprintf("%s/events-subscription",
util.GetResourceUri(models.ServiceName_NPCF_POLICYAUTHORIZATION, appSession.AppSessionId))
client := util.GetNpcfPolicyAuthorizationCallbackClient()
httpResponse, err := client.PolicyAuthorizationEventNotificationApi.PolicyAuthorizationEventNotification(
context.Background(), uri, request)
ctx, uri, request)
if err != nil {
if httpResponse != nil {
logger.PolicyAuthLog.Warnf("Send App Session Event Notification Error[%s]", httpResponse.Status)
Expand Down Expand Up @@ -1071,11 +1076,17 @@ func SendAppSessionTermination(appSession *pcf_context.AppSessionData, request m
return
}
uri := appSession.AppSessionContext.AscReqData.NotifUri

ctx, _, err := pcf_context.GetSelf().GetTokenCtx("nnrf-nfm", models.NfType_NRF)
if err != nil {
return
}

if uri != "" {
request.ResUri = util.GetResourceUri(models.ServiceName_NPCF_POLICYAUTHORIZATION, appSession.AppSessionId)
client := util.GetNpcfPolicyAuthorizationCallbackClient()
httpResponse, err := client.PolicyAuthorizationTerminateRequestApi.PolicyAuthorizationTerminateRequest(
context.Background(), uri, request)
ctx, uri, request)
if err != nil {
if httpResponse != nil {
logger.PolicyAuthLog.Warnf("Send App Session Termination Error[%s]", httpResponse.Status)
Expand Down Expand Up @@ -1118,8 +1129,14 @@ func handleBDTPolicyInd(pcfSelf *pcf_context.PCFContext,
SuppFeat: pcfSelf.PcfSuppFeats[models.ServiceName_NPCF_POLICYAUTHORIZATION].NegotiateWith(
requestSuppFeat).String(),
}

ctx, _, err := pcf_context.GetSelf().GetTokenCtx("nnrf-nfm", models.NfType_NRF)
if err != nil {
return err
}

client := util.GetNudrClient(getDefaultUdrUri(pcfSelf))
bdtData, resp, err1 := client.DefaultApi.PolicyDataBdtDataBdtReferenceIdGet(context.Background(), req.BdtRefId)
bdtData, resp, err1 := client.DefaultApi.PolicyDataBdtDataBdtReferenceIdGet(ctx, req.BdtRefId)
if err1 != nil {
return fmt.Errorf("UDR Get BdtData error[%s]", err1.Error())
} else if resp == nil || resp.StatusCode != http.StatusOK {
Expand Down
34 changes: 28 additions & 6 deletions internal/sbi/producer/smpolicy.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package producer

import (
"context"
"fmt"
"net/http"
"strconv"
Expand Down Expand Up @@ -108,7 +107,13 @@ func createSMPolicyProcedure(request models.SmPolicyContextData) (
Dnn: optional.NewString(request.Dnn),
}
var response *http.Response
smData, response, err = client.DefaultApi.PolicyDataUesUeIdSmDataGet(context.Background(), ue.Supi, &param)

ctx, pd, err := pcf_context.GetSelf().GetTokenCtx("nnrf-nfm", models.NfType_NRF)
if err != nil {
return nil, nil, pd
}

smData, response, err = client.DefaultApi.PolicyDataUesUeIdSmDataGet(ctx, ue.Supi, &param)
if err != nil || response == nil || response.StatusCode != http.StatusOK {
problemDetail := util.GetProblemDetail("Can't find UE SM Policy Data in UDR", util.USER_UNKNOWN)
logger.SmPolicyLog.Warnf("Can't find UE[%s] SM Policy Data in UDR", ue.Supi)
Expand Down Expand Up @@ -254,10 +259,15 @@ func createSMPolicyProcedure(request models.SmPolicyContextData) (
Supis: optional.NewInterface([]string{request.Supi}),
}

ctx, pd, err := pcf_context.GetSelf().GetTokenCtx("nnrf-nfm", models.NfType_NRF)
if err != nil {
return nil, nil, pd
}

udrClient := util.GetNudrClient(udrUri)
var resp *http.Response
trafficInfluDatas, resp, err := udrClient.InfluenceDataApi.
ApplicationDataInfluenceDataGet(context.Background(), &reqParam)
ApplicationDataInfluenceDataGet(ctx, &reqParam)
if err != nil || resp == nil || resp.StatusCode != http.StatusOK {
logger.SmPolicyLog.Warnf("Error response from UDR Application Data Influence Data Get")
}
Expand Down Expand Up @@ -309,7 +319,7 @@ func createSMPolicyProcedure(request models.SmPolicyContextData) (
bsfUri := consumer.SendNFInstancesBSF(pcf_context.GetSelf().NrfUri)
if bsfUri != "" {
bsfClient := util.GetNbsfClient(bsfUri)
_, resp, err = bsfClient.PCFBindingsCollectionApi.CreatePCFBinding(context.Background(), pcfBinding)
_, resp, err = bsfClient.PCFBindingsCollectionApi.CreatePCFBinding(ctx, pcfBinding)
if err != nil || resp == nil || resp.StatusCode != http.StatusCreated {
logger.SmPolicyLog.Warnf("Create PCF binding data in BSF error[%+v]", err)
// Uncomment the following to return error response --> PDU SessEstReq will fail
Expand Down Expand Up @@ -1010,9 +1020,15 @@ func SendSMPolicyUpdateNotification(
logger.SmPolicyLog.Warnln("SM Policy Update Notification Error[uri is empty]")
return
}

ctx, _, err := pcf_context.GetSelf().GetTokenCtx("nnrf-nfm", models.NfType_NRF)
if err != nil {
return
}

client := util.GetNpcfSMPolicyCallbackClient()
logger.SmPolicyLog.Infof("Send SM Policy Update Notification to SMF")
_, httpResponse, err := client.DefaultCallbackApi.SmPolicyUpdateNotification(context.Background(), uri, *request)
_, httpResponse, err := client.DefaultCallbackApi.SmPolicyUpdateNotification(ctx, uri, *request)
defer func() {
if httpResponse != nil {
if err = httpResponse.Body.Close(); err != nil {
Expand Down Expand Up @@ -1046,9 +1062,15 @@ func SendSMPolicyTerminationRequestNotification(
logger.SmPolicyLog.Warnln("SM Policy Termination Request Notification Error[uri is empty]")
return
}

ctx, _, err := pcf_context.GetSelf().GetTokenCtx("nnrf-nfm", models.NfType_NRF)
if err != nil {
return
}

client := util.GetNpcfSMPolicyCallbackClient()
rsp, err := client.DefaultCallbackApi.
SmPolicyControlTerminationRequestNotification(context.Background(), uri, *request)
SmPolicyControlTerminationRequestNotification(ctx, uri, *request)
defer func() {
if rsp != nil {
if err = rsp.Body.Close(); err != nil {
Expand Down

0 comments on commit 17abf70

Please sign in to comment.