Skip to content

Commit

Permalink
NW trigger UE dereg support
Browse files Browse the repository at this point in the history
  • Loading branch information
thakurajayL committed Mar 9, 2022
1 parent d16fdb5 commit 0afaf53
Show file tree
Hide file tree
Showing 11 changed files with 183 additions and 66 deletions.
16 changes: 9 additions & 7 deletions common/procedures.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,23 @@ const (
UE_INITIATED_DEREGISTRATION_PROCEDURE
AN_RELEASE_PROCEDURE
UE_TRIGGERED_SERVICE_REQUEST_PROCEDURE
NW_TRIGGERED_UE_DEREGISTRATION_PROCEDURE
)

var procStrMap = map[ProcedureType]string{
REGISTRATION_PROCEDURE: "REGISTRATION-PROCEDURE",
PDU_SESSION_ESTABLISHMENT_PROCEDURE: "PDU-SESSION-ESTABLISHMENT-PROCEDURE",
USER_DATA_PKT_GENERATION_PROCEDURE: "USER-DATA-PACKET-GENERATION-PROCEDURE",
UE_INITIATED_DEREGISTRATION_PROCEDURE: "UE-INITIATED-DEREGISTRATION-PROCEDURE",
AN_RELEASE_PROCEDURE: "AN-RELEASE-PROCEDURE",
UE_TRIGGERED_SERVICE_REQUEST_PROCEDURE: "UE-TRIGGERED-SERVICE-REQUEST-PROCEDURE",
REGISTRATION_PROCEDURE: "REGISTRATION-PROCEDURE",
PDU_SESSION_ESTABLISHMENT_PROCEDURE: "PDU-SESSION-ESTABLISHMENT-PROCEDURE",
USER_DATA_PKT_GENERATION_PROCEDURE: "USER-DATA-PACKET-GENERATION-PROCEDURE",
UE_INITIATED_DEREGISTRATION_PROCEDURE: "UE-INITIATED-DEREGISTRATION-PROCEDURE",
AN_RELEASE_PROCEDURE: "AN-RELEASE-PROCEDURE",
UE_TRIGGERED_SERVICE_REQUEST_PROCEDURE: "UE-TRIGGERED-SERVICE-REQUEST-PROCEDURE",
NW_TRIGGERED_UE_DEREGISTRATION_PROCEDURE: "NW-TRIGGERED-UE-DEREGISTRATION-PROCEDURE",
}

func (id ProcedureType) String() string {
procStr, ok := procStrMap[id]
if !ok {
logger.AppLog.Fatalln("Invaid Procedure ID:", id)
logger.AppLog.Fatalln("Invalid Procedure ID:", id)
}
return procStr
}
12 changes: 11 additions & 1 deletion config/gnbsim.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ configuration:
mnc: 93 # Mobile Network Code (2 or 3 digits string, digit: 0~9)
- profileType: pdusessest # profile type
profileName: profile2 # uniqely identifies a profile within application
enable: true # Set true to execute the profile, false otherwise.
enable: false # Set true to execute the profile, false otherwise.
gnbName: gnb1 # gNB to be used for this profile
startImsi: 208930100007492 # First IMSI. Subsequent values will be used if ueCount is more than 1
ueCount: 5 # Number of UEs for for which the profile will be executed
Expand Down Expand Up @@ -83,6 +83,16 @@ configuration:
plmnId: # Public Land Mobile Network ID, <PLMN ID> = <MCC><MNC>. Should match startImsi
mcc: 208 # Mobile Country Code (3 digits string, digit: 0~9)
mnc: 93 # Mobile Network Code (2 or 3 digits string, digit: 0~9)
- profileType: nwtriggeruedereg # profile type
profileName: profile6 # uniqely identifies a profile within application
enable: false # Set true to execute the profile, false otherwise.
gnbName: gnb1 # gNB to be used for this profile
startImsi: 208930100007497 # First IMSI. Subsequent values will be used if ueCount is more than 1
ueCount: 1 # Number of UEs for for which the profile will be executed
perUserTimeout: 10 #if no expected event received in this time then treat it as failure
plmnId: # Public Land Mobile Network ID, <PLMN ID> = <MCC><MNC>. Should match startImsi
mcc: 208 # Mobile Country Code (3 digits string, digit: 0~9)
mnc: 93 # Mobile Network Code (2 or 3 digits string, digit: 0~9)

