forked from omec-project/gnbsim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgnbsim.go
162 lines (134 loc) · 3.85 KB
/
gnbsim.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
// SPDX-FileCopyrightText: 2022 Great Software Laboratory Pvt. Ltd
// SPDX-FileCopyrightText: 2021 Open Networking Foundation <info@opennetworking.org>
// Copyright 2019 free5GC.org
//
// SPDX-License-Identifier: Apache-2.0
package main
import (
"net/http"
_ "net/http/pprof" //Using package only for invoking initialization.
"os"
"os/signal"
"sync"
"syscall"
"time"
"github.com/omec-project/gnbsim/common"
"github.com/omec-project/gnbsim/factory"
"github.com/omec-project/gnbsim/gnodeb"
"github.com/omec-project/gnbsim/httpserver"
"github.com/omec-project/gnbsim/logger"
prof "github.com/omec-project/gnbsim/profile"
profctx "github.com/omec-project/gnbsim/profile/context"
"github.com/urfave/cli"
)
func main() {
app := cli.NewApp()
app.Name = "GNBSIM"
app.Usage = "./gnbsim --cfg [gnbsim configuration file]"
app.Action = action
app.Flags = getCliFlags()
logger.AppLog.Infoln("App Name:", app.Name)
if err := app.Run(os.Args); err != nil {
logger.AppLog.Errorln("Failed to run GNBSIM:", err)
return
}
}
func action(c *cli.Context) error {
cfg := c.String("cfg")
if cfg == "" {
logger.AppLog.Warnln("No configuration file provided. Using default configuration file:", factory.GNBSIM_DEFAULT_CONFIG_PATH)
logger.AppLog.Infoln("Application Usage:", c.App.Usage)
cfg = factory.GNBSIM_DEFAULT_CONFIG_PATH
}
if err := factory.InitConfigFactory(cfg); err != nil {
logger.AppLog.Errorln("Failed to initialize config factory:", err)
return err
}
//Initiating a server for profiling
go func() {
err := http.ListenAndServe(":5000", nil)
if err != nil {
logger.AppLog.Errorln("Failed to start profiling server")
}
}()
config := factory.AppConfig
lvl := config.Logger.LogLevel
logger.AppLog.Infoln("Setting log level to:", lvl)
logger.SetLogLevel(lvl)
prof.InitializeAllProfiles()
err := gnodeb.InitializeAllGnbs()
if err != nil {
logger.AppLog.Errorln("Failed to initialize gNodeBs:", err)
return err
}
go ListenAndLogSummary()
var appWaitGrp sync.WaitGroup
if config.Configuration.Server.Enable {
appWaitGrp.Add(1)
go func() {
defer appWaitGrp.Done()
err := httpserver.StartHttpServer()
if err != nil {
logger.AppLog.Infoln("StartHttpServer returned :", err)
}
}()
signalChannel := make(chan os.Signal, 1)
signal.Notify(signalChannel, os.Interrupt, syscall.SIGTERM)
go func() {
<-signalChannel
httpserver.StopHttpServer()
}()
}
var profileWaitGrp sync.WaitGroup
for _, profile := range config.Configuration.Profiles {
if !profile.Enable {
continue
}
profileWaitGrp.Add(1)
go func(profileCtx *profctx.Profile) {
defer profileWaitGrp.Done()
prof.ExecuteProfile(profileCtx, profctx.SummaryChan)
}(profile)
if config.Configuration.ExecInParallel == false {
profileWaitGrp.Wait()
}
}
if config.Configuration.ExecInParallel == true {
profileWaitGrp.Wait()
}
appWaitGrp.Wait()
// TODO: To be removed. Allowing summary logger to dump the logs
time.Sleep(time.Second * 5)
return nil
}
func getCliFlags() []cli.Flag {
return []cli.Flag{
cli.StringFlag{
Name: "cfg",
Usage: "GNBSIM config file",
},
}
}
func ListenAndLogSummary() {
for intfcMsg := range profctx.SummaryChan {
if intfcMsg.GetEventType() == common.QUIT_EVENT {
return
}
result := "PASS"
// Waiting for execution summary from profile routine
msg, ok := intfcMsg.(*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 len(msg.ErrorList) != 0 {
result = "FAIL"
logger.AppSummaryLog.Infoln("Profile Errors:")
for _, err := range msg.ErrorList {
logger.AppSummaryLog.Errorln(err)
}
}
logger.AppSummaryLog.Infoln("Profile Status:", result)
}
}