blob: 6b9f7c0bde1c71dd9abc8e8049e9dcef2f06072d [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
25 "github.com/opencord/voltha-lib-go/v3/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
61func init() {
62 _, _ = log.AddPackage(log.JSON, log.WarnLevel, nil)
63}
64
65func 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
78func 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 Kupusoglu66b00d82020-03-13 12:06:33 +030089 IsGroupTest: defaultIsGroupTest,
Girish Gowdra64503432020-01-07 10:59:10 +053090 }
91 return &OpenOltScaleTesterConfig
92}
93
94// ParseCommandArguments parses the arguments for OpenOltScale Tester
95func (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 Kupusoglu66b00d82020-03-13 12:06:33 +0300127 help = fmt.Sprintf("Is this run a group test")
128 flag.BoolVar(&(st.IsGroupTest), "is_group_test", defaultIsGroupTest, help)
Girish Gowdra64503432020-01-07 10:59:10 +0530129
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +0300130 flag.Parse()
Girish Gowdra64503432020-01-07 10:59:10 +0530131}