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