blob: f2521cca18e43726e2d6b97f38b18bfac43e2470 [file] [log] [blame]
Zack Williamse940c7a2019-08-21 14:25:39 -07001/*
2 * Copyright 2019-present Ciena Corporation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package commands
17
18import (
19 "context"
Akash Soni6e879c22024-12-20 17:01:34 +053020 "encoding/json"
Zack Williamse940c7a2019-08-21 14:25:39 -070021 "fmt"
David Bainbridge7052fe82020-03-25 10:37:00 -070022 "os"
balaji.nagarajan1f7c6392026-05-22 16:16:30 +053023 "sort"
David Bainbridge7052fe82020-03-25 10:37:00 -070024 "strconv"
25 "strings"
Girish Gowdra610acb42021-01-27 13:33:57 -080026 "time"
David Bainbridge7052fe82020-03-25 10:37:00 -070027
Scott Baker9173ed82020-05-19 08:30:12 -070028 "github.com/golang/protobuf/ptypes/empty"
Zack Williamse940c7a2019-08-21 14:25:39 -070029 flags "github.com/jessevdk/go-flags"
Scott Baker2b0ad652019-08-21 14:57:07 -070030 "github.com/opencord/voltctl/pkg/format"
David K. Bainbridgebd6b2882021-08-26 13:31:02 +000031 "github.com/opencord/voltha-protos/v5/go/common"
32 "github.com/opencord/voltha-protos/v5/go/extension"
33 "github.com/opencord/voltha-protos/v5/go/voltha"
Zack Williamse940c7a2019-08-21 14:25:39 -070034)
35
36const (
David K. Bainbridge89003c42020-02-27 17:22:49 -080037 DEFAULT_DEVICE_FORMAT = "table{{ .Id }}\t{{.Type}}\t{{.Root}}\t{{.ParentId}}\t{{.SerialNumber}}\t{{.AdminState}}\t{{.OperStatus}}\t{{.ConnectStatus}}\t{{.Reason}}"
Hardik Windlass9361bb82022-03-23 05:58:48 +000038 DEFAULT_DEVICE_ORDER = "Type,Id"
Zack Williamse940c7a2019-08-21 14:25:39 -070039 DEFAULT_DEVICE_PORTS_FORMAT = "table{{.PortNo}}\t{{.Label}}\t{{.Type}}\t{{.AdminState}}\t{{.OperStatus}}\t{{.DeviceId}}\t{{.Peers}}"
40 DEFAULT_DEVICE_INSPECT_FORMAT = `ID: {{.Id}}
41 TYPE: {{.Type}}
42 ROOT: {{.Root}}
43 PARENTID: {{.ParentId}}
44 SERIALNUMBER: {{.SerialNumber}}
45 VLAN: {{.Vlan}}
46 ADMINSTATE: {{.AdminState}}
47 OPERSTATUS: {{.OperStatus}}
48 CONNECTSTATUS: {{.ConnectStatus}}`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +000049 DEFAULT_DEVICE_PM_CONFIG_GET_FORMAT = "table{{.DefaultFreq}}\t{{.Grouped}}\t{{.FreqOverride}}"
50 DEFAULT_DEVICE_PM_CONFIG_METRIC_LIST_FORMAT = "table{{.Name}}\t{{.Type}}\t{{.Enabled}}\t{{.SampleFreq}}"
51 DEFAULT_DEVICE_PM_CONFIG_GROUP_LIST_FORMAT = "table{{.GroupName}}\t{{.Enabled}}\t{{.GroupFreq}}"
52 DEFAULT_DEVICE_VALUE_GET_FORMAT = "table{{.Name}}\t{{.Result}}"
Andrea Campanella791d88b2021-01-08 13:29:00 +010053 DEFAULT_DEVICE_IMAGE_LIST_GET_FORMAT = "table{{.Name}}\t{{.Url}}\t{{.Crc}}\t{{.DownloadState}}\t{{.ImageVersion}}\t{{.LocalDir}}\t{{.ImageState}}\t{{.FileSize}}"
ssiddiqui7bc89e92021-05-20 20:58:02 +053054 ONU_IMAGE_LIST_FORMAT = "table{{.Version}}\t{{.IsCommited}}\t{{.IsActive}}\t{{.IsValid}}\t{{.ProductCode}}\t{{.Hash}}"
55 ONU_IMAGE_STATUS_FORMAT = "table{{.DeviceId}}\t{{.ImageState.Version}}\t{{.ImageState.DownloadState}}\t{{.ImageState.Reason}}\t{{.ImageState.ImageState}}\t"
kesavand8ec4fc02021-01-27 09:10:22 -050056 DEFAULT_DEVICE_GET_PORT_STATUS_FORMAT = `
57 TXBYTES: {{.TxBytes}}
58 TXPACKETS: {{.TxPackets}}
59 TXERRPACKETS: {{.TxErrorPackets}}
60 TXBCASTPACKETS: {{.TxBcastPackets}}
61 TXUCASTPACKETS: {{.TxUcastPackets}}
62 TXMCASTPACKETS: {{.TxMcastPackets}}
63 RXBYTES: {{.RxBytes}}
64 RXPACKETS: {{.RxPackets}}
65 RXERRPACKETS: {{.RxErrorPackets}}
66 RXBCASTPACKETS: {{.RxBcastPackets}}
67 RXUCASTPACKETS: {{.RxUcastPackets}}
68 RXMCASTPACKETS: {{.RxMcastPackets}}`
kesavand6d1131f2021-02-05 22:38:15 +053069 DEFAULT_DEVICE_GET_UNI_STATUS_FORMAT = `
70 ADMIN_STATE: {{.AdmState}}
71 OPERATIONAL_STATE: {{.OperState}}
72 CONFIG_IND: {{.ConfigInd}}`
Girish Gowdra4f5ce7c2021-04-29 18:53:21 -070073 DEFAULT_ONU_PON_OPTICAL_INFO_STATUS_FORMAT = `
74 POWER_FEED_VOLTAGE__VOLTS: {{.PowerFeedVoltage}}
75 RECEIVED_OPTICAL_POWER__dBm: {{.ReceivedOpticalPower}}
76 MEAN_OPTICAL_LAUNCH_POWER__dBm: {{.MeanOpticalLaunchPower}}
77 LASER_BIAS_CURRENT__mA: {{.LaserBiasCurrent}}
78 TEMPERATURE__Celsius: {{.Temperature}}`
Gamze Abakac857a462021-05-26 13:45:54 +000079 DEFAULT_RX_POWER_STATUS_FORMAT = `
80 INTF_ID: {{.IntfId}}
81 ONU_ID: {{.OnuId}}
82 STATUS: {{.Status}}
83 FAIL_REASON: {{.FailReason}}
84 RX_POWER : {{.RxPower}}`
Himani Chawla553a1392021-06-10 23:39:17 +053085 DEFAULT_ETHERNET_FRAME_EXTENDED_PM_COUNTERS_FORMAT = `Upstream_Drop_Events: {{.UDropEvents}}
86Upstream_Octets: {{.UOctets}}
87UFrames: {{.UFrames}}
88UBroadcastFrames: {{.UBroadcastFrames}}
89UMulticastFrames: {{.UMulticastFrames}}
90UCrcErroredFrames: {{.UCrcErroredFrames}}
91UUndersizeFrames: {{.UUndersizeFrames}}
92UOversizeFrames: {{.UOversizeFrames}}
93UFrames_64Octets: {{.UFrames_64Octets}}
94UFrames_65To_127Octets: {{.UFrames_65To_127Octets}}
95UFrames_128To_255Octets: {{.UFrames_128To_255Octets}}
96UFrames_256To_511Octets: {{.UFrames_256To_511Octets}}
97UFrames_512To_1023Octets: {{.UFrames_512To_1023Octets}}
98UFrames_1024To_1518Octets: {{.UFrames_1024To_1518Octets}}
99DDropEvents: {{.DDropEvents}}
100DOctets: {{.DOctets}}
101DFrames: {{.DFrames}}
102DBroadcastFrames: {{.DBroadcastFrames}}
103DMulticastFrames: {{.DMulticastFrames}}
104DCrcErroredFrames: {{.DCrcErroredFrames}}
105DUndersizeFrames: {{.DUndersizeFrames}}
106DOversizeFrames: {{.DOversizeFrames}}
107DFrames_64Octets: {{.DFrames_64Octets}}
108DFrames_65To_127Octets: {{.DFrames_65To_127Octets}}
109DFrames_128To_255Octets: {{.DFrames_128To_255Octets}}
110DFrames_256To_511Octets: {{.DFrames_256To_511Octets}}
111DFrames_512To_1023Octets: {{.DFrames_512To_1023Octets}}
Himani Chawlabac0f892021-08-25 17:14:06 +0530112DFrames_1024To_1518Octets: {{.DFrames_1024To_1518Octets}}
113PmFormat: {{.PmFormat}}`
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +0530114 DEFAULT_PON_PORT_STATS_FORMAT = `Pon Port: {{.PonPort}}
115Bip Units: {{.BipUnits}}
116Bip Errors: {{.BipErrors}}
117RxPackets: {{.RxPackets}}
balaji.nagarajan8a2a7ee2026-06-19 22:31:13 +0530118RxFrames: {{.RxFrames}}
119RxBytes: {{.RxBytes}}
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +0530120RxGem: {{.RxGem}}
121RxGemDropped: {{.RxGemDropped}}
122RxGemIdle: {{.RxGemIdle}}
123RxGemCorrected: {{.RxGemCorrected}}
124RxGemIllegal: {{.RxGemIllegal}}
125RxCrcError: {{.RxCrcErrors}}
126RxFragmentError: {{.RxFragmentError}}
127RxPacketsDropped: {{.RxPacketsDropped}}
128RxCpuOmciPacketsDropped: {{.RxCpuOmciPacketsDropped}}
129RxCpu: {{.RxCpu}}
130RxOmci: {{.RxOmci}}
131RxOmciPacketsCrcError: {{.RxOmciPacketsCrcError}}
balaji.nagarajan8a2a7ee2026-06-19 22:31:13 +0530132RxErrorPackets: {{.RxErrorPackets}}
133RxErrorFrames: {{.RxErrorFrames}}
134RxDiscardedFrames: {{.RxDiscardedFrames}}
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +0530135TxPackets: {{.TxPackets}}
balaji.nagarajan8a2a7ee2026-06-19 22:31:13 +0530136TxFrames: {{.TxFrames}}
137TxBytes: {{.TxBytes}}
138TxErrorFrames: {{.TxErrorFrames}}
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +0530139TxGem: {{.TxGem}}
140TxCpu: {{.TxCpu}}
141TxOmci: {{.TxOmci}}
142TxDroppedIllegalLength: {{.TxDroppedIllegalLength}}
143TxDroppedTpidMiss: {{.TxDroppedTpidMiss}}
144TxDroppedVidMiss: {{.TxDroppedVidMiss}}
145TxDroppedTotal: {{.TxDroppedTotal}}`
146 DEFAULT_NNI_PORT_STATS_FORMAT = `Nni Port: {{.NniPort}}
147RxBytes: {{.RxBytes}}
Akash Reddy Kankanalaeba72f62026-01-29 12:49:17 +0000148RxFrames: {{.RxFrames}}
149RxUcastFrames: {{.RxUcastFrames}}
150RxMcastFrames: {{.RxMcastFrames}}
151RxBcastFrames: {{.RxBcastFrames}}
152RxErrorFrames: {{.RxErrorFrames}}
153RxFcsErrorPackets: {{.RxFcsErrorPackets}}
154RxUndersizePackets: {{.RxUndersizePackets}}
155RxOversizePackets: {{.RxOversizePackets}}
balaji.nagarajan8a2a7ee2026-06-19 22:31:13 +0530156RxRightFrames: {{.RxRightFrames}}
157RxCRCErrorFrames: {{.RxCrcErrors}}
158RxDiscardedFrames: {{.RxDiscardedFrames}}
Akash Reddy Kankanalaeba72f62026-01-29 12:49:17 +0000159TxBytes: {{.TxBytes}}
160TxFrames: {{.TxFrames}}
161TxUcastFrames: {{.TxUcastFrames}}
162TxMcastFrames: {{.TxMcastFrames}}
163TxBcastFrames: {{.TxBcastFrames}}
164TxErrorFrames: {{.TxErrorFrames}}
165TxUndersizePackets: {{.TxUndersizePackets}}
166TxOversizePackets: {{.TxOversizePackets}}
balaji.nagarajan8a2a7ee2026-06-19 22:31:13 +0530167TxDroppedTotal: {{.TxDroppedTotal}}
Akash Reddy Kankanalaeba72f62026-01-29 12:49:17 +0000168
169# Deprecated packet counters to be removed in future releases
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +0530170RxPackets: {{.RxPackets}}
171RxUcastPackets: {{.RxUcastPackets}}
172RxMcastPackets: {{.RxMcastPackets}}
173RxBcastPackets: {{.RxBcastPackets}}
174RxErrorPackets: {{.RxErrorPackets}}
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +0530175TxPackets: {{.TxPackets}}
176TxUcastPackets: {{.TxUcastPackets}}
177TxMcastPackets: {{.TxMcastPackets}}
178TxBcastPackets: {{.TxBcastPackets}}
Akash Reddy Kankanalaeba72f62026-01-29 12:49:17 +0000179TxErrorPackets: {{.TxErrorPackets}}`
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +0530180
serkantul3d22fc72022-09-14 12:22:56 +0300181 DEFAULT_ONU_OMCI_TX_RX_STATS_FORMAT = `BaseTxArFrames: {{.BaseTxArFrames}}
182BaseRxAkFrames: {{.BaseRxAkFrames}}
183BaseTxNoArFrames: {{.BaseTxNoArFrames}}
184BaseRxNoAkFrames: {{.BaseRxNoAkFrames}}
185ExtTxArFrames: {{.ExtTxArFrames}}
186ExtRxAkFrames: {{.ExtRxAkFrames}}
187ExtTxNoArFrames: {{.ExtTxNoArFrames}}
188ExtRxNoAkFrames: {{.ExtRxNoAkFrames}}
189TxOmciCounterRetries: {{.TxOmciCounterRetries}}
190TxOmciCounterTimeouts: {{.TxOmciCounterTimeouts}}`
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +0530191 DEFAULT_ONU_STATS_FROM_OLT_FORMAT = `AllocId: {{.AllocId}}
192AllocRxBytes: {{.AllocRxBytes}}
193{{range .GemPortStats}}
194-GemId: {{.GemId}}
195 RxPackets: {{.RxPackets}}
196 RxBytes: {{.RxBytes}}
197 TxPackets: {{.TxPackets}}
198 TxBytes: {{.TxBytes}}{{end}}`
Akash Reddy Kankanala6965c652025-10-15 23:30:16 +0530199 DEFAULT_ONU_FEC_HISTORY_FORMAT = `CorrectedBytes: {{.CorrectedBytes}}
balaji.nagarajan8a2a7ee2026-06-19 22:31:13 +0530200CorrectedCodeWords: {{.CorrectedCodeWords}}
201FecSeconds: {{.FecSeconds}}
202TotalCodeWords: {{.TotalCodeWords}}
203UncorrectableCodeWords: {{.UncorrectableCodeWords}}
204FecCorrectedBytes_64: {{.FecCorrectedBytes_64}}
205FecCorrectedCodeWords_64: {{.FecCorrectedCodeWords_64}}
206TotalCodeWords_64: {{.TotalCodeWords_64}}
207UncorrectableCodeWords_64: {{.UncorrectableCodeWords_64}}`
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +0530208
209 DEFAULT_ONU_DISTANCE_FORMAT = `Distance`
210 DEFAULT_DEVICE_ALARMS_FORMAT = "table{{ .ClassId }}\t{{.InstanceId}}\t{{.Name}}\t{{.Description}}"
211 DEFAULT_DEVICE_ALARMS_ORDER = "ClassId,InstanceId"
212 DEFAULT_PON_RX_POWER_STATUS_FORMAT = "table{{.OnuSn}}\t{{.Status}}\t{{.FailReason}}\t{{.RxPower}}\t"
213 DEFAULT_DEVICE_VALUE_GEM_PORT_FORMAT = `AllocId: {{.AllocId}}
214 AllocRxBytes: {{.AllocRxBytes}}
215 {{range .GemHistoryStats}}
balaji.nagarajan8a2a7ee2026-06-19 22:31:13 +0530216-GemId: {{.GemId}}
217 TransmittedGEMFrames: {{.TransmittedGEMFrames}}
218 ReceivedGEMFrames: {{.ReceivedGEMFrames}}
219 ReceivedPayloadBytes: {{.ReceivedPayloadBytes}}
220 TransmittedPayloadBytes: {{.TransmittedPayloadBytes}}
221 EncryptionKeyErrors: {{.EncryptionKeyErrors}}{{end}}`
balaji.nagarajan1f7c6392026-05-22 16:16:30 +0530222 DEFAULT_OFFLOAD_APP_STATS_DHCPv4_FORMAT = `AdditionalStats:
223{{index . "additional_stats"}}
224InBadPacketsFromClient: {{index . "in_bad_packets_from_client"}}
225InBadPacketsFromServer: {{index . "in_bad_packets_from_server"}}
226InPacketsFromClient: {{index . "in_packets_from_client"}}
227InPacketsFromServer: {{index . "in_packets_from_server"}}
228OutPacketsToServer: {{index . "out_packets_to_server"}}
229OutPacketsToClient: {{index . "out_packets_to_client"}}
230Option_82InsertedPacketsToServer: {{index . "option_82_inserted_packets_to_server"}}
231Option_82RemovedPacketsToClient: {{index . "option_82_removed_packets_to_client"}}
232Option_82NotInsertedToServer: {{index . "option_82_not_inserted_to_server"}}`
233 DEFAULT_OFFLOAD_APP_STATS_DHCPv6_FORMAT = `AdditionalStats:
234{{index . "additional_stats"}}
235InBadPacketsFromClient: {{index . "in_bad_packets_from_client"}}
236InBadPacketsFromServer: {{index . "in_bad_packets_from_server"}}
237Option_17InsertedPacketsToServer: {{index . "option_17_inserted_packets_to_server"}}
238Option_17RemovedPacketsToClient: {{index . "option_17_removed_packets_to_client"}}
239Option_18InsertedPacketsToServer: {{index . "option_18_inserted_packets_to_server"}}
240Option_18RemovedPacketsToClient: {{index . "option_18_removed_packets_to_client"}}
241Option_37InsertedPacketsToServer: {{index . "option_37_inserted_packets_to_server"}}
242Option_37RemovedPacketsToClient: {{index . "option_37_removed_packets_to_client"}}
243OutgoingMtuExceededPacketsFromClient: {{index . "outgoing_mtu_exceeded_packets_from_client"}}`
244 DEFAULT_OFFLOAD_APP_STATS_PPPOE_IA_FORMAT = `AdditionalStats:
245{{index . "additional_stats"}}
246InErrorPacketsFromClient: {{index . "in_error_packets_from_client"}}
247InErrorPacketsFromServer: {{index . "in_error_packets_from_server"}}
248InPacketsFromClient: {{index . "in_packets_from_client"}}
249InPacketsFromServer: {{index . "in_packets_from_server"}}
250OutPacketsToServer: {{index . "out_packets_to_server"}}
251OutPacketsToClient: {{index . "out_packets_to_client"}}
252VendorSpecificTagInsertedPacketsToServer: {{index . "vendor_specific_tag_inserted_packets_to_server"}}
253VendorSpecificTagRemovedPacketsToClient: {{index . "vendor_specific_tag_removed_packets_to_client"}}
254OutgoingMtuExceededPacketsFromClient: {{index . "outgoing_mtu_exceeded_packets_from_client"}}`
Zack Williamse940c7a2019-08-21 14:25:39 -0700255)
256
257type DeviceList struct {
258 ListOutputOptions
259}
260
Akash Reddy Kankanala501ef802026-07-15 16:43:09 +0530261type DeviceUpdate struct {
262 ListOutputOptions
263 Args struct {
264 Id string `positional-arg-name:"DEVICE_ID" required:"yes"`
265 AddressType string `positional-arg-name:"ADDRESS_TYPE" required:"yes" choice:"IPV4" choice:"IPV6" choice:"HOST_AND_PORT"`
266 Address string `positional-arg-name:"HOST_AND_PORT" required:"yes"`
267 } `positional-args:"yes"`
268}
269
Zack Williamse940c7a2019-08-21 14:25:39 -0700270type DeviceCreate struct {
David Bainbridge1a514392020-06-23 11:12:51 -0700271 DeviceType string `short:"t" required:"true" long:"devicetype" description:"Device type"`
David Bainbridge835dd0e2020-04-01 10:30:09 -0700272 MACAddress string `short:"m" long:"macaddress" default:"" description:"MAC Address"`
Zack Williamse940c7a2019-08-21 14:25:39 -0700273 IPAddress string `short:"i" long:"ipaddress" default:"" description:"IP Address"`
274 HostAndPort string `short:"H" long:"hostandport" default:"" description:"Host and port"`
275}
276
277type DeviceId string
Akash Soni66db9632024-04-15 09:05:15 +0530278type OnuId string
Zack Williamse940c7a2019-08-21 14:25:39 -0700279
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000280type MetricName string
281type GroupName string
kesavand12cd8eb2020-01-20 22:25:22 -0500282type PortNum uint32
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -0800283type ValueFlag string
kesavand12cd8eb2020-01-20 22:25:22 -0500284
Zack Williamse940c7a2019-08-21 14:25:39 -0700285type DeviceDelete struct {
Himani Chawla9933ddc2020-10-12 23:53:27 +0530286 Force bool `long:"force" description:"Delete device forcefully"`
287 Args struct {
Zack Williamse940c7a2019-08-21 14:25:39 -0700288 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
289 } `positional-args:"yes"`
290}
291
292type DeviceEnable struct {
293 Args struct {
294 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
295 } `positional-args:"yes"`
296}
297
298type DeviceDisable struct {
299 Args struct {
300 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
301 } `positional-args:"yes"`
302}
303
304type DeviceReboot struct {
305 Args struct {
306 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
307 } `positional-args:"yes"`
308}
309
310type DeviceFlowList struct {
311 ListOutputOptions
Maninder045921e2020-09-29 16:46:02 +0530312 FlowIdOptions
Zack Williamse940c7a2019-08-21 14:25:39 -0700313 Args struct {
314 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
315 } `positional-args:"yes"`
316}
317
Himani Chawla3c161c62021-05-13 16:36:51 +0530318type DeviceFlowGroupList struct {
319 ListOutputOptions
320 GroupListOptions
321 Args struct {
322 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
323 } `positional-args:"yes"`
324}
Zack Williamse940c7a2019-08-21 14:25:39 -0700325type DevicePortList struct {
326 ListOutputOptions
327 Args struct {
328 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
329 } `positional-args:"yes"`
330}
331
332type DeviceInspect struct {
333 OutputOptionsJson
334 Args struct {
335 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
336 } `positional-args:"yes"`
337}
338
kesavand12cd8eb2020-01-20 22:25:22 -0500339type DevicePortEnable struct {
340 Args struct {
341 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
342 PortId PortNum `positional-arg-name:"PORT_NUMBER" required:"yes"`
343 } `positional-args:"yes"`
344}
345
346type DevicePortDisable struct {
347 Args struct {
348 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
349 PortId PortNum `positional-arg-name:"PORT_NUMBER" required:"yes"`
350 } `positional-args:"yes"`
351}
352
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000353type DevicePmConfigsGet struct {
354 ListOutputOptions
355 Args struct {
356 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
357 } `positional-args:"yes"`
358}
359
360type DevicePmConfigMetricList struct {
361 ListOutputOptions
362 Args struct {
363 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
364 } `positional-args:"yes"`
365}
366
367type DevicePmConfigGroupList struct {
368 ListOutputOptions
369 Args struct {
370 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
371 } `positional-args:"yes"`
372}
373
374type DevicePmConfigGroupMetricList struct {
375 ListOutputOptions
376 Args struct {
377 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
378 Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"`
379 } `positional-args:"yes"`
380}
381
382type DevicePmConfigFrequencySet struct {
383 OutputOptions
384 Args struct {
Girish Gowdra610acb42021-01-27 13:33:57 -0800385 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
386 Interval time.Duration `positional-arg-name:"INTERVAL" required:"yes"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000387 } `positional-args:"yes"`
388}
389
390type DevicePmConfigMetricEnable struct {
391 Args struct {
392 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
393 Metrics []MetricName `positional-arg-name:"METRIC_NAME" required:"yes"`
394 } `positional-args:"yes"`
395}
396
397type DevicePmConfigMetricDisable struct {
398 Args struct {
399 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
400 Metrics []MetricName `positional-arg-name:"METRIC_NAME" required:"yes"`
401 } `positional-args:"yes"`
402}
403
404type DevicePmConfigGroupEnable struct {
405 Args struct {
Girish Gowdra610acb42021-01-27 13:33:57 -0800406 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
407 Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000408 } `positional-args:"yes"`
409}
410
411type DevicePmConfigGroupDisable struct {
412 Args struct {
Girish Gowdra610acb42021-01-27 13:33:57 -0800413 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
414 Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"`
415 } `positional-args:"yes"`
416}
417
418type DevicePmConfigGroupFrequencySet struct {
419 OutputOptions
420 Args struct {
421 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
422 Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"`
423 Interval time.Duration `positional-arg-name:"INTERVAL" required:"yes"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000424 } `positional-args:"yes"`
425}
426
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -0800427type DeviceGetExtValue struct {
428 ListOutputOptions
429 Args struct {
430 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
431 Valueflag ValueFlag `positional-arg-name:"VALUE_FLAG" required:"yes"`
432 } `positional-args:"yes"`
433}
Rohan Agrawald7df3772020-06-29 11:23:36 +0000434
435type DevicePmConfigSetMaxSkew struct {
436 Args struct {
437 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
438 MaxSkew uint32 `positional-arg-name:"MAX_SKEW" required:"yes"`
439 } `positional-args:"yes"`
440}
441
Andrea Campanella791d88b2021-01-08 13:29:00 +0100442type DeviceOnuListImages struct {
443 ListOutputOptions
444 Args struct {
445 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
446 } `positional-args:"yes"`
447}
448
449type DeviceOnuDownloadImage struct {
450 Args struct {
451 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
452 Name string `positional-arg-name:"IMAGE_NAME" required:"yes"`
453 Url string `positional-arg-name:"IMAGE_URL" required:"yes"`
454 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
455 Crc uint32 `positional-arg-name:"IMAGE_CRC" required:"yes"`
456 LocalDir string `positional-arg-name:"IMAGE_LOCAL_DIRECTORY"`
457 } `positional-args:"yes"`
458}
459
460type DeviceOnuActivateImageUpdate struct {
461 Args struct {
462 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
463 Name string `positional-arg-name:"IMAGE_NAME" required:"yes"`
464 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
465 SaveConfig bool `positional-arg-name:"SAVE_EXISTING_CONFIG"`
466 LocalDir string `positional-arg-name:"IMAGE_LOCAL_DIRECTORY"`
Andrea Campanella7b2ecf42021-02-25 12:27:15 +0100467 } `positional-args:"yes"`
kesavand8ec4fc02021-01-27 09:10:22 -0500468}
kesavand3e2f9f62021-04-22 11:06:38 +0530469
470type OnuDownloadImage struct {
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +0200471 ListOutputOptions
kesavand3e2f9f62021-04-22 11:06:38 +0530472 Args struct {
473 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
474 Url string `positional-arg-name:"IMAGE_URL" required:"yes"`
ssiddiqui7bc89e92021-05-20 20:58:02 +0530475 Vendor string `positional-arg-name:"IMAGE_VENDOR"`
kesavand3e2f9f62021-04-22 11:06:38 +0530476 ActivateOnSuccess bool `positional-arg-name:"IMAGE_ACTIVATE_ON_SUCCESS"`
477 CommitOnSuccess bool `positional-arg-name:"IMAGE_COMMIT_ON_SUCCESS"`
478 Crc uint32 `positional-arg-name:"IMAGE_CRC"`
479 IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
480 } `positional-args:"yes"`
481}
482
483type OnuActivateImage struct {
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +0200484 ListOutputOptions
kesavand3e2f9f62021-04-22 11:06:38 +0530485 Args struct {
486 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
487 CommitOnSuccess bool `positional-arg-name:"IMAGE_COMMIT_ON_SUCCESS"`
488 IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
489 } `positional-args:"yes"`
490}
491
492type OnuAbortUpgradeImage struct {
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +0200493 ListOutputOptions
kesavand3e2f9f62021-04-22 11:06:38 +0530494 Args struct {
495 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
496 IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
497 } `positional-args:"yes"`
498}
499
500type OnuCommitImage struct {
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +0200501 ListOutputOptions
kesavand3e2f9f62021-04-22 11:06:38 +0530502 Args struct {
503 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
504 IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
505 } `positional-args:"yes"`
506}
507
508type OnuImageStatus struct {
509 ListOutputOptions
510 Args struct {
511 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
Elia Battiston859f3e62022-02-08 15:57:52 +0100512 IDs []DeviceId `positional-arg-name:"DEVICE_ID"`
kesavand3e2f9f62021-04-22 11:06:38 +0530513 } `positional-args:"yes"`
514}
515
516type OnuListImages struct {
517 ListOutputOptions
518 Args struct {
519 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
520 } `positional-args:"yes"`
521}
522
kesavand8ec4fc02021-01-27 09:10:22 -0500523type DeviceGetPortStats struct {
524 ListOutputOptions
525 Args struct {
526 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
527 PortNo uint32 `positional-arg-name:"PORT_NO" required:"yes"`
528 PortType string `positional-arg-name:"PORT_TYPE" required:"yes"`
Andrea Campanella791d88b2021-01-08 13:29:00 +0100529 } `positional-args:"yes"`
530}
kesavand6d1131f2021-02-05 22:38:15 +0530531type UniStatus struct {
532 ListOutputOptions
533 Args struct {
534 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
535 UniIndex uint32 `positional-arg-name:"UNI_INDEX" required:"yes"`
536 } `positional-args:"yes"`
537}
Girish Gowdra4f5ce7c2021-04-29 18:53:21 -0700538type OnuPonOpticalInfo struct {
539 ListOutputOptions
540 Args struct {
541 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
542 } `positional-args:"yes"`
543}
Himani Chawla40acc122021-05-26 18:52:29 +0530544
545type GetOnuStats struct {
546 ListOutputOptions
547 Args struct {
548 OltId DeviceId `positional-arg-name:"OLT_DEVICE_ID" required:"yes"`
549 IntfId uint32 `positional-arg-name:"PON_INTF_ID" required:"yes"`
550 OnuId uint32 `positional-arg-name:"ONU_ID" required:"yes"`
551 } `positional-args:"yes"`
552}
553
Akash Soni6e879c22024-12-20 17:01:34 +0530554type GetOffloadApp struct {
Akash Soni51b6b7a2024-11-20 11:39:38 +0530555 ListOutputOptions
556 Args struct {
557 OltId DeviceId `positional-arg-name:"OLT_DEVICE_ID" required:"yes"`
558 StatsFor extension.GetOffloadedAppsStatisticsRequest_OffloadedApp `positional-arg-name:"OFFLOADED_APP" required:"yes"`
559 } `positional-args:"yes"`
560}
561
Akash Soni6e879c22024-12-20 17:01:34 +0530562type SetOffloadApp struct {
563 ListOutputOptions
Akash Soni51b6b7a2024-11-20 11:39:38 +0530564 Args struct {
Akash Soni6e879c22024-12-20 17:01:34 +0530565 OltId DeviceId `positional-arg-name:"OLT_DEVICE_ID" required:"yes"`
566 Config string `positional-arg-name:"CONFIG" required:"yes"` // Accept JSON or CSV input
Akash Soni51b6b7a2024-11-20 11:39:38 +0530567 } `positional-args:"yes"`
568}
569
Akash Soni6e879c22024-12-20 17:01:34 +0530570type AppOffloadOnuConfig struct {
571 AgentRemoteID string
572 AgentCircuitID string
573 OnuUniId uint32
574}
575
576type SetOnuOffload struct {
577 ListOutputOptions
Akash Soni51b6b7a2024-11-20 11:39:38 +0530578 Args struct {
Akash Soni6e879c22024-12-20 17:01:34 +0530579 OltId DeviceId `positional-arg-name:"OLT_DEVICE_ID" required:"yes"`
580 OnuDeviceId string `positional-arg-name:"ONU_DEVICE_ID" required:"yes"`
581 PerUniInfo string `positional-arg-name:"PER_UNI_INFO" json:"per_uni_info" required:"yes"` // Accept list as JSON or CSV
Akash Soni51b6b7a2024-11-20 11:39:38 +0530582 } `positional-args:"yes"`
583}
584
Himani Chawla553a1392021-06-10 23:39:17 +0530585type GetOnuEthernetFrameExtendedPmCounters struct {
586 ListOutputOptions
Himani Chawla806aa892021-08-30 15:51:46 +0530587 Reset bool `long:"reset" description:"Reset the counters"`
588 Args struct {
589 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
590 UniIndex *uint32 `positional-arg-name:"UNI_INDEX"`
Himani Chawla553a1392021-06-10 23:39:17 +0530591 } `positional-args:"yes"`
592}
593
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +0530594type GetPonPortStats struct {
595 ListOutputOptions
596 Reset bool `long:"reset" description:"Reset the counters"`
597 Args struct {
598 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
599 PortLabel string `positional-arg-name:"PORT_LABEL" required:"yes"`
600 } `positional-args:"yes"`
601}
602
603type GetNniPortStats struct {
604 ListOutputOptions
605 Reset bool `long:"reset" description:"Reset the counters"`
606 Args struct {
607 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
608 PortLabel string `positional-arg-name:"PORT_LABEL" required:"yes"`
609 } `positional-args:"yes"`
610}
611
612type GetOnuAllocGemStatsFromOlt struct {
613 ListOutputOptions
614 Args struct {
615 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
616 } `positional-args:"yes"`
617}
Gamze Abakac857a462021-05-26 13:45:54 +0000618type RxPower struct {
619 ListOutputOptions
620 Args struct {
621 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
622 PortNo uint32 `positional-arg-name:"PORT_NO" required:"yes"`
623 OnuNo uint32 `positional-arg-name:"ONU_NO" required:"yes"`
624 } `positional-args:"yes"`
625}
626
praneeth nalmas39c71ad2023-09-27 18:29:04 +0530627type PonRxPower struct {
628 ListOutputOptions
629 Args struct {
630 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
631 PortLabel string `positional-arg-name:"PORT_LABEL" required:"yes"`
632 SerialNo string `positional-arg-name:"ONU_SERIAL_NUMBER"`
633 } `positional-args:"yes"`
634}
635
serkantul3d22fc72022-09-14 12:22:56 +0300636type OnuOmciTxRxStats struct {
637 ListOutputOptions
638 Args struct {
639 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
640 } `positional-args:"yes"`
641}
642
praneeth nalmas1dd094c2022-12-22 14:15:13 +0530643type GetOnuOmciActiveAlarms struct {
644 ListOutputOptions
645 Args struct {
646 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
647 } `positional-args:"yes"`
648}
649
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +0530650type GetOnuGEMStats struct {
651 ListOutputOptions
652 Args struct {
653 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
654 } `positional-args:"yes"`
655}
656
Akash Reddy Kankanala6965c652025-10-15 23:30:16 +0530657type GetOnuFecHistory struct {
658 ListOutputOptions
659 Args struct {
660 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
661 } `positional-args:"yes"`
662}
Akash Soni66db9632024-04-15 09:05:15 +0530663type GetOnuDistance struct {
664 ListOutputOptions
665 Args struct {
666 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
667 OnuId OnuId `positional-arg-name:"ONU_ID" required:"yes"`
668 } `positional-args:"yes"` //onu device id
669}
670
mgouda35b90e62025-07-16 14:58:29 +0530671type DisableOnuDevice struct {
672 Args struct {
673 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
674 } `positional-args:"yes"`
675}
676
677type EnableOnuDevice struct {
678 Args struct {
679 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
680 } `positional-args:"yes"`
681}
682
683type DisableOnuSerialNumber struct {
684 Args struct {
685 SerialNumber string `positional-arg-name:"ONU_SERIAL_NUMBER" required:"yes"`
686 Port PortNum `positional-arg-name:"PORT_NO" required:"yes"`
687 OltDeviceId DeviceId `positional-arg-name:"OLT_DEVICE_ID" required:"yes"`
688 } `positional-args:"yes"`
689}
690
691type EnableOnuSerialNumber struct {
692 Args struct {
693 SerialNumber string `positional-arg-name:"ONU_SERIAL_NUMBER" required:"yes"`
694 Port PortNum `positional-arg-name:"PORT_NO" required:"yes"`
695 OltDeviceId DeviceId `positional-arg-name:"OLT_DEVICE_ID" required:"yes"`
696 } `positional-args:"yes"`
697}
698
Zack Williamse940c7a2019-08-21 14:25:39 -0700699type DeviceOpts struct {
mgouda35b90e62025-07-16 14:58:29 +0530700 List DeviceList `command:"list"`
701 Create DeviceCreate `command:"create"`
702 Delete DeviceDelete `command:"delete"`
703 Enable DeviceEnable `command:"enable"`
704 Disable DeviceDisable `command:"disable"`
705 DisableOnuDevice DisableOnuDevice `command:"disable_onu"`
706 EnableOnuDevice EnableOnuDevice `command:"enable_onu"`
707 DisableOnuSerialNumber DisableOnuSerialNumber `command:"disable_onu_serial"`
708 EnableOnuSerialNumber EnableOnuSerialNumber `command:"enable_onu_serial"`
709 Flows DeviceFlowList `command:"flows"`
710 Groups DeviceFlowGroupList `command:"groups"`
Akash Reddy Kankanala501ef802026-07-15 16:43:09 +0530711 Update DeviceUpdate `command:"update"`
mgouda35b90e62025-07-16 14:58:29 +0530712 Port struct {
kesavand12cd8eb2020-01-20 22:25:22 -0500713 List DevicePortList `command:"list"`
714 Enable DevicePortEnable `command:"enable"`
715 Disable DevicePortDisable `command:"disable"`
716 } `command:"port"`
717 Inspect DeviceInspect `command:"inspect"`
718 Reboot DeviceReboot `command:"reboot"`
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -0800719 Value struct {
720 Get DeviceGetExtValue `command:"get"`
721 } `command:"value"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000722 PmConfig struct {
Rohan Agrawald7df3772020-06-29 11:23:36 +0000723 Get DevicePmConfigsGet `command:"get"`
724 MaxSkew struct {
725 Set DevicePmConfigSetMaxSkew `command:"set"`
726 } `command:"maxskew"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000727 Frequency struct {
728 Set DevicePmConfigFrequencySet `command:"set"`
729 } `command:"frequency"`
730 Metric struct {
731 List DevicePmConfigMetricList `command:"list"`
732 Enable DevicePmConfigMetricEnable `command:"enable"`
733 Disable DevicePmConfigMetricDisable `command:"disable"`
734 } `command:"metric"`
735 Group struct {
Girish Gowdra610acb42021-01-27 13:33:57 -0800736 List DevicePmConfigGroupList `command:"list"`
737 Enable DevicePmConfigGroupEnable `command:"enable"`
738 Disable DevicePmConfigGroupDisable `command:"disable"`
739 Set DevicePmConfigGroupFrequencySet `command:"set"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000740 } `command:"group"`
741 GroupMetric struct {
742 List DevicePmConfigGroupMetricList `command:"list"`
743 } `command:"groupmetric"`
744 } `command:"pmconfig"`
Andrea Campanella791d88b2021-01-08 13:29:00 +0100745 Image struct {
746 Get DeviceOnuListImages `command:"list"`
747 Download DeviceOnuDownloadImage `command:"download"`
748 Activate DeviceOnuActivateImageUpdate `command:"activate"`
749 } `command:"image"`
kesavand3e2f9f62021-04-22 11:06:38 +0530750 DownloadImage struct {
751 Download OnuDownloadImage `command:"download"`
752 Activate OnuActivateImage `command:"activate"`
753 Commit OnuCommitImage `command:"commit"`
754 AbortUpgrade OnuAbortUpgradeImage `command:"abort"`
755 Status OnuImageStatus `command:"status"`
756 List OnuListImages `command:"list" `
757 } `command:"onuimage"`
kesavand8ec4fc02021-01-27 09:10:22 -0500758 GetExtVal struct {
Himani Chawla553a1392021-06-10 23:39:17 +0530759 Stats DeviceGetPortStats `command:"portstats"`
760 UniStatus UniStatus `command:"unistatus"`
761 OpticalInfo OnuPonOpticalInfo `command:"onu_pon_optical_info"`
762 OnuStats GetOnuStats `command:"onu_stats"`
763 EthernetFrameExtendedPm GetOnuEthernetFrameExtendedPmCounters `command:"ethernet_frame_extended_pm"`
764 RxPower RxPower `command:"rxpower"`
serkantul3d22fc72022-09-14 12:22:56 +0300765 OnuOmciStats OnuOmciTxRxStats `command:"onu_omci_stats"`
praneeth nalmas1dd094c2022-12-22 14:15:13 +0530766 OnuOmciActiveAlarms GetOnuOmciActiveAlarms `command:"onu_omci_active_alarms"`
praneeth nalmas39c71ad2023-09-27 18:29:04 +0530767 PonRxPower PonRxPower `command:"pon_rx_power"`
Akash Soni66db9632024-04-15 09:05:15 +0530768 OnuDistance GetOnuDistance `command:"onu_distance"`
Akash Soni6e879c22024-12-20 17:01:34 +0530769 OffloadAppStats GetOffloadApp `command:"offload_app_stats"`
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +0530770 PonStats GetPonPortStats `command:"itu_pon_stats"`
771 NniStats GetNniPortStats `command:"nni_statistics"`
772 OnuGEMStats GetOnuGEMStats `command:"onu_gem_stats"`
773 OnuAllocGemStats GetOnuAllocGemStatsFromOlt `command:"onu_alloc_gem_from_olt"`
Akash Reddy Kankanala6965c652025-10-15 23:30:16 +0530774 OnuFecHistory GetOnuFecHistory `command:"onu_fec_history"`
kesavand8ec4fc02021-01-27 09:10:22 -0500775 } `command:"getextval"`
Akash Soni51b6b7a2024-11-20 11:39:38 +0530776 SetExtVal struct {
Akash Soni6e879c22024-12-20 17:01:34 +0530777 OffloadAppStatsSet SetOffloadApp `command:"set_offload_app"`
778 OnuOffloadStatsSet SetOnuOffload `command:"set_onu_offload"`
Akash Soni51b6b7a2024-11-20 11:39:38 +0530779 } `command:"setextval"`
Zack Williamse940c7a2019-08-21 14:25:39 -0700780}
781
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +0530782type AllocGemStatsFromOlt struct {
783 AllocId uint32
784 AllocRxBytes uint64
785 GemPortStats []GemPortStatsFromOlt
786}
787type GemPortStatsFromOlt struct {
788 GemId uint32
789 RxPackets uint64
790 RxBytes uint64
791 TxPackets uint64
792 TxBytes uint64
793}
794type onugemstats struct {
795 AllocId uint32
796 AllocRxBytes uint32
797 GemHistoryStats []gemHistoryStats
798}
799type gemHistoryStats struct {
800 GemId uint32
801 TransmittedGEMFrames uint32
802 ReceivedGEMFrames uint32
Akash Reddy Kankanalaeba72f62026-01-29 12:49:17 +0000803 ReceivedPayloadBytes uint64
804 TransmittedPayloadBytes uint64
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +0530805 EncryptionKeyErrors uint32
806}
807
808type PortStats struct {
809 PonPort uint32 // use this for PON
810 NniPort uint32 // use this for NNI
811 *common.PortStatistics
812}
813
Zack Williamse940c7a2019-08-21 14:25:39 -0700814var deviceOpts = DeviceOpts{}
815
816func RegisterDeviceCommands(parser *flags.Parser) {
David Bainbridge12f036f2019-10-15 22:09:04 +0000817 if _, err := parser.AddCommand("device", "device commands", "Commands to query and manipulate VOLTHA devices", &deviceOpts); err != nil {
David Bainbridgea6722342019-10-24 23:55:53 +0000818 Error.Fatalf("Unexpected error while attempting to register device commands : %s", err)
David Bainbridge12f036f2019-10-15 22:09:04 +0000819 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700820}
821
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000822func (i *MetricName) Complete(match string) []flags.Completion {
823 conn, err := NewConnection()
824 if err != nil {
825 return nil
826 }
827 defer conn.Close()
828
829 client := voltha.NewVolthaServiceClient(conn)
830
831 var deviceId string
832found:
833 for i := len(os.Args) - 1; i >= 0; i -= 1 {
834 switch os.Args[i] {
835 case "enable":
836 fallthrough
837 case "disable":
838 if len(os.Args) > i+1 {
839 deviceId = os.Args[i+1]
840 } else {
841 return nil
842 }
843 break found
844 default:
845 }
846 }
847
848 if len(deviceId) == 0 {
849 return nil
850 }
851
David K. Bainbridge9189c632021-03-26 21:52:21 +0000852 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000853 defer cancel()
854
855 id := voltha.ID{Id: string(deviceId)}
856
857 pmconfigs, err := client.ListDevicePmConfigs(ctx, &id)
858
859 if err != nil {
860 return nil
861 }
862
863 list := make([]flags.Completion, 0)
864 for _, metrics := range pmconfigs.Metrics {
865 if strings.HasPrefix(metrics.Name, match) {
866 list = append(list, flags.Completion{Item: metrics.Name})
867 }
868 }
869
870 return list
871}
872
873func (i *GroupName) Complete(match string) []flags.Completion {
874 conn, err := NewConnection()
875 if err != nil {
876 return nil
877 }
878 defer conn.Close()
879
880 client := voltha.NewVolthaServiceClient(conn)
881
882 var deviceId string
883found:
884 for i := len(os.Args) - 1; i >= 0; i -= 1 {
885 switch os.Args[i] {
886 case "list":
887 fallthrough
888 case "enable":
889 fallthrough
890 case "disable":
891 if len(os.Args) > i+1 {
892 deviceId = os.Args[i+1]
893 } else {
894 return nil
895 }
896 break found
897 default:
898 }
899 }
900
901 if len(deviceId) == 0 {
902 return nil
903 }
904
David K. Bainbridge9189c632021-03-26 21:52:21 +0000905 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000906 defer cancel()
907
908 id := voltha.ID{Id: string(deviceId)}
909
910 pmconfigs, err := client.ListDevicePmConfigs(ctx, &id)
911
912 if err != nil {
913 return nil
914 }
915
916 list := make([]flags.Completion, 0)
917 for _, group := range pmconfigs.Groups {
918 if strings.HasPrefix(group.GroupName, match) {
919 list = append(list, flags.Completion{Item: group.GroupName})
920 }
921 }
922 return list
923}
924
kesavand12cd8eb2020-01-20 22:25:22 -0500925func (i *PortNum) Complete(match string) []flags.Completion {
926 conn, err := NewConnection()
927 if err != nil {
928 return nil
929 }
930 defer conn.Close()
931
Scott Baker9173ed82020-05-19 08:30:12 -0700932 client := voltha.NewVolthaServiceClient(conn)
kesavand12cd8eb2020-01-20 22:25:22 -0500933
934 /*
935 * The command line args when completing for PortNum will be a DeviceId
936 * followed by one or more PortNums. So walk the argument list from the
937 * end and find the first argument that is enable/disable as those are
938 * the subcommands that come before the positional arguments. It would
939 * be nice if this package gave us the list of optional arguments
940 * already parsed.
941 */
942 var deviceId string
943found:
944 for i := len(os.Args) - 1; i >= 0; i -= 1 {
945 switch os.Args[i] {
946 case "enable":
947 fallthrough
948 case "disable":
949 if len(os.Args) > i+1 {
950 deviceId = os.Args[i+1]
951 } else {
952 return nil
953 }
954 break found
955 default:
956 }
957 }
958
959 if len(deviceId) == 0 {
960 return nil
961 }
962
David K. Bainbridge9189c632021-03-26 21:52:21 +0000963 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand12cd8eb2020-01-20 22:25:22 -0500964 defer cancel()
kesavand12cd8eb2020-01-20 22:25:22 -0500965
Scott Baker9173ed82020-05-19 08:30:12 -0700966 id := voltha.ID{Id: string(deviceId)}
kesavand12cd8eb2020-01-20 22:25:22 -0500967
Scott Baker9173ed82020-05-19 08:30:12 -0700968 ports, err := client.ListDevicePorts(ctx, &id)
kesavand12cd8eb2020-01-20 22:25:22 -0500969 if err != nil {
970 return nil
971 }
972
973 list := make([]flags.Completion, 0)
Scott Baker9173ed82020-05-19 08:30:12 -0700974 for _, item := range ports.Items {
975 pn := strconv.FormatUint(uint64(item.PortNo), 10)
kesavand12cd8eb2020-01-20 22:25:22 -0500976 if strings.HasPrefix(pn, match) {
977 list = append(list, flags.Completion{Item: pn})
978 }
979 }
980
981 return list
982}
983
Zack Williamse940c7a2019-08-21 14:25:39 -0700984func (i *DeviceId) Complete(match string) []flags.Completion {
985 conn, err := NewConnection()
986 if err != nil {
987 return nil
988 }
989 defer conn.Close()
990
Scott Baker9173ed82020-05-19 08:30:12 -0700991 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700992
David K. Bainbridge9189c632021-03-26 21:52:21 +0000993 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700994 defer cancel()
995
Scott Baker9173ed82020-05-19 08:30:12 -0700996 devices, err := client.ListDevices(ctx, &empty.Empty{})
Zack Williamse940c7a2019-08-21 14:25:39 -0700997 if err != nil {
998 return nil
999 }
1000
1001 list := make([]flags.Completion, 0)
Scott Baker9173ed82020-05-19 08:30:12 -07001002 for _, item := range devices.Items {
1003 if strings.HasPrefix(item.Id, match) {
1004 list = append(list, flags.Completion{Item: item.Id})
Zack Williamse940c7a2019-08-21 14:25:39 -07001005 }
1006 }
1007
1008 return list
1009}
1010
1011func (options *DeviceList) Execute(args []string) error {
1012
1013 conn, err := NewConnection()
1014 if err != nil {
1015 return err
1016 }
1017 defer conn.Close()
1018
Scott Baker9173ed82020-05-19 08:30:12 -07001019 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -07001020
David K. Bainbridge9189c632021-03-26 21:52:21 +00001021 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -07001022 defer cancel()
1023
Scott Baker9173ed82020-05-19 08:30:12 -07001024 devices, err := client.ListDevices(ctx, &empty.Empty{})
Zack Williamse940c7a2019-08-21 14:25:39 -07001025 if err != nil {
1026 return err
1027 }
1028
1029 outputFormat := CharReplacer.Replace(options.Format)
1030 if outputFormat == "" {
David Bainbridgea6722342019-10-24 23:55:53 +00001031 outputFormat = GetCommandOptionWithDefault("device-list", "format", DEFAULT_DEVICE_FORMAT)
Zack Williamse940c7a2019-08-21 14:25:39 -07001032 }
1033 if options.Quiet {
1034 outputFormat = "{{.Id}}"
1035 }
1036
David Bainbridgea6722342019-10-24 23:55:53 +00001037 orderBy := options.OrderBy
1038 if orderBy == "" {
Hardik Windlass9361bb82022-03-23 05:58:48 +00001039 orderBy = GetCommandOptionWithDefault("device-list", "order", DEFAULT_DEVICE_ORDER)
David Bainbridgea6722342019-10-24 23:55:53 +00001040 }
1041
Scott Baker9173ed82020-05-19 08:30:12 -07001042 // Make sure json output prints an empty list, not "null"
1043 if devices.Items == nil {
1044 devices.Items = make([]*voltha.Device, 0)
Zack Williamse940c7a2019-08-21 14:25:39 -07001045 }
1046
1047 result := CommandResult{
1048 Format: format.Format(outputFormat),
1049 Filter: options.Filter,
David Bainbridgea6722342019-10-24 23:55:53 +00001050 OrderBy: orderBy,
Zack Williamse940c7a2019-08-21 14:25:39 -07001051 OutputAs: toOutputType(options.OutputAs),
1052 NameLimit: options.NameLimit,
Scott Baker9173ed82020-05-19 08:30:12 -07001053 Data: devices.Items,
Zack Williamse940c7a2019-08-21 14:25:39 -07001054 }
1055
1056 GenerateOutput(&result)
1057 return nil
1058}
1059
1060func (options *DeviceCreate) Execute(args []string) error {
1061
Scott Baker9173ed82020-05-19 08:30:12 -07001062 device := voltha.Device{}
Zack Williamse940c7a2019-08-21 14:25:39 -07001063 if options.HostAndPort != "" {
Scott Baker9173ed82020-05-19 08:30:12 -07001064 device.Address = &voltha.Device_HostAndPort{HostAndPort: options.HostAndPort}
Zack Williamse940c7a2019-08-21 14:25:39 -07001065 } else if options.IPAddress != "" {
Scott Baker9173ed82020-05-19 08:30:12 -07001066 device.Address = &voltha.Device_Ipv4Address{Ipv4Address: options.IPAddress}
Hardik Windlassce1de342020-02-04 21:58:07 +00001067 }
1068 if options.MACAddress != "" {
Scott Baker9173ed82020-05-19 08:30:12 -07001069 device.MacAddress = strings.ToLower(options.MACAddress)
Zack Williamse940c7a2019-08-21 14:25:39 -07001070 }
1071 if options.DeviceType != "" {
Scott Baker9173ed82020-05-19 08:30:12 -07001072 device.Type = options.DeviceType
Zack Williamse940c7a2019-08-21 14:25:39 -07001073 }
1074
1075 conn, err := NewConnection()
1076 if err != nil {
1077 return err
1078 }
1079 defer conn.Close()
1080
Scott Baker9173ed82020-05-19 08:30:12 -07001081 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -07001082
David K. Bainbridge9189c632021-03-26 21:52:21 +00001083 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -07001084 defer cancel()
1085
Scott Baker9173ed82020-05-19 08:30:12 -07001086 createdDevice, err := client.CreateDevice(ctx, &device)
Zack Williamse940c7a2019-08-21 14:25:39 -07001087 if err != nil {
1088 return err
Zack Williamse940c7a2019-08-21 14:25:39 -07001089 }
1090
Scott Baker9173ed82020-05-19 08:30:12 -07001091 fmt.Printf("%s\n", createdDevice.Id)
Zack Williamse940c7a2019-08-21 14:25:39 -07001092
1093 return nil
1094}
1095
1096func (options *DeviceDelete) Execute(args []string) error {
1097
1098 conn, err := NewConnection()
1099 if err != nil {
1100 return err
1101 }
1102 defer conn.Close()
1103
Scott Baker9173ed82020-05-19 08:30:12 -07001104 client := voltha.NewVolthaServiceClient(conn)
David Bainbridge7052fe82020-03-25 10:37:00 -07001105 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -07001106 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +00001107 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -07001108 defer cancel()
1109
Scott Baker9173ed82020-05-19 08:30:12 -07001110 id := voltha.ID{Id: string(i)}
Himani Chawla9933ddc2020-10-12 23:53:27 +05301111 if options.Force {
1112 _, err = client.ForceDeleteDevice(ctx, &id)
1113 } else {
1114 _, err = client.DeleteDevice(ctx, &id)
1115 }
Scott Baker9173ed82020-05-19 08:30:12 -07001116
Zack Williamse940c7a2019-08-21 14:25:39 -07001117 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +00001118 Error.Printf("Error while deleting '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -07001119 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -07001120 continue
Zack Williamse940c7a2019-08-21 14:25:39 -07001121 }
1122 fmt.Printf("%s\n", i)
1123 }
1124
David Bainbridge7052fe82020-03-25 10:37:00 -07001125 if lastErr != nil {
1126 return NoReportErr
1127 }
Zack Williamse940c7a2019-08-21 14:25:39 -07001128 return nil
1129}
1130
1131func (options *DeviceEnable) Execute(args []string) error {
1132 conn, err := NewConnection()
1133 if err != nil {
1134 return err
1135 }
1136 defer conn.Close()
1137
Scott Baker9173ed82020-05-19 08:30:12 -07001138 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -07001139
David Bainbridge7052fe82020-03-25 10:37:00 -07001140 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -07001141 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +00001142 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -07001143 defer cancel()
1144
Scott Baker9173ed82020-05-19 08:30:12 -07001145 id := voltha.ID{Id: string(i)}
1146
1147 _, err := client.EnableDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -07001148 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +00001149 Error.Printf("Error while enabling '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -07001150 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -07001151 continue
Zack Williamse940c7a2019-08-21 14:25:39 -07001152 }
1153 fmt.Printf("%s\n", i)
1154 }
1155
David Bainbridge7052fe82020-03-25 10:37:00 -07001156 if lastErr != nil {
1157 return NoReportErr
1158 }
Zack Williamse940c7a2019-08-21 14:25:39 -07001159 return nil
1160}
1161
1162func (options *DeviceDisable) Execute(args []string) error {
1163 conn, err := NewConnection()
1164 if err != nil {
1165 return err
1166 }
1167 defer conn.Close()
1168
Scott Baker9173ed82020-05-19 08:30:12 -07001169 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -07001170
David Bainbridge7052fe82020-03-25 10:37:00 -07001171 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -07001172 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +00001173 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -07001174 defer cancel()
1175
Scott Baker9173ed82020-05-19 08:30:12 -07001176 id := voltha.ID{Id: string(i)}
1177
1178 _, err := client.DisableDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -07001179 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +00001180 Error.Printf("Error while disabling '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -07001181 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -07001182 continue
Zack Williamse940c7a2019-08-21 14:25:39 -07001183 }
1184 fmt.Printf("%s\n", i)
1185 }
1186
David Bainbridge7052fe82020-03-25 10:37:00 -07001187 if lastErr != nil {
1188 return NoReportErr
1189 }
Zack Williamse940c7a2019-08-21 14:25:39 -07001190 return nil
1191}
1192
1193func (options *DeviceReboot) Execute(args []string) error {
1194 conn, err := NewConnection()
1195 if err != nil {
1196 return err
1197 }
1198 defer conn.Close()
1199
Scott Baker9173ed82020-05-19 08:30:12 -07001200 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -07001201
David Bainbridge7052fe82020-03-25 10:37:00 -07001202 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -07001203 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +00001204 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -07001205 defer cancel()
1206
Scott Baker9173ed82020-05-19 08:30:12 -07001207 id := voltha.ID{Id: string(i)}
1208
1209 _, err := client.RebootDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -07001210 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +00001211 Error.Printf("Error while rebooting '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -07001212 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -07001213 continue
Zack Williamse940c7a2019-08-21 14:25:39 -07001214 }
1215 fmt.Printf("%s\n", i)
1216 }
1217
David Bainbridge7052fe82020-03-25 10:37:00 -07001218 if lastErr != nil {
1219 return NoReportErr
1220 }
Zack Williamse940c7a2019-08-21 14:25:39 -07001221 return nil
1222}
1223
1224func (options *DevicePortList) Execute(args []string) error {
1225
1226 conn, err := NewConnection()
1227 if err != nil {
1228 return err
1229 }
1230 defer conn.Close()
1231
Scott Baker9173ed82020-05-19 08:30:12 -07001232 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -07001233
David K. Bainbridge9189c632021-03-26 21:52:21 +00001234 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -07001235 defer cancel()
1236
Scott Baker9173ed82020-05-19 08:30:12 -07001237 id := voltha.ID{Id: string(options.Args.Id)}
Zack Williamse940c7a2019-08-21 14:25:39 -07001238
Scott Baker9173ed82020-05-19 08:30:12 -07001239 ports, err := client.ListDevicePorts(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -07001240 if err != nil {
1241 return err
1242 }
1243
1244 outputFormat := CharReplacer.Replace(options.Format)
1245 if outputFormat == "" {
David Bainbridgea6722342019-10-24 23:55:53 +00001246 outputFormat = GetCommandOptionWithDefault("device-ports", "format", DEFAULT_DEVICE_PORTS_FORMAT)
Zack Williamse940c7a2019-08-21 14:25:39 -07001247 }
Zack Williamse940c7a2019-08-21 14:25:39 -07001248
David Bainbridgea6722342019-10-24 23:55:53 +00001249 orderBy := options.OrderBy
1250 if orderBy == "" {
1251 orderBy = GetCommandOptionWithDefault("device-ports", "order", "")
1252 }
1253
Zack Williamse940c7a2019-08-21 14:25:39 -07001254 result := CommandResult{
1255 Format: format.Format(outputFormat),
1256 Filter: options.Filter,
David Bainbridgea6722342019-10-24 23:55:53 +00001257 OrderBy: orderBy,
Zack Williamse940c7a2019-08-21 14:25:39 -07001258 OutputAs: toOutputType(options.OutputAs),
1259 NameLimit: options.NameLimit,
Scott Baker9173ed82020-05-19 08:30:12 -07001260 Data: ports.Items,
Zack Williamse940c7a2019-08-21 14:25:39 -07001261 }
1262
1263 GenerateOutput(&result)
1264 return nil
1265}
1266
1267func (options *DeviceFlowList) Execute(args []string) error {
1268 fl := &FlowList{}
1269 fl.ListOutputOptions = options.ListOutputOptions
Maninder045921e2020-09-29 16:46:02 +05301270 fl.FlowIdOptions = options.FlowIdOptions
Zack Williamse940c7a2019-08-21 14:25:39 -07001271 fl.Args.Id = string(options.Args.Id)
David Bainbridgea6722342019-10-24 23:55:53 +00001272 fl.Method = "device-flows"
Zack Williamse940c7a2019-08-21 14:25:39 -07001273 return fl.Execute(args)
1274}
1275
Himani Chawla3c161c62021-05-13 16:36:51 +05301276func (options *DeviceFlowGroupList) Execute(args []string) error {
1277 grp := &GroupList{}
1278 grp.ListOutputOptions = options.ListOutputOptions
1279 grp.GroupListOptions = options.GroupListOptions
1280 grp.Args.Id = string(options.Args.Id)
1281 grp.Method = "device-groups"
1282 return grp.Execute(args)
1283}
1284
Zack Williamse940c7a2019-08-21 14:25:39 -07001285func (options *DeviceInspect) Execute(args []string) error {
1286 if len(args) > 0 {
1287 return fmt.Errorf("only a single argument 'DEVICE_ID' can be provided")
1288 }
1289
1290 conn, err := NewConnection()
1291 if err != nil {
1292 return err
1293 }
1294 defer conn.Close()
1295
Scott Baker9173ed82020-05-19 08:30:12 -07001296 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -07001297
David K. Bainbridge9189c632021-03-26 21:52:21 +00001298 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -07001299 defer cancel()
1300
Scott Baker9173ed82020-05-19 08:30:12 -07001301 id := voltha.ID{Id: string(options.Args.Id)}
Zack Williamse940c7a2019-08-21 14:25:39 -07001302
Scott Baker9173ed82020-05-19 08:30:12 -07001303 device, err := client.GetDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -07001304 if err != nil {
1305 return err
1306 }
1307
Zack Williamse940c7a2019-08-21 14:25:39 -07001308 outputFormat := CharReplacer.Replace(options.Format)
1309 if outputFormat == "" {
David Bainbridgea6722342019-10-24 23:55:53 +00001310 outputFormat = GetCommandOptionWithDefault("device-inspect", "format", DEFAULT_DEVICE_INSPECT_FORMAT)
Zack Williamse940c7a2019-08-21 14:25:39 -07001311 }
1312 if options.Quiet {
1313 outputFormat = "{{.Id}}"
1314 }
1315
1316 result := CommandResult{
1317 Format: format.Format(outputFormat),
1318 OutputAs: toOutputType(options.OutputAs),
1319 NameLimit: options.NameLimit,
1320 Data: device,
1321 }
1322 GenerateOutput(&result)
1323 return nil
1324}
kesavand12cd8eb2020-01-20 22:25:22 -05001325
1326/*Device Port Enable */
1327func (options *DevicePortEnable) Execute(args []string) error {
1328 conn, err := NewConnection()
1329 if err != nil {
1330 return err
1331 }
1332 defer conn.Close()
1333
Scott Baker9173ed82020-05-19 08:30:12 -07001334 client := voltha.NewVolthaServiceClient(conn)
kesavand12cd8eb2020-01-20 22:25:22 -05001335
David K. Bainbridge9189c632021-03-26 21:52:21 +00001336 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand12cd8eb2020-01-20 22:25:22 -05001337 defer cancel()
1338
Scott Baker9173ed82020-05-19 08:30:12 -07001339 port := voltha.Port{DeviceId: string(options.Args.Id), PortNo: uint32(options.Args.PortId)}
1340
1341 _, err = client.EnablePort(ctx, &port)
kesavand12cd8eb2020-01-20 22:25:22 -05001342 if err != nil {
1343 Error.Printf("Error enabling port number %v on device Id %s,err=%s\n", options.Args.PortId, options.Args.Id, ErrorToString(err))
1344 return err
kesavand12cd8eb2020-01-20 22:25:22 -05001345 }
1346
1347 return nil
1348}
1349
Scott Baker9173ed82020-05-19 08:30:12 -07001350/*Device Port Disable */
kesavand12cd8eb2020-01-20 22:25:22 -05001351func (options *DevicePortDisable) Execute(args []string) error {
1352 conn, err := NewConnection()
1353 if err != nil {
1354 return err
1355 }
1356 defer conn.Close()
1357
Scott Baker9173ed82020-05-19 08:30:12 -07001358 client := voltha.NewVolthaServiceClient(conn)
1359
David K. Bainbridge9189c632021-03-26 21:52:21 +00001360 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand12cd8eb2020-01-20 22:25:22 -05001361 defer cancel()
1362
Scott Baker9173ed82020-05-19 08:30:12 -07001363 port := voltha.Port{DeviceId: string(options.Args.Id), PortNo: uint32(options.Args.PortId)}
1364
1365 _, err = client.DisablePort(ctx, &port)
kesavand12cd8eb2020-01-20 22:25:22 -05001366 if err != nil {
Scott Baker9173ed82020-05-19 08:30:12 -07001367 Error.Printf("Error enabling port number %v on device Id %s,err=%s\n", options.Args.PortId, options.Args.Id, ErrorToString(err))
kesavand12cd8eb2020-01-20 22:25:22 -05001368 return err
kesavand12cd8eb2020-01-20 22:25:22 -05001369 }
Scott Baker9173ed82020-05-19 08:30:12 -07001370
kesavand12cd8eb2020-01-20 22:25:22 -05001371 return nil
1372}
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08001373
Rohan Agrawald7df3772020-06-29 11:23:36 +00001374func (options *DevicePmConfigSetMaxSkew) Execute(args []string) error {
1375 conn, err := NewConnection()
1376 if err != nil {
1377 return err
1378 }
1379 defer conn.Close()
1380
1381 client := voltha.NewVolthaServiceClient(conn)
1382
David K. Bainbridge9189c632021-03-26 21:52:21 +00001383 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawald7df3772020-06-29 11:23:36 +00001384 defer cancel()
1385
1386 id := voltha.ID{Id: string(options.Args.Id)}
1387
1388 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1389 if err != nil {
1390 return err
1391 }
1392
1393 pmConfigs.MaxSkew = options.Args.MaxSkew
1394
1395 _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs)
1396 if err != nil {
1397 return err
1398 }
1399
1400 return nil
1401}
1402
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001403func (options *DevicePmConfigsGet) Execute(args []string) error {
1404
1405 conn, err := NewConnection()
1406 if err != nil {
1407 return err
1408 }
1409 defer conn.Close()
1410
1411 client := voltha.NewVolthaServiceClient(conn)
1412
David K. Bainbridge9189c632021-03-26 21:52:21 +00001413 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001414 defer cancel()
1415
1416 id := voltha.ID{Id: string(options.Args.Id)}
1417
1418 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1419 if err != nil {
1420 return err
1421 }
1422
1423 outputFormat := CharReplacer.Replace(options.Format)
1424 if outputFormat == "" {
1425 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GET_FORMAT)
1426 }
1427
1428 orderBy := options.OrderBy
1429 if orderBy == "" {
1430 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1431 }
1432
1433 result := CommandResult{
1434 Format: format.Format(outputFormat),
1435 Filter: options.Filter,
1436 OrderBy: orderBy,
1437 OutputAs: toOutputType(options.OutputAs),
1438 NameLimit: options.NameLimit,
1439 Data: pmConfigs,
1440 }
1441
1442 GenerateOutput(&result)
1443 return nil
1444
1445}
1446
1447func (options *DevicePmConfigMetricList) Execute(args []string) error {
1448
1449 conn, err := NewConnection()
1450 if err != nil {
1451 return err
1452 }
1453 defer conn.Close()
1454
1455 client := voltha.NewVolthaServiceClient(conn)
1456
David K. Bainbridge9189c632021-03-26 21:52:21 +00001457 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001458 defer cancel()
1459
1460 id := voltha.ID{Id: string(options.Args.Id)}
1461
1462 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1463 if err != nil {
1464 return err
1465 }
1466
1467 if !pmConfigs.Grouped {
1468 for _, metric := range pmConfigs.Metrics {
1469 if metric.SampleFreq == 0 {
1470 metric.SampleFreq = pmConfigs.DefaultFreq
1471 }
1472 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001473 outputFormat := CharReplacer.Replace(options.Format)
1474 if outputFormat == "" {
1475 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_METRIC_LIST_FORMAT)
1476 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001477
Rohan Agrawalbca69122020-06-17 14:59:03 +00001478 orderBy := options.OrderBy
1479 if orderBy == "" {
1480 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1481 }
1482
1483 result := CommandResult{
1484 Format: format.Format(outputFormat),
1485 Filter: options.Filter,
1486 OrderBy: orderBy,
1487 OutputAs: toOutputType(options.OutputAs),
1488 NameLimit: options.NameLimit,
1489 Data: pmConfigs.Metrics,
1490 }
1491
1492 GenerateOutput(&result)
1493 return nil
1494 } else {
1495 return fmt.Errorf("Device '%s' does not have Non Grouped Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001496 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001497}
1498
1499func (options *DevicePmConfigMetricEnable) Execute(args []string) error {
1500
1501 conn, err := NewConnection()
1502 if err != nil {
1503 return err
1504 }
1505 defer conn.Close()
1506
1507 client := voltha.NewVolthaServiceClient(conn)
1508
David K. Bainbridge9189c632021-03-26 21:52:21 +00001509 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001510 defer cancel()
1511
1512 id := voltha.ID{Id: string(options.Args.Id)}
1513
1514 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1515 if err != nil {
1516 return err
1517 }
1518
1519 if !pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001520 metrics := make(map[string]struct{})
1521 for _, metric := range pmConfigs.Metrics {
1522 metrics[metric.Name] = struct{}{}
1523 }
1524
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001525 for _, metric := range pmConfigs.Metrics {
1526 for _, mName := range options.Args.Metrics {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001527 if _, exist := metrics[string(mName)]; !exist {
1528 return fmt.Errorf("Metric Name '%s' does not exist", mName)
1529 }
1530
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001531 if string(mName) == metric.Name && !metric.Enabled {
1532 metric.Enabled = true
1533 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1534 if err != nil {
1535 return err
1536 }
1537 }
1538 }
1539 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001540 } else {
1541 return fmt.Errorf("Device '%s' does not have Non Grouped Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001542 }
1543 return nil
1544}
1545
1546func (options *DevicePmConfigMetricDisable) Execute(args []string) error {
1547
1548 conn, err := NewConnection()
1549 if err != nil {
1550 return err
1551 }
1552 defer conn.Close()
1553
1554 client := voltha.NewVolthaServiceClient(conn)
1555
David K. Bainbridge9189c632021-03-26 21:52:21 +00001556 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001557 defer cancel()
1558
1559 id := voltha.ID{Id: string(options.Args.Id)}
1560
1561 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1562 if err != nil {
1563 return err
1564 }
1565
1566 if !pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001567 metrics := make(map[string]struct{})
1568 for _, metric := range pmConfigs.Metrics {
1569 metrics[metric.Name] = struct{}{}
1570 }
1571
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001572 for _, metric := range pmConfigs.Metrics {
1573 for _, mName := range options.Args.Metrics {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001574 if _, have := metrics[string(mName)]; !have {
1575 return fmt.Errorf("Metric Name '%s' does not exist", mName)
1576 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001577 if string(mName) == metric.Name && metric.Enabled {
1578 metric.Enabled = false
1579 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1580 if err != nil {
1581 return err
1582 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001583 } else {
1584 return fmt.Errorf("Metric '%s' cannot be disabled", string(mName))
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001585 }
1586 }
1587 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001588 } else {
1589 return fmt.Errorf("Device '%s' does not have Non Grouped Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001590 }
1591 return nil
1592}
1593
1594func (options *DevicePmConfigGroupEnable) Execute(args []string) error {
1595
1596 conn, err := NewConnection()
1597 if err != nil {
1598 return err
1599 }
1600 defer conn.Close()
1601
1602 client := voltha.NewVolthaServiceClient(conn)
1603
David K. Bainbridge9189c632021-03-26 21:52:21 +00001604 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001605 defer cancel()
1606
1607 id := voltha.ID{Id: string(options.Args.Id)}
1608
1609 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1610 if err != nil {
1611 return err
1612 }
1613
1614 if pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001615 groups := make(map[string]struct{})
1616 for _, group := range pmConfigs.Groups {
1617 groups[group.GroupName] = struct{}{}
1618 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001619 for _, group := range pmConfigs.Groups {
Girish Gowdra610acb42021-01-27 13:33:57 -08001620 if _, have := groups[string(options.Args.Group)]; !have {
1621 return fmt.Errorf("Group Name '%s' does not exist", options.Args.Group)
1622 }
1623 if string(options.Args.Group) == group.GroupName && !group.Enabled {
1624 group.Enabled = true
1625 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1626 if err != nil {
1627 return err
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001628 }
1629 }
1630 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001631 } else {
1632 return fmt.Errorf("Device '%s' does not have Group Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001633 }
1634 return nil
1635}
1636
1637func (options *DevicePmConfigGroupDisable) Execute(args []string) error {
1638
1639 conn, err := NewConnection()
1640 if err != nil {
1641 return err
1642 }
1643 defer conn.Close()
1644
1645 client := voltha.NewVolthaServiceClient(conn)
1646
David K. Bainbridge9189c632021-03-26 21:52:21 +00001647 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001648 defer cancel()
1649
1650 id := voltha.ID{Id: string(options.Args.Id)}
1651
1652 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1653 if err != nil {
1654 return err
1655 }
1656
1657 if pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001658 groups := make(map[string]struct{})
1659 for _, group := range pmConfigs.Groups {
1660 groups[group.GroupName] = struct{}{}
1661 }
1662
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001663 for _, group := range pmConfigs.Groups {
Girish Gowdra610acb42021-01-27 13:33:57 -08001664 if _, have := groups[string(options.Args.Group)]; !have {
1665 return fmt.Errorf("Group Name '%s' does not exist", options.Args.Group)
1666 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001667
Girish Gowdra610acb42021-01-27 13:33:57 -08001668 if string(options.Args.Group) == group.GroupName && group.Enabled {
1669 group.Enabled = false
1670 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1671 if err != nil {
1672 return err
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001673 }
1674 }
1675 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001676 } else {
1677 return fmt.Errorf("Device '%s' does not have Group Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001678 }
1679 return nil
1680}
1681
Girish Gowdra610acb42021-01-27 13:33:57 -08001682func (options *DevicePmConfigGroupFrequencySet) Execute(args []string) error {
1683
1684 conn, err := NewConnection()
1685 if err != nil {
1686 return err
1687 }
1688 defer conn.Close()
1689
1690 client := voltha.NewVolthaServiceClient(conn)
1691
David K. Bainbridge9189c632021-03-26 21:52:21 +00001692 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Girish Gowdra610acb42021-01-27 13:33:57 -08001693 defer cancel()
1694
1695 id := voltha.ID{Id: string(options.Args.Id)}
1696
1697 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1698 if err != nil {
1699 return err
1700 }
1701
1702 if pmConfigs.Grouped {
1703 groups := make(map[string]struct{})
1704 for _, group := range pmConfigs.Groups {
1705 groups[group.GroupName] = struct{}{}
1706 }
1707
1708 for _, group := range pmConfigs.Groups {
1709 if _, have := groups[string(options.Args.Group)]; !have {
1710 return fmt.Errorf("group name '%s' does not exist", options.Args.Group)
1711 }
1712
1713 if string(options.Args.Group) == group.GroupName {
1714 if !group.Enabled {
1715 return fmt.Errorf("group '%s' is not enabled", options.Args.Group)
1716 }
1717 group.GroupFreq = uint32(options.Args.Interval.Seconds())
1718 _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs)
1719 if err != nil {
1720 return err
1721 }
1722 }
1723 }
1724 } else {
1725 return fmt.Errorf("device '%s' does not have group metrics", options.Args.Id)
1726 }
1727 return nil
1728}
1729
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001730func (options *DevicePmConfigGroupList) Execute(args []string) error {
1731
1732 conn, err := NewConnection()
1733 if err != nil {
1734 return err
1735 }
1736 defer conn.Close()
1737
1738 client := voltha.NewVolthaServiceClient(conn)
1739
David K. Bainbridge9189c632021-03-26 21:52:21 +00001740 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001741 defer cancel()
1742
1743 id := voltha.ID{Id: string(options.Args.Id)}
1744
1745 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1746 if err != nil {
1747 return err
1748 }
1749
1750 if pmConfigs.Grouped {
1751 for _, group := range pmConfigs.Groups {
1752 if group.GroupFreq == 0 {
1753 group.GroupFreq = pmConfigs.DefaultFreq
1754 }
1755 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001756 outputFormat := CharReplacer.Replace(options.Format)
1757 if outputFormat == "" {
1758 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GROUP_LIST_FORMAT)
1759 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001760
Rohan Agrawalbca69122020-06-17 14:59:03 +00001761 orderBy := options.OrderBy
1762 if orderBy == "" {
1763 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1764 }
1765
1766 result := CommandResult{
1767 Format: format.Format(outputFormat),
1768 Filter: options.Filter,
1769 OrderBy: orderBy,
1770 OutputAs: toOutputType(options.OutputAs),
1771 NameLimit: options.NameLimit,
1772 Data: pmConfigs.Groups,
1773 }
1774
1775 GenerateOutput(&result)
1776 } else {
1777 return fmt.Errorf("Device '%s' does not have Group Metrics", string(options.Args.Id))
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001778 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001779 return nil
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001780}
1781
1782func (options *DevicePmConfigGroupMetricList) Execute(args []string) error {
1783
1784 var metrics []*voltha.PmConfig
1785 conn, err := NewConnection()
1786 if err != nil {
1787 return err
1788 }
1789 defer conn.Close()
1790
1791 client := voltha.NewVolthaServiceClient(conn)
1792
David K. Bainbridge9189c632021-03-26 21:52:21 +00001793 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001794 defer cancel()
1795
1796 id := voltha.ID{Id: string(options.Args.Id)}
1797
1798 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1799 if err != nil {
1800 return err
1801 }
1802
1803 for _, groups := range pmConfigs.Groups {
1804
1805 if string(options.Args.Group) == groups.GroupName {
1806 for _, metric := range groups.Metrics {
1807 if metric.SampleFreq == 0 && groups.GroupFreq == 0 {
1808 metric.SampleFreq = pmConfigs.DefaultFreq
1809 } else {
1810 metric.SampleFreq = groups.GroupFreq
1811 }
1812 }
1813 metrics = groups.Metrics
1814 }
1815 }
1816
1817 outputFormat := CharReplacer.Replace(options.Format)
1818 if outputFormat == "" {
1819 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_METRIC_LIST_FORMAT)
1820 }
1821
1822 orderBy := options.OrderBy
1823 if orderBy == "" {
1824 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1825 }
1826
1827 result := CommandResult{
1828 Format: format.Format(outputFormat),
1829 Filter: options.Filter,
1830 OrderBy: orderBy,
1831 OutputAs: toOutputType(options.OutputAs),
1832 NameLimit: options.NameLimit,
1833 Data: metrics,
1834 }
1835
1836 GenerateOutput(&result)
1837 return nil
1838
1839}
1840
1841func (options *DevicePmConfigFrequencySet) Execute(args []string) error {
1842
1843 conn, err := NewConnection()
1844 if err != nil {
1845 return err
1846 }
1847 defer conn.Close()
1848
1849 client := voltha.NewVolthaServiceClient(conn)
1850
David K. Bainbridge9189c632021-03-26 21:52:21 +00001851 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001852 defer cancel()
1853
1854 id := voltha.ID{Id: string(options.Args.Id)}
1855
1856 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1857 if err != nil {
1858 return err
1859 }
1860
Girish Gowdra610acb42021-01-27 13:33:57 -08001861 pmConfigs.DefaultFreq = uint32(options.Args.Interval.Seconds())
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001862
1863 _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs)
1864 if err != nil {
1865 return err
1866 }
1867
1868 outputFormat := CharReplacer.Replace(options.Format)
1869 if outputFormat == "" {
1870 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GET_FORMAT)
1871 }
1872 if options.Quiet {
1873 outputFormat = "{{.Id}}"
1874 }
1875
1876 result := CommandResult{
1877 Format: format.Format(outputFormat),
1878 OutputAs: toOutputType(options.OutputAs),
1879 NameLimit: options.NameLimit,
1880 Data: pmConfigs,
1881 }
1882
1883 GenerateOutput(&result)
1884 return nil
1885
1886}
1887
kesavand3e2f9f62021-04-22 11:06:38 +05301888func (options *OnuDownloadImage) Execute(args []string) error {
1889
1890 conn, err := NewConnection()
1891 if err != nil {
1892 return err
1893 }
1894 defer conn.Close()
1895
1896 client := voltha.NewVolthaServiceClient(conn)
1897
1898 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1899 defer cancel()
1900
1901 var devIDList []*common.ID
1902 for _, i := range options.Args.IDs {
1903
1904 devIDList = append(devIDList, &common.ID{Id: string(i)})
1905 }
1906
1907 downloadImage := voltha.DeviceImageDownloadRequest{
1908 DeviceId: devIDList,
1909 Image: &voltha.Image{
1910 Url: options.Args.Url,
1911 Crc32: options.Args.Crc,
ssiddiqui7bc89e92021-05-20 20:58:02 +05301912 Vendor: options.Args.Vendor,
kesavand3e2f9f62021-04-22 11:06:38 +05301913 Version: options.Args.ImageVersion,
1914 },
1915 ActivateOnSuccess: options.Args.ActivateOnSuccess,
1916 CommitOnSuccess: options.Args.CommitOnSuccess,
1917 }
1918
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001919 deviceImageResp, err := client.DownloadImageToDevice(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301920 if err != nil {
1921 return err
1922 }
1923
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001924 outputFormat := GetCommandOptionWithDefault("onu-image-download", "format", ONU_IMAGE_STATUS_FORMAT)
1925 // Make sure json output prints an empty list, not "null"
1926 if deviceImageResp.DeviceImageStates == nil {
1927 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1928 }
1929 result := CommandResult{
1930 Format: format.Format(outputFormat),
1931 OutputAs: toOutputType(options.OutputAs),
1932 NameLimit: options.NameLimit,
1933 Data: deviceImageResp.DeviceImageStates,
1934 }
1935 GenerateOutput(&result)
kesavand3e2f9f62021-04-22 11:06:38 +05301936 return nil
1937
1938}
1939
1940func (options *OnuActivateImage) Execute(args []string) error {
1941
1942 conn, err := NewConnection()
1943 if err != nil {
1944 return err
1945 }
1946 defer conn.Close()
1947
1948 client := voltha.NewVolthaServiceClient(conn)
1949
1950 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1951 defer cancel()
1952
1953 var devIDList []*common.ID
1954 for _, i := range options.Args.IDs {
1955
1956 devIDList = append(devIDList, &common.ID{Id: string(i)})
1957 }
1958
1959 downloadImage := voltha.DeviceImageRequest{
1960 DeviceId: devIDList,
1961 Version: options.Args.ImageVersion,
1962 CommitOnSuccess: options.Args.CommitOnSuccess,
1963 }
1964
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001965 deviceImageResp, err := client.ActivateImage(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301966 if err != nil {
1967 return err
1968 }
1969
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001970 outputFormat := GetCommandOptionWithDefault("onu-image-activate", "format", ONU_IMAGE_STATUS_FORMAT)
1971 // Make sure json output prints an empty list, not "null"
1972 if deviceImageResp.DeviceImageStates == nil {
1973 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1974 }
1975 result := CommandResult{
1976 Format: format.Format(outputFormat),
1977 OutputAs: toOutputType(options.OutputAs),
1978 NameLimit: options.NameLimit,
1979 Data: deviceImageResp.DeviceImageStates,
1980 }
1981 GenerateOutput(&result)
1982
kesavand3e2f9f62021-04-22 11:06:38 +05301983 return nil
1984
1985}
1986
1987func (options *OnuAbortUpgradeImage) Execute(args []string) error {
1988
1989 conn, err := NewConnection()
1990 if err != nil {
1991 return err
1992 }
1993 defer conn.Close()
1994
1995 client := voltha.NewVolthaServiceClient(conn)
1996
1997 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1998 defer cancel()
1999
2000 var devIDList []*common.ID
2001 for _, i := range options.Args.IDs {
2002
2003 devIDList = append(devIDList, &common.ID{Id: string(i)})
2004 }
2005
2006 downloadImage := voltha.DeviceImageRequest{
2007 DeviceId: devIDList,
2008 Version: options.Args.ImageVersion,
2009 }
2010
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02002011 deviceImageResp, err := client.AbortImageUpgradeToDevice(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05302012 if err != nil {
2013 return err
2014 }
2015
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02002016 outputFormat := GetCommandOptionWithDefault("onu-image-abort", "format", ONU_IMAGE_STATUS_FORMAT)
2017 // Make sure json output prints an empty list, not "null"
2018 if deviceImageResp.DeviceImageStates == nil {
2019 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
2020 }
2021 result := CommandResult{
2022 Format: format.Format(outputFormat),
2023 OutputAs: toOutputType(options.OutputAs),
2024 NameLimit: options.NameLimit,
2025 Data: deviceImageResp.DeviceImageStates,
2026 }
2027 GenerateOutput(&result)
2028
kesavand3e2f9f62021-04-22 11:06:38 +05302029 return nil
2030
2031}
2032
2033func (options *OnuCommitImage) Execute(args []string) error {
2034
2035 conn, err := NewConnection()
2036 if err != nil {
2037 return err
2038 }
2039 defer conn.Close()
2040
2041 client := voltha.NewVolthaServiceClient(conn)
2042
2043 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2044 defer cancel()
2045
2046 var devIDList []*common.ID
2047 for _, i := range options.Args.IDs {
2048
2049 devIDList = append(devIDList, &common.ID{Id: string(i)})
2050 }
2051 downloadImage := voltha.DeviceImageRequest{
2052 DeviceId: devIDList,
2053 Version: options.Args.ImageVersion,
2054 }
2055
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02002056 deviceImageResp, err := client.CommitImage(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05302057 if err != nil {
2058 return err
2059 }
2060
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02002061 outputFormat := GetCommandOptionWithDefault("onu-image-commit", "format", ONU_IMAGE_STATUS_FORMAT)
2062 // Make sure json output prints an empty list, not "null"
2063 if deviceImageResp.DeviceImageStates == nil {
2064 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
2065 }
2066 result := CommandResult{
2067 Format: format.Format(outputFormat),
2068 OutputAs: toOutputType(options.OutputAs),
2069 NameLimit: options.NameLimit,
2070 Data: deviceImageResp.DeviceImageStates,
2071 }
2072 GenerateOutput(&result)
2073
kesavand3e2f9f62021-04-22 11:06:38 +05302074 return nil
2075
2076}
2077
2078func (options *OnuListImages) Execute(args []string) error {
2079
2080 conn, err := NewConnection()
2081 if err != nil {
2082 return err
2083 }
2084 defer conn.Close()
2085
2086 client := voltha.NewVolthaServiceClient(conn)
2087
2088 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2089 defer cancel()
2090
2091 id := common.ID{Id: string(options.Args.Id)}
2092
2093 onuImages, err := client.GetOnuImages(ctx, &id)
2094 if err != nil {
2095 return err
2096 }
2097
2098 outputFormat := CharReplacer.Replace(options.Format)
2099 if outputFormat == "" {
2100 outputFormat = GetCommandOptionWithDefault("onu-image-list", "format", ONU_IMAGE_LIST_FORMAT)
2101 }
2102
2103 if options.Quiet {
2104 outputFormat = "{{.Id}}"
2105 }
2106
2107 //TODO orderby
2108
2109 // Make sure json output prints an empty list, not "null"
2110 if onuImages.Items == nil {
2111 onuImages.Items = make([]*voltha.OnuImage, 0)
2112 }
2113
2114 result := CommandResult{
2115 Format: format.Format(outputFormat),
2116 OutputAs: toOutputType(options.OutputAs),
2117 NameLimit: options.NameLimit,
2118 Data: onuImages.Items,
2119 }
2120
2121 GenerateOutput(&result)
2122 return nil
2123
2124}
2125
2126func (options *OnuImageStatus) Execute(args []string) error {
2127
2128 conn, err := NewConnection()
2129 if err != nil {
2130 return err
2131 }
2132 defer conn.Close()
2133
2134 client := voltha.NewVolthaServiceClient(conn)
2135
2136 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2137 defer cancel()
2138
2139 var devIDList []*common.ID
kesavand3e2f9f62021-04-22 11:06:38 +05302140
Elia Battiston859f3e62022-02-08 15:57:52 +01002141 if options.Args.IDs == nil {
2142 //Use an empty IDs list to retrieve the status of all devices
2143 //with the requested image version
2144 devIDList = []*common.ID{}
2145 } else {
2146 for _, i := range options.Args.IDs {
2147 devIDList = append(devIDList, &common.ID{Id: string(i)})
2148 }
kesavand3e2f9f62021-04-22 11:06:38 +05302149 }
2150
2151 imageStatusReq := voltha.DeviceImageRequest{
2152 DeviceId: devIDList,
2153 Version: options.Args.ImageVersion,
2154 }
2155 imageStatus, err := client.GetImageStatus(ctx, &imageStatusReq)
2156 if err != nil {
2157 return err
2158 }
2159
2160 outputFormat := CharReplacer.Replace(options.Format)
2161 if outputFormat == "" {
2162 outputFormat = GetCommandOptionWithDefault("device-image-list", "format", ONU_IMAGE_STATUS_FORMAT)
2163 }
2164
2165 if options.Quiet {
2166 outputFormat = "{{.Id}}"
2167 }
2168
2169 //TODO orderby
2170
2171 // Make sure json output prints an empty list, not "null"
2172 if imageStatus.DeviceImageStates == nil {
2173 imageStatus.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
2174 }
2175
2176 result := CommandResult{
2177 Format: format.Format(outputFormat),
2178 OutputAs: toOutputType(options.OutputAs),
2179 NameLimit: options.NameLimit,
2180 Data: imageStatus.DeviceImageStates,
2181 }
2182
2183 GenerateOutput(&result)
2184 return nil
2185
2186}
2187
Andrea Campanella791d88b2021-01-08 13:29:00 +01002188func (options *DeviceOnuListImages) Execute(args []string) error {
2189
2190 conn, err := NewConnection()
2191 if err != nil {
2192 return err
2193 }
2194 defer conn.Close()
2195
2196 client := voltha.NewVolthaServiceClient(conn)
2197
David K. Bainbridge9189c632021-03-26 21:52:21 +00002198 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Andrea Campanella791d88b2021-01-08 13:29:00 +01002199 defer cancel()
2200
2201 id := common.ID{Id: string(options.Args.Id)}
2202
2203 imageDownloads, err := client.ListImageDownloads(ctx, &id)
2204 if err != nil {
2205 return err
2206 }
2207
2208 outputFormat := CharReplacer.Replace(options.Format)
2209 if outputFormat == "" {
2210 outputFormat = GetCommandOptionWithDefault("device-image-list", "format", DEFAULT_DEVICE_IMAGE_LIST_GET_FORMAT)
2211 }
2212
2213 if options.Quiet {
2214 outputFormat = "{{.Id}}"
2215 }
2216
2217 //TODO orderby
2218
2219 // Make sure json output prints an empty list, not "null"
2220 if imageDownloads.Items == nil {
2221 imageDownloads.Items = make([]*voltha.ImageDownload, 0)
2222 }
2223
2224 result := CommandResult{
2225 Format: format.Format(outputFormat),
2226 OutputAs: toOutputType(options.OutputAs),
2227 NameLimit: options.NameLimit,
2228 Data: imageDownloads.Items,
2229 }
2230
2231 GenerateOutput(&result)
2232 return nil
2233
2234}
2235
2236func (options *DeviceOnuDownloadImage) Execute(args []string) error {
2237
2238 conn, err := NewConnection()
2239 if err != nil {
2240 return err
2241 }
2242 defer conn.Close()
2243
2244 client := voltha.NewVolthaServiceClient(conn)
2245
David K. Bainbridge9189c632021-03-26 21:52:21 +00002246 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Andrea Campanella791d88b2021-01-08 13:29:00 +01002247 defer cancel()
2248
2249 downloadImage := voltha.ImageDownload{
2250 Id: string(options.Args.Id),
2251 Name: options.Args.Name,
2252 Url: options.Args.Url,
2253 Crc: options.Args.Crc,
2254 LocalDir: options.Args.LocalDir,
2255 }
2256
2257 _, err = client.DownloadImage(ctx, &downloadImage)
2258 if err != nil {
2259 return err
2260 }
2261
2262 return nil
2263
2264}
2265
2266func (options *DeviceOnuActivateImageUpdate) Execute(args []string) error {
2267
2268 conn, err := NewConnection()
2269 if err != nil {
2270 return err
2271 }
2272 defer conn.Close()
2273
2274 client := voltha.NewVolthaServiceClient(conn)
2275
David K. Bainbridge9189c632021-03-26 21:52:21 +00002276 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Andrea Campanella791d88b2021-01-08 13:29:00 +01002277 defer cancel()
2278
2279 downloadImage := voltha.ImageDownload{
2280 Id: string(options.Args.Id),
2281 Name: options.Args.Name,
2282 ImageVersion: options.Args.ImageVersion,
2283 SaveConfig: options.Args.SaveConfig,
2284 LocalDir: options.Args.LocalDir,
2285 }
2286
2287 _, err = client.ActivateImageUpdate(ctx, &downloadImage)
2288 if err != nil {
2289 return err
2290 }
2291
2292 return nil
2293
2294}
2295
Scott Baker9173ed82020-05-19 08:30:12 -07002296type ReturnValueRow struct {
2297 Name string `json:"name"`
2298 Result interface{} `json:"result"`
2299}
2300
kesavand8ec4fc02021-01-27 09:10:22 -05002301func (options *DeviceGetPortStats) Execute(args []string) error {
2302 conn, err := NewConnection()
2303 if err != nil {
2304 return err
2305 }
2306 defer conn.Close()
2307 client := extension.NewExtensionClient(conn)
2308 var portType extension.GetOltPortCounters_PortType
2309
2310 if options.Args.PortType == "pon" {
2311 portType = extension.GetOltPortCounters_Port_PON_OLT
2312 } else if options.Args.PortType == "nni" {
2313
2314 portType = extension.GetOltPortCounters_Port_ETHERNET_NNI
2315 } else {
2316 return fmt.Errorf("expected interface type pon/nni, provided %s", options.Args.PortType)
2317 }
2318
2319 singleGetValReq := extension.SingleGetValueRequest{
2320 TargetId: string(options.Args.Id),
2321 Request: &extension.GetValueRequest{
2322 Request: &extension.GetValueRequest_OltPortInfo{
2323 OltPortInfo: &extension.GetOltPortCounters{
2324 PortNo: options.Args.PortNo,
2325 PortType: portType,
2326 },
2327 },
2328 },
2329 }
2330
David K. Bainbridge9189c632021-03-26 21:52:21 +00002331 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand8ec4fc02021-01-27 09:10:22 -05002332 defer cancel()
2333 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2334 if err != nil {
2335 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2336 return err
2337 }
2338
2339 if rv.Response.Status != extension.GetValueResponse_OK {
2340 return fmt.Errorf("failed to get port stats %v", rv.Response.ErrReason.String())
2341 }
2342
2343 outputFormat := CharReplacer.Replace(options.Format)
2344 if outputFormat == "" {
2345 outputFormat = GetCommandOptionWithDefault("device-get-port-status", "format", DEFAULT_DEVICE_GET_PORT_STATUS_FORMAT)
2346 }
2347
2348 result := CommandResult{
2349 Format: format.Format(outputFormat),
2350 OutputAs: toOutputType(options.OutputAs),
2351 NameLimit: options.NameLimit,
2352 Data: rv.GetResponse().GetPortCoutners(),
2353 }
2354 GenerateOutput(&result)
2355 return nil
2356}
2357
Himani Chawla40acc122021-05-26 18:52:29 +05302358func (options *GetOnuStats) Execute(args []string) error {
2359 conn, err := NewConnection()
2360 if err != nil {
2361 return err
2362 }
2363 defer conn.Close()
2364 client := extension.NewExtensionClient(conn)
2365
2366 singleGetValReq := extension.SingleGetValueRequest{
2367 TargetId: string(options.Args.OltId),
2368 Request: &extension.GetValueRequest{
2369 Request: &extension.GetValueRequest_OnuPonInfo{
2370 OnuPonInfo: &extension.GetOnuCountersRequest{
2371 IntfId: options.Args.IntfId,
2372 OnuId: options.Args.OnuId,
2373 },
2374 },
2375 },
2376 }
2377 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2378 defer cancel()
2379 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2380 if err != nil {
2381 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.OltId, ErrorToString(err))
2382 return err
2383 }
2384
2385 if rv.Response.Status != extension.GetValueResponse_OK {
2386 return fmt.Errorf("failed to get onu stats %v", rv.Response.ErrReason.String())
2387 }
2388 outputFormat := CharReplacer.Replace(options.Format)
2389 data, formatStr := buildOnuStatsOutputFormat(rv.GetResponse().GetOnuPonCounters())
2390 if outputFormat == "" {
2391 outputFormat = GetCommandOptionWithDefault("device-get-onu-status", "format", formatStr)
2392 }
Himani Chawla553a1392021-06-10 23:39:17 +05302393 result := CommandResult{
2394 Format: format.Format(outputFormat),
2395 OutputAs: toOutputType(options.OutputAs),
2396 NameLimit: options.NameLimit,
2397 Data: data,
2398 }
2399 GenerateOutput(&result)
2400 return nil
2401}
Himani Chawla40acc122021-05-26 18:52:29 +05302402
Akash Soni6e879c22024-12-20 17:01:34 +05302403func (options *GetOffloadApp) Execute(args []string) error {
Akash Soni51b6b7a2024-11-20 11:39:38 +05302404 // Establish a connection to the gRPC server
2405 conn, err := NewConnection()
2406 if err != nil {
2407 return err
2408 }
2409 defer conn.Close()
2410
2411 client := extension.NewExtensionClient(conn)
2412
2413 // Build the request
2414 singleGetValReq := &extension.SingleGetValueRequest{
2415 TargetId: string(options.Args.OltId),
2416 Request: &extension.GetValueRequest{
2417 Request: &extension.GetValueRequest_OffloadedAppsStats{
2418 OffloadedAppsStats: &extension.GetOffloadedAppsStatisticsRequest{
2419 StatsFor: options.Args.StatsFor,
2420 },
2421 },
2422 },
2423 }
2424
2425 // Set a context with timeout
2426 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2427 defer cancel()
2428
2429 // Perform the gRPC call
2430 rv, err := client.GetExtValue(ctx, singleGetValReq)
2431 if err != nil {
2432 Error.Printf("Error getting value for device ID %s, err=%s\n", options.Args.OltId, ErrorToString(err))
2433 return err
2434 }
2435
2436 // Check response status
2437 if rv.GetResponse().GetStatus() != extension.GetValueResponse_OK {
2438 return fmt.Errorf("failed to get offloaded app stats: %v", rv.GetResponse().GetErrReason().String())
2439 }
2440
2441 // Process the response data
2442 stats, formatStr := buildOffloadAppStatsOutputFormat(rv.GetResponse().GetOffloadedAppsStats())
balaji.nagarajan1f7c6392026-05-22 16:16:30 +05302443
2444 formatAdditionalStats(stats)
Akash Soni51b6b7a2024-11-20 11:39:38 +05302445 outputFormat := CharReplacer.Replace(options.Format)
2446 if outputFormat == "" {
2447 outputFormat = GetCommandOptionWithDefault("device-get-offload-app-stats", "format", formatStr)
2448 }
2449
2450 // Generate and display the output
2451 result := CommandResult{
2452 Format: format.Format(outputFormat),
2453 OutputAs: toOutputType(options.OutputAs),
2454 NameLimit: options.NameLimit,
2455 Data: stats,
2456 }
2457 GenerateOutput(&result)
2458
2459 return nil
2460}
2461
balaji.nagarajan1f7c6392026-05-22 16:16:30 +05302462func formatAdditionalStats(stats map[string]interface{}) {
2463 if v, ok := stats["additional_stats"]; ok {
2464 if m, ok := v.(map[string]interface{}); ok {
2465
2466 keys := make([]string, 0, len(m))
2467 for k := range m {
2468 keys = append(keys, k)
2469 }
2470
2471 sort.Strings(keys)
2472
2473 var b strings.Builder
2474
2475 for _, k := range keys {
2476 b.WriteString(fmt.Sprintf(
2477 " %-65s : %v\n",
2478 k,
2479 m[k],
2480 ))
2481 }
2482
2483 stats["additional_stats"] = b.String()
2484 }
2485 }
2486}
2487
Akash Soni6e879c22024-12-20 17:01:34 +05302488func (options *SetOffloadApp) Execute(args []string) error {
Akash Soni51b6b7a2024-11-20 11:39:38 +05302489 conn, err := NewConnection()
2490 if err != nil {
Akash Soni6e879c22024-12-20 17:01:34 +05302491 return fmt.Errorf("failed to establish gRPC connection: %w", err)
Akash Soni51b6b7a2024-11-20 11:39:38 +05302492 }
2493 defer conn.Close()
2494
2495 client := extension.NewExtensionClient(conn)
2496
Akash Soni6e879c22024-12-20 17:01:34 +05302497 // Parse JSON input
2498 var config extension.AppOffloadConfig
2499 if err := json.Unmarshal([]byte(options.Args.Config), &config); err != nil {
2500 return fmt.Errorf("failed to parse CONFIG as JSON: %w", err)
2501 }
2502
Akash Soni51b6b7a2024-11-20 11:39:38 +05302503 setValueRequest := &extension.SetValueRequest{
2504 Request: &extension.SetValueRequest_AppOffloadConfig{
Akash Soni6e879c22024-12-20 17:01:34 +05302505 AppOffloadConfig: &config,
Akash Soni51b6b7a2024-11-20 11:39:38 +05302506 },
2507 }
2508
2509 singleSetValReq := &extension.SingleSetValueRequest{
2510 TargetId: string(options.Args.OltId),
2511 Request: setValueRequest,
2512 }
2513
Akash Soni6e879c22024-12-20 17:01:34 +05302514 // Log the request object
2515 logRequestAppOffloadConfig(singleSetValReq)
2516
Akash Soni51b6b7a2024-11-20 11:39:38 +05302517 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2518 defer cancel()
2519
2520 resp, err := client.SetExtValue(ctx, singleSetValReq)
2521 if err != nil {
Akash Soni6e879c22024-12-20 17:01:34 +05302522 return fmt.Errorf("failed to set AppOffloadConfig: %w", err)
Akash Soni51b6b7a2024-11-20 11:39:38 +05302523 }
2524
2525 if resp.Response.Status != extension.SetValueResponse_OK {
Akash Soni6e879c22024-12-20 17:01:34 +05302526 return fmt.Errorf("operation failed with status %v: %s", resp.Response.Status, resp.Response.ErrReason)
Akash Soni51b6b7a2024-11-20 11:39:38 +05302527 }
2528
2529 fmt.Printf("AppOffloadConfig successfully set for OLT ID: %s\n", options.Args.OltId)
2530 return nil
2531}
2532
Akash Soni6e879c22024-12-20 17:01:34 +05302533func logRequestAppOffloadConfig(req *extension.SingleSetValueRequest) {
2534 fmt.Printf("Request details:\n")
2535 fmt.Printf("TargetId: %s\n", req.TargetId)
2536 if config, ok := req.Request.Request.(*extension.SetValueRequest_AppOffloadConfig); ok {
2537 fmt.Printf("AppOffloadConfig:\n")
2538 fmt.Printf(" EnableDHCPv4RA: %t\n", config.AppOffloadConfig.EnableDHCPv4RA)
2539 fmt.Printf(" EnableDHCPv6RA: %t\n", config.AppOffloadConfig.EnableDHCPv6RA)
2540 fmt.Printf(" EnablePPPoEIA: %t\n", config.AppOffloadConfig.EnablePPPoEIA)
2541 fmt.Printf(" AccessNodeID: %s\n", config.AppOffloadConfig.AccessNodeID)
2542 }
2543}
2544
2545func (options *SetOnuOffload) Execute(args []string) error {
2546 // Create the gRPC client connection
Akash Soni51b6b7a2024-11-20 11:39:38 +05302547 conn, err := NewConnection()
2548 if err != nil {
2549 return fmt.Errorf("failed to establish gRPC connection: %v", err)
2550 }
2551 defer conn.Close()
2552
2553 client := extension.NewExtensionClient(conn)
2554
Akash Soni6e879c22024-12-20 17:01:34 +05302555 // Parse PerUniInfo into a slice of PerUniConfig
2556 var perUniConfigs []AppOffloadOnuConfig
2557 if err := json.Unmarshal([]byte(options.Args.PerUniInfo), &perUniConfigs); err != nil {
2558 return fmt.Errorf("failed to parse PerUniInfo as JSON: %v", err)
Akash Soni51b6b7a2024-11-20 11:39:38 +05302559 }
Akash Soni6e879c22024-12-20 17:01:34 +05302560
2561 // Convert to []*AppOffloadOnuConfig_PerUniConfig for gRPC
2562 var grpcPerUniInfo []*extension.AppOffloadOnuConfig_PerUniConfig
2563 for _, config := range perUniConfigs {
2564 grpcPerUniInfo = append(grpcPerUniInfo, &extension.AppOffloadOnuConfig_PerUniConfig{
2565 AgentRemoteID: config.AgentRemoteID,
2566 AgentCircuitID: config.AgentCircuitID,
2567 OnuUniId: config.OnuUniId,
2568 })
2569 }
2570
Akash Soni51b6b7a2024-11-20 11:39:38 +05302571 // Build the AppOffloadOnuConfig request
2572 onuConfig := &extension.AppOffloadOnuConfig{
2573 OnuDeviceId: options.Args.OnuDeviceId,
Akash Soni6e879c22024-12-20 17:01:34 +05302574 PerUniInfo: grpcPerUniInfo,
Akash Soni51b6b7a2024-11-20 11:39:38 +05302575 }
2576
2577 setValueRequest := &extension.SetValueRequest{
2578 Request: &extension.SetValueRequest_AppOffloadOnuConfig{
2579 AppOffloadOnuConfig: onuConfig,
2580 },
2581 }
2582
2583 singleSetValReq := &extension.SingleSetValueRequest{
Akash Soni6e879c22024-12-20 17:01:34 +05302584 TargetId: string(options.Args.OltId),
Akash Soni51b6b7a2024-11-20 11:39:38 +05302585 Request: setValueRequest,
2586 }
2587
Akash Soni6e879c22024-12-20 17:01:34 +05302588 // Log the request object
2589 logRequestAppOffloadOnuConfig(singleSetValReq)
2590
2591 // Make the gRPC call
Akash Soni51b6b7a2024-11-20 11:39:38 +05302592 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2593 defer cancel()
2594
2595 resp, err := client.SetExtValue(ctx, singleSetValReq)
2596 if err != nil {
2597 return fmt.Errorf("failed to set AppOffloadOnuConfig: %v", err)
2598 }
2599
2600 if resp.Response.Status != extension.SetValueResponse_OK {
Akash Soni6e879c22024-12-20 17:01:34 +05302601 return fmt.Errorf("operation failed with status %v: %s", resp.Response.Status, resp.Response.ErrReason)
Akash Soni51b6b7a2024-11-20 11:39:38 +05302602 }
2603
2604 fmt.Printf("AppOffloadOnuConfig successfully set for ONU ID: %s\n", options.Args.OnuDeviceId)
2605 return nil
2606}
2607
Akash Soni6e879c22024-12-20 17:01:34 +05302608// Debugging helper to log the gRPC request details
2609func logRequestAppOffloadOnuConfig(req *extension.SingleSetValueRequest) {
2610 fmt.Printf("Request details:\n")
2611 fmt.Printf("TargetId: %s\n", req.TargetId)
2612 fmt.Printf("OnuDeviceId: %s\n", req.Request.GetAppOffloadOnuConfig().OnuDeviceId)
2613 if config, ok := req.Request.Request.(*extension.SetValueRequest_AppOffloadOnuConfig); ok {
2614 fmt.Printf("AppOffloadOnuConfig:\n")
2615 for i, uniInfo := range config.AppOffloadOnuConfig.PerUniInfo {
2616 fmt.Printf(" UniInfo %d:\n", i+1)
2617 fmt.Printf(" AgentRemoteID: %s\n", uniInfo.AgentRemoteID)
2618 fmt.Printf(" AgentCircuitID: %s\n", uniInfo.AgentCircuitID)
2619 fmt.Printf(" OnuUniId: %d\n", uniInfo.OnuUniId)
2620 }
2621 }
2622}
2623
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +05302624func (options *GetPonPortStats) Execute(args []string) error {
2625 conn, err := NewConnection()
2626 if err != nil {
2627 return err
2628 }
2629 defer conn.Close()
2630 client := extension.NewExtensionClient(conn)
2631
2632 singleGetValReq := extension.SingleGetValueRequest{
2633 TargetId: string(options.Args.Id),
2634 Request: &extension.GetValueRequest{
2635 Request: &extension.GetValueRequest_OltPonStats{
2636 OltPonStats: &extension.GetPonStatsRequest{
2637 PortInfo: &extension.GetPonStatsRequest_PortLabel{
2638 PortLabel: options.Args.PortLabel,
2639 },
2640 },
2641 },
2642 },
2643 }
2644 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2645 defer cancel()
2646 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2647 if err != nil {
2648 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2649 return err
2650 }
2651
2652 if rv.Response.Status != extension.GetValueResponse_OK {
2653 return fmt.Errorf("failed to get pon port stats %v", rv.Response.ErrReason.String())
2654 }
2655 outputFormat := CharReplacer.Replace(options.Format)
2656 if outputFormat == "" {
2657 outputFormat = GetCommandOptionWithDefault("device-get-pon-stats", "format", DEFAULT_PON_PORT_STATS_FORMAT)
2658 }
2659 data := PortStats{
2660 PonPort: rv.GetResponse().GetOltPonStatsResponse().GetPonPort(),
2661 PortStatistics: rv.GetResponse().GetOltPonStatsResponse().GetPortStatistics(),
2662 }
2663 result := CommandResult{
2664 Format: format.Format(outputFormat),
2665 OutputAs: toOutputType(options.OutputAs),
2666 NameLimit: options.NameLimit,
2667 Data: data,
2668 }
2669 GenerateOutput(&result)
2670 return nil
2671}
2672
2673func (options *GetNniPortStats) Execute(args []string) error {
2674 conn, err := NewConnection()
2675 if err != nil {
2676 return err
2677 }
2678 defer conn.Close()
2679 client := extension.NewExtensionClient(conn)
2680
2681 singleGetValReq := extension.SingleGetValueRequest{
2682 TargetId: string(options.Args.Id),
2683 Request: &extension.GetValueRequest{
2684 Request: &extension.GetValueRequest_OltNniStats{
2685 OltNniStats: &extension.GetNNIStatsRequest{
2686 PortInfo: &extension.GetNNIStatsRequest_PortLabel{
2687 PortLabel: options.Args.PortLabel,
2688 },
2689 },
2690 },
2691 },
2692 }
2693 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2694 defer cancel()
2695 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2696 if err != nil {
2697 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2698 return err
2699 }
2700
2701 if rv.Response.Status != extension.GetValueResponse_OK {
2702 return fmt.Errorf("failed to get nni port stats %v", rv.Response.ErrReason.String())
2703 }
2704 outputFormat := CharReplacer.Replace(options.Format)
2705 if outputFormat == "" {
2706 outputFormat = GetCommandOptionWithDefault("device-get-nni-stats", "format", DEFAULT_NNI_PORT_STATS_FORMAT)
2707 }
2708 data := PortStats{
2709 NniPort: rv.GetResponse().GetOltNniStatsResponse().GetNniPort(),
2710 PortStatistics: rv.GetResponse().GetOltNniStatsResponse().GetPortStatistics(),
2711 }
2712 result := CommandResult{
2713 Format: format.Format(outputFormat),
2714 OutputAs: toOutputType(options.OutputAs),
2715 NameLimit: options.NameLimit,
2716 Data: data,
2717 }
2718 GenerateOutput(&result)
2719 return nil
2720}
2721
Himani Chawla553a1392021-06-10 23:39:17 +05302722func (options *GetOnuEthernetFrameExtendedPmCounters) Execute(args []string) error {
2723 conn, err := NewConnection()
2724 if err != nil {
2725 return err
2726 }
2727 defer conn.Close()
2728 client := extension.NewExtensionClient(conn)
Himani Chawla806aa892021-08-30 15:51:46 +05302729 var singleGetValReq extension.SingleGetValueRequest
Himani Chawla553a1392021-06-10 23:39:17 +05302730
Himani Chawla806aa892021-08-30 15:51:46 +05302731 if options.Args.UniIndex != nil {
2732 singleGetValReq = extension.SingleGetValueRequest{
2733 TargetId: string(options.Args.Id),
2734 Request: &extension.GetValueRequest{
2735 Request: &extension.GetValueRequest_OnuInfo{
2736 OnuInfo: &extension.GetOmciEthernetFrameExtendedPmRequest{
2737 OnuDeviceId: string(options.Args.Id),
2738 Reset_: options.Reset,
2739 IsUniIndex: &extension.GetOmciEthernetFrameExtendedPmRequest_UniIndex{
2740 UniIndex: *options.Args.UniIndex,
2741 },
2742 },
Himani Chawla553a1392021-06-10 23:39:17 +05302743 },
2744 },
Himani Chawla806aa892021-08-30 15:51:46 +05302745 }
2746 } else {
2747 singleGetValReq = extension.SingleGetValueRequest{
2748 TargetId: string(options.Args.Id),
2749 Request: &extension.GetValueRequest{
2750 Request: &extension.GetValueRequest_OnuInfo{
2751 OnuInfo: &extension.GetOmciEthernetFrameExtendedPmRequest{
2752 OnuDeviceId: string(options.Args.Id),
2753 Reset_: options.Reset,
2754 },
2755 },
2756 },
2757 }
Himani Chawla553a1392021-06-10 23:39:17 +05302758 }
Himani Chawla806aa892021-08-30 15:51:46 +05302759
Himani Chawla553a1392021-06-10 23:39:17 +05302760 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2761 defer cancel()
2762 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2763 if err != nil {
2764 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2765 return err
2766 }
2767
2768 if rv.Response.Status != extension.GetValueResponse_OK {
2769 return fmt.Errorf("failed to get ethernet frame extended pm counters %v", rv.Response.ErrReason.String())
2770 }
2771 outputFormat := CharReplacer.Replace(options.Format)
2772 data := buildOnuEthernetFrameExtendedPmOutputFormat(rv.GetResponse().GetOnuCounters())
2773 if outputFormat == "" {
2774 outputFormat = GetCommandOptionWithDefault("device-get-onu-status", "format", DEFAULT_ETHERNET_FRAME_EXTENDED_PM_COUNTERS_FORMAT)
2775 }
Himani Chawla40acc122021-05-26 18:52:29 +05302776 result := CommandResult{
2777 Format: format.Format(outputFormat),
2778 OutputAs: toOutputType(options.OutputAs),
2779 NameLimit: options.NameLimit,
2780 Data: data,
2781 }
2782 GenerateOutput(&result)
2783 return nil
2784}
2785
kesavand6d1131f2021-02-05 22:38:15 +05302786func (options *UniStatus) Execute(args []string) error {
2787 conn, err := NewConnection()
2788 if err != nil {
2789 return err
2790 }
2791 defer conn.Close()
2792 client := extension.NewExtensionClient(conn)
2793
2794 singleGetValReq := extension.SingleGetValueRequest{
2795 TargetId: string(options.Args.Id),
2796 Request: &extension.GetValueRequest{
2797 Request: &extension.GetValueRequest_UniInfo{
2798 UniInfo: &extension.GetOnuUniInfoRequest{
2799 UniIndex: options.Args.UniIndex,
2800 },
2801 },
2802 },
2803 }
David K. Bainbridge9189c632021-03-26 21:52:21 +00002804 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand6d1131f2021-02-05 22:38:15 +05302805 defer cancel()
2806 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2807 if err != nil {
2808 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2809 return err
2810 }
2811 if rv.Response.Status != extension.GetValueResponse_OK {
2812 return fmt.Errorf("failed to get uni status %v", rv.Response.ErrReason.String())
2813 }
2814 outputFormat := CharReplacer.Replace(options.Format)
2815 if outputFormat == "" {
2816 outputFormat = GetCommandOptionWithDefault("device-get-uni-status", "format", DEFAULT_DEVICE_GET_UNI_STATUS_FORMAT)
2817 }
2818 result := CommandResult{
2819 Format: format.Format(outputFormat),
2820 OutputAs: toOutputType(options.OutputAs),
2821 NameLimit: options.NameLimit,
2822 Data: rv.GetResponse().GetUniInfo(),
2823 }
2824 GenerateOutput(&result)
2825 return nil
2826}
2827
Girish Gowdra4f5ce7c2021-04-29 18:53:21 -07002828func (options *OnuPonOpticalInfo) Execute(args []string) error {
2829 conn, err := NewConnection()
2830 if err != nil {
2831 return err
2832 }
2833 defer conn.Close()
2834 client := extension.NewExtensionClient(conn)
2835
2836 singleGetValReq := extension.SingleGetValueRequest{
2837 TargetId: string(options.Args.Id),
2838 Request: &extension.GetValueRequest{
2839 Request: &extension.GetValueRequest_OnuOpticalInfo{
2840 OnuOpticalInfo: &extension.GetOnuPonOpticalInfo{},
2841 },
2842 },
2843 }
2844 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2845 defer cancel()
2846 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2847 if err != nil {
2848 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2849 return err
2850 }
2851 if rv.Response.Status != extension.GetValueResponse_OK {
2852 return fmt.Errorf("failed to get onu pon optical info %v", rv.Response.ErrReason.String())
2853 }
2854 outputFormat := CharReplacer.Replace(options.Format)
2855 if outputFormat == "" {
2856 outputFormat = GetCommandOptionWithDefault("device-get-onu-pon-optical-info", "format", DEFAULT_ONU_PON_OPTICAL_INFO_STATUS_FORMAT)
2857 }
2858 result := CommandResult{
2859 Format: format.Format(outputFormat),
2860 OutputAs: toOutputType(options.OutputAs),
2861 NameLimit: options.NameLimit,
2862 Data: rv.GetResponse().GetOnuOpticalInfo(),
2863 }
2864 GenerateOutput(&result)
2865 return nil
2866}
2867
Gamze Abakac857a462021-05-26 13:45:54 +00002868func (options *RxPower) Execute(args []string) error {
2869 conn, err := NewConnection()
2870 if err != nil {
2871 return err
2872 }
2873 defer conn.Close()
2874 client := extension.NewExtensionClient(conn)
2875
2876 singleGetValReq := extension.SingleGetValueRequest{
2877 TargetId: string(options.Args.Id),
2878 Request: &extension.GetValueRequest{
2879 Request: &extension.GetValueRequest_RxPower{
2880 RxPower: &extension.GetRxPowerRequest{
2881 IntfId: options.Args.PortNo,
2882 OnuId: options.Args.OnuNo,
2883 },
2884 },
2885 },
2886 }
2887
2888 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2889 defer cancel()
2890 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2891 if err != nil {
2892 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2893 return err
2894 }
2895 if rv.Response.Status != extension.GetValueResponse_OK {
2896 return fmt.Errorf("failed to get rx power %v", rv.Response.ErrReason.String())
2897 }
2898 outputFormat := CharReplacer.Replace(options.Format)
2899 if outputFormat == "" {
2900 outputFormat = GetCommandOptionWithDefault("device-get-rx-power", "format", DEFAULT_RX_POWER_STATUS_FORMAT)
2901 }
2902 result := CommandResult{
2903 Format: format.Format(outputFormat),
2904 OutputAs: toOutputType(options.OutputAs),
2905 NameLimit: options.NameLimit,
2906 Data: rv.GetResponse().GetRxPower(),
2907 }
2908 GenerateOutput(&result)
2909 return nil
2910}
2911
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002912/*Device get Onu Distance */
2913func (options *DeviceGetExtValue) Execute(args []string) error {
2914 conn, err := NewConnection()
2915 if err != nil {
2916 return err
2917 }
2918 defer conn.Close()
2919
Scott Baker9173ed82020-05-19 08:30:12 -07002920 client := voltha.NewVolthaServiceClient(conn)
2921
khenaidoo080ce882021-10-19 17:35:08 -04002922 valueflag, okay := extension.ValueType_Type_value[string(options.Args.Valueflag)]
Scott Baker9173ed82020-05-19 08:30:12 -07002923 if !okay {
2924 Error.Printf("Unknown valueflag %s\n", options.Args.Valueflag)
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002925 }
2926
khenaidoo080ce882021-10-19 17:35:08 -04002927 val := extension.ValueSpecifier{Id: string(options.Args.Id), Value: extension.ValueType_Type(valueflag)}
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002928
David K. Bainbridge9189c632021-03-26 21:52:21 +00002929 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002930 defer cancel()
2931
Scott Baker9173ed82020-05-19 08:30:12 -07002932 rv, err := client.GetExtValue(ctx, &val)
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002933 if err != nil {
2934 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2935 return err
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002936 }
2937
Scott Baker9173ed82020-05-19 08:30:12 -07002938 var rows []ReturnValueRow
khenaidoo080ce882021-10-19 17:35:08 -04002939 for name, num := range extension.ValueType_Type_value {
Scott Baker9173ed82020-05-19 08:30:12 -07002940 if num == 0 {
2941 // EMPTY is not a real value
2942 continue
2943 }
2944 if (rv.Error & uint32(num)) != 0 {
2945 row := ReturnValueRow{Name: name, Result: "Error"}
2946 rows = append(rows, row)
2947 }
2948 if (rv.Unsupported & uint32(num)) != 0 {
2949 row := ReturnValueRow{Name: name, Result: "Unsupported"}
2950 rows = append(rows, row)
2951 }
2952 if (rv.Set & uint32(num)) != 0 {
2953 switch name {
2954 case "DISTANCE":
2955 row := ReturnValueRow{Name: name, Result: rv.Distance}
2956 rows = append(rows, row)
2957 default:
2958 row := ReturnValueRow{Name: name, Result: "Unimplemented-in-voltctl"}
2959 rows = append(rows, row)
2960 }
2961 }
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002962 }
2963
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002964 outputFormat := CharReplacer.Replace(options.Format)
2965 if outputFormat == "" {
2966 outputFormat = GetCommandOptionWithDefault("device-value-get", "format", DEFAULT_DEVICE_VALUE_GET_FORMAT)
2967 }
2968
2969 result := CommandResult{
2970 Format: format.Format(outputFormat),
2971 OutputAs: toOutputType(options.OutputAs),
2972 NameLimit: options.NameLimit,
Scott Baker9173ed82020-05-19 08:30:12 -07002973 Data: rows,
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002974 }
2975 GenerateOutput(&result)
2976 return nil
2977}
serkantul3d22fc72022-09-14 12:22:56 +03002978
2979/*Device get Onu OMCI TX RX Stats */
2980func (options *OnuOmciTxRxStats) Execute(args []string) error {
2981 conn, err := NewConnection()
2982 if err != nil {
2983 return err
2984 }
2985 defer conn.Close()
2986 client := extension.NewExtensionClient(conn)
2987
2988 singleGetValReq := extension.SingleGetValueRequest{
2989 TargetId: string(options.Args.Id),
2990 Request: &extension.GetValueRequest{
2991 Request: &extension.GetValueRequest_OnuOmciStats{
2992 OnuOmciStats: &extension.GetOnuOmciTxRxStatsRequest{},
2993 },
2994 },
2995 }
2996
2997 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2998 defer cancel()
2999 rv, err := client.GetExtValue(ctx, &singleGetValReq)
3000 if err != nil {
3001 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
3002 return err
3003 }
3004
3005 if rv.Response.Status != extension.GetValueResponse_OK {
3006 return fmt.Errorf("failed to get onu omci tx rx stats %v", rv.Response.ErrReason.String())
3007 }
3008 outputFormat := CharReplacer.Replace(options.Format)
3009 if outputFormat == "" {
3010 outputFormat = GetCommandOptionWithDefault("device-get-onu-omci-tx-rx-stats", "format", DEFAULT_ONU_OMCI_TX_RX_STATS_FORMAT)
3011 }
3012 result := CommandResult{
3013 Format: format.Format(outputFormat),
3014 OutputAs: toOutputType(options.OutputAs),
3015 NameLimit: options.NameLimit,
3016 Data: rv.GetResponse().GetOnuOmciStats(),
3017 }
3018 GenerateOutput(&result)
3019 return nil
3020}
praneeth nalmas1dd094c2022-12-22 14:15:13 +05303021
3022/*Device get Onu Active Alarms */
3023func (options *GetOnuOmciActiveAlarms) Execute(args []string) error {
3024 conn, err := NewConnection()
3025 if err != nil {
3026 return err
3027 }
3028 defer conn.Close()
3029 client := extension.NewExtensionClient(conn)
3030
3031 singleGetValReq := extension.SingleGetValueRequest{
3032 TargetId: string(options.Args.Id),
3033 Request: &extension.GetValueRequest{
3034 Request: &extension.GetValueRequest_OnuActiveAlarms{
3035 OnuActiveAlarms: &extension.GetOnuOmciActiveAlarmsRequest{},
3036 },
3037 },
3038 }
3039 Info.Printf("Getting omci_active_alarms for device Id %s\n", options.Args.Id)
3040 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3041 defer cancel()
3042 rv, err := client.GetExtValue(ctx, &singleGetValReq)
3043 if err != nil {
3044 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
3045 return err
3046 }
3047
3048 if rv.Response.Status != extension.GetValueResponse_OK {
3049 return fmt.Errorf("failed to get onu omci active alarms list %v", rv.Response.ErrReason.String())
3050 }
3051 outputFormat := CharReplacer.Replace(options.Format)
3052 if outputFormat == "" {
3053 outputFormat = GetCommandOptionWithDefault("device-get-onu-omci-active-alarms", "format", DEFAULT_DEVICE_ALARMS_FORMAT)
3054 }
3055
3056 orderBy := options.OrderBy
3057 if orderBy == "" {
3058 orderBy = GetCommandOptionWithDefault("device-list", "order", DEFAULT_DEVICE_ALARMS_ORDER)
3059 }
3060
3061 result := CommandResult{
3062 Format: format.Format(outputFormat),
3063 OutputAs: toOutputType(options.OutputAs),
3064 OrderBy: orderBy,
3065 NameLimit: options.NameLimit,
3066 Data: rv.GetResponse().GetOnuActiveAlarms().GetActiveAlarms(),
3067 }
3068 GenerateOutput(&result)
3069 return nil
3070}
praneeth nalmas39c71ad2023-09-27 18:29:04 +05303071
Akash Soni66db9632024-04-15 09:05:15 +05303072/*Device get Onu Active Alarms */
3073func (options *GetOnuDistance) Execute(args []string) error {
3074 conn, err := NewConnection()
3075 if err != nil {
3076 return err
3077 }
3078 defer conn.Close()
3079 client := extension.NewExtensionClient(conn)
3080
3081 singleGetValReq := extension.SingleGetValueRequest{
3082 TargetId: string(options.Args.Id),
3083 Request: &extension.GetValueRequest{
3084 Request: &extension.GetValueRequest_Distance{
3085 Distance: &extension.GetDistanceRequest{
3086 OnuDeviceId: string(options.Args.OnuId),
3087 },
3088 },
3089 },
3090 }
3091 Info.Printf("Getting onu distance for device Id %s\n", options.Args.Id)
3092 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3093 defer cancel()
3094 rv, err := client.GetExtValue(ctx, &singleGetValReq)
3095 if err != nil {
3096 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
3097 return err
3098 }
3099
3100 if rv.Response.Status != extension.GetValueResponse_OK {
3101 return fmt.Errorf("failed to get onu distance stats %v", rv.Response.ErrReason.String())
3102 }
3103 outputFormat := CharReplacer.Replace(options.Format)
3104 if outputFormat == "" {
3105 outputFormat = GetCommandOptionWithDefault("get-onu-distance", "format", DEFAULT_ONU_DISTANCE_FORMAT)
3106 }
3107
3108 result := CommandResult{
3109 Format: format.Format(outputFormat),
3110 OutputAs: toOutputType(options.OutputAs),
3111 NameLimit: options.NameLimit,
3112 Data: rv.GetResponse().GetDistance().GetDistance(),
3113 }
3114 fmt.Println("onu distance : ", rv)
3115 GenerateOutput(&result)
3116 return nil
3117}
3118
praneeth nalmas39c71ad2023-09-27 18:29:04 +05303119func (options *PonRxPower) Execute(args []string) error {
3120 conn, err := NewConnection()
3121 if err != nil {
3122 return err
3123 }
3124 defer conn.Close()
3125 client := extension.NewExtensionClient(conn)
3126
3127 singleGetValReq := extension.SingleGetValueRequest{
3128 TargetId: string(options.Args.Id),
3129 Request: &extension.GetValueRequest{
3130 Request: &extension.GetValueRequest_OltRxPower{
3131 OltRxPower: &extension.GetOltRxPowerRequest{
3132 PortLabel: options.Args.PortLabel,
3133 OnuSn: options.Args.SerialNo,
3134 },
3135 },
3136 },
3137 }
3138
3139 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3140 defer cancel()
3141 rv, err := client.GetExtValue(ctx, &singleGetValReq)
3142 if err != nil {
3143 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
3144 return err
3145 }
3146 if rv.Response.Status != extension.GetValueResponse_OK {
3147 return fmt.Errorf("failed to get rx power %v", rv.Response.ErrReason.String())
3148 }
3149 outputFormat := CharReplacer.Replace(options.Format)
3150 if outputFormat == "" {
3151 outputFormat = GetCommandOptionWithDefault("device-get-pon-rx-power", "format", DEFAULT_PON_RX_POWER_STATUS_FORMAT)
3152 }
3153 result := CommandResult{
3154 Format: format.Format(outputFormat),
3155 OutputAs: toOutputType(options.OutputAs),
3156 NameLimit: options.NameLimit,
3157 Data: rv.GetResponse().GetOltRxPower().GetRxPower(),
3158 }
3159 GenerateOutput(&result)
3160 return nil
3161}
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +05303162
3163func (options *GetOnuGEMStats) Execute(args []string) error {
3164
3165 conn, err := NewConnection()
3166 if err != nil {
3167 return err
3168 }
3169 defer conn.Close()
3170 client := extension.NewExtensionClient(conn)
3171 singleGetValReq := extension.SingleGetValueRequest{
3172 TargetId: string(options.Args.Id),
3173 Request: &extension.GetValueRequest{
3174 Request: &extension.GetValueRequest_OnuAllocGemStats{
3175 OnuAllocGemStats: &extension.GetOnuAllocGemHistoryRequest{},
3176 },
3177 },
3178 }
3179
3180 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3181 defer cancel()
3182
3183 rv, err := client.GetExtValue(ctx, &singleGetValReq)
3184
3185 if err != nil {
3186 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
3187 return err
3188 }
3189
3190 if rv.Response.Status != extension.GetValueResponse_OK {
3191 return fmt.Errorf("failed to get gem port response %v", rv.Response.ErrReason.String())
3192 }
3193 outputFormat := CharReplacer.Replace(options.Format)
3194 if outputFormat == "" {
3195 outputFormat = GetCommandOptionWithDefault("device-get-gem-port", "format", DEFAULT_DEVICE_VALUE_GEM_PORT_FORMAT)
3196 }
3197 onugemhistoryresponse := rv.GetResponse().GetOnuAllocGemStatsResponse()
3198 for _, OnuallocGemHistoryData := range onugemhistoryresponse.OnuAllocGemHistoryData {
3199 data := onugemstats{}
3200 data.AllocId = OnuallocGemHistoryData.OnuAllocIdInfo.AllocId
3201 data.AllocRxBytes = OnuallocGemHistoryData.OnuAllocIdInfo.RxBytes
3202 for _, gemStatsInfo := range OnuallocGemHistoryData.GemPortInfo {
3203 data.GemHistoryStats = append(data.GemHistoryStats, gemHistoryStats{
3204 GemId: gemStatsInfo.GemId,
3205 TransmittedGEMFrames: gemStatsInfo.TransmittedGEMFrames,
3206 ReceivedGEMFrames: gemStatsInfo.ReceivedGEMFrames,
Akash Reddy Kankanalaeba72f62026-01-29 12:49:17 +00003207 ReceivedPayloadBytes: gemStatsInfo.ReceivedPayloadBytes_64,
3208 TransmittedPayloadBytes: gemStatsInfo.TransmittedPayloadBytes_64,
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +05303209 EncryptionKeyErrors: gemStatsInfo.EncryptionKeyErrors,
3210 })
3211 }
3212 result := CommandResult{
3213 Format: format.Format(outputFormat),
3214 OutputAs: toOutputType(options.OutputAs),
3215 NameLimit: options.NameLimit,
3216 Data: &data,
3217 }
3218 GenerateOutput(&result)
3219 }
3220 return nil
3221
3222}
3223
Akash Reddy Kankanala6965c652025-10-15 23:30:16 +05303224func (options *GetOnuFecHistory) Execute(args []string) error {
3225 conn, err := NewConnection()
3226 if err != nil {
3227 return err
3228 }
3229 defer conn.Close()
3230 client := extension.NewExtensionClient(conn)
3231 singleGetValReq := extension.SingleGetValueRequest{
3232 TargetId: string(options.Args.Id),
3233 Request: &extension.GetValueRequest{
3234 Request: &extension.GetValueRequest_FecHistory{
3235 FecHistory: &extension.GetOnuFecHistory{},
3236 },
3237 },
3238 }
3239 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3240 defer cancel()
3241 rv, err := client.GetExtValue(ctx, &singleGetValReq)
3242 if err != nil {
3243 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
3244 return err
3245 }
3246 if rv.Response.Status != extension.GetValueResponse_OK {
3247 return fmt.Errorf("Failed to get onu FEC history stats from ONT %v", rv.Response.ErrReason.String())
3248 }
3249
3250 outputFormat := CharReplacer.Replace(options.Format)
3251 if outputFormat == "" {
3252 outputFormat = GetCommandOptionWithDefault("device-get-onu-fec-History", "format", DEFAULT_ONU_FEC_HISTORY_FORMAT)
3253 }
3254 result := CommandResult{
3255 Format: format.Format(outputFormat),
3256 OutputAs: toOutputType(options.OutputAs),
3257 NameLimit: options.NameLimit,
3258 Data: rv.GetResponse().GetFecHistory(),
3259 }
3260 GenerateOutput(&result)
3261 return nil
3262
3263}
3264
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +05303265func (options *GetOnuAllocGemStatsFromOlt) Execute(args []string) error {
3266 conn, err := NewConnection()
3267 if err != nil {
3268 return err
3269 }
3270 defer conn.Close()
3271 client := extension.NewExtensionClient(conn)
3272
3273 singleGetValReq := extension.SingleGetValueRequest{
3274 TargetId: string(options.Args.Id),
3275 Request: &extension.GetValueRequest{
3276 Request: &extension.GetValueRequest_OnuStatsFromOlt{
3277 OnuStatsFromOlt: &extension.GetOnuStatsFromOltRequest{},
3278 },
3279 },
3280 }
3281 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3282 defer cancel()
3283 rv, err := client.GetExtValue(ctx, &singleGetValReq)
3284 if err != nil {
3285 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
3286 return err
3287 }
3288
3289 if rv.Response.Status != extension.GetValueResponse_OK {
3290 return fmt.Errorf("failed to get onu alloc gem stats from olt %v", rv.Response.ErrReason.String())
3291 }
3292 outputFormat := CharReplacer.Replace(options.Format)
3293 if outputFormat == "" {
3294 outputFormat = GetCommandOptionWithDefault("device-get-onu-status", "format", DEFAULT_ONU_STATS_FROM_OLT_FORMAT)
3295 }
3296
3297 onuAllocGemStatsResponse := rv.GetResponse().GetOnuStatsFromOltResponse()
3298
3299 for _, allocGemStatsInfo := range onuAllocGemStatsResponse.AllocGemStatsInfo {
3300 data := AllocGemStatsFromOlt{}
3301 data.AllocId = allocGemStatsInfo.AllocIdInfo.AllocId
3302 data.AllocRxBytes = allocGemStatsInfo.AllocIdInfo.RxBytes
3303 for _, gemStatsInfo := range allocGemStatsInfo.GemPortInfo {
3304 data.GemPortStats = append(data.GemPortStats, GemPortStatsFromOlt{
3305 GemId: gemStatsInfo.GemId,
3306 RxBytes: gemStatsInfo.RxBytes,
3307 RxPackets: gemStatsInfo.RxPackets,
3308 TxBytes: gemStatsInfo.TxBytes,
3309 TxPackets: gemStatsInfo.TxPackets,
3310 })
3311 }
3312 result := CommandResult{
3313 Format: format.Format(outputFormat),
3314 OutputAs: toOutputType(options.OutputAs),
3315 NameLimit: options.NameLimit,
3316 Data: &data,
3317 }
3318 GenerateOutput(&result)
3319 }
3320
3321 return nil
3322}
mgouda35b90e62025-07-16 14:58:29 +05303323
3324func (options *DisableOnuDevice) Execute(args []string) error {
3325 conn, err := NewConnection()
3326 if err != nil {
3327 return err
3328 }
3329 defer conn.Close()
3330
3331 client := voltha.NewVolthaServiceClient(conn)
3332
3333 var lastErr error
3334 for _, i := range options.Args.Ids {
3335 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3336 defer cancel()
3337
3338 id := voltha.ID{Id: string(i)}
3339
3340 _, err := client.DisableOnuDevice(ctx, &id)
3341 if err != nil {
3342 Error.Printf("Error while disabling the onu serial number'%s': %s\n", i, err)
3343 lastErr = err
3344 continue
3345 }
3346 fmt.Printf("%s\n", i)
3347 }
3348
3349 if lastErr != nil {
3350 return NoReportErr
3351 }
3352 return nil
3353}
3354
3355func (options *EnableOnuDevice) Execute(args []string) error {
3356 conn, err := NewConnection()
3357 if err != nil {
3358 return err
3359 }
3360 defer conn.Close()
3361
3362 client := voltha.NewVolthaServiceClient(conn)
3363
3364 var lastErr error
3365 for _, i := range options.Args.Ids {
3366 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3367 defer cancel()
3368
3369 id := voltha.ID{Id: string(i)}
3370
3371 _, err := client.EnableOnuDevice(ctx, &id)
3372 if err != nil {
3373 Error.Printf("Error while enabling the onu serial number'%s': %s\n", i, err)
3374 lastErr = err
3375 continue
3376 }
3377 fmt.Printf("%s\n", i)
3378 }
3379
3380 if lastErr != nil {
3381 return NoReportErr
3382 }
3383 return nil
3384}
3385
3386func (options *DisableOnuSerialNumber) Execute(args []string) error {
3387 conn, err := NewConnection()
3388 if err != nil {
3389 return err
3390 }
3391 defer conn.Close()
3392
3393 client := voltha.NewVolthaServiceClient(conn)
3394
3395 id := common.ID{Id: string(options.Args.OltDeviceId)}
3396 port := voltha.Port{PortNo: uint32(options.Args.Port)}
3397
3398 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3399 defer cancel()
3400
3401 req := &voltha.OnuSerialNumberOnOLTPon{
3402 OltDeviceId: &id,
3403 SerialNumber: options.Args.SerialNumber,
3404 Port: &port,
3405 }
3406
3407 _, err = client.DisableOnuSerialNumber(ctx, req)
3408 if err != nil {
3409 Error.Printf("Error disabling ONU serial '%s' on OLT '%s': %v\n", options.Args.SerialNumber, options.Args.OltDeviceId, err)
3410 return err
3411 }
3412 fmt.Printf("Disabled ONU serial '%s' on OLT '%s'\n", options.Args.SerialNumber, options.Args.OltDeviceId)
3413 return nil
3414}
3415
3416func (options *EnableOnuSerialNumber) Execute(args []string) error {
3417 conn, err := NewConnection()
3418 if err != nil {
3419 return err
3420 }
3421 defer conn.Close()
3422
3423 client := voltha.NewVolthaServiceClient(conn)
3424
3425 id := common.ID{Id: string(options.Args.OltDeviceId)}
3426 port := voltha.Port{PortNo: uint32(options.Args.Port)}
3427
3428 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3429 defer cancel()
3430
3431 req := &voltha.OnuSerialNumberOnOLTPon{
3432 OltDeviceId: &id,
3433 SerialNumber: options.Args.SerialNumber,
3434 Port: &port,
3435 }
3436
3437 _, err = client.EnableOnuSerialNumber(ctx, req)
3438 if err != nil {
3439 Error.Printf("Error enabling ONU serial '%s' on OLT '%s': %v\n", options.Args.SerialNumber, options.Args.OltDeviceId, err)
3440 return err
3441 }
3442 fmt.Printf("Enabled ONU serial '%s' on OLT '%s'\n", options.Args.SerialNumber, options.Args.OltDeviceId)
3443 return nil
3444}
Akash Reddy Kankanala501ef802026-07-15 16:43:09 +05303445
3446func (options *DeviceUpdate) Execute(args []string) error {
3447 conn, err := NewConnection()
3448 if err != nil {
3449 return err
3450 }
3451 defer conn.Close()
3452 client := voltha.NewVolthaServiceClient(conn)
3453 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3454 defer cancel()
3455 var deviceConfig voltha.UpdateDevice
3456 switch options.Args.AddressType {
3457 case "IPV4":
3458 deviceConfig.Id = options.Args.Id
3459 deviceConfig.Address = &voltha.UpdateDevice_Ipv4Address{Ipv4Address: options.Args.Address}
3460 case "IPV6":
3461 deviceConfig.Id = options.Args.Id
3462 deviceConfig.Address = &voltha.UpdateDevice_Ipv6Address{Ipv6Address: options.Args.Address}
3463 case "HOST_AND_PORT":
3464 deviceConfig.Id = options.Args.Id
3465 deviceConfig.Address = &voltha.UpdateDevice_HostAndPort{HostAndPort: options.Args.Address}
3466 default:
3467 return fmt.Errorf("invalid address type %s, supported types are IPV4, IPV6, HOST_AND_PORT", options.Args.AddressType)
3468 }
3469 _, err = client.UpdateDevice(ctx, &deviceConfig)
3470 if err != nil {
3471 Error.Printf("Error updating device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
3472 return err
3473 }
3474 return nil
3475
3476}