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 | |
| 25 | "github.com/opencord/voltha-lib-go/v3/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 | |
| 61 | func init() { |
| 62 | _, _ = log.AddPackage(log.JSON, log.WarnLevel, nil) |
| 63 | } |
| 64 | |
| 65 | func GetTpIDList(tpIDsStr string) []int { |
| 66 | stringSlice := strings.Split(tpIDsStr, ",") |
| 67 | var tpIDSlice []int |
| 68 | for _, s := range stringSlice { |
| 69 | if tpID, err := strconv.Atoi(s); err == nil { |
| 70 | tpIDSlice = append(tpIDSlice, tpID) |
| 71 | } |
| 72 | } |
| 73 | log.Debugw("parsed-tp-id-slice", log.Fields{"tpIDSlice": tpIDSlice}) |
| 74 | return tpIDSlice |
| 75 | } |
| 76 | |
| 77 | // NewOpenOltScaleTesterConfig returns a new RWCore config |
| 78 | func NewOpenOltScaleTesterConfig() *OpenOltScaleTesterConfig { |
| 79 | var OpenOltScaleTesterConfig = OpenOltScaleTesterConfig{ // Default values |
| 80 | OpenOltAgentAddress: defaultOpenOltAgentIp + ":" + strconv.Itoa(defaultOpenOltAgentPort), |
| 81 | NumOfOnu: defaultNumOfOnu, |
| 82 | SubscribersPerOnu: defaultNumOfSubscribersPerOnu, |
| 83 | WorkflowName: defaultWorkFlowName, |
| 84 | TimeIntervalBetweenSubs: defaultTimeIntervalBetweenSubs, |
| 85 | NniIntfID: defaultNniIntfId, |
| 86 | KVStoreHost: defaultKVstoreHost, |
| 87 | KVStorePort: defaultKVstorePort, |
| 88 | TpIDList: GetTpIDList(defaultTpIDs), |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame^] | 89 | IsGroupTest: defaultIsGroupTest, |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 90 | } |
| 91 | return &OpenOltScaleTesterConfig |
| 92 | } |
| 93 | |
| 94 | // ParseCommandArguments parses the arguments for OpenOltScale Tester |
| 95 | func (st *OpenOltScaleTesterConfig) ParseCommandArguments() { |
| 96 | |
| 97 | help := fmt.Sprintf("OpenOLT Agent IP Address") |
| 98 | flag.StringVar(&(st.OpenOltAgentIP), "openolt_agent_ip_address", defaultOpenOltAgentIp, help) |
| 99 | |
| 100 | help = fmt.Sprintf("OpenOLT Agent gRPC port") |
| 101 | flag.UintVar(&(st.OpenOltAgentPort), "openolt_agent_port", defaultOpenOltAgentPort, help) |
| 102 | |
| 103 | help = fmt.Sprintf("OpenOLT Agent Nni Intf Id") |
| 104 | flag.UintVar(&(st.NniIntfID), "openolt_agent_nni_intf_id", defaultNniIntfId, help) |
| 105 | |
| 106 | help = fmt.Sprintf("Number of ONU") |
| 107 | flag.UintVar(&(st.NumOfOnu), "num_of_onu", defaultNumOfOnu, help) |
| 108 | |
| 109 | help = fmt.Sprintf("Subscribers per ONU") |
| 110 | flag.UintVar(&(st.SubscribersPerOnu), "subscribers_per_onu", defaultNumOfSubscribersPerOnu, help) |
| 111 | |
| 112 | help = fmt.Sprintf("Workflow name") |
| 113 | flag.StringVar(&(st.WorkflowName), "workflow_name", defaultWorkFlowName, help) |
| 114 | |
| 115 | help = fmt.Sprintf("Time Interval Between provisioning each subscriber") |
| 116 | flag.UintVar(&(st.TimeIntervalBetweenSubs), "time_interval_between_subs", defaultTimeIntervalBetweenSubs, help) |
| 117 | |
| 118 | help = fmt.Sprintf("KV store host") |
| 119 | flag.StringVar(&(st.KVStoreHost), "kv_store_host", defaultKVstoreHost, help) |
| 120 | |
| 121 | help = fmt.Sprintf("KV store port") |
| 122 | flag.IntVar(&(st.KVStorePort), "kv_store_port", defaultKVstorePort, help) |
| 123 | |
| 124 | help = fmt.Sprintf("Command seperated TP ID list for Workflow") |
| 125 | flag.StringVar(&(st.TpIDsString), "tp_ids", defaultTpIDs, help) |
| 126 | |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame^] | 127 | help = fmt.Sprintf("Is this run a group test") |
| 128 | flag.BoolVar(&(st.IsGroupTest), "is_group_test", defaultIsGroupTest, help) |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 129 | |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame^] | 130 | flag.Parse() |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 131 | } |