-
Notifications
You must be signed in to change notification settings - Fork 95
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
feat: support SDM Subscription and Unsubscription for UE Session #123
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package context | ||
|
||
import "sync" | ||
|
||
type UeData struct { | ||
PduSessionCount int // store number of PDU Sessions for each UE | ||
SdmSubscriptionId string // store SDM Subscription ID per UE | ||
} | ||
|
||
type Ues struct { | ||
ues map[string]UeData // map to store UE data with SUPI as key | ||
mu sync.Mutex // mutex for concurrent access | ||
} | ||
|
||
func InitSmfUeData() *Ues { | ||
return &Ues{ | ||
ues: make(map[string]UeData), | ||
} | ||
} | ||
|
||
// IncrementPduSessionCount increments the PDU session count for a given UE. | ||
func (u *Ues) IncrementPduSessionCount(ueId string) { | ||
u.mu.Lock() | ||
defer u.mu.Unlock() | ||
|
||
ueData := u.ues[ueId] | ||
ueData.PduSessionCount++ | ||
u.ues[ueId] = ueData | ||
} | ||
|
||
// DecrementPduSessionCount decrements the PDU session count for a given UE. | ||
func (u *Ues) DecrementPduSessionCount(ueId string) { | ||
u.mu.Lock() | ||
defer u.mu.Unlock() | ||
|
||
ueData := u.ues[ueId] | ||
if ueData.PduSessionCount > 0 { | ||
ueData.PduSessionCount-- | ||
u.ues[ueId] = ueData | ||
} | ||
} | ||
|
||
// SetSubscriptionId sets the SDM subscription ID for a given UE. | ||
func (u *Ues) SetSubscriptionId(ueId, subscriptionId string) { | ||
u.mu.Lock() | ||
defer u.mu.Unlock() | ||
|
||
ueData := u.ues[ueId] | ||
ueData.SdmSubscriptionId = subscriptionId | ||
u.ues[ueId] = ueData | ||
} | ||
|
||
// GetSubscriptionId returns the SDM subscription ID for a given UE. | ||
func (u *Ues) GetSubscriptionId(ueId string) string { | ||
u.mu.Lock() | ||
defer u.mu.Unlock() | ||
|
||
return u.ues[ueId].SdmSubscriptionId | ||
} | ||
|
||
// GetUeData returns the data for a given UE. | ||
func (u *Ues) GetUeData(ueId string) UeData { | ||
u.mu.Lock() | ||
defer u.mu.Unlock() | ||
|
||
return u.ues[ueId] | ||
} | ||
|
||
// DeleteUe deletes a UE. | ||
func (u *Ues) DeleteUe(ueId string) { | ||
u.mu.Lock() | ||
defer u.mu.Unlock() | ||
|
||
delete(u.ues, ueId) | ||
} | ||
|
||
// UeExists checks if a UE already exists. | ||
func (u *Ues) UeExists(ueId string) bool { | ||
u.mu.Lock() | ||
defer u.mu.Unlock() | ||
|
||
_, exists := u.ues[ueId] | ||
return exists | ||
} | ||
|
||
// IsLastPduSession checks if it is the last PDU session for a given UE. | ||
func (u *Ues) IsLastPduSession(ueID string) bool { | ||
u.mu.Lock() | ||
defer u.mu.Unlock() | ||
|
||
return u.ues[ueID].PduSessionCount == 1 | ||
} | ||
|
||
// GetPduSessionCount returns the number of sessions for a given UE. | ||
func (u *Ues) GetPduSessionCount(ueId string) int { | ||
u.mu.Lock() | ||
defer u.mu.Unlock() | ||
|
||
return u.ues[ueId].PduSessionCount | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,6 +121,17 @@ func (p *Processor) HandlePDUSessionSMContextCreate( | |
} | ||
} | ||
|
||
if !p.Context().Ues.UeExists(smContext.Supi) { | ||
if problemDetails, err := p.Consumer(). | ||
Subscribe(ctx, smContext, smPlmnID); problemDetails != nil { | ||
smContext.Log.Errorln("SDM Subscription Failed Problem:", problemDetails) | ||
} else if err != nil { | ||
smContext.Log.Errorln("SDM Subscription Error:", err) | ||
} | ||
} else { | ||
p.Context().Ues.IncrementPduSessionCount(smContext.Supi) | ||
} | ||
|
||
establishmentRequest := m.PDUSessionEstablishmentRequest | ||
if err := HandlePDUSessionEstablishmentRequest(smContext, establishmentRequest); err != nil { | ||
smContext.Log.Errorf("PDU Session Establishment fail by %s", err) | ||
|
@@ -325,6 +336,15 @@ func (p *Processor) HandlePDUSessionSMContextUpdate( | |
} | ||
} | ||
|
||
if smf_context.GetSelf().Ues.UeExists(smContext.Supi) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. |
||
problemDetails, clientErr := p.Consumer().UnSubscribe(smContext) | ||
if problemDetails != nil { | ||
logger.PduSessLog.Errorf("SDM UnSubscription Failed Problem[%+v]", problemDetails) | ||
} else if clientErr != nil { | ||
logger.PduSessLog.Errorf("SDM UnSubscription Error[%+v]", err) | ||
} | ||
} | ||
|
||
if smContext.UeCmRegistered { | ||
problemDetails, errUeCmDeregistration := p.Consumer().UeCmDeregistration(smContext) | ||
if problemDetails != nil { | ||
|
@@ -878,6 +898,15 @@ func (p *Processor) HandlePDUSessionSMContextRelease( | |
} | ||
} | ||
|
||
if p.Context().Ues.UeExists(smContext.Supi) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. |
||
problemDetails, err := p.Consumer().UnSubscribe(smContext) | ||
if problemDetails != nil { | ||
logger.PduSessLog.Errorf("SDM UnSubscription Failed Problem[%+v]", problemDetails) | ||
} else if err != nil { | ||
logger.PduSessLog.Errorf("SDM UnSubscription Error[%+v]", err) | ||
} | ||
} | ||
|
||
if smContext.UeCmRegistered { | ||
problemDetails, err := p.Consumer().UeCmDeregistration(smContext) | ||
if problemDetails != nil { | ||
|
@@ -969,6 +998,15 @@ func (p *Processor) HandlePDUSessionSMContextLocalRelease( | |
} | ||
} | ||
|
||
if p.Context().Ues.UeExists(smContext.Supi) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. |
||
problemDetails, err := p.Consumer().UnSubscribe(smContext) | ||
if problemDetails != nil { | ||
logger.PduSessLog.Errorf("SDM UnSubscription Failed Problem[%+v]", problemDetails) | ||
} else if err != nil { | ||
logger.PduSessLog.Errorf("SDM UnSubscription Error[%+v]", err) | ||
} | ||
} | ||
|
||
if smContext.UeCmRegistered { | ||
problemDetails, err := p.Consumer().UeCmDeregistration(smContext) | ||
if problemDetails != nil { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if the error happens after the SDM data changed?
I think use the
defer
would be better in this case: