blob: 7ce777a83b03fc06ed7b987370c8ad02385b0c4f [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
261type DeviceCreate struct {
David Bainbridge1a514392020-06-23 11:12:51 -0700262 DeviceType string `short:"t" required:"true" long:"devicetype" description:"Device type"`
David Bainbridge835dd0e2020-04-01 10:30:09 -0700263 MACAddress string `short:"m" long:"macaddress" default:"" description:"MAC Address"`
Zack Williamse940c7a2019-08-21 14:25:39 -0700264 IPAddress string `short:"i" long:"ipaddress" default:"" description:"IP Address"`
265 HostAndPort string `short:"H" long:"hostandport" default:"" description:"Host and port"`
266}
267
268type DeviceId string
Akash Soni66db9632024-04-15 09:05:15 +0530269type OnuId string
Zack Williamse940c7a2019-08-21 14:25:39 -0700270
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000271type MetricName string
272type GroupName string
kesavand12cd8eb2020-01-20 22:25:22 -0500273type PortNum uint32
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -0800274type ValueFlag string
kesavand12cd8eb2020-01-20 22:25:22 -0500275
Zack Williamse940c7a2019-08-21 14:25:39 -0700276type DeviceDelete struct {
Himani Chawla9933ddc2020-10-12 23:53:27 +0530277 Force bool `long:"force" description:"Delete device forcefully"`
278 Args struct {
Zack Williamse940c7a2019-08-21 14:25:39 -0700279 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
280 } `positional-args:"yes"`
281}
282
283type DeviceEnable struct {
284 Args struct {
285 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
286 } `positional-args:"yes"`
287}
288
289type DeviceDisable struct {
290 Args struct {
291 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
292 } `positional-args:"yes"`
293}
294
295type DeviceReboot struct {
296 Args struct {
297 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
298 } `positional-args:"yes"`
299}
300
301type DeviceFlowList struct {
302 ListOutputOptions
Maninder045921e2020-09-29 16:46:02 +0530303 FlowIdOptions
Zack Williamse940c7a2019-08-21 14:25:39 -0700304 Args struct {
305 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
306 } `positional-args:"yes"`
307}
308
Himani Chawla3c161c62021-05-13 16:36:51 +0530309type DeviceFlowGroupList struct {
310 ListOutputOptions
311 GroupListOptions
312 Args struct {
313 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
314 } `positional-args:"yes"`
315}
Zack Williamse940c7a2019-08-21 14:25:39 -0700316type DevicePortList struct {
317 ListOutputOptions
318 Args struct {
319 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
320 } `positional-args:"yes"`
321}
322
323type DeviceInspect struct {
324 OutputOptionsJson
325 Args struct {
326 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
327 } `positional-args:"yes"`
328}
329
kesavand12cd8eb2020-01-20 22:25:22 -0500330type DevicePortEnable struct {
331 Args struct {
332 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
333 PortId PortNum `positional-arg-name:"PORT_NUMBER" required:"yes"`
334 } `positional-args:"yes"`
335}
336
337type DevicePortDisable struct {
338 Args struct {
339 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
340 PortId PortNum `positional-arg-name:"PORT_NUMBER" required:"yes"`
341 } `positional-args:"yes"`
342}
343
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000344type DevicePmConfigsGet struct {
345 ListOutputOptions
346 Args struct {
347 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
348 } `positional-args:"yes"`
349}
350
351type DevicePmConfigMetricList struct {
352 ListOutputOptions
353 Args struct {
354 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
355 } `positional-args:"yes"`
356}
357
358type DevicePmConfigGroupList struct {
359 ListOutputOptions
360 Args struct {
361 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
362 } `positional-args:"yes"`
363}
364
365type DevicePmConfigGroupMetricList struct {
366 ListOutputOptions
367 Args struct {
368 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
369 Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"`
370 } `positional-args:"yes"`
371}
372
373type DevicePmConfigFrequencySet struct {
374 OutputOptions
375 Args struct {
Girish Gowdra610acb42021-01-27 13:33:57 -0800376 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
377 Interval time.Duration `positional-arg-name:"INTERVAL" required:"yes"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000378 } `positional-args:"yes"`
379}
380
381type DevicePmConfigMetricEnable struct {
382 Args struct {
383 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
384 Metrics []MetricName `positional-arg-name:"METRIC_NAME" required:"yes"`
385 } `positional-args:"yes"`
386}
387
388type DevicePmConfigMetricDisable struct {
389 Args struct {
390 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
391 Metrics []MetricName `positional-arg-name:"METRIC_NAME" required:"yes"`
392 } `positional-args:"yes"`
393}
394
395type DevicePmConfigGroupEnable struct {
396 Args struct {
Girish Gowdra610acb42021-01-27 13:33:57 -0800397 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
398 Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000399 } `positional-args:"yes"`
400}
401
402type DevicePmConfigGroupDisable struct {
403 Args struct {
Girish Gowdra610acb42021-01-27 13:33:57 -0800404 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
405 Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"`
406 } `positional-args:"yes"`
407}
408
409type DevicePmConfigGroupFrequencySet struct {
410 OutputOptions
411 Args struct {
412 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
413 Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"`
414 Interval time.Duration `positional-arg-name:"INTERVAL" required:"yes"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000415 } `positional-args:"yes"`
416}
417
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -0800418type DeviceGetExtValue struct {
419 ListOutputOptions
420 Args struct {
421 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
422 Valueflag ValueFlag `positional-arg-name:"VALUE_FLAG" required:"yes"`
423 } `positional-args:"yes"`
424}
Rohan Agrawald7df3772020-06-29 11:23:36 +0000425
426type DevicePmConfigSetMaxSkew struct {
427 Args struct {
428 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
429 MaxSkew uint32 `positional-arg-name:"MAX_SKEW" required:"yes"`
430 } `positional-args:"yes"`
431}
432
Andrea Campanella791d88b2021-01-08 13:29:00 +0100433type DeviceOnuListImages struct {
434 ListOutputOptions
435 Args struct {
436 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
437 } `positional-args:"yes"`
438}
439
440type DeviceOnuDownloadImage struct {
441 Args struct {
442 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
443 Name string `positional-arg-name:"IMAGE_NAME" required:"yes"`
444 Url string `positional-arg-name:"IMAGE_URL" required:"yes"`
445 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
446 Crc uint32 `positional-arg-name:"IMAGE_CRC" required:"yes"`
447 LocalDir string `positional-arg-name:"IMAGE_LOCAL_DIRECTORY"`
448 } `positional-args:"yes"`
449}
450
451type DeviceOnuActivateImageUpdate struct {
452 Args struct {
453 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
454 Name string `positional-arg-name:"IMAGE_NAME" required:"yes"`
455 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
456 SaveConfig bool `positional-arg-name:"SAVE_EXISTING_CONFIG"`
457 LocalDir string `positional-arg-name:"IMAGE_LOCAL_DIRECTORY"`
Andrea Campanella7b2ecf42021-02-25 12:27:15 +0100458 } `positional-args:"yes"`
kesavand8ec4fc02021-01-27 09:10:22 -0500459}
kesavand3e2f9f62021-04-22 11:06:38 +0530460
461type OnuDownloadImage struct {
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +0200462 ListOutputOptions
kesavand3e2f9f62021-04-22 11:06:38 +0530463 Args struct {
464 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
465 Url string `positional-arg-name:"IMAGE_URL" required:"yes"`
ssiddiqui7bc89e92021-05-20 20:58:02 +0530466 Vendor string `positional-arg-name:"IMAGE_VENDOR"`
kesavand3e2f9f62021-04-22 11:06:38 +0530467 ActivateOnSuccess bool `positional-arg-name:"IMAGE_ACTIVATE_ON_SUCCESS"`
468 CommitOnSuccess bool `positional-arg-name:"IMAGE_COMMIT_ON_SUCCESS"`
469 Crc uint32 `positional-arg-name:"IMAGE_CRC"`
470 IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
471 } `positional-args:"yes"`
472}
473
474type OnuActivateImage struct {
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +0200475 ListOutputOptions
kesavand3e2f9f62021-04-22 11:06:38 +0530476 Args struct {
477 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
478 CommitOnSuccess bool `positional-arg-name:"IMAGE_COMMIT_ON_SUCCESS"`
479 IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
480 } `positional-args:"yes"`
481}
482
483type OnuAbortUpgradeImage 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 IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
488 } `positional-args:"yes"`
489}
490
491type OnuCommitImage struct {
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +0200492 ListOutputOptions
kesavand3e2f9f62021-04-22 11:06:38 +0530493 Args struct {
494 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
495 IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
496 } `positional-args:"yes"`
497}
498
499type OnuImageStatus struct {
500 ListOutputOptions
501 Args struct {
502 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
Elia Battiston859f3e62022-02-08 15:57:52 +0100503 IDs []DeviceId `positional-arg-name:"DEVICE_ID"`
kesavand3e2f9f62021-04-22 11:06:38 +0530504 } `positional-args:"yes"`
505}
506
507type OnuListImages struct {
508 ListOutputOptions
509 Args struct {
510 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
511 } `positional-args:"yes"`
512}
513
kesavand8ec4fc02021-01-27 09:10:22 -0500514type DeviceGetPortStats struct {
515 ListOutputOptions
516 Args struct {
517 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
518 PortNo uint32 `positional-arg-name:"PORT_NO" required:"yes"`
519 PortType string `positional-arg-name:"PORT_TYPE" required:"yes"`
Andrea Campanella791d88b2021-01-08 13:29:00 +0100520 } `positional-args:"yes"`
521}
kesavand6d1131f2021-02-05 22:38:15 +0530522type UniStatus struct {
523 ListOutputOptions
524 Args struct {
525 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
526 UniIndex uint32 `positional-arg-name:"UNI_INDEX" required:"yes"`
527 } `positional-args:"yes"`
528}
Girish Gowdra4f5ce7c2021-04-29 18:53:21 -0700529type OnuPonOpticalInfo struct {
530 ListOutputOptions
531 Args struct {
532 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
533 } `positional-args:"yes"`
534}
Himani Chawla40acc122021-05-26 18:52:29 +0530535
536type GetOnuStats struct {
537 ListOutputOptions
538 Args struct {
539 OltId DeviceId `positional-arg-name:"OLT_DEVICE_ID" required:"yes"`
540 IntfId uint32 `positional-arg-name:"PON_INTF_ID" required:"yes"`
541 OnuId uint32 `positional-arg-name:"ONU_ID" required:"yes"`
542 } `positional-args:"yes"`
543}
544
Akash Soni6e879c22024-12-20 17:01:34 +0530545type GetOffloadApp struct {
Akash Soni51b6b7a2024-11-20 11:39:38 +0530546 ListOutputOptions
547 Args struct {
548 OltId DeviceId `positional-arg-name:"OLT_DEVICE_ID" required:"yes"`
549 StatsFor extension.GetOffloadedAppsStatisticsRequest_OffloadedApp `positional-arg-name:"OFFLOADED_APP" required:"yes"`
550 } `positional-args:"yes"`
551}
552
Akash Soni6e879c22024-12-20 17:01:34 +0530553type SetOffloadApp struct {
554 ListOutputOptions
Akash Soni51b6b7a2024-11-20 11:39:38 +0530555 Args struct {
Akash Soni6e879c22024-12-20 17:01:34 +0530556 OltId DeviceId `positional-arg-name:"OLT_DEVICE_ID" required:"yes"`
557 Config string `positional-arg-name:"CONFIG" required:"yes"` // Accept JSON or CSV input
Akash Soni51b6b7a2024-11-20 11:39:38 +0530558 } `positional-args:"yes"`
559}
560
Akash Soni6e879c22024-12-20 17:01:34 +0530561type AppOffloadOnuConfig struct {
562 AgentRemoteID string
563 AgentCircuitID string
564 OnuUniId uint32
565}
566
567type SetOnuOffload struct {
568 ListOutputOptions
Akash Soni51b6b7a2024-11-20 11:39:38 +0530569 Args struct {
Akash Soni6e879c22024-12-20 17:01:34 +0530570 OltId DeviceId `positional-arg-name:"OLT_DEVICE_ID" required:"yes"`
571 OnuDeviceId string `positional-arg-name:"ONU_DEVICE_ID" required:"yes"`
572 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 +0530573 } `positional-args:"yes"`
574}
575
Himani Chawla553a1392021-06-10 23:39:17 +0530576type GetOnuEthernetFrameExtendedPmCounters struct {
577 ListOutputOptions
Himani Chawla806aa892021-08-30 15:51:46 +0530578 Reset bool `long:"reset" description:"Reset the counters"`
579 Args struct {
580 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
581 UniIndex *uint32 `positional-arg-name:"UNI_INDEX"`
Himani Chawla553a1392021-06-10 23:39:17 +0530582 } `positional-args:"yes"`
583}
584
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +0530585type GetPonPortStats struct {
586 ListOutputOptions
587 Reset bool `long:"reset" description:"Reset the counters"`
588 Args struct {
589 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
590 PortLabel string `positional-arg-name:"PORT_LABEL" required:"yes"`
591 } `positional-args:"yes"`
592}
593
594type GetNniPortStats 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 GetOnuAllocGemStatsFromOlt struct {
604 ListOutputOptions
605 Args struct {
606 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
607 } `positional-args:"yes"`
608}
Gamze Abakac857a462021-05-26 13:45:54 +0000609type RxPower struct {
610 ListOutputOptions
611 Args struct {
612 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
613 PortNo uint32 `positional-arg-name:"PORT_NO" required:"yes"`
614 OnuNo uint32 `positional-arg-name:"ONU_NO" required:"yes"`
615 } `positional-args:"yes"`
616}
617
praneeth nalmas39c71ad2023-09-27 18:29:04 +0530618type PonRxPower struct {
619 ListOutputOptions
620 Args struct {
621 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
622 PortLabel string `positional-arg-name:"PORT_LABEL" required:"yes"`
623 SerialNo string `positional-arg-name:"ONU_SERIAL_NUMBER"`
624 } `positional-args:"yes"`
625}
626
serkantul3d22fc72022-09-14 12:22:56 +0300627type OnuOmciTxRxStats struct {
628 ListOutputOptions
629 Args struct {
630 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
631 } `positional-args:"yes"`
632}
633
praneeth nalmas1dd094c2022-12-22 14:15:13 +0530634type GetOnuOmciActiveAlarms struct {
635 ListOutputOptions
636 Args struct {
637 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
638 } `positional-args:"yes"`
639}
640
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +0530641type GetOnuGEMStats struct {
642 ListOutputOptions
643 Args struct {
644 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
645 } `positional-args:"yes"`
646}
647
Akash Reddy Kankanala6965c652025-10-15 23:30:16 +0530648type GetOnuFecHistory struct {
649 ListOutputOptions
650 Args struct {
651 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
652 } `positional-args:"yes"`
653}
Akash Soni66db9632024-04-15 09:05:15 +0530654type GetOnuDistance struct {
655 ListOutputOptions
656 Args struct {
657 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
658 OnuId OnuId `positional-arg-name:"ONU_ID" required:"yes"`
659 } `positional-args:"yes"` //onu device id
660}
661
mgouda35b90e62025-07-16 14:58:29 +0530662type DisableOnuDevice struct {
663 Args struct {
664 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
665 } `positional-args:"yes"`
666}
667
668type EnableOnuDevice struct {
669 Args struct {
670 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
671 } `positional-args:"yes"`
672}
673
674type DisableOnuSerialNumber struct {
675 Args struct {
676 SerialNumber string `positional-arg-name:"ONU_SERIAL_NUMBER" required:"yes"`
677 Port PortNum `positional-arg-name:"PORT_NO" required:"yes"`
678 OltDeviceId DeviceId `positional-arg-name:"OLT_DEVICE_ID" required:"yes"`
679 } `positional-args:"yes"`
680}
681
682type EnableOnuSerialNumber struct {
683 Args struct {
684 SerialNumber string `positional-arg-name:"ONU_SERIAL_NUMBER" required:"yes"`
685 Port PortNum `positional-arg-name:"PORT_NO" required:"yes"`
686 OltDeviceId DeviceId `positional-arg-name:"OLT_DEVICE_ID" required:"yes"`
687 } `positional-args:"yes"`
688}
689
Zack Williamse940c7a2019-08-21 14:25:39 -0700690type DeviceOpts struct {
mgouda35b90e62025-07-16 14:58:29 +0530691 List DeviceList `command:"list"`
692 Create DeviceCreate `command:"create"`
693 Delete DeviceDelete `command:"delete"`
694 Enable DeviceEnable `command:"enable"`
695 Disable DeviceDisable `command:"disable"`
696 DisableOnuDevice DisableOnuDevice `command:"disable_onu"`
697 EnableOnuDevice EnableOnuDevice `command:"enable_onu"`
698 DisableOnuSerialNumber DisableOnuSerialNumber `command:"disable_onu_serial"`
699 EnableOnuSerialNumber EnableOnuSerialNumber `command:"enable_onu_serial"`
700 Flows DeviceFlowList `command:"flows"`
701 Groups DeviceFlowGroupList `command:"groups"`
702 Port struct {
kesavand12cd8eb2020-01-20 22:25:22 -0500703 List DevicePortList `command:"list"`
704 Enable DevicePortEnable `command:"enable"`
705 Disable DevicePortDisable `command:"disable"`
706 } `command:"port"`
707 Inspect DeviceInspect `command:"inspect"`
708 Reboot DeviceReboot `command:"reboot"`
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -0800709 Value struct {
710 Get DeviceGetExtValue `command:"get"`
711 } `command:"value"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000712 PmConfig struct {
Rohan Agrawald7df3772020-06-29 11:23:36 +0000713 Get DevicePmConfigsGet `command:"get"`
714 MaxSkew struct {
715 Set DevicePmConfigSetMaxSkew `command:"set"`
716 } `command:"maxskew"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000717 Frequency struct {
718 Set DevicePmConfigFrequencySet `command:"set"`
719 } `command:"frequency"`
720 Metric struct {
721 List DevicePmConfigMetricList `command:"list"`
722 Enable DevicePmConfigMetricEnable `command:"enable"`
723 Disable DevicePmConfigMetricDisable `command:"disable"`
724 } `command:"metric"`
725 Group struct {
Girish Gowdra610acb42021-01-27 13:33:57 -0800726 List DevicePmConfigGroupList `command:"list"`
727 Enable DevicePmConfigGroupEnable `command:"enable"`
728 Disable DevicePmConfigGroupDisable `command:"disable"`
729 Set DevicePmConfigGroupFrequencySet `command:"set"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000730 } `command:"group"`
731 GroupMetric struct {
732 List DevicePmConfigGroupMetricList `command:"list"`
733 } `command:"groupmetric"`
734 } `command:"pmconfig"`
Andrea Campanella791d88b2021-01-08 13:29:00 +0100735 Image struct {
736 Get DeviceOnuListImages `command:"list"`
737 Download DeviceOnuDownloadImage `command:"download"`
738 Activate DeviceOnuActivateImageUpdate `command:"activate"`
739 } `command:"image"`
kesavand3e2f9f62021-04-22 11:06:38 +0530740 DownloadImage struct {
741 Download OnuDownloadImage `command:"download"`
742 Activate OnuActivateImage `command:"activate"`
743 Commit OnuCommitImage `command:"commit"`
744 AbortUpgrade OnuAbortUpgradeImage `command:"abort"`
745 Status OnuImageStatus `command:"status"`
746 List OnuListImages `command:"list" `
747 } `command:"onuimage"`
kesavand8ec4fc02021-01-27 09:10:22 -0500748 GetExtVal struct {
Himani Chawla553a1392021-06-10 23:39:17 +0530749 Stats DeviceGetPortStats `command:"portstats"`
750 UniStatus UniStatus `command:"unistatus"`
751 OpticalInfo OnuPonOpticalInfo `command:"onu_pon_optical_info"`
752 OnuStats GetOnuStats `command:"onu_stats"`
753 EthernetFrameExtendedPm GetOnuEthernetFrameExtendedPmCounters `command:"ethernet_frame_extended_pm"`
754 RxPower RxPower `command:"rxpower"`
serkantul3d22fc72022-09-14 12:22:56 +0300755 OnuOmciStats OnuOmciTxRxStats `command:"onu_omci_stats"`
praneeth nalmas1dd094c2022-12-22 14:15:13 +0530756 OnuOmciActiveAlarms GetOnuOmciActiveAlarms `command:"onu_omci_active_alarms"`
praneeth nalmas39c71ad2023-09-27 18:29:04 +0530757 PonRxPower PonRxPower `command:"pon_rx_power"`
Akash Soni66db9632024-04-15 09:05:15 +0530758 OnuDistance GetOnuDistance `command:"onu_distance"`
Akash Soni6e879c22024-12-20 17:01:34 +0530759 OffloadAppStats GetOffloadApp `command:"offload_app_stats"`
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +0530760 PonStats GetPonPortStats `command:"itu_pon_stats"`
761 NniStats GetNniPortStats `command:"nni_statistics"`
762 OnuGEMStats GetOnuGEMStats `command:"onu_gem_stats"`
763 OnuAllocGemStats GetOnuAllocGemStatsFromOlt `command:"onu_alloc_gem_from_olt"`
Akash Reddy Kankanala6965c652025-10-15 23:30:16 +0530764 OnuFecHistory GetOnuFecHistory `command:"onu_fec_history"`
kesavand8ec4fc02021-01-27 09:10:22 -0500765 } `command:"getextval"`
Akash Soni51b6b7a2024-11-20 11:39:38 +0530766 SetExtVal struct {
Akash Soni6e879c22024-12-20 17:01:34 +0530767 OffloadAppStatsSet SetOffloadApp `command:"set_offload_app"`
768 OnuOffloadStatsSet SetOnuOffload `command:"set_onu_offload"`
Akash Soni51b6b7a2024-11-20 11:39:38 +0530769 } `command:"setextval"`
Zack Williamse940c7a2019-08-21 14:25:39 -0700770}
771
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +0530772type AllocGemStatsFromOlt struct {
773 AllocId uint32
774 AllocRxBytes uint64
775 GemPortStats []GemPortStatsFromOlt
776}
777type GemPortStatsFromOlt struct {
778 GemId uint32
779 RxPackets uint64
780 RxBytes uint64
781 TxPackets uint64
782 TxBytes uint64
783}
784type onugemstats struct {
785 AllocId uint32
786 AllocRxBytes uint32
787 GemHistoryStats []gemHistoryStats
788}
789type gemHistoryStats struct {
790 GemId uint32
791 TransmittedGEMFrames uint32
792 ReceivedGEMFrames uint32
Akash Reddy Kankanalaeba72f62026-01-29 12:49:17 +0000793 ReceivedPayloadBytes uint64
794 TransmittedPayloadBytes uint64
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +0530795 EncryptionKeyErrors uint32
796}
797
798type PortStats struct {
799 PonPort uint32 // use this for PON
800 NniPort uint32 // use this for NNI
801 *common.PortStatistics
802}
803
Zack Williamse940c7a2019-08-21 14:25:39 -0700804var deviceOpts = DeviceOpts{}
805
806func RegisterDeviceCommands(parser *flags.Parser) {
David Bainbridge12f036f2019-10-15 22:09:04 +0000807 if _, err := parser.AddCommand("device", "device commands", "Commands to query and manipulate VOLTHA devices", &deviceOpts); err != nil {
David Bainbridgea6722342019-10-24 23:55:53 +0000808 Error.Fatalf("Unexpected error while attempting to register device commands : %s", err)
David Bainbridge12f036f2019-10-15 22:09:04 +0000809 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700810}
811
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000812func (i *MetricName) Complete(match string) []flags.Completion {
813 conn, err := NewConnection()
814 if err != nil {
815 return nil
816 }
817 defer conn.Close()
818
819 client := voltha.NewVolthaServiceClient(conn)
820
821 var deviceId string
822found:
823 for i := len(os.Args) - 1; i >= 0; i -= 1 {
824 switch os.Args[i] {
825 case "enable":
826 fallthrough
827 case "disable":
828 if len(os.Args) > i+1 {
829 deviceId = os.Args[i+1]
830 } else {
831 return nil
832 }
833 break found
834 default:
835 }
836 }
837
838 if len(deviceId) == 0 {
839 return nil
840 }
841
David K. Bainbridge9189c632021-03-26 21:52:21 +0000842 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000843 defer cancel()
844
845 id := voltha.ID{Id: string(deviceId)}
846
847 pmconfigs, err := client.ListDevicePmConfigs(ctx, &id)
848
849 if err != nil {
850 return nil
851 }
852
853 list := make([]flags.Completion, 0)
854 for _, metrics := range pmconfigs.Metrics {
855 if strings.HasPrefix(metrics.Name, match) {
856 list = append(list, flags.Completion{Item: metrics.Name})
857 }
858 }
859
860 return list
861}
862
863func (i *GroupName) Complete(match string) []flags.Completion {
864 conn, err := NewConnection()
865 if err != nil {
866 return nil
867 }
868 defer conn.Close()
869
870 client := voltha.NewVolthaServiceClient(conn)
871
872 var deviceId string
873found:
874 for i := len(os.Args) - 1; i >= 0; i -= 1 {
875 switch os.Args[i] {
876 case "list":
877 fallthrough
878 case "enable":
879 fallthrough
880 case "disable":
881 if len(os.Args) > i+1 {
882 deviceId = os.Args[i+1]
883 } else {
884 return nil
885 }
886 break found
887 default:
888 }
889 }
890
891 if len(deviceId) == 0 {
892 return nil
893 }
894
David K. Bainbridge9189c632021-03-26 21:52:21 +0000895 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000896 defer cancel()
897
898 id := voltha.ID{Id: string(deviceId)}
899
900 pmconfigs, err := client.ListDevicePmConfigs(ctx, &id)
901
902 if err != nil {
903 return nil
904 }
905
906 list := make([]flags.Completion, 0)
907 for _, group := range pmconfigs.Groups {
908 if strings.HasPrefix(group.GroupName, match) {
909 list = append(list, flags.Completion{Item: group.GroupName})
910 }
911 }
912 return list
913}
914
kesavand12cd8eb2020-01-20 22:25:22 -0500915func (i *PortNum) Complete(match string) []flags.Completion {
916 conn, err := NewConnection()
917 if err != nil {
918 return nil
919 }
920 defer conn.Close()
921
Scott Baker9173ed82020-05-19 08:30:12 -0700922 client := voltha.NewVolthaServiceClient(conn)
kesavand12cd8eb2020-01-20 22:25:22 -0500923
924 /*
925 * The command line args when completing for PortNum will be a DeviceId
926 * followed by one or more PortNums. So walk the argument list from the
927 * end and find the first argument that is enable/disable as those are
928 * the subcommands that come before the positional arguments. It would
929 * be nice if this package gave us the list of optional arguments
930 * already parsed.
931 */
932 var deviceId string
933found:
934 for i := len(os.Args) - 1; i >= 0; i -= 1 {
935 switch os.Args[i] {
936 case "enable":
937 fallthrough
938 case "disable":
939 if len(os.Args) > i+1 {
940 deviceId = os.Args[i+1]
941 } else {
942 return nil
943 }
944 break found
945 default:
946 }
947 }
948
949 if len(deviceId) == 0 {
950 return nil
951 }
952
David K. Bainbridge9189c632021-03-26 21:52:21 +0000953 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand12cd8eb2020-01-20 22:25:22 -0500954 defer cancel()
kesavand12cd8eb2020-01-20 22:25:22 -0500955
Scott Baker9173ed82020-05-19 08:30:12 -0700956 id := voltha.ID{Id: string(deviceId)}
kesavand12cd8eb2020-01-20 22:25:22 -0500957
Scott Baker9173ed82020-05-19 08:30:12 -0700958 ports, err := client.ListDevicePorts(ctx, &id)
kesavand12cd8eb2020-01-20 22:25:22 -0500959 if err != nil {
960 return nil
961 }
962
963 list := make([]flags.Completion, 0)
Scott Baker9173ed82020-05-19 08:30:12 -0700964 for _, item := range ports.Items {
965 pn := strconv.FormatUint(uint64(item.PortNo), 10)
kesavand12cd8eb2020-01-20 22:25:22 -0500966 if strings.HasPrefix(pn, match) {
967 list = append(list, flags.Completion{Item: pn})
968 }
969 }
970
971 return list
972}
973
Zack Williamse940c7a2019-08-21 14:25:39 -0700974func (i *DeviceId) Complete(match string) []flags.Completion {
975 conn, err := NewConnection()
976 if err != nil {
977 return nil
978 }
979 defer conn.Close()
980
Scott Baker9173ed82020-05-19 08:30:12 -0700981 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700982
David K. Bainbridge9189c632021-03-26 21:52:21 +0000983 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700984 defer cancel()
985
Scott Baker9173ed82020-05-19 08:30:12 -0700986 devices, err := client.ListDevices(ctx, &empty.Empty{})
Zack Williamse940c7a2019-08-21 14:25:39 -0700987 if err != nil {
988 return nil
989 }
990
991 list := make([]flags.Completion, 0)
Scott Baker9173ed82020-05-19 08:30:12 -0700992 for _, item := range devices.Items {
993 if strings.HasPrefix(item.Id, match) {
994 list = append(list, flags.Completion{Item: item.Id})
Zack Williamse940c7a2019-08-21 14:25:39 -0700995 }
996 }
997
998 return list
999}
1000
1001func (options *DeviceList) Execute(args []string) error {
1002
1003 conn, err := NewConnection()
1004 if err != nil {
1005 return err
1006 }
1007 defer conn.Close()
1008
Scott Baker9173ed82020-05-19 08:30:12 -07001009 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -07001010
David K. Bainbridge9189c632021-03-26 21:52:21 +00001011 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -07001012 defer cancel()
1013
Scott Baker9173ed82020-05-19 08:30:12 -07001014 devices, err := client.ListDevices(ctx, &empty.Empty{})
Zack Williamse940c7a2019-08-21 14:25:39 -07001015 if err != nil {
1016 return err
1017 }
1018
1019 outputFormat := CharReplacer.Replace(options.Format)
1020 if outputFormat == "" {
David Bainbridgea6722342019-10-24 23:55:53 +00001021 outputFormat = GetCommandOptionWithDefault("device-list", "format", DEFAULT_DEVICE_FORMAT)
Zack Williamse940c7a2019-08-21 14:25:39 -07001022 }
1023 if options.Quiet {
1024 outputFormat = "{{.Id}}"
1025 }
1026
David Bainbridgea6722342019-10-24 23:55:53 +00001027 orderBy := options.OrderBy
1028 if orderBy == "" {
Hardik Windlass9361bb82022-03-23 05:58:48 +00001029 orderBy = GetCommandOptionWithDefault("device-list", "order", DEFAULT_DEVICE_ORDER)
David Bainbridgea6722342019-10-24 23:55:53 +00001030 }
1031
Scott Baker9173ed82020-05-19 08:30:12 -07001032 // Make sure json output prints an empty list, not "null"
1033 if devices.Items == nil {
1034 devices.Items = make([]*voltha.Device, 0)
Zack Williamse940c7a2019-08-21 14:25:39 -07001035 }
1036
1037 result := CommandResult{
1038 Format: format.Format(outputFormat),
1039 Filter: options.Filter,
David Bainbridgea6722342019-10-24 23:55:53 +00001040 OrderBy: orderBy,
Zack Williamse940c7a2019-08-21 14:25:39 -07001041 OutputAs: toOutputType(options.OutputAs),
1042 NameLimit: options.NameLimit,
Scott Baker9173ed82020-05-19 08:30:12 -07001043 Data: devices.Items,
Zack Williamse940c7a2019-08-21 14:25:39 -07001044 }
1045
1046 GenerateOutput(&result)
1047 return nil
1048}
1049
1050func (options *DeviceCreate) Execute(args []string) error {
1051
Scott Baker9173ed82020-05-19 08:30:12 -07001052 device := voltha.Device{}
Zack Williamse940c7a2019-08-21 14:25:39 -07001053 if options.HostAndPort != "" {
Scott Baker9173ed82020-05-19 08:30:12 -07001054 device.Address = &voltha.Device_HostAndPort{HostAndPort: options.HostAndPort}
Zack Williamse940c7a2019-08-21 14:25:39 -07001055 } else if options.IPAddress != "" {
Scott Baker9173ed82020-05-19 08:30:12 -07001056 device.Address = &voltha.Device_Ipv4Address{Ipv4Address: options.IPAddress}
Hardik Windlassce1de342020-02-04 21:58:07 +00001057 }
1058 if options.MACAddress != "" {
Scott Baker9173ed82020-05-19 08:30:12 -07001059 device.MacAddress = strings.ToLower(options.MACAddress)
Zack Williamse940c7a2019-08-21 14:25:39 -07001060 }
1061 if options.DeviceType != "" {
Scott Baker9173ed82020-05-19 08:30:12 -07001062 device.Type = options.DeviceType
Zack Williamse940c7a2019-08-21 14:25:39 -07001063 }
1064
1065 conn, err := NewConnection()
1066 if err != nil {
1067 return err
1068 }
1069 defer conn.Close()
1070
Scott Baker9173ed82020-05-19 08:30:12 -07001071 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -07001072
David K. Bainbridge9189c632021-03-26 21:52:21 +00001073 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -07001074 defer cancel()
1075
Scott Baker9173ed82020-05-19 08:30:12 -07001076 createdDevice, err := client.CreateDevice(ctx, &device)
Zack Williamse940c7a2019-08-21 14:25:39 -07001077 if err != nil {
1078 return err
Zack Williamse940c7a2019-08-21 14:25:39 -07001079 }
1080
Scott Baker9173ed82020-05-19 08:30:12 -07001081 fmt.Printf("%s\n", createdDevice.Id)
Zack Williamse940c7a2019-08-21 14:25:39 -07001082
1083 return nil
1084}
1085
1086func (options *DeviceDelete) Execute(args []string) error {
1087
1088 conn, err := NewConnection()
1089 if err != nil {
1090 return err
1091 }
1092 defer conn.Close()
1093
Scott Baker9173ed82020-05-19 08:30:12 -07001094 client := voltha.NewVolthaServiceClient(conn)
David Bainbridge7052fe82020-03-25 10:37:00 -07001095 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -07001096 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +00001097 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -07001098 defer cancel()
1099
Scott Baker9173ed82020-05-19 08:30:12 -07001100 id := voltha.ID{Id: string(i)}
Himani Chawla9933ddc2020-10-12 23:53:27 +05301101 if options.Force {
1102 _, err = client.ForceDeleteDevice(ctx, &id)
1103 } else {
1104 _, err = client.DeleteDevice(ctx, &id)
1105 }
Scott Baker9173ed82020-05-19 08:30:12 -07001106
Zack Williamse940c7a2019-08-21 14:25:39 -07001107 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +00001108 Error.Printf("Error while deleting '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -07001109 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -07001110 continue
Zack Williamse940c7a2019-08-21 14:25:39 -07001111 }
1112 fmt.Printf("%s\n", i)
1113 }
1114
David Bainbridge7052fe82020-03-25 10:37:00 -07001115 if lastErr != nil {
1116 return NoReportErr
1117 }
Zack Williamse940c7a2019-08-21 14:25:39 -07001118 return nil
1119}
1120
1121func (options *DeviceEnable) Execute(args []string) error {
1122 conn, err := NewConnection()
1123 if err != nil {
1124 return err
1125 }
1126 defer conn.Close()
1127
Scott Baker9173ed82020-05-19 08:30:12 -07001128 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -07001129
David Bainbridge7052fe82020-03-25 10:37:00 -07001130 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -07001131 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +00001132 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -07001133 defer cancel()
1134
Scott Baker9173ed82020-05-19 08:30:12 -07001135 id := voltha.ID{Id: string(i)}
1136
1137 _, err := client.EnableDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -07001138 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +00001139 Error.Printf("Error while enabling '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -07001140 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -07001141 continue
Zack Williamse940c7a2019-08-21 14:25:39 -07001142 }
1143 fmt.Printf("%s\n", i)
1144 }
1145
David Bainbridge7052fe82020-03-25 10:37:00 -07001146 if lastErr != nil {
1147 return NoReportErr
1148 }
Zack Williamse940c7a2019-08-21 14:25:39 -07001149 return nil
1150}
1151
1152func (options *DeviceDisable) Execute(args []string) error {
1153 conn, err := NewConnection()
1154 if err != nil {
1155 return err
1156 }
1157 defer conn.Close()
1158
Scott Baker9173ed82020-05-19 08:30:12 -07001159 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -07001160
David Bainbridge7052fe82020-03-25 10:37:00 -07001161 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -07001162 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +00001163 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -07001164 defer cancel()
1165
Scott Baker9173ed82020-05-19 08:30:12 -07001166 id := voltha.ID{Id: string(i)}
1167
1168 _, err := client.DisableDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -07001169 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +00001170 Error.Printf("Error while disabling '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -07001171 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -07001172 continue
Zack Williamse940c7a2019-08-21 14:25:39 -07001173 }
1174 fmt.Printf("%s\n", i)
1175 }
1176
David Bainbridge7052fe82020-03-25 10:37:00 -07001177 if lastErr != nil {
1178 return NoReportErr
1179 }
Zack Williamse940c7a2019-08-21 14:25:39 -07001180 return nil
1181}
1182
1183func (options *DeviceReboot) Execute(args []string) error {
1184 conn, err := NewConnection()
1185 if err != nil {
1186 return err
1187 }
1188 defer conn.Close()
1189
Scott Baker9173ed82020-05-19 08:30:12 -07001190 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -07001191
David Bainbridge7052fe82020-03-25 10:37:00 -07001192 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -07001193 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +00001194 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -07001195 defer cancel()
1196
Scott Baker9173ed82020-05-19 08:30:12 -07001197 id := voltha.ID{Id: string(i)}
1198
1199 _, err := client.RebootDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -07001200 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +00001201 Error.Printf("Error while rebooting '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -07001202 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -07001203 continue
Zack Williamse940c7a2019-08-21 14:25:39 -07001204 }
1205 fmt.Printf("%s\n", i)
1206 }
1207
David Bainbridge7052fe82020-03-25 10:37:00 -07001208 if lastErr != nil {
1209 return NoReportErr
1210 }
Zack Williamse940c7a2019-08-21 14:25:39 -07001211 return nil
1212}
1213
1214func (options *DevicePortList) Execute(args []string) error {
1215
1216 conn, err := NewConnection()
1217 if err != nil {
1218 return err
1219 }
1220 defer conn.Close()
1221
Scott Baker9173ed82020-05-19 08:30:12 -07001222 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -07001223
David K. Bainbridge9189c632021-03-26 21:52:21 +00001224 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -07001225 defer cancel()
1226
Scott Baker9173ed82020-05-19 08:30:12 -07001227 id := voltha.ID{Id: string(options.Args.Id)}
Zack Williamse940c7a2019-08-21 14:25:39 -07001228
Scott Baker9173ed82020-05-19 08:30:12 -07001229 ports, err := client.ListDevicePorts(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -07001230 if err != nil {
1231 return err
1232 }
1233
1234 outputFormat := CharReplacer.Replace(options.Format)
1235 if outputFormat == "" {
David Bainbridgea6722342019-10-24 23:55:53 +00001236 outputFormat = GetCommandOptionWithDefault("device-ports", "format", DEFAULT_DEVICE_PORTS_FORMAT)
Zack Williamse940c7a2019-08-21 14:25:39 -07001237 }
Zack Williamse940c7a2019-08-21 14:25:39 -07001238
David Bainbridgea6722342019-10-24 23:55:53 +00001239 orderBy := options.OrderBy
1240 if orderBy == "" {
1241 orderBy = GetCommandOptionWithDefault("device-ports", "order", "")
1242 }
1243
Zack Williamse940c7a2019-08-21 14:25:39 -07001244 result := CommandResult{
1245 Format: format.Format(outputFormat),
1246 Filter: options.Filter,
David Bainbridgea6722342019-10-24 23:55:53 +00001247 OrderBy: orderBy,
Zack Williamse940c7a2019-08-21 14:25:39 -07001248 OutputAs: toOutputType(options.OutputAs),
1249 NameLimit: options.NameLimit,
Scott Baker9173ed82020-05-19 08:30:12 -07001250 Data: ports.Items,
Zack Williamse940c7a2019-08-21 14:25:39 -07001251 }
1252
1253 GenerateOutput(&result)
1254 return nil
1255}
1256
1257func (options *DeviceFlowList) Execute(args []string) error {
1258 fl := &FlowList{}
1259 fl.ListOutputOptions = options.ListOutputOptions
Maninder045921e2020-09-29 16:46:02 +05301260 fl.FlowIdOptions = options.FlowIdOptions
Zack Williamse940c7a2019-08-21 14:25:39 -07001261 fl.Args.Id = string(options.Args.Id)
David Bainbridgea6722342019-10-24 23:55:53 +00001262 fl.Method = "device-flows"
Zack Williamse940c7a2019-08-21 14:25:39 -07001263 return fl.Execute(args)
1264}
1265
Himani Chawla3c161c62021-05-13 16:36:51 +05301266func (options *DeviceFlowGroupList) Execute(args []string) error {
1267 grp := &GroupList{}
1268 grp.ListOutputOptions = options.ListOutputOptions
1269 grp.GroupListOptions = options.GroupListOptions
1270 grp.Args.Id = string(options.Args.Id)
1271 grp.Method = "device-groups"
1272 return grp.Execute(args)
1273}
1274
Zack Williamse940c7a2019-08-21 14:25:39 -07001275func (options *DeviceInspect) Execute(args []string) error {
1276 if len(args) > 0 {
1277 return fmt.Errorf("only a single argument 'DEVICE_ID' can be provided")
1278 }
1279
1280 conn, err := NewConnection()
1281 if err != nil {
1282 return err
1283 }
1284 defer conn.Close()
1285
Scott Baker9173ed82020-05-19 08:30:12 -07001286 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -07001287
David K. Bainbridge9189c632021-03-26 21:52:21 +00001288 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -07001289 defer cancel()
1290
Scott Baker9173ed82020-05-19 08:30:12 -07001291 id := voltha.ID{Id: string(options.Args.Id)}
Zack Williamse940c7a2019-08-21 14:25:39 -07001292
Scott Baker9173ed82020-05-19 08:30:12 -07001293 device, err := client.GetDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -07001294 if err != nil {
1295 return err
1296 }
1297
Zack Williamse940c7a2019-08-21 14:25:39 -07001298 outputFormat := CharReplacer.Replace(options.Format)
1299 if outputFormat == "" {
David Bainbridgea6722342019-10-24 23:55:53 +00001300 outputFormat = GetCommandOptionWithDefault("device-inspect", "format", DEFAULT_DEVICE_INSPECT_FORMAT)
Zack Williamse940c7a2019-08-21 14:25:39 -07001301 }
1302 if options.Quiet {
1303 outputFormat = "{{.Id}}"
1304 }
1305
1306 result := CommandResult{
1307 Format: format.Format(outputFormat),
1308 OutputAs: toOutputType(options.OutputAs),
1309 NameLimit: options.NameLimit,
1310 Data: device,
1311 }
1312 GenerateOutput(&result)
1313 return nil
1314}
kesavand12cd8eb2020-01-20 22:25:22 -05001315
1316/*Device Port Enable */
1317func (options *DevicePortEnable) Execute(args []string) error {
1318 conn, err := NewConnection()
1319 if err != nil {
1320 return err
1321 }
1322 defer conn.Close()
1323
Scott Baker9173ed82020-05-19 08:30:12 -07001324 client := voltha.NewVolthaServiceClient(conn)
kesavand12cd8eb2020-01-20 22:25:22 -05001325
David K. Bainbridge9189c632021-03-26 21:52:21 +00001326 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand12cd8eb2020-01-20 22:25:22 -05001327 defer cancel()
1328
Scott Baker9173ed82020-05-19 08:30:12 -07001329 port := voltha.Port{DeviceId: string(options.Args.Id), PortNo: uint32(options.Args.PortId)}
1330
1331 _, err = client.EnablePort(ctx, &port)
kesavand12cd8eb2020-01-20 22:25:22 -05001332 if err != nil {
1333 Error.Printf("Error enabling port number %v on device Id %s,err=%s\n", options.Args.PortId, options.Args.Id, ErrorToString(err))
1334 return err
kesavand12cd8eb2020-01-20 22:25:22 -05001335 }
1336
1337 return nil
1338}
1339
Scott Baker9173ed82020-05-19 08:30:12 -07001340/*Device Port Disable */
kesavand12cd8eb2020-01-20 22:25:22 -05001341func (options *DevicePortDisable) Execute(args []string) error {
1342 conn, err := NewConnection()
1343 if err != nil {
1344 return err
1345 }
1346 defer conn.Close()
1347
Scott Baker9173ed82020-05-19 08:30:12 -07001348 client := voltha.NewVolthaServiceClient(conn)
1349
David K. Bainbridge9189c632021-03-26 21:52:21 +00001350 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand12cd8eb2020-01-20 22:25:22 -05001351 defer cancel()
1352
Scott Baker9173ed82020-05-19 08:30:12 -07001353 port := voltha.Port{DeviceId: string(options.Args.Id), PortNo: uint32(options.Args.PortId)}
1354
1355 _, err = client.DisablePort(ctx, &port)
kesavand12cd8eb2020-01-20 22:25:22 -05001356 if err != nil {
Scott Baker9173ed82020-05-19 08:30:12 -07001357 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 -05001358 return err
kesavand12cd8eb2020-01-20 22:25:22 -05001359 }
Scott Baker9173ed82020-05-19 08:30:12 -07001360
kesavand12cd8eb2020-01-20 22:25:22 -05001361 return nil
1362}
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08001363
Rohan Agrawald7df3772020-06-29 11:23:36 +00001364func (options *DevicePmConfigSetMaxSkew) Execute(args []string) error {
1365 conn, err := NewConnection()
1366 if err != nil {
1367 return err
1368 }
1369 defer conn.Close()
1370
1371 client := voltha.NewVolthaServiceClient(conn)
1372
David K. Bainbridge9189c632021-03-26 21:52:21 +00001373 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawald7df3772020-06-29 11:23:36 +00001374 defer cancel()
1375
1376 id := voltha.ID{Id: string(options.Args.Id)}
1377
1378 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1379 if err != nil {
1380 return err
1381 }
1382
1383 pmConfigs.MaxSkew = options.Args.MaxSkew
1384
1385 _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs)
1386 if err != nil {
1387 return err
1388 }
1389
1390 return nil
1391}
1392
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001393func (options *DevicePmConfigsGet) Execute(args []string) error {
1394
1395 conn, err := NewConnection()
1396 if err != nil {
1397 return err
1398 }
1399 defer conn.Close()
1400
1401 client := voltha.NewVolthaServiceClient(conn)
1402
David K. Bainbridge9189c632021-03-26 21:52:21 +00001403 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001404 defer cancel()
1405
1406 id := voltha.ID{Id: string(options.Args.Id)}
1407
1408 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1409 if err != nil {
1410 return err
1411 }
1412
1413 outputFormat := CharReplacer.Replace(options.Format)
1414 if outputFormat == "" {
1415 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GET_FORMAT)
1416 }
1417
1418 orderBy := options.OrderBy
1419 if orderBy == "" {
1420 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1421 }
1422
1423 result := CommandResult{
1424 Format: format.Format(outputFormat),
1425 Filter: options.Filter,
1426 OrderBy: orderBy,
1427 OutputAs: toOutputType(options.OutputAs),
1428 NameLimit: options.NameLimit,
1429 Data: pmConfigs,
1430 }
1431
1432 GenerateOutput(&result)
1433 return nil
1434
1435}
1436
1437func (options *DevicePmConfigMetricList) Execute(args []string) error {
1438
1439 conn, err := NewConnection()
1440 if err != nil {
1441 return err
1442 }
1443 defer conn.Close()
1444
1445 client := voltha.NewVolthaServiceClient(conn)
1446
David K. Bainbridge9189c632021-03-26 21:52:21 +00001447 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001448 defer cancel()
1449
1450 id := voltha.ID{Id: string(options.Args.Id)}
1451
1452 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1453 if err != nil {
1454 return err
1455 }
1456
1457 if !pmConfigs.Grouped {
1458 for _, metric := range pmConfigs.Metrics {
1459 if metric.SampleFreq == 0 {
1460 metric.SampleFreq = pmConfigs.DefaultFreq
1461 }
1462 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001463 outputFormat := CharReplacer.Replace(options.Format)
1464 if outputFormat == "" {
1465 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_METRIC_LIST_FORMAT)
1466 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001467
Rohan Agrawalbca69122020-06-17 14:59:03 +00001468 orderBy := options.OrderBy
1469 if orderBy == "" {
1470 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1471 }
1472
1473 result := CommandResult{
1474 Format: format.Format(outputFormat),
1475 Filter: options.Filter,
1476 OrderBy: orderBy,
1477 OutputAs: toOutputType(options.OutputAs),
1478 NameLimit: options.NameLimit,
1479 Data: pmConfigs.Metrics,
1480 }
1481
1482 GenerateOutput(&result)
1483 return nil
1484 } else {
1485 return fmt.Errorf("Device '%s' does not have Non Grouped Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001486 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001487}
1488
1489func (options *DevicePmConfigMetricEnable) Execute(args []string) error {
1490
1491 conn, err := NewConnection()
1492 if err != nil {
1493 return err
1494 }
1495 defer conn.Close()
1496
1497 client := voltha.NewVolthaServiceClient(conn)
1498
David K. Bainbridge9189c632021-03-26 21:52:21 +00001499 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001500 defer cancel()
1501
1502 id := voltha.ID{Id: string(options.Args.Id)}
1503
1504 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1505 if err != nil {
1506 return err
1507 }
1508
1509 if !pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001510 metrics := make(map[string]struct{})
1511 for _, metric := range pmConfigs.Metrics {
1512 metrics[metric.Name] = struct{}{}
1513 }
1514
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001515 for _, metric := range pmConfigs.Metrics {
1516 for _, mName := range options.Args.Metrics {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001517 if _, exist := metrics[string(mName)]; !exist {
1518 return fmt.Errorf("Metric Name '%s' does not exist", mName)
1519 }
1520
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001521 if string(mName) == metric.Name && !metric.Enabled {
1522 metric.Enabled = true
1523 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1524 if err != nil {
1525 return err
1526 }
1527 }
1528 }
1529 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001530 } else {
1531 return fmt.Errorf("Device '%s' does not have Non Grouped Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001532 }
1533 return nil
1534}
1535
1536func (options *DevicePmConfigMetricDisable) Execute(args []string) error {
1537
1538 conn, err := NewConnection()
1539 if err != nil {
1540 return err
1541 }
1542 defer conn.Close()
1543
1544 client := voltha.NewVolthaServiceClient(conn)
1545
David K. Bainbridge9189c632021-03-26 21:52:21 +00001546 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001547 defer cancel()
1548
1549 id := voltha.ID{Id: string(options.Args.Id)}
1550
1551 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1552 if err != nil {
1553 return err
1554 }
1555
1556 if !pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001557 metrics := make(map[string]struct{})
1558 for _, metric := range pmConfigs.Metrics {
1559 metrics[metric.Name] = struct{}{}
1560 }
1561
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001562 for _, metric := range pmConfigs.Metrics {
1563 for _, mName := range options.Args.Metrics {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001564 if _, have := metrics[string(mName)]; !have {
1565 return fmt.Errorf("Metric Name '%s' does not exist", mName)
1566 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001567 if string(mName) == metric.Name && metric.Enabled {
1568 metric.Enabled = false
1569 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1570 if err != nil {
1571 return err
1572 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001573 } else {
1574 return fmt.Errorf("Metric '%s' cannot be disabled", string(mName))
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001575 }
1576 }
1577 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001578 } else {
1579 return fmt.Errorf("Device '%s' does not have Non Grouped Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001580 }
1581 return nil
1582}
1583
1584func (options *DevicePmConfigGroupEnable) Execute(args []string) error {
1585
1586 conn, err := NewConnection()
1587 if err != nil {
1588 return err
1589 }
1590 defer conn.Close()
1591
1592 client := voltha.NewVolthaServiceClient(conn)
1593
David K. Bainbridge9189c632021-03-26 21:52:21 +00001594 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001595 defer cancel()
1596
1597 id := voltha.ID{Id: string(options.Args.Id)}
1598
1599 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1600 if err != nil {
1601 return err
1602 }
1603
1604 if pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001605 groups := make(map[string]struct{})
1606 for _, group := range pmConfigs.Groups {
1607 groups[group.GroupName] = struct{}{}
1608 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001609 for _, group := range pmConfigs.Groups {
Girish Gowdra610acb42021-01-27 13:33:57 -08001610 if _, have := groups[string(options.Args.Group)]; !have {
1611 return fmt.Errorf("Group Name '%s' does not exist", options.Args.Group)
1612 }
1613 if string(options.Args.Group) == group.GroupName && !group.Enabled {
1614 group.Enabled = true
1615 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1616 if err != nil {
1617 return err
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001618 }
1619 }
1620 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001621 } else {
1622 return fmt.Errorf("Device '%s' does not have Group Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001623 }
1624 return nil
1625}
1626
1627func (options *DevicePmConfigGroupDisable) Execute(args []string) error {
1628
1629 conn, err := NewConnection()
1630 if err != nil {
1631 return err
1632 }
1633 defer conn.Close()
1634
1635 client := voltha.NewVolthaServiceClient(conn)
1636
David K. Bainbridge9189c632021-03-26 21:52:21 +00001637 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001638 defer cancel()
1639
1640 id := voltha.ID{Id: string(options.Args.Id)}
1641
1642 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1643 if err != nil {
1644 return err
1645 }
1646
1647 if pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001648 groups := make(map[string]struct{})
1649 for _, group := range pmConfigs.Groups {
1650 groups[group.GroupName] = struct{}{}
1651 }
1652
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001653 for _, group := range pmConfigs.Groups {
Girish Gowdra610acb42021-01-27 13:33:57 -08001654 if _, have := groups[string(options.Args.Group)]; !have {
1655 return fmt.Errorf("Group Name '%s' does not exist", options.Args.Group)
1656 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001657
Girish Gowdra610acb42021-01-27 13:33:57 -08001658 if string(options.Args.Group) == group.GroupName && group.Enabled {
1659 group.Enabled = false
1660 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1661 if err != nil {
1662 return err
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001663 }
1664 }
1665 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001666 } else {
1667 return fmt.Errorf("Device '%s' does not have Group Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001668 }
1669 return nil
1670}
1671
Girish Gowdra610acb42021-01-27 13:33:57 -08001672func (options *DevicePmConfigGroupFrequencySet) Execute(args []string) error {
1673
1674 conn, err := NewConnection()
1675 if err != nil {
1676 return err
1677 }
1678 defer conn.Close()
1679
1680 client := voltha.NewVolthaServiceClient(conn)
1681
David K. Bainbridge9189c632021-03-26 21:52:21 +00001682 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Girish Gowdra610acb42021-01-27 13:33:57 -08001683 defer cancel()
1684
1685 id := voltha.ID{Id: string(options.Args.Id)}
1686
1687 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1688 if err != nil {
1689 return err
1690 }
1691
1692 if pmConfigs.Grouped {
1693 groups := make(map[string]struct{})
1694 for _, group := range pmConfigs.Groups {
1695 groups[group.GroupName] = struct{}{}
1696 }
1697
1698 for _, group := range pmConfigs.Groups {
1699 if _, have := groups[string(options.Args.Group)]; !have {
1700 return fmt.Errorf("group name '%s' does not exist", options.Args.Group)
1701 }
1702
1703 if string(options.Args.Group) == group.GroupName {
1704 if !group.Enabled {
1705 return fmt.Errorf("group '%s' is not enabled", options.Args.Group)
1706 }
1707 group.GroupFreq = uint32(options.Args.Interval.Seconds())
1708 _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs)
1709 if err != nil {
1710 return err
1711 }
1712 }
1713 }
1714 } else {
1715 return fmt.Errorf("device '%s' does not have group metrics", options.Args.Id)
1716 }
1717 return nil
1718}
1719
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001720func (options *DevicePmConfigGroupList) Execute(args []string) error {
1721
1722 conn, err := NewConnection()
1723 if err != nil {
1724 return err
1725 }
1726 defer conn.Close()
1727
1728 client := voltha.NewVolthaServiceClient(conn)
1729
David K. Bainbridge9189c632021-03-26 21:52:21 +00001730 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001731 defer cancel()
1732
1733 id := voltha.ID{Id: string(options.Args.Id)}
1734
1735 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1736 if err != nil {
1737 return err
1738 }
1739
1740 if pmConfigs.Grouped {
1741 for _, group := range pmConfigs.Groups {
1742 if group.GroupFreq == 0 {
1743 group.GroupFreq = pmConfigs.DefaultFreq
1744 }
1745 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001746 outputFormat := CharReplacer.Replace(options.Format)
1747 if outputFormat == "" {
1748 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GROUP_LIST_FORMAT)
1749 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001750
Rohan Agrawalbca69122020-06-17 14:59:03 +00001751 orderBy := options.OrderBy
1752 if orderBy == "" {
1753 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1754 }
1755
1756 result := CommandResult{
1757 Format: format.Format(outputFormat),
1758 Filter: options.Filter,
1759 OrderBy: orderBy,
1760 OutputAs: toOutputType(options.OutputAs),
1761 NameLimit: options.NameLimit,
1762 Data: pmConfigs.Groups,
1763 }
1764
1765 GenerateOutput(&result)
1766 } else {
1767 return fmt.Errorf("Device '%s' does not have Group Metrics", string(options.Args.Id))
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001768 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001769 return nil
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001770}
1771
1772func (options *DevicePmConfigGroupMetricList) Execute(args []string) error {
1773
1774 var metrics []*voltha.PmConfig
1775 conn, err := NewConnection()
1776 if err != nil {
1777 return err
1778 }
1779 defer conn.Close()
1780
1781 client := voltha.NewVolthaServiceClient(conn)
1782
David K. Bainbridge9189c632021-03-26 21:52:21 +00001783 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001784 defer cancel()
1785
1786 id := voltha.ID{Id: string(options.Args.Id)}
1787
1788 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1789 if err != nil {
1790 return err
1791 }
1792
1793 for _, groups := range pmConfigs.Groups {
1794
1795 if string(options.Args.Group) == groups.GroupName {
1796 for _, metric := range groups.Metrics {
1797 if metric.SampleFreq == 0 && groups.GroupFreq == 0 {
1798 metric.SampleFreq = pmConfigs.DefaultFreq
1799 } else {
1800 metric.SampleFreq = groups.GroupFreq
1801 }
1802 }
1803 metrics = groups.Metrics
1804 }
1805 }
1806
1807 outputFormat := CharReplacer.Replace(options.Format)
1808 if outputFormat == "" {
1809 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_METRIC_LIST_FORMAT)
1810 }
1811
1812 orderBy := options.OrderBy
1813 if orderBy == "" {
1814 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1815 }
1816
1817 result := CommandResult{
1818 Format: format.Format(outputFormat),
1819 Filter: options.Filter,
1820 OrderBy: orderBy,
1821 OutputAs: toOutputType(options.OutputAs),
1822 NameLimit: options.NameLimit,
1823 Data: metrics,
1824 }
1825
1826 GenerateOutput(&result)
1827 return nil
1828
1829}
1830
1831func (options *DevicePmConfigFrequencySet) Execute(args []string) error {
1832
1833 conn, err := NewConnection()
1834 if err != nil {
1835 return err
1836 }
1837 defer conn.Close()
1838
1839 client := voltha.NewVolthaServiceClient(conn)
1840
David K. Bainbridge9189c632021-03-26 21:52:21 +00001841 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001842 defer cancel()
1843
1844 id := voltha.ID{Id: string(options.Args.Id)}
1845
1846 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1847 if err != nil {
1848 return err
1849 }
1850
Girish Gowdra610acb42021-01-27 13:33:57 -08001851 pmConfigs.DefaultFreq = uint32(options.Args.Interval.Seconds())
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001852
1853 _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs)
1854 if err != nil {
1855 return err
1856 }
1857
1858 outputFormat := CharReplacer.Replace(options.Format)
1859 if outputFormat == "" {
1860 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GET_FORMAT)
1861 }
1862 if options.Quiet {
1863 outputFormat = "{{.Id}}"
1864 }
1865
1866 result := CommandResult{
1867 Format: format.Format(outputFormat),
1868 OutputAs: toOutputType(options.OutputAs),
1869 NameLimit: options.NameLimit,
1870 Data: pmConfigs,
1871 }
1872
1873 GenerateOutput(&result)
1874 return nil
1875
1876}
1877
kesavand3e2f9f62021-04-22 11:06:38 +05301878func (options *OnuDownloadImage) Execute(args []string) error {
1879
1880 conn, err := NewConnection()
1881 if err != nil {
1882 return err
1883 }
1884 defer conn.Close()
1885
1886 client := voltha.NewVolthaServiceClient(conn)
1887
1888 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1889 defer cancel()
1890
1891 var devIDList []*common.ID
1892 for _, i := range options.Args.IDs {
1893
1894 devIDList = append(devIDList, &common.ID{Id: string(i)})
1895 }
1896
1897 downloadImage := voltha.DeviceImageDownloadRequest{
1898 DeviceId: devIDList,
1899 Image: &voltha.Image{
1900 Url: options.Args.Url,
1901 Crc32: options.Args.Crc,
ssiddiqui7bc89e92021-05-20 20:58:02 +05301902 Vendor: options.Args.Vendor,
kesavand3e2f9f62021-04-22 11:06:38 +05301903 Version: options.Args.ImageVersion,
1904 },
1905 ActivateOnSuccess: options.Args.ActivateOnSuccess,
1906 CommitOnSuccess: options.Args.CommitOnSuccess,
1907 }
1908
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001909 deviceImageResp, err := client.DownloadImageToDevice(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301910 if err != nil {
1911 return err
1912 }
1913
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001914 outputFormat := GetCommandOptionWithDefault("onu-image-download", "format", ONU_IMAGE_STATUS_FORMAT)
1915 // Make sure json output prints an empty list, not "null"
1916 if deviceImageResp.DeviceImageStates == nil {
1917 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1918 }
1919 result := CommandResult{
1920 Format: format.Format(outputFormat),
1921 OutputAs: toOutputType(options.OutputAs),
1922 NameLimit: options.NameLimit,
1923 Data: deviceImageResp.DeviceImageStates,
1924 }
1925 GenerateOutput(&result)
kesavand3e2f9f62021-04-22 11:06:38 +05301926 return nil
1927
1928}
1929
1930func (options *OnuActivateImage) Execute(args []string) error {
1931
1932 conn, err := NewConnection()
1933 if err != nil {
1934 return err
1935 }
1936 defer conn.Close()
1937
1938 client := voltha.NewVolthaServiceClient(conn)
1939
1940 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1941 defer cancel()
1942
1943 var devIDList []*common.ID
1944 for _, i := range options.Args.IDs {
1945
1946 devIDList = append(devIDList, &common.ID{Id: string(i)})
1947 }
1948
1949 downloadImage := voltha.DeviceImageRequest{
1950 DeviceId: devIDList,
1951 Version: options.Args.ImageVersion,
1952 CommitOnSuccess: options.Args.CommitOnSuccess,
1953 }
1954
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001955 deviceImageResp, err := client.ActivateImage(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301956 if err != nil {
1957 return err
1958 }
1959
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001960 outputFormat := GetCommandOptionWithDefault("onu-image-activate", "format", ONU_IMAGE_STATUS_FORMAT)
1961 // Make sure json output prints an empty list, not "null"
1962 if deviceImageResp.DeviceImageStates == nil {
1963 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1964 }
1965 result := CommandResult{
1966 Format: format.Format(outputFormat),
1967 OutputAs: toOutputType(options.OutputAs),
1968 NameLimit: options.NameLimit,
1969 Data: deviceImageResp.DeviceImageStates,
1970 }
1971 GenerateOutput(&result)
1972
kesavand3e2f9f62021-04-22 11:06:38 +05301973 return nil
1974
1975}
1976
1977func (options *OnuAbortUpgradeImage) Execute(args []string) error {
1978
1979 conn, err := NewConnection()
1980 if err != nil {
1981 return err
1982 }
1983 defer conn.Close()
1984
1985 client := voltha.NewVolthaServiceClient(conn)
1986
1987 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1988 defer cancel()
1989
1990 var devIDList []*common.ID
1991 for _, i := range options.Args.IDs {
1992
1993 devIDList = append(devIDList, &common.ID{Id: string(i)})
1994 }
1995
1996 downloadImage := voltha.DeviceImageRequest{
1997 DeviceId: devIDList,
1998 Version: options.Args.ImageVersion,
1999 }
2000
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02002001 deviceImageResp, err := client.AbortImageUpgradeToDevice(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05302002 if err != nil {
2003 return err
2004 }
2005
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02002006 outputFormat := GetCommandOptionWithDefault("onu-image-abort", "format", ONU_IMAGE_STATUS_FORMAT)
2007 // Make sure json output prints an empty list, not "null"
2008 if deviceImageResp.DeviceImageStates == nil {
2009 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
2010 }
2011 result := CommandResult{
2012 Format: format.Format(outputFormat),
2013 OutputAs: toOutputType(options.OutputAs),
2014 NameLimit: options.NameLimit,
2015 Data: deviceImageResp.DeviceImageStates,
2016 }
2017 GenerateOutput(&result)
2018
kesavand3e2f9f62021-04-22 11:06:38 +05302019 return nil
2020
2021}
2022
2023func (options *OnuCommitImage) Execute(args []string) error {
2024
2025 conn, err := NewConnection()
2026 if err != nil {
2027 return err
2028 }
2029 defer conn.Close()
2030
2031 client := voltha.NewVolthaServiceClient(conn)
2032
2033 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2034 defer cancel()
2035
2036 var devIDList []*common.ID
2037 for _, i := range options.Args.IDs {
2038
2039 devIDList = append(devIDList, &common.ID{Id: string(i)})
2040 }
2041 downloadImage := voltha.DeviceImageRequest{
2042 DeviceId: devIDList,
2043 Version: options.Args.ImageVersion,
2044 }
2045
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02002046 deviceImageResp, err := client.CommitImage(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05302047 if err != nil {
2048 return err
2049 }
2050
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02002051 outputFormat := GetCommandOptionWithDefault("onu-image-commit", "format", ONU_IMAGE_STATUS_FORMAT)
2052 // Make sure json output prints an empty list, not "null"
2053 if deviceImageResp.DeviceImageStates == nil {
2054 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
2055 }
2056 result := CommandResult{
2057 Format: format.Format(outputFormat),
2058 OutputAs: toOutputType(options.OutputAs),
2059 NameLimit: options.NameLimit,
2060 Data: deviceImageResp.DeviceImageStates,
2061 }
2062 GenerateOutput(&result)
2063
kesavand3e2f9f62021-04-22 11:06:38 +05302064 return nil
2065
2066}
2067
2068func (options *OnuListImages) Execute(args []string) error {
2069
2070 conn, err := NewConnection()
2071 if err != nil {
2072 return err
2073 }
2074 defer conn.Close()
2075
2076 client := voltha.NewVolthaServiceClient(conn)
2077
2078 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2079 defer cancel()
2080
2081 id := common.ID{Id: string(options.Args.Id)}
2082
2083 onuImages, err := client.GetOnuImages(ctx, &id)
2084 if err != nil {
2085 return err
2086 }
2087
2088 outputFormat := CharReplacer.Replace(options.Format)
2089 if outputFormat == "" {
2090 outputFormat = GetCommandOptionWithDefault("onu-image-list", "format", ONU_IMAGE_LIST_FORMAT)
2091 }
2092
2093 if options.Quiet {
2094 outputFormat = "{{.Id}}"
2095 }
2096
2097 //TODO orderby
2098
2099 // Make sure json output prints an empty list, not "null"
2100 if onuImages.Items == nil {
2101 onuImages.Items = make([]*voltha.OnuImage, 0)
2102 }
2103
2104 result := CommandResult{
2105 Format: format.Format(outputFormat),
2106 OutputAs: toOutputType(options.OutputAs),
2107 NameLimit: options.NameLimit,
2108 Data: onuImages.Items,
2109 }
2110
2111 GenerateOutput(&result)
2112 return nil
2113
2114}
2115
2116func (options *OnuImageStatus) Execute(args []string) error {
2117
2118 conn, err := NewConnection()
2119 if err != nil {
2120 return err
2121 }
2122 defer conn.Close()
2123
2124 client := voltha.NewVolthaServiceClient(conn)
2125
2126 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2127 defer cancel()
2128
2129 var devIDList []*common.ID
kesavand3e2f9f62021-04-22 11:06:38 +05302130
Elia Battiston859f3e62022-02-08 15:57:52 +01002131 if options.Args.IDs == nil {
2132 //Use an empty IDs list to retrieve the status of all devices
2133 //with the requested image version
2134 devIDList = []*common.ID{}
2135 } else {
2136 for _, i := range options.Args.IDs {
2137 devIDList = append(devIDList, &common.ID{Id: string(i)})
2138 }
kesavand3e2f9f62021-04-22 11:06:38 +05302139 }
2140
2141 imageStatusReq := voltha.DeviceImageRequest{
2142 DeviceId: devIDList,
2143 Version: options.Args.ImageVersion,
2144 }
2145 imageStatus, err := client.GetImageStatus(ctx, &imageStatusReq)
2146 if err != nil {
2147 return err
2148 }
2149
2150 outputFormat := CharReplacer.Replace(options.Format)
2151 if outputFormat == "" {
2152 outputFormat = GetCommandOptionWithDefault("device-image-list", "format", ONU_IMAGE_STATUS_FORMAT)
2153 }
2154
2155 if options.Quiet {
2156 outputFormat = "{{.Id}}"
2157 }
2158
2159 //TODO orderby
2160
2161 // Make sure json output prints an empty list, not "null"
2162 if imageStatus.DeviceImageStates == nil {
2163 imageStatus.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
2164 }
2165
2166 result := CommandResult{
2167 Format: format.Format(outputFormat),
2168 OutputAs: toOutputType(options.OutputAs),
2169 NameLimit: options.NameLimit,
2170 Data: imageStatus.DeviceImageStates,
2171 }
2172
2173 GenerateOutput(&result)
2174 return nil
2175
2176}
2177
Andrea Campanella791d88b2021-01-08 13:29:00 +01002178func (options *DeviceOnuListImages) Execute(args []string) error {
2179
2180 conn, err := NewConnection()
2181 if err != nil {
2182 return err
2183 }
2184 defer conn.Close()
2185
2186 client := voltha.NewVolthaServiceClient(conn)
2187
David K. Bainbridge9189c632021-03-26 21:52:21 +00002188 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Andrea Campanella791d88b2021-01-08 13:29:00 +01002189 defer cancel()
2190
2191 id := common.ID{Id: string(options.Args.Id)}
2192
2193 imageDownloads, err := client.ListImageDownloads(ctx, &id)
2194 if err != nil {
2195 return err
2196 }
2197
2198 outputFormat := CharReplacer.Replace(options.Format)
2199 if outputFormat == "" {
2200 outputFormat = GetCommandOptionWithDefault("device-image-list", "format", DEFAULT_DEVICE_IMAGE_LIST_GET_FORMAT)
2201 }
2202
2203 if options.Quiet {
2204 outputFormat = "{{.Id}}"
2205 }
2206
2207 //TODO orderby
2208
2209 // Make sure json output prints an empty list, not "null"
2210 if imageDownloads.Items == nil {
2211 imageDownloads.Items = make([]*voltha.ImageDownload, 0)
2212 }
2213
2214 result := CommandResult{
2215 Format: format.Format(outputFormat),
2216 OutputAs: toOutputType(options.OutputAs),
2217 NameLimit: options.NameLimit,
2218 Data: imageDownloads.Items,
2219 }
2220
2221 GenerateOutput(&result)
2222 return nil
2223
2224}
2225
2226func (options *DeviceOnuDownloadImage) Execute(args []string) error {
2227
2228 conn, err := NewConnection()
2229 if err != nil {
2230 return err
2231 }
2232 defer conn.Close()
2233
2234 client := voltha.NewVolthaServiceClient(conn)
2235
David K. Bainbridge9189c632021-03-26 21:52:21 +00002236 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Andrea Campanella791d88b2021-01-08 13:29:00 +01002237 defer cancel()
2238
2239 downloadImage := voltha.ImageDownload{
2240 Id: string(options.Args.Id),
2241 Name: options.Args.Name,
2242 Url: options.Args.Url,
2243 Crc: options.Args.Crc,
2244 LocalDir: options.Args.LocalDir,
2245 }
2246
2247 _, err = client.DownloadImage(ctx, &downloadImage)
2248 if err != nil {
2249 return err
2250 }
2251
2252 return nil
2253
2254}
2255
2256func (options *DeviceOnuActivateImageUpdate) Execute(args []string) error {
2257
2258 conn, err := NewConnection()
2259 if err != nil {
2260 return err
2261 }
2262 defer conn.Close()
2263
2264 client := voltha.NewVolthaServiceClient(conn)
2265
David K. Bainbridge9189c632021-03-26 21:52:21 +00002266 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Andrea Campanella791d88b2021-01-08 13:29:00 +01002267 defer cancel()
2268
2269 downloadImage := voltha.ImageDownload{
2270 Id: string(options.Args.Id),
2271 Name: options.Args.Name,
2272 ImageVersion: options.Args.ImageVersion,
2273 SaveConfig: options.Args.SaveConfig,
2274 LocalDir: options.Args.LocalDir,
2275 }
2276
2277 _, err = client.ActivateImageUpdate(ctx, &downloadImage)
2278 if err != nil {
2279 return err
2280 }
2281
2282 return nil
2283
2284}
2285
Scott Baker9173ed82020-05-19 08:30:12 -07002286type ReturnValueRow struct {
2287 Name string `json:"name"`
2288 Result interface{} `json:"result"`
2289}
2290
kesavand8ec4fc02021-01-27 09:10:22 -05002291func (options *DeviceGetPortStats) Execute(args []string) error {
2292 conn, err := NewConnection()
2293 if err != nil {
2294 return err
2295 }
2296 defer conn.Close()
2297 client := extension.NewExtensionClient(conn)
2298 var portType extension.GetOltPortCounters_PortType
2299
2300 if options.Args.PortType == "pon" {
2301 portType = extension.GetOltPortCounters_Port_PON_OLT
2302 } else if options.Args.PortType == "nni" {
2303
2304 portType = extension.GetOltPortCounters_Port_ETHERNET_NNI
2305 } else {
2306 return fmt.Errorf("expected interface type pon/nni, provided %s", options.Args.PortType)
2307 }
2308
2309 singleGetValReq := extension.SingleGetValueRequest{
2310 TargetId: string(options.Args.Id),
2311 Request: &extension.GetValueRequest{
2312 Request: &extension.GetValueRequest_OltPortInfo{
2313 OltPortInfo: &extension.GetOltPortCounters{
2314 PortNo: options.Args.PortNo,
2315 PortType: portType,
2316 },
2317 },
2318 },
2319 }
2320
David K. Bainbridge9189c632021-03-26 21:52:21 +00002321 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand8ec4fc02021-01-27 09:10:22 -05002322 defer cancel()
2323 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2324 if err != nil {
2325 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2326 return err
2327 }
2328
2329 if rv.Response.Status != extension.GetValueResponse_OK {
2330 return fmt.Errorf("failed to get port stats %v", rv.Response.ErrReason.String())
2331 }
2332
2333 outputFormat := CharReplacer.Replace(options.Format)
2334 if outputFormat == "" {
2335 outputFormat = GetCommandOptionWithDefault("device-get-port-status", "format", DEFAULT_DEVICE_GET_PORT_STATUS_FORMAT)
2336 }
2337
2338 result := CommandResult{
2339 Format: format.Format(outputFormat),
2340 OutputAs: toOutputType(options.OutputAs),
2341 NameLimit: options.NameLimit,
2342 Data: rv.GetResponse().GetPortCoutners(),
2343 }
2344 GenerateOutput(&result)
2345 return nil
2346}
2347
Himani Chawla40acc122021-05-26 18:52:29 +05302348func (options *GetOnuStats) Execute(args []string) error {
2349 conn, err := NewConnection()
2350 if err != nil {
2351 return err
2352 }
2353 defer conn.Close()
2354 client := extension.NewExtensionClient(conn)
2355
2356 singleGetValReq := extension.SingleGetValueRequest{
2357 TargetId: string(options.Args.OltId),
2358 Request: &extension.GetValueRequest{
2359 Request: &extension.GetValueRequest_OnuPonInfo{
2360 OnuPonInfo: &extension.GetOnuCountersRequest{
2361 IntfId: options.Args.IntfId,
2362 OnuId: options.Args.OnuId,
2363 },
2364 },
2365 },
2366 }
2367 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2368 defer cancel()
2369 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2370 if err != nil {
2371 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.OltId, ErrorToString(err))
2372 return err
2373 }
2374
2375 if rv.Response.Status != extension.GetValueResponse_OK {
2376 return fmt.Errorf("failed to get onu stats %v", rv.Response.ErrReason.String())
2377 }
2378 outputFormat := CharReplacer.Replace(options.Format)
2379 data, formatStr := buildOnuStatsOutputFormat(rv.GetResponse().GetOnuPonCounters())
2380 if outputFormat == "" {
2381 outputFormat = GetCommandOptionWithDefault("device-get-onu-status", "format", formatStr)
2382 }
Himani Chawla553a1392021-06-10 23:39:17 +05302383 result := CommandResult{
2384 Format: format.Format(outputFormat),
2385 OutputAs: toOutputType(options.OutputAs),
2386 NameLimit: options.NameLimit,
2387 Data: data,
2388 }
2389 GenerateOutput(&result)
2390 return nil
2391}
Himani Chawla40acc122021-05-26 18:52:29 +05302392
Akash Soni6e879c22024-12-20 17:01:34 +05302393func (options *GetOffloadApp) Execute(args []string) error {
Akash Soni51b6b7a2024-11-20 11:39:38 +05302394 // Establish a connection to the gRPC server
2395 conn, err := NewConnection()
2396 if err != nil {
2397 return err
2398 }
2399 defer conn.Close()
2400
2401 client := extension.NewExtensionClient(conn)
2402
2403 // Build the request
2404 singleGetValReq := &extension.SingleGetValueRequest{
2405 TargetId: string(options.Args.OltId),
2406 Request: &extension.GetValueRequest{
2407 Request: &extension.GetValueRequest_OffloadedAppsStats{
2408 OffloadedAppsStats: &extension.GetOffloadedAppsStatisticsRequest{
2409 StatsFor: options.Args.StatsFor,
2410 },
2411 },
2412 },
2413 }
2414
2415 // Set a context with timeout
2416 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2417 defer cancel()
2418
2419 // Perform the gRPC call
2420 rv, err := client.GetExtValue(ctx, singleGetValReq)
2421 if err != nil {
2422 Error.Printf("Error getting value for device ID %s, err=%s\n", options.Args.OltId, ErrorToString(err))
2423 return err
2424 }
2425
2426 // Check response status
2427 if rv.GetResponse().GetStatus() != extension.GetValueResponse_OK {
2428 return fmt.Errorf("failed to get offloaded app stats: %v", rv.GetResponse().GetErrReason().String())
2429 }
2430
2431 // Process the response data
2432 stats, formatStr := buildOffloadAppStatsOutputFormat(rv.GetResponse().GetOffloadedAppsStats())
balaji.nagarajan1f7c6392026-05-22 16:16:30 +05302433
2434 formatAdditionalStats(stats)
Akash Soni51b6b7a2024-11-20 11:39:38 +05302435 outputFormat := CharReplacer.Replace(options.Format)
2436 if outputFormat == "" {
2437 outputFormat = GetCommandOptionWithDefault("device-get-offload-app-stats", "format", formatStr)
2438 }
2439
2440 // Generate and display the output
2441 result := CommandResult{
2442 Format: format.Format(outputFormat),
2443 OutputAs: toOutputType(options.OutputAs),
2444 NameLimit: options.NameLimit,
2445 Data: stats,
2446 }
2447 GenerateOutput(&result)
2448
2449 return nil
2450}
2451
balaji.nagarajan1f7c6392026-05-22 16:16:30 +05302452func formatAdditionalStats(stats map[string]interface{}) {
2453 if v, ok := stats["additional_stats"]; ok {
2454 if m, ok := v.(map[string]interface{}); ok {
2455
2456 keys := make([]string, 0, len(m))
2457 for k := range m {
2458 keys = append(keys, k)
2459 }
2460
2461 sort.Strings(keys)
2462
2463 var b strings.Builder
2464
2465 for _, k := range keys {
2466 b.WriteString(fmt.Sprintf(
2467 " %-65s : %v\n",
2468 k,
2469 m[k],
2470 ))
2471 }
2472
2473 stats["additional_stats"] = b.String()
2474 }
2475 }
2476}
2477
Akash Soni6e879c22024-12-20 17:01:34 +05302478func (options *SetOffloadApp) Execute(args []string) error {
Akash Soni51b6b7a2024-11-20 11:39:38 +05302479 conn, err := NewConnection()
2480 if err != nil {
Akash Soni6e879c22024-12-20 17:01:34 +05302481 return fmt.Errorf("failed to establish gRPC connection: %w", err)
Akash Soni51b6b7a2024-11-20 11:39:38 +05302482 }
2483 defer conn.Close()
2484
2485 client := extension.NewExtensionClient(conn)
2486
Akash Soni6e879c22024-12-20 17:01:34 +05302487 // Parse JSON input
2488 var config extension.AppOffloadConfig
2489 if err := json.Unmarshal([]byte(options.Args.Config), &config); err != nil {
2490 return fmt.Errorf("failed to parse CONFIG as JSON: %w", err)
2491 }
2492
Akash Soni51b6b7a2024-11-20 11:39:38 +05302493 setValueRequest := &extension.SetValueRequest{
2494 Request: &extension.SetValueRequest_AppOffloadConfig{
Akash Soni6e879c22024-12-20 17:01:34 +05302495 AppOffloadConfig: &config,
Akash Soni51b6b7a2024-11-20 11:39:38 +05302496 },
2497 }
2498
2499 singleSetValReq := &extension.SingleSetValueRequest{
2500 TargetId: string(options.Args.OltId),
2501 Request: setValueRequest,
2502 }
2503
Akash Soni6e879c22024-12-20 17:01:34 +05302504 // Log the request object
2505 logRequestAppOffloadConfig(singleSetValReq)
2506
Akash Soni51b6b7a2024-11-20 11:39:38 +05302507 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2508 defer cancel()
2509
2510 resp, err := client.SetExtValue(ctx, singleSetValReq)
2511 if err != nil {
Akash Soni6e879c22024-12-20 17:01:34 +05302512 return fmt.Errorf("failed to set AppOffloadConfig: %w", err)
Akash Soni51b6b7a2024-11-20 11:39:38 +05302513 }
2514
2515 if resp.Response.Status != extension.SetValueResponse_OK {
Akash Soni6e879c22024-12-20 17:01:34 +05302516 return fmt.Errorf("operation failed with status %v: %s", resp.Response.Status, resp.Response.ErrReason)
Akash Soni51b6b7a2024-11-20 11:39:38 +05302517 }
2518
2519 fmt.Printf("AppOffloadConfig successfully set for OLT ID: %s\n", options.Args.OltId)
2520 return nil
2521}
2522
Akash Soni6e879c22024-12-20 17:01:34 +05302523func logRequestAppOffloadConfig(req *extension.SingleSetValueRequest) {
2524 fmt.Printf("Request details:\n")
2525 fmt.Printf("TargetId: %s\n", req.TargetId)
2526 if config, ok := req.Request.Request.(*extension.SetValueRequest_AppOffloadConfig); ok {
2527 fmt.Printf("AppOffloadConfig:\n")
2528 fmt.Printf(" EnableDHCPv4RA: %t\n", config.AppOffloadConfig.EnableDHCPv4RA)
2529 fmt.Printf(" EnableDHCPv6RA: %t\n", config.AppOffloadConfig.EnableDHCPv6RA)
2530 fmt.Printf(" EnablePPPoEIA: %t\n", config.AppOffloadConfig.EnablePPPoEIA)
2531 fmt.Printf(" AccessNodeID: %s\n", config.AppOffloadConfig.AccessNodeID)
2532 }
2533}
2534
2535func (options *SetOnuOffload) Execute(args []string) error {
2536 // Create the gRPC client connection
Akash Soni51b6b7a2024-11-20 11:39:38 +05302537 conn, err := NewConnection()
2538 if err != nil {
2539 return fmt.Errorf("failed to establish gRPC connection: %v", err)
2540 }
2541 defer conn.Close()
2542
2543 client := extension.NewExtensionClient(conn)
2544
Akash Soni6e879c22024-12-20 17:01:34 +05302545 // Parse PerUniInfo into a slice of PerUniConfig
2546 var perUniConfigs []AppOffloadOnuConfig
2547 if err := json.Unmarshal([]byte(options.Args.PerUniInfo), &perUniConfigs); err != nil {
2548 return fmt.Errorf("failed to parse PerUniInfo as JSON: %v", err)
Akash Soni51b6b7a2024-11-20 11:39:38 +05302549 }
Akash Soni6e879c22024-12-20 17:01:34 +05302550
2551 // Convert to []*AppOffloadOnuConfig_PerUniConfig for gRPC
2552 var grpcPerUniInfo []*extension.AppOffloadOnuConfig_PerUniConfig
2553 for _, config := range perUniConfigs {
2554 grpcPerUniInfo = append(grpcPerUniInfo, &extension.AppOffloadOnuConfig_PerUniConfig{
2555 AgentRemoteID: config.AgentRemoteID,
2556 AgentCircuitID: config.AgentCircuitID,
2557 OnuUniId: config.OnuUniId,
2558 })
2559 }
2560
Akash Soni51b6b7a2024-11-20 11:39:38 +05302561 // Build the AppOffloadOnuConfig request
2562 onuConfig := &extension.AppOffloadOnuConfig{
2563 OnuDeviceId: options.Args.OnuDeviceId,
Akash Soni6e879c22024-12-20 17:01:34 +05302564 PerUniInfo: grpcPerUniInfo,
Akash Soni51b6b7a2024-11-20 11:39:38 +05302565 }
2566
2567 setValueRequest := &extension.SetValueRequest{
2568 Request: &extension.SetValueRequest_AppOffloadOnuConfig{
2569 AppOffloadOnuConfig: onuConfig,
2570 },
2571 }
2572
2573 singleSetValReq := &extension.SingleSetValueRequest{
Akash Soni6e879c22024-12-20 17:01:34 +05302574 TargetId: string(options.Args.OltId),
Akash Soni51b6b7a2024-11-20 11:39:38 +05302575 Request: setValueRequest,
2576 }
2577
Akash Soni6e879c22024-12-20 17:01:34 +05302578 // Log the request object
2579 logRequestAppOffloadOnuConfig(singleSetValReq)
2580
2581 // Make the gRPC call
Akash Soni51b6b7a2024-11-20 11:39:38 +05302582 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2583 defer cancel()
2584
2585 resp, err := client.SetExtValue(ctx, singleSetValReq)
2586 if err != nil {
2587 return fmt.Errorf("failed to set AppOffloadOnuConfig: %v", err)
2588 }
2589
2590 if resp.Response.Status != extension.SetValueResponse_OK {
Akash Soni6e879c22024-12-20 17:01:34 +05302591 return fmt.Errorf("operation failed with status %v: %s", resp.Response.Status, resp.Response.ErrReason)
Akash Soni51b6b7a2024-11-20 11:39:38 +05302592 }
2593
2594 fmt.Printf("AppOffloadOnuConfig successfully set for ONU ID: %s\n", options.Args.OnuDeviceId)
2595 return nil
2596}
2597
Akash Soni6e879c22024-12-20 17:01:34 +05302598// Debugging helper to log the gRPC request details
2599func logRequestAppOffloadOnuConfig(req *extension.SingleSetValueRequest) {
2600 fmt.Printf("Request details:\n")
2601 fmt.Printf("TargetId: %s\n", req.TargetId)
2602 fmt.Printf("OnuDeviceId: %s\n", req.Request.GetAppOffloadOnuConfig().OnuDeviceId)
2603 if config, ok := req.Request.Request.(*extension.SetValueRequest_AppOffloadOnuConfig); ok {
2604 fmt.Printf("AppOffloadOnuConfig:\n")
2605 for i, uniInfo := range config.AppOffloadOnuConfig.PerUniInfo {
2606 fmt.Printf(" UniInfo %d:\n", i+1)
2607 fmt.Printf(" AgentRemoteID: %s\n", uniInfo.AgentRemoteID)
2608 fmt.Printf(" AgentCircuitID: %s\n", uniInfo.AgentCircuitID)
2609 fmt.Printf(" OnuUniId: %d\n", uniInfo.OnuUniId)
2610 }
2611 }
2612}
2613
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +05302614func (options *GetPonPortStats) Execute(args []string) error {
2615 conn, err := NewConnection()
2616 if err != nil {
2617 return err
2618 }
2619 defer conn.Close()
2620 client := extension.NewExtensionClient(conn)
2621
2622 singleGetValReq := extension.SingleGetValueRequest{
2623 TargetId: string(options.Args.Id),
2624 Request: &extension.GetValueRequest{
2625 Request: &extension.GetValueRequest_OltPonStats{
2626 OltPonStats: &extension.GetPonStatsRequest{
2627 PortInfo: &extension.GetPonStatsRequest_PortLabel{
2628 PortLabel: options.Args.PortLabel,
2629 },
2630 },
2631 },
2632 },
2633 }
2634 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2635 defer cancel()
2636 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2637 if err != nil {
2638 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2639 return err
2640 }
2641
2642 if rv.Response.Status != extension.GetValueResponse_OK {
2643 return fmt.Errorf("failed to get pon port stats %v", rv.Response.ErrReason.String())
2644 }
2645 outputFormat := CharReplacer.Replace(options.Format)
2646 if outputFormat == "" {
2647 outputFormat = GetCommandOptionWithDefault("device-get-pon-stats", "format", DEFAULT_PON_PORT_STATS_FORMAT)
2648 }
2649 data := PortStats{
2650 PonPort: rv.GetResponse().GetOltPonStatsResponse().GetPonPort(),
2651 PortStatistics: rv.GetResponse().GetOltPonStatsResponse().GetPortStatistics(),
2652 }
2653 result := CommandResult{
2654 Format: format.Format(outputFormat),
2655 OutputAs: toOutputType(options.OutputAs),
2656 NameLimit: options.NameLimit,
2657 Data: data,
2658 }
2659 GenerateOutput(&result)
2660 return nil
2661}
2662
2663func (options *GetNniPortStats) Execute(args []string) error {
2664 conn, err := NewConnection()
2665 if err != nil {
2666 return err
2667 }
2668 defer conn.Close()
2669 client := extension.NewExtensionClient(conn)
2670
2671 singleGetValReq := extension.SingleGetValueRequest{
2672 TargetId: string(options.Args.Id),
2673 Request: &extension.GetValueRequest{
2674 Request: &extension.GetValueRequest_OltNniStats{
2675 OltNniStats: &extension.GetNNIStatsRequest{
2676 PortInfo: &extension.GetNNIStatsRequest_PortLabel{
2677 PortLabel: options.Args.PortLabel,
2678 },
2679 },
2680 },
2681 },
2682 }
2683 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2684 defer cancel()
2685 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2686 if err != nil {
2687 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2688 return err
2689 }
2690
2691 if rv.Response.Status != extension.GetValueResponse_OK {
2692 return fmt.Errorf("failed to get nni port stats %v", rv.Response.ErrReason.String())
2693 }
2694 outputFormat := CharReplacer.Replace(options.Format)
2695 if outputFormat == "" {
2696 outputFormat = GetCommandOptionWithDefault("device-get-nni-stats", "format", DEFAULT_NNI_PORT_STATS_FORMAT)
2697 }
2698 data := PortStats{
2699 NniPort: rv.GetResponse().GetOltNniStatsResponse().GetNniPort(),
2700 PortStatistics: rv.GetResponse().GetOltNniStatsResponse().GetPortStatistics(),
2701 }
2702 result := CommandResult{
2703 Format: format.Format(outputFormat),
2704 OutputAs: toOutputType(options.OutputAs),
2705 NameLimit: options.NameLimit,
2706 Data: data,
2707 }
2708 GenerateOutput(&result)
2709 return nil
2710}
2711
Himani Chawla553a1392021-06-10 23:39:17 +05302712func (options *GetOnuEthernetFrameExtendedPmCounters) Execute(args []string) error {
2713 conn, err := NewConnection()
2714 if err != nil {
2715 return err
2716 }
2717 defer conn.Close()
2718 client := extension.NewExtensionClient(conn)
Himani Chawla806aa892021-08-30 15:51:46 +05302719 var singleGetValReq extension.SingleGetValueRequest
Himani Chawla553a1392021-06-10 23:39:17 +05302720
Himani Chawla806aa892021-08-30 15:51:46 +05302721 if options.Args.UniIndex != nil {
2722 singleGetValReq = extension.SingleGetValueRequest{
2723 TargetId: string(options.Args.Id),
2724 Request: &extension.GetValueRequest{
2725 Request: &extension.GetValueRequest_OnuInfo{
2726 OnuInfo: &extension.GetOmciEthernetFrameExtendedPmRequest{
2727 OnuDeviceId: string(options.Args.Id),
2728 Reset_: options.Reset,
2729 IsUniIndex: &extension.GetOmciEthernetFrameExtendedPmRequest_UniIndex{
2730 UniIndex: *options.Args.UniIndex,
2731 },
2732 },
Himani Chawla553a1392021-06-10 23:39:17 +05302733 },
2734 },
Himani Chawla806aa892021-08-30 15:51:46 +05302735 }
2736 } else {
2737 singleGetValReq = extension.SingleGetValueRequest{
2738 TargetId: string(options.Args.Id),
2739 Request: &extension.GetValueRequest{
2740 Request: &extension.GetValueRequest_OnuInfo{
2741 OnuInfo: &extension.GetOmciEthernetFrameExtendedPmRequest{
2742 OnuDeviceId: string(options.Args.Id),
2743 Reset_: options.Reset,
2744 },
2745 },
2746 },
2747 }
Himani Chawla553a1392021-06-10 23:39:17 +05302748 }
Himani Chawla806aa892021-08-30 15:51:46 +05302749
Himani Chawla553a1392021-06-10 23:39:17 +05302750 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2751 defer cancel()
2752 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2753 if err != nil {
2754 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2755 return err
2756 }
2757
2758 if rv.Response.Status != extension.GetValueResponse_OK {
2759 return fmt.Errorf("failed to get ethernet frame extended pm counters %v", rv.Response.ErrReason.String())
2760 }
2761 outputFormat := CharReplacer.Replace(options.Format)
2762 data := buildOnuEthernetFrameExtendedPmOutputFormat(rv.GetResponse().GetOnuCounters())
2763 if outputFormat == "" {
2764 outputFormat = GetCommandOptionWithDefault("device-get-onu-status", "format", DEFAULT_ETHERNET_FRAME_EXTENDED_PM_COUNTERS_FORMAT)
2765 }
Himani Chawla40acc122021-05-26 18:52:29 +05302766 result := CommandResult{
2767 Format: format.Format(outputFormat),
2768 OutputAs: toOutputType(options.OutputAs),
2769 NameLimit: options.NameLimit,
2770 Data: data,
2771 }
2772 GenerateOutput(&result)
2773 return nil
2774}
2775
kesavand6d1131f2021-02-05 22:38:15 +05302776func (options *UniStatus) Execute(args []string) error {
2777 conn, err := NewConnection()
2778 if err != nil {
2779 return err
2780 }
2781 defer conn.Close()
2782 client := extension.NewExtensionClient(conn)
2783
2784 singleGetValReq := extension.SingleGetValueRequest{
2785 TargetId: string(options.Args.Id),
2786 Request: &extension.GetValueRequest{
2787 Request: &extension.GetValueRequest_UniInfo{
2788 UniInfo: &extension.GetOnuUniInfoRequest{
2789 UniIndex: options.Args.UniIndex,
2790 },
2791 },
2792 },
2793 }
David K. Bainbridge9189c632021-03-26 21:52:21 +00002794 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand6d1131f2021-02-05 22:38:15 +05302795 defer cancel()
2796 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2797 if err != nil {
2798 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2799 return err
2800 }
2801 if rv.Response.Status != extension.GetValueResponse_OK {
2802 return fmt.Errorf("failed to get uni status %v", rv.Response.ErrReason.String())
2803 }
2804 outputFormat := CharReplacer.Replace(options.Format)
2805 if outputFormat == "" {
2806 outputFormat = GetCommandOptionWithDefault("device-get-uni-status", "format", DEFAULT_DEVICE_GET_UNI_STATUS_FORMAT)
2807 }
2808 result := CommandResult{
2809 Format: format.Format(outputFormat),
2810 OutputAs: toOutputType(options.OutputAs),
2811 NameLimit: options.NameLimit,
2812 Data: rv.GetResponse().GetUniInfo(),
2813 }
2814 GenerateOutput(&result)
2815 return nil
2816}
2817
Girish Gowdra4f5ce7c2021-04-29 18:53:21 -07002818func (options *OnuPonOpticalInfo) Execute(args []string) error {
2819 conn, err := NewConnection()
2820 if err != nil {
2821 return err
2822 }
2823 defer conn.Close()
2824 client := extension.NewExtensionClient(conn)
2825
2826 singleGetValReq := extension.SingleGetValueRequest{
2827 TargetId: string(options.Args.Id),
2828 Request: &extension.GetValueRequest{
2829 Request: &extension.GetValueRequest_OnuOpticalInfo{
2830 OnuOpticalInfo: &extension.GetOnuPonOpticalInfo{},
2831 },
2832 },
2833 }
2834 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2835 defer cancel()
2836 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2837 if err != nil {
2838 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2839 return err
2840 }
2841 if rv.Response.Status != extension.GetValueResponse_OK {
2842 return fmt.Errorf("failed to get onu pon optical info %v", rv.Response.ErrReason.String())
2843 }
2844 outputFormat := CharReplacer.Replace(options.Format)
2845 if outputFormat == "" {
2846 outputFormat = GetCommandOptionWithDefault("device-get-onu-pon-optical-info", "format", DEFAULT_ONU_PON_OPTICAL_INFO_STATUS_FORMAT)
2847 }
2848 result := CommandResult{
2849 Format: format.Format(outputFormat),
2850 OutputAs: toOutputType(options.OutputAs),
2851 NameLimit: options.NameLimit,
2852 Data: rv.GetResponse().GetOnuOpticalInfo(),
2853 }
2854 GenerateOutput(&result)
2855 return nil
2856}
2857
Gamze Abakac857a462021-05-26 13:45:54 +00002858func (options *RxPower) Execute(args []string) error {
2859 conn, err := NewConnection()
2860 if err != nil {
2861 return err
2862 }
2863 defer conn.Close()
2864 client := extension.NewExtensionClient(conn)
2865
2866 singleGetValReq := extension.SingleGetValueRequest{
2867 TargetId: string(options.Args.Id),
2868 Request: &extension.GetValueRequest{
2869 Request: &extension.GetValueRequest_RxPower{
2870 RxPower: &extension.GetRxPowerRequest{
2871 IntfId: options.Args.PortNo,
2872 OnuId: options.Args.OnuNo,
2873 },
2874 },
2875 },
2876 }
2877
2878 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2879 defer cancel()
2880 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2881 if err != nil {
2882 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2883 return err
2884 }
2885 if rv.Response.Status != extension.GetValueResponse_OK {
2886 return fmt.Errorf("failed to get rx power %v", rv.Response.ErrReason.String())
2887 }
2888 outputFormat := CharReplacer.Replace(options.Format)
2889 if outputFormat == "" {
2890 outputFormat = GetCommandOptionWithDefault("device-get-rx-power", "format", DEFAULT_RX_POWER_STATUS_FORMAT)
2891 }
2892 result := CommandResult{
2893 Format: format.Format(outputFormat),
2894 OutputAs: toOutputType(options.OutputAs),
2895 NameLimit: options.NameLimit,
2896 Data: rv.GetResponse().GetRxPower(),
2897 }
2898 GenerateOutput(&result)
2899 return nil
2900}
2901
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002902/*Device get Onu Distance */
2903func (options *DeviceGetExtValue) Execute(args []string) error {
2904 conn, err := NewConnection()
2905 if err != nil {
2906 return err
2907 }
2908 defer conn.Close()
2909
Scott Baker9173ed82020-05-19 08:30:12 -07002910 client := voltha.NewVolthaServiceClient(conn)
2911
khenaidoo080ce882021-10-19 17:35:08 -04002912 valueflag, okay := extension.ValueType_Type_value[string(options.Args.Valueflag)]
Scott Baker9173ed82020-05-19 08:30:12 -07002913 if !okay {
2914 Error.Printf("Unknown valueflag %s\n", options.Args.Valueflag)
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002915 }
2916
khenaidoo080ce882021-10-19 17:35:08 -04002917 val := extension.ValueSpecifier{Id: string(options.Args.Id), Value: extension.ValueType_Type(valueflag)}
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002918
David K. Bainbridge9189c632021-03-26 21:52:21 +00002919 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002920 defer cancel()
2921
Scott Baker9173ed82020-05-19 08:30:12 -07002922 rv, err := client.GetExtValue(ctx, &val)
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002923 if err != nil {
2924 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2925 return err
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002926 }
2927
Scott Baker9173ed82020-05-19 08:30:12 -07002928 var rows []ReturnValueRow
khenaidoo080ce882021-10-19 17:35:08 -04002929 for name, num := range extension.ValueType_Type_value {
Scott Baker9173ed82020-05-19 08:30:12 -07002930 if num == 0 {
2931 // EMPTY is not a real value
2932 continue
2933 }
2934 if (rv.Error & uint32(num)) != 0 {
2935 row := ReturnValueRow{Name: name, Result: "Error"}
2936 rows = append(rows, row)
2937 }
2938 if (rv.Unsupported & uint32(num)) != 0 {
2939 row := ReturnValueRow{Name: name, Result: "Unsupported"}
2940 rows = append(rows, row)
2941 }
2942 if (rv.Set & uint32(num)) != 0 {
2943 switch name {
2944 case "DISTANCE":
2945 row := ReturnValueRow{Name: name, Result: rv.Distance}
2946 rows = append(rows, row)
2947 default:
2948 row := ReturnValueRow{Name: name, Result: "Unimplemented-in-voltctl"}
2949 rows = append(rows, row)
2950 }
2951 }
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002952 }
2953
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002954 outputFormat := CharReplacer.Replace(options.Format)
2955 if outputFormat == "" {
2956 outputFormat = GetCommandOptionWithDefault("device-value-get", "format", DEFAULT_DEVICE_VALUE_GET_FORMAT)
2957 }
2958
2959 result := CommandResult{
2960 Format: format.Format(outputFormat),
2961 OutputAs: toOutputType(options.OutputAs),
2962 NameLimit: options.NameLimit,
Scott Baker9173ed82020-05-19 08:30:12 -07002963 Data: rows,
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002964 }
2965 GenerateOutput(&result)
2966 return nil
2967}
serkantul3d22fc72022-09-14 12:22:56 +03002968
2969/*Device get Onu OMCI TX RX Stats */
2970func (options *OnuOmciTxRxStats) Execute(args []string) error {
2971 conn, err := NewConnection()
2972 if err != nil {
2973 return err
2974 }
2975 defer conn.Close()
2976 client := extension.NewExtensionClient(conn)
2977
2978 singleGetValReq := extension.SingleGetValueRequest{
2979 TargetId: string(options.Args.Id),
2980 Request: &extension.GetValueRequest{
2981 Request: &extension.GetValueRequest_OnuOmciStats{
2982 OnuOmciStats: &extension.GetOnuOmciTxRxStatsRequest{},
2983 },
2984 },
2985 }
2986
2987 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2988 defer cancel()
2989 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2990 if err != nil {
2991 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2992 return err
2993 }
2994
2995 if rv.Response.Status != extension.GetValueResponse_OK {
2996 return fmt.Errorf("failed to get onu omci tx rx stats %v", rv.Response.ErrReason.String())
2997 }
2998 outputFormat := CharReplacer.Replace(options.Format)
2999 if outputFormat == "" {
3000 outputFormat = GetCommandOptionWithDefault("device-get-onu-omci-tx-rx-stats", "format", DEFAULT_ONU_OMCI_TX_RX_STATS_FORMAT)
3001 }
3002 result := CommandResult{
3003 Format: format.Format(outputFormat),
3004 OutputAs: toOutputType(options.OutputAs),
3005 NameLimit: options.NameLimit,
3006 Data: rv.GetResponse().GetOnuOmciStats(),
3007 }
3008 GenerateOutput(&result)
3009 return nil
3010}
praneeth nalmas1dd094c2022-12-22 14:15:13 +05303011
3012/*Device get Onu Active Alarms */
3013func (options *GetOnuOmciActiveAlarms) Execute(args []string) error {
3014 conn, err := NewConnection()
3015 if err != nil {
3016 return err
3017 }
3018 defer conn.Close()
3019 client := extension.NewExtensionClient(conn)
3020
3021 singleGetValReq := extension.SingleGetValueRequest{
3022 TargetId: string(options.Args.Id),
3023 Request: &extension.GetValueRequest{
3024 Request: &extension.GetValueRequest_OnuActiveAlarms{
3025 OnuActiveAlarms: &extension.GetOnuOmciActiveAlarmsRequest{},
3026 },
3027 },
3028 }
3029 Info.Printf("Getting omci_active_alarms for device Id %s\n", options.Args.Id)
3030 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3031 defer cancel()
3032 rv, err := client.GetExtValue(ctx, &singleGetValReq)
3033 if err != nil {
3034 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
3035 return err
3036 }
3037
3038 if rv.Response.Status != extension.GetValueResponse_OK {
3039 return fmt.Errorf("failed to get onu omci active alarms list %v", rv.Response.ErrReason.String())
3040 }
3041 outputFormat := CharReplacer.Replace(options.Format)
3042 if outputFormat == "" {
3043 outputFormat = GetCommandOptionWithDefault("device-get-onu-omci-active-alarms", "format", DEFAULT_DEVICE_ALARMS_FORMAT)
3044 }
3045
3046 orderBy := options.OrderBy
3047 if orderBy == "" {
3048 orderBy = GetCommandOptionWithDefault("device-list", "order", DEFAULT_DEVICE_ALARMS_ORDER)
3049 }
3050
3051 result := CommandResult{
3052 Format: format.Format(outputFormat),
3053 OutputAs: toOutputType(options.OutputAs),
3054 OrderBy: orderBy,
3055 NameLimit: options.NameLimit,
3056 Data: rv.GetResponse().GetOnuActiveAlarms().GetActiveAlarms(),
3057 }
3058 GenerateOutput(&result)
3059 return nil
3060}
praneeth nalmas39c71ad2023-09-27 18:29:04 +05303061
Akash Soni66db9632024-04-15 09:05:15 +05303062/*Device get Onu Active Alarms */
3063func (options *GetOnuDistance) Execute(args []string) error {
3064 conn, err := NewConnection()
3065 if err != nil {
3066 return err
3067 }
3068 defer conn.Close()
3069 client := extension.NewExtensionClient(conn)
3070
3071 singleGetValReq := extension.SingleGetValueRequest{
3072 TargetId: string(options.Args.Id),
3073 Request: &extension.GetValueRequest{
3074 Request: &extension.GetValueRequest_Distance{
3075 Distance: &extension.GetDistanceRequest{
3076 OnuDeviceId: string(options.Args.OnuId),
3077 },
3078 },
3079 },
3080 }
3081 Info.Printf("Getting onu distance for device Id %s\n", options.Args.Id)
3082 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3083 defer cancel()
3084 rv, err := client.GetExtValue(ctx, &singleGetValReq)
3085 if err != nil {
3086 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
3087 return err
3088 }
3089
3090 if rv.Response.Status != extension.GetValueResponse_OK {
3091 return fmt.Errorf("failed to get onu distance stats %v", rv.Response.ErrReason.String())
3092 }
3093 outputFormat := CharReplacer.Replace(options.Format)
3094 if outputFormat == "" {
3095 outputFormat = GetCommandOptionWithDefault("get-onu-distance", "format", DEFAULT_ONU_DISTANCE_FORMAT)
3096 }
3097
3098 result := CommandResult{
3099 Format: format.Format(outputFormat),
3100 OutputAs: toOutputType(options.OutputAs),
3101 NameLimit: options.NameLimit,
3102 Data: rv.GetResponse().GetDistance().GetDistance(),
3103 }
3104 fmt.Println("onu distance : ", rv)
3105 GenerateOutput(&result)
3106 return nil
3107}
3108
praneeth nalmas39c71ad2023-09-27 18:29:04 +05303109func (options *PonRxPower) Execute(args []string) error {
3110 conn, err := NewConnection()
3111 if err != nil {
3112 return err
3113 }
3114 defer conn.Close()
3115 client := extension.NewExtensionClient(conn)
3116
3117 singleGetValReq := extension.SingleGetValueRequest{
3118 TargetId: string(options.Args.Id),
3119 Request: &extension.GetValueRequest{
3120 Request: &extension.GetValueRequest_OltRxPower{
3121 OltRxPower: &extension.GetOltRxPowerRequest{
3122 PortLabel: options.Args.PortLabel,
3123 OnuSn: options.Args.SerialNo,
3124 },
3125 },
3126 },
3127 }
3128
3129 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3130 defer cancel()
3131 rv, err := client.GetExtValue(ctx, &singleGetValReq)
3132 if err != nil {
3133 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
3134 return err
3135 }
3136 if rv.Response.Status != extension.GetValueResponse_OK {
3137 return fmt.Errorf("failed to get rx power %v", rv.Response.ErrReason.String())
3138 }
3139 outputFormat := CharReplacer.Replace(options.Format)
3140 if outputFormat == "" {
3141 outputFormat = GetCommandOptionWithDefault("device-get-pon-rx-power", "format", DEFAULT_PON_RX_POWER_STATUS_FORMAT)
3142 }
3143 result := CommandResult{
3144 Format: format.Format(outputFormat),
3145 OutputAs: toOutputType(options.OutputAs),
3146 NameLimit: options.NameLimit,
3147 Data: rv.GetResponse().GetOltRxPower().GetRxPower(),
3148 }
3149 GenerateOutput(&result)
3150 return nil
3151}
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +05303152
3153func (options *GetOnuGEMStats) Execute(args []string) error {
3154
3155 conn, err := NewConnection()
3156 if err != nil {
3157 return err
3158 }
3159 defer conn.Close()
3160 client := extension.NewExtensionClient(conn)
3161 singleGetValReq := extension.SingleGetValueRequest{
3162 TargetId: string(options.Args.Id),
3163 Request: &extension.GetValueRequest{
3164 Request: &extension.GetValueRequest_OnuAllocGemStats{
3165 OnuAllocGemStats: &extension.GetOnuAllocGemHistoryRequest{},
3166 },
3167 },
3168 }
3169
3170 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3171 defer cancel()
3172
3173 rv, err := client.GetExtValue(ctx, &singleGetValReq)
3174
3175 if err != nil {
3176 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
3177 return err
3178 }
3179
3180 if rv.Response.Status != extension.GetValueResponse_OK {
3181 return fmt.Errorf("failed to get gem port response %v", rv.Response.ErrReason.String())
3182 }
3183 outputFormat := CharReplacer.Replace(options.Format)
3184 if outputFormat == "" {
3185 outputFormat = GetCommandOptionWithDefault("device-get-gem-port", "format", DEFAULT_DEVICE_VALUE_GEM_PORT_FORMAT)
3186 }
3187 onugemhistoryresponse := rv.GetResponse().GetOnuAllocGemStatsResponse()
3188 for _, OnuallocGemHistoryData := range onugemhistoryresponse.OnuAllocGemHistoryData {
3189 data := onugemstats{}
3190 data.AllocId = OnuallocGemHistoryData.OnuAllocIdInfo.AllocId
3191 data.AllocRxBytes = OnuallocGemHistoryData.OnuAllocIdInfo.RxBytes
3192 for _, gemStatsInfo := range OnuallocGemHistoryData.GemPortInfo {
3193 data.GemHistoryStats = append(data.GemHistoryStats, gemHistoryStats{
3194 GemId: gemStatsInfo.GemId,
3195 TransmittedGEMFrames: gemStatsInfo.TransmittedGEMFrames,
3196 ReceivedGEMFrames: gemStatsInfo.ReceivedGEMFrames,
Akash Reddy Kankanalaeba72f62026-01-29 12:49:17 +00003197 ReceivedPayloadBytes: gemStatsInfo.ReceivedPayloadBytes_64,
3198 TransmittedPayloadBytes: gemStatsInfo.TransmittedPayloadBytes_64,
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +05303199 EncryptionKeyErrors: gemStatsInfo.EncryptionKeyErrors,
3200 })
3201 }
3202 result := CommandResult{
3203 Format: format.Format(outputFormat),
3204 OutputAs: toOutputType(options.OutputAs),
3205 NameLimit: options.NameLimit,
3206 Data: &data,
3207 }
3208 GenerateOutput(&result)
3209 }
3210 return nil
3211
3212}
3213
Akash Reddy Kankanala6965c652025-10-15 23:30:16 +05303214func (options *GetOnuFecHistory) Execute(args []string) error {
3215 conn, err := NewConnection()
3216 if err != nil {
3217 return err
3218 }
3219 defer conn.Close()
3220 client := extension.NewExtensionClient(conn)
3221 singleGetValReq := extension.SingleGetValueRequest{
3222 TargetId: string(options.Args.Id),
3223 Request: &extension.GetValueRequest{
3224 Request: &extension.GetValueRequest_FecHistory{
3225 FecHistory: &extension.GetOnuFecHistory{},
3226 },
3227 },
3228 }
3229 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3230 defer cancel()
3231 rv, err := client.GetExtValue(ctx, &singleGetValReq)
3232 if err != nil {
3233 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
3234 return err
3235 }
3236 if rv.Response.Status != extension.GetValueResponse_OK {
3237 return fmt.Errorf("Failed to get onu FEC history stats from ONT %v", rv.Response.ErrReason.String())
3238 }
3239
3240 outputFormat := CharReplacer.Replace(options.Format)
3241 if outputFormat == "" {
3242 outputFormat = GetCommandOptionWithDefault("device-get-onu-fec-History", "format", DEFAULT_ONU_FEC_HISTORY_FORMAT)
3243 }
3244 result := CommandResult{
3245 Format: format.Format(outputFormat),
3246 OutputAs: toOutputType(options.OutputAs),
3247 NameLimit: options.NameLimit,
3248 Data: rv.GetResponse().GetFecHistory(),
3249 }
3250 GenerateOutput(&result)
3251 return nil
3252
3253}
3254
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +05303255func (options *GetOnuAllocGemStatsFromOlt) Execute(args []string) error {
3256 conn, err := NewConnection()
3257 if err != nil {
3258 return err
3259 }
3260 defer conn.Close()
3261 client := extension.NewExtensionClient(conn)
3262
3263 singleGetValReq := extension.SingleGetValueRequest{
3264 TargetId: string(options.Args.Id),
3265 Request: &extension.GetValueRequest{
3266 Request: &extension.GetValueRequest_OnuStatsFromOlt{
3267 OnuStatsFromOlt: &extension.GetOnuStatsFromOltRequest{},
3268 },
3269 },
3270 }
3271 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3272 defer cancel()
3273 rv, err := client.GetExtValue(ctx, &singleGetValReq)
3274 if err != nil {
3275 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
3276 return err
3277 }
3278
3279 if rv.Response.Status != extension.GetValueResponse_OK {
3280 return fmt.Errorf("failed to get onu alloc gem stats from olt %v", rv.Response.ErrReason.String())
3281 }
3282 outputFormat := CharReplacer.Replace(options.Format)
3283 if outputFormat == "" {
3284 outputFormat = GetCommandOptionWithDefault("device-get-onu-status", "format", DEFAULT_ONU_STATS_FROM_OLT_FORMAT)
3285 }
3286
3287 onuAllocGemStatsResponse := rv.GetResponse().GetOnuStatsFromOltResponse()
3288
3289 for _, allocGemStatsInfo := range onuAllocGemStatsResponse.AllocGemStatsInfo {
3290 data := AllocGemStatsFromOlt{}
3291 data.AllocId = allocGemStatsInfo.AllocIdInfo.AllocId
3292 data.AllocRxBytes = allocGemStatsInfo.AllocIdInfo.RxBytes
3293 for _, gemStatsInfo := range allocGemStatsInfo.GemPortInfo {
3294 data.GemPortStats = append(data.GemPortStats, GemPortStatsFromOlt{
3295 GemId: gemStatsInfo.GemId,
3296 RxBytes: gemStatsInfo.RxBytes,
3297 RxPackets: gemStatsInfo.RxPackets,
3298 TxBytes: gemStatsInfo.TxBytes,
3299 TxPackets: gemStatsInfo.TxPackets,
3300 })
3301 }
3302 result := CommandResult{
3303 Format: format.Format(outputFormat),
3304 OutputAs: toOutputType(options.OutputAs),
3305 NameLimit: options.NameLimit,
3306 Data: &data,
3307 }
3308 GenerateOutput(&result)
3309 }
3310
3311 return nil
3312}
mgouda35b90e62025-07-16 14:58:29 +05303313
3314func (options *DisableOnuDevice) Execute(args []string) error {
3315 conn, err := NewConnection()
3316 if err != nil {
3317 return err
3318 }
3319 defer conn.Close()
3320
3321 client := voltha.NewVolthaServiceClient(conn)
3322
3323 var lastErr error
3324 for _, i := range options.Args.Ids {
3325 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3326 defer cancel()
3327
3328 id := voltha.ID{Id: string(i)}
3329
3330 _, err := client.DisableOnuDevice(ctx, &id)
3331 if err != nil {
3332 Error.Printf("Error while disabling the onu serial number'%s': %s\n", i, err)
3333 lastErr = err
3334 continue
3335 }
3336 fmt.Printf("%s\n", i)
3337 }
3338
3339 if lastErr != nil {
3340 return NoReportErr
3341 }
3342 return nil
3343}
3344
3345func (options *EnableOnuDevice) Execute(args []string) error {
3346 conn, err := NewConnection()
3347 if err != nil {
3348 return err
3349 }
3350 defer conn.Close()
3351
3352 client := voltha.NewVolthaServiceClient(conn)
3353
3354 var lastErr error
3355 for _, i := range options.Args.Ids {
3356 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3357 defer cancel()
3358
3359 id := voltha.ID{Id: string(i)}
3360
3361 _, err := client.EnableOnuDevice(ctx, &id)
3362 if err != nil {
3363 Error.Printf("Error while enabling the onu serial number'%s': %s\n", i, err)
3364 lastErr = err
3365 continue
3366 }
3367 fmt.Printf("%s\n", i)
3368 }
3369
3370 if lastErr != nil {
3371 return NoReportErr
3372 }
3373 return nil
3374}
3375
3376func (options *DisableOnuSerialNumber) Execute(args []string) error {
3377 conn, err := NewConnection()
3378 if err != nil {
3379 return err
3380 }
3381 defer conn.Close()
3382
3383 client := voltha.NewVolthaServiceClient(conn)
3384
3385 id := common.ID{Id: string(options.Args.OltDeviceId)}
3386 port := voltha.Port{PortNo: uint32(options.Args.Port)}
3387
3388 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3389 defer cancel()
3390
3391 req := &voltha.OnuSerialNumberOnOLTPon{
3392 OltDeviceId: &id,
3393 SerialNumber: options.Args.SerialNumber,
3394 Port: &port,
3395 }
3396
3397 _, err = client.DisableOnuSerialNumber(ctx, req)
3398 if err != nil {
3399 Error.Printf("Error disabling ONU serial '%s' on OLT '%s': %v\n", options.Args.SerialNumber, options.Args.OltDeviceId, err)
3400 return err
3401 }
3402 fmt.Printf("Disabled ONU serial '%s' on OLT '%s'\n", options.Args.SerialNumber, options.Args.OltDeviceId)
3403 return nil
3404}
3405
3406func (options *EnableOnuSerialNumber) Execute(args []string) error {
3407 conn, err := NewConnection()
3408 if err != nil {
3409 return err
3410 }
3411 defer conn.Close()
3412
3413 client := voltha.NewVolthaServiceClient(conn)
3414
3415 id := common.ID{Id: string(options.Args.OltDeviceId)}
3416 port := voltha.Port{PortNo: uint32(options.Args.Port)}
3417
3418 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3419 defer cancel()
3420
3421 req := &voltha.OnuSerialNumberOnOLTPon{
3422 OltDeviceId: &id,
3423 SerialNumber: options.Args.SerialNumber,
3424 Port: &port,
3425 }
3426
3427 _, err = client.EnableOnuSerialNumber(ctx, req)
3428 if err != nil {
3429 Error.Printf("Error enabling ONU serial '%s' on OLT '%s': %v\n", options.Args.SerialNumber, options.Args.OltDeviceId, err)
3430 return err
3431 }
3432 fmt.Printf("Enabled ONU serial '%s' on OLT '%s'\n", options.Args.SerialNumber, options.Args.OltDeviceId)
3433 return nil
3434}