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