Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 1 | /* |
| 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 |
| 18 | package main |
| 19 | |
| 20 | import ( |
| 21 | "fmt" |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 22 | "os" |
| 23 | "os/signal" |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 24 | "strconv" |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 25 | "syscall" |
| 26 | "time" |
| 27 | |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 28 | "github.com/opencord/openolt-scale-tester/core" |
| 29 | |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 30 | "github.com/opencord/openolt-scale-tester/config" |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 31 | "github.com/opencord/voltha-lib-go/v3/pkg/log" |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 32 | ) |
| 33 | |
| 34 | func init() { |
| 35 | _, _ = log.AddPackage(log.JSON, log.DebugLevel, nil) |
| 36 | } |
| 37 | |
| 38 | const ( |
| 39 | // DefaultLivelinessCheck to check the liveliness |
| 40 | DefaultLivelinessCheck = 30 * time.Second |
| 41 | // DefaultTimeout to close the connection |
| 42 | DefaultTimeout = 10 |
| 43 | ) |
| 44 | |
| 45 | type OpenOltScaleTester struct { |
| 46 | openOltManager *core.OpenOltManager |
| 47 | } |
| 48 | |
| 49 | func 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 | |
| 78 | func printBanner() { |
| 79 | fmt.Println("TODO: Print banner here") |
| 80 | } |
| 81 | |
| 82 | func main() { |
| 83 | start := time.Now() |
| 84 | sc := OpenOltScaleTester{} |
| 85 | cf := config.NewOpenOltScaleTesterConfig() |
| 86 | cf.ParseCommandArguments() |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 87 | |
| 88 | cf.OpenOltAgentAddress = cf.OpenOltAgentIP + ":" + strconv.FormatUint(uint64(cf.OpenOltAgentPort), 10) |
| 89 | |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 90 | // 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 Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 108 | log.SetPackageLogLevel("github.com/opencord/voltha-lib-go/v3/pkg/adapters/common", log.DebugLevel) |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 109 | |
| 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 | } |