blob: 7d824f40980d9b26e9fea55fe16b0b5866fb2563 [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
Zack Williamse940c7a2019-08-21 14:25:39 -0700589type DeviceOpts struct {
Himani Chawla3c161c62021-05-13 16:36:51 +0530590 List DeviceList `command:"list"`
591 Create DeviceCreate `command:"create"`
592 Delete DeviceDelete `command:"delete"`
593 Enable DeviceEnable `command:"enable"`
594 Disable DeviceDisable `command:"disable"`
595 Flows DeviceFlowList `command:"flows"`
596 Groups DeviceFlowGroupList `command:"groups"`
kesavand12cd8eb2020-01-20 22:25:22 -0500597 Port struct {
598 List DevicePortList `command:"list"`
599 Enable DevicePortEnable `command:"enable"`
600 Disable DevicePortDisable `command:"disable"`
601 } `command:"port"`
602 Inspect DeviceInspect `command:"inspect"`
603 Reboot DeviceReboot `command:"reboot"`
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -0800604 Value struct {
605 Get DeviceGetExtValue `command:"get"`
606 } `command:"value"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000607 PmConfig struct {
Rohan Agrawald7df3772020-06-29 11:23:36 +0000608 Get DevicePmConfigsGet `command:"get"`
609 MaxSkew struct {
610 Set DevicePmConfigSetMaxSkew `command:"set"`
611 } `command:"maxskew"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000612 Frequency struct {
613 Set DevicePmConfigFrequencySet `command:"set"`
614 } `command:"frequency"`
615 Metric struct {
616 List DevicePmConfigMetricList `command:"list"`
617 Enable DevicePmConfigMetricEnable `command:"enable"`
618 Disable DevicePmConfigMetricDisable `command:"disable"`
619 } `command:"metric"`
620 Group struct {
Girish Gowdra610acb42021-01-27 13:33:57 -0800621 List DevicePmConfigGroupList `command:"list"`
622 Enable DevicePmConfigGroupEnable `command:"enable"`
623 Disable DevicePmConfigGroupDisable `command:"disable"`
624 Set DevicePmConfigGroupFrequencySet `command:"set"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000625 } `command:"group"`
626 GroupMetric struct {
627 List DevicePmConfigGroupMetricList `command:"list"`
628 } `command:"groupmetric"`
629 } `command:"pmconfig"`
Andrea Campanella791d88b2021-01-08 13:29:00 +0100630 Image struct {
631 Get DeviceOnuListImages `command:"list"`
632 Download DeviceOnuDownloadImage `command:"download"`
633 Activate DeviceOnuActivateImageUpdate `command:"activate"`
634 } `command:"image"`
kesavand3e2f9f62021-04-22 11:06:38 +0530635 DownloadImage struct {
636 Download OnuDownloadImage `command:"download"`
637 Activate OnuActivateImage `command:"activate"`
638 Commit OnuCommitImage `command:"commit"`
639 AbortUpgrade OnuAbortUpgradeImage `command:"abort"`
640 Status OnuImageStatus `command:"status"`
641 List OnuListImages `command:"list" `
642 } `command:"onuimage"`
kesavand8ec4fc02021-01-27 09:10:22 -0500643 GetExtVal struct {
Himani Chawla553a1392021-06-10 23:39:17 +0530644 Stats DeviceGetPortStats `command:"portstats"`
645 UniStatus UniStatus `command:"unistatus"`
646 OpticalInfo OnuPonOpticalInfo `command:"onu_pon_optical_info"`
647 OnuStats GetOnuStats `command:"onu_stats"`
648 EthernetFrameExtendedPm GetOnuEthernetFrameExtendedPmCounters `command:"ethernet_frame_extended_pm"`
649 RxPower RxPower `command:"rxpower"`
serkantul3d22fc72022-09-14 12:22:56 +0300650 OnuOmciStats OnuOmciTxRxStats `command:"onu_omci_stats"`
praneeth nalmas1dd094c2022-12-22 14:15:13 +0530651 OnuOmciActiveAlarms GetOnuOmciActiveAlarms `command:"onu_omci_active_alarms"`
praneeth nalmas39c71ad2023-09-27 18:29:04 +0530652 PonRxPower PonRxPower `command:"pon_rx_power"`
Akash Soni66db9632024-04-15 09:05:15 +0530653 OnuDistance GetOnuDistance `command:"onu_distance"`
Akash Soni6e879c22024-12-20 17:01:34 +0530654 OffloadAppStats GetOffloadApp `command:"offload_app_stats"`
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +0530655 PonStats GetPonPortStats `command:"itu_pon_stats"`
656 NniStats GetNniPortStats `command:"nni_statistics"`
657 OnuGEMStats GetOnuGEMStats `command:"onu_gem_stats"`
658 OnuAllocGemStats GetOnuAllocGemStatsFromOlt `command:"onu_alloc_gem_from_olt"`
kesavand8ec4fc02021-01-27 09:10:22 -0500659 } `command:"getextval"`
Akash Soni51b6b7a2024-11-20 11:39:38 +0530660 SetExtVal struct {
Akash Soni6e879c22024-12-20 17:01:34 +0530661 OffloadAppStatsSet SetOffloadApp `command:"set_offload_app"`
662 OnuOffloadStatsSet SetOnuOffload `command:"set_onu_offload"`
Akash Soni51b6b7a2024-11-20 11:39:38 +0530663 } `command:"setextval"`
Zack Williamse940c7a2019-08-21 14:25:39 -0700664}
665
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +0530666type AllocGemStatsFromOlt struct {
667 AllocId uint32
668 AllocRxBytes uint64
669 GemPortStats []GemPortStatsFromOlt
670}
671type GemPortStatsFromOlt struct {
672 GemId uint32
673 RxPackets uint64
674 RxBytes uint64
675 TxPackets uint64
676 TxBytes uint64
677}
678type onugemstats struct {
679 AllocId uint32
680 AllocRxBytes uint32
681 GemHistoryStats []gemHistoryStats
682}
683type gemHistoryStats struct {
684 GemId uint32
685 TransmittedGEMFrames uint32
686 ReceivedGEMFrames uint32
687 ReceivedPayloadBytes uint32
688 TransmittedPayloadBytes uint32
689 EncryptionKeyErrors uint32
690}
691
692type PortStats struct {
693 PonPort uint32 // use this for PON
694 NniPort uint32 // use this for NNI
695 *common.PortStatistics
696}
697
Zack Williamse940c7a2019-08-21 14:25:39 -0700698var deviceOpts = DeviceOpts{}
699
700func RegisterDeviceCommands(parser *flags.Parser) {
David Bainbridge12f036f2019-10-15 22:09:04 +0000701 if _, err := parser.AddCommand("device", "device commands", "Commands to query and manipulate VOLTHA devices", &deviceOpts); err != nil {
David Bainbridgea6722342019-10-24 23:55:53 +0000702 Error.Fatalf("Unexpected error while attempting to register device commands : %s", err)
David Bainbridge12f036f2019-10-15 22:09:04 +0000703 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700704}
705
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000706func (i *MetricName) Complete(match string) []flags.Completion {
707 conn, err := NewConnection()
708 if err != nil {
709 return nil
710 }
711 defer conn.Close()
712
713 client := voltha.NewVolthaServiceClient(conn)
714
715 var deviceId string
716found:
717 for i := len(os.Args) - 1; i >= 0; i -= 1 {
718 switch os.Args[i] {
719 case "enable":
720 fallthrough
721 case "disable":
722 if len(os.Args) > i+1 {
723 deviceId = os.Args[i+1]
724 } else {
725 return nil
726 }
727 break found
728 default:
729 }
730 }
731
732 if len(deviceId) == 0 {
733 return nil
734 }
735
David K. Bainbridge9189c632021-03-26 21:52:21 +0000736 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000737 defer cancel()
738
739 id := voltha.ID{Id: string(deviceId)}
740
741 pmconfigs, err := client.ListDevicePmConfigs(ctx, &id)
742
743 if err != nil {
744 return nil
745 }
746
747 list := make([]flags.Completion, 0)
748 for _, metrics := range pmconfigs.Metrics {
749 if strings.HasPrefix(metrics.Name, match) {
750 list = append(list, flags.Completion{Item: metrics.Name})
751 }
752 }
753
754 return list
755}
756
757func (i *GroupName) Complete(match string) []flags.Completion {
758 conn, err := NewConnection()
759 if err != nil {
760 return nil
761 }
762 defer conn.Close()
763
764 client := voltha.NewVolthaServiceClient(conn)
765
766 var deviceId string
767found:
768 for i := len(os.Args) - 1; i >= 0; i -= 1 {
769 switch os.Args[i] {
770 case "list":
771 fallthrough
772 case "enable":
773 fallthrough
774 case "disable":
775 if len(os.Args) > i+1 {
776 deviceId = os.Args[i+1]
777 } else {
778 return nil
779 }
780 break found
781 default:
782 }
783 }
784
785 if len(deviceId) == 0 {
786 return nil
787 }
788
David K. Bainbridge9189c632021-03-26 21:52:21 +0000789 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000790 defer cancel()
791
792 id := voltha.ID{Id: string(deviceId)}
793
794 pmconfigs, err := client.ListDevicePmConfigs(ctx, &id)
795
796 if err != nil {
797 return nil
798 }
799
800 list := make([]flags.Completion, 0)
801 for _, group := range pmconfigs.Groups {
802 if strings.HasPrefix(group.GroupName, match) {
803 list = append(list, flags.Completion{Item: group.GroupName})
804 }
805 }
806 return list
807}
808
kesavand12cd8eb2020-01-20 22:25:22 -0500809func (i *PortNum) Complete(match string) []flags.Completion {
810 conn, err := NewConnection()
811 if err != nil {
812 return nil
813 }
814 defer conn.Close()
815
Scott Baker9173ed82020-05-19 08:30:12 -0700816 client := voltha.NewVolthaServiceClient(conn)
kesavand12cd8eb2020-01-20 22:25:22 -0500817
818 /*
819 * The command line args when completing for PortNum will be a DeviceId
820 * followed by one or more PortNums. So walk the argument list from the
821 * end and find the first argument that is enable/disable as those are
822 * the subcommands that come before the positional arguments. It would
823 * be nice if this package gave us the list of optional arguments
824 * already parsed.
825 */
826 var deviceId string
827found:
828 for i := len(os.Args) - 1; i >= 0; i -= 1 {
829 switch os.Args[i] {
830 case "enable":
831 fallthrough
832 case "disable":
833 if len(os.Args) > i+1 {
834 deviceId = os.Args[i+1]
835 } else {
836 return nil
837 }
838 break found
839 default:
840 }
841 }
842
843 if len(deviceId) == 0 {
844 return nil
845 }
846
David K. Bainbridge9189c632021-03-26 21:52:21 +0000847 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand12cd8eb2020-01-20 22:25:22 -0500848 defer cancel()
kesavand12cd8eb2020-01-20 22:25:22 -0500849
Scott Baker9173ed82020-05-19 08:30:12 -0700850 id := voltha.ID{Id: string(deviceId)}
kesavand12cd8eb2020-01-20 22:25:22 -0500851
Scott Baker9173ed82020-05-19 08:30:12 -0700852 ports, err := client.ListDevicePorts(ctx, &id)
kesavand12cd8eb2020-01-20 22:25:22 -0500853 if err != nil {
854 return nil
855 }
856
857 list := make([]flags.Completion, 0)
Scott Baker9173ed82020-05-19 08:30:12 -0700858 for _, item := range ports.Items {
859 pn := strconv.FormatUint(uint64(item.PortNo), 10)
kesavand12cd8eb2020-01-20 22:25:22 -0500860 if strings.HasPrefix(pn, match) {
861 list = append(list, flags.Completion{Item: pn})
862 }
863 }
864
865 return list
866}
867
Zack Williamse940c7a2019-08-21 14:25:39 -0700868func (i *DeviceId) Complete(match string) []flags.Completion {
869 conn, err := NewConnection()
870 if err != nil {
871 return nil
872 }
873 defer conn.Close()
874
Scott Baker9173ed82020-05-19 08:30:12 -0700875 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700876
David K. Bainbridge9189c632021-03-26 21:52:21 +0000877 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700878 defer cancel()
879
Scott Baker9173ed82020-05-19 08:30:12 -0700880 devices, err := client.ListDevices(ctx, &empty.Empty{})
Zack Williamse940c7a2019-08-21 14:25:39 -0700881 if err != nil {
882 return nil
883 }
884
885 list := make([]flags.Completion, 0)
Scott Baker9173ed82020-05-19 08:30:12 -0700886 for _, item := range devices.Items {
887 if strings.HasPrefix(item.Id, match) {
888 list = append(list, flags.Completion{Item: item.Id})
Zack Williamse940c7a2019-08-21 14:25:39 -0700889 }
890 }
891
892 return list
893}
894
895func (options *DeviceList) Execute(args []string) error {
896
897 conn, err := NewConnection()
898 if err != nil {
899 return err
900 }
901 defer conn.Close()
902
Scott Baker9173ed82020-05-19 08:30:12 -0700903 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700904
David K. Bainbridge9189c632021-03-26 21:52:21 +0000905 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700906 defer cancel()
907
Scott Baker9173ed82020-05-19 08:30:12 -0700908 devices, err := client.ListDevices(ctx, &empty.Empty{})
Zack Williamse940c7a2019-08-21 14:25:39 -0700909 if err != nil {
910 return err
911 }
912
913 outputFormat := CharReplacer.Replace(options.Format)
914 if outputFormat == "" {
David Bainbridgea6722342019-10-24 23:55:53 +0000915 outputFormat = GetCommandOptionWithDefault("device-list", "format", DEFAULT_DEVICE_FORMAT)
Zack Williamse940c7a2019-08-21 14:25:39 -0700916 }
917 if options.Quiet {
918 outputFormat = "{{.Id}}"
919 }
920
David Bainbridgea6722342019-10-24 23:55:53 +0000921 orderBy := options.OrderBy
922 if orderBy == "" {
Hardik Windlass9361bb82022-03-23 05:58:48 +0000923 orderBy = GetCommandOptionWithDefault("device-list", "order", DEFAULT_DEVICE_ORDER)
David Bainbridgea6722342019-10-24 23:55:53 +0000924 }
925
Scott Baker9173ed82020-05-19 08:30:12 -0700926 // Make sure json output prints an empty list, not "null"
927 if devices.Items == nil {
928 devices.Items = make([]*voltha.Device, 0)
Zack Williamse940c7a2019-08-21 14:25:39 -0700929 }
930
931 result := CommandResult{
932 Format: format.Format(outputFormat),
933 Filter: options.Filter,
David Bainbridgea6722342019-10-24 23:55:53 +0000934 OrderBy: orderBy,
Zack Williamse940c7a2019-08-21 14:25:39 -0700935 OutputAs: toOutputType(options.OutputAs),
936 NameLimit: options.NameLimit,
Scott Baker9173ed82020-05-19 08:30:12 -0700937 Data: devices.Items,
Zack Williamse940c7a2019-08-21 14:25:39 -0700938 }
939
940 GenerateOutput(&result)
941 return nil
942}
943
944func (options *DeviceCreate) Execute(args []string) error {
945
Scott Baker9173ed82020-05-19 08:30:12 -0700946 device := voltha.Device{}
Zack Williamse940c7a2019-08-21 14:25:39 -0700947 if options.HostAndPort != "" {
Scott Baker9173ed82020-05-19 08:30:12 -0700948 device.Address = &voltha.Device_HostAndPort{HostAndPort: options.HostAndPort}
Zack Williamse940c7a2019-08-21 14:25:39 -0700949 } else if options.IPAddress != "" {
Scott Baker9173ed82020-05-19 08:30:12 -0700950 device.Address = &voltha.Device_Ipv4Address{Ipv4Address: options.IPAddress}
Hardik Windlassce1de342020-02-04 21:58:07 +0000951 }
952 if options.MACAddress != "" {
Scott Baker9173ed82020-05-19 08:30:12 -0700953 device.MacAddress = strings.ToLower(options.MACAddress)
Zack Williamse940c7a2019-08-21 14:25:39 -0700954 }
955 if options.DeviceType != "" {
Scott Baker9173ed82020-05-19 08:30:12 -0700956 device.Type = options.DeviceType
Zack Williamse940c7a2019-08-21 14:25:39 -0700957 }
958
959 conn, err := NewConnection()
960 if err != nil {
961 return err
962 }
963 defer conn.Close()
964
Scott Baker9173ed82020-05-19 08:30:12 -0700965 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700966
David K. Bainbridge9189c632021-03-26 21:52:21 +0000967 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700968 defer cancel()
969
Scott Baker9173ed82020-05-19 08:30:12 -0700970 createdDevice, err := client.CreateDevice(ctx, &device)
Zack Williamse940c7a2019-08-21 14:25:39 -0700971 if err != nil {
972 return err
Zack Williamse940c7a2019-08-21 14:25:39 -0700973 }
974
Scott Baker9173ed82020-05-19 08:30:12 -0700975 fmt.Printf("%s\n", createdDevice.Id)
Zack Williamse940c7a2019-08-21 14:25:39 -0700976
977 return nil
978}
979
980func (options *DeviceDelete) Execute(args []string) error {
981
982 conn, err := NewConnection()
983 if err != nil {
984 return err
985 }
986 defer conn.Close()
987
Scott Baker9173ed82020-05-19 08:30:12 -0700988 client := voltha.NewVolthaServiceClient(conn)
David Bainbridge7052fe82020-03-25 10:37:00 -0700989 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -0700990 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +0000991 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700992 defer cancel()
993
Scott Baker9173ed82020-05-19 08:30:12 -0700994 id := voltha.ID{Id: string(i)}
Himani Chawla9933ddc2020-10-12 23:53:27 +0530995 if options.Force {
996 _, err = client.ForceDeleteDevice(ctx, &id)
997 } else {
998 _, err = client.DeleteDevice(ctx, &id)
999 }
Scott Baker9173ed82020-05-19 08:30:12 -07001000
Zack Williamse940c7a2019-08-21 14:25:39 -07001001 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +00001002 Error.Printf("Error while deleting '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -07001003 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -07001004 continue
Zack Williamse940c7a2019-08-21 14:25:39 -07001005 }
1006 fmt.Printf("%s\n", i)
1007 }
1008
David Bainbridge7052fe82020-03-25 10:37:00 -07001009 if lastErr != nil {
1010 return NoReportErr
1011 }
Zack Williamse940c7a2019-08-21 14:25:39 -07001012 return nil
1013}
1014
1015func (options *DeviceEnable) Execute(args []string) error {
1016 conn, err := NewConnection()
1017 if err != nil {
1018 return err
1019 }
1020 defer conn.Close()
1021
Scott Baker9173ed82020-05-19 08:30:12 -07001022 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -07001023
David Bainbridge7052fe82020-03-25 10:37:00 -07001024 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -07001025 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +00001026 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -07001027 defer cancel()
1028
Scott Baker9173ed82020-05-19 08:30:12 -07001029 id := voltha.ID{Id: string(i)}
1030
1031 _, err := client.EnableDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -07001032 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +00001033 Error.Printf("Error while enabling '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -07001034 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -07001035 continue
Zack Williamse940c7a2019-08-21 14:25:39 -07001036 }
1037 fmt.Printf("%s\n", i)
1038 }
1039
David Bainbridge7052fe82020-03-25 10:37:00 -07001040 if lastErr != nil {
1041 return NoReportErr
1042 }
Zack Williamse940c7a2019-08-21 14:25:39 -07001043 return nil
1044}
1045
1046func (options *DeviceDisable) Execute(args []string) error {
1047 conn, err := NewConnection()
1048 if err != nil {
1049 return err
1050 }
1051 defer conn.Close()
1052
Scott Baker9173ed82020-05-19 08:30:12 -07001053 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -07001054
David Bainbridge7052fe82020-03-25 10:37:00 -07001055 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -07001056 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +00001057 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -07001058 defer cancel()
1059
Scott Baker9173ed82020-05-19 08:30:12 -07001060 id := voltha.ID{Id: string(i)}
1061
1062 _, err := client.DisableDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -07001063 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +00001064 Error.Printf("Error while disabling '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -07001065 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -07001066 continue
Zack Williamse940c7a2019-08-21 14:25:39 -07001067 }
1068 fmt.Printf("%s\n", i)
1069 }
1070
David Bainbridge7052fe82020-03-25 10:37:00 -07001071 if lastErr != nil {
1072 return NoReportErr
1073 }
Zack Williamse940c7a2019-08-21 14:25:39 -07001074 return nil
1075}
1076
1077func (options *DeviceReboot) Execute(args []string) error {
1078 conn, err := NewConnection()
1079 if err != nil {
1080 return err
1081 }
1082 defer conn.Close()
1083
Scott Baker9173ed82020-05-19 08:30:12 -07001084 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -07001085
David Bainbridge7052fe82020-03-25 10:37:00 -07001086 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -07001087 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +00001088 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -07001089 defer cancel()
1090
Scott Baker9173ed82020-05-19 08:30:12 -07001091 id := voltha.ID{Id: string(i)}
1092
1093 _, err := client.RebootDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -07001094 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +00001095 Error.Printf("Error while rebooting '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -07001096 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -07001097 continue
Zack Williamse940c7a2019-08-21 14:25:39 -07001098 }
1099 fmt.Printf("%s\n", i)
1100 }
1101
David Bainbridge7052fe82020-03-25 10:37:00 -07001102 if lastErr != nil {
1103 return NoReportErr
1104 }
Zack Williamse940c7a2019-08-21 14:25:39 -07001105 return nil
1106}
1107
1108func (options *DevicePortList) Execute(args []string) error {
1109
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 K. Bainbridge9189c632021-03-26 21:52:21 +00001118 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -07001119 defer cancel()
1120
Scott Baker9173ed82020-05-19 08:30:12 -07001121 id := voltha.ID{Id: string(options.Args.Id)}
Zack Williamse940c7a2019-08-21 14:25:39 -07001122
Scott Baker9173ed82020-05-19 08:30:12 -07001123 ports, err := client.ListDevicePorts(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -07001124 if err != nil {
1125 return err
1126 }
1127
1128 outputFormat := CharReplacer.Replace(options.Format)
1129 if outputFormat == "" {
David Bainbridgea6722342019-10-24 23:55:53 +00001130 outputFormat = GetCommandOptionWithDefault("device-ports", "format", DEFAULT_DEVICE_PORTS_FORMAT)
Zack Williamse940c7a2019-08-21 14:25:39 -07001131 }
Zack Williamse940c7a2019-08-21 14:25:39 -07001132
David Bainbridgea6722342019-10-24 23:55:53 +00001133 orderBy := options.OrderBy
1134 if orderBy == "" {
1135 orderBy = GetCommandOptionWithDefault("device-ports", "order", "")
1136 }
1137
Zack Williamse940c7a2019-08-21 14:25:39 -07001138 result := CommandResult{
1139 Format: format.Format(outputFormat),
1140 Filter: options.Filter,
David Bainbridgea6722342019-10-24 23:55:53 +00001141 OrderBy: orderBy,
Zack Williamse940c7a2019-08-21 14:25:39 -07001142 OutputAs: toOutputType(options.OutputAs),
1143 NameLimit: options.NameLimit,
Scott Baker9173ed82020-05-19 08:30:12 -07001144 Data: ports.Items,
Zack Williamse940c7a2019-08-21 14:25:39 -07001145 }
1146
1147 GenerateOutput(&result)
1148 return nil
1149}
1150
1151func (options *DeviceFlowList) Execute(args []string) error {
1152 fl := &FlowList{}
1153 fl.ListOutputOptions = options.ListOutputOptions
Maninder045921e2020-09-29 16:46:02 +05301154 fl.FlowIdOptions = options.FlowIdOptions
Zack Williamse940c7a2019-08-21 14:25:39 -07001155 fl.Args.Id = string(options.Args.Id)
David Bainbridgea6722342019-10-24 23:55:53 +00001156 fl.Method = "device-flows"
Zack Williamse940c7a2019-08-21 14:25:39 -07001157 return fl.Execute(args)
1158}
1159
Himani Chawla3c161c62021-05-13 16:36:51 +05301160func (options *DeviceFlowGroupList) Execute(args []string) error {
1161 grp := &GroupList{}
1162 grp.ListOutputOptions = options.ListOutputOptions
1163 grp.GroupListOptions = options.GroupListOptions
1164 grp.Args.Id = string(options.Args.Id)
1165 grp.Method = "device-groups"
1166 return grp.Execute(args)
1167}
1168
Zack Williamse940c7a2019-08-21 14:25:39 -07001169func (options *DeviceInspect) Execute(args []string) error {
1170 if len(args) > 0 {
1171 return fmt.Errorf("only a single argument 'DEVICE_ID' can be provided")
1172 }
1173
1174 conn, err := NewConnection()
1175 if err != nil {
1176 return err
1177 }
1178 defer conn.Close()
1179
Scott Baker9173ed82020-05-19 08:30:12 -07001180 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -07001181
David K. Bainbridge9189c632021-03-26 21:52:21 +00001182 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -07001183 defer cancel()
1184
Scott Baker9173ed82020-05-19 08:30:12 -07001185 id := voltha.ID{Id: string(options.Args.Id)}
Zack Williamse940c7a2019-08-21 14:25:39 -07001186
Scott Baker9173ed82020-05-19 08:30:12 -07001187 device, err := client.GetDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -07001188 if err != nil {
1189 return err
1190 }
1191
Zack Williamse940c7a2019-08-21 14:25:39 -07001192 outputFormat := CharReplacer.Replace(options.Format)
1193 if outputFormat == "" {
David Bainbridgea6722342019-10-24 23:55:53 +00001194 outputFormat = GetCommandOptionWithDefault("device-inspect", "format", DEFAULT_DEVICE_INSPECT_FORMAT)
Zack Williamse940c7a2019-08-21 14:25:39 -07001195 }
1196 if options.Quiet {
1197 outputFormat = "{{.Id}}"
1198 }
1199
1200 result := CommandResult{
1201 Format: format.Format(outputFormat),
1202 OutputAs: toOutputType(options.OutputAs),
1203 NameLimit: options.NameLimit,
1204 Data: device,
1205 }
1206 GenerateOutput(&result)
1207 return nil
1208}
kesavand12cd8eb2020-01-20 22:25:22 -05001209
1210/*Device Port Enable */
1211func (options *DevicePortEnable) Execute(args []string) error {
1212 conn, err := NewConnection()
1213 if err != nil {
1214 return err
1215 }
1216 defer conn.Close()
1217
Scott Baker9173ed82020-05-19 08:30:12 -07001218 client := voltha.NewVolthaServiceClient(conn)
kesavand12cd8eb2020-01-20 22:25:22 -05001219
David K. Bainbridge9189c632021-03-26 21:52:21 +00001220 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand12cd8eb2020-01-20 22:25:22 -05001221 defer cancel()
1222
Scott Baker9173ed82020-05-19 08:30:12 -07001223 port := voltha.Port{DeviceId: string(options.Args.Id), PortNo: uint32(options.Args.PortId)}
1224
1225 _, err = client.EnablePort(ctx, &port)
kesavand12cd8eb2020-01-20 22:25:22 -05001226 if err != nil {
1227 Error.Printf("Error enabling port number %v on device Id %s,err=%s\n", options.Args.PortId, options.Args.Id, ErrorToString(err))
1228 return err
kesavand12cd8eb2020-01-20 22:25:22 -05001229 }
1230
1231 return nil
1232}
1233
Scott Baker9173ed82020-05-19 08:30:12 -07001234/*Device Port Disable */
kesavand12cd8eb2020-01-20 22:25:22 -05001235func (options *DevicePortDisable) Execute(args []string) error {
1236 conn, err := NewConnection()
1237 if err != nil {
1238 return err
1239 }
1240 defer conn.Close()
1241
Scott Baker9173ed82020-05-19 08:30:12 -07001242 client := voltha.NewVolthaServiceClient(conn)
1243
David K. Bainbridge9189c632021-03-26 21:52:21 +00001244 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand12cd8eb2020-01-20 22:25:22 -05001245 defer cancel()
1246
Scott Baker9173ed82020-05-19 08:30:12 -07001247 port := voltha.Port{DeviceId: string(options.Args.Id), PortNo: uint32(options.Args.PortId)}
1248
1249 _, err = client.DisablePort(ctx, &port)
kesavand12cd8eb2020-01-20 22:25:22 -05001250 if err != nil {
Scott Baker9173ed82020-05-19 08:30:12 -07001251 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 -05001252 return err
kesavand12cd8eb2020-01-20 22:25:22 -05001253 }
Scott Baker9173ed82020-05-19 08:30:12 -07001254
kesavand12cd8eb2020-01-20 22:25:22 -05001255 return nil
1256}
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08001257
Rohan Agrawald7df3772020-06-29 11:23:36 +00001258func (options *DevicePmConfigSetMaxSkew) Execute(args []string) error {
1259 conn, err := NewConnection()
1260 if err != nil {
1261 return err
1262 }
1263 defer conn.Close()
1264
1265 client := voltha.NewVolthaServiceClient(conn)
1266
David K. Bainbridge9189c632021-03-26 21:52:21 +00001267 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawald7df3772020-06-29 11:23:36 +00001268 defer cancel()
1269
1270 id := voltha.ID{Id: string(options.Args.Id)}
1271
1272 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1273 if err != nil {
1274 return err
1275 }
1276
1277 pmConfigs.MaxSkew = options.Args.MaxSkew
1278
1279 _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs)
1280 if err != nil {
1281 return err
1282 }
1283
1284 return nil
1285}
1286
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001287func (options *DevicePmConfigsGet) Execute(args []string) error {
1288
1289 conn, err := NewConnection()
1290 if err != nil {
1291 return err
1292 }
1293 defer conn.Close()
1294
1295 client := voltha.NewVolthaServiceClient(conn)
1296
David K. Bainbridge9189c632021-03-26 21:52:21 +00001297 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001298 defer cancel()
1299
1300 id := voltha.ID{Id: string(options.Args.Id)}
1301
1302 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1303 if err != nil {
1304 return err
1305 }
1306
1307 outputFormat := CharReplacer.Replace(options.Format)
1308 if outputFormat == "" {
1309 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GET_FORMAT)
1310 }
1311
1312 orderBy := options.OrderBy
1313 if orderBy == "" {
1314 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1315 }
1316
1317 result := CommandResult{
1318 Format: format.Format(outputFormat),
1319 Filter: options.Filter,
1320 OrderBy: orderBy,
1321 OutputAs: toOutputType(options.OutputAs),
1322 NameLimit: options.NameLimit,
1323 Data: pmConfigs,
1324 }
1325
1326 GenerateOutput(&result)
1327 return nil
1328
1329}
1330
1331func (options *DevicePmConfigMetricList) Execute(args []string) error {
1332
1333 conn, err := NewConnection()
1334 if err != nil {
1335 return err
1336 }
1337 defer conn.Close()
1338
1339 client := voltha.NewVolthaServiceClient(conn)
1340
David K. Bainbridge9189c632021-03-26 21:52:21 +00001341 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001342 defer cancel()
1343
1344 id := voltha.ID{Id: string(options.Args.Id)}
1345
1346 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1347 if err != nil {
1348 return err
1349 }
1350
1351 if !pmConfigs.Grouped {
1352 for _, metric := range pmConfigs.Metrics {
1353 if metric.SampleFreq == 0 {
1354 metric.SampleFreq = pmConfigs.DefaultFreq
1355 }
1356 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001357 outputFormat := CharReplacer.Replace(options.Format)
1358 if outputFormat == "" {
1359 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_METRIC_LIST_FORMAT)
1360 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001361
Rohan Agrawalbca69122020-06-17 14:59:03 +00001362 orderBy := options.OrderBy
1363 if orderBy == "" {
1364 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1365 }
1366
1367 result := CommandResult{
1368 Format: format.Format(outputFormat),
1369 Filter: options.Filter,
1370 OrderBy: orderBy,
1371 OutputAs: toOutputType(options.OutputAs),
1372 NameLimit: options.NameLimit,
1373 Data: pmConfigs.Metrics,
1374 }
1375
1376 GenerateOutput(&result)
1377 return nil
1378 } else {
1379 return fmt.Errorf("Device '%s' does not have Non Grouped Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001380 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001381}
1382
1383func (options *DevicePmConfigMetricEnable) Execute(args []string) error {
1384
1385 conn, err := NewConnection()
1386 if err != nil {
1387 return err
1388 }
1389 defer conn.Close()
1390
1391 client := voltha.NewVolthaServiceClient(conn)
1392
David K. Bainbridge9189c632021-03-26 21:52:21 +00001393 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001394 defer cancel()
1395
1396 id := voltha.ID{Id: string(options.Args.Id)}
1397
1398 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1399 if err != nil {
1400 return err
1401 }
1402
1403 if !pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001404 metrics := make(map[string]struct{})
1405 for _, metric := range pmConfigs.Metrics {
1406 metrics[metric.Name] = struct{}{}
1407 }
1408
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001409 for _, metric := range pmConfigs.Metrics {
1410 for _, mName := range options.Args.Metrics {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001411 if _, exist := metrics[string(mName)]; !exist {
1412 return fmt.Errorf("Metric Name '%s' does not exist", mName)
1413 }
1414
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001415 if string(mName) == metric.Name && !metric.Enabled {
1416 metric.Enabled = true
1417 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1418 if err != nil {
1419 return err
1420 }
1421 }
1422 }
1423 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001424 } else {
1425 return fmt.Errorf("Device '%s' does not have Non Grouped Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001426 }
1427 return nil
1428}
1429
1430func (options *DevicePmConfigMetricDisable) Execute(args []string) error {
1431
1432 conn, err := NewConnection()
1433 if err != nil {
1434 return err
1435 }
1436 defer conn.Close()
1437
1438 client := voltha.NewVolthaServiceClient(conn)
1439
David K. Bainbridge9189c632021-03-26 21:52:21 +00001440 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001441 defer cancel()
1442
1443 id := voltha.ID{Id: string(options.Args.Id)}
1444
1445 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1446 if err != nil {
1447 return err
1448 }
1449
1450 if !pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001451 metrics := make(map[string]struct{})
1452 for _, metric := range pmConfigs.Metrics {
1453 metrics[metric.Name] = struct{}{}
1454 }
1455
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001456 for _, metric := range pmConfigs.Metrics {
1457 for _, mName := range options.Args.Metrics {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001458 if _, have := metrics[string(mName)]; !have {
1459 return fmt.Errorf("Metric Name '%s' does not exist", mName)
1460 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001461 if string(mName) == metric.Name && metric.Enabled {
1462 metric.Enabled = false
1463 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1464 if err != nil {
1465 return err
1466 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001467 } else {
1468 return fmt.Errorf("Metric '%s' cannot be disabled", string(mName))
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001469 }
1470 }
1471 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001472 } else {
1473 return fmt.Errorf("Device '%s' does not have Non Grouped Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001474 }
1475 return nil
1476}
1477
1478func (options *DevicePmConfigGroupEnable) Execute(args []string) error {
1479
1480 conn, err := NewConnection()
1481 if err != nil {
1482 return err
1483 }
1484 defer conn.Close()
1485
1486 client := voltha.NewVolthaServiceClient(conn)
1487
David K. Bainbridge9189c632021-03-26 21:52:21 +00001488 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001489 defer cancel()
1490
1491 id := voltha.ID{Id: string(options.Args.Id)}
1492
1493 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1494 if err != nil {
1495 return err
1496 }
1497
1498 if pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001499 groups := make(map[string]struct{})
1500 for _, group := range pmConfigs.Groups {
1501 groups[group.GroupName] = struct{}{}
1502 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001503 for _, group := range pmConfigs.Groups {
Girish Gowdra610acb42021-01-27 13:33:57 -08001504 if _, have := groups[string(options.Args.Group)]; !have {
1505 return fmt.Errorf("Group Name '%s' does not exist", options.Args.Group)
1506 }
1507 if string(options.Args.Group) == group.GroupName && !group.Enabled {
1508 group.Enabled = true
1509 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1510 if err != nil {
1511 return err
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001512 }
1513 }
1514 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001515 } else {
1516 return fmt.Errorf("Device '%s' does not have Group Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001517 }
1518 return nil
1519}
1520
1521func (options *DevicePmConfigGroupDisable) Execute(args []string) error {
1522
1523 conn, err := NewConnection()
1524 if err != nil {
1525 return err
1526 }
1527 defer conn.Close()
1528
1529 client := voltha.NewVolthaServiceClient(conn)
1530
David K. Bainbridge9189c632021-03-26 21:52:21 +00001531 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001532 defer cancel()
1533
1534 id := voltha.ID{Id: string(options.Args.Id)}
1535
1536 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1537 if err != nil {
1538 return err
1539 }
1540
1541 if pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001542 groups := make(map[string]struct{})
1543 for _, group := range pmConfigs.Groups {
1544 groups[group.GroupName] = struct{}{}
1545 }
1546
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001547 for _, group := range pmConfigs.Groups {
Girish Gowdra610acb42021-01-27 13:33:57 -08001548 if _, have := groups[string(options.Args.Group)]; !have {
1549 return fmt.Errorf("Group Name '%s' does not exist", options.Args.Group)
1550 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001551
Girish Gowdra610acb42021-01-27 13:33:57 -08001552 if string(options.Args.Group) == group.GroupName && group.Enabled {
1553 group.Enabled = false
1554 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1555 if err != nil {
1556 return err
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001557 }
1558 }
1559 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001560 } else {
1561 return fmt.Errorf("Device '%s' does not have Group Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001562 }
1563 return nil
1564}
1565
Girish Gowdra610acb42021-01-27 13:33:57 -08001566func (options *DevicePmConfigGroupFrequencySet) Execute(args []string) error {
1567
1568 conn, err := NewConnection()
1569 if err != nil {
1570 return err
1571 }
1572 defer conn.Close()
1573
1574 client := voltha.NewVolthaServiceClient(conn)
1575
David K. Bainbridge9189c632021-03-26 21:52:21 +00001576 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Girish Gowdra610acb42021-01-27 13:33:57 -08001577 defer cancel()
1578
1579 id := voltha.ID{Id: string(options.Args.Id)}
1580
1581 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1582 if err != nil {
1583 return err
1584 }
1585
1586 if pmConfigs.Grouped {
1587 groups := make(map[string]struct{})
1588 for _, group := range pmConfigs.Groups {
1589 groups[group.GroupName] = struct{}{}
1590 }
1591
1592 for _, group := range pmConfigs.Groups {
1593 if _, have := groups[string(options.Args.Group)]; !have {
1594 return fmt.Errorf("group name '%s' does not exist", options.Args.Group)
1595 }
1596
1597 if string(options.Args.Group) == group.GroupName {
1598 if !group.Enabled {
1599 return fmt.Errorf("group '%s' is not enabled", options.Args.Group)
1600 }
1601 group.GroupFreq = uint32(options.Args.Interval.Seconds())
1602 _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs)
1603 if err != nil {
1604 return err
1605 }
1606 }
1607 }
1608 } else {
1609 return fmt.Errorf("device '%s' does not have group metrics", options.Args.Id)
1610 }
1611 return nil
1612}
1613
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001614func (options *DevicePmConfigGroupList) Execute(args []string) error {
1615
1616 conn, err := NewConnection()
1617 if err != nil {
1618 return err
1619 }
1620 defer conn.Close()
1621
1622 client := voltha.NewVolthaServiceClient(conn)
1623
David K. Bainbridge9189c632021-03-26 21:52:21 +00001624 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001625 defer cancel()
1626
1627 id := voltha.ID{Id: string(options.Args.Id)}
1628
1629 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1630 if err != nil {
1631 return err
1632 }
1633
1634 if pmConfigs.Grouped {
1635 for _, group := range pmConfigs.Groups {
1636 if group.GroupFreq == 0 {
1637 group.GroupFreq = pmConfigs.DefaultFreq
1638 }
1639 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001640 outputFormat := CharReplacer.Replace(options.Format)
1641 if outputFormat == "" {
1642 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GROUP_LIST_FORMAT)
1643 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001644
Rohan Agrawalbca69122020-06-17 14:59:03 +00001645 orderBy := options.OrderBy
1646 if orderBy == "" {
1647 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1648 }
1649
1650 result := CommandResult{
1651 Format: format.Format(outputFormat),
1652 Filter: options.Filter,
1653 OrderBy: orderBy,
1654 OutputAs: toOutputType(options.OutputAs),
1655 NameLimit: options.NameLimit,
1656 Data: pmConfigs.Groups,
1657 }
1658
1659 GenerateOutput(&result)
1660 } else {
1661 return fmt.Errorf("Device '%s' does not have Group Metrics", string(options.Args.Id))
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001662 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001663 return nil
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001664}
1665
1666func (options *DevicePmConfigGroupMetricList) Execute(args []string) error {
1667
1668 var metrics []*voltha.PmConfig
1669 conn, err := NewConnection()
1670 if err != nil {
1671 return err
1672 }
1673 defer conn.Close()
1674
1675 client := voltha.NewVolthaServiceClient(conn)
1676
David K. Bainbridge9189c632021-03-26 21:52:21 +00001677 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001678 defer cancel()
1679
1680 id := voltha.ID{Id: string(options.Args.Id)}
1681
1682 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1683 if err != nil {
1684 return err
1685 }
1686
1687 for _, groups := range pmConfigs.Groups {
1688
1689 if string(options.Args.Group) == groups.GroupName {
1690 for _, metric := range groups.Metrics {
1691 if metric.SampleFreq == 0 && groups.GroupFreq == 0 {
1692 metric.SampleFreq = pmConfigs.DefaultFreq
1693 } else {
1694 metric.SampleFreq = groups.GroupFreq
1695 }
1696 }
1697 metrics = groups.Metrics
1698 }
1699 }
1700
1701 outputFormat := CharReplacer.Replace(options.Format)
1702 if outputFormat == "" {
1703 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_METRIC_LIST_FORMAT)
1704 }
1705
1706 orderBy := options.OrderBy
1707 if orderBy == "" {
1708 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1709 }
1710
1711 result := CommandResult{
1712 Format: format.Format(outputFormat),
1713 Filter: options.Filter,
1714 OrderBy: orderBy,
1715 OutputAs: toOutputType(options.OutputAs),
1716 NameLimit: options.NameLimit,
1717 Data: metrics,
1718 }
1719
1720 GenerateOutput(&result)
1721 return nil
1722
1723}
1724
1725func (options *DevicePmConfigFrequencySet) Execute(args []string) error {
1726
1727 conn, err := NewConnection()
1728 if err != nil {
1729 return err
1730 }
1731 defer conn.Close()
1732
1733 client := voltha.NewVolthaServiceClient(conn)
1734
David K. Bainbridge9189c632021-03-26 21:52:21 +00001735 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001736 defer cancel()
1737
1738 id := voltha.ID{Id: string(options.Args.Id)}
1739
1740 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1741 if err != nil {
1742 return err
1743 }
1744
Girish Gowdra610acb42021-01-27 13:33:57 -08001745 pmConfigs.DefaultFreq = uint32(options.Args.Interval.Seconds())
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001746
1747 _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs)
1748 if err != nil {
1749 return err
1750 }
1751
1752 outputFormat := CharReplacer.Replace(options.Format)
1753 if outputFormat == "" {
1754 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GET_FORMAT)
1755 }
1756 if options.Quiet {
1757 outputFormat = "{{.Id}}"
1758 }
1759
1760 result := CommandResult{
1761 Format: format.Format(outputFormat),
1762 OutputAs: toOutputType(options.OutputAs),
1763 NameLimit: options.NameLimit,
1764 Data: pmConfigs,
1765 }
1766
1767 GenerateOutput(&result)
1768 return nil
1769
1770}
1771
kesavand3e2f9f62021-04-22 11:06:38 +05301772func (options *OnuDownloadImage) Execute(args []string) error {
1773
1774 conn, err := NewConnection()
1775 if err != nil {
1776 return err
1777 }
1778 defer conn.Close()
1779
1780 client := voltha.NewVolthaServiceClient(conn)
1781
1782 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1783 defer cancel()
1784
1785 var devIDList []*common.ID
1786 for _, i := range options.Args.IDs {
1787
1788 devIDList = append(devIDList, &common.ID{Id: string(i)})
1789 }
1790
1791 downloadImage := voltha.DeviceImageDownloadRequest{
1792 DeviceId: devIDList,
1793 Image: &voltha.Image{
1794 Url: options.Args.Url,
1795 Crc32: options.Args.Crc,
ssiddiqui7bc89e92021-05-20 20:58:02 +05301796 Vendor: options.Args.Vendor,
kesavand3e2f9f62021-04-22 11:06:38 +05301797 Version: options.Args.ImageVersion,
1798 },
1799 ActivateOnSuccess: options.Args.ActivateOnSuccess,
1800 CommitOnSuccess: options.Args.CommitOnSuccess,
1801 }
1802
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001803 deviceImageResp, err := client.DownloadImageToDevice(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301804 if err != nil {
1805 return err
1806 }
1807
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001808 outputFormat := GetCommandOptionWithDefault("onu-image-download", "format", ONU_IMAGE_STATUS_FORMAT)
1809 // Make sure json output prints an empty list, not "null"
1810 if deviceImageResp.DeviceImageStates == nil {
1811 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1812 }
1813 result := CommandResult{
1814 Format: format.Format(outputFormat),
1815 OutputAs: toOutputType(options.OutputAs),
1816 NameLimit: options.NameLimit,
1817 Data: deviceImageResp.DeviceImageStates,
1818 }
1819 GenerateOutput(&result)
kesavand3e2f9f62021-04-22 11:06:38 +05301820 return nil
1821
1822}
1823
1824func (options *OnuActivateImage) Execute(args []string) error {
1825
1826 conn, err := NewConnection()
1827 if err != nil {
1828 return err
1829 }
1830 defer conn.Close()
1831
1832 client := voltha.NewVolthaServiceClient(conn)
1833
1834 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1835 defer cancel()
1836
1837 var devIDList []*common.ID
1838 for _, i := range options.Args.IDs {
1839
1840 devIDList = append(devIDList, &common.ID{Id: string(i)})
1841 }
1842
1843 downloadImage := voltha.DeviceImageRequest{
1844 DeviceId: devIDList,
1845 Version: options.Args.ImageVersion,
1846 CommitOnSuccess: options.Args.CommitOnSuccess,
1847 }
1848
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001849 deviceImageResp, err := client.ActivateImage(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301850 if err != nil {
1851 return err
1852 }
1853
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001854 outputFormat := GetCommandOptionWithDefault("onu-image-activate", "format", ONU_IMAGE_STATUS_FORMAT)
1855 // Make sure json output prints an empty list, not "null"
1856 if deviceImageResp.DeviceImageStates == nil {
1857 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1858 }
1859 result := CommandResult{
1860 Format: format.Format(outputFormat),
1861 OutputAs: toOutputType(options.OutputAs),
1862 NameLimit: options.NameLimit,
1863 Data: deviceImageResp.DeviceImageStates,
1864 }
1865 GenerateOutput(&result)
1866
kesavand3e2f9f62021-04-22 11:06:38 +05301867 return nil
1868
1869}
1870
1871func (options *OnuAbortUpgradeImage) Execute(args []string) error {
1872
1873 conn, err := NewConnection()
1874 if err != nil {
1875 return err
1876 }
1877 defer conn.Close()
1878
1879 client := voltha.NewVolthaServiceClient(conn)
1880
1881 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1882 defer cancel()
1883
1884 var devIDList []*common.ID
1885 for _, i := range options.Args.IDs {
1886
1887 devIDList = append(devIDList, &common.ID{Id: string(i)})
1888 }
1889
1890 downloadImage := voltha.DeviceImageRequest{
1891 DeviceId: devIDList,
1892 Version: options.Args.ImageVersion,
1893 }
1894
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001895 deviceImageResp, err := client.AbortImageUpgradeToDevice(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301896 if err != nil {
1897 return err
1898 }
1899
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001900 outputFormat := GetCommandOptionWithDefault("onu-image-abort", "format", ONU_IMAGE_STATUS_FORMAT)
1901 // Make sure json output prints an empty list, not "null"
1902 if deviceImageResp.DeviceImageStates == nil {
1903 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1904 }
1905 result := CommandResult{
1906 Format: format.Format(outputFormat),
1907 OutputAs: toOutputType(options.OutputAs),
1908 NameLimit: options.NameLimit,
1909 Data: deviceImageResp.DeviceImageStates,
1910 }
1911 GenerateOutput(&result)
1912
kesavand3e2f9f62021-04-22 11:06:38 +05301913 return nil
1914
1915}
1916
1917func (options *OnuCommitImage) Execute(args []string) error {
1918
1919 conn, err := NewConnection()
1920 if err != nil {
1921 return err
1922 }
1923 defer conn.Close()
1924
1925 client := voltha.NewVolthaServiceClient(conn)
1926
1927 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1928 defer cancel()
1929
1930 var devIDList []*common.ID
1931 for _, i := range options.Args.IDs {
1932
1933 devIDList = append(devIDList, &common.ID{Id: string(i)})
1934 }
1935 downloadImage := voltha.DeviceImageRequest{
1936 DeviceId: devIDList,
1937 Version: options.Args.ImageVersion,
1938 }
1939
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001940 deviceImageResp, err := client.CommitImage(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301941 if err != nil {
1942 return err
1943 }
1944
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001945 outputFormat := GetCommandOptionWithDefault("onu-image-commit", "format", ONU_IMAGE_STATUS_FORMAT)
1946 // Make sure json output prints an empty list, not "null"
1947 if deviceImageResp.DeviceImageStates == nil {
1948 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1949 }
1950 result := CommandResult{
1951 Format: format.Format(outputFormat),
1952 OutputAs: toOutputType(options.OutputAs),
1953 NameLimit: options.NameLimit,
1954 Data: deviceImageResp.DeviceImageStates,
1955 }
1956 GenerateOutput(&result)
1957
kesavand3e2f9f62021-04-22 11:06:38 +05301958 return nil
1959
1960}
1961
1962func (options *OnuListImages) Execute(args []string) error {
1963
1964 conn, err := NewConnection()
1965 if err != nil {
1966 return err
1967 }
1968 defer conn.Close()
1969
1970 client := voltha.NewVolthaServiceClient(conn)
1971
1972 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1973 defer cancel()
1974
1975 id := common.ID{Id: string(options.Args.Id)}
1976
1977 onuImages, err := client.GetOnuImages(ctx, &id)
1978 if err != nil {
1979 return err
1980 }
1981
1982 outputFormat := CharReplacer.Replace(options.Format)
1983 if outputFormat == "" {
1984 outputFormat = GetCommandOptionWithDefault("onu-image-list", "format", ONU_IMAGE_LIST_FORMAT)
1985 }
1986
1987 if options.Quiet {
1988 outputFormat = "{{.Id}}"
1989 }
1990
1991 //TODO orderby
1992
1993 // Make sure json output prints an empty list, not "null"
1994 if onuImages.Items == nil {
1995 onuImages.Items = make([]*voltha.OnuImage, 0)
1996 }
1997
1998 result := CommandResult{
1999 Format: format.Format(outputFormat),
2000 OutputAs: toOutputType(options.OutputAs),
2001 NameLimit: options.NameLimit,
2002 Data: onuImages.Items,
2003 }
2004
2005 GenerateOutput(&result)
2006 return nil
2007
2008}
2009
2010func (options *OnuImageStatus) Execute(args []string) error {
2011
2012 conn, err := NewConnection()
2013 if err != nil {
2014 return err
2015 }
2016 defer conn.Close()
2017
2018 client := voltha.NewVolthaServiceClient(conn)
2019
2020 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2021 defer cancel()
2022
2023 var devIDList []*common.ID
kesavand3e2f9f62021-04-22 11:06:38 +05302024
Elia Battiston859f3e62022-02-08 15:57:52 +01002025 if options.Args.IDs == nil {
2026 //Use an empty IDs list to retrieve the status of all devices
2027 //with the requested image version
2028 devIDList = []*common.ID{}
2029 } else {
2030 for _, i := range options.Args.IDs {
2031 devIDList = append(devIDList, &common.ID{Id: string(i)})
2032 }
kesavand3e2f9f62021-04-22 11:06:38 +05302033 }
2034
2035 imageStatusReq := voltha.DeviceImageRequest{
2036 DeviceId: devIDList,
2037 Version: options.Args.ImageVersion,
2038 }
2039 imageStatus, err := client.GetImageStatus(ctx, &imageStatusReq)
2040 if err != nil {
2041 return err
2042 }
2043
2044 outputFormat := CharReplacer.Replace(options.Format)
2045 if outputFormat == "" {
2046 outputFormat = GetCommandOptionWithDefault("device-image-list", "format", ONU_IMAGE_STATUS_FORMAT)
2047 }
2048
2049 if options.Quiet {
2050 outputFormat = "{{.Id}}"
2051 }
2052
2053 //TODO orderby
2054
2055 // Make sure json output prints an empty list, not "null"
2056 if imageStatus.DeviceImageStates == nil {
2057 imageStatus.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
2058 }
2059
2060 result := CommandResult{
2061 Format: format.Format(outputFormat),
2062 OutputAs: toOutputType(options.OutputAs),
2063 NameLimit: options.NameLimit,
2064 Data: imageStatus.DeviceImageStates,
2065 }
2066
2067 GenerateOutput(&result)
2068 return nil
2069
2070}
2071
Andrea Campanella791d88b2021-01-08 13:29:00 +01002072func (options *DeviceOnuListImages) Execute(args []string) error {
2073
2074 conn, err := NewConnection()
2075 if err != nil {
2076 return err
2077 }
2078 defer conn.Close()
2079
2080 client := voltha.NewVolthaServiceClient(conn)
2081
David K. Bainbridge9189c632021-03-26 21:52:21 +00002082 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Andrea Campanella791d88b2021-01-08 13:29:00 +01002083 defer cancel()
2084
2085 id := common.ID{Id: string(options.Args.Id)}
2086
2087 imageDownloads, err := client.ListImageDownloads(ctx, &id)
2088 if err != nil {
2089 return err
2090 }
2091
2092 outputFormat := CharReplacer.Replace(options.Format)
2093 if outputFormat == "" {
2094 outputFormat = GetCommandOptionWithDefault("device-image-list", "format", DEFAULT_DEVICE_IMAGE_LIST_GET_FORMAT)
2095 }
2096
2097 if options.Quiet {
2098 outputFormat = "{{.Id}}"
2099 }
2100
2101 //TODO orderby
2102
2103 // Make sure json output prints an empty list, not "null"
2104 if imageDownloads.Items == nil {
2105 imageDownloads.Items = make([]*voltha.ImageDownload, 0)
2106 }
2107
2108 result := CommandResult{
2109 Format: format.Format(outputFormat),
2110 OutputAs: toOutputType(options.OutputAs),
2111 NameLimit: options.NameLimit,
2112 Data: imageDownloads.Items,
2113 }
2114
2115 GenerateOutput(&result)
2116 return nil
2117
2118}
2119
2120func (options *DeviceOnuDownloadImage) Execute(args []string) error {
2121
2122 conn, err := NewConnection()
2123 if err != nil {
2124 return err
2125 }
2126 defer conn.Close()
2127
2128 client := voltha.NewVolthaServiceClient(conn)
2129
David K. Bainbridge9189c632021-03-26 21:52:21 +00002130 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Andrea Campanella791d88b2021-01-08 13:29:00 +01002131 defer cancel()
2132
2133 downloadImage := voltha.ImageDownload{
2134 Id: string(options.Args.Id),
2135 Name: options.Args.Name,
2136 Url: options.Args.Url,
2137 Crc: options.Args.Crc,
2138 LocalDir: options.Args.LocalDir,
2139 }
2140
2141 _, err = client.DownloadImage(ctx, &downloadImage)
2142 if err != nil {
2143 return err
2144 }
2145
2146 return nil
2147
2148}
2149
2150func (options *DeviceOnuActivateImageUpdate) Execute(args []string) error {
2151
2152 conn, err := NewConnection()
2153 if err != nil {
2154 return err
2155 }
2156 defer conn.Close()
2157
2158 client := voltha.NewVolthaServiceClient(conn)
2159
David K. Bainbridge9189c632021-03-26 21:52:21 +00002160 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Andrea Campanella791d88b2021-01-08 13:29:00 +01002161 defer cancel()
2162
2163 downloadImage := voltha.ImageDownload{
2164 Id: string(options.Args.Id),
2165 Name: options.Args.Name,
2166 ImageVersion: options.Args.ImageVersion,
2167 SaveConfig: options.Args.SaveConfig,
2168 LocalDir: options.Args.LocalDir,
2169 }
2170
2171 _, err = client.ActivateImageUpdate(ctx, &downloadImage)
2172 if err != nil {
2173 return err
2174 }
2175
2176 return nil
2177
2178}
2179
Scott Baker9173ed82020-05-19 08:30:12 -07002180type ReturnValueRow struct {
2181 Name string `json:"name"`
2182 Result interface{} `json:"result"`
2183}
2184
kesavand8ec4fc02021-01-27 09:10:22 -05002185func (options *DeviceGetPortStats) Execute(args []string) error {
2186 conn, err := NewConnection()
2187 if err != nil {
2188 return err
2189 }
2190 defer conn.Close()
2191 client := extension.NewExtensionClient(conn)
2192 var portType extension.GetOltPortCounters_PortType
2193
2194 if options.Args.PortType == "pon" {
2195 portType = extension.GetOltPortCounters_Port_PON_OLT
2196 } else if options.Args.PortType == "nni" {
2197
2198 portType = extension.GetOltPortCounters_Port_ETHERNET_NNI
2199 } else {
2200 return fmt.Errorf("expected interface type pon/nni, provided %s", options.Args.PortType)
2201 }
2202
2203 singleGetValReq := extension.SingleGetValueRequest{
2204 TargetId: string(options.Args.Id),
2205 Request: &extension.GetValueRequest{
2206 Request: &extension.GetValueRequest_OltPortInfo{
2207 OltPortInfo: &extension.GetOltPortCounters{
2208 PortNo: options.Args.PortNo,
2209 PortType: portType,
2210 },
2211 },
2212 },
2213 }
2214
David K. Bainbridge9189c632021-03-26 21:52:21 +00002215 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand8ec4fc02021-01-27 09:10:22 -05002216 defer cancel()
2217 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2218 if err != nil {
2219 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2220 return err
2221 }
2222
2223 if rv.Response.Status != extension.GetValueResponse_OK {
2224 return fmt.Errorf("failed to get port stats %v", rv.Response.ErrReason.String())
2225 }
2226
2227 outputFormat := CharReplacer.Replace(options.Format)
2228 if outputFormat == "" {
2229 outputFormat = GetCommandOptionWithDefault("device-get-port-status", "format", DEFAULT_DEVICE_GET_PORT_STATUS_FORMAT)
2230 }
2231
2232 result := CommandResult{
2233 Format: format.Format(outputFormat),
2234 OutputAs: toOutputType(options.OutputAs),
2235 NameLimit: options.NameLimit,
2236 Data: rv.GetResponse().GetPortCoutners(),
2237 }
2238 GenerateOutput(&result)
2239 return nil
2240}
2241
Himani Chawla40acc122021-05-26 18:52:29 +05302242func (options *GetOnuStats) Execute(args []string) error {
2243 conn, err := NewConnection()
2244 if err != nil {
2245 return err
2246 }
2247 defer conn.Close()
2248 client := extension.NewExtensionClient(conn)
2249
2250 singleGetValReq := extension.SingleGetValueRequest{
2251 TargetId: string(options.Args.OltId),
2252 Request: &extension.GetValueRequest{
2253 Request: &extension.GetValueRequest_OnuPonInfo{
2254 OnuPonInfo: &extension.GetOnuCountersRequest{
2255 IntfId: options.Args.IntfId,
2256 OnuId: options.Args.OnuId,
2257 },
2258 },
2259 },
2260 }
2261 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2262 defer cancel()
2263 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2264 if err != nil {
2265 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.OltId, ErrorToString(err))
2266 return err
2267 }
2268
2269 if rv.Response.Status != extension.GetValueResponse_OK {
2270 return fmt.Errorf("failed to get onu stats %v", rv.Response.ErrReason.String())
2271 }
2272 outputFormat := CharReplacer.Replace(options.Format)
2273 data, formatStr := buildOnuStatsOutputFormat(rv.GetResponse().GetOnuPonCounters())
2274 if outputFormat == "" {
2275 outputFormat = GetCommandOptionWithDefault("device-get-onu-status", "format", formatStr)
2276 }
Himani Chawla553a1392021-06-10 23:39:17 +05302277 result := CommandResult{
2278 Format: format.Format(outputFormat),
2279 OutputAs: toOutputType(options.OutputAs),
2280 NameLimit: options.NameLimit,
2281 Data: data,
2282 }
2283 GenerateOutput(&result)
2284 return nil
2285}
Himani Chawla40acc122021-05-26 18:52:29 +05302286
Akash Soni6e879c22024-12-20 17:01:34 +05302287func (options *GetOffloadApp) Execute(args []string) error {
Akash Soni51b6b7a2024-11-20 11:39:38 +05302288 // Establish a connection to the gRPC server
2289 conn, err := NewConnection()
2290 if err != nil {
2291 return err
2292 }
2293 defer conn.Close()
2294
2295 client := extension.NewExtensionClient(conn)
2296
2297 // Build the request
2298 singleGetValReq := &extension.SingleGetValueRequest{
2299 TargetId: string(options.Args.OltId),
2300 Request: &extension.GetValueRequest{
2301 Request: &extension.GetValueRequest_OffloadedAppsStats{
2302 OffloadedAppsStats: &extension.GetOffloadedAppsStatisticsRequest{
2303 StatsFor: options.Args.StatsFor,
2304 },
2305 },
2306 },
2307 }
2308
2309 // Set a context with timeout
2310 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2311 defer cancel()
2312
2313 // Perform the gRPC call
2314 rv, err := client.GetExtValue(ctx, singleGetValReq)
2315 if err != nil {
2316 Error.Printf("Error getting value for device ID %s, err=%s\n", options.Args.OltId, ErrorToString(err))
2317 return err
2318 }
2319
2320 // Check response status
2321 if rv.GetResponse().GetStatus() != extension.GetValueResponse_OK {
2322 return fmt.Errorf("failed to get offloaded app stats: %v", rv.GetResponse().GetErrReason().String())
2323 }
2324
2325 // Process the response data
2326 stats, formatStr := buildOffloadAppStatsOutputFormat(rv.GetResponse().GetOffloadedAppsStats())
2327 outputFormat := CharReplacer.Replace(options.Format)
2328 if outputFormat == "" {
2329 outputFormat = GetCommandOptionWithDefault("device-get-offload-app-stats", "format", formatStr)
2330 }
2331
2332 // Generate and display the output
2333 result := CommandResult{
2334 Format: format.Format(outputFormat),
2335 OutputAs: toOutputType(options.OutputAs),
2336 NameLimit: options.NameLimit,
2337 Data: stats,
2338 }
2339 GenerateOutput(&result)
2340
2341 return nil
2342}
2343
Akash Soni6e879c22024-12-20 17:01:34 +05302344func (options *SetOffloadApp) Execute(args []string) error {
Akash Soni51b6b7a2024-11-20 11:39:38 +05302345 conn, err := NewConnection()
2346 if err != nil {
Akash Soni6e879c22024-12-20 17:01:34 +05302347 return fmt.Errorf("failed to establish gRPC connection: %w", err)
Akash Soni51b6b7a2024-11-20 11:39:38 +05302348 }
2349 defer conn.Close()
2350
2351 client := extension.NewExtensionClient(conn)
2352
Akash Soni6e879c22024-12-20 17:01:34 +05302353 // Parse JSON input
2354 var config extension.AppOffloadConfig
2355 if err := json.Unmarshal([]byte(options.Args.Config), &config); err != nil {
2356 return fmt.Errorf("failed to parse CONFIG as JSON: %w", err)
2357 }
2358
Akash Soni51b6b7a2024-11-20 11:39:38 +05302359 setValueRequest := &extension.SetValueRequest{
2360 Request: &extension.SetValueRequest_AppOffloadConfig{
Akash Soni6e879c22024-12-20 17:01:34 +05302361 AppOffloadConfig: &config,
Akash Soni51b6b7a2024-11-20 11:39:38 +05302362 },
2363 }
2364
2365 singleSetValReq := &extension.SingleSetValueRequest{
2366 TargetId: string(options.Args.OltId),
2367 Request: setValueRequest,
2368 }
2369
Akash Soni6e879c22024-12-20 17:01:34 +05302370 // Log the request object
2371 logRequestAppOffloadConfig(singleSetValReq)
2372
Akash Soni51b6b7a2024-11-20 11:39:38 +05302373 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2374 defer cancel()
2375
2376 resp, err := client.SetExtValue(ctx, singleSetValReq)
2377 if err != nil {
Akash Soni6e879c22024-12-20 17:01:34 +05302378 return fmt.Errorf("failed to set AppOffloadConfig: %w", err)
Akash Soni51b6b7a2024-11-20 11:39:38 +05302379 }
2380
2381 if resp.Response.Status != extension.SetValueResponse_OK {
Akash Soni6e879c22024-12-20 17:01:34 +05302382 return fmt.Errorf("operation failed with status %v: %s", resp.Response.Status, resp.Response.ErrReason)
Akash Soni51b6b7a2024-11-20 11:39:38 +05302383 }
2384
2385 fmt.Printf("AppOffloadConfig successfully set for OLT ID: %s\n", options.Args.OltId)
2386 return nil
2387}
2388
Akash Soni6e879c22024-12-20 17:01:34 +05302389func logRequestAppOffloadConfig(req *extension.SingleSetValueRequest) {
2390 fmt.Printf("Request details:\n")
2391 fmt.Printf("TargetId: %s\n", req.TargetId)
2392 if config, ok := req.Request.Request.(*extension.SetValueRequest_AppOffloadConfig); ok {
2393 fmt.Printf("AppOffloadConfig:\n")
2394 fmt.Printf(" EnableDHCPv4RA: %t\n", config.AppOffloadConfig.EnableDHCPv4RA)
2395 fmt.Printf(" EnableDHCPv6RA: %t\n", config.AppOffloadConfig.EnableDHCPv6RA)
2396 fmt.Printf(" EnablePPPoEIA: %t\n", config.AppOffloadConfig.EnablePPPoEIA)
2397 fmt.Printf(" AccessNodeID: %s\n", config.AppOffloadConfig.AccessNodeID)
2398 }
2399}
2400
2401func (options *SetOnuOffload) Execute(args []string) error {
2402 // Create the gRPC client connection
Akash Soni51b6b7a2024-11-20 11:39:38 +05302403 conn, err := NewConnection()
2404 if err != nil {
2405 return fmt.Errorf("failed to establish gRPC connection: %v", err)
2406 }
2407 defer conn.Close()
2408
2409 client := extension.NewExtensionClient(conn)
2410
Akash Soni6e879c22024-12-20 17:01:34 +05302411 // Parse PerUniInfo into a slice of PerUniConfig
2412 var perUniConfigs []AppOffloadOnuConfig
2413 if err := json.Unmarshal([]byte(options.Args.PerUniInfo), &perUniConfigs); err != nil {
2414 return fmt.Errorf("failed to parse PerUniInfo as JSON: %v", err)
Akash Soni51b6b7a2024-11-20 11:39:38 +05302415 }
Akash Soni6e879c22024-12-20 17:01:34 +05302416
2417 // Convert to []*AppOffloadOnuConfig_PerUniConfig for gRPC
2418 var grpcPerUniInfo []*extension.AppOffloadOnuConfig_PerUniConfig
2419 for _, config := range perUniConfigs {
2420 grpcPerUniInfo = append(grpcPerUniInfo, &extension.AppOffloadOnuConfig_PerUniConfig{
2421 AgentRemoteID: config.AgentRemoteID,
2422 AgentCircuitID: config.AgentCircuitID,
2423 OnuUniId: config.OnuUniId,
2424 })
2425 }
2426
Akash Soni51b6b7a2024-11-20 11:39:38 +05302427 // Build the AppOffloadOnuConfig request
2428 onuConfig := &extension.AppOffloadOnuConfig{
2429 OnuDeviceId: options.Args.OnuDeviceId,
Akash Soni6e879c22024-12-20 17:01:34 +05302430 PerUniInfo: grpcPerUniInfo,
Akash Soni51b6b7a2024-11-20 11:39:38 +05302431 }
2432
2433 setValueRequest := &extension.SetValueRequest{
2434 Request: &extension.SetValueRequest_AppOffloadOnuConfig{
2435 AppOffloadOnuConfig: onuConfig,
2436 },
2437 }
2438
2439 singleSetValReq := &extension.SingleSetValueRequest{
Akash Soni6e879c22024-12-20 17:01:34 +05302440 TargetId: string(options.Args.OltId),
Akash Soni51b6b7a2024-11-20 11:39:38 +05302441 Request: setValueRequest,
2442 }
2443
Akash Soni6e879c22024-12-20 17:01:34 +05302444 // Log the request object
2445 logRequestAppOffloadOnuConfig(singleSetValReq)
2446
2447 // Make the gRPC call
Akash Soni51b6b7a2024-11-20 11:39:38 +05302448 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2449 defer cancel()
2450
2451 resp, err := client.SetExtValue(ctx, singleSetValReq)
2452 if err != nil {
2453 return fmt.Errorf("failed to set AppOffloadOnuConfig: %v", err)
2454 }
2455
2456 if resp.Response.Status != extension.SetValueResponse_OK {
Akash Soni6e879c22024-12-20 17:01:34 +05302457 return fmt.Errorf("operation failed with status %v: %s", resp.Response.Status, resp.Response.ErrReason)
Akash Soni51b6b7a2024-11-20 11:39:38 +05302458 }
2459
2460 fmt.Printf("AppOffloadOnuConfig successfully set for ONU ID: %s\n", options.Args.OnuDeviceId)
2461 return nil
2462}
2463
Akash Soni6e879c22024-12-20 17:01:34 +05302464// Debugging helper to log the gRPC request details
2465func logRequestAppOffloadOnuConfig(req *extension.SingleSetValueRequest) {
2466 fmt.Printf("Request details:\n")
2467 fmt.Printf("TargetId: %s\n", req.TargetId)
2468 fmt.Printf("OnuDeviceId: %s\n", req.Request.GetAppOffloadOnuConfig().OnuDeviceId)
2469 if config, ok := req.Request.Request.(*extension.SetValueRequest_AppOffloadOnuConfig); ok {
2470 fmt.Printf("AppOffloadOnuConfig:\n")
2471 for i, uniInfo := range config.AppOffloadOnuConfig.PerUniInfo {
2472 fmt.Printf(" UniInfo %d:\n", i+1)
2473 fmt.Printf(" AgentRemoteID: %s\n", uniInfo.AgentRemoteID)
2474 fmt.Printf(" AgentCircuitID: %s\n", uniInfo.AgentCircuitID)
2475 fmt.Printf(" OnuUniId: %d\n", uniInfo.OnuUniId)
2476 }
2477 }
2478}
2479
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +05302480func (options *GetPonPortStats) Execute(args []string) error {
2481 conn, err := NewConnection()
2482 if err != nil {
2483 return err
2484 }
2485 defer conn.Close()
2486 client := extension.NewExtensionClient(conn)
2487
2488 singleGetValReq := extension.SingleGetValueRequest{
2489 TargetId: string(options.Args.Id),
2490 Request: &extension.GetValueRequest{
2491 Request: &extension.GetValueRequest_OltPonStats{
2492 OltPonStats: &extension.GetPonStatsRequest{
2493 PortInfo: &extension.GetPonStatsRequest_PortLabel{
2494 PortLabel: options.Args.PortLabel,
2495 },
2496 },
2497 },
2498 },
2499 }
2500 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2501 defer cancel()
2502 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2503 if err != nil {
2504 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2505 return err
2506 }
2507
2508 if rv.Response.Status != extension.GetValueResponse_OK {
2509 return fmt.Errorf("failed to get pon port stats %v", rv.Response.ErrReason.String())
2510 }
2511 outputFormat := CharReplacer.Replace(options.Format)
2512 if outputFormat == "" {
2513 outputFormat = GetCommandOptionWithDefault("device-get-pon-stats", "format", DEFAULT_PON_PORT_STATS_FORMAT)
2514 }
2515 data := PortStats{
2516 PonPort: rv.GetResponse().GetOltPonStatsResponse().GetPonPort(),
2517 PortStatistics: rv.GetResponse().GetOltPonStatsResponse().GetPortStatistics(),
2518 }
2519 result := CommandResult{
2520 Format: format.Format(outputFormat),
2521 OutputAs: toOutputType(options.OutputAs),
2522 NameLimit: options.NameLimit,
2523 Data: data,
2524 }
2525 GenerateOutput(&result)
2526 return nil
2527}
2528
2529func (options *GetNniPortStats) Execute(args []string) error {
2530 conn, err := NewConnection()
2531 if err != nil {
2532 return err
2533 }
2534 defer conn.Close()
2535 client := extension.NewExtensionClient(conn)
2536
2537 singleGetValReq := extension.SingleGetValueRequest{
2538 TargetId: string(options.Args.Id),
2539 Request: &extension.GetValueRequest{
2540 Request: &extension.GetValueRequest_OltNniStats{
2541 OltNniStats: &extension.GetNNIStatsRequest{
2542 PortInfo: &extension.GetNNIStatsRequest_PortLabel{
2543 PortLabel: options.Args.PortLabel,
2544 },
2545 },
2546 },
2547 },
2548 }
2549 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2550 defer cancel()
2551 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2552 if err != nil {
2553 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2554 return err
2555 }
2556
2557 if rv.Response.Status != extension.GetValueResponse_OK {
2558 return fmt.Errorf("failed to get nni port stats %v", rv.Response.ErrReason.String())
2559 }
2560 outputFormat := CharReplacer.Replace(options.Format)
2561 if outputFormat == "" {
2562 outputFormat = GetCommandOptionWithDefault("device-get-nni-stats", "format", DEFAULT_NNI_PORT_STATS_FORMAT)
2563 }
2564 data := PortStats{
2565 NniPort: rv.GetResponse().GetOltNniStatsResponse().GetNniPort(),
2566 PortStatistics: rv.GetResponse().GetOltNniStatsResponse().GetPortStatistics(),
2567 }
2568 result := CommandResult{
2569 Format: format.Format(outputFormat),
2570 OutputAs: toOutputType(options.OutputAs),
2571 NameLimit: options.NameLimit,
2572 Data: data,
2573 }
2574 GenerateOutput(&result)
2575 return nil
2576}
2577
Himani Chawla553a1392021-06-10 23:39:17 +05302578func (options *GetOnuEthernetFrameExtendedPmCounters) Execute(args []string) error {
2579 conn, err := NewConnection()
2580 if err != nil {
2581 return err
2582 }
2583 defer conn.Close()
2584 client := extension.NewExtensionClient(conn)
Himani Chawla806aa892021-08-30 15:51:46 +05302585 var singleGetValReq extension.SingleGetValueRequest
Himani Chawla553a1392021-06-10 23:39:17 +05302586
Himani Chawla806aa892021-08-30 15:51:46 +05302587 if options.Args.UniIndex != nil {
2588 singleGetValReq = extension.SingleGetValueRequest{
2589 TargetId: string(options.Args.Id),
2590 Request: &extension.GetValueRequest{
2591 Request: &extension.GetValueRequest_OnuInfo{
2592 OnuInfo: &extension.GetOmciEthernetFrameExtendedPmRequest{
2593 OnuDeviceId: string(options.Args.Id),
2594 Reset_: options.Reset,
2595 IsUniIndex: &extension.GetOmciEthernetFrameExtendedPmRequest_UniIndex{
2596 UniIndex: *options.Args.UniIndex,
2597 },
2598 },
Himani Chawla553a1392021-06-10 23:39:17 +05302599 },
2600 },
Himani Chawla806aa892021-08-30 15:51:46 +05302601 }
2602 } else {
2603 singleGetValReq = extension.SingleGetValueRequest{
2604 TargetId: string(options.Args.Id),
2605 Request: &extension.GetValueRequest{
2606 Request: &extension.GetValueRequest_OnuInfo{
2607 OnuInfo: &extension.GetOmciEthernetFrameExtendedPmRequest{
2608 OnuDeviceId: string(options.Args.Id),
2609 Reset_: options.Reset,
2610 },
2611 },
2612 },
2613 }
Himani Chawla553a1392021-06-10 23:39:17 +05302614 }
Himani Chawla806aa892021-08-30 15:51:46 +05302615
Himani Chawla553a1392021-06-10 23:39:17 +05302616 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2617 defer cancel()
2618 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2619 if err != nil {
2620 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2621 return err
2622 }
2623
2624 if rv.Response.Status != extension.GetValueResponse_OK {
2625 return fmt.Errorf("failed to get ethernet frame extended pm counters %v", rv.Response.ErrReason.String())
2626 }
2627 outputFormat := CharReplacer.Replace(options.Format)
2628 data := buildOnuEthernetFrameExtendedPmOutputFormat(rv.GetResponse().GetOnuCounters())
2629 if outputFormat == "" {
2630 outputFormat = GetCommandOptionWithDefault("device-get-onu-status", "format", DEFAULT_ETHERNET_FRAME_EXTENDED_PM_COUNTERS_FORMAT)
2631 }
Himani Chawla40acc122021-05-26 18:52:29 +05302632 result := CommandResult{
2633 Format: format.Format(outputFormat),
2634 OutputAs: toOutputType(options.OutputAs),
2635 NameLimit: options.NameLimit,
2636 Data: data,
2637 }
2638 GenerateOutput(&result)
2639 return nil
2640}
2641
kesavand6d1131f2021-02-05 22:38:15 +05302642func (options *UniStatus) Execute(args []string) error {
2643 conn, err := NewConnection()
2644 if err != nil {
2645 return err
2646 }
2647 defer conn.Close()
2648 client := extension.NewExtensionClient(conn)
2649
2650 singleGetValReq := extension.SingleGetValueRequest{
2651 TargetId: string(options.Args.Id),
2652 Request: &extension.GetValueRequest{
2653 Request: &extension.GetValueRequest_UniInfo{
2654 UniInfo: &extension.GetOnuUniInfoRequest{
2655 UniIndex: options.Args.UniIndex,
2656 },
2657 },
2658 },
2659 }
David K. Bainbridge9189c632021-03-26 21:52:21 +00002660 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand6d1131f2021-02-05 22:38:15 +05302661 defer cancel()
2662 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2663 if err != nil {
2664 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2665 return err
2666 }
2667 if rv.Response.Status != extension.GetValueResponse_OK {
2668 return fmt.Errorf("failed to get uni status %v", rv.Response.ErrReason.String())
2669 }
2670 outputFormat := CharReplacer.Replace(options.Format)
2671 if outputFormat == "" {
2672 outputFormat = GetCommandOptionWithDefault("device-get-uni-status", "format", DEFAULT_DEVICE_GET_UNI_STATUS_FORMAT)
2673 }
2674 result := CommandResult{
2675 Format: format.Format(outputFormat),
2676 OutputAs: toOutputType(options.OutputAs),
2677 NameLimit: options.NameLimit,
2678 Data: rv.GetResponse().GetUniInfo(),
2679 }
2680 GenerateOutput(&result)
2681 return nil
2682}
2683
Girish Gowdra4f5ce7c2021-04-29 18:53:21 -07002684func (options *OnuPonOpticalInfo) Execute(args []string) error {
2685 conn, err := NewConnection()
2686 if err != nil {
2687 return err
2688 }
2689 defer conn.Close()
2690 client := extension.NewExtensionClient(conn)
2691
2692 singleGetValReq := extension.SingleGetValueRequest{
2693 TargetId: string(options.Args.Id),
2694 Request: &extension.GetValueRequest{
2695 Request: &extension.GetValueRequest_OnuOpticalInfo{
2696 OnuOpticalInfo: &extension.GetOnuPonOpticalInfo{},
2697 },
2698 },
2699 }
2700 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2701 defer cancel()
2702 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2703 if err != nil {
2704 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2705 return err
2706 }
2707 if rv.Response.Status != extension.GetValueResponse_OK {
2708 return fmt.Errorf("failed to get onu pon optical info %v", rv.Response.ErrReason.String())
2709 }
2710 outputFormat := CharReplacer.Replace(options.Format)
2711 if outputFormat == "" {
2712 outputFormat = GetCommandOptionWithDefault("device-get-onu-pon-optical-info", "format", DEFAULT_ONU_PON_OPTICAL_INFO_STATUS_FORMAT)
2713 }
2714 result := CommandResult{
2715 Format: format.Format(outputFormat),
2716 OutputAs: toOutputType(options.OutputAs),
2717 NameLimit: options.NameLimit,
2718 Data: rv.GetResponse().GetOnuOpticalInfo(),
2719 }
2720 GenerateOutput(&result)
2721 return nil
2722}
2723
Gamze Abakac857a462021-05-26 13:45:54 +00002724func (options *RxPower) Execute(args []string) error {
2725 conn, err := NewConnection()
2726 if err != nil {
2727 return err
2728 }
2729 defer conn.Close()
2730 client := extension.NewExtensionClient(conn)
2731
2732 singleGetValReq := extension.SingleGetValueRequest{
2733 TargetId: string(options.Args.Id),
2734 Request: &extension.GetValueRequest{
2735 Request: &extension.GetValueRequest_RxPower{
2736 RxPower: &extension.GetRxPowerRequest{
2737 IntfId: options.Args.PortNo,
2738 OnuId: options.Args.OnuNo,
2739 },
2740 },
2741 },
2742 }
2743
2744 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2745 defer cancel()
2746 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2747 if err != nil {
2748 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2749 return err
2750 }
2751 if rv.Response.Status != extension.GetValueResponse_OK {
2752 return fmt.Errorf("failed to get rx power %v", rv.Response.ErrReason.String())
2753 }
2754 outputFormat := CharReplacer.Replace(options.Format)
2755 if outputFormat == "" {
2756 outputFormat = GetCommandOptionWithDefault("device-get-rx-power", "format", DEFAULT_RX_POWER_STATUS_FORMAT)
2757 }
2758 result := CommandResult{
2759 Format: format.Format(outputFormat),
2760 OutputAs: toOutputType(options.OutputAs),
2761 NameLimit: options.NameLimit,
2762 Data: rv.GetResponse().GetRxPower(),
2763 }
2764 GenerateOutput(&result)
2765 return nil
2766}
2767
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002768/*Device get Onu Distance */
2769func (options *DeviceGetExtValue) Execute(args []string) error {
2770 conn, err := NewConnection()
2771 if err != nil {
2772 return err
2773 }
2774 defer conn.Close()
2775
Scott Baker9173ed82020-05-19 08:30:12 -07002776 client := voltha.NewVolthaServiceClient(conn)
2777
khenaidoo080ce882021-10-19 17:35:08 -04002778 valueflag, okay := extension.ValueType_Type_value[string(options.Args.Valueflag)]
Scott Baker9173ed82020-05-19 08:30:12 -07002779 if !okay {
2780 Error.Printf("Unknown valueflag %s\n", options.Args.Valueflag)
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002781 }
2782
khenaidoo080ce882021-10-19 17:35:08 -04002783 val := extension.ValueSpecifier{Id: string(options.Args.Id), Value: extension.ValueType_Type(valueflag)}
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002784
David K. Bainbridge9189c632021-03-26 21:52:21 +00002785 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002786 defer cancel()
2787
Scott Baker9173ed82020-05-19 08:30:12 -07002788 rv, err := client.GetExtValue(ctx, &val)
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002789 if err != nil {
2790 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2791 return err
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002792 }
2793
Scott Baker9173ed82020-05-19 08:30:12 -07002794 var rows []ReturnValueRow
khenaidoo080ce882021-10-19 17:35:08 -04002795 for name, num := range extension.ValueType_Type_value {
Scott Baker9173ed82020-05-19 08:30:12 -07002796 if num == 0 {
2797 // EMPTY is not a real value
2798 continue
2799 }
2800 if (rv.Error & uint32(num)) != 0 {
2801 row := ReturnValueRow{Name: name, Result: "Error"}
2802 rows = append(rows, row)
2803 }
2804 if (rv.Unsupported & uint32(num)) != 0 {
2805 row := ReturnValueRow{Name: name, Result: "Unsupported"}
2806 rows = append(rows, row)
2807 }
2808 if (rv.Set & uint32(num)) != 0 {
2809 switch name {
2810 case "DISTANCE":
2811 row := ReturnValueRow{Name: name, Result: rv.Distance}
2812 rows = append(rows, row)
2813 default:
2814 row := ReturnValueRow{Name: name, Result: "Unimplemented-in-voltctl"}
2815 rows = append(rows, row)
2816 }
2817 }
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002818 }
2819
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002820 outputFormat := CharReplacer.Replace(options.Format)
2821 if outputFormat == "" {
2822 outputFormat = GetCommandOptionWithDefault("device-value-get", "format", DEFAULT_DEVICE_VALUE_GET_FORMAT)
2823 }
2824
2825 result := CommandResult{
2826 Format: format.Format(outputFormat),
2827 OutputAs: toOutputType(options.OutputAs),
2828 NameLimit: options.NameLimit,
Scott Baker9173ed82020-05-19 08:30:12 -07002829 Data: rows,
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002830 }
2831 GenerateOutput(&result)
2832 return nil
2833}
serkantul3d22fc72022-09-14 12:22:56 +03002834
2835/*Device get Onu OMCI TX RX Stats */
2836func (options *OnuOmciTxRxStats) Execute(args []string) error {
2837 conn, err := NewConnection()
2838 if err != nil {
2839 return err
2840 }
2841 defer conn.Close()
2842 client := extension.NewExtensionClient(conn)
2843
2844 singleGetValReq := extension.SingleGetValueRequest{
2845 TargetId: string(options.Args.Id),
2846 Request: &extension.GetValueRequest{
2847 Request: &extension.GetValueRequest_OnuOmciStats{
2848 OnuOmciStats: &extension.GetOnuOmciTxRxStatsRequest{},
2849 },
2850 },
2851 }
2852
2853 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2854 defer cancel()
2855 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2856 if err != nil {
2857 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2858 return err
2859 }
2860
2861 if rv.Response.Status != extension.GetValueResponse_OK {
2862 return fmt.Errorf("failed to get onu omci tx rx stats %v", rv.Response.ErrReason.String())
2863 }
2864 outputFormat := CharReplacer.Replace(options.Format)
2865 if outputFormat == "" {
2866 outputFormat = GetCommandOptionWithDefault("device-get-onu-omci-tx-rx-stats", "format", DEFAULT_ONU_OMCI_TX_RX_STATS_FORMAT)
2867 }
2868 result := CommandResult{
2869 Format: format.Format(outputFormat),
2870 OutputAs: toOutputType(options.OutputAs),
2871 NameLimit: options.NameLimit,
2872 Data: rv.GetResponse().GetOnuOmciStats(),
2873 }
2874 GenerateOutput(&result)
2875 return nil
2876}
praneeth nalmas1dd094c2022-12-22 14:15:13 +05302877
2878/*Device get Onu Active Alarms */
2879func (options *GetOnuOmciActiveAlarms) Execute(args []string) error {
2880 conn, err := NewConnection()
2881 if err != nil {
2882 return err
2883 }
2884 defer conn.Close()
2885 client := extension.NewExtensionClient(conn)
2886
2887 singleGetValReq := extension.SingleGetValueRequest{
2888 TargetId: string(options.Args.Id),
2889 Request: &extension.GetValueRequest{
2890 Request: &extension.GetValueRequest_OnuActiveAlarms{
2891 OnuActiveAlarms: &extension.GetOnuOmciActiveAlarmsRequest{},
2892 },
2893 },
2894 }
2895 Info.Printf("Getting omci_active_alarms for device Id %s\n", options.Args.Id)
2896 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2897 defer cancel()
2898 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2899 if err != nil {
2900 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2901 return err
2902 }
2903
2904 if rv.Response.Status != extension.GetValueResponse_OK {
2905 return fmt.Errorf("failed to get onu omci active alarms list %v", rv.Response.ErrReason.String())
2906 }
2907 outputFormat := CharReplacer.Replace(options.Format)
2908 if outputFormat == "" {
2909 outputFormat = GetCommandOptionWithDefault("device-get-onu-omci-active-alarms", "format", DEFAULT_DEVICE_ALARMS_FORMAT)
2910 }
2911
2912 orderBy := options.OrderBy
2913 if orderBy == "" {
2914 orderBy = GetCommandOptionWithDefault("device-list", "order", DEFAULT_DEVICE_ALARMS_ORDER)
2915 }
2916
2917 result := CommandResult{
2918 Format: format.Format(outputFormat),
2919 OutputAs: toOutputType(options.OutputAs),
2920 OrderBy: orderBy,
2921 NameLimit: options.NameLimit,
2922 Data: rv.GetResponse().GetOnuActiveAlarms().GetActiveAlarms(),
2923 }
2924 GenerateOutput(&result)
2925 return nil
2926}
praneeth nalmas39c71ad2023-09-27 18:29:04 +05302927
Akash Soni66db9632024-04-15 09:05:15 +05302928/*Device get Onu Active Alarms */
2929func (options *GetOnuDistance) Execute(args []string) error {
2930 conn, err := NewConnection()
2931 if err != nil {
2932 return err
2933 }
2934 defer conn.Close()
2935 client := extension.NewExtensionClient(conn)
2936
2937 singleGetValReq := extension.SingleGetValueRequest{
2938 TargetId: string(options.Args.Id),
2939 Request: &extension.GetValueRequest{
2940 Request: &extension.GetValueRequest_Distance{
2941 Distance: &extension.GetDistanceRequest{
2942 OnuDeviceId: string(options.Args.OnuId),
2943 },
2944 },
2945 },
2946 }
2947 Info.Printf("Getting onu distance for device Id %s\n", options.Args.Id)
2948 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2949 defer cancel()
2950 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2951 if err != nil {
2952 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2953 return err
2954 }
2955
2956 if rv.Response.Status != extension.GetValueResponse_OK {
2957 return fmt.Errorf("failed to get onu distance stats %v", rv.Response.ErrReason.String())
2958 }
2959 outputFormat := CharReplacer.Replace(options.Format)
2960 if outputFormat == "" {
2961 outputFormat = GetCommandOptionWithDefault("get-onu-distance", "format", DEFAULT_ONU_DISTANCE_FORMAT)
2962 }
2963
2964 result := CommandResult{
2965 Format: format.Format(outputFormat),
2966 OutputAs: toOutputType(options.OutputAs),
2967 NameLimit: options.NameLimit,
2968 Data: rv.GetResponse().GetDistance().GetDistance(),
2969 }
2970 fmt.Println("onu distance : ", rv)
2971 GenerateOutput(&result)
2972 return nil
2973}
2974
praneeth nalmas39c71ad2023-09-27 18:29:04 +05302975func (options *PonRxPower) Execute(args []string) error {
2976 conn, err := NewConnection()
2977 if err != nil {
2978 return err
2979 }
2980 defer conn.Close()
2981 client := extension.NewExtensionClient(conn)
2982
2983 singleGetValReq := extension.SingleGetValueRequest{
2984 TargetId: string(options.Args.Id),
2985 Request: &extension.GetValueRequest{
2986 Request: &extension.GetValueRequest_OltRxPower{
2987 OltRxPower: &extension.GetOltRxPowerRequest{
2988 PortLabel: options.Args.PortLabel,
2989 OnuSn: options.Args.SerialNo,
2990 },
2991 },
2992 },
2993 }
2994
2995 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2996 defer cancel()
2997 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2998 if err != nil {
2999 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
3000 return err
3001 }
3002 if rv.Response.Status != extension.GetValueResponse_OK {
3003 return fmt.Errorf("failed to get rx power %v", rv.Response.ErrReason.String())
3004 }
3005 outputFormat := CharReplacer.Replace(options.Format)
3006 if outputFormat == "" {
3007 outputFormat = GetCommandOptionWithDefault("device-get-pon-rx-power", "format", DEFAULT_PON_RX_POWER_STATUS_FORMAT)
3008 }
3009 result := CommandResult{
3010 Format: format.Format(outputFormat),
3011 OutputAs: toOutputType(options.OutputAs),
3012 NameLimit: options.NameLimit,
3013 Data: rv.GetResponse().GetOltRxPower().GetRxPower(),
3014 }
3015 GenerateOutput(&result)
3016 return nil
3017}
Akash Reddy Kankanalac0014632025-05-21 17:12:20 +05303018
3019func (options *GetOnuGEMStats) Execute(args []string) error {
3020
3021 conn, err := NewConnection()
3022 if err != nil {
3023 return err
3024 }
3025 defer conn.Close()
3026 client := extension.NewExtensionClient(conn)
3027 singleGetValReq := extension.SingleGetValueRequest{
3028 TargetId: string(options.Args.Id),
3029 Request: &extension.GetValueRequest{
3030 Request: &extension.GetValueRequest_OnuAllocGemStats{
3031 OnuAllocGemStats: &extension.GetOnuAllocGemHistoryRequest{},
3032 },
3033 },
3034 }
3035
3036 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3037 defer cancel()
3038
3039 rv, err := client.GetExtValue(ctx, &singleGetValReq)
3040
3041 if err != nil {
3042 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
3043 return err
3044 }
3045
3046 if rv.Response.Status != extension.GetValueResponse_OK {
3047 return fmt.Errorf("failed to get gem port response %v", rv.Response.ErrReason.String())
3048 }
3049 outputFormat := CharReplacer.Replace(options.Format)
3050 if outputFormat == "" {
3051 outputFormat = GetCommandOptionWithDefault("device-get-gem-port", "format", DEFAULT_DEVICE_VALUE_GEM_PORT_FORMAT)
3052 }
3053 onugemhistoryresponse := rv.GetResponse().GetOnuAllocGemStatsResponse()
3054 for _, OnuallocGemHistoryData := range onugemhistoryresponse.OnuAllocGemHistoryData {
3055 data := onugemstats{}
3056 data.AllocId = OnuallocGemHistoryData.OnuAllocIdInfo.AllocId
3057 data.AllocRxBytes = OnuallocGemHistoryData.OnuAllocIdInfo.RxBytes
3058 for _, gemStatsInfo := range OnuallocGemHistoryData.GemPortInfo {
3059 data.GemHistoryStats = append(data.GemHistoryStats, gemHistoryStats{
3060 GemId: gemStatsInfo.GemId,
3061 TransmittedGEMFrames: gemStatsInfo.TransmittedGEMFrames,
3062 ReceivedGEMFrames: gemStatsInfo.ReceivedGEMFrames,
3063 ReceivedPayloadBytes: gemStatsInfo.ReceivedPayloadBytes,
3064 TransmittedPayloadBytes: gemStatsInfo.TransmittedPayloadBytes,
3065 EncryptionKeyErrors: gemStatsInfo.EncryptionKeyErrors,
3066 })
3067 }
3068 result := CommandResult{
3069 Format: format.Format(outputFormat),
3070 OutputAs: toOutputType(options.OutputAs),
3071 NameLimit: options.NameLimit,
3072 Data: &data,
3073 }
3074 GenerateOutput(&result)
3075 }
3076 return nil
3077
3078}
3079
3080func (options *GetOnuAllocGemStatsFromOlt) Execute(args []string) error {
3081 conn, err := NewConnection()
3082 if err != nil {
3083 return err
3084 }
3085 defer conn.Close()
3086 client := extension.NewExtensionClient(conn)
3087
3088 singleGetValReq := extension.SingleGetValueRequest{
3089 TargetId: string(options.Args.Id),
3090 Request: &extension.GetValueRequest{
3091 Request: &extension.GetValueRequest_OnuStatsFromOlt{
3092 OnuStatsFromOlt: &extension.GetOnuStatsFromOltRequest{},
3093 },
3094 },
3095 }
3096 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
3097 defer cancel()
3098 rv, err := client.GetExtValue(ctx, &singleGetValReq)
3099 if err != nil {
3100 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
3101 return err
3102 }
3103
3104 if rv.Response.Status != extension.GetValueResponse_OK {
3105 return fmt.Errorf("failed to get onu alloc gem stats from olt %v", rv.Response.ErrReason.String())
3106 }
3107 outputFormat := CharReplacer.Replace(options.Format)
3108 if outputFormat == "" {
3109 outputFormat = GetCommandOptionWithDefault("device-get-onu-status", "format", DEFAULT_ONU_STATS_FROM_OLT_FORMAT)
3110 }
3111
3112 onuAllocGemStatsResponse := rv.GetResponse().GetOnuStatsFromOltResponse()
3113
3114 for _, allocGemStatsInfo := range onuAllocGemStatsResponse.AllocGemStatsInfo {
3115 data := AllocGemStatsFromOlt{}
3116 data.AllocId = allocGemStatsInfo.AllocIdInfo.AllocId
3117 data.AllocRxBytes = allocGemStatsInfo.AllocIdInfo.RxBytes
3118 for _, gemStatsInfo := range allocGemStatsInfo.GemPortInfo {
3119 data.GemPortStats = append(data.GemPortStats, GemPortStatsFromOlt{
3120 GemId: gemStatsInfo.GemId,
3121 RxBytes: gemStatsInfo.RxBytes,
3122 RxPackets: gemStatsInfo.RxPackets,
3123 TxBytes: gemStatsInfo.TxBytes,
3124 TxPackets: gemStatsInfo.TxPackets,
3125 })
3126 }
3127 result := CommandResult{
3128 Format: format.Format(outputFormat),
3129 OutputAs: toOutputType(options.OutputAs),
3130 NameLimit: options.NameLimit,
3131 Data: &data,
3132 }
3133 GenerateOutput(&result)
3134 }
3135
3136 return nil
3137}