diff --git a/config/gnbsim.yaml b/config/gnbsim.yaml index 03dea859..2a0ffa3a 100644 --- a/config/gnbsim.yaml +++ b/config/gnbsim.yaml @@ -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 diff --git a/gnbsim.go b/gnbsim.go index 2625f768..5b23f282 100644 --- a/gnbsim.go +++ b/gnbsim.go @@ -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) diff --git a/gnodeb/worker/gnbcpueworker/handler.go b/gnodeb/worker/gnbcpueworker/handler.go index 20fb6b64..2803493c 100644 --- a/gnodeb/worker/gnbcpueworker/handler.go +++ b/gnodeb/worker/gnbcpueworker/handler.go @@ -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, diff --git a/profile/context/profile.go b/profile/context/profile.go index e1e58c96..e3d49f4d 100644 --- a/profile/context/profile.go +++ b/profile/context/profile.go @@ -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 } @@ -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{} @@ -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] diff --git a/realue/nas/build.go b/realue/nas/build.go index 231ba4f2..a2462f9a 100644 --- a/realue/nas/build.go +++ b/realue/nas/build.go @@ -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 diff --git a/realue/nas/nas_security.go b/realue/nas/nas_security.go index 324befee..b6e0ecae 100644 --- a/realue/nas/nas_security.go +++ b/realue/nas/nas_security.go @@ -8,6 +8,7 @@ package nas import ( "fmt" "reflect" + "sync" realuectx "github.com/omec-project/gnbsim/realue/context" @@ -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() @@ -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") @@ -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