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