logger:
logLevel: info # how detailed the log will be, values: trace, debug, info, warn, error, fatal, panic
39 changes: 20 additions & 19 deletions gnbsim.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,30 +71,31 @@ func action(c *cli.Context) error {
result := "PASS"

for _, profileCtx := range config.Configuration.Profiles {
if profileCtx.Enable {
logger.AppLog.Infoln("executing profile:", profileCtx.Name,
", profile type:", profileCtx.ProfileType)
if !profileCtx.Enable {
continue
}
logger.AppLog.Infoln("executing profile:", profileCtx.Name,
", profile type:", profileCtx.ProfileType)

go profile.ExecuteProfile(profileCtx, summaryChan)
go profile.ExecuteProfile(profileCtx, summaryChan)

// Waiting for execution summary from profile routine
msg, ok := (<-summaryChan).(*common.SummaryMessage)
if !ok {
logger.AppLog.Fatalln("Invalid Message Type")
}
// Waiting for execution summary from profile routine
msg, ok := (<-summaryChan).(*common.SummaryMessage)
if !ok {
logger.AppLog.Fatalln("Invalid Message Type")
}

logger.AppSummaryLog.Infoln("Profile Name:", msg.ProfileName, ", Profile Type:", msg.ProfileType)
logger.AppSummaryLog.Infoln("Ue's Passed:", msg.UePassedCount, ", Ue's Failed:", msg.UeFailedCount)
logger.AppSummaryLog.Infoln("Profile Name:", msg.ProfileName, ", Profile Type:", msg.ProfileType)
logger.AppSummaryLog.Infoln("Ue's Passed:", msg.UePassedCount, ", Ue's Failed:", msg.UeFailedCount)

if msg.UeFailedCount != 0 {
result = "FAIL"
}
if msg.UeFailedCount != 0 {
result = "FAIL"
}

if len(msg.ErrorList) != 0 {
logger.AppSummaryLog.Infoln("Profile Errors:")
for _, err := range msg.ErrorList {
logger.AppSummaryLog.Errorln(err)
}
if len(msg.ErrorList) != 0 {
logger.AppSummaryLog.Infoln("Profile Errors:")
for _, err := range msg.ErrorList {
logger.AppSummaryLog.Errorln(err)
}
}
}
Expand Down
1 change: 1 addition & 0 deletions gnodeb/idrange/idrange.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const (
MAX_RANGE_BITS uint8 = 8
)

// TODO : add UT
func GetIdRange() (start, end uint32) {
maxRangeSelectVal := (1 << MAX_RANGE_BITS) - 1
idBitCount := MAX_ID_BITS - MAX_RANGE_BITS
Expand Down
24 changes: 13 additions & 11 deletions profile/context/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,20 @@ import (
"github.com/sirupsen/logrus"
)

const PER_USER_TIMEOUT uint32 = 100 //seconds

type Profile struct {
ProfileType string `yaml:"profileType"`
Name string `yaml:"profileName"`
Enable bool `yanl:"enable"`
Events map[common.EventType]common.EventType
Procedures []common.ProcedureType
GnbName string `yaml:"gnbName"`
StartImsi string `yaml:"startImsi"`
UeCount int `yaml:"ueCount"`
Plmn *models.PlmnId `yaml:"plmnId"`
DataPktCount int `yaml:"dataPktCount"`
ProfileType string `yaml:"profileType"`
Name string `yaml:"profileName"`
Enable bool `yanl:"enable"`
Events map[common.EventType]common.EventType
Procedures []common.ProcedureType
GnbName string `yaml:"gnbName"`
StartImsi string `yaml:"startImsi"`
UeCount int `yaml:"ueCount"`
Plmn *models.PlmnId `yaml:"plmnId"`
DataPktCount int `yaml:"dataPktCount"`
PerUserTimeout uint32 `yaml:"perUserTimeout"`

// Profile routine reads messages from other entities on this channel
// Entities can be SimUe, Main routine.
Expand Down Expand Up @@ -80,7 +83,6 @@ func (p *Profile) GetNextProcedure(currentProcedure common.ProcedureType) common
nextProcedure = p.Procedures[i+1]
break
}

p.Log.Infoln("No more procedures left")
}
}
Expand Down
76 changes: 58 additions & 18 deletions profile/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@ package profile

import (
"fmt"
"strconv"
"sync"
"time"

"github.com/omec-project/gnbsim/common"
"github.com/omec-project/gnbsim/factory"
profctx "github.com/omec-project/gnbsim/profile/context"
"github.com/omec-project/gnbsim/profile/util"
"github.com/omec-project/gnbsim/simue"
simuectx "github.com/omec-project/gnbsim/simue/context"
"strconv"
"sync"
"time"
)

//profile names
const (
REGISTER string = "register"
PDU_SESS_EST string = "pdusessest"
DEREGISTER string = "deregister"
AN_RELEASE string = "anrelease"
UE_TRIGG_SERVICE_REQ string = "uetriggservicereq"
REGISTER string = "register"
PDU_SESS_EST string = "pdusessest"
DEREGISTER string = "deregister"
AN_RELEASE string = "anrelease"
UE_TRIGG_SERVICE_REQ string = "uetriggservicereq"
NW_TRIGG_UE_DEREG_REQ string = "nwtriggeruedereg"
)

func InitializeAllProfiles() {
Expand All @@ -37,6 +37,9 @@ func ExecuteProfile(profile *profctx.Profile, summaryChan chan common.InterfaceM
initEventMap(profile)
initProcedureList(profile)

if profile.PerUserTimeout == 0 {
profile.PerUserTimeout = profctx.PER_USER_TIMEOUT
}
gnb, err := factory.AppConfig.Configuration.GetGNodeB(profile.GnbName)
if err != nil {
profile.Log.Errorln("GetGNodeB returned:", err)
Expand All @@ -55,23 +58,40 @@ func ExecuteProfile(profile *profctx.Profile, summaryChan chan common.InterfaceM

// Currently executing profile for one IMSI at a time
for count := 1; count <= profile.UeCount; count++ {
simUe := simuectx.NewSimUe("imsi-"+strconv.Itoa(imsi), gnb, profile)
imsiStr := "imsi-" + strconv.Itoa(imsi)
simUe := simuectx.NewSimUe(imsiStr, gnb, profile)

wg.Add(1)
go simue.Init(simUe, &wg)
go func() {
defer wg.Done()
simue.Init(simUe)
}()
util.SendToSimUe(simUe, common.PROFILE_START_EVENT)

msg := <-profile.ReadChan
switch msg.Event {
case common.PROFILE_PASS_EVENT:
profile.Log.Infoln("Result: PASS, imsi:", msg.Supi)
summary.UePassedCount++
case common.PROFILE_FAIL_EVENT:
err := fmt.Errorf("imsi:%v, procedure:%v, error:%v", msg.Supi, msg.Proc, msg.Error)
timeout := time.Duration(profile.PerUserTimeout) * time.Second
ticker := time.NewTicker(timeout)

select {
case <-ticker.C:
err := fmt.Errorf("imsi:%v, profile timeout", imsiStr)
profile.Log.Infoln("Result: FAIL,", err)
summary.UeFailedCount++
summary.ErrorList = append(summary.ErrorList, err)
util.SendToSimUe(simUe, common.QUIT_EVENT)

case msg := <-profile.ReadChan:
switch msg.Event {
case common.PROFILE_PASS_EVENT:
profile.Log.Infoln("Result: PASS, imsi:", msg.Supi)
summary.UePassedCount++
case common.PROFILE_FAIL_EVENT:
err := fmt.Errorf("imsi:%v, procedure:%v, error:%v", msg.Supi, msg.Proc, msg.Error)
profile.Log.Infoln("Result: FAIL,", err)
summary.UeFailedCount++
summary.ErrorList = append(summary.ErrorList, err)
}
}
ticker.Stop()
time.Sleep(2 * time.Second)
imsi++
}
Expand Down Expand Up @@ -134,6 +154,19 @@ func initEventMap(profile *profctx.Profile) {
common.TRIGGER_AN_RELEASE_EVENT: common.CONNECTION_RELEASE_REQUEST_EVENT,
common.PROFILE_PASS_EVENT: common.QUIT_EVENT,
}
case NW_TRIGG_UE_DEREG_REQ:
profile.Events = map[common.EventType]common.EventType{
common.REG_REQUEST_EVENT: common.AUTH_REQUEST_EVENT,
common.AUTH_REQUEST_EVENT: common.AUTH_RESPONSE_EVENT,
common.SEC_MOD_COMMAND_EVENT: common.SEC_MOD_COMPLETE_EVENT,
common.REG_ACCEPT_EVENT: common.REG_COMPLETE_EVENT,
common.PDU_SESS_EST_REQUEST_EVENT: common.PDU_SESS_EST_ACCEPT_EVENT,
common.PDU_SESS_EST_ACCEPT_EVENT: common.PDU_SESS_EST_ACCEPT_EVENT,
common.DEREG_REQUEST_UE_TERM_EVENT: common.DEREG_ACCEPT_UE_TERM_EVENT,
common.DEREG_ACCEPT_UE_TERM_EVENT: common.DEREG_ACCEPT_UE_TERM_EVENT,
common.PROFILE_PASS_EVENT: common.QUIT_EVENT,
}

}
}

Expand Down Expand Up @@ -169,5 +202,12 @@ func initProcedureList(profile *profctx.Profile) {
common.AN_RELEASE_PROCEDURE,
common.UE_TRIGGERED_SERVICE_REQUEST_PROCEDURE,
}
case NW_TRIGG_UE_DEREG_REQ:
profile.Procedures = []common.ProcedureType{
common.REGISTRATION_PROCEDURE,
common.PDU_SESSION_ESTABLISHMENT_PROCEDURE,
common.USER_DATA_PKT_GENERATION_PROCEDURE,
common.NW_TRIGGERED_UE_DEREGISTRATION_PROCEDURE,
}
}
}
18 changes: 18 additions & 0 deletions realue/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,3 +372,21 @@ func HandleServiceRequestEvent(ue *realuectx.RealUe,
SendToSimUe(ue, m)
return nil
}

func HandleDeregAcceptEvent(ue *realuectx.RealUe, msg common.InterfaceMessage) (err error) {
ue.Log.Traceln("Generating Dereg Accept Message")
nasPdu := nasTestpacket.GetDeregistrationAccept()

nasPdu, err = realue_nas.EncodeNasPduWithSecurity(ue, nasPdu,
nas.SecurityHeaderTypeIntegrityProtectedAndCipheredWithNew5gNasSecurityContext,
true)
if err != nil {
ue.Log.Errorln("EncodeNasPduWithSecurity() returned:", err)
return fmt.Errorf("failed to encrypt security mode complete message")
}

m := formUuMessage(common.DEREG_ACCEPT_UE_TERM_EVENT, nasPdu)
SendToSimUe(ue, m)
ue.Log.Traceln("Sent Dereg Accept UE Terminated Message to SimUe")
return nil
}
7 changes: 3 additions & 4 deletions realue/realue.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,20 @@
package realue

import (
"sync"

"github.com/omec-project/gnbsim/common"
realuectx "github.com/omec-project/gnbsim/realue/context"
"github.com/omec-project/gnbsim/util/test"

"github.com/free5gc/CommonConsumerTestData/UDM/TestGenAuthData"
)

func Init(ue *realuectx.RealUe, wg *sync.WaitGroup) {
func Init(ue *realuectx.RealUe) {

ue.AuthenticationSubs = test.GetAuthSubscription(TestGenAuthData.MilenageTestSet19.K,
TestGenAuthData.MilenageTestSet19.OPC,
"")

HandleEvents(ue)
wg.Done()
}

func HandleEvents(ue *realuectx.RealUe) (err error) {
Expand Down Expand Up @@ -57,6 +54,8 @@ func HandleEvents(ue *realuectx.RealUe) (err error) {
err = HandleServiceRequestEvent(ue, msg)
case common.CONNECTION_RELEASE_REQUEST_EVENT:
err = HandleConnectionReleaseRequestEvent(ue, msg)
case common.DEREG_ACCEPT_UE_TERM_EVENT:
err = HandleDeregAcceptEvent(ue, msg)
case common.ERROR_EVENT:
HandleErrorEvent(ue, msg)
case common.QUIT_EVENT:
Expand Down
2 changes: 1 addition & 1 deletion simue/context/simue.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ func NewSimUe(supi string, gnb *gnbctx.GNodeB, profile *profctx.Profile) *SimUe

simue.Log = logger.SimUeLog.WithField(logger.FieldSupi, supi)

simue.Log.Traceln("Created new context")
simue.Log.Traceln("Created new SimUe context")
return &simue
}

0 comments on commit 0afaf53

Please sign in to comment.