Pragya Arya | bd731ec | 2020-02-11 16:38:17 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Portions copyright 2019-present Open Networking Foundation |
| 3 | * Original copyright 2019-present Ciena Corporation |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | package commands |
| 19 | |
| 20 | import ( |
| 21 | "context" |
| 22 | "fmt" |
| 23 | |
| 24 | "github.com/jessevdk/go-flags" |
| 25 | pb "github.com/opencord/bbsim/api/bbsim" |
| 26 | "github.com/opencord/bbsim/internal/bbsimctl/config" |
| 27 | log "github.com/sirupsen/logrus" |
| 28 | ) |
| 29 | |
| 30 | type PonPoweronAllOnus struct { |
| 31 | Args struct { |
| 32 | IntfID OltInterfaceID |
| 33 | } `positional-args:"yes" required:"yes"` |
| 34 | } |
| 35 | |
| 36 | type PonShutdownAllOnus struct { |
| 37 | Args struct { |
| 38 | IntfID OltInterfaceID |
| 39 | } `positional-args:"yes" required:"yes"` |
| 40 | } |
| 41 | |
| 42 | type PONOptions struct { |
| 43 | PoweronAllOnus PonPoweronAllOnus `command:"poweronAllONUs"` |
| 44 | ShutdownAllOnus PonShutdownAllOnus `command:"shutdownAllONUs"` |
| 45 | } |
| 46 | |
| 47 | func RegisterPonCommands(parser *flags.Parser) { |
| 48 | parser.AddCommand("pon", "PON Commands", "Commands to query and manipulate the PON port", &PONOptions{}) |
| 49 | } |
| 50 | |
| 51 | func (pon *PonPoweronAllOnus) Execute(args []string) error { |
| 52 | client, conn := connect() |
| 53 | defer conn.Close() |
| 54 | |
| 55 | ctx, cancel := context.WithTimeout(context.Background(), config.GlobalConfig.Grpc.Timeout) |
| 56 | defer cancel() |
| 57 | |
| 58 | req := pb.PONRequest{ |
| 59 | PonPortId: uint32(pon.Args.IntfID), |
| 60 | } |
| 61 | |
| 62 | res, err := client.PoweronONUsOnPON(ctx, &req) |
| 63 | if err != nil { |
| 64 | log.Errorf("Cannot poweron all ONUs on PON port: %v", err) |
| 65 | return err |
| 66 | } |
| 67 | |
| 68 | fmt.Println(fmt.Sprintf("[Status: %d] %s", res.StatusCode, res.Message)) |
| 69 | return nil |
| 70 | } |
| 71 | |
| 72 | func (pon *PonShutdownAllOnus) Execute(args []string) error { |
| 73 | client, conn := connect() |
| 74 | defer conn.Close() |
| 75 | |
| 76 | ctx, cancel := context.WithTimeout(context.Background(), config.GlobalConfig.Grpc.Timeout) |
| 77 | defer cancel() |
| 78 | |
| 79 | req := pb.PONRequest{ |
| 80 | PonPortId: uint32(pon.Args.IntfID), |
| 81 | } |
| 82 | |
| 83 | res, err := client.ShutdownONUsOnPON(ctx, &req) |
| 84 | if err != nil { |
| 85 | log.Errorf("Cannot shutdown all ONUs on PON port: %v", err) |
| 86 | return err |
| 87 | } |
| 88 | |
| 89 | fmt.Println(fmt.Sprintf("[Status: %d] %s", res.StatusCode, res.Message)) |
| 90 | return nil |
| 91 | } |