Skip to content

Commit

Permalink
feat: add GetAfInfluenceData & TODO
Browse files Browse the repository at this point in the history
  • Loading branch information
ianchen0119 committed Jul 17, 2024
1 parent 87f04ae commit d21af26
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 17 deletions.
49 changes: 49 additions & 0 deletions internal/sbi/consumer/udr_service.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package consumer

import (
"errors"
"strconv"
"strings"
"sync"

"github.com/antihax/optional"
"github.com/free5gc/openapi"
"github.com/free5gc/openapi/Nudr_DataRepository"
"github.com/free5gc/openapi/models"
Expand Down Expand Up @@ -43,6 +45,53 @@ func (s *nudrService) getDataSubscription(uri string) *Nudr_DataRepository.APICl
return client
}

func (s *nudrService) GetAfInfluenceData(
ue *pcf_context.UeContext,
supi, dnn string,
interGrpIds []string,
sliceInfo *models.Snssai,
) (
tiData []models.TrafficInfluData,
problemDetails *models.ProblemDetails,
err error,
) {
client := s.getDataSubscription(ue.UdrUri)
ctx, pd, err := s.consumer.Context().GetTokenCtx(
models.ServiceName_NUDR_DR,
models.NfType_UDR)
if err != nil {
return []models.TrafficInfluData{}, pd, err
}

param := &Nudr_DataRepository.ApplicationDataInfluenceDataGetParamOpts{
Dnns: optional.NewInterface([]string{dnn}),
Snssais: optional.NewInterface(
util.MarshToJsonString([]models.Snssai{*sliceInfo}),
),
Supis: optional.NewInterface([]string{supi}),
InfluenceIds: optional.NewInterface(interGrpIds),
}

tiData, rsp, err := client.InfluenceDataApi.ApplicationDataInfluenceDataGet(ctx, param)
defer func() {
if rsp != nil {
if rsp.Body != nil {
if rsp.Body.Close() != nil {
logger.ConsumerLog.Errorf("getAfInfluenceData response body cannot close")
}
}
}
}()
if err != nil {
apiError := new(openapi.GenericOpenAPIError)
if ok := errors.As(err, &apiError); ok {
problemDetails = apiError.Model().(*models.ProblemDetails)
}
}

return tiData, problemDetails, err
}

func (s *nudrService) CreateInfluenceDataSubscription(ue *pcf_context.UeContext, request models.SmPolicyContextData) (
subscriptionID string, problemDetails *models.ProblemDetails, err error,
) {
Expand Down
25 changes: 8 additions & 17 deletions internal/sbi/processor/smpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,29 +366,19 @@ func (p *Processor) HandleCreateSmPolicyRequest(
smPolicyData.PolicyDecision = &decision
// TODO: PCC rule, PraInfo ...
// Get Application Data Influence Data from UDR
reqParam := Nudr_DataRepository.ApplicationDataInfluenceDataGetParamOpts{
Dnns: optional.NewInterface([]string{request.Dnn}),
Snssais: optional.NewInterface(util.MarshToJsonString([]models.Snssai{*request.SliceInfo})),
InternalGroupIds: optional.NewInterface(request.InterGrpIds),
Supis: optional.NewInterface([]string{request.Supi}),
}

ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR)
trafficInfluDatas, pd, err := p.Consumer().GetAfInfluenceData(
ue,
request.Supi,
request.Dnn,
request.InterGrpIds,
request.SliceInfo,
)
if err != nil {
c.JSON(int(pd.Status), pd)
return
}

udrClient := util.GetNudrClient(udrUri)
var resp *http.Response
trafficInfluDatas, resp, err := udrClient.InfluenceDataApi.
ApplicationDataInfluenceDataGet(ctx, &reqParam)
if err != nil || resp == nil || resp.StatusCode != http.StatusOK {
logger.SmPolicyLog.Warnf("Error response from UDR Application Data Influence Data Get")
}
if err = resp.Body.Close(); err != nil {
logger.SmPolicyLog.Warnf("failed to close response of Application Data Influence Data Get")
}
logger.SmPolicyLog.Infof("Matched [%d] trafficInfluDatas from UDR", len(trafficInfluDatas))
if len(trafficInfluDatas) != 0 {
// UE identity in UDR appData and apply appData to sm poliocy
Expand All @@ -405,6 +395,7 @@ func (p *Processor) HandleCreateSmPolicyRequest(
precedence++
}
}
// TODO: trasfer tiData to tcData and apply to PCC rule
}

// Subscribe to Traffic Influence Data in UDR
Expand Down

0 comments on commit d21af26

Please sign in to comment.