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 config |
| 18 | |
| 19 | import ( |
| 20 | "flag" |
| 21 | "fmt" |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 22 | "strconv" |
| 23 | "strings" |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 24 | |
Girish Gowdra | 390f12f | 2021-07-01 15:53:49 -0700 | [diff] [blame^] | 25 | "github.com/opencord/voltha-lib-go/v7/pkg/log" |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 26 | ) |
| 27 | |
| 28 | // Open OLT default constants |
| 29 | const ( |
| 30 | defaultOpenOltAgentIp = "10.90.0.114" |
| 31 | defaultOpenOltAgentPort = 9191 |
| 32 | defaultNumOfOnu = 128 |
| 33 | defaultNumOfSubscribersPerOnu = 1 |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 34 | defaultWorkFlowName = "TT" |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 35 | defaultTimeIntervalBetweenSubs = 5 // in seconds |
| 36 | defaultNniIntfId = 0 |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 37 | defaultKVstoreHost = "192.168.1.1" |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 38 | defaultKVstorePort = 2379 |
| 39 | defaultTpIDs = "64" |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 40 | defaultIsGroupTest = false |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 41 | ) |
| 42 | |
| 43 | // OpenOltScaleTesterConfigConfig represents the set of configurations used by the read-write adaptercore service |
| 44 | type OpenOltScaleTesterConfig struct { |
| 45 | // Command line parameters |
| 46 | OpenOltAgentAddress string |
| 47 | OpenOltAgentIP string |
| 48 | OpenOltAgentPort uint |
| 49 | NniIntfID uint |
| 50 | NumOfOnu uint |
| 51 | SubscribersPerOnu uint |
| 52 | WorkflowName string |
| 53 | TimeIntervalBetweenSubs uint // in seconds |
| 54 | KVStoreHost string |
| 55 | KVStorePort int |
| 56 | TpIDsString string |
| 57 | TpIDList []int |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 58 | IsGroupTest bool |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 59 | } |
| 60 | |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 61 | var logger log.CLogger |
| 62 | |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 63 | func init() { |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 64 | // Setup this package so that it's log level can be modified at run time |
| 65 | var err error |
| 66 | logger, err = log.RegisterPackage(log.JSON, log.DebugLevel, log.Fields{}) |
| 67 | if err != nil { |
| 68 | panic(err) |
| 69 | } |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | func GetTpIDList(tpIDsStr string) []int { |
| 73 | stringSlice := strings.Split(tpIDsStr, ",") |
| 74 | var tpIDSlice []int |
| 75 | for _, s := range stringSlice { |
| 76 | if tpID, err := strconv.Atoi(s); err == nil { |
| 77 | tpIDSlice = append(tpIDSlice, tpID) |
| 78 | } |
| 79 | } |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 80 | logger.Debugw(nil, "parsed-tp-id-slice", log.Fields{"tpIDSlice": tpIDSlice}) |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 81 | return tpIDSlice |
| 82 | } |
| 83 | |
| 84 | // NewOpenOltScaleTesterConfig returns a new RWCore config |
| 85 | func NewOpenOltScaleTesterConfig() *OpenOltScaleTesterConfig { |
| 86 | var OpenOltScaleTesterConfig = OpenOltScaleTesterConfig{ // Default values |
| 87 | OpenOltAgentAddress: defaultOpenOltAgentIp + ":" + strconv.Itoa(defaultOpenOltAgentPort), |
| 88 | NumOfOnu: defaultNumOfOnu, |
| 89 | SubscribersPerOnu: defaultNumOfSubscribersPerOnu, |
| 90 | WorkflowName: defaultWorkFlowName, |
| 91 | TimeIntervalBetweenSubs: defaultTimeIntervalBetweenSubs, |
| 92 | NniIntfID: defaultNniIntfId, |
| 93 | KVStoreHost: defaultKVstoreHost, |
| 94 | KVStorePort: defaultKVstorePort, |
| 95 | TpIDList: GetTpIDList(defaultTpIDs), |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 96 | IsGroupTest: defaultIsGroupTest, |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 97 | } |
| 98 | return &OpenOltScaleTesterConfig |
| 99 | } |
| 100 | |
| 101 | // ParseCommandArguments parses the arguments for OpenOltScale Tester |
| 102 | func (st *OpenOltScaleTesterConfig) ParseCommandArguments() { |
| 103 | |
| 104 | help := fmt.Sprintf("OpenOLT Agent IP Address") |
| 105 | flag.StringVar(&(st.OpenOltAgentIP), "openolt_agent_ip_address", defaultOpenOltAgentIp, help) |
| 106 | |
| 107 | help = fmt.Sprintf("OpenOLT Agent gRPC port") |
| 108 | flag.UintVar(&(st.OpenOltAgentPort), "openolt_agent_port", defaultOpenOltAgentPort, help) |
| 109 | |
| 110 | help = fmt.Sprintf("OpenOLT Agent Nni Intf Id") |
| 111 | flag.UintVar(&(st.NniIntfID), "openolt_agent_nni_intf_id", defaultNniIntfId, help) |
| 112 | |
| 113 | help = fmt.Sprintf("Number of ONU") |
| 114 | flag.UintVar(&(st.NumOfOnu), "num_of_onu", defaultNumOfOnu, help) |
| 115 | |
| 116 | help = fmt.Sprintf("Subscribers per ONU") |
| 117 | flag.UintVar(&(st.SubscribersPerOnu), "subscribers_per_onu", defaultNumOfSubscribersPerOnu, help) |
| 118 | |
| 119 | help = fmt.Sprintf("Workflow name") |
| 120 | flag.StringVar(&(st.WorkflowName), "workflow_name", defaultWorkFlowName, help) |
| 121 | |
| 122 | help = fmt.Sprintf("Time Interval Between provisioning each subscriber") |
| 123 | flag.UintVar(&(st.TimeIntervalBetweenSubs), "time_interval_between_subs", defaultTimeIntervalBetweenSubs, help) |
| 124 | |
| 125 | help = fmt.Sprintf("KV store host") |
| 126 | flag.StringVar(&(st.KVStoreHost), "kv_store_host", defaultKVstoreHost, help) |
| 127 | |
| 128 | help = fmt.Sprintf("KV store port") |
| 129 | flag.IntVar(&(st.KVStorePort), "kv_store_port", defaultKVstorePort, help) |
| 130 | |
| 131 | help = fmt.Sprintf("Command seperated TP ID list for Workflow") |
| 132 | flag.StringVar(&(st.TpIDsString), "tp_ids", defaultTpIDs, help) |
| 133 | |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 134 | help = fmt.Sprintf("Is this run a group test") |
| 135 | flag.BoolVar(&(st.IsGroupTest), "is_group_test", defaultIsGroupTest, help) |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 136 | |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 137 | flag.Parse() |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 138 | } |