blob: 7acac8c550b4c66870660a7a11870b93573cfd80 [file] [log] [blame]
Zack Williamse940c7a2019-08-21 14:25:39 -07001/*
2 * Copyright 2019-present Ciena Corporation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package commands
17
18import (
19 "context"
20 "fmt"
David Bainbridge7052fe82020-03-25 10:37:00 -070021 "os"
22 "strconv"
23 "strings"
Girish Gowdra610acb42021-01-27 13:33:57 -080024 "time"
David Bainbridge7052fe82020-03-25 10:37:00 -070025
Scott Baker9173ed82020-05-19 08:30:12 -070026 "github.com/golang/protobuf/ptypes/empty"
Zack Williamse940c7a2019-08-21 14:25:39 -070027 flags "github.com/jessevdk/go-flags"
Scott Baker2b0ad652019-08-21 14:57:07 -070028 "github.com/opencord/voltctl/pkg/format"
David K. Bainbridgebd6b2882021-08-26 13:31:02 +000029 "github.com/opencord/voltha-protos/v5/go/common"
30 "github.com/opencord/voltha-protos/v5/go/extension"
31 "github.com/opencord/voltha-protos/v5/go/voltha"
Zack Williamse940c7a2019-08-21 14:25:39 -070032)
33
34const (
David K. Bainbridge89003c42020-02-27 17:22:49 -080035 DEFAULT_DEVICE_FORMAT = "table{{ .Id }}\t{{.Type}}\t{{.Root}}\t{{.ParentId}}\t{{.SerialNumber}}\t{{.AdminState}}\t{{.OperStatus}}\t{{.ConnectStatus}}\t{{.Reason}}"
Hardik Windlass9361bb82022-03-23 05:58:48 +000036 DEFAULT_DEVICE_ORDER = "Type,Id"
Zack Williamse940c7a2019-08-21 14:25:39 -070037 DEFAULT_DEVICE_PORTS_FORMAT = "table{{.PortNo}}\t{{.Label}}\t{{.Type}}\t{{.AdminState}}\t{{.OperStatus}}\t{{.DeviceId}}\t{{.Peers}}"
38 DEFAULT_DEVICE_INSPECT_FORMAT = `ID: {{.Id}}
39 TYPE: {{.Type}}
40 ROOT: {{.Root}}
41 PARENTID: {{.ParentId}}
42 SERIALNUMBER: {{.SerialNumber}}
43 VLAN: {{.Vlan}}
44 ADMINSTATE: {{.AdminState}}
45 OPERSTATUS: {{.OperStatus}}
46 CONNECTSTATUS: {{.ConnectStatus}}`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +000047 DEFAULT_DEVICE_PM_CONFIG_GET_FORMAT = "table{{.DefaultFreq}}\t{{.Grouped}}\t{{.FreqOverride}}"
48 DEFAULT_DEVICE_PM_CONFIG_METRIC_LIST_FORMAT = "table{{.Name}}\t{{.Type}}\t{{.Enabled}}\t{{.SampleFreq}}"
49 DEFAULT_DEVICE_PM_CONFIG_GROUP_LIST_FORMAT = "table{{.GroupName}}\t{{.Enabled}}\t{{.GroupFreq}}"
50 DEFAULT_DEVICE_VALUE_GET_FORMAT = "table{{.Name}}\t{{.Result}}"
Andrea Campanella791d88b2021-01-08 13:29:00 +010051 DEFAULT_DEVICE_IMAGE_LIST_GET_FORMAT = "table{{.Name}}\t{{.Url}}\t{{.Crc}}\t{{.DownloadState}}\t{{.ImageVersion}}\t{{.LocalDir}}\t{{.ImageState}}\t{{.FileSize}}"
ssiddiqui7bc89e92021-05-20 20:58:02 +053052 ONU_IMAGE_LIST_FORMAT = "table{{.Version}}\t{{.IsCommited}}\t{{.IsActive}}\t{{.IsValid}}\t{{.ProductCode}}\t{{.Hash}}"
53 ONU_IMAGE_STATUS_FORMAT = "table{{.DeviceId}}\t{{.ImageState.Version}}\t{{.ImageState.DownloadState}}\t{{.ImageState.Reason}}\t{{.ImageState.ImageState}}\t"
kesavand8ec4fc02021-01-27 09:10:22 -050054 DEFAULT_DEVICE_GET_PORT_STATUS_FORMAT = `
55 TXBYTES: {{.TxBytes}}
56 TXPACKETS: {{.TxPackets}}
57 TXERRPACKETS: {{.TxErrorPackets}}
58 TXBCASTPACKETS: {{.TxBcastPackets}}
59 TXUCASTPACKETS: {{.TxUcastPackets}}
60 TXMCASTPACKETS: {{.TxMcastPackets}}
61 RXBYTES: {{.RxBytes}}
62 RXPACKETS: {{.RxPackets}}
63 RXERRPACKETS: {{.RxErrorPackets}}
64 RXBCASTPACKETS: {{.RxBcastPackets}}
65 RXUCASTPACKETS: {{.RxUcastPackets}}
66 RXMCASTPACKETS: {{.RxMcastPackets}}`
kesavand6d1131f2021-02-05 22:38:15 +053067 DEFAULT_DEVICE_GET_UNI_STATUS_FORMAT = `
68 ADMIN_STATE: {{.AdmState}}
69 OPERATIONAL_STATE: {{.OperState}}
70 CONFIG_IND: {{.ConfigInd}}`
Girish Gowdra4f5ce7c2021-04-29 18:53:21 -070071 DEFAULT_ONU_PON_OPTICAL_INFO_STATUS_FORMAT = `
72 POWER_FEED_VOLTAGE__VOLTS: {{.PowerFeedVoltage}}
73 RECEIVED_OPTICAL_POWER__dBm: {{.ReceivedOpticalPower}}
74 MEAN_OPTICAL_LAUNCH_POWER__dBm: {{.MeanOpticalLaunchPower}}
75 LASER_BIAS_CURRENT__mA: {{.LaserBiasCurrent}}
76 TEMPERATURE__Celsius: {{.Temperature}}`
Gamze Abakac857a462021-05-26 13:45:54 +000077 DEFAULT_RX_POWER_STATUS_FORMAT = `
78 INTF_ID: {{.IntfId}}
79 ONU_ID: {{.OnuId}}
80 STATUS: {{.Status}}
81 FAIL_REASON: {{.FailReason}}
82 RX_POWER : {{.RxPower}}`
Himani Chawla553a1392021-06-10 23:39:17 +053083 DEFAULT_ETHERNET_FRAME_EXTENDED_PM_COUNTERS_FORMAT = `Upstream_Drop_Events: {{.UDropEvents}}
84Upstream_Octets: {{.UOctets}}
85UFrames: {{.UFrames}}
86UBroadcastFrames: {{.UBroadcastFrames}}
87UMulticastFrames: {{.UMulticastFrames}}
88UCrcErroredFrames: {{.UCrcErroredFrames}}
89UUndersizeFrames: {{.UUndersizeFrames}}
90UOversizeFrames: {{.UOversizeFrames}}
91UFrames_64Octets: {{.UFrames_64Octets}}
92UFrames_65To_127Octets: {{.UFrames_65To_127Octets}}
93UFrames_128To_255Octets: {{.UFrames_128To_255Octets}}
94UFrames_256To_511Octets: {{.UFrames_256To_511Octets}}
95UFrames_512To_1023Octets: {{.UFrames_512To_1023Octets}}
96UFrames_1024To_1518Octets: {{.UFrames_1024To_1518Octets}}
97DDropEvents: {{.DDropEvents}}
98DOctets: {{.DOctets}}
99DFrames: {{.DFrames}}
100DBroadcastFrames: {{.DBroadcastFrames}}
101DMulticastFrames: {{.DMulticastFrames}}
102DCrcErroredFrames: {{.DCrcErroredFrames}}
103DUndersizeFrames: {{.DUndersizeFrames}}
104DOversizeFrames: {{.DOversizeFrames}}
105DFrames_64Octets: {{.DFrames_64Octets}}
106DFrames_65To_127Octets: {{.DFrames_65To_127Octets}}
107DFrames_128To_255Octets: {{.DFrames_128To_255Octets}}
108DFrames_256To_511Octets: {{.DFrames_256To_511Octets}}
109DFrames_512To_1023Octets: {{.DFrames_512To_1023Octets}}
Himani Chawlabac0f892021-08-25 17:14:06 +0530110DFrames_1024To_1518Octets: {{.DFrames_1024To_1518Octets}}
111PmFormat: {{.PmFormat}}`
Zack Williamse940c7a2019-08-21 14:25:39 -0700112)
113
114type DeviceList struct {
115 ListOutputOptions
116}
117
118type DeviceCreate struct {
David Bainbridge1a514392020-06-23 11:12:51 -0700119 DeviceType string `short:"t" required:"true" long:"devicetype" description:"Device type"`
David Bainbridge835dd0e2020-04-01 10:30:09 -0700120 MACAddress string `short:"m" long:"macaddress" default:"" description:"MAC Address"`
Zack Williamse940c7a2019-08-21 14:25:39 -0700121 IPAddress string `short:"i" long:"ipaddress" default:"" description:"IP Address"`
122 HostAndPort string `short:"H" long:"hostandport" default:"" description:"Host and port"`
123}
124
125type DeviceId string
126
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000127type MetricName string
128type GroupName string
kesavand12cd8eb2020-01-20 22:25:22 -0500129type PortNum uint32
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -0800130type ValueFlag string
kesavand12cd8eb2020-01-20 22:25:22 -0500131
Zack Williamse940c7a2019-08-21 14:25:39 -0700132type DeviceDelete struct {
Himani Chawla9933ddc2020-10-12 23:53:27 +0530133 Force bool `long:"force" description:"Delete device forcefully"`
134 Args struct {
Zack Williamse940c7a2019-08-21 14:25:39 -0700135 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
136 } `positional-args:"yes"`
137}
138
139type DeviceEnable struct {
140 Args struct {
141 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
142 } `positional-args:"yes"`
143}
144
145type DeviceDisable struct {
146 Args struct {
147 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
148 } `positional-args:"yes"`
149}
150
151type DeviceReboot struct {
152 Args struct {
153 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
154 } `positional-args:"yes"`
155}
156
157type DeviceFlowList struct {
158 ListOutputOptions
Maninder045921e2020-09-29 16:46:02 +0530159 FlowIdOptions
Zack Williamse940c7a2019-08-21 14:25:39 -0700160 Args struct {
161 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
162 } `positional-args:"yes"`
163}
164
Himani Chawla3c161c62021-05-13 16:36:51 +0530165type DeviceFlowGroupList struct {
166 ListOutputOptions
167 GroupListOptions
168 Args struct {
169 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
170 } `positional-args:"yes"`
171}
Zack Williamse940c7a2019-08-21 14:25:39 -0700172type DevicePortList struct {
173 ListOutputOptions
174 Args struct {
175 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
176 } `positional-args:"yes"`
177}
178
179type DeviceInspect struct {
180 OutputOptionsJson
181 Args struct {
182 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
183 } `positional-args:"yes"`
184}
185
kesavand12cd8eb2020-01-20 22:25:22 -0500186type DevicePortEnable struct {
187 Args struct {
188 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
189 PortId PortNum `positional-arg-name:"PORT_NUMBER" required:"yes"`
190 } `positional-args:"yes"`
191}
192
193type DevicePortDisable struct {
194 Args struct {
195 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
196 PortId PortNum `positional-arg-name:"PORT_NUMBER" required:"yes"`
197 } `positional-args:"yes"`
198}
199
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000200type DevicePmConfigsGet struct {
201 ListOutputOptions
202 Args struct {
203 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
204 } `positional-args:"yes"`
205}
206
207type DevicePmConfigMetricList struct {
208 ListOutputOptions
209 Args struct {
210 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
211 } `positional-args:"yes"`
212}
213
214type DevicePmConfigGroupList struct {
215 ListOutputOptions
216 Args struct {
217 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
218 } `positional-args:"yes"`
219}
220
221type DevicePmConfigGroupMetricList struct {
222 ListOutputOptions
223 Args struct {
224 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
225 Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"`
226 } `positional-args:"yes"`
227}
228
229type DevicePmConfigFrequencySet struct {
230 OutputOptions
231 Args struct {
Girish Gowdra610acb42021-01-27 13:33:57 -0800232 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
233 Interval time.Duration `positional-arg-name:"INTERVAL" required:"yes"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000234 } `positional-args:"yes"`
235}
236
237type DevicePmConfigMetricEnable struct {
238 Args struct {
239 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
240 Metrics []MetricName `positional-arg-name:"METRIC_NAME" required:"yes"`
241 } `positional-args:"yes"`
242}
243
244type DevicePmConfigMetricDisable struct {
245 Args struct {
246 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
247 Metrics []MetricName `positional-arg-name:"METRIC_NAME" required:"yes"`
248 } `positional-args:"yes"`
249}
250
251type DevicePmConfigGroupEnable struct {
252 Args struct {
Girish Gowdra610acb42021-01-27 13:33:57 -0800253 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
254 Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000255 } `positional-args:"yes"`
256}
257
258type DevicePmConfigGroupDisable struct {
259 Args struct {
Girish Gowdra610acb42021-01-27 13:33:57 -0800260 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
261 Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"`
262 } `positional-args:"yes"`
263}
264
265type DevicePmConfigGroupFrequencySet struct {
266 OutputOptions
267 Args struct {
268 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
269 Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"`
270 Interval time.Duration `positional-arg-name:"INTERVAL" required:"yes"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000271 } `positional-args:"yes"`
272}
273
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -0800274type DeviceGetExtValue struct {
275 ListOutputOptions
276 Args struct {
277 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
278 Valueflag ValueFlag `positional-arg-name:"VALUE_FLAG" required:"yes"`
279 } `positional-args:"yes"`
280}
Rohan Agrawald7df3772020-06-29 11:23:36 +0000281
282type DevicePmConfigSetMaxSkew struct {
283 Args struct {
284 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
285 MaxSkew uint32 `positional-arg-name:"MAX_SKEW" required:"yes"`
286 } `positional-args:"yes"`
287}
288
Andrea Campanella791d88b2021-01-08 13:29:00 +0100289type DeviceOnuListImages struct {
290 ListOutputOptions
291 Args struct {
292 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
293 } `positional-args:"yes"`
294}
295
296type DeviceOnuDownloadImage struct {
297 Args struct {
298 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
299 Name string `positional-arg-name:"IMAGE_NAME" required:"yes"`
300 Url string `positional-arg-name:"IMAGE_URL" required:"yes"`
301 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
302 Crc uint32 `positional-arg-name:"IMAGE_CRC" required:"yes"`
303 LocalDir string `positional-arg-name:"IMAGE_LOCAL_DIRECTORY"`
304 } `positional-args:"yes"`
305}
306
307type DeviceOnuActivateImageUpdate struct {
308 Args struct {
309 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
310 Name string `positional-arg-name:"IMAGE_NAME" required:"yes"`
311 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
312 SaveConfig bool `positional-arg-name:"SAVE_EXISTING_CONFIG"`
313 LocalDir string `positional-arg-name:"IMAGE_LOCAL_DIRECTORY"`
Andrea Campanella7b2ecf42021-02-25 12:27:15 +0100314 } `positional-args:"yes"`
kesavand8ec4fc02021-01-27 09:10:22 -0500315}
kesavand3e2f9f62021-04-22 11:06:38 +0530316
317type OnuDownloadImage struct {
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +0200318 ListOutputOptions
kesavand3e2f9f62021-04-22 11:06:38 +0530319 Args struct {
320 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
321 Url string `positional-arg-name:"IMAGE_URL" required:"yes"`
ssiddiqui7bc89e92021-05-20 20:58:02 +0530322 Vendor string `positional-arg-name:"IMAGE_VENDOR"`
kesavand3e2f9f62021-04-22 11:06:38 +0530323 ActivateOnSuccess bool `positional-arg-name:"IMAGE_ACTIVATE_ON_SUCCESS"`
324 CommitOnSuccess bool `positional-arg-name:"IMAGE_COMMIT_ON_SUCCESS"`
325 Crc uint32 `positional-arg-name:"IMAGE_CRC"`
326 IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
327 } `positional-args:"yes"`
328}
329
330type OnuActivateImage struct {
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +0200331 ListOutputOptions
kesavand3e2f9f62021-04-22 11:06:38 +0530332 Args struct {
333 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
334 CommitOnSuccess bool `positional-arg-name:"IMAGE_COMMIT_ON_SUCCESS"`
335 IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
336 } `positional-args:"yes"`
337}
338
339type OnuAbortUpgradeImage struct {
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +0200340 ListOutputOptions
kesavand3e2f9f62021-04-22 11:06:38 +0530341 Args struct {
342 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
343 IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
344 } `positional-args:"yes"`
345}
346
347type OnuCommitImage struct {
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +0200348 ListOutputOptions
kesavand3e2f9f62021-04-22 11:06:38 +0530349 Args struct {
350 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
351 IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
352 } `positional-args:"yes"`
353}
354
355type OnuImageStatus struct {
356 ListOutputOptions
357 Args struct {
358 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
Elia Battiston859f3e62022-02-08 15:57:52 +0100359 IDs []DeviceId `positional-arg-name:"DEVICE_ID"`
kesavand3e2f9f62021-04-22 11:06:38 +0530360 } `positional-args:"yes"`
361}
362
363type OnuListImages struct {
364 ListOutputOptions
365 Args struct {
366 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
367 } `positional-args:"yes"`
368}
369
kesavand8ec4fc02021-01-27 09:10:22 -0500370type DeviceGetPortStats struct {
371 ListOutputOptions
372 Args struct {
373 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
374 PortNo uint32 `positional-arg-name:"PORT_NO" required:"yes"`
375 PortType string `positional-arg-name:"PORT_TYPE" required:"yes"`
Andrea Campanella791d88b2021-01-08 13:29:00 +0100376 } `positional-args:"yes"`
377}
kesavand6d1131f2021-02-05 22:38:15 +0530378type UniStatus struct {
379 ListOutputOptions
380 Args struct {
381 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
382 UniIndex uint32 `positional-arg-name:"UNI_INDEX" required:"yes"`
383 } `positional-args:"yes"`
384}
Girish Gowdra4f5ce7c2021-04-29 18:53:21 -0700385type OnuPonOpticalInfo struct {
386 ListOutputOptions
387 Args struct {
388 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
389 } `positional-args:"yes"`
390}
Himani Chawla40acc122021-05-26 18:52:29 +0530391
392type GetOnuStats struct {
393 ListOutputOptions
394 Args struct {
395 OltId DeviceId `positional-arg-name:"OLT_DEVICE_ID" required:"yes"`
396 IntfId uint32 `positional-arg-name:"PON_INTF_ID" required:"yes"`
397 OnuId uint32 `positional-arg-name:"ONU_ID" required:"yes"`
398 } `positional-args:"yes"`
399}
400
Himani Chawla553a1392021-06-10 23:39:17 +0530401type GetOnuEthernetFrameExtendedPmCounters struct {
402 ListOutputOptions
Himani Chawla806aa892021-08-30 15:51:46 +0530403 Reset bool `long:"reset" description:"Reset the counters"`
404 Args struct {
405 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
406 UniIndex *uint32 `positional-arg-name:"UNI_INDEX"`
Himani Chawla553a1392021-06-10 23:39:17 +0530407 } `positional-args:"yes"`
408}
409
Gamze Abakac857a462021-05-26 13:45:54 +0000410type RxPower struct {
411 ListOutputOptions
412 Args struct {
413 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
414 PortNo uint32 `positional-arg-name:"PORT_NO" required:"yes"`
415 OnuNo uint32 `positional-arg-name:"ONU_NO" required:"yes"`
416 } `positional-args:"yes"`
417}
418
Zack Williamse940c7a2019-08-21 14:25:39 -0700419type DeviceOpts struct {
Himani Chawla3c161c62021-05-13 16:36:51 +0530420 List DeviceList `command:"list"`
421 Create DeviceCreate `command:"create"`
422 Delete DeviceDelete `command:"delete"`
423 Enable DeviceEnable `command:"enable"`
424 Disable DeviceDisable `command:"disable"`
425 Flows DeviceFlowList `command:"flows"`
426 Groups DeviceFlowGroupList `command:"groups"`
kesavand12cd8eb2020-01-20 22:25:22 -0500427 Port struct {
428 List DevicePortList `command:"list"`
429 Enable DevicePortEnable `command:"enable"`
430 Disable DevicePortDisable `command:"disable"`
431 } `command:"port"`
432 Inspect DeviceInspect `command:"inspect"`
433 Reboot DeviceReboot `command:"reboot"`
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -0800434 Value struct {
435 Get DeviceGetExtValue `command:"get"`
436 } `command:"value"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000437 PmConfig struct {
Rohan Agrawald7df3772020-06-29 11:23:36 +0000438 Get DevicePmConfigsGet `command:"get"`
439 MaxSkew struct {
440 Set DevicePmConfigSetMaxSkew `command:"set"`
441 } `command:"maxskew"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000442 Frequency struct {
443 Set DevicePmConfigFrequencySet `command:"set"`
444 } `command:"frequency"`
445 Metric struct {
446 List DevicePmConfigMetricList `command:"list"`
447 Enable DevicePmConfigMetricEnable `command:"enable"`
448 Disable DevicePmConfigMetricDisable `command:"disable"`
449 } `command:"metric"`
450 Group struct {
Girish Gowdra610acb42021-01-27 13:33:57 -0800451 List DevicePmConfigGroupList `command:"list"`
452 Enable DevicePmConfigGroupEnable `command:"enable"`
453 Disable DevicePmConfigGroupDisable `command:"disable"`
454 Set DevicePmConfigGroupFrequencySet `command:"set"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000455 } `command:"group"`
456 GroupMetric struct {
457 List DevicePmConfigGroupMetricList `command:"list"`
458 } `command:"groupmetric"`
459 } `command:"pmconfig"`
Andrea Campanella791d88b2021-01-08 13:29:00 +0100460 Image struct {
461 Get DeviceOnuListImages `command:"list"`
462 Download DeviceOnuDownloadImage `command:"download"`
463 Activate DeviceOnuActivateImageUpdate `command:"activate"`
464 } `command:"image"`
kesavand3e2f9f62021-04-22 11:06:38 +0530465 DownloadImage struct {
466 Download OnuDownloadImage `command:"download"`
467 Activate OnuActivateImage `command:"activate"`
468 Commit OnuCommitImage `command:"commit"`
469 AbortUpgrade OnuAbortUpgradeImage `command:"abort"`
470 Status OnuImageStatus `command:"status"`
471 List OnuListImages `command:"list" `
472 } `command:"onuimage"`
kesavand8ec4fc02021-01-27 09:10:22 -0500473 GetExtVal struct {
Himani Chawla553a1392021-06-10 23:39:17 +0530474 Stats DeviceGetPortStats `command:"portstats"`
475 UniStatus UniStatus `command:"unistatus"`
476 OpticalInfo OnuPonOpticalInfo `command:"onu_pon_optical_info"`
477 OnuStats GetOnuStats `command:"onu_stats"`
478 EthernetFrameExtendedPm GetOnuEthernetFrameExtendedPmCounters `command:"ethernet_frame_extended_pm"`
479 RxPower RxPower `command:"rxpower"`
kesavand8ec4fc02021-01-27 09:10:22 -0500480 } `command:"getextval"`
Zack Williamse940c7a2019-08-21 14:25:39 -0700481}
482
483var deviceOpts = DeviceOpts{}
484
485func RegisterDeviceCommands(parser *flags.Parser) {
David Bainbridge12f036f2019-10-15 22:09:04 +0000486 if _, err := parser.AddCommand("device", "device commands", "Commands to query and manipulate VOLTHA devices", &deviceOpts); err != nil {
David Bainbridgea6722342019-10-24 23:55:53 +0000487 Error.Fatalf("Unexpected error while attempting to register device commands : %s", err)
David Bainbridge12f036f2019-10-15 22:09:04 +0000488 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700489}
490
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000491func (i *MetricName) Complete(match string) []flags.Completion {
492 conn, err := NewConnection()
493 if err != nil {
494 return nil
495 }
496 defer conn.Close()
497
498 client := voltha.NewVolthaServiceClient(conn)
499
500 var deviceId string
501found:
502 for i := len(os.Args) - 1; i >= 0; i -= 1 {
503 switch os.Args[i] {
504 case "enable":
505 fallthrough
506 case "disable":
507 if len(os.Args) > i+1 {
508 deviceId = os.Args[i+1]
509 } else {
510 return nil
511 }
512 break found
513 default:
514 }
515 }
516
517 if len(deviceId) == 0 {
518 return nil
519 }
520
David K. Bainbridge9189c632021-03-26 21:52:21 +0000521 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000522 defer cancel()
523
524 id := voltha.ID{Id: string(deviceId)}
525
526 pmconfigs, err := client.ListDevicePmConfigs(ctx, &id)
527
528 if err != nil {
529 return nil
530 }
531
532 list := make([]flags.Completion, 0)
533 for _, metrics := range pmconfigs.Metrics {
534 if strings.HasPrefix(metrics.Name, match) {
535 list = append(list, flags.Completion{Item: metrics.Name})
536 }
537 }
538
539 return list
540}
541
542func (i *GroupName) Complete(match string) []flags.Completion {
543 conn, err := NewConnection()
544 if err != nil {
545 return nil
546 }
547 defer conn.Close()
548
549 client := voltha.NewVolthaServiceClient(conn)
550
551 var deviceId string
552found:
553 for i := len(os.Args) - 1; i >= 0; i -= 1 {
554 switch os.Args[i] {
555 case "list":
556 fallthrough
557 case "enable":
558 fallthrough
559 case "disable":
560 if len(os.Args) > i+1 {
561 deviceId = os.Args[i+1]
562 } else {
563 return nil
564 }
565 break found
566 default:
567 }
568 }
569
570 if len(deviceId) == 0 {
571 return nil
572 }
573
David K. Bainbridge9189c632021-03-26 21:52:21 +0000574 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000575 defer cancel()
576
577 id := voltha.ID{Id: string(deviceId)}
578
579 pmconfigs, err := client.ListDevicePmConfigs(ctx, &id)
580
581 if err != nil {
582 return nil
583 }
584
585 list := make([]flags.Completion, 0)
586 for _, group := range pmconfigs.Groups {
587 if strings.HasPrefix(group.GroupName, match) {
588 list = append(list, flags.Completion{Item: group.GroupName})
589 }
590 }
591 return list
592}
593
kesavand12cd8eb2020-01-20 22:25:22 -0500594func (i *PortNum) Complete(match string) []flags.Completion {
595 conn, err := NewConnection()
596 if err != nil {
597 return nil
598 }
599 defer conn.Close()
600
Scott Baker9173ed82020-05-19 08:30:12 -0700601 client := voltha.NewVolthaServiceClient(conn)
kesavand12cd8eb2020-01-20 22:25:22 -0500602
603 /*
604 * The command line args when completing for PortNum will be a DeviceId
605 * followed by one or more PortNums. So walk the argument list from the
606 * end and find the first argument that is enable/disable as those are
607 * the subcommands that come before the positional arguments. It would
608 * be nice if this package gave us the list of optional arguments
609 * already parsed.
610 */
611 var deviceId string
612found:
613 for i := len(os.Args) - 1; i >= 0; i -= 1 {
614 switch os.Args[i] {
615 case "enable":
616 fallthrough
617 case "disable":
618 if len(os.Args) > i+1 {
619 deviceId = os.Args[i+1]
620 } else {
621 return nil
622 }
623 break found
624 default:
625 }
626 }
627
628 if len(deviceId) == 0 {
629 return nil
630 }
631
David K. Bainbridge9189c632021-03-26 21:52:21 +0000632 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand12cd8eb2020-01-20 22:25:22 -0500633 defer cancel()
kesavand12cd8eb2020-01-20 22:25:22 -0500634
Scott Baker9173ed82020-05-19 08:30:12 -0700635 id := voltha.ID{Id: string(deviceId)}
kesavand12cd8eb2020-01-20 22:25:22 -0500636
Scott Baker9173ed82020-05-19 08:30:12 -0700637 ports, err := client.ListDevicePorts(ctx, &id)
kesavand12cd8eb2020-01-20 22:25:22 -0500638 if err != nil {
639 return nil
640 }
641
642 list := make([]flags.Completion, 0)
Scott Baker9173ed82020-05-19 08:30:12 -0700643 for _, item := range ports.Items {
644 pn := strconv.FormatUint(uint64(item.PortNo), 10)
kesavand12cd8eb2020-01-20 22:25:22 -0500645 if strings.HasPrefix(pn, match) {
646 list = append(list, flags.Completion{Item: pn})
647 }
648 }
649
650 return list
651}
652
Zack Williamse940c7a2019-08-21 14:25:39 -0700653func (i *DeviceId) Complete(match string) []flags.Completion {
654 conn, err := NewConnection()
655 if err != nil {
656 return nil
657 }
658 defer conn.Close()
659
Scott Baker9173ed82020-05-19 08:30:12 -0700660 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700661
David K. Bainbridge9189c632021-03-26 21:52:21 +0000662 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700663 defer cancel()
664
Scott Baker9173ed82020-05-19 08:30:12 -0700665 devices, err := client.ListDevices(ctx, &empty.Empty{})
Zack Williamse940c7a2019-08-21 14:25:39 -0700666 if err != nil {
667 return nil
668 }
669
670 list := make([]flags.Completion, 0)
Scott Baker9173ed82020-05-19 08:30:12 -0700671 for _, item := range devices.Items {
672 if strings.HasPrefix(item.Id, match) {
673 list = append(list, flags.Completion{Item: item.Id})
Zack Williamse940c7a2019-08-21 14:25:39 -0700674 }
675 }
676
677 return list
678}
679
680func (options *DeviceList) Execute(args []string) error {
681
682 conn, err := NewConnection()
683 if err != nil {
684 return err
685 }
686 defer conn.Close()
687
Scott Baker9173ed82020-05-19 08:30:12 -0700688 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700689
David K. Bainbridge9189c632021-03-26 21:52:21 +0000690 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700691 defer cancel()
692
Scott Baker9173ed82020-05-19 08:30:12 -0700693 devices, err := client.ListDevices(ctx, &empty.Empty{})
Zack Williamse940c7a2019-08-21 14:25:39 -0700694 if err != nil {
695 return err
696 }
697
698 outputFormat := CharReplacer.Replace(options.Format)
699 if outputFormat == "" {
David Bainbridgea6722342019-10-24 23:55:53 +0000700 outputFormat = GetCommandOptionWithDefault("device-list", "format", DEFAULT_DEVICE_FORMAT)
Zack Williamse940c7a2019-08-21 14:25:39 -0700701 }
702 if options.Quiet {
703 outputFormat = "{{.Id}}"
704 }
705
David Bainbridgea6722342019-10-24 23:55:53 +0000706 orderBy := options.OrderBy
707 if orderBy == "" {
Hardik Windlass9361bb82022-03-23 05:58:48 +0000708 orderBy = GetCommandOptionWithDefault("device-list", "order", DEFAULT_DEVICE_ORDER)
David Bainbridgea6722342019-10-24 23:55:53 +0000709 }
710
Scott Baker9173ed82020-05-19 08:30:12 -0700711 // Make sure json output prints an empty list, not "null"
712 if devices.Items == nil {
713 devices.Items = make([]*voltha.Device, 0)
Zack Williamse940c7a2019-08-21 14:25:39 -0700714 }
715
716 result := CommandResult{
717 Format: format.Format(outputFormat),
718 Filter: options.Filter,
David Bainbridgea6722342019-10-24 23:55:53 +0000719 OrderBy: orderBy,
Zack Williamse940c7a2019-08-21 14:25:39 -0700720 OutputAs: toOutputType(options.OutputAs),
721 NameLimit: options.NameLimit,
Scott Baker9173ed82020-05-19 08:30:12 -0700722 Data: devices.Items,
Zack Williamse940c7a2019-08-21 14:25:39 -0700723 }
724
725 GenerateOutput(&result)
726 return nil
727}
728
729func (options *DeviceCreate) Execute(args []string) error {
730
Scott Baker9173ed82020-05-19 08:30:12 -0700731 device := voltha.Device{}
Zack Williamse940c7a2019-08-21 14:25:39 -0700732 if options.HostAndPort != "" {
Scott Baker9173ed82020-05-19 08:30:12 -0700733 device.Address = &voltha.Device_HostAndPort{HostAndPort: options.HostAndPort}
Zack Williamse940c7a2019-08-21 14:25:39 -0700734 } else if options.IPAddress != "" {
Scott Baker9173ed82020-05-19 08:30:12 -0700735 device.Address = &voltha.Device_Ipv4Address{Ipv4Address: options.IPAddress}
Hardik Windlassce1de342020-02-04 21:58:07 +0000736 }
737 if options.MACAddress != "" {
Scott Baker9173ed82020-05-19 08:30:12 -0700738 device.MacAddress = strings.ToLower(options.MACAddress)
Zack Williamse940c7a2019-08-21 14:25:39 -0700739 }
740 if options.DeviceType != "" {
Scott Baker9173ed82020-05-19 08:30:12 -0700741 device.Type = options.DeviceType
Zack Williamse940c7a2019-08-21 14:25:39 -0700742 }
743
744 conn, err := NewConnection()
745 if err != nil {
746 return err
747 }
748 defer conn.Close()
749
Scott Baker9173ed82020-05-19 08:30:12 -0700750 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700751
David K. Bainbridge9189c632021-03-26 21:52:21 +0000752 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700753 defer cancel()
754
Scott Baker9173ed82020-05-19 08:30:12 -0700755 createdDevice, err := client.CreateDevice(ctx, &device)
Zack Williamse940c7a2019-08-21 14:25:39 -0700756 if err != nil {
757 return err
Zack Williamse940c7a2019-08-21 14:25:39 -0700758 }
759
Scott Baker9173ed82020-05-19 08:30:12 -0700760 fmt.Printf("%s\n", createdDevice.Id)
Zack Williamse940c7a2019-08-21 14:25:39 -0700761
762 return nil
763}
764
765func (options *DeviceDelete) Execute(args []string) error {
766
767 conn, err := NewConnection()
768 if err != nil {
769 return err
770 }
771 defer conn.Close()
772
Scott Baker9173ed82020-05-19 08:30:12 -0700773 client := voltha.NewVolthaServiceClient(conn)
David Bainbridge7052fe82020-03-25 10:37:00 -0700774 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -0700775 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +0000776 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700777 defer cancel()
778
Scott Baker9173ed82020-05-19 08:30:12 -0700779 id := voltha.ID{Id: string(i)}
Himani Chawla9933ddc2020-10-12 23:53:27 +0530780 if options.Force {
781 _, err = client.ForceDeleteDevice(ctx, &id)
782 } else {
783 _, err = client.DeleteDevice(ctx, &id)
784 }
Scott Baker9173ed82020-05-19 08:30:12 -0700785
Zack Williamse940c7a2019-08-21 14:25:39 -0700786 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +0000787 Error.Printf("Error while deleting '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -0700788 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -0700789 continue
Zack Williamse940c7a2019-08-21 14:25:39 -0700790 }
791 fmt.Printf("%s\n", i)
792 }
793
David Bainbridge7052fe82020-03-25 10:37:00 -0700794 if lastErr != nil {
795 return NoReportErr
796 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700797 return nil
798}
799
800func (options *DeviceEnable) Execute(args []string) error {
801 conn, err := NewConnection()
802 if err != nil {
803 return err
804 }
805 defer conn.Close()
806
Scott Baker9173ed82020-05-19 08:30:12 -0700807 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700808
David Bainbridge7052fe82020-03-25 10:37:00 -0700809 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -0700810 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +0000811 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700812 defer cancel()
813
Scott Baker9173ed82020-05-19 08:30:12 -0700814 id := voltha.ID{Id: string(i)}
815
816 _, err := client.EnableDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -0700817 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +0000818 Error.Printf("Error while enabling '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -0700819 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -0700820 continue
Zack Williamse940c7a2019-08-21 14:25:39 -0700821 }
822 fmt.Printf("%s\n", i)
823 }
824
David Bainbridge7052fe82020-03-25 10:37:00 -0700825 if lastErr != nil {
826 return NoReportErr
827 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700828 return nil
829}
830
831func (options *DeviceDisable) Execute(args []string) error {
832 conn, err := NewConnection()
833 if err != nil {
834 return err
835 }
836 defer conn.Close()
837
Scott Baker9173ed82020-05-19 08:30:12 -0700838 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700839
David Bainbridge7052fe82020-03-25 10:37:00 -0700840 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -0700841 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +0000842 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700843 defer cancel()
844
Scott Baker9173ed82020-05-19 08:30:12 -0700845 id := voltha.ID{Id: string(i)}
846
847 _, err := client.DisableDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -0700848 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +0000849 Error.Printf("Error while disabling '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -0700850 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -0700851 continue
Zack Williamse940c7a2019-08-21 14:25:39 -0700852 }
853 fmt.Printf("%s\n", i)
854 }
855
David Bainbridge7052fe82020-03-25 10:37:00 -0700856 if lastErr != nil {
857 return NoReportErr
858 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700859 return nil
860}
861
862func (options *DeviceReboot) Execute(args []string) error {
863 conn, err := NewConnection()
864 if err != nil {
865 return err
866 }
867 defer conn.Close()
868
Scott Baker9173ed82020-05-19 08:30:12 -0700869 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700870
David Bainbridge7052fe82020-03-25 10:37:00 -0700871 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -0700872 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +0000873 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700874 defer cancel()
875
Scott Baker9173ed82020-05-19 08:30:12 -0700876 id := voltha.ID{Id: string(i)}
877
878 _, err := client.RebootDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -0700879 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +0000880 Error.Printf("Error while rebooting '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -0700881 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -0700882 continue
Zack Williamse940c7a2019-08-21 14:25:39 -0700883 }
884 fmt.Printf("%s\n", i)
885 }
886
David Bainbridge7052fe82020-03-25 10:37:00 -0700887 if lastErr != nil {
888 return NoReportErr
889 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700890 return nil
891}
892
893func (options *DevicePortList) Execute(args []string) error {
894
895 conn, err := NewConnection()
896 if err != nil {
897 return err
898 }
899 defer conn.Close()
900
Scott Baker9173ed82020-05-19 08:30:12 -0700901 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700902
David K. Bainbridge9189c632021-03-26 21:52:21 +0000903 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700904 defer cancel()
905
Scott Baker9173ed82020-05-19 08:30:12 -0700906 id := voltha.ID{Id: string(options.Args.Id)}
Zack Williamse940c7a2019-08-21 14:25:39 -0700907
Scott Baker9173ed82020-05-19 08:30:12 -0700908 ports, err := client.ListDevicePorts(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -0700909 if err != nil {
910 return err
911 }
912
913 outputFormat := CharReplacer.Replace(options.Format)
914 if outputFormat == "" {
David Bainbridgea6722342019-10-24 23:55:53 +0000915 outputFormat = GetCommandOptionWithDefault("device-ports", "format", DEFAULT_DEVICE_PORTS_FORMAT)
Zack Williamse940c7a2019-08-21 14:25:39 -0700916 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700917
David Bainbridgea6722342019-10-24 23:55:53 +0000918 orderBy := options.OrderBy
919 if orderBy == "" {
920 orderBy = GetCommandOptionWithDefault("device-ports", "order", "")
921 }
922
Zack Williamse940c7a2019-08-21 14:25:39 -0700923 result := CommandResult{
924 Format: format.Format(outputFormat),
925 Filter: options.Filter,
David Bainbridgea6722342019-10-24 23:55:53 +0000926 OrderBy: orderBy,
Zack Williamse940c7a2019-08-21 14:25:39 -0700927 OutputAs: toOutputType(options.OutputAs),
928 NameLimit: options.NameLimit,
Scott Baker9173ed82020-05-19 08:30:12 -0700929 Data: ports.Items,
Zack Williamse940c7a2019-08-21 14:25:39 -0700930 }
931
932 GenerateOutput(&result)
933 return nil
934}
935
936func (options *DeviceFlowList) Execute(args []string) error {
937 fl := &FlowList{}
938 fl.ListOutputOptions = options.ListOutputOptions
Maninder045921e2020-09-29 16:46:02 +0530939 fl.FlowIdOptions = options.FlowIdOptions
Zack Williamse940c7a2019-08-21 14:25:39 -0700940 fl.Args.Id = string(options.Args.Id)
David Bainbridgea6722342019-10-24 23:55:53 +0000941 fl.Method = "device-flows"
Zack Williamse940c7a2019-08-21 14:25:39 -0700942 return fl.Execute(args)
943}
944
Himani Chawla3c161c62021-05-13 16:36:51 +0530945func (options *DeviceFlowGroupList) Execute(args []string) error {
946 grp := &GroupList{}
947 grp.ListOutputOptions = options.ListOutputOptions
948 grp.GroupListOptions = options.GroupListOptions
949 grp.Args.Id = string(options.Args.Id)
950 grp.Method = "device-groups"
951 return grp.Execute(args)
952}
953
Zack Williamse940c7a2019-08-21 14:25:39 -0700954func (options *DeviceInspect) Execute(args []string) error {
955 if len(args) > 0 {
956 return fmt.Errorf("only a single argument 'DEVICE_ID' can be provided")
957 }
958
959 conn, err := NewConnection()
960 if err != nil {
961 return err
962 }
963 defer conn.Close()
964
Scott Baker9173ed82020-05-19 08:30:12 -0700965 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700966
David K. Bainbridge9189c632021-03-26 21:52:21 +0000967 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700968 defer cancel()
969
Scott Baker9173ed82020-05-19 08:30:12 -0700970 id := voltha.ID{Id: string(options.Args.Id)}
Zack Williamse940c7a2019-08-21 14:25:39 -0700971
Scott Baker9173ed82020-05-19 08:30:12 -0700972 device, err := client.GetDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -0700973 if err != nil {
974 return err
975 }
976
Zack Williamse940c7a2019-08-21 14:25:39 -0700977 outputFormat := CharReplacer.Replace(options.Format)
978 if outputFormat == "" {
David Bainbridgea6722342019-10-24 23:55:53 +0000979 outputFormat = GetCommandOptionWithDefault("device-inspect", "format", DEFAULT_DEVICE_INSPECT_FORMAT)
Zack Williamse940c7a2019-08-21 14:25:39 -0700980 }
981 if options.Quiet {
982 outputFormat = "{{.Id}}"
983 }
984
985 result := CommandResult{
986 Format: format.Format(outputFormat),
987 OutputAs: toOutputType(options.OutputAs),
988 NameLimit: options.NameLimit,
989 Data: device,
990 }
991 GenerateOutput(&result)
992 return nil
993}
kesavand12cd8eb2020-01-20 22:25:22 -0500994
995/*Device Port Enable */
996func (options *DevicePortEnable) Execute(args []string) error {
997 conn, err := NewConnection()
998 if err != nil {
999 return err
1000 }
1001 defer conn.Close()
1002
Scott Baker9173ed82020-05-19 08:30:12 -07001003 client := voltha.NewVolthaServiceClient(conn)
kesavand12cd8eb2020-01-20 22:25:22 -05001004
David K. Bainbridge9189c632021-03-26 21:52:21 +00001005 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand12cd8eb2020-01-20 22:25:22 -05001006 defer cancel()
1007
Scott Baker9173ed82020-05-19 08:30:12 -07001008 port := voltha.Port{DeviceId: string(options.Args.Id), PortNo: uint32(options.Args.PortId)}
1009
1010 _, err = client.EnablePort(ctx, &port)
kesavand12cd8eb2020-01-20 22:25:22 -05001011 if err != nil {
1012 Error.Printf("Error enabling port number %v on device Id %s,err=%s\n", options.Args.PortId, options.Args.Id, ErrorToString(err))
1013 return err
kesavand12cd8eb2020-01-20 22:25:22 -05001014 }
1015
1016 return nil
1017}
1018
Scott Baker9173ed82020-05-19 08:30:12 -07001019/*Device Port Disable */
kesavand12cd8eb2020-01-20 22:25:22 -05001020func (options *DevicePortDisable) Execute(args []string) error {
1021 conn, err := NewConnection()
1022 if err != nil {
1023 return err
1024 }
1025 defer conn.Close()
1026
Scott Baker9173ed82020-05-19 08:30:12 -07001027 client := voltha.NewVolthaServiceClient(conn)
1028
David K. Bainbridge9189c632021-03-26 21:52:21 +00001029 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand12cd8eb2020-01-20 22:25:22 -05001030 defer cancel()
1031
Scott Baker9173ed82020-05-19 08:30:12 -07001032 port := voltha.Port{DeviceId: string(options.Args.Id), PortNo: uint32(options.Args.PortId)}
1033
1034 _, err = client.DisablePort(ctx, &port)
kesavand12cd8eb2020-01-20 22:25:22 -05001035 if err != nil {
Scott Baker9173ed82020-05-19 08:30:12 -07001036 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 -05001037 return err
kesavand12cd8eb2020-01-20 22:25:22 -05001038 }
Scott Baker9173ed82020-05-19 08:30:12 -07001039
kesavand12cd8eb2020-01-20 22:25:22 -05001040 return nil
1041}
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08001042
Rohan Agrawald7df3772020-06-29 11:23:36 +00001043func (options *DevicePmConfigSetMaxSkew) Execute(args []string) error {
1044 conn, err := NewConnection()
1045 if err != nil {
1046 return err
1047 }
1048 defer conn.Close()
1049
1050 client := voltha.NewVolthaServiceClient(conn)
1051
David K. Bainbridge9189c632021-03-26 21:52:21 +00001052 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawald7df3772020-06-29 11:23:36 +00001053 defer cancel()
1054
1055 id := voltha.ID{Id: string(options.Args.Id)}
1056
1057 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1058 if err != nil {
1059 return err
1060 }
1061
1062 pmConfigs.MaxSkew = options.Args.MaxSkew
1063
1064 _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs)
1065 if err != nil {
1066 return err
1067 }
1068
1069 return nil
1070}
1071
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001072func (options *DevicePmConfigsGet) Execute(args []string) error {
1073
1074 conn, err := NewConnection()
1075 if err != nil {
1076 return err
1077 }
1078 defer conn.Close()
1079
1080 client := voltha.NewVolthaServiceClient(conn)
1081
David K. Bainbridge9189c632021-03-26 21:52:21 +00001082 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001083 defer cancel()
1084
1085 id := voltha.ID{Id: string(options.Args.Id)}
1086
1087 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1088 if err != nil {
1089 return err
1090 }
1091
1092 outputFormat := CharReplacer.Replace(options.Format)
1093 if outputFormat == "" {
1094 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GET_FORMAT)
1095 }
1096
1097 orderBy := options.OrderBy
1098 if orderBy == "" {
1099 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1100 }
1101
1102 result := CommandResult{
1103 Format: format.Format(outputFormat),
1104 Filter: options.Filter,
1105 OrderBy: orderBy,
1106 OutputAs: toOutputType(options.OutputAs),
1107 NameLimit: options.NameLimit,
1108 Data: pmConfigs,
1109 }
1110
1111 GenerateOutput(&result)
1112 return nil
1113
1114}
1115
1116func (options *DevicePmConfigMetricList) Execute(args []string) error {
1117
1118 conn, err := NewConnection()
1119 if err != nil {
1120 return err
1121 }
1122 defer conn.Close()
1123
1124 client := voltha.NewVolthaServiceClient(conn)
1125
David K. Bainbridge9189c632021-03-26 21:52:21 +00001126 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001127 defer cancel()
1128
1129 id := voltha.ID{Id: string(options.Args.Id)}
1130
1131 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1132 if err != nil {
1133 return err
1134 }
1135
1136 if !pmConfigs.Grouped {
1137 for _, metric := range pmConfigs.Metrics {
1138 if metric.SampleFreq == 0 {
1139 metric.SampleFreq = pmConfigs.DefaultFreq
1140 }
1141 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001142 outputFormat := CharReplacer.Replace(options.Format)
1143 if outputFormat == "" {
1144 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_METRIC_LIST_FORMAT)
1145 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001146
Rohan Agrawalbca69122020-06-17 14:59:03 +00001147 orderBy := options.OrderBy
1148 if orderBy == "" {
1149 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1150 }
1151
1152 result := CommandResult{
1153 Format: format.Format(outputFormat),
1154 Filter: options.Filter,
1155 OrderBy: orderBy,
1156 OutputAs: toOutputType(options.OutputAs),
1157 NameLimit: options.NameLimit,
1158 Data: pmConfigs.Metrics,
1159 }
1160
1161 GenerateOutput(&result)
1162 return nil
1163 } else {
1164 return fmt.Errorf("Device '%s' does not have Non Grouped Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001165 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001166}
1167
1168func (options *DevicePmConfigMetricEnable) Execute(args []string) error {
1169
1170 conn, err := NewConnection()
1171 if err != nil {
1172 return err
1173 }
1174 defer conn.Close()
1175
1176 client := voltha.NewVolthaServiceClient(conn)
1177
David K. Bainbridge9189c632021-03-26 21:52:21 +00001178 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001179 defer cancel()
1180
1181 id := voltha.ID{Id: string(options.Args.Id)}
1182
1183 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1184 if err != nil {
1185 return err
1186 }
1187
1188 if !pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001189 metrics := make(map[string]struct{})
1190 for _, metric := range pmConfigs.Metrics {
1191 metrics[metric.Name] = struct{}{}
1192 }
1193
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001194 for _, metric := range pmConfigs.Metrics {
1195 for _, mName := range options.Args.Metrics {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001196 if _, exist := metrics[string(mName)]; !exist {
1197 return fmt.Errorf("Metric Name '%s' does not exist", mName)
1198 }
1199
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001200 if string(mName) == metric.Name && !metric.Enabled {
1201 metric.Enabled = true
1202 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1203 if err != nil {
1204 return err
1205 }
1206 }
1207 }
1208 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001209 } else {
1210 return fmt.Errorf("Device '%s' does not have Non Grouped Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001211 }
1212 return nil
1213}
1214
1215func (options *DevicePmConfigMetricDisable) Execute(args []string) error {
1216
1217 conn, err := NewConnection()
1218 if err != nil {
1219 return err
1220 }
1221 defer conn.Close()
1222
1223 client := voltha.NewVolthaServiceClient(conn)
1224
David K. Bainbridge9189c632021-03-26 21:52:21 +00001225 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001226 defer cancel()
1227
1228 id := voltha.ID{Id: string(options.Args.Id)}
1229
1230 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1231 if err != nil {
1232 return err
1233 }
1234
1235 if !pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001236 metrics := make(map[string]struct{})
1237 for _, metric := range pmConfigs.Metrics {
1238 metrics[metric.Name] = struct{}{}
1239 }
1240
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001241 for _, metric := range pmConfigs.Metrics {
1242 for _, mName := range options.Args.Metrics {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001243 if _, have := metrics[string(mName)]; !have {
1244 return fmt.Errorf("Metric Name '%s' does not exist", mName)
1245 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001246 if string(mName) == metric.Name && metric.Enabled {
1247 metric.Enabled = false
1248 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1249 if err != nil {
1250 return err
1251 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001252 } else {
1253 return fmt.Errorf("Metric '%s' cannot be disabled", string(mName))
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001254 }
1255 }
1256 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001257 } else {
1258 return fmt.Errorf("Device '%s' does not have Non Grouped Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001259 }
1260 return nil
1261}
1262
1263func (options *DevicePmConfigGroupEnable) Execute(args []string) error {
1264
1265 conn, err := NewConnection()
1266 if err != nil {
1267 return err
1268 }
1269 defer conn.Close()
1270
1271 client := voltha.NewVolthaServiceClient(conn)
1272
David K. Bainbridge9189c632021-03-26 21:52:21 +00001273 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001274 defer cancel()
1275
1276 id := voltha.ID{Id: string(options.Args.Id)}
1277
1278 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1279 if err != nil {
1280 return err
1281 }
1282
1283 if pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001284 groups := make(map[string]struct{})
1285 for _, group := range pmConfigs.Groups {
1286 groups[group.GroupName] = struct{}{}
1287 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001288 for _, group := range pmConfigs.Groups {
Girish Gowdra610acb42021-01-27 13:33:57 -08001289 if _, have := groups[string(options.Args.Group)]; !have {
1290 return fmt.Errorf("Group Name '%s' does not exist", options.Args.Group)
1291 }
1292 if string(options.Args.Group) == group.GroupName && !group.Enabled {
1293 group.Enabled = true
1294 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1295 if err != nil {
1296 return err
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001297 }
1298 }
1299 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001300 } else {
1301 return fmt.Errorf("Device '%s' does not have Group Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001302 }
1303 return nil
1304}
1305
1306func (options *DevicePmConfigGroupDisable) Execute(args []string) error {
1307
1308 conn, err := NewConnection()
1309 if err != nil {
1310 return err
1311 }
1312 defer conn.Close()
1313
1314 client := voltha.NewVolthaServiceClient(conn)
1315
David K. Bainbridge9189c632021-03-26 21:52:21 +00001316 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001317 defer cancel()
1318
1319 id := voltha.ID{Id: string(options.Args.Id)}
1320
1321 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1322 if err != nil {
1323 return err
1324 }
1325
1326 if pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001327 groups := make(map[string]struct{})
1328 for _, group := range pmConfigs.Groups {
1329 groups[group.GroupName] = struct{}{}
1330 }
1331
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001332 for _, group := range pmConfigs.Groups {
Girish Gowdra610acb42021-01-27 13:33:57 -08001333 if _, have := groups[string(options.Args.Group)]; !have {
1334 return fmt.Errorf("Group Name '%s' does not exist", options.Args.Group)
1335 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001336
Girish Gowdra610acb42021-01-27 13:33:57 -08001337 if string(options.Args.Group) == group.GroupName && group.Enabled {
1338 group.Enabled = false
1339 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1340 if err != nil {
1341 return err
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001342 }
1343 }
1344 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001345 } else {
1346 return fmt.Errorf("Device '%s' does not have Group Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001347 }
1348 return nil
1349}
1350
Girish Gowdra610acb42021-01-27 13:33:57 -08001351func (options *DevicePmConfigGroupFrequencySet) Execute(args []string) error {
1352
1353 conn, err := NewConnection()
1354 if err != nil {
1355 return err
1356 }
1357 defer conn.Close()
1358
1359 client := voltha.NewVolthaServiceClient(conn)
1360
David K. Bainbridge9189c632021-03-26 21:52:21 +00001361 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Girish Gowdra610acb42021-01-27 13:33:57 -08001362 defer cancel()
1363
1364 id := voltha.ID{Id: string(options.Args.Id)}
1365
1366 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1367 if err != nil {
1368 return err
1369 }
1370
1371 if pmConfigs.Grouped {
1372 groups := make(map[string]struct{})
1373 for _, group := range pmConfigs.Groups {
1374 groups[group.GroupName] = struct{}{}
1375 }
1376
1377 for _, group := range pmConfigs.Groups {
1378 if _, have := groups[string(options.Args.Group)]; !have {
1379 return fmt.Errorf("group name '%s' does not exist", options.Args.Group)
1380 }
1381
1382 if string(options.Args.Group) == group.GroupName {
1383 if !group.Enabled {
1384 return fmt.Errorf("group '%s' is not enabled", options.Args.Group)
1385 }
1386 group.GroupFreq = uint32(options.Args.Interval.Seconds())
1387 _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs)
1388 if err != nil {
1389 return err
1390 }
1391 }
1392 }
1393 } else {
1394 return fmt.Errorf("device '%s' does not have group metrics", options.Args.Id)
1395 }
1396 return nil
1397}
1398
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001399func (options *DevicePmConfigGroupList) Execute(args []string) error {
1400
1401 conn, err := NewConnection()
1402 if err != nil {
1403 return err
1404 }
1405 defer conn.Close()
1406
1407 client := voltha.NewVolthaServiceClient(conn)
1408
David K. Bainbridge9189c632021-03-26 21:52:21 +00001409 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001410 defer cancel()
1411
1412 id := voltha.ID{Id: string(options.Args.Id)}
1413
1414 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1415 if err != nil {
1416 return err
1417 }
1418
1419 if pmConfigs.Grouped {
1420 for _, group := range pmConfigs.Groups {
1421 if group.GroupFreq == 0 {
1422 group.GroupFreq = pmConfigs.DefaultFreq
1423 }
1424 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001425 outputFormat := CharReplacer.Replace(options.Format)
1426 if outputFormat == "" {
1427 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GROUP_LIST_FORMAT)
1428 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001429
Rohan Agrawalbca69122020-06-17 14:59:03 +00001430 orderBy := options.OrderBy
1431 if orderBy == "" {
1432 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1433 }
1434
1435 result := CommandResult{
1436 Format: format.Format(outputFormat),
1437 Filter: options.Filter,
1438 OrderBy: orderBy,
1439 OutputAs: toOutputType(options.OutputAs),
1440 NameLimit: options.NameLimit,
1441 Data: pmConfigs.Groups,
1442 }
1443
1444 GenerateOutput(&result)
1445 } else {
1446 return fmt.Errorf("Device '%s' does not have Group Metrics", string(options.Args.Id))
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001447 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001448 return nil
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001449}
1450
1451func (options *DevicePmConfigGroupMetricList) Execute(args []string) error {
1452
1453 var metrics []*voltha.PmConfig
1454 conn, err := NewConnection()
1455 if err != nil {
1456 return err
1457 }
1458 defer conn.Close()
1459
1460 client := voltha.NewVolthaServiceClient(conn)
1461
David K. Bainbridge9189c632021-03-26 21:52:21 +00001462 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001463 defer cancel()
1464
1465 id := voltha.ID{Id: string(options.Args.Id)}
1466
1467 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1468 if err != nil {
1469 return err
1470 }
1471
1472 for _, groups := range pmConfigs.Groups {
1473
1474 if string(options.Args.Group) == groups.GroupName {
1475 for _, metric := range groups.Metrics {
1476 if metric.SampleFreq == 0 && groups.GroupFreq == 0 {
1477 metric.SampleFreq = pmConfigs.DefaultFreq
1478 } else {
1479 metric.SampleFreq = groups.GroupFreq
1480 }
1481 }
1482 metrics = groups.Metrics
1483 }
1484 }
1485
1486 outputFormat := CharReplacer.Replace(options.Format)
1487 if outputFormat == "" {
1488 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_METRIC_LIST_FORMAT)
1489 }
1490
1491 orderBy := options.OrderBy
1492 if orderBy == "" {
1493 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1494 }
1495
1496 result := CommandResult{
1497 Format: format.Format(outputFormat),
1498 Filter: options.Filter,
1499 OrderBy: orderBy,
1500 OutputAs: toOutputType(options.OutputAs),
1501 NameLimit: options.NameLimit,
1502 Data: metrics,
1503 }
1504
1505 GenerateOutput(&result)
1506 return nil
1507
1508}
1509
1510func (options *DevicePmConfigFrequencySet) Execute(args []string) error {
1511
1512 conn, err := NewConnection()
1513 if err != nil {
1514 return err
1515 }
1516 defer conn.Close()
1517
1518 client := voltha.NewVolthaServiceClient(conn)
1519
David K. Bainbridge9189c632021-03-26 21:52:21 +00001520 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001521 defer cancel()
1522
1523 id := voltha.ID{Id: string(options.Args.Id)}
1524
1525 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1526 if err != nil {
1527 return err
1528 }
1529
Girish Gowdra610acb42021-01-27 13:33:57 -08001530 pmConfigs.DefaultFreq = uint32(options.Args.Interval.Seconds())
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001531
1532 _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs)
1533 if err != nil {
1534 return err
1535 }
1536
1537 outputFormat := CharReplacer.Replace(options.Format)
1538 if outputFormat == "" {
1539 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GET_FORMAT)
1540 }
1541 if options.Quiet {
1542 outputFormat = "{{.Id}}"
1543 }
1544
1545 result := CommandResult{
1546 Format: format.Format(outputFormat),
1547 OutputAs: toOutputType(options.OutputAs),
1548 NameLimit: options.NameLimit,
1549 Data: pmConfigs,
1550 }
1551
1552 GenerateOutput(&result)
1553 return nil
1554
1555}
1556
kesavand3e2f9f62021-04-22 11:06:38 +05301557func (options *OnuDownloadImage) Execute(args []string) error {
1558
1559 conn, err := NewConnection()
1560 if err != nil {
1561 return err
1562 }
1563 defer conn.Close()
1564
1565 client := voltha.NewVolthaServiceClient(conn)
1566
1567 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1568 defer cancel()
1569
1570 var devIDList []*common.ID
1571 for _, i := range options.Args.IDs {
1572
1573 devIDList = append(devIDList, &common.ID{Id: string(i)})
1574 }
1575
1576 downloadImage := voltha.DeviceImageDownloadRequest{
1577 DeviceId: devIDList,
1578 Image: &voltha.Image{
1579 Url: options.Args.Url,
1580 Crc32: options.Args.Crc,
ssiddiqui7bc89e92021-05-20 20:58:02 +05301581 Vendor: options.Args.Vendor,
kesavand3e2f9f62021-04-22 11:06:38 +05301582 Version: options.Args.ImageVersion,
1583 },
1584 ActivateOnSuccess: options.Args.ActivateOnSuccess,
1585 CommitOnSuccess: options.Args.CommitOnSuccess,
1586 }
1587
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001588 deviceImageResp, err := client.DownloadImageToDevice(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301589 if err != nil {
1590 return err
1591 }
1592
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001593 outputFormat := GetCommandOptionWithDefault("onu-image-download", "format", ONU_IMAGE_STATUS_FORMAT)
1594 // Make sure json output prints an empty list, not "null"
1595 if deviceImageResp.DeviceImageStates == nil {
1596 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1597 }
1598 result := CommandResult{
1599 Format: format.Format(outputFormat),
1600 OutputAs: toOutputType(options.OutputAs),
1601 NameLimit: options.NameLimit,
1602 Data: deviceImageResp.DeviceImageStates,
1603 }
1604 GenerateOutput(&result)
kesavand3e2f9f62021-04-22 11:06:38 +05301605 return nil
1606
1607}
1608
1609func (options *OnuActivateImage) Execute(args []string) error {
1610
1611 conn, err := NewConnection()
1612 if err != nil {
1613 return err
1614 }
1615 defer conn.Close()
1616
1617 client := voltha.NewVolthaServiceClient(conn)
1618
1619 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1620 defer cancel()
1621
1622 var devIDList []*common.ID
1623 for _, i := range options.Args.IDs {
1624
1625 devIDList = append(devIDList, &common.ID{Id: string(i)})
1626 }
1627
1628 downloadImage := voltha.DeviceImageRequest{
1629 DeviceId: devIDList,
1630 Version: options.Args.ImageVersion,
1631 CommitOnSuccess: options.Args.CommitOnSuccess,
1632 }
1633
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001634 deviceImageResp, err := client.ActivateImage(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301635 if err != nil {
1636 return err
1637 }
1638
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001639 outputFormat := GetCommandOptionWithDefault("onu-image-activate", "format", ONU_IMAGE_STATUS_FORMAT)
1640 // Make sure json output prints an empty list, not "null"
1641 if deviceImageResp.DeviceImageStates == nil {
1642 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1643 }
1644 result := CommandResult{
1645 Format: format.Format(outputFormat),
1646 OutputAs: toOutputType(options.OutputAs),
1647 NameLimit: options.NameLimit,
1648 Data: deviceImageResp.DeviceImageStates,
1649 }
1650 GenerateOutput(&result)
1651
kesavand3e2f9f62021-04-22 11:06:38 +05301652 return nil
1653
1654}
1655
1656func (options *OnuAbortUpgradeImage) Execute(args []string) error {
1657
1658 conn, err := NewConnection()
1659 if err != nil {
1660 return err
1661 }
1662 defer conn.Close()
1663
1664 client := voltha.NewVolthaServiceClient(conn)
1665
1666 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1667 defer cancel()
1668
1669 var devIDList []*common.ID
1670 for _, i := range options.Args.IDs {
1671
1672 devIDList = append(devIDList, &common.ID{Id: string(i)})
1673 }
1674
1675 downloadImage := voltha.DeviceImageRequest{
1676 DeviceId: devIDList,
1677 Version: options.Args.ImageVersion,
1678 }
1679
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001680 deviceImageResp, err := client.AbortImageUpgradeToDevice(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301681 if err != nil {
1682 return err
1683 }
1684
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001685 outputFormat := GetCommandOptionWithDefault("onu-image-abort", "format", ONU_IMAGE_STATUS_FORMAT)
1686 // Make sure json output prints an empty list, not "null"
1687 if deviceImageResp.DeviceImageStates == nil {
1688 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1689 }
1690 result := CommandResult{
1691 Format: format.Format(outputFormat),
1692 OutputAs: toOutputType(options.OutputAs),
1693 NameLimit: options.NameLimit,
1694 Data: deviceImageResp.DeviceImageStates,
1695 }
1696 GenerateOutput(&result)
1697
kesavand3e2f9f62021-04-22 11:06:38 +05301698 return nil
1699
1700}
1701
1702func (options *OnuCommitImage) Execute(args []string) error {
1703
1704 conn, err := NewConnection()
1705 if err != nil {
1706 return err
1707 }
1708 defer conn.Close()
1709
1710 client := voltha.NewVolthaServiceClient(conn)
1711
1712 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1713 defer cancel()
1714
1715 var devIDList []*common.ID
1716 for _, i := range options.Args.IDs {
1717
1718 devIDList = append(devIDList, &common.ID{Id: string(i)})
1719 }
1720 downloadImage := voltha.DeviceImageRequest{
1721 DeviceId: devIDList,
1722 Version: options.Args.ImageVersion,
1723 }
1724
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001725 deviceImageResp, err := client.CommitImage(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301726 if err != nil {
1727 return err
1728 }
1729
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001730 outputFormat := GetCommandOptionWithDefault("onu-image-commit", "format", ONU_IMAGE_STATUS_FORMAT)
1731 // Make sure json output prints an empty list, not "null"
1732 if deviceImageResp.DeviceImageStates == nil {
1733 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1734 }
1735 result := CommandResult{
1736 Format: format.Format(outputFormat),
1737 OutputAs: toOutputType(options.OutputAs),
1738 NameLimit: options.NameLimit,
1739 Data: deviceImageResp.DeviceImageStates,
1740 }
1741 GenerateOutput(&result)
1742
kesavand3e2f9f62021-04-22 11:06:38 +05301743 return nil
1744
1745}
1746
1747func (options *OnuListImages) Execute(args []string) error {
1748
1749 conn, err := NewConnection()
1750 if err != nil {
1751 return err
1752 }
1753 defer conn.Close()
1754
1755 client := voltha.NewVolthaServiceClient(conn)
1756
1757 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1758 defer cancel()
1759
1760 id := common.ID{Id: string(options.Args.Id)}
1761
1762 onuImages, err := client.GetOnuImages(ctx, &id)
1763 if err != nil {
1764 return err
1765 }
1766
1767 outputFormat := CharReplacer.Replace(options.Format)
1768 if outputFormat == "" {
1769 outputFormat = GetCommandOptionWithDefault("onu-image-list", "format", ONU_IMAGE_LIST_FORMAT)
1770 }
1771
1772 if options.Quiet {
1773 outputFormat = "{{.Id}}"
1774 }
1775
1776 //TODO orderby
1777
1778 // Make sure json output prints an empty list, not "null"
1779 if onuImages.Items == nil {
1780 onuImages.Items = make([]*voltha.OnuImage, 0)
1781 }
1782
1783 result := CommandResult{
1784 Format: format.Format(outputFormat),
1785 OutputAs: toOutputType(options.OutputAs),
1786 NameLimit: options.NameLimit,
1787 Data: onuImages.Items,
1788 }
1789
1790 GenerateOutput(&result)
1791 return nil
1792
1793}
1794
1795func (options *OnuImageStatus) Execute(args []string) error {
1796
1797 conn, err := NewConnection()
1798 if err != nil {
1799 return err
1800 }
1801 defer conn.Close()
1802
1803 client := voltha.NewVolthaServiceClient(conn)
1804
1805 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1806 defer cancel()
1807
1808 var devIDList []*common.ID
kesavand3e2f9f62021-04-22 11:06:38 +05301809
Elia Battiston859f3e62022-02-08 15:57:52 +01001810 if options.Args.IDs == nil {
1811 //Use an empty IDs list to retrieve the status of all devices
1812 //with the requested image version
1813 devIDList = []*common.ID{}
1814 } else {
1815 for _, i := range options.Args.IDs {
1816 devIDList = append(devIDList, &common.ID{Id: string(i)})
1817 }
kesavand3e2f9f62021-04-22 11:06:38 +05301818 }
1819
1820 imageStatusReq := voltha.DeviceImageRequest{
1821 DeviceId: devIDList,
1822 Version: options.Args.ImageVersion,
1823 }
1824 imageStatus, err := client.GetImageStatus(ctx, &imageStatusReq)
1825 if err != nil {
1826 return err
1827 }
1828
1829 outputFormat := CharReplacer.Replace(options.Format)
1830 if outputFormat == "" {
1831 outputFormat = GetCommandOptionWithDefault("device-image-list", "format", ONU_IMAGE_STATUS_FORMAT)
1832 }
1833
1834 if options.Quiet {
1835 outputFormat = "{{.Id}}"
1836 }
1837
1838 //TODO orderby
1839
1840 // Make sure json output prints an empty list, not "null"
1841 if imageStatus.DeviceImageStates == nil {
1842 imageStatus.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1843 }
1844
1845 result := CommandResult{
1846 Format: format.Format(outputFormat),
1847 OutputAs: toOutputType(options.OutputAs),
1848 NameLimit: options.NameLimit,
1849 Data: imageStatus.DeviceImageStates,
1850 }
1851
1852 GenerateOutput(&result)
1853 return nil
1854
1855}
1856
Andrea Campanella791d88b2021-01-08 13:29:00 +01001857func (options *DeviceOnuListImages) Execute(args []string) error {
1858
1859 conn, err := NewConnection()
1860 if err != nil {
1861 return err
1862 }
1863 defer conn.Close()
1864
1865 client := voltha.NewVolthaServiceClient(conn)
1866
David K. Bainbridge9189c632021-03-26 21:52:21 +00001867 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Andrea Campanella791d88b2021-01-08 13:29:00 +01001868 defer cancel()
1869
1870 id := common.ID{Id: string(options.Args.Id)}
1871
1872 imageDownloads, err := client.ListImageDownloads(ctx, &id)
1873 if err != nil {
1874 return err
1875 }
1876
1877 outputFormat := CharReplacer.Replace(options.Format)
1878 if outputFormat == "" {
1879 outputFormat = GetCommandOptionWithDefault("device-image-list", "format", DEFAULT_DEVICE_IMAGE_LIST_GET_FORMAT)
1880 }
1881
1882 if options.Quiet {
1883 outputFormat = "{{.Id}}"
1884 }
1885
1886 //TODO orderby
1887
1888 // Make sure json output prints an empty list, not "null"
1889 if imageDownloads.Items == nil {
1890 imageDownloads.Items = make([]*voltha.ImageDownload, 0)
1891 }
1892
1893 result := CommandResult{
1894 Format: format.Format(outputFormat),
1895 OutputAs: toOutputType(options.OutputAs),
1896 NameLimit: options.NameLimit,
1897 Data: imageDownloads.Items,
1898 }
1899
1900 GenerateOutput(&result)
1901 return nil
1902
1903}
1904
1905func (options *DeviceOnuDownloadImage) Execute(args []string) error {
1906
1907 conn, err := NewConnection()
1908 if err != nil {
1909 return err
1910 }
1911 defer conn.Close()
1912
1913 client := voltha.NewVolthaServiceClient(conn)
1914
David K. Bainbridge9189c632021-03-26 21:52:21 +00001915 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Andrea Campanella791d88b2021-01-08 13:29:00 +01001916 defer cancel()
1917
1918 downloadImage := voltha.ImageDownload{
1919 Id: string(options.Args.Id),
1920 Name: options.Args.Name,
1921 Url: options.Args.Url,
1922 Crc: options.Args.Crc,
1923 LocalDir: options.Args.LocalDir,
1924 }
1925
1926 _, err = client.DownloadImage(ctx, &downloadImage)
1927 if err != nil {
1928 return err
1929 }
1930
1931 return nil
1932
1933}
1934
1935func (options *DeviceOnuActivateImageUpdate) Execute(args []string) error {
1936
1937 conn, err := NewConnection()
1938 if err != nil {
1939 return err
1940 }
1941 defer conn.Close()
1942
1943 client := voltha.NewVolthaServiceClient(conn)
1944
David K. Bainbridge9189c632021-03-26 21:52:21 +00001945 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Andrea Campanella791d88b2021-01-08 13:29:00 +01001946 defer cancel()
1947
1948 downloadImage := voltha.ImageDownload{
1949 Id: string(options.Args.Id),
1950 Name: options.Args.Name,
1951 ImageVersion: options.Args.ImageVersion,
1952 SaveConfig: options.Args.SaveConfig,
1953 LocalDir: options.Args.LocalDir,
1954 }
1955
1956 _, err = client.ActivateImageUpdate(ctx, &downloadImage)
1957 if err != nil {
1958 return err
1959 }
1960
1961 return nil
1962
1963}
1964
Scott Baker9173ed82020-05-19 08:30:12 -07001965type ReturnValueRow struct {
1966 Name string `json:"name"`
1967 Result interface{} `json:"result"`
1968}
1969
kesavand8ec4fc02021-01-27 09:10:22 -05001970func (options *DeviceGetPortStats) Execute(args []string) error {
1971 conn, err := NewConnection()
1972 if err != nil {
1973 return err
1974 }
1975 defer conn.Close()
1976 client := extension.NewExtensionClient(conn)
1977 var portType extension.GetOltPortCounters_PortType
1978
1979 if options.Args.PortType == "pon" {
1980 portType = extension.GetOltPortCounters_Port_PON_OLT
1981 } else if options.Args.PortType == "nni" {
1982
1983 portType = extension.GetOltPortCounters_Port_ETHERNET_NNI
1984 } else {
1985 return fmt.Errorf("expected interface type pon/nni, provided %s", options.Args.PortType)
1986 }
1987
1988 singleGetValReq := extension.SingleGetValueRequest{
1989 TargetId: string(options.Args.Id),
1990 Request: &extension.GetValueRequest{
1991 Request: &extension.GetValueRequest_OltPortInfo{
1992 OltPortInfo: &extension.GetOltPortCounters{
1993 PortNo: options.Args.PortNo,
1994 PortType: portType,
1995 },
1996 },
1997 },
1998 }
1999
David K. Bainbridge9189c632021-03-26 21:52:21 +00002000 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand8ec4fc02021-01-27 09:10:22 -05002001 defer cancel()
2002 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2003 if err != nil {
2004 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2005 return err
2006 }
2007
2008 if rv.Response.Status != extension.GetValueResponse_OK {
2009 return fmt.Errorf("failed to get port stats %v", rv.Response.ErrReason.String())
2010 }
2011
2012 outputFormat := CharReplacer.Replace(options.Format)
2013 if outputFormat == "" {
2014 outputFormat = GetCommandOptionWithDefault("device-get-port-status", "format", DEFAULT_DEVICE_GET_PORT_STATUS_FORMAT)
2015 }
2016
2017 result := CommandResult{
2018 Format: format.Format(outputFormat),
2019 OutputAs: toOutputType(options.OutputAs),
2020 NameLimit: options.NameLimit,
2021 Data: rv.GetResponse().GetPortCoutners(),
2022 }
2023 GenerateOutput(&result)
2024 return nil
2025}
2026
Himani Chawla40acc122021-05-26 18:52:29 +05302027func (options *GetOnuStats) Execute(args []string) error {
2028 conn, err := NewConnection()
2029 if err != nil {
2030 return err
2031 }
2032 defer conn.Close()
2033 client := extension.NewExtensionClient(conn)
2034
2035 singleGetValReq := extension.SingleGetValueRequest{
2036 TargetId: string(options.Args.OltId),
2037 Request: &extension.GetValueRequest{
2038 Request: &extension.GetValueRequest_OnuPonInfo{
2039 OnuPonInfo: &extension.GetOnuCountersRequest{
2040 IntfId: options.Args.IntfId,
2041 OnuId: options.Args.OnuId,
2042 },
2043 },
2044 },
2045 }
2046 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2047 defer cancel()
2048 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2049 if err != nil {
2050 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.OltId, ErrorToString(err))
2051 return err
2052 }
2053
2054 if rv.Response.Status != extension.GetValueResponse_OK {
2055 return fmt.Errorf("failed to get onu stats %v", rv.Response.ErrReason.String())
2056 }
2057 outputFormat := CharReplacer.Replace(options.Format)
2058 data, formatStr := buildOnuStatsOutputFormat(rv.GetResponse().GetOnuPonCounters())
2059 if outputFormat == "" {
2060 outputFormat = GetCommandOptionWithDefault("device-get-onu-status", "format", formatStr)
2061 }
Himani Chawla553a1392021-06-10 23:39:17 +05302062 result := CommandResult{
2063 Format: format.Format(outputFormat),
2064 OutputAs: toOutputType(options.OutputAs),
2065 NameLimit: options.NameLimit,
2066 Data: data,
2067 }
2068 GenerateOutput(&result)
2069 return nil
2070}
Himani Chawla40acc122021-05-26 18:52:29 +05302071
Himani Chawla553a1392021-06-10 23:39:17 +05302072func (options *GetOnuEthernetFrameExtendedPmCounters) Execute(args []string) error {
2073 conn, err := NewConnection()
2074 if err != nil {
2075 return err
2076 }
2077 defer conn.Close()
2078 client := extension.NewExtensionClient(conn)
Himani Chawla806aa892021-08-30 15:51:46 +05302079 var singleGetValReq extension.SingleGetValueRequest
Himani Chawla553a1392021-06-10 23:39:17 +05302080
Himani Chawla806aa892021-08-30 15:51:46 +05302081 if options.Args.UniIndex != nil {
2082 singleGetValReq = extension.SingleGetValueRequest{
2083 TargetId: string(options.Args.Id),
2084 Request: &extension.GetValueRequest{
2085 Request: &extension.GetValueRequest_OnuInfo{
2086 OnuInfo: &extension.GetOmciEthernetFrameExtendedPmRequest{
2087 OnuDeviceId: string(options.Args.Id),
2088 Reset_: options.Reset,
2089 IsUniIndex: &extension.GetOmciEthernetFrameExtendedPmRequest_UniIndex{
2090 UniIndex: *options.Args.UniIndex,
2091 },
2092 },
Himani Chawla553a1392021-06-10 23:39:17 +05302093 },
2094 },
Himani Chawla806aa892021-08-30 15:51:46 +05302095 }
2096 } else {
2097 singleGetValReq = extension.SingleGetValueRequest{
2098 TargetId: string(options.Args.Id),
2099 Request: &extension.GetValueRequest{
2100 Request: &extension.GetValueRequest_OnuInfo{
2101 OnuInfo: &extension.GetOmciEthernetFrameExtendedPmRequest{
2102 OnuDeviceId: string(options.Args.Id),
2103 Reset_: options.Reset,
2104 },
2105 },
2106 },
2107 }
Himani Chawla553a1392021-06-10 23:39:17 +05302108 }
Himani Chawla806aa892021-08-30 15:51:46 +05302109
Himani Chawla553a1392021-06-10 23:39:17 +05302110 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2111 defer cancel()
2112 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2113 if err != nil {
2114 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2115 return err
2116 }
2117
2118 if rv.Response.Status != extension.GetValueResponse_OK {
2119 return fmt.Errorf("failed to get ethernet frame extended pm counters %v", rv.Response.ErrReason.String())
2120 }
2121 outputFormat := CharReplacer.Replace(options.Format)
2122 data := buildOnuEthernetFrameExtendedPmOutputFormat(rv.GetResponse().GetOnuCounters())
2123 if outputFormat == "" {
2124 outputFormat = GetCommandOptionWithDefault("device-get-onu-status", "format", DEFAULT_ETHERNET_FRAME_EXTENDED_PM_COUNTERS_FORMAT)
2125 }
Himani Chawla40acc122021-05-26 18:52:29 +05302126 result := CommandResult{
2127 Format: format.Format(outputFormat),
2128 OutputAs: toOutputType(options.OutputAs),
2129 NameLimit: options.NameLimit,
2130 Data: data,
2131 }
2132 GenerateOutput(&result)
2133 return nil
2134}
2135
kesavand6d1131f2021-02-05 22:38:15 +05302136func (options *UniStatus) Execute(args []string) error {
2137 conn, err := NewConnection()
2138 if err != nil {
2139 return err
2140 }
2141 defer conn.Close()
2142 client := extension.NewExtensionClient(conn)
2143
2144 singleGetValReq := extension.SingleGetValueRequest{
2145 TargetId: string(options.Args.Id),
2146 Request: &extension.GetValueRequest{
2147 Request: &extension.GetValueRequest_UniInfo{
2148 UniInfo: &extension.GetOnuUniInfoRequest{
2149 UniIndex: options.Args.UniIndex,
2150 },
2151 },
2152 },
2153 }
David K. Bainbridge9189c632021-03-26 21:52:21 +00002154 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand6d1131f2021-02-05 22:38:15 +05302155 defer cancel()
2156 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2157 if err != nil {
2158 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2159 return err
2160 }
2161 if rv.Response.Status != extension.GetValueResponse_OK {
2162 return fmt.Errorf("failed to get uni status %v", rv.Response.ErrReason.String())
2163 }
2164 outputFormat := CharReplacer.Replace(options.Format)
2165 if outputFormat == "" {
2166 outputFormat = GetCommandOptionWithDefault("device-get-uni-status", "format", DEFAULT_DEVICE_GET_UNI_STATUS_FORMAT)
2167 }
2168 result := CommandResult{
2169 Format: format.Format(outputFormat),
2170 OutputAs: toOutputType(options.OutputAs),
2171 NameLimit: options.NameLimit,
2172 Data: rv.GetResponse().GetUniInfo(),
2173 }
2174 GenerateOutput(&result)
2175 return nil
2176}
2177
Girish Gowdra4f5ce7c2021-04-29 18:53:21 -07002178func (options *OnuPonOpticalInfo) Execute(args []string) error {
2179 conn, err := NewConnection()
2180 if err != nil {
2181 return err
2182 }
2183 defer conn.Close()
2184 client := extension.NewExtensionClient(conn)
2185
2186 singleGetValReq := extension.SingleGetValueRequest{
2187 TargetId: string(options.Args.Id),
2188 Request: &extension.GetValueRequest{
2189 Request: &extension.GetValueRequest_OnuOpticalInfo{
2190 OnuOpticalInfo: &extension.GetOnuPonOpticalInfo{},
2191 },
2192 },
2193 }
2194 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2195 defer cancel()
2196 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2197 if err != nil {
2198 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2199 return err
2200 }
2201 if rv.Response.Status != extension.GetValueResponse_OK {
2202 return fmt.Errorf("failed to get onu pon optical info %v", rv.Response.ErrReason.String())
2203 }
2204 outputFormat := CharReplacer.Replace(options.Format)
2205 if outputFormat == "" {
2206 outputFormat = GetCommandOptionWithDefault("device-get-onu-pon-optical-info", "format", DEFAULT_ONU_PON_OPTICAL_INFO_STATUS_FORMAT)
2207 }
2208 result := CommandResult{
2209 Format: format.Format(outputFormat),
2210 OutputAs: toOutputType(options.OutputAs),
2211 NameLimit: options.NameLimit,
2212 Data: rv.GetResponse().GetOnuOpticalInfo(),
2213 }
2214 GenerateOutput(&result)
2215 return nil
2216}
2217
Gamze Abakac857a462021-05-26 13:45:54 +00002218func (options *RxPower) Execute(args []string) error {
2219 conn, err := NewConnection()
2220 if err != nil {
2221 return err
2222 }
2223 defer conn.Close()
2224 client := extension.NewExtensionClient(conn)
2225
2226 singleGetValReq := extension.SingleGetValueRequest{
2227 TargetId: string(options.Args.Id),
2228 Request: &extension.GetValueRequest{
2229 Request: &extension.GetValueRequest_RxPower{
2230 RxPower: &extension.GetRxPowerRequest{
2231 IntfId: options.Args.PortNo,
2232 OnuId: options.Args.OnuNo,
2233 },
2234 },
2235 },
2236 }
2237
2238 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2239 defer cancel()
2240 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2241 if err != nil {
2242 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2243 return err
2244 }
2245 if rv.Response.Status != extension.GetValueResponse_OK {
2246 return fmt.Errorf("failed to get rx power %v", rv.Response.ErrReason.String())
2247 }
2248 outputFormat := CharReplacer.Replace(options.Format)
2249 if outputFormat == "" {
2250 outputFormat = GetCommandOptionWithDefault("device-get-rx-power", "format", DEFAULT_RX_POWER_STATUS_FORMAT)
2251 }
2252 result := CommandResult{
2253 Format: format.Format(outputFormat),
2254 OutputAs: toOutputType(options.OutputAs),
2255 NameLimit: options.NameLimit,
2256 Data: rv.GetResponse().GetRxPower(),
2257 }
2258 GenerateOutput(&result)
2259 return nil
2260}
2261
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002262/*Device get Onu Distance */
2263func (options *DeviceGetExtValue) Execute(args []string) error {
2264 conn, err := NewConnection()
2265 if err != nil {
2266 return err
2267 }
2268 defer conn.Close()
2269
Scott Baker9173ed82020-05-19 08:30:12 -07002270 client := voltha.NewVolthaServiceClient(conn)
2271
khenaidoo080ce882021-10-19 17:35:08 -04002272 valueflag, okay := extension.ValueType_Type_value[string(options.Args.Valueflag)]
Scott Baker9173ed82020-05-19 08:30:12 -07002273 if !okay {
2274 Error.Printf("Unknown valueflag %s\n", options.Args.Valueflag)
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002275 }
2276
khenaidoo080ce882021-10-19 17:35:08 -04002277 val := extension.ValueSpecifier{Id: string(options.Args.Id), Value: extension.ValueType_Type(valueflag)}
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002278
David K. Bainbridge9189c632021-03-26 21:52:21 +00002279 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002280 defer cancel()
2281
Scott Baker9173ed82020-05-19 08:30:12 -07002282 rv, err := client.GetExtValue(ctx, &val)
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002283 if err != nil {
2284 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2285 return err
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002286 }
2287
Scott Baker9173ed82020-05-19 08:30:12 -07002288 var rows []ReturnValueRow
khenaidoo080ce882021-10-19 17:35:08 -04002289 for name, num := range extension.ValueType_Type_value {
Scott Baker9173ed82020-05-19 08:30:12 -07002290 if num == 0 {
2291 // EMPTY is not a real value
2292 continue
2293 }
2294 if (rv.Error & uint32(num)) != 0 {
2295 row := ReturnValueRow{Name: name, Result: "Error"}
2296 rows = append(rows, row)
2297 }
2298 if (rv.Unsupported & uint32(num)) != 0 {
2299 row := ReturnValueRow{Name: name, Result: "Unsupported"}
2300 rows = append(rows, row)
2301 }
2302 if (rv.Set & uint32(num)) != 0 {
2303 switch name {
2304 case "DISTANCE":
2305 row := ReturnValueRow{Name: name, Result: rv.Distance}
2306 rows = append(rows, row)
2307 default:
2308 row := ReturnValueRow{Name: name, Result: "Unimplemented-in-voltctl"}
2309 rows = append(rows, row)
2310 }
2311 }
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002312 }
2313
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002314 outputFormat := CharReplacer.Replace(options.Format)
2315 if outputFormat == "" {
2316 outputFormat = GetCommandOptionWithDefault("device-value-get", "format", DEFAULT_DEVICE_VALUE_GET_FORMAT)
2317 }
2318
2319 result := CommandResult{
2320 Format: format.Format(outputFormat),
2321 OutputAs: toOutputType(options.OutputAs),
2322 NameLimit: options.NameLimit,
Scott Baker9173ed82020-05-19 08:30:12 -07002323 Data: rows,
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002324 }
2325 GenerateOutput(&result)
2326 return nil
2327}