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