@@ -28,7 +28,7 @@ type ScenarioManager struct {
2828 reportChan chan report
2929 registrationQueue chan order
3030 gnbWg * sync.WaitGroup
31- taskExecuterWg * sync.WaitGroup
31+ taskExecutorWg * sync.WaitGroup
3232 sigStop chan os.Signal
3333 ueScenarios []UEScenario
3434 stop bool
@@ -65,12 +65,17 @@ func Start(gnbConfs []config.GNodeB, amfConfs []*config.AMF, ueScenarios []UESce
6565func initManager (ueScenarios []UEScenario , timeBetweenRegistration int , timeout int ) * ScenarioManager {
6666 log .Debug ("Init manager with timeBetweenRegistration = " , timeBetweenRegistration )
6767 s := & ScenarioManager {}
68- s .taskExecuterWg = & sync.WaitGroup {}
68+
69+ s .ues = make (map [int ]* ueTasksCtx )
70+
71+ s .taskExecutorWg = & sync.WaitGroup {}
6972 s .gnbWg = & sync.WaitGroup {}
73+
74+ s .reportChan = make (chan report , 10 )
75+
7076 s .registrationQueue = make (chan order , len (ueScenarios ))
7177 go startOrderRateController (s .registrationQueue , timeBetweenRegistration )
72- s .reportChan = make (chan report , 10 )
73- s .ues = make (map [int ]* ueTasksCtx )
78+
7479 s .sigStop = make (chan os.Signal , 1 )
7580 signal .Notify (s .sigStop , os .Interrupt )
7681 if timeout > 0 {
@@ -82,22 +87,87 @@ func initManager(ueScenarios []UEScenario, timeBetweenRegistration int, timeout
8287 return s
8388}
8489
90+ func startOrderRateController (orderChan <- chan order , timeBetweenRegistration int ) {
91+ waitTime := time .Duration (timeBetweenRegistration ) * time .Millisecond
92+ orderTicker := time .NewTicker (waitTime )
93+ var order order
94+ var open bool
95+ for {
96+ <- orderTicker .C
97+ orderTicker .Stop ()
98+ order , open = <- orderChan
99+ if open {
100+ order .workerChan <- order .task
101+ orderTicker .Reset (waitTime )
102+ } else {
103+ return
104+ }
105+ }
106+ }
107+
108+ func (s * ScenarioManager ) setupGnbs (gnbConfs []config.GNodeB , amfConfs []* config.AMF ) {
109+ s .gnbs = make (map [string ]* context.GNBContext )
110+
111+ for gnbConf := range gnbConfs {
112+ s .gnbs [gnbConfs [gnbConf ].PlmnList .GnbId ] = InitGnb (gnbConfs [gnbConf ], amfConfs , s .gnbWg )
113+ s .gnbWg .Add (1 )
114+ }
115+
116+ // Wait for gNB to be connected before registering UEs
117+ // TODO: We should wait for NGSetupResponse instead
118+ time .Sleep (2 * time .Second )
119+ }
120+
85121func (s * ScenarioManager ) setupScenarios (ueScenarios []UEScenario ) {
86122 s .stop = false
87123 s .ueScenarios = ueScenarios
88124 for ueId := 1 ; ueId <= len (ueScenarios ); ueId ++ {
89- if err := s .setupUeTaskExecuter (ueId , ueScenarios [ueId - 1 ]); err != nil {
125+ if err := s .setupUeTaskExecutor (ueId , ueScenarios [ueId - 1 ]); err != nil {
90126 log .Errorf ("scenario for UE %d could not be started: %v" , ueId , err )
91127 }
92- select {
93- case <- s .sigStop :
94- s .stop = true
95- ueId = len (ueScenarios ) + 1 // exit loop
96- default :
97- }
98128 }
99129}
100130
131+ func (s * ScenarioManager ) setupUeTaskExecutor (ueId int , ueScenario UEScenario ) error {
132+ if ueId < 1 {
133+ return errors .New ("ueId must be at least 1" )
134+ }
135+ _ , exist := s .ues [ueId ]
136+ if exist {
137+ return errors .New ("this ue already have a task executor" )
138+ }
139+ if ueScenario .Tasks == nil {
140+ return errors .New ("tasks list is nil" )
141+ }
142+ if ueScenario .Config == (config.Ue {}) {
143+ return errors .New ("config is empty" )
144+ }
145+ if s .reportChan == nil {
146+ return errors .New ("scenario manager's report channel is not set" )
147+ }
148+ if s .gnbs == nil {
149+ return errors .New ("scenario manager's gnb list is not set" )
150+ }
151+ ue := ueTasksCtx {
152+ done : false ,
153+ nextTasks : ueScenario .Tasks ,
154+ workerChan : make (chan Task , 1 ),
155+ }
156+
157+ worker := ueTaskExecutor {
158+ UeId : ueId ,
159+ UeCfg : ueScenario .Config ,
160+ TaskChan : ue .workerChan ,
161+ ReportChan : s .reportChan ,
162+ Gnbs : s .gnbs ,
163+ Wg : s .taskExecutorWg ,
164+ }
165+ worker .Run ()
166+
167+ s .ues [ueId ] = & ue
168+ return nil
169+ }
170+
101171func (s * ScenarioManager ) executeScenarios () {
102172 for ! s .stop {
103173 select {
@@ -121,28 +191,6 @@ func (s *ScenarioManager) executeScenarios() {
121191 }
122192}
123193
124- func (s * ScenarioManager ) cleanup () {
125- drainAndCloseOrderRateController (s .registrationQueue )
126-
127- go func () {
128- open := true
129- var report report
130- for open {
131- report , open = <- s .reportChan
132- log .Debug ("Got report from UE " , report .ueId , " during cleanup: " , report .reason )
133- }
134- }()
135-
136- for _ , ue := range s .ues {
137- ue .workerChan <- Task {
138- TaskType : Terminate ,
139- }
140- }
141-
142- s .taskExecuterWg .Wait ()
143- close (s .reportChan )
144- }
145-
146194func (s * ScenarioManager ) handleReport (report report ) {
147195 if ! report .success {
148196 s .ues [report .ueId ].nextTasks = []Task {}
@@ -194,75 +242,26 @@ func (s *ScenarioManager) restartUeScenario(ueId int, ueScenario UEScenario) err
194242 return nil
195243}
196244
197- func (s * ScenarioManager ) setupGnbs (gnbConfs []config.GNodeB , amfConfs []* config.AMF ) {
198- s .gnbs = make (map [string ]* context.GNBContext )
199-
200- for gnbConf := range gnbConfs {
201- s .gnbs [gnbConfs [gnbConf ].PlmnList .GnbId ] = InitGnb (gnbConfs [gnbConf ], amfConfs , s .gnbWg )
202- s .gnbWg .Add (1 )
203- }
204-
205- // Wait for gNB to be connected before registering UEs
206- // TODO: We should wait for NGSetupResponse instead
207- time .Sleep (2 * time .Second )
208- }
209-
210- func (s * ScenarioManager ) setupUeTaskExecuter (ueId int , ueScenario UEScenario ) error {
211- if ueId < 1 {
212- return errors .New ("ueId must be at least 1" )
213- }
214- _ , exist := s .ues [ueId ]
215- if exist {
216- return errors .New ("this ue already have a task executer" )
217- }
218- if ueScenario .Tasks == nil {
219- return errors .New ("tasks list is nil" )
220- }
221- if ueScenario .Config == (config.Ue {}) {
222- return errors .New ("config is empty" )
223- }
224- if s .reportChan == nil {
225- return errors .New ("scenario manager's report channel is not set" )
226- }
227- if s .gnbs == nil {
228- return errors .New ("scenario manager's gnb list is not set" )
229- }
230- ue := ueTasksCtx {
231- done : false ,
232- nextTasks : ueScenario .Tasks ,
233- workerChan : make (chan Task , 1 ),
234- }
235-
236- worker := ueTaskExecuter {
237- UeId : ueId ,
238- UeCfg : ueScenario .Config ,
239- TaskChan : ue .workerChan ,
240- ReportChan : s .reportChan ,
241- Gnbs : s .gnbs ,
242- Wg : s .taskExecuterWg ,
243- }
244- worker .Run ()
245+ func (s * ScenarioManager ) cleanup () {
246+ drainAndCloseOrderRateController (s .registrationQueue )
245247
246- s .ues [ueId ] = & ue
247- return nil
248- }
248+ go func () {
249+ open := true
250+ var report report
251+ for open {
252+ report , open = <- s .reportChan
253+ log .Debug ("Got report from UE " , report .ueId , " during cleanup: " , report .reason )
254+ }
255+ }()
249256
250- func startOrderRateController (orderChan <- chan order , timeBetweenRegistration int ) {
251- waitTime := time .Duration (timeBetweenRegistration ) * time .Millisecond
252- orderTicker := time .NewTicker (waitTime )
253- var order order
254- var open bool
255- for {
256- <- orderTicker .C
257- orderTicker .Stop ()
258- order , open = <- orderChan
259- if open {
260- order .workerChan <- order .task
261- orderTicker .Reset (waitTime )
262- } else {
263- return
257+ for _ , ue := range s .ues {
258+ ue .workerChan <- Task {
259+ TaskType : Terminate ,
264260 }
265261 }
262+
263+ s .taskExecutorWg .Wait ()
264+ close (s .reportChan )
266265}
267266
268267func drainAndCloseOrderRateController (orderChan chan order ) {
0 commit comments