blob: 61bb758edb4ddbd7ac742266a6ca3962c27faa31 [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}}`
174
175 DEFAULT_ONU_DISTANCE_FORMAT = `Distance`
176 DEFAULT_DEVICE_ALARMS_FORMAT = "table{{ .ClassId }}\t{{.InstanceId}}\t{{.Name}}\t{{.Description}}"
177 DEFAULT_DEVICE_ALARMS_ORDER = "ClassId,InstanceId"
178 DEFAULT_PON_RX_POWER_STATUS_FORMAT = "table{{.OnuSn}}\t{{.Status}}\t{{.FailReason}}\t{{.RxPower}}\t"
179 DEFAULT_DEVICE_VALUE_GEM_PORT_FORMAT = `AllocId: {{.AllocId}}
180 AllocRxBytes: {{.AllocRxBytes}}
181 {{range .GemHistoryStats}}
182-GemId: {{.GemId}}
183 TransmittedGEMFrames: {{.TransmittedGEMFrames}}
184 ReceivedGEMFrames: {{.ReceivedGEMFrames}}
185 ReceivedPayloadBytes: {{.ReceivedPayloadBytes}}
186 TransmittedPayloadBytes:{{.TransmittedPayloadBytes}}
187 EncryptionKeyErrors: {{.EncryptionKeyErrors}}{{end}}`
Zack Williamse940c7a2019-08-21 14:25:39 -0700188)
189
190type DeviceList struct {
191 ListOutputOptions
192}
193
194type DeviceCreate struct {
David Bainbridge1a514392020-06-23 11:12:51 -0700195 DeviceType string `short:"t" required:"true" long:"devicetype" description:"Device type"`
David Bainbridge835dd0e2020-04-01 10:30:09 -0700196 MACAddress string `short:"m" long:"macaddress" default:"" description:"MAC Address"`
Zack Williamse940c7a2019-08-21 14:25:39 -0700197 IPAddress string `short:"i" long:"ipaddress" default:"" description:"IP Address"`
198 HostAndPort string `short:"H" long:"hostandport" default:"" description:"Host and port"`
199}
200
201type DeviceId string
Akash Soni66db9632024-04-15 09:05:15 +0530202type OnuId string
Zack Williamse940c7a2019-08-21 14:25:39 -0700203
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000204type MetricName string
205type GroupName string
kesavand12cd8eb2020-01-20 22:25:22 -0500206type PortNum uint32
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -0800207type ValueFlag string
kesavand12cd8eb2020-01-20 22:25:22 -0500208
Zack Williamse940c7a2019-08-21 14:25:39 -0700209type DeviceDelete struct {
Himani Chawla9933ddc2020-10-12 23:53:27 +0530210 Force bool `long:"force" description:"Delete device forcefully"`
211 Args struct {
Zack Williamse940c7a2019-08-21 14:25:39 -0700212 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
213 } `positional-args:"yes"`
214}
215
216type DeviceEnable struct {
217 Args struct {
218 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
219 } `positional-args:"yes"`
220}
221
222type DeviceDisable struct {
223 Args struct {
224 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
225 } `positional-args:"yes"`
226}
227
228type DeviceReboot struct {
229 Args struct {
230 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
231 } `positional-args:"yes"`
232}
233
234type DeviceFlowList struct {
235 ListOutputOptions
Maninder045921e2020-09-29 16:46:02 +0530236 FlowIdOptions
Zack Williamse940c7a2019-08-21 14:25:39 -0700237 Args struct {
238 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
239 } `positional-args:"yes"`
240}
241
Himani Chawla3c161c62021-05-13 16:36:51 +0530242type DeviceFlowGroupList struct {
243 ListOutputOptions
244 GroupListOptions
245 Args struct {
246 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
247 } `positional-args:"yes"`
248}
Zack Williamse940c7a2019-08-21 14:25:39 -0700249type DevicePortList struct {
250 ListOutputOptions
251 Args struct {
252 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
253 } `positional-args:"yes"`
254}
255
256type DeviceInspect struct {
257 OutputOptionsJson
258 Args struct {
259 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
260 } `positional-args:"yes"`
261}
262
kesavand12cd8eb2020-01-20 22:25:22 -0500263type DevicePortEnable struct {
264 Args struct {
265 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
266 PortId PortNum `positional-arg-name:"PORT_NUMBER" required:"yes"`
267 } `positional-args:"yes"`
268}
269
270type DevicePortDisable struct {
271 Args struct {
272 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
273 PortId PortNum `positional-arg-name:"PORT_NUMBER" required:"yes"`
274 } `positional-args:"yes"`
275}
276
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000277type DevicePmConfigsGet struct {
278 ListOutputOptions
279 Args struct {
280 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
281 } `positional-args:"yes"`
282}
283
284type DevicePmConfigMetricList struct {
285 ListOutputOptions
286 Args struct {
287 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
288 } `positional-args:"yes"`
289}
290
291type DevicePmConfigGroupList struct {
292 ListOutputOptions
293 Args struct {
294 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
295 } `positional-args:"yes"`
296}
297
298type DevicePmConfigGroupMetricList struct {
299 ListOutputOptions
300 Args struct {
301 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
302 Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"`
303 } `positional-args:"yes"`
304}
305
306type DevicePmConfigFrequencySet struct {
307 OutputOptions
308 Args struct {
Girish Gowdra610acb42021-01-27 13:33:57 -0800309 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
310 Interval time.Duration `positional-arg-name:"INTERVAL" required:"yes"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000311 } `positional-args:"yes"`
312}
313
314type DevicePmConfigMetricEnable struct {
315 Args struct {
316 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
317 Metrics []MetricName `positional-arg-name:"METRIC_NAME" required:"yes"`
318 } `positional-args:"yes"`
319}
320
321type DevicePmConfigMetricDisable struct {
322 Args struct {
323 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
324 Metrics []MetricName `positional-arg-name:"METRIC_NAME" required:"yes"`
325 } `positional-args:"yes"`
326}
327
328type DevicePmConfigGroupEnable struct {
329 Args struct {
Girish Gowdra610acb42021-01-27 13:33:57 -0800330 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
331 Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000332 } `positional-args:"yes"`
333}
334
335type DevicePmConfigGroupDisable struct {
336 Args struct {
Girish Gowdra610acb42021-01-27 13:33:57 -0800337 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
338 Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"`
339 } `positional-args:"yes"`
340}
341
342type DevicePmConfigGroupFrequencySet struct {
343 OutputOptions
344 Args struct {
345 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
346 Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"`
347 Interval time.Duration `positional-arg-name:"INTERVAL" required:"yes"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000348 } `positional-args:"yes"`
349}
350
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -0800351type DeviceGetExtValue struct {
352 ListOutputOptions
353 Args struct {
354 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
355 Valueflag ValueFlag `positional-arg-name:"VALUE_FLAG" required:"yes"`
356 } `positional-args:"yes"`
357}
Rohan Agrawald7df3772020-06-29 11:23:36 +0000358
359type DevicePmConfigSetMaxSkew struct {
360 Args struct {
361 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
362 MaxSkew uint32 `positional-arg-name:"MAX_SKEW" required:"yes"`
363 } `positional-args:"yes"`
364}
365
Andrea Campanella791d88b2021-01-08 13:29:00 +0100366type DeviceOnuListImages struct {
367 ListOutputOptions
368 Args struct {
369 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
370 } `positional-args:"yes"`
371}
372
373type DeviceOnuDownloadImage struct {
374 Args struct {
375 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
376 Name string `positional-arg-name:"IMAGE_NAME" required:"yes"`
377 Url string `positional-arg-name:"IMAGE_URL" required:"yes"`
378 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
379 Crc uint32 `positional-arg-name:"IMAGE_CRC" required:"yes"`
380 LocalDir string `positional-arg-name:"IMAGE_LOCAL_DIRECTORY"`
381 } `positional-args:"yes"`
382}
383
384type DeviceOnuActivateImageUpdate struct {
385 Args struct {
386 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
387 Name string `positional-arg-name:"IMAGE_NAME" required:"yes"`
388 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
389 SaveConfig bool `positional-arg-name:"SAVE_EXISTING_CONFIG"`
390 LocalDir string `positional-arg-name:"IMAGE_LOCAL_DIRECTORY"`
Andrea Campanella7b2ecf42021-02-25 12:27:15 +0100391 } `positional-args:"yes"`
kesavand8ec4fc02021-01-27 09:10:22 -0500392}
kesavand3e2f9f62021-04-22 11:06:38 +0530393
394type OnuDownloadImage struct {
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +0200395 ListOutputOptions
kesavand3e2f9f62021-04-22 11:06:38 +0530396 Args struct {
397 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
398 Url string `positional-arg-name:"IMAGE_URL" required:"yes"`
ssiddiqui7bc89e92021-05-20 20:58:02 +0530399 Vendor string `positional-arg-name:"IMAGE_VENDOR"`
kesavand3e2f9f62021-04-22 11:06:38 +0530400 ActivateOnSuccess bool `positional-arg-name:"IMAGE_ACTIVATE_ON_SUCCESS"`
401 CommitOnSuccess bool `positional-arg-name:"IMAGE_COMMIT_ON_SUCCESS"`
402 Crc uint32 `positional-arg-name:"IMAGE_CRC"`
403 IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
404 } `positional-args:"yes"`
405}
406
407type OnuActivateImage struct {
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +0200408 ListOutputOptions
kesavand3e2f9f62021-04-22 11:06:38 +0530409 Args struct {
410 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
411 CommitOnSuccess bool `positional-arg-name:"IMAGE_COMMIT_ON_SUCCESS"`
412 IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
413 } `positional-args:"yes"`
414}
415
416type OnuAbortUpgradeImage struct {
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +0200417 ListOutputOptions
kesavand3e2f9f62021-04-22 11:06:38 +0530418 Args struct {
419 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
420 IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
421 } `positional-args:"yes"`
422}
423
424type OnuCommitImage struct {
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +0200425 ListOutputOptions
kesavand3e2f9f62021-04-22 11:06:38 +0530426 Args struct {
427 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
428 IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
429 } `positional-args:"yes"`
430}
431
432type OnuImageStatus struct {
433 ListOutputOptions
434 Args struct {
435 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
Elia Battiston859f3e62022-02-08 15:57:52 +0100436 IDs []DeviceId `positional-arg-name:"DEVICE_ID"`
kesavand3e2f9f62021-04-22 11:06:38 +0530437 } `positional-args:"yes"`
438}
439
440type OnuListImages struct {
441 ListOutputOptions
442 Args struct {
443 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
444 } `positional-args:"yes"`
445}
446
kesavand8ec4fc02021-01-27 09:10:22 -0500447type DeviceGetPortStats struct {
448 ListOutputOptions
449 Args struct {
450 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
451 PortNo uint32 `positional-arg-name:"PORT_NO" required:"yes"`
452 PortType string `positional-arg-name:"PORT_TYPE" required:"yes"`
Andrea Campanella791d88b2021-01-08 13:29:00 +0100453 } `positional-args:"yes"`
454}
kesavand6d1131f2021-02-05 22:38:15 +0530455type UniStatus struct {
456 ListOutputOptions
457 Args struct {
458 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
459 UniIndex uint32 `positional-arg-name:"UNI_INDEX" required:"yes"`
460 } `positional-args:"yes"`
461}
Girish Gowdra4f5ce7c2021-04-29 18:53:21 -0700462type OnuPonOpticalInfo struct {
463 ListOutputOptions
464 Args struct {
465 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
466 } `positional-args:"yes"`
467}
Himani Chawla40acc122021-05-26 18:52:29 +0530468
469type GetOnuStats struct {
470 ListOutputOptions
471 Args struct {
472 OltId DeviceId `positional-arg-name:"OLT_DEVICE_ID" required:"yes"`
473 IntfId uint32 `positional-arg-name:"PON_INTF_ID" required:"yes"`
474 OnuId uint32 `positional-arg-name:"ONU_ID" required:"yes"`
475 } `positional-args:"yes"`
476}
477
Akash Soni6e879c22024-12-20 17:01:34 +0530478type GetOffloadApp struct {
Akash Soni51b6b7a2024-11-20 11:39:38 +0530479 ListOutputOptions
480 Args struct {
481 OltId DeviceId `positional-arg-name:"OLT_DEVICE_ID" required:"yes"`
482 StatsFor extension.GetOffloadedAppsStatisticsRequest_OffloadedApp `positional-arg-name:"OFFLOADED_APP" required:"yes"`
483 } `positional-args:"yes"`
484}
485
Akash Soni6e879c22024-12-20 17:01:34 +0530486type SetOffloadApp struct {
487 ListOutputOptions
Akash Soni51b6b7a2024-11-20 11:39:38 +0530488 Args struct {
Akash Soni6e879c22024-12-20 17:01:34 +0530489 OltId DeviceId `positional-arg-name:"OLT_DEVICE_ID" required:"yes"`
490 Config string `positional-arg-name:"CONFIG" required:"yes"` // Accept JSON or CSV input
Akash Soni51b6b7a2024-11-20 11:39:38 +0530491 } `positional-args:"yes"`
492}
493
Akash Soni6e879c22024-12-20 17:01:34 +0530494type AppOffloadOnuConfig struct {
495 AgentRemoteID string
496 AgentCircuitID string
497 OnuUniId uint32
498}
499
500type SetOnuOffload struct {
501 ListOutputOptions
Akash Soni51b6b7a2024-11-20 11:39:38 +0530502 Args struct {
Akash Soni6e879c22024-12-20 17:01:34 +0530503 OltId DeviceId `positional-arg-name:"OLT_DEVICE_ID" required:"yes"`
504 OnuDeviceId string `positional-arg-name:"ONU_DEVICE_ID" required:"yes"`
505 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 +0530506 } `positional-args:"yes"`
507}
508
Himani Chawla553a1392021-06-10 23:39:17 +0530509type GetOnuEthernetFrameExtendedPmCounters struct {
510 ListOutputOptions
Himani Chawla806aa892021-08-30 15:51:46 +0530511 Reset bool `long:"reset" description:"Reset the counters"`
512 Args struct {
513 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
514 UniIndex *uint32 `positional-arg-name:"UNI_INDEX"`
Himani Chawla553a1392021-06-10 23:39:17 +0530515 } `positional-args:"yes"`
516}
517
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +0530518type GetPonPortStats struct {
519 ListOutputOptions
520 Reset bool `long:"reset" description:"Reset the counters"`
521 Args struct {
522 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
523 PortLabel string `positional-arg-name:"PORT_LABEL" required:"yes"`
524 } `positional-args:"yes"`
525}
526
527type GetNniPortStats struct {
528 ListOutputOptions
529 Reset bool `long:"reset" description:"Reset the counters"`
530 Args struct {
531 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
532 PortLabel string `positional-arg-name:"PORT_LABEL" required:"yes"`
533 } `positional-args:"yes"`
534}
535
536type GetOnuAllocGemStatsFromOlt struct {
537 ListOutputOptions
538 Args struct {
539 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
540 } `positional-args:"yes"`
541}
Gamze Abakac857a462021-05-26 13:45:54 +0000542type RxPower struct {
543 ListOutputOptions
544 Args struct {
545 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
546 PortNo uint32 `positional-arg-name:"PORT_NO" required:"yes"`
547 OnuNo uint32 `positional-arg-name:"ONU_NO" required:"yes"`
548 } `positional-args:"yes"`
549}
550
praneeth nalmas39c71ad2023-09-27 18:29:04 +0530551type PonRxPower struct {
552 ListOutputOptions
553 Args struct {
554 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
555 PortLabel string `positional-arg-name:"PORT_LABEL" required:"yes"`
556 SerialNo string `positional-arg-name:"ONU_SERIAL_NUMBER"`
557 } `positional-args:"yes"`
558}
559
serkantul3d22fc72022-09-14 12:22:56 +0300560type OnuOmciTxRxStats struct {
561 ListOutputOptions
562 Args struct {
563 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
564 } `positional-args:"yes"`
565}
566
praneeth nalmas1dd094c2022-12-22 14:15:13 +0530567type GetOnuOmciActiveAlarms struct {
568 ListOutputOptions
569 Args struct {
570 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
571 } `positional-args:"yes"`
572}
573
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +0530574type GetOnuGEMStats struct {
575 ListOutputOptions
576 Args struct {
577 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
578 } `positional-args:"yes"`
579}
580
Akash Soni66db9632024-04-15 09:05:15 +0530581type GetOnuDistance struct {
582 ListOutputOptions
583 Args struct {
584 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
585 OnuId OnuId `positional-arg-name:"ONU_ID" required:"yes"`
586 } `positional-args:"yes"` //onu device id
587}
588
mgouda35b90e62025-07-16 14:58:29 +0530589type DisableOnuDevice struct {
590 Args struct {
591 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
592 } `positional-args:"yes"`
593}
594
595type EnableOnuDevice struct {
596 Args struct {
597 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
598 } `positional-args:"yes"`
599}
600
601type DisableOnuSerialNumber struct {
602 Args struct {
603 SerialNumber string `positional-arg-name:"ONU_SERIAL_NUMBER" required:"yes"`
604 Port PortNum `positional-arg-name:"PORT_NO" required:"yes"`
605 OltDeviceId DeviceId `positional-arg-name:"OLT_DEVICE_ID" required:"yes"`
606 } `positional-args:"yes"`
607}
608
609type EnableOnuSerialNumber struct {
610 Args struct {
611 SerialNumber string `positional-arg-name:"ONU_SERIAL_NUMBER" required:"yes"`
612 Port PortNum `positional-arg-name:"PORT_NO" required:"yes"`
613 OltDeviceId DeviceId `positional-arg-name:"OLT_DEVICE_ID" required:"yes"`
614 } `positional-args:"yes"`
615}
616
Zack Williamse940c7a2019-08-21 14:25:39 -0700617type DeviceOpts struct {
mgouda35b90e62025-07-16 14:58:29 +0530618 List DeviceList `command:"list"`
619 Create DeviceCreate `command:"create"`
620 Delete DeviceDelete `command:"delete"`
621 Enable DeviceEnable `command:"enable"`
622 Disable DeviceDisable `command:"disable"`
623 DisableOnuDevice DisableOnuDevice `command:"disable_onu"`
624 EnableOnuDevice EnableOnuDevice `command:"enable_onu"`
625 DisableOnuSerialNumber DisableOnuSerialNumber `command:"disable_onu_serial"`
626 EnableOnuSerialNumber EnableOnuSerialNumber `command:"enable_onu_serial"`
627 Flows DeviceFlowList `command:"flows"`
628 Groups DeviceFlowGroupList `command:"groups"`
629 Port struct {
kesavand12cd8eb2020-01-20 22:25:22 -0500630 List DevicePortList `command:"list"`
631 Enable DevicePortEnable `command:"enable"`
632 Disable DevicePortDisable `command:"disable"`
633 } `command:"port"`
634 Inspect DeviceInspect `command:"inspect"`
635 Reboot DeviceReboot `command:"reboot"`
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -0800636 Value struct {
637 Get DeviceGetExtValue `command:"get"`
638 } `command:"value"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000639 PmConfig struct {
Rohan Agrawald7df3772020-06-29 11:23:36 +0000640 Get DevicePmConfigsGet `command:"get"`
641 MaxSkew struct {
642 Set DevicePmConfigSetMaxSkew `command:"set"`
643 } `command:"maxskew"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000644 Frequency struct {
645 Set DevicePmConfigFrequencySet `command:"set"`
646 } `command:"frequency"`
647 Metric struct {
648 List DevicePmConfigMetricList `command:"list"`
649 Enable DevicePmConfigMetricEnable `command:"enable"`
650 Disable DevicePmConfigMetricDisable `command:"disable"`
651 } `command:"metric"`
652 Group struct {
Girish Gowdra610acb42021-01-27 13:33:57 -0800653 List DevicePmConfigGroupList `command:"list"`
654 Enable DevicePmConfigGroupEnable `command:"enable"`
655 Disable DevicePmConfigGroupDisable `command:"disable"`
656 Set DevicePmConfigGroupFrequencySet `command:"set"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000657 } `command:"group"`
658 GroupMetric struct {
659 List DevicePmConfigGroupMetricList `command:"list"`
660 } `command:"groupmetric"`
661 } `command:"pmconfig"`
Andrea Campanella791d88b2021-01-08 13:29:00 +0100662 Image struct {
663 Get DeviceOnuListImages `command:"list"`
664 Download DeviceOnuDownloadImage `command:"download"`
665 Activate DeviceOnuActivateImageUpdate `command:"activate"`
666 } `command:"image"`
kesavand3e2f9f62021-04-22 11:06:38 +0530667 DownloadImage struct {
668 Download OnuDownloadImage `command:"download"`
669 Activate OnuActivateImage `command:"activate"`
670 Commit OnuCommitImage `command:"commit"`
671 AbortUpgrade OnuAbortUpgradeImage `command:"abort"`
672 Status OnuImageStatus `command:"status"`
673 List OnuListImages `command:"list" `
674 } `command:"onuimage"`
kesavand8ec4fc02021-01-27 09:10:22 -0500675 GetExtVal struct {
Himani Chawla553a1392021-06-10 23:39:17 +0530676 Stats DeviceGetPortStats `command:"portstats"`
677 UniStatus UniStatus `command:"unistatus"`
678 OpticalInfo OnuPonOpticalInfo `command:"onu_pon_optical_info"`
679 OnuStats GetOnuStats `command:"onu_stats"`
680 EthernetFrameExtendedPm GetOnuEthernetFrameExtendedPmCounters `command:"ethernet_frame_extended_pm"`
681 RxPower RxPower `command:"rxpower"`
serkantul3d22fc72022-09-14 12:22:56 +0300682 OnuOmciStats OnuOmciTxRxStats `command:"onu_omci_stats"`
praneeth nalmas1dd094c2022-12-22 14:15:13 +0530683 OnuOmciActiveAlarms GetOnuOmciActiveAlarms `command:"onu_omci_active_alarms"`
praneeth nalmas39c71ad2023-09-27 18:29:04 +0530684 PonRxPower PonRxPower `command:"pon_rx_power"`
Akash Soni66db9632024-04-15 09:05:15 +0530685 OnuDistance GetOnuDistance `command:"onu_distance"`
Akash Soni6e879c22024-12-20 17:01:34 +0530686 OffloadAppStats GetOffloadApp `command:"offload_app_stats"`
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +0530687 PonStats GetPonPortStats `command:"itu_pon_stats"`
688 NniStats GetNniPortStats `command:"nni_statistics"`
689 OnuGEMStats GetOnuGEMStats `command:"onu_gem_stats"`
690 OnuAllocGemStats GetOnuAllocGemStatsFromOlt `command:"onu_alloc_gem_from_olt"`
kesavand8ec4fc02021-01-27 09:10:22 -0500691 } `command:"getextval"`
Akash Soni51b6b7a2024-11-20 11:39:38 +0530692 SetExtVal struct {
Akash Soni6e879c22024-12-20 17:01:34 +0530693 OffloadAppStatsSet SetOffloadApp `command:"set_offload_app"`
694 OnuOffloadStatsSet SetOnuOffload `command:"set_onu_offload"`
Akash Soni51b6b7a2024-11-20 11:39:38 +0530695 } `command:"setextval"`
Zack Williamse940c7a2019-08-21 14:25:39 -0700696}
697
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +0530698type AllocGemStatsFromOlt struct {
699 AllocId uint32
700 AllocRxBytes uint64
701 GemPortStats []GemPortStatsFromOlt
702}
703type GemPortStatsFromOlt struct {
704 GemId uint32
705 RxPackets uint64
706 RxBytes uint64
707 TxPackets uint64
708 TxBytes uint64
709}
710type onugemstats struct {
711 AllocId uint32
712 AllocRxBytes uint32
713 GemHistoryStats []gemHistoryStats
714}
715type gemHistoryStats struct {
716 GemId uint32
717 TransmittedGEMFrames uint32
718 ReceivedGEMFrames uint32
719 ReceivedPayloadBytes uint32
720 TransmittedPayloadBytes uint32
721 EncryptionKeyErrors uint32
722}
723
724type PortStats struct {
725 PonPort uint32 // use this for PON
726 NniPort uint32 // use this for NNI
727 *common.PortStatistics
728}
729
Zack Williamse940c7a2019-08-21 14:25:39 -0700730var deviceOpts = DeviceOpts{}
731
732func RegisterDeviceCommands(parser *flags.Parser) {
David Bainbridge12f036f2019-10-15 22:09:04 +0000733 if _, err := parser.AddCommand("device", "device commands", "Commands to query and manipulate VOLTHA devices", &deviceOpts); err != nil {
David Bainbridgea6722342019-10-24 23:55:53 +0000734 Error.Fatalf("Unexpected error while attempting to register device commands : %s", err)
David Bainbridge12f036f2019-10-15 22:09:04 +0000735 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700736}
737
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000738func (i *MetricName) Complete(match string) []flags.Completion {
739 conn, err := NewConnection()
740 if err != nil {
741 return nil
742 }
743 defer conn.Close()
744
745 client := voltha.NewVolthaServiceClient(conn)
746
747 var deviceId string
748found:
749 for i := len(os.Args) - 1; i >= 0; i -= 1 {
750 switch os.Args[i] {
751 case "enable":
752 fallthrough
753 case "disable":
754 if len(os.Args) > i+1 {
755 deviceId = os.Args[i+1]
756 } else {
757 return nil
758 }
759 break found
760 default:
761 }
762 }
763
764 if len(deviceId) == 0 {
765 return nil
766 }
767
David K. Bainbridge9189c632021-03-26 21:52:21 +0000768 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000769 defer cancel()
770
771 id := voltha.ID{Id: string(deviceId)}
772
773 pmconfigs, err := client.ListDevicePmConfigs(ctx, &id)
774
775 if err != nil {
776 return nil
777 }
778
779 list := make([]flags.Completion, 0)
780 for _, metrics := range pmconfigs.Metrics {
781 if strings.HasPrefix(metrics.Name, match) {
782 list = append(list, flags.Completion{Item: metrics.Name})
783 }
784 }
785
786 return list
787}
788
789func (i *GroupName) Complete(match string) []flags.Completion {
790 conn, err := NewConnection()
791 if err != nil {
792 return nil
793 }
794 defer conn.Close()
795
796 client := voltha.NewVolthaServiceClient(conn)
797
798 var deviceId string
799found:
800 for i := len(os.Args) - 1; i >= 0; i -= 1 {
801 switch os.Args[i] {
802 case "list":
803 fallthrough
804 case "enable":
805 fallthrough
806 case "disable":
807 if len(os.Args) > i+1 {
808 deviceId = os.Args[i+1]
809 } else {
810 return nil
811 }
812 break found
813 default:
814 }
815 }
816
817 if len(deviceId) == 0 {
818 return nil
819 }
820
David K. Bainbridge9189c632021-03-26 21:52:21 +0000821 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000822 defer cancel()
823
824 id := voltha.ID{Id: string(deviceId)}
825
826 pmconfigs, err := client.ListDevicePmConfigs(ctx, &id)
827
828 if err != nil {
829 return nil
830 }
831
832 list := make([]flags.Completion, 0)
833 for _, group := range pmconfigs.Groups {
834 if strings.HasPrefix(group.GroupName, match) {
835 list = append(list, flags.Completion{Item: group.GroupName})
836 }
837 }
838 return list
839}
840
kesavand12cd8eb2020-01-20 22:25:22 -0500841func (i *PortNum) Complete(match string) []flags.Completion {
842 conn, err := NewConnection()
843 if err != nil {
844 return nil
845 }
846 defer conn.Close()
847
Scott Baker9173ed82020-05-19 08:30:12 -0700848 client := voltha.NewVolthaServiceClient(conn)
kesavand12cd8eb2020-01-20 22:25:22 -0500849
850 /*
851 * The command line args when completing for PortNum will be a DeviceId
852 * followed by one or more PortNums. So walk the argument list from the
853 * end and find the first argument that is enable/disable as those are
854 * the subcommands that come before the positional arguments. It would
855 * be nice if this package gave us the list of optional arguments
856 * already parsed.
857 */
858 var deviceId string
859found:
860 for i := len(os.Args) - 1; i >= 0; i -= 1 {
861 switch os.Args[i] {
862 case "enable":
863 fallthrough
864 case "disable":
865 if len(os.Args) > i+1 {
866 deviceId = os.Args[i+1]
867 } else {
868 return nil
869 }
870 break found
871 default:
872 }
873 }
874
875 if len(deviceId) == 0 {
876 return nil
877 }
878
David K. Bainbridge9189c632021-03-26 21:52:21 +0000879 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand12cd8eb2020-01-20 22:25:22 -0500880 defer cancel()
kesavand12cd8eb2020-01-20 22:25:22 -0500881
Scott Baker9173ed82020-05-19 08:30:12 -0700882 id := voltha.ID{Id: string(deviceId)}
kesavand12cd8eb2020-01-20 22:25:22 -0500883
Scott Baker9173ed82020-05-19 08:30:12 -0700884 ports, err := client.ListDevicePorts(ctx, &id)
kesavand12cd8eb2020-01-20 22:25:22 -0500885 if err != nil {
886 return nil
887 }
888
889 list := make([]flags.Completion, 0)
Scott Baker9173ed82020-05-19 08:30:12 -0700890 for _, item := range ports.Items {
891 pn := strconv.FormatUint(uint64(item.PortNo), 10)
kesavand12cd8eb2020-01-20 22:25:22 -0500892 if strings.HasPrefix(pn, match) {
893 list = append(list, flags.Completion{Item: pn})
894 }
895 }
896
897 return list
898}
899
Zack Williamse940c7a2019-08-21 14:25:39 -0700900func (i *DeviceId) Complete(match string) []flags.Completion {
901 conn, err := NewConnection()
902 if err != nil {
903 return nil
904 }
905 defer conn.Close()
906
Scott Baker9173ed82020-05-19 08:30:12 -0700907 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700908
David K. Bainbridge9189c632021-03-26 21:52:21 +0000909 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700910 defer cancel()
911
Scott Baker9173ed82020-05-19 08:30:12 -0700912 devices, err := client.ListDevices(ctx, &empty.Empty{})
Zack Williamse940c7a2019-08-21 14:25:39 -0700913 if err != nil {
914 return nil
915 }
916
917 list := make([]flags.Completion, 0)
Scott Baker9173ed82020-05-19 08:30:12 -0700918 for _, item := range devices.Items {
919 if strings.HasPrefix(item.Id, match) {
920 list = append(list, flags.Completion{Item: item.Id})
Zack Williamse940c7a2019-08-21 14:25:39 -0700921 }
922 }
923
924 return list
925}
926
927func (options *DeviceList) Execute(args []string) error {
928
929 conn, err := NewConnection()
930 if err != nil {
931 return err
932 }
933 defer conn.Close()
934
Scott Baker9173ed82020-05-19 08:30:12 -0700935 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700936
David K. Bainbridge9189c632021-03-26 21:52:21 +0000937 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700938 defer cancel()
939
Scott Baker9173ed82020-05-19 08:30:12 -0700940 devices, err := client.ListDevices(ctx, &empty.Empty{})
Zack Williamse940c7a2019-08-21 14:25:39 -0700941 if err != nil {
942 return err
943 }
944
945 outputFormat := CharReplacer.Replace(options.Format)
946 if outputFormat == "" {
David Bainbridgea6722342019-10-24 23:55:53 +0000947 outputFormat = GetCommandOptionWithDefault("device-list", "format", DEFAULT_DEVICE_FORMAT)
Zack Williamse940c7a2019-08-21 14:25:39 -0700948 }
949 if options.Quiet {
950 outputFormat = "{{.Id}}"
951 }
952
David Bainbridgea6722342019-10-24 23:55:53 +0000953 orderBy := options.OrderBy
954 if orderBy == "" {
Hardik Windlass9361bb82022-03-23 05:58:48 +0000955 orderBy = GetCommandOptionWithDefault("device-list", "order", DEFAULT_DEVICE_ORDER)
David Bainbridgea6722342019-10-24 23:55:53 +0000956 }
957
Scott Baker9173ed82020-05-19 08:30:12 -0700958 // Make sure json output prints an empty list, not "null"
959 if devices.Items == nil {
960 devices.Items = make([]*voltha.Device, 0)
Zack Williamse940c7a2019-08-21 14:25:39 -0700961 }
962
963 result := CommandResult{
964 Format: format.Format(outputFormat),
965 Filter: options.Filter,
David Bainbridgea6722342019-10-24 23:55:53 +0000966 OrderBy: orderBy,
Zack Williamse940c7a2019-08-21 14:25:39 -0700967 OutputAs: toOutputType(options.OutputAs),
968 NameLimit: options.NameLimit,
Scott Baker9173ed82020-05-19 08:30:12 -0700969 Data: devices.Items,
Zack Williamse940c7a2019-08-21 14:25:39 -0700970 }
971
972 GenerateOutput(&result)
973 return nil
974}
975
976func (options *DeviceCreate) Execute(args []string) error {
977
Scott Baker9173ed82020-05-19 08:30:12 -0700978 device := voltha.Device{}
Zack Williamse940c7a2019-08-21 14:25:39 -0700979 if options.HostAndPort != "" {
Scott Baker9173ed82020-05-19 08:30:12 -0700980 device.Address = &voltha.Device_HostAndPort{HostAndPort: options.HostAndPort}
Zack Williamse940c7a2019-08-21 14:25:39 -0700981 } else if options.IPAddress != "" {
Scott Baker9173ed82020-05-19 08:30:12 -0700982 device.Address = &voltha.Device_Ipv4Address{Ipv4Address: options.IPAddress}
Hardik Windlassce1de342020-02-04 21:58:07 +0000983 }
984 if options.MACAddress != "" {
Scott Baker9173ed82020-05-19 08:30:12 -0700985 device.MacAddress = strings.ToLower(options.MACAddress)
Zack Williamse940c7a2019-08-21 14:25:39 -0700986 }
987 if options.DeviceType != "" {
Scott Baker9173ed82020-05-19 08:30:12 -0700988 device.Type = options.DeviceType
Zack Williamse940c7a2019-08-21 14:25:39 -0700989 }
990
991 conn, err := NewConnection()
992 if err != nil {
993 return err
994 }
995 defer conn.Close()
996
Scott Baker9173ed82020-05-19 08:30:12 -0700997 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700998
David K. Bainbridge9189c632021-03-26 21:52:21 +0000999 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -07001000 defer cancel()
1001
Scott Baker9173ed82020-05-19 08:30:12 -07001002 createdDevice, err := client.CreateDevice(ctx, &device)
Zack Williamse940c7a2019-08-21 14:25:39 -07001003 if err != nil {
1004 return err
Zack Williamse940c7a2019-08-21 14:25:39 -07001005 }
1006
Scott Baker9173ed82020-05-19 08:30:12 -07001007 fmt.Printf("%s\n", createdDevice.Id)
Zack Williamse940c7a2019-08-21 14:25:39 -07001008
1009 return nil
1010}
1011
1012func (options *DeviceDelete) Execute(args []string) error {
1013
1014 conn, err := NewConnection()
1015 if err != nil {
1016 return err
1017 }
1018 defer conn.Close()
1019
Scott Baker9173ed82020-05-19 08:30:12 -07001020 client := voltha.NewVolthaServiceClient(conn)
David Bainbridge7052fe82020-03-25 10:37:00 -07001021 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -07001022 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +00001023 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -07001024 defer cancel()
1025
Scott Baker9173ed82020-05-19 08:30:12 -07001026 id := voltha.ID{Id: string(i)}
Himani Chawla9933ddc2020-10-12 23:53:27 +05301027 if options.Force {
1028 _, err = client.ForceDeleteDevice(ctx, &id)
1029 } else {
1030 _, err = client.DeleteDevice(ctx, &id)
1031 }
Scott Baker9173ed82020-05-19 08:30:12 -07001032
Zack Williamse940c7a2019-08-21 14:25:39 -07001033 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +00001034 Error.Printf("Error while deleting '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -07001035 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -07001036 continue
Zack Williamse940c7a2019-08-21 14:25:39 -07001037 }
1038 fmt.Printf("%s\n", i)
1039 }
1040
David Bainbridge7052fe82020-03-25 10:37:00 -07001041 if lastErr != nil {
1042 return NoReportErr
1043 }
Zack Williamse940c7a2019-08-21 14:25:39 -07001044 return nil
1045}
1046
1047func (options *DeviceEnable) Execute(args []string) error {
1048 conn, err := NewConnection()
1049 if err != nil {
1050 return err
1051 }
1052 defer conn.Close()
1053
Scott Baker9173ed82020-05-19 08:30:12 -07001054 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -07001055
David Bainbridge7052fe82020-03-25 10:37:00 -07001056 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -07001057 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +00001058 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -07001059 defer cancel()
1060
Scott Baker9173ed82020-05-19 08:30:12 -07001061 id := voltha.ID{Id: string(i)}
1062
1063 _, err := client.EnableDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -07001064 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +00001065 Error.Printf("Error while enabling '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -07001066 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -07001067 continue
Zack Williamse940c7a2019-08-21 14:25:39 -07001068 }
1069 fmt.Printf("%s\n", i)
1070 }
1071
David Bainbridge7052fe82020-03-25 10:37:00 -07001072 if lastErr != nil {
1073 return NoReportErr
1074 }
Zack Williamse940c7a2019-08-21 14:25:39 -07001075 return nil
1076}
1077
1078func (options *DeviceDisable) Execute(args []string) error {
1079 conn, err := NewConnection()
1080 if err != nil {
1081 return err
1082 }
1083 defer conn.Close()
1084
Scott Baker9173ed82020-05-19 08:30:12 -07001085 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -07001086
David Bainbridge7052fe82020-03-25 10:37:00 -07001087 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -07001088 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +00001089 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -07001090 defer cancel()
1091
Scott Baker9173ed82020-05-19 08:30:12 -07001092 id := voltha.ID{Id: string(i)}
1093
1094 _, err := client.DisableDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -07001095 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +00001096 Error.Printf("Error while disabling '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -07001097 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -07001098 continue
Zack Williamse940c7a2019-08-21 14:25:39 -07001099 }
1100 fmt.Printf("%s\n", i)
1101 }
1102
David Bainbridge7052fe82020-03-25 10:37:00 -07001103 if lastErr != nil {
1104 return NoReportErr
1105 }
Zack Williamse940c7a2019-08-21 14:25:39 -07001106 return nil
1107}
1108
1109func (options *DeviceReboot) Execute(args []string) error {
1110 conn, err := NewConnection()
1111 if err != nil {
1112 return err
1113 }
1114 defer conn.Close()
1115
Scott Baker9173ed82020-05-19 08:30:12 -07001116 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -07001117
David Bainbridge7052fe82020-03-25 10:37:00 -07001118 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -07001119 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +00001120 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -07001121 defer cancel()
1122
Scott Baker9173ed82020-05-19 08:30:12 -07001123 id := voltha.ID{Id: string(i)}
1124
1125 _, err := client.RebootDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -07001126 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +00001127 Error.Printf("Error while rebooting '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -07001128 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -07001129 continue
Zack Williamse940c7a2019-08-21 14:25:39 -07001130 }
1131 fmt.Printf("%s\n", i)
1132 }
1133
David Bainbridge7052fe82020-03-25 10:37:00 -07001134 if lastErr != nil {
1135 return NoReportErr
1136 }
Zack Williamse940c7a2019-08-21 14:25:39 -07001137 return nil
1138}
1139
1140func (options *DevicePortList) Execute(args []string) error {
1141
1142 conn, err := NewConnection()
1143 if err != nil {
1144 return err
1145 }
1146 defer conn.Close()
1147
Scott Baker9173ed82020-05-19 08:30:12 -07001148 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -07001149
David K. Bainbridge9189c632021-03-26 21:52:21 +00001150 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -07001151 defer cancel()
1152
Scott Baker9173ed82020-05-19 08:30:12 -07001153 id := voltha.ID{Id: string(options.Args.Id)}
Zack Williamse940c7a2019-08-21 14:25:39 -07001154
Scott Baker9173ed82020-05-19 08:30:12 -07001155 ports, err := client.ListDevicePorts(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -07001156 if err != nil {
1157 return err
1158 }
1159
1160 outputFormat := CharReplacer.Replace(options.Format)
1161 if outputFormat == "" {
David Bainbridgea6722342019-10-24 23:55:53 +00001162 outputFormat = GetCommandOptionWithDefault("device-ports", "format", DEFAULT_DEVICE_PORTS_FORMAT)
Zack Williamse940c7a2019-08-21 14:25:39 -07001163 }
Zack Williamse940c7a2019-08-21 14:25:39 -07001164
David Bainbridgea6722342019-10-24 23:55:53 +00001165 orderBy := options.OrderBy
1166 if orderBy == "" {
1167 orderBy = GetCommandOptionWithDefault("device-ports", "order", "")
1168 }
1169
Zack Williamse940c7a2019-08-21 14:25:39 -07001170 result := CommandResult{
1171 Format: format.Format(outputFormat),
1172 Filter: options.Filter,
David Bainbridgea6722342019-10-24 23:55:53 +00001173 OrderBy: orderBy,
Zack Williamse940c7a2019-08-21 14:25:39 -07001174 OutputAs: toOutputType(options.OutputAs),
1175 NameLimit: options.NameLimit,
Scott Baker9173ed82020-05-19 08:30:12 -07001176 Data: ports.Items,
Zack Williamse940c7a2019-08-21 14:25:39 -07001177 }
1178
1179 GenerateOutput(&result)
1180 return nil
1181}
1182
1183func (options *DeviceFlowList) Execute(args []string) error {
1184 fl := &FlowList{}
1185 fl.ListOutputOptions = options.ListOutputOptions
Maninder045921e2020-09-29 16:46:02 +05301186 fl.FlowIdOptions = options.FlowIdOptions
Zack Williamse940c7a2019-08-21 14:25:39 -07001187 fl.Args.Id = string(options.Args.Id)
David Bainbridgea6722342019-10-24 23:55:53 +00001188 fl.Method = "device-flows"
Zack Williamse940c7a2019-08-21 14:25:39 -07001189 return fl.Execute(args)
1190}
1191
Himani Chawla3c161c62021-05-13 16:36:51 +05301192func (options *DeviceFlowGroupList) Execute(args []string) error {
1193 grp := &GroupList{}
1194 grp.ListOutputOptions = options.ListOutputOptions
1195 grp.GroupListOptions = options.GroupListOptions
1196 grp.Args.Id = string(options.Args.Id)
1197 grp.Method = "device-groups"
1198 return grp.Execute(args)
1199}
1200
Zack Williamse940c7a2019-08-21 14:25:39 -07001201func (options *DeviceInspect) Execute(args []string) error {
1202 if len(args) > 0 {
1203 return fmt.Errorf("only a single argument 'DEVICE_ID' can be provided")
1204 }
1205
1206 conn, err := NewConnection()
1207 if err != nil {
1208 return err
1209 }
1210 defer conn.Close()
1211
Scott Baker9173ed82020-05-19 08:30:12 -07001212 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -07001213
David K. Bainbridge9189c632021-03-26 21:52:21 +00001214 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -07001215 defer cancel()
1216
Scott Baker9173ed82020-05-19 08:30:12 -07001217 id := voltha.ID{Id: string(options.Args.Id)}
Zack Williamse940c7a2019-08-21 14:25:39 -07001218
Scott Baker9173ed82020-05-19 08:30:12 -07001219 device, err := client.GetDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -07001220 if err != nil {
1221 return err
1222 }
1223
Zack Williamse940c7a2019-08-21 14:25:39 -07001224 outputFormat := CharReplacer.Replace(options.Format)
1225 if outputFormat == "" {
David Bainbridgea6722342019-10-24 23:55:53 +00001226 outputFormat = GetCommandOptionWithDefault("device-inspect", "format", DEFAULT_DEVICE_INSPECT_FORMAT)
Zack Williamse940c7a2019-08-21 14:25:39 -07001227 }
1228 if options.Quiet {
1229 outputFormat = "{{.Id}}"
1230 }
1231
1232 result := CommandResult{
1233 Format: format.Format(outputFormat),
1234 OutputAs: toOutputType(options.OutputAs),
1235 NameLimit: options.NameLimit,
1236 Data: device,
1237 }
1238 GenerateOutput(&result)
1239 return nil
1240}
kesavand12cd8eb2020-01-20 22:25:22 -05001241
1242/*Device Port Enable */
1243func (options *DevicePortEnable) Execute(args []string) error {
1244 conn, err := NewConnection()
1245 if err != nil {
1246 return err
1247 }
1248 defer conn.Close()
1249
Scott Baker9173ed82020-05-19 08:30:12 -07001250 client := voltha.NewVolthaServiceClient(conn)
kesavand12cd8eb2020-01-20 22:25:22 -05001251
David K. Bainbridge9189c632021-03-26 21:52:21 +00001252 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand12cd8eb2020-01-20 22:25:22 -05001253 defer cancel()
1254
Scott Baker9173ed82020-05-19 08:30:12 -07001255 port := voltha.Port{DeviceId: string(options.Args.Id), PortNo: uint32(options.Args.PortId)}
1256
1257 _, err = client.EnablePort(ctx, &port)
kesavand12cd8eb2020-01-20 22:25:22 -05001258 if err != nil {
1259 Error.Printf("Error enabling port number %v on device Id %s,err=%s\n", options.Args.PortId, options.Args.Id, ErrorToString(err))
1260 return err
kesavand12cd8eb2020-01-20 22:25:22 -05001261 }
1262
1263 return nil
1264}
1265
Scott Baker9173ed82020-05-19 08:30:12 -07001266/*Device Port Disable */
kesavand12cd8eb2020-01-20 22:25:22 -05001267func (options *DevicePortDisable) Execute(args []string) error {
1268 conn, err := NewConnection()
1269 if err != nil {
1270 return err
1271 }
1272 defer conn.Close()
1273
Scott Baker9173ed82020-05-19 08:30:12 -07001274 client := voltha.NewVolthaServiceClient(conn)
1275
David K. Bainbridge9189c632021-03-26 21:52:21 +00001276 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand12cd8eb2020-01-20 22:25:22 -05001277 defer cancel()
1278
Scott Baker9173ed82020-05-19 08:30:12 -07001279 port := voltha.Port{DeviceId: string(options.Args.Id), PortNo: uint32(options.Args.PortId)}
1280
1281 _, err = client.DisablePort(ctx, &port)
kesavand12cd8eb2020-01-20 22:25:22 -05001282 if err != nil {
Scott Baker9173ed82020-05-19 08:30:12 -07001283 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 -05001284 return err
kesavand12cd8eb2020-01-20 22:25:22 -05001285 }
Scott Baker9173ed82020-05-19 08:30:12 -07001286
kesavand12cd8eb2020-01-20 22:25:22 -05001287 return nil
1288}
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08001289
Rohan Agrawald7df3772020-06-29 11:23:36 +00001290func (options *DevicePmConfigSetMaxSkew) Execute(args []string) error {
1291 conn, err := NewConnection()
1292 if err != nil {
1293 return err
1294 }
1295 defer conn.Close()
1296
1297 client := voltha.NewVolthaServiceClient(conn)
1298
David K. Bainbridge9189c632021-03-26 21:52:21 +00001299 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawald7df3772020-06-29 11:23:36 +00001300 defer cancel()
1301
1302 id := voltha.ID{Id: string(options.Args.Id)}
1303
1304 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1305 if err != nil {
1306 return err
1307 }
1308
1309 pmConfigs.MaxSkew = options.Args.MaxSkew
1310
1311 _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs)
1312 if err != nil {
1313 return err
1314 }
1315
1316 return nil
1317}
1318
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001319func (options *DevicePmConfigsGet) Execute(args []string) error {
1320
1321 conn, err := NewConnection()
1322 if err != nil {
1323 return err
1324 }
1325 defer conn.Close()
1326
1327 client := voltha.NewVolthaServiceClient(conn)
1328
David K. Bainbridge9189c632021-03-26 21:52:21 +00001329 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001330 defer cancel()
1331
1332 id := voltha.ID{Id: string(options.Args.Id)}
1333
1334 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1335 if err != nil {
1336 return err
1337 }
1338
1339 outputFormat := CharReplacer.Replace(options.Format)
1340 if outputFormat == "" {
1341 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GET_FORMAT)
1342 }
1343
1344 orderBy := options.OrderBy
1345 if orderBy == "" {
1346 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1347 }
1348
1349 result := CommandResult{
1350 Format: format.Format(outputFormat),
1351 Filter: options.Filter,
1352 OrderBy: orderBy,
1353 OutputAs: toOutputType(options.OutputAs),
1354 NameLimit: options.NameLimit,
1355 Data: pmConfigs,
1356 }
1357
1358 GenerateOutput(&result)
1359 return nil
1360
1361}
1362
1363func (options *DevicePmConfigMetricList) Execute(args []string) error {
1364
1365 conn, err := NewConnection()
1366 if err != nil {
1367 return err
1368 }
1369 defer conn.Close()
1370
1371 client := voltha.NewVolthaServiceClient(conn)
1372
David K. Bainbridge9189c632021-03-26 21:52:21 +00001373 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001374 defer cancel()
1375
1376 id := voltha.ID{Id: string(options.Args.Id)}
1377
1378 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1379 if err != nil {
1380 return err
1381 }
1382
1383 if !pmConfigs.Grouped {
1384 for _, metric := range pmConfigs.Metrics {
1385 if metric.SampleFreq == 0 {
1386 metric.SampleFreq = pmConfigs.DefaultFreq
1387 }
1388 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001389 outputFormat := CharReplacer.Replace(options.Format)
1390 if outputFormat == "" {
1391 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_METRIC_LIST_FORMAT)
1392 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001393
Rohan Agrawalbca69122020-06-17 14:59:03 +00001394 orderBy := options.OrderBy
1395 if orderBy == "" {
1396 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1397 }
1398
1399 result := CommandResult{
1400 Format: format.Format(outputFormat),
1401 Filter: options.Filter,
1402 OrderBy: orderBy,
1403 OutputAs: toOutputType(options.OutputAs),
1404 NameLimit: options.NameLimit,
1405 Data: pmConfigs.Metrics,
1406 }
1407
1408 GenerateOutput(&result)
1409 return nil
1410 } else {
1411 return fmt.Errorf("Device '%s' does not have Non Grouped Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001412 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001413}
1414
1415func (options *DevicePmConfigMetricEnable) Execute(args []string) error {
1416
1417 conn, err := NewConnection()
1418 if err != nil {
1419 return err
1420 }
1421 defer conn.Close()
1422
1423 client := voltha.NewVolthaServiceClient(conn)
1424
David K. Bainbridge9189c632021-03-26 21:52:21 +00001425 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001426 defer cancel()
1427
1428 id := voltha.ID{Id: string(options.Args.Id)}
1429
1430 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1431 if err != nil {
1432 return err
1433 }
1434
1435 if !pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001436 metrics := make(map[string]struct{})
1437 for _, metric := range pmConfigs.Metrics {
1438 metrics[metric.Name] = struct{}{}
1439 }
1440
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001441 for _, metric := range pmConfigs.Metrics {
1442 for _, mName := range options.Args.Metrics {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001443 if _, exist := metrics[string(mName)]; !exist {
1444 return fmt.Errorf("Metric Name '%s' does not exist", mName)
1445 }
1446
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001447 if string(mName) == metric.Name && !metric.Enabled {
1448 metric.Enabled = true
1449 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1450 if err != nil {
1451 return err
1452 }
1453 }
1454 }
1455 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001456 } else {
1457 return fmt.Errorf("Device '%s' does not have Non Grouped Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001458 }
1459 return nil
1460}
1461
1462func (options *DevicePmConfigMetricDisable) Execute(args []string) error {
1463
1464 conn, err := NewConnection()
1465 if err != nil {
1466 return err
1467 }
1468 defer conn.Close()
1469
1470 client := voltha.NewVolthaServiceClient(conn)
1471
David K. Bainbridge9189c632021-03-26 21:52:21 +00001472 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001473 defer cancel()
1474
1475 id := voltha.ID{Id: string(options.Args.Id)}
1476
1477 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1478 if err != nil {
1479 return err
1480 }
1481
1482 if !pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001483 metrics := make(map[string]struct{})
1484 for _, metric := range pmConfigs.Metrics {
1485 metrics[metric.Name] = struct{}{}
1486 }
1487
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001488 for _, metric := range pmConfigs.Metrics {
1489 for _, mName := range options.Args.Metrics {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001490 if _, have := metrics[string(mName)]; !have {
1491 return fmt.Errorf("Metric Name '%s' does not exist", mName)
1492 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001493 if string(mName) == metric.Name && metric.Enabled {
1494 metric.Enabled = false
1495 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1496 if err != nil {
1497 return err
1498 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001499 } else {
1500 return fmt.Errorf("Metric '%s' cannot be disabled", string(mName))
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001501 }
1502 }
1503 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001504 } else {
1505 return fmt.Errorf("Device '%s' does not have Non Grouped Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001506 }
1507 return nil
1508}
1509
1510func (options *DevicePmConfigGroupEnable) Execute(args []string) error {
1511
1512 conn, err := NewConnection()
1513 if err != nil {
1514 return err
1515 }
1516 defer conn.Close()
1517
1518 client := voltha.NewVolthaServiceClient(conn)
1519
David K. Bainbridge9189c632021-03-26 21:52:21 +00001520 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001521 defer cancel()
1522
1523 id := voltha.ID{Id: string(options.Args.Id)}
1524
1525 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1526 if err != nil {
1527 return err
1528 }
1529
1530 if pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001531 groups := make(map[string]struct{})
1532 for _, group := range pmConfigs.Groups {
1533 groups[group.GroupName] = struct{}{}
1534 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001535 for _, group := range pmConfigs.Groups {
Girish Gowdra610acb42021-01-27 13:33:57 -08001536 if _, have := groups[string(options.Args.Group)]; !have {
1537 return fmt.Errorf("Group Name '%s' does not exist", options.Args.Group)
1538 }
1539 if string(options.Args.Group) == group.GroupName && !group.Enabled {
1540 group.Enabled = true
1541 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1542 if err != nil {
1543 return err
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001544 }
1545 }
1546 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001547 } else {
1548 return fmt.Errorf("Device '%s' does not have Group Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001549 }
1550 return nil
1551}
1552
1553func (options *DevicePmConfigGroupDisable) Execute(args []string) error {
1554
1555 conn, err := NewConnection()
1556 if err != nil {
1557 return err
1558 }
1559 defer conn.Close()
1560
1561 client := voltha.NewVolthaServiceClient(conn)
1562
David K. Bainbridge9189c632021-03-26 21:52:21 +00001563 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001564 defer cancel()
1565
1566 id := voltha.ID{Id: string(options.Args.Id)}
1567
1568 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1569 if err != nil {
1570 return err
1571 }
1572
1573 if pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001574 groups := make(map[string]struct{})
1575 for _, group := range pmConfigs.Groups {
1576 groups[group.GroupName] = struct{}{}
1577 }
1578
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001579 for _, group := range pmConfigs.Groups {
Girish Gowdra610acb42021-01-27 13:33:57 -08001580 if _, have := groups[string(options.Args.Group)]; !have {
1581 return fmt.Errorf("Group Name '%s' does not exist", options.Args.Group)
1582 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001583
Girish Gowdra610acb42021-01-27 13:33:57 -08001584 if string(options.Args.Group) == group.GroupName && group.Enabled {
1585 group.Enabled = false
1586 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1587 if err != nil {
1588 return err
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001589 }
1590 }
1591 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001592 } else {
1593 return fmt.Errorf("Device '%s' does not have Group Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001594 }
1595 return nil
1596}
1597
Girish Gowdra610acb42021-01-27 13:33:57 -08001598func (options *DevicePmConfigGroupFrequencySet) Execute(args []string) error {
1599
1600 conn, err := NewConnection()
1601 if err != nil {
1602 return err
1603 }
1604 defer conn.Close()
1605
1606 client := voltha.NewVolthaServiceClient(conn)
1607
David K. Bainbridge9189c632021-03-26 21:52:21 +00001608 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Girish Gowdra610acb42021-01-27 13:33:57 -08001609 defer cancel()
1610
1611 id := voltha.ID{Id: string(options.Args.Id)}
1612
1613 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1614 if err != nil {
1615 return err
1616 }
1617
1618 if pmConfigs.Grouped {
1619 groups := make(map[string]struct{})
1620 for _, group := range pmConfigs.Groups {
1621 groups[group.GroupName] = struct{}{}
1622 }
1623
1624 for _, group := range pmConfigs.Groups {
1625 if _, have := groups[string(options.Args.Group)]; !have {
1626 return fmt.Errorf("group name '%s' does not exist", options.Args.Group)
1627 }
1628
1629 if string(options.Args.Group) == group.GroupName {
1630 if !group.Enabled {
1631 return fmt.Errorf("group '%s' is not enabled", options.Args.Group)
1632 }
1633 group.GroupFreq = uint32(options.Args.Interval.Seconds())
1634 _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs)
1635 if err != nil {
1636 return err
1637 }
1638 }
1639 }
1640 } else {
1641 return fmt.Errorf("device '%s' does not have group metrics", options.Args.Id)
1642 }
1643 return nil
1644}
1645
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001646func (options *DevicePmConfigGroupList) Execute(args []string) error {
1647
1648 conn, err := NewConnection()
1649 if err != nil {
1650 return err
1651 }
1652 defer conn.Close()
1653
1654 client := voltha.NewVolthaServiceClient(conn)
1655
David K. Bainbridge9189c632021-03-26 21:52:21 +00001656 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001657 defer cancel()
1658
1659 id := voltha.ID{Id: string(options.Args.Id)}
1660
1661 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1662 if err != nil {
1663 return err
1664 }
1665
1666 if pmConfigs.Grouped {
1667 for _, group := range pmConfigs.Groups {
1668 if group.GroupFreq == 0 {
1669 group.GroupFreq = pmConfigs.DefaultFreq
1670 }
1671 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001672 outputFormat := CharReplacer.Replace(options.Format)
1673 if outputFormat == "" {
1674 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GROUP_LIST_FORMAT)
1675 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001676
Rohan Agrawalbca69122020-06-17 14:59:03 +00001677 orderBy := options.OrderBy
1678 if orderBy == "" {
1679 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1680 }
1681
1682 result := CommandResult{
1683 Format: format.Format(outputFormat),
1684 Filter: options.Filter,
1685 OrderBy: orderBy,
1686 OutputAs: toOutputType(options.OutputAs),
1687 NameLimit: options.NameLimit,
1688 Data: pmConfigs.Groups,
1689 }
1690
1691 GenerateOutput(&result)
1692 } else {
1693 return fmt.Errorf("Device '%s' does not have Group Metrics", string(options.Args.Id))
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001694 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001695 return nil
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001696}
1697
1698func (options *DevicePmConfigGroupMetricList) Execute(args []string) error {
1699
1700 var metrics []*voltha.PmConfig
1701 conn, err := NewConnection()
1702 if err != nil {
1703 return err
1704 }
1705 defer conn.Close()
1706
1707 client := voltha.NewVolthaServiceClient(conn)
1708
David K. Bainbridge9189c632021-03-26 21:52:21 +00001709 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001710 defer cancel()
1711
1712 id := voltha.ID{Id: string(options.Args.Id)}
1713
1714 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1715 if err != nil {
1716 return err
1717 }
1718
1719 for _, groups := range pmConfigs.Groups {
1720
1721 if string(options.Args.Group) == groups.GroupName {
1722 for _, metric := range groups.Metrics {
1723 if metric.SampleFreq == 0 && groups.GroupFreq == 0 {
1724 metric.SampleFreq = pmConfigs.DefaultFreq
1725 } else {
1726 metric.SampleFreq = groups.GroupFreq
1727 }
1728 }
1729 metrics = groups.Metrics
1730 }
1731 }
1732
1733 outputFormat := CharReplacer.Replace(options.Format)
1734 if outputFormat == "" {
1735 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_METRIC_LIST_FORMAT)
1736 }
1737
1738 orderBy := options.OrderBy
1739 if orderBy == "" {
1740 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1741 }
1742
1743 result := CommandResult{
1744 Format: format.Format(outputFormat),
1745 Filter: options.Filter,
1746 OrderBy: orderBy,
1747 OutputAs: toOutputType(options.OutputAs),
1748 NameLimit: options.NameLimit,
1749 Data: metrics,
1750 }
1751
1752 GenerateOutput(&result)
1753 return nil
1754
1755}
1756
1757func (options *DevicePmConfigFrequencySet) Execute(args []string) error {
1758
1759 conn, err := NewConnection()
1760 if err != nil {
1761 return err
1762 }
1763 defer conn.Close()
1764
1765 client := voltha.NewVolthaServiceClient(conn)
1766
David K. Bainbridge9189c632021-03-26 21:52:21 +00001767 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001768 defer cancel()
1769
1770 id := voltha.ID{Id: string(options.Args.Id)}
1771
1772 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1773 if err != nil {
1774 return err
1775 }
1776
Girish Gowdra610acb42021-01-27 13:33:57 -08001777 pmConfigs.DefaultFreq = uint32(options.Args.Interval.Seconds())
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001778
1779 _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs)
1780 if err != nil {
1781 return err
1782 }
1783
1784 outputFormat := CharReplacer.Replace(options.Format)
1785 if outputFormat == "" {
1786 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GET_FORMAT)
1787 }
1788 if options.Quiet {
1789 outputFormat = "{{.Id}}"
1790 }
1791
1792 result := CommandResult{
1793 Format: format.Format(outputFormat),
1794 OutputAs: toOutputType(options.OutputAs),
1795 NameLimit: options.NameLimit,
1796 Data: pmConfigs,
1797 }
1798
1799 GenerateOutput(&result)
1800 return nil
1801
1802}
1803
kesavand3e2f9f62021-04-22 11:06:38 +05301804func (options *OnuDownloadImage) Execute(args []string) error {
1805
1806 conn, err := NewConnection()
1807 if err != nil {
1808 return err
1809 }
1810 defer conn.Close()
1811
1812 client := voltha.NewVolthaServiceClient(conn)
1813
1814 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1815 defer cancel()
1816
1817 var devIDList []*common.ID
1818 for _, i := range options.Args.IDs {
1819
1820 devIDList = append(devIDList, &common.ID{Id: string(i)})
1821 }
1822
1823 downloadImage := voltha.DeviceImageDownloadRequest{
1824 DeviceId: devIDList,
1825 Image: &voltha.Image{
1826 Url: options.Args.Url,
1827 Crc32: options.Args.Crc,
ssiddiqui7bc89e92021-05-20 20:58:02 +05301828 Vendor: options.Args.Vendor,
kesavand3e2f9f62021-04-22 11:06:38 +05301829 Version: options.Args.ImageVersion,
1830 },
1831 ActivateOnSuccess: options.Args.ActivateOnSuccess,
1832 CommitOnSuccess: options.Args.CommitOnSuccess,
1833 }
1834
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001835 deviceImageResp, err := client.DownloadImageToDevice(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301836 if err != nil {
1837 return err
1838 }
1839
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001840 outputFormat := GetCommandOptionWithDefault("onu-image-download", "format", ONU_IMAGE_STATUS_FORMAT)
1841 // Make sure json output prints an empty list, not "null"
1842 if deviceImageResp.DeviceImageStates == nil {
1843 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1844 }
1845 result := CommandResult{
1846 Format: format.Format(outputFormat),
1847 OutputAs: toOutputType(options.OutputAs),
1848 NameLimit: options.NameLimit,
1849 Data: deviceImageResp.DeviceImageStates,
1850 }
1851 GenerateOutput(&result)
kesavand3e2f9f62021-04-22 11:06:38 +05301852 return nil
1853
1854}
1855
1856func (options *OnuActivateImage) Execute(args []string) error {
1857
1858 conn, err := NewConnection()
1859 if err != nil {
1860 return err
1861 }
1862 defer conn.Close()
1863
1864 client := voltha.NewVolthaServiceClient(conn)
1865
1866 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1867 defer cancel()
1868
1869 var devIDList []*common.ID
1870 for _, i := range options.Args.IDs {
1871
1872 devIDList = append(devIDList, &common.ID{Id: string(i)})
1873 }
1874
1875 downloadImage := voltha.DeviceImageRequest{
1876 DeviceId: devIDList,
1877 Version: options.Args.ImageVersion,
1878 CommitOnSuccess: options.Args.CommitOnSuccess,
1879 }
1880
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001881 deviceImageResp, err := client.ActivateImage(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301882 if err != nil {
1883 return err
1884 }
1885
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001886 outputFormat := GetCommandOptionWithDefault("onu-image-activate", "format", ONU_IMAGE_STATUS_FORMAT)
1887 // Make sure json output prints an empty list, not "null"
1888 if deviceImageResp.DeviceImageStates == nil {
1889 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1890 }
1891 result := CommandResult{
1892 Format: format.Format(outputFormat),
1893 OutputAs: toOutputType(options.OutputAs),
1894 NameLimit: options.NameLimit,
1895 Data: deviceImageResp.DeviceImageStates,
1896 }
1897 GenerateOutput(&result)
1898
kesavand3e2f9f62021-04-22 11:06:38 +05301899 return nil
1900
1901}
1902
1903func (options *OnuAbortUpgradeImage) Execute(args []string) error {
1904
1905 conn, err := NewConnection()
1906 if err != nil {
1907 return err
1908 }
1909 defer conn.Close()
1910
1911 client := voltha.NewVolthaServiceClient(conn)
1912
1913 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1914 defer cancel()
1915
1916 var devIDList []*common.ID
1917 for _, i := range options.Args.IDs {
1918
1919 devIDList = append(devIDList, &common.ID{Id: string(i)})
1920 }
1921
1922 downloadImage := voltha.DeviceImageRequest{
1923 DeviceId: devIDList,
1924 Version: options.Args.ImageVersion,
1925 }
1926
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001927 deviceImageResp, err := client.AbortImageUpgradeToDevice(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301928 if err != nil {
1929 return err
1930 }
1931
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001932 outputFormat := GetCommandOptionWithDefault("onu-image-abort", "format", ONU_IMAGE_STATUS_FORMAT)
1933 // Make sure json output prints an empty list, not "null"
1934 if deviceImageResp.DeviceImageStates == nil {
1935 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1936 }
1937 result := CommandResult{
1938 Format: format.Format(outputFormat),
1939 OutputAs: toOutputType(options.OutputAs),
1940 NameLimit: options.NameLimit,
1941 Data: deviceImageResp.DeviceImageStates,
1942 }
1943 GenerateOutput(&result)
1944
kesavand3e2f9f62021-04-22 11:06:38 +05301945 return nil
1946
1947}
1948
1949func (options *OnuCommitImage) Execute(args []string) error {
1950
1951 conn, err := NewConnection()
1952 if err != nil {
1953 return err
1954 }
1955 defer conn.Close()
1956
1957 client := voltha.NewVolthaServiceClient(conn)
1958
1959 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1960 defer cancel()
1961
1962 var devIDList []*common.ID
1963 for _, i := range options.Args.IDs {
1964
1965 devIDList = append(devIDList, &common.ID{Id: string(i)})
1966 }
1967 downloadImage := voltha.DeviceImageRequest{
1968 DeviceId: devIDList,
1969 Version: options.Args.ImageVersion,
1970 }
1971
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001972 deviceImageResp, err := client.CommitImage(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301973 if err != nil {
1974 return err
1975 }
1976
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001977 outputFormat := GetCommandOptionWithDefault("onu-image-commit", "format", ONU_IMAGE_STATUS_FORMAT)
1978 // Make sure json output prints an empty list, not "null"
1979 if deviceImageResp.DeviceImageStates == nil {
1980 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1981 }
1982 result := CommandResult{
1983 Format: format.Format(outputFormat),
1984 OutputAs: toOutputType(options.OutputAs),
1985 NameLimit: options.NameLimit,
1986 Data: deviceImageResp.DeviceImageStates,
1987 }
1988 GenerateOutput(&result)
1989
kesavand3e2f9f62021-04-22 11:06:38 +05301990 return nil
1991
1992}
1993
1994func (options *OnuListImages) Execute(args []string) error {
1995
1996 conn, err := NewConnection()
1997 if err != nil {
1998 return err
1999 }
2000 defer conn.Close()
2001
2002 client := voltha.NewVolthaServiceClient(conn)
2003
2004 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2005 defer cancel()
2006
2007 id := common.ID{Id: string(options.Args.Id)}
2008
2009 onuImages, err := client.GetOnuImages(ctx, &id)
2010 if err != nil {
2011 return err
2012 }
2013
2014 outputFormat := CharReplacer.Replace(options.Format)
2015 if outputFormat == "" {
2016 outputFormat = GetCommandOptionWithDefault("onu-image-list", "format", ONU_IMAGE_LIST_FORMAT)
2017 }
2018
2019 if options.Quiet {
2020 outputFormat = "{{.Id}}"
2021 }
2022
2023 //TODO orderby
2024
2025 // Make sure json output prints an empty list, not "null"
2026 if onuImages.Items == nil {
2027 onuImages.Items = make([]*voltha.OnuImage, 0)
2028 }
2029
2030 result := CommandResult{
2031 Format: format.Format(outputFormat),
2032 OutputAs: toOutputType(options.OutputAs),
2033 NameLimit: options.NameLimit,
2034 Data: onuImages.Items,
2035 }
2036
2037 GenerateOutput(&result)
2038 return nil
2039
2040}
2041
2042func (options *OnuImageStatus) Execute(args []string) error {
2043
2044 conn, err := NewConnection()
2045 if err != nil {
2046 return err
2047 }
2048 defer conn.Close()
2049
2050 client := voltha.NewVolthaServiceClient(conn)
2051
2052 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2053 defer cancel()
2054
2055 var devIDList []*common.ID
kesavand3e2f9f62021-04-22 11:06:38 +05302056
Elia Battiston859f3e62022-02-08 15:57:52 +01002057 if options.Args.IDs == nil {
2058 //Use an empty IDs list to retrieve the status of all devices
2059 //with the requested image version
2060 devIDList = []*common.ID{}
2061 } else {
2062 for _, i := range options.Args.IDs {
2063 devIDList = append(devIDList, &common.ID{Id: string(i)})
2064 }
kesavand3e2f9f62021-04-22 11:06:38 +05302065 }
2066
2067 imageStatusReq := voltha.DeviceImageRequest{
2068 DeviceId: devIDList,
2069 Version: options.Args.ImageVersion,
2070 }
2071 imageStatus, err := client.GetImageStatus(ctx, &imageStatusReq)
2072 if err != nil {
2073 return err
2074 }
2075
2076 outputFormat := CharReplacer.Replace(options.Format)
2077 if outputFormat == "" {
2078 outputFormat = GetCommandOptionWithDefault("device-image-list", "format", ONU_IMAGE_STATUS_FORMAT)
2079 }
2080
2081 if options.Quiet {
2082 outputFormat = "{{.Id}}"
2083 }
2084
2085 //TODO orderby
2086
2087 // Make sure json output prints an empty list, not "null"
2088 if imageStatus.DeviceImageStates == nil {
2089 imageStatus.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
2090 }
2091
2092 result := CommandResult{
2093 Format: format.Format(outputFormat),
2094 OutputAs: toOutputType(options.OutputAs),
2095 NameLimit: options.NameLimit,
2096 Data: imageStatus.DeviceImageStates,
2097 }
2098
2099 GenerateOutput(&result)
2100 return nil
2101
2102}
2103
Andrea Campanella791d88b2021-01-08 13:29:00 +01002104func (options *DeviceOnuListImages) Execute(args []string) error {
2105
2106 conn, err := NewConnection()
2107 if err != nil {
2108 return err
2109 }
2110 defer conn.Close()
2111
2112 client := voltha.NewVolthaServiceClient(conn)
2113
David K. Bainbridge9189c632021-03-26 21:52:21 +00002114 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Andrea Campanella791d88b2021-01-08 13:29:00 +01002115 defer cancel()
2116
2117 id := common.ID{Id: string(options.Args.Id)}
2118
2119 imageDownloads, err := client.ListImageDownloads(ctx, &id)
2120 if err != nil {
2121 return err
2122 }
2123
2124 outputFormat := CharReplacer.Replace(options.Format)
2125 if outputFormat == "" {
2126 outputFormat = GetCommandOptionWithDefault("device-image-list", "format", DEFAULT_DEVICE_IMAGE_LIST_GET_FORMAT)
2127 }
2128
2129 if options.Quiet {
2130 outputFormat = "{{.Id}}"
2131 }
2132
2133 //TODO orderby
2134
2135 // Make sure json output prints an empty list, not "null"
2136 if imageDownloads.Items == nil {
2137 imageDownloads.Items = make([]*voltha.ImageDownload, 0)
2138 }
2139
2140 result := CommandResult{
2141 Format: format.Format(outputFormat),
2142 OutputAs: toOutputType(options.OutputAs),
2143 NameLimit: options.NameLimit,
2144 Data: imageDownloads.Items,
2145 }
2146
2147 GenerateOutput(&result)
2148 return nil
2149
2150}
2151
2152func (options *DeviceOnuDownloadImage) Execute(args []string) error {
2153
2154 conn, err := NewConnection()
2155 if err != nil {
2156 return err
2157 }
2158 defer conn.Close()
2159
2160 client := voltha.NewVolthaServiceClient(conn)
2161
David K. Bainbridge9189c632021-03-26 21:52:21 +00002162 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Andrea Campanella791d88b2021-01-08 13:29:00 +01002163 defer cancel()
2164
2165 downloadImage := voltha.ImageDownload{
2166 Id: string(options.Args.Id),
2167 Name: options.Args.Name,
2168 Url: options.Args.Url,
2169 Crc: options.Args.Crc,
2170 LocalDir: options.Args.LocalDir,
2171 }
2172
2173 _, err = client.DownloadImage(ctx, &downloadImage)
2174 if err != nil {
2175 return err
2176 }
2177
2178 return nil
2179
2180}
2181
2182func (options *DeviceOnuActivateImageUpdate) Execute(args []string) error {
2183
2184 conn, err := NewConnection()
2185 if err != nil {
2186 return err
2187 }
2188 defer conn.Close()
2189
2190 client := voltha.NewVolthaServiceClient(conn)
2191
David K. Bainbridge9189c632021-03-26 21:52:21 +00002192 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Andrea Campanella791d88b2021-01-08 13:29:00 +01002193 defer cancel()
2194
2195 downloadImage := voltha.ImageDownload{
2196 Id: string(options.Args.Id),
2197 Name: options.Args.Name,
2198 ImageVersion: options.Args.ImageVersion,
2199 SaveConfig: options.Args.SaveConfig,
2200 LocalDir: options.Args.LocalDir,
2201 }
2202
2203 _, err = client.ActivateImageUpdate(ctx, &downloadImage)
2204 if err != nil {
2205 return err
2206 }
2207
2208 return nil
2209
2210}
2211
Scott Baker9173ed82020-05-19 08:30:12 -07002212type ReturnValueRow struct {
2213 Name string `json:"name"`
2214 Result interface{} `json:"result"`
2215}
2216
kesavand8ec4fc02021-01-27 09:10:22 -05002217func (options *DeviceGetPortStats) Execute(args []string) error {
2218 conn, err := NewConnection()
2219 if err != nil {
2220 return err
2221 }
2222 defer conn.Close()
2223 client := extension.NewExtensionClient(conn)
2224 var portType extension.GetOltPortCounters_PortType
2225
2226 if options.Args.PortType == "pon" {
2227 portType = extension.GetOltPortCounters_Port_PON_OLT
2228 } else if options.Args.PortType == "nni" {
2229
2230 portType = extension.GetOltPortCounters_Port_ETHERNET_NNI
2231 } else {
2232 return fmt.Errorf("expected interface type pon/nni, provided %s", options.Args.PortType)
2233 }
2234
2235 singleGetValReq := extension.SingleGetValueRequest{
2236 TargetId: string(options.Args.Id),
2237 Request: &extension.GetValueRequest{
2238 Request: &extension.GetValueRequest_OltPortInfo{
2239 OltPortInfo: &extension.GetOltPortCounters{
2240 PortNo: options.Args.PortNo,
2241 PortType: portType,
2242 },
2243 },
2244 },
2245 }
2246
David K. Bainbridge9189c632021-03-26 21:52:21 +00002247 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand8ec4fc02021-01-27 09:10:22 -05002248 defer cancel()
2249 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2250 if err != nil {
2251 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2252 return err
2253 }
2254
2255 if rv.Response.Status != extension.GetValueResponse_OK {
2256 return fmt.Errorf("failed to get port stats %v", rv.Response.ErrReason.String())
2257 }
2258
2259 outputFormat := CharReplacer.Replace(options.Format)
2260 if outputFormat == "" {
2261 outputFormat = GetCommandOptionWithDefault("device-get-port-status", "format", DEFAULT_DEVICE_GET_PORT_STATUS_FORMAT)
2262 }
2263
2264 result := CommandResult{
2265 Format: format.Format(outputFormat),
2266 OutputAs: toOutputType(options.OutputAs),
2267 NameLimit: options.NameLimit,
2268 Data: rv.GetResponse().GetPortCoutners(),
2269 }
2270 GenerateOutput(&result)
2271 return nil
2272}
2273
Himani Chawla40acc122021-05-26 18:52:29 +05302274func (options *GetOnuStats) Execute(args []string) error {
2275 conn, err := NewConnection()
2276 if err != nil {
2277 return err
2278 }
2279 defer conn.Close()
2280 client := extension.NewExtensionClient(conn)
2281
2282 singleGetValReq := extension.SingleGetValueRequest{
2283 TargetId: string(options.Args.OltId),
2284 Request: &extension.GetValueRequest{
2285 Request: &extension.GetValueRequest_OnuPonInfo{
2286 OnuPonInfo: &extension.GetOnuCountersRequest{
2287 IntfId: options.Args.IntfId,
2288 OnuId: options.Args.OnuId,
2289 },
2290 },
2291 },
2292 }
2293 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2294 defer cancel()
2295 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2296 if err != nil {
2297 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.OltId, ErrorToString(err))
2298 return err
2299 }
2300
2301 if rv.Response.Status != extension.GetValueResponse_OK {
2302 return fmt.Errorf("failed to get onu stats %v", rv.Response.ErrReason.String())
2303 }
2304 outputFormat := CharReplacer.Replace(options.Format)
2305 data, formatStr := buildOnuStatsOutputFormat(rv.GetResponse().GetOnuPonCounters())
2306 if outputFormat == "" {
2307 outputFormat = GetCommandOptionWithDefault("device-get-onu-status", "format", formatStr)
2308 }
Himani Chawla553a1392021-06-10 23:39:17 +05302309 result := CommandResult{
2310 Format: format.Format(outputFormat),
2311 OutputAs: toOutputType(options.OutputAs),
2312 NameLimit: options.NameLimit,
2313 Data: data,
2314 }
2315 GenerateOutput(&result)
2316 return nil
2317}
Himani Chawla40acc122021-05-26 18:52:29 +05302318
Akash Soni6e879c22024-12-20 17:01:34 +05302319func (options *GetOffloadApp) Execute(args []string) error {
Akash Soni51b6b7a2024-11-20 11:39:38 +05302320 // Establish a connection to the gRPC server
2321 conn, err := NewConnection()
2322 if err != nil {
2323 return err
2324 }
2325 defer conn.Close()
2326
2327 client := extension.NewExtensionClient(conn)
2328
2329 // Build the request
2330 singleGetValReq := &extension.SingleGetValueRequest{
2331 TargetId: string(options.Args.OltId),
2332 Request: &extension.GetValueRequest{
2333 Request: &extension.GetValueRequest_OffloadedAppsStats{
2334 OffloadedAppsStats: &extension.GetOffloadedAppsStatisticsRequest{
2335 StatsFor: options.Args.StatsFor,
2336 },
2337 },
2338 },
2339 }
2340
2341 // Set a context with timeout
2342 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2343 defer cancel()
2344
2345 // Perform the gRPC call
2346 rv, err := client.GetExtValue(ctx, singleGetValReq)
2347 if err != nil {
2348 Error.Printf("Error getting value for device ID %s, err=%s\n", options.Args.OltId, ErrorToString(err))
2349 return err
2350 }
2351
2352 // Check response status
2353 if rv.GetResponse().GetStatus() != extension.GetValueResponse_OK {
2354 return fmt.Errorf("failed to get offloaded app stats: %v", rv.GetResponse().GetErrReason().String())
2355 }
2356
2357 // Process the response data
2358 stats, formatStr := buildOffloadAppStatsOutputFormat(rv.GetResponse().GetOffloadedAppsStats())
2359 outputFormat := CharReplacer.Replace(options.Format)
2360 if outputFormat == "" {
2361 outputFormat = GetCommandOptionWithDefault("device-get-offload-app-stats", "format", formatStr)
2362 }
2363
2364 // Generate and display the output
2365 result := CommandResult{
2366 Format: format.Format(outputFormat),
2367 OutputAs: toOutputType(options.OutputAs),
2368 NameLimit: options.NameLimit,
2369 Data: stats,
2370 }
2371 GenerateOutput(&result)
2372
2373 return nil
2374}
2375
Akash Soni6e879c22024-12-20 17:01:34 +05302376func (options *SetOffloadApp) Execute(args []string) error {
Akash Soni51b6b7a2024-11-20 11:39:38 +05302377 conn, err := NewConnection()
2378 if err != nil {
Akash Soni6e879c22024-12-20 17:01:34 +05302379 return fmt.Errorf("failed to establish gRPC connection: %w", err)
Akash Soni51b6b7a2024-11-20 11:39:38 +05302380 }
2381 defer conn.Close()
2382
2383 client := extension.NewExtensionClient(conn)
2384
Akash Soni6e879c22024-12-20 17:01:34 +05302385 // Parse JSON input
2386 var config extension.AppOffloadConfig
2387 if err := json.Unmarshal([]byte(options.Args.Config), &config); err != nil {
2388 return fmt.Errorf("failed to parse CONFIG as JSON: %w", err)
2389 }
2390
Akash Soni51b6b7a2024-11-20 11:39:38 +05302391 setValueRequest := &extension.SetValueRequest{
2392 Request: &extension.SetValueRequest_AppOffloadConfig{
Akash Soni6e879c22024-12-20 17:01:34 +05302393 AppOffloadConfig: &config,
Akash Soni51b6b7a2024-11-20 11:39:38 +05302394 },
2395 }
2396
2397 singleSetValReq := &extension.SingleSetValueRequest{
2398 TargetId: string(options.Args.OltId),
2399 Request: setValueRequest,
2400 }
2401
Akash Soni6e879c22024-12-20 17:01:34 +05302402 // Log the request object
2403 logRequestAppOffloadConfig(singleSetValReq)
2404
Akash Soni51b6b7a2024-11-20 11:39:38 +05302405 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2406 defer cancel()
2407
2408 resp, err := client.SetExtValue(ctx, singleSetValReq)
2409 if err != nil {
Akash Soni6e879c22024-12-20 17:01:34 +05302410 return fmt.Errorf("failed to set AppOffloadConfig: %w", err)
Akash Soni51b6b7a2024-11-20 11:39:38 +05302411 }
2412
2413 if resp.Response.Status != extension.SetValueResponse_OK {
Akash Soni6e879c22024-12-20 17:01:34 +05302414 return fmt.Errorf("operation failed with status %v: %s", resp.Response.Status, resp.Response.ErrReason)
Akash Soni51b6b7a2024-11-20 11:39:38 +05302415 }
2416
2417 fmt.Printf("AppOffloadConfig successfully set for OLT ID: %s\n", options.Args.OltId)
2418 return nil
2419}
2420
Akash Soni6e879c22024-12-20 17:01:34 +05302421func logRequestAppOffloadConfig(req *extension.SingleSetValueRequest) {
2422 fmt.Printf("Request details:\n")
2423 fmt.Printf("TargetId: %s\n", req.TargetId)
2424 if config, ok := req.Request.Request.(*extension.SetValueRequest_AppOffloadConfig); ok {
2425 fmt.Printf("AppOffloadConfig:\n")
2426 fmt.Printf(" EnableDHCPv4RA: %t\n", config.AppOffloadConfig.EnableDHCPv4RA)
2427 fmt.Printf(" EnableDHCPv6RA: %t\n", config.AppOffloadConfig.EnableDHCPv6RA)
2428 fmt.Printf(" EnablePPPoEIA: %t\n", config.AppOffloadConfig.EnablePPPoEIA)
2429 fmt.Printf(" AccessNodeID: %s\n", config.AppOffloadConfig.AccessNodeID)
2430 }
2431}
2432
2433func (options *SetOnuOffload) Execute(args []string) error {
2434 // Create the gRPC client connection
Akash Soni51b6b7a2024-11-20 11:39:38 +05302435 conn, err := NewConnection()
2436 if err != nil {
2437 return fmt.Errorf("failed to establish gRPC connection: %v", err)
2438 }
2439 defer conn.Close()
2440
2441 client := extension.NewExtensionClient(conn)
2442
Akash Soni6e879c22024-12-20 17:01:34 +05302443 // Parse PerUniInfo into a slice of PerUniConfig
2444 var perUniConfigs []AppOffloadOnuConfig
2445 if err := json.Unmarshal([]byte(options.Args.PerUniInfo), &perUniConfigs); err != nil {
2446 return fmt.Errorf("failed to parse PerUniInfo as JSON: %v", err)
Akash Soni51b6b7a2024-11-20 11:39:38 +05302447 }
Akash Soni6e879c22024-12-20 17:01:34 +05302448
2449 // Convert to []*AppOffloadOnuConfig_PerUniConfig for gRPC
2450 var grpcPerUniInfo []*extension.AppOffloadOnuConfig_PerUniConfig
2451 for _, config := range perUniConfigs {
2452 grpcPerUniInfo = append(grpcPerUniInfo, &extension.AppOffloadOnuConfig_PerUniConfig{
2453 AgentRemoteID: config.AgentRemoteID,
2454 AgentCircuitID: config.AgentCircuitID,
2455 OnuUniId: config.OnuUniId,
2456 })
2457 }
2458
Akash Soni51b6b7a2024-11-20 11:39:38 +05302459 // Build the AppOffloadOnuConfig request
2460 onuConfig := &extension.AppOffloadOnuConfig{
2461 OnuDeviceId: options.Args.OnuDeviceId,
Akash Soni6e879c22024-12-20 17:01:34 +05302462 PerUniInfo: grpcPerUniInfo,
Akash Soni51b6b7a2024-11-20 11:39:38 +05302463 }
2464
2465 setValueRequest := &extension.SetValueRequest{
2466 Request: &extension.SetValueRequest_AppOffloadOnuConfig{
2467 AppOffloadOnuConfig: onuConfig,
2468 },
2469 }
2470
2471 singleSetValReq := &extension.SingleSetValueRequest{
Akash Soni6e879c22024-12-20 17:01:34 +05302472 TargetId: string(options.Args.OltId),
Akash Soni51b6b7a2024-11-20 11:39:38 +05302473 Request: setValueRequest,
2474 }
2475
Akash Soni6e879c22024-12-20 17:01:34 +05302476 // Log the request object
2477 logRequestAppOffloadOnuConfig(singleSetValReq)
2478
2479 // Make the gRPC call
Akash Soni51b6b7a2024-11-20 11:39:38 +05302480 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2481 defer cancel()
2482
2483 resp, err := client.SetExtValue(ctx, singleSetValReq)
2484 if err != nil {
2485 return fmt.Errorf("failed to set AppOffloadOnuConfig: %v", err)
2486 }
2487
2488 if resp.Response.Status != extension.SetValueResponse_OK {
Akash Soni6e879c22024-12-20 17:01:34 +05302489 return fmt.Errorf("operation failed with status %v: %s", resp.Response.Status, resp.Response.ErrReason)
Akash Soni51b6b7a2024-11-20 11:39:38 +05302490 }
2491
2492 fmt.Printf("AppOffloadOnuConfig successfully set for ONU ID: %s\n", options.Args.OnuDeviceId)
2493 return nil
2494}
2495
Akash Soni6e879c22024-12-20 17:01:34 +05302496// Debugging helper to log the gRPC request details
2497func logRequestAppOffloadOnuConfig(req *extension.SingleSetValueRequest) {
2498 fmt.Printf("Request details:\n")
2499 fmt.Printf("TargetId: %s\n", req.TargetId)
2500 fmt.Printf("OnuDeviceId: %s\n", req.Request.GetAppOffloadOnuConfig().OnuDeviceId)
2501 if config, ok := req.Request.Request.(*extension.SetValueRequest_AppOffloadOnuConfig); ok {
2502 fmt.Printf("AppOffloadOnuConfig:\n")
2503 for i, uniInfo := range config.AppOffloadOnuConfig.PerUniInfo {
2504 fmt.Printf(" UniInfo %d:\n", i+1)
2505 fmt.Printf(" AgentRemoteID: %s\n", uniInfo.AgentRemoteID)
2506 fmt.Printf(" AgentCircuitID: %s\n", uniInfo.AgentCircuitID)
2507 fmt.Printf(" OnuUniId: %d\n", uniInfo.OnuUniId)
2508 }
2509 }
2510}
2511
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +05302512func (options *GetPonPortStats) Execute(args []string) error {
2513 conn, err := NewConnection()
2514 if err != nil {
2515 return err
2516 }
2517 defer conn.Close()
2518 client := extension.NewExtensionClient(conn)
2519
2520 singleGetValReq := extension.SingleGetValueRequest{
2521 TargetId: string(options.Args.Id),
2522 Request: &extension.GetValueRequest{
2523 Request: &extension.GetValueRequest_OltPonStats{
2524 OltPonStats: &extension.GetPonStatsRequest{
2525 PortInfo: &extension.GetPonStatsRequest_PortLabel{
2526 PortLabel: options.Args.PortLabel,
2527 },
2528 },
2529 },
2530 },
2531 }
2532 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2533 defer cancel()
2534 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2535 if err != nil {
2536 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2537 return err
2538 }
2539
2540 if rv.Response.Status != extension.GetValueResponse_OK {
2541 return fmt.Errorf("failed to get pon port stats %v", rv.Response.ErrReason.String())
2542 }
2543 outputFormat := CharReplacer.Replace(options.Format)
2544 if outputFormat == "" {
2545 outputFormat = GetCommandOptionWithDefault("device-get-pon-stats", "format", DEFAULT_PON_PORT_STATS_FORMAT)
2546 }
2547 data := PortStats{
2548 PonPort: rv.GetResponse().GetOltPonStatsResponse().GetPonPort(),
2549 PortStatistics: rv.GetResponse().GetOltPonStatsResponse().GetPortStatistics(),
2550 }
2551 result := CommandResult{
2552 Format: format.Format(outputFormat),
2553 OutputAs: toOutputType(options.OutputAs),
2554 NameLimit: options.NameLimit,
2555 Data: data,
2556 }
2557 GenerateOutput(&result)
2558 return nil
2559}
2560
2561func (options *GetNniPortStats) Execute(args []string) error {
2562 conn, err := NewConnection()
2563 if err != nil {
2564 return err
2565 }
2566 defer conn.Close()
2567 client := extension.NewExtensionClient(conn)
2568
2569 singleGetValReq := extension.SingleGetValueRequest{
2570 TargetId: string(options.Args.Id),
2571 Request: &extension.GetValueRequest{
2572 Request: &extension.GetValueRequest_OltNniStats{
2573 OltNniStats: &extension.GetNNIStatsRequest{
2574 PortInfo: &extension.GetNNIStatsRequest_PortLabel{
2575 PortLabel: options.Args.PortLabel,
2576 },
2577 },
2578 },
2579 },
2580 }
2581 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2582 defer cancel()
2583 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2584 if err != nil {
2585 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2586 return err
2587 }
2588
2589 if rv.Response.Status != extension.GetValueResponse_OK {
2590 return fmt.Errorf("failed to get nni port stats %v", rv.Response.ErrReason.String())
2591 }
2592 outputFormat := CharReplacer.Replace(options.Format)
2593 if outputFormat == "" {
2594 outputFormat = GetCommandOptionWithDefault("device-get-nni-stats", "format", DEFAULT_NNI_PORT_STATS_FORMAT)
2595 }
2596 data := PortStats{
2597 NniPort: rv.GetResponse().GetOltNniStatsResponse().GetNniPort(),
2598 PortStatistics: rv.GetResponse().GetOltNniStatsResponse().GetPortStatistics(),
2599 }
2600 result := CommandResult{
2601 Format: format.Format(outputFormat),
2602 OutputAs: toOutputType(options.OutputAs),
2603 NameLimit: options.NameLimit,
2604 Data: data,
2605 }
2606 GenerateOutput(&result)
2607 return nil
2608}
2609
Himani Chawla553a1392021-06-10 23:39:17 +05302610func (options *GetOnuEthernetFrameExtendedPmCounters) Execute(args []string) error {
2611 conn, err := NewConnection()
2612 if err != nil {
2613 return err
2614 }
2615 defer conn.Close()
2616 client := extension.NewExtensionClient(conn)
Himani Chawla806aa892021-08-30 15:51:46 +05302617 var singleGetValReq extension.SingleGetValueRequest
Himani Chawla553a1392021-06-10 23:39:17 +05302618
Himani Chawla806aa892021-08-30 15:51:46 +05302619 if options.Args.UniIndex != nil {
2620 singleGetValReq = extension.SingleGetValueRequest{
2621 TargetId: string(options.Args.Id),
2622 Request: &extension.GetValueRequest{
2623 Request: &extension.GetValueRequest_OnuInfo{
2624 OnuInfo: &extension.GetOmciEthernetFrameExtendedPmRequest{
2625 OnuDeviceId: string(options.Args.Id),
2626 Reset_: options.Reset,
2627 IsUniIndex: &extension.GetOmciEthernetFrameExtendedPmRequest_UniIndex{
2628 UniIndex: *options.Args.UniIndex,
2629 },
2630 },
Himani Chawla553a1392021-06-10 23:39:17 +05302631 },
2632 },
Himani Chawla806aa892021-08-30 15:51:46 +05302633 }
2634 } else {
2635 singleGetValReq = extension.SingleGetValueRequest{
2636 TargetId: string(options.Args.Id),
2637 Request: &extension.GetValueRequest{
2638 Request: &extension.GetValueRequest_OnuInfo{
2639 OnuInfo: &extension.GetOmciEthernetFrameExtendedPmRequest{
2640 OnuDeviceId: string(options.Args.Id),
2641 Reset_: options.Reset,
2642 },
2643 },
2644 },
2645 }
Himani Chawla553a1392021-06-10 23:39:17 +05302646 }
Himani Chawla806aa892021-08-30 15:51:46 +05302647
Himani Chawla553a1392021-06-10 23:39:17 +05302648 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2649 defer cancel()
2650 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2651 if err != nil {
2652 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2653 return err
2654 }
2655
2656 if rv.Response.Status != extension.GetValueResponse_OK {
2657 return fmt.Errorf("failed to get ethernet frame extended pm counters %v", rv.Response.ErrReason.String())
2658 }
2659 outputFormat := CharReplacer.Replace(options.Format)
2660 data := buildOnuEthernetFrameExtendedPmOutputFormat(rv.GetResponse().GetOnuCounters())
2661 if outputFormat == "" {
2662 outputFormat = GetCommandOptionWithDefault("device-get-onu-status", "format", DEFAULT_ETHERNET_FRAME_EXTENDED_PM_COUNTERS_FORMAT)
2663 }
Himani Chawla40acc122021-05-26 18:52:29 +05302664 result := CommandResult{
2665 Format: format.Format(outputFormat),
2666 OutputAs: toOutputType(options.OutputAs),
2667 NameLimit: options.NameLimit,
2668 Data: data,
2669 }
2670 GenerateOutput(&result)
2671 return nil
2672}
2673
kesavand6d1131f2021-02-05 22:38:15 +05302674func (options *UniStatus) Execute(args []string) error {
2675 conn, err := NewConnection()
2676 if err != nil {
2677 return err
2678 }
2679 defer conn.Close()
2680 client := extension.NewExtensionClient(conn)
2681
2682 singleGetValReq := extension.SingleGetValueRequest{
2683 TargetId: string(options.Args.Id),
2684 Request: &extension.GetValueRequest{
2685 Request: &extension.GetValueRequest_UniInfo{
2686 UniInfo: &extension.GetOnuUniInfoRequest{
2687 UniIndex: options.Args.UniIndex,
2688 },
2689 },
2690 },
2691 }
David K. Bainbridge9189c632021-03-26 21:52:21 +00002692 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand6d1131f2021-02-05 22:38:15 +05302693 defer cancel()
2694 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2695 if err != nil {
2696 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2697 return err
2698 }
2699 if rv.Response.Status != extension.GetValueResponse_OK {
2700 return fmt.Errorf("failed to get uni status %v", rv.Response.ErrReason.String())
2701 }
2702 outputFormat := CharReplacer.Replace(options.Format)
2703 if outputFormat == "" {
2704 outputFormat = GetCommandOptionWithDefault("device-get-uni-status", "format", DEFAULT_DEVICE_GET_UNI_STATUS_FORMAT)
2705 }
2706 result := CommandResult{
2707 Format: format.Format(outputFormat),
2708 OutputAs: toOutputType(options.OutputAs),
2709 NameLimit: options.NameLimit,
2710 Data: rv.GetResponse().GetUniInfo(),
2711 }
2712 GenerateOutput(&result)
2713 return nil
2714}
2715
Girish Gowdra4f5ce7c2021-04-29 18:53:21 -07002716func (options *OnuPonOpticalInfo) Execute(args []string) error {
2717 conn, err := NewConnection()
2718 if err != nil {
2719 return err
2720 }
2721 defer conn.Close()
2722 client := extension.NewExtensionClient(conn)
2723
2724 singleGetValReq := extension.SingleGetValueRequest{
2725 TargetId: string(options.Args.Id),
2726 Request: &extension.GetValueRequest{
2727 Request: &extension.GetValueRequest_OnuOpticalInfo{
2728 OnuOpticalInfo: &extension.GetOnuPonOpticalInfo{},
2729 },
2730 },
2731 }
2732 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2733 defer cancel()
2734 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2735 if err != nil {
2736 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2737 return err
2738 }
2739 if rv.Response.Status != extension.GetValueResponse_OK {
2740 return fmt.Errorf("failed to get onu pon optical info %v", rv.Response.ErrReason.String())
2741 }
2742 outputFormat := CharReplacer.Replace(options.Format)
2743 if outputFormat == "" {
2744 outputFormat = GetCommandOptionWithDefault("device-get-onu-pon-optical-info", "format", DEFAULT_ONU_PON_OPTICAL_INFO_STATUS_FORMAT)
2745 }
2746 result := CommandResult{
2747 Format: format.Format(outputFormat),
2748 OutputAs: toOutputType(options.OutputAs),
2749 NameLimit: options.NameLimit,
2750 Data: rv.GetResponse().GetOnuOpticalInfo(),
2751 }
2752 GenerateOutput(&result)
2753 return nil
2754}
2755
Gamze Abakac857a462021-05-26 13:45:54 +00002756func (options *RxPower) Execute(args []string) error {
2757 conn, err := NewConnection()
2758 if err != nil {
2759 return err
2760 }
2761 defer conn.Close()
2762 client := extension.NewExtensionClient(conn)
2763
2764 singleGetValReq := extension.SingleGetValueRequest{
2765 TargetId: string(options.Args.Id),
2766 Request: &extension.GetValueRequest{
2767 Request: &extension.GetValueRequest_RxPower{
2768 RxPower: &extension.GetRxPowerRequest{
2769 IntfId: options.Args.PortNo,
2770 OnuId: options.Args.OnuNo,
2771 },
2772 },
2773 },
2774 }
2775
2776 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2777 defer cancel()
2778 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2779 if err != nil {
2780 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2781 return err
2782 }
2783 if rv.Response.Status != extension.GetValueResponse_OK {
2784 return fmt.Errorf("failed to get rx power %v", rv.Response.ErrReason.String())
2785 }
2786 outputFormat := CharReplacer.Replace(options.Format)
2787 if outputFormat == "" {
2788 outputFormat = GetCommandOptionWithDefault("device-get-rx-power", "format", DEFAULT_RX_POWER_STATUS_FORMAT)
2789 }
2790 result := CommandResult{
2791 Format: format.Format(outputFormat),
2792 OutputAs: toOutputType(options.OutputAs),
2793 NameLimit: options.NameLimit,
2794 Data: rv.GetResponse().GetRxPower(),
2795 }
2796 GenerateOutput(&result)
2797 return nil
2798}
2799
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002800/*Device get Onu Distance */
2801func (options *DeviceGetExtValue) Execute(args []string) error {
2802 conn, err := NewConnection()
2803 if err != nil {
2804 return err
2805 }
2806 defer conn.Close()
2807
Scott Baker9173ed82020-05-19 08:30:12 -07002808 client := voltha.NewVolthaServiceClient(conn)
2809
khenaidoo080ce882021-10-19 17:35:08 -04002810 valueflag, okay := extension.ValueType_Type_value[string(options.Args.Valueflag)]
Scott Baker9173ed82020-05-19 08:30:12 -07002811 if !okay {
2812 Error.Printf("Unknown valueflag %s\n", options.Args.Valueflag)
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002813 }
2814
khenaidoo080ce882021-10-19 17:35:08 -04002815 val := extension.ValueSpecifier{Id: string(options.Args.Id), Value: extension.ValueType_Type(valueflag)}
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002816
David K. Bainbridge9189c632021-03-26 21:52:21 +00002817 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002818 defer cancel()
2819
Scott Baker9173ed82020-05-19 08:30:12 -07002820 rv, err := client.GetExtValue(ctx, &val)
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002821 if err != nil {
2822 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2823 return err
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002824 }
2825
Scott Baker9173ed82020-05-19 08:30:12 -07002826 var rows []ReturnValueRow
khenaidoo080ce882021-10-19 17:35:08 -04002827 for name, num := range extension.ValueType_Type_value {
Scott Baker9173ed82020-05-19 08:30:12 -07002828 if num == 0 {
2829 // EMPTY is not a real value
2830 continue
2831 }
2832 if (rv.Error & uint32(num)) != 0 {
2833 row := ReturnValueRow{Name: name, Result: "Error"}
2834 rows = append(rows, row)
2835 }
2836 if (rv.Unsupported & uint32(num)) != 0 {
2837 row := ReturnValueRow{Name: name, Result: "Unsupported"}
2838 rows = append(rows, row)
2839 }
2840 if (rv.Set & uint32(num)) != 0 {
2841 switch name {
2842 case "DISTANCE":
2843 row := ReturnValueRow{Name: name, Result: rv.Distance}
2844 rows = append(rows, row)
2845 default:
2846 row := ReturnValueRow{Name: name, Result: "Unimplemented-in-voltctl"}
2847 rows = append(rows, row)
2848 }
2849 }
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002850 }
2851
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002852 outputFormat := CharReplacer.Replace(options.Format)
2853 if outputFormat == "" {
2854 outputFormat = GetCommandOptionWithDefault("device-value-get", "format", DEFAULT_DEVICE_VALUE_GET_FORMAT)
2855 }
2856
2857 result := CommandResult{
2858 Format: format.Format(outputFormat),
2859 OutputAs: toOutputType(options.OutputAs),
2860 NameLimit: options.NameLimit,
Scott Baker9173ed82020-05-19 08:30:12 -07002861 Data: rows,
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002862 }
2863 GenerateOutput(&result)
2864 return nil
2865}
serkantul3d22fc72022-09-14 12:22:56 +03002866
2867/*Device get Onu OMCI TX RX Stats */
2868func (options *OnuOmciTxRxStats) Execute(args []string) error {
2869 conn, err := NewConnection()
2870 if err != nil {
2871 return err
2872 }
2873 defer conn.Close()
2874 client := extension.NewExtensionClient(conn)
2875
2876 singleGetValReq := extension.SingleGetValueRequest{
2877 TargetId: string(options.Args.Id),
2878 Request: &extension.GetValueRequest{
2879 Request: &extension.GetValueRequest_OnuOmciStats{
2880 OnuOmciStats: &extension.GetOnuOmciTxRxStatsRequest{},
2881 },
2882 },
2883 }
2884
2885 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2886 defer cancel()
2887 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2888 if err != nil {
2889 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2890 return err
2891 }
2892
2893 if rv.Response.Status != extension.GetValueResponse_OK {
2894 return fmt.Errorf("failed to get onu omci tx rx stats %v", rv.Response.ErrReason.String())
2895 }
2896 outputFormat := CharReplacer.Replace(options.Format)
2897 if outputFormat == "" {
2898 outputFormat = GetCommandOptionWithDefault("device-get-onu-omci-tx-rx-stats", "format", DEFAULT_ONU_OMCI_TX_RX_STATS_FORMAT)
2899 }
2900 result := CommandResult{
2901 Format: format.Format(outputFormat),
2902 OutputAs: toOutputType(options.OutputAs),
2903 NameLimit: options.NameLimit,
2904 Data: rv.GetResponse().GetOnuOmciStats(),
2905 }
2906 GenerateOutput(&result)
2907 return nil
2908}
praneeth nalmas1dd094c2022-12-22 14:15:13 +05302909
2910/*Device get Onu Active Alarms */
2911func (options *GetOnuOmciActiveAlarms) Execute(args []string) error {
2912 conn, err := NewConnection()
2913 if err != nil {
2914 return err
2915 }
2916 defer conn.Close()
2917 client := extension.NewExtensionClient(conn)
2918
2919 singleGetValReq := extension.SingleGetValueRequest{
2920 TargetId: string(options.Args.Id),
2921 Request: &extension.GetValueRequest{
2922 Request: &extension.GetValueRequest_OnuActiveAlarms{
2923 OnuActiveAlarms: &extension.GetOnuOmciActiveAlarmsRequest{},
2924 },
2925 },
2926 }
2927 Info.Printf("Getting omci_active_alarms for device Id %s\n", options.Args.Id)
2928 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2929 defer cancel()
2930 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2931 if err != nil {
2932 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2933 return err
2934 }
2935
2936 if rv.Response.Status != extension.GetValueResponse_OK {
2937 return fmt.Errorf("failed to get onu omci active alarms list %v", rv.Response.ErrReason.String())
2938 }
2939 outputFormat := CharReplacer.Replace(options.Format)
2940 if outputFormat == "" {
2941 outputFormat = GetCommandOptionWithDefault("device-get-onu-omci-active-alarms", "format", DEFAULT_DEVICE_ALARMS_FORMAT)
2942 }
2943
2944 orderBy := options.OrderBy
2945 if orderBy == "" {
2946 orderBy = GetCommandOptionWithDefault("device-list", "order", DEFAULT_DEVICE_ALARMS_ORDER)
2947 }
2948
2949 result := CommandResult{
2950 Format: format.Format(outputFormat),
2951 OutputAs: toOutputType(options.OutputAs),
2952 OrderBy: orderBy,
2953 NameLimit: options.NameLimit,
2954 Data: rv.GetResponse().GetOnuActiveAlarms().GetActiveAlarms(),
2955 }
2956 GenerateOutput(&result)
2957 return nil
2958}
praneeth nalmas39c71ad2023-09-27 18:29:04 +05302959
Akash Soni66db9632024-04-15 09:05:15 +05302960/*Device get Onu Active Alarms */
2961func (options *GetOnuDistance) Execute(args []string) error {
2962 conn, err := NewConnection()
2963 if err != nil {
2964 return err
2965 }
2966 defer conn.Close()
2967 client := extension.NewExtensionClient(conn)
2968
2969 singleGetValReq := extension.SingleGetValueRequest{
2970 TargetId: string(options.Args.Id),
2971 Request: &extension.GetValueRequest{
2972 Request: &extension.GetValueRequest_Distance{
2973 Distance: &extension.GetDistanceRequest{
2974 OnuDeviceId: string(options.Args.OnuId),
2975 },
2976 },
2977 },
2978 }
2979 Info.Printf("Getting onu distance for device Id %s\n", options.Args.Id)
2980 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2981 defer cancel()
2982 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2983 if err != nil {
2984 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2985 return err
2986 }
2987
2988 if rv.Response.Status != extension.GetValueResponse_OK {
2989 return fmt.Errorf("failed to get onu distance stats %v", rv.Response.ErrReason.String())
2990 }
2991 outputFormat := CharReplacer.Replace(options.Format)
2992 if outputFormat == "" {
2993 outputFormat = GetCommandOptionWithDefault("get-onu-distance", "format", DEFAULT_ONU_DISTANCE_FORMAT)
2994 }
2995
2996 result := CommandResult{
2997 Format: format.Format(outputFormat),
2998 OutputAs: toOutputType(options.OutputAs),
2999 NameLimit: options.NameLimit,
3000 Data: rv.GetResponse().GetDistance().GetDistance(),
3001 }
3002 fmt.Println("onu distance : ", rv)
3003 GenerateOutput(&result)
3004 return nil
3005}
3006
praneeth nalmas39c71ad2023-09-27 18:29:04 +05303007func (options *PonRxPower) Execute(args []string) error {
3008 conn, err := NewConnection()
3009 if err != nil {
3010 return err
3011 }
3012 defer conn.Close()
3013 client := extension.NewExtensionClient(conn)
3014
3015 singleGetValReq := extension.SingleGetValueRequest{
3016 TargetId: string(options.Args.Id),
3017 Request: &extension.GetValueRequest{
3018 Request: &extension.GetValueRequest_OltRxPower{
3019 OltRxPower: &extension.GetOltRxPowerRequest{
3020 PortLabel: options.Args.PortLabel,
3021 OnuSn: options.Args.SerialNo,
3022 },
3023 },
3024 },
3025 }
3026
3027 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3028 defer cancel()
3029 rv, err := client.GetExtValue(ctx, &singleGetValReq)
3030 if err != nil {
3031 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
3032 return err
3033 }
3034 if rv.Response.Status != extension.GetValueResponse_OK {
3035 return fmt.Errorf("failed to get rx power %v", rv.Response.ErrReason.String())
3036 }
3037 outputFormat := CharReplacer.Replace(options.Format)
3038 if outputFormat == "" {
3039 outputFormat = GetCommandOptionWithDefault("device-get-pon-rx-power", "format", DEFAULT_PON_RX_POWER_STATUS_FORMAT)
3040 }
3041 result := CommandResult{
3042 Format: format.Format(outputFormat),
3043 OutputAs: toOutputType(options.OutputAs),
3044 NameLimit: options.NameLimit,
3045 Data: rv.GetResponse().GetOltRxPower().GetRxPower(),
3046 }
3047 GenerateOutput(&result)
3048 return nil
3049}
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +05303050
3051func (options *GetOnuGEMStats) Execute(args []string) error {
3052
3053 conn, err := NewConnection()
3054 if err != nil {
3055 return err
3056 }
3057 defer conn.Close()
3058 client := extension.NewExtensionClient(conn)
3059 singleGetValReq := extension.SingleGetValueRequest{
3060 TargetId: string(options.Args.Id),
3061 Request: &extension.GetValueRequest{
3062 Request: &extension.GetValueRequest_OnuAllocGemStats{
3063 OnuAllocGemStats: &extension.GetOnuAllocGemHistoryRequest{},
3064 },
3065 },
3066 }
3067
3068 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3069 defer cancel()
3070
3071 rv, err := client.GetExtValue(ctx, &singleGetValReq)
3072
3073 if err != nil {
3074 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
3075 return err
3076 }
3077
3078 if rv.Response.Status != extension.GetValueResponse_OK {
3079 return fmt.Errorf("failed to get gem port response %v", rv.Response.ErrReason.String())
3080 }
3081 outputFormat := CharReplacer.Replace(options.Format)
3082 if outputFormat == "" {
3083 outputFormat = GetCommandOptionWithDefault("device-get-gem-port", "format", DEFAULT_DEVICE_VALUE_GEM_PORT_FORMAT)
3084 }
3085 onugemhistoryresponse := rv.GetResponse().GetOnuAllocGemStatsResponse()
3086 for _, OnuallocGemHistoryData := range onugemhistoryresponse.OnuAllocGemHistoryData {
3087 data := onugemstats{}
3088 data.AllocId = OnuallocGemHistoryData.OnuAllocIdInfo.AllocId
3089 data.AllocRxBytes = OnuallocGemHistoryData.OnuAllocIdInfo.RxBytes
3090 for _, gemStatsInfo := range OnuallocGemHistoryData.GemPortInfo {
3091 data.GemHistoryStats = append(data.GemHistoryStats, gemHistoryStats{
3092 GemId: gemStatsInfo.GemId,
3093 TransmittedGEMFrames: gemStatsInfo.TransmittedGEMFrames,
3094 ReceivedGEMFrames: gemStatsInfo.ReceivedGEMFrames,
3095 ReceivedPayloadBytes: gemStatsInfo.ReceivedPayloadBytes,
3096 TransmittedPayloadBytes: gemStatsInfo.TransmittedPayloadBytes,
3097 EncryptionKeyErrors: gemStatsInfo.EncryptionKeyErrors,
3098 })
3099 }
3100 result := CommandResult{
3101 Format: format.Format(outputFormat),
3102 OutputAs: toOutputType(options.OutputAs),
3103 NameLimit: options.NameLimit,
3104 Data: &data,
3105 }
3106 GenerateOutput(&result)
3107 }
3108 return nil
3109
3110}
3111
3112func (options *GetOnuAllocGemStatsFromOlt) Execute(args []string) error {
3113 conn, err := NewConnection()
3114 if err != nil {
3115 return err
3116 }
3117 defer conn.Close()
3118 client := extension.NewExtensionClient(conn)
3119
3120 singleGetValReq := extension.SingleGetValueRequest{
3121 TargetId: string(options.Args.Id),
3122 Request: &extension.GetValueRequest{
3123 Request: &extension.GetValueRequest_OnuStatsFromOlt{
3124 OnuStatsFromOlt: &extension.GetOnuStatsFromOltRequest{},
3125 },
3126 },
3127 }
3128 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3129 defer cancel()
3130 rv, err := client.GetExtValue(ctx, &singleGetValReq)
3131 if err != nil {
3132 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
3133 return err
3134 }
3135
3136 if rv.Response.Status != extension.GetValueResponse_OK {
3137 return fmt.Errorf("failed to get onu alloc gem stats from olt %v", rv.Response.ErrReason.String())
3138 }
3139 outputFormat := CharReplacer.Replace(options.Format)
3140 if outputFormat == "" {
3141 outputFormat = GetCommandOptionWithDefault("device-get-onu-status", "format", DEFAULT_ONU_STATS_FROM_OLT_FORMAT)
3142 }
3143
3144 onuAllocGemStatsResponse := rv.GetResponse().GetOnuStatsFromOltResponse()
3145
3146 for _, allocGemStatsInfo := range onuAllocGemStatsResponse.AllocGemStatsInfo {
3147 data := AllocGemStatsFromOlt{}
3148 data.AllocId = allocGemStatsInfo.AllocIdInfo.AllocId
3149 data.AllocRxBytes = allocGemStatsInfo.AllocIdInfo.RxBytes
3150 for _, gemStatsInfo := range allocGemStatsInfo.GemPortInfo {
3151 data.GemPortStats = append(data.GemPortStats, GemPortStatsFromOlt{
3152 GemId: gemStatsInfo.GemId,
3153 RxBytes: gemStatsInfo.RxBytes,
3154 RxPackets: gemStatsInfo.RxPackets,
3155 TxBytes: gemStatsInfo.TxBytes,
3156 TxPackets: gemStatsInfo.TxPackets,
3157 })
3158 }
3159 result := CommandResult{
3160 Format: format.Format(outputFormat),
3161 OutputAs: toOutputType(options.OutputAs),
3162 NameLimit: options.NameLimit,
3163 Data: &data,
3164 }
3165 GenerateOutput(&result)
3166 }
3167
3168 return nil
3169}
mgouda35b90e62025-07-16 14:58:29 +05303170
3171func (options *DisableOnuDevice) Execute(args []string) error {
3172 conn, err := NewConnection()
3173 if err != nil {
3174 return err
3175 }
3176 defer conn.Close()
3177
3178 client := voltha.NewVolthaServiceClient(conn)
3179
3180 var lastErr error
3181 for _, i := range options.Args.Ids {
3182 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3183 defer cancel()
3184
3185 id := voltha.ID{Id: string(i)}
3186
3187 _, err := client.DisableOnuDevice(ctx, &id)
3188 if err != nil {
3189 Error.Printf("Error while disabling the onu serial number'%s': %s\n", i, err)
3190 lastErr = err
3191 continue
3192 }
3193 fmt.Printf("%s\n", i)
3194 }
3195
3196 if lastErr != nil {
3197 return NoReportErr
3198 }
3199 return nil
3200}
3201
3202func (options *EnableOnuDevice) Execute(args []string) error {
3203 conn, err := NewConnection()
3204 if err != nil {
3205 return err
3206 }
3207 defer conn.Close()
3208
3209 client := voltha.NewVolthaServiceClient(conn)
3210
3211 var lastErr error
3212 for _, i := range options.Args.Ids {
3213 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3214 defer cancel()
3215
3216 id := voltha.ID{Id: string(i)}
3217
3218 _, err := client.EnableOnuDevice(ctx, &id)
3219 if err != nil {
3220 Error.Printf("Error while enabling the onu serial number'%s': %s\n", i, err)
3221 lastErr = err
3222 continue
3223 }
3224 fmt.Printf("%s\n", i)
3225 }
3226
3227 if lastErr != nil {
3228 return NoReportErr
3229 }
3230 return nil
3231}
3232
3233func (options *DisableOnuSerialNumber) Execute(args []string) error {
3234 conn, err := NewConnection()
3235 if err != nil {
3236 return err
3237 }
3238 defer conn.Close()
3239
3240 client := voltha.NewVolthaServiceClient(conn)
3241
3242 id := common.ID{Id: string(options.Args.OltDeviceId)}
3243 port := voltha.Port{PortNo: uint32(options.Args.Port)}
3244
3245 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3246 defer cancel()
3247
3248 req := &voltha.OnuSerialNumberOnOLTPon{
3249 OltDeviceId: &id,
3250 SerialNumber: options.Args.SerialNumber,
3251 Port: &port,
3252 }
3253
3254 _, err = client.DisableOnuSerialNumber(ctx, req)
3255 if err != nil {
3256 Error.Printf("Error disabling ONU serial '%s' on OLT '%s': %v\n", options.Args.SerialNumber, options.Args.OltDeviceId, err)
3257 return err
3258 }
3259 fmt.Printf("Disabled ONU serial '%s' on OLT '%s'\n", options.Args.SerialNumber, options.Args.OltDeviceId)
3260 return nil
3261}
3262
3263func (options *EnableOnuSerialNumber) Execute(args []string) error {
3264 conn, err := NewConnection()
3265 if err != nil {
3266 return err
3267 }
3268 defer conn.Close()
3269
3270 client := voltha.NewVolthaServiceClient(conn)
3271
3272 id := common.ID{Id: string(options.Args.OltDeviceId)}
3273 port := voltha.Port{PortNo: uint32(options.Args.Port)}
3274
3275 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3276 defer cancel()
3277
3278 req := &voltha.OnuSerialNumberOnOLTPon{
3279 OltDeviceId: &id,
3280 SerialNumber: options.Args.SerialNumber,
3281 Port: &port,
3282 }
3283
3284 _, err = client.EnableOnuSerialNumber(ctx, req)
3285 if err != nil {
3286 Error.Printf("Error enabling ONU serial '%s' on OLT '%s': %v\n", options.Args.SerialNumber, options.Args.OltDeviceId, err)
3287 return err
3288 }
3289 fmt.Printf("Enabled ONU serial '%s' on OLT '%s'\n", options.Args.SerialNumber, options.Args.OltDeviceId)
3290 return nil
3291}