blob: 3dff4c4ed456ff5f0b10f9b28a6114ce29ceb720 [file] [log] [blame]
Pragya Aryabd731ec2020-02-11 16:38:17 +05301/*
Joey Armstrong2c039362024-02-04 18:51:52 -05002 * Portions Copyright 2019-2024 Open Networking Foundation (ONF) and the ONF Contributors
Pragya Aryabd731ec2020-02-11 16:38:17 +05303 * 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
18package commands
19
20import (
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
30type PonPoweronAllOnus struct {
31 Args struct {
32 IntfID OltInterfaceID
33 } `positional-args:"yes" required:"yes"`
34}
35
36type PonShutdownAllOnus struct {
37 Args struct {
38 IntfID OltInterfaceID
39 } `positional-args:"yes" required:"yes"`
40}
41
42type PONOptions struct {
43 PoweronAllOnus PonPoweronAllOnus `command:"poweronAllONUs"`
44 ShutdownAllOnus PonShutdownAllOnus `command:"shutdownAllONUs"`
45}
46
47func RegisterPonCommands(parser *flags.Parser) {
Shrey Baid688b4242020-07-10 20:40:10 +053048 _, _ = parser.AddCommand("pon", "PON Commands", "Commands to query and manipulate the PON port", &PONOptions{})
Pragya Aryabd731ec2020-02-11 16:38:17 +053049}
50
51func (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
72func (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}