blob: c9410d23f7295e48f63d80ca48083680b20ac58e [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"
Akash Soni66db9632024-04-15 09:05:15 +0530125 DEFAULT_ONU_DISTANCE_FORMAT = `Distance`
Zack Williamse940c7a2019-08-21 14:25:39 -0700126)
127
128type DeviceList struct {
129 ListOutputOptions
130}
131
132type DeviceCreate struct {
David Bainbridge1a514392020-06-23 11:12:51 -0700133 DeviceType string `short:"t" required:"true" long:"devicetype" description:"Device type"`
David Bainbridge835dd0e2020-04-01 10:30:09 -0700134 MACAddress string `short:"m" long:"macaddress" default:"" description:"MAC Address"`
Zack Williamse940c7a2019-08-21 14:25:39 -0700135 IPAddress string `short:"i" long:"ipaddress" default:"" description:"IP Address"`
136 HostAndPort string `short:"H" long:"hostandport" default:"" description:"Host and port"`
137}
138
139type DeviceId string
Akash Soni66db9632024-04-15 09:05:15 +0530140type OnuId string
Zack Williamse940c7a2019-08-21 14:25:39 -0700141
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000142type MetricName string
143type GroupName string
kesavand12cd8eb2020-01-20 22:25:22 -0500144type PortNum uint32
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -0800145type ValueFlag string
kesavand12cd8eb2020-01-20 22:25:22 -0500146
Zack Williamse940c7a2019-08-21 14:25:39 -0700147type DeviceDelete struct {
Himani Chawla9933ddc2020-10-12 23:53:27 +0530148 Force bool `long:"force" description:"Delete device forcefully"`
149 Args struct {
Zack Williamse940c7a2019-08-21 14:25:39 -0700150 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
151 } `positional-args:"yes"`
152}
153
154type DeviceEnable struct {
155 Args struct {
156 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
157 } `positional-args:"yes"`
158}
159
160type DeviceDisable struct {
161 Args struct {
162 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
163 } `positional-args:"yes"`
164}
165
166type DeviceReboot struct {
167 Args struct {
168 Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
169 } `positional-args:"yes"`
170}
171
172type DeviceFlowList struct {
173 ListOutputOptions
Maninder045921e2020-09-29 16:46:02 +0530174 FlowIdOptions
Zack Williamse940c7a2019-08-21 14:25:39 -0700175 Args struct {
176 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
177 } `positional-args:"yes"`
178}
179
Himani Chawla3c161c62021-05-13 16:36:51 +0530180type DeviceFlowGroupList struct {
181 ListOutputOptions
182 GroupListOptions
183 Args struct {
184 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
185 } `positional-args:"yes"`
186}
Zack Williamse940c7a2019-08-21 14:25:39 -0700187type DevicePortList struct {
188 ListOutputOptions
189 Args struct {
190 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
191 } `positional-args:"yes"`
192}
193
194type DeviceInspect struct {
195 OutputOptionsJson
196 Args struct {
197 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
198 } `positional-args:"yes"`
199}
200
kesavand12cd8eb2020-01-20 22:25:22 -0500201type DevicePortEnable struct {
202 Args struct {
203 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
204 PortId PortNum `positional-arg-name:"PORT_NUMBER" required:"yes"`
205 } `positional-args:"yes"`
206}
207
208type DevicePortDisable struct {
209 Args struct {
210 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
211 PortId PortNum `positional-arg-name:"PORT_NUMBER" required:"yes"`
212 } `positional-args:"yes"`
213}
214
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000215type DevicePmConfigsGet struct {
216 ListOutputOptions
217 Args struct {
218 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
219 } `positional-args:"yes"`
220}
221
222type DevicePmConfigMetricList struct {
223 ListOutputOptions
224 Args struct {
225 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
226 } `positional-args:"yes"`
227}
228
229type DevicePmConfigGroupList struct {
230 ListOutputOptions
231 Args struct {
232 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
233 } `positional-args:"yes"`
234}
235
236type DevicePmConfigGroupMetricList struct {
237 ListOutputOptions
238 Args struct {
239 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
240 Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"`
241 } `positional-args:"yes"`
242}
243
244type DevicePmConfigFrequencySet struct {
245 OutputOptions
246 Args struct {
Girish Gowdra610acb42021-01-27 13:33:57 -0800247 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
248 Interval time.Duration `positional-arg-name:"INTERVAL" required:"yes"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000249 } `positional-args:"yes"`
250}
251
252type DevicePmConfigMetricEnable struct {
253 Args struct {
254 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
255 Metrics []MetricName `positional-arg-name:"METRIC_NAME" required:"yes"`
256 } `positional-args:"yes"`
257}
258
259type DevicePmConfigMetricDisable struct {
260 Args struct {
261 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
262 Metrics []MetricName `positional-arg-name:"METRIC_NAME" required:"yes"`
263 } `positional-args:"yes"`
264}
265
266type DevicePmConfigGroupEnable struct {
267 Args struct {
Girish Gowdra610acb42021-01-27 13:33:57 -0800268 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
269 Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000270 } `positional-args:"yes"`
271}
272
273type DevicePmConfigGroupDisable struct {
274 Args struct {
Girish Gowdra610acb42021-01-27 13:33:57 -0800275 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
276 Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"`
277 } `positional-args:"yes"`
278}
279
280type DevicePmConfigGroupFrequencySet struct {
281 OutputOptions
282 Args struct {
283 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
284 Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"`
285 Interval time.Duration `positional-arg-name:"INTERVAL" required:"yes"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000286 } `positional-args:"yes"`
287}
288
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -0800289type DeviceGetExtValue struct {
290 ListOutputOptions
291 Args struct {
292 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
293 Valueflag ValueFlag `positional-arg-name:"VALUE_FLAG" required:"yes"`
294 } `positional-args:"yes"`
295}
Rohan Agrawald7df3772020-06-29 11:23:36 +0000296
297type DevicePmConfigSetMaxSkew struct {
298 Args struct {
299 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
300 MaxSkew uint32 `positional-arg-name:"MAX_SKEW" required:"yes"`
301 } `positional-args:"yes"`
302}
303
Andrea Campanella791d88b2021-01-08 13:29:00 +0100304type DeviceOnuListImages struct {
305 ListOutputOptions
306 Args struct {
307 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
308 } `positional-args:"yes"`
309}
310
311type DeviceOnuDownloadImage struct {
312 Args struct {
313 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
314 Name string `positional-arg-name:"IMAGE_NAME" required:"yes"`
315 Url string `positional-arg-name:"IMAGE_URL" required:"yes"`
316 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
317 Crc uint32 `positional-arg-name:"IMAGE_CRC" required:"yes"`
318 LocalDir string `positional-arg-name:"IMAGE_LOCAL_DIRECTORY"`
319 } `positional-args:"yes"`
320}
321
322type DeviceOnuActivateImageUpdate struct {
323 Args struct {
324 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
325 Name string `positional-arg-name:"IMAGE_NAME" required:"yes"`
326 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
327 SaveConfig bool `positional-arg-name:"SAVE_EXISTING_CONFIG"`
328 LocalDir string `positional-arg-name:"IMAGE_LOCAL_DIRECTORY"`
Andrea Campanella7b2ecf42021-02-25 12:27:15 +0100329 } `positional-args:"yes"`
kesavand8ec4fc02021-01-27 09:10:22 -0500330}
kesavand3e2f9f62021-04-22 11:06:38 +0530331
332type OnuDownloadImage struct {
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +0200333 ListOutputOptions
kesavand3e2f9f62021-04-22 11:06:38 +0530334 Args struct {
335 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
336 Url string `positional-arg-name:"IMAGE_URL" required:"yes"`
ssiddiqui7bc89e92021-05-20 20:58:02 +0530337 Vendor string `positional-arg-name:"IMAGE_VENDOR"`
kesavand3e2f9f62021-04-22 11:06:38 +0530338 ActivateOnSuccess bool `positional-arg-name:"IMAGE_ACTIVATE_ON_SUCCESS"`
339 CommitOnSuccess bool `positional-arg-name:"IMAGE_COMMIT_ON_SUCCESS"`
340 Crc uint32 `positional-arg-name:"IMAGE_CRC"`
341 IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
342 } `positional-args:"yes"`
343}
344
345type OnuActivateImage struct {
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +0200346 ListOutputOptions
kesavand3e2f9f62021-04-22 11:06:38 +0530347 Args struct {
348 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
349 CommitOnSuccess bool `positional-arg-name:"IMAGE_COMMIT_ON_SUCCESS"`
350 IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
351 } `positional-args:"yes"`
352}
353
354type OnuAbortUpgradeImage struct {
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +0200355 ListOutputOptions
kesavand3e2f9f62021-04-22 11:06:38 +0530356 Args struct {
357 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
358 IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
359 } `positional-args:"yes"`
360}
361
362type OnuCommitImage struct {
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +0200363 ListOutputOptions
kesavand3e2f9f62021-04-22 11:06:38 +0530364 Args struct {
365 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
366 IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
367 } `positional-args:"yes"`
368}
369
370type OnuImageStatus struct {
371 ListOutputOptions
372 Args struct {
373 ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"`
Elia Battiston859f3e62022-02-08 15:57:52 +0100374 IDs []DeviceId `positional-arg-name:"DEVICE_ID"`
kesavand3e2f9f62021-04-22 11:06:38 +0530375 } `positional-args:"yes"`
376}
377
378type OnuListImages struct {
379 ListOutputOptions
380 Args struct {
381 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
382 } `positional-args:"yes"`
383}
384
kesavand8ec4fc02021-01-27 09:10:22 -0500385type DeviceGetPortStats struct {
386 ListOutputOptions
387 Args struct {
388 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
389 PortNo uint32 `positional-arg-name:"PORT_NO" required:"yes"`
390 PortType string `positional-arg-name:"PORT_TYPE" required:"yes"`
Andrea Campanella791d88b2021-01-08 13:29:00 +0100391 } `positional-args:"yes"`
392}
kesavand6d1131f2021-02-05 22:38:15 +0530393type UniStatus struct {
394 ListOutputOptions
395 Args struct {
396 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
397 UniIndex uint32 `positional-arg-name:"UNI_INDEX" required:"yes"`
398 } `positional-args:"yes"`
399}
Girish Gowdra4f5ce7c2021-04-29 18:53:21 -0700400type OnuPonOpticalInfo struct {
401 ListOutputOptions
402 Args struct {
403 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
404 } `positional-args:"yes"`
405}
Himani Chawla40acc122021-05-26 18:52:29 +0530406
407type GetOnuStats struct {
408 ListOutputOptions
409 Args struct {
410 OltId DeviceId `positional-arg-name:"OLT_DEVICE_ID" required:"yes"`
411 IntfId uint32 `positional-arg-name:"PON_INTF_ID" required:"yes"`
412 OnuId uint32 `positional-arg-name:"ONU_ID" required:"yes"`
413 } `positional-args:"yes"`
414}
415
Himani Chawla553a1392021-06-10 23:39:17 +0530416type GetOnuEthernetFrameExtendedPmCounters struct {
417 ListOutputOptions
Himani Chawla806aa892021-08-30 15:51:46 +0530418 Reset bool `long:"reset" description:"Reset the counters"`
419 Args struct {
420 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
421 UniIndex *uint32 `positional-arg-name:"UNI_INDEX"`
Himani Chawla553a1392021-06-10 23:39:17 +0530422 } `positional-args:"yes"`
423}
424
Gamze Abakac857a462021-05-26 13:45:54 +0000425type RxPower struct {
426 ListOutputOptions
427 Args struct {
428 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
429 PortNo uint32 `positional-arg-name:"PORT_NO" required:"yes"`
430 OnuNo uint32 `positional-arg-name:"ONU_NO" required:"yes"`
431 } `positional-args:"yes"`
432}
433
praneeth nalmas39c71ad2023-09-27 18:29:04 +0530434type PonRxPower struct {
435 ListOutputOptions
436 Args struct {
437 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
438 PortLabel string `positional-arg-name:"PORT_LABEL" required:"yes"`
439 SerialNo string `positional-arg-name:"ONU_SERIAL_NUMBER"`
440 } `positional-args:"yes"`
441}
442
serkantul3d22fc72022-09-14 12:22:56 +0300443type OnuOmciTxRxStats struct {
444 ListOutputOptions
445 Args struct {
446 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
447 } `positional-args:"yes"`
448}
449
praneeth nalmas1dd094c2022-12-22 14:15:13 +0530450type GetOnuOmciActiveAlarms struct {
451 ListOutputOptions
452 Args struct {
453 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
454 } `positional-args:"yes"`
455}
456
Akash Soni66db9632024-04-15 09:05:15 +0530457type GetOnuDistance struct {
458 ListOutputOptions
459 Args struct {
460 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
461 OnuId OnuId `positional-arg-name:"ONU_ID" required:"yes"`
462 } `positional-args:"yes"` //onu device id
463}
464
Zack Williamse940c7a2019-08-21 14:25:39 -0700465type DeviceOpts struct {
Himani Chawla3c161c62021-05-13 16:36:51 +0530466 List DeviceList `command:"list"`
467 Create DeviceCreate `command:"create"`
468 Delete DeviceDelete `command:"delete"`
469 Enable DeviceEnable `command:"enable"`
470 Disable DeviceDisable `command:"disable"`
471 Flows DeviceFlowList `command:"flows"`
472 Groups DeviceFlowGroupList `command:"groups"`
kesavand12cd8eb2020-01-20 22:25:22 -0500473 Port struct {
474 List DevicePortList `command:"list"`
475 Enable DevicePortEnable `command:"enable"`
476 Disable DevicePortDisable `command:"disable"`
477 } `command:"port"`
478 Inspect DeviceInspect `command:"inspect"`
479 Reboot DeviceReboot `command:"reboot"`
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -0800480 Value struct {
481 Get DeviceGetExtValue `command:"get"`
482 } `command:"value"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000483 PmConfig struct {
Rohan Agrawald7df3772020-06-29 11:23:36 +0000484 Get DevicePmConfigsGet `command:"get"`
485 MaxSkew struct {
486 Set DevicePmConfigSetMaxSkew `command:"set"`
487 } `command:"maxskew"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000488 Frequency struct {
489 Set DevicePmConfigFrequencySet `command:"set"`
490 } `command:"frequency"`
491 Metric struct {
492 List DevicePmConfigMetricList `command:"list"`
493 Enable DevicePmConfigMetricEnable `command:"enable"`
494 Disable DevicePmConfigMetricDisable `command:"disable"`
495 } `command:"metric"`
496 Group struct {
Girish Gowdra610acb42021-01-27 13:33:57 -0800497 List DevicePmConfigGroupList `command:"list"`
498 Enable DevicePmConfigGroupEnable `command:"enable"`
499 Disable DevicePmConfigGroupDisable `command:"disable"`
500 Set DevicePmConfigGroupFrequencySet `command:"set"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000501 } `command:"group"`
502 GroupMetric struct {
503 List DevicePmConfigGroupMetricList `command:"list"`
504 } `command:"groupmetric"`
505 } `command:"pmconfig"`
Andrea Campanella791d88b2021-01-08 13:29:00 +0100506 Image struct {
507 Get DeviceOnuListImages `command:"list"`
508 Download DeviceOnuDownloadImage `command:"download"`
509 Activate DeviceOnuActivateImageUpdate `command:"activate"`
510 } `command:"image"`
kesavand3e2f9f62021-04-22 11:06:38 +0530511 DownloadImage struct {
512 Download OnuDownloadImage `command:"download"`
513 Activate OnuActivateImage `command:"activate"`
514 Commit OnuCommitImage `command:"commit"`
515 AbortUpgrade OnuAbortUpgradeImage `command:"abort"`
516 Status OnuImageStatus `command:"status"`
517 List OnuListImages `command:"list" `
518 } `command:"onuimage"`
kesavand8ec4fc02021-01-27 09:10:22 -0500519 GetExtVal struct {
Himani Chawla553a1392021-06-10 23:39:17 +0530520 Stats DeviceGetPortStats `command:"portstats"`
521 UniStatus UniStatus `command:"unistatus"`
522 OpticalInfo OnuPonOpticalInfo `command:"onu_pon_optical_info"`
523 OnuStats GetOnuStats `command:"onu_stats"`
524 EthernetFrameExtendedPm GetOnuEthernetFrameExtendedPmCounters `command:"ethernet_frame_extended_pm"`
525 RxPower RxPower `command:"rxpower"`
serkantul3d22fc72022-09-14 12:22:56 +0300526 OnuOmciStats OnuOmciTxRxStats `command:"onu_omci_stats"`
praneeth nalmas1dd094c2022-12-22 14:15:13 +0530527 OnuOmciActiveAlarms GetOnuOmciActiveAlarms `command:"onu_omci_active_alarms"`
praneeth nalmas39c71ad2023-09-27 18:29:04 +0530528 PonRxPower PonRxPower `command:"pon_rx_power"`
Akash Soni66db9632024-04-15 09:05:15 +0530529 OnuDistance GetOnuDistance `command:"onu_distance"`
kesavand8ec4fc02021-01-27 09:10:22 -0500530 } `command:"getextval"`
Zack Williamse940c7a2019-08-21 14:25:39 -0700531}
532
533var deviceOpts = DeviceOpts{}
534
535func RegisterDeviceCommands(parser *flags.Parser) {
David Bainbridge12f036f2019-10-15 22:09:04 +0000536 if _, err := parser.AddCommand("device", "device commands", "Commands to query and manipulate VOLTHA devices", &deviceOpts); err != nil {
David Bainbridgea6722342019-10-24 23:55:53 +0000537 Error.Fatalf("Unexpected error while attempting to register device commands : %s", err)
David Bainbridge12f036f2019-10-15 22:09:04 +0000538 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700539}
540
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000541func (i *MetricName) Complete(match string) []flags.Completion {
542 conn, err := NewConnection()
543 if err != nil {
544 return nil
545 }
546 defer conn.Close()
547
548 client := voltha.NewVolthaServiceClient(conn)
549
550 var deviceId string
551found:
552 for i := len(os.Args) - 1; i >= 0; i -= 1 {
553 switch os.Args[i] {
554 case "enable":
555 fallthrough
556 case "disable":
557 if len(os.Args) > i+1 {
558 deviceId = os.Args[i+1]
559 } else {
560 return nil
561 }
562 break found
563 default:
564 }
565 }
566
567 if len(deviceId) == 0 {
568 return nil
569 }
570
David K. Bainbridge9189c632021-03-26 21:52:21 +0000571 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000572 defer cancel()
573
574 id := voltha.ID{Id: string(deviceId)}
575
576 pmconfigs, err := client.ListDevicePmConfigs(ctx, &id)
577
578 if err != nil {
579 return nil
580 }
581
582 list := make([]flags.Completion, 0)
583 for _, metrics := range pmconfigs.Metrics {
584 if strings.HasPrefix(metrics.Name, match) {
585 list = append(list, flags.Completion{Item: metrics.Name})
586 }
587 }
588
589 return list
590}
591
592func (i *GroupName) Complete(match string) []flags.Completion {
593 conn, err := NewConnection()
594 if err != nil {
595 return nil
596 }
597 defer conn.Close()
598
599 client := voltha.NewVolthaServiceClient(conn)
600
601 var deviceId string
602found:
603 for i := len(os.Args) - 1; i >= 0; i -= 1 {
604 switch os.Args[i] {
605 case "list":
606 fallthrough
607 case "enable":
608 fallthrough
609 case "disable":
610 if len(os.Args) > i+1 {
611 deviceId = os.Args[i+1]
612 } else {
613 return nil
614 }
615 break found
616 default:
617 }
618 }
619
620 if len(deviceId) == 0 {
621 return nil
622 }
623
David K. Bainbridge9189c632021-03-26 21:52:21 +0000624 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000625 defer cancel()
626
627 id := voltha.ID{Id: string(deviceId)}
628
629 pmconfigs, err := client.ListDevicePmConfigs(ctx, &id)
630
631 if err != nil {
632 return nil
633 }
634
635 list := make([]flags.Completion, 0)
636 for _, group := range pmconfigs.Groups {
637 if strings.HasPrefix(group.GroupName, match) {
638 list = append(list, flags.Completion{Item: group.GroupName})
639 }
640 }
641 return list
642}
643
kesavand12cd8eb2020-01-20 22:25:22 -0500644func (i *PortNum) Complete(match string) []flags.Completion {
645 conn, err := NewConnection()
646 if err != nil {
647 return nil
648 }
649 defer conn.Close()
650
Scott Baker9173ed82020-05-19 08:30:12 -0700651 client := voltha.NewVolthaServiceClient(conn)
kesavand12cd8eb2020-01-20 22:25:22 -0500652
653 /*
654 * The command line args when completing for PortNum will be a DeviceId
655 * followed by one or more PortNums. So walk the argument list from the
656 * end and find the first argument that is enable/disable as those are
657 * the subcommands that come before the positional arguments. It would
658 * be nice if this package gave us the list of optional arguments
659 * already parsed.
660 */
661 var deviceId string
662found:
663 for i := len(os.Args) - 1; i >= 0; i -= 1 {
664 switch os.Args[i] {
665 case "enable":
666 fallthrough
667 case "disable":
668 if len(os.Args) > i+1 {
669 deviceId = os.Args[i+1]
670 } else {
671 return nil
672 }
673 break found
674 default:
675 }
676 }
677
678 if len(deviceId) == 0 {
679 return nil
680 }
681
David K. Bainbridge9189c632021-03-26 21:52:21 +0000682 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand12cd8eb2020-01-20 22:25:22 -0500683 defer cancel()
kesavand12cd8eb2020-01-20 22:25:22 -0500684
Scott Baker9173ed82020-05-19 08:30:12 -0700685 id := voltha.ID{Id: string(deviceId)}
kesavand12cd8eb2020-01-20 22:25:22 -0500686
Scott Baker9173ed82020-05-19 08:30:12 -0700687 ports, err := client.ListDevicePorts(ctx, &id)
kesavand12cd8eb2020-01-20 22:25:22 -0500688 if err != nil {
689 return nil
690 }
691
692 list := make([]flags.Completion, 0)
Scott Baker9173ed82020-05-19 08:30:12 -0700693 for _, item := range ports.Items {
694 pn := strconv.FormatUint(uint64(item.PortNo), 10)
kesavand12cd8eb2020-01-20 22:25:22 -0500695 if strings.HasPrefix(pn, match) {
696 list = append(list, flags.Completion{Item: pn})
697 }
698 }
699
700 return list
701}
702
Zack Williamse940c7a2019-08-21 14:25:39 -0700703func (i *DeviceId) Complete(match string) []flags.Completion {
704 conn, err := NewConnection()
705 if err != nil {
706 return nil
707 }
708 defer conn.Close()
709
Scott Baker9173ed82020-05-19 08:30:12 -0700710 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700711
David K. Bainbridge9189c632021-03-26 21:52:21 +0000712 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700713 defer cancel()
714
Scott Baker9173ed82020-05-19 08:30:12 -0700715 devices, err := client.ListDevices(ctx, &empty.Empty{})
Zack Williamse940c7a2019-08-21 14:25:39 -0700716 if err != nil {
717 return nil
718 }
719
720 list := make([]flags.Completion, 0)
Scott Baker9173ed82020-05-19 08:30:12 -0700721 for _, item := range devices.Items {
722 if strings.HasPrefix(item.Id, match) {
723 list = append(list, flags.Completion{Item: item.Id})
Zack Williamse940c7a2019-08-21 14:25:39 -0700724 }
725 }
726
727 return list
728}
729
730func (options *DeviceList) Execute(args []string) error {
731
732 conn, err := NewConnection()
733 if err != nil {
734 return err
735 }
736 defer conn.Close()
737
Scott Baker9173ed82020-05-19 08:30:12 -0700738 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700739
David K. Bainbridge9189c632021-03-26 21:52:21 +0000740 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700741 defer cancel()
742
Scott Baker9173ed82020-05-19 08:30:12 -0700743 devices, err := client.ListDevices(ctx, &empty.Empty{})
Zack Williamse940c7a2019-08-21 14:25:39 -0700744 if err != nil {
745 return err
746 }
747
748 outputFormat := CharReplacer.Replace(options.Format)
749 if outputFormat == "" {
David Bainbridgea6722342019-10-24 23:55:53 +0000750 outputFormat = GetCommandOptionWithDefault("device-list", "format", DEFAULT_DEVICE_FORMAT)
Zack Williamse940c7a2019-08-21 14:25:39 -0700751 }
752 if options.Quiet {
753 outputFormat = "{{.Id}}"
754 }
755
David Bainbridgea6722342019-10-24 23:55:53 +0000756 orderBy := options.OrderBy
757 if orderBy == "" {
Hardik Windlass9361bb82022-03-23 05:58:48 +0000758 orderBy = GetCommandOptionWithDefault("device-list", "order", DEFAULT_DEVICE_ORDER)
David Bainbridgea6722342019-10-24 23:55:53 +0000759 }
760
Scott Baker9173ed82020-05-19 08:30:12 -0700761 // Make sure json output prints an empty list, not "null"
762 if devices.Items == nil {
763 devices.Items = make([]*voltha.Device, 0)
Zack Williamse940c7a2019-08-21 14:25:39 -0700764 }
765
766 result := CommandResult{
767 Format: format.Format(outputFormat),
768 Filter: options.Filter,
David Bainbridgea6722342019-10-24 23:55:53 +0000769 OrderBy: orderBy,
Zack Williamse940c7a2019-08-21 14:25:39 -0700770 OutputAs: toOutputType(options.OutputAs),
771 NameLimit: options.NameLimit,
Scott Baker9173ed82020-05-19 08:30:12 -0700772 Data: devices.Items,
Zack Williamse940c7a2019-08-21 14:25:39 -0700773 }
774
775 GenerateOutput(&result)
776 return nil
777}
778
779func (options *DeviceCreate) Execute(args []string) error {
780
Scott Baker9173ed82020-05-19 08:30:12 -0700781 device := voltha.Device{}
Zack Williamse940c7a2019-08-21 14:25:39 -0700782 if options.HostAndPort != "" {
Scott Baker9173ed82020-05-19 08:30:12 -0700783 device.Address = &voltha.Device_HostAndPort{HostAndPort: options.HostAndPort}
Zack Williamse940c7a2019-08-21 14:25:39 -0700784 } else if options.IPAddress != "" {
Scott Baker9173ed82020-05-19 08:30:12 -0700785 device.Address = &voltha.Device_Ipv4Address{Ipv4Address: options.IPAddress}
Hardik Windlassce1de342020-02-04 21:58:07 +0000786 }
787 if options.MACAddress != "" {
Scott Baker9173ed82020-05-19 08:30:12 -0700788 device.MacAddress = strings.ToLower(options.MACAddress)
Zack Williamse940c7a2019-08-21 14:25:39 -0700789 }
790 if options.DeviceType != "" {
Scott Baker9173ed82020-05-19 08:30:12 -0700791 device.Type = options.DeviceType
Zack Williamse940c7a2019-08-21 14:25:39 -0700792 }
793
794 conn, err := NewConnection()
795 if err != nil {
796 return err
797 }
798 defer conn.Close()
799
Scott Baker9173ed82020-05-19 08:30:12 -0700800 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700801
David K. Bainbridge9189c632021-03-26 21:52:21 +0000802 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700803 defer cancel()
804
Scott Baker9173ed82020-05-19 08:30:12 -0700805 createdDevice, err := client.CreateDevice(ctx, &device)
Zack Williamse940c7a2019-08-21 14:25:39 -0700806 if err != nil {
807 return err
Zack Williamse940c7a2019-08-21 14:25:39 -0700808 }
809
Scott Baker9173ed82020-05-19 08:30:12 -0700810 fmt.Printf("%s\n", createdDevice.Id)
Zack Williamse940c7a2019-08-21 14:25:39 -0700811
812 return nil
813}
814
815func (options *DeviceDelete) Execute(args []string) error {
816
817 conn, err := NewConnection()
818 if err != nil {
819 return err
820 }
821 defer conn.Close()
822
Scott Baker9173ed82020-05-19 08:30:12 -0700823 client := voltha.NewVolthaServiceClient(conn)
David Bainbridge7052fe82020-03-25 10:37:00 -0700824 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -0700825 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +0000826 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700827 defer cancel()
828
Scott Baker9173ed82020-05-19 08:30:12 -0700829 id := voltha.ID{Id: string(i)}
Himani Chawla9933ddc2020-10-12 23:53:27 +0530830 if options.Force {
831 _, err = client.ForceDeleteDevice(ctx, &id)
832 } else {
833 _, err = client.DeleteDevice(ctx, &id)
834 }
Scott Baker9173ed82020-05-19 08:30:12 -0700835
Zack Williamse940c7a2019-08-21 14:25:39 -0700836 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +0000837 Error.Printf("Error while deleting '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -0700838 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -0700839 continue
Zack Williamse940c7a2019-08-21 14:25:39 -0700840 }
841 fmt.Printf("%s\n", i)
842 }
843
David Bainbridge7052fe82020-03-25 10:37:00 -0700844 if lastErr != nil {
845 return NoReportErr
846 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700847 return nil
848}
849
850func (options *DeviceEnable) Execute(args []string) error {
851 conn, err := NewConnection()
852 if err != nil {
853 return err
854 }
855 defer conn.Close()
856
Scott Baker9173ed82020-05-19 08:30:12 -0700857 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700858
David Bainbridge7052fe82020-03-25 10:37:00 -0700859 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -0700860 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +0000861 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700862 defer cancel()
863
Scott Baker9173ed82020-05-19 08:30:12 -0700864 id := voltha.ID{Id: string(i)}
865
866 _, err := client.EnableDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -0700867 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +0000868 Error.Printf("Error while enabling '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -0700869 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -0700870 continue
Zack Williamse940c7a2019-08-21 14:25:39 -0700871 }
872 fmt.Printf("%s\n", i)
873 }
874
David Bainbridge7052fe82020-03-25 10:37:00 -0700875 if lastErr != nil {
876 return NoReportErr
877 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700878 return nil
879}
880
881func (options *DeviceDisable) Execute(args []string) error {
882 conn, err := NewConnection()
883 if err != nil {
884 return err
885 }
886 defer conn.Close()
887
Scott Baker9173ed82020-05-19 08:30:12 -0700888 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700889
David Bainbridge7052fe82020-03-25 10:37:00 -0700890 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -0700891 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +0000892 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700893 defer cancel()
894
Scott Baker9173ed82020-05-19 08:30:12 -0700895 id := voltha.ID{Id: string(i)}
896
897 _, err := client.DisableDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -0700898 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +0000899 Error.Printf("Error while disabling '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -0700900 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -0700901 continue
Zack Williamse940c7a2019-08-21 14:25:39 -0700902 }
903 fmt.Printf("%s\n", i)
904 }
905
David Bainbridge7052fe82020-03-25 10:37:00 -0700906 if lastErr != nil {
907 return NoReportErr
908 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700909 return nil
910}
911
912func (options *DeviceReboot) Execute(args []string) error {
913 conn, err := NewConnection()
914 if err != nil {
915 return err
916 }
917 defer conn.Close()
918
Scott Baker9173ed82020-05-19 08:30:12 -0700919 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700920
David Bainbridge7052fe82020-03-25 10:37:00 -0700921 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -0700922 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +0000923 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700924 defer cancel()
925
Scott Baker9173ed82020-05-19 08:30:12 -0700926 id := voltha.ID{Id: string(i)}
927
928 _, err := client.RebootDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -0700929 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +0000930 Error.Printf("Error while rebooting '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -0700931 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -0700932 continue
Zack Williamse940c7a2019-08-21 14:25:39 -0700933 }
934 fmt.Printf("%s\n", i)
935 }
936
David Bainbridge7052fe82020-03-25 10:37:00 -0700937 if lastErr != nil {
938 return NoReportErr
939 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700940 return nil
941}
942
943func (options *DevicePortList) Execute(args []string) error {
944
945 conn, err := NewConnection()
946 if err != nil {
947 return err
948 }
949 defer conn.Close()
950
Scott Baker9173ed82020-05-19 08:30:12 -0700951 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700952
David K. Bainbridge9189c632021-03-26 21:52:21 +0000953 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700954 defer cancel()
955
Scott Baker9173ed82020-05-19 08:30:12 -0700956 id := voltha.ID{Id: string(options.Args.Id)}
Zack Williamse940c7a2019-08-21 14:25:39 -0700957
Scott Baker9173ed82020-05-19 08:30:12 -0700958 ports, err := client.ListDevicePorts(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -0700959 if err != nil {
960 return err
961 }
962
963 outputFormat := CharReplacer.Replace(options.Format)
964 if outputFormat == "" {
David Bainbridgea6722342019-10-24 23:55:53 +0000965 outputFormat = GetCommandOptionWithDefault("device-ports", "format", DEFAULT_DEVICE_PORTS_FORMAT)
Zack Williamse940c7a2019-08-21 14:25:39 -0700966 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700967
David Bainbridgea6722342019-10-24 23:55:53 +0000968 orderBy := options.OrderBy
969 if orderBy == "" {
970 orderBy = GetCommandOptionWithDefault("device-ports", "order", "")
971 }
972
Zack Williamse940c7a2019-08-21 14:25:39 -0700973 result := CommandResult{
974 Format: format.Format(outputFormat),
975 Filter: options.Filter,
David Bainbridgea6722342019-10-24 23:55:53 +0000976 OrderBy: orderBy,
Zack Williamse940c7a2019-08-21 14:25:39 -0700977 OutputAs: toOutputType(options.OutputAs),
978 NameLimit: options.NameLimit,
Scott Baker9173ed82020-05-19 08:30:12 -0700979 Data: ports.Items,
Zack Williamse940c7a2019-08-21 14:25:39 -0700980 }
981
982 GenerateOutput(&result)
983 return nil
984}
985
986func (options *DeviceFlowList) Execute(args []string) error {
987 fl := &FlowList{}
988 fl.ListOutputOptions = options.ListOutputOptions
Maninder045921e2020-09-29 16:46:02 +0530989 fl.FlowIdOptions = options.FlowIdOptions
Zack Williamse940c7a2019-08-21 14:25:39 -0700990 fl.Args.Id = string(options.Args.Id)
David Bainbridgea6722342019-10-24 23:55:53 +0000991 fl.Method = "device-flows"
Zack Williamse940c7a2019-08-21 14:25:39 -0700992 return fl.Execute(args)
993}
994
Himani Chawla3c161c62021-05-13 16:36:51 +0530995func (options *DeviceFlowGroupList) Execute(args []string) error {
996 grp := &GroupList{}
997 grp.ListOutputOptions = options.ListOutputOptions
998 grp.GroupListOptions = options.GroupListOptions
999 grp.Args.Id = string(options.Args.Id)
1000 grp.Method = "device-groups"
1001 return grp.Execute(args)
1002}
1003
Zack Williamse940c7a2019-08-21 14:25:39 -07001004func (options *DeviceInspect) Execute(args []string) error {
1005 if len(args) > 0 {
1006 return fmt.Errorf("only a single argument 'DEVICE_ID' can be provided")
1007 }
1008
1009 conn, err := NewConnection()
1010 if err != nil {
1011 return err
1012 }
1013 defer conn.Close()
1014
Scott Baker9173ed82020-05-19 08:30:12 -07001015 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -07001016
David K. Bainbridge9189c632021-03-26 21:52:21 +00001017 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -07001018 defer cancel()
1019
Scott Baker9173ed82020-05-19 08:30:12 -07001020 id := voltha.ID{Id: string(options.Args.Id)}
Zack Williamse940c7a2019-08-21 14:25:39 -07001021
Scott Baker9173ed82020-05-19 08:30:12 -07001022 device, err := client.GetDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -07001023 if err != nil {
1024 return err
1025 }
1026
Zack Williamse940c7a2019-08-21 14:25:39 -07001027 outputFormat := CharReplacer.Replace(options.Format)
1028 if outputFormat == "" {
David Bainbridgea6722342019-10-24 23:55:53 +00001029 outputFormat = GetCommandOptionWithDefault("device-inspect", "format", DEFAULT_DEVICE_INSPECT_FORMAT)
Zack Williamse940c7a2019-08-21 14:25:39 -07001030 }
1031 if options.Quiet {
1032 outputFormat = "{{.Id}}"
1033 }
1034
1035 result := CommandResult{
1036 Format: format.Format(outputFormat),
1037 OutputAs: toOutputType(options.OutputAs),
1038 NameLimit: options.NameLimit,
1039 Data: device,
1040 }
1041 GenerateOutput(&result)
1042 return nil
1043}
kesavand12cd8eb2020-01-20 22:25:22 -05001044
1045/*Device Port Enable */
1046func (options *DevicePortEnable) Execute(args []string) error {
1047 conn, err := NewConnection()
1048 if err != nil {
1049 return err
1050 }
1051 defer conn.Close()
1052
Scott Baker9173ed82020-05-19 08:30:12 -07001053 client := voltha.NewVolthaServiceClient(conn)
kesavand12cd8eb2020-01-20 22:25:22 -05001054
David K. Bainbridge9189c632021-03-26 21:52:21 +00001055 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand12cd8eb2020-01-20 22:25:22 -05001056 defer cancel()
1057
Scott Baker9173ed82020-05-19 08:30:12 -07001058 port := voltha.Port{DeviceId: string(options.Args.Id), PortNo: uint32(options.Args.PortId)}
1059
1060 _, err = client.EnablePort(ctx, &port)
kesavand12cd8eb2020-01-20 22:25:22 -05001061 if err != nil {
1062 Error.Printf("Error enabling port number %v on device Id %s,err=%s\n", options.Args.PortId, options.Args.Id, ErrorToString(err))
1063 return err
kesavand12cd8eb2020-01-20 22:25:22 -05001064 }
1065
1066 return nil
1067}
1068
Scott Baker9173ed82020-05-19 08:30:12 -07001069/*Device Port Disable */
kesavand12cd8eb2020-01-20 22:25:22 -05001070func (options *DevicePortDisable) Execute(args []string) error {
1071 conn, err := NewConnection()
1072 if err != nil {
1073 return err
1074 }
1075 defer conn.Close()
1076
Scott Baker9173ed82020-05-19 08:30:12 -07001077 client := voltha.NewVolthaServiceClient(conn)
1078
David K. Bainbridge9189c632021-03-26 21:52:21 +00001079 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand12cd8eb2020-01-20 22:25:22 -05001080 defer cancel()
1081
Scott Baker9173ed82020-05-19 08:30:12 -07001082 port := voltha.Port{DeviceId: string(options.Args.Id), PortNo: uint32(options.Args.PortId)}
1083
1084 _, err = client.DisablePort(ctx, &port)
kesavand12cd8eb2020-01-20 22:25:22 -05001085 if err != nil {
Scott Baker9173ed82020-05-19 08:30:12 -07001086 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 -05001087 return err
kesavand12cd8eb2020-01-20 22:25:22 -05001088 }
Scott Baker9173ed82020-05-19 08:30:12 -07001089
kesavand12cd8eb2020-01-20 22:25:22 -05001090 return nil
1091}
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08001092
Rohan Agrawald7df3772020-06-29 11:23:36 +00001093func (options *DevicePmConfigSetMaxSkew) Execute(args []string) error {
1094 conn, err := NewConnection()
1095 if err != nil {
1096 return err
1097 }
1098 defer conn.Close()
1099
1100 client := voltha.NewVolthaServiceClient(conn)
1101
David K. Bainbridge9189c632021-03-26 21:52:21 +00001102 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawald7df3772020-06-29 11:23:36 +00001103 defer cancel()
1104
1105 id := voltha.ID{Id: string(options.Args.Id)}
1106
1107 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1108 if err != nil {
1109 return err
1110 }
1111
1112 pmConfigs.MaxSkew = options.Args.MaxSkew
1113
1114 _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs)
1115 if err != nil {
1116 return err
1117 }
1118
1119 return nil
1120}
1121
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001122func (options *DevicePmConfigsGet) Execute(args []string) error {
1123
1124 conn, err := NewConnection()
1125 if err != nil {
1126 return err
1127 }
1128 defer conn.Close()
1129
1130 client := voltha.NewVolthaServiceClient(conn)
1131
David K. Bainbridge9189c632021-03-26 21:52:21 +00001132 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001133 defer cancel()
1134
1135 id := voltha.ID{Id: string(options.Args.Id)}
1136
1137 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1138 if err != nil {
1139 return err
1140 }
1141
1142 outputFormat := CharReplacer.Replace(options.Format)
1143 if outputFormat == "" {
1144 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GET_FORMAT)
1145 }
1146
1147 orderBy := options.OrderBy
1148 if orderBy == "" {
1149 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1150 }
1151
1152 result := CommandResult{
1153 Format: format.Format(outputFormat),
1154 Filter: options.Filter,
1155 OrderBy: orderBy,
1156 OutputAs: toOutputType(options.OutputAs),
1157 NameLimit: options.NameLimit,
1158 Data: pmConfigs,
1159 }
1160
1161 GenerateOutput(&result)
1162 return nil
1163
1164}
1165
1166func (options *DevicePmConfigMetricList) Execute(args []string) error {
1167
1168 conn, err := NewConnection()
1169 if err != nil {
1170 return err
1171 }
1172 defer conn.Close()
1173
1174 client := voltha.NewVolthaServiceClient(conn)
1175
David K. Bainbridge9189c632021-03-26 21:52:21 +00001176 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001177 defer cancel()
1178
1179 id := voltha.ID{Id: string(options.Args.Id)}
1180
1181 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1182 if err != nil {
1183 return err
1184 }
1185
1186 if !pmConfigs.Grouped {
1187 for _, metric := range pmConfigs.Metrics {
1188 if metric.SampleFreq == 0 {
1189 metric.SampleFreq = pmConfigs.DefaultFreq
1190 }
1191 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001192 outputFormat := CharReplacer.Replace(options.Format)
1193 if outputFormat == "" {
1194 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_METRIC_LIST_FORMAT)
1195 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001196
Rohan Agrawalbca69122020-06-17 14:59:03 +00001197 orderBy := options.OrderBy
1198 if orderBy == "" {
1199 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1200 }
1201
1202 result := CommandResult{
1203 Format: format.Format(outputFormat),
1204 Filter: options.Filter,
1205 OrderBy: orderBy,
1206 OutputAs: toOutputType(options.OutputAs),
1207 NameLimit: options.NameLimit,
1208 Data: pmConfigs.Metrics,
1209 }
1210
1211 GenerateOutput(&result)
1212 return nil
1213 } else {
1214 return fmt.Errorf("Device '%s' does not have Non Grouped Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001215 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001216}
1217
1218func (options *DevicePmConfigMetricEnable) Execute(args []string) error {
1219
1220 conn, err := NewConnection()
1221 if err != nil {
1222 return err
1223 }
1224 defer conn.Close()
1225
1226 client := voltha.NewVolthaServiceClient(conn)
1227
David K. Bainbridge9189c632021-03-26 21:52:21 +00001228 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001229 defer cancel()
1230
1231 id := voltha.ID{Id: string(options.Args.Id)}
1232
1233 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1234 if err != nil {
1235 return err
1236 }
1237
1238 if !pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001239 metrics := make(map[string]struct{})
1240 for _, metric := range pmConfigs.Metrics {
1241 metrics[metric.Name] = struct{}{}
1242 }
1243
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001244 for _, metric := range pmConfigs.Metrics {
1245 for _, mName := range options.Args.Metrics {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001246 if _, exist := metrics[string(mName)]; !exist {
1247 return fmt.Errorf("Metric Name '%s' does not exist", mName)
1248 }
1249
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001250 if string(mName) == metric.Name && !metric.Enabled {
1251 metric.Enabled = true
1252 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1253 if err != nil {
1254 return err
1255 }
1256 }
1257 }
1258 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001259 } else {
1260 return fmt.Errorf("Device '%s' does not have Non Grouped Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001261 }
1262 return nil
1263}
1264
1265func (options *DevicePmConfigMetricDisable) Execute(args []string) error {
1266
1267 conn, err := NewConnection()
1268 if err != nil {
1269 return err
1270 }
1271 defer conn.Close()
1272
1273 client := voltha.NewVolthaServiceClient(conn)
1274
David K. Bainbridge9189c632021-03-26 21:52:21 +00001275 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001276 defer cancel()
1277
1278 id := voltha.ID{Id: string(options.Args.Id)}
1279
1280 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1281 if err != nil {
1282 return err
1283 }
1284
1285 if !pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001286 metrics := make(map[string]struct{})
1287 for _, metric := range pmConfigs.Metrics {
1288 metrics[metric.Name] = struct{}{}
1289 }
1290
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001291 for _, metric := range pmConfigs.Metrics {
1292 for _, mName := range options.Args.Metrics {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001293 if _, have := metrics[string(mName)]; !have {
1294 return fmt.Errorf("Metric Name '%s' does not exist", mName)
1295 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001296 if string(mName) == metric.Name && metric.Enabled {
1297 metric.Enabled = false
1298 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1299 if err != nil {
1300 return err
1301 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001302 } else {
1303 return fmt.Errorf("Metric '%s' cannot be disabled", string(mName))
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001304 }
1305 }
1306 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001307 } else {
1308 return fmt.Errorf("Device '%s' does not have Non Grouped Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001309 }
1310 return nil
1311}
1312
1313func (options *DevicePmConfigGroupEnable) Execute(args []string) error {
1314
1315 conn, err := NewConnection()
1316 if err != nil {
1317 return err
1318 }
1319 defer conn.Close()
1320
1321 client := voltha.NewVolthaServiceClient(conn)
1322
David K. Bainbridge9189c632021-03-26 21:52:21 +00001323 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001324 defer cancel()
1325
1326 id := voltha.ID{Id: string(options.Args.Id)}
1327
1328 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1329 if err != nil {
1330 return err
1331 }
1332
1333 if pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001334 groups := make(map[string]struct{})
1335 for _, group := range pmConfigs.Groups {
1336 groups[group.GroupName] = struct{}{}
1337 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001338 for _, group := range pmConfigs.Groups {
Girish Gowdra610acb42021-01-27 13:33:57 -08001339 if _, have := groups[string(options.Args.Group)]; !have {
1340 return fmt.Errorf("Group Name '%s' does not exist", options.Args.Group)
1341 }
1342 if string(options.Args.Group) == group.GroupName && !group.Enabled {
1343 group.Enabled = true
1344 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1345 if err != nil {
1346 return err
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001347 }
1348 }
1349 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001350 } else {
1351 return fmt.Errorf("Device '%s' does not have Group Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001352 }
1353 return nil
1354}
1355
1356func (options *DevicePmConfigGroupDisable) Execute(args []string) error {
1357
1358 conn, err := NewConnection()
1359 if err != nil {
1360 return err
1361 }
1362 defer conn.Close()
1363
1364 client := voltha.NewVolthaServiceClient(conn)
1365
David K. Bainbridge9189c632021-03-26 21:52:21 +00001366 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001367 defer cancel()
1368
1369 id := voltha.ID{Id: string(options.Args.Id)}
1370
1371 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1372 if err != nil {
1373 return err
1374 }
1375
1376 if pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001377 groups := make(map[string]struct{})
1378 for _, group := range pmConfigs.Groups {
1379 groups[group.GroupName] = struct{}{}
1380 }
1381
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001382 for _, group := range pmConfigs.Groups {
Girish Gowdra610acb42021-01-27 13:33:57 -08001383 if _, have := groups[string(options.Args.Group)]; !have {
1384 return fmt.Errorf("Group Name '%s' does not exist", options.Args.Group)
1385 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001386
Girish Gowdra610acb42021-01-27 13:33:57 -08001387 if string(options.Args.Group) == group.GroupName && group.Enabled {
1388 group.Enabled = false
1389 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1390 if err != nil {
1391 return err
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001392 }
1393 }
1394 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001395 } else {
1396 return fmt.Errorf("Device '%s' does not have Group Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001397 }
1398 return nil
1399}
1400
Girish Gowdra610acb42021-01-27 13:33:57 -08001401func (options *DevicePmConfigGroupFrequencySet) Execute(args []string) error {
1402
1403 conn, err := NewConnection()
1404 if err != nil {
1405 return err
1406 }
1407 defer conn.Close()
1408
1409 client := voltha.NewVolthaServiceClient(conn)
1410
David K. Bainbridge9189c632021-03-26 21:52:21 +00001411 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Girish Gowdra610acb42021-01-27 13:33:57 -08001412 defer cancel()
1413
1414 id := voltha.ID{Id: string(options.Args.Id)}
1415
1416 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1417 if err != nil {
1418 return err
1419 }
1420
1421 if pmConfigs.Grouped {
1422 groups := make(map[string]struct{})
1423 for _, group := range pmConfigs.Groups {
1424 groups[group.GroupName] = struct{}{}
1425 }
1426
1427 for _, group := range pmConfigs.Groups {
1428 if _, have := groups[string(options.Args.Group)]; !have {
1429 return fmt.Errorf("group name '%s' does not exist", options.Args.Group)
1430 }
1431
1432 if string(options.Args.Group) == group.GroupName {
1433 if !group.Enabled {
1434 return fmt.Errorf("group '%s' is not enabled", options.Args.Group)
1435 }
1436 group.GroupFreq = uint32(options.Args.Interval.Seconds())
1437 _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs)
1438 if err != nil {
1439 return err
1440 }
1441 }
1442 }
1443 } else {
1444 return fmt.Errorf("device '%s' does not have group metrics", options.Args.Id)
1445 }
1446 return nil
1447}
1448
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001449func (options *DevicePmConfigGroupList) Execute(args []string) error {
1450
1451 conn, err := NewConnection()
1452 if err != nil {
1453 return err
1454 }
1455 defer conn.Close()
1456
1457 client := voltha.NewVolthaServiceClient(conn)
1458
David K. Bainbridge9189c632021-03-26 21:52:21 +00001459 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001460 defer cancel()
1461
1462 id := voltha.ID{Id: string(options.Args.Id)}
1463
1464 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1465 if err != nil {
1466 return err
1467 }
1468
1469 if pmConfigs.Grouped {
1470 for _, group := range pmConfigs.Groups {
1471 if group.GroupFreq == 0 {
1472 group.GroupFreq = pmConfigs.DefaultFreq
1473 }
1474 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001475 outputFormat := CharReplacer.Replace(options.Format)
1476 if outputFormat == "" {
1477 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GROUP_LIST_FORMAT)
1478 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001479
Rohan Agrawalbca69122020-06-17 14:59:03 +00001480 orderBy := options.OrderBy
1481 if orderBy == "" {
1482 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1483 }
1484
1485 result := CommandResult{
1486 Format: format.Format(outputFormat),
1487 Filter: options.Filter,
1488 OrderBy: orderBy,
1489 OutputAs: toOutputType(options.OutputAs),
1490 NameLimit: options.NameLimit,
1491 Data: pmConfigs.Groups,
1492 }
1493
1494 GenerateOutput(&result)
1495 } else {
1496 return fmt.Errorf("Device '%s' does not have Group Metrics", string(options.Args.Id))
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001497 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001498 return nil
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001499}
1500
1501func (options *DevicePmConfigGroupMetricList) Execute(args []string) error {
1502
1503 var metrics []*voltha.PmConfig
1504 conn, err := NewConnection()
1505 if err != nil {
1506 return err
1507 }
1508 defer conn.Close()
1509
1510 client := voltha.NewVolthaServiceClient(conn)
1511
David K. Bainbridge9189c632021-03-26 21:52:21 +00001512 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001513 defer cancel()
1514
1515 id := voltha.ID{Id: string(options.Args.Id)}
1516
1517 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1518 if err != nil {
1519 return err
1520 }
1521
1522 for _, groups := range pmConfigs.Groups {
1523
1524 if string(options.Args.Group) == groups.GroupName {
1525 for _, metric := range groups.Metrics {
1526 if metric.SampleFreq == 0 && groups.GroupFreq == 0 {
1527 metric.SampleFreq = pmConfigs.DefaultFreq
1528 } else {
1529 metric.SampleFreq = groups.GroupFreq
1530 }
1531 }
1532 metrics = groups.Metrics
1533 }
1534 }
1535
1536 outputFormat := CharReplacer.Replace(options.Format)
1537 if outputFormat == "" {
1538 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_METRIC_LIST_FORMAT)
1539 }
1540
1541 orderBy := options.OrderBy
1542 if orderBy == "" {
1543 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1544 }
1545
1546 result := CommandResult{
1547 Format: format.Format(outputFormat),
1548 Filter: options.Filter,
1549 OrderBy: orderBy,
1550 OutputAs: toOutputType(options.OutputAs),
1551 NameLimit: options.NameLimit,
1552 Data: metrics,
1553 }
1554
1555 GenerateOutput(&result)
1556 return nil
1557
1558}
1559
1560func (options *DevicePmConfigFrequencySet) Execute(args []string) error {
1561
1562 conn, err := NewConnection()
1563 if err != nil {
1564 return err
1565 }
1566 defer conn.Close()
1567
1568 client := voltha.NewVolthaServiceClient(conn)
1569
David K. Bainbridge9189c632021-03-26 21:52:21 +00001570 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001571 defer cancel()
1572
1573 id := voltha.ID{Id: string(options.Args.Id)}
1574
1575 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1576 if err != nil {
1577 return err
1578 }
1579
Girish Gowdra610acb42021-01-27 13:33:57 -08001580 pmConfigs.DefaultFreq = uint32(options.Args.Interval.Seconds())
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001581
1582 _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs)
1583 if err != nil {
1584 return err
1585 }
1586
1587 outputFormat := CharReplacer.Replace(options.Format)
1588 if outputFormat == "" {
1589 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GET_FORMAT)
1590 }
1591 if options.Quiet {
1592 outputFormat = "{{.Id}}"
1593 }
1594
1595 result := CommandResult{
1596 Format: format.Format(outputFormat),
1597 OutputAs: toOutputType(options.OutputAs),
1598 NameLimit: options.NameLimit,
1599 Data: pmConfigs,
1600 }
1601
1602 GenerateOutput(&result)
1603 return nil
1604
1605}
1606
kesavand3e2f9f62021-04-22 11:06:38 +05301607func (options *OnuDownloadImage) Execute(args []string) error {
1608
1609 conn, err := NewConnection()
1610 if err != nil {
1611 return err
1612 }
1613 defer conn.Close()
1614
1615 client := voltha.NewVolthaServiceClient(conn)
1616
1617 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1618 defer cancel()
1619
1620 var devIDList []*common.ID
1621 for _, i := range options.Args.IDs {
1622
1623 devIDList = append(devIDList, &common.ID{Id: string(i)})
1624 }
1625
1626 downloadImage := voltha.DeviceImageDownloadRequest{
1627 DeviceId: devIDList,
1628 Image: &voltha.Image{
1629 Url: options.Args.Url,
1630 Crc32: options.Args.Crc,
ssiddiqui7bc89e92021-05-20 20:58:02 +05301631 Vendor: options.Args.Vendor,
kesavand3e2f9f62021-04-22 11:06:38 +05301632 Version: options.Args.ImageVersion,
1633 },
1634 ActivateOnSuccess: options.Args.ActivateOnSuccess,
1635 CommitOnSuccess: options.Args.CommitOnSuccess,
1636 }
1637
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001638 deviceImageResp, err := client.DownloadImageToDevice(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301639 if err != nil {
1640 return err
1641 }
1642
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001643 outputFormat := GetCommandOptionWithDefault("onu-image-download", "format", ONU_IMAGE_STATUS_FORMAT)
1644 // Make sure json output prints an empty list, not "null"
1645 if deviceImageResp.DeviceImageStates == nil {
1646 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1647 }
1648 result := CommandResult{
1649 Format: format.Format(outputFormat),
1650 OutputAs: toOutputType(options.OutputAs),
1651 NameLimit: options.NameLimit,
1652 Data: deviceImageResp.DeviceImageStates,
1653 }
1654 GenerateOutput(&result)
kesavand3e2f9f62021-04-22 11:06:38 +05301655 return nil
1656
1657}
1658
1659func (options *OnuActivateImage) Execute(args []string) error {
1660
1661 conn, err := NewConnection()
1662 if err != nil {
1663 return err
1664 }
1665 defer conn.Close()
1666
1667 client := voltha.NewVolthaServiceClient(conn)
1668
1669 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1670 defer cancel()
1671
1672 var devIDList []*common.ID
1673 for _, i := range options.Args.IDs {
1674
1675 devIDList = append(devIDList, &common.ID{Id: string(i)})
1676 }
1677
1678 downloadImage := voltha.DeviceImageRequest{
1679 DeviceId: devIDList,
1680 Version: options.Args.ImageVersion,
1681 CommitOnSuccess: options.Args.CommitOnSuccess,
1682 }
1683
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001684 deviceImageResp, err := client.ActivateImage(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301685 if err != nil {
1686 return err
1687 }
1688
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001689 outputFormat := GetCommandOptionWithDefault("onu-image-activate", "format", ONU_IMAGE_STATUS_FORMAT)
1690 // Make sure json output prints an empty list, not "null"
1691 if deviceImageResp.DeviceImageStates == nil {
1692 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1693 }
1694 result := CommandResult{
1695 Format: format.Format(outputFormat),
1696 OutputAs: toOutputType(options.OutputAs),
1697 NameLimit: options.NameLimit,
1698 Data: deviceImageResp.DeviceImageStates,
1699 }
1700 GenerateOutput(&result)
1701
kesavand3e2f9f62021-04-22 11:06:38 +05301702 return nil
1703
1704}
1705
1706func (options *OnuAbortUpgradeImage) Execute(args []string) error {
1707
1708 conn, err := NewConnection()
1709 if err != nil {
1710 return err
1711 }
1712 defer conn.Close()
1713
1714 client := voltha.NewVolthaServiceClient(conn)
1715
1716 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1717 defer cancel()
1718
1719 var devIDList []*common.ID
1720 for _, i := range options.Args.IDs {
1721
1722 devIDList = append(devIDList, &common.ID{Id: string(i)})
1723 }
1724
1725 downloadImage := voltha.DeviceImageRequest{
1726 DeviceId: devIDList,
1727 Version: options.Args.ImageVersion,
1728 }
1729
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001730 deviceImageResp, err := client.AbortImageUpgradeToDevice(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301731 if err != nil {
1732 return err
1733 }
1734
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001735 outputFormat := GetCommandOptionWithDefault("onu-image-abort", "format", ONU_IMAGE_STATUS_FORMAT)
1736 // Make sure json output prints an empty list, not "null"
1737 if deviceImageResp.DeviceImageStates == nil {
1738 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1739 }
1740 result := CommandResult{
1741 Format: format.Format(outputFormat),
1742 OutputAs: toOutputType(options.OutputAs),
1743 NameLimit: options.NameLimit,
1744 Data: deviceImageResp.DeviceImageStates,
1745 }
1746 GenerateOutput(&result)
1747
kesavand3e2f9f62021-04-22 11:06:38 +05301748 return nil
1749
1750}
1751
1752func (options *OnuCommitImage) Execute(args []string) error {
1753
1754 conn, err := NewConnection()
1755 if err != nil {
1756 return err
1757 }
1758 defer conn.Close()
1759
1760 client := voltha.NewVolthaServiceClient(conn)
1761
1762 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1763 defer cancel()
1764
1765 var devIDList []*common.ID
1766 for _, i := range options.Args.IDs {
1767
1768 devIDList = append(devIDList, &common.ID{Id: string(i)})
1769 }
1770 downloadImage := voltha.DeviceImageRequest{
1771 DeviceId: devIDList,
1772 Version: options.Args.ImageVersion,
1773 }
1774
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001775 deviceImageResp, err := client.CommitImage(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301776 if err != nil {
1777 return err
1778 }
1779
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001780 outputFormat := GetCommandOptionWithDefault("onu-image-commit", "format", ONU_IMAGE_STATUS_FORMAT)
1781 // Make sure json output prints an empty list, not "null"
1782 if deviceImageResp.DeviceImageStates == nil {
1783 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1784 }
1785 result := CommandResult{
1786 Format: format.Format(outputFormat),
1787 OutputAs: toOutputType(options.OutputAs),
1788 NameLimit: options.NameLimit,
1789 Data: deviceImageResp.DeviceImageStates,
1790 }
1791 GenerateOutput(&result)
1792
kesavand3e2f9f62021-04-22 11:06:38 +05301793 return nil
1794
1795}
1796
1797func (options *OnuListImages) Execute(args []string) error {
1798
1799 conn, err := NewConnection()
1800 if err != nil {
1801 return err
1802 }
1803 defer conn.Close()
1804
1805 client := voltha.NewVolthaServiceClient(conn)
1806
1807 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1808 defer cancel()
1809
1810 id := common.ID{Id: string(options.Args.Id)}
1811
1812 onuImages, err := client.GetOnuImages(ctx, &id)
1813 if err != nil {
1814 return err
1815 }
1816
1817 outputFormat := CharReplacer.Replace(options.Format)
1818 if outputFormat == "" {
1819 outputFormat = GetCommandOptionWithDefault("onu-image-list", "format", ONU_IMAGE_LIST_FORMAT)
1820 }
1821
1822 if options.Quiet {
1823 outputFormat = "{{.Id}}"
1824 }
1825
1826 //TODO orderby
1827
1828 // Make sure json output prints an empty list, not "null"
1829 if onuImages.Items == nil {
1830 onuImages.Items = make([]*voltha.OnuImage, 0)
1831 }
1832
1833 result := CommandResult{
1834 Format: format.Format(outputFormat),
1835 OutputAs: toOutputType(options.OutputAs),
1836 NameLimit: options.NameLimit,
1837 Data: onuImages.Items,
1838 }
1839
1840 GenerateOutput(&result)
1841 return nil
1842
1843}
1844
1845func (options *OnuImageStatus) Execute(args []string) error {
1846
1847 conn, err := NewConnection()
1848 if err != nil {
1849 return err
1850 }
1851 defer conn.Close()
1852
1853 client := voltha.NewVolthaServiceClient(conn)
1854
1855 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1856 defer cancel()
1857
1858 var devIDList []*common.ID
kesavand3e2f9f62021-04-22 11:06:38 +05301859
Elia Battiston859f3e62022-02-08 15:57:52 +01001860 if options.Args.IDs == nil {
1861 //Use an empty IDs list to retrieve the status of all devices
1862 //with the requested image version
1863 devIDList = []*common.ID{}
1864 } else {
1865 for _, i := range options.Args.IDs {
1866 devIDList = append(devIDList, &common.ID{Id: string(i)})
1867 }
kesavand3e2f9f62021-04-22 11:06:38 +05301868 }
1869
1870 imageStatusReq := voltha.DeviceImageRequest{
1871 DeviceId: devIDList,
1872 Version: options.Args.ImageVersion,
1873 }
1874 imageStatus, err := client.GetImageStatus(ctx, &imageStatusReq)
1875 if err != nil {
1876 return err
1877 }
1878
1879 outputFormat := CharReplacer.Replace(options.Format)
1880 if outputFormat == "" {
1881 outputFormat = GetCommandOptionWithDefault("device-image-list", "format", ONU_IMAGE_STATUS_FORMAT)
1882 }
1883
1884 if options.Quiet {
1885 outputFormat = "{{.Id}}"
1886 }
1887
1888 //TODO orderby
1889
1890 // Make sure json output prints an empty list, not "null"
1891 if imageStatus.DeviceImageStates == nil {
1892 imageStatus.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1893 }
1894
1895 result := CommandResult{
1896 Format: format.Format(outputFormat),
1897 OutputAs: toOutputType(options.OutputAs),
1898 NameLimit: options.NameLimit,
1899 Data: imageStatus.DeviceImageStates,
1900 }
1901
1902 GenerateOutput(&result)
1903 return nil
1904
1905}
1906
Andrea Campanella791d88b2021-01-08 13:29:00 +01001907func (options *DeviceOnuListImages) Execute(args []string) error {
1908
1909 conn, err := NewConnection()
1910 if err != nil {
1911 return err
1912 }
1913 defer conn.Close()
1914
1915 client := voltha.NewVolthaServiceClient(conn)
1916
David K. Bainbridge9189c632021-03-26 21:52:21 +00001917 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Andrea Campanella791d88b2021-01-08 13:29:00 +01001918 defer cancel()
1919
1920 id := common.ID{Id: string(options.Args.Id)}
1921
1922 imageDownloads, err := client.ListImageDownloads(ctx, &id)
1923 if err != nil {
1924 return err
1925 }
1926
1927 outputFormat := CharReplacer.Replace(options.Format)
1928 if outputFormat == "" {
1929 outputFormat = GetCommandOptionWithDefault("device-image-list", "format", DEFAULT_DEVICE_IMAGE_LIST_GET_FORMAT)
1930 }
1931
1932 if options.Quiet {
1933 outputFormat = "{{.Id}}"
1934 }
1935
1936 //TODO orderby
1937
1938 // Make sure json output prints an empty list, not "null"
1939 if imageDownloads.Items == nil {
1940 imageDownloads.Items = make([]*voltha.ImageDownload, 0)
1941 }
1942
1943 result := CommandResult{
1944 Format: format.Format(outputFormat),
1945 OutputAs: toOutputType(options.OutputAs),
1946 NameLimit: options.NameLimit,
1947 Data: imageDownloads.Items,
1948 }
1949
1950 GenerateOutput(&result)
1951 return nil
1952
1953}
1954
1955func (options *DeviceOnuDownloadImage) Execute(args []string) error {
1956
1957 conn, err := NewConnection()
1958 if err != nil {
1959 return err
1960 }
1961 defer conn.Close()
1962
1963 client := voltha.NewVolthaServiceClient(conn)
1964
David K. Bainbridge9189c632021-03-26 21:52:21 +00001965 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Andrea Campanella791d88b2021-01-08 13:29:00 +01001966 defer cancel()
1967
1968 downloadImage := voltha.ImageDownload{
1969 Id: string(options.Args.Id),
1970 Name: options.Args.Name,
1971 Url: options.Args.Url,
1972 Crc: options.Args.Crc,
1973 LocalDir: options.Args.LocalDir,
1974 }
1975
1976 _, err = client.DownloadImage(ctx, &downloadImage)
1977 if err != nil {
1978 return err
1979 }
1980
1981 return nil
1982
1983}
1984
1985func (options *DeviceOnuActivateImageUpdate) Execute(args []string) error {
1986
1987 conn, err := NewConnection()
1988 if err != nil {
1989 return err
1990 }
1991 defer conn.Close()
1992
1993 client := voltha.NewVolthaServiceClient(conn)
1994
David K. Bainbridge9189c632021-03-26 21:52:21 +00001995 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Andrea Campanella791d88b2021-01-08 13:29:00 +01001996 defer cancel()
1997
1998 downloadImage := voltha.ImageDownload{
1999 Id: string(options.Args.Id),
2000 Name: options.Args.Name,
2001 ImageVersion: options.Args.ImageVersion,
2002 SaveConfig: options.Args.SaveConfig,
2003 LocalDir: options.Args.LocalDir,
2004 }
2005
2006 _, err = client.ActivateImageUpdate(ctx, &downloadImage)
2007 if err != nil {
2008 return err
2009 }
2010
2011 return nil
2012
2013}
2014
Scott Baker9173ed82020-05-19 08:30:12 -07002015type ReturnValueRow struct {
2016 Name string `json:"name"`
2017 Result interface{} `json:"result"`
2018}
2019
kesavand8ec4fc02021-01-27 09:10:22 -05002020func (options *DeviceGetPortStats) Execute(args []string) error {
2021 conn, err := NewConnection()
2022 if err != nil {
2023 return err
2024 }
2025 defer conn.Close()
2026 client := extension.NewExtensionClient(conn)
2027 var portType extension.GetOltPortCounters_PortType
2028
2029 if options.Args.PortType == "pon" {
2030 portType = extension.GetOltPortCounters_Port_PON_OLT
2031 } else if options.Args.PortType == "nni" {
2032
2033 portType = extension.GetOltPortCounters_Port_ETHERNET_NNI
2034 } else {
2035 return fmt.Errorf("expected interface type pon/nni, provided %s", options.Args.PortType)
2036 }
2037
2038 singleGetValReq := extension.SingleGetValueRequest{
2039 TargetId: string(options.Args.Id),
2040 Request: &extension.GetValueRequest{
2041 Request: &extension.GetValueRequest_OltPortInfo{
2042 OltPortInfo: &extension.GetOltPortCounters{
2043 PortNo: options.Args.PortNo,
2044 PortType: portType,
2045 },
2046 },
2047 },
2048 }
2049
David K. Bainbridge9189c632021-03-26 21:52:21 +00002050 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand8ec4fc02021-01-27 09:10:22 -05002051 defer cancel()
2052 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2053 if err != nil {
2054 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2055 return err
2056 }
2057
2058 if rv.Response.Status != extension.GetValueResponse_OK {
2059 return fmt.Errorf("failed to get port stats %v", rv.Response.ErrReason.String())
2060 }
2061
2062 outputFormat := CharReplacer.Replace(options.Format)
2063 if outputFormat == "" {
2064 outputFormat = GetCommandOptionWithDefault("device-get-port-status", "format", DEFAULT_DEVICE_GET_PORT_STATUS_FORMAT)
2065 }
2066
2067 result := CommandResult{
2068 Format: format.Format(outputFormat),
2069 OutputAs: toOutputType(options.OutputAs),
2070 NameLimit: options.NameLimit,
2071 Data: rv.GetResponse().GetPortCoutners(),
2072 }
2073 GenerateOutput(&result)
2074 return nil
2075}
2076
Himani Chawla40acc122021-05-26 18:52:29 +05302077func (options *GetOnuStats) Execute(args []string) error {
2078 conn, err := NewConnection()
2079 if err != nil {
2080 return err
2081 }
2082 defer conn.Close()
2083 client := extension.NewExtensionClient(conn)
2084
2085 singleGetValReq := extension.SingleGetValueRequest{
2086 TargetId: string(options.Args.OltId),
2087 Request: &extension.GetValueRequest{
2088 Request: &extension.GetValueRequest_OnuPonInfo{
2089 OnuPonInfo: &extension.GetOnuCountersRequest{
2090 IntfId: options.Args.IntfId,
2091 OnuId: options.Args.OnuId,
2092 },
2093 },
2094 },
2095 }
2096 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2097 defer cancel()
2098 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2099 if err != nil {
2100 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.OltId, ErrorToString(err))
2101 return err
2102 }
2103
2104 if rv.Response.Status != extension.GetValueResponse_OK {
2105 return fmt.Errorf("failed to get onu stats %v", rv.Response.ErrReason.String())
2106 }
2107 outputFormat := CharReplacer.Replace(options.Format)
2108 data, formatStr := buildOnuStatsOutputFormat(rv.GetResponse().GetOnuPonCounters())
2109 if outputFormat == "" {
2110 outputFormat = GetCommandOptionWithDefault("device-get-onu-status", "format", formatStr)
2111 }
Himani Chawla553a1392021-06-10 23:39:17 +05302112 result := CommandResult{
2113 Format: format.Format(outputFormat),
2114 OutputAs: toOutputType(options.OutputAs),
2115 NameLimit: options.NameLimit,
2116 Data: data,
2117 }
2118 GenerateOutput(&result)
2119 return nil
2120}
Himani Chawla40acc122021-05-26 18:52:29 +05302121
Himani Chawla553a1392021-06-10 23:39:17 +05302122func (options *GetOnuEthernetFrameExtendedPmCounters) Execute(args []string) error {
2123 conn, err := NewConnection()
2124 if err != nil {
2125 return err
2126 }
2127 defer conn.Close()
2128 client := extension.NewExtensionClient(conn)
Himani Chawla806aa892021-08-30 15:51:46 +05302129 var singleGetValReq extension.SingleGetValueRequest
Himani Chawla553a1392021-06-10 23:39:17 +05302130
Himani Chawla806aa892021-08-30 15:51:46 +05302131 if options.Args.UniIndex != nil {
2132 singleGetValReq = extension.SingleGetValueRequest{
2133 TargetId: string(options.Args.Id),
2134 Request: &extension.GetValueRequest{
2135 Request: &extension.GetValueRequest_OnuInfo{
2136 OnuInfo: &extension.GetOmciEthernetFrameExtendedPmRequest{
2137 OnuDeviceId: string(options.Args.Id),
2138 Reset_: options.Reset,
2139 IsUniIndex: &extension.GetOmciEthernetFrameExtendedPmRequest_UniIndex{
2140 UniIndex: *options.Args.UniIndex,
2141 },
2142 },
Himani Chawla553a1392021-06-10 23:39:17 +05302143 },
2144 },
Himani Chawla806aa892021-08-30 15:51:46 +05302145 }
2146 } else {
2147 singleGetValReq = extension.SingleGetValueRequest{
2148 TargetId: string(options.Args.Id),
2149 Request: &extension.GetValueRequest{
2150 Request: &extension.GetValueRequest_OnuInfo{
2151 OnuInfo: &extension.GetOmciEthernetFrameExtendedPmRequest{
2152 OnuDeviceId: string(options.Args.Id),
2153 Reset_: options.Reset,
2154 },
2155 },
2156 },
2157 }
Himani Chawla553a1392021-06-10 23:39:17 +05302158 }
Himani Chawla806aa892021-08-30 15:51:46 +05302159
Himani Chawla553a1392021-06-10 23:39:17 +05302160 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2161 defer cancel()
2162 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2163 if err != nil {
2164 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2165 return err
2166 }
2167
2168 if rv.Response.Status != extension.GetValueResponse_OK {
2169 return fmt.Errorf("failed to get ethernet frame extended pm counters %v", rv.Response.ErrReason.String())
2170 }
2171 outputFormat := CharReplacer.Replace(options.Format)
2172 data := buildOnuEthernetFrameExtendedPmOutputFormat(rv.GetResponse().GetOnuCounters())
2173 if outputFormat == "" {
2174 outputFormat = GetCommandOptionWithDefault("device-get-onu-status", "format", DEFAULT_ETHERNET_FRAME_EXTENDED_PM_COUNTERS_FORMAT)
2175 }
Himani Chawla40acc122021-05-26 18:52:29 +05302176 result := CommandResult{
2177 Format: format.Format(outputFormat),
2178 OutputAs: toOutputType(options.OutputAs),
2179 NameLimit: options.NameLimit,
2180 Data: data,
2181 }
2182 GenerateOutput(&result)
2183 return nil
2184}
2185
kesavand6d1131f2021-02-05 22:38:15 +05302186func (options *UniStatus) Execute(args []string) error {
2187 conn, err := NewConnection()
2188 if err != nil {
2189 return err
2190 }
2191 defer conn.Close()
2192 client := extension.NewExtensionClient(conn)
2193
2194 singleGetValReq := extension.SingleGetValueRequest{
2195 TargetId: string(options.Args.Id),
2196 Request: &extension.GetValueRequest{
2197 Request: &extension.GetValueRequest_UniInfo{
2198 UniInfo: &extension.GetOnuUniInfoRequest{
2199 UniIndex: options.Args.UniIndex,
2200 },
2201 },
2202 },
2203 }
David K. Bainbridge9189c632021-03-26 21:52:21 +00002204 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand6d1131f2021-02-05 22:38:15 +05302205 defer cancel()
2206 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2207 if err != nil {
2208 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2209 return err
2210 }
2211 if rv.Response.Status != extension.GetValueResponse_OK {
2212 return fmt.Errorf("failed to get uni status %v", rv.Response.ErrReason.String())
2213 }
2214 outputFormat := CharReplacer.Replace(options.Format)
2215 if outputFormat == "" {
2216 outputFormat = GetCommandOptionWithDefault("device-get-uni-status", "format", DEFAULT_DEVICE_GET_UNI_STATUS_FORMAT)
2217 }
2218 result := CommandResult{
2219 Format: format.Format(outputFormat),
2220 OutputAs: toOutputType(options.OutputAs),
2221 NameLimit: options.NameLimit,
2222 Data: rv.GetResponse().GetUniInfo(),
2223 }
2224 GenerateOutput(&result)
2225 return nil
2226}
2227
Girish Gowdra4f5ce7c2021-04-29 18:53:21 -07002228func (options *OnuPonOpticalInfo) Execute(args []string) error {
2229 conn, err := NewConnection()
2230 if err != nil {
2231 return err
2232 }
2233 defer conn.Close()
2234 client := extension.NewExtensionClient(conn)
2235
2236 singleGetValReq := extension.SingleGetValueRequest{
2237 TargetId: string(options.Args.Id),
2238 Request: &extension.GetValueRequest{
2239 Request: &extension.GetValueRequest_OnuOpticalInfo{
2240 OnuOpticalInfo: &extension.GetOnuPonOpticalInfo{},
2241 },
2242 },
2243 }
2244 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2245 defer cancel()
2246 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2247 if err != nil {
2248 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2249 return err
2250 }
2251 if rv.Response.Status != extension.GetValueResponse_OK {
2252 return fmt.Errorf("failed to get onu pon optical info %v", rv.Response.ErrReason.String())
2253 }
2254 outputFormat := CharReplacer.Replace(options.Format)
2255 if outputFormat == "" {
2256 outputFormat = GetCommandOptionWithDefault("device-get-onu-pon-optical-info", "format", DEFAULT_ONU_PON_OPTICAL_INFO_STATUS_FORMAT)
2257 }
2258 result := CommandResult{
2259 Format: format.Format(outputFormat),
2260 OutputAs: toOutputType(options.OutputAs),
2261 NameLimit: options.NameLimit,
2262 Data: rv.GetResponse().GetOnuOpticalInfo(),
2263 }
2264 GenerateOutput(&result)
2265 return nil
2266}
2267
Gamze Abakac857a462021-05-26 13:45:54 +00002268func (options *RxPower) Execute(args []string) error {
2269 conn, err := NewConnection()
2270 if err != nil {
2271 return err
2272 }
2273 defer conn.Close()
2274 client := extension.NewExtensionClient(conn)
2275
2276 singleGetValReq := extension.SingleGetValueRequest{
2277 TargetId: string(options.Args.Id),
2278 Request: &extension.GetValueRequest{
2279 Request: &extension.GetValueRequest_RxPower{
2280 RxPower: &extension.GetRxPowerRequest{
2281 IntfId: options.Args.PortNo,
2282 OnuId: options.Args.OnuNo,
2283 },
2284 },
2285 },
2286 }
2287
2288 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2289 defer cancel()
2290 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2291 if err != nil {
2292 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2293 return err
2294 }
2295 if rv.Response.Status != extension.GetValueResponse_OK {
2296 return fmt.Errorf("failed to get rx power %v", rv.Response.ErrReason.String())
2297 }
2298 outputFormat := CharReplacer.Replace(options.Format)
2299 if outputFormat == "" {
2300 outputFormat = GetCommandOptionWithDefault("device-get-rx-power", "format", DEFAULT_RX_POWER_STATUS_FORMAT)
2301 }
2302 result := CommandResult{
2303 Format: format.Format(outputFormat),
2304 OutputAs: toOutputType(options.OutputAs),
2305 NameLimit: options.NameLimit,
2306 Data: rv.GetResponse().GetRxPower(),
2307 }
2308 GenerateOutput(&result)
2309 return nil
2310}
2311
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002312/*Device get Onu Distance */
2313func (options *DeviceGetExtValue) Execute(args []string) error {
2314 conn, err := NewConnection()
2315 if err != nil {
2316 return err
2317 }
2318 defer conn.Close()
2319
Scott Baker9173ed82020-05-19 08:30:12 -07002320 client := voltha.NewVolthaServiceClient(conn)
2321
khenaidoo080ce882021-10-19 17:35:08 -04002322 valueflag, okay := extension.ValueType_Type_value[string(options.Args.Valueflag)]
Scott Baker9173ed82020-05-19 08:30:12 -07002323 if !okay {
2324 Error.Printf("Unknown valueflag %s\n", options.Args.Valueflag)
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002325 }
2326
khenaidoo080ce882021-10-19 17:35:08 -04002327 val := extension.ValueSpecifier{Id: string(options.Args.Id), Value: extension.ValueType_Type(valueflag)}
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002328
David K. Bainbridge9189c632021-03-26 21:52:21 +00002329 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002330 defer cancel()
2331
Scott Baker9173ed82020-05-19 08:30:12 -07002332 rv, err := client.GetExtValue(ctx, &val)
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002333 if err != nil {
2334 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2335 return err
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002336 }
2337
Scott Baker9173ed82020-05-19 08:30:12 -07002338 var rows []ReturnValueRow
khenaidoo080ce882021-10-19 17:35:08 -04002339 for name, num := range extension.ValueType_Type_value {
Scott Baker9173ed82020-05-19 08:30:12 -07002340 if num == 0 {
2341 // EMPTY is not a real value
2342 continue
2343 }
2344 if (rv.Error & uint32(num)) != 0 {
2345 row := ReturnValueRow{Name: name, Result: "Error"}
2346 rows = append(rows, row)
2347 }
2348 if (rv.Unsupported & uint32(num)) != 0 {
2349 row := ReturnValueRow{Name: name, Result: "Unsupported"}
2350 rows = append(rows, row)
2351 }
2352 if (rv.Set & uint32(num)) != 0 {
2353 switch name {
2354 case "DISTANCE":
2355 row := ReturnValueRow{Name: name, Result: rv.Distance}
2356 rows = append(rows, row)
2357 default:
2358 row := ReturnValueRow{Name: name, Result: "Unimplemented-in-voltctl"}
2359 rows = append(rows, row)
2360 }
2361 }
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002362 }
2363
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002364 outputFormat := CharReplacer.Replace(options.Format)
2365 if outputFormat == "" {
2366 outputFormat = GetCommandOptionWithDefault("device-value-get", "format", DEFAULT_DEVICE_VALUE_GET_FORMAT)
2367 }
2368
2369 result := CommandResult{
2370 Format: format.Format(outputFormat),
2371 OutputAs: toOutputType(options.OutputAs),
2372 NameLimit: options.NameLimit,
Scott Baker9173ed82020-05-19 08:30:12 -07002373 Data: rows,
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002374 }
2375 GenerateOutput(&result)
2376 return nil
2377}
serkantul3d22fc72022-09-14 12:22:56 +03002378
2379/*Device get Onu OMCI TX RX Stats */
2380func (options *OnuOmciTxRxStats) Execute(args []string) error {
2381 conn, err := NewConnection()
2382 if err != nil {
2383 return err
2384 }
2385 defer conn.Close()
2386 client := extension.NewExtensionClient(conn)
2387
2388 singleGetValReq := extension.SingleGetValueRequest{
2389 TargetId: string(options.Args.Id),
2390 Request: &extension.GetValueRequest{
2391 Request: &extension.GetValueRequest_OnuOmciStats{
2392 OnuOmciStats: &extension.GetOnuOmciTxRxStatsRequest{},
2393 },
2394 },
2395 }
2396
2397 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2398 defer cancel()
2399 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2400 if err != nil {
2401 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2402 return err
2403 }
2404
2405 if rv.Response.Status != extension.GetValueResponse_OK {
2406 return fmt.Errorf("failed to get onu omci tx rx stats %v", rv.Response.ErrReason.String())
2407 }
2408 outputFormat := CharReplacer.Replace(options.Format)
2409 if outputFormat == "" {
2410 outputFormat = GetCommandOptionWithDefault("device-get-onu-omci-tx-rx-stats", "format", DEFAULT_ONU_OMCI_TX_RX_STATS_FORMAT)
2411 }
2412 result := CommandResult{
2413 Format: format.Format(outputFormat),
2414 OutputAs: toOutputType(options.OutputAs),
2415 NameLimit: options.NameLimit,
2416 Data: rv.GetResponse().GetOnuOmciStats(),
2417 }
2418 GenerateOutput(&result)
2419 return nil
2420}
praneeth nalmas1dd094c2022-12-22 14:15:13 +05302421
2422/*Device get Onu Active Alarms */
2423func (options *GetOnuOmciActiveAlarms) Execute(args []string) error {
2424 conn, err := NewConnection()
2425 if err != nil {
2426 return err
2427 }
2428 defer conn.Close()
2429 client := extension.NewExtensionClient(conn)
2430
2431 singleGetValReq := extension.SingleGetValueRequest{
2432 TargetId: string(options.Args.Id),
2433 Request: &extension.GetValueRequest{
2434 Request: &extension.GetValueRequest_OnuActiveAlarms{
2435 OnuActiveAlarms: &extension.GetOnuOmciActiveAlarmsRequest{},
2436 },
2437 },
2438 }
2439 Info.Printf("Getting omci_active_alarms for device Id %s\n", options.Args.Id)
2440 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2441 defer cancel()
2442 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2443 if err != nil {
2444 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2445 return err
2446 }
2447
2448 if rv.Response.Status != extension.GetValueResponse_OK {
2449 return fmt.Errorf("failed to get onu omci active alarms list %v", rv.Response.ErrReason.String())
2450 }
2451 outputFormat := CharReplacer.Replace(options.Format)
2452 if outputFormat == "" {
2453 outputFormat = GetCommandOptionWithDefault("device-get-onu-omci-active-alarms", "format", DEFAULT_DEVICE_ALARMS_FORMAT)
2454 }
2455
2456 orderBy := options.OrderBy
2457 if orderBy == "" {
2458 orderBy = GetCommandOptionWithDefault("device-list", "order", DEFAULT_DEVICE_ALARMS_ORDER)
2459 }
2460
2461 result := CommandResult{
2462 Format: format.Format(outputFormat),
2463 OutputAs: toOutputType(options.OutputAs),
2464 OrderBy: orderBy,
2465 NameLimit: options.NameLimit,
2466 Data: rv.GetResponse().GetOnuActiveAlarms().GetActiveAlarms(),
2467 }
2468 GenerateOutput(&result)
2469 return nil
2470}
praneeth nalmas39c71ad2023-09-27 18:29:04 +05302471
Akash Soni66db9632024-04-15 09:05:15 +05302472/*Device get Onu Active Alarms */
2473func (options *GetOnuDistance) Execute(args []string) error {
2474 conn, err := NewConnection()
2475 if err != nil {
2476 return err
2477 }
2478 defer conn.Close()
2479 client := extension.NewExtensionClient(conn)
2480
2481 singleGetValReq := extension.SingleGetValueRequest{
2482 TargetId: string(options.Args.Id),
2483 Request: &extension.GetValueRequest{
2484 Request: &extension.GetValueRequest_Distance{
2485 Distance: &extension.GetDistanceRequest{
2486 OnuDeviceId: string(options.Args.OnuId),
2487 },
2488 },
2489 },
2490 }
2491 Info.Printf("Getting onu distance for device Id %s\n", options.Args.Id)
2492 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2493 defer cancel()
2494 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2495 if err != nil {
2496 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2497 return err
2498 }
2499
2500 if rv.Response.Status != extension.GetValueResponse_OK {
2501 return fmt.Errorf("failed to get onu distance stats %v", rv.Response.ErrReason.String())
2502 }
2503 outputFormat := CharReplacer.Replace(options.Format)
2504 if outputFormat == "" {
2505 outputFormat = GetCommandOptionWithDefault("get-onu-distance", "format", DEFAULT_ONU_DISTANCE_FORMAT)
2506 }
2507
2508 result := CommandResult{
2509 Format: format.Format(outputFormat),
2510 OutputAs: toOutputType(options.OutputAs),
2511 NameLimit: options.NameLimit,
2512 Data: rv.GetResponse().GetDistance().GetDistance(),
2513 }
2514 fmt.Println("onu distance : ", rv)
2515 GenerateOutput(&result)
2516 return nil
2517}
2518
praneeth nalmas39c71ad2023-09-27 18:29:04 +05302519func (options *PonRxPower) Execute(args []string) error {
2520 conn, err := NewConnection()
2521 if err != nil {
2522 return err
2523 }
2524 defer conn.Close()
2525 client := extension.NewExtensionClient(conn)
2526
2527 singleGetValReq := extension.SingleGetValueRequest{
2528 TargetId: string(options.Args.Id),
2529 Request: &extension.GetValueRequest{
2530 Request: &extension.GetValueRequest_OltRxPower{
2531 OltRxPower: &extension.GetOltRxPowerRequest{
2532 PortLabel: options.Args.PortLabel,
2533 OnuSn: options.Args.SerialNo,
2534 },
2535 },
2536 },
2537 }
2538
2539 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2540 defer cancel()
2541 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2542 if err != nil {
2543 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2544 return err
2545 }
2546 if rv.Response.Status != extension.GetValueResponse_OK {
2547 return fmt.Errorf("failed to get rx power %v", rv.Response.ErrReason.String())
2548 }
2549 outputFormat := CharReplacer.Replace(options.Format)
2550 if outputFormat == "" {
2551 outputFormat = GetCommandOptionWithDefault("device-get-pon-rx-power", "format", DEFAULT_PON_RX_POWER_STATUS_FORMAT)
2552 }
2553 result := CommandResult{
2554 Format: format.Format(outputFormat),
2555 OutputAs: toOutputType(options.OutputAs),
2556 NameLimit: options.NameLimit,
2557 Data: rv.GetResponse().GetOltRxPower().GetRxPower(),
2558 }
2559 GenerateOutput(&result)
2560 return nil
2561}