Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [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 common |
| 18 | |
| 19 | import "flag" |
| 20 | |
| 21 | type BBSimCliOptions struct { |
| 22 | OltID int |
| 23 | NumNniPerOlt int |
| 24 | NumPonPerOlt int |
| 25 | NumOnuPerPon int |
| 26 | STag int |
| 27 | CTagInit int |
Matteo Scandolo | c114709 | 2019-10-29 09:38:33 -0700 | [diff] [blame] | 28 | Auth bool |
| 29 | Dhcp bool |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 30 | ProfileCpu *string |
| 31 | LogLevel string |
| 32 | LogCaller bool |
Matteo Scandolo | e33447a | 2019-10-31 12:38:23 -0700 | [diff] [blame] | 33 | Delay int |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | type BBRCliOptions struct { |
| 37 | *BBSimCliOptions |
| 38 | BBSimIp string |
| 39 | BBSimPort string |
| 40 | BBSimApiPort string |
Matteo Scandolo | f5c537e | 2019-10-28 16:45:57 -0700 | [diff] [blame] | 41 | LogFile string |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | func GetBBSimOpts() *BBSimCliOptions { |
| 45 | |
| 46 | olt_id := flag.Int("olt_id", 0, "Number of OLT devices to be emulated") |
| 47 | nni := flag.Int("nni", 1, "Number of NNI ports per OLT device to be emulated") |
| 48 | pon := flag.Int("pon", 1, "Number of PON ports per OLT device to be emulated") |
| 49 | onu := flag.Int("onu", 1, "Number of ONU devices per PON port to be emulated") |
| 50 | |
Matteo Scandolo | c114709 | 2019-10-29 09:38:33 -0700 | [diff] [blame] | 51 | auth := flag.Bool("auth", false, "Set this flag if you want authentication to start automatically") |
| 52 | dhcp := flag.Bool("dhcp", false, "Set this flag if you want DHCP to start automatically") |
| 53 | |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 54 | s_tag := flag.Int("s_tag", 900, "S-Tag value") |
| 55 | c_tag_init := flag.Int("c_tag", 900, "C-Tag starting value, each ONU will get a sequential one (targeting 1024 ONUs per BBSim instance the range is big enough)") |
| 56 | |
| 57 | profileCpu := flag.String("cpuprofile", "", "write cpu profile to file") |
| 58 | |
| 59 | logLevel := flag.String("logLevel", "debug", "Set the log level (trace, debug, info, warn, error)") |
| 60 | logCaller := flag.Bool("logCaller", false, "Whether to print the caller filename or not") |
| 61 | |
Matteo Scandolo | cae57b5 | 2019-11-12 10:52:53 -0800 | [diff] [blame] | 62 | delay := flag.Int("delay", 200, "The delay between ONU DISCOVERY batches in milliseconds (1 ONU per each PON PORT at a time") |
Matteo Scandolo | e33447a | 2019-10-31 12:38:23 -0700 | [diff] [blame] | 63 | |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 64 | flag.Parse() |
| 65 | |
| 66 | o := new(BBSimCliOptions) |
| 67 | |
| 68 | o.OltID = int(*olt_id) |
| 69 | o.NumNniPerOlt = int(*nni) |
| 70 | o.NumPonPerOlt = int(*pon) |
| 71 | o.NumOnuPerPon = int(*onu) |
| 72 | o.STag = int(*s_tag) |
| 73 | o.CTagInit = int(*c_tag_init) |
| 74 | o.ProfileCpu = profileCpu |
| 75 | o.LogLevel = *logLevel |
| 76 | o.LogCaller = *logCaller |
Matteo Scandolo | c114709 | 2019-10-29 09:38:33 -0700 | [diff] [blame] | 77 | o.Auth = *auth |
| 78 | o.Dhcp = *dhcp |
Matteo Scandolo | cae57b5 | 2019-11-12 10:52:53 -0800 | [diff] [blame] | 79 | o.Delay = *delay |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 80 | |
| 81 | return o |
| 82 | } |
| 83 | |
| 84 | func GetBBROpts() BBRCliOptions { |
| 85 | |
| 86 | bbsimIp := flag.String("bbsimIp", "127.0.0.1", "BBSim IP") |
| 87 | bbsimPort := flag.String("bbsimPort", "50060", "BBSim Port") |
| 88 | bbsimApiPort := flag.String("bbsimApiPort", "50070", "BBSim API Port") |
Matteo Scandolo | f5c537e | 2019-10-28 16:45:57 -0700 | [diff] [blame] | 89 | logFile := flag.String("logfile", "", "Log to a file") |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 90 | |
| 91 | options := GetBBSimOpts() |
| 92 | |
| 93 | bbrOptions := BBRCliOptions{ |
| 94 | options, |
| 95 | *bbsimIp, |
| 96 | *bbsimPort, |
| 97 | *bbsimApiPort, |
Matteo Scandolo | f5c537e | 2019-10-28 16:45:57 -0700 | [diff] [blame] | 98 | *logFile, |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | return bbrOptions |
| 102 | } |