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