blob: 1169904eddfc5e7b808237c3b0690585c59759a5 [file] [log] [blame]
Abhilash S.L765ad002019-04-24 16:40:57 +05301/*
Joey Armstrong11f5a572024-01-12 19:11:32 -05002 * Copyright 2019-2024 Open Networking Foundation (ONF) and the ONF Contributors
Abhilash S.L765ad002019-04-24 16:40:57 +05303
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 Gowdru6a80bbd2019-07-02 07:36:09 -070016
Joey Armstrong3f0e2422023-07-05 18:25:41 -040017// Package core provides the utility for olt devices, flows and statistics
Scott Bakerdbd960e2020-02-28 08:57:51 -080018package core
Abhilash S.L765ad002019-04-24 16:40:57 +053019
20import (
kesavand62126212021-01-12 04:56:06 -050021 "container/list"
Neha Sharma96b7bf22020-06-15 10:37:32 +000022 "context"
Abhilash S.L765ad002019-04-24 16:40:57 +053023 "fmt"
Shrey Baid26912972020-04-16 21:02:31 +053024 "sync"
25 "time"
26
Mahir Gunyel85f61c12021-10-06 11:53:45 -070027 plt "github.com/opencord/voltha-lib-go/v7/pkg/platform"
khenaidoo106c61a2021-08-11 18:05:46 -040028 rsrcMgr "github.com/opencord/voltha-openolt-adapter/internal/pkg/resourcemanager"
29
30 "github.com/opencord/voltha-lib-go/v7/pkg/log"
Thomas Lee S94109f12020-03-03 16:39:29 +053031 "github.com/opencord/voltha-openolt-adapter/internal/pkg/olterrors"
Akash Reddy Kankanalac6b6ca12025-06-12 14:26:57 +053032 "github.com/opencord/voltha-protos/v5/go/common"
khenaidoo106c61a2021-08-11 18:05:46 -040033 "github.com/opencord/voltha-protos/v5/go/extension"
34 "github.com/opencord/voltha-protos/v5/go/openolt"
35 "github.com/opencord/voltha-protos/v5/go/voltha"
Abhilash S.L765ad002019-04-24 16:40:57 +053036)
37
Gamze Abakafcbd6e72020-12-17 13:25:16 +000038const (
Akash Kankanala041a2122024-10-16 15:49:22 +053039 // NNIStats statType constant
Gamze Abakafcbd6e72020-12-17 13:25:16 +000040 NNIStats = "NNIStats"
Akash Kankanala041a2122024-10-16 15:49:22 +053041 // PONStats statType constant
Gamze Abakafcbd6e72020-12-17 13:25:16 +000042 PONStats = "PONStats"
Akash Kankanala041a2122024-10-16 15:49:22 +053043 // ONUStats statType constant
Gamze Abakafcbd6e72020-12-17 13:25:16 +000044 ONUStats = "ONUStats"
Akash Kankanala041a2122024-10-16 15:49:22 +053045 // GEMStats statType constant
Gamze Abakafcbd6e72020-12-17 13:25:16 +000046 GEMStats = "GEMStats"
47
Akash Kankanala041a2122024-10-16 15:49:22 +053048 // RxBytes constant
Gamze Abakafcbd6e72020-12-17 13:25:16 +000049 RxBytes = "RxBytes"
Akash Kankanala041a2122024-10-16 15:49:22 +053050 // RxPackets constant
Gamze Abakafcbd6e72020-12-17 13:25:16 +000051 RxPackets = "RxPackets"
Akash Kankanala041a2122024-10-16 15:49:22 +053052 // TxBytes constant
Gamze Abakafcbd6e72020-12-17 13:25:16 +000053 TxBytes = "TxBytes"
Akash Kankanala041a2122024-10-16 15:49:22 +053054 // TxPackets constant
Gamze Abakafcbd6e72020-12-17 13:25:16 +000055 TxPackets = "TxPackets"
Akash Kankanala041a2122024-10-16 15:49:22 +053056 // FecCodewords constant
Gamze Abakafcbd6e72020-12-17 13:25:16 +000057 FecCodewords = "FecCodewords"
Akash Kankanala041a2122024-10-16 15:49:22 +053058 // BipUnits constant
Gamze Abakafcbd6e72020-12-17 13:25:16 +000059 BipUnits = "BipUnits"
Akash Kankanala041a2122024-10-16 15:49:22 +053060 // BipErrors constant
Gamze Abakafcbd6e72020-12-17 13:25:16 +000061 BipErrors = "BipErrors"
Akash Kankanala041a2122024-10-16 15:49:22 +053062 // RxPloamsNonIdle constant
Gamze Abakafcbd6e72020-12-17 13:25:16 +000063 RxPloamsNonIdle = "RxPloamsNonIdle"
Akash Kankanala041a2122024-10-16 15:49:22 +053064 // RxPloamsError constant
Gamze Abakafcbd6e72020-12-17 13:25:16 +000065 RxPloamsError = "RxPloamsError"
Akash Kankanala041a2122024-10-16 15:49:22 +053066 // RxOmci constant
Gamze Abakafcbd6e72020-12-17 13:25:16 +000067 RxOmci = "RxOmci"
Akash Kankanala041a2122024-10-16 15:49:22 +053068 // RxOmciPacketsCrcError constant
Gamze Abakafcbd6e72020-12-17 13:25:16 +000069 RxOmciPacketsCrcError = "RxOmciPacketsCrcError"
Akash Kankanala041a2122024-10-16 15:49:22 +053070 // PositiveDrift constant
Gamze Abakafcbd6e72020-12-17 13:25:16 +000071 PositiveDrift = "PositiveDrift"
Akash Kankanala041a2122024-10-16 15:49:22 +053072 // NegativeDrift constant
Gamze Abakafcbd6e72020-12-17 13:25:16 +000073 NegativeDrift = "NegativeDrift"
Akash Kankanala041a2122024-10-16 15:49:22 +053074 // DelimiterMissDetection constant
Gamze Abakafcbd6e72020-12-17 13:25:16 +000075 DelimiterMissDetection = "DelimiterMissDetection"
Akash Kankanala041a2122024-10-16 15:49:22 +053076 // FecCorrectedSymbols constant
Gamze Abakafcbd6e72020-12-17 13:25:16 +000077 FecCorrectedSymbols = "FecCorrectedSymbols"
Akash Kankanala041a2122024-10-16 15:49:22 +053078 // FecCodewordsCorrected constant
Gamze Abakafcbd6e72020-12-17 13:25:16 +000079 FecCodewordsCorrected = "FecCodewordsCorrected"
Akash Kankanala041a2122024-10-16 15:49:22 +053080 // fecCodewordsUncorrectable constant
Gamze Abakafcbd6e72020-12-17 13:25:16 +000081 fecCodewordsUncorrectable = "fec_codewords_uncorrectable"
Akash Kankanala041a2122024-10-16 15:49:22 +053082 // FecCorrectedUnits constant
Gamze Abakafcbd6e72020-12-17 13:25:16 +000083 FecCorrectedUnits = "FecCorrectedUnits"
Akash Kankanala041a2122024-10-16 15:49:22 +053084 // XGEMKeyErrors constant
Gamze Abakafcbd6e72020-12-17 13:25:16 +000085 XGEMKeyErrors = "XGEMKeyErrors"
Akash Kankanala041a2122024-10-16 15:49:22 +053086 // XGEMLoss constant
Gamze Abakafcbd6e72020-12-17 13:25:16 +000087 XGEMLoss = "XGEMLOSS"
Akash Kankanala041a2122024-10-16 15:49:22 +053088 // BerReported constant
Gamze Abakafcbd6e72020-12-17 13:25:16 +000089 BerReported = "BerReported"
Akash Kankanala041a2122024-10-16 15:49:22 +053090 // LcdgErrors constant
Gamze Abakafcbd6e72020-12-17 13:25:16 +000091 LcdgErrors = "LcdgErrors"
Akash Kankanala041a2122024-10-16 15:49:22 +053092 // RdiErrors constant
Gamze Abakafcbd6e72020-12-17 13:25:16 +000093 RdiErrors = "RdiErrors"
Akash Kankanala041a2122024-10-16 15:49:22 +053094 // Timestamp constant
Himani Chawla2c8ae0f2021-05-18 23:27:00 +053095 Timestamp = "Timestamp"
Gamze Abakafcbd6e72020-12-17 13:25:16 +000096)
97
Naga Manjunath7615e552019-10-11 22:35:47 +053098var mutex = &sync.Mutex{}
99
Gamze Abakafcbd6e72020-12-17 13:25:16 +0000100var onuStats = make(chan *openolt.OnuStatistics, 100)
101var gemStats = make(chan *openolt.GemPortStatistics, 100)
102
Joey Armstrong3f0e2422023-07-05 18:25:41 -0400103// statRegInfo is used to register for notifications
104// on receiving port stats and flow stats indication
kesavand62126212021-01-12 04:56:06 -0500105type statRegInfo struct {
106 chn chan bool
107 portNo uint32
108 portType extension.GetOltPortCounters_PortType
109}
110
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700111// PonPort representation
Abhilash S.L765ad002019-04-24 16:40:57 +0530112type PonPort struct {
Abhilash S.L765ad002019-04-24 16:40:57 +0530113 ONUs map[uint32]interface{}
114 ONUsByID map[uint32]interface{}
115
Akash Kankanala041a2122024-10-16 15:49:22 +0530116 DeviceID string
117 Label string
118
Abhilash S.L765ad002019-04-24 16:40:57 +0530119 RxBytes uint64
120 RxPackets uint64
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000121 RxUcastPackets uint64
Abhilash S.L765ad002019-04-24 16:40:57 +0530122 RxMcastPackets uint64
123 RxBcastPackets uint64
124 RxErrorPackets uint64
125 TxBytes uint64
126 TxPackets uint64
127 TxUcastPackets uint64
128 TxMcastPackets uint64
129 TxBcastPackets uint64
130 TxErrorPackets uint64
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000131 RxCrcErrors uint64
132 BipErrors uint64
Akash Kankanala041a2122024-10-16 15:49:22 +0530133 /*
134 This is a highly reduced version taken from the adtran pon_port.
135 TODO: Extend for use in the openolt adapter set.
136 */
137 /* MAX_ONUS_SUPPORTED = 256
138 DEFAULT_ENABLED = False
139 MAX_DEPLOYMENT_RANGE = 25000 # Meters (OLT-PB maximum)
140
141 _MCAST_ONU_ID = 253
142 _MCAST_ALLOC_BASE = 0x500
143
144 _SUPPORTED_ACTIVATION_METHODS = ['autodiscovery'] # , 'autoactivate']
145 _SUPPORTED_AUTHENTICATION_METHODS = ['serial-number']
146 */
147 PONID uint32
148 IntfID uint32
149 PortNum uint32
150 PortID uint32
Abhilash S.L765ad002019-04-24 16:40:57 +0530151}
152
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700153// NewPONPort returns a new instance of PonPort initialized with given PONID, DeviceID, IntfID and PortNum
Abhilash S.L765ad002019-04-24 16:40:57 +0530154func NewPONPort(PONID uint32, DeviceID string, IntfID uint32, PortNum uint32) *PonPort {
Abhilash S.L765ad002019-04-24 16:40:57 +0530155 var PON PonPort
156
157 PON.PONID = PONID
158 PON.DeviceID = DeviceID
159 PON.IntfID = IntfID
160 PON.PortNum = PortNum
161 PON.PortID = 0
Naga Manjunath7615e552019-10-11 22:35:47 +0530162 PON.Label = fmt.Sprintf("%s%d", "pon-", PONID)
Abhilash S.L765ad002019-04-24 16:40:57 +0530163
164 PON.ONUs = make(map[uint32]interface{})
165 PON.ONUsByID = make(map[uint32]interface{})
166
167 /*
168 Statistics taken from nni_port
169 self.intf_id = 0 #handled by getter
170 self.port_no = 0 #handled by getter
171 self.port_id = 0 #handled by getter
172
173 Note: In the current implementation of the kpis coming from the BAL the stats are the
174 samne model for NNI and PON.
175
176 TODO: Integrate additional kpis for the PON and other southbound port objecgts.
177
178 */
179
180 PON.RxBytes = 0
181 PON.RxPackets = 0
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000182 PON.RxUcastPackets = 0
Abhilash S.L765ad002019-04-24 16:40:57 +0530183 PON.RxMcastPackets = 0
184 PON.RxBcastPackets = 0
185 PON.RxErrorPackets = 0
186 PON.TxBytes = 0
187 PON.TxPackets = 0
188 PON.TxUcastPackets = 0
189 PON.TxMcastPackets = 0
190 PON.TxBcastPackets = 0
191 PON.TxErrorPackets = 0
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000192 PON.RxCrcErrors = 0
193 PON.BipErrors = 0
Abhilash S.L765ad002019-04-24 16:40:57 +0530194
195 /* def __str__(self):
196 return "PonPort-{}: Admin: {}, Oper: {}, OLT: {}".format(self._label,
197 self._admin_state,
198 self._oper_status,
199 self.olt)
200 */
201 return &PON
202}
203
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700204// NniPort representation
Abhilash S.L765ad002019-04-24 16:40:57 +0530205type NniPort struct {
Akash Kankanala041a2122024-10-16 15:49:22 +0530206 Name string
Abhilash S.L765ad002019-04-24 16:40:57 +0530207
208 RxBytes uint64
209 RxPackets uint64
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000210 RxUcastPackets uint64
Abhilash S.L765ad002019-04-24 16:40:57 +0530211 RxMcastPackets uint64
212 RxBcastPackets uint64
213 RxErrorPackets uint64
214 TxBytes uint64
215 TxPackets uint64
216 TxUcastPackets uint64
217 TxMcastPackets uint64
218 TxBcastPackets uint64
219 TxErrorPackets uint64
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000220 RxCrcErrors uint64
221 BipErrors uint64
Akash Kankanala041a2122024-10-16 15:49:22 +0530222 /*
223 Northbound network port, often Ethernet-based
224
225 This is a highly reduced version taken from the adtran nni_port code set
226 TODO: add functions to allow for port specific values and operations
227 */
228 PortNum uint32
229 LogicalPort uint32
230 IntfID uint32
Abhilash S.L765ad002019-04-24 16:40:57 +0530231}
232
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700233// NewNniPort returns a new instance of NniPort initialized with the given PortNum and IntfID
Abhilash S.L765ad002019-04-24 16:40:57 +0530234func NewNniPort(PortNum uint32, IntfID uint32) *NniPort {
Abhilash S.L765ad002019-04-24 16:40:57 +0530235 var NNI NniPort
236
237 NNI.PortNum = PortNum
Naga Manjunath7615e552019-10-11 22:35:47 +0530238 NNI.Name = fmt.Sprintf("%s%d", "nni-", PortNum)
Abhilash S.L765ad002019-04-24 16:40:57 +0530239 NNI.IntfID = IntfID
240
241 NNI.RxBytes = 0
242 NNI.RxPackets = 0
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000243 NNI.RxUcastPackets = 0
Abhilash S.L765ad002019-04-24 16:40:57 +0530244 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 Kuchhangi52cfbe12020-01-15 20:16:21 +0000253 NNI.RxCrcErrors = 0
254 NNI.BipErrors = 0
Abhilash S.L765ad002019-04-24 16:40:57 +0530255
256 return &NNI
257}
258
Joey Armstrong3f0e2422023-07-05 18:25:41 -0400259// StatType defines portStatsType and flowStatsType types
kesavand62126212021-01-12 04:56:06 -0500260type StatType int
261
262const (
263 portStatsType StatType = iota
264 flowStatsType
265)
266
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700267// OpenOltStatisticsMgr structure
Abhilash S.L765ad002019-04-24 16:40:57 +0530268type OpenOltStatisticsMgr struct {
Akash Kankanala041a2122024-10-16 15:49:22 +0530269 Device *DeviceHandler
270 NorthBoundPort map[uint32]*NniPort
271 SouthBoundPort map[uint32]*PonPort
272 statIndListners map[StatType]*list.List
Abhilash S.L765ad002019-04-24 16:40:57 +0530273 // TODO PMMetrics Metrics
Akash Kankanala041a2122024-10-16 15:49:22 +0530274 // statIndListners is the list of requests to be notified when port and flow stats indication is received
kesavand62126212021-01-12 04:56:06 -0500275 statIndListnerMu sync.Mutex
Abhilash S.L765ad002019-04-24 16:40:57 +0530276}
277
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700278// NewOpenOltStatsMgr returns a new instance of the OpenOltStatisticsMgr
Neha Sharma96b7bf22020-06-15 10:37:32 +0000279func NewOpenOltStatsMgr(ctx context.Context, Dev *DeviceHandler) *OpenOltStatisticsMgr {
Abhilash S.L765ad002019-04-24 16:40:57 +0530280 var StatMgr OpenOltStatisticsMgr
281
282 StatMgr.Device = Dev
283 // TODO call metric PMMetric =
284 // Northbound and Southbound ports
285 // added to initialize the pm_metrics
286 var Ports interface{}
Sridhar Ravindrad104e8d2025-06-02 13:04:49 +0530287 NumNniPorts := Dev.resourceMgr[0].DevInfo.GetNniPorts()
288 Ports, _ = InitPorts(ctx, "nni", Dev.device.Id, NumNniPorts)
Naga Manjunath7615e552019-10-11 22:35:47 +0530289 StatMgr.NorthBoundPort, _ = Ports.(map[uint32]*NniPort)
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700290 NumPonPorts := Dev.resourceMgr[0].DevInfo.GetPonPorts()
Neha Sharma96b7bf22020-06-15 10:37:32 +0000291 Ports, _ = InitPorts(ctx, "pon", Dev.device.Id, NumPonPorts)
Naga Manjunath7615e552019-10-11 22:35:47 +0530292 StatMgr.SouthBoundPort, _ = Ports.(map[uint32]*PonPort)
Gamze Abakafcbd6e72020-12-17 13:25:16 +0000293 if StatMgr.Device.openOLT.enableONUStats {
294 go StatMgr.publishOnuStats()
295 }
296 if StatMgr.Device.openOLT.enableGemStats {
297 go StatMgr.publishGemStats()
298 }
kesavand62126212021-01-12 04:56:06 -0500299 StatMgr.statIndListners = make(map[StatType]*list.List)
300 StatMgr.statIndListners[portStatsType] = list.New()
301 StatMgr.statIndListners[flowStatsType] = list.New()
Abhilash S.L765ad002019-04-24 16:40:57 +0530302 return &StatMgr
303}
304
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700305// InitPorts collects the port objects: nni and pon that are updated with the current data from the OLT
Neha Sharma96b7bf22020-06-15 10:37:32 +0000306func InitPorts(ctx context.Context, Intftype string, DeviceID string, numOfPorts uint32) (interface{}, error) {
Abhilash S.L765ad002019-04-24 16:40:57 +0530307 /*
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 Manjunath7615e552019-10-11 22:35:47 +0530320 NniPorts := make(map[uint32]*NniPort)
321 for i = 0; i < numOfPorts; i++ {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000322 Port := BuildPortObject(ctx, i, "nni", DeviceID).(*NniPort)
Naga Manjunath7615e552019-10-11 22:35:47 +0530323 NniPorts[Port.IntfID] = Port
Abhilash S.L765ad002019-04-24 16:40:57 +0530324 }
325 return NniPorts, nil
326 } else if Intftype == "pon" {
Naga Manjunath7615e552019-10-11 22:35:47 +0530327 PONPorts := make(map[uint32]*PonPort)
328 for i = 0; i < numOfPorts; i++ {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000329 PONPort := BuildPortObject(ctx, i, "pon", DeviceID).(*PonPort)
Mahir Gunyel85f61c12021-10-06 11:53:45 -0700330 PONPorts[plt.PortNoToIntfID(PONPort.IntfID, voltha.Port_PON_OLT)] = PONPort
Abhilash S.L765ad002019-04-24 16:40:57 +0530331 }
332 return PONPorts, nil
333 } else {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000334 logger.Errorw(ctx, "invalid-type-of-interface", log.Fields{"interface-type": Intftype})
Thomas Lee S94109f12020-03-03 16:39:29 +0530335 return nil, olterrors.NewErrInvalidValue(log.Fields{"interface-type": Intftype}, nil)
Abhilash S.L765ad002019-04-24 16:40:57 +0530336 }
337}
338
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700339// BuildPortObject allows for updating north and southbound ports, newly discovered ports, and devices
Neha Sharma96b7bf22020-06-15 10:37:32 +0000340func BuildPortObject(ctx context.Context, PortNum uint32, IntfType string, DeviceID string) interface{} {
Abhilash S.L765ad002019-04-24 16:40:57 +0530341 /*
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700342 Separate method to allow for updating north and southbound ports
Abhilash S.L765ad002019-04-24 16:40:57 +0530343 newly discovered ports and devices
344
345 :param port_num:
346 :param type:
347 :return:
348 */
349
Akash Kankanala041a2122024-10-16 15:49:22 +0530350 // This builds a port object which is added to the
351 // appropriate northbound or southbound values
Abhilash S.L765ad002019-04-24 16:40:57 +0530352 if IntfType == "nni" {
Mahir Gunyel85f61c12021-10-06 11:53:45 -0700353 IntfID := plt.IntfIDToPortNo(PortNum, voltha.Port_ETHERNET_NNI)
354 nniID := plt.PortNoToIntfID(IntfID, voltha.Port_ETHERNET_NNI)
Neha Sharma96b7bf22020-06-15 10:37:32 +0000355 logger.Debugw(ctx, "interface-type-nni",
Shrey Baid26912972020-04-16 21:02:31 +0530356 log.Fields{
357 "nni-id": nniID,
358 "intf-type": IntfType})
Naga Manjunath7615e552019-10-11 22:35:47 +0530359 return NewNniPort(PortNum, nniID)
Abhilash S.L765ad002019-04-24 16:40:57 +0530360 } else if IntfType == "pon" {
361 // PON ports require a different configuration
362 // intf_id and pon_id are currently equal.
Mahir Gunyel85f61c12021-10-06 11:53:45 -0700363 IntfID := plt.IntfIDToPortNo(PortNum, voltha.Port_PON_OLT)
364 PONID := plt.PortNoToIntfID(IntfID, voltha.Port_PON_OLT)
Neha Sharma96b7bf22020-06-15 10:37:32 +0000365 logger.Debugw(ctx, "interface-type-pon",
Shrey Baid26912972020-04-16 21:02:31 +0530366 log.Fields{
367 "pon-id": PONID,
368 "intf-type": IntfType})
Abhilash S.L765ad002019-04-24 16:40:57 +0530369 return NewPONPort(PONID, DeviceID, IntfID, PortNum)
370 } else {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000371 logger.Errorw(ctx, "invalid-type-of-interface", log.Fields{"intf-type": IntfType})
Abhilash S.L765ad002019-04-24 16:40:57 +0530372 return nil
373 }
374}
375
Naga Manjunath7615e552019-10-11 22:35:47 +0530376// collectNNIMetrics will collect the nni port metrics
377func (StatMgr *OpenOltStatisticsMgr) collectNNIMetrics(nniID uint32) map[string]float32 {
Naga Manjunath7615e552019-10-11 22:35:47 +0530378 nnival := make(map[string]float32)
379 mutex.Lock()
380 cm := StatMgr.Device.portStats.NorthBoundPort[nniID]
381 mutex.Unlock()
Rohan Agrawalda5e0b22020-05-20 11:10:26 +0000382 metricNames := StatMgr.Device.metrics.GetSubscriberMetrics()
Naga Manjunath7615e552019-10-11 22:35:47 +0530383
Rohan Agrawalda5e0b22020-05-20 11:10:26 +0000384 var metrics []string
Kent Hagermane6ff1012020-07-14 15:07:53 -0400385 for metric := range metricNames {
386 if metricNames[metric].Enabled {
387 metrics = append(metrics, metric)
Naga Manjunath7615e552019-10-11 22:35:47 +0530388 }
389 }
Rohan Agrawalda5e0b22020-05-20 11:10:26 +0000390
Sridhar Ravindra0f57ac12025-10-27 20:22:11 +0530391 if cm != nil {
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 }
Rohan Agrawalda5e0b22020-05-20 11:10:26 +0000413 }
414 }
Naga Manjunath7615e552019-10-11 22:35:47 +0530415 return nnival
416}
417
418// collectPONMetrics will collect the pon port metrics
419func (StatMgr *OpenOltStatisticsMgr) collectPONMetrics(pID uint32) map[string]float32 {
Naga Manjunath7615e552019-10-11 22:35:47 +0530420 ponval := make(map[string]float32)
421 mutex.Lock()
422 cm := StatMgr.Device.portStats.SouthBoundPort[pID]
423 mutex.Unlock()
Rohan Agrawalda5e0b22020-05-20 11:10:26 +0000424 metricNames := StatMgr.Device.metrics.GetSubscriberMetrics()
Naga Manjunath7615e552019-10-11 22:35:47 +0530425
Rohan Agrawalda5e0b22020-05-20 11:10:26 +0000426 var metrics []string
Kent Hagermane6ff1012020-07-14 15:07:53 -0400427 for metric := range metricNames {
428 if metricNames[metric].Enabled {
429 metrics = append(metrics, metric)
Naga Manjunath7615e552019-10-11 22:35:47 +0530430 }
431 }
Rohan Agrawalda5e0b22020-05-20 11:10:26 +0000432
Sridhar Ravindra0f57ac12025-10-27 20:22:11 +0530433 if cm != nil {
434 for _, mName := range metrics {
435 switch mName {
436 case "rx_bytes":
437 ponval["RxBytes"] = float32(cm.RxBytes)
438 case "rx_packets":
439 ponval["RxPackets"] = float32(cm.RxPackets)
440 case "rx_ucast_packets":
441 ponval["RxUcastPackets"] = float32(cm.RxUcastPackets)
442 case "rx_mcast_packets":
443 ponval["RxMcastPackets"] = float32(cm.RxMcastPackets)
444 case "rx_bcast_packets":
445 ponval["RxBcastPackets"] = float32(cm.RxBcastPackets)
446 case "tx_bytes":
447 ponval["TxBytes"] = float32(cm.TxBytes)
448 case "tx_packets":
449 ponval["TxPackets"] = float32(cm.TxPackets)
450 case "tx_mcast_packets":
451 ponval["TxMcastPackets"] = float32(cm.TxMcastPackets)
452 case "tx_bcast_packets":
453 ponval["TxBcastPackets"] = float32(cm.TxBcastPackets)
454 }
Rohan Agrawalda5e0b22020-05-20 11:10:26 +0000455 }
456 }
457
Naga Manjunath7615e552019-10-11 22:35:47 +0530458 return ponval
459}
460
Gamze Abakafcbd6e72020-12-17 13:25:16 +0000461// converGemStats will convert gem stats response to kpi context
462func (StatMgr *OpenOltStatisticsMgr) convertGemStats(gemStats *openolt.GemPortStatistics) map[string]float32 {
463 gemStatsVal := make(map[string]float32)
464 gemStatsVal[IntfID] = float32(gemStats.IntfId)
465 gemStatsVal[GemID] = float32(gemStats.GemportId)
466 gemStatsVal[RxPackets] = float32(gemStats.RxPackets)
467 gemStatsVal[RxBytes] = float32(gemStats.RxBytes)
468 gemStatsVal[TxPackets] = float32(gemStats.TxPackets)
469 gemStatsVal[TxBytes] = float32(gemStats.TxBytes)
470 return gemStatsVal
471}
472
473// convertONUStats will convert onu stats response to kpi context
474func (StatMgr *OpenOltStatisticsMgr) convertONUStats(onuStats *openolt.OnuStatistics) map[string]float32 {
475 onuStatsVal := make(map[string]float32)
476 onuStatsVal[IntfID] = float32(onuStats.IntfId)
477 onuStatsVal[OnuID] = float32(onuStats.OnuId)
478 onuStatsVal[PositiveDrift] = float32(onuStats.PositiveDrift)
479 onuStatsVal[NegativeDrift] = float32(onuStats.NegativeDrift)
480 onuStatsVal[DelimiterMissDetection] = float32(onuStats.DelimiterMissDetection)
481 onuStatsVal[BipErrors] = float32(onuStats.BipErrors)
482 onuStatsVal[BipUnits] = float32(onuStats.BipUnits)
483 onuStatsVal[FecCorrectedSymbols] = float32(onuStats.FecCorrectedSymbols)
484 onuStatsVal[FecCodewordsCorrected] = float32(onuStats.FecCodewordsCorrected)
485 onuStatsVal[fecCodewordsUncorrectable] = float32(onuStats.FecCodewordsUncorrectable)
486 onuStatsVal[FecCodewords] = float32(onuStats.FecCodewords)
487 onuStatsVal[FecCorrectedUnits] = float32(onuStats.FecCorrectedUnits)
488 onuStatsVal[XGEMKeyErrors] = float32(onuStats.XgemKeyErrors)
489 onuStatsVal[XGEMLoss] = float32(onuStats.XgemLoss)
490 onuStatsVal[RxPloamsError] = float32(onuStats.RxPloamsError)
491 onuStatsVal[RxPloamsNonIdle] = float32(onuStats.RxPloamsNonIdle)
492 onuStatsVal[RxOmci] = float32(onuStats.RxOmci)
493 onuStatsVal[RxOmciPacketsCrcError] = float32(onuStats.RxOmciPacketsCrcError)
494 onuStatsVal[RxBytes] = float32(onuStats.RxBytes)
495 onuStatsVal[RxPackets] = float32(onuStats.RxPackets)
496 onuStatsVal[TxBytes] = float32(onuStats.TxBytes)
497 onuStatsVal[TxPackets] = float32(onuStats.TxPackets)
498 onuStatsVal[BerReported] = float32(onuStats.BerReported)
499 onuStatsVal[LcdgErrors] = float32(onuStats.LcdgErrors)
500 onuStatsVal[RdiErrors] = float32(onuStats.RdiErrors)
Himani Chawla2c8ae0f2021-05-18 23:27:00 +0530501 onuStatsVal[Timestamp] = float32(onuStats.Timestamp)
Gamze Abakafcbd6e72020-12-17 13:25:16 +0000502 return onuStatsVal
503}
504
505// collectOnuStats will collect the onu metrics
506func (StatMgr *OpenOltStatisticsMgr) collectOnuStats(ctx context.Context, onuGemInfo rsrcMgr.OnuGemInfo) {
507 onu := &openolt.Onu{IntfId: onuGemInfo.IntfID, OnuId: onuGemInfo.OnuID}
508 logger.Debugw(ctx, "pulling-onu-stats", log.Fields{"IntfID": onuGemInfo.IntfID, "OnuID": onuGemInfo.OnuID})
509 if stats, err := StatMgr.Device.Client.GetOnuStatistics(context.Background(), onu); err == nil {
510 onuStats <- stats
511 } else {
512 logger.Errorw(ctx, "error-while-getting-onu-stats-for-onu", log.Fields{"IntfID": onuGemInfo.IntfID, "OnuID": onuGemInfo.OnuID, "err": err})
513 }
514}
515
Himani Chawla2c8ae0f2021-05-18 23:27:00 +0530516// collectOnDemandOnuStats will collect the onui-pon metrics
517func (StatMgr *OpenOltStatisticsMgr) collectOnDemandOnuStats(ctx context.Context, intfID uint32, onuID uint32) map[string]float32 {
518 onu := &openolt.Onu{IntfId: intfID, OnuId: onuID}
519 var stats *openolt.OnuStatistics
520 var err error
521 logger.Debugw(ctx, "pulling-onu-stats-on-demand", log.Fields{"IntfID": intfID, "OnuID": onuID})
522 if stats, err = StatMgr.Device.Client.GetOnuStatistics(context.Background(), onu); err == nil {
523 statValue := StatMgr.convertONUStats(stats)
524 return statValue
Himani Chawla2c8ae0f2021-05-18 23:27:00 +0530525 }
526 logger.Errorw(ctx, "error-while-getting-onu-stats-for-onu", log.Fields{"IntfID": intfID, "OnuID": onuID, "err": err})
527 return nil
528}
529
Gamze Abakafcbd6e72020-12-17 13:25:16 +0000530// collectOnuAndGemStats will collect both onu and gem metrics
531func (StatMgr *OpenOltStatisticsMgr) collectOnuAndGemStats(ctx context.Context, onuGemInfo []rsrcMgr.OnuGemInfo) {
532 if !StatMgr.Device.openOLT.enableONUStats && !StatMgr.Device.openOLT.enableGemStats {
533 return
534 }
535
536 for _, onuInfo := range onuGemInfo {
537 if StatMgr.Device.openOLT.enableONUStats {
538 go StatMgr.collectOnuStats(ctx, onuInfo)
539 }
540 if StatMgr.Device.openOLT.enableGemStats {
541 go StatMgr.collectGemStats(ctx, onuInfo)
542 }
543 }
544}
545
546// collectGemStats will collect gem metrics
547func (StatMgr *OpenOltStatisticsMgr) collectGemStats(ctx context.Context, onuGemInfo rsrcMgr.OnuGemInfo) {
548 for _, gem := range onuGemInfo.GemPorts {
549 logger.Debugw(ctx, "pulling-gem-stats", log.Fields{"IntfID": onuGemInfo.IntfID, "OnuID": onuGemInfo.OnuID, "GemID": gem})
550 onuPacket := &openolt.OnuPacket{IntfId: onuGemInfo.IntfID, OnuId: onuGemInfo.OnuID, GemportId: gem}
551 if stats, err := StatMgr.Device.Client.GetGemPortStatistics(context.Background(), onuPacket); err == nil {
552 gemStats <- stats
553 } else {
554 logger.Errorw(ctx, "error-while-getting-gem-stats-for-onu",
555 log.Fields{"IntfID": onuGemInfo.IntfID, "OnuID": onuGemInfo.OnuID, "GemID": gem, "err": err})
556 }
557 }
558}
559
560// publishGemStats will publish the gem metrics
561func (StatMgr *OpenOltStatisticsMgr) publishGemStats() {
562 for {
563 statValue := StatMgr.convertGemStats(<-gemStats)
564 StatMgr.publishMetrics(context.Background(), GEMStats, statValue, &voltha.Port{Label: "GEM"}, StatMgr.Device.device.Id, StatMgr.Device.device.Type)
565 }
566}
567
568// publishOnuStats will publish the onu metrics
569func (StatMgr *OpenOltStatisticsMgr) publishOnuStats() {
570 for {
571 statValue := StatMgr.convertONUStats(<-onuStats)
572 StatMgr.publishMetrics(context.Background(), ONUStats, statValue, &voltha.Port{Label: "ONU"}, StatMgr.Device.device.Id, StatMgr.Device.device.Type)
573 }
574}
575
576// publishMetrics will publish the pon port metrics
kesavand62126212021-01-12 04:56:06 -0500577func (StatMgr *OpenOltStatisticsMgr) publishMetrics(ctx context.Context, statType string, val map[string]float32,
Girish Gowdra34815db2020-05-11 17:18:04 -0700578 port *voltha.Port, devID string, devType string) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000579 logger.Debugw(ctx, "publish-metrics",
Shrey Baid26912972020-04-16 21:02:31 +0530580 log.Fields{
581 "port": port.Label,
582 "metrics": val})
Naga Manjunath7615e552019-10-11 22:35:47 +0530583
584 var metricInfo voltha.MetricInformation
585 var ke voltha.KpiEvent2
Esin Karamanccb714b2019-11-29 15:02:06 +0000586 var volthaEventSubCatgry voltha.EventSubCategory_Types
Girish Gowdra34815db2020-05-11 17:18:04 -0700587 metricsContext := make(map[string]string)
588 metricsContext["oltid"] = devID
589 metricsContext["devicetype"] = devType
590 metricsContext["portlabel"] = port.Label
Naga Manjunath7615e552019-10-11 22:35:47 +0530591
Gamze Abakafcbd6e72020-12-17 13:25:16 +0000592 if statType == NNIStats {
Naga Manjunath7615e552019-10-11 22:35:47 +0530593 volthaEventSubCatgry = voltha.EventSubCategory_NNI
Gamze Abakafcbd6e72020-12-17 13:25:16 +0000594 } else if statType == PONStats {
Naga Manjunath7615e552019-10-11 22:35:47 +0530595 volthaEventSubCatgry = voltha.EventSubCategory_PON
Gamze Abakafcbd6e72020-12-17 13:25:16 +0000596 } else if statType == GEMStats || statType == ONUStats {
597 volthaEventSubCatgry = voltha.EventSubCategory_ONT
Naga Manjunath7615e552019-10-11 22:35:47 +0530598 }
599
Girish Gowdrac1b9d5e2021-04-22 12:47:44 -0700600 raisedTs := time.Now().Unix()
Naga Manjunath7615e552019-10-11 22:35:47 +0530601 mmd := voltha.MetricMetaData{
Gamze Abakafcbd6e72020-12-17 13:25:16 +0000602 Title: statType,
Girish Gowdrac1b9d5e2021-04-22 12:47:44 -0700603 Ts: float64(raisedTs),
Girish Gowdra34815db2020-05-11 17:18:04 -0700604 Context: metricsContext,
Naga Manjunath7615e552019-10-11 22:35:47 +0530605 DeviceId: devID,
606 }
607
608 metricInfo.Metadata = &mmd
609 metricInfo.Metrics = val
610
611 ke.SliceData = []*voltha.MetricInformation{&metricInfo}
612 ke.Type = voltha.KpiEventType_slice
Girish Gowdrac1b9d5e2021-04-22 12:47:44 -0700613 ke.Ts = float64(raisedTs)
Naga Manjunath7615e552019-10-11 22:35:47 +0530614
Himani Chawla473496d2021-12-01 00:10:30 +0530615 if err := StatMgr.Device.EventProxy.SendKpiEvent(ctx, "STATS_PUBLISH_EVENT", &ke, voltha.EventCategory_EQUIPMENT, volthaEventSubCatgry, raisedTs); err != nil {
Gamze Abakafcbd6e72020-12-17 13:25:16 +0000616 logger.Errorw(ctx, "failed-to-send-stats", log.Fields{"err": err})
Naga Manjunath7615e552019-10-11 22:35:47 +0530617 }
Naga Manjunath7615e552019-10-11 22:35:47 +0530618}
619
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700620// PortStatisticsIndication handles the port statistics indication
Akash Reddy Kankanalac6b6ca12025-06-12 14:26:57 +0530621func (StatMgr *OpenOltStatisticsMgr) PortStatisticsIndication(ctx context.Context, PortStats *common.PortStatistics, NumPonPorts uint32) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000622 StatMgr.PortsStatisticsKpis(ctx, PortStats, NumPonPorts)
623 logger.Debugw(ctx, "received-port-stats-indication", log.Fields{"port-stats": PortStats})
Akash Kankanala041a2122024-10-16 15:49:22 +0530624 // Indicate that PortStatisticsIndication is handled
625 // PortStats.IntfId is actually the port number
kesavand62126212021-01-12 04:56:06 -0500626 StatMgr.processStatIndication(ctx, portStatsType, PortStats.IntfId)
Abhilash S.L765ad002019-04-24 16:40:57 +0530627 // TODO send stats to core topic to the voltha kafka or a different kafka ?
628}
629
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700630// FlowStatisticsIndication to be implemented
Neha Sharma96b7bf22020-06-15 10:37:32 +0000631func FlowStatisticsIndication(ctx context.Context, self, FlowStats *openolt.FlowStatistics) {
632 logger.Debugw(ctx, "flow-stats-collected", log.Fields{"flow-stats": FlowStats})
Akash Kankanala041a2122024-10-16 15:49:22 +0530633 // TODO send to kafka ?
Abhilash S.L765ad002019-04-24 16:40:57 +0530634}
635
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700636// PortsStatisticsKpis map the port stats values into a dictionary, creates the kpiEvent and then publish to Kafka
Akash Reddy Kankanalac6b6ca12025-06-12 14:26:57 +0530637func (StatMgr *OpenOltStatisticsMgr) PortsStatisticsKpis(ctx context.Context, PortStats *common.PortStatistics, NumPonPorts uint32) {
Abhilash S.L765ad002019-04-24 16:40:57 +0530638 /*map the port stats values into a dictionary
639 Create a kpoEvent and publish to Kafka
640
641 :param port_stats:
642 :return:
643 */
Akash Kankanala041a2122024-10-16 15:49:22 +0530644 // var err error
Abhilash S.L765ad002019-04-24 16:40:57 +0530645 IntfID := PortStats.IntfId
646
Mahir Gunyel85f61c12021-10-06 11:53:45 -0700647 if (plt.IntfIDToPortNo(1, voltha.Port_ETHERNET_NNI) < IntfID) &&
648 (IntfID < plt.IntfIDToPortNo(4, voltha.Port_ETHERNET_NNI)) {
Abhilash S.L765ad002019-04-24 16:40:57 +0530649 /*
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 Gunyel85f61c12021-10-06 11:53:45 -0700655 } else if plt.IntfIDToPortNo(0, voltha.Port_ETHERNET_NNI) == IntfID {
Naga Manjunath7615e552019-10-11 22:35:47 +0530656 var portNNIStat NniPort
657 portNNIStat.IntfID = IntfID
658 portNNIStat.PortNum = uint32(0)
659 portNNIStat.RxBytes = PortStats.RxBytes
660 portNNIStat.RxPackets = PortStats.RxPackets
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000661 portNNIStat.RxUcastPackets = PortStats.RxUcastPackets
Naga Manjunath7615e552019-10-11 22:35:47 +0530662 portNNIStat.RxMcastPackets = PortStats.RxMcastPackets
663 portNNIStat.RxBcastPackets = PortStats.RxBcastPackets
664 portNNIStat.TxBytes = PortStats.TxBytes
665 portNNIStat.TxPackets = PortStats.TxPackets
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000666 portNNIStat.TxUcastPackets = PortStats.TxUcastPackets
Naga Manjunath7615e552019-10-11 22:35:47 +0530667 portNNIStat.TxMcastPackets = PortStats.TxMcastPackets
668 portNNIStat.TxBcastPackets = PortStats.TxBcastPackets
669 mutex.Lock()
670 StatMgr.NorthBoundPort[0] = &portNNIStat
671 mutex.Unlock()
Neha Sharma96b7bf22020-06-15 10:37:32 +0000672 logger.Debugw(ctx, "received-nni-stats", log.Fields{"nni-stats": StatMgr.NorthBoundPort})
Naga Manjunath7615e552019-10-11 22:35:47 +0530673 }
674 for i := uint32(0); i < NumPonPorts; i++ {
Mahir Gunyel85f61c12021-10-06 11:53:45 -0700675 if plt.IntfIDToPortNo(i, voltha.Port_PON_OLT) == IntfID {
Naga Manjunath7615e552019-10-11 22:35:47 +0530676 var portPonStat PonPort
677 portPonStat.IntfID = IntfID
678 portPonStat.PortNum = i
679 portPonStat.PONID = i
680 portPonStat.RxBytes = PortStats.RxBytes
681 portPonStat.RxPackets = PortStats.RxPackets
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000682 portPonStat.RxUcastPackets = PortStats.RxUcastPackets
Naga Manjunath7615e552019-10-11 22:35:47 +0530683 portPonStat.RxMcastPackets = PortStats.RxMcastPackets
684 portPonStat.RxBcastPackets = PortStats.RxBcastPackets
685 portPonStat.TxBytes = PortStats.TxBytes
686 portPonStat.TxPackets = PortStats.TxPackets
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000687 portPonStat.TxUcastPackets = PortStats.TxUcastPackets
Naga Manjunath7615e552019-10-11 22:35:47 +0530688 portPonStat.TxMcastPackets = PortStats.TxMcastPackets
689 portPonStat.TxBcastPackets = PortStats.TxBcastPackets
690 mutex.Lock()
691 StatMgr.SouthBoundPort[i] = &portPonStat
692 mutex.Unlock()
Neha Sharma96b7bf22020-06-15 10:37:32 +0000693 logger.Debugw(ctx, "received-pon-stats-for-port", log.Fields{"port-pon-stats": portPonStat})
Naga Manjunath7615e552019-10-11 22:35:47 +0530694 }
695 }
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700696 /*
697 Based upon the intf_id map to an nni port or a pon port
698 the intf_id is the key to the north or south bound collections
699
700 Based upon the intf_id the port object (nni_port or pon_port) will
701 have its data attr. updated by the current dataset collected.
702
703 For prefixing the rule is currently to use the port number and not the intf_id
704 */
Akash Kankanala041a2122024-10-16 15:49:22 +0530705 // FIXME : Just use first NNI for now
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700706 /* TODO should the data be marshaled before sending it ?
707 if IntfID == IntfIdToPortNo(0, voltha.Port_ETHERNET_NNI) {
708 //NNI port (just the first one)
709 err = UpdatePortObjectKpiData(StatMgr.NorthBoundPorts[PortStats.IntfID], PMData)
710 } else {
711 //PON ports
712 err = UpdatePortObjectKpiData(SouthboundPorts[PortStats.IntfID], PMData)
713 }
714 if (err != nil) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000715 logger.Error(ctx, "Error publishing statistics data")
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700716 }
717 */
Abhilash S.L765ad002019-04-24 16:40:57 +0530718}
kesavand62126212021-01-12 04:56:06 -0500719
720func (StatMgr *OpenOltStatisticsMgr) updateGetOltPortCountersResponse(ctx context.Context, singleValResp *extension.SingleGetValueResponse, stats map[string]float32) {
kesavand62126212021-01-12 04:56:06 -0500721 metrics := singleValResp.GetResponse().GetPortCoutners()
722 metrics.TxBytes = uint64(stats["TxBytes"])
723 metrics.RxBytes = uint64(stats["RxBytes"])
724 metrics.TxPackets = uint64(stats["TxPackets"])
725 metrics.RxPackets = uint64(stats["RxPackets"])
726 metrics.TxErrorPackets = uint64(stats["TxErrorPackets"])
727 metrics.RxErrorPackets = uint64(stats["RxErrorPackets"])
728 metrics.TxBcastPackets = uint64(stats["TxBcastPackets"])
729 metrics.RxBcastPackets = uint64(stats["RxBcastPackets"])
730 metrics.TxUcastPackets = uint64(stats["TxUcastPackets"])
731 metrics.RxUcastPackets = uint64(stats["RxUcastPackets"])
732 metrics.TxMcastPackets = uint64(stats["TxMcastPackets"])
733 metrics.RxMcastPackets = uint64(stats["RxMcastPackets"])
734
735 singleValResp.Response.Status = extension.GetValueResponse_OK
736 logger.Debugw(ctx, "updateGetOltPortCountersResponse", log.Fields{"resp": singleValResp})
737}
738
Joey Armstrong3f0e2422023-07-05 18:25:41 -0400739// RegisterForStatIndication registers ch as a channel on which indication is sent when statistics of type t is received
kesavand62126212021-01-12 04:56:06 -0500740func (StatMgr *OpenOltStatisticsMgr) RegisterForStatIndication(ctx context.Context, t StatType, ch chan bool, portNo uint32, portType extension.GetOltPortCounters_PortType) {
741 statInd := statRegInfo{
742 chn: ch,
743 portNo: portNo,
744 portType: portType,
745 }
746
747 logger.Debugf(ctx, "RegisterForStatIndication stat type %v portno %v porttype %v chan %v", t, portNo, portType, ch)
748 StatMgr.statIndListnerMu.Lock()
749 StatMgr.statIndListners[t].PushBack(statInd)
750 StatMgr.statIndListnerMu.Unlock()
kesavand62126212021-01-12 04:56:06 -0500751}
752
Joey Armstrong3f0e2422023-07-05 18:25:41 -0400753// DeRegisterFromStatIndication removes the previously registered channel ch for type t of statistics
kesavand62126212021-01-12 04:56:06 -0500754func (StatMgr *OpenOltStatisticsMgr) DeRegisterFromStatIndication(ctx context.Context, t StatType, ch chan bool) {
755 StatMgr.statIndListnerMu.Lock()
756 defer StatMgr.statIndListnerMu.Unlock()
757
758 for e := StatMgr.statIndListners[t].Front(); e != nil; e = e.Next() {
759 statInd := e.Value.(statRegInfo)
760 if statInd.chn == ch {
761 StatMgr.statIndListners[t].Remove(e)
762 return
763 }
764 }
765}
766
767func (StatMgr *OpenOltStatisticsMgr) processStatIndication(ctx context.Context, t StatType, portNo uint32) {
768 var deRegList []*list.Element
769 var statInd statRegInfo
770
771 StatMgr.statIndListnerMu.Lock()
772 defer StatMgr.statIndListnerMu.Unlock()
773
774 if StatMgr.statIndListners[t] == nil || StatMgr.statIndListners[t].Len() == 0 {
775 logger.Debugf(ctx, "processStatIndication %v list is empty ", t)
776 return
777 }
778
779 for e := StatMgr.statIndListners[t].Front(); e != nil; e = e.Next() {
780 statInd = e.Value.(statRegInfo)
781 if statInd.portNo != portNo {
782 fmt.Printf("Skipping %v\n", e.Value)
783 continue
784 }
785 // message sent
786 statInd.chn <- true
787 deRegList = append(deRegList, e)
kesavand62126212021-01-12 04:56:06 -0500788 }
789 for _, e := range deRegList {
790 StatMgr.statIndListners[t].Remove(e)
791 }
kesavand62126212021-01-12 04:56:06 -0500792}
Himani Chawla2c8ae0f2021-05-18 23:27:00 +0530793
794func (StatMgr *OpenOltStatisticsMgr) updateGetOnuPonCountersResponse(ctx context.Context, singleValResp *extension.SingleGetValueResponse, stats map[string]float32) {
Himani Chawla2c8ae0f2021-05-18 23:27:00 +0530795 metrics := singleValResp.GetResponse().GetOnuPonCounters()
796 metrics.IsIntfId = &extension.GetOnuCountersResponse_IntfId{
797 IntfId: uint32(stats[IntfID]),
798 }
799 metrics.IsOnuId = &extension.GetOnuCountersResponse_OnuId{
800 OnuId: uint32(stats[OnuID]),
801 }
802 metrics.IsPositiveDrift = &extension.GetOnuCountersResponse_PositiveDrift{
803 PositiveDrift: uint64(stats[PositiveDrift]),
804 }
805 metrics.IsNegativeDrift = &extension.GetOnuCountersResponse_NegativeDrift{
806 NegativeDrift: uint64(stats[NegativeDrift]),
807 }
808 metrics.IsDelimiterMissDetection = &extension.GetOnuCountersResponse_DelimiterMissDetection{
809 DelimiterMissDetection: uint64(stats[DelimiterMissDetection]),
810 }
811 metrics.IsBipErrors = &extension.GetOnuCountersResponse_BipErrors{
812 BipErrors: uint64(stats[BipErrors]),
813 }
814 metrics.IsBipUnits = &extension.GetOnuCountersResponse_BipUnits{
815 BipUnits: uint64(stats[BipUnits]),
816 }
817 metrics.IsFecCorrectedSymbols = &extension.GetOnuCountersResponse_FecCorrectedSymbols{
818 FecCorrectedSymbols: uint64(stats[FecCorrectedSymbols]),
819 }
820 metrics.IsFecCodewordsCorrected = &extension.GetOnuCountersResponse_FecCodewordsCorrected{
821 FecCodewordsCorrected: uint64(stats[FecCodewordsCorrected]),
822 }
823 metrics.IsFecCodewordsUncorrectable = &extension.GetOnuCountersResponse_FecCodewordsUncorrectable{
824 FecCodewordsUncorrectable: uint64(stats[fecCodewordsUncorrectable]),
825 }
826 metrics.IsFecCodewords = &extension.GetOnuCountersResponse_FecCodewords{
827 FecCodewords: uint64(stats[FecCodewords]),
828 }
829 metrics.IsFecCorrectedUnits = &extension.GetOnuCountersResponse_FecCorrectedUnits{
830 FecCorrectedUnits: uint64(stats[FecCorrectedUnits]),
831 }
832 metrics.IsXgemKeyErrors = &extension.GetOnuCountersResponse_XgemKeyErrors{
833 XgemKeyErrors: uint64(stats[XGEMKeyErrors]),
834 }
835 metrics.IsXgemLoss = &extension.GetOnuCountersResponse_XgemLoss{
836 XgemLoss: uint64(stats[XGEMLoss]),
837 }
838 metrics.IsRxPloamsError = &extension.GetOnuCountersResponse_RxPloamsError{
839 RxPloamsError: uint64(stats[RxPloamsError]),
840 }
841 metrics.IsRxPloamsNonIdle = &extension.GetOnuCountersResponse_RxPloamsNonIdle{
842 RxPloamsNonIdle: uint64(stats[RxPloamsNonIdle]),
843 }
844 metrics.IsRxOmci = &extension.GetOnuCountersResponse_RxOmci{
845 RxOmci: uint64(stats[RxOmci]),
846 }
847 metrics.IsRxOmciPacketsCrcError = &extension.GetOnuCountersResponse_RxOmciPacketsCrcError{
848 RxOmciPacketsCrcError: uint64(stats[RxOmciPacketsCrcError]),
849 }
850 metrics.IsRxBytes = &extension.GetOnuCountersResponse_RxBytes{
851 RxBytes: uint64(stats[RxBytes]),
852 }
853 metrics.IsRxPackets = &extension.GetOnuCountersResponse_RxPackets{
854 RxPackets: uint64(stats[RxPackets]),
855 }
856 metrics.IsTxBytes = &extension.GetOnuCountersResponse_TxBytes{
857 TxBytes: uint64(stats[TxBytes]),
858 }
859 metrics.IsTxPackets = &extension.GetOnuCountersResponse_TxPackets{
860 TxPackets: uint64(stats[TxPackets]),
861 }
862 metrics.IsBerReported = &extension.GetOnuCountersResponse_BerReported{
863 BerReported: uint64(stats[BerReported]),
864 }
865 metrics.IsLcdgErrors = &extension.GetOnuCountersResponse_LcdgErrors{
866 LcdgErrors: uint64(stats[LcdgErrors]),
867 }
868 metrics.IsRdiErrors = &extension.GetOnuCountersResponse_RdiErrors{
869 RdiErrors: uint64(stats[RdiErrors]),
870 }
871 metrics.IsTimestamp = &extension.GetOnuCountersResponse_Timestamp{
872 Timestamp: uint32(stats[Timestamp]),
873 }
874
875 singleValResp.Response.Status = extension.GetValueResponse_OK
876 logger.Debugw(ctx, "updateGetOnuPonCountersResponse", log.Fields{"resp": singleValResp})
877}