blob: 91b1d5971cb831cde35c82976f30f4f741a14b57 [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"
23 "strconv"
24 "strings"
Girish Gowdra610acb42021-01-27 13:33:57 -080025 "time"
David Bainbridge7052fe82020-03-25 10:37:00 -070026
Scott Baker9173ed82020-05-19 08:30:12 -070027 "github.com/golang/protobuf/ptypes/empty"
Zack Williamse940c7a2019-08-21 14:25:39 -070028 flags "github.com/jessevdk/go-flags"
Scott Baker2b0ad652019-08-21 14:57:07 -070029 "github.com/opencord/voltctl/pkg/format"
David K. Bainbridgebd6b2882021-08-26 13:31:02 +000030 "github.com/opencord/voltha-protos/v5/go/common"
31 "github.com/opencord/voltha-protos/v5/go/extension"
32 "github.com/opencord/voltha-protos/v5/go/voltha"
Zack Williamse940c7a2019-08-21 14:25:39 -070033)
34
35const (
David K. Bainbridge89003c42020-02-27 17:22:49 -080036 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 +000037 DEFAULT_DEVICE_ORDER = "Type,Id"
Zack Williamse940c7a2019-08-21 14:25:39 -070038 DEFAULT_DEVICE_PORTS_FORMAT = "table{{.PortNo}}\t{{.Label}}\t{{.Type}}\t{{.AdminState}}\t{{.OperStatus}}\t{{.DeviceId}}\t{{.Peers}}"
39 DEFAULT_DEVICE_INSPECT_FORMAT = `ID: {{.Id}}
40 TYPE: {{.Type}}
41 ROOT: {{.Root}}
42 PARENTID: {{.ParentId}}
43 SERIALNUMBER: {{.SerialNumber}}
44 VLAN: {{.Vlan}}
45 ADMINSTATE: {{.AdminState}}
46 OPERSTATUS: {{.OperStatus}}
47 CONNECTSTATUS: {{.ConnectStatus}}`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +000048 DEFAULT_DEVICE_PM_CONFIG_GET_FORMAT = "table{{.DefaultFreq}}\t{{.Grouped}}\t{{.FreqOverride}}"
49 DEFAULT_DEVICE_PM_CONFIG_METRIC_LIST_FORMAT = "table{{.Name}}\t{{.Type}}\t{{.Enabled}}\t{{.SampleFreq}}"
50 DEFAULT_DEVICE_PM_CONFIG_GROUP_LIST_FORMAT = "table{{.GroupName}}\t{{.Enabled}}\t{{.GroupFreq}}"
51 DEFAULT_DEVICE_VALUE_GET_FORMAT = "table{{.Name}}\t{{.Result}}"
Andrea Campanella791d88b2021-01-08 13:29:00 +010052 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 +053053 ONU_IMAGE_LIST_FORMAT = "table{{.Version}}\t{{.IsCommited}}\t{{.IsActive}}\t{{.IsValid}}\t{{.ProductCode}}\t{{.Hash}}"
54 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 -050055 DEFAULT_DEVICE_GET_PORT_STATUS_FORMAT = `
56 TXBYTES: {{.TxBytes}}
57 TXPACKETS: {{.TxPackets}}
58 TXERRPACKETS: {{.TxErrorPackets}}
59 TXBCASTPACKETS: {{.TxBcastPackets}}
60 TXUCASTPACKETS: {{.TxUcastPackets}}
61 TXMCASTPACKETS: {{.TxMcastPackets}}
62 RXBYTES: {{.RxBytes}}
63 RXPACKETS: {{.RxPackets}}
64 RXERRPACKETS: {{.RxErrorPackets}}
65 RXBCASTPACKETS: {{.RxBcastPackets}}
66 RXUCASTPACKETS: {{.RxUcastPackets}}
67 RXMCASTPACKETS: {{.RxMcastPackets}}`
kesavand6d1131f2021-02-05 22:38:15 +053068 DEFAULT_DEVICE_GET_UNI_STATUS_FORMAT = `
69 ADMIN_STATE: {{.AdmState}}
70 OPERATIONAL_STATE: {{.OperState}}
71 CONFIG_IND: {{.ConfigInd}}`
Girish Gowdra4f5ce7c2021-04-29 18:53:21 -070072 DEFAULT_ONU_PON_OPTICAL_INFO_STATUS_FORMAT = `
73 POWER_FEED_VOLTAGE__VOLTS: {{.PowerFeedVoltage}}
74 RECEIVED_OPTICAL_POWER__dBm: {{.ReceivedOpticalPower}}
75 MEAN_OPTICAL_LAUNCH_POWER__dBm: {{.MeanOpticalLaunchPower}}
76 LASER_BIAS_CURRENT__mA: {{.LaserBiasCurrent}}
77 TEMPERATURE__Celsius: {{.Temperature}}`
Gamze Abakac857a462021-05-26 13:45:54 +000078 DEFAULT_RX_POWER_STATUS_FORMAT = `
79 INTF_ID: {{.IntfId}}
80 ONU_ID: {{.OnuId}}
81 STATUS: {{.Status}}
82 FAIL_REASON: {{.FailReason}}
83 RX_POWER : {{.RxPower}}`
Himani Chawla553a1392021-06-10 23:39:17 +053084 DEFAULT_ETHERNET_FRAME_EXTENDED_PM_COUNTERS_FORMAT = `Upstream_Drop_Events: {{.UDropEvents}}
85Upstream_Octets: {{.UOctets}}
86UFrames: {{.UFrames}}
87UBroadcastFrames: {{.UBroadcastFrames}}
88UMulticastFrames: {{.UMulticastFrames}}
89UCrcErroredFrames: {{.UCrcErroredFrames}}
90UUndersizeFrames: {{.UUndersizeFrames}}
91UOversizeFrames: {{.UOversizeFrames}}
92UFrames_64Octets: {{.UFrames_64Octets}}
93UFrames_65To_127Octets: {{.UFrames_65To_127Octets}}
94UFrames_128To_255Octets: {{.UFrames_128To_255Octets}}
95UFrames_256To_511Octets: {{.UFrames_256To_511Octets}}
96UFrames_512To_1023Octets: {{.UFrames_512To_1023Octets}}
97UFrames_1024To_1518Octets: {{.UFrames_1024To_1518Octets}}
98DDropEvents: {{.DDropEvents}}
99DOctets: {{.DOctets}}
100DFrames: {{.DFrames}}
101DBroadcastFrames: {{.DBroadcastFrames}}
102DMulticastFrames: {{.DMulticastFrames}}
103DCrcErroredFrames: {{.DCrcErroredFrames}}
104DUndersizeFrames: {{.DUndersizeFrames}}
105DOversizeFrames: {{.DOversizeFrames}}
106DFrames_64Octets: {{.DFrames_64Octets}}
107DFrames_65To_127Octets: {{.DFrames_65To_127Octets}}
108DFrames_128To_255Octets: {{.DFrames_128To_255Octets}}
109DFrames_256To_511Octets: {{.DFrames_256To_511Octets}}
110DFrames_512To_1023Octets: {{.DFrames_512To_1023Octets}}
Himani Chawlabac0f892021-08-25 17:14:06 +0530111DFrames_1024To_1518Octets: {{.DFrames_1024To_1518Octets}}
112PmFormat: {{.PmFormat}}`
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +0530113 DEFAULT_PON_PORT_STATS_FORMAT = `Pon Port: {{.PonPort}}
114Bip Units: {{.BipUnits}}
115Bip Errors: {{.BipErrors}}
116RxPackets: {{.RxPackets}}
117RxGem: {{.RxGem}}
118RxGemDropped: {{.RxGemDropped}}
119RxGemIdle: {{.RxGemIdle}}
120RxGemCorrected: {{.RxGemCorrected}}
121RxGemIllegal: {{.RxGemIllegal}}
122RxCrcError: {{.RxCrcErrors}}
123RxFragmentError: {{.RxFragmentError}}
124RxPacketsDropped: {{.RxPacketsDropped}}
125RxCpuOmciPacketsDropped: {{.RxCpuOmciPacketsDropped}}
126RxCpu: {{.RxCpu}}
127RxOmci: {{.RxOmci}}
128RxOmciPacketsCrcError: {{.RxOmciPacketsCrcError}}
129TxPackets: {{.TxPackets}}
130TxGem: {{.TxGem}}
131TxCpu: {{.TxCpu}}
132TxOmci: {{.TxOmci}}
133TxDroppedIllegalLength: {{.TxDroppedIllegalLength}}
134TxDroppedTpidMiss: {{.TxDroppedTpidMiss}}
135TxDroppedVidMiss: {{.TxDroppedVidMiss}}
136TxDroppedTotal: {{.TxDroppedTotal}}`
137 DEFAULT_NNI_PORT_STATS_FORMAT = `Nni Port: {{.NniPort}}
138RxBytes: {{.RxBytes}}
Akash Reddy Kankanalaeba72f62026-01-29 12:49:17 +0000139RxFrames: {{.RxFrames}}
140RxUcastFrames: {{.RxUcastFrames}}
141RxMcastFrames: {{.RxMcastFrames}}
142RxBcastFrames: {{.RxBcastFrames}}
143RxErrorFrames: {{.RxErrorFrames}}
144RxFcsErrorPackets: {{.RxFcsErrorPackets}}
145RxUndersizePackets: {{.RxUndersizePackets}}
146RxOversizePackets: {{.RxOversizePackets}}
147TxBytes: {{.TxBytes}}
148TxFrames: {{.TxFrames}}
149TxUcastFrames: {{.TxUcastFrames}}
150TxMcastFrames: {{.TxMcastFrames}}
151TxBcastFrames: {{.TxBcastFrames}}
152TxErrorFrames: {{.TxErrorFrames}}
153TxUndersizePackets: {{.TxUndersizePackets}}
154TxOversizePackets: {{.TxOversizePackets}}
155
156# Deprecated packet counters to be removed in future releases
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +0530157RxPackets: {{.RxPackets}}
158RxUcastPackets: {{.RxUcastPackets}}
159RxMcastPackets: {{.RxMcastPackets}}
160RxBcastPackets: {{.RxBcastPackets}}
161RxErrorPackets: {{.RxErrorPackets}}
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +0530162TxPackets: {{.TxPackets}}
163TxUcastPackets: {{.TxUcastPackets}}
164TxMcastPackets: {{.TxMcastPackets}}
165TxBcastPackets: {{.TxBcastPackets}}
Akash Reddy Kankanalaeba72f62026-01-29 12:49:17 +0000166TxErrorPackets: {{.TxErrorPackets}}`
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +0530167
serkantul3d22fc72022-09-14 12:22:56 +0300168 DEFAULT_ONU_OMCI_TX_RX_STATS_FORMAT = `BaseTxArFrames: {{.BaseTxArFrames}}
169BaseRxAkFrames: {{.BaseRxAkFrames}}
170BaseTxNoArFrames: {{.BaseTxNoArFrames}}
171BaseRxNoAkFrames: {{.BaseRxNoAkFrames}}
172ExtTxArFrames: {{.ExtTxArFrames}}
173ExtRxAkFrames: {{.ExtRxAkFrames}}
174ExtTxNoArFrames: {{.ExtTxNoArFrames}}
175ExtRxNoAkFrames: {{.ExtRxNoAkFrames}}
176TxOmciCounterRetries: {{.TxOmciCounterRetries}}
177TxOmciCounterTimeouts: {{.TxOmciCounterTimeouts}}`
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +0530178 DEFAULT_ONU_STATS_FROM_OLT_FORMAT = `AllocId: {{.AllocId}}
179AllocRxBytes: {{.AllocRxBytes}}
180{{range .GemPortStats}}
181-GemId: {{.GemId}}
182 RxPackets: {{.RxPackets}}
183 RxBytes: {{.RxBytes}}
184 TxPackets: {{.TxPackets}}
185 TxBytes: {{.TxBytes}}{{end}}`
Akash Reddy Kankanala6965c652025-10-15 23:30:16 +0530186 DEFAULT_ONU_FEC_HISTORY_FORMAT = `CorrectedBytes: {{.CorrectedBytes}}
187CorrectedCodeWords: {{.CorrectedCodeWords}}
188FecSeconds: {{.FecSeconds}}
189TotalCodeWords: {{.TotalCodeWords}}
190UncorrectableCodeWords: {{.UncorrectableCodeWords}}`
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +0530191
192 DEFAULT_ONU_DISTANCE_FORMAT = `Distance`
193 DEFAULT_DEVICE_ALARMS_FORMAT = "table{{ .ClassId }}\t{{.InstanceId}}\t{{.Name}}\t{{.Description}}"
194 DEFAULT_DEVICE_ALARMS_ORDER = "ClassId,InstanceId"
195 DEFAULT_PON_RX_POWER_STATUS_FORMAT = "table{{.OnuSn}}\t{{.Status}}\t{{.FailReason}}\t{{.RxPower}}\t"
196 DEFAULT_DEVICE_VALUE_GEM_PORT_FORMAT = `AllocId: {{.AllocId}}
197 AllocRxBytes: {{.AllocRxBytes}}
198 {{range .GemHistoryStats}}
199-GemId: {{.GemId}}
200 TransmittedGEMFrames: {{.TransmittedGEMFrames}}
201 ReceivedGEMFrames: {{.ReceivedGEMFrames}}
202 ReceivedPayloadBytes: {{.ReceivedPayloadBytes}}
203 TransmittedPayloadBytes:{{.TransmittedPayloadBytes}}
204 EncryptionKeyErrors: {{.EncryptionKeyErrors}}{{end}}`
Zack Williamse940c7a2019-08-21 14:25:39 -0700205)
206
207type DeviceList struct {
208 ListOutputOptions
209}
210
211type DeviceCreate struct {
David Bainbridge1a514392020-06-23 11:12:51 -0700212 DeviceType string `short:"t" required:"true" long:"devicetype" description:"Device type"`
David Bainbridge835dd0e2020-04-01 10:30:09 -0700213 MACAddress string `short:"m" long:"macaddress" default:"" description:"MAC Address"`
Zack Williamse940c7a2019-08-21 14:25:39 -0700214 IPAddress string `short:"i" long:"ipaddress" default:"" description:"IP Address"`
215 HostAndPort string `short:"H" long:"hostandport" default:"" description:"Host and port"`
216}
217
218type DeviceId string
Akash Soni66db9632024-04-15 09:05:15 +0530219type OnuId string
Zack Williamse940c7a2019-08-21 14:25:39 -0700220
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000221type MetricName string
222type GroupName string
kesavand12cd8eb2020-01-20 22:25:22 -0500223type PortNum uint32
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -0800224type ValueFlag string
kesavand12cd8eb2020-01-20 22:25:22 -0500225
Zack Williamse940c7a2019-08-21 14:25:39 -0700226type DeviceDelete struct {
Himani Chawla9933ddc2020-10-12 23:53:27 +0530227 Force bool `long:"force" description:"Delete device forcefully"`
228 Args struct {
Zack Williamse940c7a2019-08-21 14:25:39 -0700229 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
230 } `positional-args:"yes"`
231}
232
233type DeviceEnable struct {
234 Args struct {
235 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
236 } `positional-args:"yes"`
237}
238
239type DeviceDisable struct {
240 Args struct {
241 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
242 } `positional-args:"yes"`
243}
244
245type DeviceReboot struct {
246 Args struct {
247 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
248 } `positional-args:"yes"`
249}
250
251type DeviceFlowList struct {
252 ListOutputOptions
Maninder045921e2020-09-29 16:46:02 +0530253 FlowIdOptions
Zack Williamse940c7a2019-08-21 14:25:39 -0700254 Args struct {
255 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
256 } `positional-args:"yes"`
257}
258
Himani Chawla3c161c62021-05-13 16:36:51 +0530259type DeviceFlowGroupList struct {
260 ListOutputOptions
261 GroupListOptions
262 Args struct {
263 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
264 } `positional-args:"yes"`
265}
Zack Williamse940c7a2019-08-21 14:25:39 -0700266type DevicePortList struct {
267 ListOutputOptions
268 Args struct {
269 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
270 } `positional-args:"yes"`
271}
272
273type DeviceInspect struct {
274 OutputOptionsJson
275 Args struct {
276 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
277 } `positional-args:"yes"`
278}
279
kesavand12cd8eb2020-01-20 22:25:22 -0500280type DevicePortEnable struct {
281 Args struct {
282 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
283 PortId PortNum `positional-arg-name:"PORT_NUMBER" required:"yes"`
284 } `positional-args:"yes"`
285}
286
287type DevicePortDisable struct {
288 Args struct {
289 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
290 PortId PortNum `positional-arg-name:"PORT_NUMBER" required:"yes"`
291 } `positional-args:"yes"`
292}
293
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000294type DevicePmConfigsGet struct {
295 ListOutputOptions
296 Args struct {
297 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
298 } `positional-args:"yes"`
299}
300
301type DevicePmConfigMetricList struct {
302 ListOutputOptions
303 Args struct {
304 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
305 } `positional-args:"yes"`
306}
307
308type DevicePmConfigGroupList struct {
309 ListOutputOptions
310 Args struct {
311 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
312 } `positional-args:"yes"`
313}
314
315type DevicePmConfigGroupMetricList struct {
316 ListOutputOptions
317 Args struct {
318 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
319 Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"`
320 } `positional-args:"yes"`
321}
322
323type DevicePmConfigFrequencySet struct {
324 OutputOptions
325 Args struct {
Girish Gowdra610acb42021-01-27 13:33:57 -0800326 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
327 Interval time.Duration `positional-arg-name:"INTERVAL" required:"yes"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000328 } `positional-args:"yes"`
329}
330
331type DevicePmConfigMetricEnable struct {
332 Args struct {
333 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
334 Metrics []MetricName `positional-arg-name:"METRIC_NAME" required:"yes"`
335 } `positional-args:"yes"`
336}
337
338type DevicePmConfigMetricDisable struct {
339 Args struct {
340 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
341 Metrics []MetricName `positional-arg-name:"METRIC_NAME" required:"yes"`
342 } `positional-args:"yes"`
343}
344
345type DevicePmConfigGroupEnable struct {
346 Args struct {
Girish Gowdra610acb42021-01-27 13:33:57 -0800347 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
348 Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000349 } `positional-args:"yes"`
350}
351
352type DevicePmConfigGroupDisable struct {
353 Args struct {
Girish Gowdra610acb42021-01-27 13:33:57 -0800354 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
355 Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"`
356 } `positional-args:"yes"`
357}
358
359type DevicePmConfigGroupFrequencySet struct {
360 OutputOptions
361 Args struct {
362 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
363 Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"`
364 Interval time.Duration `positional-arg-name:"INTERVAL" required:"yes"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000365 } `positional-args:"yes"`
366}
367
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -0800368type DeviceGetExtValue struct {
369 ListOutputOptions
370 Args struct {
371 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
372 Valueflag ValueFlag `positional-arg-name:"VALUE_FLAG" required:"yes"`
373 } `positional-args:"yes"`
374}
Rohan Agrawald7df3772020-06-29 11:23:36 +0000375
376type DevicePmConfigSetMaxSkew struct {
377 Args struct {
378 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
379 MaxSkew uint32 `positional-arg-name:"MAX_SKEW" required:"yes"`
380 } `positional-args:"yes"`
381}
382
Andrea Campanella791d88b2021-01-08 13:29:00 +0100383type DeviceOnuListImages struct {
384 ListOutputOptions
385 Args struct {
386 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
387 } `positional-args:"yes"`
388}
389
390type DeviceOnuDownloadImage struct {
391 Args struct {
392 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
393 Name string `positional-arg-name:"IMAGE_NAME" required:"yes"`
394 Url string `positional-arg-name:"IMAGE_URL" required:"yes"`
395 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
396 Crc uint32 `positional-arg-name:"IMAGE_CRC" required:"yes"`
397 LocalDir string `positional-arg-name:"IMAGE_LOCAL_DIRECTORY"`
398 } `positional-args:"yes"`
399}
400
401type DeviceOnuActivateImageUpdate struct {
402 Args struct {
403 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
404 Name string `positional-arg-name:"IMAGE_NAME" required:"yes"`
405 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
406 SaveConfig bool `positional-arg-name:"SAVE_EXISTING_CONFIG"`
407 LocalDir string `positional-arg-name:"IMAGE_LOCAL_DIRECTORY"`
Andrea Campanella7b2ecf42021-02-25 12:27:15 +0100408 } `positional-args:"yes"`
kesavand8ec4fc02021-01-27 09:10:22 -0500409}
kesavand3e2f9f62021-04-22 11:06:38 +0530410
411type OnuDownloadImage struct {
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +0200412 ListOutputOptions
kesavand3e2f9f62021-04-22 11:06:38 +0530413 Args struct {
414 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
415 Url string `positional-arg-name:"IMAGE_URL" required:"yes"`
ssiddiqui7bc89e92021-05-20 20:58:02 +0530416 Vendor string `positional-arg-name:"IMAGE_VENDOR"`
kesavand3e2f9f62021-04-22 11:06:38 +0530417 ActivateOnSuccess bool `positional-arg-name:"IMAGE_ACTIVATE_ON_SUCCESS"`
418 CommitOnSuccess bool `positional-arg-name:"IMAGE_COMMIT_ON_SUCCESS"`
419 Crc uint32 `positional-arg-name:"IMAGE_CRC"`
420 IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
421 } `positional-args:"yes"`
422}
423
424type OnuActivateImage struct {
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +0200425 ListOutputOptions
kesavand3e2f9f62021-04-22 11:06:38 +0530426 Args struct {
427 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
428 CommitOnSuccess bool `positional-arg-name:"IMAGE_COMMIT_ON_SUCCESS"`
429 IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
430 } `positional-args:"yes"`
431}
432
433type OnuAbortUpgradeImage struct {
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +0200434 ListOutputOptions
kesavand3e2f9f62021-04-22 11:06:38 +0530435 Args struct {
436 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
437 IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
438 } `positional-args:"yes"`
439}
440
441type OnuCommitImage struct {
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +0200442 ListOutputOptions
kesavand3e2f9f62021-04-22 11:06:38 +0530443 Args struct {
444 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
445 IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
446 } `positional-args:"yes"`
447}
448
449type OnuImageStatus struct {
450 ListOutputOptions
451 Args struct {
452 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
Elia Battiston859f3e62022-02-08 15:57:52 +0100453 IDs []DeviceId `positional-arg-name:"DEVICE_ID"`
kesavand3e2f9f62021-04-22 11:06:38 +0530454 } `positional-args:"yes"`
455}
456
457type OnuListImages struct {
458 ListOutputOptions
459 Args struct {
460 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
461 } `positional-args:"yes"`
462}
463
kesavand8ec4fc02021-01-27 09:10:22 -0500464type DeviceGetPortStats struct {
465 ListOutputOptions
466 Args struct {
467 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
468 PortNo uint32 `positional-arg-name:"PORT_NO" required:"yes"`
469 PortType string `positional-arg-name:"PORT_TYPE" required:"yes"`
Andrea Campanella791d88b2021-01-08 13:29:00 +0100470 } `positional-args:"yes"`
471}
kesavand6d1131f2021-02-05 22:38:15 +0530472type UniStatus struct {
473 ListOutputOptions
474 Args struct {
475 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
476 UniIndex uint32 `positional-arg-name:"UNI_INDEX" required:"yes"`
477 } `positional-args:"yes"`
478}
Girish Gowdra4f5ce7c2021-04-29 18:53:21 -0700479type OnuPonOpticalInfo struct {
480 ListOutputOptions
481 Args struct {
482 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
483 } `positional-args:"yes"`
484}
Himani Chawla40acc122021-05-26 18:52:29 +0530485
486type GetOnuStats struct {
487 ListOutputOptions
488 Args struct {
489 OltId DeviceId `positional-arg-name:"OLT_DEVICE_ID" required:"yes"`
490 IntfId uint32 `positional-arg-name:"PON_INTF_ID" required:"yes"`
491 OnuId uint32 `positional-arg-name:"ONU_ID" required:"yes"`
492 } `positional-args:"yes"`
493}
494
Akash Soni6e879c22024-12-20 17:01:34 +0530495type GetOffloadApp struct {
Akash Soni51b6b7a2024-11-20 11:39:38 +0530496 ListOutputOptions
497 Args struct {
498 OltId DeviceId `positional-arg-name:"OLT_DEVICE_ID" required:"yes"`
499 StatsFor extension.GetOffloadedAppsStatisticsRequest_OffloadedApp `positional-arg-name:"OFFLOADED_APP" required:"yes"`
500 } `positional-args:"yes"`
501}
502
Akash Soni6e879c22024-12-20 17:01:34 +0530503type SetOffloadApp struct {
504 ListOutputOptions
Akash Soni51b6b7a2024-11-20 11:39:38 +0530505 Args struct {
Akash Soni6e879c22024-12-20 17:01:34 +0530506 OltId DeviceId `positional-arg-name:"OLT_DEVICE_ID" required:"yes"`
507 Config string `positional-arg-name:"CONFIG" required:"yes"` // Accept JSON or CSV input
Akash Soni51b6b7a2024-11-20 11:39:38 +0530508 } `positional-args:"yes"`
509}
510
Akash Soni6e879c22024-12-20 17:01:34 +0530511type AppOffloadOnuConfig struct {
512 AgentRemoteID string
513 AgentCircuitID string
514 OnuUniId uint32
515}
516
517type SetOnuOffload struct {
518 ListOutputOptions
Akash Soni51b6b7a2024-11-20 11:39:38 +0530519 Args struct {
Akash Soni6e879c22024-12-20 17:01:34 +0530520 OltId DeviceId `positional-arg-name:"OLT_DEVICE_ID" required:"yes"`
521 OnuDeviceId string `positional-arg-name:"ONU_DEVICE_ID" required:"yes"`
522 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 +0530523 } `positional-args:"yes"`
524}
525
Himani Chawla553a1392021-06-10 23:39:17 +0530526type GetOnuEthernetFrameExtendedPmCounters struct {
527 ListOutputOptions
Himani Chawla806aa892021-08-30 15:51:46 +0530528 Reset bool `long:"reset" description:"Reset the counters"`
529 Args struct {
530 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
531 UniIndex *uint32 `positional-arg-name:"UNI_INDEX"`
Himani Chawla553a1392021-06-10 23:39:17 +0530532 } `positional-args:"yes"`
533}
534
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +0530535type GetPonPortStats struct {
536 ListOutputOptions
537 Reset bool `long:"reset" description:"Reset the counters"`
538 Args struct {
539 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
540 PortLabel string `positional-arg-name:"PORT_LABEL" required:"yes"`
541 } `positional-args:"yes"`
542}
543
544type GetNniPortStats struct {
545 ListOutputOptions
546 Reset bool `long:"reset" description:"Reset the counters"`
547 Args struct {
548 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
549 PortLabel string `positional-arg-name:"PORT_LABEL" required:"yes"`
550 } `positional-args:"yes"`
551}
552
553type GetOnuAllocGemStatsFromOlt struct {
554 ListOutputOptions
555 Args struct {
556 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
557 } `positional-args:"yes"`
558}
Gamze Abakac857a462021-05-26 13:45:54 +0000559type RxPower struct {
560 ListOutputOptions
561 Args struct {
562 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
563 PortNo uint32 `positional-arg-name:"PORT_NO" required:"yes"`
564 OnuNo uint32 `positional-arg-name:"ONU_NO" required:"yes"`
565 } `positional-args:"yes"`
566}
567
praneeth nalmas39c71ad2023-09-27 18:29:04 +0530568type PonRxPower struct {
569 ListOutputOptions
570 Args struct {
571 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
572 PortLabel string `positional-arg-name:"PORT_LABEL" required:"yes"`
573 SerialNo string `positional-arg-name:"ONU_SERIAL_NUMBER"`
574 } `positional-args:"yes"`
575}
576
serkantul3d22fc72022-09-14 12:22:56 +0300577type OnuOmciTxRxStats struct {
578 ListOutputOptions
579 Args struct {
580 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
581 } `positional-args:"yes"`
582}
583
praneeth nalmas1dd094c2022-12-22 14:15:13 +0530584type GetOnuOmciActiveAlarms struct {
585 ListOutputOptions
586 Args struct {
587 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
588 } `positional-args:"yes"`
589}
590
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +0530591type GetOnuGEMStats struct {
592 ListOutputOptions
593 Args struct {
594 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
595 } `positional-args:"yes"`
596}
597
Akash Reddy Kankanala6965c652025-10-15 23:30:16 +0530598type GetOnuFecHistory struct {
599 ListOutputOptions
600 Args struct {
601 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
602 } `positional-args:"yes"`
603}
Akash Soni66db9632024-04-15 09:05:15 +0530604type GetOnuDistance struct {
605 ListOutputOptions
606 Args struct {
607 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
608 OnuId OnuId `positional-arg-name:"ONU_ID" required:"yes"`
609 } `positional-args:"yes"` //onu device id
610}
611
mgouda35b90e62025-07-16 14:58:29 +0530612type DisableOnuDevice struct {
613 Args struct {
614 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
615 } `positional-args:"yes"`
616}
617
618type EnableOnuDevice struct {
619 Args struct {
620 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
621 } `positional-args:"yes"`
622}
623
624type DisableOnuSerialNumber struct {
625 Args struct {
626 SerialNumber string `positional-arg-name:"ONU_SERIAL_NUMBER" required:"yes"`
627 Port PortNum `positional-arg-name:"PORT_NO" required:"yes"`
628 OltDeviceId DeviceId `positional-arg-name:"OLT_DEVICE_ID" required:"yes"`
629 } `positional-args:"yes"`
630}
631
632type EnableOnuSerialNumber struct {
633 Args struct {
634 SerialNumber string `positional-arg-name:"ONU_SERIAL_NUMBER" required:"yes"`
635 Port PortNum `positional-arg-name:"PORT_NO" required:"yes"`
636 OltDeviceId DeviceId `positional-arg-name:"OLT_DEVICE_ID" required:"yes"`
637 } `positional-args:"yes"`
638}
639
Zack Williamse940c7a2019-08-21 14:25:39 -0700640type DeviceOpts struct {
mgouda35b90e62025-07-16 14:58:29 +0530641 List DeviceList `command:"list"`
642 Create DeviceCreate `command:"create"`
643 Delete DeviceDelete `command:"delete"`
644 Enable DeviceEnable `command:"enable"`
645 Disable DeviceDisable `command:"disable"`
646 DisableOnuDevice DisableOnuDevice `command:"disable_onu"`
647 EnableOnuDevice EnableOnuDevice `command:"enable_onu"`
648 DisableOnuSerialNumber DisableOnuSerialNumber `command:"disable_onu_serial"`
649 EnableOnuSerialNumber EnableOnuSerialNumber `command:"enable_onu_serial"`
650 Flows DeviceFlowList `command:"flows"`
651 Groups DeviceFlowGroupList `command:"groups"`
652 Port struct {
kesavand12cd8eb2020-01-20 22:25:22 -0500653 List DevicePortList `command:"list"`
654 Enable DevicePortEnable `command:"enable"`
655 Disable DevicePortDisable `command:"disable"`
656 } `command:"port"`
657 Inspect DeviceInspect `command:"inspect"`
658 Reboot DeviceReboot `command:"reboot"`
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -0800659 Value struct {
660 Get DeviceGetExtValue `command:"get"`
661 } `command:"value"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000662 PmConfig struct {
Rohan Agrawald7df3772020-06-29 11:23:36 +0000663 Get DevicePmConfigsGet `command:"get"`
664 MaxSkew struct {
665 Set DevicePmConfigSetMaxSkew `command:"set"`
666 } `command:"maxskew"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000667 Frequency struct {
668 Set DevicePmConfigFrequencySet `command:"set"`
669 } `command:"frequency"`
670 Metric struct {
671 List DevicePmConfigMetricList `command:"list"`
672 Enable DevicePmConfigMetricEnable `command:"enable"`
673 Disable DevicePmConfigMetricDisable `command:"disable"`
674 } `command:"metric"`
675 Group struct {
Girish Gowdra610acb42021-01-27 13:33:57 -0800676 List DevicePmConfigGroupList `command:"list"`
677 Enable DevicePmConfigGroupEnable `command:"enable"`
678 Disable DevicePmConfigGroupDisable `command:"disable"`
679 Set DevicePmConfigGroupFrequencySet `command:"set"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000680 } `command:"group"`
681 GroupMetric struct {
682 List DevicePmConfigGroupMetricList `command:"list"`
683 } `command:"groupmetric"`
684 } `command:"pmconfig"`
Andrea Campanella791d88b2021-01-08 13:29:00 +0100685 Image struct {
686 Get DeviceOnuListImages `command:"list"`
687 Download DeviceOnuDownloadImage `command:"download"`
688 Activate DeviceOnuActivateImageUpdate `command:"activate"`
689 } `command:"image"`
kesavand3e2f9f62021-04-22 11:06:38 +0530690 DownloadImage struct {
691 Download OnuDownloadImage `command:"download"`
692 Activate OnuActivateImage `command:"activate"`
693 Commit OnuCommitImage `command:"commit"`
694 AbortUpgrade OnuAbortUpgradeImage `command:"abort"`
695 Status OnuImageStatus `command:"status"`
696 List OnuListImages `command:"list" `
697 } `command:"onuimage"`
kesavand8ec4fc02021-01-27 09:10:22 -0500698 GetExtVal struct {
Himani Chawla553a1392021-06-10 23:39:17 +0530699 Stats DeviceGetPortStats `command:"portstats"`
700 UniStatus UniStatus `command:"unistatus"`
701 OpticalInfo OnuPonOpticalInfo `command:"onu_pon_optical_info"`
702 OnuStats GetOnuStats `command:"onu_stats"`
703 EthernetFrameExtendedPm GetOnuEthernetFrameExtendedPmCounters `command:"ethernet_frame_extended_pm"`
704 RxPower RxPower `command:"rxpower"`
serkantul3d22fc72022-09-14 12:22:56 +0300705 OnuOmciStats OnuOmciTxRxStats `command:"onu_omci_stats"`
praneeth nalmas1dd094c2022-12-22 14:15:13 +0530706 OnuOmciActiveAlarms GetOnuOmciActiveAlarms `command:"onu_omci_active_alarms"`
praneeth nalmas39c71ad2023-09-27 18:29:04 +0530707 PonRxPower PonRxPower `command:"pon_rx_power"`
Akash Soni66db9632024-04-15 09:05:15 +0530708 OnuDistance GetOnuDistance `command:"onu_distance"`
Akash Soni6e879c22024-12-20 17:01:34 +0530709 OffloadAppStats GetOffloadApp `command:"offload_app_stats"`
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +0530710 PonStats GetPonPortStats `command:"itu_pon_stats"`
711 NniStats GetNniPortStats `command:"nni_statistics"`
712 OnuGEMStats GetOnuGEMStats `command:"onu_gem_stats"`
713 OnuAllocGemStats GetOnuAllocGemStatsFromOlt `command:"onu_alloc_gem_from_olt"`
Akash Reddy Kankanala6965c652025-10-15 23:30:16 +0530714 OnuFecHistory GetOnuFecHistory `command:"onu_fec_history"`
kesavand8ec4fc02021-01-27 09:10:22 -0500715 } `command:"getextval"`
Akash Soni51b6b7a2024-11-20 11:39:38 +0530716 SetExtVal struct {
Akash Soni6e879c22024-12-20 17:01:34 +0530717 OffloadAppStatsSet SetOffloadApp `command:"set_offload_app"`
718 OnuOffloadStatsSet SetOnuOffload `command:"set_onu_offload"`
Akash Soni51b6b7a2024-11-20 11:39:38 +0530719 } `command:"setextval"`
Zack Williamse940c7a2019-08-21 14:25:39 -0700720}
721
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +0530722type AllocGemStatsFromOlt struct {
723 AllocId uint32
724 AllocRxBytes uint64
725 GemPortStats []GemPortStatsFromOlt
726}
727type GemPortStatsFromOlt struct {
728 GemId uint32
729 RxPackets uint64
730 RxBytes uint64
731 TxPackets uint64
732 TxBytes uint64
733}
734type onugemstats struct {
735 AllocId uint32
736 AllocRxBytes uint32
737 GemHistoryStats []gemHistoryStats
738}
739type gemHistoryStats struct {
740 GemId uint32
741 TransmittedGEMFrames uint32
742 ReceivedGEMFrames uint32
Akash Reddy Kankanalaeba72f62026-01-29 12:49:17 +0000743 ReceivedPayloadBytes uint64
744 TransmittedPayloadBytes uint64
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +0530745 EncryptionKeyErrors uint32
746}
747
748type PortStats struct {
749 PonPort uint32 // use this for PON
750 NniPort uint32 // use this for NNI
751 *common.PortStatistics
752}
753
Zack Williamse940c7a2019-08-21 14:25:39 -0700754var deviceOpts = DeviceOpts{}
755
756func RegisterDeviceCommands(parser *flags.Parser) {
David Bainbridge12f036f2019-10-15 22:09:04 +0000757 if _, err := parser.AddCommand("device", "device commands", "Commands to query and manipulate VOLTHA devices", &deviceOpts); err != nil {
David Bainbridgea6722342019-10-24 23:55:53 +0000758 Error.Fatalf("Unexpected error while attempting to register device commands : %s", err)
David Bainbridge12f036f2019-10-15 22:09:04 +0000759 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700760}
761
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000762func (i *MetricName) Complete(match string) []flags.Completion {
763 conn, err := NewConnection()
764 if err != nil {
765 return nil
766 }
767 defer conn.Close()
768
769 client := voltha.NewVolthaServiceClient(conn)
770
771 var deviceId string
772found:
773 for i := len(os.Args) - 1; i >= 0; i -= 1 {
774 switch os.Args[i] {
775 case "enable":
776 fallthrough
777 case "disable":
778 if len(os.Args) > i+1 {
779 deviceId = os.Args[i+1]
780 } else {
781 return nil
782 }
783 break found
784 default:
785 }
786 }
787
788 if len(deviceId) == 0 {
789 return nil
790 }
791
David K. Bainbridge9189c632021-03-26 21:52:21 +0000792 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000793 defer cancel()
794
795 id := voltha.ID{Id: string(deviceId)}
796
797 pmconfigs, err := client.ListDevicePmConfigs(ctx, &id)
798
799 if err != nil {
800 return nil
801 }
802
803 list := make([]flags.Completion, 0)
804 for _, metrics := range pmconfigs.Metrics {
805 if strings.HasPrefix(metrics.Name, match) {
806 list = append(list, flags.Completion{Item: metrics.Name})
807 }
808 }
809
810 return list
811}
812
813func (i *GroupName) Complete(match string) []flags.Completion {
814 conn, err := NewConnection()
815 if err != nil {
816 return nil
817 }
818 defer conn.Close()
819
820 client := voltha.NewVolthaServiceClient(conn)
821
822 var deviceId string
823found:
824 for i := len(os.Args) - 1; i >= 0; i -= 1 {
825 switch os.Args[i] {
826 case "list":
827 fallthrough
828 case "enable":
829 fallthrough
830 case "disable":
831 if len(os.Args) > i+1 {
832 deviceId = os.Args[i+1]
833 } else {
834 return nil
835 }
836 break found
837 default:
838 }
839 }
840
841 if len(deviceId) == 0 {
842 return nil
843 }
844
David K. Bainbridge9189c632021-03-26 21:52:21 +0000845 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000846 defer cancel()
847
848 id := voltha.ID{Id: string(deviceId)}
849
850 pmconfigs, err := client.ListDevicePmConfigs(ctx, &id)
851
852 if err != nil {
853 return nil
854 }
855
856 list := make([]flags.Completion, 0)
857 for _, group := range pmconfigs.Groups {
858 if strings.HasPrefix(group.GroupName, match) {
859 list = append(list, flags.Completion{Item: group.GroupName})
860 }
861 }
862 return list
863}
864
kesavand12cd8eb2020-01-20 22:25:22 -0500865func (i *PortNum) Complete(match string) []flags.Completion {
866 conn, err := NewConnection()
867 if err != nil {
868 return nil
869 }
870 defer conn.Close()
871
Scott Baker9173ed82020-05-19 08:30:12 -0700872 client := voltha.NewVolthaServiceClient(conn)
kesavand12cd8eb2020-01-20 22:25:22 -0500873
874 /*
875 * The command line args when completing for PortNum will be a DeviceId
876 * followed by one or more PortNums. So walk the argument list from the
877 * end and find the first argument that is enable/disable as those are
878 * the subcommands that come before the positional arguments. It would
879 * be nice if this package gave us the list of optional arguments
880 * already parsed.
881 */
882 var deviceId string
883found:
884 for i := len(os.Args) - 1; i >= 0; i -= 1 {
885 switch os.Args[i] {
886 case "enable":
887 fallthrough
888 case "disable":
889 if len(os.Args) > i+1 {
890 deviceId = os.Args[i+1]
891 } else {
892 return nil
893 }
894 break found
895 default:
896 }
897 }
898
899 if len(deviceId) == 0 {
900 return nil
901 }
902
David K. Bainbridge9189c632021-03-26 21:52:21 +0000903 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand12cd8eb2020-01-20 22:25:22 -0500904 defer cancel()
kesavand12cd8eb2020-01-20 22:25:22 -0500905
Scott Baker9173ed82020-05-19 08:30:12 -0700906 id := voltha.ID{Id: string(deviceId)}
kesavand12cd8eb2020-01-20 22:25:22 -0500907
Scott Baker9173ed82020-05-19 08:30:12 -0700908 ports, err := client.ListDevicePorts(ctx, &id)
kesavand12cd8eb2020-01-20 22:25:22 -0500909 if err != nil {
910 return nil
911 }
912
913 list := make([]flags.Completion, 0)
Scott Baker9173ed82020-05-19 08:30:12 -0700914 for _, item := range ports.Items {
915 pn := strconv.FormatUint(uint64(item.PortNo), 10)
kesavand12cd8eb2020-01-20 22:25:22 -0500916 if strings.HasPrefix(pn, match) {
917 list = append(list, flags.Completion{Item: pn})
918 }
919 }
920
921 return list
922}
923
Zack Williamse940c7a2019-08-21 14:25:39 -0700924func (i *DeviceId) Complete(match string) []flags.Completion {
925 conn, err := NewConnection()
926 if err != nil {
927 return nil
928 }
929 defer conn.Close()
930
Scott Baker9173ed82020-05-19 08:30:12 -0700931 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700932
David K. Bainbridge9189c632021-03-26 21:52:21 +0000933 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700934 defer cancel()
935
Scott Baker9173ed82020-05-19 08:30:12 -0700936 devices, err := client.ListDevices(ctx, &empty.Empty{})
Zack Williamse940c7a2019-08-21 14:25:39 -0700937 if err != nil {
938 return nil
939 }
940
941 list := make([]flags.Completion, 0)
Scott Baker9173ed82020-05-19 08:30:12 -0700942 for _, item := range devices.Items {
943 if strings.HasPrefix(item.Id, match) {
944 list = append(list, flags.Completion{Item: item.Id})
Zack Williamse940c7a2019-08-21 14:25:39 -0700945 }
946 }
947
948 return list
949}
950
951func (options *DeviceList) Execute(args []string) error {
952
953 conn, err := NewConnection()
954 if err != nil {
955 return err
956 }
957 defer conn.Close()
958
Scott Baker9173ed82020-05-19 08:30:12 -0700959 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700960
David K. Bainbridge9189c632021-03-26 21:52:21 +0000961 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700962 defer cancel()
963
Scott Baker9173ed82020-05-19 08:30:12 -0700964 devices, err := client.ListDevices(ctx, &empty.Empty{})
Zack Williamse940c7a2019-08-21 14:25:39 -0700965 if err != nil {
966 return err
967 }
968
969 outputFormat := CharReplacer.Replace(options.Format)
970 if outputFormat == "" {
David Bainbridgea6722342019-10-24 23:55:53 +0000971 outputFormat = GetCommandOptionWithDefault("device-list", "format", DEFAULT_DEVICE_FORMAT)
Zack Williamse940c7a2019-08-21 14:25:39 -0700972 }
973 if options.Quiet {
974 outputFormat = "{{.Id}}"
975 }
976
David Bainbridgea6722342019-10-24 23:55:53 +0000977 orderBy := options.OrderBy
978 if orderBy == "" {
Hardik Windlass9361bb82022-03-23 05:58:48 +0000979 orderBy = GetCommandOptionWithDefault("device-list", "order", DEFAULT_DEVICE_ORDER)
David Bainbridgea6722342019-10-24 23:55:53 +0000980 }
981
Scott Baker9173ed82020-05-19 08:30:12 -0700982 // Make sure json output prints an empty list, not "null"
983 if devices.Items == nil {
984 devices.Items = make([]*voltha.Device, 0)
Zack Williamse940c7a2019-08-21 14:25:39 -0700985 }
986
987 result := CommandResult{
988 Format: format.Format(outputFormat),
989 Filter: options.Filter,
David Bainbridgea6722342019-10-24 23:55:53 +0000990 OrderBy: orderBy,
Zack Williamse940c7a2019-08-21 14:25:39 -0700991 OutputAs: toOutputType(options.OutputAs),
992 NameLimit: options.NameLimit,
Scott Baker9173ed82020-05-19 08:30:12 -0700993 Data: devices.Items,
Zack Williamse940c7a2019-08-21 14:25:39 -0700994 }
995
996 GenerateOutput(&result)
997 return nil
998}
999
1000func (options *DeviceCreate) Execute(args []string) error {
1001
Scott Baker9173ed82020-05-19 08:30:12 -07001002 device := voltha.Device{}
Zack Williamse940c7a2019-08-21 14:25:39 -07001003 if options.HostAndPort != "" {
Scott Baker9173ed82020-05-19 08:30:12 -07001004 device.Address = &voltha.Device_HostAndPort{HostAndPort: options.HostAndPort}
Zack Williamse940c7a2019-08-21 14:25:39 -07001005 } else if options.IPAddress != "" {
Scott Baker9173ed82020-05-19 08:30:12 -07001006 device.Address = &voltha.Device_Ipv4Address{Ipv4Address: options.IPAddress}
Hardik Windlassce1de342020-02-04 21:58:07 +00001007 }
1008 if options.MACAddress != "" {
Scott Baker9173ed82020-05-19 08:30:12 -07001009 device.MacAddress = strings.ToLower(options.MACAddress)
Zack Williamse940c7a2019-08-21 14:25:39 -07001010 }
1011 if options.DeviceType != "" {
Scott Baker9173ed82020-05-19 08:30:12 -07001012 device.Type = options.DeviceType
Zack Williamse940c7a2019-08-21 14:25:39 -07001013 }
1014
1015 conn, err := NewConnection()
1016 if err != nil {
1017 return err
1018 }
1019 defer conn.Close()
1020
Scott Baker9173ed82020-05-19 08:30:12 -07001021 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -07001022
David K. Bainbridge9189c632021-03-26 21:52:21 +00001023 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -07001024 defer cancel()
1025
Scott Baker9173ed82020-05-19 08:30:12 -07001026 createdDevice, err := client.CreateDevice(ctx, &device)
Zack Williamse940c7a2019-08-21 14:25:39 -07001027 if err != nil {
1028 return err
Zack Williamse940c7a2019-08-21 14:25:39 -07001029 }
1030
Scott Baker9173ed82020-05-19 08:30:12 -07001031 fmt.Printf("%s\n", createdDevice.Id)
Zack Williamse940c7a2019-08-21 14:25:39 -07001032
1033 return nil
1034}
1035
1036func (options *DeviceDelete) Execute(args []string) error {
1037
1038 conn, err := NewConnection()
1039 if err != nil {
1040 return err
1041 }
1042 defer conn.Close()
1043
Scott Baker9173ed82020-05-19 08:30:12 -07001044 client := voltha.NewVolthaServiceClient(conn)
David Bainbridge7052fe82020-03-25 10:37:00 -07001045 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -07001046 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +00001047 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -07001048 defer cancel()
1049
Scott Baker9173ed82020-05-19 08:30:12 -07001050 id := voltha.ID{Id: string(i)}
Himani Chawla9933ddc2020-10-12 23:53:27 +05301051 if options.Force {
1052 _, err = client.ForceDeleteDevice(ctx, &id)
1053 } else {
1054 _, err = client.DeleteDevice(ctx, &id)
1055 }
Scott Baker9173ed82020-05-19 08:30:12 -07001056
Zack Williamse940c7a2019-08-21 14:25:39 -07001057 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +00001058 Error.Printf("Error while deleting '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -07001059 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -07001060 continue
Zack Williamse940c7a2019-08-21 14:25:39 -07001061 }
1062 fmt.Printf("%s\n", i)
1063 }
1064
David Bainbridge7052fe82020-03-25 10:37:00 -07001065 if lastErr != nil {
1066 return NoReportErr
1067 }
Zack Williamse940c7a2019-08-21 14:25:39 -07001068 return nil
1069}
1070
1071func (options *DeviceEnable) Execute(args []string) error {
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)
Zack Williamse940c7a2019-08-21 14:25:39 -07001079
David Bainbridge7052fe82020-03-25 10:37:00 -07001080 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -07001081 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +00001082 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -07001083 defer cancel()
1084
Scott Baker9173ed82020-05-19 08:30:12 -07001085 id := voltha.ID{Id: string(i)}
1086
1087 _, err := client.EnableDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -07001088 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +00001089 Error.Printf("Error while enabling '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -07001090 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -07001091 continue
Zack Williamse940c7a2019-08-21 14:25:39 -07001092 }
1093 fmt.Printf("%s\n", i)
1094 }
1095
David Bainbridge7052fe82020-03-25 10:37:00 -07001096 if lastErr != nil {
1097 return NoReportErr
1098 }
Zack Williamse940c7a2019-08-21 14:25:39 -07001099 return nil
1100}
1101
1102func (options *DeviceDisable) Execute(args []string) error {
1103 conn, err := NewConnection()
1104 if err != nil {
1105 return err
1106 }
1107 defer conn.Close()
1108
Scott Baker9173ed82020-05-19 08:30:12 -07001109 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -07001110
David Bainbridge7052fe82020-03-25 10:37:00 -07001111 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -07001112 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +00001113 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -07001114 defer cancel()
1115
Scott Baker9173ed82020-05-19 08:30:12 -07001116 id := voltha.ID{Id: string(i)}
1117
1118 _, err := client.DisableDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -07001119 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +00001120 Error.Printf("Error while disabling '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -07001121 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -07001122 continue
Zack Williamse940c7a2019-08-21 14:25:39 -07001123 }
1124 fmt.Printf("%s\n", i)
1125 }
1126
David Bainbridge7052fe82020-03-25 10:37:00 -07001127 if lastErr != nil {
1128 return NoReportErr
1129 }
Zack Williamse940c7a2019-08-21 14:25:39 -07001130 return nil
1131}
1132
1133func (options *DeviceReboot) Execute(args []string) error {
1134 conn, err := NewConnection()
1135 if err != nil {
1136 return err
1137 }
1138 defer conn.Close()
1139
Scott Baker9173ed82020-05-19 08:30:12 -07001140 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -07001141
David Bainbridge7052fe82020-03-25 10:37:00 -07001142 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -07001143 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +00001144 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -07001145 defer cancel()
1146
Scott Baker9173ed82020-05-19 08:30:12 -07001147 id := voltha.ID{Id: string(i)}
1148
1149 _, err := client.RebootDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -07001150 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +00001151 Error.Printf("Error while rebooting '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -07001152 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -07001153 continue
Zack Williamse940c7a2019-08-21 14:25:39 -07001154 }
1155 fmt.Printf("%s\n", i)
1156 }
1157
David Bainbridge7052fe82020-03-25 10:37:00 -07001158 if lastErr != nil {
1159 return NoReportErr
1160 }
Zack Williamse940c7a2019-08-21 14:25:39 -07001161 return nil
1162}
1163
1164func (options *DevicePortList) Execute(args []string) error {
1165
1166 conn, err := NewConnection()
1167 if err != nil {
1168 return err
1169 }
1170 defer conn.Close()
1171
Scott Baker9173ed82020-05-19 08:30:12 -07001172 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -07001173
David K. Bainbridge9189c632021-03-26 21:52:21 +00001174 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -07001175 defer cancel()
1176
Scott Baker9173ed82020-05-19 08:30:12 -07001177 id := voltha.ID{Id: string(options.Args.Id)}
Zack Williamse940c7a2019-08-21 14:25:39 -07001178
Scott Baker9173ed82020-05-19 08:30:12 -07001179 ports, err := client.ListDevicePorts(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -07001180 if err != nil {
1181 return err
1182 }
1183
1184 outputFormat := CharReplacer.Replace(options.Format)
1185 if outputFormat == "" {
David Bainbridgea6722342019-10-24 23:55:53 +00001186 outputFormat = GetCommandOptionWithDefault("device-ports", "format", DEFAULT_DEVICE_PORTS_FORMAT)
Zack Williamse940c7a2019-08-21 14:25:39 -07001187 }
Zack Williamse940c7a2019-08-21 14:25:39 -07001188
David Bainbridgea6722342019-10-24 23:55:53 +00001189 orderBy := options.OrderBy
1190 if orderBy == "" {
1191 orderBy = GetCommandOptionWithDefault("device-ports", "order", "")
1192 }
1193
Zack Williamse940c7a2019-08-21 14:25:39 -07001194 result := CommandResult{
1195 Format: format.Format(outputFormat),
1196 Filter: options.Filter,
David Bainbridgea6722342019-10-24 23:55:53 +00001197 OrderBy: orderBy,
Zack Williamse940c7a2019-08-21 14:25:39 -07001198 OutputAs: toOutputType(options.OutputAs),
1199 NameLimit: options.NameLimit,
Scott Baker9173ed82020-05-19 08:30:12 -07001200 Data: ports.Items,
Zack Williamse940c7a2019-08-21 14:25:39 -07001201 }
1202
1203 GenerateOutput(&result)
1204 return nil
1205}
1206
1207func (options *DeviceFlowList) Execute(args []string) error {
1208 fl := &FlowList{}
1209 fl.ListOutputOptions = options.ListOutputOptions
Maninder045921e2020-09-29 16:46:02 +05301210 fl.FlowIdOptions = options.FlowIdOptions
Zack Williamse940c7a2019-08-21 14:25:39 -07001211 fl.Args.Id = string(options.Args.Id)
David Bainbridgea6722342019-10-24 23:55:53 +00001212 fl.Method = "device-flows"
Zack Williamse940c7a2019-08-21 14:25:39 -07001213 return fl.Execute(args)
1214}
1215
Himani Chawla3c161c62021-05-13 16:36:51 +05301216func (options *DeviceFlowGroupList) Execute(args []string) error {
1217 grp := &GroupList{}
1218 grp.ListOutputOptions = options.ListOutputOptions
1219 grp.GroupListOptions = options.GroupListOptions
1220 grp.Args.Id = string(options.Args.Id)
1221 grp.Method = "device-groups"
1222 return grp.Execute(args)
1223}
1224
Zack Williamse940c7a2019-08-21 14:25:39 -07001225func (options *DeviceInspect) Execute(args []string) error {
1226 if len(args) > 0 {
1227 return fmt.Errorf("only a single argument 'DEVICE_ID' can be provided")
1228 }
1229
1230 conn, err := NewConnection()
1231 if err != nil {
1232 return err
1233 }
1234 defer conn.Close()
1235
Scott Baker9173ed82020-05-19 08:30:12 -07001236 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -07001237
David K. Bainbridge9189c632021-03-26 21:52:21 +00001238 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -07001239 defer cancel()
1240
Scott Baker9173ed82020-05-19 08:30:12 -07001241 id := voltha.ID{Id: string(options.Args.Id)}
Zack Williamse940c7a2019-08-21 14:25:39 -07001242
Scott Baker9173ed82020-05-19 08:30:12 -07001243 device, err := client.GetDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -07001244 if err != nil {
1245 return err
1246 }
1247
Zack Williamse940c7a2019-08-21 14:25:39 -07001248 outputFormat := CharReplacer.Replace(options.Format)
1249 if outputFormat == "" {
David Bainbridgea6722342019-10-24 23:55:53 +00001250 outputFormat = GetCommandOptionWithDefault("device-inspect", "format", DEFAULT_DEVICE_INSPECT_FORMAT)
Zack Williamse940c7a2019-08-21 14:25:39 -07001251 }
1252 if options.Quiet {
1253 outputFormat = "{{.Id}}"
1254 }
1255
1256 result := CommandResult{
1257 Format: format.Format(outputFormat),
1258 OutputAs: toOutputType(options.OutputAs),
1259 NameLimit: options.NameLimit,
1260 Data: device,
1261 }
1262 GenerateOutput(&result)
1263 return nil
1264}
kesavand12cd8eb2020-01-20 22:25:22 -05001265
1266/*Device Port Enable */
1267func (options *DevicePortEnable) Execute(args []string) error {
1268 conn, err := NewConnection()
1269 if err != nil {
1270 return err
1271 }
1272 defer conn.Close()
1273
Scott Baker9173ed82020-05-19 08:30:12 -07001274 client := voltha.NewVolthaServiceClient(conn)
kesavand12cd8eb2020-01-20 22:25:22 -05001275
David K. Bainbridge9189c632021-03-26 21:52:21 +00001276 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand12cd8eb2020-01-20 22:25:22 -05001277 defer cancel()
1278
Scott Baker9173ed82020-05-19 08:30:12 -07001279 port := voltha.Port{DeviceId: string(options.Args.Id), PortNo: uint32(options.Args.PortId)}
1280
1281 _, err = client.EnablePort(ctx, &port)
kesavand12cd8eb2020-01-20 22:25:22 -05001282 if err != nil {
1283 Error.Printf("Error enabling port number %v on device Id %s,err=%s\n", options.Args.PortId, options.Args.Id, ErrorToString(err))
1284 return err
kesavand12cd8eb2020-01-20 22:25:22 -05001285 }
1286
1287 return nil
1288}
1289
Scott Baker9173ed82020-05-19 08:30:12 -07001290/*Device Port Disable */
kesavand12cd8eb2020-01-20 22:25:22 -05001291func (options *DevicePortDisable) Execute(args []string) error {
1292 conn, err := NewConnection()
1293 if err != nil {
1294 return err
1295 }
1296 defer conn.Close()
1297
Scott Baker9173ed82020-05-19 08:30:12 -07001298 client := voltha.NewVolthaServiceClient(conn)
1299
David K. Bainbridge9189c632021-03-26 21:52:21 +00001300 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand12cd8eb2020-01-20 22:25:22 -05001301 defer cancel()
1302
Scott Baker9173ed82020-05-19 08:30:12 -07001303 port := voltha.Port{DeviceId: string(options.Args.Id), PortNo: uint32(options.Args.PortId)}
1304
1305 _, err = client.DisablePort(ctx, &port)
kesavand12cd8eb2020-01-20 22:25:22 -05001306 if err != nil {
Scott Baker9173ed82020-05-19 08:30:12 -07001307 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 -05001308 return err
kesavand12cd8eb2020-01-20 22:25:22 -05001309 }
Scott Baker9173ed82020-05-19 08:30:12 -07001310
kesavand12cd8eb2020-01-20 22:25:22 -05001311 return nil
1312}
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08001313
Rohan Agrawald7df3772020-06-29 11:23:36 +00001314func (options *DevicePmConfigSetMaxSkew) Execute(args []string) error {
1315 conn, err := NewConnection()
1316 if err != nil {
1317 return err
1318 }
1319 defer conn.Close()
1320
1321 client := voltha.NewVolthaServiceClient(conn)
1322
David K. Bainbridge9189c632021-03-26 21:52:21 +00001323 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawald7df3772020-06-29 11:23:36 +00001324 defer cancel()
1325
1326 id := voltha.ID{Id: string(options.Args.Id)}
1327
1328 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1329 if err != nil {
1330 return err
1331 }
1332
1333 pmConfigs.MaxSkew = options.Args.MaxSkew
1334
1335 _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs)
1336 if err != nil {
1337 return err
1338 }
1339
1340 return nil
1341}
1342
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001343func (options *DevicePmConfigsGet) Execute(args []string) error {
1344
1345 conn, err := NewConnection()
1346 if err != nil {
1347 return err
1348 }
1349 defer conn.Close()
1350
1351 client := voltha.NewVolthaServiceClient(conn)
1352
David K. Bainbridge9189c632021-03-26 21:52:21 +00001353 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001354 defer cancel()
1355
1356 id := voltha.ID{Id: string(options.Args.Id)}
1357
1358 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1359 if err != nil {
1360 return err
1361 }
1362
1363 outputFormat := CharReplacer.Replace(options.Format)
1364 if outputFormat == "" {
1365 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GET_FORMAT)
1366 }
1367
1368 orderBy := options.OrderBy
1369 if orderBy == "" {
1370 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1371 }
1372
1373 result := CommandResult{
1374 Format: format.Format(outputFormat),
1375 Filter: options.Filter,
1376 OrderBy: orderBy,
1377 OutputAs: toOutputType(options.OutputAs),
1378 NameLimit: options.NameLimit,
1379 Data: pmConfigs,
1380 }
1381
1382 GenerateOutput(&result)
1383 return nil
1384
1385}
1386
1387func (options *DevicePmConfigMetricList) Execute(args []string) error {
1388
1389 conn, err := NewConnection()
1390 if err != nil {
1391 return err
1392 }
1393 defer conn.Close()
1394
1395 client := voltha.NewVolthaServiceClient(conn)
1396
David K. Bainbridge9189c632021-03-26 21:52:21 +00001397 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001398 defer cancel()
1399
1400 id := voltha.ID{Id: string(options.Args.Id)}
1401
1402 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1403 if err != nil {
1404 return err
1405 }
1406
1407 if !pmConfigs.Grouped {
1408 for _, metric := range pmConfigs.Metrics {
1409 if metric.SampleFreq == 0 {
1410 metric.SampleFreq = pmConfigs.DefaultFreq
1411 }
1412 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001413 outputFormat := CharReplacer.Replace(options.Format)
1414 if outputFormat == "" {
1415 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_METRIC_LIST_FORMAT)
1416 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001417
Rohan Agrawalbca69122020-06-17 14:59:03 +00001418 orderBy := options.OrderBy
1419 if orderBy == "" {
1420 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1421 }
1422
1423 result := CommandResult{
1424 Format: format.Format(outputFormat),
1425 Filter: options.Filter,
1426 OrderBy: orderBy,
1427 OutputAs: toOutputType(options.OutputAs),
1428 NameLimit: options.NameLimit,
1429 Data: pmConfigs.Metrics,
1430 }
1431
1432 GenerateOutput(&result)
1433 return nil
1434 } else {
1435 return fmt.Errorf("Device '%s' does not have Non Grouped Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001436 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001437}
1438
1439func (options *DevicePmConfigMetricEnable) Execute(args []string) error {
1440
1441 conn, err := NewConnection()
1442 if err != nil {
1443 return err
1444 }
1445 defer conn.Close()
1446
1447 client := voltha.NewVolthaServiceClient(conn)
1448
David K. Bainbridge9189c632021-03-26 21:52:21 +00001449 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001450 defer cancel()
1451
1452 id := voltha.ID{Id: string(options.Args.Id)}
1453
1454 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1455 if err != nil {
1456 return err
1457 }
1458
1459 if !pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001460 metrics := make(map[string]struct{})
1461 for _, metric := range pmConfigs.Metrics {
1462 metrics[metric.Name] = struct{}{}
1463 }
1464
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001465 for _, metric := range pmConfigs.Metrics {
1466 for _, mName := range options.Args.Metrics {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001467 if _, exist := metrics[string(mName)]; !exist {
1468 return fmt.Errorf("Metric Name '%s' does not exist", mName)
1469 }
1470
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001471 if string(mName) == metric.Name && !metric.Enabled {
1472 metric.Enabled = true
1473 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1474 if err != nil {
1475 return err
1476 }
1477 }
1478 }
1479 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001480 } else {
1481 return fmt.Errorf("Device '%s' does not have Non Grouped Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001482 }
1483 return nil
1484}
1485
1486func (options *DevicePmConfigMetricDisable) Execute(args []string) error {
1487
1488 conn, err := NewConnection()
1489 if err != nil {
1490 return err
1491 }
1492 defer conn.Close()
1493
1494 client := voltha.NewVolthaServiceClient(conn)
1495
David K. Bainbridge9189c632021-03-26 21:52:21 +00001496 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001497 defer cancel()
1498
1499 id := voltha.ID{Id: string(options.Args.Id)}
1500
1501 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1502 if err != nil {
1503 return err
1504 }
1505
1506 if !pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001507 metrics := make(map[string]struct{})
1508 for _, metric := range pmConfigs.Metrics {
1509 metrics[metric.Name] = struct{}{}
1510 }
1511
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001512 for _, metric := range pmConfigs.Metrics {
1513 for _, mName := range options.Args.Metrics {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001514 if _, have := metrics[string(mName)]; !have {
1515 return fmt.Errorf("Metric Name '%s' does not exist", mName)
1516 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001517 if string(mName) == metric.Name && metric.Enabled {
1518 metric.Enabled = false
1519 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1520 if err != nil {
1521 return err
1522 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001523 } else {
1524 return fmt.Errorf("Metric '%s' cannot be disabled", string(mName))
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001525 }
1526 }
1527 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001528 } else {
1529 return fmt.Errorf("Device '%s' does not have Non Grouped Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001530 }
1531 return nil
1532}
1533
1534func (options *DevicePmConfigGroupEnable) Execute(args []string) error {
1535
1536 conn, err := NewConnection()
1537 if err != nil {
1538 return err
1539 }
1540 defer conn.Close()
1541
1542 client := voltha.NewVolthaServiceClient(conn)
1543
David K. Bainbridge9189c632021-03-26 21:52:21 +00001544 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001545 defer cancel()
1546
1547 id := voltha.ID{Id: string(options.Args.Id)}
1548
1549 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1550 if err != nil {
1551 return err
1552 }
1553
1554 if pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001555 groups := make(map[string]struct{})
1556 for _, group := range pmConfigs.Groups {
1557 groups[group.GroupName] = struct{}{}
1558 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001559 for _, group := range pmConfigs.Groups {
Girish Gowdra610acb42021-01-27 13:33:57 -08001560 if _, have := groups[string(options.Args.Group)]; !have {
1561 return fmt.Errorf("Group Name '%s' does not exist", options.Args.Group)
1562 }
1563 if string(options.Args.Group) == group.GroupName && !group.Enabled {
1564 group.Enabled = true
1565 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1566 if err != nil {
1567 return err
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001568 }
1569 }
1570 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001571 } else {
1572 return fmt.Errorf("Device '%s' does not have Group Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001573 }
1574 return nil
1575}
1576
1577func (options *DevicePmConfigGroupDisable) Execute(args []string) error {
1578
1579 conn, err := NewConnection()
1580 if err != nil {
1581 return err
1582 }
1583 defer conn.Close()
1584
1585 client := voltha.NewVolthaServiceClient(conn)
1586
David K. Bainbridge9189c632021-03-26 21:52:21 +00001587 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001588 defer cancel()
1589
1590 id := voltha.ID{Id: string(options.Args.Id)}
1591
1592 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1593 if err != nil {
1594 return err
1595 }
1596
1597 if pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001598 groups := make(map[string]struct{})
1599 for _, group := range pmConfigs.Groups {
1600 groups[group.GroupName] = struct{}{}
1601 }
1602
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001603 for _, group := range pmConfigs.Groups {
Girish Gowdra610acb42021-01-27 13:33:57 -08001604 if _, have := groups[string(options.Args.Group)]; !have {
1605 return fmt.Errorf("Group Name '%s' does not exist", options.Args.Group)
1606 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001607
Girish Gowdra610acb42021-01-27 13:33:57 -08001608 if string(options.Args.Group) == group.GroupName && group.Enabled {
1609 group.Enabled = false
1610 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1611 if err != nil {
1612 return err
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001613 }
1614 }
1615 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001616 } else {
1617 return fmt.Errorf("Device '%s' does not have Group Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001618 }
1619 return nil
1620}
1621
Girish Gowdra610acb42021-01-27 13:33:57 -08001622func (options *DevicePmConfigGroupFrequencySet) Execute(args []string) error {
1623
1624 conn, err := NewConnection()
1625 if err != nil {
1626 return err
1627 }
1628 defer conn.Close()
1629
1630 client := voltha.NewVolthaServiceClient(conn)
1631
David K. Bainbridge9189c632021-03-26 21:52:21 +00001632 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Girish Gowdra610acb42021-01-27 13:33:57 -08001633 defer cancel()
1634
1635 id := voltha.ID{Id: string(options.Args.Id)}
1636
1637 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1638 if err != nil {
1639 return err
1640 }
1641
1642 if pmConfigs.Grouped {
1643 groups := make(map[string]struct{})
1644 for _, group := range pmConfigs.Groups {
1645 groups[group.GroupName] = struct{}{}
1646 }
1647
1648 for _, group := range pmConfigs.Groups {
1649 if _, have := groups[string(options.Args.Group)]; !have {
1650 return fmt.Errorf("group name '%s' does not exist", options.Args.Group)
1651 }
1652
1653 if string(options.Args.Group) == group.GroupName {
1654 if !group.Enabled {
1655 return fmt.Errorf("group '%s' is not enabled", options.Args.Group)
1656 }
1657 group.GroupFreq = uint32(options.Args.Interval.Seconds())
1658 _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs)
1659 if err != nil {
1660 return err
1661 }
1662 }
1663 }
1664 } else {
1665 return fmt.Errorf("device '%s' does not have group metrics", options.Args.Id)
1666 }
1667 return nil
1668}
1669
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001670func (options *DevicePmConfigGroupList) Execute(args []string) error {
1671
1672 conn, err := NewConnection()
1673 if err != nil {
1674 return err
1675 }
1676 defer conn.Close()
1677
1678 client := voltha.NewVolthaServiceClient(conn)
1679
David K. Bainbridge9189c632021-03-26 21:52:21 +00001680 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001681 defer cancel()
1682
1683 id := voltha.ID{Id: string(options.Args.Id)}
1684
1685 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1686 if err != nil {
1687 return err
1688 }
1689
1690 if pmConfigs.Grouped {
1691 for _, group := range pmConfigs.Groups {
1692 if group.GroupFreq == 0 {
1693 group.GroupFreq = pmConfigs.DefaultFreq
1694 }
1695 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001696 outputFormat := CharReplacer.Replace(options.Format)
1697 if outputFormat == "" {
1698 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GROUP_LIST_FORMAT)
1699 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001700
Rohan Agrawalbca69122020-06-17 14:59:03 +00001701 orderBy := options.OrderBy
1702 if orderBy == "" {
1703 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1704 }
1705
1706 result := CommandResult{
1707 Format: format.Format(outputFormat),
1708 Filter: options.Filter,
1709 OrderBy: orderBy,
1710 OutputAs: toOutputType(options.OutputAs),
1711 NameLimit: options.NameLimit,
1712 Data: pmConfigs.Groups,
1713 }
1714
1715 GenerateOutput(&result)
1716 } else {
1717 return fmt.Errorf("Device '%s' does not have Group Metrics", string(options.Args.Id))
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001718 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001719 return nil
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001720}
1721
1722func (options *DevicePmConfigGroupMetricList) Execute(args []string) error {
1723
1724 var metrics []*voltha.PmConfig
1725 conn, err := NewConnection()
1726 if err != nil {
1727 return err
1728 }
1729 defer conn.Close()
1730
1731 client := voltha.NewVolthaServiceClient(conn)
1732
David K. Bainbridge9189c632021-03-26 21:52:21 +00001733 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001734 defer cancel()
1735
1736 id := voltha.ID{Id: string(options.Args.Id)}
1737
1738 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1739 if err != nil {
1740 return err
1741 }
1742
1743 for _, groups := range pmConfigs.Groups {
1744
1745 if string(options.Args.Group) == groups.GroupName {
1746 for _, metric := range groups.Metrics {
1747 if metric.SampleFreq == 0 && groups.GroupFreq == 0 {
1748 metric.SampleFreq = pmConfigs.DefaultFreq
1749 } else {
1750 metric.SampleFreq = groups.GroupFreq
1751 }
1752 }
1753 metrics = groups.Metrics
1754 }
1755 }
1756
1757 outputFormat := CharReplacer.Replace(options.Format)
1758 if outputFormat == "" {
1759 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_METRIC_LIST_FORMAT)
1760 }
1761
1762 orderBy := options.OrderBy
1763 if orderBy == "" {
1764 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1765 }
1766
1767 result := CommandResult{
1768 Format: format.Format(outputFormat),
1769 Filter: options.Filter,
1770 OrderBy: orderBy,
1771 OutputAs: toOutputType(options.OutputAs),
1772 NameLimit: options.NameLimit,
1773 Data: metrics,
1774 }
1775
1776 GenerateOutput(&result)
1777 return nil
1778
1779}
1780
1781func (options *DevicePmConfigFrequencySet) Execute(args []string) error {
1782
1783 conn, err := NewConnection()
1784 if err != nil {
1785 return err
1786 }
1787 defer conn.Close()
1788
1789 client := voltha.NewVolthaServiceClient(conn)
1790
David K. Bainbridge9189c632021-03-26 21:52:21 +00001791 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001792 defer cancel()
1793
1794 id := voltha.ID{Id: string(options.Args.Id)}
1795
1796 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1797 if err != nil {
1798 return err
1799 }
1800
Girish Gowdra610acb42021-01-27 13:33:57 -08001801 pmConfigs.DefaultFreq = uint32(options.Args.Interval.Seconds())
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001802
1803 _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs)
1804 if err != nil {
1805 return err
1806 }
1807
1808 outputFormat := CharReplacer.Replace(options.Format)
1809 if outputFormat == "" {
1810 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GET_FORMAT)
1811 }
1812 if options.Quiet {
1813 outputFormat = "{{.Id}}"
1814 }
1815
1816 result := CommandResult{
1817 Format: format.Format(outputFormat),
1818 OutputAs: toOutputType(options.OutputAs),
1819 NameLimit: options.NameLimit,
1820 Data: pmConfigs,
1821 }
1822
1823 GenerateOutput(&result)
1824 return nil
1825
1826}
1827
kesavand3e2f9f62021-04-22 11:06:38 +05301828func (options *OnuDownloadImage) Execute(args []string) error {
1829
1830 conn, err := NewConnection()
1831 if err != nil {
1832 return err
1833 }
1834 defer conn.Close()
1835
1836 client := voltha.NewVolthaServiceClient(conn)
1837
1838 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1839 defer cancel()
1840
1841 var devIDList []*common.ID
1842 for _, i := range options.Args.IDs {
1843
1844 devIDList = append(devIDList, &common.ID{Id: string(i)})
1845 }
1846
1847 downloadImage := voltha.DeviceImageDownloadRequest{
1848 DeviceId: devIDList,
1849 Image: &voltha.Image{
1850 Url: options.Args.Url,
1851 Crc32: options.Args.Crc,
ssiddiqui7bc89e92021-05-20 20:58:02 +05301852 Vendor: options.Args.Vendor,
kesavand3e2f9f62021-04-22 11:06:38 +05301853 Version: options.Args.ImageVersion,
1854 },
1855 ActivateOnSuccess: options.Args.ActivateOnSuccess,
1856 CommitOnSuccess: options.Args.CommitOnSuccess,
1857 }
1858
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001859 deviceImageResp, err := client.DownloadImageToDevice(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301860 if err != nil {
1861 return err
1862 }
1863
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001864 outputFormat := GetCommandOptionWithDefault("onu-image-download", "format", ONU_IMAGE_STATUS_FORMAT)
1865 // Make sure json output prints an empty list, not "null"
1866 if deviceImageResp.DeviceImageStates == nil {
1867 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1868 }
1869 result := CommandResult{
1870 Format: format.Format(outputFormat),
1871 OutputAs: toOutputType(options.OutputAs),
1872 NameLimit: options.NameLimit,
1873 Data: deviceImageResp.DeviceImageStates,
1874 }
1875 GenerateOutput(&result)
kesavand3e2f9f62021-04-22 11:06:38 +05301876 return nil
1877
1878}
1879
1880func (options *OnuActivateImage) Execute(args []string) error {
1881
1882 conn, err := NewConnection()
1883 if err != nil {
1884 return err
1885 }
1886 defer conn.Close()
1887
1888 client := voltha.NewVolthaServiceClient(conn)
1889
1890 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1891 defer cancel()
1892
1893 var devIDList []*common.ID
1894 for _, i := range options.Args.IDs {
1895
1896 devIDList = append(devIDList, &common.ID{Id: string(i)})
1897 }
1898
1899 downloadImage := voltha.DeviceImageRequest{
1900 DeviceId: devIDList,
1901 Version: options.Args.ImageVersion,
1902 CommitOnSuccess: options.Args.CommitOnSuccess,
1903 }
1904
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001905 deviceImageResp, err := client.ActivateImage(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301906 if err != nil {
1907 return err
1908 }
1909
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001910 outputFormat := GetCommandOptionWithDefault("onu-image-activate", "format", ONU_IMAGE_STATUS_FORMAT)
1911 // Make sure json output prints an empty list, not "null"
1912 if deviceImageResp.DeviceImageStates == nil {
1913 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1914 }
1915 result := CommandResult{
1916 Format: format.Format(outputFormat),
1917 OutputAs: toOutputType(options.OutputAs),
1918 NameLimit: options.NameLimit,
1919 Data: deviceImageResp.DeviceImageStates,
1920 }
1921 GenerateOutput(&result)
1922
kesavand3e2f9f62021-04-22 11:06:38 +05301923 return nil
1924
1925}
1926
1927func (options *OnuAbortUpgradeImage) Execute(args []string) error {
1928
1929 conn, err := NewConnection()
1930 if err != nil {
1931 return err
1932 }
1933 defer conn.Close()
1934
1935 client := voltha.NewVolthaServiceClient(conn)
1936
1937 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1938 defer cancel()
1939
1940 var devIDList []*common.ID
1941 for _, i := range options.Args.IDs {
1942
1943 devIDList = append(devIDList, &common.ID{Id: string(i)})
1944 }
1945
1946 downloadImage := voltha.DeviceImageRequest{
1947 DeviceId: devIDList,
1948 Version: options.Args.ImageVersion,
1949 }
1950
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001951 deviceImageResp, err := client.AbortImageUpgradeToDevice(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301952 if err != nil {
1953 return err
1954 }
1955
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001956 outputFormat := GetCommandOptionWithDefault("onu-image-abort", "format", ONU_IMAGE_STATUS_FORMAT)
1957 // Make sure json output prints an empty list, not "null"
1958 if deviceImageResp.DeviceImageStates == nil {
1959 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1960 }
1961 result := CommandResult{
1962 Format: format.Format(outputFormat),
1963 OutputAs: toOutputType(options.OutputAs),
1964 NameLimit: options.NameLimit,
1965 Data: deviceImageResp.DeviceImageStates,
1966 }
1967 GenerateOutput(&result)
1968
kesavand3e2f9f62021-04-22 11:06:38 +05301969 return nil
1970
1971}
1972
1973func (options *OnuCommitImage) Execute(args []string) error {
1974
1975 conn, err := NewConnection()
1976 if err != nil {
1977 return err
1978 }
1979 defer conn.Close()
1980
1981 client := voltha.NewVolthaServiceClient(conn)
1982
1983 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1984 defer cancel()
1985
1986 var devIDList []*common.ID
1987 for _, i := range options.Args.IDs {
1988
1989 devIDList = append(devIDList, &common.ID{Id: string(i)})
1990 }
1991 downloadImage := voltha.DeviceImageRequest{
1992 DeviceId: devIDList,
1993 Version: options.Args.ImageVersion,
1994 }
1995
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001996 deviceImageResp, err := client.CommitImage(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301997 if err != nil {
1998 return err
1999 }
2000
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02002001 outputFormat := GetCommandOptionWithDefault("onu-image-commit", "format", ONU_IMAGE_STATUS_FORMAT)
2002 // Make sure json output prints an empty list, not "null"
2003 if deviceImageResp.DeviceImageStates == nil {
2004 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
2005 }
2006 result := CommandResult{
2007 Format: format.Format(outputFormat),
2008 OutputAs: toOutputType(options.OutputAs),
2009 NameLimit: options.NameLimit,
2010 Data: deviceImageResp.DeviceImageStates,
2011 }
2012 GenerateOutput(&result)
2013
kesavand3e2f9f62021-04-22 11:06:38 +05302014 return nil
2015
2016}
2017
2018func (options *OnuListImages) Execute(args []string) error {
2019
2020 conn, err := NewConnection()
2021 if err != nil {
2022 return err
2023 }
2024 defer conn.Close()
2025
2026 client := voltha.NewVolthaServiceClient(conn)
2027
2028 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2029 defer cancel()
2030
2031 id := common.ID{Id: string(options.Args.Id)}
2032
2033 onuImages, err := client.GetOnuImages(ctx, &id)
2034 if err != nil {
2035 return err
2036 }
2037
2038 outputFormat := CharReplacer.Replace(options.Format)
2039 if outputFormat == "" {
2040 outputFormat = GetCommandOptionWithDefault("onu-image-list", "format", ONU_IMAGE_LIST_FORMAT)
2041 }
2042
2043 if options.Quiet {
2044 outputFormat = "{{.Id}}"
2045 }
2046
2047 //TODO orderby
2048
2049 // Make sure json output prints an empty list, not "null"
2050 if onuImages.Items == nil {
2051 onuImages.Items = make([]*voltha.OnuImage, 0)
2052 }
2053
2054 result := CommandResult{
2055 Format: format.Format(outputFormat),
2056 OutputAs: toOutputType(options.OutputAs),
2057 NameLimit: options.NameLimit,
2058 Data: onuImages.Items,
2059 }
2060
2061 GenerateOutput(&result)
2062 return nil
2063
2064}
2065
2066func (options *OnuImageStatus) Execute(args []string) error {
2067
2068 conn, err := NewConnection()
2069 if err != nil {
2070 return err
2071 }
2072 defer conn.Close()
2073
2074 client := voltha.NewVolthaServiceClient(conn)
2075
2076 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2077 defer cancel()
2078
2079 var devIDList []*common.ID
kesavand3e2f9f62021-04-22 11:06:38 +05302080
Elia Battiston859f3e62022-02-08 15:57:52 +01002081 if options.Args.IDs == nil {
2082 //Use an empty IDs list to retrieve the status of all devices
2083 //with the requested image version
2084 devIDList = []*common.ID{}
2085 } else {
2086 for _, i := range options.Args.IDs {
2087 devIDList = append(devIDList, &common.ID{Id: string(i)})
2088 }
kesavand3e2f9f62021-04-22 11:06:38 +05302089 }
2090
2091 imageStatusReq := voltha.DeviceImageRequest{
2092 DeviceId: devIDList,
2093 Version: options.Args.ImageVersion,
2094 }
2095 imageStatus, err := client.GetImageStatus(ctx, &imageStatusReq)
2096 if err != nil {
2097 return err
2098 }
2099
2100 outputFormat := CharReplacer.Replace(options.Format)
2101 if outputFormat == "" {
2102 outputFormat = GetCommandOptionWithDefault("device-image-list", "format", ONU_IMAGE_STATUS_FORMAT)
2103 }
2104
2105 if options.Quiet {
2106 outputFormat = "{{.Id}}"
2107 }
2108
2109 //TODO orderby
2110
2111 // Make sure json output prints an empty list, not "null"
2112 if imageStatus.DeviceImageStates == nil {
2113 imageStatus.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
2114 }
2115
2116 result := CommandResult{
2117 Format: format.Format(outputFormat),
2118 OutputAs: toOutputType(options.OutputAs),
2119 NameLimit: options.NameLimit,
2120 Data: imageStatus.DeviceImageStates,
2121 }
2122
2123 GenerateOutput(&result)
2124 return nil
2125
2126}
2127
Andrea Campanella791d88b2021-01-08 13:29:00 +01002128func (options *DeviceOnuListImages) Execute(args []string) error {
2129
2130 conn, err := NewConnection()
2131 if err != nil {
2132 return err
2133 }
2134 defer conn.Close()
2135
2136 client := voltha.NewVolthaServiceClient(conn)
2137
David K. Bainbridge9189c632021-03-26 21:52:21 +00002138 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Andrea Campanella791d88b2021-01-08 13:29:00 +01002139 defer cancel()
2140
2141 id := common.ID{Id: string(options.Args.Id)}
2142
2143 imageDownloads, err := client.ListImageDownloads(ctx, &id)
2144 if err != nil {
2145 return err
2146 }
2147
2148 outputFormat := CharReplacer.Replace(options.Format)
2149 if outputFormat == "" {
2150 outputFormat = GetCommandOptionWithDefault("device-image-list", "format", DEFAULT_DEVICE_IMAGE_LIST_GET_FORMAT)
2151 }
2152
2153 if options.Quiet {
2154 outputFormat = "{{.Id}}"
2155 }
2156
2157 //TODO orderby
2158
2159 // Make sure json output prints an empty list, not "null"
2160 if imageDownloads.Items == nil {
2161 imageDownloads.Items = make([]*voltha.ImageDownload, 0)
2162 }
2163
2164 result := CommandResult{
2165 Format: format.Format(outputFormat),
2166 OutputAs: toOutputType(options.OutputAs),
2167 NameLimit: options.NameLimit,
2168 Data: imageDownloads.Items,
2169 }
2170
2171 GenerateOutput(&result)
2172 return nil
2173
2174}
2175
2176func (options *DeviceOnuDownloadImage) Execute(args []string) error {
2177
2178 conn, err := NewConnection()
2179 if err != nil {
2180 return err
2181 }
2182 defer conn.Close()
2183
2184 client := voltha.NewVolthaServiceClient(conn)
2185
David K. Bainbridge9189c632021-03-26 21:52:21 +00002186 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Andrea Campanella791d88b2021-01-08 13:29:00 +01002187 defer cancel()
2188
2189 downloadImage := voltha.ImageDownload{
2190 Id: string(options.Args.Id),
2191 Name: options.Args.Name,
2192 Url: options.Args.Url,
2193 Crc: options.Args.Crc,
2194 LocalDir: options.Args.LocalDir,
2195 }
2196
2197 _, err = client.DownloadImage(ctx, &downloadImage)
2198 if err != nil {
2199 return err
2200 }
2201
2202 return nil
2203
2204}
2205
2206func (options *DeviceOnuActivateImageUpdate) Execute(args []string) error {
2207
2208 conn, err := NewConnection()
2209 if err != nil {
2210 return err
2211 }
2212 defer conn.Close()
2213
2214 client := voltha.NewVolthaServiceClient(conn)
2215
David K. Bainbridge9189c632021-03-26 21:52:21 +00002216 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Andrea Campanella791d88b2021-01-08 13:29:00 +01002217 defer cancel()
2218
2219 downloadImage := voltha.ImageDownload{
2220 Id: string(options.Args.Id),
2221 Name: options.Args.Name,
2222 ImageVersion: options.Args.ImageVersion,
2223 SaveConfig: options.Args.SaveConfig,
2224 LocalDir: options.Args.LocalDir,
2225 }
2226
2227 _, err = client.ActivateImageUpdate(ctx, &downloadImage)
2228 if err != nil {
2229 return err
2230 }
2231
2232 return nil
2233
2234}
2235
Scott Baker9173ed82020-05-19 08:30:12 -07002236type ReturnValueRow struct {
2237 Name string `json:"name"`
2238 Result interface{} `json:"result"`
2239}
2240
kesavand8ec4fc02021-01-27 09:10:22 -05002241func (options *DeviceGetPortStats) Execute(args []string) error {
2242 conn, err := NewConnection()
2243 if err != nil {
2244 return err
2245 }
2246 defer conn.Close()
2247 client := extension.NewExtensionClient(conn)
2248 var portType extension.GetOltPortCounters_PortType
2249
2250 if options.Args.PortType == "pon" {
2251 portType = extension.GetOltPortCounters_Port_PON_OLT
2252 } else if options.Args.PortType == "nni" {
2253
2254 portType = extension.GetOltPortCounters_Port_ETHERNET_NNI
2255 } else {
2256 return fmt.Errorf("expected interface type pon/nni, provided %s", options.Args.PortType)
2257 }
2258
2259 singleGetValReq := extension.SingleGetValueRequest{
2260 TargetId: string(options.Args.Id),
2261 Request: &extension.GetValueRequest{
2262 Request: &extension.GetValueRequest_OltPortInfo{
2263 OltPortInfo: &extension.GetOltPortCounters{
2264 PortNo: options.Args.PortNo,
2265 PortType: portType,
2266 },
2267 },
2268 },
2269 }
2270
David K. Bainbridge9189c632021-03-26 21:52:21 +00002271 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand8ec4fc02021-01-27 09:10:22 -05002272 defer cancel()
2273 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2274 if err != nil {
2275 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2276 return err
2277 }
2278
2279 if rv.Response.Status != extension.GetValueResponse_OK {
2280 return fmt.Errorf("failed to get port stats %v", rv.Response.ErrReason.String())
2281 }
2282
2283 outputFormat := CharReplacer.Replace(options.Format)
2284 if outputFormat == "" {
2285 outputFormat = GetCommandOptionWithDefault("device-get-port-status", "format", DEFAULT_DEVICE_GET_PORT_STATUS_FORMAT)
2286 }
2287
2288 result := CommandResult{
2289 Format: format.Format(outputFormat),
2290 OutputAs: toOutputType(options.OutputAs),
2291 NameLimit: options.NameLimit,
2292 Data: rv.GetResponse().GetPortCoutners(),
2293 }
2294 GenerateOutput(&result)
2295 return nil
2296}
2297
Himani Chawla40acc122021-05-26 18:52:29 +05302298func (options *GetOnuStats) Execute(args []string) error {
2299 conn, err := NewConnection()
2300 if err != nil {
2301 return err
2302 }
2303 defer conn.Close()
2304 client := extension.NewExtensionClient(conn)
2305
2306 singleGetValReq := extension.SingleGetValueRequest{
2307 TargetId: string(options.Args.OltId),
2308 Request: &extension.GetValueRequest{
2309 Request: &extension.GetValueRequest_OnuPonInfo{
2310 OnuPonInfo: &extension.GetOnuCountersRequest{
2311 IntfId: options.Args.IntfId,
2312 OnuId: options.Args.OnuId,
2313 },
2314 },
2315 },
2316 }
2317 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2318 defer cancel()
2319 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2320 if err != nil {
2321 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.OltId, ErrorToString(err))
2322 return err
2323 }
2324
2325 if rv.Response.Status != extension.GetValueResponse_OK {
2326 return fmt.Errorf("failed to get onu stats %v", rv.Response.ErrReason.String())
2327 }
2328 outputFormat := CharReplacer.Replace(options.Format)
2329 data, formatStr := buildOnuStatsOutputFormat(rv.GetResponse().GetOnuPonCounters())
2330 if outputFormat == "" {
2331 outputFormat = GetCommandOptionWithDefault("device-get-onu-status", "format", formatStr)
2332 }
Himani Chawla553a1392021-06-10 23:39:17 +05302333 result := CommandResult{
2334 Format: format.Format(outputFormat),
2335 OutputAs: toOutputType(options.OutputAs),
2336 NameLimit: options.NameLimit,
2337 Data: data,
2338 }
2339 GenerateOutput(&result)
2340 return nil
2341}
Himani Chawla40acc122021-05-26 18:52:29 +05302342
Akash Soni6e879c22024-12-20 17:01:34 +05302343func (options *GetOffloadApp) Execute(args []string) error {
Akash Soni51b6b7a2024-11-20 11:39:38 +05302344 // Establish a connection to the gRPC server
2345 conn, err := NewConnection()
2346 if err != nil {
2347 return err
2348 }
2349 defer conn.Close()
2350
2351 client := extension.NewExtensionClient(conn)
2352
2353 // Build the request
2354 singleGetValReq := &extension.SingleGetValueRequest{
2355 TargetId: string(options.Args.OltId),
2356 Request: &extension.GetValueRequest{
2357 Request: &extension.GetValueRequest_OffloadedAppsStats{
2358 OffloadedAppsStats: &extension.GetOffloadedAppsStatisticsRequest{
2359 StatsFor: options.Args.StatsFor,
2360 },
2361 },
2362 },
2363 }
2364
2365 // Set a context with timeout
2366 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2367 defer cancel()
2368
2369 // Perform the gRPC call
2370 rv, err := client.GetExtValue(ctx, singleGetValReq)
2371 if err != nil {
2372 Error.Printf("Error getting value for device ID %s, err=%s\n", options.Args.OltId, ErrorToString(err))
2373 return err
2374 }
2375
2376 // Check response status
2377 if rv.GetResponse().GetStatus() != extension.GetValueResponse_OK {
2378 return fmt.Errorf("failed to get offloaded app stats: %v", rv.GetResponse().GetErrReason().String())
2379 }
2380
2381 // Process the response data
2382 stats, formatStr := buildOffloadAppStatsOutputFormat(rv.GetResponse().GetOffloadedAppsStats())
2383 outputFormat := CharReplacer.Replace(options.Format)
2384 if outputFormat == "" {
2385 outputFormat = GetCommandOptionWithDefault("device-get-offload-app-stats", "format", formatStr)
2386 }
2387
2388 // Generate and display the output
2389 result := CommandResult{
2390 Format: format.Format(outputFormat),
2391 OutputAs: toOutputType(options.OutputAs),
2392 NameLimit: options.NameLimit,
2393 Data: stats,
2394 }
2395 GenerateOutput(&result)
2396
2397 return nil
2398}
2399
Akash Soni6e879c22024-12-20 17:01:34 +05302400func (options *SetOffloadApp) Execute(args []string) error {
Akash Soni51b6b7a2024-11-20 11:39:38 +05302401 conn, err := NewConnection()
2402 if err != nil {
Akash Soni6e879c22024-12-20 17:01:34 +05302403 return fmt.Errorf("failed to establish gRPC connection: %w", err)
Akash Soni51b6b7a2024-11-20 11:39:38 +05302404 }
2405 defer conn.Close()
2406
2407 client := extension.NewExtensionClient(conn)
2408
Akash Soni6e879c22024-12-20 17:01:34 +05302409 // Parse JSON input
2410 var config extension.AppOffloadConfig
2411 if err := json.Unmarshal([]byte(options.Args.Config), &config); err != nil {
2412 return fmt.Errorf("failed to parse CONFIG as JSON: %w", err)
2413 }
2414
Akash Soni51b6b7a2024-11-20 11:39:38 +05302415 setValueRequest := &extension.SetValueRequest{
2416 Request: &extension.SetValueRequest_AppOffloadConfig{
Akash Soni6e879c22024-12-20 17:01:34 +05302417 AppOffloadConfig: &config,
Akash Soni51b6b7a2024-11-20 11:39:38 +05302418 },
2419 }
2420
2421 singleSetValReq := &extension.SingleSetValueRequest{
2422 TargetId: string(options.Args.OltId),
2423 Request: setValueRequest,
2424 }
2425
Akash Soni6e879c22024-12-20 17:01:34 +05302426 // Log the request object
2427 logRequestAppOffloadConfig(singleSetValReq)
2428
Akash Soni51b6b7a2024-11-20 11:39:38 +05302429 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2430 defer cancel()
2431
2432 resp, err := client.SetExtValue(ctx, singleSetValReq)
2433 if err != nil {
Akash Soni6e879c22024-12-20 17:01:34 +05302434 return fmt.Errorf("failed to set AppOffloadConfig: %w", err)
Akash Soni51b6b7a2024-11-20 11:39:38 +05302435 }
2436
2437 if resp.Response.Status != extension.SetValueResponse_OK {
Akash Soni6e879c22024-12-20 17:01:34 +05302438 return fmt.Errorf("operation failed with status %v: %s", resp.Response.Status, resp.Response.ErrReason)
Akash Soni51b6b7a2024-11-20 11:39:38 +05302439 }
2440
2441 fmt.Printf("AppOffloadConfig successfully set for OLT ID: %s\n", options.Args.OltId)
2442 return nil
2443}
2444
Akash Soni6e879c22024-12-20 17:01:34 +05302445func logRequestAppOffloadConfig(req *extension.SingleSetValueRequest) {
2446 fmt.Printf("Request details:\n")
2447 fmt.Printf("TargetId: %s\n", req.TargetId)
2448 if config, ok := req.Request.Request.(*extension.SetValueRequest_AppOffloadConfig); ok {
2449 fmt.Printf("AppOffloadConfig:\n")
2450 fmt.Printf(" EnableDHCPv4RA: %t\n", config.AppOffloadConfig.EnableDHCPv4RA)
2451 fmt.Printf(" EnableDHCPv6RA: %t\n", config.AppOffloadConfig.EnableDHCPv6RA)
2452 fmt.Printf(" EnablePPPoEIA: %t\n", config.AppOffloadConfig.EnablePPPoEIA)
2453 fmt.Printf(" AccessNodeID: %s\n", config.AppOffloadConfig.AccessNodeID)
2454 }
2455}
2456
2457func (options *SetOnuOffload) Execute(args []string) error {
2458 // Create the gRPC client connection
Akash Soni51b6b7a2024-11-20 11:39:38 +05302459 conn, err := NewConnection()
2460 if err != nil {
2461 return fmt.Errorf("failed to establish gRPC connection: %v", err)
2462 }
2463 defer conn.Close()
2464
2465 client := extension.NewExtensionClient(conn)
2466
Akash Soni6e879c22024-12-20 17:01:34 +05302467 // Parse PerUniInfo into a slice of PerUniConfig
2468 var perUniConfigs []AppOffloadOnuConfig
2469 if err := json.Unmarshal([]byte(options.Args.PerUniInfo), &perUniConfigs); err != nil {
2470 return fmt.Errorf("failed to parse PerUniInfo as JSON: %v", err)
Akash Soni51b6b7a2024-11-20 11:39:38 +05302471 }
Akash Soni6e879c22024-12-20 17:01:34 +05302472
2473 // Convert to []*AppOffloadOnuConfig_PerUniConfig for gRPC
2474 var grpcPerUniInfo []*extension.AppOffloadOnuConfig_PerUniConfig
2475 for _, config := range perUniConfigs {
2476 grpcPerUniInfo = append(grpcPerUniInfo, &extension.AppOffloadOnuConfig_PerUniConfig{
2477 AgentRemoteID: config.AgentRemoteID,
2478 AgentCircuitID: config.AgentCircuitID,
2479 OnuUniId: config.OnuUniId,
2480 })
2481 }
2482
Akash Soni51b6b7a2024-11-20 11:39:38 +05302483 // Build the AppOffloadOnuConfig request
2484 onuConfig := &extension.AppOffloadOnuConfig{
2485 OnuDeviceId: options.Args.OnuDeviceId,
Akash Soni6e879c22024-12-20 17:01:34 +05302486 PerUniInfo: grpcPerUniInfo,
Akash Soni51b6b7a2024-11-20 11:39:38 +05302487 }
2488
2489 setValueRequest := &extension.SetValueRequest{
2490 Request: &extension.SetValueRequest_AppOffloadOnuConfig{
2491 AppOffloadOnuConfig: onuConfig,
2492 },
2493 }
2494
2495 singleSetValReq := &extension.SingleSetValueRequest{
Akash Soni6e879c22024-12-20 17:01:34 +05302496 TargetId: string(options.Args.OltId),
Akash Soni51b6b7a2024-11-20 11:39:38 +05302497 Request: setValueRequest,
2498 }
2499
Akash Soni6e879c22024-12-20 17:01:34 +05302500 // Log the request object
2501 logRequestAppOffloadOnuConfig(singleSetValReq)
2502
2503 // Make the gRPC call
Akash Soni51b6b7a2024-11-20 11:39:38 +05302504 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2505 defer cancel()
2506
2507 resp, err := client.SetExtValue(ctx, singleSetValReq)
2508 if err != nil {
2509 return fmt.Errorf("failed to set AppOffloadOnuConfig: %v", err)
2510 }
2511
2512 if resp.Response.Status != extension.SetValueResponse_OK {
Akash Soni6e879c22024-12-20 17:01:34 +05302513 return fmt.Errorf("operation failed with status %v: %s", resp.Response.Status, resp.Response.ErrReason)
Akash Soni51b6b7a2024-11-20 11:39:38 +05302514 }
2515
2516 fmt.Printf("AppOffloadOnuConfig successfully set for ONU ID: %s\n", options.Args.OnuDeviceId)
2517 return nil
2518}
2519
Akash Soni6e879c22024-12-20 17:01:34 +05302520// Debugging helper to log the gRPC request details
2521func logRequestAppOffloadOnuConfig(req *extension.SingleSetValueRequest) {
2522 fmt.Printf("Request details:\n")
2523 fmt.Printf("TargetId: %s\n", req.TargetId)
2524 fmt.Printf("OnuDeviceId: %s\n", req.Request.GetAppOffloadOnuConfig().OnuDeviceId)
2525 if config, ok := req.Request.Request.(*extension.SetValueRequest_AppOffloadOnuConfig); ok {
2526 fmt.Printf("AppOffloadOnuConfig:\n")
2527 for i, uniInfo := range config.AppOffloadOnuConfig.PerUniInfo {
2528 fmt.Printf(" UniInfo %d:\n", i+1)
2529 fmt.Printf(" AgentRemoteID: %s\n", uniInfo.AgentRemoteID)
2530 fmt.Printf(" AgentCircuitID: %s\n", uniInfo.AgentCircuitID)
2531 fmt.Printf(" OnuUniId: %d\n", uniInfo.OnuUniId)
2532 }
2533 }
2534}
2535
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +05302536func (options *GetPonPortStats) Execute(args []string) error {
2537 conn, err := NewConnection()
2538 if err != nil {
2539 return err
2540 }
2541 defer conn.Close()
2542 client := extension.NewExtensionClient(conn)
2543
2544 singleGetValReq := extension.SingleGetValueRequest{
2545 TargetId: string(options.Args.Id),
2546 Request: &extension.GetValueRequest{
2547 Request: &extension.GetValueRequest_OltPonStats{
2548 OltPonStats: &extension.GetPonStatsRequest{
2549 PortInfo: &extension.GetPonStatsRequest_PortLabel{
2550 PortLabel: options.Args.PortLabel,
2551 },
2552 },
2553 },
2554 },
2555 }
2556 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2557 defer cancel()
2558 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2559 if err != nil {
2560 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2561 return err
2562 }
2563
2564 if rv.Response.Status != extension.GetValueResponse_OK {
2565 return fmt.Errorf("failed to get pon port stats %v", rv.Response.ErrReason.String())
2566 }
2567 outputFormat := CharReplacer.Replace(options.Format)
2568 if outputFormat == "" {
2569 outputFormat = GetCommandOptionWithDefault("device-get-pon-stats", "format", DEFAULT_PON_PORT_STATS_FORMAT)
2570 }
2571 data := PortStats{
2572 PonPort: rv.GetResponse().GetOltPonStatsResponse().GetPonPort(),
2573 PortStatistics: rv.GetResponse().GetOltPonStatsResponse().GetPortStatistics(),
2574 }
2575 result := CommandResult{
2576 Format: format.Format(outputFormat),
2577 OutputAs: toOutputType(options.OutputAs),
2578 NameLimit: options.NameLimit,
2579 Data: data,
2580 }
2581 GenerateOutput(&result)
2582 return nil
2583}
2584
2585func (options *GetNniPortStats) Execute(args []string) error {
2586 conn, err := NewConnection()
2587 if err != nil {
2588 return err
2589 }
2590 defer conn.Close()
2591 client := extension.NewExtensionClient(conn)
2592
2593 singleGetValReq := extension.SingleGetValueRequest{
2594 TargetId: string(options.Args.Id),
2595 Request: &extension.GetValueRequest{
2596 Request: &extension.GetValueRequest_OltNniStats{
2597 OltNniStats: &extension.GetNNIStatsRequest{
2598 PortInfo: &extension.GetNNIStatsRequest_PortLabel{
2599 PortLabel: options.Args.PortLabel,
2600 },
2601 },
2602 },
2603 },
2604 }
2605 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2606 defer cancel()
2607 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2608 if err != nil {
2609 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2610 return err
2611 }
2612
2613 if rv.Response.Status != extension.GetValueResponse_OK {
2614 return fmt.Errorf("failed to get nni port stats %v", rv.Response.ErrReason.String())
2615 }
2616 outputFormat := CharReplacer.Replace(options.Format)
2617 if outputFormat == "" {
2618 outputFormat = GetCommandOptionWithDefault("device-get-nni-stats", "format", DEFAULT_NNI_PORT_STATS_FORMAT)
2619 }
2620 data := PortStats{
2621 NniPort: rv.GetResponse().GetOltNniStatsResponse().GetNniPort(),
2622 PortStatistics: rv.GetResponse().GetOltNniStatsResponse().GetPortStatistics(),
2623 }
2624 result := CommandResult{
2625 Format: format.Format(outputFormat),
2626 OutputAs: toOutputType(options.OutputAs),
2627 NameLimit: options.NameLimit,
2628 Data: data,
2629 }
2630 GenerateOutput(&result)
2631 return nil
2632}
2633
Himani Chawla553a1392021-06-10 23:39:17 +05302634func (options *GetOnuEthernetFrameExtendedPmCounters) Execute(args []string) error {
2635 conn, err := NewConnection()
2636 if err != nil {
2637 return err
2638 }
2639 defer conn.Close()
2640 client := extension.NewExtensionClient(conn)
Himani Chawla806aa892021-08-30 15:51:46 +05302641 var singleGetValReq extension.SingleGetValueRequest
Himani Chawla553a1392021-06-10 23:39:17 +05302642
Himani Chawla806aa892021-08-30 15:51:46 +05302643 if options.Args.UniIndex != nil {
2644 singleGetValReq = extension.SingleGetValueRequest{
2645 TargetId: string(options.Args.Id),
2646 Request: &extension.GetValueRequest{
2647 Request: &extension.GetValueRequest_OnuInfo{
2648 OnuInfo: &extension.GetOmciEthernetFrameExtendedPmRequest{
2649 OnuDeviceId: string(options.Args.Id),
2650 Reset_: options.Reset,
2651 IsUniIndex: &extension.GetOmciEthernetFrameExtendedPmRequest_UniIndex{
2652 UniIndex: *options.Args.UniIndex,
2653 },
2654 },
Himani Chawla553a1392021-06-10 23:39:17 +05302655 },
2656 },
Himani Chawla806aa892021-08-30 15:51:46 +05302657 }
2658 } else {
2659 singleGetValReq = extension.SingleGetValueRequest{
2660 TargetId: string(options.Args.Id),
2661 Request: &extension.GetValueRequest{
2662 Request: &extension.GetValueRequest_OnuInfo{
2663 OnuInfo: &extension.GetOmciEthernetFrameExtendedPmRequest{
2664 OnuDeviceId: string(options.Args.Id),
2665 Reset_: options.Reset,
2666 },
2667 },
2668 },
2669 }
Himani Chawla553a1392021-06-10 23:39:17 +05302670 }
Himani Chawla806aa892021-08-30 15:51:46 +05302671
Himani Chawla553a1392021-06-10 23:39:17 +05302672 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2673 defer cancel()
2674 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2675 if err != nil {
2676 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2677 return err
2678 }
2679
2680 if rv.Response.Status != extension.GetValueResponse_OK {
2681 return fmt.Errorf("failed to get ethernet frame extended pm counters %v", rv.Response.ErrReason.String())
2682 }
2683 outputFormat := CharReplacer.Replace(options.Format)
2684 data := buildOnuEthernetFrameExtendedPmOutputFormat(rv.GetResponse().GetOnuCounters())
2685 if outputFormat == "" {
2686 outputFormat = GetCommandOptionWithDefault("device-get-onu-status", "format", DEFAULT_ETHERNET_FRAME_EXTENDED_PM_COUNTERS_FORMAT)
2687 }
Himani Chawla40acc122021-05-26 18:52:29 +05302688 result := CommandResult{
2689 Format: format.Format(outputFormat),
2690 OutputAs: toOutputType(options.OutputAs),
2691 NameLimit: options.NameLimit,
2692 Data: data,
2693 }
2694 GenerateOutput(&result)
2695 return nil
2696}
2697
kesavand6d1131f2021-02-05 22:38:15 +05302698func (options *UniStatus) Execute(args []string) error {
2699 conn, err := NewConnection()
2700 if err != nil {
2701 return err
2702 }
2703 defer conn.Close()
2704 client := extension.NewExtensionClient(conn)
2705
2706 singleGetValReq := extension.SingleGetValueRequest{
2707 TargetId: string(options.Args.Id),
2708 Request: &extension.GetValueRequest{
2709 Request: &extension.GetValueRequest_UniInfo{
2710 UniInfo: &extension.GetOnuUniInfoRequest{
2711 UniIndex: options.Args.UniIndex,
2712 },
2713 },
2714 },
2715 }
David K. Bainbridge9189c632021-03-26 21:52:21 +00002716 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand6d1131f2021-02-05 22:38:15 +05302717 defer cancel()
2718 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2719 if err != nil {
2720 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2721 return err
2722 }
2723 if rv.Response.Status != extension.GetValueResponse_OK {
2724 return fmt.Errorf("failed to get uni status %v", rv.Response.ErrReason.String())
2725 }
2726 outputFormat := CharReplacer.Replace(options.Format)
2727 if outputFormat == "" {
2728 outputFormat = GetCommandOptionWithDefault("device-get-uni-status", "format", DEFAULT_DEVICE_GET_UNI_STATUS_FORMAT)
2729 }
2730 result := CommandResult{
2731 Format: format.Format(outputFormat),
2732 OutputAs: toOutputType(options.OutputAs),
2733 NameLimit: options.NameLimit,
2734 Data: rv.GetResponse().GetUniInfo(),
2735 }
2736 GenerateOutput(&result)
2737 return nil
2738}
2739
Girish Gowdra4f5ce7c2021-04-29 18:53:21 -07002740func (options *OnuPonOpticalInfo) Execute(args []string) error {
2741 conn, err := NewConnection()
2742 if err != nil {
2743 return err
2744 }
2745 defer conn.Close()
2746 client := extension.NewExtensionClient(conn)
2747
2748 singleGetValReq := extension.SingleGetValueRequest{
2749 TargetId: string(options.Args.Id),
2750 Request: &extension.GetValueRequest{
2751 Request: &extension.GetValueRequest_OnuOpticalInfo{
2752 OnuOpticalInfo: &extension.GetOnuPonOpticalInfo{},
2753 },
2754 },
2755 }
2756 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2757 defer cancel()
2758 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2759 if err != nil {
2760 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2761 return err
2762 }
2763 if rv.Response.Status != extension.GetValueResponse_OK {
2764 return fmt.Errorf("failed to get onu pon optical info %v", rv.Response.ErrReason.String())
2765 }
2766 outputFormat := CharReplacer.Replace(options.Format)
2767 if outputFormat == "" {
2768 outputFormat = GetCommandOptionWithDefault("device-get-onu-pon-optical-info", "format", DEFAULT_ONU_PON_OPTICAL_INFO_STATUS_FORMAT)
2769 }
2770 result := CommandResult{
2771 Format: format.Format(outputFormat),
2772 OutputAs: toOutputType(options.OutputAs),
2773 NameLimit: options.NameLimit,
2774 Data: rv.GetResponse().GetOnuOpticalInfo(),
2775 }
2776 GenerateOutput(&result)
2777 return nil
2778}
2779
Gamze Abakac857a462021-05-26 13:45:54 +00002780func (options *RxPower) Execute(args []string) error {
2781 conn, err := NewConnection()
2782 if err != nil {
2783 return err
2784 }
2785 defer conn.Close()
2786 client := extension.NewExtensionClient(conn)
2787
2788 singleGetValReq := extension.SingleGetValueRequest{
2789 TargetId: string(options.Args.Id),
2790 Request: &extension.GetValueRequest{
2791 Request: &extension.GetValueRequest_RxPower{
2792 RxPower: &extension.GetRxPowerRequest{
2793 IntfId: options.Args.PortNo,
2794 OnuId: options.Args.OnuNo,
2795 },
2796 },
2797 },
2798 }
2799
2800 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2801 defer cancel()
2802 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2803 if err != nil {
2804 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2805 return err
2806 }
2807 if rv.Response.Status != extension.GetValueResponse_OK {
2808 return fmt.Errorf("failed to get rx power %v", rv.Response.ErrReason.String())
2809 }
2810 outputFormat := CharReplacer.Replace(options.Format)
2811 if outputFormat == "" {
2812 outputFormat = GetCommandOptionWithDefault("device-get-rx-power", "format", DEFAULT_RX_POWER_STATUS_FORMAT)
2813 }
2814 result := CommandResult{
2815 Format: format.Format(outputFormat),
2816 OutputAs: toOutputType(options.OutputAs),
2817 NameLimit: options.NameLimit,
2818 Data: rv.GetResponse().GetRxPower(),
2819 }
2820 GenerateOutput(&result)
2821 return nil
2822}
2823
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002824/*Device get Onu Distance */
2825func (options *DeviceGetExtValue) Execute(args []string) error {
2826 conn, err := NewConnection()
2827 if err != nil {
2828 return err
2829 }
2830 defer conn.Close()
2831
Scott Baker9173ed82020-05-19 08:30:12 -07002832 client := voltha.NewVolthaServiceClient(conn)
2833
khenaidoo080ce882021-10-19 17:35:08 -04002834 valueflag, okay := extension.ValueType_Type_value[string(options.Args.Valueflag)]
Scott Baker9173ed82020-05-19 08:30:12 -07002835 if !okay {
2836 Error.Printf("Unknown valueflag %s\n", options.Args.Valueflag)
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002837 }
2838
khenaidoo080ce882021-10-19 17:35:08 -04002839 val := extension.ValueSpecifier{Id: string(options.Args.Id), Value: extension.ValueType_Type(valueflag)}
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002840
David K. Bainbridge9189c632021-03-26 21:52:21 +00002841 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002842 defer cancel()
2843
Scott Baker9173ed82020-05-19 08:30:12 -07002844 rv, err := client.GetExtValue(ctx, &val)
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002845 if err != nil {
2846 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2847 return err
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002848 }
2849
Scott Baker9173ed82020-05-19 08:30:12 -07002850 var rows []ReturnValueRow
khenaidoo080ce882021-10-19 17:35:08 -04002851 for name, num := range extension.ValueType_Type_value {
Scott Baker9173ed82020-05-19 08:30:12 -07002852 if num == 0 {
2853 // EMPTY is not a real value
2854 continue
2855 }
2856 if (rv.Error & uint32(num)) != 0 {
2857 row := ReturnValueRow{Name: name, Result: "Error"}
2858 rows = append(rows, row)
2859 }
2860 if (rv.Unsupported & uint32(num)) != 0 {
2861 row := ReturnValueRow{Name: name, Result: "Unsupported"}
2862 rows = append(rows, row)
2863 }
2864 if (rv.Set & uint32(num)) != 0 {
2865 switch name {
2866 case "DISTANCE":
2867 row := ReturnValueRow{Name: name, Result: rv.Distance}
2868 rows = append(rows, row)
2869 default:
2870 row := ReturnValueRow{Name: name, Result: "Unimplemented-in-voltctl"}
2871 rows = append(rows, row)
2872 }
2873 }
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002874 }
2875
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002876 outputFormat := CharReplacer.Replace(options.Format)
2877 if outputFormat == "" {
2878 outputFormat = GetCommandOptionWithDefault("device-value-get", "format", DEFAULT_DEVICE_VALUE_GET_FORMAT)
2879 }
2880
2881 result := CommandResult{
2882 Format: format.Format(outputFormat),
2883 OutputAs: toOutputType(options.OutputAs),
2884 NameLimit: options.NameLimit,
Scott Baker9173ed82020-05-19 08:30:12 -07002885 Data: rows,
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002886 }
2887 GenerateOutput(&result)
2888 return nil
2889}
serkantul3d22fc72022-09-14 12:22:56 +03002890
2891/*Device get Onu OMCI TX RX Stats */
2892func (options *OnuOmciTxRxStats) Execute(args []string) error {
2893 conn, err := NewConnection()
2894 if err != nil {
2895 return err
2896 }
2897 defer conn.Close()
2898 client := extension.NewExtensionClient(conn)
2899
2900 singleGetValReq := extension.SingleGetValueRequest{
2901 TargetId: string(options.Args.Id),
2902 Request: &extension.GetValueRequest{
2903 Request: &extension.GetValueRequest_OnuOmciStats{
2904 OnuOmciStats: &extension.GetOnuOmciTxRxStatsRequest{},
2905 },
2906 },
2907 }
2908
2909 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2910 defer cancel()
2911 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2912 if err != nil {
2913 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2914 return err
2915 }
2916
2917 if rv.Response.Status != extension.GetValueResponse_OK {
2918 return fmt.Errorf("failed to get onu omci tx rx stats %v", rv.Response.ErrReason.String())
2919 }
2920 outputFormat := CharReplacer.Replace(options.Format)
2921 if outputFormat == "" {
2922 outputFormat = GetCommandOptionWithDefault("device-get-onu-omci-tx-rx-stats", "format", DEFAULT_ONU_OMCI_TX_RX_STATS_FORMAT)
2923 }
2924 result := CommandResult{
2925 Format: format.Format(outputFormat),
2926 OutputAs: toOutputType(options.OutputAs),
2927 NameLimit: options.NameLimit,
2928 Data: rv.GetResponse().GetOnuOmciStats(),
2929 }
2930 GenerateOutput(&result)
2931 return nil
2932}
praneeth nalmas1dd094c2022-12-22 14:15:13 +05302933
2934/*Device get Onu Active Alarms */
2935func (options *GetOnuOmciActiveAlarms) Execute(args []string) error {
2936 conn, err := NewConnection()
2937 if err != nil {
2938 return err
2939 }
2940 defer conn.Close()
2941 client := extension.NewExtensionClient(conn)
2942
2943 singleGetValReq := extension.SingleGetValueRequest{
2944 TargetId: string(options.Args.Id),
2945 Request: &extension.GetValueRequest{
2946 Request: &extension.GetValueRequest_OnuActiveAlarms{
2947 OnuActiveAlarms: &extension.GetOnuOmciActiveAlarmsRequest{},
2948 },
2949 },
2950 }
2951 Info.Printf("Getting omci_active_alarms for device Id %s\n", options.Args.Id)
2952 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2953 defer cancel()
2954 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2955 if err != nil {
2956 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2957 return err
2958 }
2959
2960 if rv.Response.Status != extension.GetValueResponse_OK {
2961 return fmt.Errorf("failed to get onu omci active alarms list %v", rv.Response.ErrReason.String())
2962 }
2963 outputFormat := CharReplacer.Replace(options.Format)
2964 if outputFormat == "" {
2965 outputFormat = GetCommandOptionWithDefault("device-get-onu-omci-active-alarms", "format", DEFAULT_DEVICE_ALARMS_FORMAT)
2966 }
2967
2968 orderBy := options.OrderBy
2969 if orderBy == "" {
2970 orderBy = GetCommandOptionWithDefault("device-list", "order", DEFAULT_DEVICE_ALARMS_ORDER)
2971 }
2972
2973 result := CommandResult{
2974 Format: format.Format(outputFormat),
2975 OutputAs: toOutputType(options.OutputAs),
2976 OrderBy: orderBy,
2977 NameLimit: options.NameLimit,
2978 Data: rv.GetResponse().GetOnuActiveAlarms().GetActiveAlarms(),
2979 }
2980 GenerateOutput(&result)
2981 return nil
2982}
praneeth nalmas39c71ad2023-09-27 18:29:04 +05302983
Akash Soni66db9632024-04-15 09:05:15 +05302984/*Device get Onu Active Alarms */
2985func (options *GetOnuDistance) Execute(args []string) error {
2986 conn, err := NewConnection()
2987 if err != nil {
2988 return err
2989 }
2990 defer conn.Close()
2991 client := extension.NewExtensionClient(conn)
2992
2993 singleGetValReq := extension.SingleGetValueRequest{
2994 TargetId: string(options.Args.Id),
2995 Request: &extension.GetValueRequest{
2996 Request: &extension.GetValueRequest_Distance{
2997 Distance: &extension.GetDistanceRequest{
2998 OnuDeviceId: string(options.Args.OnuId),
2999 },
3000 },
3001 },
3002 }
3003 Info.Printf("Getting onu distance for device Id %s\n", options.Args.Id)
3004 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3005 defer cancel()
3006 rv, err := client.GetExtValue(ctx, &singleGetValReq)
3007 if err != nil {
3008 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
3009 return err
3010 }
3011
3012 if rv.Response.Status != extension.GetValueResponse_OK {
3013 return fmt.Errorf("failed to get onu distance stats %v", rv.Response.ErrReason.String())
3014 }
3015 outputFormat := CharReplacer.Replace(options.Format)
3016 if outputFormat == "" {
3017 outputFormat = GetCommandOptionWithDefault("get-onu-distance", "format", DEFAULT_ONU_DISTANCE_FORMAT)
3018 }
3019
3020 result := CommandResult{
3021 Format: format.Format(outputFormat),
3022 OutputAs: toOutputType(options.OutputAs),
3023 NameLimit: options.NameLimit,
3024 Data: rv.GetResponse().GetDistance().GetDistance(),
3025 }
3026 fmt.Println("onu distance : ", rv)
3027 GenerateOutput(&result)
3028 return nil
3029}
3030
praneeth nalmas39c71ad2023-09-27 18:29:04 +05303031func (options *PonRxPower) Execute(args []string) error {
3032 conn, err := NewConnection()
3033 if err != nil {
3034 return err
3035 }
3036 defer conn.Close()
3037 client := extension.NewExtensionClient(conn)
3038
3039 singleGetValReq := extension.SingleGetValueRequest{
3040 TargetId: string(options.Args.Id),
3041 Request: &extension.GetValueRequest{
3042 Request: &extension.GetValueRequest_OltRxPower{
3043 OltRxPower: &extension.GetOltRxPowerRequest{
3044 PortLabel: options.Args.PortLabel,
3045 OnuSn: options.Args.SerialNo,
3046 },
3047 },
3048 },
3049 }
3050
3051 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3052 defer cancel()
3053 rv, err := client.GetExtValue(ctx, &singleGetValReq)
3054 if err != nil {
3055 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
3056 return err
3057 }
3058 if rv.Response.Status != extension.GetValueResponse_OK {
3059 return fmt.Errorf("failed to get rx power %v", rv.Response.ErrReason.String())
3060 }
3061 outputFormat := CharReplacer.Replace(options.Format)
3062 if outputFormat == "" {
3063 outputFormat = GetCommandOptionWithDefault("device-get-pon-rx-power", "format", DEFAULT_PON_RX_POWER_STATUS_FORMAT)
3064 }
3065 result := CommandResult{
3066 Format: format.Format(outputFormat),
3067 OutputAs: toOutputType(options.OutputAs),
3068 NameLimit: options.NameLimit,
3069 Data: rv.GetResponse().GetOltRxPower().GetRxPower(),
3070 }
3071 GenerateOutput(&result)
3072 return nil
3073}
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +05303074
3075func (options *GetOnuGEMStats) Execute(args []string) error {
3076
3077 conn, err := NewConnection()
3078 if err != nil {
3079 return err
3080 }
3081 defer conn.Close()
3082 client := extension.NewExtensionClient(conn)
3083 singleGetValReq := extension.SingleGetValueRequest{
3084 TargetId: string(options.Args.Id),
3085 Request: &extension.GetValueRequest{
3086 Request: &extension.GetValueRequest_OnuAllocGemStats{
3087 OnuAllocGemStats: &extension.GetOnuAllocGemHistoryRequest{},
3088 },
3089 },
3090 }
3091
3092 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3093 defer cancel()
3094
3095 rv, err := client.GetExtValue(ctx, &singleGetValReq)
3096
3097 if err != nil {
3098 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
3099 return err
3100 }
3101
3102 if rv.Response.Status != extension.GetValueResponse_OK {
3103 return fmt.Errorf("failed to get gem port response %v", rv.Response.ErrReason.String())
3104 }
3105 outputFormat := CharReplacer.Replace(options.Format)
3106 if outputFormat == "" {
3107 outputFormat = GetCommandOptionWithDefault("device-get-gem-port", "format", DEFAULT_DEVICE_VALUE_GEM_PORT_FORMAT)
3108 }
3109 onugemhistoryresponse := rv.GetResponse().GetOnuAllocGemStatsResponse()
3110 for _, OnuallocGemHistoryData := range onugemhistoryresponse.OnuAllocGemHistoryData {
3111 data := onugemstats{}
3112 data.AllocId = OnuallocGemHistoryData.OnuAllocIdInfo.AllocId
3113 data.AllocRxBytes = OnuallocGemHistoryData.OnuAllocIdInfo.RxBytes
3114 for _, gemStatsInfo := range OnuallocGemHistoryData.GemPortInfo {
3115 data.GemHistoryStats = append(data.GemHistoryStats, gemHistoryStats{
3116 GemId: gemStatsInfo.GemId,
3117 TransmittedGEMFrames: gemStatsInfo.TransmittedGEMFrames,
3118 ReceivedGEMFrames: gemStatsInfo.ReceivedGEMFrames,
Akash Reddy Kankanalaeba72f62026-01-29 12:49:17 +00003119 ReceivedPayloadBytes: gemStatsInfo.ReceivedPayloadBytes_64,
3120 TransmittedPayloadBytes: gemStatsInfo.TransmittedPayloadBytes_64,
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +05303121 EncryptionKeyErrors: gemStatsInfo.EncryptionKeyErrors,
3122 })
3123 }
3124 result := CommandResult{
3125 Format: format.Format(outputFormat),
3126 OutputAs: toOutputType(options.OutputAs),
3127 NameLimit: options.NameLimit,
3128 Data: &data,
3129 }
3130 GenerateOutput(&result)
3131 }
3132 return nil
3133
3134}
3135
Akash Reddy Kankanala6965c652025-10-15 23:30:16 +05303136func (options *GetOnuFecHistory) Execute(args []string) error {
3137 conn, err := NewConnection()
3138 if err != nil {
3139 return err
3140 }
3141 defer conn.Close()
3142 client := extension.NewExtensionClient(conn)
3143 singleGetValReq := extension.SingleGetValueRequest{
3144 TargetId: string(options.Args.Id),
3145 Request: &extension.GetValueRequest{
3146 Request: &extension.GetValueRequest_FecHistory{
3147 FecHistory: &extension.GetOnuFecHistory{},
3148 },
3149 },
3150 }
3151 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3152 defer cancel()
3153 rv, err := client.GetExtValue(ctx, &singleGetValReq)
3154 if err != nil {
3155 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
3156 return err
3157 }
3158 if rv.Response.Status != extension.GetValueResponse_OK {
3159 return fmt.Errorf("Failed to get onu FEC history stats from ONT %v", rv.Response.ErrReason.String())
3160 }
3161
3162 outputFormat := CharReplacer.Replace(options.Format)
3163 if outputFormat == "" {
3164 outputFormat = GetCommandOptionWithDefault("device-get-onu-fec-History", "format", DEFAULT_ONU_FEC_HISTORY_FORMAT)
3165 }
3166 result := CommandResult{
3167 Format: format.Format(outputFormat),
3168 OutputAs: toOutputType(options.OutputAs),
3169 NameLimit: options.NameLimit,
3170 Data: rv.GetResponse().GetFecHistory(),
3171 }
3172 GenerateOutput(&result)
3173 return nil
3174
3175}
3176
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +05303177func (options *GetOnuAllocGemStatsFromOlt) Execute(args []string) error {
3178 conn, err := NewConnection()
3179 if err != nil {
3180 return err
3181 }
3182 defer conn.Close()
3183 client := extension.NewExtensionClient(conn)
3184
3185 singleGetValReq := extension.SingleGetValueRequest{
3186 TargetId: string(options.Args.Id),
3187 Request: &extension.GetValueRequest{
3188 Request: &extension.GetValueRequest_OnuStatsFromOlt{
3189 OnuStatsFromOlt: &extension.GetOnuStatsFromOltRequest{},
3190 },
3191 },
3192 }
3193 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3194 defer cancel()
3195 rv, err := client.GetExtValue(ctx, &singleGetValReq)
3196 if err != nil {
3197 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
3198 return err
3199 }
3200
3201 if rv.Response.Status != extension.GetValueResponse_OK {
3202 return fmt.Errorf("failed to get onu alloc gem stats from olt %v", rv.Response.ErrReason.String())
3203 }
3204 outputFormat := CharReplacer.Replace(options.Format)
3205 if outputFormat == "" {
3206 outputFormat = GetCommandOptionWithDefault("device-get-onu-status", "format", DEFAULT_ONU_STATS_FROM_OLT_FORMAT)
3207 }
3208
3209 onuAllocGemStatsResponse := rv.GetResponse().GetOnuStatsFromOltResponse()
3210
3211 for _, allocGemStatsInfo := range onuAllocGemStatsResponse.AllocGemStatsInfo {
3212 data := AllocGemStatsFromOlt{}
3213 data.AllocId = allocGemStatsInfo.AllocIdInfo.AllocId
3214 data.AllocRxBytes = allocGemStatsInfo.AllocIdInfo.RxBytes
3215 for _, gemStatsInfo := range allocGemStatsInfo.GemPortInfo {
3216 data.GemPortStats = append(data.GemPortStats, GemPortStatsFromOlt{
3217 GemId: gemStatsInfo.GemId,
3218 RxBytes: gemStatsInfo.RxBytes,
3219 RxPackets: gemStatsInfo.RxPackets,
3220 TxBytes: gemStatsInfo.TxBytes,
3221 TxPackets: gemStatsInfo.TxPackets,
3222 })
3223 }
3224 result := CommandResult{
3225 Format: format.Format(outputFormat),
3226 OutputAs: toOutputType(options.OutputAs),
3227 NameLimit: options.NameLimit,
3228 Data: &data,
3229 }
3230 GenerateOutput(&result)
3231 }
3232
3233 return nil
3234}
mgouda35b90e62025-07-16 14:58:29 +05303235
3236func (options *DisableOnuDevice) Execute(args []string) error {
3237 conn, err := NewConnection()
3238 if err != nil {
3239 return err
3240 }
3241 defer conn.Close()
3242
3243 client := voltha.NewVolthaServiceClient(conn)
3244
3245 var lastErr error
3246 for _, i := range options.Args.Ids {
3247 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3248 defer cancel()
3249
3250 id := voltha.ID{Id: string(i)}
3251
3252 _, err := client.DisableOnuDevice(ctx, &id)
3253 if err != nil {
3254 Error.Printf("Error while disabling the onu serial number'%s': %s\n", i, err)
3255 lastErr = err
3256 continue
3257 }
3258 fmt.Printf("%s\n", i)
3259 }
3260
3261 if lastErr != nil {
3262 return NoReportErr
3263 }
3264 return nil
3265}
3266
3267func (options *EnableOnuDevice) Execute(args []string) error {
3268 conn, err := NewConnection()
3269 if err != nil {
3270 return err
3271 }
3272 defer conn.Close()
3273
3274 client := voltha.NewVolthaServiceClient(conn)
3275
3276 var lastErr error
3277 for _, i := range options.Args.Ids {
3278 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3279 defer cancel()
3280
3281 id := voltha.ID{Id: string(i)}
3282
3283 _, err := client.EnableOnuDevice(ctx, &id)
3284 if err != nil {
3285 Error.Printf("Error while enabling the onu serial number'%s': %s\n", i, err)
3286 lastErr = err
3287 continue
3288 }
3289 fmt.Printf("%s\n", i)
3290 }
3291
3292 if lastErr != nil {
3293 return NoReportErr
3294 }
3295 return nil
3296}
3297
3298func (options *DisableOnuSerialNumber) 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 id := common.ID{Id: string(options.Args.OltDeviceId)}
3308 port := voltha.Port{PortNo: uint32(options.Args.Port)}
3309
3310 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3311 defer cancel()
3312
3313 req := &voltha.OnuSerialNumberOnOLTPon{
3314 OltDeviceId: &id,
3315 SerialNumber: options.Args.SerialNumber,
3316 Port: &port,
3317 }
3318
3319 _, err = client.DisableOnuSerialNumber(ctx, req)
3320 if err != nil {
3321 Error.Printf("Error disabling ONU serial '%s' on OLT '%s': %v\n", options.Args.SerialNumber, options.Args.OltDeviceId, err)
3322 return err
3323 }
3324 fmt.Printf("Disabled ONU serial '%s' on OLT '%s'\n", options.Args.SerialNumber, options.Args.OltDeviceId)
3325 return nil
3326}
3327
3328func (options *EnableOnuSerialNumber) Execute(args []string) error {
3329 conn, err := NewConnection()
3330 if err != nil {
3331 return err
3332 }
3333 defer conn.Close()
3334
3335 client := voltha.NewVolthaServiceClient(conn)
3336
3337 id := common.ID{Id: string(options.Args.OltDeviceId)}
3338 port := voltha.Port{PortNo: uint32(options.Args.Port)}
3339
3340 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3341 defer cancel()
3342
3343 req := &voltha.OnuSerialNumberOnOLTPon{
3344 OltDeviceId: &id,
3345 SerialNumber: options.Args.SerialNumber,
3346 Port: &port,
3347 }
3348
3349 _, err = client.EnableOnuSerialNumber(ctx, req)
3350 if err != nil {
3351 Error.Printf("Error enabling ONU serial '%s' on OLT '%s': %v\n", options.Args.SerialNumber, options.Args.OltDeviceId, err)
3352 return err
3353 }
3354 fmt.Printf("Enabled ONU serial '%s' on OLT '%s'\n", options.Args.SerialNumber, options.Args.OltDeviceId)
3355 return nil
3356}