blob: 19506686fc073e8283c9b4ba5a7ee87e7756b2dd [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 NISHIMOTO3b8b9c02018-10-09 09:40:01 +090020 "gerrit.opencord.org/voltha-bbsim/protos"
21 "gerrit.opencord.org/voltha-bbsim/core"
Keita NISHIMOTOd771cd12018-06-07 08:37:24 +090022 "flag"
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090023 "fmt"
24 "log"
25 "os"
26 "os/signal"
Keita NISHIMOTOd771cd12018-06-07 08:37:24 +090027 "strconv"
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090028 "strings"
Keita NISHIMOTOd771cd12018-06-07 08:37:24 +090029 "sync"
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090030 "time"
Keita NISHIMOTOd771cd12018-06-07 08:37:24 +090031)
32
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090033func printBanner() {
Keita NISHIMOTOd771cd12018-06-07 08:37:24 +090034 log.Println(" ________ _______ ________ ")
35 log.Println(" / ____ | / ____ | / ______/ __ ")
36 log.Println(" / /____/ / / /____/ / / /_____ /_/ ")
37 log.Println(" / _____ | / _____ | /______ | __ __________ ")
38 log.Println(" / /____/ / / /____/ / _______/ / / / / __ __ / ")
39 log.Println("/________/ /________/ /________/ /_/ /_/ /_/ /_/ ")
40}
41
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090042func getOptions() (uint32, string, uint32, uint32, uint32, int, int, string, core.Mode) {
43 addressport := flag.String("H", ":50060", "IP address:port")
44 oltid := flag.Int("id", 0, "OLT-ID")
45 nintfs := flag.Int("i", 1, "Number of PON-IF ports")
46 nonus := flag.Int("n", 1, "Number of ONUs per PON-IF port")
47 modeopt := flag.String("m", "default", "Emulation mode (default, aaa, both (aaa & dhcp))")
48 aaawait := flag.Int("a", 30, "Wait time (sec) for activation WPA supplicants")
49 dhcpwait := flag.Int("d", 10, "Wait time (sec) for activation DHCP clients")
50 dhcpservip := flag.String("s", "182.21.0.1", "DHCP Server IP Address")
51 mode := core.DEFAULT
Keita NISHIMOTOd771cd12018-06-07 08:37:24 +090052 flag.Parse()
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090053 if *modeopt == "aaa" {
54 mode = core.AAA
55 } else if *modeopt == "both" {
56 mode = core.BOTH
57 }
58 address := strings.Split(*addressport, ":")[0]
59 tmp, _ := strconv.Atoi(strings.Split(*addressport, ":")[1])
60 port := uint32(tmp)
61 return uint32(*oltid), address, port, uint32(*nintfs), uint32(*nonus), *aaawait, *dhcpwait, *dhcpservip, mode
Keita NISHIMOTOd771cd12018-06-07 08:37:24 +090062}
63
Keita NISHIMOTOd771cd12018-06-07 08:37:24 +090064func main() {
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090065 // CLI Shows up
Keita NISHIMOTOd771cd12018-06-07 08:37:24 +090066 printBanner()
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090067 oltid, ip, port, npon, nonus, aaawait, dhcpwait, dhcpservip, mode := getOptions()
68 log.Printf("ip:%s, baseport:%d, npon:%d, nonus:%d, mode:%d\n", ip, port, npon, nonus, mode)
69
70 // Set up gRPC Server
Keita NISHIMOTOd771cd12018-06-07 08:37:24 +090071 var wg sync.WaitGroup
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090072
73 addressport := ip + ":" + strconv.Itoa(int(port))
74 endchan := make(chan int, 1)
75 listener, gserver, err := core.CreateGrpcServer(oltid, npon, nonus, addressport)
Keita NISHIMOTOca4da5f2018-10-15 22:48:52 +090076 server := core.Create(oltid, npon, nonus, aaawait, dhcpwait, dhcpservip, gserver, mode, endchan)
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090077 if err != nil {
78 log.Println(err)
Keita NISHIMOTOd771cd12018-06-07 08:37:24 +090079 }
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090080 openolt.RegisterOpenoltServer(gserver, server)
81
82 wg.Add(1)
83 go func() {
84 defer wg.Done()
85 gserver.Serve(listener)
86 }()
87
88 c := make(chan os.Signal, 1)
89 signal.Notify(c, os.Interrupt)
90 go func() {
91 for sig := range c {
92 fmt.Println("SIGINT", sig)
93 close(c)
94 close(server.Endchan)
95 gserver.Stop()
96 }
97 }()
Keita NISHIMOTOd771cd12018-06-07 08:37:24 +090098 wg.Wait()
Keita NISHIMOTO3b8b9c02018-10-09 09:40:01 +090099 time.Sleep(5 * time.Second)
100 log.Println("Reach to the end line")
Keita NISHIMOTOd771cd12018-06-07 08:37:24 +0900101}