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