blob: 6b8756ee470a8b742a6472ab89d479a63b54e8f5 [file] [log] [blame]
Zack Williamse940c7a2019-08-21 14:25:39 -07001/*
2 * Copyright 2019-present Ciena Corporation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package commands
17
18import (
19 "context"
20 "fmt"
David Bainbridge7052fe82020-03-25 10:37:00 -070021 "os"
22 "strconv"
23 "strings"
Girish Gowdra610acb42021-01-27 13:33:57 -080024 "time"
David Bainbridge7052fe82020-03-25 10:37:00 -070025
Scott Baker9173ed82020-05-19 08:30:12 -070026 "github.com/golang/protobuf/ptypes/empty"
Zack Williamse940c7a2019-08-21 14:25:39 -070027 flags "github.com/jessevdk/go-flags"
Scott Baker2b0ad652019-08-21 14:57:07 -070028 "github.com/opencord/voltctl/pkg/format"
David K. Bainbridgebd6b2882021-08-26 13:31:02 +000029 "github.com/opencord/voltha-protos/v5/go/common"
30 "github.com/opencord/voltha-protos/v5/go/extension"
31 "github.com/opencord/voltha-protos/v5/go/voltha"
Zack Williamse940c7a2019-08-21 14:25:39 -070032)
33
34const (
David K. Bainbridge89003c42020-02-27 17:22:49 -080035 DEFAULT_DEVICE_FORMAT = "table{{ .Id }}\t{{.Type}}\t{{.Root}}\t{{.ParentId}}\t{{.SerialNumber}}\t{{.AdminState}}\t{{.OperStatus}}\t{{.ConnectStatus}}\t{{.Reason}}"
Hardik Windlass9361bb82022-03-23 05:58:48 +000036 DEFAULT_DEVICE_ORDER = "Type,Id"
Zack Williamse940c7a2019-08-21 14:25:39 -070037 DEFAULT_DEVICE_PORTS_FORMAT = "table{{.PortNo}}\t{{.Label}}\t{{.Type}}\t{{.AdminState}}\t{{.OperStatus}}\t{{.DeviceId}}\t{{.Peers}}"
38 DEFAULT_DEVICE_INSPECT_FORMAT = `ID: {{.Id}}
39 TYPE: {{.Type}}
40 ROOT: {{.Root}}
41 PARENTID: {{.ParentId}}
42 SERIALNUMBER: {{.SerialNumber}}
43 VLAN: {{.Vlan}}
44 ADMINSTATE: {{.AdminState}}
45 OPERSTATUS: {{.OperStatus}}
46 CONNECTSTATUS: {{.ConnectStatus}}`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +000047 DEFAULT_DEVICE_PM_CONFIG_GET_FORMAT = "table{{.DefaultFreq}}\t{{.Grouped}}\t{{.FreqOverride}}"
48 DEFAULT_DEVICE_PM_CONFIG_METRIC_LIST_FORMAT = "table{{.Name}}\t{{.Type}}\t{{.Enabled}}\t{{.SampleFreq}}"
49 DEFAULT_DEVICE_PM_CONFIG_GROUP_LIST_FORMAT = "table{{.GroupName}}\t{{.Enabled}}\t{{.GroupFreq}}"
50 DEFAULT_DEVICE_VALUE_GET_FORMAT = "table{{.Name}}\t{{.Result}}"
Andrea Campanella791d88b2021-01-08 13:29:00 +010051 DEFAULT_DEVICE_IMAGE_LIST_GET_FORMAT = "table{{.Name}}\t{{.Url}}\t{{.Crc}}\t{{.DownloadState}}\t{{.ImageVersion}}\t{{.LocalDir}}\t{{.ImageState}}\t{{.FileSize}}"
ssiddiqui7bc89e92021-05-20 20:58:02 +053052 ONU_IMAGE_LIST_FORMAT = "table{{.Version}}\t{{.IsCommited}}\t{{.IsActive}}\t{{.IsValid}}\t{{.ProductCode}}\t{{.Hash}}"
53 ONU_IMAGE_STATUS_FORMAT = "table{{.DeviceId}}\t{{.ImageState.Version}}\t{{.ImageState.DownloadState}}\t{{.ImageState.Reason}}\t{{.ImageState.ImageState}}\t"
kesavand8ec4fc02021-01-27 09:10:22 -050054 DEFAULT_DEVICE_GET_PORT_STATUS_FORMAT = `
55 TXBYTES: {{.TxBytes}}
56 TXPACKETS: {{.TxPackets}}
57 TXERRPACKETS: {{.TxErrorPackets}}
58 TXBCASTPACKETS: {{.TxBcastPackets}}
59 TXUCASTPACKETS: {{.TxUcastPackets}}
60 TXMCASTPACKETS: {{.TxMcastPackets}}
61 RXBYTES: {{.RxBytes}}
62 RXPACKETS: {{.RxPackets}}
63 RXERRPACKETS: {{.RxErrorPackets}}
64 RXBCASTPACKETS: {{.RxBcastPackets}}
65 RXUCASTPACKETS: {{.RxUcastPackets}}
66 RXMCASTPACKETS: {{.RxMcastPackets}}`
kesavand6d1131f2021-02-05 22:38:15 +053067 DEFAULT_DEVICE_GET_UNI_STATUS_FORMAT = `
68 ADMIN_STATE: {{.AdmState}}
69 OPERATIONAL_STATE: {{.OperState}}
70 CONFIG_IND: {{.ConfigInd}}`
Girish Gowdra4f5ce7c2021-04-29 18:53:21 -070071 DEFAULT_ONU_PON_OPTICAL_INFO_STATUS_FORMAT = `
72 POWER_FEED_VOLTAGE__VOLTS: {{.PowerFeedVoltage}}
73 RECEIVED_OPTICAL_POWER__dBm: {{.ReceivedOpticalPower}}
74 MEAN_OPTICAL_LAUNCH_POWER__dBm: {{.MeanOpticalLaunchPower}}
75 LASER_BIAS_CURRENT__mA: {{.LaserBiasCurrent}}
76 TEMPERATURE__Celsius: {{.Temperature}}`
Gamze Abakac857a462021-05-26 13:45:54 +000077 DEFAULT_RX_POWER_STATUS_FORMAT = `
78 INTF_ID: {{.IntfId}}
79 ONU_ID: {{.OnuId}}
80 STATUS: {{.Status}}
81 FAIL_REASON: {{.FailReason}}
82 RX_POWER : {{.RxPower}}`
Himani Chawla553a1392021-06-10 23:39:17 +053083 DEFAULT_ETHERNET_FRAME_EXTENDED_PM_COUNTERS_FORMAT = `Upstream_Drop_Events: {{.UDropEvents}}
84Upstream_Octets: {{.UOctets}}
85UFrames: {{.UFrames}}
86UBroadcastFrames: {{.UBroadcastFrames}}
87UMulticastFrames: {{.UMulticastFrames}}
88UCrcErroredFrames: {{.UCrcErroredFrames}}
89UUndersizeFrames: {{.UUndersizeFrames}}
90UOversizeFrames: {{.UOversizeFrames}}
91UFrames_64Octets: {{.UFrames_64Octets}}
92UFrames_65To_127Octets: {{.UFrames_65To_127Octets}}
93UFrames_128To_255Octets: {{.UFrames_128To_255Octets}}
94UFrames_256To_511Octets: {{.UFrames_256To_511Octets}}
95UFrames_512To_1023Octets: {{.UFrames_512To_1023Octets}}
96UFrames_1024To_1518Octets: {{.UFrames_1024To_1518Octets}}
97DDropEvents: {{.DDropEvents}}
98DOctets: {{.DOctets}}
99DFrames: {{.DFrames}}
100DBroadcastFrames: {{.DBroadcastFrames}}
101DMulticastFrames: {{.DMulticastFrames}}
102DCrcErroredFrames: {{.DCrcErroredFrames}}
103DUndersizeFrames: {{.DUndersizeFrames}}
104DOversizeFrames: {{.DOversizeFrames}}
105DFrames_64Octets: {{.DFrames_64Octets}}
106DFrames_65To_127Octets: {{.DFrames_65To_127Octets}}
107DFrames_128To_255Octets: {{.DFrames_128To_255Octets}}
108DFrames_256To_511Octets: {{.DFrames_256To_511Octets}}
109DFrames_512To_1023Octets: {{.DFrames_512To_1023Octets}}
Himani Chawlabac0f892021-08-25 17:14:06 +0530110DFrames_1024To_1518Octets: {{.DFrames_1024To_1518Octets}}
111PmFormat: {{.PmFormat}}`
serkantul3d22fc72022-09-14 12:22:56 +0300112 DEFAULT_ONU_OMCI_TX_RX_STATS_FORMAT = `BaseTxArFrames: {{.BaseTxArFrames}}
113BaseRxAkFrames: {{.BaseRxAkFrames}}
114BaseTxNoArFrames: {{.BaseTxNoArFrames}}
115BaseRxNoAkFrames: {{.BaseRxNoAkFrames}}
116ExtTxArFrames: {{.ExtTxArFrames}}
117ExtRxAkFrames: {{.ExtRxAkFrames}}
118ExtTxNoArFrames: {{.ExtTxNoArFrames}}
119ExtRxNoAkFrames: {{.ExtRxNoAkFrames}}
120TxOmciCounterRetries: {{.TxOmciCounterRetries}}
121TxOmciCounterTimeouts: {{.TxOmciCounterTimeouts}}`
praneeth nalmas39c71ad2023-09-27 18:29:04 +0530122 DEFAULT_DEVICE_ALARMS_FORMAT = "table{{ .ClassId }}\t{{.InstanceId}}\t{{.Name}}\t{{.Description}}"
123 DEFAULT_DEVICE_ALARMS_ORDER = "ClassId,InstanceId"
124 DEFAULT_PON_RX_POWER_STATUS_FORMAT = "table{{.OnuSn}}\t{{.Status}}\t{{.FailReason}}\t{{.RxPower}}\t"
Zack Williamse940c7a2019-08-21 14:25:39 -0700125)
126
127type DeviceList struct {
128 ListOutputOptions
129}
130
131type DeviceCreate struct {
David Bainbridge1a514392020-06-23 11:12:51 -0700132 DeviceType string `short:"t" required:"true" long:"devicetype" description:"Device type"`
David Bainbridge835dd0e2020-04-01 10:30:09 -0700133 MACAddress string `short:"m" long:"macaddress" default:"" description:"MAC Address"`
Zack Williamse940c7a2019-08-21 14:25:39 -0700134 IPAddress string `short:"i" long:"ipaddress" default:"" description:"IP Address"`
135 HostAndPort string `short:"H" long:"hostandport" default:"" description:"Host and port"`
136}
137
138type DeviceId string
139
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000140type MetricName string
141type GroupName string
kesavand12cd8eb2020-01-20 22:25:22 -0500142type PortNum uint32
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -0800143type ValueFlag string
kesavand12cd8eb2020-01-20 22:25:22 -0500144
Zack Williamse940c7a2019-08-21 14:25:39 -0700145type DeviceDelete struct {
Himani Chawla9933ddc2020-10-12 23:53:27 +0530146 Force bool `long:"force" description:"Delete device forcefully"`
147 Args struct {
Zack Williamse940c7a2019-08-21 14:25:39 -0700148 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
149 } `positional-args:"yes"`
150}
151
152type DeviceEnable struct {
153 Args struct {
154 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
155 } `positional-args:"yes"`
156}
157
158type DeviceDisable struct {
159 Args struct {
160 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
161 } `positional-args:"yes"`
162}
163
164type DeviceReboot struct {
165 Args struct {
166 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
167 } `positional-args:"yes"`
168}
169
170type DeviceFlowList struct {
171 ListOutputOptions
Maninder045921e2020-09-29 16:46:02 +0530172 FlowIdOptions
Zack Williamse940c7a2019-08-21 14:25:39 -0700173 Args struct {
174 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
175 } `positional-args:"yes"`
176}
177
Himani Chawla3c161c62021-05-13 16:36:51 +0530178type DeviceFlowGroupList struct {
179 ListOutputOptions
180 GroupListOptions
181 Args struct {
182 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
183 } `positional-args:"yes"`
184}
Zack Williamse940c7a2019-08-21 14:25:39 -0700185type DevicePortList struct {
186 ListOutputOptions
187 Args struct {
188 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
189 } `positional-args:"yes"`
190}
191
192type DeviceInspect struct {
193 OutputOptionsJson
194 Args struct {
195 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
196 } `positional-args:"yes"`
197}
198
kesavand12cd8eb2020-01-20 22:25:22 -0500199type DevicePortEnable struct {
200 Args struct {
201 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
202 PortId PortNum `positional-arg-name:"PORT_NUMBER" required:"yes"`
203 } `positional-args:"yes"`
204}
205
206type DevicePortDisable struct {
207 Args struct {
208 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
209 PortId PortNum `positional-arg-name:"PORT_NUMBER" required:"yes"`
210 } `positional-args:"yes"`
211}
212
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000213type DevicePmConfigsGet struct {
214 ListOutputOptions
215 Args struct {
216 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
217 } `positional-args:"yes"`
218}
219
220type DevicePmConfigMetricList struct {
221 ListOutputOptions
222 Args struct {
223 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
224 } `positional-args:"yes"`
225}
226
227type DevicePmConfigGroupList struct {
228 ListOutputOptions
229 Args struct {
230 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
231 } `positional-args:"yes"`
232}
233
234type DevicePmConfigGroupMetricList struct {
235 ListOutputOptions
236 Args struct {
237 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
238 Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"`
239 } `positional-args:"yes"`
240}
241
242type DevicePmConfigFrequencySet struct {
243 OutputOptions
244 Args struct {
Girish Gowdra610acb42021-01-27 13:33:57 -0800245 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
246 Interval time.Duration `positional-arg-name:"INTERVAL" required:"yes"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000247 } `positional-args:"yes"`
248}
249
250type DevicePmConfigMetricEnable struct {
251 Args struct {
252 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
253 Metrics []MetricName `positional-arg-name:"METRIC_NAME" required:"yes"`
254 } `positional-args:"yes"`
255}
256
257type DevicePmConfigMetricDisable struct {
258 Args struct {
259 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
260 Metrics []MetricName `positional-arg-name:"METRIC_NAME" required:"yes"`
261 } `positional-args:"yes"`
262}
263
264type DevicePmConfigGroupEnable struct {
265 Args struct {
Girish Gowdra610acb42021-01-27 13:33:57 -0800266 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
267 Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000268 } `positional-args:"yes"`
269}
270
271type DevicePmConfigGroupDisable struct {
272 Args struct {
Girish Gowdra610acb42021-01-27 13:33:57 -0800273 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
274 Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"`
275 } `positional-args:"yes"`
276}
277
278type DevicePmConfigGroupFrequencySet struct {
279 OutputOptions
280 Args struct {
281 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
282 Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"`
283 Interval time.Duration `positional-arg-name:"INTERVAL" required:"yes"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000284 } `positional-args:"yes"`
285}
286
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -0800287type DeviceGetExtValue struct {
288 ListOutputOptions
289 Args struct {
290 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
291 Valueflag ValueFlag `positional-arg-name:"VALUE_FLAG" required:"yes"`
292 } `positional-args:"yes"`
293}
Rohan Agrawald7df3772020-06-29 11:23:36 +0000294
295type DevicePmConfigSetMaxSkew struct {
296 Args struct {
297 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
298 MaxSkew uint32 `positional-arg-name:"MAX_SKEW" required:"yes"`
299 } `positional-args:"yes"`
300}
301
Andrea Campanella791d88b2021-01-08 13:29:00 +0100302type DeviceOnuListImages struct {
303 ListOutputOptions
304 Args struct {
305 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
306 } `positional-args:"yes"`
307}
308
309type DeviceOnuDownloadImage struct {
310 Args struct {
311 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
312 Name string `positional-arg-name:"IMAGE_NAME" required:"yes"`
313 Url string `positional-arg-name:"IMAGE_URL" required:"yes"`
314 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
315 Crc uint32 `positional-arg-name:"IMAGE_CRC" required:"yes"`
316 LocalDir string `positional-arg-name:"IMAGE_LOCAL_DIRECTORY"`
317 } `positional-args:"yes"`
318}
319
320type DeviceOnuActivateImageUpdate struct {
321 Args struct {
322 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
323 Name string `positional-arg-name:"IMAGE_NAME" required:"yes"`
324 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
325 SaveConfig bool `positional-arg-name:"SAVE_EXISTING_CONFIG"`
326 LocalDir string `positional-arg-name:"IMAGE_LOCAL_DIRECTORY"`
Andrea Campanella7b2ecf42021-02-25 12:27:15 +0100327 } `positional-args:"yes"`
kesavand8ec4fc02021-01-27 09:10:22 -0500328}
kesavand3e2f9f62021-04-22 11:06:38 +0530329
330type OnuDownloadImage 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 Url string `positional-arg-name:"IMAGE_URL" required:"yes"`
ssiddiqui7bc89e92021-05-20 20:58:02 +0530335 Vendor string `positional-arg-name:"IMAGE_VENDOR"`
kesavand3e2f9f62021-04-22 11:06:38 +0530336 ActivateOnSuccess bool `positional-arg-name:"IMAGE_ACTIVATE_ON_SUCCESS"`
337 CommitOnSuccess bool `positional-arg-name:"IMAGE_COMMIT_ON_SUCCESS"`
338 Crc uint32 `positional-arg-name:"IMAGE_CRC"`
339 IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
340 } `positional-args:"yes"`
341}
342
343type OnuActivateImage struct {
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +0200344 ListOutputOptions
kesavand3e2f9f62021-04-22 11:06:38 +0530345 Args struct {
346 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
347 CommitOnSuccess bool `positional-arg-name:"IMAGE_COMMIT_ON_SUCCESS"`
348 IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
349 } `positional-args:"yes"`
350}
351
352type OnuAbortUpgradeImage struct {
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +0200353 ListOutputOptions
kesavand3e2f9f62021-04-22 11:06:38 +0530354 Args struct {
355 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
356 IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
357 } `positional-args:"yes"`
358}
359
360type OnuCommitImage struct {
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +0200361 ListOutputOptions
kesavand3e2f9f62021-04-22 11:06:38 +0530362 Args struct {
363 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
364 IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
365 } `positional-args:"yes"`
366}
367
368type OnuImageStatus struct {
369 ListOutputOptions
370 Args struct {
371 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
Elia Battiston859f3e62022-02-08 15:57:52 +0100372 IDs []DeviceId `positional-arg-name:"DEVICE_ID"`
kesavand3e2f9f62021-04-22 11:06:38 +0530373 } `positional-args:"yes"`
374}
375
376type OnuListImages struct {
377 ListOutputOptions
378 Args struct {
379 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
380 } `positional-args:"yes"`
381}
382
kesavand8ec4fc02021-01-27 09:10:22 -0500383type DeviceGetPortStats struct {
384 ListOutputOptions
385 Args struct {
386 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
387 PortNo uint32 `positional-arg-name:"PORT_NO" required:"yes"`
388 PortType string `positional-arg-name:"PORT_TYPE" required:"yes"`
Andrea Campanella791d88b2021-01-08 13:29:00 +0100389 } `positional-args:"yes"`
390}
kesavand6d1131f2021-02-05 22:38:15 +0530391type UniStatus struct {
392 ListOutputOptions
393 Args struct {
394 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
395 UniIndex uint32 `positional-arg-name:"UNI_INDEX" required:"yes"`
396 } `positional-args:"yes"`
397}
Girish Gowdra4f5ce7c2021-04-29 18:53:21 -0700398type OnuPonOpticalInfo struct {
399 ListOutputOptions
400 Args struct {
401 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
402 } `positional-args:"yes"`
403}
Himani Chawla40acc122021-05-26 18:52:29 +0530404
405type GetOnuStats struct {
406 ListOutputOptions
407 Args struct {
408 OltId DeviceId `positional-arg-name:"OLT_DEVICE_ID" required:"yes"`
409 IntfId uint32 `positional-arg-name:"PON_INTF_ID" required:"yes"`
410 OnuId uint32 `positional-arg-name:"ONU_ID" required:"yes"`
411 } `positional-args:"yes"`
412}
413
Himani Chawla553a1392021-06-10 23:39:17 +0530414type GetOnuEthernetFrameExtendedPmCounters struct {
415 ListOutputOptions
Himani Chawla806aa892021-08-30 15:51:46 +0530416 Reset bool `long:"reset" description:"Reset the counters"`
417 Args struct {
418 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
419 UniIndex *uint32 `positional-arg-name:"UNI_INDEX"`
Himani Chawla553a1392021-06-10 23:39:17 +0530420 } `positional-args:"yes"`
421}
422
Gamze Abakac857a462021-05-26 13:45:54 +0000423type RxPower struct {
424 ListOutputOptions
425 Args struct {
426 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
427 PortNo uint32 `positional-arg-name:"PORT_NO" required:"yes"`
428 OnuNo uint32 `positional-arg-name:"ONU_NO" required:"yes"`
429 } `positional-args:"yes"`
430}
431
praneeth nalmas39c71ad2023-09-27 18:29:04 +0530432type PonRxPower struct {
433 ListOutputOptions
434 Args struct {
435 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
436 PortLabel string `positional-arg-name:"PORT_LABEL" required:"yes"`
437 SerialNo string `positional-arg-name:"ONU_SERIAL_NUMBER"`
438 } `positional-args:"yes"`
439}
440
serkantul3d22fc72022-09-14 12:22:56 +0300441type OnuOmciTxRxStats struct {
442 ListOutputOptions
443 Args struct {
444 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
445 } `positional-args:"yes"`
446}
447
praneeth nalmas1dd094c2022-12-22 14:15:13 +0530448type GetOnuOmciActiveAlarms struct {
449 ListOutputOptions
450 Args struct {
451 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
452 } `positional-args:"yes"`
453}
454
Zack Williamse940c7a2019-08-21 14:25:39 -0700455type DeviceOpts struct {
Himani Chawla3c161c62021-05-13 16:36:51 +0530456 List DeviceList `command:"list"`
457 Create DeviceCreate `command:"create"`
458 Delete DeviceDelete `command:"delete"`
459 Enable DeviceEnable `command:"enable"`
460 Disable DeviceDisable `command:"disable"`
461 Flows DeviceFlowList `command:"flows"`
462 Groups DeviceFlowGroupList `command:"groups"`
kesavand12cd8eb2020-01-20 22:25:22 -0500463 Port struct {
464 List DevicePortList `command:"list"`
465 Enable DevicePortEnable `command:"enable"`
466 Disable DevicePortDisable `command:"disable"`
467 } `command:"port"`
468 Inspect DeviceInspect `command:"inspect"`
469 Reboot DeviceReboot `command:"reboot"`
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -0800470 Value struct {
471 Get DeviceGetExtValue `command:"get"`
472 } `command:"value"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000473 PmConfig struct {
Rohan Agrawald7df3772020-06-29 11:23:36 +0000474 Get DevicePmConfigsGet `command:"get"`
475 MaxSkew struct {
476 Set DevicePmConfigSetMaxSkew `command:"set"`
477 } `command:"maxskew"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000478 Frequency struct {
479 Set DevicePmConfigFrequencySet `command:"set"`
480 } `command:"frequency"`
481 Metric struct {
482 List DevicePmConfigMetricList `command:"list"`
483 Enable DevicePmConfigMetricEnable `command:"enable"`
484 Disable DevicePmConfigMetricDisable `command:"disable"`
485 } `command:"metric"`
486 Group struct {
Girish Gowdra610acb42021-01-27 13:33:57 -0800487 List DevicePmConfigGroupList `command:"list"`
488 Enable DevicePmConfigGroupEnable `command:"enable"`
489 Disable DevicePmConfigGroupDisable `command:"disable"`
490 Set DevicePmConfigGroupFrequencySet `command:"set"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000491 } `command:"group"`
492 GroupMetric struct {
493 List DevicePmConfigGroupMetricList `command:"list"`
494 } `command:"groupmetric"`
495 } `command:"pmconfig"`
Andrea Campanella791d88b2021-01-08 13:29:00 +0100496 Image struct {
497 Get DeviceOnuListImages `command:"list"`
498 Download DeviceOnuDownloadImage `command:"download"`
499 Activate DeviceOnuActivateImageUpdate `command:"activate"`
500 } `command:"image"`
kesavand3e2f9f62021-04-22 11:06:38 +0530501 DownloadImage struct {
502 Download OnuDownloadImage `command:"download"`
503 Activate OnuActivateImage `command:"activate"`
504 Commit OnuCommitImage `command:"commit"`
505 AbortUpgrade OnuAbortUpgradeImage `command:"abort"`
506 Status OnuImageStatus `command:"status"`
507 List OnuListImages `command:"list" `
508 } `command:"onuimage"`
kesavand8ec4fc02021-01-27 09:10:22 -0500509 GetExtVal struct {
Himani Chawla553a1392021-06-10 23:39:17 +0530510 Stats DeviceGetPortStats `command:"portstats"`
511 UniStatus UniStatus `command:"unistatus"`
512 OpticalInfo OnuPonOpticalInfo `command:"onu_pon_optical_info"`
513 OnuStats GetOnuStats `command:"onu_stats"`
514 EthernetFrameExtendedPm GetOnuEthernetFrameExtendedPmCounters `command:"ethernet_frame_extended_pm"`
515 RxPower RxPower `command:"rxpower"`
serkantul3d22fc72022-09-14 12:22:56 +0300516 OnuOmciStats OnuOmciTxRxStats `command:"onu_omci_stats"`
praneeth nalmas1dd094c2022-12-22 14:15:13 +0530517 OnuOmciActiveAlarms GetOnuOmciActiveAlarms `command:"onu_omci_active_alarms"`
praneeth nalmas39c71ad2023-09-27 18:29:04 +0530518 PonRxPower PonRxPower `command:"pon_rx_power"`
kesavand8ec4fc02021-01-27 09:10:22 -0500519 } `command:"getextval"`
Zack Williamse940c7a2019-08-21 14:25:39 -0700520}
521
522var deviceOpts = DeviceOpts{}
523
524func RegisterDeviceCommands(parser *flags.Parser) {
David Bainbridge12f036f2019-10-15 22:09:04 +0000525 if _, err := parser.AddCommand("device", "device commands", "Commands to query and manipulate VOLTHA devices", &deviceOpts); err != nil {
David Bainbridgea6722342019-10-24 23:55:53 +0000526 Error.Fatalf("Unexpected error while attempting to register device commands : %s", err)
David Bainbridge12f036f2019-10-15 22:09:04 +0000527 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700528}
529
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000530func (i *MetricName) Complete(match string) []flags.Completion {
531 conn, err := NewConnection()
532 if err != nil {
533 return nil
534 }
535 defer conn.Close()
536
537 client := voltha.NewVolthaServiceClient(conn)
538
539 var deviceId string
540found:
541 for i := len(os.Args) - 1; i >= 0; i -= 1 {
542 switch os.Args[i] {
543 case "enable":
544 fallthrough
545 case "disable":
546 if len(os.Args) > i+1 {
547 deviceId = os.Args[i+1]
548 } else {
549 return nil
550 }
551 break found
552 default:
553 }
554 }
555
556 if len(deviceId) == 0 {
557 return nil
558 }
559
David K. Bainbridge9189c632021-03-26 21:52:21 +0000560 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000561 defer cancel()
562
563 id := voltha.ID{Id: string(deviceId)}
564
565 pmconfigs, err := client.ListDevicePmConfigs(ctx, &id)
566
567 if err != nil {
568 return nil
569 }
570
571 list := make([]flags.Completion, 0)
572 for _, metrics := range pmconfigs.Metrics {
573 if strings.HasPrefix(metrics.Name, match) {
574 list = append(list, flags.Completion{Item: metrics.Name})
575 }
576 }
577
578 return list
579}
580
581func (i *GroupName) Complete(match string) []flags.Completion {
582 conn, err := NewConnection()
583 if err != nil {
584 return nil
585 }
586 defer conn.Close()
587
588 client := voltha.NewVolthaServiceClient(conn)
589
590 var deviceId string
591found:
592 for i := len(os.Args) - 1; i >= 0; i -= 1 {
593 switch os.Args[i] {
594 case "list":
595 fallthrough
596 case "enable":
597 fallthrough
598 case "disable":
599 if len(os.Args) > i+1 {
600 deviceId = os.Args[i+1]
601 } else {
602 return nil
603 }
604 break found
605 default:
606 }
607 }
608
609 if len(deviceId) == 0 {
610 return nil
611 }
612
David K. Bainbridge9189c632021-03-26 21:52:21 +0000613 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000614 defer cancel()
615
616 id := voltha.ID{Id: string(deviceId)}
617
618 pmconfigs, err := client.ListDevicePmConfigs(ctx, &id)
619
620 if err != nil {
621 return nil
622 }
623
624 list := make([]flags.Completion, 0)
625 for _, group := range pmconfigs.Groups {
626 if strings.HasPrefix(group.GroupName, match) {
627 list = append(list, flags.Completion{Item: group.GroupName})
628 }
629 }
630 return list
631}
632
kesavand12cd8eb2020-01-20 22:25:22 -0500633func (i *PortNum) Complete(match string) []flags.Completion {
634 conn, err := NewConnection()
635 if err != nil {
636 return nil
637 }
638 defer conn.Close()
639
Scott Baker9173ed82020-05-19 08:30:12 -0700640 client := voltha.NewVolthaServiceClient(conn)
kesavand12cd8eb2020-01-20 22:25:22 -0500641
642 /*
643 * The command line args when completing for PortNum will be a DeviceId
644 * followed by one or more PortNums. So walk the argument list from the
645 * end and find the first argument that is enable/disable as those are
646 * the subcommands that come before the positional arguments. It would
647 * be nice if this package gave us the list of optional arguments
648 * already parsed.
649 */
650 var deviceId string
651found:
652 for i := len(os.Args) - 1; i >= 0; i -= 1 {
653 switch os.Args[i] {
654 case "enable":
655 fallthrough
656 case "disable":
657 if len(os.Args) > i+1 {
658 deviceId = os.Args[i+1]
659 } else {
660 return nil
661 }
662 break found
663 default:
664 }
665 }
666
667 if len(deviceId) == 0 {
668 return nil
669 }
670
David K. Bainbridge9189c632021-03-26 21:52:21 +0000671 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand12cd8eb2020-01-20 22:25:22 -0500672 defer cancel()
kesavand12cd8eb2020-01-20 22:25:22 -0500673
Scott Baker9173ed82020-05-19 08:30:12 -0700674 id := voltha.ID{Id: string(deviceId)}
kesavand12cd8eb2020-01-20 22:25:22 -0500675
Scott Baker9173ed82020-05-19 08:30:12 -0700676 ports, err := client.ListDevicePorts(ctx, &id)
kesavand12cd8eb2020-01-20 22:25:22 -0500677 if err != nil {
678 return nil
679 }
680
681 list := make([]flags.Completion, 0)
Scott Baker9173ed82020-05-19 08:30:12 -0700682 for _, item := range ports.Items {
683 pn := strconv.FormatUint(uint64(item.PortNo), 10)
kesavand12cd8eb2020-01-20 22:25:22 -0500684 if strings.HasPrefix(pn, match) {
685 list = append(list, flags.Completion{Item: pn})
686 }
687 }
688
689 return list
690}
691
Zack Williamse940c7a2019-08-21 14:25:39 -0700692func (i *DeviceId) Complete(match string) []flags.Completion {
693 conn, err := NewConnection()
694 if err != nil {
695 return nil
696 }
697 defer conn.Close()
698
Scott Baker9173ed82020-05-19 08:30:12 -0700699 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700700
David K. Bainbridge9189c632021-03-26 21:52:21 +0000701 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700702 defer cancel()
703
Scott Baker9173ed82020-05-19 08:30:12 -0700704 devices, err := client.ListDevices(ctx, &empty.Empty{})
Zack Williamse940c7a2019-08-21 14:25:39 -0700705 if err != nil {
706 return nil
707 }
708
709 list := make([]flags.Completion, 0)
Scott Baker9173ed82020-05-19 08:30:12 -0700710 for _, item := range devices.Items {
711 if strings.HasPrefix(item.Id, match) {
712 list = append(list, flags.Completion{Item: item.Id})
Zack Williamse940c7a2019-08-21 14:25:39 -0700713 }
714 }
715
716 return list
717}
718
719func (options *DeviceList) Execute(args []string) error {
720
721 conn, err := NewConnection()
722 if err != nil {
723 return err
724 }
725 defer conn.Close()
726
Scott Baker9173ed82020-05-19 08:30:12 -0700727 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700728
David K. Bainbridge9189c632021-03-26 21:52:21 +0000729 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700730 defer cancel()
731
Scott Baker9173ed82020-05-19 08:30:12 -0700732 devices, err := client.ListDevices(ctx, &empty.Empty{})
Zack Williamse940c7a2019-08-21 14:25:39 -0700733 if err != nil {
734 return err
735 }
736
737 outputFormat := CharReplacer.Replace(options.Format)
738 if outputFormat == "" {
David Bainbridgea6722342019-10-24 23:55:53 +0000739 outputFormat = GetCommandOptionWithDefault("device-list", "format", DEFAULT_DEVICE_FORMAT)
Zack Williamse940c7a2019-08-21 14:25:39 -0700740 }
741 if options.Quiet {
742 outputFormat = "{{.Id}}"
743 }
744
David Bainbridgea6722342019-10-24 23:55:53 +0000745 orderBy := options.OrderBy
746 if orderBy == "" {
Hardik Windlass9361bb82022-03-23 05:58:48 +0000747 orderBy = GetCommandOptionWithDefault("device-list", "order", DEFAULT_DEVICE_ORDER)
David Bainbridgea6722342019-10-24 23:55:53 +0000748 }
749
Scott Baker9173ed82020-05-19 08:30:12 -0700750 // Make sure json output prints an empty list, not "null"
751 if devices.Items == nil {
752 devices.Items = make([]*voltha.Device, 0)
Zack Williamse940c7a2019-08-21 14:25:39 -0700753 }
754
755 result := CommandResult{
756 Format: format.Format(outputFormat),
757 Filter: options.Filter,
David Bainbridgea6722342019-10-24 23:55:53 +0000758 OrderBy: orderBy,
Zack Williamse940c7a2019-08-21 14:25:39 -0700759 OutputAs: toOutputType(options.OutputAs),
760 NameLimit: options.NameLimit,
Scott Baker9173ed82020-05-19 08:30:12 -0700761 Data: devices.Items,
Zack Williamse940c7a2019-08-21 14:25:39 -0700762 }
763
764 GenerateOutput(&result)
765 return nil
766}
767
768func (options *DeviceCreate) Execute(args []string) error {
769
Scott Baker9173ed82020-05-19 08:30:12 -0700770 device := voltha.Device{}
Zack Williamse940c7a2019-08-21 14:25:39 -0700771 if options.HostAndPort != "" {
Scott Baker9173ed82020-05-19 08:30:12 -0700772 device.Address = &voltha.Device_HostAndPort{HostAndPort: options.HostAndPort}
Zack Williamse940c7a2019-08-21 14:25:39 -0700773 } else if options.IPAddress != "" {
Scott Baker9173ed82020-05-19 08:30:12 -0700774 device.Address = &voltha.Device_Ipv4Address{Ipv4Address: options.IPAddress}
Hardik Windlassce1de342020-02-04 21:58:07 +0000775 }
776 if options.MACAddress != "" {
Scott Baker9173ed82020-05-19 08:30:12 -0700777 device.MacAddress = strings.ToLower(options.MACAddress)
Zack Williamse940c7a2019-08-21 14:25:39 -0700778 }
779 if options.DeviceType != "" {
Scott Baker9173ed82020-05-19 08:30:12 -0700780 device.Type = options.DeviceType
Zack Williamse940c7a2019-08-21 14:25:39 -0700781 }
782
783 conn, err := NewConnection()
784 if err != nil {
785 return err
786 }
787 defer conn.Close()
788
Scott Baker9173ed82020-05-19 08:30:12 -0700789 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700790
David K. Bainbridge9189c632021-03-26 21:52:21 +0000791 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700792 defer cancel()
793
Scott Baker9173ed82020-05-19 08:30:12 -0700794 createdDevice, err := client.CreateDevice(ctx, &device)
Zack Williamse940c7a2019-08-21 14:25:39 -0700795 if err != nil {
796 return err
Zack Williamse940c7a2019-08-21 14:25:39 -0700797 }
798
Scott Baker9173ed82020-05-19 08:30:12 -0700799 fmt.Printf("%s\n", createdDevice.Id)
Zack Williamse940c7a2019-08-21 14:25:39 -0700800
801 return nil
802}
803
804func (options *DeviceDelete) Execute(args []string) error {
805
806 conn, err := NewConnection()
807 if err != nil {
808 return err
809 }
810 defer conn.Close()
811
Scott Baker9173ed82020-05-19 08:30:12 -0700812 client := voltha.NewVolthaServiceClient(conn)
David Bainbridge7052fe82020-03-25 10:37:00 -0700813 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -0700814 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +0000815 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700816 defer cancel()
817
Scott Baker9173ed82020-05-19 08:30:12 -0700818 id := voltha.ID{Id: string(i)}
Himani Chawla9933ddc2020-10-12 23:53:27 +0530819 if options.Force {
820 _, err = client.ForceDeleteDevice(ctx, &id)
821 } else {
822 _, err = client.DeleteDevice(ctx, &id)
823 }
Scott Baker9173ed82020-05-19 08:30:12 -0700824
Zack Williamse940c7a2019-08-21 14:25:39 -0700825 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +0000826 Error.Printf("Error while deleting '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -0700827 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -0700828 continue
Zack Williamse940c7a2019-08-21 14:25:39 -0700829 }
830 fmt.Printf("%s\n", i)
831 }
832
David Bainbridge7052fe82020-03-25 10:37:00 -0700833 if lastErr != nil {
834 return NoReportErr
835 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700836 return nil
837}
838
839func (options *DeviceEnable) Execute(args []string) error {
840 conn, err := NewConnection()
841 if err != nil {
842 return err
843 }
844 defer conn.Close()
845
Scott Baker9173ed82020-05-19 08:30:12 -0700846 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700847
David Bainbridge7052fe82020-03-25 10:37:00 -0700848 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -0700849 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +0000850 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700851 defer cancel()
852
Scott Baker9173ed82020-05-19 08:30:12 -0700853 id := voltha.ID{Id: string(i)}
854
855 _, err := client.EnableDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -0700856 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +0000857 Error.Printf("Error while enabling '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -0700858 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -0700859 continue
Zack Williamse940c7a2019-08-21 14:25:39 -0700860 }
861 fmt.Printf("%s\n", i)
862 }
863
David Bainbridge7052fe82020-03-25 10:37:00 -0700864 if lastErr != nil {
865 return NoReportErr
866 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700867 return nil
868}
869
870func (options *DeviceDisable) Execute(args []string) error {
871 conn, err := NewConnection()
872 if err != nil {
873 return err
874 }
875 defer conn.Close()
876
Scott Baker9173ed82020-05-19 08:30:12 -0700877 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700878
David Bainbridge7052fe82020-03-25 10:37:00 -0700879 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -0700880 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +0000881 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700882 defer cancel()
883
Scott Baker9173ed82020-05-19 08:30:12 -0700884 id := voltha.ID{Id: string(i)}
885
886 _, err := client.DisableDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -0700887 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +0000888 Error.Printf("Error while disabling '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -0700889 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -0700890 continue
Zack Williamse940c7a2019-08-21 14:25:39 -0700891 }
892 fmt.Printf("%s\n", i)
893 }
894
David Bainbridge7052fe82020-03-25 10:37:00 -0700895 if lastErr != nil {
896 return NoReportErr
897 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700898 return nil
899}
900
901func (options *DeviceReboot) Execute(args []string) error {
902 conn, err := NewConnection()
903 if err != nil {
904 return err
905 }
906 defer conn.Close()
907
Scott Baker9173ed82020-05-19 08:30:12 -0700908 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700909
David Bainbridge7052fe82020-03-25 10:37:00 -0700910 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -0700911 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +0000912 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700913 defer cancel()
914
Scott Baker9173ed82020-05-19 08:30:12 -0700915 id := voltha.ID{Id: string(i)}
916
917 _, err := client.RebootDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -0700918 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +0000919 Error.Printf("Error while rebooting '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -0700920 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -0700921 continue
Zack Williamse940c7a2019-08-21 14:25:39 -0700922 }
923 fmt.Printf("%s\n", i)
924 }
925
David Bainbridge7052fe82020-03-25 10:37:00 -0700926 if lastErr != nil {
927 return NoReportErr
928 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700929 return nil
930}
931
932func (options *DevicePortList) Execute(args []string) error {
933
934 conn, err := NewConnection()
935 if err != nil {
936 return err
937 }
938 defer conn.Close()
939
Scott Baker9173ed82020-05-19 08:30:12 -0700940 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700941
David K. Bainbridge9189c632021-03-26 21:52:21 +0000942 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700943 defer cancel()
944
Scott Baker9173ed82020-05-19 08:30:12 -0700945 id := voltha.ID{Id: string(options.Args.Id)}
Zack Williamse940c7a2019-08-21 14:25:39 -0700946
Scott Baker9173ed82020-05-19 08:30:12 -0700947 ports, err := client.ListDevicePorts(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -0700948 if err != nil {
949 return err
950 }
951
952 outputFormat := CharReplacer.Replace(options.Format)
953 if outputFormat == "" {
David Bainbridgea6722342019-10-24 23:55:53 +0000954 outputFormat = GetCommandOptionWithDefault("device-ports", "format", DEFAULT_DEVICE_PORTS_FORMAT)
Zack Williamse940c7a2019-08-21 14:25:39 -0700955 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700956
David Bainbridgea6722342019-10-24 23:55:53 +0000957 orderBy := options.OrderBy
958 if orderBy == "" {
959 orderBy = GetCommandOptionWithDefault("device-ports", "order", "")
960 }
961
Zack Williamse940c7a2019-08-21 14:25:39 -0700962 result := CommandResult{
963 Format: format.Format(outputFormat),
964 Filter: options.Filter,
David Bainbridgea6722342019-10-24 23:55:53 +0000965 OrderBy: orderBy,
Zack Williamse940c7a2019-08-21 14:25:39 -0700966 OutputAs: toOutputType(options.OutputAs),
967 NameLimit: options.NameLimit,
Scott Baker9173ed82020-05-19 08:30:12 -0700968 Data: ports.Items,
Zack Williamse940c7a2019-08-21 14:25:39 -0700969 }
970
971 GenerateOutput(&result)
972 return nil
973}
974
975func (options *DeviceFlowList) Execute(args []string) error {
976 fl := &FlowList{}
977 fl.ListOutputOptions = options.ListOutputOptions
Maninder045921e2020-09-29 16:46:02 +0530978 fl.FlowIdOptions = options.FlowIdOptions
Zack Williamse940c7a2019-08-21 14:25:39 -0700979 fl.Args.Id = string(options.Args.Id)
David Bainbridgea6722342019-10-24 23:55:53 +0000980 fl.Method = "device-flows"
Zack Williamse940c7a2019-08-21 14:25:39 -0700981 return fl.Execute(args)
982}
983
Himani Chawla3c161c62021-05-13 16:36:51 +0530984func (options *DeviceFlowGroupList) Execute(args []string) error {
985 grp := &GroupList{}
986 grp.ListOutputOptions = options.ListOutputOptions
987 grp.GroupListOptions = options.GroupListOptions
988 grp.Args.Id = string(options.Args.Id)
989 grp.Method = "device-groups"
990 return grp.Execute(args)
991}
992
Zack Williamse940c7a2019-08-21 14:25:39 -0700993func (options *DeviceInspect) Execute(args []string) error {
994 if len(args) > 0 {
995 return fmt.Errorf("only a single argument 'DEVICE_ID' can be provided")
996 }
997
998 conn, err := NewConnection()
999 if err != nil {
1000 return err
1001 }
1002 defer conn.Close()
1003
Scott Baker9173ed82020-05-19 08:30:12 -07001004 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -07001005
David K. Bainbridge9189c632021-03-26 21:52:21 +00001006 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -07001007 defer cancel()
1008
Scott Baker9173ed82020-05-19 08:30:12 -07001009 id := voltha.ID{Id: string(options.Args.Id)}
Zack Williamse940c7a2019-08-21 14:25:39 -07001010
Scott Baker9173ed82020-05-19 08:30:12 -07001011 device, err := client.GetDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -07001012 if err != nil {
1013 return err
1014 }
1015
Zack Williamse940c7a2019-08-21 14:25:39 -07001016 outputFormat := CharReplacer.Replace(options.Format)
1017 if outputFormat == "" {
David Bainbridgea6722342019-10-24 23:55:53 +00001018 outputFormat = GetCommandOptionWithDefault("device-inspect", "format", DEFAULT_DEVICE_INSPECT_FORMAT)
Zack Williamse940c7a2019-08-21 14:25:39 -07001019 }
1020 if options.Quiet {
1021 outputFormat = "{{.Id}}"
1022 }
1023
1024 result := CommandResult{
1025 Format: format.Format(outputFormat),
1026 OutputAs: toOutputType(options.OutputAs),
1027 NameLimit: options.NameLimit,
1028 Data: device,
1029 }
1030 GenerateOutput(&result)
1031 return nil
1032}
kesavand12cd8eb2020-01-20 22:25:22 -05001033
1034/*Device Port Enable */
1035func (options *DevicePortEnable) Execute(args []string) error {
1036 conn, err := NewConnection()
1037 if err != nil {
1038 return err
1039 }
1040 defer conn.Close()
1041
Scott Baker9173ed82020-05-19 08:30:12 -07001042 client := voltha.NewVolthaServiceClient(conn)
kesavand12cd8eb2020-01-20 22:25:22 -05001043
David K. Bainbridge9189c632021-03-26 21:52:21 +00001044 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand12cd8eb2020-01-20 22:25:22 -05001045 defer cancel()
1046
Scott Baker9173ed82020-05-19 08:30:12 -07001047 port := voltha.Port{DeviceId: string(options.Args.Id), PortNo: uint32(options.Args.PortId)}
1048
1049 _, err = client.EnablePort(ctx, &port)
kesavand12cd8eb2020-01-20 22:25:22 -05001050 if err != nil {
1051 Error.Printf("Error enabling port number %v on device Id %s,err=%s\n", options.Args.PortId, options.Args.Id, ErrorToString(err))
1052 return err
kesavand12cd8eb2020-01-20 22:25:22 -05001053 }
1054
1055 return nil
1056}
1057
Scott Baker9173ed82020-05-19 08:30:12 -07001058/*Device Port Disable */
kesavand12cd8eb2020-01-20 22:25:22 -05001059func (options *DevicePortDisable) Execute(args []string) error {
1060 conn, err := NewConnection()
1061 if err != nil {
1062 return err
1063 }
1064 defer conn.Close()
1065
Scott Baker9173ed82020-05-19 08:30:12 -07001066 client := voltha.NewVolthaServiceClient(conn)
1067
David K. Bainbridge9189c632021-03-26 21:52:21 +00001068 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand12cd8eb2020-01-20 22:25:22 -05001069 defer cancel()
1070
Scott Baker9173ed82020-05-19 08:30:12 -07001071 port := voltha.Port{DeviceId: string(options.Args.Id), PortNo: uint32(options.Args.PortId)}
1072
1073 _, err = client.DisablePort(ctx, &port)
kesavand12cd8eb2020-01-20 22:25:22 -05001074 if err != nil {
Scott Baker9173ed82020-05-19 08:30:12 -07001075 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 -05001076 return err
kesavand12cd8eb2020-01-20 22:25:22 -05001077 }
Scott Baker9173ed82020-05-19 08:30:12 -07001078
kesavand12cd8eb2020-01-20 22:25:22 -05001079 return nil
1080}
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08001081
Rohan Agrawald7df3772020-06-29 11:23:36 +00001082func (options *DevicePmConfigSetMaxSkew) Execute(args []string) error {
1083 conn, err := NewConnection()
1084 if err != nil {
1085 return err
1086 }
1087 defer conn.Close()
1088
1089 client := voltha.NewVolthaServiceClient(conn)
1090
David K. Bainbridge9189c632021-03-26 21:52:21 +00001091 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawald7df3772020-06-29 11:23:36 +00001092 defer cancel()
1093
1094 id := voltha.ID{Id: string(options.Args.Id)}
1095
1096 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1097 if err != nil {
1098 return err
1099 }
1100
1101 pmConfigs.MaxSkew = options.Args.MaxSkew
1102
1103 _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs)
1104 if err != nil {
1105 return err
1106 }
1107
1108 return nil
1109}
1110
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001111func (options *DevicePmConfigsGet) Execute(args []string) error {
1112
1113 conn, err := NewConnection()
1114 if err != nil {
1115 return err
1116 }
1117 defer conn.Close()
1118
1119 client := voltha.NewVolthaServiceClient(conn)
1120
David K. Bainbridge9189c632021-03-26 21:52:21 +00001121 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001122 defer cancel()
1123
1124 id := voltha.ID{Id: string(options.Args.Id)}
1125
1126 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1127 if err != nil {
1128 return err
1129 }
1130
1131 outputFormat := CharReplacer.Replace(options.Format)
1132 if outputFormat == "" {
1133 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GET_FORMAT)
1134 }
1135
1136 orderBy := options.OrderBy
1137 if orderBy == "" {
1138 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1139 }
1140
1141 result := CommandResult{
1142 Format: format.Format(outputFormat),
1143 Filter: options.Filter,
1144 OrderBy: orderBy,
1145 OutputAs: toOutputType(options.OutputAs),
1146 NameLimit: options.NameLimit,
1147 Data: pmConfigs,
1148 }
1149
1150 GenerateOutput(&result)
1151 return nil
1152
1153}
1154
1155func (options *DevicePmConfigMetricList) Execute(args []string) error {
1156
1157 conn, err := NewConnection()
1158 if err != nil {
1159 return err
1160 }
1161 defer conn.Close()
1162
1163 client := voltha.NewVolthaServiceClient(conn)
1164
David K. Bainbridge9189c632021-03-26 21:52:21 +00001165 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001166 defer cancel()
1167
1168 id := voltha.ID{Id: string(options.Args.Id)}
1169
1170 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1171 if err != nil {
1172 return err
1173 }
1174
1175 if !pmConfigs.Grouped {
1176 for _, metric := range pmConfigs.Metrics {
1177 if metric.SampleFreq == 0 {
1178 metric.SampleFreq = pmConfigs.DefaultFreq
1179 }
1180 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001181 outputFormat := CharReplacer.Replace(options.Format)
1182 if outputFormat == "" {
1183 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_METRIC_LIST_FORMAT)
1184 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001185
Rohan Agrawalbca69122020-06-17 14:59:03 +00001186 orderBy := options.OrderBy
1187 if orderBy == "" {
1188 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1189 }
1190
1191 result := CommandResult{
1192 Format: format.Format(outputFormat),
1193 Filter: options.Filter,
1194 OrderBy: orderBy,
1195 OutputAs: toOutputType(options.OutputAs),
1196 NameLimit: options.NameLimit,
1197 Data: pmConfigs.Metrics,
1198 }
1199
1200 GenerateOutput(&result)
1201 return nil
1202 } else {
1203 return fmt.Errorf("Device '%s' does not have Non Grouped Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001204 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001205}
1206
1207func (options *DevicePmConfigMetricEnable) Execute(args []string) error {
1208
1209 conn, err := NewConnection()
1210 if err != nil {
1211 return err
1212 }
1213 defer conn.Close()
1214
1215 client := voltha.NewVolthaServiceClient(conn)
1216
David K. Bainbridge9189c632021-03-26 21:52:21 +00001217 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001218 defer cancel()
1219
1220 id := voltha.ID{Id: string(options.Args.Id)}
1221
1222 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1223 if err != nil {
1224 return err
1225 }
1226
1227 if !pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001228 metrics := make(map[string]struct{})
1229 for _, metric := range pmConfigs.Metrics {
1230 metrics[metric.Name] = struct{}{}
1231 }
1232
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001233 for _, metric := range pmConfigs.Metrics {
1234 for _, mName := range options.Args.Metrics {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001235 if _, exist := metrics[string(mName)]; !exist {
1236 return fmt.Errorf("Metric Name '%s' does not exist", mName)
1237 }
1238
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001239 if string(mName) == metric.Name && !metric.Enabled {
1240 metric.Enabled = true
1241 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1242 if err != nil {
1243 return err
1244 }
1245 }
1246 }
1247 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001248 } else {
1249 return fmt.Errorf("Device '%s' does not have Non Grouped Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001250 }
1251 return nil
1252}
1253
1254func (options *DevicePmConfigMetricDisable) Execute(args []string) error {
1255
1256 conn, err := NewConnection()
1257 if err != nil {
1258 return err
1259 }
1260 defer conn.Close()
1261
1262 client := voltha.NewVolthaServiceClient(conn)
1263
David K. Bainbridge9189c632021-03-26 21:52:21 +00001264 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001265 defer cancel()
1266
1267 id := voltha.ID{Id: string(options.Args.Id)}
1268
1269 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1270 if err != nil {
1271 return err
1272 }
1273
1274 if !pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001275 metrics := make(map[string]struct{})
1276 for _, metric := range pmConfigs.Metrics {
1277 metrics[metric.Name] = struct{}{}
1278 }
1279
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001280 for _, metric := range pmConfigs.Metrics {
1281 for _, mName := range options.Args.Metrics {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001282 if _, have := metrics[string(mName)]; !have {
1283 return fmt.Errorf("Metric Name '%s' does not exist", mName)
1284 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001285 if string(mName) == metric.Name && metric.Enabled {
1286 metric.Enabled = false
1287 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1288 if err != nil {
1289 return err
1290 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001291 } else {
1292 return fmt.Errorf("Metric '%s' cannot be disabled", string(mName))
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 Non Grouped Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001298 }
1299 return nil
1300}
1301
1302func (options *DevicePmConfigGroupEnable) 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 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001327 for _, group := range pmConfigs.Groups {
Girish Gowdra610acb42021-01-27 13:33:57 -08001328 if _, have := groups[string(options.Args.Group)]; !have {
1329 return fmt.Errorf("Group Name '%s' does not exist", options.Args.Group)
1330 }
1331 if string(options.Args.Group) == group.GroupName && !group.Enabled {
1332 group.Enabled = true
1333 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1334 if err != nil {
1335 return err
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001336 }
1337 }
1338 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001339 } else {
1340 return fmt.Errorf("Device '%s' does not have Group Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001341 }
1342 return nil
1343}
1344
1345func (options *DevicePmConfigGroupDisable) Execute(args []string) error {
1346
1347 conn, err := NewConnection()
1348 if err != nil {
1349 return err
1350 }
1351 defer conn.Close()
1352
1353 client := voltha.NewVolthaServiceClient(conn)
1354
David K. Bainbridge9189c632021-03-26 21:52:21 +00001355 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001356 defer cancel()
1357
1358 id := voltha.ID{Id: string(options.Args.Id)}
1359
1360 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1361 if err != nil {
1362 return err
1363 }
1364
1365 if pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001366 groups := make(map[string]struct{})
1367 for _, group := range pmConfigs.Groups {
1368 groups[group.GroupName] = struct{}{}
1369 }
1370
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001371 for _, group := range pmConfigs.Groups {
Girish Gowdra610acb42021-01-27 13:33:57 -08001372 if _, have := groups[string(options.Args.Group)]; !have {
1373 return fmt.Errorf("Group Name '%s' does not exist", options.Args.Group)
1374 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001375
Girish Gowdra610acb42021-01-27 13:33:57 -08001376 if string(options.Args.Group) == group.GroupName && group.Enabled {
1377 group.Enabled = false
1378 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1379 if err != nil {
1380 return err
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001381 }
1382 }
1383 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001384 } else {
1385 return fmt.Errorf("Device '%s' does not have Group Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001386 }
1387 return nil
1388}
1389
Girish Gowdra610acb42021-01-27 13:33:57 -08001390func (options *DevicePmConfigGroupFrequencySet) Execute(args []string) error {
1391
1392 conn, err := NewConnection()
1393 if err != nil {
1394 return err
1395 }
1396 defer conn.Close()
1397
1398 client := voltha.NewVolthaServiceClient(conn)
1399
David K. Bainbridge9189c632021-03-26 21:52:21 +00001400 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Girish Gowdra610acb42021-01-27 13:33:57 -08001401 defer cancel()
1402
1403 id := voltha.ID{Id: string(options.Args.Id)}
1404
1405 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1406 if err != nil {
1407 return err
1408 }
1409
1410 if pmConfigs.Grouped {
1411 groups := make(map[string]struct{})
1412 for _, group := range pmConfigs.Groups {
1413 groups[group.GroupName] = struct{}{}
1414 }
1415
1416 for _, group := range pmConfigs.Groups {
1417 if _, have := groups[string(options.Args.Group)]; !have {
1418 return fmt.Errorf("group name '%s' does not exist", options.Args.Group)
1419 }
1420
1421 if string(options.Args.Group) == group.GroupName {
1422 if !group.Enabled {
1423 return fmt.Errorf("group '%s' is not enabled", options.Args.Group)
1424 }
1425 group.GroupFreq = uint32(options.Args.Interval.Seconds())
1426 _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs)
1427 if err != nil {
1428 return err
1429 }
1430 }
1431 }
1432 } else {
1433 return fmt.Errorf("device '%s' does not have group metrics", options.Args.Id)
1434 }
1435 return nil
1436}
1437
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001438func (options *DevicePmConfigGroupList) Execute(args []string) error {
1439
1440 conn, err := NewConnection()
1441 if err != nil {
1442 return err
1443 }
1444 defer conn.Close()
1445
1446 client := voltha.NewVolthaServiceClient(conn)
1447
David K. Bainbridge9189c632021-03-26 21:52:21 +00001448 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001449 defer cancel()
1450
1451 id := voltha.ID{Id: string(options.Args.Id)}
1452
1453 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1454 if err != nil {
1455 return err
1456 }
1457
1458 if pmConfigs.Grouped {
1459 for _, group := range pmConfigs.Groups {
1460 if group.GroupFreq == 0 {
1461 group.GroupFreq = pmConfigs.DefaultFreq
1462 }
1463 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001464 outputFormat := CharReplacer.Replace(options.Format)
1465 if outputFormat == "" {
1466 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GROUP_LIST_FORMAT)
1467 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001468
Rohan Agrawalbca69122020-06-17 14:59:03 +00001469 orderBy := options.OrderBy
1470 if orderBy == "" {
1471 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1472 }
1473
1474 result := CommandResult{
1475 Format: format.Format(outputFormat),
1476 Filter: options.Filter,
1477 OrderBy: orderBy,
1478 OutputAs: toOutputType(options.OutputAs),
1479 NameLimit: options.NameLimit,
1480 Data: pmConfigs.Groups,
1481 }
1482
1483 GenerateOutput(&result)
1484 } else {
1485 return fmt.Errorf("Device '%s' does not have Group Metrics", string(options.Args.Id))
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001486 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001487 return nil
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001488}
1489
1490func (options *DevicePmConfigGroupMetricList) Execute(args []string) error {
1491
1492 var metrics []*voltha.PmConfig
1493 conn, err := NewConnection()
1494 if err != nil {
1495 return err
1496 }
1497 defer conn.Close()
1498
1499 client := voltha.NewVolthaServiceClient(conn)
1500
David K. Bainbridge9189c632021-03-26 21:52:21 +00001501 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001502 defer cancel()
1503
1504 id := voltha.ID{Id: string(options.Args.Id)}
1505
1506 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1507 if err != nil {
1508 return err
1509 }
1510
1511 for _, groups := range pmConfigs.Groups {
1512
1513 if string(options.Args.Group) == groups.GroupName {
1514 for _, metric := range groups.Metrics {
1515 if metric.SampleFreq == 0 && groups.GroupFreq == 0 {
1516 metric.SampleFreq = pmConfigs.DefaultFreq
1517 } else {
1518 metric.SampleFreq = groups.GroupFreq
1519 }
1520 }
1521 metrics = groups.Metrics
1522 }
1523 }
1524
1525 outputFormat := CharReplacer.Replace(options.Format)
1526 if outputFormat == "" {
1527 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_METRIC_LIST_FORMAT)
1528 }
1529
1530 orderBy := options.OrderBy
1531 if orderBy == "" {
1532 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1533 }
1534
1535 result := CommandResult{
1536 Format: format.Format(outputFormat),
1537 Filter: options.Filter,
1538 OrderBy: orderBy,
1539 OutputAs: toOutputType(options.OutputAs),
1540 NameLimit: options.NameLimit,
1541 Data: metrics,
1542 }
1543
1544 GenerateOutput(&result)
1545 return nil
1546
1547}
1548
1549func (options *DevicePmConfigFrequencySet) Execute(args []string) error {
1550
1551 conn, err := NewConnection()
1552 if err != nil {
1553 return err
1554 }
1555 defer conn.Close()
1556
1557 client := voltha.NewVolthaServiceClient(conn)
1558
David K. Bainbridge9189c632021-03-26 21:52:21 +00001559 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001560 defer cancel()
1561
1562 id := voltha.ID{Id: string(options.Args.Id)}
1563
1564 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1565 if err != nil {
1566 return err
1567 }
1568
Girish Gowdra610acb42021-01-27 13:33:57 -08001569 pmConfigs.DefaultFreq = uint32(options.Args.Interval.Seconds())
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001570
1571 _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs)
1572 if err != nil {
1573 return err
1574 }
1575
1576 outputFormat := CharReplacer.Replace(options.Format)
1577 if outputFormat == "" {
1578 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GET_FORMAT)
1579 }
1580 if options.Quiet {
1581 outputFormat = "{{.Id}}"
1582 }
1583
1584 result := CommandResult{
1585 Format: format.Format(outputFormat),
1586 OutputAs: toOutputType(options.OutputAs),
1587 NameLimit: options.NameLimit,
1588 Data: pmConfigs,
1589 }
1590
1591 GenerateOutput(&result)
1592 return nil
1593
1594}
1595
kesavand3e2f9f62021-04-22 11:06:38 +05301596func (options *OnuDownloadImage) Execute(args []string) error {
1597
1598 conn, err := NewConnection()
1599 if err != nil {
1600 return err
1601 }
1602 defer conn.Close()
1603
1604 client := voltha.NewVolthaServiceClient(conn)
1605
1606 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1607 defer cancel()
1608
1609 var devIDList []*common.ID
1610 for _, i := range options.Args.IDs {
1611
1612 devIDList = append(devIDList, &common.ID{Id: string(i)})
1613 }
1614
1615 downloadImage := voltha.DeviceImageDownloadRequest{
1616 DeviceId: devIDList,
1617 Image: &voltha.Image{
1618 Url: options.Args.Url,
1619 Crc32: options.Args.Crc,
ssiddiqui7bc89e92021-05-20 20:58:02 +05301620 Vendor: options.Args.Vendor,
kesavand3e2f9f62021-04-22 11:06:38 +05301621 Version: options.Args.ImageVersion,
1622 },
1623 ActivateOnSuccess: options.Args.ActivateOnSuccess,
1624 CommitOnSuccess: options.Args.CommitOnSuccess,
1625 }
1626
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001627 deviceImageResp, err := client.DownloadImageToDevice(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301628 if err != nil {
1629 return err
1630 }
1631
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001632 outputFormat := GetCommandOptionWithDefault("onu-image-download", "format", ONU_IMAGE_STATUS_FORMAT)
1633 // Make sure json output prints an empty list, not "null"
1634 if deviceImageResp.DeviceImageStates == nil {
1635 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1636 }
1637 result := CommandResult{
1638 Format: format.Format(outputFormat),
1639 OutputAs: toOutputType(options.OutputAs),
1640 NameLimit: options.NameLimit,
1641 Data: deviceImageResp.DeviceImageStates,
1642 }
1643 GenerateOutput(&result)
kesavand3e2f9f62021-04-22 11:06:38 +05301644 return nil
1645
1646}
1647
1648func (options *OnuActivateImage) Execute(args []string) error {
1649
1650 conn, err := NewConnection()
1651 if err != nil {
1652 return err
1653 }
1654 defer conn.Close()
1655
1656 client := voltha.NewVolthaServiceClient(conn)
1657
1658 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1659 defer cancel()
1660
1661 var devIDList []*common.ID
1662 for _, i := range options.Args.IDs {
1663
1664 devIDList = append(devIDList, &common.ID{Id: string(i)})
1665 }
1666
1667 downloadImage := voltha.DeviceImageRequest{
1668 DeviceId: devIDList,
1669 Version: options.Args.ImageVersion,
1670 CommitOnSuccess: options.Args.CommitOnSuccess,
1671 }
1672
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001673 deviceImageResp, err := client.ActivateImage(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301674 if err != nil {
1675 return err
1676 }
1677
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001678 outputFormat := GetCommandOptionWithDefault("onu-image-activate", "format", ONU_IMAGE_STATUS_FORMAT)
1679 // Make sure json output prints an empty list, not "null"
1680 if deviceImageResp.DeviceImageStates == nil {
1681 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1682 }
1683 result := CommandResult{
1684 Format: format.Format(outputFormat),
1685 OutputAs: toOutputType(options.OutputAs),
1686 NameLimit: options.NameLimit,
1687 Data: deviceImageResp.DeviceImageStates,
1688 }
1689 GenerateOutput(&result)
1690
kesavand3e2f9f62021-04-22 11:06:38 +05301691 return nil
1692
1693}
1694
1695func (options *OnuAbortUpgradeImage) Execute(args []string) error {
1696
1697 conn, err := NewConnection()
1698 if err != nil {
1699 return err
1700 }
1701 defer conn.Close()
1702
1703 client := voltha.NewVolthaServiceClient(conn)
1704
1705 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1706 defer cancel()
1707
1708 var devIDList []*common.ID
1709 for _, i := range options.Args.IDs {
1710
1711 devIDList = append(devIDList, &common.ID{Id: string(i)})
1712 }
1713
1714 downloadImage := voltha.DeviceImageRequest{
1715 DeviceId: devIDList,
1716 Version: options.Args.ImageVersion,
1717 }
1718
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001719 deviceImageResp, err := client.AbortImageUpgradeToDevice(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301720 if err != nil {
1721 return err
1722 }
1723
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001724 outputFormat := GetCommandOptionWithDefault("onu-image-abort", "format", ONU_IMAGE_STATUS_FORMAT)
1725 // Make sure json output prints an empty list, not "null"
1726 if deviceImageResp.DeviceImageStates == nil {
1727 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1728 }
1729 result := CommandResult{
1730 Format: format.Format(outputFormat),
1731 OutputAs: toOutputType(options.OutputAs),
1732 NameLimit: options.NameLimit,
1733 Data: deviceImageResp.DeviceImageStates,
1734 }
1735 GenerateOutput(&result)
1736
kesavand3e2f9f62021-04-22 11:06:38 +05301737 return nil
1738
1739}
1740
1741func (options *OnuCommitImage) Execute(args []string) error {
1742
1743 conn, err := NewConnection()
1744 if err != nil {
1745 return err
1746 }
1747 defer conn.Close()
1748
1749 client := voltha.NewVolthaServiceClient(conn)
1750
1751 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1752 defer cancel()
1753
1754 var devIDList []*common.ID
1755 for _, i := range options.Args.IDs {
1756
1757 devIDList = append(devIDList, &common.ID{Id: string(i)})
1758 }
1759 downloadImage := voltha.DeviceImageRequest{
1760 DeviceId: devIDList,
1761 Version: options.Args.ImageVersion,
1762 }
1763
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001764 deviceImageResp, err := client.CommitImage(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301765 if err != nil {
1766 return err
1767 }
1768
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001769 outputFormat := GetCommandOptionWithDefault("onu-image-commit", "format", ONU_IMAGE_STATUS_FORMAT)
1770 // Make sure json output prints an empty list, not "null"
1771 if deviceImageResp.DeviceImageStates == nil {
1772 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1773 }
1774 result := CommandResult{
1775 Format: format.Format(outputFormat),
1776 OutputAs: toOutputType(options.OutputAs),
1777 NameLimit: options.NameLimit,
1778 Data: deviceImageResp.DeviceImageStates,
1779 }
1780 GenerateOutput(&result)
1781
kesavand3e2f9f62021-04-22 11:06:38 +05301782 return nil
1783
1784}
1785
1786func (options *OnuListImages) Execute(args []string) error {
1787
1788 conn, err := NewConnection()
1789 if err != nil {
1790 return err
1791 }
1792 defer conn.Close()
1793
1794 client := voltha.NewVolthaServiceClient(conn)
1795
1796 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1797 defer cancel()
1798
1799 id := common.ID{Id: string(options.Args.Id)}
1800
1801 onuImages, err := client.GetOnuImages(ctx, &id)
1802 if err != nil {
1803 return err
1804 }
1805
1806 outputFormat := CharReplacer.Replace(options.Format)
1807 if outputFormat == "" {
1808 outputFormat = GetCommandOptionWithDefault("onu-image-list", "format", ONU_IMAGE_LIST_FORMAT)
1809 }
1810
1811 if options.Quiet {
1812 outputFormat = "{{.Id}}"
1813 }
1814
1815 //TODO orderby
1816
1817 // Make sure json output prints an empty list, not "null"
1818 if onuImages.Items == nil {
1819 onuImages.Items = make([]*voltha.OnuImage, 0)
1820 }
1821
1822 result := CommandResult{
1823 Format: format.Format(outputFormat),
1824 OutputAs: toOutputType(options.OutputAs),
1825 NameLimit: options.NameLimit,
1826 Data: onuImages.Items,
1827 }
1828
1829 GenerateOutput(&result)
1830 return nil
1831
1832}
1833
1834func (options *OnuImageStatus) Execute(args []string) error {
1835
1836 conn, err := NewConnection()
1837 if err != nil {
1838 return err
1839 }
1840 defer conn.Close()
1841
1842 client := voltha.NewVolthaServiceClient(conn)
1843
1844 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1845 defer cancel()
1846
1847 var devIDList []*common.ID
kesavand3e2f9f62021-04-22 11:06:38 +05301848
Elia Battiston859f3e62022-02-08 15:57:52 +01001849 if options.Args.IDs == nil {
1850 //Use an empty IDs list to retrieve the status of all devices
1851 //with the requested image version
1852 devIDList = []*common.ID{}
1853 } else {
1854 for _, i := range options.Args.IDs {
1855 devIDList = append(devIDList, &common.ID{Id: string(i)})
1856 }
kesavand3e2f9f62021-04-22 11:06:38 +05301857 }
1858
1859 imageStatusReq := voltha.DeviceImageRequest{
1860 DeviceId: devIDList,
1861 Version: options.Args.ImageVersion,
1862 }
1863 imageStatus, err := client.GetImageStatus(ctx, &imageStatusReq)
1864 if err != nil {
1865 return err
1866 }
1867
1868 outputFormat := CharReplacer.Replace(options.Format)
1869 if outputFormat == "" {
1870 outputFormat = GetCommandOptionWithDefault("device-image-list", "format", ONU_IMAGE_STATUS_FORMAT)
1871 }
1872
1873 if options.Quiet {
1874 outputFormat = "{{.Id}}"
1875 }
1876
1877 //TODO orderby
1878
1879 // Make sure json output prints an empty list, not "null"
1880 if imageStatus.DeviceImageStates == nil {
1881 imageStatus.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1882 }
1883
1884 result := CommandResult{
1885 Format: format.Format(outputFormat),
1886 OutputAs: toOutputType(options.OutputAs),
1887 NameLimit: options.NameLimit,
1888 Data: imageStatus.DeviceImageStates,
1889 }
1890
1891 GenerateOutput(&result)
1892 return nil
1893
1894}
1895
Andrea Campanella791d88b2021-01-08 13:29:00 +01001896func (options *DeviceOnuListImages) Execute(args []string) error {
1897
1898 conn, err := NewConnection()
1899 if err != nil {
1900 return err
1901 }
1902 defer conn.Close()
1903
1904 client := voltha.NewVolthaServiceClient(conn)
1905
David K. Bainbridge9189c632021-03-26 21:52:21 +00001906 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Andrea Campanella791d88b2021-01-08 13:29:00 +01001907 defer cancel()
1908
1909 id := common.ID{Id: string(options.Args.Id)}
1910
1911 imageDownloads, err := client.ListImageDownloads(ctx, &id)
1912 if err != nil {
1913 return err
1914 }
1915
1916 outputFormat := CharReplacer.Replace(options.Format)
1917 if outputFormat == "" {
1918 outputFormat = GetCommandOptionWithDefault("device-image-list", "format", DEFAULT_DEVICE_IMAGE_LIST_GET_FORMAT)
1919 }
1920
1921 if options.Quiet {
1922 outputFormat = "{{.Id}}"
1923 }
1924
1925 //TODO orderby
1926
1927 // Make sure json output prints an empty list, not "null"
1928 if imageDownloads.Items == nil {
1929 imageDownloads.Items = make([]*voltha.ImageDownload, 0)
1930 }
1931
1932 result := CommandResult{
1933 Format: format.Format(outputFormat),
1934 OutputAs: toOutputType(options.OutputAs),
1935 NameLimit: options.NameLimit,
1936 Data: imageDownloads.Items,
1937 }
1938
1939 GenerateOutput(&result)
1940 return nil
1941
1942}
1943
1944func (options *DeviceOnuDownloadImage) Execute(args []string) error {
1945
1946 conn, err := NewConnection()
1947 if err != nil {
1948 return err
1949 }
1950 defer conn.Close()
1951
1952 client := voltha.NewVolthaServiceClient(conn)
1953
David K. Bainbridge9189c632021-03-26 21:52:21 +00001954 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Andrea Campanella791d88b2021-01-08 13:29:00 +01001955 defer cancel()
1956
1957 downloadImage := voltha.ImageDownload{
1958 Id: string(options.Args.Id),
1959 Name: options.Args.Name,
1960 Url: options.Args.Url,
1961 Crc: options.Args.Crc,
1962 LocalDir: options.Args.LocalDir,
1963 }
1964
1965 _, err = client.DownloadImage(ctx, &downloadImage)
1966 if err != nil {
1967 return err
1968 }
1969
1970 return nil
1971
1972}
1973
1974func (options *DeviceOnuActivateImageUpdate) Execute(args []string) error {
1975
1976 conn, err := NewConnection()
1977 if err != nil {
1978 return err
1979 }
1980 defer conn.Close()
1981
1982 client := voltha.NewVolthaServiceClient(conn)
1983
David K. Bainbridge9189c632021-03-26 21:52:21 +00001984 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Andrea Campanella791d88b2021-01-08 13:29:00 +01001985 defer cancel()
1986
1987 downloadImage := voltha.ImageDownload{
1988 Id: string(options.Args.Id),
1989 Name: options.Args.Name,
1990 ImageVersion: options.Args.ImageVersion,
1991 SaveConfig: options.Args.SaveConfig,
1992 LocalDir: options.Args.LocalDir,
1993 }
1994
1995 _, err = client.ActivateImageUpdate(ctx, &downloadImage)
1996 if err != nil {
1997 return err
1998 }
1999
2000 return nil
2001
2002}
2003
Scott Baker9173ed82020-05-19 08:30:12 -07002004type ReturnValueRow struct {
2005 Name string `json:"name"`
2006 Result interface{} `json:"result"`
2007}
2008
kesavand8ec4fc02021-01-27 09:10:22 -05002009func (options *DeviceGetPortStats) Execute(args []string) error {
2010 conn, err := NewConnection()
2011 if err != nil {
2012 return err
2013 }
2014 defer conn.Close()
2015 client := extension.NewExtensionClient(conn)
2016 var portType extension.GetOltPortCounters_PortType
2017
2018 if options.Args.PortType == "pon" {
2019 portType = extension.GetOltPortCounters_Port_PON_OLT
2020 } else if options.Args.PortType == "nni" {
2021
2022 portType = extension.GetOltPortCounters_Port_ETHERNET_NNI
2023 } else {
2024 return fmt.Errorf("expected interface type pon/nni, provided %s", options.Args.PortType)
2025 }
2026
2027 singleGetValReq := extension.SingleGetValueRequest{
2028 TargetId: string(options.Args.Id),
2029 Request: &extension.GetValueRequest{
2030 Request: &extension.GetValueRequest_OltPortInfo{
2031 OltPortInfo: &extension.GetOltPortCounters{
2032 PortNo: options.Args.PortNo,
2033 PortType: portType,
2034 },
2035 },
2036 },
2037 }
2038
David K. Bainbridge9189c632021-03-26 21:52:21 +00002039 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand8ec4fc02021-01-27 09:10:22 -05002040 defer cancel()
2041 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2042 if err != nil {
2043 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2044 return err
2045 }
2046
2047 if rv.Response.Status != extension.GetValueResponse_OK {
2048 return fmt.Errorf("failed to get port stats %v", rv.Response.ErrReason.String())
2049 }
2050
2051 outputFormat := CharReplacer.Replace(options.Format)
2052 if outputFormat == "" {
2053 outputFormat = GetCommandOptionWithDefault("device-get-port-status", "format", DEFAULT_DEVICE_GET_PORT_STATUS_FORMAT)
2054 }
2055
2056 result := CommandResult{
2057 Format: format.Format(outputFormat),
2058 OutputAs: toOutputType(options.OutputAs),
2059 NameLimit: options.NameLimit,
2060 Data: rv.GetResponse().GetPortCoutners(),
2061 }
2062 GenerateOutput(&result)
2063 return nil
2064}
2065
Himani Chawla40acc122021-05-26 18:52:29 +05302066func (options *GetOnuStats) Execute(args []string) error {
2067 conn, err := NewConnection()
2068 if err != nil {
2069 return err
2070 }
2071 defer conn.Close()
2072 client := extension.NewExtensionClient(conn)
2073
2074 singleGetValReq := extension.SingleGetValueRequest{
2075 TargetId: string(options.Args.OltId),
2076 Request: &extension.GetValueRequest{
2077 Request: &extension.GetValueRequest_OnuPonInfo{
2078 OnuPonInfo: &extension.GetOnuCountersRequest{
2079 IntfId: options.Args.IntfId,
2080 OnuId: options.Args.OnuId,
2081 },
2082 },
2083 },
2084 }
2085 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2086 defer cancel()
2087 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2088 if err != nil {
2089 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.OltId, ErrorToString(err))
2090 return err
2091 }
2092
2093 if rv.Response.Status != extension.GetValueResponse_OK {
2094 return fmt.Errorf("failed to get onu stats %v", rv.Response.ErrReason.String())
2095 }
2096 outputFormat := CharReplacer.Replace(options.Format)
2097 data, formatStr := buildOnuStatsOutputFormat(rv.GetResponse().GetOnuPonCounters())
2098 if outputFormat == "" {
2099 outputFormat = GetCommandOptionWithDefault("device-get-onu-status", "format", formatStr)
2100 }
Himani Chawla553a1392021-06-10 23:39:17 +05302101 result := CommandResult{
2102 Format: format.Format(outputFormat),
2103 OutputAs: toOutputType(options.OutputAs),
2104 NameLimit: options.NameLimit,
2105 Data: data,
2106 }
2107 GenerateOutput(&result)
2108 return nil
2109}
Himani Chawla40acc122021-05-26 18:52:29 +05302110
Himani Chawla553a1392021-06-10 23:39:17 +05302111func (options *GetOnuEthernetFrameExtendedPmCounters) Execute(args []string) error {
2112 conn, err := NewConnection()
2113 if err != nil {
2114 return err
2115 }
2116 defer conn.Close()
2117 client := extension.NewExtensionClient(conn)
Himani Chawla806aa892021-08-30 15:51:46 +05302118 var singleGetValReq extension.SingleGetValueRequest
Himani Chawla553a1392021-06-10 23:39:17 +05302119
Himani Chawla806aa892021-08-30 15:51:46 +05302120 if options.Args.UniIndex != nil {
2121 singleGetValReq = extension.SingleGetValueRequest{
2122 TargetId: string(options.Args.Id),
2123 Request: &extension.GetValueRequest{
2124 Request: &extension.GetValueRequest_OnuInfo{
2125 OnuInfo: &extension.GetOmciEthernetFrameExtendedPmRequest{
2126 OnuDeviceId: string(options.Args.Id),
2127 Reset_: options.Reset,
2128 IsUniIndex: &extension.GetOmciEthernetFrameExtendedPmRequest_UniIndex{
2129 UniIndex: *options.Args.UniIndex,
2130 },
2131 },
Himani Chawla553a1392021-06-10 23:39:17 +05302132 },
2133 },
Himani Chawla806aa892021-08-30 15:51:46 +05302134 }
2135 } else {
2136 singleGetValReq = extension.SingleGetValueRequest{
2137 TargetId: string(options.Args.Id),
2138 Request: &extension.GetValueRequest{
2139 Request: &extension.GetValueRequest_OnuInfo{
2140 OnuInfo: &extension.GetOmciEthernetFrameExtendedPmRequest{
2141 OnuDeviceId: string(options.Args.Id),
2142 Reset_: options.Reset,
2143 },
2144 },
2145 },
2146 }
Himani Chawla553a1392021-06-10 23:39:17 +05302147 }
Himani Chawla806aa892021-08-30 15:51:46 +05302148
Himani Chawla553a1392021-06-10 23:39:17 +05302149 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2150 defer cancel()
2151 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2152 if err != nil {
2153 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2154 return err
2155 }
2156
2157 if rv.Response.Status != extension.GetValueResponse_OK {
2158 return fmt.Errorf("failed to get ethernet frame extended pm counters %v", rv.Response.ErrReason.String())
2159 }
2160 outputFormat := CharReplacer.Replace(options.Format)
2161 data := buildOnuEthernetFrameExtendedPmOutputFormat(rv.GetResponse().GetOnuCounters())
2162 if outputFormat == "" {
2163 outputFormat = GetCommandOptionWithDefault("device-get-onu-status", "format", DEFAULT_ETHERNET_FRAME_EXTENDED_PM_COUNTERS_FORMAT)
2164 }
Himani Chawla40acc122021-05-26 18:52:29 +05302165 result := CommandResult{
2166 Format: format.Format(outputFormat),
2167 OutputAs: toOutputType(options.OutputAs),
2168 NameLimit: options.NameLimit,
2169 Data: data,
2170 }
2171 GenerateOutput(&result)
2172 return nil
2173}
2174
kesavand6d1131f2021-02-05 22:38:15 +05302175func (options *UniStatus) Execute(args []string) error {
2176 conn, err := NewConnection()
2177 if err != nil {
2178 return err
2179 }
2180 defer conn.Close()
2181 client := extension.NewExtensionClient(conn)
2182
2183 singleGetValReq := extension.SingleGetValueRequest{
2184 TargetId: string(options.Args.Id),
2185 Request: &extension.GetValueRequest{
2186 Request: &extension.GetValueRequest_UniInfo{
2187 UniInfo: &extension.GetOnuUniInfoRequest{
2188 UniIndex: options.Args.UniIndex,
2189 },
2190 },
2191 },
2192 }
David K. Bainbridge9189c632021-03-26 21:52:21 +00002193 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand6d1131f2021-02-05 22:38:15 +05302194 defer cancel()
2195 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2196 if err != nil {
2197 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2198 return err
2199 }
2200 if rv.Response.Status != extension.GetValueResponse_OK {
2201 return fmt.Errorf("failed to get uni status %v", rv.Response.ErrReason.String())
2202 }
2203 outputFormat := CharReplacer.Replace(options.Format)
2204 if outputFormat == "" {
2205 outputFormat = GetCommandOptionWithDefault("device-get-uni-status", "format", DEFAULT_DEVICE_GET_UNI_STATUS_FORMAT)
2206 }
2207 result := CommandResult{
2208 Format: format.Format(outputFormat),
2209 OutputAs: toOutputType(options.OutputAs),
2210 NameLimit: options.NameLimit,
2211 Data: rv.GetResponse().GetUniInfo(),
2212 }
2213 GenerateOutput(&result)
2214 return nil
2215}
2216
Girish Gowdra4f5ce7c2021-04-29 18:53:21 -07002217func (options *OnuPonOpticalInfo) Execute(args []string) error {
2218 conn, err := NewConnection()
2219 if err != nil {
2220 return err
2221 }
2222 defer conn.Close()
2223 client := extension.NewExtensionClient(conn)
2224
2225 singleGetValReq := extension.SingleGetValueRequest{
2226 TargetId: string(options.Args.Id),
2227 Request: &extension.GetValueRequest{
2228 Request: &extension.GetValueRequest_OnuOpticalInfo{
2229 OnuOpticalInfo: &extension.GetOnuPonOpticalInfo{},
2230 },
2231 },
2232 }
2233 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2234 defer cancel()
2235 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2236 if err != nil {
2237 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2238 return err
2239 }
2240 if rv.Response.Status != extension.GetValueResponse_OK {
2241 return fmt.Errorf("failed to get onu pon optical info %v", rv.Response.ErrReason.String())
2242 }
2243 outputFormat := CharReplacer.Replace(options.Format)
2244 if outputFormat == "" {
2245 outputFormat = GetCommandOptionWithDefault("device-get-onu-pon-optical-info", "format", DEFAULT_ONU_PON_OPTICAL_INFO_STATUS_FORMAT)
2246 }
2247 result := CommandResult{
2248 Format: format.Format(outputFormat),
2249 OutputAs: toOutputType(options.OutputAs),
2250 NameLimit: options.NameLimit,
2251 Data: rv.GetResponse().GetOnuOpticalInfo(),
2252 }
2253 GenerateOutput(&result)
2254 return nil
2255}
2256
Gamze Abakac857a462021-05-26 13:45:54 +00002257func (options *RxPower) Execute(args []string) error {
2258 conn, err := NewConnection()
2259 if err != nil {
2260 return err
2261 }
2262 defer conn.Close()
2263 client := extension.NewExtensionClient(conn)
2264
2265 singleGetValReq := extension.SingleGetValueRequest{
2266 TargetId: string(options.Args.Id),
2267 Request: &extension.GetValueRequest{
2268 Request: &extension.GetValueRequest_RxPower{
2269 RxPower: &extension.GetRxPowerRequest{
2270 IntfId: options.Args.PortNo,
2271 OnuId: options.Args.OnuNo,
2272 },
2273 },
2274 },
2275 }
2276
2277 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2278 defer cancel()
2279 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2280 if err != nil {
2281 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2282 return err
2283 }
2284 if rv.Response.Status != extension.GetValueResponse_OK {
2285 return fmt.Errorf("failed to get rx power %v", rv.Response.ErrReason.String())
2286 }
2287 outputFormat := CharReplacer.Replace(options.Format)
2288 if outputFormat == "" {
2289 outputFormat = GetCommandOptionWithDefault("device-get-rx-power", "format", DEFAULT_RX_POWER_STATUS_FORMAT)
2290 }
2291 result := CommandResult{
2292 Format: format.Format(outputFormat),
2293 OutputAs: toOutputType(options.OutputAs),
2294 NameLimit: options.NameLimit,
2295 Data: rv.GetResponse().GetRxPower(),
2296 }
2297 GenerateOutput(&result)
2298 return nil
2299}
2300
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002301/*Device get Onu Distance */
2302func (options *DeviceGetExtValue) Execute(args []string) error {
2303 conn, err := NewConnection()
2304 if err != nil {
2305 return err
2306 }
2307 defer conn.Close()
2308
Scott Baker9173ed82020-05-19 08:30:12 -07002309 client := voltha.NewVolthaServiceClient(conn)
2310
khenaidoo080ce882021-10-19 17:35:08 -04002311 valueflag, okay := extension.ValueType_Type_value[string(options.Args.Valueflag)]
Scott Baker9173ed82020-05-19 08:30:12 -07002312 if !okay {
2313 Error.Printf("Unknown valueflag %s\n", options.Args.Valueflag)
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002314 }
2315
khenaidoo080ce882021-10-19 17:35:08 -04002316 val := extension.ValueSpecifier{Id: string(options.Args.Id), Value: extension.ValueType_Type(valueflag)}
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002317
David K. Bainbridge9189c632021-03-26 21:52:21 +00002318 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002319 defer cancel()
2320
Scott Baker9173ed82020-05-19 08:30:12 -07002321 rv, err := client.GetExtValue(ctx, &val)
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002322 if err != nil {
2323 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2324 return err
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002325 }
2326
Scott Baker9173ed82020-05-19 08:30:12 -07002327 var rows []ReturnValueRow
khenaidoo080ce882021-10-19 17:35:08 -04002328 for name, num := range extension.ValueType_Type_value {
Scott Baker9173ed82020-05-19 08:30:12 -07002329 if num == 0 {
2330 // EMPTY is not a real value
2331 continue
2332 }
2333 if (rv.Error & uint32(num)) != 0 {
2334 row := ReturnValueRow{Name: name, Result: "Error"}
2335 rows = append(rows, row)
2336 }
2337 if (rv.Unsupported & uint32(num)) != 0 {
2338 row := ReturnValueRow{Name: name, Result: "Unsupported"}
2339 rows = append(rows, row)
2340 }
2341 if (rv.Set & uint32(num)) != 0 {
2342 switch name {
2343 case "DISTANCE":
2344 row := ReturnValueRow{Name: name, Result: rv.Distance}
2345 rows = append(rows, row)
2346 default:
2347 row := ReturnValueRow{Name: name, Result: "Unimplemented-in-voltctl"}
2348 rows = append(rows, row)
2349 }
2350 }
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002351 }
2352
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002353 outputFormat := CharReplacer.Replace(options.Format)
2354 if outputFormat == "" {
2355 outputFormat = GetCommandOptionWithDefault("device-value-get", "format", DEFAULT_DEVICE_VALUE_GET_FORMAT)
2356 }
2357
2358 result := CommandResult{
2359 Format: format.Format(outputFormat),
2360 OutputAs: toOutputType(options.OutputAs),
2361 NameLimit: options.NameLimit,
Scott Baker9173ed82020-05-19 08:30:12 -07002362 Data: rows,
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002363 }
2364 GenerateOutput(&result)
2365 return nil
2366}
serkantul3d22fc72022-09-14 12:22:56 +03002367
2368/*Device get Onu OMCI TX RX Stats */
2369func (options *OnuOmciTxRxStats) Execute(args []string) error {
2370 conn, err := NewConnection()
2371 if err != nil {
2372 return err
2373 }
2374 defer conn.Close()
2375 client := extension.NewExtensionClient(conn)
2376
2377 singleGetValReq := extension.SingleGetValueRequest{
2378 TargetId: string(options.Args.Id),
2379 Request: &extension.GetValueRequest{
2380 Request: &extension.GetValueRequest_OnuOmciStats{
2381 OnuOmciStats: &extension.GetOnuOmciTxRxStatsRequest{},
2382 },
2383 },
2384 }
2385
2386 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2387 defer cancel()
2388 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2389 if err != nil {
2390 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2391 return err
2392 }
2393
2394 if rv.Response.Status != extension.GetValueResponse_OK {
2395 return fmt.Errorf("failed to get onu omci tx rx stats %v", rv.Response.ErrReason.String())
2396 }
2397 outputFormat := CharReplacer.Replace(options.Format)
2398 if outputFormat == "" {
2399 outputFormat = GetCommandOptionWithDefault("device-get-onu-omci-tx-rx-stats", "format", DEFAULT_ONU_OMCI_TX_RX_STATS_FORMAT)
2400 }
2401 result := CommandResult{
2402 Format: format.Format(outputFormat),
2403 OutputAs: toOutputType(options.OutputAs),
2404 NameLimit: options.NameLimit,
2405 Data: rv.GetResponse().GetOnuOmciStats(),
2406 }
2407 GenerateOutput(&result)
2408 return nil
2409}
praneeth nalmas1dd094c2022-12-22 14:15:13 +05302410
2411/*Device get Onu Active Alarms */
2412func (options *GetOnuOmciActiveAlarms) Execute(args []string) error {
2413 conn, err := NewConnection()
2414 if err != nil {
2415 return err
2416 }
2417 defer conn.Close()
2418 client := extension.NewExtensionClient(conn)
2419
2420 singleGetValReq := extension.SingleGetValueRequest{
2421 TargetId: string(options.Args.Id),
2422 Request: &extension.GetValueRequest{
2423 Request: &extension.GetValueRequest_OnuActiveAlarms{
2424 OnuActiveAlarms: &extension.GetOnuOmciActiveAlarmsRequest{},
2425 },
2426 },
2427 }
2428 Info.Printf("Getting omci_active_alarms for device Id %s\n", options.Args.Id)
2429 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2430 defer cancel()
2431 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2432 if err != nil {
2433 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2434 return err
2435 }
2436
2437 if rv.Response.Status != extension.GetValueResponse_OK {
2438 return fmt.Errorf("failed to get onu omci active alarms list %v", rv.Response.ErrReason.String())
2439 }
2440 outputFormat := CharReplacer.Replace(options.Format)
2441 if outputFormat == "" {
2442 outputFormat = GetCommandOptionWithDefault("device-get-onu-omci-active-alarms", "format", DEFAULT_DEVICE_ALARMS_FORMAT)
2443 }
2444
2445 orderBy := options.OrderBy
2446 if orderBy == "" {
2447 orderBy = GetCommandOptionWithDefault("device-list", "order", DEFAULT_DEVICE_ALARMS_ORDER)
2448 }
2449
2450 result := CommandResult{
2451 Format: format.Format(outputFormat),
2452 OutputAs: toOutputType(options.OutputAs),
2453 OrderBy: orderBy,
2454 NameLimit: options.NameLimit,
2455 Data: rv.GetResponse().GetOnuActiveAlarms().GetActiveAlarms(),
2456 }
2457 GenerateOutput(&result)
2458 return nil
2459}
praneeth nalmas39c71ad2023-09-27 18:29:04 +05302460
2461func (options *PonRxPower) Execute(args []string) error {
2462 conn, err := NewConnection()
2463 if err != nil {
2464 return err
2465 }
2466 defer conn.Close()
2467 client := extension.NewExtensionClient(conn)
2468
2469 singleGetValReq := extension.SingleGetValueRequest{
2470 TargetId: string(options.Args.Id),
2471 Request: &extension.GetValueRequest{
2472 Request: &extension.GetValueRequest_OltRxPower{
2473 OltRxPower: &extension.GetOltRxPowerRequest{
2474 PortLabel: options.Args.PortLabel,
2475 OnuSn: options.Args.SerialNo,
2476 },
2477 },
2478 },
2479 }
2480
2481 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2482 defer cancel()
2483 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2484 if err != nil {
2485 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2486 return err
2487 }
2488 if rv.Response.Status != extension.GetValueResponse_OK {
2489 return fmt.Errorf("failed to get rx power %v", rv.Response.ErrReason.String())
2490 }
2491 outputFormat := CharReplacer.Replace(options.Format)
2492 if outputFormat == "" {
2493 outputFormat = GetCommandOptionWithDefault("device-get-pon-rx-power", "format", DEFAULT_PON_RX_POWER_STATUS_FORMAT)
2494 }
2495 result := CommandResult{
2496 Format: format.Format(outputFormat),
2497 OutputAs: toOutputType(options.OutputAs),
2498 NameLimit: options.NameLimit,
2499 Data: rv.GetResponse().GetOltRxPower().GetRxPower(),
2500 }
2501 GenerateOutput(&result)
2502 return nil
2503}