Skip to content

Commit

Permalink
Refactoring finished, session establishment and release tested
Browse files Browse the repository at this point in the history
  • Loading branch information
Laura Henning committed May 23, 2024
1 parent c5997ed commit 4a76918
Show file tree
Hide file tree
Showing 11 changed files with 244 additions and 257 deletions.
8 changes: 4 additions & 4 deletions internal/context/datapath.go
Original file line number Diff line number Diff line change
Expand Up @@ -695,12 +695,12 @@ func (dataPath *DataPath) DeactivateTunnelAndPDR(smContext *SMContext) {
func (p *DataPath) MarkPDRsForRemoval() {
for curDPNode := p.FirstDPNode; curDPNode != nil; curDPNode = curDPNode.Next() {
if curDPNode.DownLinkTunnel != nil && curDPNode.DownLinkTunnel.PDR != nil {
curDPNode.DownLinkTunnel.PDR.SetStateAll(RULE_REMOVE)
curDPNode.DownLinkTunnel.PDR.FAR.SetStateAll(RULE_REMOVE)
curDPNode.DownLinkTunnel.PDR.SetState(RULE_REMOVE)
curDPNode.DownLinkTunnel.PDR.FAR.SetState(RULE_REMOVE)
}
if curDPNode.UpLinkTunnel != nil && curDPNode.UpLinkTunnel.PDR != nil {
curDPNode.UpLinkTunnel.PDR.SetStateAll(RULE_REMOVE)
curDPNode.UpLinkTunnel.PDR.FAR.SetStateAll(RULE_REMOVE)
curDPNode.UpLinkTunnel.PDR.SetState(RULE_REMOVE)
curDPNode.UpLinkTunnel.PDR.FAR.SetState(RULE_REMOVE)
}
}
}
Expand Down
185 changes: 91 additions & 94 deletions internal/context/pfcp_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ package context

import (
"fmt"
"sync"
"time"

"github.com/free5gc/pfcp/pfcpType"
"github.com/google/uuid"
)

const (
Expand All @@ -15,10 +13,28 @@ const (
RULE_UPDATE RuleState = 2
RULE_REMOVE RuleState = 3
RULE_QUERY RuleState = 4
RULE_SYNCED RuleState = 5 // SMF notes that UPF successfully received rule via PFCP
)

type RuleState uint8

func (rs RuleState) String() string {
switch rs {
case RULE_INITIAL:
return "RULE_INITIAL"
case RULE_CREATE:
return "RULE_CREATE"
case RULE_UPDATE:
return "RULE_UPDATE"
case RULE_REMOVE:
return "RULE_REMOVE"
case RULE_QUERY:
return "RULE_QUERY"
default:
return fmt.Sprintf("UNKNOWN_RULE_STATE(%d)", rs)
}
}

// Packet Detection Rule. Table 7.5.2.2-1
type PDR struct {
PDRID uint16
Expand All @@ -31,28 +47,35 @@ type PDR struct {
URR []*URR
QER []*QER

state sync.Map // map UPF uuid to state (rule can be applied to multiple UPFs)
state RuleState
}

func (pdr *PDR) SetState(uuid uuid.UUID, state RuleState) {
pdr.state.Store(uuid, state)
func (pdr *PDR) SetState(state RuleState) {
pdr.state = state
}

func (pdr *PDR) GetState(uuid uuid.UUID) RuleState {
state, _ := pdr.state.Load(uuid)
return state.(RuleState)
func (pdr *PDR) GetState() RuleState {
return pdr.state
}

func (pdr *PDR) SetStateAll(state RuleState) {
pdr.state.Range(func(uuid, s interface{}) bool {
pdr.state.Store(uuid, state)
return true
})
func (pdr *PDR) CheckState(expectedState RuleState) bool {
return pdr.state == expectedState
}

func (pdr *PDR) CheckState(uuid uuid.UUID, expectedState RuleState) bool {
state, _ := pdr.state.Load(uuid)
return state == expectedState
func (pdr *PDR) SetStateRecursive(state RuleState) {
pdr.state = state
if pdr.FAR != nil {
pdr.FAR.state = state
if pdr.FAR.BAR != nil {
pdr.FAR.BAR.state = state
}
}
for _, urr := range pdr.URR {
urr.state = state
}
for _, qer := range pdr.QER {
qer.state = state
}
}

const (
Expand All @@ -73,28 +96,19 @@ type URR struct {
MeasurementInformation pfcpType.MeasurementInformation
VolumeThreshold uint64
VolumeQuota uint64
state sync.Map //map[uuid.UUID]RuleState
state RuleState
}

func (urr *URR) SetState(uuid uuid.UUID, state RuleState) {
urr.state.Store(uuid, state)
//urr.state[uuid] = state
func (urr *URR) SetState(state RuleState) {
urr.state = state
}

func (urr *URR) SetStateAll(state RuleState) {
//for uuid := range urr.state {
// urr.state[uuid] = state
//}
urr.state.Range(func(uuid, s interface{}) bool {
urr.state.Store(uuid, state)
return true
})
func (urr *URR) GetState() RuleState {
return urr.state
}

func (urr *URR) CheckState(uuid uuid.UUID, expectedState RuleState) bool {
//return urr.state[uuid] == expectedState
state, _ := urr.state.Load(uuid)
return state == expectedState
func (urr *URR) CheckState(expectedState RuleState) bool {
return urr.state == expectedState
}

type UrrOpt func(urr *URR)
Expand Down Expand Up @@ -175,7 +189,7 @@ type FAR struct {
ForwardingParameters *ForwardingParameters

BAR *BAR
state sync.Map //map[uuid.UUID]RuleState
state RuleState
}

// Forwarding Parameters. 7.5.2.3-2
Expand All @@ -187,25 +201,16 @@ type ForwardingParameters struct {
SendEndMarker bool
}

func (far *FAR) SetState(uuid uuid.UUID, state RuleState) {
far.state.Store(uuid, state)
}

func (far *FAR) GetState(uuid uuid.UUID) RuleState {
state, _ := far.state.Load(uuid)
return state.(RuleState)
func (far *FAR) SetState(state RuleState) {
far.state = state
}

func (far *FAR) SetStateAll(state RuleState) {
far.state.Range(func(uuid, s interface{}) bool {
far.state.Store(uuid, state)
return true
})
func (far *FAR) GetState() RuleState {
return far.state
}

func (far *FAR) CheckState(uuid uuid.UUID, expectedState RuleState) bool {
state, _ := far.state.Load(uuid)
return state == expectedState
func (far *FAR) CheckState(expectedState RuleState) bool {
return far.state == expectedState
}

// Buffering Action Rule 7.5.2.6-1
Expand All @@ -215,33 +220,19 @@ type BAR struct {
DownlinkDataNotificationDelay pfcpType.DownlinkDataNotificationDelay
SuggestedBufferingPacketsCount pfcpType.SuggestedBufferingPacketsCount

state sync.Map //map[uuid.UUID]RuleState
}

func (bar *BAR) SetState(uuid uuid.UUID, state RuleState) {
bar.state.Store(uuid, state)
//bar.state[uuid] = state
state RuleState
}

func (bar *BAR) GetState(uuid uuid.UUID) RuleState {
//return bar.state[uuid]
state, _ := bar.state.Load(uuid)
return state.(RuleState)
func (bar *BAR) SetState(state RuleState) {
bar.state = state
}

func (bar *BAR) SetStateAll(state RuleState) {
//for uuid := range bar.state {
// bar.state[uuid] = state
//}
bar.state.Range(func(uuid, s interface{}) bool {
bar.state.Store(uuid, state)
return true
})
func (bar *BAR) GetState() RuleState {
return bar.state
}

func (bar *BAR) CheckState(uuid uuid.UUID, expectedState RuleState) bool {
state, _ := bar.state.Load(uuid)
return state == expectedState
func (bar *BAR) CheckState(expectedState RuleState) bool {
return bar.state == expectedState
}

// QoS Enhancement Rule
Expand All @@ -254,33 +245,25 @@ type QER struct {
MBR *pfcpType.MBR
GBR *pfcpType.GBR

state sync.Map //map[uuid.UUID]RuleState
state RuleState
}

func (qer *QER) SetState(uuid uuid.UUID, state RuleState) {
qer.state.Store(uuid, state)
//qer.state[uuid] = state
func (qer *QER) SetState(state RuleState) {
qer.state = state
}

func (qer *QER) SetStateAll(state RuleState) {
//for uuid := range qer.state {
// qer.state[uuid] = state
//}
qer.state.Range(func(uuid, s interface{}) bool {
qer.state.Store(uuid, state)
return true
})
func (qer *QER) GetState() RuleState {
return qer.state
}

func (qer *QER) CheckState(uuid uuid.UUID, expectedState RuleState) bool {
//return qer.state[uuid] == expectedState
state, _ := qer.state.Load(uuid)
return state == expectedState
func (qer *QER) CheckState(expectedState RuleState) bool {
return qer.state == expectedState
}

func (pdr *PDR) String() string {
prefix := " "
str := fmt.Sprintf("\nPDR %d {\n", pdr.PDRID)
str += prefix + fmt.Sprintf("State: %s\n", pdr.state)
str += prefix + fmt.Sprintf("Precedence: %d\n", pdr.Precedence)
str += prefix + fmt.Sprintf("%s\n", pdr.PDI.String(prefix))
str += prefix + fmt.Sprintf("OuterHeaderRemoval: %+v\n", pdr.OuterHeaderRemoval)
Expand All @@ -295,23 +278,28 @@ func (pdr *PDR) String() string {
str += prefix + fmt.Sprintf("%s\n", qer.String(prefix))
}
}
//str += prefix + fmt.Sprintf("State: %d\n", pdr.State)
str += "}\n"
return str
}

func (urr *URR) String(prefix string) string {
if urr == nil {
return prefix + "URR: nil"
}
str := fmt.Sprintf("URR %d {\n", urr.URRID)
prefix += " "
str += prefix + fmt.Sprintf("State: %s\n", urr.state)
str += prefix + fmt.Sprintf("MeasureMethod: %s\n", urr.MeasureMethod)
str += prefix + fmt.Sprintf("VolumeThreshold: %d\n", urr.VolumeThreshold)
//str += prefix + fmt.Sprintf("State: %d\n", urr.State)
prefix = prefix[:len(prefix)-2]
str += prefix + "}\n"
return str
}

func (pdi *PDI) String(prefix string) string {
if pdi == nil {
return prefix + "PDI: nil"
}
str := "PDI {\n"
prefix += " "
str += prefix + fmt.Sprintf("SourceInterface: %d\n", pdi.SourceInterface.InterfaceValue)
Expand Down Expand Up @@ -344,21 +332,24 @@ func FTEIDToString(fteid *pfcpType.FTEID, prefix string) string {
}

func (far *FAR) String(prefix string) string {
str := fmt.Sprintf("FAR %d {\n", far.FARID)
if far == nil {
return prefix + "FAR: nil"
}
str := prefix + fmt.Sprintf("FAR %d {\n", far.FARID)
prefix += " "
str += prefix + fmt.Sprintf("State: %s\n", far.state)
str += prefix + fmt.Sprintf("ApplyAction: %+v\n", far.ApplyAction)
str += prefix + fmt.Sprintf("%s\n", far.ForwardingParameters.String(prefix))
if far.BAR != nil {
str += prefix + fmt.Sprintf("%s\n", far.BAR.String(prefix))
}
//str += prefix + fmt.Sprintf("State: %d\n", far.State)
prefix = prefix[:len(prefix)-2]
str += prefix + "}"
return str
}

func OhcToString(ohc *pfcpType.OuterHeaderCreation, prefix string) string {
str := "OuterHeaderCreation {\n"
str := prefix + "OuterHeaderCreation {\n"
prefix += " "
str += prefix + fmt.Sprintf("OuterHeaderCreationDescription: %d\n", ohc.OuterHeaderCreationDescription)
str += prefix + fmt.Sprintf("Teid: %d\n", ohc.Teid)
Expand All @@ -372,9 +363,9 @@ func OhcToString(ohc *pfcpType.OuterHeaderCreation, prefix string) string {

func (fp *ForwardingParameters) String(prefix string) string {
if fp == nil {
return "ForwardingParameters: nil\n"
return prefix + "ForwardingParameters: nil"
}
str := "ForwardingParameters {\n"
str := prefix + "ForwardingParameters {\n"
prefix += " "
str += prefix + fmt.Sprintf("DestinationInterface: %+v\n", fp.DestinationInterface)
str += prefix + fmt.Sprintf("NetworkInstance: %+v\n", fp.NetworkInstance)
Expand All @@ -387,19 +378,26 @@ func (fp *ForwardingParameters) String(prefix string) string {
}

func (bar *BAR) String(prefix string) string {
if bar == nil {
return prefix + "BAR: nil"
}
str := fmt.Sprintf("BAR %d {\n", bar.BARID)
prefix += " "
str += prefix + fmt.Sprintf("State: %s\n", bar.state)
str += prefix + fmt.Sprintf("DownlinkDataNotificationDelay: %+v\n", bar.DownlinkDataNotificationDelay)
str += prefix + fmt.Sprintf("SuggestedBufferingPacketsCount: %+v\n", bar.SuggestedBufferingPacketsCount)
//str += prefix + fmt.Sprintf("State: %d\n", bar.State)
prefix = prefix[:len(prefix)-2]
str += prefix + "}"
return str
}

func (qer *QER) String(prefix string) string {
if qer == nil {
return prefix + "QER: nil"
}
str := fmt.Sprintf("QER %d {\n", qer.QERID)
prefix += " "
str += prefix + fmt.Sprintf("State: %s\n", qer.state)
str += prefix + fmt.Sprintf("QFI: %+v\n", qer.QFI)
if qer.GateStatus != nil {
str += prefix + fmt.Sprintf("GateStatus: DLGate %d, ULGate %d\n", qer.GateStatus.DLGate, qer.GateStatus.ULGate)
Expand All @@ -410,7 +408,6 @@ func (qer *QER) String(prefix string) string {
if qer.GBR != nil {
str += prefix + fmt.Sprintf("GBR: DLGBR %d ULGBR %d\n", qer.GBR.DLGBR, qer.GBR.DLGBR)
}
//str += prefix + fmt.Sprintf("State: %d\n", qer.State)
prefix = prefix[:len(prefix)-2]
str += prefix + "}"
return str
Expand Down
Loading

0 comments on commit 4a76918

Please sign in to comment.