Skip to content
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

Added support for parallel execution of profiles #46

Merged
merged 1 commit into from
Mar 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:

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
Expand Down
1 change: 1 addition & 0 deletions factory/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
64 changes: 42 additions & 22 deletions gnbsim.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions profile/context/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions profile/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down