blob: ae398b5ceb8fb3ffff1c20b405c4121966f9a2cc [file] [log] [blame]
Matteo Scandolo8df63df2019-09-12 10:34:32 -07001/*
Joey Armstrong4d6878e2024-02-08 16:29:26 -05002 * Portions Copyright 2019-2024 Open Networking Foundation (ONF) and the ONF Contributors
Matteo Scandolo8df63df2019-09-12 10:34:32 -07003 * 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
Baris Ertas0ce2f7c2023-04-11 11:44:24 +030041type UniId int
Arjun E K57a7fcb2020-01-30 06:44:45 +000042type IgmpSubAction string
Onur Kalinagac9f9faca2021-01-21 14:04:34 +000043type GroupAddress string
Baris Ertas0ce2f7c2023-04-11 11:44:24 +030044type VLAN int
Arjun E K57a7fcb2020-01-30 06:44:45 +000045
46const IgmpJoinKey string = "join"
47const IgmpLeaveKey string = "leave"
Arjun E Kdd443f02020-02-07 15:24:01 +000048const IgmpJoinKeyV3 string = "joinv3"
Arjun E K57a7fcb2020-01-30 06:44:45 +000049
Matteo Scandolo618a6582020-09-09 12:21:29 -070050var IgmpAllowedActions = []string{IgmpJoinKey, IgmpLeaveKey, IgmpJoinKeyV3}
51
Matteo Scandolo4a036262020-08-17 15:56:13 -070052type ONUList struct {
53 Verbose bool `short:"v" long:"verbose" description:"Print all the informations we have about ONUs"`
54}
Matteo Scandolod2ca2c72019-10-04 16:50:22 -070055
56type ONUGet struct {
Matteo Scandolo4a036262020-08-17 15:56:13 -070057 Verbose bool `short:"v" long:"verbose" description:"Print all the informations we have about ONUs"`
58 Args struct {
59 OnuSn OnuSnString
60 } `positional-args:"yes" required:"yes"`
61}
62
Matteo Scandoloef4e8f82021-05-17 11:20:49 -070063type ONUUnis struct {
Matteo Scandolo8a574812021-05-20 15:18:53 -070064 Verbose bool `short:"v" long:"verbose" description:"Print all the informations we have about UNIs"`
65 Args struct {
Matteo Scandoloef4e8f82021-05-17 11:20:49 -070066 OnuSn OnuSnString
67 } `positional-args:"yes" required:"yes"`
68}
69
Matteo Scandolo10f965c2019-09-24 10:40:46 -070070type ONUShutDown struct {
71 Args struct {
72 OnuSn OnuSnString
73 } `positional-args:"yes" required:"yes"`
Matteo Scandolo8df63df2019-09-12 10:34:32 -070074}
75
Matteo Scandolo10f965c2019-09-24 10:40:46 -070076type ONUPowerOn struct {
77 Args struct {
78 OnuSn OnuSnString
79 } `positional-args:"yes" required:"yes"`
80}
81
Matteo Scandoloe383d5d2019-10-25 14:47:27 -070082type ONUEapolRestart struct {
83 Args struct {
84 OnuSn OnuSnString
85 } `positional-args:"yes" required:"yes"`
86}
87
88type ONUDhcpRestart struct {
89 Args struct {
90 OnuSn OnuSnString
91 } `positional-args:"yes" required:"yes"`
92}
93
Arjun E K57a7fcb2020-01-30 06:44:45 +000094type ONUIgmp struct {
95 Args struct {
Onur Kalinagac9f9faca2021-01-21 14:04:34 +000096 OnuSn OnuSnString
Baris Ertas0ce2f7c2023-04-11 11:44:24 +030097 UniId UniId
Onur Kalinagac9f9faca2021-01-21 14:04:34 +000098 SubAction IgmpSubAction
99 GroupAddress GroupAddress
Arjun E K57a7fcb2020-01-30 06:44:45 +0000100 } `positional-args:"yes" required:"yes"`
Baris Ertas0ce2f7c2023-04-11 11:44:24 +0300101 VLAN VLAN `short:"v" long:"vlan" description:"VLAN to set"`
Arjun E K57a7fcb2020-01-30 06:44:45 +0000102}
103
Pragya Arya8bdb4532020-03-02 17:08:09 +0530104type ONUTrafficSchedulers struct {
105 Args struct {
106 OnuSn OnuSnString
107 } `positional-args:"yes" required:"yes"`
108}
109
110type ONUFlows struct {
111 Args struct {
112 OnuSn OnuSnString
113 } `positional-args:"yes" required:"yes"`
114}
115
Nitin Subramanianb0a333a2021-07-08 15:01:41 -0700116type ONUServices struct {
117 Args struct {
118 OnuSn OnuSnString
119 } `positional-args:"yes"`
120}
121
Elia Battistonfe017662022-01-05 11:43:16 +0100122type ONUInvalidateMds struct {
123 Args struct {
124 OnuSn OnuSnString
125 } `positional-args:"yes" required:"yes"`
126}
127
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700128type ONUOptions struct {
Anand S Katti09541352020-01-29 15:54:01 +0530129 List ONUList `command:"list"`
130 Get ONUGet `command:"get"`
131 ShutDown ONUShutDown `command:"shutdown"`
132 PowerOn ONUPowerOn `command:"poweron"`
133 RestartEapol ONUEapolRestart `command:"auth_restart"`
134 RestartDchp ONUDhcpRestart `command:"dhcp_restart"`
135 Igmp ONUIgmp `command:"igmp"`
136 TrafficSchedulers ONUTrafficSchedulers `command:"traffic_schedulers"`
Anand S Katti86552f92020-03-03 21:56:32 +0530137 Alarms AlarmOptions `command:"alarms"`
Pragya Arya8bdb4532020-03-02 17:08:09 +0530138 Flows ONUFlows `command:"flows"`
Nitin Subramanianb0a333a2021-07-08 15:01:41 -0700139 Services ONUServices `command:"services"`
Elia Battistonfe017662022-01-05 11:43:16 +0100140 InvalidateMds ONUInvalidateMds `command:"invalidate_mds"`
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700141}
142
143func RegisterONUCommands(parser *flags.Parser) {
Shrey Baid688b4242020-07-10 20:40:10 +0530144 _, _ = parser.AddCommand("onu", "ONU Commands", "Commands to query and manipulate ONU devices", &ONUOptions{})
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700145}
146
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700147func getONUs() *pb.ONUs {
148
149 client, conn := connect()
Matteo Scandolo8df63df2019-09-12 10:34:32 -0700150 defer conn.Close()
Matteo Scandolo8df63df2019-09-12 10:34:32 -0700151
152 // Contact the server and print out its response.
Matteo Scandolo8df63df2019-09-12 10:34:32 -0700153 ctx, cancel := context.WithTimeout(context.Background(), config.GlobalConfig.Grpc.Timeout)
154 defer cancel()
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700155
156 onus, err := client.GetONUs(ctx, &pb.Empty{})
Matteo Scandolo8df63df2019-09-12 10:34:32 -0700157 if err != nil {
Matteo Scandolo2bf742a2019-10-01 11:33:34 -0700158 log.Fatalf("could not get OLT: %v", err)
Matteo Scandolo8df63df2019-09-12 10:34:32 -0700159 return nil
160 }
161 return onus
162}
163
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700164func (options *ONUList) Execute(args []string) error {
Matteo Scandolo8df63df2019-09-12 10:34:32 -0700165 onus := getONUs()
166
167 // print out
Matteo Scandolo4a036262020-08-17 15:56:13 -0700168 var tableFormat format.Format
169 if options.Verbose {
170 tableFormat = format.Format(DEFAULT_ONU_DEVICE_HEADER_FORMAT_WITH_SERVICES)
171 } else {
172 tableFormat = format.Format(DEFAULT_ONU_DEVICE_HEADER_FORMAT)
173 }
Matteo Scandolo8df63df2019-09-12 10:34:32 -0700174 if err := tableFormat.Execute(os.Stdout, true, onus.Items); err != nil {
175 log.Fatalf("Error while formatting ONUs table: %s", err)
176 }
177
178 return nil
179}
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700180
Matteo Scandolod2ca2c72019-10-04 16:50:22 -0700181func (options *ONUGet) Execute(args []string) error {
182 client, conn := connect()
183 defer conn.Close()
184
185 ctx, cancel := context.WithTimeout(context.Background(), config.GlobalConfig.Grpc.Timeout)
186 defer cancel()
187 req := pb.ONURequest{
188 SerialNumber: string(options.Args.OnuSn),
189 }
190 res, err := client.GetONU(ctx, &req)
191
192 if err != nil {
Matteo Scandolo4a036262020-08-17 15:56:13 -0700193 log.Fatalf("Cannot not get ONU %s: %v", options.Args.OnuSn, err)
Matteo Scandolod2ca2c72019-10-04 16:50:22 -0700194 return err
195 }
196
Matteo Scandolo4a036262020-08-17 15:56:13 -0700197 var tableFormat format.Format
198 if options.Verbose {
199 tableFormat = format.Format(DEFAULT_ONU_DEVICE_HEADER_FORMAT_WITH_SERVICES)
200 } else {
201 tableFormat = format.Format(DEFAULT_ONU_DEVICE_HEADER_FORMAT)
202 }
Matteo Scandolod2ca2c72019-10-04 16:50:22 -0700203 if err := tableFormat.Execute(os.Stdout, true, []*pb.ONU{res}); err != nil {
204 log.Fatalf("Error while formatting ONUs table: %s", err)
205 }
206
207 return nil
208}
209
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700210func (options *ONUShutDown) Execute(args []string) error {
211
212 client, conn := connect()
213 defer conn.Close()
214
215 ctx, cancel := context.WithTimeout(context.Background(), config.GlobalConfig.Grpc.Timeout)
216 defer cancel()
217 req := pb.ONURequest{
218 SerialNumber: string(options.Args.OnuSn),
219 }
220 res, err := client.ShutdownONU(ctx, &req)
221
222 if err != nil {
Matteo Scandoloe383d5d2019-10-25 14:47:27 -0700223 log.Fatalf("Cannot shutdown ONU %s: %v", options.Args.OnuSn, err)
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700224 return err
225 }
226
227 fmt.Println(fmt.Sprintf("[Status: %d] %s", res.StatusCode, res.Message))
228
229 return nil
230}
231
232func (options *ONUPowerOn) Execute(args []string) error {
233 client, conn := connect()
234 defer conn.Close()
235
236 ctx, cancel := context.WithTimeout(context.Background(), config.GlobalConfig.Grpc.Timeout)
237 defer cancel()
238 req := pb.ONURequest{
239 SerialNumber: string(options.Args.OnuSn),
240 }
241 res, err := client.PoweronONU(ctx, &req)
242
243 if err != nil {
Matteo Scandoloe383d5d2019-10-25 14:47:27 -0700244 log.Fatalf("Cannot power on ONU %s: %v", options.Args.OnuSn, err)
245 return err
246 }
247
248 fmt.Println(fmt.Sprintf("[Status: %d] %s", res.StatusCode, res.Message))
249
250 return nil
251}
252
253func (options *ONUEapolRestart) Execute(args []string) error {
254 client, conn := connect()
255 defer conn.Close()
256
257 ctx, cancel := context.WithTimeout(context.Background(), config.GlobalConfig.Grpc.Timeout)
258 defer cancel()
Nitin Subramanian150f1bb2021-08-02 12:04:05 -0700259 req := pb.UNIRequest{
260 OnuSerialNumber: string(options.Args.OnuSn),
261 UniID: "",
Matteo Scandoloe383d5d2019-10-25 14:47:27 -0700262 }
263 res, err := client.RestartEapol(ctx, &req)
264
265 if err != nil {
266 log.Fatalf("Cannot restart EAPOL for ONU %s: %v", options.Args.OnuSn, err)
267 return err
268 }
269
270 fmt.Println(fmt.Sprintf("[Status: %d] %s", res.StatusCode, res.Message))
271
272 return nil
273}
274
275func (options *ONUDhcpRestart) Execute(args []string) error {
276 client, conn := connect()
277 defer conn.Close()
278
279 ctx, cancel := context.WithTimeout(context.Background(), config.GlobalConfig.Grpc.Timeout)
280 defer cancel()
Nitin Subramanian150f1bb2021-08-02 12:04:05 -0700281 req := pb.UNIRequest{
282 OnuSerialNumber: string(options.Args.OnuSn),
283 UniID: "",
Matteo Scandoloe383d5d2019-10-25 14:47:27 -0700284 }
285 res, err := client.RestartDhcp(ctx, &req)
286
287 if err != nil {
288 log.Fatalf("Cannot restart DHCP for ONU %s: %v", options.Args.OnuSn, err)
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700289 return err
290 }
291
292 fmt.Println(fmt.Sprintf("[Status: %d] %s", res.StatusCode, res.Message))
293
294 return nil
295}
296
Arjun E K57a7fcb2020-01-30 06:44:45 +0000297func (options *ONUIgmp) Execute(args []string) error {
298 client, conn := connect()
299 defer conn.Close()
300
301 ctx, cancel := context.WithTimeout(context.Background(), config.GlobalConfig.Grpc.Timeout)
302 defer cancel()
303
Arjun E K57a7fcb2020-01-30 06:44:45 +0000304 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{
Baris Ertas0ce2f7c2023-04-11 11:44:24 +0300314 OnuSerialNumber: string(options.Args.OnuSn),
315 UniID: int32(options.Args.UniId),
316 SubActionVal: subActionVal,
317 GroupAddress: string(options.Args.GroupAddress),
318 VLAN: int32(options.VLAN),
Arjun E K57a7fcb2020-01-30 06:44:45 +0000319 }
Baris Ertas0ce2f7c2023-04-11 11:44:24 +0300320 req := &pb.ONURequest{
321 SerialNumber: string(options.Args.OnuSn),
322 }
323 res, err := client.GetONU(ctx, req)
Arjun E K57a7fcb2020-01-30 06:44:45 +0000324 if err != nil {
325 log.WithFields(log.Fields{
326 "SerialNumber": options.Args.OnuSn,
327 }).Errorf("Cannot not get details on ONU error: %v", err)
328 }
329 log.WithFields(log.Fields{
Baris Ertas0ce2f7c2023-04-11 11:44:24 +0300330 "SerialNumber": igmpReq.OnuSerialNumber,
Onur Kalinagac9f9faca2021-01-21 14:04:34 +0000331 }).Debugf("ONU has identified : %s", res)
Arjun E K57a7fcb2020-01-30 06:44:45 +0000332
333 igmpRes, igmpErr := client.ChangeIgmpState(ctx, &igmpReq)
334 if igmpErr != nil {
335 log.WithFields(log.Fields{
336 "SubAction": options.Args.SubAction,
337 }).Errorf("Could not process Action: error: %v", igmpErr)
338 } else {
339 log.WithFields(log.Fields{
340 "SubAction": options.Args.SubAction,
341 }).Debugf("igmp state has been changed with response: %s",
342 igmpRes.Message)
343 }
344
345 return nil
346}
347
Pragya Arya8bdb4532020-03-02 17:08:09 +0530348func (options *ONUFlows) Execute(args []string) error {
349 client, conn := connect()
350 defer conn.Close()
351
352 ctx, cancel := context.WithTimeout(context.Background(), config.GlobalConfig.Grpc.Timeout)
353 defer cancel()
354 req := pb.ONURequest{
355 SerialNumber: string(options.Args.OnuSn),
356 }
357 res, err := client.GetFlows(ctx, &req)
358 if err != nil {
359 log.Errorf("Cannot get flows for ONU %s: %v", options.Args.OnuSn, err)
360 return err
361 }
362
363 if res.Flows == nil {
364 fmt.Println(fmt.Sprintf("ONU %s has no flows", options.Args.OnuSn))
365 return nil
366 }
367
368 flowHeader := []string{
369 "access_intf_id",
370 "onu_id",
371 "uni_id",
372 "flow_id",
373 "flow_type",
374 "eth_type",
375 "alloc_id",
376 "network_intf_id",
377 "gemport_id",
378 "classifier",
379 "action",
380 "priority",
381 "cookie",
382 "port_no",
383 }
384
385 tableFlow := tablewriter.NewWriter(os.Stdout)
386 tableFlow.SetRowLine(true)
387 fmt.Fprintf(os.Stdout, "ONU Flows:\n")
388 tableFlow.SetHeader(flowHeader)
389
390 for _, flow := range res.Flows {
391 flowInfo := []string{}
392 flowInfo = append(flowInfo,
393 strconv.Itoa(int(flow.AccessIntfId)),
394 strconv.Itoa(int(flow.OnuId)),
395 strconv.Itoa(int(flow.UniId)),
396 strconv.Itoa(int(flow.FlowId)),
397 flow.FlowType,
398 fmt.Sprintf("%x", flow.Classifier.EthType),
399 strconv.Itoa(int(flow.AllocId)),
400 strconv.Itoa(int(flow.NetworkIntfId)),
401 strconv.Itoa(int(flow.GemportId)),
402 flow.Classifier.String(),
403 flow.Action.String(),
404 strconv.Itoa(int(flow.Priority)),
405 strconv.Itoa(int(flow.Cookie)),
406 strconv.Itoa(int(flow.PortNo)),
407 )
408 tableFlow.Append(flowInfo)
409 }
410 tableFlow.Render()
411 tableFlow.SetNewLine("")
412 return nil
413}
414
Elia Battistonfe017662022-01-05 11:43:16 +0100415func (options *ONUInvalidateMds) Execute(args []string) error {
416 client, conn := connect()
417 defer conn.Close()
418
419 ctx, cancel := context.WithTimeout(context.Background(), config.GlobalConfig.Grpc.Timeout)
420 defer cancel()
421 req := pb.ONURequest{
422 SerialNumber: string(options.Args.OnuSn),
423 }
424 res, err := client.InvalidateMds(ctx, &req)
425
426 if err != nil {
427 log.Fatalf("Cannot invalidate MDS counter on ONU %s: %v", options.Args.OnuSn, err)
428 return err
429 }
430
431 fmt.Println(fmt.Sprintf("[Status: %d] %s", res.StatusCode, res.Message))
432
433 return nil
434}
435
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700436func (onuSn *OnuSnString) Complete(match string) []flags.Completion {
437 client, conn := connect()
438 defer conn.Close()
439
440 ctx, cancel := context.WithTimeout(context.Background(), config.GlobalConfig.Grpc.Timeout)
441 defer cancel()
442
443 onus, err := client.GetONUs(ctx, &pb.Empty{})
444 if err != nil {
Matteo Scandolo86e8ce62019-10-11 12:03:10 -0700445 log.Fatalf("could not get ONUs: %v", err)
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700446 return nil
447 }
448
449 list := make([]flags.Completion, 0)
450 for _, k := range onus.Items {
451 if strings.HasPrefix(k.SerialNumber, match) {
452 list = append(list, flags.Completion{Item: k.SerialNumber})
453 }
454 }
455
456 return list
457}
Anand S Katti09541352020-01-29 15:54:01 +0530458
Matteo Scandolo618a6582020-09-09 12:21:29 -0700459func (onuSn *IgmpSubAction) Complete(match string) []flags.Completion {
460 list := make([]flags.Completion, 0)
461 for _, k := range IgmpAllowedActions {
462 if strings.HasPrefix(k, match) {
463 list = append(list, flags.Completion{Item: k})
464 }
465 }
466 return list
467}
468
Anand S Katti09541352020-01-29 15:54:01 +0530469func (options *ONUTrafficSchedulers) Execute(args []string) error {
470 client, conn := connect()
471 defer conn.Close()
472
473 ctx, cancel := context.WithTimeout(context.Background(), config.GlobalConfig.Grpc.Timeout)
474 defer cancel()
475 req := pb.ONURequest{
476 SerialNumber: string(options.Args.OnuSn),
477 }
478 res, err := client.GetOnuTrafficSchedulers(ctx, &req)
479 if err != nil {
480 log.Fatalf("Cannot get traffic schedulers for ONU %s: %v", options.Args.OnuSn, err)
481 return err
482 }
483
484 if res.TraffSchedulers == nil {
485 log.Fatalf("Cannot get traffic schedulers for ONU: %s (unavailable)", options.Args.OnuSn)
486 return nil
487 }
488
489 SchedulerHeader := []string{"Direction",
490 "AllocId",
491 "Scheduler.Direction",
492 "Scheduler.AdditionalBw",
493 "Scheduler.Priority",
494 "Scheduler.Weight",
495 "Scheduler.SchedPolicy",
496 }
497
498 ShapingInfoHeader := []string{"InferredAdditionBwIndication",
499 "Cbs",
500 "Cir",
501 "Gir",
502 "Pbs",
503 "Pir",
504 }
505
506 SchedulerVals := []string{}
507 ShapingInfoVals := []string{}
508 for _, v := range res.TraffSchedulers.TrafficScheds {
509 SchedulerVals = append(SchedulerVals,
510 v.GetDirection().String(),
511 strconv.Itoa(int(v.GetAllocId())),
512 v.Scheduler.GetDirection().String(),
513 v.Scheduler.GetAdditionalBw().String(),
514 strconv.Itoa(int(v.Scheduler.GetPriority())),
515 strconv.Itoa(int(v.Scheduler.GetWeight())),
516 v.GetScheduler().GetSchedPolicy().String(),
517 )
518
519 ShapingInfoVals = append(ShapingInfoVals,
520 v.TrafficShapingInfo.GetAddBwInd().String(),
521 strconv.Itoa(int(v.TrafficShapingInfo.GetCbs())),
522 strconv.Itoa(int(v.TrafficShapingInfo.GetCir())),
523 strconv.Itoa(int(v.TrafficShapingInfo.GetGir())),
524 strconv.Itoa(int(v.TrafficShapingInfo.GetPbs())),
525 strconv.Itoa(int(v.TrafficShapingInfo.GetPir())),
526 )
527 }
528
529 fmt.Fprintf(os.Stdout, "OnuId: %d \n", int(res.TraffSchedulers.OnuId))
530 fmt.Fprintf(os.Stdout, "IntfId: %d \n", int(res.TraffSchedulers.IntfId))
531 fmt.Fprintf(os.Stdout, "UniId: %d \n", int(res.TraffSchedulers.UniId))
532 fmt.Fprintf(os.Stdout, "OnuPortNo: %d \n", int(res.TraffSchedulers.PortNo))
533
534 tableSched := tablewriter.NewWriter(os.Stdout)
535 tableSched.SetRowLine(true)
536 fmt.Fprintf(os.Stdout, "Traffic Schedulers Info:\n")
537 tableSched.SetHeader(SchedulerHeader)
538 tableSched.Append(SchedulerVals)
539 tableSched.Render()
540 tableSched.SetNewLine("")
541
542 tableShap := tablewriter.NewWriter(os.Stdout)
543 tableShap.SetRowLine(true)
544 fmt.Fprintf(os.Stdout, "Traffic Shaping Info:\n")
545 tableShap.SetHeader(ShapingInfoHeader)
546 tableShap.Append(ShapingInfoVals)
547 tableShap.Render()
548
549 return nil
550}
Nitin Subramanianb0a333a2021-07-08 15:01:41 -0700551
552func (options *ONUServices) Execute(args []string) error {
553 services, err := getServices(string(options.Args.OnuSn), "")
554
555 if err != nil {
556 log.Errorf("Cannot get services for ONU %s: %v", options.Args.OnuSn, err)
557 return err
558 }
559
560 // print out
561 tableFormat := format.Format(DEFAULT_SERVICE_HEADER_FORMAT)
562 if err := tableFormat.Execute(os.Stdout, true, services.Items); err != nil {
563 log.Fatalf("Error while formatting ONUs table: %s", err)
564 }
565
566 return nil
567}