blob: 07c29ff515d0de753e32fcc268770fc5258d6755 [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"
22 "github.com/opencord/openolt-scale-tester/core"
23 "os"
24 "os/signal"
25 "syscall"
26 "time"
27
28 "github.com/opencord/openolt-scale-tester/config"
29 "github.com/opencord/voltha-lib-go/v2/pkg/log"
30)
31
32func init() {
33 _, _ = log.AddPackage(log.JSON, log.DebugLevel, nil)
34}
35
36const (
37 // DefaultLivelinessCheck to check the liveliness
38 DefaultLivelinessCheck = 30 * time.Second
39 // DefaultTimeout to close the connection
40 DefaultTimeout = 10
41)
42
43type OpenOltScaleTester struct {
44 openOltManager *core.OpenOltManager
45}
46
47func waitForExit() int {
48 signalChannel := make(chan os.Signal, 1)
49 signal.Notify(signalChannel,
50 syscall.SIGHUP,
51 syscall.SIGINT,
52 syscall.SIGTERM,
53 syscall.SIGQUIT)
54
55 exitChannel := make(chan int)
56
57 go func() {
58 s := <-signalChannel
59 switch s {
60 case syscall.SIGHUP,
61 syscall.SIGINT,
62 syscall.SIGTERM,
63 syscall.SIGQUIT:
64 log.Infow("closing-signal-received", log.Fields{"signal": s})
65 exitChannel <- 0
66 default:
67 log.Infow("unexpected-signal-received", log.Fields{"signal": s})
68 exitChannel <- 1
69 }
70 }()
71
72 code := <-exitChannel
73 return code
74}
75
76func printBanner() {
77 fmt.Println("TODO: Print banner here")
78}
79
80func main() {
81 start := time.Now()
82 sc := OpenOltScaleTester{}
83 cf := config.NewOpenOltScaleTesterConfig()
84 cf.ParseCommandArguments()
85 // Generate TP ID List from TP ID string parsed from command line for a given subscriber
86 cf.TpIDList = config.GetTpIDList(cf.TpIDsString)
87 sc.openOltManager = core.NewOpenOltManager(cf.OpenOltAgentAddress)
88
89 printBanner()
90
91 // Setup logging
92
93 // Setup default logger - applies for packages that do not have specific logger set
94 if _, err := log.SetDefaultLogger(log.JSON, 0, log.Fields{"instanceId": 0}); err != nil {
95 log.With(log.Fields{"error": err}).Fatal("Cannot setup logging")
96 }
97
98 // Update all loggers (provisioned via init) with a common field
99 if err := log.UpdateAllLoggers(log.Fields{"instanceId": 0}); err != nil {
100 log.With(log.Fields{"error": err}).Fatal("Cannot setup logging")
101 }
102
103 log.SetPackageLogLevel("github.com/opencord/voltha-lib-go/v2/pkg/adapters/common", log.DebugLevel)
104
105 log.Infow("config", log.Fields{"config": *cf})
106
107 go sc.openOltManager.Start(cf)
108
109 code := waitForExit()
110 log.Infow("received-a-closing-signal", log.Fields{"code": code})
111
112 elapsed := time.Since(start)
113 log.Infow("run-time", log.Fields{"instanceId": 0, "time": elapsed / time.Second})
114}