Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: ratingGroup map with smPolicyId and refactor allocation and release #23

Merged
merged 4 commits into from
Mar 22, 2024
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
3 changes: 3 additions & 0 deletions internal/context/ue.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ type UeContext struct {
AppSessionIdStore *AppSessionIdStore
PolicyDataSubscriptionStore *models.PolicyDataSubscription
PolicyDataChangeStore *models.PolicyDataChangeNotification

// ChargingRatingGroup
RatingGroupData map[string][]int32 // use smPolicyId(ue.Supi-pduSessionId) as key
}

type UeAMPolicyData struct {
Expand Down
44 changes: 33 additions & 11 deletions internal/sbi/producer/smpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,16 @@ func createSMPolicyProcedure(request models.SmPolicyContextData) (
}
util.SetPccRuleRelatedData(&decision, pcc, nil, nil, chgData, nil)

chargingBsonM := bson.M{
"ratingGroup": chgData.RatingGroup,
}
logger.SmPolicyLog.Traceln("put ratingGroup to MongoDB")
if _, err = mongoapi.RestfulAPIPutOne(chargingDataColl, filterCharging, chargingBsonM, queryStrength); err != nil {
chargingInterface["ratingGroup"] = chgData.RatingGroup
logger.SmPolicyLog.Tracef("put ratingGroup[%+v] for [%+v] to MongoDB", chgData.RatingGroup, ue.Supi)
if _, err = mongoapi.RestfulAPIPutOne(
chargingDataColl, chargingInterface, chargingInterface, queryStrength); err != nil {
logger.SmPolicyLog.Errorf("Fail to put charging data to mongoDB err: %+v", err)
}
if ue.RatingGroupData == nil {
ue.RatingGroupData = make(map[string][]int32)
}
ue.RatingGroupData[smPolicyID] = append(ue.RatingGroupData[smPolicyID], chgData.RatingGroup)

smPolicyData.ChargingIdGenerator++
}
Expand Down Expand Up @@ -329,8 +332,10 @@ func createSMPolicyProcedure(request models.SmPolicyContextData) (
}, "")

filterCharging := bson.M{
"ueId": ue.Supi, "snssai": util.SnssaiModelsToHex(*request.SliceInfo),
"dnn": request.Dnn, "filter": val,
"ueId": ue.Supi,
"snssai": util.SnssaiModelsToHex(*request.SliceInfo),
"dnn": request.Dnn,
"filter": val,
}
var chargingInterface map[string]interface{}
chargingInterface, err = mongoapi.RestfulAPIGetOne(chargingDataColl, filterCharging, 2)
Expand Down Expand Up @@ -363,15 +368,19 @@ func createSMPolicyProcedure(request models.SmPolicyContextData) (
decision.ChgDecs = make(map[string]*models.ChargingData)
}

chargingBsonM := bson.M{
"ratingGroup": chgData.RatingGroup,
}
if _, err = mongoapi.RestfulAPIPutOne(chargingDataColl, filterCharging, chargingBsonM, queryStrength); err != nil {
chargingInterface["ratingGroup"] = chgData.RatingGroup
logger.SmPolicyLog.Tracef("put ratingGroup[%+v] for [%+v] to MongoDB", chgData.RatingGroup, ue.Supi)
if _, err = mongoapi.RestfulAPIPutOne(
chargingDataColl, chargingInterface, chargingInterface, queryStrength); err != nil {
logger.SmPolicyLog.Errorf("Fail to put charging data to mongoDB err: %+v", err)
} else {
util.SetPccRuleRelatedData(&decision, pccRule, nil, nil, chgData, nil)
smPolicyData.ChargingIdGenerator++
}
if ue.RatingGroupData == nil {
ue.RatingGroupData = make(map[string][]int32)
}
ue.RatingGroupData[smPolicyID] = append(ue.RatingGroupData[smPolicyID], chgData.RatingGroup)
}
qosRef := strconv.Itoa(int(flowRule["qosRef"].(float64)))
util.SetPccRuleRelatedByQosRef(&decision, pccRule, qosRef)
Expand Down Expand Up @@ -542,6 +551,19 @@ func deleteSmPolicyContextProcedure(smPolicyID string) *models.ProblemDetails {
logger.SmPolicyLog.Tracef("SMPolicy[%s] DELETE Related AppSession[%s]", smPolicyID, appSessionID)
}
}

for _, ratingGroup := range ue.RatingGroupData[smPolicyID] {
pcfSelf.RatingGroupIdGenerator.FreeID(int64(ratingGroup))

filterCharging := bson.M{
"ratingGroup": ratingGroup,
}
err := mongoapi.RestfulAPIDeleteMany(chargingDataColl, filterCharging)
if err != nil {
logger.SmPolicyLog.Errorf("Fail to delete charging data, ratingGroup: %+v, err: %+v", ratingGroup, err)
}
}
delete(ue.RatingGroupData, smPolicyID)
return nil
}

Expand Down
Loading