blob: d45d663543584def3f1cd3bc187ca627f2142286 [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
Akash Soni51b6b7a2024-11-20 11:39:38 +0530416type GetOffloadAppStats struct {
417 ListOutputOptions
418 Args struct {
419 OltId DeviceId `positional-arg-name:"OLT_DEVICE_ID" required:"yes"`
420 StatsFor extension.GetOffloadedAppsStatisticsRequest_OffloadedApp `positional-arg-name:"OFFLOADED_APP" required:"yes"`
421 } `positional-args:"yes"`
422}
423
424type SetOffloadAppState struct {
425 Args struct {
426 OltId DeviceId `positional-arg-name:"OLT_DEVICE_ID" required:"yes"`
427 Config extension.AppOffloadConfig `json:"config" required:"yes"`
428 } `positional-args:"yes"`
429}
430
431type SetOnuOffloadState struct {
432 Args struct {
433 OnuDeviceId string `positional-arg-name:"ONU_DEVICE_ID" required:"yes"`
434 PerUniInfo []extension.AppOffloadOnuConfig_PerUniConfig `json:"per_uni_info" required:"yes"`
435 } `positional-args:"yes"`
436}
437
Himani Chawla553a1392021-06-10 23:39:17 +0530438type GetOnuEthernetFrameExtendedPmCounters struct {
439 ListOutputOptions
Himani Chawla806aa892021-08-30 15:51:46 +0530440 Reset bool `long:"reset" description:"Reset the counters"`
441 Args struct {
442 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
443 UniIndex *uint32 `positional-arg-name:"UNI_INDEX"`
Himani Chawla553a1392021-06-10 23:39:17 +0530444 } `positional-args:"yes"`
445}
446
Gamze Abakac857a462021-05-26 13:45:54 +0000447type RxPower struct {
448 ListOutputOptions
449 Args struct {
450 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
451 PortNo uint32 `positional-arg-name:"PORT_NO" required:"yes"`
452 OnuNo uint32 `positional-arg-name:"ONU_NO" required:"yes"`
453 } `positional-args:"yes"`
454}
455
praneeth nalmas39c71ad2023-09-27 18:29:04 +0530456type PonRxPower struct {
457 ListOutputOptions
458 Args struct {
459 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
460 PortLabel string `positional-arg-name:"PORT_LABEL" required:"yes"`
461 SerialNo string `positional-arg-name:"ONU_SERIAL_NUMBER"`
462 } `positional-args:"yes"`
463}
464
serkantul3d22fc72022-09-14 12:22:56 +0300465type OnuOmciTxRxStats struct {
466 ListOutputOptions
467 Args struct {
468 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
469 } `positional-args:"yes"`
470}
471
praneeth nalmas1dd094c2022-12-22 14:15:13 +0530472type GetOnuOmciActiveAlarms struct {
473 ListOutputOptions
474 Args struct {
475 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
476 } `positional-args:"yes"`
477}
478
Akash Soni66db9632024-04-15 09:05:15 +0530479type GetOnuDistance struct {
480 ListOutputOptions
481 Args struct {
482 Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"`
483 OnuId OnuId `positional-arg-name:"ONU_ID" required:"yes"`
484 } `positional-args:"yes"` //onu device id
485}
486
Zack Williamse940c7a2019-08-21 14:25:39 -0700487type DeviceOpts struct {
Himani Chawla3c161c62021-05-13 16:36:51 +0530488 List DeviceList `command:"list"`
489 Create DeviceCreate `command:"create"`
490 Delete DeviceDelete `command:"delete"`
491 Enable DeviceEnable `command:"enable"`
492 Disable DeviceDisable `command:"disable"`
493 Flows DeviceFlowList `command:"flows"`
494 Groups DeviceFlowGroupList `command:"groups"`
kesavand12cd8eb2020-01-20 22:25:22 -0500495 Port struct {
496 List DevicePortList `command:"list"`
497 Enable DevicePortEnable `command:"enable"`
498 Disable DevicePortDisable `command:"disable"`
499 } `command:"port"`
500 Inspect DeviceInspect `command:"inspect"`
501 Reboot DeviceReboot `command:"reboot"`
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -0800502 Value struct {
503 Get DeviceGetExtValue `command:"get"`
504 } `command:"value"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000505 PmConfig struct {
Rohan Agrawald7df3772020-06-29 11:23:36 +0000506 Get DevicePmConfigsGet `command:"get"`
507 MaxSkew struct {
508 Set DevicePmConfigSetMaxSkew `command:"set"`
509 } `command:"maxskew"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000510 Frequency struct {
511 Set DevicePmConfigFrequencySet `command:"set"`
512 } `command:"frequency"`
513 Metric struct {
514 List DevicePmConfigMetricList `command:"list"`
515 Enable DevicePmConfigMetricEnable `command:"enable"`
516 Disable DevicePmConfigMetricDisable `command:"disable"`
517 } `command:"metric"`
518 Group struct {
Girish Gowdra610acb42021-01-27 13:33:57 -0800519 List DevicePmConfigGroupList `command:"list"`
520 Enable DevicePmConfigGroupEnable `command:"enable"`
521 Disable DevicePmConfigGroupDisable `command:"disable"`
522 Set DevicePmConfigGroupFrequencySet `command:"set"`
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000523 } `command:"group"`
524 GroupMetric struct {
525 List DevicePmConfigGroupMetricList `command:"list"`
526 } `command:"groupmetric"`
527 } `command:"pmconfig"`
Andrea Campanella791d88b2021-01-08 13:29:00 +0100528 Image struct {
529 Get DeviceOnuListImages `command:"list"`
530 Download DeviceOnuDownloadImage `command:"download"`
531 Activate DeviceOnuActivateImageUpdate `command:"activate"`
532 } `command:"image"`
kesavand3e2f9f62021-04-22 11:06:38 +0530533 DownloadImage struct {
534 Download OnuDownloadImage `command:"download"`
535 Activate OnuActivateImage `command:"activate"`
536 Commit OnuCommitImage `command:"commit"`
537 AbortUpgrade OnuAbortUpgradeImage `command:"abort"`
538 Status OnuImageStatus `command:"status"`
539 List OnuListImages `command:"list" `
540 } `command:"onuimage"`
kesavand8ec4fc02021-01-27 09:10:22 -0500541 GetExtVal struct {
Himani Chawla553a1392021-06-10 23:39:17 +0530542 Stats DeviceGetPortStats `command:"portstats"`
543 UniStatus UniStatus `command:"unistatus"`
544 OpticalInfo OnuPonOpticalInfo `command:"onu_pon_optical_info"`
545 OnuStats GetOnuStats `command:"onu_stats"`
546 EthernetFrameExtendedPm GetOnuEthernetFrameExtendedPmCounters `command:"ethernet_frame_extended_pm"`
547 RxPower RxPower `command:"rxpower"`
serkantul3d22fc72022-09-14 12:22:56 +0300548 OnuOmciStats OnuOmciTxRxStats `command:"onu_omci_stats"`
praneeth nalmas1dd094c2022-12-22 14:15:13 +0530549 OnuOmciActiveAlarms GetOnuOmciActiveAlarms `command:"onu_omci_active_alarms"`
praneeth nalmas39c71ad2023-09-27 18:29:04 +0530550 PonRxPower PonRxPower `command:"pon_rx_power"`
Akash Soni66db9632024-04-15 09:05:15 +0530551 OnuDistance GetOnuDistance `command:"onu_distance"`
Akash Soni51b6b7a2024-11-20 11:39:38 +0530552 OffloadAppStats GetOffloadAppStats `command:"offload_app_stats"`
kesavand8ec4fc02021-01-27 09:10:22 -0500553 } `command:"getextval"`
Akash Soni51b6b7a2024-11-20 11:39:38 +0530554 SetExtVal struct {
555 OffloadAppStatsSet SetOffloadAppState `command:"set_offload_app_stats"`
556 OnuOffloadStatsSet SetOnuOffloadState `command:"set_onu_offload_stats"`
557 } `command:"setextval"`
Zack Williamse940c7a2019-08-21 14:25:39 -0700558}
559
560var deviceOpts = DeviceOpts{}
561
562func RegisterDeviceCommands(parser *flags.Parser) {
David Bainbridge12f036f2019-10-15 22:09:04 +0000563 if _, err := parser.AddCommand("device", "device commands", "Commands to query and manipulate VOLTHA devices", &deviceOpts); err != nil {
David Bainbridgea6722342019-10-24 23:55:53 +0000564 Error.Fatalf("Unexpected error while attempting to register device commands : %s", err)
David Bainbridge12f036f2019-10-15 22:09:04 +0000565 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700566}
567
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000568func (i *MetricName) Complete(match string) []flags.Completion {
569 conn, err := NewConnection()
570 if err != nil {
571 return nil
572 }
573 defer conn.Close()
574
575 client := voltha.NewVolthaServiceClient(conn)
576
577 var deviceId string
578found:
579 for i := len(os.Args) - 1; i >= 0; i -= 1 {
580 switch os.Args[i] {
581 case "enable":
582 fallthrough
583 case "disable":
584 if len(os.Args) > i+1 {
585 deviceId = os.Args[i+1]
586 } else {
587 return nil
588 }
589 break found
590 default:
591 }
592 }
593
594 if len(deviceId) == 0 {
595 return nil
596 }
597
David K. Bainbridge9189c632021-03-26 21:52:21 +0000598 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000599 defer cancel()
600
601 id := voltha.ID{Id: string(deviceId)}
602
603 pmconfigs, err := client.ListDevicePmConfigs(ctx, &id)
604
605 if err != nil {
606 return nil
607 }
608
609 list := make([]flags.Completion, 0)
610 for _, metrics := range pmconfigs.Metrics {
611 if strings.HasPrefix(metrics.Name, match) {
612 list = append(list, flags.Completion{Item: metrics.Name})
613 }
614 }
615
616 return list
617}
618
619func (i *GroupName) Complete(match string) []flags.Completion {
620 conn, err := NewConnection()
621 if err != nil {
622 return nil
623 }
624 defer conn.Close()
625
626 client := voltha.NewVolthaServiceClient(conn)
627
628 var deviceId string
629found:
630 for i := len(os.Args) - 1; i >= 0; i -= 1 {
631 switch os.Args[i] {
632 case "list":
633 fallthrough
634 case "enable":
635 fallthrough
636 case "disable":
637 if len(os.Args) > i+1 {
638 deviceId = os.Args[i+1]
639 } else {
640 return nil
641 }
642 break found
643 default:
644 }
645 }
646
647 if len(deviceId) == 0 {
648 return nil
649 }
650
David K. Bainbridge9189c632021-03-26 21:52:21 +0000651 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +0000652 defer cancel()
653
654 id := voltha.ID{Id: string(deviceId)}
655
656 pmconfigs, err := client.ListDevicePmConfigs(ctx, &id)
657
658 if err != nil {
659 return nil
660 }
661
662 list := make([]flags.Completion, 0)
663 for _, group := range pmconfigs.Groups {
664 if strings.HasPrefix(group.GroupName, match) {
665 list = append(list, flags.Completion{Item: group.GroupName})
666 }
667 }
668 return list
669}
670
kesavand12cd8eb2020-01-20 22:25:22 -0500671func (i *PortNum) Complete(match string) []flags.Completion {
672 conn, err := NewConnection()
673 if err != nil {
674 return nil
675 }
676 defer conn.Close()
677
Scott Baker9173ed82020-05-19 08:30:12 -0700678 client := voltha.NewVolthaServiceClient(conn)
kesavand12cd8eb2020-01-20 22:25:22 -0500679
680 /*
681 * The command line args when completing for PortNum will be a DeviceId
682 * followed by one or more PortNums. So walk the argument list from the
683 * end and find the first argument that is enable/disable as those are
684 * the subcommands that come before the positional arguments. It would
685 * be nice if this package gave us the list of optional arguments
686 * already parsed.
687 */
688 var deviceId string
689found:
690 for i := len(os.Args) - 1; i >= 0; i -= 1 {
691 switch os.Args[i] {
692 case "enable":
693 fallthrough
694 case "disable":
695 if len(os.Args) > i+1 {
696 deviceId = os.Args[i+1]
697 } else {
698 return nil
699 }
700 break found
701 default:
702 }
703 }
704
705 if len(deviceId) == 0 {
706 return nil
707 }
708
David K. Bainbridge9189c632021-03-26 21:52:21 +0000709 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand12cd8eb2020-01-20 22:25:22 -0500710 defer cancel()
kesavand12cd8eb2020-01-20 22:25:22 -0500711
Scott Baker9173ed82020-05-19 08:30:12 -0700712 id := voltha.ID{Id: string(deviceId)}
kesavand12cd8eb2020-01-20 22:25:22 -0500713
Scott Baker9173ed82020-05-19 08:30:12 -0700714 ports, err := client.ListDevicePorts(ctx, &id)
kesavand12cd8eb2020-01-20 22:25:22 -0500715 if err != nil {
716 return nil
717 }
718
719 list := make([]flags.Completion, 0)
Scott Baker9173ed82020-05-19 08:30:12 -0700720 for _, item := range ports.Items {
721 pn := strconv.FormatUint(uint64(item.PortNo), 10)
kesavand12cd8eb2020-01-20 22:25:22 -0500722 if strings.HasPrefix(pn, match) {
723 list = append(list, flags.Completion{Item: pn})
724 }
725 }
726
727 return list
728}
729
Zack Williamse940c7a2019-08-21 14:25:39 -0700730func (i *DeviceId) Complete(match string) []flags.Completion {
731 conn, err := NewConnection()
732 if err != nil {
733 return nil
734 }
735 defer conn.Close()
736
Scott Baker9173ed82020-05-19 08:30:12 -0700737 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700738
David K. Bainbridge9189c632021-03-26 21:52:21 +0000739 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700740 defer cancel()
741
Scott Baker9173ed82020-05-19 08:30:12 -0700742 devices, err := client.ListDevices(ctx, &empty.Empty{})
Zack Williamse940c7a2019-08-21 14:25:39 -0700743 if err != nil {
744 return nil
745 }
746
747 list := make([]flags.Completion, 0)
Scott Baker9173ed82020-05-19 08:30:12 -0700748 for _, item := range devices.Items {
749 if strings.HasPrefix(item.Id, match) {
750 list = append(list, flags.Completion{Item: item.Id})
Zack Williamse940c7a2019-08-21 14:25:39 -0700751 }
752 }
753
754 return list
755}
756
757func (options *DeviceList) Execute(args []string) error {
758
759 conn, err := NewConnection()
760 if err != nil {
761 return err
762 }
763 defer conn.Close()
764
Scott Baker9173ed82020-05-19 08:30:12 -0700765 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700766
David K. Bainbridge9189c632021-03-26 21:52:21 +0000767 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700768 defer cancel()
769
Scott Baker9173ed82020-05-19 08:30:12 -0700770 devices, err := client.ListDevices(ctx, &empty.Empty{})
Zack Williamse940c7a2019-08-21 14:25:39 -0700771 if err != nil {
772 return err
773 }
774
775 outputFormat := CharReplacer.Replace(options.Format)
776 if outputFormat == "" {
David Bainbridgea6722342019-10-24 23:55:53 +0000777 outputFormat = GetCommandOptionWithDefault("device-list", "format", DEFAULT_DEVICE_FORMAT)
Zack Williamse940c7a2019-08-21 14:25:39 -0700778 }
779 if options.Quiet {
780 outputFormat = "{{.Id}}"
781 }
782
David Bainbridgea6722342019-10-24 23:55:53 +0000783 orderBy := options.OrderBy
784 if orderBy == "" {
Hardik Windlass9361bb82022-03-23 05:58:48 +0000785 orderBy = GetCommandOptionWithDefault("device-list", "order", DEFAULT_DEVICE_ORDER)
David Bainbridgea6722342019-10-24 23:55:53 +0000786 }
787
Scott Baker9173ed82020-05-19 08:30:12 -0700788 // Make sure json output prints an empty list, not "null"
789 if devices.Items == nil {
790 devices.Items = make([]*voltha.Device, 0)
Zack Williamse940c7a2019-08-21 14:25:39 -0700791 }
792
793 result := CommandResult{
794 Format: format.Format(outputFormat),
795 Filter: options.Filter,
David Bainbridgea6722342019-10-24 23:55:53 +0000796 OrderBy: orderBy,
Zack Williamse940c7a2019-08-21 14:25:39 -0700797 OutputAs: toOutputType(options.OutputAs),
798 NameLimit: options.NameLimit,
Scott Baker9173ed82020-05-19 08:30:12 -0700799 Data: devices.Items,
Zack Williamse940c7a2019-08-21 14:25:39 -0700800 }
801
802 GenerateOutput(&result)
803 return nil
804}
805
806func (options *DeviceCreate) Execute(args []string) error {
807
Scott Baker9173ed82020-05-19 08:30:12 -0700808 device := voltha.Device{}
Zack Williamse940c7a2019-08-21 14:25:39 -0700809 if options.HostAndPort != "" {
Scott Baker9173ed82020-05-19 08:30:12 -0700810 device.Address = &voltha.Device_HostAndPort{HostAndPort: options.HostAndPort}
Zack Williamse940c7a2019-08-21 14:25:39 -0700811 } else if options.IPAddress != "" {
Scott Baker9173ed82020-05-19 08:30:12 -0700812 device.Address = &voltha.Device_Ipv4Address{Ipv4Address: options.IPAddress}
Hardik Windlassce1de342020-02-04 21:58:07 +0000813 }
814 if options.MACAddress != "" {
Scott Baker9173ed82020-05-19 08:30:12 -0700815 device.MacAddress = strings.ToLower(options.MACAddress)
Zack Williamse940c7a2019-08-21 14:25:39 -0700816 }
817 if options.DeviceType != "" {
Scott Baker9173ed82020-05-19 08:30:12 -0700818 device.Type = options.DeviceType
Zack Williamse940c7a2019-08-21 14:25:39 -0700819 }
820
821 conn, err := NewConnection()
822 if err != nil {
823 return err
824 }
825 defer conn.Close()
826
Scott Baker9173ed82020-05-19 08:30:12 -0700827 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700828
David K. Bainbridge9189c632021-03-26 21:52:21 +0000829 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700830 defer cancel()
831
Scott Baker9173ed82020-05-19 08:30:12 -0700832 createdDevice, err := client.CreateDevice(ctx, &device)
Zack Williamse940c7a2019-08-21 14:25:39 -0700833 if err != nil {
834 return err
Zack Williamse940c7a2019-08-21 14:25:39 -0700835 }
836
Scott Baker9173ed82020-05-19 08:30:12 -0700837 fmt.Printf("%s\n", createdDevice.Id)
Zack Williamse940c7a2019-08-21 14:25:39 -0700838
839 return nil
840}
841
842func (options *DeviceDelete) Execute(args []string) error {
843
844 conn, err := NewConnection()
845 if err != nil {
846 return err
847 }
848 defer conn.Close()
849
Scott Baker9173ed82020-05-19 08:30:12 -0700850 client := voltha.NewVolthaServiceClient(conn)
David Bainbridge7052fe82020-03-25 10:37:00 -0700851 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -0700852 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +0000853 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700854 defer cancel()
855
Scott Baker9173ed82020-05-19 08:30:12 -0700856 id := voltha.ID{Id: string(i)}
Himani Chawla9933ddc2020-10-12 23:53:27 +0530857 if options.Force {
858 _, err = client.ForceDeleteDevice(ctx, &id)
859 } else {
860 _, err = client.DeleteDevice(ctx, &id)
861 }
Scott Baker9173ed82020-05-19 08:30:12 -0700862
Zack Williamse940c7a2019-08-21 14:25:39 -0700863 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +0000864 Error.Printf("Error while deleting '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -0700865 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -0700866 continue
Zack Williamse940c7a2019-08-21 14:25:39 -0700867 }
868 fmt.Printf("%s\n", i)
869 }
870
David Bainbridge7052fe82020-03-25 10:37:00 -0700871 if lastErr != nil {
872 return NoReportErr
873 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700874 return nil
875}
876
877func (options *DeviceEnable) Execute(args []string) error {
878 conn, err := NewConnection()
879 if err != nil {
880 return err
881 }
882 defer conn.Close()
883
Scott Baker9173ed82020-05-19 08:30:12 -0700884 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700885
David Bainbridge7052fe82020-03-25 10:37:00 -0700886 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -0700887 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +0000888 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700889 defer cancel()
890
Scott Baker9173ed82020-05-19 08:30:12 -0700891 id := voltha.ID{Id: string(i)}
892
893 _, err := client.EnableDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -0700894 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +0000895 Error.Printf("Error while enabling '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -0700896 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -0700897 continue
Zack Williamse940c7a2019-08-21 14:25:39 -0700898 }
899 fmt.Printf("%s\n", i)
900 }
901
David Bainbridge7052fe82020-03-25 10:37:00 -0700902 if lastErr != nil {
903 return NoReportErr
904 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700905 return nil
906}
907
908func (options *DeviceDisable) Execute(args []string) error {
909 conn, err := NewConnection()
910 if err != nil {
911 return err
912 }
913 defer conn.Close()
914
Scott Baker9173ed82020-05-19 08:30:12 -0700915 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700916
David Bainbridge7052fe82020-03-25 10:37:00 -0700917 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -0700918 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +0000919 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700920 defer cancel()
921
Scott Baker9173ed82020-05-19 08:30:12 -0700922 id := voltha.ID{Id: string(i)}
923
924 _, err := client.DisableDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -0700925 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +0000926 Error.Printf("Error while disabling '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -0700927 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -0700928 continue
Zack Williamse940c7a2019-08-21 14:25:39 -0700929 }
930 fmt.Printf("%s\n", i)
931 }
932
David Bainbridge7052fe82020-03-25 10:37:00 -0700933 if lastErr != nil {
934 return NoReportErr
935 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700936 return nil
937}
938
939func (options *DeviceReboot) Execute(args []string) error {
940 conn, err := NewConnection()
941 if err != nil {
942 return err
943 }
944 defer conn.Close()
945
Scott Baker9173ed82020-05-19 08:30:12 -0700946 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700947
David Bainbridge7052fe82020-03-25 10:37:00 -0700948 var lastErr error
Zack Williamse940c7a2019-08-21 14:25:39 -0700949 for _, i := range options.Args.Ids {
David K. Bainbridge9189c632021-03-26 21:52:21 +0000950 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700951 defer cancel()
952
Scott Baker9173ed82020-05-19 08:30:12 -0700953 id := voltha.ID{Id: string(i)}
954
955 _, err := client.RebootDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -0700956 if err != nil {
David Bainbridge0f758d42019-10-26 05:17:48 +0000957 Error.Printf("Error while rebooting '%s': %s\n", i, err)
David Bainbridge7052fe82020-03-25 10:37:00 -0700958 lastErr = err
Zack Williamse940c7a2019-08-21 14:25:39 -0700959 continue
Zack Williamse940c7a2019-08-21 14:25:39 -0700960 }
961 fmt.Printf("%s\n", i)
962 }
963
David Bainbridge7052fe82020-03-25 10:37:00 -0700964 if lastErr != nil {
965 return NoReportErr
966 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700967 return nil
968}
969
970func (options *DevicePortList) Execute(args []string) error {
971
972 conn, err := NewConnection()
973 if err != nil {
974 return err
975 }
976 defer conn.Close()
977
Scott Baker9173ed82020-05-19 08:30:12 -0700978 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -0700979
David K. Bainbridge9189c632021-03-26 21:52:21 +0000980 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -0700981 defer cancel()
982
Scott Baker9173ed82020-05-19 08:30:12 -0700983 id := voltha.ID{Id: string(options.Args.Id)}
Zack Williamse940c7a2019-08-21 14:25:39 -0700984
Scott Baker9173ed82020-05-19 08:30:12 -0700985 ports, err := client.ListDevicePorts(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -0700986 if err != nil {
987 return err
988 }
989
990 outputFormat := CharReplacer.Replace(options.Format)
991 if outputFormat == "" {
David Bainbridgea6722342019-10-24 23:55:53 +0000992 outputFormat = GetCommandOptionWithDefault("device-ports", "format", DEFAULT_DEVICE_PORTS_FORMAT)
Zack Williamse940c7a2019-08-21 14:25:39 -0700993 }
Zack Williamse940c7a2019-08-21 14:25:39 -0700994
David Bainbridgea6722342019-10-24 23:55:53 +0000995 orderBy := options.OrderBy
996 if orderBy == "" {
997 orderBy = GetCommandOptionWithDefault("device-ports", "order", "")
998 }
999
Zack Williamse940c7a2019-08-21 14:25:39 -07001000 result := CommandResult{
1001 Format: format.Format(outputFormat),
1002 Filter: options.Filter,
David Bainbridgea6722342019-10-24 23:55:53 +00001003 OrderBy: orderBy,
Zack Williamse940c7a2019-08-21 14:25:39 -07001004 OutputAs: toOutputType(options.OutputAs),
1005 NameLimit: options.NameLimit,
Scott Baker9173ed82020-05-19 08:30:12 -07001006 Data: ports.Items,
Zack Williamse940c7a2019-08-21 14:25:39 -07001007 }
1008
1009 GenerateOutput(&result)
1010 return nil
1011}
1012
1013func (options *DeviceFlowList) Execute(args []string) error {
1014 fl := &FlowList{}
1015 fl.ListOutputOptions = options.ListOutputOptions
Maninder045921e2020-09-29 16:46:02 +05301016 fl.FlowIdOptions = options.FlowIdOptions
Zack Williamse940c7a2019-08-21 14:25:39 -07001017 fl.Args.Id = string(options.Args.Id)
David Bainbridgea6722342019-10-24 23:55:53 +00001018 fl.Method = "device-flows"
Zack Williamse940c7a2019-08-21 14:25:39 -07001019 return fl.Execute(args)
1020}
1021
Himani Chawla3c161c62021-05-13 16:36:51 +05301022func (options *DeviceFlowGroupList) Execute(args []string) error {
1023 grp := &GroupList{}
1024 grp.ListOutputOptions = options.ListOutputOptions
1025 grp.GroupListOptions = options.GroupListOptions
1026 grp.Args.Id = string(options.Args.Id)
1027 grp.Method = "device-groups"
1028 return grp.Execute(args)
1029}
1030
Zack Williamse940c7a2019-08-21 14:25:39 -07001031func (options *DeviceInspect) Execute(args []string) error {
1032 if len(args) > 0 {
1033 return fmt.Errorf("only a single argument 'DEVICE_ID' can be provided")
1034 }
1035
1036 conn, err := NewConnection()
1037 if err != nil {
1038 return err
1039 }
1040 defer conn.Close()
1041
Scott Baker9173ed82020-05-19 08:30:12 -07001042 client := voltha.NewVolthaServiceClient(conn)
Zack Williamse940c7a2019-08-21 14:25:39 -07001043
David K. Bainbridge9189c632021-03-26 21:52:21 +00001044 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Zack Williamse940c7a2019-08-21 14:25:39 -07001045 defer cancel()
1046
Scott Baker9173ed82020-05-19 08:30:12 -07001047 id := voltha.ID{Id: string(options.Args.Id)}
Zack Williamse940c7a2019-08-21 14:25:39 -07001048
Scott Baker9173ed82020-05-19 08:30:12 -07001049 device, err := client.GetDevice(ctx, &id)
Zack Williamse940c7a2019-08-21 14:25:39 -07001050 if err != nil {
1051 return err
1052 }
1053
Zack Williamse940c7a2019-08-21 14:25:39 -07001054 outputFormat := CharReplacer.Replace(options.Format)
1055 if outputFormat == "" {
David Bainbridgea6722342019-10-24 23:55:53 +00001056 outputFormat = GetCommandOptionWithDefault("device-inspect", "format", DEFAULT_DEVICE_INSPECT_FORMAT)
Zack Williamse940c7a2019-08-21 14:25:39 -07001057 }
1058 if options.Quiet {
1059 outputFormat = "{{.Id}}"
1060 }
1061
1062 result := CommandResult{
1063 Format: format.Format(outputFormat),
1064 OutputAs: toOutputType(options.OutputAs),
1065 NameLimit: options.NameLimit,
1066 Data: device,
1067 }
1068 GenerateOutput(&result)
1069 return nil
1070}
kesavand12cd8eb2020-01-20 22:25:22 -05001071
1072/*Device Port Enable */
1073func (options *DevicePortEnable) Execute(args []string) error {
1074 conn, err := NewConnection()
1075 if err != nil {
1076 return err
1077 }
1078 defer conn.Close()
1079
Scott Baker9173ed82020-05-19 08:30:12 -07001080 client := voltha.NewVolthaServiceClient(conn)
kesavand12cd8eb2020-01-20 22:25:22 -05001081
David K. Bainbridge9189c632021-03-26 21:52:21 +00001082 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand12cd8eb2020-01-20 22:25:22 -05001083 defer cancel()
1084
Scott Baker9173ed82020-05-19 08:30:12 -07001085 port := voltha.Port{DeviceId: string(options.Args.Id), PortNo: uint32(options.Args.PortId)}
1086
1087 _, err = client.EnablePort(ctx, &port)
kesavand12cd8eb2020-01-20 22:25:22 -05001088 if err != nil {
1089 Error.Printf("Error enabling port number %v on device Id %s,err=%s\n", options.Args.PortId, options.Args.Id, ErrorToString(err))
1090 return err
kesavand12cd8eb2020-01-20 22:25:22 -05001091 }
1092
1093 return nil
1094}
1095
Scott Baker9173ed82020-05-19 08:30:12 -07001096/*Device Port Disable */
kesavand12cd8eb2020-01-20 22:25:22 -05001097func (options *DevicePortDisable) Execute(args []string) error {
1098 conn, err := NewConnection()
1099 if err != nil {
1100 return err
1101 }
1102 defer conn.Close()
1103
Scott Baker9173ed82020-05-19 08:30:12 -07001104 client := voltha.NewVolthaServiceClient(conn)
1105
David K. Bainbridge9189c632021-03-26 21:52:21 +00001106 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand12cd8eb2020-01-20 22:25:22 -05001107 defer cancel()
1108
Scott Baker9173ed82020-05-19 08:30:12 -07001109 port := voltha.Port{DeviceId: string(options.Args.Id), PortNo: uint32(options.Args.PortId)}
1110
1111 _, err = client.DisablePort(ctx, &port)
kesavand12cd8eb2020-01-20 22:25:22 -05001112 if err != nil {
Scott Baker9173ed82020-05-19 08:30:12 -07001113 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 -05001114 return err
kesavand12cd8eb2020-01-20 22:25:22 -05001115 }
Scott Baker9173ed82020-05-19 08:30:12 -07001116
kesavand12cd8eb2020-01-20 22:25:22 -05001117 return nil
1118}
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08001119
Rohan Agrawald7df3772020-06-29 11:23:36 +00001120func (options *DevicePmConfigSetMaxSkew) Execute(args []string) error {
1121 conn, err := NewConnection()
1122 if err != nil {
1123 return err
1124 }
1125 defer conn.Close()
1126
1127 client := voltha.NewVolthaServiceClient(conn)
1128
David K. Bainbridge9189c632021-03-26 21:52:21 +00001129 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawald7df3772020-06-29 11:23:36 +00001130 defer cancel()
1131
1132 id := voltha.ID{Id: string(options.Args.Id)}
1133
1134 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1135 if err != nil {
1136 return err
1137 }
1138
1139 pmConfigs.MaxSkew = options.Args.MaxSkew
1140
1141 _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs)
1142 if err != nil {
1143 return err
1144 }
1145
1146 return nil
1147}
1148
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001149func (options *DevicePmConfigsGet) Execute(args []string) error {
1150
1151 conn, err := NewConnection()
1152 if err != nil {
1153 return err
1154 }
1155 defer conn.Close()
1156
1157 client := voltha.NewVolthaServiceClient(conn)
1158
David K. Bainbridge9189c632021-03-26 21:52:21 +00001159 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001160 defer cancel()
1161
1162 id := voltha.ID{Id: string(options.Args.Id)}
1163
1164 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1165 if err != nil {
1166 return err
1167 }
1168
1169 outputFormat := CharReplacer.Replace(options.Format)
1170 if outputFormat == "" {
1171 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GET_FORMAT)
1172 }
1173
1174 orderBy := options.OrderBy
1175 if orderBy == "" {
1176 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1177 }
1178
1179 result := CommandResult{
1180 Format: format.Format(outputFormat),
1181 Filter: options.Filter,
1182 OrderBy: orderBy,
1183 OutputAs: toOutputType(options.OutputAs),
1184 NameLimit: options.NameLimit,
1185 Data: pmConfigs,
1186 }
1187
1188 GenerateOutput(&result)
1189 return nil
1190
1191}
1192
1193func (options *DevicePmConfigMetricList) Execute(args []string) error {
1194
1195 conn, err := NewConnection()
1196 if err != nil {
1197 return err
1198 }
1199 defer conn.Close()
1200
1201 client := voltha.NewVolthaServiceClient(conn)
1202
David K. Bainbridge9189c632021-03-26 21:52:21 +00001203 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001204 defer cancel()
1205
1206 id := voltha.ID{Id: string(options.Args.Id)}
1207
1208 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1209 if err != nil {
1210 return err
1211 }
1212
1213 if !pmConfigs.Grouped {
1214 for _, metric := range pmConfigs.Metrics {
1215 if metric.SampleFreq == 0 {
1216 metric.SampleFreq = pmConfigs.DefaultFreq
1217 }
1218 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001219 outputFormat := CharReplacer.Replace(options.Format)
1220 if outputFormat == "" {
1221 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_METRIC_LIST_FORMAT)
1222 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001223
Rohan Agrawalbca69122020-06-17 14:59:03 +00001224 orderBy := options.OrderBy
1225 if orderBy == "" {
1226 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1227 }
1228
1229 result := CommandResult{
1230 Format: format.Format(outputFormat),
1231 Filter: options.Filter,
1232 OrderBy: orderBy,
1233 OutputAs: toOutputType(options.OutputAs),
1234 NameLimit: options.NameLimit,
1235 Data: pmConfigs.Metrics,
1236 }
1237
1238 GenerateOutput(&result)
1239 return nil
1240 } else {
1241 return fmt.Errorf("Device '%s' does not have Non Grouped Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001242 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001243}
1244
1245func (options *DevicePmConfigMetricEnable) Execute(args []string) error {
1246
1247 conn, err := NewConnection()
1248 if err != nil {
1249 return err
1250 }
1251 defer conn.Close()
1252
1253 client := voltha.NewVolthaServiceClient(conn)
1254
David K. Bainbridge9189c632021-03-26 21:52:21 +00001255 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001256 defer cancel()
1257
1258 id := voltha.ID{Id: string(options.Args.Id)}
1259
1260 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1261 if err != nil {
1262 return err
1263 }
1264
1265 if !pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001266 metrics := make(map[string]struct{})
1267 for _, metric := range pmConfigs.Metrics {
1268 metrics[metric.Name] = struct{}{}
1269 }
1270
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001271 for _, metric := range pmConfigs.Metrics {
1272 for _, mName := range options.Args.Metrics {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001273 if _, exist := metrics[string(mName)]; !exist {
1274 return fmt.Errorf("Metric Name '%s' does not exist", mName)
1275 }
1276
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001277 if string(mName) == metric.Name && !metric.Enabled {
1278 metric.Enabled = true
1279 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1280 if err != nil {
1281 return err
1282 }
1283 }
1284 }
1285 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001286 } else {
1287 return fmt.Errorf("Device '%s' does not have Non Grouped Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001288 }
1289 return nil
1290}
1291
1292func (options *DevicePmConfigMetricDisable) Execute(args []string) error {
1293
1294 conn, err := NewConnection()
1295 if err != nil {
1296 return err
1297 }
1298 defer conn.Close()
1299
1300 client := voltha.NewVolthaServiceClient(conn)
1301
David K. Bainbridge9189c632021-03-26 21:52:21 +00001302 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001303 defer cancel()
1304
1305 id := voltha.ID{Id: string(options.Args.Id)}
1306
1307 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1308 if err != nil {
1309 return err
1310 }
1311
1312 if !pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001313 metrics := make(map[string]struct{})
1314 for _, metric := range pmConfigs.Metrics {
1315 metrics[metric.Name] = struct{}{}
1316 }
1317
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001318 for _, metric := range pmConfigs.Metrics {
1319 for _, mName := range options.Args.Metrics {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001320 if _, have := metrics[string(mName)]; !have {
1321 return fmt.Errorf("Metric Name '%s' does not exist", mName)
1322 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001323 if string(mName) == metric.Name && metric.Enabled {
1324 metric.Enabled = false
1325 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1326 if err != nil {
1327 return err
1328 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001329 } else {
1330 return fmt.Errorf("Metric '%s' cannot be disabled", string(mName))
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001331 }
1332 }
1333 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001334 } else {
1335 return fmt.Errorf("Device '%s' does not have Non Grouped Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001336 }
1337 return nil
1338}
1339
1340func (options *DevicePmConfigGroupEnable) Execute(args []string) error {
1341
1342 conn, err := NewConnection()
1343 if err != nil {
1344 return err
1345 }
1346 defer conn.Close()
1347
1348 client := voltha.NewVolthaServiceClient(conn)
1349
David K. Bainbridge9189c632021-03-26 21:52:21 +00001350 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001351 defer cancel()
1352
1353 id := voltha.ID{Id: string(options.Args.Id)}
1354
1355 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1356 if err != nil {
1357 return err
1358 }
1359
1360 if pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001361 groups := make(map[string]struct{})
1362 for _, group := range pmConfigs.Groups {
1363 groups[group.GroupName] = struct{}{}
1364 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001365 for _, group := range pmConfigs.Groups {
Girish Gowdra610acb42021-01-27 13:33:57 -08001366 if _, have := groups[string(options.Args.Group)]; !have {
1367 return fmt.Errorf("Group Name '%s' does not exist", options.Args.Group)
1368 }
1369 if string(options.Args.Group) == group.GroupName && !group.Enabled {
1370 group.Enabled = true
1371 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1372 if err != nil {
1373 return err
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001374 }
1375 }
1376 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001377 } else {
1378 return fmt.Errorf("Device '%s' does not have Group Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001379 }
1380 return nil
1381}
1382
1383func (options *DevicePmConfigGroupDisable) Execute(args []string) error {
1384
1385 conn, err := NewConnection()
1386 if err != nil {
1387 return err
1388 }
1389 defer conn.Close()
1390
1391 client := voltha.NewVolthaServiceClient(conn)
1392
David K. Bainbridge9189c632021-03-26 21:52:21 +00001393 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001394 defer cancel()
1395
1396 id := voltha.ID{Id: string(options.Args.Id)}
1397
1398 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1399 if err != nil {
1400 return err
1401 }
1402
1403 if pmConfigs.Grouped {
Rohan Agrawalbca69122020-06-17 14:59:03 +00001404 groups := make(map[string]struct{})
1405 for _, group := range pmConfigs.Groups {
1406 groups[group.GroupName] = struct{}{}
1407 }
1408
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001409 for _, group := range pmConfigs.Groups {
Girish Gowdra610acb42021-01-27 13:33:57 -08001410 if _, have := groups[string(options.Args.Group)]; !have {
1411 return fmt.Errorf("Group Name '%s' does not exist", options.Args.Group)
1412 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001413
Girish Gowdra610acb42021-01-27 13:33:57 -08001414 if string(options.Args.Group) == group.GroupName && group.Enabled {
1415 group.Enabled = false
1416 _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs)
1417 if err != nil {
1418 return err
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001419 }
1420 }
1421 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001422 } else {
1423 return fmt.Errorf("Device '%s' does not have Group Metrics", options.Args.Id)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001424 }
1425 return nil
1426}
1427
Girish Gowdra610acb42021-01-27 13:33:57 -08001428func (options *DevicePmConfigGroupFrequencySet) Execute(args []string) error {
1429
1430 conn, err := NewConnection()
1431 if err != nil {
1432 return err
1433 }
1434 defer conn.Close()
1435
1436 client := voltha.NewVolthaServiceClient(conn)
1437
David K. Bainbridge9189c632021-03-26 21:52:21 +00001438 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Girish Gowdra610acb42021-01-27 13:33:57 -08001439 defer cancel()
1440
1441 id := voltha.ID{Id: string(options.Args.Id)}
1442
1443 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1444 if err != nil {
1445 return err
1446 }
1447
1448 if pmConfigs.Grouped {
1449 groups := make(map[string]struct{})
1450 for _, group := range pmConfigs.Groups {
1451 groups[group.GroupName] = struct{}{}
1452 }
1453
1454 for _, group := range pmConfigs.Groups {
1455 if _, have := groups[string(options.Args.Group)]; !have {
1456 return fmt.Errorf("group name '%s' does not exist", options.Args.Group)
1457 }
1458
1459 if string(options.Args.Group) == group.GroupName {
1460 if !group.Enabled {
1461 return fmt.Errorf("group '%s' is not enabled", options.Args.Group)
1462 }
1463 group.GroupFreq = uint32(options.Args.Interval.Seconds())
1464 _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs)
1465 if err != nil {
1466 return err
1467 }
1468 }
1469 }
1470 } else {
1471 return fmt.Errorf("device '%s' does not have group metrics", options.Args.Id)
1472 }
1473 return nil
1474}
1475
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001476func (options *DevicePmConfigGroupList) Execute(args []string) error {
1477
1478 conn, err := NewConnection()
1479 if err != nil {
1480 return err
1481 }
1482 defer conn.Close()
1483
1484 client := voltha.NewVolthaServiceClient(conn)
1485
David K. Bainbridge9189c632021-03-26 21:52:21 +00001486 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001487 defer cancel()
1488
1489 id := voltha.ID{Id: string(options.Args.Id)}
1490
1491 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1492 if err != nil {
1493 return err
1494 }
1495
1496 if pmConfigs.Grouped {
1497 for _, group := range pmConfigs.Groups {
1498 if group.GroupFreq == 0 {
1499 group.GroupFreq = pmConfigs.DefaultFreq
1500 }
1501 }
Rohan Agrawalbca69122020-06-17 14:59:03 +00001502 outputFormat := CharReplacer.Replace(options.Format)
1503 if outputFormat == "" {
1504 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GROUP_LIST_FORMAT)
1505 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001506
Rohan Agrawalbca69122020-06-17 14:59:03 +00001507 orderBy := options.OrderBy
1508 if orderBy == "" {
1509 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1510 }
1511
1512 result := CommandResult{
1513 Format: format.Format(outputFormat),
1514 Filter: options.Filter,
1515 OrderBy: orderBy,
1516 OutputAs: toOutputType(options.OutputAs),
1517 NameLimit: options.NameLimit,
1518 Data: pmConfigs.Groups,
1519 }
1520
1521 GenerateOutput(&result)
1522 } else {
1523 return fmt.Errorf("Device '%s' does not have Group Metrics", string(options.Args.Id))
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001524 }
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001525 return nil
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001526}
1527
1528func (options *DevicePmConfigGroupMetricList) Execute(args []string) error {
1529
1530 var metrics []*voltha.PmConfig
1531 conn, err := NewConnection()
1532 if err != nil {
1533 return err
1534 }
1535 defer conn.Close()
1536
1537 client := voltha.NewVolthaServiceClient(conn)
1538
David K. Bainbridge9189c632021-03-26 21:52:21 +00001539 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001540 defer cancel()
1541
1542 id := voltha.ID{Id: string(options.Args.Id)}
1543
1544 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1545 if err != nil {
1546 return err
1547 }
1548
1549 for _, groups := range pmConfigs.Groups {
1550
1551 if string(options.Args.Group) == groups.GroupName {
1552 for _, metric := range groups.Metrics {
1553 if metric.SampleFreq == 0 && groups.GroupFreq == 0 {
1554 metric.SampleFreq = pmConfigs.DefaultFreq
1555 } else {
1556 metric.SampleFreq = groups.GroupFreq
1557 }
1558 }
1559 metrics = groups.Metrics
1560 }
1561 }
1562
1563 outputFormat := CharReplacer.Replace(options.Format)
1564 if outputFormat == "" {
1565 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_METRIC_LIST_FORMAT)
1566 }
1567
1568 orderBy := options.OrderBy
1569 if orderBy == "" {
1570 orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "")
1571 }
1572
1573 result := CommandResult{
1574 Format: format.Format(outputFormat),
1575 Filter: options.Filter,
1576 OrderBy: orderBy,
1577 OutputAs: toOutputType(options.OutputAs),
1578 NameLimit: options.NameLimit,
1579 Data: metrics,
1580 }
1581
1582 GenerateOutput(&result)
1583 return nil
1584
1585}
1586
1587func (options *DevicePmConfigFrequencySet) Execute(args []string) error {
1588
1589 conn, err := NewConnection()
1590 if err != nil {
1591 return err
1592 }
1593 defer conn.Close()
1594
1595 client := voltha.NewVolthaServiceClient(conn)
1596
David K. Bainbridge9189c632021-03-26 21:52:21 +00001597 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001598 defer cancel()
1599
1600 id := voltha.ID{Id: string(options.Args.Id)}
1601
1602 pmConfigs, err := client.ListDevicePmConfigs(ctx, &id)
1603 if err != nil {
1604 return err
1605 }
1606
Girish Gowdra610acb42021-01-27 13:33:57 -08001607 pmConfigs.DefaultFreq = uint32(options.Args.Interval.Seconds())
Rohan Agrawal9228d2f2020-06-03 07:48:50 +00001608
1609 _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs)
1610 if err != nil {
1611 return err
1612 }
1613
1614 outputFormat := CharReplacer.Replace(options.Format)
1615 if outputFormat == "" {
1616 outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GET_FORMAT)
1617 }
1618 if options.Quiet {
1619 outputFormat = "{{.Id}}"
1620 }
1621
1622 result := CommandResult{
1623 Format: format.Format(outputFormat),
1624 OutputAs: toOutputType(options.OutputAs),
1625 NameLimit: options.NameLimit,
1626 Data: pmConfigs,
1627 }
1628
1629 GenerateOutput(&result)
1630 return nil
1631
1632}
1633
kesavand3e2f9f62021-04-22 11:06:38 +05301634func (options *OnuDownloadImage) Execute(args []string) error {
1635
1636 conn, err := NewConnection()
1637 if err != nil {
1638 return err
1639 }
1640 defer conn.Close()
1641
1642 client := voltha.NewVolthaServiceClient(conn)
1643
1644 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1645 defer cancel()
1646
1647 var devIDList []*common.ID
1648 for _, i := range options.Args.IDs {
1649
1650 devIDList = append(devIDList, &common.ID{Id: string(i)})
1651 }
1652
1653 downloadImage := voltha.DeviceImageDownloadRequest{
1654 DeviceId: devIDList,
1655 Image: &voltha.Image{
1656 Url: options.Args.Url,
1657 Crc32: options.Args.Crc,
ssiddiqui7bc89e92021-05-20 20:58:02 +05301658 Vendor: options.Args.Vendor,
kesavand3e2f9f62021-04-22 11:06:38 +05301659 Version: options.Args.ImageVersion,
1660 },
1661 ActivateOnSuccess: options.Args.ActivateOnSuccess,
1662 CommitOnSuccess: options.Args.CommitOnSuccess,
1663 }
1664
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001665 deviceImageResp, err := client.DownloadImageToDevice(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301666 if err != nil {
1667 return err
1668 }
1669
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001670 outputFormat := GetCommandOptionWithDefault("onu-image-download", "format", ONU_IMAGE_STATUS_FORMAT)
1671 // Make sure json output prints an empty list, not "null"
1672 if deviceImageResp.DeviceImageStates == nil {
1673 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1674 }
1675 result := CommandResult{
1676 Format: format.Format(outputFormat),
1677 OutputAs: toOutputType(options.OutputAs),
1678 NameLimit: options.NameLimit,
1679 Data: deviceImageResp.DeviceImageStates,
1680 }
1681 GenerateOutput(&result)
kesavand3e2f9f62021-04-22 11:06:38 +05301682 return nil
1683
1684}
1685
1686func (options *OnuActivateImage) Execute(args []string) error {
1687
1688 conn, err := NewConnection()
1689 if err != nil {
1690 return err
1691 }
1692 defer conn.Close()
1693
1694 client := voltha.NewVolthaServiceClient(conn)
1695
1696 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1697 defer cancel()
1698
1699 var devIDList []*common.ID
1700 for _, i := range options.Args.IDs {
1701
1702 devIDList = append(devIDList, &common.ID{Id: string(i)})
1703 }
1704
1705 downloadImage := voltha.DeviceImageRequest{
1706 DeviceId: devIDList,
1707 Version: options.Args.ImageVersion,
1708 CommitOnSuccess: options.Args.CommitOnSuccess,
1709 }
1710
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001711 deviceImageResp, err := client.ActivateImage(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301712 if err != nil {
1713 return err
1714 }
1715
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001716 outputFormat := GetCommandOptionWithDefault("onu-image-activate", "format", ONU_IMAGE_STATUS_FORMAT)
1717 // Make sure json output prints an empty list, not "null"
1718 if deviceImageResp.DeviceImageStates == nil {
1719 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1720 }
1721 result := CommandResult{
1722 Format: format.Format(outputFormat),
1723 OutputAs: toOutputType(options.OutputAs),
1724 NameLimit: options.NameLimit,
1725 Data: deviceImageResp.DeviceImageStates,
1726 }
1727 GenerateOutput(&result)
1728
kesavand3e2f9f62021-04-22 11:06:38 +05301729 return nil
1730
1731}
1732
1733func (options *OnuAbortUpgradeImage) Execute(args []string) error {
1734
1735 conn, err := NewConnection()
1736 if err != nil {
1737 return err
1738 }
1739 defer conn.Close()
1740
1741 client := voltha.NewVolthaServiceClient(conn)
1742
1743 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1744 defer cancel()
1745
1746 var devIDList []*common.ID
1747 for _, i := range options.Args.IDs {
1748
1749 devIDList = append(devIDList, &common.ID{Id: string(i)})
1750 }
1751
1752 downloadImage := voltha.DeviceImageRequest{
1753 DeviceId: devIDList,
1754 Version: options.Args.ImageVersion,
1755 }
1756
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001757 deviceImageResp, err := client.AbortImageUpgradeToDevice(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301758 if err != nil {
1759 return err
1760 }
1761
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001762 outputFormat := GetCommandOptionWithDefault("onu-image-abort", "format", ONU_IMAGE_STATUS_FORMAT)
1763 // Make sure json output prints an empty list, not "null"
1764 if deviceImageResp.DeviceImageStates == nil {
1765 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1766 }
1767 result := CommandResult{
1768 Format: format.Format(outputFormat),
1769 OutputAs: toOutputType(options.OutputAs),
1770 NameLimit: options.NameLimit,
1771 Data: deviceImageResp.DeviceImageStates,
1772 }
1773 GenerateOutput(&result)
1774
kesavand3e2f9f62021-04-22 11:06:38 +05301775 return nil
1776
1777}
1778
1779func (options *OnuCommitImage) Execute(args []string) error {
1780
1781 conn, err := NewConnection()
1782 if err != nil {
1783 return err
1784 }
1785 defer conn.Close()
1786
1787 client := voltha.NewVolthaServiceClient(conn)
1788
1789 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1790 defer cancel()
1791
1792 var devIDList []*common.ID
1793 for _, i := range options.Args.IDs {
1794
1795 devIDList = append(devIDList, &common.ID{Id: string(i)})
1796 }
1797 downloadImage := voltha.DeviceImageRequest{
1798 DeviceId: devIDList,
1799 Version: options.Args.ImageVersion,
1800 }
1801
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001802 deviceImageResp, err := client.CommitImage(ctx, &downloadImage)
kesavand3e2f9f62021-04-22 11:06:38 +05301803 if err != nil {
1804 return err
1805 }
1806
Andrea Campanellaeaf1e0c2021-06-07 14:41:34 +02001807 outputFormat := GetCommandOptionWithDefault("onu-image-commit", "format", ONU_IMAGE_STATUS_FORMAT)
1808 // Make sure json output prints an empty list, not "null"
1809 if deviceImageResp.DeviceImageStates == nil {
1810 deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1811 }
1812 result := CommandResult{
1813 Format: format.Format(outputFormat),
1814 OutputAs: toOutputType(options.OutputAs),
1815 NameLimit: options.NameLimit,
1816 Data: deviceImageResp.DeviceImageStates,
1817 }
1818 GenerateOutput(&result)
1819
kesavand3e2f9f62021-04-22 11:06:38 +05301820 return nil
1821
1822}
1823
1824func (options *OnuListImages) Execute(args []string) error {
1825
1826 conn, err := NewConnection()
1827 if err != nil {
1828 return err
1829 }
1830 defer conn.Close()
1831
1832 client := voltha.NewVolthaServiceClient(conn)
1833
1834 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1835 defer cancel()
1836
1837 id := common.ID{Id: string(options.Args.Id)}
1838
1839 onuImages, err := client.GetOnuImages(ctx, &id)
1840 if err != nil {
1841 return err
1842 }
1843
1844 outputFormat := CharReplacer.Replace(options.Format)
1845 if outputFormat == "" {
1846 outputFormat = GetCommandOptionWithDefault("onu-image-list", "format", ONU_IMAGE_LIST_FORMAT)
1847 }
1848
1849 if options.Quiet {
1850 outputFormat = "{{.Id}}"
1851 }
1852
1853 //TODO orderby
1854
1855 // Make sure json output prints an empty list, not "null"
1856 if onuImages.Items == nil {
1857 onuImages.Items = make([]*voltha.OnuImage, 0)
1858 }
1859
1860 result := CommandResult{
1861 Format: format.Format(outputFormat),
1862 OutputAs: toOutputType(options.OutputAs),
1863 NameLimit: options.NameLimit,
1864 Data: onuImages.Items,
1865 }
1866
1867 GenerateOutput(&result)
1868 return nil
1869
1870}
1871
1872func (options *OnuImageStatus) Execute(args []string) error {
1873
1874 conn, err := NewConnection()
1875 if err != nil {
1876 return err
1877 }
1878 defer conn.Close()
1879
1880 client := voltha.NewVolthaServiceClient(conn)
1881
1882 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
1883 defer cancel()
1884
1885 var devIDList []*common.ID
kesavand3e2f9f62021-04-22 11:06:38 +05301886
Elia Battiston859f3e62022-02-08 15:57:52 +01001887 if options.Args.IDs == nil {
1888 //Use an empty IDs list to retrieve the status of all devices
1889 //with the requested image version
1890 devIDList = []*common.ID{}
1891 } else {
1892 for _, i := range options.Args.IDs {
1893 devIDList = append(devIDList, &common.ID{Id: string(i)})
1894 }
kesavand3e2f9f62021-04-22 11:06:38 +05301895 }
1896
1897 imageStatusReq := voltha.DeviceImageRequest{
1898 DeviceId: devIDList,
1899 Version: options.Args.ImageVersion,
1900 }
1901 imageStatus, err := client.GetImageStatus(ctx, &imageStatusReq)
1902 if err != nil {
1903 return err
1904 }
1905
1906 outputFormat := CharReplacer.Replace(options.Format)
1907 if outputFormat == "" {
1908 outputFormat = GetCommandOptionWithDefault("device-image-list", "format", ONU_IMAGE_STATUS_FORMAT)
1909 }
1910
1911 if options.Quiet {
1912 outputFormat = "{{.Id}}"
1913 }
1914
1915 //TODO orderby
1916
1917 // Make sure json output prints an empty list, not "null"
1918 if imageStatus.DeviceImageStates == nil {
1919 imageStatus.DeviceImageStates = make([]*voltha.DeviceImageState, 0)
1920 }
1921
1922 result := CommandResult{
1923 Format: format.Format(outputFormat),
1924 OutputAs: toOutputType(options.OutputAs),
1925 NameLimit: options.NameLimit,
1926 Data: imageStatus.DeviceImageStates,
1927 }
1928
1929 GenerateOutput(&result)
1930 return nil
1931
1932}
1933
Andrea Campanella791d88b2021-01-08 13:29:00 +01001934func (options *DeviceOnuListImages) Execute(args []string) error {
1935
1936 conn, err := NewConnection()
1937 if err != nil {
1938 return err
1939 }
1940 defer conn.Close()
1941
1942 client := voltha.NewVolthaServiceClient(conn)
1943
David K. Bainbridge9189c632021-03-26 21:52:21 +00001944 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Andrea Campanella791d88b2021-01-08 13:29:00 +01001945 defer cancel()
1946
1947 id := common.ID{Id: string(options.Args.Id)}
1948
1949 imageDownloads, err := client.ListImageDownloads(ctx, &id)
1950 if err != nil {
1951 return err
1952 }
1953
1954 outputFormat := CharReplacer.Replace(options.Format)
1955 if outputFormat == "" {
1956 outputFormat = GetCommandOptionWithDefault("device-image-list", "format", DEFAULT_DEVICE_IMAGE_LIST_GET_FORMAT)
1957 }
1958
1959 if options.Quiet {
1960 outputFormat = "{{.Id}}"
1961 }
1962
1963 //TODO orderby
1964
1965 // Make sure json output prints an empty list, not "null"
1966 if imageDownloads.Items == nil {
1967 imageDownloads.Items = make([]*voltha.ImageDownload, 0)
1968 }
1969
1970 result := CommandResult{
1971 Format: format.Format(outputFormat),
1972 OutputAs: toOutputType(options.OutputAs),
1973 NameLimit: options.NameLimit,
1974 Data: imageDownloads.Items,
1975 }
1976
1977 GenerateOutput(&result)
1978 return nil
1979
1980}
1981
1982func (options *DeviceOnuDownloadImage) Execute(args []string) error {
1983
1984 conn, err := NewConnection()
1985 if err != nil {
1986 return err
1987 }
1988 defer conn.Close()
1989
1990 client := voltha.NewVolthaServiceClient(conn)
1991
David K. Bainbridge9189c632021-03-26 21:52:21 +00001992 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Andrea Campanella791d88b2021-01-08 13:29:00 +01001993 defer cancel()
1994
1995 downloadImage := voltha.ImageDownload{
1996 Id: string(options.Args.Id),
1997 Name: options.Args.Name,
1998 Url: options.Args.Url,
1999 Crc: options.Args.Crc,
2000 LocalDir: options.Args.LocalDir,
2001 }
2002
2003 _, err = client.DownloadImage(ctx, &downloadImage)
2004 if err != nil {
2005 return err
2006 }
2007
2008 return nil
2009
2010}
2011
2012func (options *DeviceOnuActivateImageUpdate) Execute(args []string) error {
2013
2014 conn, err := NewConnection()
2015 if err != nil {
2016 return err
2017 }
2018 defer conn.Close()
2019
2020 client := voltha.NewVolthaServiceClient(conn)
2021
David K. Bainbridge9189c632021-03-26 21:52:21 +00002022 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Andrea Campanella791d88b2021-01-08 13:29:00 +01002023 defer cancel()
2024
2025 downloadImage := voltha.ImageDownload{
2026 Id: string(options.Args.Id),
2027 Name: options.Args.Name,
2028 ImageVersion: options.Args.ImageVersion,
2029 SaveConfig: options.Args.SaveConfig,
2030 LocalDir: options.Args.LocalDir,
2031 }
2032
2033 _, err = client.ActivateImageUpdate(ctx, &downloadImage)
2034 if err != nil {
2035 return err
2036 }
2037
2038 return nil
2039
2040}
2041
Scott Baker9173ed82020-05-19 08:30:12 -07002042type ReturnValueRow struct {
2043 Name string `json:"name"`
2044 Result interface{} `json:"result"`
2045}
2046
kesavand8ec4fc02021-01-27 09:10:22 -05002047func (options *DeviceGetPortStats) Execute(args []string) error {
2048 conn, err := NewConnection()
2049 if err != nil {
2050 return err
2051 }
2052 defer conn.Close()
2053 client := extension.NewExtensionClient(conn)
2054 var portType extension.GetOltPortCounters_PortType
2055
2056 if options.Args.PortType == "pon" {
2057 portType = extension.GetOltPortCounters_Port_PON_OLT
2058 } else if options.Args.PortType == "nni" {
2059
2060 portType = extension.GetOltPortCounters_Port_ETHERNET_NNI
2061 } else {
2062 return fmt.Errorf("expected interface type pon/nni, provided %s", options.Args.PortType)
2063 }
2064
2065 singleGetValReq := extension.SingleGetValueRequest{
2066 TargetId: string(options.Args.Id),
2067 Request: &extension.GetValueRequest{
2068 Request: &extension.GetValueRequest_OltPortInfo{
2069 OltPortInfo: &extension.GetOltPortCounters{
2070 PortNo: options.Args.PortNo,
2071 PortType: portType,
2072 },
2073 },
2074 },
2075 }
2076
David K. Bainbridge9189c632021-03-26 21:52:21 +00002077 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand8ec4fc02021-01-27 09:10:22 -05002078 defer cancel()
2079 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2080 if err != nil {
2081 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2082 return err
2083 }
2084
2085 if rv.Response.Status != extension.GetValueResponse_OK {
2086 return fmt.Errorf("failed to get port stats %v", rv.Response.ErrReason.String())
2087 }
2088
2089 outputFormat := CharReplacer.Replace(options.Format)
2090 if outputFormat == "" {
2091 outputFormat = GetCommandOptionWithDefault("device-get-port-status", "format", DEFAULT_DEVICE_GET_PORT_STATUS_FORMAT)
2092 }
2093
2094 result := CommandResult{
2095 Format: format.Format(outputFormat),
2096 OutputAs: toOutputType(options.OutputAs),
2097 NameLimit: options.NameLimit,
2098 Data: rv.GetResponse().GetPortCoutners(),
2099 }
2100 GenerateOutput(&result)
2101 return nil
2102}
2103
Himani Chawla40acc122021-05-26 18:52:29 +05302104func (options *GetOnuStats) Execute(args []string) error {
2105 conn, err := NewConnection()
2106 if err != nil {
2107 return err
2108 }
2109 defer conn.Close()
2110 client := extension.NewExtensionClient(conn)
2111
2112 singleGetValReq := extension.SingleGetValueRequest{
2113 TargetId: string(options.Args.OltId),
2114 Request: &extension.GetValueRequest{
2115 Request: &extension.GetValueRequest_OnuPonInfo{
2116 OnuPonInfo: &extension.GetOnuCountersRequest{
2117 IntfId: options.Args.IntfId,
2118 OnuId: options.Args.OnuId,
2119 },
2120 },
2121 },
2122 }
2123 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2124 defer cancel()
2125 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2126 if err != nil {
2127 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.OltId, ErrorToString(err))
2128 return err
2129 }
2130
2131 if rv.Response.Status != extension.GetValueResponse_OK {
2132 return fmt.Errorf("failed to get onu stats %v", rv.Response.ErrReason.String())
2133 }
2134 outputFormat := CharReplacer.Replace(options.Format)
2135 data, formatStr := buildOnuStatsOutputFormat(rv.GetResponse().GetOnuPonCounters())
2136 if outputFormat == "" {
2137 outputFormat = GetCommandOptionWithDefault("device-get-onu-status", "format", formatStr)
2138 }
Himani Chawla553a1392021-06-10 23:39:17 +05302139 result := CommandResult{
2140 Format: format.Format(outputFormat),
2141 OutputAs: toOutputType(options.OutputAs),
2142 NameLimit: options.NameLimit,
2143 Data: data,
2144 }
2145 GenerateOutput(&result)
2146 return nil
2147}
Himani Chawla40acc122021-05-26 18:52:29 +05302148
Akash Soni51b6b7a2024-11-20 11:39:38 +05302149func (options *GetOffloadAppStats) Execute(args []string) error {
2150 // Establish a connection to the gRPC server
2151 conn, err := NewConnection()
2152 if err != nil {
2153 return err
2154 }
2155 defer conn.Close()
2156
2157 client := extension.NewExtensionClient(conn)
2158
2159 // Build the request
2160 singleGetValReq := &extension.SingleGetValueRequest{
2161 TargetId: string(options.Args.OltId),
2162 Request: &extension.GetValueRequest{
2163 Request: &extension.GetValueRequest_OffloadedAppsStats{
2164 OffloadedAppsStats: &extension.GetOffloadedAppsStatisticsRequest{
2165 StatsFor: options.Args.StatsFor,
2166 },
2167 },
2168 },
2169 }
2170
2171 // Set a context with timeout
2172 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2173 defer cancel()
2174
2175 // Perform the gRPC call
2176 rv, err := client.GetExtValue(ctx, singleGetValReq)
2177 if err != nil {
2178 Error.Printf("Error getting value for device ID %s, err=%s\n", options.Args.OltId, ErrorToString(err))
2179 return err
2180 }
2181
2182 // Check response status
2183 if rv.GetResponse().GetStatus() != extension.GetValueResponse_OK {
2184 return fmt.Errorf("failed to get offloaded app stats: %v", rv.GetResponse().GetErrReason().String())
2185 }
2186
2187 // Process the response data
2188 stats, formatStr := buildOffloadAppStatsOutputFormat(rv.GetResponse().GetOffloadedAppsStats())
2189 outputFormat := CharReplacer.Replace(options.Format)
2190 if outputFormat == "" {
2191 outputFormat = GetCommandOptionWithDefault("device-get-offload-app-stats", "format", formatStr)
2192 }
2193
2194 // Generate and display the output
2195 result := CommandResult{
2196 Format: format.Format(outputFormat),
2197 OutputAs: toOutputType(options.OutputAs),
2198 NameLimit: options.NameLimit,
2199 Data: stats,
2200 }
2201 GenerateOutput(&result)
2202
2203 return nil
2204}
2205
2206func (options *SetOffloadAppState) Execute(args []string) error {
2207 conn, err := NewConnection()
2208 if err != nil {
2209 return fmt.Errorf("failed to establish gRPC connection: %v", err)
2210 }
2211 defer conn.Close()
2212
2213 client := extension.NewExtensionClient(conn)
2214
2215 // Build the AppOffloadConfig request
2216 setValueRequest := &extension.SetValueRequest{
2217 Request: &extension.SetValueRequest_AppOffloadConfig{
2218 AppOffloadConfig: &options.Args.Config,
2219 },
2220 }
2221
2222 singleSetValReq := &extension.SingleSetValueRequest{
2223 TargetId: string(options.Args.OltId),
2224 Request: setValueRequest,
2225 }
2226
2227 // Make gRPC call
2228 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2229 defer cancel()
2230
2231 resp, err := client.SetExtValue(ctx, singleSetValReq)
2232 if err != nil {
2233 return fmt.Errorf("failed to set AppOffloadConfig: %v", err)
2234 }
2235
2236 if resp.Response.Status != extension.SetValueResponse_OK {
2237 return fmt.Errorf("failed with status %v: %s", resp.Response.Status, resp.Response.ErrReason)
2238 }
2239
2240 fmt.Printf("AppOffloadConfig successfully set for OLT ID: %s\n", options.Args.OltId)
2241 return nil
2242}
2243
2244func (options *SetOnuOffloadState) Execute(args []string) error {
2245 conn, err := NewConnection()
2246 if err != nil {
2247 return fmt.Errorf("failed to establish gRPC connection: %v", err)
2248 }
2249 defer conn.Close()
2250
2251 client := extension.NewExtensionClient(conn)
2252
2253 // Convert PerUniInfo to []*extension.AppOffloadOnuConfig_PerUniConfig
2254 var perUniInfo []*extension.AppOffloadOnuConfig_PerUniConfig
2255 for i := range options.Args.PerUniInfo {
2256 perUniInfo = append(perUniInfo, &options.Args.PerUniInfo[i])
2257 }
2258 // Build the AppOffloadOnuConfig request
2259 onuConfig := &extension.AppOffloadOnuConfig{
2260 OnuDeviceId: options.Args.OnuDeviceId,
2261 PerUniInfo: perUniInfo,
2262 }
2263
2264 setValueRequest := &extension.SetValueRequest{
2265 Request: &extension.SetValueRequest_AppOffloadOnuConfig{
2266 AppOffloadOnuConfig: onuConfig,
2267 },
2268 }
2269
2270 singleSetValReq := &extension.SingleSetValueRequest{
2271 TargetId: options.Args.OnuDeviceId,
2272 Request: setValueRequest,
2273 }
2274
2275 // Make gRPC call
2276 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2277 defer cancel()
2278
2279 resp, err := client.SetExtValue(ctx, singleSetValReq)
2280 if err != nil {
2281 return fmt.Errorf("failed to set AppOffloadOnuConfig: %v", err)
2282 }
2283
2284 if resp.Response.Status != extension.SetValueResponse_OK {
2285 return fmt.Errorf("failed with status %v: %s", resp.Response.Status, resp.Response.ErrReason)
2286 }
2287
2288 fmt.Printf("AppOffloadOnuConfig successfully set for ONU ID: %s\n", options.Args.OnuDeviceId)
2289 return nil
2290}
2291
Himani Chawla553a1392021-06-10 23:39:17 +05302292func (options *GetOnuEthernetFrameExtendedPmCounters) Execute(args []string) error {
2293 conn, err := NewConnection()
2294 if err != nil {
2295 return err
2296 }
2297 defer conn.Close()
2298 client := extension.NewExtensionClient(conn)
Himani Chawla806aa892021-08-30 15:51:46 +05302299 var singleGetValReq extension.SingleGetValueRequest
Himani Chawla553a1392021-06-10 23:39:17 +05302300
Himani Chawla806aa892021-08-30 15:51:46 +05302301 if options.Args.UniIndex != nil {
2302 singleGetValReq = extension.SingleGetValueRequest{
2303 TargetId: string(options.Args.Id),
2304 Request: &extension.GetValueRequest{
2305 Request: &extension.GetValueRequest_OnuInfo{
2306 OnuInfo: &extension.GetOmciEthernetFrameExtendedPmRequest{
2307 OnuDeviceId: string(options.Args.Id),
2308 Reset_: options.Reset,
2309 IsUniIndex: &extension.GetOmciEthernetFrameExtendedPmRequest_UniIndex{
2310 UniIndex: *options.Args.UniIndex,
2311 },
2312 },
Himani Chawla553a1392021-06-10 23:39:17 +05302313 },
2314 },
Himani Chawla806aa892021-08-30 15:51:46 +05302315 }
2316 } else {
2317 singleGetValReq = extension.SingleGetValueRequest{
2318 TargetId: string(options.Args.Id),
2319 Request: &extension.GetValueRequest{
2320 Request: &extension.GetValueRequest_OnuInfo{
2321 OnuInfo: &extension.GetOmciEthernetFrameExtendedPmRequest{
2322 OnuDeviceId: string(options.Args.Id),
2323 Reset_: options.Reset,
2324 },
2325 },
2326 },
2327 }
Himani Chawla553a1392021-06-10 23:39:17 +05302328 }
Himani Chawla806aa892021-08-30 15:51:46 +05302329
Himani Chawla553a1392021-06-10 23:39:17 +05302330 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2331 defer cancel()
2332 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2333 if err != nil {
2334 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2335 return err
2336 }
2337
2338 if rv.Response.Status != extension.GetValueResponse_OK {
2339 return fmt.Errorf("failed to get ethernet frame extended pm counters %v", rv.Response.ErrReason.String())
2340 }
2341 outputFormat := CharReplacer.Replace(options.Format)
2342 data := buildOnuEthernetFrameExtendedPmOutputFormat(rv.GetResponse().GetOnuCounters())
2343 if outputFormat == "" {
2344 outputFormat = GetCommandOptionWithDefault("device-get-onu-status", "format", DEFAULT_ETHERNET_FRAME_EXTENDED_PM_COUNTERS_FORMAT)
2345 }
Himani Chawla40acc122021-05-26 18:52:29 +05302346 result := CommandResult{
2347 Format: format.Format(outputFormat),
2348 OutputAs: toOutputType(options.OutputAs),
2349 NameLimit: options.NameLimit,
2350 Data: data,
2351 }
2352 GenerateOutput(&result)
2353 return nil
2354}
2355
kesavand6d1131f2021-02-05 22:38:15 +05302356func (options *UniStatus) Execute(args []string) error {
2357 conn, err := NewConnection()
2358 if err != nil {
2359 return err
2360 }
2361 defer conn.Close()
2362 client := extension.NewExtensionClient(conn)
2363
2364 singleGetValReq := extension.SingleGetValueRequest{
2365 TargetId: string(options.Args.Id),
2366 Request: &extension.GetValueRequest{
2367 Request: &extension.GetValueRequest_UniInfo{
2368 UniInfo: &extension.GetOnuUniInfoRequest{
2369 UniIndex: options.Args.UniIndex,
2370 },
2371 },
2372 },
2373 }
David K. Bainbridge9189c632021-03-26 21:52:21 +00002374 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
kesavand6d1131f2021-02-05 22:38:15 +05302375 defer cancel()
2376 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2377 if err != nil {
2378 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2379 return err
2380 }
2381 if rv.Response.Status != extension.GetValueResponse_OK {
2382 return fmt.Errorf("failed to get uni status %v", rv.Response.ErrReason.String())
2383 }
2384 outputFormat := CharReplacer.Replace(options.Format)
2385 if outputFormat == "" {
2386 outputFormat = GetCommandOptionWithDefault("device-get-uni-status", "format", DEFAULT_DEVICE_GET_UNI_STATUS_FORMAT)
2387 }
2388 result := CommandResult{
2389 Format: format.Format(outputFormat),
2390 OutputAs: toOutputType(options.OutputAs),
2391 NameLimit: options.NameLimit,
2392 Data: rv.GetResponse().GetUniInfo(),
2393 }
2394 GenerateOutput(&result)
2395 return nil
2396}
2397
Girish Gowdra4f5ce7c2021-04-29 18:53:21 -07002398func (options *OnuPonOpticalInfo) Execute(args []string) error {
2399 conn, err := NewConnection()
2400 if err != nil {
2401 return err
2402 }
2403 defer conn.Close()
2404 client := extension.NewExtensionClient(conn)
2405
2406 singleGetValReq := extension.SingleGetValueRequest{
2407 TargetId: string(options.Args.Id),
2408 Request: &extension.GetValueRequest{
2409 Request: &extension.GetValueRequest_OnuOpticalInfo{
2410 OnuOpticalInfo: &extension.GetOnuPonOpticalInfo{},
2411 },
2412 },
2413 }
2414 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2415 defer cancel()
2416 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2417 if err != nil {
2418 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2419 return err
2420 }
2421 if rv.Response.Status != extension.GetValueResponse_OK {
2422 return fmt.Errorf("failed to get onu pon optical info %v", rv.Response.ErrReason.String())
2423 }
2424 outputFormat := CharReplacer.Replace(options.Format)
2425 if outputFormat == "" {
2426 outputFormat = GetCommandOptionWithDefault("device-get-onu-pon-optical-info", "format", DEFAULT_ONU_PON_OPTICAL_INFO_STATUS_FORMAT)
2427 }
2428 result := CommandResult{
2429 Format: format.Format(outputFormat),
2430 OutputAs: toOutputType(options.OutputAs),
2431 NameLimit: options.NameLimit,
2432 Data: rv.GetResponse().GetOnuOpticalInfo(),
2433 }
2434 GenerateOutput(&result)
2435 return nil
2436}
2437
Gamze Abakac857a462021-05-26 13:45:54 +00002438func (options *RxPower) Execute(args []string) error {
2439 conn, err := NewConnection()
2440 if err != nil {
2441 return err
2442 }
2443 defer conn.Close()
2444 client := extension.NewExtensionClient(conn)
2445
2446 singleGetValReq := extension.SingleGetValueRequest{
2447 TargetId: string(options.Args.Id),
2448 Request: &extension.GetValueRequest{
2449 Request: &extension.GetValueRequest_RxPower{
2450 RxPower: &extension.GetRxPowerRequest{
2451 IntfId: options.Args.PortNo,
2452 OnuId: options.Args.OnuNo,
2453 },
2454 },
2455 },
2456 }
2457
2458 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2459 defer cancel()
2460 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2461 if err != nil {
2462 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2463 return err
2464 }
2465 if rv.Response.Status != extension.GetValueResponse_OK {
2466 return fmt.Errorf("failed to get rx power %v", rv.Response.ErrReason.String())
2467 }
2468 outputFormat := CharReplacer.Replace(options.Format)
2469 if outputFormat == "" {
2470 outputFormat = GetCommandOptionWithDefault("device-get-rx-power", "format", DEFAULT_RX_POWER_STATUS_FORMAT)
2471 }
2472 result := CommandResult{
2473 Format: format.Format(outputFormat),
2474 OutputAs: toOutputType(options.OutputAs),
2475 NameLimit: options.NameLimit,
2476 Data: rv.GetResponse().GetRxPower(),
2477 }
2478 GenerateOutput(&result)
2479 return nil
2480}
2481
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002482/*Device get Onu Distance */
2483func (options *DeviceGetExtValue) Execute(args []string) error {
2484 conn, err := NewConnection()
2485 if err != nil {
2486 return err
2487 }
2488 defer conn.Close()
2489
Scott Baker9173ed82020-05-19 08:30:12 -07002490 client := voltha.NewVolthaServiceClient(conn)
2491
khenaidoo080ce882021-10-19 17:35:08 -04002492 valueflag, okay := extension.ValueType_Type_value[string(options.Args.Valueflag)]
Scott Baker9173ed82020-05-19 08:30:12 -07002493 if !okay {
2494 Error.Printf("Unknown valueflag %s\n", options.Args.Valueflag)
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002495 }
2496
khenaidoo080ce882021-10-19 17:35:08 -04002497 val := extension.ValueSpecifier{Id: string(options.Args.Id), Value: extension.ValueType_Type(valueflag)}
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002498
David K. Bainbridge9189c632021-03-26 21:52:21 +00002499 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002500 defer cancel()
2501
Scott Baker9173ed82020-05-19 08:30:12 -07002502 rv, err := client.GetExtValue(ctx, &val)
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002503 if err != nil {
2504 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2505 return err
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002506 }
2507
Scott Baker9173ed82020-05-19 08:30:12 -07002508 var rows []ReturnValueRow
khenaidoo080ce882021-10-19 17:35:08 -04002509 for name, num := range extension.ValueType_Type_value {
Scott Baker9173ed82020-05-19 08:30:12 -07002510 if num == 0 {
2511 // EMPTY is not a real value
2512 continue
2513 }
2514 if (rv.Error & uint32(num)) != 0 {
2515 row := ReturnValueRow{Name: name, Result: "Error"}
2516 rows = append(rows, row)
2517 }
2518 if (rv.Unsupported & uint32(num)) != 0 {
2519 row := ReturnValueRow{Name: name, Result: "Unsupported"}
2520 rows = append(rows, row)
2521 }
2522 if (rv.Set & uint32(num)) != 0 {
2523 switch name {
2524 case "DISTANCE":
2525 row := ReturnValueRow{Name: name, Result: rv.Distance}
2526 rows = append(rows, row)
2527 default:
2528 row := ReturnValueRow{Name: name, Result: "Unimplemented-in-voltctl"}
2529 rows = append(rows, row)
2530 }
2531 }
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002532 }
2533
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002534 outputFormat := CharReplacer.Replace(options.Format)
2535 if outputFormat == "" {
2536 outputFormat = GetCommandOptionWithDefault("device-value-get", "format", DEFAULT_DEVICE_VALUE_GET_FORMAT)
2537 }
2538
2539 result := CommandResult{
2540 Format: format.Format(outputFormat),
2541 OutputAs: toOutputType(options.OutputAs),
2542 NameLimit: options.NameLimit,
Scott Baker9173ed82020-05-19 08:30:12 -07002543 Data: rows,
Dinesh Belwalkarc9aa6d82020-03-04 15:22:17 -08002544 }
2545 GenerateOutput(&result)
2546 return nil
2547}
serkantul3d22fc72022-09-14 12:22:56 +03002548
2549/*Device get Onu OMCI TX RX Stats */
2550func (options *OnuOmciTxRxStats) Execute(args []string) error {
2551 conn, err := NewConnection()
2552 if err != nil {
2553 return err
2554 }
2555 defer conn.Close()
2556 client := extension.NewExtensionClient(conn)
2557
2558 singleGetValReq := extension.SingleGetValueRequest{
2559 TargetId: string(options.Args.Id),
2560 Request: &extension.GetValueRequest{
2561 Request: &extension.GetValueRequest_OnuOmciStats{
2562 OnuOmciStats: &extension.GetOnuOmciTxRxStatsRequest{},
2563 },
2564 },
2565 }
2566
2567 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2568 defer cancel()
2569 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2570 if err != nil {
2571 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2572 return err
2573 }
2574
2575 if rv.Response.Status != extension.GetValueResponse_OK {
2576 return fmt.Errorf("failed to get onu omci tx rx stats %v", rv.Response.ErrReason.String())
2577 }
2578 outputFormat := CharReplacer.Replace(options.Format)
2579 if outputFormat == "" {
2580 outputFormat = GetCommandOptionWithDefault("device-get-onu-omci-tx-rx-stats", "format", DEFAULT_ONU_OMCI_TX_RX_STATS_FORMAT)
2581 }
2582 result := CommandResult{
2583 Format: format.Format(outputFormat),
2584 OutputAs: toOutputType(options.OutputAs),
2585 NameLimit: options.NameLimit,
2586 Data: rv.GetResponse().GetOnuOmciStats(),
2587 }
2588 GenerateOutput(&result)
2589 return nil
2590}
praneeth nalmas1dd094c2022-12-22 14:15:13 +05302591
2592/*Device get Onu Active Alarms */
2593func (options *GetOnuOmciActiveAlarms) Execute(args []string) error {
2594 conn, err := NewConnection()
2595 if err != nil {
2596 return err
2597 }
2598 defer conn.Close()
2599 client := extension.NewExtensionClient(conn)
2600
2601 singleGetValReq := extension.SingleGetValueRequest{
2602 TargetId: string(options.Args.Id),
2603 Request: &extension.GetValueRequest{
2604 Request: &extension.GetValueRequest_OnuActiveAlarms{
2605 OnuActiveAlarms: &extension.GetOnuOmciActiveAlarmsRequest{},
2606 },
2607 },
2608 }
2609 Info.Printf("Getting omci_active_alarms for device Id %s\n", options.Args.Id)
2610 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2611 defer cancel()
2612 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2613 if err != nil {
2614 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2615 return err
2616 }
2617
2618 if rv.Response.Status != extension.GetValueResponse_OK {
2619 return fmt.Errorf("failed to get onu omci active alarms list %v", rv.Response.ErrReason.String())
2620 }
2621 outputFormat := CharReplacer.Replace(options.Format)
2622 if outputFormat == "" {
2623 outputFormat = GetCommandOptionWithDefault("device-get-onu-omci-active-alarms", "format", DEFAULT_DEVICE_ALARMS_FORMAT)
2624 }
2625
2626 orderBy := options.OrderBy
2627 if orderBy == "" {
2628 orderBy = GetCommandOptionWithDefault("device-list", "order", DEFAULT_DEVICE_ALARMS_ORDER)
2629 }
2630
2631 result := CommandResult{
2632 Format: format.Format(outputFormat),
2633 OutputAs: toOutputType(options.OutputAs),
2634 OrderBy: orderBy,
2635 NameLimit: options.NameLimit,
2636 Data: rv.GetResponse().GetOnuActiveAlarms().GetActiveAlarms(),
2637 }
2638 GenerateOutput(&result)
2639 return nil
2640}
praneeth nalmas39c71ad2023-09-27 18:29:04 +05302641
Akash Soni66db9632024-04-15 09:05:15 +05302642/*Device get Onu Active Alarms */
2643func (options *GetOnuDistance) Execute(args []string) error {
2644 conn, err := NewConnection()
2645 if err != nil {
2646 return err
2647 }
2648 defer conn.Close()
2649 client := extension.NewExtensionClient(conn)
2650
2651 singleGetValReq := extension.SingleGetValueRequest{
2652 TargetId: string(options.Args.Id),
2653 Request: &extension.GetValueRequest{
2654 Request: &extension.GetValueRequest_Distance{
2655 Distance: &extension.GetDistanceRequest{
2656 OnuDeviceId: string(options.Args.OnuId),
2657 },
2658 },
2659 },
2660 }
2661 Info.Printf("Getting onu distance for device Id %s\n", options.Args.Id)
2662 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2663 defer cancel()
2664 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2665 if err != nil {
2666 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2667 return err
2668 }
2669
2670 if rv.Response.Status != extension.GetValueResponse_OK {
2671 return fmt.Errorf("failed to get onu distance stats %v", rv.Response.ErrReason.String())
2672 }
2673 outputFormat := CharReplacer.Replace(options.Format)
2674 if outputFormat == "" {
2675 outputFormat = GetCommandOptionWithDefault("get-onu-distance", "format", DEFAULT_ONU_DISTANCE_FORMAT)
2676 }
2677
2678 result := CommandResult{
2679 Format: format.Format(outputFormat),
2680 OutputAs: toOutputType(options.OutputAs),
2681 NameLimit: options.NameLimit,
2682 Data: rv.GetResponse().GetDistance().GetDistance(),
2683 }
2684 fmt.Println("onu distance : ", rv)
2685 GenerateOutput(&result)
2686 return nil
2687}
2688
praneeth nalmas39c71ad2023-09-27 18:29:04 +05302689func (options *PonRxPower) Execute(args []string) error {
2690 conn, err := NewConnection()
2691 if err != nil {
2692 return err
2693 }
2694 defer conn.Close()
2695 client := extension.NewExtensionClient(conn)
2696
2697 singleGetValReq := extension.SingleGetValueRequest{
2698 TargetId: string(options.Args.Id),
2699 Request: &extension.GetValueRequest{
2700 Request: &extension.GetValueRequest_OltRxPower{
2701 OltRxPower: &extension.GetOltRxPowerRequest{
2702 PortLabel: options.Args.PortLabel,
2703 OnuSn: options.Args.SerialNo,
2704 },
2705 },
2706 },
2707 }
2708
2709 ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout)
2710 defer cancel()
2711 rv, err := client.GetExtValue(ctx, &singleGetValReq)
2712 if err != nil {
2713 Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err))
2714 return err
2715 }
2716 if rv.Response.Status != extension.GetValueResponse_OK {
2717 return fmt.Errorf("failed to get rx power %v", rv.Response.ErrReason.String())
2718 }
2719 outputFormat := CharReplacer.Replace(options.Format)
2720 if outputFormat == "" {
2721 outputFormat = GetCommandOptionWithDefault("device-get-pon-rx-power", "format", DEFAULT_PON_RX_POWER_STATUS_FORMAT)
2722 }
2723 result := CommandResult{
2724 Format: format.Format(outputFormat),
2725 OutputAs: toOutputType(options.OutputAs),
2726 NameLimit: options.NameLimit,
2727 Data: rv.GetResponse().GetOltRxPower().GetRxPower(),
2728 }
2729 GenerateOutput(&result)
2730 return nil
2731}