Matteo Scandolo | 1100699 | 2019-08-28 11:29:46 -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 | |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 17 | package main |
| 18 | |
| 19 | import ( |
| 20 | "flag" |
Matteo Scandolo | 1100699 | 2019-08-28 11:29:46 -0700 | [diff] [blame^] | 21 | "github.com/opencord/bbsim/api/bbsim" |
| 22 | "github.com/opencord/bbsim/internal/bbsim/devices" |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 23 | log "github.com/sirupsen/logrus" |
Matteo Scandolo | 84f7d48 | 2019-08-08 19:00:47 -0700 | [diff] [blame] | 24 | "google.golang.org/grpc" |
| 25 | "google.golang.org/grpc/reflection" |
| 26 | "net" |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 27 | "sync" |
| 28 | ) |
| 29 | |
| 30 | func getOpts() *CliOptions { |
| 31 | |
| 32 | olt_id := flag.Int("olt_id", 0, "Number of OLT devices to be emulated (default is 1)") |
| 33 | nni := flag.Int("nni", 1, "Number of NNI ports per OLT device to be emulated (default is 1)") |
| 34 | pon := flag.Int("pon", 1, "Number of PON ports per OLT device to be emulated (default is 1)") |
| 35 | onu := flag.Int("onu", 1, "Number of ONU devices per PON port to be emulated (default is 1)") |
| 36 | flag.Parse() |
| 37 | |
| 38 | o := new(CliOptions) |
| 39 | |
| 40 | o.OltID = int(*olt_id) |
| 41 | o.NumNniPerOlt = int(*nni) |
| 42 | o.NumPonPerOlt = int(*pon) |
| 43 | o.NumOnuPerPon = int(*onu) |
| 44 | |
| 45 | return o |
| 46 | } |
| 47 | |
Matteo Scandolo | 84f7d48 | 2019-08-08 19:00:47 -0700 | [diff] [blame] | 48 | func startApiServer() { |
| 49 | // TODO make configurable |
| 50 | address := "0.0.0.0:50070" |
| 51 | log.Debugf("APIServer Listening on: %v", address) |
| 52 | lis, err := net.Listen("tcp", address) |
| 53 | if err != nil { |
| 54 | log.Fatalf("APIServer failed to listen: %v", err) |
| 55 | } |
| 56 | grpcServer := grpc.NewServer() |
| 57 | bbsim.RegisterBBSimServer(grpcServer, BBSimServer{}) |
| 58 | |
| 59 | reflection.Register(grpcServer) |
| 60 | |
| 61 | go grpcServer.Serve(lis) |
| 62 | } |
| 63 | |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 64 | func init() { |
Matteo Scandolo | c559ef1 | 2019-08-20 13:24:21 -0700 | [diff] [blame] | 65 | //log.SetLevel(log.DebugLevel) |
| 66 | log.SetLevel(log.TraceLevel) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 67 | //log.SetReportCaller(true) |
| 68 | } |
| 69 | |
| 70 | func main() { |
| 71 | |
| 72 | options := getOpts() |
| 73 | |
| 74 | log.WithFields(log.Fields{ |
| 75 | "OltID": options.OltID, |
| 76 | "NumNniPerOlt": options.NumNniPerOlt, |
| 77 | "NumPonPerOlt": options.NumPonPerOlt, |
| 78 | "NumOnuPerPon": options.NumOnuPerPon, |
| 79 | }).Info("BroadBand Simulator is on") |
| 80 | |
| 81 | wg := sync.WaitGroup{} |
Matteo Scandolo | 84f7d48 | 2019-08-08 19:00:47 -0700 | [diff] [blame] | 82 | wg.Add(2) |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 83 | |
| 84 | |
| 85 | go devices.CreateOLT(options.OltID, options.NumNniPerOlt, options.NumPonPerOlt, options.NumOnuPerPon) |
| 86 | log.Debugf("Created OLT with id: %d", options.OltID) |
Matteo Scandolo | 84f7d48 | 2019-08-08 19:00:47 -0700 | [diff] [blame] | 87 | go startApiServer() |
| 88 | log.Debugf("Started APIService") |
Matteo Scandolo | 4747d29 | 2019-08-05 11:50:18 -0700 | [diff] [blame] | 89 | |
| 90 | wg.Wait() |
| 91 | |
| 92 | defer func() { |
| 93 | log.Info("BroadBand Simulator is off") |
| 94 | }() |
| 95 | } |