Matteo Scandolo | 8df63df | 2019-09-12 10:34:32 -0700 | [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" |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 22 | "fmt" |
Anand S Katti | 0954135 | 2020-01-29 15:54:01 +0530 | [diff] [blame] | 23 | "os" |
| 24 | "strconv" |
| 25 | "strings" |
| 26 | |
Matteo Scandolo | 8df63df | 2019-09-12 10:34:32 -0700 | [diff] [blame] | 27 | "github.com/jessevdk/go-flags" |
Anand S Katti | 0954135 | 2020-01-29 15:54:01 +0530 | [diff] [blame] | 28 | "github.com/olekukonko/tablewriter" |
Matteo Scandolo | 8df63df | 2019-09-12 10:34:32 -0700 | [diff] [blame] | 29 | pb "github.com/opencord/bbsim/api/bbsim" |
| 30 | "github.com/opencord/bbsim/internal/bbsimctl/config" |
| 31 | "github.com/opencord/cordctl/pkg/format" |
| 32 | log "github.com/sirupsen/logrus" |
| 33 | "google.golang.org/grpc" |
Matteo Scandolo | 8df63df | 2019-09-12 10:34:32 -0700 | [diff] [blame] | 34 | ) |
| 35 | |
| 36 | const ( |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 37 | DEFAULT_ONU_DEVICE_HEADER_FORMAT = "table{{ .PonPortID }}\t{{ .ID }}\t{{ .PortNo }}\t{{ .SerialNumber }}\t{{ .OperState }}\t{{ .InternalState }}" |
| 38 | DEFAULT_ONU_DEVICE_HEADER_FORMAT_WITH_SERVICES = "table{{ .PonPortID }}\t{{ .ID }}\t{{ .PortNo }}\t{{ .SerialNumber }}\t{{ .OperState }}\t{{ .InternalState }}\t{{ .Services }}" |
Matteo Scandolo | 8df63df | 2019-09-12 10:34:32 -0700 | [diff] [blame] | 39 | ) |
| 40 | |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 41 | type OnuSnString string |
Arjun E K | 57a7fcb | 2020-01-30 06:44:45 +0000 | [diff] [blame] | 42 | type IgmpSubAction string |
| 43 | |
| 44 | const IgmpJoinKey string = "join" |
| 45 | const IgmpLeaveKey string = "leave" |
Arjun E K | dd443f0 | 2020-02-07 15:24:01 +0000 | [diff] [blame] | 46 | const IgmpJoinKeyV3 string = "joinv3" |
Arjun E K | 57a7fcb | 2020-01-30 06:44:45 +0000 | [diff] [blame] | 47 | |
Matteo Scandolo | 618a658 | 2020-09-09 12:21:29 -0700 | [diff] [blame] | 48 | var IgmpAllowedActions = []string{IgmpJoinKey, IgmpLeaveKey, IgmpJoinKeyV3} |
| 49 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 50 | type ONUList struct { |
| 51 | Verbose bool `short:"v" long:"verbose" description:"Print all the informations we have about ONUs"` |
| 52 | } |
Matteo Scandolo | d2ca2c7 | 2019-10-04 16:50:22 -0700 | [diff] [blame] | 53 | |
| 54 | type ONUGet struct { |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 55 | Verbose bool `short:"v" long:"verbose" description:"Print all the informations we have about ONUs"` |
| 56 | Args struct { |
| 57 | OnuSn OnuSnString |
| 58 | } `positional-args:"yes" required:"yes"` |
| 59 | } |
| 60 | |
| 61 | type ONUServices struct { |
Matteo Scandolo | d2ca2c7 | 2019-10-04 16:50:22 -0700 | [diff] [blame] | 62 | Args struct { |
| 63 | OnuSn OnuSnString |
| 64 | } `positional-args:"yes" required:"yes"` |
| 65 | } |
| 66 | |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 67 | type ONUShutDown struct { |
| 68 | Args struct { |
| 69 | OnuSn OnuSnString |
| 70 | } `positional-args:"yes" required:"yes"` |
Matteo Scandolo | 8df63df | 2019-09-12 10:34:32 -0700 | [diff] [blame] | 71 | } |
| 72 | |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 73 | type ONUPowerOn struct { |
| 74 | Args struct { |
| 75 | OnuSn OnuSnString |
| 76 | } `positional-args:"yes" required:"yes"` |
| 77 | } |
| 78 | |
Matteo Scandolo | e383d5d | 2019-10-25 14:47:27 -0700 | [diff] [blame] | 79 | type ONUEapolRestart struct { |
| 80 | Args struct { |
| 81 | OnuSn OnuSnString |
| 82 | } `positional-args:"yes" required:"yes"` |
| 83 | } |
| 84 | |
| 85 | type ONUDhcpRestart struct { |
| 86 | Args struct { |
| 87 | OnuSn OnuSnString |
| 88 | } `positional-args:"yes" required:"yes"` |
| 89 | } |
| 90 | |
Arjun E K | 57a7fcb | 2020-01-30 06:44:45 +0000 | [diff] [blame] | 91 | type ONUIgmp struct { |
| 92 | Args struct { |
| 93 | OnuSn OnuSnString |
| 94 | SubAction IgmpSubAction |
| 95 | } `positional-args:"yes" required:"yes"` |
| 96 | } |
| 97 | |
Pragya Arya | 8bdb453 | 2020-03-02 17:08:09 +0530 | [diff] [blame] | 98 | type ONUTrafficSchedulers struct { |
| 99 | Args struct { |
| 100 | OnuSn OnuSnString |
| 101 | } `positional-args:"yes" required:"yes"` |
| 102 | } |
| 103 | |
| 104 | type ONUFlows struct { |
| 105 | Args struct { |
| 106 | OnuSn OnuSnString |
| 107 | } `positional-args:"yes" required:"yes"` |
| 108 | } |
| 109 | |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 110 | type ONUOptions struct { |
Anand S Katti | 0954135 | 2020-01-29 15:54:01 +0530 | [diff] [blame] | 111 | List ONUList `command:"list"` |
| 112 | Get ONUGet `command:"get"` |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 113 | Services ONUServices `command:"services"` |
Anand S Katti | 0954135 | 2020-01-29 15:54:01 +0530 | [diff] [blame] | 114 | ShutDown ONUShutDown `command:"shutdown"` |
| 115 | PowerOn ONUPowerOn `command:"poweron"` |
| 116 | RestartEapol ONUEapolRestart `command:"auth_restart"` |
| 117 | RestartDchp ONUDhcpRestart `command:"dhcp_restart"` |
| 118 | Igmp ONUIgmp `command:"igmp"` |
| 119 | TrafficSchedulers ONUTrafficSchedulers `command:"traffic_schedulers"` |
Anand S Katti | 86552f9 | 2020-03-03 21:56:32 +0530 | [diff] [blame] | 120 | Alarms AlarmOptions `command:"alarms"` |
Pragya Arya | 8bdb453 | 2020-03-02 17:08:09 +0530 | [diff] [blame] | 121 | Flows ONUFlows `command:"flows"` |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | func RegisterONUCommands(parser *flags.Parser) { |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 125 | _, _ = parser.AddCommand("onu", "ONU Commands", "Commands to query and manipulate ONU devices", &ONUOptions{}) |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | func connect() (pb.BBSimClient, *grpc.ClientConn) { |
Matteo Scandolo | 8df63df | 2019-09-12 10:34:32 -0700 | [diff] [blame] | 129 | conn, err := grpc.Dial(config.GlobalConfig.Server, grpc.WithInsecure()) |
| 130 | |
| 131 | if err != nil { |
Matteo Scandolo | 2bf742a | 2019-10-01 11:33:34 -0700 | [diff] [blame] | 132 | log.Fatalf("did not connect: %v", err) |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 133 | return nil, conn |
Matteo Scandolo | 8df63df | 2019-09-12 10:34:32 -0700 | [diff] [blame] | 134 | } |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 135 | return pb.NewBBSimClient(conn), conn |
| 136 | } |
| 137 | |
| 138 | func getONUs() *pb.ONUs { |
| 139 | |
| 140 | client, conn := connect() |
Matteo Scandolo | 8df63df | 2019-09-12 10:34:32 -0700 | [diff] [blame] | 141 | defer conn.Close() |
Matteo Scandolo | 8df63df | 2019-09-12 10:34:32 -0700 | [diff] [blame] | 142 | |
| 143 | // Contact the server and print out its response. |
Matteo Scandolo | 8df63df | 2019-09-12 10:34:32 -0700 | [diff] [blame] | 144 | ctx, cancel := context.WithTimeout(context.Background(), config.GlobalConfig.Grpc.Timeout) |
| 145 | defer cancel() |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 146 | |
| 147 | onus, err := client.GetONUs(ctx, &pb.Empty{}) |
Matteo Scandolo | 8df63df | 2019-09-12 10:34:32 -0700 | [diff] [blame] | 148 | if err != nil { |
Matteo Scandolo | 2bf742a | 2019-10-01 11:33:34 -0700 | [diff] [blame] | 149 | log.Fatalf("could not get OLT: %v", err) |
Matteo Scandolo | 8df63df | 2019-09-12 10:34:32 -0700 | [diff] [blame] | 150 | return nil |
| 151 | } |
| 152 | return onus |
| 153 | } |
| 154 | |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 155 | func (options *ONUList) Execute(args []string) error { |
Matteo Scandolo | 8df63df | 2019-09-12 10:34:32 -0700 | [diff] [blame] | 156 | onus := getONUs() |
| 157 | |
| 158 | // print out |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 159 | var tableFormat format.Format |
| 160 | if options.Verbose { |
| 161 | tableFormat = format.Format(DEFAULT_ONU_DEVICE_HEADER_FORMAT_WITH_SERVICES) |
| 162 | } else { |
| 163 | tableFormat = format.Format(DEFAULT_ONU_DEVICE_HEADER_FORMAT) |
| 164 | } |
Matteo Scandolo | 8df63df | 2019-09-12 10:34:32 -0700 | [diff] [blame] | 165 | if err := tableFormat.Execute(os.Stdout, true, onus.Items); err != nil { |
| 166 | log.Fatalf("Error while formatting ONUs table: %s", err) |
| 167 | } |
| 168 | |
| 169 | return nil |
| 170 | } |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 171 | |
Matteo Scandolo | d2ca2c7 | 2019-10-04 16:50:22 -0700 | [diff] [blame] | 172 | func (options *ONUGet) Execute(args []string) error { |
| 173 | client, conn := connect() |
| 174 | defer conn.Close() |
| 175 | |
| 176 | ctx, cancel := context.WithTimeout(context.Background(), config.GlobalConfig.Grpc.Timeout) |
| 177 | defer cancel() |
| 178 | req := pb.ONURequest{ |
| 179 | SerialNumber: string(options.Args.OnuSn), |
| 180 | } |
| 181 | res, err := client.GetONU(ctx, &req) |
| 182 | |
| 183 | if err != nil { |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 184 | log.Fatalf("Cannot not get ONU %s: %v", options.Args.OnuSn, err) |
Matteo Scandolo | d2ca2c7 | 2019-10-04 16:50:22 -0700 | [diff] [blame] | 185 | return err |
| 186 | } |
| 187 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 188 | var tableFormat format.Format |
| 189 | if options.Verbose { |
| 190 | tableFormat = format.Format(DEFAULT_ONU_DEVICE_HEADER_FORMAT_WITH_SERVICES) |
| 191 | } else { |
| 192 | tableFormat = format.Format(DEFAULT_ONU_DEVICE_HEADER_FORMAT) |
| 193 | } |
Matteo Scandolo | d2ca2c7 | 2019-10-04 16:50:22 -0700 | [diff] [blame] | 194 | if err := tableFormat.Execute(os.Stdout, true, []*pb.ONU{res}); err != nil { |
| 195 | log.Fatalf("Error while formatting ONUs table: %s", err) |
| 196 | } |
| 197 | |
| 198 | return nil |
| 199 | } |
| 200 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 201 | func (options *ONUServices) Execute(args []string) error { |
| 202 | |
| 203 | client, conn := connect() |
| 204 | defer conn.Close() |
| 205 | |
| 206 | ctx, cancel := context.WithTimeout(context.Background(), config.GlobalConfig.Grpc.Timeout) |
| 207 | defer cancel() |
| 208 | req := pb.ONURequest{ |
| 209 | SerialNumber: string(options.Args.OnuSn), |
| 210 | } |
| 211 | res, err := client.GetOnuServices(ctx, &req) |
| 212 | |
| 213 | if err != nil { |
| 214 | log.Fatalf("Cannot not get services for ONU %s: %v", options.Args.OnuSn, err) |
| 215 | return err |
| 216 | } |
| 217 | |
| 218 | tableFormat := format.Format(DEFAULT_SERVICE_HEADER_FORMAT) |
| 219 | if err := tableFormat.Execute(os.Stdout, true, res.Items); err != nil { |
| 220 | log.Fatalf("Error while formatting Services table: %s", err) |
| 221 | } |
| 222 | |
| 223 | return nil |
| 224 | } |
| 225 | |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 226 | func (options *ONUShutDown) Execute(args []string) error { |
| 227 | |
| 228 | client, conn := connect() |
| 229 | defer conn.Close() |
| 230 | |
| 231 | ctx, cancel := context.WithTimeout(context.Background(), config.GlobalConfig.Grpc.Timeout) |
| 232 | defer cancel() |
| 233 | req := pb.ONURequest{ |
| 234 | SerialNumber: string(options.Args.OnuSn), |
| 235 | } |
| 236 | res, err := client.ShutdownONU(ctx, &req) |
| 237 | |
| 238 | if err != nil { |
Matteo Scandolo | e383d5d | 2019-10-25 14:47:27 -0700 | [diff] [blame] | 239 | log.Fatalf("Cannot shutdown ONU %s: %v", options.Args.OnuSn, err) |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 240 | return err |
| 241 | } |
| 242 | |
| 243 | fmt.Println(fmt.Sprintf("[Status: %d] %s", res.StatusCode, res.Message)) |
| 244 | |
| 245 | return nil |
| 246 | } |
| 247 | |
| 248 | func (options *ONUPowerOn) Execute(args []string) error { |
| 249 | client, conn := connect() |
| 250 | defer conn.Close() |
| 251 | |
| 252 | ctx, cancel := context.WithTimeout(context.Background(), config.GlobalConfig.Grpc.Timeout) |
| 253 | defer cancel() |
| 254 | req := pb.ONURequest{ |
| 255 | SerialNumber: string(options.Args.OnuSn), |
| 256 | } |
| 257 | res, err := client.PoweronONU(ctx, &req) |
| 258 | |
| 259 | if err != nil { |
Matteo Scandolo | e383d5d | 2019-10-25 14:47:27 -0700 | [diff] [blame] | 260 | log.Fatalf("Cannot power on ONU %s: %v", options.Args.OnuSn, err) |
| 261 | return err |
| 262 | } |
| 263 | |
| 264 | fmt.Println(fmt.Sprintf("[Status: %d] %s", res.StatusCode, res.Message)) |
| 265 | |
| 266 | return nil |
| 267 | } |
| 268 | |
| 269 | func (options *ONUEapolRestart) Execute(args []string) error { |
| 270 | client, conn := connect() |
| 271 | defer conn.Close() |
| 272 | |
| 273 | ctx, cancel := context.WithTimeout(context.Background(), config.GlobalConfig.Grpc.Timeout) |
| 274 | defer cancel() |
| 275 | req := pb.ONURequest{ |
| 276 | SerialNumber: string(options.Args.OnuSn), |
| 277 | } |
| 278 | res, err := client.RestartEapol(ctx, &req) |
| 279 | |
| 280 | if err != nil { |
| 281 | log.Fatalf("Cannot restart EAPOL for ONU %s: %v", options.Args.OnuSn, err) |
| 282 | return err |
| 283 | } |
| 284 | |
| 285 | fmt.Println(fmt.Sprintf("[Status: %d] %s", res.StatusCode, res.Message)) |
| 286 | |
| 287 | return nil |
| 288 | } |
| 289 | |
| 290 | func (options *ONUDhcpRestart) Execute(args []string) error { |
| 291 | client, conn := connect() |
| 292 | defer conn.Close() |
| 293 | |
| 294 | ctx, cancel := context.WithTimeout(context.Background(), config.GlobalConfig.Grpc.Timeout) |
| 295 | defer cancel() |
| 296 | req := pb.ONURequest{ |
| 297 | SerialNumber: string(options.Args.OnuSn), |
| 298 | } |
| 299 | res, err := client.RestartDhcp(ctx, &req) |
| 300 | |
| 301 | if err != nil { |
| 302 | log.Fatalf("Cannot restart DHCP for ONU %s: %v", options.Args.OnuSn, err) |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 303 | return err |
| 304 | } |
| 305 | |
| 306 | fmt.Println(fmt.Sprintf("[Status: %d] %s", res.StatusCode, res.Message)) |
| 307 | |
| 308 | return nil |
| 309 | } |
| 310 | |
Arjun E K | 57a7fcb | 2020-01-30 06:44:45 +0000 | [diff] [blame] | 311 | func (options *ONUIgmp) Execute(args []string) error { |
| 312 | client, conn := connect() |
| 313 | defer conn.Close() |
| 314 | |
| 315 | ctx, cancel := context.WithTimeout(context.Background(), config.GlobalConfig.Grpc.Timeout) |
| 316 | defer cancel() |
| 317 | |
| 318 | req := pb.ONURequest{ |
| 319 | SerialNumber: string(options.Args.OnuSn), |
| 320 | } |
| 321 | |
| 322 | var subActionVal pb.SubActionTypes |
| 323 | if string(options.Args.SubAction) == IgmpJoinKey { |
| 324 | subActionVal = pb.SubActionTypes_JOIN |
| 325 | } else if string(options.Args.SubAction) == IgmpLeaveKey { |
| 326 | subActionVal = pb.SubActionTypes_LEAVE |
Anand S Katti | 0954135 | 2020-01-29 15:54:01 +0530 | [diff] [blame] | 327 | } else if string(options.Args.SubAction) == IgmpJoinKeyV3 { |
| 328 | subActionVal = pb.SubActionTypes_JOINV3 |
| 329 | } |
Arjun E K | 57a7fcb | 2020-01-30 06:44:45 +0000 | [diff] [blame] | 330 | |
| 331 | igmpReq := pb.IgmpRequest{ |
| 332 | OnuReq: &req, |
| 333 | SubActionVal: subActionVal, |
| 334 | } |
| 335 | res, err := client.GetONU(ctx, igmpReq.OnuReq) |
| 336 | if err != nil { |
| 337 | log.WithFields(log.Fields{ |
| 338 | "SerialNumber": options.Args.OnuSn, |
| 339 | }).Errorf("Cannot not get details on ONU error: %v", err) |
| 340 | } |
| 341 | log.WithFields(log.Fields{ |
| 342 | "SerialNumber": igmpReq.OnuReq.SerialNumber, |
| 343 | }).Debugf("ONU has indentified : %s", res) |
| 344 | |
| 345 | igmpRes, igmpErr := client.ChangeIgmpState(ctx, &igmpReq) |
| 346 | if igmpErr != nil { |
| 347 | log.WithFields(log.Fields{ |
| 348 | "SubAction": options.Args.SubAction, |
| 349 | }).Errorf("Could not process Action: error: %v", igmpErr) |
| 350 | } else { |
| 351 | log.WithFields(log.Fields{ |
| 352 | "SubAction": options.Args.SubAction, |
| 353 | }).Debugf("igmp state has been changed with response: %s", |
| 354 | igmpRes.Message) |
| 355 | } |
| 356 | |
| 357 | return nil |
| 358 | } |
| 359 | |
Pragya Arya | 8bdb453 | 2020-03-02 17:08:09 +0530 | [diff] [blame] | 360 | func (options *ONUFlows) Execute(args []string) error { |
| 361 | client, conn := connect() |
| 362 | defer conn.Close() |
| 363 | |
| 364 | ctx, cancel := context.WithTimeout(context.Background(), config.GlobalConfig.Grpc.Timeout) |
| 365 | defer cancel() |
| 366 | req := pb.ONURequest{ |
| 367 | SerialNumber: string(options.Args.OnuSn), |
| 368 | } |
| 369 | res, err := client.GetFlows(ctx, &req) |
| 370 | if err != nil { |
| 371 | log.Errorf("Cannot get flows for ONU %s: %v", options.Args.OnuSn, err) |
| 372 | return err |
| 373 | } |
| 374 | |
| 375 | if res.Flows == nil { |
| 376 | fmt.Println(fmt.Sprintf("ONU %s has no flows", options.Args.OnuSn)) |
| 377 | return nil |
| 378 | } |
| 379 | |
| 380 | flowHeader := []string{ |
| 381 | "access_intf_id", |
| 382 | "onu_id", |
| 383 | "uni_id", |
| 384 | "flow_id", |
| 385 | "flow_type", |
| 386 | "eth_type", |
| 387 | "alloc_id", |
| 388 | "network_intf_id", |
| 389 | "gemport_id", |
| 390 | "classifier", |
| 391 | "action", |
| 392 | "priority", |
| 393 | "cookie", |
| 394 | "port_no", |
| 395 | } |
| 396 | |
| 397 | tableFlow := tablewriter.NewWriter(os.Stdout) |
| 398 | tableFlow.SetRowLine(true) |
| 399 | fmt.Fprintf(os.Stdout, "ONU Flows:\n") |
| 400 | tableFlow.SetHeader(flowHeader) |
| 401 | |
| 402 | for _, flow := range res.Flows { |
| 403 | flowInfo := []string{} |
| 404 | flowInfo = append(flowInfo, |
| 405 | strconv.Itoa(int(flow.AccessIntfId)), |
| 406 | strconv.Itoa(int(flow.OnuId)), |
| 407 | strconv.Itoa(int(flow.UniId)), |
| 408 | strconv.Itoa(int(flow.FlowId)), |
| 409 | flow.FlowType, |
| 410 | fmt.Sprintf("%x", flow.Classifier.EthType), |
| 411 | strconv.Itoa(int(flow.AllocId)), |
| 412 | strconv.Itoa(int(flow.NetworkIntfId)), |
| 413 | strconv.Itoa(int(flow.GemportId)), |
| 414 | flow.Classifier.String(), |
| 415 | flow.Action.String(), |
| 416 | strconv.Itoa(int(flow.Priority)), |
| 417 | strconv.Itoa(int(flow.Cookie)), |
| 418 | strconv.Itoa(int(flow.PortNo)), |
| 419 | ) |
| 420 | tableFlow.Append(flowInfo) |
| 421 | } |
| 422 | tableFlow.Render() |
| 423 | tableFlow.SetNewLine("") |
| 424 | return nil |
| 425 | } |
| 426 | |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 427 | func (onuSn *OnuSnString) Complete(match string) []flags.Completion { |
| 428 | client, conn := connect() |
| 429 | defer conn.Close() |
| 430 | |
| 431 | ctx, cancel := context.WithTimeout(context.Background(), config.GlobalConfig.Grpc.Timeout) |
| 432 | defer cancel() |
| 433 | |
| 434 | onus, err := client.GetONUs(ctx, &pb.Empty{}) |
| 435 | if err != nil { |
Matteo Scandolo | 86e8ce6 | 2019-10-11 12:03:10 -0700 | [diff] [blame] | 436 | log.Fatalf("could not get ONUs: %v", err) |
Matteo Scandolo | 10f965c | 2019-09-24 10:40:46 -0700 | [diff] [blame] | 437 | return nil |
| 438 | } |
| 439 | |
| 440 | list := make([]flags.Completion, 0) |
| 441 | for _, k := range onus.Items { |
| 442 | if strings.HasPrefix(k.SerialNumber, match) { |
| 443 | list = append(list, flags.Completion{Item: k.SerialNumber}) |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | return list |
| 448 | } |
Anand S Katti | 0954135 | 2020-01-29 15:54:01 +0530 | [diff] [blame] | 449 | |
Matteo Scandolo | 618a658 | 2020-09-09 12:21:29 -0700 | [diff] [blame] | 450 | func (onuSn *IgmpSubAction) Complete(match string) []flags.Completion { |
| 451 | list := make([]flags.Completion, 0) |
| 452 | for _, k := range IgmpAllowedActions { |
| 453 | if strings.HasPrefix(k, match) { |
| 454 | list = append(list, flags.Completion{Item: k}) |
| 455 | } |
| 456 | } |
| 457 | return list |
| 458 | } |
| 459 | |
Anand S Katti | 0954135 | 2020-01-29 15:54:01 +0530 | [diff] [blame] | 460 | func (options *ONUTrafficSchedulers) Execute(args []string) error { |
| 461 | client, conn := connect() |
| 462 | defer conn.Close() |
| 463 | |
| 464 | ctx, cancel := context.WithTimeout(context.Background(), config.GlobalConfig.Grpc.Timeout) |
| 465 | defer cancel() |
| 466 | req := pb.ONURequest{ |
| 467 | SerialNumber: string(options.Args.OnuSn), |
| 468 | } |
| 469 | res, err := client.GetOnuTrafficSchedulers(ctx, &req) |
| 470 | if err != nil { |
| 471 | log.Fatalf("Cannot get traffic schedulers for ONU %s: %v", options.Args.OnuSn, err) |
| 472 | return err |
| 473 | } |
| 474 | |
| 475 | if res.TraffSchedulers == nil { |
| 476 | log.Fatalf("Cannot get traffic schedulers for ONU: %s (unavailable)", options.Args.OnuSn) |
| 477 | return nil |
| 478 | } |
| 479 | |
| 480 | SchedulerHeader := []string{"Direction", |
| 481 | "AllocId", |
| 482 | "Scheduler.Direction", |
| 483 | "Scheduler.AdditionalBw", |
| 484 | "Scheduler.Priority", |
| 485 | "Scheduler.Weight", |
| 486 | "Scheduler.SchedPolicy", |
| 487 | } |
| 488 | |
| 489 | ShapingInfoHeader := []string{"InferredAdditionBwIndication", |
| 490 | "Cbs", |
| 491 | "Cir", |
| 492 | "Gir", |
| 493 | "Pbs", |
| 494 | "Pir", |
| 495 | } |
| 496 | |
| 497 | SchedulerVals := []string{} |
| 498 | ShapingInfoVals := []string{} |
| 499 | for _, v := range res.TraffSchedulers.TrafficScheds { |
| 500 | SchedulerVals = append(SchedulerVals, |
| 501 | v.GetDirection().String(), |
| 502 | strconv.Itoa(int(v.GetAllocId())), |
| 503 | v.Scheduler.GetDirection().String(), |
| 504 | v.Scheduler.GetAdditionalBw().String(), |
| 505 | strconv.Itoa(int(v.Scheduler.GetPriority())), |
| 506 | strconv.Itoa(int(v.Scheduler.GetWeight())), |
| 507 | v.GetScheduler().GetSchedPolicy().String(), |
| 508 | ) |
| 509 | |
| 510 | ShapingInfoVals = append(ShapingInfoVals, |
| 511 | v.TrafficShapingInfo.GetAddBwInd().String(), |
| 512 | strconv.Itoa(int(v.TrafficShapingInfo.GetCbs())), |
| 513 | strconv.Itoa(int(v.TrafficShapingInfo.GetCir())), |
| 514 | strconv.Itoa(int(v.TrafficShapingInfo.GetGir())), |
| 515 | strconv.Itoa(int(v.TrafficShapingInfo.GetPbs())), |
| 516 | strconv.Itoa(int(v.TrafficShapingInfo.GetPir())), |
| 517 | ) |
| 518 | } |
| 519 | |
| 520 | fmt.Fprintf(os.Stdout, "OnuId: %d \n", int(res.TraffSchedulers.OnuId)) |
| 521 | fmt.Fprintf(os.Stdout, "IntfId: %d \n", int(res.TraffSchedulers.IntfId)) |
| 522 | fmt.Fprintf(os.Stdout, "UniId: %d \n", int(res.TraffSchedulers.UniId)) |
| 523 | fmt.Fprintf(os.Stdout, "OnuPortNo: %d \n", int(res.TraffSchedulers.PortNo)) |
| 524 | |
| 525 | tableSched := tablewriter.NewWriter(os.Stdout) |
| 526 | tableSched.SetRowLine(true) |
| 527 | fmt.Fprintf(os.Stdout, "Traffic Schedulers Info:\n") |
| 528 | tableSched.SetHeader(SchedulerHeader) |
| 529 | tableSched.Append(SchedulerVals) |
| 530 | tableSched.Render() |
| 531 | tableSched.SetNewLine("") |
| 532 | |
| 533 | tableShap := tablewriter.NewWriter(os.Stdout) |
| 534 | tableShap.SetRowLine(true) |
| 535 | fmt.Fprintf(os.Stdout, "Traffic Shaping Info:\n") |
| 536 | tableShap.SetHeader(ShapingInfoHeader) |
| 537 | tableShap.Append(ShapingInfoVals) |
| 538 | tableShap.Render() |
| 539 | |
| 540 | return nil |
| 541 | } |