blob: d0858f34bb9cdc1bf59eb395c49efd61a72e0662 [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}}`
Zack Williamse940c7a2019-08-21 14:25:39 -0700122)
123
124type DeviceList struct {
125 ListOutputOptions
126}
127
128type DeviceCreate struct {
David Bainbridge1a514392020-06-23 11:12:51 -0700129 DeviceType string `short:"t" required:"true" long:"devicetype" description:"Device type"`
David Bainbridge835dd0e2020-04-01 10:30:09 -0700130 MACAddress string `short:"m" long:"macaddress" default:"" description:"MAC Address"`
Zack Williamse940c7a2019-08-21 14:25:39 -0700131 IPAddress string `short:"i" long:"ipaddress" default:"" description:"IP Address"`
132 HostAndPort string `short:"H" long:"hostandport" default:"" description:"Host and port"`
133}
134
135type DeviceId string
136
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000137type MetricName string
138type GroupName string
kesavand12cd8eb2020-01-20 22:25:22 -0500139type PortNum uint32
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -0800140type ValueFlag string
kesavand12cd8eb2020-01-20 22:25:22 -0500141
Zack Williamse940c7a2019-08-21 14:25:39 -0700142type DeviceDelete struct {
Himani Chawla9933ddc2020-10-12 23:53:27 +0530143 Force bool `long:"force" description:"Delete device forcefully"`
144 Args struct {
Zack Williamse940c7a2019-08-21 14:25:39 -0700145 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
146 } `positional-args:"yes"`
147}
148
149type DeviceEnable struct {
150 Args struct {
151 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
152 } `positional-args:"yes"`
153}
154
155type DeviceDisable struct {
156 Args struct {
157 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
158 } `positional-args:"yes"`
159}
160
161type DeviceReboot struct {
162 Args struct {
163 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
164 } `positional-args:"yes"`
165}
166
167type DeviceFlowList struct {
168 ListOutputOptions
Maninder045921e2020-09-29 16:46:02 +0530169 FlowIdOptions
Zack Williamse940c7a2019-08-21 14:25:39 -0700170 Args struct {
171 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
172 } `positional-args:"yes"`
173}
174
Himani Chawla3c161c62021-05-13 16:36:51 +0530175type DeviceFlowGroupList struct {
176 ListOutputOptions
177 GroupListOptions
178 Args struct {
179 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
180 } `positional-args:"yes"`
181}
Zack Williamse940c7a2019-08-21 14:25:39 -0700182type DevicePortList struct {
183 ListOutputOptions
184 Args struct {
185 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
186 } `positional-args:"yes"`
187}
188
189type DeviceInspect struct {
190 OutputOptionsJson
191 Args struct {
192 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
193 } `positional-args:"yes"`
194}
195
kesavand12cd8eb2020-01-20 22:25:22 -0500196type DevicePortEnable struct {
197 Args struct {
198 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
199 PortId PortNum `positional-arg-name:"PORT_NUMBER" required:"yes"`
200 } `positional-args:"yes"`
201}
202
203type DevicePortDisable struct {
204 Args struct {
205 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
206 PortId PortNum `positional-arg-name:"PORT_NUMBER" required:"yes"`
207 } `positional-args:"yes"`
208}
209
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000210type DevicePmConfigsGet struct {
211 ListOutputOptions
212 Args struct {
213 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
214 } `positional-args:"yes"`
215}
216
217type DevicePmConfigMetricList struct {
218 ListOutputOptions
219 Args struct {
220 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
221 } `positional-args:"yes"`
222}
223
224type DevicePmConfigGroupList struct {
225 ListOutputOptions
226 Args struct {
227 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
228 } `positional-args:"yes"`
229}
230
231type DevicePmConfigGroupMetricList struct {
232 ListOutputOptions
233 Args struct {
234 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
235 Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"`
236 } `positional-args:"yes"`
237}
238
239type DevicePmConfigFrequencySet struct {
240 OutputOptions
241 Args struct {
Girish Gowdra610acb42021-01-27 13:33:57 -0800242 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
243 Interval time.Duration `positional-arg-name:"INTERVAL" required:"yes"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000244 } `positional-args:"yes"`
245}
246
247type DevicePmConfigMetricEnable struct {
248 Args struct {
249 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
250 Metrics []MetricName `positional-arg-name:"METRIC_NAME" required:"yes"`
251 } `positional-args:"yes"`
252}
253
254type DevicePmConfigMetricDisable struct {
255 Args struct {
256 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
257 Metrics []MetricName `positional-arg-name:"METRIC_NAME" required:"yes"`
258 } `positional-args:"yes"`
259}
260
261type DevicePmConfigGroupEnable struct {
262 Args struct {
Girish Gowdra610acb42021-01-27 13:33:57 -0800263 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
264 Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000265 } `positional-args:"yes"`
266}
267
268type DevicePmConfigGroupDisable struct {
269 Args struct {
Girish Gowdra610acb42021-01-27 13:33:57 -0800270 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
271 Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"`
272 } `positional-args:"yes"`
273}
274
275type DevicePmConfigGroupFrequencySet struct {
276 OutputOptions
277 Args struct {
278 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
279 Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"`
280 Interval time.Duration `positional-arg-name:"INTERVAL" required:"yes"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000281 } `positional-args:"yes"`
282}
283
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -0800284type DeviceGetExtValue struct {
285 ListOutputOptions
286 Args struct {
287 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
288 Valueflag ValueFlag `positional-arg-name:"VALUE_FLAG" required:"yes"`
289 } `positional-args:"yes"`
290}
Rohan Agrawald7df3772020-06-29 11:23:36 +0000291
292type DevicePmConfigSetMaxSkew struct {
293 Args struct {
294 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
295 MaxSkew uint32 `positional-arg-name:"MAX_SKEW" required:"yes"`
296 } `positional-args:"yes"`
297}
298
Andrea Campanella791d88b2021-01-08 13:29:00 +0100299type DeviceOnuListImages struct {
300 ListOutputOptions
301 Args struct {
302 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
303 } `positional-args:"yes"`
304}
305
306type DeviceOnuDownloadImage struct {
307 Args struct {
308 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
309 Name string `positional-arg-name:"IMAGE_NAME" required:"yes"`
310 Url string `positional-arg-name:"IMAGE_URL" required:"yes"`
311 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
312 Crc uint32 `positional-arg-name:"IMAGE_CRC" required:"yes"`
313 LocalDir string `positional-arg-name:"IMAGE_LOCAL_DIRECTORY"`
314 } `positional-args:"yes"`
315}
316
317type DeviceOnuActivateImageUpdate struct {
318 Args struct {
319 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
320 Name string `positional-arg-name:"IMAGE_NAME" required:"yes"`
321 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
322 SaveConfig bool `positional-arg-name:"SAVE_EXISTING_CONFIG"`
323 LocalDir string `positional-arg-name:"IMAGE_LOCAL_DIRECTORY"`
Andrea Campanella7b2ecf42021-02-25 12:27:15 +0100324 } `positional-args:"yes"`
kesavand8ec4fc02021-01-27 09:10:22 -0500325}
kesavand3e2f9f62021-04-22 11:06:38 +0530326
327type OnuDownloadImage struct {
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +0200328 ListOutputOptions
kesavand3e2f9f62021-04-22 11:06:38 +0530329 Args struct {
330 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
331 Url string `positional-arg-name:"IMAGE_URL" required:"yes"`
ssiddiqui7bc89e92021-05-20 20:58:02 +0530332 Vendor string `positional-arg-name:"IMAGE_VENDOR"`
kesavand3e2f9f62021-04-22 11:06:38 +0530333 ActivateOnSuccess bool `positional-arg-name:"IMAGE_ACTIVATE_ON_SUCCESS"`
334 CommitOnSuccess bool `positional-arg-name:"IMAGE_COMMIT_ON_SUCCESS"`
335 Crc uint32 `positional-arg-name:"IMAGE_CRC"`
336 IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
337 } `positional-args:"yes"`
338}
339
340type OnuActivateImage struct {
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +0200341 ListOutputOptions
kesavand3e2f9f62021-04-22 11:06:38 +0530342 Args struct {
343 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
344 CommitOnSuccess bool `positional-arg-name:"IMAGE_COMMIT_ON_SUCCESS"`
345 IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
346 } `positional-args:"yes"`
347}
348
349type OnuAbortUpgradeImage struct {
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +0200350 ListOutputOptions
kesavand3e2f9f62021-04-22 11:06:38 +0530351 Args struct {
352 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
353 IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
354 } `positional-args:"yes"`
355}
356
357type OnuCommitImage struct {
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +0200358 ListOutputOptions
kesavand3e2f9f62021-04-22 11:06:38 +0530359 Args struct {
360 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
361 IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
362 } `positional-args:"yes"`
363}
364
365type OnuImageStatus struct {
366 ListOutputOptions
367 Args struct {
368 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
Elia Battiston859f3e62022-02-08 15:57:52 +0100369 IDs []DeviceId `positional-arg-name:"DEVICE_ID"`
kesavand3e2f9f62021-04-22 11:06:38 +0530370 } `positional-args:"yes"`
371}
372
373type OnuListImages struct {
374 ListOutputOptions
375 Args struct {
376 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
377 } `positional-args:"yes"`
378}
379
kesavand8ec4fc02021-01-27 09:10:22 -0500380type DeviceGetPortStats struct {
381 ListOutputOptions
382 Args struct {
383 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
384 PortNo uint32 `positional-arg-name:"PORT_NO" required:"yes"`
385 PortType string `positional-arg-name:"PORT_TYPE" required:"yes"`
Andrea Campanella791d88b2021-01-08 13:29:00 +0100386 } `positional-args:"yes"`
387}
kesavand6d1131f2021-02-05 22:38:15 +0530388type UniStatus struct {
389 ListOutputOptions
390 Args struct {
391 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
392 UniIndex uint32 `positional-arg-name:"UNI_INDEX" required:"yes"`
393 } `positional-args:"yes"`
394}
Girish Gowdra4f5ce7c2021-04-29 18:53:21 -0700395type OnuPonOpticalInfo struct {
396 ListOutputOptions
397 Args struct {
398 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
399 } `positional-args:"yes"`
400}
Himani Chawla40acc122021-05-26 18:52:29 +0530401
402type GetOnuStats struct {
403 ListOutputOptions
404 Args struct {
405 OltId DeviceId `positional-arg-name:"OLT_DEVICE_ID" required:"yes"`
406 IntfId uint32 `positional-arg-name:"PON_INTF_ID" required:"yes"`
407 OnuId uint32 `positional-arg-name:"ONU_ID" required:"yes"`
408 } `positional-args:"yes"`
409}
410
Himani Chawla553a1392021-06-10 23:39:17 +0530411type GetOnuEthernetFrameExtendedPmCounters struct {
412 ListOutputOptions
Himani Chawla806aa892021-08-30 15:51:46 +0530413 Reset bool `long:"reset" description:"Reset the counters"`
414 Args struct {
415 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
416 UniIndex *uint32 `positional-arg-name:"UNI_INDEX"`
Himani Chawla553a1392021-06-10 23:39:17 +0530417 } `positional-args:"yes"`
418}
419
Gamze Abakac857a462021-05-26 13:45:54 +0000420type RxPower struct {
421 ListOutputOptions
422 Args struct {
423 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
424 PortNo uint32 `positional-arg-name:"PORT_NO" required:"yes"`
425 OnuNo uint32 `positional-arg-name:"ONU_NO" required:"yes"`
426 } `positional-args:"yes"`
427}
428
serkantul3d22fc72022-09-14 12:22:56 +0300429type OnuOmciTxRxStats struct {
430 ListOutputOptions
431 Args struct {
432 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
433 } `positional-args:"yes"`
434}
435
Zack Williamse940c7a2019-08-21 14:25:39 -0700436type DeviceOpts struct {
Himani Chawla3c161c62021-05-13 16:36:51 +0530437 List DeviceList `command:"list"`
438 Create DeviceCreate `command:"create"`
439 Delete DeviceDelete `command:"delete"`
440 Enable DeviceEnable `command:"enable"`
441 Disable DeviceDisable `command:"disable"`
442 Flows DeviceFlowList `command:"flows"`
443 Groups DeviceFlowGroupList `command:"groups"`
kesavand12cd8eb2020-01-20 22:25:22 -0500444 Port struct {
445 List DevicePortList `command:"list"`
446 Enable DevicePortEnable `command:"enable"`
447 Disable DevicePortDisable `command:"disable"`
448 } `command:"port"`
449 Inspect DeviceInspect `command:"inspect"`
450 Reboot DeviceReboot `command:"reboot"`
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -0800451 Value struct {
452 Get DeviceGetExtValue `command:"get"`
453 } `command:"value"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000454 PmConfig struct {
Rohan Agrawald7df3772020-06-29 11:23:36 +0000455 Get DevicePmConfigsGet `command:"get"`
456 MaxSkew struct {
457 Set DevicePmConfigSetMaxSkew `command:"set"`
458 } `command:"maxskew"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000459 Frequency struct {
460 Set DevicePmConfigFrequencySet `command:"set"`
461 } `command:"frequency"`
462 Metric struct {
463 List DevicePmConfigMetricList `command:"list"`
464 Enable DevicePmConfigMetricEnable `command:"enable"`
465 Disable DevicePmConfigMetricDisable `command:"disable"`
466 } `command:"metric"`
467 Group struct {
Girish Gowdra610acb42021-01-27 13:33:57 -0800468 List DevicePmConfigGroupList `command:"list"`
469 Enable DevicePmConfigGroupEnable `command:"enable"`
470 Disable DevicePmConfigGroupDisable `command:"disable"`
471 Set DevicePmConfigGroupFrequencySet `command:"set"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000472 } `command:"group"`
473 GroupMetric struct {
474 List DevicePmConfigGroupMetricList `command:"list"`
475 } `command:"groupmetric"`
476 } `command:"pmconfig"`
Andrea Campanella791d88b2021-01-08 13:29:00 +0100477 Image struct {
478 Get DeviceOnuListImages `command:"list"`
479 Download DeviceOnuDownloadImage `command:"download"`
480 Activate DeviceOnuActivateImageUpdate `command:"activate"`
481 } `command:"image"`
kesavand3e2f9f62021-04-22 11:06:38 +0530482 DownloadImage struct {
483 Download OnuDownloadImage `command:"download"`
484 Activate OnuActivateImage `command:"activate"`
485 Commit OnuCommitImage `command:"commit"`
486 AbortUpgrade OnuAbortUpgradeImage `command:"abort"`
487 Status OnuImageStatus `command:"status"`
488 List OnuListImages `command:"list" `
489 } `command:"onuimage"`
kesavand8ec4fc02021-01-27 09:10:22 -0500490 GetExtVal struct {
Himani Chawla553a1392021-06-10 23:39:17 +0530491 Stats DeviceGetPortStats `command:"portstats"`
492 UniStatus UniStatus `command:"unistatus"`
493 OpticalInfo OnuPonOpticalInfo `command:"onu_pon_optical_info"`
494 OnuStats GetOnuStats `command:"onu_stats"`
495 EthernetFrameExtendedPm GetOnuEthernetFrameExtendedPmCounters `command:"ethernet_frame_extended_pm"`
496 RxPower RxPower `command:"rxpower"`
serkantul3d22fc72022-09-14 12:22:56 +0300497 OnuOmciStats OnuOmciTxRxStats `command:"onu_omci_stats"`
kesavand8ec4fc02021-01-27 09:10:22 -0500498 } `command:"getextval"`
Zack Williamse940c7a2019-08-21 14:25:39 -0700499}
500
501var deviceOpts = DeviceOpts{}
502
503func RegisterDeviceCommands(parser *flags.Parser) {
David Bainbridge12f036f2019-10-15 22:09:04 +0000504 if _, err := parser.AddCommand("device", "device commands", "Commands to query and manipulate VOLTHA devices", &deviceOpts); err != nil {
David Bainbridgea6722342019-10-24 23:55:53 +0000505 Error.Fatalf("Unexpected error while attempting to register device commands : %s", err)
David Bainbridge12f036f2019-10-15 22:09:04 +0000506 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700507}
508
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000509func (i *MetricName) Complete(match string) []flags.Completion {
510 conn, err := NewConnection()
511 if err != nil {
512 return nil
513 }
514 defer conn.Close()
515
516 client := voltha.NewVolthaServiceClient(conn)
517
518 var deviceId string
519found:
520 for i := len(os.Args) - 1; i >= 0; i -= 1 {
521 switch os.Args[i] {
522 case "enable":
523 fallthrough
524 case "disable":
525 if len(os.Args) > i+1 {
526 deviceId = os.Args[i+1]
527 } else {
528 return nil
529 }
530 break found
531 default:
532 }
533 }
534
535 if len(deviceId) == 0 {
536 return nil
537 }
538
David K. Bainbridge9189c632021-03-26 21:52:21 +0000539 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000540 defer cancel()
541
542 id := voltha.ID{Id: string(deviceId)}
543
544 pmconfigs, err := client.ListDevicePmConfigs(ctx, &id)
545
546 if err != nil {
547 return nil
548 }
549
550 list := make([]flags.Completion, 0)
551 for _, metrics := range pmconfigs.Metrics {
552 if strings.HasPrefix(metrics.Name, match) {
553 list = append(list, flags.Completion{Item: metrics.Name})
554 }
555 }
556
557 return list
558}
559
560func (i *GroupName) Complete(match string) []flags.Completion {
561 conn, err := NewConnection()
562 if err != nil {
563 return nil
564 }
565 defer conn.Close()
566
567 client := voltha.NewVolthaServiceClient(conn)
568
569 var deviceId string
570found:
571 for i := len(os.Args) - 1; i >= 0; i -= 1 {
572 switch os.Args[i] {
573 case "list":
574 fallthrough
575 case "enable":
576 fallthrough
577 case "disable":
578 if len(os.Args) > i+1 {
579 deviceId = os.Args[i+1]
580 } else {
581 return nil
582 }
583 break found
584 default:
585 }
586 }
587
588 if len(deviceId) == 0 {
589 return nil
590 }
591
David K. Bainbridge9189c632021-03-26 21:52:21 +0000592 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000593 defer cancel()
594
595 id := voltha.ID{Id: string(deviceId)}
596
597 pmconfigs, err := client.ListDevicePmConfigs(ctx, &id)
598
599 if err != nil {
600 return nil
601 }
602
603 list := make([]flags.Completion, 0)
604 for _, group := range pmconfigs.Groups {
605 if strings.HasPrefix(group.GroupName, match) {
606 list = append(list, flags.Completion{Item: group.GroupName})
607 }
608 }
609 return list
610}
611
kesavand12cd8eb2020-01-20 22:25:22 -0500612func (i *PortNum) Complete(match string) []flags.Completion {
613 conn, err := NewConnection()
614 if err != nil {
615 return nil
616 }
617 defer conn.Close()
618
Scott Baker9173ed82020-05-19 08:30:12 -0700619 client := voltha.NewVolthaServiceClient(conn)
kesavand12cd8eb2020-01-20 22:25:22 -0500620
621 /*
622 * The command line args when completing for PortNum will be a DeviceId
623 * followed by one or more PortNums. So walk the argument list from the
624 * end and find the first argument that is enable/disable as those are
625 * the subcommands that come before the positional arguments. It would
626 * be nice if this package gave us the list of optional arguments
627 * already parsed.
628 */
629 var deviceId string
630found:
631 for i := len(os.Args) - 1; i >= 0; i -= 1 {
632 switch os.Args[i] {
633 case "enable":
634 fallthrough
635 case "disable":
636 if len(os.Args) > i+1 {
637 deviceId = os.Args[i+1]
638 } else {
639 return nil
640 }
641 break found
642 default:
643 }
644 }
645
646 if len(deviceId) == 0 {
647 return nil
648 }
649
David K. Bainbridge9189c632021-03-26 21:52:21 +0000650 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand12cd8eb2020-01-20 22:25:22 -0500651 defer cancel()
kesavand12cd8eb2020-01-20 22:25:22 -0500652
Scott Baker9173ed82020-05-19 08:30:12 -0700653 id := voltha.ID{Id: string(deviceId)}
kesavand12cd8eb2020-01-20 22:25:22 -0500654
Scott Baker9173ed82020-05-19 08:30:12 -0700655 ports, err := client.ListDevicePorts(ctx, &id)
kesavand12cd8eb2020-01-20 22:25:22 -0500656 if err != nil {
657 return nil
658 }
659
660 list := make([]flags.Completion, 0)
Scott Baker9173ed82020-05-19 08:30:12 -0700661 for _, item := range ports.Items {
662 pn := strconv.FormatUint(uint64(item.PortNo), 10)
kesavand12cd8eb2020-01-20 22:25:22 -0500663 if strings.HasPrefix(pn, match) {
664 list = append(list, flags.Completion{Item: pn})
665 }
666 }
667
668 return list
669}
670
Zack Williamse940c7a2019-08-21 14:25:39 -0700671func (i *DeviceId) Complete(match string) []flags.Completion {
672 conn, err := NewConnection()
673 if err != nil {
674 return nil
675 }
676 defer conn.Close()
677
Scott Baker9173ed82020-05-19 08:30:12 -0700678 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700679
David K. Bainbridge9189c632021-03-26 21:52:21 +0000680 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700681 defer cancel()
682
Scott Baker9173ed82020-05-19 08:30:12 -0700683 devices, err := client.ListDevices(ctx, &empty.Empty{})
Zack Williamse940c7a2019-08-21 14:25:39 -0700684 if err != nil {
685 return nil
686 }
687
688 list := make([]flags.Completion, 0)
Scott Baker9173ed82020-05-19 08:30:12 -0700689 for _, item := range devices.Items {
690 if strings.HasPrefix(item.Id, match) {
691 list = append(list, flags.Completion{Item: item.Id})
Zack Williamse940c7a2019-08-21 14:25:39 -0700692 }
693 }
694
695 return list
696}
697
698func (options *DeviceList) Execute(args []string) error {
699
700 conn, err := NewConnection()
701 if err != nil {
702 return err
703 }
704 defer conn.Close()
705
Scott Baker9173ed82020-05-19 08:30:12 -0700706 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700707
David K. Bainbridge9189c632021-03-26 21:52:21 +0000708 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700709 defer cancel()
710
Scott Baker9173ed82020-05-19 08:30:12 -0700711 devices, err := client.ListDevices(ctx, &empty.Empty{})
Zack Williamse940c7a2019-08-21 14:25:39 -0700712 if err != nil {
713 return err
714 }
715
716 outputFormat := CharReplacer.Replace(options.Format)
717 if outputFormat == "" {
David Bainbridgea6722342019-10-24 23:55:53 +0000718 outputFormat = GetCommandOptionWithDefault("device-list", "format", DEFAULT_DEVICE_FORMAT)
Zack Williamse940c7a2019-08-21 14:25:39 -0700719 }
720 if options.Quiet {
721 outputFormat = "{{.Id}}"
722 }
723
David Bainbridgea6722342019-10-24 23:55:53 +0000724 orderBy := options.OrderBy
725 if orderBy == "" {
Hardik Windlass9361bb82022-03-23 05:58:48 +0000726 orderBy = GetCommandOptionWithDefault("device-list", "order", DEFAULT_DEVICE_ORDER)
David Bainbridgea6722342019-10-24 23:55:53 +0000727 }
728
Scott Baker9173ed82020-05-19 08:30:12 -0700729 // Make sure json output prints an empty list, not "null"
730 if devices.Items == nil {
731 devices.Items = make([]*voltha.Device, 0)
Zack Williamse940c7a2019-08-21 14:25:39 -0700732 }
733
734 result := CommandResult{
735 Format: format.Format(outputFormat),
736 Filter: options.Filter,
David Bainbridgea6722342019-10-24 23:55:53 +0000737 OrderBy: orderBy,
Zack Williamse940c7a2019-08-21 14:25:39 -0700738 OutputAs: toOutputType(options.OutputAs),
739 NameLimit: options.NameLimit,
Scott Baker9173ed82020-05-19 08:30:12 -0700740 Data: devices.Items,
Zack Williamse940c7a2019-08-21 14:25:39 -0700741 }
742
743 GenerateOutput(&result)
744 return nil
745}
746
747func (options *DeviceCreate) Execute(args []string) error {
748
Scott Baker9173ed82020-05-19 08:30:12 -0700749 device := voltha.Device{}
Zack Williamse940c7a2019-08-21 14:25:39 -0700750 if options.HostAndPort != "" {
Scott Baker9173ed82020-05-19 08:30:12 -0700751 device.Address = &voltha.Device_HostAndPort{HostAndPort: options.HostAndPort}
Zack Williamse940c7a2019-08-21 14:25:39 -0700752 } else if options.IPAddress != "" {
Scott Baker9173ed82020-05-19 08:30:12 -0700753 device.Address = &voltha.Device_Ipv4Address{Ipv4Address: options.IPAddress}
Hardik Windlassce1de342020-02-04 21:58:07 +0000754 }
755 if options.MACAddress != "" {
Scott Baker9173ed82020-05-19 08:30:12 -0700756 device.MacAddress = strings.ToLower(options.MACAddress)
Zack Williamse940c7a2019-08-21 14:25:39 -0700757 }
758 if options.DeviceType != "" {
Scott Baker9173ed82020-05-19 08:30:12 -0700759 device.Type = options.DeviceType
Zack Williamse940c7a2019-08-21 14:25:39 -0700760 }
761
762 conn, err := NewConnection()
763 if err != nil {
764 return err
765 }
766 defer conn.Close()
767
Scott Baker9173ed82020-05-19 08:30:12 -0700768 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700769
David K. Bainbridge9189c632021-03-26 21:52:21 +0000770 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700771 defer cancel()
772
Scott Baker9173ed82020-05-19 08:30:12 -0700773 createdDevice, err := client.CreateDevice(ctx, &device)
Zack Williamse940c7a2019-08-21 14:25:39 -0700774 if err != nil {
775 return err
Zack Williamse940c7a2019-08-21 14:25:39 -0700776 }
777
Scott Baker9173ed82020-05-19 08:30:12 -0700778 fmt.Printf("%s\n", createdDevice.Id)
Zack Williamse940c7a2019-08-21 14:25:39 -0700779
780 return nil
781}
782
783func (options *DeviceDelete) Execute(args []string) error {
784
785 conn, err := NewConnection()
786 if err != nil {
787 return err
788 }
789 defer conn.Close()
790
Scott Baker9173ed82020-05-19 08:30:12 -0700791 client := voltha.NewVolthaServiceClient(conn)
David Bainbridge7052fe82020-03-25 10:37:00 -0700792 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -0700793 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +0000794 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700795 defer cancel()
796
Scott Baker9173ed82020-05-19 08:30:12 -0700797 id := voltha.ID{Id: string(i)}
Himani Chawla9933ddc2020-10-12 23:53:27 +0530798 if options.Force {
799 _, err = client.ForceDeleteDevice(ctx, &id)
800 } else {
801 _, err = client.DeleteDevice(ctx, &id)
802 }
Scott Baker9173ed82020-05-19 08:30:12 -0700803
Zack Williamse940c7a2019-08-21 14:25:39 -0700804 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +0000805 Error.Printf("Error while deleting '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -0700806 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -0700807 continue
Zack Williamse940c7a2019-08-21 14:25:39 -0700808 }
809 fmt.Printf("%s\n", i)
810 }
811
David Bainbridge7052fe82020-03-25 10:37:00 -0700812 if lastErr != nil {
813 return NoReportErr
814 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700815 return nil
816}
817
818func (options *DeviceEnable) Execute(args []string) error {
819 conn, err := NewConnection()
820 if err != nil {
821 return err
822 }
823 defer conn.Close()
824
Scott Baker9173ed82020-05-19 08:30:12 -0700825 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700826
David Bainbridge7052fe82020-03-25 10:37:00 -0700827 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -0700828 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +0000829 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700830 defer cancel()
831
Scott Baker9173ed82020-05-19 08:30:12 -0700832 id := voltha.ID{Id: string(i)}
833
834 _, err := client.EnableDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -0700835 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +0000836 Error.Printf("Error while enabling '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -0700837 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -0700838 continue
Zack Williamse940c7a2019-08-21 14:25:39 -0700839 }
840 fmt.Printf("%s\n", i)
841 }
842
David Bainbridge7052fe82020-03-25 10:37:00 -0700843 if lastErr != nil {
844 return NoReportErr
845 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700846 return nil
847}
848
849func (options *DeviceDisable) Execute(args []string) error {
850 conn, err := NewConnection()
851 if err != nil {
852 return err
853 }
854 defer conn.Close()
855
Scott Baker9173ed82020-05-19 08:30:12 -0700856 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700857
David Bainbridge7052fe82020-03-25 10:37:00 -0700858 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -0700859 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +0000860 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700861 defer cancel()
862
Scott Baker9173ed82020-05-19 08:30:12 -0700863 id := voltha.ID{Id: string(i)}
864
865 _, err := client.DisableDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -0700866 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +0000867 Error.Printf("Error while disabling '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -0700868 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -0700869 continue
Zack Williamse940c7a2019-08-21 14:25:39 -0700870 }
871 fmt.Printf("%s\n", i)
872 }
873
David Bainbridge7052fe82020-03-25 10:37:00 -0700874 if lastErr != nil {
875 return NoReportErr
876 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700877 return nil
878}
879
880func (options *DeviceReboot) Execute(args []string) error {
881 conn, err := NewConnection()
882 if err != nil {
883 return err
884 }
885 defer conn.Close()
886
Scott Baker9173ed82020-05-19 08:30:12 -0700887 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700888
David Bainbridge7052fe82020-03-25 10:37:00 -0700889 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -0700890 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +0000891 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700892 defer cancel()
893
Scott Baker9173ed82020-05-19 08:30:12 -0700894 id := voltha.ID{Id: string(i)}
895
896 _, err := client.RebootDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -0700897 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +0000898 Error.Printf("Error while rebooting '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -0700899 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -0700900 continue
Zack Williamse940c7a2019-08-21 14:25:39 -0700901 }
902 fmt.Printf("%s\n", i)
903 }
904
David Bainbridge7052fe82020-03-25 10:37:00 -0700905 if lastErr != nil {
906 return NoReportErr
907 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700908 return nil
909}
910
911func (options *DevicePortList) Execute(args []string) error {
912
913 conn, err := NewConnection()
914 if err != nil {
915 return err
916 }
917 defer conn.Close()
918
Scott Baker9173ed82020-05-19 08:30:12 -0700919 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700920
David K. Bainbridge9189c632021-03-26 21:52:21 +0000921 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700922 defer cancel()
923
Scott Baker9173ed82020-05-19 08:30:12 -0700924 id := voltha.ID{Id: string(options.Args.Id)}
Zack Williamse940c7a2019-08-21 14:25:39 -0700925
Scott Baker9173ed82020-05-19 08:30:12 -0700926 ports, err := client.ListDevicePorts(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -0700927 if err != nil {
928 return err
929 }
930
931 outputFormat := CharReplacer.Replace(options.Format)
932 if outputFormat == "" {
David Bainbridgea6722342019-10-24 23:55:53 +0000933 outputFormat = GetCommandOptionWithDefault("device-ports", "format", DEFAULT_DEVICE_PORTS_FORMAT)
Zack Williamse940c7a2019-08-21 14:25:39 -0700934 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700935
David Bainbridgea6722342019-10-24 23:55:53 +0000936 orderBy := options.OrderBy
937 if orderBy == "" {
938 orderBy = GetCommandOptionWithDefault("device-ports", "order", "")
939 }
940
Zack Williamse940c7a2019-08-21 14:25:39 -0700941 result := CommandResult{
942 Format: format.Format(outputFormat),
943 Filter: options.Filter,
David Bainbridgea6722342019-10-24 23:55:53 +0000944 OrderBy: orderBy,
Zack Williamse940c7a2019-08-21 14:25:39 -0700945 OutputAs: toOutputType(options.OutputAs),
946 NameLimit: options.NameLimit,
Scott Baker9173ed82020-05-19 08:30:12 -0700947 Data: ports.Items,
Zack Williamse940c7a2019-08-21 14:25:39 -0700948 }
949
950 GenerateOutput(&result)
951 return nil
952}
953
954func (options *DeviceFlowList) Execute(args []string) error {
955 fl := &FlowList{}
956 fl.ListOutputOptions = options.ListOutputOptions
Maninder045921e2020-09-29 16:46:02 +0530957 fl.FlowIdOptions = options.FlowIdOptions
Zack Williamse940c7a2019-08-21 14:25:39 -0700958 fl.Args.Id = string(options.Args.Id)
David Bainbridgea6722342019-10-24 23:55:53 +0000959 fl.Method = "device-flows"
Zack Williamse940c7a2019-08-21 14:25:39 -0700960 return fl.Execute(args)
961}
962
Himani Chawla3c161c62021-05-13 16:36:51 +0530963func (options *DeviceFlowGroupList) Execute(args []string) error {
964 grp := &GroupList{}
965 grp.ListOutputOptions = options.ListOutputOptions
966 grp.GroupListOptions = options.GroupListOptions
967 grp.Args.Id = string(options.Args.Id)
968 grp.Method = "device-groups"
969 return grp.Execute(args)
970}
971
Zack Williamse940c7a2019-08-21 14:25:39 -0700972func (options *DeviceInspect) Execute(args []string) error {
973 if len(args) > 0 {
974 return fmt.Errorf("only a single argument 'DEVICE_ID' can be provided")
975 }
976
977 conn, err := NewConnection()
978 if err != nil {
979 return err
980 }
981 defer conn.Close()
982
Scott Baker9173ed82020-05-19 08:30:12 -0700983 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700984
David K. Bainbridge9189c632021-03-26 21:52:21 +0000985 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700986 defer cancel()
987
Scott Baker9173ed82020-05-19 08:30:12 -0700988 id := voltha.ID{Id: string(options.Args.Id)}
Zack Williamse940c7a2019-08-21 14:25:39 -0700989
Scott Baker9173ed82020-05-19 08:30:12 -0700990 device, err := client.GetDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -0700991 if err != nil {
992 return err
993 }
994
Zack Williamse940c7a2019-08-21 14:25:39 -0700995 outputFormat := CharReplacer.Replace(options.Format)
996 if outputFormat == "" {
David Bainbridgea6722342019-10-24 23:55:53 +0000997 outputFormat = GetCommandOptionWithDefault("device-inspect", "format", DEFAULT_DEVICE_INSPECT_FORMAT)
Zack Williamse940c7a2019-08-21 14:25:39 -0700998 }
999 if options.Quiet {
1000 outputFormat = "{{.Id}}"
1001 }
1002
1003 result := CommandResult{
1004 Format: format.Format(outputFormat),
1005 OutputAs: toOutputType(options.OutputAs),
1006 NameLimit: options.NameLimit,
1007 Data: device,
1008 }
1009 GenerateOutput(&result)
1010 return nil
1011}
kesavand12cd8eb2020-01-20 22:25:22 -05001012
1013/*Device Port Enable */
1014func (options *DevicePortEnable) Execute(args []string) error {
1015 conn, err := NewConnection()
1016 if err != nil {
1017 return err
1018 }
1019 defer conn.Close()
1020
Scott Baker9173ed82020-05-19 08:30:12 -07001021 client := voltha.NewVolthaServiceClient(conn)
kesavand12cd8eb2020-01-20 22:25:22 -05001022
David K. Bainbridge9189c632021-03-26 21:52:21 +00001023 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand12cd8eb2020-01-20 22:25:22 -05001024 defer cancel()
1025
Scott Baker9173ed82020-05-19 08:30:12 -07001026 port := voltha.Port{DeviceId: string(options.Args.Id), PortNo: uint32(options.Args.PortId)}
1027
1028 _, err = client.EnablePort(ctx, &port)
kesavand12cd8eb2020-01-20 22:25:22 -05001029 if err != nil {
1030 Error.Printf("Error enabling port number %v on device Id %s,err=%s\n", options.Args.PortId, options.Args.Id, ErrorToString(err))
1031 return err
kesavand12cd8eb2020-01-20 22:25:22 -05001032 }
1033
1034 return nil
1035}
1036
Scott Baker9173ed82020-05-19 08:30:12 -07001037/*Device Port Disable */
kesavand12cd8eb2020-01-20 22:25:22 -05001038func (options *DevicePortDisable) Execute(args []string) error {
1039 conn, err := NewConnection()
1040 if err != nil {
1041 return err
1042 }
1043 defer conn.Close()
1044
Scott Baker9173ed82020-05-19 08:30:12 -07001045 client := voltha.NewVolthaServiceClient(conn)
1046
David K. Bainbridge9189c632021-03-26 21:52:21 +00001047 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand12cd8eb2020-01-20 22:25:22 -05001048 defer cancel()
1049
Scott Baker9173ed82020-05-19 08:30:12 -07001050 port := voltha.Port{DeviceId: string(options.Args.Id), PortNo: uint32(options.Args.PortId)}
1051
1052 _, err = client.DisablePort(ctx, &port)
kesavand12cd8eb2020-01-20 22:25:22 -05001053 if err != nil {
Scott Baker9173ed82020-05-19 08:30:12 -07001054 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 -05001055 return err
kesavand12cd8eb2020-01-20 22:25:22 -05001056 }
Scott Baker9173ed82020-05-19 08:30:12 -07001057
kesavand12cd8eb2020-01-20 22:25:22 -05001058 return nil
1059}
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08001060
Rohan Agrawald7df3772020-06-29 11:23:36 +00001061func (options *DevicePmConfigSetMaxSkew) Execute(args []string) error {
1062 conn, err := NewConnection()
1063 if err != nil {
1064 return err
1065 }
1066 defer conn.Close()
1067
1068 client := voltha.NewVolthaServiceClient(conn)
1069
David K. Bainbridge9189c632021-03-26 21:52:21 +00001070 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawald7df3772020-06-29 11:23:36 +00001071 defer cancel()
1072
1073 id := voltha.ID{Id: string(options.Args.Id)}
1074
1075 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1076 if err != nil {
1077 return err
1078 }
1079
1080 pmConfigs.MaxSkew = options.Args.MaxSkew
1081
1082 _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs)
1083 if err != nil {
1084 return err
1085 }
1086
1087 return nil
1088}
1089
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001090func (options *DevicePmConfigsGet) Execute(args []string) error {
1091
1092 conn, err := NewConnection()
1093 if err != nil {
1094 return err
1095 }
1096 defer conn.Close()
1097
1098 client := voltha.NewVolthaServiceClient(conn)
1099
David K. Bainbridge9189c632021-03-26 21:52:21 +00001100 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001101 defer cancel()
1102
1103 id := voltha.ID{Id: string(options.Args.Id)}
1104
1105 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1106 if err != nil {
1107 return err
1108 }
1109
1110 outputFormat := CharReplacer.Replace(options.Format)
1111 if outputFormat == "" {
1112 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GET_FORMAT)
1113 }
1114
1115 orderBy := options.OrderBy
1116 if orderBy == "" {
1117 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1118 }
1119
1120 result := CommandResult{
1121 Format: format.Format(outputFormat),
1122 Filter: options.Filter,
1123 OrderBy: orderBy,
1124 OutputAs: toOutputType(options.OutputAs),
1125 NameLimit: options.NameLimit,
1126 Data: pmConfigs,
1127 }
1128
1129 GenerateOutput(&result)
1130 return nil
1131
1132}
1133
1134func (options *DevicePmConfigMetricList) Execute(args []string) error {
1135
1136 conn, err := NewConnection()
1137 if err != nil {
1138 return err
1139 }
1140 defer conn.Close()
1141
1142 client := voltha.NewVolthaServiceClient(conn)
1143
David K. Bainbridge9189c632021-03-26 21:52:21 +00001144 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001145 defer cancel()
1146
1147 id := voltha.ID{Id: string(options.Args.Id)}
1148
1149 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1150 if err != nil {
1151 return err
1152 }
1153
1154 if !pmConfigs.Grouped {
1155 for _, metric := range pmConfigs.Metrics {
1156 if metric.SampleFreq == 0 {
1157 metric.SampleFreq = pmConfigs.DefaultFreq
1158 }
1159 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001160 outputFormat := CharReplacer.Replace(options.Format)
1161 if outputFormat == "" {
1162 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_METRIC_LIST_FORMAT)
1163 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001164
Rohan Agrawalbca69122020-06-17 14:59:03 +00001165 orderBy := options.OrderBy
1166 if orderBy == "" {
1167 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1168 }
1169
1170 result := CommandResult{
1171 Format: format.Format(outputFormat),
1172 Filter: options.Filter,
1173 OrderBy: orderBy,
1174 OutputAs: toOutputType(options.OutputAs),
1175 NameLimit: options.NameLimit,
1176 Data: pmConfigs.Metrics,
1177 }
1178
1179 GenerateOutput(&result)
1180 return nil
1181 } else {
1182 return fmt.Errorf("Device '%s' does not have Non Grouped Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001183 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001184}
1185
1186func (options *DevicePmConfigMetricEnable) Execute(args []string) error {
1187
1188 conn, err := NewConnection()
1189 if err != nil {
1190 return err
1191 }
1192 defer conn.Close()
1193
1194 client := voltha.NewVolthaServiceClient(conn)
1195
David K. Bainbridge9189c632021-03-26 21:52:21 +00001196 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001197 defer cancel()
1198
1199 id := voltha.ID{Id: string(options.Args.Id)}
1200
1201 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1202 if err != nil {
1203 return err
1204 }
1205
1206 if !pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001207 metrics := make(map[string]struct{})
1208 for _, metric := range pmConfigs.Metrics {
1209 metrics[metric.Name] = struct{}{}
1210 }
1211
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001212 for _, metric := range pmConfigs.Metrics {
1213 for _, mName := range options.Args.Metrics {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001214 if _, exist := metrics[string(mName)]; !exist {
1215 return fmt.Errorf("Metric Name '%s' does not exist", mName)
1216 }
1217
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001218 if string(mName) == metric.Name && !metric.Enabled {
1219 metric.Enabled = true
1220 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1221 if err != nil {
1222 return err
1223 }
1224 }
1225 }
1226 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001227 } else {
1228 return fmt.Errorf("Device '%s' does not have Non Grouped Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001229 }
1230 return nil
1231}
1232
1233func (options *DevicePmConfigMetricDisable) Execute(args []string) error {
1234
1235 conn, err := NewConnection()
1236 if err != nil {
1237 return err
1238 }
1239 defer conn.Close()
1240
1241 client := voltha.NewVolthaServiceClient(conn)
1242
David K. Bainbridge9189c632021-03-26 21:52:21 +00001243 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001244 defer cancel()
1245
1246 id := voltha.ID{Id: string(options.Args.Id)}
1247
1248 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1249 if err != nil {
1250 return err
1251 }
1252
1253 if !pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001254 metrics := make(map[string]struct{})
1255 for _, metric := range pmConfigs.Metrics {
1256 metrics[metric.Name] = struct{}{}
1257 }
1258
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001259 for _, metric := range pmConfigs.Metrics {
1260 for _, mName := range options.Args.Metrics {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001261 if _, have := metrics[string(mName)]; !have {
1262 return fmt.Errorf("Metric Name '%s' does not exist", mName)
1263 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001264 if string(mName) == metric.Name && metric.Enabled {
1265 metric.Enabled = false
1266 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1267 if err != nil {
1268 return err
1269 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001270 } else {
1271 return fmt.Errorf("Metric '%s' cannot be disabled", string(mName))
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001272 }
1273 }
1274 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001275 } else {
1276 return fmt.Errorf("Device '%s' does not have Non Grouped Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001277 }
1278 return nil
1279}
1280
1281func (options *DevicePmConfigGroupEnable) Execute(args []string) error {
1282
1283 conn, err := NewConnection()
1284 if err != nil {
1285 return err
1286 }
1287 defer conn.Close()
1288
1289 client := voltha.NewVolthaServiceClient(conn)
1290
David K. Bainbridge9189c632021-03-26 21:52:21 +00001291 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001292 defer cancel()
1293
1294 id := voltha.ID{Id: string(options.Args.Id)}
1295
1296 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1297 if err != nil {
1298 return err
1299 }
1300
1301 if pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001302 groups := make(map[string]struct{})
1303 for _, group := range pmConfigs.Groups {
1304 groups[group.GroupName] = struct{}{}
1305 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001306 for _, group := range pmConfigs.Groups {
Girish Gowdra610acb42021-01-27 13:33:57 -08001307 if _, have := groups[string(options.Args.Group)]; !have {
1308 return fmt.Errorf("Group Name '%s' does not exist", options.Args.Group)
1309 }
1310 if string(options.Args.Group) == group.GroupName && !group.Enabled {
1311 group.Enabled = true
1312 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1313 if err != nil {
1314 return err
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001315 }
1316 }
1317 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001318 } else {
1319 return fmt.Errorf("Device '%s' does not have Group Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001320 }
1321 return nil
1322}
1323
1324func (options *DevicePmConfigGroupDisable) Execute(args []string) error {
1325
1326 conn, err := NewConnection()
1327 if err != nil {
1328 return err
1329 }
1330 defer conn.Close()
1331
1332 client := voltha.NewVolthaServiceClient(conn)
1333
David K. Bainbridge9189c632021-03-26 21:52:21 +00001334 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001335 defer cancel()
1336
1337 id := voltha.ID{Id: string(options.Args.Id)}
1338
1339 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1340 if err != nil {
1341 return err
1342 }
1343
1344 if pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001345 groups := make(map[string]struct{})
1346 for _, group := range pmConfigs.Groups {
1347 groups[group.GroupName] = struct{}{}
1348 }
1349
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001350 for _, group := range pmConfigs.Groups {
Girish Gowdra610acb42021-01-27 13:33:57 -08001351 if _, have := groups[string(options.Args.Group)]; !have {
1352 return fmt.Errorf("Group Name '%s' does not exist", options.Args.Group)
1353 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001354
Girish Gowdra610acb42021-01-27 13:33:57 -08001355 if string(options.Args.Group) == group.GroupName && group.Enabled {
1356 group.Enabled = false
1357 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1358 if err != nil {
1359 return err
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001360 }
1361 }
1362 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001363 } else {
1364 return fmt.Errorf("Device '%s' does not have Group Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001365 }
1366 return nil
1367}
1368
Girish Gowdra610acb42021-01-27 13:33:57 -08001369func (options *DevicePmConfigGroupFrequencySet) Execute(args []string) error {
1370
1371 conn, err := NewConnection()
1372 if err != nil {
1373 return err
1374 }
1375 defer conn.Close()
1376
1377 client := voltha.NewVolthaServiceClient(conn)
1378
David K. Bainbridge9189c632021-03-26 21:52:21 +00001379 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Girish Gowdra610acb42021-01-27 13:33:57 -08001380 defer cancel()
1381
1382 id := voltha.ID{Id: string(options.Args.Id)}
1383
1384 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1385 if err != nil {
1386 return err
1387 }
1388
1389 if pmConfigs.Grouped {
1390 groups := make(map[string]struct{})
1391 for _, group := range pmConfigs.Groups {
1392 groups[group.GroupName] = struct{}{}
1393 }
1394
1395 for _, group := range pmConfigs.Groups {
1396 if _, have := groups[string(options.Args.Group)]; !have {
1397 return fmt.Errorf("group name '%s' does not exist", options.Args.Group)
1398 }
1399
1400 if string(options.Args.Group) == group.GroupName {
1401 if !group.Enabled {
1402 return fmt.Errorf("group '%s' is not enabled", options.Args.Group)
1403 }
1404 group.GroupFreq = uint32(options.Args.Interval.Seconds())
1405 _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs)
1406 if err != nil {
1407 return err
1408 }
1409 }
1410 }
1411 } else {
1412 return fmt.Errorf("device '%s' does not have group metrics", options.Args.Id)
1413 }
1414 return nil
1415}
1416
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001417func (options *DevicePmConfigGroupList) Execute(args []string) error {
1418
1419 conn, err := NewConnection()
1420 if err != nil {
1421 return err
1422 }
1423 defer conn.Close()
1424
1425 client := voltha.NewVolthaServiceClient(conn)
1426
David K. Bainbridge9189c632021-03-26 21:52:21 +00001427 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001428 defer cancel()
1429
1430 id := voltha.ID{Id: string(options.Args.Id)}
1431
1432 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1433 if err != nil {
1434 return err
1435 }
1436
1437 if pmConfigs.Grouped {
1438 for _, group := range pmConfigs.Groups {
1439 if group.GroupFreq == 0 {
1440 group.GroupFreq = pmConfigs.DefaultFreq
1441 }
1442 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001443 outputFormat := CharReplacer.Replace(options.Format)
1444 if outputFormat == "" {
1445 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GROUP_LIST_FORMAT)
1446 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001447
Rohan Agrawalbca69122020-06-17 14:59:03 +00001448 orderBy := options.OrderBy
1449 if orderBy == "" {
1450 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1451 }
1452
1453 result := CommandResult{
1454 Format: format.Format(outputFormat),
1455 Filter: options.Filter,
1456 OrderBy: orderBy,
1457 OutputAs: toOutputType(options.OutputAs),
1458 NameLimit: options.NameLimit,
1459 Data: pmConfigs.Groups,
1460 }
1461
1462 GenerateOutput(&result)
1463 } else {
1464 return fmt.Errorf("Device '%s' does not have Group Metrics", string(options.Args.Id))
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001465 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001466 return nil
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001467}
1468
1469func (options *DevicePmConfigGroupMetricList) Execute(args []string) error {
1470
1471 var metrics []*voltha.PmConfig
1472 conn, err := NewConnection()
1473 if err != nil {
1474 return err
1475 }
1476 defer conn.Close()
1477
1478 client := voltha.NewVolthaServiceClient(conn)
1479
David K. Bainbridge9189c632021-03-26 21:52:21 +00001480 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001481 defer cancel()
1482
1483 id := voltha.ID{Id: string(options.Args.Id)}
1484
1485 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1486 if err != nil {
1487 return err
1488 }
1489
1490 for _, groups := range pmConfigs.Groups {
1491
1492 if string(options.Args.Group) == groups.GroupName {
1493 for _, metric := range groups.Metrics {
1494 if metric.SampleFreq == 0 && groups.GroupFreq == 0 {
1495 metric.SampleFreq = pmConfigs.DefaultFreq
1496 } else {
1497 metric.SampleFreq = groups.GroupFreq
1498 }
1499 }
1500 metrics = groups.Metrics
1501 }
1502 }
1503
1504 outputFormat := CharReplacer.Replace(options.Format)
1505 if outputFormat == "" {
1506 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_METRIC_LIST_FORMAT)
1507 }
1508
1509 orderBy := options.OrderBy
1510 if orderBy == "" {
1511 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1512 }
1513
1514 result := CommandResult{
1515 Format: format.Format(outputFormat),
1516 Filter: options.Filter,
1517 OrderBy: orderBy,
1518 OutputAs: toOutputType(options.OutputAs),
1519 NameLimit: options.NameLimit,
1520 Data: metrics,
1521 }
1522
1523 GenerateOutput(&result)
1524 return nil
1525
1526}
1527
1528func (options *DevicePmConfigFrequencySet) Execute(args []string) error {
1529
1530 conn, err := NewConnection()
1531 if err != nil {
1532 return err
1533 }
1534 defer conn.Close()
1535
1536 client := voltha.NewVolthaServiceClient(conn)
1537
David K. Bainbridge9189c632021-03-26 21:52:21 +00001538 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001539 defer cancel()
1540
1541 id := voltha.ID{Id: string(options.Args.Id)}
1542
1543 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1544 if err != nil {
1545 return err
1546 }
1547
Girish Gowdra610acb42021-01-27 13:33:57 -08001548 pmConfigs.DefaultFreq = uint32(options.Args.Interval.Seconds())
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001549
1550 _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs)
1551 if err != nil {
1552 return err
1553 }
1554
1555 outputFormat := CharReplacer.Replace(options.Format)
1556 if outputFormat == "" {
1557 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GET_FORMAT)
1558 }
1559 if options.Quiet {
1560 outputFormat = "{{.Id}}"
1561 }
1562
1563 result := CommandResult{
1564 Format: format.Format(outputFormat),
1565 OutputAs: toOutputType(options.OutputAs),
1566 NameLimit: options.NameLimit,
1567 Data: pmConfigs,
1568 }
1569
1570 GenerateOutput(&result)
1571 return nil
1572
1573}
1574
kesavand3e2f9f62021-04-22 11:06:38 +05301575func (options *OnuDownloadImage) Execute(args []string) error {
1576
1577 conn, err := NewConnection()
1578 if err != nil {
1579 return err
1580 }
1581 defer conn.Close()
1582
1583 client := voltha.NewVolthaServiceClient(conn)
1584
1585 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1586 defer cancel()
1587
1588 var devIDList []*common.ID
1589 for _, i := range options.Args.IDs {
1590
1591 devIDList = append(devIDList, &common.ID{Id: string(i)})
1592 }
1593
1594 downloadImage := voltha.DeviceImageDownloadRequest{
1595 DeviceId: devIDList,
1596 Image: &voltha.Image{
1597 Url: options.Args.Url,
1598 Crc32: options.Args.Crc,
ssiddiqui7bc89e92021-05-20 20:58:02 +05301599 Vendor: options.Args.Vendor,
kesavand3e2f9f62021-04-22 11:06:38 +05301600 Version: options.Args.ImageVersion,
1601 },
1602 ActivateOnSuccess: options.Args.ActivateOnSuccess,
1603 CommitOnSuccess: options.Args.CommitOnSuccess,
1604 }
1605
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001606 deviceImageResp, err := client.DownloadImageToDevice(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301607 if err != nil {
1608 return err
1609 }
1610
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001611 outputFormat := GetCommandOptionWithDefault("onu-image-download", "format", ONU_IMAGE_STATUS_FORMAT)
1612 // Make sure json output prints an empty list, not "null"
1613 if deviceImageResp.DeviceImageStates == nil {
1614 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1615 }
1616 result := CommandResult{
1617 Format: format.Format(outputFormat),
1618 OutputAs: toOutputType(options.OutputAs),
1619 NameLimit: options.NameLimit,
1620 Data: deviceImageResp.DeviceImageStates,
1621 }
1622 GenerateOutput(&result)
kesavand3e2f9f62021-04-22 11:06:38 +05301623 return nil
1624
1625}
1626
1627func (options *OnuActivateImage) Execute(args []string) error {
1628
1629 conn, err := NewConnection()
1630 if err != nil {
1631 return err
1632 }
1633 defer conn.Close()
1634
1635 client := voltha.NewVolthaServiceClient(conn)
1636
1637 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1638 defer cancel()
1639
1640 var devIDList []*common.ID
1641 for _, i := range options.Args.IDs {
1642
1643 devIDList = append(devIDList, &common.ID{Id: string(i)})
1644 }
1645
1646 downloadImage := voltha.DeviceImageRequest{
1647 DeviceId: devIDList,
1648 Version: options.Args.ImageVersion,
1649 CommitOnSuccess: options.Args.CommitOnSuccess,
1650 }
1651
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001652 deviceImageResp, err := client.ActivateImage(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301653 if err != nil {
1654 return err
1655 }
1656
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001657 outputFormat := GetCommandOptionWithDefault("onu-image-activate", "format", ONU_IMAGE_STATUS_FORMAT)
1658 // Make sure json output prints an empty list, not "null"
1659 if deviceImageResp.DeviceImageStates == nil {
1660 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1661 }
1662 result := CommandResult{
1663 Format: format.Format(outputFormat),
1664 OutputAs: toOutputType(options.OutputAs),
1665 NameLimit: options.NameLimit,
1666 Data: deviceImageResp.DeviceImageStates,
1667 }
1668 GenerateOutput(&result)
1669
kesavand3e2f9f62021-04-22 11:06:38 +05301670 return nil
1671
1672}
1673
1674func (options *OnuAbortUpgradeImage) Execute(args []string) error {
1675
1676 conn, err := NewConnection()
1677 if err != nil {
1678 return err
1679 }
1680 defer conn.Close()
1681
1682 client := voltha.NewVolthaServiceClient(conn)
1683
1684 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1685 defer cancel()
1686
1687 var devIDList []*common.ID
1688 for _, i := range options.Args.IDs {
1689
1690 devIDList = append(devIDList, &common.ID{Id: string(i)})
1691 }
1692
1693 downloadImage := voltha.DeviceImageRequest{
1694 DeviceId: devIDList,
1695 Version: options.Args.ImageVersion,
1696 }
1697
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001698 deviceImageResp, err := client.AbortImageUpgradeToDevice(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301699 if err != nil {
1700 return err
1701 }
1702
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001703 outputFormat := GetCommandOptionWithDefault("onu-image-abort", "format", ONU_IMAGE_STATUS_FORMAT)
1704 // Make sure json output prints an empty list, not "null"
1705 if deviceImageResp.DeviceImageStates == nil {
1706 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1707 }
1708 result := CommandResult{
1709 Format: format.Format(outputFormat),
1710 OutputAs: toOutputType(options.OutputAs),
1711 NameLimit: options.NameLimit,
1712 Data: deviceImageResp.DeviceImageStates,
1713 }
1714 GenerateOutput(&result)
1715
kesavand3e2f9f62021-04-22 11:06:38 +05301716 return nil
1717
1718}
1719
1720func (options *OnuCommitImage) Execute(args []string) error {
1721
1722 conn, err := NewConnection()
1723 if err != nil {
1724 return err
1725 }
1726 defer conn.Close()
1727
1728 client := voltha.NewVolthaServiceClient(conn)
1729
1730 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1731 defer cancel()
1732
1733 var devIDList []*common.ID
1734 for _, i := range options.Args.IDs {
1735
1736 devIDList = append(devIDList, &common.ID{Id: string(i)})
1737 }
1738 downloadImage := voltha.DeviceImageRequest{
1739 DeviceId: devIDList,
1740 Version: options.Args.ImageVersion,
1741 }
1742
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001743 deviceImageResp, err := client.CommitImage(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301744 if err != nil {
1745 return err
1746 }
1747
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001748 outputFormat := GetCommandOptionWithDefault("onu-image-commit", "format", ONU_IMAGE_STATUS_FORMAT)
1749 // Make sure json output prints an empty list, not "null"
1750 if deviceImageResp.DeviceImageStates == nil {
1751 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1752 }
1753 result := CommandResult{
1754 Format: format.Format(outputFormat),
1755 OutputAs: toOutputType(options.OutputAs),
1756 NameLimit: options.NameLimit,
1757 Data: deviceImageResp.DeviceImageStates,
1758 }
1759 GenerateOutput(&result)
1760
kesavand3e2f9f62021-04-22 11:06:38 +05301761 return nil
1762
1763}
1764
1765func (options *OnuListImages) Execute(args []string) error {
1766
1767 conn, err := NewConnection()
1768 if err != nil {
1769 return err
1770 }
1771 defer conn.Close()
1772
1773 client := voltha.NewVolthaServiceClient(conn)
1774
1775 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1776 defer cancel()
1777
1778 id := common.ID{Id: string(options.Args.Id)}
1779
1780 onuImages, err := client.GetOnuImages(ctx, &id)
1781 if err != nil {
1782 return err
1783 }
1784
1785 outputFormat := CharReplacer.Replace(options.Format)
1786 if outputFormat == "" {
1787 outputFormat = GetCommandOptionWithDefault("onu-image-list", "format", ONU_IMAGE_LIST_FORMAT)
1788 }
1789
1790 if options.Quiet {
1791 outputFormat = "{{.Id}}"
1792 }
1793
1794 //TODO orderby
1795
1796 // Make sure json output prints an empty list, not "null"
1797 if onuImages.Items == nil {
1798 onuImages.Items = make([]*voltha.OnuImage, 0)
1799 }
1800
1801 result := CommandResult{
1802 Format: format.Format(outputFormat),
1803 OutputAs: toOutputType(options.OutputAs),
1804 NameLimit: options.NameLimit,
1805 Data: onuImages.Items,
1806 }
1807
1808 GenerateOutput(&result)
1809 return nil
1810
1811}
1812
1813func (options *OnuImageStatus) Execute(args []string) error {
1814
1815 conn, err := NewConnection()
1816 if err != nil {
1817 return err
1818 }
1819 defer conn.Close()
1820
1821 client := voltha.NewVolthaServiceClient(conn)
1822
1823 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1824 defer cancel()
1825
1826 var devIDList []*common.ID
kesavand3e2f9f62021-04-22 11:06:38 +05301827
Elia Battiston859f3e62022-02-08 15:57:52 +01001828 if options.Args.IDs == nil {
1829 //Use an empty IDs list to retrieve the status of all devices
1830 //with the requested image version
1831 devIDList = []*common.ID{}
1832 } else {
1833 for _, i := range options.Args.IDs {
1834 devIDList = append(devIDList, &common.ID{Id: string(i)})
1835 }
kesavand3e2f9f62021-04-22 11:06:38 +05301836 }
1837
1838 imageStatusReq := voltha.DeviceImageRequest{
1839 DeviceId: devIDList,
1840 Version: options.Args.ImageVersion,
1841 }
1842 imageStatus, err := client.GetImageStatus(ctx, &imageStatusReq)
1843 if err != nil {
1844 return err
1845 }
1846
1847 outputFormat := CharReplacer.Replace(options.Format)
1848 if outputFormat == "" {
1849 outputFormat = GetCommandOptionWithDefault("device-image-list", "format", ONU_IMAGE_STATUS_FORMAT)
1850 }
1851
1852 if options.Quiet {
1853 outputFormat = "{{.Id}}"
1854 }
1855
1856 //TODO orderby
1857
1858 // Make sure json output prints an empty list, not "null"
1859 if imageStatus.DeviceImageStates == nil {
1860 imageStatus.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1861 }
1862
1863 result := CommandResult{
1864 Format: format.Format(outputFormat),
1865 OutputAs: toOutputType(options.OutputAs),
1866 NameLimit: options.NameLimit,
1867 Data: imageStatus.DeviceImageStates,
1868 }
1869
1870 GenerateOutput(&result)
1871 return nil
1872
1873}
1874
Andrea Campanella791d88b2021-01-08 13:29:00 +01001875func (options *DeviceOnuListImages) Execute(args []string) error {
1876
1877 conn, err := NewConnection()
1878 if err != nil {
1879 return err
1880 }
1881 defer conn.Close()
1882
1883 client := voltha.NewVolthaServiceClient(conn)
1884
David K. Bainbridge9189c632021-03-26 21:52:21 +00001885 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Andrea Campanella791d88b2021-01-08 13:29:00 +01001886 defer cancel()
1887
1888 id := common.ID{Id: string(options.Args.Id)}
1889
1890 imageDownloads, err := client.ListImageDownloads(ctx, &id)
1891 if err != nil {
1892 return err
1893 }
1894
1895 outputFormat := CharReplacer.Replace(options.Format)
1896 if outputFormat == "" {
1897 outputFormat = GetCommandOptionWithDefault("device-image-list", "format", DEFAULT_DEVICE_IMAGE_LIST_GET_FORMAT)
1898 }
1899
1900 if options.Quiet {
1901 outputFormat = "{{.Id}}"
1902 }
1903
1904 //TODO orderby
1905
1906 // Make sure json output prints an empty list, not "null"
1907 if imageDownloads.Items == nil {
1908 imageDownloads.Items = make([]*voltha.ImageDownload, 0)
1909 }
1910
1911 result := CommandResult{
1912 Format: format.Format(outputFormat),
1913 OutputAs: toOutputType(options.OutputAs),
1914 NameLimit: options.NameLimit,
1915 Data: imageDownloads.Items,
1916 }
1917
1918 GenerateOutput(&result)
1919 return nil
1920
1921}
1922
1923func (options *DeviceOnuDownloadImage) Execute(args []string) error {
1924
1925 conn, err := NewConnection()
1926 if err != nil {
1927 return err
1928 }
1929 defer conn.Close()
1930
1931 client := voltha.NewVolthaServiceClient(conn)
1932
David K. Bainbridge9189c632021-03-26 21:52:21 +00001933 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Andrea Campanella791d88b2021-01-08 13:29:00 +01001934 defer cancel()
1935
1936 downloadImage := voltha.ImageDownload{
1937 Id: string(options.Args.Id),
1938 Name: options.Args.Name,
1939 Url: options.Args.Url,
1940 Crc: options.Args.Crc,
1941 LocalDir: options.Args.LocalDir,
1942 }
1943
1944 _, err = client.DownloadImage(ctx, &downloadImage)
1945 if err != nil {
1946 return err
1947 }
1948
1949 return nil
1950
1951}
1952
1953func (options *DeviceOnuActivateImageUpdate) Execute(args []string) error {
1954
1955 conn, err := NewConnection()
1956 if err != nil {
1957 return err
1958 }
1959 defer conn.Close()
1960
1961 client := voltha.NewVolthaServiceClient(conn)
1962
David K. Bainbridge9189c632021-03-26 21:52:21 +00001963 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Andrea Campanella791d88b2021-01-08 13:29:00 +01001964 defer cancel()
1965
1966 downloadImage := voltha.ImageDownload{
1967 Id: string(options.Args.Id),
1968 Name: options.Args.Name,
1969 ImageVersion: options.Args.ImageVersion,
1970 SaveConfig: options.Args.SaveConfig,
1971 LocalDir: options.Args.LocalDir,
1972 }
1973
1974 _, err = client.ActivateImageUpdate(ctx, &downloadImage)
1975 if err != nil {
1976 return err
1977 }
1978
1979 return nil
1980
1981}
1982
Scott Baker9173ed82020-05-19 08:30:12 -07001983type ReturnValueRow struct {
1984 Name string `json:"name"`
1985 Result interface{} `json:"result"`
1986}
1987
kesavand8ec4fc02021-01-27 09:10:22 -05001988func (options *DeviceGetPortStats) Execute(args []string) error {
1989 conn, err := NewConnection()
1990 if err != nil {
1991 return err
1992 }
1993 defer conn.Close()
1994 client := extension.NewExtensionClient(conn)
1995 var portType extension.GetOltPortCounters_PortType
1996
1997 if options.Args.PortType == "pon" {
1998 portType = extension.GetOltPortCounters_Port_PON_OLT
1999 } else if options.Args.PortType == "nni" {
2000
2001 portType = extension.GetOltPortCounters_Port_ETHERNET_NNI
2002 } else {
2003 return fmt.Errorf("expected interface type pon/nni, provided %s", options.Args.PortType)
2004 }
2005
2006 singleGetValReq := extension.SingleGetValueRequest{
2007 TargetId: string(options.Args.Id),
2008 Request: &extension.GetValueRequest{
2009 Request: &extension.GetValueRequest_OltPortInfo{
2010 OltPortInfo: &extension.GetOltPortCounters{
2011 PortNo: options.Args.PortNo,
2012 PortType: portType,
2013 },
2014 },
2015 },
2016 }
2017
David K. Bainbridge9189c632021-03-26 21:52:21 +00002018 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand8ec4fc02021-01-27 09:10:22 -05002019 defer cancel()
2020 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2021 if err != nil {
2022 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2023 return err
2024 }
2025
2026 if rv.Response.Status != extension.GetValueResponse_OK {
2027 return fmt.Errorf("failed to get port stats %v", rv.Response.ErrReason.String())
2028 }
2029
2030 outputFormat := CharReplacer.Replace(options.Format)
2031 if outputFormat == "" {
2032 outputFormat = GetCommandOptionWithDefault("device-get-port-status", "format", DEFAULT_DEVICE_GET_PORT_STATUS_FORMAT)
2033 }
2034
2035 result := CommandResult{
2036 Format: format.Format(outputFormat),
2037 OutputAs: toOutputType(options.OutputAs),
2038 NameLimit: options.NameLimit,
2039 Data: rv.GetResponse().GetPortCoutners(),
2040 }
2041 GenerateOutput(&result)
2042 return nil
2043}
2044
Himani Chawla40acc122021-05-26 18:52:29 +05302045func (options *GetOnuStats) Execute(args []string) error {
2046 conn, err := NewConnection()
2047 if err != nil {
2048 return err
2049 }
2050 defer conn.Close()
2051 client := extension.NewExtensionClient(conn)
2052
2053 singleGetValReq := extension.SingleGetValueRequest{
2054 TargetId: string(options.Args.OltId),
2055 Request: &extension.GetValueRequest{
2056 Request: &extension.GetValueRequest_OnuPonInfo{
2057 OnuPonInfo: &extension.GetOnuCountersRequest{
2058 IntfId: options.Args.IntfId,
2059 OnuId: options.Args.OnuId,
2060 },
2061 },
2062 },
2063 }
2064 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2065 defer cancel()
2066 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2067 if err != nil {
2068 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.OltId, ErrorToString(err))
2069 return err
2070 }
2071
2072 if rv.Response.Status != extension.GetValueResponse_OK {
2073 return fmt.Errorf("failed to get onu stats %v", rv.Response.ErrReason.String())
2074 }
2075 outputFormat := CharReplacer.Replace(options.Format)
2076 data, formatStr := buildOnuStatsOutputFormat(rv.GetResponse().GetOnuPonCounters())
2077 if outputFormat == "" {
2078 outputFormat = GetCommandOptionWithDefault("device-get-onu-status", "format", formatStr)
2079 }
Himani Chawla553a1392021-06-10 23:39:17 +05302080 result := CommandResult{
2081 Format: format.Format(outputFormat),
2082 OutputAs: toOutputType(options.OutputAs),
2083 NameLimit: options.NameLimit,
2084 Data: data,
2085 }
2086 GenerateOutput(&result)
2087 return nil
2088}
Himani Chawla40acc122021-05-26 18:52:29 +05302089
Himani Chawla553a1392021-06-10 23:39:17 +05302090func (options *GetOnuEthernetFrameExtendedPmCounters) Execute(args []string) error {
2091 conn, err := NewConnection()
2092 if err != nil {
2093 return err
2094 }
2095 defer conn.Close()
2096 client := extension.NewExtensionClient(conn)
Himani Chawla806aa892021-08-30 15:51:46 +05302097 var singleGetValReq extension.SingleGetValueRequest
Himani Chawla553a1392021-06-10 23:39:17 +05302098
Himani Chawla806aa892021-08-30 15:51:46 +05302099 if options.Args.UniIndex != nil {
2100 singleGetValReq = extension.SingleGetValueRequest{
2101 TargetId: string(options.Args.Id),
2102 Request: &extension.GetValueRequest{
2103 Request: &extension.GetValueRequest_OnuInfo{
2104 OnuInfo: &extension.GetOmciEthernetFrameExtendedPmRequest{
2105 OnuDeviceId: string(options.Args.Id),
2106 Reset_: options.Reset,
2107 IsUniIndex: &extension.GetOmciEthernetFrameExtendedPmRequest_UniIndex{
2108 UniIndex: *options.Args.UniIndex,
2109 },
2110 },
Himani Chawla553a1392021-06-10 23:39:17 +05302111 },
2112 },
Himani Chawla806aa892021-08-30 15:51:46 +05302113 }
2114 } else {
2115 singleGetValReq = extension.SingleGetValueRequest{
2116 TargetId: string(options.Args.Id),
2117 Request: &extension.GetValueRequest{
2118 Request: &extension.GetValueRequest_OnuInfo{
2119 OnuInfo: &extension.GetOmciEthernetFrameExtendedPmRequest{
2120 OnuDeviceId: string(options.Args.Id),
2121 Reset_: options.Reset,
2122 },
2123 },
2124 },
2125 }
Himani Chawla553a1392021-06-10 23:39:17 +05302126 }
Himani Chawla806aa892021-08-30 15:51:46 +05302127
Himani Chawla553a1392021-06-10 23:39:17 +05302128 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2129 defer cancel()
2130 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2131 if err != nil {
2132 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2133 return err
2134 }
2135
2136 if rv.Response.Status != extension.GetValueResponse_OK {
2137 return fmt.Errorf("failed to get ethernet frame extended pm counters %v", rv.Response.ErrReason.String())
2138 }
2139 outputFormat := CharReplacer.Replace(options.Format)
2140 data := buildOnuEthernetFrameExtendedPmOutputFormat(rv.GetResponse().GetOnuCounters())
2141 if outputFormat == "" {
2142 outputFormat = GetCommandOptionWithDefault("device-get-onu-status", "format", DEFAULT_ETHERNET_FRAME_EXTENDED_PM_COUNTERS_FORMAT)
2143 }
Himani Chawla40acc122021-05-26 18:52:29 +05302144 result := CommandResult{
2145 Format: format.Format(outputFormat),
2146 OutputAs: toOutputType(options.OutputAs),
2147 NameLimit: options.NameLimit,
2148 Data: data,
2149 }
2150 GenerateOutput(&result)
2151 return nil
2152}
2153
kesavand6d1131f2021-02-05 22:38:15 +05302154func (options *UniStatus) Execute(args []string) error {
2155 conn, err := NewConnection()
2156 if err != nil {
2157 return err
2158 }
2159 defer conn.Close()
2160 client := extension.NewExtensionClient(conn)
2161
2162 singleGetValReq := extension.SingleGetValueRequest{
2163 TargetId: string(options.Args.Id),
2164 Request: &extension.GetValueRequest{
2165 Request: &extension.GetValueRequest_UniInfo{
2166 UniInfo: &extension.GetOnuUniInfoRequest{
2167 UniIndex: options.Args.UniIndex,
2168 },
2169 },
2170 },
2171 }
David K. Bainbridge9189c632021-03-26 21:52:21 +00002172 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand6d1131f2021-02-05 22:38:15 +05302173 defer cancel()
2174 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2175 if err != nil {
2176 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2177 return err
2178 }
2179 if rv.Response.Status != extension.GetValueResponse_OK {
2180 return fmt.Errorf("failed to get uni status %v", rv.Response.ErrReason.String())
2181 }
2182 outputFormat := CharReplacer.Replace(options.Format)
2183 if outputFormat == "" {
2184 outputFormat = GetCommandOptionWithDefault("device-get-uni-status", "format", DEFAULT_DEVICE_GET_UNI_STATUS_FORMAT)
2185 }
2186 result := CommandResult{
2187 Format: format.Format(outputFormat),
2188 OutputAs: toOutputType(options.OutputAs),
2189 NameLimit: options.NameLimit,
2190 Data: rv.GetResponse().GetUniInfo(),
2191 }
2192 GenerateOutput(&result)
2193 return nil
2194}
2195
Girish Gowdra4f5ce7c2021-04-29 18:53:21 -07002196func (options *OnuPonOpticalInfo) Execute(args []string) error {
2197 conn, err := NewConnection()
2198 if err != nil {
2199 return err
2200 }
2201 defer conn.Close()
2202 client := extension.NewExtensionClient(conn)
2203
2204 singleGetValReq := extension.SingleGetValueRequest{
2205 TargetId: string(options.Args.Id),
2206 Request: &extension.GetValueRequest{
2207 Request: &extension.GetValueRequest_OnuOpticalInfo{
2208 OnuOpticalInfo: &extension.GetOnuPonOpticalInfo{},
2209 },
2210 },
2211 }
2212 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2213 defer cancel()
2214 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2215 if err != nil {
2216 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2217 return err
2218 }
2219 if rv.Response.Status != extension.GetValueResponse_OK {
2220 return fmt.Errorf("failed to get onu pon optical info %v", rv.Response.ErrReason.String())
2221 }
2222 outputFormat := CharReplacer.Replace(options.Format)
2223 if outputFormat == "" {
2224 outputFormat = GetCommandOptionWithDefault("device-get-onu-pon-optical-info", "format", DEFAULT_ONU_PON_OPTICAL_INFO_STATUS_FORMAT)
2225 }
2226 result := CommandResult{
2227 Format: format.Format(outputFormat),
2228 OutputAs: toOutputType(options.OutputAs),
2229 NameLimit: options.NameLimit,
2230 Data: rv.GetResponse().GetOnuOpticalInfo(),
2231 }
2232 GenerateOutput(&result)
2233 return nil
2234}
2235
Gamze Abakac857a462021-05-26 13:45:54 +00002236func (options *RxPower) Execute(args []string) error {
2237 conn, err := NewConnection()
2238 if err != nil {
2239 return err
2240 }
2241 defer conn.Close()
2242 client := extension.NewExtensionClient(conn)
2243
2244 singleGetValReq := extension.SingleGetValueRequest{
2245 TargetId: string(options.Args.Id),
2246 Request: &extension.GetValueRequest{
2247 Request: &extension.GetValueRequest_RxPower{
2248 RxPower: &extension.GetRxPowerRequest{
2249 IntfId: options.Args.PortNo,
2250 OnuId: options.Args.OnuNo,
2251 },
2252 },
2253 },
2254 }
2255
2256 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2257 defer cancel()
2258 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2259 if err != nil {
2260 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2261 return err
2262 }
2263 if rv.Response.Status != extension.GetValueResponse_OK {
2264 return fmt.Errorf("failed to get rx power %v", rv.Response.ErrReason.String())
2265 }
2266 outputFormat := CharReplacer.Replace(options.Format)
2267 if outputFormat == "" {
2268 outputFormat = GetCommandOptionWithDefault("device-get-rx-power", "format", DEFAULT_RX_POWER_STATUS_FORMAT)
2269 }
2270 result := CommandResult{
2271 Format: format.Format(outputFormat),
2272 OutputAs: toOutputType(options.OutputAs),
2273 NameLimit: options.NameLimit,
2274 Data: rv.GetResponse().GetRxPower(),
2275 }
2276 GenerateOutput(&result)
2277 return nil
2278}
2279
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002280/*Device get Onu Distance */
2281func (options *DeviceGetExtValue) Execute(args []string) error {
2282 conn, err := NewConnection()
2283 if err != nil {
2284 return err
2285 }
2286 defer conn.Close()
2287
Scott Baker9173ed82020-05-19 08:30:12 -07002288 client := voltha.NewVolthaServiceClient(conn)
2289
khenaidoo080ce882021-10-19 17:35:08 -04002290 valueflag, okay := extension.ValueType_Type_value[string(options.Args.Valueflag)]
Scott Baker9173ed82020-05-19 08:30:12 -07002291 if !okay {
2292 Error.Printf("Unknown valueflag %s\n", options.Args.Valueflag)
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002293 }
2294
khenaidoo080ce882021-10-19 17:35:08 -04002295 val := extension.ValueSpecifier{Id: string(options.Args.Id), Value: extension.ValueType_Type(valueflag)}
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002296
David K. Bainbridge9189c632021-03-26 21:52:21 +00002297 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002298 defer cancel()
2299
Scott Baker9173ed82020-05-19 08:30:12 -07002300 rv, err := client.GetExtValue(ctx, &val)
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002301 if err != nil {
2302 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2303 return err
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002304 }
2305
Scott Baker9173ed82020-05-19 08:30:12 -07002306 var rows []ReturnValueRow
khenaidoo080ce882021-10-19 17:35:08 -04002307 for name, num := range extension.ValueType_Type_value {
Scott Baker9173ed82020-05-19 08:30:12 -07002308 if num == 0 {
2309 // EMPTY is not a real value
2310 continue
2311 }
2312 if (rv.Error & uint32(num)) != 0 {
2313 row := ReturnValueRow{Name: name, Result: "Error"}
2314 rows = append(rows, row)
2315 }
2316 if (rv.Unsupported & uint32(num)) != 0 {
2317 row := ReturnValueRow{Name: name, Result: "Unsupported"}
2318 rows = append(rows, row)
2319 }
2320 if (rv.Set & uint32(num)) != 0 {
2321 switch name {
2322 case "DISTANCE":
2323 row := ReturnValueRow{Name: name, Result: rv.Distance}
2324 rows = append(rows, row)
2325 default:
2326 row := ReturnValueRow{Name: name, Result: "Unimplemented-in-voltctl"}
2327 rows = append(rows, row)
2328 }
2329 }
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002330 }
2331
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002332 outputFormat := CharReplacer.Replace(options.Format)
2333 if outputFormat == "" {
2334 outputFormat = GetCommandOptionWithDefault("device-value-get", "format", DEFAULT_DEVICE_VALUE_GET_FORMAT)
2335 }
2336
2337 result := CommandResult{
2338 Format: format.Format(outputFormat),
2339 OutputAs: toOutputType(options.OutputAs),
2340 NameLimit: options.NameLimit,
Scott Baker9173ed82020-05-19 08:30:12 -07002341 Data: rows,
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002342 }
2343 GenerateOutput(&result)
2344 return nil
2345}
serkantul3d22fc72022-09-14 12:22:56 +03002346
2347/*Device get Onu OMCI TX RX Stats */
2348func (options *OnuOmciTxRxStats) Execute(args []string) error {
2349 conn, err := NewConnection()
2350 if err != nil {
2351 return err
2352 }
2353 defer conn.Close()
2354 client := extension.NewExtensionClient(conn)
2355
2356 singleGetValReq := extension.SingleGetValueRequest{
2357 TargetId: string(options.Args.Id),
2358 Request: &extension.GetValueRequest{
2359 Request: &extension.GetValueRequest_OnuOmciStats{
2360 OnuOmciStats: &extension.GetOnuOmciTxRxStatsRequest{},
2361 },
2362 },
2363 }
2364
2365 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2366 defer cancel()
2367 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2368 if err != nil {
2369 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2370 return err
2371 }
2372
2373 if rv.Response.Status != extension.GetValueResponse_OK {
2374 return fmt.Errorf("failed to get onu omci tx rx stats %v", rv.Response.ErrReason.String())
2375 }
2376 outputFormat := CharReplacer.Replace(options.Format)
2377 if outputFormat == "" {
2378 outputFormat = GetCommandOptionWithDefault("device-get-onu-omci-tx-rx-stats", "format", DEFAULT_ONU_OMCI_TX_RX_STATS_FORMAT)
2379 }
2380 result := CommandResult{
2381 Format: format.Format(outputFormat),
2382 OutputAs: toOutputType(options.OutputAs),
2383 NameLimit: options.NameLimit,
2384 Data: rv.GetResponse().GetOnuOmciStats(),
2385 }
2386 GenerateOutput(&result)
2387 return nil
2388}