blob: 0bcda77484953067c3cf39c443da724395a641a2 [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"
kesavand8ec4fc02021-01-27 09:10:22 -050029 "github.com/opencord/voltha-protos/v4/go/common"
30 "github.com/opencord/voltha-protos/v4/go/extension"
31 "github.com/opencord/voltha-protos/v4/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}}
109DFrames_1024To_1518Octets: {{.DFrames_1024To_1518Octets}}`
Zack Williamse940c7a2019-08-21 14:25:39 -0700110)
111
112type DeviceList struct {
113 ListOutputOptions
114}
115
116type DeviceCreate struct {
David Bainbridge1a514392020-06-23 11:12:51 -0700117 DeviceType string `short:"t" required:"true" long:"devicetype" description:"Device type"`
David Bainbridge835dd0e2020-04-01 10:30:09 -0700118 MACAddress string `short:"m" long:"macaddress" default:"" description:"MAC Address"`
Zack Williamse940c7a2019-08-21 14:25:39 -0700119 IPAddress string `short:"i" long:"ipaddress" default:"" description:"IP Address"`
120 HostAndPort string `short:"H" long:"hostandport" default:"" description:"Host and port"`
121}
122
123type DeviceId string
124
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000125type MetricName string
126type GroupName string
kesavand12cd8eb2020-01-20 22:25:22 -0500127type PortNum uint32
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -0800128type ValueFlag string
kesavand12cd8eb2020-01-20 22:25:22 -0500129
Zack Williamse940c7a2019-08-21 14:25:39 -0700130type DeviceDelete struct {
Himani Chawla9933ddc2020-10-12 23:53:27 +0530131 Force bool `long:"force" description:"Delete device forcefully"`
132 Args struct {
Zack Williamse940c7a2019-08-21 14:25:39 -0700133 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
134 } `positional-args:"yes"`
135}
136
137type DeviceEnable struct {
138 Args struct {
139 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
140 } `positional-args:"yes"`
141}
142
143type DeviceDisable struct {
144 Args struct {
145 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
146 } `positional-args:"yes"`
147}
148
149type DeviceReboot struct {
150 Args struct {
151 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
152 } `positional-args:"yes"`
153}
154
155type DeviceFlowList struct {
156 ListOutputOptions
Maninder045921e2020-09-29 16:46:02 +0530157 FlowIdOptions
Zack Williamse940c7a2019-08-21 14:25:39 -0700158 Args struct {
159 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
160 } `positional-args:"yes"`
161}
162
Himani Chawla3c161c62021-05-13 16:36:51 +0530163type DeviceFlowGroupList struct {
164 ListOutputOptions
165 GroupListOptions
166 Args struct {
167 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
168 } `positional-args:"yes"`
169}
Zack Williamse940c7a2019-08-21 14:25:39 -0700170type DevicePortList struct {
171 ListOutputOptions
172 Args struct {
173 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
174 } `positional-args:"yes"`
175}
176
177type DeviceInspect struct {
178 OutputOptionsJson
179 Args struct {
180 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
181 } `positional-args:"yes"`
182}
183
kesavand12cd8eb2020-01-20 22:25:22 -0500184type DevicePortEnable struct {
185 Args struct {
186 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
187 PortId PortNum `positional-arg-name:"PORT_NUMBER" required:"yes"`
188 } `positional-args:"yes"`
189}
190
191type DevicePortDisable struct {
192 Args struct {
193 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
194 PortId PortNum `positional-arg-name:"PORT_NUMBER" required:"yes"`
195 } `positional-args:"yes"`
196}
197
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000198type DevicePmConfigsGet struct {
199 ListOutputOptions
200 Args struct {
201 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
202 } `positional-args:"yes"`
203}
204
205type DevicePmConfigMetricList struct {
206 ListOutputOptions
207 Args struct {
208 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
209 } `positional-args:"yes"`
210}
211
212type DevicePmConfigGroupList struct {
213 ListOutputOptions
214 Args struct {
215 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
216 } `positional-args:"yes"`
217}
218
219type DevicePmConfigGroupMetricList struct {
220 ListOutputOptions
221 Args struct {
222 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
223 Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"`
224 } `positional-args:"yes"`
225}
226
227type DevicePmConfigFrequencySet struct {
228 OutputOptions
229 Args struct {
Girish Gowdra610acb42021-01-27 13:33:57 -0800230 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
231 Interval time.Duration `positional-arg-name:"INTERVAL" required:"yes"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000232 } `positional-args:"yes"`
233}
234
235type DevicePmConfigMetricEnable struct {
236 Args struct {
237 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
238 Metrics []MetricName `positional-arg-name:"METRIC_NAME" required:"yes"`
239 } `positional-args:"yes"`
240}
241
242type DevicePmConfigMetricDisable struct {
243 Args struct {
244 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
245 Metrics []MetricName `positional-arg-name:"METRIC_NAME" required:"yes"`
246 } `positional-args:"yes"`
247}
248
249type DevicePmConfigGroupEnable struct {
250 Args struct {
Girish Gowdra610acb42021-01-27 13:33:57 -0800251 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
252 Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000253 } `positional-args:"yes"`
254}
255
256type DevicePmConfigGroupDisable struct {
257 Args struct {
Girish Gowdra610acb42021-01-27 13:33:57 -0800258 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
259 Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"`
260 } `positional-args:"yes"`
261}
262
263type DevicePmConfigGroupFrequencySet struct {
264 OutputOptions
265 Args struct {
266 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
267 Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"`
268 Interval time.Duration `positional-arg-name:"INTERVAL" required:"yes"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000269 } `positional-args:"yes"`
270}
271
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -0800272type DeviceGetExtValue struct {
273 ListOutputOptions
274 Args struct {
275 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
276 Valueflag ValueFlag `positional-arg-name:"VALUE_FLAG" required:"yes"`
277 } `positional-args:"yes"`
278}
Rohan Agrawald7df3772020-06-29 11:23:36 +0000279
280type DevicePmConfigSetMaxSkew struct {
281 Args struct {
282 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
283 MaxSkew uint32 `positional-arg-name:"MAX_SKEW" required:"yes"`
284 } `positional-args:"yes"`
285}
286
Andrea Campanella791d88b2021-01-08 13:29:00 +0100287type DeviceOnuListImages struct {
288 ListOutputOptions
289 Args struct {
290 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
291 } `positional-args:"yes"`
292}
293
294type DeviceOnuDownloadImage struct {
295 Args struct {
296 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
297 Name string `positional-arg-name:"IMAGE_NAME" required:"yes"`
298 Url string `positional-arg-name:"IMAGE_URL" required:"yes"`
299 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
300 Crc uint32 `positional-arg-name:"IMAGE_CRC" required:"yes"`
301 LocalDir string `positional-arg-name:"IMAGE_LOCAL_DIRECTORY"`
302 } `positional-args:"yes"`
303}
304
305type DeviceOnuActivateImageUpdate struct {
306 Args struct {
307 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
308 Name string `positional-arg-name:"IMAGE_NAME" required:"yes"`
309 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
310 SaveConfig bool `positional-arg-name:"SAVE_EXISTING_CONFIG"`
311 LocalDir string `positional-arg-name:"IMAGE_LOCAL_DIRECTORY"`
Andrea Campanella7b2ecf42021-02-25 12:27:15 +0100312 } `positional-args:"yes"`
kesavand8ec4fc02021-01-27 09:10:22 -0500313}
kesavand3e2f9f62021-04-22 11:06:38 +0530314
315type OnuDownloadImage struct {
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +0200316 ListOutputOptions
kesavand3e2f9f62021-04-22 11:06:38 +0530317 Args struct {
318 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
319 Url string `positional-arg-name:"IMAGE_URL" required:"yes"`
ssiddiqui7bc89e92021-05-20 20:58:02 +0530320 Vendor string `positional-arg-name:"IMAGE_VENDOR"`
kesavand3e2f9f62021-04-22 11:06:38 +0530321 ActivateOnSuccess bool `positional-arg-name:"IMAGE_ACTIVATE_ON_SUCCESS"`
322 CommitOnSuccess bool `positional-arg-name:"IMAGE_COMMIT_ON_SUCCESS"`
323 Crc uint32 `positional-arg-name:"IMAGE_CRC"`
324 IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
325 } `positional-args:"yes"`
326}
327
328type OnuActivateImage struct {
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +0200329 ListOutputOptions
kesavand3e2f9f62021-04-22 11:06:38 +0530330 Args struct {
331 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
332 CommitOnSuccess bool `positional-arg-name:"IMAGE_COMMIT_ON_SUCCESS"`
333 IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
334 } `positional-args:"yes"`
335}
336
337type OnuAbortUpgradeImage struct {
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +0200338 ListOutputOptions
kesavand3e2f9f62021-04-22 11:06:38 +0530339 Args struct {
340 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
341 IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
342 } `positional-args:"yes"`
343}
344
345type OnuCommitImage struct {
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +0200346 ListOutputOptions
kesavand3e2f9f62021-04-22 11:06:38 +0530347 Args struct {
348 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
349 IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
350 } `positional-args:"yes"`
351}
352
353type OnuImageStatus struct {
354 ListOutputOptions
355 Args struct {
356 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
357 IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
358 } `positional-args:"yes"`
359}
360
361type OnuListImages struct {
362 ListOutputOptions
363 Args struct {
364 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
365 } `positional-args:"yes"`
366}
367
kesavand8ec4fc02021-01-27 09:10:22 -0500368type DeviceGetPortStats struct {
369 ListOutputOptions
370 Args struct {
371 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
372 PortNo uint32 `positional-arg-name:"PORT_NO" required:"yes"`
373 PortType string `positional-arg-name:"PORT_TYPE" required:"yes"`
Andrea Campanella791d88b2021-01-08 13:29:00 +0100374 } `positional-args:"yes"`
375}
kesavand6d1131f2021-02-05 22:38:15 +0530376type UniStatus struct {
377 ListOutputOptions
378 Args struct {
379 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
380 UniIndex uint32 `positional-arg-name:"UNI_INDEX" required:"yes"`
381 } `positional-args:"yes"`
382}
Girish Gowdra4f5ce7c2021-04-29 18:53:21 -0700383type OnuPonOpticalInfo struct {
384 ListOutputOptions
385 Args struct {
386 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
387 } `positional-args:"yes"`
388}
Himani Chawla40acc122021-05-26 18:52:29 +0530389
390type GetOnuStats struct {
391 ListOutputOptions
392 Args struct {
393 OltId DeviceId `positional-arg-name:"OLT_DEVICE_ID" required:"yes"`
394 IntfId uint32 `positional-arg-name:"PON_INTF_ID" required:"yes"`
395 OnuId uint32 `positional-arg-name:"ONU_ID" required:"yes"`
396 } `positional-args:"yes"`
397}
398
Himani Chawla553a1392021-06-10 23:39:17 +0530399type GetOnuEthernetFrameExtendedPmCounters struct {
400 ListOutputOptions
401 Args struct {
402 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
403 } `positional-args:"yes"`
404}
405
Gamze Abakac857a462021-05-26 13:45:54 +0000406type RxPower struct {
407 ListOutputOptions
408 Args struct {
409 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
410 PortNo uint32 `positional-arg-name:"PORT_NO" required:"yes"`
411 OnuNo uint32 `positional-arg-name:"ONU_NO" required:"yes"`
412 } `positional-args:"yes"`
413}
414
Zack Williamse940c7a2019-08-21 14:25:39 -0700415type DeviceOpts struct {
Himani Chawla3c161c62021-05-13 16:36:51 +0530416 List DeviceList `command:"list"`
417 Create DeviceCreate `command:"create"`
418 Delete DeviceDelete `command:"delete"`
419 Enable DeviceEnable `command:"enable"`
420 Disable DeviceDisable `command:"disable"`
421 Flows DeviceFlowList `command:"flows"`
422 Groups DeviceFlowGroupList `command:"groups"`
kesavand12cd8eb2020-01-20 22:25:22 -0500423 Port struct {
424 List DevicePortList `command:"list"`
425 Enable DevicePortEnable `command:"enable"`
426 Disable DevicePortDisable `command:"disable"`
427 } `command:"port"`
428 Inspect DeviceInspect `command:"inspect"`
429 Reboot DeviceReboot `command:"reboot"`
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -0800430 Value struct {
431 Get DeviceGetExtValue `command:"get"`
432 } `command:"value"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000433 PmConfig struct {
Rohan Agrawald7df3772020-06-29 11:23:36 +0000434 Get DevicePmConfigsGet `command:"get"`
435 MaxSkew struct {
436 Set DevicePmConfigSetMaxSkew `command:"set"`
437 } `command:"maxskew"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000438 Frequency struct {
439 Set DevicePmConfigFrequencySet `command:"set"`
440 } `command:"frequency"`
441 Metric struct {
442 List DevicePmConfigMetricList `command:"list"`
443 Enable DevicePmConfigMetricEnable `command:"enable"`
444 Disable DevicePmConfigMetricDisable `command:"disable"`
445 } `command:"metric"`
446 Group struct {
Girish Gowdra610acb42021-01-27 13:33:57 -0800447 List DevicePmConfigGroupList `command:"list"`
448 Enable DevicePmConfigGroupEnable `command:"enable"`
449 Disable DevicePmConfigGroupDisable `command:"disable"`
450 Set DevicePmConfigGroupFrequencySet `command:"set"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000451 } `command:"group"`
452 GroupMetric struct {
453 List DevicePmConfigGroupMetricList `command:"list"`
454 } `command:"groupmetric"`
455 } `command:"pmconfig"`
Andrea Campanella791d88b2021-01-08 13:29:00 +0100456 Image struct {
457 Get DeviceOnuListImages `command:"list"`
458 Download DeviceOnuDownloadImage `command:"download"`
459 Activate DeviceOnuActivateImageUpdate `command:"activate"`
460 } `command:"image"`
kesavand3e2f9f62021-04-22 11:06:38 +0530461 DownloadImage struct {
462 Download OnuDownloadImage `command:"download"`
463 Activate OnuActivateImage `command:"activate"`
464 Commit OnuCommitImage `command:"commit"`
465 AbortUpgrade OnuAbortUpgradeImage `command:"abort"`
466 Status OnuImageStatus `command:"status"`
467 List OnuListImages `command:"list" `
468 } `command:"onuimage"`
kesavand8ec4fc02021-01-27 09:10:22 -0500469 GetExtVal struct {
Himani Chawla553a1392021-06-10 23:39:17 +0530470 Stats DeviceGetPortStats `command:"portstats"`
471 UniStatus UniStatus `command:"unistatus"`
472 OpticalInfo OnuPonOpticalInfo `command:"onu_pon_optical_info"`
473 OnuStats GetOnuStats `command:"onu_stats"`
474 EthernetFrameExtendedPm GetOnuEthernetFrameExtendedPmCounters `command:"ethernet_frame_extended_pm"`
475 RxPower RxPower `command:"rxpower"`
kesavand8ec4fc02021-01-27 09:10:22 -0500476 } `command:"getextval"`
Zack Williamse940c7a2019-08-21 14:25:39 -0700477}
478
479var deviceOpts = DeviceOpts{}
480
481func RegisterDeviceCommands(parser *flags.Parser) {
David Bainbridge12f036f2019-10-15 22:09:04 +0000482 if _, err := parser.AddCommand("device", "device commands", "Commands to query and manipulate VOLTHA devices", &deviceOpts); err != nil {
David Bainbridgea6722342019-10-24 23:55:53 +0000483 Error.Fatalf("Unexpected error while attempting to register device commands : %s", err)
David Bainbridge12f036f2019-10-15 22:09:04 +0000484 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700485}
486
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000487func (i *MetricName) Complete(match string) []flags.Completion {
488 conn, err := NewConnection()
489 if err != nil {
490 return nil
491 }
492 defer conn.Close()
493
494 client := voltha.NewVolthaServiceClient(conn)
495
496 var deviceId string
497found:
498 for i := len(os.Args) - 1; i >= 0; i -= 1 {
499 switch os.Args[i] {
500 case "enable":
501 fallthrough
502 case "disable":
503 if len(os.Args) > i+1 {
504 deviceId = os.Args[i+1]
505 } else {
506 return nil
507 }
508 break found
509 default:
510 }
511 }
512
513 if len(deviceId) == 0 {
514 return nil
515 }
516
David K. Bainbridge9189c632021-03-26 21:52:21 +0000517 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000518 defer cancel()
519
520 id := voltha.ID{Id: string(deviceId)}
521
522 pmconfigs, err := client.ListDevicePmConfigs(ctx, &id)
523
524 if err != nil {
525 return nil
526 }
527
528 list := make([]flags.Completion, 0)
529 for _, metrics := range pmconfigs.Metrics {
530 if strings.HasPrefix(metrics.Name, match) {
531 list = append(list, flags.Completion{Item: metrics.Name})
532 }
533 }
534
535 return list
536}
537
538func (i *GroupName) Complete(match string) []flags.Completion {
539 conn, err := NewConnection()
540 if err != nil {
541 return nil
542 }
543 defer conn.Close()
544
545 client := voltha.NewVolthaServiceClient(conn)
546
547 var deviceId string
548found:
549 for i := len(os.Args) - 1; i >= 0; i -= 1 {
550 switch os.Args[i] {
551 case "list":
552 fallthrough
553 case "enable":
554 fallthrough
555 case "disable":
556 if len(os.Args) > i+1 {
557 deviceId = os.Args[i+1]
558 } else {
559 return nil
560 }
561 break found
562 default:
563 }
564 }
565
566 if len(deviceId) == 0 {
567 return nil
568 }
569
David K. Bainbridge9189c632021-03-26 21:52:21 +0000570 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000571 defer cancel()
572
573 id := voltha.ID{Id: string(deviceId)}
574
575 pmconfigs, err := client.ListDevicePmConfigs(ctx, &id)
576
577 if err != nil {
578 return nil
579 }
580
581 list := make([]flags.Completion, 0)
582 for _, group := range pmconfigs.Groups {
583 if strings.HasPrefix(group.GroupName, match) {
584 list = append(list, flags.Completion{Item: group.GroupName})
585 }
586 }
587 return list
588}
589
kesavand12cd8eb2020-01-20 22:25:22 -0500590func (i *PortNum) Complete(match string) []flags.Completion {
591 conn, err := NewConnection()
592 if err != nil {
593 return nil
594 }
595 defer conn.Close()
596
Scott Baker9173ed82020-05-19 08:30:12 -0700597 client := voltha.NewVolthaServiceClient(conn)
kesavand12cd8eb2020-01-20 22:25:22 -0500598
599 /*
600 * The command line args when completing for PortNum will be a DeviceId
601 * followed by one or more PortNums. So walk the argument list from the
602 * end and find the first argument that is enable/disable as those are
603 * the subcommands that come before the positional arguments. It would
604 * be nice if this package gave us the list of optional arguments
605 * already parsed.
606 */
607 var deviceId string
608found:
609 for i := len(os.Args) - 1; i >= 0; i -= 1 {
610 switch os.Args[i] {
611 case "enable":
612 fallthrough
613 case "disable":
614 if len(os.Args) > i+1 {
615 deviceId = os.Args[i+1]
616 } else {
617 return nil
618 }
619 break found
620 default:
621 }
622 }
623
624 if len(deviceId) == 0 {
625 return nil
626 }
627
David K. Bainbridge9189c632021-03-26 21:52:21 +0000628 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand12cd8eb2020-01-20 22:25:22 -0500629 defer cancel()
kesavand12cd8eb2020-01-20 22:25:22 -0500630
Scott Baker9173ed82020-05-19 08:30:12 -0700631 id := voltha.ID{Id: string(deviceId)}
kesavand12cd8eb2020-01-20 22:25:22 -0500632
Scott Baker9173ed82020-05-19 08:30:12 -0700633 ports, err := client.ListDevicePorts(ctx, &id)
kesavand12cd8eb2020-01-20 22:25:22 -0500634 if err != nil {
635 return nil
636 }
637
638 list := make([]flags.Completion, 0)
Scott Baker9173ed82020-05-19 08:30:12 -0700639 for _, item := range ports.Items {
640 pn := strconv.FormatUint(uint64(item.PortNo), 10)
kesavand12cd8eb2020-01-20 22:25:22 -0500641 if strings.HasPrefix(pn, match) {
642 list = append(list, flags.Completion{Item: pn})
643 }
644 }
645
646 return list
647}
648
Zack Williamse940c7a2019-08-21 14:25:39 -0700649func (i *DeviceId) Complete(match string) []flags.Completion {
650 conn, err := NewConnection()
651 if err != nil {
652 return nil
653 }
654 defer conn.Close()
655
Scott Baker9173ed82020-05-19 08:30:12 -0700656 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700657
David K. Bainbridge9189c632021-03-26 21:52:21 +0000658 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700659 defer cancel()
660
Scott Baker9173ed82020-05-19 08:30:12 -0700661 devices, err := client.ListDevices(ctx, &empty.Empty{})
Zack Williamse940c7a2019-08-21 14:25:39 -0700662 if err != nil {
663 return nil
664 }
665
666 list := make([]flags.Completion, 0)
Scott Baker9173ed82020-05-19 08:30:12 -0700667 for _, item := range devices.Items {
668 if strings.HasPrefix(item.Id, match) {
669 list = append(list, flags.Completion{Item: item.Id})
Zack Williamse940c7a2019-08-21 14:25:39 -0700670 }
671 }
672
673 return list
674}
675
676func (options *DeviceList) Execute(args []string) error {
677
678 conn, err := NewConnection()
679 if err != nil {
680 return err
681 }
682 defer conn.Close()
683
Scott Baker9173ed82020-05-19 08:30:12 -0700684 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700685
David K. Bainbridge9189c632021-03-26 21:52:21 +0000686 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700687 defer cancel()
688
Scott Baker9173ed82020-05-19 08:30:12 -0700689 devices, err := client.ListDevices(ctx, &empty.Empty{})
Zack Williamse940c7a2019-08-21 14:25:39 -0700690 if err != nil {
691 return err
692 }
693
694 outputFormat := CharReplacer.Replace(options.Format)
695 if outputFormat == "" {
David Bainbridgea6722342019-10-24 23:55:53 +0000696 outputFormat = GetCommandOptionWithDefault("device-list", "format", DEFAULT_DEVICE_FORMAT)
Zack Williamse940c7a2019-08-21 14:25:39 -0700697 }
698 if options.Quiet {
699 outputFormat = "{{.Id}}"
700 }
701
David Bainbridgea6722342019-10-24 23:55:53 +0000702 orderBy := options.OrderBy
703 if orderBy == "" {
704 orderBy = GetCommandOptionWithDefault("device-list", "order", "")
705 }
706
Scott Baker9173ed82020-05-19 08:30:12 -0700707 // Make sure json output prints an empty list, not "null"
708 if devices.Items == nil {
709 devices.Items = make([]*voltha.Device, 0)
Zack Williamse940c7a2019-08-21 14:25:39 -0700710 }
711
712 result := CommandResult{
713 Format: format.Format(outputFormat),
714 Filter: options.Filter,
David Bainbridgea6722342019-10-24 23:55:53 +0000715 OrderBy: orderBy,
Zack Williamse940c7a2019-08-21 14:25:39 -0700716 OutputAs: toOutputType(options.OutputAs),
717 NameLimit: options.NameLimit,
Scott Baker9173ed82020-05-19 08:30:12 -0700718 Data: devices.Items,
Zack Williamse940c7a2019-08-21 14:25:39 -0700719 }
720
721 GenerateOutput(&result)
722 return nil
723}
724
725func (options *DeviceCreate) Execute(args []string) error {
726
Scott Baker9173ed82020-05-19 08:30:12 -0700727 device := voltha.Device{}
Zack Williamse940c7a2019-08-21 14:25:39 -0700728 if options.HostAndPort != "" {
Scott Baker9173ed82020-05-19 08:30:12 -0700729 device.Address = &voltha.Device_HostAndPort{HostAndPort: options.HostAndPort}
Zack Williamse940c7a2019-08-21 14:25:39 -0700730 } else if options.IPAddress != "" {
Scott Baker9173ed82020-05-19 08:30:12 -0700731 device.Address = &voltha.Device_Ipv4Address{Ipv4Address: options.IPAddress}
Hardik Windlassce1de342020-02-04 21:58:07 +0000732 }
733 if options.MACAddress != "" {
Scott Baker9173ed82020-05-19 08:30:12 -0700734 device.MacAddress = strings.ToLower(options.MACAddress)
Zack Williamse940c7a2019-08-21 14:25:39 -0700735 }
736 if options.DeviceType != "" {
Scott Baker9173ed82020-05-19 08:30:12 -0700737 device.Type = options.DeviceType
Zack Williamse940c7a2019-08-21 14:25:39 -0700738 }
739
740 conn, err := NewConnection()
741 if err != nil {
742 return err
743 }
744 defer conn.Close()
745
Scott Baker9173ed82020-05-19 08:30:12 -0700746 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700747
David K. Bainbridge9189c632021-03-26 21:52:21 +0000748 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700749 defer cancel()
750
Scott Baker9173ed82020-05-19 08:30:12 -0700751 createdDevice, err := client.CreateDevice(ctx, &device)
Zack Williamse940c7a2019-08-21 14:25:39 -0700752 if err != nil {
753 return err
Zack Williamse940c7a2019-08-21 14:25:39 -0700754 }
755
Scott Baker9173ed82020-05-19 08:30:12 -0700756 fmt.Printf("%s\n", createdDevice.Id)
Zack Williamse940c7a2019-08-21 14:25:39 -0700757
758 return nil
759}
760
761func (options *DeviceDelete) Execute(args []string) error {
762
763 conn, err := NewConnection()
764 if err != nil {
765 return err
766 }
767 defer conn.Close()
768
Scott Baker9173ed82020-05-19 08:30:12 -0700769 client := voltha.NewVolthaServiceClient(conn)
David Bainbridge7052fe82020-03-25 10:37:00 -0700770 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -0700771 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +0000772 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700773 defer cancel()
774
Scott Baker9173ed82020-05-19 08:30:12 -0700775 id := voltha.ID{Id: string(i)}
Himani Chawla9933ddc2020-10-12 23:53:27 +0530776 if options.Force {
777 _, err = client.ForceDeleteDevice(ctx, &id)
778 } else {
779 _, err = client.DeleteDevice(ctx, &id)
780 }
Scott Baker9173ed82020-05-19 08:30:12 -0700781
Zack Williamse940c7a2019-08-21 14:25:39 -0700782 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +0000783 Error.Printf("Error while deleting '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -0700784 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -0700785 continue
Zack Williamse940c7a2019-08-21 14:25:39 -0700786 }
787 fmt.Printf("%s\n", i)
788 }
789
David Bainbridge7052fe82020-03-25 10:37:00 -0700790 if lastErr != nil {
791 return NoReportErr
792 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700793 return nil
794}
795
796func (options *DeviceEnable) Execute(args []string) error {
797 conn, err := NewConnection()
798 if err != nil {
799 return err
800 }
801 defer conn.Close()
802
Scott Baker9173ed82020-05-19 08:30:12 -0700803 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700804
David Bainbridge7052fe82020-03-25 10:37:00 -0700805 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -0700806 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +0000807 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700808 defer cancel()
809
Scott Baker9173ed82020-05-19 08:30:12 -0700810 id := voltha.ID{Id: string(i)}
811
812 _, err := client.EnableDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -0700813 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +0000814 Error.Printf("Error while enabling '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -0700815 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -0700816 continue
Zack Williamse940c7a2019-08-21 14:25:39 -0700817 }
818 fmt.Printf("%s\n", i)
819 }
820
David Bainbridge7052fe82020-03-25 10:37:00 -0700821 if lastErr != nil {
822 return NoReportErr
823 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700824 return nil
825}
826
827func (options *DeviceDisable) Execute(args []string) error {
828 conn, err := NewConnection()
829 if err != nil {
830 return err
831 }
832 defer conn.Close()
833
Scott Baker9173ed82020-05-19 08:30:12 -0700834 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700835
David Bainbridge7052fe82020-03-25 10:37:00 -0700836 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -0700837 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +0000838 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700839 defer cancel()
840
Scott Baker9173ed82020-05-19 08:30:12 -0700841 id := voltha.ID{Id: string(i)}
842
843 _, err := client.DisableDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -0700844 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +0000845 Error.Printf("Error while disabling '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -0700846 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -0700847 continue
Zack Williamse940c7a2019-08-21 14:25:39 -0700848 }
849 fmt.Printf("%s\n", i)
850 }
851
David Bainbridge7052fe82020-03-25 10:37:00 -0700852 if lastErr != nil {
853 return NoReportErr
854 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700855 return nil
856}
857
858func (options *DeviceReboot) Execute(args []string) error {
859 conn, err := NewConnection()
860 if err != nil {
861 return err
862 }
863 defer conn.Close()
864
Scott Baker9173ed82020-05-19 08:30:12 -0700865 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700866
David Bainbridge7052fe82020-03-25 10:37:00 -0700867 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -0700868 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +0000869 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700870 defer cancel()
871
Scott Baker9173ed82020-05-19 08:30:12 -0700872 id := voltha.ID{Id: string(i)}
873
874 _, err := client.RebootDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -0700875 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +0000876 Error.Printf("Error while rebooting '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -0700877 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -0700878 continue
Zack Williamse940c7a2019-08-21 14:25:39 -0700879 }
880 fmt.Printf("%s\n", i)
881 }
882
David Bainbridge7052fe82020-03-25 10:37:00 -0700883 if lastErr != nil {
884 return NoReportErr
885 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700886 return nil
887}
888
889func (options *DevicePortList) Execute(args []string) error {
890
891 conn, err := NewConnection()
892 if err != nil {
893 return err
894 }
895 defer conn.Close()
896
Scott Baker9173ed82020-05-19 08:30:12 -0700897 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700898
David K. Bainbridge9189c632021-03-26 21:52:21 +0000899 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700900 defer cancel()
901
Scott Baker9173ed82020-05-19 08:30:12 -0700902 id := voltha.ID{Id: string(options.Args.Id)}
Zack Williamse940c7a2019-08-21 14:25:39 -0700903
Scott Baker9173ed82020-05-19 08:30:12 -0700904 ports, err := client.ListDevicePorts(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -0700905 if err != nil {
906 return err
907 }
908
909 outputFormat := CharReplacer.Replace(options.Format)
910 if outputFormat == "" {
David Bainbridgea6722342019-10-24 23:55:53 +0000911 outputFormat = GetCommandOptionWithDefault("device-ports", "format", DEFAULT_DEVICE_PORTS_FORMAT)
Zack Williamse940c7a2019-08-21 14:25:39 -0700912 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700913
David Bainbridgea6722342019-10-24 23:55:53 +0000914 orderBy := options.OrderBy
915 if orderBy == "" {
916 orderBy = GetCommandOptionWithDefault("device-ports", "order", "")
917 }
918
Zack Williamse940c7a2019-08-21 14:25:39 -0700919 result := CommandResult{
920 Format: format.Format(outputFormat),
921 Filter: options.Filter,
David Bainbridgea6722342019-10-24 23:55:53 +0000922 OrderBy: orderBy,
Zack Williamse940c7a2019-08-21 14:25:39 -0700923 OutputAs: toOutputType(options.OutputAs),
924 NameLimit: options.NameLimit,
Scott Baker9173ed82020-05-19 08:30:12 -0700925 Data: ports.Items,
Zack Williamse940c7a2019-08-21 14:25:39 -0700926 }
927
928 GenerateOutput(&result)
929 return nil
930}
931
932func (options *DeviceFlowList) Execute(args []string) error {
933 fl := &FlowList{}
934 fl.ListOutputOptions = options.ListOutputOptions
Maninder045921e2020-09-29 16:46:02 +0530935 fl.FlowIdOptions = options.FlowIdOptions
Zack Williamse940c7a2019-08-21 14:25:39 -0700936 fl.Args.Id = string(options.Args.Id)
David Bainbridgea6722342019-10-24 23:55:53 +0000937 fl.Method = "device-flows"
Zack Williamse940c7a2019-08-21 14:25:39 -0700938 return fl.Execute(args)
939}
940
Himani Chawla3c161c62021-05-13 16:36:51 +0530941func (options *DeviceFlowGroupList) Execute(args []string) error {
942 grp := &GroupList{}
943 grp.ListOutputOptions = options.ListOutputOptions
944 grp.GroupListOptions = options.GroupListOptions
945 grp.Args.Id = string(options.Args.Id)
946 grp.Method = "device-groups"
947 return grp.Execute(args)
948}
949
Zack Williamse940c7a2019-08-21 14:25:39 -0700950func (options *DeviceInspect) Execute(args []string) error {
951 if len(args) > 0 {
952 return fmt.Errorf("only a single argument 'DEVICE_ID' can be provided")
953 }
954
955 conn, err := NewConnection()
956 if err != nil {
957 return err
958 }
959 defer conn.Close()
960
Scott Baker9173ed82020-05-19 08:30:12 -0700961 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700962
David K. Bainbridge9189c632021-03-26 21:52:21 +0000963 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700964 defer cancel()
965
Scott Baker9173ed82020-05-19 08:30:12 -0700966 id := voltha.ID{Id: string(options.Args.Id)}
Zack Williamse940c7a2019-08-21 14:25:39 -0700967
Scott Baker9173ed82020-05-19 08:30:12 -0700968 device, err := client.GetDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -0700969 if err != nil {
970 return err
971 }
972
Zack Williamse940c7a2019-08-21 14:25:39 -0700973 outputFormat := CharReplacer.Replace(options.Format)
974 if outputFormat == "" {
David Bainbridgea6722342019-10-24 23:55:53 +0000975 outputFormat = GetCommandOptionWithDefault("device-inspect", "format", DEFAULT_DEVICE_INSPECT_FORMAT)
Zack Williamse940c7a2019-08-21 14:25:39 -0700976 }
977 if options.Quiet {
978 outputFormat = "{{.Id}}"
979 }
980
981 result := CommandResult{
982 Format: format.Format(outputFormat),
983 OutputAs: toOutputType(options.OutputAs),
984 NameLimit: options.NameLimit,
985 Data: device,
986 }
987 GenerateOutput(&result)
988 return nil
989}
kesavand12cd8eb2020-01-20 22:25:22 -0500990
991/*Device Port Enable */
992func (options *DevicePortEnable) Execute(args []string) error {
993 conn, err := NewConnection()
994 if err != nil {
995 return err
996 }
997 defer conn.Close()
998
Scott Baker9173ed82020-05-19 08:30:12 -0700999 client := voltha.NewVolthaServiceClient(conn)
kesavand12cd8eb2020-01-20 22:25:22 -05001000
David K. Bainbridge9189c632021-03-26 21:52:21 +00001001 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand12cd8eb2020-01-20 22:25:22 -05001002 defer cancel()
1003
Scott Baker9173ed82020-05-19 08:30:12 -07001004 port := voltha.Port{DeviceId: string(options.Args.Id), PortNo: uint32(options.Args.PortId)}
1005
1006 _, err = client.EnablePort(ctx, &port)
kesavand12cd8eb2020-01-20 22:25:22 -05001007 if err != nil {
1008 Error.Printf("Error enabling port number %v on device Id %s,err=%s\n", options.Args.PortId, options.Args.Id, ErrorToString(err))
1009 return err
kesavand12cd8eb2020-01-20 22:25:22 -05001010 }
1011
1012 return nil
1013}
1014
Scott Baker9173ed82020-05-19 08:30:12 -07001015/*Device Port Disable */
kesavand12cd8eb2020-01-20 22:25:22 -05001016func (options *DevicePortDisable) Execute(args []string) error {
1017 conn, err := NewConnection()
1018 if err != nil {
1019 return err
1020 }
1021 defer conn.Close()
1022
Scott Baker9173ed82020-05-19 08:30:12 -07001023 client := voltha.NewVolthaServiceClient(conn)
1024
David K. Bainbridge9189c632021-03-26 21:52:21 +00001025 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand12cd8eb2020-01-20 22:25:22 -05001026 defer cancel()
1027
Scott Baker9173ed82020-05-19 08:30:12 -07001028 port := voltha.Port{DeviceId: string(options.Args.Id), PortNo: uint32(options.Args.PortId)}
1029
1030 _, err = client.DisablePort(ctx, &port)
kesavand12cd8eb2020-01-20 22:25:22 -05001031 if err != nil {
Scott Baker9173ed82020-05-19 08:30:12 -07001032 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 -05001033 return err
kesavand12cd8eb2020-01-20 22:25:22 -05001034 }
Scott Baker9173ed82020-05-19 08:30:12 -07001035
kesavand12cd8eb2020-01-20 22:25:22 -05001036 return nil
1037}
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08001038
Rohan Agrawald7df3772020-06-29 11:23:36 +00001039func (options *DevicePmConfigSetMaxSkew) Execute(args []string) error {
1040 conn, err := NewConnection()
1041 if err != nil {
1042 return err
1043 }
1044 defer conn.Close()
1045
1046 client := voltha.NewVolthaServiceClient(conn)
1047
David K. Bainbridge9189c632021-03-26 21:52:21 +00001048 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawald7df3772020-06-29 11:23:36 +00001049 defer cancel()
1050
1051 id := voltha.ID{Id: string(options.Args.Id)}
1052
1053 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1054 if err != nil {
1055 return err
1056 }
1057
1058 pmConfigs.MaxSkew = options.Args.MaxSkew
1059
1060 _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs)
1061 if err != nil {
1062 return err
1063 }
1064
1065 return nil
1066}
1067
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001068func (options *DevicePmConfigsGet) Execute(args []string) error {
1069
1070 conn, err := NewConnection()
1071 if err != nil {
1072 return err
1073 }
1074 defer conn.Close()
1075
1076 client := voltha.NewVolthaServiceClient(conn)
1077
David K. Bainbridge9189c632021-03-26 21:52:21 +00001078 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001079 defer cancel()
1080
1081 id := voltha.ID{Id: string(options.Args.Id)}
1082
1083 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1084 if err != nil {
1085 return err
1086 }
1087
1088 outputFormat := CharReplacer.Replace(options.Format)
1089 if outputFormat == "" {
1090 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GET_FORMAT)
1091 }
1092
1093 orderBy := options.OrderBy
1094 if orderBy == "" {
1095 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1096 }
1097
1098 result := CommandResult{
1099 Format: format.Format(outputFormat),
1100 Filter: options.Filter,
1101 OrderBy: orderBy,
1102 OutputAs: toOutputType(options.OutputAs),
1103 NameLimit: options.NameLimit,
1104 Data: pmConfigs,
1105 }
1106
1107 GenerateOutput(&result)
1108 return nil
1109
1110}
1111
1112func (options *DevicePmConfigMetricList) Execute(args []string) error {
1113
1114 conn, err := NewConnection()
1115 if err != nil {
1116 return err
1117 }
1118 defer conn.Close()
1119
1120 client := voltha.NewVolthaServiceClient(conn)
1121
David K. Bainbridge9189c632021-03-26 21:52:21 +00001122 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001123 defer cancel()
1124
1125 id := voltha.ID{Id: string(options.Args.Id)}
1126
1127 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1128 if err != nil {
1129 return err
1130 }
1131
1132 if !pmConfigs.Grouped {
1133 for _, metric := range pmConfigs.Metrics {
1134 if metric.SampleFreq == 0 {
1135 metric.SampleFreq = pmConfigs.DefaultFreq
1136 }
1137 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001138 outputFormat := CharReplacer.Replace(options.Format)
1139 if outputFormat == "" {
1140 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_METRIC_LIST_FORMAT)
1141 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001142
Rohan Agrawalbca69122020-06-17 14:59:03 +00001143 orderBy := options.OrderBy
1144 if orderBy == "" {
1145 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1146 }
1147
1148 result := CommandResult{
1149 Format: format.Format(outputFormat),
1150 Filter: options.Filter,
1151 OrderBy: orderBy,
1152 OutputAs: toOutputType(options.OutputAs),
1153 NameLimit: options.NameLimit,
1154 Data: pmConfigs.Metrics,
1155 }
1156
1157 GenerateOutput(&result)
1158 return nil
1159 } else {
1160 return fmt.Errorf("Device '%s' does not have Non Grouped Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001161 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001162}
1163
1164func (options *DevicePmConfigMetricEnable) Execute(args []string) error {
1165
1166 conn, err := NewConnection()
1167 if err != nil {
1168 return err
1169 }
1170 defer conn.Close()
1171
1172 client := voltha.NewVolthaServiceClient(conn)
1173
David K. Bainbridge9189c632021-03-26 21:52:21 +00001174 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001175 defer cancel()
1176
1177 id := voltha.ID{Id: string(options.Args.Id)}
1178
1179 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1180 if err != nil {
1181 return err
1182 }
1183
1184 if !pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001185 metrics := make(map[string]struct{})
1186 for _, metric := range pmConfigs.Metrics {
1187 metrics[metric.Name] = struct{}{}
1188 }
1189
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001190 for _, metric := range pmConfigs.Metrics {
1191 for _, mName := range options.Args.Metrics {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001192 if _, exist := metrics[string(mName)]; !exist {
1193 return fmt.Errorf("Metric Name '%s' does not exist", mName)
1194 }
1195
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001196 if string(mName) == metric.Name && !metric.Enabled {
1197 metric.Enabled = true
1198 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1199 if err != nil {
1200 return err
1201 }
1202 }
1203 }
1204 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001205 } else {
1206 return fmt.Errorf("Device '%s' does not have Non Grouped Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001207 }
1208 return nil
1209}
1210
1211func (options *DevicePmConfigMetricDisable) Execute(args []string) error {
1212
1213 conn, err := NewConnection()
1214 if err != nil {
1215 return err
1216 }
1217 defer conn.Close()
1218
1219 client := voltha.NewVolthaServiceClient(conn)
1220
David K. Bainbridge9189c632021-03-26 21:52:21 +00001221 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001222 defer cancel()
1223
1224 id := voltha.ID{Id: string(options.Args.Id)}
1225
1226 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1227 if err != nil {
1228 return err
1229 }
1230
1231 if !pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001232 metrics := make(map[string]struct{})
1233 for _, metric := range pmConfigs.Metrics {
1234 metrics[metric.Name] = struct{}{}
1235 }
1236
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001237 for _, metric := range pmConfigs.Metrics {
1238 for _, mName := range options.Args.Metrics {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001239 if _, have := metrics[string(mName)]; !have {
1240 return fmt.Errorf("Metric Name '%s' does not exist", mName)
1241 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001242 if string(mName) == metric.Name && metric.Enabled {
1243 metric.Enabled = false
1244 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1245 if err != nil {
1246 return err
1247 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001248 } else {
1249 return fmt.Errorf("Metric '%s' cannot be disabled", string(mName))
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001250 }
1251 }
1252 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001253 } else {
1254 return fmt.Errorf("Device '%s' does not have Non Grouped Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001255 }
1256 return nil
1257}
1258
1259func (options *DevicePmConfigGroupEnable) Execute(args []string) error {
1260
1261 conn, err := NewConnection()
1262 if err != nil {
1263 return err
1264 }
1265 defer conn.Close()
1266
1267 client := voltha.NewVolthaServiceClient(conn)
1268
David K. Bainbridge9189c632021-03-26 21:52:21 +00001269 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001270 defer cancel()
1271
1272 id := voltha.ID{Id: string(options.Args.Id)}
1273
1274 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1275 if err != nil {
1276 return err
1277 }
1278
1279 if pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001280 groups := make(map[string]struct{})
1281 for _, group := range pmConfigs.Groups {
1282 groups[group.GroupName] = struct{}{}
1283 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001284 for _, group := range pmConfigs.Groups {
Girish Gowdra610acb42021-01-27 13:33:57 -08001285 if _, have := groups[string(options.Args.Group)]; !have {
1286 return fmt.Errorf("Group Name '%s' does not exist", options.Args.Group)
1287 }
1288 if string(options.Args.Group) == group.GroupName && !group.Enabled {
1289 group.Enabled = true
1290 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1291 if err != nil {
1292 return err
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001293 }
1294 }
1295 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001296 } else {
1297 return fmt.Errorf("Device '%s' does not have Group Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001298 }
1299 return nil
1300}
1301
1302func (options *DevicePmConfigGroupDisable) Execute(args []string) error {
1303
1304 conn, err := NewConnection()
1305 if err != nil {
1306 return err
1307 }
1308 defer conn.Close()
1309
1310 client := voltha.NewVolthaServiceClient(conn)
1311
David K. Bainbridge9189c632021-03-26 21:52:21 +00001312 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001313 defer cancel()
1314
1315 id := voltha.ID{Id: string(options.Args.Id)}
1316
1317 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1318 if err != nil {
1319 return err
1320 }
1321
1322 if pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001323 groups := make(map[string]struct{})
1324 for _, group := range pmConfigs.Groups {
1325 groups[group.GroupName] = struct{}{}
1326 }
1327
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001328 for _, group := range pmConfigs.Groups {
Girish Gowdra610acb42021-01-27 13:33:57 -08001329 if _, have := groups[string(options.Args.Group)]; !have {
1330 return fmt.Errorf("Group Name '%s' does not exist", options.Args.Group)
1331 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001332
Girish Gowdra610acb42021-01-27 13:33:57 -08001333 if string(options.Args.Group) == group.GroupName && group.Enabled {
1334 group.Enabled = false
1335 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1336 if err != nil {
1337 return err
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001338 }
1339 }
1340 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001341 } else {
1342 return fmt.Errorf("Device '%s' does not have Group Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001343 }
1344 return nil
1345}
1346
Girish Gowdra610acb42021-01-27 13:33:57 -08001347func (options *DevicePmConfigGroupFrequencySet) Execute(args []string) error {
1348
1349 conn, err := NewConnection()
1350 if err != nil {
1351 return err
1352 }
1353 defer conn.Close()
1354
1355 client := voltha.NewVolthaServiceClient(conn)
1356
David K. Bainbridge9189c632021-03-26 21:52:21 +00001357 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Girish Gowdra610acb42021-01-27 13:33:57 -08001358 defer cancel()
1359
1360 id := voltha.ID{Id: string(options.Args.Id)}
1361
1362 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1363 if err != nil {
1364 return err
1365 }
1366
1367 if pmConfigs.Grouped {
1368 groups := make(map[string]struct{})
1369 for _, group := range pmConfigs.Groups {
1370 groups[group.GroupName] = struct{}{}
1371 }
1372
1373 for _, group := range pmConfigs.Groups {
1374 if _, have := groups[string(options.Args.Group)]; !have {
1375 return fmt.Errorf("group name '%s' does not exist", options.Args.Group)
1376 }
1377
1378 if string(options.Args.Group) == group.GroupName {
1379 if !group.Enabled {
1380 return fmt.Errorf("group '%s' is not enabled", options.Args.Group)
1381 }
1382 group.GroupFreq = uint32(options.Args.Interval.Seconds())
1383 _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs)
1384 if err != nil {
1385 return err
1386 }
1387 }
1388 }
1389 } else {
1390 return fmt.Errorf("device '%s' does not have group metrics", options.Args.Id)
1391 }
1392 return nil
1393}
1394
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001395func (options *DevicePmConfigGroupList) Execute(args []string) error {
1396
1397 conn, err := NewConnection()
1398 if err != nil {
1399 return err
1400 }
1401 defer conn.Close()
1402
1403 client := voltha.NewVolthaServiceClient(conn)
1404
David K. Bainbridge9189c632021-03-26 21:52:21 +00001405 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001406 defer cancel()
1407
1408 id := voltha.ID{Id: string(options.Args.Id)}
1409
1410 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1411 if err != nil {
1412 return err
1413 }
1414
1415 if pmConfigs.Grouped {
1416 for _, group := range pmConfigs.Groups {
1417 if group.GroupFreq == 0 {
1418 group.GroupFreq = pmConfigs.DefaultFreq
1419 }
1420 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001421 outputFormat := CharReplacer.Replace(options.Format)
1422 if outputFormat == "" {
1423 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GROUP_LIST_FORMAT)
1424 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001425
Rohan Agrawalbca69122020-06-17 14:59:03 +00001426 orderBy := options.OrderBy
1427 if orderBy == "" {
1428 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1429 }
1430
1431 result := CommandResult{
1432 Format: format.Format(outputFormat),
1433 Filter: options.Filter,
1434 OrderBy: orderBy,
1435 OutputAs: toOutputType(options.OutputAs),
1436 NameLimit: options.NameLimit,
1437 Data: pmConfigs.Groups,
1438 }
1439
1440 GenerateOutput(&result)
1441 } else {
1442 return fmt.Errorf("Device '%s' does not have Group Metrics", string(options.Args.Id))
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001443 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001444 return nil
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001445}
1446
1447func (options *DevicePmConfigGroupMetricList) Execute(args []string) error {
1448
1449 var metrics []*voltha.PmConfig
1450 conn, err := NewConnection()
1451 if err != nil {
1452 return err
1453 }
1454 defer conn.Close()
1455
1456 client := voltha.NewVolthaServiceClient(conn)
1457
David K. Bainbridge9189c632021-03-26 21:52:21 +00001458 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001459 defer cancel()
1460
1461 id := voltha.ID{Id: string(options.Args.Id)}
1462
1463 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1464 if err != nil {
1465 return err
1466 }
1467
1468 for _, groups := range pmConfigs.Groups {
1469
1470 if string(options.Args.Group) == groups.GroupName {
1471 for _, metric := range groups.Metrics {
1472 if metric.SampleFreq == 0 && groups.GroupFreq == 0 {
1473 metric.SampleFreq = pmConfigs.DefaultFreq
1474 } else {
1475 metric.SampleFreq = groups.GroupFreq
1476 }
1477 }
1478 metrics = groups.Metrics
1479 }
1480 }
1481
1482 outputFormat := CharReplacer.Replace(options.Format)
1483 if outputFormat == "" {
1484 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_METRIC_LIST_FORMAT)
1485 }
1486
1487 orderBy := options.OrderBy
1488 if orderBy == "" {
1489 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1490 }
1491
1492 result := CommandResult{
1493 Format: format.Format(outputFormat),
1494 Filter: options.Filter,
1495 OrderBy: orderBy,
1496 OutputAs: toOutputType(options.OutputAs),
1497 NameLimit: options.NameLimit,
1498 Data: metrics,
1499 }
1500
1501 GenerateOutput(&result)
1502 return nil
1503
1504}
1505
1506func (options *DevicePmConfigFrequencySet) Execute(args []string) error {
1507
1508 conn, err := NewConnection()
1509 if err != nil {
1510 return err
1511 }
1512 defer conn.Close()
1513
1514 client := voltha.NewVolthaServiceClient(conn)
1515
David K. Bainbridge9189c632021-03-26 21:52:21 +00001516 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001517 defer cancel()
1518
1519 id := voltha.ID{Id: string(options.Args.Id)}
1520
1521 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1522 if err != nil {
1523 return err
1524 }
1525
Girish Gowdra610acb42021-01-27 13:33:57 -08001526 pmConfigs.DefaultFreq = uint32(options.Args.Interval.Seconds())
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001527
1528 _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs)
1529 if err != nil {
1530 return err
1531 }
1532
1533 outputFormat := CharReplacer.Replace(options.Format)
1534 if outputFormat == "" {
1535 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GET_FORMAT)
1536 }
1537 if options.Quiet {
1538 outputFormat = "{{.Id}}"
1539 }
1540
1541 result := CommandResult{
1542 Format: format.Format(outputFormat),
1543 OutputAs: toOutputType(options.OutputAs),
1544 NameLimit: options.NameLimit,
1545 Data: pmConfigs,
1546 }
1547
1548 GenerateOutput(&result)
1549 return nil
1550
1551}
1552
kesavand3e2f9f62021-04-22 11:06:38 +05301553func (options *OnuDownloadImage) Execute(args []string) error {
1554
1555 conn, err := NewConnection()
1556 if err != nil {
1557 return err
1558 }
1559 defer conn.Close()
1560
1561 client := voltha.NewVolthaServiceClient(conn)
1562
1563 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1564 defer cancel()
1565
1566 var devIDList []*common.ID
1567 for _, i := range options.Args.IDs {
1568
1569 devIDList = append(devIDList, &common.ID{Id: string(i)})
1570 }
1571
1572 downloadImage := voltha.DeviceImageDownloadRequest{
1573 DeviceId: devIDList,
1574 Image: &voltha.Image{
1575 Url: options.Args.Url,
1576 Crc32: options.Args.Crc,
ssiddiqui7bc89e92021-05-20 20:58:02 +05301577 Vendor: options.Args.Vendor,
kesavand3e2f9f62021-04-22 11:06:38 +05301578 Version: options.Args.ImageVersion,
1579 },
1580 ActivateOnSuccess: options.Args.ActivateOnSuccess,
1581 CommitOnSuccess: options.Args.CommitOnSuccess,
1582 }
1583
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001584 deviceImageResp, err := client.DownloadImageToDevice(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301585 if err != nil {
1586 return err
1587 }
1588
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001589 outputFormat := GetCommandOptionWithDefault("onu-image-download", "format", ONU_IMAGE_STATUS_FORMAT)
1590 // Make sure json output prints an empty list, not "null"
1591 if deviceImageResp.DeviceImageStates == nil {
1592 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1593 }
1594 result := CommandResult{
1595 Format: format.Format(outputFormat),
1596 OutputAs: toOutputType(options.OutputAs),
1597 NameLimit: options.NameLimit,
1598 Data: deviceImageResp.DeviceImageStates,
1599 }
1600 GenerateOutput(&result)
kesavand3e2f9f62021-04-22 11:06:38 +05301601 return nil
1602
1603}
1604
1605func (options *OnuActivateImage) Execute(args []string) error {
1606
1607 conn, err := NewConnection()
1608 if err != nil {
1609 return err
1610 }
1611 defer conn.Close()
1612
1613 client := voltha.NewVolthaServiceClient(conn)
1614
1615 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1616 defer cancel()
1617
1618 var devIDList []*common.ID
1619 for _, i := range options.Args.IDs {
1620
1621 devIDList = append(devIDList, &common.ID{Id: string(i)})
1622 }
1623
1624 downloadImage := voltha.DeviceImageRequest{
1625 DeviceId: devIDList,
1626 Version: options.Args.ImageVersion,
1627 CommitOnSuccess: options.Args.CommitOnSuccess,
1628 }
1629
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001630 deviceImageResp, err := client.ActivateImage(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301631 if err != nil {
1632 return err
1633 }
1634
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001635 outputFormat := GetCommandOptionWithDefault("onu-image-activate", "format", ONU_IMAGE_STATUS_FORMAT)
1636 // Make sure json output prints an empty list, not "null"
1637 if deviceImageResp.DeviceImageStates == nil {
1638 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1639 }
1640 result := CommandResult{
1641 Format: format.Format(outputFormat),
1642 OutputAs: toOutputType(options.OutputAs),
1643 NameLimit: options.NameLimit,
1644 Data: deviceImageResp.DeviceImageStates,
1645 }
1646 GenerateOutput(&result)
1647
kesavand3e2f9f62021-04-22 11:06:38 +05301648 return nil
1649
1650}
1651
1652func (options *OnuAbortUpgradeImage) Execute(args []string) error {
1653
1654 conn, err := NewConnection()
1655 if err != nil {
1656 return err
1657 }
1658 defer conn.Close()
1659
1660 client := voltha.NewVolthaServiceClient(conn)
1661
1662 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1663 defer cancel()
1664
1665 var devIDList []*common.ID
1666 for _, i := range options.Args.IDs {
1667
1668 devIDList = append(devIDList, &common.ID{Id: string(i)})
1669 }
1670
1671 downloadImage := voltha.DeviceImageRequest{
1672 DeviceId: devIDList,
1673 Version: options.Args.ImageVersion,
1674 }
1675
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001676 deviceImageResp, err := client.AbortImageUpgradeToDevice(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301677 if err != nil {
1678 return err
1679 }
1680
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001681 outputFormat := GetCommandOptionWithDefault("onu-image-abort", "format", ONU_IMAGE_STATUS_FORMAT)
1682 // Make sure json output prints an empty list, not "null"
1683 if deviceImageResp.DeviceImageStates == nil {
1684 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1685 }
1686 result := CommandResult{
1687 Format: format.Format(outputFormat),
1688 OutputAs: toOutputType(options.OutputAs),
1689 NameLimit: options.NameLimit,
1690 Data: deviceImageResp.DeviceImageStates,
1691 }
1692 GenerateOutput(&result)
1693
kesavand3e2f9f62021-04-22 11:06:38 +05301694 return nil
1695
1696}
1697
1698func (options *OnuCommitImage) Execute(args []string) error {
1699
1700 conn, err := NewConnection()
1701 if err != nil {
1702 return err
1703 }
1704 defer conn.Close()
1705
1706 client := voltha.NewVolthaServiceClient(conn)
1707
1708 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1709 defer cancel()
1710
1711 var devIDList []*common.ID
1712 for _, i := range options.Args.IDs {
1713
1714 devIDList = append(devIDList, &common.ID{Id: string(i)})
1715 }
1716 downloadImage := voltha.DeviceImageRequest{
1717 DeviceId: devIDList,
1718 Version: options.Args.ImageVersion,
1719 }
1720
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001721 deviceImageResp, err := client.CommitImage(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301722 if err != nil {
1723 return err
1724 }
1725
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001726 outputFormat := GetCommandOptionWithDefault("onu-image-commit", "format", ONU_IMAGE_STATUS_FORMAT)
1727 // Make sure json output prints an empty list, not "null"
1728 if deviceImageResp.DeviceImageStates == nil {
1729 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1730 }
1731 result := CommandResult{
1732 Format: format.Format(outputFormat),
1733 OutputAs: toOutputType(options.OutputAs),
1734 NameLimit: options.NameLimit,
1735 Data: deviceImageResp.DeviceImageStates,
1736 }
1737 GenerateOutput(&result)
1738
kesavand3e2f9f62021-04-22 11:06:38 +05301739 return nil
1740
1741}
1742
1743func (options *OnuListImages) Execute(args []string) error {
1744
1745 conn, err := NewConnection()
1746 if err != nil {
1747 return err
1748 }
1749 defer conn.Close()
1750
1751 client := voltha.NewVolthaServiceClient(conn)
1752
1753 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1754 defer cancel()
1755
1756 id := common.ID{Id: string(options.Args.Id)}
1757
1758 onuImages, err := client.GetOnuImages(ctx, &id)
1759 if err != nil {
1760 return err
1761 }
1762
1763 outputFormat := CharReplacer.Replace(options.Format)
1764 if outputFormat == "" {
1765 outputFormat = GetCommandOptionWithDefault("onu-image-list", "format", ONU_IMAGE_LIST_FORMAT)
1766 }
1767
1768 if options.Quiet {
1769 outputFormat = "{{.Id}}"
1770 }
1771
1772 //TODO orderby
1773
1774 // Make sure json output prints an empty list, not "null"
1775 if onuImages.Items == nil {
1776 onuImages.Items = make([]*voltha.OnuImage, 0)
1777 }
1778
1779 result := CommandResult{
1780 Format: format.Format(outputFormat),
1781 OutputAs: toOutputType(options.OutputAs),
1782 NameLimit: options.NameLimit,
1783 Data: onuImages.Items,
1784 }
1785
1786 GenerateOutput(&result)
1787 return nil
1788
1789}
1790
1791func (options *OnuImageStatus) Execute(args []string) error {
1792
1793 conn, err := NewConnection()
1794 if err != nil {
1795 return err
1796 }
1797 defer conn.Close()
1798
1799 client := voltha.NewVolthaServiceClient(conn)
1800
1801 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1802 defer cancel()
1803
1804 var devIDList []*common.ID
1805 for _, i := range options.Args.IDs {
1806
1807 devIDList = append(devIDList, &common.ID{Id: string(i)})
1808 }
1809
1810 imageStatusReq := voltha.DeviceImageRequest{
1811 DeviceId: devIDList,
1812 Version: options.Args.ImageVersion,
1813 }
1814 imageStatus, err := client.GetImageStatus(ctx, &imageStatusReq)
1815 if err != nil {
1816 return err
1817 }
1818
1819 outputFormat := CharReplacer.Replace(options.Format)
1820 if outputFormat == "" {
1821 outputFormat = GetCommandOptionWithDefault("device-image-list", "format", ONU_IMAGE_STATUS_FORMAT)
1822 }
1823
1824 if options.Quiet {
1825 outputFormat = "{{.Id}}"
1826 }
1827
1828 //TODO orderby
1829
1830 // Make sure json output prints an empty list, not "null"
1831 if imageStatus.DeviceImageStates == nil {
1832 imageStatus.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1833 }
1834
1835 result := CommandResult{
1836 Format: format.Format(outputFormat),
1837 OutputAs: toOutputType(options.OutputAs),
1838 NameLimit: options.NameLimit,
1839 Data: imageStatus.DeviceImageStates,
1840 }
1841
1842 GenerateOutput(&result)
1843 return nil
1844
1845}
1846
Andrea Campanella791d88b2021-01-08 13:29:00 +01001847func (options *DeviceOnuListImages) Execute(args []string) error {
1848
1849 conn, err := NewConnection()
1850 if err != nil {
1851 return err
1852 }
1853 defer conn.Close()
1854
1855 client := voltha.NewVolthaServiceClient(conn)
1856
David K. Bainbridge9189c632021-03-26 21:52:21 +00001857 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Andrea Campanella791d88b2021-01-08 13:29:00 +01001858 defer cancel()
1859
1860 id := common.ID{Id: string(options.Args.Id)}
1861
1862 imageDownloads, err := client.ListImageDownloads(ctx, &id)
1863 if err != nil {
1864 return err
1865 }
1866
1867 outputFormat := CharReplacer.Replace(options.Format)
1868 if outputFormat == "" {
1869 outputFormat = GetCommandOptionWithDefault("device-image-list", "format", DEFAULT_DEVICE_IMAGE_LIST_GET_FORMAT)
1870 }
1871
1872 if options.Quiet {
1873 outputFormat = "{{.Id}}"
1874 }
1875
1876 //TODO orderby
1877
1878 // Make sure json output prints an empty list, not "null"
1879 if imageDownloads.Items == nil {
1880 imageDownloads.Items = make([]*voltha.ImageDownload, 0)
1881 }
1882
1883 result := CommandResult{
1884 Format: format.Format(outputFormat),
1885 OutputAs: toOutputType(options.OutputAs),
1886 NameLimit: options.NameLimit,
1887 Data: imageDownloads.Items,
1888 }
1889
1890 GenerateOutput(&result)
1891 return nil
1892
1893}
1894
1895func (options *DeviceOnuDownloadImage) Execute(args []string) error {
1896
1897 conn, err := NewConnection()
1898 if err != nil {
1899 return err
1900 }
1901 defer conn.Close()
1902
1903 client := voltha.NewVolthaServiceClient(conn)
1904
David K. Bainbridge9189c632021-03-26 21:52:21 +00001905 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Andrea Campanella791d88b2021-01-08 13:29:00 +01001906 defer cancel()
1907
1908 downloadImage := voltha.ImageDownload{
1909 Id: string(options.Args.Id),
1910 Name: options.Args.Name,
1911 Url: options.Args.Url,
1912 Crc: options.Args.Crc,
1913 LocalDir: options.Args.LocalDir,
1914 }
1915
1916 _, err = client.DownloadImage(ctx, &downloadImage)
1917 if err != nil {
1918 return err
1919 }
1920
1921 return nil
1922
1923}
1924
1925func (options *DeviceOnuActivateImageUpdate) Execute(args []string) error {
1926
1927 conn, err := NewConnection()
1928 if err != nil {
1929 return err
1930 }
1931 defer conn.Close()
1932
1933 client := voltha.NewVolthaServiceClient(conn)
1934
David K. Bainbridge9189c632021-03-26 21:52:21 +00001935 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Andrea Campanella791d88b2021-01-08 13:29:00 +01001936 defer cancel()
1937
1938 downloadImage := voltha.ImageDownload{
1939 Id: string(options.Args.Id),
1940 Name: options.Args.Name,
1941 ImageVersion: options.Args.ImageVersion,
1942 SaveConfig: options.Args.SaveConfig,
1943 LocalDir: options.Args.LocalDir,
1944 }
1945
1946 _, err = client.ActivateImageUpdate(ctx, &downloadImage)
1947 if err != nil {
1948 return err
1949 }
1950
1951 return nil
1952
1953}
1954
Scott Baker9173ed82020-05-19 08:30:12 -07001955type ReturnValueRow struct {
1956 Name string `json:"name"`
1957 Result interface{} `json:"result"`
1958}
1959
kesavand8ec4fc02021-01-27 09:10:22 -05001960func (options *DeviceGetPortStats) Execute(args []string) error {
1961 conn, err := NewConnection()
1962 if err != nil {
1963 return err
1964 }
1965 defer conn.Close()
1966 client := extension.NewExtensionClient(conn)
1967 var portType extension.GetOltPortCounters_PortType
1968
1969 if options.Args.PortType == "pon" {
1970 portType = extension.GetOltPortCounters_Port_PON_OLT
1971 } else if options.Args.PortType == "nni" {
1972
1973 portType = extension.GetOltPortCounters_Port_ETHERNET_NNI
1974 } else {
1975 return fmt.Errorf("expected interface type pon/nni, provided %s", options.Args.PortType)
1976 }
1977
1978 singleGetValReq := extension.SingleGetValueRequest{
1979 TargetId: string(options.Args.Id),
1980 Request: &extension.GetValueRequest{
1981 Request: &extension.GetValueRequest_OltPortInfo{
1982 OltPortInfo: &extension.GetOltPortCounters{
1983 PortNo: options.Args.PortNo,
1984 PortType: portType,
1985 },
1986 },
1987 },
1988 }
1989
David K. Bainbridge9189c632021-03-26 21:52:21 +00001990 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand8ec4fc02021-01-27 09:10:22 -05001991 defer cancel()
1992 rv, err := client.GetExtValue(ctx, &singleGetValReq)
1993 if err != nil {
1994 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
1995 return err
1996 }
1997
1998 if rv.Response.Status != extension.GetValueResponse_OK {
1999 return fmt.Errorf("failed to get port stats %v", rv.Response.ErrReason.String())
2000 }
2001
2002 outputFormat := CharReplacer.Replace(options.Format)
2003 if outputFormat == "" {
2004 outputFormat = GetCommandOptionWithDefault("device-get-port-status", "format", DEFAULT_DEVICE_GET_PORT_STATUS_FORMAT)
2005 }
2006
2007 result := CommandResult{
2008 Format: format.Format(outputFormat),
2009 OutputAs: toOutputType(options.OutputAs),
2010 NameLimit: options.NameLimit,
2011 Data: rv.GetResponse().GetPortCoutners(),
2012 }
2013 GenerateOutput(&result)
2014 return nil
2015}
2016
Himani Chawla40acc122021-05-26 18:52:29 +05302017func (options *GetOnuStats) Execute(args []string) error {
2018 conn, err := NewConnection()
2019 if err != nil {
2020 return err
2021 }
2022 defer conn.Close()
2023 client := extension.NewExtensionClient(conn)
2024
2025 singleGetValReq := extension.SingleGetValueRequest{
2026 TargetId: string(options.Args.OltId),
2027 Request: &extension.GetValueRequest{
2028 Request: &extension.GetValueRequest_OnuPonInfo{
2029 OnuPonInfo: &extension.GetOnuCountersRequest{
2030 IntfId: options.Args.IntfId,
2031 OnuId: options.Args.OnuId,
2032 },
2033 },
2034 },
2035 }
2036 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2037 defer cancel()
2038 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2039 if err != nil {
2040 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.OltId, ErrorToString(err))
2041 return err
2042 }
2043
2044 if rv.Response.Status != extension.GetValueResponse_OK {
2045 return fmt.Errorf("failed to get onu stats %v", rv.Response.ErrReason.String())
2046 }
2047 outputFormat := CharReplacer.Replace(options.Format)
2048 data, formatStr := buildOnuStatsOutputFormat(rv.GetResponse().GetOnuPonCounters())
2049 if outputFormat == "" {
2050 outputFormat = GetCommandOptionWithDefault("device-get-onu-status", "format", formatStr)
2051 }
Himani Chawla553a1392021-06-10 23:39:17 +05302052 result := CommandResult{
2053 Format: format.Format(outputFormat),
2054 OutputAs: toOutputType(options.OutputAs),
2055 NameLimit: options.NameLimit,
2056 Data: data,
2057 }
2058 GenerateOutput(&result)
2059 return nil
2060}
Himani Chawla40acc122021-05-26 18:52:29 +05302061
Himani Chawla553a1392021-06-10 23:39:17 +05302062func (options *GetOnuEthernetFrameExtendedPmCounters) Execute(args []string) error {
2063 conn, err := NewConnection()
2064 if err != nil {
2065 return err
2066 }
2067 defer conn.Close()
2068 client := extension.NewExtensionClient(conn)
2069
2070 singleGetValReq := extension.SingleGetValueRequest{
2071 TargetId: string(options.Args.Id),
2072 Request: &extension.GetValueRequest{
2073 Request: &extension.GetValueRequest_OnuInfo{
2074 OnuInfo: &extension.GetOmciEthernetFrameExtendedPmRequest{
2075 OnuDeviceId: string(options.Args.Id),
2076 },
2077 },
2078 },
2079 }
2080 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2081 defer cancel()
2082 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2083 if err != nil {
2084 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2085 return err
2086 }
2087
2088 if rv.Response.Status != extension.GetValueResponse_OK {
2089 return fmt.Errorf("failed to get ethernet frame extended pm counters %v", rv.Response.ErrReason.String())
2090 }
2091 outputFormat := CharReplacer.Replace(options.Format)
2092 data := buildOnuEthernetFrameExtendedPmOutputFormat(rv.GetResponse().GetOnuCounters())
2093 if outputFormat == "" {
2094 outputFormat = GetCommandOptionWithDefault("device-get-onu-status", "format", DEFAULT_ETHERNET_FRAME_EXTENDED_PM_COUNTERS_FORMAT)
2095 }
Himani Chawla40acc122021-05-26 18:52:29 +05302096 result := CommandResult{
2097 Format: format.Format(outputFormat),
2098 OutputAs: toOutputType(options.OutputAs),
2099 NameLimit: options.NameLimit,
2100 Data: data,
2101 }
2102 GenerateOutput(&result)
2103 return nil
2104}
2105
kesavand6d1131f2021-02-05 22:38:15 +05302106func (options *UniStatus) Execute(args []string) error {
2107 conn, err := NewConnection()
2108 if err != nil {
2109 return err
2110 }
2111 defer conn.Close()
2112 client := extension.NewExtensionClient(conn)
2113
2114 singleGetValReq := extension.SingleGetValueRequest{
2115 TargetId: string(options.Args.Id),
2116 Request: &extension.GetValueRequest{
2117 Request: &extension.GetValueRequest_UniInfo{
2118 UniInfo: &extension.GetOnuUniInfoRequest{
2119 UniIndex: options.Args.UniIndex,
2120 },
2121 },
2122 },
2123 }
David K. Bainbridge9189c632021-03-26 21:52:21 +00002124 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand6d1131f2021-02-05 22:38:15 +05302125 defer cancel()
2126 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2127 if err != nil {
2128 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2129 return err
2130 }
2131 if rv.Response.Status != extension.GetValueResponse_OK {
2132 return fmt.Errorf("failed to get uni status %v", rv.Response.ErrReason.String())
2133 }
2134 outputFormat := CharReplacer.Replace(options.Format)
2135 if outputFormat == "" {
2136 outputFormat = GetCommandOptionWithDefault("device-get-uni-status", "format", DEFAULT_DEVICE_GET_UNI_STATUS_FORMAT)
2137 }
2138 result := CommandResult{
2139 Format: format.Format(outputFormat),
2140 OutputAs: toOutputType(options.OutputAs),
2141 NameLimit: options.NameLimit,
2142 Data: rv.GetResponse().GetUniInfo(),
2143 }
2144 GenerateOutput(&result)
2145 return nil
2146}
2147
Girish Gowdra4f5ce7c2021-04-29 18:53:21 -07002148func (options *OnuPonOpticalInfo) Execute(args []string) error {
2149 conn, err := NewConnection()
2150 if err != nil {
2151 return err
2152 }
2153 defer conn.Close()
2154 client := extension.NewExtensionClient(conn)
2155
2156 singleGetValReq := extension.SingleGetValueRequest{
2157 TargetId: string(options.Args.Id),
2158 Request: &extension.GetValueRequest{
2159 Request: &extension.GetValueRequest_OnuOpticalInfo{
2160 OnuOpticalInfo: &extension.GetOnuPonOpticalInfo{},
2161 },
2162 },
2163 }
2164 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2165 defer cancel()
2166 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2167 if err != nil {
2168 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2169 return err
2170 }
2171 if rv.Response.Status != extension.GetValueResponse_OK {
2172 return fmt.Errorf("failed to get onu pon optical info %v", rv.Response.ErrReason.String())
2173 }
2174 outputFormat := CharReplacer.Replace(options.Format)
2175 if outputFormat == "" {
2176 outputFormat = GetCommandOptionWithDefault("device-get-onu-pon-optical-info", "format", DEFAULT_ONU_PON_OPTICAL_INFO_STATUS_FORMAT)
2177 }
2178 result := CommandResult{
2179 Format: format.Format(outputFormat),
2180 OutputAs: toOutputType(options.OutputAs),
2181 NameLimit: options.NameLimit,
2182 Data: rv.GetResponse().GetOnuOpticalInfo(),
2183 }
2184 GenerateOutput(&result)
2185 return nil
2186}
2187
Gamze Abakac857a462021-05-26 13:45:54 +00002188func (options *RxPower) Execute(args []string) error {
2189 conn, err := NewConnection()
2190 if err != nil {
2191 return err
2192 }
2193 defer conn.Close()
2194 client := extension.NewExtensionClient(conn)
2195
2196 singleGetValReq := extension.SingleGetValueRequest{
2197 TargetId: string(options.Args.Id),
2198 Request: &extension.GetValueRequest{
2199 Request: &extension.GetValueRequest_RxPower{
2200 RxPower: &extension.GetRxPowerRequest{
2201 IntfId: options.Args.PortNo,
2202 OnuId: options.Args.OnuNo,
2203 },
2204 },
2205 },
2206 }
2207
2208 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2209 defer cancel()
2210 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2211 if err != nil {
2212 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2213 return err
2214 }
2215 if rv.Response.Status != extension.GetValueResponse_OK {
2216 return fmt.Errorf("failed to get rx power %v", rv.Response.ErrReason.String())
2217 }
2218 outputFormat := CharReplacer.Replace(options.Format)
2219 if outputFormat == "" {
2220 outputFormat = GetCommandOptionWithDefault("device-get-rx-power", "format", DEFAULT_RX_POWER_STATUS_FORMAT)
2221 }
2222 result := CommandResult{
2223 Format: format.Format(outputFormat),
2224 OutputAs: toOutputType(options.OutputAs),
2225 NameLimit: options.NameLimit,
2226 Data: rv.GetResponse().GetRxPower(),
2227 }
2228 GenerateOutput(&result)
2229 return nil
2230}
2231
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002232/*Device get Onu Distance */
2233func (options *DeviceGetExtValue) Execute(args []string) error {
2234 conn, err := NewConnection()
2235 if err != nil {
2236 return err
2237 }
2238 defer conn.Close()
2239
Scott Baker9173ed82020-05-19 08:30:12 -07002240 client := voltha.NewVolthaServiceClient(conn)
2241
2242 valueflag, okay := common.ValueType_Type_value[string(options.Args.Valueflag)]
2243 if !okay {
2244 Error.Printf("Unknown valueflag %s\n", options.Args.Valueflag)
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002245 }
2246
Scott Baker9173ed82020-05-19 08:30:12 -07002247 val := voltha.ValueSpecifier{Id: string(options.Args.Id), Value: common.ValueType_Type(valueflag)}
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002248
David K. Bainbridge9189c632021-03-26 21:52:21 +00002249 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002250 defer cancel()
2251
Scott Baker9173ed82020-05-19 08:30:12 -07002252 rv, err := client.GetExtValue(ctx, &val)
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002253 if err != nil {
2254 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2255 return err
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002256 }
2257
Scott Baker9173ed82020-05-19 08:30:12 -07002258 var rows []ReturnValueRow
2259 for name, num := range common.ValueType_Type_value {
2260 if num == 0 {
2261 // EMPTY is not a real value
2262 continue
2263 }
2264 if (rv.Error & uint32(num)) != 0 {
2265 row := ReturnValueRow{Name: name, Result: "Error"}
2266 rows = append(rows, row)
2267 }
2268 if (rv.Unsupported & uint32(num)) != 0 {
2269 row := ReturnValueRow{Name: name, Result: "Unsupported"}
2270 rows = append(rows, row)
2271 }
2272 if (rv.Set & uint32(num)) != 0 {
2273 switch name {
2274 case "DISTANCE":
2275 row := ReturnValueRow{Name: name, Result: rv.Distance}
2276 rows = append(rows, row)
2277 default:
2278 row := ReturnValueRow{Name: name, Result: "Unimplemented-in-voltctl"}
2279 rows = append(rows, row)
2280 }
2281 }
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002282 }
2283
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002284 outputFormat := CharReplacer.Replace(options.Format)
2285 if outputFormat == "" {
2286 outputFormat = GetCommandOptionWithDefault("device-value-get", "format", DEFAULT_DEVICE_VALUE_GET_FORMAT)
2287 }
2288
2289 result := CommandResult{
2290 Format: format.Format(outputFormat),
2291 OutputAs: toOutputType(options.OutputAs),
2292 NameLimit: options.NameLimit,
Scott Baker9173ed82020-05-19 08:30:12 -07002293 Data: rows,
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002294 }
2295 GenerateOutput(&result)
2296 return nil
2297}