Skip to content

Commit

Permalink
Adding code to get lock before NAS Mac calculation (#92)
Browse files Browse the repository at this point in the history
* Update gnbsim document

* Adding mutex for NAS encode/decode

* Provide ms option and send initial UE or uplinkMsg

* Fixing go sum errors, Fixing spell check

* Update dockerfile. Fixing lint errors

Separate lock for encode & decode NAS message
  • Loading branch information
thakurajayL authored Dec 7, 2023
1 parent 3c577f5 commit 35f72e5
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 15 deletions.
1 change: 1 addition & 0 deletions config/gnbsim.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ info:
description: GNBSIM initial local configuration

configuration:
runConfigProfilesAtStart: true
singleInterface: false #default value
execInParallel: false #run all profiles in parallel
httpServer: # Serves APIs to create/control profiles on the go
Expand Down
1 change: 1 addition & 0 deletions gnbsim.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ func action(c *cli.Context) error {
// Keep running gnbsim as long as profiles are not finished
for _, profile := range config.Configuration.Profiles {
if !profile.Enable {
logger.AppLog.Errorln("disabled profileType ", profile.ProfileType)
continue
}
profileWaitGrp.Add(1)
Expand Down
35 changes: 24 additions & 11 deletions gnodeb/worker/gnbcpueworker/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,31 @@ func HandleInitialUEMessage(gnbue *gnbctx.GnbCpUe,
intfcMsg common.InterfaceMessage) {

msg := intfcMsg.(*common.UuMessage)
sendMsg, err := test.GetInitialUEMessage(gnbue.GnbUeNgapId, msg.NasPdus[0], "")
if err != nil {
gnbue.Log.Errorln("GetInitialUEMessage failed:", err)
return
}
err = gnbue.Gnb.CpTransport.SendToPeer(gnbue.Amf, sendMsg)
if err != nil {
gnbue.Log.Errorln("SendToPeer failed:", err)
return
if gnbue.AmfUeNgapId != 0 {
sendMsg, err := test.GetUplinkNASTransport(gnbue.AmfUeNgapId, gnbue.GnbUeNgapId, msg.NasPdus[0])
if err != nil {
gnbue.Log.Errorln("GetUplinkNASMessage failed:", err)
return
}
err = gnbue.Gnb.CpTransport.SendToPeer(gnbue.Amf, sendMsg)
if err != nil {
gnbue.Log.Errorln("SendToPeer failed:", err)
return
}
gnbue.Log.Traceln("Sent Uplink NAS Message to AMF")
} else {
sendMsg, err := test.GetInitialUEMessage(gnbue.GnbUeNgapId, msg.NasPdus[0], "")
if err != nil {
gnbue.Log.Errorln("GetInitialUEMessage failed:", err)
return
}
err = gnbue.Gnb.CpTransport.SendToPeer(gnbue.Amf, sendMsg)
if err != nil {
gnbue.Log.Errorln("SendToPeer failed:", err)
return
}
gnbue.Log.Traceln("Sent Initial UE Message to AMF")
}

gnbue.Log.Traceln("Sent Initial UE Message to AMF")
}

func HandleDownlinkNasTransport(gnbue *gnbctx.GnbCpUe,
Expand Down
6 changes: 3 additions & 3 deletions profile/context/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (profile *Profile) Init() {
func SendStepEventProfile(name string) error {
profile, found := ProfileMap[name]
if found == false {
err := fmt.Errorf("unknown profile:%v", profile)
err := fmt.Errorf("unknown profile:%s", name)
log.Println(err)
return err
}
Expand All @@ -144,7 +144,7 @@ func SendStepEventProfile(name string) error {
func SendAddNewCallsEventProfile(name string, number int32) error {
profile, found := ProfileMap[name]
if found == false {
err := fmt.Errorf("unknown profile:%v", profile)
err := fmt.Errorf("unknown profile:%s", name)
return err
}
msg := &common.ProfileMessage{}
Expand Down Expand Up @@ -237,7 +237,7 @@ func (p *Profile) GetNextProcedure(pCtx *ProfileUeContext, currentProcedure comm
itp, _ := p.PIterations[pCtx.CurrentItr]
pCtx.Log.Infoln("Current Iteration map - ", itp)
if itp.WaitMap[pCtx.CurrentProcIndex] != 0 {
time.Sleep(time.Second * time.Duration(itp.WaitMap[pCtx.CurrentProcIndex]))
time.Sleep(time.Millisecond * time.Duration(itp.WaitMap[pCtx.CurrentProcIndex]))
}
nextProcIndex := pCtx.CurrentProcIndex + 1
nextProcedure, found := itp.ProcMap[nextProcIndex]
Expand Down
2 changes: 1 addition & 1 deletion realue/nas/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func GetServiceRequest(ue *realuectx.RealUe) ([]byte, error) {
data := new(bytes.Buffer)
err := nasMsg.GmmMessageEncode(data)
if err != nil {
return nil, fmt.Errorf("encode failed: %v\n", err)
return nil, fmt.Errorf("encode failed:+%v", err)
}

return data.Bytes(), nil
Expand Down
9 changes: 9 additions & 0 deletions realue/nas/nas_security.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package nas
import (
"fmt"
"reflect"
"sync"

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

Expand All @@ -17,6 +18,9 @@ import (
"github.com/omec-project/ngap/ngapType"
)

var decodeMutex sync.Mutex
var encodeMutex sync.Mutex

func EncodeNasPduWithSecurity(ue *realuectx.RealUe, pdu []byte, securityHeaderType uint8,
securityContextAvailable bool) ([]byte, error) {
m := nas.NewMessage()
Expand Down Expand Up @@ -68,6 +72,8 @@ func GetNasPduSetupRequest(ue *realuectx.RealUe, msg *ngapType.PDUSessionResourc

func NASEncode(ue *realuectx.RealUe, msg *nas.Message, securityContextAvailable bool) (
payload []byte, err error) {
encodeMutex.Lock()
defer encodeMutex.Unlock()

if ue == nil {
err = fmt.Errorf("amfUe is nil")
Expand Down Expand Up @@ -137,6 +143,9 @@ func NASEncode(ue *realuectx.RealUe, msg *nas.Message, securityContextAvailable
}

func NASDecode(ue *realuectx.RealUe, securityHeaderType uint8, payload []byte) (msg *nas.Message, err error) {
decodeMutex.Lock()
defer decodeMutex.Unlock()

if ue == nil {
err = fmt.Errorf("amfUe is nil")
return
Expand Down

0 comments on commit 35f72e5

Please sign in to comment.