Ai
1 Star 1 Fork 1

刘昭/smf

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
callback.go 3.55 KB
Copy Edit Raw Blame History
刘昭 authored 2022-01-25 19:32 +08:00 . 0.2.0
package producer
import (
"net/http"
smf_context "gitee.com/liu-zhao234568/smf/context"
"gitee.com/liu-zhao234568/smf/logger"
"github.com/free5gc/http_wrapper"
"github.com/free5gc/openapi/models"
)
func HandleSMPolicyUpdateNotify(smContextRef string, request models.SmPolicyNotification) *http_wrapper.Response {
logger.PduSessLog.Infoln("In HandleSMPolicyUpdateNotify")
decision := request.SmPolicyDecision
smContext := smf_context.GetSMContext(smContextRef)
if smContext == nil {
logger.PduSessLog.Errorf("SMContext[%s] not found", smContextRef)
httpResponse := http_wrapper.NewResponse(http.StatusBadRequest, nil, nil)
return httpResponse
}
smContext.SMLock.Lock()
defer smContext.SMLock.Unlock()
if smContext.SMContextState != smf_context.Active {
// Wait till the state becomes Active again
// TODO: implement waiting in concurrent architecture
logger.PduSessLog.Warnf("SMContext[%s-%02d] should be Active, but actual %s",
smContext.Supi, smContext.PDUSessionID, smContext.SMContextState.String())
}
//TODO: Response data type -
//[200 OK] UeCampingRep
//[200 OK] array(PartialSuccessReport)
//[400 Bad Request] ErrorReport
httpResponse := http_wrapper.NewResponse(http.StatusNoContent, nil, nil)
if err := ApplySmPolicyFromDecision(smContext, decision); err != nil {
logger.PduSessLog.Errorf("apply sm policy decision error: %+v", err)
// TODO: Fill the error body
httpResponse.Status = http.StatusBadRequest
}
return httpResponse
}
func handleSessionRule(smContext *smf_context.SMContext, id string, sessionRuleModel *models.SessionRule) {
if sessionRuleModel == nil {
logger.PduSessLog.Debugf("Delete SessionRule[%s]", id)
delete(smContext.SessionRules, id)
} else {
sessRule := smf_context.NewSessionRuleFromModel(sessionRuleModel)
// Session rule installation
if oldSessRule, exist := smContext.SessionRules[id]; !exist {
logger.PduSessLog.Debugf("Install SessionRule[%s]", id)
smContext.SessionRules[id] = sessRule
} else { // Session rule modification
logger.PduSessLog.Debugf("Modify SessionRule[%s]", oldSessRule.SessionRuleID)
smContext.SessionRules[id] = sessRule
}
}
}
func ApplySmPolicyFromDecision(smContext *smf_context.SMContext, decision *models.SmPolicyDecision) error {
logger.PduSessLog.Traceln("In ApplySmPolicyFromDecision")
var err error
smContext.SMContextState = smf_context.ModificationPending
selectedSessionRule := smContext.SelectedSessionRule()
if selectedSessionRule == nil { // No active session rule
// Update session rules from decision
for id, sessRuleModel := range decision.SessRules {
handleSessionRule(smContext, id, sessRuleModel)
}
for id := range smContext.SessionRules {
// Randomly choose a session rule to activate
smf_context.SetSessionRuleActivateState(smContext.SessionRules[id], true)
break
}
} else {
selectedSessionRuleID := selectedSessionRule.SessionRuleID
// Update session rules from decision
for id, sessRuleModel := range decision.SessRules {
handleSessionRule(smContext, id, sessRuleModel)
}
if _, exist := smContext.SessionRules[selectedSessionRuleID]; !exist {
// Original active session rule is deleted; choose again
for id := range smContext.SessionRules {
// Randomly choose a session rule to activate
smf_context.SetSessionRuleActivateState(smContext.SessionRules[id], true)
break
}
} else {
// Activate original active session rule
smf_context.SetSessionRuleActivateState(smContext.SessionRules[selectedSessionRuleID], true)
}
}
logger.PduSessLog.Traceln("End of ApplySmPolicyFromDecision")
return err
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/liu-zhao234568/smf.git
git@gitee.com:liu-zhao234568/smf.git
liu-zhao234568
smf
smf
v1.0.0

Search