blob: 3b81eacb61b494e8854940268e4f2fd5056f95c8 [file] [log] [blame]
Girish Gowdra64503432020-01-07 10:59:10 +05301/*
2 * Copyright 2018-present Open Networking Foundation
3
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7
8 * http://www.apache.org/licenses/LICENSE-2.0
9
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17//Package main invokes the application
18package main
19
20import (
21 "fmt"
Girish Gowdra64503432020-01-07 10:59:10 +053022 "os"
23 "os/signal"
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +030024 "strconv"
Girish Gowdra64503432020-01-07 10:59:10 +053025 "syscall"
26 "time"
27
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +030028 "github.com/opencord/openolt-scale-tester/core"
29
Girish Gowdra64503432020-01-07 10:59:10 +053030 "github.com/opencord/openolt-scale-tester/config"
Girish Gowdra390f12f2021-07-01 15:53:49 -070031 "github.com/opencord/voltha-lib-go/v7/pkg/log"
Girish Gowdra64503432020-01-07 10:59:10 +053032)
33
Girish Gowdra5d7d6442020-09-08 17:03:11 -070034var logger log.CLogger
35
Girish Gowdra64503432020-01-07 10:59:10 +053036func init() {
Girish Gowdra5d7d6442020-09-08 17:03:11 -070037 // Setup this package so that it's log level can be modified at run time
38 var err error
39 logger, err = log.RegisterPackage(log.JSON, log.DebugLevel, log.Fields{})
40 if err != nil {
41 panic(err)
42 }
Girish Gowdra64503432020-01-07 10:59:10 +053043}
44
45const (
46 // DefaultLivelinessCheck to check the liveliness
47 DefaultLivelinessCheck = 30 * time.Second
48 // DefaultTimeout to close the connection
49 DefaultTimeout = 10
50)
51
52type OpenOltScaleTester struct {
53 openOltManager *core.OpenOltManager
54}
55
56func waitForExit() int {
57 signalChannel := make(chan os.Signal, 1)
58 signal.Notify(signalChannel,
59 syscall.SIGHUP,
60 syscall.SIGINT,
61 syscall.SIGTERM,
62 syscall.SIGQUIT)
63
64 exitChannel := make(chan int)
65
66 go func() {
67 s := <-signalChannel
68 switch s {
69 case syscall.SIGHUP,
70 syscall.SIGINT,
71 syscall.SIGTERM,
72 syscall.SIGQUIT:
Girish Gowdra5d7d6442020-09-08 17:03:11 -070073 logger.Infow(nil, "closing-signal-received", log.Fields{"signal": s})
Girish Gowdra64503432020-01-07 10:59:10 +053074 exitChannel <- 0
75 default:
Girish Gowdra5d7d6442020-09-08 17:03:11 -070076 logger.Infow(nil, "unexpected-signal-received", log.Fields{"signal": s})
Girish Gowdra64503432020-01-07 10:59:10 +053077 exitChannel <- 1
78 }
79 }()
80
81 code := <-exitChannel
82 return code
83}
84
85func printBanner() {
86 fmt.Println("TODO: Print banner here")
87}
88
89func main() {
90 start := time.Now()
91 sc := OpenOltScaleTester{}
92 cf := config.NewOpenOltScaleTesterConfig()
93 cf.ParseCommandArguments()
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +030094
95 cf.OpenOltAgentAddress = cf.OpenOltAgentIP + ":" + strconv.FormatUint(uint64(cf.OpenOltAgentPort), 10)
96
Girish Gowdra64503432020-01-07 10:59:10 +053097 // Generate TP ID List from TP ID string parsed from command line for a given subscriber
98 cf.TpIDList = config.GetTpIDList(cf.TpIDsString)
99 sc.openOltManager = core.NewOpenOltManager(cf.OpenOltAgentAddress)
100
101 printBanner()
102
103 // Setup logging
104
105 // Setup default logger - applies for packages that do not have specific logger set
106 if _, err := log.SetDefaultLogger(log.JSON, 0, log.Fields{"instanceId": 0}); err != nil {
Girish Gowdra5d7d6442020-09-08 17:03:11 -0700107 logger.With(log.Fields{"error": err}).Fatal(nil, "Cannot setup logging")
Girish Gowdra64503432020-01-07 10:59:10 +0530108 }
109
110 // Update all loggers (provisioned via init) with a common field
111 if err := log.UpdateAllLoggers(log.Fields{"instanceId": 0}); err != nil {
Girish Gowdra5d7d6442020-09-08 17:03:11 -0700112 logger.With(log.Fields{"error": err}).Fatal(nil, "Cannot setup logging")
Girish Gowdra64503432020-01-07 10:59:10 +0530113 }
114
Girish Gowdra390f12f2021-07-01 15:53:49 -0700115 log.SetPackageLogLevel("github.com/opencord/voltha-lib-go/v7/pkg/adapters/common", log.DebugLevel)
Girish Gowdra64503432020-01-07 10:59:10 +0530116
Girish Gowdra5d7d6442020-09-08 17:03:11 -0700117 logger.Infow(nil, "config", log.Fields{"config": *cf})
Girish Gowdra64503432020-01-07 10:59:10 +0530118
119 go sc.openOltManager.Start(cf)
120
121 code := waitForExit()
Girish Gowdra5d7d6442020-09-08 17:03:11 -0700122 logger.Infow(nil, "received-a-closing-signal", log.Fields{"code": code})
Girish Gowdra64503432020-01-07 10:59:10 +0530123
124 elapsed := time.Since(start)
Girish Gowdra5d7d6442020-09-08 17:03:11 -0700125 logger.Infow(nil, "run-time", log.Fields{"instanceId": 0, "time": elapsed / time.Second})
Girish Gowdra64503432020-01-07 10:59:10 +0530126}