blob: 3512f8905751a957552d4dfdd26e94e68e58a11c [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"
Shrey Baid26912972020-04-16 21:02:31 +053022 "sync"
23 "time"
24
25 "strconv"
26
Esin Karamanccb714b2019-11-29 15:02:06 +000027 "github.com/opencord/voltha-lib-go/v3/pkg/log"
Thomas Lee S94109f12020-03-03 16:39:29 +053028 "github.com/opencord/voltha-openolt-adapter/internal/pkg/olterrors"
Esin Karamanccb714b2019-11-29 15:02:06 +000029 "github.com/opencord/voltha-protos/v3/go/openolt"
30 "github.com/opencord/voltha-protos/v3/go/voltha"
Abhilash S.L765ad002019-04-24 16:40:57 +053031)
32
Naga Manjunath7615e552019-10-11 22:35:47 +053033var mutex = &sync.Mutex{}
34
Girish Gowdru6a80bbd2019-07-02 07:36:09 -070035// PonPort representation
Abhilash S.L765ad002019-04-24 16:40:57 +053036type PonPort struct {
37 /*
38 This is a highly reduced version taken from the adtran pon_port.
39 TODO: Extend for use in the openolt adapter set.
40 */
41 /* MAX_ONUS_SUPPORTED = 256
42 DEFAULT_ENABLED = False
43 MAX_DEPLOYMENT_RANGE = 25000 # Meters (OLT-PB maximum)
44
45 _MCAST_ONU_ID = 253
46 _MCAST_ALLOC_BASE = 0x500
47
48 _SUPPORTED_ACTIVATION_METHODS = ['autodiscovery'] # , 'autoactivate']
49 _SUPPORTED_AUTHENTICATION_METHODS = ['serial-number']
50 */
51 PONID uint32
52 DeviceID string
53 IntfID uint32
54 PortNum uint32
55 PortID uint32
56 Label string
57 ONUs map[uint32]interface{}
58 ONUsByID map[uint32]interface{}
59
60 RxBytes uint64
61 RxPackets uint64
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +000062 RxUcastPackets uint64
Abhilash S.L765ad002019-04-24 16:40:57 +053063 RxMcastPackets uint64
64 RxBcastPackets uint64
65 RxErrorPackets uint64
66 TxBytes uint64
67 TxPackets uint64
68 TxUcastPackets uint64
69 TxMcastPackets uint64
70 TxBcastPackets uint64
71 TxErrorPackets uint64
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +000072 RxCrcErrors uint64
73 BipErrors uint64
Abhilash S.L765ad002019-04-24 16:40:57 +053074}
75
Girish Gowdru6a80bbd2019-07-02 07:36:09 -070076// NewPONPort returns a new instance of PonPort initialized with given PONID, DeviceID, IntfID and PortNum
Abhilash S.L765ad002019-04-24 16:40:57 +053077func NewPONPort(PONID uint32, DeviceID string, IntfID uint32, PortNum uint32) *PonPort {
78
79 var PON PonPort
80
81 PON.PONID = PONID
82 PON.DeviceID = DeviceID
83 PON.IntfID = IntfID
84 PON.PortNum = PortNum
85 PON.PortID = 0
Naga Manjunath7615e552019-10-11 22:35:47 +053086 PON.Label = fmt.Sprintf("%s%d", "pon-", PONID)
Abhilash S.L765ad002019-04-24 16:40:57 +053087
88 PON.ONUs = make(map[uint32]interface{})
89 PON.ONUsByID = make(map[uint32]interface{})
90
91 /*
92 Statistics taken from nni_port
93 self.intf_id = 0 #handled by getter
94 self.port_no = 0 #handled by getter
95 self.port_id = 0 #handled by getter
96
97 Note: In the current implementation of the kpis coming from the BAL the stats are the
98 samne model for NNI and PON.
99
100 TODO: Integrate additional kpis for the PON and other southbound port objecgts.
101
102 */
103
104 PON.RxBytes = 0
105 PON.RxPackets = 0
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000106 PON.RxUcastPackets = 0
Abhilash S.L765ad002019-04-24 16:40:57 +0530107 PON.RxMcastPackets = 0
108 PON.RxBcastPackets = 0
109 PON.RxErrorPackets = 0
110 PON.TxBytes = 0
111 PON.TxPackets = 0
112 PON.TxUcastPackets = 0
113 PON.TxMcastPackets = 0
114 PON.TxBcastPackets = 0
115 PON.TxErrorPackets = 0
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000116 PON.RxCrcErrors = 0
117 PON.BipErrors = 0
Abhilash S.L765ad002019-04-24 16:40:57 +0530118
119 /* def __str__(self):
120 return "PonPort-{}: Admin: {}, Oper: {}, OLT: {}".format(self._label,
121 self._admin_state,
122 self._oper_status,
123 self.olt)
124 */
125 return &PON
126}
127
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700128// NniPort representation
Abhilash S.L765ad002019-04-24 16:40:57 +0530129type NniPort struct {
130 /*
131 Northbound network port, often Ethernet-based
132
133 This is a highly reduced version taken from the adtran nni_port code set
134 TODO: add functions to allow for port specific values and operations
135 */
136 PortNum uint32
137 Name string
138 LogicalPort uint32
139 IntfID uint32
140
141 RxBytes uint64
142 RxPackets uint64
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000143 RxUcastPackets uint64
Abhilash S.L765ad002019-04-24 16:40:57 +0530144 RxMcastPackets uint64
145 RxBcastPackets uint64
146 RxErrorPackets uint64
147 TxBytes uint64
148 TxPackets uint64
149 TxUcastPackets uint64
150 TxMcastPackets uint64
151 TxBcastPackets uint64
152 TxErrorPackets uint64
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000153 RxCrcErrors uint64
154 BipErrors uint64
Abhilash S.L765ad002019-04-24 16:40:57 +0530155}
156
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700157// NewNniPort returns a new instance of NniPort initialized with the given PortNum and IntfID
Abhilash S.L765ad002019-04-24 16:40:57 +0530158func NewNniPort(PortNum uint32, IntfID uint32) *NniPort {
159
160 var NNI NniPort
161
162 NNI.PortNum = PortNum
Naga Manjunath7615e552019-10-11 22:35:47 +0530163 NNI.Name = fmt.Sprintf("%s%d", "nni-", PortNum)
Abhilash S.L765ad002019-04-24 16:40:57 +0530164 NNI.IntfID = IntfID
165
166 NNI.RxBytes = 0
167 NNI.RxPackets = 0
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000168 NNI.RxUcastPackets = 0
Abhilash S.L765ad002019-04-24 16:40:57 +0530169 NNI.RxMcastPackets = 0
170 NNI.RxBcastPackets = 0
171 NNI.RxErrorPackets = 0
172 NNI.TxBytes = 0
173 NNI.TxPackets = 0
174 NNI.TxUcastPackets = 0
175 NNI.TxMcastPackets = 0
176 NNI.TxBcastPackets = 0
177 NNI.TxErrorPackets = 0
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000178 NNI.RxCrcErrors = 0
179 NNI.BipErrors = 0
Abhilash S.L765ad002019-04-24 16:40:57 +0530180
181 return &NNI
182}
183
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700184// OpenOltStatisticsMgr structure
Abhilash S.L765ad002019-04-24 16:40:57 +0530185type OpenOltStatisticsMgr struct {
186 Device *DeviceHandler
Naga Manjunath7615e552019-10-11 22:35:47 +0530187 NorthBoundPort map[uint32]*NniPort
188 SouthBoundPort map[uint32]*PonPort
Abhilash S.L765ad002019-04-24 16:40:57 +0530189 // TODO PMMetrics Metrics
190}
191
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700192// NewOpenOltStatsMgr returns a new instance of the OpenOltStatisticsMgr
Abhilash S.L765ad002019-04-24 16:40:57 +0530193func NewOpenOltStatsMgr(Dev *DeviceHandler) *OpenOltStatisticsMgr {
194
195 var StatMgr OpenOltStatisticsMgr
196
197 StatMgr.Device = Dev
198 // TODO call metric PMMetric =
199 // Northbound and Southbound ports
200 // added to initialize the pm_metrics
201 var Ports interface{}
Thomas Lee S985938d2020-05-04 11:40:41 +0530202 Ports, _ = InitPorts("nni", Dev.device.Id, 1)
Naga Manjunath7615e552019-10-11 22:35:47 +0530203 StatMgr.NorthBoundPort, _ = Ports.(map[uint32]*NniPort)
204 NumPonPorts := Dev.resourceMgr.DevInfo.GetPonPorts()
Thomas Lee S985938d2020-05-04 11:40:41 +0530205 Ports, _ = InitPorts("pon", Dev.device.Id, NumPonPorts)
Naga Manjunath7615e552019-10-11 22:35:47 +0530206 StatMgr.SouthBoundPort, _ = Ports.(map[uint32]*PonPort)
Abhilash S.L765ad002019-04-24 16:40:57 +0530207 return &StatMgr
208}
209
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700210// 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 +0530211func InitPorts(Intftype string, DeviceID string, numOfPorts uint32) (interface{}, error) {
Abhilash S.L765ad002019-04-24 16:40:57 +0530212 /*
213 This method collects the port objects: nni and pon that are updated with the
214 current data from the OLT
215
216 Both the northbound (nni) and southbound ports are indexed by the interface id (intf_id)
217 and NOT the port number. When the port object is instantiated it will contain the intf_id and
218 port_no values
219
220 :param type:
221 :return:
222 */
223 var i uint32
224 if Intftype == "nni" {
Naga Manjunath7615e552019-10-11 22:35:47 +0530225 NniPorts := make(map[uint32]*NniPort)
226 for i = 0; i < numOfPorts; i++ {
kdarapu768708d2019-09-16 23:19:15 +0530227 Port := BuildPortObject(i, "nni", DeviceID).(*NniPort)
Naga Manjunath7615e552019-10-11 22:35:47 +0530228 NniPorts[Port.IntfID] = Port
Abhilash S.L765ad002019-04-24 16:40:57 +0530229 }
230 return NniPorts, nil
231 } else if Intftype == "pon" {
Naga Manjunath7615e552019-10-11 22:35:47 +0530232 PONPorts := make(map[uint32]*PonPort)
233 for i = 0; i < numOfPorts; i++ {
kdarapu768708d2019-09-16 23:19:15 +0530234 PONPort := BuildPortObject(i, "pon", DeviceID).(*PonPort)
Naga Manjunath7615e552019-10-11 22:35:47 +0530235 PONPorts[PortNoToIntfID(PONPort.IntfID, voltha.Port_PON_OLT)] = PONPort
Abhilash S.L765ad002019-04-24 16:40:57 +0530236 }
237 return PONPorts, nil
238 } else {
Shrey Baid26912972020-04-16 21:02:31 +0530239 logger.Errorw("invalid-type-of-interface", log.Fields{"interface-type": Intftype})
Thomas Lee S94109f12020-03-03 16:39:29 +0530240 return nil, olterrors.NewErrInvalidValue(log.Fields{"interface-type": Intftype}, nil)
Abhilash S.L765ad002019-04-24 16:40:57 +0530241 }
242}
243
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700244// BuildPortObject allows for updating north and southbound ports, newly discovered ports, and devices
Abhilash S.L765ad002019-04-24 16:40:57 +0530245func BuildPortObject(PortNum uint32, IntfType string, DeviceID string) interface{} {
246 /*
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700247 Separate method to allow for updating north and southbound ports
Abhilash S.L765ad002019-04-24 16:40:57 +0530248 newly discovered ports and devices
249
250 :param port_num:
251 :param type:
252 :return:
253 */
254
255 //This builds a port object which is added to the
256 //appropriate northbound or southbound values
257 if IntfType == "nni" {
Naga Manjunath7615e552019-10-11 22:35:47 +0530258 IntfID := IntfIDToPortNo(PortNum, voltha.Port_ETHERNET_NNI)
259 nniID := PortNoToIntfID(IntfID, voltha.Port_ETHERNET_NNI)
Shrey Baid26912972020-04-16 21:02:31 +0530260 logger.Debugw("interface-type-nni",
261 log.Fields{
262 "nni-id": nniID,
263 "intf-type": IntfType})
Naga Manjunath7615e552019-10-11 22:35:47 +0530264 return NewNniPort(PortNum, nniID)
Abhilash S.L765ad002019-04-24 16:40:57 +0530265 } else if IntfType == "pon" {
266 // PON ports require a different configuration
267 // intf_id and pon_id are currently equal.
Naga Manjunath7615e552019-10-11 22:35:47 +0530268 IntfID := IntfIDToPortNo(PortNum, voltha.Port_PON_OLT)
269 PONID := PortNoToIntfID(IntfID, voltha.Port_PON_OLT)
Shrey Baid26912972020-04-16 21:02:31 +0530270 logger.Debugw("interface-type-pon",
271 log.Fields{
272 "pon-id": PONID,
273 "intf-type": IntfType})
Abhilash S.L765ad002019-04-24 16:40:57 +0530274 return NewPONPort(PONID, DeviceID, IntfID, PortNum)
275 } else {
Shrey Baid26912972020-04-16 21:02:31 +0530276 logger.Errorw("invalid-type-of-interface", log.Fields{"intf-type": IntfType})
Abhilash S.L765ad002019-04-24 16:40:57 +0530277 return nil
278 }
279}
280
Naga Manjunath7615e552019-10-11 22:35:47 +0530281// collectNNIMetrics will collect the nni port metrics
282func (StatMgr *OpenOltStatisticsMgr) collectNNIMetrics(nniID uint32) map[string]float32 {
283
284 nnival := make(map[string]float32)
285 mutex.Lock()
286 cm := StatMgr.Device.portStats.NorthBoundPort[nniID]
287 mutex.Unlock()
288 metricName := StatMgr.Device.metrics.GetSubscriberMetrics()
289
290 if metricName != nil && len(metricName) > 0 {
291 for mName := range metricName {
292 switch mName {
293 case "rx_bytes":
294 nnival["RxBytes"] = float32(cm.RxBytes)
295 case "rx_packets":
296 nnival["RxPackets"] = float32(cm.RxPackets)
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000297 case "rx_ucast_packets":
298 nnival["RxUcastPackets"] = float32(cm.RxUcastPackets)
Naga Manjunath7615e552019-10-11 22:35:47 +0530299 case "rx_mcast_packets":
300 nnival["RxMcastPackets"] = float32(cm.RxMcastPackets)
301 case "rx_bcast_packets":
302 nnival["RxBcastPackets"] = float32(cm.RxBcastPackets)
303 case "tx_bytes":
304 nnival["TxBytes"] = float32(cm.TxBytes)
305 case "tx_packets":
306 nnival["TxPackets"] = float32(cm.TxPackets)
307 case "tx_mcast_packets":
308 nnival["TxMcastPackets"] = float32(cm.TxMcastPackets)
309 case "tx_bcast_packets":
310 nnival["TxBcastPackets"] = float32(cm.TxBcastPackets)
311 }
312 }
313 }
314 return nnival
315}
316
317// collectPONMetrics will collect the pon port metrics
318func (StatMgr *OpenOltStatisticsMgr) collectPONMetrics(pID uint32) map[string]float32 {
319
320 ponval := make(map[string]float32)
321 mutex.Lock()
322 cm := StatMgr.Device.portStats.SouthBoundPort[pID]
323 mutex.Unlock()
324 metricName := StatMgr.Device.metrics.GetSubscriberMetrics()
325
326 if metricName != nil && len(metricName) > 0 {
327 for mName := range metricName {
328 switch mName {
329 case "rx_bytes":
330 ponval["RxBytes"] = float32(cm.RxBytes)
331 case "rx_packets":
332 ponval["RxPackets"] = float32(cm.RxPackets)
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000333 // these are not supported in OpenOlt Agent now
334 // will return zero until supported
335 case "rx_ucast_packets":
336 ponval["RxUcastPackets"] = float32(cm.RxUcastPackets)
Naga Manjunath7615e552019-10-11 22:35:47 +0530337 case "rx_mcast_packets":
338 ponval["RxMcastPackets"] = float32(cm.RxMcastPackets)
339 case "rx_bcast_packets":
340 ponval["RxBcastPackets"] = float32(cm.RxBcastPackets)
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000341 // End will return zero until supported
Naga Manjunath7615e552019-10-11 22:35:47 +0530342 case "tx_bytes":
343 ponval["TxBytes"] = float32(cm.TxBytes)
344 case "tx_packets":
345 ponval["TxPackets"] = float32(cm.TxPackets)
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000346 // these are not supported in OpenOlt Agent now
347 // will return zero until supported
348 case "tx_ucast_packets":
349 ponval["TxUcastPackets"] = float32(cm.TxUcastPackets)
Naga Manjunath7615e552019-10-11 22:35:47 +0530350 case "tx_mcast_packets":
351 ponval["TxMcastPackets"] = float32(cm.TxMcastPackets)
352 case "tx_bcast_packets":
353 ponval["TxBcastPackets"] = float32(cm.TxBcastPackets)
354 }
355 }
356 }
357 return ponval
358}
359
360// publishMatrics will publish the pon port metrics
Kishore Darapuaaf9c102020-05-04 13:06:57 +0530361func (StatMgr OpenOltStatisticsMgr) publishMetrics(val map[string]float32,
Girish Gowdra34815db2020-05-11 17:18:04 -0700362 port *voltha.Port, devID string, devType string) {
Shrey Baid26912972020-04-16 21:02:31 +0530363 logger.Debugw("publish-metrics",
364 log.Fields{
365 "port": port.Label,
366 "metrics": val})
Naga Manjunath7615e552019-10-11 22:35:47 +0530367
368 var metricInfo voltha.MetricInformation
369 var ke voltha.KpiEvent2
Esin Karamanccb714b2019-11-29 15:02:06 +0000370 var volthaEventSubCatgry voltha.EventSubCategory_Types
Girish Gowdra34815db2020-05-11 17:18:04 -0700371 metricsContext := make(map[string]string)
372 metricsContext["oltid"] = devID
373 metricsContext["devicetype"] = devType
374 metricsContext["portlabel"] = port.Label
375 metricsContext["portno"] = strconv.Itoa(int(port.PortNo))
Naga Manjunath7615e552019-10-11 22:35:47 +0530376
Kishore Darapuaaf9c102020-05-04 13:06:57 +0530377 if port.Type == voltha.Port_ETHERNET_NNI {
Naga Manjunath7615e552019-10-11 22:35:47 +0530378 volthaEventSubCatgry = voltha.EventSubCategory_NNI
379 } else {
380 volthaEventSubCatgry = voltha.EventSubCategory_PON
381 }
382
383 raisedTs := time.Now().UnixNano()
384 mmd := voltha.MetricMetaData{
Kishore Darapuaaf9c102020-05-04 13:06:57 +0530385 Title: port.Type.String(),
Naga Manjunath7615e552019-10-11 22:35:47 +0530386 Ts: float64(raisedTs),
Girish Gowdra34815db2020-05-11 17:18:04 -0700387 Context: metricsContext,
Naga Manjunath7615e552019-10-11 22:35:47 +0530388 DeviceId: devID,
389 }
390
391 metricInfo.Metadata = &mmd
392 metricInfo.Metrics = val
393
394 ke.SliceData = []*voltha.MetricInformation{&metricInfo}
395 ke.Type = voltha.KpiEventType_slice
396 ke.Ts = float64(time.Now().UnixNano())
397
398 if err := StatMgr.Device.EventProxy.SendKpiEvent("STATS_EVENT", &ke, voltha.EventCategory_EQUIPMENT, volthaEventSubCatgry, raisedTs); err != nil {
Shrey Baid26912972020-04-16 21:02:31 +0530399 logger.Errorw("failed-to-send-pon-stats", log.Fields{"err": err})
Naga Manjunath7615e552019-10-11 22:35:47 +0530400 }
Naga Manjunath7615e552019-10-11 22:35:47 +0530401}
402
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700403// PortStatisticsIndication handles the port statistics indication
Naga Manjunath7615e552019-10-11 22:35:47 +0530404func (StatMgr *OpenOltStatisticsMgr) PortStatisticsIndication(PortStats *openolt.PortStatistics, NumPonPorts uint32) {
Naga Manjunath7615e552019-10-11 22:35:47 +0530405 StatMgr.PortsStatisticsKpis(PortStats, NumPonPorts)
Shrey Baid26912972020-04-16 21:02:31 +0530406 logger.Debugw("received-port-stats-indication", log.Fields{"port-stats": PortStats})
Abhilash S.L765ad002019-04-24 16:40:57 +0530407 // TODO send stats to core topic to the voltha kafka or a different kafka ?
408}
409
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700410// FlowStatisticsIndication to be implemented
Abhilash S.L765ad002019-04-24 16:40:57 +0530411func FlowStatisticsIndication(self, FlowStats *openolt.FlowStatistics) {
Shrey Baid26912972020-04-16 21:02:31 +0530412 logger.Debugw("flow-stats-collected", log.Fields{"flow-stats": FlowStats})
Abhilash S.L765ad002019-04-24 16:40:57 +0530413 //TODO send to kafka ?
414}
415
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700416// PortsStatisticsKpis map the port stats values into a dictionary, creates the kpiEvent and then publish to Kafka
Naga Manjunath7615e552019-10-11 22:35:47 +0530417func (StatMgr *OpenOltStatisticsMgr) PortsStatisticsKpis(PortStats *openolt.PortStatistics, NumPonPorts uint32) {
Abhilash S.L765ad002019-04-24 16:40:57 +0530418
419 /*map the port stats values into a dictionary
420 Create a kpoEvent and publish to Kafka
421
422 :param port_stats:
423 :return:
424 */
425 //var err error
426 IntfID := PortStats.IntfId
427
Naga Manjunath7615e552019-10-11 22:35:47 +0530428 if (IntfIDToPortNo(1, voltha.Port_ETHERNET_NNI) < IntfID) &&
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700429 (IntfID < IntfIDToPortNo(4, voltha.Port_ETHERNET_NNI)) {
Abhilash S.L765ad002019-04-24 16:40:57 +0530430 /*
431 for this release we are only interested in the first NNI for
432 Northbound.
433 we are not using the other 3
434 */
435 return
Naga Manjunath7615e552019-10-11 22:35:47 +0530436 } else if IntfIDToPortNo(0, voltha.Port_ETHERNET_NNI) == IntfID {
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700437
Naga Manjunath7615e552019-10-11 22:35:47 +0530438 var portNNIStat NniPort
439 portNNIStat.IntfID = IntfID
440 portNNIStat.PortNum = uint32(0)
441 portNNIStat.RxBytes = PortStats.RxBytes
442 portNNIStat.RxPackets = PortStats.RxPackets
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000443 portNNIStat.RxUcastPackets = PortStats.RxUcastPackets
Naga Manjunath7615e552019-10-11 22:35:47 +0530444 portNNIStat.RxMcastPackets = PortStats.RxMcastPackets
445 portNNIStat.RxBcastPackets = PortStats.RxBcastPackets
446 portNNIStat.TxBytes = PortStats.TxBytes
447 portNNIStat.TxPackets = PortStats.TxPackets
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000448 portNNIStat.TxUcastPackets = PortStats.TxUcastPackets
Naga Manjunath7615e552019-10-11 22:35:47 +0530449 portNNIStat.TxMcastPackets = PortStats.TxMcastPackets
450 portNNIStat.TxBcastPackets = PortStats.TxBcastPackets
451 mutex.Lock()
452 StatMgr.NorthBoundPort[0] = &portNNIStat
453 mutex.Unlock()
Shrey Baid26912972020-04-16 21:02:31 +0530454 logger.Debugw("received-nni-stats", log.Fields{"nni-stats": StatMgr.NorthBoundPort})
Naga Manjunath7615e552019-10-11 22:35:47 +0530455 }
456 for i := uint32(0); i < NumPonPorts; i++ {
457
458 if IntfIDToPortNo(i, voltha.Port_PON_OLT) == IntfID {
459 var portPonStat PonPort
460 portPonStat.IntfID = IntfID
461 portPonStat.PortNum = i
462 portPonStat.PONID = i
463 portPonStat.RxBytes = PortStats.RxBytes
464 portPonStat.RxPackets = PortStats.RxPackets
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000465 portPonStat.RxUcastPackets = PortStats.RxUcastPackets
Naga Manjunath7615e552019-10-11 22:35:47 +0530466 portPonStat.RxMcastPackets = PortStats.RxMcastPackets
467 portPonStat.RxBcastPackets = PortStats.RxBcastPackets
468 portPonStat.TxBytes = PortStats.TxBytes
469 portPonStat.TxPackets = PortStats.TxPackets
Dileep Kuchhangi52cfbe12020-01-15 20:16:21 +0000470 portPonStat.TxUcastPackets = PortStats.TxUcastPackets
Naga Manjunath7615e552019-10-11 22:35:47 +0530471 portPonStat.TxMcastPackets = PortStats.TxMcastPackets
472 portPonStat.TxBcastPackets = PortStats.TxBcastPackets
473 mutex.Lock()
474 StatMgr.SouthBoundPort[i] = &portPonStat
475 mutex.Unlock()
Shrey Baid26912972020-04-16 21:02:31 +0530476 logger.Debugw("received-pon-stats-for-port", log.Fields{"port-pon-stats": portPonStat})
Naga Manjunath7615e552019-10-11 22:35:47 +0530477 }
478 }
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700479
480 /*
481 Based upon the intf_id map to an nni port or a pon port
482 the intf_id is the key to the north or south bound collections
483
484 Based upon the intf_id the port object (nni_port or pon_port) will
485 have its data attr. updated by the current dataset collected.
486
487 For prefixing the rule is currently to use the port number and not the intf_id
488 */
489 //FIXME : Just use first NNI for now
490 /* TODO should the data be marshaled before sending it ?
491 if IntfID == IntfIdToPortNo(0, voltha.Port_ETHERNET_NNI) {
492 //NNI port (just the first one)
493 err = UpdatePortObjectKpiData(StatMgr.NorthBoundPorts[PortStats.IntfID], PMData)
494 } else {
495 //PON ports
496 err = UpdatePortObjectKpiData(SouthboundPorts[PortStats.IntfID], PMData)
497 }
498 if (err != nil) {
Girish Kumar2ad402b2020-03-20 19:45:12 +0000499 logger.Error("Error publishing statistics data")
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700500 }
501 */
502
Abhilash S.L765ad002019-04-24 16:40:57 +0530503}