blob: 340889ba063c786cc9c8dbadd03a38ac69c42d26 [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}}
118RxGem: {{.RxGem}}
119RxGemDropped: {{.RxGemDropped}}
120RxGemIdle: {{.RxGemIdle}}
121RxGemCorrected: {{.RxGemCorrected}}
122RxGemIllegal: {{.RxGemIllegal}}
123RxCrcError: {{.RxCrcErrors}}
124RxFragmentError: {{.RxFragmentError}}
125RxPacketsDropped: {{.RxPacketsDropped}}
126RxCpuOmciPacketsDropped: {{.RxCpuOmciPacketsDropped}}
127RxCpu: {{.RxCpu}}
128RxOmci: {{.RxOmci}}
129RxOmciPacketsCrcError: {{.RxOmciPacketsCrcError}}
130TxPackets: {{.TxPackets}}
131TxGem: {{.TxGem}}
132TxCpu: {{.TxCpu}}
133TxOmci: {{.TxOmci}}
134TxDroppedIllegalLength: {{.TxDroppedIllegalLength}}
135TxDroppedTpidMiss: {{.TxDroppedTpidMiss}}
136TxDroppedVidMiss: {{.TxDroppedVidMiss}}
137TxDroppedTotal: {{.TxDroppedTotal}}`
138 DEFAULT_NNI_PORT_STATS_FORMAT = `Nni Port: {{.NniPort}}
139RxBytes: {{.RxBytes}}
Akash Reddy Kankanalaeba72f62026-01-29 12:49:17 +0000140RxFrames: {{.RxFrames}}
141RxUcastFrames: {{.RxUcastFrames}}
142RxMcastFrames: {{.RxMcastFrames}}
143RxBcastFrames: {{.RxBcastFrames}}
144RxErrorFrames: {{.RxErrorFrames}}
145RxFcsErrorPackets: {{.RxFcsErrorPackets}}
146RxUndersizePackets: {{.RxUndersizePackets}}
147RxOversizePackets: {{.RxOversizePackets}}
148TxBytes: {{.TxBytes}}
149TxFrames: {{.TxFrames}}
150TxUcastFrames: {{.TxUcastFrames}}
151TxMcastFrames: {{.TxMcastFrames}}
152TxBcastFrames: {{.TxBcastFrames}}
153TxErrorFrames: {{.TxErrorFrames}}
154TxUndersizePackets: {{.TxUndersizePackets}}
155TxOversizePackets: {{.TxOversizePackets}}
156
157# Deprecated packet counters to be removed in future releases
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +0530158RxPackets: {{.RxPackets}}
159RxUcastPackets: {{.RxUcastPackets}}
160RxMcastPackets: {{.RxMcastPackets}}
161RxBcastPackets: {{.RxBcastPackets}}
162RxErrorPackets: {{.RxErrorPackets}}
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +0530163TxPackets: {{.TxPackets}}
164TxUcastPackets: {{.TxUcastPackets}}
165TxMcastPackets: {{.TxMcastPackets}}
166TxBcastPackets: {{.TxBcastPackets}}
Akash Reddy Kankanalaeba72f62026-01-29 12:49:17 +0000167TxErrorPackets: {{.TxErrorPackets}}`
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +0530168
serkantul3d22fc72022-09-14 12:22:56 +0300169 DEFAULT_ONU_OMCI_TX_RX_STATS_FORMAT = `BaseTxArFrames: {{.BaseTxArFrames}}
170BaseRxAkFrames: {{.BaseRxAkFrames}}
171BaseTxNoArFrames: {{.BaseTxNoArFrames}}
172BaseRxNoAkFrames: {{.BaseRxNoAkFrames}}
173ExtTxArFrames: {{.ExtTxArFrames}}
174ExtRxAkFrames: {{.ExtRxAkFrames}}
175ExtTxNoArFrames: {{.ExtTxNoArFrames}}
176ExtRxNoAkFrames: {{.ExtRxNoAkFrames}}
177TxOmciCounterRetries: {{.TxOmciCounterRetries}}
178TxOmciCounterTimeouts: {{.TxOmciCounterTimeouts}}`
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +0530179 DEFAULT_ONU_STATS_FROM_OLT_FORMAT = `AllocId: {{.AllocId}}
180AllocRxBytes: {{.AllocRxBytes}}
181{{range .GemPortStats}}
182-GemId: {{.GemId}}
183 RxPackets: {{.RxPackets}}
184 RxBytes: {{.RxBytes}}
185 TxPackets: {{.TxPackets}}
186 TxBytes: {{.TxBytes}}{{end}}`
Akash Reddy Kankanala6965c652025-10-15 23:30:16 +0530187 DEFAULT_ONU_FEC_HISTORY_FORMAT = `CorrectedBytes: {{.CorrectedBytes}}
188CorrectedCodeWords: {{.CorrectedCodeWords}}
189FecSeconds: {{.FecSeconds}}
190TotalCodeWords: {{.TotalCodeWords}}
191UncorrectableCodeWords: {{.UncorrectableCodeWords}}`
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +0530192
193 DEFAULT_ONU_DISTANCE_FORMAT = `Distance`
194 DEFAULT_DEVICE_ALARMS_FORMAT = "table{{ .ClassId }}\t{{.InstanceId}}\t{{.Name}}\t{{.Description}}"
195 DEFAULT_DEVICE_ALARMS_ORDER = "ClassId,InstanceId"
196 DEFAULT_PON_RX_POWER_STATUS_FORMAT = "table{{.OnuSn}}\t{{.Status}}\t{{.FailReason}}\t{{.RxPower}}\t"
197 DEFAULT_DEVICE_VALUE_GEM_PORT_FORMAT = `AllocId: {{.AllocId}}
198 AllocRxBytes: {{.AllocRxBytes}}
199 {{range .GemHistoryStats}}
200-GemId: {{.GemId}}
201 TransmittedGEMFrames: {{.TransmittedGEMFrames}}
202 ReceivedGEMFrames: {{.ReceivedGEMFrames}}
203 ReceivedPayloadBytes: {{.ReceivedPayloadBytes}}
204 TransmittedPayloadBytes:{{.TransmittedPayloadBytes}}
205 EncryptionKeyErrors: {{.EncryptionKeyErrors}}{{end}}`
balaji.nagarajan1f7c6392026-05-22 16:16:30 +0530206 DEFAULT_OFFLOAD_APP_STATS_DHCPv4_FORMAT = `AdditionalStats:
207{{index . "additional_stats"}}
208InBadPacketsFromClient: {{index . "in_bad_packets_from_client"}}
209InBadPacketsFromServer: {{index . "in_bad_packets_from_server"}}
210InPacketsFromClient: {{index . "in_packets_from_client"}}
211InPacketsFromServer: {{index . "in_packets_from_server"}}
212OutPacketsToServer: {{index . "out_packets_to_server"}}
213OutPacketsToClient: {{index . "out_packets_to_client"}}
214Option_82InsertedPacketsToServer: {{index . "option_82_inserted_packets_to_server"}}
215Option_82RemovedPacketsToClient: {{index . "option_82_removed_packets_to_client"}}
216Option_82NotInsertedToServer: {{index . "option_82_not_inserted_to_server"}}`
217 DEFAULT_OFFLOAD_APP_STATS_DHCPv6_FORMAT = `AdditionalStats:
218{{index . "additional_stats"}}
219InBadPacketsFromClient: {{index . "in_bad_packets_from_client"}}
220InBadPacketsFromServer: {{index . "in_bad_packets_from_server"}}
221Option_17InsertedPacketsToServer: {{index . "option_17_inserted_packets_to_server"}}
222Option_17RemovedPacketsToClient: {{index . "option_17_removed_packets_to_client"}}
223Option_18InsertedPacketsToServer: {{index . "option_18_inserted_packets_to_server"}}
224Option_18RemovedPacketsToClient: {{index . "option_18_removed_packets_to_client"}}
225Option_37InsertedPacketsToServer: {{index . "option_37_inserted_packets_to_server"}}
226Option_37RemovedPacketsToClient: {{index . "option_37_removed_packets_to_client"}}
227OutgoingMtuExceededPacketsFromClient: {{index . "outgoing_mtu_exceeded_packets_from_client"}}`
228 DEFAULT_OFFLOAD_APP_STATS_PPPOE_IA_FORMAT = `AdditionalStats:
229{{index . "additional_stats"}}
230InErrorPacketsFromClient: {{index . "in_error_packets_from_client"}}
231InErrorPacketsFromServer: {{index . "in_error_packets_from_server"}}
232InPacketsFromClient: {{index . "in_packets_from_client"}}
233InPacketsFromServer: {{index . "in_packets_from_server"}}
234OutPacketsToServer: {{index . "out_packets_to_server"}}
235OutPacketsToClient: {{index . "out_packets_to_client"}}
236VendorSpecificTagInsertedPacketsToServer: {{index . "vendor_specific_tag_inserted_packets_to_server"}}
237VendorSpecificTagRemovedPacketsToClient: {{index . "vendor_specific_tag_removed_packets_to_client"}}
238OutgoingMtuExceededPacketsFromClient: {{index . "outgoing_mtu_exceeded_packets_from_client"}}`
Zack Williamse940c7a2019-08-21 14:25:39 -0700239)
240
241type DeviceList struct {
242 ListOutputOptions
243}
244
245type DeviceCreate struct {
David Bainbridge1a514392020-06-23 11:12:51 -0700246 DeviceType string `short:"t" required:"true" long:"devicetype" description:"Device type"`
David Bainbridge835dd0e2020-04-01 10:30:09 -0700247 MACAddress string `short:"m" long:"macaddress" default:"" description:"MAC Address"`
Zack Williamse940c7a2019-08-21 14:25:39 -0700248 IPAddress string `short:"i" long:"ipaddress" default:"" description:"IP Address"`
249 HostAndPort string `short:"H" long:"hostandport" default:"" description:"Host and port"`
250}
251
252type DeviceId string
Akash Soni66db9632024-04-15 09:05:15 +0530253type OnuId string
Zack Williamse940c7a2019-08-21 14:25:39 -0700254
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000255type MetricName string
256type GroupName string
kesavand12cd8eb2020-01-20 22:25:22 -0500257type PortNum uint32
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -0800258type ValueFlag string
kesavand12cd8eb2020-01-20 22:25:22 -0500259
Zack Williamse940c7a2019-08-21 14:25:39 -0700260type DeviceDelete struct {
Himani Chawla9933ddc2020-10-12 23:53:27 +0530261 Force bool `long:"force" description:"Delete device forcefully"`
262 Args struct {
Zack Williamse940c7a2019-08-21 14:25:39 -0700263 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
264 } `positional-args:"yes"`
265}
266
267type DeviceEnable struct {
268 Args struct {
269 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
270 } `positional-args:"yes"`
271}
272
273type DeviceDisable struct {
274 Args struct {
275 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
276 } `positional-args:"yes"`
277}
278
279type DeviceReboot struct {
280 Args struct {
281 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
282 } `positional-args:"yes"`
283}
284
285type DeviceFlowList struct {
286 ListOutputOptions
Maninder045921e2020-09-29 16:46:02 +0530287 FlowIdOptions
Zack Williamse940c7a2019-08-21 14:25:39 -0700288 Args struct {
289 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
290 } `positional-args:"yes"`
291}
292
Himani Chawla3c161c62021-05-13 16:36:51 +0530293type DeviceFlowGroupList struct {
294 ListOutputOptions
295 GroupListOptions
296 Args struct {
297 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
298 } `positional-args:"yes"`
299}
Zack Williamse940c7a2019-08-21 14:25:39 -0700300type DevicePortList struct {
301 ListOutputOptions
302 Args struct {
303 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
304 } `positional-args:"yes"`
305}
306
307type DeviceInspect struct {
308 OutputOptionsJson
309 Args struct {
310 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
311 } `positional-args:"yes"`
312}
313
kesavand12cd8eb2020-01-20 22:25:22 -0500314type DevicePortEnable struct {
315 Args struct {
316 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
317 PortId PortNum `positional-arg-name:"PORT_NUMBER" required:"yes"`
318 } `positional-args:"yes"`
319}
320
321type DevicePortDisable struct {
322 Args struct {
323 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
324 PortId PortNum `positional-arg-name:"PORT_NUMBER" required:"yes"`
325 } `positional-args:"yes"`
326}
327
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000328type DevicePmConfigsGet struct {
329 ListOutputOptions
330 Args struct {
331 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
332 } `positional-args:"yes"`
333}
334
335type DevicePmConfigMetricList struct {
336 ListOutputOptions
337 Args struct {
338 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
339 } `positional-args:"yes"`
340}
341
342type DevicePmConfigGroupList struct {
343 ListOutputOptions
344 Args struct {
345 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
346 } `positional-args:"yes"`
347}
348
349type DevicePmConfigGroupMetricList struct {
350 ListOutputOptions
351 Args struct {
352 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
353 Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"`
354 } `positional-args:"yes"`
355}
356
357type DevicePmConfigFrequencySet struct {
358 OutputOptions
359 Args struct {
Girish Gowdra610acb42021-01-27 13:33:57 -0800360 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
361 Interval time.Duration `positional-arg-name:"INTERVAL" required:"yes"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000362 } `positional-args:"yes"`
363}
364
365type DevicePmConfigMetricEnable struct {
366 Args struct {
367 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
368 Metrics []MetricName `positional-arg-name:"METRIC_NAME" required:"yes"`
369 } `positional-args:"yes"`
370}
371
372type DevicePmConfigMetricDisable struct {
373 Args struct {
374 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
375 Metrics []MetricName `positional-arg-name:"METRIC_NAME" required:"yes"`
376 } `positional-args:"yes"`
377}
378
379type DevicePmConfigGroupEnable struct {
380 Args struct {
Girish Gowdra610acb42021-01-27 13:33:57 -0800381 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
382 Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000383 } `positional-args:"yes"`
384}
385
386type DevicePmConfigGroupDisable struct {
387 Args struct {
Girish Gowdra610acb42021-01-27 13:33:57 -0800388 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
389 Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"`
390 } `positional-args:"yes"`
391}
392
393type DevicePmConfigGroupFrequencySet struct {
394 OutputOptions
395 Args struct {
396 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
397 Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"`
398 Interval time.Duration `positional-arg-name:"INTERVAL" required:"yes"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000399 } `positional-args:"yes"`
400}
401
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -0800402type DeviceGetExtValue struct {
403 ListOutputOptions
404 Args struct {
405 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
406 Valueflag ValueFlag `positional-arg-name:"VALUE_FLAG" required:"yes"`
407 } `positional-args:"yes"`
408}
Rohan Agrawald7df3772020-06-29 11:23:36 +0000409
410type DevicePmConfigSetMaxSkew struct {
411 Args struct {
412 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
413 MaxSkew uint32 `positional-arg-name:"MAX_SKEW" required:"yes"`
414 } `positional-args:"yes"`
415}
416
Andrea Campanella791d88b2021-01-08 13:29:00 +0100417type DeviceOnuListImages struct {
418 ListOutputOptions
419 Args struct {
420 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
421 } `positional-args:"yes"`
422}
423
424type DeviceOnuDownloadImage struct {
425 Args struct {
426 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
427 Name string `positional-arg-name:"IMAGE_NAME" required:"yes"`
428 Url string `positional-arg-name:"IMAGE_URL" required:"yes"`
429 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
430 Crc uint32 `positional-arg-name:"IMAGE_CRC" required:"yes"`
431 LocalDir string `positional-arg-name:"IMAGE_LOCAL_DIRECTORY"`
432 } `positional-args:"yes"`
433}
434
435type DeviceOnuActivateImageUpdate struct {
436 Args struct {
437 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
438 Name string `positional-arg-name:"IMAGE_NAME" required:"yes"`
439 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
440 SaveConfig bool `positional-arg-name:"SAVE_EXISTING_CONFIG"`
441 LocalDir string `positional-arg-name:"IMAGE_LOCAL_DIRECTORY"`
Andrea Campanella7b2ecf42021-02-25 12:27:15 +0100442 } `positional-args:"yes"`
kesavand8ec4fc02021-01-27 09:10:22 -0500443}
kesavand3e2f9f62021-04-22 11:06:38 +0530444
445type OnuDownloadImage struct {
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +0200446 ListOutputOptions
kesavand3e2f9f62021-04-22 11:06:38 +0530447 Args struct {
448 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
449 Url string `positional-arg-name:"IMAGE_URL" required:"yes"`
ssiddiqui7bc89e92021-05-20 20:58:02 +0530450 Vendor string `positional-arg-name:"IMAGE_VENDOR"`
kesavand3e2f9f62021-04-22 11:06:38 +0530451 ActivateOnSuccess bool `positional-arg-name:"IMAGE_ACTIVATE_ON_SUCCESS"`
452 CommitOnSuccess bool `positional-arg-name:"IMAGE_COMMIT_ON_SUCCESS"`
453 Crc uint32 `positional-arg-name:"IMAGE_CRC"`
454 IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
455 } `positional-args:"yes"`
456}
457
458type OnuActivateImage struct {
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +0200459 ListOutputOptions
kesavand3e2f9f62021-04-22 11:06:38 +0530460 Args struct {
461 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
462 CommitOnSuccess bool `positional-arg-name:"IMAGE_COMMIT_ON_SUCCESS"`
463 IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
464 } `positional-args:"yes"`
465}
466
467type OnuAbortUpgradeImage struct {
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +0200468 ListOutputOptions
kesavand3e2f9f62021-04-22 11:06:38 +0530469 Args struct {
470 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
471 IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
472 } `positional-args:"yes"`
473}
474
475type OnuCommitImage struct {
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +0200476 ListOutputOptions
kesavand3e2f9f62021-04-22 11:06:38 +0530477 Args struct {
478 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
479 IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
480 } `positional-args:"yes"`
481}
482
483type OnuImageStatus struct {
484 ListOutputOptions
485 Args struct {
486 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
Elia Battiston859f3e62022-02-08 15:57:52 +0100487 IDs []DeviceId `positional-arg-name:"DEVICE_ID"`
kesavand3e2f9f62021-04-22 11:06:38 +0530488 } `positional-args:"yes"`
489}
490
491type OnuListImages struct {
492 ListOutputOptions
493 Args struct {
494 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
495 } `positional-args:"yes"`
496}
497
kesavand8ec4fc02021-01-27 09:10:22 -0500498type DeviceGetPortStats struct {
499 ListOutputOptions
500 Args struct {
501 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
502 PortNo uint32 `positional-arg-name:"PORT_NO" required:"yes"`
503 PortType string `positional-arg-name:"PORT_TYPE" required:"yes"`
Andrea Campanella791d88b2021-01-08 13:29:00 +0100504 } `positional-args:"yes"`
505}
kesavand6d1131f2021-02-05 22:38:15 +0530506type UniStatus struct {
507 ListOutputOptions
508 Args struct {
509 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
510 UniIndex uint32 `positional-arg-name:"UNI_INDEX" required:"yes"`
511 } `positional-args:"yes"`
512}
Girish Gowdra4f5ce7c2021-04-29 18:53:21 -0700513type OnuPonOpticalInfo struct {
514 ListOutputOptions
515 Args struct {
516 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
517 } `positional-args:"yes"`
518}
Himani Chawla40acc122021-05-26 18:52:29 +0530519
520type GetOnuStats struct {
521 ListOutputOptions
522 Args struct {
523 OltId DeviceId `positional-arg-name:"OLT_DEVICE_ID" required:"yes"`
524 IntfId uint32 `positional-arg-name:"PON_INTF_ID" required:"yes"`
525 OnuId uint32 `positional-arg-name:"ONU_ID" required:"yes"`
526 } `positional-args:"yes"`
527}
528
Akash Soni6e879c22024-12-20 17:01:34 +0530529type GetOffloadApp struct {
Akash Soni51b6b7a2024-11-20 11:39:38 +0530530 ListOutputOptions
531 Args struct {
532 OltId DeviceId `positional-arg-name:"OLT_DEVICE_ID" required:"yes"`
533 StatsFor extension.GetOffloadedAppsStatisticsRequest_OffloadedApp `positional-arg-name:"OFFLOADED_APP" required:"yes"`
534 } `positional-args:"yes"`
535}
536
Akash Soni6e879c22024-12-20 17:01:34 +0530537type SetOffloadApp struct {
538 ListOutputOptions
Akash Soni51b6b7a2024-11-20 11:39:38 +0530539 Args struct {
Akash Soni6e879c22024-12-20 17:01:34 +0530540 OltId DeviceId `positional-arg-name:"OLT_DEVICE_ID" required:"yes"`
541 Config string `positional-arg-name:"CONFIG" required:"yes"` // Accept JSON or CSV input
Akash Soni51b6b7a2024-11-20 11:39:38 +0530542 } `positional-args:"yes"`
543}
544
Akash Soni6e879c22024-12-20 17:01:34 +0530545type AppOffloadOnuConfig struct {
546 AgentRemoteID string
547 AgentCircuitID string
548 OnuUniId uint32
549}
550
551type SetOnuOffload struct {
552 ListOutputOptions
Akash Soni51b6b7a2024-11-20 11:39:38 +0530553 Args struct {
Akash Soni6e879c22024-12-20 17:01:34 +0530554 OltId DeviceId `positional-arg-name:"OLT_DEVICE_ID" required:"yes"`
555 OnuDeviceId string `positional-arg-name:"ONU_DEVICE_ID" required:"yes"`
556 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 +0530557 } `positional-args:"yes"`
558}
559
Himani Chawla553a1392021-06-10 23:39:17 +0530560type GetOnuEthernetFrameExtendedPmCounters struct {
561 ListOutputOptions
Himani Chawla806aa892021-08-30 15:51:46 +0530562 Reset bool `long:"reset" description:"Reset the counters"`
563 Args struct {
564 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
565 UniIndex *uint32 `positional-arg-name:"UNI_INDEX"`
Himani Chawla553a1392021-06-10 23:39:17 +0530566 } `positional-args:"yes"`
567}
568
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +0530569type GetPonPortStats struct {
570 ListOutputOptions
571 Reset bool `long:"reset" description:"Reset the counters"`
572 Args struct {
573 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
574 PortLabel string `positional-arg-name:"PORT_LABEL" required:"yes"`
575 } `positional-args:"yes"`
576}
577
578type GetNniPortStats struct {
579 ListOutputOptions
580 Reset bool `long:"reset" description:"Reset the counters"`
581 Args struct {
582 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
583 PortLabel string `positional-arg-name:"PORT_LABEL" required:"yes"`
584 } `positional-args:"yes"`
585}
586
587type GetOnuAllocGemStatsFromOlt struct {
588 ListOutputOptions
589 Args struct {
590 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
591 } `positional-args:"yes"`
592}
Gamze Abakac857a462021-05-26 13:45:54 +0000593type RxPower struct {
594 ListOutputOptions
595 Args struct {
596 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
597 PortNo uint32 `positional-arg-name:"PORT_NO" required:"yes"`
598 OnuNo uint32 `positional-arg-name:"ONU_NO" required:"yes"`
599 } `positional-args:"yes"`
600}
601
praneeth nalmas39c71ad2023-09-27 18:29:04 +0530602type PonRxPower struct {
603 ListOutputOptions
604 Args struct {
605 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
606 PortLabel string `positional-arg-name:"PORT_LABEL" required:"yes"`
607 SerialNo string `positional-arg-name:"ONU_SERIAL_NUMBER"`
608 } `positional-args:"yes"`
609}
610
serkantul3d22fc72022-09-14 12:22:56 +0300611type OnuOmciTxRxStats struct {
612 ListOutputOptions
613 Args struct {
614 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
615 } `positional-args:"yes"`
616}
617
praneeth nalmas1dd094c2022-12-22 14:15:13 +0530618type GetOnuOmciActiveAlarms struct {
619 ListOutputOptions
620 Args struct {
621 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
622 } `positional-args:"yes"`
623}
624
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +0530625type GetOnuGEMStats struct {
626 ListOutputOptions
627 Args struct {
628 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
629 } `positional-args:"yes"`
630}
631
Akash Reddy Kankanala6965c652025-10-15 23:30:16 +0530632type GetOnuFecHistory struct {
633 ListOutputOptions
634 Args struct {
635 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
636 } `positional-args:"yes"`
637}
Akash Soni66db9632024-04-15 09:05:15 +0530638type GetOnuDistance struct {
639 ListOutputOptions
640 Args struct {
641 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
642 OnuId OnuId `positional-arg-name:"ONU_ID" required:"yes"`
643 } `positional-args:"yes"` //onu device id
644}
645
mgouda35b90e62025-07-16 14:58:29 +0530646type DisableOnuDevice struct {
647 Args struct {
648 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
649 } `positional-args:"yes"`
650}
651
652type EnableOnuDevice struct {
653 Args struct {
654 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
655 } `positional-args:"yes"`
656}
657
658type DisableOnuSerialNumber struct {
659 Args struct {
660 SerialNumber string `positional-arg-name:"ONU_SERIAL_NUMBER" required:"yes"`
661 Port PortNum `positional-arg-name:"PORT_NO" required:"yes"`
662 OltDeviceId DeviceId `positional-arg-name:"OLT_DEVICE_ID" required:"yes"`
663 } `positional-args:"yes"`
664}
665
666type EnableOnuSerialNumber struct {
667 Args struct {
668 SerialNumber string `positional-arg-name:"ONU_SERIAL_NUMBER" required:"yes"`
669 Port PortNum `positional-arg-name:"PORT_NO" required:"yes"`
670 OltDeviceId DeviceId `positional-arg-name:"OLT_DEVICE_ID" required:"yes"`
671 } `positional-args:"yes"`
672}
673
Zack Williamse940c7a2019-08-21 14:25:39 -0700674type DeviceOpts struct {
mgouda35b90e62025-07-16 14:58:29 +0530675 List DeviceList `command:"list"`
676 Create DeviceCreate `command:"create"`
677 Delete DeviceDelete `command:"delete"`
678 Enable DeviceEnable `command:"enable"`
679 Disable DeviceDisable `command:"disable"`
680 DisableOnuDevice DisableOnuDevice `command:"disable_onu"`
681 EnableOnuDevice EnableOnuDevice `command:"enable_onu"`
682 DisableOnuSerialNumber DisableOnuSerialNumber `command:"disable_onu_serial"`
683 EnableOnuSerialNumber EnableOnuSerialNumber `command:"enable_onu_serial"`
684 Flows DeviceFlowList `command:"flows"`
685 Groups DeviceFlowGroupList `command:"groups"`
686 Port struct {
kesavand12cd8eb2020-01-20 22:25:22 -0500687 List DevicePortList `command:"list"`
688 Enable DevicePortEnable `command:"enable"`
689 Disable DevicePortDisable `command:"disable"`
690 } `command:"port"`
691 Inspect DeviceInspect `command:"inspect"`
692 Reboot DeviceReboot `command:"reboot"`
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -0800693 Value struct {
694 Get DeviceGetExtValue `command:"get"`
695 } `command:"value"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000696 PmConfig struct {
Rohan Agrawald7df3772020-06-29 11:23:36 +0000697 Get DevicePmConfigsGet `command:"get"`
698 MaxSkew struct {
699 Set DevicePmConfigSetMaxSkew `command:"set"`
700 } `command:"maxskew"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000701 Frequency struct {
702 Set DevicePmConfigFrequencySet `command:"set"`
703 } `command:"frequency"`
704 Metric struct {
705 List DevicePmConfigMetricList `command:"list"`
706 Enable DevicePmConfigMetricEnable `command:"enable"`
707 Disable DevicePmConfigMetricDisable `command:"disable"`
708 } `command:"metric"`
709 Group struct {
Girish Gowdra610acb42021-01-27 13:33:57 -0800710 List DevicePmConfigGroupList `command:"list"`
711 Enable DevicePmConfigGroupEnable `command:"enable"`
712 Disable DevicePmConfigGroupDisable `command:"disable"`
713 Set DevicePmConfigGroupFrequencySet `command:"set"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000714 } `command:"group"`
715 GroupMetric struct {
716 List DevicePmConfigGroupMetricList `command:"list"`
717 } `command:"groupmetric"`
718 } `command:"pmconfig"`
Andrea Campanella791d88b2021-01-08 13:29:00 +0100719 Image struct {
720 Get DeviceOnuListImages `command:"list"`
721 Download DeviceOnuDownloadImage `command:"download"`
722 Activate DeviceOnuActivateImageUpdate `command:"activate"`
723 } `command:"image"`
kesavand3e2f9f62021-04-22 11:06:38 +0530724 DownloadImage struct {
725 Download OnuDownloadImage `command:"download"`
726 Activate OnuActivateImage `command:"activate"`
727 Commit OnuCommitImage `command:"commit"`
728 AbortUpgrade OnuAbortUpgradeImage `command:"abort"`
729 Status OnuImageStatus `command:"status"`
730 List OnuListImages `command:"list" `
731 } `command:"onuimage"`
kesavand8ec4fc02021-01-27 09:10:22 -0500732 GetExtVal struct {
Himani Chawla553a1392021-06-10 23:39:17 +0530733 Stats DeviceGetPortStats `command:"portstats"`
734 UniStatus UniStatus `command:"unistatus"`
735 OpticalInfo OnuPonOpticalInfo `command:"onu_pon_optical_info"`
736 OnuStats GetOnuStats `command:"onu_stats"`
737 EthernetFrameExtendedPm GetOnuEthernetFrameExtendedPmCounters `command:"ethernet_frame_extended_pm"`
738 RxPower RxPower `command:"rxpower"`
serkantul3d22fc72022-09-14 12:22:56 +0300739 OnuOmciStats OnuOmciTxRxStats `command:"onu_omci_stats"`
praneeth nalmas1dd094c2022-12-22 14:15:13 +0530740 OnuOmciActiveAlarms GetOnuOmciActiveAlarms `command:"onu_omci_active_alarms"`
praneeth nalmas39c71ad2023-09-27 18:29:04 +0530741 PonRxPower PonRxPower `command:"pon_rx_power"`
Akash Soni66db9632024-04-15 09:05:15 +0530742 OnuDistance GetOnuDistance `command:"onu_distance"`
Akash Soni6e879c22024-12-20 17:01:34 +0530743 OffloadAppStats GetOffloadApp `command:"offload_app_stats"`
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +0530744 PonStats GetPonPortStats `command:"itu_pon_stats"`
745 NniStats GetNniPortStats `command:"nni_statistics"`
746 OnuGEMStats GetOnuGEMStats `command:"onu_gem_stats"`
747 OnuAllocGemStats GetOnuAllocGemStatsFromOlt `command:"onu_alloc_gem_from_olt"`
Akash Reddy Kankanala6965c652025-10-15 23:30:16 +0530748 OnuFecHistory GetOnuFecHistory `command:"onu_fec_history"`
kesavand8ec4fc02021-01-27 09:10:22 -0500749 } `command:"getextval"`
Akash Soni51b6b7a2024-11-20 11:39:38 +0530750 SetExtVal struct {
Akash Soni6e879c22024-12-20 17:01:34 +0530751 OffloadAppStatsSet SetOffloadApp `command:"set_offload_app"`
752 OnuOffloadStatsSet SetOnuOffload `command:"set_onu_offload"`
Akash Soni51b6b7a2024-11-20 11:39:38 +0530753 } `command:"setextval"`
Zack Williamse940c7a2019-08-21 14:25:39 -0700754}
755
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +0530756type AllocGemStatsFromOlt struct {
757 AllocId uint32
758 AllocRxBytes uint64
759 GemPortStats []GemPortStatsFromOlt
760}
761type GemPortStatsFromOlt struct {
762 GemId uint32
763 RxPackets uint64
764 RxBytes uint64
765 TxPackets uint64
766 TxBytes uint64
767}
768type onugemstats struct {
769 AllocId uint32
770 AllocRxBytes uint32
771 GemHistoryStats []gemHistoryStats
772}
773type gemHistoryStats struct {
774 GemId uint32
775 TransmittedGEMFrames uint32
776 ReceivedGEMFrames uint32
Akash Reddy Kankanalaeba72f62026-01-29 12:49:17 +0000777 ReceivedPayloadBytes uint64
778 TransmittedPayloadBytes uint64
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +0530779 EncryptionKeyErrors uint32
780}
781
782type PortStats struct {
783 PonPort uint32 // use this for PON
784 NniPort uint32 // use this for NNI
785 *common.PortStatistics
786}
787
Zack Williamse940c7a2019-08-21 14:25:39 -0700788var deviceOpts = DeviceOpts{}
789
790func RegisterDeviceCommands(parser *flags.Parser) {
David Bainbridge12f036f2019-10-15 22:09:04 +0000791 if _, err := parser.AddCommand("device", "device commands", "Commands to query and manipulate VOLTHA devices", &deviceOpts); err != nil {
David Bainbridgea6722342019-10-24 23:55:53 +0000792 Error.Fatalf("Unexpected error while attempting to register device commands : %s", err)
David Bainbridge12f036f2019-10-15 22:09:04 +0000793 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700794}
795
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000796func (i *MetricName) Complete(match string) []flags.Completion {
797 conn, err := NewConnection()
798 if err != nil {
799 return nil
800 }
801 defer conn.Close()
802
803 client := voltha.NewVolthaServiceClient(conn)
804
805 var deviceId string
806found:
807 for i := len(os.Args) - 1; i >= 0; i -= 1 {
808 switch os.Args[i] {
809 case "enable":
810 fallthrough
811 case "disable":
812 if len(os.Args) > i+1 {
813 deviceId = os.Args[i+1]
814 } else {
815 return nil
816 }
817 break found
818 default:
819 }
820 }
821
822 if len(deviceId) == 0 {
823 return nil
824 }
825
David K. Bainbridge9189c632021-03-26 21:52:21 +0000826 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000827 defer cancel()
828
829 id := voltha.ID{Id: string(deviceId)}
830
831 pmconfigs, err := client.ListDevicePmConfigs(ctx, &id)
832
833 if err != nil {
834 return nil
835 }
836
837 list := make([]flags.Completion, 0)
838 for _, metrics := range pmconfigs.Metrics {
839 if strings.HasPrefix(metrics.Name, match) {
840 list = append(list, flags.Completion{Item: metrics.Name})
841 }
842 }
843
844 return list
845}
846
847func (i *GroupName) Complete(match string) []flags.Completion {
848 conn, err := NewConnection()
849 if err != nil {
850 return nil
851 }
852 defer conn.Close()
853
854 client := voltha.NewVolthaServiceClient(conn)
855
856 var deviceId string
857found:
858 for i := len(os.Args) - 1; i >= 0; i -= 1 {
859 switch os.Args[i] {
860 case "list":
861 fallthrough
862 case "enable":
863 fallthrough
864 case "disable":
865 if len(os.Args) > i+1 {
866 deviceId = os.Args[i+1]
867 } else {
868 return nil
869 }
870 break found
871 default:
872 }
873 }
874
875 if len(deviceId) == 0 {
876 return nil
877 }
878
David K. Bainbridge9189c632021-03-26 21:52:21 +0000879 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000880 defer cancel()
881
882 id := voltha.ID{Id: string(deviceId)}
883
884 pmconfigs, err := client.ListDevicePmConfigs(ctx, &id)
885
886 if err != nil {
887 return nil
888 }
889
890 list := make([]flags.Completion, 0)
891 for _, group := range pmconfigs.Groups {
892 if strings.HasPrefix(group.GroupName, match) {
893 list = append(list, flags.Completion{Item: group.GroupName})
894 }
895 }
896 return list
897}
898
kesavand12cd8eb2020-01-20 22:25:22 -0500899func (i *PortNum) Complete(match string) []flags.Completion {
900 conn, err := NewConnection()
901 if err != nil {
902 return nil
903 }
904 defer conn.Close()
905
Scott Baker9173ed82020-05-19 08:30:12 -0700906 client := voltha.NewVolthaServiceClient(conn)
kesavand12cd8eb2020-01-20 22:25:22 -0500907
908 /*
909 * The command line args when completing for PortNum will be a DeviceId
910 * followed by one or more PortNums. So walk the argument list from the
911 * end and find the first argument that is enable/disable as those are
912 * the subcommands that come before the positional arguments. It would
913 * be nice if this package gave us the list of optional arguments
914 * already parsed.
915 */
916 var deviceId string
917found:
918 for i := len(os.Args) - 1; i >= 0; i -= 1 {
919 switch os.Args[i] {
920 case "enable":
921 fallthrough
922 case "disable":
923 if len(os.Args) > i+1 {
924 deviceId = os.Args[i+1]
925 } else {
926 return nil
927 }
928 break found
929 default:
930 }
931 }
932
933 if len(deviceId) == 0 {
934 return nil
935 }
936
David K. Bainbridge9189c632021-03-26 21:52:21 +0000937 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand12cd8eb2020-01-20 22:25:22 -0500938 defer cancel()
kesavand12cd8eb2020-01-20 22:25:22 -0500939
Scott Baker9173ed82020-05-19 08:30:12 -0700940 id := voltha.ID{Id: string(deviceId)}
kesavand12cd8eb2020-01-20 22:25:22 -0500941
Scott Baker9173ed82020-05-19 08:30:12 -0700942 ports, err := client.ListDevicePorts(ctx, &id)
kesavand12cd8eb2020-01-20 22:25:22 -0500943 if err != nil {
944 return nil
945 }
946
947 list := make([]flags.Completion, 0)
Scott Baker9173ed82020-05-19 08:30:12 -0700948 for _, item := range ports.Items {
949 pn := strconv.FormatUint(uint64(item.PortNo), 10)
kesavand12cd8eb2020-01-20 22:25:22 -0500950 if strings.HasPrefix(pn, match) {
951 list = append(list, flags.Completion{Item: pn})
952 }
953 }
954
955 return list
956}
957
Zack Williamse940c7a2019-08-21 14:25:39 -0700958func (i *DeviceId) Complete(match string) []flags.Completion {
959 conn, err := NewConnection()
960 if err != nil {
961 return nil
962 }
963 defer conn.Close()
964
Scott Baker9173ed82020-05-19 08:30:12 -0700965 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700966
David K. Bainbridge9189c632021-03-26 21:52:21 +0000967 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700968 defer cancel()
969
Scott Baker9173ed82020-05-19 08:30:12 -0700970 devices, err := client.ListDevices(ctx, &empty.Empty{})
Zack Williamse940c7a2019-08-21 14:25:39 -0700971 if err != nil {
972 return nil
973 }
974
975 list := make([]flags.Completion, 0)
Scott Baker9173ed82020-05-19 08:30:12 -0700976 for _, item := range devices.Items {
977 if strings.HasPrefix(item.Id, match) {
978 list = append(list, flags.Completion{Item: item.Id})
Zack Williamse940c7a2019-08-21 14:25:39 -0700979 }
980 }
981
982 return list
983}
984
985func (options *DeviceList) Execute(args []string) error {
986
987 conn, err := NewConnection()
988 if err != nil {
989 return err
990 }
991 defer conn.Close()
992
Scott Baker9173ed82020-05-19 08:30:12 -0700993 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700994
David K. Bainbridge9189c632021-03-26 21:52:21 +0000995 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700996 defer cancel()
997
Scott Baker9173ed82020-05-19 08:30:12 -0700998 devices, err := client.ListDevices(ctx, &empty.Empty{})
Zack Williamse940c7a2019-08-21 14:25:39 -0700999 if err != nil {
1000 return err
1001 }
1002
1003 outputFormat := CharReplacer.Replace(options.Format)
1004 if outputFormat == "" {
David Bainbridgea6722342019-10-24 23:55:53 +00001005 outputFormat = GetCommandOptionWithDefault("device-list", "format", DEFAULT_DEVICE_FORMAT)
Zack Williamse940c7a2019-08-21 14:25:39 -07001006 }
1007 if options.Quiet {
1008 outputFormat = "{{.Id}}"
1009 }
1010
David Bainbridgea6722342019-10-24 23:55:53 +00001011 orderBy := options.OrderBy
1012 if orderBy == "" {
Hardik Windlass9361bb82022-03-23 05:58:48 +00001013 orderBy = GetCommandOptionWithDefault("device-list", "order", DEFAULT_DEVICE_ORDER)
David Bainbridgea6722342019-10-24 23:55:53 +00001014 }
1015
Scott Baker9173ed82020-05-19 08:30:12 -07001016 // Make sure json output prints an empty list, not "null"
1017 if devices.Items == nil {
1018 devices.Items = make([]*voltha.Device, 0)
Zack Williamse940c7a2019-08-21 14:25:39 -07001019 }
1020
1021 result := CommandResult{
1022 Format: format.Format(outputFormat),
1023 Filter: options.Filter,
David Bainbridgea6722342019-10-24 23:55:53 +00001024 OrderBy: orderBy,
Zack Williamse940c7a2019-08-21 14:25:39 -07001025 OutputAs: toOutputType(options.OutputAs),
1026 NameLimit: options.NameLimit,
Scott Baker9173ed82020-05-19 08:30:12 -07001027 Data: devices.Items,
Zack Williamse940c7a2019-08-21 14:25:39 -07001028 }
1029
1030 GenerateOutput(&result)
1031 return nil
1032}
1033
1034func (options *DeviceCreate) Execute(args []string) error {
1035
Scott Baker9173ed82020-05-19 08:30:12 -07001036 device := voltha.Device{}
Zack Williamse940c7a2019-08-21 14:25:39 -07001037 if options.HostAndPort != "" {
Scott Baker9173ed82020-05-19 08:30:12 -07001038 device.Address = &voltha.Device_HostAndPort{HostAndPort: options.HostAndPort}
Zack Williamse940c7a2019-08-21 14:25:39 -07001039 } else if options.IPAddress != "" {
Scott Baker9173ed82020-05-19 08:30:12 -07001040 device.Address = &voltha.Device_Ipv4Address{Ipv4Address: options.IPAddress}
Hardik Windlassce1de342020-02-04 21:58:07 +00001041 }
1042 if options.MACAddress != "" {
Scott Baker9173ed82020-05-19 08:30:12 -07001043 device.MacAddress = strings.ToLower(options.MACAddress)
Zack Williamse940c7a2019-08-21 14:25:39 -07001044 }
1045 if options.DeviceType != "" {
Scott Baker9173ed82020-05-19 08:30:12 -07001046 device.Type = options.DeviceType
Zack Williamse940c7a2019-08-21 14:25:39 -07001047 }
1048
1049 conn, err := NewConnection()
1050 if err != nil {
1051 return err
1052 }
1053 defer conn.Close()
1054
Scott Baker9173ed82020-05-19 08:30:12 -07001055 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -07001056
David K. Bainbridge9189c632021-03-26 21:52:21 +00001057 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -07001058 defer cancel()
1059
Scott Baker9173ed82020-05-19 08:30:12 -07001060 createdDevice, err := client.CreateDevice(ctx, &device)
Zack Williamse940c7a2019-08-21 14:25:39 -07001061 if err != nil {
1062 return err
Zack Williamse940c7a2019-08-21 14:25:39 -07001063 }
1064
Scott Baker9173ed82020-05-19 08:30:12 -07001065 fmt.Printf("%s\n", createdDevice.Id)
Zack Williamse940c7a2019-08-21 14:25:39 -07001066
1067 return nil
1068}
1069
1070func (options *DeviceDelete) Execute(args []string) error {
1071
1072 conn, err := NewConnection()
1073 if err != nil {
1074 return err
1075 }
1076 defer conn.Close()
1077
Scott Baker9173ed82020-05-19 08:30:12 -07001078 client := voltha.NewVolthaServiceClient(conn)
David Bainbridge7052fe82020-03-25 10:37:00 -07001079 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -07001080 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +00001081 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -07001082 defer cancel()
1083
Scott Baker9173ed82020-05-19 08:30:12 -07001084 id := voltha.ID{Id: string(i)}
Himani Chawla9933ddc2020-10-12 23:53:27 +05301085 if options.Force {
1086 _, err = client.ForceDeleteDevice(ctx, &id)
1087 } else {
1088 _, err = client.DeleteDevice(ctx, &id)
1089 }
Scott Baker9173ed82020-05-19 08:30:12 -07001090
Zack Williamse940c7a2019-08-21 14:25:39 -07001091 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +00001092 Error.Printf("Error while deleting '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -07001093 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -07001094 continue
Zack Williamse940c7a2019-08-21 14:25:39 -07001095 }
1096 fmt.Printf("%s\n", i)
1097 }
1098
David Bainbridge7052fe82020-03-25 10:37:00 -07001099 if lastErr != nil {
1100 return NoReportErr
1101 }
Zack Williamse940c7a2019-08-21 14:25:39 -07001102 return nil
1103}
1104
1105func (options *DeviceEnable) Execute(args []string) error {
1106 conn, err := NewConnection()
1107 if err != nil {
1108 return err
1109 }
1110 defer conn.Close()
1111
Scott Baker9173ed82020-05-19 08:30:12 -07001112 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -07001113
David Bainbridge7052fe82020-03-25 10:37:00 -07001114 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -07001115 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +00001116 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -07001117 defer cancel()
1118
Scott Baker9173ed82020-05-19 08:30:12 -07001119 id := voltha.ID{Id: string(i)}
1120
1121 _, err := client.EnableDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -07001122 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +00001123 Error.Printf("Error while enabling '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -07001124 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -07001125 continue
Zack Williamse940c7a2019-08-21 14:25:39 -07001126 }
1127 fmt.Printf("%s\n", i)
1128 }
1129
David Bainbridge7052fe82020-03-25 10:37:00 -07001130 if lastErr != nil {
1131 return NoReportErr
1132 }
Zack Williamse940c7a2019-08-21 14:25:39 -07001133 return nil
1134}
1135
1136func (options *DeviceDisable) Execute(args []string) error {
1137 conn, err := NewConnection()
1138 if err != nil {
1139 return err
1140 }
1141 defer conn.Close()
1142
Scott Baker9173ed82020-05-19 08:30:12 -07001143 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -07001144
David Bainbridge7052fe82020-03-25 10:37:00 -07001145 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -07001146 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +00001147 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -07001148 defer cancel()
1149
Scott Baker9173ed82020-05-19 08:30:12 -07001150 id := voltha.ID{Id: string(i)}
1151
1152 _, err := client.DisableDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -07001153 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +00001154 Error.Printf("Error while disabling '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -07001155 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -07001156 continue
Zack Williamse940c7a2019-08-21 14:25:39 -07001157 }
1158 fmt.Printf("%s\n", i)
1159 }
1160
David Bainbridge7052fe82020-03-25 10:37:00 -07001161 if lastErr != nil {
1162 return NoReportErr
1163 }
Zack Williamse940c7a2019-08-21 14:25:39 -07001164 return nil
1165}
1166
1167func (options *DeviceReboot) Execute(args []string) error {
1168 conn, err := NewConnection()
1169 if err != nil {
1170 return err
1171 }
1172 defer conn.Close()
1173
Scott Baker9173ed82020-05-19 08:30:12 -07001174 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -07001175
David Bainbridge7052fe82020-03-25 10:37:00 -07001176 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -07001177 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +00001178 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -07001179 defer cancel()
1180
Scott Baker9173ed82020-05-19 08:30:12 -07001181 id := voltha.ID{Id: string(i)}
1182
1183 _, err := client.RebootDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -07001184 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +00001185 Error.Printf("Error while rebooting '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -07001186 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -07001187 continue
Zack Williamse940c7a2019-08-21 14:25:39 -07001188 }
1189 fmt.Printf("%s\n", i)
1190 }
1191
David Bainbridge7052fe82020-03-25 10:37:00 -07001192 if lastErr != nil {
1193 return NoReportErr
1194 }
Zack Williamse940c7a2019-08-21 14:25:39 -07001195 return nil
1196}
1197
1198func (options *DevicePortList) Execute(args []string) error {
1199
1200 conn, err := NewConnection()
1201 if err != nil {
1202 return err
1203 }
1204 defer conn.Close()
1205
Scott Baker9173ed82020-05-19 08:30:12 -07001206 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -07001207
David K. Bainbridge9189c632021-03-26 21:52:21 +00001208 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -07001209 defer cancel()
1210
Scott Baker9173ed82020-05-19 08:30:12 -07001211 id := voltha.ID{Id: string(options.Args.Id)}
Zack Williamse940c7a2019-08-21 14:25:39 -07001212
Scott Baker9173ed82020-05-19 08:30:12 -07001213 ports, err := client.ListDevicePorts(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -07001214 if err != nil {
1215 return err
1216 }
1217
1218 outputFormat := CharReplacer.Replace(options.Format)
1219 if outputFormat == "" {
David Bainbridgea6722342019-10-24 23:55:53 +00001220 outputFormat = GetCommandOptionWithDefault("device-ports", "format", DEFAULT_DEVICE_PORTS_FORMAT)
Zack Williamse940c7a2019-08-21 14:25:39 -07001221 }
Zack Williamse940c7a2019-08-21 14:25:39 -07001222
David Bainbridgea6722342019-10-24 23:55:53 +00001223 orderBy := options.OrderBy
1224 if orderBy == "" {
1225 orderBy = GetCommandOptionWithDefault("device-ports", "order", "")
1226 }
1227
Zack Williamse940c7a2019-08-21 14:25:39 -07001228 result := CommandResult{
1229 Format: format.Format(outputFormat),
1230 Filter: options.Filter,
David Bainbridgea6722342019-10-24 23:55:53 +00001231 OrderBy: orderBy,
Zack Williamse940c7a2019-08-21 14:25:39 -07001232 OutputAs: toOutputType(options.OutputAs),
1233 NameLimit: options.NameLimit,
Scott Baker9173ed82020-05-19 08:30:12 -07001234 Data: ports.Items,
Zack Williamse940c7a2019-08-21 14:25:39 -07001235 }
1236
1237 GenerateOutput(&result)
1238 return nil
1239}
1240
1241func (options *DeviceFlowList) Execute(args []string) error {
1242 fl := &FlowList{}
1243 fl.ListOutputOptions = options.ListOutputOptions
Maninder045921e2020-09-29 16:46:02 +05301244 fl.FlowIdOptions = options.FlowIdOptions
Zack Williamse940c7a2019-08-21 14:25:39 -07001245 fl.Args.Id = string(options.Args.Id)
David Bainbridgea6722342019-10-24 23:55:53 +00001246 fl.Method = "device-flows"
Zack Williamse940c7a2019-08-21 14:25:39 -07001247 return fl.Execute(args)
1248}
1249
Himani Chawla3c161c62021-05-13 16:36:51 +05301250func (options *DeviceFlowGroupList) Execute(args []string) error {
1251 grp := &GroupList{}
1252 grp.ListOutputOptions = options.ListOutputOptions
1253 grp.GroupListOptions = options.GroupListOptions
1254 grp.Args.Id = string(options.Args.Id)
1255 grp.Method = "device-groups"
1256 return grp.Execute(args)
1257}
1258
Zack Williamse940c7a2019-08-21 14:25:39 -07001259func (options *DeviceInspect) Execute(args []string) error {
1260 if len(args) > 0 {
1261 return fmt.Errorf("only a single argument 'DEVICE_ID' can be provided")
1262 }
1263
1264 conn, err := NewConnection()
1265 if err != nil {
1266 return err
1267 }
1268 defer conn.Close()
1269
Scott Baker9173ed82020-05-19 08:30:12 -07001270 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -07001271
David K. Bainbridge9189c632021-03-26 21:52:21 +00001272 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -07001273 defer cancel()
1274
Scott Baker9173ed82020-05-19 08:30:12 -07001275 id := voltha.ID{Id: string(options.Args.Id)}
Zack Williamse940c7a2019-08-21 14:25:39 -07001276
Scott Baker9173ed82020-05-19 08:30:12 -07001277 device, err := client.GetDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -07001278 if err != nil {
1279 return err
1280 }
1281
Zack Williamse940c7a2019-08-21 14:25:39 -07001282 outputFormat := CharReplacer.Replace(options.Format)
1283 if outputFormat == "" {
David Bainbridgea6722342019-10-24 23:55:53 +00001284 outputFormat = GetCommandOptionWithDefault("device-inspect", "format", DEFAULT_DEVICE_INSPECT_FORMAT)
Zack Williamse940c7a2019-08-21 14:25:39 -07001285 }
1286 if options.Quiet {
1287 outputFormat = "{{.Id}}"
1288 }
1289
1290 result := CommandResult{
1291 Format: format.Format(outputFormat),
1292 OutputAs: toOutputType(options.OutputAs),
1293 NameLimit: options.NameLimit,
1294 Data: device,
1295 }
1296 GenerateOutput(&result)
1297 return nil
1298}
kesavand12cd8eb2020-01-20 22:25:22 -05001299
1300/*Device Port Enable */
1301func (options *DevicePortEnable) Execute(args []string) error {
1302 conn, err := NewConnection()
1303 if err != nil {
1304 return err
1305 }
1306 defer conn.Close()
1307
Scott Baker9173ed82020-05-19 08:30:12 -07001308 client := voltha.NewVolthaServiceClient(conn)
kesavand12cd8eb2020-01-20 22:25:22 -05001309
David K. Bainbridge9189c632021-03-26 21:52:21 +00001310 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand12cd8eb2020-01-20 22:25:22 -05001311 defer cancel()
1312
Scott Baker9173ed82020-05-19 08:30:12 -07001313 port := voltha.Port{DeviceId: string(options.Args.Id), PortNo: uint32(options.Args.PortId)}
1314
1315 _, err = client.EnablePort(ctx, &port)
kesavand12cd8eb2020-01-20 22:25:22 -05001316 if err != nil {
1317 Error.Printf("Error enabling port number %v on device Id %s,err=%s\n", options.Args.PortId, options.Args.Id, ErrorToString(err))
1318 return err
kesavand12cd8eb2020-01-20 22:25:22 -05001319 }
1320
1321 return nil
1322}
1323
Scott Baker9173ed82020-05-19 08:30:12 -07001324/*Device Port Disable */
kesavand12cd8eb2020-01-20 22:25:22 -05001325func (options *DevicePortDisable) Execute(args []string) error {
1326 conn, err := NewConnection()
1327 if err != nil {
1328 return err
1329 }
1330 defer conn.Close()
1331
Scott Baker9173ed82020-05-19 08:30:12 -07001332 client := voltha.NewVolthaServiceClient(conn)
1333
David K. Bainbridge9189c632021-03-26 21:52:21 +00001334 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand12cd8eb2020-01-20 22:25:22 -05001335 defer cancel()
1336
Scott Baker9173ed82020-05-19 08:30:12 -07001337 port := voltha.Port{DeviceId: string(options.Args.Id), PortNo: uint32(options.Args.PortId)}
1338
1339 _, err = client.DisablePort(ctx, &port)
kesavand12cd8eb2020-01-20 22:25:22 -05001340 if err != nil {
Scott Baker9173ed82020-05-19 08:30:12 -07001341 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 -05001342 return err
kesavand12cd8eb2020-01-20 22:25:22 -05001343 }
Scott Baker9173ed82020-05-19 08:30:12 -07001344
kesavand12cd8eb2020-01-20 22:25:22 -05001345 return nil
1346}
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08001347
Rohan Agrawald7df3772020-06-29 11:23:36 +00001348func (options *DevicePmConfigSetMaxSkew) Execute(args []string) error {
1349 conn, err := NewConnection()
1350 if err != nil {
1351 return err
1352 }
1353 defer conn.Close()
1354
1355 client := voltha.NewVolthaServiceClient(conn)
1356
David K. Bainbridge9189c632021-03-26 21:52:21 +00001357 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawald7df3772020-06-29 11:23:36 +00001358 defer cancel()
1359
1360 id := voltha.ID{Id: string(options.Args.Id)}
1361
1362 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1363 if err != nil {
1364 return err
1365 }
1366
1367 pmConfigs.MaxSkew = options.Args.MaxSkew
1368
1369 _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs)
1370 if err != nil {
1371 return err
1372 }
1373
1374 return nil
1375}
1376
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001377func (options *DevicePmConfigsGet) Execute(args []string) error {
1378
1379 conn, err := NewConnection()
1380 if err != nil {
1381 return err
1382 }
1383 defer conn.Close()
1384
1385 client := voltha.NewVolthaServiceClient(conn)
1386
David K. Bainbridge9189c632021-03-26 21:52:21 +00001387 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001388 defer cancel()
1389
1390 id := voltha.ID{Id: string(options.Args.Id)}
1391
1392 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1393 if err != nil {
1394 return err
1395 }
1396
1397 outputFormat := CharReplacer.Replace(options.Format)
1398 if outputFormat == "" {
1399 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GET_FORMAT)
1400 }
1401
1402 orderBy := options.OrderBy
1403 if orderBy == "" {
1404 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1405 }
1406
1407 result := CommandResult{
1408 Format: format.Format(outputFormat),
1409 Filter: options.Filter,
1410 OrderBy: orderBy,
1411 OutputAs: toOutputType(options.OutputAs),
1412 NameLimit: options.NameLimit,
1413 Data: pmConfigs,
1414 }
1415
1416 GenerateOutput(&result)
1417 return nil
1418
1419}
1420
1421func (options *DevicePmConfigMetricList) Execute(args []string) error {
1422
1423 conn, err := NewConnection()
1424 if err != nil {
1425 return err
1426 }
1427 defer conn.Close()
1428
1429 client := voltha.NewVolthaServiceClient(conn)
1430
David K. Bainbridge9189c632021-03-26 21:52:21 +00001431 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001432 defer cancel()
1433
1434 id := voltha.ID{Id: string(options.Args.Id)}
1435
1436 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1437 if err != nil {
1438 return err
1439 }
1440
1441 if !pmConfigs.Grouped {
1442 for _, metric := range pmConfigs.Metrics {
1443 if metric.SampleFreq == 0 {
1444 metric.SampleFreq = pmConfigs.DefaultFreq
1445 }
1446 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001447 outputFormat := CharReplacer.Replace(options.Format)
1448 if outputFormat == "" {
1449 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_METRIC_LIST_FORMAT)
1450 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001451
Rohan Agrawalbca69122020-06-17 14:59:03 +00001452 orderBy := options.OrderBy
1453 if orderBy == "" {
1454 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1455 }
1456
1457 result := CommandResult{
1458 Format: format.Format(outputFormat),
1459 Filter: options.Filter,
1460 OrderBy: orderBy,
1461 OutputAs: toOutputType(options.OutputAs),
1462 NameLimit: options.NameLimit,
1463 Data: pmConfigs.Metrics,
1464 }
1465
1466 GenerateOutput(&result)
1467 return nil
1468 } else {
1469 return fmt.Errorf("Device '%s' does not have Non Grouped Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001470 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001471}
1472
1473func (options *DevicePmConfigMetricEnable) Execute(args []string) error {
1474
1475 conn, err := NewConnection()
1476 if err != nil {
1477 return err
1478 }
1479 defer conn.Close()
1480
1481 client := voltha.NewVolthaServiceClient(conn)
1482
David K. Bainbridge9189c632021-03-26 21:52:21 +00001483 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001484 defer cancel()
1485
1486 id := voltha.ID{Id: string(options.Args.Id)}
1487
1488 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1489 if err != nil {
1490 return err
1491 }
1492
1493 if !pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001494 metrics := make(map[string]struct{})
1495 for _, metric := range pmConfigs.Metrics {
1496 metrics[metric.Name] = struct{}{}
1497 }
1498
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001499 for _, metric := range pmConfigs.Metrics {
1500 for _, mName := range options.Args.Metrics {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001501 if _, exist := metrics[string(mName)]; !exist {
1502 return fmt.Errorf("Metric Name '%s' does not exist", mName)
1503 }
1504
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001505 if string(mName) == metric.Name && !metric.Enabled {
1506 metric.Enabled = true
1507 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1508 if err != nil {
1509 return err
1510 }
1511 }
1512 }
1513 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001514 } else {
1515 return fmt.Errorf("Device '%s' does not have Non Grouped Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001516 }
1517 return nil
1518}
1519
1520func (options *DevicePmConfigMetricDisable) Execute(args []string) error {
1521
1522 conn, err := NewConnection()
1523 if err != nil {
1524 return err
1525 }
1526 defer conn.Close()
1527
1528 client := voltha.NewVolthaServiceClient(conn)
1529
David K. Bainbridge9189c632021-03-26 21:52:21 +00001530 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001531 defer cancel()
1532
1533 id := voltha.ID{Id: string(options.Args.Id)}
1534
1535 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1536 if err != nil {
1537 return err
1538 }
1539
1540 if !pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001541 metrics := make(map[string]struct{})
1542 for _, metric := range pmConfigs.Metrics {
1543 metrics[metric.Name] = struct{}{}
1544 }
1545
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001546 for _, metric := range pmConfigs.Metrics {
1547 for _, mName := range options.Args.Metrics {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001548 if _, have := metrics[string(mName)]; !have {
1549 return fmt.Errorf("Metric Name '%s' does not exist", mName)
1550 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001551 if string(mName) == metric.Name && metric.Enabled {
1552 metric.Enabled = false
1553 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1554 if err != nil {
1555 return err
1556 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001557 } else {
1558 return fmt.Errorf("Metric '%s' cannot be disabled", string(mName))
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001559 }
1560 }
1561 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001562 } else {
1563 return fmt.Errorf("Device '%s' does not have Non Grouped Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001564 }
1565 return nil
1566}
1567
1568func (options *DevicePmConfigGroupEnable) Execute(args []string) error {
1569
1570 conn, err := NewConnection()
1571 if err != nil {
1572 return err
1573 }
1574 defer conn.Close()
1575
1576 client := voltha.NewVolthaServiceClient(conn)
1577
David K. Bainbridge9189c632021-03-26 21:52:21 +00001578 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001579 defer cancel()
1580
1581 id := voltha.ID{Id: string(options.Args.Id)}
1582
1583 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1584 if err != nil {
1585 return err
1586 }
1587
1588 if pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001589 groups := make(map[string]struct{})
1590 for _, group := range pmConfigs.Groups {
1591 groups[group.GroupName] = struct{}{}
1592 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001593 for _, group := range pmConfigs.Groups {
Girish Gowdra610acb42021-01-27 13:33:57 -08001594 if _, have := groups[string(options.Args.Group)]; !have {
1595 return fmt.Errorf("Group Name '%s' does not exist", options.Args.Group)
1596 }
1597 if string(options.Args.Group) == group.GroupName && !group.Enabled {
1598 group.Enabled = true
1599 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1600 if err != nil {
1601 return err
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001602 }
1603 }
1604 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001605 } else {
1606 return fmt.Errorf("Device '%s' does not have Group Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001607 }
1608 return nil
1609}
1610
1611func (options *DevicePmConfigGroupDisable) Execute(args []string) error {
1612
1613 conn, err := NewConnection()
1614 if err != nil {
1615 return err
1616 }
1617 defer conn.Close()
1618
1619 client := voltha.NewVolthaServiceClient(conn)
1620
David K. Bainbridge9189c632021-03-26 21:52:21 +00001621 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001622 defer cancel()
1623
1624 id := voltha.ID{Id: string(options.Args.Id)}
1625
1626 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1627 if err != nil {
1628 return err
1629 }
1630
1631 if pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001632 groups := make(map[string]struct{})
1633 for _, group := range pmConfigs.Groups {
1634 groups[group.GroupName] = struct{}{}
1635 }
1636
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001637 for _, group := range pmConfigs.Groups {
Girish Gowdra610acb42021-01-27 13:33:57 -08001638 if _, have := groups[string(options.Args.Group)]; !have {
1639 return fmt.Errorf("Group Name '%s' does not exist", options.Args.Group)
1640 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001641
Girish Gowdra610acb42021-01-27 13:33:57 -08001642 if string(options.Args.Group) == group.GroupName && group.Enabled {
1643 group.Enabled = false
1644 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1645 if err != nil {
1646 return err
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001647 }
1648 }
1649 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001650 } else {
1651 return fmt.Errorf("Device '%s' does not have Group Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001652 }
1653 return nil
1654}
1655
Girish Gowdra610acb42021-01-27 13:33:57 -08001656func (options *DevicePmConfigGroupFrequencySet) Execute(args []string) error {
1657
1658 conn, err := NewConnection()
1659 if err != nil {
1660 return err
1661 }
1662 defer conn.Close()
1663
1664 client := voltha.NewVolthaServiceClient(conn)
1665
David K. Bainbridge9189c632021-03-26 21:52:21 +00001666 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Girish Gowdra610acb42021-01-27 13:33:57 -08001667 defer cancel()
1668
1669 id := voltha.ID{Id: string(options.Args.Id)}
1670
1671 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1672 if err != nil {
1673 return err
1674 }
1675
1676 if pmConfigs.Grouped {
1677 groups := make(map[string]struct{})
1678 for _, group := range pmConfigs.Groups {
1679 groups[group.GroupName] = struct{}{}
1680 }
1681
1682 for _, group := range pmConfigs.Groups {
1683 if _, have := groups[string(options.Args.Group)]; !have {
1684 return fmt.Errorf("group name '%s' does not exist", options.Args.Group)
1685 }
1686
1687 if string(options.Args.Group) == group.GroupName {
1688 if !group.Enabled {
1689 return fmt.Errorf("group '%s' is not enabled", options.Args.Group)
1690 }
1691 group.GroupFreq = uint32(options.Args.Interval.Seconds())
1692 _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs)
1693 if err != nil {
1694 return err
1695 }
1696 }
1697 }
1698 } else {
1699 return fmt.Errorf("device '%s' does not have group metrics", options.Args.Id)
1700 }
1701 return nil
1702}
1703
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001704func (options *DevicePmConfigGroupList) Execute(args []string) error {
1705
1706 conn, err := NewConnection()
1707 if err != nil {
1708 return err
1709 }
1710 defer conn.Close()
1711
1712 client := voltha.NewVolthaServiceClient(conn)
1713
David K. Bainbridge9189c632021-03-26 21:52:21 +00001714 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001715 defer cancel()
1716
1717 id := voltha.ID{Id: string(options.Args.Id)}
1718
1719 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1720 if err != nil {
1721 return err
1722 }
1723
1724 if pmConfigs.Grouped {
1725 for _, group := range pmConfigs.Groups {
1726 if group.GroupFreq == 0 {
1727 group.GroupFreq = pmConfigs.DefaultFreq
1728 }
1729 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001730 outputFormat := CharReplacer.Replace(options.Format)
1731 if outputFormat == "" {
1732 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GROUP_LIST_FORMAT)
1733 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001734
Rohan Agrawalbca69122020-06-17 14:59:03 +00001735 orderBy := options.OrderBy
1736 if orderBy == "" {
1737 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1738 }
1739
1740 result := CommandResult{
1741 Format: format.Format(outputFormat),
1742 Filter: options.Filter,
1743 OrderBy: orderBy,
1744 OutputAs: toOutputType(options.OutputAs),
1745 NameLimit: options.NameLimit,
1746 Data: pmConfigs.Groups,
1747 }
1748
1749 GenerateOutput(&result)
1750 } else {
1751 return fmt.Errorf("Device '%s' does not have Group Metrics", string(options.Args.Id))
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001752 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001753 return nil
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001754}
1755
1756func (options *DevicePmConfigGroupMetricList) Execute(args []string) error {
1757
1758 var metrics []*voltha.PmConfig
1759 conn, err := NewConnection()
1760 if err != nil {
1761 return err
1762 }
1763 defer conn.Close()
1764
1765 client := voltha.NewVolthaServiceClient(conn)
1766
David K. Bainbridge9189c632021-03-26 21:52:21 +00001767 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001768 defer cancel()
1769
1770 id := voltha.ID{Id: string(options.Args.Id)}
1771
1772 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1773 if err != nil {
1774 return err
1775 }
1776
1777 for _, groups := range pmConfigs.Groups {
1778
1779 if string(options.Args.Group) == groups.GroupName {
1780 for _, metric := range groups.Metrics {
1781 if metric.SampleFreq == 0 && groups.GroupFreq == 0 {
1782 metric.SampleFreq = pmConfigs.DefaultFreq
1783 } else {
1784 metric.SampleFreq = groups.GroupFreq
1785 }
1786 }
1787 metrics = groups.Metrics
1788 }
1789 }
1790
1791 outputFormat := CharReplacer.Replace(options.Format)
1792 if outputFormat == "" {
1793 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_METRIC_LIST_FORMAT)
1794 }
1795
1796 orderBy := options.OrderBy
1797 if orderBy == "" {
1798 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1799 }
1800
1801 result := CommandResult{
1802 Format: format.Format(outputFormat),
1803 Filter: options.Filter,
1804 OrderBy: orderBy,
1805 OutputAs: toOutputType(options.OutputAs),
1806 NameLimit: options.NameLimit,
1807 Data: metrics,
1808 }
1809
1810 GenerateOutput(&result)
1811 return nil
1812
1813}
1814
1815func (options *DevicePmConfigFrequencySet) Execute(args []string) error {
1816
1817 conn, err := NewConnection()
1818 if err != nil {
1819 return err
1820 }
1821 defer conn.Close()
1822
1823 client := voltha.NewVolthaServiceClient(conn)
1824
David K. Bainbridge9189c632021-03-26 21:52:21 +00001825 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001826 defer cancel()
1827
1828 id := voltha.ID{Id: string(options.Args.Id)}
1829
1830 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1831 if err != nil {
1832 return err
1833 }
1834
Girish Gowdra610acb42021-01-27 13:33:57 -08001835 pmConfigs.DefaultFreq = uint32(options.Args.Interval.Seconds())
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001836
1837 _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs)
1838 if err != nil {
1839 return err
1840 }
1841
1842 outputFormat := CharReplacer.Replace(options.Format)
1843 if outputFormat == "" {
1844 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GET_FORMAT)
1845 }
1846 if options.Quiet {
1847 outputFormat = "{{.Id}}"
1848 }
1849
1850 result := CommandResult{
1851 Format: format.Format(outputFormat),
1852 OutputAs: toOutputType(options.OutputAs),
1853 NameLimit: options.NameLimit,
1854 Data: pmConfigs,
1855 }
1856
1857 GenerateOutput(&result)
1858 return nil
1859
1860}
1861
kesavand3e2f9f62021-04-22 11:06:38 +05301862func (options *OnuDownloadImage) Execute(args []string) error {
1863
1864 conn, err := NewConnection()
1865 if err != nil {
1866 return err
1867 }
1868 defer conn.Close()
1869
1870 client := voltha.NewVolthaServiceClient(conn)
1871
1872 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1873 defer cancel()
1874
1875 var devIDList []*common.ID
1876 for _, i := range options.Args.IDs {
1877
1878 devIDList = append(devIDList, &common.ID{Id: string(i)})
1879 }
1880
1881 downloadImage := voltha.DeviceImageDownloadRequest{
1882 DeviceId: devIDList,
1883 Image: &voltha.Image{
1884 Url: options.Args.Url,
1885 Crc32: options.Args.Crc,
ssiddiqui7bc89e92021-05-20 20:58:02 +05301886 Vendor: options.Args.Vendor,
kesavand3e2f9f62021-04-22 11:06:38 +05301887 Version: options.Args.ImageVersion,
1888 },
1889 ActivateOnSuccess: options.Args.ActivateOnSuccess,
1890 CommitOnSuccess: options.Args.CommitOnSuccess,
1891 }
1892
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001893 deviceImageResp, err := client.DownloadImageToDevice(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301894 if err != nil {
1895 return err
1896 }
1897
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001898 outputFormat := GetCommandOptionWithDefault("onu-image-download", "format", ONU_IMAGE_STATUS_FORMAT)
1899 // Make sure json output prints an empty list, not "null"
1900 if deviceImageResp.DeviceImageStates == nil {
1901 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1902 }
1903 result := CommandResult{
1904 Format: format.Format(outputFormat),
1905 OutputAs: toOutputType(options.OutputAs),
1906 NameLimit: options.NameLimit,
1907 Data: deviceImageResp.DeviceImageStates,
1908 }
1909 GenerateOutput(&result)
kesavand3e2f9f62021-04-22 11:06:38 +05301910 return nil
1911
1912}
1913
1914func (options *OnuActivateImage) Execute(args []string) error {
1915
1916 conn, err := NewConnection()
1917 if err != nil {
1918 return err
1919 }
1920 defer conn.Close()
1921
1922 client := voltha.NewVolthaServiceClient(conn)
1923
1924 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1925 defer cancel()
1926
1927 var devIDList []*common.ID
1928 for _, i := range options.Args.IDs {
1929
1930 devIDList = append(devIDList, &common.ID{Id: string(i)})
1931 }
1932
1933 downloadImage := voltha.DeviceImageRequest{
1934 DeviceId: devIDList,
1935 Version: options.Args.ImageVersion,
1936 CommitOnSuccess: options.Args.CommitOnSuccess,
1937 }
1938
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001939 deviceImageResp, err := client.ActivateImage(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301940 if err != nil {
1941 return err
1942 }
1943
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001944 outputFormat := GetCommandOptionWithDefault("onu-image-activate", "format", ONU_IMAGE_STATUS_FORMAT)
1945 // Make sure json output prints an empty list, not "null"
1946 if deviceImageResp.DeviceImageStates == nil {
1947 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1948 }
1949 result := CommandResult{
1950 Format: format.Format(outputFormat),
1951 OutputAs: toOutputType(options.OutputAs),
1952 NameLimit: options.NameLimit,
1953 Data: deviceImageResp.DeviceImageStates,
1954 }
1955 GenerateOutput(&result)
1956
kesavand3e2f9f62021-04-22 11:06:38 +05301957 return nil
1958
1959}
1960
1961func (options *OnuAbortUpgradeImage) Execute(args []string) error {
1962
1963 conn, err := NewConnection()
1964 if err != nil {
1965 return err
1966 }
1967 defer conn.Close()
1968
1969 client := voltha.NewVolthaServiceClient(conn)
1970
1971 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1972 defer cancel()
1973
1974 var devIDList []*common.ID
1975 for _, i := range options.Args.IDs {
1976
1977 devIDList = append(devIDList, &common.ID{Id: string(i)})
1978 }
1979
1980 downloadImage := voltha.DeviceImageRequest{
1981 DeviceId: devIDList,
1982 Version: options.Args.ImageVersion,
1983 }
1984
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001985 deviceImageResp, err := client.AbortImageUpgradeToDevice(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301986 if err != nil {
1987 return err
1988 }
1989
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001990 outputFormat := GetCommandOptionWithDefault("onu-image-abort", "format", ONU_IMAGE_STATUS_FORMAT)
1991 // Make sure json output prints an empty list, not "null"
1992 if deviceImageResp.DeviceImageStates == nil {
1993 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1994 }
1995 result := CommandResult{
1996 Format: format.Format(outputFormat),
1997 OutputAs: toOutputType(options.OutputAs),
1998 NameLimit: options.NameLimit,
1999 Data: deviceImageResp.DeviceImageStates,
2000 }
2001 GenerateOutput(&result)
2002
kesavand3e2f9f62021-04-22 11:06:38 +05302003 return nil
2004
2005}
2006
2007func (options *OnuCommitImage) Execute(args []string) error {
2008
2009 conn, err := NewConnection()
2010 if err != nil {
2011 return err
2012 }
2013 defer conn.Close()
2014
2015 client := voltha.NewVolthaServiceClient(conn)
2016
2017 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2018 defer cancel()
2019
2020 var devIDList []*common.ID
2021 for _, i := range options.Args.IDs {
2022
2023 devIDList = append(devIDList, &common.ID{Id: string(i)})
2024 }
2025 downloadImage := voltha.DeviceImageRequest{
2026 DeviceId: devIDList,
2027 Version: options.Args.ImageVersion,
2028 }
2029
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02002030 deviceImageResp, err := client.CommitImage(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05302031 if err != nil {
2032 return err
2033 }
2034
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02002035 outputFormat := GetCommandOptionWithDefault("onu-image-commit", "format", ONU_IMAGE_STATUS_FORMAT)
2036 // Make sure json output prints an empty list, not "null"
2037 if deviceImageResp.DeviceImageStates == nil {
2038 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
2039 }
2040 result := CommandResult{
2041 Format: format.Format(outputFormat),
2042 OutputAs: toOutputType(options.OutputAs),
2043 NameLimit: options.NameLimit,
2044 Data: deviceImageResp.DeviceImageStates,
2045 }
2046 GenerateOutput(&result)
2047
kesavand3e2f9f62021-04-22 11:06:38 +05302048 return nil
2049
2050}
2051
2052func (options *OnuListImages) Execute(args []string) error {
2053
2054 conn, err := NewConnection()
2055 if err != nil {
2056 return err
2057 }
2058 defer conn.Close()
2059
2060 client := voltha.NewVolthaServiceClient(conn)
2061
2062 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2063 defer cancel()
2064
2065 id := common.ID{Id: string(options.Args.Id)}
2066
2067 onuImages, err := client.GetOnuImages(ctx, &id)
2068 if err != nil {
2069 return err
2070 }
2071
2072 outputFormat := CharReplacer.Replace(options.Format)
2073 if outputFormat == "" {
2074 outputFormat = GetCommandOptionWithDefault("onu-image-list", "format", ONU_IMAGE_LIST_FORMAT)
2075 }
2076
2077 if options.Quiet {
2078 outputFormat = "{{.Id}}"
2079 }
2080
2081 //TODO orderby
2082
2083 // Make sure json output prints an empty list, not "null"
2084 if onuImages.Items == nil {
2085 onuImages.Items = make([]*voltha.OnuImage, 0)
2086 }
2087
2088 result := CommandResult{
2089 Format: format.Format(outputFormat),
2090 OutputAs: toOutputType(options.OutputAs),
2091 NameLimit: options.NameLimit,
2092 Data: onuImages.Items,
2093 }
2094
2095 GenerateOutput(&result)
2096 return nil
2097
2098}
2099
2100func (options *OnuImageStatus) Execute(args []string) error {
2101
2102 conn, err := NewConnection()
2103 if err != nil {
2104 return err
2105 }
2106 defer conn.Close()
2107
2108 client := voltha.NewVolthaServiceClient(conn)
2109
2110 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2111 defer cancel()
2112
2113 var devIDList []*common.ID
kesavand3e2f9f62021-04-22 11:06:38 +05302114
Elia Battiston859f3e62022-02-08 15:57:52 +01002115 if options.Args.IDs == nil {
2116 //Use an empty IDs list to retrieve the status of all devices
2117 //with the requested image version
2118 devIDList = []*common.ID{}
2119 } else {
2120 for _, i := range options.Args.IDs {
2121 devIDList = append(devIDList, &common.ID{Id: string(i)})
2122 }
kesavand3e2f9f62021-04-22 11:06:38 +05302123 }
2124
2125 imageStatusReq := voltha.DeviceImageRequest{
2126 DeviceId: devIDList,
2127 Version: options.Args.ImageVersion,
2128 }
2129 imageStatus, err := client.GetImageStatus(ctx, &imageStatusReq)
2130 if err != nil {
2131 return err
2132 }
2133
2134 outputFormat := CharReplacer.Replace(options.Format)
2135 if outputFormat == "" {
2136 outputFormat = GetCommandOptionWithDefault("device-image-list", "format", ONU_IMAGE_STATUS_FORMAT)
2137 }
2138
2139 if options.Quiet {
2140 outputFormat = "{{.Id}}"
2141 }
2142
2143 //TODO orderby
2144
2145 // Make sure json output prints an empty list, not "null"
2146 if imageStatus.DeviceImageStates == nil {
2147 imageStatus.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
2148 }
2149
2150 result := CommandResult{
2151 Format: format.Format(outputFormat),
2152 OutputAs: toOutputType(options.OutputAs),
2153 NameLimit: options.NameLimit,
2154 Data: imageStatus.DeviceImageStates,
2155 }
2156
2157 GenerateOutput(&result)
2158 return nil
2159
2160}
2161
Andrea Campanella791d88b2021-01-08 13:29:00 +01002162func (options *DeviceOnuListImages) Execute(args []string) error {
2163
2164 conn, err := NewConnection()
2165 if err != nil {
2166 return err
2167 }
2168 defer conn.Close()
2169
2170 client := voltha.NewVolthaServiceClient(conn)
2171
David K. Bainbridge9189c632021-03-26 21:52:21 +00002172 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Andrea Campanella791d88b2021-01-08 13:29:00 +01002173 defer cancel()
2174
2175 id := common.ID{Id: string(options.Args.Id)}
2176
2177 imageDownloads, err := client.ListImageDownloads(ctx, &id)
2178 if err != nil {
2179 return err
2180 }
2181
2182 outputFormat := CharReplacer.Replace(options.Format)
2183 if outputFormat == "" {
2184 outputFormat = GetCommandOptionWithDefault("device-image-list", "format", DEFAULT_DEVICE_IMAGE_LIST_GET_FORMAT)
2185 }
2186
2187 if options.Quiet {
2188 outputFormat = "{{.Id}}"
2189 }
2190
2191 //TODO orderby
2192
2193 // Make sure json output prints an empty list, not "null"
2194 if imageDownloads.Items == nil {
2195 imageDownloads.Items = make([]*voltha.ImageDownload, 0)
2196 }
2197
2198 result := CommandResult{
2199 Format: format.Format(outputFormat),
2200 OutputAs: toOutputType(options.OutputAs),
2201 NameLimit: options.NameLimit,
2202 Data: imageDownloads.Items,
2203 }
2204
2205 GenerateOutput(&result)
2206 return nil
2207
2208}
2209
2210func (options *DeviceOnuDownloadImage) Execute(args []string) error {
2211
2212 conn, err := NewConnection()
2213 if err != nil {
2214 return err
2215 }
2216 defer conn.Close()
2217
2218 client := voltha.NewVolthaServiceClient(conn)
2219
David K. Bainbridge9189c632021-03-26 21:52:21 +00002220 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Andrea Campanella791d88b2021-01-08 13:29:00 +01002221 defer cancel()
2222
2223 downloadImage := voltha.ImageDownload{
2224 Id: string(options.Args.Id),
2225 Name: options.Args.Name,
2226 Url: options.Args.Url,
2227 Crc: options.Args.Crc,
2228 LocalDir: options.Args.LocalDir,
2229 }
2230
2231 _, err = client.DownloadImage(ctx, &downloadImage)
2232 if err != nil {
2233 return err
2234 }
2235
2236 return nil
2237
2238}
2239
2240func (options *DeviceOnuActivateImageUpdate) Execute(args []string) error {
2241
2242 conn, err := NewConnection()
2243 if err != nil {
2244 return err
2245 }
2246 defer conn.Close()
2247
2248 client := voltha.NewVolthaServiceClient(conn)
2249
David K. Bainbridge9189c632021-03-26 21:52:21 +00002250 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Andrea Campanella791d88b2021-01-08 13:29:00 +01002251 defer cancel()
2252
2253 downloadImage := voltha.ImageDownload{
2254 Id: string(options.Args.Id),
2255 Name: options.Args.Name,
2256 ImageVersion: options.Args.ImageVersion,
2257 SaveConfig: options.Args.SaveConfig,
2258 LocalDir: options.Args.LocalDir,
2259 }
2260
2261 _, err = client.ActivateImageUpdate(ctx, &downloadImage)
2262 if err != nil {
2263 return err
2264 }
2265
2266 return nil
2267
2268}
2269
Scott Baker9173ed82020-05-19 08:30:12 -07002270type ReturnValueRow struct {
2271 Name string `json:"name"`
2272 Result interface{} `json:"result"`
2273}
2274
kesavand8ec4fc02021-01-27 09:10:22 -05002275func (options *DeviceGetPortStats) Execute(args []string) error {
2276 conn, err := NewConnection()
2277 if err != nil {
2278 return err
2279 }
2280 defer conn.Close()
2281 client := extension.NewExtensionClient(conn)
2282 var portType extension.GetOltPortCounters_PortType
2283
2284 if options.Args.PortType == "pon" {
2285 portType = extension.GetOltPortCounters_Port_PON_OLT
2286 } else if options.Args.PortType == "nni" {
2287
2288 portType = extension.GetOltPortCounters_Port_ETHERNET_NNI
2289 } else {
2290 return fmt.Errorf("expected interface type pon/nni, provided %s", options.Args.PortType)
2291 }
2292
2293 singleGetValReq := extension.SingleGetValueRequest{
2294 TargetId: string(options.Args.Id),
2295 Request: &extension.GetValueRequest{
2296 Request: &extension.GetValueRequest_OltPortInfo{
2297 OltPortInfo: &extension.GetOltPortCounters{
2298 PortNo: options.Args.PortNo,
2299 PortType: portType,
2300 },
2301 },
2302 },
2303 }
2304
David K. Bainbridge9189c632021-03-26 21:52:21 +00002305 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand8ec4fc02021-01-27 09:10:22 -05002306 defer cancel()
2307 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2308 if err != nil {
2309 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2310 return err
2311 }
2312
2313 if rv.Response.Status != extension.GetValueResponse_OK {
2314 return fmt.Errorf("failed to get port stats %v", rv.Response.ErrReason.String())
2315 }
2316
2317 outputFormat := CharReplacer.Replace(options.Format)
2318 if outputFormat == "" {
2319 outputFormat = GetCommandOptionWithDefault("device-get-port-status", "format", DEFAULT_DEVICE_GET_PORT_STATUS_FORMAT)
2320 }
2321
2322 result := CommandResult{
2323 Format: format.Format(outputFormat),
2324 OutputAs: toOutputType(options.OutputAs),
2325 NameLimit: options.NameLimit,
2326 Data: rv.GetResponse().GetPortCoutners(),
2327 }
2328 GenerateOutput(&result)
2329 return nil
2330}
2331
Himani Chawla40acc122021-05-26 18:52:29 +05302332func (options *GetOnuStats) Execute(args []string) error {
2333 conn, err := NewConnection()
2334 if err != nil {
2335 return err
2336 }
2337 defer conn.Close()
2338 client := extension.NewExtensionClient(conn)
2339
2340 singleGetValReq := extension.SingleGetValueRequest{
2341 TargetId: string(options.Args.OltId),
2342 Request: &extension.GetValueRequest{
2343 Request: &extension.GetValueRequest_OnuPonInfo{
2344 OnuPonInfo: &extension.GetOnuCountersRequest{
2345 IntfId: options.Args.IntfId,
2346 OnuId: options.Args.OnuId,
2347 },
2348 },
2349 },
2350 }
2351 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2352 defer cancel()
2353 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2354 if err != nil {
2355 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.OltId, ErrorToString(err))
2356 return err
2357 }
2358
2359 if rv.Response.Status != extension.GetValueResponse_OK {
2360 return fmt.Errorf("failed to get onu stats %v", rv.Response.ErrReason.String())
2361 }
2362 outputFormat := CharReplacer.Replace(options.Format)
2363 data, formatStr := buildOnuStatsOutputFormat(rv.GetResponse().GetOnuPonCounters())
2364 if outputFormat == "" {
2365 outputFormat = GetCommandOptionWithDefault("device-get-onu-status", "format", formatStr)
2366 }
Himani Chawla553a1392021-06-10 23:39:17 +05302367 result := CommandResult{
2368 Format: format.Format(outputFormat),
2369 OutputAs: toOutputType(options.OutputAs),
2370 NameLimit: options.NameLimit,
2371 Data: data,
2372 }
2373 GenerateOutput(&result)
2374 return nil
2375}
Himani Chawla40acc122021-05-26 18:52:29 +05302376
Akash Soni6e879c22024-12-20 17:01:34 +05302377func (options *GetOffloadApp) Execute(args []string) error {
Akash Soni51b6b7a2024-11-20 11:39:38 +05302378 // Establish a connection to the gRPC server
2379 conn, err := NewConnection()
2380 if err != nil {
2381 return err
2382 }
2383 defer conn.Close()
2384
2385 client := extension.NewExtensionClient(conn)
2386
2387 // Build the request
2388 singleGetValReq := &extension.SingleGetValueRequest{
2389 TargetId: string(options.Args.OltId),
2390 Request: &extension.GetValueRequest{
2391 Request: &extension.GetValueRequest_OffloadedAppsStats{
2392 OffloadedAppsStats: &extension.GetOffloadedAppsStatisticsRequest{
2393 StatsFor: options.Args.StatsFor,
2394 },
2395 },
2396 },
2397 }
2398
2399 // Set a context with timeout
2400 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2401 defer cancel()
2402
2403 // Perform the gRPC call
2404 rv, err := client.GetExtValue(ctx, singleGetValReq)
2405 if err != nil {
2406 Error.Printf("Error getting value for device ID %s, err=%s\n", options.Args.OltId, ErrorToString(err))
2407 return err
2408 }
2409
2410 // Check response status
2411 if rv.GetResponse().GetStatus() != extension.GetValueResponse_OK {
2412 return fmt.Errorf("failed to get offloaded app stats: %v", rv.GetResponse().GetErrReason().String())
2413 }
2414
2415 // Process the response data
2416 stats, formatStr := buildOffloadAppStatsOutputFormat(rv.GetResponse().GetOffloadedAppsStats())
balaji.nagarajan1f7c6392026-05-22 16:16:30 +05302417
2418 formatAdditionalStats(stats)
Akash Soni51b6b7a2024-11-20 11:39:38 +05302419 outputFormat := CharReplacer.Replace(options.Format)
2420 if outputFormat == "" {
2421 outputFormat = GetCommandOptionWithDefault("device-get-offload-app-stats", "format", formatStr)
2422 }
2423
2424 // Generate and display the output
2425 result := CommandResult{
2426 Format: format.Format(outputFormat),
2427 OutputAs: toOutputType(options.OutputAs),
2428 NameLimit: options.NameLimit,
2429 Data: stats,
2430 }
2431 GenerateOutput(&result)
2432
2433 return nil
2434}
2435
balaji.nagarajan1f7c6392026-05-22 16:16:30 +05302436func formatAdditionalStats(stats map[string]interface{}) {
2437 if v, ok := stats["additional_stats"]; ok {
2438 if m, ok := v.(map[string]interface{}); ok {
2439
2440 keys := make([]string, 0, len(m))
2441 for k := range m {
2442 keys = append(keys, k)
2443 }
2444
2445 sort.Strings(keys)
2446
2447 var b strings.Builder
2448
2449 for _, k := range keys {
2450 b.WriteString(fmt.Sprintf(
2451 " %-65s : %v\n",
2452 k,
2453 m[k],
2454 ))
2455 }
2456
2457 stats["additional_stats"] = b.String()
2458 }
2459 }
2460}
2461
Akash Soni6e879c22024-12-20 17:01:34 +05302462func (options *SetOffloadApp) Execute(args []string) error {
Akash Soni51b6b7a2024-11-20 11:39:38 +05302463 conn, err := NewConnection()
2464 if err != nil {
Akash Soni6e879c22024-12-20 17:01:34 +05302465 return fmt.Errorf("failed to establish gRPC connection: %w", err)
Akash Soni51b6b7a2024-11-20 11:39:38 +05302466 }
2467 defer conn.Close()
2468
2469 client := extension.NewExtensionClient(conn)
2470
Akash Soni6e879c22024-12-20 17:01:34 +05302471 // Parse JSON input
2472 var config extension.AppOffloadConfig
2473 if err := json.Unmarshal([]byte(options.Args.Config), &config); err != nil {
2474 return fmt.Errorf("failed to parse CONFIG as JSON: %w", err)
2475 }
2476
Akash Soni51b6b7a2024-11-20 11:39:38 +05302477 setValueRequest := &extension.SetValueRequest{
2478 Request: &extension.SetValueRequest_AppOffloadConfig{
Akash Soni6e879c22024-12-20 17:01:34 +05302479 AppOffloadConfig: &config,
Akash Soni51b6b7a2024-11-20 11:39:38 +05302480 },
2481 }
2482
2483 singleSetValReq := &extension.SingleSetValueRequest{
2484 TargetId: string(options.Args.OltId),
2485 Request: setValueRequest,
2486 }
2487
Akash Soni6e879c22024-12-20 17:01:34 +05302488 // Log the request object
2489 logRequestAppOffloadConfig(singleSetValReq)
2490
Akash Soni51b6b7a2024-11-20 11:39:38 +05302491 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2492 defer cancel()
2493
2494 resp, err := client.SetExtValue(ctx, singleSetValReq)
2495 if err != nil {
Akash Soni6e879c22024-12-20 17:01:34 +05302496 return fmt.Errorf("failed to set AppOffloadConfig: %w", err)
Akash Soni51b6b7a2024-11-20 11:39:38 +05302497 }
2498
2499 if resp.Response.Status != extension.SetValueResponse_OK {
Akash Soni6e879c22024-12-20 17:01:34 +05302500 return fmt.Errorf("operation failed with status %v: %s", resp.Response.Status, resp.Response.ErrReason)
Akash Soni51b6b7a2024-11-20 11:39:38 +05302501 }
2502
2503 fmt.Printf("AppOffloadConfig successfully set for OLT ID: %s\n", options.Args.OltId)
2504 return nil
2505}
2506
Akash Soni6e879c22024-12-20 17:01:34 +05302507func logRequestAppOffloadConfig(req *extension.SingleSetValueRequest) {
2508 fmt.Printf("Request details:\n")
2509 fmt.Printf("TargetId: %s\n", req.TargetId)
2510 if config, ok := req.Request.Request.(*extension.SetValueRequest_AppOffloadConfig); ok {
2511 fmt.Printf("AppOffloadConfig:\n")
2512 fmt.Printf(" EnableDHCPv4RA: %t\n", config.AppOffloadConfig.EnableDHCPv4RA)
2513 fmt.Printf(" EnableDHCPv6RA: %t\n", config.AppOffloadConfig.EnableDHCPv6RA)
2514 fmt.Printf(" EnablePPPoEIA: %t\n", config.AppOffloadConfig.EnablePPPoEIA)
2515 fmt.Printf(" AccessNodeID: %s\n", config.AppOffloadConfig.AccessNodeID)
2516 }
2517}
2518
2519func (options *SetOnuOffload) Execute(args []string) error {
2520 // Create the gRPC client connection
Akash Soni51b6b7a2024-11-20 11:39:38 +05302521 conn, err := NewConnection()
2522 if err != nil {
2523 return fmt.Errorf("failed to establish gRPC connection: %v", err)
2524 }
2525 defer conn.Close()
2526
2527 client := extension.NewExtensionClient(conn)
2528
Akash Soni6e879c22024-12-20 17:01:34 +05302529 // Parse PerUniInfo into a slice of PerUniConfig
2530 var perUniConfigs []AppOffloadOnuConfig
2531 if err := json.Unmarshal([]byte(options.Args.PerUniInfo), &perUniConfigs); err != nil {
2532 return fmt.Errorf("failed to parse PerUniInfo as JSON: %v", err)
Akash Soni51b6b7a2024-11-20 11:39:38 +05302533 }
Akash Soni6e879c22024-12-20 17:01:34 +05302534
2535 // Convert to []*AppOffloadOnuConfig_PerUniConfig for gRPC
2536 var grpcPerUniInfo []*extension.AppOffloadOnuConfig_PerUniConfig
2537 for _, config := range perUniConfigs {
2538 grpcPerUniInfo = append(grpcPerUniInfo, &extension.AppOffloadOnuConfig_PerUniConfig{
2539 AgentRemoteID: config.AgentRemoteID,
2540 AgentCircuitID: config.AgentCircuitID,
2541 OnuUniId: config.OnuUniId,
2542 })
2543 }
2544
Akash Soni51b6b7a2024-11-20 11:39:38 +05302545 // Build the AppOffloadOnuConfig request
2546 onuConfig := &extension.AppOffloadOnuConfig{
2547 OnuDeviceId: options.Args.OnuDeviceId,
Akash Soni6e879c22024-12-20 17:01:34 +05302548 PerUniInfo: grpcPerUniInfo,
Akash Soni51b6b7a2024-11-20 11:39:38 +05302549 }
2550
2551 setValueRequest := &extension.SetValueRequest{
2552 Request: &extension.SetValueRequest_AppOffloadOnuConfig{
2553 AppOffloadOnuConfig: onuConfig,
2554 },
2555 }
2556
2557 singleSetValReq := &extension.SingleSetValueRequest{
Akash Soni6e879c22024-12-20 17:01:34 +05302558 TargetId: string(options.Args.OltId),
Akash Soni51b6b7a2024-11-20 11:39:38 +05302559 Request: setValueRequest,
2560 }
2561
Akash Soni6e879c22024-12-20 17:01:34 +05302562 // Log the request object
2563 logRequestAppOffloadOnuConfig(singleSetValReq)
2564
2565 // Make the gRPC call
Akash Soni51b6b7a2024-11-20 11:39:38 +05302566 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2567 defer cancel()
2568
2569 resp, err := client.SetExtValue(ctx, singleSetValReq)
2570 if err != nil {
2571 return fmt.Errorf("failed to set AppOffloadOnuConfig: %v", err)
2572 }
2573
2574 if resp.Response.Status != extension.SetValueResponse_OK {
Akash Soni6e879c22024-12-20 17:01:34 +05302575 return fmt.Errorf("operation failed with status %v: %s", resp.Response.Status, resp.Response.ErrReason)
Akash Soni51b6b7a2024-11-20 11:39:38 +05302576 }
2577
2578 fmt.Printf("AppOffloadOnuConfig successfully set for ONU ID: %s\n", options.Args.OnuDeviceId)
2579 return nil
2580}
2581
Akash Soni6e879c22024-12-20 17:01:34 +05302582// Debugging helper to log the gRPC request details
2583func logRequestAppOffloadOnuConfig(req *extension.SingleSetValueRequest) {
2584 fmt.Printf("Request details:\n")
2585 fmt.Printf("TargetId: %s\n", req.TargetId)
2586 fmt.Printf("OnuDeviceId: %s\n", req.Request.GetAppOffloadOnuConfig().OnuDeviceId)
2587 if config, ok := req.Request.Request.(*extension.SetValueRequest_AppOffloadOnuConfig); ok {
2588 fmt.Printf("AppOffloadOnuConfig:\n")
2589 for i, uniInfo := range config.AppOffloadOnuConfig.PerUniInfo {
2590 fmt.Printf(" UniInfo %d:\n", i+1)
2591 fmt.Printf(" AgentRemoteID: %s\n", uniInfo.AgentRemoteID)
2592 fmt.Printf(" AgentCircuitID: %s\n", uniInfo.AgentCircuitID)
2593 fmt.Printf(" OnuUniId: %d\n", uniInfo.OnuUniId)
2594 }
2595 }
2596}
2597
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +05302598func (options *GetPonPortStats) Execute(args []string) error {
2599 conn, err := NewConnection()
2600 if err != nil {
2601 return err
2602 }
2603 defer conn.Close()
2604 client := extension.NewExtensionClient(conn)
2605
2606 singleGetValReq := extension.SingleGetValueRequest{
2607 TargetId: string(options.Args.Id),
2608 Request: &extension.GetValueRequest{
2609 Request: &extension.GetValueRequest_OltPonStats{
2610 OltPonStats: &extension.GetPonStatsRequest{
2611 PortInfo: &extension.GetPonStatsRequest_PortLabel{
2612 PortLabel: options.Args.PortLabel,
2613 },
2614 },
2615 },
2616 },
2617 }
2618 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2619 defer cancel()
2620 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2621 if err != nil {
2622 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2623 return err
2624 }
2625
2626 if rv.Response.Status != extension.GetValueResponse_OK {
2627 return fmt.Errorf("failed to get pon port stats %v", rv.Response.ErrReason.String())
2628 }
2629 outputFormat := CharReplacer.Replace(options.Format)
2630 if outputFormat == "" {
2631 outputFormat = GetCommandOptionWithDefault("device-get-pon-stats", "format", DEFAULT_PON_PORT_STATS_FORMAT)
2632 }
2633 data := PortStats{
2634 PonPort: rv.GetResponse().GetOltPonStatsResponse().GetPonPort(),
2635 PortStatistics: rv.GetResponse().GetOltPonStatsResponse().GetPortStatistics(),
2636 }
2637 result := CommandResult{
2638 Format: format.Format(outputFormat),
2639 OutputAs: toOutputType(options.OutputAs),
2640 NameLimit: options.NameLimit,
2641 Data: data,
2642 }
2643 GenerateOutput(&result)
2644 return nil
2645}
2646
2647func (options *GetNniPortStats) Execute(args []string) error {
2648 conn, err := NewConnection()
2649 if err != nil {
2650 return err
2651 }
2652 defer conn.Close()
2653 client := extension.NewExtensionClient(conn)
2654
2655 singleGetValReq := extension.SingleGetValueRequest{
2656 TargetId: string(options.Args.Id),
2657 Request: &extension.GetValueRequest{
2658 Request: &extension.GetValueRequest_OltNniStats{
2659 OltNniStats: &extension.GetNNIStatsRequest{
2660 PortInfo: &extension.GetNNIStatsRequest_PortLabel{
2661 PortLabel: options.Args.PortLabel,
2662 },
2663 },
2664 },
2665 },
2666 }
2667 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2668 defer cancel()
2669 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2670 if err != nil {
2671 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2672 return err
2673 }
2674
2675 if rv.Response.Status != extension.GetValueResponse_OK {
2676 return fmt.Errorf("failed to get nni port stats %v", rv.Response.ErrReason.String())
2677 }
2678 outputFormat := CharReplacer.Replace(options.Format)
2679 if outputFormat == "" {
2680 outputFormat = GetCommandOptionWithDefault("device-get-nni-stats", "format", DEFAULT_NNI_PORT_STATS_FORMAT)
2681 }
2682 data := PortStats{
2683 NniPort: rv.GetResponse().GetOltNniStatsResponse().GetNniPort(),
2684 PortStatistics: rv.GetResponse().GetOltNniStatsResponse().GetPortStatistics(),
2685 }
2686 result := CommandResult{
2687 Format: format.Format(outputFormat),
2688 OutputAs: toOutputType(options.OutputAs),
2689 NameLimit: options.NameLimit,
2690 Data: data,
2691 }
2692 GenerateOutput(&result)
2693 return nil
2694}
2695
Himani Chawla553a1392021-06-10 23:39:17 +05302696func (options *GetOnuEthernetFrameExtendedPmCounters) Execute(args []string) error {
2697 conn, err := NewConnection()
2698 if err != nil {
2699 return err
2700 }
2701 defer conn.Close()
2702 client := extension.NewExtensionClient(conn)
Himani Chawla806aa892021-08-30 15:51:46 +05302703 var singleGetValReq extension.SingleGetValueRequest
Himani Chawla553a1392021-06-10 23:39:17 +05302704
Himani Chawla806aa892021-08-30 15:51:46 +05302705 if options.Args.UniIndex != nil {
2706 singleGetValReq = extension.SingleGetValueRequest{
2707 TargetId: string(options.Args.Id),
2708 Request: &extension.GetValueRequest{
2709 Request: &extension.GetValueRequest_OnuInfo{
2710 OnuInfo: &extension.GetOmciEthernetFrameExtendedPmRequest{
2711 OnuDeviceId: string(options.Args.Id),
2712 Reset_: options.Reset,
2713 IsUniIndex: &extension.GetOmciEthernetFrameExtendedPmRequest_UniIndex{
2714 UniIndex: *options.Args.UniIndex,
2715 },
2716 },
Himani Chawla553a1392021-06-10 23:39:17 +05302717 },
2718 },
Himani Chawla806aa892021-08-30 15:51:46 +05302719 }
2720 } else {
2721 singleGetValReq = extension.SingleGetValueRequest{
2722 TargetId: string(options.Args.Id),
2723 Request: &extension.GetValueRequest{
2724 Request: &extension.GetValueRequest_OnuInfo{
2725 OnuInfo: &extension.GetOmciEthernetFrameExtendedPmRequest{
2726 OnuDeviceId: string(options.Args.Id),
2727 Reset_: options.Reset,
2728 },
2729 },
2730 },
2731 }
Himani Chawla553a1392021-06-10 23:39:17 +05302732 }
Himani Chawla806aa892021-08-30 15:51:46 +05302733
Himani Chawla553a1392021-06-10 23:39:17 +05302734 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2735 defer cancel()
2736 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2737 if err != nil {
2738 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2739 return err
2740 }
2741
2742 if rv.Response.Status != extension.GetValueResponse_OK {
2743 return fmt.Errorf("failed to get ethernet frame extended pm counters %v", rv.Response.ErrReason.String())
2744 }
2745 outputFormat := CharReplacer.Replace(options.Format)
2746 data := buildOnuEthernetFrameExtendedPmOutputFormat(rv.GetResponse().GetOnuCounters())
2747 if outputFormat == "" {
2748 outputFormat = GetCommandOptionWithDefault("device-get-onu-status", "format", DEFAULT_ETHERNET_FRAME_EXTENDED_PM_COUNTERS_FORMAT)
2749 }
Himani Chawla40acc122021-05-26 18:52:29 +05302750 result := CommandResult{
2751 Format: format.Format(outputFormat),
2752 OutputAs: toOutputType(options.OutputAs),
2753 NameLimit: options.NameLimit,
2754 Data: data,
2755 }
2756 GenerateOutput(&result)
2757 return nil
2758}
2759
kesavand6d1131f2021-02-05 22:38:15 +05302760func (options *UniStatus) Execute(args []string) error {
2761 conn, err := NewConnection()
2762 if err != nil {
2763 return err
2764 }
2765 defer conn.Close()
2766 client := extension.NewExtensionClient(conn)
2767
2768 singleGetValReq := extension.SingleGetValueRequest{
2769 TargetId: string(options.Args.Id),
2770 Request: &extension.GetValueRequest{
2771 Request: &extension.GetValueRequest_UniInfo{
2772 UniInfo: &extension.GetOnuUniInfoRequest{
2773 UniIndex: options.Args.UniIndex,
2774 },
2775 },
2776 },
2777 }
David K. Bainbridge9189c632021-03-26 21:52:21 +00002778 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand6d1131f2021-02-05 22:38:15 +05302779 defer cancel()
2780 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2781 if err != nil {
2782 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2783 return err
2784 }
2785 if rv.Response.Status != extension.GetValueResponse_OK {
2786 return fmt.Errorf("failed to get uni status %v", rv.Response.ErrReason.String())
2787 }
2788 outputFormat := CharReplacer.Replace(options.Format)
2789 if outputFormat == "" {
2790 outputFormat = GetCommandOptionWithDefault("device-get-uni-status", "format", DEFAULT_DEVICE_GET_UNI_STATUS_FORMAT)
2791 }
2792 result := CommandResult{
2793 Format: format.Format(outputFormat),
2794 OutputAs: toOutputType(options.OutputAs),
2795 NameLimit: options.NameLimit,
2796 Data: rv.GetResponse().GetUniInfo(),
2797 }
2798 GenerateOutput(&result)
2799 return nil
2800}
2801
Girish Gowdra4f5ce7c2021-04-29 18:53:21 -07002802func (options *OnuPonOpticalInfo) Execute(args []string) error {
2803 conn, err := NewConnection()
2804 if err != nil {
2805 return err
2806 }
2807 defer conn.Close()
2808 client := extension.NewExtensionClient(conn)
2809
2810 singleGetValReq := extension.SingleGetValueRequest{
2811 TargetId: string(options.Args.Id),
2812 Request: &extension.GetValueRequest{
2813 Request: &extension.GetValueRequest_OnuOpticalInfo{
2814 OnuOpticalInfo: &extension.GetOnuPonOpticalInfo{},
2815 },
2816 },
2817 }
2818 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2819 defer cancel()
2820 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2821 if err != nil {
2822 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2823 return err
2824 }
2825 if rv.Response.Status != extension.GetValueResponse_OK {
2826 return fmt.Errorf("failed to get onu pon optical info %v", rv.Response.ErrReason.String())
2827 }
2828 outputFormat := CharReplacer.Replace(options.Format)
2829 if outputFormat == "" {
2830 outputFormat = GetCommandOptionWithDefault("device-get-onu-pon-optical-info", "format", DEFAULT_ONU_PON_OPTICAL_INFO_STATUS_FORMAT)
2831 }
2832 result := CommandResult{
2833 Format: format.Format(outputFormat),
2834 OutputAs: toOutputType(options.OutputAs),
2835 NameLimit: options.NameLimit,
2836 Data: rv.GetResponse().GetOnuOpticalInfo(),
2837 }
2838 GenerateOutput(&result)
2839 return nil
2840}
2841
Gamze Abakac857a462021-05-26 13:45:54 +00002842func (options *RxPower) Execute(args []string) error {
2843 conn, err := NewConnection()
2844 if err != nil {
2845 return err
2846 }
2847 defer conn.Close()
2848 client := extension.NewExtensionClient(conn)
2849
2850 singleGetValReq := extension.SingleGetValueRequest{
2851 TargetId: string(options.Args.Id),
2852 Request: &extension.GetValueRequest{
2853 Request: &extension.GetValueRequest_RxPower{
2854 RxPower: &extension.GetRxPowerRequest{
2855 IntfId: options.Args.PortNo,
2856 OnuId: options.Args.OnuNo,
2857 },
2858 },
2859 },
2860 }
2861
2862 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2863 defer cancel()
2864 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2865 if err != nil {
2866 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2867 return err
2868 }
2869 if rv.Response.Status != extension.GetValueResponse_OK {
2870 return fmt.Errorf("failed to get rx power %v", rv.Response.ErrReason.String())
2871 }
2872 outputFormat := CharReplacer.Replace(options.Format)
2873 if outputFormat == "" {
2874 outputFormat = GetCommandOptionWithDefault("device-get-rx-power", "format", DEFAULT_RX_POWER_STATUS_FORMAT)
2875 }
2876 result := CommandResult{
2877 Format: format.Format(outputFormat),
2878 OutputAs: toOutputType(options.OutputAs),
2879 NameLimit: options.NameLimit,
2880 Data: rv.GetResponse().GetRxPower(),
2881 }
2882 GenerateOutput(&result)
2883 return nil
2884}
2885
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002886/*Device get Onu Distance */
2887func (options *DeviceGetExtValue) Execute(args []string) error {
2888 conn, err := NewConnection()
2889 if err != nil {
2890 return err
2891 }
2892 defer conn.Close()
2893
Scott Baker9173ed82020-05-19 08:30:12 -07002894 client := voltha.NewVolthaServiceClient(conn)
2895
khenaidoo080ce882021-10-19 17:35:08 -04002896 valueflag, okay := extension.ValueType_Type_value[string(options.Args.Valueflag)]
Scott Baker9173ed82020-05-19 08:30:12 -07002897 if !okay {
2898 Error.Printf("Unknown valueflag %s\n", options.Args.Valueflag)
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002899 }
2900
khenaidoo080ce882021-10-19 17:35:08 -04002901 val := extension.ValueSpecifier{Id: string(options.Args.Id), Value: extension.ValueType_Type(valueflag)}
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002902
David K. Bainbridge9189c632021-03-26 21:52:21 +00002903 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002904 defer cancel()
2905
Scott Baker9173ed82020-05-19 08:30:12 -07002906 rv, err := client.GetExtValue(ctx, &val)
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002907 if err != nil {
2908 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2909 return err
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002910 }
2911
Scott Baker9173ed82020-05-19 08:30:12 -07002912 var rows []ReturnValueRow
khenaidoo080ce882021-10-19 17:35:08 -04002913 for name, num := range extension.ValueType_Type_value {
Scott Baker9173ed82020-05-19 08:30:12 -07002914 if num == 0 {
2915 // EMPTY is not a real value
2916 continue
2917 }
2918 if (rv.Error & uint32(num)) != 0 {
2919 row := ReturnValueRow{Name: name, Result: "Error"}
2920 rows = append(rows, row)
2921 }
2922 if (rv.Unsupported & uint32(num)) != 0 {
2923 row := ReturnValueRow{Name: name, Result: "Unsupported"}
2924 rows = append(rows, row)
2925 }
2926 if (rv.Set & uint32(num)) != 0 {
2927 switch name {
2928 case "DISTANCE":
2929 row := ReturnValueRow{Name: name, Result: rv.Distance}
2930 rows = append(rows, row)
2931 default:
2932 row := ReturnValueRow{Name: name, Result: "Unimplemented-in-voltctl"}
2933 rows = append(rows, row)
2934 }
2935 }
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002936 }
2937
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002938 outputFormat := CharReplacer.Replace(options.Format)
2939 if outputFormat == "" {
2940 outputFormat = GetCommandOptionWithDefault("device-value-get", "format", DEFAULT_DEVICE_VALUE_GET_FORMAT)
2941 }
2942
2943 result := CommandResult{
2944 Format: format.Format(outputFormat),
2945 OutputAs: toOutputType(options.OutputAs),
2946 NameLimit: options.NameLimit,
Scott Baker9173ed82020-05-19 08:30:12 -07002947 Data: rows,
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002948 }
2949 GenerateOutput(&result)
2950 return nil
2951}
serkantul3d22fc72022-09-14 12:22:56 +03002952
2953/*Device get Onu OMCI TX RX Stats */
2954func (options *OnuOmciTxRxStats) Execute(args []string) error {
2955 conn, err := NewConnection()
2956 if err != nil {
2957 return err
2958 }
2959 defer conn.Close()
2960 client := extension.NewExtensionClient(conn)
2961
2962 singleGetValReq := extension.SingleGetValueRequest{
2963 TargetId: string(options.Args.Id),
2964 Request: &extension.GetValueRequest{
2965 Request: &extension.GetValueRequest_OnuOmciStats{
2966 OnuOmciStats: &extension.GetOnuOmciTxRxStatsRequest{},
2967 },
2968 },
2969 }
2970
2971 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2972 defer cancel()
2973 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2974 if err != nil {
2975 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2976 return err
2977 }
2978
2979 if rv.Response.Status != extension.GetValueResponse_OK {
2980 return fmt.Errorf("failed to get onu omci tx rx stats %v", rv.Response.ErrReason.String())
2981 }
2982 outputFormat := CharReplacer.Replace(options.Format)
2983 if outputFormat == "" {
2984 outputFormat = GetCommandOptionWithDefault("device-get-onu-omci-tx-rx-stats", "format", DEFAULT_ONU_OMCI_TX_RX_STATS_FORMAT)
2985 }
2986 result := CommandResult{
2987 Format: format.Format(outputFormat),
2988 OutputAs: toOutputType(options.OutputAs),
2989 NameLimit: options.NameLimit,
2990 Data: rv.GetResponse().GetOnuOmciStats(),
2991 }
2992 GenerateOutput(&result)
2993 return nil
2994}
praneeth nalmas1dd094c2022-12-22 14:15:13 +05302995
2996/*Device get Onu Active Alarms */
2997func (options *GetOnuOmciActiveAlarms) Execute(args []string) error {
2998 conn, err := NewConnection()
2999 if err != nil {
3000 return err
3001 }
3002 defer conn.Close()
3003 client := extension.NewExtensionClient(conn)
3004
3005 singleGetValReq := extension.SingleGetValueRequest{
3006 TargetId: string(options.Args.Id),
3007 Request: &extension.GetValueRequest{
3008 Request: &extension.GetValueRequest_OnuActiveAlarms{
3009 OnuActiveAlarms: &extension.GetOnuOmciActiveAlarmsRequest{},
3010 },
3011 },
3012 }
3013 Info.Printf("Getting omci_active_alarms for device Id %s\n", options.Args.Id)
3014 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3015 defer cancel()
3016 rv, err := client.GetExtValue(ctx, &singleGetValReq)
3017 if err != nil {
3018 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
3019 return err
3020 }
3021
3022 if rv.Response.Status != extension.GetValueResponse_OK {
3023 return fmt.Errorf("failed to get onu omci active alarms list %v", rv.Response.ErrReason.String())
3024 }
3025 outputFormat := CharReplacer.Replace(options.Format)
3026 if outputFormat == "" {
3027 outputFormat = GetCommandOptionWithDefault("device-get-onu-omci-active-alarms", "format", DEFAULT_DEVICE_ALARMS_FORMAT)
3028 }
3029
3030 orderBy := options.OrderBy
3031 if orderBy == "" {
3032 orderBy = GetCommandOptionWithDefault("device-list", "order", DEFAULT_DEVICE_ALARMS_ORDER)
3033 }
3034
3035 result := CommandResult{
3036 Format: format.Format(outputFormat),
3037 OutputAs: toOutputType(options.OutputAs),
3038 OrderBy: orderBy,
3039 NameLimit: options.NameLimit,
3040 Data: rv.GetResponse().GetOnuActiveAlarms().GetActiveAlarms(),
3041 }
3042 GenerateOutput(&result)
3043 return nil
3044}
praneeth nalmas39c71ad2023-09-27 18:29:04 +05303045
Akash Soni66db9632024-04-15 09:05:15 +05303046/*Device get Onu Active Alarms */
3047func (options *GetOnuDistance) Execute(args []string) error {
3048 conn, err := NewConnection()
3049 if err != nil {
3050 return err
3051 }
3052 defer conn.Close()
3053 client := extension.NewExtensionClient(conn)
3054
3055 singleGetValReq := extension.SingleGetValueRequest{
3056 TargetId: string(options.Args.Id),
3057 Request: &extension.GetValueRequest{
3058 Request: &extension.GetValueRequest_Distance{
3059 Distance: &extension.GetDistanceRequest{
3060 OnuDeviceId: string(options.Args.OnuId),
3061 },
3062 },
3063 },
3064 }
3065 Info.Printf("Getting onu distance for device Id %s\n", options.Args.Id)
3066 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3067 defer cancel()
3068 rv, err := client.GetExtValue(ctx, &singleGetValReq)
3069 if err != nil {
3070 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
3071 return err
3072 }
3073
3074 if rv.Response.Status != extension.GetValueResponse_OK {
3075 return fmt.Errorf("failed to get onu distance stats %v", rv.Response.ErrReason.String())
3076 }
3077 outputFormat := CharReplacer.Replace(options.Format)
3078 if outputFormat == "" {
3079 outputFormat = GetCommandOptionWithDefault("get-onu-distance", "format", DEFAULT_ONU_DISTANCE_FORMAT)
3080 }
3081
3082 result := CommandResult{
3083 Format: format.Format(outputFormat),
3084 OutputAs: toOutputType(options.OutputAs),
3085 NameLimit: options.NameLimit,
3086 Data: rv.GetResponse().GetDistance().GetDistance(),
3087 }
3088 fmt.Println("onu distance : ", rv)
3089 GenerateOutput(&result)
3090 return nil
3091}
3092
praneeth nalmas39c71ad2023-09-27 18:29:04 +05303093func (options *PonRxPower) Execute(args []string) error {
3094 conn, err := NewConnection()
3095 if err != nil {
3096 return err
3097 }
3098 defer conn.Close()
3099 client := extension.NewExtensionClient(conn)
3100
3101 singleGetValReq := extension.SingleGetValueRequest{
3102 TargetId: string(options.Args.Id),
3103 Request: &extension.GetValueRequest{
3104 Request: &extension.GetValueRequest_OltRxPower{
3105 OltRxPower: &extension.GetOltRxPowerRequest{
3106 PortLabel: options.Args.PortLabel,
3107 OnuSn: options.Args.SerialNo,
3108 },
3109 },
3110 },
3111 }
3112
3113 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3114 defer cancel()
3115 rv, err := client.GetExtValue(ctx, &singleGetValReq)
3116 if err != nil {
3117 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
3118 return err
3119 }
3120 if rv.Response.Status != extension.GetValueResponse_OK {
3121 return fmt.Errorf("failed to get rx power %v", rv.Response.ErrReason.String())
3122 }
3123 outputFormat := CharReplacer.Replace(options.Format)
3124 if outputFormat == "" {
3125 outputFormat = GetCommandOptionWithDefault("device-get-pon-rx-power", "format", DEFAULT_PON_RX_POWER_STATUS_FORMAT)
3126 }
3127 result := CommandResult{
3128 Format: format.Format(outputFormat),
3129 OutputAs: toOutputType(options.OutputAs),
3130 NameLimit: options.NameLimit,
3131 Data: rv.GetResponse().GetOltRxPower().GetRxPower(),
3132 }
3133 GenerateOutput(&result)
3134 return nil
3135}
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +05303136
3137func (options *GetOnuGEMStats) Execute(args []string) error {
3138
3139 conn, err := NewConnection()
3140 if err != nil {
3141 return err
3142 }
3143 defer conn.Close()
3144 client := extension.NewExtensionClient(conn)
3145 singleGetValReq := extension.SingleGetValueRequest{
3146 TargetId: string(options.Args.Id),
3147 Request: &extension.GetValueRequest{
3148 Request: &extension.GetValueRequest_OnuAllocGemStats{
3149 OnuAllocGemStats: &extension.GetOnuAllocGemHistoryRequest{},
3150 },
3151 },
3152 }
3153
3154 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3155 defer cancel()
3156
3157 rv, err := client.GetExtValue(ctx, &singleGetValReq)
3158
3159 if err != nil {
3160 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
3161 return err
3162 }
3163
3164 if rv.Response.Status != extension.GetValueResponse_OK {
3165 return fmt.Errorf("failed to get gem port response %v", rv.Response.ErrReason.String())
3166 }
3167 outputFormat := CharReplacer.Replace(options.Format)
3168 if outputFormat == "" {
3169 outputFormat = GetCommandOptionWithDefault("device-get-gem-port", "format", DEFAULT_DEVICE_VALUE_GEM_PORT_FORMAT)
3170 }
3171 onugemhistoryresponse := rv.GetResponse().GetOnuAllocGemStatsResponse()
3172 for _, OnuallocGemHistoryData := range onugemhistoryresponse.OnuAllocGemHistoryData {
3173 data := onugemstats{}
3174 data.AllocId = OnuallocGemHistoryData.OnuAllocIdInfo.AllocId
3175 data.AllocRxBytes = OnuallocGemHistoryData.OnuAllocIdInfo.RxBytes
3176 for _, gemStatsInfo := range OnuallocGemHistoryData.GemPortInfo {
3177 data.GemHistoryStats = append(data.GemHistoryStats, gemHistoryStats{
3178 GemId: gemStatsInfo.GemId,
3179 TransmittedGEMFrames: gemStatsInfo.TransmittedGEMFrames,
3180 ReceivedGEMFrames: gemStatsInfo.ReceivedGEMFrames,
Akash Reddy Kankanalaeba72f62026-01-29 12:49:17 +00003181 ReceivedPayloadBytes: gemStatsInfo.ReceivedPayloadBytes_64,
3182 TransmittedPayloadBytes: gemStatsInfo.TransmittedPayloadBytes_64,
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +05303183 EncryptionKeyErrors: gemStatsInfo.EncryptionKeyErrors,
3184 })
3185 }
3186 result := CommandResult{
3187 Format: format.Format(outputFormat),
3188 OutputAs: toOutputType(options.OutputAs),
3189 NameLimit: options.NameLimit,
3190 Data: &data,
3191 }
3192 GenerateOutput(&result)
3193 }
3194 return nil
3195
3196}
3197
Akash Reddy Kankanala6965c652025-10-15 23:30:16 +05303198func (options *GetOnuFecHistory) Execute(args []string) error {
3199 conn, err := NewConnection()
3200 if err != nil {
3201 return err
3202 }
3203 defer conn.Close()
3204 client := extension.NewExtensionClient(conn)
3205 singleGetValReq := extension.SingleGetValueRequest{
3206 TargetId: string(options.Args.Id),
3207 Request: &extension.GetValueRequest{
3208 Request: &extension.GetValueRequest_FecHistory{
3209 FecHistory: &extension.GetOnuFecHistory{},
3210 },
3211 },
3212 }
3213 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3214 defer cancel()
3215 rv, err := client.GetExtValue(ctx, &singleGetValReq)
3216 if err != nil {
3217 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
3218 return err
3219 }
3220 if rv.Response.Status != extension.GetValueResponse_OK {
3221 return fmt.Errorf("Failed to get onu FEC history stats from ONT %v", rv.Response.ErrReason.String())
3222 }
3223
3224 outputFormat := CharReplacer.Replace(options.Format)
3225 if outputFormat == "" {
3226 outputFormat = GetCommandOptionWithDefault("device-get-onu-fec-History", "format", DEFAULT_ONU_FEC_HISTORY_FORMAT)
3227 }
3228 result := CommandResult{
3229 Format: format.Format(outputFormat),
3230 OutputAs: toOutputType(options.OutputAs),
3231 NameLimit: options.NameLimit,
3232 Data: rv.GetResponse().GetFecHistory(),
3233 }
3234 GenerateOutput(&result)
3235 return nil
3236
3237}
3238
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +05303239func (options *GetOnuAllocGemStatsFromOlt) Execute(args []string) error {
3240 conn, err := NewConnection()
3241 if err != nil {
3242 return err
3243 }
3244 defer conn.Close()
3245 client := extension.NewExtensionClient(conn)
3246
3247 singleGetValReq := extension.SingleGetValueRequest{
3248 TargetId: string(options.Args.Id),
3249 Request: &extension.GetValueRequest{
3250 Request: &extension.GetValueRequest_OnuStatsFromOlt{
3251 OnuStatsFromOlt: &extension.GetOnuStatsFromOltRequest{},
3252 },
3253 },
3254 }
3255 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3256 defer cancel()
3257 rv, err := client.GetExtValue(ctx, &singleGetValReq)
3258 if err != nil {
3259 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
3260 return err
3261 }
3262
3263 if rv.Response.Status != extension.GetValueResponse_OK {
3264 return fmt.Errorf("failed to get onu alloc gem stats from olt %v", rv.Response.ErrReason.String())
3265 }
3266 outputFormat := CharReplacer.Replace(options.Format)
3267 if outputFormat == "" {
3268 outputFormat = GetCommandOptionWithDefault("device-get-onu-status", "format", DEFAULT_ONU_STATS_FROM_OLT_FORMAT)
3269 }
3270
3271 onuAllocGemStatsResponse := rv.GetResponse().GetOnuStatsFromOltResponse()
3272
3273 for _, allocGemStatsInfo := range onuAllocGemStatsResponse.AllocGemStatsInfo {
3274 data := AllocGemStatsFromOlt{}
3275 data.AllocId = allocGemStatsInfo.AllocIdInfo.AllocId
3276 data.AllocRxBytes = allocGemStatsInfo.AllocIdInfo.RxBytes
3277 for _, gemStatsInfo := range allocGemStatsInfo.GemPortInfo {
3278 data.GemPortStats = append(data.GemPortStats, GemPortStatsFromOlt{
3279 GemId: gemStatsInfo.GemId,
3280 RxBytes: gemStatsInfo.RxBytes,
3281 RxPackets: gemStatsInfo.RxPackets,
3282 TxBytes: gemStatsInfo.TxBytes,
3283 TxPackets: gemStatsInfo.TxPackets,
3284 })
3285 }
3286 result := CommandResult{
3287 Format: format.Format(outputFormat),
3288 OutputAs: toOutputType(options.OutputAs),
3289 NameLimit: options.NameLimit,
3290 Data: &data,
3291 }
3292 GenerateOutput(&result)
3293 }
3294
3295 return nil
3296}
mgouda35b90e62025-07-16 14:58:29 +05303297
3298func (options *DisableOnuDevice) Execute(args []string) error {
3299 conn, err := NewConnection()
3300 if err != nil {
3301 return err
3302 }
3303 defer conn.Close()
3304
3305 client := voltha.NewVolthaServiceClient(conn)
3306
3307 var lastErr error
3308 for _, i := range options.Args.Ids {
3309 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3310 defer cancel()
3311
3312 id := voltha.ID{Id: string(i)}
3313
3314 _, err := client.DisableOnuDevice(ctx, &id)
3315 if err != nil {
3316 Error.Printf("Error while disabling the onu serial number'%s': %s\n", i, err)
3317 lastErr = err
3318 continue
3319 }
3320 fmt.Printf("%s\n", i)
3321 }
3322
3323 if lastErr != nil {
3324 return NoReportErr
3325 }
3326 return nil
3327}
3328
3329func (options *EnableOnuDevice) Execute(args []string) error {
3330 conn, err := NewConnection()
3331 if err != nil {
3332 return err
3333 }
3334 defer conn.Close()
3335
3336 client := voltha.NewVolthaServiceClient(conn)
3337
3338 var lastErr error
3339 for _, i := range options.Args.Ids {
3340 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3341 defer cancel()
3342
3343 id := voltha.ID{Id: string(i)}
3344
3345 _, err := client.EnableOnuDevice(ctx, &id)
3346 if err != nil {
3347 Error.Printf("Error while enabling the onu serial number'%s': %s\n", i, err)
3348 lastErr = err
3349 continue
3350 }
3351 fmt.Printf("%s\n", i)
3352 }
3353
3354 if lastErr != nil {
3355 return NoReportErr
3356 }
3357 return nil
3358}
3359
3360func (options *DisableOnuSerialNumber) Execute(args []string) error {
3361 conn, err := NewConnection()
3362 if err != nil {
3363 return err
3364 }
3365 defer conn.Close()
3366
3367 client := voltha.NewVolthaServiceClient(conn)
3368
3369 id := common.ID{Id: string(options.Args.OltDeviceId)}
3370 port := voltha.Port{PortNo: uint32(options.Args.Port)}
3371
3372 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3373 defer cancel()
3374
3375 req := &voltha.OnuSerialNumberOnOLTPon{
3376 OltDeviceId: &id,
3377 SerialNumber: options.Args.SerialNumber,
3378 Port: &port,
3379 }
3380
3381 _, err = client.DisableOnuSerialNumber(ctx, req)
3382 if err != nil {
3383 Error.Printf("Error disabling ONU serial '%s' on OLT '%s': %v\n", options.Args.SerialNumber, options.Args.OltDeviceId, err)
3384 return err
3385 }
3386 fmt.Printf("Disabled ONU serial '%s' on OLT '%s'\n", options.Args.SerialNumber, options.Args.OltDeviceId)
3387 return nil
3388}
3389
3390func (options *EnableOnuSerialNumber) Execute(args []string) error {
3391 conn, err := NewConnection()
3392 if err != nil {
3393 return err
3394 }
3395 defer conn.Close()
3396
3397 client := voltha.NewVolthaServiceClient(conn)
3398
3399 id := common.ID{Id: string(options.Args.OltDeviceId)}
3400 port := voltha.Port{PortNo: uint32(options.Args.Port)}
3401
3402 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3403 defer cancel()
3404
3405 req := &voltha.OnuSerialNumberOnOLTPon{
3406 OltDeviceId: &id,
3407 SerialNumber: options.Args.SerialNumber,
3408 Port: &port,
3409 }
3410
3411 _, err = client.EnableOnuSerialNumber(ctx, req)
3412 if err != nil {
3413 Error.Printf("Error enabling ONU serial '%s' on OLT '%s': %v\n", options.Args.SerialNumber, options.Args.OltDeviceId, err)
3414 return err
3415 }
3416 fmt.Printf("Enabled ONU serial '%s' on OLT '%s'\n", options.Args.SerialNumber, options.Args.OltDeviceId)
3417 return nil
3418}