blob: 7ef8a5eceb57dbb0fdc61c9979dae899845ce52c [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
Himani Chawla806aa892021-08-30 15:51:46 +0530402 Reset bool `long:"reset" description:"Reset the counters"`
403 Args struct {
404 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
405 UniIndex *uint32 `positional-arg-name:"UNI_INDEX"`
Himani Chawla553a1392021-06-10 23:39:17 +0530406 } `positional-args:"yes"`
407}
408
Gamze Abakac857a462021-05-26 13:45:54 +0000409type RxPower struct {
410 ListOutputOptions
411 Args struct {
412 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
413 PortNo uint32 `positional-arg-name:"PORT_NO" required:"yes"`
414 OnuNo uint32 `positional-arg-name:"ONU_NO" required:"yes"`
415 } `positional-args:"yes"`
416}
417
Zack Williamse940c7a2019-08-21 14:25:39 -0700418type DeviceOpts struct {
Himani Chawla3c161c62021-05-13 16:36:51 +0530419 List DeviceList `command:"list"`
420 Create DeviceCreate `command:"create"`
421 Delete DeviceDelete `command:"delete"`
422 Enable DeviceEnable `command:"enable"`
423 Disable DeviceDisable `command:"disable"`
424 Flows DeviceFlowList `command:"flows"`
425 Groups DeviceFlowGroupList `command:"groups"`
kesavand12cd8eb2020-01-20 22:25:22 -0500426 Port struct {
427 List DevicePortList `command:"list"`
428 Enable DevicePortEnable `command:"enable"`
429 Disable DevicePortDisable `command:"disable"`
430 } `command:"port"`
431 Inspect DeviceInspect `command:"inspect"`
432 Reboot DeviceReboot `command:"reboot"`
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -0800433 Value struct {
434 Get DeviceGetExtValue `command:"get"`
435 } `command:"value"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000436 PmConfig struct {
Rohan Agrawald7df3772020-06-29 11:23:36 +0000437 Get DevicePmConfigsGet `command:"get"`
438 MaxSkew struct {
439 Set DevicePmConfigSetMaxSkew `command:"set"`
440 } `command:"maxskew"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000441 Frequency struct {
442 Set DevicePmConfigFrequencySet `command:"set"`
443 } `command:"frequency"`
444 Metric struct {
445 List DevicePmConfigMetricList `command:"list"`
446 Enable DevicePmConfigMetricEnable `command:"enable"`
447 Disable DevicePmConfigMetricDisable `command:"disable"`
448 } `command:"metric"`
449 Group struct {
Girish Gowdra610acb42021-01-27 13:33:57 -0800450 List DevicePmConfigGroupList `command:"list"`
451 Enable DevicePmConfigGroupEnable `command:"enable"`
452 Disable DevicePmConfigGroupDisable `command:"disable"`
453 Set DevicePmConfigGroupFrequencySet `command:"set"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000454 } `command:"group"`
455 GroupMetric struct {
456 List DevicePmConfigGroupMetricList `command:"list"`
457 } `command:"groupmetric"`
458 } `command:"pmconfig"`
Andrea Campanella791d88b2021-01-08 13:29:00 +0100459 Image struct {
460 Get DeviceOnuListImages `command:"list"`
461 Download DeviceOnuDownloadImage `command:"download"`
462 Activate DeviceOnuActivateImageUpdate `command:"activate"`
463 } `command:"image"`
kesavand3e2f9f62021-04-22 11:06:38 +0530464 DownloadImage struct {
465 Download OnuDownloadImage `command:"download"`
466 Activate OnuActivateImage `command:"activate"`
467 Commit OnuCommitImage `command:"commit"`
468 AbortUpgrade OnuAbortUpgradeImage `command:"abort"`
469 Status OnuImageStatus `command:"status"`
470 List OnuListImages `command:"list" `
471 } `command:"onuimage"`
kesavand8ec4fc02021-01-27 09:10:22 -0500472 GetExtVal struct {
Himani Chawla553a1392021-06-10 23:39:17 +0530473 Stats DeviceGetPortStats `command:"portstats"`
474 UniStatus UniStatus `command:"unistatus"`
475 OpticalInfo OnuPonOpticalInfo `command:"onu_pon_optical_info"`
476 OnuStats GetOnuStats `command:"onu_stats"`
477 EthernetFrameExtendedPm GetOnuEthernetFrameExtendedPmCounters `command:"ethernet_frame_extended_pm"`
478 RxPower RxPower `command:"rxpower"`
kesavand8ec4fc02021-01-27 09:10:22 -0500479 } `command:"getextval"`
Zack Williamse940c7a2019-08-21 14:25:39 -0700480}
481
482var deviceOpts = DeviceOpts{}
483
484func RegisterDeviceCommands(parser *flags.Parser) {
David Bainbridge12f036f2019-10-15 22:09:04 +0000485 if _, err := parser.AddCommand("device", "device commands", "Commands to query and manipulate VOLTHA devices", &deviceOpts); err != nil {
David Bainbridgea6722342019-10-24 23:55:53 +0000486 Error.Fatalf("Unexpected error while attempting to register device commands : %s", err)
David Bainbridge12f036f2019-10-15 22:09:04 +0000487 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700488}
489
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000490func (i *MetricName) Complete(match string) []flags.Completion {
491 conn, err := NewConnection()
492 if err != nil {
493 return nil
494 }
495 defer conn.Close()
496
497 client := voltha.NewVolthaServiceClient(conn)
498
499 var deviceId string
500found:
501 for i := len(os.Args) - 1; i >= 0; i -= 1 {
502 switch os.Args[i] {
503 case "enable":
504 fallthrough
505 case "disable":
506 if len(os.Args) > i+1 {
507 deviceId = os.Args[i+1]
508 } else {
509 return nil
510 }
511 break found
512 default:
513 }
514 }
515
516 if len(deviceId) == 0 {
517 return nil
518 }
519
David K. Bainbridge9189c632021-03-26 21:52:21 +0000520 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000521 defer cancel()
522
523 id := voltha.ID{Id: string(deviceId)}
524
525 pmconfigs, err := client.ListDevicePmConfigs(ctx, &id)
526
527 if err != nil {
528 return nil
529 }
530
531 list := make([]flags.Completion, 0)
532 for _, metrics := range pmconfigs.Metrics {
533 if strings.HasPrefix(metrics.Name, match) {
534 list = append(list, flags.Completion{Item: metrics.Name})
535 }
536 }
537
538 return list
539}
540
541func (i *GroupName) Complete(match string) []flags.Completion {
542 conn, err := NewConnection()
543 if err != nil {
544 return nil
545 }
546 defer conn.Close()
547
548 client := voltha.NewVolthaServiceClient(conn)
549
550 var deviceId string
551found:
552 for i := len(os.Args) - 1; i >= 0; i -= 1 {
553 switch os.Args[i] {
554 case "list":
555 fallthrough
556 case "enable":
557 fallthrough
558 case "disable":
559 if len(os.Args) > i+1 {
560 deviceId = os.Args[i+1]
561 } else {
562 return nil
563 }
564 break found
565 default:
566 }
567 }
568
569 if len(deviceId) == 0 {
570 return nil
571 }
572
David K. Bainbridge9189c632021-03-26 21:52:21 +0000573 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000574 defer cancel()
575
576 id := voltha.ID{Id: string(deviceId)}
577
578 pmconfigs, err := client.ListDevicePmConfigs(ctx, &id)
579
580 if err != nil {
581 return nil
582 }
583
584 list := make([]flags.Completion, 0)
585 for _, group := range pmconfigs.Groups {
586 if strings.HasPrefix(group.GroupName, match) {
587 list = append(list, flags.Completion{Item: group.GroupName})
588 }
589 }
590 return list
591}
592
kesavand12cd8eb2020-01-20 22:25:22 -0500593func (i *PortNum) Complete(match string) []flags.Completion {
594 conn, err := NewConnection()
595 if err != nil {
596 return nil
597 }
598 defer conn.Close()
599
Scott Baker9173ed82020-05-19 08:30:12 -0700600 client := voltha.NewVolthaServiceClient(conn)
kesavand12cd8eb2020-01-20 22:25:22 -0500601
602 /*
603 * The command line args when completing for PortNum will be a DeviceId
604 * followed by one or more PortNums. So walk the argument list from the
605 * end and find the first argument that is enable/disable as those are
606 * the subcommands that come before the positional arguments. It would
607 * be nice if this package gave us the list of optional arguments
608 * already parsed.
609 */
610 var deviceId string
611found:
612 for i := len(os.Args) - 1; i >= 0; i -= 1 {
613 switch os.Args[i] {
614 case "enable":
615 fallthrough
616 case "disable":
617 if len(os.Args) > i+1 {
618 deviceId = os.Args[i+1]
619 } else {
620 return nil
621 }
622 break found
623 default:
624 }
625 }
626
627 if len(deviceId) == 0 {
628 return nil
629 }
630
David K. Bainbridge9189c632021-03-26 21:52:21 +0000631 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand12cd8eb2020-01-20 22:25:22 -0500632 defer cancel()
kesavand12cd8eb2020-01-20 22:25:22 -0500633
Scott Baker9173ed82020-05-19 08:30:12 -0700634 id := voltha.ID{Id: string(deviceId)}
kesavand12cd8eb2020-01-20 22:25:22 -0500635
Scott Baker9173ed82020-05-19 08:30:12 -0700636 ports, err := client.ListDevicePorts(ctx, &id)
kesavand12cd8eb2020-01-20 22:25:22 -0500637 if err != nil {
638 return nil
639 }
640
641 list := make([]flags.Completion, 0)
Scott Baker9173ed82020-05-19 08:30:12 -0700642 for _, item := range ports.Items {
643 pn := strconv.FormatUint(uint64(item.PortNo), 10)
kesavand12cd8eb2020-01-20 22:25:22 -0500644 if strings.HasPrefix(pn, match) {
645 list = append(list, flags.Completion{Item: pn})
646 }
647 }
648
649 return list
650}
651
Zack Williamse940c7a2019-08-21 14:25:39 -0700652func (i *DeviceId) Complete(match string) []flags.Completion {
653 conn, err := NewConnection()
654 if err != nil {
655 return nil
656 }
657 defer conn.Close()
658
Scott Baker9173ed82020-05-19 08:30:12 -0700659 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700660
David K. Bainbridge9189c632021-03-26 21:52:21 +0000661 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700662 defer cancel()
663
Scott Baker9173ed82020-05-19 08:30:12 -0700664 devices, err := client.ListDevices(ctx, &empty.Empty{})
Zack Williamse940c7a2019-08-21 14:25:39 -0700665 if err != nil {
666 return nil
667 }
668
669 list := make([]flags.Completion, 0)
Scott Baker9173ed82020-05-19 08:30:12 -0700670 for _, item := range devices.Items {
671 if strings.HasPrefix(item.Id, match) {
672 list = append(list, flags.Completion{Item: item.Id})
Zack Williamse940c7a2019-08-21 14:25:39 -0700673 }
674 }
675
676 return list
677}
678
679func (options *DeviceList) Execute(args []string) error {
680
681 conn, err := NewConnection()
682 if err != nil {
683 return err
684 }
685 defer conn.Close()
686
Scott Baker9173ed82020-05-19 08:30:12 -0700687 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700688
David K. Bainbridge9189c632021-03-26 21:52:21 +0000689 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700690 defer cancel()
691
Scott Baker9173ed82020-05-19 08:30:12 -0700692 devices, err := client.ListDevices(ctx, &empty.Empty{})
Zack Williamse940c7a2019-08-21 14:25:39 -0700693 if err != nil {
694 return err
695 }
696
697 outputFormat := CharReplacer.Replace(options.Format)
698 if outputFormat == "" {
David Bainbridgea6722342019-10-24 23:55:53 +0000699 outputFormat = GetCommandOptionWithDefault("device-list", "format", DEFAULT_DEVICE_FORMAT)
Zack Williamse940c7a2019-08-21 14:25:39 -0700700 }
701 if options.Quiet {
702 outputFormat = "{{.Id}}"
703 }
704
David Bainbridgea6722342019-10-24 23:55:53 +0000705 orderBy := options.OrderBy
706 if orderBy == "" {
707 orderBy = GetCommandOptionWithDefault("device-list", "order", "")
708 }
709
Scott Baker9173ed82020-05-19 08:30:12 -0700710 // Make sure json output prints an empty list, not "null"
711 if devices.Items == nil {
712 devices.Items = make([]*voltha.Device, 0)
Zack Williamse940c7a2019-08-21 14:25:39 -0700713 }
714
715 result := CommandResult{
716 Format: format.Format(outputFormat),
717 Filter: options.Filter,
David Bainbridgea6722342019-10-24 23:55:53 +0000718 OrderBy: orderBy,
Zack Williamse940c7a2019-08-21 14:25:39 -0700719 OutputAs: toOutputType(options.OutputAs),
720 NameLimit: options.NameLimit,
Scott Baker9173ed82020-05-19 08:30:12 -0700721 Data: devices.Items,
Zack Williamse940c7a2019-08-21 14:25:39 -0700722 }
723
724 GenerateOutput(&result)
725 return nil
726}
727
728func (options *DeviceCreate) Execute(args []string) error {
729
Scott Baker9173ed82020-05-19 08:30:12 -0700730 device := voltha.Device{}
Zack Williamse940c7a2019-08-21 14:25:39 -0700731 if options.HostAndPort != "" {
Scott Baker9173ed82020-05-19 08:30:12 -0700732 device.Address = &voltha.Device_HostAndPort{HostAndPort: options.HostAndPort}
Zack Williamse940c7a2019-08-21 14:25:39 -0700733 } else if options.IPAddress != "" {
Scott Baker9173ed82020-05-19 08:30:12 -0700734 device.Address = &voltha.Device_Ipv4Address{Ipv4Address: options.IPAddress}
Hardik Windlassce1de342020-02-04 21:58:07 +0000735 }
736 if options.MACAddress != "" {
Scott Baker9173ed82020-05-19 08:30:12 -0700737 device.MacAddress = strings.ToLower(options.MACAddress)
Zack Williamse940c7a2019-08-21 14:25:39 -0700738 }
739 if options.DeviceType != "" {
Scott Baker9173ed82020-05-19 08:30:12 -0700740 device.Type = options.DeviceType
Zack Williamse940c7a2019-08-21 14:25:39 -0700741 }
742
743 conn, err := NewConnection()
744 if err != nil {
745 return err
746 }
747 defer conn.Close()
748
Scott Baker9173ed82020-05-19 08:30:12 -0700749 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700750
David K. Bainbridge9189c632021-03-26 21:52:21 +0000751 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700752 defer cancel()
753
Scott Baker9173ed82020-05-19 08:30:12 -0700754 createdDevice, err := client.CreateDevice(ctx, &device)
Zack Williamse940c7a2019-08-21 14:25:39 -0700755 if err != nil {
756 return err
Zack Williamse940c7a2019-08-21 14:25:39 -0700757 }
758
Scott Baker9173ed82020-05-19 08:30:12 -0700759 fmt.Printf("%s\n", createdDevice.Id)
Zack Williamse940c7a2019-08-21 14:25:39 -0700760
761 return nil
762}
763
764func (options *DeviceDelete) Execute(args []string) error {
765
766 conn, err := NewConnection()
767 if err != nil {
768 return err
769 }
770 defer conn.Close()
771
Scott Baker9173ed82020-05-19 08:30:12 -0700772 client := voltha.NewVolthaServiceClient(conn)
David Bainbridge7052fe82020-03-25 10:37:00 -0700773 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -0700774 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +0000775 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700776 defer cancel()
777
Scott Baker9173ed82020-05-19 08:30:12 -0700778 id := voltha.ID{Id: string(i)}
Himani Chawla9933ddc2020-10-12 23:53:27 +0530779 if options.Force {
780 _, err = client.ForceDeleteDevice(ctx, &id)
781 } else {
782 _, err = client.DeleteDevice(ctx, &id)
783 }
Scott Baker9173ed82020-05-19 08:30:12 -0700784
Zack Williamse940c7a2019-08-21 14:25:39 -0700785 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +0000786 Error.Printf("Error while deleting '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -0700787 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -0700788 continue
Zack Williamse940c7a2019-08-21 14:25:39 -0700789 }
790 fmt.Printf("%s\n", i)
791 }
792
David Bainbridge7052fe82020-03-25 10:37:00 -0700793 if lastErr != nil {
794 return NoReportErr
795 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700796 return nil
797}
798
799func (options *DeviceEnable) Execute(args []string) error {
800 conn, err := NewConnection()
801 if err != nil {
802 return err
803 }
804 defer conn.Close()
805
Scott Baker9173ed82020-05-19 08:30:12 -0700806 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700807
David Bainbridge7052fe82020-03-25 10:37:00 -0700808 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -0700809 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +0000810 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700811 defer cancel()
812
Scott Baker9173ed82020-05-19 08:30:12 -0700813 id := voltha.ID{Id: string(i)}
814
815 _, err := client.EnableDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -0700816 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +0000817 Error.Printf("Error while enabling '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -0700818 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -0700819 continue
Zack Williamse940c7a2019-08-21 14:25:39 -0700820 }
821 fmt.Printf("%s\n", i)
822 }
823
David Bainbridge7052fe82020-03-25 10:37:00 -0700824 if lastErr != nil {
825 return NoReportErr
826 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700827 return nil
828}
829
830func (options *DeviceDisable) Execute(args []string) error {
831 conn, err := NewConnection()
832 if err != nil {
833 return err
834 }
835 defer conn.Close()
836
Scott Baker9173ed82020-05-19 08:30:12 -0700837 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700838
David Bainbridge7052fe82020-03-25 10:37:00 -0700839 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -0700840 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +0000841 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700842 defer cancel()
843
Scott Baker9173ed82020-05-19 08:30:12 -0700844 id := voltha.ID{Id: string(i)}
845
846 _, err := client.DisableDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -0700847 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +0000848 Error.Printf("Error while disabling '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -0700849 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -0700850 continue
Zack Williamse940c7a2019-08-21 14:25:39 -0700851 }
852 fmt.Printf("%s\n", i)
853 }
854
David Bainbridge7052fe82020-03-25 10:37:00 -0700855 if lastErr != nil {
856 return NoReportErr
857 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700858 return nil
859}
860
861func (options *DeviceReboot) Execute(args []string) error {
862 conn, err := NewConnection()
863 if err != nil {
864 return err
865 }
866 defer conn.Close()
867
Scott Baker9173ed82020-05-19 08:30:12 -0700868 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700869
David Bainbridge7052fe82020-03-25 10:37:00 -0700870 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -0700871 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +0000872 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700873 defer cancel()
874
Scott Baker9173ed82020-05-19 08:30:12 -0700875 id := voltha.ID{Id: string(i)}
876
877 _, err := client.RebootDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -0700878 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +0000879 Error.Printf("Error while rebooting '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -0700880 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -0700881 continue
Zack Williamse940c7a2019-08-21 14:25:39 -0700882 }
883 fmt.Printf("%s\n", i)
884 }
885
David Bainbridge7052fe82020-03-25 10:37:00 -0700886 if lastErr != nil {
887 return NoReportErr
888 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700889 return nil
890}
891
892func (options *DevicePortList) Execute(args []string) error {
893
894 conn, err := NewConnection()
895 if err != nil {
896 return err
897 }
898 defer conn.Close()
899
Scott Baker9173ed82020-05-19 08:30:12 -0700900 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700901
David K. Bainbridge9189c632021-03-26 21:52:21 +0000902 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700903 defer cancel()
904
Scott Baker9173ed82020-05-19 08:30:12 -0700905 id := voltha.ID{Id: string(options.Args.Id)}
Zack Williamse940c7a2019-08-21 14:25:39 -0700906
Scott Baker9173ed82020-05-19 08:30:12 -0700907 ports, err := client.ListDevicePorts(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -0700908 if err != nil {
909 return err
910 }
911
912 outputFormat := CharReplacer.Replace(options.Format)
913 if outputFormat == "" {
David Bainbridgea6722342019-10-24 23:55:53 +0000914 outputFormat = GetCommandOptionWithDefault("device-ports", "format", DEFAULT_DEVICE_PORTS_FORMAT)
Zack Williamse940c7a2019-08-21 14:25:39 -0700915 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700916
David Bainbridgea6722342019-10-24 23:55:53 +0000917 orderBy := options.OrderBy
918 if orderBy == "" {
919 orderBy = GetCommandOptionWithDefault("device-ports", "order", "")
920 }
921
Zack Williamse940c7a2019-08-21 14:25:39 -0700922 result := CommandResult{
923 Format: format.Format(outputFormat),
924 Filter: options.Filter,
David Bainbridgea6722342019-10-24 23:55:53 +0000925 OrderBy: orderBy,
Zack Williamse940c7a2019-08-21 14:25:39 -0700926 OutputAs: toOutputType(options.OutputAs),
927 NameLimit: options.NameLimit,
Scott Baker9173ed82020-05-19 08:30:12 -0700928 Data: ports.Items,
Zack Williamse940c7a2019-08-21 14:25:39 -0700929 }
930
931 GenerateOutput(&result)
932 return nil
933}
934
935func (options *DeviceFlowList) Execute(args []string) error {
936 fl := &FlowList{}
937 fl.ListOutputOptions = options.ListOutputOptions
Maninder045921e2020-09-29 16:46:02 +0530938 fl.FlowIdOptions = options.FlowIdOptions
Zack Williamse940c7a2019-08-21 14:25:39 -0700939 fl.Args.Id = string(options.Args.Id)
David Bainbridgea6722342019-10-24 23:55:53 +0000940 fl.Method = "device-flows"
Zack Williamse940c7a2019-08-21 14:25:39 -0700941 return fl.Execute(args)
942}
943
Himani Chawla3c161c62021-05-13 16:36:51 +0530944func (options *DeviceFlowGroupList) Execute(args []string) error {
945 grp := &GroupList{}
946 grp.ListOutputOptions = options.ListOutputOptions
947 grp.GroupListOptions = options.GroupListOptions
948 grp.Args.Id = string(options.Args.Id)
949 grp.Method = "device-groups"
950 return grp.Execute(args)
951}
952
Zack Williamse940c7a2019-08-21 14:25:39 -0700953func (options *DeviceInspect) Execute(args []string) error {
954 if len(args) > 0 {
955 return fmt.Errorf("only a single argument 'DEVICE_ID' can be provided")
956 }
957
958 conn, err := NewConnection()
959 if err != nil {
960 return err
961 }
962 defer conn.Close()
963
Scott Baker9173ed82020-05-19 08:30:12 -0700964 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700965
David K. Bainbridge9189c632021-03-26 21:52:21 +0000966 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700967 defer cancel()
968
Scott Baker9173ed82020-05-19 08:30:12 -0700969 id := voltha.ID{Id: string(options.Args.Id)}
Zack Williamse940c7a2019-08-21 14:25:39 -0700970
Scott Baker9173ed82020-05-19 08:30:12 -0700971 device, err := client.GetDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -0700972 if err != nil {
973 return err
974 }
975
Zack Williamse940c7a2019-08-21 14:25:39 -0700976 outputFormat := CharReplacer.Replace(options.Format)
977 if outputFormat == "" {
David Bainbridgea6722342019-10-24 23:55:53 +0000978 outputFormat = GetCommandOptionWithDefault("device-inspect", "format", DEFAULT_DEVICE_INSPECT_FORMAT)
Zack Williamse940c7a2019-08-21 14:25:39 -0700979 }
980 if options.Quiet {
981 outputFormat = "{{.Id}}"
982 }
983
984 result := CommandResult{
985 Format: format.Format(outputFormat),
986 OutputAs: toOutputType(options.OutputAs),
987 NameLimit: options.NameLimit,
988 Data: device,
989 }
990 GenerateOutput(&result)
991 return nil
992}
kesavand12cd8eb2020-01-20 22:25:22 -0500993
994/*Device Port Enable */
995func (options *DevicePortEnable) Execute(args []string) error {
996 conn, err := NewConnection()
997 if err != nil {
998 return err
999 }
1000 defer conn.Close()
1001
Scott Baker9173ed82020-05-19 08:30:12 -07001002 client := voltha.NewVolthaServiceClient(conn)
kesavand12cd8eb2020-01-20 22:25:22 -05001003
David K. Bainbridge9189c632021-03-26 21:52:21 +00001004 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand12cd8eb2020-01-20 22:25:22 -05001005 defer cancel()
1006
Scott Baker9173ed82020-05-19 08:30:12 -07001007 port := voltha.Port{DeviceId: string(options.Args.Id), PortNo: uint32(options.Args.PortId)}
1008
1009 _, err = client.EnablePort(ctx, &port)
kesavand12cd8eb2020-01-20 22:25:22 -05001010 if err != nil {
1011 Error.Printf("Error enabling port number %v on device Id %s,err=%s\n", options.Args.PortId, options.Args.Id, ErrorToString(err))
1012 return err
kesavand12cd8eb2020-01-20 22:25:22 -05001013 }
1014
1015 return nil
1016}
1017
Scott Baker9173ed82020-05-19 08:30:12 -07001018/*Device Port Disable */
kesavand12cd8eb2020-01-20 22:25:22 -05001019func (options *DevicePortDisable) Execute(args []string) error {
1020 conn, err := NewConnection()
1021 if err != nil {
1022 return err
1023 }
1024 defer conn.Close()
1025
Scott Baker9173ed82020-05-19 08:30:12 -07001026 client := voltha.NewVolthaServiceClient(conn)
1027
David K. Bainbridge9189c632021-03-26 21:52:21 +00001028 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand12cd8eb2020-01-20 22:25:22 -05001029 defer cancel()
1030
Scott Baker9173ed82020-05-19 08:30:12 -07001031 port := voltha.Port{DeviceId: string(options.Args.Id), PortNo: uint32(options.Args.PortId)}
1032
1033 _, err = client.DisablePort(ctx, &port)
kesavand12cd8eb2020-01-20 22:25:22 -05001034 if err != nil {
Scott Baker9173ed82020-05-19 08:30:12 -07001035 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 -05001036 return err
kesavand12cd8eb2020-01-20 22:25:22 -05001037 }
Scott Baker9173ed82020-05-19 08:30:12 -07001038
kesavand12cd8eb2020-01-20 22:25:22 -05001039 return nil
1040}
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08001041
Rohan Agrawald7df3772020-06-29 11:23:36 +00001042func (options *DevicePmConfigSetMaxSkew) Execute(args []string) error {
1043 conn, err := NewConnection()
1044 if err != nil {
1045 return err
1046 }
1047 defer conn.Close()
1048
1049 client := voltha.NewVolthaServiceClient(conn)
1050
David K. Bainbridge9189c632021-03-26 21:52:21 +00001051 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawald7df3772020-06-29 11:23:36 +00001052 defer cancel()
1053
1054 id := voltha.ID{Id: string(options.Args.Id)}
1055
1056 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1057 if err != nil {
1058 return err
1059 }
1060
1061 pmConfigs.MaxSkew = options.Args.MaxSkew
1062
1063 _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs)
1064 if err != nil {
1065 return err
1066 }
1067
1068 return nil
1069}
1070
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001071func (options *DevicePmConfigsGet) Execute(args []string) error {
1072
1073 conn, err := NewConnection()
1074 if err != nil {
1075 return err
1076 }
1077 defer conn.Close()
1078
1079 client := voltha.NewVolthaServiceClient(conn)
1080
David K. Bainbridge9189c632021-03-26 21:52:21 +00001081 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001082 defer cancel()
1083
1084 id := voltha.ID{Id: string(options.Args.Id)}
1085
1086 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1087 if err != nil {
1088 return err
1089 }
1090
1091 outputFormat := CharReplacer.Replace(options.Format)
1092 if outputFormat == "" {
1093 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GET_FORMAT)
1094 }
1095
1096 orderBy := options.OrderBy
1097 if orderBy == "" {
1098 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1099 }
1100
1101 result := CommandResult{
1102 Format: format.Format(outputFormat),
1103 Filter: options.Filter,
1104 OrderBy: orderBy,
1105 OutputAs: toOutputType(options.OutputAs),
1106 NameLimit: options.NameLimit,
1107 Data: pmConfigs,
1108 }
1109
1110 GenerateOutput(&result)
1111 return nil
1112
1113}
1114
1115func (options *DevicePmConfigMetricList) Execute(args []string) error {
1116
1117 conn, err := NewConnection()
1118 if err != nil {
1119 return err
1120 }
1121 defer conn.Close()
1122
1123 client := voltha.NewVolthaServiceClient(conn)
1124
David K. Bainbridge9189c632021-03-26 21:52:21 +00001125 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001126 defer cancel()
1127
1128 id := voltha.ID{Id: string(options.Args.Id)}
1129
1130 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1131 if err != nil {
1132 return err
1133 }
1134
1135 if !pmConfigs.Grouped {
1136 for _, metric := range pmConfigs.Metrics {
1137 if metric.SampleFreq == 0 {
1138 metric.SampleFreq = pmConfigs.DefaultFreq
1139 }
1140 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001141 outputFormat := CharReplacer.Replace(options.Format)
1142 if outputFormat == "" {
1143 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_METRIC_LIST_FORMAT)
1144 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001145
Rohan Agrawalbca69122020-06-17 14:59:03 +00001146 orderBy := options.OrderBy
1147 if orderBy == "" {
1148 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1149 }
1150
1151 result := CommandResult{
1152 Format: format.Format(outputFormat),
1153 Filter: options.Filter,
1154 OrderBy: orderBy,
1155 OutputAs: toOutputType(options.OutputAs),
1156 NameLimit: options.NameLimit,
1157 Data: pmConfigs.Metrics,
1158 }
1159
1160 GenerateOutput(&result)
1161 return nil
1162 } else {
1163 return fmt.Errorf("Device '%s' does not have Non Grouped Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001164 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001165}
1166
1167func (options *DevicePmConfigMetricEnable) Execute(args []string) error {
1168
1169 conn, err := NewConnection()
1170 if err != nil {
1171 return err
1172 }
1173 defer conn.Close()
1174
1175 client := voltha.NewVolthaServiceClient(conn)
1176
David K. Bainbridge9189c632021-03-26 21:52:21 +00001177 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001178 defer cancel()
1179
1180 id := voltha.ID{Id: string(options.Args.Id)}
1181
1182 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1183 if err != nil {
1184 return err
1185 }
1186
1187 if !pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001188 metrics := make(map[string]struct{})
1189 for _, metric := range pmConfigs.Metrics {
1190 metrics[metric.Name] = struct{}{}
1191 }
1192
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001193 for _, metric := range pmConfigs.Metrics {
1194 for _, mName := range options.Args.Metrics {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001195 if _, exist := metrics[string(mName)]; !exist {
1196 return fmt.Errorf("Metric Name '%s' does not exist", mName)
1197 }
1198
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001199 if string(mName) == metric.Name && !metric.Enabled {
1200 metric.Enabled = true
1201 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1202 if err != nil {
1203 return err
1204 }
1205 }
1206 }
1207 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001208 } else {
1209 return fmt.Errorf("Device '%s' does not have Non Grouped Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001210 }
1211 return nil
1212}
1213
1214func (options *DevicePmConfigMetricDisable) Execute(args []string) error {
1215
1216 conn, err := NewConnection()
1217 if err != nil {
1218 return err
1219 }
1220 defer conn.Close()
1221
1222 client := voltha.NewVolthaServiceClient(conn)
1223
David K. Bainbridge9189c632021-03-26 21:52:21 +00001224 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001225 defer cancel()
1226
1227 id := voltha.ID{Id: string(options.Args.Id)}
1228
1229 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1230 if err != nil {
1231 return err
1232 }
1233
1234 if !pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001235 metrics := make(map[string]struct{})
1236 for _, metric := range pmConfigs.Metrics {
1237 metrics[metric.Name] = struct{}{}
1238 }
1239
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001240 for _, metric := range pmConfigs.Metrics {
1241 for _, mName := range options.Args.Metrics {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001242 if _, have := metrics[string(mName)]; !have {
1243 return fmt.Errorf("Metric Name '%s' does not exist", mName)
1244 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001245 if string(mName) == metric.Name && metric.Enabled {
1246 metric.Enabled = false
1247 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1248 if err != nil {
1249 return err
1250 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001251 } else {
1252 return fmt.Errorf("Metric '%s' cannot be disabled", string(mName))
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001253 }
1254 }
1255 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001256 } else {
1257 return fmt.Errorf("Device '%s' does not have Non Grouped Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001258 }
1259 return nil
1260}
1261
1262func (options *DevicePmConfigGroupEnable) Execute(args []string) error {
1263
1264 conn, err := NewConnection()
1265 if err != nil {
1266 return err
1267 }
1268 defer conn.Close()
1269
1270 client := voltha.NewVolthaServiceClient(conn)
1271
David K. Bainbridge9189c632021-03-26 21:52:21 +00001272 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001273 defer cancel()
1274
1275 id := voltha.ID{Id: string(options.Args.Id)}
1276
1277 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1278 if err != nil {
1279 return err
1280 }
1281
1282 if pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001283 groups := make(map[string]struct{})
1284 for _, group := range pmConfigs.Groups {
1285 groups[group.GroupName] = struct{}{}
1286 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001287 for _, group := range pmConfigs.Groups {
Girish Gowdra610acb42021-01-27 13:33:57 -08001288 if _, have := groups[string(options.Args.Group)]; !have {
1289 return fmt.Errorf("Group Name '%s' does not exist", options.Args.Group)
1290 }
1291 if string(options.Args.Group) == group.GroupName && !group.Enabled {
1292 group.Enabled = true
1293 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1294 if err != nil {
1295 return err
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001296 }
1297 }
1298 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001299 } else {
1300 return fmt.Errorf("Device '%s' does not have Group Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001301 }
1302 return nil
1303}
1304
1305func (options *DevicePmConfigGroupDisable) Execute(args []string) error {
1306
1307 conn, err := NewConnection()
1308 if err != nil {
1309 return err
1310 }
1311 defer conn.Close()
1312
1313 client := voltha.NewVolthaServiceClient(conn)
1314
David K. Bainbridge9189c632021-03-26 21:52:21 +00001315 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001316 defer cancel()
1317
1318 id := voltha.ID{Id: string(options.Args.Id)}
1319
1320 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1321 if err != nil {
1322 return err
1323 }
1324
1325 if pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001326 groups := make(map[string]struct{})
1327 for _, group := range pmConfigs.Groups {
1328 groups[group.GroupName] = struct{}{}
1329 }
1330
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001331 for _, group := range pmConfigs.Groups {
Girish Gowdra610acb42021-01-27 13:33:57 -08001332 if _, have := groups[string(options.Args.Group)]; !have {
1333 return fmt.Errorf("Group Name '%s' does not exist", options.Args.Group)
1334 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001335
Girish Gowdra610acb42021-01-27 13:33:57 -08001336 if string(options.Args.Group) == group.GroupName && group.Enabled {
1337 group.Enabled = false
1338 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1339 if err != nil {
1340 return err
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001341 }
1342 }
1343 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001344 } else {
1345 return fmt.Errorf("Device '%s' does not have Group Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001346 }
1347 return nil
1348}
1349
Girish Gowdra610acb42021-01-27 13:33:57 -08001350func (options *DevicePmConfigGroupFrequencySet) Execute(args []string) error {
1351
1352 conn, err := NewConnection()
1353 if err != nil {
1354 return err
1355 }
1356 defer conn.Close()
1357
1358 client := voltha.NewVolthaServiceClient(conn)
1359
David K. Bainbridge9189c632021-03-26 21:52:21 +00001360 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Girish Gowdra610acb42021-01-27 13:33:57 -08001361 defer cancel()
1362
1363 id := voltha.ID{Id: string(options.Args.Id)}
1364
1365 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1366 if err != nil {
1367 return err
1368 }
1369
1370 if pmConfigs.Grouped {
1371 groups := make(map[string]struct{})
1372 for _, group := range pmConfigs.Groups {
1373 groups[group.GroupName] = struct{}{}
1374 }
1375
1376 for _, group := range pmConfigs.Groups {
1377 if _, have := groups[string(options.Args.Group)]; !have {
1378 return fmt.Errorf("group name '%s' does not exist", options.Args.Group)
1379 }
1380
1381 if string(options.Args.Group) == group.GroupName {
1382 if !group.Enabled {
1383 return fmt.Errorf("group '%s' is not enabled", options.Args.Group)
1384 }
1385 group.GroupFreq = uint32(options.Args.Interval.Seconds())
1386 _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs)
1387 if err != nil {
1388 return err
1389 }
1390 }
1391 }
1392 } else {
1393 return fmt.Errorf("device '%s' does not have group metrics", options.Args.Id)
1394 }
1395 return nil
1396}
1397
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001398func (options *DevicePmConfigGroupList) Execute(args []string) error {
1399
1400 conn, err := NewConnection()
1401 if err != nil {
1402 return err
1403 }
1404 defer conn.Close()
1405
1406 client := voltha.NewVolthaServiceClient(conn)
1407
David K. Bainbridge9189c632021-03-26 21:52:21 +00001408 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001409 defer cancel()
1410
1411 id := voltha.ID{Id: string(options.Args.Id)}
1412
1413 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1414 if err != nil {
1415 return err
1416 }
1417
1418 if pmConfigs.Grouped {
1419 for _, group := range pmConfigs.Groups {
1420 if group.GroupFreq == 0 {
1421 group.GroupFreq = pmConfigs.DefaultFreq
1422 }
1423 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001424 outputFormat := CharReplacer.Replace(options.Format)
1425 if outputFormat == "" {
1426 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GROUP_LIST_FORMAT)
1427 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001428
Rohan Agrawalbca69122020-06-17 14:59:03 +00001429 orderBy := options.OrderBy
1430 if orderBy == "" {
1431 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1432 }
1433
1434 result := CommandResult{
1435 Format: format.Format(outputFormat),
1436 Filter: options.Filter,
1437 OrderBy: orderBy,
1438 OutputAs: toOutputType(options.OutputAs),
1439 NameLimit: options.NameLimit,
1440 Data: pmConfigs.Groups,
1441 }
1442
1443 GenerateOutput(&result)
1444 } else {
1445 return fmt.Errorf("Device '%s' does not have Group Metrics", string(options.Args.Id))
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001446 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001447 return nil
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001448}
1449
1450func (options *DevicePmConfigGroupMetricList) Execute(args []string) error {
1451
1452 var metrics []*voltha.PmConfig
1453 conn, err := NewConnection()
1454 if err != nil {
1455 return err
1456 }
1457 defer conn.Close()
1458
1459 client := voltha.NewVolthaServiceClient(conn)
1460
David K. Bainbridge9189c632021-03-26 21:52:21 +00001461 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001462 defer cancel()
1463
1464 id := voltha.ID{Id: string(options.Args.Id)}
1465
1466 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1467 if err != nil {
1468 return err
1469 }
1470
1471 for _, groups := range pmConfigs.Groups {
1472
1473 if string(options.Args.Group) == groups.GroupName {
1474 for _, metric := range groups.Metrics {
1475 if metric.SampleFreq == 0 && groups.GroupFreq == 0 {
1476 metric.SampleFreq = pmConfigs.DefaultFreq
1477 } else {
1478 metric.SampleFreq = groups.GroupFreq
1479 }
1480 }
1481 metrics = groups.Metrics
1482 }
1483 }
1484
1485 outputFormat := CharReplacer.Replace(options.Format)
1486 if outputFormat == "" {
1487 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_METRIC_LIST_FORMAT)
1488 }
1489
1490 orderBy := options.OrderBy
1491 if orderBy == "" {
1492 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1493 }
1494
1495 result := CommandResult{
1496 Format: format.Format(outputFormat),
1497 Filter: options.Filter,
1498 OrderBy: orderBy,
1499 OutputAs: toOutputType(options.OutputAs),
1500 NameLimit: options.NameLimit,
1501 Data: metrics,
1502 }
1503
1504 GenerateOutput(&result)
1505 return nil
1506
1507}
1508
1509func (options *DevicePmConfigFrequencySet) Execute(args []string) error {
1510
1511 conn, err := NewConnection()
1512 if err != nil {
1513 return err
1514 }
1515 defer conn.Close()
1516
1517 client := voltha.NewVolthaServiceClient(conn)
1518
David K. Bainbridge9189c632021-03-26 21:52:21 +00001519 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001520 defer cancel()
1521
1522 id := voltha.ID{Id: string(options.Args.Id)}
1523
1524 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1525 if err != nil {
1526 return err
1527 }
1528
Girish Gowdra610acb42021-01-27 13:33:57 -08001529 pmConfigs.DefaultFreq = uint32(options.Args.Interval.Seconds())
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001530
1531 _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs)
1532 if err != nil {
1533 return err
1534 }
1535
1536 outputFormat := CharReplacer.Replace(options.Format)
1537 if outputFormat == "" {
1538 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GET_FORMAT)
1539 }
1540 if options.Quiet {
1541 outputFormat = "{{.Id}}"
1542 }
1543
1544 result := CommandResult{
1545 Format: format.Format(outputFormat),
1546 OutputAs: toOutputType(options.OutputAs),
1547 NameLimit: options.NameLimit,
1548 Data: pmConfigs,
1549 }
1550
1551 GenerateOutput(&result)
1552 return nil
1553
1554}
1555
kesavand3e2f9f62021-04-22 11:06:38 +05301556func (options *OnuDownloadImage) Execute(args []string) error {
1557
1558 conn, err := NewConnection()
1559 if err != nil {
1560 return err
1561 }
1562 defer conn.Close()
1563
1564 client := voltha.NewVolthaServiceClient(conn)
1565
1566 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1567 defer cancel()
1568
1569 var devIDList []*common.ID
1570 for _, i := range options.Args.IDs {
1571
1572 devIDList = append(devIDList, &common.ID{Id: string(i)})
1573 }
1574
1575 downloadImage := voltha.DeviceImageDownloadRequest{
1576 DeviceId: devIDList,
1577 Image: &voltha.Image{
1578 Url: options.Args.Url,
1579 Crc32: options.Args.Crc,
ssiddiqui7bc89e92021-05-20 20:58:02 +05301580 Vendor: options.Args.Vendor,
kesavand3e2f9f62021-04-22 11:06:38 +05301581 Version: options.Args.ImageVersion,
1582 },
1583 ActivateOnSuccess: options.Args.ActivateOnSuccess,
1584 CommitOnSuccess: options.Args.CommitOnSuccess,
1585 }
1586
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001587 deviceImageResp, err := client.DownloadImageToDevice(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301588 if err != nil {
1589 return err
1590 }
1591
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001592 outputFormat := GetCommandOptionWithDefault("onu-image-download", "format", ONU_IMAGE_STATUS_FORMAT)
1593 // Make sure json output prints an empty list, not "null"
1594 if deviceImageResp.DeviceImageStates == nil {
1595 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1596 }
1597 result := CommandResult{
1598 Format: format.Format(outputFormat),
1599 OutputAs: toOutputType(options.OutputAs),
1600 NameLimit: options.NameLimit,
1601 Data: deviceImageResp.DeviceImageStates,
1602 }
1603 GenerateOutput(&result)
kesavand3e2f9f62021-04-22 11:06:38 +05301604 return nil
1605
1606}
1607
1608func (options *OnuActivateImage) Execute(args []string) error {
1609
1610 conn, err := NewConnection()
1611 if err != nil {
1612 return err
1613 }
1614 defer conn.Close()
1615
1616 client := voltha.NewVolthaServiceClient(conn)
1617
1618 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1619 defer cancel()
1620
1621 var devIDList []*common.ID
1622 for _, i := range options.Args.IDs {
1623
1624 devIDList = append(devIDList, &common.ID{Id: string(i)})
1625 }
1626
1627 downloadImage := voltha.DeviceImageRequest{
1628 DeviceId: devIDList,
1629 Version: options.Args.ImageVersion,
1630 CommitOnSuccess: options.Args.CommitOnSuccess,
1631 }
1632
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001633 deviceImageResp, err := client.ActivateImage(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301634 if err != nil {
1635 return err
1636 }
1637
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001638 outputFormat := GetCommandOptionWithDefault("onu-image-activate", "format", ONU_IMAGE_STATUS_FORMAT)
1639 // Make sure json output prints an empty list, not "null"
1640 if deviceImageResp.DeviceImageStates == nil {
1641 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1642 }
1643 result := CommandResult{
1644 Format: format.Format(outputFormat),
1645 OutputAs: toOutputType(options.OutputAs),
1646 NameLimit: options.NameLimit,
1647 Data: deviceImageResp.DeviceImageStates,
1648 }
1649 GenerateOutput(&result)
1650
kesavand3e2f9f62021-04-22 11:06:38 +05301651 return nil
1652
1653}
1654
1655func (options *OnuAbortUpgradeImage) Execute(args []string) error {
1656
1657 conn, err := NewConnection()
1658 if err != nil {
1659 return err
1660 }
1661 defer conn.Close()
1662
1663 client := voltha.NewVolthaServiceClient(conn)
1664
1665 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1666 defer cancel()
1667
1668 var devIDList []*common.ID
1669 for _, i := range options.Args.IDs {
1670
1671 devIDList = append(devIDList, &common.ID{Id: string(i)})
1672 }
1673
1674 downloadImage := voltha.DeviceImageRequest{
1675 DeviceId: devIDList,
1676 Version: options.Args.ImageVersion,
1677 }
1678
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001679 deviceImageResp, err := client.AbortImageUpgradeToDevice(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301680 if err != nil {
1681 return err
1682 }
1683
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001684 outputFormat := GetCommandOptionWithDefault("onu-image-abort", "format", ONU_IMAGE_STATUS_FORMAT)
1685 // Make sure json output prints an empty list, not "null"
1686 if deviceImageResp.DeviceImageStates == nil {
1687 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1688 }
1689 result := CommandResult{
1690 Format: format.Format(outputFormat),
1691 OutputAs: toOutputType(options.OutputAs),
1692 NameLimit: options.NameLimit,
1693 Data: deviceImageResp.DeviceImageStates,
1694 }
1695 GenerateOutput(&result)
1696
kesavand3e2f9f62021-04-22 11:06:38 +05301697 return nil
1698
1699}
1700
1701func (options *OnuCommitImage) Execute(args []string) error {
1702
1703 conn, err := NewConnection()
1704 if err != nil {
1705 return err
1706 }
1707 defer conn.Close()
1708
1709 client := voltha.NewVolthaServiceClient(conn)
1710
1711 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1712 defer cancel()
1713
1714 var devIDList []*common.ID
1715 for _, i := range options.Args.IDs {
1716
1717 devIDList = append(devIDList, &common.ID{Id: string(i)})
1718 }
1719 downloadImage := voltha.DeviceImageRequest{
1720 DeviceId: devIDList,
1721 Version: options.Args.ImageVersion,
1722 }
1723
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001724 deviceImageResp, err := client.CommitImage(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301725 if err != nil {
1726 return err
1727 }
1728
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001729 outputFormat := GetCommandOptionWithDefault("onu-image-commit", "format", ONU_IMAGE_STATUS_FORMAT)
1730 // Make sure json output prints an empty list, not "null"
1731 if deviceImageResp.DeviceImageStates == nil {
1732 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1733 }
1734 result := CommandResult{
1735 Format: format.Format(outputFormat),
1736 OutputAs: toOutputType(options.OutputAs),
1737 NameLimit: options.NameLimit,
1738 Data: deviceImageResp.DeviceImageStates,
1739 }
1740 GenerateOutput(&result)
1741
kesavand3e2f9f62021-04-22 11:06:38 +05301742 return nil
1743
1744}
1745
1746func (options *OnuListImages) Execute(args []string) error {
1747
1748 conn, err := NewConnection()
1749 if err != nil {
1750 return err
1751 }
1752 defer conn.Close()
1753
1754 client := voltha.NewVolthaServiceClient(conn)
1755
1756 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1757 defer cancel()
1758
1759 id := common.ID{Id: string(options.Args.Id)}
1760
1761 onuImages, err := client.GetOnuImages(ctx, &id)
1762 if err != nil {
1763 return err
1764 }
1765
1766 outputFormat := CharReplacer.Replace(options.Format)
1767 if outputFormat == "" {
1768 outputFormat = GetCommandOptionWithDefault("onu-image-list", "format", ONU_IMAGE_LIST_FORMAT)
1769 }
1770
1771 if options.Quiet {
1772 outputFormat = "{{.Id}}"
1773 }
1774
1775 //TODO orderby
1776
1777 // Make sure json output prints an empty list, not "null"
1778 if onuImages.Items == nil {
1779 onuImages.Items = make([]*voltha.OnuImage, 0)
1780 }
1781
1782 result := CommandResult{
1783 Format: format.Format(outputFormat),
1784 OutputAs: toOutputType(options.OutputAs),
1785 NameLimit: options.NameLimit,
1786 Data: onuImages.Items,
1787 }
1788
1789 GenerateOutput(&result)
1790 return nil
1791
1792}
1793
1794func (options *OnuImageStatus) Execute(args []string) error {
1795
1796 conn, err := NewConnection()
1797 if err != nil {
1798 return err
1799 }
1800 defer conn.Close()
1801
1802 client := voltha.NewVolthaServiceClient(conn)
1803
1804 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1805 defer cancel()
1806
1807 var devIDList []*common.ID
1808 for _, i := range options.Args.IDs {
1809
1810 devIDList = append(devIDList, &common.ID{Id: string(i)})
1811 }
1812
1813 imageStatusReq := voltha.DeviceImageRequest{
1814 DeviceId: devIDList,
1815 Version: options.Args.ImageVersion,
1816 }
1817 imageStatus, err := client.GetImageStatus(ctx, &imageStatusReq)
1818 if err != nil {
1819 return err
1820 }
1821
1822 outputFormat := CharReplacer.Replace(options.Format)
1823 if outputFormat == "" {
1824 outputFormat = GetCommandOptionWithDefault("device-image-list", "format", ONU_IMAGE_STATUS_FORMAT)
1825 }
1826
1827 if options.Quiet {
1828 outputFormat = "{{.Id}}"
1829 }
1830
1831 //TODO orderby
1832
1833 // Make sure json output prints an empty list, not "null"
1834 if imageStatus.DeviceImageStates == nil {
1835 imageStatus.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1836 }
1837
1838 result := CommandResult{
1839 Format: format.Format(outputFormat),
1840 OutputAs: toOutputType(options.OutputAs),
1841 NameLimit: options.NameLimit,
1842 Data: imageStatus.DeviceImageStates,
1843 }
1844
1845 GenerateOutput(&result)
1846 return nil
1847
1848}
1849
Andrea Campanella791d88b2021-01-08 13:29:00 +01001850func (options *DeviceOnuListImages) Execute(args []string) error {
1851
1852 conn, err := NewConnection()
1853 if err != nil {
1854 return err
1855 }
1856 defer conn.Close()
1857
1858 client := voltha.NewVolthaServiceClient(conn)
1859
David K. Bainbridge9189c632021-03-26 21:52:21 +00001860 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Andrea Campanella791d88b2021-01-08 13:29:00 +01001861 defer cancel()
1862
1863 id := common.ID{Id: string(options.Args.Id)}
1864
1865 imageDownloads, err := client.ListImageDownloads(ctx, &id)
1866 if err != nil {
1867 return err
1868 }
1869
1870 outputFormat := CharReplacer.Replace(options.Format)
1871 if outputFormat == "" {
1872 outputFormat = GetCommandOptionWithDefault("device-image-list", "format", DEFAULT_DEVICE_IMAGE_LIST_GET_FORMAT)
1873 }
1874
1875 if options.Quiet {
1876 outputFormat = "{{.Id}}"
1877 }
1878
1879 //TODO orderby
1880
1881 // Make sure json output prints an empty list, not "null"
1882 if imageDownloads.Items == nil {
1883 imageDownloads.Items = make([]*voltha.ImageDownload, 0)
1884 }
1885
1886 result := CommandResult{
1887 Format: format.Format(outputFormat),
1888 OutputAs: toOutputType(options.OutputAs),
1889 NameLimit: options.NameLimit,
1890 Data: imageDownloads.Items,
1891 }
1892
1893 GenerateOutput(&result)
1894 return nil
1895
1896}
1897
1898func (options *DeviceOnuDownloadImage) Execute(args []string) error {
1899
1900 conn, err := NewConnection()
1901 if err != nil {
1902 return err
1903 }
1904 defer conn.Close()
1905
1906 client := voltha.NewVolthaServiceClient(conn)
1907
David K. Bainbridge9189c632021-03-26 21:52:21 +00001908 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Andrea Campanella791d88b2021-01-08 13:29:00 +01001909 defer cancel()
1910
1911 downloadImage := voltha.ImageDownload{
1912 Id: string(options.Args.Id),
1913 Name: options.Args.Name,
1914 Url: options.Args.Url,
1915 Crc: options.Args.Crc,
1916 LocalDir: options.Args.LocalDir,
1917 }
1918
1919 _, err = client.DownloadImage(ctx, &downloadImage)
1920 if err != nil {
1921 return err
1922 }
1923
1924 return nil
1925
1926}
1927
1928func (options *DeviceOnuActivateImageUpdate) Execute(args []string) error {
1929
1930 conn, err := NewConnection()
1931 if err != nil {
1932 return err
1933 }
1934 defer conn.Close()
1935
1936 client := voltha.NewVolthaServiceClient(conn)
1937
David K. Bainbridge9189c632021-03-26 21:52:21 +00001938 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Andrea Campanella791d88b2021-01-08 13:29:00 +01001939 defer cancel()
1940
1941 downloadImage := voltha.ImageDownload{
1942 Id: string(options.Args.Id),
1943 Name: options.Args.Name,
1944 ImageVersion: options.Args.ImageVersion,
1945 SaveConfig: options.Args.SaveConfig,
1946 LocalDir: options.Args.LocalDir,
1947 }
1948
1949 _, err = client.ActivateImageUpdate(ctx, &downloadImage)
1950 if err != nil {
1951 return err
1952 }
1953
1954 return nil
1955
1956}
1957
Scott Baker9173ed82020-05-19 08:30:12 -07001958type ReturnValueRow struct {
1959 Name string `json:"name"`
1960 Result interface{} `json:"result"`
1961}
1962
kesavand8ec4fc02021-01-27 09:10:22 -05001963func (options *DeviceGetPortStats) Execute(args []string) error {
1964 conn, err := NewConnection()
1965 if err != nil {
1966 return err
1967 }
1968 defer conn.Close()
1969 client := extension.NewExtensionClient(conn)
1970 var portType extension.GetOltPortCounters_PortType
1971
1972 if options.Args.PortType == "pon" {
1973 portType = extension.GetOltPortCounters_Port_PON_OLT
1974 } else if options.Args.PortType == "nni" {
1975
1976 portType = extension.GetOltPortCounters_Port_ETHERNET_NNI
1977 } else {
1978 return fmt.Errorf("expected interface type pon/nni, provided %s", options.Args.PortType)
1979 }
1980
1981 singleGetValReq := extension.SingleGetValueRequest{
1982 TargetId: string(options.Args.Id),
1983 Request: &extension.GetValueRequest{
1984 Request: &extension.GetValueRequest_OltPortInfo{
1985 OltPortInfo: &extension.GetOltPortCounters{
1986 PortNo: options.Args.PortNo,
1987 PortType: portType,
1988 },
1989 },
1990 },
1991 }
1992
David K. Bainbridge9189c632021-03-26 21:52:21 +00001993 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand8ec4fc02021-01-27 09:10:22 -05001994 defer cancel()
1995 rv, err := client.GetExtValue(ctx, &singleGetValReq)
1996 if err != nil {
1997 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
1998 return err
1999 }
2000
2001 if rv.Response.Status != extension.GetValueResponse_OK {
2002 return fmt.Errorf("failed to get port stats %v", rv.Response.ErrReason.String())
2003 }
2004
2005 outputFormat := CharReplacer.Replace(options.Format)
2006 if outputFormat == "" {
2007 outputFormat = GetCommandOptionWithDefault("device-get-port-status", "format", DEFAULT_DEVICE_GET_PORT_STATUS_FORMAT)
2008 }
2009
2010 result := CommandResult{
2011 Format: format.Format(outputFormat),
2012 OutputAs: toOutputType(options.OutputAs),
2013 NameLimit: options.NameLimit,
2014 Data: rv.GetResponse().GetPortCoutners(),
2015 }
2016 GenerateOutput(&result)
2017 return nil
2018}
2019
Himani Chawla40acc122021-05-26 18:52:29 +05302020func (options *GetOnuStats) Execute(args []string) error {
2021 conn, err := NewConnection()
2022 if err != nil {
2023 return err
2024 }
2025 defer conn.Close()
2026 client := extension.NewExtensionClient(conn)
2027
2028 singleGetValReq := extension.SingleGetValueRequest{
2029 TargetId: string(options.Args.OltId),
2030 Request: &extension.GetValueRequest{
2031 Request: &extension.GetValueRequest_OnuPonInfo{
2032 OnuPonInfo: &extension.GetOnuCountersRequest{
2033 IntfId: options.Args.IntfId,
2034 OnuId: options.Args.OnuId,
2035 },
2036 },
2037 },
2038 }
2039 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2040 defer cancel()
2041 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2042 if err != nil {
2043 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.OltId, ErrorToString(err))
2044 return err
2045 }
2046
2047 if rv.Response.Status != extension.GetValueResponse_OK {
2048 return fmt.Errorf("failed to get onu stats %v", rv.Response.ErrReason.String())
2049 }
2050 outputFormat := CharReplacer.Replace(options.Format)
2051 data, formatStr := buildOnuStatsOutputFormat(rv.GetResponse().GetOnuPonCounters())
2052 if outputFormat == "" {
2053 outputFormat = GetCommandOptionWithDefault("device-get-onu-status", "format", formatStr)
2054 }
Himani Chawla553a1392021-06-10 23:39:17 +05302055 result := CommandResult{
2056 Format: format.Format(outputFormat),
2057 OutputAs: toOutputType(options.OutputAs),
2058 NameLimit: options.NameLimit,
2059 Data: data,
2060 }
2061 GenerateOutput(&result)
2062 return nil
2063}
Himani Chawla40acc122021-05-26 18:52:29 +05302064
Himani Chawla553a1392021-06-10 23:39:17 +05302065func (options *GetOnuEthernetFrameExtendedPmCounters) Execute(args []string) error {
2066 conn, err := NewConnection()
2067 if err != nil {
2068 return err
2069 }
2070 defer conn.Close()
2071 client := extension.NewExtensionClient(conn)
Himani Chawla806aa892021-08-30 15:51:46 +05302072 var singleGetValReq extension.SingleGetValueRequest
Himani Chawla553a1392021-06-10 23:39:17 +05302073
Himani Chawla806aa892021-08-30 15:51:46 +05302074 if options.Args.UniIndex != nil {
2075 singleGetValReq = extension.SingleGetValueRequest{
2076 TargetId: string(options.Args.Id),
2077 Request: &extension.GetValueRequest{
2078 Request: &extension.GetValueRequest_OnuInfo{
2079 OnuInfo: &extension.GetOmciEthernetFrameExtendedPmRequest{
2080 OnuDeviceId: string(options.Args.Id),
2081 Reset_: options.Reset,
2082 IsUniIndex: &extension.GetOmciEthernetFrameExtendedPmRequest_UniIndex{
2083 UniIndex: *options.Args.UniIndex,
2084 },
2085 },
Himani Chawla553a1392021-06-10 23:39:17 +05302086 },
2087 },
Himani Chawla806aa892021-08-30 15:51:46 +05302088 }
2089 } else {
2090 singleGetValReq = extension.SingleGetValueRequest{
2091 TargetId: string(options.Args.Id),
2092 Request: &extension.GetValueRequest{
2093 Request: &extension.GetValueRequest_OnuInfo{
2094 OnuInfo: &extension.GetOmciEthernetFrameExtendedPmRequest{
2095 OnuDeviceId: string(options.Args.Id),
2096 Reset_: options.Reset,
2097 },
2098 },
2099 },
2100 }
Himani Chawla553a1392021-06-10 23:39:17 +05302101 }
Himani Chawla806aa892021-08-30 15:51:46 +05302102
Himani Chawla553a1392021-06-10 23:39:17 +05302103 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2104 defer cancel()
2105 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2106 if err != nil {
2107 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2108 return err
2109 }
2110
2111 if rv.Response.Status != extension.GetValueResponse_OK {
2112 return fmt.Errorf("failed to get ethernet frame extended pm counters %v", rv.Response.ErrReason.String())
2113 }
2114 outputFormat := CharReplacer.Replace(options.Format)
2115 data := buildOnuEthernetFrameExtendedPmOutputFormat(rv.GetResponse().GetOnuCounters())
2116 if outputFormat == "" {
2117 outputFormat = GetCommandOptionWithDefault("device-get-onu-status", "format", DEFAULT_ETHERNET_FRAME_EXTENDED_PM_COUNTERS_FORMAT)
2118 }
Himani Chawla40acc122021-05-26 18:52:29 +05302119 result := CommandResult{
2120 Format: format.Format(outputFormat),
2121 OutputAs: toOutputType(options.OutputAs),
2122 NameLimit: options.NameLimit,
2123 Data: data,
2124 }
2125 GenerateOutput(&result)
2126 return nil
2127}
2128
kesavand6d1131f2021-02-05 22:38:15 +05302129func (options *UniStatus) Execute(args []string) error {
2130 conn, err := NewConnection()
2131 if err != nil {
2132 return err
2133 }
2134 defer conn.Close()
2135 client := extension.NewExtensionClient(conn)
2136
2137 singleGetValReq := extension.SingleGetValueRequest{
2138 TargetId: string(options.Args.Id),
2139 Request: &extension.GetValueRequest{
2140 Request: &extension.GetValueRequest_UniInfo{
2141 UniInfo: &extension.GetOnuUniInfoRequest{
2142 UniIndex: options.Args.UniIndex,
2143 },
2144 },
2145 },
2146 }
David K. Bainbridge9189c632021-03-26 21:52:21 +00002147 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand6d1131f2021-02-05 22:38:15 +05302148 defer cancel()
2149 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2150 if err != nil {
2151 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2152 return err
2153 }
2154 if rv.Response.Status != extension.GetValueResponse_OK {
2155 return fmt.Errorf("failed to get uni status %v", rv.Response.ErrReason.String())
2156 }
2157 outputFormat := CharReplacer.Replace(options.Format)
2158 if outputFormat == "" {
2159 outputFormat = GetCommandOptionWithDefault("device-get-uni-status", "format", DEFAULT_DEVICE_GET_UNI_STATUS_FORMAT)
2160 }
2161 result := CommandResult{
2162 Format: format.Format(outputFormat),
2163 OutputAs: toOutputType(options.OutputAs),
2164 NameLimit: options.NameLimit,
2165 Data: rv.GetResponse().GetUniInfo(),
2166 }
2167 GenerateOutput(&result)
2168 return nil
2169}
2170
Girish Gowdra4f5ce7c2021-04-29 18:53:21 -07002171func (options *OnuPonOpticalInfo) Execute(args []string) error {
2172 conn, err := NewConnection()
2173 if err != nil {
2174 return err
2175 }
2176 defer conn.Close()
2177 client := extension.NewExtensionClient(conn)
2178
2179 singleGetValReq := extension.SingleGetValueRequest{
2180 TargetId: string(options.Args.Id),
2181 Request: &extension.GetValueRequest{
2182 Request: &extension.GetValueRequest_OnuOpticalInfo{
2183 OnuOpticalInfo: &extension.GetOnuPonOpticalInfo{},
2184 },
2185 },
2186 }
2187 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2188 defer cancel()
2189 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2190 if err != nil {
2191 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2192 return err
2193 }
2194 if rv.Response.Status != extension.GetValueResponse_OK {
2195 return fmt.Errorf("failed to get onu pon optical info %v", rv.Response.ErrReason.String())
2196 }
2197 outputFormat := CharReplacer.Replace(options.Format)
2198 if outputFormat == "" {
2199 outputFormat = GetCommandOptionWithDefault("device-get-onu-pon-optical-info", "format", DEFAULT_ONU_PON_OPTICAL_INFO_STATUS_FORMAT)
2200 }
2201 result := CommandResult{
2202 Format: format.Format(outputFormat),
2203 OutputAs: toOutputType(options.OutputAs),
2204 NameLimit: options.NameLimit,
2205 Data: rv.GetResponse().GetOnuOpticalInfo(),
2206 }
2207 GenerateOutput(&result)
2208 return nil
2209}
2210
Gamze Abakac857a462021-05-26 13:45:54 +00002211func (options *RxPower) Execute(args []string) error {
2212 conn, err := NewConnection()
2213 if err != nil {
2214 return err
2215 }
2216 defer conn.Close()
2217 client := extension.NewExtensionClient(conn)
2218
2219 singleGetValReq := extension.SingleGetValueRequest{
2220 TargetId: string(options.Args.Id),
2221 Request: &extension.GetValueRequest{
2222 Request: &extension.GetValueRequest_RxPower{
2223 RxPower: &extension.GetRxPowerRequest{
2224 IntfId: options.Args.PortNo,
2225 OnuId: options.Args.OnuNo,
2226 },
2227 },
2228 },
2229 }
2230
2231 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2232 defer cancel()
2233 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2234 if err != nil {
2235 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2236 return err
2237 }
2238 if rv.Response.Status != extension.GetValueResponse_OK {
2239 return fmt.Errorf("failed to get rx power %v", rv.Response.ErrReason.String())
2240 }
2241 outputFormat := CharReplacer.Replace(options.Format)
2242 if outputFormat == "" {
2243 outputFormat = GetCommandOptionWithDefault("device-get-rx-power", "format", DEFAULT_RX_POWER_STATUS_FORMAT)
2244 }
2245 result := CommandResult{
2246 Format: format.Format(outputFormat),
2247 OutputAs: toOutputType(options.OutputAs),
2248 NameLimit: options.NameLimit,
2249 Data: rv.GetResponse().GetRxPower(),
2250 }
2251 GenerateOutput(&result)
2252 return nil
2253}
2254
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002255/*Device get Onu Distance */
2256func (options *DeviceGetExtValue) Execute(args []string) error {
2257 conn, err := NewConnection()
2258 if err != nil {
2259 return err
2260 }
2261 defer conn.Close()
2262
Scott Baker9173ed82020-05-19 08:30:12 -07002263 client := voltha.NewVolthaServiceClient(conn)
2264
2265 valueflag, okay := common.ValueType_Type_value[string(options.Args.Valueflag)]
2266 if !okay {
2267 Error.Printf("Unknown valueflag %s\n", options.Args.Valueflag)
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002268 }
2269
Scott Baker9173ed82020-05-19 08:30:12 -07002270 val := voltha.ValueSpecifier{Id: string(options.Args.Id), Value: common.ValueType_Type(valueflag)}
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002271
David K. Bainbridge9189c632021-03-26 21:52:21 +00002272 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002273 defer cancel()
2274
Scott Baker9173ed82020-05-19 08:30:12 -07002275 rv, err := client.GetExtValue(ctx, &val)
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002276 if err != nil {
2277 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2278 return err
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002279 }
2280
Scott Baker9173ed82020-05-19 08:30:12 -07002281 var rows []ReturnValueRow
2282 for name, num := range common.ValueType_Type_value {
2283 if num == 0 {
2284 // EMPTY is not a real value
2285 continue
2286 }
2287 if (rv.Error & uint32(num)) != 0 {
2288 row := ReturnValueRow{Name: name, Result: "Error"}
2289 rows = append(rows, row)
2290 }
2291 if (rv.Unsupported & uint32(num)) != 0 {
2292 row := ReturnValueRow{Name: name, Result: "Unsupported"}
2293 rows = append(rows, row)
2294 }
2295 if (rv.Set & uint32(num)) != 0 {
2296 switch name {
2297 case "DISTANCE":
2298 row := ReturnValueRow{Name: name, Result: rv.Distance}
2299 rows = append(rows, row)
2300 default:
2301 row := ReturnValueRow{Name: name, Result: "Unimplemented-in-voltctl"}
2302 rows = append(rows, row)
2303 }
2304 }
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002305 }
2306
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002307 outputFormat := CharReplacer.Replace(options.Format)
2308 if outputFormat == "" {
2309 outputFormat = GetCommandOptionWithDefault("device-value-get", "format", DEFAULT_DEVICE_VALUE_GET_FORMAT)
2310 }
2311
2312 result := CommandResult{
2313 Format: format.Format(outputFormat),
2314 OutputAs: toOutputType(options.OutputAs),
2315 NameLimit: options.NameLimit,
Scott Baker9173ed82020-05-19 08:30:12 -07002316 Data: rows,
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002317 }
2318 GenerateOutput(&result)
2319 return nil
2320}