blob: 301716521e33264b7bc6c039480adb9e70ae1c6b [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
17package config
18
19import (
20 "flag"
21 "fmt"
Girish Gowdra64503432020-01-07 10:59:10 +053022 "strconv"
23 "strings"
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +030024
Girish Gowdra390f12f2021-07-01 15:53:49 -070025 "github.com/opencord/voltha-lib-go/v7/pkg/log"
Girish Gowdra64503432020-01-07 10:59:10 +053026)
27
28// Open OLT default constants
29const (
30 defaultOpenOltAgentIp = "10.90.0.114"
31 defaultOpenOltAgentPort = 9191
32 defaultNumOfOnu = 128
33 defaultNumOfSubscribersPerOnu = 1
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +030034 defaultWorkFlowName = "TT"
Girish Gowdra64503432020-01-07 10:59:10 +053035 defaultTimeIntervalBetweenSubs = 5 // in seconds
36 defaultNniIntfId = 0
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +030037 defaultKVstoreHost = "192.168.1.1"
Girish Gowdra64503432020-01-07 10:59:10 +053038 defaultKVstorePort = 2379
39 defaultTpIDs = "64"
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +030040 defaultIsGroupTest = false
Girish Gowdra64503432020-01-07 10:59:10 +053041)
42
43// OpenOltScaleTesterConfigConfig represents the set of configurations used by the read-write adaptercore service
44type 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 Kupusoglu66b00d82020-03-13 12:06:33 +030058 IsGroupTest bool
Girish Gowdra64503432020-01-07 10:59:10 +053059}
60
Girish Gowdra5d7d6442020-09-08 17:03:11 -070061var logger log.CLogger
62
Girish Gowdra64503432020-01-07 10:59:10 +053063func init() {
Girish Gowdra5d7d6442020-09-08 17:03:11 -070064 // 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 Gowdra64503432020-01-07 10:59:10 +053070}
71
72func 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 Gowdra5d7d6442020-09-08 17:03:11 -070080 logger.Debugw(nil, "parsed-tp-id-slice", log.Fields{"tpIDSlice": tpIDSlice})
Girish Gowdra64503432020-01-07 10:59:10 +053081 return tpIDSlice
82}
83
84// NewOpenOltScaleTesterConfig returns a new RWCore config
85func 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 Kupusoglu66b00d82020-03-13 12:06:33 +030096 IsGroupTest: defaultIsGroupTest,
Girish Gowdra64503432020-01-07 10:59:10 +053097 }
98 return &OpenOltScaleTesterConfig
99}
100
101// ParseCommandArguments parses the arguments for OpenOltScale Tester
102func (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 Kupusoglu66b00d82020-03-13 12:06:33 +0300134 help = fmt.Sprintf("Is this run a group test")
135 flag.BoolVar(&(st.IsGroupTest), "is_group_test", defaultIsGroupTest, help)
Girish Gowdra64503432020-01-07 10:59:10 +0530136
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +0300137 flag.Parse()
Girish Gowdra64503432020-01-07 10:59:10 +0530138}