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 | d771cd1 | 2018-06-07 08:37:24 +0900 | [diff] [blame] | 20 | "flag" |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 21 | "fmt" |
| 22 | "log" |
| 23 | "os" |
| 24 | "os/signal" |
Keita NISHIMOTO | d771cd1 | 2018-06-07 08:37:24 +0900 | [diff] [blame] | 25 | "strconv" |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 26 | "strings" |
Keita NISHIMOTO | d771cd1 | 2018-06-07 08:37:24 +0900 | [diff] [blame] | 27 | "sync" |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 28 | "time" |
Matteo Scandolo | 4549d3f | 2018-10-19 12:48:20 -0700 | [diff] [blame^] | 29 | |
| 30 | "gerrit.opencord.org/voltha-bbsim/core" |
| 31 | "gerrit.opencord.org/voltha-bbsim/protos" |
Keita NISHIMOTO | d771cd1 | 2018-06-07 08:37:24 +0900 | [diff] [blame] | 32 | ) |
| 33 | |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 34 | func printBanner() { |
Keita NISHIMOTO | d771cd1 | 2018-06-07 08:37:24 +0900 | [diff] [blame] | 35 | log.Println(" ________ _______ ________ ") |
| 36 | log.Println(" / ____ | / ____ | / ______/ __ ") |
| 37 | log.Println(" / /____/ / / /____/ / / /_____ /_/ ") |
| 38 | log.Println(" / _____ | / _____ | /______ | __ __________ ") |
| 39 | log.Println(" / /____/ / / /____/ / _______/ / / / / __ __ / ") |
| 40 | log.Println("/________/ /________/ /________/ /_/ /_/ /_/ /_/ ") |
| 41 | } |
| 42 | |
Matteo Scandolo | 4549d3f | 2018-10-19 12:48:20 -0700 | [diff] [blame^] | 43 | func getOptions() (uint32, string, uint32, uint32, uint32, int, int, string, int, core.Mode) { |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 44 | 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 Scandolo | 4549d3f | 2018-10-19 12:48:20 -0700 | [diff] [blame^] | 52 | delay := flag.Int("delay", 1, "Delay between ONU events") |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 53 | mode := core.DEFAULT |
Keita NISHIMOTO | d771cd1 | 2018-06-07 08:37:24 +0900 | [diff] [blame] | 54 | flag.Parse() |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 55 | 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 Scandolo | 4549d3f | 2018-10-19 12:48:20 -0700 | [diff] [blame^] | 63 | return uint32(*oltid), address, port, uint32(*nintfs), uint32(*nonus), *aaawait, *dhcpwait, *dhcpservip, *delay, mode |
Keita NISHIMOTO | d771cd1 | 2018-06-07 08:37:24 +0900 | [diff] [blame] | 64 | } |
| 65 | |
Keita NISHIMOTO | d771cd1 | 2018-06-07 08:37:24 +0900 | [diff] [blame] | 66 | func main() { |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 67 | // CLI Shows up |
Keita NISHIMOTO | d771cd1 | 2018-06-07 08:37:24 +0900 | [diff] [blame] | 68 | printBanner() |
Matteo Scandolo | 4549d3f | 2018-10-19 12:48:20 -0700 | [diff] [blame^] | 69 | oltid, ip, port, npon, nonus, aaawait, dhcpwait, dhcpservip, delay, mode := getOptions() |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 70 | 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 NISHIMOTO | d771cd1 | 2018-06-07 08:37:24 +0900 | [diff] [blame] | 73 | var wg sync.WaitGroup |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 74 | |
| 75 | addressport := ip + ":" + strconv.Itoa(int(port)) |
| 76 | endchan := make(chan int, 1) |
| 77 | listener, gserver, err := core.CreateGrpcServer(oltid, npon, nonus, addressport) |
Matteo Scandolo | 4549d3f | 2018-10-19 12:48:20 -0700 | [diff] [blame^] | 78 | server := core.Create(oltid, npon, nonus, aaawait, dhcpwait, dhcpservip, delay, gserver, mode, endchan) |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 79 | if err != nil { |
| 80 | log.Println(err) |
Keita NISHIMOTO | d771cd1 | 2018-06-07 08:37:24 +0900 | [diff] [blame] | 81 | } |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 82 | 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 NISHIMOTO | d771cd1 | 2018-06-07 08:37:24 +0900 | [diff] [blame] | 100 | wg.Wait() |
Keita NISHIMOTO | 3b8b9c0 | 2018-10-09 09:40:01 +0900 | [diff] [blame] | 101 | time.Sleep(5 * time.Second) |
| 102 | log.Println("Reach to the end line") |
Keita NISHIMOTO | d771cd1 | 2018-06-07 08:37:24 +0900 | [diff] [blame] | 103 | } |