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 |
| 28 | ProfileCpu *string |
| 29 | LogLevel string |
| 30 | LogCaller bool |
| 31 | } |
| 32 | |
| 33 | type BBRCliOptions struct { |
| 34 | *BBSimCliOptions |
| 35 | BBSimIp string |
| 36 | BBSimPort string |
| 37 | BBSimApiPort string |
Matteo Scandolo | f5c537e | 2019-10-28 16:45:57 -0700 | [diff] [blame] | 38 | LogFile string |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | func GetBBSimOpts() *BBSimCliOptions { |
| 42 | |
| 43 | olt_id := flag.Int("olt_id", 0, "Number of OLT devices to be emulated") |
| 44 | nni := flag.Int("nni", 1, "Number of NNI ports per OLT device to be emulated") |
| 45 | pon := flag.Int("pon", 1, "Number of PON ports per OLT device to be emulated") |
| 46 | onu := flag.Int("onu", 1, "Number of ONU devices per PON port to be emulated") |
| 47 | |
| 48 | s_tag := flag.Int("s_tag", 900, "S-Tag value") |
| 49 | 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)") |
| 50 | |
| 51 | profileCpu := flag.String("cpuprofile", "", "write cpu profile to file") |
| 52 | |
| 53 | logLevel := flag.String("logLevel", "debug", "Set the log level (trace, debug, info, warn, error)") |
| 54 | logCaller := flag.Bool("logCaller", false, "Whether to print the caller filename or not") |
| 55 | |
| 56 | flag.Parse() |
| 57 | |
| 58 | o := new(BBSimCliOptions) |
| 59 | |
| 60 | o.OltID = int(*olt_id) |
| 61 | o.NumNniPerOlt = int(*nni) |
| 62 | o.NumPonPerOlt = int(*pon) |
| 63 | o.NumOnuPerPon = int(*onu) |
| 64 | o.STag = int(*s_tag) |
| 65 | o.CTagInit = int(*c_tag_init) |
| 66 | o.ProfileCpu = profileCpu |
| 67 | o.LogLevel = *logLevel |
| 68 | o.LogCaller = *logCaller |
| 69 | |
| 70 | return o |
| 71 | } |
| 72 | |
| 73 | func GetBBROpts() BBRCliOptions { |
| 74 | |
| 75 | bbsimIp := flag.String("bbsimIp", "127.0.0.1", "BBSim IP") |
| 76 | bbsimPort := flag.String("bbsimPort", "50060", "BBSim Port") |
| 77 | bbsimApiPort := flag.String("bbsimApiPort", "50070", "BBSim API Port") |
Matteo Scandolo | f5c537e | 2019-10-28 16:45:57 -0700 | [diff] [blame] | 78 | logFile := flag.String("logfile", "", "Log to a file") |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 79 | |
| 80 | options := GetBBSimOpts() |
| 81 | |
| 82 | bbrOptions := BBRCliOptions{ |
| 83 | options, |
| 84 | *bbsimIp, |
| 85 | *bbsimPort, |
| 86 | *bbsimApiPort, |
Matteo Scandolo | f5c537e | 2019-10-28 16:45:57 -0700 | [diff] [blame] | 87 | *logFile, |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | return bbrOptions |
| 91 | } |