blob: b8fdc71961b9d67c4a328dcf8ceb6b27067e2940 [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}}"
Zack Williamse940c7a2019-08-21 14:25:39 -070036 DEFAULT_DEVICE_PORTS_FORMAT = "table{{.PortNo}}\t{{.Label}}\t{{.Type}}\t{{.AdminState}}\t{{.OperStatus}}\t{{.DeviceId}}\t{{.Peers}}"
37 DEFAULT_DEVICE_INSPECT_FORMAT = `ID: {{.Id}}
38 TYPE: {{.Type}}
39 ROOT: {{.Root}}
40 PARENTID: {{.ParentId}}
41 SERIALNUMBER: {{.SerialNumber}}
42 VLAN: {{.Vlan}}
43 ADMINSTATE: {{.AdminState}}
44 OPERSTATUS: {{.OperStatus}}
45 CONNECTSTATUS: {{.ConnectStatus}}`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +000046 DEFAULT_DEVICE_PM_CONFIG_GET_FORMAT = "table{{.DefaultFreq}}\t{{.Grouped}}\t{{.FreqOverride}}"
47 DEFAULT_DEVICE_PM_CONFIG_METRIC_LIST_FORMAT = "table{{.Name}}\t{{.Type}}\t{{.Enabled}}\t{{.SampleFreq}}"
48 DEFAULT_DEVICE_PM_CONFIG_GROUP_LIST_FORMAT = "table{{.GroupName}}\t{{.Enabled}}\t{{.GroupFreq}}"
49 DEFAULT_DEVICE_VALUE_GET_FORMAT = "table{{.Name}}\t{{.Result}}"
Andrea Campanella791d88b2021-01-08 13:29:00 +010050 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 +053051 ONU_IMAGE_LIST_FORMAT = "table{{.Version}}\t{{.IsCommited}}\t{{.IsActive}}\t{{.IsValid}}\t{{.ProductCode}}\t{{.Hash}}"
52 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 -050053 DEFAULT_DEVICE_GET_PORT_STATUS_FORMAT = `
54 TXBYTES: {{.TxBytes}}
55 TXPACKETS: {{.TxPackets}}
56 TXERRPACKETS: {{.TxErrorPackets}}
57 TXBCASTPACKETS: {{.TxBcastPackets}}
58 TXUCASTPACKETS: {{.TxUcastPackets}}
59 TXMCASTPACKETS: {{.TxMcastPackets}}
60 RXBYTES: {{.RxBytes}}
61 RXPACKETS: {{.RxPackets}}
62 RXERRPACKETS: {{.RxErrorPackets}}
63 RXBCASTPACKETS: {{.RxBcastPackets}}
64 RXUCASTPACKETS: {{.RxUcastPackets}}
65 RXMCASTPACKETS: {{.RxMcastPackets}}`
kesavand6d1131f2021-02-05 22:38:15 +053066 DEFAULT_DEVICE_GET_UNI_STATUS_FORMAT = `
67 ADMIN_STATE: {{.AdmState}}
68 OPERATIONAL_STATE: {{.OperState}}
69 CONFIG_IND: {{.ConfigInd}}`
Girish Gowdra4f5ce7c2021-04-29 18:53:21 -070070 DEFAULT_ONU_PON_OPTICAL_INFO_STATUS_FORMAT = `
71 POWER_FEED_VOLTAGE__VOLTS: {{.PowerFeedVoltage}}
72 RECEIVED_OPTICAL_POWER__dBm: {{.ReceivedOpticalPower}}
73 MEAN_OPTICAL_LAUNCH_POWER__dBm: {{.MeanOpticalLaunchPower}}
74 LASER_BIAS_CURRENT__mA: {{.LaserBiasCurrent}}
75 TEMPERATURE__Celsius: {{.Temperature}}`
Gamze Abakac857a462021-05-26 13:45:54 +000076 DEFAULT_RX_POWER_STATUS_FORMAT = `
77 INTF_ID: {{.IntfId}}
78 ONU_ID: {{.OnuId}}
79 STATUS: {{.Status}}
80 FAIL_REASON: {{.FailReason}}
81 RX_POWER : {{.RxPower}}`
Himani Chawla553a1392021-06-10 23:39:17 +053082 DEFAULT_ETHERNET_FRAME_EXTENDED_PM_COUNTERS_FORMAT = `Upstream_Drop_Events: {{.UDropEvents}}
83Upstream_Octets: {{.UOctets}}
84UFrames: {{.UFrames}}
85UBroadcastFrames: {{.UBroadcastFrames}}
86UMulticastFrames: {{.UMulticastFrames}}
87UCrcErroredFrames: {{.UCrcErroredFrames}}
88UUndersizeFrames: {{.UUndersizeFrames}}
89UOversizeFrames: {{.UOversizeFrames}}
90UFrames_64Octets: {{.UFrames_64Octets}}
91UFrames_65To_127Octets: {{.UFrames_65To_127Octets}}
92UFrames_128To_255Octets: {{.UFrames_128To_255Octets}}
93UFrames_256To_511Octets: {{.UFrames_256To_511Octets}}
94UFrames_512To_1023Octets: {{.UFrames_512To_1023Octets}}
95UFrames_1024To_1518Octets: {{.UFrames_1024To_1518Octets}}
96DDropEvents: {{.DDropEvents}}
97DOctets: {{.DOctets}}
98DFrames: {{.DFrames}}
99DBroadcastFrames: {{.DBroadcastFrames}}
100DMulticastFrames: {{.DMulticastFrames}}
101DCrcErroredFrames: {{.DCrcErroredFrames}}
102DUndersizeFrames: {{.DUndersizeFrames}}
103DOversizeFrames: {{.DOversizeFrames}}
104DFrames_64Octets: {{.DFrames_64Octets}}
105DFrames_65To_127Octets: {{.DFrames_65To_127Octets}}
106DFrames_128To_255Octets: {{.DFrames_128To_255Octets}}
107DFrames_256To_511Octets: {{.DFrames_256To_511Octets}}
108DFrames_512To_1023Octets: {{.DFrames_512To_1023Octets}}
Himani Chawlabac0f892021-08-25 17:14:06 +0530109DFrames_1024To_1518Octets: {{.DFrames_1024To_1518Octets}}
110PmFormat: {{.PmFormat}}`
Zack Williamse940c7a2019-08-21 14:25:39 -0700111)
112
113type DeviceList struct {
114 ListOutputOptions
115}
116
117type DeviceCreate struct {
David Bainbridge1a514392020-06-23 11:12:51 -0700118 DeviceType string `short:"t" required:"true" long:"devicetype" description:"Device type"`
David Bainbridge835dd0e2020-04-01 10:30:09 -0700119 MACAddress string `short:"m" long:"macaddress" default:"" description:"MAC Address"`
Zack Williamse940c7a2019-08-21 14:25:39 -0700120 IPAddress string `short:"i" long:"ipaddress" default:"" description:"IP Address"`
121 HostAndPort string `short:"H" long:"hostandport" default:"" description:"Host and port"`
122}
123
124type DeviceId string
125
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000126type MetricName string
127type GroupName string
kesavand12cd8eb2020-01-20 22:25:22 -0500128type PortNum uint32
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -0800129type ValueFlag string
kesavand12cd8eb2020-01-20 22:25:22 -0500130
Zack Williamse940c7a2019-08-21 14:25:39 -0700131type DeviceDelete struct {
Himani Chawla9933ddc2020-10-12 23:53:27 +0530132 Force bool `long:"force" description:"Delete device forcefully"`
133 Args struct {
Zack Williamse940c7a2019-08-21 14:25:39 -0700134 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
135 } `positional-args:"yes"`
136}
137
138type DeviceEnable struct {
139 Args struct {
140 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
141 } `positional-args:"yes"`
142}
143
144type DeviceDisable struct {
145 Args struct {
146 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
147 } `positional-args:"yes"`
148}
149
150type DeviceReboot struct {
151 Args struct {
152 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
153 } `positional-args:"yes"`
154}
155
156type DeviceFlowList struct {
157 ListOutputOptions
Maninder045921e2020-09-29 16:46:02 +0530158 FlowIdOptions
Zack Williamse940c7a2019-08-21 14:25:39 -0700159 Args struct {
160 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
161 } `positional-args:"yes"`
162}
163
Himani Chawla3c161c62021-05-13 16:36:51 +0530164type DeviceFlowGroupList struct {
165 ListOutputOptions
166 GroupListOptions
167 Args struct {
168 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
169 } `positional-args:"yes"`
170}
Zack Williamse940c7a2019-08-21 14:25:39 -0700171type DevicePortList struct {
172 ListOutputOptions
173 Args struct {
174 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
175 } `positional-args:"yes"`
176}
177
178type DeviceInspect struct {
179 OutputOptionsJson
180 Args struct {
181 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
182 } `positional-args:"yes"`
183}
184
kesavand12cd8eb2020-01-20 22:25:22 -0500185type DevicePortEnable struct {
186 Args struct {
187 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
188 PortId PortNum `positional-arg-name:"PORT_NUMBER" required:"yes"`
189 } `positional-args:"yes"`
190}
191
192type DevicePortDisable struct {
193 Args struct {
194 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
195 PortId PortNum `positional-arg-name:"PORT_NUMBER" required:"yes"`
196 } `positional-args:"yes"`
197}
198
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000199type DevicePmConfigsGet struct {
200 ListOutputOptions
201 Args struct {
202 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
203 } `positional-args:"yes"`
204}
205
206type DevicePmConfigMetricList struct {
207 ListOutputOptions
208 Args struct {
209 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
210 } `positional-args:"yes"`
211}
212
213type DevicePmConfigGroupList struct {
214 ListOutputOptions
215 Args struct {
216 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
217 } `positional-args:"yes"`
218}
219
220type DevicePmConfigGroupMetricList struct {
221 ListOutputOptions
222 Args struct {
223 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
224 Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"`
225 } `positional-args:"yes"`
226}
227
228type DevicePmConfigFrequencySet struct {
229 OutputOptions
230 Args struct {
Girish Gowdra610acb42021-01-27 13:33:57 -0800231 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
232 Interval time.Duration `positional-arg-name:"INTERVAL" required:"yes"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000233 } `positional-args:"yes"`
234}
235
236type DevicePmConfigMetricEnable struct {
237 Args struct {
238 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
239 Metrics []MetricName `positional-arg-name:"METRIC_NAME" required:"yes"`
240 } `positional-args:"yes"`
241}
242
243type DevicePmConfigMetricDisable struct {
244 Args struct {
245 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
246 Metrics []MetricName `positional-arg-name:"METRIC_NAME" required:"yes"`
247 } `positional-args:"yes"`
248}
249
250type DevicePmConfigGroupEnable struct {
251 Args struct {
Girish Gowdra610acb42021-01-27 13:33:57 -0800252 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
253 Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000254 } `positional-args:"yes"`
255}
256
257type DevicePmConfigGroupDisable struct {
258 Args struct {
Girish Gowdra610acb42021-01-27 13:33:57 -0800259 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
260 Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"`
261 } `positional-args:"yes"`
262}
263
264type DevicePmConfigGroupFrequencySet struct {
265 OutputOptions
266 Args struct {
267 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
268 Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"`
269 Interval time.Duration `positional-arg-name:"INTERVAL" required:"yes"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000270 } `positional-args:"yes"`
271}
272
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -0800273type DeviceGetExtValue struct {
274 ListOutputOptions
275 Args struct {
276 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
277 Valueflag ValueFlag `positional-arg-name:"VALUE_FLAG" required:"yes"`
278 } `positional-args:"yes"`
279}
Rohan Agrawald7df3772020-06-29 11:23:36 +0000280
281type DevicePmConfigSetMaxSkew struct {
282 Args struct {
283 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
284 MaxSkew uint32 `positional-arg-name:"MAX_SKEW" required:"yes"`
285 } `positional-args:"yes"`
286}
287
Andrea Campanella791d88b2021-01-08 13:29:00 +0100288type DeviceOnuListImages struct {
289 ListOutputOptions
290 Args struct {
291 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
292 } `positional-args:"yes"`
293}
294
295type DeviceOnuDownloadImage struct {
296 Args struct {
297 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
298 Name string `positional-arg-name:"IMAGE_NAME" required:"yes"`
299 Url string `positional-arg-name:"IMAGE_URL" required:"yes"`
300 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
301 Crc uint32 `positional-arg-name:"IMAGE_CRC" required:"yes"`
302 LocalDir string `positional-arg-name:"IMAGE_LOCAL_DIRECTORY"`
303 } `positional-args:"yes"`
304}
305
306type DeviceOnuActivateImageUpdate 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 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
311 SaveConfig bool `positional-arg-name:"SAVE_EXISTING_CONFIG"`
312 LocalDir string `positional-arg-name:"IMAGE_LOCAL_DIRECTORY"`
Andrea Campanella7b2ecf42021-02-25 12:27:15 +0100313 } `positional-args:"yes"`
kesavand8ec4fc02021-01-27 09:10:22 -0500314}
kesavand3e2f9f62021-04-22 11:06:38 +0530315
316type OnuDownloadImage struct {
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +0200317 ListOutputOptions
kesavand3e2f9f62021-04-22 11:06:38 +0530318 Args struct {
319 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
320 Url string `positional-arg-name:"IMAGE_URL" required:"yes"`
ssiddiqui7bc89e92021-05-20 20:58:02 +0530321 Vendor string `positional-arg-name:"IMAGE_VENDOR"`
kesavand3e2f9f62021-04-22 11:06:38 +0530322 ActivateOnSuccess bool `positional-arg-name:"IMAGE_ACTIVATE_ON_SUCCESS"`
323 CommitOnSuccess bool `positional-arg-name:"IMAGE_COMMIT_ON_SUCCESS"`
324 Crc uint32 `positional-arg-name:"IMAGE_CRC"`
325 IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
326 } `positional-args:"yes"`
327}
328
329type OnuActivateImage 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 CommitOnSuccess bool `positional-arg-name:"IMAGE_COMMIT_ON_SUCCESS"`
334 IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
335 } `positional-args:"yes"`
336}
337
338type OnuAbortUpgradeImage struct {
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +0200339 ListOutputOptions
kesavand3e2f9f62021-04-22 11:06:38 +0530340 Args struct {
341 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
342 IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
343 } `positional-args:"yes"`
344}
345
346type OnuCommitImage struct {
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +0200347 ListOutputOptions
kesavand3e2f9f62021-04-22 11:06:38 +0530348 Args struct {
349 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
350 IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
351 } `positional-args:"yes"`
352}
353
354type OnuImageStatus struct {
355 ListOutputOptions
356 Args struct {
357 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
358 IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
359 } `positional-args:"yes"`
360}
361
362type OnuListImages struct {
363 ListOutputOptions
364 Args struct {
365 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
366 } `positional-args:"yes"`
367}
368
kesavand8ec4fc02021-01-27 09:10:22 -0500369type DeviceGetPortStats struct {
370 ListOutputOptions
371 Args struct {
372 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
373 PortNo uint32 `positional-arg-name:"PORT_NO" required:"yes"`
374 PortType string `positional-arg-name:"PORT_TYPE" required:"yes"`
Andrea Campanella791d88b2021-01-08 13:29:00 +0100375 } `positional-args:"yes"`
376}
kesavand6d1131f2021-02-05 22:38:15 +0530377type UniStatus struct {
378 ListOutputOptions
379 Args struct {
380 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
381 UniIndex uint32 `positional-arg-name:"UNI_INDEX" required:"yes"`
382 } `positional-args:"yes"`
383}
Girish Gowdra4f5ce7c2021-04-29 18:53:21 -0700384type OnuPonOpticalInfo struct {
385 ListOutputOptions
386 Args struct {
387 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
388 } `positional-args:"yes"`
389}
Himani Chawla40acc122021-05-26 18:52:29 +0530390
391type GetOnuStats struct {
392 ListOutputOptions
393 Args struct {
394 OltId DeviceId `positional-arg-name:"OLT_DEVICE_ID" required:"yes"`
395 IntfId uint32 `positional-arg-name:"PON_INTF_ID" required:"yes"`
396 OnuId uint32 `positional-arg-name:"ONU_ID" required:"yes"`
397 } `positional-args:"yes"`
398}
399
Himani Chawla553a1392021-06-10 23:39:17 +0530400type GetOnuEthernetFrameExtendedPmCounters struct {
401 ListOutputOptions
402 Args struct {
403 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
404 } `positional-args:"yes"`
405}
406
Gamze Abakac857a462021-05-26 13:45:54 +0000407type RxPower struct {
408 ListOutputOptions
409 Args struct {
410 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
411 PortNo uint32 `positional-arg-name:"PORT_NO" required:"yes"`
412 OnuNo uint32 `positional-arg-name:"ONU_NO" required:"yes"`
413 } `positional-args:"yes"`
414}
415
Zack Williamse940c7a2019-08-21 14:25:39 -0700416type DeviceOpts struct {
Himani Chawla3c161c62021-05-13 16:36:51 +0530417 List DeviceList `command:"list"`
418 Create DeviceCreate `command:"create"`
419 Delete DeviceDelete `command:"delete"`
420 Enable DeviceEnable `command:"enable"`
421 Disable DeviceDisable `command:"disable"`
422 Flows DeviceFlowList `command:"flows"`
423 Groups DeviceFlowGroupList `command:"groups"`
kesavand12cd8eb2020-01-20 22:25:22 -0500424 Port struct {
425 List DevicePortList `command:"list"`
426 Enable DevicePortEnable `command:"enable"`
427 Disable DevicePortDisable `command:"disable"`
428 } `command:"port"`
429 Inspect DeviceInspect `command:"inspect"`
430 Reboot DeviceReboot `command:"reboot"`
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -0800431 Value struct {
432 Get DeviceGetExtValue `command:"get"`
433 } `command:"value"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000434 PmConfig struct {
Rohan Agrawald7df3772020-06-29 11:23:36 +0000435 Get DevicePmConfigsGet `command:"get"`
436 MaxSkew struct {
437 Set DevicePmConfigSetMaxSkew `command:"set"`
438 } `command:"maxskew"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000439 Frequency struct {
440 Set DevicePmConfigFrequencySet `command:"set"`
441 } `command:"frequency"`
442 Metric struct {
443 List DevicePmConfigMetricList `command:"list"`
444 Enable DevicePmConfigMetricEnable `command:"enable"`
445 Disable DevicePmConfigMetricDisable `command:"disable"`
446 } `command:"metric"`
447 Group struct {
Girish Gowdra610acb42021-01-27 13:33:57 -0800448 List DevicePmConfigGroupList `command:"list"`
449 Enable DevicePmConfigGroupEnable `command:"enable"`
450 Disable DevicePmConfigGroupDisable `command:"disable"`
451 Set DevicePmConfigGroupFrequencySet `command:"set"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000452 } `command:"group"`
453 GroupMetric struct {
454 List DevicePmConfigGroupMetricList `command:"list"`
455 } `command:"groupmetric"`
456 } `command:"pmconfig"`
Andrea Campanella791d88b2021-01-08 13:29:00 +0100457 Image struct {
458 Get DeviceOnuListImages `command:"list"`
459 Download DeviceOnuDownloadImage `command:"download"`
460 Activate DeviceOnuActivateImageUpdate `command:"activate"`
461 } `command:"image"`
kesavand3e2f9f62021-04-22 11:06:38 +0530462 DownloadImage struct {
463 Download OnuDownloadImage `command:"download"`
464 Activate OnuActivateImage `command:"activate"`
465 Commit OnuCommitImage `command:"commit"`
466 AbortUpgrade OnuAbortUpgradeImage `command:"abort"`
467 Status OnuImageStatus `command:"status"`
468 List OnuListImages `command:"list" `
469 } `command:"onuimage"`
kesavand8ec4fc02021-01-27 09:10:22 -0500470 GetExtVal struct {
Himani Chawla553a1392021-06-10 23:39:17 +0530471 Stats DeviceGetPortStats `command:"portstats"`
472 UniStatus UniStatus `command:"unistatus"`
473 OpticalInfo OnuPonOpticalInfo `command:"onu_pon_optical_info"`
474 OnuStats GetOnuStats `command:"onu_stats"`
475 EthernetFrameExtendedPm GetOnuEthernetFrameExtendedPmCounters `command:"ethernet_frame_extended_pm"`
476 RxPower RxPower `command:"rxpower"`
kesavand8ec4fc02021-01-27 09:10:22 -0500477 } `command:"getextval"`
Zack Williamse940c7a2019-08-21 14:25:39 -0700478}
479
480var deviceOpts = DeviceOpts{}
481
482func RegisterDeviceCommands(parser *flags.Parser) {
David Bainbridge12f036f2019-10-15 22:09:04 +0000483 if _, err := parser.AddCommand("device", "device commands", "Commands to query and manipulate VOLTHA devices", &deviceOpts); err != nil {
David Bainbridgea6722342019-10-24 23:55:53 +0000484 Error.Fatalf("Unexpected error while attempting to register device commands : %s", err)
David Bainbridge12f036f2019-10-15 22:09:04 +0000485 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700486}
487
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000488func (i *MetricName) Complete(match string) []flags.Completion {
489 conn, err := NewConnection()
490 if err != nil {
491 return nil
492 }
493 defer conn.Close()
494
495 client := voltha.NewVolthaServiceClient(conn)
496
497 var deviceId string
498found:
499 for i := len(os.Args) - 1; i >= 0; i -= 1 {
500 switch os.Args[i] {
501 case "enable":
502 fallthrough
503 case "disable":
504 if len(os.Args) > i+1 {
505 deviceId = os.Args[i+1]
506 } else {
507 return nil
508 }
509 break found
510 default:
511 }
512 }
513
514 if len(deviceId) == 0 {
515 return nil
516 }
517
David K. Bainbridge9189c632021-03-26 21:52:21 +0000518 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000519 defer cancel()
520
521 id := voltha.ID{Id: string(deviceId)}
522
523 pmconfigs, err := client.ListDevicePmConfigs(ctx, &id)
524
525 if err != nil {
526 return nil
527 }
528
529 list := make([]flags.Completion, 0)
530 for _, metrics := range pmconfigs.Metrics {
531 if strings.HasPrefix(metrics.Name, match) {
532 list = append(list, flags.Completion{Item: metrics.Name})
533 }
534 }
535
536 return list
537}
538
539func (i *GroupName) Complete(match string) []flags.Completion {
540 conn, err := NewConnection()
541 if err != nil {
542 return nil
543 }
544 defer conn.Close()
545
546 client := voltha.NewVolthaServiceClient(conn)
547
548 var deviceId string
549found:
550 for i := len(os.Args) - 1; i >= 0; i -= 1 {
551 switch os.Args[i] {
552 case "list":
553 fallthrough
554 case "enable":
555 fallthrough
556 case "disable":
557 if len(os.Args) > i+1 {
558 deviceId = os.Args[i+1]
559 } else {
560 return nil
561 }
562 break found
563 default:
564 }
565 }
566
567 if len(deviceId) == 0 {
568 return nil
569 }
570
David K. Bainbridge9189c632021-03-26 21:52:21 +0000571 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000572 defer cancel()
573
574 id := voltha.ID{Id: string(deviceId)}
575
576 pmconfigs, err := client.ListDevicePmConfigs(ctx, &id)
577
578 if err != nil {
579 return nil
580 }
581
582 list := make([]flags.Completion, 0)
583 for _, group := range pmconfigs.Groups {
584 if strings.HasPrefix(group.GroupName, match) {
585 list = append(list, flags.Completion{Item: group.GroupName})
586 }
587 }
588 return list
589}
590
kesavand12cd8eb2020-01-20 22:25:22 -0500591func (i *PortNum) Complete(match string) []flags.Completion {
592 conn, err := NewConnection()
593 if err != nil {
594 return nil
595 }
596 defer conn.Close()
597
Scott Baker9173ed82020-05-19 08:30:12 -0700598 client := voltha.NewVolthaServiceClient(conn)
kesavand12cd8eb2020-01-20 22:25:22 -0500599
600 /*
601 * The command line args when completing for PortNum will be a DeviceId
602 * followed by one or more PortNums. So walk the argument list from the
603 * end and find the first argument that is enable/disable as those are
604 * the subcommands that come before the positional arguments. It would
605 * be nice if this package gave us the list of optional arguments
606 * already parsed.
607 */
608 var deviceId string
609found:
610 for i := len(os.Args) - 1; i >= 0; i -= 1 {
611 switch os.Args[i] {
612 case "enable":
613 fallthrough
614 case "disable":
615 if len(os.Args) > i+1 {
616 deviceId = os.Args[i+1]
617 } else {
618 return nil
619 }
620 break found
621 default:
622 }
623 }
624
625 if len(deviceId) == 0 {
626 return nil
627 }
628
David K. Bainbridge9189c632021-03-26 21:52:21 +0000629 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand12cd8eb2020-01-20 22:25:22 -0500630 defer cancel()
kesavand12cd8eb2020-01-20 22:25:22 -0500631
Scott Baker9173ed82020-05-19 08:30:12 -0700632 id := voltha.ID{Id: string(deviceId)}
kesavand12cd8eb2020-01-20 22:25:22 -0500633
Scott Baker9173ed82020-05-19 08:30:12 -0700634 ports, err := client.ListDevicePorts(ctx, &id)
kesavand12cd8eb2020-01-20 22:25:22 -0500635 if err != nil {
636 return nil
637 }
638
639 list := make([]flags.Completion, 0)
Scott Baker9173ed82020-05-19 08:30:12 -0700640 for _, item := range ports.Items {
641 pn := strconv.FormatUint(uint64(item.PortNo), 10)
kesavand12cd8eb2020-01-20 22:25:22 -0500642 if strings.HasPrefix(pn, match) {
643 list = append(list, flags.Completion{Item: pn})
644 }
645 }
646
647 return list
648}
649
Zack Williamse940c7a2019-08-21 14:25:39 -0700650func (i *DeviceId) Complete(match string) []flags.Completion {
651 conn, err := NewConnection()
652 if err != nil {
653 return nil
654 }
655 defer conn.Close()
656
Scott Baker9173ed82020-05-19 08:30:12 -0700657 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700658
David K. Bainbridge9189c632021-03-26 21:52:21 +0000659 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700660 defer cancel()
661
Scott Baker9173ed82020-05-19 08:30:12 -0700662 devices, err := client.ListDevices(ctx, &empty.Empty{})
Zack Williamse940c7a2019-08-21 14:25:39 -0700663 if err != nil {
664 return nil
665 }
666
667 list := make([]flags.Completion, 0)
Scott Baker9173ed82020-05-19 08:30:12 -0700668 for _, item := range devices.Items {
669 if strings.HasPrefix(item.Id, match) {
670 list = append(list, flags.Completion{Item: item.Id})
Zack Williamse940c7a2019-08-21 14:25:39 -0700671 }
672 }
673
674 return list
675}
676
677func (options *DeviceList) Execute(args []string) error {
678
679 conn, err := NewConnection()
680 if err != nil {
681 return err
682 }
683 defer conn.Close()
684
Scott Baker9173ed82020-05-19 08:30:12 -0700685 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700686
David K. Bainbridge9189c632021-03-26 21:52:21 +0000687 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700688 defer cancel()
689
Scott Baker9173ed82020-05-19 08:30:12 -0700690 devices, err := client.ListDevices(ctx, &empty.Empty{})
Zack Williamse940c7a2019-08-21 14:25:39 -0700691 if err != nil {
692 return err
693 }
694
695 outputFormat := CharReplacer.Replace(options.Format)
696 if outputFormat == "" {
David Bainbridgea6722342019-10-24 23:55:53 +0000697 outputFormat = GetCommandOptionWithDefault("device-list", "format", DEFAULT_DEVICE_FORMAT)
Zack Williamse940c7a2019-08-21 14:25:39 -0700698 }
699 if options.Quiet {
700 outputFormat = "{{.Id}}"
701 }
702
David Bainbridgea6722342019-10-24 23:55:53 +0000703 orderBy := options.OrderBy
704 if orderBy == "" {
705 orderBy = GetCommandOptionWithDefault("device-list", "order", "")
706 }
707
Scott Baker9173ed82020-05-19 08:30:12 -0700708 // Make sure json output prints an empty list, not "null"
709 if devices.Items == nil {
710 devices.Items = make([]*voltha.Device, 0)
Zack Williamse940c7a2019-08-21 14:25:39 -0700711 }
712
713 result := CommandResult{
714 Format: format.Format(outputFormat),
715 Filter: options.Filter,
David Bainbridgea6722342019-10-24 23:55:53 +0000716 OrderBy: orderBy,
Zack Williamse940c7a2019-08-21 14:25:39 -0700717 OutputAs: toOutputType(options.OutputAs),
718 NameLimit: options.NameLimit,
Scott Baker9173ed82020-05-19 08:30:12 -0700719 Data: devices.Items,
Zack Williamse940c7a2019-08-21 14:25:39 -0700720 }
721
722 GenerateOutput(&result)
723 return nil
724}
725
726func (options *DeviceCreate) Execute(args []string) error {
727
Scott Baker9173ed82020-05-19 08:30:12 -0700728 device := voltha.Device{}
Zack Williamse940c7a2019-08-21 14:25:39 -0700729 if options.HostAndPort != "" {
Scott Baker9173ed82020-05-19 08:30:12 -0700730 device.Address = &voltha.Device_HostAndPort{HostAndPort: options.HostAndPort}
Zack Williamse940c7a2019-08-21 14:25:39 -0700731 } else if options.IPAddress != "" {
Scott Baker9173ed82020-05-19 08:30:12 -0700732 device.Address = &voltha.Device_Ipv4Address{Ipv4Address: options.IPAddress}
Hardik Windlassce1de342020-02-04 21:58:07 +0000733 }
734 if options.MACAddress != "" {
Scott Baker9173ed82020-05-19 08:30:12 -0700735 device.MacAddress = strings.ToLower(options.MACAddress)
Zack Williamse940c7a2019-08-21 14:25:39 -0700736 }
737 if options.DeviceType != "" {
Scott Baker9173ed82020-05-19 08:30:12 -0700738 device.Type = options.DeviceType
Zack Williamse940c7a2019-08-21 14:25:39 -0700739 }
740
741 conn, err := NewConnection()
742 if err != nil {
743 return err
744 }
745 defer conn.Close()
746
Scott Baker9173ed82020-05-19 08:30:12 -0700747 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700748
David K. Bainbridge9189c632021-03-26 21:52:21 +0000749 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700750 defer cancel()
751
Scott Baker9173ed82020-05-19 08:30:12 -0700752 createdDevice, err := client.CreateDevice(ctx, &device)
Zack Williamse940c7a2019-08-21 14:25:39 -0700753 if err != nil {
754 return err
Zack Williamse940c7a2019-08-21 14:25:39 -0700755 }
756
Scott Baker9173ed82020-05-19 08:30:12 -0700757 fmt.Printf("%s\n", createdDevice.Id)
Zack Williamse940c7a2019-08-21 14:25:39 -0700758
759 return nil
760}
761
762func (options *DeviceDelete) Execute(args []string) error {
763
764 conn, err := NewConnection()
765 if err != nil {
766 return err
767 }
768 defer conn.Close()
769
Scott Baker9173ed82020-05-19 08:30:12 -0700770 client := voltha.NewVolthaServiceClient(conn)
David Bainbridge7052fe82020-03-25 10:37:00 -0700771 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -0700772 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +0000773 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700774 defer cancel()
775
Scott Baker9173ed82020-05-19 08:30:12 -0700776 id := voltha.ID{Id: string(i)}
Himani Chawla9933ddc2020-10-12 23:53:27 +0530777 if options.Force {
778 _, err = client.ForceDeleteDevice(ctx, &id)
779 } else {
780 _, err = client.DeleteDevice(ctx, &id)
781 }
Scott Baker9173ed82020-05-19 08:30:12 -0700782
Zack Williamse940c7a2019-08-21 14:25:39 -0700783 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +0000784 Error.Printf("Error while deleting '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -0700785 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -0700786 continue
Zack Williamse940c7a2019-08-21 14:25:39 -0700787 }
788 fmt.Printf("%s\n", i)
789 }
790
David Bainbridge7052fe82020-03-25 10:37:00 -0700791 if lastErr != nil {
792 return NoReportErr
793 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700794 return nil
795}
796
797func (options *DeviceEnable) Execute(args []string) error {
798 conn, err := NewConnection()
799 if err != nil {
800 return err
801 }
802 defer conn.Close()
803
Scott Baker9173ed82020-05-19 08:30:12 -0700804 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700805
David Bainbridge7052fe82020-03-25 10:37:00 -0700806 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -0700807 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +0000808 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700809 defer cancel()
810
Scott Baker9173ed82020-05-19 08:30:12 -0700811 id := voltha.ID{Id: string(i)}
812
813 _, err := client.EnableDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -0700814 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +0000815 Error.Printf("Error while enabling '%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 *DeviceDisable) 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.DisableDevice(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 disabling '%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 *DeviceReboot) 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.RebootDevice(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 rebooting '%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 *DevicePortList) Execute(args []string) error {
891
892 conn, err := NewConnection()
893 if err != nil {
894 return err
895 }
896 defer conn.Close()
897
Scott Baker9173ed82020-05-19 08:30:12 -0700898 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700899
David K. Bainbridge9189c632021-03-26 21:52:21 +0000900 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700901 defer cancel()
902
Scott Baker9173ed82020-05-19 08:30:12 -0700903 id := voltha.ID{Id: string(options.Args.Id)}
Zack Williamse940c7a2019-08-21 14:25:39 -0700904
Scott Baker9173ed82020-05-19 08:30:12 -0700905 ports, err := client.ListDevicePorts(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -0700906 if err != nil {
907 return err
908 }
909
910 outputFormat := CharReplacer.Replace(options.Format)
911 if outputFormat == "" {
David Bainbridgea6722342019-10-24 23:55:53 +0000912 outputFormat = GetCommandOptionWithDefault("device-ports", "format", DEFAULT_DEVICE_PORTS_FORMAT)
Zack Williamse940c7a2019-08-21 14:25:39 -0700913 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700914
David Bainbridgea6722342019-10-24 23:55:53 +0000915 orderBy := options.OrderBy
916 if orderBy == "" {
917 orderBy = GetCommandOptionWithDefault("device-ports", "order", "")
918 }
919
Zack Williamse940c7a2019-08-21 14:25:39 -0700920 result := CommandResult{
921 Format: format.Format(outputFormat),
922 Filter: options.Filter,
David Bainbridgea6722342019-10-24 23:55:53 +0000923 OrderBy: orderBy,
Zack Williamse940c7a2019-08-21 14:25:39 -0700924 OutputAs: toOutputType(options.OutputAs),
925 NameLimit: options.NameLimit,
Scott Baker9173ed82020-05-19 08:30:12 -0700926 Data: ports.Items,
Zack Williamse940c7a2019-08-21 14:25:39 -0700927 }
928
929 GenerateOutput(&result)
930 return nil
931}
932
933func (options *DeviceFlowList) Execute(args []string) error {
934 fl := &FlowList{}
935 fl.ListOutputOptions = options.ListOutputOptions
Maninder045921e2020-09-29 16:46:02 +0530936 fl.FlowIdOptions = options.FlowIdOptions
Zack Williamse940c7a2019-08-21 14:25:39 -0700937 fl.Args.Id = string(options.Args.Id)
David Bainbridgea6722342019-10-24 23:55:53 +0000938 fl.Method = "device-flows"
Zack Williamse940c7a2019-08-21 14:25:39 -0700939 return fl.Execute(args)
940}
941
Himani Chawla3c161c62021-05-13 16:36:51 +0530942func (options *DeviceFlowGroupList) Execute(args []string) error {
943 grp := &GroupList{}
944 grp.ListOutputOptions = options.ListOutputOptions
945 grp.GroupListOptions = options.GroupListOptions
946 grp.Args.Id = string(options.Args.Id)
947 grp.Method = "device-groups"
948 return grp.Execute(args)
949}
950
Zack Williamse940c7a2019-08-21 14:25:39 -0700951func (options *DeviceInspect) Execute(args []string) error {
952 if len(args) > 0 {
953 return fmt.Errorf("only a single argument 'DEVICE_ID' can be provided")
954 }
955
956 conn, err := NewConnection()
957 if err != nil {
958 return err
959 }
960 defer conn.Close()
961
Scott Baker9173ed82020-05-19 08:30:12 -0700962 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700963
David K. Bainbridge9189c632021-03-26 21:52:21 +0000964 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700965 defer cancel()
966
Scott Baker9173ed82020-05-19 08:30:12 -0700967 id := voltha.ID{Id: string(options.Args.Id)}
Zack Williamse940c7a2019-08-21 14:25:39 -0700968
Scott Baker9173ed82020-05-19 08:30:12 -0700969 device, err := client.GetDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -0700970 if err != nil {
971 return err
972 }
973
Zack Williamse940c7a2019-08-21 14:25:39 -0700974 outputFormat := CharReplacer.Replace(options.Format)
975 if outputFormat == "" {
David Bainbridgea6722342019-10-24 23:55:53 +0000976 outputFormat = GetCommandOptionWithDefault("device-inspect", "format", DEFAULT_DEVICE_INSPECT_FORMAT)
Zack Williamse940c7a2019-08-21 14:25:39 -0700977 }
978 if options.Quiet {
979 outputFormat = "{{.Id}}"
980 }
981
982 result := CommandResult{
983 Format: format.Format(outputFormat),
984 OutputAs: toOutputType(options.OutputAs),
985 NameLimit: options.NameLimit,
986 Data: device,
987 }
988 GenerateOutput(&result)
989 return nil
990}
kesavand12cd8eb2020-01-20 22:25:22 -0500991
992/*Device Port Enable */
993func (options *DevicePortEnable) Execute(args []string) error {
994 conn, err := NewConnection()
995 if err != nil {
996 return err
997 }
998 defer conn.Close()
999
Scott Baker9173ed82020-05-19 08:30:12 -07001000 client := voltha.NewVolthaServiceClient(conn)
kesavand12cd8eb2020-01-20 22:25:22 -05001001
David K. Bainbridge9189c632021-03-26 21:52:21 +00001002 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand12cd8eb2020-01-20 22:25:22 -05001003 defer cancel()
1004
Scott Baker9173ed82020-05-19 08:30:12 -07001005 port := voltha.Port{DeviceId: string(options.Args.Id), PortNo: uint32(options.Args.PortId)}
1006
1007 _, err = client.EnablePort(ctx, &port)
kesavand12cd8eb2020-01-20 22:25:22 -05001008 if err != nil {
1009 Error.Printf("Error enabling port number %v on device Id %s,err=%s\n", options.Args.PortId, options.Args.Id, ErrorToString(err))
1010 return err
kesavand12cd8eb2020-01-20 22:25:22 -05001011 }
1012
1013 return nil
1014}
1015
Scott Baker9173ed82020-05-19 08:30:12 -07001016/*Device Port Disable */
kesavand12cd8eb2020-01-20 22:25:22 -05001017func (options *DevicePortDisable) Execute(args []string) error {
1018 conn, err := NewConnection()
1019 if err != nil {
1020 return err
1021 }
1022 defer conn.Close()
1023
Scott Baker9173ed82020-05-19 08:30:12 -07001024 client := voltha.NewVolthaServiceClient(conn)
1025
David K. Bainbridge9189c632021-03-26 21:52:21 +00001026 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand12cd8eb2020-01-20 22:25:22 -05001027 defer cancel()
1028
Scott Baker9173ed82020-05-19 08:30:12 -07001029 port := voltha.Port{DeviceId: string(options.Args.Id), PortNo: uint32(options.Args.PortId)}
1030
1031 _, err = client.DisablePort(ctx, &port)
kesavand12cd8eb2020-01-20 22:25:22 -05001032 if err != nil {
Scott Baker9173ed82020-05-19 08:30:12 -07001033 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 -05001034 return err
kesavand12cd8eb2020-01-20 22:25:22 -05001035 }
Scott Baker9173ed82020-05-19 08:30:12 -07001036
kesavand12cd8eb2020-01-20 22:25:22 -05001037 return nil
1038}
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08001039
Rohan Agrawald7df3772020-06-29 11:23:36 +00001040func (options *DevicePmConfigSetMaxSkew) Execute(args []string) error {
1041 conn, err := NewConnection()
1042 if err != nil {
1043 return err
1044 }
1045 defer conn.Close()
1046
1047 client := voltha.NewVolthaServiceClient(conn)
1048
David K. Bainbridge9189c632021-03-26 21:52:21 +00001049 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawald7df3772020-06-29 11:23:36 +00001050 defer cancel()
1051
1052 id := voltha.ID{Id: string(options.Args.Id)}
1053
1054 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1055 if err != nil {
1056 return err
1057 }
1058
1059 pmConfigs.MaxSkew = options.Args.MaxSkew
1060
1061 _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs)
1062 if err != nil {
1063 return err
1064 }
1065
1066 return nil
1067}
1068
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001069func (options *DevicePmConfigsGet) Execute(args []string) error {
1070
1071 conn, err := NewConnection()
1072 if err != nil {
1073 return err
1074 }
1075 defer conn.Close()
1076
1077 client := voltha.NewVolthaServiceClient(conn)
1078
David K. Bainbridge9189c632021-03-26 21:52:21 +00001079 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001080 defer cancel()
1081
1082 id := voltha.ID{Id: string(options.Args.Id)}
1083
1084 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1085 if err != nil {
1086 return err
1087 }
1088
1089 outputFormat := CharReplacer.Replace(options.Format)
1090 if outputFormat == "" {
1091 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GET_FORMAT)
1092 }
1093
1094 orderBy := options.OrderBy
1095 if orderBy == "" {
1096 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1097 }
1098
1099 result := CommandResult{
1100 Format: format.Format(outputFormat),
1101 Filter: options.Filter,
1102 OrderBy: orderBy,
1103 OutputAs: toOutputType(options.OutputAs),
1104 NameLimit: options.NameLimit,
1105 Data: pmConfigs,
1106 }
1107
1108 GenerateOutput(&result)
1109 return nil
1110
1111}
1112
1113func (options *DevicePmConfigMetricList) Execute(args []string) error {
1114
1115 conn, err := NewConnection()
1116 if err != nil {
1117 return err
1118 }
1119 defer conn.Close()
1120
1121 client := voltha.NewVolthaServiceClient(conn)
1122
David K. Bainbridge9189c632021-03-26 21:52:21 +00001123 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001124 defer cancel()
1125
1126 id := voltha.ID{Id: string(options.Args.Id)}
1127
1128 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1129 if err != nil {
1130 return err
1131 }
1132
1133 if !pmConfigs.Grouped {
1134 for _, metric := range pmConfigs.Metrics {
1135 if metric.SampleFreq == 0 {
1136 metric.SampleFreq = pmConfigs.DefaultFreq
1137 }
1138 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001139 outputFormat := CharReplacer.Replace(options.Format)
1140 if outputFormat == "" {
1141 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_METRIC_LIST_FORMAT)
1142 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001143
Rohan Agrawalbca69122020-06-17 14:59:03 +00001144 orderBy := options.OrderBy
1145 if orderBy == "" {
1146 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1147 }
1148
1149 result := CommandResult{
1150 Format: format.Format(outputFormat),
1151 Filter: options.Filter,
1152 OrderBy: orderBy,
1153 OutputAs: toOutputType(options.OutputAs),
1154 NameLimit: options.NameLimit,
1155 Data: pmConfigs.Metrics,
1156 }
1157
1158 GenerateOutput(&result)
1159 return nil
1160 } else {
1161 return fmt.Errorf("Device '%s' does not have Non Grouped Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001162 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001163}
1164
1165func (options *DevicePmConfigMetricEnable) Execute(args []string) error {
1166
1167 conn, err := NewConnection()
1168 if err != nil {
1169 return err
1170 }
1171 defer conn.Close()
1172
1173 client := voltha.NewVolthaServiceClient(conn)
1174
David K. Bainbridge9189c632021-03-26 21:52:21 +00001175 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001176 defer cancel()
1177
1178 id := voltha.ID{Id: string(options.Args.Id)}
1179
1180 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1181 if err != nil {
1182 return err
1183 }
1184
1185 if !pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001186 metrics := make(map[string]struct{})
1187 for _, metric := range pmConfigs.Metrics {
1188 metrics[metric.Name] = struct{}{}
1189 }
1190
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001191 for _, metric := range pmConfigs.Metrics {
1192 for _, mName := range options.Args.Metrics {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001193 if _, exist := metrics[string(mName)]; !exist {
1194 return fmt.Errorf("Metric Name '%s' does not exist", mName)
1195 }
1196
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001197 if string(mName) == metric.Name && !metric.Enabled {
1198 metric.Enabled = true
1199 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1200 if err != nil {
1201 return err
1202 }
1203 }
1204 }
1205 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001206 } else {
1207 return fmt.Errorf("Device '%s' does not have Non Grouped Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001208 }
1209 return nil
1210}
1211
1212func (options *DevicePmConfigMetricDisable) Execute(args []string) error {
1213
1214 conn, err := NewConnection()
1215 if err != nil {
1216 return err
1217 }
1218 defer conn.Close()
1219
1220 client := voltha.NewVolthaServiceClient(conn)
1221
David K. Bainbridge9189c632021-03-26 21:52:21 +00001222 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001223 defer cancel()
1224
1225 id := voltha.ID{Id: string(options.Args.Id)}
1226
1227 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1228 if err != nil {
1229 return err
1230 }
1231
1232 if !pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001233 metrics := make(map[string]struct{})
1234 for _, metric := range pmConfigs.Metrics {
1235 metrics[metric.Name] = struct{}{}
1236 }
1237
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001238 for _, metric := range pmConfigs.Metrics {
1239 for _, mName := range options.Args.Metrics {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001240 if _, have := metrics[string(mName)]; !have {
1241 return fmt.Errorf("Metric Name '%s' does not exist", mName)
1242 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001243 if string(mName) == metric.Name && metric.Enabled {
1244 metric.Enabled = false
1245 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1246 if err != nil {
1247 return err
1248 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001249 } else {
1250 return fmt.Errorf("Metric '%s' cannot be disabled", string(mName))
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001251 }
1252 }
1253 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001254 } else {
1255 return fmt.Errorf("Device '%s' does not have Non Grouped Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001256 }
1257 return nil
1258}
1259
1260func (options *DevicePmConfigGroupEnable) Execute(args []string) error {
1261
1262 conn, err := NewConnection()
1263 if err != nil {
1264 return err
1265 }
1266 defer conn.Close()
1267
1268 client := voltha.NewVolthaServiceClient(conn)
1269
David K. Bainbridge9189c632021-03-26 21:52:21 +00001270 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001271 defer cancel()
1272
1273 id := voltha.ID{Id: string(options.Args.Id)}
1274
1275 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1276 if err != nil {
1277 return err
1278 }
1279
1280 if pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001281 groups := make(map[string]struct{})
1282 for _, group := range pmConfigs.Groups {
1283 groups[group.GroupName] = struct{}{}
1284 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001285 for _, group := range pmConfigs.Groups {
Girish Gowdra610acb42021-01-27 13:33:57 -08001286 if _, have := groups[string(options.Args.Group)]; !have {
1287 return fmt.Errorf("Group Name '%s' does not exist", options.Args.Group)
1288 }
1289 if string(options.Args.Group) == group.GroupName && !group.Enabled {
1290 group.Enabled = true
1291 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1292 if err != nil {
1293 return err
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001294 }
1295 }
1296 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001297 } else {
1298 return fmt.Errorf("Device '%s' does not have Group Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001299 }
1300 return nil
1301}
1302
1303func (options *DevicePmConfigGroupDisable) Execute(args []string) error {
1304
1305 conn, err := NewConnection()
1306 if err != nil {
1307 return err
1308 }
1309 defer conn.Close()
1310
1311 client := voltha.NewVolthaServiceClient(conn)
1312
David K. Bainbridge9189c632021-03-26 21:52:21 +00001313 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001314 defer cancel()
1315
1316 id := voltha.ID{Id: string(options.Args.Id)}
1317
1318 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1319 if err != nil {
1320 return err
1321 }
1322
1323 if pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001324 groups := make(map[string]struct{})
1325 for _, group := range pmConfigs.Groups {
1326 groups[group.GroupName] = struct{}{}
1327 }
1328
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001329 for _, group := range pmConfigs.Groups {
Girish Gowdra610acb42021-01-27 13:33:57 -08001330 if _, have := groups[string(options.Args.Group)]; !have {
1331 return fmt.Errorf("Group Name '%s' does not exist", options.Args.Group)
1332 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001333
Girish Gowdra610acb42021-01-27 13:33:57 -08001334 if string(options.Args.Group) == group.GroupName && group.Enabled {
1335 group.Enabled = false
1336 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1337 if err != nil {
1338 return err
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001339 }
1340 }
1341 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001342 } else {
1343 return fmt.Errorf("Device '%s' does not have Group Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001344 }
1345 return nil
1346}
1347
Girish Gowdra610acb42021-01-27 13:33:57 -08001348func (options *DevicePmConfigGroupFrequencySet) Execute(args []string) error {
1349
1350 conn, err := NewConnection()
1351 if err != nil {
1352 return err
1353 }
1354 defer conn.Close()
1355
1356 client := voltha.NewVolthaServiceClient(conn)
1357
David K. Bainbridge9189c632021-03-26 21:52:21 +00001358 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Girish Gowdra610acb42021-01-27 13:33:57 -08001359 defer cancel()
1360
1361 id := voltha.ID{Id: string(options.Args.Id)}
1362
1363 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1364 if err != nil {
1365 return err
1366 }
1367
1368 if pmConfigs.Grouped {
1369 groups := make(map[string]struct{})
1370 for _, group := range pmConfigs.Groups {
1371 groups[group.GroupName] = struct{}{}
1372 }
1373
1374 for _, group := range pmConfigs.Groups {
1375 if _, have := groups[string(options.Args.Group)]; !have {
1376 return fmt.Errorf("group name '%s' does not exist", options.Args.Group)
1377 }
1378
1379 if string(options.Args.Group) == group.GroupName {
1380 if !group.Enabled {
1381 return fmt.Errorf("group '%s' is not enabled", options.Args.Group)
1382 }
1383 group.GroupFreq = uint32(options.Args.Interval.Seconds())
1384 _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs)
1385 if err != nil {
1386 return err
1387 }
1388 }
1389 }
1390 } else {
1391 return fmt.Errorf("device '%s' does not have group metrics", options.Args.Id)
1392 }
1393 return nil
1394}
1395
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001396func (options *DevicePmConfigGroupList) Execute(args []string) error {
1397
1398 conn, err := NewConnection()
1399 if err != nil {
1400 return err
1401 }
1402 defer conn.Close()
1403
1404 client := voltha.NewVolthaServiceClient(conn)
1405
David K. Bainbridge9189c632021-03-26 21:52:21 +00001406 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001407 defer cancel()
1408
1409 id := voltha.ID{Id: string(options.Args.Id)}
1410
1411 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1412 if err != nil {
1413 return err
1414 }
1415
1416 if pmConfigs.Grouped {
1417 for _, group := range pmConfigs.Groups {
1418 if group.GroupFreq == 0 {
1419 group.GroupFreq = pmConfigs.DefaultFreq
1420 }
1421 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001422 outputFormat := CharReplacer.Replace(options.Format)
1423 if outputFormat == "" {
1424 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GROUP_LIST_FORMAT)
1425 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001426
Rohan Agrawalbca69122020-06-17 14:59:03 +00001427 orderBy := options.OrderBy
1428 if orderBy == "" {
1429 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1430 }
1431
1432 result := CommandResult{
1433 Format: format.Format(outputFormat),
1434 Filter: options.Filter,
1435 OrderBy: orderBy,
1436 OutputAs: toOutputType(options.OutputAs),
1437 NameLimit: options.NameLimit,
1438 Data: pmConfigs.Groups,
1439 }
1440
1441 GenerateOutput(&result)
1442 } else {
1443 return fmt.Errorf("Device '%s' does not have Group Metrics", string(options.Args.Id))
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001444 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001445 return nil
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001446}
1447
1448func (options *DevicePmConfigGroupMetricList) Execute(args []string) error {
1449
1450 var metrics []*voltha.PmConfig
1451 conn, err := NewConnection()
1452 if err != nil {
1453 return err
1454 }
1455 defer conn.Close()
1456
1457 client := voltha.NewVolthaServiceClient(conn)
1458
David K. Bainbridge9189c632021-03-26 21:52:21 +00001459 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001460 defer cancel()
1461
1462 id := voltha.ID{Id: string(options.Args.Id)}
1463
1464 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1465 if err != nil {
1466 return err
1467 }
1468
1469 for _, groups := range pmConfigs.Groups {
1470
1471 if string(options.Args.Group) == groups.GroupName {
1472 for _, metric := range groups.Metrics {
1473 if metric.SampleFreq == 0 && groups.GroupFreq == 0 {
1474 metric.SampleFreq = pmConfigs.DefaultFreq
1475 } else {
1476 metric.SampleFreq = groups.GroupFreq
1477 }
1478 }
1479 metrics = groups.Metrics
1480 }
1481 }
1482
1483 outputFormat := CharReplacer.Replace(options.Format)
1484 if outputFormat == "" {
1485 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_METRIC_LIST_FORMAT)
1486 }
1487
1488 orderBy := options.OrderBy
1489 if orderBy == "" {
1490 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1491 }
1492
1493 result := CommandResult{
1494 Format: format.Format(outputFormat),
1495 Filter: options.Filter,
1496 OrderBy: orderBy,
1497 OutputAs: toOutputType(options.OutputAs),
1498 NameLimit: options.NameLimit,
1499 Data: metrics,
1500 }
1501
1502 GenerateOutput(&result)
1503 return nil
1504
1505}
1506
1507func (options *DevicePmConfigFrequencySet) Execute(args []string) error {
1508
1509 conn, err := NewConnection()
1510 if err != nil {
1511 return err
1512 }
1513 defer conn.Close()
1514
1515 client := voltha.NewVolthaServiceClient(conn)
1516
David K. Bainbridge9189c632021-03-26 21:52:21 +00001517 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001518 defer cancel()
1519
1520 id := voltha.ID{Id: string(options.Args.Id)}
1521
1522 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1523 if err != nil {
1524 return err
1525 }
1526
Girish Gowdra610acb42021-01-27 13:33:57 -08001527 pmConfigs.DefaultFreq = uint32(options.Args.Interval.Seconds())
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001528
1529 _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs)
1530 if err != nil {
1531 return err
1532 }
1533
1534 outputFormat := CharReplacer.Replace(options.Format)
1535 if outputFormat == "" {
1536 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GET_FORMAT)
1537 }
1538 if options.Quiet {
1539 outputFormat = "{{.Id}}"
1540 }
1541
1542 result := CommandResult{
1543 Format: format.Format(outputFormat),
1544 OutputAs: toOutputType(options.OutputAs),
1545 NameLimit: options.NameLimit,
1546 Data: pmConfigs,
1547 }
1548
1549 GenerateOutput(&result)
1550 return nil
1551
1552}
1553
kesavand3e2f9f62021-04-22 11:06:38 +05301554func (options *OnuDownloadImage) Execute(args []string) error {
1555
1556 conn, err := NewConnection()
1557 if err != nil {
1558 return err
1559 }
1560 defer conn.Close()
1561
1562 client := voltha.NewVolthaServiceClient(conn)
1563
1564 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1565 defer cancel()
1566
1567 var devIDList []*common.ID
1568 for _, i := range options.Args.IDs {
1569
1570 devIDList = append(devIDList, &common.ID{Id: string(i)})
1571 }
1572
1573 downloadImage := voltha.DeviceImageDownloadRequest{
1574 DeviceId: devIDList,
1575 Image: &voltha.Image{
1576 Url: options.Args.Url,
1577 Crc32: options.Args.Crc,
ssiddiqui7bc89e92021-05-20 20:58:02 +05301578 Vendor: options.Args.Vendor,
kesavand3e2f9f62021-04-22 11:06:38 +05301579 Version: options.Args.ImageVersion,
1580 },
1581 ActivateOnSuccess: options.Args.ActivateOnSuccess,
1582 CommitOnSuccess: options.Args.CommitOnSuccess,
1583 }
1584
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001585 deviceImageResp, err := client.DownloadImageToDevice(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301586 if err != nil {
1587 return err
1588 }
1589
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001590 outputFormat := GetCommandOptionWithDefault("onu-image-download", "format", ONU_IMAGE_STATUS_FORMAT)
1591 // Make sure json output prints an empty list, not "null"
1592 if deviceImageResp.DeviceImageStates == nil {
1593 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1594 }
1595 result := CommandResult{
1596 Format: format.Format(outputFormat),
1597 OutputAs: toOutputType(options.OutputAs),
1598 NameLimit: options.NameLimit,
1599 Data: deviceImageResp.DeviceImageStates,
1600 }
1601 GenerateOutput(&result)
kesavand3e2f9f62021-04-22 11:06:38 +05301602 return nil
1603
1604}
1605
1606func (options *OnuActivateImage) Execute(args []string) error {
1607
1608 conn, err := NewConnection()
1609 if err != nil {
1610 return err
1611 }
1612 defer conn.Close()
1613
1614 client := voltha.NewVolthaServiceClient(conn)
1615
1616 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1617 defer cancel()
1618
1619 var devIDList []*common.ID
1620 for _, i := range options.Args.IDs {
1621
1622 devIDList = append(devIDList, &common.ID{Id: string(i)})
1623 }
1624
1625 downloadImage := voltha.DeviceImageRequest{
1626 DeviceId: devIDList,
1627 Version: options.Args.ImageVersion,
1628 CommitOnSuccess: options.Args.CommitOnSuccess,
1629 }
1630
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001631 deviceImageResp, err := client.ActivateImage(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301632 if err != nil {
1633 return err
1634 }
1635
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001636 outputFormat := GetCommandOptionWithDefault("onu-image-activate", "format", ONU_IMAGE_STATUS_FORMAT)
1637 // Make sure json output prints an empty list, not "null"
1638 if deviceImageResp.DeviceImageStates == nil {
1639 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1640 }
1641 result := CommandResult{
1642 Format: format.Format(outputFormat),
1643 OutputAs: toOutputType(options.OutputAs),
1644 NameLimit: options.NameLimit,
1645 Data: deviceImageResp.DeviceImageStates,
1646 }
1647 GenerateOutput(&result)
1648
kesavand3e2f9f62021-04-22 11:06:38 +05301649 return nil
1650
1651}
1652
1653func (options *OnuAbortUpgradeImage) Execute(args []string) error {
1654
1655 conn, err := NewConnection()
1656 if err != nil {
1657 return err
1658 }
1659 defer conn.Close()
1660
1661 client := voltha.NewVolthaServiceClient(conn)
1662
1663 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1664 defer cancel()
1665
1666 var devIDList []*common.ID
1667 for _, i := range options.Args.IDs {
1668
1669 devIDList = append(devIDList, &common.ID{Id: string(i)})
1670 }
1671
1672 downloadImage := voltha.DeviceImageRequest{
1673 DeviceId: devIDList,
1674 Version: options.Args.ImageVersion,
1675 }
1676
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001677 deviceImageResp, err := client.AbortImageUpgradeToDevice(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301678 if err != nil {
1679 return err
1680 }
1681
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001682 outputFormat := GetCommandOptionWithDefault("onu-image-abort", "format", ONU_IMAGE_STATUS_FORMAT)
1683 // Make sure json output prints an empty list, not "null"
1684 if deviceImageResp.DeviceImageStates == nil {
1685 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1686 }
1687 result := CommandResult{
1688 Format: format.Format(outputFormat),
1689 OutputAs: toOutputType(options.OutputAs),
1690 NameLimit: options.NameLimit,
1691 Data: deviceImageResp.DeviceImageStates,
1692 }
1693 GenerateOutput(&result)
1694
kesavand3e2f9f62021-04-22 11:06:38 +05301695 return nil
1696
1697}
1698
1699func (options *OnuCommitImage) Execute(args []string) error {
1700
1701 conn, err := NewConnection()
1702 if err != nil {
1703 return err
1704 }
1705 defer conn.Close()
1706
1707 client := voltha.NewVolthaServiceClient(conn)
1708
1709 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1710 defer cancel()
1711
1712 var devIDList []*common.ID
1713 for _, i := range options.Args.IDs {
1714
1715 devIDList = append(devIDList, &common.ID{Id: string(i)})
1716 }
1717 downloadImage := voltha.DeviceImageRequest{
1718 DeviceId: devIDList,
1719 Version: options.Args.ImageVersion,
1720 }
1721
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001722 deviceImageResp, err := client.CommitImage(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301723 if err != nil {
1724 return err
1725 }
1726
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001727 outputFormat := GetCommandOptionWithDefault("onu-image-commit", "format", ONU_IMAGE_STATUS_FORMAT)
1728 // Make sure json output prints an empty list, not "null"
1729 if deviceImageResp.DeviceImageStates == nil {
1730 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1731 }
1732 result := CommandResult{
1733 Format: format.Format(outputFormat),
1734 OutputAs: toOutputType(options.OutputAs),
1735 NameLimit: options.NameLimit,
1736 Data: deviceImageResp.DeviceImageStates,
1737 }
1738 GenerateOutput(&result)
1739
kesavand3e2f9f62021-04-22 11:06:38 +05301740 return nil
1741
1742}
1743
1744func (options *OnuListImages) Execute(args []string) error {
1745
1746 conn, err := NewConnection()
1747 if err != nil {
1748 return err
1749 }
1750 defer conn.Close()
1751
1752 client := voltha.NewVolthaServiceClient(conn)
1753
1754 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1755 defer cancel()
1756
1757 id := common.ID{Id: string(options.Args.Id)}
1758
1759 onuImages, err := client.GetOnuImages(ctx, &id)
1760 if err != nil {
1761 return err
1762 }
1763
1764 outputFormat := CharReplacer.Replace(options.Format)
1765 if outputFormat == "" {
1766 outputFormat = GetCommandOptionWithDefault("onu-image-list", "format", ONU_IMAGE_LIST_FORMAT)
1767 }
1768
1769 if options.Quiet {
1770 outputFormat = "{{.Id}}"
1771 }
1772
1773 //TODO orderby
1774
1775 // Make sure json output prints an empty list, not "null"
1776 if onuImages.Items == nil {
1777 onuImages.Items = make([]*voltha.OnuImage, 0)
1778 }
1779
1780 result := CommandResult{
1781 Format: format.Format(outputFormat),
1782 OutputAs: toOutputType(options.OutputAs),
1783 NameLimit: options.NameLimit,
1784 Data: onuImages.Items,
1785 }
1786
1787 GenerateOutput(&result)
1788 return nil
1789
1790}
1791
1792func (options *OnuImageStatus) Execute(args []string) error {
1793
1794 conn, err := NewConnection()
1795 if err != nil {
1796 return err
1797 }
1798 defer conn.Close()
1799
1800 client := voltha.NewVolthaServiceClient(conn)
1801
1802 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1803 defer cancel()
1804
1805 var devIDList []*common.ID
1806 for _, i := range options.Args.IDs {
1807
1808 devIDList = append(devIDList, &common.ID{Id: string(i)})
1809 }
1810
1811 imageStatusReq := voltha.DeviceImageRequest{
1812 DeviceId: devIDList,
1813 Version: options.Args.ImageVersion,
1814 }
1815 imageStatus, err := client.GetImageStatus(ctx, &imageStatusReq)
1816 if err != nil {
1817 return err
1818 }
1819
1820 outputFormat := CharReplacer.Replace(options.Format)
1821 if outputFormat == "" {
1822 outputFormat = GetCommandOptionWithDefault("device-image-list", "format", ONU_IMAGE_STATUS_FORMAT)
1823 }
1824
1825 if options.Quiet {
1826 outputFormat = "{{.Id}}"
1827 }
1828
1829 //TODO orderby
1830
1831 // Make sure json output prints an empty list, not "null"
1832 if imageStatus.DeviceImageStates == nil {
1833 imageStatus.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1834 }
1835
1836 result := CommandResult{
1837 Format: format.Format(outputFormat),
1838 OutputAs: toOutputType(options.OutputAs),
1839 NameLimit: options.NameLimit,
1840 Data: imageStatus.DeviceImageStates,
1841 }
1842
1843 GenerateOutput(&result)
1844 return nil
1845
1846}
1847
Andrea Campanella791d88b2021-01-08 13:29:00 +01001848func (options *DeviceOnuListImages) Execute(args []string) error {
1849
1850 conn, err := NewConnection()
1851 if err != nil {
1852 return err
1853 }
1854 defer conn.Close()
1855
1856 client := voltha.NewVolthaServiceClient(conn)
1857
David K. Bainbridge9189c632021-03-26 21:52:21 +00001858 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Andrea Campanella791d88b2021-01-08 13:29:00 +01001859 defer cancel()
1860
1861 id := common.ID{Id: string(options.Args.Id)}
1862
1863 imageDownloads, err := client.ListImageDownloads(ctx, &id)
1864 if err != nil {
1865 return err
1866 }
1867
1868 outputFormat := CharReplacer.Replace(options.Format)
1869 if outputFormat == "" {
1870 outputFormat = GetCommandOptionWithDefault("device-image-list", "format", DEFAULT_DEVICE_IMAGE_LIST_GET_FORMAT)
1871 }
1872
1873 if options.Quiet {
1874 outputFormat = "{{.Id}}"
1875 }
1876
1877 //TODO orderby
1878
1879 // Make sure json output prints an empty list, not "null"
1880 if imageDownloads.Items == nil {
1881 imageDownloads.Items = make([]*voltha.ImageDownload, 0)
1882 }
1883
1884 result := CommandResult{
1885 Format: format.Format(outputFormat),
1886 OutputAs: toOutputType(options.OutputAs),
1887 NameLimit: options.NameLimit,
1888 Data: imageDownloads.Items,
1889 }
1890
1891 GenerateOutput(&result)
1892 return nil
1893
1894}
1895
1896func (options *DeviceOnuDownloadImage) Execute(args []string) error {
1897
1898 conn, err := NewConnection()
1899 if err != nil {
1900 return err
1901 }
1902 defer conn.Close()
1903
1904 client := voltha.NewVolthaServiceClient(conn)
1905
David K. Bainbridge9189c632021-03-26 21:52:21 +00001906 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Andrea Campanella791d88b2021-01-08 13:29:00 +01001907 defer cancel()
1908
1909 downloadImage := voltha.ImageDownload{
1910 Id: string(options.Args.Id),
1911 Name: options.Args.Name,
1912 Url: options.Args.Url,
1913 Crc: options.Args.Crc,
1914 LocalDir: options.Args.LocalDir,
1915 }
1916
1917 _, err = client.DownloadImage(ctx, &downloadImage)
1918 if err != nil {
1919 return err
1920 }
1921
1922 return nil
1923
1924}
1925
1926func (options *DeviceOnuActivateImageUpdate) Execute(args []string) error {
1927
1928 conn, err := NewConnection()
1929 if err != nil {
1930 return err
1931 }
1932 defer conn.Close()
1933
1934 client := voltha.NewVolthaServiceClient(conn)
1935
David K. Bainbridge9189c632021-03-26 21:52:21 +00001936 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Andrea Campanella791d88b2021-01-08 13:29:00 +01001937 defer cancel()
1938
1939 downloadImage := voltha.ImageDownload{
1940 Id: string(options.Args.Id),
1941 Name: options.Args.Name,
1942 ImageVersion: options.Args.ImageVersion,
1943 SaveConfig: options.Args.SaveConfig,
1944 LocalDir: options.Args.LocalDir,
1945 }
1946
1947 _, err = client.ActivateImageUpdate(ctx, &downloadImage)
1948 if err != nil {
1949 return err
1950 }
1951
1952 return nil
1953
1954}
1955
Scott Baker9173ed82020-05-19 08:30:12 -07001956type ReturnValueRow struct {
1957 Name string `json:"name"`
1958 Result interface{} `json:"result"`
1959}
1960
kesavand8ec4fc02021-01-27 09:10:22 -05001961func (options *DeviceGetPortStats) Execute(args []string) error {
1962 conn, err := NewConnection()
1963 if err != nil {
1964 return err
1965 }
1966 defer conn.Close()
1967 client := extension.NewExtensionClient(conn)
1968 var portType extension.GetOltPortCounters_PortType
1969
1970 if options.Args.PortType == "pon" {
1971 portType = extension.GetOltPortCounters_Port_PON_OLT
1972 } else if options.Args.PortType == "nni" {
1973
1974 portType = extension.GetOltPortCounters_Port_ETHERNET_NNI
1975 } else {
1976 return fmt.Errorf("expected interface type pon/nni, provided %s", options.Args.PortType)
1977 }
1978
1979 singleGetValReq := extension.SingleGetValueRequest{
1980 TargetId: string(options.Args.Id),
1981 Request: &extension.GetValueRequest{
1982 Request: &extension.GetValueRequest_OltPortInfo{
1983 OltPortInfo: &extension.GetOltPortCounters{
1984 PortNo: options.Args.PortNo,
1985 PortType: portType,
1986 },
1987 },
1988 },
1989 }
1990
David K. Bainbridge9189c632021-03-26 21:52:21 +00001991 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand8ec4fc02021-01-27 09:10:22 -05001992 defer cancel()
1993 rv, err := client.GetExtValue(ctx, &singleGetValReq)
1994 if err != nil {
1995 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
1996 return err
1997 }
1998
1999 if rv.Response.Status != extension.GetValueResponse_OK {
2000 return fmt.Errorf("failed to get port stats %v", rv.Response.ErrReason.String())
2001 }
2002
2003 outputFormat := CharReplacer.Replace(options.Format)
2004 if outputFormat == "" {
2005 outputFormat = GetCommandOptionWithDefault("device-get-port-status", "format", DEFAULT_DEVICE_GET_PORT_STATUS_FORMAT)
2006 }
2007
2008 result := CommandResult{
2009 Format: format.Format(outputFormat),
2010 OutputAs: toOutputType(options.OutputAs),
2011 NameLimit: options.NameLimit,
2012 Data: rv.GetResponse().GetPortCoutners(),
2013 }
2014 GenerateOutput(&result)
2015 return nil
2016}
2017
Himani Chawla40acc122021-05-26 18:52:29 +05302018func (options *GetOnuStats) Execute(args []string) error {
2019 conn, err := NewConnection()
2020 if err != nil {
2021 return err
2022 }
2023 defer conn.Close()
2024 client := extension.NewExtensionClient(conn)
2025
2026 singleGetValReq := extension.SingleGetValueRequest{
2027 TargetId: string(options.Args.OltId),
2028 Request: &extension.GetValueRequest{
2029 Request: &extension.GetValueRequest_OnuPonInfo{
2030 OnuPonInfo: &extension.GetOnuCountersRequest{
2031 IntfId: options.Args.IntfId,
2032 OnuId: options.Args.OnuId,
2033 },
2034 },
2035 },
2036 }
2037 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2038 defer cancel()
2039 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2040 if err != nil {
2041 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.OltId, ErrorToString(err))
2042 return err
2043 }
2044
2045 if rv.Response.Status != extension.GetValueResponse_OK {
2046 return fmt.Errorf("failed to get onu stats %v", rv.Response.ErrReason.String())
2047 }
2048 outputFormat := CharReplacer.Replace(options.Format)
2049 data, formatStr := buildOnuStatsOutputFormat(rv.GetResponse().GetOnuPonCounters())
2050 if outputFormat == "" {
2051 outputFormat = GetCommandOptionWithDefault("device-get-onu-status", "format", formatStr)
2052 }
Himani Chawla553a1392021-06-10 23:39:17 +05302053 result := CommandResult{
2054 Format: format.Format(outputFormat),
2055 OutputAs: toOutputType(options.OutputAs),
2056 NameLimit: options.NameLimit,
2057 Data: data,
2058 }
2059 GenerateOutput(&result)
2060 return nil
2061}
Himani Chawla40acc122021-05-26 18:52:29 +05302062
Himani Chawla553a1392021-06-10 23:39:17 +05302063func (options *GetOnuEthernetFrameExtendedPmCounters) Execute(args []string) error {
2064 conn, err := NewConnection()
2065 if err != nil {
2066 return err
2067 }
2068 defer conn.Close()
2069 client := extension.NewExtensionClient(conn)
2070
2071 singleGetValReq := extension.SingleGetValueRequest{
2072 TargetId: string(options.Args.Id),
2073 Request: &extension.GetValueRequest{
2074 Request: &extension.GetValueRequest_OnuInfo{
2075 OnuInfo: &extension.GetOmciEthernetFrameExtendedPmRequest{
2076 OnuDeviceId: string(options.Args.Id),
2077 },
2078 },
2079 },
2080 }
2081 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2082 defer cancel()
2083 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2084 if err != nil {
2085 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2086 return err
2087 }
2088
2089 if rv.Response.Status != extension.GetValueResponse_OK {
2090 return fmt.Errorf("failed to get ethernet frame extended pm counters %v", rv.Response.ErrReason.String())
2091 }
2092 outputFormat := CharReplacer.Replace(options.Format)
2093 data := buildOnuEthernetFrameExtendedPmOutputFormat(rv.GetResponse().GetOnuCounters())
2094 if outputFormat == "" {
2095 outputFormat = GetCommandOptionWithDefault("device-get-onu-status", "format", DEFAULT_ETHERNET_FRAME_EXTENDED_PM_COUNTERS_FORMAT)
2096 }
Himani Chawla40acc122021-05-26 18:52:29 +05302097 result := CommandResult{
2098 Format: format.Format(outputFormat),
2099 OutputAs: toOutputType(options.OutputAs),
2100 NameLimit: options.NameLimit,
2101 Data: data,
2102 }
2103 GenerateOutput(&result)
2104 return nil
2105}
2106
kesavand6d1131f2021-02-05 22:38:15 +05302107func (options *UniStatus) Execute(args []string) error {
2108 conn, err := NewConnection()
2109 if err != nil {
2110 return err
2111 }
2112 defer conn.Close()
2113 client := extension.NewExtensionClient(conn)
2114
2115 singleGetValReq := extension.SingleGetValueRequest{
2116 TargetId: string(options.Args.Id),
2117 Request: &extension.GetValueRequest{
2118 Request: &extension.GetValueRequest_UniInfo{
2119 UniInfo: &extension.GetOnuUniInfoRequest{
2120 UniIndex: options.Args.UniIndex,
2121 },
2122 },
2123 },
2124 }
David K. Bainbridge9189c632021-03-26 21:52:21 +00002125 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand6d1131f2021-02-05 22:38:15 +05302126 defer cancel()
2127 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2128 if err != nil {
2129 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2130 return err
2131 }
2132 if rv.Response.Status != extension.GetValueResponse_OK {
2133 return fmt.Errorf("failed to get uni status %v", rv.Response.ErrReason.String())
2134 }
2135 outputFormat := CharReplacer.Replace(options.Format)
2136 if outputFormat == "" {
2137 outputFormat = GetCommandOptionWithDefault("device-get-uni-status", "format", DEFAULT_DEVICE_GET_UNI_STATUS_FORMAT)
2138 }
2139 result := CommandResult{
2140 Format: format.Format(outputFormat),
2141 OutputAs: toOutputType(options.OutputAs),
2142 NameLimit: options.NameLimit,
2143 Data: rv.GetResponse().GetUniInfo(),
2144 }
2145 GenerateOutput(&result)
2146 return nil
2147}
2148
Girish Gowdra4f5ce7c2021-04-29 18:53:21 -07002149func (options *OnuPonOpticalInfo) Execute(args []string) error {
2150 conn, err := NewConnection()
2151 if err != nil {
2152 return err
2153 }
2154 defer conn.Close()
2155 client := extension.NewExtensionClient(conn)
2156
2157 singleGetValReq := extension.SingleGetValueRequest{
2158 TargetId: string(options.Args.Id),
2159 Request: &extension.GetValueRequest{
2160 Request: &extension.GetValueRequest_OnuOpticalInfo{
2161 OnuOpticalInfo: &extension.GetOnuPonOpticalInfo{},
2162 },
2163 },
2164 }
2165 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2166 defer cancel()
2167 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2168 if err != nil {
2169 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2170 return err
2171 }
2172 if rv.Response.Status != extension.GetValueResponse_OK {
2173 return fmt.Errorf("failed to get onu pon optical info %v", rv.Response.ErrReason.String())
2174 }
2175 outputFormat := CharReplacer.Replace(options.Format)
2176 if outputFormat == "" {
2177 outputFormat = GetCommandOptionWithDefault("device-get-onu-pon-optical-info", "format", DEFAULT_ONU_PON_OPTICAL_INFO_STATUS_FORMAT)
2178 }
2179 result := CommandResult{
2180 Format: format.Format(outputFormat),
2181 OutputAs: toOutputType(options.OutputAs),
2182 NameLimit: options.NameLimit,
2183 Data: rv.GetResponse().GetOnuOpticalInfo(),
2184 }
2185 GenerateOutput(&result)
2186 return nil
2187}
2188
Gamze Abakac857a462021-05-26 13:45:54 +00002189func (options *RxPower) Execute(args []string) error {
2190 conn, err := NewConnection()
2191 if err != nil {
2192 return err
2193 }
2194 defer conn.Close()
2195 client := extension.NewExtensionClient(conn)
2196
2197 singleGetValReq := extension.SingleGetValueRequest{
2198 TargetId: string(options.Args.Id),
2199 Request: &extension.GetValueRequest{
2200 Request: &extension.GetValueRequest_RxPower{
2201 RxPower: &extension.GetRxPowerRequest{
2202 IntfId: options.Args.PortNo,
2203 OnuId: options.Args.OnuNo,
2204 },
2205 },
2206 },
2207 }
2208
2209 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2210 defer cancel()
2211 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2212 if err != nil {
2213 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2214 return err
2215 }
2216 if rv.Response.Status != extension.GetValueResponse_OK {
2217 return fmt.Errorf("failed to get rx power %v", rv.Response.ErrReason.String())
2218 }
2219 outputFormat := CharReplacer.Replace(options.Format)
2220 if outputFormat == "" {
2221 outputFormat = GetCommandOptionWithDefault("device-get-rx-power", "format", DEFAULT_RX_POWER_STATUS_FORMAT)
2222 }
2223 result := CommandResult{
2224 Format: format.Format(outputFormat),
2225 OutputAs: toOutputType(options.OutputAs),
2226 NameLimit: options.NameLimit,
2227 Data: rv.GetResponse().GetRxPower(),
2228 }
2229 GenerateOutput(&result)
2230 return nil
2231}
2232
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002233/*Device get Onu Distance */
2234func (options *DeviceGetExtValue) Execute(args []string) error {
2235 conn, err := NewConnection()
2236 if err != nil {
2237 return err
2238 }
2239 defer conn.Close()
2240
Scott Baker9173ed82020-05-19 08:30:12 -07002241 client := voltha.NewVolthaServiceClient(conn)
2242
2243 valueflag, okay := common.ValueType_Type_value[string(options.Args.Valueflag)]
2244 if !okay {
2245 Error.Printf("Unknown valueflag %s\n", options.Args.Valueflag)
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002246 }
2247
Scott Baker9173ed82020-05-19 08:30:12 -07002248 val := voltha.ValueSpecifier{Id: string(options.Args.Id), Value: common.ValueType_Type(valueflag)}
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002249
David K. Bainbridge9189c632021-03-26 21:52:21 +00002250 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002251 defer cancel()
2252
Scott Baker9173ed82020-05-19 08:30:12 -07002253 rv, err := client.GetExtValue(ctx, &val)
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002254 if err != nil {
2255 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2256 return err
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002257 }
2258
Scott Baker9173ed82020-05-19 08:30:12 -07002259 var rows []ReturnValueRow
2260 for name, num := range common.ValueType_Type_value {
2261 if num == 0 {
2262 // EMPTY is not a real value
2263 continue
2264 }
2265 if (rv.Error & uint32(num)) != 0 {
2266 row := ReturnValueRow{Name: name, Result: "Error"}
2267 rows = append(rows, row)
2268 }
2269 if (rv.Unsupported & uint32(num)) != 0 {
2270 row := ReturnValueRow{Name: name, Result: "Unsupported"}
2271 rows = append(rows, row)
2272 }
2273 if (rv.Set & uint32(num)) != 0 {
2274 switch name {
2275 case "DISTANCE":
2276 row := ReturnValueRow{Name: name, Result: rv.Distance}
2277 rows = append(rows, row)
2278 default:
2279 row := ReturnValueRow{Name: name, Result: "Unimplemented-in-voltctl"}
2280 rows = append(rows, row)
2281 }
2282 }
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002283 }
2284
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002285 outputFormat := CharReplacer.Replace(options.Format)
2286 if outputFormat == "" {
2287 outputFormat = GetCommandOptionWithDefault("device-value-get", "format", DEFAULT_DEVICE_VALUE_GET_FORMAT)
2288 }
2289
2290 result := CommandResult{
2291 Format: format.Format(outputFormat),
2292 OutputAs: toOutputType(options.OutputAs),
2293 NameLimit: options.NameLimit,
Scott Baker9173ed82020-05-19 08:30:12 -07002294 Data: rows,
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002295 }
2296 GenerateOutput(&result)
2297 return nil
2298}