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