blob: 0374700af1ee0d179d5d71ab7533da3b1522ba3b [file] [log] [blame]
Keita NISHIMOTO26dab092018-07-06 09:52:45 +09001/*
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
Keita NISHIMOTOd771cd12018-06-07 08:37:24 +090017package main
18
19import (
Keita NISHIMOTOd771cd12018-06-07 08:37:24 +090020 "flag"
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090021 "fmt"
22 "log"
23 "os"
24 "os/signal"
Keita NISHIMOTOd771cd12018-06-07 08:37:24 +090025 "strconv"
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090026 "strings"
Keita NISHIMOTOd771cd12018-06-07 08:37:24 +090027 "sync"
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090028 "time"
Matteo Scandolo4549d3f2018-10-19 12:48:20 -070029
30 "gerrit.opencord.org/voltha-bbsim/core"
31 "gerrit.opencord.org/voltha-bbsim/protos"
Keita NISHIMOTOd771cd12018-06-07 08:37:24 +090032)
33
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090034func printBanner() {
Keita NISHIMOTOd771cd12018-06-07 08:37:24 +090035 log.Println(" ________ _______ ________ ")
36 log.Println(" / ____ | / ____ | / ______/ __ ")
37 log.Println(" / /____/ / / /____/ / / /_____ /_/ ")
38 log.Println(" / _____ | / _____ | /______ | __ __________ ")
39 log.Println(" / /____/ / / /____/ / _______/ / / / / __ __ / ")
40 log.Println("/________/ /________/ /________/ /_/ /_/ /_/ /_/ ")
41}
42
Matteo Scandolo4549d3f2018-10-19 12:48:20 -070043func getOptions() (uint32, string, uint32, uint32, uint32, int, int, string, int, core.Mode) {
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090044 addressport := flag.String("H", ":50060", "IP address:port")
45 oltid := flag.Int("id", 0, "OLT-ID")
46 nintfs := flag.Int("i", 1, "Number of PON-IF ports")
47 nonus := flag.Int("n", 1, "Number of ONUs per PON-IF port")
48 modeopt := flag.String("m", "default", "Emulation mode (default, aaa, both (aaa & dhcp))")
49 aaawait := flag.Int("a", 30, "Wait time (sec) for activation WPA supplicants")
50 dhcpwait := flag.Int("d", 10, "Wait time (sec) for activation DHCP clients")
51 dhcpservip := flag.String("s", "182.21.0.1", "DHCP Server IP Address")
Matteo Scandolo4549d3f2018-10-19 12:48:20 -070052 delay := flag.Int("delay", 1, "Delay between ONU events")
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090053 mode := core.DEFAULT
Keita NISHIMOTOd771cd12018-06-07 08:37:24 +090054 flag.Parse()
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090055 if *modeopt == "aaa" {
56 mode = core.AAA
57 } else if *modeopt == "both" {
58 mode = core.BOTH
59 }
60 address := strings.Split(*addressport, ":")[0]
61 tmp, _ := strconv.Atoi(strings.Split(*addressport, ":")[1])
62 port := uint32(tmp)
Matteo Scandolo4549d3f2018-10-19 12:48:20 -070063 return uint32(*oltid), address, port, uint32(*nintfs), uint32(*nonus), *aaawait, *dhcpwait, *dhcpservip, *delay, mode
Keita NISHIMOTOd771cd12018-06-07 08:37:24 +090064}
65
Keita NISHIMOTOd771cd12018-06-07 08:37:24 +090066func main() {
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090067 // CLI Shows up
Keita NISHIMOTOd771cd12018-06-07 08:37:24 +090068 printBanner()
Matteo Scandolo4549d3f2018-10-19 12:48:20 -070069 oltid, ip, port, npon, nonus, aaawait, dhcpwait, dhcpservip, delay, mode := getOptions()
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090070 log.Printf("ip:%s, baseport:%d, npon:%d, nonus:%d, mode:%d\n", ip, port, npon, nonus, mode)
71
72 // Set up gRPC Server
Keita NISHIMOTOd771cd12018-06-07 08:37:24 +090073 var wg sync.WaitGroup
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090074
75 addressport := ip + ":" + strconv.Itoa(int(port))
76 endchan := make(chan int, 1)
77 listener, gserver, err := core.CreateGrpcServer(oltid, npon, nonus, addressport)
Matteo Scandolo4549d3f2018-10-19 12:48:20 -070078 server := core.Create(oltid, npon, nonus, aaawait, dhcpwait, dhcpservip, delay, gserver, mode, endchan)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090079 if err != nil {
80 log.Println(err)
Keita NISHIMOTOd771cd12018-06-07 08:37:24 +090081 }
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090082 openolt.RegisterOpenoltServer(gserver, server)
83
84 wg.Add(1)
85 go func() {
86 defer wg.Done()
87 gserver.Serve(listener)
88 }()
89
90 c := make(chan os.Signal, 1)
91 signal.Notify(c, os.Interrupt)
92 go func() {
93 for sig := range c {
94 fmt.Println("SIGINT", sig)
95 close(c)
96 close(server.Endchan)
97 gserver.Stop()
98 }
99 }()
Keita NISHIMOTOd771cd12018-06-07 08:37:24 +0900100 wg.Wait()
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +0900101 time.Sleep(5 * time.Second)
102 log.Println("Reach to the end line")
Keita NISHIMOTOd771cd12018-06-07 08:37:24 +0900103}