Keita NISHIMOTO | 26dab09 | 2018-07-06 09:52:45 +0900 | [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 | |
Keita NISHIMOTO | d771cd1 | 2018-06-07 08:37:24 +0900 | [diff] [blame] | 17 | package main |
| 18 | |
| 19 | import ( |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 20 | "gerrit.opencord.org/voltha-bbsim/protos" |
| 21 | "gerrit.opencord.org/voltha-bbsim/core" |
Keita NISHIMOTO | d771cd1 | 2018-06-07 08:37:24 +0900 | [diff] [blame] | 22 | "flag" |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 23 | "fmt" |
| 24 | "log" |
| 25 | "os" |
| 26 | "os/signal" |
Keita NISHIMOTO | d771cd1 | 2018-06-07 08:37:24 +0900 | [diff] [blame] | 27 | "strconv" |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 28 | "strings" |
Keita NISHIMOTO | d771cd1 | 2018-06-07 08:37:24 +0900 | [diff] [blame] | 29 | "sync" |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 30 | "time" |
Keita NISHIMOTO | d771cd1 | 2018-06-07 08:37:24 +0900 | [diff] [blame] | 31 | ) |
| 32 | |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 33 | func printBanner() { |
Keita NISHIMOTO | d771cd1 | 2018-06-07 08:37:24 +0900 | [diff] [blame] | 34 | log.Println(" ________ _______ ________ ") |
| 35 | log.Println(" / ____ | / ____ | / ______/ __ ") |
| 36 | log.Println(" / /____/ / / /____/ / / /_____ /_/ ") |
| 37 | log.Println(" / _____ | / _____ | /______ | __ __________ ") |
| 38 | log.Println(" / /____/ / / /____/ / _______/ / / / / __ __ / ") |
| 39 | log.Println("/________/ /________/ /________/ /_/ /_/ /_/ /_/ ") |
| 40 | } |
| 41 | |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 42 | func 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 NISHIMOTO | d771cd1 | 2018-06-07 08:37:24 +0900 | [diff] [blame] | 52 | flag.Parse() |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 53 | 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 NISHIMOTO | d771cd1 | 2018-06-07 08:37:24 +0900 | [diff] [blame] | 62 | } |
| 63 | |
Keita NISHIMOTO | d771cd1 | 2018-06-07 08:37:24 +0900 | [diff] [blame] | 64 | func main() { |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 65 | // CLI Shows up |
Keita NISHIMOTO | d771cd1 | 2018-06-07 08:37:24 +0900 | [diff] [blame] | 66 | printBanner() |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 67 | 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 NISHIMOTO | d771cd1 | 2018-06-07 08:37:24 +0900 | [diff] [blame] | 71 | var wg sync.WaitGroup |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 72 | |
| 73 | addressport := ip + ":" + strconv.Itoa(int(port)) |
| 74 | endchan := make(chan int, 1) |
| 75 | listener, gserver, err := core.CreateGrpcServer(oltid, npon, nonus, addressport) |
Keita NISHIMOTO | ca4da5f | 2018-10-15 22:48:52 +0900 | [diff] [blame] | 76 | server := core.Create(oltid, npon, nonus, aaawait, dhcpwait, dhcpservip, gserver, mode, endchan) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 77 | if err != nil { |
| 78 | log.Println(err) |
Keita NISHIMOTO | d771cd1 | 2018-06-07 08:37:24 +0900 | [diff] [blame] | 79 | } |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 80 | 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 NISHIMOTO | d771cd1 | 2018-06-07 08:37:24 +0900 | [diff] [blame] | 98 | wg.Wait() |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 99 | time.Sleep(5 * time.Second) |
| 100 | log.Println("Reach to the end line") |
Keita NISHIMOTO | d771cd1 | 2018-06-07 08:37:24 +0900 | [diff] [blame] | 101 | } |