blob: 72c8bdc0776911e719608609fd1d891b60d28825 [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"
20 "fmt"
David Bainbridge7052fe82020-03-25 10:37:00 -070021 "os"
22 "strconv"
23 "strings"
Girish Gowdra610acb42021-01-27 13:33:57 -080024 "time"
David Bainbridge7052fe82020-03-25 10:37:00 -070025
Scott Baker9173ed82020-05-19 08:30:12 -070026 "github.com/golang/protobuf/ptypes/empty"
Zack Williamse940c7a2019-08-21 14:25:39 -070027 flags "github.com/jessevdk/go-flags"
Scott Baker2b0ad652019-08-21 14:57:07 -070028 "github.com/opencord/voltctl/pkg/format"
David K. Bainbridgebd6b2882021-08-26 13:31:02 +000029 "github.com/opencord/voltha-protos/v5/go/common"
30 "github.com/opencord/voltha-protos/v5/go/extension"
31 "github.com/opencord/voltha-protos/v5/go/voltha"
Zack Williamse940c7a2019-08-21 14:25:39 -070032)
33
34const (
David K. Bainbridge89003c42020-02-27 17:22:49 -080035 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 +000036 DEFAULT_DEVICE_ORDER = "Type,Id"
Zack Williamse940c7a2019-08-21 14:25:39 -070037 DEFAULT_DEVICE_PORTS_FORMAT = "table{{.PortNo}}\t{{.Label}}\t{{.Type}}\t{{.AdminState}}\t{{.OperStatus}}\t{{.DeviceId}}\t{{.Peers}}"
38 DEFAULT_DEVICE_INSPECT_FORMAT = `ID: {{.Id}}
39 TYPE: {{.Type}}
40 ROOT: {{.Root}}
41 PARENTID: {{.ParentId}}
42 SERIALNUMBER: {{.SerialNumber}}
43 VLAN: {{.Vlan}}
44 ADMINSTATE: {{.AdminState}}
45 OPERSTATUS: {{.OperStatus}}
46 CONNECTSTATUS: {{.ConnectStatus}}`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +000047 DEFAULT_DEVICE_PM_CONFIG_GET_FORMAT = "table{{.DefaultFreq}}\t{{.Grouped}}\t{{.FreqOverride}}"
48 DEFAULT_DEVICE_PM_CONFIG_METRIC_LIST_FORMAT = "table{{.Name}}\t{{.Type}}\t{{.Enabled}}\t{{.SampleFreq}}"
49 DEFAULT_DEVICE_PM_CONFIG_GROUP_LIST_FORMAT = "table{{.GroupName}}\t{{.Enabled}}\t{{.GroupFreq}}"
50 DEFAULT_DEVICE_VALUE_GET_FORMAT = "table{{.Name}}\t{{.Result}}"
Andrea Campanella791d88b2021-01-08 13:29:00 +010051 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 +053052 ONU_IMAGE_LIST_FORMAT = "table{{.Version}}\t{{.IsCommited}}\t{{.IsActive}}\t{{.IsValid}}\t{{.ProductCode}}\t{{.Hash}}"
53 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 -050054 DEFAULT_DEVICE_GET_PORT_STATUS_FORMAT = `
55 TXBYTES: {{.TxBytes}}
56 TXPACKETS: {{.TxPackets}}
57 TXERRPACKETS: {{.TxErrorPackets}}
58 TXBCASTPACKETS: {{.TxBcastPackets}}
59 TXUCASTPACKETS: {{.TxUcastPackets}}
60 TXMCASTPACKETS: {{.TxMcastPackets}}
61 RXBYTES: {{.RxBytes}}
62 RXPACKETS: {{.RxPackets}}
63 RXERRPACKETS: {{.RxErrorPackets}}
64 RXBCASTPACKETS: {{.RxBcastPackets}}
65 RXUCASTPACKETS: {{.RxUcastPackets}}
66 RXMCASTPACKETS: {{.RxMcastPackets}}`
kesavand6d1131f2021-02-05 22:38:15 +053067 DEFAULT_DEVICE_GET_UNI_STATUS_FORMAT = `
68 ADMIN_STATE: {{.AdmState}}
69 OPERATIONAL_STATE: {{.OperState}}
70 CONFIG_IND: {{.ConfigInd}}`
Girish Gowdra4f5ce7c2021-04-29 18:53:21 -070071 DEFAULT_ONU_PON_OPTICAL_INFO_STATUS_FORMAT = `
72 POWER_FEED_VOLTAGE__VOLTS: {{.PowerFeedVoltage}}
73 RECEIVED_OPTICAL_POWER__dBm: {{.ReceivedOpticalPower}}
74 MEAN_OPTICAL_LAUNCH_POWER__dBm: {{.MeanOpticalLaunchPower}}
75 LASER_BIAS_CURRENT__mA: {{.LaserBiasCurrent}}
76 TEMPERATURE__Celsius: {{.Temperature}}`
Gamze Abakac857a462021-05-26 13:45:54 +000077 DEFAULT_RX_POWER_STATUS_FORMAT = `
78 INTF_ID: {{.IntfId}}
79 ONU_ID: {{.OnuId}}
80 STATUS: {{.Status}}
81 FAIL_REASON: {{.FailReason}}
82 RX_POWER : {{.RxPower}}`
Himani Chawla553a1392021-06-10 23:39:17 +053083 DEFAULT_ETHERNET_FRAME_EXTENDED_PM_COUNTERS_FORMAT = `Upstream_Drop_Events: {{.UDropEvents}}
84Upstream_Octets: {{.UOctets}}
85UFrames: {{.UFrames}}
86UBroadcastFrames: {{.UBroadcastFrames}}
87UMulticastFrames: {{.UMulticastFrames}}
88UCrcErroredFrames: {{.UCrcErroredFrames}}
89UUndersizeFrames: {{.UUndersizeFrames}}
90UOversizeFrames: {{.UOversizeFrames}}
91UFrames_64Octets: {{.UFrames_64Octets}}
92UFrames_65To_127Octets: {{.UFrames_65To_127Octets}}
93UFrames_128To_255Octets: {{.UFrames_128To_255Octets}}
94UFrames_256To_511Octets: {{.UFrames_256To_511Octets}}
95UFrames_512To_1023Octets: {{.UFrames_512To_1023Octets}}
96UFrames_1024To_1518Octets: {{.UFrames_1024To_1518Octets}}
97DDropEvents: {{.DDropEvents}}
98DOctets: {{.DOctets}}
99DFrames: {{.DFrames}}
100DBroadcastFrames: {{.DBroadcastFrames}}
101DMulticastFrames: {{.DMulticastFrames}}
102DCrcErroredFrames: {{.DCrcErroredFrames}}
103DUndersizeFrames: {{.DUndersizeFrames}}
104DOversizeFrames: {{.DOversizeFrames}}
105DFrames_64Octets: {{.DFrames_64Octets}}
106DFrames_65To_127Octets: {{.DFrames_65To_127Octets}}
107DFrames_128To_255Octets: {{.DFrames_128To_255Octets}}
108DFrames_256To_511Octets: {{.DFrames_256To_511Octets}}
109DFrames_512To_1023Octets: {{.DFrames_512To_1023Octets}}
Himani Chawlabac0f892021-08-25 17:14:06 +0530110DFrames_1024To_1518Octets: {{.DFrames_1024To_1518Octets}}
111PmFormat: {{.PmFormat}}`
serkantul3d22fc72022-09-14 12:22:56 +0300112 DEFAULT_ONU_OMCI_TX_RX_STATS_FORMAT = `BaseTxArFrames: {{.BaseTxArFrames}}
113BaseRxAkFrames: {{.BaseRxAkFrames}}
114BaseTxNoArFrames: {{.BaseTxNoArFrames}}
115BaseRxNoAkFrames: {{.BaseRxNoAkFrames}}
116ExtTxArFrames: {{.ExtTxArFrames}}
117ExtRxAkFrames: {{.ExtRxAkFrames}}
118ExtTxNoArFrames: {{.ExtTxNoArFrames}}
119ExtRxNoAkFrames: {{.ExtRxNoAkFrames}}
120TxOmciCounterRetries: {{.TxOmciCounterRetries}}
121TxOmciCounterTimeouts: {{.TxOmciCounterTimeouts}}`
praneeth nalmas1dd094c2022-12-22 14:15:13 +0530122 DEFAULT_DEVICE_ALARMS_FORMAT = "table{{ .ClassId }}\t{{.InstanceId}}\t{{.Name}}\t{{.Description}}"
123 DEFAULT_DEVICE_ALARMS_ORDER = "ClassId,InstanceId"
Zack Williamse940c7a2019-08-21 14:25:39 -0700124)
125
126type DeviceList struct {
127 ListOutputOptions
128}
129
130type DeviceCreate struct {
David Bainbridge1a514392020-06-23 11:12:51 -0700131 DeviceType string `short:"t" required:"true" long:"devicetype" description:"Device type"`
David Bainbridge835dd0e2020-04-01 10:30:09 -0700132 MACAddress string `short:"m" long:"macaddress" default:"" description:"MAC Address"`
Zack Williamse940c7a2019-08-21 14:25:39 -0700133 IPAddress string `short:"i" long:"ipaddress" default:"" description:"IP Address"`
134 HostAndPort string `short:"H" long:"hostandport" default:"" description:"Host and port"`
135}
136
137type DeviceId string
138
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000139type MetricName string
140type GroupName string
kesavand12cd8eb2020-01-20 22:25:22 -0500141type PortNum uint32
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -0800142type ValueFlag string
kesavand12cd8eb2020-01-20 22:25:22 -0500143
Zack Williamse940c7a2019-08-21 14:25:39 -0700144type DeviceDelete struct {
Himani Chawla9933ddc2020-10-12 23:53:27 +0530145 Force bool `long:"force" description:"Delete device forcefully"`
146 Args struct {
Zack Williamse940c7a2019-08-21 14:25:39 -0700147 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
148 } `positional-args:"yes"`
149}
150
151type DeviceEnable struct {
152 Args struct {
153 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
154 } `positional-args:"yes"`
155}
156
157type DeviceDisable struct {
158 Args struct {
159 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
160 } `positional-args:"yes"`
161}
162
163type DeviceReboot struct {
164 Args struct {
165 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
166 } `positional-args:"yes"`
167}
168
169type DeviceFlowList struct {
170 ListOutputOptions
Maninder045921e2020-09-29 16:46:02 +0530171 FlowIdOptions
Zack Williamse940c7a2019-08-21 14:25:39 -0700172 Args struct {
173 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
174 } `positional-args:"yes"`
175}
176
Himani Chawla3c161c62021-05-13 16:36:51 +0530177type DeviceFlowGroupList struct {
178 ListOutputOptions
179 GroupListOptions
180 Args struct {
181 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
182 } `positional-args:"yes"`
183}
Zack Williamse940c7a2019-08-21 14:25:39 -0700184type DevicePortList struct {
185 ListOutputOptions
186 Args struct {
187 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
188 } `positional-args:"yes"`
189}
190
191type DeviceInspect struct {
192 OutputOptionsJson
193 Args struct {
194 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
195 } `positional-args:"yes"`
196}
197
kesavand12cd8eb2020-01-20 22:25:22 -0500198type DevicePortEnable struct {
199 Args struct {
200 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
201 PortId PortNum `positional-arg-name:"PORT_NUMBER" required:"yes"`
202 } `positional-args:"yes"`
203}
204
205type DevicePortDisable struct {
206 Args struct {
207 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
208 PortId PortNum `positional-arg-name:"PORT_NUMBER" required:"yes"`
209 } `positional-args:"yes"`
210}
211
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000212type DevicePmConfigsGet struct {
213 ListOutputOptions
214 Args struct {
215 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
216 } `positional-args:"yes"`
217}
218
219type DevicePmConfigMetricList struct {
220 ListOutputOptions
221 Args struct {
222 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
223 } `positional-args:"yes"`
224}
225
226type DevicePmConfigGroupList struct {
227 ListOutputOptions
228 Args struct {
229 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
230 } `positional-args:"yes"`
231}
232
233type DevicePmConfigGroupMetricList struct {
234 ListOutputOptions
235 Args struct {
236 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
237 Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"`
238 } `positional-args:"yes"`
239}
240
241type DevicePmConfigFrequencySet struct {
242 OutputOptions
243 Args struct {
Girish Gowdra610acb42021-01-27 13:33:57 -0800244 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
245 Interval time.Duration `positional-arg-name:"INTERVAL" required:"yes"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000246 } `positional-args:"yes"`
247}
248
249type DevicePmConfigMetricEnable struct {
250 Args struct {
251 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
252 Metrics []MetricName `positional-arg-name:"METRIC_NAME" required:"yes"`
253 } `positional-args:"yes"`
254}
255
256type DevicePmConfigMetricDisable struct {
257 Args struct {
258 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
259 Metrics []MetricName `positional-arg-name:"METRIC_NAME" required:"yes"`
260 } `positional-args:"yes"`
261}
262
263type DevicePmConfigGroupEnable struct {
264 Args struct {
Girish Gowdra610acb42021-01-27 13:33:57 -0800265 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
266 Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000267 } `positional-args:"yes"`
268}
269
270type DevicePmConfigGroupDisable struct {
271 Args struct {
Girish Gowdra610acb42021-01-27 13:33:57 -0800272 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
273 Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"`
274 } `positional-args:"yes"`
275}
276
277type DevicePmConfigGroupFrequencySet struct {
278 OutputOptions
279 Args struct {
280 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
281 Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"`
282 Interval time.Duration `positional-arg-name:"INTERVAL" required:"yes"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000283 } `positional-args:"yes"`
284}
285
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -0800286type DeviceGetExtValue struct {
287 ListOutputOptions
288 Args struct {
289 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
290 Valueflag ValueFlag `positional-arg-name:"VALUE_FLAG" required:"yes"`
291 } `positional-args:"yes"`
292}
Rohan Agrawald7df3772020-06-29 11:23:36 +0000293
294type DevicePmConfigSetMaxSkew struct {
295 Args struct {
296 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
297 MaxSkew uint32 `positional-arg-name:"MAX_SKEW" required:"yes"`
298 } `positional-args:"yes"`
299}
300
Andrea Campanella791d88b2021-01-08 13:29:00 +0100301type DeviceOnuListImages struct {
302 ListOutputOptions
303 Args struct {
304 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
305 } `positional-args:"yes"`
306}
307
308type DeviceOnuDownloadImage struct {
309 Args struct {
310 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
311 Name string `positional-arg-name:"IMAGE_NAME" required:"yes"`
312 Url string `positional-arg-name:"IMAGE_URL" required:"yes"`
313 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
314 Crc uint32 `positional-arg-name:"IMAGE_CRC" required:"yes"`
315 LocalDir string `positional-arg-name:"IMAGE_LOCAL_DIRECTORY"`
316 } `positional-args:"yes"`
317}
318
319type DeviceOnuActivateImageUpdate struct {
320 Args struct {
321 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
322 Name string `positional-arg-name:"IMAGE_NAME" required:"yes"`
323 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
324 SaveConfig bool `positional-arg-name:"SAVE_EXISTING_CONFIG"`
325 LocalDir string `positional-arg-name:"IMAGE_LOCAL_DIRECTORY"`
Andrea Campanella7b2ecf42021-02-25 12:27:15 +0100326 } `positional-args:"yes"`
kesavand8ec4fc02021-01-27 09:10:22 -0500327}
kesavand3e2f9f62021-04-22 11:06:38 +0530328
329type OnuDownloadImage struct {
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +0200330 ListOutputOptions
kesavand3e2f9f62021-04-22 11:06:38 +0530331 Args struct {
332 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
333 Url string `positional-arg-name:"IMAGE_URL" required:"yes"`
ssiddiqui7bc89e92021-05-20 20:58:02 +0530334 Vendor string `positional-arg-name:"IMAGE_VENDOR"`
kesavand3e2f9f62021-04-22 11:06:38 +0530335 ActivateOnSuccess bool `positional-arg-name:"IMAGE_ACTIVATE_ON_SUCCESS"`
336 CommitOnSuccess bool `positional-arg-name:"IMAGE_COMMIT_ON_SUCCESS"`
337 Crc uint32 `positional-arg-name:"IMAGE_CRC"`
338 IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
339 } `positional-args:"yes"`
340}
341
342type OnuActivateImage struct {
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +0200343 ListOutputOptions
kesavand3e2f9f62021-04-22 11:06:38 +0530344 Args struct {
345 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
346 CommitOnSuccess bool `positional-arg-name:"IMAGE_COMMIT_ON_SUCCESS"`
347 IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
348 } `positional-args:"yes"`
349}
350
351type OnuAbortUpgradeImage struct {
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +0200352 ListOutputOptions
kesavand3e2f9f62021-04-22 11:06:38 +0530353 Args struct {
354 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
355 IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
356 } `positional-args:"yes"`
357}
358
359type OnuCommitImage struct {
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +0200360 ListOutputOptions
kesavand3e2f9f62021-04-22 11:06:38 +0530361 Args struct {
362 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
363 IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
364 } `positional-args:"yes"`
365}
366
367type OnuImageStatus struct {
368 ListOutputOptions
369 Args struct {
370 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
Elia Battiston859f3e62022-02-08 15:57:52 +0100371 IDs []DeviceId `positional-arg-name:"DEVICE_ID"`
kesavand3e2f9f62021-04-22 11:06:38 +0530372 } `positional-args:"yes"`
373}
374
375type OnuListImages struct {
376 ListOutputOptions
377 Args struct {
378 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
379 } `positional-args:"yes"`
380}
381
kesavand8ec4fc02021-01-27 09:10:22 -0500382type DeviceGetPortStats struct {
383 ListOutputOptions
384 Args struct {
385 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
386 PortNo uint32 `positional-arg-name:"PORT_NO" required:"yes"`
387 PortType string `positional-arg-name:"PORT_TYPE" required:"yes"`
Andrea Campanella791d88b2021-01-08 13:29:00 +0100388 } `positional-args:"yes"`
389}
kesavand6d1131f2021-02-05 22:38:15 +0530390type UniStatus struct {
391 ListOutputOptions
392 Args struct {
393 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
394 UniIndex uint32 `positional-arg-name:"UNI_INDEX" required:"yes"`
395 } `positional-args:"yes"`
396}
Girish Gowdra4f5ce7c2021-04-29 18:53:21 -0700397type OnuPonOpticalInfo struct {
398 ListOutputOptions
399 Args struct {
400 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
401 } `positional-args:"yes"`
402}
Himani Chawla40acc122021-05-26 18:52:29 +0530403
404type GetOnuStats struct {
405 ListOutputOptions
406 Args struct {
407 OltId DeviceId `positional-arg-name:"OLT_DEVICE_ID" required:"yes"`
408 IntfId uint32 `positional-arg-name:"PON_INTF_ID" required:"yes"`
409 OnuId uint32 `positional-arg-name:"ONU_ID" required:"yes"`
410 } `positional-args:"yes"`
411}
412
Himani Chawla553a1392021-06-10 23:39:17 +0530413type GetOnuEthernetFrameExtendedPmCounters struct {
414 ListOutputOptions
Himani Chawla806aa892021-08-30 15:51:46 +0530415 Reset bool `long:"reset" description:"Reset the counters"`
416 Args struct {
417 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
418 UniIndex *uint32 `positional-arg-name:"UNI_INDEX"`
Himani Chawla553a1392021-06-10 23:39:17 +0530419 } `positional-args:"yes"`
420}
421
Gamze Abakac857a462021-05-26 13:45:54 +0000422type RxPower struct {
423 ListOutputOptions
424 Args struct {
425 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
426 PortNo uint32 `positional-arg-name:"PORT_NO" required:"yes"`
427 OnuNo uint32 `positional-arg-name:"ONU_NO" required:"yes"`
428 } `positional-args:"yes"`
429}
430
serkantul3d22fc72022-09-14 12:22:56 +0300431type OnuOmciTxRxStats struct {
432 ListOutputOptions
433 Args struct {
434 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
435 } `positional-args:"yes"`
436}
437
praneeth nalmas1dd094c2022-12-22 14:15:13 +0530438type GetOnuOmciActiveAlarms struct {
439 ListOutputOptions
440 Args struct {
441 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
442 } `positional-args:"yes"`
443}
444
Zack Williamse940c7a2019-08-21 14:25:39 -0700445type DeviceOpts struct {
Himani Chawla3c161c62021-05-13 16:36:51 +0530446 List DeviceList `command:"list"`
447 Create DeviceCreate `command:"create"`
448 Delete DeviceDelete `command:"delete"`
449 Enable DeviceEnable `command:"enable"`
450 Disable DeviceDisable `command:"disable"`
451 Flows DeviceFlowList `command:"flows"`
452 Groups DeviceFlowGroupList `command:"groups"`
kesavand12cd8eb2020-01-20 22:25:22 -0500453 Port struct {
454 List DevicePortList `command:"list"`
455 Enable DevicePortEnable `command:"enable"`
456 Disable DevicePortDisable `command:"disable"`
457 } `command:"port"`
458 Inspect DeviceInspect `command:"inspect"`
459 Reboot DeviceReboot `command:"reboot"`
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -0800460 Value struct {
461 Get DeviceGetExtValue `command:"get"`
462 } `command:"value"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000463 PmConfig struct {
Rohan Agrawald7df3772020-06-29 11:23:36 +0000464 Get DevicePmConfigsGet `command:"get"`
465 MaxSkew struct {
466 Set DevicePmConfigSetMaxSkew `command:"set"`
467 } `command:"maxskew"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000468 Frequency struct {
469 Set DevicePmConfigFrequencySet `command:"set"`
470 } `command:"frequency"`
471 Metric struct {
472 List DevicePmConfigMetricList `command:"list"`
473 Enable DevicePmConfigMetricEnable `command:"enable"`
474 Disable DevicePmConfigMetricDisable `command:"disable"`
475 } `command:"metric"`
476 Group struct {
Girish Gowdra610acb42021-01-27 13:33:57 -0800477 List DevicePmConfigGroupList `command:"list"`
478 Enable DevicePmConfigGroupEnable `command:"enable"`
479 Disable DevicePmConfigGroupDisable `command:"disable"`
480 Set DevicePmConfigGroupFrequencySet `command:"set"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000481 } `command:"group"`
482 GroupMetric struct {
483 List DevicePmConfigGroupMetricList `command:"list"`
484 } `command:"groupmetric"`
485 } `command:"pmconfig"`
Andrea Campanella791d88b2021-01-08 13:29:00 +0100486 Image struct {
487 Get DeviceOnuListImages `command:"list"`
488 Download DeviceOnuDownloadImage `command:"download"`
489 Activate DeviceOnuActivateImageUpdate `command:"activate"`
490 } `command:"image"`
kesavand3e2f9f62021-04-22 11:06:38 +0530491 DownloadImage struct {
492 Download OnuDownloadImage `command:"download"`
493 Activate OnuActivateImage `command:"activate"`
494 Commit OnuCommitImage `command:"commit"`
495 AbortUpgrade OnuAbortUpgradeImage `command:"abort"`
496 Status OnuImageStatus `command:"status"`
497 List OnuListImages `command:"list" `
498 } `command:"onuimage"`
kesavand8ec4fc02021-01-27 09:10:22 -0500499 GetExtVal struct {
Himani Chawla553a1392021-06-10 23:39:17 +0530500 Stats DeviceGetPortStats `command:"portstats"`
501 UniStatus UniStatus `command:"unistatus"`
502 OpticalInfo OnuPonOpticalInfo `command:"onu_pon_optical_info"`
503 OnuStats GetOnuStats `command:"onu_stats"`
504 EthernetFrameExtendedPm GetOnuEthernetFrameExtendedPmCounters `command:"ethernet_frame_extended_pm"`
505 RxPower RxPower `command:"rxpower"`
serkantul3d22fc72022-09-14 12:22:56 +0300506 OnuOmciStats OnuOmciTxRxStats `command:"onu_omci_stats"`
praneeth nalmas1dd094c2022-12-22 14:15:13 +0530507 OnuOmciActiveAlarms GetOnuOmciActiveAlarms `command:"onu_omci_active_alarms"`
kesavand8ec4fc02021-01-27 09:10:22 -0500508 } `command:"getextval"`
Zack Williamse940c7a2019-08-21 14:25:39 -0700509}
510
511var deviceOpts = DeviceOpts{}
512
513func RegisterDeviceCommands(parser *flags.Parser) {
David Bainbridge12f036f2019-10-15 22:09:04 +0000514 if _, err := parser.AddCommand("device", "device commands", "Commands to query and manipulate VOLTHA devices", &deviceOpts); err != nil {
David Bainbridgea6722342019-10-24 23:55:53 +0000515 Error.Fatalf("Unexpected error while attempting to register device commands : %s", err)
David Bainbridge12f036f2019-10-15 22:09:04 +0000516 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700517}
518
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000519func (i *MetricName) Complete(match string) []flags.Completion {
520 conn, err := NewConnection()
521 if err != nil {
522 return nil
523 }
524 defer conn.Close()
525
526 client := voltha.NewVolthaServiceClient(conn)
527
528 var deviceId string
529found:
530 for i := len(os.Args) - 1; i >= 0; i -= 1 {
531 switch os.Args[i] {
532 case "enable":
533 fallthrough
534 case "disable":
535 if len(os.Args) > i+1 {
536 deviceId = os.Args[i+1]
537 } else {
538 return nil
539 }
540 break found
541 default:
542 }
543 }
544
545 if len(deviceId) == 0 {
546 return nil
547 }
548
David K. Bainbridge9189c632021-03-26 21:52:21 +0000549 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000550 defer cancel()
551
552 id := voltha.ID{Id: string(deviceId)}
553
554 pmconfigs, err := client.ListDevicePmConfigs(ctx, &id)
555
556 if err != nil {
557 return nil
558 }
559
560 list := make([]flags.Completion, 0)
561 for _, metrics := range pmconfigs.Metrics {
562 if strings.HasPrefix(metrics.Name, match) {
563 list = append(list, flags.Completion{Item: metrics.Name})
564 }
565 }
566
567 return list
568}
569
570func (i *GroupName) Complete(match string) []flags.Completion {
571 conn, err := NewConnection()
572 if err != nil {
573 return nil
574 }
575 defer conn.Close()
576
577 client := voltha.NewVolthaServiceClient(conn)
578
579 var deviceId string
580found:
581 for i := len(os.Args) - 1; i >= 0; i -= 1 {
582 switch os.Args[i] {
583 case "list":
584 fallthrough
585 case "enable":
586 fallthrough
587 case "disable":
588 if len(os.Args) > i+1 {
589 deviceId = os.Args[i+1]
590 } else {
591 return nil
592 }
593 break found
594 default:
595 }
596 }
597
598 if len(deviceId) == 0 {
599 return nil
600 }
601
David K. Bainbridge9189c632021-03-26 21:52:21 +0000602 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000603 defer cancel()
604
605 id := voltha.ID{Id: string(deviceId)}
606
607 pmconfigs, err := client.ListDevicePmConfigs(ctx, &id)
608
609 if err != nil {
610 return nil
611 }
612
613 list := make([]flags.Completion, 0)
614 for _, group := range pmconfigs.Groups {
615 if strings.HasPrefix(group.GroupName, match) {
616 list = append(list, flags.Completion{Item: group.GroupName})
617 }
618 }
619 return list
620}
621
kesavand12cd8eb2020-01-20 22:25:22 -0500622func (i *PortNum) Complete(match string) []flags.Completion {
623 conn, err := NewConnection()
624 if err != nil {
625 return nil
626 }
627 defer conn.Close()
628
Scott Baker9173ed82020-05-19 08:30:12 -0700629 client := voltha.NewVolthaServiceClient(conn)
kesavand12cd8eb2020-01-20 22:25:22 -0500630
631 /*
632 * The command line args when completing for PortNum will be a DeviceId
633 * followed by one or more PortNums. So walk the argument list from the
634 * end and find the first argument that is enable/disable as those are
635 * the subcommands that come before the positional arguments. It would
636 * be nice if this package gave us the list of optional arguments
637 * already parsed.
638 */
639 var deviceId string
640found:
641 for i := len(os.Args) - 1; i >= 0; i -= 1 {
642 switch os.Args[i] {
643 case "enable":
644 fallthrough
645 case "disable":
646 if len(os.Args) > i+1 {
647 deviceId = os.Args[i+1]
648 } else {
649 return nil
650 }
651 break found
652 default:
653 }
654 }
655
656 if len(deviceId) == 0 {
657 return nil
658 }
659
David K. Bainbridge9189c632021-03-26 21:52:21 +0000660 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand12cd8eb2020-01-20 22:25:22 -0500661 defer cancel()
kesavand12cd8eb2020-01-20 22:25:22 -0500662
Scott Baker9173ed82020-05-19 08:30:12 -0700663 id := voltha.ID{Id: string(deviceId)}
kesavand12cd8eb2020-01-20 22:25:22 -0500664
Scott Baker9173ed82020-05-19 08:30:12 -0700665 ports, err := client.ListDevicePorts(ctx, &id)
kesavand12cd8eb2020-01-20 22:25:22 -0500666 if err != nil {
667 return nil
668 }
669
670 list := make([]flags.Completion, 0)
Scott Baker9173ed82020-05-19 08:30:12 -0700671 for _, item := range ports.Items {
672 pn := strconv.FormatUint(uint64(item.PortNo), 10)
kesavand12cd8eb2020-01-20 22:25:22 -0500673 if strings.HasPrefix(pn, match) {
674 list = append(list, flags.Completion{Item: pn})
675 }
676 }
677
678 return list
679}
680
Zack Williamse940c7a2019-08-21 14:25:39 -0700681func (i *DeviceId) Complete(match string) []flags.Completion {
682 conn, err := NewConnection()
683 if err != nil {
684 return nil
685 }
686 defer conn.Close()
687
Scott Baker9173ed82020-05-19 08:30:12 -0700688 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700689
David K. Bainbridge9189c632021-03-26 21:52:21 +0000690 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700691 defer cancel()
692
Scott Baker9173ed82020-05-19 08:30:12 -0700693 devices, err := client.ListDevices(ctx, &empty.Empty{})
Zack Williamse940c7a2019-08-21 14:25:39 -0700694 if err != nil {
695 return nil
696 }
697
698 list := make([]flags.Completion, 0)
Scott Baker9173ed82020-05-19 08:30:12 -0700699 for _, item := range devices.Items {
700 if strings.HasPrefix(item.Id, match) {
701 list = append(list, flags.Completion{Item: item.Id})
Zack Williamse940c7a2019-08-21 14:25:39 -0700702 }
703 }
704
705 return list
706}
707
708func (options *DeviceList) Execute(args []string) error {
709
710 conn, err := NewConnection()
711 if err != nil {
712 return err
713 }
714 defer conn.Close()
715
Scott Baker9173ed82020-05-19 08:30:12 -0700716 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700717
David K. Bainbridge9189c632021-03-26 21:52:21 +0000718 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700719 defer cancel()
720
Scott Baker9173ed82020-05-19 08:30:12 -0700721 devices, err := client.ListDevices(ctx, &empty.Empty{})
Zack Williamse940c7a2019-08-21 14:25:39 -0700722 if err != nil {
723 return err
724 }
725
726 outputFormat := CharReplacer.Replace(options.Format)
727 if outputFormat == "" {
David Bainbridgea6722342019-10-24 23:55:53 +0000728 outputFormat = GetCommandOptionWithDefault("device-list", "format", DEFAULT_DEVICE_FORMAT)
Zack Williamse940c7a2019-08-21 14:25:39 -0700729 }
730 if options.Quiet {
731 outputFormat = "{{.Id}}"
732 }
733
David Bainbridgea6722342019-10-24 23:55:53 +0000734 orderBy := options.OrderBy
735 if orderBy == "" {
Hardik Windlass9361bb82022-03-23 05:58:48 +0000736 orderBy = GetCommandOptionWithDefault("device-list", "order", DEFAULT_DEVICE_ORDER)
David Bainbridgea6722342019-10-24 23:55:53 +0000737 }
738
Scott Baker9173ed82020-05-19 08:30:12 -0700739 // Make sure json output prints an empty list, not "null"
740 if devices.Items == nil {
741 devices.Items = make([]*voltha.Device, 0)
Zack Williamse940c7a2019-08-21 14:25:39 -0700742 }
743
744 result := CommandResult{
745 Format: format.Format(outputFormat),
746 Filter: options.Filter,
David Bainbridgea6722342019-10-24 23:55:53 +0000747 OrderBy: orderBy,
Zack Williamse940c7a2019-08-21 14:25:39 -0700748 OutputAs: toOutputType(options.OutputAs),
749 NameLimit: options.NameLimit,
Scott Baker9173ed82020-05-19 08:30:12 -0700750 Data: devices.Items,
Zack Williamse940c7a2019-08-21 14:25:39 -0700751 }
752
753 GenerateOutput(&result)
754 return nil
755}
756
757func (options *DeviceCreate) Execute(args []string) error {
758
Scott Baker9173ed82020-05-19 08:30:12 -0700759 device := voltha.Device{}
Zack Williamse940c7a2019-08-21 14:25:39 -0700760 if options.HostAndPort != "" {
Scott Baker9173ed82020-05-19 08:30:12 -0700761 device.Address = &voltha.Device_HostAndPort{HostAndPort: options.HostAndPort}
Zack Williamse940c7a2019-08-21 14:25:39 -0700762 } else if options.IPAddress != "" {
Scott Baker9173ed82020-05-19 08:30:12 -0700763 device.Address = &voltha.Device_Ipv4Address{Ipv4Address: options.IPAddress}
Hardik Windlassce1de342020-02-04 21:58:07 +0000764 }
765 if options.MACAddress != "" {
Scott Baker9173ed82020-05-19 08:30:12 -0700766 device.MacAddress = strings.ToLower(options.MACAddress)
Zack Williamse940c7a2019-08-21 14:25:39 -0700767 }
768 if options.DeviceType != "" {
Scott Baker9173ed82020-05-19 08:30:12 -0700769 device.Type = options.DeviceType
Zack Williamse940c7a2019-08-21 14:25:39 -0700770 }
771
772 conn, err := NewConnection()
773 if err != nil {
774 return err
775 }
776 defer conn.Close()
777
Scott Baker9173ed82020-05-19 08:30:12 -0700778 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700779
David K. Bainbridge9189c632021-03-26 21:52:21 +0000780 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700781 defer cancel()
782
Scott Baker9173ed82020-05-19 08:30:12 -0700783 createdDevice, err := client.CreateDevice(ctx, &device)
Zack Williamse940c7a2019-08-21 14:25:39 -0700784 if err != nil {
785 return err
Zack Williamse940c7a2019-08-21 14:25:39 -0700786 }
787
Scott Baker9173ed82020-05-19 08:30:12 -0700788 fmt.Printf("%s\n", createdDevice.Id)
Zack Williamse940c7a2019-08-21 14:25:39 -0700789
790 return nil
791}
792
793func (options *DeviceDelete) Execute(args []string) error {
794
795 conn, err := NewConnection()
796 if err != nil {
797 return err
798 }
799 defer conn.Close()
800
Scott Baker9173ed82020-05-19 08:30:12 -0700801 client := voltha.NewVolthaServiceClient(conn)
David Bainbridge7052fe82020-03-25 10:37:00 -0700802 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -0700803 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +0000804 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700805 defer cancel()
806
Scott Baker9173ed82020-05-19 08:30:12 -0700807 id := voltha.ID{Id: string(i)}
Himani Chawla9933ddc2020-10-12 23:53:27 +0530808 if options.Force {
809 _, err = client.ForceDeleteDevice(ctx, &id)
810 } else {
811 _, err = client.DeleteDevice(ctx, &id)
812 }
Scott Baker9173ed82020-05-19 08:30:12 -0700813
Zack Williamse940c7a2019-08-21 14:25:39 -0700814 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +0000815 Error.Printf("Error while deleting '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -0700816 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -0700817 continue
Zack Williamse940c7a2019-08-21 14:25:39 -0700818 }
819 fmt.Printf("%s\n", i)
820 }
821
David Bainbridge7052fe82020-03-25 10:37:00 -0700822 if lastErr != nil {
823 return NoReportErr
824 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700825 return nil
826}
827
828func (options *DeviceEnable) Execute(args []string) error {
829 conn, err := NewConnection()
830 if err != nil {
831 return err
832 }
833 defer conn.Close()
834
Scott Baker9173ed82020-05-19 08:30:12 -0700835 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700836
David Bainbridge7052fe82020-03-25 10:37:00 -0700837 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -0700838 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +0000839 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700840 defer cancel()
841
Scott Baker9173ed82020-05-19 08:30:12 -0700842 id := voltha.ID{Id: string(i)}
843
844 _, err := client.EnableDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -0700845 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +0000846 Error.Printf("Error while enabling '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -0700847 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -0700848 continue
Zack Williamse940c7a2019-08-21 14:25:39 -0700849 }
850 fmt.Printf("%s\n", i)
851 }
852
David Bainbridge7052fe82020-03-25 10:37:00 -0700853 if lastErr != nil {
854 return NoReportErr
855 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700856 return nil
857}
858
859func (options *DeviceDisable) Execute(args []string) error {
860 conn, err := NewConnection()
861 if err != nil {
862 return err
863 }
864 defer conn.Close()
865
Scott Baker9173ed82020-05-19 08:30:12 -0700866 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700867
David Bainbridge7052fe82020-03-25 10:37:00 -0700868 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -0700869 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +0000870 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700871 defer cancel()
872
Scott Baker9173ed82020-05-19 08:30:12 -0700873 id := voltha.ID{Id: string(i)}
874
875 _, err := client.DisableDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -0700876 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +0000877 Error.Printf("Error while disabling '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -0700878 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -0700879 continue
Zack Williamse940c7a2019-08-21 14:25:39 -0700880 }
881 fmt.Printf("%s\n", i)
882 }
883
David Bainbridge7052fe82020-03-25 10:37:00 -0700884 if lastErr != nil {
885 return NoReportErr
886 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700887 return nil
888}
889
890func (options *DeviceReboot) Execute(args []string) error {
891 conn, err := NewConnection()
892 if err != nil {
893 return err
894 }
895 defer conn.Close()
896
Scott Baker9173ed82020-05-19 08:30:12 -0700897 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700898
David Bainbridge7052fe82020-03-25 10:37:00 -0700899 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -0700900 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +0000901 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700902 defer cancel()
903
Scott Baker9173ed82020-05-19 08:30:12 -0700904 id := voltha.ID{Id: string(i)}
905
906 _, err := client.RebootDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -0700907 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +0000908 Error.Printf("Error while rebooting '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -0700909 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -0700910 continue
Zack Williamse940c7a2019-08-21 14:25:39 -0700911 }
912 fmt.Printf("%s\n", i)
913 }
914
David Bainbridge7052fe82020-03-25 10:37:00 -0700915 if lastErr != nil {
916 return NoReportErr
917 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700918 return nil
919}
920
921func (options *DevicePortList) Execute(args []string) error {
922
923 conn, err := NewConnection()
924 if err != nil {
925 return err
926 }
927 defer conn.Close()
928
Scott Baker9173ed82020-05-19 08:30:12 -0700929 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700930
David K. Bainbridge9189c632021-03-26 21:52:21 +0000931 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700932 defer cancel()
933
Scott Baker9173ed82020-05-19 08:30:12 -0700934 id := voltha.ID{Id: string(options.Args.Id)}
Zack Williamse940c7a2019-08-21 14:25:39 -0700935
Scott Baker9173ed82020-05-19 08:30:12 -0700936 ports, err := client.ListDevicePorts(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -0700937 if err != nil {
938 return err
939 }
940
941 outputFormat := CharReplacer.Replace(options.Format)
942 if outputFormat == "" {
David Bainbridgea6722342019-10-24 23:55:53 +0000943 outputFormat = GetCommandOptionWithDefault("device-ports", "format", DEFAULT_DEVICE_PORTS_FORMAT)
Zack Williamse940c7a2019-08-21 14:25:39 -0700944 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700945
David Bainbridgea6722342019-10-24 23:55:53 +0000946 orderBy := options.OrderBy
947 if orderBy == "" {
948 orderBy = GetCommandOptionWithDefault("device-ports", "order", "")
949 }
950
Zack Williamse940c7a2019-08-21 14:25:39 -0700951 result := CommandResult{
952 Format: format.Format(outputFormat),
953 Filter: options.Filter,
David Bainbridgea6722342019-10-24 23:55:53 +0000954 OrderBy: orderBy,
Zack Williamse940c7a2019-08-21 14:25:39 -0700955 OutputAs: toOutputType(options.OutputAs),
956 NameLimit: options.NameLimit,
Scott Baker9173ed82020-05-19 08:30:12 -0700957 Data: ports.Items,
Zack Williamse940c7a2019-08-21 14:25:39 -0700958 }
959
960 GenerateOutput(&result)
961 return nil
962}
963
964func (options *DeviceFlowList) Execute(args []string) error {
965 fl := &FlowList{}
966 fl.ListOutputOptions = options.ListOutputOptions
Maninder045921e2020-09-29 16:46:02 +0530967 fl.FlowIdOptions = options.FlowIdOptions
Zack Williamse940c7a2019-08-21 14:25:39 -0700968 fl.Args.Id = string(options.Args.Id)
David Bainbridgea6722342019-10-24 23:55:53 +0000969 fl.Method = "device-flows"
Zack Williamse940c7a2019-08-21 14:25:39 -0700970 return fl.Execute(args)
971}
972
Himani Chawla3c161c62021-05-13 16:36:51 +0530973func (options *DeviceFlowGroupList) Execute(args []string) error {
974 grp := &GroupList{}
975 grp.ListOutputOptions = options.ListOutputOptions
976 grp.GroupListOptions = options.GroupListOptions
977 grp.Args.Id = string(options.Args.Id)
978 grp.Method = "device-groups"
979 return grp.Execute(args)
980}
981
Zack Williamse940c7a2019-08-21 14:25:39 -0700982func (options *DeviceInspect) Execute(args []string) error {
983 if len(args) > 0 {
984 return fmt.Errorf("only a single argument 'DEVICE_ID' can be provided")
985 }
986
987 conn, err := NewConnection()
988 if err != nil {
989 return err
990 }
991 defer conn.Close()
992
Scott Baker9173ed82020-05-19 08:30:12 -0700993 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700994
David K. Bainbridge9189c632021-03-26 21:52:21 +0000995 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700996 defer cancel()
997
Scott Baker9173ed82020-05-19 08:30:12 -0700998 id := voltha.ID{Id: string(options.Args.Id)}
Zack Williamse940c7a2019-08-21 14:25:39 -0700999
Scott Baker9173ed82020-05-19 08:30:12 -07001000 device, err := client.GetDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -07001001 if err != nil {
1002 return err
1003 }
1004
Zack Williamse940c7a2019-08-21 14:25:39 -07001005 outputFormat := CharReplacer.Replace(options.Format)
1006 if outputFormat == "" {
David Bainbridgea6722342019-10-24 23:55:53 +00001007 outputFormat = GetCommandOptionWithDefault("device-inspect", "format", DEFAULT_DEVICE_INSPECT_FORMAT)
Zack Williamse940c7a2019-08-21 14:25:39 -07001008 }
1009 if options.Quiet {
1010 outputFormat = "{{.Id}}"
1011 }
1012
1013 result := CommandResult{
1014 Format: format.Format(outputFormat),
1015 OutputAs: toOutputType(options.OutputAs),
1016 NameLimit: options.NameLimit,
1017 Data: device,
1018 }
1019 GenerateOutput(&result)
1020 return nil
1021}
kesavand12cd8eb2020-01-20 22:25:22 -05001022
1023/*Device Port Enable */
1024func (options *DevicePortEnable) Execute(args []string) error {
1025 conn, err := NewConnection()
1026 if err != nil {
1027 return err
1028 }
1029 defer conn.Close()
1030
Scott Baker9173ed82020-05-19 08:30:12 -07001031 client := voltha.NewVolthaServiceClient(conn)
kesavand12cd8eb2020-01-20 22:25:22 -05001032
David K. Bainbridge9189c632021-03-26 21:52:21 +00001033 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand12cd8eb2020-01-20 22:25:22 -05001034 defer cancel()
1035
Scott Baker9173ed82020-05-19 08:30:12 -07001036 port := voltha.Port{DeviceId: string(options.Args.Id), PortNo: uint32(options.Args.PortId)}
1037
1038 _, err = client.EnablePort(ctx, &port)
kesavand12cd8eb2020-01-20 22:25:22 -05001039 if err != nil {
1040 Error.Printf("Error enabling port number %v on device Id %s,err=%s\n", options.Args.PortId, options.Args.Id, ErrorToString(err))
1041 return err
kesavand12cd8eb2020-01-20 22:25:22 -05001042 }
1043
1044 return nil
1045}
1046
Scott Baker9173ed82020-05-19 08:30:12 -07001047/*Device Port Disable */
kesavand12cd8eb2020-01-20 22:25:22 -05001048func (options *DevicePortDisable) Execute(args []string) error {
1049 conn, err := NewConnection()
1050 if err != nil {
1051 return err
1052 }
1053 defer conn.Close()
1054
Scott Baker9173ed82020-05-19 08:30:12 -07001055 client := voltha.NewVolthaServiceClient(conn)
1056
David K. Bainbridge9189c632021-03-26 21:52:21 +00001057 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand12cd8eb2020-01-20 22:25:22 -05001058 defer cancel()
1059
Scott Baker9173ed82020-05-19 08:30:12 -07001060 port := voltha.Port{DeviceId: string(options.Args.Id), PortNo: uint32(options.Args.PortId)}
1061
1062 _, err = client.DisablePort(ctx, &port)
kesavand12cd8eb2020-01-20 22:25:22 -05001063 if err != nil {
Scott Baker9173ed82020-05-19 08:30:12 -07001064 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 -05001065 return err
kesavand12cd8eb2020-01-20 22:25:22 -05001066 }
Scott Baker9173ed82020-05-19 08:30:12 -07001067
kesavand12cd8eb2020-01-20 22:25:22 -05001068 return nil
1069}
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08001070
Rohan Agrawald7df3772020-06-29 11:23:36 +00001071func (options *DevicePmConfigSetMaxSkew) Execute(args []string) error {
1072 conn, err := NewConnection()
1073 if err != nil {
1074 return err
1075 }
1076 defer conn.Close()
1077
1078 client := voltha.NewVolthaServiceClient(conn)
1079
David K. Bainbridge9189c632021-03-26 21:52:21 +00001080 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawald7df3772020-06-29 11:23:36 +00001081 defer cancel()
1082
1083 id := voltha.ID{Id: string(options.Args.Id)}
1084
1085 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1086 if err != nil {
1087 return err
1088 }
1089
1090 pmConfigs.MaxSkew = options.Args.MaxSkew
1091
1092 _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs)
1093 if err != nil {
1094 return err
1095 }
1096
1097 return nil
1098}
1099
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001100func (options *DevicePmConfigsGet) Execute(args []string) error {
1101
1102 conn, err := NewConnection()
1103 if err != nil {
1104 return err
1105 }
1106 defer conn.Close()
1107
1108 client := voltha.NewVolthaServiceClient(conn)
1109
David K. Bainbridge9189c632021-03-26 21:52:21 +00001110 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001111 defer cancel()
1112
1113 id := voltha.ID{Id: string(options.Args.Id)}
1114
1115 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1116 if err != nil {
1117 return err
1118 }
1119
1120 outputFormat := CharReplacer.Replace(options.Format)
1121 if outputFormat == "" {
1122 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GET_FORMAT)
1123 }
1124
1125 orderBy := options.OrderBy
1126 if orderBy == "" {
1127 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1128 }
1129
1130 result := CommandResult{
1131 Format: format.Format(outputFormat),
1132 Filter: options.Filter,
1133 OrderBy: orderBy,
1134 OutputAs: toOutputType(options.OutputAs),
1135 NameLimit: options.NameLimit,
1136 Data: pmConfigs,
1137 }
1138
1139 GenerateOutput(&result)
1140 return nil
1141
1142}
1143
1144func (options *DevicePmConfigMetricList) Execute(args []string) error {
1145
1146 conn, err := NewConnection()
1147 if err != nil {
1148 return err
1149 }
1150 defer conn.Close()
1151
1152 client := voltha.NewVolthaServiceClient(conn)
1153
David K. Bainbridge9189c632021-03-26 21:52:21 +00001154 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001155 defer cancel()
1156
1157 id := voltha.ID{Id: string(options.Args.Id)}
1158
1159 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1160 if err != nil {
1161 return err
1162 }
1163
1164 if !pmConfigs.Grouped {
1165 for _, metric := range pmConfigs.Metrics {
1166 if metric.SampleFreq == 0 {
1167 metric.SampleFreq = pmConfigs.DefaultFreq
1168 }
1169 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001170 outputFormat := CharReplacer.Replace(options.Format)
1171 if outputFormat == "" {
1172 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_METRIC_LIST_FORMAT)
1173 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001174
Rohan Agrawalbca69122020-06-17 14:59:03 +00001175 orderBy := options.OrderBy
1176 if orderBy == "" {
1177 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1178 }
1179
1180 result := CommandResult{
1181 Format: format.Format(outputFormat),
1182 Filter: options.Filter,
1183 OrderBy: orderBy,
1184 OutputAs: toOutputType(options.OutputAs),
1185 NameLimit: options.NameLimit,
1186 Data: pmConfigs.Metrics,
1187 }
1188
1189 GenerateOutput(&result)
1190 return nil
1191 } else {
1192 return fmt.Errorf("Device '%s' does not have Non Grouped Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001193 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001194}
1195
1196func (options *DevicePmConfigMetricEnable) Execute(args []string) error {
1197
1198 conn, err := NewConnection()
1199 if err != nil {
1200 return err
1201 }
1202 defer conn.Close()
1203
1204 client := voltha.NewVolthaServiceClient(conn)
1205
David K. Bainbridge9189c632021-03-26 21:52:21 +00001206 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001207 defer cancel()
1208
1209 id := voltha.ID{Id: string(options.Args.Id)}
1210
1211 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1212 if err != nil {
1213 return err
1214 }
1215
1216 if !pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001217 metrics := make(map[string]struct{})
1218 for _, metric := range pmConfigs.Metrics {
1219 metrics[metric.Name] = struct{}{}
1220 }
1221
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001222 for _, metric := range pmConfigs.Metrics {
1223 for _, mName := range options.Args.Metrics {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001224 if _, exist := metrics[string(mName)]; !exist {
1225 return fmt.Errorf("Metric Name '%s' does not exist", mName)
1226 }
1227
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001228 if string(mName) == metric.Name && !metric.Enabled {
1229 metric.Enabled = true
1230 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1231 if err != nil {
1232 return err
1233 }
1234 }
1235 }
1236 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001237 } else {
1238 return fmt.Errorf("Device '%s' does not have Non Grouped Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001239 }
1240 return nil
1241}
1242
1243func (options *DevicePmConfigMetricDisable) Execute(args []string) error {
1244
1245 conn, err := NewConnection()
1246 if err != nil {
1247 return err
1248 }
1249 defer conn.Close()
1250
1251 client := voltha.NewVolthaServiceClient(conn)
1252
David K. Bainbridge9189c632021-03-26 21:52:21 +00001253 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001254 defer cancel()
1255
1256 id := voltha.ID{Id: string(options.Args.Id)}
1257
1258 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1259 if err != nil {
1260 return err
1261 }
1262
1263 if !pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001264 metrics := make(map[string]struct{})
1265 for _, metric := range pmConfigs.Metrics {
1266 metrics[metric.Name] = struct{}{}
1267 }
1268
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001269 for _, metric := range pmConfigs.Metrics {
1270 for _, mName := range options.Args.Metrics {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001271 if _, have := metrics[string(mName)]; !have {
1272 return fmt.Errorf("Metric Name '%s' does not exist", mName)
1273 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001274 if string(mName) == metric.Name && metric.Enabled {
1275 metric.Enabled = false
1276 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1277 if err != nil {
1278 return err
1279 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001280 } else {
1281 return fmt.Errorf("Metric '%s' cannot be disabled", string(mName))
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001282 }
1283 }
1284 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001285 } else {
1286 return fmt.Errorf("Device '%s' does not have Non Grouped Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001287 }
1288 return nil
1289}
1290
1291func (options *DevicePmConfigGroupEnable) Execute(args []string) error {
1292
1293 conn, err := NewConnection()
1294 if err != nil {
1295 return err
1296 }
1297 defer conn.Close()
1298
1299 client := voltha.NewVolthaServiceClient(conn)
1300
David K. Bainbridge9189c632021-03-26 21:52:21 +00001301 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001302 defer cancel()
1303
1304 id := voltha.ID{Id: string(options.Args.Id)}
1305
1306 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1307 if err != nil {
1308 return err
1309 }
1310
1311 if pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001312 groups := make(map[string]struct{})
1313 for _, group := range pmConfigs.Groups {
1314 groups[group.GroupName] = struct{}{}
1315 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001316 for _, group := range pmConfigs.Groups {
Girish Gowdra610acb42021-01-27 13:33:57 -08001317 if _, have := groups[string(options.Args.Group)]; !have {
1318 return fmt.Errorf("Group Name '%s' does not exist", options.Args.Group)
1319 }
1320 if string(options.Args.Group) == group.GroupName && !group.Enabled {
1321 group.Enabled = true
1322 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1323 if err != nil {
1324 return err
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001325 }
1326 }
1327 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001328 } else {
1329 return fmt.Errorf("Device '%s' does not have Group Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001330 }
1331 return nil
1332}
1333
1334func (options *DevicePmConfigGroupDisable) Execute(args []string) error {
1335
1336 conn, err := NewConnection()
1337 if err != nil {
1338 return err
1339 }
1340 defer conn.Close()
1341
1342 client := voltha.NewVolthaServiceClient(conn)
1343
David K. Bainbridge9189c632021-03-26 21:52:21 +00001344 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001345 defer cancel()
1346
1347 id := voltha.ID{Id: string(options.Args.Id)}
1348
1349 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1350 if err != nil {
1351 return err
1352 }
1353
1354 if pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001355 groups := make(map[string]struct{})
1356 for _, group := range pmConfigs.Groups {
1357 groups[group.GroupName] = struct{}{}
1358 }
1359
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001360 for _, group := range pmConfigs.Groups {
Girish Gowdra610acb42021-01-27 13:33:57 -08001361 if _, have := groups[string(options.Args.Group)]; !have {
1362 return fmt.Errorf("Group Name '%s' does not exist", options.Args.Group)
1363 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001364
Girish Gowdra610acb42021-01-27 13:33:57 -08001365 if string(options.Args.Group) == group.GroupName && group.Enabled {
1366 group.Enabled = false
1367 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1368 if err != nil {
1369 return err
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001370 }
1371 }
1372 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001373 } else {
1374 return fmt.Errorf("Device '%s' does not have Group Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001375 }
1376 return nil
1377}
1378
Girish Gowdra610acb42021-01-27 13:33:57 -08001379func (options *DevicePmConfigGroupFrequencySet) Execute(args []string) error {
1380
1381 conn, err := NewConnection()
1382 if err != nil {
1383 return err
1384 }
1385 defer conn.Close()
1386
1387 client := voltha.NewVolthaServiceClient(conn)
1388
David K. Bainbridge9189c632021-03-26 21:52:21 +00001389 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Girish Gowdra610acb42021-01-27 13:33:57 -08001390 defer cancel()
1391
1392 id := voltha.ID{Id: string(options.Args.Id)}
1393
1394 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1395 if err != nil {
1396 return err
1397 }
1398
1399 if pmConfigs.Grouped {
1400 groups := make(map[string]struct{})
1401 for _, group := range pmConfigs.Groups {
1402 groups[group.GroupName] = struct{}{}
1403 }
1404
1405 for _, group := range pmConfigs.Groups {
1406 if _, have := groups[string(options.Args.Group)]; !have {
1407 return fmt.Errorf("group name '%s' does not exist", options.Args.Group)
1408 }
1409
1410 if string(options.Args.Group) == group.GroupName {
1411 if !group.Enabled {
1412 return fmt.Errorf("group '%s' is not enabled", options.Args.Group)
1413 }
1414 group.GroupFreq = uint32(options.Args.Interval.Seconds())
1415 _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs)
1416 if err != nil {
1417 return err
1418 }
1419 }
1420 }
1421 } else {
1422 return fmt.Errorf("device '%s' does not have group metrics", options.Args.Id)
1423 }
1424 return nil
1425}
1426
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001427func (options *DevicePmConfigGroupList) Execute(args []string) error {
1428
1429 conn, err := NewConnection()
1430 if err != nil {
1431 return err
1432 }
1433 defer conn.Close()
1434
1435 client := voltha.NewVolthaServiceClient(conn)
1436
David K. Bainbridge9189c632021-03-26 21:52:21 +00001437 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001438 defer cancel()
1439
1440 id := voltha.ID{Id: string(options.Args.Id)}
1441
1442 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1443 if err != nil {
1444 return err
1445 }
1446
1447 if pmConfigs.Grouped {
1448 for _, group := range pmConfigs.Groups {
1449 if group.GroupFreq == 0 {
1450 group.GroupFreq = pmConfigs.DefaultFreq
1451 }
1452 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001453 outputFormat := CharReplacer.Replace(options.Format)
1454 if outputFormat == "" {
1455 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GROUP_LIST_FORMAT)
1456 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001457
Rohan Agrawalbca69122020-06-17 14:59:03 +00001458 orderBy := options.OrderBy
1459 if orderBy == "" {
1460 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1461 }
1462
1463 result := CommandResult{
1464 Format: format.Format(outputFormat),
1465 Filter: options.Filter,
1466 OrderBy: orderBy,
1467 OutputAs: toOutputType(options.OutputAs),
1468 NameLimit: options.NameLimit,
1469 Data: pmConfigs.Groups,
1470 }
1471
1472 GenerateOutput(&result)
1473 } else {
1474 return fmt.Errorf("Device '%s' does not have Group Metrics", string(options.Args.Id))
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001475 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001476 return nil
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001477}
1478
1479func (options *DevicePmConfigGroupMetricList) Execute(args []string) error {
1480
1481 var metrics []*voltha.PmConfig
1482 conn, err := NewConnection()
1483 if err != nil {
1484 return err
1485 }
1486 defer conn.Close()
1487
1488 client := voltha.NewVolthaServiceClient(conn)
1489
David K. Bainbridge9189c632021-03-26 21:52:21 +00001490 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001491 defer cancel()
1492
1493 id := voltha.ID{Id: string(options.Args.Id)}
1494
1495 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1496 if err != nil {
1497 return err
1498 }
1499
1500 for _, groups := range pmConfigs.Groups {
1501
1502 if string(options.Args.Group) == groups.GroupName {
1503 for _, metric := range groups.Metrics {
1504 if metric.SampleFreq == 0 && groups.GroupFreq == 0 {
1505 metric.SampleFreq = pmConfigs.DefaultFreq
1506 } else {
1507 metric.SampleFreq = groups.GroupFreq
1508 }
1509 }
1510 metrics = groups.Metrics
1511 }
1512 }
1513
1514 outputFormat := CharReplacer.Replace(options.Format)
1515 if outputFormat == "" {
1516 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_METRIC_LIST_FORMAT)
1517 }
1518
1519 orderBy := options.OrderBy
1520 if orderBy == "" {
1521 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1522 }
1523
1524 result := CommandResult{
1525 Format: format.Format(outputFormat),
1526 Filter: options.Filter,
1527 OrderBy: orderBy,
1528 OutputAs: toOutputType(options.OutputAs),
1529 NameLimit: options.NameLimit,
1530 Data: metrics,
1531 }
1532
1533 GenerateOutput(&result)
1534 return nil
1535
1536}
1537
1538func (options *DevicePmConfigFrequencySet) Execute(args []string) error {
1539
1540 conn, err := NewConnection()
1541 if err != nil {
1542 return err
1543 }
1544 defer conn.Close()
1545
1546 client := voltha.NewVolthaServiceClient(conn)
1547
David K. Bainbridge9189c632021-03-26 21:52:21 +00001548 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001549 defer cancel()
1550
1551 id := voltha.ID{Id: string(options.Args.Id)}
1552
1553 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1554 if err != nil {
1555 return err
1556 }
1557
Girish Gowdra610acb42021-01-27 13:33:57 -08001558 pmConfigs.DefaultFreq = uint32(options.Args.Interval.Seconds())
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001559
1560 _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs)
1561 if err != nil {
1562 return err
1563 }
1564
1565 outputFormat := CharReplacer.Replace(options.Format)
1566 if outputFormat == "" {
1567 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GET_FORMAT)
1568 }
1569 if options.Quiet {
1570 outputFormat = "{{.Id}}"
1571 }
1572
1573 result := CommandResult{
1574 Format: format.Format(outputFormat),
1575 OutputAs: toOutputType(options.OutputAs),
1576 NameLimit: options.NameLimit,
1577 Data: pmConfigs,
1578 }
1579
1580 GenerateOutput(&result)
1581 return nil
1582
1583}
1584
kesavand3e2f9f62021-04-22 11:06:38 +05301585func (options *OnuDownloadImage) Execute(args []string) error {
1586
1587 conn, err := NewConnection()
1588 if err != nil {
1589 return err
1590 }
1591 defer conn.Close()
1592
1593 client := voltha.NewVolthaServiceClient(conn)
1594
1595 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1596 defer cancel()
1597
1598 var devIDList []*common.ID
1599 for _, i := range options.Args.IDs {
1600
1601 devIDList = append(devIDList, &common.ID{Id: string(i)})
1602 }
1603
1604 downloadImage := voltha.DeviceImageDownloadRequest{
1605 DeviceId: devIDList,
1606 Image: &voltha.Image{
1607 Url: options.Args.Url,
1608 Crc32: options.Args.Crc,
ssiddiqui7bc89e92021-05-20 20:58:02 +05301609 Vendor: options.Args.Vendor,
kesavand3e2f9f62021-04-22 11:06:38 +05301610 Version: options.Args.ImageVersion,
1611 },
1612 ActivateOnSuccess: options.Args.ActivateOnSuccess,
1613 CommitOnSuccess: options.Args.CommitOnSuccess,
1614 }
1615
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001616 deviceImageResp, err := client.DownloadImageToDevice(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301617 if err != nil {
1618 return err
1619 }
1620
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001621 outputFormat := GetCommandOptionWithDefault("onu-image-download", "format", ONU_IMAGE_STATUS_FORMAT)
1622 // Make sure json output prints an empty list, not "null"
1623 if deviceImageResp.DeviceImageStates == nil {
1624 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1625 }
1626 result := CommandResult{
1627 Format: format.Format(outputFormat),
1628 OutputAs: toOutputType(options.OutputAs),
1629 NameLimit: options.NameLimit,
1630 Data: deviceImageResp.DeviceImageStates,
1631 }
1632 GenerateOutput(&result)
kesavand3e2f9f62021-04-22 11:06:38 +05301633 return nil
1634
1635}
1636
1637func (options *OnuActivateImage) Execute(args []string) error {
1638
1639 conn, err := NewConnection()
1640 if err != nil {
1641 return err
1642 }
1643 defer conn.Close()
1644
1645 client := voltha.NewVolthaServiceClient(conn)
1646
1647 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1648 defer cancel()
1649
1650 var devIDList []*common.ID
1651 for _, i := range options.Args.IDs {
1652
1653 devIDList = append(devIDList, &common.ID{Id: string(i)})
1654 }
1655
1656 downloadImage := voltha.DeviceImageRequest{
1657 DeviceId: devIDList,
1658 Version: options.Args.ImageVersion,
1659 CommitOnSuccess: options.Args.CommitOnSuccess,
1660 }
1661
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001662 deviceImageResp, err := client.ActivateImage(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301663 if err != nil {
1664 return err
1665 }
1666
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001667 outputFormat := GetCommandOptionWithDefault("onu-image-activate", "format", ONU_IMAGE_STATUS_FORMAT)
1668 // Make sure json output prints an empty list, not "null"
1669 if deviceImageResp.DeviceImageStates == nil {
1670 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1671 }
1672 result := CommandResult{
1673 Format: format.Format(outputFormat),
1674 OutputAs: toOutputType(options.OutputAs),
1675 NameLimit: options.NameLimit,
1676 Data: deviceImageResp.DeviceImageStates,
1677 }
1678 GenerateOutput(&result)
1679
kesavand3e2f9f62021-04-22 11:06:38 +05301680 return nil
1681
1682}
1683
1684func (options *OnuAbortUpgradeImage) Execute(args []string) error {
1685
1686 conn, err := NewConnection()
1687 if err != nil {
1688 return err
1689 }
1690 defer conn.Close()
1691
1692 client := voltha.NewVolthaServiceClient(conn)
1693
1694 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1695 defer cancel()
1696
1697 var devIDList []*common.ID
1698 for _, i := range options.Args.IDs {
1699
1700 devIDList = append(devIDList, &common.ID{Id: string(i)})
1701 }
1702
1703 downloadImage := voltha.DeviceImageRequest{
1704 DeviceId: devIDList,
1705 Version: options.Args.ImageVersion,
1706 }
1707
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001708 deviceImageResp, err := client.AbortImageUpgradeToDevice(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301709 if err != nil {
1710 return err
1711 }
1712
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001713 outputFormat := GetCommandOptionWithDefault("onu-image-abort", "format", ONU_IMAGE_STATUS_FORMAT)
1714 // Make sure json output prints an empty list, not "null"
1715 if deviceImageResp.DeviceImageStates == nil {
1716 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1717 }
1718 result := CommandResult{
1719 Format: format.Format(outputFormat),
1720 OutputAs: toOutputType(options.OutputAs),
1721 NameLimit: options.NameLimit,
1722 Data: deviceImageResp.DeviceImageStates,
1723 }
1724 GenerateOutput(&result)
1725
kesavand3e2f9f62021-04-22 11:06:38 +05301726 return nil
1727
1728}
1729
1730func (options *OnuCommitImage) Execute(args []string) error {
1731
1732 conn, err := NewConnection()
1733 if err != nil {
1734 return err
1735 }
1736 defer conn.Close()
1737
1738 client := voltha.NewVolthaServiceClient(conn)
1739
1740 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1741 defer cancel()
1742
1743 var devIDList []*common.ID
1744 for _, i := range options.Args.IDs {
1745
1746 devIDList = append(devIDList, &common.ID{Id: string(i)})
1747 }
1748 downloadImage := voltha.DeviceImageRequest{
1749 DeviceId: devIDList,
1750 Version: options.Args.ImageVersion,
1751 }
1752
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001753 deviceImageResp, err := client.CommitImage(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301754 if err != nil {
1755 return err
1756 }
1757
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001758 outputFormat := GetCommandOptionWithDefault("onu-image-commit", "format", ONU_IMAGE_STATUS_FORMAT)
1759 // Make sure json output prints an empty list, not "null"
1760 if deviceImageResp.DeviceImageStates == nil {
1761 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1762 }
1763 result := CommandResult{
1764 Format: format.Format(outputFormat),
1765 OutputAs: toOutputType(options.OutputAs),
1766 NameLimit: options.NameLimit,
1767 Data: deviceImageResp.DeviceImageStates,
1768 }
1769 GenerateOutput(&result)
1770
kesavand3e2f9f62021-04-22 11:06:38 +05301771 return nil
1772
1773}
1774
1775func (options *OnuListImages) Execute(args []string) error {
1776
1777 conn, err := NewConnection()
1778 if err != nil {
1779 return err
1780 }
1781 defer conn.Close()
1782
1783 client := voltha.NewVolthaServiceClient(conn)
1784
1785 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1786 defer cancel()
1787
1788 id := common.ID{Id: string(options.Args.Id)}
1789
1790 onuImages, err := client.GetOnuImages(ctx, &id)
1791 if err != nil {
1792 return err
1793 }
1794
1795 outputFormat := CharReplacer.Replace(options.Format)
1796 if outputFormat == "" {
1797 outputFormat = GetCommandOptionWithDefault("onu-image-list", "format", ONU_IMAGE_LIST_FORMAT)
1798 }
1799
1800 if options.Quiet {
1801 outputFormat = "{{.Id}}"
1802 }
1803
1804 //TODO orderby
1805
1806 // Make sure json output prints an empty list, not "null"
1807 if onuImages.Items == nil {
1808 onuImages.Items = make([]*voltha.OnuImage, 0)
1809 }
1810
1811 result := CommandResult{
1812 Format: format.Format(outputFormat),
1813 OutputAs: toOutputType(options.OutputAs),
1814 NameLimit: options.NameLimit,
1815 Data: onuImages.Items,
1816 }
1817
1818 GenerateOutput(&result)
1819 return nil
1820
1821}
1822
1823func (options *OnuImageStatus) Execute(args []string) error {
1824
1825 conn, err := NewConnection()
1826 if err != nil {
1827 return err
1828 }
1829 defer conn.Close()
1830
1831 client := voltha.NewVolthaServiceClient(conn)
1832
1833 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1834 defer cancel()
1835
1836 var devIDList []*common.ID
kesavand3e2f9f62021-04-22 11:06:38 +05301837
Elia Battiston859f3e62022-02-08 15:57:52 +01001838 if options.Args.IDs == nil {
1839 //Use an empty IDs list to retrieve the status of all devices
1840 //with the requested image version
1841 devIDList = []*common.ID{}
1842 } else {
1843 for _, i := range options.Args.IDs {
1844 devIDList = append(devIDList, &common.ID{Id: string(i)})
1845 }
kesavand3e2f9f62021-04-22 11:06:38 +05301846 }
1847
1848 imageStatusReq := voltha.DeviceImageRequest{
1849 DeviceId: devIDList,
1850 Version: options.Args.ImageVersion,
1851 }
1852 imageStatus, err := client.GetImageStatus(ctx, &imageStatusReq)
1853 if err != nil {
1854 return err
1855 }
1856
1857 outputFormat := CharReplacer.Replace(options.Format)
1858 if outputFormat == "" {
1859 outputFormat = GetCommandOptionWithDefault("device-image-list", "format", ONU_IMAGE_STATUS_FORMAT)
1860 }
1861
1862 if options.Quiet {
1863 outputFormat = "{{.Id}}"
1864 }
1865
1866 //TODO orderby
1867
1868 // Make sure json output prints an empty list, not "null"
1869 if imageStatus.DeviceImageStates == nil {
1870 imageStatus.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1871 }
1872
1873 result := CommandResult{
1874 Format: format.Format(outputFormat),
1875 OutputAs: toOutputType(options.OutputAs),
1876 NameLimit: options.NameLimit,
1877 Data: imageStatus.DeviceImageStates,
1878 }
1879
1880 GenerateOutput(&result)
1881 return nil
1882
1883}
1884
Andrea Campanella791d88b2021-01-08 13:29:00 +01001885func (options *DeviceOnuListImages) Execute(args []string) error {
1886
1887 conn, err := NewConnection()
1888 if err != nil {
1889 return err
1890 }
1891 defer conn.Close()
1892
1893 client := voltha.NewVolthaServiceClient(conn)
1894
David K. Bainbridge9189c632021-03-26 21:52:21 +00001895 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Andrea Campanella791d88b2021-01-08 13:29:00 +01001896 defer cancel()
1897
1898 id := common.ID{Id: string(options.Args.Id)}
1899
1900 imageDownloads, err := client.ListImageDownloads(ctx, &id)
1901 if err != nil {
1902 return err
1903 }
1904
1905 outputFormat := CharReplacer.Replace(options.Format)
1906 if outputFormat == "" {
1907 outputFormat = GetCommandOptionWithDefault("device-image-list", "format", DEFAULT_DEVICE_IMAGE_LIST_GET_FORMAT)
1908 }
1909
1910 if options.Quiet {
1911 outputFormat = "{{.Id}}"
1912 }
1913
1914 //TODO orderby
1915
1916 // Make sure json output prints an empty list, not "null"
1917 if imageDownloads.Items == nil {
1918 imageDownloads.Items = make([]*voltha.ImageDownload, 0)
1919 }
1920
1921 result := CommandResult{
1922 Format: format.Format(outputFormat),
1923 OutputAs: toOutputType(options.OutputAs),
1924 NameLimit: options.NameLimit,
1925 Data: imageDownloads.Items,
1926 }
1927
1928 GenerateOutput(&result)
1929 return nil
1930
1931}
1932
1933func (options *DeviceOnuDownloadImage) Execute(args []string) error {
1934
1935 conn, err := NewConnection()
1936 if err != nil {
1937 return err
1938 }
1939 defer conn.Close()
1940
1941 client := voltha.NewVolthaServiceClient(conn)
1942
David K. Bainbridge9189c632021-03-26 21:52:21 +00001943 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Andrea Campanella791d88b2021-01-08 13:29:00 +01001944 defer cancel()
1945
1946 downloadImage := voltha.ImageDownload{
1947 Id: string(options.Args.Id),
1948 Name: options.Args.Name,
1949 Url: options.Args.Url,
1950 Crc: options.Args.Crc,
1951 LocalDir: options.Args.LocalDir,
1952 }
1953
1954 _, err = client.DownloadImage(ctx, &downloadImage)
1955 if err != nil {
1956 return err
1957 }
1958
1959 return nil
1960
1961}
1962
1963func (options *DeviceOnuActivateImageUpdate) Execute(args []string) error {
1964
1965 conn, err := NewConnection()
1966 if err != nil {
1967 return err
1968 }
1969 defer conn.Close()
1970
1971 client := voltha.NewVolthaServiceClient(conn)
1972
David K. Bainbridge9189c632021-03-26 21:52:21 +00001973 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Andrea Campanella791d88b2021-01-08 13:29:00 +01001974 defer cancel()
1975
1976 downloadImage := voltha.ImageDownload{
1977 Id: string(options.Args.Id),
1978 Name: options.Args.Name,
1979 ImageVersion: options.Args.ImageVersion,
1980 SaveConfig: options.Args.SaveConfig,
1981 LocalDir: options.Args.LocalDir,
1982 }
1983
1984 _, err = client.ActivateImageUpdate(ctx, &downloadImage)
1985 if err != nil {
1986 return err
1987 }
1988
1989 return nil
1990
1991}
1992
Scott Baker9173ed82020-05-19 08:30:12 -07001993type ReturnValueRow struct {
1994 Name string `json:"name"`
1995 Result interface{} `json:"result"`
1996}
1997
kesavand8ec4fc02021-01-27 09:10:22 -05001998func (options *DeviceGetPortStats) Execute(args []string) error {
1999 conn, err := NewConnection()
2000 if err != nil {
2001 return err
2002 }
2003 defer conn.Close()
2004 client := extension.NewExtensionClient(conn)
2005 var portType extension.GetOltPortCounters_PortType
2006
2007 if options.Args.PortType == "pon" {
2008 portType = extension.GetOltPortCounters_Port_PON_OLT
2009 } else if options.Args.PortType == "nni" {
2010
2011 portType = extension.GetOltPortCounters_Port_ETHERNET_NNI
2012 } else {
2013 return fmt.Errorf("expected interface type pon/nni, provided %s", options.Args.PortType)
2014 }
2015
2016 singleGetValReq := extension.SingleGetValueRequest{
2017 TargetId: string(options.Args.Id),
2018 Request: &extension.GetValueRequest{
2019 Request: &extension.GetValueRequest_OltPortInfo{
2020 OltPortInfo: &extension.GetOltPortCounters{
2021 PortNo: options.Args.PortNo,
2022 PortType: portType,
2023 },
2024 },
2025 },
2026 }
2027
David K. Bainbridge9189c632021-03-26 21:52:21 +00002028 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand8ec4fc02021-01-27 09:10:22 -05002029 defer cancel()
2030 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2031 if err != nil {
2032 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2033 return err
2034 }
2035
2036 if rv.Response.Status != extension.GetValueResponse_OK {
2037 return fmt.Errorf("failed to get port stats %v", rv.Response.ErrReason.String())
2038 }
2039
2040 outputFormat := CharReplacer.Replace(options.Format)
2041 if outputFormat == "" {
2042 outputFormat = GetCommandOptionWithDefault("device-get-port-status", "format", DEFAULT_DEVICE_GET_PORT_STATUS_FORMAT)
2043 }
2044
2045 result := CommandResult{
2046 Format: format.Format(outputFormat),
2047 OutputAs: toOutputType(options.OutputAs),
2048 NameLimit: options.NameLimit,
2049 Data: rv.GetResponse().GetPortCoutners(),
2050 }
2051 GenerateOutput(&result)
2052 return nil
2053}
2054
Himani Chawla40acc122021-05-26 18:52:29 +05302055func (options *GetOnuStats) Execute(args []string) error {
2056 conn, err := NewConnection()
2057 if err != nil {
2058 return err
2059 }
2060 defer conn.Close()
2061 client := extension.NewExtensionClient(conn)
2062
2063 singleGetValReq := extension.SingleGetValueRequest{
2064 TargetId: string(options.Args.OltId),
2065 Request: &extension.GetValueRequest{
2066 Request: &extension.GetValueRequest_OnuPonInfo{
2067 OnuPonInfo: &extension.GetOnuCountersRequest{
2068 IntfId: options.Args.IntfId,
2069 OnuId: options.Args.OnuId,
2070 },
2071 },
2072 },
2073 }
2074 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2075 defer cancel()
2076 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2077 if err != nil {
2078 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.OltId, ErrorToString(err))
2079 return err
2080 }
2081
2082 if rv.Response.Status != extension.GetValueResponse_OK {
2083 return fmt.Errorf("failed to get onu stats %v", rv.Response.ErrReason.String())
2084 }
2085 outputFormat := CharReplacer.Replace(options.Format)
2086 data, formatStr := buildOnuStatsOutputFormat(rv.GetResponse().GetOnuPonCounters())
2087 if outputFormat == "" {
2088 outputFormat = GetCommandOptionWithDefault("device-get-onu-status", "format", formatStr)
2089 }
Himani Chawla553a1392021-06-10 23:39:17 +05302090 result := CommandResult{
2091 Format: format.Format(outputFormat),
2092 OutputAs: toOutputType(options.OutputAs),
2093 NameLimit: options.NameLimit,
2094 Data: data,
2095 }
2096 GenerateOutput(&result)
2097 return nil
2098}
Himani Chawla40acc122021-05-26 18:52:29 +05302099
Himani Chawla553a1392021-06-10 23:39:17 +05302100func (options *GetOnuEthernetFrameExtendedPmCounters) Execute(args []string) error {
2101 conn, err := NewConnection()
2102 if err != nil {
2103 return err
2104 }
2105 defer conn.Close()
2106 client := extension.NewExtensionClient(conn)
Himani Chawla806aa892021-08-30 15:51:46 +05302107 var singleGetValReq extension.SingleGetValueRequest
Himani Chawla553a1392021-06-10 23:39:17 +05302108
Himani Chawla806aa892021-08-30 15:51:46 +05302109 if options.Args.UniIndex != nil {
2110 singleGetValReq = extension.SingleGetValueRequest{
2111 TargetId: string(options.Args.Id),
2112 Request: &extension.GetValueRequest{
2113 Request: &extension.GetValueRequest_OnuInfo{
2114 OnuInfo: &extension.GetOmciEthernetFrameExtendedPmRequest{
2115 OnuDeviceId: string(options.Args.Id),
2116 Reset_: options.Reset,
2117 IsUniIndex: &extension.GetOmciEthernetFrameExtendedPmRequest_UniIndex{
2118 UniIndex: *options.Args.UniIndex,
2119 },
2120 },
Himani Chawla553a1392021-06-10 23:39:17 +05302121 },
2122 },
Himani Chawla806aa892021-08-30 15:51:46 +05302123 }
2124 } else {
2125 singleGetValReq = extension.SingleGetValueRequest{
2126 TargetId: string(options.Args.Id),
2127 Request: &extension.GetValueRequest{
2128 Request: &extension.GetValueRequest_OnuInfo{
2129 OnuInfo: &extension.GetOmciEthernetFrameExtendedPmRequest{
2130 OnuDeviceId: string(options.Args.Id),
2131 Reset_: options.Reset,
2132 },
2133 },
2134 },
2135 }
Himani Chawla553a1392021-06-10 23:39:17 +05302136 }
Himani Chawla806aa892021-08-30 15:51:46 +05302137
Himani Chawla553a1392021-06-10 23:39:17 +05302138 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2139 defer cancel()
2140 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2141 if err != nil {
2142 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2143 return err
2144 }
2145
2146 if rv.Response.Status != extension.GetValueResponse_OK {
2147 return fmt.Errorf("failed to get ethernet frame extended pm counters %v", rv.Response.ErrReason.String())
2148 }
2149 outputFormat := CharReplacer.Replace(options.Format)
2150 data := buildOnuEthernetFrameExtendedPmOutputFormat(rv.GetResponse().GetOnuCounters())
2151 if outputFormat == "" {
2152 outputFormat = GetCommandOptionWithDefault("device-get-onu-status", "format", DEFAULT_ETHERNET_FRAME_EXTENDED_PM_COUNTERS_FORMAT)
2153 }
Himani Chawla40acc122021-05-26 18:52:29 +05302154 result := CommandResult{
2155 Format: format.Format(outputFormat),
2156 OutputAs: toOutputType(options.OutputAs),
2157 NameLimit: options.NameLimit,
2158 Data: data,
2159 }
2160 GenerateOutput(&result)
2161 return nil
2162}
2163
kesavand6d1131f2021-02-05 22:38:15 +05302164func (options *UniStatus) Execute(args []string) error {
2165 conn, err := NewConnection()
2166 if err != nil {
2167 return err
2168 }
2169 defer conn.Close()
2170 client := extension.NewExtensionClient(conn)
2171
2172 singleGetValReq := extension.SingleGetValueRequest{
2173 TargetId: string(options.Args.Id),
2174 Request: &extension.GetValueRequest{
2175 Request: &extension.GetValueRequest_UniInfo{
2176 UniInfo: &extension.GetOnuUniInfoRequest{
2177 UniIndex: options.Args.UniIndex,
2178 },
2179 },
2180 },
2181 }
David K. Bainbridge9189c632021-03-26 21:52:21 +00002182 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand6d1131f2021-02-05 22:38:15 +05302183 defer cancel()
2184 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2185 if err != nil {
2186 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2187 return err
2188 }
2189 if rv.Response.Status != extension.GetValueResponse_OK {
2190 return fmt.Errorf("failed to get uni status %v", rv.Response.ErrReason.String())
2191 }
2192 outputFormat := CharReplacer.Replace(options.Format)
2193 if outputFormat == "" {
2194 outputFormat = GetCommandOptionWithDefault("device-get-uni-status", "format", DEFAULT_DEVICE_GET_UNI_STATUS_FORMAT)
2195 }
2196 result := CommandResult{
2197 Format: format.Format(outputFormat),
2198 OutputAs: toOutputType(options.OutputAs),
2199 NameLimit: options.NameLimit,
2200 Data: rv.GetResponse().GetUniInfo(),
2201 }
2202 GenerateOutput(&result)
2203 return nil
2204}
2205
Girish Gowdra4f5ce7c2021-04-29 18:53:21 -07002206func (options *OnuPonOpticalInfo) Execute(args []string) error {
2207 conn, err := NewConnection()
2208 if err != nil {
2209 return err
2210 }
2211 defer conn.Close()
2212 client := extension.NewExtensionClient(conn)
2213
2214 singleGetValReq := extension.SingleGetValueRequest{
2215 TargetId: string(options.Args.Id),
2216 Request: &extension.GetValueRequest{
2217 Request: &extension.GetValueRequest_OnuOpticalInfo{
2218 OnuOpticalInfo: &extension.GetOnuPonOpticalInfo{},
2219 },
2220 },
2221 }
2222 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2223 defer cancel()
2224 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2225 if err != nil {
2226 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2227 return err
2228 }
2229 if rv.Response.Status != extension.GetValueResponse_OK {
2230 return fmt.Errorf("failed to get onu pon optical info %v", rv.Response.ErrReason.String())
2231 }
2232 outputFormat := CharReplacer.Replace(options.Format)
2233 if outputFormat == "" {
2234 outputFormat = GetCommandOptionWithDefault("device-get-onu-pon-optical-info", "format", DEFAULT_ONU_PON_OPTICAL_INFO_STATUS_FORMAT)
2235 }
2236 result := CommandResult{
2237 Format: format.Format(outputFormat),
2238 OutputAs: toOutputType(options.OutputAs),
2239 NameLimit: options.NameLimit,
2240 Data: rv.GetResponse().GetOnuOpticalInfo(),
2241 }
2242 GenerateOutput(&result)
2243 return nil
2244}
2245
Gamze Abakac857a462021-05-26 13:45:54 +00002246func (options *RxPower) Execute(args []string) error {
2247 conn, err := NewConnection()
2248 if err != nil {
2249 return err
2250 }
2251 defer conn.Close()
2252 client := extension.NewExtensionClient(conn)
2253
2254 singleGetValReq := extension.SingleGetValueRequest{
2255 TargetId: string(options.Args.Id),
2256 Request: &extension.GetValueRequest{
2257 Request: &extension.GetValueRequest_RxPower{
2258 RxPower: &extension.GetRxPowerRequest{
2259 IntfId: options.Args.PortNo,
2260 OnuId: options.Args.OnuNo,
2261 },
2262 },
2263 },
2264 }
2265
2266 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2267 defer cancel()
2268 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2269 if err != nil {
2270 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2271 return err
2272 }
2273 if rv.Response.Status != extension.GetValueResponse_OK {
2274 return fmt.Errorf("failed to get rx power %v", rv.Response.ErrReason.String())
2275 }
2276 outputFormat := CharReplacer.Replace(options.Format)
2277 if outputFormat == "" {
2278 outputFormat = GetCommandOptionWithDefault("device-get-rx-power", "format", DEFAULT_RX_POWER_STATUS_FORMAT)
2279 }
2280 result := CommandResult{
2281 Format: format.Format(outputFormat),
2282 OutputAs: toOutputType(options.OutputAs),
2283 NameLimit: options.NameLimit,
2284 Data: rv.GetResponse().GetRxPower(),
2285 }
2286 GenerateOutput(&result)
2287 return nil
2288}
2289
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002290/*Device get Onu Distance */
2291func (options *DeviceGetExtValue) Execute(args []string) error {
2292 conn, err := NewConnection()
2293 if err != nil {
2294 return err
2295 }
2296 defer conn.Close()
2297
Scott Baker9173ed82020-05-19 08:30:12 -07002298 client := voltha.NewVolthaServiceClient(conn)
2299
khenaidoo080ce882021-10-19 17:35:08 -04002300 valueflag, okay := extension.ValueType_Type_value[string(options.Args.Valueflag)]
Scott Baker9173ed82020-05-19 08:30:12 -07002301 if !okay {
2302 Error.Printf("Unknown valueflag %s\n", options.Args.Valueflag)
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002303 }
2304
khenaidoo080ce882021-10-19 17:35:08 -04002305 val := extension.ValueSpecifier{Id: string(options.Args.Id), Value: extension.ValueType_Type(valueflag)}
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002306
David K. Bainbridge9189c632021-03-26 21:52:21 +00002307 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002308 defer cancel()
2309
Scott Baker9173ed82020-05-19 08:30:12 -07002310 rv, err := client.GetExtValue(ctx, &val)
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002311 if err != nil {
2312 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2313 return err
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002314 }
2315
Scott Baker9173ed82020-05-19 08:30:12 -07002316 var rows []ReturnValueRow
khenaidoo080ce882021-10-19 17:35:08 -04002317 for name, num := range extension.ValueType_Type_value {
Scott Baker9173ed82020-05-19 08:30:12 -07002318 if num == 0 {
2319 // EMPTY is not a real value
2320 continue
2321 }
2322 if (rv.Error & uint32(num)) != 0 {
2323 row := ReturnValueRow{Name: name, Result: "Error"}
2324 rows = append(rows, row)
2325 }
2326 if (rv.Unsupported & uint32(num)) != 0 {
2327 row := ReturnValueRow{Name: name, Result: "Unsupported"}
2328 rows = append(rows, row)
2329 }
2330 if (rv.Set & uint32(num)) != 0 {
2331 switch name {
2332 case "DISTANCE":
2333 row := ReturnValueRow{Name: name, Result: rv.Distance}
2334 rows = append(rows, row)
2335 default:
2336 row := ReturnValueRow{Name: name, Result: "Unimplemented-in-voltctl"}
2337 rows = append(rows, row)
2338 }
2339 }
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002340 }
2341
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002342 outputFormat := CharReplacer.Replace(options.Format)
2343 if outputFormat == "" {
2344 outputFormat = GetCommandOptionWithDefault("device-value-get", "format", DEFAULT_DEVICE_VALUE_GET_FORMAT)
2345 }
2346
2347 result := CommandResult{
2348 Format: format.Format(outputFormat),
2349 OutputAs: toOutputType(options.OutputAs),
2350 NameLimit: options.NameLimit,
Scott Baker9173ed82020-05-19 08:30:12 -07002351 Data: rows,
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002352 }
2353 GenerateOutput(&result)
2354 return nil
2355}
serkantul3d22fc72022-09-14 12:22:56 +03002356
2357/*Device get Onu OMCI TX RX Stats */
2358func (options *OnuOmciTxRxStats) Execute(args []string) error {
2359 conn, err := NewConnection()
2360 if err != nil {
2361 return err
2362 }
2363 defer conn.Close()
2364 client := extension.NewExtensionClient(conn)
2365
2366 singleGetValReq := extension.SingleGetValueRequest{
2367 TargetId: string(options.Args.Id),
2368 Request: &extension.GetValueRequest{
2369 Request: &extension.GetValueRequest_OnuOmciStats{
2370 OnuOmciStats: &extension.GetOnuOmciTxRxStatsRequest{},
2371 },
2372 },
2373 }
2374
2375 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2376 defer cancel()
2377 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2378 if err != nil {
2379 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2380 return err
2381 }
2382
2383 if rv.Response.Status != extension.GetValueResponse_OK {
2384 return fmt.Errorf("failed to get onu omci tx rx stats %v", rv.Response.ErrReason.String())
2385 }
2386 outputFormat := CharReplacer.Replace(options.Format)
2387 if outputFormat == "" {
2388 outputFormat = GetCommandOptionWithDefault("device-get-onu-omci-tx-rx-stats", "format", DEFAULT_ONU_OMCI_TX_RX_STATS_FORMAT)
2389 }
2390 result := CommandResult{
2391 Format: format.Format(outputFormat),
2392 OutputAs: toOutputType(options.OutputAs),
2393 NameLimit: options.NameLimit,
2394 Data: rv.GetResponse().GetOnuOmciStats(),
2395 }
2396 GenerateOutput(&result)
2397 return nil
2398}
praneeth nalmas1dd094c2022-12-22 14:15:13 +05302399
2400/*Device get Onu Active Alarms */
2401func (options *GetOnuOmciActiveAlarms) Execute(args []string) error {
2402 conn, err := NewConnection()
2403 if err != nil {
2404 return err
2405 }
2406 defer conn.Close()
2407 client := extension.NewExtensionClient(conn)
2408
2409 singleGetValReq := extension.SingleGetValueRequest{
2410 TargetId: string(options.Args.Id),
2411 Request: &extension.GetValueRequest{
2412 Request: &extension.GetValueRequest_OnuActiveAlarms{
2413 OnuActiveAlarms: &extension.GetOnuOmciActiveAlarmsRequest{},
2414 },
2415 },
2416 }
2417 Info.Printf("Getting omci_active_alarms for device Id %s\n", options.Args.Id)
2418 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2419 defer cancel()
2420 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2421 if err != nil {
2422 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2423 return err
2424 }
2425
2426 if rv.Response.Status != extension.GetValueResponse_OK {
2427 return fmt.Errorf("failed to get onu omci active alarms list %v", rv.Response.ErrReason.String())
2428 }
2429 outputFormat := CharReplacer.Replace(options.Format)
2430 if outputFormat == "" {
2431 outputFormat = GetCommandOptionWithDefault("device-get-onu-omci-active-alarms", "format", DEFAULT_DEVICE_ALARMS_FORMAT)
2432 }
2433
2434 orderBy := options.OrderBy
2435 if orderBy == "" {
2436 orderBy = GetCommandOptionWithDefault("device-list", "order", DEFAULT_DEVICE_ALARMS_ORDER)
2437 }
2438
2439 result := CommandResult{
2440 Format: format.Format(outputFormat),
2441 OutputAs: toOutputType(options.OutputAs),
2442 OrderBy: orderBy,
2443 NameLimit: options.NameLimit,
2444 Data: rv.GetResponse().GetOnuActiveAlarms().GetActiveAlarms(),
2445 }
2446 GenerateOutput(&result)
2447 return nil
2448}