Skip to content

Commit

Permalink
move out SMF's default data path
Browse files Browse the repository at this point in the history
  • Loading branch information
brianchennn committed Nov 24, 2023
1 parent fe96cf2 commit f2abe2a
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 11 deletions.
8 changes: 8 additions & 0 deletions internal/context/datapath.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,14 @@ func (dataPathPool DataPathPool) GetDefaultPath() *DataPath {
return nil
}

func (dataPathPool DataPathPool) ResetDefaultPath() error {
for _, path := range dataPathPool {
path.IsDefaultPath = false
}

return nil
}

func (dataPath *DataPath) String() string {
firstDPNode := dataPath.FirstDPNode

Expand Down
9 changes: 7 additions & 2 deletions internal/context/pcc_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,13 @@ func (r *PCCRule) AddDataPathForwardingParameters(c *SMContext,
return
}
}
r.Datapath.AddForwardingParameters(routeProf.ForwardingPolicyID,
c.Tunnel.DataPathPool.GetDefaultPath().FirstDPNode.GetUpLinkPDR().PDI.LocalFTeid.Teid)
if c.Tunnel.DataPathPool.GetDefaultPath() == nil {
logger.CtxLog.Infoln("No Default Data Path")
} else {
r.Datapath.AddForwardingParameters(routeProf.ForwardingPolicyID,
c.Tunnel.DataPathPool.GetDefaultPath().FirstDPNode.GetUpLinkPDR().PDI.LocalFTeid.Teid)
}

Check failure on line 130 in internal/context/pcc_rule.go

View workflow job for this annotation

GitHub Actions / lint (1.18)

File is not `gofumpt`-ed (gofumpt)
}

func (r *PCCRule) BuildNasQoSRule(smCtx *SMContext,
Expand Down
25 changes: 20 additions & 5 deletions internal/context/sm_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,7 @@ func (c *SMContext) AllocUeIP() error {
return nil
}

// This function create a data path to be default data path.
func (c *SMContext) SelectDefaultDataPath() error {
if c.SelectionParam == nil || c.SelectedUPF == nil {
return fmt.Errorf("SelectDefaultDataPath err: SelectionParam or SelectedUPF is nil")
Expand All @@ -646,24 +647,31 @@ func (c *SMContext) SelectDefaultDataPath() error {
c.Tunnel.DataPathPool = uePreConfigPaths.DataPathPool
c.Tunnel.PathIDGenerator = uePreConfigPaths.PathIDGenerator
defaultPath = c.Tunnel.DataPathPool.GetDefaultPath()
} else {
// UE has no pre-config path.
} else if c.Tunnel.DataPathPool.GetDefaultPath() == nil {
// UE has no pre-config path and default path
// Use default route
c.Log.Infof("Has no pre-config route")
c.Log.Infof("Has no pre-config route. Has no default path")
defaultUPPath := GetUserPlaneInformation().GetDefaultUserPlanePathByDNNAndUPF(
c.SelectionParam, c.SelectedUPF)
defaultPath = GenerateDataPath(defaultUPPath)
if defaultPath != nil {
defaultPath.IsDefaultPath = true
c.Tunnel.AddDataPath(defaultPath)
}
} else {
c.Log.Infof("Has no pre-config route. Has default path")
defaultPath = c.Tunnel.DataPathPool.GetDefaultPath()
}

if defaultPath == nil {
return fmt.Errorf("Data Path not found, Selection Parameter: %s",
return fmt.Errorf("data path not found, Selection Parameter: %s",
c.SelectionParam.String())
}
defaultPath.ActivateTunnelAndPDR(c, DefaultPrecedence)

if !defaultPath.Activated {
defaultPath.ActivateTunnelAndPDR(c, DefaultPrecedence)
}

return nil
}

Expand All @@ -689,6 +697,13 @@ func (c *SMContext) CreatePccRuleDataPath(pccRule *PCCRule,
return fmt.Errorf("fail to create data path for pcc rule[%s]", pccRule.PccRuleId)
}

// Try to use a default pcc rule as default data path
if c.Tunnel.DataPathPool.GetDefaultPath() == nil &&
pccRule.Precedence == 255 &&
pccRule.FlowInfos[0].FlowDescription == "permit out ip from any to assigned" {
createdDataPath.IsDefaultPath = true
}

createdDataPath.GBRFlow = isGBRFlow(qosData)
createdDataPath.ActivateTunnelAndPDR(c, uint32(pccRule.Precedence))
c.Tunnel.AddDataPath(createdDataPath)
Expand Down
6 changes: 6 additions & 0 deletions internal/context/sm_context_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"reflect"

"github.com/free5gc/openapi/models"
"github.com/free5gc/smf/internal/logger"
"github.com/free5gc/smf/pkg/factory"
)

Expand Down Expand Up @@ -102,6 +103,11 @@ func (c *SMContext) addPduLevelChargingRuleToFlow(pccRules map[string]*PCCRule)
}

defaultPath := c.Tunnel.DataPathPool.GetDefaultPath()
if defaultPath == nil {
logger.CtxLog.Errorln("No default data path")
return
}

for node := defaultPath.FirstDPNode; node != nil; node = node.Next() {
if node.IsAnchorUPF() {
if node.UpLinkTunnel != nil && node.UpLinkTunnel.PDR != nil {
Expand Down
10 changes: 6 additions & 4 deletions internal/sbi/producer/pdu_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@ func HandlePDUSessionSMContextCreate(isDone <-chan struct{},
&Nsmf_PDUSession.SubscriptionDenied)
}

// If PCF prepares default Pcc Rule, SMF do not need to create defaultDataPath.
if err := smContext.ApplyPccRules(smPolicyDecision); err != nil {
smContext.Log.Errorf("apply sm policy decision error: %+v", err)
}

// SelectDefaultDataPath() will create a default data path if default data path is not found.
if err := smContext.SelectDefaultDataPath(); err != nil {
smContext.SetState(smf_context.InActive)
smContext.Log.Errorf("PDUSessionSMContextCreate err: %v", err)
Expand All @@ -208,10 +214,6 @@ func HandlePDUSessionSMContextCreate(isDone <-chan struct{},
&Nsmf_PDUSession.InsufficientResourceSliceDnn)
}

if err := smContext.ApplyPccRules(smPolicyDecision); err != nil {
smContext.Log.Errorf("apply sm policy decision error: %+v", err)
}

// generate goroutine to handle PFCP and
// reply PDUSessionSMContextCreate rsp immediately
needUnlock = false
Expand Down

0 comments on commit f2abe2a

Please sign in to comment.