diff --git a/config/gnbsim.yaml b/config/gnbsim.yaml index 306907b0..95d7581c 100644 --- a/config/gnbsim.yaml +++ b/config/gnbsim.yaml @@ -10,6 +10,7 @@ info: configuration: singleInterface: false #default value + execInParallel: false #run all profiles in parallel gnbs: # pool of gNodeBs gnb1: n2IpAddr: # gNB N2 interface IP address used to connect to AMF diff --git a/factory/config.go b/factory/config.go index 32257995..a0452e64 100644 --- a/factory/config.go +++ b/factory/config.go @@ -37,6 +37,7 @@ type Configuration struct { Gnbs map[string]*gnbctx.GNodeB `yaml:"gnbs"` Profiles []*profctx.Profile `yaml:"profiles"` SingleInterface bool `yaml:"singleInterface"` + ExecInParallel bool `yaml:"execInParallel"` } type Logger struct { diff --git a/gnbsim.go b/gnbsim.go index c5201042..fd6ad5b1 100644 --- a/gnbsim.go +++ b/gnbsim.go @@ -9,12 +9,14 @@ import ( "net/http" _ "net/http/pprof" //Using package only for invoking initialization. "os" + "sync" "github.com/omec-project/gnbsim/common" "github.com/omec-project/gnbsim/factory" "github.com/omec-project/gnbsim/gnodeb" "github.com/omec-project/gnbsim/logger" "github.com/omec-project/gnbsim/profile" + profctx "github.com/omec-project/gnbsim/profile/context" "github.com/urfave/cli" ) @@ -70,35 +72,53 @@ func action(c *cli.Context) error { summaryChan := make(chan common.InterfaceMessage) result := "PASS" + var profileWaitGrp sync.WaitGroup for _, profileCtx := range config.Configuration.Profiles { if !profileCtx.Enable { continue } - logger.AppLog.Infoln("executing profile:", profileCtx.Name, - ", profile type:", profileCtx.ProfileType) - - 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") - } - - 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 len(msg.ErrorList) != 0 { - logger.AppSummaryLog.Infoln("Profile Errors:") - for _, err := range msg.ErrorList { - logger.AppSummaryLog.Errorln(err) + profileWaitGrp.Add(1) + + go func(profileCtx *profctx.Profile) { + defer profileWaitGrp.Done() + + go profile.ExecuteProfile(profileCtx, summaryChan) + + select { + // Waiting for execution summary from profile routine + case m, ok := <-summaryChan: + if !ok { + logger.AppLog.Fatalln("summary Channel closed") + break + } + msg, ok := (m).(*common.SummaryMessage) + if !ok { + logger.AppLog.Fatalln("Invalid message type") + break + } + + 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 len(msg.ErrorList) != 0 { + logger.AppSummaryLog.Infoln("Profile Errors:") + for _, err := range msg.ErrorList { + logger.AppSummaryLog.Errorln(err) + } + } } + }(profileCtx) + if config.Configuration.ExecInParallel == false { + profileWaitGrp.Wait() } } + if config.Configuration.ExecInParallel == true { + profileWaitGrp.Wait() + } logger.AppSummaryLog.Infoln("Simulation Result:", result) diff --git a/profile/context/profile.go b/profile/context/profile.go index 9f035164..39a9a2ec 100644 --- a/profile/context/profile.go +++ b/profile/context/profile.go @@ -19,7 +19,7 @@ const PER_USER_TIMEOUT uint32 = 100 //seconds type Profile struct { ProfileType string `yaml:"profileType"` Name string `yaml:"profileName"` - Enable bool `yanl:"enable"` + Enable bool `yaml:"enable"` Events map[common.EventType]common.EventType Procedures []common.ProcedureType GnbName string `yaml:"gnbName"` @@ -42,7 +42,7 @@ func (profile *Profile) Init() { profile.ReadChan = make(chan *common.ProfileMessage) profile.Log = logger.ProfileLog.WithField(logger.FieldProfile, profile.Name) - profile.Log.Traceln("profile initialized") + profile.Log.Traceln("profile initialized ", profile.Name, ", Enable ", profile.Enable) } func (p *Profile) GetNextEvent(currentEvent common.EventType) (common.EventType, error) { diff --git a/profile/profile.go b/profile/profile.go index 03b8ed5b..36eca611 100644 --- a/profile/profile.go +++ b/profile/profile.go @@ -37,6 +37,8 @@ func InitializeAllProfiles() { } func ExecuteProfile(profile *profctx.Profile, summaryChan chan common.InterfaceMessage) { + profile.Log.Infoln("executing profile:", profile.Name, + ", profile type:", profile.ProfileType) initEventMap(profile) initProcedureList(profile)