blob: 31f9804d0212fcf5b564ce84fd079cdace36e432 [file] [log] [blame]
Abhilash S.L765ad002019-04-24 16:40:57 +05301/*
2 * Copyright 2019-present Open Networking Foundation
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 Gowdru6a80bbd2019-07-02 07:36:09 -070016
Scott Bakerdbd960e2020-02-28 08:57:51 -080017//Package core provides the utility for olt devices, flows and statistics
18package core
Abhilash S.L765ad002019-04-24 16:40:57 +053019
20import (
Abhilash S.L765ad002019-04-24 16:40:57 +053021 "fmt"
Esin Karamanccb714b2019-11-29 15:02:06 +000022 "github.com/opencord/voltha-lib-go/v3/pkg/log"
Thomas Lee S94109f12020-03-03 16:39:29 +053023 "github.com/opencord/voltha-openolt-adapter/internal/pkg/olterrors"
Esin Karamanccb714b2019-11-29 15:02:06 +000024 "github.com/opencord/voltha-protos/v3/go/openolt"
25 "github.com/opencord/voltha-protos/v3/go/voltha"
David K. Bainbridge794735f2020-02-11 21:01:37 -080026 "sync"
27 "time"
Abhilash S.L765ad002019-04-24 16:40:57 +053028)
29
Naga Manjunath7615e552019-10-11 22:35:47 +053030var mutex = &sync.Mutex{}
31
Girish Gowdru6a80bbd2019-07-02 07:36:09 -070032// PonPort representation
Abhilash S.L765ad002019-04-24 16:40:57 +053033type PonPort struct {
34 /*
35 This is a highly reduced version taken from the adtran pon_port.
36 TODO: Extend for use in the openolt adapter set.
37 */
38 /* MAX_ONUS_SUPPORTED = 256
39 DEFAULT_ENABLED = False
40 MAX_DEPLOYMENT_RANGE = 25000 # Meters (OLT-PB maximum)
41
42 _MCAST_ONU_ID = 253
43 _MCAST_ALLOC_BASE = 0x500
44
45 _SUPPORTED_ACTIVATION_METHODS = ['autodiscovery'] # , 'autoactivate']
46 _SUPPORTED_AUTHENTICATION_METHODS = ['serial-number']
47 */
48 PONID uint32
49 DeviceID string
50 IntfID uint32
51 PortNum uint32
52 PortID uint32
53 Label string
54 ONUs map[uint32]interface{}
55 ONUsByID map[uint32]interface{}
56
57 RxBytes uint64
58 RxPackets uint64
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +000059 RxUcastPackets uint64
Abhilash S.L765ad002019-04-24 16:40:57 +053060 RxMcastPackets uint64
61 RxBcastPackets uint64
62 RxErrorPackets uint64
63 TxBytes uint64
64 TxPackets uint64
65 TxUcastPackets uint64
66 TxMcastPackets uint64
67 TxBcastPackets uint64
68 TxErrorPackets uint64
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +000069 RxCrcErrors uint64
70 BipErrors uint64
Abhilash S.L765ad002019-04-24 16:40:57 +053071}
72
Girish Gowdru6a80bbd2019-07-02 07:36:09 -070073// NewPONPort returns a new instance of PonPort initialized with given PONID, DeviceID, IntfID and PortNum
Abhilash S.L765ad002019-04-24 16:40:57 +053074func NewPONPort(PONID uint32, DeviceID string, IntfID uint32, PortNum uint32) *PonPort {
75
76 var PON PonPort
77
78 PON.PONID = PONID
79 PON.DeviceID = DeviceID
80 PON.IntfID = IntfID
81 PON.PortNum = PortNum
82 PON.PortID = 0
Naga Manjunath7615e552019-10-11 22:35:47 +053083 PON.Label = fmt.Sprintf("%s%d", "pon-", PONID)
Abhilash S.L765ad002019-04-24 16:40:57 +053084
85 PON.ONUs = make(map[uint32]interface{})
86 PON.ONUsByID = make(map[uint32]interface{})
87
88 /*
89 Statistics taken from nni_port
90 self.intf_id = 0 #handled by getter
91 self.port_no = 0 #handled by getter
92 self.port_id = 0 #handled by getter
93
94 Note: In the current implementation of the kpis coming from the BAL the stats are the
95 samne model for NNI and PON.
96
97 TODO: Integrate additional kpis for the PON and other southbound port objecgts.
98
99 */
100
101 PON.RxBytes = 0
102 PON.RxPackets = 0
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000103 PON.RxUcastPackets = 0
Abhilash S.L765ad002019-04-24 16:40:57 +0530104 PON.RxMcastPackets = 0
105 PON.RxBcastPackets = 0
106 PON.RxErrorPackets = 0
107 PON.TxBytes = 0
108 PON.TxPackets = 0
109 PON.TxUcastPackets = 0
110 PON.TxMcastPackets = 0
111 PON.TxBcastPackets = 0
112 PON.TxErrorPackets = 0
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000113 PON.RxCrcErrors = 0
114 PON.BipErrors = 0
Abhilash S.L765ad002019-04-24 16:40:57 +0530115
116 /* def __str__(self):
117 return "PonPort-{}: Admin: {}, Oper: {}, OLT: {}".format(self._label,
118 self._admin_state,
119 self._oper_status,
120 self.olt)
121 */
122 return &PON
123}
124
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700125// NniPort representation
Abhilash S.L765ad002019-04-24 16:40:57 +0530126type NniPort struct {
127 /*
128 Northbound network port, often Ethernet-based
129
130 This is a highly reduced version taken from the adtran nni_port code set
131 TODO: add functions to allow for port specific values and operations
132 */
133 PortNum uint32
134 Name string
135 LogicalPort uint32
136 IntfID uint32
137
138 RxBytes uint64
139 RxPackets uint64
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000140 RxUcastPackets uint64
Abhilash S.L765ad002019-04-24 16:40:57 +0530141 RxMcastPackets uint64
142 RxBcastPackets uint64
143 RxErrorPackets uint64
144 TxBytes uint64
145 TxPackets uint64
146 TxUcastPackets uint64
147 TxMcastPackets uint64
148 TxBcastPackets uint64
149 TxErrorPackets uint64
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000150 RxCrcErrors uint64
151 BipErrors uint64
Abhilash S.L765ad002019-04-24 16:40:57 +0530152}
153
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700154// NewNniPort returns a new instance of NniPort initialized with the given PortNum and IntfID
Abhilash S.L765ad002019-04-24 16:40:57 +0530155func NewNniPort(PortNum uint32, IntfID uint32) *NniPort {
156
157 var NNI NniPort
158
159 NNI.PortNum = PortNum
Naga Manjunath7615e552019-10-11 22:35:47 +0530160 NNI.Name = fmt.Sprintf("%s%d", "nni-", PortNum)
Abhilash S.L765ad002019-04-24 16:40:57 +0530161 NNI.IntfID = IntfID
162
163 NNI.RxBytes = 0
164 NNI.RxPackets = 0
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000165 NNI.RxUcastPackets = 0
Abhilash S.L765ad002019-04-24 16:40:57 +0530166 NNI.RxMcastPackets = 0
167 NNI.RxBcastPackets = 0
168 NNI.RxErrorPackets = 0
169 NNI.TxBytes = 0
170 NNI.TxPackets = 0
171 NNI.TxUcastPackets = 0
172 NNI.TxMcastPackets = 0
173 NNI.TxBcastPackets = 0
174 NNI.TxErrorPackets = 0
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000175 NNI.RxCrcErrors = 0
176 NNI.BipErrors = 0
Abhilash S.L765ad002019-04-24 16:40:57 +0530177
178 return &NNI
179}
180
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700181// OpenOltStatisticsMgr structure
Abhilash S.L765ad002019-04-24 16:40:57 +0530182type OpenOltStatisticsMgr struct {
183 Device *DeviceHandler
Naga Manjunath7615e552019-10-11 22:35:47 +0530184 NorthBoundPort map[uint32]*NniPort
185 SouthBoundPort map[uint32]*PonPort
Abhilash S.L765ad002019-04-24 16:40:57 +0530186 // TODO PMMetrics Metrics
187}
188
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700189// NewOpenOltStatsMgr returns a new instance of the OpenOltStatisticsMgr
Abhilash S.L765ad002019-04-24 16:40:57 +0530190func NewOpenOltStatsMgr(Dev *DeviceHandler) *OpenOltStatisticsMgr {
191
192 var StatMgr OpenOltStatisticsMgr
193
194 StatMgr.Device = Dev
195 // TODO call metric PMMetric =
196 // Northbound and Southbound ports
197 // added to initialize the pm_metrics
198 var Ports interface{}
Naga Manjunath7615e552019-10-11 22:35:47 +0530199 Ports, _ = InitPorts("nni", Dev.deviceID, 1)
200 StatMgr.NorthBoundPort, _ = Ports.(map[uint32]*NniPort)
201 NumPonPorts := Dev.resourceMgr.DevInfo.GetPonPorts()
202 Ports, _ = InitPorts("pon", Dev.deviceID, NumPonPorts)
203 StatMgr.SouthBoundPort, _ = Ports.(map[uint32]*PonPort)
Abhilash S.L765ad002019-04-24 16:40:57 +0530204 return &StatMgr
205}
206
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700207// InitPorts collects the port objects: nni and pon that are updated with the current data from the OLT
Naga Manjunath7615e552019-10-11 22:35:47 +0530208func InitPorts(Intftype string, DeviceID string, numOfPorts uint32) (interface{}, error) {
Abhilash S.L765ad002019-04-24 16:40:57 +0530209 /*
210 This method collects the port objects: nni and pon that are updated with the
211 current data from the OLT
212
213 Both the northbound (nni) and southbound ports are indexed by the interface id (intf_id)
214 and NOT the port number. When the port object is instantiated it will contain the intf_id and
215 port_no values
216
217 :param type:
218 :return:
219 */
220 var i uint32
221 if Intftype == "nni" {
Naga Manjunath7615e552019-10-11 22:35:47 +0530222 NniPorts := make(map[uint32]*NniPort)
223 for i = 0; i < numOfPorts; i++ {
kdarapu768708d2019-09-16 23:19:15 +0530224 Port := BuildPortObject(i, "nni", DeviceID).(*NniPort)
Naga Manjunath7615e552019-10-11 22:35:47 +0530225 NniPorts[Port.IntfID] = Port
Abhilash S.L765ad002019-04-24 16:40:57 +0530226 }
227 return NniPorts, nil
228 } else if Intftype == "pon" {
Naga Manjunath7615e552019-10-11 22:35:47 +0530229 PONPorts := make(map[uint32]*PonPort)
230 for i = 0; i < numOfPorts; i++ {
kdarapu768708d2019-09-16 23:19:15 +0530231 PONPort := BuildPortObject(i, "pon", DeviceID).(*PonPort)
Naga Manjunath7615e552019-10-11 22:35:47 +0530232 PONPorts[PortNoToIntfID(PONPort.IntfID, voltha.Port_PON_OLT)] = PONPort
Abhilash S.L765ad002019-04-24 16:40:57 +0530233 }
234 return PONPorts, nil
235 } else {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000236 logger.Errorf("Invalid type of interface %s", Intftype)
Thomas Lee S94109f12020-03-03 16:39:29 +0530237 return nil, olterrors.NewErrInvalidValue(log.Fields{"interface-type": Intftype}, nil)
Abhilash S.L765ad002019-04-24 16:40:57 +0530238 }
239}
240
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700241// BuildPortObject allows for updating north and southbound ports, newly discovered ports, and devices
Abhilash S.L765ad002019-04-24 16:40:57 +0530242func BuildPortObject(PortNum uint32, IntfType string, DeviceID string) interface{} {
243 /*
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700244 Separate method to allow for updating north and southbound ports
Abhilash S.L765ad002019-04-24 16:40:57 +0530245 newly discovered ports and devices
246
247 :param port_num:
248 :param type:
249 :return:
250 */
251
252 //This builds a port object which is added to the
253 //appropriate northbound or southbound values
254 if IntfType == "nni" {
Naga Manjunath7615e552019-10-11 22:35:47 +0530255 IntfID := IntfIDToPortNo(PortNum, voltha.Port_ETHERNET_NNI)
256 nniID := PortNoToIntfID(IntfID, voltha.Port_ETHERNET_NNI)
Girish Kumar2ad402b2020-03-20 19:45:12 +0000257 logger.Debugf("NniID %v", nniID)
Naga Manjunath7615e552019-10-11 22:35:47 +0530258 return NewNniPort(PortNum, nniID)
Abhilash S.L765ad002019-04-24 16:40:57 +0530259 } else if IntfType == "pon" {
260 // PON ports require a different configuration
261 // intf_id and pon_id are currently equal.
Naga Manjunath7615e552019-10-11 22:35:47 +0530262 IntfID := IntfIDToPortNo(PortNum, voltha.Port_PON_OLT)
263 PONID := PortNoToIntfID(IntfID, voltha.Port_PON_OLT)
Girish Kumar2ad402b2020-03-20 19:45:12 +0000264 logger.Debugf("PonID %v", PONID)
Abhilash S.L765ad002019-04-24 16:40:57 +0530265 return NewPONPort(PONID, DeviceID, IntfID, PortNum)
266 } else {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000267 logger.Errorf("Invalid type of interface %s", IntfType)
Abhilash S.L765ad002019-04-24 16:40:57 +0530268 return nil
269 }
270}
271
Naga Manjunath7615e552019-10-11 22:35:47 +0530272// collectNNIMetrics will collect the nni port metrics
273func (StatMgr *OpenOltStatisticsMgr) collectNNIMetrics(nniID uint32) map[string]float32 {
274
275 nnival := make(map[string]float32)
276 mutex.Lock()
277 cm := StatMgr.Device.portStats.NorthBoundPort[nniID]
278 mutex.Unlock()
279 metricName := StatMgr.Device.metrics.GetSubscriberMetrics()
280
281 if metricName != nil && len(metricName) > 0 {
282 for mName := range metricName {
283 switch mName {
284 case "rx_bytes":
285 nnival["RxBytes"] = float32(cm.RxBytes)
286 case "rx_packets":
287 nnival["RxPackets"] = float32(cm.RxPackets)
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000288 case "rx_ucast_packets":
289 nnival["RxUcastPackets"] = float32(cm.RxUcastPackets)
Naga Manjunath7615e552019-10-11 22:35:47 +0530290 case "rx_mcast_packets":
291 nnival["RxMcastPackets"] = float32(cm.RxMcastPackets)
292 case "rx_bcast_packets":
293 nnival["RxBcastPackets"] = float32(cm.RxBcastPackets)
294 case "tx_bytes":
295 nnival["TxBytes"] = float32(cm.TxBytes)
296 case "tx_packets":
297 nnival["TxPackets"] = float32(cm.TxPackets)
298 case "tx_mcast_packets":
299 nnival["TxMcastPackets"] = float32(cm.TxMcastPackets)
300 case "tx_bcast_packets":
301 nnival["TxBcastPackets"] = float32(cm.TxBcastPackets)
302 }
303 }
304 }
305 return nnival
306}
307
308// collectPONMetrics will collect the pon port metrics
309func (StatMgr *OpenOltStatisticsMgr) collectPONMetrics(pID uint32) map[string]float32 {
310
311 ponval := make(map[string]float32)
312 mutex.Lock()
313 cm := StatMgr.Device.portStats.SouthBoundPort[pID]
314 mutex.Unlock()
315 metricName := StatMgr.Device.metrics.GetSubscriberMetrics()
316
317 if metricName != nil && len(metricName) > 0 {
318 for mName := range metricName {
319 switch mName {
320 case "rx_bytes":
321 ponval["RxBytes"] = float32(cm.RxBytes)
322 case "rx_packets":
323 ponval["RxPackets"] = float32(cm.RxPackets)
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000324 // these are not supported in OpenOlt Agent now
325 // will return zero until supported
326 case "rx_ucast_packets":
327 ponval["RxUcastPackets"] = float32(cm.RxUcastPackets)
Naga Manjunath7615e552019-10-11 22:35:47 +0530328 case "rx_mcast_packets":
329 ponval["RxMcastPackets"] = float32(cm.RxMcastPackets)
330 case "rx_bcast_packets":
331 ponval["RxBcastPackets"] = float32(cm.RxBcastPackets)
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000332 // End will return zero until supported
Naga Manjunath7615e552019-10-11 22:35:47 +0530333 case "tx_bytes":
334 ponval["TxBytes"] = float32(cm.TxBytes)
335 case "tx_packets":
336 ponval["TxPackets"] = float32(cm.TxPackets)
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000337 // these are not supported in OpenOlt Agent now
338 // will return zero until supported
339 case "tx_ucast_packets":
340 ponval["TxUcastPackets"] = float32(cm.TxUcastPackets)
Naga Manjunath7615e552019-10-11 22:35:47 +0530341 case "tx_mcast_packets":
342 ponval["TxMcastPackets"] = float32(cm.TxMcastPackets)
343 case "tx_bcast_packets":
344 ponval["TxBcastPackets"] = float32(cm.TxBcastPackets)
345 }
346 }
347 }
348 return ponval
349}
350
351// publishMatrics will publish the pon port metrics
352func (StatMgr OpenOltStatisticsMgr) publishMetrics(portType string, val map[string]float32, portnum uint32, context map[string]string, devID string) {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000353 logger.Debugf("Post-%v %v", portType, val)
Naga Manjunath7615e552019-10-11 22:35:47 +0530354
355 var metricInfo voltha.MetricInformation
356 var ke voltha.KpiEvent2
Esin Karamanccb714b2019-11-29 15:02:06 +0000357 var volthaEventSubCatgry voltha.EventSubCategory_Types
Naga Manjunath7615e552019-10-11 22:35:47 +0530358
359 if portType == "NNIStats" {
360 volthaEventSubCatgry = voltha.EventSubCategory_NNI
361 } else {
362 volthaEventSubCatgry = voltha.EventSubCategory_PON
363 }
364
365 raisedTs := time.Now().UnixNano()
366 mmd := voltha.MetricMetaData{
367 Title: portType,
368 Ts: float64(raisedTs),
369 Context: context,
370 DeviceId: devID,
371 }
372
373 metricInfo.Metadata = &mmd
374 metricInfo.Metrics = val
375
376 ke.SliceData = []*voltha.MetricInformation{&metricInfo}
377 ke.Type = voltha.KpiEventType_slice
378 ke.Ts = float64(time.Now().UnixNano())
379
380 if err := StatMgr.Device.EventProxy.SendKpiEvent("STATS_EVENT", &ke, voltha.EventCategory_EQUIPMENT, volthaEventSubCatgry, raisedTs); err != nil {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000381 logger.Errorw("Failed to send Pon stats", log.Fields{"err": err})
Naga Manjunath7615e552019-10-11 22:35:47 +0530382 }
383
384}
385
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700386// PortStatisticsIndication handles the port statistics indication
Naga Manjunath7615e552019-10-11 22:35:47 +0530387func (StatMgr *OpenOltStatisticsMgr) PortStatisticsIndication(PortStats *openolt.PortStatistics, NumPonPorts uint32) {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000388 logger.Debugf("port-stats-collected %v", PortStats)
Naga Manjunath7615e552019-10-11 22:35:47 +0530389 StatMgr.PortsStatisticsKpis(PortStats, NumPonPorts)
Girish Kumar2ad402b2020-03-20 19:45:12 +0000390 logger.Infow("Received port stats indication", log.Fields{"PortStats": PortStats})
Abhilash S.L765ad002019-04-24 16:40:57 +0530391 // TODO send stats to core topic to the voltha kafka or a different kafka ?
392}
393
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700394// FlowStatisticsIndication to be implemented
Abhilash S.L765ad002019-04-24 16:40:57 +0530395func FlowStatisticsIndication(self, FlowStats *openolt.FlowStatistics) {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000396 logger.Debugf("flow-stats-collected %v", FlowStats)
Abhilash S.L765ad002019-04-24 16:40:57 +0530397 //TODO send to kafka ?
398}
399
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700400// PortsStatisticsKpis map the port stats values into a dictionary, creates the kpiEvent and then publish to Kafka
Naga Manjunath7615e552019-10-11 22:35:47 +0530401func (StatMgr *OpenOltStatisticsMgr) PortsStatisticsKpis(PortStats *openolt.PortStatistics, NumPonPorts uint32) {
Abhilash S.L765ad002019-04-24 16:40:57 +0530402
403 /*map the port stats values into a dictionary
404 Create a kpoEvent and publish to Kafka
405
406 :param port_stats:
407 :return:
408 */
409 //var err error
410 IntfID := PortStats.IntfId
411
Naga Manjunath7615e552019-10-11 22:35:47 +0530412 if (IntfIDToPortNo(1, voltha.Port_ETHERNET_NNI) < IntfID) &&
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700413 (IntfID < IntfIDToPortNo(4, voltha.Port_ETHERNET_NNI)) {
Abhilash S.L765ad002019-04-24 16:40:57 +0530414 /*
415 for this release we are only interested in the first NNI for
416 Northbound.
417 we are not using the other 3
418 */
419 return
Naga Manjunath7615e552019-10-11 22:35:47 +0530420 } else if IntfIDToPortNo(0, voltha.Port_ETHERNET_NNI) == IntfID {
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700421
Naga Manjunath7615e552019-10-11 22:35:47 +0530422 var portNNIStat NniPort
423 portNNIStat.IntfID = IntfID
424 portNNIStat.PortNum = uint32(0)
425 portNNIStat.RxBytes = PortStats.RxBytes
426 portNNIStat.RxPackets = PortStats.RxPackets
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000427 portNNIStat.RxUcastPackets = PortStats.RxUcastPackets
Naga Manjunath7615e552019-10-11 22:35:47 +0530428 portNNIStat.RxMcastPackets = PortStats.RxMcastPackets
429 portNNIStat.RxBcastPackets = PortStats.RxBcastPackets
430 portNNIStat.TxBytes = PortStats.TxBytes
431 portNNIStat.TxPackets = PortStats.TxPackets
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000432 portNNIStat.TxUcastPackets = PortStats.TxUcastPackets
Naga Manjunath7615e552019-10-11 22:35:47 +0530433 portNNIStat.TxMcastPackets = PortStats.TxMcastPackets
434 portNNIStat.TxBcastPackets = PortStats.TxBcastPackets
435 mutex.Lock()
436 StatMgr.NorthBoundPort[0] = &portNNIStat
437 mutex.Unlock()
Girish Kumar2ad402b2020-03-20 19:45:12 +0000438 logger.Debugf("Received-NNI-Stats: %v", StatMgr.NorthBoundPort)
Naga Manjunath7615e552019-10-11 22:35:47 +0530439 }
440 for i := uint32(0); i < NumPonPorts; i++ {
441
442 if IntfIDToPortNo(i, voltha.Port_PON_OLT) == IntfID {
443 var portPonStat PonPort
444 portPonStat.IntfID = IntfID
445 portPonStat.PortNum = i
446 portPonStat.PONID = i
447 portPonStat.RxBytes = PortStats.RxBytes
448 portPonStat.RxPackets = PortStats.RxPackets
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000449 portPonStat.RxUcastPackets = PortStats.RxUcastPackets
Naga Manjunath7615e552019-10-11 22:35:47 +0530450 portPonStat.RxMcastPackets = PortStats.RxMcastPackets
451 portPonStat.RxBcastPackets = PortStats.RxBcastPackets
452 portPonStat.TxBytes = PortStats.TxBytes
453 portPonStat.TxPackets = PortStats.TxPackets
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000454 portPonStat.TxUcastPackets = PortStats.TxUcastPackets
Naga Manjunath7615e552019-10-11 22:35:47 +0530455 portPonStat.TxMcastPackets = PortStats.TxMcastPackets
456 portPonStat.TxBcastPackets = PortStats.TxBcastPackets
457 mutex.Lock()
458 StatMgr.SouthBoundPort[i] = &portPonStat
459 mutex.Unlock()
Girish Kumar2ad402b2020-03-20 19:45:12 +0000460 logger.Debugf("Received-PON-Stats-for-Port %v : %v", i, StatMgr.SouthBoundPort[i])
Naga Manjunath7615e552019-10-11 22:35:47 +0530461 }
462 }
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700463
464 /*
465 Based upon the intf_id map to an nni port or a pon port
466 the intf_id is the key to the north or south bound collections
467
468 Based upon the intf_id the port object (nni_port or pon_port) will
469 have its data attr. updated by the current dataset collected.
470
471 For prefixing the rule is currently to use the port number and not the intf_id
472 */
473 //FIXME : Just use first NNI for now
474 /* TODO should the data be marshaled before sending it ?
475 if IntfID == IntfIdToPortNo(0, voltha.Port_ETHERNET_NNI) {
476 //NNI port (just the first one)
477 err = UpdatePortObjectKpiData(StatMgr.NorthBoundPorts[PortStats.IntfID], PMData)
478 } else {
479 //PON ports
480 err = UpdatePortObjectKpiData(SouthboundPorts[PortStats.IntfID], PMData)
481 }
482 if (err != nil) {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000483 logger.Error("Error publishing statistics data")
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700484 }
485 */
486
Abhilash S.L765ad002019-04-24 16:40:57 +0530487}