blob: 80e5f0d47a829c9db48f1fa8318d5deff9c94bb2 [file] [log] [blame]
Matteo Scandolo8df63df2019-09-12 10:34:32 -07001/*
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
18package commands
19
20import (
21 "context"
Matteo Scandolo10f965c2019-09-24 10:40:46 -070022 "fmt"
Anand S Katti09541352020-01-29 15:54:01 +053023 "os"
24 "strconv"
25 "strings"
26
Matteo Scandolo8df63df2019-09-12 10:34:32 -070027 "github.com/jessevdk/go-flags"
Anand S Katti09541352020-01-29 15:54:01 +053028 "github.com/olekukonko/tablewriter"
Matteo Scandolo8df63df2019-09-12 10:34:32 -070029 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"
Matteo Scandolo8df63df2019-09-12 10:34:32 -070033)
34
35const (
Matteo Scandolo8a574812021-05-20 15:18:53 -070036 DEFAULT_ONU_DEVICE_HEADER_FORMAT = "table{{ .PonPortID }}\t{{ .ID }}\t{{ .SerialNumber }}\t{{ .OperState }}\t{{ .InternalState }}\t{{ .ImageSoftwareExpectedSections }}\t{{ .ImageSoftwareReceivedSections }}\t{{ .ActiveImageEntityId }}\t{{ .CommittedImageEntityId }}"
37 DEFAULT_ONU_DEVICE_HEADER_FORMAT_WITH_SERVICES = "table{{ .PonPortID }}\t{{ .ID }}\t{{ .SerialNumber }}\t{{ .OperState }}\t{{ .InternalState }}\t{{ .ImageSoftwareExpectedSections }}\t{{ .ImageSoftwareReceivedSections }}\t{{ .ActiveImageEntityId }}\t{{ .CommittedImageEntityId }}\t{{ .Unis }}"
Matteo Scandolo8df63df2019-09-12 10:34:32 -070038)
39
Matteo Scandolo10f965c2019-09-24 10:40:46 -070040type OnuSnString string
Arjun E K57a7fcb2020-01-30 06:44:45 +000041type IgmpSubAction string
Onur Kalinagac9f9faca2021-01-21 14:04:34 +000042type GroupAddress string
Arjun E K57a7fcb2020-01-30 06:44:45 +000043
44const IgmpJoinKey string = "join"
45const IgmpLeaveKey string = "leave"
Arjun E Kdd443f02020-02-07 15:24:01 +000046const IgmpJoinKeyV3 string = "joinv3"
Arjun E K57a7fcb2020-01-30 06:44:45 +000047
Matteo Scandolo618a6582020-09-09 12:21:29 -070048var IgmpAllowedActions = []string{IgmpJoinKey, IgmpLeaveKey, IgmpJoinKeyV3}
49
Matteo Scandolo4a036262020-08-17 15:56:13 -070050type ONUList struct {
51 Verbose bool `short:"v" long:"verbose" description:"Print all the informations we have about ONUs"`
52}
Matteo Scandolod2ca2c72019-10-04 16:50:22 -070053
54type ONUGet struct {
Matteo Scandolo4a036262020-08-17 15:56:13 -070055 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
Matteo Scandoloef4e8f82021-05-17 11:20:49 -070061type ONUUnis struct {
Matteo Scandolo8a574812021-05-20 15:18:53 -070062 Verbose bool `short:"v" long:"verbose" description:"Print all the informations we have about UNIs"`
63 Args struct {
Matteo Scandoloef4e8f82021-05-17 11:20:49 -070064 OnuSn OnuSnString
65 } `positional-args:"yes" required:"yes"`
66}
67
Matteo Scandolo10f965c2019-09-24 10:40:46 -070068type ONUShutDown struct {
69 Args struct {
70 OnuSn OnuSnString
71 } `positional-args:"yes" required:"yes"`
Matteo Scandolo8df63df2019-09-12 10:34:32 -070072}
73
Matteo Scandolo10f965c2019-09-24 10:40:46 -070074type ONUPowerOn struct {
75 Args struct {
76 OnuSn OnuSnString
77 } `positional-args:"yes" required:"yes"`
78}
79
Matteo Scandoloe383d5d2019-10-25 14:47:27 -070080type ONUEapolRestart struct {
81 Args struct {
82 OnuSn OnuSnString
83 } `positional-args:"yes" required:"yes"`
84}
85
86type ONUDhcpRestart struct {
87 Args struct {
88 OnuSn OnuSnString
89 } `positional-args:"yes" required:"yes"`
90}
91
Arjun E K57a7fcb2020-01-30 06:44:45 +000092type ONUIgmp struct {
93 Args struct {
Onur Kalinagac9f9faca2021-01-21 14:04:34 +000094 OnuSn OnuSnString
95 SubAction IgmpSubAction
96 GroupAddress GroupAddress
Arjun E K57a7fcb2020-01-30 06:44:45 +000097 } `positional-args:"yes" required:"yes"`
98}
99
Pragya Arya8bdb4532020-03-02 17:08:09 +0530100type ONUTrafficSchedulers struct {
101 Args struct {
102 OnuSn OnuSnString
103 } `positional-args:"yes" required:"yes"`
104}
105
106type ONUFlows struct {
107 Args struct {
108 OnuSn OnuSnString
109 } `positional-args:"yes" required:"yes"`
110}
111
Nitin Subramanianb0a333a2021-07-08 15:01:41 -0700112type ONUServices struct {
113 Args struct {
114 OnuSn OnuSnString
115 } `positional-args:"yes"`
116}
117
Elia Battistonfe017662022-01-05 11:43:16 +0100118type ONUInvalidateMds struct {
119 Args struct {
120 OnuSn OnuSnString
121 } `positional-args:"yes" required:"yes"`
122}
123
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700124type ONUOptions struct {
Anand S Katti09541352020-01-29 15:54:01 +0530125 List ONUList `command:"list"`
126 Get ONUGet `command:"get"`
127 ShutDown ONUShutDown `command:"shutdown"`
128 PowerOn ONUPowerOn `command:"poweron"`
129 RestartEapol ONUEapolRestart `command:"auth_restart"`
130 RestartDchp ONUDhcpRestart `command:"dhcp_restart"`
131 Igmp ONUIgmp `command:"igmp"`
132 TrafficSchedulers ONUTrafficSchedulers `command:"traffic_schedulers"`
Anand S Katti86552f92020-03-03 21:56:32 +0530133 Alarms AlarmOptions `command:"alarms"`
Pragya Arya8bdb4532020-03-02 17:08:09 +0530134 Flows ONUFlows `command:"flows"`
Nitin Subramanianb0a333a2021-07-08 15:01:41 -0700135 Services ONUServices `command:"services"`
Elia Battistonfe017662022-01-05 11:43:16 +0100136 InvalidateMds ONUInvalidateMds `command:"invalidate_mds"`
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700137}
138
139func RegisterONUCommands(parser *flags.Parser) {
Shrey Baid688b4242020-07-10 20:40:10 +0530140 _, _ = parser.AddCommand("onu", "ONU Commands", "Commands to query and manipulate ONU devices", &ONUOptions{})
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700141}
142
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700143func getONUs() *pb.ONUs {
144
145 client, conn := connect()
Matteo Scandolo8df63df2019-09-12 10:34:32 -0700146 defer conn.Close()
Matteo Scandolo8df63df2019-09-12 10:34:32 -0700147
148 // Contact the server and print out its response.
Matteo Scandolo8df63df2019-09-12 10:34:32 -0700149 ctx, cancel := context.WithTimeout(context.Background(), config.GlobalConfig.Grpc.Timeout)
150 defer cancel()
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700151
152 onus, err := client.GetONUs(ctx, &pb.Empty{})
Matteo Scandolo8df63df2019-09-12 10:34:32 -0700153 if err != nil {
Matteo Scandolo2bf742a2019-10-01 11:33:34 -0700154 log.Fatalf("could not get OLT: %v", err)
Matteo Scandolo8df63df2019-09-12 10:34:32 -0700155 return nil
156 }
157 return onus
158}
159
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700160func (options *ONUList) Execute(args []string) error {
Matteo Scandolo8df63df2019-09-12 10:34:32 -0700161 onus := getONUs()
162
163 // print out
Matteo Scandolo4a036262020-08-17 15:56:13 -0700164 var tableFormat format.Format
165 if options.Verbose {
166 tableFormat = format.Format(DEFAULT_ONU_DEVICE_HEADER_FORMAT_WITH_SERVICES)
167 } else {
168 tableFormat = format.Format(DEFAULT_ONU_DEVICE_HEADER_FORMAT)
169 }
Matteo Scandolo8df63df2019-09-12 10:34:32 -0700170 if err := tableFormat.Execute(os.Stdout, true, onus.Items); err != nil {
171 log.Fatalf("Error while formatting ONUs table: %s", err)
172 }
173
174 return nil
175}
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700176
Matteo Scandolod2ca2c72019-10-04 16:50:22 -0700177func (options *ONUGet) Execute(args []string) error {
178 client, conn := connect()
179 defer conn.Close()
180
181 ctx, cancel := context.WithTimeout(context.Background(), config.GlobalConfig.Grpc.Timeout)
182 defer cancel()
183 req := pb.ONURequest{
184 SerialNumber: string(options.Args.OnuSn),
185 }
186 res, err := client.GetONU(ctx, &req)
187
188 if err != nil {
Matteo Scandolo4a036262020-08-17 15:56:13 -0700189 log.Fatalf("Cannot not get ONU %s: %v", options.Args.OnuSn, err)
Matteo Scandolod2ca2c72019-10-04 16:50:22 -0700190 return err
191 }
192
Matteo Scandolo4a036262020-08-17 15:56:13 -0700193 var tableFormat format.Format
194 if options.Verbose {
195 tableFormat = format.Format(DEFAULT_ONU_DEVICE_HEADER_FORMAT_WITH_SERVICES)
196 } else {
197 tableFormat = format.Format(DEFAULT_ONU_DEVICE_HEADER_FORMAT)
198 }
Matteo Scandolod2ca2c72019-10-04 16:50:22 -0700199 if err := tableFormat.Execute(os.Stdout, true, []*pb.ONU{res}); err != nil {
200 log.Fatalf("Error while formatting ONUs table: %s", err)
201 }
202
203 return nil
204}
205
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700206func (options *ONUShutDown) Execute(args []string) error {
207
208 client, conn := connect()
209 defer conn.Close()
210
211 ctx, cancel := context.WithTimeout(context.Background(), config.GlobalConfig.Grpc.Timeout)
212 defer cancel()
213 req := pb.ONURequest{
214 SerialNumber: string(options.Args.OnuSn),
215 }
216 res, err := client.ShutdownONU(ctx, &req)
217
218 if err != nil {
Matteo Scandoloe383d5d2019-10-25 14:47:27 -0700219 log.Fatalf("Cannot shutdown ONU %s: %v", options.Args.OnuSn, err)
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700220 return err
221 }
222
223 fmt.Println(fmt.Sprintf("[Status: %d] %s", res.StatusCode, res.Message))
224
225 return nil
226}
227
228func (options *ONUPowerOn) Execute(args []string) error {
229 client, conn := connect()
230 defer conn.Close()
231
232 ctx, cancel := context.WithTimeout(context.Background(), config.GlobalConfig.Grpc.Timeout)
233 defer cancel()
234 req := pb.ONURequest{
235 SerialNumber: string(options.Args.OnuSn),
236 }
237 res, err := client.PoweronONU(ctx, &req)
238
239 if err != nil {
Matteo Scandoloe383d5d2019-10-25 14:47:27 -0700240 log.Fatalf("Cannot power on ONU %s: %v", options.Args.OnuSn, err)
241 return err
242 }
243
244 fmt.Println(fmt.Sprintf("[Status: %d] %s", res.StatusCode, res.Message))
245
246 return nil
247}
248
249func (options *ONUEapolRestart) Execute(args []string) error {
250 client, conn := connect()
251 defer conn.Close()
252
253 ctx, cancel := context.WithTimeout(context.Background(), config.GlobalConfig.Grpc.Timeout)
254 defer cancel()
Nitin Subramanian150f1bb2021-08-02 12:04:05 -0700255 req := pb.UNIRequest{
256 OnuSerialNumber: string(options.Args.OnuSn),
257 UniID: "",
Matteo Scandoloe383d5d2019-10-25 14:47:27 -0700258 }
259 res, err := client.RestartEapol(ctx, &req)
260
261 if err != nil {
262 log.Fatalf("Cannot restart EAPOL for ONU %s: %v", options.Args.OnuSn, err)
263 return err
264 }
265
266 fmt.Println(fmt.Sprintf("[Status: %d] %s", res.StatusCode, res.Message))
267
268 return nil
269}
270
271func (options *ONUDhcpRestart) Execute(args []string) error {
272 client, conn := connect()
273 defer conn.Close()
274
275 ctx, cancel := context.WithTimeout(context.Background(), config.GlobalConfig.Grpc.Timeout)
276 defer cancel()
Nitin Subramanian150f1bb2021-08-02 12:04:05 -0700277 req := pb.UNIRequest{
278 OnuSerialNumber: string(options.Args.OnuSn),
279 UniID: "",
Matteo Scandoloe383d5d2019-10-25 14:47:27 -0700280 }
281 res, err := client.RestartDhcp(ctx, &req)
282
283 if err != nil {
284 log.Fatalf("Cannot restart DHCP for ONU %s: %v", options.Args.OnuSn, err)
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700285 return err
286 }
287
288 fmt.Println(fmt.Sprintf("[Status: %d] %s", res.StatusCode, res.Message))
289
290 return nil
291}
292
Arjun E K57a7fcb2020-01-30 06:44:45 +0000293func (options *ONUIgmp) Execute(args []string) error {
294 client, conn := connect()
295 defer conn.Close()
296
297 ctx, cancel := context.WithTimeout(context.Background(), config.GlobalConfig.Grpc.Timeout)
298 defer cancel()
299
300 req := pb.ONURequest{
301 SerialNumber: string(options.Args.OnuSn),
302 }
303
304 var subActionVal pb.SubActionTypes
305 if string(options.Args.SubAction) == IgmpJoinKey {
306 subActionVal = pb.SubActionTypes_JOIN
307 } else if string(options.Args.SubAction) == IgmpLeaveKey {
308 subActionVal = pb.SubActionTypes_LEAVE
Anand S Katti09541352020-01-29 15:54:01 +0530309 } else if string(options.Args.SubAction) == IgmpJoinKeyV3 {
310 subActionVal = pb.SubActionTypes_JOINV3
311 }
Arjun E K57a7fcb2020-01-30 06:44:45 +0000312
313 igmpReq := pb.IgmpRequest{
314 OnuReq: &req,
315 SubActionVal: subActionVal,
Onur Kalinagac9f9faca2021-01-21 14:04:34 +0000316 GroupAddress: string(options.Args.GroupAddress),
Arjun E K57a7fcb2020-01-30 06:44:45 +0000317 }
318 res, err := client.GetONU(ctx, igmpReq.OnuReq)
319 if err != nil {
320 log.WithFields(log.Fields{
321 "SerialNumber": options.Args.OnuSn,
322 }).Errorf("Cannot not get details on ONU error: %v", err)
323 }
324 log.WithFields(log.Fields{
325 "SerialNumber": igmpReq.OnuReq.SerialNumber,
Onur Kalinagac9f9faca2021-01-21 14:04:34 +0000326 }).Debugf("ONU has identified : %s", res)
Arjun E K57a7fcb2020-01-30 06:44:45 +0000327
328 igmpRes, igmpErr := client.ChangeIgmpState(ctx, &igmpReq)
329 if igmpErr != nil {
330 log.WithFields(log.Fields{
331 "SubAction": options.Args.SubAction,
332 }).Errorf("Could not process Action: error: %v", igmpErr)
333 } else {
334 log.WithFields(log.Fields{
335 "SubAction": options.Args.SubAction,
336 }).Debugf("igmp state has been changed with response: %s",
337 igmpRes.Message)
338 }
339
340 return nil
341}
342
Pragya Arya8bdb4532020-03-02 17:08:09 +0530343func (options *ONUFlows) Execute(args []string) error {
344 client, conn := connect()
345 defer conn.Close()
346
347 ctx, cancel := context.WithTimeout(context.Background(), config.GlobalConfig.Grpc.Timeout)
348 defer cancel()
349 req := pb.ONURequest{
350 SerialNumber: string(options.Args.OnuSn),
351 }
352 res, err := client.GetFlows(ctx, &req)
353 if err != nil {
354 log.Errorf("Cannot get flows for ONU %s: %v", options.Args.OnuSn, err)
355 return err
356 }
357
358 if res.Flows == nil {
359 fmt.Println(fmt.Sprintf("ONU %s has no flows", options.Args.OnuSn))
360 return nil
361 }
362
363 flowHeader := []string{
364 "access_intf_id",
365 "onu_id",
366 "uni_id",
367 "flow_id",
368 "flow_type",
369 "eth_type",
370 "alloc_id",
371 "network_intf_id",
372 "gemport_id",
373 "classifier",
374 "action",
375 "priority",
376 "cookie",
377 "port_no",
378 }
379
380 tableFlow := tablewriter.NewWriter(os.Stdout)
381 tableFlow.SetRowLine(true)
382 fmt.Fprintf(os.Stdout, "ONU Flows:\n")
383 tableFlow.SetHeader(flowHeader)
384
385 for _, flow := range res.Flows {
386 flowInfo := []string{}
387 flowInfo = append(flowInfo,
388 strconv.Itoa(int(flow.AccessIntfId)),
389 strconv.Itoa(int(flow.OnuId)),
390 strconv.Itoa(int(flow.UniId)),
391 strconv.Itoa(int(flow.FlowId)),
392 flow.FlowType,
393 fmt.Sprintf("%x", flow.Classifier.EthType),
394 strconv.Itoa(int(flow.AllocId)),
395 strconv.Itoa(int(flow.NetworkIntfId)),
396 strconv.Itoa(int(flow.GemportId)),
397 flow.Classifier.String(),
398 flow.Action.String(),
399 strconv.Itoa(int(flow.Priority)),
400 strconv.Itoa(int(flow.Cookie)),
401 strconv.Itoa(int(flow.PortNo)),
402 )
403 tableFlow.Append(flowInfo)
404 }
405 tableFlow.Render()
406 tableFlow.SetNewLine("")
407 return nil
408}
409
Elia Battistonfe017662022-01-05 11:43:16 +0100410func (options *ONUInvalidateMds) Execute(args []string) error {
411 client, conn := connect()
412 defer conn.Close()
413
414 ctx, cancel := context.WithTimeout(context.Background(), config.GlobalConfig.Grpc.Timeout)
415 defer cancel()
416 req := pb.ONURequest{
417 SerialNumber: string(options.Args.OnuSn),
418 }
419 res, err := client.InvalidateMds(ctx, &req)
420
421 if err != nil {
422 log.Fatalf("Cannot invalidate MDS counter on ONU %s: %v", options.Args.OnuSn, err)
423 return err
424 }
425
426 fmt.Println(fmt.Sprintf("[Status: %d] %s", res.StatusCode, res.Message))
427
428 return nil
429}
430
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700431func (onuSn *OnuSnString) Complete(match string) []flags.Completion {
432 client, conn := connect()
433 defer conn.Close()
434
435 ctx, cancel := context.WithTimeout(context.Background(), config.GlobalConfig.Grpc.Timeout)
436 defer cancel()
437
438 onus, err := client.GetONUs(ctx, &pb.Empty{})
439 if err != nil {
Matteo Scandolo86e8ce62019-10-11 12:03:10 -0700440 log.Fatalf("could not get ONUs: %v", err)
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700441 return nil
442 }
443
444 list := make([]flags.Completion, 0)
445 for _, k := range onus.Items {
446 if strings.HasPrefix(k.SerialNumber, match) {
447 list = append(list, flags.Completion{Item: k.SerialNumber})
448 }
449 }
450
451 return list
452}
Anand S Katti09541352020-01-29 15:54:01 +0530453
Matteo Scandolo618a6582020-09-09 12:21:29 -0700454func (onuSn *IgmpSubAction) Complete(match string) []flags.Completion {
455 list := make([]flags.Completion, 0)
456 for _, k := range IgmpAllowedActions {
457 if strings.HasPrefix(k, match) {
458 list = append(list, flags.Completion{Item: k})
459 }
460 }
461 return list
462}
463
Anand S Katti09541352020-01-29 15:54:01 +0530464func (options *ONUTrafficSchedulers) Execute(args []string) error {
465 client, conn := connect()
466 defer conn.Close()
467
468 ctx, cancel := context.WithTimeout(context.Background(), config.GlobalConfig.Grpc.Timeout)
469 defer cancel()
470 req := pb.ONURequest{
471 SerialNumber: string(options.Args.OnuSn),
472 }
473 res, err := client.GetOnuTrafficSchedulers(ctx, &req)
474 if err != nil {
475 log.Fatalf("Cannot get traffic schedulers for ONU %s: %v", options.Args.OnuSn, err)
476 return err
477 }
478
479 if res.TraffSchedulers == nil {
480 log.Fatalf("Cannot get traffic schedulers for ONU: %s (unavailable)", options.Args.OnuSn)
481 return nil
482 }
483
484 SchedulerHeader := []string{"Direction",
485 "AllocId",
486 "Scheduler.Direction",
487 "Scheduler.AdditionalBw",
488 "Scheduler.Priority",
489 "Scheduler.Weight",
490 "Scheduler.SchedPolicy",
491 }
492
493 ShapingInfoHeader := []string{"InferredAdditionBwIndication",
494 "Cbs",
495 "Cir",
496 "Gir",
497 "Pbs",
498 "Pir",
499 }
500
501 SchedulerVals := []string{}
502 ShapingInfoVals := []string{}
503 for _, v := range res.TraffSchedulers.TrafficScheds {
504 SchedulerVals = append(SchedulerVals,
505 v.GetDirection().String(),
506 strconv.Itoa(int(v.GetAllocId())),
507 v.Scheduler.GetDirection().String(),
508 v.Scheduler.GetAdditionalBw().String(),
509 strconv.Itoa(int(v.Scheduler.GetPriority())),
510 strconv.Itoa(int(v.Scheduler.GetWeight())),
511 v.GetScheduler().GetSchedPolicy().String(),
512 )
513
514 ShapingInfoVals = append(ShapingInfoVals,
515 v.TrafficShapingInfo.GetAddBwInd().String(),
516 strconv.Itoa(int(v.TrafficShapingInfo.GetCbs())),
517 strconv.Itoa(int(v.TrafficShapingInfo.GetCir())),
518 strconv.Itoa(int(v.TrafficShapingInfo.GetGir())),
519 strconv.Itoa(int(v.TrafficShapingInfo.GetPbs())),
520 strconv.Itoa(int(v.TrafficShapingInfo.GetPir())),
521 )
522 }
523
524 fmt.Fprintf(os.Stdout, "OnuId: %d \n", int(res.TraffSchedulers.OnuId))
525 fmt.Fprintf(os.Stdout, "IntfId: %d \n", int(res.TraffSchedulers.IntfId))
526 fmt.Fprintf(os.Stdout, "UniId: %d \n", int(res.TraffSchedulers.UniId))
527 fmt.Fprintf(os.Stdout, "OnuPortNo: %d \n", int(res.TraffSchedulers.PortNo))
528
529 tableSched := tablewriter.NewWriter(os.Stdout)
530 tableSched.SetRowLine(true)
531 fmt.Fprintf(os.Stdout, "Traffic Schedulers Info:\n")
532 tableSched.SetHeader(SchedulerHeader)
533 tableSched.Append(SchedulerVals)
534 tableSched.Render()
535 tableSched.SetNewLine("")
536
537 tableShap := tablewriter.NewWriter(os.Stdout)
538 tableShap.SetRowLine(true)
539 fmt.Fprintf(os.Stdout, "Traffic Shaping Info:\n")
540 tableShap.SetHeader(ShapingInfoHeader)
541 tableShap.Append(ShapingInfoVals)
542 tableShap.Render()
543
544 return nil
545}
Nitin Subramanianb0a333a2021-07-08 15:01:41 -0700546
547func (options *ONUServices) Execute(args []string) error {
548 services, err := getServices(string(options.Args.OnuSn), "")
549
550 if err != nil {
551 log.Errorf("Cannot get services for ONU %s: %v", options.Args.OnuSn, err)
552 return err
553 }
554
555 // print out
556 tableFormat := format.Format(DEFAULT_SERVICE_HEADER_FORMAT)
557 if err := tableFormat.Execute(os.Stdout, true, services.Items); err != nil {
558 log.Fatalf("Error while formatting ONUs table: %s", err)
559 }
560
561 return nil
562}