| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package commands |
| 17 | |
| 18 | import ( |
| 19 | "context" |
| Akash Soni | 6e879c2 | 2024-12-20 17:01:34 +0530 | [diff] [blame] | 20 | "encoding/json" |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 21 | "fmt" |
| David Bainbridge | 7052fe8 | 2020-03-25 10:37:00 -0700 | [diff] [blame] | 22 | "os" |
| 23 | "strconv" |
| 24 | "strings" |
| Girish Gowdra | 610acb4 | 2021-01-27 13:33:57 -0800 | [diff] [blame] | 25 | "time" |
| David Bainbridge | 7052fe8 | 2020-03-25 10:37:00 -0700 | [diff] [blame] | 26 | |
| Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 27 | "github.com/golang/protobuf/ptypes/empty" |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 28 | flags "github.com/jessevdk/go-flags" |
| Scott Baker | 2b0ad65 | 2019-08-21 14:57:07 -0700 | [diff] [blame] | 29 | "github.com/opencord/voltctl/pkg/format" |
| David K. Bainbridge | bd6b288 | 2021-08-26 13:31:02 +0000 | [diff] [blame] | 30 | "github.com/opencord/voltha-protos/v5/go/common" |
| 31 | "github.com/opencord/voltha-protos/v5/go/extension" |
| 32 | "github.com/opencord/voltha-protos/v5/go/voltha" |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 33 | ) |
| 34 | |
| 35 | const ( |
| David K. Bainbridge | 89003c4 | 2020-02-27 17:22:49 -0800 | [diff] [blame] | 36 | DEFAULT_DEVICE_FORMAT = "table{{ .Id }}\t{{.Type}}\t{{.Root}}\t{{.ParentId}}\t{{.SerialNumber}}\t{{.AdminState}}\t{{.OperStatus}}\t{{.ConnectStatus}}\t{{.Reason}}" |
| Hardik Windlass | 9361bb8 | 2022-03-23 05:58:48 +0000 | [diff] [blame] | 37 | DEFAULT_DEVICE_ORDER = "Type,Id" |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 38 | DEFAULT_DEVICE_PORTS_FORMAT = "table{{.PortNo}}\t{{.Label}}\t{{.Type}}\t{{.AdminState}}\t{{.OperStatus}}\t{{.DeviceId}}\t{{.Peers}}" |
| 39 | DEFAULT_DEVICE_INSPECT_FORMAT = `ID: {{.Id}} |
| 40 | TYPE: {{.Type}} |
| 41 | ROOT: {{.Root}} |
| 42 | PARENTID: {{.ParentId}} |
| 43 | SERIALNUMBER: {{.SerialNumber}} |
| 44 | VLAN: {{.Vlan}} |
| 45 | ADMINSTATE: {{.AdminState}} |
| 46 | OPERSTATUS: {{.OperStatus}} |
| 47 | CONNECTSTATUS: {{.ConnectStatus}}` |
| Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 48 | DEFAULT_DEVICE_PM_CONFIG_GET_FORMAT = "table{{.DefaultFreq}}\t{{.Grouped}}\t{{.FreqOverride}}" |
| 49 | DEFAULT_DEVICE_PM_CONFIG_METRIC_LIST_FORMAT = "table{{.Name}}\t{{.Type}}\t{{.Enabled}}\t{{.SampleFreq}}" |
| 50 | DEFAULT_DEVICE_PM_CONFIG_GROUP_LIST_FORMAT = "table{{.GroupName}}\t{{.Enabled}}\t{{.GroupFreq}}" |
| 51 | DEFAULT_DEVICE_VALUE_GET_FORMAT = "table{{.Name}}\t{{.Result}}" |
| Andrea Campanella | 791d88b | 2021-01-08 13:29:00 +0100 | [diff] [blame] | 52 | DEFAULT_DEVICE_IMAGE_LIST_GET_FORMAT = "table{{.Name}}\t{{.Url}}\t{{.Crc}}\t{{.DownloadState}}\t{{.ImageVersion}}\t{{.LocalDir}}\t{{.ImageState}}\t{{.FileSize}}" |
| ssiddiqui | 7bc89e9 | 2021-05-20 20:58:02 +0530 | [diff] [blame] | 53 | ONU_IMAGE_LIST_FORMAT = "table{{.Version}}\t{{.IsCommited}}\t{{.IsActive}}\t{{.IsValid}}\t{{.ProductCode}}\t{{.Hash}}" |
| 54 | ONU_IMAGE_STATUS_FORMAT = "table{{.DeviceId}}\t{{.ImageState.Version}}\t{{.ImageState.DownloadState}}\t{{.ImageState.Reason}}\t{{.ImageState.ImageState}}\t" |
| kesavand | 8ec4fc0 | 2021-01-27 09:10:22 -0500 | [diff] [blame] | 55 | DEFAULT_DEVICE_GET_PORT_STATUS_FORMAT = ` |
| 56 | TXBYTES: {{.TxBytes}} |
| 57 | TXPACKETS: {{.TxPackets}} |
| 58 | TXERRPACKETS: {{.TxErrorPackets}} |
| 59 | TXBCASTPACKETS: {{.TxBcastPackets}} |
| 60 | TXUCASTPACKETS: {{.TxUcastPackets}} |
| 61 | TXMCASTPACKETS: {{.TxMcastPackets}} |
| 62 | RXBYTES: {{.RxBytes}} |
| 63 | RXPACKETS: {{.RxPackets}} |
| 64 | RXERRPACKETS: {{.RxErrorPackets}} |
| 65 | RXBCASTPACKETS: {{.RxBcastPackets}} |
| 66 | RXUCASTPACKETS: {{.RxUcastPackets}} |
| 67 | RXMCASTPACKETS: {{.RxMcastPackets}}` |
| kesavand | 6d1131f | 2021-02-05 22:38:15 +0530 | [diff] [blame] | 68 | DEFAULT_DEVICE_GET_UNI_STATUS_FORMAT = ` |
| 69 | ADMIN_STATE: {{.AdmState}} |
| 70 | OPERATIONAL_STATE: {{.OperState}} |
| 71 | CONFIG_IND: {{.ConfigInd}}` |
| Girish Gowdra | 4f5ce7c | 2021-04-29 18:53:21 -0700 | [diff] [blame] | 72 | DEFAULT_ONU_PON_OPTICAL_INFO_STATUS_FORMAT = ` |
| 73 | POWER_FEED_VOLTAGE__VOLTS: {{.PowerFeedVoltage}} |
| 74 | RECEIVED_OPTICAL_POWER__dBm: {{.ReceivedOpticalPower}} |
| 75 | MEAN_OPTICAL_LAUNCH_POWER__dBm: {{.MeanOpticalLaunchPower}} |
| 76 | LASER_BIAS_CURRENT__mA: {{.LaserBiasCurrent}} |
| 77 | TEMPERATURE__Celsius: {{.Temperature}}` |
| Gamze Abaka | c857a46 | 2021-05-26 13:45:54 +0000 | [diff] [blame] | 78 | DEFAULT_RX_POWER_STATUS_FORMAT = ` |
| 79 | INTF_ID: {{.IntfId}} |
| 80 | ONU_ID: {{.OnuId}} |
| 81 | STATUS: {{.Status}} |
| 82 | FAIL_REASON: {{.FailReason}} |
| 83 | RX_POWER : {{.RxPower}}` |
| Himani Chawla | 553a139 | 2021-06-10 23:39:17 +0530 | [diff] [blame] | 84 | DEFAULT_ETHERNET_FRAME_EXTENDED_PM_COUNTERS_FORMAT = `Upstream_Drop_Events: {{.UDropEvents}} |
| 85 | Upstream_Octets: {{.UOctets}} |
| 86 | UFrames: {{.UFrames}} |
| 87 | UBroadcastFrames: {{.UBroadcastFrames}} |
| 88 | UMulticastFrames: {{.UMulticastFrames}} |
| 89 | UCrcErroredFrames: {{.UCrcErroredFrames}} |
| 90 | UUndersizeFrames: {{.UUndersizeFrames}} |
| 91 | UOversizeFrames: {{.UOversizeFrames}} |
| 92 | UFrames_64Octets: {{.UFrames_64Octets}} |
| 93 | UFrames_65To_127Octets: {{.UFrames_65To_127Octets}} |
| 94 | UFrames_128To_255Octets: {{.UFrames_128To_255Octets}} |
| 95 | UFrames_256To_511Octets: {{.UFrames_256To_511Octets}} |
| 96 | UFrames_512To_1023Octets: {{.UFrames_512To_1023Octets}} |
| 97 | UFrames_1024To_1518Octets: {{.UFrames_1024To_1518Octets}} |
| 98 | DDropEvents: {{.DDropEvents}} |
| 99 | DOctets: {{.DOctets}} |
| 100 | DFrames: {{.DFrames}} |
| 101 | DBroadcastFrames: {{.DBroadcastFrames}} |
| 102 | DMulticastFrames: {{.DMulticastFrames}} |
| 103 | DCrcErroredFrames: {{.DCrcErroredFrames}} |
| 104 | DUndersizeFrames: {{.DUndersizeFrames}} |
| 105 | DOversizeFrames: {{.DOversizeFrames}} |
| 106 | DFrames_64Octets: {{.DFrames_64Octets}} |
| 107 | DFrames_65To_127Octets: {{.DFrames_65To_127Octets}} |
| 108 | DFrames_128To_255Octets: {{.DFrames_128To_255Octets}} |
| 109 | DFrames_256To_511Octets: {{.DFrames_256To_511Octets}} |
| 110 | DFrames_512To_1023Octets: {{.DFrames_512To_1023Octets}} |
| Himani Chawla | bac0f89 | 2021-08-25 17:14:06 +0530 | [diff] [blame] | 111 | DFrames_1024To_1518Octets: {{.DFrames_1024To_1518Octets}} |
| 112 | PmFormat: {{.PmFormat}}` |
| Akash Reddy Kankanala | c001463 | 2025-05-21 17:12:20 +0530 | [diff] [blame] | 113 | DEFAULT_PON_PORT_STATS_FORMAT = `Pon Port: {{.PonPort}} |
| 114 | Bip Units: {{.BipUnits}} |
| 115 | Bip Errors: {{.BipErrors}} |
| 116 | RxPackets: {{.RxPackets}} |
| 117 | RxGem: {{.RxGem}} |
| 118 | RxGemDropped: {{.RxGemDropped}} |
| 119 | RxGemIdle: {{.RxGemIdle}} |
| 120 | RxGemCorrected: {{.RxGemCorrected}} |
| 121 | RxGemIllegal: {{.RxGemIllegal}} |
| 122 | RxCrcError: {{.RxCrcErrors}} |
| 123 | RxFragmentError: {{.RxFragmentError}} |
| 124 | RxPacketsDropped: {{.RxPacketsDropped}} |
| 125 | RxCpuOmciPacketsDropped: {{.RxCpuOmciPacketsDropped}} |
| 126 | RxCpu: {{.RxCpu}} |
| 127 | RxOmci: {{.RxOmci}} |
| 128 | RxOmciPacketsCrcError: {{.RxOmciPacketsCrcError}} |
| 129 | TxPackets: {{.TxPackets}} |
| 130 | TxGem: {{.TxGem}} |
| 131 | TxCpu: {{.TxCpu}} |
| 132 | TxOmci: {{.TxOmci}} |
| 133 | TxDroppedIllegalLength: {{.TxDroppedIllegalLength}} |
| 134 | TxDroppedTpidMiss: {{.TxDroppedTpidMiss}} |
| 135 | TxDroppedVidMiss: {{.TxDroppedVidMiss}} |
| 136 | TxDroppedTotal: {{.TxDroppedTotal}}` |
| 137 | DEFAULT_NNI_PORT_STATS_FORMAT = `Nni Port: {{.NniPort}} |
| 138 | RxBytes: {{.RxBytes}} |
| 139 | RxPackets: {{.RxPackets}} |
| 140 | RxUcastPackets: {{.RxUcastPackets}} |
| 141 | RxMcastPackets: {{.RxMcastPackets}} |
| 142 | RxBcastPackets: {{.RxBcastPackets}} |
| 143 | RxErrorPackets: {{.RxErrorPackets}} |
| 144 | RxFcsErrorPackets: {{.RxFcsErrorPackets}} |
| 145 | RxUndersizePackets: {{.RxUndersizePackets}} |
| 146 | RxOversizePackets: {{.RxOversizePackets}} |
| 147 | TxBytes: {{.TxBytes}} |
| 148 | TxPackets: {{.TxPackets}} |
| 149 | TxUcastPackets: {{.TxUcastPackets}} |
| 150 | TxMcastPackets: {{.TxMcastPackets}} |
| 151 | TxBcastPackets: {{.TxBcastPackets}} |
| 152 | TxErrorPackets: {{.TxErrorPackets}} |
| 153 | TxUndersizePackets: {{.TxUndersizePackets}} |
| 154 | TxOversizePackets: {{.TxOversizePackets}}` |
| 155 | |
| serkantul | 3d22fc7 | 2022-09-14 12:22:56 +0300 | [diff] [blame] | 156 | DEFAULT_ONU_OMCI_TX_RX_STATS_FORMAT = `BaseTxArFrames: {{.BaseTxArFrames}} |
| 157 | BaseRxAkFrames: {{.BaseRxAkFrames}} |
| 158 | BaseTxNoArFrames: {{.BaseTxNoArFrames}} |
| 159 | BaseRxNoAkFrames: {{.BaseRxNoAkFrames}} |
| 160 | ExtTxArFrames: {{.ExtTxArFrames}} |
| 161 | ExtRxAkFrames: {{.ExtRxAkFrames}} |
| 162 | ExtTxNoArFrames: {{.ExtTxNoArFrames}} |
| 163 | ExtRxNoAkFrames: {{.ExtRxNoAkFrames}} |
| 164 | TxOmciCounterRetries: {{.TxOmciCounterRetries}} |
| 165 | TxOmciCounterTimeouts: {{.TxOmciCounterTimeouts}}` |
| Akash Reddy Kankanala | c001463 | 2025-05-21 17:12:20 +0530 | [diff] [blame] | 166 | DEFAULT_ONU_STATS_FROM_OLT_FORMAT = `AllocId: {{.AllocId}} |
| 167 | AllocRxBytes: {{.AllocRxBytes}} |
| 168 | {{range .GemPortStats}} |
| 169 | -GemId: {{.GemId}} |
| 170 | RxPackets: {{.RxPackets}} |
| 171 | RxBytes: {{.RxBytes}} |
| 172 | TxPackets: {{.TxPackets}} |
| 173 | TxBytes: {{.TxBytes}}{{end}}` |
| Akash Reddy Kankanala | 6965c65 | 2025-10-15 23:30:16 +0530 | [diff] [blame^] | 174 | DEFAULT_ONU_FEC_HISTORY_FORMAT = `CorrectedBytes: {{.CorrectedBytes}} |
| 175 | CorrectedCodeWords: {{.CorrectedCodeWords}} |
| 176 | FecSeconds: {{.FecSeconds}} |
| 177 | TotalCodeWords: {{.TotalCodeWords}} |
| 178 | UncorrectableCodeWords: {{.UncorrectableCodeWords}}` |
| Akash Reddy Kankanala | c001463 | 2025-05-21 17:12:20 +0530 | [diff] [blame] | 179 | |
| 180 | DEFAULT_ONU_DISTANCE_FORMAT = `Distance` |
| 181 | DEFAULT_DEVICE_ALARMS_FORMAT = "table{{ .ClassId }}\t{{.InstanceId}}\t{{.Name}}\t{{.Description}}" |
| 182 | DEFAULT_DEVICE_ALARMS_ORDER = "ClassId,InstanceId" |
| 183 | DEFAULT_PON_RX_POWER_STATUS_FORMAT = "table{{.OnuSn}}\t{{.Status}}\t{{.FailReason}}\t{{.RxPower}}\t" |
| 184 | DEFAULT_DEVICE_VALUE_GEM_PORT_FORMAT = `AllocId: {{.AllocId}} |
| 185 | AllocRxBytes: {{.AllocRxBytes}} |
| 186 | {{range .GemHistoryStats}} |
| 187 | -GemId: {{.GemId}} |
| 188 | TransmittedGEMFrames: {{.TransmittedGEMFrames}} |
| 189 | ReceivedGEMFrames: {{.ReceivedGEMFrames}} |
| 190 | ReceivedPayloadBytes: {{.ReceivedPayloadBytes}} |
| 191 | TransmittedPayloadBytes:{{.TransmittedPayloadBytes}} |
| 192 | EncryptionKeyErrors: {{.EncryptionKeyErrors}}{{end}}` |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 193 | ) |
| 194 | |
| 195 | type DeviceList struct { |
| 196 | ListOutputOptions |
| 197 | } |
| 198 | |
| 199 | type DeviceCreate struct { |
| David Bainbridge | 1a51439 | 2020-06-23 11:12:51 -0700 | [diff] [blame] | 200 | DeviceType string `short:"t" required:"true" long:"devicetype" description:"Device type"` |
| David Bainbridge | 835dd0e | 2020-04-01 10:30:09 -0700 | [diff] [blame] | 201 | MACAddress string `short:"m" long:"macaddress" default:"" description:"MAC Address"` |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 202 | IPAddress string `short:"i" long:"ipaddress" default:"" description:"IP Address"` |
| 203 | HostAndPort string `short:"H" long:"hostandport" default:"" description:"Host and port"` |
| 204 | } |
| 205 | |
| 206 | type DeviceId string |
| Akash Soni | 66db963 | 2024-04-15 09:05:15 +0530 | [diff] [blame] | 207 | type OnuId string |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 208 | |
| Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 209 | type MetricName string |
| 210 | type GroupName string |
| kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 211 | type PortNum uint32 |
| Dinesh Belwalkar | c9aa6d8 | 2020-03-04 15:22:17 -0800 | [diff] [blame] | 212 | type ValueFlag string |
| kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 213 | |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 214 | type DeviceDelete struct { |
| Himani Chawla | 9933ddc | 2020-10-12 23:53:27 +0530 | [diff] [blame] | 215 | Force bool `long:"force" description:"Delete device forcefully"` |
| 216 | Args struct { |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 217 | Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 218 | } `positional-args:"yes"` |
| 219 | } |
| 220 | |
| 221 | type DeviceEnable struct { |
| 222 | Args struct { |
| 223 | Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 224 | } `positional-args:"yes"` |
| 225 | } |
| 226 | |
| 227 | type DeviceDisable struct { |
| 228 | Args struct { |
| 229 | Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 230 | } `positional-args:"yes"` |
| 231 | } |
| 232 | |
| 233 | type DeviceReboot struct { |
| 234 | Args struct { |
| 235 | Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 236 | } `positional-args:"yes"` |
| 237 | } |
| 238 | |
| 239 | type DeviceFlowList struct { |
| 240 | ListOutputOptions |
| Maninder | 045921e | 2020-09-29 16:46:02 +0530 | [diff] [blame] | 241 | FlowIdOptions |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 242 | Args struct { |
| 243 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 244 | } `positional-args:"yes"` |
| 245 | } |
| 246 | |
| Himani Chawla | 3c161c6 | 2021-05-13 16:36:51 +0530 | [diff] [blame] | 247 | type DeviceFlowGroupList struct { |
| 248 | ListOutputOptions |
| 249 | GroupListOptions |
| 250 | Args struct { |
| 251 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 252 | } `positional-args:"yes"` |
| 253 | } |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 254 | type DevicePortList struct { |
| 255 | ListOutputOptions |
| 256 | Args struct { |
| 257 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 258 | } `positional-args:"yes"` |
| 259 | } |
| 260 | |
| 261 | type DeviceInspect struct { |
| 262 | OutputOptionsJson |
| 263 | Args struct { |
| 264 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 265 | } `positional-args:"yes"` |
| 266 | } |
| 267 | |
| kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 268 | type DevicePortEnable struct { |
| 269 | Args struct { |
| 270 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 271 | PortId PortNum `positional-arg-name:"PORT_NUMBER" required:"yes"` |
| 272 | } `positional-args:"yes"` |
| 273 | } |
| 274 | |
| 275 | type DevicePortDisable struct { |
| 276 | Args struct { |
| 277 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 278 | PortId PortNum `positional-arg-name:"PORT_NUMBER" required:"yes"` |
| 279 | } `positional-args:"yes"` |
| 280 | } |
| 281 | |
| Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 282 | type DevicePmConfigsGet struct { |
| 283 | ListOutputOptions |
| 284 | Args struct { |
| 285 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 286 | } `positional-args:"yes"` |
| 287 | } |
| 288 | |
| 289 | type DevicePmConfigMetricList struct { |
| 290 | ListOutputOptions |
| 291 | Args struct { |
| 292 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 293 | } `positional-args:"yes"` |
| 294 | } |
| 295 | |
| 296 | type DevicePmConfigGroupList struct { |
| 297 | ListOutputOptions |
| 298 | Args struct { |
| 299 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 300 | } `positional-args:"yes"` |
| 301 | } |
| 302 | |
| 303 | type DevicePmConfigGroupMetricList struct { |
| 304 | ListOutputOptions |
| 305 | Args struct { |
| 306 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 307 | Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"` |
| 308 | } `positional-args:"yes"` |
| 309 | } |
| 310 | |
| 311 | type DevicePmConfigFrequencySet struct { |
| 312 | OutputOptions |
| 313 | Args struct { |
| Girish Gowdra | 610acb4 | 2021-01-27 13:33:57 -0800 | [diff] [blame] | 314 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 315 | Interval time.Duration `positional-arg-name:"INTERVAL" required:"yes"` |
| Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 316 | } `positional-args:"yes"` |
| 317 | } |
| 318 | |
| 319 | type DevicePmConfigMetricEnable struct { |
| 320 | Args struct { |
| 321 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 322 | Metrics []MetricName `positional-arg-name:"METRIC_NAME" required:"yes"` |
| 323 | } `positional-args:"yes"` |
| 324 | } |
| 325 | |
| 326 | type DevicePmConfigMetricDisable struct { |
| 327 | Args struct { |
| 328 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 329 | Metrics []MetricName `positional-arg-name:"METRIC_NAME" required:"yes"` |
| 330 | } `positional-args:"yes"` |
| 331 | } |
| 332 | |
| 333 | type DevicePmConfigGroupEnable struct { |
| 334 | Args struct { |
| Girish Gowdra | 610acb4 | 2021-01-27 13:33:57 -0800 | [diff] [blame] | 335 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 336 | Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"` |
| Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 337 | } `positional-args:"yes"` |
| 338 | } |
| 339 | |
| 340 | type DevicePmConfigGroupDisable struct { |
| 341 | Args struct { |
| Girish Gowdra | 610acb4 | 2021-01-27 13:33:57 -0800 | [diff] [blame] | 342 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 343 | Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"` |
| 344 | } `positional-args:"yes"` |
| 345 | } |
| 346 | |
| 347 | type DevicePmConfigGroupFrequencySet struct { |
| 348 | OutputOptions |
| 349 | Args struct { |
| 350 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 351 | Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"` |
| 352 | Interval time.Duration `positional-arg-name:"INTERVAL" required:"yes"` |
| Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 353 | } `positional-args:"yes"` |
| 354 | } |
| 355 | |
| Dinesh Belwalkar | c9aa6d8 | 2020-03-04 15:22:17 -0800 | [diff] [blame] | 356 | type DeviceGetExtValue struct { |
| 357 | ListOutputOptions |
| 358 | Args struct { |
| 359 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 360 | Valueflag ValueFlag `positional-arg-name:"VALUE_FLAG" required:"yes"` |
| 361 | } `positional-args:"yes"` |
| 362 | } |
| Rohan Agrawal | d7df377 | 2020-06-29 11:23:36 +0000 | [diff] [blame] | 363 | |
| 364 | type DevicePmConfigSetMaxSkew struct { |
| 365 | Args struct { |
| 366 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 367 | MaxSkew uint32 `positional-arg-name:"MAX_SKEW" required:"yes"` |
| 368 | } `positional-args:"yes"` |
| 369 | } |
| 370 | |
| Andrea Campanella | 791d88b | 2021-01-08 13:29:00 +0100 | [diff] [blame] | 371 | type DeviceOnuListImages struct { |
| 372 | ListOutputOptions |
| 373 | Args struct { |
| 374 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 375 | } `positional-args:"yes"` |
| 376 | } |
| 377 | |
| 378 | type DeviceOnuDownloadImage struct { |
| 379 | Args struct { |
| 380 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 381 | Name string `positional-arg-name:"IMAGE_NAME" required:"yes"` |
| 382 | Url string `positional-arg-name:"IMAGE_URL" required:"yes"` |
| 383 | ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"` |
| 384 | Crc uint32 `positional-arg-name:"IMAGE_CRC" required:"yes"` |
| 385 | LocalDir string `positional-arg-name:"IMAGE_LOCAL_DIRECTORY"` |
| 386 | } `positional-args:"yes"` |
| 387 | } |
| 388 | |
| 389 | type DeviceOnuActivateImageUpdate struct { |
| 390 | Args struct { |
| 391 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 392 | Name string `positional-arg-name:"IMAGE_NAME" required:"yes"` |
| 393 | ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"` |
| 394 | SaveConfig bool `positional-arg-name:"SAVE_EXISTING_CONFIG"` |
| 395 | LocalDir string `positional-arg-name:"IMAGE_LOCAL_DIRECTORY"` |
| Andrea Campanella | 7b2ecf4 | 2021-02-25 12:27:15 +0100 | [diff] [blame] | 396 | } `positional-args:"yes"` |
| kesavand | 8ec4fc0 | 2021-01-27 09:10:22 -0500 | [diff] [blame] | 397 | } |
| kesavand | 3e2f9f6 | 2021-04-22 11:06:38 +0530 | [diff] [blame] | 398 | |
| 399 | type OnuDownloadImage struct { |
| Andrea Campanella | eaf1e0c | 2021-06-07 14:41:34 +0200 | [diff] [blame] | 400 | ListOutputOptions |
| kesavand | 3e2f9f6 | 2021-04-22 11:06:38 +0530 | [diff] [blame] | 401 | Args struct { |
| 402 | ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"` |
| 403 | Url string `positional-arg-name:"IMAGE_URL" required:"yes"` |
| ssiddiqui | 7bc89e9 | 2021-05-20 20:58:02 +0530 | [diff] [blame] | 404 | Vendor string `positional-arg-name:"IMAGE_VENDOR"` |
| kesavand | 3e2f9f6 | 2021-04-22 11:06:38 +0530 | [diff] [blame] | 405 | ActivateOnSuccess bool `positional-arg-name:"IMAGE_ACTIVATE_ON_SUCCESS"` |
| 406 | CommitOnSuccess bool `positional-arg-name:"IMAGE_COMMIT_ON_SUCCESS"` |
| 407 | Crc uint32 `positional-arg-name:"IMAGE_CRC"` |
| 408 | IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 409 | } `positional-args:"yes"` |
| 410 | } |
| 411 | |
| 412 | type OnuActivateImage struct { |
| Andrea Campanella | eaf1e0c | 2021-06-07 14:41:34 +0200 | [diff] [blame] | 413 | ListOutputOptions |
| kesavand | 3e2f9f6 | 2021-04-22 11:06:38 +0530 | [diff] [blame] | 414 | Args struct { |
| 415 | ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"` |
| 416 | CommitOnSuccess bool `positional-arg-name:"IMAGE_COMMIT_ON_SUCCESS"` |
| 417 | IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 418 | } `positional-args:"yes"` |
| 419 | } |
| 420 | |
| 421 | type OnuAbortUpgradeImage struct { |
| Andrea Campanella | eaf1e0c | 2021-06-07 14:41:34 +0200 | [diff] [blame] | 422 | ListOutputOptions |
| kesavand | 3e2f9f6 | 2021-04-22 11:06:38 +0530 | [diff] [blame] | 423 | Args struct { |
| 424 | ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"` |
| 425 | IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 426 | } `positional-args:"yes"` |
| 427 | } |
| 428 | |
| 429 | type OnuCommitImage struct { |
| Andrea Campanella | eaf1e0c | 2021-06-07 14:41:34 +0200 | [diff] [blame] | 430 | ListOutputOptions |
| kesavand | 3e2f9f6 | 2021-04-22 11:06:38 +0530 | [diff] [blame] | 431 | Args struct { |
| 432 | ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"` |
| 433 | IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 434 | } `positional-args:"yes"` |
| 435 | } |
| 436 | |
| 437 | type OnuImageStatus struct { |
| 438 | ListOutputOptions |
| 439 | Args struct { |
| 440 | ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"` |
| Elia Battiston | 859f3e6 | 2022-02-08 15:57:52 +0100 | [diff] [blame] | 441 | IDs []DeviceId `positional-arg-name:"DEVICE_ID"` |
| kesavand | 3e2f9f6 | 2021-04-22 11:06:38 +0530 | [diff] [blame] | 442 | } `positional-args:"yes"` |
| 443 | } |
| 444 | |
| 445 | type OnuListImages struct { |
| 446 | ListOutputOptions |
| 447 | Args struct { |
| 448 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 449 | } `positional-args:"yes"` |
| 450 | } |
| 451 | |
| kesavand | 8ec4fc0 | 2021-01-27 09:10:22 -0500 | [diff] [blame] | 452 | type DeviceGetPortStats struct { |
| 453 | ListOutputOptions |
| 454 | Args struct { |
| 455 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 456 | PortNo uint32 `positional-arg-name:"PORT_NO" required:"yes"` |
| 457 | PortType string `positional-arg-name:"PORT_TYPE" required:"yes"` |
| Andrea Campanella | 791d88b | 2021-01-08 13:29:00 +0100 | [diff] [blame] | 458 | } `positional-args:"yes"` |
| 459 | } |
| kesavand | 6d1131f | 2021-02-05 22:38:15 +0530 | [diff] [blame] | 460 | type UniStatus struct { |
| 461 | ListOutputOptions |
| 462 | Args struct { |
| 463 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 464 | UniIndex uint32 `positional-arg-name:"UNI_INDEX" required:"yes"` |
| 465 | } `positional-args:"yes"` |
| 466 | } |
| Girish Gowdra | 4f5ce7c | 2021-04-29 18:53:21 -0700 | [diff] [blame] | 467 | type OnuPonOpticalInfo struct { |
| 468 | ListOutputOptions |
| 469 | Args struct { |
| 470 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 471 | } `positional-args:"yes"` |
| 472 | } |
| Himani Chawla | 40acc12 | 2021-05-26 18:52:29 +0530 | [diff] [blame] | 473 | |
| 474 | type GetOnuStats struct { |
| 475 | ListOutputOptions |
| 476 | Args struct { |
| 477 | OltId DeviceId `positional-arg-name:"OLT_DEVICE_ID" required:"yes"` |
| 478 | IntfId uint32 `positional-arg-name:"PON_INTF_ID" required:"yes"` |
| 479 | OnuId uint32 `positional-arg-name:"ONU_ID" required:"yes"` |
| 480 | } `positional-args:"yes"` |
| 481 | } |
| 482 | |
| Akash Soni | 6e879c2 | 2024-12-20 17:01:34 +0530 | [diff] [blame] | 483 | type GetOffloadApp struct { |
| Akash Soni | 51b6b7a | 2024-11-20 11:39:38 +0530 | [diff] [blame] | 484 | ListOutputOptions |
| 485 | Args struct { |
| 486 | OltId DeviceId `positional-arg-name:"OLT_DEVICE_ID" required:"yes"` |
| 487 | StatsFor extension.GetOffloadedAppsStatisticsRequest_OffloadedApp `positional-arg-name:"OFFLOADED_APP" required:"yes"` |
| 488 | } `positional-args:"yes"` |
| 489 | } |
| 490 | |
| Akash Soni | 6e879c2 | 2024-12-20 17:01:34 +0530 | [diff] [blame] | 491 | type SetOffloadApp struct { |
| 492 | ListOutputOptions |
| Akash Soni | 51b6b7a | 2024-11-20 11:39:38 +0530 | [diff] [blame] | 493 | Args struct { |
| Akash Soni | 6e879c2 | 2024-12-20 17:01:34 +0530 | [diff] [blame] | 494 | OltId DeviceId `positional-arg-name:"OLT_DEVICE_ID" required:"yes"` |
| 495 | Config string `positional-arg-name:"CONFIG" required:"yes"` // Accept JSON or CSV input |
| Akash Soni | 51b6b7a | 2024-11-20 11:39:38 +0530 | [diff] [blame] | 496 | } `positional-args:"yes"` |
| 497 | } |
| 498 | |
| Akash Soni | 6e879c2 | 2024-12-20 17:01:34 +0530 | [diff] [blame] | 499 | type AppOffloadOnuConfig struct { |
| 500 | AgentRemoteID string |
| 501 | AgentCircuitID string |
| 502 | OnuUniId uint32 |
| 503 | } |
| 504 | |
| 505 | type SetOnuOffload struct { |
| 506 | ListOutputOptions |
| Akash Soni | 51b6b7a | 2024-11-20 11:39:38 +0530 | [diff] [blame] | 507 | Args struct { |
| Akash Soni | 6e879c2 | 2024-12-20 17:01:34 +0530 | [diff] [blame] | 508 | OltId DeviceId `positional-arg-name:"OLT_DEVICE_ID" required:"yes"` |
| 509 | OnuDeviceId string `positional-arg-name:"ONU_DEVICE_ID" required:"yes"` |
| 510 | PerUniInfo string `positional-arg-name:"PER_UNI_INFO" json:"per_uni_info" required:"yes"` // Accept list as JSON or CSV |
| Akash Soni | 51b6b7a | 2024-11-20 11:39:38 +0530 | [diff] [blame] | 511 | } `positional-args:"yes"` |
| 512 | } |
| 513 | |
| Himani Chawla | 553a139 | 2021-06-10 23:39:17 +0530 | [diff] [blame] | 514 | type GetOnuEthernetFrameExtendedPmCounters struct { |
| 515 | ListOutputOptions |
| Himani Chawla | 806aa89 | 2021-08-30 15:51:46 +0530 | [diff] [blame] | 516 | Reset bool `long:"reset" description:"Reset the counters"` |
| 517 | Args struct { |
| 518 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 519 | UniIndex *uint32 `positional-arg-name:"UNI_INDEX"` |
| Himani Chawla | 553a139 | 2021-06-10 23:39:17 +0530 | [diff] [blame] | 520 | } `positional-args:"yes"` |
| 521 | } |
| 522 | |
| Akash Reddy Kankanala | c001463 | 2025-05-21 17:12:20 +0530 | [diff] [blame] | 523 | type GetPonPortStats struct { |
| 524 | ListOutputOptions |
| 525 | Reset bool `long:"reset" description:"Reset the counters"` |
| 526 | Args struct { |
| 527 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 528 | PortLabel string `positional-arg-name:"PORT_LABEL" required:"yes"` |
| 529 | } `positional-args:"yes"` |
| 530 | } |
| 531 | |
| 532 | type GetNniPortStats struct { |
| 533 | ListOutputOptions |
| 534 | Reset bool `long:"reset" description:"Reset the counters"` |
| 535 | Args struct { |
| 536 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 537 | PortLabel string `positional-arg-name:"PORT_LABEL" required:"yes"` |
| 538 | } `positional-args:"yes"` |
| 539 | } |
| 540 | |
| 541 | type GetOnuAllocGemStatsFromOlt struct { |
| 542 | ListOutputOptions |
| 543 | Args struct { |
| 544 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 545 | } `positional-args:"yes"` |
| 546 | } |
| Gamze Abaka | c857a46 | 2021-05-26 13:45:54 +0000 | [diff] [blame] | 547 | type RxPower struct { |
| 548 | ListOutputOptions |
| 549 | Args struct { |
| 550 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 551 | PortNo uint32 `positional-arg-name:"PORT_NO" required:"yes"` |
| 552 | OnuNo uint32 `positional-arg-name:"ONU_NO" required:"yes"` |
| 553 | } `positional-args:"yes"` |
| 554 | } |
| 555 | |
| praneeth nalmas | 39c71ad | 2023-09-27 18:29:04 +0530 | [diff] [blame] | 556 | type PonRxPower struct { |
| 557 | ListOutputOptions |
| 558 | Args struct { |
| 559 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 560 | PortLabel string `positional-arg-name:"PORT_LABEL" required:"yes"` |
| 561 | SerialNo string `positional-arg-name:"ONU_SERIAL_NUMBER"` |
| 562 | } `positional-args:"yes"` |
| 563 | } |
| 564 | |
| serkantul | 3d22fc7 | 2022-09-14 12:22:56 +0300 | [diff] [blame] | 565 | type OnuOmciTxRxStats struct { |
| 566 | ListOutputOptions |
| 567 | Args struct { |
| 568 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 569 | } `positional-args:"yes"` |
| 570 | } |
| 571 | |
| praneeth nalmas | 1dd094c | 2022-12-22 14:15:13 +0530 | [diff] [blame] | 572 | type GetOnuOmciActiveAlarms struct { |
| 573 | ListOutputOptions |
| 574 | Args struct { |
| 575 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 576 | } `positional-args:"yes"` |
| 577 | } |
| 578 | |
| Akash Reddy Kankanala | c001463 | 2025-05-21 17:12:20 +0530 | [diff] [blame] | 579 | type GetOnuGEMStats struct { |
| 580 | ListOutputOptions |
| 581 | Args struct { |
| 582 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 583 | } `positional-args:"yes"` |
| 584 | } |
| 585 | |
| Akash Reddy Kankanala | 6965c65 | 2025-10-15 23:30:16 +0530 | [diff] [blame^] | 586 | type GetOnuFecHistory struct { |
| 587 | ListOutputOptions |
| 588 | Args struct { |
| 589 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 590 | } `positional-args:"yes"` |
| 591 | } |
| Akash Soni | 66db963 | 2024-04-15 09:05:15 +0530 | [diff] [blame] | 592 | type GetOnuDistance struct { |
| 593 | ListOutputOptions |
| 594 | Args struct { |
| 595 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 596 | OnuId OnuId `positional-arg-name:"ONU_ID" required:"yes"` |
| 597 | } `positional-args:"yes"` //onu device id |
| 598 | } |
| 599 | |
| mgouda | 35b90e6 | 2025-07-16 14:58:29 +0530 | [diff] [blame] | 600 | type DisableOnuDevice struct { |
| 601 | Args struct { |
| 602 | Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 603 | } `positional-args:"yes"` |
| 604 | } |
| 605 | |
| 606 | type EnableOnuDevice struct { |
| 607 | Args struct { |
| 608 | Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 609 | } `positional-args:"yes"` |
| 610 | } |
| 611 | |
| 612 | type DisableOnuSerialNumber struct { |
| 613 | Args struct { |
| 614 | SerialNumber string `positional-arg-name:"ONU_SERIAL_NUMBER" required:"yes"` |
| 615 | Port PortNum `positional-arg-name:"PORT_NO" required:"yes"` |
| 616 | OltDeviceId DeviceId `positional-arg-name:"OLT_DEVICE_ID" required:"yes"` |
| 617 | } `positional-args:"yes"` |
| 618 | } |
| 619 | |
| 620 | type EnableOnuSerialNumber struct { |
| 621 | Args struct { |
| 622 | SerialNumber string `positional-arg-name:"ONU_SERIAL_NUMBER" required:"yes"` |
| 623 | Port PortNum `positional-arg-name:"PORT_NO" required:"yes"` |
| 624 | OltDeviceId DeviceId `positional-arg-name:"OLT_DEVICE_ID" required:"yes"` |
| 625 | } `positional-args:"yes"` |
| 626 | } |
| 627 | |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 628 | type DeviceOpts struct { |
| mgouda | 35b90e6 | 2025-07-16 14:58:29 +0530 | [diff] [blame] | 629 | List DeviceList `command:"list"` |
| 630 | Create DeviceCreate `command:"create"` |
| 631 | Delete DeviceDelete `command:"delete"` |
| 632 | Enable DeviceEnable `command:"enable"` |
| 633 | Disable DeviceDisable `command:"disable"` |
| 634 | DisableOnuDevice DisableOnuDevice `command:"disable_onu"` |
| 635 | EnableOnuDevice EnableOnuDevice `command:"enable_onu"` |
| 636 | DisableOnuSerialNumber DisableOnuSerialNumber `command:"disable_onu_serial"` |
| 637 | EnableOnuSerialNumber EnableOnuSerialNumber `command:"enable_onu_serial"` |
| 638 | Flows DeviceFlowList `command:"flows"` |
| 639 | Groups DeviceFlowGroupList `command:"groups"` |
| 640 | Port struct { |
| kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 641 | List DevicePortList `command:"list"` |
| 642 | Enable DevicePortEnable `command:"enable"` |
| 643 | Disable DevicePortDisable `command:"disable"` |
| 644 | } `command:"port"` |
| 645 | Inspect DeviceInspect `command:"inspect"` |
| 646 | Reboot DeviceReboot `command:"reboot"` |
| Dinesh Belwalkar | c9aa6d8 | 2020-03-04 15:22:17 -0800 | [diff] [blame] | 647 | Value struct { |
| 648 | Get DeviceGetExtValue `command:"get"` |
| 649 | } `command:"value"` |
| Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 650 | PmConfig struct { |
| Rohan Agrawal | d7df377 | 2020-06-29 11:23:36 +0000 | [diff] [blame] | 651 | Get DevicePmConfigsGet `command:"get"` |
| 652 | MaxSkew struct { |
| 653 | Set DevicePmConfigSetMaxSkew `command:"set"` |
| 654 | } `command:"maxskew"` |
| Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 655 | Frequency struct { |
| 656 | Set DevicePmConfigFrequencySet `command:"set"` |
| 657 | } `command:"frequency"` |
| 658 | Metric struct { |
| 659 | List DevicePmConfigMetricList `command:"list"` |
| 660 | Enable DevicePmConfigMetricEnable `command:"enable"` |
| 661 | Disable DevicePmConfigMetricDisable `command:"disable"` |
| 662 | } `command:"metric"` |
| 663 | Group struct { |
| Girish Gowdra | 610acb4 | 2021-01-27 13:33:57 -0800 | [diff] [blame] | 664 | List DevicePmConfigGroupList `command:"list"` |
| 665 | Enable DevicePmConfigGroupEnable `command:"enable"` |
| 666 | Disable DevicePmConfigGroupDisable `command:"disable"` |
| 667 | Set DevicePmConfigGroupFrequencySet `command:"set"` |
| Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 668 | } `command:"group"` |
| 669 | GroupMetric struct { |
| 670 | List DevicePmConfigGroupMetricList `command:"list"` |
| 671 | } `command:"groupmetric"` |
| 672 | } `command:"pmconfig"` |
| Andrea Campanella | 791d88b | 2021-01-08 13:29:00 +0100 | [diff] [blame] | 673 | Image struct { |
| 674 | Get DeviceOnuListImages `command:"list"` |
| 675 | Download DeviceOnuDownloadImage `command:"download"` |
| 676 | Activate DeviceOnuActivateImageUpdate `command:"activate"` |
| 677 | } `command:"image"` |
| kesavand | 3e2f9f6 | 2021-04-22 11:06:38 +0530 | [diff] [blame] | 678 | DownloadImage struct { |
| 679 | Download OnuDownloadImage `command:"download"` |
| 680 | Activate OnuActivateImage `command:"activate"` |
| 681 | Commit OnuCommitImage `command:"commit"` |
| 682 | AbortUpgrade OnuAbortUpgradeImage `command:"abort"` |
| 683 | Status OnuImageStatus `command:"status"` |
| 684 | List OnuListImages `command:"list" ` |
| 685 | } `command:"onuimage"` |
| kesavand | 8ec4fc0 | 2021-01-27 09:10:22 -0500 | [diff] [blame] | 686 | GetExtVal struct { |
| Himani Chawla | 553a139 | 2021-06-10 23:39:17 +0530 | [diff] [blame] | 687 | Stats DeviceGetPortStats `command:"portstats"` |
| 688 | UniStatus UniStatus `command:"unistatus"` |
| 689 | OpticalInfo OnuPonOpticalInfo `command:"onu_pon_optical_info"` |
| 690 | OnuStats GetOnuStats `command:"onu_stats"` |
| 691 | EthernetFrameExtendedPm GetOnuEthernetFrameExtendedPmCounters `command:"ethernet_frame_extended_pm"` |
| 692 | RxPower RxPower `command:"rxpower"` |
| serkantul | 3d22fc7 | 2022-09-14 12:22:56 +0300 | [diff] [blame] | 693 | OnuOmciStats OnuOmciTxRxStats `command:"onu_omci_stats"` |
| praneeth nalmas | 1dd094c | 2022-12-22 14:15:13 +0530 | [diff] [blame] | 694 | OnuOmciActiveAlarms GetOnuOmciActiveAlarms `command:"onu_omci_active_alarms"` |
| praneeth nalmas | 39c71ad | 2023-09-27 18:29:04 +0530 | [diff] [blame] | 695 | PonRxPower PonRxPower `command:"pon_rx_power"` |
| Akash Soni | 66db963 | 2024-04-15 09:05:15 +0530 | [diff] [blame] | 696 | OnuDistance GetOnuDistance `command:"onu_distance"` |
| Akash Soni | 6e879c2 | 2024-12-20 17:01:34 +0530 | [diff] [blame] | 697 | OffloadAppStats GetOffloadApp `command:"offload_app_stats"` |
| Akash Reddy Kankanala | c001463 | 2025-05-21 17:12:20 +0530 | [diff] [blame] | 698 | PonStats GetPonPortStats `command:"itu_pon_stats"` |
| 699 | NniStats GetNniPortStats `command:"nni_statistics"` |
| 700 | OnuGEMStats GetOnuGEMStats `command:"onu_gem_stats"` |
| 701 | OnuAllocGemStats GetOnuAllocGemStatsFromOlt `command:"onu_alloc_gem_from_olt"` |
| Akash Reddy Kankanala | 6965c65 | 2025-10-15 23:30:16 +0530 | [diff] [blame^] | 702 | OnuFecHistory GetOnuFecHistory `command:"onu_fec_history"` |
| kesavand | 8ec4fc0 | 2021-01-27 09:10:22 -0500 | [diff] [blame] | 703 | } `command:"getextval"` |
| Akash Soni | 51b6b7a | 2024-11-20 11:39:38 +0530 | [diff] [blame] | 704 | SetExtVal struct { |
| Akash Soni | 6e879c2 | 2024-12-20 17:01:34 +0530 | [diff] [blame] | 705 | OffloadAppStatsSet SetOffloadApp `command:"set_offload_app"` |
| 706 | OnuOffloadStatsSet SetOnuOffload `command:"set_onu_offload"` |
| Akash Soni | 51b6b7a | 2024-11-20 11:39:38 +0530 | [diff] [blame] | 707 | } `command:"setextval"` |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 708 | } |
| 709 | |
| Akash Reddy Kankanala | c001463 | 2025-05-21 17:12:20 +0530 | [diff] [blame] | 710 | type AllocGemStatsFromOlt struct { |
| 711 | AllocId uint32 |
| 712 | AllocRxBytes uint64 |
| 713 | GemPortStats []GemPortStatsFromOlt |
| 714 | } |
| 715 | type GemPortStatsFromOlt struct { |
| 716 | GemId uint32 |
| 717 | RxPackets uint64 |
| 718 | RxBytes uint64 |
| 719 | TxPackets uint64 |
| 720 | TxBytes uint64 |
| 721 | } |
| 722 | type onugemstats struct { |
| 723 | AllocId uint32 |
| 724 | AllocRxBytes uint32 |
| 725 | GemHistoryStats []gemHistoryStats |
| 726 | } |
| 727 | type gemHistoryStats struct { |
| 728 | GemId uint32 |
| 729 | TransmittedGEMFrames uint32 |
| 730 | ReceivedGEMFrames uint32 |
| 731 | ReceivedPayloadBytes uint32 |
| 732 | TransmittedPayloadBytes uint32 |
| 733 | EncryptionKeyErrors uint32 |
| 734 | } |
| 735 | |
| 736 | type PortStats struct { |
| 737 | PonPort uint32 // use this for PON |
| 738 | NniPort uint32 // use this for NNI |
| 739 | *common.PortStatistics |
| 740 | } |
| 741 | |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 742 | var deviceOpts = DeviceOpts{} |
| 743 | |
| 744 | func RegisterDeviceCommands(parser *flags.Parser) { |
| David Bainbridge | 12f036f | 2019-10-15 22:09:04 +0000 | [diff] [blame] | 745 | if _, err := parser.AddCommand("device", "device commands", "Commands to query and manipulate VOLTHA devices", &deviceOpts); err != nil { |
| David Bainbridge | a672234 | 2019-10-24 23:55:53 +0000 | [diff] [blame] | 746 | Error.Fatalf("Unexpected error while attempting to register device commands : %s", err) |
| David Bainbridge | 12f036f | 2019-10-15 22:09:04 +0000 | [diff] [blame] | 747 | } |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 748 | } |
| 749 | |
| Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 750 | func (i *MetricName) Complete(match string) []flags.Completion { |
| 751 | conn, err := NewConnection() |
| 752 | if err != nil { |
| 753 | return nil |
| 754 | } |
| 755 | defer conn.Close() |
| 756 | |
| 757 | client := voltha.NewVolthaServiceClient(conn) |
| 758 | |
| 759 | var deviceId string |
| 760 | found: |
| 761 | for i := len(os.Args) - 1; i >= 0; i -= 1 { |
| 762 | switch os.Args[i] { |
| 763 | case "enable": |
| 764 | fallthrough |
| 765 | case "disable": |
| 766 | if len(os.Args) > i+1 { |
| 767 | deviceId = os.Args[i+1] |
| 768 | } else { |
| 769 | return nil |
| 770 | } |
| 771 | break found |
| 772 | default: |
| 773 | } |
| 774 | } |
| 775 | |
| 776 | if len(deviceId) == 0 { |
| 777 | return nil |
| 778 | } |
| 779 | |
| David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 780 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 781 | defer cancel() |
| 782 | |
| 783 | id := voltha.ID{Id: string(deviceId)} |
| 784 | |
| 785 | pmconfigs, err := client.ListDevicePmConfigs(ctx, &id) |
| 786 | |
| 787 | if err != nil { |
| 788 | return nil |
| 789 | } |
| 790 | |
| 791 | list := make([]flags.Completion, 0) |
| 792 | for _, metrics := range pmconfigs.Metrics { |
| 793 | if strings.HasPrefix(metrics.Name, match) { |
| 794 | list = append(list, flags.Completion{Item: metrics.Name}) |
| 795 | } |
| 796 | } |
| 797 | |
| 798 | return list |
| 799 | } |
| 800 | |
| 801 | func (i *GroupName) Complete(match string) []flags.Completion { |
| 802 | conn, err := NewConnection() |
| 803 | if err != nil { |
| 804 | return nil |
| 805 | } |
| 806 | defer conn.Close() |
| 807 | |
| 808 | client := voltha.NewVolthaServiceClient(conn) |
| 809 | |
| 810 | var deviceId string |
| 811 | found: |
| 812 | for i := len(os.Args) - 1; i >= 0; i -= 1 { |
| 813 | switch os.Args[i] { |
| 814 | case "list": |
| 815 | fallthrough |
| 816 | case "enable": |
| 817 | fallthrough |
| 818 | case "disable": |
| 819 | if len(os.Args) > i+1 { |
| 820 | deviceId = os.Args[i+1] |
| 821 | } else { |
| 822 | return nil |
| 823 | } |
| 824 | break found |
| 825 | default: |
| 826 | } |
| 827 | } |
| 828 | |
| 829 | if len(deviceId) == 0 { |
| 830 | return nil |
| 831 | } |
| 832 | |
| David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 833 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 834 | defer cancel() |
| 835 | |
| 836 | id := voltha.ID{Id: string(deviceId)} |
| 837 | |
| 838 | pmconfigs, err := client.ListDevicePmConfigs(ctx, &id) |
| 839 | |
| 840 | if err != nil { |
| 841 | return nil |
| 842 | } |
| 843 | |
| 844 | list := make([]flags.Completion, 0) |
| 845 | for _, group := range pmconfigs.Groups { |
| 846 | if strings.HasPrefix(group.GroupName, match) { |
| 847 | list = append(list, flags.Completion{Item: group.GroupName}) |
| 848 | } |
| 849 | } |
| 850 | return list |
| 851 | } |
| 852 | |
| kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 853 | func (i *PortNum) Complete(match string) []flags.Completion { |
| 854 | conn, err := NewConnection() |
| 855 | if err != nil { |
| 856 | return nil |
| 857 | } |
| 858 | defer conn.Close() |
| 859 | |
| Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 860 | client := voltha.NewVolthaServiceClient(conn) |
| kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 861 | |
| 862 | /* |
| 863 | * The command line args when completing for PortNum will be a DeviceId |
| 864 | * followed by one or more PortNums. So walk the argument list from the |
| 865 | * end and find the first argument that is enable/disable as those are |
| 866 | * the subcommands that come before the positional arguments. It would |
| 867 | * be nice if this package gave us the list of optional arguments |
| 868 | * already parsed. |
| 869 | */ |
| 870 | var deviceId string |
| 871 | found: |
| 872 | for i := len(os.Args) - 1; i >= 0; i -= 1 { |
| 873 | switch os.Args[i] { |
| 874 | case "enable": |
| 875 | fallthrough |
| 876 | case "disable": |
| 877 | if len(os.Args) > i+1 { |
| 878 | deviceId = os.Args[i+1] |
| 879 | } else { |
| 880 | return nil |
| 881 | } |
| 882 | break found |
| 883 | default: |
| 884 | } |
| 885 | } |
| 886 | |
| 887 | if len(deviceId) == 0 { |
| 888 | return nil |
| 889 | } |
| 890 | |
| David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 891 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 892 | defer cancel() |
| kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 893 | |
| Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 894 | id := voltha.ID{Id: string(deviceId)} |
| kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 895 | |
| Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 896 | ports, err := client.ListDevicePorts(ctx, &id) |
| kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 897 | if err != nil { |
| 898 | return nil |
| 899 | } |
| 900 | |
| 901 | list := make([]flags.Completion, 0) |
| Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 902 | for _, item := range ports.Items { |
| 903 | pn := strconv.FormatUint(uint64(item.PortNo), 10) |
| kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 904 | if strings.HasPrefix(pn, match) { |
| 905 | list = append(list, flags.Completion{Item: pn}) |
| 906 | } |
| 907 | } |
| 908 | |
| 909 | return list |
| 910 | } |
| 911 | |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 912 | func (i *DeviceId) Complete(match string) []flags.Completion { |
| 913 | conn, err := NewConnection() |
| 914 | if err != nil { |
| 915 | return nil |
| 916 | } |
| 917 | defer conn.Close() |
| 918 | |
| Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 919 | client := voltha.NewVolthaServiceClient(conn) |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 920 | |
| David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 921 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 922 | defer cancel() |
| 923 | |
| Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 924 | devices, err := client.ListDevices(ctx, &empty.Empty{}) |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 925 | if err != nil { |
| 926 | return nil |
| 927 | } |
| 928 | |
| 929 | list := make([]flags.Completion, 0) |
| Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 930 | for _, item := range devices.Items { |
| 931 | if strings.HasPrefix(item.Id, match) { |
| 932 | list = append(list, flags.Completion{Item: item.Id}) |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 933 | } |
| 934 | } |
| 935 | |
| 936 | return list |
| 937 | } |
| 938 | |
| 939 | func (options *DeviceList) Execute(args []string) error { |
| 940 | |
| 941 | conn, err := NewConnection() |
| 942 | if err != nil { |
| 943 | return err |
| 944 | } |
| 945 | defer conn.Close() |
| 946 | |
| Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 947 | client := voltha.NewVolthaServiceClient(conn) |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 948 | |
| David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 949 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 950 | defer cancel() |
| 951 | |
| Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 952 | devices, err := client.ListDevices(ctx, &empty.Empty{}) |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 953 | if err != nil { |
| 954 | return err |
| 955 | } |
| 956 | |
| 957 | outputFormat := CharReplacer.Replace(options.Format) |
| 958 | if outputFormat == "" { |
| David Bainbridge | a672234 | 2019-10-24 23:55:53 +0000 | [diff] [blame] | 959 | outputFormat = GetCommandOptionWithDefault("device-list", "format", DEFAULT_DEVICE_FORMAT) |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 960 | } |
| 961 | if options.Quiet { |
| 962 | outputFormat = "{{.Id}}" |
| 963 | } |
| 964 | |
| David Bainbridge | a672234 | 2019-10-24 23:55:53 +0000 | [diff] [blame] | 965 | orderBy := options.OrderBy |
| 966 | if orderBy == "" { |
| Hardik Windlass | 9361bb8 | 2022-03-23 05:58:48 +0000 | [diff] [blame] | 967 | orderBy = GetCommandOptionWithDefault("device-list", "order", DEFAULT_DEVICE_ORDER) |
| David Bainbridge | a672234 | 2019-10-24 23:55:53 +0000 | [diff] [blame] | 968 | } |
| 969 | |
| Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 970 | // Make sure json output prints an empty list, not "null" |
| 971 | if devices.Items == nil { |
| 972 | devices.Items = make([]*voltha.Device, 0) |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 973 | } |
| 974 | |
| 975 | result := CommandResult{ |
| 976 | Format: format.Format(outputFormat), |
| 977 | Filter: options.Filter, |
| David Bainbridge | a672234 | 2019-10-24 23:55:53 +0000 | [diff] [blame] | 978 | OrderBy: orderBy, |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 979 | OutputAs: toOutputType(options.OutputAs), |
| 980 | NameLimit: options.NameLimit, |
| Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 981 | Data: devices.Items, |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 982 | } |
| 983 | |
| 984 | GenerateOutput(&result) |
| 985 | return nil |
| 986 | } |
| 987 | |
| 988 | func (options *DeviceCreate) Execute(args []string) error { |
| 989 | |
| Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 990 | device := voltha.Device{} |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 991 | if options.HostAndPort != "" { |
| Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 992 | device.Address = &voltha.Device_HostAndPort{HostAndPort: options.HostAndPort} |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 993 | } else if options.IPAddress != "" { |
| Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 994 | device.Address = &voltha.Device_Ipv4Address{Ipv4Address: options.IPAddress} |
| Hardik Windlass | ce1de34 | 2020-02-04 21:58:07 +0000 | [diff] [blame] | 995 | } |
| 996 | if options.MACAddress != "" { |
| Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 997 | device.MacAddress = strings.ToLower(options.MACAddress) |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 998 | } |
| 999 | if options.DeviceType != "" { |
| Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 1000 | device.Type = options.DeviceType |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1001 | } |
| 1002 | |
| 1003 | conn, err := NewConnection() |
| 1004 | if err != nil { |
| 1005 | return err |
| 1006 | } |
| 1007 | defer conn.Close() |
| 1008 | |
| Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 1009 | client := voltha.NewVolthaServiceClient(conn) |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1010 | |
| David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 1011 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1012 | defer cancel() |
| 1013 | |
| Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 1014 | createdDevice, err := client.CreateDevice(ctx, &device) |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1015 | if err != nil { |
| 1016 | return err |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1017 | } |
| 1018 | |
| Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 1019 | fmt.Printf("%s\n", createdDevice.Id) |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1020 | |
| 1021 | return nil |
| 1022 | } |
| 1023 | |
| 1024 | func (options *DeviceDelete) Execute(args []string) error { |
| 1025 | |
| 1026 | conn, err := NewConnection() |
| 1027 | if err != nil { |
| 1028 | return err |
| 1029 | } |
| 1030 | defer conn.Close() |
| 1031 | |
| Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 1032 | client := voltha.NewVolthaServiceClient(conn) |
| David Bainbridge | 7052fe8 | 2020-03-25 10:37:00 -0700 | [diff] [blame] | 1033 | var lastErr error |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1034 | for _, i := range options.Args.Ids { |
| David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 1035 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1036 | defer cancel() |
| 1037 | |
| Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 1038 | id := voltha.ID{Id: string(i)} |
| Himani Chawla | 9933ddc | 2020-10-12 23:53:27 +0530 | [diff] [blame] | 1039 | if options.Force { |
| 1040 | _, err = client.ForceDeleteDevice(ctx, &id) |
| 1041 | } else { |
| 1042 | _, err = client.DeleteDevice(ctx, &id) |
| 1043 | } |
| Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 1044 | |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1045 | if err != nil { |
| David Bainbridge | 0f758d4 | 2019-10-26 05:17:48 +0000 | [diff] [blame] | 1046 | Error.Printf("Error while deleting '%s': %s\n", i, err) |
| David Bainbridge | 7052fe8 | 2020-03-25 10:37:00 -0700 | [diff] [blame] | 1047 | lastErr = err |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1048 | continue |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1049 | } |
| 1050 | fmt.Printf("%s\n", i) |
| 1051 | } |
| 1052 | |
| David Bainbridge | 7052fe8 | 2020-03-25 10:37:00 -0700 | [diff] [blame] | 1053 | if lastErr != nil { |
| 1054 | return NoReportErr |
| 1055 | } |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1056 | return nil |
| 1057 | } |
| 1058 | |
| 1059 | func (options *DeviceEnable) Execute(args []string) error { |
| 1060 | conn, err := NewConnection() |
| 1061 | if err != nil { |
| 1062 | return err |
| 1063 | } |
| 1064 | defer conn.Close() |
| 1065 | |
| Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 1066 | client := voltha.NewVolthaServiceClient(conn) |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1067 | |
| David Bainbridge | 7052fe8 | 2020-03-25 10:37:00 -0700 | [diff] [blame] | 1068 | var lastErr error |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1069 | for _, i := range options.Args.Ids { |
| David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 1070 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1071 | defer cancel() |
| 1072 | |
| Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 1073 | id := voltha.ID{Id: string(i)} |
| 1074 | |
| 1075 | _, err := client.EnableDevice(ctx, &id) |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1076 | if err != nil { |
| David Bainbridge | 0f758d4 | 2019-10-26 05:17:48 +0000 | [diff] [blame] | 1077 | Error.Printf("Error while enabling '%s': %s\n", i, err) |
| David Bainbridge | 7052fe8 | 2020-03-25 10:37:00 -0700 | [diff] [blame] | 1078 | lastErr = err |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1079 | continue |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1080 | } |
| 1081 | fmt.Printf("%s\n", i) |
| 1082 | } |
| 1083 | |
| David Bainbridge | 7052fe8 | 2020-03-25 10:37:00 -0700 | [diff] [blame] | 1084 | if lastErr != nil { |
| 1085 | return NoReportErr |
| 1086 | } |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1087 | return nil |
| 1088 | } |
| 1089 | |
| 1090 | func (options *DeviceDisable) Execute(args []string) error { |
| 1091 | conn, err := NewConnection() |
| 1092 | if err != nil { |
| 1093 | return err |
| 1094 | } |
| 1095 | defer conn.Close() |
| 1096 | |
| Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 1097 | client := voltha.NewVolthaServiceClient(conn) |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1098 | |
| David Bainbridge | 7052fe8 | 2020-03-25 10:37:00 -0700 | [diff] [blame] | 1099 | var lastErr error |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1100 | for _, i := range options.Args.Ids { |
| David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 1101 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1102 | defer cancel() |
| 1103 | |
| Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 1104 | id := voltha.ID{Id: string(i)} |
| 1105 | |
| 1106 | _, err := client.DisableDevice(ctx, &id) |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1107 | if err != nil { |
| David Bainbridge | 0f758d4 | 2019-10-26 05:17:48 +0000 | [diff] [blame] | 1108 | Error.Printf("Error while disabling '%s': %s\n", i, err) |
| David Bainbridge | 7052fe8 | 2020-03-25 10:37:00 -0700 | [diff] [blame] | 1109 | lastErr = err |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1110 | continue |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1111 | } |
| 1112 | fmt.Printf("%s\n", i) |
| 1113 | } |
| 1114 | |
| David Bainbridge | 7052fe8 | 2020-03-25 10:37:00 -0700 | [diff] [blame] | 1115 | if lastErr != nil { |
| 1116 | return NoReportErr |
| 1117 | } |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1118 | return nil |
| 1119 | } |
| 1120 | |
| 1121 | func (options *DeviceReboot) Execute(args []string) error { |
| 1122 | conn, err := NewConnection() |
| 1123 | if err != nil { |
| 1124 | return err |
| 1125 | } |
| 1126 | defer conn.Close() |
| 1127 | |
| Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 1128 | client := voltha.NewVolthaServiceClient(conn) |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1129 | |
| David Bainbridge | 7052fe8 | 2020-03-25 10:37:00 -0700 | [diff] [blame] | 1130 | var lastErr error |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1131 | for _, i := range options.Args.Ids { |
| David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 1132 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1133 | defer cancel() |
| 1134 | |
| Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 1135 | id := voltha.ID{Id: string(i)} |
| 1136 | |
| 1137 | _, err := client.RebootDevice(ctx, &id) |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1138 | if err != nil { |
| David Bainbridge | 0f758d4 | 2019-10-26 05:17:48 +0000 | [diff] [blame] | 1139 | Error.Printf("Error while rebooting '%s': %s\n", i, err) |
| David Bainbridge | 7052fe8 | 2020-03-25 10:37:00 -0700 | [diff] [blame] | 1140 | lastErr = err |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1141 | continue |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1142 | } |
| 1143 | fmt.Printf("%s\n", i) |
| 1144 | } |
| 1145 | |
| David Bainbridge | 7052fe8 | 2020-03-25 10:37:00 -0700 | [diff] [blame] | 1146 | if lastErr != nil { |
| 1147 | return NoReportErr |
| 1148 | } |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1149 | return nil |
| 1150 | } |
| 1151 | |
| 1152 | func (options *DevicePortList) Execute(args []string) error { |
| 1153 | |
| 1154 | conn, err := NewConnection() |
| 1155 | if err != nil { |
| 1156 | return err |
| 1157 | } |
| 1158 | defer conn.Close() |
| 1159 | |
| Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 1160 | client := voltha.NewVolthaServiceClient(conn) |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1161 | |
| David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 1162 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1163 | defer cancel() |
| 1164 | |
| Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 1165 | id := voltha.ID{Id: string(options.Args.Id)} |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1166 | |
| Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 1167 | ports, err := client.ListDevicePorts(ctx, &id) |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1168 | if err != nil { |
| 1169 | return err |
| 1170 | } |
| 1171 | |
| 1172 | outputFormat := CharReplacer.Replace(options.Format) |
| 1173 | if outputFormat == "" { |
| David Bainbridge | a672234 | 2019-10-24 23:55:53 +0000 | [diff] [blame] | 1174 | outputFormat = GetCommandOptionWithDefault("device-ports", "format", DEFAULT_DEVICE_PORTS_FORMAT) |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1175 | } |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1176 | |
| David Bainbridge | a672234 | 2019-10-24 23:55:53 +0000 | [diff] [blame] | 1177 | orderBy := options.OrderBy |
| 1178 | if orderBy == "" { |
| 1179 | orderBy = GetCommandOptionWithDefault("device-ports", "order", "") |
| 1180 | } |
| 1181 | |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1182 | result := CommandResult{ |
| 1183 | Format: format.Format(outputFormat), |
| 1184 | Filter: options.Filter, |
| David Bainbridge | a672234 | 2019-10-24 23:55:53 +0000 | [diff] [blame] | 1185 | OrderBy: orderBy, |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1186 | OutputAs: toOutputType(options.OutputAs), |
| 1187 | NameLimit: options.NameLimit, |
| Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 1188 | Data: ports.Items, |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1189 | } |
| 1190 | |
| 1191 | GenerateOutput(&result) |
| 1192 | return nil |
| 1193 | } |
| 1194 | |
| 1195 | func (options *DeviceFlowList) Execute(args []string) error { |
| 1196 | fl := &FlowList{} |
| 1197 | fl.ListOutputOptions = options.ListOutputOptions |
| Maninder | 045921e | 2020-09-29 16:46:02 +0530 | [diff] [blame] | 1198 | fl.FlowIdOptions = options.FlowIdOptions |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1199 | fl.Args.Id = string(options.Args.Id) |
| David Bainbridge | a672234 | 2019-10-24 23:55:53 +0000 | [diff] [blame] | 1200 | fl.Method = "device-flows" |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1201 | return fl.Execute(args) |
| 1202 | } |
| 1203 | |
| Himani Chawla | 3c161c6 | 2021-05-13 16:36:51 +0530 | [diff] [blame] | 1204 | func (options *DeviceFlowGroupList) Execute(args []string) error { |
| 1205 | grp := &GroupList{} |
| 1206 | grp.ListOutputOptions = options.ListOutputOptions |
| 1207 | grp.GroupListOptions = options.GroupListOptions |
| 1208 | grp.Args.Id = string(options.Args.Id) |
| 1209 | grp.Method = "device-groups" |
| 1210 | return grp.Execute(args) |
| 1211 | } |
| 1212 | |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1213 | func (options *DeviceInspect) Execute(args []string) error { |
| 1214 | if len(args) > 0 { |
| 1215 | return fmt.Errorf("only a single argument 'DEVICE_ID' can be provided") |
| 1216 | } |
| 1217 | |
| 1218 | conn, err := NewConnection() |
| 1219 | if err != nil { |
| 1220 | return err |
| 1221 | } |
| 1222 | defer conn.Close() |
| 1223 | |
| Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 1224 | client := voltha.NewVolthaServiceClient(conn) |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1225 | |
| David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 1226 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1227 | defer cancel() |
| 1228 | |
| Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 1229 | id := voltha.ID{Id: string(options.Args.Id)} |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1230 | |
| Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 1231 | device, err := client.GetDevice(ctx, &id) |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1232 | if err != nil { |
| 1233 | return err |
| 1234 | } |
| 1235 | |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1236 | outputFormat := CharReplacer.Replace(options.Format) |
| 1237 | if outputFormat == "" { |
| David Bainbridge | a672234 | 2019-10-24 23:55:53 +0000 | [diff] [blame] | 1238 | outputFormat = GetCommandOptionWithDefault("device-inspect", "format", DEFAULT_DEVICE_INSPECT_FORMAT) |
| Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1239 | } |
| 1240 | if options.Quiet { |
| 1241 | outputFormat = "{{.Id}}" |
| 1242 | } |
| 1243 | |
| 1244 | result := CommandResult{ |
| 1245 | Format: format.Format(outputFormat), |
| 1246 | OutputAs: toOutputType(options.OutputAs), |
| 1247 | NameLimit: options.NameLimit, |
| 1248 | Data: device, |
| 1249 | } |
| 1250 | GenerateOutput(&result) |
| 1251 | return nil |
| 1252 | } |
| kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 1253 | |
| 1254 | /*Device Port Enable */ |
| 1255 | func (options *DevicePortEnable) Execute(args []string) error { |
| 1256 | conn, err := NewConnection() |
| 1257 | if err != nil { |
| 1258 | return err |
| 1259 | } |
| 1260 | defer conn.Close() |
| 1261 | |
| Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 1262 | client := voltha.NewVolthaServiceClient(conn) |
| kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 1263 | |
| David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 1264 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 1265 | defer cancel() |
| 1266 | |
| Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 1267 | port := voltha.Port{DeviceId: string(options.Args.Id), PortNo: uint32(options.Args.PortId)} |
| 1268 | |
| 1269 | _, err = client.EnablePort(ctx, &port) |
| kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 1270 | if err != nil { |
| 1271 | Error.Printf("Error enabling port number %v on device Id %s,err=%s\n", options.Args.PortId, options.Args.Id, ErrorToString(err)) |
| 1272 | return err |
| kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 1273 | } |
| 1274 | |
| 1275 | return nil |
| 1276 | } |
| 1277 | |
| Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 1278 | /*Device Port Disable */ |
| kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 1279 | func (options *DevicePortDisable) Execute(args []string) error { |
| 1280 | conn, err := NewConnection() |
| 1281 | if err != nil { |
| 1282 | return err |
| 1283 | } |
| 1284 | defer conn.Close() |
| 1285 | |
| Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 1286 | client := voltha.NewVolthaServiceClient(conn) |
| 1287 | |
| David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 1288 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 1289 | defer cancel() |
| 1290 | |
| Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 1291 | port := voltha.Port{DeviceId: string(options.Args.Id), PortNo: uint32(options.Args.PortId)} |
| 1292 | |
| 1293 | _, err = client.DisablePort(ctx, &port) |
| kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 1294 | if err != nil { |
| Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 1295 | Error.Printf("Error enabling port number %v on device Id %s,err=%s\n", options.Args.PortId, options.Args.Id, ErrorToString(err)) |
| kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 1296 | return err |
| kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 1297 | } |
| Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 1298 | |
| kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 1299 | return nil |
| 1300 | } |
| Dinesh Belwalkar | c9aa6d8 | 2020-03-04 15:22:17 -0800 | [diff] [blame] | 1301 | |
| Rohan Agrawal | d7df377 | 2020-06-29 11:23:36 +0000 | [diff] [blame] | 1302 | func (options *DevicePmConfigSetMaxSkew) Execute(args []string) error { |
| 1303 | conn, err := NewConnection() |
| 1304 | if err != nil { |
| 1305 | return err |
| 1306 | } |
| 1307 | defer conn.Close() |
| 1308 | |
| 1309 | client := voltha.NewVolthaServiceClient(conn) |
| 1310 | |
| David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 1311 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| Rohan Agrawal | d7df377 | 2020-06-29 11:23:36 +0000 | [diff] [blame] | 1312 | defer cancel() |
| 1313 | |
| 1314 | id := voltha.ID{Id: string(options.Args.Id)} |
| 1315 | |
| 1316 | pmConfigs, err := client.ListDevicePmConfigs(ctx, &id) |
| 1317 | if err != nil { |
| 1318 | return err |
| 1319 | } |
| 1320 | |
| 1321 | pmConfigs.MaxSkew = options.Args.MaxSkew |
| 1322 | |
| 1323 | _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs) |
| 1324 | if err != nil { |
| 1325 | return err |
| 1326 | } |
| 1327 | |
| 1328 | return nil |
| 1329 | } |
| 1330 | |
| Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1331 | func (options *DevicePmConfigsGet) Execute(args []string) error { |
| 1332 | |
| 1333 | conn, err := NewConnection() |
| 1334 | if err != nil { |
| 1335 | return err |
| 1336 | } |
| 1337 | defer conn.Close() |
| 1338 | |
| 1339 | client := voltha.NewVolthaServiceClient(conn) |
| 1340 | |
| David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 1341 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1342 | defer cancel() |
| 1343 | |
| 1344 | id := voltha.ID{Id: string(options.Args.Id)} |
| 1345 | |
| 1346 | pmConfigs, err := client.ListDevicePmConfigs(ctx, &id) |
| 1347 | if err != nil { |
| 1348 | return err |
| 1349 | } |
| 1350 | |
| 1351 | outputFormat := CharReplacer.Replace(options.Format) |
| 1352 | if outputFormat == "" { |
| 1353 | outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GET_FORMAT) |
| 1354 | } |
| 1355 | |
| 1356 | orderBy := options.OrderBy |
| 1357 | if orderBy == "" { |
| 1358 | orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "") |
| 1359 | } |
| 1360 | |
| 1361 | result := CommandResult{ |
| 1362 | Format: format.Format(outputFormat), |
| 1363 | Filter: options.Filter, |
| 1364 | OrderBy: orderBy, |
| 1365 | OutputAs: toOutputType(options.OutputAs), |
| 1366 | NameLimit: options.NameLimit, |
| 1367 | Data: pmConfigs, |
| 1368 | } |
| 1369 | |
| 1370 | GenerateOutput(&result) |
| 1371 | return nil |
| 1372 | |
| 1373 | } |
| 1374 | |
| 1375 | func (options *DevicePmConfigMetricList) Execute(args []string) error { |
| 1376 | |
| 1377 | conn, err := NewConnection() |
| 1378 | if err != nil { |
| 1379 | return err |
| 1380 | } |
| 1381 | defer conn.Close() |
| 1382 | |
| 1383 | client := voltha.NewVolthaServiceClient(conn) |
| 1384 | |
| David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 1385 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1386 | defer cancel() |
| 1387 | |
| 1388 | id := voltha.ID{Id: string(options.Args.Id)} |
| 1389 | |
| 1390 | pmConfigs, err := client.ListDevicePmConfigs(ctx, &id) |
| 1391 | if err != nil { |
| 1392 | return err |
| 1393 | } |
| 1394 | |
| 1395 | if !pmConfigs.Grouped { |
| 1396 | for _, metric := range pmConfigs.Metrics { |
| 1397 | if metric.SampleFreq == 0 { |
| 1398 | metric.SampleFreq = pmConfigs.DefaultFreq |
| 1399 | } |
| 1400 | } |
| Rohan Agrawal | bca6912 | 2020-06-17 14:59:03 +0000 | [diff] [blame] | 1401 | outputFormat := CharReplacer.Replace(options.Format) |
| 1402 | if outputFormat == "" { |
| 1403 | outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_METRIC_LIST_FORMAT) |
| 1404 | } |
| Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1405 | |
| Rohan Agrawal | bca6912 | 2020-06-17 14:59:03 +0000 | [diff] [blame] | 1406 | orderBy := options.OrderBy |
| 1407 | if orderBy == "" { |
| 1408 | orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "") |
| 1409 | } |
| 1410 | |
| 1411 | result := CommandResult{ |
| 1412 | Format: format.Format(outputFormat), |
| 1413 | Filter: options.Filter, |
| 1414 | OrderBy: orderBy, |
| 1415 | OutputAs: toOutputType(options.OutputAs), |
| 1416 | NameLimit: options.NameLimit, |
| 1417 | Data: pmConfigs.Metrics, |
| 1418 | } |
| 1419 | |
| 1420 | GenerateOutput(&result) |
| 1421 | return nil |
| 1422 | } else { |
| 1423 | return fmt.Errorf("Device '%s' does not have Non Grouped Metrics", options.Args.Id) |
| Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1424 | } |
| Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1425 | } |
| 1426 | |
| 1427 | func (options *DevicePmConfigMetricEnable) Execute(args []string) error { |
| 1428 | |
| 1429 | conn, err := NewConnection() |
| 1430 | if err != nil { |
| 1431 | return err |
| 1432 | } |
| 1433 | defer conn.Close() |
| 1434 | |
| 1435 | client := voltha.NewVolthaServiceClient(conn) |
| 1436 | |
| David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 1437 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1438 | defer cancel() |
| 1439 | |
| 1440 | id := voltha.ID{Id: string(options.Args.Id)} |
| 1441 | |
| 1442 | pmConfigs, err := client.ListDevicePmConfigs(ctx, &id) |
| 1443 | if err != nil { |
| 1444 | return err |
| 1445 | } |
| 1446 | |
| 1447 | if !pmConfigs.Grouped { |
| Rohan Agrawal | bca6912 | 2020-06-17 14:59:03 +0000 | [diff] [blame] | 1448 | metrics := make(map[string]struct{}) |
| 1449 | for _, metric := range pmConfigs.Metrics { |
| 1450 | metrics[metric.Name] = struct{}{} |
| 1451 | } |
| 1452 | |
| Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1453 | for _, metric := range pmConfigs.Metrics { |
| 1454 | for _, mName := range options.Args.Metrics { |
| Rohan Agrawal | bca6912 | 2020-06-17 14:59:03 +0000 | [diff] [blame] | 1455 | if _, exist := metrics[string(mName)]; !exist { |
| 1456 | return fmt.Errorf("Metric Name '%s' does not exist", mName) |
| 1457 | } |
| 1458 | |
| Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1459 | if string(mName) == metric.Name && !metric.Enabled { |
| 1460 | metric.Enabled = true |
| 1461 | _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs) |
| 1462 | if err != nil { |
| 1463 | return err |
| 1464 | } |
| 1465 | } |
| 1466 | } |
| 1467 | } |
| Rohan Agrawal | bca6912 | 2020-06-17 14:59:03 +0000 | [diff] [blame] | 1468 | } else { |
| 1469 | return fmt.Errorf("Device '%s' does not have Non Grouped Metrics", options.Args.Id) |
| Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1470 | } |
| 1471 | return nil |
| 1472 | } |
| 1473 | |
| 1474 | func (options *DevicePmConfigMetricDisable) Execute(args []string) error { |
| 1475 | |
| 1476 | conn, err := NewConnection() |
| 1477 | if err != nil { |
| 1478 | return err |
| 1479 | } |
| 1480 | defer conn.Close() |
| 1481 | |
| 1482 | client := voltha.NewVolthaServiceClient(conn) |
| 1483 | |
| David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 1484 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1485 | defer cancel() |
| 1486 | |
| 1487 | id := voltha.ID{Id: string(options.Args.Id)} |
| 1488 | |
| 1489 | pmConfigs, err := client.ListDevicePmConfigs(ctx, &id) |
| 1490 | if err != nil { |
| 1491 | return err |
| 1492 | } |
| 1493 | |
| 1494 | if !pmConfigs.Grouped { |
| Rohan Agrawal | bca6912 | 2020-06-17 14:59:03 +0000 | [diff] [blame] | 1495 | metrics := make(map[string]struct{}) |
| 1496 | for _, metric := range pmConfigs.Metrics { |
| 1497 | metrics[metric.Name] = struct{}{} |
| 1498 | } |
| 1499 | |
| Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1500 | for _, metric := range pmConfigs.Metrics { |
| 1501 | for _, mName := range options.Args.Metrics { |
| Rohan Agrawal | bca6912 | 2020-06-17 14:59:03 +0000 | [diff] [blame] | 1502 | if _, have := metrics[string(mName)]; !have { |
| 1503 | return fmt.Errorf("Metric Name '%s' does not exist", mName) |
| 1504 | } |
| Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1505 | if string(mName) == metric.Name && metric.Enabled { |
| 1506 | metric.Enabled = false |
| 1507 | _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs) |
| 1508 | if err != nil { |
| 1509 | return err |
| 1510 | } |
| Rohan Agrawal | bca6912 | 2020-06-17 14:59:03 +0000 | [diff] [blame] | 1511 | } else { |
| 1512 | return fmt.Errorf("Metric '%s' cannot be disabled", string(mName)) |
| Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1513 | } |
| 1514 | } |
| 1515 | } |
| Rohan Agrawal | bca6912 | 2020-06-17 14:59:03 +0000 | [diff] [blame] | 1516 | } else { |
| 1517 | return fmt.Errorf("Device '%s' does not have Non Grouped Metrics", options.Args.Id) |
| Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1518 | } |
| 1519 | return nil |
| 1520 | } |
| 1521 | |
| 1522 | func (options *DevicePmConfigGroupEnable) Execute(args []string) error { |
| 1523 | |
| 1524 | conn, err := NewConnection() |
| 1525 | if err != nil { |
| 1526 | return err |
| 1527 | } |
| 1528 | defer conn.Close() |
| 1529 | |
| 1530 | client := voltha.NewVolthaServiceClient(conn) |
| 1531 | |
| David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 1532 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1533 | defer cancel() |
| 1534 | |
| 1535 | id := voltha.ID{Id: string(options.Args.Id)} |
| 1536 | |
| 1537 | pmConfigs, err := client.ListDevicePmConfigs(ctx, &id) |
| 1538 | if err != nil { |
| 1539 | return err |
| 1540 | } |
| 1541 | |
| 1542 | if pmConfigs.Grouped { |
| Rohan Agrawal | bca6912 | 2020-06-17 14:59:03 +0000 | [diff] [blame] | 1543 | groups := make(map[string]struct{}) |
| 1544 | for _, group := range pmConfigs.Groups { |
| 1545 | groups[group.GroupName] = struct{}{} |
| 1546 | } |
| Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1547 | for _, group := range pmConfigs.Groups { |
| Girish Gowdra | 610acb4 | 2021-01-27 13:33:57 -0800 | [diff] [blame] | 1548 | if _, have := groups[string(options.Args.Group)]; !have { |
| 1549 | return fmt.Errorf("Group Name '%s' does not exist", options.Args.Group) |
| 1550 | } |
| 1551 | if string(options.Args.Group) == group.GroupName && !group.Enabled { |
| 1552 | group.Enabled = true |
| 1553 | _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs) |
| 1554 | if err != nil { |
| 1555 | return err |
| Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1556 | } |
| 1557 | } |
| 1558 | } |
| Rohan Agrawal | bca6912 | 2020-06-17 14:59:03 +0000 | [diff] [blame] | 1559 | } else { |
| 1560 | return fmt.Errorf("Device '%s' does not have Group Metrics", options.Args.Id) |
| Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1561 | } |
| 1562 | return nil |
| 1563 | } |
| 1564 | |
| 1565 | func (options *DevicePmConfigGroupDisable) Execute(args []string) error { |
| 1566 | |
| 1567 | conn, err := NewConnection() |
| 1568 | if err != nil { |
| 1569 | return err |
| 1570 | } |
| 1571 | defer conn.Close() |
| 1572 | |
| 1573 | client := voltha.NewVolthaServiceClient(conn) |
| 1574 | |
| David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 1575 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1576 | defer cancel() |
| 1577 | |
| 1578 | id := voltha.ID{Id: string(options.Args.Id)} |
| 1579 | |
| 1580 | pmConfigs, err := client.ListDevicePmConfigs(ctx, &id) |
| 1581 | if err != nil { |
| 1582 | return err |
| 1583 | } |
| 1584 | |
| 1585 | if pmConfigs.Grouped { |
| Rohan Agrawal | bca6912 | 2020-06-17 14:59:03 +0000 | [diff] [blame] | 1586 | groups := make(map[string]struct{}) |
| 1587 | for _, group := range pmConfigs.Groups { |
| 1588 | groups[group.GroupName] = struct{}{} |
| 1589 | } |
| 1590 | |
| Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1591 | for _, group := range pmConfigs.Groups { |
| Girish Gowdra | 610acb4 | 2021-01-27 13:33:57 -0800 | [diff] [blame] | 1592 | if _, have := groups[string(options.Args.Group)]; !have { |
| 1593 | return fmt.Errorf("Group Name '%s' does not exist", options.Args.Group) |
| 1594 | } |
| Rohan Agrawal | bca6912 | 2020-06-17 14:59:03 +0000 | [diff] [blame] | 1595 | |
| Girish Gowdra | 610acb4 | 2021-01-27 13:33:57 -0800 | [diff] [blame] | 1596 | if string(options.Args.Group) == group.GroupName && group.Enabled { |
| 1597 | group.Enabled = false |
| 1598 | _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs) |
| 1599 | if err != nil { |
| 1600 | return err |
| Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1601 | } |
| 1602 | } |
| 1603 | } |
| Rohan Agrawal | bca6912 | 2020-06-17 14:59:03 +0000 | [diff] [blame] | 1604 | } else { |
| 1605 | return fmt.Errorf("Device '%s' does not have Group Metrics", options.Args.Id) |
| Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1606 | } |
| 1607 | return nil |
| 1608 | } |
| 1609 | |
| Girish Gowdra | 610acb4 | 2021-01-27 13:33:57 -0800 | [diff] [blame] | 1610 | func (options *DevicePmConfigGroupFrequencySet) Execute(args []string) error { |
| 1611 | |
| 1612 | conn, err := NewConnection() |
| 1613 | if err != nil { |
| 1614 | return err |
| 1615 | } |
| 1616 | defer conn.Close() |
| 1617 | |
| 1618 | client := voltha.NewVolthaServiceClient(conn) |
| 1619 | |
| David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 1620 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| Girish Gowdra | 610acb4 | 2021-01-27 13:33:57 -0800 | [diff] [blame] | 1621 | defer cancel() |
| 1622 | |
| 1623 | id := voltha.ID{Id: string(options.Args.Id)} |
| 1624 | |
| 1625 | pmConfigs, err := client.ListDevicePmConfigs(ctx, &id) |
| 1626 | if err != nil { |
| 1627 | return err |
| 1628 | } |
| 1629 | |
| 1630 | if pmConfigs.Grouped { |
| 1631 | groups := make(map[string]struct{}) |
| 1632 | for _, group := range pmConfigs.Groups { |
| 1633 | groups[group.GroupName] = struct{}{} |
| 1634 | } |
| 1635 | |
| 1636 | for _, group := range pmConfigs.Groups { |
| 1637 | if _, have := groups[string(options.Args.Group)]; !have { |
| 1638 | return fmt.Errorf("group name '%s' does not exist", options.Args.Group) |
| 1639 | } |
| 1640 | |
| 1641 | if string(options.Args.Group) == group.GroupName { |
| 1642 | if !group.Enabled { |
| 1643 | return fmt.Errorf("group '%s' is not enabled", options.Args.Group) |
| 1644 | } |
| 1645 | group.GroupFreq = uint32(options.Args.Interval.Seconds()) |
| 1646 | _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs) |
| 1647 | if err != nil { |
| 1648 | return err |
| 1649 | } |
| 1650 | } |
| 1651 | } |
| 1652 | } else { |
| 1653 | return fmt.Errorf("device '%s' does not have group metrics", options.Args.Id) |
| 1654 | } |
| 1655 | return nil |
| 1656 | } |
| 1657 | |
| Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1658 | func (options *DevicePmConfigGroupList) Execute(args []string) error { |
| 1659 | |
| 1660 | conn, err := NewConnection() |
| 1661 | if err != nil { |
| 1662 | return err |
| 1663 | } |
| 1664 | defer conn.Close() |
| 1665 | |
| 1666 | client := voltha.NewVolthaServiceClient(conn) |
| 1667 | |
| David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 1668 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1669 | defer cancel() |
| 1670 | |
| 1671 | id := voltha.ID{Id: string(options.Args.Id)} |
| 1672 | |
| 1673 | pmConfigs, err := client.ListDevicePmConfigs(ctx, &id) |
| 1674 | if err != nil { |
| 1675 | return err |
| 1676 | } |
| 1677 | |
| 1678 | if pmConfigs.Grouped { |
| 1679 | for _, group := range pmConfigs.Groups { |
| 1680 | if group.GroupFreq == 0 { |
| 1681 | group.GroupFreq = pmConfigs.DefaultFreq |
| 1682 | } |
| 1683 | } |
| Rohan Agrawal | bca6912 | 2020-06-17 14:59:03 +0000 | [diff] [blame] | 1684 | outputFormat := CharReplacer.Replace(options.Format) |
| 1685 | if outputFormat == "" { |
| 1686 | outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GROUP_LIST_FORMAT) |
| 1687 | } |
| Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1688 | |
| Rohan Agrawal | bca6912 | 2020-06-17 14:59:03 +0000 | [diff] [blame] | 1689 | orderBy := options.OrderBy |
| 1690 | if orderBy == "" { |
| 1691 | orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "") |
| 1692 | } |
| 1693 | |
| 1694 | result := CommandResult{ |
| 1695 | Format: format.Format(outputFormat), |
| 1696 | Filter: options.Filter, |
| 1697 | OrderBy: orderBy, |
| 1698 | OutputAs: toOutputType(options.OutputAs), |
| 1699 | NameLimit: options.NameLimit, |
| 1700 | Data: pmConfigs.Groups, |
| 1701 | } |
| 1702 | |
| 1703 | GenerateOutput(&result) |
| 1704 | } else { |
| 1705 | return fmt.Errorf("Device '%s' does not have Group Metrics", string(options.Args.Id)) |
| Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1706 | } |
| Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1707 | return nil |
| Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1708 | } |
| 1709 | |
| 1710 | func (options *DevicePmConfigGroupMetricList) Execute(args []string) error { |
| 1711 | |
| 1712 | var metrics []*voltha.PmConfig |
| 1713 | conn, err := NewConnection() |
| 1714 | if err != nil { |
| 1715 | return err |
| 1716 | } |
| 1717 | defer conn.Close() |
| 1718 | |
| 1719 | client := voltha.NewVolthaServiceClient(conn) |
| 1720 | |
| David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 1721 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1722 | defer cancel() |
| 1723 | |
| 1724 | id := voltha.ID{Id: string(options.Args.Id)} |
| 1725 | |
| 1726 | pmConfigs, err := client.ListDevicePmConfigs(ctx, &id) |
| 1727 | if err != nil { |
| 1728 | return err |
| 1729 | } |
| 1730 | |
| 1731 | for _, groups := range pmConfigs.Groups { |
| 1732 | |
| 1733 | if string(options.Args.Group) == groups.GroupName { |
| 1734 | for _, metric := range groups.Metrics { |
| 1735 | if metric.SampleFreq == 0 && groups.GroupFreq == 0 { |
| 1736 | metric.SampleFreq = pmConfigs.DefaultFreq |
| 1737 | } else { |
| 1738 | metric.SampleFreq = groups.GroupFreq |
| 1739 | } |
| 1740 | } |
| 1741 | metrics = groups.Metrics |
| 1742 | } |
| 1743 | } |
| 1744 | |
| 1745 | outputFormat := CharReplacer.Replace(options.Format) |
| 1746 | if outputFormat == "" { |
| 1747 | outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_METRIC_LIST_FORMAT) |
| 1748 | } |
| 1749 | |
| 1750 | orderBy := options.OrderBy |
| 1751 | if orderBy == "" { |
| 1752 | orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "") |
| 1753 | } |
| 1754 | |
| 1755 | result := CommandResult{ |
| 1756 | Format: format.Format(outputFormat), |
| 1757 | Filter: options.Filter, |
| 1758 | OrderBy: orderBy, |
| 1759 | OutputAs: toOutputType(options.OutputAs), |
| 1760 | NameLimit: options.NameLimit, |
| 1761 | Data: metrics, |
| 1762 | } |
| 1763 | |
| 1764 | GenerateOutput(&result) |
| 1765 | return nil |
| 1766 | |
| 1767 | } |
| 1768 | |
| 1769 | func (options *DevicePmConfigFrequencySet) Execute(args []string) error { |
| 1770 | |
| 1771 | conn, err := NewConnection() |
| 1772 | if err != nil { |
| 1773 | return err |
| 1774 | } |
| 1775 | defer conn.Close() |
| 1776 | |
| 1777 | client := voltha.NewVolthaServiceClient(conn) |
| 1778 | |
| David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 1779 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1780 | defer cancel() |
| 1781 | |
| 1782 | id := voltha.ID{Id: string(options.Args.Id)} |
| 1783 | |
| 1784 | pmConfigs, err := client.ListDevicePmConfigs(ctx, &id) |
| 1785 | if err != nil { |
| 1786 | return err |
| 1787 | } |
| 1788 | |
| Girish Gowdra | 610acb4 | 2021-01-27 13:33:57 -0800 | [diff] [blame] | 1789 | pmConfigs.DefaultFreq = uint32(options.Args.Interval.Seconds()) |
| Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1790 | |
| 1791 | _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs) |
| 1792 | if err != nil { |
| 1793 | return err |
| 1794 | } |
| 1795 | |
| 1796 | outputFormat := CharReplacer.Replace(options.Format) |
| 1797 | if outputFormat == "" { |
| 1798 | outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GET_FORMAT) |
| 1799 | } |
| 1800 | if options.Quiet { |
| 1801 | outputFormat = "{{.Id}}" |
| 1802 | } |
| 1803 | |
| 1804 | result := CommandResult{ |
| 1805 | Format: format.Format(outputFormat), |
| 1806 | OutputAs: toOutputType(options.OutputAs), |
| 1807 | NameLimit: options.NameLimit, |
| 1808 | Data: pmConfigs, |
| 1809 | } |
| 1810 | |
| 1811 | GenerateOutput(&result) |
| 1812 | return nil |
| 1813 | |
| 1814 | } |
| 1815 | |
| kesavand | 3e2f9f6 | 2021-04-22 11:06:38 +0530 | [diff] [blame] | 1816 | func (options *OnuDownloadImage) Execute(args []string) error { |
| 1817 | |
| 1818 | conn, err := NewConnection() |
| 1819 | if err != nil { |
| 1820 | return err |
| 1821 | } |
| 1822 | defer conn.Close() |
| 1823 | |
| 1824 | client := voltha.NewVolthaServiceClient(conn) |
| 1825 | |
| 1826 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 1827 | defer cancel() |
| 1828 | |
| 1829 | var devIDList []*common.ID |
| 1830 | for _, i := range options.Args.IDs { |
| 1831 | |
| 1832 | devIDList = append(devIDList, &common.ID{Id: string(i)}) |
| 1833 | } |
| 1834 | |
| 1835 | downloadImage := voltha.DeviceImageDownloadRequest{ |
| 1836 | DeviceId: devIDList, |
| 1837 | Image: &voltha.Image{ |
| 1838 | Url: options.Args.Url, |
| 1839 | Crc32: options.Args.Crc, |
| ssiddiqui | 7bc89e9 | 2021-05-20 20:58:02 +0530 | [diff] [blame] | 1840 | Vendor: options.Args.Vendor, |
| kesavand | 3e2f9f6 | 2021-04-22 11:06:38 +0530 | [diff] [blame] | 1841 | Version: options.Args.ImageVersion, |
| 1842 | }, |
| 1843 | ActivateOnSuccess: options.Args.ActivateOnSuccess, |
| 1844 | CommitOnSuccess: options.Args.CommitOnSuccess, |
| 1845 | } |
| 1846 | |
| Andrea Campanella | eaf1e0c | 2021-06-07 14:41:34 +0200 | [diff] [blame] | 1847 | deviceImageResp, err := client.DownloadImageToDevice(ctx, &downloadImage) |
| kesavand | 3e2f9f6 | 2021-04-22 11:06:38 +0530 | [diff] [blame] | 1848 | if err != nil { |
| 1849 | return err |
| 1850 | } |
| 1851 | |
| Andrea Campanella | eaf1e0c | 2021-06-07 14:41:34 +0200 | [diff] [blame] | 1852 | outputFormat := GetCommandOptionWithDefault("onu-image-download", "format", ONU_IMAGE_STATUS_FORMAT) |
| 1853 | // Make sure json output prints an empty list, not "null" |
| 1854 | if deviceImageResp.DeviceImageStates == nil { |
| 1855 | deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0) |
| 1856 | } |
| 1857 | result := CommandResult{ |
| 1858 | Format: format.Format(outputFormat), |
| 1859 | OutputAs: toOutputType(options.OutputAs), |
| 1860 | NameLimit: options.NameLimit, |
| 1861 | Data: deviceImageResp.DeviceImageStates, |
| 1862 | } |
| 1863 | GenerateOutput(&result) |
| kesavand | 3e2f9f6 | 2021-04-22 11:06:38 +0530 | [diff] [blame] | 1864 | return nil |
| 1865 | |
| 1866 | } |
| 1867 | |
| 1868 | func (options *OnuActivateImage) Execute(args []string) error { |
| 1869 | |
| 1870 | conn, err := NewConnection() |
| 1871 | if err != nil { |
| 1872 | return err |
| 1873 | } |
| 1874 | defer conn.Close() |
| 1875 | |
| 1876 | client := voltha.NewVolthaServiceClient(conn) |
| 1877 | |
| 1878 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 1879 | defer cancel() |
| 1880 | |
| 1881 | var devIDList []*common.ID |
| 1882 | for _, i := range options.Args.IDs { |
| 1883 | |
| 1884 | devIDList = append(devIDList, &common.ID{Id: string(i)}) |
| 1885 | } |
| 1886 | |
| 1887 | downloadImage := voltha.DeviceImageRequest{ |
| 1888 | DeviceId: devIDList, |
| 1889 | Version: options.Args.ImageVersion, |
| 1890 | CommitOnSuccess: options.Args.CommitOnSuccess, |
| 1891 | } |
| 1892 | |
| Andrea Campanella | eaf1e0c | 2021-06-07 14:41:34 +0200 | [diff] [blame] | 1893 | deviceImageResp, err := client.ActivateImage(ctx, &downloadImage) |
| kesavand | 3e2f9f6 | 2021-04-22 11:06:38 +0530 | [diff] [blame] | 1894 | if err != nil { |
| 1895 | return err |
| 1896 | } |
| 1897 | |
| Andrea Campanella | eaf1e0c | 2021-06-07 14:41:34 +0200 | [diff] [blame] | 1898 | outputFormat := GetCommandOptionWithDefault("onu-image-activate", "format", ONU_IMAGE_STATUS_FORMAT) |
| 1899 | // Make sure json output prints an empty list, not "null" |
| 1900 | if deviceImageResp.DeviceImageStates == nil { |
| 1901 | deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0) |
| 1902 | } |
| 1903 | result := CommandResult{ |
| 1904 | Format: format.Format(outputFormat), |
| 1905 | OutputAs: toOutputType(options.OutputAs), |
| 1906 | NameLimit: options.NameLimit, |
| 1907 | Data: deviceImageResp.DeviceImageStates, |
| 1908 | } |
| 1909 | GenerateOutput(&result) |
| 1910 | |
| kesavand | 3e2f9f6 | 2021-04-22 11:06:38 +0530 | [diff] [blame] | 1911 | return nil |
| 1912 | |
| 1913 | } |
| 1914 | |
| 1915 | func (options *OnuAbortUpgradeImage) Execute(args []string) error { |
| 1916 | |
| 1917 | conn, err := NewConnection() |
| 1918 | if err != nil { |
| 1919 | return err |
| 1920 | } |
| 1921 | defer conn.Close() |
| 1922 | |
| 1923 | client := voltha.NewVolthaServiceClient(conn) |
| 1924 | |
| 1925 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 1926 | defer cancel() |
| 1927 | |
| 1928 | var devIDList []*common.ID |
| 1929 | for _, i := range options.Args.IDs { |
| 1930 | |
| 1931 | devIDList = append(devIDList, &common.ID{Id: string(i)}) |
| 1932 | } |
| 1933 | |
| 1934 | downloadImage := voltha.DeviceImageRequest{ |
| 1935 | DeviceId: devIDList, |
| 1936 | Version: options.Args.ImageVersion, |
| 1937 | } |
| 1938 | |
| Andrea Campanella | eaf1e0c | 2021-06-07 14:41:34 +0200 | [diff] [blame] | 1939 | deviceImageResp, err := client.AbortImageUpgradeToDevice(ctx, &downloadImage) |
| kesavand | 3e2f9f6 | 2021-04-22 11:06:38 +0530 | [diff] [blame] | 1940 | if err != nil { |
| 1941 | return err |
| 1942 | } |
| 1943 | |
| Andrea Campanella | eaf1e0c | 2021-06-07 14:41:34 +0200 | [diff] [blame] | 1944 | outputFormat := GetCommandOptionWithDefault("onu-image-abort", "format", ONU_IMAGE_STATUS_FORMAT) |
| 1945 | // Make sure json output prints an empty list, not "null" |
| 1946 | if deviceImageResp.DeviceImageStates == nil { |
| 1947 | deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0) |
| 1948 | } |
| 1949 | result := CommandResult{ |
| 1950 | Format: format.Format(outputFormat), |
| 1951 | OutputAs: toOutputType(options.OutputAs), |
| 1952 | NameLimit: options.NameLimit, |
| 1953 | Data: deviceImageResp.DeviceImageStates, |
| 1954 | } |
| 1955 | GenerateOutput(&result) |
| 1956 | |
| kesavand | 3e2f9f6 | 2021-04-22 11:06:38 +0530 | [diff] [blame] | 1957 | return nil |
| 1958 | |
| 1959 | } |
| 1960 | |
| 1961 | func (options *OnuCommitImage) Execute(args []string) error { |
| 1962 | |
| 1963 | conn, err := NewConnection() |
| 1964 | if err != nil { |
| 1965 | return err |
| 1966 | } |
| 1967 | defer conn.Close() |
| 1968 | |
| 1969 | client := voltha.NewVolthaServiceClient(conn) |
| 1970 | |
| 1971 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 1972 | defer cancel() |
| 1973 | |
| 1974 | var devIDList []*common.ID |
| 1975 | for _, i := range options.Args.IDs { |
| 1976 | |
| 1977 | devIDList = append(devIDList, &common.ID{Id: string(i)}) |
| 1978 | } |
| 1979 | downloadImage := voltha.DeviceImageRequest{ |
| 1980 | DeviceId: devIDList, |
| 1981 | Version: options.Args.ImageVersion, |
| 1982 | } |
| 1983 | |
| Andrea Campanella | eaf1e0c | 2021-06-07 14:41:34 +0200 | [diff] [blame] | 1984 | deviceImageResp, err := client.CommitImage(ctx, &downloadImage) |
| kesavand | 3e2f9f6 | 2021-04-22 11:06:38 +0530 | [diff] [blame] | 1985 | if err != nil { |
| 1986 | return err |
| 1987 | } |
| 1988 | |
| Andrea Campanella | eaf1e0c | 2021-06-07 14:41:34 +0200 | [diff] [blame] | 1989 | outputFormat := GetCommandOptionWithDefault("onu-image-commit", "format", ONU_IMAGE_STATUS_FORMAT) |
| 1990 | // Make sure json output prints an empty list, not "null" |
| 1991 | if deviceImageResp.DeviceImageStates == nil { |
| 1992 | deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0) |
| 1993 | } |
| 1994 | result := CommandResult{ |
| 1995 | Format: format.Format(outputFormat), |
| 1996 | OutputAs: toOutputType(options.OutputAs), |
| 1997 | NameLimit: options.NameLimit, |
| 1998 | Data: deviceImageResp.DeviceImageStates, |
| 1999 | } |
| 2000 | GenerateOutput(&result) |
| 2001 | |
| kesavand | 3e2f9f6 | 2021-04-22 11:06:38 +0530 | [diff] [blame] | 2002 | return nil |
| 2003 | |
| 2004 | } |
| 2005 | |
| 2006 | func (options *OnuListImages) Execute(args []string) error { |
| 2007 | |
| 2008 | conn, err := NewConnection() |
| 2009 | if err != nil { |
| 2010 | return err |
| 2011 | } |
| 2012 | defer conn.Close() |
| 2013 | |
| 2014 | client := voltha.NewVolthaServiceClient(conn) |
| 2015 | |
| 2016 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 2017 | defer cancel() |
| 2018 | |
| 2019 | id := common.ID{Id: string(options.Args.Id)} |
| 2020 | |
| 2021 | onuImages, err := client.GetOnuImages(ctx, &id) |
| 2022 | if err != nil { |
| 2023 | return err |
| 2024 | } |
| 2025 | |
| 2026 | outputFormat := CharReplacer.Replace(options.Format) |
| 2027 | if outputFormat == "" { |
| 2028 | outputFormat = GetCommandOptionWithDefault("onu-image-list", "format", ONU_IMAGE_LIST_FORMAT) |
| 2029 | } |
| 2030 | |
| 2031 | if options.Quiet { |
| 2032 | outputFormat = "{{.Id}}" |
| 2033 | } |
| 2034 | |
| 2035 | //TODO orderby |
| 2036 | |
| 2037 | // Make sure json output prints an empty list, not "null" |
| 2038 | if onuImages.Items == nil { |
| 2039 | onuImages.Items = make([]*voltha.OnuImage, 0) |
| 2040 | } |
| 2041 | |
| 2042 | result := CommandResult{ |
| 2043 | Format: format.Format(outputFormat), |
| 2044 | OutputAs: toOutputType(options.OutputAs), |
| 2045 | NameLimit: options.NameLimit, |
| 2046 | Data: onuImages.Items, |
| 2047 | } |
| 2048 | |
| 2049 | GenerateOutput(&result) |
| 2050 | return nil |
| 2051 | |
| 2052 | } |
| 2053 | |
| 2054 | func (options *OnuImageStatus) Execute(args []string) error { |
| 2055 | |
| 2056 | conn, err := NewConnection() |
| 2057 | if err != nil { |
| 2058 | return err |
| 2059 | } |
| 2060 | defer conn.Close() |
| 2061 | |
| 2062 | client := voltha.NewVolthaServiceClient(conn) |
| 2063 | |
| 2064 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 2065 | defer cancel() |
| 2066 | |
| 2067 | var devIDList []*common.ID |
| kesavand | 3e2f9f6 | 2021-04-22 11:06:38 +0530 | [diff] [blame] | 2068 | |
| Elia Battiston | 859f3e6 | 2022-02-08 15:57:52 +0100 | [diff] [blame] | 2069 | if options.Args.IDs == nil { |
| 2070 | //Use an empty IDs list to retrieve the status of all devices |
| 2071 | //with the requested image version |
| 2072 | devIDList = []*common.ID{} |
| 2073 | } else { |
| 2074 | for _, i := range options.Args.IDs { |
| 2075 | devIDList = append(devIDList, &common.ID{Id: string(i)}) |
| 2076 | } |
| kesavand | 3e2f9f6 | 2021-04-22 11:06:38 +0530 | [diff] [blame] | 2077 | } |
| 2078 | |
| 2079 | imageStatusReq := voltha.DeviceImageRequest{ |
| 2080 | DeviceId: devIDList, |
| 2081 | Version: options.Args.ImageVersion, |
| 2082 | } |
| 2083 | imageStatus, err := client.GetImageStatus(ctx, &imageStatusReq) |
| 2084 | if err != nil { |
| 2085 | return err |
| 2086 | } |
| 2087 | |
| 2088 | outputFormat := CharReplacer.Replace(options.Format) |
| 2089 | if outputFormat == "" { |
| 2090 | outputFormat = GetCommandOptionWithDefault("device-image-list", "format", ONU_IMAGE_STATUS_FORMAT) |
| 2091 | } |
| 2092 | |
| 2093 | if options.Quiet { |
| 2094 | outputFormat = "{{.Id}}" |
| 2095 | } |
| 2096 | |
| 2097 | //TODO orderby |
| 2098 | |
| 2099 | // Make sure json output prints an empty list, not "null" |
| 2100 | if imageStatus.DeviceImageStates == nil { |
| 2101 | imageStatus.DeviceImageStates = make([]*voltha.DeviceImageState, 0) |
| 2102 | } |
| 2103 | |
| 2104 | result := CommandResult{ |
| 2105 | Format: format.Format(outputFormat), |
| 2106 | OutputAs: toOutputType(options.OutputAs), |
| 2107 | NameLimit: options.NameLimit, |
| 2108 | Data: imageStatus.DeviceImageStates, |
| 2109 | } |
| 2110 | |
| 2111 | GenerateOutput(&result) |
| 2112 | return nil |
| 2113 | |
| 2114 | } |
| 2115 | |
| Andrea Campanella | 791d88b | 2021-01-08 13:29:00 +0100 | [diff] [blame] | 2116 | func (options *DeviceOnuListImages) Execute(args []string) error { |
| 2117 | |
| 2118 | conn, err := NewConnection() |
| 2119 | if err != nil { |
| 2120 | return err |
| 2121 | } |
| 2122 | defer conn.Close() |
| 2123 | |
| 2124 | client := voltha.NewVolthaServiceClient(conn) |
| 2125 | |
| David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 2126 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| Andrea Campanella | 791d88b | 2021-01-08 13:29:00 +0100 | [diff] [blame] | 2127 | defer cancel() |
| 2128 | |
| 2129 | id := common.ID{Id: string(options.Args.Id)} |
| 2130 | |
| 2131 | imageDownloads, err := client.ListImageDownloads(ctx, &id) |
| 2132 | if err != nil { |
| 2133 | return err |
| 2134 | } |
| 2135 | |
| 2136 | outputFormat := CharReplacer.Replace(options.Format) |
| 2137 | if outputFormat == "" { |
| 2138 | outputFormat = GetCommandOptionWithDefault("device-image-list", "format", DEFAULT_DEVICE_IMAGE_LIST_GET_FORMAT) |
| 2139 | } |
| 2140 | |
| 2141 | if options.Quiet { |
| 2142 | outputFormat = "{{.Id}}" |
| 2143 | } |
| 2144 | |
| 2145 | //TODO orderby |
| 2146 | |
| 2147 | // Make sure json output prints an empty list, not "null" |
| 2148 | if imageDownloads.Items == nil { |
| 2149 | imageDownloads.Items = make([]*voltha.ImageDownload, 0) |
| 2150 | } |
| 2151 | |
| 2152 | result := CommandResult{ |
| 2153 | Format: format.Format(outputFormat), |
| 2154 | OutputAs: toOutputType(options.OutputAs), |
| 2155 | NameLimit: options.NameLimit, |
| 2156 | Data: imageDownloads.Items, |
| 2157 | } |
| 2158 | |
| 2159 | GenerateOutput(&result) |
| 2160 | return nil |
| 2161 | |
| 2162 | } |
| 2163 | |
| 2164 | func (options *DeviceOnuDownloadImage) Execute(args []string) error { |
| 2165 | |
| 2166 | conn, err := NewConnection() |
| 2167 | if err != nil { |
| 2168 | return err |
| 2169 | } |
| 2170 | defer conn.Close() |
| 2171 | |
| 2172 | client := voltha.NewVolthaServiceClient(conn) |
| 2173 | |
| David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 2174 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| Andrea Campanella | 791d88b | 2021-01-08 13:29:00 +0100 | [diff] [blame] | 2175 | defer cancel() |
| 2176 | |
| 2177 | downloadImage := voltha.ImageDownload{ |
| 2178 | Id: string(options.Args.Id), |
| 2179 | Name: options.Args.Name, |
| 2180 | Url: options.Args.Url, |
| 2181 | Crc: options.Args.Crc, |
| 2182 | LocalDir: options.Args.LocalDir, |
| 2183 | } |
| 2184 | |
| 2185 | _, err = client.DownloadImage(ctx, &downloadImage) |
| 2186 | if err != nil { |
| 2187 | return err |
| 2188 | } |
| 2189 | |
| 2190 | return nil |
| 2191 | |
| 2192 | } |
| 2193 | |
| 2194 | func (options *DeviceOnuActivateImageUpdate) Execute(args []string) error { |
| 2195 | |
| 2196 | conn, err := NewConnection() |
| 2197 | if err != nil { |
| 2198 | return err |
| 2199 | } |
| 2200 | defer conn.Close() |
| 2201 | |
| 2202 | client := voltha.NewVolthaServiceClient(conn) |
| 2203 | |
| David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 2204 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| Andrea Campanella | 791d88b | 2021-01-08 13:29:00 +0100 | [diff] [blame] | 2205 | defer cancel() |
| 2206 | |
| 2207 | downloadImage := voltha.ImageDownload{ |
| 2208 | Id: string(options.Args.Id), |
| 2209 | Name: options.Args.Name, |
| 2210 | ImageVersion: options.Args.ImageVersion, |
| 2211 | SaveConfig: options.Args.SaveConfig, |
| 2212 | LocalDir: options.Args.LocalDir, |
| 2213 | } |
| 2214 | |
| 2215 | _, err = client.ActivateImageUpdate(ctx, &downloadImage) |
| 2216 | if err != nil { |
| 2217 | return err |
| 2218 | } |
| 2219 | |
| 2220 | return nil |
| 2221 | |
| 2222 | } |
| 2223 | |
| Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 2224 | type ReturnValueRow struct { |
| 2225 | Name string `json:"name"` |
| 2226 | Result interface{} `json:"result"` |
| 2227 | } |
| 2228 | |
| kesavand | 8ec4fc0 | 2021-01-27 09:10:22 -0500 | [diff] [blame] | 2229 | func (options *DeviceGetPortStats) Execute(args []string) error { |
| 2230 | conn, err := NewConnection() |
| 2231 | if err != nil { |
| 2232 | return err |
| 2233 | } |
| 2234 | defer conn.Close() |
| 2235 | client := extension.NewExtensionClient(conn) |
| 2236 | var portType extension.GetOltPortCounters_PortType |
| 2237 | |
| 2238 | if options.Args.PortType == "pon" { |
| 2239 | portType = extension.GetOltPortCounters_Port_PON_OLT |
| 2240 | } else if options.Args.PortType == "nni" { |
| 2241 | |
| 2242 | portType = extension.GetOltPortCounters_Port_ETHERNET_NNI |
| 2243 | } else { |
| 2244 | return fmt.Errorf("expected interface type pon/nni, provided %s", options.Args.PortType) |
| 2245 | } |
| 2246 | |
| 2247 | singleGetValReq := extension.SingleGetValueRequest{ |
| 2248 | TargetId: string(options.Args.Id), |
| 2249 | Request: &extension.GetValueRequest{ |
| 2250 | Request: &extension.GetValueRequest_OltPortInfo{ |
| 2251 | OltPortInfo: &extension.GetOltPortCounters{ |
| 2252 | PortNo: options.Args.PortNo, |
| 2253 | PortType: portType, |
| 2254 | }, |
| 2255 | }, |
| 2256 | }, |
| 2257 | } |
| 2258 | |
| David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 2259 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| kesavand | 8ec4fc0 | 2021-01-27 09:10:22 -0500 | [diff] [blame] | 2260 | defer cancel() |
| 2261 | rv, err := client.GetExtValue(ctx, &singleGetValReq) |
| 2262 | if err != nil { |
| 2263 | Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err)) |
| 2264 | return err |
| 2265 | } |
| 2266 | |
| 2267 | if rv.Response.Status != extension.GetValueResponse_OK { |
| 2268 | return fmt.Errorf("failed to get port stats %v", rv.Response.ErrReason.String()) |
| 2269 | } |
| 2270 | |
| 2271 | outputFormat := CharReplacer.Replace(options.Format) |
| 2272 | if outputFormat == "" { |
| 2273 | outputFormat = GetCommandOptionWithDefault("device-get-port-status", "format", DEFAULT_DEVICE_GET_PORT_STATUS_FORMAT) |
| 2274 | } |
| 2275 | |
| 2276 | result := CommandResult{ |
| 2277 | Format: format.Format(outputFormat), |
| 2278 | OutputAs: toOutputType(options.OutputAs), |
| 2279 | NameLimit: options.NameLimit, |
| 2280 | Data: rv.GetResponse().GetPortCoutners(), |
| 2281 | } |
| 2282 | GenerateOutput(&result) |
| 2283 | return nil |
| 2284 | } |
| 2285 | |
| Himani Chawla | 40acc12 | 2021-05-26 18:52:29 +0530 | [diff] [blame] | 2286 | func (options *GetOnuStats) Execute(args []string) error { |
| 2287 | conn, err := NewConnection() |
| 2288 | if err != nil { |
| 2289 | return err |
| 2290 | } |
| 2291 | defer conn.Close() |
| 2292 | client := extension.NewExtensionClient(conn) |
| 2293 | |
| 2294 | singleGetValReq := extension.SingleGetValueRequest{ |
| 2295 | TargetId: string(options.Args.OltId), |
| 2296 | Request: &extension.GetValueRequest{ |
| 2297 | Request: &extension.GetValueRequest_OnuPonInfo{ |
| 2298 | OnuPonInfo: &extension.GetOnuCountersRequest{ |
| 2299 | IntfId: options.Args.IntfId, |
| 2300 | OnuId: options.Args.OnuId, |
| 2301 | }, |
| 2302 | }, |
| 2303 | }, |
| 2304 | } |
| 2305 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 2306 | defer cancel() |
| 2307 | rv, err := client.GetExtValue(ctx, &singleGetValReq) |
| 2308 | if err != nil { |
| 2309 | Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.OltId, ErrorToString(err)) |
| 2310 | return err |
| 2311 | } |
| 2312 | |
| 2313 | if rv.Response.Status != extension.GetValueResponse_OK { |
| 2314 | return fmt.Errorf("failed to get onu stats %v", rv.Response.ErrReason.String()) |
| 2315 | } |
| 2316 | outputFormat := CharReplacer.Replace(options.Format) |
| 2317 | data, formatStr := buildOnuStatsOutputFormat(rv.GetResponse().GetOnuPonCounters()) |
| 2318 | if outputFormat == "" { |
| 2319 | outputFormat = GetCommandOptionWithDefault("device-get-onu-status", "format", formatStr) |
| 2320 | } |
| Himani Chawla | 553a139 | 2021-06-10 23:39:17 +0530 | [diff] [blame] | 2321 | result := CommandResult{ |
| 2322 | Format: format.Format(outputFormat), |
| 2323 | OutputAs: toOutputType(options.OutputAs), |
| 2324 | NameLimit: options.NameLimit, |
| 2325 | Data: data, |
| 2326 | } |
| 2327 | GenerateOutput(&result) |
| 2328 | return nil |
| 2329 | } |
| Himani Chawla | 40acc12 | 2021-05-26 18:52:29 +0530 | [diff] [blame] | 2330 | |
| Akash Soni | 6e879c2 | 2024-12-20 17:01:34 +0530 | [diff] [blame] | 2331 | func (options *GetOffloadApp) Execute(args []string) error { |
| Akash Soni | 51b6b7a | 2024-11-20 11:39:38 +0530 | [diff] [blame] | 2332 | // Establish a connection to the gRPC server |
| 2333 | conn, err := NewConnection() |
| 2334 | if err != nil { |
| 2335 | return err |
| 2336 | } |
| 2337 | defer conn.Close() |
| 2338 | |
| 2339 | client := extension.NewExtensionClient(conn) |
| 2340 | |
| 2341 | // Build the request |
| 2342 | singleGetValReq := &extension.SingleGetValueRequest{ |
| 2343 | TargetId: string(options.Args.OltId), |
| 2344 | Request: &extension.GetValueRequest{ |
| 2345 | Request: &extension.GetValueRequest_OffloadedAppsStats{ |
| 2346 | OffloadedAppsStats: &extension.GetOffloadedAppsStatisticsRequest{ |
| 2347 | StatsFor: options.Args.StatsFor, |
| 2348 | }, |
| 2349 | }, |
| 2350 | }, |
| 2351 | } |
| 2352 | |
| 2353 | // Set a context with timeout |
| 2354 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 2355 | defer cancel() |
| 2356 | |
| 2357 | // Perform the gRPC call |
| 2358 | rv, err := client.GetExtValue(ctx, singleGetValReq) |
| 2359 | if err != nil { |
| 2360 | Error.Printf("Error getting value for device ID %s, err=%s\n", options.Args.OltId, ErrorToString(err)) |
| 2361 | return err |
| 2362 | } |
| 2363 | |
| 2364 | // Check response status |
| 2365 | if rv.GetResponse().GetStatus() != extension.GetValueResponse_OK { |
| 2366 | return fmt.Errorf("failed to get offloaded app stats: %v", rv.GetResponse().GetErrReason().String()) |
| 2367 | } |
| 2368 | |
| 2369 | // Process the response data |
| 2370 | stats, formatStr := buildOffloadAppStatsOutputFormat(rv.GetResponse().GetOffloadedAppsStats()) |
| 2371 | outputFormat := CharReplacer.Replace(options.Format) |
| 2372 | if outputFormat == "" { |
| 2373 | outputFormat = GetCommandOptionWithDefault("device-get-offload-app-stats", "format", formatStr) |
| 2374 | } |
| 2375 | |
| 2376 | // Generate and display the output |
| 2377 | result := CommandResult{ |
| 2378 | Format: format.Format(outputFormat), |
| 2379 | OutputAs: toOutputType(options.OutputAs), |
| 2380 | NameLimit: options.NameLimit, |
| 2381 | Data: stats, |
| 2382 | } |
| 2383 | GenerateOutput(&result) |
| 2384 | |
| 2385 | return nil |
| 2386 | } |
| 2387 | |
| Akash Soni | 6e879c2 | 2024-12-20 17:01:34 +0530 | [diff] [blame] | 2388 | func (options *SetOffloadApp) Execute(args []string) error { |
| Akash Soni | 51b6b7a | 2024-11-20 11:39:38 +0530 | [diff] [blame] | 2389 | conn, err := NewConnection() |
| 2390 | if err != nil { |
| Akash Soni | 6e879c2 | 2024-12-20 17:01:34 +0530 | [diff] [blame] | 2391 | return fmt.Errorf("failed to establish gRPC connection: %w", err) |
| Akash Soni | 51b6b7a | 2024-11-20 11:39:38 +0530 | [diff] [blame] | 2392 | } |
| 2393 | defer conn.Close() |
| 2394 | |
| 2395 | client := extension.NewExtensionClient(conn) |
| 2396 | |
| Akash Soni | 6e879c2 | 2024-12-20 17:01:34 +0530 | [diff] [blame] | 2397 | // Parse JSON input |
| 2398 | var config extension.AppOffloadConfig |
| 2399 | if err := json.Unmarshal([]byte(options.Args.Config), &config); err != nil { |
| 2400 | return fmt.Errorf("failed to parse CONFIG as JSON: %w", err) |
| 2401 | } |
| 2402 | |
| Akash Soni | 51b6b7a | 2024-11-20 11:39:38 +0530 | [diff] [blame] | 2403 | setValueRequest := &extension.SetValueRequest{ |
| 2404 | Request: &extension.SetValueRequest_AppOffloadConfig{ |
| Akash Soni | 6e879c2 | 2024-12-20 17:01:34 +0530 | [diff] [blame] | 2405 | AppOffloadConfig: &config, |
| Akash Soni | 51b6b7a | 2024-11-20 11:39:38 +0530 | [diff] [blame] | 2406 | }, |
| 2407 | } |
| 2408 | |
| 2409 | singleSetValReq := &extension.SingleSetValueRequest{ |
| 2410 | TargetId: string(options.Args.OltId), |
| 2411 | Request: setValueRequest, |
| 2412 | } |
| 2413 | |
| Akash Soni | 6e879c2 | 2024-12-20 17:01:34 +0530 | [diff] [blame] | 2414 | // Log the request object |
| 2415 | logRequestAppOffloadConfig(singleSetValReq) |
| 2416 | |
| Akash Soni | 51b6b7a | 2024-11-20 11:39:38 +0530 | [diff] [blame] | 2417 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 2418 | defer cancel() |
| 2419 | |
| 2420 | resp, err := client.SetExtValue(ctx, singleSetValReq) |
| 2421 | if err != nil { |
| Akash Soni | 6e879c2 | 2024-12-20 17:01:34 +0530 | [diff] [blame] | 2422 | return fmt.Errorf("failed to set AppOffloadConfig: %w", err) |
| Akash Soni | 51b6b7a | 2024-11-20 11:39:38 +0530 | [diff] [blame] | 2423 | } |
| 2424 | |
| 2425 | if resp.Response.Status != extension.SetValueResponse_OK { |
| Akash Soni | 6e879c2 | 2024-12-20 17:01:34 +0530 | [diff] [blame] | 2426 | return fmt.Errorf("operation failed with status %v: %s", resp.Response.Status, resp.Response.ErrReason) |
| Akash Soni | 51b6b7a | 2024-11-20 11:39:38 +0530 | [diff] [blame] | 2427 | } |
| 2428 | |
| 2429 | fmt.Printf("AppOffloadConfig successfully set for OLT ID: %s\n", options.Args.OltId) |
| 2430 | return nil |
| 2431 | } |
| 2432 | |
| Akash Soni | 6e879c2 | 2024-12-20 17:01:34 +0530 | [diff] [blame] | 2433 | func logRequestAppOffloadConfig(req *extension.SingleSetValueRequest) { |
| 2434 | fmt.Printf("Request details:\n") |
| 2435 | fmt.Printf("TargetId: %s\n", req.TargetId) |
| 2436 | if config, ok := req.Request.Request.(*extension.SetValueRequest_AppOffloadConfig); ok { |
| 2437 | fmt.Printf("AppOffloadConfig:\n") |
| 2438 | fmt.Printf(" EnableDHCPv4RA: %t\n", config.AppOffloadConfig.EnableDHCPv4RA) |
| 2439 | fmt.Printf(" EnableDHCPv6RA: %t\n", config.AppOffloadConfig.EnableDHCPv6RA) |
| 2440 | fmt.Printf(" EnablePPPoEIA: %t\n", config.AppOffloadConfig.EnablePPPoEIA) |
| 2441 | fmt.Printf(" AccessNodeID: %s\n", config.AppOffloadConfig.AccessNodeID) |
| 2442 | } |
| 2443 | } |
| 2444 | |
| 2445 | func (options *SetOnuOffload) Execute(args []string) error { |
| 2446 | // Create the gRPC client connection |
| Akash Soni | 51b6b7a | 2024-11-20 11:39:38 +0530 | [diff] [blame] | 2447 | conn, err := NewConnection() |
| 2448 | if err != nil { |
| 2449 | return fmt.Errorf("failed to establish gRPC connection: %v", err) |
| 2450 | } |
| 2451 | defer conn.Close() |
| 2452 | |
| 2453 | client := extension.NewExtensionClient(conn) |
| 2454 | |
| Akash Soni | 6e879c2 | 2024-12-20 17:01:34 +0530 | [diff] [blame] | 2455 | // Parse PerUniInfo into a slice of PerUniConfig |
| 2456 | var perUniConfigs []AppOffloadOnuConfig |
| 2457 | if err := json.Unmarshal([]byte(options.Args.PerUniInfo), &perUniConfigs); err != nil { |
| 2458 | return fmt.Errorf("failed to parse PerUniInfo as JSON: %v", err) |
| Akash Soni | 51b6b7a | 2024-11-20 11:39:38 +0530 | [diff] [blame] | 2459 | } |
| Akash Soni | 6e879c2 | 2024-12-20 17:01:34 +0530 | [diff] [blame] | 2460 | |
| 2461 | // Convert to []*AppOffloadOnuConfig_PerUniConfig for gRPC |
| 2462 | var grpcPerUniInfo []*extension.AppOffloadOnuConfig_PerUniConfig |
| 2463 | for _, config := range perUniConfigs { |
| 2464 | grpcPerUniInfo = append(grpcPerUniInfo, &extension.AppOffloadOnuConfig_PerUniConfig{ |
| 2465 | AgentRemoteID: config.AgentRemoteID, |
| 2466 | AgentCircuitID: config.AgentCircuitID, |
| 2467 | OnuUniId: config.OnuUniId, |
| 2468 | }) |
| 2469 | } |
| 2470 | |
| Akash Soni | 51b6b7a | 2024-11-20 11:39:38 +0530 | [diff] [blame] | 2471 | // Build the AppOffloadOnuConfig request |
| 2472 | onuConfig := &extension.AppOffloadOnuConfig{ |
| 2473 | OnuDeviceId: options.Args.OnuDeviceId, |
| Akash Soni | 6e879c2 | 2024-12-20 17:01:34 +0530 | [diff] [blame] | 2474 | PerUniInfo: grpcPerUniInfo, |
| Akash Soni | 51b6b7a | 2024-11-20 11:39:38 +0530 | [diff] [blame] | 2475 | } |
| 2476 | |
| 2477 | setValueRequest := &extension.SetValueRequest{ |
| 2478 | Request: &extension.SetValueRequest_AppOffloadOnuConfig{ |
| 2479 | AppOffloadOnuConfig: onuConfig, |
| 2480 | }, |
| 2481 | } |
| 2482 | |
| 2483 | singleSetValReq := &extension.SingleSetValueRequest{ |
| Akash Soni | 6e879c2 | 2024-12-20 17:01:34 +0530 | [diff] [blame] | 2484 | TargetId: string(options.Args.OltId), |
| Akash Soni | 51b6b7a | 2024-11-20 11:39:38 +0530 | [diff] [blame] | 2485 | Request: setValueRequest, |
| 2486 | } |
| 2487 | |
| Akash Soni | 6e879c2 | 2024-12-20 17:01:34 +0530 | [diff] [blame] | 2488 | // Log the request object |
| 2489 | logRequestAppOffloadOnuConfig(singleSetValReq) |
| 2490 | |
| 2491 | // Make the gRPC call |
| Akash Soni | 51b6b7a | 2024-11-20 11:39:38 +0530 | [diff] [blame] | 2492 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 2493 | defer cancel() |
| 2494 | |
| 2495 | resp, err := client.SetExtValue(ctx, singleSetValReq) |
| 2496 | if err != nil { |
| 2497 | return fmt.Errorf("failed to set AppOffloadOnuConfig: %v", err) |
| 2498 | } |
| 2499 | |
| 2500 | if resp.Response.Status != extension.SetValueResponse_OK { |
| Akash Soni | 6e879c2 | 2024-12-20 17:01:34 +0530 | [diff] [blame] | 2501 | return fmt.Errorf("operation failed with status %v: %s", resp.Response.Status, resp.Response.ErrReason) |
| Akash Soni | 51b6b7a | 2024-11-20 11:39:38 +0530 | [diff] [blame] | 2502 | } |
| 2503 | |
| 2504 | fmt.Printf("AppOffloadOnuConfig successfully set for ONU ID: %s\n", options.Args.OnuDeviceId) |
| 2505 | return nil |
| 2506 | } |
| 2507 | |
| Akash Soni | 6e879c2 | 2024-12-20 17:01:34 +0530 | [diff] [blame] | 2508 | // Debugging helper to log the gRPC request details |
| 2509 | func logRequestAppOffloadOnuConfig(req *extension.SingleSetValueRequest) { |
| 2510 | fmt.Printf("Request details:\n") |
| 2511 | fmt.Printf("TargetId: %s\n", req.TargetId) |
| 2512 | fmt.Printf("OnuDeviceId: %s\n", req.Request.GetAppOffloadOnuConfig().OnuDeviceId) |
| 2513 | if config, ok := req.Request.Request.(*extension.SetValueRequest_AppOffloadOnuConfig); ok { |
| 2514 | fmt.Printf("AppOffloadOnuConfig:\n") |
| 2515 | for i, uniInfo := range config.AppOffloadOnuConfig.PerUniInfo { |
| 2516 | fmt.Printf(" UniInfo %d:\n", i+1) |
| 2517 | fmt.Printf(" AgentRemoteID: %s\n", uniInfo.AgentRemoteID) |
| 2518 | fmt.Printf(" AgentCircuitID: %s\n", uniInfo.AgentCircuitID) |
| 2519 | fmt.Printf(" OnuUniId: %d\n", uniInfo.OnuUniId) |
| 2520 | } |
| 2521 | } |
| 2522 | } |
| 2523 | |
| Akash Reddy Kankanala | c001463 | 2025-05-21 17:12:20 +0530 | [diff] [blame] | 2524 | func (options *GetPonPortStats) Execute(args []string) error { |
| 2525 | conn, err := NewConnection() |
| 2526 | if err != nil { |
| 2527 | return err |
| 2528 | } |
| 2529 | defer conn.Close() |
| 2530 | client := extension.NewExtensionClient(conn) |
| 2531 | |
| 2532 | singleGetValReq := extension.SingleGetValueRequest{ |
| 2533 | TargetId: string(options.Args.Id), |
| 2534 | Request: &extension.GetValueRequest{ |
| 2535 | Request: &extension.GetValueRequest_OltPonStats{ |
| 2536 | OltPonStats: &extension.GetPonStatsRequest{ |
| 2537 | PortInfo: &extension.GetPonStatsRequest_PortLabel{ |
| 2538 | PortLabel: options.Args.PortLabel, |
| 2539 | }, |
| 2540 | }, |
| 2541 | }, |
| 2542 | }, |
| 2543 | } |
| 2544 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 2545 | defer cancel() |
| 2546 | rv, err := client.GetExtValue(ctx, &singleGetValReq) |
| 2547 | if err != nil { |
| 2548 | Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err)) |
| 2549 | return err |
| 2550 | } |
| 2551 | |
| 2552 | if rv.Response.Status != extension.GetValueResponse_OK { |
| 2553 | return fmt.Errorf("failed to get pon port stats %v", rv.Response.ErrReason.String()) |
| 2554 | } |
| 2555 | outputFormat := CharReplacer.Replace(options.Format) |
| 2556 | if outputFormat == "" { |
| 2557 | outputFormat = GetCommandOptionWithDefault("device-get-pon-stats", "format", DEFAULT_PON_PORT_STATS_FORMAT) |
| 2558 | } |
| 2559 | data := PortStats{ |
| 2560 | PonPort: rv.GetResponse().GetOltPonStatsResponse().GetPonPort(), |
| 2561 | PortStatistics: rv.GetResponse().GetOltPonStatsResponse().GetPortStatistics(), |
| 2562 | } |
| 2563 | result := CommandResult{ |
| 2564 | Format: format.Format(outputFormat), |
| 2565 | OutputAs: toOutputType(options.OutputAs), |
| 2566 | NameLimit: options.NameLimit, |
| 2567 | Data: data, |
| 2568 | } |
| 2569 | GenerateOutput(&result) |
| 2570 | return nil |
| 2571 | } |
| 2572 | |
| 2573 | func (options *GetNniPortStats) Execute(args []string) error { |
| 2574 | conn, err := NewConnection() |
| 2575 | if err != nil { |
| 2576 | return err |
| 2577 | } |
| 2578 | defer conn.Close() |
| 2579 | client := extension.NewExtensionClient(conn) |
| 2580 | |
| 2581 | singleGetValReq := extension.SingleGetValueRequest{ |
| 2582 | TargetId: string(options.Args.Id), |
| 2583 | Request: &extension.GetValueRequest{ |
| 2584 | Request: &extension.GetValueRequest_OltNniStats{ |
| 2585 | OltNniStats: &extension.GetNNIStatsRequest{ |
| 2586 | PortInfo: &extension.GetNNIStatsRequest_PortLabel{ |
| 2587 | PortLabel: options.Args.PortLabel, |
| 2588 | }, |
| 2589 | }, |
| 2590 | }, |
| 2591 | }, |
| 2592 | } |
| 2593 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 2594 | defer cancel() |
| 2595 | rv, err := client.GetExtValue(ctx, &singleGetValReq) |
| 2596 | if err != nil { |
| 2597 | Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err)) |
| 2598 | return err |
| 2599 | } |
| 2600 | |
| 2601 | if rv.Response.Status != extension.GetValueResponse_OK { |
| 2602 | return fmt.Errorf("failed to get nni port stats %v", rv.Response.ErrReason.String()) |
| 2603 | } |
| 2604 | outputFormat := CharReplacer.Replace(options.Format) |
| 2605 | if outputFormat == "" { |
| 2606 | outputFormat = GetCommandOptionWithDefault("device-get-nni-stats", "format", DEFAULT_NNI_PORT_STATS_FORMAT) |
| 2607 | } |
| 2608 | data := PortStats{ |
| 2609 | NniPort: rv.GetResponse().GetOltNniStatsResponse().GetNniPort(), |
| 2610 | PortStatistics: rv.GetResponse().GetOltNniStatsResponse().GetPortStatistics(), |
| 2611 | } |
| 2612 | result := CommandResult{ |
| 2613 | Format: format.Format(outputFormat), |
| 2614 | OutputAs: toOutputType(options.OutputAs), |
| 2615 | NameLimit: options.NameLimit, |
| 2616 | Data: data, |
| 2617 | } |
| 2618 | GenerateOutput(&result) |
| 2619 | return nil |
| 2620 | } |
| 2621 | |
| Himani Chawla | 553a139 | 2021-06-10 23:39:17 +0530 | [diff] [blame] | 2622 | func (options *GetOnuEthernetFrameExtendedPmCounters) Execute(args []string) error { |
| 2623 | conn, err := NewConnection() |
| 2624 | if err != nil { |
| 2625 | return err |
| 2626 | } |
| 2627 | defer conn.Close() |
| 2628 | client := extension.NewExtensionClient(conn) |
| Himani Chawla | 806aa89 | 2021-08-30 15:51:46 +0530 | [diff] [blame] | 2629 | var singleGetValReq extension.SingleGetValueRequest |
| Himani Chawla | 553a139 | 2021-06-10 23:39:17 +0530 | [diff] [blame] | 2630 | |
| Himani Chawla | 806aa89 | 2021-08-30 15:51:46 +0530 | [diff] [blame] | 2631 | if options.Args.UniIndex != nil { |
| 2632 | singleGetValReq = extension.SingleGetValueRequest{ |
| 2633 | TargetId: string(options.Args.Id), |
| 2634 | Request: &extension.GetValueRequest{ |
| 2635 | Request: &extension.GetValueRequest_OnuInfo{ |
| 2636 | OnuInfo: &extension.GetOmciEthernetFrameExtendedPmRequest{ |
| 2637 | OnuDeviceId: string(options.Args.Id), |
| 2638 | Reset_: options.Reset, |
| 2639 | IsUniIndex: &extension.GetOmciEthernetFrameExtendedPmRequest_UniIndex{ |
| 2640 | UniIndex: *options.Args.UniIndex, |
| 2641 | }, |
| 2642 | }, |
| Himani Chawla | 553a139 | 2021-06-10 23:39:17 +0530 | [diff] [blame] | 2643 | }, |
| 2644 | }, |
| Himani Chawla | 806aa89 | 2021-08-30 15:51:46 +0530 | [diff] [blame] | 2645 | } |
| 2646 | } else { |
| 2647 | singleGetValReq = extension.SingleGetValueRequest{ |
| 2648 | TargetId: string(options.Args.Id), |
| 2649 | Request: &extension.GetValueRequest{ |
| 2650 | Request: &extension.GetValueRequest_OnuInfo{ |
| 2651 | OnuInfo: &extension.GetOmciEthernetFrameExtendedPmRequest{ |
| 2652 | OnuDeviceId: string(options.Args.Id), |
| 2653 | Reset_: options.Reset, |
| 2654 | }, |
| 2655 | }, |
| 2656 | }, |
| 2657 | } |
| Himani Chawla | 553a139 | 2021-06-10 23:39:17 +0530 | [diff] [blame] | 2658 | } |
| Himani Chawla | 806aa89 | 2021-08-30 15:51:46 +0530 | [diff] [blame] | 2659 | |
| Himani Chawla | 553a139 | 2021-06-10 23:39:17 +0530 | [diff] [blame] | 2660 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 2661 | defer cancel() |
| 2662 | rv, err := client.GetExtValue(ctx, &singleGetValReq) |
| 2663 | if err != nil { |
| 2664 | Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err)) |
| 2665 | return err |
| 2666 | } |
| 2667 | |
| 2668 | if rv.Response.Status != extension.GetValueResponse_OK { |
| 2669 | return fmt.Errorf("failed to get ethernet frame extended pm counters %v", rv.Response.ErrReason.String()) |
| 2670 | } |
| 2671 | outputFormat := CharReplacer.Replace(options.Format) |
| 2672 | data := buildOnuEthernetFrameExtendedPmOutputFormat(rv.GetResponse().GetOnuCounters()) |
| 2673 | if outputFormat == "" { |
| 2674 | outputFormat = GetCommandOptionWithDefault("device-get-onu-status", "format", DEFAULT_ETHERNET_FRAME_EXTENDED_PM_COUNTERS_FORMAT) |
| 2675 | } |
| Himani Chawla | 40acc12 | 2021-05-26 18:52:29 +0530 | [diff] [blame] | 2676 | result := CommandResult{ |
| 2677 | Format: format.Format(outputFormat), |
| 2678 | OutputAs: toOutputType(options.OutputAs), |
| 2679 | NameLimit: options.NameLimit, |
| 2680 | Data: data, |
| 2681 | } |
| 2682 | GenerateOutput(&result) |
| 2683 | return nil |
| 2684 | } |
| 2685 | |
| kesavand | 6d1131f | 2021-02-05 22:38:15 +0530 | [diff] [blame] | 2686 | func (options *UniStatus) Execute(args []string) error { |
| 2687 | conn, err := NewConnection() |
| 2688 | if err != nil { |
| 2689 | return err |
| 2690 | } |
| 2691 | defer conn.Close() |
| 2692 | client := extension.NewExtensionClient(conn) |
| 2693 | |
| 2694 | singleGetValReq := extension.SingleGetValueRequest{ |
| 2695 | TargetId: string(options.Args.Id), |
| 2696 | Request: &extension.GetValueRequest{ |
| 2697 | Request: &extension.GetValueRequest_UniInfo{ |
| 2698 | UniInfo: &extension.GetOnuUniInfoRequest{ |
| 2699 | UniIndex: options.Args.UniIndex, |
| 2700 | }, |
| 2701 | }, |
| 2702 | }, |
| 2703 | } |
| David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 2704 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| kesavand | 6d1131f | 2021-02-05 22:38:15 +0530 | [diff] [blame] | 2705 | defer cancel() |
| 2706 | rv, err := client.GetExtValue(ctx, &singleGetValReq) |
| 2707 | if err != nil { |
| 2708 | Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err)) |
| 2709 | return err |
| 2710 | } |
| 2711 | if rv.Response.Status != extension.GetValueResponse_OK { |
| 2712 | return fmt.Errorf("failed to get uni status %v", rv.Response.ErrReason.String()) |
| 2713 | } |
| 2714 | outputFormat := CharReplacer.Replace(options.Format) |
| 2715 | if outputFormat == "" { |
| 2716 | outputFormat = GetCommandOptionWithDefault("device-get-uni-status", "format", DEFAULT_DEVICE_GET_UNI_STATUS_FORMAT) |
| 2717 | } |
| 2718 | result := CommandResult{ |
| 2719 | Format: format.Format(outputFormat), |
| 2720 | OutputAs: toOutputType(options.OutputAs), |
| 2721 | NameLimit: options.NameLimit, |
| 2722 | Data: rv.GetResponse().GetUniInfo(), |
| 2723 | } |
| 2724 | GenerateOutput(&result) |
| 2725 | return nil |
| 2726 | } |
| 2727 | |
| Girish Gowdra | 4f5ce7c | 2021-04-29 18:53:21 -0700 | [diff] [blame] | 2728 | func (options *OnuPonOpticalInfo) Execute(args []string) error { |
| 2729 | conn, err := NewConnection() |
| 2730 | if err != nil { |
| 2731 | return err |
| 2732 | } |
| 2733 | defer conn.Close() |
| 2734 | client := extension.NewExtensionClient(conn) |
| 2735 | |
| 2736 | singleGetValReq := extension.SingleGetValueRequest{ |
| 2737 | TargetId: string(options.Args.Id), |
| 2738 | Request: &extension.GetValueRequest{ |
| 2739 | Request: &extension.GetValueRequest_OnuOpticalInfo{ |
| 2740 | OnuOpticalInfo: &extension.GetOnuPonOpticalInfo{}, |
| 2741 | }, |
| 2742 | }, |
| 2743 | } |
| 2744 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 2745 | defer cancel() |
| 2746 | rv, err := client.GetExtValue(ctx, &singleGetValReq) |
| 2747 | if err != nil { |
| 2748 | Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err)) |
| 2749 | return err |
| 2750 | } |
| 2751 | if rv.Response.Status != extension.GetValueResponse_OK { |
| 2752 | return fmt.Errorf("failed to get onu pon optical info %v", rv.Response.ErrReason.String()) |
| 2753 | } |
| 2754 | outputFormat := CharReplacer.Replace(options.Format) |
| 2755 | if outputFormat == "" { |
| 2756 | outputFormat = GetCommandOptionWithDefault("device-get-onu-pon-optical-info", "format", DEFAULT_ONU_PON_OPTICAL_INFO_STATUS_FORMAT) |
| 2757 | } |
| 2758 | result := CommandResult{ |
| 2759 | Format: format.Format(outputFormat), |
| 2760 | OutputAs: toOutputType(options.OutputAs), |
| 2761 | NameLimit: options.NameLimit, |
| 2762 | Data: rv.GetResponse().GetOnuOpticalInfo(), |
| 2763 | } |
| 2764 | GenerateOutput(&result) |
| 2765 | return nil |
| 2766 | } |
| 2767 | |
| Gamze Abaka | c857a46 | 2021-05-26 13:45:54 +0000 | [diff] [blame] | 2768 | func (options *RxPower) Execute(args []string) error { |
| 2769 | conn, err := NewConnection() |
| 2770 | if err != nil { |
| 2771 | return err |
| 2772 | } |
| 2773 | defer conn.Close() |
| 2774 | client := extension.NewExtensionClient(conn) |
| 2775 | |
| 2776 | singleGetValReq := extension.SingleGetValueRequest{ |
| 2777 | TargetId: string(options.Args.Id), |
| 2778 | Request: &extension.GetValueRequest{ |
| 2779 | Request: &extension.GetValueRequest_RxPower{ |
| 2780 | RxPower: &extension.GetRxPowerRequest{ |
| 2781 | IntfId: options.Args.PortNo, |
| 2782 | OnuId: options.Args.OnuNo, |
| 2783 | }, |
| 2784 | }, |
| 2785 | }, |
| 2786 | } |
| 2787 | |
| 2788 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 2789 | defer cancel() |
| 2790 | rv, err := client.GetExtValue(ctx, &singleGetValReq) |
| 2791 | if err != nil { |
| 2792 | Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err)) |
| 2793 | return err |
| 2794 | } |
| 2795 | if rv.Response.Status != extension.GetValueResponse_OK { |
| 2796 | return fmt.Errorf("failed to get rx power %v", rv.Response.ErrReason.String()) |
| 2797 | } |
| 2798 | outputFormat := CharReplacer.Replace(options.Format) |
| 2799 | if outputFormat == "" { |
| 2800 | outputFormat = GetCommandOptionWithDefault("device-get-rx-power", "format", DEFAULT_RX_POWER_STATUS_FORMAT) |
| 2801 | } |
| 2802 | result := CommandResult{ |
| 2803 | Format: format.Format(outputFormat), |
| 2804 | OutputAs: toOutputType(options.OutputAs), |
| 2805 | NameLimit: options.NameLimit, |
| 2806 | Data: rv.GetResponse().GetRxPower(), |
| 2807 | } |
| 2808 | GenerateOutput(&result) |
| 2809 | return nil |
| 2810 | } |
| 2811 | |
| Dinesh Belwalkar | c9aa6d8 | 2020-03-04 15:22:17 -0800 | [diff] [blame] | 2812 | /*Device get Onu Distance */ |
| 2813 | func (options *DeviceGetExtValue) Execute(args []string) error { |
| 2814 | conn, err := NewConnection() |
| 2815 | if err != nil { |
| 2816 | return err |
| 2817 | } |
| 2818 | defer conn.Close() |
| 2819 | |
| Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 2820 | client := voltha.NewVolthaServiceClient(conn) |
| 2821 | |
| khenaidoo | 080ce88 | 2021-10-19 17:35:08 -0400 | [diff] [blame] | 2822 | valueflag, okay := extension.ValueType_Type_value[string(options.Args.Valueflag)] |
| Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 2823 | if !okay { |
| 2824 | Error.Printf("Unknown valueflag %s\n", options.Args.Valueflag) |
| Dinesh Belwalkar | c9aa6d8 | 2020-03-04 15:22:17 -0800 | [diff] [blame] | 2825 | } |
| 2826 | |
| khenaidoo | 080ce88 | 2021-10-19 17:35:08 -0400 | [diff] [blame] | 2827 | val := extension.ValueSpecifier{Id: string(options.Args.Id), Value: extension.ValueType_Type(valueflag)} |
| Dinesh Belwalkar | c9aa6d8 | 2020-03-04 15:22:17 -0800 | [diff] [blame] | 2828 | |
| David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 2829 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| Dinesh Belwalkar | c9aa6d8 | 2020-03-04 15:22:17 -0800 | [diff] [blame] | 2830 | defer cancel() |
| 2831 | |
| Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 2832 | rv, err := client.GetExtValue(ctx, &val) |
| Dinesh Belwalkar | c9aa6d8 | 2020-03-04 15:22:17 -0800 | [diff] [blame] | 2833 | if err != nil { |
| 2834 | Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err)) |
| 2835 | return err |
| Dinesh Belwalkar | c9aa6d8 | 2020-03-04 15:22:17 -0800 | [diff] [blame] | 2836 | } |
| 2837 | |
| Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 2838 | var rows []ReturnValueRow |
| khenaidoo | 080ce88 | 2021-10-19 17:35:08 -0400 | [diff] [blame] | 2839 | for name, num := range extension.ValueType_Type_value { |
| Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 2840 | if num == 0 { |
| 2841 | // EMPTY is not a real value |
| 2842 | continue |
| 2843 | } |
| 2844 | if (rv.Error & uint32(num)) != 0 { |
| 2845 | row := ReturnValueRow{Name: name, Result: "Error"} |
| 2846 | rows = append(rows, row) |
| 2847 | } |
| 2848 | if (rv.Unsupported & uint32(num)) != 0 { |
| 2849 | row := ReturnValueRow{Name: name, Result: "Unsupported"} |
| 2850 | rows = append(rows, row) |
| 2851 | } |
| 2852 | if (rv.Set & uint32(num)) != 0 { |
| 2853 | switch name { |
| 2854 | case "DISTANCE": |
| 2855 | row := ReturnValueRow{Name: name, Result: rv.Distance} |
| 2856 | rows = append(rows, row) |
| 2857 | default: |
| 2858 | row := ReturnValueRow{Name: name, Result: "Unimplemented-in-voltctl"} |
| 2859 | rows = append(rows, row) |
| 2860 | } |
| 2861 | } |
| Dinesh Belwalkar | c9aa6d8 | 2020-03-04 15:22:17 -0800 | [diff] [blame] | 2862 | } |
| 2863 | |
| Dinesh Belwalkar | c9aa6d8 | 2020-03-04 15:22:17 -0800 | [diff] [blame] | 2864 | outputFormat := CharReplacer.Replace(options.Format) |
| 2865 | if outputFormat == "" { |
| 2866 | outputFormat = GetCommandOptionWithDefault("device-value-get", "format", DEFAULT_DEVICE_VALUE_GET_FORMAT) |
| 2867 | } |
| 2868 | |
| 2869 | result := CommandResult{ |
| 2870 | Format: format.Format(outputFormat), |
| 2871 | OutputAs: toOutputType(options.OutputAs), |
| 2872 | NameLimit: options.NameLimit, |
| Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 2873 | Data: rows, |
| Dinesh Belwalkar | c9aa6d8 | 2020-03-04 15:22:17 -0800 | [diff] [blame] | 2874 | } |
| 2875 | GenerateOutput(&result) |
| 2876 | return nil |
| 2877 | } |
| serkantul | 3d22fc7 | 2022-09-14 12:22:56 +0300 | [diff] [blame] | 2878 | |
| 2879 | /*Device get Onu OMCI TX RX Stats */ |
| 2880 | func (options *OnuOmciTxRxStats) Execute(args []string) error { |
| 2881 | conn, err := NewConnection() |
| 2882 | if err != nil { |
| 2883 | return err |
| 2884 | } |
| 2885 | defer conn.Close() |
| 2886 | client := extension.NewExtensionClient(conn) |
| 2887 | |
| 2888 | singleGetValReq := extension.SingleGetValueRequest{ |
| 2889 | TargetId: string(options.Args.Id), |
| 2890 | Request: &extension.GetValueRequest{ |
| 2891 | Request: &extension.GetValueRequest_OnuOmciStats{ |
| 2892 | OnuOmciStats: &extension.GetOnuOmciTxRxStatsRequest{}, |
| 2893 | }, |
| 2894 | }, |
| 2895 | } |
| 2896 | |
| 2897 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 2898 | defer cancel() |
| 2899 | rv, err := client.GetExtValue(ctx, &singleGetValReq) |
| 2900 | if err != nil { |
| 2901 | Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err)) |
| 2902 | return err |
| 2903 | } |
| 2904 | |
| 2905 | if rv.Response.Status != extension.GetValueResponse_OK { |
| 2906 | return fmt.Errorf("failed to get onu omci tx rx stats %v", rv.Response.ErrReason.String()) |
| 2907 | } |
| 2908 | outputFormat := CharReplacer.Replace(options.Format) |
| 2909 | if outputFormat == "" { |
| 2910 | outputFormat = GetCommandOptionWithDefault("device-get-onu-omci-tx-rx-stats", "format", DEFAULT_ONU_OMCI_TX_RX_STATS_FORMAT) |
| 2911 | } |
| 2912 | result := CommandResult{ |
| 2913 | Format: format.Format(outputFormat), |
| 2914 | OutputAs: toOutputType(options.OutputAs), |
| 2915 | NameLimit: options.NameLimit, |
| 2916 | Data: rv.GetResponse().GetOnuOmciStats(), |
| 2917 | } |
| 2918 | GenerateOutput(&result) |
| 2919 | return nil |
| 2920 | } |
| praneeth nalmas | 1dd094c | 2022-12-22 14:15:13 +0530 | [diff] [blame] | 2921 | |
| 2922 | /*Device get Onu Active Alarms */ |
| 2923 | func (options *GetOnuOmciActiveAlarms) Execute(args []string) error { |
| 2924 | conn, err := NewConnection() |
| 2925 | if err != nil { |
| 2926 | return err |
| 2927 | } |
| 2928 | defer conn.Close() |
| 2929 | client := extension.NewExtensionClient(conn) |
| 2930 | |
| 2931 | singleGetValReq := extension.SingleGetValueRequest{ |
| 2932 | TargetId: string(options.Args.Id), |
| 2933 | Request: &extension.GetValueRequest{ |
| 2934 | Request: &extension.GetValueRequest_OnuActiveAlarms{ |
| 2935 | OnuActiveAlarms: &extension.GetOnuOmciActiveAlarmsRequest{}, |
| 2936 | }, |
| 2937 | }, |
| 2938 | } |
| 2939 | Info.Printf("Getting omci_active_alarms for device Id %s\n", options.Args.Id) |
| 2940 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 2941 | defer cancel() |
| 2942 | rv, err := client.GetExtValue(ctx, &singleGetValReq) |
| 2943 | if err != nil { |
| 2944 | Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err)) |
| 2945 | return err |
| 2946 | } |
| 2947 | |
| 2948 | if rv.Response.Status != extension.GetValueResponse_OK { |
| 2949 | return fmt.Errorf("failed to get onu omci active alarms list %v", rv.Response.ErrReason.String()) |
| 2950 | } |
| 2951 | outputFormat := CharReplacer.Replace(options.Format) |
| 2952 | if outputFormat == "" { |
| 2953 | outputFormat = GetCommandOptionWithDefault("device-get-onu-omci-active-alarms", "format", DEFAULT_DEVICE_ALARMS_FORMAT) |
| 2954 | } |
| 2955 | |
| 2956 | orderBy := options.OrderBy |
| 2957 | if orderBy == "" { |
| 2958 | orderBy = GetCommandOptionWithDefault("device-list", "order", DEFAULT_DEVICE_ALARMS_ORDER) |
| 2959 | } |
| 2960 | |
| 2961 | result := CommandResult{ |
| 2962 | Format: format.Format(outputFormat), |
| 2963 | OutputAs: toOutputType(options.OutputAs), |
| 2964 | OrderBy: orderBy, |
| 2965 | NameLimit: options.NameLimit, |
| 2966 | Data: rv.GetResponse().GetOnuActiveAlarms().GetActiveAlarms(), |
| 2967 | } |
| 2968 | GenerateOutput(&result) |
| 2969 | return nil |
| 2970 | } |
| praneeth nalmas | 39c71ad | 2023-09-27 18:29:04 +0530 | [diff] [blame] | 2971 | |
| Akash Soni | 66db963 | 2024-04-15 09:05:15 +0530 | [diff] [blame] | 2972 | /*Device get Onu Active Alarms */ |
| 2973 | func (options *GetOnuDistance) Execute(args []string) error { |
| 2974 | conn, err := NewConnection() |
| 2975 | if err != nil { |
| 2976 | return err |
| 2977 | } |
| 2978 | defer conn.Close() |
| 2979 | client := extension.NewExtensionClient(conn) |
| 2980 | |
| 2981 | singleGetValReq := extension.SingleGetValueRequest{ |
| 2982 | TargetId: string(options.Args.Id), |
| 2983 | Request: &extension.GetValueRequest{ |
| 2984 | Request: &extension.GetValueRequest_Distance{ |
| 2985 | Distance: &extension.GetDistanceRequest{ |
| 2986 | OnuDeviceId: string(options.Args.OnuId), |
| 2987 | }, |
| 2988 | }, |
| 2989 | }, |
| 2990 | } |
| 2991 | Info.Printf("Getting onu distance for device Id %s\n", options.Args.Id) |
| 2992 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 2993 | defer cancel() |
| 2994 | rv, err := client.GetExtValue(ctx, &singleGetValReq) |
| 2995 | if err != nil { |
| 2996 | Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err)) |
| 2997 | return err |
| 2998 | } |
| 2999 | |
| 3000 | if rv.Response.Status != extension.GetValueResponse_OK { |
| 3001 | return fmt.Errorf("failed to get onu distance stats %v", rv.Response.ErrReason.String()) |
| 3002 | } |
| 3003 | outputFormat := CharReplacer.Replace(options.Format) |
| 3004 | if outputFormat == "" { |
| 3005 | outputFormat = GetCommandOptionWithDefault("get-onu-distance", "format", DEFAULT_ONU_DISTANCE_FORMAT) |
| 3006 | } |
| 3007 | |
| 3008 | result := CommandResult{ |
| 3009 | Format: format.Format(outputFormat), |
| 3010 | OutputAs: toOutputType(options.OutputAs), |
| 3011 | NameLimit: options.NameLimit, |
| 3012 | Data: rv.GetResponse().GetDistance().GetDistance(), |
| 3013 | } |
| 3014 | fmt.Println("onu distance : ", rv) |
| 3015 | GenerateOutput(&result) |
| 3016 | return nil |
| 3017 | } |
| 3018 | |
| praneeth nalmas | 39c71ad | 2023-09-27 18:29:04 +0530 | [diff] [blame] | 3019 | func (options *PonRxPower) Execute(args []string) error { |
| 3020 | conn, err := NewConnection() |
| 3021 | if err != nil { |
| 3022 | return err |
| 3023 | } |
| 3024 | defer conn.Close() |
| 3025 | client := extension.NewExtensionClient(conn) |
| 3026 | |
| 3027 | singleGetValReq := extension.SingleGetValueRequest{ |
| 3028 | TargetId: string(options.Args.Id), |
| 3029 | Request: &extension.GetValueRequest{ |
| 3030 | Request: &extension.GetValueRequest_OltRxPower{ |
| 3031 | OltRxPower: &extension.GetOltRxPowerRequest{ |
| 3032 | PortLabel: options.Args.PortLabel, |
| 3033 | OnuSn: options.Args.SerialNo, |
| 3034 | }, |
| 3035 | }, |
| 3036 | }, |
| 3037 | } |
| 3038 | |
| 3039 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 3040 | defer cancel() |
| 3041 | rv, err := client.GetExtValue(ctx, &singleGetValReq) |
| 3042 | if err != nil { |
| 3043 | Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err)) |
| 3044 | return err |
| 3045 | } |
| 3046 | if rv.Response.Status != extension.GetValueResponse_OK { |
| 3047 | return fmt.Errorf("failed to get rx power %v", rv.Response.ErrReason.String()) |
| 3048 | } |
| 3049 | outputFormat := CharReplacer.Replace(options.Format) |
| 3050 | if outputFormat == "" { |
| 3051 | outputFormat = GetCommandOptionWithDefault("device-get-pon-rx-power", "format", DEFAULT_PON_RX_POWER_STATUS_FORMAT) |
| 3052 | } |
| 3053 | result := CommandResult{ |
| 3054 | Format: format.Format(outputFormat), |
| 3055 | OutputAs: toOutputType(options.OutputAs), |
| 3056 | NameLimit: options.NameLimit, |
| 3057 | Data: rv.GetResponse().GetOltRxPower().GetRxPower(), |
| 3058 | } |
| 3059 | GenerateOutput(&result) |
| 3060 | return nil |
| 3061 | } |
| Akash Reddy Kankanala | c001463 | 2025-05-21 17:12:20 +0530 | [diff] [blame] | 3062 | |
| 3063 | func (options *GetOnuGEMStats) Execute(args []string) error { |
| 3064 | |
| 3065 | conn, err := NewConnection() |
| 3066 | if err != nil { |
| 3067 | return err |
| 3068 | } |
| 3069 | defer conn.Close() |
| 3070 | client := extension.NewExtensionClient(conn) |
| 3071 | singleGetValReq := extension.SingleGetValueRequest{ |
| 3072 | TargetId: string(options.Args.Id), |
| 3073 | Request: &extension.GetValueRequest{ |
| 3074 | Request: &extension.GetValueRequest_OnuAllocGemStats{ |
| 3075 | OnuAllocGemStats: &extension.GetOnuAllocGemHistoryRequest{}, |
| 3076 | }, |
| 3077 | }, |
| 3078 | } |
| 3079 | |
| 3080 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 3081 | defer cancel() |
| 3082 | |
| 3083 | rv, err := client.GetExtValue(ctx, &singleGetValReq) |
| 3084 | |
| 3085 | if err != nil { |
| 3086 | Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err)) |
| 3087 | return err |
| 3088 | } |
| 3089 | |
| 3090 | if rv.Response.Status != extension.GetValueResponse_OK { |
| 3091 | return fmt.Errorf("failed to get gem port response %v", rv.Response.ErrReason.String()) |
| 3092 | } |
| 3093 | outputFormat := CharReplacer.Replace(options.Format) |
| 3094 | if outputFormat == "" { |
| 3095 | outputFormat = GetCommandOptionWithDefault("device-get-gem-port", "format", DEFAULT_DEVICE_VALUE_GEM_PORT_FORMAT) |
| 3096 | } |
| 3097 | onugemhistoryresponse := rv.GetResponse().GetOnuAllocGemStatsResponse() |
| 3098 | for _, OnuallocGemHistoryData := range onugemhistoryresponse.OnuAllocGemHistoryData { |
| 3099 | data := onugemstats{} |
| 3100 | data.AllocId = OnuallocGemHistoryData.OnuAllocIdInfo.AllocId |
| 3101 | data.AllocRxBytes = OnuallocGemHistoryData.OnuAllocIdInfo.RxBytes |
| 3102 | for _, gemStatsInfo := range OnuallocGemHistoryData.GemPortInfo { |
| 3103 | data.GemHistoryStats = append(data.GemHistoryStats, gemHistoryStats{ |
| 3104 | GemId: gemStatsInfo.GemId, |
| 3105 | TransmittedGEMFrames: gemStatsInfo.TransmittedGEMFrames, |
| 3106 | ReceivedGEMFrames: gemStatsInfo.ReceivedGEMFrames, |
| 3107 | ReceivedPayloadBytes: gemStatsInfo.ReceivedPayloadBytes, |
| 3108 | TransmittedPayloadBytes: gemStatsInfo.TransmittedPayloadBytes, |
| 3109 | EncryptionKeyErrors: gemStatsInfo.EncryptionKeyErrors, |
| 3110 | }) |
| 3111 | } |
| 3112 | result := CommandResult{ |
| 3113 | Format: format.Format(outputFormat), |
| 3114 | OutputAs: toOutputType(options.OutputAs), |
| 3115 | NameLimit: options.NameLimit, |
| 3116 | Data: &data, |
| 3117 | } |
| 3118 | GenerateOutput(&result) |
| 3119 | } |
| 3120 | return nil |
| 3121 | |
| 3122 | } |
| 3123 | |
| Akash Reddy Kankanala | 6965c65 | 2025-10-15 23:30:16 +0530 | [diff] [blame^] | 3124 | func (options *GetOnuFecHistory) Execute(args []string) error { |
| 3125 | conn, err := NewConnection() |
| 3126 | if err != nil { |
| 3127 | return err |
| 3128 | } |
| 3129 | defer conn.Close() |
| 3130 | client := extension.NewExtensionClient(conn) |
| 3131 | singleGetValReq := extension.SingleGetValueRequest{ |
| 3132 | TargetId: string(options.Args.Id), |
| 3133 | Request: &extension.GetValueRequest{ |
| 3134 | Request: &extension.GetValueRequest_FecHistory{ |
| 3135 | FecHistory: &extension.GetOnuFecHistory{}, |
| 3136 | }, |
| 3137 | }, |
| 3138 | } |
| 3139 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 3140 | defer cancel() |
| 3141 | rv, err := client.GetExtValue(ctx, &singleGetValReq) |
| 3142 | if err != nil { |
| 3143 | Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err)) |
| 3144 | return err |
| 3145 | } |
| 3146 | if rv.Response.Status != extension.GetValueResponse_OK { |
| 3147 | return fmt.Errorf("Failed to get onu FEC history stats from ONT %v", rv.Response.ErrReason.String()) |
| 3148 | } |
| 3149 | |
| 3150 | outputFormat := CharReplacer.Replace(options.Format) |
| 3151 | if outputFormat == "" { |
| 3152 | outputFormat = GetCommandOptionWithDefault("device-get-onu-fec-History", "format", DEFAULT_ONU_FEC_HISTORY_FORMAT) |
| 3153 | } |
| 3154 | result := CommandResult{ |
| 3155 | Format: format.Format(outputFormat), |
| 3156 | OutputAs: toOutputType(options.OutputAs), |
| 3157 | NameLimit: options.NameLimit, |
| 3158 | Data: rv.GetResponse().GetFecHistory(), |
| 3159 | } |
| 3160 | GenerateOutput(&result) |
| 3161 | return nil |
| 3162 | |
| 3163 | } |
| 3164 | |
| Akash Reddy Kankanala | c001463 | 2025-05-21 17:12:20 +0530 | [diff] [blame] | 3165 | func (options *GetOnuAllocGemStatsFromOlt) Execute(args []string) error { |
| 3166 | conn, err := NewConnection() |
| 3167 | if err != nil { |
| 3168 | return err |
| 3169 | } |
| 3170 | defer conn.Close() |
| 3171 | client := extension.NewExtensionClient(conn) |
| 3172 | |
| 3173 | singleGetValReq := extension.SingleGetValueRequest{ |
| 3174 | TargetId: string(options.Args.Id), |
| 3175 | Request: &extension.GetValueRequest{ |
| 3176 | Request: &extension.GetValueRequest_OnuStatsFromOlt{ |
| 3177 | OnuStatsFromOlt: &extension.GetOnuStatsFromOltRequest{}, |
| 3178 | }, |
| 3179 | }, |
| 3180 | } |
| 3181 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 3182 | defer cancel() |
| 3183 | rv, err := client.GetExtValue(ctx, &singleGetValReq) |
| 3184 | if err != nil { |
| 3185 | Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err)) |
| 3186 | return err |
| 3187 | } |
| 3188 | |
| 3189 | if rv.Response.Status != extension.GetValueResponse_OK { |
| 3190 | return fmt.Errorf("failed to get onu alloc gem stats from olt %v", rv.Response.ErrReason.String()) |
| 3191 | } |
| 3192 | outputFormat := CharReplacer.Replace(options.Format) |
| 3193 | if outputFormat == "" { |
| 3194 | outputFormat = GetCommandOptionWithDefault("device-get-onu-status", "format", DEFAULT_ONU_STATS_FROM_OLT_FORMAT) |
| 3195 | } |
| 3196 | |
| 3197 | onuAllocGemStatsResponse := rv.GetResponse().GetOnuStatsFromOltResponse() |
| 3198 | |
| 3199 | for _, allocGemStatsInfo := range onuAllocGemStatsResponse.AllocGemStatsInfo { |
| 3200 | data := AllocGemStatsFromOlt{} |
| 3201 | data.AllocId = allocGemStatsInfo.AllocIdInfo.AllocId |
| 3202 | data.AllocRxBytes = allocGemStatsInfo.AllocIdInfo.RxBytes |
| 3203 | for _, gemStatsInfo := range allocGemStatsInfo.GemPortInfo { |
| 3204 | data.GemPortStats = append(data.GemPortStats, GemPortStatsFromOlt{ |
| 3205 | GemId: gemStatsInfo.GemId, |
| 3206 | RxBytes: gemStatsInfo.RxBytes, |
| 3207 | RxPackets: gemStatsInfo.RxPackets, |
| 3208 | TxBytes: gemStatsInfo.TxBytes, |
| 3209 | TxPackets: gemStatsInfo.TxPackets, |
| 3210 | }) |
| 3211 | } |
| 3212 | result := CommandResult{ |
| 3213 | Format: format.Format(outputFormat), |
| 3214 | OutputAs: toOutputType(options.OutputAs), |
| 3215 | NameLimit: options.NameLimit, |
| 3216 | Data: &data, |
| 3217 | } |
| 3218 | GenerateOutput(&result) |
| 3219 | } |
| 3220 | |
| 3221 | return nil |
| 3222 | } |
| mgouda | 35b90e6 | 2025-07-16 14:58:29 +0530 | [diff] [blame] | 3223 | |
| 3224 | func (options *DisableOnuDevice) Execute(args []string) error { |
| 3225 | conn, err := NewConnection() |
| 3226 | if err != nil { |
| 3227 | return err |
| 3228 | } |
| 3229 | defer conn.Close() |
| 3230 | |
| 3231 | client := voltha.NewVolthaServiceClient(conn) |
| 3232 | |
| 3233 | var lastErr error |
| 3234 | for _, i := range options.Args.Ids { |
| 3235 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 3236 | defer cancel() |
| 3237 | |
| 3238 | id := voltha.ID{Id: string(i)} |
| 3239 | |
| 3240 | _, err := client.DisableOnuDevice(ctx, &id) |
| 3241 | if err != nil { |
| 3242 | Error.Printf("Error while disabling the onu serial number'%s': %s\n", i, err) |
| 3243 | lastErr = err |
| 3244 | continue |
| 3245 | } |
| 3246 | fmt.Printf("%s\n", i) |
| 3247 | } |
| 3248 | |
| 3249 | if lastErr != nil { |
| 3250 | return NoReportErr |
| 3251 | } |
| 3252 | return nil |
| 3253 | } |
| 3254 | |
| 3255 | func (options *EnableOnuDevice) Execute(args []string) error { |
| 3256 | conn, err := NewConnection() |
| 3257 | if err != nil { |
| 3258 | return err |
| 3259 | } |
| 3260 | defer conn.Close() |
| 3261 | |
| 3262 | client := voltha.NewVolthaServiceClient(conn) |
| 3263 | |
| 3264 | var lastErr error |
| 3265 | for _, i := range options.Args.Ids { |
| 3266 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 3267 | defer cancel() |
| 3268 | |
| 3269 | id := voltha.ID{Id: string(i)} |
| 3270 | |
| 3271 | _, err := client.EnableOnuDevice(ctx, &id) |
| 3272 | if err != nil { |
| 3273 | Error.Printf("Error while enabling the onu serial number'%s': %s\n", i, err) |
| 3274 | lastErr = err |
| 3275 | continue |
| 3276 | } |
| 3277 | fmt.Printf("%s\n", i) |
| 3278 | } |
| 3279 | |
| 3280 | if lastErr != nil { |
| 3281 | return NoReportErr |
| 3282 | } |
| 3283 | return nil |
| 3284 | } |
| 3285 | |
| 3286 | func (options *DisableOnuSerialNumber) Execute(args []string) error { |
| 3287 | conn, err := NewConnection() |
| 3288 | if err != nil { |
| 3289 | return err |
| 3290 | } |
| 3291 | defer conn.Close() |
| 3292 | |
| 3293 | client := voltha.NewVolthaServiceClient(conn) |
| 3294 | |
| 3295 | id := common.ID{Id: string(options.Args.OltDeviceId)} |
| 3296 | port := voltha.Port{PortNo: uint32(options.Args.Port)} |
| 3297 | |
| 3298 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 3299 | defer cancel() |
| 3300 | |
| 3301 | req := &voltha.OnuSerialNumberOnOLTPon{ |
| 3302 | OltDeviceId: &id, |
| 3303 | SerialNumber: options.Args.SerialNumber, |
| 3304 | Port: &port, |
| 3305 | } |
| 3306 | |
| 3307 | _, err = client.DisableOnuSerialNumber(ctx, req) |
| 3308 | if err != nil { |
| 3309 | Error.Printf("Error disabling ONU serial '%s' on OLT '%s': %v\n", options.Args.SerialNumber, options.Args.OltDeviceId, err) |
| 3310 | return err |
| 3311 | } |
| 3312 | fmt.Printf("Disabled ONU serial '%s' on OLT '%s'\n", options.Args.SerialNumber, options.Args.OltDeviceId) |
| 3313 | return nil |
| 3314 | } |
| 3315 | |
| 3316 | func (options *EnableOnuSerialNumber) Execute(args []string) error { |
| 3317 | conn, err := NewConnection() |
| 3318 | if err != nil { |
| 3319 | return err |
| 3320 | } |
| 3321 | defer conn.Close() |
| 3322 | |
| 3323 | client := voltha.NewVolthaServiceClient(conn) |
| 3324 | |
| 3325 | id := common.ID{Id: string(options.Args.OltDeviceId)} |
| 3326 | port := voltha.Port{PortNo: uint32(options.Args.Port)} |
| 3327 | |
| 3328 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 3329 | defer cancel() |
| 3330 | |
| 3331 | req := &voltha.OnuSerialNumberOnOLTPon{ |
| 3332 | OltDeviceId: &id, |
| 3333 | SerialNumber: options.Args.SerialNumber, |
| 3334 | Port: &port, |
| 3335 | } |
| 3336 | |
| 3337 | _, err = client.EnableOnuSerialNumber(ctx, req) |
| 3338 | if err != nil { |
| 3339 | Error.Printf("Error enabling ONU serial '%s' on OLT '%s': %v\n", options.Args.SerialNumber, options.Args.OltDeviceId, err) |
| 3340 | return err |
| 3341 | } |
| 3342 | fmt.Printf("Enabled ONU serial '%s' on OLT '%s'\n", options.Args.SerialNumber, options.Args.OltDeviceId) |
| 3343 | return nil |
| 3344 | } |