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