blob: eb65adbb6bf06388452555f19b72634a0d45c013 [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}}
139RxPackets: {{.RxPackets}}
140RxUcastPackets: {{.RxUcastPackets}}
141RxMcastPackets: {{.RxMcastPackets}}
142RxBcastPackets: {{.RxBcastPackets}}
143RxErrorPackets: {{.RxErrorPackets}}
144RxFcsErrorPackets: {{.RxFcsErrorPackets}}
145RxUndersizePackets: {{.RxUndersizePackets}}
146RxOversizePackets: {{.RxOversizePackets}}
147TxBytes: {{.TxBytes}}
148TxPackets: {{.TxPackets}}
149TxUcastPackets: {{.TxUcastPackets}}
150TxMcastPackets: {{.TxMcastPackets}}
151TxBcastPackets: {{.TxBcastPackets}}
152TxErrorPackets: {{.TxErrorPackets}}
153TxUndersizePackets: {{.TxUndersizePackets}}
154TxOversizePackets: {{.TxOversizePackets}}`
155
serkantul3d22fc72022-09-14 12:22:56 +0300156 DEFAULT_ONU_OMCI_TX_RX_STATS_FORMAT = `BaseTxArFrames: {{.BaseTxArFrames}}
157BaseRxAkFrames: {{.BaseRxAkFrames}}
158BaseTxNoArFrames: {{.BaseTxNoArFrames}}
159BaseRxNoAkFrames: {{.BaseRxNoAkFrames}}
160ExtTxArFrames: {{.ExtTxArFrames}}
161ExtRxAkFrames: {{.ExtRxAkFrames}}
162ExtTxNoArFrames: {{.ExtTxNoArFrames}}
163ExtRxNoAkFrames: {{.ExtRxNoAkFrames}}
164TxOmciCounterRetries: {{.TxOmciCounterRetries}}
165TxOmciCounterTimeouts: {{.TxOmciCounterTimeouts}}`
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +0530166 DEFAULT_ONU_STATS_FROM_OLT_FORMAT = `AllocId: {{.AllocId}}
167AllocRxBytes: {{.AllocRxBytes}}
168{{range .GemPortStats}}
169-GemId: {{.GemId}}
170 RxPackets: {{.RxPackets}}
171 RxBytes: {{.RxBytes}}
172 TxPackets: {{.TxPackets}}
173 TxBytes: {{.TxBytes}}{{end}}`
Akash Reddy Kankanala6965c652025-10-15 23:30:16 +0530174 DEFAULT_ONU_FEC_HISTORY_FORMAT = `CorrectedBytes: {{.CorrectedBytes}}
175CorrectedCodeWords: {{.CorrectedCodeWords}}
176FecSeconds: {{.FecSeconds}}
177TotalCodeWords: {{.TotalCodeWords}}
178UncorrectableCodeWords: {{.UncorrectableCodeWords}}`
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +0530179
180 DEFAULT_ONU_DISTANCE_FORMAT = `Distance`
181 DEFAULT_DEVICE_ALARMS_FORMAT = "table{{ .ClassId }}\t{{.InstanceId}}\t{{.Name}}\t{{.Description}}"
182 DEFAULT_DEVICE_ALARMS_ORDER = "ClassId,InstanceId"
183 DEFAULT_PON_RX_POWER_STATUS_FORMAT = "table{{.OnuSn}}\t{{.Status}}\t{{.FailReason}}\t{{.RxPower}}\t"
184 DEFAULT_DEVICE_VALUE_GEM_PORT_FORMAT = `AllocId: {{.AllocId}}
185 AllocRxBytes: {{.AllocRxBytes}}
186 {{range .GemHistoryStats}}
187-GemId: {{.GemId}}
188 TransmittedGEMFrames: {{.TransmittedGEMFrames}}
189 ReceivedGEMFrames: {{.ReceivedGEMFrames}}
190 ReceivedPayloadBytes: {{.ReceivedPayloadBytes}}
191 TransmittedPayloadBytes:{{.TransmittedPayloadBytes}}
192 EncryptionKeyErrors: {{.EncryptionKeyErrors}}{{end}}`
Zack Williamse940c7a2019-08-21 14:25:39 -0700193)
194
195type DeviceList struct {
196 ListOutputOptions
197}
198
199type DeviceCreate struct {
David Bainbridge1a514392020-06-23 11:12:51 -0700200 DeviceType string `short:"t" required:"true" long:"devicetype" description:"Device type"`
David Bainbridge835dd0e2020-04-01 10:30:09 -0700201 MACAddress string `short:"m" long:"macaddress" default:"" description:"MAC Address"`
Zack Williamse940c7a2019-08-21 14:25:39 -0700202 IPAddress string `short:"i" long:"ipaddress" default:"" description:"IP Address"`
203 HostAndPort string `short:"H" long:"hostandport" default:"" description:"Host and port"`
204}
205
206type DeviceId string
Akash Soni66db9632024-04-15 09:05:15 +0530207type OnuId string
Zack Williamse940c7a2019-08-21 14:25:39 -0700208
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000209type MetricName string
210type GroupName string
kesavand12cd8eb2020-01-20 22:25:22 -0500211type PortNum uint32
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -0800212type ValueFlag string
kesavand12cd8eb2020-01-20 22:25:22 -0500213
Zack Williamse940c7a2019-08-21 14:25:39 -0700214type DeviceDelete struct {
Himani Chawla9933ddc2020-10-12 23:53:27 +0530215 Force bool `long:"force" description:"Delete device forcefully"`
216 Args struct {
Zack Williamse940c7a2019-08-21 14:25:39 -0700217 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
218 } `positional-args:"yes"`
219}
220
221type DeviceEnable struct {
222 Args struct {
223 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
224 } `positional-args:"yes"`
225}
226
227type DeviceDisable struct {
228 Args struct {
229 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
230 } `positional-args:"yes"`
231}
232
233type DeviceReboot struct {
234 Args struct {
235 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
236 } `positional-args:"yes"`
237}
238
239type DeviceFlowList struct {
240 ListOutputOptions
Maninder045921e2020-09-29 16:46:02 +0530241 FlowIdOptions
Zack Williamse940c7a2019-08-21 14:25:39 -0700242 Args struct {
243 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
244 } `positional-args:"yes"`
245}
246
Himani Chawla3c161c62021-05-13 16:36:51 +0530247type DeviceFlowGroupList struct {
248 ListOutputOptions
249 GroupListOptions
250 Args struct {
251 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
252 } `positional-args:"yes"`
253}
Zack Williamse940c7a2019-08-21 14:25:39 -0700254type DevicePortList struct {
255 ListOutputOptions
256 Args struct {
257 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
258 } `positional-args:"yes"`
259}
260
261type DeviceInspect struct {
262 OutputOptionsJson
263 Args struct {
264 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
265 } `positional-args:"yes"`
266}
267
kesavand12cd8eb2020-01-20 22:25:22 -0500268type DevicePortEnable struct {
269 Args struct {
270 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
271 PortId PortNum `positional-arg-name:"PORT_NUMBER" required:"yes"`
272 } `positional-args:"yes"`
273}
274
275type DevicePortDisable struct {
276 Args struct {
277 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
278 PortId PortNum `positional-arg-name:"PORT_NUMBER" required:"yes"`
279 } `positional-args:"yes"`
280}
281
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000282type DevicePmConfigsGet struct {
283 ListOutputOptions
284 Args struct {
285 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
286 } `positional-args:"yes"`
287}
288
289type DevicePmConfigMetricList struct {
290 ListOutputOptions
291 Args struct {
292 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
293 } `positional-args:"yes"`
294}
295
296type DevicePmConfigGroupList struct {
297 ListOutputOptions
298 Args struct {
299 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
300 } `positional-args:"yes"`
301}
302
303type DevicePmConfigGroupMetricList struct {
304 ListOutputOptions
305 Args struct {
306 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
307 Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"`
308 } `positional-args:"yes"`
309}
310
311type DevicePmConfigFrequencySet struct {
312 OutputOptions
313 Args struct {
Girish Gowdra610acb42021-01-27 13:33:57 -0800314 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
315 Interval time.Duration `positional-arg-name:"INTERVAL" required:"yes"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000316 } `positional-args:"yes"`
317}
318
319type DevicePmConfigMetricEnable struct {
320 Args struct {
321 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
322 Metrics []MetricName `positional-arg-name:"METRIC_NAME" required:"yes"`
323 } `positional-args:"yes"`
324}
325
326type DevicePmConfigMetricDisable struct {
327 Args struct {
328 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
329 Metrics []MetricName `positional-arg-name:"METRIC_NAME" required:"yes"`
330 } `positional-args:"yes"`
331}
332
333type DevicePmConfigGroupEnable struct {
334 Args struct {
Girish Gowdra610acb42021-01-27 13:33:57 -0800335 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
336 Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000337 } `positional-args:"yes"`
338}
339
340type DevicePmConfigGroupDisable struct {
341 Args struct {
Girish Gowdra610acb42021-01-27 13:33:57 -0800342 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
343 Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"`
344 } `positional-args:"yes"`
345}
346
347type DevicePmConfigGroupFrequencySet struct {
348 OutputOptions
349 Args struct {
350 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
351 Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"`
352 Interval time.Duration `positional-arg-name:"INTERVAL" required:"yes"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000353 } `positional-args:"yes"`
354}
355
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -0800356type DeviceGetExtValue struct {
357 ListOutputOptions
358 Args struct {
359 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
360 Valueflag ValueFlag `positional-arg-name:"VALUE_FLAG" required:"yes"`
361 } `positional-args:"yes"`
362}
Rohan Agrawald7df3772020-06-29 11:23:36 +0000363
364type DevicePmConfigSetMaxSkew struct {
365 Args struct {
366 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
367 MaxSkew uint32 `positional-arg-name:"MAX_SKEW" required:"yes"`
368 } `positional-args:"yes"`
369}
370
Andrea Campanella791d88b2021-01-08 13:29:00 +0100371type DeviceOnuListImages struct {
372 ListOutputOptions
373 Args struct {
374 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
375 } `positional-args:"yes"`
376}
377
378type DeviceOnuDownloadImage struct {
379 Args struct {
380 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
381 Name string `positional-arg-name:"IMAGE_NAME" required:"yes"`
382 Url string `positional-arg-name:"IMAGE_URL" required:"yes"`
383 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
384 Crc uint32 `positional-arg-name:"IMAGE_CRC" required:"yes"`
385 LocalDir string `positional-arg-name:"IMAGE_LOCAL_DIRECTORY"`
386 } `positional-args:"yes"`
387}
388
389type DeviceOnuActivateImageUpdate struct {
390 Args struct {
391 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
392 Name string `positional-arg-name:"IMAGE_NAME" required:"yes"`
393 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
394 SaveConfig bool `positional-arg-name:"SAVE_EXISTING_CONFIG"`
395 LocalDir string `positional-arg-name:"IMAGE_LOCAL_DIRECTORY"`
Andrea Campanella7b2ecf42021-02-25 12:27:15 +0100396 } `positional-args:"yes"`
kesavand8ec4fc02021-01-27 09:10:22 -0500397}
kesavand3e2f9f62021-04-22 11:06:38 +0530398
399type OnuDownloadImage struct {
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +0200400 ListOutputOptions
kesavand3e2f9f62021-04-22 11:06:38 +0530401 Args struct {
402 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
403 Url string `positional-arg-name:"IMAGE_URL" required:"yes"`
ssiddiqui7bc89e92021-05-20 20:58:02 +0530404 Vendor string `positional-arg-name:"IMAGE_VENDOR"`
kesavand3e2f9f62021-04-22 11:06:38 +0530405 ActivateOnSuccess bool `positional-arg-name:"IMAGE_ACTIVATE_ON_SUCCESS"`
406 CommitOnSuccess bool `positional-arg-name:"IMAGE_COMMIT_ON_SUCCESS"`
407 Crc uint32 `positional-arg-name:"IMAGE_CRC"`
408 IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
409 } `positional-args:"yes"`
410}
411
412type OnuActivateImage struct {
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +0200413 ListOutputOptions
kesavand3e2f9f62021-04-22 11:06:38 +0530414 Args struct {
415 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
416 CommitOnSuccess bool `positional-arg-name:"IMAGE_COMMIT_ON_SUCCESS"`
417 IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
418 } `positional-args:"yes"`
419}
420
421type OnuAbortUpgradeImage struct {
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +0200422 ListOutputOptions
kesavand3e2f9f62021-04-22 11:06:38 +0530423 Args struct {
424 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
425 IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
426 } `positional-args:"yes"`
427}
428
429type OnuCommitImage struct {
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +0200430 ListOutputOptions
kesavand3e2f9f62021-04-22 11:06:38 +0530431 Args struct {
432 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
433 IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
434 } `positional-args:"yes"`
435}
436
437type OnuImageStatus struct {
438 ListOutputOptions
439 Args struct {
440 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
Elia Battiston859f3e62022-02-08 15:57:52 +0100441 IDs []DeviceId `positional-arg-name:"DEVICE_ID"`
kesavand3e2f9f62021-04-22 11:06:38 +0530442 } `positional-args:"yes"`
443}
444
445type OnuListImages struct {
446 ListOutputOptions
447 Args struct {
448 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
449 } `positional-args:"yes"`
450}
451
kesavand8ec4fc02021-01-27 09:10:22 -0500452type DeviceGetPortStats struct {
453 ListOutputOptions
454 Args struct {
455 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
456 PortNo uint32 `positional-arg-name:"PORT_NO" required:"yes"`
457 PortType string `positional-arg-name:"PORT_TYPE" required:"yes"`
Andrea Campanella791d88b2021-01-08 13:29:00 +0100458 } `positional-args:"yes"`
459}
kesavand6d1131f2021-02-05 22:38:15 +0530460type UniStatus struct {
461 ListOutputOptions
462 Args struct {
463 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
464 UniIndex uint32 `positional-arg-name:"UNI_INDEX" required:"yes"`
465 } `positional-args:"yes"`
466}
Girish Gowdra4f5ce7c2021-04-29 18:53:21 -0700467type OnuPonOpticalInfo struct {
468 ListOutputOptions
469 Args struct {
470 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
471 } `positional-args:"yes"`
472}
Himani Chawla40acc122021-05-26 18:52:29 +0530473
474type GetOnuStats struct {
475 ListOutputOptions
476 Args struct {
477 OltId DeviceId `positional-arg-name:"OLT_DEVICE_ID" required:"yes"`
478 IntfId uint32 `positional-arg-name:"PON_INTF_ID" required:"yes"`
479 OnuId uint32 `positional-arg-name:"ONU_ID" required:"yes"`
480 } `positional-args:"yes"`
481}
482
Akash Soni6e879c22024-12-20 17:01:34 +0530483type GetOffloadApp struct {
Akash Soni51b6b7a2024-11-20 11:39:38 +0530484 ListOutputOptions
485 Args struct {
486 OltId DeviceId `positional-arg-name:"OLT_DEVICE_ID" required:"yes"`
487 StatsFor extension.GetOffloadedAppsStatisticsRequest_OffloadedApp `positional-arg-name:"OFFLOADED_APP" required:"yes"`
488 } `positional-args:"yes"`
489}
490
Akash Soni6e879c22024-12-20 17:01:34 +0530491type SetOffloadApp struct {
492 ListOutputOptions
Akash Soni51b6b7a2024-11-20 11:39:38 +0530493 Args struct {
Akash Soni6e879c22024-12-20 17:01:34 +0530494 OltId DeviceId `positional-arg-name:"OLT_DEVICE_ID" required:"yes"`
495 Config string `positional-arg-name:"CONFIG" required:"yes"` // Accept JSON or CSV input
Akash Soni51b6b7a2024-11-20 11:39:38 +0530496 } `positional-args:"yes"`
497}
498
Akash Soni6e879c22024-12-20 17:01:34 +0530499type AppOffloadOnuConfig struct {
500 AgentRemoteID string
501 AgentCircuitID string
502 OnuUniId uint32
503}
504
505type SetOnuOffload struct {
506 ListOutputOptions
Akash Soni51b6b7a2024-11-20 11:39:38 +0530507 Args struct {
Akash Soni6e879c22024-12-20 17:01:34 +0530508 OltId DeviceId `positional-arg-name:"OLT_DEVICE_ID" required:"yes"`
509 OnuDeviceId string `positional-arg-name:"ONU_DEVICE_ID" required:"yes"`
510 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 +0530511 } `positional-args:"yes"`
512}
513
Himani Chawla553a1392021-06-10 23:39:17 +0530514type GetOnuEthernetFrameExtendedPmCounters struct {
515 ListOutputOptions
Himani Chawla806aa892021-08-30 15:51:46 +0530516 Reset bool `long:"reset" description:"Reset the counters"`
517 Args struct {
518 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
519 UniIndex *uint32 `positional-arg-name:"UNI_INDEX"`
Himani Chawla553a1392021-06-10 23:39:17 +0530520 } `positional-args:"yes"`
521}
522
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +0530523type GetPonPortStats struct {
524 ListOutputOptions
525 Reset bool `long:"reset" description:"Reset the counters"`
526 Args struct {
527 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
528 PortLabel string `positional-arg-name:"PORT_LABEL" required:"yes"`
529 } `positional-args:"yes"`
530}
531
532type GetNniPortStats struct {
533 ListOutputOptions
534 Reset bool `long:"reset" description:"Reset the counters"`
535 Args struct {
536 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
537 PortLabel string `positional-arg-name:"PORT_LABEL" required:"yes"`
538 } `positional-args:"yes"`
539}
540
541type GetOnuAllocGemStatsFromOlt struct {
542 ListOutputOptions
543 Args struct {
544 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
545 } `positional-args:"yes"`
546}
Gamze Abakac857a462021-05-26 13:45:54 +0000547type RxPower struct {
548 ListOutputOptions
549 Args struct {
550 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
551 PortNo uint32 `positional-arg-name:"PORT_NO" required:"yes"`
552 OnuNo uint32 `positional-arg-name:"ONU_NO" required:"yes"`
553 } `positional-args:"yes"`
554}
555
praneeth nalmas39c71ad2023-09-27 18:29:04 +0530556type PonRxPower struct {
557 ListOutputOptions
558 Args struct {
559 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
560 PortLabel string `positional-arg-name:"PORT_LABEL" required:"yes"`
561 SerialNo string `positional-arg-name:"ONU_SERIAL_NUMBER"`
562 } `positional-args:"yes"`
563}
564
serkantul3d22fc72022-09-14 12:22:56 +0300565type OnuOmciTxRxStats struct {
566 ListOutputOptions
567 Args struct {
568 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
569 } `positional-args:"yes"`
570}
571
praneeth nalmas1dd094c2022-12-22 14:15:13 +0530572type GetOnuOmciActiveAlarms struct {
573 ListOutputOptions
574 Args struct {
575 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
576 } `positional-args:"yes"`
577}
578
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +0530579type GetOnuGEMStats struct {
580 ListOutputOptions
581 Args struct {
582 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
583 } `positional-args:"yes"`
584}
585
Akash Reddy Kankanala6965c652025-10-15 23:30:16 +0530586type GetOnuFecHistory struct {
587 ListOutputOptions
588 Args struct {
589 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
590 } `positional-args:"yes"`
591}
Akash Soni66db9632024-04-15 09:05:15 +0530592type GetOnuDistance struct {
593 ListOutputOptions
594 Args struct {
595 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
596 OnuId OnuId `positional-arg-name:"ONU_ID" required:"yes"`
597 } `positional-args:"yes"` //onu device id
598}
599
mgouda35b90e62025-07-16 14:58:29 +0530600type DisableOnuDevice struct {
601 Args struct {
602 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
603 } `positional-args:"yes"`
604}
605
606type EnableOnuDevice struct {
607 Args struct {
608 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
609 } `positional-args:"yes"`
610}
611
612type DisableOnuSerialNumber struct {
613 Args struct {
614 SerialNumber string `positional-arg-name:"ONU_SERIAL_NUMBER" required:"yes"`
615 Port PortNum `positional-arg-name:"PORT_NO" required:"yes"`
616 OltDeviceId DeviceId `positional-arg-name:"OLT_DEVICE_ID" required:"yes"`
617 } `positional-args:"yes"`
618}
619
620type EnableOnuSerialNumber struct {
621 Args struct {
622 SerialNumber string `positional-arg-name:"ONU_SERIAL_NUMBER" required:"yes"`
623 Port PortNum `positional-arg-name:"PORT_NO" required:"yes"`
624 OltDeviceId DeviceId `positional-arg-name:"OLT_DEVICE_ID" required:"yes"`
625 } `positional-args:"yes"`
626}
627
Zack Williamse940c7a2019-08-21 14:25:39 -0700628type DeviceOpts struct {
mgouda35b90e62025-07-16 14:58:29 +0530629 List DeviceList `command:"list"`
630 Create DeviceCreate `command:"create"`
631 Delete DeviceDelete `command:"delete"`
632 Enable DeviceEnable `command:"enable"`
633 Disable DeviceDisable `command:"disable"`
634 DisableOnuDevice DisableOnuDevice `command:"disable_onu"`
635 EnableOnuDevice EnableOnuDevice `command:"enable_onu"`
636 DisableOnuSerialNumber DisableOnuSerialNumber `command:"disable_onu_serial"`
637 EnableOnuSerialNumber EnableOnuSerialNumber `command:"enable_onu_serial"`
638 Flows DeviceFlowList `command:"flows"`
639 Groups DeviceFlowGroupList `command:"groups"`
640 Port struct {
kesavand12cd8eb2020-01-20 22:25:22 -0500641 List DevicePortList `command:"list"`
642 Enable DevicePortEnable `command:"enable"`
643 Disable DevicePortDisable `command:"disable"`
644 } `command:"port"`
645 Inspect DeviceInspect `command:"inspect"`
646 Reboot DeviceReboot `command:"reboot"`
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -0800647 Value struct {
648 Get DeviceGetExtValue `command:"get"`
649 } `command:"value"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000650 PmConfig struct {
Rohan Agrawald7df3772020-06-29 11:23:36 +0000651 Get DevicePmConfigsGet `command:"get"`
652 MaxSkew struct {
653 Set DevicePmConfigSetMaxSkew `command:"set"`
654 } `command:"maxskew"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000655 Frequency struct {
656 Set DevicePmConfigFrequencySet `command:"set"`
657 } `command:"frequency"`
658 Metric struct {
659 List DevicePmConfigMetricList `command:"list"`
660 Enable DevicePmConfigMetricEnable `command:"enable"`
661 Disable DevicePmConfigMetricDisable `command:"disable"`
662 } `command:"metric"`
663 Group struct {
Girish Gowdra610acb42021-01-27 13:33:57 -0800664 List DevicePmConfigGroupList `command:"list"`
665 Enable DevicePmConfigGroupEnable `command:"enable"`
666 Disable DevicePmConfigGroupDisable `command:"disable"`
667 Set DevicePmConfigGroupFrequencySet `command:"set"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000668 } `command:"group"`
669 GroupMetric struct {
670 List DevicePmConfigGroupMetricList `command:"list"`
671 } `command:"groupmetric"`
672 } `command:"pmconfig"`
Andrea Campanella791d88b2021-01-08 13:29:00 +0100673 Image struct {
674 Get DeviceOnuListImages `command:"list"`
675 Download DeviceOnuDownloadImage `command:"download"`
676 Activate DeviceOnuActivateImageUpdate `command:"activate"`
677 } `command:"image"`
kesavand3e2f9f62021-04-22 11:06:38 +0530678 DownloadImage struct {
679 Download OnuDownloadImage `command:"download"`
680 Activate OnuActivateImage `command:"activate"`
681 Commit OnuCommitImage `command:"commit"`
682 AbortUpgrade OnuAbortUpgradeImage `command:"abort"`
683 Status OnuImageStatus `command:"status"`
684 List OnuListImages `command:"list" `
685 } `command:"onuimage"`
kesavand8ec4fc02021-01-27 09:10:22 -0500686 GetExtVal struct {
Himani Chawla553a1392021-06-10 23:39:17 +0530687 Stats DeviceGetPortStats `command:"portstats"`
688 UniStatus UniStatus `command:"unistatus"`
689 OpticalInfo OnuPonOpticalInfo `command:"onu_pon_optical_info"`
690 OnuStats GetOnuStats `command:"onu_stats"`
691 EthernetFrameExtendedPm GetOnuEthernetFrameExtendedPmCounters `command:"ethernet_frame_extended_pm"`
692 RxPower RxPower `command:"rxpower"`
serkantul3d22fc72022-09-14 12:22:56 +0300693 OnuOmciStats OnuOmciTxRxStats `command:"onu_omci_stats"`
praneeth nalmas1dd094c2022-12-22 14:15:13 +0530694 OnuOmciActiveAlarms GetOnuOmciActiveAlarms `command:"onu_omci_active_alarms"`
praneeth nalmas39c71ad2023-09-27 18:29:04 +0530695 PonRxPower PonRxPower `command:"pon_rx_power"`
Akash Soni66db9632024-04-15 09:05:15 +0530696 OnuDistance GetOnuDistance `command:"onu_distance"`
Akash Soni6e879c22024-12-20 17:01:34 +0530697 OffloadAppStats GetOffloadApp `command:"offload_app_stats"`
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +0530698 PonStats GetPonPortStats `command:"itu_pon_stats"`
699 NniStats GetNniPortStats `command:"nni_statistics"`
700 OnuGEMStats GetOnuGEMStats `command:"onu_gem_stats"`
701 OnuAllocGemStats GetOnuAllocGemStatsFromOlt `command:"onu_alloc_gem_from_olt"`
Akash Reddy Kankanala6965c652025-10-15 23:30:16 +0530702 OnuFecHistory GetOnuFecHistory `command:"onu_fec_history"`
kesavand8ec4fc02021-01-27 09:10:22 -0500703 } `command:"getextval"`
Akash Soni51b6b7a2024-11-20 11:39:38 +0530704 SetExtVal struct {
Akash Soni6e879c22024-12-20 17:01:34 +0530705 OffloadAppStatsSet SetOffloadApp `command:"set_offload_app"`
706 OnuOffloadStatsSet SetOnuOffload `command:"set_onu_offload"`
Akash Soni51b6b7a2024-11-20 11:39:38 +0530707 } `command:"setextval"`
Zack Williamse940c7a2019-08-21 14:25:39 -0700708}
709
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +0530710type AllocGemStatsFromOlt struct {
711 AllocId uint32
712 AllocRxBytes uint64
713 GemPortStats []GemPortStatsFromOlt
714}
715type GemPortStatsFromOlt struct {
716 GemId uint32
717 RxPackets uint64
718 RxBytes uint64
719 TxPackets uint64
720 TxBytes uint64
721}
722type onugemstats struct {
723 AllocId uint32
724 AllocRxBytes uint32
725 GemHistoryStats []gemHistoryStats
726}
727type gemHistoryStats struct {
728 GemId uint32
729 TransmittedGEMFrames uint32
730 ReceivedGEMFrames uint32
731 ReceivedPayloadBytes uint32
732 TransmittedPayloadBytes uint32
733 EncryptionKeyErrors uint32
734}
735
736type PortStats struct {
737 PonPort uint32 // use this for PON
738 NniPort uint32 // use this for NNI
739 *common.PortStatistics
740}
741
Zack Williamse940c7a2019-08-21 14:25:39 -0700742var deviceOpts = DeviceOpts{}
743
744func RegisterDeviceCommands(parser *flags.Parser) {
David Bainbridge12f036f2019-10-15 22:09:04 +0000745 if _, err := parser.AddCommand("device", "device commands", "Commands to query and manipulate VOLTHA devices", &deviceOpts); err != nil {
David Bainbridgea6722342019-10-24 23:55:53 +0000746 Error.Fatalf("Unexpected error while attempting to register device commands : %s", err)
David Bainbridge12f036f2019-10-15 22:09:04 +0000747 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700748}
749
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000750func (i *MetricName) Complete(match string) []flags.Completion {
751 conn, err := NewConnection()
752 if err != nil {
753 return nil
754 }
755 defer conn.Close()
756
757 client := voltha.NewVolthaServiceClient(conn)
758
759 var deviceId string
760found:
761 for i := len(os.Args) - 1; i >= 0; i -= 1 {
762 switch os.Args[i] {
763 case "enable":
764 fallthrough
765 case "disable":
766 if len(os.Args) > i+1 {
767 deviceId = os.Args[i+1]
768 } else {
769 return nil
770 }
771 break found
772 default:
773 }
774 }
775
776 if len(deviceId) == 0 {
777 return nil
778 }
779
David K. Bainbridge9189c632021-03-26 21:52:21 +0000780 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000781 defer cancel()
782
783 id := voltha.ID{Id: string(deviceId)}
784
785 pmconfigs, err := client.ListDevicePmConfigs(ctx, &id)
786
787 if err != nil {
788 return nil
789 }
790
791 list := make([]flags.Completion, 0)
792 for _, metrics := range pmconfigs.Metrics {
793 if strings.HasPrefix(metrics.Name, match) {
794 list = append(list, flags.Completion{Item: metrics.Name})
795 }
796 }
797
798 return list
799}
800
801func (i *GroupName) Complete(match string) []flags.Completion {
802 conn, err := NewConnection()
803 if err != nil {
804 return nil
805 }
806 defer conn.Close()
807
808 client := voltha.NewVolthaServiceClient(conn)
809
810 var deviceId string
811found:
812 for i := len(os.Args) - 1; i >= 0; i -= 1 {
813 switch os.Args[i] {
814 case "list":
815 fallthrough
816 case "enable":
817 fallthrough
818 case "disable":
819 if len(os.Args) > i+1 {
820 deviceId = os.Args[i+1]
821 } else {
822 return nil
823 }
824 break found
825 default:
826 }
827 }
828
829 if len(deviceId) == 0 {
830 return nil
831 }
832
David K. Bainbridge9189c632021-03-26 21:52:21 +0000833 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000834 defer cancel()
835
836 id := voltha.ID{Id: string(deviceId)}
837
838 pmconfigs, err := client.ListDevicePmConfigs(ctx, &id)
839
840 if err != nil {
841 return nil
842 }
843
844 list := make([]flags.Completion, 0)
845 for _, group := range pmconfigs.Groups {
846 if strings.HasPrefix(group.GroupName, match) {
847 list = append(list, flags.Completion{Item: group.GroupName})
848 }
849 }
850 return list
851}
852
kesavand12cd8eb2020-01-20 22:25:22 -0500853func (i *PortNum) Complete(match string) []flags.Completion {
854 conn, err := NewConnection()
855 if err != nil {
856 return nil
857 }
858 defer conn.Close()
859
Scott Baker9173ed82020-05-19 08:30:12 -0700860 client := voltha.NewVolthaServiceClient(conn)
kesavand12cd8eb2020-01-20 22:25:22 -0500861
862 /*
863 * The command line args when completing for PortNum will be a DeviceId
864 * followed by one or more PortNums. So walk the argument list from the
865 * end and find the first argument that is enable/disable as those are
866 * the subcommands that come before the positional arguments. It would
867 * be nice if this package gave us the list of optional arguments
868 * already parsed.
869 */
870 var deviceId string
871found:
872 for i := len(os.Args) - 1; i >= 0; i -= 1 {
873 switch os.Args[i] {
874 case "enable":
875 fallthrough
876 case "disable":
877 if len(os.Args) > i+1 {
878 deviceId = os.Args[i+1]
879 } else {
880 return nil
881 }
882 break found
883 default:
884 }
885 }
886
887 if len(deviceId) == 0 {
888 return nil
889 }
890
David K. Bainbridge9189c632021-03-26 21:52:21 +0000891 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand12cd8eb2020-01-20 22:25:22 -0500892 defer cancel()
kesavand12cd8eb2020-01-20 22:25:22 -0500893
Scott Baker9173ed82020-05-19 08:30:12 -0700894 id := voltha.ID{Id: string(deviceId)}
kesavand12cd8eb2020-01-20 22:25:22 -0500895
Scott Baker9173ed82020-05-19 08:30:12 -0700896 ports, err := client.ListDevicePorts(ctx, &id)
kesavand12cd8eb2020-01-20 22:25:22 -0500897 if err != nil {
898 return nil
899 }
900
901 list := make([]flags.Completion, 0)
Scott Baker9173ed82020-05-19 08:30:12 -0700902 for _, item := range ports.Items {
903 pn := strconv.FormatUint(uint64(item.PortNo), 10)
kesavand12cd8eb2020-01-20 22:25:22 -0500904 if strings.HasPrefix(pn, match) {
905 list = append(list, flags.Completion{Item: pn})
906 }
907 }
908
909 return list
910}
911
Zack Williamse940c7a2019-08-21 14:25:39 -0700912func (i *DeviceId) Complete(match string) []flags.Completion {
913 conn, err := NewConnection()
914 if err != nil {
915 return nil
916 }
917 defer conn.Close()
918
Scott Baker9173ed82020-05-19 08:30:12 -0700919 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700920
David K. Bainbridge9189c632021-03-26 21:52:21 +0000921 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700922 defer cancel()
923
Scott Baker9173ed82020-05-19 08:30:12 -0700924 devices, err := client.ListDevices(ctx, &empty.Empty{})
Zack Williamse940c7a2019-08-21 14:25:39 -0700925 if err != nil {
926 return nil
927 }
928
929 list := make([]flags.Completion, 0)
Scott Baker9173ed82020-05-19 08:30:12 -0700930 for _, item := range devices.Items {
931 if strings.HasPrefix(item.Id, match) {
932 list = append(list, flags.Completion{Item: item.Id})
Zack Williamse940c7a2019-08-21 14:25:39 -0700933 }
934 }
935
936 return list
937}
938
939func (options *DeviceList) Execute(args []string) error {
940
941 conn, err := NewConnection()
942 if err != nil {
943 return err
944 }
945 defer conn.Close()
946
Scott Baker9173ed82020-05-19 08:30:12 -0700947 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700948
David K. Bainbridge9189c632021-03-26 21:52:21 +0000949 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700950 defer cancel()
951
Scott Baker9173ed82020-05-19 08:30:12 -0700952 devices, err := client.ListDevices(ctx, &empty.Empty{})
Zack Williamse940c7a2019-08-21 14:25:39 -0700953 if err != nil {
954 return err
955 }
956
957 outputFormat := CharReplacer.Replace(options.Format)
958 if outputFormat == "" {
David Bainbridgea6722342019-10-24 23:55:53 +0000959 outputFormat = GetCommandOptionWithDefault("device-list", "format", DEFAULT_DEVICE_FORMAT)
Zack Williamse940c7a2019-08-21 14:25:39 -0700960 }
961 if options.Quiet {
962 outputFormat = "{{.Id}}"
963 }
964
David Bainbridgea6722342019-10-24 23:55:53 +0000965 orderBy := options.OrderBy
966 if orderBy == "" {
Hardik Windlass9361bb82022-03-23 05:58:48 +0000967 orderBy = GetCommandOptionWithDefault("device-list", "order", DEFAULT_DEVICE_ORDER)
David Bainbridgea6722342019-10-24 23:55:53 +0000968 }
969
Scott Baker9173ed82020-05-19 08:30:12 -0700970 // Make sure json output prints an empty list, not "null"
971 if devices.Items == nil {
972 devices.Items = make([]*voltha.Device, 0)
Zack Williamse940c7a2019-08-21 14:25:39 -0700973 }
974
975 result := CommandResult{
976 Format: format.Format(outputFormat),
977 Filter: options.Filter,
David Bainbridgea6722342019-10-24 23:55:53 +0000978 OrderBy: orderBy,
Zack Williamse940c7a2019-08-21 14:25:39 -0700979 OutputAs: toOutputType(options.OutputAs),
980 NameLimit: options.NameLimit,
Scott Baker9173ed82020-05-19 08:30:12 -0700981 Data: devices.Items,
Zack Williamse940c7a2019-08-21 14:25:39 -0700982 }
983
984 GenerateOutput(&result)
985 return nil
986}
987
988func (options *DeviceCreate) Execute(args []string) error {
989
Scott Baker9173ed82020-05-19 08:30:12 -0700990 device := voltha.Device{}
Zack Williamse940c7a2019-08-21 14:25:39 -0700991 if options.HostAndPort != "" {
Scott Baker9173ed82020-05-19 08:30:12 -0700992 device.Address = &voltha.Device_HostAndPort{HostAndPort: options.HostAndPort}
Zack Williamse940c7a2019-08-21 14:25:39 -0700993 } else if options.IPAddress != "" {
Scott Baker9173ed82020-05-19 08:30:12 -0700994 device.Address = &voltha.Device_Ipv4Address{Ipv4Address: options.IPAddress}
Hardik Windlassce1de342020-02-04 21:58:07 +0000995 }
996 if options.MACAddress != "" {
Scott Baker9173ed82020-05-19 08:30:12 -0700997 device.MacAddress = strings.ToLower(options.MACAddress)
Zack Williamse940c7a2019-08-21 14:25:39 -0700998 }
999 if options.DeviceType != "" {
Scott Baker9173ed82020-05-19 08:30:12 -07001000 device.Type = options.DeviceType
Zack Williamse940c7a2019-08-21 14:25:39 -07001001 }
1002
1003 conn, err := NewConnection()
1004 if err != nil {
1005 return err
1006 }
1007 defer conn.Close()
1008
Scott Baker9173ed82020-05-19 08:30:12 -07001009 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -07001010
David K. Bainbridge9189c632021-03-26 21:52:21 +00001011 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -07001012 defer cancel()
1013
Scott Baker9173ed82020-05-19 08:30:12 -07001014 createdDevice, err := client.CreateDevice(ctx, &device)
Zack Williamse940c7a2019-08-21 14:25:39 -07001015 if err != nil {
1016 return err
Zack Williamse940c7a2019-08-21 14:25:39 -07001017 }
1018
Scott Baker9173ed82020-05-19 08:30:12 -07001019 fmt.Printf("%s\n", createdDevice.Id)
Zack Williamse940c7a2019-08-21 14:25:39 -07001020
1021 return nil
1022}
1023
1024func (options *DeviceDelete) Execute(args []string) error {
1025
1026 conn, err := NewConnection()
1027 if err != nil {
1028 return err
1029 }
1030 defer conn.Close()
1031
Scott Baker9173ed82020-05-19 08:30:12 -07001032 client := voltha.NewVolthaServiceClient(conn)
David Bainbridge7052fe82020-03-25 10:37:00 -07001033 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -07001034 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +00001035 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -07001036 defer cancel()
1037
Scott Baker9173ed82020-05-19 08:30:12 -07001038 id := voltha.ID{Id: string(i)}
Himani Chawla9933ddc2020-10-12 23:53:27 +05301039 if options.Force {
1040 _, err = client.ForceDeleteDevice(ctx, &id)
1041 } else {
1042 _, err = client.DeleteDevice(ctx, &id)
1043 }
Scott Baker9173ed82020-05-19 08:30:12 -07001044
Zack Williamse940c7a2019-08-21 14:25:39 -07001045 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +00001046 Error.Printf("Error while deleting '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -07001047 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -07001048 continue
Zack Williamse940c7a2019-08-21 14:25:39 -07001049 }
1050 fmt.Printf("%s\n", i)
1051 }
1052
David Bainbridge7052fe82020-03-25 10:37:00 -07001053 if lastErr != nil {
1054 return NoReportErr
1055 }
Zack Williamse940c7a2019-08-21 14:25:39 -07001056 return nil
1057}
1058
1059func (options *DeviceEnable) Execute(args []string) error {
1060 conn, err := NewConnection()
1061 if err != nil {
1062 return err
1063 }
1064 defer conn.Close()
1065
Scott Baker9173ed82020-05-19 08:30:12 -07001066 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -07001067
David Bainbridge7052fe82020-03-25 10:37:00 -07001068 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -07001069 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +00001070 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -07001071 defer cancel()
1072
Scott Baker9173ed82020-05-19 08:30:12 -07001073 id := voltha.ID{Id: string(i)}
1074
1075 _, err := client.EnableDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -07001076 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +00001077 Error.Printf("Error while enabling '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -07001078 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -07001079 continue
Zack Williamse940c7a2019-08-21 14:25:39 -07001080 }
1081 fmt.Printf("%s\n", i)
1082 }
1083
David Bainbridge7052fe82020-03-25 10:37:00 -07001084 if lastErr != nil {
1085 return NoReportErr
1086 }
Zack Williamse940c7a2019-08-21 14:25:39 -07001087 return nil
1088}
1089
1090func (options *DeviceDisable) Execute(args []string) error {
1091 conn, err := NewConnection()
1092 if err != nil {
1093 return err
1094 }
1095 defer conn.Close()
1096
Scott Baker9173ed82020-05-19 08:30:12 -07001097 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -07001098
David Bainbridge7052fe82020-03-25 10:37:00 -07001099 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -07001100 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +00001101 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -07001102 defer cancel()
1103
Scott Baker9173ed82020-05-19 08:30:12 -07001104 id := voltha.ID{Id: string(i)}
1105
1106 _, err := client.DisableDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -07001107 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +00001108 Error.Printf("Error while disabling '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -07001109 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -07001110 continue
Zack Williamse940c7a2019-08-21 14:25:39 -07001111 }
1112 fmt.Printf("%s\n", i)
1113 }
1114
David Bainbridge7052fe82020-03-25 10:37:00 -07001115 if lastErr != nil {
1116 return NoReportErr
1117 }
Zack Williamse940c7a2019-08-21 14:25:39 -07001118 return nil
1119}
1120
1121func (options *DeviceReboot) Execute(args []string) error {
1122 conn, err := NewConnection()
1123 if err != nil {
1124 return err
1125 }
1126 defer conn.Close()
1127
Scott Baker9173ed82020-05-19 08:30:12 -07001128 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -07001129
David Bainbridge7052fe82020-03-25 10:37:00 -07001130 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -07001131 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +00001132 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -07001133 defer cancel()
1134
Scott Baker9173ed82020-05-19 08:30:12 -07001135 id := voltha.ID{Id: string(i)}
1136
1137 _, err := client.RebootDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -07001138 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +00001139 Error.Printf("Error while rebooting '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -07001140 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -07001141 continue
Zack Williamse940c7a2019-08-21 14:25:39 -07001142 }
1143 fmt.Printf("%s\n", i)
1144 }
1145
David Bainbridge7052fe82020-03-25 10:37:00 -07001146 if lastErr != nil {
1147 return NoReportErr
1148 }
Zack Williamse940c7a2019-08-21 14:25:39 -07001149 return nil
1150}
1151
1152func (options *DevicePortList) Execute(args []string) error {
1153
1154 conn, err := NewConnection()
1155 if err != nil {
1156 return err
1157 }
1158 defer conn.Close()
1159
Scott Baker9173ed82020-05-19 08:30:12 -07001160 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -07001161
David K. Bainbridge9189c632021-03-26 21:52:21 +00001162 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -07001163 defer cancel()
1164
Scott Baker9173ed82020-05-19 08:30:12 -07001165 id := voltha.ID{Id: string(options.Args.Id)}
Zack Williamse940c7a2019-08-21 14:25:39 -07001166
Scott Baker9173ed82020-05-19 08:30:12 -07001167 ports, err := client.ListDevicePorts(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -07001168 if err != nil {
1169 return err
1170 }
1171
1172 outputFormat := CharReplacer.Replace(options.Format)
1173 if outputFormat == "" {
David Bainbridgea6722342019-10-24 23:55:53 +00001174 outputFormat = GetCommandOptionWithDefault("device-ports", "format", DEFAULT_DEVICE_PORTS_FORMAT)
Zack Williamse940c7a2019-08-21 14:25:39 -07001175 }
Zack Williamse940c7a2019-08-21 14:25:39 -07001176
David Bainbridgea6722342019-10-24 23:55:53 +00001177 orderBy := options.OrderBy
1178 if orderBy == "" {
1179 orderBy = GetCommandOptionWithDefault("device-ports", "order", "")
1180 }
1181
Zack Williamse940c7a2019-08-21 14:25:39 -07001182 result := CommandResult{
1183 Format: format.Format(outputFormat),
1184 Filter: options.Filter,
David Bainbridgea6722342019-10-24 23:55:53 +00001185 OrderBy: orderBy,
Zack Williamse940c7a2019-08-21 14:25:39 -07001186 OutputAs: toOutputType(options.OutputAs),
1187 NameLimit: options.NameLimit,
Scott Baker9173ed82020-05-19 08:30:12 -07001188 Data: ports.Items,
Zack Williamse940c7a2019-08-21 14:25:39 -07001189 }
1190
1191 GenerateOutput(&result)
1192 return nil
1193}
1194
1195func (options *DeviceFlowList) Execute(args []string) error {
1196 fl := &FlowList{}
1197 fl.ListOutputOptions = options.ListOutputOptions
Maninder045921e2020-09-29 16:46:02 +05301198 fl.FlowIdOptions = options.FlowIdOptions
Zack Williamse940c7a2019-08-21 14:25:39 -07001199 fl.Args.Id = string(options.Args.Id)
David Bainbridgea6722342019-10-24 23:55:53 +00001200 fl.Method = "device-flows"
Zack Williamse940c7a2019-08-21 14:25:39 -07001201 return fl.Execute(args)
1202}
1203
Himani Chawla3c161c62021-05-13 16:36:51 +05301204func (options *DeviceFlowGroupList) Execute(args []string) error {
1205 grp := &GroupList{}
1206 grp.ListOutputOptions = options.ListOutputOptions
1207 grp.GroupListOptions = options.GroupListOptions
1208 grp.Args.Id = string(options.Args.Id)
1209 grp.Method = "device-groups"
1210 return grp.Execute(args)
1211}
1212
Zack Williamse940c7a2019-08-21 14:25:39 -07001213func (options *DeviceInspect) Execute(args []string) error {
1214 if len(args) > 0 {
1215 return fmt.Errorf("only a single argument 'DEVICE_ID' can be provided")
1216 }
1217
1218 conn, err := NewConnection()
1219 if err != nil {
1220 return err
1221 }
1222 defer conn.Close()
1223
Scott Baker9173ed82020-05-19 08:30:12 -07001224 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -07001225
David K. Bainbridge9189c632021-03-26 21:52:21 +00001226 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -07001227 defer cancel()
1228
Scott Baker9173ed82020-05-19 08:30:12 -07001229 id := voltha.ID{Id: string(options.Args.Id)}
Zack Williamse940c7a2019-08-21 14:25:39 -07001230
Scott Baker9173ed82020-05-19 08:30:12 -07001231 device, err := client.GetDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -07001232 if err != nil {
1233 return err
1234 }
1235
Zack Williamse940c7a2019-08-21 14:25:39 -07001236 outputFormat := CharReplacer.Replace(options.Format)
1237 if outputFormat == "" {
David Bainbridgea6722342019-10-24 23:55:53 +00001238 outputFormat = GetCommandOptionWithDefault("device-inspect", "format", DEFAULT_DEVICE_INSPECT_FORMAT)
Zack Williamse940c7a2019-08-21 14:25:39 -07001239 }
1240 if options.Quiet {
1241 outputFormat = "{{.Id}}"
1242 }
1243
1244 result := CommandResult{
1245 Format: format.Format(outputFormat),
1246 OutputAs: toOutputType(options.OutputAs),
1247 NameLimit: options.NameLimit,
1248 Data: device,
1249 }
1250 GenerateOutput(&result)
1251 return nil
1252}
kesavand12cd8eb2020-01-20 22:25:22 -05001253
1254/*Device Port Enable */
1255func (options *DevicePortEnable) Execute(args []string) error {
1256 conn, err := NewConnection()
1257 if err != nil {
1258 return err
1259 }
1260 defer conn.Close()
1261
Scott Baker9173ed82020-05-19 08:30:12 -07001262 client := voltha.NewVolthaServiceClient(conn)
kesavand12cd8eb2020-01-20 22:25:22 -05001263
David K. Bainbridge9189c632021-03-26 21:52:21 +00001264 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand12cd8eb2020-01-20 22:25:22 -05001265 defer cancel()
1266
Scott Baker9173ed82020-05-19 08:30:12 -07001267 port := voltha.Port{DeviceId: string(options.Args.Id), PortNo: uint32(options.Args.PortId)}
1268
1269 _, err = client.EnablePort(ctx, &port)
kesavand12cd8eb2020-01-20 22:25:22 -05001270 if err != nil {
1271 Error.Printf("Error enabling port number %v on device Id %s,err=%s\n", options.Args.PortId, options.Args.Id, ErrorToString(err))
1272 return err
kesavand12cd8eb2020-01-20 22:25:22 -05001273 }
1274
1275 return nil
1276}
1277
Scott Baker9173ed82020-05-19 08:30:12 -07001278/*Device Port Disable */
kesavand12cd8eb2020-01-20 22:25:22 -05001279func (options *DevicePortDisable) Execute(args []string) error {
1280 conn, err := NewConnection()
1281 if err != nil {
1282 return err
1283 }
1284 defer conn.Close()
1285
Scott Baker9173ed82020-05-19 08:30:12 -07001286 client := voltha.NewVolthaServiceClient(conn)
1287
David K. Bainbridge9189c632021-03-26 21:52:21 +00001288 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand12cd8eb2020-01-20 22:25:22 -05001289 defer cancel()
1290
Scott Baker9173ed82020-05-19 08:30:12 -07001291 port := voltha.Port{DeviceId: string(options.Args.Id), PortNo: uint32(options.Args.PortId)}
1292
1293 _, err = client.DisablePort(ctx, &port)
kesavand12cd8eb2020-01-20 22:25:22 -05001294 if err != nil {
Scott Baker9173ed82020-05-19 08:30:12 -07001295 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 -05001296 return err
kesavand12cd8eb2020-01-20 22:25:22 -05001297 }
Scott Baker9173ed82020-05-19 08:30:12 -07001298
kesavand12cd8eb2020-01-20 22:25:22 -05001299 return nil
1300}
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08001301
Rohan Agrawald7df3772020-06-29 11:23:36 +00001302func (options *DevicePmConfigSetMaxSkew) Execute(args []string) error {
1303 conn, err := NewConnection()
1304 if err != nil {
1305 return err
1306 }
1307 defer conn.Close()
1308
1309 client := voltha.NewVolthaServiceClient(conn)
1310
David K. Bainbridge9189c632021-03-26 21:52:21 +00001311 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawald7df3772020-06-29 11:23:36 +00001312 defer cancel()
1313
1314 id := voltha.ID{Id: string(options.Args.Id)}
1315
1316 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1317 if err != nil {
1318 return err
1319 }
1320
1321 pmConfigs.MaxSkew = options.Args.MaxSkew
1322
1323 _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs)
1324 if err != nil {
1325 return err
1326 }
1327
1328 return nil
1329}
1330
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001331func (options *DevicePmConfigsGet) Execute(args []string) error {
1332
1333 conn, err := NewConnection()
1334 if err != nil {
1335 return err
1336 }
1337 defer conn.Close()
1338
1339 client := voltha.NewVolthaServiceClient(conn)
1340
David K. Bainbridge9189c632021-03-26 21:52:21 +00001341 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001342 defer cancel()
1343
1344 id := voltha.ID{Id: string(options.Args.Id)}
1345
1346 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1347 if err != nil {
1348 return err
1349 }
1350
1351 outputFormat := CharReplacer.Replace(options.Format)
1352 if outputFormat == "" {
1353 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GET_FORMAT)
1354 }
1355
1356 orderBy := options.OrderBy
1357 if orderBy == "" {
1358 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1359 }
1360
1361 result := CommandResult{
1362 Format: format.Format(outputFormat),
1363 Filter: options.Filter,
1364 OrderBy: orderBy,
1365 OutputAs: toOutputType(options.OutputAs),
1366 NameLimit: options.NameLimit,
1367 Data: pmConfigs,
1368 }
1369
1370 GenerateOutput(&result)
1371 return nil
1372
1373}
1374
1375func (options *DevicePmConfigMetricList) Execute(args []string) error {
1376
1377 conn, err := NewConnection()
1378 if err != nil {
1379 return err
1380 }
1381 defer conn.Close()
1382
1383 client := voltha.NewVolthaServiceClient(conn)
1384
David K. Bainbridge9189c632021-03-26 21:52:21 +00001385 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001386 defer cancel()
1387
1388 id := voltha.ID{Id: string(options.Args.Id)}
1389
1390 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1391 if err != nil {
1392 return err
1393 }
1394
1395 if !pmConfigs.Grouped {
1396 for _, metric := range pmConfigs.Metrics {
1397 if metric.SampleFreq == 0 {
1398 metric.SampleFreq = pmConfigs.DefaultFreq
1399 }
1400 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001401 outputFormat := CharReplacer.Replace(options.Format)
1402 if outputFormat == "" {
1403 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_METRIC_LIST_FORMAT)
1404 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001405
Rohan Agrawalbca69122020-06-17 14:59:03 +00001406 orderBy := options.OrderBy
1407 if orderBy == "" {
1408 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1409 }
1410
1411 result := CommandResult{
1412 Format: format.Format(outputFormat),
1413 Filter: options.Filter,
1414 OrderBy: orderBy,
1415 OutputAs: toOutputType(options.OutputAs),
1416 NameLimit: options.NameLimit,
1417 Data: pmConfigs.Metrics,
1418 }
1419
1420 GenerateOutput(&result)
1421 return nil
1422 } else {
1423 return fmt.Errorf("Device '%s' does not have Non Grouped Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001424 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001425}
1426
1427func (options *DevicePmConfigMetricEnable) Execute(args []string) error {
1428
1429 conn, err := NewConnection()
1430 if err != nil {
1431 return err
1432 }
1433 defer conn.Close()
1434
1435 client := voltha.NewVolthaServiceClient(conn)
1436
David K. Bainbridge9189c632021-03-26 21:52:21 +00001437 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001438 defer cancel()
1439
1440 id := voltha.ID{Id: string(options.Args.Id)}
1441
1442 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1443 if err != nil {
1444 return err
1445 }
1446
1447 if !pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001448 metrics := make(map[string]struct{})
1449 for _, metric := range pmConfigs.Metrics {
1450 metrics[metric.Name] = struct{}{}
1451 }
1452
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001453 for _, metric := range pmConfigs.Metrics {
1454 for _, mName := range options.Args.Metrics {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001455 if _, exist := metrics[string(mName)]; !exist {
1456 return fmt.Errorf("Metric Name '%s' does not exist", mName)
1457 }
1458
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001459 if string(mName) == metric.Name && !metric.Enabled {
1460 metric.Enabled = true
1461 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1462 if err != nil {
1463 return err
1464 }
1465 }
1466 }
1467 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001468 } else {
1469 return fmt.Errorf("Device '%s' does not have Non Grouped Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001470 }
1471 return nil
1472}
1473
1474func (options *DevicePmConfigMetricDisable) Execute(args []string) error {
1475
1476 conn, err := NewConnection()
1477 if err != nil {
1478 return err
1479 }
1480 defer conn.Close()
1481
1482 client := voltha.NewVolthaServiceClient(conn)
1483
David K. Bainbridge9189c632021-03-26 21:52:21 +00001484 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001485 defer cancel()
1486
1487 id := voltha.ID{Id: string(options.Args.Id)}
1488
1489 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1490 if err != nil {
1491 return err
1492 }
1493
1494 if !pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001495 metrics := make(map[string]struct{})
1496 for _, metric := range pmConfigs.Metrics {
1497 metrics[metric.Name] = struct{}{}
1498 }
1499
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001500 for _, metric := range pmConfigs.Metrics {
1501 for _, mName := range options.Args.Metrics {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001502 if _, have := metrics[string(mName)]; !have {
1503 return fmt.Errorf("Metric Name '%s' does not exist", mName)
1504 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001505 if string(mName) == metric.Name && metric.Enabled {
1506 metric.Enabled = false
1507 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1508 if err != nil {
1509 return err
1510 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001511 } else {
1512 return fmt.Errorf("Metric '%s' cannot be disabled", string(mName))
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001513 }
1514 }
1515 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001516 } else {
1517 return fmt.Errorf("Device '%s' does not have Non Grouped Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001518 }
1519 return nil
1520}
1521
1522func (options *DevicePmConfigGroupEnable) Execute(args []string) error {
1523
1524 conn, err := NewConnection()
1525 if err != nil {
1526 return err
1527 }
1528 defer conn.Close()
1529
1530 client := voltha.NewVolthaServiceClient(conn)
1531
David K. Bainbridge9189c632021-03-26 21:52:21 +00001532 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001533 defer cancel()
1534
1535 id := voltha.ID{Id: string(options.Args.Id)}
1536
1537 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1538 if err != nil {
1539 return err
1540 }
1541
1542 if pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001543 groups := make(map[string]struct{})
1544 for _, group := range pmConfigs.Groups {
1545 groups[group.GroupName] = struct{}{}
1546 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001547 for _, group := range pmConfigs.Groups {
Girish Gowdra610acb42021-01-27 13:33:57 -08001548 if _, have := groups[string(options.Args.Group)]; !have {
1549 return fmt.Errorf("Group Name '%s' does not exist", options.Args.Group)
1550 }
1551 if string(options.Args.Group) == group.GroupName && !group.Enabled {
1552 group.Enabled = true
1553 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1554 if err != nil {
1555 return err
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001556 }
1557 }
1558 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001559 } else {
1560 return fmt.Errorf("Device '%s' does not have Group Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001561 }
1562 return nil
1563}
1564
1565func (options *DevicePmConfigGroupDisable) Execute(args []string) error {
1566
1567 conn, err := NewConnection()
1568 if err != nil {
1569 return err
1570 }
1571 defer conn.Close()
1572
1573 client := voltha.NewVolthaServiceClient(conn)
1574
David K. Bainbridge9189c632021-03-26 21:52:21 +00001575 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001576 defer cancel()
1577
1578 id := voltha.ID{Id: string(options.Args.Id)}
1579
1580 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1581 if err != nil {
1582 return err
1583 }
1584
1585 if pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001586 groups := make(map[string]struct{})
1587 for _, group := range pmConfigs.Groups {
1588 groups[group.GroupName] = struct{}{}
1589 }
1590
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001591 for _, group := range pmConfigs.Groups {
Girish Gowdra610acb42021-01-27 13:33:57 -08001592 if _, have := groups[string(options.Args.Group)]; !have {
1593 return fmt.Errorf("Group Name '%s' does not exist", options.Args.Group)
1594 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001595
Girish Gowdra610acb42021-01-27 13:33:57 -08001596 if string(options.Args.Group) == group.GroupName && group.Enabled {
1597 group.Enabled = false
1598 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1599 if err != nil {
1600 return err
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001601 }
1602 }
1603 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001604 } else {
1605 return fmt.Errorf("Device '%s' does not have Group Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001606 }
1607 return nil
1608}
1609
Girish Gowdra610acb42021-01-27 13:33:57 -08001610func (options *DevicePmConfigGroupFrequencySet) Execute(args []string) error {
1611
1612 conn, err := NewConnection()
1613 if err != nil {
1614 return err
1615 }
1616 defer conn.Close()
1617
1618 client := voltha.NewVolthaServiceClient(conn)
1619
David K. Bainbridge9189c632021-03-26 21:52:21 +00001620 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Girish Gowdra610acb42021-01-27 13:33:57 -08001621 defer cancel()
1622
1623 id := voltha.ID{Id: string(options.Args.Id)}
1624
1625 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1626 if err != nil {
1627 return err
1628 }
1629
1630 if pmConfigs.Grouped {
1631 groups := make(map[string]struct{})
1632 for _, group := range pmConfigs.Groups {
1633 groups[group.GroupName] = struct{}{}
1634 }
1635
1636 for _, group := range pmConfigs.Groups {
1637 if _, have := groups[string(options.Args.Group)]; !have {
1638 return fmt.Errorf("group name '%s' does not exist", options.Args.Group)
1639 }
1640
1641 if string(options.Args.Group) == group.GroupName {
1642 if !group.Enabled {
1643 return fmt.Errorf("group '%s' is not enabled", options.Args.Group)
1644 }
1645 group.GroupFreq = uint32(options.Args.Interval.Seconds())
1646 _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs)
1647 if err != nil {
1648 return err
1649 }
1650 }
1651 }
1652 } else {
1653 return fmt.Errorf("device '%s' does not have group metrics", options.Args.Id)
1654 }
1655 return nil
1656}
1657
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001658func (options *DevicePmConfigGroupList) Execute(args []string) error {
1659
1660 conn, err := NewConnection()
1661 if err != nil {
1662 return err
1663 }
1664 defer conn.Close()
1665
1666 client := voltha.NewVolthaServiceClient(conn)
1667
David K. Bainbridge9189c632021-03-26 21:52:21 +00001668 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001669 defer cancel()
1670
1671 id := voltha.ID{Id: string(options.Args.Id)}
1672
1673 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1674 if err != nil {
1675 return err
1676 }
1677
1678 if pmConfigs.Grouped {
1679 for _, group := range pmConfigs.Groups {
1680 if group.GroupFreq == 0 {
1681 group.GroupFreq = pmConfigs.DefaultFreq
1682 }
1683 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001684 outputFormat := CharReplacer.Replace(options.Format)
1685 if outputFormat == "" {
1686 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GROUP_LIST_FORMAT)
1687 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001688
Rohan Agrawalbca69122020-06-17 14:59:03 +00001689 orderBy := options.OrderBy
1690 if orderBy == "" {
1691 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1692 }
1693
1694 result := CommandResult{
1695 Format: format.Format(outputFormat),
1696 Filter: options.Filter,
1697 OrderBy: orderBy,
1698 OutputAs: toOutputType(options.OutputAs),
1699 NameLimit: options.NameLimit,
1700 Data: pmConfigs.Groups,
1701 }
1702
1703 GenerateOutput(&result)
1704 } else {
1705 return fmt.Errorf("Device '%s' does not have Group Metrics", string(options.Args.Id))
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001706 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001707 return nil
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001708}
1709
1710func (options *DevicePmConfigGroupMetricList) Execute(args []string) error {
1711
1712 var metrics []*voltha.PmConfig
1713 conn, err := NewConnection()
1714 if err != nil {
1715 return err
1716 }
1717 defer conn.Close()
1718
1719 client := voltha.NewVolthaServiceClient(conn)
1720
David K. Bainbridge9189c632021-03-26 21:52:21 +00001721 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001722 defer cancel()
1723
1724 id := voltha.ID{Id: string(options.Args.Id)}
1725
1726 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1727 if err != nil {
1728 return err
1729 }
1730
1731 for _, groups := range pmConfigs.Groups {
1732
1733 if string(options.Args.Group) == groups.GroupName {
1734 for _, metric := range groups.Metrics {
1735 if metric.SampleFreq == 0 && groups.GroupFreq == 0 {
1736 metric.SampleFreq = pmConfigs.DefaultFreq
1737 } else {
1738 metric.SampleFreq = groups.GroupFreq
1739 }
1740 }
1741 metrics = groups.Metrics
1742 }
1743 }
1744
1745 outputFormat := CharReplacer.Replace(options.Format)
1746 if outputFormat == "" {
1747 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_METRIC_LIST_FORMAT)
1748 }
1749
1750 orderBy := options.OrderBy
1751 if orderBy == "" {
1752 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1753 }
1754
1755 result := CommandResult{
1756 Format: format.Format(outputFormat),
1757 Filter: options.Filter,
1758 OrderBy: orderBy,
1759 OutputAs: toOutputType(options.OutputAs),
1760 NameLimit: options.NameLimit,
1761 Data: metrics,
1762 }
1763
1764 GenerateOutput(&result)
1765 return nil
1766
1767}
1768
1769func (options *DevicePmConfigFrequencySet) Execute(args []string) error {
1770
1771 conn, err := NewConnection()
1772 if err != nil {
1773 return err
1774 }
1775 defer conn.Close()
1776
1777 client := voltha.NewVolthaServiceClient(conn)
1778
David K. Bainbridge9189c632021-03-26 21:52:21 +00001779 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001780 defer cancel()
1781
1782 id := voltha.ID{Id: string(options.Args.Id)}
1783
1784 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1785 if err != nil {
1786 return err
1787 }
1788
Girish Gowdra610acb42021-01-27 13:33:57 -08001789 pmConfigs.DefaultFreq = uint32(options.Args.Interval.Seconds())
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001790
1791 _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs)
1792 if err != nil {
1793 return err
1794 }
1795
1796 outputFormat := CharReplacer.Replace(options.Format)
1797 if outputFormat == "" {
1798 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GET_FORMAT)
1799 }
1800 if options.Quiet {
1801 outputFormat = "{{.Id}}"
1802 }
1803
1804 result := CommandResult{
1805 Format: format.Format(outputFormat),
1806 OutputAs: toOutputType(options.OutputAs),
1807 NameLimit: options.NameLimit,
1808 Data: pmConfigs,
1809 }
1810
1811 GenerateOutput(&result)
1812 return nil
1813
1814}
1815
kesavand3e2f9f62021-04-22 11:06:38 +05301816func (options *OnuDownloadImage) Execute(args []string) error {
1817
1818 conn, err := NewConnection()
1819 if err != nil {
1820 return err
1821 }
1822 defer conn.Close()
1823
1824 client := voltha.NewVolthaServiceClient(conn)
1825
1826 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1827 defer cancel()
1828
1829 var devIDList []*common.ID
1830 for _, i := range options.Args.IDs {
1831
1832 devIDList = append(devIDList, &common.ID{Id: string(i)})
1833 }
1834
1835 downloadImage := voltha.DeviceImageDownloadRequest{
1836 DeviceId: devIDList,
1837 Image: &voltha.Image{
1838 Url: options.Args.Url,
1839 Crc32: options.Args.Crc,
ssiddiqui7bc89e92021-05-20 20:58:02 +05301840 Vendor: options.Args.Vendor,
kesavand3e2f9f62021-04-22 11:06:38 +05301841 Version: options.Args.ImageVersion,
1842 },
1843 ActivateOnSuccess: options.Args.ActivateOnSuccess,
1844 CommitOnSuccess: options.Args.CommitOnSuccess,
1845 }
1846
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001847 deviceImageResp, err := client.DownloadImageToDevice(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301848 if err != nil {
1849 return err
1850 }
1851
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001852 outputFormat := GetCommandOptionWithDefault("onu-image-download", "format", ONU_IMAGE_STATUS_FORMAT)
1853 // Make sure json output prints an empty list, not "null"
1854 if deviceImageResp.DeviceImageStates == nil {
1855 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1856 }
1857 result := CommandResult{
1858 Format: format.Format(outputFormat),
1859 OutputAs: toOutputType(options.OutputAs),
1860 NameLimit: options.NameLimit,
1861 Data: deviceImageResp.DeviceImageStates,
1862 }
1863 GenerateOutput(&result)
kesavand3e2f9f62021-04-22 11:06:38 +05301864 return nil
1865
1866}
1867
1868func (options *OnuActivateImage) Execute(args []string) error {
1869
1870 conn, err := NewConnection()
1871 if err != nil {
1872 return err
1873 }
1874 defer conn.Close()
1875
1876 client := voltha.NewVolthaServiceClient(conn)
1877
1878 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1879 defer cancel()
1880
1881 var devIDList []*common.ID
1882 for _, i := range options.Args.IDs {
1883
1884 devIDList = append(devIDList, &common.ID{Id: string(i)})
1885 }
1886
1887 downloadImage := voltha.DeviceImageRequest{
1888 DeviceId: devIDList,
1889 Version: options.Args.ImageVersion,
1890 CommitOnSuccess: options.Args.CommitOnSuccess,
1891 }
1892
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001893 deviceImageResp, err := client.ActivateImage(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301894 if err != nil {
1895 return err
1896 }
1897
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001898 outputFormat := GetCommandOptionWithDefault("onu-image-activate", "format", ONU_IMAGE_STATUS_FORMAT)
1899 // Make sure json output prints an empty list, not "null"
1900 if deviceImageResp.DeviceImageStates == nil {
1901 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1902 }
1903 result := CommandResult{
1904 Format: format.Format(outputFormat),
1905 OutputAs: toOutputType(options.OutputAs),
1906 NameLimit: options.NameLimit,
1907 Data: deviceImageResp.DeviceImageStates,
1908 }
1909 GenerateOutput(&result)
1910
kesavand3e2f9f62021-04-22 11:06:38 +05301911 return nil
1912
1913}
1914
1915func (options *OnuAbortUpgradeImage) Execute(args []string) error {
1916
1917 conn, err := NewConnection()
1918 if err != nil {
1919 return err
1920 }
1921 defer conn.Close()
1922
1923 client := voltha.NewVolthaServiceClient(conn)
1924
1925 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1926 defer cancel()
1927
1928 var devIDList []*common.ID
1929 for _, i := range options.Args.IDs {
1930
1931 devIDList = append(devIDList, &common.ID{Id: string(i)})
1932 }
1933
1934 downloadImage := voltha.DeviceImageRequest{
1935 DeviceId: devIDList,
1936 Version: options.Args.ImageVersion,
1937 }
1938
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001939 deviceImageResp, err := client.AbortImageUpgradeToDevice(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301940 if err != nil {
1941 return err
1942 }
1943
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001944 outputFormat := GetCommandOptionWithDefault("onu-image-abort", "format", ONU_IMAGE_STATUS_FORMAT)
1945 // Make sure json output prints an empty list, not "null"
1946 if deviceImageResp.DeviceImageStates == nil {
1947 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1948 }
1949 result := CommandResult{
1950 Format: format.Format(outputFormat),
1951 OutputAs: toOutputType(options.OutputAs),
1952 NameLimit: options.NameLimit,
1953 Data: deviceImageResp.DeviceImageStates,
1954 }
1955 GenerateOutput(&result)
1956
kesavand3e2f9f62021-04-22 11:06:38 +05301957 return nil
1958
1959}
1960
1961func (options *OnuCommitImage) Execute(args []string) error {
1962
1963 conn, err := NewConnection()
1964 if err != nil {
1965 return err
1966 }
1967 defer conn.Close()
1968
1969 client := voltha.NewVolthaServiceClient(conn)
1970
1971 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1972 defer cancel()
1973
1974 var devIDList []*common.ID
1975 for _, i := range options.Args.IDs {
1976
1977 devIDList = append(devIDList, &common.ID{Id: string(i)})
1978 }
1979 downloadImage := voltha.DeviceImageRequest{
1980 DeviceId: devIDList,
1981 Version: options.Args.ImageVersion,
1982 }
1983
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001984 deviceImageResp, err := client.CommitImage(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301985 if err != nil {
1986 return err
1987 }
1988
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001989 outputFormat := GetCommandOptionWithDefault("onu-image-commit", "format", ONU_IMAGE_STATUS_FORMAT)
1990 // Make sure json output prints an empty list, not "null"
1991 if deviceImageResp.DeviceImageStates == nil {
1992 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1993 }
1994 result := CommandResult{
1995 Format: format.Format(outputFormat),
1996 OutputAs: toOutputType(options.OutputAs),
1997 NameLimit: options.NameLimit,
1998 Data: deviceImageResp.DeviceImageStates,
1999 }
2000 GenerateOutput(&result)
2001
kesavand3e2f9f62021-04-22 11:06:38 +05302002 return nil
2003
2004}
2005
2006func (options *OnuListImages) Execute(args []string) error {
2007
2008 conn, err := NewConnection()
2009 if err != nil {
2010 return err
2011 }
2012 defer conn.Close()
2013
2014 client := voltha.NewVolthaServiceClient(conn)
2015
2016 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2017 defer cancel()
2018
2019 id := common.ID{Id: string(options.Args.Id)}
2020
2021 onuImages, err := client.GetOnuImages(ctx, &id)
2022 if err != nil {
2023 return err
2024 }
2025
2026 outputFormat := CharReplacer.Replace(options.Format)
2027 if outputFormat == "" {
2028 outputFormat = GetCommandOptionWithDefault("onu-image-list", "format", ONU_IMAGE_LIST_FORMAT)
2029 }
2030
2031 if options.Quiet {
2032 outputFormat = "{{.Id}}"
2033 }
2034
2035 //TODO orderby
2036
2037 // Make sure json output prints an empty list, not "null"
2038 if onuImages.Items == nil {
2039 onuImages.Items = make([]*voltha.OnuImage, 0)
2040 }
2041
2042 result := CommandResult{
2043 Format: format.Format(outputFormat),
2044 OutputAs: toOutputType(options.OutputAs),
2045 NameLimit: options.NameLimit,
2046 Data: onuImages.Items,
2047 }
2048
2049 GenerateOutput(&result)
2050 return nil
2051
2052}
2053
2054func (options *OnuImageStatus) Execute(args []string) error {
2055
2056 conn, err := NewConnection()
2057 if err != nil {
2058 return err
2059 }
2060 defer conn.Close()
2061
2062 client := voltha.NewVolthaServiceClient(conn)
2063
2064 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2065 defer cancel()
2066
2067 var devIDList []*common.ID
kesavand3e2f9f62021-04-22 11:06:38 +05302068
Elia Battiston859f3e62022-02-08 15:57:52 +01002069 if options.Args.IDs == nil {
2070 //Use an empty IDs list to retrieve the status of all devices
2071 //with the requested image version
2072 devIDList = []*common.ID{}
2073 } else {
2074 for _, i := range options.Args.IDs {
2075 devIDList = append(devIDList, &common.ID{Id: string(i)})
2076 }
kesavand3e2f9f62021-04-22 11:06:38 +05302077 }
2078
2079 imageStatusReq := voltha.DeviceImageRequest{
2080 DeviceId: devIDList,
2081 Version: options.Args.ImageVersion,
2082 }
2083 imageStatus, err := client.GetImageStatus(ctx, &imageStatusReq)
2084 if err != nil {
2085 return err
2086 }
2087
2088 outputFormat := CharReplacer.Replace(options.Format)
2089 if outputFormat == "" {
2090 outputFormat = GetCommandOptionWithDefault("device-image-list", "format", ONU_IMAGE_STATUS_FORMAT)
2091 }
2092
2093 if options.Quiet {
2094 outputFormat = "{{.Id}}"
2095 }
2096
2097 //TODO orderby
2098
2099 // Make sure json output prints an empty list, not "null"
2100 if imageStatus.DeviceImageStates == nil {
2101 imageStatus.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
2102 }
2103
2104 result := CommandResult{
2105 Format: format.Format(outputFormat),
2106 OutputAs: toOutputType(options.OutputAs),
2107 NameLimit: options.NameLimit,
2108 Data: imageStatus.DeviceImageStates,
2109 }
2110
2111 GenerateOutput(&result)
2112 return nil
2113
2114}
2115
Andrea Campanella791d88b2021-01-08 13:29:00 +01002116func (options *DeviceOnuListImages) Execute(args []string) error {
2117
2118 conn, err := NewConnection()
2119 if err != nil {
2120 return err
2121 }
2122 defer conn.Close()
2123
2124 client := voltha.NewVolthaServiceClient(conn)
2125
David K. Bainbridge9189c632021-03-26 21:52:21 +00002126 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Andrea Campanella791d88b2021-01-08 13:29:00 +01002127 defer cancel()
2128
2129 id := common.ID{Id: string(options.Args.Id)}
2130
2131 imageDownloads, err := client.ListImageDownloads(ctx, &id)
2132 if err != nil {
2133 return err
2134 }
2135
2136 outputFormat := CharReplacer.Replace(options.Format)
2137 if outputFormat == "" {
2138 outputFormat = GetCommandOptionWithDefault("device-image-list", "format", DEFAULT_DEVICE_IMAGE_LIST_GET_FORMAT)
2139 }
2140
2141 if options.Quiet {
2142 outputFormat = "{{.Id}}"
2143 }
2144
2145 //TODO orderby
2146
2147 // Make sure json output prints an empty list, not "null"
2148 if imageDownloads.Items == nil {
2149 imageDownloads.Items = make([]*voltha.ImageDownload, 0)
2150 }
2151
2152 result := CommandResult{
2153 Format: format.Format(outputFormat),
2154 OutputAs: toOutputType(options.OutputAs),
2155 NameLimit: options.NameLimit,
2156 Data: imageDownloads.Items,
2157 }
2158
2159 GenerateOutput(&result)
2160 return nil
2161
2162}
2163
2164func (options *DeviceOnuDownloadImage) Execute(args []string) error {
2165
2166 conn, err := NewConnection()
2167 if err != nil {
2168 return err
2169 }
2170 defer conn.Close()
2171
2172 client := voltha.NewVolthaServiceClient(conn)
2173
David K. Bainbridge9189c632021-03-26 21:52:21 +00002174 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Andrea Campanella791d88b2021-01-08 13:29:00 +01002175 defer cancel()
2176
2177 downloadImage := voltha.ImageDownload{
2178 Id: string(options.Args.Id),
2179 Name: options.Args.Name,
2180 Url: options.Args.Url,
2181 Crc: options.Args.Crc,
2182 LocalDir: options.Args.LocalDir,
2183 }
2184
2185 _, err = client.DownloadImage(ctx, &downloadImage)
2186 if err != nil {
2187 return err
2188 }
2189
2190 return nil
2191
2192}
2193
2194func (options *DeviceOnuActivateImageUpdate) Execute(args []string) error {
2195
2196 conn, err := NewConnection()
2197 if err != nil {
2198 return err
2199 }
2200 defer conn.Close()
2201
2202 client := voltha.NewVolthaServiceClient(conn)
2203
David K. Bainbridge9189c632021-03-26 21:52:21 +00002204 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Andrea Campanella791d88b2021-01-08 13:29:00 +01002205 defer cancel()
2206
2207 downloadImage := voltha.ImageDownload{
2208 Id: string(options.Args.Id),
2209 Name: options.Args.Name,
2210 ImageVersion: options.Args.ImageVersion,
2211 SaveConfig: options.Args.SaveConfig,
2212 LocalDir: options.Args.LocalDir,
2213 }
2214
2215 _, err = client.ActivateImageUpdate(ctx, &downloadImage)
2216 if err != nil {
2217 return err
2218 }
2219
2220 return nil
2221
2222}
2223
Scott Baker9173ed82020-05-19 08:30:12 -07002224type ReturnValueRow struct {
2225 Name string `json:"name"`
2226 Result interface{} `json:"result"`
2227}
2228
kesavand8ec4fc02021-01-27 09:10:22 -05002229func (options *DeviceGetPortStats) Execute(args []string) error {
2230 conn, err := NewConnection()
2231 if err != nil {
2232 return err
2233 }
2234 defer conn.Close()
2235 client := extension.NewExtensionClient(conn)
2236 var portType extension.GetOltPortCounters_PortType
2237
2238 if options.Args.PortType == "pon" {
2239 portType = extension.GetOltPortCounters_Port_PON_OLT
2240 } else if options.Args.PortType == "nni" {
2241
2242 portType = extension.GetOltPortCounters_Port_ETHERNET_NNI
2243 } else {
2244 return fmt.Errorf("expected interface type pon/nni, provided %s", options.Args.PortType)
2245 }
2246
2247 singleGetValReq := extension.SingleGetValueRequest{
2248 TargetId: string(options.Args.Id),
2249 Request: &extension.GetValueRequest{
2250 Request: &extension.GetValueRequest_OltPortInfo{
2251 OltPortInfo: &extension.GetOltPortCounters{
2252 PortNo: options.Args.PortNo,
2253 PortType: portType,
2254 },
2255 },
2256 },
2257 }
2258
David K. Bainbridge9189c632021-03-26 21:52:21 +00002259 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand8ec4fc02021-01-27 09:10:22 -05002260 defer cancel()
2261 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2262 if err != nil {
2263 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2264 return err
2265 }
2266
2267 if rv.Response.Status != extension.GetValueResponse_OK {
2268 return fmt.Errorf("failed to get port stats %v", rv.Response.ErrReason.String())
2269 }
2270
2271 outputFormat := CharReplacer.Replace(options.Format)
2272 if outputFormat == "" {
2273 outputFormat = GetCommandOptionWithDefault("device-get-port-status", "format", DEFAULT_DEVICE_GET_PORT_STATUS_FORMAT)
2274 }
2275
2276 result := CommandResult{
2277 Format: format.Format(outputFormat),
2278 OutputAs: toOutputType(options.OutputAs),
2279 NameLimit: options.NameLimit,
2280 Data: rv.GetResponse().GetPortCoutners(),
2281 }
2282 GenerateOutput(&result)
2283 return nil
2284}
2285
Himani Chawla40acc122021-05-26 18:52:29 +05302286func (options *GetOnuStats) Execute(args []string) error {
2287 conn, err := NewConnection()
2288 if err != nil {
2289 return err
2290 }
2291 defer conn.Close()
2292 client := extension.NewExtensionClient(conn)
2293
2294 singleGetValReq := extension.SingleGetValueRequest{
2295 TargetId: string(options.Args.OltId),
2296 Request: &extension.GetValueRequest{
2297 Request: &extension.GetValueRequest_OnuPonInfo{
2298 OnuPonInfo: &extension.GetOnuCountersRequest{
2299 IntfId: options.Args.IntfId,
2300 OnuId: options.Args.OnuId,
2301 },
2302 },
2303 },
2304 }
2305 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2306 defer cancel()
2307 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2308 if err != nil {
2309 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.OltId, ErrorToString(err))
2310 return err
2311 }
2312
2313 if rv.Response.Status != extension.GetValueResponse_OK {
2314 return fmt.Errorf("failed to get onu stats %v", rv.Response.ErrReason.String())
2315 }
2316 outputFormat := CharReplacer.Replace(options.Format)
2317 data, formatStr := buildOnuStatsOutputFormat(rv.GetResponse().GetOnuPonCounters())
2318 if outputFormat == "" {
2319 outputFormat = GetCommandOptionWithDefault("device-get-onu-status", "format", formatStr)
2320 }
Himani Chawla553a1392021-06-10 23:39:17 +05302321 result := CommandResult{
2322 Format: format.Format(outputFormat),
2323 OutputAs: toOutputType(options.OutputAs),
2324 NameLimit: options.NameLimit,
2325 Data: data,
2326 }
2327 GenerateOutput(&result)
2328 return nil
2329}
Himani Chawla40acc122021-05-26 18:52:29 +05302330
Akash Soni6e879c22024-12-20 17:01:34 +05302331func (options *GetOffloadApp) Execute(args []string) error {
Akash Soni51b6b7a2024-11-20 11:39:38 +05302332 // Establish a connection to the gRPC server
2333 conn, err := NewConnection()
2334 if err != nil {
2335 return err
2336 }
2337 defer conn.Close()
2338
2339 client := extension.NewExtensionClient(conn)
2340
2341 // Build the request
2342 singleGetValReq := &extension.SingleGetValueRequest{
2343 TargetId: string(options.Args.OltId),
2344 Request: &extension.GetValueRequest{
2345 Request: &extension.GetValueRequest_OffloadedAppsStats{
2346 OffloadedAppsStats: &extension.GetOffloadedAppsStatisticsRequest{
2347 StatsFor: options.Args.StatsFor,
2348 },
2349 },
2350 },
2351 }
2352
2353 // Set a context with timeout
2354 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2355 defer cancel()
2356
2357 // Perform the gRPC call
2358 rv, err := client.GetExtValue(ctx, singleGetValReq)
2359 if err != nil {
2360 Error.Printf("Error getting value for device ID %s, err=%s\n", options.Args.OltId, ErrorToString(err))
2361 return err
2362 }
2363
2364 // Check response status
2365 if rv.GetResponse().GetStatus() != extension.GetValueResponse_OK {
2366 return fmt.Errorf("failed to get offloaded app stats: %v", rv.GetResponse().GetErrReason().String())
2367 }
2368
2369 // Process the response data
2370 stats, formatStr := buildOffloadAppStatsOutputFormat(rv.GetResponse().GetOffloadedAppsStats())
2371 outputFormat := CharReplacer.Replace(options.Format)
2372 if outputFormat == "" {
2373 outputFormat = GetCommandOptionWithDefault("device-get-offload-app-stats", "format", formatStr)
2374 }
2375
2376 // Generate and display the output
2377 result := CommandResult{
2378 Format: format.Format(outputFormat),
2379 OutputAs: toOutputType(options.OutputAs),
2380 NameLimit: options.NameLimit,
2381 Data: stats,
2382 }
2383 GenerateOutput(&result)
2384
2385 return nil
2386}
2387
Akash Soni6e879c22024-12-20 17:01:34 +05302388func (options *SetOffloadApp) Execute(args []string) error {
Akash Soni51b6b7a2024-11-20 11:39:38 +05302389 conn, err := NewConnection()
2390 if err != nil {
Akash Soni6e879c22024-12-20 17:01:34 +05302391 return fmt.Errorf("failed to establish gRPC connection: %w", err)
Akash Soni51b6b7a2024-11-20 11:39:38 +05302392 }
2393 defer conn.Close()
2394
2395 client := extension.NewExtensionClient(conn)
2396
Akash Soni6e879c22024-12-20 17:01:34 +05302397 // Parse JSON input
2398 var config extension.AppOffloadConfig
2399 if err := json.Unmarshal([]byte(options.Args.Config), &config); err != nil {
2400 return fmt.Errorf("failed to parse CONFIG as JSON: %w", err)
2401 }
2402
Akash Soni51b6b7a2024-11-20 11:39:38 +05302403 setValueRequest := &extension.SetValueRequest{
2404 Request: &extension.SetValueRequest_AppOffloadConfig{
Akash Soni6e879c22024-12-20 17:01:34 +05302405 AppOffloadConfig: &config,
Akash Soni51b6b7a2024-11-20 11:39:38 +05302406 },
2407 }
2408
2409 singleSetValReq := &extension.SingleSetValueRequest{
2410 TargetId: string(options.Args.OltId),
2411 Request: setValueRequest,
2412 }
2413
Akash Soni6e879c22024-12-20 17:01:34 +05302414 // Log the request object
2415 logRequestAppOffloadConfig(singleSetValReq)
2416
Akash Soni51b6b7a2024-11-20 11:39:38 +05302417 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2418 defer cancel()
2419
2420 resp, err := client.SetExtValue(ctx, singleSetValReq)
2421 if err != nil {
Akash Soni6e879c22024-12-20 17:01:34 +05302422 return fmt.Errorf("failed to set AppOffloadConfig: %w", err)
Akash Soni51b6b7a2024-11-20 11:39:38 +05302423 }
2424
2425 if resp.Response.Status != extension.SetValueResponse_OK {
Akash Soni6e879c22024-12-20 17:01:34 +05302426 return fmt.Errorf("operation failed with status %v: %s", resp.Response.Status, resp.Response.ErrReason)
Akash Soni51b6b7a2024-11-20 11:39:38 +05302427 }
2428
2429 fmt.Printf("AppOffloadConfig successfully set for OLT ID: %s\n", options.Args.OltId)
2430 return nil
2431}
2432
Akash Soni6e879c22024-12-20 17:01:34 +05302433func logRequestAppOffloadConfig(req *extension.SingleSetValueRequest) {
2434 fmt.Printf("Request details:\n")
2435 fmt.Printf("TargetId: %s\n", req.TargetId)
2436 if config, ok := req.Request.Request.(*extension.SetValueRequest_AppOffloadConfig); ok {
2437 fmt.Printf("AppOffloadConfig:\n")
2438 fmt.Printf(" EnableDHCPv4RA: %t\n", config.AppOffloadConfig.EnableDHCPv4RA)
2439 fmt.Printf(" EnableDHCPv6RA: %t\n", config.AppOffloadConfig.EnableDHCPv6RA)
2440 fmt.Printf(" EnablePPPoEIA: %t\n", config.AppOffloadConfig.EnablePPPoEIA)
2441 fmt.Printf(" AccessNodeID: %s\n", config.AppOffloadConfig.AccessNodeID)
2442 }
2443}
2444
2445func (options *SetOnuOffload) Execute(args []string) error {
2446 // Create the gRPC client connection
Akash Soni51b6b7a2024-11-20 11:39:38 +05302447 conn, err := NewConnection()
2448 if err != nil {
2449 return fmt.Errorf("failed to establish gRPC connection: %v", err)
2450 }
2451 defer conn.Close()
2452
2453 client := extension.NewExtensionClient(conn)
2454
Akash Soni6e879c22024-12-20 17:01:34 +05302455 // Parse PerUniInfo into a slice of PerUniConfig
2456 var perUniConfigs []AppOffloadOnuConfig
2457 if err := json.Unmarshal([]byte(options.Args.PerUniInfo), &perUniConfigs); err != nil {
2458 return fmt.Errorf("failed to parse PerUniInfo as JSON: %v", err)
Akash Soni51b6b7a2024-11-20 11:39:38 +05302459 }
Akash Soni6e879c22024-12-20 17:01:34 +05302460
2461 // Convert to []*AppOffloadOnuConfig_PerUniConfig for gRPC
2462 var grpcPerUniInfo []*extension.AppOffloadOnuConfig_PerUniConfig
2463 for _, config := range perUniConfigs {
2464 grpcPerUniInfo = append(grpcPerUniInfo, &extension.AppOffloadOnuConfig_PerUniConfig{
2465 AgentRemoteID: config.AgentRemoteID,
2466 AgentCircuitID: config.AgentCircuitID,
2467 OnuUniId: config.OnuUniId,
2468 })
2469 }
2470
Akash Soni51b6b7a2024-11-20 11:39:38 +05302471 // Build the AppOffloadOnuConfig request
2472 onuConfig := &extension.AppOffloadOnuConfig{
2473 OnuDeviceId: options.Args.OnuDeviceId,
Akash Soni6e879c22024-12-20 17:01:34 +05302474 PerUniInfo: grpcPerUniInfo,
Akash Soni51b6b7a2024-11-20 11:39:38 +05302475 }
2476
2477 setValueRequest := &extension.SetValueRequest{
2478 Request: &extension.SetValueRequest_AppOffloadOnuConfig{
2479 AppOffloadOnuConfig: onuConfig,
2480 },
2481 }
2482
2483 singleSetValReq := &extension.SingleSetValueRequest{
Akash Soni6e879c22024-12-20 17:01:34 +05302484 TargetId: string(options.Args.OltId),
Akash Soni51b6b7a2024-11-20 11:39:38 +05302485 Request: setValueRequest,
2486 }
2487
Akash Soni6e879c22024-12-20 17:01:34 +05302488 // Log the request object
2489 logRequestAppOffloadOnuConfig(singleSetValReq)
2490
2491 // Make the gRPC call
Akash Soni51b6b7a2024-11-20 11:39:38 +05302492 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2493 defer cancel()
2494
2495 resp, err := client.SetExtValue(ctx, singleSetValReq)
2496 if err != nil {
2497 return fmt.Errorf("failed to set AppOffloadOnuConfig: %v", err)
2498 }
2499
2500 if resp.Response.Status != extension.SetValueResponse_OK {
Akash Soni6e879c22024-12-20 17:01:34 +05302501 return fmt.Errorf("operation failed with status %v: %s", resp.Response.Status, resp.Response.ErrReason)
Akash Soni51b6b7a2024-11-20 11:39:38 +05302502 }
2503
2504 fmt.Printf("AppOffloadOnuConfig successfully set for ONU ID: %s\n", options.Args.OnuDeviceId)
2505 return nil
2506}
2507
Akash Soni6e879c22024-12-20 17:01:34 +05302508// Debugging helper to log the gRPC request details
2509func logRequestAppOffloadOnuConfig(req *extension.SingleSetValueRequest) {
2510 fmt.Printf("Request details:\n")
2511 fmt.Printf("TargetId: %s\n", req.TargetId)
2512 fmt.Printf("OnuDeviceId: %s\n", req.Request.GetAppOffloadOnuConfig().OnuDeviceId)
2513 if config, ok := req.Request.Request.(*extension.SetValueRequest_AppOffloadOnuConfig); ok {
2514 fmt.Printf("AppOffloadOnuConfig:\n")
2515 for i, uniInfo := range config.AppOffloadOnuConfig.PerUniInfo {
2516 fmt.Printf(" UniInfo %d:\n", i+1)
2517 fmt.Printf(" AgentRemoteID: %s\n", uniInfo.AgentRemoteID)
2518 fmt.Printf(" AgentCircuitID: %s\n", uniInfo.AgentCircuitID)
2519 fmt.Printf(" OnuUniId: %d\n", uniInfo.OnuUniId)
2520 }
2521 }
2522}
2523
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +05302524func (options *GetPonPortStats) Execute(args []string) error {
2525 conn, err := NewConnection()
2526 if err != nil {
2527 return err
2528 }
2529 defer conn.Close()
2530 client := extension.NewExtensionClient(conn)
2531
2532 singleGetValReq := extension.SingleGetValueRequest{
2533 TargetId: string(options.Args.Id),
2534 Request: &extension.GetValueRequest{
2535 Request: &extension.GetValueRequest_OltPonStats{
2536 OltPonStats: &extension.GetPonStatsRequest{
2537 PortInfo: &extension.GetPonStatsRequest_PortLabel{
2538 PortLabel: options.Args.PortLabel,
2539 },
2540 },
2541 },
2542 },
2543 }
2544 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2545 defer cancel()
2546 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2547 if err != nil {
2548 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2549 return err
2550 }
2551
2552 if rv.Response.Status != extension.GetValueResponse_OK {
2553 return fmt.Errorf("failed to get pon port stats %v", rv.Response.ErrReason.String())
2554 }
2555 outputFormat := CharReplacer.Replace(options.Format)
2556 if outputFormat == "" {
2557 outputFormat = GetCommandOptionWithDefault("device-get-pon-stats", "format", DEFAULT_PON_PORT_STATS_FORMAT)
2558 }
2559 data := PortStats{
2560 PonPort: rv.GetResponse().GetOltPonStatsResponse().GetPonPort(),
2561 PortStatistics: rv.GetResponse().GetOltPonStatsResponse().GetPortStatistics(),
2562 }
2563 result := CommandResult{
2564 Format: format.Format(outputFormat),
2565 OutputAs: toOutputType(options.OutputAs),
2566 NameLimit: options.NameLimit,
2567 Data: data,
2568 }
2569 GenerateOutput(&result)
2570 return nil
2571}
2572
2573func (options *GetNniPortStats) Execute(args []string) error {
2574 conn, err := NewConnection()
2575 if err != nil {
2576 return err
2577 }
2578 defer conn.Close()
2579 client := extension.NewExtensionClient(conn)
2580
2581 singleGetValReq := extension.SingleGetValueRequest{
2582 TargetId: string(options.Args.Id),
2583 Request: &extension.GetValueRequest{
2584 Request: &extension.GetValueRequest_OltNniStats{
2585 OltNniStats: &extension.GetNNIStatsRequest{
2586 PortInfo: &extension.GetNNIStatsRequest_PortLabel{
2587 PortLabel: options.Args.PortLabel,
2588 },
2589 },
2590 },
2591 },
2592 }
2593 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2594 defer cancel()
2595 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2596 if err != nil {
2597 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2598 return err
2599 }
2600
2601 if rv.Response.Status != extension.GetValueResponse_OK {
2602 return fmt.Errorf("failed to get nni port stats %v", rv.Response.ErrReason.String())
2603 }
2604 outputFormat := CharReplacer.Replace(options.Format)
2605 if outputFormat == "" {
2606 outputFormat = GetCommandOptionWithDefault("device-get-nni-stats", "format", DEFAULT_NNI_PORT_STATS_FORMAT)
2607 }
2608 data := PortStats{
2609 NniPort: rv.GetResponse().GetOltNniStatsResponse().GetNniPort(),
2610 PortStatistics: rv.GetResponse().GetOltNniStatsResponse().GetPortStatistics(),
2611 }
2612 result := CommandResult{
2613 Format: format.Format(outputFormat),
2614 OutputAs: toOutputType(options.OutputAs),
2615 NameLimit: options.NameLimit,
2616 Data: data,
2617 }
2618 GenerateOutput(&result)
2619 return nil
2620}
2621
Himani Chawla553a1392021-06-10 23:39:17 +05302622func (options *GetOnuEthernetFrameExtendedPmCounters) Execute(args []string) error {
2623 conn, err := NewConnection()
2624 if err != nil {
2625 return err
2626 }
2627 defer conn.Close()
2628 client := extension.NewExtensionClient(conn)
Himani Chawla806aa892021-08-30 15:51:46 +05302629 var singleGetValReq extension.SingleGetValueRequest
Himani Chawla553a1392021-06-10 23:39:17 +05302630
Himani Chawla806aa892021-08-30 15:51:46 +05302631 if options.Args.UniIndex != nil {
2632 singleGetValReq = extension.SingleGetValueRequest{
2633 TargetId: string(options.Args.Id),
2634 Request: &extension.GetValueRequest{
2635 Request: &extension.GetValueRequest_OnuInfo{
2636 OnuInfo: &extension.GetOmciEthernetFrameExtendedPmRequest{
2637 OnuDeviceId: string(options.Args.Id),
2638 Reset_: options.Reset,
2639 IsUniIndex: &extension.GetOmciEthernetFrameExtendedPmRequest_UniIndex{
2640 UniIndex: *options.Args.UniIndex,
2641 },
2642 },
Himani Chawla553a1392021-06-10 23:39:17 +05302643 },
2644 },
Himani Chawla806aa892021-08-30 15:51:46 +05302645 }
2646 } else {
2647 singleGetValReq = extension.SingleGetValueRequest{
2648 TargetId: string(options.Args.Id),
2649 Request: &extension.GetValueRequest{
2650 Request: &extension.GetValueRequest_OnuInfo{
2651 OnuInfo: &extension.GetOmciEthernetFrameExtendedPmRequest{
2652 OnuDeviceId: string(options.Args.Id),
2653 Reset_: options.Reset,
2654 },
2655 },
2656 },
2657 }
Himani Chawla553a1392021-06-10 23:39:17 +05302658 }
Himani Chawla806aa892021-08-30 15:51:46 +05302659
Himani Chawla553a1392021-06-10 23:39:17 +05302660 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2661 defer cancel()
2662 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2663 if err != nil {
2664 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2665 return err
2666 }
2667
2668 if rv.Response.Status != extension.GetValueResponse_OK {
2669 return fmt.Errorf("failed to get ethernet frame extended pm counters %v", rv.Response.ErrReason.String())
2670 }
2671 outputFormat := CharReplacer.Replace(options.Format)
2672 data := buildOnuEthernetFrameExtendedPmOutputFormat(rv.GetResponse().GetOnuCounters())
2673 if outputFormat == "" {
2674 outputFormat = GetCommandOptionWithDefault("device-get-onu-status", "format", DEFAULT_ETHERNET_FRAME_EXTENDED_PM_COUNTERS_FORMAT)
2675 }
Himani Chawla40acc122021-05-26 18:52:29 +05302676 result := CommandResult{
2677 Format: format.Format(outputFormat),
2678 OutputAs: toOutputType(options.OutputAs),
2679 NameLimit: options.NameLimit,
2680 Data: data,
2681 }
2682 GenerateOutput(&result)
2683 return nil
2684}
2685
kesavand6d1131f2021-02-05 22:38:15 +05302686func (options *UniStatus) Execute(args []string) error {
2687 conn, err := NewConnection()
2688 if err != nil {
2689 return err
2690 }
2691 defer conn.Close()
2692 client := extension.NewExtensionClient(conn)
2693
2694 singleGetValReq := extension.SingleGetValueRequest{
2695 TargetId: string(options.Args.Id),
2696 Request: &extension.GetValueRequest{
2697 Request: &extension.GetValueRequest_UniInfo{
2698 UniInfo: &extension.GetOnuUniInfoRequest{
2699 UniIndex: options.Args.UniIndex,
2700 },
2701 },
2702 },
2703 }
David K. Bainbridge9189c632021-03-26 21:52:21 +00002704 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand6d1131f2021-02-05 22:38:15 +05302705 defer cancel()
2706 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2707 if err != nil {
2708 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2709 return err
2710 }
2711 if rv.Response.Status != extension.GetValueResponse_OK {
2712 return fmt.Errorf("failed to get uni status %v", rv.Response.ErrReason.String())
2713 }
2714 outputFormat := CharReplacer.Replace(options.Format)
2715 if outputFormat == "" {
2716 outputFormat = GetCommandOptionWithDefault("device-get-uni-status", "format", DEFAULT_DEVICE_GET_UNI_STATUS_FORMAT)
2717 }
2718 result := CommandResult{
2719 Format: format.Format(outputFormat),
2720 OutputAs: toOutputType(options.OutputAs),
2721 NameLimit: options.NameLimit,
2722 Data: rv.GetResponse().GetUniInfo(),
2723 }
2724 GenerateOutput(&result)
2725 return nil
2726}
2727
Girish Gowdra4f5ce7c2021-04-29 18:53:21 -07002728func (options *OnuPonOpticalInfo) Execute(args []string) error {
2729 conn, err := NewConnection()
2730 if err != nil {
2731 return err
2732 }
2733 defer conn.Close()
2734 client := extension.NewExtensionClient(conn)
2735
2736 singleGetValReq := extension.SingleGetValueRequest{
2737 TargetId: string(options.Args.Id),
2738 Request: &extension.GetValueRequest{
2739 Request: &extension.GetValueRequest_OnuOpticalInfo{
2740 OnuOpticalInfo: &extension.GetOnuPonOpticalInfo{},
2741 },
2742 },
2743 }
2744 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2745 defer cancel()
2746 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2747 if err != nil {
2748 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2749 return err
2750 }
2751 if rv.Response.Status != extension.GetValueResponse_OK {
2752 return fmt.Errorf("failed to get onu pon optical info %v", rv.Response.ErrReason.String())
2753 }
2754 outputFormat := CharReplacer.Replace(options.Format)
2755 if outputFormat == "" {
2756 outputFormat = GetCommandOptionWithDefault("device-get-onu-pon-optical-info", "format", DEFAULT_ONU_PON_OPTICAL_INFO_STATUS_FORMAT)
2757 }
2758 result := CommandResult{
2759 Format: format.Format(outputFormat),
2760 OutputAs: toOutputType(options.OutputAs),
2761 NameLimit: options.NameLimit,
2762 Data: rv.GetResponse().GetOnuOpticalInfo(),
2763 }
2764 GenerateOutput(&result)
2765 return nil
2766}
2767
Gamze Abakac857a462021-05-26 13:45:54 +00002768func (options *RxPower) Execute(args []string) error {
2769 conn, err := NewConnection()
2770 if err != nil {
2771 return err
2772 }
2773 defer conn.Close()
2774 client := extension.NewExtensionClient(conn)
2775
2776 singleGetValReq := extension.SingleGetValueRequest{
2777 TargetId: string(options.Args.Id),
2778 Request: &extension.GetValueRequest{
2779 Request: &extension.GetValueRequest_RxPower{
2780 RxPower: &extension.GetRxPowerRequest{
2781 IntfId: options.Args.PortNo,
2782 OnuId: options.Args.OnuNo,
2783 },
2784 },
2785 },
2786 }
2787
2788 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2789 defer cancel()
2790 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2791 if err != nil {
2792 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2793 return err
2794 }
2795 if rv.Response.Status != extension.GetValueResponse_OK {
2796 return fmt.Errorf("failed to get rx power %v", rv.Response.ErrReason.String())
2797 }
2798 outputFormat := CharReplacer.Replace(options.Format)
2799 if outputFormat == "" {
2800 outputFormat = GetCommandOptionWithDefault("device-get-rx-power", "format", DEFAULT_RX_POWER_STATUS_FORMAT)
2801 }
2802 result := CommandResult{
2803 Format: format.Format(outputFormat),
2804 OutputAs: toOutputType(options.OutputAs),
2805 NameLimit: options.NameLimit,
2806 Data: rv.GetResponse().GetRxPower(),
2807 }
2808 GenerateOutput(&result)
2809 return nil
2810}
2811
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002812/*Device get Onu Distance */
2813func (options *DeviceGetExtValue) Execute(args []string) error {
2814 conn, err := NewConnection()
2815 if err != nil {
2816 return err
2817 }
2818 defer conn.Close()
2819
Scott Baker9173ed82020-05-19 08:30:12 -07002820 client := voltha.NewVolthaServiceClient(conn)
2821
khenaidoo080ce882021-10-19 17:35:08 -04002822 valueflag, okay := extension.ValueType_Type_value[string(options.Args.Valueflag)]
Scott Baker9173ed82020-05-19 08:30:12 -07002823 if !okay {
2824 Error.Printf("Unknown valueflag %s\n", options.Args.Valueflag)
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002825 }
2826
khenaidoo080ce882021-10-19 17:35:08 -04002827 val := extension.ValueSpecifier{Id: string(options.Args.Id), Value: extension.ValueType_Type(valueflag)}
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002828
David K. Bainbridge9189c632021-03-26 21:52:21 +00002829 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002830 defer cancel()
2831
Scott Baker9173ed82020-05-19 08:30:12 -07002832 rv, err := client.GetExtValue(ctx, &val)
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002833 if err != nil {
2834 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2835 return err
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002836 }
2837
Scott Baker9173ed82020-05-19 08:30:12 -07002838 var rows []ReturnValueRow
khenaidoo080ce882021-10-19 17:35:08 -04002839 for name, num := range extension.ValueType_Type_value {
Scott Baker9173ed82020-05-19 08:30:12 -07002840 if num == 0 {
2841 // EMPTY is not a real value
2842 continue
2843 }
2844 if (rv.Error & uint32(num)) != 0 {
2845 row := ReturnValueRow{Name: name, Result: "Error"}
2846 rows = append(rows, row)
2847 }
2848 if (rv.Unsupported & uint32(num)) != 0 {
2849 row := ReturnValueRow{Name: name, Result: "Unsupported"}
2850 rows = append(rows, row)
2851 }
2852 if (rv.Set & uint32(num)) != 0 {
2853 switch name {
2854 case "DISTANCE":
2855 row := ReturnValueRow{Name: name, Result: rv.Distance}
2856 rows = append(rows, row)
2857 default:
2858 row := ReturnValueRow{Name: name, Result: "Unimplemented-in-voltctl"}
2859 rows = append(rows, row)
2860 }
2861 }
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002862 }
2863
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002864 outputFormat := CharReplacer.Replace(options.Format)
2865 if outputFormat == "" {
2866 outputFormat = GetCommandOptionWithDefault("device-value-get", "format", DEFAULT_DEVICE_VALUE_GET_FORMAT)
2867 }
2868
2869 result := CommandResult{
2870 Format: format.Format(outputFormat),
2871 OutputAs: toOutputType(options.OutputAs),
2872 NameLimit: options.NameLimit,
Scott Baker9173ed82020-05-19 08:30:12 -07002873 Data: rows,
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002874 }
2875 GenerateOutput(&result)
2876 return nil
2877}
serkantul3d22fc72022-09-14 12:22:56 +03002878
2879/*Device get Onu OMCI TX RX Stats */
2880func (options *OnuOmciTxRxStats) Execute(args []string) error {
2881 conn, err := NewConnection()
2882 if err != nil {
2883 return err
2884 }
2885 defer conn.Close()
2886 client := extension.NewExtensionClient(conn)
2887
2888 singleGetValReq := extension.SingleGetValueRequest{
2889 TargetId: string(options.Args.Id),
2890 Request: &extension.GetValueRequest{
2891 Request: &extension.GetValueRequest_OnuOmciStats{
2892 OnuOmciStats: &extension.GetOnuOmciTxRxStatsRequest{},
2893 },
2894 },
2895 }
2896
2897 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2898 defer cancel()
2899 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2900 if err != nil {
2901 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2902 return err
2903 }
2904
2905 if rv.Response.Status != extension.GetValueResponse_OK {
2906 return fmt.Errorf("failed to get onu omci tx rx stats %v", rv.Response.ErrReason.String())
2907 }
2908 outputFormat := CharReplacer.Replace(options.Format)
2909 if outputFormat == "" {
2910 outputFormat = GetCommandOptionWithDefault("device-get-onu-omci-tx-rx-stats", "format", DEFAULT_ONU_OMCI_TX_RX_STATS_FORMAT)
2911 }
2912 result := CommandResult{
2913 Format: format.Format(outputFormat),
2914 OutputAs: toOutputType(options.OutputAs),
2915 NameLimit: options.NameLimit,
2916 Data: rv.GetResponse().GetOnuOmciStats(),
2917 }
2918 GenerateOutput(&result)
2919 return nil
2920}
praneeth nalmas1dd094c2022-12-22 14:15:13 +05302921
2922/*Device get Onu Active Alarms */
2923func (options *GetOnuOmciActiveAlarms) Execute(args []string) error {
2924 conn, err := NewConnection()
2925 if err != nil {
2926 return err
2927 }
2928 defer conn.Close()
2929 client := extension.NewExtensionClient(conn)
2930
2931 singleGetValReq := extension.SingleGetValueRequest{
2932 TargetId: string(options.Args.Id),
2933 Request: &extension.GetValueRequest{
2934 Request: &extension.GetValueRequest_OnuActiveAlarms{
2935 OnuActiveAlarms: &extension.GetOnuOmciActiveAlarmsRequest{},
2936 },
2937 },
2938 }
2939 Info.Printf("Getting omci_active_alarms for device Id %s\n", options.Args.Id)
2940 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2941 defer cancel()
2942 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2943 if err != nil {
2944 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2945 return err
2946 }
2947
2948 if rv.Response.Status != extension.GetValueResponse_OK {
2949 return fmt.Errorf("failed to get onu omci active alarms list %v", rv.Response.ErrReason.String())
2950 }
2951 outputFormat := CharReplacer.Replace(options.Format)
2952 if outputFormat == "" {
2953 outputFormat = GetCommandOptionWithDefault("device-get-onu-omci-active-alarms", "format", DEFAULT_DEVICE_ALARMS_FORMAT)
2954 }
2955
2956 orderBy := options.OrderBy
2957 if orderBy == "" {
2958 orderBy = GetCommandOptionWithDefault("device-list", "order", DEFAULT_DEVICE_ALARMS_ORDER)
2959 }
2960
2961 result := CommandResult{
2962 Format: format.Format(outputFormat),
2963 OutputAs: toOutputType(options.OutputAs),
2964 OrderBy: orderBy,
2965 NameLimit: options.NameLimit,
2966 Data: rv.GetResponse().GetOnuActiveAlarms().GetActiveAlarms(),
2967 }
2968 GenerateOutput(&result)
2969 return nil
2970}
praneeth nalmas39c71ad2023-09-27 18:29:04 +05302971
Akash Soni66db9632024-04-15 09:05:15 +05302972/*Device get Onu Active Alarms */
2973func (options *GetOnuDistance) Execute(args []string) error {
2974 conn, err := NewConnection()
2975 if err != nil {
2976 return err
2977 }
2978 defer conn.Close()
2979 client := extension.NewExtensionClient(conn)
2980
2981 singleGetValReq := extension.SingleGetValueRequest{
2982 TargetId: string(options.Args.Id),
2983 Request: &extension.GetValueRequest{
2984 Request: &extension.GetValueRequest_Distance{
2985 Distance: &extension.GetDistanceRequest{
2986 OnuDeviceId: string(options.Args.OnuId),
2987 },
2988 },
2989 },
2990 }
2991 Info.Printf("Getting onu distance for device Id %s\n", options.Args.Id)
2992 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2993 defer cancel()
2994 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2995 if err != nil {
2996 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2997 return err
2998 }
2999
3000 if rv.Response.Status != extension.GetValueResponse_OK {
3001 return fmt.Errorf("failed to get onu distance stats %v", rv.Response.ErrReason.String())
3002 }
3003 outputFormat := CharReplacer.Replace(options.Format)
3004 if outputFormat == "" {
3005 outputFormat = GetCommandOptionWithDefault("get-onu-distance", "format", DEFAULT_ONU_DISTANCE_FORMAT)
3006 }
3007
3008 result := CommandResult{
3009 Format: format.Format(outputFormat),
3010 OutputAs: toOutputType(options.OutputAs),
3011 NameLimit: options.NameLimit,
3012 Data: rv.GetResponse().GetDistance().GetDistance(),
3013 }
3014 fmt.Println("onu distance : ", rv)
3015 GenerateOutput(&result)
3016 return nil
3017}
3018
praneeth nalmas39c71ad2023-09-27 18:29:04 +05303019func (options *PonRxPower) Execute(args []string) error {
3020 conn, err := NewConnection()
3021 if err != nil {
3022 return err
3023 }
3024 defer conn.Close()
3025 client := extension.NewExtensionClient(conn)
3026
3027 singleGetValReq := extension.SingleGetValueRequest{
3028 TargetId: string(options.Args.Id),
3029 Request: &extension.GetValueRequest{
3030 Request: &extension.GetValueRequest_OltRxPower{
3031 OltRxPower: &extension.GetOltRxPowerRequest{
3032 PortLabel: options.Args.PortLabel,
3033 OnuSn: options.Args.SerialNo,
3034 },
3035 },
3036 },
3037 }
3038
3039 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3040 defer cancel()
3041 rv, err := client.GetExtValue(ctx, &singleGetValReq)
3042 if err != nil {
3043 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
3044 return err
3045 }
3046 if rv.Response.Status != extension.GetValueResponse_OK {
3047 return fmt.Errorf("failed to get rx power %v", rv.Response.ErrReason.String())
3048 }
3049 outputFormat := CharReplacer.Replace(options.Format)
3050 if outputFormat == "" {
3051 outputFormat = GetCommandOptionWithDefault("device-get-pon-rx-power", "format", DEFAULT_PON_RX_POWER_STATUS_FORMAT)
3052 }
3053 result := CommandResult{
3054 Format: format.Format(outputFormat),
3055 OutputAs: toOutputType(options.OutputAs),
3056 NameLimit: options.NameLimit,
3057 Data: rv.GetResponse().GetOltRxPower().GetRxPower(),
3058 }
3059 GenerateOutput(&result)
3060 return nil
3061}
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +05303062
3063func (options *GetOnuGEMStats) Execute(args []string) error {
3064
3065 conn, err := NewConnection()
3066 if err != nil {
3067 return err
3068 }
3069 defer conn.Close()
3070 client := extension.NewExtensionClient(conn)
3071 singleGetValReq := extension.SingleGetValueRequest{
3072 TargetId: string(options.Args.Id),
3073 Request: &extension.GetValueRequest{
3074 Request: &extension.GetValueRequest_OnuAllocGemStats{
3075 OnuAllocGemStats: &extension.GetOnuAllocGemHistoryRequest{},
3076 },
3077 },
3078 }
3079
3080 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3081 defer cancel()
3082
3083 rv, err := client.GetExtValue(ctx, &singleGetValReq)
3084
3085 if err != nil {
3086 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
3087 return err
3088 }
3089
3090 if rv.Response.Status != extension.GetValueResponse_OK {
3091 return fmt.Errorf("failed to get gem port response %v", rv.Response.ErrReason.String())
3092 }
3093 outputFormat := CharReplacer.Replace(options.Format)
3094 if outputFormat == "" {
3095 outputFormat = GetCommandOptionWithDefault("device-get-gem-port", "format", DEFAULT_DEVICE_VALUE_GEM_PORT_FORMAT)
3096 }
3097 onugemhistoryresponse := rv.GetResponse().GetOnuAllocGemStatsResponse()
3098 for _, OnuallocGemHistoryData := range onugemhistoryresponse.OnuAllocGemHistoryData {
3099 data := onugemstats{}
3100 data.AllocId = OnuallocGemHistoryData.OnuAllocIdInfo.AllocId
3101 data.AllocRxBytes = OnuallocGemHistoryData.OnuAllocIdInfo.RxBytes
3102 for _, gemStatsInfo := range OnuallocGemHistoryData.GemPortInfo {
3103 data.GemHistoryStats = append(data.GemHistoryStats, gemHistoryStats{
3104 GemId: gemStatsInfo.GemId,
3105 TransmittedGEMFrames: gemStatsInfo.TransmittedGEMFrames,
3106 ReceivedGEMFrames: gemStatsInfo.ReceivedGEMFrames,
3107 ReceivedPayloadBytes: gemStatsInfo.ReceivedPayloadBytes,
3108 TransmittedPayloadBytes: gemStatsInfo.TransmittedPayloadBytes,
3109 EncryptionKeyErrors: gemStatsInfo.EncryptionKeyErrors,
3110 })
3111 }
3112 result := CommandResult{
3113 Format: format.Format(outputFormat),
3114 OutputAs: toOutputType(options.OutputAs),
3115 NameLimit: options.NameLimit,
3116 Data: &data,
3117 }
3118 GenerateOutput(&result)
3119 }
3120 return nil
3121
3122}
3123
Akash Reddy Kankanala6965c652025-10-15 23:30:16 +05303124func (options *GetOnuFecHistory) Execute(args []string) error {
3125 conn, err := NewConnection()
3126 if err != nil {
3127 return err
3128 }
3129 defer conn.Close()
3130 client := extension.NewExtensionClient(conn)
3131 singleGetValReq := extension.SingleGetValueRequest{
3132 TargetId: string(options.Args.Id),
3133 Request: &extension.GetValueRequest{
3134 Request: &extension.GetValueRequest_FecHistory{
3135 FecHistory: &extension.GetOnuFecHistory{},
3136 },
3137 },
3138 }
3139 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3140 defer cancel()
3141 rv, err := client.GetExtValue(ctx, &singleGetValReq)
3142 if err != nil {
3143 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
3144 return err
3145 }
3146 if rv.Response.Status != extension.GetValueResponse_OK {
3147 return fmt.Errorf("Failed to get onu FEC history stats from ONT %v", rv.Response.ErrReason.String())
3148 }
3149
3150 outputFormat := CharReplacer.Replace(options.Format)
3151 if outputFormat == "" {
3152 outputFormat = GetCommandOptionWithDefault("device-get-onu-fec-History", "format", DEFAULT_ONU_FEC_HISTORY_FORMAT)
3153 }
3154 result := CommandResult{
3155 Format: format.Format(outputFormat),
3156 OutputAs: toOutputType(options.OutputAs),
3157 NameLimit: options.NameLimit,
3158 Data: rv.GetResponse().GetFecHistory(),
3159 }
3160 GenerateOutput(&result)
3161 return nil
3162
3163}
3164
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +05303165func (options *GetOnuAllocGemStatsFromOlt) Execute(args []string) error {
3166 conn, err := NewConnection()
3167 if err != nil {
3168 return err
3169 }
3170 defer conn.Close()
3171 client := extension.NewExtensionClient(conn)
3172
3173 singleGetValReq := extension.SingleGetValueRequest{
3174 TargetId: string(options.Args.Id),
3175 Request: &extension.GetValueRequest{
3176 Request: &extension.GetValueRequest_OnuStatsFromOlt{
3177 OnuStatsFromOlt: &extension.GetOnuStatsFromOltRequest{},
3178 },
3179 },
3180 }
3181 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3182 defer cancel()
3183 rv, err := client.GetExtValue(ctx, &singleGetValReq)
3184 if err != nil {
3185 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
3186 return err
3187 }
3188
3189 if rv.Response.Status != extension.GetValueResponse_OK {
3190 return fmt.Errorf("failed to get onu alloc gem stats from olt %v", rv.Response.ErrReason.String())
3191 }
3192 outputFormat := CharReplacer.Replace(options.Format)
3193 if outputFormat == "" {
3194 outputFormat = GetCommandOptionWithDefault("device-get-onu-status", "format", DEFAULT_ONU_STATS_FROM_OLT_FORMAT)
3195 }
3196
3197 onuAllocGemStatsResponse := rv.GetResponse().GetOnuStatsFromOltResponse()
3198
3199 for _, allocGemStatsInfo := range onuAllocGemStatsResponse.AllocGemStatsInfo {
3200 data := AllocGemStatsFromOlt{}
3201 data.AllocId = allocGemStatsInfo.AllocIdInfo.AllocId
3202 data.AllocRxBytes = allocGemStatsInfo.AllocIdInfo.RxBytes
3203 for _, gemStatsInfo := range allocGemStatsInfo.GemPortInfo {
3204 data.GemPortStats = append(data.GemPortStats, GemPortStatsFromOlt{
3205 GemId: gemStatsInfo.GemId,
3206 RxBytes: gemStatsInfo.RxBytes,
3207 RxPackets: gemStatsInfo.RxPackets,
3208 TxBytes: gemStatsInfo.TxBytes,
3209 TxPackets: gemStatsInfo.TxPackets,
3210 })
3211 }
3212 result := CommandResult{
3213 Format: format.Format(outputFormat),
3214 OutputAs: toOutputType(options.OutputAs),
3215 NameLimit: options.NameLimit,
3216 Data: &data,
3217 }
3218 GenerateOutput(&result)
3219 }
3220
3221 return nil
3222}
mgouda35b90e62025-07-16 14:58:29 +05303223
3224func (options *DisableOnuDevice) Execute(args []string) error {
3225 conn, err := NewConnection()
3226 if err != nil {
3227 return err
3228 }
3229 defer conn.Close()
3230
3231 client := voltha.NewVolthaServiceClient(conn)
3232
3233 var lastErr error
3234 for _, i := range options.Args.Ids {
3235 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3236 defer cancel()
3237
3238 id := voltha.ID{Id: string(i)}
3239
3240 _, err := client.DisableOnuDevice(ctx, &id)
3241 if err != nil {
3242 Error.Printf("Error while disabling the onu serial number'%s': %s\n", i, err)
3243 lastErr = err
3244 continue
3245 }
3246 fmt.Printf("%s\n", i)
3247 }
3248
3249 if lastErr != nil {
3250 return NoReportErr
3251 }
3252 return nil
3253}
3254
3255func (options *EnableOnuDevice) Execute(args []string) error {
3256 conn, err := NewConnection()
3257 if err != nil {
3258 return err
3259 }
3260 defer conn.Close()
3261
3262 client := voltha.NewVolthaServiceClient(conn)
3263
3264 var lastErr error
3265 for _, i := range options.Args.Ids {
3266 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3267 defer cancel()
3268
3269 id := voltha.ID{Id: string(i)}
3270
3271 _, err := client.EnableOnuDevice(ctx, &id)
3272 if err != nil {
3273 Error.Printf("Error while enabling the onu serial number'%s': %s\n", i, err)
3274 lastErr = err
3275 continue
3276 }
3277 fmt.Printf("%s\n", i)
3278 }
3279
3280 if lastErr != nil {
3281 return NoReportErr
3282 }
3283 return nil
3284}
3285
3286func (options *DisableOnuSerialNumber) Execute(args []string) error {
3287 conn, err := NewConnection()
3288 if err != nil {
3289 return err
3290 }
3291 defer conn.Close()
3292
3293 client := voltha.NewVolthaServiceClient(conn)
3294
3295 id := common.ID{Id: string(options.Args.OltDeviceId)}
3296 port := voltha.Port{PortNo: uint32(options.Args.Port)}
3297
3298 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3299 defer cancel()
3300
3301 req := &voltha.OnuSerialNumberOnOLTPon{
3302 OltDeviceId: &id,
3303 SerialNumber: options.Args.SerialNumber,
3304 Port: &port,
3305 }
3306
3307 _, err = client.DisableOnuSerialNumber(ctx, req)
3308 if err != nil {
3309 Error.Printf("Error disabling ONU serial '%s' on OLT '%s': %v\n", options.Args.SerialNumber, options.Args.OltDeviceId, err)
3310 return err
3311 }
3312 fmt.Printf("Disabled ONU serial '%s' on OLT '%s'\n", options.Args.SerialNumber, options.Args.OltDeviceId)
3313 return nil
3314}
3315
3316func (options *EnableOnuSerialNumber) Execute(args []string) error {
3317 conn, err := NewConnection()
3318 if err != nil {
3319 return err
3320 }
3321 defer conn.Close()
3322
3323 client := voltha.NewVolthaServiceClient(conn)
3324
3325 id := common.ID{Id: string(options.Args.OltDeviceId)}
3326 port := voltha.Port{PortNo: uint32(options.Args.Port)}
3327
3328 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3329 defer cancel()
3330
3331 req := &voltha.OnuSerialNumberOnOLTPon{
3332 OltDeviceId: &id,
3333 SerialNumber: options.Args.SerialNumber,
3334 Port: &port,
3335 }
3336
3337 _, err = client.EnableOnuSerialNumber(ctx, req)
3338 if err != nil {
3339 Error.Printf("Error enabling ONU serial '%s' on OLT '%s': %v\n", options.Args.SerialNumber, options.Args.OltDeviceId, err)
3340 return err
3341 }
3342 fmt.Printf("Enabled ONU serial '%s' on OLT '%s'\n", options.Args.SerialNumber, options.Args.OltDeviceId)
3343 return nil
3344}