Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 1 | /* |
Joey Armstrong | 11f5a57 | 2024-01-12 19:11:32 -0500 | [diff] [blame] | 2 | * Copyright 2019-2024 Open Networking Foundation (ONF) and the ONF Contributors |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 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 | */ |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 16 | |
Joey Armstrong | 3f0e242 | 2023-07-05 18:25:41 -0400 | [diff] [blame] | 17 | // Package core provides the utility for olt devices, flows and statistics |
Scott Baker | dbd960e | 2020-02-28 08:57:51 -0800 | [diff] [blame] | 18 | package core |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 19 | |
| 20 | import ( |
kesavand | 6212621 | 2021-01-12 04:56:06 -0500 | [diff] [blame] | 21 | "container/list" |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 22 | "context" |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 23 | "fmt" |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 24 | "sync" |
| 25 | "time" |
| 26 | |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 27 | plt "github.com/opencord/voltha-lib-go/v7/pkg/platform" |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 28 | rsrcMgr "github.com/opencord/voltha-openolt-adapter/internal/pkg/resourcemanager" |
| 29 | |
| 30 | "github.com/opencord/voltha-lib-go/v7/pkg/log" |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 31 | "github.com/opencord/voltha-openolt-adapter/internal/pkg/olterrors" |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 32 | "github.com/opencord/voltha-protos/v5/go/extension" |
| 33 | "github.com/opencord/voltha-protos/v5/go/openolt" |
| 34 | "github.com/opencord/voltha-protos/v5/go/voltha" |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 35 | ) |
| 36 | |
Gamze Abaka | fcbd6e7 | 2020-12-17 13:25:16 +0000 | [diff] [blame] | 37 | const ( |
| 38 | //NNIStats statType constant |
| 39 | NNIStats = "NNIStats" |
| 40 | //PONStats statType constant |
| 41 | PONStats = "PONStats" |
| 42 | //ONUStats statType constant |
| 43 | ONUStats = "ONUStats" |
| 44 | //GEMStats statType constant |
| 45 | GEMStats = "GEMStats" |
| 46 | |
| 47 | //RxBytes constant |
| 48 | RxBytes = "RxBytes" |
| 49 | //RxPackets constant |
| 50 | RxPackets = "RxPackets" |
| 51 | //TxBytes constant |
| 52 | TxBytes = "TxBytes" |
| 53 | //TxPackets constant |
| 54 | TxPackets = "TxPackets" |
| 55 | //FecCodewords constant |
| 56 | FecCodewords = "FecCodewords" |
| 57 | //BipUnits constant |
| 58 | BipUnits = "BipUnits" |
| 59 | //BipErrors constant |
| 60 | BipErrors = "BipErrors" |
| 61 | //RxPloamsNonIdle constant |
| 62 | RxPloamsNonIdle = "RxPloamsNonIdle" |
| 63 | //RxPloamsError constant |
| 64 | RxPloamsError = "RxPloamsError" |
| 65 | //RxOmci constant |
| 66 | RxOmci = "RxOmci" |
| 67 | //RxOmciPacketsCrcError constant |
| 68 | RxOmciPacketsCrcError = "RxOmciPacketsCrcError" |
| 69 | //PositiveDrift constant |
| 70 | PositiveDrift = "PositiveDrift" |
| 71 | //NegativeDrift constant |
| 72 | NegativeDrift = "NegativeDrift" |
| 73 | //DelimiterMissDetection constant |
| 74 | DelimiterMissDetection = "DelimiterMissDetection" |
| 75 | //FecCorrectedSymbols constant |
| 76 | FecCorrectedSymbols = "FecCorrectedSymbols" |
| 77 | //FecCodewordsCorrected constant |
| 78 | FecCodewordsCorrected = "FecCodewordsCorrected" |
| 79 | //fecCodewordsUncorrectable constant |
| 80 | fecCodewordsUncorrectable = "fec_codewords_uncorrectable" |
| 81 | //FecCorrectedUnits constant |
| 82 | FecCorrectedUnits = "FecCorrectedUnits" |
| 83 | //XGEMKeyErrors constant |
| 84 | XGEMKeyErrors = "XGEMKeyErrors" |
| 85 | //XGEMLoss constant |
| 86 | XGEMLoss = "XGEMLOSS" |
| 87 | //BerReported constant |
| 88 | BerReported = "BerReported" |
| 89 | //LcdgErrors constant |
| 90 | LcdgErrors = "LcdgErrors" |
| 91 | //RdiErrors constant |
| 92 | RdiErrors = "RdiErrors" |
Himani Chawla | 2c8ae0f | 2021-05-18 23:27:00 +0530 | [diff] [blame] | 93 | //Timestamp constant |
| 94 | Timestamp = "Timestamp" |
Gamze Abaka | fcbd6e7 | 2020-12-17 13:25:16 +0000 | [diff] [blame] | 95 | ) |
| 96 | |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 97 | var mutex = &sync.Mutex{} |
| 98 | |
Gamze Abaka | fcbd6e7 | 2020-12-17 13:25:16 +0000 | [diff] [blame] | 99 | var onuStats = make(chan *openolt.OnuStatistics, 100) |
| 100 | var gemStats = make(chan *openolt.GemPortStatistics, 100) |
| 101 | |
Joey Armstrong | 3f0e242 | 2023-07-05 18:25:41 -0400 | [diff] [blame] | 102 | // statRegInfo is used to register for notifications |
| 103 | // on receiving port stats and flow stats indication |
kesavand | 6212621 | 2021-01-12 04:56:06 -0500 | [diff] [blame] | 104 | type statRegInfo struct { |
| 105 | chn chan bool |
| 106 | portNo uint32 |
| 107 | portType extension.GetOltPortCounters_PortType |
| 108 | } |
| 109 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 110 | // PonPort representation |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 111 | type PonPort struct { |
| 112 | /* |
| 113 | This is a highly reduced version taken from the adtran pon_port. |
| 114 | TODO: Extend for use in the openolt adapter set. |
| 115 | */ |
| 116 | /* MAX_ONUS_SUPPORTED = 256 |
| 117 | DEFAULT_ENABLED = False |
| 118 | MAX_DEPLOYMENT_RANGE = 25000 # Meters (OLT-PB maximum) |
| 119 | |
| 120 | _MCAST_ONU_ID = 253 |
| 121 | _MCAST_ALLOC_BASE = 0x500 |
| 122 | |
| 123 | _SUPPORTED_ACTIVATION_METHODS = ['autodiscovery'] # , 'autoactivate'] |
| 124 | _SUPPORTED_AUTHENTICATION_METHODS = ['serial-number'] |
| 125 | */ |
| 126 | PONID uint32 |
| 127 | DeviceID string |
| 128 | IntfID uint32 |
| 129 | PortNum uint32 |
| 130 | PortID uint32 |
| 131 | Label string |
| 132 | ONUs map[uint32]interface{} |
| 133 | ONUsByID map[uint32]interface{} |
| 134 | |
| 135 | RxBytes uint64 |
| 136 | RxPackets uint64 |
Dileep Kuchhangi | 52cfbe1 | 2020-01-15 20:16:21 +0000 | [diff] [blame] | 137 | RxUcastPackets uint64 |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 138 | RxMcastPackets uint64 |
| 139 | RxBcastPackets uint64 |
| 140 | RxErrorPackets uint64 |
| 141 | TxBytes uint64 |
| 142 | TxPackets uint64 |
| 143 | TxUcastPackets uint64 |
| 144 | TxMcastPackets uint64 |
| 145 | TxBcastPackets uint64 |
| 146 | TxErrorPackets uint64 |
Dileep Kuchhangi | 52cfbe1 | 2020-01-15 20:16:21 +0000 | [diff] [blame] | 147 | RxCrcErrors uint64 |
| 148 | BipErrors uint64 |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 149 | } |
| 150 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 151 | // NewPONPort returns a new instance of PonPort initialized with given PONID, DeviceID, IntfID and PortNum |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 152 | func NewPONPort(PONID uint32, DeviceID string, IntfID uint32, PortNum uint32) *PonPort { |
| 153 | |
| 154 | var PON PonPort |
| 155 | |
| 156 | PON.PONID = PONID |
| 157 | PON.DeviceID = DeviceID |
| 158 | PON.IntfID = IntfID |
| 159 | PON.PortNum = PortNum |
| 160 | PON.PortID = 0 |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 161 | PON.Label = fmt.Sprintf("%s%d", "pon-", PONID) |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 162 | |
| 163 | PON.ONUs = make(map[uint32]interface{}) |
| 164 | PON.ONUsByID = make(map[uint32]interface{}) |
| 165 | |
| 166 | /* |
| 167 | Statistics taken from nni_port |
| 168 | self.intf_id = 0 #handled by getter |
| 169 | self.port_no = 0 #handled by getter |
| 170 | self.port_id = 0 #handled by getter |
| 171 | |
| 172 | Note: In the current implementation of the kpis coming from the BAL the stats are the |
| 173 | samne model for NNI and PON. |
| 174 | |
| 175 | TODO: Integrate additional kpis for the PON and other southbound port objecgts. |
| 176 | |
| 177 | */ |
| 178 | |
| 179 | PON.RxBytes = 0 |
| 180 | PON.RxPackets = 0 |
Dileep Kuchhangi | 52cfbe1 | 2020-01-15 20:16:21 +0000 | [diff] [blame] | 181 | PON.RxUcastPackets = 0 |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 182 | PON.RxMcastPackets = 0 |
| 183 | PON.RxBcastPackets = 0 |
| 184 | PON.RxErrorPackets = 0 |
| 185 | PON.TxBytes = 0 |
| 186 | PON.TxPackets = 0 |
| 187 | PON.TxUcastPackets = 0 |
| 188 | PON.TxMcastPackets = 0 |
| 189 | PON.TxBcastPackets = 0 |
| 190 | PON.TxErrorPackets = 0 |
Dileep Kuchhangi | 52cfbe1 | 2020-01-15 20:16:21 +0000 | [diff] [blame] | 191 | PON.RxCrcErrors = 0 |
| 192 | PON.BipErrors = 0 |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 193 | |
| 194 | /* def __str__(self): |
| 195 | return "PonPort-{}: Admin: {}, Oper: {}, OLT: {}".format(self._label, |
| 196 | self._admin_state, |
| 197 | self._oper_status, |
| 198 | self.olt) |
| 199 | */ |
| 200 | return &PON |
| 201 | } |
| 202 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 203 | // NniPort representation |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 204 | type NniPort struct { |
| 205 | /* |
| 206 | Northbound network port, often Ethernet-based |
| 207 | |
| 208 | This is a highly reduced version taken from the adtran nni_port code set |
| 209 | TODO: add functions to allow for port specific values and operations |
| 210 | */ |
| 211 | PortNum uint32 |
| 212 | Name string |
| 213 | LogicalPort uint32 |
| 214 | IntfID uint32 |
| 215 | |
| 216 | RxBytes uint64 |
| 217 | RxPackets uint64 |
Dileep Kuchhangi | 52cfbe1 | 2020-01-15 20:16:21 +0000 | [diff] [blame] | 218 | RxUcastPackets uint64 |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 219 | RxMcastPackets uint64 |
| 220 | RxBcastPackets uint64 |
| 221 | RxErrorPackets uint64 |
| 222 | TxBytes uint64 |
| 223 | TxPackets uint64 |
| 224 | TxUcastPackets uint64 |
| 225 | TxMcastPackets uint64 |
| 226 | TxBcastPackets uint64 |
| 227 | TxErrorPackets uint64 |
Dileep Kuchhangi | 52cfbe1 | 2020-01-15 20:16:21 +0000 | [diff] [blame] | 228 | RxCrcErrors uint64 |
| 229 | BipErrors uint64 |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 230 | } |
| 231 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 232 | // NewNniPort returns a new instance of NniPort initialized with the given PortNum and IntfID |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 233 | func NewNniPort(PortNum uint32, IntfID uint32) *NniPort { |
| 234 | |
| 235 | var NNI NniPort |
| 236 | |
| 237 | NNI.PortNum = PortNum |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 238 | NNI.Name = fmt.Sprintf("%s%d", "nni-", PortNum) |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 239 | NNI.IntfID = IntfID |
| 240 | |
| 241 | NNI.RxBytes = 0 |
| 242 | NNI.RxPackets = 0 |
Dileep Kuchhangi | 52cfbe1 | 2020-01-15 20:16:21 +0000 | [diff] [blame] | 243 | NNI.RxUcastPackets = 0 |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 244 | NNI.RxMcastPackets = 0 |
| 245 | NNI.RxBcastPackets = 0 |
| 246 | NNI.RxErrorPackets = 0 |
| 247 | NNI.TxBytes = 0 |
| 248 | NNI.TxPackets = 0 |
| 249 | NNI.TxUcastPackets = 0 |
| 250 | NNI.TxMcastPackets = 0 |
| 251 | NNI.TxBcastPackets = 0 |
| 252 | NNI.TxErrorPackets = 0 |
Dileep Kuchhangi | 52cfbe1 | 2020-01-15 20:16:21 +0000 | [diff] [blame] | 253 | NNI.RxCrcErrors = 0 |
| 254 | NNI.BipErrors = 0 |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 255 | |
| 256 | return &NNI |
| 257 | } |
| 258 | |
Joey Armstrong | 3f0e242 | 2023-07-05 18:25:41 -0400 | [diff] [blame] | 259 | // StatType defines portStatsType and flowStatsType types |
kesavand | 6212621 | 2021-01-12 04:56:06 -0500 | [diff] [blame] | 260 | type StatType int |
| 261 | |
| 262 | const ( |
| 263 | portStatsType StatType = iota |
| 264 | flowStatsType |
| 265 | ) |
| 266 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 267 | // OpenOltStatisticsMgr structure |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 268 | type OpenOltStatisticsMgr struct { |
| 269 | Device *DeviceHandler |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 270 | NorthBoundPort map[uint32]*NniPort |
| 271 | SouthBoundPort map[uint32]*PonPort |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 272 | // TODO PMMetrics Metrics |
kesavand | 6212621 | 2021-01-12 04:56:06 -0500 | [diff] [blame] | 273 | //statIndListners is the list of requests to be notified when port and flow stats indication is received |
| 274 | statIndListnerMu sync.Mutex |
| 275 | statIndListners map[StatType]*list.List |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 276 | } |
| 277 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 278 | // NewOpenOltStatsMgr returns a new instance of the OpenOltStatisticsMgr |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 279 | func NewOpenOltStatsMgr(ctx context.Context, Dev *DeviceHandler) *OpenOltStatisticsMgr { |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 280 | |
| 281 | var StatMgr OpenOltStatisticsMgr |
| 282 | |
| 283 | StatMgr.Device = Dev |
| 284 | // TODO call metric PMMetric = |
| 285 | // Northbound and Southbound ports |
| 286 | // added to initialize the pm_metrics |
| 287 | var Ports interface{} |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 288 | Ports, _ = InitPorts(ctx, "nni", Dev.device.Id, 1) |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 289 | StatMgr.NorthBoundPort, _ = Ports.(map[uint32]*NniPort) |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 290 | NumPonPorts := Dev.resourceMgr[0].DevInfo.GetPonPorts() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 291 | Ports, _ = InitPorts(ctx, "pon", Dev.device.Id, NumPonPorts) |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 292 | StatMgr.SouthBoundPort, _ = Ports.(map[uint32]*PonPort) |
Gamze Abaka | fcbd6e7 | 2020-12-17 13:25:16 +0000 | [diff] [blame] | 293 | if StatMgr.Device.openOLT.enableONUStats { |
| 294 | go StatMgr.publishOnuStats() |
| 295 | } |
| 296 | if StatMgr.Device.openOLT.enableGemStats { |
| 297 | go StatMgr.publishGemStats() |
| 298 | } |
kesavand | 6212621 | 2021-01-12 04:56:06 -0500 | [diff] [blame] | 299 | StatMgr.statIndListners = make(map[StatType]*list.List) |
| 300 | StatMgr.statIndListners[portStatsType] = list.New() |
| 301 | StatMgr.statIndListners[flowStatsType] = list.New() |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 302 | return &StatMgr |
| 303 | } |
| 304 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 305 | // InitPorts collects the port objects: nni and pon that are updated with the current data from the OLT |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 306 | func InitPorts(ctx context.Context, Intftype string, DeviceID string, numOfPorts uint32) (interface{}, error) { |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 307 | /* |
| 308 | This method collects the port objects: nni and pon that are updated with the |
| 309 | current data from the OLT |
| 310 | |
| 311 | Both the northbound (nni) and southbound ports are indexed by the interface id (intf_id) |
| 312 | and NOT the port number. When the port object is instantiated it will contain the intf_id and |
| 313 | port_no values |
| 314 | |
| 315 | :param type: |
| 316 | :return: |
| 317 | */ |
| 318 | var i uint32 |
| 319 | if Intftype == "nni" { |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 320 | NniPorts := make(map[uint32]*NniPort) |
| 321 | for i = 0; i < numOfPorts; i++ { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 322 | Port := BuildPortObject(ctx, i, "nni", DeviceID).(*NniPort) |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 323 | NniPorts[Port.IntfID] = Port |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 324 | } |
| 325 | return NniPorts, nil |
| 326 | } else if Intftype == "pon" { |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 327 | PONPorts := make(map[uint32]*PonPort) |
| 328 | for i = 0; i < numOfPorts; i++ { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 329 | PONPort := BuildPortObject(ctx, i, "pon", DeviceID).(*PonPort) |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 330 | PONPorts[plt.PortNoToIntfID(PONPort.IntfID, voltha.Port_PON_OLT)] = PONPort |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 331 | } |
| 332 | return PONPorts, nil |
| 333 | } else { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 334 | logger.Errorw(ctx, "invalid-type-of-interface", log.Fields{"interface-type": Intftype}) |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 335 | return nil, olterrors.NewErrInvalidValue(log.Fields{"interface-type": Intftype}, nil) |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 336 | } |
| 337 | } |
| 338 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 339 | // BuildPortObject allows for updating north and southbound ports, newly discovered ports, and devices |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 340 | func BuildPortObject(ctx context.Context, PortNum uint32, IntfType string, DeviceID string) interface{} { |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 341 | /* |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 342 | Separate method to allow for updating north and southbound ports |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 343 | newly discovered ports and devices |
| 344 | |
| 345 | :param port_num: |
| 346 | :param type: |
| 347 | :return: |
| 348 | */ |
| 349 | |
| 350 | //This builds a port object which is added to the |
| 351 | //appropriate northbound or southbound values |
| 352 | if IntfType == "nni" { |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 353 | IntfID := plt.IntfIDToPortNo(PortNum, voltha.Port_ETHERNET_NNI) |
| 354 | nniID := plt.PortNoToIntfID(IntfID, voltha.Port_ETHERNET_NNI) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 355 | logger.Debugw(ctx, "interface-type-nni", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 356 | log.Fields{ |
| 357 | "nni-id": nniID, |
| 358 | "intf-type": IntfType}) |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 359 | return NewNniPort(PortNum, nniID) |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 360 | } else if IntfType == "pon" { |
| 361 | // PON ports require a different configuration |
| 362 | // intf_id and pon_id are currently equal. |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 363 | IntfID := plt.IntfIDToPortNo(PortNum, voltha.Port_PON_OLT) |
| 364 | PONID := plt.PortNoToIntfID(IntfID, voltha.Port_PON_OLT) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 365 | logger.Debugw(ctx, "interface-type-pon", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 366 | log.Fields{ |
| 367 | "pon-id": PONID, |
| 368 | "intf-type": IntfType}) |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 369 | return NewPONPort(PONID, DeviceID, IntfID, PortNum) |
| 370 | } else { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 371 | logger.Errorw(ctx, "invalid-type-of-interface", log.Fields{"intf-type": IntfType}) |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 372 | return nil |
| 373 | } |
| 374 | } |
| 375 | |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 376 | // collectNNIMetrics will collect the nni port metrics |
| 377 | func (StatMgr *OpenOltStatisticsMgr) collectNNIMetrics(nniID uint32) map[string]float32 { |
| 378 | |
| 379 | nnival := make(map[string]float32) |
| 380 | mutex.Lock() |
| 381 | cm := StatMgr.Device.portStats.NorthBoundPort[nniID] |
| 382 | mutex.Unlock() |
Rohan Agrawal | da5e0b2 | 2020-05-20 11:10:26 +0000 | [diff] [blame] | 383 | metricNames := StatMgr.Device.metrics.GetSubscriberMetrics() |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 384 | |
Rohan Agrawal | da5e0b2 | 2020-05-20 11:10:26 +0000 | [diff] [blame] | 385 | var metrics []string |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 386 | for metric := range metricNames { |
| 387 | if metricNames[metric].Enabled { |
| 388 | metrics = append(metrics, metric) |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 389 | } |
| 390 | } |
Rohan Agrawal | da5e0b2 | 2020-05-20 11:10:26 +0000 | [diff] [blame] | 391 | |
| 392 | for _, mName := range metrics { |
| 393 | switch mName { |
| 394 | case "rx_bytes": |
| 395 | nnival["RxBytes"] = float32(cm.RxBytes) |
| 396 | case "rx_packets": |
| 397 | nnival["RxPackets"] = float32(cm.RxPackets) |
| 398 | case "rx_ucast_packets": |
| 399 | nnival["RxUcastPackets"] = float32(cm.RxUcastPackets) |
| 400 | case "rx_mcast_packets": |
| 401 | nnival["RxMcastPackets"] = float32(cm.RxMcastPackets) |
| 402 | case "rx_bcast_packets": |
| 403 | nnival["RxBcastPackets"] = float32(cm.RxBcastPackets) |
| 404 | case "tx_bytes": |
| 405 | nnival["TxBytes"] = float32(cm.TxBytes) |
| 406 | case "tx_packets": |
| 407 | nnival["TxPackets"] = float32(cm.TxPackets) |
| 408 | case "tx_mcast_packets": |
| 409 | nnival["TxMcastPackets"] = float32(cm.TxMcastPackets) |
| 410 | case "tx_bcast_packets": |
| 411 | nnival["TxBcastPackets"] = float32(cm.TxBcastPackets) |
| 412 | } |
| 413 | } |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 414 | return nnival |
| 415 | } |
| 416 | |
| 417 | // collectPONMetrics will collect the pon port metrics |
| 418 | func (StatMgr *OpenOltStatisticsMgr) collectPONMetrics(pID uint32) map[string]float32 { |
| 419 | |
| 420 | ponval := make(map[string]float32) |
| 421 | mutex.Lock() |
| 422 | cm := StatMgr.Device.portStats.SouthBoundPort[pID] |
| 423 | mutex.Unlock() |
Rohan Agrawal | da5e0b2 | 2020-05-20 11:10:26 +0000 | [diff] [blame] | 424 | metricNames := StatMgr.Device.metrics.GetSubscriberMetrics() |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 425 | |
Rohan Agrawal | da5e0b2 | 2020-05-20 11:10:26 +0000 | [diff] [blame] | 426 | var metrics []string |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 427 | for metric := range metricNames { |
| 428 | if metricNames[metric].Enabled { |
| 429 | metrics = append(metrics, metric) |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 430 | } |
| 431 | } |
Rohan Agrawal | da5e0b2 | 2020-05-20 11:10:26 +0000 | [diff] [blame] | 432 | |
| 433 | for _, mName := range metrics { |
| 434 | switch mName { |
| 435 | case "rx_bytes": |
| 436 | ponval["RxBytes"] = float32(cm.RxBytes) |
| 437 | case "rx_packets": |
| 438 | ponval["RxPackets"] = float32(cm.RxPackets) |
| 439 | case "rx_ucast_packets": |
| 440 | ponval["RxUcastPackets"] = float32(cm.RxUcastPackets) |
| 441 | case "rx_mcast_packets": |
| 442 | ponval["RxMcastPackets"] = float32(cm.RxMcastPackets) |
| 443 | case "rx_bcast_packets": |
| 444 | ponval["RxBcastPackets"] = float32(cm.RxBcastPackets) |
| 445 | case "tx_bytes": |
| 446 | ponval["TxBytes"] = float32(cm.TxBytes) |
| 447 | case "tx_packets": |
| 448 | ponval["TxPackets"] = float32(cm.TxPackets) |
| 449 | case "tx_mcast_packets": |
| 450 | ponval["TxMcastPackets"] = float32(cm.TxMcastPackets) |
| 451 | case "tx_bcast_packets": |
| 452 | ponval["TxBcastPackets"] = float32(cm.TxBcastPackets) |
| 453 | } |
| 454 | } |
| 455 | |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 456 | return ponval |
| 457 | } |
| 458 | |
Gamze Abaka | fcbd6e7 | 2020-12-17 13:25:16 +0000 | [diff] [blame] | 459 | // converGemStats will convert gem stats response to kpi context |
| 460 | func (StatMgr *OpenOltStatisticsMgr) convertGemStats(gemStats *openolt.GemPortStatistics) map[string]float32 { |
| 461 | gemStatsVal := make(map[string]float32) |
| 462 | gemStatsVal[IntfID] = float32(gemStats.IntfId) |
| 463 | gemStatsVal[GemID] = float32(gemStats.GemportId) |
| 464 | gemStatsVal[RxPackets] = float32(gemStats.RxPackets) |
| 465 | gemStatsVal[RxBytes] = float32(gemStats.RxBytes) |
| 466 | gemStatsVal[TxPackets] = float32(gemStats.TxPackets) |
| 467 | gemStatsVal[TxBytes] = float32(gemStats.TxBytes) |
| 468 | return gemStatsVal |
| 469 | } |
| 470 | |
| 471 | // convertONUStats will convert onu stats response to kpi context |
| 472 | func (StatMgr *OpenOltStatisticsMgr) convertONUStats(onuStats *openolt.OnuStatistics) map[string]float32 { |
| 473 | onuStatsVal := make(map[string]float32) |
| 474 | onuStatsVal[IntfID] = float32(onuStats.IntfId) |
| 475 | onuStatsVal[OnuID] = float32(onuStats.OnuId) |
| 476 | onuStatsVal[PositiveDrift] = float32(onuStats.PositiveDrift) |
| 477 | onuStatsVal[NegativeDrift] = float32(onuStats.NegativeDrift) |
| 478 | onuStatsVal[DelimiterMissDetection] = float32(onuStats.DelimiterMissDetection) |
| 479 | onuStatsVal[BipErrors] = float32(onuStats.BipErrors) |
| 480 | onuStatsVal[BipUnits] = float32(onuStats.BipUnits) |
| 481 | onuStatsVal[FecCorrectedSymbols] = float32(onuStats.FecCorrectedSymbols) |
| 482 | onuStatsVal[FecCodewordsCorrected] = float32(onuStats.FecCodewordsCorrected) |
| 483 | onuStatsVal[fecCodewordsUncorrectable] = float32(onuStats.FecCodewordsUncorrectable) |
| 484 | onuStatsVal[FecCodewords] = float32(onuStats.FecCodewords) |
| 485 | onuStatsVal[FecCorrectedUnits] = float32(onuStats.FecCorrectedUnits) |
| 486 | onuStatsVal[XGEMKeyErrors] = float32(onuStats.XgemKeyErrors) |
| 487 | onuStatsVal[XGEMLoss] = float32(onuStats.XgemLoss) |
| 488 | onuStatsVal[RxPloamsError] = float32(onuStats.RxPloamsError) |
| 489 | onuStatsVal[RxPloamsNonIdle] = float32(onuStats.RxPloamsNonIdle) |
| 490 | onuStatsVal[RxOmci] = float32(onuStats.RxOmci) |
| 491 | onuStatsVal[RxOmciPacketsCrcError] = float32(onuStats.RxOmciPacketsCrcError) |
| 492 | onuStatsVal[RxBytes] = float32(onuStats.RxBytes) |
| 493 | onuStatsVal[RxPackets] = float32(onuStats.RxPackets) |
| 494 | onuStatsVal[TxBytes] = float32(onuStats.TxBytes) |
| 495 | onuStatsVal[TxPackets] = float32(onuStats.TxPackets) |
| 496 | onuStatsVal[BerReported] = float32(onuStats.BerReported) |
| 497 | onuStatsVal[LcdgErrors] = float32(onuStats.LcdgErrors) |
| 498 | onuStatsVal[RdiErrors] = float32(onuStats.RdiErrors) |
Himani Chawla | 2c8ae0f | 2021-05-18 23:27:00 +0530 | [diff] [blame] | 499 | onuStatsVal[Timestamp] = float32(onuStats.Timestamp) |
Gamze Abaka | fcbd6e7 | 2020-12-17 13:25:16 +0000 | [diff] [blame] | 500 | return onuStatsVal |
| 501 | } |
| 502 | |
| 503 | // collectOnuStats will collect the onu metrics |
| 504 | func (StatMgr *OpenOltStatisticsMgr) collectOnuStats(ctx context.Context, onuGemInfo rsrcMgr.OnuGemInfo) { |
| 505 | onu := &openolt.Onu{IntfId: onuGemInfo.IntfID, OnuId: onuGemInfo.OnuID} |
| 506 | logger.Debugw(ctx, "pulling-onu-stats", log.Fields{"IntfID": onuGemInfo.IntfID, "OnuID": onuGemInfo.OnuID}) |
| 507 | if stats, err := StatMgr.Device.Client.GetOnuStatistics(context.Background(), onu); err == nil { |
| 508 | onuStats <- stats |
| 509 | } else { |
| 510 | logger.Errorw(ctx, "error-while-getting-onu-stats-for-onu", log.Fields{"IntfID": onuGemInfo.IntfID, "OnuID": onuGemInfo.OnuID, "err": err}) |
| 511 | } |
| 512 | } |
| 513 | |
Himani Chawla | 2c8ae0f | 2021-05-18 23:27:00 +0530 | [diff] [blame] | 514 | // collectOnDemandOnuStats will collect the onui-pon metrics |
| 515 | func (StatMgr *OpenOltStatisticsMgr) collectOnDemandOnuStats(ctx context.Context, intfID uint32, onuID uint32) map[string]float32 { |
| 516 | onu := &openolt.Onu{IntfId: intfID, OnuId: onuID} |
| 517 | var stats *openolt.OnuStatistics |
| 518 | var err error |
| 519 | logger.Debugw(ctx, "pulling-onu-stats-on-demand", log.Fields{"IntfID": intfID, "OnuID": onuID}) |
| 520 | if stats, err = StatMgr.Device.Client.GetOnuStatistics(context.Background(), onu); err == nil { |
| 521 | statValue := StatMgr.convertONUStats(stats) |
| 522 | return statValue |
| 523 | |
| 524 | } |
| 525 | logger.Errorw(ctx, "error-while-getting-onu-stats-for-onu", log.Fields{"IntfID": intfID, "OnuID": onuID, "err": err}) |
| 526 | return nil |
| 527 | } |
| 528 | |
Gamze Abaka | fcbd6e7 | 2020-12-17 13:25:16 +0000 | [diff] [blame] | 529 | // collectOnuAndGemStats will collect both onu and gem metrics |
| 530 | func (StatMgr *OpenOltStatisticsMgr) collectOnuAndGemStats(ctx context.Context, onuGemInfo []rsrcMgr.OnuGemInfo) { |
| 531 | if !StatMgr.Device.openOLT.enableONUStats && !StatMgr.Device.openOLT.enableGemStats { |
| 532 | return |
| 533 | } |
| 534 | |
| 535 | for _, onuInfo := range onuGemInfo { |
| 536 | if StatMgr.Device.openOLT.enableONUStats { |
| 537 | go StatMgr.collectOnuStats(ctx, onuInfo) |
| 538 | } |
| 539 | if StatMgr.Device.openOLT.enableGemStats { |
| 540 | go StatMgr.collectGemStats(ctx, onuInfo) |
| 541 | } |
| 542 | } |
| 543 | } |
| 544 | |
| 545 | // collectGemStats will collect gem metrics |
| 546 | func (StatMgr *OpenOltStatisticsMgr) collectGemStats(ctx context.Context, onuGemInfo rsrcMgr.OnuGemInfo) { |
| 547 | for _, gem := range onuGemInfo.GemPorts { |
| 548 | logger.Debugw(ctx, "pulling-gem-stats", log.Fields{"IntfID": onuGemInfo.IntfID, "OnuID": onuGemInfo.OnuID, "GemID": gem}) |
| 549 | onuPacket := &openolt.OnuPacket{IntfId: onuGemInfo.IntfID, OnuId: onuGemInfo.OnuID, GemportId: gem} |
| 550 | if stats, err := StatMgr.Device.Client.GetGemPortStatistics(context.Background(), onuPacket); err == nil { |
| 551 | gemStats <- stats |
| 552 | } else { |
| 553 | logger.Errorw(ctx, "error-while-getting-gem-stats-for-onu", |
| 554 | log.Fields{"IntfID": onuGemInfo.IntfID, "OnuID": onuGemInfo.OnuID, "GemID": gem, "err": err}) |
| 555 | } |
| 556 | } |
| 557 | } |
| 558 | |
| 559 | // publishGemStats will publish the gem metrics |
| 560 | func (StatMgr *OpenOltStatisticsMgr) publishGemStats() { |
| 561 | for { |
| 562 | statValue := StatMgr.convertGemStats(<-gemStats) |
| 563 | StatMgr.publishMetrics(context.Background(), GEMStats, statValue, &voltha.Port{Label: "GEM"}, StatMgr.Device.device.Id, StatMgr.Device.device.Type) |
| 564 | } |
| 565 | } |
| 566 | |
| 567 | // publishOnuStats will publish the onu metrics |
| 568 | func (StatMgr *OpenOltStatisticsMgr) publishOnuStats() { |
| 569 | for { |
| 570 | statValue := StatMgr.convertONUStats(<-onuStats) |
| 571 | StatMgr.publishMetrics(context.Background(), ONUStats, statValue, &voltha.Port{Label: "ONU"}, StatMgr.Device.device.Id, StatMgr.Device.device.Type) |
| 572 | } |
| 573 | } |
| 574 | |
| 575 | // publishMetrics will publish the pon port metrics |
kesavand | 6212621 | 2021-01-12 04:56:06 -0500 | [diff] [blame] | 576 | func (StatMgr *OpenOltStatisticsMgr) publishMetrics(ctx context.Context, statType string, val map[string]float32, |
Girish Gowdra | 34815db | 2020-05-11 17:18:04 -0700 | [diff] [blame] | 577 | port *voltha.Port, devID string, devType string) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 578 | logger.Debugw(ctx, "publish-metrics", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 579 | log.Fields{ |
| 580 | "port": port.Label, |
| 581 | "metrics": val}) |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 582 | |
| 583 | var metricInfo voltha.MetricInformation |
| 584 | var ke voltha.KpiEvent2 |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 585 | var volthaEventSubCatgry voltha.EventSubCategory_Types |
Girish Gowdra | 34815db | 2020-05-11 17:18:04 -0700 | [diff] [blame] | 586 | metricsContext := make(map[string]string) |
| 587 | metricsContext["oltid"] = devID |
| 588 | metricsContext["devicetype"] = devType |
| 589 | metricsContext["portlabel"] = port.Label |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 590 | |
Gamze Abaka | fcbd6e7 | 2020-12-17 13:25:16 +0000 | [diff] [blame] | 591 | if statType == NNIStats { |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 592 | volthaEventSubCatgry = voltha.EventSubCategory_NNI |
Gamze Abaka | fcbd6e7 | 2020-12-17 13:25:16 +0000 | [diff] [blame] | 593 | } else if statType == PONStats { |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 594 | volthaEventSubCatgry = voltha.EventSubCategory_PON |
Gamze Abaka | fcbd6e7 | 2020-12-17 13:25:16 +0000 | [diff] [blame] | 595 | } else if statType == GEMStats || statType == ONUStats { |
| 596 | volthaEventSubCatgry = voltha.EventSubCategory_ONT |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 597 | } |
| 598 | |
Girish Gowdra | c1b9d5e | 2021-04-22 12:47:44 -0700 | [diff] [blame] | 599 | raisedTs := time.Now().Unix() |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 600 | mmd := voltha.MetricMetaData{ |
Gamze Abaka | fcbd6e7 | 2020-12-17 13:25:16 +0000 | [diff] [blame] | 601 | Title: statType, |
Girish Gowdra | c1b9d5e | 2021-04-22 12:47:44 -0700 | [diff] [blame] | 602 | Ts: float64(raisedTs), |
Girish Gowdra | 34815db | 2020-05-11 17:18:04 -0700 | [diff] [blame] | 603 | Context: metricsContext, |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 604 | DeviceId: devID, |
| 605 | } |
| 606 | |
| 607 | metricInfo.Metadata = &mmd |
| 608 | metricInfo.Metrics = val |
| 609 | |
| 610 | ke.SliceData = []*voltha.MetricInformation{&metricInfo} |
| 611 | ke.Type = voltha.KpiEventType_slice |
Girish Gowdra | c1b9d5e | 2021-04-22 12:47:44 -0700 | [diff] [blame] | 612 | ke.Ts = float64(raisedTs) |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 613 | |
Himani Chawla | 473496d | 2021-12-01 00:10:30 +0530 | [diff] [blame] | 614 | if err := StatMgr.Device.EventProxy.SendKpiEvent(ctx, "STATS_PUBLISH_EVENT", &ke, voltha.EventCategory_EQUIPMENT, volthaEventSubCatgry, raisedTs); err != nil { |
Gamze Abaka | fcbd6e7 | 2020-12-17 13:25:16 +0000 | [diff] [blame] | 615 | logger.Errorw(ctx, "failed-to-send-stats", log.Fields{"err": err}) |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 616 | } |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 617 | } |
| 618 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 619 | // PortStatisticsIndication handles the port statistics indication |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 620 | func (StatMgr *OpenOltStatisticsMgr) PortStatisticsIndication(ctx context.Context, PortStats *openolt.PortStatistics, NumPonPorts uint32) { |
| 621 | StatMgr.PortsStatisticsKpis(ctx, PortStats, NumPonPorts) |
| 622 | logger.Debugw(ctx, "received-port-stats-indication", log.Fields{"port-stats": PortStats}) |
kesavand | 6212621 | 2021-01-12 04:56:06 -0500 | [diff] [blame] | 623 | //Indicate that PortStatisticsIndication is handled |
| 624 | //PortStats.IntfId is actually the port number |
| 625 | StatMgr.processStatIndication(ctx, portStatsType, PortStats.IntfId) |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 626 | // TODO send stats to core topic to the voltha kafka or a different kafka ? |
| 627 | } |
| 628 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 629 | // FlowStatisticsIndication to be implemented |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 630 | func FlowStatisticsIndication(ctx context.Context, self, FlowStats *openolt.FlowStatistics) { |
| 631 | logger.Debugw(ctx, "flow-stats-collected", log.Fields{"flow-stats": FlowStats}) |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 632 | //TODO send to kafka ? |
| 633 | } |
| 634 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 635 | // PortsStatisticsKpis map the port stats values into a dictionary, creates the kpiEvent and then publish to Kafka |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 636 | func (StatMgr *OpenOltStatisticsMgr) PortsStatisticsKpis(ctx context.Context, PortStats *openolt.PortStatistics, NumPonPorts uint32) { |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 637 | |
| 638 | /*map the port stats values into a dictionary |
| 639 | Create a kpoEvent and publish to Kafka |
| 640 | |
| 641 | :param port_stats: |
| 642 | :return: |
| 643 | */ |
| 644 | //var err error |
| 645 | IntfID := PortStats.IntfId |
| 646 | |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 647 | if (plt.IntfIDToPortNo(1, voltha.Port_ETHERNET_NNI) < IntfID) && |
| 648 | (IntfID < plt.IntfIDToPortNo(4, voltha.Port_ETHERNET_NNI)) { |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 649 | /* |
| 650 | for this release we are only interested in the first NNI for |
| 651 | Northbound. |
| 652 | we are not using the other 3 |
| 653 | */ |
| 654 | return |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 655 | } else if plt.IntfIDToPortNo(0, voltha.Port_ETHERNET_NNI) == IntfID { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 656 | |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 657 | var portNNIStat NniPort |
| 658 | portNNIStat.IntfID = IntfID |
| 659 | portNNIStat.PortNum = uint32(0) |
| 660 | portNNIStat.RxBytes = PortStats.RxBytes |
| 661 | portNNIStat.RxPackets = PortStats.RxPackets |
Dileep Kuchhangi | 52cfbe1 | 2020-01-15 20:16:21 +0000 | [diff] [blame] | 662 | portNNIStat.RxUcastPackets = PortStats.RxUcastPackets |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 663 | portNNIStat.RxMcastPackets = PortStats.RxMcastPackets |
| 664 | portNNIStat.RxBcastPackets = PortStats.RxBcastPackets |
| 665 | portNNIStat.TxBytes = PortStats.TxBytes |
| 666 | portNNIStat.TxPackets = PortStats.TxPackets |
Dileep Kuchhangi | 52cfbe1 | 2020-01-15 20:16:21 +0000 | [diff] [blame] | 667 | portNNIStat.TxUcastPackets = PortStats.TxUcastPackets |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 668 | portNNIStat.TxMcastPackets = PortStats.TxMcastPackets |
| 669 | portNNIStat.TxBcastPackets = PortStats.TxBcastPackets |
| 670 | mutex.Lock() |
| 671 | StatMgr.NorthBoundPort[0] = &portNNIStat |
| 672 | mutex.Unlock() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 673 | logger.Debugw(ctx, "received-nni-stats", log.Fields{"nni-stats": StatMgr.NorthBoundPort}) |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 674 | } |
| 675 | for i := uint32(0); i < NumPonPorts; i++ { |
| 676 | |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 677 | if plt.IntfIDToPortNo(i, voltha.Port_PON_OLT) == IntfID { |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 678 | var portPonStat PonPort |
| 679 | portPonStat.IntfID = IntfID |
| 680 | portPonStat.PortNum = i |
| 681 | portPonStat.PONID = i |
| 682 | portPonStat.RxBytes = PortStats.RxBytes |
| 683 | portPonStat.RxPackets = PortStats.RxPackets |
Dileep Kuchhangi | 52cfbe1 | 2020-01-15 20:16:21 +0000 | [diff] [blame] | 684 | portPonStat.RxUcastPackets = PortStats.RxUcastPackets |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 685 | portPonStat.RxMcastPackets = PortStats.RxMcastPackets |
| 686 | portPonStat.RxBcastPackets = PortStats.RxBcastPackets |
| 687 | portPonStat.TxBytes = PortStats.TxBytes |
| 688 | portPonStat.TxPackets = PortStats.TxPackets |
Dileep Kuchhangi | 52cfbe1 | 2020-01-15 20:16:21 +0000 | [diff] [blame] | 689 | portPonStat.TxUcastPackets = PortStats.TxUcastPackets |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 690 | portPonStat.TxMcastPackets = PortStats.TxMcastPackets |
| 691 | portPonStat.TxBcastPackets = PortStats.TxBcastPackets |
| 692 | mutex.Lock() |
| 693 | StatMgr.SouthBoundPort[i] = &portPonStat |
| 694 | mutex.Unlock() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 695 | logger.Debugw(ctx, "received-pon-stats-for-port", log.Fields{"port-pon-stats": portPonStat}) |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 696 | } |
| 697 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 698 | |
| 699 | /* |
| 700 | Based upon the intf_id map to an nni port or a pon port |
| 701 | the intf_id is the key to the north or south bound collections |
| 702 | |
| 703 | Based upon the intf_id the port object (nni_port or pon_port) will |
| 704 | have its data attr. updated by the current dataset collected. |
| 705 | |
| 706 | For prefixing the rule is currently to use the port number and not the intf_id |
| 707 | */ |
| 708 | //FIXME : Just use first NNI for now |
| 709 | /* TODO should the data be marshaled before sending it ? |
| 710 | if IntfID == IntfIdToPortNo(0, voltha.Port_ETHERNET_NNI) { |
| 711 | //NNI port (just the first one) |
| 712 | err = UpdatePortObjectKpiData(StatMgr.NorthBoundPorts[PortStats.IntfID], PMData) |
| 713 | } else { |
| 714 | //PON ports |
| 715 | err = UpdatePortObjectKpiData(SouthboundPorts[PortStats.IntfID], PMData) |
| 716 | } |
| 717 | if (err != nil) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 718 | logger.Error(ctx, "Error publishing statistics data") |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 719 | } |
| 720 | */ |
| 721 | |
Abhilash S.L | 765ad00 | 2019-04-24 16:40:57 +0530 | [diff] [blame] | 722 | } |
kesavand | 6212621 | 2021-01-12 04:56:06 -0500 | [diff] [blame] | 723 | |
| 724 | func (StatMgr *OpenOltStatisticsMgr) updateGetOltPortCountersResponse(ctx context.Context, singleValResp *extension.SingleGetValueResponse, stats map[string]float32) { |
| 725 | |
| 726 | metrics := singleValResp.GetResponse().GetPortCoutners() |
| 727 | metrics.TxBytes = uint64(stats["TxBytes"]) |
| 728 | metrics.RxBytes = uint64(stats["RxBytes"]) |
| 729 | metrics.TxPackets = uint64(stats["TxPackets"]) |
| 730 | metrics.RxPackets = uint64(stats["RxPackets"]) |
| 731 | metrics.TxErrorPackets = uint64(stats["TxErrorPackets"]) |
| 732 | metrics.RxErrorPackets = uint64(stats["RxErrorPackets"]) |
| 733 | metrics.TxBcastPackets = uint64(stats["TxBcastPackets"]) |
| 734 | metrics.RxBcastPackets = uint64(stats["RxBcastPackets"]) |
| 735 | metrics.TxUcastPackets = uint64(stats["TxUcastPackets"]) |
| 736 | metrics.RxUcastPackets = uint64(stats["RxUcastPackets"]) |
| 737 | metrics.TxMcastPackets = uint64(stats["TxMcastPackets"]) |
| 738 | metrics.RxMcastPackets = uint64(stats["RxMcastPackets"]) |
| 739 | |
| 740 | singleValResp.Response.Status = extension.GetValueResponse_OK |
| 741 | logger.Debugw(ctx, "updateGetOltPortCountersResponse", log.Fields{"resp": singleValResp}) |
| 742 | } |
| 743 | |
Joey Armstrong | 3f0e242 | 2023-07-05 18:25:41 -0400 | [diff] [blame] | 744 | // RegisterForStatIndication registers ch as a channel on which indication is sent when statistics of type t is received |
kesavand | 6212621 | 2021-01-12 04:56:06 -0500 | [diff] [blame] | 745 | func (StatMgr *OpenOltStatisticsMgr) RegisterForStatIndication(ctx context.Context, t StatType, ch chan bool, portNo uint32, portType extension.GetOltPortCounters_PortType) { |
| 746 | statInd := statRegInfo{ |
| 747 | chn: ch, |
| 748 | portNo: portNo, |
| 749 | portType: portType, |
| 750 | } |
| 751 | |
| 752 | logger.Debugf(ctx, "RegisterForStatIndication stat type %v portno %v porttype %v chan %v", t, portNo, portType, ch) |
| 753 | StatMgr.statIndListnerMu.Lock() |
| 754 | StatMgr.statIndListners[t].PushBack(statInd) |
| 755 | StatMgr.statIndListnerMu.Unlock() |
| 756 | |
| 757 | } |
| 758 | |
Joey Armstrong | 3f0e242 | 2023-07-05 18:25:41 -0400 | [diff] [blame] | 759 | // DeRegisterFromStatIndication removes the previously registered channel ch for type t of statistics |
kesavand | 6212621 | 2021-01-12 04:56:06 -0500 | [diff] [blame] | 760 | func (StatMgr *OpenOltStatisticsMgr) DeRegisterFromStatIndication(ctx context.Context, t StatType, ch chan bool) { |
| 761 | StatMgr.statIndListnerMu.Lock() |
| 762 | defer StatMgr.statIndListnerMu.Unlock() |
| 763 | |
| 764 | for e := StatMgr.statIndListners[t].Front(); e != nil; e = e.Next() { |
| 765 | statInd := e.Value.(statRegInfo) |
| 766 | if statInd.chn == ch { |
| 767 | StatMgr.statIndListners[t].Remove(e) |
| 768 | return |
| 769 | } |
| 770 | } |
| 771 | } |
| 772 | |
| 773 | func (StatMgr *OpenOltStatisticsMgr) processStatIndication(ctx context.Context, t StatType, portNo uint32) { |
| 774 | var deRegList []*list.Element |
| 775 | var statInd statRegInfo |
| 776 | |
| 777 | StatMgr.statIndListnerMu.Lock() |
| 778 | defer StatMgr.statIndListnerMu.Unlock() |
| 779 | |
| 780 | if StatMgr.statIndListners[t] == nil || StatMgr.statIndListners[t].Len() == 0 { |
| 781 | logger.Debugf(ctx, "processStatIndication %v list is empty ", t) |
| 782 | return |
| 783 | } |
| 784 | |
| 785 | for e := StatMgr.statIndListners[t].Front(); e != nil; e = e.Next() { |
| 786 | statInd = e.Value.(statRegInfo) |
| 787 | if statInd.portNo != portNo { |
| 788 | fmt.Printf("Skipping %v\n", e.Value) |
| 789 | continue |
| 790 | } |
| 791 | // message sent |
| 792 | statInd.chn <- true |
| 793 | deRegList = append(deRegList, e) |
| 794 | |
| 795 | } |
| 796 | for _, e := range deRegList { |
| 797 | StatMgr.statIndListners[t].Remove(e) |
| 798 | } |
| 799 | |
| 800 | } |
Himani Chawla | 2c8ae0f | 2021-05-18 23:27:00 +0530 | [diff] [blame] | 801 | |
| 802 | func (StatMgr *OpenOltStatisticsMgr) updateGetOnuPonCountersResponse(ctx context.Context, singleValResp *extension.SingleGetValueResponse, stats map[string]float32) { |
| 803 | |
| 804 | metrics := singleValResp.GetResponse().GetOnuPonCounters() |
| 805 | metrics.IsIntfId = &extension.GetOnuCountersResponse_IntfId{ |
| 806 | IntfId: uint32(stats[IntfID]), |
| 807 | } |
| 808 | metrics.IsOnuId = &extension.GetOnuCountersResponse_OnuId{ |
| 809 | OnuId: uint32(stats[OnuID]), |
| 810 | } |
| 811 | metrics.IsPositiveDrift = &extension.GetOnuCountersResponse_PositiveDrift{ |
| 812 | PositiveDrift: uint64(stats[PositiveDrift]), |
| 813 | } |
| 814 | metrics.IsNegativeDrift = &extension.GetOnuCountersResponse_NegativeDrift{ |
| 815 | NegativeDrift: uint64(stats[NegativeDrift]), |
| 816 | } |
| 817 | metrics.IsDelimiterMissDetection = &extension.GetOnuCountersResponse_DelimiterMissDetection{ |
| 818 | DelimiterMissDetection: uint64(stats[DelimiterMissDetection]), |
| 819 | } |
| 820 | metrics.IsBipErrors = &extension.GetOnuCountersResponse_BipErrors{ |
| 821 | BipErrors: uint64(stats[BipErrors]), |
| 822 | } |
| 823 | metrics.IsBipUnits = &extension.GetOnuCountersResponse_BipUnits{ |
| 824 | BipUnits: uint64(stats[BipUnits]), |
| 825 | } |
| 826 | metrics.IsFecCorrectedSymbols = &extension.GetOnuCountersResponse_FecCorrectedSymbols{ |
| 827 | FecCorrectedSymbols: uint64(stats[FecCorrectedSymbols]), |
| 828 | } |
| 829 | metrics.IsFecCodewordsCorrected = &extension.GetOnuCountersResponse_FecCodewordsCorrected{ |
| 830 | FecCodewordsCorrected: uint64(stats[FecCodewordsCorrected]), |
| 831 | } |
| 832 | metrics.IsFecCodewordsUncorrectable = &extension.GetOnuCountersResponse_FecCodewordsUncorrectable{ |
| 833 | FecCodewordsUncorrectable: uint64(stats[fecCodewordsUncorrectable]), |
| 834 | } |
| 835 | metrics.IsFecCodewords = &extension.GetOnuCountersResponse_FecCodewords{ |
| 836 | FecCodewords: uint64(stats[FecCodewords]), |
| 837 | } |
| 838 | metrics.IsFecCorrectedUnits = &extension.GetOnuCountersResponse_FecCorrectedUnits{ |
| 839 | FecCorrectedUnits: uint64(stats[FecCorrectedUnits]), |
| 840 | } |
| 841 | metrics.IsXgemKeyErrors = &extension.GetOnuCountersResponse_XgemKeyErrors{ |
| 842 | XgemKeyErrors: uint64(stats[XGEMKeyErrors]), |
| 843 | } |
| 844 | metrics.IsXgemLoss = &extension.GetOnuCountersResponse_XgemLoss{ |
| 845 | XgemLoss: uint64(stats[XGEMLoss]), |
| 846 | } |
| 847 | metrics.IsRxPloamsError = &extension.GetOnuCountersResponse_RxPloamsError{ |
| 848 | RxPloamsError: uint64(stats[RxPloamsError]), |
| 849 | } |
| 850 | metrics.IsRxPloamsNonIdle = &extension.GetOnuCountersResponse_RxPloamsNonIdle{ |
| 851 | RxPloamsNonIdle: uint64(stats[RxPloamsNonIdle]), |
| 852 | } |
| 853 | metrics.IsRxOmci = &extension.GetOnuCountersResponse_RxOmci{ |
| 854 | RxOmci: uint64(stats[RxOmci]), |
| 855 | } |
| 856 | metrics.IsRxOmciPacketsCrcError = &extension.GetOnuCountersResponse_RxOmciPacketsCrcError{ |
| 857 | RxOmciPacketsCrcError: uint64(stats[RxOmciPacketsCrcError]), |
| 858 | } |
| 859 | metrics.IsRxBytes = &extension.GetOnuCountersResponse_RxBytes{ |
| 860 | RxBytes: uint64(stats[RxBytes]), |
| 861 | } |
| 862 | metrics.IsRxPackets = &extension.GetOnuCountersResponse_RxPackets{ |
| 863 | RxPackets: uint64(stats[RxPackets]), |
| 864 | } |
| 865 | metrics.IsTxBytes = &extension.GetOnuCountersResponse_TxBytes{ |
| 866 | TxBytes: uint64(stats[TxBytes]), |
| 867 | } |
| 868 | metrics.IsTxPackets = &extension.GetOnuCountersResponse_TxPackets{ |
| 869 | TxPackets: uint64(stats[TxPackets]), |
| 870 | } |
| 871 | metrics.IsBerReported = &extension.GetOnuCountersResponse_BerReported{ |
| 872 | BerReported: uint64(stats[BerReported]), |
| 873 | } |
| 874 | metrics.IsLcdgErrors = &extension.GetOnuCountersResponse_LcdgErrors{ |
| 875 | LcdgErrors: uint64(stats[LcdgErrors]), |
| 876 | } |
| 877 | metrics.IsRdiErrors = &extension.GetOnuCountersResponse_RdiErrors{ |
| 878 | RdiErrors: uint64(stats[RdiErrors]), |
| 879 | } |
| 880 | metrics.IsTimestamp = &extension.GetOnuCountersResponse_Timestamp{ |
| 881 | Timestamp: uint32(stats[Timestamp]), |
| 882 | } |
| 883 | |
| 884 | singleValResp.Response.Status = extension.GetValueResponse_OK |
| 885 | logger.Debugw(ctx, "updateGetOnuPonCountersResponse", log.Fields{"resp": singleValResp}) |
| 886 | } |